From e5548f75ad9009aeef6c6d76b2f18c3ebe05966c Mon Sep 17 00:00:00 2001
From: Regis Houssin <regis@dolibarr.fr>
Date: Mon, 31 May 2010 09:58:23 +0000
Subject: [PATCH] Fix: ANSI SQL92 Todo: error in pgsql

---
 htdocs/comm/addpropal.php                              | 3 ++-
 htdocs/includes/modules/propale/mod_propale_marbre.php | 3 ++-
 2 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/htdocs/comm/addpropal.php b/htdocs/comm/addpropal.php
index 64ccc24991b..03674a54683 100644
--- a/htdocs/comm/addpropal.php
+++ b/htdocs/comm/addpropal.php
@@ -85,8 +85,9 @@ if ($_GET["action"] == 'create')
 	// Si numero deja pris (ne devrait pas arriver), on incremente par .num+1
 	$sql = "SELECT count(*) as nb";
 	$sql.= " FROM ".MAIN_DB_PREFIX."propal";
-	$sql.= " WHERE ref LIKE '$numpr%'";
+	$sql.= " WHERE ref LIKE '".$numpr."%'";
 	$sql.= " AND entity = ".$conf->entity;
+	
 	$resql=$db->query($sql);
 	if ($resql)
 	{
diff --git a/htdocs/includes/modules/propale/mod_propale_marbre.php b/htdocs/includes/modules/propale/mod_propale_marbre.php
index 59100a91034..9daa986e8b9 100644
--- a/htdocs/includes/modules/propale/mod_propale_marbre.php
+++ b/htdocs/includes/modules/propale/mod_propale_marbre.php
@@ -100,7 +100,8 @@ class mod_propale_marbre extends ModeleNumRefPropales
 
 		// D'abord on recupere la valeur max (reponse immediate car champ indexe)
 		$posindice=8;
-		$sql = "SELECT MAX(SUBSTRING(ref,".$posindice.")) as max";
+		 // TODO le 0+ cree une erreur sous pgsql mais est utile sous mysql si utilisation de différent module dans le passé
+		$sql = "SELECT MAX(0+SUBSTRING(ref FROM ".$posindice.")) as max";
 		$sql.= " FROM ".MAIN_DB_PREFIX."propal";
 		$sql.= " WHERE ref LIKE '".$this->prefix."%'";
 		$sql.= " AND entity = ".$conf->entity;
-- 
GitLab