Skip to content

Commit 1015a6d

Browse files
authored
Fix insert_all/upsert_all for table names containing numbers (#1339)
1 parent c2964ce commit 1015a6d

File tree

3 files changed

+6
-1
lines changed

3 files changed

+6
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#### Fixed
44

55
- [#1334](https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/pull/1334) Enable identity insert on view's base table for fixtures.
6+
- [#1339](https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/pull/1339) Fix `insert_all`/`upsert_all` for table names containing numbers.
67

78
## v8.0.6
89

lib/active_record/connection_adapters/sqlserver/schema_statements.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -721,7 +721,7 @@ def get_raw_table_name(sql)
721721
elsif s.match?(/^\s*UPDATE\s+.*/i)
722722
s.match(/UPDATE\s+([^\(\s]+)\s*/i)[1]
723723
elsif s.match?(/^\s*MERGE INTO.*/i)
724-
s.match(/^\s*MERGE\s+INTO\s+(\[?[a-z_ -]+\]?\.?\[?[a-z_ -]+\]?)\s+(AS|WITH|USING)/i)[1]
724+
s.match(/^\s*MERGE\s+INTO\s+(\[?[a-z0-9_ -]+\]?\.?\[?[a-z0-9_ -]+\]?)\s+(AS|WITH|USING)/i)[1]
725725
else
726726
s.match(/FROM[\s|\(]+((\[[^\(\]]+\])|[^\(\s]+)\s*/i)[1]
727727
end.strip

test/cases/schema_test_sqlserver.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,10 @@ class SchemaTestSQLServer < ActiveRecord::TestCase
118118
it do
119119
assert_equal "[with].[select notation]", connection.send(:get_raw_table_name, "MERGE INTO [with].[select notation] AS target")
120120
end
121+
122+
it do
123+
assert_equal "[with_numbers_1234]", connection.send(:get_raw_table_name, "MERGE INTO [with_numbers_1234] AS target")
124+
end
121125
end
122126

123127
describe 'CREATE VIEW statements' do

0 commit comments

Comments
 (0)