| 1316 | } |
| 1317 | |
| 1318 | func TestRebind(t *testing.T) { |
| 1319 | q1 := `INSERT INTO foo (a, b, c, d, e, f, g, h, i) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)` |
| 1320 | q2 := `INSERT INTO foo (a, b, c) VALUES (?, ?, "foo"), ("Hi", ?, ?)` |
| 1321 | |
| 1322 | s1 := Rebind(DOLLAR, q1) |
| 1323 | s2 := Rebind(DOLLAR, q2) |
| 1324 | |
| 1325 | if s1 != `INSERT INTO foo (a, b, c, d, e, f, g, h, i) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10)` { |
| 1326 | t.Errorf("q1 failed") |
| 1327 | } |
| 1328 | |
| 1329 | if s2 != `INSERT INTO foo (a, b, c) VALUES ($1, $2, "foo"), ("Hi", $3, $4)` { |
| 1330 | t.Errorf("q2 failed") |
| 1331 | } |
| 1332 | |
| 1333 | s1 = Rebind(AT, q1) |
| 1334 | s2 = Rebind(AT, q2) |
| 1335 | |
| 1336 | if s1 != `INSERT INTO foo (a, b, c, d, e, f, g, h, i) VALUES (@p1, @p2, @p3, @p4, @p5, @p6, @p7, @p8, @p9, @p10)` { |
| 1337 | t.Errorf("q1 failed") |
| 1338 | } |
| 1339 | |
| 1340 | if s2 != `INSERT INTO foo (a, b, c) VALUES (@p1, @p2, "foo"), ("Hi", @p3, @p4)` { |
| 1341 | t.Errorf("q2 failed") |
| 1342 | } |
| 1343 | |
| 1344 | s1 = Rebind(NAMED, q1) |
| 1345 | s2 = Rebind(NAMED, q2) |
| 1346 | |
| 1347 | ex1 := `INSERT INTO foo (a, b, c, d, e, f, g, h, i) VALUES ` + |
| 1348 | `(:arg1, :arg2, :arg3, :arg4, :arg5, :arg6, :arg7, :arg8, :arg9, :arg10)` |
| 1349 | if s1 != ex1 { |
| 1350 | t.Error("q1 failed on Named params") |
| 1351 | } |
| 1352 | |
| 1353 | ex2 := `INSERT INTO foo (a, b, c) VALUES (:arg1, :arg2, "foo"), ("Hi", :arg3, :arg4)` |
| 1354 | if s2 != ex2 { |
| 1355 | t.Error("q2 failed on Named params") |
| 1356 | } |
| 1357 | } |
| 1358 | |
| 1359 | func TestBindMap(t *testing.T) { |
| 1360 | // Test that it works.. |