Passed
Push — master ( 2a5ce0...65bdac )
by Alxarafe
23:02
created
dolibarr/htdocs/core/db/mssql.class.php 1 patch
Braces   +113 added lines, -99 removed lines patch added patch discarded remove patch
@@ -97,8 +97,7 @@  discard block
 block discarded – undo
97 97
 			// (La base Dolibarr a ete forcee en this->forcecharset a l'install)
98 98
 			$this->connected = true;
99 99
 			$this->ok = true;
100
-		}
101
-		else
100
+		} else
102 101
 		{
103 102
 			// host, login ou password incorrect
104 103
 			$this->connected = false;
@@ -115,8 +114,7 @@  discard block
 block discarded – undo
115 114
 				$this->database_selected = true;
116 115
 				$this->database_name = $name;
117 116
 				$this->ok = true;
118
-			}
119
-			else
117
+			} else
120 118
 			{
121 119
 				$this->database_selected = false;
122 120
 				$this->database_name = '';
@@ -124,8 +122,7 @@  discard block
 block discarded – undo
124 122
 				$this->error=$this->error();
125 123
 				dol_syslog(get_class($this)."::DoliDBMssql : Erreur Select_db ".$this->error,LOG_ERR);
126 124
 			}
127
-		}
128
-		else
125
+		} else
129 126
 		{
130 127
 			// Pas de selection de base demandee, ok ou ko
131 128
 			$this->database_selected = false;
@@ -174,7 +171,9 @@  discard block
 block discarded – undo
174 171
 	{
175 172
 		dol_syslog(get_class($this)."::connect host=$host, port=$port, login=$login, passwd=--hidden--, name=$name");
176 173
 		$newhost=$host;
177
-		if ($port) $newhost.=':'.$port;
174
+		if ($port) {
175
+		    $newhost.=':'.$port;
176
+		}
178 177
 		$this->db  = @mssql_connect($newhost, $login, $passwd);
179 178
 		//force les enregistrement en latin1 si la base est en utf8 par defaut
180 179
 		// Supprime car plante sur mon PHP-Mysql. De plus, la base est forcement en latin1 avec
@@ -205,8 +204,9 @@  discard block
 block discarded – undo
205 204
 		{
206 205
             $version=$this->fetch_array($resql);
207 206
             return $version['computed'];
208
-		}
209
-		else return '';
207
+		} else {
208
+		    return '';
209
+		}
210 210
 	}
211 211
 
212 212
 	/**
@@ -229,7 +229,9 @@  discard block
 block discarded – undo
229 229
     {
230 230
         if ($this->db)
231 231
         {
232
-          if ($this->transaction_opened > 0) dol_syslog(get_class($this)."::close Closing a connection with an opened transaction depth=".$this->transaction_opened,LOG_ERR);
232
+          if ($this->transaction_opened > 0) {
233
+              dol_syslog(get_class($this)."::close Closing a connection with an opened transaction depth=".$this->transaction_opened,LOG_ERR);
234
+          }
233 235
           $this->connected=false;
234 236
           return mssql_close($this->db);
235 237
         }
@@ -257,8 +259,7 @@  discard block
 block discarded – undo
257 259
 				dol_syslog("BEGIN Transaction",LOG_DEBUG);
258 260
 			}
259 261
 			return $ret;
260
-		}
261
-		else
262
+		} else
262 263
 		{
263 264
 			return true;
264 265
 		}
@@ -283,13 +284,11 @@  discard block
 block discarded – undo
283 284
 			{
284 285
 				dol_syslog("COMMIT Transaction",LOG_DEBUG);
285 286
 				return true;
286
-			}
287
-			else
287
+			} else
288 288
 			{
289 289
 				return false;
290 290
 			}
291
-		}
292
-		elseif ($this->transaction_opened > 1)
291
+		} elseif ($this->transaction_opened > 1)
293 292
 		{
294 293
 			return true;
295 294
 		}
@@ -313,8 +312,7 @@  discard block
 block discarded – undo
313 312
 			$ret=mssql_query("ROLLBACK TRANSACTION",$this->db);
314 313
 			dol_syslog("ROLLBACK Transaction".($log?' '.$log:''),LOG_DEBUG);
315 314
 			return $ret;
316
-		}
317
-		elseif ($this->transaction_opened > 1)
315
+		} elseif ($this->transaction_opened > 1)
318 316
 		{
319 317
 			return true;
320 318
 		}
@@ -337,7 +335,9 @@  discard block
 block discarded – undo
337 335
 
338 336
         Debug::addMessage('SQL', 'MSSQL: ' . $query);
339 337
 
340
-        if (preg_match('/^--/',$query)) return true;
338
+        if (preg_match('/^--/',$query)) {
339
+            return true;
340
+        }
341 341
 
342 342
 		// Conversion syntaxe MySql vers MSDE.
343 343
 		$query = str_ireplace("now()", "getdate()", $query);
@@ -371,11 +371,11 @@  discard block
 block discarded – undo
371 371
                             $query_comp[]=$fld->COLUMN_NAME." IS NOT NULL";
372 372
                         }
373 373
                     }
374
-                    if (! empty($query_comp))
375
-                        $query.=" WHERE ".implode(" AND ",$query_comp);
374
+                    if (! empty($query_comp)) {
375
+                                            $query.=" WHERE ".implode(" AND ",$query_comp);
376
+                    }
376 377
                 }
377
-    		}
378
-    		else
378
+    		} else
379 379
     		{
380 380
     		    if (preg_match('/ALTER TABLE\h+(\w+?)\h+ADD\h+PRIMARY\h+KEY\h+(\w+?)\h*\((.+)\)/is', $query, $matches))
381 381
     		    {
@@ -428,14 +428,15 @@  discard block
 block discarded – undo
428 428
 		}
429 429
 		//print "<!--".$query."-->";
430 430
 
431
-		if (! in_array($query,array('BEGIN','COMMIT','ROLLBACK'))) dol_syslog('sql='.$query, LOG_DEBUG);
431
+		if (! in_array($query,array('BEGIN','COMMIT','ROLLBACK'))) {
432
+		    dol_syslog('sql='.$query, LOG_DEBUG);
433
+		}
432 434
 
433 435
 		if (! $this->database_name)
434 436
 		{
435 437
 			// Ordre SQL ne necessitant pas de connexion a une base (exemple: CREATE DATABASE)
436 438
 			$ret = mssql_query($query, $this->db);
437
-		}
438
-		else
439
+		} else
439 440
 		{
440 441
 			$ret = mssql_query($query, $this->db);
441 442
 		}
@@ -458,7 +459,9 @@  discard block
 block discarded – undo
458 459
 				$this->lasterrno = $row["code"];
459 460
 
460 461
 				dol_syslog(get_class($this)."::query SQL Error query: ".$query, LOG_ERR);
461
-				if ($original_query) dol_syslog(get_class($this)."::query SQL Original query: ".$original_query, LOG_ERR);
462
+				if ($original_query) {
463
+				    dol_syslog(get_class($this)."::query SQL Original query: ".$original_query, LOG_ERR);
464
+				}
462 465
 				dol_syslog(get_class($this)."::query SQL Error message: ".$this->lasterror." (".$this->lasterrno.")", LOG_ERR);
463 466
 			}
464 467
 			$this->lastquery=$query;
@@ -562,7 +565,9 @@  discard block
 block discarded – undo
562 565
 		// Si le resultset n'est pas fourni, on prend le dernier utilise sur cette connexion
563 566
 		if (! is_resource($resultset)) { $resultset=$this->_results; }
564 567
 		// Si resultset en est un, on libere la memoire
565
-		if (is_resource($resultset)) mssql_free_result($resultset);
568
+		if (is_resource($resultset)) {
569
+		    mssql_free_result($resultset);
570
+		}
566 571
 	}
567 572
 
568 573
 	/**
@@ -600,8 +605,7 @@  discard block
 block discarded – undo
600 605
 		{
601 606
 			// Si il y a eu echec de connexion, $this->db n'est pas valide.
602 607
 			return 'DB_ERROR_FAILED_TO_CONNECT';
603
-		}
604
-		else
608
+		} else
605 609
 		{
606 610
 			// Constants to convert a MSSql error code to a generic Dolibarr error code
607 611
 			$errorcode_map = array(
@@ -652,8 +656,7 @@  discard block
 block discarded – undo
652 656
 		if (! $this->connected) {
653 657
 			// Si il y a eu echec de connexion, $this->db n'est pas valide pour mssql_get_last_message.
654 658
 			return 'Not connected. Check setup parameters in conf/conf.php file and your mssql client and server versions';
655
-		}
656
-		else {
659
+		} else {
657 660
 			return mssql_get_last_message();
658 661
 		}
659 662
 	}
@@ -673,8 +676,7 @@  discard block
 block discarded – undo
673 676
 		if ($res && $data = $this->fetch_array($res))
674 677
 		{
675 678
 			return $data["id"];
676
-		}
677
-		else
679
+		} else
678 680
 		{
679 681
 			return -1;
680 682
 		}
@@ -737,8 +739,9 @@  discard block
 block discarded – undo
737 739
 		{
738 740
             $row=$this->fetch_row($resql);
739 741
             return $row[0];
740
-		}
741
-		else return '?';
742
+		} else {
743
+		    return '?';
744
+		}
742 745
 	}
743 746
 
744 747
     // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
@@ -839,26 +842,27 @@  discard block
 block discarded – undo
839 842
 		{
840 843
 			$sqlfields[$i] = $field_name." ";
841 844
 			$sqlfields[$i]  .= $field_desc['type'];
842
-			if( preg_match("/^[^\s]/i",$field_desc['value']))
843
-			$sqlfields[$i]  .= "(".$field_desc['value'].")";
844
-			else if( preg_match("/^[^\s]/i",$field_desc['attribute']))
845
-			$sqlfields[$i]  .= " ".$field_desc['attribute'];
846
-			else if( preg_match("/^[^\s]/i",$field_desc['default']))
845
+			if( preg_match("/^[^\s]/i",$field_desc['value'])) {
846
+						$sqlfields[$i]  .= "(".$field_desc['value'].")";
847
+			} else if( preg_match("/^[^\s]/i",$field_desc['attribute'])) {
848
+						$sqlfields[$i]  .= " ".$field_desc['attribute'];
849
+			} else if( preg_match("/^[^\s]/i",$field_desc['default']))
847 850
 			{
848
-				if(preg_match("/null/i",$field_desc['default']))
849
-				$sqlfields[$i]  .= " default ".$field_desc['default'];
850
-				else
851
-				$sqlfields[$i]  .= " default '".$field_desc['default']."'";
852
-			}
853
-			else if( preg_match("/^[^\s]/i",$field_desc['null']))
854
-			$sqlfields[$i]  .= " ".$field_desc['null'];
855
-
856
-			else if( preg_match("/^[^\s]/i",$field_desc['extra']))
857
-			$sqlfields[$i]  .= " ".$field_desc['extra'];
851
+				if(preg_match("/null/i",$field_desc['default'])) {
852
+								$sqlfields[$i]  .= " default ".$field_desc['default'];
853
+				} else {
854
+								$sqlfields[$i]  .= " default '".$field_desc['default']."'";
855
+				}
856
+			} else if( preg_match("/^[^\s]/i",$field_desc['null'])) {
857
+						$sqlfields[$i]  .= " ".$field_desc['null'];
858
+			} else if( preg_match("/^[^\s]/i",$field_desc['extra'])) {
859
+						$sqlfields[$i]  .= " ".$field_desc['extra'];
860
+			}
858 861
 			$i++;
859 862
 		}
860
-		if($primary_key != "")
861
-		$pk = "primary key(".$primary_key.")";
863
+		if($primary_key != "") {
864
+				$pk = "primary key(".$primary_key.")";
865
+		}
862 866
 
863 867
 		if(is_array($unique_keys))
864 868
 		{
@@ -879,19 +883,23 @@  discard block
 block discarded – undo
879 883
 			}
880 884
 		}
881 885
 		$sql .= implode(',',$sqlfields);
882
-		if($primary_key != "")
883
-		$sql .= ",".$pk;
884
-		if(is_array($unique_keys))
885
-		$sql .= ",".implode(',',$sqluq);
886
-		if(is_array($keys))
887
-		$sql .= ",".implode(',',$sqlk);
886
+		if($primary_key != "") {
887
+				$sql .= ",".$pk;
888
+		}
889
+		if(is_array($unique_keys)) {
890
+				$sql .= ",".implode(',',$sqluq);
891
+		}
892
+		if(is_array($keys)) {
893
+				$sql .= ",".implode(',',$sqlk);
894
+		}
888 895
 		$sql .=") type=".$type;
889 896
 
890 897
 		dol_syslog($sql);
891
-		if (!$this->query($sql))
892
-            return -1;
893
-		else
894
-		return 1;
898
+		if (!$this->query($sql)) {
899
+		            return -1;
900
+		} else {
901
+				return 1;
902
+		}
895 903
 	}
896 904
 
897 905
     // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
@@ -906,10 +914,11 @@  discard block
 block discarded – undo
906 914
         // phpcs:enable
907 915
 		$sql = "DROP TABLE ".$table;
908 916
 
909
-		if (! $this->query($sql))
910
-			return -1;
911
-		else
912
-			return 1;
917
+		if (! $this->query($sql)) {
918
+					return -1;
919
+		} else {
920
+					return 1;
921
+		}
913 922
 	}
914 923
 
915 924
     // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
@@ -947,25 +956,31 @@  discard block
 block discarded – undo
947 956
 		// ex. : $field_desc = array('type'=>'int','value'=>'11','null'=>'not null','extra'=> 'auto_increment');
948 957
 		$sql= "ALTER TABLE ".$table." ADD ".$field_name." ";
949 958
 		$sql .= $field_desc['type'];
950
-		if( preg_match("/^[^\s]/i",$field_desc['value']))
951
-		$sql  .= "(".$field_desc['value'].")";
952
-		if( preg_match("/^[^\s]/i",$field_desc['attribute']))
953
-		$sql  .= " ".$field_desc['attribute'];
954
-		if( preg_match("/^[^\s]/i",$field_desc['null']))
955
-		$sql  .= " ".$field_desc['null'];
956
-		if( preg_match("/^[^\s]/i",$field_desc['default']))
957
-		if(preg_match("/null/i",$field_desc['default']))
958
-		$sql  .= " default ".$field_desc['default'];
959
-		else
960
-		$sql  .= " default '".$field_desc['default']."'";
961
-		if( preg_match("/^[^\s]/i",$field_desc['extra']))
962
-		$sql  .= " ".$field_desc['extra'];
959
+		if( preg_match("/^[^\s]/i",$field_desc['value'])) {
960
+				$sql  .= "(".$field_desc['value'].")";
961
+		}
962
+		if( preg_match("/^[^\s]/i",$field_desc['attribute'])) {
963
+				$sql  .= " ".$field_desc['attribute'];
964
+		}
965
+		if( preg_match("/^[^\s]/i",$field_desc['null'])) {
966
+				$sql  .= " ".$field_desc['null'];
967
+		}
968
+		if( preg_match("/^[^\s]/i",$field_desc['default'])) {
969
+				if(preg_match("/null/i",$field_desc['default']))
970
+		$sql  .= " default ".$field_desc['default'];
971
+		} else {
972
+				$sql  .= " default '".$field_desc['default']."'";
973
+		}
974
+		if( preg_match("/^[^\s]/i",$field_desc['extra'])) {
975
+				$sql  .= " ".$field_desc['extra'];
976
+		}
963 977
 		$sql .= " ".$field_position;
964 978
 
965
-		if (!$this->query($sql))
966
-            return -1;
967
-		else
968
-		return 1;
979
+		if (!$this->query($sql)) {
980
+		            return -1;
981
+		} else {
982
+				return 1;
983
+		}
969 984
 	}
970 985
 
971 986
     // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
@@ -987,10 +1002,11 @@  discard block
 block discarded – undo
987 1002
 		}
988 1003
 
989 1004
 		dol_syslog($sql,LOG_DEBUG);
990
-		if (! $this->query($sql))
991
-		return -1;
992
-		else
993
-		return 1;
1005
+		if (! $this->query($sql)) {
1006
+				return -1;
1007
+		} else {
1008
+				return 1;
1009
+		}
994 1010
 	}
995 1011
 
996 1012
     // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
@@ -1010,8 +1026,9 @@  discard block
 block discarded – undo
1010 1026
 		{
1011 1027
 			$this->error=$this->lasterror();
1012 1028
 			return -1;
1013
-		}
1014
-		else return 1;
1029
+		} else {
1030
+		    return 1;
1031
+		}
1015 1032
 	}
1016 1033
 
1017 1034
     // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
@@ -1035,8 +1052,7 @@  discard block
 block discarded – undo
1035 1052
             if ($this->lasterrno != '15025')
1036 1053
             {
1037 1054
 	            return -1;
1038
-            }
1039
-            else
1055
+            } else
1040 1056
 			{
1041 1057
             	// If user already exists, we continue to set permissions
1042 1058
             	dol_syslog(get_class($this)."::DDLCreateUser sql=".$sql, LOG_WARNING);
@@ -1048,8 +1064,7 @@  discard block
 block discarded – undo
1048 1064
         {
1049 1065
             dol_syslog(get_class($this)."::DDLCreateUser sql=".$sql, LOG_WARNING);
1050 1066
             return -1;
1051
-        }
1052
-        else
1067
+        } else
1053 1068
         {
1054 1069
             if ($num)
1055 1070
             {
@@ -1204,8 +1219,7 @@  discard block
 block discarded – undo
1204 1219
 	    if (is_array($fields))
1205 1220
 	    {
1206 1221
 	        $where=" IN ('".implode("','",$fields)."')";
1207
-	    }
1208
-	    else
1222
+	    } else
1209 1223
 	    {
1210 1224
 	        $where="='".$this->escape($fields)."'";
1211 1225
 	    }
@@ -1217,9 +1231,9 @@  discard block
 block discarded – undo
1217 1231
 	        {
1218 1232
 	            $result[]=$obj;
1219 1233
 	        }
1220
-	    }
1221
-	    else
1222
-	        return false;
1234
+	    } else {
1235
+	    	        return false;
1236
+	    }
1223 1237
 
1224 1238
 	    return $result;
1225 1239
 	}
Please login to merge, or discard this patch.
dolibarr/htdocs/core/db/sqlite3.class.php 1 patch
Braces   +120 added lines, -87 removed lines patch added patch discarded remove patch
@@ -68,8 +68,12 @@  discard block
 block discarded – undo
68 68
         global $conf;
69 69
 
70 70
         // Note that having "static" property for "$forcecharset" and "$forcecollate" will make error here in strict mode, so they are not static
71
-        if (! empty($conf->db->character_set)) $this->forcecharset=$conf->db->character_set;
72
-        if (! empty($conf->db->dolibarr_main_db_collation)) $this->forcecollate=$conf->db->dolibarr_main_db_collation;
71
+        if (! empty($conf->db->character_set)) {
72
+            $this->forcecharset=$conf->db->character_set;
73
+        }
74
+        if (! empty($conf->db->dolibarr_main_db_collation)) {
75
+            $this->forcecollate=$conf->db->dolibarr_main_db_collation;
76
+        }
73 77
 
74 78
         $this->database_user=$user;
75 79
         $this->database_host=$host;
@@ -117,8 +121,7 @@  discard block
 block discarded – undo
117 121
             $this->addCustomFunction('WEEKDAY');
118 122
             $this->addCustomFunction('date_format');
119 123
             //$this->db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
120
-        }
121
-        else
124
+        } else
122 125
         {
123 126
             // host, login ou password incorrect
124 127
             $this->connected = false;
@@ -155,9 +158,13 @@  discard block
 block discarded – undo
155 158
         {
156 159
             if ($type == 'auto')
157 160
             {
158
-              if (preg_match('/ALTER TABLE/i',$line)) $type='dml';
159
-              else if (preg_match('/CREATE TABLE/i',$line)) $type='dml';
160
-              else if (preg_match('/DROP TABLE/i',$line)) $type='dml';
161
+              if (preg_match('/ALTER TABLE/i',$line)) {
162
+                  $type='dml';
163
+              } else if (preg_match('/CREATE TABLE/i',$line)) {
164
+                  $type='dml';
165
+              } else if (preg_match('/DROP TABLE/i',$line)) {
166
+                  $type='dml';
167
+              }
161 168
             }
162 169
 
163 170
             if ($type == 'dml')
@@ -277,9 +284,11 @@  discard block
 block discarded – undo
277 284
             // DELETE FROM tabletodelete USING tabletodelete, othertable -> DELETE FROM tabletodelete USING othertable
278 285
             if (preg_match('/DELETE FROM ([a-z_]+) USING ([a-z_]+), ([a-z_]+)/i',$line,$reg))
279 286
             {
280
-				if ($reg[1] == $reg[2])	// If same table, we remove second one
287
+				if ($reg[1] == $reg[2]) {
288
+				    // If same table, we remove second one
281 289
                 {
282
-                    $line=preg_replace('/DELETE FROM ([a-z_]+) USING ([a-z_]+), ([a-z_]+)/i','DELETE FROM \\1 USING \\3', $line);
290
+                    $line=preg_replace('/DELETE FROM ([a-z_]+) USING ([a-z_]+), ([a-z_]+)/i','DELETE FROM \\1 USING \\3', $line);
291
+				}
283 292
                 }
284 293
             }
285 294
 
@@ -336,7 +345,9 @@  discard block
 block discarded – undo
336 345
         dol_syslog(get_class($this)."::connect name=".$name,LOG_DEBUG);
337 346
 
338 347
         $dir=$main_data_dir;
339
-        if (empty($dir)) $dir=DOL_DATA_ROOT;
348
+        if (empty($dir)) {
349
+            $dir=DOL_DATA_ROOT;
350
+        }
340 351
         // With sqlite, port must be in connect parameters
341 352
         //if (! $newport) $newport=3306;
342 353
         $database_name = $dir.'/database_'.$name.'.sdb';
@@ -345,8 +356,7 @@  discard block
 block discarded – undo
345 356
             //$this->db = new PDO("sqlite:".$dir.'/database_'.$name.'.sdb');
346 357
 			$this->db = new SQLite3($database_name);
347 358
             //$this->db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
348
-        }
349
-        catch(Exception $e)
359
+        } catch(Exception $e)
350 360
         {
351 361
             $this->error=  self::LABEL.' '.$e->getMessage().' current dir='.$database_name;
352 362
             return '';
@@ -389,7 +399,9 @@  discard block
 block discarded – undo
389 399
     {
390 400
         if ($this->db)
391 401
         {
392
-            if ($this->transaction_opened > 0) dol_syslog(get_class($this)."::close Closing a connection with an opened transaction depth=".$this->transaction_opened,LOG_ERR);
402
+            if ($this->transaction_opened > 0) {
403
+                dol_syslog(get_class($this)."::close Closing a connection with an opened transaction depth=".$this->transaction_opened,LOG_ERR);
404
+            }
393 405
             $this->connected=false;
394 406
             $this->db->close();
395 407
             unset($this->db);    // Clean this->db
@@ -467,8 +479,7 @@  discard block
 block discarded – undo
467 479
             if ($ret) {
468 480
                 $ret->queryString = $query;
469 481
             }
470
-        }
471
-        catch(Exception $e)
482
+        } catch(Exception $e)
472 483
         {
473 484
             $this->error=$this->db->lastErrorMsg();
474 485
         }
@@ -552,8 +563,7 @@  discard block
 block discarded – undo
552 563
         {
553 564
             if (! is_object($resultset)) { $resultset=$this->_results; }
554 565
             return $resultset->fetchArray(SQLITE3_NUM);
555
-        }
556
-        else
566
+        } else
557 567
         {
558 568
             // si le curseur est un booleen on retourne la valeur 0
559 569
             return false;
@@ -616,7 +626,9 @@  discard block
 block discarded – undo
616 626
         // If resultset not provided, we take the last used by connexion
617 627
         if (! is_object($resultset)) { $resultset=$this->_results; }
618 628
         // Si resultset en est un, on libere la memoire
619
-        if ($resultset && is_object($resultset)) $resultset->finalize();
629
+        if ($resultset && is_object($resultset)) {
630
+            $resultset->finalize();
631
+        }
620 632
     }
621 633
 
622 634
     /**
@@ -640,8 +652,7 @@  discard block
 block discarded – undo
640 652
         if (! $this->connected) {
641 653
             // Si il y a eu echec de connexion, $this->db n'est pas valide.
642 654
             return 'DB_ERROR_FAILED_TO_CONNECT';
643
-        }
644
-        else {
655
+        } else {
645 656
             // Constants to convert error code to a generic Dolibarr error code
646 657
             /*$errorcode_map = array(
647 658
             1004 => 'DB_ERROR_CANNOT_CREATE',
@@ -678,14 +689,21 @@  discard block
 block discarded – undo
678 689
             $errno=$this->db->lastErrorCode();
679 690
 			if ($errno=='HY000' || $errno == 0)
680 691
             {
681
-                if (preg_match('/table.*already exists/i',$this->error))     return 'DB_ERROR_TABLE_ALREADY_EXISTS';
682
-                elseif (preg_match('/index.*already exists/i',$this->error)) return 'DB_ERROR_KEY_NAME_ALREADY_EXISTS';
683
-                elseif (preg_match('/syntax error/i',$this->error))          return 'DB_ERROR_SYNTAX';
692
+                if (preg_match('/table.*already exists/i',$this->error)) {
693
+                    return 'DB_ERROR_TABLE_ALREADY_EXISTS';
694
+                } elseif (preg_match('/index.*already exists/i',$this->error)) {
695
+                    return 'DB_ERROR_KEY_NAME_ALREADY_EXISTS';
696
+                } elseif (preg_match('/syntax error/i',$this->error)) {
697
+                    return 'DB_ERROR_SYNTAX';
698
+                }
684 699
             }
685 700
             if ($errno=='23000')
686 701
             {
687
-                if (preg_match('/column.* not unique/i',$this->error))       return 'DB_ERROR_RECORD_ALREADY_EXISTS';
688
-                elseif (preg_match('/PRIMARY KEY must be unique/i',$this->error)) return 'DB_ERROR_RECORD_ALREADY_EXISTS';
702
+                if (preg_match('/column.* not unique/i',$this->error)) {
703
+                    return 'DB_ERROR_RECORD_ALREADY_EXISTS';
704
+                } elseif (preg_match('/PRIMARY KEY must be unique/i',$this->error)) {
705
+                    return 'DB_ERROR_RECORD_ALREADY_EXISTS';
706
+                }
689 707
             }
690 708
             if ($errno > 1) {
691 709
                 // TODO Voir la liste des messages d'erreur
@@ -705,8 +723,7 @@  discard block
 block discarded – undo
705 723
         if (! $this->connected) {
706 724
             // Si il y a eu echec de connexion, $this->db n'est pas valide pour sqlite_error.
707 725
             return 'Not connected. Check setup parameters in conf/conf.php file and your sqlite version';
708
-        }
709
-        else {
726
+        } else {
710 727
             return $this->error;
711 728
         }
712 729
     }
@@ -750,8 +767,7 @@  discard block
 block discarded – undo
750 767
             if ($cryptType == 2)
751 768
             {
752 769
                 $return = 'AES_ENCRYPT('.$return.',\''.$cryptKey.'\')';
753
-            }
754
-            else if ($cryptType == 1)
770
+            } else if ($cryptType == 1)
755 771
             {
756 772
                 $return = 'DES_ENCRYPT('.$return.',\''.$cryptKey.'\')';
757 773
             }
@@ -783,8 +799,7 @@  discard block
 block discarded – undo
783 799
             if ($cryptType == 2)
784 800
             {
785 801
                 $return = 'AES_DECRYPT('.$value.',\''.$cryptKey.'\')';
786
-            }
787
-            else if ($cryptType == 1)
802
+            } else if ($cryptType == 1)
788 803
             {
789 804
                 $return = 'DES_DECRYPT('.$value.',\''.$cryptKey.'\')';
790 805
             }
@@ -822,8 +837,12 @@  discard block
 block discarded – undo
822 837
     function DDLCreateDb($database,$charset='',$collation='',$owner='')
823 838
     {
824 839
         // phpcs:enable
825
-        if (empty($charset))   $charset=$this->forcecharset;
826
-        if (empty($collation)) $collation=$this->forcecollate;
840
+        if (empty($charset)) {
841
+            $charset=$this->forcecharset;
842
+        }
843
+        if (empty($collation)) {
844
+            $collation=$this->forcecollate;
845
+        }
827 846
 
828 847
         // ALTER DATABASE dolibarr_db DEFAULT CHARACTER SET latin DEFAULT COLLATE latin1_swedish_ci
829 848
         $sql = 'CREATE DATABASE '.$database;
@@ -855,7 +874,9 @@  discard block
 block discarded – undo
855 874
         $listtables=array();
856 875
 
857 876
         $like = '';
858
-        if ($table) $like = "LIKE '".$table."'";
877
+        if ($table) {
878
+            $like = "LIKE '".$table."'";
879
+        }
859 880
         $sql="SHOW TABLES FROM ".$database." ".$like.";";
860 881
         //print $sql;
861 882
         $result = $this->query($sql);
@@ -922,26 +943,27 @@  discard block
 block discarded – undo
922 943
         {
923 944
             $sqlfields[$i] = $field_name." ";
924 945
             $sqlfields[$i]  .= $field_desc['type'];
925
-            if( preg_match("/^[^\s]/i",$field_desc['value']))
926
-            $sqlfields[$i]  .= "(".$field_desc['value'].")";
927
-            else if( preg_match("/^[^\s]/i",$field_desc['attribute']))
928
-            $sqlfields[$i]  .= " ".$field_desc['attribute'];
929
-            else if( preg_match("/^[^\s]/i",$field_desc['default']))
946
+            if( preg_match("/^[^\s]/i",$field_desc['value'])) {
947
+                        $sqlfields[$i]  .= "(".$field_desc['value'].")";
948
+            } else if( preg_match("/^[^\s]/i",$field_desc['attribute'])) {
949
+                        $sqlfields[$i]  .= " ".$field_desc['attribute'];
950
+            } else if( preg_match("/^[^\s]/i",$field_desc['default']))
930 951
             {
931
-                if(preg_match("/null/i",$field_desc['default']))
932
-                $sqlfields[$i]  .= " default ".$field_desc['default'];
933
-                else
934
-                $sqlfields[$i]  .= " default '".$field_desc['default']."'";
935
-            }
936
-            else if( preg_match("/^[^\s]/i",$field_desc['null']))
937
-            $sqlfields[$i]  .= " ".$field_desc['null'];
938
-
939
-            else if( preg_match("/^[^\s]/i",$field_desc['extra']))
940
-            $sqlfields[$i]  .= " ".$field_desc['extra'];
952
+                if(preg_match("/null/i",$field_desc['default'])) {
953
+                                $sqlfields[$i]  .= " default ".$field_desc['default'];
954
+                } else {
955
+                                $sqlfields[$i]  .= " default '".$field_desc['default']."'";
956
+                }
957
+            } else if( preg_match("/^[^\s]/i",$field_desc['null'])) {
958
+                        $sqlfields[$i]  .= " ".$field_desc['null'];
959
+            } else if( preg_match("/^[^\s]/i",$field_desc['extra'])) {
960
+                        $sqlfields[$i]  .= " ".$field_desc['extra'];
961
+            }
941 962
             $i++;
942 963
         }
943
-        if($primary_key != "")
944
-        $pk = "primary key(".$primary_key.")";
964
+        if($primary_key != "") {
965
+                $pk = "primary key(".$primary_key.")";
966
+        }
945 967
 
946 968
         if(is_array($unique_keys))
947 969
         {
@@ -962,17 +984,21 @@  discard block
 block discarded – undo
962 984
             }
963 985
         }
964 986
         $sql .= implode(',',$sqlfields);
965
-        if($primary_key != "")
966
-        $sql .= ",".$pk;
967
-        if(is_array($unique_keys))
968
-        $sql .= ",".implode(',',$sqluq);
969
-        if(is_array($keys))
970
-        $sql .= ",".implode(',',$sqlk);
987
+        if($primary_key != "") {
988
+                $sql .= ",".$pk;
989
+        }
990
+        if(is_array($unique_keys)) {
991
+                $sql .= ",".implode(',',$sqluq);
992
+        }
993
+        if(is_array($keys)) {
994
+                $sql .= ",".implode(',',$sqlk);
995
+        }
971 996
         $sql .=") type=".$type;
972 997
 
973 998
         dol_syslog($sql,LOG_DEBUG);
974
-        if (!$this->query($sql))
975
-            return -1;
999
+        if (!$this->query($sql)) {
1000
+                    return -1;
1001
+        }
976 1002
         return 1;
977 1003
     }
978 1004
 
@@ -988,10 +1014,11 @@  discard block
 block discarded – undo
988 1014
         // phpcs:enable
989 1015
     	$sql = "DROP TABLE ".$table;
990 1016
 
991
-    	if (! $this->query($sql))
992
-    		return -1;
993
-    	else
994
-    		return 1;
1017
+    	if (! $this->query($sql)) {
1018
+    	    		return -1;
1019
+    	} else {
1020
+    	    		return 1;
1021
+    	}
995 1022
     }
996 1023
 
997 1024
     // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
@@ -1029,24 +1056,29 @@  discard block
 block discarded – undo
1029 1056
         // ex. : $field_desc = array('type'=>'int','value'=>'11','null'=>'not null','extra'=> 'auto_increment');
1030 1057
         $sql= "ALTER TABLE ".$table." ADD ".$field_name." ";
1031 1058
         $sql.= $field_desc['type'];
1032
-        if(preg_match("/^[^\s]/i",$field_desc['value']))
1033
-        if (! in_array($field_desc['type'],array('date','datetime')))
1059
+        if(preg_match("/^[^\s]/i",$field_desc['value'])) {
1060
+                if (! in_array($field_desc['type'],array('date','datetime')))
1034 1061
         {
1035
-            $sql.= "(".$field_desc['value'].")";
1062
+            $sql.= "(".$field_desc['value'].")";
1063
+        }
1036 1064
         }
1037
-        if(preg_match("/^[^\s]/i",$field_desc['attribute']))
1038
-        $sql.= " ".$field_desc['attribute'];
1039
-        if(preg_match("/^[^\s]/i",$field_desc['null']))
1040
-        $sql.= " ".$field_desc['null'];
1065
+        if(preg_match("/^[^\s]/i",$field_desc['attribute'])) {
1066
+                $sql.= " ".$field_desc['attribute'];
1067
+        }
1068
+        if(preg_match("/^[^\s]/i",$field_desc['null'])) {
1069
+                $sql.= " ".$field_desc['null'];
1070
+        }
1041 1071
         if(preg_match("/^[^\s]/i",$field_desc['default']))
1042 1072
         {
1043
-            if(preg_match("/null/i",$field_desc['default']))
1044
-            $sql.= " default ".$field_desc['default'];
1045
-            else
1046
-            $sql.= " default '".$field_desc['default']."'";
1073
+            if(preg_match("/null/i",$field_desc['default'])) {
1074
+                        $sql.= " default ".$field_desc['default'];
1075
+            } else {
1076
+                        $sql.= " default '".$field_desc['default']."'";
1077
+            }
1047 1078
         }
1048
-        if(preg_match("/^[^\s]/i",$field_desc['extra']))
1049
-        $sql.= " ".$field_desc['extra'];
1079
+        if(preg_match("/^[^\s]/i",$field_desc['extra'])) {
1080
+                $sql.= " ".$field_desc['extra'];
1081
+        }
1050 1082
         $sql.= " ".$field_position;
1051 1083
 
1052 1084
         dol_syslog(get_class($this)."::DDLAddField ".$sql,LOG_DEBUG);
@@ -1076,8 +1108,9 @@  discard block
 block discarded – undo
1076 1108
         }
1077 1109
 
1078 1110
         dol_syslog(get_class($this)."::DDLUpdateField ".$sql,LOG_DEBUG);
1079
-        if (! $this->query($sql))
1080
-            return -1;
1111
+        if (! $this->query($sql)) {
1112
+                    return -1;
1113
+        }
1081 1114
         return 1;
1082 1115
     }
1083 1116
 
@@ -1279,8 +1312,7 @@  discard block
 block discarded – undo
1279 1312
                 $obj = $this->fetch_row($resql);
1280 1313
                 //dol_syslog(get_class($this)."::select_db getServerParametersValues $var=". print_r($obj, true), LOG_DEBUG);
1281 1314
                 $result[$var] = $obj[0];
1282
-            }
1283
-            else {
1315
+            } else {
1284 1316
                 // TODO Récupérer le message
1285 1317
                 $result[$var] = 'FAIL';
1286 1318
             }
@@ -1350,11 +1382,12 @@  discard block
 block discarded – undo
1350 1382
     {
1351 1383
         // phpcs:enable
1352 1384
         $y = $year;
1353
-        if ($y == 0 && $month == 0) return 0;
1385
+        if ($y == 0 && $month == 0) {
1386
+            return 0;
1387
+        }
1354 1388
         $num = (365* $y + 31 * ($month - 1) + $day);
1355 1389
         if ($month <= 2) {
1356
-            $y--; }
1357
-        else {
1390
+            $y--; } else {
1358 1391
             $num -= floor(($month * 4 + 23) / 10);
1359 1392
         }
1360 1393
         $temp = floor(($y / 100 + 1) * 3 / 4);
@@ -1414,8 +1447,9 @@  discard block
 block discarded – undo
1414 1447
 
1415 1448
         if ($month == 1 && $day <= 7-$weekday)
1416 1449
         {
1417
-            if (!$week_year && (($first_weekday && $weekday != 0) || (!$first_weekday && $weekday >= 4)))
1418
-                return 0;
1450
+            if (!$week_year && (($first_weekday && $weekday != 0) || (!$first_weekday && $weekday >= 4))) {
1451
+                            return 0;
1452
+            }
1419 1453
             $week_year= 1;
1420 1454
             $calc_year--;
1421 1455
             $first_daynr-= ($days=self::calc_days_in_year($calc_year));
@@ -1424,8 +1458,7 @@  discard block
 block discarded – undo
1424 1458
 
1425 1459
       if (($first_weekday && $weekday != 0) || (!$first_weekday && $weekday >= 4)) {
1426 1460
         $days= $daynr - ($first_daynr+ (7-$weekday));
1427
-      }
1428
-      else {
1461
+      } else {
1429 1462
         $days= $daynr - ($first_daynr - $weekday);
1430 1463
       }
1431 1464
 
Please login to merge, or discard this patch.
dolibarr/htdocs/core/db/mysqli.class.php 1 patch
Braces   +109 added lines, -67 removed lines patch added patch discarded remove patch
@@ -65,8 +65,12 @@  discard block
 block discarded – undo
65 65
         global $conf,$langs;
66 66
 
67 67
         // Note that having "static" property for "$forcecharset" and "$forcecollate" will make error here in strict mode, so they are not static
68
-        if (! empty($conf->db->character_set)) $this->forcecharset=$conf->db->character_set;
69
-        if (! empty($conf->db->dolibarr_main_db_collation)) $this->forcecollate=$conf->db->dolibarr_main_db_collation;
68
+        if (! empty($conf->db->character_set)) {
69
+            $this->forcecharset=$conf->db->character_set;
70
+        }
71
+        if (! empty($conf->db->dolibarr_main_db_collation)) {
72
+            $this->forcecollate=$conf->db->dolibarr_main_db_collation;
73
+        }
70 74
 
71 75
         $this->database_user=$user;
72 76
         $this->database_host=$host;
@@ -117,18 +121,23 @@  discard block
 block discarded – undo
117 121
 
118 122
                 // If client is old latin, we force utf8
119 123
                 $clientmustbe=empty($conf->db->dolibarr_main_db_character_set)?'utf8':$conf->db->dolibarr_main_db_character_set;
120
-                if (preg_match('/latin1/', $clientmustbe)) $clientmustbe='utf8';
124
+                if (preg_match('/latin1/', $clientmustbe)) {
125
+                    $clientmustbe='utf8';
126
+                }
121 127
 
122 128
 				if ($this->db->character_set_name() != $clientmustbe) {
123 129
 					$this->db->set_charset($clientmustbe);	// This set charset, but with a bad collation
124 130
 
125 131
 					$collation = $conf->db->dolibarr_main_db_collation;
126
-					if (preg_match('/latin1/', $collation)) $collation='utf8_unicode_ci';
132
+					if (preg_match('/latin1/', $collation)) {
133
+					    $collation='utf8_unicode_ci';
134
+					}
127 135
 
128
-					if (! preg_match('/general/', $collation)) $this->db->query("SET collation_connection = ".$collation);
136
+					if (! preg_match('/general/', $collation)) {
137
+					    $this->db->query("SET collation_connection = ".$collation);
138
+					}
129 139
 				}
130
-            }
131
-            else
140
+            } else
132 141
             {
133 142
                 $this->database_selected = false;
134 143
                 $this->database_name = '';
@@ -136,8 +145,7 @@  discard block
 block discarded – undo
136 145
                 $this->error=$this->error();
137 146
                 dol_syslog(get_class($this)."::DoliDBMysqli : Select_db error ".$this->error,LOG_ERR);
138 147
             }
139
-        }
140
-        else
148
+        } else
141 149
         {
142 150
             // Pas de selection de base demandee, ok ou ko
143 151
             $this->database_selected = false;
@@ -146,15 +154,21 @@  discard block
 block discarded – undo
146 154
             {
147 155
             	// If client is old latin, we force utf8
148 156
             	$clientmustbe=empty($conf->db->dolibarr_main_db_character_set)?'utf8':$conf->db->dolibarr_main_db_character_set;
149
-            	if (preg_match('/latin1/', $clientmustbe)) $clientmustbe='utf8';
157
+            	if (preg_match('/latin1/', $clientmustbe)) {
158
+            	    $clientmustbe='utf8';
159
+            	}
150 160
 
151 161
 				if ($this->db->character_set_name() != $clientmustbe) {
152 162
 					$this->db->set_charset($clientmustbe);	// This set utf8_general_ci
153 163
 
154 164
 					$collation = $conf->db->dolibarr_main_db_collation;
155
-					if (preg_match('/latin1/', $collation)) $collation='utf8_unicode_ci';
165
+					if (preg_match('/latin1/', $collation)) {
166
+					    $collation='utf8_unicode_ci';
167
+					}
156 168
 
157
-					if (! preg_match('/general/', $collation)) $this->db->query("SET collation_connection = ".$collation);
169
+					if (! preg_match('/general/', $collation)) {
170
+					    $this->db->query("SET collation_connection = ".$collation);
171
+					}
158 172
 				}
159 173
 			}
160 174
         }
@@ -240,7 +254,9 @@  discard block
 block discarded – undo
240 254
     {
241 255
         if ($this->db)
242 256
         {
243
-	        if ($this->transaction_opened > 0) dol_syslog(get_class($this)."::close Closing a connection with an opened transaction depth=".$this->transaction_opened,LOG_ERR);
257
+	        if ($this->transaction_opened > 0) {
258
+	            dol_syslog(get_class($this)."::close Closing a connection with an opened transaction depth=".$this->transaction_opened,LOG_ERR);
259
+	        }
244 260
             $this->connected=false;
245 261
             return $this->db->close();
246 262
         }
@@ -264,14 +280,15 @@  discard block
 block discarded – undo
264 280
 
265 281
         Debug::addMessage('SQL', 'MySQL: ' . $query);
266 282
 
267
-        if (! in_array($query,array('BEGIN','COMMIT','ROLLBACK'))) dol_syslog('sql='.$query, LOG_DEBUG);
283
+        if (! in_array($query,array('BEGIN','COMMIT','ROLLBACK'))) {
284
+            dol_syslog('sql='.$query, LOG_DEBUG);
285
+        }
268 286
 
269 287
         if (! $this->database_name)
270 288
         {
271 289
             // Ordre SQL ne necessitant pas de connexion a une base (exemple: CREATE DATABASE)
272 290
             $ret = $this->db->query($query);
273
-        }
274
-        else
291
+        } else
275 292
         {
276 293
             $ret = $this->db->query($query);
277 294
         }
@@ -285,7 +302,10 @@  discard block
 block discarded – undo
285 302
                 $this->lasterror = $this->error();
286 303
                 $this->lasterrno = $this->errno();
287 304
 
288
-				if ($conf->global->SYSLOG_LEVEL < LOG_DEBUG) dol_syslog(get_class($this)."::query SQL Error query: ".$query, LOG_ERR);	// Log of request was not yet done previously
305
+				if ($conf->global->SYSLOG_LEVEL < LOG_DEBUG) {
306
+				    dol_syslog(get_class($this)."::query SQL Error query: ".$query, LOG_ERR);
307
+				}
308
+				// Log of request was not yet done previously
289 309
                 dol_syslog(get_class($this)."::query SQL Error message: ".$this->lasterrno." ".$this->lasterror, LOG_ERR);
290 310
             }
291 311
             $this->lastquery=$query;
@@ -341,8 +361,7 @@  discard block
 block discarded – undo
341 361
         {
342 362
             if (! is_object($resultset)) { $resultset=$this->_results; }
343 363
             return $resultset->fetch_row();
344
-        }
345
-        else
364
+        } else
346 365
         {
347 366
             // si le curseur est un booleen on retourne la valeur 0
348 367
             return 0;
@@ -395,7 +414,9 @@  discard block
 block discarded – undo
395 414
         // If resultset not provided, we take the last used by connexion
396 415
         if (! is_object($resultset)) { $resultset=$this->_results; }
397 416
         // Si resultset en est un, on libere la memoire
398
-        if (is_object($resultset)) $resultset->free_result();
417
+        if (is_object($resultset)) {
418
+            $resultset->free_result();
419
+        }
399 420
     }
400 421
 
401 422
     /**
@@ -470,8 +491,7 @@  discard block
 block discarded – undo
470 491
         if (! $this->connected) {
471 492
             // Si il y a eu echec de connexion, $this->db n'est pas valide pour mysqli_error.
472 493
             return 'Not connected. Check setup parameters in conf/conf.php file and your mysql client and server versions';
473
-        }
474
-        else {
494
+        } else {
475 495
             return $this->db->error;
476 496
         }
477 497
     }
@@ -516,8 +536,7 @@  discard block
 block discarded – undo
516 536
             if ($cryptType == 2)
517 537
             {
518 538
                 $return = 'AES_ENCRYPT('.$return.',\''.$cryptKey.'\')';
519
-            }
520
-            else if ($cryptType == 1)
539
+            } else if ($cryptType == 1)
521 540
             {
522 541
                 $return = 'DES_ENCRYPT('.$return.',\''.$cryptKey.'\')';
523 542
             }
@@ -549,8 +568,7 @@  discard block
 block discarded – undo
549 568
             if ($cryptType == 2)
550 569
             {
551 570
                 $return = 'AES_DECRYPT('.$value.',\''.$cryptKey.'\')';
552
-            }
553
-            else if ($cryptType == 1)
571
+            } else if ($cryptType == 1)
554 572
             {
555 573
                 $return = 'DES_DECRYPT('.$value.',\''.$cryptKey.'\')';
556 574
             }
@@ -574,8 +592,9 @@  discard block
 block discarded – undo
574 592
         {
575 593
             $row=$this->fetch_row($resql);
576 594
             return $row[0];
577
-        }
578
-        else return '?';
595
+        } else {
596
+            return '?';
597
+        }
579 598
     }
580 599
 
581 600
     // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
@@ -593,8 +612,12 @@  discard block
 block discarded – undo
593 612
     function DDLCreateDb($database,$charset='',$collation='',$owner='')
594 613
     {
595 614
         // phpcs:enable
596
-        if (empty($charset))   $charset=$this->forcecharset;
597
-        if (empty($collation)) $collation=$this->forcecollate;
615
+        if (empty($charset)) {
616
+            $charset=$this->forcecharset;
617
+        }
618
+        if (empty($collation)) {
619
+            $collation=$this->forcecollate;
620
+        }
598 621
 
599 622
         // ALTER DATABASE dolibarr_db DEFAULT CHARACTER SET latin DEFAULT COLLATE latin1_swedish_ci
600 623
 		$sql = "CREATE DATABASE `".$this->escape($database)."`";
@@ -626,7 +649,9 @@  discard block
 block discarded – undo
626 649
         $listtables=array();
627 650
 
628 651
         $like = '';
629
-        if ($table) $like = "LIKE '".$table."'";
652
+        if ($table) {
653
+            $like = "LIKE '".$table."'";
654
+        }
630 655
         $sql="SHOW TABLES FROM ".$database." ".$like.";";
631 656
         //print $sql;
632 657
         $result = $this->query($sql);
@@ -702,8 +727,7 @@  discard block
 block discarded – undo
702 727
 			{
703 728
 				if ((preg_match("/null/i",$field_desc['default'])) || (preg_match("/CURRENT_TIMESTAMP/i",$field_desc['default']))) {
704 729
 					$sqlfields[$i]  .= " default ".$field_desc['default'];
705
-				}
706
-				else {
730
+				} else {
707 731
 					$sqlfields[$i]  .= " default '".$field_desc['default']."'";
708 732
 				}
709 733
 			}
@@ -715,8 +739,9 @@  discard block
 block discarded – undo
715 739
 			}
716 740
             $i++;
717 741
         }
718
-        if($primary_key != "")
719
-        $pk = "primary key(".$primary_key.")";
742
+        if($primary_key != "") {
743
+                $pk = "primary key(".$primary_key.")";
744
+        }
720 745
 
721 746
         if(is_array($unique_keys)) {
722 747
             $i = 0;
@@ -736,18 +761,22 @@  discard block
 block discarded – undo
736 761
             }
737 762
         }
738 763
         $sql .= implode(',',$sqlfields);
739
-        if($primary_key != "")
740
-        $sql .= ",".$pk;
741
-        if($unique_keys != "")
742
-        $sql .= ",".implode(',',$sqluq);
743
-        if(is_array($keys))
744
-        $sql .= ",".implode(',',$sqlk);
764
+        if($primary_key != "") {
765
+                $sql .= ",".$pk;
766
+        }
767
+        if($unique_keys != "") {
768
+                $sql .= ",".implode(',',$sqluq);
769
+        }
770
+        if(is_array($keys)) {
771
+                $sql .= ",".implode(',',$sqlk);
772
+        }
745 773
         $sql .=") engine=".$type;
746 774
 
747
-        if(! $this->query($sql))
748
-        return -1;
749
-        else
750
-        return 1;
775
+        if(! $this->query($sql)) {
776
+                return -1;
777
+        } else {
778
+                return 1;
779
+        }
751 780
     }
752 781
 
753 782
     // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
@@ -762,10 +791,11 @@  discard block
 block discarded – undo
762 791
         // phpcs:enable
763 792
         $sql = "DROP TABLE ".$table;
764 793
 
765
-		if (! $this->query($sql))
766
- 			return -1;
767
-    	else
768
-    		return 1;
794
+		if (! $this->query($sql)) {
795
+		 			return -1;
796
+		} else {
797
+    	    		return 1;
798
+    	}
769 799
     }
770 800
 
771 801
     // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
@@ -820,10 +850,11 @@  discard block
 block discarded – undo
820 850
         }
821 851
         if (isset($field_desc['default']) && preg_match("/^[^\s]/i",$field_desc['default']))
822 852
         {
823
-            if(preg_match("/null/i",$field_desc['default']))
824
-            $sql.= " default ".$field_desc['default'];
825
-            else
826
-            $sql.= " default '".$field_desc['default']."'";
853
+            if(preg_match("/null/i",$field_desc['default'])) {
854
+                        $sql.= " default ".$field_desc['default'];
855
+            } else {
856
+                        $sql.= " default '".$field_desc['default']."'";
857
+            }
827 858
         }
828 859
         if (isset($field_desc['extra']) && preg_match("/^[^\s]/i",$field_desc['extra']))
829 860
         {
@@ -862,8 +893,7 @@  discard block
 block discarded – undo
862 893
         	{
863 894
         		$sqlbis="UPDATE ".$table." SET ".$field_name." = '".$this->escape($field_desc['default'] ? $field_desc['default'] : '')."' WHERE ".$field_name." IS NULL";
864 895
         		$this->query($sqlbis);
865
-        	}
866
-        	elseif ($field_desc['type'] == 'tinyint' || $field_desc['type'] == 'int')
896
+        	} elseif ($field_desc['type'] == 'tinyint' || $field_desc['type'] == 'int')
867 897
         	{
868 898
         		$sqlbis="UPDATE ".$table." SET ".$field_name." = ".((int) $this->escape($field_desc['default'] ? $field_desc['default'] : 0))." WHERE ".$field_name." IS NULL";
869 899
         		$this->query($sqlbis);
@@ -874,15 +904,20 @@  discard block
 block discarded – undo
874 904
 
875 905
         if ($field_desc['default'] != '')
876 906
         {
877
-			if ($field_desc['type'] == 'double' || $field_desc['type'] == 'tinyint' || $field_desc['type'] == 'int') $sql.=" DEFAULT ".$this->escape($field_desc['default']);
878
-        	elseif ($field_desc['type'] == 'text') $sql.=" DEFAULT '".$this->escape($field_desc['default'])."'";							// Default not supported on text fields
907
+			if ($field_desc['type'] == 'double' || $field_desc['type'] == 'tinyint' || $field_desc['type'] == 'int') {
908
+			    $sql.=" DEFAULT ".$this->escape($field_desc['default']);
909
+			} elseif ($field_desc['type'] == 'text') {
910
+        	    $sql.=" DEFAULT '".$this->escape($field_desc['default'])."'";
911
+        	}
912
+        	// Default not supported on text fields
879 913
         }
880 914
 
881 915
         dol_syslog(get_class($this)."::DDLUpdateField ".$sql,LOG_DEBUG);
882
-        if (! $this->query($sql))
883
-        return -1;
884
-        else
885
-        return 1;
916
+        if (! $this->query($sql)) {
917
+                return -1;
918
+        } else {
919
+                return 1;
920
+        }
886 921
     }
887 922
 
888 923
     // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
@@ -927,8 +962,7 @@  discard block
 block discarded – undo
927 962
             if ($this->lasterrno != 'DB_ERROR_USER_ALREADY_EXISTS')
928 963
             {
929 964
             	return -1;
930
-            }
931
-            else
965
+            } else
932 966
 			{
933 967
             	// If user already exists, we continue to set permissions
934 968
             	dol_syslog(get_class($this)."::DDLCreateUser sql=".$sql, LOG_WARNING);
@@ -1095,11 +1129,15 @@  discard block
 block discarded – undo
1095 1129
         $result=array();
1096 1130
 
1097 1131
         $sql='SHOW VARIABLES';
1098
-        if ($filter) $sql.=" LIKE '".$this->escape($filter)."'";
1132
+        if ($filter) {
1133
+            $sql.=" LIKE '".$this->escape($filter)."'";
1134
+        }
1099 1135
         $resql=$this->query($sql);
1100 1136
         if ($resql)
1101 1137
         {
1102
-        	while($obj=$this->fetch_object($resql)) $result[$obj->Variable_name]=$obj->Value;
1138
+        	while($obj=$this->fetch_object($resql)) {
1139
+        	    $result[$obj->Variable_name]=$obj->Value;
1140
+        	}
1103 1141
         }
1104 1142
 
1105 1143
         return $result;
@@ -1116,11 +1154,15 @@  discard block
 block discarded – undo
1116 1154
         $result=array();
1117 1155
 
1118 1156
         $sql='SHOW STATUS';
1119
-        if ($filter) $sql.=" LIKE '".$this->escape($filter)."'";
1157
+        if ($filter) {
1158
+            $sql.=" LIKE '".$this->escape($filter)."'";
1159
+        }
1120 1160
         $resql=$this->query($sql);
1121 1161
         if ($resql)
1122 1162
         {
1123
-            while($obj=$this->fetch_object($resql)) $result[$obj->Variable_name]=$obj->Value;
1163
+            while($obj=$this->fetch_object($resql)) {
1164
+                $result[$obj->Variable_name]=$obj->Value;
1165
+            }
1124 1166
         }
1125 1167
 
1126 1168
         return $result;
Please login to merge, or discard this patch.
dolibarr/htdocs/core/db/pgsql.class.php 1 patch
Braces   +164 added lines, -100 removed lines patch added patch discarded remove patch
@@ -74,8 +74,12 @@  discard block
 block discarded – undo
74 74
 		global $conf,$langs;
75 75
 
76 76
         // Note that having "static" property for "$forcecharset" and "$forcecollate" will make error here in strict mode, so they are not static
77
-		if (! empty($conf->db->character_set)) $this->forcecharset=$conf->db->character_set;
78
-		if (! empty($conf->db->dolibarr_main_db_collation))	$this->forcecollate=$conf->db->dolibarr_main_db_collation;
77
+		if (! empty($conf->db->character_set)) {
78
+		    $this->forcecharset=$conf->db->character_set;
79
+		}
80
+		if (! empty($conf->db->dolibarr_main_db_collation)) {
81
+		    $this->forcecollate=$conf->db->dolibarr_main_db_collation;
82
+		}
79 83
 
80 84
 		$this->database_user=$user;
81 85
         $this->database_host=$host;
@@ -111,8 +115,7 @@  discard block
 block discarded – undo
111 115
 		{
112 116
 			$this->connected = true;
113 117
 			$this->ok = true;
114
-		}
115
-		else
118
+		} else
116 119
 		{
117 120
 			// host, login ou password incorrect
118 121
 			$this->connected = false;
@@ -129,8 +132,7 @@  discard block
 block discarded – undo
129 132
 				$this->database_selected = true;
130 133
 				$this->database_name = $name;
131 134
 				$this->ok = true;
132
-			}
133
-			else
135
+			} else
134 136
 			{
135 137
 				$this->database_selected = false;
136 138
 				$this->database_name = '';
@@ -138,8 +140,7 @@  discard block
 block discarded – undo
138 140
 				$this->error=$this->error();
139 141
 				dol_syslog(get_class($this)."::DoliDBPgsql : Erreur Select_db ".$this->error,LOG_ERR);
140 142
 			}
141
-		}
142
-		else
143
+		} else
143 144
 		{
144 145
 			// Pas de selection de base demandee, ok ou ko
145 146
 			$this->database_selected = false;
@@ -179,9 +180,13 @@  discard block
 block discarded – undo
179 180
 
180 181
 		    if ($type == 'auto')
181 182
 		    {
182
-              if (preg_match('/ALTER TABLE/i',$line)) $type='dml';
183
-              else if (preg_match('/CREATE TABLE/i',$line)) $type='dml';
184
-              else if (preg_match('/DROP TABLE/i',$line)) $type='dml';
183
+              if (preg_match('/ALTER TABLE/i',$line)) {
184
+                  $type='dml';
185
+              } else if (preg_match('/CREATE TABLE/i',$line)) {
186
+                  $type='dml';
187
+              } else if (preg_match('/DROP TABLE/i',$line)) {
188
+                  $type='dml';
189
+              }
185 190
 		    }
186 191
 
187 192
     		$line=preg_replace('/ as signed\)/i',' as integer)',$line);
@@ -328,9 +333,11 @@  discard block
 block discarded – undo
328 333
 			// DELETE FROM tabletodelete USING tabletodelete, othertable -> DELETE FROM tabletodelete USING othertable
329 334
 			if (preg_match('/DELETE FROM ([a-z_]+) USING ([a-z_]+), ([a-z_]+)/i',$line,$reg))
330 335
 			{
331
-				if ($reg[1] == $reg[2])	// If same table, we remove second one
336
+				if ($reg[1] == $reg[2]) {
337
+				    // If same table, we remove second one
332 338
 				{
333
-					$line=preg_replace('/DELETE FROM ([a-z_]+) USING ([a-z_]+), ([a-z_]+)/i','DELETE FROM \\1 USING \\3', $line);
339
+					$line=preg_replace('/DELETE FROM ([a-z_]+) USING ([a-z_]+), ([a-z_]+)/i','DELETE FROM \\1 USING \\3', $line);
340
+				}
334 341
 				}
335 342
 			}
336 343
 
@@ -358,7 +365,9 @@  discard block
 block discarded – undo
358 365
 			// By default we do not (should be already done by db->escape function if required
359 366
 			// except for sql insert in data file that are mysql escaped so we removed them to
360 367
 			// be compatible with standard_conforming_strings=on that considers \ as ordinary character).
361
-			if ($unescapeslashquot) $line=preg_replace("/\\\'/","''",$line);
368
+			if ($unescapeslashquot) {
369
+			    $line=preg_replace("/\\\'/","''",$line);
370
+			}
362 371
 
363 372
 			//print "type=".$type." newline=".$line."<br>\n";
364 373
 		}
@@ -409,7 +418,10 @@  discard block
 block discarded – undo
409 418
 		$name = str_replace(array("\\", "'"), array("\\\\", "\\'"), $name);
410 419
 		$port = str_replace(array("\\", "'"), array("\\\\", "\\'"), $port);
411 420
 
412
-		if (! $name) $name="postgres";    // When try to connect using admin user
421
+		if (! $name) {
422
+		    $name="postgres";
423
+		}
424
+		// When try to connect using admin user
413 425
 
414 426
 		// try first Unix domain socket (local)
415 427
 		if ((! empty($host) && $host == "socket") && ! defined('NOLOCALSOCKETPGCONNECT'))
@@ -421,8 +433,12 @@  discard block
 block discarded – undo
421 433
 		// if local connection failed or not requested, use TCP/IP
422 434
 		if (! $this->db)
423 435
 		{
424
-		    if (! $host) $host = "localhost";
425
-			if (! $port) $port = 5432;
436
+		    if (! $host) {
437
+		        $host = "localhost";
438
+		    }
439
+			if (! $port) {
440
+			    $port = 5432;
441
+			}
426 442
 
427 443
 			$con_string = "host='".$host."' port='".$port."' dbname='".$name."' user='".$login."' password='".$passwd."'";
428 444
 			$this->db = @pg_connect($con_string);
@@ -475,7 +491,9 @@  discard block
 block discarded – undo
475 491
     {
476 492
         if ($this->db)
477 493
         {
478
-          if ($this->transaction_opened > 0) dol_syslog(get_class($this)."::close Closing a connection with an opened transaction depth=".$this->transaction_opened,LOG_ERR);
494
+          if ($this->transaction_opened > 0) {
495
+              dol_syslog(get_class($this)."::close Closing a connection with an opened transaction depth=".$this->transaction_opened,LOG_ERR);
496
+          }
479 497
           $this->connected=false;
480 498
           return pg_close($this->db);
481 499
         }
@@ -512,8 +530,9 @@  discard block
 block discarded – undo
512 530
 				{
513 531
 					$query=preg_replace('/([^\'])([0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9] [0-9][0-9]:[0-9][0-9]:[0-9][0-9])/','\\1\'\\2\'',$query);
514 532
 					dol_syslog("Warning: Bad formed request converted into ".$query,LOG_WARNING);
515
-				}
516
-				else $loop=false;
533
+				} else {
534
+				    $loop=false;
535
+				}
517 536
 			}
518 537
 		}
519 538
 
@@ -522,29 +541,38 @@  discard block
 block discarded – undo
522 541
 			@pg_query($this->db, 'SAVEPOINT mysavepoint');
523 542
 		}
524 543
 
525
-		if (! in_array($query,array('BEGIN','COMMIT','ROLLBACK'))) dol_syslog('sql='.$query, LOG_DEBUG);
544
+		if (! in_array($query,array('BEGIN','COMMIT','ROLLBACK'))) {
545
+		    dol_syslog('sql='.$query, LOG_DEBUG);
546
+		}
526 547
 
527 548
 		$ret = @pg_query($this->db, $query);
528 549
 
529 550
 		//print $query;
530
-		if (! preg_match("/^COMMIT/i",$query) && ! preg_match("/^ROLLBACK/i",$query)) // Si requete utilisateur, on la sauvegarde ainsi que son resultset
551
+		if (! preg_match("/^COMMIT/i",$query) && ! preg_match("/^ROLLBACK/i",$query)) {
552
+		    // Si requete utilisateur, on la sauvegarde ainsi que son resultset
531 553
 		{
532 554
 			if (! $ret)
533 555
 			{
534 556
 			    if ($this->errno() != 'DB_ERROR_25P02')	// Do not overwrite errors if this is a consecutive error
535 557
 			    {
536
-    				$this->lastqueryerror = $query;
558
+    				$this->lastqueryerror = $query;
559
+		}
537 560
     				$this->lasterror = $this->error();
538 561
     				$this->lasterrno = $this->errno();
539 562
 
540
-    				if ($conf->global->SYSLOG_LEVEL < LOG_DEBUG) dol_syslog(get_class($this)."::query SQL Error query: ".$query, LOG_ERR);	// Log of request was not yet done previously
563
+    				if ($conf->global->SYSLOG_LEVEL < LOG_DEBUG) {
564
+    				    dol_syslog(get_class($this)."::query SQL Error query: ".$query, LOG_ERR);
565
+    				}
566
+    				// Log of request was not yet done previously
541 567
 					dol_syslog(get_class($this)."::query SQL Error message: ".$this->lasterror." (".$this->lasterrno.")", LOG_ERR);
542 568
 					dol_syslog(get_class($this)."::query SQL Error usesavepoint = ".$usesavepoint, LOG_ERR);
543 569
 			    }
544 570
 
545
-				if ($usesavepoint && $this->transaction_opened)	// Warning, after that errno will be erased
571
+				if ($usesavepoint && $this->transaction_opened) {
572
+				    // Warning, after that errno will be erased
546 573
 				{
547
-					@pg_query($this->db, 'ROLLBACK TO SAVEPOINT mysavepoint');
574
+					@pg_query($this->db, 'ROLLBACK TO SAVEPOINT mysavepoint');
575
+				}
548 576
 				}
549 577
 			}
550 578
 			$this->lastquery=$query;
@@ -645,7 +673,9 @@  discard block
 block discarded – undo
645 673
         // If resultset not provided, we take the last used by connexion
646 674
 		if (! is_resource($resultset)) { $resultset=$this->_results; }
647 675
 		// Si resultset en est un, on libere la memoire
648
-		if (is_resource($resultset)) pg_free_result($resultset);
676
+		if (is_resource($resultset)) {
677
+		    pg_free_result($resultset);
678
+		}
649 679
 	}
650 680
 
651 681
 
@@ -659,10 +689,17 @@  discard block
 block discarded – undo
659 689
 	function plimit($limit=0,$offset=0)
660 690
 	{
661 691
 		global $conf;
662
-        if (empty($limit)) return "";
663
-		if ($limit < 0) $limit=$conf->liste_limit;
664
-		if ($offset > 0) return " LIMIT ".$limit." OFFSET ".$offset." ";
665
-		else return " LIMIT $limit ";
692
+        if (empty($limit)) {
693
+            return "";
694
+        }
695
+		if ($limit < 0) {
696
+		    $limit=$conf->liste_limit;
697
+		}
698
+		if ($offset > 0) {
699
+		    return " LIMIT ".$limit." OFFSET ".$offset." ";
700
+		} else {
701
+		    return " LIMIT $limit ";
702
+		}
666 703
 	}
667 704
 
668 705
 
@@ -712,8 +749,7 @@  discard block
 block discarded – undo
712 749
 		if (! $this->connected) {
713 750
 			// Si il y a eu echec de connexion, $this->db n'est pas valide.
714 751
 			return 'DB_ERROR_FAILED_TO_CONNECT';
715
-		}
716
-		else {
752
+		} else {
717 753
 			// Constants to convert error code to a generic Dolibarr error code
718 754
 			$errorcode_map = array(
719 755
 			1004 => 'DB_ERROR_CANNOT_CREATE',
@@ -874,8 +910,12 @@  discard block
 block discarded – undo
874 910
 	function DDLCreateDb($database,$charset='',$collation='',$owner='')
875 911
 	{
876 912
         // phpcs:enable
877
-	    if (empty($charset))   $charset=$this->forcecharset;
878
-		if (empty($collation)) $collation=$this->forcecollate;
913
+	    if (empty($charset)) {
914
+	        $charset=$this->forcecharset;
915
+	    }
916
+		if (empty($collation)) {
917
+		    $collation=$this->forcecollate;
918
+		}
879 919
 
880 920
 		// Test charset match LC_TYPE (pgsql error otherwise)
881 921
 		//print $charset.' '.setlocale(LC_CTYPE,'0'); exit;
@@ -900,7 +940,9 @@  discard block
 block discarded – undo
900 940
 		$listtables=array();
901 941
 
902 942
 		$like = '';
903
-		if ($table) $like = " AND table_name LIKE '".$table."'";
943
+		if ($table) {
944
+		    $like = " AND table_name LIKE '".$table."'";
945
+		}
904 946
 		$result = pg_query($this->db, "SELECT table_name FROM information_schema.tables WHERE table_schema = 'public'".$like." ORDER BY table_name");
905 947
         if ($result)
906 948
         {
@@ -980,26 +1022,27 @@  discard block
 block discarded – undo
980 1022
 		{
981 1023
 			$sqlfields[$i] = $field_name." ";
982 1024
 			$sqlfields[$i]  .= $field_desc['type'];
983
-			if( preg_match("/^[^\s]/i",$field_desc['value']))
984
-			$sqlfields[$i]  .= "(".$field_desc['value'].")";
985
-			else if( preg_match("/^[^\s]/i",$field_desc['attribute']))
986
-			$sqlfields[$i]  .= " ".$field_desc['attribute'];
987
-			else if( preg_match("/^[^\s]/i",$field_desc['default']))
1025
+			if( preg_match("/^[^\s]/i",$field_desc['value'])) {
1026
+						$sqlfields[$i]  .= "(".$field_desc['value'].")";
1027
+			} else if( preg_match("/^[^\s]/i",$field_desc['attribute'])) {
1028
+						$sqlfields[$i]  .= " ".$field_desc['attribute'];
1029
+			} else if( preg_match("/^[^\s]/i",$field_desc['default']))
988 1030
 			{
989
-				if(preg_match("/null/i",$field_desc['default']))
990
-				$sqlfields[$i]  .= " default ".$field_desc['default'];
991
-				else
992
-				$sqlfields[$i]  .= " default '".$field_desc['default']."'";
993
-			}
994
-			else if( preg_match("/^[^\s]/i",$field_desc['null']))
995
-			$sqlfields[$i]  .= " ".$field_desc['null'];
996
-
997
-			else if( preg_match("/^[^\s]/i",$field_desc['extra']))
998
-			$sqlfields[$i]  .= " ".$field_desc['extra'];
1031
+				if(preg_match("/null/i",$field_desc['default'])) {
1032
+								$sqlfields[$i]  .= " default ".$field_desc['default'];
1033
+				} else {
1034
+								$sqlfields[$i]  .= " default '".$field_desc['default']."'";
1035
+				}
1036
+			} else if( preg_match("/^[^\s]/i",$field_desc['null'])) {
1037
+						$sqlfields[$i]  .= " ".$field_desc['null'];
1038
+			} else if( preg_match("/^[^\s]/i",$field_desc['extra'])) {
1039
+						$sqlfields[$i]  .= " ".$field_desc['extra'];
1040
+			}
999 1041
 			$i++;
1000 1042
 		}
1001
-		if($primary_key != "")
1002
-		$pk = "primary key(".$primary_key.")";
1043
+		if($primary_key != "") {
1044
+				$pk = "primary key(".$primary_key.")";
1045
+		}
1003 1046
 
1004 1047
 		if(is_array($unique_keys))
1005 1048
 		{
@@ -1020,19 +1063,23 @@  discard block
 block discarded – undo
1020 1063
 			}
1021 1064
 		}
1022 1065
 		$sql .= implode(',',$sqlfields);
1023
-		if($primary_key != "")
1024
-		$sql .= ",".$pk;
1025
-		if(is_array($unique_keys))
1026
-		$sql .= ",".implode(',',$sqluq);
1027
-		if(is_array($keys))
1028
-		$sql .= ",".implode(',',$sqlk);
1066
+		if($primary_key != "") {
1067
+				$sql .= ",".$pk;
1068
+		}
1069
+		if(is_array($unique_keys)) {
1070
+				$sql .= ",".implode(',',$sqluq);
1071
+		}
1072
+		if(is_array($keys)) {
1073
+				$sql .= ",".implode(',',$sqlk);
1074
+		}
1029 1075
 		$sql .=") type=".$type;
1030 1076
 
1031 1077
 		dol_syslog($sql,LOG_DEBUG);
1032
-		if(! $this->query($sql))
1033
-		return -1;
1034
-		else
1035
-		return 1;
1078
+		if(! $this->query($sql)) {
1079
+				return -1;
1080
+		} else {
1081
+				return 1;
1082
+		}
1036 1083
 	}
1037 1084
 
1038 1085
     // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
@@ -1047,10 +1094,11 @@  discard block
 block discarded – undo
1047 1094
         // phpcs:enable
1048 1095
 		$sql = "DROP TABLE ".$table;
1049 1096
 
1050
-		if (! $this->query($sql))
1051
-			return -1;
1052
-		else
1053
-			return 1;
1097
+		if (! $this->query($sql)) {
1098
+					return -1;
1099
+		} else {
1100
+					return 1;
1101
+		}
1054 1102
 	}
1055 1103
 
1056 1104
     // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
@@ -1092,7 +1140,9 @@  discard block
 block discarded – undo
1092 1140
         // phpcs:enable
1093 1141
 		$sql ="SELECT attname FROM pg_attribute, pg_type WHERE typname = '".$table."' AND attrelid = typrelid";
1094 1142
 		$sql.=" AND attname NOT IN ('cmin', 'cmax', 'ctid', 'oid', 'tableoid', 'xmin', 'xmax')";
1095
-		if ($field) $sql.= " AND attname = '".$field."'";
1143
+		if ($field) {
1144
+		    $sql.= " AND attname = '".$field."'";
1145
+		}
1096 1146
 
1097 1147
 		dol_syslog($sql,LOG_DEBUG);
1098 1148
 		$this->_results = $this->query($sql);
@@ -1116,27 +1166,33 @@  discard block
 block discarded – undo
1116 1166
 		// ex. : $field_desc = array('type'=>'int','value'=>'11','null'=>'not null','extra'=> 'auto_increment');
1117 1167
 		$sql= "ALTER TABLE ".$table." ADD ".$field_name." ";
1118 1168
 		$sql .= $field_desc['type'];
1119
-		if (preg_match("/^[^\s]/i",$field_desc['value']))
1120
-		    if (! in_array($field_desc['type'],array('int','date','datetime')))
1169
+		if (preg_match("/^[^\s]/i",$field_desc['value'])) {
1170
+				    if (! in_array($field_desc['type'],array('int','date','datetime')))
1121 1171
 		    {
1122
-		        $sql.= "(".$field_desc['value'].")";
1172
+		        $sql.= "(".$field_desc['value'].")";
1173
+		}
1123 1174
 		    }
1124
-		if (preg_match("/^[^\s]/i",$field_desc['attribute']))
1125
-            $sql .= " ".$field_desc['attribute'];
1126
-		if (preg_match("/^[^\s]/i",$field_desc['null']))
1127
-            $sql .= " ".$field_desc['null'];
1128
-		if (preg_match("/^[^\s]/i",$field_desc['default']))
1129
-            if (preg_match("/null/i",$field_desc['default']))
1130
-                $sql .= " default ".$field_desc['default'];
1131
-		    else
1132
-                $sql .= " default '".$field_desc['default']."'";
1133
-		if (preg_match("/^[^\s]/i",$field_desc['extra']))
1134
-            $sql .= " ".$field_desc['extra'];
1175
+		if (preg_match("/^[^\s]/i",$field_desc['attribute'])) {
1176
+		            $sql .= " ".$field_desc['attribute'];
1177
+		}
1178
+		if (preg_match("/^[^\s]/i",$field_desc['null'])) {
1179
+		            $sql .= " ".$field_desc['null'];
1180
+		}
1181
+		if (preg_match("/^[^\s]/i",$field_desc['default'])) {
1182
+		            if (preg_match("/null/i",$field_desc['default']))
1183
+                $sql .= " default ".$field_desc['default'];
1184
+		} else {
1185
+		                    $sql .= " default '".$field_desc['default']."'";
1186
+		    }
1187
+		if (preg_match("/^[^\s]/i",$field_desc['extra'])) {
1188
+		            $sql .= " ".$field_desc['extra'];
1189
+		}
1135 1190
 		$sql .= " ".$field_position;
1136 1191
 
1137 1192
 		dol_syslog($sql,LOG_DEBUG);
1138
-		if (!$this->query($sql))
1139
-            return -1;
1193
+		if (!$this->query($sql)) {
1194
+		            return -1;
1195
+		}
1140 1196
 		return 1;
1141 1197
 	}
1142 1198
 
@@ -1165,8 +1221,7 @@  discard block
 block discarded – undo
1165 1221
         	{
1166 1222
         		$sqlbis="UPDATE ".$table." SET ".$field_name." = '".$this->escape($field_desc['default'] ? $field_desc['default'] : '')."' WHERE ".$field_name." IS NULL";
1167 1223
         		$this->query($sqlbis);
1168
-        	}
1169
-        	elseif ($field_desc['type'] == 'tinyint' || $field_desc['type'] == 'int')
1224
+        	} elseif ($field_desc['type'] == 'tinyint' || $field_desc['type'] == 'int')
1170 1225
         	{
1171 1226
         		$sqlbis="UPDATE ".$table." SET ".$field_name." = ".((int) $this->escape($field_desc['default'] ? $field_desc['default'] : 0))." WHERE ".$field_name." IS NULL";
1172 1227
         		$this->query($sqlbis);
@@ -1175,13 +1230,18 @@  discard block
 block discarded – undo
1175 1230
 
1176 1231
 		if ($field_desc['default'] != '')
1177 1232
 		{
1178
-			if ($field_desc['type'] == 'double' || $field_desc['type'] == 'tinyint' || $field_desc['type'] == 'int') $sql.=" DEFAULT ".$this->escape($field_desc['default']);
1179
-        	elseif ($field_desc['type'] == 'text') $sql.=" DEFAULT '".$this->escape($field_desc['default'])."'";							// Default not supported on text fields
1233
+			if ($field_desc['type'] == 'double' || $field_desc['type'] == 'tinyint' || $field_desc['type'] == 'int') {
1234
+			    $sql.=" DEFAULT ".$this->escape($field_desc['default']);
1235
+			} elseif ($field_desc['type'] == 'text') {
1236
+        	    $sql.=" DEFAULT '".$this->escape($field_desc['default'])."'";
1237
+        	}
1238
+        	// Default not supported on text fields
1180 1239
 		}
1181 1240
 
1182 1241
 		dol_syslog($sql,LOG_DEBUG);
1183
-		if (! $this->query($sql))
1184
-			return -1;
1242
+		if (! $this->query($sql)) {
1243
+					return -1;
1244
+		}
1185 1245
 		return 1;
1186 1246
 	}
1187 1247
 
@@ -1218,8 +1278,9 @@  discard block
 block discarded – undo
1218 1278
 		{
1219 1279
             $liste=$this->fetch_array($resql);
1220 1280
 		    return $liste['server_encoding'];
1221
-		}
1222
-		else return '';
1281
+		} else {
1282
+		    return '';
1283
+		}
1223 1284
 	}
1224 1285
 
1225 1286
 	/**
@@ -1259,8 +1320,9 @@  discard block
 block discarded – undo
1259 1320
 		{
1260 1321
 		    $liste=$this->fetch_array($resql);
1261 1322
 			return $liste['lc_collate'];
1262
-		}
1263
-		else return '';
1323
+		} else {
1324
+		    return '';
1325
+		}
1264 1326
 	}
1265 1327
 
1266 1328
 	/**
@@ -1299,8 +1361,7 @@  discard block
 block discarded – undo
1299 1361
 		if (file_exists('/usr/bin/pg_dump'))
1300 1362
 		{
1301 1363
 		    $fullpathofdump='/usr/bin/pg_dump';
1302
-		}
1303
-		else
1364
+		} else
1304 1365
 		{
1305 1366
             // TODO L'utilisateur de la base doit etre un superadmin pour lancer cette commande
1306 1367
 		    $resql=$this->query('SHOW data_directory');
@@ -1330,8 +1391,7 @@  discard block
 block discarded – undo
1330 1391
         if (file_exists('/usr/bin/'.$tool))
1331 1392
         {
1332 1393
             $fullpathofdump='/usr/bin/'.$tool;
1333
-        }
1334
-        else
1394
+        } else
1335 1395
         {
1336 1396
             // TODO L'utilisateur de la base doit etre un superadmin pour lancer cette commande
1337 1397
             $resql=$this->query('SHOW data_directory');
@@ -1357,11 +1417,15 @@  discard block
 block discarded – undo
1357 1417
 		$result=array();
1358 1418
 
1359 1419
 		$resql='select name,setting from pg_settings';
1360
-		if ($filter) $resql.=" WHERE name = '".$this->escape($filter)."'";
1420
+		if ($filter) {
1421
+		    $resql.=" WHERE name = '".$this->escape($filter)."'";
1422
+		}
1361 1423
 		$resql=$this->query($resql);
1362 1424
 		if ($resql)
1363 1425
 		{
1364
-			while ($obj=$this->fetch_object($resql)) $result[$obj->name]=$obj->setting;
1426
+			while ($obj=$this->fetch_object($resql)) {
1427
+			    $result[$obj->name]=$obj->setting;
1428
+			}
1365 1429
 		}
1366 1430
 
1367 1431
 		return $result;
Please login to merge, or discard this patch.