Class: ActiveRecord::ConnectionAdapters::AbstractAdapter
- Includes:
- Benchmark
- Defined in:
- lib/active_record/connection_adapters/abstract_adapter.rb
Overview
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.
Direct Known Subclasses
MysqlAdapter, PostgreSQLAdapter, SQLServerAdapter, SQLiteAdapter
Constant Summary collapse
- @@row_even =
true
Instance Method Summary collapse
- #add_limit!(sql, limit) ⇒ Object
-
#begin_db_transaction ⇒ Object
Begins the transaction (and turns off auto-committing).
-
#columns(table_name, name = nil) ⇒ Object
Returns an array of column objects for the table specified by
table_name. -
#commit_db_transaction ⇒ Object
Commits the transaction (and turns on auto-committing).
-
#delete(sql, name = nil) ⇒ Object
Executes the delete statement and returns the number of rows affected.
-
#initialize(connection, logger = nil) ⇒ AbstractAdapter
constructor
:nodoc:.
-
#insert(sql, name = nil, pk = nil, id_value = nil) ⇒ Object
Returns the last auto-generated ID from the affected table.
- #quote(value, column = nil) ⇒ Object
- #quote_column_name(name) ⇒ Object
- #quote_string(s) ⇒ Object
-
#reset_runtime ⇒ Object
:nodoc:.
-
#rollback_db_transaction ⇒ Object
Rollsback the transaction (and turns on auto-committing).
-
#select_all(sql, name = nil) ⇒ Object
Returns an array of record hashes with the column names as a keys and fields as values.
-
#select_one(sql, name = nil) ⇒ Object
Returns a record hash with the column names as a keys and fields as values.
-
#structure_dump ⇒ Object
Returns a string of the CREATE TABLE SQL statements for recreating the entire structure of the database.
-
#transaction(start_db_transaction = true) ⇒ Object
Wrap a block in a transaction.
-
#update(sql, name = nil) ⇒ Object
Executes the update statement and returns the number of rows affected.
Constructor Details
#initialize(connection, logger = nil) ⇒ AbstractAdapter
:nodoc:
282 283 284 285 |
# File 'lib/active_record/connection_adapters/abstract_adapter.rb', line 282 def initialize(connection, logger = nil) # :nodoc: @connection, @logger = connection, logger @runtime = 0 end |
Instance Method Details
#add_limit!(sql, limit) ⇒ Object
365 366 367 |
# File 'lib/active_record/connection_adapters/abstract_adapter.rb', line 365 def add_limit!(sql, limit) sql << " LIMIT #{limit}" end |
#begin_db_transaction ⇒ Object
Begins the transaction (and turns off auto-committing).
327 |
# File 'lib/active_record/connection_adapters/abstract_adapter.rb', line 327 def begin_db_transaction() end |
#columns(table_name, name = nil) ⇒ Object
Returns an array of column objects for the table specified by table_name.
294 |
# File 'lib/active_record/connection_adapters/abstract_adapter.rb', line 294 def columns(table_name, name = nil) end |
#commit_db_transaction ⇒ Object
Commits the transaction (and turns on auto-committing).
330 |
# File 'lib/active_record/connection_adapters/abstract_adapter.rb', line 330 def commit_db_transaction() end |
#delete(sql, name = nil) ⇒ Object
Executes the delete statement and returns the number of rows affected.
303 |
# File 'lib/active_record/connection_adapters/abstract_adapter.rb', line 303 def delete(sql, name = nil) end |
#insert(sql, name = nil, pk = nil, id_value = nil) ⇒ Object
Returns the last auto-generated ID from the affected table.
297 |
# File 'lib/active_record/connection_adapters/abstract_adapter.rb', line 297 def insert(sql, name = nil, pk = nil, id_value = nil) end |
#quote(value, column = nil) ⇒ Object
336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 |
# File 'lib/active_record/connection_adapters/abstract_adapter.rb', line 336 def quote(value, column = nil) case value when String if column && column.type == :binary "'#{quote_string(column.string_to_binary(value))}'" # ' (for ruby-mode) else "'#{quote_string(value)}'" # ' (for ruby-mode) end when NilClass then "NULL" when TrueClass then (column && column.type == :boolean ? "'t'" : "1") when FalseClass then (column && column.type == :boolean ? "'f'" : "0") when Float, Fixnum, Bignum then value.to_s when Date then "'#{value.to_s}'" when Time, DateTime then "'#{value.strftime("%Y-%m-%d %H:%M:%S")}'" else "'#{quote_string(value.to_yaml)}'" end end |
#quote_column_name(name) ⇒ Object
358 359 360 |
# File 'lib/active_record/connection_adapters/abstract_adapter.rb', line 358 def quote_column_name(name) return name end |
#quote_string(s) ⇒ Object
354 355 356 |
# File 'lib/active_record/connection_adapters/abstract_adapter.rb', line 354 def quote_string(s) s.gsub(/\\/, '\&\&').gsub(/'/, "''") # ' (for ruby-mode) end |
#reset_runtime ⇒ Object
:nodoc:
305 306 307 308 309 |
# File 'lib/active_record/connection_adapters/abstract_adapter.rb', line 305 def reset_runtime # :nodoc: rt = @runtime @runtime = 0 return rt end |
#rollback_db_transaction ⇒ Object
Rollsback the transaction (and turns on auto-committing). Must be done if the transaction block raises an exception or returns false.
334 |
# File 'lib/active_record/connection_adapters/abstract_adapter.rb', line 334 def rollback_db_transaction() end |
#select_all(sql, name = nil) ⇒ Object
Returns an array of record hashes with the column names as a keys and fields as values.
288 |
# File 'lib/active_record/connection_adapters/abstract_adapter.rb', line 288 def select_all(sql, name = nil) end |
#select_one(sql, name = nil) ⇒ Object
Returns a record hash with the column names as a keys and fields as values.
291 |
# File 'lib/active_record/connection_adapters/abstract_adapter.rb', line 291 def select_one(sql, name = nil) end |
#structure_dump ⇒ Object
Returns a string of the CREATE TABLE SQL statements for recreating the entire structure of the database.
363 |
# File 'lib/active_record/connection_adapters/abstract_adapter.rb', line 363 def structure_dump() end |
#transaction(start_db_transaction = true) ⇒ Object
Wrap a block in a transaction. Returns result of block.
312 313 314 315 316 317 318 319 320 321 322 323 324 |
# File 'lib/active_record/connection_adapters/abstract_adapter.rb', line 312 def transaction(start_db_transaction = true) begin if block_given? begin_db_transaction if start_db_transaction result = yield commit_db_transaction if start_db_transaction result end rescue Exception => database_transaction_rollback rollback_db_transaction if start_db_transaction raise end end |
#update(sql, name = nil) ⇒ Object
Executes the update statement and returns the number of rows affected.
300 |
# File 'lib/active_record/connection_adapters/abstract_adapter.rb', line 300 def update(sql, name = nil) end |