Skip to content

Commit 775b3c3

Browse files
committed
Proper table/column escaping in the change_column_null method. Fixes #355.
1 parent 169d79f commit 775b3c3

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#### Fixed
55

66
* Guard against empty view definitions when `sb_helptext` fails silently. Fixes #337.
7+
* Proper table/column escaping in the `change_column_null` method. Fixes #355.
78

89

910
## v4.2.0

lib/active_record/connection_adapters/sqlserver/schema_statements.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,11 +166,13 @@ def columns_for_distinct(columns, orders)
166166
end
167167

168168
def change_column_null(table_name, column_name, allow_null, default = nil)
169+
table_id = SQLServer::Utils.extract_identifiers(table_name)
170+
column_id = SQLServer::Utils.extract_identifiers(column_name)
169171
column = detect_column_for! table_name, column_name
170172
if !allow_null.nil? && allow_null == false && !default.nil?
171-
do_execute("UPDATE #{quote_table_name(table_name)} SET #{quote_column_name(column_name)}=#{quote(default)} WHERE #{quote_column_name(column_name)} IS NULL")
173+
do_execute("UPDATE #{table_id} SET #{column_id}=#{quote(default)} WHERE #{column_id} IS NULL")
172174
end
173-
sql = "ALTER TABLE #{table_name} ALTER COLUMN #{quote_column_name(column_name)} #{type_to_sql column.type, column.limit, column.precision, column.scale}"
175+
sql = "ALTER TABLE #{table_id} ALTER COLUMN #{column_id} #{type_to_sql column.type, column.limit, column.precision, column.scale}"
174176
sql << ' NOT NULL' if !allow_null.nil? && allow_null == false
175177
do_execute sql
176178
end

0 commit comments

Comments
 (0)