Skip to content

Commit 6fddb9a

Browse files
authored
Handle blank SQL when parsing table name (#1210)
1 parent 3699f2f commit 6fddb9a

File tree

3 files changed

+12
-0
lines changed

3 files changed

+12
-0
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
## Unreleased
2+
3+
#### Fixed
4+
5+
- [#1210](https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/pull/1210) Handle blank SQL when parsing table name
6+
17
## v7.1.6
28

39
#### Fixed

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)