Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
D
doctrine-dbal
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Tomáš Trávníček
doctrine-dbal
Commits
b9f74489
Commit
b9f74489
authored
Oct 13, 2009
by
romanb
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[2.0][DDC-42] Fixed.
parent
f3f522b7
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
102 additions
and
29 deletions
+102
-29
DriverManager.php
lib/Doctrine/DBAL/DriverManager.php
+2
-5
AbstractPlatform.php
lib/Doctrine/DBAL/Platforms/AbstractPlatform.php
+3
-2
Literal.php
lib/Doctrine/ORM/Query/AST/Literal.php
+24
-0
Node.php
lib/Doctrine/ORM/Query/AST/Node.php
+1
-1
Parser.php
lib/Doctrine/ORM/Query/Parser.php
+9
-11
SqlWalker.php
lib/Doctrine/ORM/Query/SqlWalker.php
+20
-10
LanguageRecognitionTest.php
tests/Doctrine/Tests/ORM/Query/LanguageRecognitionTest.php
+5
-0
SelectSqlGenerationTest.php
tests/Doctrine/Tests/ORM/Query/SelectSqlGenerationTest.php
+38
-0
No files found.
lib/Doctrine/DBAL/DriverManager.php
View file @
b9f74489
...
...
@@ -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.
...
...
lib/Doctrine/DBAL/Platforms/AbstractPlatform.php
View file @
b9f74489
...
...
@@ -1151,9 +1151,10 @@ abstract class AbstractPlatform
/**
* Some platforms need the boolean values to be converted.
* Default conversion defined here converts to integers.
*
* The default conversion in this implementation converts to integers (false => 0, true => 1).
*
* @param
array
$item
* @param
mixed
$item
*/
public
function
convertBooleans
(
$item
)
{
...
...
lib/Doctrine/ORM/Query/AST/Literal.php
0 → 100644
View file @
b9f74489
<?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
lib/Doctrine/ORM/Query/AST/Node.php
View file @
b9f74489
...
...
@@ -34,7 +34,7 @@ namespace Doctrine\ORM\Query\AST;
*/
abstract
class
Node
{
abstract
public
function
dispatch
(
$
sqlW
alker
);
abstract
public
function
dispatch
(
$
w
alker
);
/**
* Dumps the AST Node into a string representation for information purpose only
...
...
lib/Doctrine/ORM/Query/Parser.php
View file @
b9f74489
...
...
@@ -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
;
}
}
...
...
lib/Doctrine/ORM/Query/SqlWalker.php
View file @
b9f74489
...
...
@@ -1338,13 +1338,20 @@ class SqlWalker implements TreeWalker
if
(
$inExpr
->
subselect
)
{
$sql
.=
$this
->
walkSubselect
(
$inExpr
->
subselect
);
}
else
{
$sql
.=
implode
(
', '
,
array_map
(
array
(
$this
,
'walk
Literal
'
),
$inExpr
->
literals
));
$sql
.=
implode
(
', '
,
array_map
(
array
(
$this
,
'walk
InParameter
'
),
$inExpr
->
literals
));
}
$sql
.=
')'
;
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
);
...
...
tests/Doctrine/Tests/ORM/Query/LanguageRecognitionTest.php
View file @
b9f74489
...
...
@@ -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
*
...
...
tests/Doctrine/Tests/ORM/Query/SelectSqlGenerationTest.php
View file @
b9f74489
...
...
@@ -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()
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment