fix (clause/expression): Allow sql stmt terminator (#4693)

Allow the sql stmt terminator ";" at the end of a named parameter.

Example: select * from table_name where name == @name;
This commit is contained in:
Jim 2021-09-20 09:40:48 -04:00 committed by GitHub
parent 199c8529b6
commit 5202529ea1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 1 deletions

View File

@ -121,7 +121,7 @@ func (expr NamedExpr) Build(builder Builder) {
if v == '@' && !inName {
inName = true
name = []byte{}
} else if v == ' ' || v == ',' || v == ')' || v == '"' || v == '\'' || v == '`' || v == '\n' {
} else if v == ' ' || v == ',' || v == ')' || v == '"' || v == '\'' || v == '`' || v == '\n' || v == ';' {
if inName {
if nv, ok := namedMap[string(name)]; ok {
builder.AddVar(builder, nv)

View File

@ -89,6 +89,11 @@ func TestNamedExpr(t *testing.T) {
SQL: "create table ? (? ?, ? ?)",
Vars: []interface{}{},
Result: "create table ? (? ?, ? ?)",
}, {
SQL: "name1 = @name AND name2 = @name;",
Vars: []interface{}{sql.Named("name", "jinzhu")},
Result: "name1 = ? AND name2 = ?;",
ExpectedVars: []interface{}{"jinzhu", "jinzhu"},
}}
for idx, result := range results {