Active Record MySQL2 Adapter
Methods
- active?
- disconnect!
- error_number
- new
- new_client
- quote_string
- 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 66
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 35
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 133
def active?
!!@raw_connection&.ping
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 141
def disconnect!
super
@raw_connection&.close
@raw_connection = nil
end
🔎 See on GitHub
error_number(exception)
📝 Source code
# File activerecord/lib/active_record/connection_adapters/mysql2_adapter.rb, line 114
def error_number(exception)
exception.error_number if exception.respond_to?(:error_number)
end
🔎 See on GitHub
quote_string(string)
Quotes strings for use in SQL input.
📝 Source code
# File activerecord/lib/active_record/connection_adapters/mysql2_adapter.rb, line 123
def quote_string(string)
with_raw_connection(allow_retry: true, materialize_transactions: false) do |connection|
connection.escape(string)
end
end
🔎 See on GitHub
savepoint_errors_invalidate_transactions?()
📝 Source code
# File activerecord/lib/active_record/connection_adapters/mysql2_adapter.rb, line 96
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 84
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 88
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 80
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 100
def supports_lazy_transactions?
true
end
🔎 See on GitHub
supports_savepoints?()
📝 Source code
# File activerecord/lib/active_record/connection_adapters/mysql2_adapter.rb, line 92
def supports_savepoints?
true
end
🔎 See on GitHub