diff --git a/delete_dataset_example_test.go b/delete_dataset_example_test.go index 2d1716bc..f954fdda 100644 --- a/delete_dataset_example_test.go +++ b/delete_dataset_example_test.go @@ -186,11 +186,11 @@ func ExampleDeleteDataset_Where_prepared() { ).ToSQL() fmt.Println(sql, args) // Output: - // DELETE FROM "test" WHERE (("a" > ?) AND ("b" < ?) AND ("c" IS NULL) AND ("d" IN (?, ?, ?))) [10 10 a b c] - // DELETE FROM "test" WHERE (("a" > ?) OR ("b" < ?) OR ("c" IS NULL) OR ("d" IN (?, ?, ?))) [10 10 a b c] - // DELETE FROM "test" WHERE ((("a" > ?) AND ("b" < ?)) OR (("c" IS NULL) AND ("d" IN (?, ?, ?)))) [10 10 a b c] - // DELETE FROM "test" WHERE (("a" > ?) AND ("b" < ?) AND ("c" IS NULL) AND ("d" IN (?, ?, ?))) [10 10 a b c] - // DELETE FROM "test" WHERE (("a" > ?) OR (("b" < ?) AND ("c" IS NULL))) [10 10] + // DELETE FROM "test" WHERE (("a" > ?) AND ("b" < ?) AND ("c" IS ?) AND ("d" IN (?, ?, ?))) [10 10 a b c] + // DELETE FROM "test" WHERE (("a" > ?) OR ("b" < ?) OR ("c" IS ?) OR ("d" IN (?, ?, ?))) [10 10 a b c] + // DELETE FROM "test" WHERE ((("a" > ?) AND ("b" < ?)) OR (("c" IS ?) AND ("d" IN (?, ?, ?)))) [10 10 a b c] + // DELETE FROM "test" WHERE (("a" > ?) AND ("b" < ?) AND ("c" IS ?) AND ("d" IN (?, ?, ?))) [10 10 a b c] + // DELETE FROM "test" WHERE (("a" > ?) OR (("b" < ?) AND ("c" IS ?))) [10 10 ] } func ExampleDeleteDataset_ClearWhere() { diff --git a/expressions_example_test.go b/expressions_example_test.go index 126fd6c0..a79219f8 100644 --- a/expressions_example_test.go +++ b/expressions_example_test.go @@ -98,9 +98,9 @@ func ExampleAnd_withOr() { // Output: // SELECT * FROM "test" WHERE (("col1" IS TRUE) AND (("col2" > 10) OR ("col2" < 20))) [] - // SELECT * FROM "test" WHERE (("col1" IS TRUE) AND (("col2" > ?) OR ("col2" < ?))) [10 20] + // SELECT * FROM "test" WHERE (("col1" IS ?) AND (("col2" > ?) OR ("col2" < ?))) [true 10 20] // SELECT * FROM "test" WHERE (("col1" IS TRUE) AND (("col2" > 10) OR ("col2" < 20))) [] - // SELECT * FROM "test" WHERE (("col1" IS TRUE) AND (("col2" > ?) OR ("col2" < ?))) [10 20] + // SELECT * FROM "test" WHERE (("col1" IS ?) AND (("col2" > ?) OR ("col2" < ?))) [true 10 20] } // You can use ExOr inside of And expression lists. @@ -121,7 +121,7 @@ func ExampleAnd_withExOr() { // Output: // SELECT * FROM "test" WHERE (("col1" IS TRUE) AND (("col2" > 10) OR ("col3" < 20))) [] - // SELECT * FROM "test" WHERE (("col1" IS TRUE) AND (("col2" > ?) OR ("col3" < ?))) [10 20] + // SELECT * FROM "test" WHERE (("col1" IS ?) AND (("col2" > ?) OR ("col3" < ?))) [true 10 20] } func ExampleC() { @@ -153,7 +153,7 @@ func ExampleC() { // SELECT * FROM "test" [] // SELECT "col1" FROM "test" [] // SELECT * FROM "test" WHERE (("col1" = 10) AND ("col2" IN (1, 2, 3, 4)) AND ("col3" ~ '^(a|b)') AND ("col4" IS NULL)) [] - // SELECT * FROM "test" WHERE (("col1" = ?) AND ("col2" IN (?, ?, ?, ?)) AND ("col3" ~ ?) AND ("col4" IS NULL)) [10 1 2 3 4 ^(a|b)] + // SELECT * FROM "test" WHERE (("col1" = ?) AND ("col2" IN (?, ?, ?, ?)) AND ("col3" ~ ?) AND ("col4" IS ?)) [10 1 2 3 4 ^(a|b) ] } func ExampleC_as() { @@ -390,7 +390,7 @@ func ExampleCOALESCE() { fmt.Println(sql, args) // Output: // SELECT COALESCE("a", 'a'), COALESCE("a", "b", NULL) FROM "test" [] - // SELECT COALESCE("a", ?), COALESCE("a", "b", NULL) FROM "test" [a] + // SELECT COALESCE("a", ?), COALESCE("a", "b", ?) FROM "test" [a ] } func ExampleCOALESCE_as() { @@ -561,7 +561,7 @@ func ExampleDoUpdate_where() { // Output: // INSERT INTO "items" ("address") VALUES ('111 Address') ON CONFLICT (address) DO UPDATE SET "address"="EXCLUDED"."address" WHERE ("items"."updated" IS NULL) [] - // INSERT INTO "items" ("address") VALUES (?) ON CONFLICT (address) DO UPDATE SET "address"="EXCLUDED"."address" WHERE ("items"."updated" IS NULL) [111 Address] + // INSERT INTO "items" ("address") VALUES (?) ON CONFLICT (address) DO UPDATE SET "address"="EXCLUDED"."address" WHERE ("items"."updated" IS ?) [111 Address ] } func ExampleFIRST() { @@ -1032,7 +1032,7 @@ func ExampleOr_withExMap() { // Output: // SELECT * FROM "test" WHERE ((("col1" = 1) AND ("col2" IS TRUE)) OR (("col3" IS NULL) AND ("col4" = 'foo'))) [] - // SELECT * FROM "test" WHERE ((("col1" = ?) AND ("col2" IS TRUE)) OR (("col3" IS NULL) AND ("col4" = ?))) [1 foo] + // SELECT * FROM "test" WHERE ((("col1" = ?) AND ("col2" IS ?)) OR (("col3" IS ?) AND ("col4" = ?))) [1 true foo] } func ExampleRange_numbers() { @@ -1251,7 +1251,7 @@ func ExampleEx() { // Output: // SELECT * FROM "items" WHERE (("col1" = 'a') AND ("col2" = 1) AND ("col3" IS TRUE) AND ("col4" IS FALSE) AND ("col5" IS NULL) AND ("col6" IN ('a', 'b', 'c'))) [] - // SELECT * FROM "items" WHERE (("col1" = ?) AND ("col2" = ?) AND ("col3" IS TRUE) AND ("col4" IS FALSE) AND ("col5" IS NULL) AND ("col6" IN (?, ?, ?))) [a 1 a b c] + // SELECT * FROM "items" WHERE (("col1" = ?) AND ("col2" = ?) AND ("col3" IS ?) AND ("col4" IS ?) AND ("col5" IS ?) AND ("col6" IN (?, ?, ?))) [a 1 true false a b c] } func ExampleEx_withOp() { @@ -1561,23 +1561,23 @@ func ExampleOp_isComparisons() { // Output: // SELECT * FROM "test" WHERE ("a" IS TRUE) [] + // SELECT * FROM "test" WHERE ("a" IS ?) [true] // SELECT * FROM "test" WHERE ("a" IS TRUE) [] - // SELECT * FROM "test" WHERE ("a" IS TRUE) [] - // SELECT * FROM "test" WHERE ("a" IS TRUE) [] - // SELECT * FROM "test" WHERE ("a" IS FALSE) [] + // SELECT * FROM "test" WHERE ("a" IS ?) [true] // SELECT * FROM "test" WHERE ("a" IS FALSE) [] + // SELECT * FROM "test" WHERE ("a" IS ?) [false] // SELECT * FROM "test" WHERE ("a" IS FALSE) [] - // SELECT * FROM "test" WHERE ("a" IS FALSE) [] - // SELECT * FROM "test" WHERE ("a" IS NULL) [] + // SELECT * FROM "test" WHERE ("a" IS ?) [false] // SELECT * FROM "test" WHERE ("a" IS NULL) [] + // SELECT * FROM "test" WHERE ("a" IS ?) [] // SELECT * FROM "test" WHERE ("a" IS NULL) [] - // SELECT * FROM "test" WHERE ("a" IS NULL) [] - // SELECT * FROM "test" WHERE ("a" IS NOT TRUE) [] + // SELECT * FROM "test" WHERE ("a" IS ?) [] // SELECT * FROM "test" WHERE ("a" IS NOT TRUE) [] + // SELECT * FROM "test" WHERE ("a" IS NOT ?) [true] // SELECT * FROM "test" WHERE ("a" IS NOT FALSE) [] - // SELECT * FROM "test" WHERE ("a" IS NOT FALSE) [] - // SELECT * FROM "test" WHERE ("a" IS NOT NULL) [] + // SELECT * FROM "test" WHERE ("a" IS NOT ?) [false] // SELECT * FROM "test" WHERE ("a" IS NOT NULL) [] + // SELECT * FROM "test" WHERE ("a" IS NOT ?) [] } func ExampleOp_betweenComparisons() { @@ -1620,7 +1620,7 @@ func ExampleOp_withMultipleKeys() { // Output: // SELECT * FROM "items" WHERE (("col1" = 10) OR ("col1" IS NULL)) [] - // SELECT * FROM "items" WHERE (("col1" = ?) OR ("col1" IS NULL)) [10] + // SELECT * FROM "items" WHERE (("col1" = ?) OR ("col1" IS ?)) [10 ] } func ExampleRecord_insert() { diff --git a/select_dataset_example_test.go b/select_dataset_example_test.go index 08f1e39d..fbcd3a06 100644 --- a/select_dataset_example_test.go +++ b/select_dataset_example_test.go @@ -471,11 +471,11 @@ func ExampleSelectDataset_Where_prepared() { ).ToSQL() fmt.Println(sql, args) // Output: - // SELECT * FROM "test" WHERE (("a" > ?) AND ("b" < ?) AND ("c" IS NULL) AND ("d" IN (?, ?, ?))) [10 10 a b c] - // SELECT * FROM "test" WHERE (("a" > ?) OR ("b" < ?) OR ("c" IS NULL) OR ("d" IN (?, ?, ?))) [10 10 a b c] - // SELECT * FROM "test" WHERE ((("a" > ?) AND ("b" < ?)) OR (("c" IS NULL) AND ("d" IN (?, ?, ?)))) [10 10 a b c] - // SELECT * FROM "test" WHERE (("a" > ?) AND ("b" < ?) AND ("c" IS NULL) AND ("d" IN (?, ?, ?))) [10 10 a b c] - // SELECT * FROM "test" WHERE (("a" > ?) OR (("b" < ?) AND ("c" IS NULL))) [10 10] + // SELECT * FROM "test" WHERE (("a" > ?) AND ("b" < ?) AND ("c" IS ?) AND ("d" IN (?, ?, ?))) [10 10 a b c] + // SELECT * FROM "test" WHERE (("a" > ?) OR ("b" < ?) OR ("c" IS ?) OR ("d" IN (?, ?, ?))) [10 10 a b c] + // SELECT * FROM "test" WHERE ((("a" > ?) AND ("b" < ?)) OR (("c" IS ?) AND ("d" IN (?, ?, ?)))) [10 10 a b c] + // SELECT * FROM "test" WHERE (("a" > ?) AND ("b" < ?) AND ("c" IS ?) AND ("d" IN (?, ?, ?))) [10 10 a b c] + // SELECT * FROM "test" WHERE (("a" > ?) OR (("b" < ?) AND ("c" IS ?))) [10 10 ] } func ExampleSelectDataset_ClearWhere() { diff --git a/sqlgen/expression_sql_generator.go b/sqlgen/expression_sql_generator.go index 275df752..c98c3818 100644 --- a/sqlgen/expression_sql_generator.go +++ b/sqlgen/expression_sql_generator.go @@ -247,6 +247,10 @@ func (esg *expressionSQLGenerator) identifierExpressionSQL(b sb.SQLBuilder, iden // Generates SQL NULL value func (esg *expressionSQLGenerator) literalNil(b sb.SQLBuilder) { + if b.IsPrepared() { + esg.placeHolderSQL(b, nil) + return + } b.Write(esg.dialectOptions.Null) } @@ -361,7 +365,7 @@ func (esg *expressionSQLGenerator) booleanExpressionSQL(b sb.SQLBuilder, operato return } rhs := operator.RHS() - if (operatorOp == exp.IsOp || operatorOp == exp.IsNotOp) && esg.dialectOptions.UseLiteralIsBools { + if !b.IsPrepared() && (operatorOp == exp.IsOp || operatorOp == exp.IsNotOp) && esg.dialectOptions.UseLiteralIsBools { if rhs == true { rhs = TrueLiteral } else if rhs == false { diff --git a/sqlgen/expression_sql_generator_test.go b/sqlgen/expression_sql_generator_test.go index 30129da1..f74a7021 100644 --- a/sqlgen/expression_sql_generator_test.go +++ b/sqlgen/expression_sql_generator_test.go @@ -113,7 +113,7 @@ func (esgs *expressionSQLGeneratorSuite) TestGenerate_Invalid() { esgs.assertCases( NewExpressionSQLGenerator("test", DefaultDialectOptions()), expressionTestCase{val: b, sql: "NULL"}, - expressionTestCase{val: b, sql: "NULL", isPrepared: true}, + expressionTestCase{val: b, sql: "?", isPrepared: true, args: []interface{}{nil}}, ) } @@ -145,9 +145,9 @@ func (esgs *expressionSQLGeneratorSuite) TestGenerate_IncludePlaceholderNum() { }, expressionTestCase{ val: ex, - sql: `(("a" = $1) AND ("b" IS TRUE) AND ("c" IS FALSE) AND ("d" IN ($2, $3, $4)))`, + sql: `(("a" = $1) AND ("b" IS $2) AND ("c" IS $3) AND ("d" IN ($4, $5, $6)))`, isPrepared: true, - args: []interface{}{int64(1), "a", "b", "c"}, + args: []interface{}{int64(1), true, false, "a", "b", "c"}, }, ) } @@ -258,7 +258,7 @@ func (esgs *expressionSQLGeneratorSuite) TestGenerate_TimeTypes() { esgs.assertCases( NewExpressionSQLGenerator("test", DefaultDialectOptions()), expressionTestCase{val: nt, sql: "NULL"}, - expressionTestCase{val: nt, sql: "NULL", isPrepared: true}, + expressionTestCase{val: nt, sql: "?", isPrepared: true, args: []interface{}{nil}}, ) } @@ -266,7 +266,7 @@ func (esgs *expressionSQLGeneratorSuite) TestGenerate_NilTypes() { esgs.assertCases( NewExpressionSQLGenerator("test", DefaultDialectOptions()), expressionTestCase{val: nil, sql: "NULL"}, - expressionTestCase{val: nil, sql: "NULL", isPrepared: true}, + expressionTestCase{val: nil, sql: "?", isPrepared: true, args: []interface{}{nil}}, ) } @@ -464,13 +464,13 @@ func (esgs *expressionSQLGeneratorSuite) TestGenerate_BooleanExpression() { expressionTestCase{val: ident.Eq(1), sql: `("a" = ?)`, isPrepared: true, args: []interface{}{int64(1)}}, expressionTestCase{val: ident.Eq(true), sql: `("a" IS TRUE)`}, - expressionTestCase{val: ident.Eq(true), sql: `("a" IS TRUE)`, isPrepared: true}, + expressionTestCase{val: ident.Eq(true), sql: `("a" IS ?)`, isPrepared: true, args: []interface{}{true}}, expressionTestCase{val: ident.Eq(false), sql: `("a" IS FALSE)`}, - expressionTestCase{val: ident.Eq(false), sql: `("a" IS FALSE)`, isPrepared: true}, + expressionTestCase{val: ident.Eq(false), sql: `("a" IS ?)`, isPrepared: true, args: []interface{}{false}}, expressionTestCase{val: ident.Eq(nil), sql: `("a" IS NULL)`}, - expressionTestCase{val: ident.Eq(nil), sql: `("a" IS NULL)`, isPrepared: true}, + expressionTestCase{val: ident.Eq(nil), sql: `("a" IS ?)`, isPrepared: true, args: []interface{}{nil}}, expressionTestCase{val: ident.Eq([]int64{1, 2, 3}), sql: `("a" IN (1, 2, 3))`}, expressionTestCase{val: ident.Eq([]int64{1, 2, 3}), sql: `("a" IN (?, ?, ?))`, isPrepared: true, args: []interface{}{ @@ -484,13 +484,13 @@ func (esgs *expressionSQLGeneratorSuite) TestGenerate_BooleanExpression() { expressionTestCase{val: ident.Neq(1), sql: `("a" != ?)`, isPrepared: true, args: []interface{}{int64(1)}}, expressionTestCase{val: ident.Neq(true), sql: `("a" IS NOT TRUE)`}, - expressionTestCase{val: ident.Neq(true), sql: `("a" IS NOT TRUE)`, isPrepared: true}, + expressionTestCase{val: ident.Neq(true), sql: `("a" IS NOT ?)`, isPrepared: true, args: []interface{}{true}}, expressionTestCase{val: ident.Neq(false), sql: `("a" IS NOT FALSE)`}, - expressionTestCase{val: ident.Neq(false), sql: `("a" IS NOT FALSE)`, isPrepared: true}, + expressionTestCase{val: ident.Neq(false), sql: `("a" IS NOT ?)`, isPrepared: true, args: []interface{}{false}}, expressionTestCase{val: ident.Neq(nil), sql: `("a" IS NOT NULL)`}, - expressionTestCase{val: ident.Neq(nil), sql: `("a" IS NOT NULL)`, isPrepared: true}, + expressionTestCase{val: ident.Neq(nil), sql: `("a" IS NOT ?)`, isPrepared: true, args: []interface{}{nil}}, expressionTestCase{val: ident.Neq([]int64{1, 2, 3}), sql: `("a" NOT IN (1, 2, 3))`}, expressionTestCase{val: ident.Neq([]int64{1, 2, 3}), sql: `("a" NOT IN (?, ?, ?))`, isPrepared: true, args: []interface{}{ @@ -501,22 +501,22 @@ func (esgs *expressionSQLGeneratorSuite) TestGenerate_BooleanExpression() { expressionTestCase{val: ident.Neq(ae), sql: `("a" NOT IN (SELECT "id" FROM "test2"))`, isPrepared: true}, expressionTestCase{val: ident.Is(true), sql: `("a" IS TRUE)`}, - expressionTestCase{val: ident.Is(true), sql: `("a" IS TRUE)`, isPrepared: true}, + expressionTestCase{val: ident.Is(true), sql: `("a" IS ?)`, isPrepared: true, args: []interface{}{true}}, expressionTestCase{val: ident.Is(false), sql: `("a" IS FALSE)`}, - expressionTestCase{val: ident.Is(false), sql: `("a" IS FALSE)`, isPrepared: true}, + expressionTestCase{val: ident.Is(false), sql: `("a" IS ?)`, isPrepared: true, args: []interface{}{false}}, expressionTestCase{val: ident.Is(nil), sql: `("a" IS NULL)`}, - expressionTestCase{val: ident.Is(nil), sql: `("a" IS NULL)`, isPrepared: true}, + expressionTestCase{val: ident.Is(nil), sql: `("a" IS ?)`, isPrepared: true, args: []interface{}{nil}}, expressionTestCase{val: ident.IsNot(true), sql: `("a" IS NOT TRUE)`}, - expressionTestCase{val: ident.IsNot(true), sql: `("a" IS NOT TRUE)`, isPrepared: true}, + expressionTestCase{val: ident.IsNot(true), sql: `("a" IS NOT ?)`, isPrepared: true, args: []interface{}{true}}, expressionTestCase{val: ident.IsNot(false), sql: `("a" IS NOT FALSE)`}, - expressionTestCase{val: ident.IsNot(false), sql: `("a" IS NOT FALSE)`, isPrepared: true}, + expressionTestCase{val: ident.IsNot(false), sql: `("a" IS NOT ?)`, isPrepared: true, args: []interface{}{false}}, expressionTestCase{val: ident.IsNot(nil), sql: `("a" IS NOT NULL)`}, - expressionTestCase{val: ident.IsNot(nil), sql: `("a" IS NOT NULL)`, isPrepared: true}, + expressionTestCase{val: ident.IsNot(nil), sql: `("a" IS NOT ?)`, isPrepared: true, args: []interface{}{nil}}, expressionTestCase{val: ident.Gt(1), sql: `("a" > 1)`}, expressionTestCase{val: ident.Gt(1), sql: `("a" > ?)`, isPrepared: true, args: []interface{}{int64(1)}}, @@ -1119,13 +1119,13 @@ func (esgs *expressionSQLGeneratorSuite) TestGenerate_ExpressionMap() { expressionTestCase{val: exp.Ex{"a": 1}, sql: `("a" = ?)`, isPrepared: true, args: []interface{}{int64(1)}}, expressionTestCase{val: exp.Ex{"a": true}, sql: `("a" IS TRUE)`}, - expressionTestCase{val: exp.Ex{"a": true}, sql: `("a" IS TRUE)`, isPrepared: true}, + expressionTestCase{val: exp.Ex{"a": true}, sql: `("a" IS ?)`, isPrepared: true, args: []interface{}{true}}, expressionTestCase{val: exp.Ex{"a": false}, sql: `("a" IS FALSE)`}, - expressionTestCase{val: exp.Ex{"a": false}, sql: `("a" IS FALSE)`, isPrepared: true}, + expressionTestCase{val: exp.Ex{"a": false}, sql: `("a" IS ?)`, isPrepared: true, args: []interface{}{false}}, expressionTestCase{val: exp.Ex{"a": nil}, sql: `("a" IS NULL)`}, - expressionTestCase{val: exp.Ex{"a": nil}, sql: `("a" IS NULL)`, isPrepared: true}, + expressionTestCase{val: exp.Ex{"a": nil}, sql: `("a" IS ?)`, isPrepared: true, args: []interface{}{nil}}, expressionTestCase{val: exp.Ex{"a": []string{"a", "b", "c"}}, sql: `("a" IN ('a', 'b', 'c'))`}, expressionTestCase{ @@ -1141,7 +1141,7 @@ func (esgs *expressionSQLGeneratorSuite) TestGenerate_ExpressionMap() { }}, expressionTestCase{val: exp.Ex{"a": exp.Op{"isnot": true}}, sql: `("a" IS NOT TRUE)`}, - expressionTestCase{val: exp.Ex{"a": exp.Op{"isnot": true}}, sql: `("a" IS NOT TRUE)`, isPrepared: true}, + expressionTestCase{val: exp.Ex{"a": exp.Op{"isnot": true}}, sql: `("a" IS NOT ?)`, isPrepared: true, args: []interface{}{true}}, expressionTestCase{val: exp.Ex{"a": exp.Op{"gt": 1}}, sql: `("a" > 1)`}, expressionTestCase{val: exp.Ex{"a": exp.Op{"gt": 1}}, sql: `("a" > ?)`, isPrepared: true, args: []interface{}{ @@ -1274,9 +1274,9 @@ func (esgs *expressionSQLGeneratorSuite) TestGenerate_ExpressionMap() { }, expressionTestCase{ val: exp.Ex{"a": exp.Op{"is": nil, "eq": 10}}, - sql: `(("a" = ?) OR ("a" IS NULL))`, + sql: `(("a" = ?) OR ("a" IS ?))`, isPrepared: true, - args: []interface{}{int64(10)}, + args: []interface{}{int64(10), nil}, }, ) } @@ -1300,9 +1300,9 @@ func (esgs *expressionSQLGeneratorSuite) TestGenerate_ExpressionOrMap() { expressionTestCase{val: exp.ExOr{"a": 1, "b": true}, sql: `(("a" = 1) OR ("b" IS TRUE))`}, expressionTestCase{ val: exp.ExOr{"a": 1, "b": true}, - sql: `(("a" = ?) OR ("b" IS TRUE))`, + sql: `(("a" = ?) OR ("b" IS ?))`, isPrepared: true, - args: []interface{}{int64(1)}, + args: []interface{}{int64(1), true}, }, expressionTestCase{ diff --git a/sqlgen/insert_sql_generator_test.go b/sqlgen/insert_sql_generator_test.go index 7ca423ec..9126d881 100644 --- a/sqlgen/insert_sql_generator_test.go +++ b/sqlgen/insert_sql_generator_test.go @@ -89,7 +89,7 @@ func (igs *insertSQLGeneratorSuite) TestGenerate_nilValues() { igs.assertCases( NewInsertSQLGenerator("test", DefaultDialectOptions()), insertTestCase{clause: ic, sql: `INSERT INTO "test" ("a") VALUES (NULL)`}, - insertTestCase{clause: ic, sql: `INSERT INTO "test" ("a") VALUES (NULL)`, isPrepared: true}, + insertTestCase{clause: ic, sql: `INSERT INTO "test" ("a") VALUES (?)`, isPrepared: true, args: []interface{}{nil}}, ) } @@ -295,9 +295,9 @@ func (igs *insertSQLGeneratorSuite) TestGenerate_onConflict() { }, insertTestCase{ clause: icDuw, - sql: `INSERT INTO "test" ("a") VALUES (?) on conflict (test) do update set "a"=? WHERE ("foo" IS TRUE)`, + sql: `INSERT INTO "test" ("a") VALUES (?) on conflict (test) do update set "a"=? WHERE ("foo" IS ?)`, isPrepared: true, - args: []interface{}{"a1", "b"}, + args: []interface{}{"a1", "b", true}, }, insertTestCase{clause: icDuNil, err: errConflictUpdateValuesRequired.Error()}, @@ -345,9 +345,9 @@ func (igs *insertSQLGeneratorSuite) TestGenerate_onConflict() { }, insertTestCase{ clause: icDuw, - sql: `insert ignore into "test" ("a") VALUES (?) on conflict (test) do update set "a"=? WHERE ("foo" IS TRUE)`, + sql: `insert ignore into "test" ("a") VALUES (?) on conflict (test) do update set "a"=? WHERE ("foo" IS ?)`, isPrepared: true, - args: []interface{}{"a1", "b"}, + args: []interface{}{"a1", "b", true}, }, insertTestCase{clause: icDuNil, err: errConflictUpdateValuesRequired.Error()}, diff --git a/update_dataset_example_test.go b/update_dataset_example_test.go index 6015ecc6..0d9eae87 100644 --- a/update_dataset_example_test.go +++ b/update_dataset_example_test.go @@ -384,11 +384,11 @@ func ExampleUpdateDataset_Where_prepared() { ).ToSQL() fmt.Println(sql, args) // Output: - // UPDATE "test" SET "foo"=? WHERE (("a" > ?) AND ("b" < ?) AND ("c" IS NULL) AND ("d" IN (?, ?, ?))) [bar 10 10 a b c] - // UPDATE "test" SET "foo"=? WHERE (("a" > ?) OR ("b" < ?) OR ("c" IS NULL) OR ("d" IN (?, ?, ?))) [bar 10 10 a b c] - // UPDATE "test" SET "foo"=? WHERE ((("a" > ?) AND ("b" < ?)) OR (("c" IS NULL) AND ("d" IN (?, ?, ?)))) [bar 10 10 a b c] - // UPDATE "test" SET "foo"=? WHERE (("a" > ?) AND ("b" < ?) AND ("c" IS NULL) AND ("d" IN (?, ?, ?))) [bar 10 10 a b c] - // UPDATE "test" SET "foo"=? WHERE (("a" > ?) OR (("b" < ?) AND ("c" IS NULL))) [bar 10 10] + // UPDATE "test" SET "foo"=? WHERE (("a" > ?) AND ("b" < ?) AND ("c" IS ?) AND ("d" IN (?, ?, ?))) [bar 10 10 a b c] + // UPDATE "test" SET "foo"=? WHERE (("a" > ?) OR ("b" < ?) OR ("c" IS ?) OR ("d" IN (?, ?, ?))) [bar 10 10 a b c] + // UPDATE "test" SET "foo"=? WHERE ((("a" > ?) AND ("b" < ?)) OR (("c" IS ?) AND ("d" IN (?, ?, ?)))) [bar 10 10 a b c] + // UPDATE "test" SET "foo"=? WHERE (("a" > ?) AND ("b" < ?) AND ("c" IS ?) AND ("d" IN (?, ?, ?))) [bar 10 10 a b c] + // UPDATE "test" SET "foo"=? WHERE (("a" > ?) OR (("b" < ?) AND ("c" IS ?))) [bar 10 10 ] } func ExampleUpdateDataset_ClearWhere() { diff --git a/update_dataset_test.go b/update_dataset_test.go index 61893314..eb8c48f1 100644 --- a/update_dataset_test.go +++ b/update_dataset_test.go @@ -432,8 +432,8 @@ func (uds *updateDatasetSuite) TestExecutor() { updateSQL, args, err = ds.Prepared(true).Executor().ToSQL() uds.NoError(err) - uds.Equal([]interface{}{"111 Test Addr", "Test1"}, args) - uds.Equal(`UPDATE "items" SET "address"=?,"name"=? WHERE ("name" IS NULL)`, updateSQL) + uds.Equal([]interface{}{"111 Test Addr", "Test1", nil}, args) + uds.Equal(`UPDATE "items" SET "address"=?,"name"=? WHERE ("name" IS ?)`, updateSQL) } func (uds *updateDatasetSuite) TestSetError() {