mirror of
https://github.com/Dolibarr/dolibarr.git
synced 2026-02-13 03:12:35 +01:00
PSR2 space after comma in function call
This commit is contained in:
@@ -83,7 +83,7 @@ class DoliDBPgsql extends DoliDB
|
||||
$this->connected = false;
|
||||
$this->ok = false;
|
||||
$this->error="Pgsql PHP functions are not available in this version of PHP";
|
||||
dol_syslog(get_class($this)."::DoliDBPgsql : Pgsql PHP functions are not available in this version of PHP",LOG_ERR);
|
||||
dol_syslog(get_class($this)."::DoliDBPgsql : Pgsql PHP functions are not available in this version of PHP", LOG_ERR);
|
||||
return $this->ok;
|
||||
}
|
||||
|
||||
@@ -92,7 +92,7 @@ class DoliDBPgsql extends DoliDB
|
||||
$this->connected = false;
|
||||
$this->ok = false;
|
||||
$this->error=$langs->trans("ErrorWrongHostParameter");
|
||||
dol_syslog(get_class($this)."::DoliDBPgsql : Erreur Connect, wrong host parameters",LOG_ERR);
|
||||
dol_syslog(get_class($this)."::DoliDBPgsql : Erreur Connect, wrong host parameters", LOG_ERR);
|
||||
return $this->ok;
|
||||
}
|
||||
|
||||
@@ -111,7 +111,7 @@ class DoliDBPgsql extends DoliDB
|
||||
$this->connected = false;
|
||||
$this->ok = false;
|
||||
$this->error='Host, login or password incorrect';
|
||||
dol_syslog(get_class($this)."::DoliDBPgsql : Erreur Connect ".$this->error,LOG_ERR);
|
||||
dol_syslog(get_class($this)."::DoliDBPgsql : Erreur Connect ".$this->error, LOG_ERR);
|
||||
}
|
||||
|
||||
// Si connexion serveur ok et si connexion base demandee, on essaie connexion base
|
||||
@@ -129,7 +129,7 @@ class DoliDBPgsql extends DoliDB
|
||||
$this->database_name = '';
|
||||
$this->ok = false;
|
||||
$this->error=$this->error();
|
||||
dol_syslog(get_class($this)."::DoliDBPgsql : Erreur Select_db ".$this->error,LOG_ERR);
|
||||
dol_syslog(get_class($this)."::DoliDBPgsql : Erreur Select_db ".$this->error, LOG_ERR);
|
||||
}
|
||||
}
|
||||
else
|
||||
@@ -153,11 +153,11 @@ class DoliDBPgsql extends DoliDB
|
||||
static function convertSQLFromMysql($line,$type='auto',$unescapeslashquot=false)
|
||||
{
|
||||
// Removed empty line if this is a comment line for SVN tagging
|
||||
if (preg_match('/^--\s\$Id/i',$line)) {
|
||||
if (preg_match('/^--\s\$Id/i', $line)) {
|
||||
return '';
|
||||
}
|
||||
// Return line if this is a comment
|
||||
if (preg_match('/^#/i',$line) || preg_match('/^$/i',$line) || preg_match('/^--/i',$line))
|
||||
if (preg_match('/^#/i', $line) || preg_match('/^$/i', $line) || preg_match('/^--/i', $line))
|
||||
{
|
||||
return $line;
|
||||
}
|
||||
@@ -172,103 +172,103 @@ class DoliDBPgsql extends DoliDB
|
||||
|
||||
if ($type == 'auto')
|
||||
{
|
||||
if (preg_match('/ALTER TABLE/i',$line)) $type='dml';
|
||||
else if (preg_match('/CREATE TABLE/i',$line)) $type='dml';
|
||||
else if (preg_match('/DROP TABLE/i',$line)) $type='dml';
|
||||
if (preg_match('/ALTER TABLE/i', $line)) $type='dml';
|
||||
else if (preg_match('/CREATE TABLE/i', $line)) $type='dml';
|
||||
else if (preg_match('/DROP TABLE/i', $line)) $type='dml';
|
||||
}
|
||||
|
||||
$line=preg_replace('/ as signed\)/i',' as integer)',$line);
|
||||
$line=preg_replace('/ as signed\)/i', ' as integer)', $line);
|
||||
|
||||
if ($type == 'dml')
|
||||
{
|
||||
$line=preg_replace('/\s/',' ',$line); // Replace tabulation with space
|
||||
$line=preg_replace('/\s/', ' ', $line); // Replace tabulation with space
|
||||
|
||||
// we are inside create table statement so lets process datatypes
|
||||
if (preg_match('/(ISAM|innodb)/i',$line)) { // end of create table sequence
|
||||
$line=preg_replace('/\)[\s\t]*type[\s\t]*=[\s\t]*(MyISAM|innodb).*;/i',');',$line);
|
||||
$line=preg_replace('/\)[\s\t]*engine[\s\t]*=[\s\t]*(MyISAM|innodb).*;/i',');',$line);
|
||||
$line=preg_replace('/,$/','',$line);
|
||||
if (preg_match('/(ISAM|innodb)/i', $line)) { // end of create table sequence
|
||||
$line=preg_replace('/\)[\s\t]*type[\s\t]*=[\s\t]*(MyISAM|innodb).*;/i', ');', $line);
|
||||
$line=preg_replace('/\)[\s\t]*engine[\s\t]*=[\s\t]*(MyISAM|innodb).*;/i', ');', $line);
|
||||
$line=preg_replace('/,$/', '', $line);
|
||||
}
|
||||
|
||||
// Process case: "CREATE TABLE llx_mytable(rowid integer NOT NULL AUTO_INCREMENT PRIMARY KEY,code..."
|
||||
if (preg_match('/[\s\t\(]*(\w*)[\s\t]+int.*auto_increment/i',$line,$reg)) {
|
||||
$newline=preg_replace('/([\s\t\(]*)([a-zA-Z_0-9]*)[\s\t]+int.*auto_increment[^,]*/i','\\1 \\2 SERIAL PRIMARY KEY',$line);
|
||||
if (preg_match('/[\s\t\(]*(\w*)[\s\t]+int.*auto_increment/i', $line, $reg)) {
|
||||
$newline=preg_replace('/([\s\t\(]*)([a-zA-Z_0-9]*)[\s\t]+int.*auto_increment[^,]*/i', '\\1 \\2 SERIAL PRIMARY KEY', $line);
|
||||
//$line = "-- ".$line." replaced by --\n".$newline;
|
||||
$line=$newline;
|
||||
}
|
||||
|
||||
// tinyint type conversion
|
||||
$line=preg_replace('/tinyint\(?[0-9]*\)?/','smallint',$line);
|
||||
$line=preg_replace('/tinyint/i','smallint',$line);
|
||||
$line=preg_replace('/tinyint\(?[0-9]*\)?/', 'smallint', $line);
|
||||
$line=preg_replace('/tinyint/i', 'smallint', $line);
|
||||
|
||||
// nuke unsigned
|
||||
$line=preg_replace('/(int\w+|smallint)\s+unsigned/i','\\1',$line);
|
||||
$line=preg_replace('/(int\w+|smallint)\s+unsigned/i', '\\1', $line);
|
||||
|
||||
// blob -> text
|
||||
$line=preg_replace('/\w*blob/i','text',$line);
|
||||
$line=preg_replace('/\w*blob/i', 'text', $line);
|
||||
|
||||
// tinytext/mediumtext -> text
|
||||
$line=preg_replace('/tinytext/i','text',$line);
|
||||
$line=preg_replace('/mediumtext/i','text',$line);
|
||||
$line=preg_replace('/longtext/i','text',$line);
|
||||
$line=preg_replace('/tinytext/i', 'text', $line);
|
||||
$line=preg_replace('/mediumtext/i', 'text', $line);
|
||||
$line=preg_replace('/longtext/i', 'text', $line);
|
||||
|
||||
$line=preg_replace('/text\([0-9]+\)/i','text',$line);
|
||||
$line=preg_replace('/text\([0-9]+\)/i', 'text', $line);
|
||||
|
||||
// change not null datetime field to null valid ones
|
||||
// (to support remapping of "zero time" to null
|
||||
$line=preg_replace('/datetime not null/i','datetime',$line);
|
||||
$line=preg_replace('/datetime/i','timestamp',$line);
|
||||
$line=preg_replace('/datetime not null/i', 'datetime', $line);
|
||||
$line=preg_replace('/datetime/i', 'timestamp', $line);
|
||||
|
||||
// double -> numeric
|
||||
$line=preg_replace('/^double/i','numeric',$line);
|
||||
$line=preg_replace('/(\s*)double/i','\\1numeric',$line);
|
||||
$line=preg_replace('/^double/i', 'numeric', $line);
|
||||
$line=preg_replace('/(\s*)double/i', '\\1numeric', $line);
|
||||
// float -> numeric
|
||||
$line=preg_replace('/^float/i','numeric',$line);
|
||||
$line=preg_replace('/(\s*)float/i','\\1numeric',$line);
|
||||
$line=preg_replace('/^float/i', 'numeric', $line);
|
||||
$line=preg_replace('/(\s*)float/i', '\\1numeric', $line);
|
||||
|
||||
//Check tms timestamp field case (in Mysql this field is defautled to now and
|
||||
// on update defaulted by now
|
||||
$line=preg_replace('/(\s*)tms(\s*)timestamp/i','\\1tms timestamp without time zone DEFAULT now() NOT NULL',$line);
|
||||
$line=preg_replace('/(\s*)tms(\s*)timestamp/i', '\\1tms timestamp without time zone DEFAULT now() NOT NULL', $line);
|
||||
|
||||
// nuke ON UPDATE CURRENT_TIMESTAMP
|
||||
$line=preg_replace('/(\s*)on(\s*)update(\s*)CURRENT_TIMESTAMP/i','\\1',$line);
|
||||
$line=preg_replace('/(\s*)on(\s*)update(\s*)CURRENT_TIMESTAMP/i', '\\1', $line);
|
||||
|
||||
// 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);
|
||||
}
|
||||
|
||||
// We remove end of requests "AFTER fieldxxx"
|
||||
$line=preg_replace('/\sAFTER [a-z0-9_]+/i','',$line);
|
||||
$line=preg_replace('/\sAFTER [a-z0-9_]+/i', '', $line);
|
||||
|
||||
// We remove start of requests "ALTER TABLE tablexxx" if this is a DROP INDEX
|
||||
$line=preg_replace('/ALTER TABLE [a-z0-9_]+\s+DROP INDEX/i','DROP INDEX',$line);
|
||||
$line=preg_replace('/ALTER TABLE [a-z0-9_]+\s+DROP INDEX/i', 'DROP INDEX', $line);
|
||||
|
||||
// Translate order to rename fields
|
||||
if (preg_match('/ALTER TABLE ([a-z0-9_]+)\s+CHANGE(?: COLUMN)? ([a-z0-9_]+) ([a-z0-9_]+)(.*)$/i',$line,$reg))
|
||||
if (preg_match('/ALTER TABLE ([a-z0-9_]+)\s+CHANGE(?: COLUMN)? ([a-z0-9_]+) ([a-z0-9_]+)(.*)$/i', $line, $reg))
|
||||
{
|
||||
$line = "-- ".$line." replaced by --\n";
|
||||
$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_]+)\s+MODIFY(?: COLUMN)? ([a-z0-9_]+) (.*)$/i',$line,$reg))
|
||||
if (preg_match('/ALTER TABLE ([a-z0-9_]+)\s+MODIFY(?: COLUMN)? ([a-z0-9_]+) (.*)$/i', $line, $reg))
|
||||
{
|
||||
$line = "-- ".$line." replaced by --\n";
|
||||
$newreg3=$reg[3];
|
||||
$newreg3=preg_replace('/ DEFAULT NULL/i','',$newreg3);
|
||||
$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);
|
||||
$newreg3=preg_replace('/ DEFAULT NULL/i', '', $newreg3);
|
||||
$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;
|
||||
// TODO Add alter to set default value or null/not null if there is this in $reg[3]
|
||||
}
|
||||
|
||||
// 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)
|
||||
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))
|
||||
{
|
||||
$line = "-- ".$line." replaced by --\n";
|
||||
$line.= "ALTER TABLE ".$reg[1]." ADD PRIMARY KEY (".$reg[3];
|
||||
@@ -276,7 +276,7 @@ class DoliDBPgsql extends DoliDB
|
||||
|
||||
// Translate order to drop primary keys
|
||||
// ALTER TABLE llx_dolibarr_modules DROP PRIMARY KEY pk_xxx
|
||||
if (preg_match('/ALTER\s+TABLE\s*(.*)\s*DROP\s+PRIMARY\s+KEY\s*([^;]+)$/i',$line,$reg))
|
||||
if (preg_match('/ALTER\s+TABLE\s*(.*)\s*DROP\s+PRIMARY\s+KEY\s*([^;]+)$/i', $line, $reg))
|
||||
{
|
||||
$line = "-- ".$line." replaced by --\n";
|
||||
$line.= "ALTER TABLE ".$reg[1]." DROP CONSTRAINT ".$reg[2];
|
||||
@@ -284,7 +284,7 @@ class DoliDBPgsql extends DoliDB
|
||||
|
||||
// Translate order to drop foreign keys
|
||||
// ALTER TABLE llx_dolibarr_modules DROP FOREIGN KEY fk_xxx
|
||||
if (preg_match('/ALTER\s+TABLE\s*(.*)\s*DROP\s+FOREIGN\s+KEY\s*(.*)$/i',$line,$reg))
|
||||
if (preg_match('/ALTER\s+TABLE\s*(.*)\s*DROP\s+FOREIGN\s+KEY\s*(.*)$/i', $line, $reg))
|
||||
{
|
||||
$line = "-- ".$line." replaced by --\n";
|
||||
$line.= "ALTER TABLE ".$reg[1]." DROP CONSTRAINT ".$reg[2];
|
||||
@@ -292,66 +292,66 @@ class DoliDBPgsql extends DoliDB
|
||||
|
||||
// Translate order to add foreign keys
|
||||
// ALTER TABLE llx_tablechild ADD CONSTRAINT fk_tablechild_fk_fieldparent FOREIGN KEY (fk_fieldparent) REFERENCES llx_tableparent (rowid)
|
||||
if (preg_match('/ALTER\s+TABLE\s+(.*)\s*ADD CONSTRAINT\s+(.*)\s*FOREIGN\s+KEY\s*(.*)$/i',$line,$reg))
|
||||
if (preg_match('/ALTER\s+TABLE\s+(.*)\s*ADD CONSTRAINT\s+(.*)\s*FOREIGN\s+KEY\s*(.*)$/i', $line, $reg))
|
||||
{
|
||||
$line=preg_replace('/;$/','',$line);
|
||||
$line=preg_replace('/;$/', '', $line);
|
||||
$line.=" DEFERRABLE INITIALLY IMMEDIATE;";
|
||||
}
|
||||
|
||||
// alter table add [unique] [index] (field1, field2 ...)
|
||||
// ALTER TABLE llx_accountingaccount ADD INDEX idx_accountingaccount_fk_pcg_version (fk_pcg_version)
|
||||
if (preg_match('/ALTER\s+TABLE\s*(.*)\s*ADD\s+(UNIQUE INDEX|INDEX|UNIQUE)\s+(.*)\s*\(([\w,\s]+)\)/i',$line,$reg))
|
||||
if (preg_match('/ALTER\s+TABLE\s*(.*)\s*ADD\s+(UNIQUE INDEX|INDEX|UNIQUE)\s+(.*)\s*\(([\w,\s]+)\)/i', $line, $reg))
|
||||
{
|
||||
$fieldlist=$reg[4];
|
||||
$idxname=$reg[3];
|
||||
$tablename=$reg[1];
|
||||
$line = "-- ".$line." replaced by --\n";
|
||||
$line.= "CREATE ".(preg_match('/UNIQUE/',$reg[2])?'UNIQUE ':'')."INDEX ".$idxname." ON ".$tablename." (".$fieldlist.")";
|
||||
$line.= "CREATE ".(preg_match('/UNIQUE/', $reg[2])?'UNIQUE ':'')."INDEX ".$idxname." ON ".$tablename." (".$fieldlist.")";
|
||||
}
|
||||
}
|
||||
|
||||
// To have postgresql case sensitive
|
||||
$line=str_replace(' LIKE \'',' ILIKE \'',$line);
|
||||
$line=str_replace(' LIKE BINARY \'',' LIKE \'',$line);
|
||||
$line=str_replace(' LIKE \'', ' ILIKE \'', $line);
|
||||
$line=str_replace(' LIKE BINARY \'', ' LIKE \'', $line);
|
||||
|
||||
// Replace INSERT IGNORE into INSERT
|
||||
$line=preg_replace('/^INSERT IGNORE/','INSERT',$line);
|
||||
$line=preg_replace('/^INSERT IGNORE/', 'INSERT', $line);
|
||||
|
||||
// Delete using criteria on other table must not declare twice the deleted table
|
||||
// DELETE FROM tabletodelete USING tabletodelete, othertable -> DELETE FROM tabletodelete USING othertable
|
||||
if (preg_match('/DELETE FROM ([a-z_]+) USING ([a-z_]+), ([a-z_]+)/i',$line,$reg))
|
||||
if (preg_match('/DELETE FROM ([a-z_]+) USING ([a-z_]+), ([a-z_]+)/i', $line, $reg))
|
||||
{
|
||||
if ($reg[1] == $reg[2]) // If same table, we remove second one
|
||||
{
|
||||
$line=preg_replace('/DELETE FROM ([a-z_]+) USING ([a-z_]+), ([a-z_]+)/i','DELETE FROM \\1 USING \\3', $line);
|
||||
$line=preg_replace('/DELETE FROM ([a-z_]+) USING ([a-z_]+), ([a-z_]+)/i', 'DELETE FROM \\1 USING \\3', $line);
|
||||
}
|
||||
}
|
||||
|
||||
// Remove () in the tables in FROM if 1 table
|
||||
$line=preg_replace('/FROM\s*\((([a-z_]+)\s+as\s+([a-z_]+)\s*)\)/i','FROM \\1',$line);
|
||||
$line=preg_replace('/FROM\s*\((([a-z_]+)\s+as\s+([a-z_]+)\s*)\)/i', 'FROM \\1', $line);
|
||||
//print $line."\n";
|
||||
|
||||
// Remove () in the tables in FROM if 2 table
|
||||
$line=preg_replace('/FROM\s*\(([a-z_]+\s+as\s+[a-z_]+)\s*,\s*([a-z_]+\s+as\s+[a-z_]+\s*)\)/i','FROM \\1, \\2',$line);
|
||||
$line=preg_replace('/FROM\s*\(([a-z_]+\s+as\s+[a-z_]+)\s*,\s*([a-z_]+\s+as\s+[a-z_]+\s*)\)/i', 'FROM \\1, \\2', $line);
|
||||
//print $line."\n";
|
||||
|
||||
// Remove () in the tables in FROM if 3 table
|
||||
$line=preg_replace('/FROM\s*\(([a-z_]+\s+as\s+[a-z_]+)\s*,\s*([a-z_]+\s+as\s+[a-z_]+\s*),\s*([a-z_]+\s+as\s+[a-z_]+\s*)\)/i','FROM \\1, \\2, \\3',$line);
|
||||
$line=preg_replace('/FROM\s*\(([a-z_]+\s+as\s+[a-z_]+)\s*,\s*([a-z_]+\s+as\s+[a-z_]+\s*),\s*([a-z_]+\s+as\s+[a-z_]+\s*)\)/i', 'FROM \\1, \\2, \\3', $line);
|
||||
//print $line."\n";
|
||||
|
||||
// Remove () in the tables in FROM if 4 table
|
||||
$line=preg_replace('/FROM\s*\(([a-z_]+\s+as\s+[a-z_]+)\s*,\s*([a-z_]+\s+as\s+[a-z_]+\s*),\s*([a-z_]+\s+as\s+[a-z_]+\s*),\s*([a-z_]+\s+as\s+[a-z_]+\s*)\)/i','FROM \\1, \\2, \\3, \\4',$line);
|
||||
$line=preg_replace('/FROM\s*\(([a-z_]+\s+as\s+[a-z_]+)\s*,\s*([a-z_]+\s+as\s+[a-z_]+\s*),\s*([a-z_]+\s+as\s+[a-z_]+\s*),\s*([a-z_]+\s+as\s+[a-z_]+\s*)\)/i', 'FROM \\1, \\2, \\3, \\4', $line);
|
||||
//print $line."\n";
|
||||
|
||||
// Remove () in the tables in FROM if 5 table
|
||||
$line=preg_replace('/FROM\s*\(([a-z_]+\s+as\s+[a-z_]+)\s*,\s*([a-z_]+\s+as\s+[a-z_]+\s*),\s*([a-z_]+\s+as\s+[a-z_]+\s*),\s*([a-z_]+\s+as\s+[a-z_]+\s*),\s*([a-z_]+\s+as\s+[a-z_]+\s*)\)/i','FROM \\1, \\2, \\3, \\4, \\5',$line);
|
||||
$line=preg_replace('/FROM\s*\(([a-z_]+\s+as\s+[a-z_]+)\s*,\s*([a-z_]+\s+as\s+[a-z_]+\s*),\s*([a-z_]+\s+as\s+[a-z_]+\s*),\s*([a-z_]+\s+as\s+[a-z_]+\s*),\s*([a-z_]+\s+as\s+[a-z_]+\s*)\)/i', 'FROM \\1, \\2, \\3, \\4, \\5', $line);
|
||||
//print $line."\n";
|
||||
|
||||
// Replace espacing \' by ''.
|
||||
// By default we do not (should be already done by db->escape function if required
|
||||
// except for sql insert in data file that are mysql escaped so we removed them to
|
||||
// be compatible with standard_conforming_strings=on that considers \ as ordinary character).
|
||||
if ($unescapeslashquot) $line=preg_replace("/\\\'/","''",$line);
|
||||
if ($unescapeslashquot) $line=preg_replace("/\\\'/", "''", $line);
|
||||
|
||||
//print "type=".$type." newline=".$line."<br>\n";
|
||||
}
|
||||
@@ -468,7 +468,7 @@ class DoliDBPgsql extends DoliDB
|
||||
{
|
||||
if ($this->db)
|
||||
{
|
||||
if ($this->transaction_opened > 0) dol_syslog(get_class($this)."::close Closing a connection with an opened transaction depth=".$this->transaction_opened,LOG_ERR);
|
||||
if ($this->transaction_opened > 0) dol_syslog(get_class($this)."::close Closing a connection with an opened transaction depth=".$this->transaction_opened, LOG_ERR);
|
||||
$this->connected=false;
|
||||
return pg_close($this->db);
|
||||
}
|
||||
@@ -490,7 +490,7 @@ class DoliDBPgsql extends DoliDB
|
||||
$query = trim($query);
|
||||
|
||||
// Convert MySQL syntax to PostgresSQL syntax
|
||||
$query=$this->convertSQLFromMysql($query,$type,($this->unescapeslashquot && $this->standard_conforming_strings));
|
||||
$query=$this->convertSQLFromMysql($query, $type, ($this->unescapeslashquot && $this->standard_conforming_strings));
|
||||
//print "After convertSQLFromMysql:\n".$query."<br>\n";
|
||||
|
||||
if (! empty($conf->global->MAIN_DB_AUTOFIX_BAD_SQL_REQUEST))
|
||||
@@ -499,10 +499,10 @@ class DoliDBPgsql extends DoliDB
|
||||
$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))
|
||||
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\'',$query);
|
||||
dol_syslog("Warning: Bad formed request converted into ".$query,LOG_WARNING);
|
||||
$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\'', $query);
|
||||
dol_syslog("Warning: Bad formed request converted into ".$query, LOG_WARNING);
|
||||
}
|
||||
else $loop=false;
|
||||
}
|
||||
@@ -513,12 +513,12 @@ class DoliDBPgsql extends DoliDB
|
||||
@pg_query($this->db, 'SAVEPOINT mysavepoint');
|
||||
}
|
||||
|
||||
if (! in_array($query,array('BEGIN','COMMIT','ROLLBACK'))) dol_syslog('sql='.$query, LOG_DEBUG);
|
||||
if (! in_array($query, array('BEGIN','COMMIT','ROLLBACK'))) dol_syslog('sql='.$query, LOG_DEBUG);
|
||||
|
||||
$ret = @pg_query($this->db, $query);
|
||||
|
||||
//print $query;
|
||||
if (! preg_match("/^COMMIT/i",$query) && ! preg_match("/^ROLLBACK/i",$query)) // Si requete utilisateur, on la sauvegarde ainsi que son resultset
|
||||
if (! preg_match("/^COMMIT/i", $query) && ! preg_match("/^ROLLBACK/i", $query)) // Si requete utilisateur, on la sauvegarde ainsi que son resultset
|
||||
{
|
||||
if (! $ret)
|
||||
{
|
||||
@@ -677,7 +677,7 @@ class DoliDBPgsql extends DoliDB
|
||||
*/
|
||||
function idate($param)
|
||||
{
|
||||
return dol_print_date($param,"%Y-%m-%d %H:%M:%S");
|
||||
return dol_print_date($param, "%Y-%m-%d %H:%M:%S");
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -738,7 +738,7 @@ class DoliDBPgsql extends DoliDB
|
||||
|
||||
$errorlabel=pg_last_error($this->db);
|
||||
$errorcode='';
|
||||
if (preg_match('/: *([0-9P]+):/',$errorlabel,$reg))
|
||||
if (preg_match('/: *([0-9P]+):/', $errorlabel, $reg))
|
||||
{
|
||||
$errorcode=$reg[1];
|
||||
if (isset($errorcode_map[$errorcode]))
|
||||
@@ -781,14 +781,14 @@ class DoliDBPgsql extends DoliDB
|
||||
{
|
||||
// phpcs:enable
|
||||
//$result = pg_query($this->db,"SELECT MAX(".$fieldid.") FROM ".$tab);
|
||||
$result = pg_query($this->db,"SELECT currval('".$tab."_".$fieldid."_seq')");
|
||||
$result = pg_query($this->db, "SELECT currval('".$tab."_".$fieldid."_seq')");
|
||||
if (! $result)
|
||||
{
|
||||
print pg_last_error($this->db);
|
||||
exit;
|
||||
}
|
||||
//$nbre = pg_num_rows($result);
|
||||
$row = pg_fetch_result($result,0,0);
|
||||
$row = pg_fetch_result($result, 0, 0);
|
||||
return $row;
|
||||
}
|
||||
|
||||
@@ -872,7 +872,7 @@ class DoliDBPgsql extends DoliDB
|
||||
//print $charset.' '.setlocale(LC_CTYPE,'0'); exit;
|
||||
|
||||
$sql='CREATE DATABASE "'.$database.'" OWNER "'.$owner.'" ENCODING \''.$charset.'\'';
|
||||
dol_syslog($sql,LOG_DEBUG);
|
||||
dol_syslog($sql, LOG_DEBUG);
|
||||
$ret=$this->query($sql);
|
||||
return $ret;
|
||||
}
|
||||
@@ -932,7 +932,7 @@ class DoliDBPgsql extends DoliDB
|
||||
$sql.=" AND table_name='".$table."'";
|
||||
$sql.=" ORDER BY ordinal_position;";
|
||||
|
||||
dol_syslog($sql,LOG_DEBUG);
|
||||
dol_syslog($sql, LOG_DEBUG);
|
||||
$result = $this->query($sql);
|
||||
if ($result)
|
||||
{
|
||||
@@ -971,21 +971,21 @@ class DoliDBPgsql extends DoliDB
|
||||
{
|
||||
$sqlfields[$i] = $field_name." ";
|
||||
$sqlfields[$i] .= $field_desc['type'];
|
||||
if( preg_match("/^[^\s]/i",$field_desc['value']))
|
||||
if( preg_match("/^[^\s]/i", $field_desc['value']))
|
||||
$sqlfields[$i] .= "(".$field_desc['value'].")";
|
||||
else if( preg_match("/^[^\s]/i",$field_desc['attribute']))
|
||||
else if( preg_match("/^[^\s]/i", $field_desc['attribute']))
|
||||
$sqlfields[$i] .= " ".$field_desc['attribute'];
|
||||
else if( preg_match("/^[^\s]/i",$field_desc['default']))
|
||||
else if( preg_match("/^[^\s]/i", $field_desc['default']))
|
||||
{
|
||||
if(preg_match("/null/i",$field_desc['default']))
|
||||
if(preg_match("/null/i", $field_desc['default']))
|
||||
$sqlfields[$i] .= " default ".$field_desc['default'];
|
||||
else
|
||||
$sqlfields[$i] .= " default '".$field_desc['default']."'";
|
||||
}
|
||||
else if( preg_match("/^[^\s]/i",$field_desc['null']))
|
||||
else if( preg_match("/^[^\s]/i", $field_desc['null']))
|
||||
$sqlfields[$i] .= " ".$field_desc['null'];
|
||||
|
||||
else if( preg_match("/^[^\s]/i",$field_desc['extra']))
|
||||
else if( preg_match("/^[^\s]/i", $field_desc['extra']))
|
||||
$sqlfields[$i] .= " ".$field_desc['extra'];
|
||||
$i++;
|
||||
}
|
||||
@@ -1010,16 +1010,16 @@ class DoliDBPgsql extends DoliDB
|
||||
$i++;
|
||||
}
|
||||
}
|
||||
$sql .= implode(',',$sqlfields);
|
||||
$sql .= implode(',', $sqlfields);
|
||||
if($primary_key != "")
|
||||
$sql .= ",".$pk;
|
||||
if(is_array($unique_keys))
|
||||
$sql .= ",".implode(',',$sqluq);
|
||||
$sql .= ",".implode(',', $sqluq);
|
||||
if(is_array($keys))
|
||||
$sql .= ",".implode(',',$sqlk);
|
||||
$sql .= ",".implode(',', $sqlk);
|
||||
$sql .=") type=".$type;
|
||||
|
||||
dol_syslog($sql,LOG_DEBUG);
|
||||
dol_syslog($sql, LOG_DEBUG);
|
||||
if(! $this->query($sql))
|
||||
return -1;
|
||||
else
|
||||
@@ -1085,7 +1085,7 @@ class DoliDBPgsql extends DoliDB
|
||||
$sql.=" AND attname NOT IN ('cmin', 'cmax', 'ctid', 'oid', 'tableoid', 'xmin', 'xmax')";
|
||||
if ($field) $sql.= " AND attname = '".$field."'";
|
||||
|
||||
dol_syslog($sql,LOG_DEBUG);
|
||||
dol_syslog($sql, LOG_DEBUG);
|
||||
$this->_results = $this->query($sql);
|
||||
return $this->_results;
|
||||
}
|
||||
@@ -1107,25 +1107,25 @@ class DoliDBPgsql extends DoliDB
|
||||
// ex. : $field_desc = array('type'=>'int','value'=>'11','null'=>'not null','extra'=> 'auto_increment');
|
||||
$sql= "ALTER TABLE ".$table." ADD ".$field_name." ";
|
||||
$sql .= $field_desc['type'];
|
||||
if (preg_match("/^[^\s]/i",$field_desc['value']))
|
||||
if (! in_array($field_desc['type'],array('int','date','datetime')))
|
||||
if (preg_match("/^[^\s]/i", $field_desc['value']))
|
||||
if (! in_array($field_desc['type'], array('int','date','datetime')))
|
||||
{
|
||||
$sql.= "(".$field_desc['value'].")";
|
||||
}
|
||||
if (preg_match("/^[^\s]/i",$field_desc['attribute']))
|
||||
if (preg_match("/^[^\s]/i", $field_desc['attribute']))
|
||||
$sql .= " ".$field_desc['attribute'];
|
||||
if (preg_match("/^[^\s]/i",$field_desc['null']))
|
||||
if (preg_match("/^[^\s]/i", $field_desc['null']))
|
||||
$sql .= " ".$field_desc['null'];
|
||||
if (preg_match("/^[^\s]/i",$field_desc['default']))
|
||||
if (preg_match("/null/i",$field_desc['default']))
|
||||
if (preg_match("/^[^\s]/i", $field_desc['default']))
|
||||
if (preg_match("/null/i", $field_desc['default']))
|
||||
$sql .= " default ".$field_desc['default'];
|
||||
else
|
||||
$sql .= " default '".$field_desc['default']."'";
|
||||
if (preg_match("/^[^\s]/i",$field_desc['extra']))
|
||||
if (preg_match("/^[^\s]/i", $field_desc['extra']))
|
||||
$sql .= " ".$field_desc['extra'];
|
||||
$sql .= " ".$field_position;
|
||||
|
||||
dol_syslog($sql,LOG_DEBUG);
|
||||
dol_syslog($sql, LOG_DEBUG);
|
||||
if (! $this -> query($sql))
|
||||
return -1;
|
||||
return 1;
|
||||
@@ -1170,7 +1170,7 @@ class DoliDBPgsql extends DoliDB
|
||||
elseif ($field_desc['type'] == 'text') $sql.=" DEFAULT '".$this->escape($field_desc['default'])."'"; // Default not supported on text fields
|
||||
}
|
||||
|
||||
dol_syslog($sql,LOG_DEBUG);
|
||||
dol_syslog($sql, LOG_DEBUG);
|
||||
if (! $this->query($sql))
|
||||
return -1;
|
||||
return 1;
|
||||
@@ -1188,7 +1188,7 @@ class DoliDBPgsql extends DoliDB
|
||||
{
|
||||
// phpcs:enable
|
||||
$sql= "ALTER TABLE ".$table." DROP COLUMN ".$field_name;
|
||||
dol_syslog($sql,LOG_DEBUG);
|
||||
dol_syslog($sql, LOG_DEBUG);
|
||||
if (! $this->query($sql))
|
||||
{
|
||||
$this->error=$this->lasterror();
|
||||
@@ -1299,7 +1299,7 @@ class DoliDBPgsql extends DoliDB
|
||||
{
|
||||
$liste=$this->fetch_array($resql);
|
||||
$basedir=$liste['data_directory'];
|
||||
$fullpathofdump=preg_replace('/data$/','bin',$basedir).'/pg_dump';
|
||||
$fullpathofdump=preg_replace('/data$/', 'bin', $basedir).'/pg_dump';
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1330,7 +1330,7 @@ class DoliDBPgsql extends DoliDB
|
||||
{
|
||||
$liste=$this->fetch_array($resql);
|
||||
$basedir=$liste['data_directory'];
|
||||
$fullpathofdump=preg_replace('/data$/','bin',$basedir).'/'.$tool;
|
||||
$fullpathofdump=preg_replace('/data$/', 'bin', $basedir).'/'.$tool;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user