Skip to content

Commit

Permalink
[oracle] (shared) serialized attribute support + tests for oracle
Browse files Browse the repository at this point in the history
  • Loading branch information
kares committed Jan 29, 2013
1 parent fad1ede commit 3fb2018
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 10 deletions.
21 changes: 11 additions & 10 deletions lib/arjdbc/oracle/adapter.rb
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
module ::ArJdbc
require 'arjdbc/jdbc/serialized_attributes_helper'

module ArJdbc
module Oracle
def self.extended(mod)
unless @_lob_callback_added
ActiveRecord::Base.class_eval do
def after_save_with_oracle_lob
self.class.columns.select { |c| c.sql_type =~ /LOB\(|LOB$/i }.each do |c|
value = self[c.name]
if respond_to?(:unserializable_attribute?)
value = value.to_yaml if unserializable_attribute?(c.name, c)
else
value = value.to_yaml if value.is_a?(Hash)
end
self.class.columns.select { |c| c.sql_type =~ /LOB\(|LOB$/i }.each do |column|
value = ::ArJdbc::SerializedAttributesHelper.dump_column_value(self, column)
next if value.nil? || (value == '')

connection.write_large_object(c.type == :binary, c.name, self.class.table_name, self.class.primary_key, quote_value(id), value)
connection.write_large_object(
column.type == :binary, column.name,
self.class.table_name, self.class.primary_key,
quote_value(id), value
)
end
end
end
Expand Down Expand Up @@ -191,7 +192,7 @@ def type_to_sql(type, limit = nil, precision = nil, scale = nil) #:nodoc:
case type.to_sym
when :binary
# { BLOB | BINARY LARGE OBJECT } [ ( length [{K |M |G }] ) ]
# although sOracle does not like limit (length) with BLOB (or CLOB) :
# although Oracle does not like limit (length) with BLOB (or CLOB) :
#
# CREATE TABLE binaries (data BLOB, short_data BLOB(1024));
# ORA-00907: missing right parenthesis *
Expand Down
6 changes: 6 additions & 0 deletions test/oracle_serialize_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
require 'db/oracle'
require 'serialize'

class OracleSerializeTest < Test::Unit::TestCase
include SerializeTestMethods
end

0 comments on commit 3fb2018

Please sign in to comment.