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
+        }