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

cast_type_literal database_type indexes server_version supports_savepoints? tables use

### 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

cast_type_literal(type)

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 20
    20:       def cast_type_literal(type)
    21:         CAST_TYPES[type] || super
    22:       end

database_type()

MySQL uses the :mysql database type

[Source]

        # File lib/sequel/adapters/shared/mysql.rb, line 25
    25:       def database_type
    26:         :mysql
    27:       end

indexes(table)

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 35
    35:       def indexes(table)
    36:         indexes = {}
    37:         remove_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:           name = m.call(name)
    44:           remove_indexes << name if r[:Sub_part]
    45:           i = indexes[name] ||= {:columns=>[], :unique=>r[:Non_unique] != 1}
    46:           i[:columns] << m.call(r[:Column_name])
    47:         end
    48:         indexes.reject{|k,v| remove_indexes.include?(k)}
    49:       end

server_version()

Get version of MySQL server, used for determined capabilities.

[Source]

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

supports_savepoints?()

MySQL supports savepoints

[Source]

        # File lib/sequel/adapters/shared/mysql.rb, line 67
    67:       def supports_savepoints?
    68:         true
    69:       end

tables(opts={})

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 61
    61:       def tables(opts={})
    62:         m = output_identifier_meth
    63:         metadata_dataset.with_sql('SHOW TABLES').server(opts[:server]).map{|r| m.call(r.values.first)}
    64:       end

use(db_name)

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 73
    73:       def use(db_name)
    74:         disconnect
    75:         @opts[:database] = db_name if self << "USE #{db_name}"
    76:         @schemas = {}
    77:         self
    78:       end

[Validate]