From 8ed701b0f12e4707a824dabb6d32a8b864520c1c Mon Sep 17 00:00:00 2001 From: Tom Benner Date: Sat, 3 Mar 2012 17:57:49 -0500 Subject: [PATCH] Allowing for IN () queries to be made by setting an array as the value of a 'conditions' entry --- core/models/mvc_database_adapter.php | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/core/models/mvc_database_adapter.php b/core/models/mvc_database_adapter.php index 762871f..7873431 100644 --- a/core/models/mvc_database_adapter.php +++ b/core/models/mvc_database_adapter.php @@ -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) {