Skip to content

Commit

Permalink
Updates to work with connection changes
Browse files Browse the repository at this point in the history
We can't call @raw_connection right away anymore, because it is nil until
it is used after the changes in rails/rails#44576
and rails/rails#44591.

Also we need to have @lock established in order to be able to use
`with_raw_connection`. In the abstract_adapter implementation, that happens
after the arel_visitor is set, but in oracle enhanced, we need to use
`with_raw_connection` to check the database version in order to pick with
visitor to use. Calling lock_thread = nil before super means @lock isi
available to set the arel_visitor.

Rails rails/rails#48229 also requires an internal_exec_query
method that is called by the abstract adpater's exec_query. Naively renaming
the oracle-enhanced's exec_query to internal_exec_query makes the oracle
enhanced tests run.

I also saw errors due to `active?` using @raw_connection. `valid_raw_connection`
ends up calling `active?` via `with_raw_connection` and `verify` so that
can't be used as a replacement for @raw_connection here. Borrowing from
the postgres adapter implementation to get around this.
  • Loading branch information
dlagerro committed Feb 14, 2024
1 parent f6ac358 commit 99d9e8e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def execute(sql, name = nil, async: false)
log(sql, name, async: async) { @raw_connection.exec(sql) }
end

def exec_query(sql, name = "SQL", binds = [], prepare: false, async: false)
def internal_exec_query(sql, name = "SQL", binds = [], prepare: false, async: false)
sql = transform_query(sql)

type_casted_binds = type_casted_binds(binds)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,7 @@ def dealloc(stmt)
end

def initialize(config_or_deprecated_connection, deprecated_logger = nil, deprecated_connection_options = nil, deprecated_config = nil) # :nodoc:
self.lock_thread = nil
super(config_or_deprecated_connection, deprecated_logger, deprecated_connection_options, deprecated_config)
@enable_dbms_output = false
@do_not_prefetch_primary_key = {}
Expand Down Expand Up @@ -446,7 +447,11 @@ 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.
@raw_connection.ping
@lock.synchronize do
return false unless @raw_connection
@raw_connection.ping
end
true
rescue OracleEnhanced::ConnectionException
false
end
Expand Down Expand Up @@ -696,7 +701,7 @@ def max_identifier_length
alias index_name_length max_identifier_length

def get_database_version
@raw_connection.database_version
valid_raw_connection.database_version
end

def check_version
Expand Down

0 comments on commit 99d9e8e

Please sign in to comment.