Skip to content

Commit 01f59c2

Browse files
committed
Handle blank SQL when parsing table name (#1210)
1 parent 4b8da98 commit 01f59c2

File tree

2 files changed

+6
-0
lines changed

2 files changed

+6
-0
lines changed

lib/active_record/connection_adapters/sqlserver/schema_statements.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -673,6 +673,8 @@ def get_table_name(sql)
673673

674674
# Parses the raw table name that is used in the SQL. Table name could include database/schema/etc.
675675
def get_raw_table_name(sql)
676+
return if sql.blank?
677+
676678
s = sql.gsub(/^\s*EXEC sp_executesql N'/i, "")
677679

678680
if s.match?(/^\s*INSERT INTO.*/i)

test/cases/schema_test_sqlserver.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,10 @@ class SchemaTestSQLServer < ActiveRecord::TestCase
6666
it do
6767
assert_equal "[WITH - SPACES$DOLLAR]", connection.send(:get_raw_table_name, "SELECT id FROM [WITH - SPACES$DOLLAR]")
6868
end
69+
70+
it do
71+
assert_nil connection.send(:get_raw_table_name, nil)
72+
end
6973
end
7074

7175
describe 'INSERT statements' do

0 commit comments

Comments
 (0)