Skip to content

Commit

Permalink
Handle blank SQL when parsing table name (#1210)
Browse files Browse the repository at this point in the history
  • Loading branch information
aidanharan committed Aug 1, 2024
1 parent 4b8da98 commit 01f59c2
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -673,6 +673,8 @@ def get_table_name(sql)

# Parses the raw table name that is used in the SQL. Table name could include database/schema/etc.
def get_raw_table_name(sql)
return if sql.blank?

s = sql.gsub(/^\s*EXEC sp_executesql N'/i, "")

if s.match?(/^\s*INSERT INTO.*/i)
Expand Down
4 changes: 4 additions & 0 deletions test/cases/schema_test_sqlserver.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ class SchemaTestSQLServer < ActiveRecord::TestCase
it do
assert_equal "[WITH - SPACES$DOLLAR]", connection.send(:get_raw_table_name, "SELECT id FROM [WITH - SPACES$DOLLAR]")
end

it do
assert_nil connection.send(:get_raw_table_name, nil)
end
end

describe 'INSERT statements' do
Expand Down

0 comments on commit 01f59c2

Please sign in to comment.