View Issue Details

IDProjectCategoryView StatusLast Update
0006892OXID eShop (all versions)4.01. Database handlingpublic2018-08-21 10:58
Reportertimwetter 
PrioritynormalSeveritymajorReproducibilityalways
Status acknowledgedResolutionopen 
Product Version6.1.0 
Target VersionFixed in Version 
Summary0006892: oxDB:: quoteArray & getTableDescription breaks $ADODB_FETCH_MODE
Descriptionthere are many ways to break db fetch_mode, but one example

do this in one function:
- on top write $oDb = oxDb::getDb(true);
- make a oxlist
- call selectString with a wildcard (e.g. "select * from oxarticles limit 55")
- after that do something like this in the same function:
$rs = $oDb->execute("select oxartnum, oxtitle from oxarticles");
            if ($rs != false && $rs->recordCount() > 0) {
                while (!$rs->EOF) {
                      print_r($rs->fields) // look at the numeric fields -> but they should be assoc
                }
             }

please have a look @"additional information" to see my fix for this
maybe you'll find more of this bullsh*

Additional Information    /**
     * Quotes an array.
     *
     * @param array $aStrArray array of strings to quote
     *
     * @return array
     */
    public function quoteArray( $aStrArray)
    {
        global $ADODB_FETCH_MODE;
        $save = $ADODB_FETCH_MODE;

        foreach ( $aStrArray as $sKey => $sString ) {
            $aStrArray[$sKey] = self::getDb()->quote($sString);
        }

        // restore fetchmode
        $ADODB_FETCH_MODE = $save;

        return $aStrArray;
    }

    /**
     * Extracts and returns table metadata from DB.
     *
     * @param string $sTableName Name of table to invest.
     *
     * @return array
     */
    public function getTableDescription( $sTableName )
    {
        // simple cache
        if ( isset( self::$_aTblDescCache[$sTableName] ) ) {
            return self::$_aTblDescCache[$sTableName];
        }

        global $ADODB_FETCH_MODE;
        $save = $ADODB_FETCH_MODE;

        $aFields = self::getDb()->MetaColumns( $sTableName );

        // restore fetchmode
        $ADODB_FETCH_MODE = $save;

        self::$_aTblDescCache[$sTableName] = $aFields;

        return $aFields;
    }
TagsNo tags attached.
ThemeNot defined
BrowserNot defined
PHP VersionNot defined
MySQL VersionNot defined

Relationships

duplicate of 0005755 closedQA Fetch mode not always set to proper one 

Activities

QA

2018-08-21 10:55

administrator   ~0012589

Last edited: 2018-08-21 10:58

View 3 revisions

Script to reproduce (execute it in bin/):
<?php

echo PHP_EOL . 'fetch mode test.' . PHP_EOL;

require_once '../bootstrap.php';

$db = \OxidEsales\Eshop\Core\DatabaseProvider::getDb();


echo 'set fetch mode to assoc (equals string)'; 
echo PHP_EOL;
$db->setFetchMode(\OxidEsales\Eshop\Core\Database\Adapter\DatabaseInterface::FETCH_MODE_ASSOC);


$query = 'select oxid from oxuser limit 1';

$a = $db->getAll($query);
echo 'get fetch mode: ';
echo gettype(key($a[0]));
echo PHP_EOL;


echo 'execute some native methods... ';
echo PHP_EOL;

$c = oxNew(\OxidEsales\Eshop\Application\Model\Category::class);
$c->load('0f40c6a077b68c21f164767c4a903fd2');
$s = oxNew(\OxidEsales\Eshop\Application\Model\SeoEncoderCategory::class);
$s->markRelatedAsExpired($c);


$a = $db->getAll($query);
echo 'get fetch mode: ';
echo gettype(key($a[0]));
echo PHP_EOL;

echo 'test done.' . PHP_EOL;

MK