Skip to content

Commit

Permalink
feat(sqlgen): allow any type of value for prepared mode
Browse files Browse the repository at this point in the history
  • Loading branch information
yz89122 committed Nov 27, 2021
1 parent 31d438d commit 59c7b05
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
7 changes: 7 additions & 0 deletions sqlgen/expression_sql_generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,13 @@ func (esg *expressionSQLGenerator) reflectSQL(b sb.SQLBuilder, val interface{})
case util.IsBool(valKind):
esg.Generate(b, v.Bool())
default:
// allow any type of value for prepared mode
if b.IsPrepared() {
esg.placeHolderSQL(b, val)

return
}

b.SetError(errors.NewEncodeError(val))
}
}
Expand Down
8 changes: 4 additions & 4 deletions sqlgen/expression_sql_generator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,12 +123,12 @@ func (esgs *expressionSQLGeneratorSuite) TestGenerate_Invalid() {
)
}

func (esgs *expressionSQLGeneratorSuite) TestGenerate_UnsupportedType() {
type strct struct{}
func (esgs *expressionSQLGeneratorSuite) TestGenerate_OtherType() {
val := struct{}{}
esgs.assertCases(
sqlgen.NewExpressionSQLGenerator("test", sqlgen.DefaultDialectOptions()),
expressionTestCase{val: strct{}, err: "goqu_encode_error: Unable to encode value {}"},
expressionTestCase{val: strct{}, err: "goqu_encode_error: Unable to encode value {}", isPrepared: true},
expressionTestCase{val: val, err: "goqu_encode_error: Unable to encode value {}"},
expressionTestCase{val: val, sql: "?", isPrepared: true, args: []interface{}{val}},
)
}

Expand Down

0 comments on commit 59c7b05

Please sign in to comment.