Skip to content

Commit a35835a

Browse files
committed
Avoiding N'' quoting on char/varchar columns.
1 parent 1b1cd76 commit a35835a

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

lib/active_record/connection_adapters/sqlserver/type/char.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,12 @@ def type
88
:char
99
end
1010

11+
def type_cast_for_database(value)
12+
return if value.nil?
13+
return value if value.is_a?(Data)
14+
Data.new(super)
15+
end
16+
1117
class Data
1218

1319
def initialize(value)

test/cases/specific_schema_test_sqlserver.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,9 @@ def quoted_id
120120
data = ActiveRecord::Type::SQLServer::Char::Data
121121
assert_sql(/@0 = 'T'/) { SSTestDatatypeMigration.where(char_col: data.new('T')).first }
122122
assert_sql(/@0 = 'T'/) { SSTestDatatypeMigration.where(varchar_col: data.new('T')).first }
123+
# Taking care of everything.
124+
assert_sql(/@0 = 'T'/) { SSTestDatatypeMigration.where(char_col: 'T').first }
125+
assert_sql(/@0 = 'T'/) { SSTestDatatypeMigration.where(varchar_col: 'T').first }
123126
end
124127

125128
# With column names that have spaces

0 commit comments

Comments
 (0)