summaryrefslogtreecommitdiff
path: root/includes
diff options
context:
space:
mode:
authorAngie Byron <webchick@24967.no-reply.drupal.org>2010-01-08 07:43:55 +0000
committerAngie Byron <webchick@24967.no-reply.drupal.org>2010-01-08 07:43:55 +0000
commitc92ddd4cb8899b55166c8bf2ca0edd1d95783cbe (patch)
tree4eea15a0e5b48ce4b18e5eb919dc0987a3b31735 /includes
parent85c680a1a0e4b0f48526a064eae94e4b77e0d303 (diff)
downloadbrdo-c92ddd4cb8899b55166c8bf2ca0edd1d95783cbe.tar.gz
brdo-c92ddd4cb8899b55166c8bf2ca0edd1d95783cbe.tar.bz2
#601768 by Crell and Damien Tournoud: Add a DatabaseStatementEmpty to allow complex query to return a proper empty set.
Diffstat (limited to 'includes')
-rw-r--r--includes/database/database.inc85
1 files changed, 85 insertions, 0 deletions
diff --git a/includes/database/database.inc b/includes/database/database.inc
index 916ca4cc6..98f3497ae 100644
--- a/includes/database/database.inc
+++ b/includes/database/database.inc
@@ -2005,6 +2005,91 @@ class DatabaseStatementBase extends PDOStatement implements DatabaseStatementInt
}
/**
+ * Empty implementation of a database statement.
+ *
+ * This class satisfies the requirements of being a database statement/result
+ * object, but does not actually contain data. It is useful when developers
+ * need to safely return an "empty" result set without connecting to an actual
+ * database. Calling code can then treat it the same as if it were an actual
+ * result set that happens to contain no records.
+ *
+ * @see SearchQuery
+ */
+class DatabaseStatementEmpty implements Iterator, DatabaseStatementInterface {
+
+ public function execute($args = array(), $options = array()) {
+ return FALSE;
+ }
+
+ public function getQueryString() {
+ return '';
+ }
+
+ public function rowCount() {
+ return 0;
+ }
+
+ public function setFetchMode($mode, $a1 = NULL, $a2 = array()) {
+ return;
+ }
+
+ public function fetch($mode = NULL, $cursor_orientation = NULL, $cursor_offset = NULL) {
+ return NULL;
+ }
+
+ public function fetchField($index = 0) {
+ return NULL;
+ }
+
+ public function fetchObject() {
+ return NULL;
+ }
+
+ public function fetchAssoc() {
+ return NULL;
+ }
+
+ function fetchAll($mode = NULL, $column_index = NULL, array $constructor_arguments = array()) {
+ return array();
+ }
+
+ public function fetchCol($index = 0) {
+ return array();
+ }
+
+ public function fetchAllKeyed($key_index = 0, $value_index = 1) {
+ return array();
+ }
+
+ public function fetchAllAssoc($key, $fetch = PDO::FETCH_OBJ) {
+ return array();
+ }
+
+ /* Implementations of Iterator. */
+
+ public function current() {
+ return NULL;
+ }
+
+ public function key() {
+ return NULL;
+ }
+
+ public function rewind() {
+ // Nothing to do: our DatabaseStatement can't be rewound.
+ }
+
+ public function next() {
+ // Do nothing, since this is an always-empty implementation.
+ }
+
+ public function valid() {
+ return FALSE;
+ }
+}
+
+
+/**
* The following utility functions are simply convenience wrappers.
* They should never, ever have any database-specific code in them.
*/