[Fusionforge-commits] r12777 - in trunk/src: common/include plugins/cvstracker/www plugins/forumml/www plugins/globalsearch/www plugins/mantisbt/common plugins/svntracker/www www/project/stats www/softwaremap www/trove

Roland Mas lolando at fusionforge.org
Tue Mar 15 16:00:57 CET 2011


Author: lolando
Date: 2011-03-15 16:00:57 +0100 (Tue, 15 Mar 2011)
New Revision: 12777

Modified:
   trunk/src/common/include/database-pgsql.php
   trunk/src/plugins/cvstracker/www/newcommit.php
   trunk/src/plugins/forumml/www/forumml_utils.php
   trunk/src/plugins/globalsearch/www/index.php
   trunk/src/plugins/mantisbt/common/MantisBTPlugin.class.php
   trunk/src/plugins/svntracker/www/newcommit.php
   trunk/src/www/project/stats/project_stats_utils.php
   trunk/src/www/softwaremap/trove_list.php
   trunk/src/www/trove/TroveCategory.class.php
Log:
Make db_error() work the same way as other db_*() functions when an explicit database is passed in, and ensure consistency in usage of that code

Modified: trunk/src/common/include/database-pgsql.php
===================================================================
--- trunk/src/common/include/database-pgsql.php	2011-03-15 14:06:42 UTC (rev 12776)
+++ trunk/src/common/include/database-pgsql.php	2011-03-15 15:00:57 UTC (rev 12777)
@@ -116,24 +116,31 @@
         }
 }
 
-function db_switcher(&$dbserver=NULL) {
+function db_switcher($dbserver=NULL) {
 	switch ($dbserver) {
 	case NULL:
 	case 'SYS_DB_PRIMARY':
-		$dbserver = SYS_DB_PRIMARY ;
+		$dbconn = SYS_DB_PRIMARY ;
 		break ;
 	case 'SYS_DB_STATS':
-		$dbserver = SYS_DB_STATS ;
+		$dbconn = SYS_DB_STATS ;
 		break ;
 	case 'SYS_DB_TROVE':
-		$dbserver = SYS_DB_TROVE ;
+		$dbconn = SYS_DB_TROVE ;
 		break ;
 	case 'SYS_DB_SEARCH':
-		$dbserver = SYS_DB_SEARCH ;
+		$dbconn = SYS_DB_SEARCH ;
 		break ;
 	default:
-		$dbserver = SYS_DB_PRIMARY ;
+		// Cope with $dbserver already being a connection
+		if (pg_dbname($dbserver)) {
+			$dbconn = $dbserver;
+		} else {
+			$dbconn = SYS_DB_PRIMARY ;
+		}
 	}
+	
+	return $dbconn;
 }	
 
 /**
@@ -149,7 +156,7 @@
  */
 function db_query($qstring,$limit='-1',$offset=0,$dbserver=NULL) {
 	db_connect_if_needed () ;
-	db_switcher ($dbserver) ;
+	$dbconn = db_switcher($dbserver) ;
 
 	global $QUERY_COUNT;
 	$QUERY_COUNT++;
@@ -164,12 +171,11 @@
 		$qstring=$qstring." LIMIT $limit OFFSET $offset";
 	}
 
-	$res = @pg_query($dbserver,$qstring);
+	$res = @pg_query($dbconn,$qstring);
 	if (!$res) {
-		error_log('SQL: '. preg_replace('/\n\t+/', ' ',$qstring));
-		error_log('SQL> '.db_error());
+		error_log('SQL: ' . preg_replace('/\n\t+/', ' ',$qstring));
+		error_log('SQL> ' . db_error($dbconn));
 	}
-	//echo "\n<br />|*| [$qstring]: ".db_error();
 	return $res;
 }
 
@@ -184,7 +190,7 @@
  */
 function db_query_from_file($file,$limit='-1',$offset=0,$dbserver=NULL) {
 	db_connect_if_needed () ;
-	db_switcher ($dbserver) ;
+	$dbconn = db_switcher($dbserver) ;
 
 	global $QUERY_COUNT;
 	$QUERY_COUNT++;
@@ -203,12 +209,11 @@
 		}
 		$qstring=$qstring." LIMIT $limit OFFSET $offset";
 	}
-	$res = @pg_query($dbserver,$qstring);
+	$res = @pg_query($dbconn,$qstring);
 	if (!$res) {
-		error_log('SQL: '. preg_replace('/\n\t+/', ' ',$qstring));
-		error_log('SQL> '.db_error());
+		error_log('SQL: ' . preg_replace('/\n\t+/', ' ',$qstring));
+		error_log('SQL> ' . db_error($dbconn));
 	}
-	//echo "\n<br />|*| [$qstring]: ".db_error();
 	return $res;
 }
 
@@ -224,7 +229,7 @@
  */
 function db_query_params($qstring,$params,$limit='-1',$offset=0,$dbserver=NULL) {
 	db_connect_if_needed () ;
-	db_switcher ($dbserver) ;
+	$dbconn = db_switcher($dbserver) ;
 
 	global $QUERY_COUNT;
 	$QUERY_COUNT++;
@@ -239,10 +244,10 @@
 		$qstring=$qstring." LIMIT $limit OFFSET $offset";
 	}
 
-	$res = @pg_query_params($dbserver,$qstring,$params);
+	$res = @pg_query_params($dbconn,$qstring,$params);
 	if (!$res) {
-		error_log('SQL: '. preg_replace('/\n\t+/', ' ',$qstring));
-		error_log('SQL> '. db_error($dbserver));
+		error_log('SQL: ' . preg_replace('/\n\t+/', ' ',$qstring));
+		error_log('SQL> ' . db_error($dbconn));
 	}
 	return $res;
 }
@@ -468,14 +473,11 @@
  *	@return int id of the primary key or 0 on failure.
  */
 function db_insertid($qhandle,$table_name,$pkey_field_name,$dbserver=NULL) {
-	$sql="SELECT max($pkey_field_name) AS id FROM $table_name";
-	//echo $sql;
+	$sql = "SELECT max($pkey_field_name) AS id FROM $table_name";
 	$res = db_query_params ($sql, array(), -1, 0, $dbserver);
 	if (db_numrows($res) >0) {
 		return db_result($res,0,'id');
 	} else {
-	//	echo "No Rows Matched";
-	//	echo db_error();
 		return 0;
 	}
 }
@@ -487,8 +489,9 @@
  *	@return text error message.
  */
 function db_error($dbserver=NULL) {
-	//return @pg_errormessage($dbserver); 
-	return pg_last_error($dbserver);
+	$dbconn = db_switcher($dbserver);
+
+	return pg_last_error($dbconn);
 }
 
 /**

Modified: trunk/src/plugins/cvstracker/www/newcommit.php
===================================================================
--- trunk/src/plugins/cvstracker/www/newcommit.php	2011-03-15 14:06:42 UTC (rev 12776)
+++ trunk/src/plugins/cvstracker/www/newcommit.php	2011-03-15 15:00:57 UTC (rev 12777)
@@ -124,7 +124,7 @@
 					  array ($Num));
 		$HolderID= db_insertid($DBRes,'plugin_cvstracker_data_artifact','id');
 		if (!$DBRes || !$HolderID) {
-			$return['Error']='Problems with Artifact $Num: '.db_error($DBRes);
+			$return['Error']='Problems with Artifact $Num: '.db_error();
 			db_rollback();
 		} else {
 			$DBRes = db_query_params ('INSERT INTO plugin_cvstracker_data_master (holder_id, cvs_date, log_text, file, prev_version, actual_version, author) VALUES ($1,$2,$3,$4,$5,$6,$7)',
@@ -174,7 +174,7 @@
 					  array ($Num));
 		$HolderID= db_insertid($DBRes,'plugin_cvstracker_data_artifact','id');
 		if (!$DBRes || !$HolderID) {
-			$return['Error']='Problems with Task $Num: '.db_error($DBRes);
+			$return['Error']='Problems with Task $Num: '.db_error();
 			db_rollback();
 		} else {
 			$DBRes = db_query_params ('INSERT INTO plugin_cvstracker_data_master (holder_id, cvs_date, log_text, file, prev_version, actual_version, author) VALUES ($1,$2,$3,$4,$5,$6,$7)',

Modified: trunk/src/plugins/forumml/www/forumml_utils.php
===================================================================
--- trunk/src/plugins/forumml/www/forumml_utils.php	2011-03-15 14:06:42 UTC (rev 12776)
+++ trunk/src/plugins/forumml/www/forumml_utils.php	2011-03-15 15:00:57 UTC (rev 12777)
@@ -126,7 +126,7 @@
 	// Total number of threads
 	$nbThreads = 0;
 $res = getForumMLDao()->countAllThreadsFromList($list_id);
-	if ($res && !db_error($res)) {
+	if ($res && !db_error()) {
 		$row = $res->getRow();
 		$nbThreads = $row['nb'];
 	}

Modified: trunk/src/plugins/globalsearch/www/index.php
===================================================================
--- trunk/src/plugins/globalsearch/www/index.php	2011-03-15 14:06:42 UTC (rev 12776)
+++ trunk/src/plugins/globalsearch/www/index.php	2011-03-15 15:00:57 UTC (rev 12777)
@@ -153,7 +153,7 @@
         $no_rows = 1;
         echo "<h2>".sprintf (_('No matches found for %1$s'),
 			     $gwords)."</h2>";
-        echo db_error();
+        echo db_error(SYS_DB_SEARCH);
 
 } else {
 

Modified: trunk/src/plugins/mantisbt/common/MantisBTPlugin.class.php
===================================================================
--- trunk/src/plugins/mantisbt/common/MantisBTPlugin.class.php	2011-03-15 14:06:42 UTC (rev 12776)
+++ trunk/src/plugins/mantisbt/common/MantisBTPlugin.class.php	2011-03-15 15:00:57 UTC (rev 12777)
@@ -316,7 +316,7 @@
 			db_rollback($dbConnection);
 		} else {
 			db_query_params('UPDATE mantis_user_table set email = $1 where username = $2',array($row['email'],$row['user_name']),'-1','0',$dbConnection);
-			echo db_error();
+			echo db_error($dbConnection);
 		}
 	}
 
@@ -392,7 +392,7 @@
 
 			if (!$result) {
 				$this->setError(_('Insert Failed') . db_error($dbConnection));
-				db_rollback();
+				db_rollback($dbConnection);
 				return false;
 			}
 		}

Modified: trunk/src/plugins/svntracker/www/newcommit.php
===================================================================
--- trunk/src/plugins/svntracker/www/newcommit.php	2011-03-15 14:06:42 UTC (rev 12776)
+++ trunk/src/plugins/svntracker/www/newcommit.php	2011-03-15 15:00:57 UTC (rev 12777)
@@ -139,7 +139,7 @@
 					  array ($Num));
 		$HolderID= db_insertid($DBRes,'plugin_svntracker_data_artifact','id');
 		if (!$DBRes || !$HolderID) {
-			$return['Error']='Problems with Artifact $Num: '.db_error($DBRes);
+			$return['Error']='Problems with Artifact $Num: '.db_error();
 			db_rollback();
 		} else {
 			$DBRes = db_query_params ('INSERT INTO plugin_svntracker_data_master (holder_id, svn_date, log_text, file, prev_version, actual_version, author) VALUES ($1, $2, $3, $4, $5, $6, $7)',
@@ -151,7 +151,7 @@
 							 $Config['ActualVersion'],
 							 $Config['UserName'])) ;
 			if(!$DBRes) {
-				$return['Error']="Problems with Artifact $Num: ".db_error($DBRes)."\n";
+				$return['Error']="Problems with Artifact $Num: ".db_error()."\n";
 				db_rollback();
 			} else {
 				db_commit();
@@ -195,7 +195,7 @@
 			array ($Num));
 		$HolderID= db_insertid($DBRes,'plugin_svntracker_data_artifact','id');
 		if (!$DBRes || !$HolderID) {
-			$return['Error']='Problems with Task $Num: '.db_error($DBRes);
+			$return['Error']='Problems with Task $Num: '.db_error();
 			db_rollback();
 		} else {
 			$DBRes = db_query_params ('INSERT INTO plugin_svntracker_data_master 

Modified: trunk/src/www/project/stats/project_stats_utils.php
===================================================================
--- trunk/src/www/project/stats/project_stats_utils.php	2011-03-15 14:06:42 UTC (rev 12776)
+++ trunk/src/www/project/stats/project_stats_utils.php	2011-03-15 15:00:57 UTC (rev 12777)
@@ -63,7 +63,7 @@
 		$res = db_query_params($sql, array($group_id),  7, 0, SYS_DB_STATS);
 	}
 
-	echo db_error();
+	echo db_error(SYS_DB_STATS);
 
    // if there are any days, we have valid data.
 	if ( ($valid_days = db_numrows( $res )) > 0 ) {
@@ -109,7 +109,7 @@
 
 	} else {
 		echo _('Project did not exist on this date.');
-		echo db_error() .'</p>';
+		echo db_error(SYS_DB_STATS) .'</p>';
 	}
 
 }
@@ -168,7 +168,7 @@
 
 	} else {
 		echo _('Project did not exist on this date.')."<p>";
-		echo db_error();
+		echo db_error(SYS_DB_STATS);
 	}
 }
 
@@ -180,7 +180,6 @@
 		WHERE group_id=$1
 	", array($group_id), -1, 0, SYS_DB_STATS);
 	$row = db_fetch_array($res);
-//	echo db_error();
 
 	?>
 	<p><strong><?php echo _('Statistics for All Time') ?></strong></p>

Modified: trunk/src/www/softwaremap/trove_list.php
===================================================================
--- trunk/src/www/softwaremap/trove_list.php	2011-03-15 14:06:42 UTC (rev 12776)
+++ trunk/src/www/softwaremap/trove_list.php	2011-03-15 15:00:57 UTC (rev 12777)
@@ -237,7 +237,7 @@
 	$qpa = db_construct_qpa($qpa, ' ORDER BY trove_agg.trove_cat_id ASC, trove_agg.ranking ASC');
 	$res_grp = db_query_qpa($qpa, $TROVE_HARDQUERYLIMIT, 0, SYS_DB_TROVE);
 
-	echo db_error();
+	echo db_error(SYS_DB_TROVE);
 	$querytotalcount = db_numrows($res_grp);
 
 	// #################################################################

Modified: trunk/src/www/trove/TroveCategory.class.php
===================================================================
--- trunk/src/www/trove/TroveCategory.class.php	2011-03-15 14:06:42 UTC (rev 12776)
+++ trunk/src/www/trove/TroveCategory.class.php	2011-03-15 15:00:57 UTC (rev 12777)
@@ -62,7 +62,7 @@
 			if (!$dataArray || !is_array($dataArray)) {
 				if (!$this->fetchData($categoryId)) {
 					$this->setError(_('Invalid Trove Category'),
-							_('That Trove category does not exist.').' '.db_error()
+							_('That Trove category does not exist.').' '.db_error(SYS_DB_TROVE)
 					);
 				}
 			} else {




More information about the Fusionforge-commits mailing list