From a70af2a4c0d7bd66d76999f142a9babb438e53d7 Mon Sep 17 00:00:00 2001 From: Jinzhu Date: Mon, 20 Jun 2022 15:35:29 +0800 Subject: [PATCH] Fix Select with digits in column name --- statement.go | 2 +- statement_test.go | 12 ++++++++---- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/statement.go b/statement.go index ed3e8716..850af6cb 100644 --- a/statement.go +++ b/statement.go @@ -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) { diff --git a/statement_test.go b/statement_test.go index 3f099d61..a89cc7d2 100644 --- a/statement_test.go +++ b/statement_test.go @@ -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)