Skip to content

Commit

Permalink
Remove deprecated $databaseName property
Browse files Browse the repository at this point in the history
ADOConnection::$databaseName was marked as obsolete in ADOdb 4.66.

Since the assignment that was kept for backwards-compatibility in the
ADOConnection::selectDB() method is causing deprecation warnings with
PHP 8.2, now is the time to get rid of it.

The 2018 rewrite of DB2 driver introduced a private $databaseName
property; this has been removed in favor of ADOConnection::$database.

Fixes #932, #904

Signed-off-by: Damien Regad <dregad@mantisbt.org>
  • Loading branch information
dregad committed Mar 12, 2023
1 parent 92cf726 commit e475b4c
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 28 deletions.
9 changes: 8 additions & 1 deletion adodb.inc.php
Expand Up @@ -458,7 +458,14 @@ abstract class ADOConnection {
//
var $dataProvider = 'native';
var $databaseType = ''; /// RDBMS currently in use, eg. odbc, mysql, mssql
var $database = ''; /// Name of database to be used.

/**
* @var string Current database name.
*
* This used to be stored in the $databaseName property, which was marked
* as deprecated in 4.66 and removed in 5.22.5.
*/
public $database = '';

/**
* @var string If the driver is PDO, then the dsnType is e.g. sqlsrv, otherwise empty
Expand Down
31 changes: 13 additions & 18 deletions drivers/adodb-db2.inc.php
Expand Up @@ -82,11 +82,6 @@ class ADODB_db2 extends ADOConnection {
*/
public $connectStmt = '';

/*
* Holds the current database name
*/
private $databaseName = '';

/*
* Holds information about the stored procedure request
* currently being built
Expand All @@ -113,7 +108,7 @@ public function _pconnect($argDSN, $argUsername, $argPassword, $argDatabasename)

private function doDB2Connect($argDSN, $argUsername, $argPassword, $argDatabasename, $persistent=false)
{

if (!function_exists('db2_connect')) {
ADOConnection::outp("DB2 extension not installed.");
return null;
Expand Down Expand Up @@ -184,7 +179,7 @@ private function doDB2Connect($argDSN, $argUsername, $argPassword, $argDatabasen
null,
$db2Options);


$this->_errorMsg = @db2_conn_errormsg();

if ($this->_connectionID && $this->connectStmt)
Expand All @@ -207,7 +202,7 @@ private function doDB2Connect($argDSN, $argUsername, $argPassword, $argDatabasen
private function unpackParameters($argDSN, $argUsername, $argPassword, $argDatabasename)
{


$connectionParameters = array('dsn'=>'',
'uid'=>'',
'pwd'=>'',
Expand Down Expand Up @@ -257,7 +252,7 @@ private function unpackParameters($argDSN, $argUsername, $argPassword, $argDatab
$errorMessage = 'Supply uncatalogued connection parameters ';
$errorMessage.= 'in either the database or DSN arguments, ';
$errorMessage.= 'but not both';

if ($this->debug)
ADOConnection::outp($errorMessage);
return null;
Expand All @@ -282,7 +277,7 @@ private function unpackParameters($argDSN, $argUsername, $argPassword, $argDatab
{
$errorMessage = 'For uncatalogued connections, provide ';
$errorMessage.= 'both UID and PWD in the connection string';

if ($this->debug)
ADOConnection::outp($errorMessage);
return null;
Expand All @@ -307,7 +302,7 @@ private function unpackParameters($argDSN, $argUsername, $argPassword, $argDatab
}
elseif ($argDatabasename)
{
$this->databaseName = $argDatabasename;
$this->database = $argDatabasename;
$argDSN .= ';database=' . $argDatabasename;
$argDatabasename = '';
$useCataloguedConnection = false;
Expand All @@ -317,7 +312,7 @@ private function unpackParameters($argDSN, $argUsername, $argPassword, $argDatab
{
$errorMessage = 'Uncatalogued connection parameters ';
$errorMessage.= 'must contain a database= argument';

if ($this->debug)
ADOConnection::outp($errorMessage);
return null;
Expand Down Expand Up @@ -347,9 +342,9 @@ private function unpackParameters($argDSN, $argUsername, $argPassword, $argDatab
}

if ($argDatabasename)
$this->databaseName = $argDatabasename;
elseif (!$this->databaseName)
$this->databaseName = $this->getDatabasenameFromDsn($argDSN);
$this->database = $argDatabasename;
elseif (!$this->database)
$this->database = $this->getDatabasenameFromDsn($argDSN);


$connectionParameters = array('dsn'=>$argDSN,
Expand Down Expand Up @@ -1003,7 +998,7 @@ public function metaProcedures($procedureNamePattern = null, $catalog = null, $
*/
public function metaDatabases(){

$dbName = $this->getMetaCasedValue($this->databaseName);
$dbName = $this->getMetaCasedValue($this->database);

return (array)$dbName;

Expand Down Expand Up @@ -1618,10 +1613,10 @@ function _query(&$sql,$inputarr=false)
{
$this->_errorMsg = @db2_stmt_errormsg();
$this->_errorCode = @db2_stmt_error();

if ($this->debug)
ADOConnection::outp($this->_errorMsg);

return false;
}
}
Expand Down
1 change: 0 additions & 1 deletion drivers/adodb-mssql.inc.php
Expand Up @@ -541,7 +541,6 @@ function MetaTables($ttype=false,$showSchema=false,$mask=false)
function SelectDB($dbName)
{
$this->database = $dbName;
$this->databaseName = $dbName; # obsolete, retained for compat with older adodb versions
if ($this->_connectionID) {
return @mssql_select_db($dbName);
}
Expand Down
1 change: 0 additions & 1 deletion drivers/adodb-mssqlnative.inc.php
Expand Up @@ -440,7 +440,6 @@ function RowLock($tables,$where,$col='1 as adodbignore')
function SelectDB($dbName)
{
$this->database = $dbName;
$this->databaseName = $dbName; # obsolete, retained for compat with older adodb versions
if ($this->_connectionID) {
$rs = $this->Execute('USE '.$dbName);
if($rs) {
Expand Down
3 changes: 1 addition & 2 deletions drivers/adodb-mysqli.inc.php
Expand Up @@ -932,7 +932,7 @@ function MetaColumns($table, $normalize = true)

$SQL = "SELECT column_name, column_type
FROM information_schema.columns
WHERE table_schema='{$this->databaseName}'
WHERE table_schema='{$this->database}'
AND table_name='$table'";

$schemaArray = $this->getAssoc($SQL);
Expand Down Expand Up @@ -1017,7 +1017,6 @@ function SelectDB($dbName)
{
// $this->_connectionID = $this->mysqli_resolve_link($this->_connectionID);
$this->database = $dbName;
$this->databaseName = $dbName; # obsolete, retained for compat with older adodb versions

if ($this->_connectionID) {
$result = @mysqli_select_db($this->_connectionID, $dbName);
Expand Down
1 change: 0 additions & 1 deletion drivers/adodb-odbtp.inc.php
Expand Up @@ -304,7 +304,6 @@ function SelectDB($dbName)
return false;
}
$this->database = $dbName;
$this->databaseName = $dbName; # obsolete, retained for compat with older adodb versions
return true;
}

Expand Down
5 changes: 2 additions & 3 deletions drivers/adodb-pdo_mysql.inc.php
Expand Up @@ -57,7 +57,7 @@ function OffsetDate($dayFraction, $date=false)
return $date . ' + INTERVAL ' . $fraction . ' SECOND';
// return "from_unixtime(unix_timestamp($date)+$fraction)";
}

/**
* Get a list of indexes on the specified table.
*
Expand Down Expand Up @@ -266,7 +266,6 @@ function MetaColumns($table, $normalize=true)
function SelectDB($dbName)
{
$this->database = $dbName;
$this->databaseName = $dbName; # obsolete, retained for compat with older adodb versions
$try = $this->Execute('use ' . $dbName);
return ($try !== false);
}
Expand All @@ -275,7 +274,7 @@ function SelectDB($dbName)
function SelectLimit($sql, $nrows=-1, $offset=-1, $inputarr=false, $secs=0)
{
$nrows = (int) $nrows;
$offset = (int) $offset;
$offset = (int) $offset;
$offsetStr =($offset>=0) ? "$offset," : '';
// jason judge, see PHPLens Issue No: 9220
if ($nrows < 0) {
Expand Down
1 change: 0 additions & 1 deletion drivers/adodb-sybase.inc.php
Expand Up @@ -104,7 +104,6 @@ function RowLock($tables,$where,$col='top 1 null as ignore')
function SelectDB($dbName)
{
$this->database = $dbName;
$this->databaseName = $dbName; # obsolete, retained for compat with older adodb versions
if ($this->_connectionID) {
return @sybase_select_db($dbName);
}
Expand Down

0 comments on commit e475b4c

Please sign in to comment.