Qual: Better compatibility with other databases

This commit is contained in:
Laurent Destailleur 2009-10-28 17:37:40 +00:00
parent 57a23f6a17
commit 78643ec12a
24 changed files with 72 additions and 39 deletions

View File

@ -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)
{

View File

@ -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.='&thirdparty='.urlencode($_REQUEST["thirdparty"]);
$mode_search = 1;
}

View File

@ -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
{

View File

@ -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."%')";

View File

@ -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;

View File

@ -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);

View File

@ -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.= ")";

View File

@ -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);

View File

@ -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);

View File

@ -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;

View File

@ -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;

View File

@ -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)

View File

@ -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)

View File

@ -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);

View File

@ -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)
{

View File

@ -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 ";

View File

@ -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)
{

View File

@ -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))
{

View File

@ -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;

View File

@ -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);

View File

@ -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>';

View File

@ -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)
{

View File

@ -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;
}
}
}

View File

@ -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))