Passed
Push — MODEL_LIB_240928 ( d6fbb6...55f3e4 )
by Rafael
49:14
created

TraceableDB::lastqueryerror()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
/* Copyright (C) 2023       Laurent Destailleur         <[email protected]>
4
 * Copyright (C) 2024		MDW							<[email protected]>
5
 * Copyright (C) 2024       Frédéric France             <[email protected]>
6
 * Copyright (C) 2024       Rafael San José             <[email protected]>
7
 *
8
 * This program is free software; you can redistribute it and/or modify
9
 * it under the terms of the GNU General Public License as published by
10
 * the Free Software Foundation; either version 3 of the License, or
11
 * (at your option) any later version.
12
 *
13
 * This program is distributed in the hope that it will be useful,
14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
 * GNU General Public License for more details.
17
 *
18
 * You should have received a copy of the GNU General Public License
19
 * along with this program. If not, see <https://www.gnu.org/licenses/>.
20
 */
21
22
namespace Dolibarr\Tools;
23
24
use DoliDB;
25
26
/**
27
 *  \file       htdocs/debugbar/class/DataCollector/TraceableDB.php
28
 *  \brief      Class for debugbar DB
29
 *  \ingroup    debugbar
30
 */
31
32
/**
33
 * TraceableDB class
34
 *
35
 * Used to log queries into DebugBar
36
 */
37
class TraceableDB extends DoliDB
38
{
39
    /**
40
     * @var DoliDB Database handler
41
     */
42
    public $db; // cannot be protected because of parent declaration
43
    /**
44
     * @var array Queries array
45
     */
46
    public $queries;
47
    /**
48
     * @var float   Request start time in second + microseconds as decimal part (Example: 1712305485.1104)
49
     */
50
    protected $startTime;
51
    /**
52
     * @var int     Request start memory
53
     */
54
    protected $startMemory;
55
    /**
56
     * @var string type
57
     */
58
    public $type;
59
    /**
60
     * @const Database label
61
     */
62
    const LABEL = ''; // TODO: the right value should be $this->db::LABEL (but this is a constant? o_O)
63
    /**
64
     * @const Version min database
65
     */
66
    const VERSIONMIN = ''; // TODO: the same thing here, $this->db::VERSIONMIN is the right value
67
68
    /**
69
     * Constructor
70
     *
71
     * @param DoliDB $db Database handler
72
     */
73
    public function __construct($db)
74
    {
75
        $this->db = $db;
76
        $this->type = $this->db->type;
77
        $this->queries = array();
78
    }
79
80
    /**
81
     * Format a SQL IF
82
     *
83
     * @param string $test Test string (example: 'cd.statut=0', 'field IS NULL')
84
     * @param string $resok resultat si test equal
85
     * @param string $resko resultat si test non equal
86
     * @return  string                SQL string
87
     */
88
    public function ifsql($test, $resok, $resko)
89
    {
90
        return $this->db->ifsql($test, $resok, $resko);
91
    }
92
93
    // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
94
95
    /**
96
     * Return datas as an array
97
     *
98
     * @param resource $resultset Resultset of request
99
     * @return  array                  Array
100
     */
101
    public function fetch_row($resultset)
102
    {
103
        // phpcs:enable
104
        return $this->db->fetch_row($resultset);
105
    }
106
107
    /**
108
     * Convert (by PHP) a GM Timestamp date into a string date with PHP server TZ to insert into a date field.
109
     * Function to use to build INSERT, UPDATE or WHERE predica
110
     *
111
     * @param int $param Date TMS to convert
112
     * @param mixed $gm 'gmt'=Input information are GMT values, 'tzserver'=Local to server TZ
113
     * @return    string              Date in a string YYYY-MM-DD HH:MM:SS
114
     */
115
    public function idate($param, $gm = 'tzserver')
116
    {
117
        return $this->db->idate($param, $gm);
118
    }
119
120
    /**
121
     * Return last error code
122
     *
123
     * @return  string    lasterrno
124
     */
125
    public function lasterrno()
126
    {
127
        return $this->db->lasterrno();
128
    }
129
130
    /**
131
     * Start transaction
132
     *
133
     * @param string $textinlog Add a small text into log. '' by default.
134
     * @return  int                     1 if transaction successfully opened or already opened, 0 if error
135
     */
136
    public function begin($textinlog = '')
137
    {
138
        return $this->db->begin($textinlog);
139
    }
140
141
    /**
142
     * Create a new database
143
     * Do not use function xxx_create_db (xxx=mysql, ...) as they are deprecated
144
     * We force to create database with charset this->forcecharset and collate this->forcecollate
145
     *
146
     * @param string $database Database name to create
147
     * @param string $charset Charset used to store data
148
     * @param string $collation Charset used to sort data
149
     * @param string $owner Username of database owner
150
     * @return  resource                    resource defined if OK, null if KO
151
     */
152
    public function DDLCreateDb($database, $charset = '', $collation = '', $owner = '')
153
    {
154
        return $this->db->DDLCreateDb($database, $charset, $collation, $owner);
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->db->DDLCre...et, $collation, $owner) also could return the type SQLite3Result|boolean|mysqli_result which is incompatible with the documented return type resource.
Loading history...
155
    }
156
157
    /**
158
     * Return version of database server into an array
159
     *
160
     * @return  array        Version array
161
     */
162
    public function getVersionArray()
163
    {
164
        return $this->db->getVersionArray();
165
    }
166
167
    /**
168
     *  Convert a SQL request in Mysql syntax to native syntax
169
     *
170
     * @param string $line SQL request line to convert
171
     * @param string $type Type of SQL order ('ddl' for insert, update, select, delete or 'dml' for create, alter...)
172
     * @return  string         SQL request line converted
173
     */
174
    public function convertSQLFromMysql($line, $type = 'ddl')
175
    {
176
        return $this->db->convertSQLFromMysql($line);
177
    }
178
179
    // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
180
181
    /**
182
     * Return the number o flines into the result of a request INSERT, DELETE or UPDATE
183
     *
184
     * @param resource $resultset Curseur de la requete voulue
185
     * @return  int                    Number of lines
186
     * @see     num_rows()
187
     */
188
    public function affected_rows($resultset)
189
    {
190
        // phpcs:enable
191
        return $this->db->affected_rows($resultset);
192
    }
193
194
    /**
195
     * Return description of last error
196
     *
197
     * @return  string        Error text
198
     */
199
    public function error()
200
    {
201
        return $this->db->error();
202
    }
203
204
    /**
205
     *  List tables into a database
206
     *
207
     * @param string $database Name of database
208
     * @param string $table Name of table filter ('xxx%')
209
     * @return array                   List of tables in an array
210
     */
211
    public function DDLListTables($database, $table = '')
212
    {
213
        return $this->db->DDLListTables($database, $table);
214
    }
215
216
    /**
217
     *  List tables into a database with table info
218
     *
219
     * @param string $database Name of database
220
     * @param string $table Name of table filter ('xxx%')
221
     * @return array                   List of tables in an array
222
     */
223
    public function DDLListTablesFull($database, $table = '')
224
    {
225
        return $this->db->DDLListTablesFull($database, $table);
226
    }
227
228
    /**
229
     * Return last request executed with query()
230
     *
231
     * @return  string                    Last query
232
     */
233
    public function lastquery()
234
    {
235
        return $this->db->lastquery();
236
    }
237
238
    /**
239
     * Define sort criteria of request
240
     *
241
     * @param string $sortfield List of sort fields
242
     * @param string $sortorder Sort order
243
     * @return  string            String to provide syntax of a sort sql string
244
     */
245
    public function order($sortfield = null, $sortorder = null)
246
    {
247
        return $this->db->order($sortfield, $sortorder);
248
    }
249
250
    /**
251
     * Decrypt sensitive data in database
252
     *
253
     * @param string $value Value to decrypt
254
     * @return   string                    Decrypted value if used
255
     */
256
    public function decrypt($value)
257
    {
258
        return $this->db->decrypt($value);
259
    }
260
261
    // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
262
263
    /**
264
     * Return datas as an array
265
     *
266
     * @param resource $resultset Resultset of request
267
     * @return  array                  Array
268
     */
269
    public function fetch_array($resultset)
270
    {
271
        // phpcs:enable
272
        return $this->db->fetch_array($resultset);
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->db->fetch_array($resultset) could also return false which is incompatible with the documented return type array. Did you maybe forget to handle an error condition?

If the returned type also contains false, it is an indicator that maybe an error condition leading to the specific return statement remains unhandled.

Loading history...
273
    }
274
275
    /**
276
     * Return last error label
277
     *
278
     * @return  string    lasterror
279
     */
280
    public function lasterror()
281
    {
282
        return $this->db->lasterror();
283
    }
284
285
    /**
286
     * Escape a string to insert data
287
     *
288
     * @param string $stringtoencode String to escape
289
     * @return  string                        String escaped
290
     */
291
    public function escape($stringtoencode)
292
    {
293
        return $this->db->escape($stringtoencode);
294
    }
295
296
    /**
297
     *  Escape a string to insert data into a like
298
     *
299
     * @param string $stringtoencode String to escape
300
     * @return string                      String escaped
301
     */
302
    public function escapeforlike($stringtoencode)
303
    {
304
        return $this->db->escapeforlike($stringtoencode);
305
    }
306
307
    // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
308
309
    /**
310
     * Get last ID after an insert INSERT
311
     *
312
     * @param string $tab Table name concerned by insert. Ne sert pas sous MySql mais requis pour compatibilite avec Postgresql
313
     * @param string $fieldid Field name
314
     * @return  int                 Id of row
315
     */
316
    public function last_insert_id($tab, $fieldid = 'rowid')
317
    {
318
        // phpcs:enable
319
        return $this->db->last_insert_id($tab, $fieldid);
320
    }
321
322
    /**
323
     * Return full path of restore program
324
     *
325
     * @return        string        Full path of restore program
326
     */
327
    public function getPathOfRestore()
328
    {
329
        return $this->db->getPathOfRestore();
330
    }
331
332
    /**
333
     *  Cancel a transaction and go back to initial data values
334
     *
335
     * @param string $log Add more log to default log line
336
     * @return resource|int                1 if cancellation is ok or transaction not open, 0 if error
337
     */
338
    public function rollback($log = '')
339
    {
340
        return $this->db->rollback($log);
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->db->rollback($log) also could return the type resource which is incompatible with the return type mandated by Database::rollback() of integer.
Loading history...
341
    }
342
343
    /**
344
     * Execute a SQL request and return the resultset
345
     *
346
     * @param string $query SQL query string
347
     * @param 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).
348
     *                                  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.
349
     * @param string $type Type of SQL order ('ddl' for insert, update, select, delete or 'dml' for create, alter...)
350
     * @param int $result_mode Result mode
351
     * @return  resource                Resultset of answer
352
     */
353
    public function query($query, $usesavepoint = 0, $type = 'auto', $result_mode = 0)
354
    {
355
        $this->startTracing();
356
357
        $resql = $this->db->query($query, $usesavepoint, $type, $result_mode);
358
359
        $this->endTracing($query, $resql);
360
361
        return $resql;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $resql also could return the type boolean|mysqli_result which is incompatible with the documented return type resource.
Loading history...
362
    }
363
364
    /**
365
     * Start query tracing
366
     *
367
     * @return     void
368
     */
369
    protected function startTracing()
370
    {
371
        $this->startTime = microtime(true);
0 ignored issues
show
Documentation Bug introduced by
It seems like microtime(true) can also be of type string. However, the property $startTime is declared as type double. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
372
        $this->startMemory = memory_get_usage(true);
373
    }
374
375
    /**
376
     * End query tracing
377
     *
378
     * @param string $sql query string
379
     * @param string $resql query result
380
     * @return     void
381
     */
382
    protected function endTracing($sql, $resql)
383
    {
384
        $endTime = microtime(true);
385
        $duration = $endTime - $this->startTime;
386
        $endMemory = memory_get_usage(true);
387
        $memoryDelta = $endMemory - $this->startMemory;
388
389
        $this->queries[] = array(
390
            'sql' => $sql,
391
            'duration' => $duration,
392
            'memory_usage' => $memoryDelta,
393
            'is_success' => $resql ? true : false,
394
            'error_code' => $resql ? null : $this->db->lasterrno(),
395
            'error_message' => $resql ? null : $this->db->lasterror()
396
        );
397
    }
398
399
    /**
400
     * Connection to server
401
     *
402
     * @param string $host database server host
403
     * @param string $login login
404
     * @param string $passwd password
405
     * @param string $name name of database (not used for mysql, used for pgsql)
406
     * @param int $port Port of database server
407
     * @return  resource            Database access handler
408
     * @see     close()
409
     */
410
    public function connect($host, $login, $passwd, $name, $port = 0)
411
    {
412
        return $this->db->connect($host, $login, $passwd, $name, $port);
413
    }
414
415
    /**
416
     *    Define limits and offset of request
417
     *
418
     * @param int $limit Maximum number of lines returned (-1=conf->liste_limit, 0=no limit)
419
     * @param int $offset Numero of line from where starting fetch
420
     * @return  string            String with SQL syntax to add a limit and offset
421
     */
422
    public function plimit($limit = 0, $offset = 0)
423
    {
424
        return $this->db->plimit($limit, $offset);
425
    }
426
427
    /**
428
     * Return value of server parameters
429
     *
430
     * @param string $filter Filter list on a particular value
431
     * @return  array               Array of key-values (key=>value)
432
     */
433
    public function getServerParametersValues($filter = '')
434
    {
435
        return $this->db->getServerParametersValues($filter);
436
    }
437
438
    /**
439
     * Return value of server status
440
     *
441
     * @param string $filter Filter list on a particular value
442
     * @return  array               Array of key-values (key=>value)
443
     */
444
    public function getServerStatusValues($filter = '')
445
    {
446
        return $this->db->getServerStatusValues($filter);
447
    }
448
449
    /**
450
     * Return collation used in database
451
     *
452
     * @return  string        Collation value
453
     */
454
    public function getDefaultCollationDatabase()
455
    {
456
        return $this->db->getDefaultCollationDatabase();
457
    }
458
459
    // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
460
461
    /**
462
     * Return number of lines for result of a SELECT
463
     *
464
     * @param resource $resultset Resulset of requests
465
     * @return  int                    Nb of lines
466
     * @see     affected_rows()
467
     */
468
    public function num_rows($resultset)
469
    {
470
        // phpcs:enable
471
        return $this->db->num_rows($resultset);
472
    }
473
474
    /**
475
     * Return full path of dump program
476
     *
477
     * @return        string        Full path of dump program
478
     */
479
    public function getPathOfDump()
480
    {
481
        return $this->db->getPathOfDump();
482
    }
483
484
    /**
485
     * Return version of database client driver
486
     *
487
     * @return            string      Version string
488
     */
489
    public function getDriverInfo()
490
    {
491
        return $this->db->getDriverInfo();
492
    }
493
494
    /**
495
     * Return generic error code of last operation.
496
     *
497
     * @return    string        Error code (Examples: DB_ERROR_TABLE_ALREADY_EXISTS, DB_ERROR_RECORD_ALREADY_EXISTS...)
498
     */
499
    public function errno()
500
    {
501
        return $this->db->errno();
502
    }
503
504
    /**
505
     * Create a table into database
506
     *
507
     * @param string $table Name of table
508
     * @param 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]
0 ignored issues
show
Documentation Bug introduced by
The doc comment array<string,array{type:...ring>,comment?:string}> at position 16 could not be parsed: Expected '}' at position 16, but found 'int'.
Loading history...
509
     * @param string $primary_key Nom du champ qui sera la clef primaire
510
     * @param string $type Type de la table
511
     * @param array $unique_keys Tableau associatifs Nom de champs qui seront clef unique => valeur
512
     * @param array $fulltext_keys Tableau des Nom de champs qui seront indexes en fulltext
513
     * @param array $keys Tableau des champs cles noms => valeur
514
     * @return       int                    Return integer <0 if KO, >=0 if OK
515
     */
516
    public function DDLCreateTable($table, $fields, $primary_key, $type, $unique_keys = null, $fulltext_keys = null, $keys = null)
517
    {
518
        return $this->db->DDLCreateTable($table, $fields, $primary_key, $type, $unique_keys, $fulltext_keys, $keys);
519
    }
520
521
    /**
522
     * Drop a table into database
523
     *
524
     * @param string $table Name of table
525
     * @return       int                    Return integer <0 if KO, >=0 if OK
526
     */
527
    public function DDLDropTable($table)
528
    {
529
        return $this->db->DDLDropTable($table);
530
    }
531
532
    /**
533
     * Return list of available charset that can be used to store data in database
534
     *
535
     * @return        array        List of Charset
536
     */
537
    public function getListOfCharacterSet()
538
    {
539
        return $this->db->getListOfCharacterSet();
540
    }
541
542
    /**
543
     * Create a new field into table
544
     *
545
     * @param string $table Name of table
546
     * @param string $field_name Name of field to add
547
     * @param 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]
548
     * @param string $field_position Optionnel ex.: "after champtruc"
549
     * @return   int                        Return integer <0 if KO, >0 if OK
550
     */
551
    public function DDLAddField($table, $field_name, $field_desc, $field_position = "")
552
    {
553
        return $this->db->DDLAddField($table, $field_name, $field_desc, $field_position);
554
    }
555
556
    /**
557
     * Drop a field from table
558
     *
559
     * @param string $table Name of table
560
     * @param string $field_name Name of field to drop
561
     * @return   int                        Return integer <0 if KO, >0 if OK
562
     */
563
    public function DDLDropField($table, $field_name)
564
    {
565
        return $this->db->DDLDropField($table, $field_name);
566
    }
567
568
    /**
569
     * Update format of a field into a table
570
     *
571
     * @param string $table Name of table
572
     * @param string $field_name Name of field to modify
573
     * @param 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
574
     * @return   int                        Return integer <0 if KO, >0 if OK
575
     */
576
    public function DDLUpdateField($table, $field_name, $field_desc)
577
    {
578
        return $this->db->DDLUpdateField($table, $field_name, $field_desc);
579
    }
580
581
    /**
582
     * Return list of available collation that can be used for database
583
     *
584
     * @return        array                 List of Collation
585
     */
586
    public function getListOfCollation()
587
    {
588
        return $this->db->getListOfCollation();
589
    }
590
591
    /**
592
     * Return a pointer of line with description of a table or field
593
     *
594
     * @param string $table Name of table
595
     * @param string $field Optionnel : Name of field if we want description of field
596
     * @return   resource                   Resource
597
     */
598
    public function DDLDescTable($table, $field = "")
599
    {
600
        return $this->db->DDLDescTable($table, $field);
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->db->DDLDescTable($table, $field) also could return the type SQLite3Result|boolean|mysqli_result which is incompatible with the documented return type resource.
Loading history...
601
    }
602
603
    /**
604
     * Return version of database server
605
     *
606
     * @return            string            Version string
607
     */
608
    public function getVersion()
609
    {
610
        return $this->db->getVersion();
611
    }
612
613
    /**
614
     * Return charset used to store data in database
615
     *
616
     * @return        string                Charset
617
     */
618
    public function getDefaultCharacterSetDatabase()
619
    {
620
        return $this->db->getDefaultCharacterSetDatabase();
621
    }
622
623
    /**
624
     * Create a user and privileges to connect to database (even if database does not exists yet)
625
     *
626
     * @param string $dolibarr_main_db_host Ip serveur
627
     * @param string $dolibarr_main_db_user Nom user a creer
628
     * @param string $dolibarr_main_db_pass Password user a creer
629
     * @param string $dolibarr_main_db_name Database name where user must be granted
630
     * @return   int                            Return integer <0 if KO, >=0 if OK
631
     */
632
    public function DDLCreateUser($dolibarr_main_db_host, $dolibarr_main_db_user, $dolibarr_main_db_pass, $dolibarr_main_db_name)
633
    {
634
        return $this->db->DDLCreateUser($dolibarr_main_db_host, $dolibarr_main_db_user, $dolibarr_main_db_pass, $dolibarr_main_db_name);
635
    }
636
637
    // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
638
639
    /**
640
     * Convert (by PHP) a PHP server TZ string date into a Timestamps date (GMT if gm=true)
641
     * 19700101020000 -> 3600 with TZ+1 and gmt=0
642
     * 19700101020000 -> 7200 whaterver is TZ if gmt=1
643
     *
644
     * @param string $string Date in a string (YYYYMMDDHHMMSS, YYYYMMDD, YYYY-MM-DD HH:MM:SS)
645
     * @param bool $gm 1=Input information are GMT values, otherwise local to server TZ
646
     * @return  int|''                      Date TMS or ''
0 ignored issues
show
Documentation Bug introduced by
The doc comment int|'' at position 2 could not be parsed: Unknown type name '''' at position 2 in int|''.
Loading history...
647
     */
648
    public function jdate($string, $gm = false)
649
    {
650
        // phpcs:enable
651
        return $this->db->jdate($string, $gm);
652
    }
653
654
    /**
655
     * Encrypt sensitive data in database
656
     * Warning: This function includes the escape and add the SQL simple quotes on strings.
657
     *
658
     * @param string $fieldorvalue Field name or value to encrypt
659
     * @param int $withQuotes Return string including the SQL simple quotes. This param must always be 1 (Value 0 is bugged and deprecated).
660
     * @return  string                  XXX(field) or XXX('value') or field or 'value'
661
     */
662
    public function encrypt($fieldorvalue, $withQuotes = 1)
663
    {
664
        return $this->db->encrypt($fieldorvalue, $withQuotes);
665
    }
666
667
    /**
668
     * Validate a database transaction
669
     *
670
     * @param string $log Add more log to default log line
671
     * @return  int                             1 if validation is OK or transaction level no started, 0 if ERROR
672
     */
673
    public function commit($log = '')
674
    {
675
        return $this->db->commit($log);
676
    }
677
678
    /**
679
     * List information of columns into a table.
680
     *
681
     * @param string $table Name of table
682
     * @return  array                           Array with information on table
683
     */
684
    public function DDLInfoTable($table)
685
    {
686
        return $this->db->DDLInfoTable($table);
687
    }
688
689
    /**
690
     * Free last resultset used.
691
     *
692
     * @param resource $resultset Fre cursor
693
     * @return  void
694
     */
695
    public function free($resultset = null)
696
    {
697
        $this->db->free($resultset);
698
    }
699
700
    /**
701
     * Close database connection
702
     *
703
     * @return  boolean                         True if disconnect successful, false otherwise
704
     * @see     connect()
705
     */
706
    public function close()
707
    {
708
        return $this->db->close();
709
    }
710
711
    /**
712
     * Return last query in error
713
     *
714
     * @return  string    lastqueryerror
715
     */
716
    public function lastqueryerror()
717
    {
718
        return $this->db->lastqueryerror();
719
    }
720
721
    /**
722
     * Return connection ID
723
     *
724
     * @return  string      Id connection
725
     */
726
    public function DDLGetConnectId()
727
    {
728
        return $this->db->DDLGetConnectId();
729
    }
730
731
    // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
732
733
    /**
734
     * Returns the current line (as an object) for the resultset cursor
735
     *
736
     * @param resource|PgSql\Connection $resultset Handler of the desired SQL request
737
     * @return  Object                                          Object result line or false if KO or end of cursor
738
     */
739
    public function fetch_object($resultset)
740
    {
741
        // phpcs:enable
742
        return $this->db->fetch_object($resultset);
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->db->fetch_object($resultset) could also return false which is incompatible with the documented return type object. Did you maybe forget to handle an error condition?

If the returned type also contains false, it is an indicator that maybe an error condition leading to the specific return statement remains unhandled.

Loading history...
743
    }
744
745
    // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
746
747
    /**
748
     * Select a database
749
     *
750
     * @param string $database Name of database
751
     * @return  boolean              true if OK, false if KO
752
     */
753
    public function select_db($database)
754
    {
755
        // phpcs:enable
756
        return $this->db->select_db($database);
757
    }
758
}
759