Skip to content
Permalink
Browse files

Adding test for named params in queries

  • Loading branch information...
lorenzo committed May 30, 2012
1 parent b0094b9 commit 8164dcace6d422983bb2d14ab9c9ac8d3b50bb9e
@@ -246,15 +246,24 @@ public function charset($collation) {
* @return void
**/
protected function _bindValues($statement, $params, $types) {
$offset = 1;
if (!empty($types) && is_int(key($types))) {
if (empty($params)) {
return;
}
if (!empty($types) && ctype_digit(key($types))) {
$params = array_values($params);
}
$annonymousParams = is_int(key($params)) ? true : false;
$offset = 1;
foreach ($params as $index => $value) {
if ($annonymousParams) {
$index += $offset;
}
if (isset($types[$index])) {
$statement->bindValue($index + $offset, $value, $type);
$statement->bindValue($index, $value, $type);
} else {
$statement->bindValue($index + $offset, $value);
$statement->bindValue($index, $value);
}
}
}
@@ -116,6 +116,12 @@ public function testExecuteWithArguments() {
$this->assertCount(1, $statement);
$result = $statement->fetch('assoc');
$this->assertEquals(array('total' => 6), $result);
$sql = 'SELECT 1 + :one + :two AS total';
$statement = $this->connection->execute($sql, array('one' => 2, 'two' => 3));
$this->assertCount(1, $statement);
$result = $statement->fetch('assoc');
$this->assertEquals(array('total' => 6), $result);
}
}

0 comments on commit 8164dca

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