Parent

Files

Class Index [+]

Quicksearch

ActiveRecord::ConnectionAdapters::Mysql2Adapter

Constants

ADAPTER_NAME

Public Class Methods

new(connection, logger, connection_options, config) click to toggle source
    # File lib/active_record/connection_adapters/mysql2_adapter.rb, line 33
33:       def initialize(connection, logger, connection_options, config)
34:         super
35:         @visitor = BindSubstitution.new self
36:         configure_connection
37:       end

Public Instance Methods

active?() click to toggle source

CONNECTION MANAGEMENT ====================================

    # File lib/active_record/connection_adapters/mysql2_adapter.rb, line 71
71:       def active?
72:         return false unless @connection
73:         @connection.ping
74:       end
create(sql, name = nil, pk = nil, id_value = nil, sequence_name = nil) click to toggle source
Alias for: insert_sql
disconnect!() click to toggle source

Disconnects from the database if already connected. Otherwise, this method does nothing.

    # File lib/active_record/connection_adapters/mysql2_adapter.rb, line 83
83:       def disconnect!
84:         unless @connection.nil?
85:           @connection.close
86:           @connection = nil
87:         end
88:       end
error_number(exception) click to toggle source
    # File lib/active_record/connection_adapters/mysql2_adapter.rb, line 59
59:       def error_number(exception)
60:         exception.error_number if exception.respond_to?(:error_number)
61:       end
exec_delete(sql, name, binds) click to toggle source
     # File lib/active_record/connection_adapters/mysql2_adapter.rb, line 237
237:       def exec_delete(sql, name, binds)
238:         execute to_sql(sql, binds), name
239:         @connection.affected_rows
240:       end
Also aliased as: exec_update
exec_insert(sql, name, binds) click to toggle source
     # File lib/active_record/connection_adapters/mysql2_adapter.rb, line 233
233:       def exec_insert(sql, name, binds)
234:         execute to_sql(sql, binds), name
235:       end
exec_query(sql, name = 'SQL', binds = []) click to toggle source
     # File lib/active_record/connection_adapters/mysql2_adapter.rb, line 214
214:       def exec_query(sql, name = 'SQL', binds = [])
215:         result = execute(sql, name)
216:         ActiveRecord::Result.new(result.fields, result.to_a)
217:       end
Also aliased as: exec_without_stmt
exec_update(sql, name, binds) click to toggle source
Alias for: exec_delete
exec_without_stmt(sql, name = 'SQL', binds = []) click to toggle source
Alias for: exec_query
execute(sql, name = nil) click to toggle source

Executes the SQL statement in the context of this connection.

     # File lib/active_record/connection_adapters/mysql2_adapter.rb, line 206
206:       def execute(sql, name = nil)
207:         # make sure we carry over any changes to ActiveRecord::Base.default_timezone that have been
208:         # made since we established the connection
209:         @connection.query_options[:database_timezone] = ActiveRecord::Base.default_timezone
210: 
211:         super
212:       end
explain(arel, binds = []) click to toggle source

DATABASE STATEMENTS ======================================

     # File lib/active_record/connection_adapters/mysql2_adapter.rb, line 97
 97:       def explain(arel, binds = [])
 98:         sql     = "EXPLAIN #{to_sql(arel, binds.dup)}"
 99:         start   = Time.now
100:         result  = exec_query(sql, 'EXPLAIN', binds)
101:         elapsed = Time.now - start
102: 
103:         ExplainPrettyPrinter.new.pp(result, elapsed)
104:       end
insert_sql(sql, name = nil, pk = nil, id_value = nil, sequence_name = nil) click to toggle source
     # File lib/active_record/connection_adapters/mysql2_adapter.rb, line 227
227:       def insert_sql(sql, name = nil, pk = nil, id_value = nil, sequence_name = nil)
228:         super
229:         id_value || @connection.last_id
230:       end
Also aliased as: create
last_inserted_id(result) click to toggle source
     # File lib/active_record/connection_adapters/mysql2_adapter.rb, line 243
243:       def last_inserted_id(result)
244:         @connection.last_id
245:       end
quote_string(string) click to toggle source

QUOTING ==================================================

    # File lib/active_record/connection_adapters/mysql2_adapter.rb, line 65
65:       def quote_string(string)
66:         @connection.escape(string)
67:       end
reconnect!() click to toggle source
    # File lib/active_record/connection_adapters/mysql2_adapter.rb, line 76
76:       def reconnect!
77:         disconnect!
78:         connect
79:       end
reset!() click to toggle source
    # File lib/active_record/connection_adapters/mysql2_adapter.rb, line 90
90:       def reset!
91:         disconnect!
92:         connect
93:       end
select(sql, name = nil, binds = []) click to toggle source

Returns an array of record hashes with the column names as keys and column values as values.

     # File lib/active_record/connection_adapters/mysql2_adapter.rb, line 223
223:       def select(sql, name = nil, binds = [])
224:         exec_query(sql, name).to_a
225:       end
select_rows(sql, name = nil) 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 201
201:       def select_rows(sql, name = nil)
202:         execute(sql, name).to_a
203:       end
supports_explain?() click to toggle source
    # File lib/active_record/connection_adapters/mysql2_adapter.rb, line 39
39:       def supports_explain?
40:         true
41:       end

Private Instance Methods

configure_connection() click to toggle source
     # File lib/active_record/connection_adapters/mysql2_adapter.rb, line 254
254:       def configure_connection
255:         @connection.query_options.merge!(:as => :array)
256: 
257:         # By default, MySQL 'where id is null' selects the last inserted id.
258:         # Turn this off. http://dev.rubyonrails.org/ticket/6778
259:         variable_assignments = ['SQL_AUTO_IS_NULL=0']
260:         encoding = @config[:encoding]
261: 
262:         # make sure we set the encoding
263:         variable_assignments << "NAMES '#{encoding}'" if encoding
264: 
265:         # increase timeout so mysql server doesn't disconnect us
266:         wait_timeout = @config[:wait_timeout]
267:         wait_timeout = 2147483 unless wait_timeout.is_a?(Fixnum)
268:         variable_assignments << "@@wait_timeout = #{wait_timeout}"
269: 
270:         execute("SET #{variable_assignments.join(', ')}", :skip_logging)
271:       end
connect() click to toggle source
     # File lib/active_record/connection_adapters/mysql2_adapter.rb, line 249
249:       def connect
250:         @connection = Mysql2::Client.new(@config)
251:         configure_connection
252:       end
version() click to toggle source
     # File lib/active_record/connection_adapters/mysql2_adapter.rb, line 273
273:       def version
274:         @version ||= @connection.info[:version].scan(/^(\d+)\.(\d+)\.(\d+)/).flatten.map { |v| v.to_i }
275:       end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.