Class/Module Index [+]

Quicksearch

Sequel::Mysql2::Database

Database class for MySQL databases used with Sequel.

Constants

MYSQL_DATABASE_DISCONNECT_ERRORS

Mysql::Error messages that indicate the current connection should be disconnected

Attributes

convert_tinyint_to_bool[RW]

Whether to convert tinyint columns to bool for this database

Public Class Methods

new(opts={}) click to toggle source

Set the convert_tinyint_to_bool setting based on the default value.

# File lib/sequel/adapters/mysql2.rb, line 21
def initialize(opts={})
  super
  self.convert_tinyint_to_bool = Sequel::MySQL.convert_tinyint_to_bool
end

Public Instance Methods

connect(server) click to toggle source

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)

  • :config_default_group - The default group to read from the in the MySQL config file.

  • :config_local_infile - If provided, sets the Mysql::OPT_LOCAL_INFILE option on the connection with the given value.

  • :connect_timeout - Set the timeout in seconds before a connection attempt is abandoned.

  • :encoding - Set all the related character sets for this connection (connection, client, database, server, and results).

  • :socket - Use a unix socket file instead of connecting via TCP/IP.

  • :timeout - Set the timeout in seconds before the server will disconnect this connection (a.k.a. @@wait_timeout).

# File lib/sequel/adapters/mysql2.rb, line 44
def connect(server)
  opts = server_opts(server)
  opts[:host] ||= 'localhost'
  opts[:username] ||= opts[:user]
  conn = ::Mysql2::Client.new(opts)

  sqls = []
  # Set encoding a slightly different way after connecting,
  # in case the READ_DEFAULT_GROUP overrode the provided encoding.
  # Doesn't work across implicit reconnects, but Sequel doesn't turn on
  # that feature.
  if encoding = opts[:encoding] || opts[:charset]
    sqls << "SET NAMES #{conn.escape(encoding.to_s)}"
  end

  # Increase timeout so mysql server doesn't disconnect us.
  # Value used by default is maximum allowed value on Windows.
  sqls << "SET @@wait_timeout = #{opts[:timeout] || 2147483}"

  # By default, MySQL 'where id is null' selects the last inserted id
  sqls << "SET SQL_AUTO_IS_NULL=0" unless opts[:auto_is_null]

  sqls.each{|sql| log_yield(sql){conn.query(sql)}}

  add_prepared_statements_cache(conn)
  conn
end
server_version(server=nil) click to toggle source

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

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

[Validate]

Generated with the Darkfish Rdoc Generator 2.