All the concrete database adapters follow the interface laid down in this class. You can use this interface directly by borrowing the database connection from the Base with Base.connection.
- adapter_name
- add_column
- add_index
- add_limit!
- add_limit_offset!
- begin_db_transaction
- change_column
- change_column_default
- columns
- commit_db_transaction
- create_table
- delete
- drop_table
- initialize_schema_information
- insert
- native_database_types
- quote
- quote_column_name
- quote_string
- remove_column
- remove_index
- rename_column
- rollback_db_transaction
- select_all
- select_one
- structure_dump
- supports_migrations?
- supports_migrations?
- transaction
- type_to_sql
- update
Returns the human-readable name of the adapter. Use mixed case - one can always use downcase if needed.
[ show source ]
# File vendor/rails/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb, line 342
342: def adapter_name()
343: 'Abstract'
344: end
[ show source ]
# File vendor/rails/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb, line 386
386: def add_column(table_name, column_name, type, options = {})
387: native_type = native_database_types[type]
388: add_column_sql = "ALTER TABLE #{table_name} ADD #{column_name} #{type_to_sql(type, options[:limit])}"
389: add_column_options!(add_column_sql, options)
390: execute(add_column_sql)
391: end
[ show source ]
# File vendor/rails/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb, line 413
413: def add_index(table_name, column_name, index_type = '')
414: execute "CREATE #{index_type} INDEX #{table_name}_#{column_name.to_a.first}_index ON #{table_name} (#{column_name.to_a.join(", ")})"
415: end
[ show source ]
# File vendor/rails/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb, line 349
349: def add_limit!(sql, options)
350: return unless options
351: add_limit_offset!(sql, options)
352: end
[ show source ]
# File vendor/rails/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb, line 354
354: def add_limit_offset!(sql, options)
355: return if options[:limit].nil?
356: sql << " LIMIT #{options[:limit]}"
357: sql << " OFFSET #{options[:offset]}" if options.has_key?(:offset) and !options[:offset].nil?
358: end
Begins the transaction (and turns off auto-committing).
[ show source ]
# File vendor/rails/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb, line 306
306: def begin_db_transaction() end
[ show source ]
# File vendor/rails/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb, line 397
397: def change_column(table_name, column_name, type, options = {})
398: raise NotImplementedError, "change_column is not implemented"
399: end
[ show source ]
# File vendor/rails/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb, line 401
401: def change_column_default(table_name, column_name, default)
402: raise NotImplementedError, "change_column_default is not implemented"
403: end
Returns an array of column objects for the table specified by table_name.
[ show source ]
# File vendor/rails/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb, line 273
273: def columns(table_name, name = nil) end
Commits the transaction (and turns on auto-committing).
[ show source ]
# File vendor/rails/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb, line 309
309: def commit_db_transaction() end
[ show source ]
# File vendor/rails/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb, line 370
370: def create_table(name, options = {})
371: table_definition = TableDefinition.new(self)
372: table_definition.primary_key(options[:primary_key] || "id") unless options[:id] == false
373:
374: yield table_definition
375: create_sql = "CREATE TABLE #{name} ("
376: create_sql << table_definition.to_sql
377: create_sql << ") #{options[:options]}"
378:
379: execute create_sql
380: end
Executes the delete statement and returns the number of rows affected.
[ show source ]
# File vendor/rails/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb, line 282
282: def delete(sql, name = nil) end
[ show source ]
# File vendor/rails/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb, line 382
382: def drop_table(name)
383: execute "DROP TABLE #{name}"
384: end
[ show source ]
# File vendor/rails/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb, line 361
361: def initialize_schema_information
362: begin
363: execute "CREATE TABLE schema_info (version #{type_to_sql(:integer)})"
364: insert "INSERT INTO schema_info (version) VALUES(0)"
365: rescue ActiveRecord::StatementInvalid
366: # Schema has been intialized
367: end
368: end
Returns the last auto-generated ID from the affected table.
[ show source ]
# File vendor/rails/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb, line 276
276: def insert(sql, name = nil, pk = nil, id_value = nil) end
[ show source ]
# File vendor/rails/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb, line 425
425: def native_database_types
426: {}
427: end
[ show source ]
# File vendor/rails/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb, line 315
315: def quote(value, column = nil)
316: case value
317: when String
318: if column && column.type == :binary
319: "'#{quote_string(column.string_to_binary(value))}'" # ' (for ruby-mode)
320: else
321: "'#{quote_string(value)}'" # ' (for ruby-mode)
322: end
323: when NilClass then "NULL"
324: when TrueClass then (column && column.type == :boolean ? "'t'" : "1")
325: when FalseClass then (column && column.type == :boolean ? "'f'" : "0")
326: when Float, Fixnum, Bignum then value.to_s
327: when Date then "'#{value.to_s}'"
328: when Time, DateTime then "'#{value.strftime("%Y-%m-%d %H:%M:%S")}'"
329: else "'#{quote_string(value.to_yaml)}'"
330: end
331: end
[ show source ]
# File vendor/rails/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb, line 337
337: def quote_column_name(name)
338: name
339: end
[ show source ]
# File vendor/rails/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb, line 333
333: def quote_string(s)
334: s.gsub(/\\/, '\&\&').gsub(/'/, "''") # ' (for ruby-mode)
335: end
[ show source ]
# File vendor/rails/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb, line 393
393: def remove_column(table_name, column_name)
394: execute "ALTER TABLE #{table_name} DROP #{column_name}"
395: end
[ show source ]
# File vendor/rails/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb, line 417
417: def remove_index(table_name, column_name)
418: execute "DROP INDEX #{table_name}_#{column_name}_index ON #{table_name}"
419: end
[ show source ]
# File vendor/rails/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb, line 409
409: def rename_column(table_name, column_name, new_column_name)
410: raise NotImplementedError, "rename_column is not implemented"
411: end
Rolls back the transaction (and turns on auto-committing). Must be done if the transaction block raises an exception or returns false.
[ show source ]
# File vendor/rails/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb, line 313
313: def rollback_db_transaction() end
Returns an array of record hashes with the column names as a keys and fields as values.
[ show source ]
# File vendor/rails/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb, line 267
267: def select_all(sql, name = nil) end
Returns a record hash with the column names as a keys and fields as values.
[ show source ]
# File vendor/rails/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb, line 270
270: def select_one(sql, name = nil) end
Returns a string of the CREATE TABLE SQL statements for recreating the entire structure of the database.
[ show source ]
# File vendor/rails/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb, line 347
347: def structure_dump() end
[ show source ]
# File vendor/rails/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb, line 405
405: def supports_migrations?
406: false
407: end
[ show source ]
# File vendor/rails/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb, line 421
421: def supports_migrations?
422: false
423: end
Wrap a block in a transaction. Returns result of block.
[ show source ]
# File vendor/rails/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb, line 291
291: def transaction(start_db_transaction = true)
292: begin
293: if block_given?
294: begin_db_transaction if start_db_transaction
295: result = yield
296: commit_db_transaction if start_db_transaction
297: result
298: end
299: rescue Exception => database_transaction_rollback
300: rollback_db_transaction if start_db_transaction
301: raise
302: end
303: end
[ show source ]
# File vendor/rails/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb, line 429
429: def type_to_sql(type, limit = nil)
430: native = native_database_types[type]
431: limit ||= native[:limit]
432: column_type_sql = native[:name]
433: column_type_sql << "(#{limit})" if limit
434: column_type_sql
435: end
Executes the update statement and returns the number of rows affected.
[ show source ]
# File vendor/rails/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb, line 279
279: def update(sql, name = nil) end