Methods
- active?
- database_exists?
- disconnect!
- error_number
- new
- new_client
- quote_string
- reconnect!
- reset!
- supports_comments?
- supports_comments_in_create?
- supports_json?
- supports_lazy_transactions?
- supports_savepoints?
Included Modules
Constants
ADAPTER_NAME | = | "Mysql2" |
ER_BAD_DB_ERROR | = | 1049 |
Class Public methods
database_exists?(config)
📝 Source code
# File activerecord/lib/active_record/connection_adapters/mysql2_adapter.rb, line 56
def self.database_exists?(config)
!!ActiveRecord::Base.mysql2_connection(config)
rescue ActiveRecord::NoDatabaseError
false
end
🔎 See on GitHub
new(connection, logger, connection_options, config)
📝 Source code
# File activerecord/lib/active_record/connection_adapters/mysql2_adapter.rb, line 50
def initialize(connection, logger, connection_options, config)
superclass_config = config.reverse_merge(prepared_statements: false)
super(connection, logger, connection_options, superclass_config)
configure_connection
end
🔎 See on GitHub
new_client(config)
📝 Source code
# File activerecord/lib/active_record/connection_adapters/mysql2_adapter.rb, line 39
def new_client(config)
Mysql2::Client.new(config)
rescue Mysql2::Error => error
if error.error_number == ConnectionAdapters::Mysql2Adapter::ER_BAD_DB_ERROR
raise ActiveRecord::NoDatabaseError
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 112
def active?
@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 125
def disconnect!
super
@connection.close
end
🔎 See on GitHub
error_number(exception)
📝 Source code
# File activerecord/lib/active_record/connection_adapters/mysql2_adapter.rb, line 94
def error_number(exception)
exception.error_number if exception.respond_to?(:error_number)
end
🔎 See on GitHub
quote_string(string)
📝 Source code
# File activerecord/lib/active_record/connection_adapters/mysql2_adapter.rb, line 102
def quote_string(string)
@connection.escape(string)
rescue Mysql2::Error => error
raise translate_exception(error, message: error.message, sql: "<escape>", binds: [])
end
🔎 See on GitHub
reconnect!()
Also aliased as: reset!
📝 Source code
# File activerecord/lib/active_record/connection_adapters/mysql2_adapter.rb, line 116
def reconnect!
super
disconnect!
connect
end
🔎 See on GitHub
supports_comments?()
📝 Source code
# File activerecord/lib/active_record/connection_adapters/mysql2_adapter.rb, line 66
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 70
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 62
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 78
def supports_lazy_transactions?
true
end
🔎 See on GitHub
supports_savepoints?()
📝 Source code
# File activerecord/lib/active_record/connection_adapters/mysql2_adapter.rb, line 74
def supports_savepoints?
true
end
🔎 See on GitHub