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

Source for file BitDbAdodb.php

Documentation is available at BitDbAdodb.php

  1. <?php
  2. /**
  3.  * ADOdb Library interface Class
  4.  *
  5.  * @package kernel
  6.  * @version $Header$
  7.  *
  8.  *  Copyright (c) 2004 bitweaver.org
  9.  *  Copyright (c) 2003 tikwiki.org
  10.  *  Copyright (c) 2002-2003, Luis Argerich, Garland Foster, Eduardo Polidor, et. al.
  11.  *  All Rights Reserved. See below for details and a complete list of authors.
  12.  *  Licensed under the GNU LESSER GENERAL PUBLIC LICENSE. See http://www.gnu.org/copyleft/lesser.html for details
  13.  *
  14.  * @author spider <spider@steelsun.com>
  15.  */
  16.  
  17. /**
  18.  * This code must execute before adodb/adodb.inc.php runs
  19.  * Otherwsie $ADODB_CACHE_DIR ends up being set to '/tmp'
  20.  */
  21. global $ADODB_CACHE_DIR;
  22. ifempty$ADODB_CACHE_DIR )) {
  23.     $ADODB_CACHE_DIR get_temp_dir().'/adodb/'.$_SERVER['HTTP_HOST'].'/';
  24. }
  25. mkdir_p$ADODB_CACHE_DIR );
  26.  
  27. require_onceEXTERNAL_LIBS_PATH.'adodb/adodb.inc.php' );
  28. require_onceKERNEL_PKG_PATH.'BitDbBase.php' );
  29.  
  30. /**
  31.  * This class is used for database access and provides a number of functions to help
  32.  * with database portability.
  33.  *
  34.  * Currently used as a base class, this class should be optional to ensure bitweaver
  35.  * continues to function correctly, without a valid database connection.
  36.  *
  37.  * @package kernel
  38.  */
  39. class BitDbAdodb extends BitDb {
  40.     function BitDbAdodb$pConnectionHash NULL {
  41.         global $ADODB_FETCH_MODE;
  42.         ifis_null$pConnectionHash ) ) {
  43.             global $gBitDbType$gBitDbHost$gBitDbUser$gBitDbPassword$gBitDbName;
  44.             $pConnectionHash['db_type'$gBitDbType;
  45.             $pConnectionHash['db_host'$gBitDbHost;
  46.             $pConnectionHash['db_user'$gBitDbUser;
  47.             $pConnectionHash['db_password'$gBitDbPassword;
  48.             $pConnectionHash['db_name'$gBitDbName;
  49.         }
  50.  
  51.         parent::__construct();
  52.  
  53.         // Get all the ADODB stuff included
  54.         if!defined"ADODB_ASSOC_CASE" )) {
  55.             define"ADODB_ASSOC_CASE");
  56.         }
  57.         if!defined"ADODB_FETCH_MODE" )) {
  58.             define"ADODB_FETCH_MODE"ADODB_ASSOC_CASE );
  59.         }
  60.         $ADODB_FETCH_MODE ADODB_FETCH_ASSOC;
  61.  
  62.         if!empty$pConnectionHash['db_name'&& !empty$pConnectionHash['db_type') ) {
  63.             if$pConnectionHash['db_type'== 'oci8' {
  64.                 $pConnectionHash['db_type''oci8po';
  65.             }
  66.             $this->mType = $pConnectionHash['db_type'];
  67.             $this->mName = $pConnectionHash['db_name'];
  68.             if!isset$this->mName )) {
  69.                 die"No database name specified" );
  70.             }
  71.             $this->preDBConnection();
  72.             $this->mDb = ADONewConnection$pConnectionHash['db_type');
  73.             $this->mDb->Connect$pConnectionHash['db_host']$pConnectionHash['db_user']$pConnectionHash['db_password']$pConnectionHash['db_name');
  74.  
  75.             if!$this->mDb {
  76.                 die"Unable to login to the database $pConnectionHash[db_type] on $pConnectionHash[db_host] as `user` $pConnectionHash[db_user]<p>".$this->mDb->ErrorMsg() );
  77.             }
  78.             $this->postDBConnection();
  79.             unset$pDSN );
  80.             ifdefined"DB_PERFORMANCE_STATS" && constant"DB_PERFORMANCE_STATS" )) {
  81.                 $this->mDb->LogSQL();
  82.             }
  83.         }
  84.  
  85.         $this->debug$this->getDebugLevel() );
  86.     }
  87.  
  88.     /**
  89.      * Used to create tables - most commonly from package/schema_inc.php files
  90.      * @todo remove references to BIT_DB_PREFIX, us a member function
  91.      * @param pTables an array of tables and creation information in DataDict
  92.      *  style
  93.      * @param pOptions an array of options used while creating the tables
  94.      * @return TRUE|FALSE
  95.      *  TRUE if created with no errors | FALSE if errors are stored in $this->mFailed
  96.      */
  97.     function createTables$pTables$pOptions array() ) {
  98.         // If server support InnoDB for MySql set the selected engine
  99.         ifisset$_SESSION['use_innodb')) {
  100.             if$_SESSION['use_innodb'== TRUE {
  101.                 $pOptions array_merge$pOptionsarray'MYSQL' => 'ENGINE=INNODB' ));
  102.             else {
  103.                 $pOptions array_merge$pOptionsarray'MYSQL' => 'ENGINE=MYISAM' ));
  104.             }
  105.         }
  106.         $dict NewDataDictionary$this->mDb );
  107.         $this->mFailed = array();
  108.         $result TRUE;
  109.         foreacharray_keys$pTables AS $tableName {
  110.             $completeTableName defined"BIT_DB_PREFIX" )) BIT_DB_PREFIX.$tableName $tableName;
  111.             $sql $dict->CreateTableSQL($completeTableName$pTables[$tableName]$pOptions);
  112.             if$sql && $dict->ExecuteSQLArray$sql )) {
  113.                 // Success
  114.             else {
  115.                 // Failure
  116.                 $result FALSE;
  117.                 array_push$this->mFailed$sql.": ".$this->mDb->ErrorMsg() );
  118.             }
  119.         }
  120.         return $result;
  121.     }
  122.  
  123.     /**
  124.      * Used to check if tables already exists.
  125.      * @todo should be used to confirm tables are already created
  126.      * @param pTable the table name
  127.      * @return TRUE if table already exists
  128.      */
  129.     function tableExists$pTable {
  130.         $dict NewDataDictionary$this->mDb );
  131.         $pTable preg_replace"/`/"""$pTable );
  132.         $tables $dict->MetaTablesFALSEFALSE$pTable );
  133.         return array_search$pTable$tables !== FALSE;
  134.     }
  135.  
  136.     /**
  137.      * Used to drop tables
  138.      * @todo remove references to BIT_DB_PREFIX, us a member function
  139.      * @param pTables an array of table names to drop
  140.      * @return TRUE | FALSE
  141.      *  TRUE if dropped with no errors |
  142.      *  FALSE if errors are stored in $this->mFailed
  143.      */
  144.     function dropTables$pTables {
  145.         $dict NewDataDictionary$this->mDb );
  146.         $this->mFailed = array();
  147.         $return TRUE;
  148.         foreach$pTables AS $tableName {
  149.             $completeTableName defined"BIT_DB_PREFIX" )) BIT_DB_PREFIX.$tableName $tableName;
  150.             $sql $dict->DropTableSQL$completeTableName );
  151.             if$sql && $dict->ExecuteSQLArray$sql )) {
  152.                 //echo "Success<br>";
  153.             else {
  154.                 //echo "Failure<br>";
  155.                 $return FALSE;
  156.                 array_push($this->mFailed$sql);
  157.             }
  158.         }
  159.         return $return;
  160.     }
  161.  
  162.     /**
  163.      * Quotes a string to be sent to the database which is
  164.      * passed to function on to AdoDB->qstr().
  165.      * @todo not sure what its supposed to do
  166.      * @param pStr string to be quotes
  167.      * @return quoted string using AdoDB->qstr()
  168.      */
  169.     function qstr$pStr {
  170.         return $this->mDb->qstr$pStr );
  171.     }
  172.     
  173.     /**
  174.      * Returns SUBSTRING function appropiate for database.
  175.      * @return string using AdoDB->substr property
  176.      */
  177.     function substr({
  178.         return $this->mDb->substr;
  179.     }
  180.  
  181.     /**
  182.      * Returns RANDOM function appropiate for database.
  183.      * Overrides BitDbBase::random()
  184.      * @return string using AdoDB->random property
  185.      */
  186.     function random({
  187.         return $this->mDb->random;
  188.         
  189.     }
  190.  
  191.     /** Queries the database, returning an error if one occurs, rather
  192.      * than exiting while printing the error. -rlpowell
  193.      * @param pQuery the SQL query. Use backticks (`) to quote all table
  194.      *  and attribute names for AdoDB to quote appropriately.
  195.      * @param pError the error string to modify and return
  196.      * @param pValues an array of values used in a parameterised query
  197.      * @param pNumRows the number of rows (LIMIT) to return in this query
  198.      * @param pOffset the row number to begin returning rows from. Used in
  199.      * @return an AdoDB RecordSet object
  200.      *  conjunction with $pNumRows
  201.      * @todo currently not used anywhere.
  202.      */
  203.     function queryError$pQuery&$pError$pValues NULL$pNumRows = -1$pOffset = -{
  204.         $this->convertQuery$pQuery );
  205.         if$pNumRows == -&& $pOffset == -{
  206.             $result $this->mDb->Execute($pQuery$pValues);
  207.         else {
  208.             $result $this->mDb->SelectLimit($pQuery$pNumRows$pOffset$pValues);
  209.         }
  210.  
  211.         if!$result {
  212.             $pError $this->mDb->ErrorMsg();
  213.             $result=FALSE;
  214.         }
  215.         //count the number of queries made
  216.         $this->mNumQueries++;
  217.         //$this->debugger_log($pQuery, $pValues);
  218.         return $result;
  219.     }
  220.  
  221.     /** Queries the database reporting an error if detected
  222.      * than exiting while printing the error. -rlpowell
  223.      * @param pQuery the SQL query. Use backticks (`) to quote all table
  224.      *  and attribute names for AdoDB to quote appropriately.
  225.      * @param pValues an array of values used in a parameterised query
  226.      * @param pNumRows the number of rows (LIMIT) to return in this query
  227.      * @param pOffset the row number to begin returning rows from. Used in
  228.      *  conjunction with $pNumRows
  229.      * @return an AdoDB RecordSet object
  230.      */
  231.     function query$query$values FALSE$numrows BIT_QUERY_DEFAULT$offset BIT_QUERY_DEFAULT$pCacheTime=BIT_QUERY_DEFAULT {
  232.         $this->convertQuery$query );
  233.         ifempty$this->mDb )) {
  234.             return FALSE;
  235.         }
  236.  
  237.         $this->queryStart();
  238.  
  239.         if!is_numeric$numrows )) {
  240.             $numrows BIT_QUERY_DEFAULT;
  241.         }
  242.  
  243.         if!is_numeric$offset )) {
  244.             $offset BIT_QUERY_DEFAULT;
  245.         }
  246.  
  247.         if$numrows == BIT_QUERY_DEFAULT && $offset == BIT_QUERY_DEFAULT {
  248.             if!$this->isCachingActive(|| $pCacheTime == BIT_QUERY_DEFAULT {
  249.                 $result $this->mDb->Execute$query$values );
  250.             else {
  251.                 $result $this->mDb->CacheExecute$pCacheTime$query$values );
  252.             }
  253.         else {
  254.             if!$this->isCachingActive(|| $pCacheTime == BIT_QUERY_DEFAULT {
  255.                 $result $this->mDb->SelectLimit$query$numrows$offset$values );
  256.             else {
  257.                 $result $this->mDb->CacheSelectLimit$pCacheTime$query$numrows$offset$values );
  258.             }
  259.         }
  260.  
  261.         $this->queryComplete();
  262.         return $result;
  263.     }
  264.  
  265.     /**
  266.      * List columns in a database as an array of ADOFieldObjects.
  267.      * See top of file for definition of object.
  268.      *
  269.      * @param table    table name to query
  270.      * @param upper    uppercase table name (required by some databases)
  271.      * @param schema is optional database schema to use - not supported by all databases.
  272.      *
  273.      * @return  array of ADOFieldObjects for current table.
  274.      */
  275.     function MetaColumns$table,$normalize=TRUE$schema=FALSE {
  276.         $table str_replace'`'''$table );
  277.         return $this->mDb->MetaColumns$table$normalize$schema );
  278.     }
  279.  
  280.     /**
  281.      * List indexes in a database as an array of ADOFieldObjects.
  282.      * See top of file for definition of object.
  283.      *
  284.      * @param table    table name to query
  285.      * @param primary list primary indexes
  286.      * @param owner list owner of index
  287.      *
  288.      * @return  array of ADOFieldObjects for current table.
  289.      */
  290.     function MetaIndexes$table,$primary=FALSE$owner=FALSE {
  291.         $table str_replace'`'''$table );
  292.         return $this->mDb->MetaIndexes$table$primary$owner );
  293.     }
  294.  
  295.     /**
  296.      * getAll
  297.      * 
  298.      * @param string $pQuery 
  299.      * @param array $pValues 
  300.      * @param numeric $pCacheTime 
  301.      * @access public
  302.      * @return TRUE on success, FALSE on failure - mErrors will contain reason for failure
  303.      */
  304.     function getAll$pQuery$pValues=FALSE$pCacheTime=BIT_QUERY_DEFAULT {
  305.         ifempty$this->mDb )) {
  306.             return FALSE;
  307.         }
  308.         $this->queryStart();
  309.         $this->convertQuery$pQuery );
  310.         if!$this->isCachingActive(|| $pCacheTime == BIT_QUERY_DEFAULT {
  311.             $result $this->mDb->getAll$pQuery$pValues );
  312.         else {
  313.             $result $this->mDb->CacheGetAll($pCacheTime$pQuery$pValues );
  314.         }
  315.         //count the number of queries made
  316.         $this->queryComplete();
  317.         return $result;
  318.     }
  319.  
  320.     /** 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.
  321.      * See AdoDB GetCol() function for more detail.
  322.      * @param pQuery the SQL query. Use backticks (`) to quote all table
  323.      *  and attribute names for AdoDB to quote appropriately.
  324.      * @param pValues an array of values used in a parameterised query
  325.      * @param pForceArray if set to TRUE, when an array is created for each value
  326.      * @param pFirst2Cols if set to TRUE, only returns the first two columns
  327.      * @return the associative array, or FALSE if an error occurs
  328.      * @todo not currently used anywhere
  329.      */
  330.     function getCol$pQuery$pValues=FALSE$pTrim=FALSE$pCacheTime=BIT_QUERY_DEFAULT {
  331.         ifempty$this->mDb )) {
  332.             return FALSE;
  333.         }
  334.         $this->queryStart();
  335.         $this->convertQuery$pQuery );
  336.         if!$this->isCachingActive(|| $pCacheTime == BIT_QUERY_DEFAULT {
  337.             $result $this->mDb->getCol$pQuery$pValues$pTrim );
  338.         else {
  339.             $result $this->mDb->CacheGetCol$pCacheTime$pQuery$pValues$pTrim );
  340.         }
  341.         //count the number of queries made
  342.         $this->queryComplete();
  343.         return $result;
  344.     }
  345.  
  346.     /** Returns an associative array for the given query.
  347.      * See AdoDB GetAssoc() function for more detail.
  348.      * @param pQuery the SQL query. Use backticks (`) to quote all table
  349.      *  and attribute names for AdoDB to quote appropriately.
  350.      * @param pValues an array of values used in a parameterised query
  351.      * @param pForceArray if set to TRUE, when an array is created for each value
  352.      * @param pFirst2Cols if set to TRUE, only returns the first two columns
  353.      * @return the associative array, or FALSE if an error occurs
  354.      */
  355.     function getArray$pQuery$pValues=FALSE$pForceArray=FALSE$pFirst2Cols=FALSE$pCacheTime=BIT_QUERY_DEFAULT {
  356.         ifempty$this->mDb )) {
  357.             return FALSE;
  358.         }
  359.         $this->queryStart();
  360.         $this->convertQuery$pQuery );
  361.         if!$this->isCachingActive(|| $pCacheTime == BIT_QUERY_DEFAULT {
  362.             $result $this->mDb->GetArray$pQuery$pValues$pForceArray$pFirst2Cols );
  363.         else {
  364.             $result $this->mDb->CacheGetArray$pCacheTime$pQuery$pValues$pForceArray$pFirst2Cols );
  365.         }
  366.         $this->queryComplete();
  367.         return $result;
  368.     }
  369.  
  370.     /** Returns an associative array for the given query.
  371.      * See AdoDB GetAssoc() function for more detail.
  372.      * @param pQuery the SQL query. Use backticks (`) to quote all table
  373.      *  and attribute names for AdoDB to quote appropriately.
  374.      * @param pValues an array of values used in a parameterised query
  375.      * @param pForceArray if set to TRUE, when an array is created for each value
  376.      * @param pFirst2Cols if set to TRUE, only returns the first two columns
  377.      * @return the associative array, or FALSE if an error occurs
  378.      */
  379.     function getAssoc$pQuery$pValues=FALSE$pForceArray=FALSE$pFirst2Cols=FALSE$pCacheTime=BIT_QUERY_DEFAULT {
  380.         ifempty$this->mDb )) {
  381.             return FALSE;
  382.         }
  383.         $this->queryStart();
  384.         $this->convertQuery$pQuery );
  385.         if!$this->isCachingActive(|| $pCacheTime == BIT_QUERY_DEFAULT {
  386.             $result $this->mDb->GetAssoc$pQuery$pValues$pForceArray$pFirst2Cols );
  387.         else {
  388.             $result $this->mDb->CacheGetAssoc$pCacheTime$pQuery$pValues$pForceArray$pFirst2Cols );
  389.         }
  390.         $this->queryComplete();
  391.         return $result;
  392.     }
  393.  
  394.     /** 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.
  395.      * See AdoDB GetRow() function for more detail.
  396.      * @param pQuery the SQL query. Use backticks (`) to quote all table
  397.      *  and attribute names for AdoDB to quote appropriately.
  398.      * @param pValues an array of values used in a parameterised query
  399.      * @return returns the first row as an array, or FALSE if an error occurs
  400.      */
  401.     function getRow$pQuery$pValues=FALSE$pCacheTime=BIT_QUERY_DEFAULT {
  402.         ifempty$this->mDb ) ) {
  403.             return FALSE;
  404.         }
  405.         $this->queryStart();
  406.         $this->convertQuery($pQuery);
  407.         if!$this->isCachingActive(|| $pCacheTime == BIT_QUERY_DEFAULT {
  408.             $result $this->mDb->GetRow$pQuery$pValues );
  409.         else {
  410.             $result $this->mDb->CacheGetRow$pCacheTime$pQuery$pValues );
  411.         }
  412.         $this->queryComplete();
  413.         return $result;
  414.     }
  415.  
  416.     /** Returns a single column value from the database.
  417.      * @param pQuery the SQL query. Use backticks (`) to quote all table
  418.      *  and attribute names for AdoDB to quote appropriately.
  419.      * @param pValues an array of values used in a parameterised query
  420.      * @param pReportErrors report errors to STDOUT
  421.      * @param pOffset the row number to begin returning rows from.
  422.      * @return the associative array, or FALSE if an error occurs
  423.      */
  424.     function getOne$pQuery$pValues=NULL$pNumRows=NULL$pOffset=NULL$pCacheTime BIT_QUERY_DEFAULT {
  425.         $result $this->query($pQuery$pValues1$pOffset$pCacheTime );
  426.         $res $result != NULL $result->fetchRow(FALSE;
  427.         if$res === FALSE {
  428.             //simulate pears behaviour
  429.             return NULL;
  430.         }
  431.         //$this->debugger_log($pQuery, $pValues);
  432.         list$key$value each($res);
  433.         return $value;
  434.     }
  435.  
  436.     /**
  437.      * A database portable Sequence management function.
  438.      *
  439.      * @param pSequenceName Name of the sequence to be used
  440.      *         It will be created if it does not already exist
  441.      * @return        if not supported, otherwise a sequence id
  442.      */
  443.     function GenID$pSequenceName$pUseDbPrefix TRUE {
  444.         ifempty$this->mDb )) {
  445.             return FALSE;
  446.         }
  447.         if$pUseDbPrefix {
  448.             $prefix str_replace"`"""BIT_DB_PREFIX );
  449.         else {
  450.             $prefix '';
  451.         }
  452.         return $this->mDb->GenID$prefix.$pSequenceName );
  453.     }
  454.  
  455.     /**
  456.      * A database portable Sequence management function.
  457.      *
  458.      * @param pSequenceName Name of the sequence to be used
  459.      *         It will be created if it does not already exist
  460.      * @param pStartID Allows setting the initial value of the sequence
  461.      * @return        if not supported, otherwise a sequence id
  462.      * @todo    To be combined with GenID
  463.      */
  464.     function CreateSequence$pSeqname='adodbseq',$startID={
  465.         ifempty$this->mDb->_genSeqSQL )) {
  466.             return FALSE;
  467.         }
  468.         return $this->mDb->CreateSequence$pSeqname$startID );
  469.     }
  470.  
  471.     /**
  472.      * A database portable Sequence management function.
  473.      *
  474.      * @param pSequenceName Name of the sequence to be dropped
  475.      *
  476.      * @return    FALSE if not supported
  477.      */
  478.     function DropSequence$pSeqname='adodbseq' {
  479.         ifempty$this->mDb->_dropSeqSQL )) {
  480.             return FALSE;
  481.         }
  482.         return $this->mDb->DropSequence$pSeqname );
  483.     }
  484.  
  485.     /**
  486.      * A database portable IFNULL function.
  487.      *
  488.      * @param pField argument to compare to NULL
  489.      * @param pNullRepl the NULL replacement value
  490.      * @return string that represents the function that checks whether
  491.      *  $pField is NULL for the given database, and if NULL, change the
  492.      *  value returned to $pNullRepl.
  493.      */
  494.     function ifNull$pField$pNullRepl {
  495.         return $this->mDb->ifNull$pField$pNullRepl );
  496.     }
  497.  
  498.     /** Format the timestamp in the format the database accepts.
  499.      * @param pDate a Unix integer timestamp or an ISO format Y-m-d H:i:s
  500.      * @return the timestamp as a quoted string.
  501.      * @todo could be used to later convert all int timestamps into db
  502.      *  timestamps. Currently not used anywhere.
  503.      */
  504.     function ls$pDate {
  505.         // not sure what this did - maybe someone can comment why its here
  506.         //return preg_replace("/'/","", $this->mDb->DBTimeStamp($pDate));
  507.         return $this->mDb->DBTimeStamp($pDate);
  508.     }
  509.  
  510.     /**
  511.      * Format date column in sql string given an input format that understands Y M D
  512.      */
  513.     function SQLDate$pDateFormat$pBaseDate=FALSE {
  514.         return $this->mDb->SQLDate$pDateFormat$pBaseDate );
  515.     }
  516.  
  517.     /**
  518.      * Calculate the offset of a date for a particular database and generate
  519.      * appropriate SQL. Useful for calculating future/past dates and storing
  520.      * in a database.
  521.      * @param pDays Number of days to offset by
  522.      *         If dayFraction=1.5 means 1.5 days from now, 1.0/24 for 1 hour.
  523.      * @param pColumn Value to be offset
  524.      *         If NULL an offset from the current time is supplied
  525.      * @return New number of days
  526.      *
  527.      * @todo Not currently used - this is database specific and uses TIMESTAMP
  528.      *  rather than unix seconds
  529.      */
  530.     function OffsetDate$pDays$pColumn=NULL {
  531.         return $this->mDb->OffsetDate$pDays$pColumn );
  532.     }
  533.  
  534.     /** Converts backtick (`) quotes to the appropriate quote for the
  535.      * database.
  536.      * @private
  537.      * @param pQuery the SQL query using backticks (`)
  538.      * @return the correctly quoted SQL statement
  539.      * @todo investigate replacement by AdoDB NameQuote() function
  540.      */
  541.     function convertQuery&$pQuery {
  542.         if!empty$this->mType )) {
  543.             switch$this->mType {
  544.             case "oci8":
  545.                 // convert bind variables - adodb does not do that
  546.                 $qe explode"?"$pQuery );
  547.                 $pQuery "";
  548.                 for$i 0$i sizeof($qe1$i++ {
  549.                     $pQuery .= $qe[$i":" $i;
  550.                 }
  551.                 $pQuery .= $qe[$i];
  552.             default:
  553.                 parent::convertQuery$pQuery );
  554.                 break;
  555.             }
  556.         }
  557.     }
  558.  
  559.     /** will activate ADODB's native debugging output
  560.      * @param pLevel debugging level - FALSE is off, TRUE is on, 99 is verbose
  561.      ***/
  562.     function debug$pLevel=99 {
  563.         parent::debug$pLevel );
  564.         ifis_object$this->mDb )) {
  565.             $this->mDb->debug $pLevel;
  566.         }
  567.     }
  568.  
  569.     /** returns the level of query debugging output
  570.      * @return pLevel debugging level - FALSE is off, TRUE is on, 99 is verbose
  571.      ***/
  572.     function getDebugLevel({
  573.         return$this->mDebug );
  574.     }
  575.  
  576.     /**
  577.      *    Improved method of initiating a transaction. Used together with CompleteTrans().
  578.      *    Advantages include:
  579.      *
  580.      *    a. StartTrans/CompleteTrans is nestable, unlike BeginTrans/CommitTrans/RollbackTrans.
  581.      *       Only the outermost block is treated as a transaction.<br>
  582.      *    b. CompleteTrans auto-detects SQL errors, and will rollback on errors, commit otherwise.<br>
  583.      *    c. All BeginTrans/CommitTrans/RollbackTrans inside a StartTrans/CompleteTrans block
  584.      *       are disabled, making it backward compatible.
  585.      */
  586.     function StartTrans({
  587.         return $this->mDb->StartTrans();
  588.     }
  589.  
  590.     /**
  591.      *    Used together with StartTrans() to end a transaction. Monitors connection
  592.      *    for sql errors, and will commit or rollback as appropriate.
  593.      *
  594.      *    autoComplete if TRUE, monitor sql errors and commit and rollback as appropriate,
  595.      *    and if set to FALSE force rollback even if no SQL error detected.
  596.      *    @returns TRUE on commit, FALSE on rollback.
  597.      */
  598.     function CompleteTrans({
  599.         return $this->mDb->CompleteTrans();
  600.     }
  601.  
  602.     /**
  603.      * If database does not support transactions, rollbacks always fail, so return FALSE
  604.      * otherwise returns TRUE if the Rollback was successful
  605.      *
  606.      * @return TRUE/FALSE. 
  607.      */
  608.     function RollbackTrans({
  609.         $this->mDb->FailTrans();
  610.         return $this->mDb->CompleteTransFALSE );
  611.     }
  612.  
  613.     /**
  614.      * Create a list of tables available in the current database
  615.      *
  616.      * @param ttype can either be 'VIEW' or 'TABLE' or FALSE.
  617.      *          If FALSE, both views and tables are returned.
  618.      *         "VIEW" returns only views
  619.      *         "TABLE" returns only tables
  620.      * @param showSchema returns the schema/user with the table name, eg. USER.TABLE
  621.      * @param mask  is the input mask - only supported by oci8 and postgresql
  622.      *
  623.      * @return  array of tables for current database.
  624.      */
  625.     function MetaTables$ttype FALSE$showSchema FALSE$mask=FALSE {
  626.         return $this->mDb->MetaTables$ttype$showSchema$mask );
  627.     }
  628.  
  629.     /**
  630.      * @return rows affected by UPDATE/DELETE
  631.      */
  632.     function Affected_Rows({
  633.         return $this->mDb->Affected_Rows();
  634.     }
  635. }
  636.  
  637. /*
  638.  * Custom ADODB Error Handler. This will be called with the following params
  639.  *
  640.  * @param $dbms        the RDBMS you are connecting to
  641.  * @param $fn        the name of the calling function (in uppercase)
  642.  * @param $errno        the native error number from the database
  643.  * @param $errmsg    the native error msg from the database
  644.  * @param $p1        $fn specific parameter - see below
  645.  * @param $P2        $fn specific parameter - see below
  646.  */
  647. function bitdb_error_handler$dbms$fn$errno$errmsg$p1$p2&$thisConnection {
  648.     global $gBitDb;
  649.     ifini_get'error_reporting' == {
  650.         return// obey @ protocol
  651.     }
  652.  
  653.     $dbParams array(
  654.         'db_type'=>$dbms,
  655.         'call_func'=>$fn,
  656.         'errno'=>$errno,
  657.         'db_msg'=>$errmsg,
  658.         'sql'=>$p1,
  659.         'p2'=>$p2
  660.     );
  661.     $logString bit_error_string$dbParams );
  662.  
  663.     /*
  664.      * Log connection error somewhere
  665.      *    0 message is sent to PHP's system logger, using the Operating System's system
  666.      *        logging mechanism or a file, depending on what the error_log configuration
  667.      *        directive is set to.
  668.      *    1 message is sent by email to the address in the destination parameter.
  669.      *        This is the only message type where the fourth parameter, extra_headers is used.
  670.      *        This message type uses the same internal function as mail() does.
  671.      *    2 message is sent through the PHP debugging connection.
  672.      *        This option is only available if remote debugging has been enabled.
  673.      *        In this case, the destination parameter specifies the host name or IP address
  674.      *        and optionally, port number, of the socket receiving the debug information.
  675.      *    3 message is appended to the file destination
  676.      */
  677.     error_log$logString,);
  678.     $subject = isset$_SERVER['SERVER_NAME'$_SERVER['SERVER_NAME''BITWEAVER';
  679.  
  680.     $fatal FALSE;
  681.     if(( $fn == 'EXECUTE' && $thisConnection->MetaError(!= -&& (empty$gBitDb || $gBitDb->isFatalActive()) ) {
  682.         $fatal TRUE;
  683.     }
  684.  
  685.     bit_display_error$logString$dbParams['db_msg']$fatal );
  686. }
  687. ?>

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