[Mapbender-commits] r2036 - branches/2.5/http/classes

svn_mapbender at osgeo.org svn_mapbender at osgeo.org
Tue Jan 29 07:44:23 EST 2008


Author: christoph
Date: 2008-01-29 07:44:23 -0500 (Tue, 29 Jan 2008)
New Revision: 2036

Modified:
   branches/2.5/http/classes/class_wms.php
Log:
enabled transactions

prepared statements

Modified: branches/2.5/http/classes/class_wms.php
===================================================================
--- branches/2.5/http/classes/class_wms.php	2008-01-29 12:43:00 UTC (rev 2035)
+++ branches/2.5/http/classes/class_wms.php	2008-01-29 12:44:23 UTC (rev 2036)
@@ -842,7 +842,7 @@
 		global $con;
 		
 		$this->checkObj();
-		//db_begin();
+		db_begin();
 	
 		# TABLE wms
 		$sql = "INSERT INTO wms (wms_version, wms_title, wms_abstract, wms_getcapabilities, wms_getmap, ";
@@ -860,7 +860,7 @@
 		$t = array('s','s','s','s','s','s','s','s','s','s','s','s','s','s','s','s','s','s','s','s','s','s','i','i');
 		$res = db_prep_query($sql,$v,$t);
 		if(!$res){
-			////db_rollback();
+			db_rollback();
 		}
 		
 		$myWMS = db_insert_id($con,'wms', 'wms_id');
@@ -898,9 +898,9 @@
 		$t = array('s','i','i','s','s','s','s');
 		$res = db_prep_query($sql,$v,$t);
 		if(!$res){
-			////db_rollback();	
+			db_rollback();	
 		}
-		//db_commit();
+		db_commit();
 	    
 	    #Changes JW
 	    $this->wms_id = $myWMS;
@@ -927,7 +927,7 @@
 		$t = array('i','i','s','s','s','i','i','i','s','s','s');
 		$res = db_prep_query($sql,$v,$t);
 		if(!$res){
-			////db_rollback();	
+			db_rollback();	
 		}
 		else {
 			# save the id of each layer: set param2 true		
@@ -951,7 +951,7 @@
 			$l_id = $row['layer_id'];	
 		}
 		else{
-			////db_rollback();
+			db_rollback();
 			$e = new mb_exception("Not found: ".$this->objLayer[$i]->layer_name);
 			return;	
 		}	
@@ -996,7 +996,7 @@
 			$res = db_prep_query($sql,$v,$t);
 		}
 		if(!$res){
-			////db_rollback();	
+			db_rollback();	
 		}
 		else {
 			
@@ -1030,7 +1030,7 @@
 		$res = db_prep_query($sql,$v,$t);
 		#$e = new mb_exception("name des insert styles und fkey_layer_id: ".$layer_style_name." --- ".$this->objLayer[$i]->db_id);
 		if(!$res){
-			////db_rollback();	
+			db_rollback();	
 		}	
 	}
 	function appendGuiLayer($i,$myWMS,$gui_id){
@@ -1051,7 +1051,7 @@
 		$t = array('s','i','i','i','i','i','i','i','i','i','i','s');
 		$res = db_prep_query($sql,$v,$t);
 		if(!$res){
-			////db_rollback();	
+			db_rollback();	
 		}	
 	}
 	function insertSRS($myWMS){
@@ -1061,7 +1061,7 @@
 			$t = array('i','s');		
 			$res = db_prep_query($sql,$v,$t);
 			if(!$res){
-				//db_rollback();	
+				db_rollback();	
 			}
 		}	
 	}
@@ -1073,7 +1073,7 @@
 			$t = array('i','s','s');
 			$res = db_prep_query($sql,$v,$t);
 			if(!$res){
-				////db_rollback();	
+				db_rollback();	
 			}
 		}	
 	}
@@ -1092,7 +1092,7 @@
 			$t = array('i','s','d','d','d','d');
 			$res = db_prep_query($sql,$v,$t);
 			if(!$res){
-				////db_rollback();	
+				db_rollback();	
 			}
 		}
 	}
@@ -1111,7 +1111,7 @@
 			$t = array('i','s','s','s','s');
 			$res = db_prep_query($sql,$v,$t);
 			if(!$res){
-				////db_rollback();	
+				db_rollback();	
 			}
 		}
 	}
@@ -1146,7 +1146,7 @@
 					echo $k[$j];
 					$res_insertKeyword = db_prep_query($sql_insertKeyword,$v1,$t1);
 					if(!$res_insertKeyword){
-						//db_rollback();	
+						db_rollback();	
 					}
 				}
 			}
@@ -1165,13 +1165,13 @@
 				$t1 = array('i','i');
 				$res1 = db_prep_query($sql1,$v1,$t1);
 				if(!$res1){
-					////db_rollback();	
+					db_rollback();	
 				}
 			}
 		}
 	}
 	function updateObjInDB($myWMS){
-		//db_begin();
+		db_begin();
 		
 		$sql = "UPDATE wms SET ";
 		$sql .= "wms_version = $1 ,";
@@ -1192,7 +1192,7 @@
 	
 		$res = db_prep_query($sql,$v,$t);
 		if(!$res){
-			//db_rollback();	
+			db_rollback();	
 		}
 		
 		if($this->overwrite == true){
@@ -1221,7 +1221,7 @@
 			$t = array('s','s','s','s','s','s','s','s','s','s','s','s','s','s','s','i');
 			$res = db_prep_query($sql,$v,$t);
 			if(!$res){
-				//db_rollback();	
+				db_rollback();	
 			}
 		}
 		
@@ -1231,7 +1231,7 @@
 		$t = array('i');
 		$res = db_prep_query($sql,$v,$t);
 		if(!$res){
-			//db_rollback();	
+			db_rollback();	
 		}
 		$this->insertSRS($myWMS);
 		
@@ -1240,7 +1240,7 @@
 		$t = array('i');
 		$res = db_prep_query($sql,$v,$t);
 		if(!$res){
-			//db_rollback();	
+			db_rollback();	
 		}
 		$this->insertFormat($myWMS);
 		
@@ -1264,7 +1264,7 @@
 		
 		$res = db_prep_query($sql,$v,$t);
 		if(!$res){
-			//db_rollback();	
+			db_rollback();	
 		}
 			
 		# update or insert?
@@ -1302,7 +1302,7 @@
 				}
 			}
 		}
-		//db_commit();
+		db_commit();
 		return;	
 	}
 	function updateGuiLayer($i,$myWMS,$gui_id){
@@ -1314,7 +1314,7 @@
 			$l_id = $row['layer_id'];	
 		}
 		else{
-			//db_rollback();
+			db_rollback();
 			$e = new mb_exception("Not found: ".$this->objLayer[$i]->layer_name. " in gui: ".$gui_id);
 			return;	
 		}
@@ -1332,7 +1332,7 @@
 				$res1 = db_prep_query($sql1,$v,$t);
 				if(!$res1){
 					
-				//db_rollback();
+				db_rollback();
 				}
 			}
 			if($this->objLayer[$i]->layer_queryable == 1){
@@ -1343,7 +1343,7 @@
 				$res1 = db_prep_query($sql1,$v,$t);
 				if(!$res1){
 					
-				//db_rollback();
+					db_rollback();
 				}
 			}
 			if($row["gui_layer_minscale"] < $this->objLayer[$i]->layer_minscale){
@@ -1352,7 +1352,7 @@
 				$v = array($this->objLayer[$i]->layer_minscale,$l_id,$gui_id);
 				$t = array('i','i','s');
 				$res1 = db_prep_query($sql1,$v,$t);
-				if(!$res1){//db_rollback();
+				if(!$res1){db_rollback();
 				}
 			}
 			if($row["gui_layer_maxscale"] > $this->objLayer[$i]->layer_maxscale){
@@ -1361,7 +1361,7 @@
 				$v = array($this->objLayer[$i]->layer_maxscale,$l_id,$gui_id);
 				$t = array('i','i','s');
 				$res1 = db_prep_query($sql1,$v,$t);
-				if(!$res1){//db_rollback();
+				if(!$res1){db_rollback();
 				}
 			}		
 		}
@@ -1376,7 +1376,12 @@
 		while($row = db_fetch_array($res)){	
 			unset($mySubmit);
 			$myGUI[$cnt] = $row["fkey_gui_id"];
-			$sql = "UPDATE gui_wms SET ";		
+			
+			$sql = "UPDATE gui_wms SET ";
+			$v = array();
+			$t = array();
+			$paramCount = 0;		
+
 			for($i=0; $i<count($this->data_type); $i++){
 				# gui_wms_mapformat
 				if(mb_strtolower($this->data_type[$i]) == "map" && mb_strtolower($this->data_format[$i]) == mb_strtolower($row["gui_wms_mapformat"])){
@@ -1392,17 +1397,26 @@
 				}
 			}
 			if(!$myMapFormat){
-				$sql .= "gui_wms_mapformat = '".$this->gui_wms_mapformat."' ";
+				$paramCount++;
+				$sql .= "gui_wms_mapformat = $" . $paramCount . " ";
 				$mySubmit = true;
+				array_push($v, $this->gui_wms_mapformat);
+				array_push($t, "s");
 			}
 			if(!$myFeatureInfoFormat){
 				if($mySubmit){ $sql .= ",";}
-				$sql .= "gui_wms_featureinfoformat = '".$this->gui_wms_featureinfoformat."' ";
+				$paramCount++;
+				$sql .= "gui_wms_featureinfoformat = $" . $paramCount . " ";
+				array_push($v, $this->gui_wms_featureinfoformat);
+				array_push($t, "s");
 				$mySubmit = true;
 			}
 			if(!$myExceptionFormat){
 				if($mySubmit){ $sql .= ",";}
-				$sql .= "gui_wms_exceptionformat = '".$this->gui_wms_exceptionformat."' ";
+				$paramCount++;
+				$sql .= "gui_wms_exceptionformat = $" . $paramCount ." ";
+				array_push($v, $this->gui_wms_exceptionformat);
+				array_push($t, "s");
 				$mySubmit = true;
 			}
 				
@@ -1414,12 +1428,30 @@
 			}
 			if(!$myGUI_EPSG){
 				if($mySubmit){ $sql .= ",";}
-				$sql .= "gui_wms_epsg = '".$this->gui_wms_epsg."' ";
+				$paramCount++;
+				$sql .= "gui_wms_epsg = $" . $paramCount . " ";
+				array_push($v, $this->gui_wms_epsg);
+				array_push($t, "s");
 				$mySubmit = true;
 			}
-			$sql .= " WHERE fkey_gui_id = '".$row["fkey_gui_id"]."' AND fkey_wms_id = " . $myWMS;
+			$paramCount++;
+			$sql .= " WHERE fkey_gui_id = $" . $paramCount . " ";
+			array_push($v, $row["fkey_gui_id"]);
+			array_push($t, "s");
+
+			$paramCount++;
+			$sql .= "AND fkey_wms_id = $" . $paramCount;
+			array_push($v, $myWMS);
+			array_push($t, "i");
 			if($mySubmit){
-				$this->transaction($sql);
+				$res = db_prep_query($sql,$v,$t);
+				if(!$res){
+					db_rollback();	
+					echo "<pre>".$sql."</pre><br> <br><p>";
+				 	echo db_error(); 
+				 	echo "<br /> UPDATE ERROR -> KILL PROCESS AND ROLLBACK....................no update<br><br>";
+					$e = new mb_exception("class_wms.php: transaction: Transaction aborted, rollback.");
+				}
 			}
 			$cnt++;
 		}	
@@ -1435,26 +1467,7 @@
 	function getCapabilitiesDoc() {
 		return $this->wms_getcapabilities_doc;
 	}
-	function transaction($sql){
-		#echo "<hr>". $sql;
-		$ok = db_query($sql);
-		if(!$ok){
-			echo "<pre>".$sql."</pre><br> <br><p>";
-			$error = db_error();
-			$sql = "ROLLBACK";
-			$res = db_query($sql);
-			if(SYS_DBTYPE=="pgsql")
-				{
-					$sql = "SET AUTOCOMMIT=0";
-				}
-				else
-				{
-				 	$sql = "SET AUTOCOMMIT=1";
-				}
-		 	echo $error; 
-		 	echo "<br /> UPDATE ERROR -> KILL PROCESS AND ROLLBACK....................no update<br><br>";
-			}
-	}
+	
 	/**
 	* creatObjfromDB
 	*



More information about the Mapbender_commits mailing list