Skip to content

Commit b01b50b

Browse files
authored
Fix parsing of raw table name from SQL with extra parentheses (#1270)
1 parent 3c6cb72 commit b01b50b

File tree

3 files changed

+13
-1
lines changed

3 files changed

+13
-1
lines changed

CHANGELOG.md

+6
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
## Unreleased
2+
3+
#### Fixed
4+
5+
- [#1270](https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/pull/1270) Fix parsing of raw table name from SQL with extra parentheses
6+
17
## v7.2.3
28

39
#### Fixed

lib/active_record/connection_adapters/sqlserver/schema_statements.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -690,7 +690,7 @@ def get_raw_table_name(sql)
690690
elsif s.match?(/^\s*UPDATE\s+.*/i)
691691
s.match(/UPDATE\s+([^\(\s]+)\s*/i)[1]
692692
else
693-
s.match(/FROM\s+((\[[^\(\]]+\])|[^\(\s]+)\s*/i)[1]
693+
s.match(/FROM[\s|\(]+((\[[^\(\]]+\])|[^\(\s]+)\s*/i)[1]
694694
end.strip
695695
end
696696

test/cases/schema_test_sqlserver.rb

+6
Original file line numberDiff line numberDiff line change
@@ -101,5 +101,11 @@ class SchemaTestSQLServer < ActiveRecord::TestCase
101101
assert_equal "[with].[select notation]", connection.send(:get_raw_table_name, "INSERT INTO [with].[select notation] SELECT * FROM [table_name]")
102102
end
103103
end
104+
105+
describe 'CREATE VIEW statements' do
106+
it do
107+
assert_equal "test_table_as", connection.send(:get_raw_table_name, "CREATE VIEW test_views ( test_table_a_id, test_table_b_id ) AS SELECT test_table_as.id as test_table_a_id, test_table_bs.id as test_table_b_id FROM (test_table_as with(nolock) LEFT JOIN test_table_bs with(nolock) ON (test_table_as.id = test_table_bs.test_table_a_id))")
108+
end
109+
end
104110
end
105111
end

0 commit comments

Comments
 (0)