dolibarr 20.0.0
TraceableDB Class Reference

TraceableDB class. More...

Inheritance diagram for TraceableDB:
Collaboration diagram for TraceableDB:

Public Member Functions

 __construct ($db)
 Constructor.
 
 ifsql ($test, $resok, $resko)
 Format a SQL IF.
 
 fetch_row ($resultset)
 Return datas as an array.
 
 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.
 
 lasterrno ()
 Return last error code.
 
 begin ($textinlog='')
 Start transaction.
 
 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.
 
 getVersionArray ()
 Return version of database server into an array.
 
 convertSQLFromMysql ($line, $type='ddl')
 Convert a SQL request in Mysql syntax to native syntax.
 
 affected_rows ($resultset)
 Return the number o flines into the result of a request INSERT, DELETE or UPDATE.
 
 error ()
 Return description of last error.
 
 DDLListTables ($database, $table='')
 List tables into a database.
 
 DDLListTablesFull ($database, $table='')
 List tables into a database with table info.
 
 lastquery ()
 Return last request executed with query()
 
 order ($sortfield=null, $sortorder=null)
 Define sort criteria of request.
 
 decrypt ($value)
 Decrypt sensitive data in database.
 
 fetch_array ($resultset)
 Return datas as an array.
 
 lasterror ()
 Return last error label.
 
 escape ($stringtoencode)
 Escape a string to insert data.
 
 escapeforlike ($stringtoencode)
 Escape a string to insert data into a like.
 
 last_insert_id ($tab, $fieldid='rowid')
 Get last ID after an insert INSERT.
 
 getPathOfRestore ()
 Return full path of restore program.
 
 rollback ($log='')
 Cancel a transaction and go back to initial data values.
 
 query ($query, $usesavepoint=0, $type='auto', $result_mode=0)
 Execute a SQL request and return the resultset.
 
 connect ($host, $login, $passwd, $name, $port=0)
 Connection to server.
 
 plimit ($limit=0, $offset=0)
 Define limits and offset of request.
 
 getServerParametersValues ($filter='')
 Return value of server parameters.
 
 getServerStatusValues ($filter='')
 Return value of server status.
 
 getDefaultCollationDatabase ()
 Return collation used in database.
 
 num_rows ($resultset)
 Return number of lines for result of a SELECT.
 
 getPathOfDump ()
 Return full path of dump program.
 
 getDriverInfo ()
 Return version of database client driver.
 
 errno ()
 Return generic error code of last operation.
 
 DDLCreateTable ($table, $fields, $primary_key, $type, $unique_keys=null, $fulltext_keys=null, $keys=null)
 Create a table into database.
 
 DDLDropTable ($table)
 Drop a table into database.
 
 getListOfCharacterSet ()
 Return list of available charset that can be used to store data in database.
 
 DDLAddField ($table, $field_name, $field_desc, $field_position="")
 Create a new field into table.
 
 DDLDropField ($table, $field_name)
 Drop a field from table.
 
 DDLUpdateField ($table, $field_name, $field_desc)
 Update format of a field into a table.
 
 getListOfCollation ()
 Return list of available collation that can be used for database.
 
 DDLDescTable ($table, $field="")
 Return a pointer of line with description of a table or field.
 
 getVersion ()
 Return version of database server.
 
 getDefaultCharacterSetDatabase ()
 Return charset used to store data in database.
 
 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)
 
 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.
 
 encrypt ($fieldorvalue, $withQuotes=1)
 Encrypt sensitive data in database Warning: This function includes the escape and add the SQL simple quotes on strings.
 
 commit ($log='')
 Validate a database transaction.
 
 DDLInfoTable ($table)
 List information of columns into a table.
 
 free ($resultset=null)
 Free last resultset used.
 
 close ()
 Close database connection.
 
 lastqueryerror ()
 Return last query in error.
 
 DDLGetConnectId ()
 Return connection ID.
 
 fetch_object ($resultset)
 Returns the current line (as an object) for the resultset cursor.
 
 select_db ($database)
 Select a database.
 
- 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=...).
 
 stddevpop ($nameoffield)
 Return SQL string to aggregate using the Standard Deviation of population.
 
 hintindex ($nameofindex)
 Return SQL string to force an index.
 
 regexpsql ($subject, $pattern, $sqlstring=0)
 Format a SQL REGEXP.
 
 sanitize ($stringtosanitize, $allowsimplequote=0, $allowsequals=0, $allowsspace=0, $allowschars=1)
 Sanitize a string for SQL forging.
 
 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.
 
 getRows ($sql)
 Return all results from query as an array of objects.
 
- 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.
 
 sanitize ($stringtosanitize)
 Sanitize a string for SQL forging.
 

Public Attributes

const LABEL = ''
 @const Database label
 
const VERSIONMIN = ''
 @const Version min database
 
- Public Attributes inherited from DoliDB
const VERSIONMIN = self::VERSIONMIN
 Force subclass to implement VERSIONMIN - required DB version.
 
const LABEL = self::LABEL
 Force subclass to implement LABEL - description of DB type.
 

Protected Member Functions

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

Detailed Description

TraceableDB class.

Used to log queries into DebugBar

Definition at line 33 of file TraceableDB.php.

Constructor & Destructor Documentation

◆ __construct()

TraceableDB::__construct ( $db)

Constructor.

Parameters
DoliDB$dbDatabase handler

Definition at line 69 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 182 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 successfully opened or already opened, 0 if error

Reimplemented from DoliDB.

Definition at line 131 of file TraceableDB.php.

◆ close()

TraceableDB::close ( )

Close database connection.

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

Implements Database.

Definition at line 696 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 663 of file TraceableDB.php.

◆ connect()

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

Connection 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 402 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 169 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
array{type:string,label:string,enabled:int|string,position:int,notnull?:int,visible:int,noteditable?:int,default?:string,index?:int,foreignkey?:string,searchall?:int,isameasure?:int,css?:string,csslist?:string,help?:string,showoncombobox?:int,disabled?:int,arrayofkeyval?:array<int,string>,comment?:string}$field_desc Tableau associatif de description du champ a inserer[nom du parameter][valeur du parameter]
string$field_positionOptionnel ex.: "after champtruc"
Returns
int Return integer <0 if KO, >0 if OK

Implements Database.

Definition at line 542 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 147 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<string,array{type:string,label:string,enabled:int<0,2>|string,position:int,notnull?:int,visible:int,noteditable?:int,default?:string,index?:int,foreignkey?:string,searchall?:int,isameasure?:int,css?:string,csslist?:string,help?:string,showoncombobox?:int,disabled?:int,arrayofkeyval?:array<int,string>,comment?:string}>$fields Associative table [field name][table of 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 Return integer <0 if KO, >=0 if OK

Implements Database.

Definition at line 507 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_passPassword user a creer
string$dolibarr_main_db_nameDatabase name where user must be granted
Returns
int Return integer <0 if KO, >=0 if OK

Implements Database.

Definition at line 623 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 589 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 Return integer <0 if KO, >0 if OK

Implements Database.

Definition at line 554 of file TraceableDB.php.

◆ DDLDropTable()

TraceableDB::DDLDropTable ( $table)

Drop a table into database.

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

Implements Database.

Definition at line 518 of file TraceableDB.php.

◆ DDLGetConnectId()

TraceableDB::DDLGetConnectId ( )

Return connection ID.

Returns
string Id connection

Implements Database.

Definition at line 716 of file TraceableDB.php.

◆ DDLInfoTable()

TraceableDB::DDLInfoTable ( $table)

List information of columns into a table.

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

Implements Database.

Definition at line 674 of file TraceableDB.php.

◆ DDLListTables()

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

◆ DDLListTablesFull()

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

List tables into a database with table info.

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

Implements Database.

Definition at line 217 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
array{type:string,label:string,enabled:int|string,position:int,notnull?:int,visible:int,noteditable?:int,default?:string,index?:int,foreignkey?:string,searchall?:int,isameasure?:int,css?:string,csslist?:string,help?:string,showoncombobox?:int,disabled?:int,arrayofkeyval?:array<int,string>,comment?:string}$field_desc Array with description of field format
Returns
int Return integer <0 if KO, >0 if OK

Implements Database.

Definition at line 567 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 250 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 652 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 374 of file TraceableDB.php.

Referenced by query().

◆ errno()

TraceableDB::errno ( )

Return generic error code of last operation.

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

Implements Database.

Definition at line 490 of file TraceableDB.php.

◆ error()

TraceableDB::error ( )

Return description of last error.

Returns
string Error text

Implements Database.

Definition at line 193 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 284 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 295 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 262 of file TraceableDB.php.

◆ fetch_object()

TraceableDB::fetch_object ( $resultset)

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

Parameters
resource | PgSql\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 728 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 96 of file TraceableDB.php.

◆ free()

TraceableDB::free ( $resultset = null)

Free last resultset used.

Parameters
resource$resultsetFre cursor
Returns
void

Implements Database.

Definition at line 685 of file TraceableDB.php.

◆ getDefaultCharacterSetDatabase()

TraceableDB::getDefaultCharacterSetDatabase ( )

Return charset used to store data in database.

Returns
string Charset

Implements Database.

Definition at line 609 of file TraceableDB.php.

◆ getDefaultCollationDatabase()

TraceableDB::getDefaultCollationDatabase ( )

Return collation used in database.

Returns
string Collation value

Implements Database.

Definition at line 446 of file TraceableDB.php.

◆ getDriverInfo()

TraceableDB::getDriverInfo ( )

Return version of database client driver.

Returns
string Version string

Implements Database.

Definition at line 480 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 528 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 577 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 470 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 319 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 425 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 436 of file TraceableDB.php.

◆ getVersion()

TraceableDB::getVersion ( )

Return version of database server.

Returns
string Version string

Implements Database.

Definition at line 599 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 157 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 information 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 110 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 equal
string$reskoresultat si test non equal
Returns
string SQL string

Reimplemented from DoliDB.

Definition at line 84 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 information are GMT values, otherwise local to server TZ
Returns
int|'' Date TMS or ''

Reimplemented from DoliDB.

Definition at line 638 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 308 of file TraceableDB.php.

◆ lasterrno()

TraceableDB::lasterrno ( )

Return last error code.

Returns
string lasterrno

Reimplemented from DoliDB.

Definition at line 120 of file TraceableDB.php.

◆ lasterror()

TraceableDB::lasterror ( )

Return last error label.

Returns
string lasterror

Reimplemented from DoliDB.

Definition at line 273 of file TraceableDB.php.

◆ lastquery()

TraceableDB::lastquery ( )

Return last request executed with query()

Returns
string Last query

Reimplemented from DoliDB.

Definition at line 227 of file TraceableDB.php.

◆ lastqueryerror()

TraceableDB::lastqueryerror ( )

Return last query in error.

Returns
string lastqueryerror

Reimplemented from DoliDB.

Definition at line 706 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 459 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 239 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 414 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 345 of file TraceableDB.php.

References endTracing(), and 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 cancellation is ok or transaction not open, 0 if error

Reimplemented from DoliDB.

Definition at line 330 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 741 of file TraceableDB.php.

◆ startTracing()

TraceableDB::startTracing ( )
protected

Start query tracing.

Returns
void

Definition at line 361 of file TraceableDB.php.

Referenced by query().


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