edge badge
Methods
A
D
E
L
N
Q
R
S
Constants
ADAPTER_NAME = 'Mysql2'.freeze
 
Class Public methods
new(connection, logger, connection_options, config)
# File activerecord/lib/active_record/connection_adapters/mysql2_adapter.rb, line 38
def initialize(connection, logger, connection_options, config)
  super
  @prepared_statements = false
  configure_connection
end
Instance Public methods
active?()
# File activerecord/lib/active_record/connection_adapters/mysql2_adapter.rb, line 76
def active?
  return false unless @connection
  @connection.ping
end
disconnect!()

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

# File activerecord/lib/active_record/connection_adapters/mysql2_adapter.rb, line 90
def disconnect!
  super
  unless @connection.nil?
    @connection.close
    @connection = nil
  end
end
error_number(exception)
# File activerecord/lib/active_record/connection_adapters/mysql2_adapter.rb, line 60
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 143
def exec_delete(sql, name, binds)
  execute to_sql(sql, binds), name
  @connection.affected_rows
end
exec_insert(sql, name, binds, pk = nil, sequence_name = nil)
# File activerecord/lib/active_record/connection_adapters/mysql2_adapter.rb, line 139
def exec_insert(sql, name, binds, pk = nil, sequence_name = nil)
  execute to_sql(sql, binds), name
end
exec_query(sql, name = 'SQL', binds = [], prepare: false)
Also aliased as: exec_without_stmt
# File activerecord/lib/active_record/connection_adapters/mysql2_adapter.rb, line 131
def exec_query(sql, name = 'SQL', binds = [], prepare: false)
  result = execute(sql, name)
  @connection.next_result while @connection.more_results?
  ActiveRecord::Result.new(result.fields, result.to_a)
end
exec_update(sql, name, binds)
Alias for: exec_delete
exec_without_stmt(sql, name = 'SQL', binds = [], prepare: false)
Alias for: exec_query
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 121
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
last_inserted_id(result)
# File activerecord/lib/active_record/connection_adapters/mysql2_adapter.rb, line 149
def last_inserted_id(result)
  @connection.last_id
end
quote_string(string)
# File activerecord/lib/active_record/connection_adapters/mysql2_adapter.rb, line 68
def quote_string(string)
  @connection.escape(string)
end
reconnect!()
Also aliased as: reset!
# File activerecord/lib/active_record/connection_adapters/mysql2_adapter.rb, line 81
def reconnect!
  super
  disconnect!
  connect
end
reset!()
Alias for: reconnect!
select_one(arel, name = nil, binds = [])

Returns a record hash with the column names as keys and column values as values.

# File activerecord/lib/active_record/connection_adapters/mysql2_adapter.rb, line 104
def select_one(arel, name = nil, binds = [])
  arel, binds = binds_from_relation(arel, binds)
  execute(to_sql(arel, binds), name).each(as: :hash) do |row|
    @connection.next_result while @connection.more_results?
    return row
  end
end
select_rows(sql, name = nil, binds = [])

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 114
def select_rows(sql, name = nil, binds = [])
  result = execute(sql, name)
  @connection.next_result while @connection.more_results?
  result.to_a
end
supports_json?()
# File activerecord/lib/active_record/connection_adapters/mysql2_adapter.rb, line 44
def supports_json?
  !mariadb? && version >= '5.7.8'
end