@@ -299,3 +299,57 @@ func TestNamedQueries(t *testing.T) {
299299
300300 })
301301}
302+
303+ func TestFixBounds (t * testing.T ) {
304+ table := []struct {
305+ name , query , expect string
306+ loop int
307+ }{
308+ {
309+ name : `named syntax` ,
310+ query : `INSERT INTO foo (a,b,c,d) VALUES (:name, :age, :first, :last)` ,
311+ expect : `INSERT INTO foo (a,b,c,d) VALUES (:name, :age, :first, :last),(:name, :age, :first, :last)` ,
312+ loop : 2 ,
313+ },
314+ {
315+ name : `mysql syntax` ,
316+ query : `INSERT INTO foo (a,b,c,d) VALUES (?, ?, ?, ?)` ,
317+ expect : `INSERT INTO foo (a,b,c,d) VALUES (?, ?, ?, ?),(?, ?, ?, ?)` ,
318+ loop : 2 ,
319+ },
320+ {
321+ name : `named syntax w/ trailer` ,
322+ query : `INSERT INTO foo (a,b,c,d) VALUES (:name, :age, :first, :last) ;--` ,
323+ expect : `INSERT INTO foo (a,b,c,d) VALUES (:name, :age, :first, :last),(:name, :age, :first, :last) ;--` ,
324+ loop : 2 ,
325+ },
326+ {
327+ name : `mysql syntax w/ trailer` ,
328+ query : `INSERT INTO foo (a,b,c,d) VALUES (?, ?, ?, ?) ;--` ,
329+ expect : `INSERT INTO foo (a,b,c,d) VALUES (?, ?, ?, ?),(?, ?, ?, ?) ;--` ,
330+ loop : 2 ,
331+ },
332+ {
333+ name : `not found test` ,
334+ query : `INSERT INTO foo (a,b,c,d) (:name, :age, :first, :last)` ,
335+ expect : `INSERT INTO foo (a,b,c,d) (:name, :age, :first, :last)` ,
336+ loop : 2 ,
337+ },
338+ {
339+ name : `found twice test` ,
340+ query : `INSERT INTO foo (a,b,c,d) VALUES (:name, :age, :first, :last) VALUES (:name, :age, :first, :last)` ,
341+ expect : `INSERT INTO foo (a,b,c,d) VALUES (:name, :age, :first, :last) VALUES (:name, :age, :first, :last)` ,
342+ loop : 2 ,
343+ },
344+ }
345+
346+ for _ , tc := range table {
347+ t .Run (tc .name , func (t * testing.T ) {
348+ res := fixBound (tc .query , tc .loop )
349+ if res != tc .expect {
350+ t .Errorf ("mismatched results" )
351+ }
352+ })
353+ }
354+
355+ }
0 commit comments