kernel
[ class tree: kernel ] [ index: kernel ] [ all elements ]

Class: BitDbPear

Source Location: /kernel/BitDbPear.php

Class Overview

BitDb
   |
   --BitDbPear

This class is used for database access and provides a number of functions to help with database portability.


Methods


Inherited Variables

Inherited Methods

Class: BitDb

BitDb::BitDb()
During initialisation, database parameters are passed to the class.
BitDb::Affected_Rows()
BitDb::associateInsert()
This function will take a set of fields identified by an associative array - $insertData
BitDb::associateUpdate()
This function will take a set of fields identified by an associative array - $updateData
BitDb::CompleteTrans()
Used together with StartTrans() to end a transaction. Monitors connection for sql errors, and will commit or rollback as appropriate.
BitDb::convertBinary()
Returns the keyword to force a column comparison to be case sensitive
BitDb::convertQuery()
Converts backtick (`) quotes to the appropriate quote for the database.
BitDb::convertSortmode()
Converts field sorting abbreviation to SQL - you can pass in a single string or an entire array of sortmodes
BitDb::convertSortmodeOneItem()
Converts field sorting abbreviation to SQL and it also allows us to do things like sort by random rows.
BitDb::convert_binary()
BitDb::convert_sortmode()
BitDb::convert_sortmode_one_item()
BitDb::CreateSequence()
A database portable Sequence management function.
BitDb::createTables()
Used to create tables - most commonly from package/schema_inc.php files
BitDb::dbByteDecode()
Used to decode blob data (eg PostgreSQL)
BitDb::dbByteEncode()
Used to encode blob data (eg PostgreSQL). Can be called statically
BitDb::db_byte_decode()
BitDb::db_byte_encode()
BitDb::debug()
will activate ADODB like native debugging output
BitDb::depText()
BitDb::dropTables()
Used to drop tables
BitDb::Execute()
ADODB compatibility functions for bitcommerce
BitDb::GenID()
A database portable Sequence management function.
BitDb::getArray()
Returns an associative array for the given query.
BitDb::getAssoc()
Returns an associative array for the given query.
BitDb::getCaselessColumn()
Compatibility function for DBs with case insensitive searches
BitDb::getCaseSensitivity()
Sets the case sensitivity mode which is used in convertQuery
BitDb::getCol()
Executes the SQL and returns all elements of the first column as a 1-dimensional array. The recordset is discarded for you automatically. If an error occurs, false is returned.
BitDb::getDatabaseVersion()
determine current version of the databse
BitDb::getDebugLevel()
returns the level of query debugging output
BitDb::getOne()
Returns a single column value from the database.
BitDb::getPeriodFormat()
BitDb::getRow()
Executes the SQL and returns the first row as an array. The recordset and remaining rows are discarded for you automatically. If an error occurs, false is returned.
BitDb::ifNull()
A database portable IFNULL function.
BitDb::isAdvancedPostgresEnabled()
Check for Postgres specific extensions
BitDb::isCachingActive()
Function to set ADODB query caching member variable
BitDb::isFatalActive()
Determines if the database connection is valid
BitDb::isValid()
Determines if the database connection is valid
BitDb::ls()
Format the timestamp in the format the database accepts.
BitDb::MetaColumns()
List columns in a database as an array of ADOFieldObjects.
BitDb::MetaIndexes()
List indexes in a database as an array of ADOFieldObjects.
BitDb::MetaTables()
Create a list of tables available in the current database
BitDb::NOW()
Return the current timestamp literal relevent to the database type
BitDb::OffsetDate()
Calculate the offset of a date for a particular database and generate appropriate SQL. Useful for calculating future/past dates and storing in a database.
BitDb::postDBConnection()
This function contains any post-connection work
BitDb::preDBConnection()
This function contains any pre-connection work
BitDb::qstr()
Quotes a string to be sent to the database
BitDb::qtNOW()
Return the current timestamp literal relevent to the database type
BitDb::query()
Queries the database reporting an error if detected
BitDb::queryComplete()
Used to stop query tracking and output results if in debug mode
BitDb::queryError()
Queries the database, returning an error if one occurs, rather
BitDb::queryStart()
Used to start query timer if in debug mode
BitDb::random()
A database portable RANDOM() function.
BitDb::RollbackTrans()
If database does not support transactions, rollbacks always fail, so return false otherwise returns true if the Rollback was successful
BitDb::setCaching()
Function to set ADODB query caching member variable
BitDb::setCaseSensitivity()
Sets the case sensitivity mode which is used in convertQuery
BitDb::setFatalActive()
Determines if the database connection is valid
BitDb::sqlCast()
Used to cast variable types for certain databases (ie SyBase & MSSQL)
BitDb::SQLDate()
Format date column in sql string given an input format that understands Y M D
BitDb::SQLForUpdate()
Return the sql to lock selected rows for updating.
BitDb::SQLIntToTimestamp()
Return the sql to cast the given column from an long integer to a time stamp.
BitDb::SQLTimestampToInt()
Return the sql to cast the given column from a time stamp to a Unix epoch
BitDb::sql_cast()
BitDb::StartTrans()
Improved method of initiating a transaction. Used together with CompleteTrans().
BitDb::tableExists()
Used to check if tables already exists.

Class Details

[line 33]
This class is used for database access and provides a number of functions to help with database portability.

Currently used as a base class, this class should be optional to ensure bitweaver continues to function correctly, without a valid database connection.




[ Top ]


Class Methods


constructor __construct [line 35]

BitDbPear __construct( [ $pPearDsn = NULL], [ $pPearOptions = NULL])



Parameters:

   $pPearDsn  
   $pPearOptions  

[ Top ]

method Affected_Rows [line 440]

# Affected_Rows( )



Tags:

return:  rows affected by UPDATE/DELETE


Overrides BitDb::Affected_Rows() (parent method not documented)

[ Top ]

method CompleteTrans [line 402]

true CompleteTrans( )

Used together with StartTrans() to end a transaction. Monitors connection for sql errors, and will commit or rollback as appropriate.

autoComplete if true, monitor sql errors and commit and rollback as appropriate, and if set to false force rollback even if no SQL error detected.




Tags:

return:  on commit, false on rollback.


Overrides BitDb::CompleteTrans() (Used together with StartTrans() to end a transaction. Monitors connection for sql errors, and will commit or rollback as appropriate.)

[ Top ]

method CreateSequence [line 323]

0 CreateSequence( [pSequenceName $seqname = 'adodbseq'], [pStartID $startID = 1])

A database portable Sequence management function.



Tags:

return:  if not supported, otherwise a sequence id
todo:  To be combined with GenID


Overrides BitDb::CreateSequence() (A database portable Sequence management function.)

Parameters:

pSequenceName   $seqname   Name of the sequence to be used It will be created if it does not already exist
pStartID   $startID   Allows setting the initial value of the sequence

[ Top ]

method Execute [line 170]

void Execute( $pQuery, [ $pNumRows = false], [ $zf_cache = false], [ $pCacheTime = BIT_QUERY_DEFAULT])

compatibility function



Overrides BitDb::Execute() (ADODB compatibility functions for bitcommerce)

Parameters:

   $pQuery  
   $pNumRows  
   $zf_cache  
   $pCacheTime  

[ Top ]

method GenID [line 299]

0 GenID( pSequenceName $pSequenceName, [ $pUseDbPrefix = true])

A database portable Sequence management function.



Tags:

return:  if not supported, otherwise a sequence id


Overrides BitDb::GenID() (A database portable Sequence management function.)

Parameters:

pSequenceName   $pSequenceName   Name of the sequence to be used It will be created if it does not already exist
   $pUseDbPrefix  

[ Top ]

method getAll [line 221]

void getAll( $pQuery, [ $pValues = FALSE], [ $pCacheTime = BIT_QUERY_DEFAULT])



Parameters:

   $pQuery  
   $pValues  
   $pCacheTime  

[ Top ]

method getArray [line 208]

the getArray( pQuery $pQuery, [pValues $pValues = FALSE], [pForceArray $pForceArray = FALSE], [pFirst2Cols $pFirst2Cols = FALSE], [ $pCacheTime = BIT_QUERY_DEFAULT])

Returns an associative array for the given query.

See AdoDB GetAssoc() function for more detail.




Tags:

return:  associative array, or false if an error occurs


Overrides BitDb::getArray() (Returns an associative array for the given query.)

Parameters:

pQuery   $pQuery   the SQL query. Use backticks (`) to quote all table and attribute names for AdoDB to quote appropriately.
pValues   $pValues   an array of values used in a parameterised query
pForceArray   $pForceArray   if set to true, when an array is created for each value
pFirst2Cols   $pFirst2Cols   if set to true, only returns the first two columns
   $pCacheTime  

[ Top ]

method getAssoc [line 241]

the getAssoc( pQuery $pQuery, [pValues $pValues = array()], [pForceArray $pForceArray = FALSE], [pFirst2Cols $pFirst2Cols = FALSE], [ $pCacheTime = BIT_QUERY_DEFAULT])

Returns an associative array for the given query.

See AdoDB GetAssoc() function for more detail.




Tags:

return:  associative array, or false if an error occurs


Overrides BitDb::getAssoc() (Returns an associative array for the given query.)

Parameters:

pQuery   $pQuery   the SQL query. Use backticks (`) to quote all table and attribute names for AdoDB to quote appropriately.
pValues   $pValues   an array of values used in a parameterised query
pForceArray   $pForceArray   if set to true, when an array is created for each value
pFirst2Cols   $pFirst2Cols   if set to true, only returns the first two columns
   $pCacheTime  

[ Top ]

method getCol [line 185]

the getCol( pQuery $pQuery, [pValues $pValues = array()], [pForceArray $pTrim = FALSE], pFirst2Cols 3)

Executes the SQL and returns all elements of the first column as a 1-dimensional array. The recordset is discarded for you automatically. If an error occurs, false is returned.

See AdoDB GetCol() function for more detail.




Tags:

return:  associative array, or false if an error occurs
todo:  not currently used anywhere


Overrides BitDb::getCol() (Executes the SQL and returns all elements of the first column as a 1-dimensional array. The recordset is discarded for you automatically. If an error occurs, false is returned.)

Parameters:

pFirst2Cols   3   if set to true, only returns the first two columns
pQuery   $pQuery   the SQL query. Use backticks (`) to quote all table and attribute names for AdoDB to quote appropriately.
pValues   $pValues   an array of values used in a parameterised query
pForceArray   $pTrim   if set to true, when an array is created for each value

[ Top ]

method getOne [line 280]

the getOne( pQuery $pQuery, [pValues $pValues = NULL], [pReportErrors $pNumRows = NULL], [pOffset $pOffset = NULL], [ $pCacheTime = BIT_QUERY_DEFAULT])

Returns a single column value from the database.



Tags:

return:  associative array, or false if an error occurs


Overrides BitDb::getOne() (Returns a single column value from the database.)

Parameters:

pQuery   $pQuery   the SQL query. Use backticks (`) to quote all table and attribute names for AdoDB to quote appropriately.
pValues   $pValues   an array of values used in a parameterised query
pReportErrors   $pNumRows   report errors to STDOUT
pOffset   $pOffset   the row number to begin returning rows from.
   $pCacheTime  

[ Top ]

method getRow [line 260]

returns getRow( pQuery $pQuery, [pValues $pValues = FALSE], [ $pCacheTime = BIT_QUERY_DEFAULT])

Executes the SQL and returns the first row as an array. The recordset and remaining rows are discarded for you automatically. If an error occurs, false is returned.

See AdoDB GetRow() function for more detail.




Tags:

return:  the first row as an array, or false if an error occurs


Overrides BitDb::getRow() (Executes the SQL and returns the first row as an array. The recordset and remaining rows are discarded for you automatically. If an error occurs, false is returned.)

Parameters:

pQuery   $pQuery   the SQL query. Use backticks (`) to quote all table and attribute names for AdoDB to quote appropriately.
pValues   $pValues   an array of values used in a parameterised query
   $pCacheTime  

[ Top ]

method ifNull [line 338]

a ifNull( pField $pField, pNullRepl $pNullRepl)

A database portable IFNULL function.



Tags:

return:  string that represents the function that checks whether $pField is NULL for the given database, and if NULL, change the value returned to $pNullRepl.


Overrides BitDb::ifNull() (A database portable IFNULL function.)

Parameters:

pField   $pField   argument to compare to NULL
pNullRepl   $pNullRepl   the NULL replacement value

[ Top ]

method ls [line 349]

the ls( pDate $pDate)

Format the timestamp in the format the database accepts.



Tags:

return:  timestamp as a quoted string.
todo:  could be used to later convert all int timestamps into db timestamps. Currently not used anywhere.


Overrides BitDb::ls() (Format the timestamp in the format the database accepts.)

Parameters:

pDate   $pDate   a Unix integer timestamp or an ISO format Y-m-d H:i:s

[ Top ]

method MetaTables [line 432]

array MetaTables( [ttype $ttype = false], [showSchema $showSchema = false], [mask $mask = false])

Create a list of tables available in the current database



Tags:

return:  of tables for current database.


Overrides BitDb::MetaTables() (Create a list of tables available in the current database)

Parameters:

ttype   $ttype   can either be 'VIEW' or 'TABLE' or false. If false, both views and tables are returned. "VIEW" returns only views "TABLE" returns only tables
showSchema   $showSchema   returns the schema/user with the table name, eg. USER.TABLE
mask   $mask   is the input mask - only supported by oci8 and postgresql

[ Top ]

method OffsetDate [line 376]

New OffsetDate( pDays $pDays, [pColumn $pColumn = NULL])

Calculate the offset of a date for a particular database and generate appropriate SQL. Useful for calculating future/past dates and storing in a database.



Tags:

return:  number of days
todo:  Not currently used - this is database specific and uses TIMESTAMP rather than unix seconds


Overrides BitDb::OffsetDate() (Calculate the offset of a date for a particular database and generate appropriate SQL. Useful for calculating future/past dates and storing in a database.)

Parameters:

pDays   $pDays   Number of days to offset by If dayFraction=1.5 means 1.5 days from now, 1.0/24 for 1 hour.
pColumn   $pColumn   Value to be offset If NULL an offset from the current time is supplied

[ Top ]

method qstr [line 84]

quoted qstr( pStr $pStr)

Quotes a string to be sent to the database which is passed to function on to AdoDB->qstr().



Tags:

return:  string using AdoDB->qstr()
todo:  not sure what its supposed to do


Overrides BitDb::qstr() (Quotes a string to be sent to the database)

Parameters:

pStr   $pStr   string to be quotes

[ Top ]

method query [line 129]

an query( pQuery $query, [pValues $values = null], [pNumRows $numrows = BIT_QUERY_DEFAULT], [pOffset $offset = BIT_QUERY_DEFAULT], [ $pCacheTime = BIT_QUERY_DEFAULT])

Queries the database reporting an error if detected

than exiting while printing the error. -rlpowell




Tags:

return:  AdoDB RecordSet object


Overrides BitDb::query() (Queries the database reporting an error if detected)

Parameters:

pQuery   $query   the SQL query. Use backticks (`) to quote all table and attribute names for AdoDB to quote appropriately.
pValues   $values   an array of values used in a parameterised query
pNumRows   $numrows   the number of rows (LIMIT) to return in this query
pOffset   $offset   the row number to begin returning rows from. Used in conjunction with $pNumRows
   $pCacheTime  

[ Top ]

method queryComplete [line 157]

void queryComplete( )



Overrides BitDb::queryComplete() (Used to stop query tracking and output results if in debug mode)

[ Top ]

method queryError [line 101]

an queryError( pQuery $pQuery, pError &$pError, [pValues $pValues = NULL], [pNumRows $pNumRows = -1], [pOffset $pOffset = -1])

Queries the database, returning an error if one occurs, rather

than exiting while printing the error. -rlpowell




Tags:

return:  AdoDB RecordSet object conjunction with $pNumRows
todo:  currently not used anywhere.


Overrides BitDb::queryError() (Queries the database, returning an error if one occurs, rather)

Parameters:

pQuery   $pQuery   the SQL query. Use backticks (`) to quote all table and attribute names for AdoDB to quote appropriately.
pError   &$pError   the error string to modify and return
pValues   $pValues   an array of values used in a parameterised query
pNumRows   $pNumRows   the number of rows (LIMIT) to return in this query
pOffset   $pOffset   the row number to begin returning rows from. Used in

[ Top ]

method RollbackTrans [line 414]

true/false. RollbackTrans( )

If database does not support transactions, rollbacks always fail, so return false otherwise returns true if the Rollback was successful



Overrides BitDb::RollbackTrans() (If database does not support transactions, rollbacks always fail, so return false otherwise returns true if the Rollback was successful)

[ Top ]

method SQLDate [line 359]

void SQLDate( $pDateFormat, [ $pBaseDate = false])

Format date column in sql string given an input format that understands Y M D



Overrides BitDb::SQLDate() (Format date column in sql string given an input format that understands Y M D)

Parameters:

   $pDateFormat  
   $pBaseDate  

[ Top ]

method StartTrans [line 390]

void StartTrans( )

Improved method of initiating a transaction. Used together with CompleteTrans().

Advantages include:

a. StartTrans/CompleteTrans is nestable, unlike BeginTrans/CommitTrans/RollbackTrans. Only the outermost block is treated as a transaction.
b. CompleteTrans auto-detects SQL errors, and will rollback on errors, commit otherwise.
c. All BeginTrans/CommitTrans/RollbackTrans inside a StartTrans/CompleteTrans block are disabled, making it backward compatible.




Overrides BitDb::StartTrans() (Improved method of initiating a transaction. Used together with CompleteTrans().)

[ Top ]


Documentation generated on Wed, 29 Jul 2015 13:55:50 +0000 by phpDocumentor 1.5.0-lsces