Skip to content
Permalink
Browse files

Returns the number of affected rows in SQLite

  • Loading branch information...
lorenzo committed Mar 17, 2013
1 parent f379032 commit f00bb63f96b2ca609171cd30946299048eea0753
@@ -17,7 +17,7 @@
*/
namespace Cake\Model\Datasource\Database\Driver;
use Cake\Model\Datasource\Database\Statement\BufferedStatement;
use Cake\Model\Datasource\Database\Statement\SqliteStatement;
use Cake\Model\Datasource\Database\Dialect\SqliteDialectTrait;
use PDO;
@@ -88,7 +88,7 @@ public function enabled() {
*/
public function prepare($sql) {
$statement = $this->connection()->prepare($sql);
return new BufferedStatement($statement, $this);
return new SqliteStatement($statement, $this);
}
}
@@ -0,0 +1,42 @@
<?php
/**
* PHP Version 5.4
*
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
*
* Licensed under The MIT License
* For full copyright and license information, please see the LICENSE.txt
* Redistributions of files must retain the above copyright notice.
*
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
* @link http://cakephp.org CakePHP(tm) Project
* @package Cake.Model
* @since CakePHP(tm) v 3.0.0
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
namespace Cake\Model\Datasource\Database\Statement;
/**
* Statement class meant to be used by an Sqlite driver
*
*/
class SqliteStatement extends BufferedStatement {
/**
* Returns the number of rows returned of affected by last execution
*
* @return int
*/
public function rowCount() {
if (preg_match('/^(?:DELETE|UPDATE|INSERT)/i', $this->_statement->queryString)) {
$changes = $this->_driver->prepare('SELECT CHANGES()');
$changes->execute();
return $changes->fetch()[0];
}
return parent::rowCount();
}
}

0 comments on commit f00bb63

Please sign in to comment.
You can’t perform that action at this time.