Erreur bloquante avec sql_showtable() en sqlite
Glop,
(Constaté sur un SPIP 3.2.4)
La fonction "spip_sqlite_showtable()":https://git.spip.net/SPIP/spip/src/branch/spip-3.2/ecrire/req/sqlite_generique.php#L1766 renvoie un tableau incorrect pour field
dans certains cas (cf. les clés 6
et 4
ci-dessous) :
var_dump(sql_showtable('spip_billets_types')); array (size=2) 'field' => array (size=18) 'id_billets_type' => string 'INTEGER NOT NULL' (length=16) 'id_billetterie' => string 'bigint ( 21 ) NOT NULL DEFAULT 0' (length=32) 'titre' => string 'text NOT NULL DEFAULT "" COLLATE NOCASE' (length=39) 'descriptif' => string 'text NOT NULL DEFAULT "" COLLATE NOCASE' (length=39) 'quota' => string 'int ( 11 ) NOT NULL DEFAULT 0' (length=29) 'prix' => string 'decimal ( 20 ' (length=13) 6 => string ') NOT NULL DEFAULT 0' (length=20) 'taxe' => string 'decimal ( 4 ' (length=12) 4 => string ') NOT NULL DEFAULT 0' (length=20) 'selection_min' => string 'int ( 11 ) NOT NULL DEFAULT 0' (length=29) 'selection_max' => string 'int ( 11 ) NOT NULL DEFAULT 0' (length=29) 'date_fin' => string 'datetime NOT NULL DEFAULT "0000-00-00 00:00:00"' (length=47) 'date_debut' => string 'datetime NOT NULL DEFAULT "0000-00-00 00:00:00"' (length=47) 'maj' => string 'TIMESTAMP' (length=9) 'composition' => string 'varchar ( 255 ) NOT NULL DEFAULT '' COLLATE NOCASE' (length=50) 'composition_lock' => string 'tinyint ( 1 ) NOT NULL DEFAULT 0' (length=32) 'rang' => string 'int NOT NULL DEFAULT 0' (length=22) 'id_profil' => string 'bigint(21) NOT NULL DEFAULT 0' (length=29) 'key' => array (size=2) 'PRIMARY KEY' => string 'id_billets_type' (length=15) 'KEY id_billetterie' => string 'CREATE INDEX `spip_billets_types_id_billetterie` ON `spip_billets_types` ( `id_billetterie` )' (length=94)
Et voici ce qu'on devrait avoir, selon la vraie déclaration des champs :
'field'=> array( 'id_billets_type' => 'bigint(21) NOT NULL', 'id_billetterie' => 'bigint(21) NOT NULL DEFAULT 0', 'rang' => 'int NOT NULL DEFAULT 0', 'titre' => 'text NOT NULL DEFAULT ""', 'descriptif' => 'text NOT NULL DEFAULT ""', 'quota' => 'int(11) NOT NULL DEFAULT 0', 'prix' => 'decimal(20,6) NOT NULL DEFAULT 0', 'taxe' => 'decimal(4,4) NOT NULL DEFAULT 0', 'selection_min' => 'int(11) NOT NULL DEFAULT 0', 'selection_max' => 'int(11) NOT NULL DEFAULT 0', 'date_fin' => 'datetime NOT NULL DEFAULT "0000-00-00 00:00:00"', 'date_debut' => 'datetime NOT NULL DEFAULT "0000-00-00 00:00:00"', 'maj' => 'TIMESTAMP' ),
Donc ça se plante sur les champs prix_ht
et taxe
qui sont tous les 2 identiques : decimal(20,6) NOT NULL DEFAULT 0
.
On dirait qu'il y a un souci soit quand il y a une parenthèse, soit quand il y a une virgule dans la déclaration d'une colonne.
Du coup sur une table en Sqlite, la requête suivante ne passe pas :
sql_alter('TABLE spip_billets_types CHANGE prix prix_ht decimal(20,6) NOT NULL DEFAULT 0')
Car au moment de créer la table temporaire, la requête est erronée :
2019-11-20 11:49:50 127.0.0.1 (pid 12659) :Pub:ERREUR: near "6": syntax error - CREATE TABLE IF NOT EXISTS spip_billets_types_tmp ( id_billets_type INTEGER NOT NULL, id_billetterie bigint ( 21 ) NOT NULL DEFAULT 0, titre text NOT NULL DEFAULT "" COLLATE NOCASE, descriptif text NOT NULL DEFAULT "" COLLATE NOCASE, quota int ( 11 ) NOT NULL DEFAULT 0, prix_ht decimal(20,6) NOT NULL DEFAULT 0, 6 ) NOT NULL DEFAULT 0, taxe decimal ( 4 , 4 ) NOT NULL DEFAULT 0, selection_min int ( 11 ) NOT NULL DEFAULT 0, selection_max int ( 11 ) NOT NULL DEFAULT 0, date_fin datetime NOT NULL DEFAULT "0000-00-00 00:00:00", date_debut datetime NOT NULL DEFAULT "0000-00-00 00:00:00", maj TIMESTAMP, composition varchar ( 255 ) NOT NULL DEFAULT '' COLLATE NOCASE, composition_lock tinyint ( 1 ) NOT NULL DEFAULT 0, rang int NOT NULL DEFAULT 0, id_profil bigint(21) NOT NULL DEFAULT 0, PRIMARY KEY (id_billets_type))
Allez, une petite une aspirine et je regarde "la Regex qui décrypte la déclaration SQL":https://git.spip.net/SPIP/spip/src/branch/spip-3.2/ecrire/req/sqlite_generique.php#L1747 : /^[^(),]*\(((?:[^()]*\((?:[^()]*\([^()]*\))?[^()]*\)[^()]*)*[^()]*)\)[^()]*$/