Skip to content
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 @@ -12,7 +12,7 @@ module DatabaseStatements
def execute(sql, name = nil, async: false)
sql = transform_query(sql)

log(sql, name, async: async) { @connection.exec(sql) }
log(sql, name, async: async) { @raw_connection.exec(sql) }
end

def exec_query(sql, name = "SQL", binds = [], prepare: false, async: false)
Expand All @@ -25,10 +25,10 @@ def exec_query(sql, name = "SQL", binds = [], prepare: false, async: false)
cached = false
with_retry do
if without_prepared_statement?(binds)
cursor = @connection.prepare(sql)
cursor = @raw_connection.prepare(sql)
else
unless @statements.key? sql
@statements[sql] = @connection.prepare(sql)
@statements[sql] = @raw_connection.prepare(sql)
end

cursor = @statements[sql]
Expand Down Expand Up @@ -101,10 +101,10 @@ def exec_insert(sql, name = nil, binds = [], pk = nil, sequence_name = nil)
returning_id_col = returning_id_index = nil
with_retry do
if without_prepared_statement?(binds)
cursor = @connection.prepare(sql)
cursor = @raw_connection.prepare(sql)
else
unless @statements.key?(sql)
@statements[sql] = @connection.prepare(sql)
@statements[sql] = @raw_connection.prepare(sql)
end

cursor = @statements[sql]
Expand Down Expand Up @@ -141,12 +141,12 @@ def exec_update(sql, name = nil, binds = [])
with_retry do
cached = false
if without_prepared_statement?(binds)
cursor = @connection.prepare(sql)
cursor = @raw_connection.prepare(sql)
else
if @statements.key?(sql)
cursor = @statements[sql]
else
cursor = @statements[sql] = @connection.prepare(sql)
cursor = @statements[sql] = @raw_connection.prepare(sql)
end

cursor.bind_params(type_casted_binds)
Expand All @@ -164,7 +164,7 @@ def exec_update(sql, name = nil, binds = [])
alias :exec_delete :exec_update

def begin_db_transaction # :nodoc:
@connection.autocommit = false
@raw_connection.autocommit = false
end

def transaction_isolation_levels
Expand All @@ -183,15 +183,15 @@ def begin_isolated_db_transaction(isolation)
end

def commit_db_transaction # :nodoc:
@connection.commit
@raw_connection.commit
ensure
@connection.autocommit = true
@raw_connection.autocommit = true
end

def exec_rollback_db_transaction # :nodoc:
@connection.rollback
@raw_connection.rollback
ensure
@connection.autocommit = true
@raw_connection.autocommit = true
end

def create_savepoint(name = current_savepoint_name) # :nodoc:
Expand Down Expand Up @@ -265,14 +265,14 @@ def write_lobs(table_name, klass, attributes, columns) # :nodoc:
raise ActiveRecord::RecordNotFound, "statement #{sql} returned no rows"
end
lob = lob_record[col.name]
@connection.write_lob(lob, value.to_s, col.type == :binary)
@raw_connection.write_lob(lob, value.to_s, col.type == :binary)
end
end
end

private
def with_retry
@connection.with_retry do
@raw_connection.with_retry do
yield
rescue
@statements.clear
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ def database_version

class Cursor
def initialize(connection, raw_statement)
@connection = connection
@raw_connection = connection
@raw_statement = raw_statement
end

Expand Down Expand Up @@ -384,7 +384,7 @@ def fetch(options = {})
row_values = []
column_types.each_with_index do |column_type, i|
row_values <<
@connection.get_ruby_value_from_result_set(@raw_result_set, i + 1, column_type, get_lob_value)
@raw_connection.get_ruby_value_from_result_set(@raw_result_set, i + 1, column_type, get_lob_value)
end
row_values
else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ module JDBCQuoting
def type_cast(value)
case value
when ActiveModel::Type::Binary::Data
blob = Java::OracleSql::BLOB.createTemporary(@connection.raw_connection, false, Java::OracleSql::BLOB::DURATION_SESSION)
blob = Java::OracleSql::BLOB.createTemporary(@raw_connection.raw_connection, false, Java::OracleSql::BLOB::DURATION_SESSION)
blob.setBytes(1, value.to_s.to_java_bytes)
blob
when Type::OracleEnhanced::Text::Data
clob = Java::OracleSql::CLOB.createTemporary(@connection.raw_connection, false, Java::OracleSql::CLOB::DURATION_SESSION)
clob = Java::OracleSql::CLOB.createTemporary(@raw_connection.raw_connection, false, Java::OracleSql::CLOB::DURATION_SESSION)
clob.setString(1, value.to_s)
clob
when Type::OracleEnhanced::NationalCharacterText::Data
clob = Java::OracleSql::NCLOB.createTemporary(@connection.raw_connection, false, Java::OracleSql::NCLOB::DURATION_SESSION)
clob = Java::OracleSql::NCLOB.createTemporary(@raw_connection.raw_connection, false, Java::OracleSql::NCLOB::DURATION_SESSION)
clob.setString(1, value.to_s)
clob
else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def raw_oci_connection
# ActiveRecord Oracle enhanced adapter puts OCI8EnhancedAutoRecover wrapper around OCI8
# in this case we need to pass original OCI8 connection
else
@raw_connection.instance_variable_get(:@connection)
@raw_connection.instance_variable_get(:@raw_connection)
end
end

Expand Down Expand Up @@ -107,7 +107,7 @@ def prepare(sql)

class Cursor
def initialize(connection, raw_cursor)
@connection = connection
@raw_connection = connection
@raw_cursor = raw_cursor
end

Expand Down Expand Up @@ -159,7 +159,7 @@ def fetch(options = {})
get_lob_value = options[:get_lob_value]
col_index = 0
row.map do |col|
col_value = @connection.typecast_result_value(col, get_lob_value)
col_value = @raw_connection.typecast_result_value(col, get_lob_value)
col_metadata = @raw_cursor.column_metadata.fetch(col_index)
if !col_metadata.nil?
key = col_metadata.data_type
Expand Down Expand Up @@ -390,15 +390,15 @@ def initialize(config, factory) # :nodoc:
@active = true
@config = config
@factory = factory
@connection = @factory.new_connection @config
super @connection
@raw_connection = @factory.new_connection @config
super @raw_connection
end

# Checks connection, returns true if active. Note that ping actively
# checks the connection, while #active? simply returns the last
# known state.
def ping # :nodoc:
@connection.exec("select 1 from dual") { |r| nil }
@raw_connection.exec("select 1 from dual") { |r| nil }
@active = true
rescue
@active = false
Expand All @@ -409,8 +409,8 @@ def ping # :nodoc:
def reset! # :nodoc:
logoff rescue nil
begin
@connection = @factory.new_connection @config
__setobj__ @connection
@raw_connection = @factory.new_connection @config
__setobj__ @raw_connection
@active = true
rescue
@active = false
Expand Down Expand Up @@ -442,7 +442,7 @@ def with_retry # :nodoc:
end

def exec(sql, *bindvars, &block) # :nodoc:
with_retry { @connection.exec(sql, *bindvars, &block) }
with_retry { @raw_connection.exec(sql, *bindvars, &block) }
end
end
# :startdoc:
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,19 @@ def type_cast(value)
when ActiveModel::Type::Binary::Data
lob_value = value == "" ? " " : value
bind_type = OCI8::BLOB
ora_value = bind_type.new(@connection.raw_oci_connection, lob_value)
ora_value = bind_type.new(@raw_connection.raw_oci_connection, lob_value)
ora_value.size = 0 if value == ""
ora_value
when Type::OracleEnhanced::Text::Data
lob_value = value.to_s == "" ? " " : value.to_s
bind_type = OCI8::CLOB
ora_value = bind_type.new(@connection.raw_oci_connection, lob_value)
ora_value = bind_type.new(@raw_connection.raw_oci_connection, lob_value)
ora_value.size = 0 if value.to_s == ""
ora_value
when Type::OracleEnhanced::NationalCharacterText::Data
lob_value = value.to_s == "" ? " " : value.to_s
bind_type = OCI8::NCLOB
ora_value = bind_type.new(@connection.raw_oci_connection, lob_value)
ora_value = bind_type.new(@raw_connection.raw_oci_connection, lob_value)
ora_value.size = 0 if value.to_s == ""
ora_value
else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def table_exists?(table_name)
end

def data_source_exists?(table_name)
(_owner, _table_name) = @connection.describe(table_name)
(_owner, _table_name) = @raw_connection.describe(table_name)
true
rescue
false
Expand Down Expand Up @@ -87,7 +87,7 @@ def synonyms
end

def indexes(table_name) # :nodoc:
(_owner, table_name) = @connection.describe(table_name)
(_owner, table_name) = @raw_connection.describe(table_name)
default_tablespace_name = default_tablespace

result = select_all(<<~SQL.squish, "SCHEMA", [bind_string("table_name", table_name)])
Expand Down Expand Up @@ -368,7 +368,7 @@ def index_name(table_name, options) # :nodoc:
#
# Will always query database and not index cache.
def index_name_exists?(table_name, index_name)
(_owner, table_name) = @connection.describe(table_name)
(_owner, table_name) = @raw_connection.describe(table_name)
result = select_value(<<~SQL.squish, "SCHEMA", [bind_string("table_name", table_name), bind_string("index_name", index_name.to_s.upcase)])
SELECT /*+ OPTIMIZER_FEATURES_ENABLE('11.2.0.2') */ 1 FROM all_indexes i
WHERE i.owner = SYS_CONTEXT('userenv', 'current_schema')
Expand Down Expand Up @@ -511,7 +511,7 @@ def change_column_comment(table_name, column_name, comment_or_changes)

def table_comment(table_name) # :nodoc:
# TODO
(_owner, table_name) = @connection.describe(table_name)
(_owner, table_name) = @raw_connection.describe(table_name)
select_value(<<~SQL.squish, "SCHEMA", [bind_string("table_name", table_name)])
SELECT /*+ OPTIMIZER_FEATURES_ENABLE('11.2.0.2') */ comments FROM all_tab_comments
WHERE owner = SYS_CONTEXT('userenv', 'current_schema')
Expand All @@ -527,7 +527,7 @@ def table_options(table_name) # :nodoc:

def column_comment(table_name, column_name) # :nodoc:
# TODO: it does not exist in Abstract adapter
(_owner, table_name) = @connection.describe(table_name)
(_owner, table_name) = @raw_connection.describe(table_name)
select_value(<<~SQL.squish, "SCHEMA", [bind_string("table_name", table_name), bind_string("column_name", column_name.upcase)])
SELECT /*+ OPTIMIZER_FEATURES_ENABLE('11.2.0.2') */ comments FROM all_col_comments
WHERE owner = SYS_CONTEXT('userenv', 'current_schema')
Expand Down Expand Up @@ -555,7 +555,7 @@ def tablespace(table_name)

# get table foreign keys for schema dump
def foreign_keys(table_name) # :nodoc:
(_owner, desc_table_name) = @connection.describe(table_name)
(_owner, desc_table_name) = @raw_connection.describe(table_name)

fk_info = select_all(<<~SQL.squish, "SCHEMA", [bind_string("desc_table_name", desc_table_name)])
SELECT /*+ OPTIMIZER_FEATURES_ENABLE('11.2.0.2') */ r.table_name to_table
Expand Down
24 changes: 12 additions & 12 deletions lib/active_record/connection_adapters/oracle_enhanced_adapter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -426,12 +426,12 @@ def native_database_types # :nodoc:

def auto_retry=(value) # :nodoc:
@auto_retry = value
@connection.auto_retry = value if @connection
@raw_connection.auto_retry = value if @raw_connection
end

# return raw OCI8 or JDBC connection
def raw_connection
@connection.raw_connection
@raw_connection.raw_connection
end

# Returns true if the connection is active.
Expand All @@ -440,15 +440,15 @@ def active? # :nodoc:
# #active? method is also available, but that simply returns the
# last known state, which isn't good enough if the connection has
# gone stale since the last use.
@connection.ping
@raw_connection.ping
rescue OracleEnhanced::ConnectionException
false
end

# Reconnects to the database.
def reconnect! # :nodoc:
super
@connection.reset!
@raw_connection.reset!
rescue OracleEnhanced::ConnectionException => e
@logger.warn "#{adapter_name} automatic reconnection failed: #{e.message}" if @logger
end
Expand All @@ -461,12 +461,12 @@ def reset!
# Disconnects from the database.
def disconnect! # :nodoc:
super
@connection.logoff rescue nil
@raw_connection.logoff rescue nil
end

def discard!
super
@connection = nil
@raw_connection = nil
end

# use in set_sequence_name to avoid fetching primary key value from sequence
Expand All @@ -491,7 +491,7 @@ def prefetch_primary_key?(table_name = nil)
table_name = table_name.to_s
do_not_prefetch = @do_not_prefetch_primary_key[table_name]
if do_not_prefetch.nil?
owner, desc_table_name = @connection.describe(table_name)
owner, desc_table_name = @raw_connection.describe(table_name)
@do_not_prefetch_primary_key[table_name] = do_not_prefetch = !has_primary_key?(table_name, owner, desc_table_name)
end
!do_not_prefetch
Expand Down Expand Up @@ -560,7 +560,7 @@ def default_tablespace
end

def column_definitions(table_name)
(owner, desc_table_name) = @connection.describe(table_name)
(owner, desc_table_name) = @raw_connection.describe(table_name)

select_all(<<~SQL.squish, "SCHEMA", [bind_string("owner", owner), bind_string("table_name", desc_table_name)])
SELECT /*+ OPTIMIZER_FEATURES_ENABLE('11.2.0.2') */ cols.column_name AS name, cols.data_type AS sql_type,
Expand Down Expand Up @@ -592,7 +592,7 @@ def clear_table_columns_cache(table_name)
# Find a table's primary key and sequence.
# *Note*: Only primary key is implemented - sequence will be nil.
def pk_and_sequence_for(table_name, owner = nil, desc_table_name = nil) # :nodoc:
(owner, desc_table_name) = @connection.describe(table_name)
(owner, desc_table_name) = @raw_connection.describe(table_name)

seqs = select_values_forcing_binds(<<~SQL.squish, "SCHEMA", [bind_string("owner", owner), bind_string("sequence_name", default_sequence_name(desc_table_name))])
select /*+ OPTIMIZER_FEATURES_ENABLE('11.2.0.2') */ us.sequence_name
Expand Down Expand Up @@ -634,7 +634,7 @@ def has_primary_key?(table_name, owner = nil, desc_table_name = nil) # :nodoc:
end

def primary_keys(table_name) # :nodoc:
(_owner, desc_table_name) = @connection.describe(table_name)
(_owner, desc_table_name) = @raw_connection.describe(table_name)

pks = select_values_forcing_binds(<<~SQL.squish, "SCHEMA", [bind_string("table_name", desc_table_name)])
SELECT /*+ OPTIMIZER_FEATURES_ENABLE('11.2.0.2') */ cc.column_name
Expand Down Expand Up @@ -679,7 +679,7 @@ def max_identifier_length
alias index_name_length max_identifier_length

def get_database_version
@connection.database_version
@raw_connection.database_version
end

def check_version
Expand Down Expand Up @@ -749,7 +749,7 @@ def extract_limit(sql_type) # :nodoc:
end

def translate_exception(exception, message:, sql:, binds:) # :nodoc:
case @connection.error_code(exception)
case @raw_connection.error_code(exception)
when 1
RecordNotUnique.new(message, sql: sql, binds: binds)
when 60
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,7 @@ def lookup(path)

before(:all) do
ActiveRecord::Base.establish_connection(CONNECTION_PARAMS)
@conn = ActiveRecord::Base.connection.instance_variable_get("@connection")
@conn = ActiveRecord::Base.connection.instance_variable_get("@raw_connection")
@sys_conn = ActiveRecord::ConnectionAdapters::OracleEnhanced::Connection.create(SYS_CONNECTION_PARAMS)
schema_define do
create_table :posts, force: true
Expand Down
Loading