mirror of
https://github.com/Dolibarr/dolibarr.git
synced 2026-01-06 09:02:59 +01:00
Merge remote-tracking branch 'upstream/develop' into psr2squizwhite
This commit is contained in:
@@ -90,7 +90,7 @@ abstract class DoliDB implements Database
|
||||
function idate($param)
|
||||
{
|
||||
// TODO GMT $param should be gmt, so we should add tzouptut to 'gmt'
|
||||
return dol_print_date($param,"%Y-%m-%d %H:%M:%S");
|
||||
return dol_print_date($param, "%Y-%m-%d %H:%M:%S");
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -116,15 +116,15 @@ abstract class DoliDB implements Database
|
||||
if ($ret)
|
||||
{
|
||||
$this->transaction_opened++;
|
||||
dol_syslog("BEGIN Transaction",LOG_DEBUG);
|
||||
dol_syslog('',0,1);
|
||||
dol_syslog("BEGIN Transaction", LOG_DEBUG);
|
||||
dol_syslog('', 0, 1);
|
||||
}
|
||||
return $ret;
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->transaction_opened++;
|
||||
dol_syslog('',0,1);
|
||||
dol_syslog('', 0, 1);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
@@ -137,14 +137,14 @@ abstract class DoliDB implements Database
|
||||
*/
|
||||
function commit($log = '')
|
||||
{
|
||||
dol_syslog('',0,-1);
|
||||
dol_syslog('', 0, -1);
|
||||
if ($this->transaction_opened<=1)
|
||||
{
|
||||
$ret=$this->query("COMMIT");
|
||||
if ($ret)
|
||||
{
|
||||
$this->transaction_opened=0;
|
||||
dol_syslog("COMMIT Transaction".($log?' '.$log:''),LOG_DEBUG);
|
||||
dol_syslog("COMMIT Transaction".($log?' '.$log:''), LOG_DEBUG);
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
@@ -167,12 +167,12 @@ abstract class DoliDB implements Database
|
||||
*/
|
||||
function rollback($log = '')
|
||||
{
|
||||
dol_syslog('',0,-1);
|
||||
dol_syslog('', 0, -1);
|
||||
if ($this->transaction_opened<=1)
|
||||
{
|
||||
$ret=$this->query("ROLLBACK");
|
||||
$this->transaction_opened=0;
|
||||
dol_syslog("ROLLBACK Transaction".($log?' '.$log:''),LOG_DEBUG);
|
||||
dol_syslog("ROLLBACK Transaction".($log?' '.$log:''), LOG_DEBUG);
|
||||
return $ret;
|
||||
}
|
||||
else
|
||||
@@ -205,7 +205,7 @@ abstract class DoliDB implements Database
|
||||
*/
|
||||
function getVersionArray()
|
||||
{
|
||||
return preg_split("/[\.,-]/",$this->getVersion());
|
||||
return preg_split("/[\.,-]/", $this->getVersion());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -230,15 +230,15 @@ abstract class DoliDB implements Database
|
||||
if (! empty($sortfield))
|
||||
{
|
||||
$return='';
|
||||
$fields=explode(',',$sortfield);
|
||||
$orders=explode(',',$sortorder);
|
||||
$fields=explode(',', $sortfield);
|
||||
$orders=explode(',', $sortorder);
|
||||
$i=0;
|
||||
foreach($fields as $val)
|
||||
{
|
||||
if (! $return) $return.=' ORDER BY ';
|
||||
else $return.=', ';
|
||||
|
||||
$return.=preg_replace('/[^0-9a-z_\.]/i','',$val);
|
||||
$return.=preg_replace('/[^0-9a-z_\.]/i', '', $val);
|
||||
|
||||
$tmpsortorder = trim($orders[$i]);
|
||||
|
||||
@@ -282,9 +282,9 @@ abstract class DoliDB implements Database
|
||||
{
|
||||
// TODO GMT must set param gm to true by default
|
||||
if ($string==0 || $string=="0000-00-00 00:00:00") return '';
|
||||
$string=preg_replace('/([^0-9])/i','',$string);
|
||||
$string=preg_replace('/([^0-9])/i', '', $string);
|
||||
$tmp=$string.'000000';
|
||||
$date=dol_mktime(substr($tmp,8,2),substr($tmp,10,2),substr($tmp,12,2),substr($tmp,4,2),substr($tmp,6,2),substr($tmp,0,4),$gm);
|
||||
$date=dol_mktime(substr($tmp, 8, 2), substr($tmp, 10, 2), substr($tmp, 12, 2), substr($tmp, 4, 2), substr($tmp, 6, 2), substr($tmp, 0, 4), $gm);
|
||||
return $date;
|
||||
}
|
||||
|
||||
|
||||
@@ -69,7 +69,7 @@ class DoliDBMssql extends DoliDB
|
||||
$this->connected = false;
|
||||
$this->ok = false;
|
||||
$this->error="Mssql PHP functions for using MSSql driver are not available in this version of PHP";
|
||||
dol_syslog(get_class($this)."::DoliDBMssql : MSsql PHP functions for using MSsql driver are not available in this version of PHP",LOG_ERR);
|
||||
dol_syslog(get_class($this)."::DoliDBMssql : MSsql PHP functions for using MSsql driver are not available in this version of PHP", LOG_ERR);
|
||||
return $this->ok;
|
||||
}
|
||||
|
||||
@@ -78,7 +78,7 @@ class DoliDBMssql extends DoliDB
|
||||
$this->connected = false;
|
||||
$this->ok = false;
|
||||
$this->error=$langs->trans("ErrorWrongHostParameter");
|
||||
dol_syslog(get_class($this)."::DoliDBMssql : Erreur Connect, wrong host parameters",LOG_ERR);
|
||||
dol_syslog(get_class($this)."::DoliDBMssql : Erreur Connect, wrong host parameters", LOG_ERR);
|
||||
return $this->ok;
|
||||
}
|
||||
|
||||
@@ -97,7 +97,7 @@ class DoliDBMssql extends DoliDB
|
||||
$this->connected = false;
|
||||
$this->ok = false;
|
||||
$this->error=mssql_get_last_message();
|
||||
dol_syslog(get_class($this)."::DoliDBMssql : Erreur Connect mssql_get_last_message=".$this->error,LOG_ERR);
|
||||
dol_syslog(get_class($this)."::DoliDBMssql : Erreur Connect mssql_get_last_message=".$this->error, LOG_ERR);
|
||||
}
|
||||
|
||||
// Si connexion serveur ok et si connexion base demandee, on essaie connexion base
|
||||
@@ -115,7 +115,7 @@ class DoliDBMssql extends DoliDB
|
||||
$this->database_name = '';
|
||||
$this->ok = false;
|
||||
$this->error=$this->error();
|
||||
dol_syslog(get_class($this)."::DoliDBMssql : Erreur Select_db ".$this->error,LOG_ERR);
|
||||
dol_syslog(get_class($this)."::DoliDBMssql : Erreur Select_db ".$this->error, LOG_ERR);
|
||||
}
|
||||
}
|
||||
else
|
||||
@@ -181,7 +181,7 @@ class DoliDBMssql extends DoliDB
|
||||
"SET CONCAT_NULL_YIELDS_NULL ON;",
|
||||
"SET QUOTED_IDENTIFIER ON;"
|
||||
);
|
||||
mssql_query(implode(' ',$set_options),$this->db);
|
||||
mssql_query(implode(' ', $set_options), $this->db);
|
||||
|
||||
return $this->db;
|
||||
}
|
||||
@@ -222,7 +222,7 @@ class DoliDBMssql 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 mssql_close($this->db);
|
||||
}
|
||||
@@ -244,10 +244,10 @@ class DoliDBMssql extends DoliDB
|
||||
if ($this->transaction_opened == 0)
|
||||
{
|
||||
//return 1; //There is a mess with auto_commit and 'SET IMPLICIT_TRANSACTIONS ON' generate also a mess
|
||||
$ret=mssql_query("SET IMPLICIT_TRANSACTIONS OFF;BEGIN TRANSACTION;",$this->db);
|
||||
$ret=mssql_query("SET IMPLICIT_TRANSACTIONS OFF;BEGIN TRANSACTION;", $this->db);
|
||||
if ($ret)
|
||||
{
|
||||
dol_syslog("BEGIN Transaction",LOG_DEBUG);
|
||||
dol_syslog("BEGIN Transaction", LOG_DEBUG);
|
||||
}
|
||||
return $ret;
|
||||
}
|
||||
@@ -271,10 +271,10 @@ class DoliDBMssql extends DoliDB
|
||||
if ($this->transaction_opened == 1)
|
||||
{
|
||||
//return 1; //There is a mess with auto_commit and 'SET IMPLICIT_TRANSACTION ON' generate also a mess
|
||||
$ret=mssql_query("COMMIT TRANSACTION",$this->db);
|
||||
$ret=mssql_query("COMMIT TRANSACTION", $this->db);
|
||||
if ($ret)
|
||||
{
|
||||
dol_syslog("COMMIT Transaction",LOG_DEBUG);
|
||||
dol_syslog("COMMIT Transaction", LOG_DEBUG);
|
||||
return true;
|
||||
}
|
||||
else
|
||||
@@ -303,8 +303,8 @@ class DoliDBMssql extends DoliDB
|
||||
|
||||
if ($this->transaction_opened == 1)
|
||||
{
|
||||
$ret=mssql_query("ROLLBACK TRANSACTION",$this->db);
|
||||
dol_syslog("ROLLBACK Transaction".($log?' '.$log:''),LOG_DEBUG);
|
||||
$ret=mssql_query("ROLLBACK TRANSACTION", $this->db);
|
||||
dol_syslog("ROLLBACK Transaction".($log?' '.$log:''), LOG_DEBUG);
|
||||
return $ret;
|
||||
}
|
||||
elseif ($this->transaction_opened > 1)
|
||||
@@ -328,33 +328,33 @@ class DoliDBMssql extends DoliDB
|
||||
{
|
||||
$query = trim($query);
|
||||
|
||||
if (preg_match('/^--/',$query)) return true;
|
||||
if (preg_match('/^--/', $query)) return true;
|
||||
|
||||
// Conversion syntaxe MySql vers MSDE.
|
||||
$query = str_ireplace("now()", "getdate()", $query);
|
||||
// Erreur SQL: cannot update timestamp field
|
||||
$query = str_ireplace(", tms = tms", "", $query);
|
||||
|
||||
$query=preg_replace("/([. ,\t(])(percent|file|public)([. ,=\t)])/","$1[$2]$3",$query);
|
||||
$query=preg_replace("/([. ,\t(])(percent|file|public)([. ,=\t)])/", "$1[$2]$3", $query);
|
||||
|
||||
if ($type=="auto" || $type='dml')
|
||||
{
|
||||
$query=preg_replace('/AUTO_INCREMENT/i','IDENTITY',$query);
|
||||
$query=preg_replace('/double/i','float',$query);
|
||||
$query=preg_replace('/float\((.*)\)/','numeric($1)',$query);
|
||||
$query=preg_replace('/([ \t])unsigned|IF NOT EXISTS[ \t]/i','$1',$query);
|
||||
$query=preg_replace('/([ \t])(MEDIUM|TINY|LONG){0,1}TEXT([ \t,])/i',"$1VARCHAR(MAX)$3",$query);
|
||||
$query=preg_replace('/AUTO_INCREMENT/i', 'IDENTITY', $query);
|
||||
$query=preg_replace('/double/i', 'float', $query);
|
||||
$query=preg_replace('/float\((.*)\)/', 'numeric($1)', $query);
|
||||
$query=preg_replace('/([ \t])unsigned|IF NOT EXISTS[ \t]/i', '$1', $query);
|
||||
$query=preg_replace('/([ \t])(MEDIUM|TINY|LONG){0,1}TEXT([ \t,])/i', "$1VARCHAR(MAX)$3", $query);
|
||||
|
||||
$matches=array();
|
||||
$original_query='';
|
||||
if (preg_match('/ALTER TABLE\h+(\w+?)\h+ADD\h+(?:(UNIQUE)|INDEX)\h+(?:INDEX)?\h*(\w+?)\h*\((.+)\)/is', $query,$matches))
|
||||
if (preg_match('/ALTER TABLE\h+(\w+?)\h+ADD\h+(?:(UNIQUE)|INDEX)\h+(?:INDEX)?\h*(\w+?)\h*\((.+)\)/is', $query, $matches))
|
||||
{
|
||||
$original_query=$query;
|
||||
$query="CREATE ".trim($matches[2])." INDEX [".trim($matches[3])."] ON [".trim($matches[1])."] (".trim($matches[4]).")";
|
||||
if ($matches[2]) {
|
||||
//check if columun is nullable cause Sql server only allow 1 null value if unique index.
|
||||
$fields=explode(",",trim($matches[4]));
|
||||
$fields_clear=array_map('trim',$fields);
|
||||
$fields=explode(",", trim($matches[4]));
|
||||
$fields_clear=array_map('trim', $fields);
|
||||
$infos=$this->GetFieldInformation(trim($matches[1]), $fields_clear);
|
||||
$query_comp=array();
|
||||
foreach($infos as $fld) {
|
||||
@@ -363,7 +363,7 @@ class DoliDBMssql extends DoliDB
|
||||
}
|
||||
}
|
||||
if (! empty($query_comp))
|
||||
$query.=" WHERE ".implode(" AND ",$query_comp);
|
||||
$query.=" WHERE ".implode(" AND ", $query_comp);
|
||||
}
|
||||
}
|
||||
else
|
||||
@@ -407,7 +407,7 @@ class DoliDBMssql extends DoliDB
|
||||
// Inserer la date en parametre et le reste de la requete
|
||||
$query = $newquery." DATEPART(week, ".$extractvalue.$endofquery;
|
||||
}
|
||||
if (preg_match('/^insert\h+(?:INTO)?\h*(\w+?)\h*\(.*\b(?:row)?id\b.*\)\h+VALUES/i',$query,$matches))
|
||||
if (preg_match('/^insert\h+(?:INTO)?\h*(\w+?)\h*\(.*\b(?:row)?id\b.*\)\h+VALUES/i', $query, $matches))
|
||||
{
|
||||
//var_dump($query);
|
||||
//var_dump($matches);
|
||||
@@ -419,7 +419,7 @@ class DoliDBMssql extends DoliDB
|
||||
}
|
||||
//print "<!--".$query."-->";
|
||||
|
||||
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);
|
||||
|
||||
if (! $this->database_name)
|
||||
{
|
||||
@@ -436,7 +436,7 @@ class DoliDBMssql extends DoliDB
|
||||
@mssql_query($post_query, $this->db);
|
||||
}
|
||||
|
||||
if (! preg_match("/^COMMIT/i",$query) && ! preg_match("/^ROLLBACK/i",$query))
|
||||
if (! preg_match("/^COMMIT/i", $query) && ! preg_match("/^ROLLBACK/i", $query))
|
||||
{
|
||||
// Si requete utilisateur, on la sauvegarde ainsi que son resultset
|
||||
if (! $ret)
|
||||
@@ -577,7 +577,7 @@ class DoliDBMssql 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");
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -758,14 +758,14 @@ class DoliDBMssql extends DoliDB
|
||||
|
||||
$this->select_db($database);
|
||||
$sql="CREATE USER [$owner] FOR LOGIN [$owner]";
|
||||
mssql_query($sql,$this->db);
|
||||
mssql_query($sql, $this->db);
|
||||
$sql="ALTER ROLE [db_owner] ADD MEMBER [$owner]";
|
||||
mssql_query($sql,$this->db);
|
||||
mssql_query($sql, $this->db);
|
||||
|
||||
$sql="ALTER DATABASE [$database] SET ANSI_NULL_DEFAULT ON;";
|
||||
@mssql_query($sql,$this->db);
|
||||
@mssql_query($sql, $this->db);
|
||||
$sql="ALTER DATABASE [$database] SET ANSI_NULL ON;";
|
||||
@mssql_query($sql,$this->db);
|
||||
@mssql_query($sql, $this->db);
|
||||
|
||||
return $ret;
|
||||
}
|
||||
@@ -830,22 +830,22 @@ class DoliDBMssql extends DoliDB
|
||||
{
|
||||
$sqlfields[$i] = $field_name." ";
|
||||
$sqlfields[$i] .= $field_desc['type'];
|
||||
if( preg_match("/^[^\s]/i",$field_desc['value']))
|
||||
$sqlfields[$i] .= "(".$field_desc['value'].")";
|
||||
elseif( preg_match("/^[^\s]/i",$field_desc['attribute']))
|
||||
$sqlfields[$i] .= " ".$field_desc['attribute'];
|
||||
elseif( preg_match("/^[^\s]/i",$field_desc['default']))
|
||||
if( preg_match("/^[^\s]/i", $field_desc['value']))
|
||||
$sqlfields[$i] .= "(".$field_desc['value'].")";
|
||||
elseif( preg_match("/^[^\s]/i", $field_desc['attribute']))
|
||||
$sqlfields[$i] .= " ".$field_desc['attribute'];
|
||||
elseif( 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']."'";
|
||||
}
|
||||
elseif( preg_match("/^[^\s]/i",$field_desc['null']))
|
||||
$sqlfields[$i] .= " ".$field_desc['null'];
|
||||
elseif (preg_match("/^[^\s]/i", $field_desc['null']))
|
||||
$sqlfields[$i] .= " ".$field_desc['null'];
|
||||
|
||||
elseif( preg_match("/^[^\s]/i",$field_desc['extra']))
|
||||
$sqlfields[$i] .= " ".$field_desc['extra'];
|
||||
elseif (preg_match("/^[^\s]/i", $field_desc['extra']))
|
||||
$sqlfields[$i] .= " ".$field_desc['extra'];
|
||||
$i++;
|
||||
}
|
||||
if($primary_key != "")
|
||||
@@ -869,13 +869,13 @@ class DoliDBMssql 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);
|
||||
@@ -938,18 +938,18 @@ class DoliDBMssql 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( preg_match("/^[^\s]/i", $field_desc['value']))
|
||||
$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;
|
||||
|
||||
@@ -977,7 +977,7 @@ class DoliDBMssql extends DoliDB
|
||||
$sql.="(".$field_desc['value'].")";
|
||||
}
|
||||
|
||||
dol_syslog($sql,LOG_DEBUG);
|
||||
dol_syslog($sql, LOG_DEBUG);
|
||||
if (! $this->query($sql))
|
||||
return -1;
|
||||
else
|
||||
@@ -996,7 +996,7 @@ class DoliDBMssql 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();
|
||||
@@ -1194,14 +1194,14 @@ class DoliDBMssql extends DoliDB
|
||||
$sql="SELECT * from INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME='".$this->escape($table)."' AND COLUMN_NAME";
|
||||
if (is_array($fields))
|
||||
{
|
||||
$where=" IN ('".implode("','",$fields)."')";
|
||||
$where=" IN ('".implode("','", $fields)."')";
|
||||
}
|
||||
else
|
||||
{
|
||||
$where="='".$this->escape($fields)."'";
|
||||
}
|
||||
$result=array();
|
||||
$ret=mssql_query($sql.$where,$this->db);
|
||||
$ret=mssql_query($sql.$where, $this->db);
|
||||
if ($ret)
|
||||
{
|
||||
while($obj=mssql_fetch_object($ret))
|
||||
|
||||
@@ -75,7 +75,7 @@ class DoliDBMysqli extends DoliDB
|
||||
$this->connected = false;
|
||||
$this->ok = false;
|
||||
$this->error="Mysqli PHP functions for using Mysqli driver are not available in this version of PHP. Try to use another driver.";
|
||||
dol_syslog(get_class($this)."::DoliDBMysqli : Mysqli PHP functions for using Mysqli driver are not available in this version of PHP. Try to use another driver.",LOG_ERR);
|
||||
dol_syslog(get_class($this)."::DoliDBMysqli : Mysqli PHP functions for using Mysqli driver are not available in this version of PHP. Try to use another driver.", LOG_ERR);
|
||||
}
|
||||
|
||||
if (! $host)
|
||||
@@ -83,7 +83,7 @@ class DoliDBMysqli extends DoliDB
|
||||
$this->connected = false;
|
||||
$this->ok = false;
|
||||
$this->error=$langs->trans("ErrorWrongHostParameter");
|
||||
dol_syslog(get_class($this)."::DoliDBMysqli : Connect error, wrong host parameters",LOG_ERR);
|
||||
dol_syslog(get_class($this)."::DoliDBMysqli : Connect error, wrong host parameters", LOG_ERR);
|
||||
}
|
||||
|
||||
// Try server connection
|
||||
@@ -128,7 +128,7 @@ class DoliDBMysqli extends DoliDB
|
||||
$this->database_name = '';
|
||||
$this->ok = false;
|
||||
$this->error=$this->error();
|
||||
dol_syslog(get_class($this)."::DoliDBMysqli : Select_db error ".$this->error,LOG_ERR);
|
||||
dol_syslog(get_class($this)."::DoliDBMysqli : Select_db error ".$this->error, LOG_ERR);
|
||||
}
|
||||
}
|
||||
else
|
||||
@@ -234,7 +234,7 @@ class DoliDBMysqli 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 $this->db->close();
|
||||
}
|
||||
@@ -256,7 +256,7 @@ class DoliDBMysqli extends DoliDB
|
||||
|
||||
$query = trim($query);
|
||||
|
||||
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);
|
||||
|
||||
if (! $this->database_name)
|
||||
{
|
||||
@@ -268,7 +268,7 @@ class DoliDBMysqli extends DoliDB
|
||||
$ret = $this->db->query($query);
|
||||
}
|
||||
|
||||
if (! preg_match("/^COMMIT/i",$query) && ! preg_match("/^ROLLBACK/i",$query))
|
||||
if (! preg_match("/^COMMIT/i", $query) && ! preg_match("/^ROLLBACK/i", $query))
|
||||
{
|
||||
// Si requete utilisateur, on la sauvegarde ainsi que son resultset
|
||||
if (! $ret)
|
||||
@@ -592,13 +592,13 @@ class DoliDBMysqli extends DoliDB
|
||||
$sql = "CREATE DATABASE `".$this->escape($database)."`";
|
||||
$sql.= " DEFAULT CHARACTER SET `".$this->escape($charset)."` DEFAULT COLLATE `".$this->escape($collation)."`";
|
||||
|
||||
dol_syslog($sql,LOG_DEBUG);
|
||||
dol_syslog($sql, LOG_DEBUG);
|
||||
$ret=$this->query($sql);
|
||||
if (! $ret)
|
||||
{
|
||||
// We try again for compatibility with Mysql < 4.1.1
|
||||
$sql = "CREATE DATABASE `".$this->escape($database)."`";
|
||||
dol_syslog($sql,LOG_DEBUG);
|
||||
dol_syslog($sql, LOG_DEBUG);
|
||||
$ret=$this->query($sql);
|
||||
}
|
||||
return $ret;
|
||||
@@ -646,7 +646,7 @@ class DoliDBMysqli extends DoliDB
|
||||
|
||||
$sql="SHOW FULL COLUMNS FROM ".$table.";";
|
||||
|
||||
dol_syslog($sql,LOG_DEBUG);
|
||||
dol_syslog($sql, LOG_DEBUG);
|
||||
$result = $this->query($sql);
|
||||
if ($result)
|
||||
{
|
||||
@@ -684,25 +684,25 @@ class DoliDBMysqli 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'].")";
|
||||
}
|
||||
if( preg_match("/^[^\s]/i",$field_desc['attribute'])) {
|
||||
if( preg_match("/^[^\s]/i", $field_desc['attribute'])) {
|
||||
$sqlfields[$i] .= " ".$field_desc['attribute'];
|
||||
}
|
||||
if( preg_match("/^[^\s]/i",$field_desc['default']))
|
||||
if( preg_match("/^[^\s]/i", $field_desc['default']))
|
||||
{
|
||||
if ((preg_match("/null/i",$field_desc['default'])) || (preg_match("/CURRENT_TIMESTAMP/i",$field_desc['default']))) {
|
||||
if ((preg_match("/null/i", $field_desc['default'])) || (preg_match("/CURRENT_TIMESTAMP/i", $field_desc['default']))) {
|
||||
$sqlfields[$i] .= " default ".$field_desc['default'];
|
||||
}
|
||||
else {
|
||||
$sqlfields[$i] .= " default '".$field_desc['default']."'";
|
||||
}
|
||||
}
|
||||
if( preg_match("/^[^\s]/i",$field_desc['null'])) {
|
||||
if( preg_match("/^[^\s]/i", $field_desc['null'])) {
|
||||
$sqlfields[$i] .= " ".$field_desc['null'];
|
||||
}
|
||||
if( preg_match("/^[^\s]/i",$field_desc['extra'])) {
|
||||
if( preg_match("/^[^\s]/i", $field_desc['extra'])) {
|
||||
$sqlfields[$i] .= " ".$field_desc['extra'];
|
||||
}
|
||||
$i++;
|
||||
@@ -727,13 +727,13 @@ class DoliDBMysqli extends DoliDB
|
||||
$i++;
|
||||
}
|
||||
}
|
||||
$sql .= implode(',',$sqlfields);
|
||||
$sql .= implode(',', $sqlfields);
|
||||
if($primary_key != "")
|
||||
$sql .= ",".$pk;
|
||||
if($unique_keys != "")
|
||||
$sql .= ",".implode(',',$sqluq);
|
||||
$sql .= ",".implode(',', $sqluq);
|
||||
if(is_array($keys))
|
||||
$sql .= ",".implode(',',$sqlk);
|
||||
$sql .= ",".implode(',', $sqlk);
|
||||
$sql .=") engine=".$type;
|
||||
|
||||
if(! $this->query($sql))
|
||||
@@ -773,7 +773,7 @@ class DoliDBMysqli extends DoliDB
|
||||
// phpcs:enable
|
||||
$sql="DESC ".$table." ".$field;
|
||||
|
||||
dol_syslog(get_class($this)."::DDLDescTable ".$sql,LOG_DEBUG);
|
||||
dol_syslog(get_class($this)."::DDLDescTable ".$sql, LOG_DEBUG);
|
||||
$this->_results = $this->query($sql);
|
||||
return $this->_results;
|
||||
}
|
||||
@@ -795,35 +795,35 @@ class DoliDBMysqli 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 (preg_match("/^[^\s]/i", $field_desc['value']))
|
||||
{
|
||||
if (! in_array($field_desc['type'],array('date','datetime')))
|
||||
if (! in_array($field_desc['type'], array('date','datetime')))
|
||||
{
|
||||
$sql.= "(".$field_desc['value'].")";
|
||||
}
|
||||
}
|
||||
if (isset($field_desc['attribute']) && preg_match("/^[^\s]/i",$field_desc['attribute']))
|
||||
if (isset($field_desc['attribute']) && preg_match("/^[^\s]/i", $field_desc['attribute']))
|
||||
{
|
||||
$sql.= " ".$field_desc['attribute'];
|
||||
}
|
||||
if (isset($field_desc['null']) && preg_match("/^[^\s]/i",$field_desc['null']))
|
||||
if (isset($field_desc['null']) && preg_match("/^[^\s]/i", $field_desc['null']))
|
||||
{
|
||||
$sql.= " ".$field_desc['null'];
|
||||
}
|
||||
if (isset($field_desc['default']) && preg_match("/^[^\s]/i",$field_desc['default']))
|
||||
if (isset($field_desc['default']) && preg_match("/^[^\s]/i", $field_desc['default']))
|
||||
{
|
||||
if(preg_match("/null/i",$field_desc['default']))
|
||||
if(preg_match("/null/i", $field_desc['default']))
|
||||
$sql.= " default ".$field_desc['default'];
|
||||
else
|
||||
$sql.= " default '".$field_desc['default']."'";
|
||||
}
|
||||
if (isset($field_desc['extra']) && preg_match("/^[^\s]/i",$field_desc['extra']))
|
||||
if (isset($field_desc['extra']) && preg_match("/^[^\s]/i", $field_desc['extra']))
|
||||
{
|
||||
$sql.= " ".$field_desc['extra'];
|
||||
}
|
||||
$sql.= " ".$field_position;
|
||||
|
||||
dol_syslog(get_class($this)."::DDLAddField ".$sql,LOG_DEBUG);
|
||||
dol_syslog(get_class($this)."::DDLAddField ".$sql, LOG_DEBUG);
|
||||
if ($this->query($sql)) {
|
||||
return 1;
|
||||
}
|
||||
@@ -870,7 +870,7 @@ class DoliDBMysqli extends DoliDB
|
||||
elseif ($field_desc['type'] == 'text') $sql.=" DEFAULT '".$this->escape($field_desc['default'])."'"; // Default not supported on text fields
|
||||
}
|
||||
|
||||
dol_syslog(get_class($this)."::DDLUpdateField ".$sql,LOG_DEBUG);
|
||||
dol_syslog(get_class($this)."::DDLUpdateField ".$sql, LOG_DEBUG);
|
||||
if (! $this->query($sql))
|
||||
return -1;
|
||||
else
|
||||
@@ -889,7 +889,7 @@ class DoliDBMysqli extends DoliDB
|
||||
{
|
||||
// phpcs:enable
|
||||
$sql= "ALTER TABLE ".$table." DROP COLUMN `".$field_name."`";
|
||||
dol_syslog(get_class($this)."::DDLDropField ".$sql,LOG_DEBUG);
|
||||
dol_syslog(get_class($this)."::DDLDropField ".$sql, LOG_DEBUG);
|
||||
if ($this->query($sql)) {
|
||||
return 1;
|
||||
}
|
||||
@@ -1052,7 +1052,7 @@ class DoliDBMysqli extends DoliDB
|
||||
{
|
||||
$liste=$this->fetch_array($resql);
|
||||
$basedir=$liste['Value'];
|
||||
$fullpathofdump=$basedir.(preg_match('/\/$/',$basedir)?'':'/').'bin/mysqldump';
|
||||
$fullpathofdump=$basedir.(preg_match('/\/$/', $basedir)?'':'/').'bin/mysqldump';
|
||||
}
|
||||
return $fullpathofdump;
|
||||
}
|
||||
@@ -1071,7 +1071,7 @@ class DoliDBMysqli extends DoliDB
|
||||
{
|
||||
$liste=$this->fetch_array($resql);
|
||||
$basedir=$liste['Value'];
|
||||
$fullpathofimport=$basedir.(preg_match('/\/$/',$basedir)?'':'/').'bin/mysql';
|
||||
$fullpathofimport=$basedir.(preg_match('/\/$/', $basedir)?'':'/').'bin/mysql';
|
||||
}
|
||||
return $fullpathofimport;
|
||||
}
|
||||
|
||||
@@ -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';
|
||||
elseif (preg_match('/CREATE TABLE/i',$line)) $type='dml';
|
||||
elseif (preg_match('/DROP TABLE/i',$line)) $type='dml';
|
||||
if (preg_match('/ALTER TABLE/i', $line)) $type='dml';
|
||||
elseif (preg_match('/CREATE TABLE/i', $line)) $type='dml';
|
||||
elseif (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,22 +971,22 @@ class DoliDBPgsql extends DoliDB
|
||||
{
|
||||
$sqlfields[$i] = $field_name." ";
|
||||
$sqlfields[$i] .= $field_desc['type'];
|
||||
if( preg_match("/^[^\s]/i",$field_desc['value']))
|
||||
$sqlfields[$i] .= "(".$field_desc['value'].")";
|
||||
elseif( preg_match("/^[^\s]/i",$field_desc['attribute']))
|
||||
$sqlfields[$i] .= " ".$field_desc['attribute'];
|
||||
elseif( preg_match("/^[^\s]/i",$field_desc['default']))
|
||||
if( preg_match("/^[^\s]/i", $field_desc['value']))
|
||||
$sqlfields[$i] .= "(".$field_desc['value'].")";
|
||||
elseif( preg_match("/^[^\s]/i", $field_desc['attribute']))
|
||||
$sqlfields[$i] .= " ".$field_desc['attribute'];
|
||||
elseif( preg_match("/^[^\s]/i", $field_desc['default']))
|
||||
{
|
||||
if(preg_match("/null/i",$field_desc['default']))
|
||||
$sqlfields[$i] .= " default ".$field_desc['default'];
|
||||
if(preg_match("/null/i", $field_desc['default']))
|
||||
$sqlfields[$i] .= " default ".$field_desc['default'];
|
||||
else
|
||||
$sqlfields[$i] .= " default '".$field_desc['default']."'";
|
||||
$sqlfields[$i] .= " default '".$field_desc['default']."'";
|
||||
}
|
||||
elseif( preg_match("/^[^\s]/i",$field_desc['null']))
|
||||
$sqlfields[$i] .= " ".$field_desc['null'];
|
||||
elseif( preg_match("/^[^\s]/i", $field_desc['null']))
|
||||
$sqlfields[$i] .= " ".$field_desc['null'];
|
||||
|
||||
elseif( preg_match("/^[^\s]/i",$field_desc['extra']))
|
||||
$sqlfields[$i] .= " ".$field_desc['extra'];
|
||||
elseif( preg_match("/^[^\s]/i", $field_desc['extra']))
|
||||
$sqlfields[$i] .= " ".$field_desc['extra'];
|
||||
$i++;
|
||||
}
|
||||
if($primary_key != "")
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -120,7 +120,7 @@ class DoliDBSqlite3 extends DoliDB
|
||||
$this->database_selected = false;
|
||||
$this->database_name = '';
|
||||
//$this->error=sqlite_connect_error();
|
||||
dol_syslog(get_class($this)."::DoliDBSqlite3 : Error Connect ".$this->error,LOG_ERR);
|
||||
dol_syslog(get_class($this)."::DoliDBSqlite3 : Error Connect ".$this->error, LOG_ERR);
|
||||
}
|
||||
|
||||
return $this->ok;
|
||||
@@ -137,11 +137,11 @@ class DoliDBSqlite3 extends DoliDB
|
||||
static function convertSQLFromMysql($line, $type = 'ddl')
|
||||
{
|
||||
// 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;
|
||||
}
|
||||
@@ -149,90 +149,90 @@ class DoliDBSqlite3 extends DoliDB
|
||||
{
|
||||
if ($type == 'auto')
|
||||
{
|
||||
if (preg_match('/ALTER TABLE/i',$line)) $type='dml';
|
||||
elseif (preg_match('/CREATE TABLE/i',$line)) $type='dml';
|
||||
elseif (preg_match('/DROP TABLE/i',$line)) $type='dml';
|
||||
if (preg_match('/ALTER TABLE/i', $line)) $type='dml';
|
||||
elseif (preg_match('/CREATE TABLE/i', $line)) $type='dml';
|
||||
elseif (preg_match('/DROP TABLE/i', $line)) $type='dml';
|
||||
}
|
||||
|
||||
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 integer PRIMARY KEY AUTOINCREMENT',$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 integer PRIMARY KEY AUTOINCREMENT', $line);
|
||||
//$line = "-- ".$line." replaced by --\n".$newline;
|
||||
$line=$newline;
|
||||
}
|
||||
|
||||
// tinyint type conversion
|
||||
$line=str_replace('tinyint','smallint',$line);
|
||||
$line=str_replace('tinyint', '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('/tinytext/i', 'text', $line);
|
||||
$line=preg_replace('/mediumtext/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);
|
||||
|
||||
// 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('/AFTER [a-z0-9_]+/i','',$line);
|
||||
$line=preg_replace('/AFTER [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_]+ 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
|
||||
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.= "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))
|
||||
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('/ 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 create a unique index instead as dynamic creation of primary key is not supported
|
||||
// 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.= "CREATE UNIQUE INDEX ".$reg[2]." ON ".$reg[1]."(".$reg[3];
|
||||
@@ -240,7 +240,7 @@ class DoliDBSqlite3 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];
|
||||
@@ -248,15 +248,15 @@ class DoliDBSqlite3 extends DoliDB
|
||||
|
||||
// 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.")";
|
||||
}
|
||||
if (preg_match('/ALTER\s+TABLE\s*(.*)\s*ADD\s+CONSTRAINT\s+(.*)\s*FOREIGN\s+KEY\s*\(([\w,\s]+)\)\s*REFERENCES\s+(\w+)\s*\(([\w,\s]+)\)/i',$line, $reg)) {
|
||||
if (preg_match('/ALTER\s+TABLE\s*(.*)\s*ADD\s+CONSTRAINT\s+(.*)\s*FOREIGN\s+KEY\s*\(([\w,\s]+)\)\s*REFERENCES\s+(\w+)\s*\(([\w,\s]+)\)/i', $line, $reg)) {
|
||||
// Pour l'instant les contraintes ne sont pas créées
|
||||
dol_syslog(get_class().'::query line emptied');
|
||||
$line = 'SELECT 0;';
|
||||
@@ -269,24 +269,24 @@ class DoliDBSqlite3 extends DoliDB
|
||||
|
||||
// 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 one 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 two 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 two 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";
|
||||
|
||||
//print "type=".$type." newline=".$line."<br>\n";
|
||||
@@ -327,7 +327,7 @@ class DoliDBSqlite3 extends DoliDB
|
||||
{
|
||||
global $main_data_dir;
|
||||
|
||||
dol_syslog(get_class($this)."::connect name=".$name,LOG_DEBUG);
|
||||
dol_syslog(get_class($this)."::connect name=".$name, LOG_DEBUG);
|
||||
|
||||
$dir=$main_data_dir;
|
||||
if (empty($dir)) $dir=DOL_DATA_ROOT;
|
||||
@@ -383,7 +383,7 @@ class DoliDBSqlite3 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;
|
||||
$this->db->close();
|
||||
unset($this->db); // Clean this->db
|
||||
@@ -408,7 +408,7 @@ class DoliDBSqlite3 extends DoliDB
|
||||
$this->error = 0;
|
||||
|
||||
// Convert MySQL syntax to SQLite syntax
|
||||
if (preg_match('/ALTER\s+TABLE\s*(.*)\s*ADD\s+CONSTRAINT\s+(.*)\s*FOREIGN\s+KEY\s*\(([\w,\s]+)\)\s*REFERENCES\s+(\w+)\s*\(([\w,\s]+)\)/i',$query, $reg)) {
|
||||
if (preg_match('/ALTER\s+TABLE\s*(.*)\s*ADD\s+CONSTRAINT\s+(.*)\s*FOREIGN\s+KEY\s*\(([\w,\s]+)\)\s*REFERENCES\s+(\w+)\s*\(([\w,\s]+)\)/i', $query, $reg)) {
|
||||
// Ajout d'une clef étrangère à la table
|
||||
// procédure de remplacement de la table pour ajouter la contrainte
|
||||
// Exemple : ALTER TABLE llx_adherent ADD CONSTRAINT adherent_fk_soc FOREIGN KEY (fk_soc) REFERENCES llx_societe (rowid)
|
||||
@@ -445,7 +445,7 @@ class DoliDBSqlite3 extends DoliDB
|
||||
// dummy statement
|
||||
$query="SELECT 0";
|
||||
} else {
|
||||
$query=$this->convertSQLFromMysql($query,$type);
|
||||
$query=$this->convertSQLFromMysql($query, $type);
|
||||
}
|
||||
//print "After convertSQLFromMysql:\n".$query."<br>\n";
|
||||
|
||||
@@ -464,7 +464,7 @@ class DoliDBSqlite3 extends DoliDB
|
||||
$this->error=$this->db->lastErrorMsg();
|
||||
}
|
||||
|
||||
if (! preg_match("/^COMMIT/i",$query) && ! preg_match("/^ROLLBACK/i",$query))
|
||||
if (! preg_match("/^COMMIT/i", $query) && ! preg_match("/^ROLLBACK/i", $query))
|
||||
{
|
||||
// Si requete utilisateur, on la sauvegarde ainsi que son resultset
|
||||
if (! is_object($ret) || $this->error)
|
||||
@@ -477,7 +477,7 @@ class DoliDBSqlite3 extends DoliDB
|
||||
|
||||
$errormsg = get_class($this)."::query SQL Error message: ".$this->lasterror;
|
||||
|
||||
if (preg_match('/[0-9]/',$this->lasterrno)) {
|
||||
if (preg_match('/[0-9]/', $this->lasterrno)) {
|
||||
$errormsg .= ' ('.$this->lasterrno.')';
|
||||
}
|
||||
|
||||
@@ -669,14 +669,14 @@ class DoliDBSqlite3 extends DoliDB
|
||||
$errno=$this->db->lastErrorCode();
|
||||
if ($errno=='HY000' || $errno == 0)
|
||||
{
|
||||
if (preg_match('/table.*already exists/i',$this->error)) return 'DB_ERROR_TABLE_ALREADY_EXISTS';
|
||||
elseif (preg_match('/index.*already exists/i',$this->error)) return 'DB_ERROR_KEY_NAME_ALREADY_EXISTS';
|
||||
elseif (preg_match('/syntax error/i',$this->error)) return 'DB_ERROR_SYNTAX';
|
||||
if (preg_match('/table.*already exists/i', $this->error)) return 'DB_ERROR_TABLE_ALREADY_EXISTS';
|
||||
elseif (preg_match('/index.*already exists/i', $this->error)) return 'DB_ERROR_KEY_NAME_ALREADY_EXISTS';
|
||||
elseif (preg_match('/syntax error/i', $this->error)) return 'DB_ERROR_SYNTAX';
|
||||
}
|
||||
if ($errno=='23000')
|
||||
{
|
||||
if (preg_match('/column.* not unique/i',$this->error)) return 'DB_ERROR_RECORD_ALREADY_EXISTS';
|
||||
elseif (preg_match('/PRIMARY KEY must be unique/i',$this->error)) return 'DB_ERROR_RECORD_ALREADY_EXISTS';
|
||||
if (preg_match('/column.* not unique/i', $this->error)) return 'DB_ERROR_RECORD_ALREADY_EXISTS';
|
||||
elseif (preg_match('/PRIMARY KEY must be unique/i', $this->error)) return 'DB_ERROR_RECORD_ALREADY_EXISTS';
|
||||
}
|
||||
if ($errno > 1) {
|
||||
// TODO Voir la liste des messages d'erreur
|
||||
@@ -820,14 +820,14 @@ class DoliDBSqlite3 extends DoliDB
|
||||
$sql = 'CREATE DATABASE '.$database;
|
||||
$sql.= ' DEFAULT CHARACTER SET '.$charset.' DEFAULT COLLATE '.$collation;
|
||||
|
||||
dol_syslog($sql,LOG_DEBUG);
|
||||
dol_syslog($sql, LOG_DEBUG);
|
||||
$ret=$this->query($sql);
|
||||
if (! $ret)
|
||||
{
|
||||
// We try again for compatibility with Mysql < 4.1.1
|
||||
$sql = 'CREATE DATABASE '.$database;
|
||||
$ret=$this->query($sql);
|
||||
dol_syslog($sql,LOG_DEBUG);
|
||||
dol_syslog($sql, LOG_DEBUG);
|
||||
}
|
||||
return $ret;
|
||||
}
|
||||
@@ -875,7 +875,7 @@ class DoliDBSqlite3 extends DoliDB
|
||||
|
||||
$sql="SHOW FULL COLUMNS FROM ".$table.";";
|
||||
|
||||
dol_syslog($sql,LOG_DEBUG);
|
||||
dol_syslog($sql, LOG_DEBUG);
|
||||
$result = $this->query($sql);
|
||||
if ($result)
|
||||
{
|
||||
@@ -913,22 +913,22 @@ class DoliDBSqlite3 extends DoliDB
|
||||
{
|
||||
$sqlfields[$i] = $field_name." ";
|
||||
$sqlfields[$i] .= $field_desc['type'];
|
||||
if( preg_match("/^[^\s]/i",$field_desc['value']))
|
||||
$sqlfields[$i] .= "(".$field_desc['value'].")";
|
||||
elseif( preg_match("/^[^\s]/i",$field_desc['attribute']))
|
||||
$sqlfields[$i] .= " ".$field_desc['attribute'];
|
||||
elseif( preg_match("/^[^\s]/i",$field_desc['default']))
|
||||
if( preg_match("/^[^\s]/i", $field_desc['value']))
|
||||
$sqlfields[$i] .= "(".$field_desc['value'].")";
|
||||
elseif( preg_match("/^[^\s]/i", $field_desc['attribute']))
|
||||
$sqlfields[$i] .= " ".$field_desc['attribute'];
|
||||
elseif( preg_match("/^[^\s]/i", $field_desc['default']))
|
||||
{
|
||||
if(preg_match("/null/i",$field_desc['default']))
|
||||
$sqlfields[$i] .= " default ".$field_desc['default'];
|
||||
if(preg_match("/null/i", $field_desc['default']))
|
||||
$sqlfields[$i] .= " default ".$field_desc['default'];
|
||||
else
|
||||
$sqlfields[$i] .= " default '".$field_desc['default']."'";
|
||||
$sqlfields[$i] .= " default '".$field_desc['default']."'";
|
||||
}
|
||||
elseif( preg_match("/^[^\s]/i",$field_desc['null']))
|
||||
$sqlfields[$i] .= " ".$field_desc['null'];
|
||||
elseif( preg_match("/^[^\s]/i", $field_desc['null']))
|
||||
$sqlfields[$i] .= " ".$field_desc['null'];
|
||||
|
||||
elseif( preg_match("/^[^\s]/i",$field_desc['extra']))
|
||||
$sqlfields[$i] .= " ".$field_desc['extra'];
|
||||
elseif( preg_match("/^[^\s]/i", $field_desc['extra']))
|
||||
$sqlfields[$i] .= " ".$field_desc['extra'];
|
||||
$i++;
|
||||
}
|
||||
if($primary_key != "")
|
||||
@@ -952,16 +952,16 @@ class DoliDBSqlite3 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;
|
||||
return 1;
|
||||
@@ -998,7 +998,7 @@ class DoliDBSqlite3 extends DoliDB
|
||||
// phpcs:enable
|
||||
$sql="DESC ".$table." ".$field;
|
||||
|
||||
dol_syslog(get_class($this)."::DDLDescTable ".$sql,LOG_DEBUG);
|
||||
dol_syslog(get_class($this)."::DDLDescTable ".$sql, LOG_DEBUG);
|
||||
$this->_results = $this->query($sql);
|
||||
return $this->_results;
|
||||
}
|
||||
@@ -1020,27 +1020,27 @@ class DoliDBSqlite3 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('date','datetime')))
|
||||
if(preg_match("/^[^\s]/i", $field_desc['value']))
|
||||
if (! in_array($field_desc['type'], array('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("/^[^\s]/i", $field_desc['default']))
|
||||
{
|
||||
if(preg_match("/null/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(get_class($this)."::DDLAddField ".$sql,LOG_DEBUG);
|
||||
dol_syslog(get_class($this)."::DDLAddField ".$sql, LOG_DEBUG);
|
||||
if(! $this->query($sql))
|
||||
{
|
||||
return -1;
|
||||
@@ -1066,7 +1066,7 @@ class DoliDBSqlite3 extends DoliDB
|
||||
$sql.="(".$field_desc['value'].")";
|
||||
}
|
||||
|
||||
dol_syslog(get_class($this)."::DDLUpdateField ".$sql,LOG_DEBUG);
|
||||
dol_syslog(get_class($this)."::DDLUpdateField ".$sql, LOG_DEBUG);
|
||||
if (! $this->query($sql))
|
||||
return -1;
|
||||
return 1;
|
||||
@@ -1084,7 +1084,7 @@ class DoliDBSqlite3 extends DoliDB
|
||||
{
|
||||
// phpcs:enable
|
||||
$sql= "ALTER TABLE ".$table." DROP COLUMN `".$field_name."`";
|
||||
dol_syslog(get_class($this)."::DDLDropField ".$sql,LOG_DEBUG);
|
||||
dol_syslog(get_class($this)."::DDLDropField ".$sql, LOG_DEBUG);
|
||||
if (! $this->query($sql))
|
||||
{
|
||||
$this->error=$this->lasterror();
|
||||
@@ -1205,7 +1205,7 @@ class DoliDBSqlite3 extends DoliDB
|
||||
{
|
||||
$liste=$this->fetch_array($resql);
|
||||
$basedir=$liste['Value'];
|
||||
$fullpathofdump=$basedir.(preg_match('/\/$/',$basedir)?'':'/').'bin/mysqldump';
|
||||
$fullpathofdump=$basedir.(preg_match('/\/$/', $basedir)?'':'/').'bin/mysqldump';
|
||||
}
|
||||
return $fullpathofdump;
|
||||
}
|
||||
@@ -1225,7 +1225,7 @@ class DoliDBSqlite3 extends DoliDB
|
||||
{
|
||||
$liste=$this->fetch_array($resql);
|
||||
$basedir=$liste['Value'];
|
||||
$fullpathofimport=$basedir.(preg_match('/\/$/',$basedir)?'':'/').'bin/mysql';
|
||||
$fullpathofimport=$basedir.(preg_match('/\/$/', $basedir)?'':'/').'bin/mysql';
|
||||
}
|
||||
return $fullpathofimport;
|
||||
}
|
||||
@@ -1314,7 +1314,7 @@ class DoliDBSqlite3 extends DoliDB
|
||||
{
|
||||
if ($this->db)
|
||||
{
|
||||
$newname=preg_replace('/_/','',$name);
|
||||
$newname=preg_replace('/_/', '', $name);
|
||||
$localname = __CLASS__ . '::' . 'db' . $newname;
|
||||
$reflectClass = new ReflectionClass(__CLASS__);
|
||||
$reflectFunction = $reflectClass->getMethod('db' . $newname);
|
||||
@@ -1394,8 +1394,8 @@ class DoliDBSqlite3 extends DoliDB
|
||||
private static function calc_week($year, $month, $day, $week_behaviour, &$calc_year)
|
||||
{
|
||||
// phpcs:enable
|
||||
$daynr=self::calc_daynr($year,$month,$day);
|
||||
$first_daynr=self::calc_daynr($year,1,1);
|
||||
$daynr=self::calc_daynr($year, $month, $day);
|
||||
$first_daynr=self::calc_daynr($year, 1, 1);
|
||||
$monday_first= ($week_behaviour & self::WEEK_MONDAY_FIRST) ? 1 : 0;
|
||||
$week_year= ($week_behaviour & self::WEEK_YEAR) ? 1 : 0;
|
||||
$first_weekday= ($week_behaviour & self::WEEK_FIRST_WEEKDAY) ? 1 : 0;
|
||||
|
||||
Reference in New Issue
Block a user