Active Record MySQL2 Adapter

Methods

Included Modules

Constants

ADAPTER_NAME = "Mysql2"
ER_ACCESS_DENIED_ERROR = 1045
ER_BAD_DB_ERROR = 1049
ER_CONN_HOST_ERROR = 2003
ER_DBACCESS_DENIED_ERROR = 1044
ER_UNKNOWN_HOST_ERROR = 2005
ER_UNKNOWN_STMT_HANDLER = 1243
TYPE_MAP = Type::TypeMap.new.tap { |m| initialize_type_map(m) }

Class Public methods

new(...)

📝 Source code
# File activerecord/lib/active_record/connection_adapters/mysql2_adapter.rb, line 56
def initialize(...)
  super

  @affected_rows_before_warnings = nil
  @config[:flags] ||= 0

  if @config[:flags].kind_of? Array
    @config[:flags].push "FOUND_ROWS"
  else
    @config[:flags] |= ::Mysql2::Client::FOUND_ROWS
  end

  @connection_parameters ||= @config
end
🔎 See on GitHub

new_client(config)

📝 Source code
# File activerecord/lib/active_record/connection_adapters/mysql2_adapter.rb, line 25
def new_client(config)
  ::Mysql2::Client.new(config)
rescue ::Mysql2::Error => error
  case error.error_number
  when ER_BAD_DB_ERROR
    raise ActiveRecord::NoDatabaseError.db_error(config[:database])
  when ER_DBACCESS_DENIED_ERROR, ER_ACCESS_DENIED_ERROR
    raise ActiveRecord::DatabaseConnectionError.username_error(config[:username])
  when ER_CONN_HOST_ERROR, ER_UNKNOWN_HOST_ERROR
    raise ActiveRecord::DatabaseConnectionError.hostname_error(config[:host])
  else
    raise ActiveRecord::ConnectionNotEstablished, error.message
  end
end
🔎 See on GitHub

Instance Public methods

active?()

📝 Source code
# File activerecord/lib/active_record/connection_adapters/mysql2_adapter.rb, line 107
def active?
  if connected?
    @lock.synchronize do
      if @raw_connection&.ping
        verified!
        true
      end
    end
  end || false
end
🔎 See on GitHub

connected?()

📝 Source code
# File activerecord/lib/active_record/connection_adapters/mysql2_adapter.rb, line 103
def connected?
  !(@raw_connection.nil? || @raw_connection.closed?)
end
🔎 See on GitHub

disconnect!()

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

📝 Source code
# File activerecord/lib/active_record/connection_adapters/mysql2_adapter.rb, line 122
def disconnect!
  @lock.synchronize do
    super
    @raw_connection&.close
    @raw_connection = nil
  end
end
🔎 See on GitHub

error_number(exception)

📝 Source code
# File activerecord/lib/active_record/connection_adapters/mysql2_adapter.rb, line 95
def error_number(exception)
  exception.error_number if exception.respond_to?(:error_number)
end
🔎 See on GitHub

savepoint_errors_invalidate_transactions?()

📝 Source code
# File activerecord/lib/active_record/connection_adapters/mysql2_adapter.rb, line 87
def savepoint_errors_invalidate_transactions?
  true
end
🔎 See on GitHub

supports_comments?()

📝 Source code
# File activerecord/lib/active_record/connection_adapters/mysql2_adapter.rb, line 75
def supports_comments?
  true
end
🔎 See on GitHub

supports_comments_in_create?()

📝 Source code
# File activerecord/lib/active_record/connection_adapters/mysql2_adapter.rb, line 79
def supports_comments_in_create?
  true
end
🔎 See on GitHub

supports_json?()

📝 Source code
# File activerecord/lib/active_record/connection_adapters/mysql2_adapter.rb, line 71
def supports_json?
  !mariadb? && database_version >= "5.7.8"
end
🔎 See on GitHub

supports_lazy_transactions?()

📝 Source code
# File activerecord/lib/active_record/connection_adapters/mysql2_adapter.rb, line 91
def supports_lazy_transactions?
  true
end
🔎 See on GitHub

supports_savepoints?()

📝 Source code
# File activerecord/lib/active_record/connection_adapters/mysql2_adapter.rb, line 83
def supports_savepoints?
  true
end
🔎 See on GitHub

Definition files