Project

General

Profile

Bug #17552 » 6196_dbal.diff

Administrator Admin, 2010-02-13 13:15

View differences:

class.ux_t3lib_sqlparser.php (working copy)
$output .= isset($v['func']['pos']) ? ', ' . $v['func']['pos'][0] : '';
$output .= ')';
break;
}
}
} elseif (isset($v['func']) && $v['func']['type'] === 'IFNULL') {
$output .= ' ' . trim($v['modifier']) . ' ';
switch (TRUE) {
case ($GLOBALS['TYPO3_DB']->runningADOdbDriver('oci8') && $functionMapping):
$output .= 'NVL';
break;
default:
$output .= 'IFNULL';
break;
}
$output .= '(';
$output .= ($v['func']['table'] ? $v['func']['table'] . '.' : '') . $v['func']['field'];
$output .= ', ' . $v['func']['default'][1] . $this->compileAddslashes($v['func']['default'][0]) . $v['func']['default'][1];
$output .= ')';
} else {
// Set field/table with modifying prefix if any:
class.ux_t3lib_db.php (working copy)
case 'EXISTS':
$where_clause[$k]['func']['subquery'] = $this->quoteSELECTsubquery($v['func']['subquery']);
break;
case 'IFNULL':
case 'LOCATE':
if ($where_clause[$k]['func']['table'] != '') {
$where_clause[$k]['func']['table'] = $this->quoteName($v['func']['table']);
......
$this->map_sqlParts($sqlPartArray[$k]['func']['subquery']['FROM'], $subqueryDefaultTable);
$this->map_sqlParts($sqlPartArray[$k]['func']['subquery']['WHERE'], $subqueryDefaultTable);
break;
case 'IFNULL':
case 'LOCATE':
// For the field, look for table mapping (generic):
$t = $sqlPartArray[$k]['func']['table'] ? $sqlPartArray[$k]['func']['table'] : $defaultTable;
res/postgresql/postgresql-compatibility.sql (working copy)
--
-- The functions add compatibility operators for PostgreSQL to make sure comparison is possible and the SQL doesn't return an error.
--
-- Note: You may consider having a look at project mysqlcompat on http://pgfoundry.org/projects/mysqlcompat
-- and report in DBAL bugtracker if you need another compatibility operator added.
--
-- $Id$
-- R. van Twisk <typo3@rvt.dds.nl>
......
SELECT locate($1, $2, 1)
$$ IMMUTABLE STRICT LANGUAGE SQL;
-- IFNULL
CREATE OR REPLACE FUNCTION ifnull(anyelement, anyelement)
RETURNS anyelement AS $$
SELECT COALESCE($1, $2)
$$ IMMUTABLE STRICT LANGUAGE SQL;
-- Remove Compatibility operators
--
--DROP OPERATOR ~~ (integer,text);
......
--DROP FUNCTION t3compat_operator_eq(text, integer);
--DROP FUNCTION locate(text, text);
--DROP FUNCTION locate(text, text, integer);
--DROP FUNCTION ifnull(anyelement, anyelement);
tests/sqlparser_general_testcase.php (working copy)
$this->assertEquals($expected, $insert);
}
/**
* @test
* @see http://bugs.typo3.org/view.php?id=6196
*/
public function canParseIfNullKeyword() {
$parseString = 'IFNULL(tt_news_cat_mm.uid_foreign,0) IN (21,22)';
$whereParts = $this->fixture->parseWhereClause($parseString);
$this->assertTrue(is_array($whereParts), $whereParts);
$this->assertTrue(empty($parseString), 'parseString is not empty');
}
/**
* @test
* @see http://bugs.typo3.org/view.php?id=6196
*/
public function canCompileIfNullKeyword() {
$parseString = 'SELECT * FROM tx_irfaq_q_cat_mm WHERE IFNULL(tx_irfaq_q_cat_mm.uid_foreign,0) = 1';
$components = $this->fixture->_callRef('parseSELECT', $parseString);
$this->assertTrue(is_array($components), $components);
$select = $this->cleanSql($this->fixture->_callRef('compileSELECT', $components));
$expected = 'SELECT * FROM tx_irfaq_q_cat_mm WHERE IFNULL(tx_irfaq_q_cat_mm.uid_foreign, 0) = 1';
$this->assertEquals($expected, $select);
}
///////////////////////////////////////
// Tests concerning JOINs
///////////////////////////////////////
tests/db_oracle_testcase.php (working copy)
$expected = 'SELECT *, CASE WHEN INSTR("datastructure", \'(fce)\', 4) > 0 THEN 2 ELSE 1 END AS "scope" FROM "tx_templavoila_tmplobj" WHERE 1 = 1';
$this->assertEquals($expected, $query);
}
/**
* @test
* @see http://bugs.typo3.org/view.php?id=6196
*/
public function IfNullIsProperlyRemapped() {
$query = $this->cleanSql($GLOBALS['TYPO3_DB']->SELECTquery(
'*',
'tt_news_cat_mm',
'IFNULL(tt_news_cat_mm.uid_foreign,0) IN (21,22)'
));
$expected = 'SELECT * FROM "tt_news_cat_mm" WHERE NVL("tt_news_cat_mm"."uid_foreign", 0) IN (21,22)';
$this->assertEquals($expected, $query);
}
}
?>
(2-2/3)