From 78643ec12ad24828286ede874a76863459595ab7 Mon Sep 17 00:00:00 2001
From: Laurent Destailleur <eldy@users.sourceforge.net>
Date: Wed, 28 Oct 2009 17:37:40 +0000
Subject: [PATCH] Qual: Better compatibility with other databases

---
 htdocs/actioncomm.class.php                   |  2 +-
 htdocs/compta/bank/account.php                |  2 +-
 htdocs/contact/index.php                      |  2 +-
 htdocs/html.form.class.php                    |  2 +-
 htdocs/includes/boxes/box_produits.php        |  2 +-
 htdocs/includes/boxes/box_services_vendus.php |  2 +-
 .../modules/DolibarrModules.class.php         |  2 +-
 .../install/mysql/migration/2.6.0-2.7.0.sql   |  2 +-
 .../tables/llx_c_forme_juridique.key.sql      | 22 ++++++++++++++++
 .../mysql/tables/llx_c_forme_juridique.sql    | 11 ++++----
 htdocs/lib/databases/pgsql.lib.php            | 25 ++++++++++++++-----
 htdocs/lib/functions.lib.php                  |  2 +-
 htdocs/product.class.php                      |  3 +--
 htdocs/product/index.php                      |  2 +-
 htdocs/product/liste.php                      |  2 +-
 htdocs/product/popuprop.php                   |  2 +-
 htdocs/product/reassort.php                   |  2 +-
 htdocs/product/stats/index.php                |  8 +++---
 htdocs/product/stock/entrepot.class.php       |  2 +-
 htdocs/product/stock/fiche.php                |  2 +-
 htdocs/product/stock/index.php                |  6 ++---
 htdocs/product/stock/mouvement.php            |  2 +-
 htdocs/service.class.php                      |  3 +--
 htdocs/societe.class.php                      |  1 +
 24 files changed, 72 insertions(+), 39 deletions(-)
 create mode 100644 htdocs/install/mysql/tables/llx_c_forme_juridique.key.sql

diff --git a/htdocs/actioncomm.class.php b/htdocs/actioncomm.class.php
index 71e41a70861..e84d60b8489 100644
--- a/htdocs/actioncomm.class.php
+++ b/htdocs/actioncomm.class.php
@@ -178,7 +178,7 @@ class ActionComm
         $resql=$this->db->query($sql);
 		if ($resql)
         {
-            $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."actioncomm");
+            $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."actioncomm","id");
 
             if (! $notrigger)
             {
diff --git a/htdocs/compta/bank/account.php b/htdocs/compta/bank/account.php
index 96f8e1243c3..f236b7204c0 100644
--- a/htdocs/compta/bank/account.php
+++ b/htdocs/compta/bank/account.php
@@ -202,7 +202,7 @@ if ($account || $_GET["ref"])
 	}
 	if ($_REQUEST["thirdparty"])
 	{
-		$sql_rech.=" AND (IFNULL(s.nom,'') LIKE '%".addslashes($_REQUEST["thirdparty"])."%')";
+		$sql_rech.=" AND (COALESCE(s.nom,'') LIKE '%".addslashes($_REQUEST["thirdparty"])."%')";
 		$param.='&amp;thirdparty='.urlencode($_REQUEST["thirdparty"]);
 		$mode_search = 1;
 	}
diff --git a/htdocs/contact/index.php b/htdocs/contact/index.php
index 8a5c400378e..bba085ff6a1 100644
--- a/htdocs/contact/index.php
+++ b/htdocs/contact/index.php
@@ -116,7 +116,7 @@ if (!$user->rights->societe->client->voir && !$socid) $sql .= " LEFT JOIN ".MAIN
 $sql.= " WHERE p.entity = ".$conf->entity;
 if (!$user->rights->societe->client->voir && !$socid) //restriction
 {
-	$sql .= " AND IFNULL(sc.fk_user, ".$user->id.") = " .$user->id;
+	$sql .= " AND COALESCE(sc.fk_user, ".$user->id.") = " .$user->id;
 }
 if ($_GET["userid"])    // propre au commercial
 {
diff --git a/htdocs/html.form.class.php b/htdocs/html.form.class.php
index c9db47b74c8..589b71fb30f 100644
--- a/htdocs/html.form.class.php
+++ b/htdocs/html.form.class.php
@@ -859,7 +859,7 @@ class Form
 
 		if ($conf->categorie->enabled && ! $user->rights->categorie->voir)
 		{
-			$sql.= ' AND IFNULL(c.visible,1)=1';
+			$sql.= ' AND COALESCE(c.visible,1)=1';
 		}
 		if (strval($filtertype) != '') $sql.=" AND p.fk_product_type=".$filtertype;
 		if ($ajaxkeysearch && $ajaxkeysearch != '') $sql.=" AND (p.ref like '%".$ajaxkeysearch."%' OR p.label like '%".$ajaxkeysearch."%')";
diff --git a/htdocs/includes/boxes/box_produits.php b/htdocs/includes/boxes/box_produits.php
index 403576ffec6..1c5ca8eef47 100644
--- a/htdocs/includes/boxes/box_produits.php
+++ b/htdocs/includes/boxes/box_produits.php
@@ -79,7 +79,7 @@ class box_produits extends ModeleBoxes {
 			{
 				$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."categorie_product as cp ON cp.fk_product = p.rowid";
 				$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."categorie as c ON cp.fk_categorie = c.rowid";
-				$sql.= $clause." IFNULL(c.visible,1)=1";
+				$sql.= $clause." COALESCE(c.visible,1)=1";
 				$clause = " AND";
 			}
 			$sql.= $clause." p.entity = ".$conf->entity;
diff --git a/htdocs/includes/boxes/box_services_vendus.php b/htdocs/includes/boxes/box_services_vendus.php
index 91c00352236..3f72ffbd161 100644
--- a/htdocs/includes/boxes/box_services_vendus.php
+++ b/htdocs/includes/boxes/box_services_vendus.php
@@ -92,7 +92,7 @@ class box_services_vendus extends ModeleBoxes {
 			if($user->societe_id) $sql.= " AND s.rowid = ".$user->societe_id;
 			if ($conf->categorie->enabled && !$user->rights->categorie->voir)
 			{
-				$sql.= ' AND IFNULL(ca.visible,1)=1';
+				$sql.= ' AND COALESCE(ca.visible,1)=1';
 			}
 			$sql.= " ORDER BY c.tms DESC ";
 			$sql.= $db->plimit($max, 0);
diff --git a/htdocs/includes/modules/DolibarrModules.class.php b/htdocs/includes/modules/DolibarrModules.class.php
index daac4463e22..d9938a1735c 100644
--- a/htdocs/includes/modules/DolibarrModules.class.php
+++ b/htdocs/includes/modules/DolibarrModules.class.php
@@ -332,7 +332,7 @@ class DolibarrModules
 		$sql.= $this->numero;
 		$sql.= ", ".$conf->entity;
 		$sql.= ", 1";
-		$sql.= ", ".$this->db->idate(gmmktime());
+		$sql.= ", '".$this->db->idate(gmmktime())."'";
 		$sql.= ", '".$this->version."'";
 		$sql.= ")";
 
diff --git a/htdocs/install/mysql/migration/2.6.0-2.7.0.sql b/htdocs/install/mysql/migration/2.6.0-2.7.0.sql
index a5639bfe56b..ab81825b80c 100644
--- a/htdocs/install/mysql/migration/2.6.0-2.7.0.sql
+++ b/htdocs/install/mysql/migration/2.6.0-2.7.0.sql
@@ -458,7 +458,7 @@ alter table llx_commandedet modify special_code integer UNSIGNED DEFAULT 0;
 alter table llx_facturedet modify special_code integer UNSIGNED DEFAULT 0;
 alter table llx_propaldet modify special_code integer UNSIGNED DEFAULT 0;
 alter table llx_societe modify special_code integer NULL;
-alter table llx_c_forme_juridique modify code integer UNIQUE NOT NULL;
+alter table llx_c_forme_juridique modify code integer NOT NULL;
 
 ALTER TABLE llx_adherent_options ADD INDEX uk_adherent_options (adhid);
 ALTER TABLE llx_bank_class ADD UNIQUE INDEX idx_bank_class_lineid (lineid);
diff --git a/htdocs/install/mysql/tables/llx_c_forme_juridique.key.sql b/htdocs/install/mysql/tables/llx_c_forme_juridique.key.sql
new file mode 100644
index 00000000000..2b6dea6cbd3
--- /dev/null
+++ b/htdocs/install/mysql/tables/llx_c_forme_juridique.key.sql
@@ -0,0 +1,22 @@
+-- ========================================================================
+-- Copyright (C) 2004      Rodolphe Quiedeville <rodolphe@quiedeville.org>
+-- Copyright (C) 2004-2009 Laurent Destailleur  <eldy@users.sourceforge.net>
+--
+-- This program is free software; you can redistribute it and/or modify
+-- it under the terms of the GNU General Public License as published by
+-- the Free Software Foundation; either version 2 of the License, or
+-- (at your option) any later version.
+--
+-- This program is distributed in the hope that it will be useful,
+-- but WITHOUT ANY WARRANTY; without even the implied warranty of
+-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+-- GNU General Public License for more details.
+--
+-- You should have received a copy of the GNU General Public License
+-- along with this program; if not, write to the Free Software
+-- Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+--
+-- $Id$
+-- ========================================================================
+
+ALTER TABLE llx_c_forme_juridique ADD UNIQUE INDEX uk_c_forme_juridique (code);
diff --git a/htdocs/install/mysql/tables/llx_c_forme_juridique.sql b/htdocs/install/mysql/tables/llx_c_forme_juridique.sql
index 29317db44f3..846ec6369aa 100644
--- a/htdocs/install/mysql/tables/llx_c_forme_juridique.sql
+++ b/htdocs/install/mysql/tables/llx_c_forme_juridique.sql
@@ -1,6 +1,6 @@
 -- ========================================================================
--- Copyright (C) 2004 Rodolphe Quiedeville <rodolphe@quiedeville.org>
--- Copyright (C) 2004 Laurent Destailleur  <eldy@users.sourceforge.net>
+-- Copyright (C) 2004      Rodolphe Quiedeville <rodolphe@quiedeville.org>
+-- Copyright (C) 2004-2009 Laurent Destailleur  <eldy@users.sourceforge.net>
 --
 -- This program is free software; you can redistribute it and/or modify
 -- it under the terms of the GNU General Public License as published by
@@ -21,12 +21,11 @@
 
 create table llx_c_forme_juridique
 (
-  rowid      	integer       AUTO_INCREMENT PRIMARY KEY,
-  code       	integer       UNIQUE NOT NULL,
-  fk_pays    	integer       NOT NULL,
+  rowid      	integer AUTO_INCREMENT PRIMARY KEY,
+  code       	integer NOT NULL,
+  fk_pays    	integer NOT NULL,
   libelle    	varchar(255),
   isvatexempted	tinyint DEFAULT 0  NOT NULL,
   active     	tinyint DEFAULT 1  NOT NULL
-
 )type=innodb;
 
diff --git a/htdocs/lib/databases/pgsql.lib.php b/htdocs/lib/databases/pgsql.lib.php
index 9c5e257e857..fc1dbd17ce0 100644
--- a/htdocs/lib/databases/pgsql.lib.php
+++ b/htdocs/lib/databases/pgsql.lib.php
@@ -440,6 +440,19 @@ class DoliDb
 		// Convert MySQL syntax to PostgresSQL syntax
 		$query=$this->convertSQLFromMysql($query);
 		//print "FF\n".$query."<br>\n";
+
+		// Fix bad formed requests. If request contains a date without quotes, we fix this but this should not occurs.
+		$loop=true;
+		while ($loop)
+		{
+			if (preg_match('/([^\'])([0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9] [0-9][0-9]:[0-9][0-9]:[0-9][0-9])([^\'])/',$query))
+			{
+				$query=preg_replace('/([^\'])([0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9] [0-9][0-9]:[0-9][0-9]:[0-9][0-9])([^\'])/','\\1\'\\2\'\\3',$query);
+				dol_syslog("Warning: Bad formed request converted into ".$query,LOG_WARNING);
+			}
+			else $loop=false;
+		}
+
 		$ret = @pg_query($this->db, $query);
 		if (! preg_match("/^COMMIT/i",$query) && ! preg_match("/^ROLLBACK/i",$query))
 		{
@@ -613,7 +626,7 @@ class DoliDb
 	 */
 	function idate($param)
 	{
-		return "'".adodb_strftime("%Y-%m-%d %H:%M:%S",$param)."'";
+		return adodb_strftime("%Y-%m-%d %H:%M:%S",$param);
 	}
 
 	/**
@@ -752,13 +765,13 @@ class DoliDb
 	}
 
 	/**
-	 * \brief      Recupere l'id genere par le dernier INSERT.
-	 * \param     	tab     Nom de la table concernee par l'insert. Ne sert pas sous MySql mais requis pour compatibilite avec Postgresql
-	 * \return     int     id
+	 * \brief		Get last ID after an insert INSERT.
+	 * \param     	tab     Table name concerned by insert. Ne sert pas sous MySql mais requis pour compatibilite avec Postgresql
+	 * \return     	int     id
 	 */
-	function last_insert_id($tab)
+	function last_insert_id($tab,$fieldid='rowid')
 	{
-		$result = pg_query($this->db,"SELECT MAX(rowid) FROM ".$tab." ;");
+		$result = pg_query($this->db,"SELECT MAX(".$fieldid.") FROM ".$tab." ;");
 		$nbre = pg_num_rows($result);
 		$row = pg_fetch_result($result,0,0);
 		return $row;
diff --git a/htdocs/lib/functions.lib.php b/htdocs/lib/functions.lib.php
index 7ce1949a189..1911d6bba82 100644
--- a/htdocs/lib/functions.lib.php
+++ b/htdocs/lib/functions.lib.php
@@ -1688,7 +1688,7 @@ function restrictedArea($user, $features='societe', $objectid=0, $dbtablename=''
 					$sql.= " WHERE dbt.rowid = ".$objectid;
 					$sql.= " AND dbt.fk_soc = s.rowid";
 					$sql.= " AND s.entity = ".$conf->entity;
-					$sql.= " AND IFNULL(sc.fk_user, ".$user->id.") = ".$user->id;
+					$sql.= " AND COALESCE(sc.fk_user, ".$user->id.") = ".$user->id;
 				}
 				// If multicompany and internal users with all permissions, check user is in correct entity
 				else if ($conf->global->MAIN_MODULE_MULTICOMPANY)
diff --git a/htdocs/product.class.php b/htdocs/product.class.php
index a17110327ab..64c86848232 100644
--- a/htdocs/product.class.php
+++ b/htdocs/product.class.php
@@ -26,7 +26,6 @@
  *	\brief      Fichier de la classe des produits predefinis
  *	\version    $Id$
  */
-
 require_once(DOL_DOCUMENT_ROOT ."/commonobject.class.php");
 
 
@@ -2594,7 +2593,7 @@ class Product extends CommonObject
 		$sql.= " AND p.entity = ".$conf->entity;
 		if ($conf->categorie->enabled && !$user->rights->categorie->voir)
 		{
-			$sql.= " AND IFNULL(c.visible,1)=1";
+			$sql.= " AND COALESCE(c.visible,1)=1";
 		}
 		$resql=$this->db->query($sql);
 		if ($resql)
diff --git a/htdocs/product/index.php b/htdocs/product/index.php
index 796ddc7964d..d2f2326f2ae 100644
--- a/htdocs/product/index.php
+++ b/htdocs/product/index.php
@@ -164,7 +164,7 @@ if ($conf->categorie->enabled && !$user->rights->categorie->voir)
 $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."product_subproduct as sp ON p.rowid = sp.fk_product_subproduct";
 $sql.= " WHERE sp.fk_product_subproduct IS NULL";
 $sql.= " AND p.entity = ".$conf->entity;
-if ($conf->categorie->enabled && !$user->rights->categorie->voir) $sql.= " AND IFNULL(c.visible,1)=1 ";
+if ($conf->categorie->enabled && !$user->rights->categorie->voir) $sql.= " AND COALESCE(c.visible,1)=1 ";
 if (isset($_GET["type"])) $sql.= " AND p.fk_product_type = ".$_GET["type"];
 $sql.= " ORDER BY p.tms DESC ";
 $sql.= $db->plimit($max,0);
diff --git a/htdocs/product/liste.php b/htdocs/product/liste.php
index 460a780a92f..1c39958f604 100644
--- a/htdocs/product/liste.php
+++ b/htdocs/product/liste.php
@@ -145,7 +145,7 @@ if($catid)
 }
 if ($conf->categorie->enabled && !$user->rights->categorie->voir)
 {
-	$sql.= ' AND IFNULL(c.visible,1)=1';
+	$sql.= ' AND COALESCE(c.visible,1)=1';
 }
 if ($fourn_id > 0)
 {
diff --git a/htdocs/product/popuprop.php b/htdocs/product/popuprop.php
index dbb4ff443c9..654f96a5811 100644
--- a/htdocs/product/popuprop.php
+++ b/htdocs/product/popuprop.php
@@ -89,7 +89,7 @@ $sql.= " WHERE p.rowid = pd.fk_product";
 $sql.= " AND p.entity = ".$conf->entity;
 if ($conf->categorie->enabled && !$user->rights->categorie->voir)
 {
-  $sql.= ' AND IFNULL(c.visible,1)=1';
+  $sql.= ' AND COALESCE(c.visible,1)=1';
 }
 $sql.= " group by (p.rowid)";
 $sql.= " ORDER BY $sortfield $sortorder ";
diff --git a/htdocs/product/reassort.php b/htdocs/product/reassort.php
index b6e05e0bd60..d5304bf3570 100644
--- a/htdocs/product/reassort.php
+++ b/htdocs/product/reassort.php
@@ -121,7 +121,7 @@ if($catid)
 }
 if ($conf->categorie->enabled && !$user->rights->categorie->voir)
 {
-	$sql.= ' AND IFNULL(c.visible,1)=1';
+	$sql.= ' AND COALESCE(c.visible,1)=1';
 }
 if ($fourn_id > 0)
 {
diff --git a/htdocs/product/stats/index.php b/htdocs/product/stats/index.php
index 2257aad3435..5b04d0a50b7 100644
--- a/htdocs/product/stats/index.php
+++ b/htdocs/product/stats/index.php
@@ -48,7 +48,7 @@ if ($conf->categorie->enabled && !$user->rights->categorie->voir)
 }
 $sql.= " WHERE p.fk_product_type <> 1";
 $sql.= " AND p.entity = ".$conf->entity;
-if ($conf->categorie->enabled && !$user->rights->categorie->voir) $sql.= ' AND IFNULL(c.visible,1)=1';
+if ($conf->categorie->enabled && !$user->rights->categorie->voir) $sql.= ' AND COALESCE(c.visible,1)=1';
 
 if ($db->query($sql))
 {
@@ -68,7 +68,7 @@ if ($conf->categorie->enabled && !$user->rights->categorie->voir)
 $sql.= " WHERE p.envente = 0";
 $sql.= " AND p.fk_product_type <> '1'";
 $sql.= " AND p.entity = ".$conf->entity;
-if ($conf->categorie->enabled && !$user->rights->categorie->voir) $sql.= ' AND IFNULL(c.visible,1)=1';
+if ($conf->categorie->enabled && !$user->rights->categorie->voir) $sql.= ' AND COALESCE(c.visible,1)=1';
 
 if ($db->query($sql))
 {
@@ -113,7 +113,7 @@ if ($conf->service->enabled)
   }
   $sql.= " WHERE p.fk_product_type = '1'";
   $sql.= " AND p.entity = ".$conf->entity;
-  if ($conf->categorie->enabled && !$user->rights->categorie->voir) $sql.= ' AND IFNULL(c.visible,1)=1';
+  if ($conf->categorie->enabled && !$user->rights->categorie->voir) $sql.= ' AND COALESCE(c.visible,1)=1';
 
   if ($db->query($sql))
   {
@@ -132,7 +132,7 @@ if ($conf->service->enabled)
   $sql.= " WHERE p.envente = 0";
   $sql.= " AND p.fk_product_type = '1'";
   $sql.= " AND p.entity = ".$conf->entity;
-  if ($conf->categorie->enabled && !$user->rights->categorie->voir) $sql.= ' AND IFNULL(c.visible,1)=1';
+  if ($conf->categorie->enabled && !$user->rights->categorie->voir) $sql.= ' AND COALESCE(c.visible,1)=1';
 
   if ($db->query($sql))
   {
diff --git a/htdocs/product/stock/entrepot.class.php b/htdocs/product/stock/entrepot.class.php
index c1dc2061fb3..fab43edc636 100644
--- a/htdocs/product/stock/entrepot.class.php
+++ b/htdocs/product/stock/entrepot.class.php
@@ -309,7 +309,7 @@ class Entrepot extends CommonObject
 		$sql .= " WHERE ps.fk_entrepot = ".$this->id;
 		if ($conf->categorie->enabled && !$user->rights->categorie->voir)
 		{
-			$sql.= ' AND IFNULL(c.visible,1)=1';
+			$sql.= ' AND COALESCE(c.visible,1)=1';
 		}
 
 		//print $sql;
diff --git a/htdocs/product/stock/fiche.php b/htdocs/product/stock/fiche.php
index a4462d11c8a..b2d2ec8f644 100644
--- a/htdocs/product/stock/fiche.php
+++ b/htdocs/product/stock/fiche.php
@@ -330,7 +330,7 @@ else
 			$sql .= " AND ps.fk_entrepot = ".$entrepot->id;
 			if ($conf->categorie->enabled && !$user->rights->categorie->voir)
 			{
-				$sql.= ' AND IFNULL(c.visible,1)=1';
+				$sql.= ' AND COALESCE(c.visible,1)=1';
 			}
 			$sql.= " ORDER BY " . $sortfield . " " . $sortorder;
 			//$sql .= $db->plimit($limit + 1 ,$offset);
diff --git a/htdocs/product/stock/index.php b/htdocs/product/stock/index.php
index e198a6bfb5a..8962840f0dc 100644
--- a/htdocs/product/stock/index.php
+++ b/htdocs/product/stock/index.php
@@ -35,7 +35,7 @@ $langs->load("stocks");
 if (!$user->rights->stock->lire)
   accessforbidden();
 
-  
+
 /*
  * View
  */
@@ -124,7 +124,7 @@ $sql.= " AND m.fk_entrepot = s.rowid";
 $sql.= " AND s.entity = ".$conf->entity;
 if ($conf->categorie->enabled && !$user->rights->categorie->voir)
 {
-	$sql.= " AND IFNULL(c.visible,1)=1";
+	$sql.= " AND COALESCE(c.visible,1)=1";
 }
 $sql.= " ORDER BY datem DESC";
 $sql.= $db->plimit($max,0);
@@ -165,7 +165,7 @@ if ($resql)
 	}
 	$db->free($resql);
 
-	print "</table>";	
+	print "</table>";
 }
 
 print '</td></tr></table>';
diff --git a/htdocs/product/stock/mouvement.php b/htdocs/product/stock/mouvement.php
index dda56347643..e33522c2621 100644
--- a/htdocs/product/stock/mouvement.php
+++ b/htdocs/product/stock/mouvement.php
@@ -75,7 +75,7 @@ if ($_GET["id"])
 $sql.= " AND s.rowid ='".$_GET["id"]."'";
 if ($conf->categorie->enabled && !$user->rights->categorie->voir)
 {
-	$sql.= " AND IFNULL(c.visible,1)=1";
+	$sql.= " AND COALESCE(c.visible,1)=1";
 }
 if ($month > 0)
 {
diff --git a/htdocs/service.class.php b/htdocs/service.class.php
index b8430312cde..427ded52595 100644
--- a/htdocs/service.class.php
+++ b/htdocs/service.class.php
@@ -73,7 +73,7 @@ class Service
 		$sql.= " AND p.entity = ".$conf->entity;
 		if ($conf->categorie->enabled && !$user->rights->categorie->voir)
 		{
-			$sql.= " AND IFNULL(c.visible,1)=1";
+			$sql.= " AND COALESCE(c.visible,1)=1";
 		}
 		$resql=$this->db->query($sql);
 		if ($resql)
@@ -90,7 +90,6 @@ class Service
 			$this->error=$this->db->error();
 			return -1;
 		}
-
 	}
 
 }
diff --git a/htdocs/societe.class.php b/htdocs/societe.class.php
index 67ae5e8672e..636487a44c4 100644
--- a/htdocs/societe.class.php
+++ b/htdocs/societe.class.php
@@ -537,6 +537,7 @@ class Societe extends CommonObject
 		$sql .= ' WHERE s.rowid = '.$socid;
 
 		$resql=$this->db->query($sql);
+		dol_syslog("Societe::fetch ".$sql);
 		if ($resql)
 		{
 			if ($this->db->num_rows($resql))
-- 
GitLab