Skip to content

Commit

Permalink
Merge pull request #158 from doug-martin/null_literals_simple
Browse files Browse the repository at this point in the history
#132 - do not interpolate nil or boolean values
  • Loading branch information
doug-martin committed Sep 17, 2019
2 parents 67f00a5 + ae574f4 commit 8ee27de
Show file tree
Hide file tree
Showing 8 changed files with 70 additions and 66 deletions.
10 changes: 5 additions & 5 deletions delete_dataset_example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 <nil> a b c]
// DELETE FROM "test" WHERE (("a" > ?) OR ("b" < ?) OR ("c" IS ?) OR ("d" IN (?, ?, ?))) [10 10 <nil> a b c]
// DELETE FROM "test" WHERE ((("a" > ?) AND ("b" < ?)) OR (("c" IS ?) AND ("d" IN (?, ?, ?)))) [10 10 <nil> a b c]
// DELETE FROM "test" WHERE (("a" > ?) AND ("b" < ?) AND ("c" IS ?) AND ("d" IN (?, ?, ?))) [10 10 <nil> a b c]
// DELETE FROM "test" WHERE (("a" > ?) OR (("b" < ?) AND ("c" IS ?))) [10 10 <nil>]
}

func ExampleDeleteDataset_ClearWhere() {
Expand Down
36 changes: 18 additions & 18 deletions expressions_example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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() {
Expand Down Expand Up @@ -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) <nil>]
}

func ExampleC_as() {
Expand Down Expand Up @@ -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 <nil>]
}

func ExampleCOALESCE_as() {
Expand Down Expand Up @@ -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 <nil>]
}

func ExampleFIRST() {
Expand Down Expand Up @@ -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 <nil> foo]
}

func ExampleRange_numbers() {
Expand Down Expand Up @@ -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 <nil> a b c]
}

func ExampleEx_withOp() {
Expand Down Expand Up @@ -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 ?) [<nil>]
// 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 ?) [<nil>]
// 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 ?) [<nil>]
}

func ExampleOp_betweenComparisons() {
Expand Down Expand Up @@ -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 <nil>]
}

func ExampleRecord_insert() {
Expand Down
10 changes: 5 additions & 5 deletions select_dataset_example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 <nil> a b c]
// SELECT * FROM "test" WHERE (("a" > ?) OR ("b" < ?) OR ("c" IS ?) OR ("d" IN (?, ?, ?))) [10 10 <nil> a b c]
// SELECT * FROM "test" WHERE ((("a" > ?) AND ("b" < ?)) OR (("c" IS ?) AND ("d" IN (?, ?, ?)))) [10 10 <nil> a b c]
// SELECT * FROM "test" WHERE (("a" > ?) AND ("b" < ?) AND ("c" IS ?) AND ("d" IN (?, ?, ?))) [10 10 <nil> a b c]
// SELECT * FROM "test" WHERE (("a" > ?) OR (("b" < ?) AND ("c" IS ?))) [10 10 <nil>]
}

func ExampleSelectDataset_ClearWhere() {
Expand Down
6 changes: 5 additions & 1 deletion sqlgen/expression_sql_generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down Expand Up @@ -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 {
Expand Down
50 changes: 25 additions & 25 deletions sqlgen/expression_sql_generator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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}},
)
}

Expand Down Expand Up @@ -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"},
},
)
}
Expand Down Expand Up @@ -258,15 +258,15 @@ 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}},
)
}

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}},
)
}

Expand Down Expand Up @@ -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{}{
Expand All @@ -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{}{
Expand All @@ -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)}},
Expand Down Expand Up @@ -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{
Expand All @@ -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{}{
Expand Down Expand Up @@ -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},
},
)
}
Expand All @@ -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{
Expand Down
10 changes: 5 additions & 5 deletions sqlgen/insert_sql_generator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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}},
)
}

Expand Down Expand Up @@ -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()},
Expand Down Expand Up @@ -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()},
Expand Down
10 changes: 5 additions & 5 deletions update_dataset_example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 <nil> a b c]
// UPDATE "test" SET "foo"=? WHERE (("a" > ?) OR ("b" < ?) OR ("c" IS ?) OR ("d" IN (?, ?, ?))) [bar 10 10 <nil> a b c]
// UPDATE "test" SET "foo"=? WHERE ((("a" > ?) AND ("b" < ?)) OR (("c" IS ?) AND ("d" IN (?, ?, ?)))) [bar 10 10 <nil> a b c]
// UPDATE "test" SET "foo"=? WHERE (("a" > ?) AND ("b" < ?) AND ("c" IS ?) AND ("d" IN (?, ?, ?))) [bar 10 10 <nil> a b c]
// UPDATE "test" SET "foo"=? WHERE (("a" > ?) OR (("b" < ?) AND ("c" IS ?))) [bar 10 10 <nil>]
}

func ExampleUpdateDataset_ClearWhere() {
Expand Down

0 comments on commit 8ee27de

Please sign in to comment.