From 85a549e2b29fbc7c20bed0da75aa6dcd19541976 Mon Sep 17 00:00:00 2001
From: Regis Houssin <regis@dolibarr.fr>
Date: Thu, 19 Jul 2007 17:32:06 +0000
Subject: [PATCH] =?UTF-8?q?Fix:=20remplacement=20de=20LIKE=20dans=20la=20r?=
 =?UTF-8?q?equete=20sql=20par=20REGEXP=20afin=20de=20palier=20au=20diff=E9?=
 =?UTF-8?q?rent=20format=20de=20num=E9rotation?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 .../modules/mod_commande_fournisseur_orchidee.php      | 10 +++++-----
 .../includes/modules/commande/mod_commande_saphir.php  | 10 +++++-----
 .../includes/modules/facture/pluton/pluton.modules.php | 10 +++++-----
 htdocs/includes/modules/propale/mod_propale_saphir.php | 10 +++++-----
 htdocs/livraison/mods/mod_livraison_saphir.php         | 10 +++++-----
 5 files changed, 25 insertions(+), 25 deletions(-)

diff --git a/htdocs/fourn/commande/modules/mod_commande_fournisseur_orchidee.php b/htdocs/fourn/commande/modules/mod_commande_fournisseur_orchidee.php
index 5c8fa333f19..d9cf3cf749f 100644
--- a/htdocs/fourn/commande/modules/mod_commande_fournisseur_orchidee.php
+++ b/htdocs/fourn/commande/modules/mod_commande_fournisseur_orchidee.php
@@ -173,7 +173,7 @@ function info()
         $searchyy='';
         $sql = "SELECT MAX(ref)";
         $sql.= " FROM ".MAIN_DB_PREFIX."commande_fournisseur";
-        if ($conf->global->COMMANDE_FOURNISSEUR_NUM_RESTART_BEGIN_YEAR) $sql.= " WHERE ref like '".$this->searchLast."%'";
+        if ($conf->global->COMMANDE_FOURNISSEUR_NUM_RESTART_BEGIN_YEAR) $sql.= " WHERE ref REGEXP '^".$this->searchLast."'";
         $resql=$db->query($sql);
         if ($resql)
         {
@@ -188,7 +188,7 @@ function info()
           $previousyy='';
           $sql = "SELECT MAX(ref)";
           $sql.= " FROM ".MAIN_DB_PREFIX."commande_fournisseur";
-          $sql.= " WHERE ref like '".$this->searchLastWithPreviousYear."%'";
+          $sql.= " WHERE ref REGEXP '^".$this->searchLastWithPreviousYear."'";
           $resql=$db->query($sql);
           if ($resql)
           {
@@ -203,7 +203,7 @@ function info()
             // Recherche rapide car restreint par un like sur champ index�
             $sql = "SELECT MAX(0+SUBSTRING(ref,-".$posindice."))";
             $sql.= " FROM ".MAIN_DB_PREFIX."commande_fournisseur";
-            $sql.= " WHERE ref like '${searchyy}%'";
+            $sql.= " WHERE ref REGEXP '^".$searchyy."'";
             $resql=$db->query($sql);
             if ($resql)
             {
@@ -375,9 +375,9 @@ function info()
         					// On r�cup�re le mois si besoin
         					$this->mm = strftime("%m",time());
         					$this->numMatrice[$k] = '$mm';
-        					$this->searchLast .= $this->mm;
+        					$this->searchLast .= '[0-9][0-9]';
         					$this->searchLastWithNoYear .= '[0-9][0-9]';
-        					$this->searchLastWithPreviousYear .= $this->mm;
+        					$this->searchLastWithPreviousYear .= '[0-9][0-9]';
         					$k++;
         				}
         				else if ($idMatrice == 'counter')
diff --git a/htdocs/includes/modules/commande/mod_commande_saphir.php b/htdocs/includes/modules/commande/mod_commande_saphir.php
index 5422950443e..a237edd5442 100644
--- a/htdocs/includes/modules/commande/mod_commande_saphir.php
+++ b/htdocs/includes/modules/commande/mod_commande_saphir.php
@@ -175,7 +175,7 @@ function info()
           $searchyy='';
           $sql = "SELECT MAX(ref)";
           $sql.= " FROM ".MAIN_DB_PREFIX."commande";
-          if ($conf->global->COMMANDE_NUM_RESTART_BEGIN_YEAR) $sql.= " WHERE ref like '".$this->searchLast."%'";
+          if ($conf->global->COMMANDE_NUM_RESTART_BEGIN_YEAR) $sql.= " WHERE ref REGEXP '^".$this->searchLast."'";
           $resql=$db->query($sql);
           if ($resql)
           {
@@ -189,7 +189,7 @@ function info()
             $previousyy='';
             $sql = "SELECT MAX(ref)";
             $sql.= " FROM ".MAIN_DB_PREFIX."commande";
-            $sql.= " WHERE ref like '".$this->searchLastWithPreviousYear."%'";
+            $sql.= " WHERE ref REGEXP '^".$this->searchLastWithPreviousYear."'";
             $resql=$db->query($sql);
             if ($resql)
             {
@@ -204,7 +204,7 @@ function info()
             // Recherche rapide car restreint par un like sur champ index�
             $sql = "SELECT MAX(0+SUBSTRING(ref,-".$posindice."))";
             $sql.= " FROM ".MAIN_DB_PREFIX."commande";
-            $sql.= " WHERE ref like '${searchyy}%'";
+            $sql.= " WHERE ref REGEXP '^".$searchyy."'";
             $resql=$db->query($sql);
             if ($resql)
             {
@@ -377,9 +377,9 @@ function info()
         					// On r�cup�re le mois si besoin
         					$this->mm = strftime("%m",time());
         					$this->numMatrice[$k] = '$mm';
-        					$this->searchLast .= $this->mm;
+        					$this->searchLast .= '[0-9][0-9]';
         					$this->searchLastWithNoYear .= '[0-9][0-9]';
-        					$this->searchLastWithPreviousYear .= $this->mm;
+        					$this->searchLastWithPreviousYear .= '[0-9][0-9]';
         					$k++;
         				}
         				else if ($idMatrice == 'counter')
diff --git a/htdocs/includes/modules/facture/pluton/pluton.modules.php b/htdocs/includes/modules/facture/pluton/pluton.modules.php
index 0273f02272c..99023075962 100644
--- a/htdocs/includes/modules/facture/pluton/pluton.modules.php
+++ b/htdocs/includes/modules/facture/pluton/pluton.modules.php
@@ -199,7 +199,7 @@ function info()
         $sql.= " FROM ".MAIN_DB_PREFIX."facture";
         if ($conf->global->FACTURE_NUM_RESTART_BEGIN_YEAR)
         {
-        	$sql.= " WHERE facnumber like '".$this->searchLast."%'";
+        	$sql.= " WHERE facnumber REGEXP '^".$this->searchLast."'";
         }
         else if ($facture->type == 2)
         {
@@ -219,7 +219,7 @@ function info()
           $previousyy='';
           $sql = "SELECT MAX(facnumber)";
           $sql.= " FROM ".MAIN_DB_PREFIX."facture";
-          $sql.= " WHERE facnumber like '$".$this->searchLastWithPreviousYear."%'";
+          $sql.= " WHERE facnumber REGEXP '^".$this->searchLastWithPreviousYear."'";
           $resql=$db->query($sql);
           if ($resql)
           {
@@ -234,7 +234,7 @@ function info()
             // Recherche rapide car restreint par un like sur champ index�
             $sql = "SELECT MAX(0+SUBSTRING(facnumber,-".$posindice."))";
             $sql.= " FROM ".MAIN_DB_PREFIX."facture";
-            $sql.= " WHERE facnumber like '${searchyy}%'";
+            $sql.= " WHERE facnumber REGEXP '^".$searchyy."'";
             $resql=$db->query($sql);
             if ($resql)
             {
@@ -428,9 +428,9 @@ function info()
         					// On r�cup�re le mois si besoin
         					$this->mm = strftime("%m",time());
         					$this->numMatrice[$k] = '$mm';
-        					$this->searchLast .= $this->mm;
+        					$this->searchLast .= '[0-9][0-9]';
         					$this->searchLastWithNoYear .= '[0-9][0-9]';
-        					$this->searchLastWithPreviousYear .= $this->mm;
+        					$this->searchLastWithPreviousYear .= '[0-9][0-9]';
         					$k++;
         				}
         				else if ($idMatrice == 'counter')
diff --git a/htdocs/includes/modules/propale/mod_propale_saphir.php b/htdocs/includes/modules/propale/mod_propale_saphir.php
index 48ac5c59a67..c0e80d48374 100644
--- a/htdocs/includes/modules/propale/mod_propale_saphir.php
+++ b/htdocs/includes/modules/propale/mod_propale_saphir.php
@@ -175,7 +175,7 @@ function info()
         $searchyy='';
         $sql = "SELECT MAX(ref)";
         $sql.= " FROM ".MAIN_DB_PREFIX."propal";
-        if ($conf->global->PROPALE_NUM_RESTART_BEGIN_YEAR) $sql.= " WHERE ref like '".$this->searchLast."%'";
+        if ($conf->global->PROPALE_NUM_RESTART_BEGIN_YEAR) $sql.= " WHERE ref REGEXP '^".$this->searchLast."'";
         $resql=$db->query($sql);
         if ($resql)
         {
@@ -190,7 +190,7 @@ function info()
         	$previousyy='';
         	$sql = "SELECT MAX(ref)";
         	$sql.= " FROM ".MAIN_DB_PREFIX."propal";
-        	$sql.= " WHERE ref like '".$this->searchLastWithPreviousYear."%'";
+        	$sql.= " WHERE ref REGEXP '^".$this->searchLastWithPreviousYear."'";
         	$resql=$db->query($sql);
         	if ($resql)
         	{
@@ -205,7 +205,7 @@ function info()
             // Recherche rapide car restreint par un like sur champ index�
             $sql = "SELECT MAX(0+SUBSTRING(ref,-".$posindice."))";
             $sql.= " FROM ".MAIN_DB_PREFIX."propal";
-            $sql.= " WHERE ref like '${searchyy}%'";
+            $sql.= " WHERE ref like '^".$searchyy."'";
             $resql=$db->query($sql);
             if ($resql)
             {
@@ -366,9 +366,9 @@ function info()
         					// On r�cup�re le mois si besoin
         					$this->mm = strftime("%m",time());
         					$this->numMatrice[$k] = '$mm';
-        					$this->searchLast .= $this->mm;
+        					$this->searchLast .= '[0-9][0-9]';
         					$this->searchLastWithNoYear .= '[0-9][0-9]';
-        					$this->searchLastWithPreviousYear .= $this->mm;
+        					$this->searchLastWithPreviousYear .= '[0-9][0-9]';
         					$k++;
         				}
         				else if ($idMatrice == 'counter')
diff --git a/htdocs/livraison/mods/mod_livraison_saphir.php b/htdocs/livraison/mods/mod_livraison_saphir.php
index 2e53de5d29d..9a33dc0df6a 100644
--- a/htdocs/livraison/mods/mod_livraison_saphir.php
+++ b/htdocs/livraison/mods/mod_livraison_saphir.php
@@ -176,7 +176,7 @@ class mod_livraison_saphir extends ModeleNumRefDeliveryOrder
         $searchyy='';
         $sql = "SELECT MAX(ref)";
         $sql.= " FROM ".MAIN_DB_PREFIX."livraison";
-        if ($conf->global->LIVRAISON_NUM_RESTART_BEGIN_YEAR) $sql.= " WHERE ref like '".$this->searchLast."%'";
+        if ($conf->global->LIVRAISON_NUM_RESTART_BEGIN_YEAR) $sql.= " WHERE ref REGEXP '^".$this->searchLast."'";
         $resql=$db->query($sql);
         if ($resql)
         {
@@ -191,7 +191,7 @@ class mod_livraison_saphir extends ModeleNumRefDeliveryOrder
           $previousyy='';
           $sql = "SELECT MAX(ref)";
           $sql.= " FROM ".MAIN_DB_PREFIX."livraison";
-          $sql.= " WHERE ref like '".$this->searchLastWithPreviousYear."%'";
+          $sql.= " WHERE ref REGEXP '^".$this->searchLastWithPreviousYear."'";
           $resql=$db->query($sql);
           if ($resql)
           {
@@ -206,7 +206,7 @@ class mod_livraison_saphir extends ModeleNumRefDeliveryOrder
             // Recherche rapide car restreint par un like sur champ index�
             $sql = "SELECT MAX(0+SUBSTRING(ref,-".$posindice."))";
             $sql.= " FROM ".MAIN_DB_PREFIX."livraison";
-            $sql.= " WHERE ref like '${searchyy}%'";
+            $sql.= " WHERE ref REGEXP '^".$searchyy."'";
             $resql=$db->query($sql);
             if ($resql)
             {
@@ -379,9 +379,9 @@ class mod_livraison_saphir extends ModeleNumRefDeliveryOrder
         					// On r�cup�re le mois si besoin
         					$this->mm = strftime("%m",time());
         					$this->numMatrice[$k] = '$mm';
-        					$this->searchLast .= $this->mm;
+        					$this->searchLast .= '[0-9][0-9]';
         					$this->searchLastWithNoYear .= '[0-9][0-9]';
-        					$this->searchLastWithPreviousYear .= $this->mm;
+        					$this->searchLastWithPreviousYear .= '[0-9][0-9]';
         					$k++;
         				}
         				else if ($idMatrice == 'counter')
-- 
GitLab