Skip to content

Commit

Permalink
Remove need for using alias_method trick using the inheritance
Browse files Browse the repository at this point in the history
That trick make the code hard to understand, this implementation is
more readable.
  • Loading branch information
rafaelfranca committed Aug 28, 2021
1 parent 03f2b88 commit 5519921
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 18 deletions.
Expand Up @@ -196,14 +196,7 @@ def disable_referential_integrity # :nodoc:

# Executes the SQL statement in the context of this connection.
def execute(sql, name = nil, async: false)
materialize_transactions
mark_transaction_written_if_write(sql)

log(sql, name, async: async) do
ActiveSupport::Dependencies.interlock.permit_concurrent_loads do
@connection.query(sql)
end
end
raw_execute(sql, name, async)
end

# Mysql2Adapter doesn't have to free a result after using it, but we use this method
Expand Down Expand Up @@ -629,6 +622,17 @@ def type_map
emulate_booleans ? TYPE_MAP_WITH_BOOLEAN : TYPE_MAP
end

def raw_execute(sql, name, async: false)
materialize_transactions
mark_transaction_written_if_write(sql)

log(sql, name, async: async) do
ActiveSupport::Dependencies.interlock.permit_concurrent_loads do
@connection.query(sql)
end
end
end

# See https://dev.mysql.com/doc/mysql-errors/en/server-error-reference.html
ER_DB_CREATE_EXISTS = 1007
ER_FILSORT_ABORT = 1028
Expand Down
Expand Up @@ -37,16 +37,6 @@ def explain(arel, binds = [])
MySQL::ExplainPrettyPrinter.new.pp(result, elapsed)
end

def execute(sql, name = nil, async: false)
# make sure we carry over any changes to ActiveRecord.default_timezone that have been
# made since we established the connection
@connection.query_options[:database_timezone] = ActiveRecord.default_timezone

super
end
alias_method :raw_execute, :execute
private :raw_execute

# Executes the SQL statement in the context of this connection.
def execute(sql, name = nil, async: false)
sql = transform_query(sql)
Expand Down Expand Up @@ -91,6 +81,14 @@ def exec_delete(sql, name = nil, binds = []) # :nodoc:
alias :exec_update :exec_delete

private
def raw_execute(sql, name, async: false)
# make sure we carry over any changes to ActiveRecord.default_timezone that have been
# made since we established the connection
@connection.query_options[:database_timezone] = ActiveRecord.default_timezone

super
end

def execute_batch(statements, name = nil)
statements = statements.map { |sql| transform_query(sql) }
combine_multi_statements(statements).each do |statement|
Expand Down

0 comments on commit 5519921

Please sign in to comment.