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
297
Merge Requests
297
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
26b14bc5
Commit
26b14bc5
authored
Mar 09, 2016
by
catch
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issue
#664722
by amateescu: Make insert queries Countable
parent
49a419de
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
25 additions
and
2 deletions
+25
-2
core/lib/Drupal/Core/Database/Query/Insert.php
core/lib/Drupal/Core/Database/Query/Insert.php
+1
-1
core/lib/Drupal/Core/Database/Query/InsertTrait.php
core/lib/Drupal/Core/Database/Query/InsertTrait.php
+7
-0
core/lib/Drupal/Core/Database/Query/Upsert.php
core/lib/Drupal/Core/Database/Query/Upsert.php
+1
-1
core/tests/Drupal/KernelTests/Core/Database/InsertTest.php
core/tests/Drupal/KernelTests/Core/Database/InsertTest.php
+16
-0
No files found.
core/lib/Drupal/Core/Database/Query/Insert.php
View file @
26b14bc5
...
...
@@ -14,7 +14,7 @@
*
* @ingroup database
*/
class
Insert
extends
Query
{
class
Insert
extends
Query
implements
\
Countable
{
use
InsertTrait
;
...
...
core/lib/Drupal/Core/Database/Query/InsertTrait.php
View file @
26b14bc5
...
...
@@ -181,4 +181,11 @@ protected function getInsertPlaceholderFragment(array $nested_insert_values, arr
return
$values
;
}
/**
* {@inheritdoc}
*/
public
function
count
()
{
return
count
(
$this
->
insertValues
);
}
}
core/lib/Drupal/Core/Database/Query/Upsert.php
View file @
26b14bc5
...
...
@@ -18,7 +18,7 @@
* Insert except the rows will be set to the desired values even if the key
* existed before.
*/
abstract
class
Upsert
extends
Query
{
abstract
class
Upsert
extends
Query
implements
\
Countable
{
use
InsertTrait
;
...
...
core/tests/Drupal/KernelTests/Core/Database/InsertTest.php
View file @
26b14bc5
...
...
@@ -25,6 +25,9 @@ function testSimpleInsert() {
'name'
=>
'Yoko'
,
'age'
=>
'29'
,
));
// Check how many records are queued for insertion.
$this
->
assertIdentical
(
$query
->
count
(),
1
,
'One record is queued for insertion.'
);
$query
->
execute
();
$num_records_after
=
db_query
(
'SELECT COUNT(*) FROM {test}'
)
->
fetchField
();
...
...
@@ -51,9 +54,15 @@ function testMultiInsert() {
'name'
=>
'Curly'
,
));
// Check how many records are queued for insertion.
$this
->
assertIdentical
(
$query
->
count
(),
2
,
'Two records are queued for insertion.'
);
// We should be able to say "use the field order".
// This is not the recommended mechanism for most cases, but it should work.
$query
->
values
(
array
(
'Moe'
,
'32'
));
// Check how many records are queued for insertion.
$this
->
assertIdentical
(
$query
->
count
(),
3
,
'Three records are queued for insertion.'
);
$query
->
execute
();
$num_records_after
=
(
int
)
db_query
(
'SELECT COUNT(*) FROM {test}'
)
->
fetchField
();
...
...
@@ -78,6 +87,8 @@ function testRepeatedInsert() {
'name'
=>
'Larry'
,
'age'
=>
'30'
,
));
// Check how many records are queued for insertion.
$this
->
assertIdentical
(
$query
->
count
(),
1
,
'One record is queued for insertion.'
);
$query
->
execute
();
// This should run the insert, but leave the fields intact.
// We should be able to specify values in any order if named.
...
...
@@ -85,10 +96,15 @@ function testRepeatedInsert() {
'age'
=>
'31'
,
'name'
=>
'Curly'
,
));
// Check how many records are queued for insertion.
$this
->
assertIdentical
(
$query
->
count
(),
1
,
'One record is queued for insertion.'
);
$query
->
execute
();
// We should be able to say "use the field order".
$query
->
values
(
array
(
'Moe'
,
'32'
));
// Check how many records are queued for insertion.
$this
->
assertIdentical
(
$query
->
count
(),
1
,
'One record is queued for insertion.'
);
$query
->
execute
();
$num_records_after
=
db_query
(
'SELECT COUNT(*) FROM {test}'
)
->
fetchField
();
...
...
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