Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Open sidebar
project
drupal
Commits
42c26e21
Commit
42c26e21
authored
Jul 28, 2015
by
alexpott
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issue
#2521832
by neclimdul, Crell, amateescu: Uncomment StatementInterface methods
parent
5e77cbed
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
175 additions
and
41 deletions
+175
-41
core/lib/Drupal/Core/Database/Driver/sqlite/Statement.php
core/lib/Drupal/Core/Database/Driver/sqlite/Statement.php
+4
-1
core/lib/Drupal/Core/Database/Statement.php
core/lib/Drupal/Core/Database/Statement.php
+59
-0
core/lib/Drupal/Core/Database/StatementEmpty.php
core/lib/Drupal/Core/Database/StatementEmpty.php
+53
-3
core/lib/Drupal/Core/Database/StatementInterface.php
core/lib/Drupal/Core/Database/StatementInterface.php
+4
-9
core/lib/Drupal/Core/Database/StatementPrefetch.php
core/lib/Drupal/Core/Database/StatementPrefetch.php
+55
-28
No files found.
core/lib/Drupal/Core/Database/Driver/sqlite/Statement.php
View file @
42c26e21
...
...
@@ -22,7 +22,7 @@
class
Statement
extends
StatementPrefetch
implements
StatementInterface
{
/**
*
SQLite specific implementation of getStatement().
*
{@inheritdoc}
*
* The PDO SQLite layer doesn't replace numeric placeholders in queries
* correctly, and this makes numeric expressions (such as COUNT(*) >= :count)
...
...
@@ -87,6 +87,9 @@ protected function getStatement($query, &$args = array()) {
return
$this
->
pdoConnection
->
prepare
(
$query
);
}
/**
* {@inheritdoc}
*/
public
function
execute
(
$args
=
array
(),
$options
=
array
())
{
try
{
$return
=
parent
::
execute
(
$args
,
$options
);
...
...
core/lib/Drupal/Core/Database/Statement.php
View file @
42c26e21
...
...
@@ -41,6 +41,9 @@ protected function __construct(Connection $dbh) {
$this
->
setFetchMode
(
\
PDO
::
FETCH_OBJ
);
}
/**
* {@inheritdoc}
*/
public
function
execute
(
$args
=
array
(),
$options
=
array
())
{
if
(
isset
(
$options
[
'fetch'
]))
{
if
(
is_string
(
$options
[
'fetch'
]))
{
...
...
@@ -68,14 +71,23 @@ public function execute($args = array(), $options = array()) {
return
$return
;
}
/**
* {@inheritdoc}
*/
public
function
getQueryString
()
{
return
$this
->
queryString
;
}
/**
* {@inheritdoc}
*/
public
function
fetchCol
(
$index
=
0
)
{
return
$this
->
fetchAll
(
\
PDO
::
FETCH_COLUMN
,
$index
);
}
/**
* {@inheritdoc}
*/
public
function
fetchAllAssoc
(
$key
,
$fetch
=
NULL
)
{
$return
=
array
();
if
(
isset
(
$fetch
))
{
...
...
@@ -95,6 +107,9 @@ public function fetchAllAssoc($key, $fetch = NULL) {
return
$return
;
}
/**
* {@inheritdoc}
*/
public
function
fetchAllKeyed
(
$key_index
=
0
,
$value_index
=
1
)
{
$return
=
array
();
$this
->
setFetchMode
(
\
PDO
::
FETCH_NUM
);
...
...
@@ -104,11 +119,17 @@ public function fetchAllKeyed($key_index = 0, $value_index = 1) {
return
$return
;
}
/**
* {@inheritdoc}
*/
public
function
fetchField
(
$index
=
0
)
{
// Call \PDOStatement::fetchColumn to fetch the field.
return
$this
->
fetchColumn
(
$index
);
}
/**
* {@inheritdoc}
*/
public
function
fetchAssoc
()
{
// Call \PDOStatement::fetch to fetch the row.
return
$this
->
fetch
(
\
PDO
::
FETCH_ASSOC
);
...
...
@@ -127,4 +148,42 @@ public function rowCount() {
}
}
/**
* {@inheritdoc}
*/
public
function
setFetchMode
(
$mode
,
$a1
=
NULL
,
$a2
=
array
())
{
// Call \PDOStatement::setFetchMode to set fetch mode.
// \PDOStatement is picky about the number of arguments in some cases so we
// need to be pass the exact number of arguments we where given.
switch
(
func_num_args
())
{
case
1
:
return
parent
::
setFetchMode
(
$mode
);
case
2
:
return
parent
::
setFetchMode
(
$mode
,
$a1
);
case
3
:
default
:
return
parent
::
setFetchMode
(
$mode
,
$a1
,
$a2
);
}
}
/**
* {@inheritdoc}
*/
public
function
fetchAll
(
$mode
=
NULL
,
$column_index
=
NULL
,
$constructor_arguments
=
NULL
)
{
// Call \PDOStatement::fetchAll to fetch all rows.
// \PDOStatement is picky about the number of arguments in some cases so we
// need to be pass the exact number of arguments we where given.
switch
(
func_num_args
())
{
case
0
:
return
parent
::
fetchAll
();
case
1
:
return
parent
::
fetchAll
(
$mode
);
case
2
:
return
parent
::
fetchAll
(
$mode
,
$column_index
);
case
3
:
default
:
return
parent
::
fetchAll
(
$mode
,
$column_index
,
$constructor_arguments
);
}
}
}
core/lib/Drupal/Core/Database/StatementEmpty.php
View file @
42c26e21
...
...
@@ -28,14 +28,23 @@ class StatementEmpty implements \Iterator, StatementInterface {
*/
public
$allowRowCount
=
FALSE
;
/**
* {@inheritdoc}
*/
public
function
execute
(
$args
=
array
(),
$options
=
array
())
{
return
FALSE
;
}
/**
* {@inheritdoc}
*/
public
function
getQueryString
()
{
return
''
;
}
/**
* {@inheritdoc}
*/
public
function
rowCount
()
{
if
(
$this
->
allowRowCount
)
{
return
0
;
...
...
@@ -43,61 +52,102 @@ public function rowCount() {
throw
new
RowCountException
();
}
/**
* {@inheritdoc}
*/
public
function
setFetchMode
(
$mode
,
$a1
=
NULL
,
$a2
=
array
())
{
return
;
}
/**
* {@inheritdoc}
*/
public
function
fetch
(
$mode
=
NULL
,
$cursor_orientation
=
NULL
,
$cursor_offset
=
NULL
)
{
return
NULL
;
}
/**
* {@inheritdoc}
*/
public
function
fetchField
(
$index
=
0
)
{
return
NULL
;
}
/**
* {@inheritdoc}
*/
public
function
fetchObject
()
{
return
NULL
;
}
/**
* {@inheritdoc}
*/
public
function
fetchAssoc
()
{
return
NULL
;
}
function
fetchAll
(
$mode
=
NULL
,
$column_index
=
NULL
,
array
$constructor_arguments
=
array
())
{
/**
* {@inheritdoc}
*/
public
function
fetchAll
(
$mode
=
NULL
,
$column_index
=
NULL
,
$constructor_arguments
=
NULL
)
{
return
array
();
}
/**
* {@inheritdoc}
*/
public
function
fetchCol
(
$index
=
0
)
{
return
array
();
}
/**
* {@inheritdoc}
*/
public
function
fetchAllKeyed
(
$key_index
=
0
,
$value_index
=
1
)
{
return
array
();
}
/**
* {@inheritdoc}
*/
public
function
fetchAllAssoc
(
$key
,
$fetch
=
NULL
)
{
return
array
();
}
/* Implementations of Iterator. */
/**
* {@inheritdoc}
*/
public
function
current
()
{
return
NULL
;
}
/**
* {@inheritdoc}
*/
public
function
key
()
{
return
NULL
;
}
/**
* {@inheritdoc}
*/
public
function
rewind
()
{
// Nothing to do: our DatabaseStatement can't be rewound.
}
/**
* {@inheritdoc}
*/
public
function
next
()
{
// Do nothing, since this is an always-empty implementation.
}
/**
* {@inheritdoc}
*/
public
function
valid
()
{
return
FALSE
;
}
}
core/lib/Drupal/Core/Database/StatementInterface.php
View file @
42c26e21
...
...
@@ -10,11 +10,6 @@
/**
* Represents a prepared statement.
*
* Some methods in that class are purposefully commented out. Due to a change in
* how PHP defines PDOStatement, we can't define a signature for those methods
* that will work the same way between versions older than 5.2.6 and later
* versions. See http://bugs.php.net/bug.php?id=42452 for more details.
*
* Child implementations should either extend PDOStatement:
* @code
* class Drupal\Core\Database\Driver\oracle\Statement extends PDOStatement implements Drupal\Core\Database\StatementInterface {}
...
...
@@ -100,7 +95,7 @@ public function rowCount();
* If $mode is PDO::FETCH_CLASS, the optional arguments to pass to the
* constructor.
*/
//
public function setFetchMode($mode, $a1 = NULL, $a2 = array());
public
function
setFetchMode
(
$mode
,
$a1
=
NULL
,
$a2
=
array
());
/**
* Fetches the next row from a result set.
...
...
@@ -119,7 +114,7 @@ public function rowCount();
* @return
* A result, formatted according to $mode.
*/
//
public function fetch($mode = NULL, $cursor_orientation = NULL, $cursor_offset = NULL);
public
function
fetch
(
$mode
=
NULL
,
$cursor_orientation
=
NULL
,
$cursor_offset
=
NULL
);
/**
* Returns a single field from the next record of a result set.
...
...
@@ -138,7 +133,7 @@ public function fetchField($index = 0);
* The object will be of the class specified by StatementInterface::setFetchMode()
* or stdClass if not specified.
*/
//
public function fetchObject();
public
function
fetchObject
();
/**
* Fetches the next row and returns it as an associative array.
...
...
@@ -165,7 +160,7 @@ public function fetchAssoc();
* @return
* An array of results.
*/
//
function fetchAll($mode = NULL, $column_index = NULL,
array
$constructor_arguments);
function
fetchAll
(
$mode
=
NULL
,
$column_index
=
NULL
,
$constructor_arguments
=
NULL
);
/**
* Returns an entire single column of a result set as an indexed array.
...
...
core/lib/Drupal/Core/Database/StatementPrefetch.php
View file @
42c26e21
...
...
@@ -139,14 +139,7 @@ public function __construct(\PDO $pdo_connection, Connection $connection, $query
}
/**
* Executes a prepared statement.
*
* @param $args
* An array of values with as many elements as there are bound parameters in the SQL statement being executed.
* @param $options
* An array of options for this query.
* @return
* TRUE on success, or FALSE on failure.
* {@inheritdoc}
*/
public
function
execute
(
$args
=
array
(),
$options
=
array
())
{
if
(
isset
(
$options
[
'fetch'
]))
{
...
...
@@ -236,29 +229,29 @@ protected function getStatement($query, &$args = array()) {
}
/**
*
Return the object's SQL query string.
*
{@inheritdoc}
*/
public
function
getQueryString
()
{
return
$this
->
queryString
;
}
/**
*
@see \PDOStatement::setFetchMode()
*
{@inheritdoc}
*/
public
function
setFetchMode
(
$
fetchStyl
e
,
$a
2
=
NULL
,
$a
3
=
NULL
)
{
$this
->
defaultFetchStyle
=
$
fetchStyl
e
;
switch
(
$
fetchStyl
e
)
{
public
function
setFetchMode
(
$
mod
e
,
$a
1
=
NULL
,
$a
2
=
array
()
)
{
$this
->
defaultFetchStyle
=
$
mod
e
;
switch
(
$
mod
e
)
{
case
\
PDO
::
FETCH_CLASS
:
$this
->
defaultFetchOptions
[
'class'
]
=
$a
2
;
if
(
$a
3
)
{
$this
->
defaultFetchOptions
[
'constructor_args'
]
=
$a
3
;
$this
->
defaultFetchOptions
[
'class'
]
=
$a
1
;
if
(
$a
2
)
{
$this
->
defaultFetchOptions
[
'constructor_args'
]
=
$a
2
;
}
break
;
case
\
PDO
::
FETCH_COLUMN
:
$this
->
defaultFetchOptions
[
'column'
]
=
$a
2
;
$this
->
defaultFetchOptions
[
'column'
]
=
$a
1
;
break
;
case
\
PDO
::
FETCH_INTO
:
$this
->
defaultFetchOptions
[
'object'
]
=
$a
2
;
$this
->
defaultFetchOptions
[
'object'
]
=
$a
1
;
break
;
}
...
...
@@ -274,8 +267,8 @@ public function setFetchMode($fetchStyle, $a2 = NULL, $a3 = NULL) {
* array position in $this->data and format it according to $this->fetchStyle
* and $this->fetchMode.
*
* @return
* The current row formatted as requested.
* @return
mixed
*
The current row formatted as requested.
*/
public
function
current
()
{
if
(
isset
(
$this
->
currentRow
))
{
...
...
@@ -327,16 +320,23 @@ public function current() {
}
}
/* Implementations of Iterator. */
/**
* {@inheritdoc}
*/
public
function
key
()
{
return
$this
->
currentKey
;
}
/**
* {@inheritdoc}
*/
public
function
rewind
()
{
// Nothing to do: our DatabaseStatement can't be rewound.
}
/**
* {@inheritdoc}
*/
public
function
next
()
{
if
(
!
empty
(
$this
->
data
))
{
$this
->
currentRow
=
reset
(
$this
->
data
);
...
...
@@ -348,6 +348,9 @@ public function next() {
}
}
/**
* {@inheritdoc}
*/
public
function
valid
()
{
return
isset
(
$this
->
currentRow
);
}
...
...
@@ -365,6 +368,9 @@ public function rowCount() {
}
}
/**
* {@inheritdoc}
*/
public
function
fetch
(
$fetch_style
=
NULL
,
$cursor_orientation
=
\
PDO
::
FETCH_ORI_NEXT
,
$cursor_offset
=
NULL
)
{
if
(
isset
(
$this
->
currentRow
))
{
// Set the fetch parameter.
...
...
@@ -398,10 +404,16 @@ public function fetchColumn($index = 0) {
}
}
/**
* {@inheritdoc}
*/
public
function
fetchField
(
$index
=
0
)
{
return
$this
->
fetchColumn
(
$index
);
}
/**
* {@inheritdoc}
*/
public
function
fetchObject
(
$class_name
=
NULL
,
$constructor_args
=
array
())
{
if
(
isset
(
$this
->
currentRow
))
{
if
(
!
isset
(
$class_name
))
{
...
...
@@ -427,6 +439,9 @@ public function fetchObject($class_name = NULL, $constructor_args = array()) {
}
}
/**
* {@inheritdoc}
*/
public
function
fetchAssoc
()
{
if
(
isset
(
$this
->
currentRow
))
{
$result
=
$this
->
currentRow
;
...
...
@@ -438,14 +453,17 @@ public function fetchAssoc() {
}
}
public
function
fetchAll
(
$fetch_style
=
NULL
,
$fetch_column
=
NULL
,
$constructor_args
=
NULL
)
{
$this
->
fetchStyle
=
isset
(
$fetch_style
)
?
$fetch_style
:
$this
->
defaultFetchStyle
;
/**
* {@inheritdoc}
*/
public
function
fetchAll
(
$mode
=
NULL
,
$column_index
=
NULL
,
$constructor_arguments
=
NULL
)
{
$this
->
fetchStyle
=
isset
(
$mode
)
?
$mode
:
$this
->
defaultFetchStyle
;
$this
->
fetchOptions
=
$this
->
defaultFetchOptions
;
if
(
isset
(
$
fetch_
column
))
{
$this
->
fetchOptions
[
'column'
]
=
$
fetch_
column
;
if
(
isset
(
$column
_index
))
{
$this
->
fetchOptions
[
'column'
]
=
$column
_index
;
}
if
(
isset
(
$constructor_args
))
{
$this
->
fetchOptions
[
'constructor_args'
]
=
$constructor_args
;
if
(
isset
(
$constructor_arg
ument
s
))
{
$this
->
fetchOptions
[
'constructor_args'
]
=
$constructor_arg
ument
s
;
}
$result
=
array
();
...
...
@@ -462,6 +480,9 @@ public function fetchAll($fetch_style = NULL, $fetch_column = NULL, $constructor
return
$result
;
}
/**
* {@inheritdoc}
*/
public
function
fetchCol
(
$index
=
0
)
{
if
(
isset
(
$this
->
columnNames
[
$index
]))
{
$result
=
array
();
...
...
@@ -477,6 +498,9 @@ public function fetchCol($index = 0) {
}
}
/**
* {@inheritdoc}
*/
public
function
fetchAllKeyed
(
$key_index
=
0
,
$value_index
=
1
)
{
if
(
!
isset
(
$this
->
columnNames
[
$key_index
])
||
!
isset
(
$this
->
columnNames
[
$value_index
]))
return
array
();
...
...
@@ -493,6 +517,9 @@ public function fetchAllKeyed($key_index = 0, $value_index = 1) {
return
$result
;
}
/**
* {@inheritdoc}
*/
public
function
fetchAllAssoc
(
$key
,
$fetch_style
=
NULL
)
{
$this
->
fetchStyle
=
isset
(
$fetch_style
)
?
$fetch_style
:
$this
->
defaultFetchStyle
;
$this
->
fetchOptions
=
$this
->
defaultFetchOptions
;
...
...
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