Version 1
[yaffs-website] / web / core / lib / Drupal / Core / Database / StatementEmpty.php
1 <?php
2
3 namespace Drupal\Core\Database;
4
5
6 /**
7  * Empty implementation of a database statement.
8  *
9  * This class satisfies the requirements of being a database statement/result
10  * object, but does not actually contain data.  It is useful when developers
11  * need to safely return an "empty" result set without connecting to an actual
12  * database.  Calling code can then treat it the same as if it were an actual
13  * result set that happens to contain no records.
14  *
15  * @see \Drupal\search\SearchQuery
16  */
17 class StatementEmpty implements \Iterator, StatementInterface {
18
19   /**
20    * Is rowCount() execution allowed.
21    *
22    * @var bool
23    */
24   public $allowRowCount = FALSE;
25
26   /**
27    * {@inheritdoc}
28    */
29   public function execute($args = [], $options = []) {
30     return FALSE;
31   }
32
33   /**
34    * {@inheritdoc}
35    */
36   public function getQueryString() {
37     return '';
38   }
39
40   /**
41    * {@inheritdoc}
42    */
43   public function rowCount() {
44     if ($this->allowRowCount) {
45       return 0;
46     }
47     throw new RowCountException();
48   }
49
50   /**
51    * {@inheritdoc}
52    */
53   public function setFetchMode($mode, $a1 = NULL, $a2 = []) {
54     return;
55   }
56
57   /**
58    * {@inheritdoc}
59    */
60   public function fetch($mode = NULL, $cursor_orientation = NULL, $cursor_offset = NULL) {
61     return NULL;
62   }
63
64   /**
65    * {@inheritdoc}
66    */
67   public function fetchField($index = 0) {
68     return NULL;
69   }
70
71   /**
72    * {@inheritdoc}
73    */
74   public function fetchObject() {
75     return NULL;
76   }
77
78   /**
79    * {@inheritdoc}
80    */
81   public function fetchAssoc() {
82     return NULL;
83   }
84
85   /**
86    * {@inheritdoc}
87    */
88   public function fetchAll($mode = NULL, $column_index = NULL, $constructor_arguments = NULL) {
89     return [];
90   }
91
92   /**
93    * {@inheritdoc}
94    */
95   public function fetchCol($index = 0) {
96     return [];
97   }
98
99   /**
100    * {@inheritdoc}
101    */
102   public function fetchAllKeyed($key_index = 0, $value_index = 1) {
103     return [];
104   }
105
106   /**
107    * {@inheritdoc}
108    */
109   public function fetchAllAssoc($key, $fetch = NULL) {
110     return [];
111   }
112
113   /**
114    * {@inheritdoc}
115    */
116   public function current() {
117     return NULL;
118   }
119
120   /**
121    * {@inheritdoc}
122    */
123   public function key() {
124     return NULL;
125   }
126
127   /**
128    * {@inheritdoc}
129    */
130   public function rewind() {
131     // Nothing to do: our DatabaseStatement can't be rewound.
132   }
133
134   /**
135    * {@inheritdoc}
136    */
137   public function next() {
138     // Do nothing, since this is an always-empty implementation.
139   }
140
141   /**
142    * {@inheritdoc}
143    */
144   public function valid() {
145     return FALSE;
146   }
147
148 }