Active Record MySQL2 Adapter
Methods
- active?
- connected?
- disconnect!
- error_number
- new
- new_client
- savepoint_errors_invalidate_transactions?
- supports_comments?
- supports_comments_in_create?
- supports_json?
- supports_lazy_transactions?
- supports_savepoints?
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 |
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 55
def initialize(...)
super
@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 24
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 115
def active?
connected? && @lock.synchronize { @raw_connection&.ping } || false
end
🔎 See on GitHub
connected?()
📝 Source code
# File activerecord/lib/active_record/connection_adapters/mysql2_adapter.rb, line 111
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 123
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 103
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 85
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 73
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 77
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 69
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 89
def supports_lazy_transactions?
true
end
🔎 See on GitHub
supports_savepoints?()
📝 Source code
# File activerecord/lib/active_record/connection_adapters/mysql2_adapter.rb, line 81
def supports_savepoints?
true
end
🔎 See on GitHub