Skip to content

Commit a5837e2

Browse files
authored
Merge pull request #877 from yahonda/rails5_raw
Support RAW sql data type in Rails 5
2 parents d2b0a47 + d2ac636 commit a5837e2

File tree

3 files changed

+11
-16
lines changed

3 files changed

+11
-16
lines changed

lib/active_record/connection_adapters/oracle_enhanced/quoting.rb

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -115,18 +115,6 @@ def quote_date_with_to_date(value) #:nodoc:
115115
"TO_DATE('#{value}','YYYY-MM-DD HH24:MI:SS')"
116116
end
117117

118-
# Encode a string or byte array as string of hex codes
119-
def self.encode_raw(value)
120-
# When given a string, convert to a byte array.
121-
value = value.unpack('C*') if value.is_a?(String)
122-
value.map { |x| "%02X" % x }.join
123-
end
124-
125-
# quote encoded raw value
126-
def quote_raw(value) #:nodoc:
127-
"'#{self.class.encode_raw(value)}'"
128-
end
129-
130118
def quote_timestamp_with_to_timestamp(value) #:nodoc:
131119
# add up to 9 digits of fractional seconds to inserted time
132120
value = "#{quoted_date(value)}" if value.acts_like?(:time)

lib/active_record/connection_adapters/oracle_enhanced/schema_definitions.rb

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,6 @@ def initialize(name, temporary = false, options = nil, as = nil, tablespace = ni
4848
super(name, temporary, options, as, comment: comment)
4949
end
5050

51-
def raw(name, options={})
52-
column(name, :raw, options)
53-
end
54-
5551
def virtual(* args)
5652
options = args.extract_options!
5753
column_names = args

lib/active_record/oracle_enhanced/type/raw.rb

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,17 @@ class Raw < ActiveModel::Type::String # :nodoc:
88
def type
99
:raw
1010
end
11+
12+
def serialize(value)
13+
# Encode a string or byte array as string of hex codes
14+
if value.nil?
15+
super
16+
else
17+
value = value.unpack('C*')
18+
value.map { |x| "%02X" % x }.join
19+
end
20+
end
21+
1122
end
1223
end
1324
end

0 commit comments

Comments
 (0)