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 39
39:       def cast_type_literal(type)
40:         CAST_TYPES[type] || super
41:       end

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

MySQL uses the :mysql database type

[Source]

    # File lib/sequel/adapters/shared/mysql.rb, line 50
50:       def database_type
51:         :mysql
52:       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 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 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

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

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

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

MySQL supports savepoints

[Source]

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

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

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

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

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]