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 {
|
if v == '@' && !inName {
|
||||||
inName = true
|
inName = true
|
||||||
name = []byte{}
|
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 inName {
|
||||||
if nv, ok := namedMap[string(name)]; ok {
|
if nv, ok := namedMap[string(name)]; ok {
|
||||||
builder.AddVar(builder, nv)
|
builder.AddVar(builder, nv)
|
||||||
|
|
|
@ -89,6 +89,11 @@ func TestNamedExpr(t *testing.T) {
|
||||||
SQL: "create table ? (? ?, ? ?)",
|
SQL: "create table ? (? ?, ? ?)",
|
||||||
Vars: []interface{}{},
|
Vars: []interface{}{},
|
||||||
Result: "create table ? (? ?, ? ?)",
|
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 {
|
for idx, result := range results {
|
||||||
|
|
Loading…
Reference in New Issue