Class/Module Index [+]

Quicksearch

Sequel::MySQL::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

Public Instance Methods

call_sproc(name, opts={}, &block) click to toggle source

Support stored procedures on MySQL

# File lib/sequel/adapters/mysql.rb, line 75
def call_sproc(name, opts={}, &block)
  args = opts[:args] || [] 
  execute("CALL #{name}#{args.empty? ? '()' : literal(args)}", opts.merge(:sproc=>false), &block)
end
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)

  • :compress - Set to false to not compress results from the server

  • :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.

  • :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.

# File lib/sequel/adapters/mysql.rb, line 97
def connect(server)
  opts = server_opts(server)
  conn = Mysql.init
  conn.options(Mysql::READ_DEFAULT_GROUP, opts[:config_default_group] || "client")
  conn.options(Mysql::OPT_LOCAL_INFILE, opts[:config_local_infile]) if opts.has_key?(:config_local_infile)
  conn.real_connect(
    opts[:host] || 'localhost',
    opts[:user],
    opts[:password],
    opts[:database],
    opts[:port],
    opts[:socket],
    Mysql::CLIENT_MULTI_RESULTS +
    Mysql::CLIENT_MULTI_STATEMENTS +
    (opts[:compress] == false ? 0 : Mysql::CLIENT_COMPRESS)
  )
  if encoding = opts[:encoding] || opts[:charset]
    # Setting encoding before the connect appears not to work
    # with READ_DEFAULT_GROUP, so set it afterwards.
    conn.options(Mysql::SET_CHARSET_NAME, encoding)
  end

  # increase timeout so mysql server doesn't disconnect us
  conn.query("set @@wait_timeout = #{opts[:timeout] || 2592000}")

  # By default, MySQL 'where id is null' selects the last inserted id
  conn.query("set SQL_AUTO_IS_NULL=0") unless opts[:auto_is_null]
  
  class << conn
    attr_accessor :prepared_statements
  end
  conn.prepared_statements = {}
  conn
end
dataset(opts = nil) click to toggle source

Returns instance of Sequel::MySQL::Dataset with the given options.

# File lib/sequel/adapters/mysql.rb, line 133
def dataset(opts = nil)
  MySQL::Dataset.new(self, opts)
end
execute(sql, opts={}, &block) click to toggle source

Executes the given SQL using an available connection, yielding the connection if the block is given.

# File lib/sequel/adapters/mysql.rb, line 139
def execute(sql, opts={}, &block)
  if opts[:sproc]
    call_sproc(sql, opts, &block)
  elsif sql.is_a?(Symbol)
    execute_prepared_statement(sql, opts, &block)
  else
    synchronize(opts[:server]){|conn| _execute(conn, sql, opts, &block)}
  end
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/mysql.rb, line 150
def server_version(server=nil)
  @server_version ||= (synchronize(server){|conn| conn.server_version if conn.respond_to?(:server_version)} || super)
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.