Qual: More portable SQL
This commit is contained in:
parent
6cebe47a42
commit
a3b57d20e5
@ -1,6 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
/* Copyright (C) 2004 Rodolphe Quiedeville <rodolphe@quiedeville.org>
|
/* Copyright (C) 2004 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>
|
||||||
*
|
*
|
||||||
* This program is free software; you can redistribute it and/or modify
|
* 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
|
* it under the terms of the GNU General Public License as published by
|
||||||
@ -18,10 +18,10 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
\file htdocs/install/etape2.php
|
* \file htdocs/install/etape2.php
|
||||||
\ingroup install
|
* \ingroup install
|
||||||
\brief Cree les tables, cles primaires, cles etrangeres, index et fonctions en base puis charge les donnees de reference
|
* \brief Cree les tables, cles primaires, cles etrangeres, index et fonctions en base puis charge les donnees de reference
|
||||||
\version $Id$
|
* \version $Id$
|
||||||
*/
|
*/
|
||||||
|
|
||||||
include("./inc.php");
|
include("./inc.php");
|
||||||
@ -289,8 +289,8 @@ if ($_POST["action"] == "set")
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
print "<tr><td>".$langs->trans("CreateOtherKeysForTable",$name);
|
print "<tr><td>".$langs->trans("CreateOtherKeysForTable",$name);
|
||||||
print "<br>".$langs->trans("Request").' '.$requestnb.' : '.$buffer;
|
print "<br>\n".$langs->trans("Request").' '.$requestnb.' : '.$db->lastqueryerror();
|
||||||
print "</td>";
|
print "\n</td>";
|
||||||
print "<td>".$langs->trans("Error")." ".$db->errno()." ".$db->error()."</td></tr>";
|
print "<td>".$langs->trans("Error")." ".$db->errno()." ".$db->error()."</td></tr>";
|
||||||
$error++;
|
$error++;
|
||||||
}
|
}
|
||||||
@ -400,7 +400,7 @@ if ($_POST["action"] == "set")
|
|||||||
|
|
||||||
// Creation donnees
|
// Creation donnees
|
||||||
$handle=opendir($dir);
|
$handle=opendir($dir);
|
||||||
dolibarr_install_syslog("Ouverture repertoire ".$dir." handle=".$handle,LOG_DEBUG);
|
dolibarr_install_syslog("Ouverture repertoire 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))
|
||||||
|
|||||||
24
htdocs/install/mysql/tables/llx_co_exp.key.sql
Normal file
24
htdocs/install/mysql/tables/llx_co_exp.key.sql
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
-- ===================================================================
|
||||||
|
-- Copyright (C) 2003 Rodolphe Quiedeville <rodolphe@quiedeville.org>
|
||||||
|
-- Copyright (C) 2008 Regis Houssin <regis@dolibarr.fr>
|
||||||
|
-- Copyright (C) 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_co_exp ADD INDEX idx_co_exp_fk_commande (fk_commande);
|
||||||
|
ALTER TABLE llx_co_exp ADD INDEX idx_co_exp_fk_expedition (fk_expedition);
|
||||||
@ -23,8 +23,5 @@ create table llx_co_exp
|
|||||||
(
|
(
|
||||||
rowid integer AUTO_INCREMENT PRIMARY KEY,
|
rowid integer AUTO_INCREMENT PRIMARY KEY,
|
||||||
fk_commande integer NOT NULL,
|
fk_commande integer NOT NULL,
|
||||||
fk_expedition integer NOT NULL,
|
fk_expedition integer NOT NULL
|
||||||
|
|
||||||
key(fk_commande),
|
|
||||||
key(fk_expedition)
|
|
||||||
)type=innodb;
|
)type=innodb;
|
||||||
|
|||||||
24
htdocs/install/mysql/tables/llx_co_fa.key.sql
Normal file
24
htdocs/install/mysql/tables/llx_co_fa.key.sql
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
-- ===================================================================
|
||||||
|
-- Copyright (C) 2003 Rodolphe Quiedeville <rodolphe@quiedeville.org>
|
||||||
|
-- Copyright (C) 2008 Regis Houssin <regis@dolibarr.fr>
|
||||||
|
-- Copyright (C) 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_co_fa ADD INDEX idx_co_fa_fk_commande (fk_commande);
|
||||||
|
ALTER TABLE llx_co_fa ADD INDEX idx_co_fa_fk_facture (fk_facture);
|
||||||
@ -22,8 +22,5 @@ create table llx_co_fa
|
|||||||
(
|
(
|
||||||
rowid integer AUTO_INCREMENT PRIMARY KEY,
|
rowid integer AUTO_INCREMENT PRIMARY KEY,
|
||||||
fk_commande integer NOT NULL,
|
fk_commande integer NOT NULL,
|
||||||
fk_facture integer NOT NULL,
|
fk_facture integer NOT NULL
|
||||||
|
|
||||||
key(fk_commande),
|
|
||||||
key(fk_facture)
|
|
||||||
)type=innodb;
|
)type=innodb;
|
||||||
|
|||||||
24
htdocs/install/mysql/tables/llx_co_liv.key.sql
Normal file
24
htdocs/install/mysql/tables/llx_co_liv.key.sql
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
-- ===================================================================
|
||||||
|
-- Copyright (C) 2003 Rodolphe Quiedeville <rodolphe@quiedeville.org>
|
||||||
|
-- Copyright (C) 2008 Regis Houssin <regis@dolibarr.fr>
|
||||||
|
-- Copyright (C) 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_co_liv ADD INDEX idx_co_liv_fk_commande (fk_commande);
|
||||||
|
ALTER TABLE llx_co_liv ADD INDEX idx_co_liv_fk_livraison (fk_livraison);
|
||||||
@ -23,8 +23,5 @@ create table llx_co_liv
|
|||||||
(
|
(
|
||||||
rowid integer AUTO_INCREMENT PRIMARY KEY,
|
rowid integer AUTO_INCREMENT PRIMARY KEY,
|
||||||
fk_commande integer NOT NULL,
|
fk_commande integer NOT NULL,
|
||||||
fk_livraison integer NOT NULL,
|
fk_livraison integer NOT NULL
|
||||||
|
|
||||||
key(fk_commande),
|
|
||||||
key(fk_livraison)
|
|
||||||
)type=innodb;
|
)type=innodb;
|
||||||
|
|||||||
24
htdocs/install/mysql/tables/llx_co_pr.key.sql
Normal file
24
htdocs/install/mysql/tables/llx_co_pr.key.sql
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
-- ===================================================================
|
||||||
|
-- Copyright (C) 2003 Rodolphe Quiedeville <rodolphe@quiedeville.org>
|
||||||
|
-- Copyright (C) 2008 Regis Houssin <regis@dolibarr.fr>
|
||||||
|
-- Copyright (C) 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_co_pr ADD INDEX idx_co_pr_fk_commande (fk_commande);
|
||||||
|
ALTER TABLE llx_co_pr ADD INDEX idx_co_pr_fk_propale (fk_propale);
|
||||||
24
htdocs/install/mysql/tables/llx_pr_exp.key.sql
Normal file
24
htdocs/install/mysql/tables/llx_pr_exp.key.sql
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
-- ===================================================================
|
||||||
|
-- Copyright (C) 2003 Rodolphe Quiedeville <rodolphe@quiedeville.org>
|
||||||
|
-- Copyright (C) 2008 Regis Houssin <regis@dolibarr.fr>
|
||||||
|
-- Copyright (C) 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_pr_exp ADD INDEX idx_pr_exp_fk_propal (fk_propal);
|
||||||
|
ALTER TABLE llx_pr_exp ADD INDEX idx_pr_exp_fk_expedition (fk_expedition);
|
||||||
@ -23,8 +23,5 @@ create table llx_pr_exp
|
|||||||
(
|
(
|
||||||
rowid integer AUTO_INCREMENT PRIMARY KEY,
|
rowid integer AUTO_INCREMENT PRIMARY KEY,
|
||||||
fk_propal integer NOT NULL,
|
fk_propal integer NOT NULL,
|
||||||
fk_expedition integer NOT NULL,
|
fk_expedition integer NOT NULL
|
||||||
|
|
||||||
key(fk_propal),
|
|
||||||
key(fk_expedition)
|
|
||||||
)type=innodb;
|
)type=innodb;
|
||||||
|
|||||||
24
htdocs/install/mysql/tables/llx_pr_liv.key.sql
Normal file
24
htdocs/install/mysql/tables/llx_pr_liv.key.sql
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
-- ===================================================================
|
||||||
|
-- Copyright (C) 2003 Rodolphe Quiedeville <rodolphe@quiedeville.org>
|
||||||
|
-- Copyright (C) 2008 Regis Houssin <regis@dolibarr.fr>
|
||||||
|
-- Copyright (C) 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_pr_liv ADD INDEX idx_pr_liv_fk_propal (fk_propal);
|
||||||
|
ALTER TABLE llx_pr_liv ADD INDEX idx_pr_liv_fk_livraison (fk_livraison);
|
||||||
@ -23,8 +23,5 @@ create table llx_pr_liv
|
|||||||
(
|
(
|
||||||
rowid integer AUTO_INCREMENT PRIMARY KEY,
|
rowid integer AUTO_INCREMENT PRIMARY KEY,
|
||||||
fk_propal integer NOT NULL,
|
fk_propal integer NOT NULL,
|
||||||
fk_livraison integer NOT NULL,
|
fk_livraison integer NOT NULL
|
||||||
|
|
||||||
key(fk_propal),
|
|
||||||
key(fk_livraison)
|
|
||||||
)type=innodb;
|
)type=innodb;
|
||||||
|
|||||||
21
htdocs/install/mysql/tables/llx_societe_commerciaux.key.sql
Normal file
21
htdocs/install/mysql/tables/llx_societe_commerciaux.key.sql
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
-- ===================================================================
|
||||||
|
-- Copyright (C) 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_societe_commerciaux ADD UNIQUE INDEX uk_societe_commerciaux (fk_soc, fk_user);
|
||||||
@ -1,5 +1,6 @@
|
|||||||
-- ========================================================================
|
-- ========================================================================
|
||||||
-- Copyright (C) 2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
|
-- Copyright (C) 2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
|
||||||
|
-- Copyright (C) 2009 Laurent Destailleur <eldy@users.sourceforge.net>
|
||||||
--
|
--
|
||||||
-- This program is free software; you can redistribute it and/or modify
|
-- 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
|
-- it under the terms of the GNU General Public License as published by
|
||||||
@ -22,8 +23,6 @@ create table llx_societe_commerciaux
|
|||||||
(
|
(
|
||||||
rowid integer AUTO_INCREMENT PRIMARY KEY,
|
rowid integer AUTO_INCREMENT PRIMARY KEY,
|
||||||
fk_soc integer,
|
fk_soc integer,
|
||||||
fk_user integer,
|
fk_user integer
|
||||||
|
|
||||||
UNIQUE INDEX(fk_soc, fk_user)
|
|
||||||
)type=innodb;
|
)type=innodb;
|
||||||
|
|
||||||
|
|||||||
@ -20,8 +20,10 @@
|
|||||||
-- ===========================================================================
|
-- ===========================================================================
|
||||||
|
|
||||||
|
|
||||||
-- Supprimme orhpelins pour permettre montée de la clé
|
-- Supprimme orhpelins pour permettre mont<EFBFBD>e de la cl<63>
|
||||||
-- V4 DELETE llx_user_rights FROM llx_user_rights LEFT JOIN llx_user ON llx_user_rights.fk_user = llx_user.rowid WHERE llx_user.rowid IS NULL;
|
-- V4 DELETE llx_user_rights FROM llx_user_rights LEFT JOIN llx_user ON llx_user_rights.fk_user = llx_user.rowid WHERE llx_user.rowid IS NULL;
|
||||||
|
|
||||||
|
|
||||||
ALTER TABLE llx_user_rights ADD CONSTRAINT fk_user_rights_fk_user_user FOREIGN KEY (fk_user) REFERENCES llx_user (rowid);
|
ALTER TABLE llx_user_rights ADD CONSTRAINT fk_user_rights_fk_user_user FOREIGN KEY (fk_user) REFERENCES llx_user (rowid);
|
||||||
|
|
||||||
|
ALTER TABLE llx_user_rights ADD UNIQUE INDEX uk_user_rights (fk_user, fk_id);
|
||||||
|
|||||||
@ -22,8 +22,6 @@ create table llx_user_rights
|
|||||||
(
|
(
|
||||||
rowid integer AUTO_INCREMENT PRIMARY KEY,
|
rowid integer AUTO_INCREMENT PRIMARY KEY,
|
||||||
fk_user integer NOT NULL,
|
fk_user integer NOT NULL,
|
||||||
fk_id integer NOT NULL,
|
fk_id integer NOT NULL
|
||||||
|
|
||||||
UNIQUE INDEX(fk_user,fk_id)
|
|
||||||
)type=innodb;
|
)type=innodb;
|
||||||
|
|
||||||
|
|||||||
@ -161,7 +161,8 @@ class DoliDb
|
|||||||
return $line;
|
return $line;
|
||||||
}
|
}
|
||||||
if ($line != "")
|
if ($line != "")
|
||||||
{ # we are inside create table statement so lets process datatypes
|
{
|
||||||
|
# we are inside create table statement so lets process datatypes
|
||||||
if (preg_match('/(ISAM|innodb)/i',$line)) { # end of create table sequence
|
if (preg_match('/(ISAM|innodb)/i',$line)) { # end of create table sequence
|
||||||
$line=preg_replace('/\)[\s\t]*type=(MyISAM|innodb);/i',');',$line);
|
$line=preg_replace('/\)[\s\t]*type=(MyISAM|innodb);/i',');',$line);
|
||||||
$line=preg_replace('/\)[\s\t]*engine=(MyISAM|innodb);/i',');',$line);
|
$line=preg_replace('/\)[\s\t]*engine=(MyISAM|innodb);/i',');',$line);
|
||||||
@ -172,20 +173,7 @@ class DoliDb
|
|||||||
$line=preg_replace('/[\s\t]*([a-zA-Z_0-9]*)[\s\t]*.*int.*auto_increment[^,]*/i','\\1 SERIAL PRIMARY KEY',$line);
|
$line=preg_replace('/[\s\t]*([a-zA-Z_0-9]*)[\s\t]*.*int.*auto_increment[^,]*/i','\\1 SERIAL PRIMARY KEY',$line);
|
||||||
}
|
}
|
||||||
|
|
||||||
# int type conversion
|
# tinyint type conversion
|
||||||
/* } elsif (/(\w*)int\(\d+\)/i) {
|
|
||||||
$size=$1;
|
|
||||||
$size =~ tr [A-Z] [a-z];
|
|
||||||
if ($size eq "tiny" || $size eq "small") {
|
|
||||||
$out = "int2";
|
|
||||||
} elsif ($size eq "big") {
|
|
||||||
$out = "int8";
|
|
||||||
} else {
|
|
||||||
$out = "int4";
|
|
||||||
}
|
|
||||||
s/\w*int\(\d+\)/$out/g;
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
$line=str_replace('tinyint','smallint',$line);
|
$line=str_replace('tinyint','smallint',$line);
|
||||||
|
|
||||||
# nuke unsigned
|
# nuke unsigned
|
||||||
@ -223,78 +211,22 @@ class DoliDb
|
|||||||
$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 key(field1,field2)
|
|
||||||
/* if (/unique key\s*\((\w+\s*,\s*\w+)\)/i) {
|
|
||||||
s/unique key\s*\((\w+\s*,\s*\w+)\)/UNIQUE\($1\)/i;
|
|
||||||
$create_sql.=$_;
|
|
||||||
next;
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
# 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);
|
||||||
}
|
}
|
||||||
# unique key [name] (field)
|
|
||||||
/* if (/unique key\s*(\w*)\s*\((\w+)\)/i) {
|
# alter table create [unique] index (field1, field2 ...)
|
||||||
s/unique key\s*(\w*)\s*\((\w+)\)/UNIQUE\($2\)/i;
|
# ALTER TABLE llx_accountingaccount ADD INDEX idx_accountingaccount_fk_pcg_version (fk_pcg_version)
|
||||||
my $idxname=($1?"$1":"idx_${table}_$2");
|
if (preg_match('/ALTER\s*TABLE\s*(.*)\s*ADD\s*(UNIQUE)?\s*(INDEX)?\s*(.*)\s*\(([\w,\s]+)\)/i',$line,$reg))
|
||||||
$create_sql.=$_;
|
{
|
||||||
$create_index .= "CREATE INDEX $idxname ON $table ($2);\n";
|
$fieldlist=$reg[5];
|
||||||
next;
|
$idxname=$reg[4];
|
||||||
|
$tablename=$reg[1];
|
||||||
|
$line = "-- ".$line." replaced by --\n";
|
||||||
|
$line.= "CREATE ".($reg[2]?$reg[2].' ':'')."INDEX ".$idxname." ON ".$tablename." (".$fieldlist.")";
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
# unique index [name] (field)
|
|
||||||
/* if (/unique index\s*(\w*)\s*\((\w+)\)/i) {
|
|
||||||
s/unique index\s*(\w*)\s*\((\w+)\)/UNIQUE\($2\)/i;
|
|
||||||
my $idxname=($1?"$1":"idx_${table}_$2");
|
|
||||||
$create_sql.=$_;
|
|
||||||
$create_index .= "CREATE INDEX $idxname ON $table ($2);\n";
|
|
||||||
next;
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
# unique (field) et unique (field1, field2 ...)
|
|
||||||
/* if (/unique\s*\(([\w,\s]+)\)/i) {
|
|
||||||
s/unique\s*\(([\w,\s]+)\)/UNIQUE\($1\)/i;
|
|
||||||
my $fieldlist="$1";
|
|
||||||
my $idxname="idx_${table}_${fieldlist}";
|
|
||||||
$idxname =~ s/\W/_/g; $idxname =~ tr/_/_/s;
|
|
||||||
$create_sql.=$_;
|
|
||||||
$create_index .= "CREATE INDEX $idxname ON $table ($fieldlist);\n";
|
|
||||||
next;
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
# index(field)
|
|
||||||
/* if (/index\s*(\w*)\s*\((\w+)\)/i) {
|
|
||||||
my $idxname=($1?"$1":"idx_${table}_$2");
|
|
||||||
$create_index .= "CREATE INDEX $idxname ON $table ($2);\n";
|
|
||||||
next;
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
# primary key
|
|
||||||
/* if (/\bkey\b/i && !/^\s+primary key\s+/i) {
|
|
||||||
s/KEY(\s+)[^(]*(\s+)/$1 UNIQUE $2/i; # hack off name of the non-primary key
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
# key(xxx)
|
|
||||||
/* if (/key\s*\((\w+)\)/i) {
|
|
||||||
my $idxname="idx_${table}_$1";
|
|
||||||
$create_index .= "CREATE INDEX $idxname ON $table ($1);\n";
|
|
||||||
next;
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
# Quote column names
|
|
||||||
/* s/(^\s*)([^\s\-\(]+)(\s*)/$1"$2"$3/gi if (!/\bkey\b/i);
|
|
||||||
*/
|
|
||||||
# Remap colums with names of existing system attribute
|
|
||||||
/* if (/"oid"/i) {
|
|
||||||
s/"oid"/"_oid"/g;
|
|
||||||
print STDERR "WARNING: table $table uses column \"oid\" which is renamed to \"_oid\"\nYou should fix application manually! Press return to continue.";
|
|
||||||
my $wait=<STDIN>;
|
|
||||||
}
|
|
||||||
s/oid/_oid/i if (/key/i && /oid/i); # fix oid in key
|
|
||||||
$create_sql.=$_;
|
|
||||||
*/
|
|
||||||
} # END of if ($create_sql ne "") i.e. were inside create table statement so processed datatypes
|
} # END of if ($create_sql ne "") i.e. were inside create table statement so processed datatypes
|
||||||
else { # not inside create table
|
else { # not inside create table
|
||||||
#---- fix data in inserted data: (from MS world)
|
#---- fix data in inserted data: (from MS world)
|
||||||
@ -503,7 +435,7 @@ class DoliDb
|
|||||||
$this->lasterror = $this->error();
|
$this->lasterror = $this->error();
|
||||||
$this->lasterrno = $this->errno();
|
$this->lasterrno = $this->errno();
|
||||||
//print "\n>> ".$query."<br>\n";
|
//print "\n>> ".$query."<br>\n";
|
||||||
//print '>> '.$this->lasterrno.' - '.$this->lasterror.' - '.$this->laqtqueryerror."<br>\n";
|
//print '>> '.$this->lasterrno.' - '.$this->lasterror.' - '.$this->lastqueryerror."<br>\n";
|
||||||
}
|
}
|
||||||
$this->lastquery=$query;
|
$this->lastquery=$query;
|
||||||
$this->results = $ret;
|
$this->results = $ret;
|
||||||
@ -758,7 +690,7 @@ class DoliDb
|
|||||||
1051 => 'DB_ERROR_NOSUCHTABLE',
|
1051 => 'DB_ERROR_NOSUCHTABLE',
|
||||||
1054 => 'DB_ERROR_NOSUCHFIELD',
|
1054 => 'DB_ERROR_NOSUCHFIELD',
|
||||||
1060 => 'DB_ERROR_COLUMN_ALREADY_EXISTS',
|
1060 => 'DB_ERROR_COLUMN_ALREADY_EXISTS',
|
||||||
1061 => 'DB_ERROR_KEY_NAME_ALREADY_EXISTS',
|
'42710' => 'DB_ERROR_KEY_NAME_ALREADY_EXISTS',
|
||||||
1062 => 'DB_ERROR_RECORD_ALREADY_EXISTS',
|
1062 => 'DB_ERROR_RECORD_ALREADY_EXISTS',
|
||||||
'42704' => 'DB_ERROR_SYNTAX',
|
'42704' => 'DB_ERROR_SYNTAX',
|
||||||
'42601' => 'DB_ERROR_SYNTAX',
|
'42601' => 'DB_ERROR_SYNTAX',
|
||||||
@ -786,30 +718,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',
|
||||||
// TODO Virer cela
|
// '/table [\"\'].*[\"\'] does not exist/' => 'DB_ERROR_NOSUCHTABLE',
|
||||||
if (empty($error_regexps))
|
// '/Relation [\"\'].*[\"\'] already exists|Cannot insert a duplicate key into (a )?unique index.*/' => 'DB_ERROR_RECORD_ALREADY_EXISTS',
|
||||||
{
|
// '/divide by zero$/' => 'DB_ERROR_DIVZERO',
|
||||||
$error_regexps = array(
|
// '/pg_atoi: error in .*: can\'t parse /' => 'DB_ERROR_INVALID_NUMBER',
|
||||||
'/(Table does not exist\.|Relation [\"\'].*[\"\'] does not exist|sequence does not exist|class ".+" not found)$/' => 'DB_ERROR_NOSUCHTABLE',
|
// '/ttribute [\"\'].*[\"\'] not found$|Relation [\"\'].*[\"\'] does not have attribute [\"\'].*[\"\']/' => 'DB_ERROR_NOSUCHFIELD',
|
||||||
'/table [\"\'].*[\"\'] does not exist/' => 'DB_ERROR_NOSUCHTABLE',
|
// '/parser: parse error at or near \"/' => 'DB_ERROR_SYNTAX',
|
||||||
'/Relation [\"\'].*[\"\'] already exists|Cannot insert a duplicate key into (a )?unique index.*/' => 'DB_ERROR_RECORD_ALREADY_EXISTS',
|
// '/referential integrity violation/' => 'DB_ERROR_CONSTRAINT'
|
||||||
'/divide by zero$/' => 'DB_ERROR_DIVZERO',
|
|
||||||
'/pg_atoi: error in .*: can\'t parse /' => 'DB_ERROR_INVALID_NUMBER',
|
|
||||||
'/ttribute [\"\'].*[\"\'] not found$|Relation [\"\'].*[\"\'] does not have attribute [\"\'].*[\"\']/' => 'DB_ERROR_NOSUCHFIELD',
|
|
||||||
'/parser: parse error at or near \"/' => 'DB_ERROR_SYNTAX',
|
|
||||||
'/referential integrity violation/' => 'DB_ERROR_CONSTRAINT'
|
|
||||||
);
|
|
||||||
}
|
|
||||||
print 'WW'.pg_last_error($this->db).'WW';
|
|
||||||
$valerror=pg_last_error($this->db);
|
|
||||||
foreach ($error_regexps as $regexp => $code) {
|
|
||||||
if (preg_match($regexp,$valerror)) {
|
|
||||||
return $code;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
$errno=$valerror;
|
|
||||||
return ($errno?'DB_ERROR':'0');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user