dolibarr  13.0.2
TraceableDB.php
1 <?php
2 
3 require_once DOL_DOCUMENT_ROOT.'/core/db/DoliDB.class.php';
4 
10 class TraceableDB extends DoliDB
11 {
15  public $db; // cannot be protected because of parent declaration
19  public $queries;
23  protected $startTime;
27  protected $startMemory;
31  public $type;
35  const LABEL = ''; // TODO: the right value should be $this->db::LABEL (but this is a constant? o_O)
39  const VERSIONMIN = ''; // TODO: the same thing here, $this->db::VERSIONMIN is the right value
40 
46  public function __construct($db)
47  {
48  $this->db = $db;
49  $this->type = $this->db->type;
50  $this->queries = array();
51  }
52 
61  public function ifsql($test, $resok, $resko)
62  {
63  return $this->db->ifsql($test, $resok, $resko);
64  }
65 
66  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
73  public function fetch_row($resultset)
74  {
75  // phpcs:enable
76  return $this->db->fetch_row($resultset);
77  }
78 
87  public function idate($param, $gm = 'tzserver')
88  {
89  return $this->db->idate($param, $gm);
90  }
91 
97  public function lasterrno()
98  {
99  return $this->db->lasterrno();
100  }
101 
107  public function begin()
108  {
109  return $this->db->begin();
110  }
111 
123  public function DDLCreateDb($database, $charset = '', $collation = '', $owner = '')
124  {
125  return $this->db->DDLCreateDb($database, $charset, $collation, $owner);
126  }
127 
133  public function getVersionArray()
134  {
135  return $this->db->getVersionArray();
136  }
137 
145  public static function convertSQLFromMysql($line, $type = 'ddl')
146  {
147  return self::$db->convertSQLFromMysql($line);
148  }
149 
150  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
158  public function affected_rows($resultset)
159  {
160  // phpcs:enable
161  return $this->db->affected_rows($resultset);
162  }
163 
169  public function error()
170  {
171  return $this->db->error();
172  }
173 
181  public function DDLListTables($database, $table = '')
182  {
183  return $this->db->DDLListTables($database, $table);
184  }
185 
191  public function lastquery()
192  {
193  return $this->db->lastquery();
194  }
195 
203  public function order($sortfield = null, $sortorder = null)
204  {
205  return $this->db->order($sortfield, $sortorder);
206  }
207 
214  public function decrypt($value)
215  {
216  return $this->db->decrypt($value);
217  }
218 
219  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
226  public function fetch_array($resultset)
227  {
228  // phpcs:enable
229  return $this->db->fetch_array($resultset);
230  }
231 
237  public function lasterror()
238  {
239  return $this->db->lasterror();
240  }
241 
248  public function escape($stringtoencode)
249  {
250  return $this->db->escape($stringtoencode);
251  }
252 
253  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
261  public function last_insert_id($tab, $fieldid = 'rowid')
262  {
263  // phpcs:enable
264  return $this->db->last_insert_id($tab, $fieldid);
265  }
266 
272  public function getPathOfRestore()
273  {
274  return $this->db->getPathOfRestore();
275  }
276 
283  public function rollback($log = '')
284  {
285  return $this->db->rollback($log);
286  }
287 
297  public function query($query, $usesavepoint = 0, $type = 'auto')
298  {
299  $this->startTracing();
300 
301  $resql = $this->db->query($query, $usesavepoint, $type);
302 
303  $this->endTracing($query, $resql);
304 
305  return $resql;
306  }
307 
313  protected function startTracing()
314  {
315  $this->startTime = microtime(true);
316  $this->startMemory = memory_get_usage(true);
317  }
318 
326  protected function endTracing($sql, $resql)
327  {
328  $endTime = microtime(true);
329  $duration = $endTime - $this->startTime;
330  $endMemory = memory_get_usage(true);
331  $memoryDelta = $endMemory - $this->startMemory;
332 
333  $this->queries[] = array(
334  'sql' => $sql,
335  'duration' => $duration,
336  'memory_usage' => $memoryDelta,
337  'is_success' => $resql ? true : false,
338  'error_code' => $resql ? null : $this->db->lasterrno(),
339  'error_message' => $resql ? null : $this->db->lasterror()
340  );
341  }
342 
354  public function connect($host, $login, $passwd, $name, $port = 0)
355  {
356  return $this->db->connect($host, $login, $passwd, $name, $port);
357  }
358 
366  public function plimit($limit = 0, $offset = 0)
367  {
368  return $this->db->plimit($limit, $offset);
369  }
370 
377  public function getServerParametersValues($filter = '')
378  {
379  return $this->db->getServerParametersValues($filter);
380  }
381 
388  public function getServerStatusValues($filter = '')
389  {
390  return $this->db->getServerStatusValues($filter);
391  }
392 
398  public function getDefaultCollationDatabase()
399  {
400  return $this->db->getDefaultCollationDatabase();
401  }
402 
403  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
411  public function num_rows($resultset)
412  {
413  // phpcs:enable
414  return $this->db->num_rows($resultset);
415  }
416 
422  public function getPathOfDump()
423  {
424  return $this->db->getPathOfDump();
425  }
426 
432  public function getDriverInfo()
433  {
434  return $this->db->getDriverInfo();
435  }
436 
442  public function errno()
443  {
444  return $this->db->errno();
445  }
446 
459  public function DDLCreateTable($table, $fields, $primary_key, $type, $unique_keys = null, $fulltext_keys = null, $keys = null)
460  {
461  return $this->db->DDLCreateTable($table, $fields, $primary_key, $type, $unique_keys, $fulltext_keys, $keys);
462  }
463 
470  public function DDLDropTable($table)
471  {
472  return $this->db->DDLDropTable($table);
473  }
474 
480  public function getListOfCharacterSet()
481  {
482  return $this->db->getListOfCharacterSet();
483  }
484 
494  public function DDLAddField($table, $field_name, $field_desc, $field_position = "")
495  {
496  return $this->db->DDLAddField($table, $field_name, $field_desc, $field_position);
497  }
498 
506  public function DDLDropField($table, $field_name)
507  {
508  return $this->db->DDLDropField($table, $field_name);
509  }
510 
519  public function DDLUpdateField($table, $field_name, $field_desc)
520  {
521  return $this->db->DDLUpdateField($table, $field_name, $field_desc);
522  }
523 
529  public function getListOfCollation()
530  {
531  return $this->db->getListOfCollation();
532  }
533 
541  public function DDLDescTable($table, $field = "")
542  {
543  return $this->db->DDLDescTable($table, $field);
544  }
545 
551  public function getVersion()
552  {
553  return $this->db->getVersion();
554  }
555 
562  {
563  return $this->db->getDefaultCharacterSetDatabase();
564  }
565 
575  public function DDLCreateUser($dolibarr_main_db_host, $dolibarr_main_db_user, $dolibarr_main_db_pass, $dolibarr_main_db_name)
576  {
577  return $this->db->DDLCreateUser($dolibarr_main_db_host, $dolibarr_main_db_user, $dolibarr_main_db_pass, $dolibarr_main_db_name);
578  }
579 
580  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
590  public function jdate($string, $gm = false)
591  {
592  // phpcs:enable
593  return $this->db->jdate($string, $gm);
594  }
595 
604  public function encrypt($fieldorvalue, $withQuotes = 0)
605  {
606  return $this->db->encrypt($fieldorvalue, $withQuotes);
607  }
608 
615  public function commit($log = '')
616  {
617  return $this->db->commit($log);
618  }
619 
626  public function DDLInfoTable($table)
627  {
628  return $this->db->DDLInfoTable($table);
629  }
630 
637  public function free($resultset = null)
638  {
639  return $this->db->free($resultset);
640  }
641 
648  public function close()
649  {
650  return $this->db->close();
651  }
652 
658  public function lastqueryerror()
659  {
660  return $this->db->lastqueryerror();
661  }
662 
668  public function DDLGetConnectId()
669  {
670  return $this->db->DDLGetConnectId();
671  }
672 
673  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
680  public function fetch_object($resultset)
681  {
682  // phpcs:enable
683  return $this->db->fetch_object($resultset);
684  }
685 
686  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
693  public function select_db($database)
694  {
695  // phpcs:enable
696  return $this->db->select_db($database);
697  }
698 }
lastquery()
Return last request executed with query()
fetch_row($resultset)
Return datas as an array.
Definition: TraceableDB.php:73
DDLUpdateField($table, $field_name, $field_desc)
Update format of a field into a table.
endTracing($sql, $resql)
End query tracing.
DDLListTables($database, $table= '')
List tables into a database.
getVersion()
Return version of database server.
DDLInfoTable($table)
List information of columns into a table.
rollback($log= '')
Cancel a transaction and go back to initial data values.
error()
Return description of last error.
fetch_object($resultset)
Renvoie la ligne courante (comme un objet) pour le curseur resultset.
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) ...
__construct($db)
Constructor.
Definition: TraceableDB.php:46
TraceableDB class.
Definition: TraceableDB.php:10
getDefaultCharacterSetDatabase()
Return charset used to store data in database.
fetch_array($resultset)
Return datas as an array.
Class to manage Dolibarr database access.
getDriverInfo()
Return version of database client driver.
const LABEL
Database label
Definition: TraceableDB.php:35
idate($param, $gm= 'tzserver')
Convert (by PHP) a GM Timestamp date into a string date with PHP server TZ to insert into a date fiel...
Definition: TraceableDB.php:87
free($resultset=null)
Free last resultset used.
last_insert_id($tab, $fieldid= 'rowid')
Get last ID after an insert INSERT.
getServerParametersValues($filter= '')
Return value of server parameters.
DDLCreateDb($database, $charset= '', $collation= '', $owner= '')
Create a new database Do not use function xxx_create_db (xxx=mysql, ...) as they are deprecated We fo...
$conf db
API class for accounts.
Definition: inc.php:54
static convertSQLFromMysql($line, $type= 'ddl')
Convert a SQL request in Mysql syntax to native syntax.
getDefaultCollationDatabase()
Return collation used in database.
DDLCreateTable($table, $fields, $primary_key, $type, $unique_keys=null, $fulltext_keys=null, $keys=null)
Create a table into database.
getPathOfRestore()
Return full path of restore program.
query($query, $usesavepoint=0, $type= 'auto')
Execute a SQL request and return the resultset.
num_rows($resultset)
Return number of lines for result of a SELECT.
getServerStatusValues($filter= '')
Return value of server status.
lastqueryerror()
Return last query in error.
escape($stringtoencode)
Escape a string to insert data.
getListOfCharacterSet()
Return list of available charset that can be used to store data in database.
getVersionArray()
Return version of database server into an array.
errno()
Return generic error code of last operation.
lasterrno()
Return last error code.
Definition: TraceableDB.php:97
startTracing()
Start query tracing.
getPathOfDump()
Return full path of dump program.
const VERSIONMIN
Version min database
Definition: TraceableDB.php:39
close()
Close database connexion.
lasterror()
Return last error label.
DDLGetConnectId()
Return connexion ID.
commit($log= '')
Validate a database transaction.
connect($host, $login, $passwd, $name, $port=0)
Connexion to server.
encrypt($fieldorvalue, $withQuotes=0)
Encrypt sensitive data in database Warning: This function includes the escape, so it must use direct ...
if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if((!empty($conf->fournisseur->enabled)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) if(!empty($conf->don->enabled)&&$user->rights->don->lire) if(!empty($conf->tax->enabled)&&$user->rights->tax->charges->lire) if(!empty($conf->facture->enabled)&&!empty($conf->commande->enabled)&&$user->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if((!empty($conf->fournisseur->enabled)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) $resql
Social contributions to pay.
Definition: index.php:1232
select_db($database)
Select a database.
plimit($limit=0, $offset=0)
Define limits and offset of request.
decrypt($value)
Decrypt sensitive data in database.
DDLDropTable($table)
Drop a table into database.
getListOfCollation()
Return list of available collation that can be used for database.
DDLDropField($table, $field_name)
Drop a field from table.
jdate($string, $gm=false)
Convert (by PHP) a PHP server TZ string date into a Timestamps date (GMT if gm=true) 19700101020000 -...
DDLAddField($table, $field_name, $field_desc, $field_position="")
Create a new field into table.
affected_rows($resultset)
Return the number o flines into the result of a request INSERT, DELETE or UPDATE. ...
begin()
Start transaction.
if(preg_match('/crypted:/i', $dolibarr_main_db_pass)||!empty($dolibarr_main_db_encrypted_pass)) $conf db type
Definition: repair.php:105
order($sortfield=null, $sortorder=null)
Define sort criteria of request.
ifsql($test, $resok, $resko)
Format a SQL IF.
Definition: TraceableDB.php:61
DDLDescTable($table, $field="")
Return a pointer of line with description of a table or field.