Permalink
Browse files

Added prepared statements for WHERE IN

  • Loading branch information...
Daniel Khalil
Daniel Khalil committed Mar 25, 2013
1 parent 47ed3ba commit df32ec7517cd33ee4b2f7c83d28d807fc7d23751
Showing with 4 additions and 11 deletions.
  1. +4 −11 lib/Bacon/ORM/Collection.php
@@ -284,7 +284,7 @@ private function load()
$wc = $this->where_conditions();
$statement .= $wc->statement;
$values = array_merge($values, $wc->values);
$values = array_merge($values, $wc->values->to_array());
if (!empty($this->group_scope)) {
$statement .= ' GROUP BY ' . $this->group_scope;
@@ -339,20 +339,13 @@ private function where_conditions ()
foreach ($this->where_scope as $column_name => $condition) {
if (is_an_array($condition)) {
// array('id' => array(1, 2, 3)) => 'id IN (1, 2, 3)'
$conditions->push($this->table_name . '.' . $column_name . ' IN (' . str_repeat('?,', count($condition) - 1) . '?)');
$in_params = V();
$condition = V($condition);
foreach ($condition->to_array() as $c) {
$in_params->push($this->db->quote($c));
}
$conditions->push($this->table_name . '.' . $column_name . ' IN (' . $in_params->join(', ') . ')');
$values->push($condition);
} elseif (!$column_name) {
// String condition, for clauses that cover more complex conditions than simple ANDs.
$conditions->push("(" . $condition . ")")
$conditions->push("(" . $condition . ")");
} else {
if ($condition === null) {

0 comments on commit df32ec7

Please sign in to comment.