|
dolibarr 25.0.0-alpha
|
TraceableDB class. More...


Public Member Functions | |
| __construct ($db) | |
| Constructor. | |
| ifsql ($test, $resok, $resko) | |
| Format a SQL IF. | |
| regexpsql ($subject, $pattern, $sqlstring=0) | |
| format a sql regexp | |
| 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 of lines 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, $forcenew=false) | |
| 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 whatever 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, $mode=1) | |
| Return SQL string to force an index. | |
| 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. | |
| getNextAutoIncrementId ($table) | |
| Get the last ID of an auto-increment field of a table. | |
| prepare ($sql) | |
| Prepare a SQL statement for execution. | |
| execute ($stmt, $params=array()) | |
| Execute a statement previously created with prepare(). | |
Public Member Functions inherited from Database | |
| 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. | |
| isFullTracingEnabled () | |
| Check if full query tracing is enabled. | |
| endTracing ($sql, $resql) | |
| End query tracing. | |
| TraceableDB::__construct | ( | $db | ) |
| TraceableDB::affected_rows | ( | $resultset | ) |
Return the number of lines into the result of a request INSERT, DELETE or UPDATE.
| resource | $resultset | Curseur de la requete voulue |
Implements Database.
Definition at line 195 of file TraceableDB.php.
| TraceableDB::begin | ( | $textinlog = '' | ) |
Start transaction.
| string | $textinlog | Add a small text into log. '' by default. |
Reimplemented from DoliDB.
Definition at line 144 of file TraceableDB.php.
| TraceableDB::close | ( | ) |
Close database connection.
Implements Database.
Definition at line 733 of file TraceableDB.php.
| TraceableDB::commit | ( | $log = '' | ) |
Validate a database transaction.
| string | $log | Add more log to default log line |
Reimplemented from DoliDB.
Definition at line 700 of file TraceableDB.php.
| TraceableDB::connect | ( | $host, | |
| $login, | |||
| $passwd, | |||
| $name, | |||
| $port = 0, | |||
| $forcenew = false ) |
Connection to server.
| string | $host | database server host |
| string | $login | login |
| string | $passwd | password |
| string | $name | name of database (not used for mysql, used for pgsql) |
| int | $port | Port of database server |
| bool | $forcenew | Force opening of a genuinely new connection instead of reusing one already opened to the same server/database in this process (relevant for pgsql only) |
Implements Database.
Definition at line 439 of file TraceableDB.php.
| TraceableDB::convertSQLFromMysql | ( | $line, | |
| $type = 'ddl' ) |
Convert a SQL request in Mysql syntax to native syntax.
| string | $line | SQL request line to convert |
| string | $type | Type of SQL order ('ddl' for insert, update, select, delete or 'dml' for create, alter...) |
Implements Database.
Definition at line 182 of file TraceableDB.php.
| TraceableDB::DDLAddField | ( | $table, | |
| $field_name, | |||
| $field_desc, | |||
| $field_position = "" ) |
Create a new field into table.
| string | $table | Name of table |
| string | $field_name | Name of field to add |
| array{type:string,label?:string,enabled?:int<0,2>|string,position?:int,notnull?:int,visible?:int,noteditable?:int,default?:string,extra?:string,null?: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 Associative array of description of the field to insert [parameter name][parameter value] | |
| string | $field_position | Optionnel ex.: "after champtruc" |
Implements Database.
Definition at line 579 of file TraceableDB.php.
| 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.
| string | $database | Database name to create |
| string | $charset | Charset used to store data |
| string | $collation | Charset used to sort data |
| string | $owner | Username of database owner |
Implements Database.
Definition at line 160 of file TraceableDB.php.
| TraceableDB::DDLCreateTable | ( | $table, | |
| $fields, | |||
| $primary_key, | |||
| $type, | |||
| $unique_keys = null, | |||
| $fulltext_keys = null, | |||
| $keys = null ) |
Create a table into database.
| string | $table | Name of table |
| array<string,array{type:string,label?:string,enabled?:int<0,2>|string,position?:int,notnull?:int,visible?:int<-2,5>|string,alwayseditable?:int<0,1>,noteditable?:int<0,1>,default?:string,index?:int,foreignkey?:string,searchall?:int<0,1>,isameasure?:int<0,1>,css?:string,csslist?:string,help?:string,showoncombobox?:int<0,2>,disabled?:int<0,1>,arrayofkeyval?:array<int,string>,autofocusoncreate?:int<0,1>,comment?:string,copytoclipboard?:int<1,2>,validate?:int<0,1>}> | $fields Associative table [field name][table of descriptions] | |
| string | $primary_key | Nom du champ qui sera la clef primaire |
| string | $type | Type de la table |
| ?array<string,mixed> | $unique_keys Tableau associatifs Nom de champs qui seront clef unique => valeur | |
| string[] | $fulltext_keys | Tableau des Nom de champs qui seront indexes en fulltext |
| string[] | $keys | Tableau des champs cles noms => valeur |
Implements Database.
Definition at line 544 of file TraceableDB.php.
| 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)
| string | $dolibarr_main_db_host | Ip serveur |
| string | $dolibarr_main_db_user | Name of user to create |
| string | $dolibarr_main_db_pass | Password of user to create |
| string | $dolibarr_main_db_name | Database name where user must be granted |
Implements Database.
Definition at line 660 of file TraceableDB.php.
| TraceableDB::DDLDescTable | ( | $table, | |
| $field = "" ) |
Return a pointer of line with description of a table or field.
| string | $table | Name of table |
| string | $field | Optionnel : Name of field if we want description of field |
Implements Database.
Definition at line 626 of file TraceableDB.php.
| TraceableDB::DDLDropField | ( | $table, | |
| $field_name ) |
Drop a field from table.
| string | $table | Name of table |
| string | $field_name | Name of field to drop |
Implements Database.
Definition at line 591 of file TraceableDB.php.
| TraceableDB::DDLDropTable | ( | $table | ) |
Drop a table into database.
| string | $table | Name of table |
Implements Database.
Definition at line 555 of file TraceableDB.php.
| TraceableDB::DDLGetConnectId | ( | ) |
Return connection ID.
Implements Database.
Definition at line 753 of file TraceableDB.php.
| TraceableDB::DDLInfoTable | ( | $table | ) |
List information of columns into a table.
| string | $table | Name of table |
Implements Database.
Definition at line 711 of file TraceableDB.php.
| TraceableDB::DDLListTables | ( | $database, | |
| $table = '' ) |
List tables into a database.
| string | $database | Name of database |
| string | $table | Name of table filter ('xxx') |
Implements Database.
Definition at line 218 of file TraceableDB.php.
| TraceableDB::DDLListTablesFull | ( | $database, | |
| $table = '' ) |
List tables into a database with table info.
| string | $database | Name of database |
| string | $table | Name of table filter ('xxx') |
Implements Database.
Definition at line 230 of file TraceableDB.php.
| TraceableDB::DDLUpdateField | ( | $table, | |
| $field_name, | |||
| $field_desc ) |
Update format of a field into a table.
| string | $table | Name of table |
| string | $field_name | Name of field to modify |
| 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,value?:string,null?:string} | $field_desc Array with description of field format |
Implements Database.
Definition at line 604 of file TraceableDB.php.
| TraceableDB::decrypt | ( | $value | ) |
Decrypt sensitive data in database.
| string | $value | Value to decrypt |
Implements Database.
Definition at line 263 of file TraceableDB.php.
| TraceableDB::encrypt | ( | $fieldorvalue, | |
| $withQuotes = 1 ) |
Encrypt sensitive data in database Warning: This function includes the escape and add the SQL simple quotes on strings.
| string | $fieldorvalue | Field name or value to encrypt |
| int | $withQuotes | Return string including the SQL simple quotes. This param must always be 1 (Value 0 is bugged and deprecated). |
Implements Database.
Definition at line 689 of file TraceableDB.php.
|
protected |
End query tracing.
| string | $sql | query string |
| mysqli_result | bool | resource | $resql | query result |
Definition at line 403 of file TraceableDB.php.
References isFullTracingEnabled().
Referenced by query().
| TraceableDB::errno | ( | ) |
Return generic error code of last operation.
Implements Database.
Definition at line 527 of file TraceableDB.php.
| TraceableDB::error | ( | ) |
Return description of last error.
Implements Database.
Definition at line 206 of file TraceableDB.php.
| TraceableDB::escape | ( | $stringtoencode | ) |
Escape a string to insert data.
| string | $stringtoencode | String to escape |
Implements Database.
Definition at line 297 of file TraceableDB.php.
| TraceableDB::escapeforlike | ( | $stringtoencode | ) |
Escape a string to insert data into a like.
| string | $stringtoencode | String to escape |
Implements Database.
Definition at line 308 of file TraceableDB.php.
| TraceableDB::fetch_array | ( | $resultset | ) |
Return datas as an array.
| resource | $resultset | Resultset of request |
Implements Database.
Definition at line 275 of file TraceableDB.php.
| TraceableDB::fetch_object | ( | $resultset | ) |
Returns the current line (as an object) for the resultset cursor.
| resource | PgSql\Connection | $resultset | Handler of the desired SQL request |
Implements Database.
Definition at line 765 of file TraceableDB.php.
| TraceableDB::fetch_row | ( | $resultset | ) |
Return datas as an array.
| resource | $resultset | Resultset of request |
Implements Database.
Definition at line 109 of file TraceableDB.php.
| TraceableDB::free | ( | $resultset = null | ) |
Free last resultset used.
| resource | $resultset | Fre cursor |
Implements Database.
Definition at line 722 of file TraceableDB.php.
| TraceableDB::getDefaultCharacterSetDatabase | ( | ) |
Return charset used to store data in database.
Implements Database.
Definition at line 646 of file TraceableDB.php.
| TraceableDB::getDefaultCollationDatabase | ( | ) |
Return collation used in database.
Implements Database.
Definition at line 483 of file TraceableDB.php.
| TraceableDB::getDriverInfo | ( | ) |
Return version of database client driver.
Implements Database.
Definition at line 517 of file TraceableDB.php.
| TraceableDB::getListOfCharacterSet | ( | ) |
Return list of available charset that can be used to store data in database.
Implements Database.
Definition at line 565 of file TraceableDB.php.
| TraceableDB::getListOfCollation | ( | ) |
Return list of available collation that can be used for database.
Implements Database.
Definition at line 614 of file TraceableDB.php.
| TraceableDB::getPathOfDump | ( | ) |
Return full path of dump program.
Implements Database.
Definition at line 507 of file TraceableDB.php.
| TraceableDB::getPathOfRestore | ( | ) |
Return full path of restore program.
Implements Database.
Definition at line 332 of file TraceableDB.php.
| TraceableDB::getServerParametersValues | ( | $filter = '' | ) |
Return value of server parameters.
| string | $filter | Filter list on a particular value |
Implements Database.
Definition at line 462 of file TraceableDB.php.
| TraceableDB::getServerStatusValues | ( | $filter = '' | ) |
Return value of server status.
| string | $filter | Filter list on a particular value |
Implements Database.
Definition at line 473 of file TraceableDB.php.
| TraceableDB::getVersion | ( | ) |
Return version of database server.
Implements Database.
Definition at line 636 of file TraceableDB.php.
| TraceableDB::getVersionArray | ( | ) |
Return version of database server into an array.
Reimplemented from DoliDB.
Definition at line 170 of file TraceableDB.php.
| 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
| int|'' | $param Date TMS to convert |
| 'gmt'|'tzserver' | $gm 'gmt'=Input information are GMT values, 'tzserver'=Local to server TZ |
Reimplemented from DoliDB.
Definition at line 123 of file TraceableDB.php.
| TraceableDB::ifsql | ( | $test, | |
| $resok, | |||
| $resko ) |
Format a SQL IF.
| string | $test | Test string (example: 'cd.statut=0', 'field IS NULL') |
| string | $resok | result if test equal |
| string | $resko | result if test non equal |
Reimplemented from DoliDB.
Definition at line 84 of file TraceableDB.php.
|
protected |
Check if full query tracing is enabled.
Full tracing captures backtrace for ALL queries, not just failed ones. This is useful for debugging but has performance impact.
Definition at line 388 of file TraceableDB.php.
Referenced by endTracing().
| 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 whatever is TZ if gmt=1.
| ?string | $string | Date in a string (YYYYMMDDHHMMSS, YYYYMMDD, YYYY-MM-DD HH:MM:SS) |
| bool | int | string | $gm | 1=Input information are GMT values, otherwise local to server TZ |
Reimplemented from DoliDB.
Definition at line 675 of file TraceableDB.php.
| TraceableDB::last_insert_id | ( | $tab, | |
| $fieldid = 'rowid' ) |
Get last ID after an insert INSERT.
| string | $tab | Table name concerned by insert. Needed for Postgresql compatibility (not useful for MySql) |
| string | $fieldid | Field name |
Implements Database.
Definition at line 321 of file TraceableDB.php.
| TraceableDB::lasterrno | ( | ) |
Return last error code.
Reimplemented from DoliDB.
Definition at line 133 of file TraceableDB.php.
| TraceableDB::lasterror | ( | ) |
Return last error label.
Reimplemented from DoliDB.
Definition at line 286 of file TraceableDB.php.
| TraceableDB::lastquery | ( | ) |
Return last request executed with query()
Reimplemented from DoliDB.
Definition at line 240 of file TraceableDB.php.
| TraceableDB::lastqueryerror | ( | ) |
Return last query in error.
Reimplemented from DoliDB.
Definition at line 743 of file TraceableDB.php.
| TraceableDB::num_rows | ( | $resultset | ) |
Return number of lines for result of a SELECT.
| resource | $resultset | Resulset of requests |
Implements Database.
Definition at line 496 of file TraceableDB.php.
| TraceableDB::order | ( | $sortfield = null, | |
| $sortorder = null ) |
Define sort criteria of request.
| string | $sortfield | List of sort fields |
| string | $sortorder | Sort order |
Reimplemented from DoliDB.
Definition at line 252 of file TraceableDB.php.
| TraceableDB::plimit | ( | $limit = 0, | |
| $offset = 0 ) |
Define limits and offset of request.
| int | $limit | Maximum number of lines returned (-1=conf->liste_limit, 0=no limit) |
| int | $offset | Numero of line from where starting fetch |
Reimplemented from DoliDB.
Definition at line 451 of file TraceableDB.php.
| TraceableDB::query | ( | $query, | |
| $usesavepoint = 0, | |||
| $type = 'auto', | |||
| $result_mode = 0 ) |
Execute a SQL request and return the resultset.
| string | $query | SQL query string |
| int | $usesavepoint | 0=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 | $type | Type of SQL order ('ddl' for insert, update, select, delete or 'dml' for create, alter...) |
| int | $result_mode | Result mode |
Implements Database.
Definition at line 358 of file TraceableDB.php.
References endTracing(), and startTracing().
| TraceableDB::regexpsql | ( | $subject, | |
| $pattern, | |||
| $sqlstring = 0 ) |
format a sql regexp
| string | $subject | field name to test |
| string | $pattern | sql pattern to match |
| int | $sqlstring | 0=the string being tested is a hard coded string, 1=the string is a field |
Reimplemented from DoliDB.
Definition at line 97 of file TraceableDB.php.
| TraceableDB::rollback | ( | $log = '' | ) |
Cancel a transaction and go back to initial data values.
| string | $log | Add more log to default log line |
Reimplemented from DoliDB.
Definition at line 343 of file TraceableDB.php.
| TraceableDB::select_db | ( | $database | ) |
Select a database.
| string | $database | Name of database |
Implements Database.
Definition at line 778 of file TraceableDB.php.
|
protected |
Start query tracing.
Definition at line 374 of file TraceableDB.php.
Referenced by query().