You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

OC_DB_StatementWrapper.php 3.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016, ownCloud, Inc.
  4. *
  5. * @author Bart Visscher <bartv@thisnet.nl>
  6. * @author Christoph Wurst <christoph@winzerhof-wurst.at>
  7. * @author Joas Schilling <coding@schilljs.com>
  8. * @author Jörn Friedrich Dreyer <jfd@butonic.de>
  9. * @author Lukas Reschke <lukas@statuscode.ch>
  10. * @author Morris Jobke <hey@morrisjobke.de>
  11. * @author Robin Appelman <robin@icewind.nl>
  12. * @author Thomas Müller <thomas.mueller@tmit.eu>
  13. *
  14. * @license AGPL-3.0
  15. *
  16. * This code is free software: you can redistribute it and/or modify
  17. * it under the terms of the GNU Affero General Public License, version 3,
  18. * as published by the Free Software Foundation.
  19. *
  20. * This program is distributed in the hope that it will be useful,
  21. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  22. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  23. * GNU Affero General Public License for more details.
  24. *
  25. * You should have received a copy of the GNU Affero General Public License, version 3,
  26. * along with this program. If not, see <http://www.gnu.org/licenses/>
  27. *
  28. */
  29. use OCP\DB\IPreparedStatement;
  30. /**
  31. * small wrapper around \Doctrine\DBAL\Driver\Statement to make it behave, more like an MDB2 Statement
  32. *
  33. * @method boolean bindValue(mixed $param, mixed $value, integer $type = null);
  34. * @method string errorCode();
  35. * @method array errorInfo();
  36. * @method integer rowCount();
  37. * @method array fetchAll(integer $fetchMode = null);
  38. */
  39. class OC_DB_StatementWrapper {
  40. /** @var IPreparedStatement */
  41. private $statement = null;
  42. /** @var bool */
  43. private $isManipulation = false;
  44. /** @var array */
  45. private $lastArguments = [];
  46. /**
  47. * @param IPreparedStatement $statement
  48. * @param boolean $isManipulation
  49. */
  50. public function __construct(IPreparedStatement $statement, $isManipulation) {
  51. $this->statement = $statement;
  52. $this->isManipulation = $isManipulation;
  53. }
  54. /**
  55. * pass all other function directly to the \Doctrine\DBAL\Driver\Statement
  56. */
  57. public function __call($name,$arguments) {
  58. return call_user_func_array([$this->statement,$name], $arguments);
  59. }
  60. /**
  61. * make execute return the result instead of a bool
  62. *
  63. * @param mixed[] $input
  64. * @return \OC_DB_StatementWrapper|int|bool
  65. * @deprecated
  66. */
  67. public function execute($input = []) {
  68. $this->lastArguments = $input;
  69. try {
  70. if (count($input) > 0) {
  71. $result = $this->statement->execute($input);
  72. } else {
  73. $result = $this->statement->execute();
  74. }
  75. } catch (\Doctrine\DBAL\Exception $e) {
  76. return false;
  77. }
  78. if ($this->isManipulation) {
  79. return $this->statement->rowCount();
  80. }
  81. return $this;
  82. }
  83. /**
  84. * provide an alias for fetch
  85. *
  86. * @return mixed
  87. * @deprecated
  88. */
  89. public function fetchRow() {
  90. return $this->statement->fetch();
  91. }
  92. /**
  93. * Provide a simple fetchOne.
  94. *
  95. * fetch single column from the next row
  96. * @return string
  97. * @deprecated
  98. */
  99. public function fetchOne() {
  100. return $this->statement->fetchOne();
  101. }
  102. /**
  103. * Closes the cursor, enabling the statement to be executed again.
  104. *
  105. * @deprecated Use Result::free() instead.
  106. */
  107. public function closeCursor(): void {
  108. $this->statement->closeCursor();
  109. }
  110. /**
  111. * Binds a PHP variable to a corresponding named or question mark placeholder in the
  112. * SQL statement that was use to prepare the statement.
  113. *
  114. * @param mixed $column Either the placeholder name or the 1-indexed placeholder index
  115. * @param mixed $variable The variable to bind
  116. * @param integer|null $type one of the PDO::PARAM_* constants
  117. * @param integer|null $length max length when using an OUT bind
  118. * @return boolean
  119. */
  120. public function bindParam($column, &$variable, $type = null, $length = null) {
  121. return $this->statement->bindParam($column, $variable, $type, $length);
  122. }
  123. }