class SqliteAdapter extends Connection (View source)

Adapter for SQLite.

Constants

DATETIME_TRANSLATE_FORMAT

The DateTime format to use when translating other DateTime-compatible objects.

NOTE!: The DateTime "format" used must not include a time-zone (name, abbreviation, etc) or offset. Including one will cause PHP to ignore the passed in time-zone in the 3rd argument. See bug: https://bugs.php.net/bug.php?id=61022

Properties

mixed $connection The PDO connection object. from Connection
string $last_query The last query run. from Connection
string $protocol The name of the protocol that is used. from Connection
static string $date_format Database's date format from Connection
static $datetime_format
static array $PDO_OPTIONS Default PDO options to set for each connection. from Connection
static string $QUOTE_CHARACTER The quote character for stuff like column and field names. from Connection
static int $DEFAULT_PORT Default port. from Connection

Methods

static Connection
instance(string $connection_string_or_connection_name = null)

Retrieve a database connection.

static object
parse_connection_url(string $connection_url)

Use this for any adapters that can take connection info in the form below to set the adapters connection info.

__construct(array $info)

Class Connection is a singleton. Access it via instance().

array
columns(string $table)

Retrieves column meta data for the specified table.

string
escape(string $string)

Escapes quotes in a string.

int
insert_id(string $sequence = null)

Retrieve the insert id of the last model saved.

mixed
query(string $sql, array $values = array())

Execute a raw SQL query on the database.

string
query_and_fetch_one(string $sql, array $values = array())

Execute a query that returns maximum of one row with one field and return it.

query_and_fetch(string $sql, Closure $handler)

Execute a raw SQL query and fetch the results.

array
tables()

Returns all tables for the current database.

transaction()

Starts a transaction.

commit()

Commits the current transaction.

rollback()

Rollback a transaction.

boolean
supports_sequences()

Tells you if this adapter supports sequences or not.

string
get_sequence_name(string $table, string $column_name)

Return a default sequence name for the specified table.

string
next_sequence_value(string $sequence_name)

Return SQL for getting the next value in a sequence.

string
quote_name(string $string)

Quote a name like table names and field names.

string
date_to_string(DateTime $datetime)

Return a date time formatted into the database's date format.

string
datetime_to_string(DateTime $datetime)

Return a date time formatted into the database's datetime format.

object
string_to_datetime(string $string)

Converts a string representation of a datetime into a DateTime object.

string
limit(string $sql, int $offset, int $limit)

Adds a limit clause to the SQL query.

PDOStatement
query_column_info(string $table)

Query for column meta info and return statement handle.

PDOStatement
query_for_tables()

Query for all tables in the current database. The result must only contain one column which has the name of the table.

set_encoding($charset)

Executes query to specify the character set for this connection.

native_database_types()

No description

accepts_limit_and_order_for_update_and_delete()

Specifies whether or not adapter can use LIMIT/ORDER clauses with DELETE & UPDATE operations

create_column($column)

No description

Details

static Connection instance(string $connection_string_or_connection_name = null)

Retrieve a database connection.

Parameters

string $connection_string_or_connection_name A database connection string (ex. mysql://user:pass@host[:port]/dbname) Everything after the protocol:// part is specific to the connection adapter. OR A connection name that is set in ActiveRecord\Config If null it will use the default connection specified by ActiveRecord\Config->set_default_connection

Return Value

Connection

See also

parse_connection_url

static object parse_connection_url(string $connection_url)

Use this for any adapters that can take connection info in the form below to set the adapters connection info.

protocol://username:password@host[:port]/dbname protocol://urlencoded%20username:urlencoded%20password@host[:port]/dbname?decode=true protocol://username:password@unix(/some/file/path)/dbname

Sqlite has a special syntax, as it does not need a database name or user authentication:

sqlite://file.db sqlite://../relative/path/to/file.db sqlite://unix(/absolute/path/to/file.db) sqlite://windows(c%2A/absolute/path/to/file.db)

Parameters

string $connection_url A connection URL

Return Value

object the parsed URL as an object.

protected Connection __construct(array $info)

Class Connection is a singleton. Access it via instance().

Parameters

array $info Array containing URL parts

Return Value

Connection

array columns(string $table)

Retrieves column meta data for the specified table.

Parameters

string $table Name of a table

Return Value

array An array of {@link Column} objects.

string escape(string $string)

Escapes quotes in a string.

Parameters

string $string The string to be quoted.

Return Value

string The string with any quotes in it properly escaped.

int insert_id(string $sequence = null)

Retrieve the insert id of the last model saved.

Parameters

string $sequence Optional name of a sequence to use

Return Value

int

mixed query(string $sql, array $values = array())

Execute a raw SQL query on the database.

Parameters

string $sql Raw SQL string to execute.
array $values &$values Optional array of bind values

Return Value

mixed A result set object

string query_and_fetch_one(string $sql, array $values = array())

Execute a query that returns maximum of one row with one field and return it.

Parameters

string $sql Raw SQL string to execute.
array $values &$values Optional array of values to bind to the query.

Return Value

string

query_and_fetch(string $sql, Closure $handler)

Execute a raw SQL query and fetch the results.

Parameters

string $sql Raw SQL string to execute.
Closure $handler Closure that will be passed the fetched results.

array tables()

Returns all tables for the current database.

Return Value

array Array containing table names.

transaction()

Starts a transaction.

commit()

Commits the current transaction.

rollback()

Rollback a transaction.

boolean supports_sequences()

Tells you if this adapter supports sequences or not.

Return Value

boolean

string get_sequence_name(string $table, string $column_name)

Return a default sequence name for the specified table.

Parameters

string $table Name of a table
string $column_name Name of column sequence is for

Return Value

string sequence name or null if not supported.

string next_sequence_value(string $sequence_name)

Return SQL for getting the next value in a sequence.

Parameters

string $sequence_name Name of the sequence

Return Value

string

string quote_name(string $string)

Quote a name like table names and field names.

Parameters

string $string String to quote.

Return Value

string

string date_to_string(DateTime $datetime)

Return a date time formatted into the database's date format.

Parameters

DateTime $datetime The DateTime object

Return Value

string

string datetime_to_string(DateTime $datetime)

Return a date time formatted into the database's datetime format.

Parameters

DateTime $datetime The DateTime object

Return Value

string

object string_to_datetime(string $string)

Converts a string representation of a datetime into a DateTime object.

Parameters

string $string A datetime in the form accepted by date_create()

Return Value

object The date_class set in Config

string limit(string $sql, int $offset, int $limit)

Adds a limit clause to the SQL query.

Parameters

string $sql The SQL statement.
int $offset Row offset to start at.
int $limit Maximum number of rows to return.

Return Value

string The SQL query that will limit results to specified parameters

PDOStatement query_column_info(string $table)

Query for column meta info and return statement handle.

Parameters

string $table Name of a table

Return Value

PDOStatement

PDOStatement query_for_tables()

Query for all tables in the current database. The result must only contain one column which has the name of the table.

Return Value

PDOStatement

set_encoding($charset)

Executes query to specify the character set for this connection.

Parameters

$charset

native_database_types()

accepts_limit_and_order_for_update_and_delete()

Specifies whether or not adapter can use LIMIT/ORDER clauses with DELETE & UPDATE operations

create_column($column)

Parameters

$column