method
exec_stmt
v4.2.7 -
Show latest stable
-
0 notes -
Class: ActiveRecord::ConnectionAdapters::MysqlAdapter
- 1.0.0
- 1.1.6
- 1.2.6
- 2.0.3
- 2.1.0
- 2.2.1
- 2.3.8
- 3.0.0
- 3.0.9
- 3.1.0 (0)
- 3.2.1 (0)
- 3.2.8 (0)
- 3.2.13 (0)
- 4.0.2 (0)
- 4.1.8 (0)
- 4.2.1 (0)
- 4.2.7 (0)
- 4.2.9 (0)
- 5.0.0.1
- 5.1.7
- 5.2.3
- 6.0.0
- 6.1.3.1
- 6.1.7.7
- 7.0.0
- 7.1.3.2
- 7.1.3.4
- What's this?
exec_stmt(sql, name, binds)
private
Hide source
# File activerecord/lib/active_record/connection_adapters/mysql_adapter.rb, line 396 def exec_stmt(sql, name, binds) cache = {} type_casted_binds = binds.map { |col, val| [col, type_cast(val, col)] } log(sql, name, type_casted_binds) do if binds.empty? stmt = @connection.prepare(sql) else cache = @statements[sql] ||= { :stmt => @connection.prepare(sql) } stmt = cache[:stmt] end begin stmt.execute(*type_casted_binds.map { |_, val| val }) rescue Mysql::Error => e # Older versions of MySQL leave the prepared statement in a bad # place when an error occurs. To support older MySQL versions, we # need to close the statement and delete the statement from the # cache. stmt.close @statements.delete sql raise e end cols = nil if metadata = stmt.result_metadata cols = cache[:cols] ||= metadata.fetch_fields.map { |field| field.name } metadata.free end result_set = ActiveRecord::Result.new(cols, stmt.to_a) if cols affected_rows = stmt.affected_rows stmt.free_result stmt.close if binds.empty? [result_set, affected_rows] end end