Class DB

Description

A minimal Database abstraction layer.

This class offers a very minimal database abstraction layer. CompInaBox is designed to run on top of the PostGreSQL Relational DataBase Management System and requires many of its features. Therefore database independence wasn't a huge concern. However having a single place to funnel all queries through is useful for future instrumentation work.

Located in /include/classes/database/DB.inc (line 23)


	
			
Direct descendents
Class Description
 class CIB_DB CIB Core Module Database API.
 class CompDB A minimal Database abstraction layer.
Variable Summary
 object $db
 string $dbname
 int $lastOID
 string $password
 string $user
Method Summary
 DB DB (string $dbname, string $user, mixed $pass, string $password)
 void commit ()
 string getDBName ()
 string getDBpass ()
 string getDBuser ()
 int getLastOID ()
 string helper_limitOffset (int $limit, int $offset)
 array helper_queryToArray (string $query)
 array helper_queryToArrayCategories (string $query)
 array helper_queryToSimpleArray (string $query)
 mixed helper_singleValueQuery (string $query)
 QueryResult query (string $query)
 void rollback ()
 void startTransaction ([string $level = "SERIALIZABLE"])
Variables
object $db (line 29)
  • var: the database connection
  • access: private
string $dbname (line 49)
  • var: the database connected to
  • access: private
int $lastOID (line 34)
  • var: the last assigned object/row identifier, deprecated
  • access: private
string $password (line 44)
  • var: the password used to connect
  • access: private
string $user (line 39)
  • var: the username connected as
  • access: private
Methods
Constructor DB (line 62)

DB Constructor

  • internal: If your database is not on the same server as your web server you will need to add a host=host.domain part to the connection string in the source code
  • access: public
DB DB (string $dbname, string $user, mixed $pass, string $password)
  • string $dbname: what database do you want to connect to
  • string $user: as what user
  • string $password: which what password
commit (line 148)

Commit an extended transaction block

Commit an extend transaction begun by startTransaction

  • access: public
void commit ()
getDBName (line 288)

Returns the database in use

  • return: the database connected to
  • access: public
  • internal: This function is almost only used to upgrade/downgrade a database connection to a different user
string getDBName ()
getDBpass (line 315)

Returns the current user's database password

  • return: the passwod of the current user
  • access: public
  • todo: remove the password and look up from the config file?
  • internal: This function is almost only used to upgrade/downgrade a database connection to a different user
string getDBpass ()
getDBuser (line 301)

Returns the database user connected as

  • return: the current database user
  • access: public
  • internal: This function is almost only used to upgrade/downgrade a database connection to a different user
string getDBuser ()
getLastOID (line 116)

Get the last assigned OID

  • return: the last assigned OID
  • access: public
  • deprecated: please use SELECT nextval(seq_name) queries
int getLastOID ()
helper_limitOffset (line 271)

returns a LIMIT n OFFSET m modification to a query.

A convienence function used add LIMIT/OFFSET information to an existing query.

  • return: the additional piece to tack onto the query
  • todo: Change to public and rename
  • access: protected
string helper_limitOffset (int $limit, int $offset)
  • int $limit: how many items to return from the DB
  • int $offset: where to start in the DB result set
helper_queryToArray (line 221)

Execute a query that returns a list of paired values

A convienence function used to unpack the QueryResult when a a list of links is expected, the first column of each row is used as the label, with the second as the link information. Used mainly for navigation elements.

  • return: a list in answer to the query
  • todo: Change to public and rename
  • access: protected
array helper_queryToArray (string $query)
  • string $query: the query to execute
helper_queryToArrayCategories (line 246)

Execute a query that returns a list of paired values organized into categories

A convienence function used to unpack the QueryResult when a a list of links is expected, the first column of each row is used as a category, the second as the label, with the third as the link information. Used mainly for navigation elements.

  • return: a list in answer to the query
  • todo: Change to public and rename
  • access: protected
array helper_queryToArrayCategories (string $query)
  • string $query: the query to execute
helper_queryToSimpleArray (line 197)

Execute a query that returns a list of scalar values A convienence function used to unpack the QueryResult when a list of single column values is expected, for use in cases like SELECT id FROM ...

  • return: a list in answer to the query
  • todo: Change to public and rename
  • access: protected
array helper_queryToSimpleArray (string $query)
  • string $query: the query to execute
helper_singleValueQuery (line 176)

Execute a query that returns a single scalar value A convienence function used to unpack the QueryResult when a single value is expected, for use in cases like SELECT count(*) FROM ...

  • return: a scalar answer to the query
  • todo: Change to public and rename
  • access: protected
mixed helper_singleValueQuery (string $query)
  • string $query: the query to execute
query (line 82)

Execute a query against the Database Preforms the query, returns a QueryResult in all cases, however the QueryResult is only useful in cases of SELECT queries. INSERTS will update the lastOID member variable.

Error conditions are indiated in the returned QueryResult.

  • return: the result of executing the query
  • access: public
QueryResult query (string $query)
  • string $query: the SQL query to execute
rollback (line 159)

Abort/Rollback an extended transaction block

Abort/Rollback an extend transaction begun by startTransaction

  • access: public
void rollback ()
startTransaction (line 133)

Start an extended transaction block Turn off auto-commit and begin an extended transaction block with the given isolation level.

  • internal: Note: that this defaults to the strictest transaction isolation level. There is no support at present for the nested tranactions or save points.
  • access: public
void startTransaction ([string $level = "SERIALIZABLE"])
  • string $level: the desired isolation level either SERIALIZABLE or READ COMMITTED defaulting to the former

Documentation generated on Tue, 25 Apr 2006 13:00:51 -0400 by phpDocumentor 1.3.0RC3