dolibarr  7.0.0-beta
Public Member Functions | Static Public Member Functions | Public Attributes | List of all members
DoliDBPgsql Class Reference

Class to drive a Postgresql database for Dolibarr. More...

+ Inheritance diagram for DoliDBPgsql:
+ Collaboration diagram for DoliDBPgsql:

Public Member Functions

 __construct ($type, $host, $user, $pass, $name='', $port=0)
 Constructor. More...
 
 select_db ($database)
 Select a database Ici postgresql n'a aucune fonction equivalente de mysql_select_db On compare juste manuellement si la database choisie est bien celle activee par la connexion. More...
 
 connect ($host, $login, $passwd, $name, $port=0)
 Connexion to server. More...
 
 getVersion ()
 Return version of database server. More...
 
 getDriverInfo ()
 Return version of database client driver. More...
 
 close ()
 Close database connexion. More...
 
 query ($query, $usesavepoint=0, $type='auto')
 Convert request to PostgreSQL syntax, execute it and return the resultset. More...
 
 fetch_object ($resultset)
 Renvoie la ligne courante (comme un objet) pour le curseur resultset. More...
 
 fetch_array ($resultset)
 Return datas as an array. More...
 
 fetch_row ($resultset)
 Return datas as an array. More...
 
 num_rows ($resultset)
 Return number of lines for result of a SELECT. More...
 
 affected_rows ($resultset)
 Renvoie le nombre de lignes dans le resultat d'une requete INSERT, DELETE ou UPDATE. More...
 
 free ($resultset=null)
 Libere le dernier resultset utilise sur cette connexion. More...
 
 plimit ($limit=0, $offset=0)
 Define limits and offset of request. More...
 
 escape ($stringtoencode)
 Escape a string to insert data. More...
 
 idate ($param)
 Convert (by PHP) a GM Timestamp date into a GM string date to insert into a date field. More...
 
 ifsql ($test, $resok, $resko)
 Format a SQL IF. More...
 
 errno ()
 Renvoie le code erreur generique de l'operation precedente. More...
 
 error ()
 Renvoie le texte de l'erreur pgsql de l'operation precedente. More...
 
 last_insert_id ($tab, $fieldid='rowid')
 Get last ID after an insert INSERT. More...
 
 encrypt ($fieldorvalue, $withQuotes=0)
 Encrypt sensitive data in database Warning: This function includes the escape, so it must use direct value. More...
 
 decrypt ($value)
 Decrypt sensitive data in database. More...
 
 DDLGetConnectId ()
 Return connexion ID. More...
 
 DDLCreateDb ($database, $charset='', $collation='', $owner='')
 Create a new database Do not use function xxx_create_db (xxx=mysql, ...) as they are deprecated We force to create database with charset this->forcecharset and collate this->forcecollate. More...
 
 DDLListTables ($database, $table='')
 List tables into a database. More...
 
 DDLInfoTable ($table)
 List information of columns into a table. More...
 
 DDLCreateTable ($table, $fields, $primary_key, $type, $unique_keys=null, $fulltext_keys=null, $keys=null)
 Create a table into database. More...
 
 DDLDropTable ($table)
 Drop a table into database. More...
 
 DDLCreateUser ($dolibarr_main_db_host, $dolibarr_main_db_user, $dolibarr_main_db_pass, $dolibarr_main_db_name)
 Create a user to connect to database. More...
 
 DDLDescTable ($table, $field="")
 Return a pointer of line with description of a table or field. More...
 
 DDLAddField ($table, $field_name, $field_desc, $field_position="")
 Create a new field into table. More...
 
 DDLUpdateField ($table, $field_name, $field_desc)
 Update format of a field into a table. More...
 
 DDLDropField ($table, $field_name)
 Drop a field from table. More...
 
 getDefaultCharacterSetDatabase ()
 Return charset used to store data in database. More...
 
 getListOfCharacterSet ()
 Return list of available charset that can be used to store data in database. More...
 
 getDefaultCollationDatabase ()
 Return collation used in database. More...
 
 getListOfCollation ()
 Return list of available collation that can be used for database. More...
 
 getPathOfDump ()
 Return full path of dump program. More...
 
 getPathOfRestore ()
 Return full path of restore program. More...
 
 getServerParametersValues ($filter='')
 Return value of server parameters. More...
 
 getServerStatusValues ($filter='')
 Return value of server status. More...
 
- Public Member Functions inherited from DoliDB
 ifsql ($test, $resok, $resko)
 Format a SQL IF. More...
 
 idate ($param)
 Convert (by PHP) a GM Timestamp date into a string date with PHP server TZ to insert into a date field. More...
 
 lasterrno ()
 Return last error code. More...
 
 begin ()
 Start transaction. More...
 
 commit ($log='')
 Validate a database transaction. More...
 
 rollback ($log='')
 Annulation d'une transaction et retour aux anciennes valeurs. More...
 
 plimit ($limit=0, $offset=0)
 Define limits and offset of request. More...
 
 getVersionArray ()
 Return version of database server into an array. More...
 
 lastquery ()
 Return last request executed with query() More...
 
 order ($sortfield=null, $sortorder=null)
 Define sort criteria of request. More...
 
 lasterror ()
 Return last error label. More...
 
 jdate ($string, $gm=false)
 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. More...
 
 lastqueryerror ()
 Return last query in error. More...
 

Static Public Member Functions

static convertSQLFromMysql ($line, $type='auto', $unescapeslashquot=false)
 Convert a SQL request in Mysql syntax to native syntax. More...
 
- Static Public Member Functions inherited from Database
static convertSQLFromMysql ($line, $type= 'ddl')
 Convert a SQL request in Mysql syntax to native syntax. More...
 

Public Attributes

 $type ='pgsql'
 Database type.
 
const LABEL ='PostgreSQL'
 Database label.
 
 $forcecharset ='UTF8'
 Charset.
 
 $forcecollate =''
 Collate used to force collate when creating database.
 
const VERSIONMIN ='9.0.0'
 Version min database.
 

Detailed Description

Class to drive a Postgresql database for Dolibarr.

Definition at line 36 of file pgsql.class.php.

Constructor & Destructor Documentation

DoliDBPgsql::__construct (   $type,
  $host,
  $user,
  $pass,
  $name = '',
  $port = 0 
)

Constructor.

This create an opened connexion to a database server and eventually to a database

Parameters
string$typeType of database (mysql, pgsql...)
string$hostAddress of database server
string$userNom de l'utilisateur autorise
string$passMot de passe
string$nameNom de la database
int$portPort of database server

Definition at line 65 of file pgsql.class.php.

References connect(), dol_syslog(), error(), and select_db().

Member Function Documentation

DoliDBPgsql::affected_rows (   $resultset)

Renvoie le nombre de lignes dans le resultat d'une requete INSERT, DELETE ou UPDATE.

Parameters
resource$resultsetResult set of request
Returns
int Nb of lines
See also
num_rows

Implements Database.

Definition at line 603 of file pgsql.class.php.

DoliDBPgsql::close ( )

Close database connexion.

Returns
boolean True if disconnect successfull, false otherwise
See also
connect

Implements Database.

Definition at line 462 of file pgsql.class.php.

References dol_syslog().

DoliDBPgsql::connect (   $host,
  $login,
  $passwd,
  $name,
  $port = 0 
)

Connexion to server.

Parameters
string$hostDatabase server host
string$loginLogin
string$passwdPassword
string$nameName of database (not used for mysql, used for pgsql)
integer$portPort of database server
Returns
false|resource Database access handler
See also
close

Implements Database.

Definition at line 387 of file pgsql.class.php.

Referenced by __construct().

static DoliDBPgsql::convertSQLFromMysql (   $line,
  $type = 'auto',
  $unescapeslashquot = false 
)
static

Convert a SQL request in Mysql syntax to native syntax.

Parameters
string$lineSQL request line to convert
string$typeType of SQL order ('ddl' for insert, update, select, delete or 'dml' for create, alter...)
bool$unescapeslashquotUnescape slash quote with quote quote
Returns
string SQL request line converted

Definition at line 153 of file pgsql.class.php.

References $type.

Referenced by query().

DoliDBPgsql::DDLAddField (   $table,
  $field_name,
  $field_desc,
  $field_position = "" 
)

Create a new field into table.

Parameters
string$tableName of table
string$field_nameName of field to add
string$field_descTableau associatif de description du champ a inserer[nom du parametre][valeur du parametre]
string$field_positionOptionnel ex.: "after champtruc"
Returns
int <0 if KO, >0 if OK

Implements Database.

Definition at line 1069 of file pgsql.class.php.

References dol_syslog(), and query().

DoliDBPgsql::DDLCreateDb (   $database,
  $charset = '',
  $collation = '',
  $owner = '' 
)

Create a new database Do not use function xxx_create_db (xxx=mysql, ...) as they are deprecated We force to create database with charset this->forcecharset and collate this->forcecollate.

Parameters
string$databaseDatabase name to create
string$charsetCharset used to store data
string$collationCharset used to sort data
string$ownerUsername of database owner
Returns
false|resource resource defined if OK, null if KO

Implements Database.

Definition at line 845 of file pgsql.class.php.

References $forcecharset, $forcecollate, dol_syslog(), and query().

DoliDBPgsql::DDLCreateTable (   $table,
  $fields,
  $primary_key,
  $type,
  $unique_keys = null,
  $fulltext_keys = null,
  $keys = null 
)

Create a table into database.

Parameters
string$tableNom de la table
array$fieldsTableau associatif [nom champ][tableau des descriptions]
string$primary_keyNom du champ qui sera la clef primaire
string$typeType de la table
array$unique_keysTableau associatifs Nom de champs qui seront clef unique => valeur
array$fulltext_keysTableau des Nom de champs qui seront indexes en fulltext
array$keysTableau des champs cles noms => valeur
Returns
int <0 if KO, >=0 if OK

Implements Database.

Definition at line 935 of file pgsql.class.php.

References dol_syslog(), and query().

DoliDBPgsql::DDLCreateUser (   $dolibarr_main_db_host,
  $dolibarr_main_db_user,
  $dolibarr_main_db_pass,
  $dolibarr_main_db_name 
)

Create a user to connect to database.

Parameters
string$dolibarr_main_db_hostIp server
string$dolibarr_main_db_userName of user to create
string$dolibarr_main_db_passPassword of user to create
string$dolibarr_main_db_nameDatabase name where user must be granted
Returns
int <0 if KO, >=0 if OK

Implements Database.

Definition at line 1027 of file pgsql.class.php.

References $resql, dol_syslog(), escape(), and query().

DoliDBPgsql::DDLDescTable (   $table,
  $field = "" 
)

Return a pointer of line with description of a table or field.

Parameters
string$tableName of table
string$fieldOptionnel : Name of field if we want description of field
Returns
false|resource Resultset x (x->attname)

Implements Database.

Definition at line 1049 of file pgsql.class.php.

References dol_syslog(), and query().

DoliDBPgsql::DDLDropField (   $table,
  $field_name 
)

Drop a field from table.

Parameters
string$tableName of table
string$field_nameName of field to drop
Returns
int <0 if KO, >0 if OK

Implements Database.

Definition at line 1149 of file pgsql.class.php.

References dol_syslog(), error(), DoliDB\lasterror(), and query().

DoliDBPgsql::DDLDropTable (   $table)

Drop a table into database.

Parameters
string$tableName of table
Returns
int <0 if KO, >=0 if OK

Implements Database.

Definition at line 1008 of file pgsql.class.php.

References query().

DoliDBPgsql::DDLGetConnectId ( )

Return connexion ID.

Returns
string Id connexion

Implements Database.

Definition at line 827 of file pgsql.class.php.

DoliDBPgsql::DDLInfoTable (   $table)

List information of columns into a table.

Parameters
string$tableName of table
Returns
array Tableau des informations des champs de la table

Implements Database.

Definition at line 890 of file pgsql.class.php.

References dol_syslog(), fetch_row(), and query().

DoliDBPgsql::DDLListTables (   $database,
  $table = '' 
)

List tables into a database.

Parameters
string$databaseName of database
string$tableName of table filter ('xxx')
Returns
array List of tables in an array

Implements Database.

Definition at line 866 of file pgsql.class.php.

References fetch_row().

DoliDBPgsql::DDLUpdateField (   $table,
  $field_name,
  $field_desc 
)

Update format of a field into a table.

Parameters
string$tableName of table
string$field_nameName of field to modify
string$field_descArray with description of field format
Returns
int <0 if KO, >0 if OK

Implements Database.

Definition at line 1107 of file pgsql.class.php.

References dol_syslog(), escape(), and query().

DoliDBPgsql::decrypt (   $value)

Decrypt sensitive data in database.

Parameters
int$valueValue to decrypt
Returns
string Decrypted value if used

Implements Database.

Definition at line 807 of file pgsql.class.php.

DoliDBPgsql::encrypt (   $fieldorvalue,
  $withQuotes = 0 
)

Encrypt sensitive data in database Warning: This function includes the escape, so it must use direct value.

Parameters
string$fieldorvalueField name or value to encrypt
int$withQuotesReturn string with quotes
Returns
string XXX(field) or XXX('value') or field or 'value'

Implements Database.

Definition at line 786 of file pgsql.class.php.

DoliDBPgsql::errno ( )

Renvoie le code erreur generique de l'operation precedente.

Returns
string Error code (Exemples: DB_ERROR_TABLE_ALREADY_EXISTS, DB_ERROR_RECORD_ALREADY_EXISTS...)

Implements Database.

Definition at line 686 of file pgsql.class.php.

Referenced by query().

DoliDBPgsql::error ( )

Renvoie le texte de l'erreur pgsql de l'operation precedente.

Returns
string Error text

Implements Database.

Definition at line 752 of file pgsql.class.php.

Referenced by __construct(), DDLDropField(), and query().

DoliDBPgsql::escape (   $stringtoencode)

Escape a string to insert data.

Parameters
string$stringtoencodeString to escape
Returns
string String escaped

Implements Database.

Definition at line 651 of file pgsql.class.php.

Referenced by DDLCreateUser(), and DDLUpdateField().

DoliDBPgsql::fetch_array (   $resultset)

Return datas as an array.

Parameters
resource$resultsetResultset of request
Returns
false|array Array

Implements Database.

Definition at line 562 of file pgsql.class.php.

Referenced by getDefaultCharacterSetDatabase(), getDefaultCollationDatabase(), getPathOfDump(), getPathOfRestore(), and getVersion().

DoliDBPgsql::fetch_object (   $resultset)

Renvoie la ligne courante (comme un objet) pour le curseur resultset.

Parameters
resource$resultsetCurseur de la requete voulue
Returns
false|object Object result line or false if KO or end of cursor

Implements Database.

Definition at line 549 of file pgsql.class.php.

Referenced by getListOfCharacterSet(), getListOfCollation(), and getServerParametersValues().

DoliDBPgsql::fetch_row (   $resultset)

Return datas as an array.

Parameters
resource$resultsetResultset of request
Returns
false|array Array

Implements Database.

Definition at line 575 of file pgsql.class.php.

Referenced by DDLInfoTable(), and DDLListTables().

DoliDBPgsql::free (   $resultset = null)

Libere le dernier resultset utilise sur cette connexion.

Parameters
resource$resultsetResult set of request
Returns
void

Implements Database.

Definition at line 619 of file pgsql.class.php.

Referenced by getListOfCharacterSet(), and getListOfCollation().

DoliDBPgsql::getDefaultCharacterSetDatabase ( )

Return charset used to store data in database.

Returns
string Charset

Implements Database.

Definition at line 1166 of file pgsql.class.php.

References $resql, fetch_array(), and query().

DoliDBPgsql::getDefaultCollationDatabase ( )

Return collation used in database.

Returns
string Collation value

Implements Database.

Definition at line 1207 of file pgsql.class.php.

References $resql, fetch_array(), and query().

DoliDBPgsql::getDriverInfo ( )

Return version of database client driver.

Returns
string Version string

Implements Database.

Definition at line 451 of file pgsql.class.php.

DoliDBPgsql::getListOfCharacterSet ( )

Return list of available charset that can be used to store data in database.

Returns
array List of Charset

Implements Database.

Definition at line 1182 of file pgsql.class.php.

References $resql, fetch_object(), free(), and query().

DoliDBPgsql::getListOfCollation ( )

Return list of available collation that can be used for database.

Returns
array Liste of Collation

Implements Database.

Definition at line 1223 of file pgsql.class.php.

References $resql, fetch_object(), free(), and query().

DoliDBPgsql::getPathOfDump ( )

Return full path of dump program.

Returns
string Full path of dump program

Implements Database.

Definition at line 1247 of file pgsql.class.php.

References $resql, fetch_array(), and query().

DoliDBPgsql::getPathOfRestore ( )

Return full path of restore program.

Returns
string Full path of restore program

Implements Database.

Definition at line 1275 of file pgsql.class.php.

References $resql, fetch_array(), and query().

DoliDBPgsql::getServerParametersValues (   $filter = '')

Return value of server parameters.

Parameters
string$filterFilter list on a particular value
Returns
array Array of key-values (key=>value)

Implements Database.

Definition at line 1307 of file pgsql.class.php.

References $resql, fetch_object(), and query().

DoliDBPgsql::getServerStatusValues (   $filter = '')

Return value of server status.

Parameters
string$filterFilter list on a particular value
Returns
array Array of key-values (key=>value)

Implements Database.

Definition at line 1328 of file pgsql.class.php.

DoliDBPgsql::getVersion ( )

Return version of database server.

Returns
string Version string

Implements Database.

Definition at line 435 of file pgsql.class.php.

References $resql, fetch_array(), and query().

DoliDBPgsql::idate (   $param)

Convert (by PHP) a GM Timestamp date into a GM string date to insert into a date field.

Function to use to build INSERT, UPDATE or WHERE predica

Parameters
string$paramDate TMS to convert
Returns
string Date in a string YYYY-MM-DD HH:MM:SS

Implements Database.

Definition at line 663 of file pgsql.class.php.

References dol_print_date().

DoliDBPgsql::ifsql (   $test,
  $resok,
  $resko 
)

Format a SQL IF.

Parameters
string$testTest string (example: 'cd.statut=0', 'field IS NULL')
string$resokresultat si test egal
string$reskoresultat si test non egal
Returns
string chaine formate SQL

Implements Database.

Definition at line 676 of file pgsql.class.php.

DoliDBPgsql::last_insert_id (   $tab,
  $fieldid = 'rowid' 
)

Get last ID after an insert INSERT.

Parameters
string$tabTable name concerned by insert. Ne sert pas sous MySql mais requis pour compatibilite avec Postgresql
string$fieldidField name
Returns
string Id of row

Implements Database.

Definition at line 764 of file pgsql.class.php.

References print.

DoliDBPgsql::num_rows (   $resultset)

Return number of lines for result of a SELECT.

Parameters
resourse$resultsetResulset of requests
Returns
int Nb of lines, -1 on error
See also
affected_rows

Implements Database.

Definition at line 589 of file pgsql.class.php.

DoliDBPgsql::plimit (   $limit = 0,
  $offset = 0 
)

Define limits and offset of request.

Parameters
int$limitMaximum number of lines returned (-1=conf->liste_limit, 0=no limit)
int$offsetNumero of line from where starting fetch
Returns
string String with SQL syntax to add a limit and offset

Implements Database.

Definition at line 635 of file pgsql.class.php.

DoliDBPgsql::query (   $query,
  $usesavepoint = 0,
  $type = 'auto' 
)

Convert request to PostgreSQL syntax, execute it and return the resultset.

Parameters
string$querySQL query string
int$usesavepoint0=Default mode, 1=Run a savepoint before and a rollback to savepoint if error (this allow to have some request with errors inside global transactions).
string$typeType of SQL order ('ddl' for insert, update, select, delete or 'dml' for create, alter...)
Returns
false|resource Resultset of answer

Implements Database.

Definition at line 481 of file pgsql.class.php.

References $type, convertSQLFromMysql(), dol_syslog(), errno(), error(), DoliDB\lasterrno(), DoliDB\lasterror(), DoliDB\lastquery(), and DoliDB\lastqueryerror().

Referenced by DDLAddField(), DDLCreateDb(), DDLCreateTable(), DDLCreateUser(), DDLDescTable(), DDLDropField(), DDLDropTable(), DDLInfoTable(), DDLUpdateField(), getDefaultCharacterSetDatabase(), getDefaultCollationDatabase(), getListOfCharacterSet(), getListOfCollation(), getPathOfDump(), getPathOfRestore(), getServerParametersValues(), and getVersion().

DoliDBPgsql::select_db (   $database)

Select a database Ici postgresql n'a aucune fonction equivalente de mysql_select_db On compare juste manuellement si la database choisie est bien celle activee par la connexion.

Parameters
string$databaseName of database
Returns
bool true if OK, false if KO

Implements Database.

Definition at line 370 of file pgsql.class.php.

Referenced by __construct().


The documentation for this class was generated from the following file: