Files

Class/Module Index [+]

Quicksearch

ArJdbc::MySQL

Public Class Methods

arel2_visitors(config) click to toggle source
# File lib/arjdbc/mysql/adapter.rb, line 131
def self.arel2_visitors(config)
  {
    'mysql' => ::Arel::Visitors::MySQL,
    'mysql2' => ::Arel::Visitors::MySQL,
    'jdbcmysql' => ::Arel::Visitors::MySQL
  }
end
column_selector() click to toggle source
# File lib/arjdbc/mysql/adapter.rb, line 16
def self.column_selector
  [ /mysql/, lambda { |_,column| column.extend(::ArJdbc::MySQL::Column) } ]
end
extended(adapter) click to toggle source
# File lib/arjdbc/mysql/adapter.rb, line 8
def self.extended(adapter)
  adapter.configure_connection
end
jdbc_connection_class() click to toggle source
# File lib/arjdbc/mysql/adapter.rb, line 20
def self.jdbc_connection_class
  ::ActiveRecord::ConnectionAdapters::MySQLJdbcConnection
end

Public Instance Methods

add_column(table_name, column_name, type, options = {}) click to toggle source
# File lib/arjdbc/mysql/adapter.rb, line 348
def add_column(table_name, column_name, type, options = {})
  add_column_sql = "ALTER TABLE #{quote_table_name(table_name)} ADD #{quote_column_name(column_name)} #{type_to_sql(type, options[:limit], options[:precision], options[:scale])}"
  add_column_options!(add_column_sql, options)
  add_column_position!(add_column_sql, options)
  execute(add_column_sql)
end
add_column_position!(sql, options) click to toggle source
# File lib/arjdbc/mysql/adapter.rb, line 481
def add_column_position!(sql, options)
  if options[:first]
    sql << " FIRST"
  elsif options[:after]
    sql << " AFTER #{quote_column_name(options[:after])}"
  end
end
case_sensitive_equality_operator() click to toggle source
# File lib/arjdbc/mysql/adapter.rb, line 139
def case_sensitive_equality_operator
  "= BINARY"
end
case_sensitive_modifier(node) click to toggle source
# File lib/arjdbc/mysql/adapter.rb, line 143
def case_sensitive_modifier(node)
  Arel::Nodes::Bin.new(node)
end
change_column_null(table_name, column_name, null, default = nil) click to toggle source
# File lib/arjdbc/mysql/adapter.rb, line 360
def change_column_null(table_name, column_name, null, default = nil)
  column = column_for(table_name, column_name)

  unless null || default.nil?
    execute("UPDATE #{quote_table_name(table_name)} SET #{quote_column_name(column_name)}=#{quote(default)} WHERE #{quote_column_name(column_name)} IS NULL")
  end

  change_column table_name, column_name, column.sql_type, :null => null
end
charset() click to toggle source
# File lib/arjdbc/mysql/adapter.rb, line 442
def charset
  show_variable("character_set_database")
end
collation() click to toggle source
# File lib/arjdbc/mysql/adapter.rb, line 446
def collation
  show_variable("collation_database")
end
configure_connection() click to toggle source
# File lib/arjdbc/mysql/adapter.rb, line 12
def configure_connection
  execute("SET SQL_AUTO_IS_NULL=0")
end
create_savepoint() click to toggle source
# File lib/arjdbc/mysql/adapter.rb, line 209
def create_savepoint
  execute("SAVEPOINT #{current_savepoint_name}")
end
current_database() click to toggle source
# File lib/arjdbc/mysql/adapter.rb, line 331
def current_database
  select_one("SELECT DATABASE() as db")["db"]
end
exec_delete(sql, name, binds) click to toggle source
Alias for: exec_insert
exec_insert(sql, name, binds) click to toggle source

DATABASE STATEMENTS ======================================

# File lib/arjdbc/mysql/adapter.rb, line 233
def exec_insert(sql, name, binds)
  execute sql, name, binds
end
Also aliased as: exec_update, exec_delete
exec_update(sql, name, binds) click to toggle source
Alias for: exec_insert
limited_update_conditions(where_sql, quoted_table_name, quoted_primary_key) click to toggle source
# File lib/arjdbc/mysql/adapter.rb, line 147
def limited_update_conditions(where_sql, quoted_table_name, quoted_primary_key)
  where_sql
end
modify_types(types) click to toggle source
# File lib/arjdbc/mysql/adapter.rb, line 116
def modify_types(types)
  types[:primary_key] = "int(11) DEFAULT NULL auto_increment PRIMARY KEY"
  types[:integer] = { :name => 'int', :limit => 4 }
  types[:decimal] = { :name => "decimal" }
  types[:timestamp] = { :name => "datetime" }
  types[:datetime][:limit] = nil
  types
end
native_database_types() click to toggle source
# File lib/arjdbc/mysql/adapter.rb, line 112
def native_database_types
  NATIVE_DATABASE_TYPES
end
primary_key(table) click to toggle source

Returns just a table's primary key

# File lib/arjdbc/mysql/adapter.rb, line 309
def primary_key(table)
  pk_and_sequence = pk_and_sequence_for(table)
  pk_and_sequence && pk_and_sequence.first
end
quote(value, column = nil) click to toggle source

QUOTING ==================================================

# File lib/arjdbc/mysql/adapter.rb, line 153
def quote(value, column = nil)
  return value.quoted_id if value.respond_to?(:quoted_id)
  return value.to_s if column && column.type == :primary_key
  
  if value.kind_of?(String) && column && column.type == :binary && column.class.respond_to?(:string_to_binary)
    "x'#{column.class.string_to_binary(value).unpack("H*")[0]}'"
  elsif value.kind_of?(BigDecimal)
    value.to_s("F")
  else
    super
  end
end
release_savepoint() click to toggle source
# File lib/arjdbc/mysql/adapter.rb, line 217
def release_savepoint
  execute("RELEASE SAVEPOINT #{current_savepoint_name}")
end
rename_table(name, new_name) click to toggle source
# File lib/arjdbc/mysql/adapter.rb, line 339
def rename_table(name, new_name)
  execute "RENAME TABLE #{quote_table_name(name)} TO #{quote_table_name(new_name)}"
end
rollback_to_savepoint() click to toggle source
# File lib/arjdbc/mysql/adapter.rb, line 213
def rollback_to_savepoint
  execute("ROLLBACK TO SAVEPOINT #{current_savepoint_name}")
end
show_variable(var) click to toggle source
# File lib/arjdbc/mysql/adapter.rb, line 436
def show_variable(var)
  res = execute("show variables like '#{var}'")
  result_row = res.detect {|row| row["Variable_name"] == var }
  result_row && result_row["Value"]
end
supports_migrations?() click to toggle source

Returns true, since this connection adapter supports migrations.

# File lib/arjdbc/mysql/adapter.rb, line 175
def supports_migrations?
  true
end
type_to_sql(type, limit = nil, precision = nil, scale = nil) click to toggle source
# File lib/arjdbc/mysql/adapter.rb, line 450
def type_to_sql(type, limit = nil, precision = nil, scale = nil)
  case type.to_s
  when 'binary'
    case limit
    when 0..0xfff; "varbinary(#{limit})"
    when nil; "blob"
    when 0x1000..0xffffffff; "blob(#{limit})"
    else raise(ActiveRecordError, "No binary type has character length #{limit}")
    end
  when 'integer'
    case limit
    when 1; 'tinyint'
    when 2; 'smallint'
    when 3; 'mediumint'
    when nil, 4, 11; 'int(11)' # compatibility with MySQL default
    when 5..8; 'bigint'
    else raise(ActiveRecordError, "No integer type has byte size #{limit}")
    end
  when 'text'
    case limit
    when 0..0xff; 'tinytext'
    when nil, 0x100..0xffff; 'text'
    when 0x10000..0xffffff; 'mediumtext'
    when 0x1000000..0xffffffff; 'longtext'
    else raise(ActiveRecordError, "No text type has character length #{limit}")
    end
  else
    super
  end
end

Protected Instance Methods

quoted_columns_for_index(column_names, options = {}) click to toggle source
# File lib/arjdbc/mysql/adapter.rb, line 490
def quoted_columns_for_index(column_names, options = {})
  length = options[:length] if options.is_a?(Hash)

  case length
  when Hash
    column_names.map { |name| length[name] ? "#{quote_column_name(name)}(#{length[name]})" : quote_column_name(name) }
  when Fixnum
    column_names.map { |name| "#{quote_column_name(name)}(#{length})" }
  else
    column_names.map { |name| quote_column_name(name) }
  end
end
translate_exception(exception, message) click to toggle source
# File lib/arjdbc/mysql/adapter.rb, line 503
def translate_exception(exception, message)
  return super unless exception.respond_to?(:errno)

  case exception.errno
  when 1062
    ::ActiveRecord::RecordNotUnique.new(message, exception)
  when 1452
    ::ActiveRecord::InvalidForeignKey.new(message, exception)
  else
    super
  end
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.