Skip to content

Commit

Permalink
Fix parsing of raw table name from SQL with extra parentheses
Browse files Browse the repository at this point in the history
  • Loading branch information
aidanharan committed Dec 12, 2024
1 parent a1bc145 commit 1d1ea09
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -711,7 +711,7 @@ def get_raw_table_name(sql)
elsif s.match?(/^\s*UPDATE\s+.*/i)
s.match(/UPDATE\s+([^\(\s]+)\s*/i)[1]
else
s.match(/FROM\s+((\[[^\(\]]+\])|[^\(\s]+)\s*/i)[1]
s.match(/FROM[\s|\(]+((\[[^\(\]]+\])|[^\(\s]+)\s*/i)[1]
end.strip
end

Expand Down
6 changes: 6 additions & 0 deletions test/cases/schema_test_sqlserver.rb
Original file line number Diff line number Diff line change
Expand Up @@ -101,5 +101,11 @@ class SchemaTestSQLServer < ActiveRecord::TestCase
assert_equal "[with].[select notation]", connection.send(:get_raw_table_name, "INSERT INTO [with].[select notation] SELECT * FROM [table_name]")
end
end

describe 'CREATE VIEW statements' do
it do
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))")
end
end
end
end

0 comments on commit 1d1ea09

Please sign in to comment.