diff --git a/clause/expression.go b/clause/expression.go index f7b93f4c..e914b7b3 100644 --- a/clause/expression.go +++ b/clause/expression.go @@ -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) diff --git a/clause/expression_test.go b/clause/expression_test.go index 05074865..eadd96ea 100644 --- a/clause/expression_test.go +++ b/clause/expression_test.go @@ -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 {