class ActiveRecord::ConnectionAdapters::Mysql2Adapter

Parent:
ActiveRecord::ConnectionAdapters::AbstractMysqlAdapter

Constants

ADAPTER_NAME
MAX_INDEX_LENGTH_FOR_UTF8MB4

Public Class Methods

new(connection, logger, connection_options, config) Show source
# File activerecord/lib/active_record/connection_adapters/mysql2_adapter.rb, line 41
def initialize(connection, logger, connection_options, config)
  super
  @visitor = BindSubstitution.new self
  configure_connection
end

Public Instance Methods

active?() Show source

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

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

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

# File activerecord/lib/active_record/connection_adapters/mysql2_adapter.rb, line 102
def disconnect!
  super
  unless @connection.nil?
    @connection.close
    @connection = nil
  end
end
error_number(exception) Show source
# File activerecord/lib/active_record/connection_adapters/mysql2_adapter.rb, line 76
def error_number(exception)
  exception.error_number if exception.respond_to?(:error_number)
end
exec_delete(sql, name, binds) Show source
# File activerecord/lib/active_record/connection_adapters/mysql2_adapter.rb, line 253
def exec_delete(sql, name, binds)
  execute to_sql(sql, binds), name
  @connection.affected_rows
end
Also aliased as: exec_update
exec_insert(sql, name, binds, pk = nil, sequence_name = nil) Show source
# File activerecord/lib/active_record/connection_adapters/mysql2_adapter.rb, line 249
def exec_insert(sql, name, binds, pk = nil, sequence_name = nil)
  execute to_sql(sql, binds), name
end
exec_query(sql, name = 'SQL', binds = []) Show source
# File activerecord/lib/active_record/connection_adapters/mysql2_adapter.rb, line 231
def exec_query(sql, name = 'SQL', binds = [])
  result = execute(sql, name)
  ActiveRecord::Result.new(result.fields, result.to_a)
end
Also aliased as: exec_without_stmt
exec_update(sql, name, binds)
Alias for: exec_delete
exec_without_stmt(sql, name = 'SQL', binds = [])
Alias for: exec_query
execute(sql, name = nil) Show source

Executes the SQL statement in the context of this connection.

# File activerecord/lib/active_record/connection_adapters/mysql2_adapter.rb, line 221
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.query_options[:database_timezone] = ActiveRecord::Base.default_timezone
  end

  super
end
explain(arel, binds = []) Show source

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

# File activerecord/lib/active_record/connection_adapters/mysql2_adapter.rb, line 112
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
initialize_schema_migrations_table() Show source
# File activerecord/lib/active_record/connection_adapters/mysql2_adapter.rb, line 48
def initialize_schema_migrations_table
  if @config[:encoding] == 'utf8mb4'
    ActiveRecord::SchemaMigration.create_table(MAX_INDEX_LENGTH_FOR_UTF8MB4)
  else
    ActiveRecord::SchemaMigration.create_table
  end
end
insert_sql(sql, name = nil, pk = nil, id_value = nil, sequence_name = nil) Show source
# File activerecord/lib/active_record/connection_adapters/mysql2_adapter.rb, line 243
def insert_sql(sql, name = nil, pk = nil, id_value = nil, sequence_name = nil)
  super
  id_value || @connection.last_id
end
Also aliased as: create
last_inserted_id(result) Show source
# File activerecord/lib/active_record/connection_adapters/mysql2_adapter.rb, line 259
def last_inserted_id(result)
  @connection.last_id
end
quote_string(string) Show source

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

# File activerecord/lib/active_record/connection_adapters/mysql2_adapter.rb, line 82
def quote_string(string)
  @connection.escape(string)
end
reconnect!() Show source
# File activerecord/lib/active_record/connection_adapters/mysql2_adapter.rb, line 93
def reconnect!
  super
  disconnect!
  connect
end
Also aliased as: reset!
reset!()
Alias for: reconnect!
select(sql, name = nil, binds = []) Show source

Returns an ActiveRecord::Result instance.

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

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 216
def select_rows(sql, name = nil, binds = [])
  execute(sql, name).to_a
end
supports_explain?() Show source
# File activerecord/lib/active_record/connection_adapters/mysql2_adapter.rb, line 56
def supports_explain?
  true
end

© 2004–2016 David Heinemeier Hansson
Licensed under the MIT License.