1
+ # frozen_string_literal: true
2
+
1
3
module ActiveRecord
2
4
module ConnectionAdapters
3
5
module SQLServer
@@ -152,8 +154,9 @@ def change_column(table_name, column_name, type, options = {})
152
154
remove_indexes ( table_name , column_name )
153
155
end
154
156
sql_commands << "UPDATE #{ quote_table_name ( table_name ) } SET #{ quote_column_name ( column_name ) } =#{ quote_default_expression ( options [ :default ] , column_object ) } WHERE #{ quote_column_name ( column_name ) } IS NULL" if !options [ :null ] . nil? && options [ :null ] == false && !options [ :default ] . nil?
155
- sql_commands << "ALTER TABLE #{ quote_table_name ( table_name ) } ALTER COLUMN #{ quote_column_name ( column_name ) } #{ type_to_sql ( type , limit : options [ :limit ] , precision : options [ :precision ] , scale : options [ :scale ] ) } "
156
- sql_commands . last << ' NOT NULL' if !options [ :null ] . nil? && options [ :null ] == false
157
+ alter_command = "ALTER TABLE #{ quote_table_name ( table_name ) } ALTER COLUMN #{ quote_column_name ( column_name ) } #{ type_to_sql ( type , limit : options [ :limit ] , precision : options [ :precision ] , scale : options [ :scale ] ) } "
158
+ alter_command += ' NOT NULL' if !options [ :null ] . nil? && options [ :null ] == false
159
+ sql_commands << alter_command
157
160
if without_constraints
158
161
default = quote_default_expression ( default , column_object || column_for ( table_name , column_name ) )
159
162
sql_commands << "ALTER TABLE #{ quote_table_name ( table_name ) } ADD CONSTRAINT #{ default_constraint_name ( table_name , column_name ) } DEFAULT #{ default } FOR #{ quote_column_name ( column_name ) } "
@@ -267,7 +270,7 @@ def change_column_null(table_name, column_name, allow_null, default = nil)
267
270
do_execute ( "UPDATE #{ table_id } SET #{ column_id } =#{ quote ( default ) } WHERE #{ column_id } IS NULL" )
268
271
end
269
272
sql = "ALTER TABLE #{ table_id } ALTER COLUMN #{ column_id } #{ type_to_sql column . type , limit : column . limit , precision : column . precision , scale : column . scale } "
270
- sql << ' NOT NULL' if !allow_null . nil? && allow_null == false
273
+ sql += ' NOT NULL' if !allow_null . nil? && allow_null == false
271
274
do_execute sql
272
275
end
273
276
@@ -281,12 +284,12 @@ def data_source_sql(name = nil, type: nil)
281
284
scope = quoted_scope name , type : type
282
285
table_name = lowercase_schema_reflection_sql 'TABLE_NAME'
283
286
sql = "SELECT #{ table_name } "
284
- sql << ' FROM INFORMATION_SCHEMA.TABLES WITH (NOLOCK)'
285
- sql << ' WHERE TABLE_CATALOG = DB_NAME()'
286
- sql << " AND TABLE_SCHEMA = #{ quote ( scope [ :schema ] ) } "
287
- sql << " AND TABLE_NAME = #{ quote ( scope [ :name ] ) } " if scope [ :name ]
288
- sql << " AND TABLE_TYPE = #{ quote ( scope [ :type ] ) } " if scope [ :type ]
289
- sql << " ORDER BY #{ table_name } "
287
+ sql += ' FROM INFORMATION_SCHEMA.TABLES WITH (NOLOCK)'
288
+ sql += ' WHERE TABLE_CATALOG = DB_NAME()'
289
+ sql += " AND TABLE_SCHEMA = #{ quote ( scope [ :schema ] ) } "
290
+ sql += " AND TABLE_NAME = #{ quote ( scope [ :name ] ) } " if scope [ :name ]
291
+ sql += " AND TABLE_TYPE = #{ quote ( scope [ :type ] ) } " if scope [ :type ]
292
+ sql += " ORDER BY #{ table_name } "
290
293
sql
291
294
end
292
295
0 commit comments