Skip to content

Commit

Permalink
fix: allow INSERT statements with SELECT notation
Browse files Browse the repository at this point in the history
  • Loading branch information
zurchpet committed Oct 7, 2024
1 parent 9849923 commit 5f9c8cf
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -702,6 +702,7 @@ def get_raw_table_name(sql)
s.split(/INSERT INTO/i)[1]
.split(/OUTPUT INSERTED/i)[0]
.split(/(DEFAULT)?\s+VALUES/i)[0]
.split(/SELECT/i)[0]
.match(/\s*([^(]*)/i)[0]
elsif s.match?(/^\s*UPDATE\s+.*/i)
s.match(/UPDATE\s+([^\(\s]+)\s*/i)[1]
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 @@ -96,6 +96,10 @@ class SchemaTestSQLServer < ActiveRecord::TestCase
it do
assert_equal "[test].[aliens]", connection.send(:get_raw_table_name, "EXEC sp_executesql N'INSERT INTO [test].[aliens] ([name]) OUTPUT INSERTED.[id] VALUES (@0)', N'@0 varchar(255)', @0 = 'Trisolarans'")
end

it do
assert_equal "[with].[select notation]", connection.send(:get_raw_table_name, "INSERT INTO [with].[select notation] SELECT * FROM [table_name]")
end
end
end
end

0 comments on commit 5f9c8cf

Please sign in to comment.