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_limit!
- add_limit_with_offset!
- add_limit_without_offset!
- begin_db_transaction
- columns
- commit_db_transaction
- create_table
- delete
- drop_table
- initialize_schema_information
- insert
- quote
- quote_column_name
- quote_string
- remove_column
- rollback_db_transaction
- select_all
- select_one
- structure_dump
- transaction
- update
- Benchmark
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 348
348: def adapter_name()
349: 'Abstract'
350: end
[ show source ]
# File vendor/rails/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb, line 391
391: def add_column(table_name, column_name, type, options = {})
392: native_type = native_database_types[type]
393: add_column_sql = "ALTER TABLE #{table_name} ADD #{column_name} #{native_type[:name]}"
394: add_column_sql << "(#{options[:limit] || native_type[:limit]})" if options[:limit] || native_type[:limit]
395: add_column_sql << " DEFAULT '#{options[:default]}'" if options[:default]
396: execute(add_column_sql)
397: end
[ show source ]
# File vendor/rails/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb, line 355
355: def add_limit!(sql, limit)
356: if limit.is_a? Array
357: limit, offset = *limit
358: add_limit_with_offset!(sql, limit.to_i, offset.to_i)
359: else
360: add_limit_without_offset!(sql, limit)
361: end
362: end
[ show source ]
# File vendor/rails/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb, line 364
364: def add_limit_with_offset!(sql, limit, offset)
365: sql << " LIMIT #{limit} OFFSET #{offset}"
366: end
[ show source ]
# File vendor/rails/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb, line 368
368: def add_limit_without_offset!(sql, limit)
369: sql << " LIMIT #{limit}"
370: end
Begins the transaction (and turns off auto-committing).
[ show source ]
# File vendor/rails/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb, line 312
312: def begin_db_transaction() 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 279
279: 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 315
315: def commit_db_transaction() end
[ show source ]
# File vendor/rails/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb, line 381
381: def create_table(name, options = "")
382: execute "CREATE TABLE #{name} (id #{native_database_types[:primary_key]}) #{options}"
383: table_definition = yield TableDefinition.new
384: table_definition.columns.each { |column_name, type, options| add_column(name, column_name, type, options) }
385: 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 288
288: def delete(sql, name = nil) end
[ show source ]
# File vendor/rails/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb, line 387
387: def drop_table(name)
388: execute "DROP TABLE #{name}"
389: end
[ show source ]
# File vendor/rails/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb, line 372
372: def initialize_schema_information
373: begin
374: execute "CREATE TABLE schema_info (version #{native_database_types[:integer][:name]}#{native_database_types[:integer][:limit]})"
375: insert "INSERT INTO schema_info (version) VALUES(0)"
376: rescue ActiveRecord::StatementInvalid
377: # Schema has been intialized
378: end
379: 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 282
282: 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 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
[ show 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
[ show 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
[ show 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
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 319
319: 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 273
273: 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 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.
[ show source ]
# File vendor/rails/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb, line 353
353: def structure_dump() 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 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
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 285
285: def update(sql, name = nil) end