Class | Sequel::Mysql2::Database |
In: |
lib/sequel/adapters/mysql2.rb
|
Parent: | Sequel::Database |
MYSQL_DATABASE_DISCONNECT_ERRORS | = | /\A(Commands out of sync; you can't run this command now|Can't connect to local MySQL server through socket|MySQL server has gone away|This connection is still waiting for a result, try again once you have the result|closed MySQL connection)/ | Mysql::Error messages that indicate the current connection should be disconnected |
convert_tinyint_to_bool | [RW] | Whether to convert tinyint columns to bool for this database |
Set the convert_tinyint_to_bool setting based on the default value.
# File lib/sequel/adapters/mysql2.rb, line 21 21: def initialize(opts={}) 22: super 23: self.convert_tinyint_to_bool = Sequel::MySQL.convert_tinyint_to_bool 24: end
Connect to the database. In addition to the usual database options, the following options have effect:
# File lib/sequel/adapters/mysql2.rb, line 44 44: def connect(server) 45: opts = server_opts(server) 46: opts[:host] ||= 'localhost' 47: opts[:username] ||= opts[:user] 48: opts[:flags] = ::Mysql2::Client::FOUND_ROWS if ::Mysql2::Client.const_defined?(:FOUND_ROWS) 49: conn = ::Mysql2::Client.new(opts) 50: 51: sqls = mysql_connection_setting_sqls 52: 53: # Set encoding a slightly different way after connecting, 54: # in case the READ_DEFAULT_GROUP overrode the provided encoding. 55: # Doesn't work across implicit reconnects, but Sequel doesn't turn on 56: # that feature. 57: if encoding = opts[:encoding] || opts[:charset] 58: sqls.unshift("SET NAMES #{conn.escape(encoding.to_s)}") 59: end 60: 61: sqls.each{|sql| log_yield(sql){conn.query(sql)}} 62: 63: add_prepared_statements_cache(conn) 64: conn 65: end
Return the number of matched rows when executing a delete/update statement.
# File lib/sequel/adapters/mysql2.rb, line 68 68: def execute_dui(sql, opts={}) 69: execute(sql, opts){|c| return c.affected_rows} 70: end
Return the last inserted id when executing an insert statement.
# File lib/sequel/adapters/mysql2.rb, line 73 73: def execute_insert(sql, opts={}) 74: execute(sql, opts){|c| return c.last_id} 75: end