Completed
Push — master ( 92be1d...474014 )
by cam
04:25
created
ecrire/req/sqlite_generique.php 1 patch
Spacing   +91 added lines, -91 removed lines patch added patch discarded remove patch
@@ -64,27 +64,27 @@  discard block
 block discarded – undo
64 64
 	// determiner le dossier de la base : $addr ou _DIR_DB
65 65
 	$f = _DIR_DB;
66 66
 	if ($addr and strpos($addr, '/') !== false) {
67
-		$f = rtrim($addr, '/') . '/';
67
+		$f = rtrim($addr, '/').'/';
68 68
 	}
69 69
 
70 70
 	// un nom de base demande et impossible d'obtenir la base, on s'en va :
71 71
 	// il faut que la base existe ou que le repertoire parent soit writable
72
-	if ($db and !is_file($f .= $db . '.sqlite') and !is_writable(dirname($f))) {
73
-		spip_log("base $f non trouvee ou droits en ecriture manquants", 'sqlite.' . _LOG_HS);
72
+	if ($db and !is_file($f .= $db.'.sqlite') and !is_writable(dirname($f))) {
73
+		spip_log("base $f non trouvee ou droits en ecriture manquants", 'sqlite.'._LOG_HS);
74 74
 
75 75
 		return false;
76 76
 	}
77 77
 
78 78
 	// charger les modules sqlite au besoin
79 79
 	if (!_sqlite_charger_version($sqlite_version)) {
80
-		spip_log("Impossible de trouver/charger le module SQLite ($sqlite_version)!", 'sqlite.' . _LOG_HS);
80
+		spip_log("Impossible de trouver/charger le module SQLite ($sqlite_version)!", 'sqlite.'._LOG_HS);
81 81
 
82 82
 		return false;
83 83
 	}
84 84
 
85 85
 	// chargement des constantes
86 86
 	// il ne faut pas definir les constantes avant d'avoir charge les modules sqlite
87
-	$define = "spip_sqlite" . $sqlite_version . "_constantes";
87
+	$define = "spip_sqlite".$sqlite_version."_constantes";
88 88
 	$define();
89 89
 
90 90
 	$ok = false;
@@ -92,8 +92,8 @@  discard block
 block discarded – undo
92 92
 		// si pas de db ->
93 93
 		// base temporaire tant qu'on ne connait pas son vrai nom
94 94
 		// pour tester la connexion
95
-		$db = "_sqlite" . $sqlite_version . "_install";
96
-		$tmp = _DIR_DB . $db . ".sqlite";
95
+		$db = "_sqlite".$sqlite_version."_install";
96
+		$tmp = _DIR_DB.$db.".sqlite";
97 97
 		$ok = $link = new \PDO("sqlite:$tmp");
98 98
 	} else {
99 99
 		// Ouvrir (eventuellement creer la base)
@@ -102,7 +102,7 @@  discard block
 block discarded – undo
102 102
 
103 103
 	if (!$ok) {
104 104
 		$e = _sqlite_last_error_from_link($link);
105
-		spip_log("Impossible d'ouvrir la base SQLite($sqlite_version) $f : $e", 'sqlite.' . _LOG_HS);
105
+		spip_log("Impossible d'ouvrir la base SQLite($sqlite_version) $f : $e", 'sqlite.'._LOG_HS);
106 106
 
107 107
 		return false;
108 108
 	}
@@ -188,7 +188,7 @@  discard block
 block discarded – undo
188 188
 		$table = $regs[3];
189 189
 		$suite = $regs[4];
190 190
 	} else {
191
-		spip_log("SQLite : Probleme de ALTER TABLE mal forme dans $query", 'sqlite.' . _LOG_ERREUR);
191
+		spip_log("SQLite : Probleme de ALTER TABLE mal forme dans $query", 'sqlite.'._LOG_ERREUR);
192 192
 
193 193
 		return false;
194 194
 	}
@@ -205,7 +205,7 @@  discard block
 block discarded – undo
205 205
 	$i = 0;
206 206
 	$ouverte = false;
207 207
 	while ($do = array_shift($todo)) {
208
-		$todo2[$i] = isset($todo2[$i]) ? $todo2[$i] . "," . $do : $do;
208
+		$todo2[$i] = isset($todo2[$i]) ? $todo2[$i].",".$do : $do;
209 209
 		$o = (false !== strpos($do, "("));
210 210
 		$f = (false !== strpos($do, ")"));
211 211
 		if ($o and !$f) {
@@ -229,7 +229,7 @@  discard block
 block discarded – undo
229 229
 			. ')\s*([^\s]*)\s*(.*)?/i', $do, $matches)
230 230
 		) {
231 231
 			spip_log("SQLite : Probleme de ALTER TABLE, utilisation non reconnue dans : $do \n(requete d'origine : $query)",
232
-				'sqlite.' . _LOG_ERREUR);
232
+				'sqlite.'._LOG_ERREUR);
233 233
 
234 234
 			return false;
235 235
 		}
@@ -316,10 +316,10 @@  discard block
 block discarded – undo
316 316
 
317 317
 			// pas geres en sqlite2
318 318
 			case 'RENAME':
319
-				$do = "RENAME TO" . substr($do, 6);
319
+				$do = "RENAME TO".substr($do, 6);
320 320
 			case 'RENAME TO':
321 321
 				if (!spip_sqlite::executer_requete("$debut $do", $serveur)) {
322
-					spip_log("SQLite : Erreur ALTER TABLE / RENAME : $query", 'sqlite.' . _LOG_ERREUR);
322
+					spip_log("SQLite : Erreur ALTER TABLE / RENAME : $query", 'sqlite.'._LOG_ERREUR);
323 323
 
324 324
 					return false;
325 325
 				}
@@ -360,7 +360,7 @@  discard block
 block discarded – undo
360 360
 						$colonnes = substr($colonne_origine, 1, -1);
361 361
 						if (false !== strpos(",", $colonnes)) {
362 362
 							spip_log("SQLite : Erreur, impossible de creer un index sur plusieurs colonnes"
363
-								. " sans qu'il ait de nom ($table, ($colonnes))", 'sqlite.' . _LOG_ERREUR);
363
+								. " sans qu'il ait de nom ($table, ($colonnes))", 'sqlite.'._LOG_ERREUR);
364 364
 							break;
365 365
 						} else {
366 366
 							$nom_index = $colonnes;
@@ -375,12 +375,12 @@  discard block
 block discarded – undo
375 375
 
376 376
 			// pas geres en sqlite2
377 377
 			case 'ADD COLUMN':
378
-				$do = "ADD" . substr($do, 10);
378
+				$do = "ADD".substr($do, 10);
379 379
 			case 'ADD':
380 380
 			default:
381 381
 				if (!preg_match(',primary\s+key,i', $do)) {
382 382
 					if (!spip_sqlite::executer_requete("$debut $do", $serveur)) {
383
-						spip_log("SQLite : Erreur ALTER TABLE / ADD : $query", 'sqlite.' . _LOG_ERREUR);
383
+						spip_log("SQLite : Erreur ALTER TABLE / ADD : $query", 'sqlite.'._LOG_ERREUR);
384 384
 
385 385
 						return false;
386 386
 					}
@@ -401,7 +401,7 @@  discard block
 block discarded – undo
401 401
 					}
402 402
 					$opts['field'] = array($colonne_ajoutee => $def);
403 403
 					if (!_sqlite_modifier_table($table, array($colonne_ajoutee), $opts, $serveur)) {
404
-						spip_log("SQLite : Erreur ALTER TABLE / ADD : $query", 'sqlite.' . _LOG_ERREUR);
404
+						spip_log("SQLite : Erreur ALTER TABLE / ADD : $query", 'sqlite.'._LOG_ERREUR);
405 405
 
406 406
 						return false;
407 407
 					}
@@ -409,10 +409,10 @@  discard block
 block discarded – undo
409 409
 				break;
410 410
 		}
411 411
 		// tout est bon, ouf !
412
-		spip_log("SQLite ($serveur) : Changements OK : $debut $do", 'sqlite.' . _LOG_INFO);
412
+		spip_log("SQLite ($serveur) : Changements OK : $debut $do", 'sqlite.'._LOG_INFO);
413 413
 	}
414 414
 
415
-	spip_log("SQLite ($serveur) : fin ALTER TABLE OK !", 'sqlite.' . _LOG_INFO);
415
+	spip_log("SQLite ($serveur) : fin ALTER TABLE OK !", 'sqlite.'._LOG_INFO);
416 416
 
417 417
 	return true;
418 418
 }
@@ -481,9 +481,9 @@  discard block
 block discarded – undo
481 481
  * @return bool true si la base est créee.
482 482
  **/
483 483
 function spip_sqlite_create_base($nom, $serveur = '', $option = true) {
484
-	$f = $nom . '.sqlite';
484
+	$f = $nom.'.sqlite';
485 485
 	if (strpos($nom, "/") === false) {
486
-		$f = _DIR_DB . $f;
486
+		$f = _DIR_DB.$f;
487 487
 	}
488 488
 
489 489
 	$ok = new \PDO("sqlite:$f");
@@ -522,12 +522,12 @@  discard block
 block discarded – undo
522 522
 	// vue deja presente
523 523
 	if (sql_showtable($nom, false, $serveur)) {
524 524
 		spip_log("Echec creation d'une vue sql ($nom) car celle-ci existe deja (serveur:$serveur)",
525
-			'sqlite.' . _LOG_ERREUR);
525
+			'sqlite.'._LOG_ERREUR);
526 526
 
527 527
 		return false;
528 528
 	}
529 529
 
530
-	$query = "CREATE VIEW $nom AS " . $query_select;
530
+	$query = "CREATE VIEW $nom AS ".$query_select;
531 531
 
532 532
 	return spip_sqlite_query($query, $serveur, $requeter);
533 533
 }
@@ -552,15 +552,15 @@  discard block
 block discarded – undo
552 552
  */
553 553
 function spip_sqlite_create_index($nom, $table, $champs, $unique = '', $serveur = '', $requeter = true) {
554 554
 	if (!($nom or $table or $champs)) {
555
-		spip_log("Champ manquant pour creer un index sqlite ($nom, $table, (" . join(',', $champs) . "))",
556
-			'sqlite.' . _LOG_ERREUR);
555
+		spip_log("Champ manquant pour creer un index sqlite ($nom, $table, (".join(',', $champs)."))",
556
+			'sqlite.'._LOG_ERREUR);
557 557
 
558 558
 		return false;
559 559
 	}
560 560
 
561 561
 	// SQLite ne differentie pas noms des index en fonction des tables
562 562
 	// il faut donc creer des noms uniques d'index pour une base sqlite
563
-	$nom = $table . '_' . $nom;
563
+	$nom = $table.'_'.$nom;
564 564
 	// enlever d'eventuelles parentheses deja presentes sur champs
565 565
 	if (!is_array($champs)) {
566 566
 		if ($champs[0] == "(") {
@@ -582,12 +582,12 @@  discard block
 block discarded – undo
582 582
 	} else {
583 583
 		/* simuler le IF EXISTS - version 2 et sqlite < 3.3a */
584 584
 		$a = spip_sqlite_showtable($table, $serveur);
585
-		if (isset($a['key']['KEY ' . $nom])) {
585
+		if (isset($a['key']['KEY '.$nom])) {
586 586
 			return true;
587 587
 		}
588 588
 	}
589 589
 
590
-	$query = "CREATE " . ($unique ? "UNIQUE " : "") . "INDEX$ifnotexists $nom ON $table (" . join(',', $champs) . ")";
590
+	$query = "CREATE ".($unique ? "UNIQUE " : "")."INDEX$ifnotexists $nom ON $table (".join(',', $champs).")";
591 591
 	$res = spip_sqlite_query($query, $serveur, $requeter);
592 592
 	if (!$requeter) {
593 593
 		return $res;
@@ -663,7 +663,7 @@  discard block
 block discarded – undo
663 663
 	$serveur = '',
664 664
 	$requeter = true
665 665
 ) {
666
-	$c = !$groupby ? '*' : ('DISTINCT ' . (is_string($groupby) ? $groupby : join(',', $groupby)));
666
+	$c = !$groupby ? '*' : ('DISTINCT '.(is_string($groupby) ? $groupby : join(',', $groupby)));
667 667
 	$r = spip_sqlite_select("COUNT($c)", $from, $where, '', '', '',
668 668
 		$having, $serveur, $requeter);
669 669
 	if ((is_resource($r) or is_object($r)) && $requeter) { // ressource : sqlite2, object : sqlite3
@@ -761,14 +761,14 @@  discard block
 block discarded – undo
761 761
  */
762 762
 function spip_sqlite_drop_index($nom, $table, $serveur = '', $requeter = true) {
763 763
 	if (!($nom or $table)) {
764
-		spip_log("Champ manquant pour supprimer un index sqlite ($nom, $table)", 'sqlite.' . _LOG_ERREUR);
764
+		spip_log("Champ manquant pour supprimer un index sqlite ($nom, $table)", 'sqlite.'._LOG_ERREUR);
765 765
 
766 766
 		return false;
767 767
 	}
768 768
 
769 769
 	// SQLite ne differentie pas noms des index en fonction des tables
770 770
 	// il faut donc creer des noms uniques d'index pour une base sqlite
771
-	$index = $table . '_' . $nom;
771
+	$index = $table.'_'.$nom;
772 772
 	$exist = " IF EXISTS";
773 773
 
774 774
 	$query = "DROP INDEX$exist $index";
@@ -800,7 +800,7 @@  discard block
 block discarded – undo
800 800
 	if ($s) {
801 801
 		$trace = debug_backtrace();
802 802
 		if ($trace[0]['function'] != "spip_sqlite_error") {
803
-			spip_log("$s - $query - " . sql_error_backtrace(), 'sqlite.' . _LOG_ERREUR);
803
+			spip_log("$s - $query - ".sql_error_backtrace(), 'sqlite.'._LOG_ERREUR);
804 804
 		}
805 805
 	}
806 806
 
@@ -847,14 +847,14 @@  discard block
 block discarded – undo
847 847
 		$t = $link->errorInfo();
848 848
 		$s = ltrim($t[0], '0'); // 00000 si pas d'erreur
849 849
 		if ($s) {
850
-			$s .= ' / ' . $t[1];
850
+			$s .= ' / '.$t[1];
851 851
 		} // ajoute l'erreur du moteur SQLite
852 852
 	} else {
853 853
 		$s = ": aucune ressource sqlite (link)";
854 854
 	}
855 855
 
856 856
 	if ($s) {
857
-		spip_log("Erreur sqlite $s", 'sqlite.' . _LOG_ERREUR);
857
+		spip_log("Erreur sqlite $s", 'sqlite.'._LOG_ERREUR);
858 858
 	}
859 859
 
860 860
 	return $s ? $s : 0;
@@ -878,7 +878,7 @@  discard block
 block discarded – undo
878 878
 	}
879 879
 
880 880
 	$query = spip_sqlite::traduire_requete($query, $serveur);
881
-	$query = 'EXPLAIN ' . $query;
881
+	$query = 'EXPLAIN '.$query;
882 882
 	if (!$requeter) {
883 883
 		return $query;
884 884
 	}
@@ -1038,7 +1038,7 @@  discard block
 block discarded – undo
1038 1038
  **/
1039 1039
 function spip_sqlite_insert($table, $champs, $valeurs, $desc = array(), $serveur = '', $requeter = true) {
1040 1040
 
1041
-	$query = "INSERT INTO $table " . ($champs ? "$champs VALUES $valeurs" : "DEFAULT VALUES");
1041
+	$query = "INSERT INTO $table ".($champs ? "$champs VALUES $valeurs" : "DEFAULT VALUES");
1042 1042
 	if ($r = spip_sqlite_query($query, $serveur, $requeter)) {
1043 1043
 		if (!$requeter) {
1044 1044
 			return $r;
@@ -1094,8 +1094,8 @@  discard block
 block discarded – undo
1094 1094
 
1095 1095
 	$cles = $valeurs = "";
1096 1096
 	if (count($couples)) {
1097
-		$cles = "(" . join(',', array_keys($couples)) . ")";
1098
-		$valeurs = "(" . join(',', $couples) . ")";
1097
+		$cles = "(".join(',', array_keys($couples)).")";
1098
+		$valeurs = "(".join(',', $couples).")";
1099 1099
 	}
1100 1100
 
1101 1101
 	return spip_sqlite_insert($table, $cles, $valeurs, $desc, $serveur, $requeter);
@@ -1155,11 +1155,11 @@  discard block
 block discarded – undo
1155 1155
 
1156 1156
 		$champs = $valeurs = "";
1157 1157
 		if (count($couples)) {
1158
-			$champs = "(" . join(',', array_keys($couples)) . ")";
1159
-			$valeurs = "(" . join(',', $couples) . ")";
1160
-			$query = $query_start . "$champs VALUES $valeurs";
1158
+			$champs = "(".join(',', array_keys($couples)).")";
1159
+			$valeurs = "(".join(',', $couples).")";
1160
+			$query = $query_start."$champs VALUES $valeurs";
1161 1161
 		} else {
1162
-			$query = $query_start . "DEFAULT VALUES";
1162
+			$query = $query_start."DEFAULT VALUES";
1163 1163
 		}
1164 1164
 
1165 1165
 		if ($requeter) {
@@ -1291,7 +1291,7 @@  discard block
 block discarded – undo
1291 1291
  * @return string       Texte de sélection pour la requête
1292 1292
  */
1293 1293
 function spip_sqlite_multi($objet, $lang) {
1294
-	$r = "EXTRAIRE_MULTI(" . $objet . ", '" . $lang . "') AS multi";
1294
+	$r = "EXTRAIRE_MULTI(".$objet.", '".$lang."') AS multi";
1295 1295
 
1296 1296
 	return $r;
1297 1297
 }
@@ -1362,7 +1362,7 @@  discard block
 block discarded – undo
1362 1362
 function spip_sqlite_date_proche($champ, $interval, $unite) {
1363 1363
 	$op = (($interval <= 0) ? '>' : '<');
1364 1364
 
1365
-	return "($champ $op datetime('" . date("Y-m-d H:i:s") . "', '$interval $unite'))";
1365
+	return "($champ $op datetime('".date("Y-m-d H:i:s")."', '$interval $unite'))";
1366 1366
 }
1367 1367
 
1368 1368
 
@@ -1392,7 +1392,7 @@  discard block
 block discarded – undo
1392 1392
 				and (!isset($desc['key']['PRIMARY KEY']) or $desc['key']['PRIMARY KEY'] !== $c)
1393 1393
 			) {
1394 1394
 				spip_sqlite_alter($q = "TABLE $table CHANGE $c $c $d DEFAULT ''", $serveur);
1395
-				spip_log("ALTER $q", "repair" . _LOG_INFO_IMPORTANTE);
1395
+				spip_log("ALTER $q", "repair"._LOG_INFO_IMPORTANTE);
1396 1396
 			}
1397 1397
 			if (preg_match(",^(INTEGER),i", $d)
1398 1398
 				and stripos($d, "NOT NULL") !== false
@@ -1401,7 +1401,7 @@  discard block
 block discarded – undo
1401 1401
 				and (!isset($desc['key']['PRIMARY KEY']) or $desc['key']['PRIMARY KEY'] !== $c)
1402 1402
 			) {
1403 1403
 				spip_sqlite_alter($q = "TABLE $table CHANGE $c $c $d DEFAULT '0'", $serveur);
1404
-				spip_log("ALTER $q", "repair" . _LOG_INFO_IMPORTANTE);
1404
+				spip_log("ALTER $q", "repair"._LOG_INFO_IMPORTANTE);
1405 1405
 			}
1406 1406
 			if (preg_match(",^(datetime),i", $d)
1407 1407
 				and stripos($d, "NOT NULL") !== false
@@ -1410,7 +1410,7 @@  discard block
 block discarded – undo
1410 1410
 				and (!isset($desc['key']['PRIMARY KEY']) or $desc['key']['PRIMARY KEY'] !== $c)
1411 1411
 			) {
1412 1412
 				spip_sqlite_alter($q = "TABLE $table CHANGE $c $c $d DEFAULT '0000-00-00 00:00:00'", $serveur);
1413
-				spip_log("ALTER $q", "repair" . _LOG_INFO_IMPORTANTE);
1413
+				spip_log("ALTER $q", "repair"._LOG_INFO_IMPORTANTE);
1414 1414
 			}
1415 1415
 		}
1416 1416
 
@@ -1461,8 +1461,8 @@  discard block
 block discarded – undo
1461 1461
 	// recherche de champs 'timestamp' pour mise a jour auto de ceux-ci
1462 1462
 	$couples = _sqlite_ajouter_champs_timestamp($table, $couples, $desc, $serveur);
1463 1463
 
1464
-	return spip_sqlite_query("REPLACE INTO $table (" . join(',', array_keys($couples)) . ') VALUES (' . join(',',
1465
-			$couples) . ')', $serveur);
1464
+	return spip_sqlite_query("REPLACE INTO $table (".join(',', array_keys($couples)).') VALUES ('.join(',',
1465
+			$couples).')', $serveur);
1466 1466
 }
1467 1467
 
1468 1468
 
@@ -1548,7 +1548,7 @@  discard block
 block discarded – undo
1548 1548
 		. _sqlite_calculer_expression('WHERE', $where)
1549 1549
 		. _sqlite_calculer_expression('GROUP BY', $groupby, ',')
1550 1550
 		. _sqlite_calculer_expression('HAVING', $having)
1551
-		. ($orderby ? ("\nORDER BY " . _sqlite_calculer_order($orderby)) : '')
1551
+		. ($orderby ? ("\nORDER BY "._sqlite_calculer_order($orderby)) : '')
1552 1552
 		. ($limit ? "\nLIMIT $limit" : '');
1553 1553
 
1554 1554
 	// dans un select, on doit renvoyer la requête en cas d'erreur
@@ -1585,10 +1585,10 @@  discard block
 block discarded – undo
1585 1585
 
1586 1586
 	// interdire la creation d'une nouvelle base, 
1587 1587
 	// sauf si on est dans l'installation
1588
-	if (!is_file($f = _DIR_DB . $db . '.sqlite')
1588
+	if (!is_file($f = _DIR_DB.$db.'.sqlite')
1589 1589
 		&& (!defined('_ECRIRE_INSTALL') || !_ECRIRE_INSTALL)
1590 1590
 	) {
1591
-		spip_log("Il est interdit de creer la base $db", 'sqlite.' . _LOG_HS);
1591
+		spip_log("Il est interdit de creer la base $db", 'sqlite.'._LOG_HS);
1592 1592
 
1593 1593
 		return false;
1594 1594
 	}
@@ -1597,12 +1597,12 @@  discard block
 block discarded – undo
1597 1597
 	// avec les identifiants connus
1598 1598
 	$index = $serveur ? $serveur : 0;
1599 1599
 
1600
-	if ($link = spip_connect_db('', '', '', '', '@selectdb@' . $db, $serveur, '', '')) {
1600
+	if ($link = spip_connect_db('', '', '', '', '@selectdb@'.$db, $serveur, '', '')) {
1601 1601
 		if (($db == $link['db']) && $GLOBALS['connexions'][$index] = $link) {
1602 1602
 			return $db;
1603 1603
 		}
1604 1604
 	} else {
1605
-		spip_log("Impossible de selectionner la base $db", 'sqlite.' . _LOG_HS);
1605
+		spip_log("Impossible de selectionner la base $db", 'sqlite.'._LOG_HS);
1606 1606
 
1607 1607
 		return false;
1608 1608
 	}
@@ -1653,7 +1653,7 @@  discard block
 block discarded – undo
1653 1653
 	$match = str_replace("[[POURCENT]]", "%", $match);
1654 1654
 	$match = "^$match$";
1655 1655
 
1656
-	return spip_sqlite_query("SELECT name FROM sqlite_master WHERE type='table' AND tbl_name REGEXP " . _q($match),
1656
+	return spip_sqlite_query("SELECT name FROM sqlite_master WHERE type='table' AND tbl_name REGEXP "._q($match),
1657 1657
 		$serveur, $requeter);
1658 1658
 }
1659 1659
 
@@ -1741,7 +1741,7 @@  discard block
 block discarded – undo
1741 1741
 
1742 1742
 				# rustine pour DECIMAL(10,2)
1743 1743
 				if (false !== strpos($k, ')')) {
1744
-					$fields[$k_precedent] .= ',' . $k . ' ' . $def;
1744
+					$fields[$k_precedent] .= ','.$k.' '.$def;
1745 1745
 					continue;
1746 1746
 				}
1747 1747
 
@@ -1776,13 +1776,13 @@  discard block
 block discarded – undo
1776 1776
 				. 'ORDER BY substr(type,2,1), name';
1777 1777
 			$a = spip_sqlite_query($query, $serveur, $requeter);
1778 1778
 			while ($r = spip_sqlite_fetch($a, null, $serveur)) {
1779
-				$key = str_replace($nom_table . '_', '', $r['name']); // enlever le nom de la table ajoute a l'index
1779
+				$key = str_replace($nom_table.'_', '', $r['name']); // enlever le nom de la table ajoute a l'index
1780 1780
 				$keytype = "KEY";
1781 1781
 				if (strpos($r['sql'], "UNIQUE INDEX") !== false) {
1782 1782
 					$keytype = "UNIQUE KEY";
1783 1783
 				}
1784 1784
 				$colonnes = preg_replace(',.*\((.*)\).*,', '$1', $r['sql']);
1785
-				$keys[$keytype . ' ' . $key] = $colonnes;
1785
+				$keys[$keytype.' '.$key] = $colonnes;
1786 1786
 			}
1787 1787
 		}
1788 1788
 
@@ -1831,7 +1831,7 @@  discard block
 block discarded – undo
1831 1831
 
1832 1832
 	$set = array();
1833 1833
 	foreach ($champs as $champ => $val) {
1834
-		$set[] = $champ . "=$val";
1834
+		$set[] = $champ."=$val";
1835 1835
 	}
1836 1836
 	if (!empty($set)) {
1837 1837
 		return spip_sqlite_query(
@@ -1885,7 +1885,7 @@  discard block
 block discarded – undo
1885 1885
 
1886 1886
 	$set = array();
1887 1887
 	foreach ($champs as $champ => $val) {
1888
-		$set[] = $champ . '=' . _sqlite_calculer_cite($val, isset($fields[$champ]) ? $fields[$champ] : '');
1888
+		$set[] = $champ.'='._sqlite_calculer_cite($val, isset($fields[$champ]) ? $fields[$champ] : '');
1889 1889
 	}
1890 1890
 
1891 1891
 	return spip_sqlite_query(
@@ -1911,7 +1911,7 @@  discard block
 block discarded – undo
1911 1911
  */
1912 1912
 function _sqlite_init() {
1913 1913
 	if (!defined('_DIR_DB')) {
1914
-		define('_DIR_DB', _DIR_ETC . 'bases/');
1914
+		define('_DIR_DB', _DIR_ETC.'bases/');
1915 1915
 	}
1916 1916
 	if (!defined('_SQLITE_CHMOD')) {
1917 1917
 		define('_SQLITE_CHMOD', _SPIP_CHMOD);
@@ -2014,9 +2014,9 @@  discard block
 block discarded – undo
2014 2014
 	}
2015 2015
 
2016 2016
 	// echapper les ' en ''
2017
-	spip_log("Pas de methode ->quote pour echapper", "sqlite." . _LOG_INFO_IMPORTANTE);
2017
+	spip_log("Pas de methode ->quote pour echapper", "sqlite."._LOG_INFO_IMPORTANTE);
2018 2018
 
2019
-	return ("'" . str_replace("'", "''", $v) . "'");
2019
+	return ("'".str_replace("'", "''", $v)."'");
2020 2020
 }
2021 2021
 
2022 2022
 
@@ -2039,12 +2039,12 @@  discard block
 block discarded – undo
2039 2039
 	$exp = "\n$expression ";
2040 2040
 
2041 2041
 	if (!is_array($v)) {
2042
-		return $exp . $v;
2042
+		return $exp.$v;
2043 2043
 	} else {
2044 2044
 		if (strtoupper($join) === 'AND') {
2045
-			return $exp . join("\n\t$join ", array_map('_sqlite_calculer_where', $v));
2045
+			return $exp.join("\n\t$join ", array_map('_sqlite_calculer_where', $v));
2046 2046
 		} else {
2047
-			return $exp . join($join, $v);
2047
+			return $exp.join($join, $v);
2048 2048
 		}
2049 2049
 	}
2050 2050
 }
@@ -2078,17 +2078,17 @@  discard block
 block discarded – undo
2078 2078
 		if (substr($k, -1) == '@') {
2079 2079
 			// c'est une jointure qui se refere au from precedent
2080 2080
 			// pas de virgule
2081
-			$res .= '  ' . $v;
2081
+			$res .= '  '.$v;
2082 2082
 		} else {
2083 2083
 			if (!is_numeric($k)) {
2084 2084
 				$p = strpos($v, " ");
2085 2085
 				if ($p) {
2086
-					$v = substr($v, 0, $p) . " AS '$k'" . substr($v, $p);
2086
+					$v = substr($v, 0, $p)." AS '$k'".substr($v, $p);
2087 2087
 				} else {
2088 2088
 					$v .= " AS '$k'";
2089 2089
 				}
2090 2090
 			}
2091
-			$res .= ', ' . $v;
2091
+			$res .= ', '.$v;
2092 2092
 		}
2093 2093
 	}
2094 2094
 
@@ -2226,13 +2226,13 @@  discard block
 block discarded – undo
2226 2226
 
2227 2227
 	$def_origine = sql_showtable($table_origine, false, $serveur);
2228 2228
 	if (!$def_origine or !isset($def_origine['field'])) {
2229
-		spip_log("Alter table impossible sur $table_origine : table non trouvee", 'sqlite' . _LOG_ERREUR);
2229
+		spip_log("Alter table impossible sur $table_origine : table non trouvee", 'sqlite'._LOG_ERREUR);
2230 2230
 
2231 2231
 		return false;
2232 2232
 	}
2233 2233
 
2234 2234
 
2235
-	$table_tmp = $table_origine . '_tmp';
2235
+	$table_tmp = $table_origine.'_tmp';
2236 2236
 
2237 2237
 	// 1) creer une table temporaire avec les modifications	
2238 2238
 	// - DROP : suppression de la colonne
@@ -2318,7 +2318,7 @@  discard block
 block discarded – undo
2318 2318
 		} else {
2319 2319
 			// enlever KEY
2320 2320
 			$k = substr($k, 4);
2321
-			$queries[] = "CREATE INDEX $table_destination" . "_$k ON $table_destination ($v)";
2321
+			$queries[] = "CREATE INDEX $table_destination"."_$k ON $table_destination ($v)";
2322 2322
 		}
2323 2323
 	}
2324 2324
 
@@ -2329,7 +2329,7 @@  discard block
 block discarded – undo
2329 2329
 		foreach ($queries as $q) {
2330 2330
 			if (!spip_sqlite::executer_requete($q, $serveur)) {
2331 2331
 				spip_log("SQLite : ALTER TABLE table :"
2332
-					. " Erreur a l'execution de la requete : $q", 'sqlite.' . _LOG_ERREUR);
2332
+					. " Erreur a l'execution de la requete : $q", 'sqlite.'._LOG_ERREUR);
2333 2333
 				spip_sqlite::annuler_transaction($serveur);
2334 2334
 
2335 2335
 				return false;
@@ -2418,26 +2418,26 @@  discard block
 block discarded – undo
2418 2418
 	$enum = "(\s*\([^\)]*\))?";
2419 2419
 
2420 2420
 	$remplace = array(
2421
-		'/enum' . $enum . '/is' => 'VARCHAR(255)',
2421
+		'/enum'.$enum.'/is' => 'VARCHAR(255)',
2422 2422
 		'/COLLATE \w+_bin/is' => 'COLLATE BINARY',
2423 2423
 		'/COLLATE \w+_ci/is' => 'COLLATE NOCASE',
2424 2424
 		'/auto_increment/is' => '',
2425 2425
 		'/(timestamp .* )ON .*$/is' => '\\1',
2426 2426
 		'/character set \w+/is' => '',
2427
-		'/((big|small|medium|tiny)?int(eger)?)' . $num . '\s*unsigned/is' => '\\1 UNSIGNED',
2427
+		'/((big|small|medium|tiny)?int(eger)?)'.$num.'\s*unsigned/is' => '\\1 UNSIGNED',
2428 2428
 		'/(text\s+not\s+null(\s+collate\s+\w+)?)\s*$/is' => "\\1 DEFAULT ''",
2429
-		'/((char|varchar)' . $num . '\s+not\s+null(\s+collate\s+\w+)?)\s*$/is' => "\\1 DEFAULT ''",
2429
+		'/((char|varchar)'.$num.'\s+not\s+null(\s+collate\s+\w+)?)\s*$/is' => "\\1 DEFAULT ''",
2430 2430
 		'/(datetime\s+not\s+null)\s*$/is' => "\\1 DEFAULT '0000-00-00 00:00:00'",
2431 2431
 		'/(date\s+not\s+null)\s*$/is' => "\\1 DEFAULT '0000-00-00'",
2432 2432
 	);
2433 2433
 
2434 2434
 	// pour l'autoincrement, il faut des INTEGER NOT NULL PRIMARY KEY
2435 2435
 	$remplace_autocinc = array(
2436
-		'/(big|small|medium|tiny)?int(eger)?' . $num . '/is' => 'INTEGER'
2436
+		'/(big|small|medium|tiny)?int(eger)?'.$num.'/is' => 'INTEGER'
2437 2437
 	);
2438 2438
 	// pour les int non autoincrement, il faut un DEFAULT
2439 2439
 	$remplace_nonautocinc = array(
2440
-		'/((big|small|medium|tiny)?int(eger)?' . $num . '\s+not\s+null)\s*$/is' => "\\1 DEFAULT 0",
2440
+		'/((big|small|medium|tiny)?int(eger)?'.$num.'\s+not\s+null)\s*$/is' => "\\1 DEFAULT 0",
2441 2441
 	);
2442 2442
 
2443 2443
 	if (is_string($query)) {
@@ -2479,7 +2479,7 @@  discard block
 block discarded – undo
2479 2479
 		return str_ireplace("BINARY", "COLLATE BINARY", $champ);
2480 2480
 	}
2481 2481
 	if (preg_match(",^(char|varchar|(long|small|medium|tiny)?text),i", $champ)) {
2482
-		return $champ . " COLLATE NOCASE";
2482
+		return $champ." COLLATE NOCASE";
2483 2483
 	}
2484 2484
 
2485 2485
 	return $champ;
@@ -2566,7 +2566,7 @@  discard block
 block discarded – undo
2566 2566
 		} else {
2567 2567
 			/* simuler le IF EXISTS - version 2 et sqlite < 3.3a */
2568 2568
 			$a = spip_sqlite_showtable($nom, $serveur);
2569
-			if (isset($a['key']['KEY ' . $nom])) {
2569
+			if (isset($a['key']['KEY '.$nom])) {
2570 2570
 				return true;
2571 2571
 			}
2572 2572
 		}
@@ -2574,7 +2574,7 @@  discard block
 block discarded – undo
2574 2574
 	}
2575 2575
 
2576 2576
 	$temporary = $temporary ? ' TEMPORARY' : '';
2577
-	$q = "CREATE$temporary TABLE$ifnotexists $nom ($query" . ($keys ? ",$keys" : '') . ")\n";
2577
+	$q = "CREATE$temporary TABLE$ifnotexists $nom ($query".($keys ? ",$keys" : '').")\n";
2578 2578
 
2579 2579
 	return $q;
2580 2580
 }
@@ -2788,7 +2788,7 @@  discard block
 block discarded – undo
2788 2788
 		$this->serveur = strtolower($serveur);
2789 2789
 
2790 2790
 		if (!($this->link = _sqlite_link($this->serveur)) && (!defined('_ECRIRE_INSTALL') || !_ECRIRE_INSTALL)) {
2791
-			spip_log("Aucune connexion sqlite (link)", 'sqlite.' . _LOG_ERREUR);
2791
+			spip_log("Aucune connexion sqlite (link)", 'sqlite.'._LOG_ERREUR);
2792 2792
 
2793 2793
 			return false;
2794 2794
 		}
@@ -2833,7 +2833,7 @@  discard block
 block discarded – undo
2833 2833
 			try {
2834 2834
 				$r = $this->link->query($query);
2835 2835
 			} catch (\PDOException $e) {
2836
-				spip_log("PDOException: " . $e->getMessage(), 'sqlite.' . _LOG_ERREUR);
2836
+				spip_log("PDOException: ".$e->getMessage(), 'sqlite.'._LOG_ERREUR);
2837 2837
 				$r = false;
2838 2838
 			}
2839 2839
 			// sauvegarde de la requete (elle y est deja dans $r->queryString)
@@ -2854,8 +2854,8 @@  discard block
 block discarded – undo
2854 2854
 
2855 2855
 			// loger les warnings/erreurs eventuels de sqlite remontant dans PHP
2856 2856
 			if ($err = (function_exists('error_get_last') ? error_get_last() : "") and $err != $e) {
2857
-				$err = strip_tags($err['message']) . " in " . $err['file'] . " line " . $err['line'];
2858
-				spip_log("$err - " . $query, 'sqlite.' . _LOG_ERREUR);
2857
+				$err = strip_tags($err['message'])." in ".$err['file']." line ".$err['line'];
2858
+				spip_log("$err - ".$query, 'sqlite.'._LOG_ERREUR);
2859 2859
 			} else {
2860 2860
 				$err = "";
2861 2861
 			}
@@ -2934,15 +2934,15 @@  discard block
 block discarded – undo
2934 2934
 		// Correction Create Database
2935 2935
 		// Create Database -> requete ignoree
2936 2936
 		if (strpos($this->query, 'CREATE DATABASE') === 0) {
2937
-			spip_log("Sqlite : requete non executee -> $this->query", 'sqlite.' . _LOG_AVERTISSEMENT);
2937
+			spip_log("Sqlite : requete non executee -> $this->query", 'sqlite.'._LOG_AVERTISSEMENT);
2938 2938
 			$this->query = "SELECT 1";
2939 2939
 		}
2940 2940
 
2941 2941
 		// Correction Insert Ignore
2942 2942
 		// INSERT IGNORE -> insert (tout court et pas 'insert or replace')
2943 2943
 		if (strpos($this->query, 'INSERT IGNORE') === 0) {
2944
-			spip_log("Sqlite : requete transformee -> $this->query", 'sqlite.' . _LOG_DEBUG);
2945
-			$this->query = 'INSERT ' . substr($this->query, '13');
2944
+			spip_log("Sqlite : requete transformee -> $this->query", 'sqlite.'._LOG_DEBUG);
2945
+			$this->query = 'INSERT '.substr($this->query, '13');
2946 2946
 		}
2947 2947
 
2948 2948
 		// Correction des dates avec INTERVAL
@@ -2967,7 +2967,7 @@  discard block
 block discarded – undo
2967 2967
 		// problematique car la jointure ne se fait pas du coup.
2968 2968
 		if (($this->sqlite_version == 2) && (strpos($this->query, "USING") !== false)) {
2969 2969
 			spip_log("'USING (champ)' n'est pas reconnu en SQLite 2. Utilisez 'ON table1.champ = table2.champ'",
2970
-				'sqlite.' . _LOG_ERREUR);
2970
+				'sqlite.'._LOG_ERREUR);
2971 2971
 			$this->query = preg_replace('/USING\s*\([^\)]*\)/', '', $this->query);
2972 2972
 		}
2973 2973
 
@@ -2987,8 +2987,8 @@  discard block
 block discarded – undo
2987 2987
 		} else {
2988 2988
 			$suite = '';
2989 2989
 		}
2990
-		$pref = ($this->prefixe) ? $this->prefixe . "_" : "";
2991
-		$this->query = preg_replace('/([,\s])spip_/S', '\1' . $pref, $this->query) . $suite;
2990
+		$pref = ($this->prefixe) ? $this->prefixe."_" : "";
2991
+		$this->query = preg_replace('/([,\s])spip_/S', '\1'.$pref, $this->query).$suite;
2992 2992
 
2993 2993
 		// Correction zero AS x
2994 2994
 		// pg n'aime pas 0+x AS alias, sqlite, dans le meme style, 
Please login to merge, or discard this patch.