Module: ActiveRecord::ConnectionAdapters::MySQL::DatabaseStatements
- Included in:
- ActiveRecord::ConnectionAdapters::Mysql2Adapter
- Defined in:
- lib/active_record/connection_adapters/mysql/database_statements.rb
Instance Method Summary collapse
- #exec_delete(sql, name, binds) ⇒ Object (also: #exec_update)
- #exec_query(sql, name = 'SQL', binds = [], prepare: false) ⇒ Object
-
#execute(sql, name = nil) ⇒ Object
Executes the SQL statement in the context of this connection.
-
#select_all(arel, name = nil, binds = [], preparable: nil) ⇒ Object
Returns an ActiveRecord::Result instance.
-
#select_one(arel, name = nil, binds = []) ⇒ Object
Returns a record hash with the column names as keys and column values as values.
-
#select_rows(sql, name = nil, binds = []) ⇒ Object
Returns an array of arrays containing the field values.
Instance Method Details
#exec_delete(sql, name, binds) ⇒ Object Also known as: exec_update
61 62 63 64 65 66 67 |
# File 'lib/active_record/connection_adapters/mysql/database_statements.rb', line 61 def exec_delete(sql, name, binds) if without_prepared_statement?(binds) execute_and_free(sql, name) { @connection.affected_rows } else exec_stmt_and_free(sql, name, binds) { |stmt| stmt.affected_rows } end end |
#exec_query(sql, name = 'SQL', binds = [], prepare: false) ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/active_record/connection_adapters/mysql/database_statements.rb', line 49 def exec_query(sql, name = 'SQL', binds = [], prepare: false) if without_prepared_statement?(binds) execute_and_free(sql, name) do |result| ActiveRecord::Result.new(result.fields, result.to_a) if result end else exec_stmt_and_free(sql, name, binds, cache_stmt: prepare) do |_, result| ActiveRecord::Result.new(result.fields, result.to_a) if result end end end |
#execute(sql, name = nil) ⇒ Object
Executes the SQL statement in the context of this connection.
39 40 41 42 43 44 45 46 47 |
# File 'lib/active_record/connection_adapters/mysql/database_statements.rb', line 39 def execute(sql, name = nil) if @connection # 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 end super end |
#select_all(arel, name = nil, binds = [], preparable: nil) ⇒ Object
Returns an ActiveRecord::Result instance.
6 7 8 9 10 11 12 13 14 |
# File 'lib/active_record/connection_adapters/mysql/database_statements.rb', line 6 def select_all(arel, name = nil, binds = [], preparable: nil) result = if ExplainRegistry.collect? && prepared_statements unprepared_statement { super } else super end @connection.next_result while @connection.more_results? result end |
#select_one(arel, name = nil, binds = []) ⇒ Object
Returns a record hash with the column names as keys and column values as values.
18 19 20 21 22 23 24 25 26 27 |
# File 'lib/active_record/connection_adapters/mysql/database_statements.rb', line 18 def select_one(arel, name = nil, binds = []) arel, binds = binds_from_relation(arel, binds) @connection..merge!(as: :hash) select_result(to_sql(arel, binds), name, binds) do |result| @connection.next_result while @connection.more_results? result.first end ensure @connection..merge!(as: :array) end |
#select_rows(sql, name = nil, binds = []) ⇒ Object
Returns an array of arrays containing the field values. Order is the same as that returned by columns
.
31 32 33 34 35 36 |
# File 'lib/active_record/connection_adapters/mysql/database_statements.rb', line 31 def select_rows(sql, name = nil, binds = []) select_result(sql, name, binds) do |result| @connection.next_result while @connection.more_results? result.to_a end end |