Skip to content

Handle blank SQL when parsing table name #1210

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Aug 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## Unreleased

#### Fixed

- [#1210](https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/pull/1210) Handle blank SQL when parsing table name

## v7.1.6

#### Fixed
Expand Down
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
Loading