Module Sequel::MySQL::DatabaseMethods
In: lib/sequel/adapters/shared/mysql.rb

Methods shared by Database instances that connect to MySQL, currently supported by the native and JDBC adapters.

Methods

Constants

AUTO_INCREMENT = 'AUTO_INCREMENT'.freeze
CAST_TYPES = {String=>:CHAR, Integer=>:SIGNED, Time=>:DATETIME, DateTime=>:DATETIME, Numeric=>:DECIMAL, BigDecimal=>:DECIMAL, File=>:BINARY}
PRIMARY = 'PRIMARY'.freeze

Public Instance methods

MySQL‘s cast rules are restrictive in that you can‘t just cast to any possible database type.

[Source]

    # File lib/sequel/adapters/shared/mysql.rb, line 23
23:       def cast_type_literal(type)
24:         CAST_TYPES[type] || super
25:       end

MySQL uses the :mysql database type

[Source]

    # File lib/sequel/adapters/shared/mysql.rb, line 28
28:       def database_type
29:         :mysql
30:       end

Return a hash containing index information. Hash keys are index name symbols. Values are subhashes with two keys, :columns and :unique. The value of :columns is an array of symbols of column names. The value of :unique is true or false depending on if the index is unique.

[Source]

    # File lib/sequel/adapters/shared/mysql.rb, line 36
36:       def indexes(table)
37:         indexes = {}
38:         m = output_identifier_meth
39:         im = input_identifier_meth
40:         metadata_dataset.with_sql("SHOW INDEX FROM ?", SQL::Identifier.new(im.call(table))).each do |r|
41:           name = r[:Key_name]
42:           next if name == PRIMARY
43:           i = indexes[m.call(name)] ||= {:columns=>[], :unique=>r[:Non_unique] != 1}
44:           i[:columns] << m.call(r[:Column_name])
45:         end
46:         indexes
47:       end

Get version of MySQL server, used for determined capabilities.

[Source]

    # File lib/sequel/adapters/shared/mysql.rb, line 50
50:       def server_version
51:         m = /(\d+)\.(\d+)\.(\d+)/.match(get(SQL::Function.new(:version)))
52:         @server_version ||= (m[1].to_i * 10000) + (m[2].to_i * 100) + m[3].to_i
53:       end

Return an array of symbols specifying table names in the current database.

Options:

  • :server - Set the server to use

[Source]

    # File lib/sequel/adapters/shared/mysql.rb, line 59
59:       def tables(opts={})
60:         m = output_identifier_meth
61:         metadata_dataset.with_sql('SHOW TABLES').server(opts[:server]).map{|r| m.call(r.values.first)}
62:       end

Changes the database in use by issuing a USE statement. I would be very careful if I used this.

[Source]

    # File lib/sequel/adapters/shared/mysql.rb, line 66
66:       def use(db_name)
67:         disconnect
68:         @opts[:database] = db_name if self << "USE #{db_name}"
69:         @schemas = nil
70:         self
71:       end

[Validate]