Browse files

Added Subquery (WHERE IN only) support to the Where() call

  • Loading branch information...
1 parent 41e0c0b commit f93abebbd953aab2ca530b0de122f45effe0b338 @mlabrum committed Sep 12, 2011
Showing with 25 additions and 0 deletions.
  1. +25 −0 QueryBuilder.php
View
25 QueryBuilder.php
@@ -60,6 +60,11 @@ class QueryBuilder3 {
* Specifies that the where() column name is the full where field, eg where("users.password = password(?)", "test", QueryBuilder3::RAW_WHERE)
*/
const RAW_WHERE = "raw";
+
+ /**
+ * Specifies that the where() column contains a subquery
+ */
+ const SUB_QUERY = "subquery";
/**
* PDO database connection to use in executing the query.
@@ -795,6 +800,26 @@ private function getCriteriaString(array &$criteria, $usePlaceholders = true, ar
$currentCriterion['column'] = str_replace("?", $this->quote($currentCriterion['value']), $currentCriterion['column']);
}
break;
+
+ case self::SUB_QUERY:
+ $value = "";
+ $currentCriterion['operator'] = self::IN;
+
+ if($currentCriterion['value'] instanceof self){
+ if($usePlaceholders){
+ $value = $currentCriterion['value']->getQueryString();
+ $placeholderValues = array_merge($placeholderValues, $currentCriterion['value']->getPlaceholderValues());
+ }else{
+ $value = $currentCriterion['value']->getQueryString(false);
+ }
+ }else{
+ // Raw sql
+ $value = $currentCriterion['value'];
+ }
+
+ // Wrap the subquery
+ $value = self::BRACKET_OPEN . $value . self::BRACKET_CLOSE;
+ break;
default:
if ($usePlaceholders) {

0 comments on commit f93abeb

Please sign in to comment.