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_create_table_if_not_exists? supports_prepared_transactions? supports_savepoints? supports_transaction_isolation_levels? tables use views

### Constants

AUTO_INCREMENT | = | 'AUTO_INCREMENT'.freeze
CAST_TYPES | = | {String=>:CHAR, Integer=>:SIGNED, Time=>:DATETIME, DateTime=>:DATETIME, Numeric=>:DECIMAL, BigDecimal=>:DECIMAL, File=>:BINARY}
COLUMN_DEFINITION_ORDER | = | [:null, :default, :unique, :primary_key, :auto_increment, :references]
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 39
    39:       def cast_type_literal(type)
    40:         CAST_TYPES[type] || super
    41:       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 45
    45:       def commit_prepared_transaction(transaction_id)
    46:         run("XA COMMIT #{literal(transaction_id)}")
    47:       end

database_type()

MySQL uses the :mysql database type

[Source]

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

indexes(table, opts={})

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

By default partial indexes are not included, you can use the option :partial to override this.

[Source]

        # File lib/sequel/adapters/shared/mysql.rb, line 59
    59:       def indexes(table, opts={})
    60:         indexes = {}
    61:         remove_indexes = []
    62:         m = output_identifier_meth
    63:         im = input_identifier_meth
    64:         metadata_dataset.with_sql("SHOW INDEX FROM ?", SQL::Identifier.new(im.call(table))).each do |r|
    65:           name = r[:Key_name]
    66:           next if name == PRIMARY
    67:           name = m.call(name)
    68:           remove_indexes << name if r[:Sub_part] && ! opts[:partial]
    69:           i = indexes[name] ||= {:columns=>[], :unique=>r[:Non_unique] != 1}
    70:           i[:columns] << m.call(r[:Column_name])
    71:         end
    72:         indexes.reject{|k,v| remove_indexes.include?(k)}
    73:       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 77
    77:       def rollback_prepared_transaction(transaction_id)
    78:         run("XA ROLLBACK #{literal(transaction_id)}")
    79:       end

server_version()

Get version of MySQL server, used for determined capabilities.

[Source]

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

supports_create_table_if_not_exists?()

MySQL supports CREATE TABLE IF NOT EXISTS syntax.

[Source]

        # File lib/sequel/adapters/shared/mysql.rb, line 88
    88:       def supports_create_table_if_not_exists?
    89:         true
    90:       end

supports_prepared_transactions?()

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

[Source]

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

supports_savepoints?()

MySQL supports savepoints

[Source]

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

supports_transaction_isolation_levels?()

MySQL supports transaction isolation levels

[Source]

         # File lib/sequel/adapters/shared/mysql.rb, line 103
    103:       def supports_transaction_isolation_levels?
    104:         true
    105:       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 111
    111:       def tables(opts={})
    112:         full_tables('BASE TABLE', opts)
    113:       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 117
    117:       def use(db_name)
    118:         disconnect
    119:         @opts[:database] = db_name if self << "USE #{db_name}"
    120:         @schemas = {}
    121:         self
    122:       end

views(opts={})

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

Options:

- :server - Set the server to use

[Source]

         # File lib/sequel/adapters/shared/mysql.rb, line 128
    128:       def views(opts={})
    129:         full_tables('VIEW', opts)
    130:       end

[Validate]