Project

General

Profile

Bug #21514 » 12535_v2.diff

Administrator Admin, 2009-11-10 23:58

View differences:

class.ux_t3lib_sqlparser.php (working copy)
// Find "comparator":
$stack[$level][$pnt[$level]]['comparator'] = $this->nextPart($parseString, '^(<=|>=|<|>|=|!=|NOT[[:space:]]+IN|IN|NOT[[:space:]]+LIKE|LIKE|IS[[:space:]]+NOT|IS)');
if (strlen($stack[$level][$pnt[$level]]['comparator'])) {
if (in_array($stack[$level][$pnt[$level]]['comparator'], array('LIKE', 'NOT LIKE'))) {
// Handle the "BINARY" operator
if (preg_match('/^BINARY[[:space:]]*/i', $parseString)) {
switch (TRUE) {
case $GLOBALS['TYPO3_DB']->runningADOdbDriver('postgres'):
case $GLOBALS['TYPO3_DB']->runningADOdbDriver('postgres64'):
case $GLOBALS['TYPO3_DB']->runningADOdbDriver('postgres7'):
case $GLOBALS['TYPO3_DB']->runningADOdbDriver('postgres8'):
// Remap (NOT)? LIKE BINARY to (NOT)? LIKE
$this->nextPart($parseString, '^(BINARY)');
break;
case $GLOBALS['TYPO3_DB']->runningADOdbDriver('oci8'):
default:
// Remove the BINARY operator
$this->nextPart($parseString, '^(BINARY)');
break;
}
} else {
switch (TRUE) {
case $GLOBALS['TYPO3_DB']->runningADOdbDriver('postgres'):
case $GLOBALS['TYPO3_DB']->runningADOdbDriver('postgres64'):
case $GLOBALS['TYPO3_DB']->runningADOdbDriver('postgres7'):
case $GLOBALS['TYPO3_DB']->runningADOdbDriver('postgres8'):
// Remap (NOT)? LIKE to (NOT)? ILIKE
$stack[$level][$pnt[$level]]['comparator'] = preg_replace('/(NOT[[:space:]]+)?LIKE/i', '\1ILIKE', $stack[$level][$pnt[$level]]['comparator']);
break;
}
}
}
if (preg_match('/^CONCAT[[:space:]]*\(/i', $parseString)) {
$this->nextPart($parseString, '^(CONCAT[[:space:]]?[(])');
$values = array(
tests/db_general_testcase.php (working copy)
$expected = 'INSERT INTO tx_test_dbal ( foo, foobar ) VALUES ( \'99.12\', \'-120\' )';
$this->assertEquals($expected, $query);
}
/**
* @test
* @see http://bugs.typo3.org/view.php?id=12535
*/
public function likeBinaryOperatorIsKept() {
$query = $this->cleanSql($GLOBALS['TYPO3_DB']->SELECTquery(
'*',
'tt_content',
'bodytext LIKE BINARY \'test\''
));
$expected = 'SELECT * FROM tt_content WHERE bodytext LIKE BINARY \'test\'';
$this->assertEquals($expected, $query);
}
/**
* @test
* @see http://bugs.typo3.org/view.php?id=12535
*/
public function notLikeBinaryOperatorIsKept() {
$query = $this->cleanSql($GLOBALS['TYPO3_DB']->SELECTquery(
'*',
'tt_content',
'bodytext NOT LIKE BINARY \'test\''
));
$expected = 'SELECT * FROM tt_content WHERE bodytext NOT LIKE BINARY \'test\'';
$this->assertEquals($expected, $query);
}
}
?>
tests/fixtures/postgres7.config.php (revision 0)
<?php
/**
* PostgreSQL configuration
*
* $Id$
*
* @author Xavier Perseguers <typo3@perseguers.ch>
*
* @package TYPO3
* @subpackage dbal
*/
global $TYPO3_CONF_VARS;
$TYPO3_CONF_VARS['EXTCONF']['dbal']['handlerCfg'] = array(
'_DEFAULT' => array(
'type' => 'adodb',
'config' => array(
'driver' => 'postgres8',
),
),
);
$TYPO3_CONF_VARS['EXTCONF']['dbal']['mapping'] = array(
);
?>
tests/db_postgresql_testcase.php (revision 0)
<?php
/***************************************************************
* Copyright notice
*
* (c) 2009 Xavier Perseguers <typo3@perseguers.ch>
* All rights reserved
*
* This script is part of the TYPO3 project. The TYPO3 project is
* free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* The GNU General Public License can be found at
* http://www.gnu.org/copyleft/gpl.html.
*
* This script is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* This copyright notice MUST APPEAR in all copies of the script!
***************************************************************/
require_once('BaseTestCase.php');
require_once('FakeDbConnection.php');
/**
* Testcase for class ux_t3lib_db. Testing PostgreSQL database handling.
*
* $Id$
*
* @author Xavier Perseguers <typo3@perseguers.ch>
*
* @package TYPO3
* @subpackage dbal
*/
class db_postgresql_testcase extends BaseTestCase {
/**
* @var t3lib_db
*/
protected $db;
/**
* @var array
*/
protected $dbalConfig;
/**
* Prepares the environment before running a test.
*/
public function setUp() {
// Backup DBAL configuration
$this->dbalConfig = $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['dbal'];
// Backup database connection
$this->db = $GLOBALS['TYPO3_DB'];
// Reconfigure DBAL to use PostgreSQL
require('fixtures/postgres7.config.php');
$className = self::buildAccessibleProxy('ux_t3lib_db');
$GLOBALS['TYPO3_DB'] = new $className;
// Initialize a fake Oracle connection
FakeDbConnection::connect($GLOBALS['TYPO3_DB'], 'postgres7');
$this->assertTrue($GLOBALS['TYPO3_DB']->handlerInstance['_DEFAULT']->isConnected());
}
/**
* Cleans up the environment after running a test.
*/
public function tearDown() {
// Clear DBAL-generated cache files
$GLOBALS['TYPO3_DB']->clearCachedFieldInfo();
// Restore DBAL configuration
$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['dbal'] = $this->dbalConfig;
// Restore DB connection
$GLOBALS['TYPO3_DB'] = $this->db;
}
/**
* Cleans a SQL query.
*
* @param mixed $sql
* @return mixed (string or array)
*/
private function cleanSql($sql) {
if (!is_string($sql)) {
return $sql;
}
$sql = str_replace("\n", ' ', $sql);
$sql = preg_replace('/\s+/', ' ', $sql);
return $sql;
}
/**
* @test
*/
public function configurationIsUsingAdodbAndDriverPostgres() {
$configuration = $GLOBALS['TYPO3_DB']->conf['handlerCfg'];
$this->assertTrue(is_array($configuration) && count($configuration) > 0, 'No configuration found');
$this->assertEquals('adodb', $configuration['_DEFAULT']['type']);
$isPostgres = $GLOBALS['TYPO3_DB']->runningADOdbDriver('postgres7') || $GLOBALS['TYPO3_DB']->runningADOdbDriver('postgres8');
$this->assertTrue($isPostgres, 'Not using postgres driver');
}
/**
* @test
* @see http://bugs.typo3.org/view.php?id=12535
*/
public function likeBinaryOperatorIsRemappedToLike() {
$query = $this->cleanSql($GLOBALS['TYPO3_DB']->SELECTquery(
'*',
'tt_content',
'bodytext LIKE BINARY \'test\''
));
$expected = 'SELECT * FROM "tt_content" WHERE "bodytext" LIKE \'test\'';
$this->assertEquals($expected, $query);
}
/**
* @test
* @see http://bugs.typo3.org/view.php?id=12535
*/
public function notLikeBinaryOperatorIsRemappedToNotLike() {
$query = $this->cleanSql($GLOBALS['TYPO3_DB']->SELECTquery(
'*',
'tt_content',
'bodytext NOT LIKE BINARY \'test\''
));
$expected = 'SELECT * FROM "tt_content" WHERE "bodytext" NOT LIKE \'test\'';
$this->assertEquals($expected, $query);
}
/**
* @test
* @see http://bugs.typo3.org/view.php?id=12535
*/
public function likeOperatorIsRemappedToIlike() {
$query = $this->cleanSql($GLOBALS['TYPO3_DB']->SELECTquery(
'*',
'tt_content',
'bodytext LIKE \'test\''
));
$expected = 'SELECT * FROM "tt_content" WHERE "bodytext" ILIKE \'test\'';
$this->assertEquals($expected, $query);
}
/**
* @test
* @see http://bugs.typo3.org/view.php?id=12535
*/
public function notLikeOperatorIsRemappedToNotIlike() {
$query = $this->cleanSql($GLOBALS['TYPO3_DB']->SELECTquery(
'*',
'tt_content',
'bodytext NOT LIKE \'test\''
));
$expected = 'SELECT * FROM "tt_content" WHERE "bodytext" NOT ILIKE \'test\'';
$this->assertEquals($expected, $query);
}
}
?>
tests/db_oracle_testcase.php (working copy)
$expected .= ' AND (dbms_lob.instr("sys_refindex"."ref_string", CONCAT("tx_dam_file_tracking"."path","tx_dam_file_tracking"."filename"),1,1) > 0)';
$this->assertEquals($expected, $query);
}
/**
* @test
* @see http://bugs.typo3.org/view.php?id=12535
*/
public function likeBinaryOperatorIsRemoved() {
$query = $this->cleanSql($GLOBALS['TYPO3_DB']->SELECTquery(
'*',
'tt_content',
'bodytext LIKE BINARY \'test\''
));
$expected = 'SELECT * FROM "tt_content" WHERE (dbms_lob.instr("bodytext", \'test\',1,1) > 0)';
$this->assertEquals($expected, $query);
}
}
(2-2/4)