[Fusionforge-commits] r8505 - trunk/gforge/db

Roland Mas lolando at libremir.placard.fr.eu.org
Thu Dec 10 14:17:38 CET 2009


Author: lolando
Date: 2009-12-10 14:17:38 +0100 (Thu, 10 Dec 2009)
New Revision: 8505

Modified:
   trunk/gforge/db/20010304-4-artifact-convert-files.php
   trunk/gforge/db/20021213-2-doc_data-migrate.php
   trunk/gforge/db/20040826_migrateforum.php
   trunk/gforge/db/20040826_migraterbac.php
   trunk/gforge/db/20041211-syncmail.php
   trunk/gforge/db/20041222-1-delete-task-artifact.php
   trunk/gforge/db/20050617.php
   trunk/gforge/db/20050804-2.php
   trunk/gforge/db/20090507-install_workflow.php
   trunk/gforge/db/upgrade-db.php
Log:
db_query_params for db upgrade scripts

Modified: trunk/gforge/db/20010304-4-artifact-convert-files.php
===================================================================
--- trunk/gforge/db/20010304-4-artifact-convert-files.php	2009-12-10 13:17:23 UTC (rev 8504)
+++ trunk/gforge/db/20010304-4-artifact-convert-files.php	2009-12-10 13:17:38 UTC (rev 8505)
@@ -1,22 +1,22 @@
 #! /usr/bin/php5
 <?php
 
-require_once dirname(__FILE__).'/../www/env.inc.php';
+require_once (dirname(__FILE__)).'/../www/env.inc.php';
 require $gfwww.'include/squal_pre.php';
 
 db_begin();
-
-$rel = db_query("SELECT id,bin_data FROM artifact_file ORDER BY id ASC;");
+			      
+$rel = db_query_params ('SELECT id,bin_data FROM artifact_file ORDER BY id ASC',
+						      array ());
 echo db_error();
 
 $rows=db_numrows($rel);
 
 for ($i=0; $i<$rows; $i++) {
+	$res = db_query_params ('UPDATE artifact_file SET bin_data=$1 WHERE id=$2',
+				array (base64_encode(util_unconvert_htmlspecialchars(db_result($rel,$i,'bin_data'))),
+				       db_result($rel,$i,'id'))) ;
 
-	$res=db_query("UPDATE artifact_file 
-		SET bin_data='". base64_encode( util_unconvert_htmlspecialchars( db_result($rel,$i,'bin_data') ) ) ."' 
-		WHERE id='". db_result($rel,$i,'id') ."'");
-
 	echo db_error();
 	echo "<br />Num: $i | id: ".db_result($rel,$i,'id');
 
@@ -32,4 +32,9 @@
 			array()) ;
 
 
+// Local Variables:
+// mode: php
+// c-file-style: "bsd"
+// End:
+
 ?>

Modified: trunk/gforge/db/20021213-2-doc_data-migrate.php
===================================================================
--- trunk/gforge/db/20021213-2-doc_data-migrate.php	2009-12-10 13:17:23 UTC (rev 8504)
+++ trunk/gforge/db/20021213-2-doc_data-migrate.php	2009-12-10 13:17:38 UTC (rev 8505)
@@ -28,13 +28,11 @@
 $rows=db_numrows($res);
 
 for ($i=0; $i<$rows; $i++) {
-
-	$res2=db_query("UPDATE doc_data 
-		SET 
-		data='". base64_encode( util_unconvert_htmlspecialchars( db_result($res,$i,'data') )) ."',
-		filename='file".db_result($res,$i,'docid').".html',
-		filetype='text/html'
-		WHERE docid='".db_result($res,$i,'docid')."'");
+	$res2 = db_query_params ('UPDATE doc_data SET data=$1,filename=$2,filetype=$3 WHERE docid=$4',
+				 array (base64_encode( util_unconvert_htmlspecialchars( db_result($res,$i,'data'))),
+					'file'.db_result($res,$i,'docid').'.html',
+					'text/html',
+					db_result($res,$i,'docid'))) ;
 	if (!$res2 || db_affected_rows($res2) < 1) {
 		echo 'DB ERROR'.db_error();
 		db_rollback();
@@ -44,4 +42,10 @@
 
 db_commit();
 echo "SUCCESS\n";
+
+// Local Variables:
+// mode: php
+// c-file-style: "bsd"
+// End:
+
 ?>

Modified: trunk/gforge/db/20040826_migrateforum.php
===================================================================
--- trunk/gforge/db/20040826_migrateforum.php	2009-12-10 13:17:23 UTC (rev 8504)
+++ trunk/gforge/db/20040826_migrateforum.php	2009-12-10 13:17:38 UTC (rev 8505)
@@ -41,10 +41,9 @@
 
 for ($i=0; $i<db_numrows($res); $i++) {
 
-	$sql="UPDATE forum_group_list 
-		SET forum_name='". ereg_replace('[^_\.0-9a-z-]','-', strtolower(db_result($res,$i,'forum_name')) )."' 
-		WHERE group_forum_id='".db_result($res,$i,'group_forum_id')."'";
-	$res2=db_query($sql);
+	$res2 = db_query_params ('UPDATE forum_group_list SET forum_name=$1 WHERE group_forum_id=$2',
+				 array (ereg_replace('[^_\.0-9a-z-]','-', strtolower(db_result($res,$i,'forum_name'))),
+					db_result($res,$i,'group_forum_id'))) ;
 	if (!$res2) {
 		echo db_error();
 		db_rollback();
@@ -70,4 +69,10 @@
 
 db_commit();
 echo "SUCCESS\n";
+
+// Local Variables:
+// mode: php
+// c-file-style: "bsd"
+// End:
+
 ?>

Modified: trunk/gforge/db/20040826_migraterbac.php
===================================================================
--- trunk/gforge/db/20040826_migraterbac.php	2009-12-10 13:17:23 UTC (rev 8504)
+++ trunk/gforge/db/20040826_migraterbac.php	2009-12-10 13:17:38 UTC (rev 8505)
@@ -100,12 +100,17 @@
 		}
 	}
 
-	$roleid=db_query("SELECT role_id FROM role WHERE group_id='".$arr[$i]."' AND role_name='Admin'");
+	$roleid = db_query_params ('SELECT role_id FROM role WHERE group_id=$1  AND role_name=$2',
+				   array ($arr[$i],
+					  'Admin'));
 	$admin_roleid=db_result($roleid,0,0);
-	$roleid=db_query("SELECT role_id FROM role WHERE group_id='".$arr[$i]."' AND role_name='Junior Developer'");
+	$roleid = db_query_params ('SELECT role_id FROM role WHERE group_id=$1 AND role_name=$2',
+				   array ($arr[$i],
+					  'Junior Developer')) ;
 	$junior_roleid=db_result($roleid,0,0);
 
-	$rrole=db_query("SELECT user_id,admin_flags FROM user_group WHERE group_id='".$arr[$i]."'");
+	$rrole = db_query_params ('SELECT user_id,admin_flags FROM user_group WHERE group_id=$1',
+				  array ($arr[$i])) ;
 	while ($arrole = db_fetch_array($rrole)) {
 
 		$role_id= (( trim($arrole['admin_flags']) == 'A' ) ? $admin_roleid : $junior_roleid );
@@ -131,4 +136,10 @@
 db_commit();
 echo "SUCCESS\n";
 exit(0);
+
+// Local Variables:
+// mode: php
+// c-file-style: "bsd"
+// End:
+
 ?>

Modified: trunk/gforge/db/20041211-syncmail.php
===================================================================
--- trunk/gforge/db/20041211-syncmail.php	2009-12-10 13:17:23 UTC (rev 8504)
+++ trunk/gforge/db/20041211-syncmail.php	2009-12-10 13:17:38 UTC (rev 8505)
@@ -43,9 +43,9 @@
 		$group_id   = db_result($res,$i,'group_id');
 		$group_name = db_result($res,$i,'unix_group_name');
 	
-		$res2 = db_query("SELECT * FROM mail_group_list 
-			WHERE group_id = '".$group_id."' 
-			AND list_name = '".$group_name."-commits'");
+		$res2 = db_query_params ('SELECT * FROM mail_group_list WHERE group_id = $1 AND list_name = $2',
+					 array ($group_id,
+						$group_name."-commits'")) ;
 	
 		if (db_numrows($res2) < 1) {
 			$group = new Group($group_id);
@@ -57,9 +57,9 @@
 				echo "Could Not Get Group Object for $group_name: ".$group->getErrorMessage();
 			} else {
 	
-				$res_aux2 = db_query("SELECT user_id FROM user_group 
-					WHERE admin_flags = 'A' 
-					AND group_id = '".$group_id."'");
+				$res_aux2 = db_query_params ('SELECT user_id FROM user_group WHERE admin_flags = $1 AND group_id = $2',
+							     array ('A',
+								    $group_id)) ;
 	
 				$group_admin = db_result($res_aux2,0,'user_id');
 	
@@ -93,4 +93,10 @@
 		echo "SUCCESS\n";
 	}
 }
+
+// Local Variables:
+// mode: php
+// c-file-style: "bsd"
+// End:
+
 ?>

Modified: trunk/gforge/db/20041222-1-delete-task-artifact.php
===================================================================
--- trunk/gforge/db/20041222-1-delete-task-artifact.php	2009-12-10 13:17:23 UTC (rev 8504)
+++ trunk/gforge/db/20041222-1-delete-task-artifact.php	2009-12-10 13:17:38 UTC (rev 8505)
@@ -22,43 +22,50 @@
 	}
 	
 	foreach ($tasks as $task_id) {
-		$res = db_query("DELETE FROM project_assigned_to WHERE project_task_id='".$task_id."'");
+		$res = db_query_params ('DELETE FROM project_assigned_to WHERE project_task_id=$1',
+					array ($task_id));
 		if (!$res) {
 			echo 'Error deleting assigned users relationship: '.db_error();
 			db_rollback();
 			exit();
 		}
-		$res = db_query("DELETE FROM project_dependencies WHERE project_task_id='".$task_id."'");
+		$res = db_query_params ('DELETE FROM project_dependencies WHERE project_task_id=$1',
+					array ($task_id)) ;
 		if (!$res) {
 			echo 'Error deleting dependencies: '.db_error();
 			db_rollback();
 			exit();
 		}
-		$res = db_query("DELETE FROM project_history WHERE project_task_id='".$task_id."'");
+		$res = db_query_params ('DELETE FROM project_history WHERE project_task_id=$1',
+					array ($task_id)) ;
 		if (!$res) {
 			echo 'Error deleting history: '.db_error();
 			db_rollback();
 			exit();
 		}
-		$res = db_query("DELETE FROM project_messages WHERE project_task_id='".$task_id."'");
+		$res = db_query_params ('DELETE FROM project_messages WHERE project_task_id=$1',
+					array ($task_id)) ;
 		if (!$res) {
 			echo 'Error deleting messages: '.db_error();
 			db_rollback();
 			eixt();
 		}
-		$res = db_query("DELETE FROM project_task_artifact	WHERE project_task_id='".$task_id."'");
+		$res = db_query_params ('DELETE FROM project_task_artifact WHERE project_task_id=$1',
+					array ($task_id)) ;
 		if (!$res) {
 			echo 'Error deleting artifacts: '.db_error();
 			db_rollback();
 			exit();
 		}
-		$res = db_query("DELETE FROM rep_time_tracking	WHERE project_task_id='".$task_id."'");
+		$res = db_query_params ('DELETE FROM rep_time_tracking WHERE project_task_id=$1',
+					array ($task_id)) ;
 		if (!$res) {
 			echo 'Error deleting time tracking report: '.db_error();
 			db_rollback();
 			exit();
 		}
-		$res = db_query("DELETE FROM project_task WHERE project_task_id='".$task_id."'");
+		$res = db_query_params ('DELETE FROM project_task WHERE project_task_id=$1',
+					array ($task_id)) ;
 		if (!$res) {
 			echo 'Error deleting task: '.db_error();
 			db_rollback();
@@ -83,37 +90,43 @@
 	}
 	
 	foreach ($artifacts as $artifact_id) {
-		$res = db_query("DELETE FROM artifact_extra_field_data WHERE artifact_id='".$artifact_id."'");
+		$res = db_query_params ('DELETE FROM artifact_extra_field_data WHERE artifact_id=$1',
+					array ($artifact_id)) ;
 		if (!$res) {
 			echo 'Error deleting extra field data: '.db_error();
 			db_rollback();
 			exit();
 		}
-		$res = db_query("DELETE FROM artifact_file WHERE artifact_id='".$artifact_id."'");
+		$res = db_query_params ('DELETE FROM artifact_file WHERE artifact_id=$1',
+					array ($artifact_id)) ;
 		if (!$res) {
 			echo 'Error deleting file from db: '.db_error();
 			db_rollback();
 			exit();
 		}
-		$res = db_query("DELETE FROM artifact_message WHERE artifact_id='".$artifact_id."'");
+		$res = db_query_params ('DELETE FROM artifact_message WHERE artifact_id=$1',
+					array ($artifact_id)) ;
 		if (!$res) {
 			echo 'Error deleting message: '.db_error();
 			db_rollback();
 			exit();
 		}
-		$res = db_query("DELETE FROM artifact_history WHERE artifact_id='".$artifact_id."'");
+		$res = db_query_params ('DELETE FROM artifact_history WHERE artifact_id=$1',
+					array ($artifact_id)) ;
 		if (!$res) {
 			echo 'Error deleting history: '.db_error();
 			db_rollback();
 			exit();
 		}
-		$res = db_query("DELETE FROM artifact_monitor WHERE artifact_id='".$artifact_id."'");
+		$res = db_query_params ('DELETE FROM artifact_monitor WHERE artifact_id=$1',
+					array ($artifact_id)) ;
 		if (!$res) {
 			echo 'Error deleting monitor: '.db_error();
 			db_rollback();
 			exit();
 		}
-		$res = db_query("DELETE FROM artifact WHERE artifact_id='".$artifact_id."'");
+		$res = db_query_params ('DELETE FROM artifact WHERE artifact_id=$1',
+					array ($artifact_id)) ;
 		if (!$res) {
 			echo 'Error deleting artifact: '.db_error();
 			db_rollback();
@@ -123,4 +136,10 @@
 }
 echo "SUCCESS\n";
 db_commit();
+
+// Local Variables:
+// mode: php
+// c-file-style: "bsd"
+// End:
+
 ?>

Modified: trunk/gforge/db/20050617.php
===================================================================
--- trunk/gforge/db/20050617.php	2009-12-10 13:17:23 UTC (rev 8504)
+++ trunk/gforge/db/20050617.php	2009-12-10 13:17:38 UTC (rev 8505)
@@ -92,10 +92,10 @@
 	$conflict = false;
 	$count = 1;
 	do {
-		$previous_def = db_query("SELECT * FROM artifact_extra_field_list " .
-								"WHERE group_artifact_id=".$row["group_artifact_id"]." AND ".
-								"LOWER(alias)='".$alias."' AND ".
-								"extra_field_id <> ".$row["extra_field_id"]);
+		$previous_def = db_query_params ('SELECT * FROM artifact_extra_field_list WHERE group_artifact_id=$1 AND LOWER(alias)=$2 AND extra_field_id <> $3',
+						 array ($row["group_artifact_id"],
+							$alias,
+							$row["extra_field_id"])) ;
 		if (db_numrows($previous_def) > 0) {	// alias exists...
 			$conflict = true;
 			$alias = $alias.$count;		// do something like "alias1"
@@ -106,14 +106,22 @@
 	} while ($conflict);
 
 	// at this point we can safely insert the alias
-	$update = db_query("UPDATE artifact_extra_field_list SET alias='".$alias."' WHERE extra_field_id=".$row["extra_field_id"]);
+	$update = db_query_params ('UPDATE artifact_extra_field_list SET alias=$1 WHERE extra_field_id=$2',
+				   array ($alias,
+					  $row["extra_field_id"])) ;
 	if (!$update) {
 		echo db_error();
 		exit(3);
 	}	
 }
-db_query("COMMIT WORK");
+db_commit ();
 
 echo "SUCCESS\n";
 exit(0);
+
+// Local Variables:
+// mode: php
+// c-file-style: "bsd"
+// End:
+
 ?>

Modified: trunk/gforge/db/20050804-2.php
===================================================================
--- trunk/gforge/db/20050804-2.php	2009-12-10 13:17:23 UTC (rev 8504)
+++ trunk/gforge/db/20050804-2.php	2009-12-10 13:17:38 UTC (rev 8505)
@@ -41,7 +41,9 @@
 	$data = base64_decode($base64_data);
 	$size = strlen($data);
 	
-	$res2 = db_query("UPDATE doc_data SET filesize='".$size."' WHERE docid='".$docid."'");
+	$res2 = db_query_params ('UPDATE doc_data SET filesize=$1 WHERE docid=$2',
+				 array ($size,
+					$docid)) ;
 	if (!$res2) {
 		echo "Couldn't update document #".$docid.":".db_error()."\n";
 		db_rollback();
@@ -50,4 +52,10 @@
 }
 echo "SUCCESS\n";
 db_commit();
+
+// Local Variables:
+// mode: php
+// c-file-style: "bsd"
+// End:
+
 ?>

Modified: trunk/gforge/db/20090507-install_workflow.php
===================================================================
--- trunk/gforge/db/20090507-install_workflow.php	2009-12-10 13:17:23 UTC (rev 8504)
+++ trunk/gforge/db/20090507-install_workflow.php	2009-12-10 13:17:38 UTC (rev 8505)
@@ -21,14 +21,13 @@
 $admin_id = db_result($res,0,'user_id');
 session_set_new($admin_id);
 
-$sql = "SELECT group_id, artifact_group_list.group_artifact_id, element_id, artifact_extra_field_elements.extra_field_id
+			      $res = db_query_params ('SELECT group_id, artifact_group_list.group_artifact_id, element_id, artifact_extra_field_elements.extra_field_id
 		FROM artifact_extra_field_list, artifact_extra_field_elements, artifact_group_list
 		WHERE 
 			artifact_extra_field_list.extra_field_id=artifact_extra_field_elements.extra_field_id
 		AND 	artifact_group_list.group_artifact_id = artifact_extra_field_list.group_artifact_id
-		AND	field_type=7";
-
-$res = db_query($sql);
+		AND	field_type=7',
+						      array ()) ;
 while($row = db_fetch_array($res)) {
 	print "Upgrading group_id=".$row['group_id']." (group_artifact_id=".$row['group_artifact_id'].")\n";
 	$group =& group_get_object($row['group_id']);
@@ -43,4 +42,10 @@
 }
 
 echo "SUCCESS";
+
+// Local Variables:
+// mode: php
+// c-file-style: "bsd"
+// End:
+
 ?>

Modified: trunk/gforge/db/upgrade-db.php
===================================================================
--- trunk/gforge/db/upgrade-db.php	2009-12-10 13:17:23 UTC (rev 8504)
+++ trunk/gforge/db/upgrade-db.php	2009-12-10 13:17:38 UTC (rev 8505)
@@ -76,7 +76,8 @@
 
 foreach ($scripts as $script) {
 	if ((int) $script['date'] > $date) {
-		$res = db_query("SELECT * FROM database_changes WHERE filename='{$script['filename']}'");
+		$res = db_query_params ('SELECT * FROM database_changes WHERE filename=$1',
+					array ("{$script['filename']}")) ;
 		if (!$res) {
 			// error
 			show("ERROR-2: ".db_error()."\n");
@@ -85,7 +86,8 @@
 			show("Running script: {$script['filename']}\n");
 			$result = run_script($script);
 			if ($result) {
-				$res = db_query("INSERT INTO database_changes (filename) VALUES ('{$script['filename']}')");
+				$res = db_query_params ('INSERT INTO database_changes (filename) VALUES ($1)',
+							array ("{$script['filename']}")) ;
 				if (!$res)
 				{
 					show("ERROR-3: ".db_error()."\n");
@@ -489,4 +491,9 @@
 	fwrite(STDOUT, $text);
 }
 
+// Local Variables:
+// mode: php
+// c-file-style: "bsd"
+// End:
+
 ?>
\ No newline at end of file




More information about the Fusionforge-commits mailing list