Module: ArJdbc::MySQL

Includes:
BulkChangeTable
Included in:
ActiveRecord::ConnectionAdapters::MysqlAdapter
Defined in:
lib/arjdbc/mysql/column.rb,
lib/arjdbc/mysql/adapter.rb,
lib/arjdbc/mysql/explain_support.rb,
lib/arjdbc/mysql/schema_creation.rb,
lib/arjdbc/mysql/bulk_change_table.rb

Defined Under Namespace

Modules: BulkChangeTable, Column, ExplainSupport Classes: SchemaCreation

Constant Summary collapse

NATIVE_DATABASE_TYPES =
{
  :primary_key => "int(11) DEFAULT NULL auto_increment PRIMARY KEY",
  :string => { :name => "varchar", :limit => 255 },
  :text => { :name => "text" },
  :integer => { :name => "int", :limit => 4 },
  :float => { :name => "float" },
  # :double => { :name=>"double", :limit=>17 }
  # :real => { :name=>"real", :limit=>17 }
  :numeric => { :name => "numeric" }, # :limit => 65
  :decimal => { :name => "decimal" }, # :limit => 65
  :datetime => { :name => "datetime" },
  # TIMESTAMP has varying properties depending on MySQL version (SQL mode)
  :timestamp => { :name => "datetime" },
  :time => { :name => "time" },
  :date => { :name => "date" },
  :binary => { :name => "blob" },
  :boolean => { :name => "tinyint", :limit => 1 },
  # AR-JDBC added :
  :bit => { :name => "bit" }, # :limit => 1
  :enum => { :name => "enum" },
  :set => { :name => "set" }, # :limit => 64
  :char => { :name => "char" }, # :limit => 255
}
ADAPTER_NAME =
'MySQL'.freeze
INDEX_TYPES =
[ :fulltext, :spatial ]
INDEX_USINGS =
[ :btree, :hash ]

Class Method Summary collapse

Instance Method Summary collapse

Methods included from BulkChangeTable

#add_column_sql, #add_index_sql, #add_timestamps_sql, #bulk_change_table, #change_column_sql, #remove_column_sql, #remove_columns_sql, #remove_index_sql, #remove_timestamps_sql, #rename_column_sql, #supports_bulk_alter?

Class Method Details

.arel_visitor_type(config = nil) ⇒ Object



136
137
138
# File 'lib/arjdbc/mysql/adapter.rb', line 136

def self.arel_visitor_type(config = nil)
  ::Arel::Visitors::MySQL
end

.column_selectorObject

See Also:

  • ActiveRecord::ConnectionAdapters::JdbcColumn#column_types


5
6
7
# File 'lib/arjdbc/mysql/column.rb', line 5

def self.column_selector
  [ /mysql/i, lambda { |config, column| column.extend(Column) } ]
end

.emulate_booleansObject

Deprecated.

Use #emulate_booleans? instead.



96
# File 'lib/arjdbc/mysql/adapter.rb', line 96

def self.emulate_booleans; @@emulate_booleans; end

.emulate_booleans=(emulate) ⇒ Object

See Also:

  • #emulate_booleans?


98
# File 'lib/arjdbc/mysql/adapter.rb', line 98

def self.emulate_booleans=(emulate); @@emulate_booleans = emulate; end

.emulate_booleans?Boolean

Boolean emulation can be disabled using (or using the adapter method) :

ArJdbc::MySQL.emulate_booleans = false

Returns:

  • (Boolean)

See Also:

  • ActiveRecord::ConnectionAdapters::MysqlAdapter#emulate_booleans


94
# File 'lib/arjdbc/mysql/adapter.rb', line 94

def self.emulate_booleans?; @@emulate_booleans; end

.jdbc_connection_classObject



20
21
22
# File 'lib/arjdbc/mysql/adapter.rb', line 20

def self.jdbc_connection_class
  ::ActiveRecord::ConnectionAdapters::MySQLJdbcConnection
end

Instance Method Details

#adapter_nameObject



132
133
134
# File 'lib/arjdbc/mysql/adapter.rb', line 132

def adapter_name
  ADAPTER_NAME
end

#add_column(table_name, column_name, type, options = {}) ⇒ Object



449
450
451
452
453
454
# File 'lib/arjdbc/mysql/adapter.rb', line 449

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) ⇒ Object



510
511
512
513
514
515
516
# File 'lib/arjdbc/mysql/adapter.rb', line 510

def add_column_position!(sql, options)
  if options[:first]
    sql << " FIRST"
  elsif options[:after]
    sql << " AFTER #{quote_column_name(options[:after])}"
  end
end

#add_limit_offset!(sql, options) ⇒ Object

Note:

Only used with (non-AREL) ActiveRecord 2.3.

See Also:

  • Arel::Visitors::MySQL


520
521
522
523
524
525
526
527
528
529
530
# File 'lib/arjdbc/mysql/adapter.rb', line 520

def add_limit_offset!(sql, options)
  limit, offset = options[:limit], options[:offset]
  if limit && offset
    sql << " LIMIT #{offset.to_i}, #{sanitize_limit(limit)}"
  elsif limit
    sql << " LIMIT #{sanitize_limit(limit)}"
  elsif offset
    sql << " OFFSET #{offset.to_i}"
  end
  sql
end

#case_sensitive_equality_operatorObject



146
147
148
# File 'lib/arjdbc/mysql/adapter.rb', line 146

def case_sensitive_equality_operator
  "= BINARY"
end

#case_sensitive_modifier(node, table_attribute) ⇒ Object



150
151
152
# File 'lib/arjdbc/mysql/adapter.rb', line 150

def case_sensitive_modifier(node)
  Arel::Nodes::Bin.new(node)
end

#change_column(table_name, column_name, type, options = {}) ⇒ Object



472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
# File 'lib/arjdbc/mysql/adapter.rb', line 472

def change_column(table_name, column_name, type, options = {})
  column = column_for(table_name, column_name)

  unless options_include_default?(options)
    # NOTE: no defaults for BLOB/TEXT columns with MySQL
    options[:default] = column.default if type != :text && type != :binary
  end

  unless options.has_key?(:null)
    options[:null] = column.null
  end

  change_column_sql = "ALTER TABLE #{quote_table_name(table_name)} CHANGE #{quote_column_name(column_name)} #{quote_column_name(column_name)} #{type_to_sql(type, options[:limit], options[:precision], options[:scale])}"
  add_column_options!(change_column_sql, options)
  add_column_position!(change_column_sql, options)
  execute(change_column_sql)
end

#change_column_default(table_name, column_name, default) ⇒ Object



456
457
458
459
# File 'lib/arjdbc/mysql/adapter.rb', line 456

def change_column_default(table_name, column_name, default)
  column = column_for(table_name, column_name)
  change_column table_name, column_name, column.sql_type, :default => default
end

#change_column_null(table_name, column_name, null, default = nil) ⇒ Object

unless const_defined? :SchemaCreation



461
462
463
464
465
466
467
468
469
# File 'lib/arjdbc/mysql/adapter.rb', line 461

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

#charsetObject



560
561
562
# File 'lib/arjdbc/mysql/adapter.rb', line 560

def charset
  show_variable("character_set_database")
end

#collationObject



564
565
566
# File 'lib/arjdbc/mysql/adapter.rb', line 564

def collation
  show_variable("collation_database")
end

#columns(table_name, name = nil) ⇒ Object

Returns an array of Column objects for the table specified.



375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
# File 'lib/arjdbc/mysql/adapter.rb', line 375

def columns(table_name, name = nil)
  sql = "SHOW FULL COLUMNS FROM #{quote_table_name(table_name)}"
  columns = execute(sql, name || 'SCHEMA')
  strict = strict_mode?
  pass_cast_type = respond_to?(:lookup_cast_type)
  columns.map! do |field|
    sql_type = field['Type']
    null = field['Null'] == "YES"
    if pass_cast_type
      cast_type = lookup_cast_type(sql_type)
      jdbc_column_class.new(field['Field'], field['Default'], cast_type, sql_type, null, field['Collation'], strict, field['Extra'])
    else
      jdbc_column_class.new(field['Field'], field['Default'], sql_type, null, field['Collation'], strict, field['Extra'])
    end
  end
  columns
end

#configure_connectionObject



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/arjdbc/mysql/adapter.rb', line 44

def configure_connection
  variables = config[:variables] || {}
  # By default, MySQL 'where id is null' selects the last inserted id. Turn this off.
  variables[:sql_auto_is_null] = 0 # execute "SET SQL_AUTO_IS_NULL=0"

  # Increase timeout so the server doesn't disconnect us.
  wait_timeout = config[:wait_timeout]
  wait_timeout = self.class.type_cast_config_to_integer(wait_timeout)
  variables[:wait_timeout] = wait_timeout.is_a?(Fixnum) ? wait_timeout : 2147483

  # Make MySQL reject illegal values rather than truncating or blanking them, see
  # http://dev.mysql.com/doc/refman/5.0/en/server-sql-mode.html#sqlmode_strict_all_tables
  # If the user has provided another value for sql_mode, don't replace it.
  if strict_mode? && ! variables.has_key?(:sql_mode)
    variables[:sql_mode] = 'STRICT_ALL_TABLES' # SET SQL_MODE='STRICT_ALL_TABLES'
  end

  # NAMES does not have an equals sign, see
  # http://dev.mysql.com/doc/refman/5.0/en/set-statement.html#id944430
  # (trailing comma because variable_assignments will always have content)
  encoding = "NAMES #{config[:encoding]}, " if config[:encoding]

  # Gather up all of the SET variables...
  variable_assignments = variables.map do |k, v|
    if v == ':default' || v == :default
      "@@SESSION.#{k.to_s} = DEFAULT" # Sets the value to the global or compile default
    elsif ! v.nil?
      "@@SESSION.#{k.to_s} = #{quote(v)}"
    end
    # or else nil; compact to clear nils out
  end.compact.join(', ')

  # ...and send them all in one query
  execute("SET #{encoding} #{variable_assignments}", :skip_logging)
end

#create_database(name, options = {}) ⇒ Object



401
402
403
404
405
406
407
# File 'lib/arjdbc/mysql/adapter.rb', line 401

def create_database(name, options = {})
  if options[:collation]
    execute "CREATE DATABASE `#{name}` DEFAULT CHARACTER SET `#{options[:charset] || 'utf8'}` COLLATE `#{options[:collation]}`"
  else
    execute "CREATE DATABASE `#{name}` DEFAULT CHARACTER SET `#{options[:charset] || 'utf8'}`"
  end
end

#create_savepoint(name = current_savepoint_name(true)) ⇒ Object



263
264
265
# File 'lib/arjdbc/mysql/adapter.rb', line 263

def create_savepoint(name = current_savepoint_name(true))
  log("SAVEPOINT #{name}", 'Savepoint') { super }
end

#create_table(name, options = {}) ⇒ Object



419
420
421
# File 'lib/arjdbc/mysql/adapter.rb', line 419

def create_table(name, options = {})
  super(name, {:options => "ENGINE=InnoDB DEFAULT CHARSET=utf8"}.merge(options))
end

#current_databaseObject



414
415
416
# File 'lib/arjdbc/mysql/adapter.rb', line 414

def current_database
  select_one("SELECT DATABASE() as db")["db"]
end

#disable_referential_integrityObject



277
278
279
280
281
282
283
284
285
# File 'lib/arjdbc/mysql/adapter.rb', line 277

def disable_referential_integrity
  fk_checks = select_value("SELECT @@FOREIGN_KEY_CHECKS")
  begin
    update("SET FOREIGN_KEY_CHECKS = 0")
    yield
  ensure
    update("SET FOREIGN_KEY_CHECKS = #{fk_checks}")
  end
end

#drop_database(name) ⇒ Object



410
411
412
# File 'lib/arjdbc/mysql/adapter.rb', line 410

def drop_database(name)
  execute "DROP DATABASE IF EXISTS `#{name}`"
end

#drop_table(table_name, options = {}) ⇒ Object



423
424
425
# File 'lib/arjdbc/mysql/adapter.rb', line 423

def drop_table(table_name, options = {})
  execute "DROP#{' TEMPORARY' if options[:temporary]} TABLE #{quote_table_name(table_name)}"
end

#empty_insert_statement_valueObject



600
601
602
# File 'lib/arjdbc/mysql/adapter.rb', line 600

def empty_insert_statement_value
  "VALUES ()"
end

#indexes(table_name, name = nil) ⇒ Object

Returns an array of indexes for the given table.



347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
# File 'lib/arjdbc/mysql/adapter.rb', line 347

def indexes(table_name, name = nil)
  indexes = []
  current_index = nil
  result = execute("SHOW KEYS FROM #{quote_table_name(table_name)}", name || 'SCHEMA')
  result.each do |row|
    key_name = row['Key_name']
    if current_index != key_name
      next if key_name == 'PRIMARY' # skip the primary key
      current_index = key_name
      indexes <<
        if self.class.const_defined?(:INDEX_TYPES) # AR 4.0
          mysql_index_type = row['Index_type'].downcase.to_sym
          index_type = INDEX_TYPES.include?(mysql_index_type) ? mysql_index_type : nil
          index_using = INDEX_USINGS.include?(mysql_index_type) ? mysql_index_type : nil
          IndexDefinition.new(row['Table'], key_name, row['Non_unique'].to_i == 0, [], [], nil, nil, index_type, index_using)
        else
          IndexDefinition.new(row['Table'], key_name, row['Non_unique'].to_i == 0, [], [])
        end
    end

    indexes.last.columns << row["Column_name"]
    indexes.last.lengths << row["Sub_part"]
  end
  indexes
end

#initialize_schema_migrations_tableObject



163
164
165
166
167
168
169
# File 'lib/arjdbc/mysql/adapter.rb', line 163

def initialize_schema_migrations_table
  if @config[:encoding] == 'utf8mb4'
    ActiveRecord::SchemaMigration.create_table(191)
  else
    ActiveRecord::SchemaMigration.create_table
  end
end

#jdbc_column_classObject



24
25
26
# File 'lib/arjdbc/mysql/adapter.rb', line 24

def jdbc_column_class
  ::ActiveRecord::ConnectionAdapters::MysqlAdapter::Column
end

#limited_update_conditions(where_sql, quoted_table_name, quoted_primary_key) ⇒ Object



159
160
161
# File 'lib/arjdbc/mysql/adapter.rb', line 159

def limited_update_conditions(where_sql, quoted_table_name, quoted_primary_key)
  where_sql
end

#native_database_typesObject



125
126
127
# File 'lib/arjdbc/mysql/adapter.rb', line 125

def native_database_types
  NATIVE_DATABASE_TYPES
end

#pk_and_sequence_for(table) ⇒ Object

Note:

Not used, only here for potential compatibility with native adapter.

Returns a table's primary key and belonging sequence.



325
326
327
328
329
330
331
332
333
# File 'lib/arjdbc/mysql/adapter.rb', line 325

def pk_and_sequence_for(table)
  result = execute("SHOW CREATE TABLE #{quote_table_name(table)}", 'SCHEMA').first
  if result['Create Table'].to_s =~ /PRIMARY KEY\s+(?:USING\s+\w+\s+)?\((.+)\)/
    keys = $1.split(","); keys.map! { |key| key.gsub(/[`"]/, "") }
    return keys.length == 1 ? [ keys.first, nil ] : nil
  else
    return nil
  end
end

#primary_key(table) ⇒ Object

Returns just a table's primary key.



316
317
318
319
320
# File 'lib/arjdbc/mysql/adapter.rb', line 316

def primary_key(table)
  #pk_and_sequence = pk_and_sequence_for(table)
  #pk_and_sequence && pk_and_sequence.first
  @connection.primary_keys(table).first
end

#quote(value, column = nil) ⇒ Object



191
192
193
194
195
196
197
198
199
200
201
202
203
# File 'lib/arjdbc/mysql/adapter.rb', line 191

def quote(value, column = nil)
  return value.quoted_id if value.respond_to?(:quoted_id)
  return value if sql_literal?(value)
  return value.to_s if column && column.type == :primary_key

  if value.kind_of?(String) && column && column.type == :binary
    "x'#{value.unpack("H*")[0]}'"
  elsif value.kind_of?(BigDecimal)
    value.to_s("F")
  else
    super
  end
end

#quote_column_name(name) ⇒ Object



206
207
208
# File 'lib/arjdbc/mysql/adapter.rb', line 206

def quote_column_name(name)
  "`#{name.to_s.gsub('`', '``')}`"
end

#quote_table_name(name) ⇒ Object



211
212
213
# File 'lib/arjdbc/mysql/adapter.rb', line 211

def quote_table_name(name)
  quote_column_name(name).gsub('.', '`.`')
end

#quoted_columns_for_index(column_names, options = {}) ⇒ Object (protected)



605
606
607
608
609
610
611
612
613
614
615
616
# File 'lib/arjdbc/mysql/adapter.rb', line 605

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

#release_savepoint(name = current_savepoint_name) ⇒ Object



273
274
275
# File 'lib/arjdbc/mysql/adapter.rb', line 273

def release_savepoint(name = current_savepoint_name)
  log("RELEASE SAVEPOINT #{name}", 'Savepoint') { super }
end

#remove_index!(table_name, index_name) ⇒ Object



434
435
436
437
# File 'lib/arjdbc/mysql/adapter.rb', line 434

def remove_index!(table_name, index_name)
  # missing table_name quoting in AR-2.3
  execute "DROP INDEX #{quote_column_name(index_name)} ON #{quote_table_name(table_name)}"
end

#rename_column(table_name, column_name, new_column_name) ⇒ Object



491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
# File 'lib/arjdbc/mysql/adapter.rb', line 491

def rename_column(table_name, column_name, new_column_name)
  options = {}

  if column = columns(table_name).find { |c| c.name == column_name.to_s }
    type = column.type
    options[:default] = column.default if type != :text && type != :binary
    options[:null] = column.null
  else
    raise ActiveRecord::ActiveRecordError, "No such column: #{table_name}.#{column_name}"
  end

  current_type = select_one("SHOW COLUMNS FROM #{quote_table_name(table_name)} LIKE '#{column_name}'")["Type"]

  rename_column_sql = "ALTER TABLE #{quote_table_name(table_name)} CHANGE #{quote_column_name(column_name)} #{quote_column_name(new_column_name)} #{current_type}"
  add_column_options!(rename_column_sql, options)
  execute(rename_column_sql)
  rename_column_indexes(table_name, column_name, new_column_name) if respond_to?(:rename_column_indexes) # AR-4.0 SchemaStatements
end

#rename_index(table_name, old_name, new_name) ⇒ Object



440
441
442
443
444
445
446
# File 'lib/arjdbc/mysql/adapter.rb', line 440

def rename_index(table_name, old_name, new_name)
  if supports_rename_index?
    execute "ALTER TABLE #{quote_table_name(table_name)} RENAME INDEX #{quote_table_name(old_name)} TO #{quote_table_name(new_name)}"
  else
    super
  end
end

#rename_table(table_name, new_name) ⇒ Object



428
429
430
431
# File 'lib/arjdbc/mysql/adapter.rb', line 428

def rename_table(table_name, new_name)
  execute "RENAME TABLE #{quote_table_name(table_name)} TO #{quote_table_name(new_name)}"
  rename_table_indexes(table_name, new_name) if respond_to?(:rename_table_indexes) # AR-4.0 SchemaStatements
end

#rollback_to_savepoint(name = current_savepoint_name) ⇒ Object



268
269
270
# File 'lib/arjdbc/mysql/adapter.rb', line 268

def rollback_to_savepoint(name = current_savepoint_name)
  log("ROLLBACK TO SAVEPOINT #{name}", 'Savepoint') { super }
end

#show_variable(var) ⇒ Object



554
555
556
557
558
# File 'lib/arjdbc/mysql/adapter.rb', line 554

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

#strict_mode?Boolean

strict_mode is default since AR 4.0

Returns:

  • (Boolean)


80
81
82
83
84
# File 'lib/arjdbc/mysql/adapter.rb', line 80

def strict_mode? # strict_mode is default since AR 4.0
  config.key?(:strict) ?
    self.class.type_cast_config_to_boolean(config[:strict]) :
      ::ActiveRecord::VERSION::MAJOR > 3
end

#structure_dumpObject

Deprecated.

no longer used - handled with (AR built-in) Rake tasks



295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
# File 'lib/arjdbc/mysql/adapter.rb', line 295

def structure_dump
  # NOTE: due AR (2.3-3.2) compatibility views are not included
  if supports_views?
    sql = "SHOW FULL TABLES WHERE Table_type = 'BASE TABLE'"
  else
    sql = "SHOW TABLES"
  end

  @connection.execute_query_raw(sql).map do |table|
    # e.g. { "Tables_in_arjdbc_test"=>"big_fields", "Table_type"=>"BASE TABLE" }
    table.delete('Table_type')
    table_name = table.to_a.first.last

    create_table = select_one("SHOW CREATE TABLE #{quote_table_name(table_name)}")

    "#{create_table['Create Table']};\n\n"
  end.join
end

#supports_index_sort_order?Boolean

Returns:

  • (Boolean)


226
227
228
229
230
# File 'lib/arjdbc/mysql/adapter.rb', line 226

def supports_index_sort_order?
  # Technically MySQL allows to create indexes with the sort order syntax
  # but at the moment (5.5) it doesn't yet implement them.
  true
end

#supports_migrations?Boolean

Returns:

  • (Boolean)


216
217
218
# File 'lib/arjdbc/mysql/adapter.rb', line 216

def supports_migrations?
  true
end

#supports_primary_key?Boolean

Returns:

  • (Boolean)


221
222
223
# File 'lib/arjdbc/mysql/adapter.rb', line 221

def supports_primary_key?
  true
end

#supports_rename_index?Boolean

Returns:

  • (Boolean)


245
246
247
248
# File 'lib/arjdbc/mysql/adapter.rb', line 245

def supports_rename_index?
  return false if mariadb? || ! version[0]
  (version[0] == 5 && version[1] >= 7) || version[0] >= 6
end

#supports_savepoints?Boolean

Returns:

  • (Boolean)


258
259
260
# File 'lib/arjdbc/mysql/adapter.rb', line 258

def supports_savepoints?
  true
end

#supports_transaction_isolation?(level = nil) ⇒ Boolean

Returns:

  • (Boolean)


233
234
235
236
237
238
# File 'lib/arjdbc/mysql/adapter.rb', line 233

def supports_transaction_isolation?
  # MySQL 4 technically support transaction isolation, but it is affected by
  # a bug where the transaction level gets persisted for the whole session:
  # http://bugs.mysql.com/bug.php?id=39170
  version[0] && version[0] >= 5
end

#supports_views?Boolean

Returns:

  • (Boolean)


241
242
243
# File 'lib/arjdbc/mysql/adapter.rb', line 241

def supports_views?
  version[0] && version[0] >= 5
end

#translate_exception(exception, message) ⇒ Object (protected)



619
620
621
622
623
624
625
626
627
628
629
630
# File 'lib/arjdbc/mysql/adapter.rb', line 619

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

#type_to_sql(type, limit = nil, precision = nil, scale = nil) ⇒ Object



568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
# File 'lib/arjdbc/mysql/adapter.rb', line 568

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

#update_sql(sql, name = nil) ⇒ Object



288
289
290
# File 'lib/arjdbc/mysql/adapter.rb', line 288

def update_sql(sql, name = nil)
  super
end