Masterminds / squirrel

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

ToSQL placeholders no longer compatible with MySQL 8 #368

Closed pidgezero-one closed 9 months ago

pidgezero-one commented 9 months ago

From the MySQL changelog:

The use of the dollar sign ($) as the initial character of an unquoted identifier was deprecated in MySQL 8.0.32. In this release, the use of an unquoted identifier starting with the dollar sign and containing one or more dollar signs in addition to the first one generates a syntax error.

This means that code such as this:

    q, args, err = sq.Select("col1", "col2", "col3").
        From("tablename").
        Where(sq.Eq{"col1": someArray}).
        ToSql()

which produces a query like this:

SELECT col1, col2, col3 FROM tablename WHERE col1 IN ($1,$2)

produces an error when using the query and args in methods like sqlx.DB.SelectContext:

"Error 1054 (42S22): Unknown column '$1' in 'where clause'"
pidgezero-one commented 9 months ago

Closing this because I didn't know about PlaceholderFormat