Abstract Class Misago\ActiveRecord\ConnectionAdapters\AbstractAdapter

Abstract adapter to build real Misago\ActiveRecord adapters.

Public instance attributes

Protected instance attributes

Methods

Public instance methods

__construct(array $config)

__destruct()

add_column($table, $column, $type, array $options=null)

Adds a column to a table.

add_index($table, $column, $options=null)

Adds an index to a table column.

By default the index is named $table_$column_idx or $table_$column_uniq.

Available options:

  • type - null or unique
  • name - manual naming of the index
  • size - specified size of the index, in case of a blob/text.

IMPROVE: Support indices on multiple columns.

config($name)

Returns the value of a configuration setting.

connect()

Connects to the database.

create_table($table, array $definition)

Creates a table.

Definition:

  • temporary - true to create a temporary table
  • columns - eg: {:name => {:type, :limit, :null, :default, :signed, :primary_key}}
  • options - eg: "engine = innodb"
  • force - true: drop table before create, false: create if not exists

delete($table, $conditions=null, $options=null)

Deletes rows from a table.

drop_column($table, $column)

Removes a column from a table.

drop_index($table, $name)

Drops an index from a table.

drop_table($table, array $options=null)

Drops a table.

Options:

  • temporary - true if table to drop is a temporary table.

insert($table, array $data, $primary_key=null)

Inserts a row in a table.

new_table($table, array $options=null)

Returns a helper to create a new table.

Available options:

  • temporary - true to create a temporary table
  • id - true to automatically add an auto incrementing id column
  • options - additional string (eg: "engine = innodb")

quote_column($column)

Quotes a column name for use in a SQL query.

quote_columns($columns)

Quotes a series of columns for use in a SQL query.

quote_value($value)

Quotes and escapes a table name for use in a SQL query.

sanitize_limit($limit=null, $page=null)

Creates a LIMIT + OFFSET SQL fragment.

sanitize_order($columns)

Quotes a list of ORDER/GROUP BY columns.

sanitize_sql_array($ary)

Accepts an array of conditions. The array has each value sanitized and interpolated into the SQL statement.

sanitize_sql_array(array("name = :name AND post_id = :id",
  array('name' => 'toto', post_id => 59)));
# => "name = 'toto'"

sanitize_sql_array(array("name = '%s' AND group_id = %d", 'toto', 123));
# => "name = 'toto' AND group_id = 123" 

sanitize_sql_for_assignment($assignments)

Accepts an array, hash, or string of SQL assignments and sanitizes them into a valid SQL fragment for a SET clause.

sanitize_sql_for_conditions($conditions)

Accepts an array, hash, or string of SQL conditions and sanitizes them into a valid SQL fragment for a WHERE clause.

See sanitize_sql_array and sanitize_sql_hash for examples.

sanitize_sql_hash(array $hash)

Sanitizes a hash of attribute/value pairs for use in SQL conditions or assignments.

sanitize_sql_hash(array("a" => 'b', "c" => 'd'));
# => array("\"a\" = 'b'", "\"c\" = 'd'") 

sanitize_sql_hash_for_assignment(array $assignments)

Sanitizes a hash of attribute/value pairs into SQL assignments for a SET clause.

sanitize_sql_hash_for_conditions(array $conditions)

Sanitizes a hash of attribute/value pairs into SQL conditions for a WHERE clause.

select_one($sql)

Returns a single hash of columns => values.

select_value($sql)

Returns a single value.

transaction($action)

Declares transaction state.

Available actions:

  • begin - starts a transaction
  • commit - ends a transaction and commits statements to the database.
  • rollback - ends a transaction and drops statements (nothing is recorded in the database).

Note: prefer using ActiveRecord::transaction() instead.

truncate($table_name)

Truncates a table.

update($table, $data, $conditions=null, $options=null)

Updates rows in a table.

Protected instance methods

log_query($sql, $affected_rows, $time)

report_error($sql, $message)