Skip to content

Commit

Permalink
Fix Select with digits in column name
Browse files Browse the repository at this point in the history
  • Loading branch information
jinzhu committed Jun 20, 2022
1 parent 1305f63 commit a70af2a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
2 changes: 1 addition & 1 deletion statement.go
Original file line number Diff line number Diff line change
Expand Up @@ -650,7 +650,7 @@ func (stmt *Statement) Changed(fields ...string) bool {
return false
}

var nameMatcher = regexp.MustCompile(`^[\W]?(?:[a-z_]+?)[\W]?\.[\W]?([a-z_]+?)[\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
func (stmt *Statement) SelectAndOmitColumns(requireCreate, requireUpdate bool) (map[string]bool, bool) {
Expand Down
12 changes: 8 additions & 4 deletions statement_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,14 @@ func TestWhereCloneCorruption(t *testing.T) {

func TestNameMatcher(t *testing.T) {
for k, v := range map[string]string{
"table.name": "name",
"`table`.`name`": "name",
"'table'.'name'": "name",
"'table'.name": "name",
"table.name": "name",
"`table`.`name`": "name",
"'table'.'name'": "name",
"'table'.name": "name",
"table1.name_23": "name_23",
"`table_1`.`name23`": "name23",
"'table23'.'name_1'": "name_1",
"'table23'.name1": "name1",
} {
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)
Expand Down

0 comments on commit a70af2a

Please sign in to comment.