Masterminds / squirrel

Fluent SQL generation for golang
Other
6.67k stars 458 forks source link

Where condition placeholder #363

Open dennissetiawan opened 12 months ago

dennissetiawan commented 12 months ago

I noticed something weird why can't we use ? in column name? sql, args, err := sb.Select("test").Where("y = ?", 2).ToSql() OK but sql, args, err := sb.Select("test").Where("? = ?","y", 2).ToSql() error

this also happens in sq.Expr

crjm commented 7 months ago

Hey! Encountered the same issue when passing two arguments to SelectBuilder.Where.

For example:

testQuery := sq.Select("test").
    From("test").
    Where("? = ?", 1, 2)

query, args, err := testQuery.ToSql()
fmt.Printf("query: %s\n", query)
fmt.Printf("args: %v\n", args)
query: SELECT test FROM test WHERE ? = ?
args: [1 2]

This is the error I get.

*errors.errorString have no arg for param ? at position 1

This doesn't happen with SelectBuilder.Having for example.

crjm commented 7 months ago

Turns out I was not passing args as a slice in the follow-up implementation. The issue was not related to this library. My bad!