Class Sequel::Mysql2::Database
In: lib/sequel/adapters/mysql2.rb
Parent: Sequel::Database

Database class for MySQL databases used with Sequel.

Methods

Included Modules

Sequel::MySQL::DatabaseMethods Sequel::MySQL::PreparedStatements::DatabaseMethods

Attributes

convert_tinyint_to_bool  [RW]  Whether to convert tinyint columns to bool for this database

Public Instance methods

Connect to the database. In addition to the usual database options, the following options have effect:

  • :auto_is_null - Set to true to use MySQL default behavior of having a filter for an autoincrement column equals NULL to return the last inserted row.
  • :charset - Same as :encoding (:encoding takes precendence)
  • :encoding - Set all the related character sets for this connection (connection, client, database, server, and results).

The options hash is also passed to mysql2, and can include mysql2 options such as :local_infile.

[Source]

    # File lib/sequel/adapters/mysql2.rb, line 29
29:       def connect(server)
30:         opts = server_opts(server)
31:         opts[:host] ||= 'localhost'
32:         opts[:username] ||= opts.delete(:user)
33:         opts[:flags] = ::Mysql2::Client::FOUND_ROWS if ::Mysql2::Client.const_defined?(:FOUND_ROWS)
34:         conn = ::Mysql2::Client.new(opts)
35:         conn.query_options.merge!(:symbolize_keys=>true, :cache_rows=>false)
36: 
37:         sqls = mysql_connection_setting_sqls
38: 
39:         # Set encoding a slightly different way after connecting,
40:         # in case the READ_DEFAULT_GROUP overrode the provided encoding.
41:         # Doesn't work across implicit reconnects, but Sequel doesn't turn on
42:         # that feature.
43:         if encoding = opts[:encoding] || opts[:charset]
44:           sqls.unshift("SET NAMES #{conn.escape(encoding.to_s)}")
45:         end
46: 
47:         sqls.each{|sql| log_yield(sql){conn.query(sql)}}
48: 
49:         add_prepared_statements_cache(conn)
50:         conn
51:       end

Return the number of matched rows when executing a delete/update statement.

[Source]

    # File lib/sequel/adapters/mysql2.rb, line 54
54:       def execute_dui(sql, opts=OPTS)
55:         execute(sql, opts){|c| return c.affected_rows}
56:       end

Return the last inserted id when executing an insert statement.

[Source]

    # File lib/sequel/adapters/mysql2.rb, line 59
59:       def execute_insert(sql, opts=OPTS)
60:         execute(sql, opts){|c| return c.last_id}
61:       end

Return the version of the MySQL server two which we are connecting.

[Source]

    # File lib/sequel/adapters/mysql2.rb, line 64
64:       def server_version(server=nil)
65:         @server_version ||= (synchronize(server){|conn| conn.server_info[:id]} || super)
66:       end

[Validate]