[Cs-webapplibs-commits] SF.net SVN: cs-webapplibs:[177] trunk/0.3
Status: Beta
Brought to you by:
crazedsanity
From: <cra...@us...> - 2010-07-07 14:14:55
|
Revision: 177 http://cs-webapplibs.svn.sourceforge.net/cs-webapplibs/?rev=177&view=rev Author: crazedsanity Date: 2010-07-07 14:14:46 +0000 (Wed, 07 Jul 2010) Log Message: ----------- Better checking, exceptions on invalid data, add queryList to cs_phpDB. /cs_phpDB.class.php: * MAIN::: -- NEW (public) VAR: $queryList=array() * __call(): -- if method is 'exec', add query to the queryList (holds last 20) * is_connected(): -- returns the value of dbLayerObj->is_connected(). /cs_webdblogger.class.php: * __construct(): -- throws an exception if the passed $db object isn't an object. /cs_webdbupgrade.class.php: * load_initial_version(): -- put calls to cs_phpDB methods into try/catch /abstract/cs_singleTableHandler.abstract.class.php: * MAIN::: -- changed members/vars to non-abstract (not valid) * __construct(): -- better checking of the database object. /db_types/cs_phpDB__pgsql.class.php: * exec(): -- simplify checking: if numRows() gives a good answer, use that; otherwise, use the output of numAffected(). /db_types/cs_phpDB__mysql.class.php: * exec(): -- simplify check as in pgsql layer. /db_types/cs_phpDB__sqlite.class.php: * exec(): -- simplify check as in pgsql layer. /tests/testOfCSGenericPermissions.php: * get_valid_users(): -- put stuff into try/catch. -- NOTE::: there's a call to cs_debug_backtrace(), which is a function that only exists locally. Modified Paths: -------------- trunk/0.3/abstract/cs_singleTableHandler.abstract.class.php trunk/0.3/cs_phpDB.class.php trunk/0.3/cs_webdblogger.class.php trunk/0.3/cs_webdbupgrade.class.php trunk/0.3/db_types/cs_phpDB__mysql.class.php trunk/0.3/db_types/cs_phpDB__pgsql.class.php trunk/0.3/db_types/cs_phpDB__sqlite.class.php trunk/0.3/tests/testOfCSGenericPermissions.php Modified: trunk/0.3/abstract/cs_singleTableHandler.abstract.class.php =================================================================== --- trunk/0.3/abstract/cs_singleTableHandler.abstract.class.php 2010-06-24 21:15:25 UTC (rev 176) +++ trunk/0.3/abstract/cs_singleTableHandler.abstract.class.php 2010-07-07 14:14:46 UTC (rev 177) @@ -13,11 +13,11 @@ abstract class cs_singleTableHandlerAbstract extends cs_webapplibsAbstract { protected $gfObj; - abstract protected $tableName; - abstract protected $seqName; - abstract protected $pkeyField; - abstract protected $cleanStringArr; - abstract protected $dbParams; + protected $tableName; + protected $seqName; + protected $pkeyField; + protected $cleanStringArr; + protected $dbParams; //------------------------------------------------------------------------- /** @@ -33,11 +33,11 @@ $this->set_version_file_location(dirname(__FILE__) . '/../VERSION'); parent::__construct(true); - if($dbObj->is_connnected()) { + if(isset($dbObj) && is_object($dbObj) && $dbObj->is_connected()) { $this->dbObj = $dbObj; } else { - throw new exception(__METHOD__ .":: database object not connected"); + throw new exception(__METHOD__ .":: database object not connected or not passed"); } if(is_string($tableName) && strlen($tableName)) { Modified: trunk/0.3/cs_phpDB.class.php =================================================================== --- trunk/0.3/cs_phpDB.class.php 2010-06-24 21:15:25 UTC (rev 176) +++ trunk/0.3/cs_phpDB.class.php 2010-07-07 14:14:46 UTC (rev 177) @@ -26,6 +26,7 @@ class cs_phpDB extends cs_webapplibsAbstract { + public $queryList=array(); private $dbLayerObj; private $dbType; public $connectParams = array(); @@ -60,6 +61,13 @@ //capture the connection parameters. $this->connectParams = $args[0]; } + elseif($methodName == 'exec') { + //update lastQuery list... should hold the last few SQL commands. + if(count($this->queryList) > 20) { + array_pop($this->queryList); + } + array_unshift($this->queryList, $args[0]); + } $retval = call_user_func_array(array($this->dbLayerObj, $methodName), $args); } else { @@ -204,6 +212,14 @@ return($retval); }//end run_sql_file() //========================================================================= + + + + //========================================================================= + public function is_connected() { + return($this->dbLayerObj->is_connected()); + }//end is_connected() + //========================================================================= } // end class phpDB ?> Modified: trunk/0.3/cs_webdblogger.class.php =================================================================== --- trunk/0.3/cs_webdblogger.class.php 2010-06-24 21:15:25 UTC (rev 176) +++ trunk/0.3/cs_webdblogger.class.php 2010-07-07 14:14:46 UTC (rev 177) @@ -86,7 +86,12 @@ */ public function __construct(cs_phpDB &$db, $logCategory=null, $checkForUpgrades=true) { //assign the database object. - $this->db = $db; + if(is_object($db) && get_class($db) == 'cs_phpDB') { + $this->db = $db; + } + else { + throw new exception(__METHOD__ .":: invalid database object"); + } $this->set_version_file_location(dirname(__FILE__) . '/VERSION'); Modified: trunk/0.3/cs_webdbupgrade.class.php =================================================================== --- trunk/0.3/cs_webdbupgrade.class.php 2010-06-24 21:15:25 UTC (rev 176) +++ trunk/0.3/cs_webdbupgrade.class.php 2010-07-07 14:14:46 UTC (rev 177) @@ -1058,12 +1058,17 @@ $sql = 'INSERT INTO '. $this->config['DB_TABLE'] . $this->gfObj->string_from_array($insertData, 'insert'); - if($this->db->run_insert($sql, $this->sequenceName)) { - $loadRes = true; - $this->do_log("Created data for '". $this->projectName ."' with version '". $insertData['version_string'] ."'", 'initialize'); + try { + if($this->db->run_insert($sql, $this->sequenceName)) { + $loadRes = true; + $this->do_log("Created data for '". $this->projectName ."' with version '". $insertData['version_string'] ."'", 'initialize'); + } + else { + $this->error_handler(__METHOD__ .": failed to load initial version::: ". $e->getMessage()); + } } - else { - $this->error_handler(__METHOD__ .": failed to load initial version::: ". $e->getMessage()); + catch(Exception $e) { + $this->error_handler(__METHOD__ .":: failed to load initial version due to exception, DETAILS::: ". $e->getMessage()); } return($loadRes); Modified: trunk/0.3/db_types/cs_phpDB__mysql.class.php =================================================================== --- trunk/0.3/db_types/cs_phpDB__mysql.class.php 2010-06-24 21:15:25 UTC (rev 176) +++ trunk/0.3/db_types/cs_phpDB__mysql.class.php 2010-07-07 14:14:46 UTC (rev 177) @@ -213,19 +213,18 @@ $this->result = mysql_query($query, $this->connectionID); if($this->result !== false) { - if (eregi("^[[:space:]]*select", $query)) { - //If we didn't have an error and we are a select statement, move the pointer to first result + if($this->result !== false) { $numRows = $this->numRows(); - if($numRows > 0) { - $this->move_first(); + if($numRows != 0) { + $returnVal = $numRows; + if($numRows > 0) { + $this->move_first(); + } } - $returnVal = $numRows; - + else { + $returnVal = $this->numAffected(); + } } - else { - //We got something other than an update. Use numAffected - $returnVal = $this->numAffected(); - } } return($returnVal); }//end exec() Modified: trunk/0.3/db_types/cs_phpDB__pgsql.class.php =================================================================== --- trunk/0.3/db_types/cs_phpDB__pgsql.class.php 2010-06-24 21:15:25 UTC (rev 176) +++ trunk/0.3/db_types/cs_phpDB__pgsql.class.php 2010-07-07 14:14:46 UTC (rev 177) @@ -230,27 +230,25 @@ if($this->useQueryList) { $this->queryList[] = $query; } - $returnVal = false; + $returnVal = false; if(($this->get_transaction_status() != -1) && ($this->connectionID != -1)) { $this->result = @pg_query($this->connectionID, $query); if($this->result !== false) { - if (eregi("^[[:space:]]*select", $query)) { - //If we didn't have an error and we are a select statement, move the pointer to first result - $numRows = $this->numRows(); + $numRows = $this->numRows(); + if($numRows != 0) { + $returnVal = $numRows; if($numRows > 0) { $this->move_first(); } - $returnVal = $numRows; - } else { - //We got something other than an update. Use numAffected $returnVal = $this->numAffected(); } } } + return($returnVal); }//end exec() //========================================================================= Modified: trunk/0.3/db_types/cs_phpDB__sqlite.class.php =================================================================== --- trunk/0.3/db_types/cs_phpDB__sqlite.class.php 2010-06-24 21:15:25 UTC (rev 176) +++ trunk/0.3/db_types/cs_phpDB__sqlite.class.php 2010-07-07 14:14:46 UTC (rev 177) @@ -178,13 +178,14 @@ $this->result = @sqlite_query($this->connectionID, $query); if($this->result !== false) { - if (eregi("^[[:space:]]*select", $query)) { - //If we didn't have an error and we are a select statement, move the pointer to first result - $numRows = $this->numRows(); + $numRows = $this->numRows(); + if($numRows != 0) { $returnVal = $numRows; + if($numRows > 0) { + $this->move_first(); + } } else { - //We got something other than an update. Use numAffected $returnVal = $this->numAffected(); } } Modified: trunk/0.3/tests/testOfCSGenericPermissions.php =================================================================== --- trunk/0.3/tests/testOfCSGenericPermissions.php 2010-06-24 21:15:25 UTC (rev 176) +++ trunk/0.3/tests/testOfCSGenericPermissions.php 2010-07-07 14:14:46 UTC (rev 177) @@ -81,8 +81,14 @@ */ private function get_valid_users() { $sql = "SELECT uid,username FROM cs_authentication_table ORDER BY uid"; - $db = $this->create_dbconn(); - $this->validUsers = $db->run_query($sql); + try { + $db = $this->create_dbconn(); + $this->validUsers = $db->run_query($sql); + } + catch(Exception $e) { + cs_debug_backtrace(1); + throw new exception(__METHOD__ .":: failed to retrieve any records (". $db->numRows() ."), DB OBJECT::: ". $this->gfObj->debug_print($db,0)); + } }//end get_valid_users() //-------------------------------------------------------------------------- This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |