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
991f456f
Commit
991f456f
authored
Oct 29, 2007
by
zYne
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fixes #514, literal value as the first operand for IN
parent
32c3a34d
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
61 additions
and
45 deletions
+61
-45
Query.php
lib/Doctrine/Query.php
+48
-34
Where.php
lib/Doctrine/Query/Where.php
+4
-11
WhereTestCase.php
tests/Query/WhereTestCase.php
+9
-0
No files found.
lib/Doctrine/Query.php
View file @
991f456f
...
...
@@ -65,12 +65,12 @@ class Doctrine_Query extends Doctrine_Query_Abstract implements Countable
* @var array $pendingSubqueries SELECT part subqueries, these are called pending subqueries since
* they cannot be parsed directly (some queries might be correlated)
*/
protected
$pendingSubqueries
=
array
();
protected
$
_
pendingSubqueries
=
array
();
/**
* @var array $
pendingFields
* @var array $
_pendingFields an array of pending fields (fields waiting to be parsed)
*/
protected
$pendingFields
=
array
();
protected
$
_
pendingFields
=
array
();
/**
* @var array $_parsers an array of parser objects, each DQL query part has its own parser
...
...
@@ -123,8 +123,8 @@ class Doctrine_Query extends Doctrine_Query_Abstract implements Countable
public
function
reset
()
{
$this
->
_pendingJoinConditions
=
array
();
$this
->
pendingSubqueries
=
array
();
$this
->
pendingFields
=
array
();
$this
->
_
pendingSubqueries
=
array
();
$this
->
_
pendingFields
=
array
();
$this
->
_neededTables
=
array
();
$this
->
_expressionMap
=
array
();
$this
->
subqueryAliases
=
array
();
...
...
@@ -387,8 +387,8 @@ class Doctrine_Query extends Doctrine_Query_Abstract implements Countable
$tableAlias
=
$this
->
getTableAlias
(
$componentAlias
);
$table
=
$this
->
_aliasMap
[
$componentAlias
][
'table'
];
if
(
isset
(
$this
->
pendingFields
[
$componentAlias
]))
{
$fields
=
$this
->
pendingFields
[
$componentAlias
];
if
(
isset
(
$this
->
_
pendingFields
[
$componentAlias
]))
{
$fields
=
$this
->
_
pendingFields
[
$componentAlias
];
// check for wildcards
if
(
in_array
(
'*'
,
$fields
))
{
...
...
@@ -555,7 +555,7 @@ class Doctrine_Query extends Doctrine_Query_Abstract implements Countable
$field
=
$e
[
0
];
}
$this
->
pendingFields
[
$componentAlias
][]
=
$field
;
$this
->
_
pendingFields
[
$componentAlias
][]
=
$field
;
}
}
}
...
...
@@ -576,6 +576,10 @@ class Doctrine_Query extends Doctrine_Query_Abstract implements Countable
*/
public
function
parseClause
(
$clause
)
{
if
(
is_numeric
(
$clause
))
{
return
$clause
;
}
$terms
=
Doctrine_Tokenizer
::
clauseExplode
(
$clause
,
array
(
' '
,
'+'
,
'-'
,
'*'
,
'/'
));
$str
=
''
;
...
...
@@ -622,29 +626,39 @@ class Doctrine_Query extends Doctrine_Query_Abstract implements Countable
$e
=
explode
(
'.'
,
$term
[
0
]);
$field
=
array_pop
(
$e
);
$componentAlias
=
implode
(
'.'
,
$e
);
// check the existence of the component alias
if
(
!
isset
(
$this
->
_aliasMap
[
$componentAlias
]))
{
throw
new
Doctrine_Query_Exception
(
'Unknown component alias '
.
$componentAlias
);
}
$table
=
$this
->
_aliasMap
[
$componentAlias
][
'table'
];
// get the actual field name from alias
$field
=
$table
->
getColumnName
(
$field
);
// check column existence
if
(
!
$table
->
hasColumn
(
$field
))
{
throw
new
Doctrine_Query_Exception
(
'Unknown column '
.
$field
);
if
(
$this
->
getType
()
===
Doctrine_Query
::
SELECT
)
{
$componentAlias
=
implode
(
'.'
,
$e
);
if
(
empty
(
$componentAlias
))
{
$componentAlias
=
$this
->
getRootAlias
();
}
// check the existence of the component alias
if
(
!
isset
(
$this
->
_aliasMap
[
$componentAlias
]))
{
throw
new
Doctrine_Query_Exception
(
'Unknown component alias '
.
$componentAlias
);
}
$table
=
$this
->
_aliasMap
[
$componentAlias
][
'table'
];
// get the actual field name from alias
$field
=
$table
->
getColumnName
(
$field
);
// check column existence
if
(
!
$table
->
hasColumn
(
$field
))
{
throw
new
Doctrine_Query_Exception
(
'Unknown column '
.
$field
);
}
$tableAlias
=
$this
->
getTableAlias
(
$componentAlias
);
// build sql expression
$term
[
0
]
=
$this
->
_conn
->
quoteIdentifier
(
$tableAlias
)
.
'.'
.
$this
->
_conn
->
quoteIdentifier
(
$field
);
}
else
{
// build sql expression
$term
[
0
]
=
$this
->
_conn
->
quoteIdentifier
(
$field
);
}
$tableAlias
=
$this
->
getTableAlias
(
$componentAlias
);
// build sql expression
$term
[
0
]
=
$this
->
_conn
->
quoteIdentifier
(
$tableAlias
)
.
'.'
.
$this
->
_conn
->
quoteIdentifier
(
$field
);
}
}
}
...
...
@@ -725,7 +739,7 @@ class Doctrine_Query extends Doctrine_Query_Abstract implements Countable
*/
public
function
processPendingSubqueries
()
{
foreach
(
$this
->
pendingSubqueries
as
$value
)
{
foreach
(
$this
->
_
pendingSubqueries
as
$value
)
{
list
(
$dql
,
$alias
)
=
$value
;
$subquery
=
$this
->
createSubquery
();
...
...
@@ -743,7 +757,7 @@ class Doctrine_Query extends Doctrine_Query_Abstract implements Countable
$this
->
aggregateMap
[
$alias
]
=
$sqlAlias
;
$this
->
_aliasMap
[
$componentAlias
][
'agg'
][]
=
$alias
;
}
$this
->
pendingSubqueries
=
array
();
$this
->
_
pendingSubqueries
=
array
();
}
/**
...
...
@@ -869,7 +883,7 @@ class Doctrine_Query extends Doctrine_Query_Abstract implements Countable
if
(
!
in_array
(
$e
[
3
],
$aliases
)
&&
!
in_array
(
$e
[
2
],
$aliases
)
&&
!
empty
(
$this
->
pendingFields
))
{
!
empty
(
$this
->
_
pendingFields
))
{
continue
;
}
...
...
@@ -1019,7 +1033,7 @@ class Doctrine_Query extends Doctrine_Query_Abstract implements Countable
array_unshift
(
$this
->
parts
[
'select'
],
implode
(
', '
,
$sql
));
}
$this
->
pendingFields
=
array
();
$this
->
_
pendingFields
=
array
();
// build the basic query
$q
=
$this
->
getQueryBase
();
...
...
@@ -1536,7 +1550,7 @@ class Doctrine_Query extends Doctrine_Query_Abstract implements Countable
$restoreState
=
false
;
// load fields if necessary
if
(
$loadFields
&&
empty
(
$this
->
_dqlParts
[
'select'
]))
{
$this
->
pendingFields
[
$componentAlias
]
=
array
(
'*'
);
$this
->
_
pendingFields
[
$componentAlias
]
=
array
(
'*'
);
}
}
$parent
=
$prevPath
;
...
...
lib/Doctrine/Query/Where.php
View file @
991f456f
...
...
@@ -74,17 +74,10 @@ class Doctrine_Query_Where extends Doctrine_Query_Condition
$alias
=
$this
->
query
->
getTableAlias
(
$reference
);
$table
=
$map
[
'table'
];
}
if
(
$this
->
query
->
getType
()
===
Doctrine_Query
::
SELECT
)
{
$first
=
$conn
->
quoteIdentifier
(
$alias
)
.
'.'
.
$conn
->
quoteIdentifier
(
$table
->
getColumnName
(
$field
));
}
else
{
$first
=
$conn
->
quoteIdentifier
(
$table
->
getColumnName
(
$field
));
}
}
else
{
$first
=
$this
->
query
->
parseClause
(
$first
);
}
}
$first
=
$this
->
query
->
parseClause
(
$first
);
$sql
=
$first
.
' '
.
$operator
.
' '
.
$this
->
parseValue
(
$value
,
$table
,
$field
);
return
$sql
;
...
...
@@ -174,4 +167,4 @@ class Doctrine_Query_Where extends Doctrine_Query_Condition
return
$operator
.
' ('
.
$this
->
query
->
createSubquery
()
->
parseQuery
(
$sub
,
false
)
->
getQuery
()
.
')'
;
}
}
\ No newline at end of file
}
tests/Query/WhereTestCase.php
View file @
991f456f
...
...
@@ -40,6 +40,7 @@ class Doctrine_Query_Where_TestCase extends Doctrine_UnitTestCase
$this
->
tables
=
array
(
'Entity'
,
'EnumTest'
,
'GroupUser'
,
'Account'
,
'Book'
);
parent
::
prepareTables
();
}
public
function
testDirectParameterSetting
()
{
$this
->
connection
->
clear
();
...
...
@@ -306,4 +307,12 @@ class Doctrine_Query_Where_TestCase extends Doctrine_UnitTestCase
$q
->
execute
(
array
(
1
,
'verified'
));
}
public
function
testLiteralValueAsInOperatorOperandIsSupported
()
{
$q
=
new
Doctrine_Query
();
$q
->
select
(
'u.id'
)
->
from
(
'User u'
)
->
where
(
'1 IN (1, 2)'
);
$this
->
assertEqual
(
$q
->
getSql
(),
'SELECT e.id AS e__id FROM entity e WHERE 1 IN (1, 2) AND (e.type = 0)'
);
}
}
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