Skip to content

Commit

Permalink
More Sqlite tests passing
Browse files Browse the repository at this point in the history
  • Loading branch information
lorenzo committed Jul 11, 2012
1 parent 0988256 commit a7eae51
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 8 deletions.
13 changes: 12 additions & 1 deletion lib/Cake/Model/Datasource/Database/Driver/Sqlite.php
Expand Up @@ -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 {
Expand Down Expand Up @@ -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);
}

}
8 changes: 4 additions & 4 deletions lib/Cake/Model/Datasource/Database/Statement.php
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
}
}

Expand Down
Expand Up @@ -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);
Expand Down

0 comments on commit a7eae51

Please sign in to comment.