diff --git a/lib/Cake/Model/Datasource/Database/Driver/Sqlite.php b/lib/Cake/Model/Datasource/Database/Driver/Sqlite.php index 158257579bd..660480db7a5 100644 --- a/lib/Cake/Model/Datasource/Database/Driver/Sqlite.php +++ b/lib/Cake/Model/Datasource/Database/Driver/Sqlite.php @@ -2,7 +2,7 @@ namespace Cake\Model\Datasource\Database\Driver; -use Cake\Model\Datasource\Database\Statement; +use Cake\Model\Datasource\Database\Statement\BufferedStatement; use PDO; class Sqlite extends \Cake\Model\Datasource\Database\Driver { @@ -52,4 +52,15 @@ public function enabled() { return in_array('sqlite', PDO::getAvailableDrivers()); } +/** + * Prepares a sql statement to be executed + * + * @param string $sql + * @return Cake\Model\Datasource\Database\Statement + **/ + public function prepare($sql) { + $statement = $this->connection()->prepare($sql); + return new BufferedStatement($statement, $this); + } + } diff --git a/lib/Cake/Model/Datasource/Database/Statement.php b/lib/Cake/Model/Datasource/Database/Statement.php index cf87132de70..70ded226a74 100644 --- a/lib/Cake/Model/Datasource/Database/Statement.php +++ b/lib/Cake/Model/Datasource/Database/Statement.php @@ -86,8 +86,8 @@ public function __get($property) { * @param string|integer $type PDO type or name of configured Type class * @return void **/ - public function bindValue($column, $value, $type = null) { - if ($type !== null && !ctype_digit($type)) { + public function bindValue($column, $value, $type = 'string') { + if (!ctype_digit($type)) { list($value, $type) = $this->cast($value, $type); } $this->_statement->bindValue($column, $value, $type); @@ -196,9 +196,9 @@ public function fetch($type = 'num') { public function fetchAll($type = 'num') { switch ($type) { case 'num': - return $this->_statement->fetch(PDO::FETCH_NUM); + return $this->_statement->fetchAll(PDO::FETCH_NUM); case 'assoc': - return $this->_statement->fetch(PDO::FETCH_ASSOC); + return $this->_statement->fetchAll(PDO::FETCH_ASSOC); } } diff --git a/lib/Cake/Test/TestCase/Model/Datasource/Database/ConnectionTest.php b/lib/Cake/Test/TestCase/Model/Datasource/Database/ConnectionTest.php index 805814f783c..a078326736f 100644 --- a/lib/Cake/Test/TestCase/Model/Datasource/Database/ConnectionTest.php +++ b/lib/Cake/Test/TestCase/Model/Datasource/Database/ConnectionTest.php @@ -111,19 +111,19 @@ public function testPrepare() { **/ public function testExecuteWithArguments() { $sql = 'SELECT 1 + ?'; - $statement = $this->connection->execute($sql, [1]); + $statement = $this->connection->execute($sql, [1], array('integer')); $this->assertCount(1, $statement); $result = $statement->fetch(); $this->assertEquals([2], $result); $sql = 'SELECT 1 + ? + ? AS total'; - $statement = $this->connection->execute($sql, [2, 3]); + $statement = $this->connection->execute($sql, [2, 3], array('integer', 'integer')); $this->assertCount(1, $statement); $result = $statement->fetch('assoc'); $this->assertEquals(['total' => 6], $result); $sql = 'SELECT 1 + :one + :two AS total'; - $statement = $this->connection->execute($sql, ['one' => 2, 'two' => 3]); + $statement = $this->connection->execute($sql, ['one' => 2, 'two' => 3], array('one' => 'integer', 'two' => 'integer')); $this->assertCount(1, $statement); $result = $statement->fetch('assoc'); $this->assertEquals(['total' => 6], $result);