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 commit_prepared_transaction database_type indexes rollback_prepared_transaction server_version supports_prepared_transactions? supports_savepoints? supports_transaction_isolation_levels? 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 37
    37:       def cast_type_literal(type)
    38:         CAST_TYPES[type] || super
    39:       end

commit_prepared_transaction(transaction_id)

Commit an existing prepared transaction with the given transaction identifier string.

[Source]

        # File lib/sequel/adapters/shared/mysql.rb, line 43
    43:       def commit_prepared_transaction(transaction_id)
    44:         run("XA COMMIT #{literal(transaction_id)}")
    45:       end

database_type()

MySQL uses the :mysql database type

[Source]

        # File lib/sequel/adapters/shared/mysql.rb, line 48
    48:       def database_type
    49:         :mysql
    50:       end

indexes(table, opts={})

Use SHOW INDEX FROM to get the index information for the table.

[Source]

        # File lib/sequel/adapters/shared/mysql.rb, line 53
    53:       def indexes(table, opts={})
    54:         indexes = {}
    55:         remove_indexes = []
    56:         m = output_identifier_meth
    57:         im = input_identifier_meth
    58:         metadata_dataset.with_sql("SHOW INDEX FROM ?", SQL::Identifier.new(im.call(table))).each do |r|
    59:           name = r[:Key_name]
    60:           next if name == PRIMARY
    61:           name = m.call(name)
    62:           remove_indexes << name if r[:Sub_part]
    63:           i = indexes[name] ||= {:columns=>[], :unique=>r[:Non_unique] != 1}
    64:           i[:columns] << m.call(r[:Column_name])
    65:         end
    66:         indexes.reject{|k,v| remove_indexes.include?(k)}
    67:       end

rollback_prepared_transaction(transaction_id)

Rollback an existing prepared transaction with the given transaction identifier string.

[Source]

        # File lib/sequel/adapters/shared/mysql.rb, line 71
    71:       def rollback_prepared_transaction(transaction_id)
    72:         run("XA ROLLBACK #{literal(transaction_id)}")
    73:       end

server_version()

Get version of MySQL server, used for determined capabilities.

[Source]

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

supports_prepared_transactions?()

MySQL supports prepared transactions (two-phase commit) using XA

[Source]

        # File lib/sequel/adapters/shared/mysql.rb, line 91
    91:       def supports_prepared_transactions?
    92:         true
    93:       end

supports_savepoints?()

MySQL supports savepoints

[Source]

        # File lib/sequel/adapters/shared/mysql.rb, line 96
    96:       def supports_savepoints?
    97:         true
    98:       end

supports_transaction_isolation_levels?()

MySQL supports transaction isolation levels

[Source]

         # File lib/sequel/adapters/shared/mysql.rb, line 101
    101:       def supports_transaction_isolation_levels?
    102:         true
    103:       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 85
    85:       def tables(opts={})
    86:         m = output_identifier_meth
    87:         metadata_dataset.with_sql('SHOW TABLES').server(opts[:server]).map{|r| m.call(r.values.first)}
    88:       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 107
    107:       def use(db_name)
    108:         disconnect
    109:         @opts[:database] = db_name if self << "USE #{db_name}"
    110:         @schemas = {}
    111:         self
    112:       end

[Validate]