Module | Sequel::MySQL::DatabaseMethods |
In: |
lib/sequel/adapters/shared/mysql.rb
|
AUTO_INCREMENT | = | 'AUTO_INCREMENT'.freeze |
CAST_TYPES | = | {String=>:CHAR, Integer=>:SIGNED, Time=>:DATETIME, DateTime=>:DATETIME, Numeric=>:DECIMAL, BigDecimal=>:DECIMAL, File=>:BINARY} |
COLUMN_DEFINITION_ORDER | = | [:collate, :null, :default, :unique, :primary_key, :auto_increment, :references] |
PRIMARY | = | 'PRIMARY'.freeze |
MYSQL_TIMESTAMP_RE | = | /\ACURRENT_(?:DATE|TIMESTAMP)?\z/ |
DATABASE_ERROR_REGEXPS | = | { /Duplicate entry .+ for key/ => UniqueConstraintViolation, /foreign key constraint fails/ => ForeignKeyConstraintViolation, /cannot be null/ => NotNullConstraintViolation, /Deadlock found when trying to get lock; try restarting transaction/ => SerializationFailure, }.freeze |
Commit an existing prepared transaction with the given transaction identifier string.
# File lib/sequel/adapters/shared/mysql.rb, line 63 63: def commit_prepared_transaction(transaction_id, opts=OPTS) 64: run("XA COMMIT #{literal(transaction_id)}", opts) 65: end
Use the Information Schema‘s KEY_COLUMN_USAGE table to get basic information on foreign key columns, but include the constraint name.
# File lib/sequel/adapters/shared/mysql.rb, line 75 75: def foreign_key_list(table, opts=OPTS) 76: m = output_identifier_meth 77: im = input_identifier_meth 78: ds = metadata_dataset. 79: from(:INFORMATION_SCHEMA__KEY_COLUMN_USAGE). 80: where(:TABLE_NAME=>im.call(table), :TABLE_SCHEMA=>Sequel.function(:DATABASE)). 81: exclude(:CONSTRAINT_NAME=>'PRIMARY'). 82: exclude(:REFERENCED_TABLE_NAME=>nil). 83: select(:CONSTRAINT_NAME___name, :COLUMN_NAME___column, :REFERENCED_TABLE_NAME___table, :REFERENCED_COLUMN_NAME___key) 84: 85: h = {} 86: ds.each do |row| 87: if r = h[row[:name]] 88: r[:columns] << m.call(row[:column]) 89: r[:key] << m.call(row[:key]) 90: else 91: h[row[:name]] = {:name=>m.call(row[:name]), :columns=>[m.call(row[:column])], :table=>m.call(row[:table]), :key=>[m.call(row[:key])]} 92: end 93: end 94: h.values 95: 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.
# File lib/sequel/adapters/shared/mysql.rb, line 107 107: def indexes(table, opts=OPTS) 108: indexes = {} 109: remove_indexes = [] 110: m = output_identifier_meth 111: im = input_identifier_meth 112: metadata_dataset.with_sql("SHOW INDEX FROM ?", SQL::Identifier.new(im.call(table))).each do |r| 113: name = r[:Key_name] 114: next if name == PRIMARY 115: name = m.call(name) 116: remove_indexes << name if r[:Sub_part] && ! opts[:partial] 117: i = indexes[name] ||= {:columns=>[], :unique=>r[:Non_unique] != 1} 118: i[:columns] << m.call(r[:Column_name]) 119: end 120: indexes.reject{|k,v| remove_indexes.include?(k)} 121: end
Rollback an existing prepared transaction with the given transaction identifier string.
# File lib/sequel/adapters/shared/mysql.rb, line 125 125: def rollback_prepared_transaction(transaction_id, opts=OPTS) 126: run("XA ROLLBACK #{literal(transaction_id)}", opts) 127: end
Get version of MySQL server, used for determined capabilities.
# File lib/sequel/adapters/shared/mysql.rb, line 130 130: def server_version 131: @server_version ||= begin 132: m = /(\d+)\.(\d+)\.(\d+)/.match(get(SQL::Function.new(:version))) 133: (m[1].to_i * 10000) + (m[2].to_i * 100) + m[3].to_i 134: end 135: end
MySQL doesn‘t support savepoints inside prepared transactions in from 5.5.12 to 5.5.23, see bugs.mysql.com/bug.php?id=64374
# File lib/sequel/adapters/shared/mysql.rb, line 154 154: def supports_savepoints_in_prepared_transactions? 155: super && (server_version <= 50512 || server_version >= 50523) 156: end
Support fractional timestamps on MySQL 5.6.5+ if the :fractional_seconds Database option is used. Technically, MySQL 5.6.4+ supports them, but automatic initialization of datetime values wasn‘t supported to 5.6.5+, and this is related to that.
# File lib/sequel/adapters/shared/mysql.rb, line 162 162: def supports_timestamp_usecs? 163: @supports_timestamp_usecs ||= server_version >= 50605 && typecast_value_boolean(opts[:fractional_seconds]) 164: end