[BUG] Update statement reserved word not escaped

Update statement, using MODEL struct, now generates escaped SQL identifier if column name is reserved word.
This commit is contained in:
go-jet 2021-05-09 17:17:14 +02:00
parent 063b17ca05
commit 256be8a406
3 changed files with 41 additions and 12 deletions

View file

@ -2,6 +2,7 @@ package mysql
import (
"fmt"
"strings"
"testing"
)
@ -52,11 +53,29 @@ WHERE table1.col1 = ?;
).
WHERE(table1Col1.EQ(Int(2)))
//fmt.Println(stmt.Sql())
assertStatementSql(t, stmt, expectedSQL, int64(2))
}
func TestUpdateReservedWorldColumn(t *testing.T) {
type table struct {
Load string
}
loadColumn := StringColumn("Load")
assertStatementSql(t,
table1.UPDATE(loadColumn).
MODEL(
table{
Load: "foo",
},
).
WHERE(loadColumn.EQ(String("bar"))), strings.Replace(`
UPDATE db.table1
SET ''Load'' = ?
WHERE ''Load'' = ?;
`, "''", "`", -1), "foo", "bar")
}
func TestInvalidInputs(t *testing.T) {
assertStatementSqlErr(t, table1.UPDATE(table1ColInt).SET(1), "jet: WHERE clause not set")
assertStatementSqlErr(t, table1.UPDATE(nil).SET(1), "jet: nil column in columns list for SET clause")