Fixed bug where '@' was incorrectly identified as a named variable in `'`or`"`

This commit is contained in:
rankgice 2024-09-25 21:03:49 +08:00
parent 68434b76eb
commit c930baab81
1 changed files with 9 additions and 0 deletions

View File

@ -88,6 +88,7 @@ func (expr NamedExpr) Build(builder Builder) {
inName bool
afterParenthesis bool
namedMap = make(map[string]interface{}, len(expr.Vars))
quotationMarks byte
)
for _, v := range expr.Vars {
@ -124,6 +125,14 @@ func (expr NamedExpr) Build(builder Builder) {
name := make([]byte, 0, 10)
for _, v := range []byte(expr.SQL) {
if quotationMarks == v && (v == '"' || v == '\'') {
quotationMarks = 0
} else if quotationMarks == 0 && (v == '"' || v == '\'') {
quotationMarks = v
} else if quotationMarks == '"' || quotationMarks == '\'' {
builder.WriteByte(v)
continue
}
if v == '@' && !inName {
inName = true
name = name[:0]