class ActiveRecord::ConnectionAdapters::Mysql2Adapter
Constants
- ADAPTER_NAME
- MAX_INDEX_LENGTH_FOR_UTF8MB4
Public Class Methods
# File activerecord/lib/active_record/connection_adapters/mysql2_adapter.rb, line 34 def initialize(connection, logger, connection_options, config) super @prepared_statements = false configure_connection end
Calls superclass method ActiveRecord::ConnectionAdapters::AbstractMysqlAdapter.new
Public Instance Methods
# File activerecord/lib/active_record/connection_adapters/mysql2_adapter.rb, line 81 def active? @connection.ping end
create(sql, name = nil, pk = nil, id_value = nil, sequence_name = nil)
Alias for: insert_sql
# File activerecord/lib/active_record/connection_adapters/mysql2_adapter.rb, line 94 def disconnect! super @connection.close end
Disconnects from the database if already connected. Otherwise, this method does nothing.
Calls superclass method ActiveRecord::ConnectionAdapters::AbstractAdapter#disconnect!
# File activerecord/lib/active_record/connection_adapters/mysql2_adapter.rb, line 65 def error_number(exception) exception.error_number if exception.respond_to?(:error_number) end
# File activerecord/lib/active_record/connection_adapters/mysql2_adapter.rb, line 237 def exec_delete(sql, name, binds) execute to_sql(sql, binds), name @connection.affected_rows end
Also aliased as: exec_update
# File activerecord/lib/active_record/connection_adapters/mysql2_adapter.rb, line 233 def exec_insert(sql, name, binds, pk = nil, sequence_name = nil) execute to_sql(sql, binds), name end
# File activerecord/lib/active_record/connection_adapters/mysql2_adapter.rb, line 220 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
exec_update(sql, name, binds)
Alias for: exec_delete
exec_without_stmt(sql, name = 'SQL', binds = [])
Alias for: exec_query
# File activerecord/lib/active_record/connection_adapters/mysql2_adapter.rb, line 212 def execute(sql, name = nil) # 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 super end
Executes the SQL statement in the context of this connection.
Calls superclass method ActiveRecord::ConnectionAdapters::AbstractMysqlAdapter#execute
# File activerecord/lib/active_record/connection_adapters/mysql2_adapter.rb, line 103 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
# File activerecord/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
# File activerecord/lib/active_record/connection_adapters/mysql2_adapter.rb, line 227 def insert_sql(sql, name = nil, pk = nil, id_value = nil, sequence_name = nil) super id_value || @connection.last_id end
Calls superclass method
Also aliased as: create
# File activerecord/lib/active_record/connection_adapters/mysql2_adapter.rb, line 243 def last_inserted_id(result) @connection.last_id end
# File activerecord/lib/active_record/connection_adapters/mysql2_adapter.rb, line 73 def quote_string(string) @connection.escape(string) end
# File activerecord/lib/active_record/connection_adapters/mysql2_adapter.rb, line 85 def reconnect! super disconnect! connect end
Calls superclass method ActiveRecord::ConnectionAdapters::AbstractAdapter#reconnect!
Also aliased as: reset!
reset!()
Alias for: reconnect!
# File activerecord/lib/active_record/connection_adapters/mysql2_adapter.rb, line 207 def select_rows(sql, name = nil, binds = []) execute(sql, name).to_a end
Returns an array of arrays containing the field values. Order is the same as that returned by columns
.
# File activerecord/lib/active_record/connection_adapters/mysql2_adapter.rb, line 49 def supports_explain? true end
© 2004–2018 David Heinemeier Hansson
Licensed under the MIT License.