Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
project
drupal
Commits
7613aa59
Commit
7613aa59
authored
Jun 27, 2009
by
Dries
Browse files
- Patch
#369314
by Berdir: make sub-selects work.
parent
c25f3ac5
Changes
2
Hide whitespace changes
Inline
Side-by-side
includes/database/query.inc
View file @
7613aa59
...
...
@@ -1179,6 +1179,7 @@ public function compile(DatabaseConnection $connection) {
}
$operator
+=
$operator_defaults
;
$placeholders
=
array
();
if
(
$condition
[
'value'
]
instanceof
SelectQuery
)
{
$placeholders
[]
=
(
string
)
$condition
[
'value'
];
$arguments
+=
$condition
[
'value'
]
->
arguments
();
...
...
@@ -1189,7 +1190,6 @@ public function compile(DatabaseConnection $connection) {
elseif
(
!
$operator
[
'delimiter'
])
{
$condition
[
'value'
]
=
array
(
$condition
[
'value'
]);
}
$placeholders
=
array
();
if
(
$operator
[
'use_value'
])
{
foreach
(
$condition
[
'value'
]
as
$value
)
{
$placeholder
=
':db_condition_placeholder_'
.
$next_placeholder
++
;
...
...
modules/simpletest/tests/database_test.test
View file @
7613aa59
...
...
@@ -1364,6 +1364,29 @@ class DatabaseSelectSubqueryTestCase extends DatabaseTestCase {
$this
->
assertEqual
(
count
(
$people
),
1
,
t
(
'Returned the correct number of rows.'
));
}
/**
* Test that we can use a subquery in a FROM clause.
*/
function
testConditionSubquerySelect
()
{
// Create a subquery, which is just a normal query object.
$subquery
=
db_select
(
'test_task'
,
'tt'
);
$subquery
->
addField
(
'tt'
,
'pid'
,
'pid'
);
$subquery
->
condition
(
'tt.priority'
,
1
);
// Create another query that joins against the virtual table resulting
// from the subquery.
$select
=
db_select
(
'test_task'
,
'tt2'
);
$select
->
addField
(
'tt2'
,
'task'
);
$select
->
condition
(
'tt2.pid'
,
$subquery
,
'IN'
);
// The resulting query should be equivalent to:
// SELECT tt2.name
// FROM test tt2
// WHERE tt2.pid IN (SELECT tt.pid AS pid FROM test_task tt WHERE tt.priority=1)
$people
=
$select
->
execute
()
->
fetchCol
();
$this
->
assertEqual
(
count
(
$people
),
5
,
t
(
'Returned the correct number of rows.'
));
}
/**
* Test that we can use a subquery in a JOIN clause.
*/
...
...
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