diff --git a/sqlgen/expression_sql_generator.go b/sqlgen/expression_sql_generator.go index 82ce15c5..fdc02893 100644 --- a/sqlgen/expression_sql_generator.go +++ b/sqlgen/expression_sql_generator.go @@ -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)) } } diff --git a/sqlgen/expression_sql_generator_test.go b/sqlgen/expression_sql_generator_test.go index ed75e12f..e5c057eb 100644 --- a/sqlgen/expression_sql_generator_test.go +++ b/sqlgen/expression_sql_generator_test.go @@ -123,12 +123,12 @@ func (esgs *expressionSQLGeneratorSuite) TestGenerate_Invalid() { ) } -func (esgs *expressionSQLGeneratorSuite) TestGenerate_UnsupportedType() { +func (esgs *expressionSQLGeneratorSuite) TestGenerate_OtherType() { type strct 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: strct{}, sql: "?", isPrepared: true, args: []interface{}{strct{}}}, ) }