Skip to content

Commit

Permalink
Set $fetchMode property in ADORecordSet constructor
Browse files Browse the repository at this point in the history
This reduces code duplication as the logic to initialize $fetchMode from
$ADODB_FETCH_MODE global was repeated in most drivers.

$adodbFetchMode is systematically initialized as well now; previously it
was only set in those drivers having specific fetch modes.

Fixes #958
  • Loading branch information
dregad committed Apr 16, 2023
1 parent 5e734b0 commit ce236b1
Show file tree
Hide file tree
Showing 22 changed files with 83 additions and 216 deletions.
21 changes: 15 additions & 6 deletions adodb.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -4014,7 +4014,7 @@ class ADORecordSet implements IteratorAggregate {
var $timeCreated=0; /// datetime in Unix format rs created -- for cached recordsets

var $bind = false; /// used by Fields() to hold array - should be private?
var $fetchMode; /// default fetch mode
/** @var ADOConnection The parent connection */
var $connection = false;
/**
Expand Down Expand Up @@ -4063,6 +4063,11 @@ class ADORecordSet implements IteratorAggregate {
*/
protected $fieldObjectsIndex = array();

/**
* @var bool|int Driver-specific fetch mode
*/
var $fetchMode;

/**
* @var int Defines the Fetch Mode for a recordset
* See the ADODB_FETCH_* constants
Expand All @@ -4075,7 +4080,13 @@ class ADORecordSet implements IteratorAggregate {
* @param resource|int $queryID Query ID returned by ADOConnection->_query()
* @param int|bool $mode The ADODB_FETCH_MODE value
*/
function __construct($queryID,$mode=false) {
function __construct($queryID, $mode=false) {
if ($mode === false) {
global $ADODB_FETCH_MODE;
$mode = $ADODB_FETCH_MODE;
}
$this->adodbFetchMode = $this->fetchMode = $mode;

$this->_queryID = $queryID;
}

Expand Down Expand Up @@ -5295,15 +5306,13 @@ class ADORecordSet_array extends ADORecordSet
* @param int|bool $mode The ADODB_FETCH_MODE value
*/
function __construct($queryID, $mode=false) {
global $ADODB_FETCH_MODE,$ADODB_COMPAT_FETCH;
parent::__construct(self::DUMMY_QUERY_ID);

// fetch() on EOF does not delete $this->fields
global $ADODB_COMPAT_FETCH;
$this->compat = !empty($ADODB_COMPAT_FETCH);
parent::__construct($queryID); // fake queryID
$this->fetchMode = $ADODB_FETCH_MODE;
}


/**
* Setup the array.
*
Expand Down
10 changes: 0 additions & 10 deletions drivers/adodb-ado.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -349,16 +349,6 @@ class ADORecordSet_ado extends ADORecordSet {
var $canSeek = true;
var $hideErrors = true;

function __construct($id,$mode=false)
{
if ($mode === false) {
global $ADODB_FETCH_MODE;
$mode = $ADODB_FETCH_MODE;
}
$this->fetchMode = $mode;
parent::__construct($id);
}


// returns the field object
function FetchField($fieldOffset = -1) {
Expand Down
10 changes: 0 additions & 10 deletions drivers/adodb-ado5.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -383,16 +383,6 @@ class ADORecordSet_ado extends ADORecordSet {
var $canSeek = true;
var $hideErrors = true;

function __construct($id,$mode=false)
{
if ($mode === false) {
global $ADODB_FETCH_MODE;
$mode = $ADODB_FETCH_MODE;
}
$this->fetchMode = $mode;
parent::__construct($id);
}


// returns the field object
function FetchField($fieldOffset = -1) {
Expand Down
11 changes: 2 additions & 9 deletions drivers/adodb-ads.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -685,20 +685,13 @@ class ADORecordSet_ads extends ADORecordSet
var $dataProvider = "ads";
var $useFetchArray;

function __construct($id, $mode = false)
function __construct($queryID, $mode = false)
{
if ($mode === false) {
global $ADODB_FETCH_MODE;
$mode = $ADODB_FETCH_MODE;
}
$this->fetchMode = $mode;

$this->_queryID = $id;
parent::__construct($queryID, $mode);

// the following is required for mysql odbc driver in 4.3.1 -- why?
$this->EOF = false;
$this->_currentRow = -1;
//parent::__construct($id);
}


Expand Down
11 changes: 0 additions & 11 deletions drivers/adodb-db2.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -1832,17 +1832,6 @@ class ADORecordSet_db2 extends ADORecordSet {
var $dataProvider = "db2";
var $useFetchArray;

function __construct($id,$mode=false)
{
if ($mode === false) {
global $ADODB_FETCH_MODE;
$mode = $ADODB_FETCH_MODE;
}
$this->fetchMode = $mode;

$this->_queryID = $id;
}


// returns the field object
function fetchField($offset = 0)
Expand Down
24 changes: 13 additions & 11 deletions drivers/adodb-fbsql.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -170,20 +170,22 @@ class ADORecordSet_fbsql extends ADORecordSet{
var $databaseType = "fbsql";
var $canSeek = true;

function __construct($queryID,$mode=false)
function __construct($queryID, $mode=false)
{
if (!$mode) {
global $ADODB_FETCH_MODE;
$mode = $ADODB_FETCH_MODE;
}
parent::__construct($queryID, $mode);

switch ($mode) {
case ADODB_FETCH_NUM: $this->fetchMode = FBSQL_NUM; break;
case ADODB_FETCH_ASSOC: $this->fetchMode = FBSQL_ASSOC; break;
case ADODB_FETCH_BOTH:
default:
$this->fetchMode = FBSQL_BOTH; break;
case ADODB_FETCH_NUM:
$this->fetchMode = FBSQL_NUM;
break;
case ADODB_FETCH_ASSOC:
$this->fetchMode = FBSQL_ASSOC;
break;
case ADODB_FETCH_BOTH:
default:
$this->fetchMode = FBSQL_BOTH;
break;
}
parent::__construct($queryID);
}

function _initrs()
Expand Down
8 changes: 0 additions & 8 deletions drivers/adodb-firebird.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -1024,14 +1024,6 @@ class ADORecordset_firebird extends ADORecordSet
*/
private $fieldObjectsHaveBlob = false;

function __construct($id, $mode = false)
{
global $ADODB_FETCH_MODE;

$this->fetchMode = ($mode === false) ? $ADODB_FETCH_MODE : $mode;
parent::__construct($id);
}


/**
* Returns: an object containing field information.
Expand Down
7 changes: 0 additions & 7 deletions drivers/adodb-ibase.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -741,13 +741,6 @@ class ADORecordset_ibase extends ADORecordSet
var $bind=false;
var $_cacheType;

function __construct($id,$mode=false)
{
global $ADODB_FETCH_MODE;

$this->fetchMode = ($mode === false) ? $ADODB_FETCH_MODE : $mode;
parent::__construct($id);
}

/* Returns: an object containing field information.
Get column information in the Recordset object. fetchField() can be used in order to obtain information about
Expand Down
11 changes: 0 additions & 11 deletions drivers/adodb-informix72.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -400,17 +400,6 @@ class ADORecordset_informix72 extends ADORecordSet {
var $canSeek = true;
var $_fieldprops = false;

function __construct($id,$mode=false)
{
if ($mode === false) {
global $ADODB_FETCH_MODE;
$mode = $ADODB_FETCH_MODE;
}
$this->fetchMode = $mode;
parent::__construct($id);
}



/* Returns: an object containing field information.
Get column information in the Recordset object. fetchField() can be used in order to obtain information about
Expand Down
35 changes: 15 additions & 20 deletions drivers/adodb-ldap.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -296,28 +296,23 @@ class ADORecordSet_ldap extends ADORecordSet{
var $canSeek = false;
var $_entryID; /* keeps track of the entry resource identifier */

function __construct($queryID,$mode=false)
function __construct($queryID, $mode=false)
{
if ($mode === false) {
global $ADODB_FETCH_MODE;
$mode = $ADODB_FETCH_MODE;
}
switch ($mode)
{
case ADODB_FETCH_NUM:
$this->fetchMode = LDAP_NUM;
break;
case ADODB_FETCH_ASSOC:
$this->fetchMode = LDAP_ASSOC;
break;
case ADODB_FETCH_DEFAULT:
case ADODB_FETCH_BOTH:
default:
$this->fetchMode = LDAP_BOTH;
break;
}
parent::__construct($queryID, $mode);

parent::__construct($queryID);
switch ($mode) {
case ADODB_FETCH_NUM:
$this->fetchMode = LDAP_NUM;
break;
case ADODB_FETCH_ASSOC:
$this->fetchMode = LDAP_ASSOC;
break;
case ADODB_FETCH_DEFAULT:
case ADODB_FETCH_BOTH:
default:
$this->fetchMode = LDAP_BOTH;
break;
}
}

function _initrs()
Expand Down
12 changes: 3 additions & 9 deletions drivers/adodb-mssql.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -858,18 +858,12 @@ class ADORecordset_mssql extends ADORecordSet {
var $hasFetchAssoc; // see PHPLens Issue No: 6083
// _mths works only in non-localised system

function __construct($id,$mode=false)
function __construct($queryID, $mode=false)
{
parent::__construct($queryID, $mode);

// freedts check...
$this->hasFetchAssoc = function_exists('mssql_fetch_assoc');

if ($mode === false) {
global $ADODB_FETCH_MODE;
$mode = $ADODB_FETCH_MODE;

}
$this->fetchMode = $mode;
return parent::__construct($id);
}


Expand Down
14 changes: 0 additions & 14 deletions drivers/adodb-mssqlnative.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -1084,20 +1084,6 @@ class ADORecordset_mssqlnative extends ADORecordSet {
);




function __construct($id,$mode=false)
{
if ($mode === false) {
global $ADODB_FETCH_MODE;
$mode = $ADODB_FETCH_MODE;

}
$this->fetchMode = $mode;
parent::__construct($id);
}


function _initrs()
{
$this->_numOfRows = -1;//not supported
Expand Down
7 changes: 1 addition & 6 deletions drivers/adodb-mysqli.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -1406,10 +1406,7 @@ class ADORecordSet_mysqli extends ADORecordSet{

function __construct($queryID, $mode = false)
{
if ($mode === false) {
global $ADODB_FETCH_MODE;
$mode = $ADODB_FETCH_MODE;
}
parent::__construct($queryID, $mode);

switch ($mode) {
case ADODB_FETCH_NUM:
Expand All @@ -1424,8 +1421,6 @@ function __construct($queryID, $mode = false)
$this->fetchMode = MYSQLI_BOTH;
break;
}
$this->adodbFetchMode = $mode;
parent::__construct($queryID);
}

function _initrs()
Expand Down
10 changes: 3 additions & 7 deletions drivers/adodb-oci8.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -1625,12 +1625,10 @@ class ADORecordset_oci8 extends ADORecordSet {
/** @var resource Cursor reference */
var $_refcursor;

function __construct($queryID,$mode=false)
function __construct($queryID, $mode=false)
{
if ($mode === false) {
global $ADODB_FETCH_MODE;
$mode = $ADODB_FETCH_MODE;
}
parent::__construct($queryID, $mode);

switch ($mode) {
case ADODB_FETCH_ASSOC:
$this->fetchMode = OCI_ASSOC;
Expand All @@ -1645,8 +1643,6 @@ function __construct($queryID,$mode=false)
break;
}
$this->fetchMode += OCI_RETURN_NULLS + OCI_RETURN_LOBS;
$this->adodbFetchMode = $mode;
$this->_queryID = $queryID;
}

/**
Expand Down
11 changes: 2 additions & 9 deletions drivers/adodb-odbc.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -614,20 +614,13 @@ class ADORecordSet_odbc extends ADORecordSet {
var $dataProvider = "odbc";
var $useFetchArray;

function __construct($id,$mode=false)
function __construct($queryID, $mode=false)
{
if ($mode === false) {
global $ADODB_FETCH_MODE;
$mode = $ADODB_FETCH_MODE;
}
$this->fetchMode = $mode;

$this->_queryID = $id;
parent::__construct($queryID, $mode);

// the following is required for mysql odbc driver in 4.3.1 -- why?
$this->EOF = false;
$this->_currentRow = -1;
//parent::__construct($id);
}


Expand Down
9 changes: 0 additions & 9 deletions drivers/adodb-odbtp.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -684,15 +684,6 @@ class ADORecordSet_odbtp extends ADORecordSet {
var $databaseType = 'odbtp';
var $canSeek = true;

function __construct($queryID,$mode=false)
{
if ($mode === false) {
global $ADODB_FETCH_MODE;
$mode = $ADODB_FETCH_MODE;
}
$this->fetchMode = $mode;
parent::__construct($queryID);
}

function _initrs()
{
Expand Down
Loading

0 comments on commit ce236b1

Please sign in to comment.