Skip to content
Permalink
Browse files

More Sqlite tests passing

  • Loading branch information...
lorenzo committed Jul 11, 2012
1 parent 49269b1 commit 925a43842c91ee8801dde3f0fd675a8df762189f
@@ -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);
}
}
@@ -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);
}
}
@@ -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);

0 comments on commit 925a438

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