Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
D
drupal
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Custom Issue Tracker
Custom Issue Tracker
Labels
Merge Requests
222
Merge Requests
222
Requirements
Requirements
List
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Analytics
Analytics
Code Review
Insights
Issue
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
project
drupal
Commits
cd5a8cf9
Commit
cd5a8cf9
authored
Jul 28, 2015
by
alexpott
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issue
#2541420
by amateescu, chx: Introduce QueryConditionTrait
parent
6220d90f
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
141 additions
and
336 deletions
+141
-336
core/lib/Drupal/Core/Database/Query/Delete.php
core/lib/Drupal/Core/Database/Query/Delete.php
+2
-85
core/lib/Drupal/Core/Database/Query/Merge.php
core/lib/Drupal/Core/Database/Query/Merge.php
+3
-76
core/lib/Drupal/Core/Database/Query/Query.php
core/lib/Drupal/Core/Database/Query/Query.php
+0
-21
core/lib/Drupal/Core/Database/Query/QueryConditionTrait.php
core/lib/Drupal/Core/Database/Query/QueryConditionTrait.php
+125
-0
core/lib/Drupal/Core/Database/Query/Select.php
core/lib/Drupal/Core/Database/Query/Select.php
+9
-69
core/lib/Drupal/Core/Database/Query/Update.php
core/lib/Drupal/Core/Database/Query/Update.php
+2
-85
No files found.
core/lib/Drupal/Core/Database/Query/Delete.php
View file @
cd5a8cf9
...
...
@@ -17,6 +17,8 @@
*/
class
Delete
extends
Query
implements
ConditionInterface
{
use
QueryConditionTrait
;
/**
* The table from which to delete.
*
...
...
@@ -24,15 +26,6 @@ class Delete extends Query implements ConditionInterface {
*/
protected
$table
;
/**
* The condition object for this query.
*
* Condition handling is handled via composition.
*
* @var Condition
*/
protected
$condition
;
/**
* Constructs a Delete object.
*
...
...
@@ -51,82 +44,6 @@ public function __construct(Connection $connection, $table, array $options = arr
$this
->
condition
=
new
Condition
(
'AND'
);
}
/**
* Implements Drupal\Core\Database\Query\ConditionInterface::condition().
*/
public
function
condition
(
$field
,
$value
=
NULL
,
$operator
=
'='
)
{
$this
->
condition
->
condition
(
$field
,
$value
,
$operator
);
return
$this
;
}
/**
* Implements Drupal\Core\Database\Query\ConditionInterface::isNull().
*/
public
function
isNull
(
$field
)
{
$this
->
condition
->
isNull
(
$field
);
return
$this
;
}
/**
* Implements Drupal\Core\Database\Query\ConditionInterface::isNotNull().
*/
public
function
isNotNull
(
$field
)
{
$this
->
condition
->
isNotNull
(
$field
);
return
$this
;
}
/**
* Implements Drupal\Core\Database\Query\ConditionInterface::exists().
*/
public
function
exists
(
SelectInterface
$select
)
{
$this
->
condition
->
exists
(
$select
);
return
$this
;
}
/**
* Implements Drupal\Core\Database\Query\ConditionInterface::notExists().
*/
public
function
notExists
(
SelectInterface
$select
)
{
$this
->
condition
->
notExists
(
$select
);
return
$this
;
}
/**
* Implements Drupal\Core\Database\Query\ConditionInterface::conditions().
*/
public
function
&
conditions
()
{
return
$this
->
condition
->
conditions
();
}
/**
* Implements Drupal\Core\Database\Query\ConditionInterface::arguments().
*/
public
function
arguments
()
{
return
$this
->
condition
->
arguments
();
}
/**
* Implements Drupal\Core\Database\Query\ConditionInterface::where().
*/
public
function
where
(
$snippet
,
$args
=
array
())
{
$this
->
condition
->
where
(
$snippet
,
$args
);
return
$this
;
}
/**
* Implements Drupal\Core\Database\Query\ConditionInterface::compile().
*/
public
function
compile
(
Connection
$connection
,
PlaceholderInterface
$queryPlaceholder
)
{
return
$this
->
condition
->
compile
(
$connection
,
$queryPlaceholder
);
}
/**
* Implements Drupal\Core\Database\Query\ConditionInterface::compiled().
*/
public
function
compiled
()
{
return
$this
->
condition
->
compiled
();
}
/**
* Executes the DELETE query.
*
...
...
core/lib/Drupal/Core/Database/Query/Merge.php
View file @
cd5a8cf9
...
...
@@ -49,6 +49,9 @@
* fields() and updateFields().
*/
class
Merge
extends
Query
implements
ConditionInterface
{
use
QueryConditionTrait
;
/**
* Returned by execute() if an INSERT query has been executed.
*/
...
...
@@ -339,82 +342,6 @@ public function key($field, $value = NULL) {
return
$this
;
}
/**
* Implements Drupal\Core\Database\Query\ConditionInterface::condition().
*/
public
function
condition
(
$field
,
$value
=
NULL
,
$operator
=
'='
)
{
$this
->
condition
->
condition
(
$field
,
$value
,
$operator
);
return
$this
;
}
/**
* Implements Drupal\Core\Database\Query\ConditionInterface::isNull().
*/
public
function
isNull
(
$field
)
{
$this
->
condition
->
isNull
(
$field
);
return
$this
;
}
/**
* Implements Drupal\Core\Database\Query\ConditionInterface::isNotNull().
*/
public
function
isNotNull
(
$field
)
{
$this
->
condition
->
isNotNull
(
$field
);
return
$this
;
}
/**
* Implements Drupal\Core\Database\Query\ConditionInterface::exists().
*/
public
function
exists
(
SelectInterface
$select
)
{
$this
->
condition
->
exists
(
$select
);
return
$this
;
}
/**
* Implements Drupal\Core\Database\Query\ConditionInterface::notExists().
*/
public
function
notExists
(
SelectInterface
$select
)
{
$this
->
condition
->
notExists
(
$select
);
return
$this
;
}
/**
* Implements Drupal\Core\Database\Query\ConditionInterface::conditions().
*/
public
function
&
conditions
()
{
return
$this
->
condition
->
conditions
();
}
/**
* Implements Drupal\Core\Database\Query\ConditionInterface::arguments().
*/
public
function
arguments
()
{
return
$this
->
condition
->
arguments
();
}
/**
* Implements Drupal\Core\Database\Query\ConditionInterface::where().
*/
public
function
where
(
$snippet
,
$args
=
array
())
{
$this
->
condition
->
where
(
$snippet
,
$args
);
return
$this
;
}
/**
* Implements Drupal\Core\Database\Query\ConditionInterface::compile().
*/
public
function
compile
(
Connection
$connection
,
PlaceholderInterface
$queryPlaceholder
)
{
return
$this
->
condition
->
compile
(
$connection
,
$queryPlaceholder
);
}
/**
* Implements Drupal\Core\Database\Query\ConditionInterface::compiled().
*/
public
function
compiled
()
{
return
$this
->
condition
->
compiled
();
}
/**
* Implements PHP magic __toString method to convert the query to a string.
*
...
...
core/lib/Drupal/Core/Database/Query/Query.php
View file @
cd5a8cf9
...
...
@@ -180,25 +180,4 @@ public function &getComments() {
return
$this
->
comments
;
}
/**
* {@inheritdoc}
*/
public
function
conditionGroupFactory
(
$conjunction
=
'AND'
)
{
return
new
Condition
(
$conjunction
);
}
/**
* {@inheritdoc}
*/
public
function
andConditionGroup
()
{
return
$this
->
conditionGroupFactory
(
'AND'
);
}
/**
* {@inheritdoc}
*/
public
function
orConditionGroup
()
{
return
$this
->
conditionGroupFactory
(
'OR'
);
}
}
core/lib/Drupal/Core/Database/Query/QueryConditionTrait.php
0 → 100644
View file @
cd5a8cf9
<?php
/**
* @file
* Contains \Drupal\Core\Database\Query\QueryConditionTrait.
*/
namespace
Drupal\Core\Database\Query
;
use
Drupal\Core\Database\Connection
;
/**
* Provides an implementation of ConditionInterface.
*
* @see \Drupal\Core\Database\Query\ConditionInterface
*/
trait
QueryConditionTrait
{
/**
* The condition object for this query.
*
* Condition handling is handled via composition.
*
* @var \Drupal\Core\Database\Query\Condition
*/
protected
$condition
;
/**
* Implements Drupal\Core\Database\Query\ConditionInterface::condition().
*/
public
function
condition
(
$field
,
$value
=
NULL
,
$operator
=
'='
)
{
$this
->
condition
->
condition
(
$field
,
$value
,
$operator
);
return
$this
;
}
/**
* Implements Drupal\Core\Database\Query\ConditionInterface::isNull().
*/
public
function
isNull
(
$field
)
{
$this
->
condition
->
isNull
(
$field
);
return
$this
;
}
/**
* Implements Drupal\Core\Database\Query\ConditionInterface::isNotNull().
*/
public
function
isNotNull
(
$field
)
{
$this
->
condition
->
isNotNull
(
$field
);
return
$this
;
}
/**
* Implements Drupal\Core\Database\Query\ConditionInterface::exists().
*/
public
function
exists
(
SelectInterface
$select
)
{
$this
->
condition
->
exists
(
$select
);
return
$this
;
}
/**
* Implements Drupal\Core\Database\Query\ConditionInterface::notExists().
*/
public
function
notExists
(
SelectInterface
$select
)
{
$this
->
condition
->
notExists
(
$select
);
return
$this
;
}
/**
* Implements Drupal\Core\Database\Query\ConditionInterface::conditions().
*/
public
function
&
conditions
()
{
return
$this
->
condition
->
conditions
();
}
/**
* Implements Drupal\Core\Database\Query\ConditionInterface::arguments().
*/
public
function
arguments
()
{
return
$this
->
condition
->
arguments
();
}
/**
* Implements Drupal\Core\Database\Query\ConditionInterface::where().
*/
public
function
where
(
$snippet
,
$args
=
array
())
{
$this
->
condition
->
where
(
$snippet
,
$args
);
return
$this
;
}
/**
* Implements Drupal\Core\Database\Query\ConditionInterface::compile().
*/
public
function
compile
(
Connection
$connection
,
PlaceholderInterface
$queryPlaceholder
)
{
$this
->
condition
->
compile
(
$connection
,
$queryPlaceholder
);
}
/**
* Implements Drupal\Core\Database\Query\ConditionInterface::compiled().
*/
public
function
compiled
()
{
return
$this
->
condition
->
compiled
();
}
/**
* Implements Drupal\Core\Database\Query\ConditionInterface::conditionGroupFactory().
*/
public
function
conditionGroupFactory
(
$conjunction
=
'AND'
)
{
return
new
Condition
(
$conjunction
);
}
/**
* Implements Drupal\Core\Database\Query\ConditionInterface::andConditionGroup().
*/
public
function
andConditionGroup
()
{
return
$this
->
conditionGroupFactory
(
'AND'
);
}
/**
* Implements Drupal\Core\Database\Query\ConditionInterface::orConditionGroup().
*/
public
function
orConditionGroup
()
{
return
$this
->
conditionGroupFactory
(
'OR'
);
}
}
core/lib/Drupal/Core/Database/Query/Select.php
View file @
cd5a8cf9
...
...
@@ -18,6 +18,8 @@
*/
class
Select
extends
Query
implements
SelectInterface
{
use
QueryConditionTrait
;
/**
* The fields to SELECT.
*
...
...
@@ -71,13 +73,6 @@ class Select extends Query implements SelectInterface {
*/
protected
$group
=
array
();
/**
* The conditional object for the WHERE clause.
*
* @var \Drupal\Core\Database\Query\Condition
*/
protected
$where
;
/**
* The conditional object for the HAVING clause.
*
...
...
@@ -139,7 +134,7 @@ public function __construct($table, $alias = NULL, Connection $connection, $opti
$options
[
'return'
]
=
Database
::
RETURN_STATEMENT
;
parent
::
__construct
(
$connection
,
$options
);
$conjunction
=
isset
(
$options
[
'conjunction'
])
?
$options
[
'conjunction'
]
:
'AND'
;
$this
->
where
=
new
Condition
(
$conjunction
);
$this
->
condition
=
new
Condition
(
$conjunction
);
$this
->
having
=
new
Condition
(
$conjunction
);
$this
->
addJoin
(
NULL
,
$table
,
$alias
);
}
...
...
@@ -188,21 +183,6 @@ public function getMetaData($key) {
return
isset
(
$this
->
alterMetaData
[
$key
])
?
$this
->
alterMetaData
[
$key
]
:
NULL
;
}
/**
* {@inheritdoc}
*/
public
function
condition
(
$field
,
$value
=
NULL
,
$operator
=
'='
)
{
$this
->
where
->
condition
(
$field
,
$value
,
$operator
);
return
$this
;
}
/**
* {@inheritdoc}
*/
public
function
&
conditions
()
{
return
$this
->
where
->
conditions
();
}
/**
* {@inheritdoc}
*/
...
...
@@ -211,7 +191,7 @@ public function arguments() {
return
NULL
;
}
$args
=
$this
->
where
->
arguments
()
+
$this
->
having
->
arguments
();
$args
=
$this
->
condition
->
arguments
()
+
$this
->
having
->
arguments
();
foreach
(
$this
->
tables
as
$table
)
{
if
(
$table
[
'arguments'
])
{
...
...
@@ -238,51 +218,11 @@ public function arguments() {
return
$args
;
}
/**
* {@inheritdoc}
*/
public
function
where
(
$snippet
,
$args
=
array
())
{
$this
->
where
->
where
(
$snippet
,
$args
);
return
$this
;
}
/**
* {@inheritdoc}
*/
public
function
isNull
(
$field
)
{
$this
->
where
->
isNull
(
$field
);
return
$this
;
}
/**
* {@inheritdoc}
*/
public
function
isNotNull
(
$field
)
{
$this
->
where
->
isNotNull
(
$field
);
return
$this
;
}
/**
* {@inheritdoc}
*/
public
function
exists
(
SelectInterface
$select
)
{
$this
->
where
->
exists
(
$select
);
return
$this
;
}
/**
* {@inheritdoc}
*/
public
function
notExists
(
SelectInterface
$select
)
{
$this
->
where
->
notExists
(
$select
);
return
$this
;
}
/**
* {@inheritdoc}
*/
public
function
compile
(
Connection
$connection
,
PlaceholderInterface
$queryPlaceholder
)
{
$this
->
where
->
compile
(
$connection
,
$queryPlaceholder
);
$this
->
condition
->
compile
(
$connection
,
$queryPlaceholder
);
$this
->
having
->
compile
(
$connection
,
$queryPlaceholder
);
foreach
(
$this
->
tables
as
$table
)
{
...
...
@@ -302,7 +242,7 @@ public function compile(Connection $connection, PlaceholderInterface $queryPlace
* {@inheritdoc}
*/
public
function
compiled
()
{
if
(
!
$this
->
where
->
compiled
()
||
!
$this
->
having
->
compiled
())
{
if
(
!
$this
->
condition
->
compiled
()
||
!
$this
->
having
->
compiled
())
{
return
FALSE
;
}
...
...
@@ -892,9 +832,9 @@ public function __toString() {
}
// WHERE
if
(
count
(
$this
->
where
))
{
if
(
count
(
$this
->
condition
))
{
// There is an implicit string cast on $this->condition.
$query
.
=
"
\n
WHERE "
.
$this
->
where
;
$query
.
=
"
\n
WHERE "
.
$this
->
condition
;
}
// GROUP BY
...
...
@@ -950,7 +890,7 @@ public function __clone() {
// want to clone the database connection object as that would duplicate the
// connection itself.
$this
->
where
=
clone
(
$this
->
where
);
$this
->
condition
=
clone
(
$this
->
condition
);
$this
->
having
=
clone
(
$this
->
having
);
foreach
(
$this
->
union
as
$key
=>
$aggregate
)
{
$this
->
union
[
$key
][
'query'
]
=
clone
(
$aggregate
[
'query'
]);
...
...
core/lib/Drupal/Core/Database/Query/Update.php
View file @
cd5a8cf9
...
...
@@ -17,6 +17,8 @@
*/
class
Update
extends
Query
implements
ConditionInterface
{
use
QueryConditionTrait
;
/**
* The table to update.
*
...
...
@@ -38,15 +40,6 @@ class Update extends Query implements ConditionInterface {
*/
protected
$arguments
=
array
();
/**
* The condition object for this query.
*
* Condition handling is handled via composition.
*
* @var \Drupal\Core\Database\Query\Condition
*/
protected
$condition
;
/**
* Array of fields to update to an expression in case of a duplicate record.
*
...
...
@@ -80,82 +73,6 @@ public function __construct(Connection $connection, $table, array $options = arr
$this
->
condition
=
new
Condition
(
'AND'
);
}
/**
* Implements Drupal\Core\Database\Query\ConditionInterface::condition().
*/
public
function
condition
(
$field
,
$value
=
NULL
,
$operator
=
'='
)
{
$this
->
condition
->
condition
(
$field
,
$value
,
$operator
);
return
$this
;
}
/**
* Implements Drupal\Core\Database\Query\ConditionInterface::isNull().
*/
public
function
isNull
(
$field
)
{
$this
->
condition
->
isNull
(
$field
);
return
$this
;
}
/**
* Implements Drupal\Core\Database\Query\ConditionInterface::isNotNull().
*/
public
function
isNotNull
(
$field
)
{
$this
->
condition
->
isNotNull
(
$field
);
return
$this
;
}
/**
* Implements Drupal\Core\Database\Query\ConditionInterface::exists().
*/
public
function
exists
(
SelectInterface
$select
)
{
$this
->
condition
->
exists
(
$select
);
return
$this
;
}
/**
* Implements Drupal\Core\Database\Query\ConditionInterface::notExists().
*/
public
function
notExists
(
SelectInterface
$select
)
{
$this
->
condition
->
notExists
(
$select
);
return
$this
;
}
/**
* Implements Drupal\Core\Database\Query\ConditionInterface::conditions().
*/
public
function
&
conditions
()
{
return
$this
->
condition
->
conditions
();
}
/**
* Implements Drupal\Core\Database\Query\ConditionInterface::arguments().
*/
public
function
arguments
()
{
return
$this
->
condition
->
arguments
();
}
/**
* Implements Drupal\Core\Database\Query\ConditionInterface::where().
*/
public
function
where
(
$snippet
,
$args
=
array
())
{
$this
->
condition
->
where
(
$snippet
,
$args
);
return
$this
;
}
/**
* Implements Drupal\Core\Database\Query\ConditionInterface::compile().
*/
public
function
compile
(
Connection
$connection
,
PlaceholderInterface
$queryPlaceholder
)
{
return
$this
->
condition
->
compile
(
$connection
,
$queryPlaceholder
);
}
/**
* Implements Drupal\Core\Database\Query\ConditionInterface::compiled().
*/
public
function
compiled
()
{
return
$this
->
condition
->
compiled
();
}
/**
* Adds a set of field->value pairs to be updated.
*
...
...
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