File tree Expand file tree Collapse file tree 5 files changed +22
-1
lines changed
lib/active_record/connection_adapters/sqlserver Expand file tree Collapse file tree 5 files changed +22
-1
lines changed Original file line number Diff line number Diff line change 11
22* master *
33
4+ * Properly quote table names when reflecting on views.
5+
46* Add "dead or not enabled" to :dblib's lost connection messages.
57
68
Original file line number Diff line number Diff line change @@ -305,7 +305,7 @@ def view_information(table_name)
305305 if view_info
306306 view_info = view_info . with_indifferent_access
307307 if view_info [ :VIEW_DEFINITION ] . blank? || view_info [ :VIEW_DEFINITION ] . length == 4000
308- view_info [ :VIEW_DEFINITION ] = info_schema_query { select_values ( "EXEC sp_helptext #{ table_name } " ) . join }
308+ view_info [ :VIEW_DEFINITION ] = info_schema_query { select_values ( "EXEC sp_helptext #{ quote_table_name ( table_name ) } " ) . join }
309309 end
310310 end
311311 view_info
Original file line number Diff line number Diff line change @@ -13,6 +13,15 @@ def set_new_id
1313
1414class SpecificSchemaTestSqlserver < ActiveRecord ::TestCase
1515
16+ should 'quote table names properly even when they are views' do
17+ obj = SqlServerQuotedTable . create!
18+ assert_nothing_raised { SqlServerQuotedTable . first }
19+ obj = SqlServerQuotedView1 . create!
20+ assert_nothing_raised { SqlServerQuotedView1 . first }
21+ obj = SqlServerQuotedView2 . create!
22+ assert_nothing_raised { SqlServerQuotedView2 . first }
23+ end
24+
1625 should 'cope with multi line defaults' do
1726 default = StringDefault . new
1827 assert_equal "Some long default with a\n new line." , default . string_with_multiline_default
Original file line number Diff line number Diff line change @@ -33,6 +33,9 @@ class NumericData < ActiveRecord::Base ; self.table_name = 'numeric_data' ; end
3333class CustomersView < ActiveRecord ::Base ; self . table_name = 'customers_view' ; end
3434class StringDefaultsView < ActiveRecord ::Base ; self . table_name = 'string_defaults_view' ; end
3535class StringDefaultsBigView < ActiveRecord ::Base ; self . table_name = 'string_defaults_big_view' ; end
36+ class SqlServerQuotedTable < ActiveRecord ::Base ; self . table_name = 'quoted-table' ; end
37+ class SqlServerQuotedView1 < ActiveRecord ::Base ; self . table_name = 'quoted-view1' ; end
38+ class SqlServerQuotedView2 < ActiveRecord ::Base ; self . table_name = 'quoted-view2' ; end
3639class SqlServerUnicode < ActiveRecord ::Base ; end
3740class SqlServerString < ActiveRecord ::Base ; end
3841class SqlServerChronic < ActiveRecord ::Base
Original file line number Diff line number Diff line change 7070 execute %|ALTER TABLE [sql_server_edge_schemas] ADD [guid_newid] uniqueidentifier DEFAULT NEWID();|
7171 execute %|ALTER TABLE [sql_server_edge_schemas] ADD [guid_newseqid] uniqueidentifier DEFAULT NEWSEQUENTIALID();|
7272
73+ create_table 'quoted-table' , :force => true do |t |
74+ end
75+ execute "IF EXISTS (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME = 'quoted-view1') DROP VIEW [quoted-view1]"
76+ execute "CREATE VIEW [quoted-view1] AS SELECT * FROM [quoted-table]"
77+ execute "IF EXISTS (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME = 'quoted-view2') DROP VIEW [quoted-view2]"
78+ execute "CREATE VIEW [quoted-view2] AS \n /*#{ 'x' *4000 } }*/ \n SELECT * FROM [quoted-table]"
79+
7380 execute "IF EXISTS (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME = 'customers_view') DROP VIEW customers_view"
7481 execute <<-CUSTOMERSVIEW
7582 CREATE VIEW customers_view AS
You can’t perform that action at this time.
0 commit comments