Skip to content

Commit 1d1ea09

Browse files
committed
Fix parsing of raw table name from SQL with extra parentheses
1 parent a1bc145 commit 1d1ea09

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

lib/active_record/connection_adapters/sqlserver/schema_statements.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -711,7 +711,7 @@ def get_raw_table_name(sql)
711711
elsif s.match?(/^\s*UPDATE\s+.*/i)
712712
s.match(/UPDATE\s+([^\(\s]+)\s*/i)[1]
713713
else
714-
s.match(/FROM\s+((\[[^\(\]]+\])|[^\(\s]+)\s*/i)[1]
714+
s.match(/FROM[\s|\(]+((\[[^\(\]]+\])|[^\(\s]+)\s*/i)[1]
715715
end.strip
716716
end
717717

test/cases/schema_test_sqlserver.rb

Lines changed: 6 additions & 0 deletions
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)