Skip to content

Commit

Permalink
Merge pull request #877 from yahonda/rails5_raw
Browse files Browse the repository at this point in the history
Support RAW sql data type in Rails 5
  • Loading branch information
yahonda authored Jun 28, 2016
2 parents d2b0a47 + d2ac636 commit a5837e2
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 16 deletions.
12 changes: 0 additions & 12 deletions lib/active_record/connection_adapters/oracle_enhanced/quoting.rb
Original file line number Diff line number Diff line change
Expand Up @@ -115,18 +115,6 @@ def quote_date_with_to_date(value) #:nodoc:
"TO_DATE('#{value}','YYYY-MM-DD HH24:MI:SS')"
end

# Encode a string or byte array as string of hex codes
def self.encode_raw(value)
# When given a string, convert to a byte array.
value = value.unpack('C*') if value.is_a?(String)
value.map { |x| "%02X" % x }.join
end

# quote encoded raw value
def quote_raw(value) #:nodoc:
"'#{self.class.encode_raw(value)}'"
end

def quote_timestamp_with_to_timestamp(value) #:nodoc:
# add up to 9 digits of fractional seconds to inserted time
value = "#{quoted_date(value)}" if value.acts_like?(:time)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,6 @@ def initialize(name, temporary = false, options = nil, as = nil, tablespace = ni
super(name, temporary, options, as, comment: comment)
end

def raw(name, options={})
column(name, :raw, options)
end

def virtual(* args)
options = args.extract_options!
column_names = args
Expand Down
11 changes: 11 additions & 0 deletions lib/active_record/oracle_enhanced/type/raw.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,17 @@ class Raw < ActiveModel::Type::String # :nodoc:
def type
:raw
end

def serialize(value)
# Encode a string or byte array as string of hex codes
if value.nil?
super
else
value = value.unpack('C*')
value.map { |x| "%02X" % x }.join
end
end

end
end
end
Expand Down

0 comments on commit a5837e2

Please sign in to comment.