Methods
A
C
D
E
I
L
N
Q
R
S
Constants
ADAPTER_NAME = 'Mysql2'
 
Class Public methods
new(connection, logger, connection_options, config)
# File activerecord/lib/active_record/connection_adapters/mysql2_adapter.rb, line 33
def initialize(connection, logger, connection_options, config)
  super
  @visitor = BindSubstitution.new self
  configure_connection
end
Instance Public methods
active?()

CONNECTION MANAGEMENT ====================================

# File activerecord/lib/active_record/connection_adapters/mysql2_adapter.rb, line 71
def active?
  return false unless @connection
  @connection.ping
end
create(sql, name = nil, pk = nil, id_value = nil, sequence_name = nil)
disconnect!()

Disconnects from the database if already connected. Otherwise, this method does nothing.

# File activerecord/lib/active_record/connection_adapters/mysql2_adapter.rb, line 83
def disconnect!
  unless @connection.nil?
    @connection.close
    @connection = nil
  end
end
error_number(exception)
# File activerecord/lib/active_record/connection_adapters/mysql2_adapter.rb, line 59
def error_number(exception)
  exception.error_number if exception.respond_to?(:error_number)
end
exec_delete(sql, name, binds)
Also aliased as: exec_update
# File activerecord/lib/active_record/connection_adapters/mysql2_adapter.rb, line 237
def exec_delete(sql, name, binds)
  execute to_sql(sql, binds), name
  @connection.affected_rows
end
exec_insert(sql, name, binds)
# File activerecord/lib/active_record/connection_adapters/mysql2_adapter.rb, line 233
def exec_insert(sql, name, binds)
  execute to_sql(sql, binds), name
end
exec_query(sql, name = 'SQL', binds = [])
Also aliased as: exec_without_stmt
# File activerecord/lib/active_record/connection_adapters/mysql2_adapter.rb, line 214
def exec_query(sql, name = 'SQL', binds = [])
  result = execute(sql, name)
  ActiveRecord::Result.new(result.fields, result.to_a)
end
exec_update(sql, name, binds)
exec_without_stmt(sql, name = 'SQL', binds = [])
execute(sql, name = nil)

Executes the SQL statement in the context of this connection.

# File activerecord/lib/active_record/connection_adapters/mysql2_adapter.rb, line 206
def execute(sql, name = nil)
  # make sure we carry over any changes to ActiveRecord::Base.default_timezone that have been
  # made since we established the connection
  @connection.query_options[:database_timezone] = ActiveRecord::Base.default_timezone

  super
end
explain(arel, binds = [])

DATABASE STATEMENTS ======================================

# File activerecord/lib/active_record/connection_adapters/mysql2_adapter.rb, line 97
def explain(arel, binds = [])
  sql     = "EXPLAIN #{to_sql(arel, binds.dup)}"
  start   = Time.now
  result  = exec_query(sql, 'EXPLAIN', binds)
  elapsed = Time.now - start

  ExplainPrettyPrinter.new.pp(result, elapsed)
end
insert_sql(sql, name = nil, pk = nil, id_value = nil, sequence_name = nil)
Also aliased as: create
# File activerecord/lib/active_record/connection_adapters/mysql2_adapter.rb, line 227
def insert_sql(sql, name = nil, pk = nil, id_value = nil, sequence_name = nil)
  super
  id_value || @connection.last_id
end
last_inserted_id(result)
# File activerecord/lib/active_record/connection_adapters/mysql2_adapter.rb, line 243
def last_inserted_id(result)
  @connection.last_id
end
quote_string(string)

QUOTING ==================================================

# File activerecord/lib/active_record/connection_adapters/mysql2_adapter.rb, line 65
def quote_string(string)
  @connection.escape(string)
end
reconnect!()
# File activerecord/lib/active_record/connection_adapters/mysql2_adapter.rb, line 76
def reconnect!
  disconnect!
  connect
end
reset!()
# File activerecord/lib/active_record/connection_adapters/mysql2_adapter.rb, line 90
def reset!
  disconnect!
  connect
end
select(sql, name = nil, binds = [])

Returns an array of record hashes with the column names as keys and column values as values.

# File activerecord/lib/active_record/connection_adapters/mysql2_adapter.rb, line 223
def select(sql, name = nil, binds = [])
  exec_query(sql, name).to_a
end
select_rows(sql, name = nil)

Returns an array of arrays containing the field values. Order is the same as that returned by columns.

# File activerecord/lib/active_record/connection_adapters/mysql2_adapter.rb, line 201
def select_rows(sql, name = nil)
  execute(sql, name).to_a
end
supports_explain?()
# File activerecord/lib/active_record/connection_adapters/mysql2_adapter.rb, line 39
def supports_explain?
  true
end