ActiveRecord::ConnectionAdapters::DatabaseStatements


Files

Methods

Public Instance methods

add_limit! (sql, options)

Alias for add_limit_offset!.

add_limit_offset! (sql, options)

Appends LIMIT and OFFSET options to an SQL statement, or some SQL fragment that has the same semantics as LIMIT and OFFSET.

options must be a Hash which contains a +:limit+ option (required) and an +:offset+ option (optional).

This method modifies the sql parameter.

Examples
 add_limit_offset!('SELECT * FROM suppliers', {:limit => 10, :offset => 50})

generates

 SELECT * FROM suppliers LIMIT 10 OFFSET 50

add_lock! (sql, options)

Appends a locking clause to an SQL statement. This method modifies the sql parameter.

  # SELECT * FROM suppliers FOR UPDATE
  add_lock! 'SELECT * FROM suppliers', :lock => true
  add_lock! 'SELECT * FROM suppliers', :lock => ' FOR UPDATE'

begin_db_transaction ()

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

case_sensitive_equality_operator ()

commit_db_transaction ()

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

default_sequence_name (table, column)

delete (sql, name = nil)

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

empty_insert_statement (table_name)

execute (sql, name = nil, skip_logging = false)

Executes the SQL statement in the context of this connection.

insert (sql, name = nil, pk = nil, id_value = nil, sequence_name = nil)

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

insert_fixture (fixture, table_name)

Inserts the given fixture into the table. Overridden in adapters that require something beyond a simple insert (eg. Oracle).

limited_update_conditions (where_sql, quoted_table_name, quoted_primary_key)

reset_sequence! (table, column, sequence = nil)

Set the sequence to the max value of the table‘s column.

rollback_db_transaction ()

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

select_all (sql, name = nil)

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

select_one (sql, name = nil)

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

select_rows (sql, name = nil)

Returns an array of arrays containing the field values. Order is the same as that returned by columns.

select_value (sql, name = nil)

Returns a single value from a record

select_values (sql, name = nil)

Returns an array of the values of the first column in a select:

  select_values("SELECT id FROM companies LIMIT 3") => [1,2,3]

transaction (start_db_transaction = true) {|| ...}

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

update (sql, name = nil)

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

Protected Instance methods

delete_sql (sql, name = nil)

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

insert_sql (sql, name = nil, pk = nil, id_value = nil, sequence_name = nil)

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

sanitize_limit (limit)

Sanitizes the given LIMIT parameter in order to prevent SQL injection.

limit may be anything that can evaluate to a string via to_s. It should look like an integer, or a comma-delimited list of integers.

Returns the sanitized limit parameter, either as an integer, or as a string which contains a comma-delimited list of integers.

select (sql, name = nil)

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

update_sql (sql, name = nil)

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