Skip to content

Commit

Permalink
fix #7
Browse files Browse the repository at this point in the history
  • Loading branch information
ddliu committed Mar 9, 2016
1 parent 43c19d9 commit 200f58d
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/QueryBuilder.php
Expand Up @@ -700,8 +700,8 @@ public function update($table, $values, $conditions, $params = array()){
if (is_integer($k)) {
$updates[] = $value;
} else {
$updates[] = $this->db->quoteColumn($k).' = :'.$k;
$params[':'.$k] = $value;
$updates[] = $this->db->quoteColumn($k).' = :__'.$k;
$params[':__'.$k] = $value;
}
}

Expand Down
27 changes: 27 additions & 0 deletions tests/DatabaseTest.php
Expand Up @@ -187,4 +187,31 @@ public function testDangerousDelete() {

public function testTransaction(){
}

public function testUpdateParam() {
$id = $this->db->builder()
->insert('{{contact}}', [
'name' => 'user1',
'email' => 'user1@example.com',
'point' => 10,
]);

$affected = $this->db->builder()
->update('{{contact}}', [
'point' => 5,
], 'id = :id AND point = :point', [
':id' => $id,
':point' => 10,
]);

$this->assertEquals(1, $affected);

$result = $this->db->builder()
->select('point')
->from('{{contact}}')
->where('id = ?', [$id])
->queryValue();

$this->assertEquals(5, $result);
}
}

0 comments on commit 200f58d

Please sign in to comment.