Class ActiveRecord::ConnectionAdapters::AbstractAdapter
In: vendor/rails/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb
Parent: Object

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.

Methods

Public Instance methods

Returns the human-readable name of the adapter. Use mixed case - one can always use downcase if needed.

[Source]

     # File vendor/rails/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb, line 348
348:       def adapter_name()
349:         'Abstract'
350:       end

[Source]

     # File vendor/rails/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb, line 392
392:       def add_column(table_name, column_name, type, options = {})
393:         native_type = native_database_types[type]
394:         add_column_sql = "ALTER TABLE #{table_name} ADD #{column_name} #{type_to_sql(type, options[:limit])}"
395:         add_column_options!(add_column_sql, options)
396:         execute(add_column_sql)
397:       end

[Source]

     # File vendor/rails/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb, line 419
419:       def add_index(table_name, column_name, index_type = '')
420:         execute "CREATE #{index_type} INDEX #{table_name}_#{column_name.to_a.first}_index ON #{table_name} (#{column_name.to_a.join(", ")})"
421:       end

[Source]

     # File vendor/rails/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb, line 355
355:       def add_limit!(sql, options)
356:         return unless options
357:         add_limit_offset!(sql, options)
358:       end

[Source]

     # File vendor/rails/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb, line 360
360:       def add_limit_offset!(sql, options)
361:         return if options[:limit].nil?
362:         sql << " LIMIT #{options[:limit]}"
363:         sql << " OFFSET #{options[:offset]}" if options.has_key?(:offset) and !options[:offset].nil?
364:       end

Begins the transaction (and turns off auto-committing).

[Source]

     # File vendor/rails/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb, line 312
312:       def begin_db_transaction()    end

[Source]

     # File vendor/rails/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb, line 403
403:       def change_column(table_name, column_name, type, options = {})
404:         raise NotImplementedError, "change_column is not implemented"
405:       end

[Source]

     # File vendor/rails/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb, line 407
407:       def change_column_default(table_name, column_name, default)
408:         raise NotImplementedError, "change_column_default is not implemented"
409:       end

Returns an array of column objects for the table specified by table_name.

[Source]

     # File vendor/rails/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb, line 279
279:       def columns(table_name, name = nil) end

Commits the transaction (and turns on auto-committing).

[Source]

     # File vendor/rails/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb, line 315
315:       def commit_db_transaction()   end

[Source]

     # File vendor/rails/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb, line 376
376:       def create_table(name, options = {})
377:         table_definition = TableDefinition.new(self)
378:         table_definition.primary_key(options[:primary_key] || "id") unless options[:id] == false
379: 
380:         yield table_definition
381:         create_sql = "CREATE TABLE #{name} ("
382:         create_sql << table_definition.to_sql
383:         create_sql << ") #{options[:options]}"
384:                 
385:         execute create_sql
386:       end

Executes the delete statement and returns the number of rows affected.

[Source]

     # File vendor/rails/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb, line 288
288:       def delete(sql, name = nil) end

[Source]

     # File vendor/rails/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb, line 388
388:       def drop_table(name)
389:         execute "DROP TABLE #{name}"
390:       end

[Source]

     # File vendor/rails/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb, line 367
367:       def initialize_schema_information
368:         begin
369:           execute "CREATE TABLE schema_info (version #{type_to_sql(:integer)})"
370:           execute "INSERT INTO schema_info (version) VALUES(0)"
371:         rescue ActiveRecord::StatementInvalid
372:           # Schema has been intialized
373:         end
374:       end

Returns the last auto-generated ID from the affected table.

[Source]

     # File vendor/rails/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb, line 282
282:       def insert(sql, name = nil, pk = nil, id_value = nil) end

[Source]

     # File vendor/rails/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb, line 431
431:       def native_database_types
432:         {}
433:       end

[Source]

     # File vendor/rails/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb, line 321
321:       def quote(value, column = nil)
322:         case value
323:           when String
324:             if column && column.type == :binary
325:               "'#{quote_string(column.string_to_binary(value))}'" # ' (for ruby-mode)
326:             else
327:               "'#{quote_string(value)}'" # ' (for ruby-mode)
328:             end
329:           when NilClass              then "NULL"
330:           when TrueClass             then (column && column.type == :boolean ? "'t'" : "1")
331:           when FalseClass            then (column && column.type == :boolean ? "'f'" : "0")
332:           when Float, Fixnum, Bignum then value.to_s
333:           when Date                  then "'#{value.to_s}'"
334:           when Time, DateTime        then "'#{value.strftime("%Y-%m-%d %H:%M:%S")}'"
335:           else                            "'#{quote_string(value.to_yaml)}'"
336:         end
337:       end

[Source]

     # File vendor/rails/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb, line 343
343:       def quote_column_name(name)
344:         name
345:       end

[Source]

     # File vendor/rails/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb, line 339
339:       def quote_string(s)
340:         s.gsub(/\\/, '\&\&').gsub(/'/, "''") # ' (for ruby-mode)
341:       end

[Source]

     # File vendor/rails/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb, line 399
399:       def remove_column(table_name, column_name)
400:         execute "ALTER TABLE #{table_name} DROP #{column_name}"
401:       end

[Source]

     # File vendor/rails/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb, line 423
423:       def remove_index(table_name, column_name)
424:         execute "DROP INDEX #{table_name}_#{column_name}_index ON #{table_name}"
425:       end

[Source]

     # File vendor/rails/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb, line 415
415:       def rename_column(table_name, column_name, new_column_name)
416:         raise NotImplementedError, "rename_column is not implemented"
417:       end

Rolls back the transaction (and turns on auto-committing). Must be done if the transaction block raises an exception or returns false.

[Source]

     # File vendor/rails/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb, line 319
319:       def rollback_db_transaction() end

Returns an array of record hashes with the column names as a keys and fields as values.

[Source]

     # File vendor/rails/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb, line 273
273:       def select_all(sql, name = nil) end

Returns a record hash with the column names as a keys and fields as values.

[Source]

     # File vendor/rails/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb, line 276
276:       def select_one(sql, name = nil) end

Returns a string of the CREATE TABLE SQL statements for recreating the entire structure of the database.

[Source]

     # File vendor/rails/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb, line 353
353:       def structure_dump() end

[Source]

     # File vendor/rails/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb, line 411
411:       def supports_migrations?
412:         false
413:       end

[Source]

     # File vendor/rails/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb, line 427
427:       def supports_migrations?
428:         false
429:       end

Wrap a block in a transaction. Returns result of block.

[Source]

     # File vendor/rails/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb, line 297
297:       def transaction(start_db_transaction = true)
298:         begin
299:           if block_given?
300:             begin_db_transaction if start_db_transaction
301:             result = yield
302:             commit_db_transaction if start_db_transaction
303:             result
304:           end
305:         rescue Exception => database_transaction_rollback
306:           rollback_db_transaction if start_db_transaction
307:           raise
308:         end
309:       end

[Source]

     # File vendor/rails/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb, line 435
435:       def type_to_sql(type, limit = nil)
436:         native = native_database_types[type]
437:         limit ||= native[:limit]
438:         column_type_sql = native[:name]
439:         column_type_sql << "(#{limit})" if limit
440:         column_type_sql
441:       end

Executes the update statement and returns the number of rows affected.

[Source]

     # File vendor/rails/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb, line 285
285:       def update(sql, name = nil) end

[Validate]