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)/ | Mysql::Error messages that indicate the current connection should be disconnected |
Connect to the database. In addition to the usual database options, the following options have effect:
# File lib/sequel/adapters/mysql2.rb, line 36 36: def connect(server) 37: opts = server_opts(server) 38: opts[:host] ||= 'localhost' 39: opts[:username] ||= opts[:user] 40: conn = ::Mysql2::Client.new(opts) 41: 42: sqls = [] 43: # Set encoding a slightly different way after connecting, 44: # in case the READ_DEFAULT_GROUP overrode the provided encoding. 45: # Doesn't work across implicit reconnects, but Sequel doesn't turn on 46: # that feature. 47: if encoding = opts[:encoding] || opts[:charset] 48: sqls << "SET NAMES #{conn.escape(encoding.to_s)}" 49: end 50: 51: # Increase timeout so mysql server doesn't disconnect us. 52: # Value used by default is maximum allowed value on Windows. 53: sqls << "SET @@wait_timeout = #{opts[:timeout] || 2147483}" 54: 55: # By default, MySQL 'where id is null' selects the last inserted id 56: sqls << "SET SQL_AUTO_IS_NULL=0" unless opts[:auto_is_null] 57: 58: sqls.each{|sql| log_yield(sql){conn.query(sql)}} 59: 60: conn 61: end
Returns instance of Sequel::MySQL::Dataset with the given options.
# File lib/sequel/adapters/mysql2.rb, line 64 64: def dataset(opts = nil) 65: Mysql2::Dataset.new(self, opts) 66: end
Executes the given SQL using an available connection, yielding the connection if the block is given.
# File lib/sequel/adapters/mysql2.rb, line 70 70: def execute(sql, opts={}, &block) 71: if opts[:sproc] 72: call_sproc(sql, opts, &block) 73: else 74: synchronize(opts[:server]){|conn| _execute(conn, sql, opts, &block)} 75: end 76: end