[Vtigercrm-developers] adodb exceptions

Adam Heinz amh at metricwise.net
Thu Feb 9 06:56:40 PST 2012


I don't run with exceptions turned on in production (yet), but often
when I'm debugging, I'll enable adodb exceptions in PearDatabase.php.
(First patch below)  This has the advantage of turning

PHP Fatal error:  Uncaught exception 'Exception' with message 'result
is not an object' in
var/www/html/include/database/PearDatabase.php:789 (query_result
function)

into an exception that can be handled.  This has been really helpful
in finding SQL syntax errors.  I do enable exceptions when I am
applying database updates, as I want them to complain loudly if they
fail.  As a result, I find myself having to code around situations
where the code was originally written with the assumption that it is
okay to fail silently.  (Second patch below)

Anyway, just thought other people might be interested into this
technique.  I have been using ADOdb for the last five years, so I have
a strong bias towards using it directly, rather than the PearDatabase
class that wraps it.

Index: include/database/PearDatabase.php
===================================================================
--- include/database/PearDatabase.php	(revision 2291)
+++ /include/database/PearDatabase.php	(working copy)
@@ -15,6 +15,7 @@

 require_once('include/logging.php');
 include('adodb/adodb.inc.php');
+require_once('adodb/adodb-exceptions.inc.php');
 require_once("adodb/adodb-xmlschema.inc.php");

 $log =& LoggerManager::getLogger('VT');

Index: vtlib/Vtiger/Field.php
===================================================================
--- vtlib/Vtiger/Field.php	(revision 2291)
+++ vtlib/Vtiger/Field.php	(working copy)
@@ -118,16 +118,17 @@
 	 * @internal Creates table vtiger_fieldmodulerel if it does not exists
 	 */
 	function setRelatedModules($moduleNames) {
-
-		// We need to create core table to capture the relation between the
field and modules.
-		Vtiger_Utils::CreateTable(
-			'vtiger_fieldmodulerel',
-			'(fieldid INT NOT NULL, module VARCHAR(100) NOT NULL, relmodule
VARCHAR(100) NOT NULL, status VARCHAR(10), sequence INT)',
-			true
-		);
-		// END
-
 		global $adb;
+		
+		if (!$adb->database->GetRow("SHOW TABLES LIKE 'vtiger_fieldmodulerel'")) {
+			// We need to create core table to capture the relation between
the field and modules.
+			Vtiger_Utils::CreateTable(
+				'vtiger_fieldmodulerel',
+				'(fieldid INT NOT NULL, module VARCHAR(100) NOT NULL, relmodule
VARCHAR(100) NOT NULL, status VARCHAR(10), sequence INT)',
+				true
+			);
+		}
+
 		foreach($moduleNames as $relmodule) {
 			$checkres = $adb->pquery('SELECT * FROM vtiger_fieldmodulerel
WHERE fieldid=? AND module=? AND relmodule=?',
 				Array($this->id, $this->getModuleName(), $relmodule));



More information about the vtigercrm-developers mailing list