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:
279 280 281 282 |
# File 'lib/active_record/connection_adapters/abstract_adapter.rb', line 279 def initialize(connection, logger = nil) # :nodoc: @connection, @logger = connection, logger @runtime = 0 end |
Instance Method Details
#add_limit!(sql, limit) ⇒ Object
362 363 364 |
# File 'lib/active_record/connection_adapters/abstract_adapter.rb', line 362 def add_limit!(sql, limit) sql << " LIMIT #{limit}" end |
#begin_db_transaction ⇒ Object
Begins the transaction (and turns off auto-committing).
324 |
# File 'lib/active_record/connection_adapters/abstract_adapter.rb', line 324 def begin_db_transaction() end |
#columns(table_name, name = nil) ⇒ Object
Returns an array of column objects for the table specified by table_name
.
291 |
# File 'lib/active_record/connection_adapters/abstract_adapter.rb', line 291 def columns(table_name, name = nil) end |
#commit_db_transaction ⇒ Object
Commits the transaction (and turns on auto-committing).
327 |
# File 'lib/active_record/connection_adapters/abstract_adapter.rb', line 327 def commit_db_transaction() end |
#delete(sql, name = nil) ⇒ Object
Executes the delete statement and returns the number of rows affected.
300 |
# File 'lib/active_record/connection_adapters/abstract_adapter.rb', line 300 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.
294 |
# File 'lib/active_record/connection_adapters/abstract_adapter.rb', line 294 def insert(sql, name = nil, pk = nil, id_value = nil) end |
#quote(value, column = nil) ⇒ Object
333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 |
# File 'lib/active_record/connection_adapters/abstract_adapter.rb', line 333 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
355 356 357 |
# File 'lib/active_record/connection_adapters/abstract_adapter.rb', line 355 def quote_column_name(name) name end |
#quote_string(s) ⇒ Object
351 352 353 |
# File 'lib/active_record/connection_adapters/abstract_adapter.rb', line 351 def quote_string(s) s.gsub(/\\/, '\&\&').gsub(/'/, "''") # ' (for ruby-mode) end |
#reset_runtime ⇒ Object
:nodoc:
302 303 304 305 306 |
# File 'lib/active_record/connection_adapters/abstract_adapter.rb', line 302 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.
331 |
# File 'lib/active_record/connection_adapters/abstract_adapter.rb', line 331 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.
285 |
# File 'lib/active_record/connection_adapters/abstract_adapter.rb', line 285 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.
288 |
# File 'lib/active_record/connection_adapters/abstract_adapter.rb', line 288 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.
360 |
# File 'lib/active_record/connection_adapters/abstract_adapter.rb', line 360 def structure_dump() end |
#transaction(start_db_transaction = true) ⇒ Object
Wrap a block in a transaction. Returns result of block.
309 310 311 312 313 314 315 316 317 318 319 320 321 |
# File 'lib/active_record/connection_adapters/abstract_adapter.rb', line 309 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.
297 |
# File 'lib/active_record/connection_adapters/abstract_adapter.rb', line 297 def update(sql, name = nil) end |