Skip to content

Commit

Permalink
Merge pull request #1546 from yahonda/move_write_lobs
Browse files Browse the repository at this point in the history
Move `write_lobs` under `OracleEnhanced::DatabaseStatements` module
  • Loading branch information
yahonda authored Oct 20, 2017
2 parents d32c742 + 8d32fd3 commit 9c27717
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,29 @@ def insert_fixtures(fixtures, table_name)
def empty_insert_statement_value
raise NotImplementedError
end

# Writes LOB values from attributes for specified columns
def write_lobs(table_name, klass, attributes, columns) #:nodoc:
id = quote(attributes[klass.primary_key])
columns.each do |col|
value = attributes[col.name]
# changed sequence of next two lines - should check if value is nil before converting to yaml
next if value.blank?
if klass.attribute_types[col.name].is_a? Type::Serialized
value = klass.attribute_types[col.name].serialize(value)
end
uncached do
unless lob_record = select_one(<<-SQL, "Writable Large Object")
SELECT #{quote_column_name(col.name)} FROM #{quote_table_name(table_name)}
WHERE #{quote_column_name(klass.primary_key)} = #{id} FOR UPDATE
SQL
raise ActiveRecord::RecordNotFound, "statement #{sql} returned no rows"
end
lob = lob_record[col.name]
@connection.write_lob(lob, value.to_s, col.type == :binary)
end
end
end
end
end
end
Expand Down
21 changes: 0 additions & 21 deletions lib/active_record/connection_adapters/oracle_enhanced_adapter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -483,27 +483,6 @@ def reset_pk_sequence!(table_name, primary_key = nil, sequence_name = nil) #:nod
end
end

# Writes LOB values from attributes for specified columns
def write_lobs(table_name, klass, attributes, columns) #:nodoc:
id = quote(attributes[klass.primary_key])
columns.each do |col|
value = attributes[col.name]
# changed sequence of next two lines - should check if value is nil before converting to yaml
next if value.blank?
if klass.attribute_types[col.name].is_a? Type::Serialized
value = klass.attribute_types[col.name].serialize(value)
end
uncached do
sql = "SELECT #{quote_column_name(col.name)} FROM #{quote_table_name(table_name)} WHERE #{quote_column_name(klass.primary_key)} = #{id} FOR UPDATE"
unless lob_record = select_one(sql, "Writable Large Object")
raise ActiveRecord::RecordNotFound, "statement #{sql} returned no rows"
end
lob = lob_record[col.name]
@connection.write_lob(lob, value.to_s, col.type == :binary)
end
end
end

# Current database name
def current_database
select_value("SELECT SYS_CONTEXT('userenv', 'con_name') FROM dual")
Expand Down

0 comments on commit 9c27717

Please sign in to comment.