Qual: More portable SQL
This commit is contained in:
parent
66f7b34e33
commit
05533ffe77
@ -349,13 +349,16 @@ if ($_POST["action"] == "set")
|
|||||||
|
|
||||||
// Creation donnees
|
// Creation donnees
|
||||||
$file = "functions.sql";
|
$file = "functions.sql";
|
||||||
if (file_exists($dir.$file)) {
|
if (file_exists($dir.$file))
|
||||||
$fp = fopen($dir.$file,"r");
|
{
|
||||||
if ($fp)
|
$fp = fopen($dir.$file,"r");
|
||||||
|
dolibarr_install_syslog("Open function file ".$dir.$file." handle=".$fp,LOG_DEBUG);
|
||||||
|
if ($fp)
|
||||||
{
|
{
|
||||||
|
$buffer='';
|
||||||
while (!feof ($fp))
|
while (!feof ($fp))
|
||||||
{
|
{
|
||||||
$buffer = fgets($fp, 4096);
|
$buf = fgets($fp, 4096);
|
||||||
if (substr($buf, 0, 2) <> '--')
|
if (substr($buf, 0, 2) <> '--')
|
||||||
{
|
{
|
||||||
$buffer .= $buf;
|
$buffer .= $buf;
|
||||||
@ -365,11 +368,15 @@ if ($_POST["action"] == "set")
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Si plusieurs requetes, on boucle sur chaque
|
// Si plusieurs requetes, on boucle sur chaque
|
||||||
$listesql=explode('§',preg_replace(";';",";'§",$buffer)); // TODO vérifier expression
|
$buffer=preg_replace('/;\';/',";'§",$buffer);
|
||||||
foreach ($listesql as $buffer) {
|
$listesql=explode('§',$buffer);
|
||||||
if (trim($buffer)) {
|
foreach ($listesql as $buffer)
|
||||||
|
{
|
||||||
if ($db->query(trim($buffer)))
|
$buffer=trim($buffer);
|
||||||
|
if ($buffer)
|
||||||
|
{
|
||||||
|
dolibarr_install_syslog("Request: ".$buffer,LOG_DEBUG);
|
||||||
|
if ($db->query($buffer))
|
||||||
{
|
{
|
||||||
$ok = 1;
|
$ok = 1;
|
||||||
}
|
}
|
||||||
@ -382,7 +389,7 @@ if ($_POST["action"] == "set")
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
$ok = 0;
|
$ok = 0;
|
||||||
print $langs->trans("ErrorSQL")." : ".$db->errno()." - '$buffer' - ".$db->error()."<br>";
|
print $langs->trans("ErrorSQL")." : ".$db->errno()." - '$buffer' - ".$db->lastqueryerror()."<br>";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -413,9 +420,9 @@ if ($_POST["action"] == "set")
|
|||||||
// We always choose in mysql directory (Conversion is done by driver to translate SQL syntax)
|
// We always choose in mysql directory (Conversion is done by driver to translate SQL syntax)
|
||||||
$dir = "mysql/data/";
|
$dir = "mysql/data/";
|
||||||
|
|
||||||
// Creation donnees
|
// Insert data
|
||||||
$handle=opendir($dir);
|
$handle=opendir($dir);
|
||||||
dolibarr_install_syslog("Ouverture repertoire data ".$dir." handle=".$handle,LOG_DEBUG);
|
dolibarr_install_syslog("Open directory data ".$dir." handle=".$handle,LOG_DEBUG);
|
||||||
while (($file = readdir($handle))!==false)
|
while (($file = readdir($handle))!==false)
|
||||||
{
|
{
|
||||||
if (preg_match('/\.sql$/i',$file) && preg_match('/^llx_/i',$file))
|
if (preg_match('/\.sql$/i',$file) && preg_match('/^llx_/i',$file))
|
||||||
|
|||||||
@ -35,7 +35,7 @@
|
|||||||
delete from llx_accountingaccount;
|
delete from llx_accountingaccount;
|
||||||
delete from llx_accountingsystem;
|
delete from llx_accountingsystem;
|
||||||
|
|
||||||
insert into llx_accountingsystem (pcg_version, fk_pays, label, datec, fk_author, active) VALUES ('PCG99-ABREGE', 1, 'Plan de compte standard français abrégé', curdate(), null, 0);
|
insert into llx_accountingsystem (pcg_version, fk_pays, label, datec, fk_author, active) VALUES ('PCG99-ABREGE', 1, 'The simple accountancy french plan', CURRENT_DATE, null, 0);
|
||||||
|
|
||||||
insert into llx_accountingaccount (rowid, fk_pcg_version, pcg_type, pcg_subtype, account_number, account_parent, label) VALUES ( 1,'PCG99-ABREGE','CAPIT', 'CAPITAL', '101', '1', 'Capital');
|
insert into llx_accountingaccount (rowid, fk_pcg_version, pcg_type, pcg_subtype, account_number, account_parent, label) VALUES ( 1,'PCG99-ABREGE','CAPIT', 'CAPITAL', '101', '1', 'Capital');
|
||||||
insert into llx_accountingaccount (rowid, fk_pcg_version, pcg_type, pcg_subtype, account_number, account_parent, label) VALUES ( 2,'PCG99-ABREGE','CAPIT', 'XXXXXX', '105', '1', 'Ecarts de réévaluation');
|
insert into llx_accountingaccount (rowid, fk_pcg_version, pcg_type, pcg_subtype, account_number, account_parent, label) VALUES ( 2,'PCG99-ABREGE','CAPIT', 'XXXXXX', '105', '1', 'Ecarts de réévaluation');
|
||||||
|
|||||||
@ -16,23 +16,10 @@
|
|||||||
-- Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
-- Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||||
--
|
--
|
||||||
-- $Id$
|
-- $Id$
|
||||||
--
|
|
||||||
-- ============================================================================
|
-- ============================================================================
|
||||||
|
|
||||||
CREATE OR REPLACE FUNCTION UNIX_TIMESTAMP(TIMESTAMP WITHOUT TIME ZONE)
|
CREATE OR REPLACE FUNCTION UNIX_TIMESTAMP(TIMESTAMP WITHOUT TIME ZONE) RETURNS BIGINT LANGUAGE SQL IMMUTABLE STRICT AS 'SELECT EXTRACT(EPOCH FROM $1)::bigint;';
|
||||||
RETURNS BIGINT
|
|
||||||
LANGUAGE SQL
|
|
||||||
IMMUTABLE STRICT
|
|
||||||
AS 'SELECT EXTRACT(EPOCH FROM $1)::bigint;';
|
|
||||||
|
|
||||||
CREATE OR REPLACE FUNCTION UNIX_TIMESTAMP(TIMESTAMP WITH TIME ZONE)
|
CREATE OR REPLACE FUNCTION UNIX_TIMESTAMP(TIMESTAMP WITH TIME ZONE) RETURNS BIGINT LANGUAGE SQL IMMUTABLE STRICT AS 'SELECT EXTRACT(EPOCH FROM $1)::bigint;';
|
||||||
RETURNS BIGINT
|
|
||||||
LANGUAGE SQL
|
|
||||||
IMMUTABLE STRICT
|
|
||||||
AS 'SELECT EXTRACT(EPOCH FROM $1)::bigint;';
|
|
||||||
|
|
||||||
CREATE OR REPLACE FUNCTION FROM_UNIXTIME(BIGINT, VARCHAR)
|
CREATE OR REPLACE FUNCTION FROM_UNIXTIME(BIGINT, VARCHAR) RETURNS TIMESTAMP WITH TIME ZONE LANGUAGE SQL IMMUTABLE STRICT AS 'SELECT TIMESTAMP WITH TIME ZONE \'epoch\' + $1 * interval \'1 second\' ;';
|
||||||
RETURNS TIMESTAMP WITH TIME ZONE
|
|
||||||
LANGUAGE SQL
|
|
||||||
IMMUTABLE STRICT
|
|
||||||
AS 'SELECT TIMESTAMP WITH TIME ZONE \'epoch\' + $1 * interval \'1 second\' ;';
|
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
/* Copyright (C) 2001 Fabien Seisen <seisen@linuxfr.org>
|
/* Copyright (C) 2001 Fabien Seisen <seisen@linuxfr.org>
|
||||||
* Copyright (C) 2002-2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
|
* Copyright (C) 2002-2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
|
||||||
* Copyright (C) 2004-2008 Laurent Destailleur <eldy@users.sourceforge.net>
|
* Copyright (C) 2004-2009 Laurent Destailleur <eldy@users.sourceforge.net>
|
||||||
* Copyright (C) 2004 Sebastien Di Cintio <sdicintio@ressource-toi.org>
|
* Copyright (C) 2004 Sebastien Di Cintio <sdicintio@ressource-toi.org>
|
||||||
* Copyright (C) 2004 Benoit Mortier <benoit.mortier@opensides.be>
|
* Copyright (C) 2004 Benoit Mortier <benoit.mortier@opensides.be>
|
||||||
* Copyright (C) 2005-2009 Regis Houssin <regis@dolibarr.fr>
|
* Copyright (C) 2005-2009 Regis Houssin <regis@dolibarr.fr>
|
||||||
@ -22,9 +22,9 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
\file htdocs/lib/databases/pgsql.lib.php
|
* \file htdocs/lib/databases/pgsql.lib.php
|
||||||
\brief Fichier de la classe permettant de gerer une base pgsql
|
* \brief Fichier de la classe permettant de gerer une base pgsql
|
||||||
\version $Id$
|
* \version $Id$
|
||||||
*/
|
*/
|
||||||
// For compatibility during upgrade
|
// For compatibility during upgrade
|
||||||
if (! defined('DOL_DOCUMENT_ROOT')) define('DOL_DOCUMENT_ROOT', '../..');
|
if (! defined('DOL_DOCUMENT_ROOT')) define('DOL_DOCUMENT_ROOT', '../..');
|
||||||
@ -32,8 +32,8 @@ if (! defined('ADODB_DATE_VERSION')) include_once(DOL_DOCUMENT_ROOT."/includes/a
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
\class DoliDb
|
* \class DoliDb
|
||||||
\brief Classe permettant de gerer la database de dolibarr
|
* \brief Classe permettant de gerer la database de dolibarr
|
||||||
*/
|
*/
|
||||||
class DoliDb
|
class DoliDb
|
||||||
{
|
{
|
||||||
@ -201,17 +201,14 @@ class DoliDb
|
|||||||
$line=preg_replace('/datetime not null/i','datetime',$line);
|
$line=preg_replace('/datetime not null/i','datetime',$line);
|
||||||
$line=preg_replace('/datetime/i','timestamp',$line);
|
$line=preg_replace('/datetime/i','timestamp',$line);
|
||||||
|
|
||||||
# nuke size of timestamp
|
|
||||||
$line=preg_replace('/timestamp\([^)]*\)/i','timestamp',$line);
|
|
||||||
|
|
||||||
# double -> numeric
|
# double -> numeric
|
||||||
$line=preg_replace('/^double/i','numeric',$line);
|
$line=preg_replace('/^double/i','numeric',$line);
|
||||||
$line=preg_replace('/(\s*)double/i','\\1numeric',$line);
|
$line=preg_replace('/(\s*)double/i','\\1numeric',$line);
|
||||||
# float -> numeric
|
# float -> numeric
|
||||||
$line=preg_replace('/^float/i','numeric',$line);
|
$line=preg_replace('/^float/i','numeric',$line);
|
||||||
$line=preg_replace('/(\s*)float/i','\\1numeric',$line);
|
$line=preg_replace('/(\s*)float/i','\\1numeric',$line);
|
||||||
|
|
||||||
# unique index(field1,field2)
|
# unique index(field1,field2)
|
||||||
if (preg_match('/unique index\s*\((\w+\s*,\s*\w+)\)/i',$line))
|
if (preg_match('/unique index\s*\((\w+\s*,\s*\w+)\)/i',$line))
|
||||||
{
|
{
|
||||||
$line=preg_replace('/unique index\s*\((\w+\s*,\s*\w+)\)/i','UNIQUE\(\\1\)',$line);
|
$line=preg_replace('/unique index\s*\((\w+\s*,\s*\w+)\)/i','UNIQUE\(\\1\)',$line);
|
||||||
@ -422,9 +419,9 @@ class DoliDb
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief Effectue une requete et renvoi le resultset de reponse de la base
|
* \brief Convert request to PostgreSQL syntax, execute it and return the resultset
|
||||||
* \param query Contenu de la query
|
* \param query query string
|
||||||
* \return resource Resultset de la reponse
|
* \return resource Resultset of answer
|
||||||
*/
|
*/
|
||||||
function query($query)
|
function query($query)
|
||||||
{
|
{
|
||||||
@ -432,7 +429,7 @@ class DoliDb
|
|||||||
|
|
||||||
// Convert MySQL syntax to PostgresSQL syntax
|
// Convert MySQL syntax to PostgresSQL syntax
|
||||||
$query=$this->convertSQLFromMysql($query);
|
$query=$this->convertSQLFromMysql($query);
|
||||||
|
//print "FF\n".$query."<br>\n";
|
||||||
$ret = @pg_query($this->db, $query);
|
$ret = @pg_query($this->db, $query);
|
||||||
if (! preg_match("/^COMMIT/i",$query) && ! preg_match("/^ROLLBACK/i",$query))
|
if (! preg_match("/^COMMIT/i",$query) && ! preg_match("/^ROLLBACK/i",$query))
|
||||||
{
|
{
|
||||||
@ -695,11 +692,10 @@ class DoliDb
|
|||||||
1046 => 'DB_ERROR_NODBSELECTED',
|
1046 => 'DB_ERROR_NODBSELECTED',
|
||||||
1048 => 'DB_ERROR_CONSTRAINT',
|
1048 => 'DB_ERROR_CONSTRAINT',
|
||||||
'42P07' => 'DB_ERROR_TABLE_OR_KEY_ALREADY_EXISTS',
|
'42P07' => 'DB_ERROR_TABLE_OR_KEY_ALREADY_EXISTS',
|
||||||
1051 => 'DB_ERROR_NOSUCHTABLE',
|
'42703' => 'DB_ERROR_NOSUCHFIELD',
|
||||||
1054 => 'DB_ERROR_NOSUCHFIELD',
|
|
||||||
1060 => 'DB_ERROR_COLUMN_ALREADY_EXISTS',
|
1060 => 'DB_ERROR_COLUMN_ALREADY_EXISTS',
|
||||||
'42710' => 'DB_ERROR_KEY_NAME_ALREADY_EXISTS',
|
'42710' => 'DB_ERROR_KEY_NAME_ALREADY_EXISTS',
|
||||||
1062 => 'DB_ERROR_RECORD_ALREADY_EXISTS',
|
'23505' => 'DB_ERROR_RECORD_ALREADY_EXISTS',
|
||||||
'42704' => 'DB_ERROR_SYNTAX',
|
'42704' => 'DB_ERROR_SYNTAX',
|
||||||
'42601' => 'DB_ERROR_SYNTAX',
|
'42601' => 'DB_ERROR_SYNTAX',
|
||||||
'42P16' => 'DB_ERROR_PRIMARY_KEY_ALREADY_EXISTS',
|
'42P16' => 'DB_ERROR_PRIMARY_KEY_ALREADY_EXISTS',
|
||||||
@ -707,8 +703,8 @@ class DoliDb
|
|||||||
1091 => 'DB_ERROR_NOSUCHFIELD',
|
1091 => 'DB_ERROR_NOSUCHFIELD',
|
||||||
1100 => 'DB_ERROR_NOT_LOCKED',
|
1100 => 'DB_ERROR_NOT_LOCKED',
|
||||||
1136 => 'DB_ERROR_VALUE_COUNT_ON_ROW',
|
1136 => 'DB_ERROR_VALUE_COUNT_ON_ROW',
|
||||||
1146 => 'DB_ERROR_NOSUCHTABLE',
|
'42P01' => 'DB_ERROR_NOSUCHTABLE',
|
||||||
1216 => 'DB_ERROR_NO_PARENT',
|
'23503' => 'DB_ERROR_NO_PARENT',
|
||||||
1217 => 'DB_ERROR_CHILD_EXISTS',
|
1217 => 'DB_ERROR_CHILD_EXISTS',
|
||||||
1451 => 'DB_ERROR_CHILD_EXISTS'
|
1451 => 'DB_ERROR_CHILD_EXISTS'
|
||||||
);
|
);
|
||||||
@ -726,14 +722,14 @@ class DoliDb
|
|||||||
$errno=$errorcode?$errorcode:$errorlabel;
|
$errno=$errorcode?$errorcode:$errorlabel;
|
||||||
return ($errno?'DB_ERROR_'.$errno:'0');
|
return ($errno?'DB_ERROR_'.$errno:'0');
|
||||||
}
|
}
|
||||||
// '/(Table does not exist\.|Relation [\"\'].*[\"\'] does not exist|sequence does not exist|class ".+" not found)$/' => 'DB_ERROR_NOSUCHTABLE',
|
// '/(Table does not exist\.|Relation [\"\'].*[\"\'] does not exist|sequence does not exist|class ".+" not found)$/' => 'DB_ERROR_NOSUCHTABLE',
|
||||||
// '/table [\"\'].*[\"\'] does not exist/' => 'DB_ERROR_NOSUCHTABLE',
|
// '/table [\"\'].*[\"\'] does not exist/' => 'DB_ERROR_NOSUCHTABLE',
|
||||||
// '/Relation [\"\'].*[\"\'] already exists|Cannot insert a duplicate key into (a )?unique index.*/' => 'DB_ERROR_RECORD_ALREADY_EXISTS',
|
// '/Relation [\"\'].*[\"\'] already exists|Cannot insert a duplicate key into (a )?unique index.*/' => 'DB_ERROR_RECORD_ALREADY_EXISTS',
|
||||||
// '/divide by zero$/' => 'DB_ERROR_DIVZERO',
|
// '/divide by zero$/' => 'DB_ERROR_DIVZERO',
|
||||||
// '/pg_atoi: error in .*: can\'t parse /' => 'DB_ERROR_INVALID_NUMBER',
|
// '/pg_atoi: error in .*: can\'t parse /' => 'DB_ERROR_INVALID_NUMBER',
|
||||||
// '/ttribute [\"\'].*[\"\'] not found$|Relation [\"\'].*[\"\'] does not have attribute [\"\'].*[\"\']/' => 'DB_ERROR_NOSUCHFIELD',
|
// '/ttribute [\"\'].*[\"\'] not found$|Relation [\"\'].*[\"\'] does not have attribute [\"\'].*[\"\']/' => 'DB_ERROR_NOSUCHFIELD',
|
||||||
// '/parser: parse error at or near \"/' => 'DB_ERROR_SYNTAX',
|
// '/parser: parse error at or near \"/' => 'DB_ERROR_SYNTAX',
|
||||||
// '/referential integrity violation/' => 'DB_ERROR_CONSTRAINT'
|
// '/referential integrity violation/' => 'DB_ERROR_CONSTRAINT'
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -961,7 +957,6 @@ class DoliDb
|
|||||||
}
|
}
|
||||||
$this->free($resql);
|
$this->free($resql);
|
||||||
} else {
|
} else {
|
||||||
// version Mysql < 4.1.1
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
return $liste;
|
return $liste;
|
||||||
@ -996,7 +991,6 @@ class DoliDb
|
|||||||
}
|
}
|
||||||
$this->free($resql);
|
$this->free($resql);
|
||||||
} else {
|
} else {
|
||||||
// version Mysql < 4.1.1
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
return $liste;
|
return $liste;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user