SnapDBI Class Reference
[Core]

Customized database interface for Snap2. More...

Inheritance diagram for SnapDBI:

Inheritance graph
[legend]

List of all members.

Static Public Member Functions

static cancelTransaction ()
 Cancel all transactions.
static cleanupTransactions ()
 Cancels any transactions still pending.
static commitTransaction ()
 Commit a transaction.
static connect ($user, $pass, $host, $db)
 Connects to a database.
static criteriaToString ($arr, $attributes)
 Converts criteria array to a string.
static disconnect ()
 INSERT BRIEF DESCRIPTION HERE.
static firstRow ($reset=false)
 Returns first row of results.
static freeResult ()
 INSERT BRIEF DESCRIPTION HERE.
static getInsertId ()
 Returns primary key from last INSERT operation.
static getNumRows ()
 Returns number of rows in result set.
static getRow ($rowNum=false)
 Returns a single row of results.
static limitToString ($limit)
 Converts limit array to a string.
static orderToString ($order, $attributes)
 Converts order array to string.
static query ($query, $getResult=false)
 Query the database.
static startTransaction ()
 Start a transaction.

Static Private Attributes

static $CONN
static $QUERY_COUNT
static $RCOOKIE
static $transLevel


Detailed Description

Customized database interface for Snap2.

For internal use only.

This class implements many of the same features of our beloved old DBI, but it is tailored towards the usage needed by Snap2 and it also avoids overhead where not needed. One of the major extra features is that it supports database transactions, so that all Snap operations can be atomic.

Definition at line 13 of file SnapDBI.php5.


Member Function Documentation

static SnapDBI::cancelTransaction (  )  [static]

static SnapDBI::cleanupTransactions (  )  [static]

Cancels any transactions still pending.

For internal use only.

This method is a shutdown function intended to prevent the database from getting locked up in a transaction if the script dies in the middle of a transaction. It is public because shutdown functions must be public.

Definition at line 81 of file SnapDBI.php5.

static SnapDBI::commitTransaction (  )  [static]

Commit a transaction.

For internal use only.

If transaction nesting level is greater than 1, then this method is a no-op.

If a transaction fails to commit, then it's best for the script to bail instead of having a complex system to rollback any updates to objects and the cache, it makes more sense to simply treat all objects involved in the transaction as tainted and try to gracefully exit the script as soon as possible; in general, transactions should never fail unless there is a bug or a problem with the DB server

Returns:
[boolean]: success or failure

Definition at line 227 of file SnapDBI.php5.

References Snap2::checkInit().

Referenced by SnapPathCache::addPathSet(), SnapPermission::commit(), SnapMetadata::commit(), SnapResourceUserPermission::copy(), SnapResourceGroupPermission::copy(), SnapDirectoryUserPermission::copy(), SnapDirectoryGroupPermission::copy(), SnapDirectory::createDirectory(), SnapDirectory::createResource(), SnapPermission::grantPrivilege(), SnapPathCache::regenPathCache(), SnapPathCache::removePathSet(), SnapFile::restore(), SnapPermission::revokePrivilege(), SnapContentMediaNetlogoApplet::updateFileList(), SnapContentMediaInteractivateApplet::updateFileList(), SnapContentMediaImage::updateFileList(), SnapContentMediaFile::updateFileList(), SnapContentMediaDocument::updateFileList(), SnapContentMediaAgentsheetsApplet::updateFileList(), and SnapPathCache::updatePathSet().

static SnapDBI::connect ( user,
pass,
host,
db 
) [static]

Connects to a database.

For internal use only.

Parameters:
$user [string]: username of DB user
$pass [string]: password for user
$host [string]: database server host
$db [string]: database name
Returns:
[boolean]: whether connection was successful

Definition at line 36 of file SnapDBI.php5.

Referenced by Snap2::init(), and Snap2::reinit().

static SnapDBI::criteriaToString ( arr,
attributes 
) [static]

Converts criteria array to a string.

For internal use only.

See the SWAT Model2 documentation on the wiki for more about the structure of this array

Parameters:
$arr [array]: criteria array
$attributes [array]: list of attributes that can be used in criteria array
Returns:
[string]: SQL string to be appended as a WHERE clause (does not include 'WHERE', though)

Definition at line 269 of file SnapDBI.php5.

Referenced by SnapMetadata::findKeys(), and SnapDirectory::listContents().

static SnapDBI::disconnect (  )  [static]

INSERT BRIEF DESCRIPTION HERE.

INSERT FULL DESCRIPTION HERE

Returns:
[TYPE]: RETURN DESCRIPTION

Definition at line 65 of file SnapDBI.php5.

Referenced by Snap2::reinit().

static SnapDBI::firstRow ( reset = false  )  [static]

Returns first row of results.

For internal use only.

Parameters:
$reset [boolean]: whether to reset to row 0 (usually not needed)
Returns:
[array]: first row of results, or false if not connected

Definition at line 161 of file SnapDBI.php5.

References Snap2::checkInit().

Referenced by SnapVersion::populate().

static SnapDBI::freeResult (  )  [static]

static SnapDBI::getInsertId (  )  [static]

Returns primary key from last INSERT operation.

For internal use only.

Returns:
[integer]: primary key from last INSERT or false if database not initialized

Definition at line 135 of file SnapDBI.php5.

References Snap2::checkInit().

Referenced by SnapDirectory::createDirectory(), and SnapDirectory::createResource().

static SnapDBI::getNumRows (  )  [static]

Returns number of rows in result set.

For internal use only.

Returns:
[integer]: number of rows in result set, or false if not connected

Definition at line 173 of file SnapDBI.php5.

References Snap2::checkInit().

Referenced by SnapDirectory::canCreateResource(), SnapPermission::loadSpecialUsers(), and SnapVersion::populate().

static SnapDBI::getRow ( rowNum = false  )  [static]

Returns a single row of results.

For internal use only.

Parameters:
$rowNum [integer]: index of row to retrieve, or false if retrieving "next" row
Returns:
[array]: single row of data, or false if not connected

Definition at line 146 of file SnapDBI.php5.

References Snap2::checkInit().

Referenced by SnapPermissionCache::__construct(), SnapPermissionObject::getCapabilities(), SnapDirectory::listContents(), SnapBulkAction::listVersionsRecursive(), SnapPermission::loadParties(), SnapPermission::loadSpecialUsers(), SnapPermissionObject::populate(), SnapPermissionObject::warmCache(), and SnapPermissionCache::warmCache().

static SnapDBI::limitToString ( limit  )  [static]

Converts limit array to a string.

For internal use only.

If limit is an array, the one or two elements are treated as the one or two arguments to the SQL 'LIMIT' qualifier. If limit is a number, then that single number is treated as the sole argument to the SQL 'LIMIT' qualifier.

Parameters:
$limit [array]: limit array
Returns:
[string]: SQL for limit (including 'LIMIT')

Definition at line 391 of file SnapDBI.php5.

Referenced by SnapMetadata::findKeys(), and SnapDirectory::listContents().

static SnapDBI::orderToString ( order,
attributes 
) [static]

Converts order array to string.

For internal use only.

If $order is array, then each element indicates another sort column. If element is associative, the key is treated as the attribute and the value must be either 'ASC' or 'DESC'. If $order is a string, it is used as is.

Parameters:
$order [mixed]: order array or string
$attributes [array]: array of attributes that can be used in order array
Returns:
[string]: SQL string for order (including 'ORDER BY');

Definition at line 434 of file SnapDBI.php5.

Referenced by SnapMetadata::findKeys(), and SnapDirectory::listContents().

static SnapDBI::query ( query,
getResult = false 
) [static]

Query the database.

For internal use only.

This method has the feature of not retrieving any results unless asked for them. This way, the results can be gathered row by row instead of creating a giant array, only to loop over it again in calling code.

Parameters:
$query [string]: database query
$getResult [boolean]: whether to return a result array
Returns:
[mixed]: boolean indicating success if $getResult is false, otherwise, result array, or true if non-SELECT query was run.

Definition at line 98 of file SnapDBI.php5.

References Snap2::checkInit().

Referenced by SnapPermissionCache::__construct(), SnapFile::_canMove(), SnapPathCache::addPathSet(), SnapDirectory::canCreateResource(), SnapPermission::commit(), SnapMetadata::commit(), SnapResourceUserPermission::copy(), SnapResourceGroupPermission::copy(), SnapDirectoryUserPermission::copy(), SnapDirectoryGroupPermission::copy(), SnapDirectory::createDirectory(), SnapDirectory::createResource(), SnapPermission::doCommit(), SnapSearch::execute(), SnapMetadata::findKeys(), SnapPermissionObject::getCapabilities(), SnapPermission::grantPrivilege(), SnapDirectory::listContents(), SnapBulkAction::listVersionsRecursive(), SnapDirectory::loadMaxDirOrdinal(), SnapResource::loadMaxOrdinal(), SnapDirectory::loadMaxResOrdinal(), SnapPermission::loadParties(), SnapPermission::loadSpecialUsers(), SnapPermissionObject::populate(), SnapVersion::populate(), SnapMetadata::populate(), SnapFile::populate(), SnapPathCache::recRegenDirectory(), SnapPathCache::recRegenResource(), SnapPathCache::regenPathCache(), SnapPathCache::removePathSet(), SnapFile::restore(), SnapPathCache::retrievePath(), SnapPermission::revokePrivilege(), SnapPathCache::updatePathSet(), SnapPermissionObject::warmCache(), and SnapPermissionCache::warmCache().

static SnapDBI::startTransaction (  )  [static]


Member Data Documentation

SnapDBI::$CONN [static, private]

Connection to MySQL database

Definition at line 15 of file SnapDBI.php5.

SnapDBI::$QUERY_COUNT [static, private]

Number of queries performed so far (only used for debug statements)

Definition at line 19 of file SnapDBI.php5.

SnapDBI::$RCOOKIE [static, private]

Cookie for last result from a query

Definition at line 17 of file SnapDBI.php5.

SnapDBI::$transLevel [static, private]

How many levels of transaction nesting are we in?

Definition at line 22 of file SnapDBI.php5.


The documentation for this class was generated from the following file:

Generated on Wed Nov 24 02:06:25 2010 for Common by  doxygen 1.5.6