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 17
17:       def cast_type_literal(type)
18:         CAST_TYPES[type] || super
19:       end

MySQL uses the :mysql database type

[Source]

    # File lib/sequel/adapters/shared/mysql.rb, line 22
22:       def database_type
23:         :mysql
24:       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.

Does not include the primary key index or indexes on partial keys.

[Source]

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

Get version of MySQL server, used for determined capabilities.

[Source]

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

MySQL supports savepoints

[Source]

    # File lib/sequel/adapters/shared/mysql.rb, line 64
64:       def supports_savepoints?
65:         true
66:       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 58
58:       def tables(opts={})
59:         m = output_identifier_meth
60:         metadata_dataset.with_sql('SHOW TABLES').server(opts[:server]).map{|r| m.call(r.values.first)}
61:       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 70
70:       def use(db_name)
71:         disconnect
72:         @opts[:database] = db_name if self << "USE #{db_name}"
73:         @schemas = {}
74:         self
75:       end

[Validate]