Closed jingyugao closed 5 years ago
It is a problem. The current workaround is adding a white space like you said. I'll fix it later. And contribution is welcome😆
@jingyugao In your case:
select {{name}},{{comment}},value from table
I want to know why your select fields are dynamic. Is there any use case that people can't set their select fields?
@jingyugao I found that
The markers in prepared statements are not allowed for identifiers (such as table or column names)
So can you execute select ? from table_a
?
The markers are legal only in certain places in SQL statements. For example, they are permitted in the VALUES() list of an INSERT statement (to specify column values for a row), or in a comparison with a column in a WHERE clause to specify a comparison value. However, they are not permitted for identifiers (such as table or column names), or to specify both operands of a binary operator such as the = equal sign. The latter restriction is necessary because it would be impossible to determine the parameter type. In general, parameters are legal only in Data Manipulation Language (DML) statements, and not in Data Definition Language (DDL) statements.
The marker is not identifiers. It is variable such as 1,"mysql" and so on.
`package main
import ( "fmt"
_ "github.com/go-sql-driver/mysql"
"github.com/jmoiron/sqlx"
)
func main() { db, err := sqlx.Connect("mysql", "root:@tcp(127.0.0.1:3306)/db0") if err != nil { panic(err) } id := []int64{} db.Select(&id, "select ? from table0", 2) fmt.Println(id) }`
190701 8:30:32 4 Connect root@172.20.0.1 on db0 4 Prepare select ? from table 4 Execute select 2 from table 4 Close stmt
this is the mysql log
Ok,明天上午之前修复这个问题
@jingyugao fixed, see the latest release
https://github.com/didi/gendry/blob/master/builder/builder.go#L394 this regex is greedy. It should be non-greedy. for example, "select {{name}},{{comment}},value from table" In mysql, this is ok. but gendry will parser it as "name}},{{comment". I must insert an space between }} and {{ .