Module: ActiveRecord::ConnectionAdapters::MySQL::DatabaseStatements
Relationships & Source Files | |
Extension / Inclusion / Inheritance Descendants | |
Included In:
| |
Defined in: | activerecord/lib/active_record/connection_adapters/mysql/database_statements.rb |
Instance Method Summary
- #exec_delete(sql, name = nil, binds = []) (also: #exec_update)
- #exec_query(sql, name = "SQL", binds = [], prepare: false)
-
#exec_update(sql, name = nil, binds = [])
Alias for #exec_delete.
-
#execute(sql, name = nil)
Executes the SQL statement in the context of this connection.
- #explain(arel, binds = [])
Instance Method Details
#exec_delete(sql, name = nil, binds = []) Also known as: #exec_update
[ GitHub ]# File 'activerecord/lib/active_record/connection_adapters/mysql/database_statements.rb', line 75
def exec_delete(sql, name = nil, binds = []) if without_prepared_statement?(binds) @lock.synchronize do execute_and_free(sql, name) { @connection.affected_rows } end else exec_stmt_and_free(sql, name, binds) { |stmt| stmt.affected_rows } end end
#exec_query(sql, name = "SQL", binds = [], prepare: false)
[ GitHub ]# File 'activerecord/lib/active_record/connection_adapters/mysql/database_statements.rb', line 55
def exec_query(sql, name = "SQL", binds = [], prepare: false) if without_prepared_statement?(binds) execute_and_free(sql, name) do |result| if result build_result(columns: result.fields, rows: result.to_a) else build_result(columns: [], rows: []) end end else exec_stmt_and_free(sql, name, binds, cache_stmt: prepare) do |_, result| if result build_result(columns: result.fields, rows: result.to_a) else build_result(columns: [], rows: []) end end end end
#exec_update(sql, name = nil, binds = [])
Alias for #exec_delete.
# File 'activerecord/lib/active_record/connection_adapters/mysql/database_statements.rb', line 84
alias :exec_update :exec_delete
#execute(sql, name = nil)
Executes the SQL statement in the context of this connection.
# File 'activerecord/lib/active_record/connection_adapters/mysql/database_statements.rb', line 43
def execute(sql, name = nil) if preventing_writes? && write_query?(sql) raise ActiveRecord::ReadOnlyError, "Write query attempted while in readonly mode: #{sql}" end # make sure we carry over any changes to ActiveRecord::Base.default_timezone that have been # made since we established the connection @connection. [:database_timezone] = ActiveRecord::Base.default_timezone super end
#explain(arel, binds = [])
[ GitHub ]# File 'activerecord/lib/active_record/connection_adapters/mysql/database_statements.rb', line 33
def explain(arel, binds = []) sql = "EXPLAIN #{to_sql(arel, binds)}" start = Concurrent.monotonic_time result = exec_query(sql, "EXPLAIN", binds) elapsed = Concurrent.monotonic_time - start MySQL::ExplainPrettyPrinter.new.pp(result, elapsed) end