Class: ActiveRecord::ConnectionAdapters::NeverBlockMysqlAdapter

Inherits:
MysqlAdapter
  • Object
show all
Defined in:
lib/active_record/connection_adapters/neverblock_mysql_adapter.rb

Instance Method Summary collapse

Instance Method Details

#adapter_nameObject

Returns ‘NeverBlockMySQL’ as adapter name for identification purposes



9
10
11
# File 'lib/active_record/connection_adapters/neverblock_mysql_adapter.rb', line 9

def adapter_name
  'NeverBlockMySQL'
end

#connectObject



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/active_record/connection_adapters/neverblock_mysql_adapter.rb', line 23

def connect
  #initialize the connection pool
  unless @connection
    @connection = ::NB::DB::PooledDBConnection.new(@connection_options[0]) do
      conn = ::NB::DB::FMysql.init
      encoding = @config[:encoding]
      if encoding
        conn.options(::NB::DB::FMysql::SET_CHARSET_NAME, encoding) rescue nil
      end
      conn.ssl_set(@config[:sslkey], @config[:sslcert], @config[:sslca], @config[:sslcapath], @config[:sslcipher]) if @config[:sslkey]
      conn.real_connect(*@connection_options[1..(@connection_options.length-1)])
      NB.neverblock(false) do
        conn.query("SET NAMES '#{encoding}'") if encoding
        # By default, MySQL 'where id is null' selects the last inserted id.
        # Turn this off. http://dev.rubyonrails.org/ticket/6778
        conn.query("SET SQL_AUTO_IS_NULL=0")
      end
      conn
    end
  else  # we have a connection pool, we need to recover a connection
    @connection.replace_acquired_connection
  end
end

#insert_sql(sql, name = nil, pk = nil, id_value = nil, sequence_name = nil) ⇒ Object

:nodoc:



13
14
15
16
# File 'lib/active_record/connection_adapters/neverblock_mysql_adapter.rb', line 13

def insert_sql(sql, name = nil, pk = nil, id_value = nil, sequence_name = nil) #:nodoc:
  super sql, name
  id_value || @connection.insert_id
end

#update_sql(sql, name = nil) ⇒ Object

:nodoc:



18
19
20
21
# File 'lib/active_record/connection_adapters/neverblock_mysql_adapter.rb', line 18

def update_sql(sql, name = nil) #:nodoc:
  super
  @connection.affected_rows
end