mirror of https://github.com/go-gorm/gorm.git
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:
parent
199c8529b6
commit
5202529ea1
|
@ -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)
|
||||
|
|
|
@ -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 {
|
||||
|
|
Loading…
Reference in New Issue