BitOwl Application Suit provides a database abstraction layer in order to make interacting with various database types transparent. Be it SQL or otherwise.
The DBAL works with associative arrays to represent rows in a database.
BitOwl_Database
is an abstract class to all DBAL interfaces. It
serves as an API for the DBAL.
BitOwl_Database::__construct($host[, $user[, $pass[, $db]]])
Initializes the DBAL. Parameters after $host are not needed since the flatfile database only needs one value.
int BitOwl_Database::findQuerySection($section, $argc, $argv[, $expected[, $start]]) [protected]
Searches $argv for $section and returns the value if it exists. If not -1 will be returned. $expected allows a form of error checking and says how many arguments the parameter should take (usually 1 or 0). $start changes the offset in which the search starts.
array BitOwl_Database::query($table, $action[, $params...]) [abstract]
Executes a database query. You must specify a table followed by an action (see below) and finally any parameters to pass in.
Action | Description |
---|---|
BITOWL_DB_SELECT |
Performs a data fetching operation. |
BITOWL_DB_INSERT |
Adds a new row to the database. Must be supplemented with additional data (the row in which to insert). |
BITOWL_DB_UPDATE |
Updates a row. As long as the id is unchanged you can simply pass the row in and let the DBAL do the work. |
BITOWL_DB_DELETE |
Deletes a row. As with update, the row can be pass in if the id is unchanged. |
Parameter | Description |
---|---|
BITOWL_DB_WHERE |
Indicates a filter condition on the result set. Takes one
array with the column name and the condition. In addition an
operator and multioperator can be passed in which can be either BITOWL_DB_WHERE_EQUALS
, BITOWL_DB_WHERE_BITWISEAND , or BITOWL_DB_WHERE_LESSTHAN . Example:
array('category', 2, 'operator' => BITOWL_DB_WHERE_BITWISEAND)
would match any row with category having a 2 in the bitfield. A
multioperator (BITOWL_DB_WHERE_AND or BITOWL_DB_WHERE_OR) changes
how multiple where clauses are handled. This is ignored for the
first where clause and switching operations is not guarenteed. |
BITOWL_DB_LIMIT |
Limits the number of results. Takes an array containing the starting index and how many indexes to return. |
BITOWL_DB_COLUMNLIST |
Specifies which columns are wanted. Takes an array of names. |
BITOWL_DB_VALUES |
Specifies the values for the columns in BITOWL_DB_COLUMNLIST .
Takes a non-associative array. |
BITOWL_DB_ROW |
Allows you to specify both BITOWL_DB_COLUMNLIST and BITOWL_DB_VALUES
at the same time. Takes an associative array in the form of 'column' => 'value' . |
BITOWL_DB_RCHRONOLOGICAL |
Reverses the table lookup. This is chronological with respect to isertion time. |
BITOWL_DB_PAGINATED |
Executes an additional query which counts the total number of rows. |
BITOWL_DB_SEARCH |
MySQL Only: Allows a database to be searched by a full text field. This should not be used by provided code, but rather by end users. |
BITOWL_DB_NESTEDSET |
Enables nested set operations. All standard operations
in addition the following table should be used. When performing
queries on a NESTEDSET table, it is best that this flag always
be used. Tables using the NESTEDSET flag need to have lft and rgt columns holding integers. |
Parameter | Description |
---|---|
BITOWL_DB_SELECTCHILDREN |
Selects all of the child nodes contained by the query. |
BITOWL_DB_SELECTPARENTS |
Selects all the parents of the node from the root upwards. |
BITOWL_DB_SELIMEDCHILDREN |
Selects only the immediate children of the selected node. |
BITOWL_DB_SETNSPARENT |
Use with INSERT and UPDATE to set the parent node. |
str BitOwl_Database::getName()
Returns the name of the database type.
int BitOwl_Database::getSize() [abstract]
Returns the size of the database in bytes.
int BitOwl_Database::getTotalResults()
Returns the total number of possible rows in the last query. This
value is only updated if BITOWL_DB_PAGINATE
was used.
void BitOwl_Database::createTable($table, $flags[, $params...]) [abstract]
The main purpose of this function is to initalize the tables during installation. It creates a table with the passed in params. Each param must be an array with the following format.
array( 'name' => 'columnName', 'type' => BITOWL_DB_CREATETABLE_TYPE );Type should be one of the following constants:
BITOWL_DB_CREATETABLE_BOOL |
Boolean value. Either 0 or 1. |
BITOWL_DB_CREATETABLE_INT |
Integer value. Should be capable of handling -231 through 231 (or more accurately, a signed 32-bit integer). |
BITOWL_DB_CREATETABLE_STRING |
String value. Less than or equal to 255 characters. |
BITOWL_DB_CREATETABLE_TEXT |
String value, but can be more than 255 characters. |
The defined flags are (if not explicitly specified flags are required to be handled by the DB engine):
BITOWL_DB_CREATETABLE_NESTEDSET |
Adds the proper columns for nested set operations. |
BITOWL_DB_CREATETABLE_FLIPPED |
Opimizes a table for reading rows in the reverse order from which they are inserted. This flag is not required to be implemented by the DB engine. |
void BitOwl_Database::modifyTable($table, $action, $column[, $after[, $type[, $default]]])
Adds or removes columns from the specified table. $action
can be either BITOWL_DB_MODIFYTABLE_INSERT
or
BITOWL_DB_MODIFYTABLE_DELETE
. The optional parameters only
apply to column insertions. Since 'id' will always be the first column
specifing that will allow you to add a column to the beginning of a
table.
BitOwl_Database BitOwl_Database::createDatabaseObject($host[, $user[, $pass[, $db[, $flags]]]]) [static]
Determines which database interface to use and loads the proper object.
The pagination class helps with displaying results in pages. The class is generic so it may be used for paginating other data as well.
BitOwl_Pagination::__construct($itemsperpage[, $id])
Initializes a pagination with the specified items per page. The $id parameter is used to allow multiple paginations on a given page.
void BitOwl_Pagination::setTotal($total)
Specifies the total number of items in a result set.
int BitOwl_Pagination::start()
Returns the starting index for the current page.
void BitOwl_Pagination::show()
Displays the pagination navigation.
The following is the MySQL code to create the needed tables for BOAS. Keep in mind that certain properties are not needed. For example the defaults are not important. Anything that forces a column to be unique is also not needed.