SqliteStatement.php 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. <?php
  2. /**
  3. * CakePHP(tm) : Rapid Development Framework (https://cakephp.org)
  4. * Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
  5. *
  6. * Licensed under The MIT License
  7. * For full copyright and license information, please see the LICENSE.txt
  8. * Redistributions of files must retain the above copyright notice.
  9. *
  10. * @copyright Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
  11. * @link https://cakephp.org CakePHP(tm) Project
  12. * @since 3.0.0
  13. * @license https://opensource.org/licenses/mit-license.php MIT License
  14. */
  15. namespace Cake\Database\Statement;
  16. /**
  17. * Statement class meant to be used by an Sqlite driver
  18. *
  19. * @internal
  20. */
  21. class SqliteStatement extends StatementDecorator
  22. {
  23. use BufferResultsTrait;
  24. /**
  25. * {@inheritDoc}
  26. *
  27. */
  28. public function execute($params = null)
  29. {
  30. if ($this->_statement instanceof BufferedStatement) {
  31. $this->_statement = $this->_statement->getInnerStatement();
  32. }
  33. if ($this->_bufferResults) {
  34. $this->_statement = new BufferedStatement($this->_statement, $this->_driver);
  35. }
  36. return $this->_statement->execute($params);
  37. }
  38. /**
  39. * Returns the number of rows returned of affected by last execution
  40. *
  41. * @return int
  42. */
  43. public function rowCount()
  44. {
  45. if (preg_match('/^(?:DELETE|UPDATE|INSERT)/i', $this->_statement->queryString)) {
  46. $changes = $this->_driver->prepare('SELECT CHANGES()');
  47. $changes->execute();
  48. $count = $changes->fetch()[0];
  49. $changes->closeCursor();
  50. return (int)$count;
  51. }
  52. return parent::rowCount();
  53. }
  54. }