Fixed bug #15160: Queries should only be parsed once
authorXavier Perseguers <typo3@perseguers.ch>
Tue, 27 Jul 2010 06:05:33 +0000 (06:05 +0000)
committerXavier Perseguers <typo3@perseguers.ch>
Tue, 27 Jul 2010 06:05:33 +0000 (06:05 +0000)
git-svn-id: https://svn.typo3.org/TYPO3v4/Extensions/dbal/trunk@36076 735d13b6-9817-0410-8766-e36946ffe9aa

typo3/sysext/dbal/ChangeLog
typo3/sysext/dbal/class.ux_t3lib_db.php
typo3/sysext/dbal/tests/dbMssqlTest.php
typo3/sysext/dbal/tests/dbOracleTest.php

index ac96f90..8b0654f 100644 (file)
@@ -1,3 +1,7 @@
+2010-07-27  Xavier Perseguers  <typo3@perseguers.ch>
+
+       * Fixed bug #15160: Queries should only be parsed once
+
 2010-07-17  Xavier Perseguers  <typo3@perseguers.ch>
 
        * Updated PHP documentation
index 346c991..e841029 100644 (file)
@@ -690,8 +690,11 @@ class ux_t3lib_DB extends t3lib_DB {
 
                        // Map table / field names if needed:
                $ORIG_tableName = $from_table;  // Saving table names in $ORIG_from_table since $from_table is transformed beneath:
-               if ($tableArray = $this->map_needMapping($ORIG_tableName)) {
-                       $this->map_remapSELECTQueryParts($select_fields,$from_table,$where_clause,$groupBy,$orderBy);   // Variables passed by reference!
+               $parsedFromTable = array();
+               $remappedParameters = array();
+               if ($tableArray = $this->map_needMapping($ORIG_tableName, FALSE, $parsedFromTable)) {
+                       $from = $parsedFromTable ? $parsedFromTable : $from_table;
+                       $remappedParameters = $this->map_remapSELECTQueryParts($select_fields, $from, $where_clause, $groupBy, $orderBy);
                }
 
                        // Get handler key and select API:
@@ -699,7 +702,10 @@ class ux_t3lib_DB extends t3lib_DB {
                $hType = (string)$this->handlerCfg[$this->lastHandlerKey]['type'];
                switch ($hType) {
                        case 'native':
-                               $this->lastQuery = $this->SELECTquery($select_fields,$from_table,$where_clause,$groupBy,$orderBy,$limit);
+                               if (count($remappedParameters) > 0) {
+                                       list($select_fields, $from_table, $where_clause, $groupBy, $orderBy) = $this->compileSelectParameters($remappedParameters);
+                               }
+                               $this->lastQuery = $this->SELECTquery($select_fields, $from_table, $where_clause, $groupBy, $orderBy, $limit);
                                $sqlResult = mysql_query($this->lastQuery, $this->handlerInstance[$this->lastHandlerKey]['link']);
                                $this->resourceIdToTableNameMap[(string)$sqlResult] = $ORIG_tableName;
                                break;
@@ -714,10 +720,18 @@ class ux_t3lib_DB extends t3lib_DB {
                                                $offset = 0;
                                        }
 
-                                       $sqlResult = $this->handlerInstance[$this->lastHandlerKey]->SelectLimit($this->SELECTquery($select_fields,$from_table,$where_clause,$groupBy,$orderBy), $numrows, $offset);
+                                       if (count($remappedParameters) > 0) {
+                                               $sqlResult = $this->handlerInstance[$this->lastHandlerKey]->SelectLimit($this->SELECTqueryFromArray($remappedParameters), $numrows, $offset);
+                                       } else {
+                                               $sqlResult = $this->handlerInstance[$this->lastHandlerKey]->SelectLimit($this->SELECTquery($select_fields, $from_table, $where_clause, $groupBy, $orderBy), $numrows, $offset);
+                                       }
                                        $this->lastQuery = $sqlResult->sql;
                                } else {
-                                       $this->lastQuery = $this->SELECTquery($select_fields,$from_table,$where_clause,$groupBy,$orderBy);
+                                       if (count($remappedParameters) > 0) {
+                                               $this->lastQuery = $this->SELECTqueryFromArray($remappedParameters);
+                                       } else {
+                                               $this->lastQuery = $this->SELECTquery($select_fields, $from_table, $where_clause, $groupBy, $orderBy);
+                                       }
                                        $sqlResult = $this->handlerInstance[$this->lastHandlerKey]->_Execute($this->lastQuery);
                                }
 
@@ -725,7 +739,10 @@ class ux_t3lib_DB extends t3lib_DB {
                                $sqlResult->TYPO3_DBAL_tableList = $ORIG_tableName;
                                break;
                        case 'userdefined':
-                               $sqlResult = $this->handlerInstance[$this->lastHandlerKey]->exec_SELECTquery($select_fields,$from_table,$where_clause,$groupBy,$orderBy,$limit);
+                               if (count($remappedParameters) > 0) {
+                                       list($select_fields, $from_table, $where_clause, $groupBy, $orderBy) = $this->compileSelectParameters($remappedParameters);
+                               }
+                               $sqlResult = $this->handlerInstance[$this->lastHandlerKey]->exec_SELECTquery($select_fields, $from_table, $where_clause, $groupBy, $orderBy, $limit);
                                if (is_object($sqlResult)) {
                                        $sqlResult->TYPO3_DBAL_handlerType = 'userdefined';     // Setting handler type in result object (for later recognition!)
                                        $sqlResult->TYPO3_DBAL_tableList = $ORIG_tableName;
@@ -1131,6 +1148,60 @@ class ux_t3lib_DB extends t3lib_DB {
        }
 
        /**
+        * Creates a SELECT SQL-statement to be used with an ADOdb backend. 
+        *
+        * @param       array           parsed parameters: array($select_fields, $from_table, $where_clause, $groupBy, $orderBy)
+        * @return      string          Full SQL query for SELECT
+        */
+       protected function SELECTqueryFromArray(array $params) {
+                       // $select_fields
+               $params[0] = $this->_quoteFieldNames($params[0]);
+                       // $from_table
+               $params[1] = $this->_quoteFromTables($params[1]);
+                       // $where_clause
+               if (count($params[2]) > 0) {
+                       $params[2] = $this->_quoteWhereClause($params[2]);
+               }
+                       // $group_by
+               if (count($params[3]) > 0) {
+                       $params[3] = $this->_quoteGroupBy($params[3]);
+               }
+                       // $order_by
+               if (count($params[4]) > 0) {
+                       $params[4] = $this->_quoteOrderBy($params[4]);
+               }
+
+                       // Compile the SELECT parameters
+               list($select_fields, $from_table, $where_clause, $groupBy, $orderBy) = $this->compileSelectParameters($params);
+
+                       // Call parent method to build actual query
+               $query = parent::SELECTquery($select_fields, $from_table, $where_clause, $groupBy, $orderBy);
+
+               if ($this->debugOutput || $this->store_lastBuiltQuery) {
+                       $this->debug_lastBuiltQuery = $query;
+               }
+
+               return $query;
+       }
+
+       /**
+        * Compiles and returns an array of SELECTquery parameters (without $limit) to
+        * be used with SELECTquery() or exec_SELECTquery().
+        *
+        * @param array $params
+        * @return array array($select_fields, $from_table, $where_clause, $groupBy, $orderBy)
+        */
+       protected function compileSelectParameters(array $params) {
+               $select_fields = $this->SQLparser->compileFieldList($params[0]);
+               $from_table = $this->SQLparser->compileFromTables($params[1]);
+               $where_clause = (count($params[2]) > 0) ? $this->SQLparser->compileWhereClause($params[2]) : '';
+               $groupBy = (count($params[3]) > 0) ? $this->SQLparser->compileFieldList($params[3]) : '';
+               $orderBy = (count($params[4]) > 0) ? $this->SQLparser->compileFieldList($params[4]) : '';
+
+               return array($select_fields, $from_table, $where_clause, $groupBy, $orderBy);
+       }
+
+       /**
         * Creates a TRUNCATE TABLE SQL-statement
         * 
         * @param       string          See exec_TRUNCATEquery()
@@ -1380,24 +1451,37 @@ class ux_t3lib_DB extends t3lib_DB {
        }
 
        /**
-        * Quotes field names in a SQL GROUP BY clause acccording to DB rules
+        * Quotes the field (and table) names within a group by clause with the quote
+        * character suitable for the DB being used
         *
-        * @param       array           $groupBy The parsed GROUP BY clause to quote
-        * @return      array
-        * @see quoteGroupBy()
+        * @param       string          A group by clause that can by parsed by parseFieldList
+        * @return      string          Usable group by clause with quoted field/table names
         */
        protected function quoteGroupBy($groupBy) {
                if ($groupBy === '') return '';
                if ($this->runningNative()) return $groupBy;
 
                $groupBy = $this->SQLparser->parseFieldList($groupBy);
+               $groupBy = $this->_quoteGroupBy($groupBy);
+
+               return $this->SQLparser->compileFieldList($groupBy);
+       }
+
+       /**
+        * Quotes field names in a SQL GROUP BY clause acccording to DB rules
+        *
+        * @param       array           $groupBy The parsed GROUP BY clause to quote
+        * @return      array
+        * @see quoteGroupBy()
+        */
+       protected function _quoteGroupBy(array $groupBy) {
                foreach ($groupBy as $k => $v) {
                        $groupBy[$k]['field'] = $this->quoteName($groupBy[$k]['field']);
                        if ($groupBy[$k]['table'] != '') {
                                $groupBy[$k]['table'] = $this->quoteName($groupBy[$k]['table']);
                        }
                }
-               return $this->SQLparser->compileFieldList($groupBy);
+               return $groupBy;
        }
 
        /**
@@ -1412,17 +1496,29 @@ class ux_t3lib_DB extends t3lib_DB {
                if ($this->runningNative()) return $orderBy;
 
                $orderBy = $this->SQLparser->parseFieldList($orderBy);
+               $orderBy = $this->_quoteOrderBy($orderBy);
+
+               return $this->SQLparser->compileFieldList($orderBy);
+       }
+
+       /**
+        * Quotes field names in a SQL ORDER BY clause acccording to DB rules
+        *
+        * @param       array           $orderBy The parsed ORDER BY clause to quote
+        * @return      array
+        * @see quoteOrderBy()
+        */
+       protected function _quoteOrderBy(array $orderBy) {
                foreach ($orderBy as $k => $v) {
                        $orderBy[$k]['field'] = $this->quoteName($orderBy[$k]['field']);
                        if ($orderBy[$k]['table'] != '') {
                                $orderBy[$k]['table'] = $this->quoteName($orderBy[$k]['table']);
                        }
                }
-               return $this->SQLparser->compileFieldList($orderBy);
+               return $orderBy;
        }
 
 
-
        /**************************************
        *
        * Various helper functions
@@ -2679,15 +2775,17 @@ class ux_t3lib_DB extends t3lib_DB {
         *
         * @param       string          List of tables in query
         * @param       boolean         If TRUE, it will check only if FIELDs are configured and ignore the mapped table name if any.
+        * @param       array           Parsed list of tables, should be passed as reference to be reused and prevent double parsing 
         * @return      mixed           Returns an array of table names (parsed version of input table) if mapping is needed, otherwise just FALSE.
         */
-       protected function map_needMapping($tableList, $fieldMappingOnly = FALSE) {
+       protected function map_needMapping($tableList, $fieldMappingOnly = FALSE, array &$parsedTableList = array()) {
                $key = $tableList.'|'.$fieldMappingOnly;
                if (!isset($this->cache_mappingFromTableList[$key])) {
                        $this->cache_mappingFromTableList[$key] = FALSE;        // Default:
 
                        $tables = $this->SQLparser->parseFromTables($tableList);
                        if (is_array($tables)) {
+                               $parsedTableList = $tables;
                                foreach ($tables as $tableCfg) {
                                        if ($fieldMappingOnly) {
                                                if (is_array($this->mapping[$tableCfg['table']]['mapFieldNames'])) {
@@ -2769,9 +2867,8 @@ class ux_t3lib_DB extends t3lib_DB {
 
        /**
         * Remaps table/field names in a SELECT query's parts
-        * Notice: All arguments are passed by reference!
         *
-        * @param       string          List of fields to select from the table. This is what comes right after "SELECT ...". Required value.
+        * @param       mixed           Either parsed list of tables (SQLparser->parseFromTables()) or list of fields to select from the table. This is what comes right after "SELECT ...". Required value.
         * @param       string          Table(s) from which to select. This is what comes right after "FROM ...". Require value.
         * @param       string          Where clause. This is what comes right after "WHERE ...". Can be blank.
         * @param       string          Group by field(s)
@@ -2779,12 +2876,12 @@ class ux_t3lib_DB extends t3lib_DB {
         * @return      void
         * @see exec_SELECTquery()
         */
-       protected function map_remapSELECTQueryParts(&$select_fields, &$from_table, &$where_clause, &$groupBy, &$orderBy) {
+       protected function map_remapSELECTQueryParts($select_fields, $from_table, $where_clause, $groupBy, $orderBy) {
                        // Backup current mapping as it may be altered if aliases on mapped tables are found
                $backupMapping = $this->mapping;
 
                        // Tables:
-               $tables = $this->SQLparser->parseFromTables($from_table);
+               $tables = is_array($from_table) ? $from_table : $this->SQLparser->parseFromTables($from_table);
                $defaultTable = $tables[0]['table'];
                        // Prepare mapping for aliased tables. This will copy the definition of the original table name.
                        // The alias is prefixed with a database-incompatible character to prevent naming clash with real table name
@@ -2841,30 +2938,28 @@ class ux_t3lib_DB extends t3lib_DB {
                                }
                        }
                }
-               $from_table = $this->SQLparser->compileFromTables($tables);
+               $fromParts = $tables;
 
                        // Where clause:
                $whereParts = $this->SQLparser->parseWhereClause($where_clause);
-               $this->map_sqlParts($whereParts,$defaultTable);
-               $where_clause = $this->SQLparser->compileWhereClause($whereParts, FALSE);
+               $this->map_sqlParts($whereParts, $defaultTable);
 
                        // Select fields:
-               $expFields = $this->SQLparser->parseFieldList($select_fields);
-               $this->map_sqlParts($expFields,$defaultTable);
-               $select_fields = $this->SQLparser->compileFieldList($expFields, FALSE, FALSE);
+               $selectParts = $this->SQLparser->parseFieldList($select_fields);
+               $this->map_sqlParts($selectParts, $defaultTable);
 
                        // Group By fields
-               $expFields = $this->SQLparser->parseFieldList($groupBy);
-               $this->map_sqlParts($expFields,$defaultTable);
-               $groupBy = $this->SQLparser->compileFieldList($expFields);
+               $groupByParts = $this->SQLparser->parseFieldList($groupBy);
+               $this->map_sqlParts($groupByParts, $defaultTable);
 
                        // Order By fields
-               $expFields = $this->SQLparser->parseFieldList($orderBy);
-               $this->map_sqlParts($expFields,$defaultTable);
-               $orderBy = $this->SQLparser->compileFieldList($expFields);
+               $orderByParts = $this->SQLparser->parseFieldList($orderBy);
+               $this->map_sqlParts($orderByParts, $defaultTable);
 
                        // Restore the original mapping
                $this->mapping = $backupMapping;
+
+               return array($selectParts, $fromParts, $whereParts, $groupByParts, $orderByParts);
        }
 
        /**
index 5776181..3c4a233 100644 (file)
@@ -157,8 +157,8 @@ class dbMssqlTest extends BaseTestCase {
                $groupBy      = '';
                $orderBy      = '';
 
-               $GLOBALS['TYPO3_DB']->_callRef('map_remapSELECTQueryParts', $selectFields, $fromTables, $whereClause, $groupBy, $orderBy);
-               $query = $this->cleanSql($GLOBALS['TYPO3_DB']->SELECTquery($selectFields, $fromTables, $whereClause, $groupBy, $orderBy));
+               $remappedParameters = $GLOBALS['TYPO3_DB']->_call('map_remapSELECTQueryParts', $selectFields, $fromTables, $whereClause, $groupBy, $orderBy);
+               $query = $this->cleanSql($GLOBALS['TYPO3_DB']->_call('SELECTqueryFromArray', $remappedParameters));
 
                $expected = 'SELECT "MemberID", "FirstName", "LastName" FROM "Members" WHERE 0 = 0 AND 1 = 1';
                $this->assertEquals($expected, $query);
@@ -216,8 +216,8 @@ class dbMssqlTest extends BaseTestCase {
                $groupBy      = '';
                $orderBy      = '';
 
-               $GLOBALS['TYPO3_DB']->_callRef('map_remapSELECTQueryParts', $selectFields, $fromTables, $whereClause, $groupBy, $orderBy);
-               $query = $this->cleanSql($GLOBALS['TYPO3_DB']->SELECTquery($selectFields, $fromTables, $whereClause, $groupBy, $orderBy));
+               $remappedParameters = $GLOBALS['TYPO3_DB']->_call('map_remapSELECTQueryParts', $selectFields, $fromTables, $whereClause, $groupBy, $orderBy);
+               $query = $this->cleanSql($GLOBALS['TYPO3_DB']->_call('SELECTqueryFromArray', $remappedParameters));
 
                $expected = 'SELECT *, CASE WHEN CHARINDEX(\'(fce)\', "ds", 4) > 0 THEN 2 ELSE 1 END AS "scope" FROM "tx_templavoila_tmplobj" WHERE 1 = 1';
                $this->assertEquals($expected, $query);
@@ -237,8 +237,8 @@ class dbMssqlTest extends BaseTestCase {
                $groupBy      = '';
                $orderBy      = '';
 
-               $GLOBALS['TYPO3_DB']->_callRef('map_remapSELECTQueryParts', $selectFields, $fromTables, $whereClause, $groupBy, $orderBy);
-               $query = $this->cleanSql($GLOBALS['TYPO3_DB']->SELECTquery($selectFields, $fromTables, $whereClause, $groupBy, $orderBy));
+               $remappedParameters = $GLOBALS['TYPO3_DB']->_call('map_remapSELECTQueryParts', $selectFields, $fromTables, $whereClause, $groupBy, $orderBy);
+               $query = $this->cleanSql($GLOBALS['TYPO3_DB']->_call('SELECTqueryFromArray', $remappedParameters));
 
                $expected = 'SELECT *, CASE WHEN CHARINDEX(\'(fce)\', "tx_templavoila_tmplobj"."ds", 4) > 0 THEN 2 ELSE 1 END AS "scope" FROM "tx_templavoila_tmplobj" WHERE 1 = 1';
                $this->assertEquals($expected, $query);
index 1f7fc92..42dae51 100644 (file)
@@ -362,8 +362,8 @@ class dbOracleTest extends BaseTestCase {
                $groupBy      = '';
                $orderBy      = '';
 
-               $GLOBALS['TYPO3_DB']->_callRef('map_remapSELECTQueryParts', $selectFields, $fromTables, $whereClause, $groupBy, $orderBy);
-               $query = $this->cleanSql($GLOBALS['TYPO3_DB']->SELECTquery($selectFields, $fromTables, $whereClause, $groupBy, $orderBy));
+               $remappedParameters = $GLOBALS['TYPO3_DB']->_call('map_remapSELECTQueryParts', $selectFields, $fromTables, $whereClause, $groupBy, $orderBy);
+               $query = $this->cleanSql($GLOBALS['TYPO3_DB']->_call('SELECTqueryFromArray', $remappedParameters));
 
                $expected = 'SELECT * FROM "ext_tt_news_cat"';
                $expected .= ' INNER JOIN "ext_tt_news_cat_mm" ON "ext_tt_news_cat"."cat_uid"="ext_tt_news_cat_mm"."uid_foreign"';
@@ -383,8 +383,8 @@ class dbOracleTest extends BaseTestCase {
                $groupBy      = '';
                $orderBy      = '';
 
-               $GLOBALS['TYPO3_DB']->_callRef('map_remapSELECTQueryParts', $selectFields, $fromTables, $whereClause, $groupBy, $orderBy);
-               $query = $this->cleanSql($GLOBALS['TYPO3_DB']->SELECTquery($selectFields, $fromTables, $whereClause, $groupBy, $orderBy));
+               $remappedParameters = $GLOBALS['TYPO3_DB']->_call('map_remapSELECTQueryParts', $selectFields, $fromTables, $whereClause, $groupBy, $orderBy);
+               $query = $this->cleanSql($GLOBALS['TYPO3_DB']->_call('SELECTqueryFromArray', $remappedParameters));
 
                $expected = 'SELECT "tstamp", "script", SUM("exec_time") AS "calc_sum", COUNT(*) AS "qrycount", MAX("errorflag") AS "error" FROM "tx_dbal_debuglog" WHERE 1 = 1';
                $this->assertEquals($expected, $query);
@@ -401,8 +401,8 @@ class dbOracleTest extends BaseTestCase {
                $groupBy      = '';
                $orderBy      = '';
 
-               $GLOBALS['TYPO3_DB']->_callRef('map_remapSELECTQueryParts', $selectFields, $fromTables, $whereClause, $groupBy, $orderBy);
-               $query = $this->cleanSql($GLOBALS['TYPO3_DB']->SELECTquery($selectFields, $fromTables, $whereClause, $groupBy, $orderBy));
+               $remappedParameters = $GLOBALS['TYPO3_DB']->_call('map_remapSELECTQueryParts', $selectFields, $fromTables, $whereClause, $groupBy, $orderBy);
+               $query = $this->cleanSql($GLOBALS['TYPO3_DB']->_call('SELECTqueryFromArray', $remappedParameters));
 
                $expected = 'SELECT MAX("ext_tt_news_cat"."cat_uid") AS "biggest_id" FROM "ext_tt_news_cat"';
                $expected .= ' INNER JOIN "ext_tt_news_cat_mm" ON "ext_tt_news_cat"."cat_uid"="ext_tt_news_cat_mm"."uid_foreign"';
@@ -423,8 +423,8 @@ class dbOracleTest extends BaseTestCase {
                $groupBy      = '';
                $orderBy      = '';
 
-               $GLOBALS['TYPO3_DB']->_callRef('map_remapSELECTQueryParts', $selectFields, $fromTables, $whereClause, $groupBy, $orderBy);
-               $query = $this->cleanSql($GLOBALS['TYPO3_DB']->SELECTquery($selectFields, $fromTables, $whereClause, $groupBy, $orderBy));
+               $remappedParameters = $GLOBALS['TYPO3_DB']->_call('map_remapSELECTQueryParts', $selectFields, $fromTables, $whereClause, $groupBy, $orderBy);
+               $query = $this->cleanSql($GLOBALS['TYPO3_DB']->_call('SELECTqueryFromArray', $remappedParameters));
 
                $expected = 'SELECT * FROM "sys_refindex", "tx_dam_file_tracking" WHERE "sys_refindex"."tablename" = \'tx_dam_file_tracking\'';
                $expected .= ' AND (instr("sys_refindex"."ref_string", CONCAT("tx_dam_file_tracking"."path","tx_dam_file_tracking"."filename"),1,1) > 0)';
@@ -442,8 +442,8 @@ class dbOracleTest extends BaseTestCase {
                $groupBy      = '';
                $orderBy      = 'cpg_categories.pos';
 
-               $GLOBALS['TYPO3_DB']->_callRef('map_remapSELECTQueryParts', $selectFields, $fromTables, $whereClause, $groupBy, $orderBy);
-               $query = $this->cleanSql($GLOBALS['TYPO3_DB']->SELECTquery($selectFields, $fromTables, $whereClause, $groupBy, $orderBy));
+               $remappedParameters = $GLOBALS['TYPO3_DB']->_call('map_remapSELECTQueryParts', $selectFields, $fromTables, $whereClause, $groupBy, $orderBy);
+               $query = $this->cleanSql($GLOBALS['TYPO3_DB']->_call('SELECTqueryFromArray', $remappedParameters));
 
                $expected = 'SELECT "cpg_categories"."uid", "cpg_categories"."name" FROM "cpg_categories", "my_pages" WHERE "my_pages"."page_uid" = "cpg_categories"."page_id"';
                $expected .= ' AND "my_pages"."deleted" = 0 AND 1 = 1 ORDER BY "cpg_categories"."pos"';
@@ -461,8 +461,8 @@ class dbOracleTest extends BaseTestCase {
                $groupBy      = '';
                $orderBy      = '';
 
-               $GLOBALS['TYPO3_DB']->_callRef('map_remapSELECTQueryParts', $selectFields, $fromTables, $whereClause, $groupBy, $orderBy);
-               $query = $this->cleanSql($GLOBALS['TYPO3_DB']->SELECTquery($selectFields, $fromTables, $whereClause, $groupBy, $orderBy));
+               $remappedParameters = $GLOBALS['TYPO3_DB']->_call('map_remapSELECTQueryParts', $selectFields, $fromTables, $whereClause, $groupBy, $orderBy);
+               $query = $this->cleanSql($GLOBALS['TYPO3_DB']->_call('SELECTqueryFromArray', $remappedParameters));
 
                $expected = 'SELECT "news"."news_uid" FROM "ext_tt_news" AS "news" WHERE "news"."news_uid" = 1';
                $this->assertEquals($expected, $query);
@@ -482,8 +482,8 @@ class dbOracleTest extends BaseTestCase {
                $groupBy      = '';
                $orderBy      = '';
 
-               $GLOBALS['TYPO3_DB']->_callRef('map_remapSELECTQueryParts', $selectFields, $fromTables, $whereClause, $groupBy, $orderBy);
-               $query = $this->cleanSql($GLOBALS['TYPO3_DB']->SELECTquery($selectFields, $fromTables, $whereClause, $groupBy, $orderBy));
+               $remappedParameters = $GLOBALS['TYPO3_DB']->_call('map_remapSELECTQueryParts', $selectFields, $fromTables, $whereClause, $groupBy, $orderBy);
+               $query = $this->cleanSql($GLOBALS['TYPO3_DB']->_call('SELECTqueryFromArray', $remappedParameters));
 
                $expected = 'SELECT "tt_news_cat"."news_uid" FROM "ext_tt_news" AS "tt_news_cat" WHERE "tt_news_cat"."news_uid" = 1';
                $this->assertEquals($expected, $query);
@@ -501,7 +501,7 @@ class dbOracleTest extends BaseTestCase {
                $orderBy      = '';
 
                        // First call to possibly alter (in memory) the mapping from localconf.php 
-               $GLOBALS['TYPO3_DB']->_callRef('map_remapSELECTQueryParts', $selectFields, $fromTables, $whereClause, $groupBy, $orderBy);
+               $remappedParameters = $GLOBALS['TYPO3_DB']->_call('map_remapSELECTQueryParts', $selectFields, $fromTables, $whereClause, $groupBy, $orderBy);
 
                $selectFields = 'uid';
                $fromTables   = 'foo';
@@ -509,8 +509,8 @@ class dbOracleTest extends BaseTestCase {
                $groupBy      = '';
                $orderBy      = '';
 
-               $GLOBALS['TYPO3_DB']->_callRef('map_remapSELECTQueryParts', $selectFields, $fromTables, $whereClause, $groupBy, $orderBy);
-               $query = $this->cleanSql($GLOBALS['TYPO3_DB']->SELECTquery($selectFields, $fromTables, $whereClause, $groupBy, $orderBy));
+               $remappedParameters = $GLOBALS['TYPO3_DB']->_call('map_remapSELECTQueryParts', $selectFields, $fromTables, $whereClause, $groupBy, $orderBy);
+               $query = $this->cleanSql($GLOBALS['TYPO3_DB']->_call('SELECTqueryFromArray', $remappedParameters));
 
                $expected = 'SELECT "uid" FROM "foo" WHERE "uid" = 1';
                $this->assertEquals($expected, $query);
@@ -529,8 +529,8 @@ class dbOracleTest extends BaseTestCase {
                $groupBy      = '';
                $orderBy      = '';
 
-               $GLOBALS['TYPO3_DB']->_callRef('map_remapSELECTQueryParts', $selectFields, $fromTables, $whereClause, $groupBy, $orderBy);
-               $query = $this->cleanSql($GLOBALS['TYPO3_DB']->SELECTquery($selectFields, $fromTables, $whereClause, $groupBy, $orderBy));
+               $remappedParameters = $GLOBALS['TYPO3_DB']->_call('map_remapSELECTQueryParts', $selectFields, $fromTables, $whereClause, $groupBy, $orderBy);
+               $query = $this->cleanSql($GLOBALS['TYPO3_DB']->_call('SELECTqueryFromArray', $remappedParameters));
 
                $expected = 'SELECT "cat"."cat_uid", "cat_mm"."local_uid", "news"."news_uid"';
                $expected .= ' FROM "ext_tt_news_cat" AS "cat"';
@@ -551,8 +551,8 @@ class dbOracleTest extends BaseTestCase {
                $groupBy      = '';
                $orderBy      = 'foo.uid';
 
-               $GLOBALS['TYPO3_DB']->_callRef('map_remapSELECTQueryParts', $selectFields, $fromTables, $whereClause, $groupBy, $orderBy);
-               $query = $this->cleanSql($GLOBALS['TYPO3_DB']->SELECTquery($selectFields, $fromTables, $whereClause, $groupBy, $orderBy));
+               $remappedParameters = $GLOBALS['TYPO3_DB']->_call('map_remapSELECTQueryParts', $selectFields, $fromTables, $whereClause, $groupBy, $orderBy);
+               $query = $this->cleanSql($GLOBALS['TYPO3_DB']->_call('SELECTqueryFromArray', $remappedParameters));
 
                $expected = 'SELECT "foo"."news_uid" FROM "ext_tt_news" AS "foo"';
                $expected .= ' INNER JOIN "ext_tt_news_cat_mm" ON "ext_tt_news_cat_mm"."local_uid"="foo"."news_uid"';
@@ -574,8 +574,8 @@ class dbOracleTest extends BaseTestCase {
                $groupBy      = '';
                $orderBy      = 'foo.uid';
 
-               $GLOBALS['TYPO3_DB']->_callRef('map_remapSELECTQueryParts', $selectFields, $fromTables, $whereClause, $groupBy, $orderBy);
-               $query = $this->cleanSql($GLOBALS['TYPO3_DB']->SELECTquery($selectFields, $fromTables, $whereClause, $groupBy, $orderBy));
+               $remappedParameters = $GLOBALS['TYPO3_DB']->_call('map_remapSELECTQueryParts', $selectFields, $fromTables, $whereClause, $groupBy, $orderBy);
+               $query = $this->cleanSql($GLOBALS['TYPO3_DB']->_call('SELECTqueryFromArray', $remappedParameters));
 
                $expected = 'SELECT "foo"."news_uid" FROM "ext_tt_news" AS "foo"';
                $expected .= ' INNER JOIN "ext_tt_news_cat_mm" ON "ext_tt_news_cat_mm"."local_uid"="foo"."news_uid"';
@@ -600,8 +600,8 @@ class dbOracleTest extends BaseTestCase {
                $groupBy      = '';
                $orderBy      = '';
 
-               $GLOBALS['TYPO3_DB']->_callRef('map_remapSELECTQueryParts', $selectFields, $fromTables, $whereClause, $groupBy, $orderBy);
-               $query = $this->cleanSql($GLOBALS['TYPO3_DB']->SELECTquery($selectFields, $fromTables, $whereClause, $groupBy, $orderBy));
+               $remappedParameters = $GLOBALS['TYPO3_DB']->_call('map_remapSELECTQueryParts', $selectFields, $fromTables, $whereClause, $groupBy, $orderBy);
+               $query = $this->cleanSql($GLOBALS['TYPO3_DB']->_call('SELECTqueryFromArray', $remappedParameters));
 
                $expected = 'SELECT "foo"."news_uid" FROM "ext_tt_news" AS "foo"';
                $expected .= ' WHERE "news_uid" IN (';
@@ -623,8 +623,8 @@ class dbOracleTest extends BaseTestCase {
                $groupBy      = '';
                $orderBy      = 'pages.uid';
 
-               $GLOBALS['TYPO3_DB']->_callRef('map_remapSELECTQueryParts', $selectFields, $fromTables, $whereClause, $groupBy, $orderBy);
-               $query = $this->cleanSql($GLOBALS['TYPO3_DB']->SELECTquery($selectFields, $fromTables, $whereClause, $groupBy, $orderBy));
+               $remappedParameters = $GLOBALS['TYPO3_DB']->_call('map_remapSELECTQueryParts', $selectFields, $fromTables, $whereClause, $groupBy, $orderBy);
+               $query = $this->cleanSql($GLOBALS['TYPO3_DB']->_call('SELECTqueryFromArray', $remappedParameters));
 
                $expected = 'SELECT "pages"."news_uid" FROM "ext_tt_news" AS "pages"';
                $expected .= ' INNER JOIN "ext_tt_news_cat_mm" AS "cat_mm" ON "cat_mm"."local_uid"="pages"."news_uid"';
@@ -810,8 +810,8 @@ class dbOracleTest extends BaseTestCase {
                $groupBy      = '';
                $orderBy      = '';
 
-               $GLOBALS['TYPO3_DB']->_callRef('map_remapSELECTQueryParts', $selectFields, $fromTables, $whereClause, $groupBy, $orderBy);
-               $query = $this->cleanSql($GLOBALS['TYPO3_DB']->SELECTquery($selectFields, $fromTables, $whereClause, $groupBy, $orderBy));
+               $remappedParameters = $GLOBALS['TYPO3_DB']->_call('map_remapSELECTQueryParts', $selectFields, $fromTables, $whereClause, $groupBy, $orderBy);
+               $query = $this->cleanSql($GLOBALS['TYPO3_DB']->_call('SELECTqueryFromArray', $remappedParameters));
 
                $expected = 'SELECT * FROM "tx_crawler_queue" WHERE "process_id" IN (SELECT "ps_id" FROM "tx_crawler_ps" WHERE "is_active" = 0 AND "deleted" = 0)';
                $this->assertEquals($expected, $query);
@@ -913,8 +913,8 @@ class dbOracleTest extends BaseTestCase {
                $groupBy      = '';
                $orderBy      = '';
 
-               $GLOBALS['TYPO3_DB']->_callRef('map_remapSELECTQueryParts', $selectFields, $fromTables, $whereClause, $groupBy, $orderBy);
-               $query = $this->cleanSql($GLOBALS['TYPO3_DB']->SELECTquery($selectFields, $fromTables, $whereClause, $groupBy, $orderBy));
+               $remappedParameters = $GLOBALS['TYPO3_DB']->_call('map_remapSELECTQueryParts', $selectFields, $fromTables, $whereClause, $groupBy, $orderBy);
+               $query = $this->cleanSql($GLOBALS['TYPO3_DB']->_call('SELECTqueryFromArray', $remappedParameters));
 
                $expected = 'SELECT * FROM "tx_crawler_ps" WHERE "is_active" = 0 AND NOT EXISTS (';
                $expected .= 'SELECT * FROM "tx_crawler_queue" WHERE "tx_crawler_queue"."process_id" = "tx_crawler_ps"."ps_id" AND "tx_crawler_queue"."exec_time" = 0';
@@ -959,8 +959,8 @@ class dbOracleTest extends BaseTestCase {
                $groupBy      = '';
                $orderBy      = '';
 
-               $GLOBALS['TYPO3_DB']->_callRef('map_remapSELECTQueryParts', $selectFields, $fromTables, $whereClause, $groupBy, $orderBy);
-               $query = $this->cleanSql($GLOBALS['TYPO3_DB']->SELECTquery($selectFields, $fromTables, $whereClause, $groupBy, $orderBy));
+               $remappedParameters = $GLOBALS['TYPO3_DB']->_call('map_remapSELECTQueryParts', $selectFields, $fromTables, $whereClause, $groupBy, $orderBy);
+               $query = $this->cleanSql($GLOBALS['TYPO3_DB']->_call('SELECTqueryFromArray', $remappedParameters));
 
                $expected = 'SELECT "ps_id", CASE "is_active" WHEN 1 THEN \'one\' WHEN 2 THEN \'two\' ELSE \'out of range\' END AS "number" ';
                $expected .= 'FROM "tx_crawler_ps" WHERE 1 = 1';
@@ -982,8 +982,8 @@ class dbOracleTest extends BaseTestCase {
                $groupBy      = '';
                $orderBy      = '';
 
-               $GLOBALS['TYPO3_DB']->_callRef('map_remapSELECTQueryParts', $selectFields, $fromTables, $whereClause, $groupBy, $orderBy);
-               $query = $this->cleanSql($GLOBALS['TYPO3_DB']->SELECTquery($selectFields, $fromTables, $whereClause, $groupBy, $orderBy));
+               $remappedParameters = $GLOBALS['TYPO3_DB']->_call('map_remapSELECTQueryParts', $selectFields, $fromTables, $whereClause, $groupBy, $orderBy);
+               $query = $this->cleanSql($GLOBALS['TYPO3_DB']->_call('SELECTqueryFromArray', $remappedParameters));
 
                $expected = 'SELECT "ps_id", CASE "ext_tt_news"."news_uid" WHEN 1 THEN \'one\' WHEN 2 THEN \'two\' ELSE \'out of range\' END AS "number" ';
                $expected .= 'FROM "tx_crawler_ps", "ext_tt_news" WHERE 1 = 1';
@@ -1063,8 +1063,8 @@ class dbOracleTest extends BaseTestCase {
                $groupBy      = '';
                $orderBy      = '';
 
-               $GLOBALS['TYPO3_DB']->_callRef('map_remapSELECTQueryParts', $selectFields, $fromTables, $whereClause, $groupBy, $orderBy);
-               $query = $this->cleanSql($GLOBALS['TYPO3_DB']->SELECTquery($selectFields, $fromTables, $whereClause, $groupBy, $orderBy));
+               $remappedParameters = $GLOBALS['TYPO3_DB']->_call('map_remapSELECTQueryParts', $selectFields, $fromTables, $whereClause, $groupBy, $orderBy);
+               $query = $this->cleanSql($GLOBALS['TYPO3_DB']->_call('SELECTqueryFromArray', $remappedParameters));
 
                $expected = 'SELECT "usergroup" FROM "ext_tt_news" WHERE \',\'||"ext_tt_news"."usergroup"||\',\' LIKE \'%,10,%\'';
                $this->assertEquals($expected, $query);