Commit b9f74489 authored by romanb's avatar romanb

[2.0][DDC-42] Fixed.

parent f3f522b7
......@@ -36,15 +36,14 @@ final class DriverManager
* List of supported drivers and their mappings to the driver classes.
*
* @var array
* @todo REMOVE. Users should directly supply class names instead.
*/
private static $_driverMap = array(
'pdo_mysql' => 'Doctrine\DBAL\Driver\PDOMySql\Driver',
'pdo_sqlite' => 'Doctrine\DBAL\Driver\PDOSqlite\Driver',
'pdo_pgsql' => 'Doctrine\DBAL\Driver\PDOPgSql\Driver',
'pdo_oci' => 'Doctrine\DBAL\Driver\PDOOracle\Driver',
'pdo_mssql' => 'Doctrine\DBAL\Driver\PDOMsSql\Driver',
'pdo_firebird' => 'Doctrine\DBAL\Driver\PDOFirebird\Driver',
'pdo_informix' => 'Doctrine\DBAL\Driver\PDOInformix\Driver',
'pdo_mssql' => 'Doctrine\DBAL\Driver\PDOMsSql\Driver'
);
/** Private constructor. This class cannot be instantiated. */
......@@ -66,8 +65,6 @@ final class DriverManager
* pdo_pgsql
* pdo_oracle
* pdo_mssql
* pdo_firebird
* pdo_informix
*
* OR 'driverClass' that contains the full class name (with namespace) of the
* driver class to instantiate.
......
......@@ -1151,9 +1151,10 @@ abstract class AbstractPlatform
/**
* Some platforms need the boolean values to be converted.
* Default conversion defined here converts to integers.
*
* @param array $item
* The default conversion in this implementation converts to integers (false => 0, true => 1).
*
* @param mixed $item
*/
public function convertBooleans($item)
{
......
<?php
namespace Doctrine\ORM\Query\AST;
class Literal extends Node
{
const STRING = 1;
const BOOLEAN = 2;
const NUMERIC = 3;
public $type;
public $value;
public function __construct($type, $value)
{
$this->type = $type;
$this->value = $value;
}
public function dispatch($walker)
{
return $walker->walkLiteral($this);
}
}
\ No newline at end of file
......@@ -34,7 +34,7 @@ namespace Doctrine\ORM\Query\AST;
*/
abstract class Node
{
abstract public function dispatch($sqlWalker);
abstract public function dispatch($walker);
/**
* Dumps the AST Node into a string representation for information purpose only
......
......@@ -1875,12 +1875,16 @@ class Parser
{
switch ($this->_lexer->lookahead['type']) {
case Lexer::T_STRING:
$this->match($this->_lexer->lookahead['value']);
return new AST\Literal(AST\Literal::STRING, $this->_lexer->token['value']);
case Lexer::T_INTEGER:
case Lexer::T_FLOAT:
$this->match($this->_lexer->lookahead['value']);
return $this->_lexer->token['value'];
return new AST\Literal(AST\Literal::NUMERIC, $this->_lexer->token['value']);
case Lexer::T_TRUE:
case Lexer::T_FALSE:
$this->match($this->_lexer->lookahead['value']);
return new AST\Literal(AST\Literal::BOOLEAN, $this->_lexer->token['value']);
default:
$this->syntaxError('Literal');
}
......@@ -2040,11 +2044,6 @@ class Parser
case Lexer::T_INPUT_PARAMETER:
return $this->InputParameter();
case Lexer::T_STRING:
case Lexer::T_INTEGER:
case Lexer::T_FLOAT:
return $this->Literal();
default:
$peek = $this->_lexer->glimpse();
......@@ -2054,10 +2053,9 @@ class Parser
}
return $this->FunctionDeclaration();
} else {
return $this->Literal();
}
$this->syntaxError();
break;
}
}
......
......@@ -1338,7 +1338,7 @@ class SqlWalker implements TreeWalker
if ($inExpr->subselect) {
$sql .= $this->walkSubselect($inExpr->subselect);
} else {
$sql .= implode(', ', array_map(array($this, 'walkLiteral'), $inExpr->literals));
$sql .= implode(', ', array_map(array($this, 'walkInParameter'), $inExpr->literals));
}
$sql .= ')';
......@@ -1346,6 +1346,13 @@ class SqlWalker implements TreeWalker
return $sql;
}
public function walkInParameter($inParam)
{
return $inParam instanceof AST\InputParameter ?
$this->walkInputParameter($inParam) :
$this->walkLiteral($inParam);
}
/**
* Walks down a literal that represents an AST node, thereby generating the appropriate SQL.
*
......@@ -1354,11 +1361,18 @@ class SqlWalker implements TreeWalker
*/
public function walkLiteral($literal)
{
if ($literal instanceof AST\InputParameter) {
return $this->walkInputParameter($literal);
switch ($literal->type) {
case AST\Literal::STRING:
return $this->_conn->quote($literal->value);
case AST\Literal::BOOLEAN:
$bool = strtolower($literal->value) == 'true' ? true : false;
$boolVal = $this->_conn->getDatabasePlatform()->convertBooleans($bool);
return is_string($boolVal) ? $this->_conn->quote($boolVal) : $boolVal;
case AST\Literal::NUMERIC:
return $literal->value;
default:
throw QueryException::invalidLiteral($literal);
}
return $literal; //TODO: quote() ?
}
/**
......@@ -1513,11 +1527,7 @@ class SqlWalker implements TreeWalker
$sql = ($factor->isNegativeSigned() ? '-' : ($factor->isPositiveSigned() ? '+' : ''));
$primary = $factor->arithmeticPrimary;
if (is_numeric($primary)) {
$sql .= $primary;
} else if (is_string($primary)) {
$sql .= $this->_conn->quote($primary);
} else if ($primary instanceof AST\SimpleArithmeticExpression) {
if ($primary instanceof AST\SimpleArithmeticExpression) {
$sql .= '(' . $this->walkSimpleArithmeticExpression($primary) . ')';
} else if ($primary instanceof AST\Node) {
$sql .= $primary->dispatch($this);
......
......@@ -346,6 +346,11 @@ class LanguageRecognitionTest extends \Doctrine\Tests\OrmTestCase
$this->assertValidDql('SELECT p FROM Doctrine\Tests\Models\CMS\CmsPhonenumber p WHERE p.user = ?1');
}
public function testBooleanLiteralInWhere()
{
$this->assertValidDql('SELECT b FROM Doctrine\Tests\Models\Generic\BooleanModel b WHERE b.booleanField = true');
}
/**
* This checks for invalid attempt to hydrate a proxy. It should throw an exception
*
......
......@@ -416,6 +416,44 @@ class SelectSqlGenerationTest extends \Doctrine\Tests\OrmTestCase
);
}
public function testBooleanLiteralInWhereOnSqlite()
{
$oldPlat = $this->_em->getConnection()->getDatabasePlatform();
$this->_em->getConnection()->setDatabasePlatform(new \Doctrine\DBAL\Platforms\SqlitePlatform);
$this->assertSqlGeneration(
"SELECT b FROM Doctrine\Tests\Models\Generic\BooleanModel b WHERE b.booleanField = true",
"SELECT b0_.id AS id0, b0_.booleanField AS booleanField1 FROM boolean_model b0_ WHERE b0_.booleanField = 1"
);
$this->assertSqlGeneration(
"SELECT b FROM Doctrine\Tests\Models\Generic\BooleanModel b WHERE b.booleanField = false",
"SELECT b0_.id AS id0, b0_.booleanField AS booleanField1 FROM boolean_model b0_ WHERE b0_.booleanField = 0"
);
$this->_em->getConnection()->setDatabasePlatform($oldPlat);
}
public function testBooleanLiteralInWhereOnPostgres()
{
$oldPlat = $this->_em->getConnection()->getDatabasePlatform();
$this->_em->getConnection()->setDatabasePlatform(new \Doctrine\DBAL\Platforms\PostgreSqlPlatform);
$this->assertSqlGeneration(
"SELECT b FROM Doctrine\Tests\Models\Generic\BooleanModel b WHERE b.booleanField = true",
"SELECT b0_.id AS id0, b0_.booleanField AS booleanField1 FROM boolean_model b0_ WHERE b0_.booleanField = 'true'"
);
$this->assertSqlGeneration(
"SELECT b FROM Doctrine\Tests\Models\Generic\BooleanModel b WHERE b.booleanField = false",
"SELECT b0_.id AS id0, b0_.booleanField AS booleanField1 FROM boolean_model b0_ WHERE b0_.booleanField = 'false'"
);
$this->_em->getConnection()->setDatabasePlatform($oldPlat);
}
/* Not yet implemented, needs more thought
public function testSingleValuedAssociationFieldInWhere()
{
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment