Skip to content
Extraits de code Groupes Projets
Valider 0b9ff22b rédigé par marcimat's avatar marcimat
Parcourir les fichiers

Remplacer le critere REGEXP en sqlite2 par une fonction pour réaliser la même...

Remplacer le critere REGEXP en sqlite2 par une fonction pour réaliser la même chose, (il faudra peut être améliorer le preg_replace). Crayons fonctionnels sous SQLite2. Il reste un problème sous SQLite3.
parent ca6eb05d
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
......@@ -43,7 +43,7 @@ function _sqlite_init_functions(&$sqlite){
'MONTH' => array( '_sqlite_func_month' ,1),
'RAND' => array( '_sqlite_func_rand' ,0), // sinon random() v2.4
# 'REGEXP' => array( '_sqlite_func_regexp' ,2), // critere REGEXP supporte a partir de v3.3.2
'REGEXP_MATCH' => array( '_sqlite_func_regexp_match' ,2), // critere REGEXP supporte a partir de v3.3.2
'REGEXP_REPLACE'=> array( '_sqlite_func_regexp_replace' ,3),
'RIGHT' => array( '_sqlite_func_right' ,2),
# 'RTRIM' => array( 'rtrim' ,1), // present en theorie
......@@ -179,6 +179,13 @@ function _sqlite_func_right ($s, $lenght) {
}
function _sqlite_func_regexp_match($quoi, $cherche) {
$return = preg_match('%'.$cherche.'%', $quoi);
#spip_log("regexp_replace : $quoi, $cherche, $remplace, $return",'debug');
return $return;
}
function _sqlite_func_regexp_replace($quoi, $cherche, $remplace) {
$return = preg_replace('%'.$cherche.'%', $remplace, $quoi);
#spip_log("regexp_replace : $quoi, $cherche, $remplace, $return",'debug');
......
......@@ -776,11 +776,8 @@ function _sqlite_calculer_expression($expression, $v, $join = 'AND'){
// pour conversion 0x ?
// pour conversion 0+x ? (pas la peine en sqlite)
function _sqlite_calculer_order($orderby) {
//if (!is_array($orderby)) $orderby = explode(',', $orderby);
//array_walk($orderby, '_sqlite_mettre_quote');
//return join(", ", $orderby);
return (is_array($orderby)) ? join(", ", $orderby) : $orderby;
}
......@@ -1033,6 +1030,7 @@ class sqlite_analyse_query {
$this->corrigerTablesFrom();
$this->corrigerZeroAsX();
$this->corrigerAntiquotes();
$this->corrigerRegexp();
}
......@@ -1082,7 +1080,13 @@ class sqlite_analyse_query {
$this->query = 'INSERT ' . substr($this->query,'13');
}
}
// critere REGEXP non reconnu en sqlite2
function corrigerRegexp(){
if (($this->sqlite_version == 2) && (strpos($this->query, 'REGEXP')!==false)){
$this->query = preg_replace('/([^\s\(]*)(\s*)REGEXP(\s*)([^\s\)]*)/', 'REGEXP_MATCH($1, $4)', $this->query);
}
}
// mettre les bons noms de table dans from, update, insert, replace...
function corrigerTablesFrom(){
......
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter