dolibarr 18.0.6
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.
 
 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)
 Connexion 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 connexion.
 
 lastqueryerror ()
 Return last query in error.
 
 DDLGetConnectId ()
 Return connexion 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=...).
 
 hintindex ($nameofindex)
 Return SQL string to force an index.
 
 regexpsql ($subject, $pattern, $sqlstring=false)
 Format a SQL REGEXP.
 
 sanitize ($stringtosanitize, $allowsimplequote=0, $allowsequals=0)
 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 Note : This method executes a given SQL query and retrieves all row of results 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.
 

Static Public Member Functions

static convertSQLFromMysql ($line, $type='ddl')
 Convert a SQL request in Mysql syntax to native syntax.
 

Public Attributes

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

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 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()

static TraceableDB::convertSQLFromMysql ( $line,
$type = 'ddl' )
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...)
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.

Referenced by query().

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