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}
COLUMN_DEFINITION_ORDER = [:null, :default, :unique, :primary_key, :auto_increment, :references]
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 38
38:       def cast_type_literal(type)
39:         CAST_TYPES[type] || super
40:       end

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

[Source]

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

MySQL uses the :mysql database type

[Source]

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

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 58
58:       def indexes(table, opts={})
59:         indexes = {}
60:         remove_indexes = []
61:         m = output_identifier_meth
62:         im = input_identifier_meth
63:         metadata_dataset.with_sql("SHOW INDEX FROM ?", SQL::Identifier.new(im.call(table))).each do |r|
64:           name = r[:Key_name]
65:           next if name == PRIMARY
66:           name = m.call(name)
67:           remove_indexes << name if r[:Sub_part] && ! opts[:partial]
68:           i = indexes[name] ||= {:columns=>[], :unique=>r[:Non_unique] != 1}
69:           i[:columns] << m.call(r[:Column_name])
70:         end
71:         indexes.reject{|k,v| remove_indexes.include?(k)}
72:       end

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

[Source]

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

Get version of MySQL server, used for determined capabilities.

[Source]

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

MySQL supports CREATE TABLE IF NOT EXISTS syntax.

[Source]

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

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

[Source]

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

MySQL supports savepoints

[Source]

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

MySQL supports transaction isolation levels

[Source]

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

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 127
127:       def views(opts={})
128:         full_tables('VIEW', opts)
129:       end

[Validate]