Skip to content

Commit

Permalink
Allowing for IN () queries to be made by setting an array as the valu…
Browse files Browse the repository at this point in the history
…e of a 'conditions' entry
  • Loading branch information
tombenner committed Mar 3, 2012
1 parent d67eab1 commit 8ed701b
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions core/models/mvc_database_adapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,18 @@ public function get_where_sql_clauses($conditions, $options=array()) {
$sql_clauses = array();
foreach ($conditions as $key => $value) {
if (is_array($value)) {
$clauses = $this->get_where_sql_clauses($value);
$logical_operator = $key == 'OR' ? ' OR ' : ' AND ';
$sql_clauses[] = '('.implode($logical_operator, $clauses).')';
if (is_string($key) && !in_array($key, array('OR', 'AND'))) {
$values = array();
foreach ($value as $val) {
$values[] = '"'.$this->escape($val).'"';
}
$values = implode(',', $values);
$sql_clauses[] = $this->escape($key).' IN ('.$values.')';
} else {
$clauses = $this->get_where_sql_clauses($value);
$logical_operator = $key == 'OR' ? ' OR ' : ' AND ';
$sql_clauses[] = '('.implode($logical_operator, $clauses).')';
}
continue;
}
if (strpos($key, '.') === false && $use_table_alias) {
Expand Down

0 comments on commit 8ed701b

Please sign in to comment.