[Fusionforge-commits] r7872 - trunk/gforge/www/snippet

Roland Mas lolando at libremir.placard.fr.eu.org
Fri Jun 19 11:57:06 CEST 2009


Author: lolando
Date: 2009-06-19 11:57:06 +0200 (Fri, 19 Jun 2009)
New Revision: 7872

Modified:
   trunk/gforge/www/snippet/add_snippet_to_package.php
   trunk/gforge/www/snippet/addversion.php
   trunk/gforge/www/snippet/delete.php
   trunk/gforge/www/snippet/detail.php
   trunk/gforge/www/snippet/snippet_utils.php
Log:
Semi-automated db_query_params() transition for simple cases

Modified: trunk/gforge/www/snippet/add_snippet_to_package.php
===================================================================
--- trunk/gforge/www/snippet/add_snippet_to_package.php	2009-06-19 09:56:57 UTC (rev 7871)
+++ trunk/gforge/www/snippet/add_snippet_to_package.php	2009-06-19 09:57:06 UTC (rev 7872)
@@ -64,7 +64,8 @@
 			/*
 				make sure the snippet_version_id exists
 			*/
-			$result=db_query("SELECT * FROM snippet_version WHERE snippet_version_id='$snippet_version_id'");
+			$result=db_query_params ('SELECT * FROM snippet_version WHERE snippet_version_id=$1',
+			array($snippet_version_id));
 			if (!$result || db_numrows($result) < 1) {
 				echo '<h1>' ._('Error - That snippet doesn\'t exist.').'</h1>';
 				echo util_make_link ('/snippet/add_snippet_to_package.php?snippet_package_version_id='.$snippet_package_version_id,_('Back To Add Page'));
@@ -74,9 +75,11 @@
 			/*
 				make sure the snippet_version_id isn't already in this package
 			*/
-			$result=db_query("SELECT * FROM snippet_package_item ".
-				"WHERE snippet_package_version_id='$snippet_package_version_id' ".
-				"AND snippet_version_id='$snippet_version_id'");
+			$result=db_query_params ('SELECT * FROM snippet_package_item 
+WHERE snippet_package_version_id=$1 
+AND snippet_version_id=$2',
+			array($snippet_package_version_id,
+				$snippet_version_id));
 			if ($result && db_numrows($result) > 0) {
 				echo '<h1>'._('Error - That snippet was already added to this package.').'</h1>';
 				echo util_make_url ('/snippet/add_snippet_to_package.php?snippet_package_version_id='.$snippet_package_version_id,_('Back To Add Page'));
@@ -86,8 +89,8 @@
 			/*
 				create the snippet version
 			*/
-			$sql="INSERT INTO snippet_package_item (snippet_package_version_id,snippet_version_id) ".
-				"VALUES ('$snippet_package_version_id','$snippet_version_id')";
+			$sql="INSERT INTO snippet_package_item (snippet_package_version_id,snippet_version_id) 
+VALUES ('$snippet_package_version_id','$snippet_version_id')";
 			$result=db_query($sql);
 
 			if (!$result) {
@@ -104,10 +107,11 @@
 
 	}
 
-	$result=db_query("SELECT snippet_package.name,snippet_package_version.version ".
-			"FROM snippet_package,snippet_package_version ".
-			"WHERE snippet_package.snippet_package_id=snippet_package_version.snippet_package_id ".
-			"AND snippet_package_version.snippet_package_version_id='$snippet_package_version_id'");
+	$result=db_query_params ('SELECT snippet_package.name,snippet_package_version.version 
+FROM snippet_package,snippet_package_version 
+WHERE snippet_package.snippet_package_id=snippet_package_version.snippet_package_id 
+AND snippet_package_version.snippet_package_version_id=$1',
+			array($snippet_package_version_id));
 
 	?>
 	<p>
@@ -157,11 +161,12 @@
 	/*
 		Show the snippets in this package
 	*/
-	$result=db_query("SELECT snippet_package_item.snippet_version_id, snippet_version.version, snippet.name ".
-		"FROM snippet,snippet_version,snippet_package_item ".
-		"WHERE snippet.snippet_id=snippet_version.snippet_id ".
-		"AND snippet_version.snippet_version_id=snippet_package_item.snippet_version_id ".
-		"AND snippet_package_item.snippet_package_version_id='$snippet_package_version_id'");
+	$result=db_query_params ('SELECT snippet_package_item.snippet_version_id, snippet_version.version, snippet.name 
+FROM snippet,snippet_version,snippet_package_item 
+WHERE snippet.snippet_id=snippet_version.snippet_id 
+AND snippet_version.snippet_version_id=snippet_package_item.snippet_version_id 
+AND snippet_package_item.snippet_package_version_id=$1',
+			array($snippet_package_version_id));
 	$rows=db_numrows($result);
 	if (!$result || $rows < 1) {
 		echo db_error();

Modified: trunk/gforge/www/snippet/addversion.php
===================================================================
--- trunk/gforge/www/snippet/addversion.php	2009-06-19 09:56:57 UTC (rev 7871)
+++ trunk/gforge/www/snippet/addversion.php	2009-06-19 09:57:06 UTC (rev 7872)
@@ -22,7 +22,8 @@
 		/*
 			See if the snippet exists first
 		*/
-		$result=db_query("SELECT * FROM snippet WHERE snippet_id='$id'");
+		$result=db_query_params ('SELECT * FROM snippet WHERE snippet_id=$1',
+			array($id));
 		if (!$result || db_numrows($result) < 1) {
 			exit_error(_('Error - snippet doesn\'t exist'));
 		}
@@ -108,7 +109,8 @@
 		/*
 			See if the package exists first
 		*/
-		$result=db_query("SELECT * FROM snippet_package WHERE snippet_package_id='$id'");
+		$result=db_query_params ('SELECT * FROM snippet_package WHERE snippet_package_id=$1',
+			array($id));
 		if (!$result || db_numrows($result) < 1) {
 			exit_error(_('Error - snippet_package doesn\'t exist'));
 		}

Modified: trunk/gforge/www/snippet/delete.php
===================================================================
--- trunk/gforge/www/snippet/delete.php	2009-06-19 09:56:57 UTC (rev 7871)
+++ trunk/gforge/www/snippet/delete.php	2009-06-19 09:57:06 UTC (rev 7872)
@@ -41,9 +41,11 @@
 		} else {
 
 			//Remove the item from the package
-			$result=db_query("DELETE FROM snippet_package_item ".
-				"WHERE snippet_version_id='$snippet_version_id' ".
-				"AND snippet_package_version_id='$snippet_package_version_id'");
+			$result=db_query_params ('DELETE FROM snippet_package_item 
+WHERE snippet_version_id=$1 
+AND snippet_package_version_id=$2',
+			array($snippet_version_id,
+				$snippet_package_version_id));
 			if (!$result || db_affected_rows($result) < 1) {
 				echo '<h1>Error - That snippet doesn\'t exist in this package.</h1>';
 				snippet_footer(array());

Modified: trunk/gforge/www/snippet/detail.php
===================================================================
--- trunk/gforge/www/snippet/detail.php	2009-06-19 09:56:57 UTC (rev 7871)
+++ trunk/gforge/www/snippet/detail.php	2009-06-19 09:57:06 UTC (rev 7872)
@@ -35,10 +35,10 @@
 	/*
 		Get all the versions of this snippet
 	*/
-	$sql="SELECT users.realname,users.user_name,users.user_id,snippet_version.snippet_version_id,snippet_version.version,snippet_version.post_date,snippet_version.changes ".
-		"FROM snippet_version,users ".
-		"WHERE users.user_id=snippet_version.submitted_by AND snippet_id='$id' ".
-		"ORDER BY snippet_version.snippet_version_id DESC";
+	$sql="SELECT users.realname,users.user_name,users.user_id,snippet_version.snippet_version_id,snippet_version.version,snippet_version.post_date,snippet_version.changes 
+FROM snippet_version,users 
+WHERE users.user_id=snippet_version.submitted_by AND snippet_id='$id' 
+ORDER BY snippet_version.snippet_version_id DESC";
 
 	$result=db_query($sql);
 	$rows=db_numrows($result);
@@ -87,7 +87,8 @@
 	/*
 		show the latest version of this snippet's code
 	*/
-	$result=db_query("SELECT code,version FROM snippet_version WHERE snippet_version_id='$newest_version'");	
+	$result=db_query_params ('SELECT code,version FROM snippet_version WHERE snippet_version_id=$1',
+			array($newest_version));	
 
 	echo '
 		<p>&nbsp;</p>
@@ -123,11 +124,11 @@
 	/*
 		Get all the versions of this package
 	*/
-	$sql="SELECT users.realname,users.user_name,users.user_id,snippet_package_version.snippet_package_version_id,".
-		"snippet_package_version.version,snippet_package_version.post_date ".
-		"FROM snippet_package_version,users ".
-		"WHERE users.user_id=snippet_package_version.submitted_by AND snippet_package_id='$id' ".
-		"ORDER BY snippet_package_version.snippet_package_version_id DESC";
+	$sql="SELECT users.realname,users.user_name,users.user_id,snippet_package_version.snippet_package_version_id,
+snippet_package_version.version,snippet_package_version.post_date 
+FROM snippet_package_version,users 
+WHERE users.user_id=snippet_package_version.submitted_by AND snippet_package_id='$id' 
+ORDER BY snippet_package_version.snippet_package_version_id DESC";
 
 	$result=db_query($sql);
 	$rows=db_numrows($result);

Modified: trunk/gforge/www/snippet/snippet_utils.php
===================================================================
--- trunk/gforge/www/snippet/snippet_utils.php	2009-06-19 09:56:57 UTC (rev 7871)
+++ trunk/gforge/www/snippet/snippet_utils.php	2009-06-19 09:57:06 UTC (rev 7872)
@@ -121,12 +121,12 @@
 
 function snippet_show_package_snippets($version) {
 	//show the latest version
-	$sql="SELECT snippet_package_item.snippet_version_id, snippet_version.version,snippet.name,users.user_name ".
-		"FROM snippet,snippet_version,snippet_package_item,users ".
-		"WHERE snippet.snippet_id=snippet_version.snippet_id ".
-		"AND users.user_id=snippet_version.submitted_by ".
-		"AND snippet_version.snippet_version_id=snippet_package_item.snippet_version_id ".
-		"AND snippet_package_item.snippet_package_version_id='$version'";
+	$sql="SELECT snippet_package_item.snippet_version_id, snippet_version.version,snippet.name,users.user_name 
+FROM snippet,snippet_version,snippet_package_item,users 
+WHERE snippet.snippet_id=snippet_version.snippet_id 
+AND users.user_id=snippet_version.submitted_by 
+AND snippet_version.snippet_version_id=snippet_package_item.snippet_version_id 
+AND snippet_package_item.snippet_package_version_id='$version'";
 
 	$result=db_query($sql);
 	$rows=db_numrows($result);




More information about the Fusionforge-commits mailing list