| 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 34
34: def connect(server)
35: opts = server_opts(server)
36: opts[:host] ||= 'localhost'
37: opts[:username] ||= opts[:user]
38: conn = ::Mysql2::Client.new(opts)
39:
40: sqls = []
41: # Set encoding a slightly different way after connecting,
42: # in case the READ_DEFAULT_GROUP overrode the provided encoding.
43: # Doesn't work across implicit reconnects, but Sequel doesn't turn on
44: # that feature.
45: if encoding = opts[:encoding] || opts[:charset]
46: sqls << "SET NAMES #{conn.escape(encoding.to_s)}"
47: end
48:
49: # increase timeout so mysql server doesn't disconnect us
50: sqls << "SET @@wait_timeout = #{opts[:timeout] || 2592000}"
51:
52: # By default, MySQL 'where id is null' selects the last inserted id
53: sqls << "SET SQL_AUTO_IS_NULL=0" unless opts[:auto_is_null]
54:
55: sqls.each{|sql| log_yield(sql){conn.query(sql)}}
56:
57: conn
58: end
Returns instance of Sequel::MySQL::Dataset with the given options.
# File lib/sequel/adapters/mysql2.rb, line 61
61: def dataset(opts = nil)
62: Mysql2::Dataset.new(self, opts)
63: end
Executes the given SQL using an available connection, yielding the connection if the block is given.
# File lib/sequel/adapters/mysql2.rb, line 67
67: def execute(sql, opts={}, &block)
68: if opts[:sproc]
69: call_sproc(sql, opts, &block)
70: else
71: synchronize(opts[:server]){|conn| _execute(conn, sql, opts, &block)}
72: end
73: end