Fix: Better postgresql compatibility
This commit is contained in:
parent
8dabc0d659
commit
c082f6e39b
@ -137,8 +137,8 @@ ALTER TABLE llx_expedition ADD COLUMN ref_customer varchar(30) AFTER entity;
|
|||||||
ALTER TABLE llx_expedition ADD COLUMN date_delivery date DEFAULT NULL AFTER date_expedition;
|
ALTER TABLE llx_expedition ADD COLUMN date_delivery date DEFAULT NULL AFTER date_expedition;
|
||||||
ALTER TABLE llx_expedition CHANGE COLUMN fk_adresse_livraison fk_address integer DEFAULT NULL;
|
ALTER TABLE llx_expedition CHANGE COLUMN fk_adresse_livraison fk_address integer DEFAULT NULL;
|
||||||
|
|
||||||
ALTER TABLE llx_livraison change ref_client ref_customer varchar(30);
|
ALTER TABLE llx_livraison CHANGE COLUMN ref_client ref_customer varchar(30);
|
||||||
ALTER TABLE llx_livraison change date_livraison date_delivery date DEFAULT NULL;
|
ALTER TABLE llx_livraison CHANGE COLUMN date_livraison date_delivery date DEFAULT NULL;
|
||||||
ALTER TABLE llx_livraison CHANGE COLUMN fk_adresse_livraison fk_address integer DEFAULT NULL;
|
ALTER TABLE llx_livraison CHANGE COLUMN fk_adresse_livraison fk_address integer DEFAULT NULL;
|
||||||
|
|
||||||
ALTER TABLE llx_c_actioncomm MODIFY libelle varchar(48) NOT NULL;
|
ALTER TABLE llx_c_actioncomm MODIFY libelle varchar(48) NOT NULL;
|
||||||
@ -254,8 +254,8 @@ ALTER TABLE llx_expedition DROP INDEX idx_expedition_fk_adresse_livraison;
|
|||||||
ALTER TABLE llx_livraison DROP FOREIGN KEY fk_livraison_fk_adresse_livraison;
|
ALTER TABLE llx_livraison DROP FOREIGN KEY fk_livraison_fk_adresse_livraison;
|
||||||
ALTER TABLE llx_livraison DROP INDEX idx_livraison_fk_adresse_livraison;
|
ALTER TABLE llx_livraison DROP INDEX idx_livraison_fk_adresse_livraison;
|
||||||
ALTER TABLE llx_societe_adresse_livraison RENAME TO llx_societe_address;
|
ALTER TABLE llx_societe_adresse_livraison RENAME TO llx_societe_address;
|
||||||
ALTER TABLE llx_societe_address CHANGE nom name varchar(60);
|
ALTER TABLE llx_societe_address CHANGE COLUMN nom name varchar(60);
|
||||||
ALTER TABLE llx_societe_address CHANGE fk_societe fk_soc integer DEFAULT 0;
|
ALTER TABLE llx_societe_address CHANGE COLUMN fk_societe fk_soc integer DEFAULT 0;
|
||||||
|
|
||||||
-- Add new spanish VAT from July 2010
|
-- Add new spanish VAT from July 2010
|
||||||
insert into llx_c_tva(rowid,fk_pays,taux,recuperableonly,localtax1,note,active) values ( 45, 4, '18','0','4','VAT standard rate from July 2010',1);
|
insert into llx_c_tva(rowid,fk_pays,taux,recuperableonly,localtax1,note,active) values ( 45, 4, '18','0','4','VAT standard rate from July 2010',1);
|
||||||
|
|||||||
@ -6,7 +6,7 @@
|
|||||||
-- when current version is 2.8.0 or higher.
|
-- when current version is 2.8.0 or higher.
|
||||||
--
|
--
|
||||||
-- To add a column: ALTER TABLE llx_table ADD COLUMN newcol varchar(60) NOT NULL DEFAULT '0' AFTER existingcol;
|
-- To add a column: ALTER TABLE llx_table ADD COLUMN newcol varchar(60) NOT NULL DEFAULT '0' AFTER existingcol;
|
||||||
-- To rename a column: ALTER TABLE llx_table CHANGE oldname newname varchar(60);
|
-- To rename a column: ALTER TABLE llx_table CHANGE COLUMN oldname newname varchar(60);
|
||||||
-- To change type of field: ALTER TABLE llx_table MODIFY name varchar(60);
|
-- To change type of field: ALTER TABLE llx_table MODIFY name varchar(60);
|
||||||
--
|
--
|
||||||
|
|
||||||
|
|||||||
@ -259,6 +259,7 @@ function run_sql($sqlfile,$silent=1,$entity='',$usesavepoint=1)
|
|||||||
'DB_ERROR_NOSUCHTABLE',
|
'DB_ERROR_NOSUCHTABLE',
|
||||||
'DB_ERROR_NOSUCHFIELD',
|
'DB_ERROR_NOSUCHFIELD',
|
||||||
'DB_ERROR_NO_FOREIGN_KEY_TO_DROP',
|
'DB_ERROR_NO_FOREIGN_KEY_TO_DROP',
|
||||||
|
'DB_ERROR_NO_INDEX_TO_DROP',
|
||||||
'DB_ERROR_CANNOT_CREATE', // Qd contrainte deja existante
|
'DB_ERROR_CANNOT_CREATE', // Qd contrainte deja existante
|
||||||
'DB_ERROR_CANT_DROP_PRIMARY_KEY',
|
'DB_ERROR_CANT_DROP_PRIMARY_KEY',
|
||||||
'DB_ERROR_PRIMARY_KEY_ALREADY_EXISTS'
|
'DB_ERROR_PRIMARY_KEY_ALREADY_EXISTS'
|
||||||
|
|||||||
@ -212,12 +212,24 @@ class DoliDb
|
|||||||
$line=preg_replace('/ALTER TABLE [a-z0-9_]+ DROP INDEX/i','DROP INDEX',$line);
|
$line=preg_replace('/ALTER TABLE [a-z0-9_]+ DROP INDEX/i','DROP INDEX',$line);
|
||||||
|
|
||||||
# Translate order to rename fields
|
# Translate order to rename fields
|
||||||
if (preg_match('/ALTER TABLE ([a-z0-9_]+) CHANGE COLUMN ([a-z0-9_]+) ([a-z0-9_]+)(.*)$/i',$line,$reg))
|
if (preg_match('/ALTER TABLE ([a-z0-9_]+) CHANGE(?: COLUMN)? ([a-z0-9_]+) ([a-z0-9_]+)(.*)$/i',$line,$reg))
|
||||||
{
|
{
|
||||||
$line = "-- ".$line." replaced by --\n";
|
$line = "-- ".$line." replaced by --\n";
|
||||||
$line.= "ALTER TABLE ".$reg[1]." RENAME COLUMN ".$reg[2]." TO ".$reg[3];
|
$line.= "ALTER TABLE ".$reg[1]." RENAME COLUMN ".$reg[2]." TO ".$reg[3];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Translate order to modify field format
|
||||||
|
if (preg_match('/ALTER TABLE ([a-z0-9_]+) MODIFY(?: COLUMN)? ([a-z0-9_]+) (.*)$/i',$line,$reg))
|
||||||
|
{
|
||||||
|
$line = "-- ".$line." replaced by --\n";
|
||||||
|
$newreg3=$reg[3];
|
||||||
|
$newreg3=preg_replace('/ NOT NULL/i','',$newreg3);
|
||||||
|
$newreg3=preg_replace('/ NULL/i','',$newreg3);
|
||||||
|
$newreg3=preg_replace('/ DEFAULT 0/i','',$newreg3);
|
||||||
|
$newreg3=preg_replace('/ DEFAULT \'[0-9a-zA-Z_@]*\'/i','',$newreg3);
|
||||||
|
$line.= "ALTER TABLE ".$reg[1]." ALTER COLUMN ".$reg[2]." TYPE ".$newreg3;
|
||||||
|
}
|
||||||
|
|
||||||
# alter table add primary key (field1, field2 ...) -> We remove the primary key name not accepted by PostGreSQL
|
# alter table add primary key (field1, field2 ...) -> We remove the primary key name not accepted by PostGreSQL
|
||||||
# ALTER TABLE llx_dolibarr_modules ADD PRIMARY KEY pk_dolibarr_modules (numero, entity);
|
# ALTER TABLE llx_dolibarr_modules ADD PRIMARY KEY pk_dolibarr_modules (numero, entity);
|
||||||
if (preg_match('/ALTER\s+TABLE\s*(.*)\s*ADD\s+PRIMARY\s+KEY\s*(.*)\s*\((.*)$/i',$line,$reg))
|
if (preg_match('/ALTER\s+TABLE\s*(.*)\s*ADD\s+PRIMARY\s+KEY\s*(.*)\s*\((.*)$/i',$line,$reg))
|
||||||
@ -261,6 +273,7 @@ class DoliDb
|
|||||||
|
|
||||||
// Replace espacing \' by ''
|
// Replace espacing \' by ''
|
||||||
$line=preg_replace("/\\\'/","''",$line);
|
$line=preg_replace("/\\\'/","''",$line);
|
||||||
|
|
||||||
//print $line."\n";
|
//print $line."\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -741,7 +754,7 @@ class DoliDb
|
|||||||
42701=> 'DB_ERROR_COLUMN_ALREADY_EXISTS',
|
42701=> 'DB_ERROR_COLUMN_ALREADY_EXISTS',
|
||||||
'42710' => 'DB_ERROR_KEY_NAME_ALREADY_EXISTS',
|
'42710' => 'DB_ERROR_KEY_NAME_ALREADY_EXISTS',
|
||||||
'23505' => 'DB_ERROR_RECORD_ALREADY_EXISTS',
|
'23505' => 'DB_ERROR_RECORD_ALREADY_EXISTS',
|
||||||
'42704' => 'DB_ERROR_SYNTAX',
|
'42704' => 'DB_ERROR_NO_INDEX_TO_DROP',
|
||||||
'42601' => 'DB_ERROR_SYNTAX',
|
'42601' => 'DB_ERROR_SYNTAX',
|
||||||
'42P16' => 'DB_ERROR_PRIMARY_KEY_ALREADY_EXISTS',
|
'42P16' => 'DB_ERROR_PRIMARY_KEY_ALREADY_EXISTS',
|
||||||
1075 => 'DB_ERROR_CANT_DROP_PRIMARY_KEY',
|
1075 => 'DB_ERROR_CANT_DROP_PRIMARY_KEY',
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user