class ActiveRecord::ConnectionAdapters::Mysql2Adapter
Constants
- ADAPTER_NAME
- MAX_INDEX_LENGTH_FOR_UTF8MB4
Public Class Methods
new(connection, logger, connection_options, config)
click to toggle source
Calls superclass method
ActiveRecord::ConnectionAdapters::AbstractMysqlAdapter.new
# File lib/active_record/connection_adapters/mysql2_adapter.rb, line 34 def initialize(connection, logger, connection_options, config) super @prepared_statements = false configure_connection end
Public Instance Methods
active?()
click to toggle source
# File lib/active_record/connection_adapters/mysql2_adapter.rb, line 89 def active? return false unless @connection @connection.ping end
disconnect!()
click to toggle source
Disconnects from the database if already connected. Otherwise, this method does nothing.
Calls superclass method
ActiveRecord::ConnectionAdapters::AbstractAdapter#disconnect!
# File lib/active_record/connection_adapters/mysql2_adapter.rb, line 103 def disconnect! super unless @connection.nil? @connection.close @connection = nil end end
error_number(exception)
click to toggle source
# File lib/active_record/connection_adapters/mysql2_adapter.rb, line 65 def error_number(exception) exception.error_number if exception.respond_to?(:error_number) end
exec_delete(sql, name, binds)
click to toggle source
# File lib/active_record/connection_adapters/mysql2_adapter.rb, line 251 def exec_delete(sql, name, binds) execute to_sql(sql, binds), name @connection.affected_rows end
Also aliased as: exec_update
exec_insert(sql, name, binds, pk = nil, sequence_name = nil)
click to toggle source
# File lib/active_record/connection_adapters/mysql2_adapter.rb, line 247 def exec_insert(sql, name, binds, pk = nil, sequence_name = nil) execute to_sql(sql, binds), name end
exec_query(sql, name = 'SQL', binds = [])
click to toggle source
# File lib/active_record/connection_adapters/mysql2_adapter.rb, line 234 def exec_query(sql, name = 'SQL', binds = []) result = execute(sql, name) ActiveRecord::Result.new(result.fields, result.to_a) end
Also aliased as: exec_without_stmt
execute(sql, name = nil)
click to toggle source
Executes the SQL statement in the context of this connection.
Calls superclass method
ActiveRecord::ConnectionAdapters::AbstractMysqlAdapter#execute
# File lib/active_record/connection_adapters/mysql2_adapter.rb, line 224 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
explain(arel, binds = [])
click to toggle source
# File lib/active_record/connection_adapters/mysql2_adapter.rb, line 115 def explain(arel, binds = []) sql = "EXPLAIN #{to_sql(arel, binds.dup)}" start = Time.now result = exec_query(sql, 'EXPLAIN', binds) elapsed = Time.now - start ExplainPrettyPrinter.new.pp(result, elapsed) end
initialize_schema_migrations_table()
click to toggle source
# File lib/active_record/connection_adapters/mysql2_adapter.rb, line 41 def initialize_schema_migrations_table if charset == 'utf8mb4' ActiveRecord::SchemaMigration.create_table(MAX_INDEX_LENGTH_FOR_UTF8MB4) else ActiveRecord::SchemaMigration.create_table end end
insert_sql(sql, name = nil, pk = nil, id_value = nil, sequence_name = nil)
click to toggle source
Calls superclass method
# File lib/active_record/connection_adapters/mysql2_adapter.rb, line 241 def insert_sql(sql, name = nil, pk = nil, id_value = nil, sequence_name = nil) super id_value || @connection.last_id end
Also aliased as: create
last_inserted_id(result)
click to toggle source
# File lib/active_record/connection_adapters/mysql2_adapter.rb, line 257 def last_inserted_id(result) @connection.last_id end
quote_string(string)
click to toggle source
# File lib/active_record/connection_adapters/mysql2_adapter.rb, line 73 def quote_string(string) @connection.escape(string) end
quoted_date(value)
click to toggle source
Calls superclass method
ActiveRecord::ConnectionAdapters::Quoting#quoted_date
# File lib/active_record/connection_adapters/mysql2_adapter.rb, line 77 def quoted_date(value) if value.acts_like?(:time) && value.respond_to?(:usec) "#{super}.#{sprintf("%06d", value.usec)}" else super end end
reconnect!()
click to toggle source
Calls superclass method
ActiveRecord::ConnectionAdapters::AbstractAdapter#reconnect!
# File lib/active_record/connection_adapters/mysql2_adapter.rb, line 94 def reconnect! super disconnect! connect end
Also aliased as: reset!
select_rows(sql, name = nil, binds = [])
click to toggle source
Returns an array of arrays containing the field values. Order is the same
as that returned by columns
.
# File lib/active_record/connection_adapters/mysql2_adapter.rb, line 219 def select_rows(sql, name = nil, binds = []) execute(sql, name).to_a end
supports_explain?()
click to toggle source
# File lib/active_record/connection_adapters/mysql2_adapter.rb, line 49 def supports_explain? true end
Private Instance Methods
configure_connection()
click to toggle source
Calls superclass method
ActiveRecord::ConnectionAdapters::AbstractMysqlAdapter#configure_connection
# File lib/active_record/connection_adapters/mysql2_adapter.rb, line 268 def configure_connection @connection.query_options.merge!(:as => :array) super end
connect()
click to toggle source
# File lib/active_record/connection_adapters/mysql2_adapter.rb, line 263 def connect @connection = Mysql2::Client.new(@config) configure_connection end
full_version()
click to toggle source
# File lib/active_record/connection_adapters/mysql2_adapter.rb, line 273 def full_version @full_version ||= @connection.server_info[:version] end
set_field_encoding(field_name)
click to toggle source
# File lib/active_record/connection_adapters/mysql2_adapter.rb, line 277 def set_field_encoding field_name field_name end