Skip to content

Commit fff8892

Browse files
Sukeerthi Adiga GLalitha
Sukeerthi Adiga G
authored and
Lalitha
committed
Force data from a binary column type in SQLServer adapter to be treated as binary / ASCII-8Bit
- Added a check to make sure the object is String. ActiveRecord tests passes objects which are other than String. - Added a check to make sure we are not modifying the frozen object. There are tests which passes frozen objects.
1 parent 728377d commit fff8892

File tree

1 file changed

+8
-0
lines changed
  • lib/active_record/connection_adapters/sqlserver/type

1 file changed

+8
-0
lines changed

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,14 @@ module SQLServer
44
module Type
55
class Binary < ActiveRecord::Type::Binary
66

7+
def cast_value(value)
8+
if value.class.to_s == 'String' and !value.frozen?
9+
value.force_encoding(Encoding::BINARY) =~ /[^[:xdigit:]]/ ? value : [value].pack('H*')
10+
else
11+
value
12+
end
13+
end
14+
715
def type
816
:binary_basic
917
end

0 commit comments

Comments
 (0)