[Cs-webapplibs-commits] SF.net SVN: cs-webapplibs:[184] trunk/0.3/abstract/cs_singleTableHandler. a
Status: Beta
Brought to you by:
crazedsanity
From: <cra...@us...> - 2010-09-01 14:13:03
|
Revision: 184 http://cs-webapplibs.svn.sourceforge.net/cs-webapplibs/?rev=184&view=rev Author: crazedsanity Date: 2010-09-01 14:12:57 +0000 (Wed, 01 Sep 2010) Log Message: ----------- Throw exceptions when invalid data is encountered. /abstract/cs_singleTableHandler.abstract.class.php: * create_record(): -- throw an exception if there is no data. * get_single_record(): -- throw an exception if there's no data in the filter. * get_records(): -- throw an exception if there's a filter but no actual SQL appears to have been created (if the text is less than 3 characters). Modified Paths: -------------- trunk/0.3/abstract/cs_singleTableHandler.abstract.class.php Modified: trunk/0.3/abstract/cs_singleTableHandler.abstract.class.php =================================================================== --- trunk/0.3/abstract/cs_singleTableHandler.abstract.class.php 2010-09-01 14:09:53 UTC (rev 183) +++ trunk/0.3/abstract/cs_singleTableHandler.abstract.class.php 2010-09-01 14:12:57 UTC (rev 184) @@ -82,13 +82,18 @@ * @EXCEPTION FAIL: exception indicates the error. */ protected function create_record(array $data) { - $sql = 'INSERT INTO '. $this->tableName .' ' - . $this->gfObj->string_from_array($data, 'insert', null, $this->cleanStringArr, true); - try { - $newId = $this->dbObj->run_insert($sql, $this->seqName); + if(is_array($data) && count($data)) { + $sql = 'INSERT INTO '. $this->tableName .' ' + . $this->gfObj->string_from_array($data, 'insert', null, $this->cleanStringArr, true); + try { + $newId = $this->dbObj->run_insert($sql, $this->seqName); + } + catch(Exception $e) { + throw new exception(__METHOD__ .":: failed to create record, DETAILS::: ". $e->getMessage()); + } } - catch(Exception $e) { - throw new exception(__METHOD__ .":: failed to create record, DETAILS::: ". $e->getMessage()); + else { + throw new exception(__METHOD__ .":: no data passed"); } return($newId); }//end create_record() @@ -133,14 +138,19 @@ * @EXCEPTION FAIL: exception indicates error */ protected function get_single_record(array $filter) { - try { - $data = $this->get_records($filter, null, 1); - - $keys = array_keys($data); - $retval = $data[$keys[0]]; + if(is_array($filter) && count($filter)) { + try { + $data = $this->get_records($filter, null, 1); + + $keys = array_keys($data); + $retval = $data[$keys[0]]; + } + catch(Exception $e) { + throw new exception(__METHOD__ .":: failed to retrieve record, DETAILS::: ". $e->getMessage()); + } } - catch(Exception $e) { - throw new exception(__METHOD__ .":: failed to retrieve record, DETAILS::: ". $e->getMessage()); + else { + throw new exception(__METHOD__ .":: no filter passed"); } return($retval); @@ -179,7 +189,13 @@ $filterStr = ''; if(is_array($filter) && count($filter) > 0) { - $filterStr = ' WHERE '. $this->gfObj->string_from_array($filter, 'select', null, $this->cleanStringArr, true); + $filterSql = $this->gfObj->string_from_array($filter, 'select', null, $this->cleanStringArr, true); + if(strlen($filterSql) > 2) { + $filterStr = ' WHERE '. $filterSql; + } + else { + throw new exception(__METHOD__ .":: no filter created (". $this->gfObj->debug_print($filter,0) .")"); + } } $sql = 'SELECT * FROM '. $this->tableName . $filterStr . $orderByStr . $limitOffsetStr; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |