From 827a00af5286df8572dd31a337b421e8945dd283 Mon Sep 17 00:00:00 2001 From: Paul Holden Date: Mon, 18 Dec 2023 20:01:56 +0000 Subject: [PATCH] MDL-79662 libraries: upgrade to version 5.22.7 of ADOdb. --- lib/adodb/adodb-csvlib.inc.php | 2 +- lib/adodb/adodb-errorhandler.inc.php | 9 ++- lib/adodb/adodb-errorpear.inc.php | 10 ++- lib/adodb/adodb-exceptions.inc.php | 16 +++-- lib/adodb/adodb-lib.inc.php | 60 +++++++++++----- lib/adodb/adodb-loadbalancer.inc.php | 12 ++-- lib/adodb/adodb-perf.inc.php | 6 +- lib/adodb/adodb-time.inc.php | 2 + lib/adodb/adodb-xmlschema.inc.php | 4 +- lib/adodb/adodb-xmlschema03.inc.php | 16 ++--- lib/adodb/adodb.inc.php | 56 ++++++++++----- lib/adodb/drivers/adodb-ado.inc.php | 6 +- lib/adodb/drivers/adodb-ado5.inc.php | 7 +- lib/adodb/drivers/adodb-ads.inc.php | 1 - lib/adodb/drivers/adodb-csv.inc.php | 2 +- lib/adodb/drivers/adodb-db2.inc.php | 2 +- lib/adodb/drivers/adodb-fbsql.inc.php | 1 - lib/adodb/drivers/adodb-firebird.inc.php | 20 +++--- lib/adodb/drivers/adodb-ibase.inc.php | 22 +++--- lib/adodb/drivers/adodb-informix72.inc.php | 1 - lib/adodb/drivers/adodb-ldap.inc.php | 1 - lib/adodb/drivers/adodb-mssql.inc.php | 1 - lib/adodb/drivers/adodb-mysqli.inc.php | 37 +++++----- lib/adodb/drivers/adodb-oci8.inc.php | 77 ++++++++++----------- lib/adodb/drivers/adodb-oci8po.inc.php | 11 ++- lib/adodb/drivers/adodb-odbc.inc.php | 9 ++- lib/adodb/drivers/adodb-oracle.inc.php | 1 - lib/adodb/drivers/adodb-pdo.inc.php | 1 - lib/adodb/drivers/adodb-postgres64.inc.php | 5 +- lib/adodb/drivers/adodb-postgres8.inc.php | 20 ++++-- lib/adodb/drivers/adodb-sqlanywhere.inc.php | 2 +- lib/adodb/drivers/adodb-sqlite.inc.php | 1 - lib/adodb/drivers/adodb-sqlite3.inc.php | 1 - lib/adodb/drivers/adodb-sybase.inc.php | 1 - lib/adodb/drivers/adodb-text.inc.php | 23 +++--- lib/adodb/perf/perf-oci8.inc.php | 2 +- lib/adodb/readme_moodle.txt | 3 - lib/adodb/tohtml.inc.php | 5 +- lib/thirdpartylibs.xml | 2 +- 39 files changed, 272 insertions(+), 186 deletions(-) diff --git a/lib/adodb/adodb-csvlib.inc.php b/lib/adodb/adodb-csvlib.inc.php index 8273a17ac6c..87efd9406cc 100644 --- a/lib/adodb/adodb-csvlib.inc.php +++ b/lib/adodb/adodb-csvlib.inc.php @@ -76,10 +76,10 @@ $ADODB_INCLUDED_CSV = 1; $savefetch = isset($rs->adodbFetchMode) ? $rs->adodbFetchMode : $rs->fetchMode; $class = $rs->connection->arrayClass; + /** @var ADORecordSet $rs2 */ $rs2 = new $class(ADORecordSet::DUMMY_QUERY_ID); $rs2->timeCreated = $rs->timeCreated; # memcache fix $rs2->sql = $rs->sql; - $rs2->oldProvider = $rs->dataProvider; $rs2->InitArrayFields($rows,$flds); $rs2->fetchMode = $savefetch; return $line.serialize($rs2); diff --git a/lib/adodb/adodb-errorhandler.inc.php b/lib/adodb/adodb-errorhandler.inc.php index 0cd3f218b4b..1d3b9e9e521 100644 --- a/lib/adodb/adodb-errorhandler.inc.php +++ b/lib/adodb/adodb-errorhandler.inc.php @@ -37,7 +37,14 @@ if (!defined('ADODB_ERROR_HANDLER')) define('ADODB_ERROR_HANDLER','ADODB_Error_H */ function ADODB_Error_Handler($dbms, $fn, $errno, $errmsg, $p1, $p2, &$thisConnection) { - if (error_reporting() == 0) return; // obey @ protocol + // Do not throw if errors are suppressed by @ operator + // error_reporting() value for suppressed errors changed in PHP 8.0.0 + $suppressed = version_compare(PHP_VERSION, '8.0.0', '<') + ? 0 + : E_ERROR | E_CORE_ERROR | E_COMPILE_ERROR | E_USER_ERROR | E_RECOVERABLE_ERROR | E_PARSE; + if (error_reporting() == $suppressed) { + return; + } switch($fn) { case 'EXECUTE': $sql = $p1; diff --git a/lib/adodb/adodb-errorpear.inc.php b/lib/adodb/adodb-errorpear.inc.php index 2bb15947e89..7b173da84fd 100644 --- a/lib/adodb/adodb-errorpear.inc.php +++ b/lib/adodb/adodb-errorpear.inc.php @@ -52,7 +52,15 @@ function ADODB_Error_PEAR($dbms, $fn, $errno, $errmsg, $p1=false, $p2=false) { global $ADODB_Last_PEAR_Error; - if (error_reporting() == 0) return; // obey @ protocol + // Do not throw if errors are suppressed by @ operator + // error_reporting() value for suppressed errors changed in PHP 8.0.0 + $suppressed = version_compare(PHP_VERSION, '8.0.0', '<') + ? 0 + : E_ERROR | E_CORE_ERROR | E_COMPILE_ERROR | E_USER_ERROR | E_RECOVERABLE_ERROR | E_PARSE; + if (error_reporting() == $suppressed) { + return; + } + switch($fn) { case 'EXECUTE': $sql = $p1; diff --git a/lib/adodb/adodb-exceptions.inc.php b/lib/adodb/adodb-exceptions.inc.php index 36566de4378..e4fae817e73 100644 --- a/lib/adodb/adodb-exceptions.inc.php +++ b/lib/adodb/adodb-exceptions.inc.php @@ -81,10 +81,18 @@ var $database = ''; function adodb_throw($dbms, $fn, $errno, $errmsg, $p1, $p2, $thisConnection) { -global $ADODB_EXCEPTION; + global $ADODB_EXCEPTION; + + // Do not throw if errors are suppressed by @ operator + // error_reporting() value for suppressed errors changed in PHP 8.0.0 + $suppressed = version_compare(PHP_VERSION, '8.0.0', '<') + ? 0 + : E_ERROR | E_CORE_ERROR | E_COMPILE_ERROR | E_USER_ERROR | E_RECOVERABLE_ERROR | E_PARSE; + if (error_reporting() == $suppressed) { + return; + } + + $errfn = is_string($ADODB_EXCEPTION) ? $ADODB_EXCEPTION : 'ADODB_EXCEPTION'; - if (error_reporting() == 0) return; // obey @ protocol - if (is_string($ADODB_EXCEPTION)) $errfn = $ADODB_EXCEPTION; - else $errfn = 'ADODB_EXCEPTION'; throw new $errfn($dbms, $fn, $errno, $errmsg, $p1, $p2, $thisConnection); } diff --git a/lib/adodb/adodb-lib.inc.php b/lib/adodb/adodb-lib.inc.php index 4c2668b26ac..90b8b9d6b8f 100644 --- a/lib/adodb/adodb-lib.inc.php +++ b/lib/adodb/adodb-lib.inc.php @@ -508,32 +508,38 @@ function _adodb_getcount($zthis, $sql,$inputarr=false,$secs2cache=0) return $qryRecs; } -/* - Code originally from "Cornel G" - - This code might not work with SQL that has UNION in it - - Also if you are using CachePageExecute(), there is a strong possibility that - data will get out of synch. use CachePageExecute() only with tables that - rarely change. -*/ -function _adodb_pageexecute_all_rows($zthis, $sql, $nrows, $page, - $inputarr=false, $secs2cache=0) +/** + * Execute query with pagination including record count. + * + * This code might not work with SQL that has UNION in it. + * Also if you are using cachePageExecute(), there is a strong possibility that + * data will get out of sync. cachePageExecute() should only be used with + * tables that rarely change. + * + * @param ADOConnection $zthis Connection + * @param string $sql Query to execute + * @param int $nrows Number of rows per page + * @param int $page Page number to retrieve (1-based) + * @param array $inputarr Array of bind variables + * @param int $secs2cache Time-to-live of the cache (in seconds), 0 to force query execution + * + * @return ADORecordSet|bool + * + * @author Cornel G + */ +function _adodb_pageexecute_all_rows($zthis, $sql, $nrows, $page, $inputarr=false, $secs2cache=0) { $atfirstpage = false; $atlastpage = false; - // If an invalid nrows is supplied, - // we assume a default value of 10 rows per page + // If an invalid nrows is supplied, assume a default value of 10 rows per page if (!isset($nrows) || $nrows <= 0) $nrows = 10; $qryRecs = _adodb_getcount($zthis,$sql,$inputarr,$secs2cache); $lastpageno = (int) ceil($qryRecs / $nrows); - $zthis->_maxRecordCount = $qryRecs; - // ***** Here we check whether $page is the last page or - // whether we are trying to retrieve - // a page number greater than the last page number. + // Check whether $page is the last page or if we are trying to retrieve + // a page number greater than the last one. if ($page >= $lastpageno) { $page = $lastpageno; $atlastpage = true; @@ -565,7 +571,25 @@ function _adodb_pageexecute_all_rows($zthis, $sql, $nrows, $page, return $rsreturn; } -// Iván Oliva version +/** + * Execute query with pagination without last page information. + * + * This code might not work with SQL that has UNION in it. + * Also if you are using cachePageExecute(), there is a strong possibility that + * data will get out of sync. cachePageExecute() should only be used with + * tables that rarely change. + * + * @param ADOConnection $zthis Connection + * @param string $sql Query to execute + * @param int $nrows Number of rows per page + * @param int $page Page number to retrieve (1-based) + * @param array $inputarr Array of bind variables + * @param int $secs2cache Time-to-live of the cache (in seconds), 0 to force query execution + * + * @return ADORecordSet|bool + * + * @author Iván Oliva + */ function _adodb_pageexecute_no_last_page($zthis, $sql, $nrows, $page, $inputarr=false, $secs2cache=0) { $atfirstpage = false; diff --git a/lib/adodb/adodb-loadbalancer.inc.php b/lib/adodb/adodb-loadbalancer.inc.php index 88f5d0fdc21..de067805b5f 100644 --- a/lib/adodb/adodb-loadbalancer.inc.php +++ b/lib/adodb/adodb-loadbalancer.inc.php @@ -38,17 +38,17 @@ class ADOdbLoadBalancer /** * @var bool|array All connections to each database. */ - protected $connections = false; + protected $connections = []; /** * @var bool|array Just connections to the write capable database. */ - protected $connections_write = false; + protected $connections_write = []; /** * @var bool|array Just connections to the readonly database. */ - protected $connections_readonly = false; + protected $connections_readonly = []; /** * @var array Counts of all connections and their types. @@ -73,12 +73,12 @@ class ADOdbLoadBalancer /** * @var bool Session variables that must be maintained across all connections, ie: SET TIME ZONE. */ - protected $session_variables = false; + protected $session_variables = []; /** * @var bool Called immediately after connecting to any DB. */ - protected $user_defined_session_init_sql = false; + protected $user_defined_session_init_sql = []; /** @@ -403,7 +403,7 @@ class ADOdbLoadBalancer */ private function executeSessionVariables($adodb_obj = false) { - if (is_array($this->session_variables)) { + if (is_array($this->session_variables) && count($this->session_variables) > 0) { $sql = ''; foreach ($this->session_variables as $name => $value) { // $sql .= 'SET SESSION '. $name .' '. $value; diff --git a/lib/adodb/adodb-perf.inc.php b/lib/adodb/adodb-perf.inc.php index b8804dff28c..91610536545 100644 --- a/lib/adodb/adodb-perf.inc.php +++ b/lib/adodb/adodb-perf.inc.php @@ -1017,7 +1017,7 @@ Committed_AS: 348732 kB * ADODB_OPT_LOW for CPU-less optimization * Default is LOW ADODB_OPT_LOW * @author Markus Staab - * @return Returns true on success and false on error + * @return bool true on success, false on error */ function OptimizeTables() { @@ -1048,7 +1048,7 @@ Committed_AS: 348732 kB * ADODB_OPT_LOW for CPU-less optimization * Default is LOW ADODB_OPT_LOW * @author Markus Staab - * @return Returns true on success and false on error + * @return bool true on success, false on error */ function OptimizeTable( $table, $mode = ADODB_OPT_LOW) { @@ -1062,7 +1062,7 @@ Committed_AS: 348732 kB * optimize each using optmizeTable() * * @author Markus Staab - * @return Returns true on success and false on error + * @return bool true on success, false on error */ function optimizeDatabase() { diff --git a/lib/adodb/adodb-time.inc.php b/lib/adodb/adodb-time.inc.php index cfbdc6a5caa..0c3dd11de69 100644 --- a/lib/adodb/adodb-time.inc.php +++ b/lib/adodb/adodb-time.inc.php @@ -2,6 +2,8 @@ /** * ADOdb Date Library. * + * @deprecated 5.22.6 Use 64-bit PHP native functions instead. + * * PHP native date functions use integer timestamps for computations. * Because of this, dates are restricted to the years 1901-2038 on Unix * and 1970-2038 on Windows due to integer overflow for dates beyond diff --git a/lib/adodb/adodb-xmlschema.inc.php b/lib/adodb/adodb-xmlschema.inc.php index ac13d34ec72..662e2aaec82 100644 --- a/lib/adodb/adodb-xmlschema.inc.php +++ b/lib/adodb/adodb-xmlschema.inc.php @@ -412,7 +412,7 @@ class dbTable extends dbObject { * @param string $type ADODB datadict field type. * @param string $size Field size * @param array $opts Field options array - * @return array Field specifier array + * @return void */ function addField( $name, $type, $size = NULL, $opts = NULL ) { $field_id = $this->FieldID( $name ); @@ -446,7 +446,7 @@ class dbTable extends dbObject { * @param string $field Field name * @param string $opt ADOdb field option * @param mixed $value Field option value - * @return array Field specifier array + * @return void */ function addFieldOpt( $field, $opt, $value = NULL ) { if( !isset( $value ) ) { diff --git a/lib/adodb/adodb-xmlschema03.inc.php b/lib/adodb/adodb-xmlschema03.inc.php index 83a0a788e9b..3c8bce5d4f3 100644 --- a/lib/adodb/adodb-xmlschema03.inc.php +++ b/lib/adodb/adodb-xmlschema03.inc.php @@ -450,7 +450,7 @@ class dbTable extends dbObject { * @param string $type ADODB datadict field type. * @param string $size Field size * @param array $opts Field options array - * @return array Field specifier array + * @return void */ function addField( $name, $type, $size = NULL, $opts = NULL ) { $field_id = $this->fieldID( $name ); @@ -486,7 +486,7 @@ class dbTable extends dbObject { * @param string $field Field name * @param string $opt ADOdb field option * @param mixed $value Field option value - * @return array Field specifier array + * @return void */ function addFieldOpt( $field, $opt, $value = NULL ) { if( $this->currentPlatform ) { @@ -766,7 +766,7 @@ class dbIndex extends dbObject { * Adds a field to the index * * @param string $name Field name - * @return string Field list + * @return string[] Field list */ function addField( $name ) { $this->columns[$this->fieldID( $name )] = $name; @@ -779,7 +779,7 @@ class dbIndex extends dbObject { * Adds options to the index * * @param string $opt Comma-separated list of index options. - * @return string Option list + * @return string[] Option list */ function addIndexOpt( $opt ) { $this->opts[] = $opt; @@ -929,10 +929,10 @@ class dbData extends dbObject { } /** - * Adds options to the index + * Adds data. * - * @param string $opt Comma-separated list of index options. - * @return string Option list + * @param string $cdata Data to add + * @return void */ function addData( $cdata ) { // check we're in a valid field @@ -1782,7 +1782,7 @@ class adoSchema { $sqlArray = $this->sqlArray; } if( !isset( $sqlArray ) ) { - return FALSE; + return false; } $fp = fopen( $filename, "w" ); diff --git a/lib/adodb/adodb.inc.php b/lib/adodb/adodb.inc.php index 876ab9c822e..ea29adeb416 100644 --- a/lib/adodb/adodb.inc.php +++ b/lib/adodb/adodb.inc.php @@ -198,7 +198,7 @@ if (!defined('_ADODB_LAYER')) { /** * ADODB version as a string. */ - $ADODB_vers = 'v5.22.5 2023-04-03'; + $ADODB_vers = 'v5.22.7 2023-11-04'; /** * Determines whether recordset->RecordCount() is used. @@ -1466,7 +1466,7 @@ if (!defined('_ADODB_LAYER')) { * @param array|bool $inputarr holds the input data to bind to. * Null elements will be set to null. * - * @return ADORecordSet|bool + * @return ADORecordSet|false */ public function Execute($sql, $inputarr = false) { if ($this->fnExecute) { @@ -1666,6 +1666,18 @@ if (!defined('_ADODB_LAYER')) { return $rs; } + /** + * Execute a query. + * + * @param string|array $sql Query to execute. + * @param array $inputarr An optional array of parameters. + * + * @return mixed|bool Query identifier or true if execution successful, false if failed. + */ + function _query($sql, $inputarr = false) { + return false; + } + function CreateSequence($seqname='adodbseq',$startID=1) { if (empty($this->_genSeqSQL)) { return false; @@ -3554,20 +3566,21 @@ http://www.stanford.edu/dept/itss/docs/oracle/10g/server.101/b10759/statements_1 /** - * Will select the supplied $page number from a recordset, given that it is paginated in pages of - * $nrows rows per page. It also saves two boolean values saying if the given page is the first - * and/or last one of the recordset. Added by Iván Oliva to provide recordset pagination. + * Execute query with pagination. * - * See docs-adodb.htm#ex8 for an example of usage. - * NOTE: phpLens uses a different algorithm and does not use PageExecute(). + * Will select the supplied $page number from a recordset, divided in + * pages of $nrows rows each. It also saves two boolean values saying + * if the given page is the first and/or last one of the recordset. * - * @param string $sql - * @param int $nrows Number of rows per page to get - * @param int $page Page number to get (1-based) - * @param mixed[]|bool $inputarr Array of bind variables - * @param int $secs2cache Private parameter only used by jlim + * @param string $sql Query to execute + * @param int $nrows Number of rows per page + * @param int $page Page number to retrieve (1-based) + * @param array|bool $inputarr Array of bind variables + * @param int $secs2cache Time-to-live of the cache (in seconds), 0 to force query execution * - * @return mixed the recordset ($rs->databaseType == 'array') + * @return ADORecordSet|bool the recordset ($rs->databaseType == 'array') + * + * @author Iván Oliva */ function PageExecute($sql, $nrows, $page, $inputarr=false, $secs2cache=0) { global $ADODB_INCLUDED_LIB; @@ -3743,7 +3756,7 @@ http://www.stanford.edu/dept/itss/docs/oracle/10g/server.101/b10759/statements_1 /** * Internal placeholder for record objects. Used by ADORecordSet->FetchObj(). */ - #[AllowDynamicProperties] + #[\AllowDynamicProperties] class ADOFetchObj { }; @@ -3983,11 +3996,20 @@ class ADORecordSet implements IteratorAggregate { var $_obj; /** Used by FetchObj */ var $_names; /** Used by FetchObj */ - var $_currentPage = -1; /** Added by Iván Oliva to implement recordset pagination */ - var $_atFirstPage = false; /** Added by Iván Oliva to implement recordset pagination */ - var $_atLastPage = false; /** Added by Iván Oliva to implement recordset pagination */ + // Recordset pagination + /** @var int Number of rows per page */ + var $rowsPerPage; + /** @var int Current page number */ + var $_currentPage = -1; + /** @var bool True if current page is the first page */ + var $_atFirstPage = false; + /** @var bool True if current page is the last page */ + var $_atLastPage = false; + /** @var int Last page number */ var $_lastPageNo = -1; + /** @var int Total number of rows in recordset */ var $_maxRecordCount = 0; + var $datetime = false; public $customActualTypes; diff --git a/lib/adodb/drivers/adodb-ado.inc.php b/lib/adodb/drivers/adodb-ado.inc.php index fc000cecb38..df95c690129 100644 --- a/lib/adodb/drivers/adodb-ado.inc.php +++ b/lib/adodb/drivers/adodb-ado.inc.php @@ -208,10 +208,6 @@ class ADODB_ado extends ADOConnection { return empty($arr) ? $false : $arr; } - - - - /* returns queryID or false */ function _query($sql,$inputarr=false) { @@ -504,7 +500,7 @@ class ADORecordSet_ado extends ADORecordSet { $t = $fieldobj->type; $len = $fieldobj->max_length; } - + if (array_key_exists($t,$this->connection->customActualTypes)) return $this->connection->customActualTypes[$t]; diff --git a/lib/adodb/drivers/adodb-ado5.inc.php b/lib/adodb/drivers/adodb-ado5.inc.php index 36f9c3b8d5b..04b45abf658 100644 --- a/lib/adodb/drivers/adodb-ado5.inc.php +++ b/lib/adodb/drivers/adodb-ado5.inc.php @@ -233,7 +233,6 @@ class ADODB_ado extends ADOConnection { return $arr; } - /* returns queryID or false */ function _query($sql,$inputarr=false) { try { // In PHP5, all COM errors are exceptions, so to maintain old behaviour... @@ -545,13 +544,13 @@ class ADORecordSet_ado extends ADORecordSet { $t = $fieldobj->type; $len = $fieldobj->max_length; } - + $t = strtoupper($t); - + if (array_key_exists($t,$this->connection->customActualTypes)) return $this->connection->customActualTypes[$t]; - if (!is_numeric($t)) + if (!is_numeric($t)) return $t; switch ($t) { diff --git a/lib/adodb/drivers/adodb-ads.inc.php b/lib/adodb/drivers/adodb-ads.inc.php index 8b877b6dfbc..16eec976695 100644 --- a/lib/adodb/drivers/adodb-ads.inc.php +++ b/lib/adodb/drivers/adodb-ads.inc.php @@ -564,7 +564,6 @@ class ADODB_ads extends ADOConnection return array($sql, $stmt, false); } - /* returns queryID or false */ function _query($sql, $inputarr = false) { $last_php_error = $this->resetLastError(); diff --git a/lib/adodb/drivers/adodb-csv.inc.php b/lib/adodb/drivers/adodb-csv.inc.php index 8a59626e14c..e6694d9adcc 100644 --- a/lib/adodb/drivers/adodb-csv.inc.php +++ b/lib/adodb/drivers/adodb-csv.inc.php @@ -199,7 +199,7 @@ class ADODB_csv extends ADOConnection { } } // class -class ADORecordset_csv extends ADORecordset { +class ADORecordset_csv extends ADORecordSet { function _close() { diff --git a/lib/adodb/drivers/adodb-db2.inc.php b/lib/adodb/drivers/adodb-db2.inc.php index e214d2d7e10..7c773849de4 100644 --- a/lib/adodb/drivers/adodb-db2.inc.php +++ b/lib/adodb/drivers/adodb-db2.inc.php @@ -1568,7 +1568,7 @@ See http://msdn.microsoft.com/library/default.asp?url=/library/en-us/db2/htm/db2 * * @return mixed either the queryID or false */ - function _query(&$sql,$inputarr=false) + function _query($sql, $inputarr = false) { $db2Options = array(); /* diff --git a/lib/adodb/drivers/adodb-fbsql.inc.php b/lib/adodb/drivers/adodb-fbsql.inc.php index a4255eb97ed..64913bc249f 100644 --- a/lib/adodb/drivers/adodb-fbsql.inc.php +++ b/lib/adodb/drivers/adodb-fbsql.inc.php @@ -134,7 +134,6 @@ class ADODB_fbsql extends ADOConnection { } - // returns queryID or false function _query($sql,$inputarr=false) { return fbsql_query("$sql;",$this->_connectionID); diff --git a/lib/adodb/drivers/adodb-firebird.inc.php b/lib/adodb/drivers/adodb-firebird.inc.php index 133d9f43c8c..db3cca5d6f0 100644 --- a/lib/adodb/drivers/adodb-firebird.inc.php +++ b/lib/adodb/drivers/adodb-firebird.inc.php @@ -483,14 +483,14 @@ class ADODB_firebird extends ADOConnection { } /** - * Return the query id. - * - * @param string|array $sql - * @param array $iarr - * - * @return bool|object - */ - function _query($sql, $iarr = false) + * Execute a query. + * + * @param string|array $sql Query to execute. + * @param array $inputarr An optional array of parameters. + * + * @return object|bool Query identifier or true if execution successful, false if failed. + */ + function _query($sql, $inputarr = false) { if (!$this->isConnected()) { return false; @@ -512,8 +512,8 @@ class ADODB_firebird extends ADOConnection { $fn = 'fbird_query'; $args = [$conn, $sql]; } - if (is_array($iarr)) { - $args = array_merge($args, $iarr); + if (is_array($inputarr)) { + $args = array_merge($args, $inputarr); } $ret = call_user_func_array($fn, $args); diff --git a/lib/adodb/drivers/adodb-ibase.inc.php b/lib/adodb/drivers/adodb-ibase.inc.php index 25a9c3e86b7..8159c512d68 100644 --- a/lib/adodb/drivers/adodb-ibase.inc.php +++ b/lib/adodb/drivers/adodb-ibase.inc.php @@ -256,7 +256,7 @@ class ADODB_ibase extends ADOConnection { // See http://community.borland.com/article/0,1410,25844,00.html - function RowLock($tables,$where,$col=false) + function rowLock($table, $where, $col = false) { if ($this->autoCommit) { $this->BeginTrans(); @@ -332,7 +332,7 @@ class ADODB_ibase extends ADOConnection { // returns query ID if successful, otherwise false // there have been reports of problems with nested queries - the code is probably not re-entrant? - function _query($sql,$iarr=false) + function _query($sql, $inputarr = false) { if (!$this->autoCommit && $this->_transactionID) { $conn = $this->_transactionID; @@ -344,11 +344,11 @@ class ADODB_ibase extends ADOConnection { if (is_array($sql)) { $fn = 'ibase_execute'; $sql = $sql[1]; - if (is_array($iarr)) { - if (!isset($iarr[0])) { - $iarr[0] = ''; // PHP5 compat hack + if (is_array($inputarr)) { + if (!isset($inputarr[0])) { + $inputarr[0] = ''; // PHP5 compat hack } - $fnarr = array_merge(array($sql), $iarr); + $fnarr = array_merge(array($sql), $inputarr); $ret = call_user_func_array($fn, $fnarr); } else { $ret = $fn($sql); @@ -356,11 +356,11 @@ class ADODB_ibase extends ADOConnection { } else { $fn = 'ibase_query'; - if (is_array($iarr)) { - if (sizeof($iarr) == 0) { - $iarr[0] = ''; // PHP5 compat hack + if (is_array($inputarr)) { + if (sizeof($inputarr) == 0) { + $inputarr[0] = ''; // PHP5 compat hack } - $fnarr = array_merge(array($conn, $sql), $iarr); + $fnarr = array_merge(array($conn, $sql), $inputarr); $ret = call_user_func_array($fn, $fnarr); } else { $ret = $fn($conn, $sql); @@ -734,7 +734,7 @@ class ADODB_ibase extends ADOConnection { Class Name: Recordset --------------------------------------------------------------------------------------*/ -class ADORecordset_ibase extends ADORecordSet +class ADORecordSet_ibase extends ADORecordSet { var $databaseType = "ibase"; diff --git a/lib/adodb/drivers/adodb-informix72.inc.php b/lib/adodb/drivers/adodb-informix72.inc.php index 759bd5c8f8e..6fddde3d62d 100644 --- a/lib/adodb/drivers/adodb-informix72.inc.php +++ b/lib/adodb/drivers/adodb-informix72.inc.php @@ -334,7 +334,6 @@ class ADODB_informix72 extends ADOConnection { else return array($sql,$stmt); } */ - // returns query ID if successful, otherwise false function _query($sql,$inputarr=false) { global $ADODB_COUNTRECS; diff --git a/lib/adodb/drivers/adodb-ldap.inc.php b/lib/adodb/drivers/adodb-ldap.inc.php index 323b35856bf..305f6a7ff4e 100644 --- a/lib/adodb/drivers/adodb-ldap.inc.php +++ b/lib/adodb/drivers/adodb-ldap.inc.php @@ -157,7 +157,6 @@ class ADODB_ldap extends ADOConnection { } } - /* returns _queryID or false */ function _query($sql,$inputarr=false) { $rs = @ldap_search( $this->_connectionID, $this->database, $sql ); diff --git a/lib/adodb/drivers/adodb-mssql.inc.php b/lib/adodb/drivers/adodb-mssql.inc.php index 269dd7ed38c..c0b714ede26 100644 --- a/lib/adodb/drivers/adodb-mssql.inc.php +++ b/lib/adodb/drivers/adodb-mssql.inc.php @@ -725,7 +725,6 @@ order by constraint_name, referenced_table_name, keyno"; return $this->Execute($sql) != false; } - // returns query ID if successful, otherwise false function _query($sql,$inputarr=false) { $this->_errorMsg = false; diff --git a/lib/adodb/drivers/adodb-mysqli.inc.php b/lib/adodb/drivers/adodb-mysqli.inc.php index 545c694824c..7ec8962d4b9 100644 --- a/lib/adodb/drivers/adodb-mysqli.inc.php +++ b/lib/adodb/drivers/adodb-mysqli.inc.php @@ -167,6 +167,14 @@ class ADODB_mysqli extends ADOConnection { if(!extension_loaded("mysqli")) { return null; } + // Check for a function that only exists in mysqlnd + if (!function_exists('mysqli_stmt_get_result')) { + // @TODO This will be treated as if the mysqli extension were not available + // This could be misleading, so we output an additional error message. + // We should probably throw a specific exception instead. + $this->outp("MySQL Native Driver (msqlnd) required"); + return null; + } $this->_connectionID = @mysqli_init(); if (is_null($this->_connectionID)) { @@ -1091,16 +1099,6 @@ class ADODB_mysqli extends ADOConnection { return array($sql,$stmt); } - /** - * Execute SQL - * - * @param string $sql SQL statement to execute, or possibly an array - * holding prepared statement ($sql[0] will hold sql text) - * @param array|bool $inputarr holds the input data to bind to. - * Null elements will be set to null. - * - * @return ADORecordSet|bool - */ public function execute($sql, $inputarr = false) { if ($this->fnExecute) { @@ -1146,8 +1144,10 @@ class ADODB_mysqli extends ADOConnection { } $bulkTypeArray[] = $typeArray; } + $currentBulkBind = $this->bulkBind; $this->bulkBind = false; $ret = $this->_execute($sql, $bulkTypeArray); + $this->bulkBind = $currentBulkBind; } else { $typeArray = $this->getBindParamWithType($inputarr); $ret = $this->_execute($sql, $typeArray); @@ -1189,14 +1189,14 @@ class ADODB_mysqli extends ADOConnection { } /** - * Return the query id. - * - * @param string|array $sql - * @param array $inputarr - * - * @return bool|mysqli_result + * Execute a query. + * + * @param string|array $sql Query to execute. + * @param array $inputarr An optional array of parameters. + * + * @return mysqli_result|bool */ - function _query($sql, $inputarr) + function _query($sql, $inputarr = false) { global $ADODB_COUNTRECS; // Move to the next recordset, or return false if there is none. In a stored proc @@ -1466,6 +1466,9 @@ class ADODB_mysqli extends ADOConnection { return $this->charSet ?: false; } + /** + * @deprecated 5.21.0 Use {@see setConnectionParameter()} instead + */ function setCharSet($charset) { if (!$this->_connectionID || !method_exists($this->_connectionID,'set_charset')) { diff --git a/lib/adodb/drivers/adodb-oci8.inc.php b/lib/adodb/drivers/adodb-oci8.inc.php index ca78772191f..965c1621c69 100644 --- a/lib/adodb/drivers/adodb-oci8.inc.php +++ b/lib/adodb/drivers/adodb-oci8.inc.php @@ -92,7 +92,7 @@ END; var $random = "abs(mod(DBMS_RANDOM.RANDOM,10000001)/10000000)"; var $noNullStrings = false; var $connectSID = false; - var $_bind = false; + var $_bind = array(); var $_nestedSQL = true; var $_getarray = false; // currently not working var $leftOuter = ''; // oracle wierdness, $col = $value (+) for LEFT OUTER, $col (+)= $value for RIGHT OUTER @@ -781,6 +781,11 @@ END; $hint = ''; } + // If non-bound statement, $inputarr is false + if (!$inputarr) { + $inputarr = array(); + } + if ($offset == -1 || ($offset < $this->selectOffsetAlg1 && 0 < $nrows && $nrows < 1000)) { if ($nrows > 0) { if ($offset > 0) { @@ -788,10 +793,6 @@ END; } $sql = "select * from (".$sql.") where rownum <= :adodb_offset"; - // If non-bound statement, $inputarr is false - if (!$inputarr) { - $inputarr = array(); - } $inputarr['adodb_offset'] = $nrows; $nrows = -1; } @@ -809,32 +810,31 @@ END; } $stmt = $stmt_arr[1]; - if (is_array($inputarr)) { - foreach($inputarr as $k => $v) { - $i=0; - if ($this->databaseType == 'oci8po') { - $bv_name = ":".$i++; + foreach($inputarr as $k => $v) { + $i = 0; + if ($this->databaseType == 'oci8po') { + $bv_name = ":" . $i++; + } else { + $bv_name = ":" . $k; + } + if (is_array($v)) { + // suggested by g.giunta@libero. + if (sizeof($v) == 2) { + oci_bind_by_name($stmt, $bv_name, $inputarr[$k][0], $v[1]); } else { - $bv_name = ":".$k; + oci_bind_by_name($stmt, $bv_name, $inputarr[$k][0], $v[1], $v[2]); } - if (is_array($v)) { - // suggested by g.giunta@libero. - if (sizeof($v) == 2) { - oci_bind_by_name($stmt,$bv_name,$inputarr[$k][0],$v[1]); - } - else { - oci_bind_by_name($stmt,$bv_name,$inputarr[$k][0],$v[1],$v[2]); - } + } else { + $len = -1; + if ($v === ' ') { + $len = 1; + } + if (isset($bindarr)) { + // prepared sql, so no need to oci_bind_by_name again + $bindarr[$k] = $v; } else { - $len = -1; - if ($v === ' ') { - $len = 1; - } - if (isset($bindarr)) { // is prepared sql, so no need to oci_bind_by_name again - $bindarr[$k] = $v; - } else { // dynamic sql, so rebind every time - oci_bind_by_name($stmt,$bv_name,$inputarr[$k],$len); - } + // dynamic sql, so rebind every time + oci_bind_by_name($stmt, $bv_name, $inputarr[$k], $len); } } } @@ -971,16 +971,6 @@ END; return $rez; } - /** - * Execute SQL - * - * @param string|array $sql SQL statement to execute, or possibly an array holding - * prepared statement ($sql[0] will hold sql text). - * @param array|false $inputarr holds the input data to bind to. - * Null elements will be set to null. - * - * @return ADORecordSet|false - */ function Execute($sql,$inputarr=false) { if ($this->fnExecute) { @@ -1282,7 +1272,8 @@ END; } /** - * returns query ID if successful, otherwise false + * Execute a query. + * * this version supports: * * 1. $db->execute('select * from table'); @@ -1295,6 +1286,11 @@ END; * 4. $db->prepare('insert into table (a,b,c) values (:0,:1,:2)'); * $db->bind($stmt,1); $db->bind($stmt,2); $db->bind($stmt,3); * $db->execute($stmt); + * + * @param string|array $sql Query to execute. + * @param array $inputarr An optional array of parameters. + * + * @return mixed|bool Query identifier or true if execution successful, false if failed. */ function _query($sql,$inputarr=false) { @@ -1583,6 +1579,9 @@ SELECT /*+ RULE */ distinct b.column_name if ($this->noNullStrings && strlen($s) == 0) { $s = ' '; } + else if (strlen($s) == 0) { + return "''"; + } if ($this->replaceQuote[0] == '\\'){ $s = str_replace('\\','\\\\',$s); } diff --git a/lib/adodb/drivers/adodb-oci8po.inc.php b/lib/adodb/drivers/adodb-oci8po.inc.php index aaf4bb5fa41..71c203b62a3 100644 --- a/lib/adodb/drivers/adodb-oci8po.inc.php +++ b/lib/adodb/drivers/adodb-oci8po.inc.php @@ -70,7 +70,16 @@ class ADODB_oci8po extends ADODB_oci8 { return ADOConnection::SelectLimit($sql, $nrows, $offset, $inputarr, $secs2cache); } - // emulate handling of parameters ? ?, replacing with :bind0 :bind1 + /** + * Execute a query. + * + * Emulate handling of parameters ? ?, replacing with :bind0 :bind1 + * + * @param string|array $sql Query to execute. + * @param array $inputarr An optional array of parameters. + * + * @return mixed|bool Query identifier or true if execution successful, false if failed. + */ function _query($sql,$inputarr=false) { if (is_array($inputarr)) { diff --git a/lib/adodb/drivers/adodb-odbc.inc.php b/lib/adodb/drivers/adodb-odbc.inc.php index 508711a3032..56db8b0e1ba 100644 --- a/lib/adodb/drivers/adodb-odbc.inc.php +++ b/lib/adodb/drivers/adodb-odbc.inc.php @@ -26,7 +26,7 @@ if (!defined('ADODB_DIR')) die(); /* * These constants are used to set define MetaColumns() method's behavior. - * - METACOLUMNS_RETURNS_ACTUAL makes the driver return the actual type, + * - METACOLUMNS_RETURNS_ACTUAL makes the driver return the actual type, * like all other drivers do (default) * - METACOLUMNS_RETURNS_META is provided for legacy compatibility (makes * driver behave as it did prior to v5.21) @@ -35,7 +35,7 @@ if (!defined('ADODB_DIR')) die(); */ DEFINE('METACOLUMNS_RETURNS_ACTUAL', 0); DEFINE('METACOLUMNS_RETURNS_META', 1); - + /*-------------------------------------------------------------------------------------- --------------------------------------------------------------------------------------*/ @@ -57,7 +57,7 @@ class ADODB_odbc extends ADOConnection { var $_autocommit = true; var $_lastAffectedRows = 0; var $uCaseTables = true; // for meta* functions, uppercase table names - + /* * Tells the metaColumns feature whether to return actual or meta type */ @@ -473,7 +473,7 @@ See http://msdn.microsoft.com/library/default.asp?url=/library/en-us/odbc/htm/od $fld = new ADOFieldObject(); $fld->name = $rs->fields[3]; if ($this->metaColumnsReturnType == METACOLUMNS_RETURNS_META) - /* + /* * This is the broken, original value */ $fld->type = $this->ODBCTypes($rs->fields[4]); @@ -518,7 +518,6 @@ See http://msdn.microsoft.com/library/default.asp?url=/library/en-us/odbc/htm/od return array($sql,$stmt,false); } - /* returns queryID or false */ function _query($sql,$inputarr=false) { $last_php_error = $this->resetLastError(); diff --git a/lib/adodb/drivers/adodb-oracle.inc.php b/lib/adodb/drivers/adodb-oracle.inc.php index 1a2735b1474..dc0462fe2f3 100644 --- a/lib/adodb/drivers/adodb-oracle.inc.php +++ b/lib/adodb/drivers/adodb-oracle.inc.php @@ -181,7 +181,6 @@ class ADODB_oracle extends ADOConnection { } - // returns query ID if successful, otherwise false function _query($sql,$inputarr=false) { // Reset error messages before executing diff --git a/lib/adodb/drivers/adodb-pdo.inc.php b/lib/adodb/drivers/adodb-pdo.inc.php index 0fbe3e2f732..d3ce12d08d8 100644 --- a/lib/adodb/drivers/adodb-pdo.inc.php +++ b/lib/adodb/drivers/adodb-pdo.inc.php @@ -578,7 +578,6 @@ class ADODB_pdo extends ADOConnection { } - /* returns queryID or false */ function _query($sql,$inputarr=false) { $ok = false; diff --git a/lib/adodb/drivers/adodb-postgres64.inc.php b/lib/adodb/drivers/adodb-postgres64.inc.php index fa8e5fba7aa..9bf9e713c6a 100644 --- a/lib/adodb/drivers/adodb-postgres64.inc.php +++ b/lib/adodb/drivers/adodb-postgres64.inc.php @@ -258,7 +258,9 @@ class ADODB_postgres64 extends ADOConnection{ if ($this->_connectionID) { return "'" . pg_escape_string($this->_connectionID, $s) . "'"; } else { - return "'" . pg_escape_string($s) . "'"; + // Fall back to emulated escaping when there is no database connection. + // Avoids errors when using setSessionVariables() in the load balancer. + return parent::qStr( $s ); } } @@ -782,7 +784,6 @@ class ADODB_postgres64 extends ADOConnection{ } - // returns queryID or false function _query($sql,$inputarr=false) { $this->_pnum = 0; diff --git a/lib/adodb/drivers/adodb-postgres8.inc.php b/lib/adodb/drivers/adodb-postgres8.inc.php index 37c2aae1413..58df47c63eb 100644 --- a/lib/adodb/drivers/adodb-postgres8.inc.php +++ b/lib/adodb/drivers/adodb-postgres8.inc.php @@ -45,11 +45,23 @@ class ADODB_postgres8 extends ADODB_postgres7 * @return int last inserted ID for given table/column, or the most recently * returned one if $table or $column are empty */ - protected function _insertID($table = '', $column = '') + protected function _insertID( $table = '', $column = '' ) { - return empty($table) || empty($column) - ? $this->GetOne("SELECT lastval()") - : $this->GetOne("SELECT currval(pg_get_serial_sequence('$table', '$column'))"); + global $ADODB_GETONE_EOF; + + $sql = empty($table) || empty($column) + ? 'SELECT lastval()' + : "SELECT currval(pg_get_serial_sequence('$table', '$column'))"; + + // Squelch "ERROR: lastval is not yet defined in this session" (see #978) + $result = @$this->GetOne($sql); + if ($result === false || $result == $ADODB_GETONE_EOF) { + if ($this->debug) { + ADOConnection::outp(__FUNCTION__ . "() failed : " . $this->errorMsg()); + } + return false; + } + return $result; } } diff --git a/lib/adodb/drivers/adodb-sqlanywhere.inc.php b/lib/adodb/drivers/adodb-sqlanywhere.inc.php index 88897af9267..8d909fdea1c 100644 --- a/lib/adodb/drivers/adodb-sqlanywhere.inc.php +++ b/lib/adodb/drivers/adodb-sqlanywhere.inc.php @@ -116,7 +116,7 @@ if (!defined('ADODB_SYBASE_SQLANYWHERE')){ $conn->Execute('INSERT INTO blobtable (id, blobcol) VALUES (1, null)'); $conn->UpdateBlob('blobtable','blobcol',$blob,'id=1'); */ - function UpdateBlob($table,$column,&$val,$where,$blobtype='BLOB') + function updateBlob($table, $column, $val, $where, $blobtype = 'BLOB') { $blobVarName = 'hold_blob'; $this->create_blobvar($blobVarName); diff --git a/lib/adodb/drivers/adodb-sqlite.inc.php b/lib/adodb/drivers/adodb-sqlite.inc.php index 0711f1dde1c..d41829c04aa 100644 --- a/lib/adodb/drivers/adodb-sqlite.inc.php +++ b/lib/adodb/drivers/adodb-sqlite.inc.php @@ -211,7 +211,6 @@ class ADODB_sqlite extends ADOConnection { return true; } - // returns query ID if successful, otherwise false function _query($sql,$inputarr=false) { $rez = sqlite_query($sql,$this->_connectionID); diff --git a/lib/adodb/drivers/adodb-sqlite3.inc.php b/lib/adodb/drivers/adodb-sqlite3.inc.php index 318171a8c5e..7623a3c887c 100644 --- a/lib/adodb/drivers/adodb-sqlite3.inc.php +++ b/lib/adodb/drivers/adodb-sqlite3.inc.php @@ -331,7 +331,6 @@ class ADODB_sqlite3 extends ADOConnection { return $this->_connect($argHostname, $argUsername, $argPassword, $argDatabasename); } - // returns query ID if successful, otherwise false function _query($sql,$inputarr=false) { $rez = $this->_connectionID->query($sql); diff --git a/lib/adodb/drivers/adodb-sybase.inc.php b/lib/adodb/drivers/adodb-sybase.inc.php index 5eb217a84d2..79fb82e8b5f 100644 --- a/lib/adodb/drivers/adodb-sybase.inc.php +++ b/lib/adodb/drivers/adodb-sybase.inc.php @@ -170,7 +170,6 @@ class ADODB_sybase extends ADOConnection { return true; } - // returns query ID if successful, otherwise false function _query($sql,$inputarr=false) { global $ADODB_COUNTRECS; diff --git a/lib/adodb/drivers/adodb-text.inc.php b/lib/adodb/drivers/adodb-text.inc.php index 77ad06a0ba0..36a1a0d4dc4 100644 --- a/lib/adodb/drivers/adodb-text.inc.php +++ b/lib/adodb/drivers/adodb-text.inc.php @@ -129,14 +129,21 @@ class ADODB_text extends ADOConnection { return true; } - - - // returns queryID or false - // We presume that the select statement is on the same table (what else?), - // with the only difference being the order by. - //You can filter by using $eval and each clause is stored in $arr .eg. $arr[1] == 'name' - // also supports SELECT [DISTINCT] COL FROM ... -- only 1 col supported - function _query($sql,$input_arr,$eval=false) + /** + * Execute a query. + * + * We presume that the select statement is on the same table (what else?), + * with the only difference being the order by. + * You can filter by using $eval and each clause is stored in $arr e.g. $arr[1] == 'name' + * also supports SELECT [DISTINCT] COL FROM ... -- only 1 col supported + * + * @param string|array $sql Query to execute. + * @param array $inputarr An optional array of parameters. + * @param string $eval Optional eval string + * + * @return mixed|bool Query identifier or true if execution successful, false if failed. + */ + function _query($sql, $inputarr=false, $eval=false) { if ($this->_origarray === false) return false; diff --git a/lib/adodb/perf/perf-oci8.inc.php b/lib/adodb/perf/perf-oci8.inc.php index c11b261fd17..345d8929ff3 100644 --- a/lib/adodb/perf/perf-oci8.inc.php +++ b/lib/adodb/perf/perf-oci8.inc.php @@ -23,7 +23,7 @@ if (!defined('ADODB_DIR')) die(); -class perf_oci8 extends ADODB_perf{ +class perf_oci8 extends adodb_perf{ var $noShowIxora = 15; // if the sql for suspicious sql is taking too long, then disable ixora diff --git a/lib/adodb/readme_moodle.txt b/lib/adodb/readme_moodle.txt index f3abcaea09b..be981c8fbe1 100644 --- a/lib/adodb/readme_moodle.txt +++ b/lib/adodb/readme_moodle.txt @@ -23,6 +23,3 @@ Removed: Added: * index.html - prevent directory browsing on misconfigured servers * readme_moodle.txt - this file ;-) - -Notes: - * 2023-09-28 Added #[AllowDynamicProperties] above the ADOFetchObj class. \ No newline at end of file diff --git a/lib/adodb/tohtml.inc.php b/lib/adodb/tohtml.inc.php index a36fdf6b84e..6e9a62863c2 100644 --- a/lib/adodb/tohtml.inc.php +++ b/lib/adodb/tohtml.inc.php @@ -141,7 +141,10 @@ GLOBAL $gSQLMaxRows,$gSQLBlockRows,$ADODB_ROUND; default: if ($v) { - $v = htmlspecialchars(stripslashes(trim($v))); + $v = trim($v); + if ($htmlspecialchars) { + $v = htmlspecialchars($v); + } } elseif ($v === null) { $v = '(NULL)'; } else { diff --git a/lib/thirdpartylibs.xml b/lib/thirdpartylibs.xml index 9b6d7e60162..cec06d2861d 100644 --- a/lib/thirdpartylibs.xml +++ b/lib/thirdpartylibs.xml @@ -4,7 +4,7 @@ adodb AdoDB Database abstraction library for MySQL, PostgreSQL, MSSQL, Oracle, Interbase, Foxpro, Access, ADO, Sybase, DB2 and ODBC. - 5.22.5 + 5.22.7 BSD/LGPL 3-Clause/2.1+ https://github.com/ADOdb/ADOdb