class Sequel::Mysql2::Database

  1. lib/sequel/adapters/mysql2.rb
Superclass: Sequel::Database

Attributes

convert_tinyint_to_bool [RW]

Whether to convert tinyint columns to bool for this database

Public Instance methods

connect(server)

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.

[show source]
   # File lib/sequel/adapters/mysql2.rb
37 def connect(server)
38   opts = server_opts(server)
39   opts[:username] ||= opts.delete(:user)
40   opts[:flags] ||= 0
41   opts[:flags] |= ::Mysql2::Client::FOUND_ROWS if ::Mysql2::Client.const_defined?(:FOUND_ROWS)
42   opts[:encoding] ||= opts[:charset]
43   conn = ::Mysql2::Client.new(opts)
44   conn.query_options.merge!(:symbolize_keys=>true, :cache_rows=>false)
45     
46   if NativePreparedStatements
47     conn.instance_variable_set(:@sequel_default_query_options, conn.query_options.dup)
48   end
49 
50   sqls = mysql_connection_setting_sqls
51 
52   # Set encoding a slightly different way after connecting,
53   # in case the READ_DEFAULT_GROUP overrode the provided encoding.
54   # Doesn't work across implicit reconnects, but Sequel doesn't turn on
55   # that feature.
56   if encoding = opts[:encoding]
57     sqls.unshift("SET NAMES #{conn.escape(encoding.to_s)}")
58   end
59 
60   sqls.each{|sql| log_connection_yield(sql, conn){conn.query(sql)}}
61 
62   add_prepared_statements_cache(conn)
63   conn
64 end
execute_dui(sql, opts=OPTS)
[show source]
   # File lib/sequel/adapters/mysql2.rb
66 def execute_dui(sql, opts=OPTS)
67   execute(sql, opts){|c| return c.affected_rows}
68 end
execute_insert(sql, opts=OPTS)
[show source]
   # File lib/sequel/adapters/mysql2.rb
70 def execute_insert(sql, opts=OPTS)
71   execute(sql, opts){|c| return c.last_id}
72 end
freeze()
[show source]
   # File lib/sequel/adapters/mysql2.rb
74 def freeze
75   server_version
76   super
77 end
server_version(_server=nil)

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

[show source]
   # File lib/sequel/adapters/mysql2.rb
80 def server_version(_server=nil)
81   @server_version ||= super()
82 end