dolibarr  19.0.0-dev
Public Member Functions | Public Attributes | Protected Member Functions | List of all members
TraceableDB Class Reference

TraceableDB class. More...

Inheritance diagram for TraceableDB:
Inheritance graph
[legend]
Collaboration diagram for TraceableDB:
Collaboration graph
[legend]

Public Member Functions

 __construct ($db)
 Constructor. More...
 
 ifsql ($test, $resok, $resko)
 Format a SQL IF. More...
 
 fetch_row ($resultset)
 Return datas as an array. More...
 
 idate ($param, $gm='tzserver')
 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 ($textinlog='')
 Start transaction. 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...
 
 getVersionArray ()
 Return version of database server into an array. More...
 
 convertSQLFromMysql ($line, $type='ddl')
 Convert a SQL request in Mysql syntax to native syntax. More...
 
 affected_rows ($resultset)
 Return the number o flines into the result of a request INSERT, DELETE or UPDATE. More...
 
 error ()
 Return description of last error. More...
 
 DDLListTables ($database, $table='')
 List tables into a database. More...
 
 DDLListTablesFull ($database, $table='')
 List tables into a database with table info. More...
 
 lastquery ()
 Return last request executed with query() More...
 
 order ($sortfield=null, $sortorder=null)
 Define sort criteria of request. More...
 
 decrypt ($value)
 Decrypt sensitive data in database. More...
 
 fetch_array ($resultset)
 Return datas as an array. More...
 
 lasterror ()
 Return last error label. More...
 
 escape ($stringtoencode)
 Escape a string to insert data. More...
 
 escapeforlike ($stringtoencode)
 Escape a string to insert data into a like. More...
 
 last_insert_id ($tab, $fieldid='rowid')
 Get last ID after an insert INSERT. More...
 
 getPathOfRestore ()
 Return full path of restore program. More...
 
 rollback ($log='')
 Cancel a transaction and go back to initial data values. More...
 
 query ($query, $usesavepoint=0, $type='auto', $result_mode=0)
 Execute a SQL request and return the resultset. More...
 
 connect ($host, $login, $passwd, $name, $port=0)
 Connexion to server. More...
 
 plimit ($limit=0, $offset=0)
 Define limits and offset of request. More...
 
 getServerParametersValues ($filter='')
 Return value of server parameters. More...
 
 getServerStatusValues ($filter='')
 Return value of server status. More...
 
 getDefaultCollationDatabase ()
 Return collation used in database. More...
 
 num_rows ($resultset)
 Return number of lines for result of a SELECT. More...
 
 getPathOfDump ()
 Return full path of dump program. More...
 
 getDriverInfo ()
 Return version of database client driver. More...
 
 errno ()
 Return generic error code of last operation. 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...
 
 getListOfCharacterSet ()
 Return list of available charset that can be used to store data in database. More...
 
 DDLAddField ($table, $field_name, $field_desc, $field_position="")
 Create a new field into table. More...
 
 DDLDropField ($table, $field_name)
 Drop a field from table. More...
 
 DDLUpdateField ($table, $field_name, $field_desc)
 Update format of a field into a table. More...
 
 getListOfCollation ()
 Return list of available collation that can be used for database. More...
 
 DDLDescTable ($table, $field="")
 Return a pointer of line with description of a table or field. More...
 
 getVersion ()
 Return version of database server. More...
 
 getDefaultCharacterSetDatabase ()
 Return charset used to store data in database. More...
 
 DDLCreateUser ($dolibarr_main_db_host, $dolibarr_main_db_user, $dolibarr_main_db_pass, $dolibarr_main_db_name)
 Create a user and privileges to connect to database (even if database does not exists yet) 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...
 
 encrypt ($fieldorvalue, $withQuotes=1)
 Encrypt sensitive data in database Warning: This function includes the escape and add the SQL simple quotes on strings. More...
 
 commit ($log='')
 Validate a database transaction. More...
 
 DDLInfoTable ($table)
 List information of columns into a table. More...
 
 free ($resultset=null)
 Free last resultset used. More...
 
 close ()
 Close database connexion. More...
 
 lastqueryerror ()
 Return last query in error. More...
 
 DDLGetConnectId ()
 Return connexion ID. More...
 
 fetch_object ($resultset)
 Returns the current line (as an object) for the resultset cursor. More...
 
 select_db ($database)
 Select a database. More...
 
- Public Member Functions inherited from DoliDB
 prefix ()
 Return the DB prefix found into prefix_db (if it was set manually by doing $dbhandler->prefix_db=...). More...
 
 hintindex ($nameofindex)
 Return SQL string to force an index. More...
 
 regexpsql ($subject, $pattern, $sqlstring=false)
 Format a SQL REGEXP. More...
 
 sanitize ($stringtosanitize, $allowsimplequote=0, $allowsequals=0)
 Sanitize a string for SQL forging. More...
 
 getRow ($sql)
 Return first result from query as object Note : This method executes a given SQL query and retrieves the first row of results as an object. More...
 
 getRows ($sql)
 Return all results from query as an array of objects Note : This method executes a given SQL query and retrieves all row of results as an array of objects. More...
 
- Public Member Functions inherited from Database
 idate ($param)
 Convert (by PHP) a GM Timestamp date into a string date with PHP server TZ to insert into a date field. More...
 
 sanitize ($stringtosanitize)
 Sanitize a string for SQL forging. More...
 

Public Attributes

const LABEL = ''
 @const Database label
 
const VERSIONMIN = ''
 @const Version min database
 

Protected Member Functions

 startTracing ()
 Start query tracing. More...
 
 endTracing ($sql, $resql)
 End query tracing. More...
 

Detailed Description

TraceableDB class.

Used to log queries into DebugBar

Definition at line 31 of file TraceableDB.php.

Constructor & Destructor Documentation

◆ __construct()

TraceableDB::__construct (   $db)

Constructor.

Parameters
DoliDB$dbDatabase handler

Definition at line 67 of file TraceableDB.php.

References type.

Member Function Documentation

◆ affected_rows()

TraceableDB::affected_rows (   $resultset)

Return the number o flines into the result of a request INSERT, DELETE or UPDATE.

Parameters
resource$resultsetCurseur de la requete voulue
Returns
int Number of lines
See also
num_rows()

Implements Database.

Definition at line 180 of file TraceableDB.php.

◆ begin()

TraceableDB::begin (   $textinlog = '')

Start transaction.

Parameters
string$textinlogAdd a small text into log. '' by default.
Returns
int 1 if transaction successfuly opened or already opened, 0 if error

Reimplemented from DoliDB.

Definition at line 129 of file TraceableDB.php.

◆ close()

TraceableDB::close ( )

Close database connexion.

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

Implements Database.

Definition at line 694 of file TraceableDB.php.

◆ commit()

TraceableDB::commit (   $log = '')

Validate a database transaction.

Parameters
string$logAdd more log to default log line
Returns
int 1 if validation is OK or transaction level no started, 0 if ERROR

Reimplemented from DoliDB.

Definition at line 661 of file TraceableDB.php.

◆ connect()

TraceableDB::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)
int$portPort of database server
Returns
resource Database access handler
See also
close()

Implements Database.

Definition at line 400 of file TraceableDB.php.

◆ convertSQLFromMysql()

TraceableDB::convertSQLFromMysql (   $line,
  $type = 'ddl' 
)

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...)
Returns
string SQL request line converted

Implements Database.

Definition at line 167 of file TraceableDB.php.

◆ DDLAddField()

TraceableDB::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 540 of file TraceableDB.php.

◆ DDLCreateDb()

TraceableDB::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
resource resource defined if OK, null if KO

Implements Database.

Definition at line 145 of file TraceableDB.php.

◆ DDLCreateTable()

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

Create a table into database.

Parameters
string$tableName of 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 505 of file TraceableDB.php.

◆ DDLCreateUser()

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

Create a user and privileges to connect to database (even if database does not exists yet)

Parameters
string$dolibarr_main_db_hostIp serveur
string$dolibarr_main_db_userNom user a creer
string$dolibarr_main_db_passMot de passe user a creer
string$dolibarr_main_db_nameDatabase name where user must be granted
Returns
int <0 if KO, >=0 if OK

Implements Database.

Definition at line 621 of file TraceableDB.php.

◆ DDLDescTable()

TraceableDB::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
resource Resource

Implements Database.

Definition at line 587 of file TraceableDB.php.

◆ DDLDropField()

TraceableDB::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 552 of file TraceableDB.php.

◆ DDLDropTable()

TraceableDB::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 516 of file TraceableDB.php.

◆ DDLGetConnectId()

TraceableDB::DDLGetConnectId ( )

Return connexion ID.

Returns
string Id connexion

Implements Database.

Definition at line 714 of file TraceableDB.php.

◆ DDLInfoTable()

TraceableDB::DDLInfoTable (   $table)

List information of columns into a table.

Parameters
string$tableName of table
Returns
array Array with inforation on table

Implements Database.

Definition at line 672 of file TraceableDB.php.

◆ DDLListTables()

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

List tables into a database.

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

Implements Database.

Definition at line 203 of file TraceableDB.php.

◆ DDLListTablesFull()

TraceableDB::DDLListTablesFull (   $database,
  $table = '' 
)

List tables into a database with table info.

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

Implements Database.

Definition at line 215 of file TraceableDB.php.

◆ DDLUpdateField()

TraceableDB::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 565 of file TraceableDB.php.

◆ decrypt()

TraceableDB::decrypt (   $value)

Decrypt sensitive data in database.

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

Implements Database.

Definition at line 248 of file TraceableDB.php.

◆ encrypt()

TraceableDB::encrypt (   $fieldorvalue,
  $withQuotes = 1 
)

Encrypt sensitive data in database Warning: This function includes the escape and add the SQL simple quotes on strings.

Parameters
string$fieldorvalueField name or value to encrypt
int$withQuotesReturn string including the SQL simple quotes. This param must always be 1 (Value 0 is bugged and deprecated).
Returns
string XXX(field) or XXX('value') or field or 'value'

Implements Database.

Definition at line 650 of file TraceableDB.php.

◆ endTracing()

TraceableDB::endTracing (   $sql,
  $resql 
)
protected

End query tracing.

Parameters
string$sqlquery string
string$resqlquery result
Returns
void

Definition at line 372 of file TraceableDB.php.

◆ errno()

TraceableDB::errno ( )

Return generic error code of last operation.

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

Implements Database.

Definition at line 488 of file TraceableDB.php.

◆ error()

TraceableDB::error ( )

Return description of last error.

Returns
string Error text

Implements Database.

Definition at line 191 of file TraceableDB.php.

◆ escape()

TraceableDB::escape (   $stringtoencode)

Escape a string to insert data.

Parameters
string$stringtoencodeString to escape
Returns
string String escaped

Implements Database.

Definition at line 282 of file TraceableDB.php.

◆ escapeforlike()

TraceableDB::escapeforlike (   $stringtoencode)

Escape a string to insert data into a like.

Parameters
string$stringtoencodeString to escape
Returns
string String escaped

Implements Database.

Definition at line 293 of file TraceableDB.php.

◆ fetch_array()

TraceableDB::fetch_array (   $resultset)

Return datas as an array.

Parameters
resource$resultsetResultset of request
Returns
array Array

Implements Database.

Definition at line 260 of file TraceableDB.php.

◆ fetch_object()

TraceableDB::fetch_object (   $resultset)

Returns the current line (as an object) for the resultset cursor.

Parameters
resource | Connection$resultsetHandler of the desired SQL request
Returns
Object Object result line or false if KO or end of cursor

Implements Database.

Definition at line 726 of file TraceableDB.php.

◆ fetch_row()

TraceableDB::fetch_row (   $resultset)

Return datas as an array.

Parameters
resource$resultsetResultset of request
Returns
array Array

Implements Database.

Definition at line 94 of file TraceableDB.php.

◆ free()

TraceableDB::free (   $resultset = null)

Free last resultset used.

Parameters
resource$resultsetFre cursor
Returns
void

Implements Database.

Definition at line 683 of file TraceableDB.php.

◆ getDefaultCharacterSetDatabase()

TraceableDB::getDefaultCharacterSetDatabase ( )

Return charset used to store data in database.

Returns
string Charset

Implements Database.

Definition at line 607 of file TraceableDB.php.

◆ getDefaultCollationDatabase()

TraceableDB::getDefaultCollationDatabase ( )

Return collation used in database.

Returns
string Collation value

Implements Database.

Definition at line 444 of file TraceableDB.php.

◆ getDriverInfo()

TraceableDB::getDriverInfo ( )

Return version of database client driver.

Returns
string Version string

Implements Database.

Definition at line 478 of file TraceableDB.php.

◆ getListOfCharacterSet()

TraceableDB::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 526 of file TraceableDB.php.

◆ getListOfCollation()

TraceableDB::getListOfCollation ( )

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

Returns
array List of Collation

Implements Database.

Definition at line 575 of file TraceableDB.php.

◆ getPathOfDump()

TraceableDB::getPathOfDump ( )

Return full path of dump program.

Returns
string Full path of dump program

Implements Database.

Definition at line 468 of file TraceableDB.php.

◆ getPathOfRestore()

TraceableDB::getPathOfRestore ( )

Return full path of restore program.

Returns
string Full path of restore program

Implements Database.

Definition at line 317 of file TraceableDB.php.

◆ getServerParametersValues()

TraceableDB::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 423 of file TraceableDB.php.

◆ getServerStatusValues()

TraceableDB::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 434 of file TraceableDB.php.

◆ getVersion()

TraceableDB::getVersion ( )

Return version of database server.

Returns
string Version string

Implements Database.

Definition at line 597 of file TraceableDB.php.

◆ getVersionArray()

TraceableDB::getVersionArray ( )

Return version of database server into an array.

Returns
array Version array

Reimplemented from DoliDB.

Definition at line 155 of file TraceableDB.php.

◆ idate()

TraceableDB::idate (   $param,
  $gm = 'tzserver' 
)

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

Parameters
int$paramDate TMS to convert
mixed$gm'gmt'=Input informations are GMT values, 'tzserver'=Local to server TZ
Returns
string Date in a string YYYY-MM-DD HH:MM:SS

Reimplemented from DoliDB.

Definition at line 108 of file TraceableDB.php.

◆ ifsql()

TraceableDB::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 SQL string

Reimplemented from DoliDB.

Definition at line 82 of file TraceableDB.php.

◆ jdate()

TraceableDB::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.

Parameters
string$stringDate in a string (YYYYMMDDHHMMSS, YYYYMMDD, YYYY-MM-DD HH:MM:SS)
bool$gm1=Input informations are GMT values, otherwise local to server TZ
Returns
int|string Date TMS or ''

Reimplemented from DoliDB.

Definition at line 636 of file TraceableDB.php.

◆ last_insert_id()

TraceableDB::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
int Id of row

Implements Database.

Definition at line 306 of file TraceableDB.php.

◆ lasterrno()

TraceableDB::lasterrno ( )

Return last error code.

Returns
string lasterrno

Reimplemented from DoliDB.

Definition at line 118 of file TraceableDB.php.

◆ lasterror()

TraceableDB::lasterror ( )

Return last error label.

Returns
string lasterror

Reimplemented from DoliDB.

Definition at line 271 of file TraceableDB.php.

◆ lastquery()

TraceableDB::lastquery ( )

Return last request executed with query()

Returns
string Last query

Reimplemented from DoliDB.

Definition at line 225 of file TraceableDB.php.

◆ lastqueryerror()

TraceableDB::lastqueryerror ( )

Return last query in error.

Returns
string lastqueryerror

Reimplemented from DoliDB.

Definition at line 704 of file TraceableDB.php.

◆ num_rows()

TraceableDB::num_rows (   $resultset)

Return number of lines for result of a SELECT.

Parameters
resource$resultsetResulset of requests
Returns
int Nb of lines
See also
affected_rows()

Implements Database.

Definition at line 457 of file TraceableDB.php.

◆ order()

TraceableDB::order (   $sortfield = null,
  $sortorder = null 
)

Define sort criteria of request.

Parameters
string$sortfieldList of sort fields
string$sortorderSort order
Returns
string String to provide syntax of a sort sql string

Reimplemented from DoliDB.

Definition at line 237 of file TraceableDB.php.

◆ plimit()

TraceableDB::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

Reimplemented from DoliDB.

Definition at line 412 of file TraceableDB.php.

◆ query()

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

Execute a SQL request 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). Note that with Mysql, this parameter is not used as Myssql can already commit a transaction even if one request is in error, without using savepoints.
string$typeType of SQL order ('ddl' for insert, update, select, delete or 'dml' for create, alter...)
int$result_modeResult mode
Returns
resource Resultset of answer

Implements Database.

Definition at line 343 of file TraceableDB.php.

References startTracing().

◆ rollback()

TraceableDB::rollback (   $log = '')

Cancel a transaction and go back to initial data values.

Parameters
string$logAdd more log to default log line
Returns
resource|int 1 if cancelation is ok or transaction not open, 0 if error

Reimplemented from DoliDB.

Definition at line 328 of file TraceableDB.php.

◆ select_db()

TraceableDB::select_db (   $database)

Select a database.

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

Implements Database.

Definition at line 739 of file TraceableDB.php.

◆ startTracing()

TraceableDB::startTracing ( )
protected

Start query tracing.

Returns
void

Definition at line 359 of file TraceableDB.php.

Referenced by query().


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