Skip to content

Commit

Permalink
MDL-84401 libraries: upgrade to version 5.22.8 of ADOdb.
Browse files Browse the repository at this point in the history
  • Loading branch information
paulholden committed Feb 5, 2025
1 parent 07881a5 commit 23bdc3a
Show file tree
Hide file tree
Showing 12 changed files with 194 additions and 77 deletions.
10 changes: 3 additions & 7 deletions lib/adodb/adodb-active-record.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -1055,10 +1055,10 @@ function Update()
$valarr = array();
$neworig = array();
$pairs = array();
$i = -1;
$i = 0;
$cnt = 0;
foreach($table->flds as $name=>$fld) {
$i += 1;
$orig = $this->_original[$i++] ?? null;
$val = $this->$name;
$neworig[] = $val;

Expand All @@ -1078,11 +1078,7 @@ function Update()
}
}

if (isset($this->_original[$i]) && strcmp($val,$this->_original[$i]) == 0) {
continue;
}

if (is_null($this->_original[$i]) && is_null($val)) {
if ($val === $orig) {
continue;
}

Expand Down
6 changes: 3 additions & 3 deletions lib/adodb/adodb-active-recordx.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -1142,10 +1142,10 @@ function Update()
$valarr = array();
$neworig = array();
$pairs = array();
$i = -1;
$i = 0;
$cnt = 0;
foreach($table->flds as $name=>$fld) {
$i += 1;
$orig = $this->_original[$i++] ?? null;
$val = $this->$name;
$neworig[] = $val;

Expand All @@ -1165,7 +1165,7 @@ function Update()
}
}

if (isset($this->_original[$i]) && $val === $this->_original[$i]) {
if ($val === $orig) {
continue;
}
$valarr[] = $val;
Expand Down
21 changes: 15 additions & 6 deletions lib/adodb/adodb-datadict.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -510,10 +510,12 @@ function addColumnSQL($tabname, $flds)
*
* As some DBMs can't do that on their own, you need to supply the complete definition of the new table,
* to allow recreating the table and copying the content over to the new table
* @param string $tabname table-name
* @param string $flds column-name and type for the changed column
* @param string $tableflds='' complete definition of the new table, eg. for postgres, default ''
*
* @param string $tabname table-name
* @param array|string $flds column-name and type for the changed column
* @param string $tableflds='' complete definition of the new table, eg. for postgres, default ''
* @param array|string $tableoptions='' options for the new table see createTableSQL, default ''
*
* @return array with SQL strings
*/
function alterColumnSQL($tabname, $flds, $tableflds='',$tableoptions='')
Expand Down Expand Up @@ -1027,7 +1029,6 @@ function _getSizePrec($size)
function changeTableSQL($tablename, $flds, $tableoptions = false, $dropOldFlds=false)
{
global $ADODB_FETCH_MODE;

$save = $ADODB_FETCH_MODE;
$ADODB_FETCH_MODE = ADODB_FETCH_ASSOC;
if ($this->connection->fetchMode !== false) $savem = $this->connection->setFetchMode(false);
Expand All @@ -1045,12 +1046,15 @@ function changeTableSQL($tablename, $flds, $tableoptions = false, $dropOldFlds=f
return $this->createTableSQL($tablename, $flds, $tableoptions);
}

$sql = [];
if (is_array($flds)) {
// Cycle through the update fields, comparing
// existing fields to fields to update.
// if the Metatype and size is exactly the
// same, ignore - by Mark Newham
$holdflds = array();
$fields_to_add = [];
$fields_to_alter = [];
foreach($flds as $k=>$v) {
if ( isset($cols[$k]) && is_object($cols[$k]) ) {
// If already not allowing nulls, then don't change
Expand All @@ -1074,15 +1078,20 @@ function changeTableSQL($tablename, $flds, $tableoptions = false, $dropOldFlds=f
if ($mt == 'X') $ml = $v['SIZE'];
if (($mt != $v['TYPE']) || ($ml != $fsize || $sc != $fprec) || (isset($v['AUTOINCREMENT']) && $v['AUTOINCREMENT'] != $obj->auto_increment)) {
$holdflds[$k] = $v;
$fields_to_alter[$k] = $v;
}
} else {
$fields_to_add[$k] = $v;
$holdflds[$k] = $v;
}
}
$flds = $holdflds;
}

$sql = $this->alterColumnSql($tablename, $flds);
$sql = array_merge(
$this->addColumnSQL($tablename, $fields_to_add),
$this->alterColumnSql($tablename, $fields_to_alter)
);
}

if ($dropOldFlds) {
foreach ($cols as $id => $v) {
Expand Down
33 changes: 19 additions & 14 deletions lib/adodb/adodb-lib.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,7 @@ function _adodb_getmenu_select($name, $defstr = '', $blank1stItem = true,
function _adodb_getmenu_option($defstr, $compare, $value, $display)
{
if ( is_array($defstr) && in_array($compare, $defstr)
|| !is_array($defstr) && strcasecmp($compare, $defstr) == 0
|| !is_array($defstr) && strcasecmp($compare, $defstr ?? '') == 0
) {
$selected = ' selected="selected"';
} else {
Expand All @@ -376,18 +376,23 @@ function _adodb_getmenu_option($defstr, $compare, $value, $display)
return "\n<option $value$selected>" . htmlspecialchars($display) . '</option>';
}

/*
Count the number of records this sql statement will return by using
query rewriting heuristics...
Does not work with UNIONs, except with postgresql and oracle.
Usage:
$conn->Connect(...);
$cnt = _adodb_getcount($conn, $sql);
*/
/**
* Count the number of records this sql statement will return by using
* query rewriting heuristics...
*
* Does not work with UNIONs, except with postgresql and oracle.
*
* Usage:
* $conn->Connect(...);
* $cnt = _adodb_getcount($conn, $sql);
*
* @param ADOConnection $zthis
* @param string $sql
* @param bool $inputarr
* @param int $secs2cache
*
* @return false|int|mixed
*/
function _adodb_getcount($zthis, $sql,$inputarr=false,$secs2cache=0)
{
$qryRecs = 0;
Expand Down Expand Up @@ -1381,7 +1386,7 @@ function _adodb_backtrace($printOrArr=true, $maximumDepth=9999, $elementsToIgnor
$s .= '</pre>';
}
if ($printOrArr) {
print $s;
ADOConnection::outp($s);
}

return $s;
Expand Down
10 changes: 6 additions & 4 deletions lib/adodb/adodb.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ function ADODB_Setup() {
/**
* ADODB version as a string.
*/
$ADODB_vers = 'v5.22.7 2023-11-04';
$ADODB_vers = 'v5.22.8 2025-01-25';

/**
* Determines whether recordset->RecordCount() is used.
Expand Down Expand Up @@ -4300,6 +4300,8 @@ function getRows($nRows = -1) {
*/
function getAssoc($force_array = false, $first2cols = false)
{
global $ADODB_FETCH_MODE;

/*
* Insufficient rows to show data
*/
Expand All @@ -4322,8 +4324,8 @@ function getAssoc($force_array = false, $first2cols = false)
* Get the fetch mode when the call was executed, this may be
* different than ADODB_FETCH_MODE
*/
$fetchMode = $this->connection->fetchMode;
if ($fetchMode == ADODB_FETCH_BOTH) {
$fetchMode = $this->adodbFetchMode;
if ($fetchMode == ADODB_FETCH_BOTH || $fetchMode == ADODB_FETCH_DEFAULT) {
/*
* If we are using BOTH, we present the data as if it
* was in ASSOC mode. This could be enhanced by adding
Expand Down Expand Up @@ -4355,7 +4357,7 @@ function getAssoc($force_array = false, $first2cols = false)

$myFields = $this->fields;

if ($fetchMode == ADODB_FETCH_BOTH) {
if ($fetchMode == ADODB_FETCH_BOTH || $fetchMode == ADODB_FETCH_DEFAULT) {
/*
* extract the associative keys
*/
Expand Down
53 changes: 40 additions & 13 deletions lib/adodb/drivers/adodb-db2.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,10 +109,12 @@ private function doDB2Connect($argDSN, $argUsername, $argPassword, $argDatabasen
return null;
}

$connectionParameters = $this->unpackParameters($argDSN,
$argUsername,
$argPassword,
$argDatabasename);
$connectionParameters = $this->unpackParameters(
$argDSN,
$argUsername,
$argPassword,
$argDatabasename
);

if ($connectionParameters == null)
{
Expand All @@ -129,7 +131,12 @@ private function doDB2Connect($argDSN, $argUsername, $argPassword, $argDatabasen
$useCataloguedConnection = $connectionParameters['catalogue'];

if ($this->debug){
if ($useCataloguedConnection){
if (strcmp($argDSN,'*LOCAL') == 0)
{
$connectMessage = '*LOCAL connection';
}
else if ($useCataloguedConnection)
{
$connectMessage = "Catalogued connection using parameters: ";
$connectMessage .= "DB=$argDatabasename / ";
$connectMessage .= "UID=$argUsername / ";
Expand All @@ -141,6 +148,7 @@ private function doDB2Connect($argDSN, $argUsername, $argPassword, $argDatabasen
}
ADOConnection::outp($connectMessage);
}

/*
* This needs to be set before the connect().
*/
Expand All @@ -164,14 +172,17 @@ private function doDB2Connect($argDSN, $argUsername, $argPassword, $argDatabasen
}

if ($useCataloguedConnection)
{
$this->_connectionID = $db2Function($argDatabasename,
$argUsername,
$argPassword,
$db2Options);
}
else

$this->_connectionID = $db2Function($argDSN,
null,
null,
'',
'',
$db2Options);


Expand All @@ -180,6 +191,9 @@ private function doDB2Connect($argDSN, $argUsername, $argPassword, $argDatabasen
if ($this->_connectionID && $this->connectStmt)
$this->execute($this->connectStmt);

if ($this->_connectionID && $argDatabasename)
$this->execute("SET SCHEMA=$argDatabasename");

return $this->_connectionID != false;

}
Expand All @@ -198,12 +212,25 @@ private function unpackParameters($argDSN, $argUsername, $argPassword, $argDatab
{


$connectionParameters = array('dsn'=>'',
'uid'=>'',
'pwd'=>'',
'database'=>'',
'catalogue'=>true
);
$connectionParameters = array(
'dsn'=>'',
'uid'=>'',
'pwd'=>'',
'database'=>'',
'catalogue'=>true
);

/*
* Shortcut for *LOCAL
*/
if (strcmp($argDSN,'*LOCAL') == 0)
{
$connectionParameters['dsn'] = $argDSN;
$connectionParameters['database'] = $argDatabasename;
$connectionParameters['catalogue'] = false;

return $connectionParameters;
}

/*
* Uou can either connect to a catalogued connection
Expand Down
2 changes: 1 addition & 1 deletion lib/adodb/drivers/adodb-ldap.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ function _connect( $host, $username, $password, $ldapbase)
if ($this->debug) ADOConnection::outp($e);
return false;
}
if( count( $LDAP_CONNECT_OPTIONS ) > 0 ) {
if(!empty($LDAP_CONNECT_OPTIONS)) {
$this->_inject_bind_options( $LDAP_CONNECT_OPTIONS );
}

Expand Down
Loading

0 comments on commit 23bdc3a

Please sign in to comment.