Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
drupal-3443915
Manage
Activity
Members
Labels
Plan
Custom issue tracker
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Model registry
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Issue forks
drupal-3443915
Commits
ad244e2c
Commit
ad244e2c
authored
12 years ago
by
David Rothstein
Browse files
Options
Downloads
Patches
Plain Diff
Issue
#1792380
by theo_: Fixed DatabaseCondition not cloning SelectQuery value object.
parent
7d76caba
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
includes/database/query.inc
+7
-2
7 additions, 2 deletions
includes/database/query.inc
modules/simpletest/tests/database_test.test
+39
-0
39 additions, 0 deletions
modules/simpletest/tests/database_test.test
with
46 additions
and
2 deletions
includes/database/query.inc
+
7
−
2
View file @
ad244e2c
...
...
@@ -1898,8 +1898,13 @@ public function __toString() {
function
__clone
()
{
$this
->
changed
=
TRUE
;
foreach
(
$this
->
conditions
as
$key
=>
$condition
)
{
if
(
$key
!==
'#conjunction'
&&
$condition
[
'field'
]
instanceOf
QueryConditionInterface
)
{
$this
->
conditions
[
$key
][
'field'
]
=
clone
(
$condition
[
'field'
]);
if
(
$key
!==
'#conjunction'
)
{
if
(
$condition
[
'field'
]
instanceOf
QueryConditionInterface
)
{
$this
->
conditions
[
$key
][
'field'
]
=
clone
(
$condition
[
'field'
]);
}
if
(
$condition
[
'value'
]
instanceOf
SelectQueryInterface
)
{
$this
->
conditions
[
$key
][
'value'
]
=
clone
(
$condition
[
'value'
]);
}
}
}
}
...
...
This diff is collapsed.
Click to expand it.
modules/simpletest/tests/database_test.test
+
39
−
0
View file @
ad244e2c
...
...
@@ -281,6 +281,45 @@ class DatabaseConnectionTestCase extends DatabaseTestCase {
}
}
/**
* Test cloning Select queries.
*/
class
DatabaseSelectCloneTest
extends
DatabaseTestCase
{
public
static
function
getInfo
()
{
return
array
(
'name'
=>
'Select tests, cloning'
,
'description'
=>
'Test cloning Select queries.'
,
'group'
=>
'Database'
,
);
}
/**
* Test that subqueries as value within conditions are cloned properly.
*/
function
testSelectConditionSubQueryCloning
()
{
$subquery
=
db_select
(
'test'
,
't'
);
$subquery
->
addField
(
't'
,
'id'
,
'id'
);
$subquery
->
condition
(
'age'
,
28
,
'<'
);
$query
=
db_select
(
'test'
,
't'
);
$query
->
addField
(
't'
,
'name'
,
'name'
);
$query
->
condition
(
'id'
,
$subquery
,
'IN'
);
$clone
=
clone
$query
;
// Cloned query should not be altered by the following modification
// happening on original query.
$subquery
->
condition
(
'age'
,
25
,
'>'
);
$clone_result
=
$clone
->
countQuery
()
->
execute
()
->
fetchField
();
$query_result
=
$query
->
countQuery
()
->
execute
()
->
fetchField
();
// Make sure the cloned query has not been modified
$this
->
assertEqual
(
3
,
$clone_result
,
'The cloned query returns the expected number of rows'
);
$this
->
assertEqual
(
2
,
$query_result
,
'The query returns the expected number of rows'
);
}
}
/**
* Test fetch actions, part 1.
*
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment