Fix select with quoted column name

This commit is contained in:
Jinzhu 2022-07-13 17:21:19 +08:00
parent 62fdc2bb3b
commit 08f6d06e47
2 changed files with 3 additions and 1 deletions

View File

@ -650,7 +650,7 @@ func (stmt *Statement) Changed(fields ...string) bool {
return false return false
} }
var nameMatcher = regexp.MustCompile(`^[\W]?(?:[a-z_0-9]+?)[\W]?\.[\W]?([a-z_0-9]+?)[\W]?$`) var nameMatcher = regexp.MustCompile(`^(?:[\W]?(?:[a-z_0-9]+?)[\W]?\.)?[\W]?([a-z_0-9]+?)[\W]?$`)
// SelectAndOmitColumns get select and omit columns, select -> true, omit -> false // SelectAndOmitColumns get select and omit columns, select -> true, omit -> false
func (stmt *Statement) SelectAndOmitColumns(requireCreate, requireUpdate bool) (map[string]bool, bool) { func (stmt *Statement) SelectAndOmitColumns(requireCreate, requireUpdate bool) (map[string]bool, bool) {

View File

@ -45,6 +45,8 @@ func TestNameMatcher(t *testing.T) {
"`table_1`.`name23`": "name23", "`table_1`.`name23`": "name23",
"'table23'.'name_1'": "name_1", "'table23'.'name_1'": "name_1",
"'table23'.name1": "name1", "'table23'.name1": "name1",
"'name1'": "name1",
"`name_1`": "name_1",
} { } {
if matches := nameMatcher.FindStringSubmatch(k); len(matches) < 2 || matches[1] != v { if matches := nameMatcher.FindStringSubmatch(k); len(matches) < 2 || matches[1] != v {
t.Errorf("failed to match value: %v, got %v, expect: %v", k, matches, v) t.Errorf("failed to match value: %v, got %v, expect: %v", k, matches, v)