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}
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 29
29:       def cast_type_literal(type)
30:         CAST_TYPES[type] || super
31:       end

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

[Source]

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

MySQL uses the :mysql database type

[Source]

    # File lib/sequel/adapters/shared/mysql.rb, line 40
40:       def database_type
41:         :mysql
42:       end

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

[Source]

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

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

[Source]

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

Get version of MySQL server, used for determined capabilities.

[Source]

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

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

[Source]

    # File lib/sequel/adapters/shared/mysql.rb, line 83
83:       def supports_prepared_transactions?
84:         true
85:       end

MySQL supports savepoints

[Source]

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

MySQL supports transaction isolation levels

[Source]

    # File lib/sequel/adapters/shared/mysql.rb, line 93
93:       def supports_transaction_isolation_levels?
94:         true
95:       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 77
77:       def tables(opts={})
78:         m = output_identifier_meth
79:         metadata_dataset.with_sql('SHOW TABLES').server(opts[:server]).map{|r| m.call(r.values.first)}
80:       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 99
 99:       def use(db_name)
100:         disconnect
101:         @opts[:database] = db_name if self << "USE #{db_name}"
102:         @schemas = {}
103:         self
104:       end

[Validate]