Skip to content
Snippets Groups Projects
Commit 6acaf20c authored by Laurent Destailleur's avatar Laurent Destailleur
Browse files

Merge pull request #1474 from GPCsolutions/dolibdb

Dolidb factorization
parents 271c2a89 a23f6d6a
No related branches found
No related tags found
No related merge requests found
......@@ -35,9 +35,9 @@ abstract class DoliDB implements Database
//! Database label
static $label;
//! Charset used to force charset when creating database
public $forcecharset;
public $forcecharset='utf8';
//! Collate used to force collate when creating database
public $forcecollate;
public $forcecollate='utf8_general_ci';
//! Min database version
static $versionmin;
//! Resultset of last query
......@@ -64,7 +64,96 @@ abstract class DoliDB implements Database
public $ok;
public $error;
/**
* Format a SQL IF
*
* @param string $test Test string (example: 'cd.statut=0', 'field IS NULL')
* @param string $resok resultat si test egal
* @param string $resko resultat si test non egal
* @return string SQL string
*/
function ifsql($test,$resok,$resko)
{
return 'IF('.$test.','.$resok.','.$resko.')';
}
/**
* Convert (by PHP) a GM Timestamp date into a string date with PHP server TZ to insert into a date field.
* Function to use to build INSERT, UPDATE or WHERE predica
*
* @param string $param Date TMS to convert
* @return string Date in a string YYYYMMDDHHMMSS
*/
function idate($param)
{
return dol_print_date($param,"%Y%m%d%H%M%S");
}
/**
* Return last error code
*
* @return string lasterrno
*/
function lasterrno()
{
return $this->lasterrno;
}
/**
* Start transaction
*
* @return int 1 if transaction successfuly opened or already opened, 0 if error
*/
function begin()
{
if (! $this->transaction_opened)
{
$ret=$this->query("BEGIN");
if ($ret)
{
$this->transaction_opened++;
dol_syslog("BEGIN Transaction",LOG_DEBUG);
dol_syslog('',0,1);
}
return $ret;
}
else
{
$this->transaction_opened++;
dol_syslog('',0,1);
return 1;
}
}
/**
* Return version of database server into an array
*
* @return array Version array
*/
function getVersionArray()
{
return explode('.',$this->getVersion());
}
/**
* Return label of manager
*
* @return string Label
*/
function getLabel()
{
return $this->label;
}
/**
* Return last request executed with query()
*
* @return string Last query
*/
function lastquery()
{
return $this->lastquery;
}
/**
* Define sort criteria of request
......@@ -94,5 +183,42 @@ abstract class DoliDB implements Database
return '';
}
}
/**
* Return last error label
*
* @return string lasterror
*/
function lasterror()
{
return $this->lasterror;
}
/**
* Convert (by PHP) a PHP server TZ string date into a Timestamps date (GMT if gm=true)
* 19700101020000 -> 3600 with TZ+1 and gmt=0
* 19700101020000 -> 7200 whaterver is TZ if gmt=1
*
* @param string $string Date in a string (YYYYMMDDHHMMSS, YYYYMMDD, YYYY-MM-DD HH:MM:SS)
* @param int $gm 1=Input informations are GMT values, otherwise local to server TZ
* @return date Date TMS
*/
function jdate($string, $gm=false)
{
$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);
return $date;
}
/**
* Return last query in error
*
* @return string lastqueryerror
*/
function lastqueryerror()
{
return $this->lastqueryerror;
}
}
......@@ -30,8 +30,6 @@ require_once DOL_DOCUMENT_ROOT .'/core/db/DoliDB.class.php';
*/
class DoliDBMssql extends DoliDB
{
//! Database handler
var $db;
//! Database type
public $type='mssql';
//! Database label
......@@ -42,30 +40,8 @@ class DoliDBMssql extends DoliDB
var $forcecollate='latin1_swedish_ci'; // Can't be static as it may be forced with a dynamic value
//! Version min database
static $versionmin=array(2000);
//! Resultset of last request
//! Resultset of last query
private $_results;
//! 1 si connecte, 0 sinon
var $connected;
//! 1 si base selectionne, 0 sinon
var $database_selected;
//! Nom base selectionnee
var $database_name;
//! Nom user base
var $database_user;
//! >=1 if a transaction is opened, 0 otherwise
var $transaction_opened;
//! Derniere requete executee
var $lastquery;
//! Derniere requete executee avec echec
var $lastqueryerror;
//! Message erreur mysql
var $lasterror;
//! Message erreur mysql
var $lasterrno;
var $ok;
var $error;
/**
* Constructor.
......@@ -197,16 +173,6 @@ class DoliDBMssql extends DoliDB
return $this->db;
}
/**
* Return label of manager
*
* @return string Label
*/
function getLabel()
{
return $this->label;
}
/**
* Return version of database server
*
......@@ -219,17 +185,6 @@ class DoliDBMssql extends DoliDB
return $version['computed'];
}
/**
* Return version of database server into an array
*
* @return array Version array
*/
function getVersionArray()
{
return explode('.',$this->getVersion());
}
/**
* Return version of database client driver
*
......@@ -553,77 +508,6 @@ class DoliDBMssql extends DoliDB
return dol_print_date($param,"%Y-%m-%d %H:%M:%S");
}
/**
* Convert (by PHP) a PHP server TZ string date into a Timestamps date (GMT if gm=true)
* 19700101020000 -> 3600 with TZ+1 and gmt=0
* 19700101020000 -> 7200 whaterver is TZ if gmt=1
*
* @param string $string Date in a string (YYYYMMDDHHMMSS, YYYYMMDD, YYYY-MM-DD HH:MM:SS)
* @param int $gm 1=Input informations are GMT values, otherwise local to server TZ
* @return date Date TMS
*/
function jdate($string, $gm=false)
{
$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);
return $date;
}
/**
* Format a SQL IF
*
* @param string $test Test string (example: 'cd.statut=0', 'field IS NULL')
* @param string $resok resultat si test egal
* @param string $resko resultat si test non egal
* @return string SQL string
*/
function ifsql($test,$resok,$resko)
{
return 'IF('.$test.','.$resok.','.$resko.')';
}
/**
* Return last request executed with query()
*
* @return string Last query
*/
function lastquery()
{
return $this->lastquery;
}
/**
* Return last query in error
*
* @return string lastqueryerror
*/
function lastqueryerror()
{
return $this->lastqueryerror;
}
/**
* Return last error label
*
* @return string lasterror
*/
function lasterror()
{
return $this->lasterror;
}
/**
* Return last error code
*
* @return string lasterrno
*/
function lasterrno()
{
return $this->lasterrno;
}
/**
* Return generic error code of last operation.
*
......
......@@ -31,42 +31,14 @@ require_once DOL_DOCUMENT_ROOT .'/core/db/DoliDB.class.php';
*/
class DoliDBMysql extends DoliDB
{
//! Database handler
var $db;
//! Database type
public $type='mysql';
//! Database label
static $label='MySQL';
//! Charset used to force charset when creating database
var $forcecharset='utf8'; // latin1, utf8. Can't be static as it may be forced with a dynamic value
//! Collate used to force collate when creating database
var $forcecollate='utf8_general_ci'; // latin1_swedish_ci, utf8_general_ci. Can't be static as it may be forced with a dynamic value
//! Version min database
static $versionmin=array(4,1,0);
//! Resultset of last request
//! Resultset of last query
private $_results;
//! 1 if connected, 0 else
var $connected;
//! 1 if database selected, 0 else
var $database_selected;
//! Database name selected
var $database_name;
//! Nom user base
var $database_user;
//! >=1 if a transaction is opened, 0 otherwise
var $transaction_opened;
//! Last executed request
var $lastquery;
//! Last failed executed request
var $lastqueryerror;
//! Message erreur mysql
var $lasterror;
//! Message erreur mysql
var $lasterrno;
var $ok;
var $error;
/**
* Constructor.
......@@ -229,16 +201,6 @@ class DoliDBMysql extends DoliDB
return $this->db;
}
/**
* Return label of manager
*
* @return string Label
*/
function getLabel()
{
return $this->label;
}
/**
* Return version of database server
*
......@@ -249,16 +211,6 @@ class DoliDBMysql extends DoliDB
return mysql_get_server_info($this->db);
}
/**
* Return version of database server into an array
*
* @return array Version array
*/
function getVersionArray()
{
return explode('.',$this->getVersion());
}
/**
* Return version of database client driver
*
......@@ -287,33 +239,6 @@ class DoliDBMysql extends DoliDB
return false;
}
/**
* Start transaction
*
* @return int 1 if transaction successfuly opened or already opened, 0 if error
*/
function begin()
{
if (! $this->transaction_opened)
{
$ret=$this->query("BEGIN");
if ($ret)
{
$this->transaction_opened++;
dol_syslog("BEGIN Transaction",LOG_DEBUG);
dol_syslog('',0,1);
}
return $ret;
}
else
{
$this->transaction_opened++;
dol_syslog('',0,1);
return 1;
}
}
/**
* Validate a database transaction
*
......@@ -518,90 +443,6 @@ class DoliDBMysql extends DoliDB
return addslashes($stringtoencode);
}
/**
* Convert (by PHP) a GM Timestamp date into a string date with PHP server TZ to insert into a date field.
* Function to use to build INSERT, UPDATE or WHERE predica
*
* @param string $param Date TMS to convert
* @return string Date in a string YYYYMMDDHHMMSS
*/
function idate($param)
{
return dol_print_date($param,"%Y%m%d%H%M%S");
}
/**
* Convert (by PHP) a PHP server TZ string date into a Timestamps date (GMT if gm=true)
* 19700101020000 -> 3600 with TZ+1 and gmt=0
* 19700101020000 -> 7200 whaterver is TZ if gmt=1
*
* @param string $string Date in a string (YYYYMMDDHHMMSS, YYYYMMDD, YYYY-MM-DD HH:MM:SS)
* @param int $gm 1=Input informations are GMT values, otherwise local to server TZ
* @return date Date TMS
*/
function jdate($string, $gm=false)
{
$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);
return $date;
}
/**
* Format a SQL IF
*
* @param string $test Test string (example: 'cd.statut=0', 'field IS NULL')
* @param string $resok resultat si test egal
* @param string $resko resultat si test non egal
* @return string SQL string
*/
function ifsql($test,$resok,$resko)
{
return 'IF('.$test.','.$resok.','.$resko.')';
}
/**
* Return last request executed with query()
*
* @return string Last query
*/
function lastquery()
{
return $this->lastquery;
}
/**
* Return last query in error
*
* @return string lastqueryerror
*/
function lastqueryerror()
{
return $this->lastqueryerror;
}
/**
* Return last error label
*
* @return string lasterror
*/
function lasterror()
{
return $this->lasterror;
}
/**
* Return last error code
*
* @return string lasterrno
*/
function lasterrno()
{
return $this->lasterrno;
}
/**
* Return generic error code of last operation.
*
......
......@@ -31,42 +31,14 @@ require_once DOL_DOCUMENT_ROOT .'/core/db/DoliDB.class.php';
*/
class DoliDBMysqli extends DoliDB
{
//! Database handler
var $db;
//! Database type
public $type='mysqli';
//! Database label
static $label='MySQL';
//! Charset used to force charset when creating database
var $forcecharset='utf8'; // latin1, utf8. Can't be static as it may be forced with a dynamic value
//! Collate used to force collate when creating database
var $forcecollate='utf8_general_ci'; // latin1_swedish_ci, utf8_general_ci. Can't be static as it may be forced with a dynamic value
//! Version min database
static $versionmin=array(4,1,0);
//! Resultset of last request
//! Resultset of last query
private $_results;
//! 1 if connected, 0 else
var $connected;
//! 1 if database selected, 0 else
var $database_selected;
//! Database name selected
var $database_name;
//! Nom user base
var $database_user;
//! >=1 if a transaction is opened, 0 otherwise
var $transaction_opened;
//! Last executed request
var $lastquery;
//! Last failed executed request
var $lastqueryerror;
//! Message erreur mysql
var $lasterror;
//! Message erreur mysql
var $lasterrno;
var $ok;
var $error;
/**
* Constructor.
......@@ -233,16 +205,6 @@ class DoliDBMysqli extends DoliDB
return $this->db;
}
/**
* Return label of manager
*
* @return string Label
*/
function getLabel()
{
return $this->label;
}
/**
* Return version of database server
*
......@@ -253,16 +215,6 @@ class DoliDBMysqli extends DoliDB
return mysqli_get_server_info($this->db);
}
/**
* Return version of database server into an array
*
* @return array Version array
*/
function getVersionArray()
{
return explode('.',$this->getVersion());
}
/**
* Return version of database client driver
*
......@@ -291,33 +243,6 @@ class DoliDBMysqli extends DoliDB
return false;
}
/**
* Start transaction
*
* @return int 1 if transaction successfuly opened or already opened, 0 if error
*/
function begin()
{
if (! $this->transaction_opened)
{
$ret=$this->query("BEGIN");
if ($ret)
{
$this->transaction_opened++;
dol_syslog("BEGIN Transaction",LOG_DEBUG);
dol_syslog('',0,1);
}
return $ret;
}
else
{
$this->transaction_opened++;
dol_syslog('',0,1);
return 1;
}
}
/**
* Validate a database transaction
*
......@@ -529,89 +454,6 @@ class DoliDBMysqli extends DoliDB
return addslashes($stringtoencode);
}
/**
* Convert (by PHP) a GM Timestamp date into a string date with PHP server TZ to insert into a date field.
* Function to use to build INSERT, UPDATE or WHERE predica
*
* @param string $param Date TMS to convert
* @return string Date in a string YYYYMMDDHHMMSS
*/
function idate($param)
{
return dol_print_date($param,"%Y%m%d%H%M%S");
}
/**
* Convert (by PHP) a PHP server TZ string date into a Timestamps date (GMT if gm=true)
* 19700101020000 -> 3600 with TZ+1 and gmt=0
* 19700101020000 -> 7200 whaterver is TZ if gmt=1
*
* @param string $string Date in a string (YYYYMMDDHHMMSS, YYYYMMDD, YYYY-MM-DD HH:MM:SS)
* @param int $gm 1=Input informations are GMT values, otherwise local to server TZ
* @return date Date TMS
*/
function jdate($string, $gm=false)
{
$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);
return $date;
}
/**
* Format a SQL IF
*
* @param string $test Test string (example: 'cd.statut=0', 'field IS NULL')
* @param string $resok resultat si test egal
* @param string $resko resultat si test non egal
* @return string SQL string
*/
function ifsql($test,$resok,$resko)
{
return 'IF('.$test.','.$resok.','.$resko.')';
}
/**
* Return last request executed with query()
*
* @return string Last query
*/
function lastquery()
{
return $this->lastquery;
}
/**
* Renvoie la derniere requete en erreur
*
* @return string lastqueryerror
*/
function lastqueryerror()
{
return $this->lastqueryerror;
}
/**
* Renvoie le libelle derniere erreur
*
* @return string lasterror
*/
function lasterror()
{
return $this->lasterror;
}
/**
* Renvoie le code derniere erreur
*
* @return string lasterrno
*/
function lasterrno()
{
return $this->lasterrno;
}
/**
* Return generic error code of last operation.
*
......
......@@ -34,8 +34,6 @@ require_once DOL_DOCUMENT_ROOT .'/core/db/DoliDB.class.php';
*/
class DoliDBPgsql extends DoliDB
{
//! Database handler
var $db;
//! Database type
public $type='pgsql'; // Name of manager
//! Database label
......@@ -46,29 +44,9 @@ class DoliDBPgsql extends DoliDB
var $forcecollate=''; // Can't be static as it may be forced with a dynamic value
//! Version min database
static $versionmin=array(8,4,0); // Version min database
//! Resultset of last request
//! Resultset of last query
private $_results;
var $connected; // 1 si connecte, 0 sinon
var $database_selected; // 1 si base selectionne, 0 sinon
var $database_name; //! Nom base selectionnee
var $database_user; //! Nom user base
//! >=1 if a transaction is opened, 0 otherwise
var $transaction_opened;
var $lastquery;
// Saved last error
var $lastqueryerror;
var $lasterror;
var $lasterrno;
var $unescapeslashquot=0; // By default we do not force the unescape of \'. This is used only to process sql with mysql escaped data.
var $standard_conforming_strings=1; // Database has option standard_conforming_strings to on
var $ok;
var $error;
/**
* Constructor.
* This create an opened connexion to a database server and eventually to a database
......@@ -424,16 +402,6 @@ class DoliDBPgsql extends DoliDB
return $this->db;
}
/**
* Return label of manager
*
* @return string Label
*/
function getLabel()
{
return $this->label;
}
/**
* Return version of database server
*
......@@ -450,16 +418,6 @@ class DoliDBPgsql extends DoliDB
return '';
}
/**
* Return version of database server into an array
*
* @return array Version array
*/
function getVersionArray()
{
return explode('.',$this->getVersion());
}
/**
* Return version of database client driver
*
......@@ -752,23 +710,6 @@ class DoliDBPgsql extends DoliDB
return dol_print_date($param,"%Y-%m-%d %H:%M:%S");
}
/**
* Convert (by PHP) a PHP server TZ string date into a Timestamps date (GMT if gm=true)
* 19700101020000 -> 3600 with TZ+1 and gmt=0
* 19700101020000 -> 7200 whaterver is TZ if gmt=1
*
* @param string $string Date in a string (YYYYMMDDHHMMSS, YYYYMMDD, YYYY-MM-DD HH:MM:SS)
* @param int $gm 1=Input informations are GMT values, otherwise local to server TZ
* @return date Date TMS
*/
function jdate($string, $gm=false)
{
$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);
return $date;
}
/**
* Format a SQL IF
*
......@@ -782,47 +723,6 @@ class DoliDBPgsql extends DoliDB
return '(CASE WHEN '.$test.' THEN '.$resok.' ELSE '.$resko.' END)';
}
/**
* Renvoie la derniere requete soumise par la methode query()
*
* @return lastquery
*/
function lastquery()
{
return $this->lastquery;
}
/**
* Renvoie la derniere requete en erreur
*
* @return string lastqueryerror
*/
function lastqueryerror()
{
return $this->lastqueryerror;
}
/**
* Renvoie le libelle derniere erreur
*
* @return string lasterror
*/
function lasterror()
{
return $this->lasterror;
}
/**
* Renvoie le code derniere erreur
*
* @return string lasterrno
*/
function lasterrno()
{
return $this->lasterrno;
}
/**
* Renvoie le code erreur generique de l'operation precedente.
*
......
......@@ -31,42 +31,14 @@ require_once DOL_DOCUMENT_ROOT .'/core/db/DoliDB.class.php';
*/
class DoliDBSqlite extends DoliDB
{
//! Database handler
var $db;
//! Database type
public $type='sqlite';
//! Database label
static $label='PDO Sqlite';
//! Charset used to force charset when creating database
var $forcecharset='utf8'; // latin1, utf8. Can't be static as it may be forced with a dynamic value
//! Collate used to force collate when creating database
var $forcecollate='utf8_general_ci'; // latin1_swedish_ci, utf8_general_ci. Can't be static as it may be forced with a dynamic value
//! Version min database
static $versionmin=array(3,0,0);
//! Resultset of last request
//! Resultset of last query
private $_results;
//! 1 if connected, 0 else
var $connected;
//! 1 if database selected, 0 else
var $database_selected;
//! Database name selected
var $database_name;
//! Nom user base
var $database_user;
//! >=1 if a transaction is opened, 0 otherwise
var $transaction_opened;
//! Last executed request
var $lastquery;
//! Last failed executed request
var $lastqueryerror;
//! Message erreur mysql
var $lasterror;
//! Message erreur mysql
var $lasterrno;
var $ok;
var $error;
/**
* Constructor.
......@@ -351,15 +323,6 @@ class DoliDBSqlite extends DoliDB
return $this->db;
}
/**
* Return label of manager
*
* @return string Label
*/
function getLabel()
{
return $this->label;
}
/**
* Return version of database server
......@@ -373,16 +336,6 @@ class DoliDBSqlite extends DoliDB
return $row[0];
}
/**
* Return version of database server into an array
*
* @return array Version array
*/
function getVersionArray()
{
return explode('.',$this->getVersion());
}
/**
* Return version of database client driver
*
......@@ -415,33 +368,6 @@ class DoliDBSqlite extends DoliDB
return false;
}
/**
* Start transaction
*
* @return int 1 if transaction successfuly opened or already opened, 0 if error
*/
function begin()
{
if (! $this->transaction_opened)
{
$ret=$this->query("BEGIN");
if ($ret)
{
$this->transaction_opened++;
dol_syslog("BEGIN Transaction",LOG_DEBUG);
dol_syslog('',0,1);
}
return $ret;
}
else
{
$this->transaction_opened++;
dol_syslog('',0,1);
return 1;
}
}
/**
* Validate a database transaction
*
......@@ -662,90 +588,6 @@ class DoliDBSqlite extends DoliDB
return $this->db->quote($stringtoencode);
}
/**
* Convert (by PHP) a GM Timestamp date into a PHP server TZ to insert into a date field.
* Function to use to build INSERT, UPDATE or WHERE predica
*
* @param string $param Date TMS to convert
* @return string Date in a string YYYYMMDDHHMMSS
*/
function idate($param)
{
return dol_print_date($param,"%Y%m%d%H%M%S");
}
/**
* Convert (by PHP) a PHP server TZ string date into a Timestamps date (GMT if gm=true)
* 19700101020000 -> 3600 with TZ+1 and gmt=0
* 19700101020000 -> 7200 whaterver is TZ if gmt=1
*
* @param string $string Date in a string (YYYYMMDDHHMMSS, YYYYMMDD, YYYY-MM-DD HH:MM:SS)
* @param int $gm 1=Input informations are GMT values, otherwise local to server TZ
* @return date Date TMS
*/
function jdate($string, $gm=false)
{
$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);
return $date;
}
/**
* Format a SQL IF
*
* @param string $test Test string (example: 'cd.statut=0', 'field IS NULL')
* @param string $resok resultat si test egal
* @param string $resko resultat si test non egal
* @return string SQL string
*/
function ifsql($test,$resok,$resko)
{
return 'IF('.$test.','.$resok.','.$resko.')';
}
/**
* Renvoie la derniere requete soumise par la methode query()
*
* @return lastquery
*/
function lastquery()
{
return $this->lastquery;
}
/**
* Return last query in error
*
* @return string lastqueryerror
*/
function lastqueryerror()
{
return $this->lastqueryerror;
}
/**
* Return last error label
*
* @return string lasterror
*/
function lasterror()
{
return $this->lasterror;
}
/**
* Return last error code
*
* @return string lasterrno
*/
function lasterrno()
{
return $this->lasterrno;
}
/**
* Renvoie le code erreur generique de l'operation precedente.
*
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment