Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move write_lobs under OracleEnhanced::DatabaseStatements module #1546

Merged
merged 1 commit into from
Oct 20, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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