| Class | ActiveRecord::ConnectionAdapters::AbstractAdapter |
| In: |
vendor/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.
Returns the human-readable name of the adapter. Use mixed case - one can always use downcase if needed.
# File vendor/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb, line 348
348: def adapter_name()
349: 'Abstract'
350: end
# File vendor/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb, line 379
379: def add_column(table_name, column_name, type, options = {})
380: add_column_sql = "ALTER TABLE #{table_name} ADD #{column_name} #{native_database_types[type]}"
381: add_column_sql << "(#{limit})" if options[:limit]
382: add_column_sql << " DEFAULT '#{options[:default]}'" if options[:default]
383: execute(add_column_sql)
384: end
# File vendor/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb, line 355
355: def add_limit!(sql, limit)
356: sql << " LIMIT #{limit}"
357: end
Begins the transaction (and turns off auto-committing).
# File vendor/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.
# File vendor/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).
# File vendor/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb, line 315
315: def commit_db_transaction() end
# File vendor/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb, line 369
369: def create_table(name)
370: execute "CREATE TABLE #{name} (id #{native_database_types[:primary_key]})"
371: table_definition = yield TableDefinition.new
372: table_definition.columns.each { |column_name, type, options| add_column(name, column_name, type, options) }
373: end
Executes the delete statement and returns the number of rows affected.
# File vendor/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb, line 288
288: def delete(sql, name = nil) end
# File vendor/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb, line 375
375: def drop_table(name)
376: execute "DROP TABLE #{name}"
377: end
# File vendor/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb, line 360
360: def initialize_schema_information
361: begin
362: execute "CREATE TABLE schema_info (version #{native_database_types[:integer]})"
363: insert "INSERT INTO schema_info (version) VALUES(0)"
364: rescue ActiveRecord::StatementInvalid
365: # Schema has been intialized
366: end
367: end
Returns the last auto-generated ID from the affected table.
# File vendor/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb, line 282
282: def insert(sql, name = nil, pk = nil, id_value = nil) end
# File vendor/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
# File vendor/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb, line 343
343: def quote_column_name(name)
344: name
345: end
# File vendor/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
# File vendor/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb, line 386
386: def remove_column(table_name, column_name)
387: execute "ALTER TABLE #{table_name} DROP #{column_name}"
388: end
Rolls back the transaction (and turns on auto-committing). Must be done if the transaction block raises an exception or returns false.
# File vendor/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.
# File vendor/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.
# File vendor/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.
# File vendor/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.
# File vendor/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