public function where($condition, $parameters = array())
{
if ($condition === null) {
return $this->resetClause('WHERE');
}
if (!$condition) {
return $this;
}
if (is_array($condition)) {
// where(array("column1" => 1, "column2 > ?" => 2))
foreach ($condition as $key => $val) {
$this->where($key, $val);
}
return $this;
}
$args = func_get_args();
if (count($args) == 1) {
return $this->addStatement('WHERE', $condition);
}
// check that there are 2 arguments, a condition and a parameter value
// if the condition contains a parameter simply add them
// since its up to the user if it's valid sql or not
// Otherwise we're probably with just an identifier. So lets
// construct a new condition based on the passed parameter value.
if (count($args) == 2 && !preg_match('/(\\?|:\\w+)/i', $condition)) {
// condition is column only
if (is_null($parameters)) {
return $this->addStatement('WHERE', "{$condition} is NULL");
} elseif (is_array($args[1])) {
$in = $this->quote($args[1]);
return $this->addStatement('WHERE', "{$condition} IN {$in}");
}
$condition = "{$condition} = ?";
}
array_shift($args);
return $this->addStatement('WHERE', $condition, $args);
}