Skip to content

Commit

Permalink
Implementing Connection::query() and added test
Browse files Browse the repository at this point in the history
  • Loading branch information
lorenzo committed Oct 14, 2012
1 parent 83a878f commit 193594c
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
7 changes: 5 additions & 2 deletions lib/Cake/Model/Datasource/Database/Connection.php
Expand Up @@ -118,7 +118,7 @@ public function execute($query, array $params = array(), array $types = array())
$this->_bindValues($statement, $params, $types);
$result = $statement->execute();
} else {
$result = $this->query($query);
$statement = $this->query($query);
}
return $statement;
}
Expand All @@ -129,7 +129,10 @@ public function execute($query, array $params = array(), array $types = array())
* @return Cake\Model\Datasource\Database\Statement
**/
public function query($sql) {

$this->connect();
$statement = $this->prepare($sql);
$statement->execute();
return $statement;
}

/**
Expand Down
Expand Up @@ -153,5 +153,17 @@ public function testExecuteWithMissingType() {
$statement = $this->connection->execute($sql, array(new \DateTime('2012-01-01')), array('bar'));
}

/**
* Tests executing a qury with no params also works
*
* @return void
**/
public function testExecuteWithNoParams() {
$sql = 'SELECT 1';
$statement = $this->connection->execute($sql);
$result = $statement->fetch();
$this->assertCount(1, $result);
$this->assertEquals(array(1), $result);
}

}

0 comments on commit 193594c

Please sign in to comment.