StatementEmpty.php 2.5 KB

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