public function orWhereExists($clause) { if (isset($clause) && is_callable($clause)) { $this->addCondition(ConditionInfo::make(ConditionInfo::CONDITION_OR, WhereExistsConditionBuilder::make($clause))); } return $this; }
public function toQueryString(QueryContext $context) { if ($this->schema->getSoftDelete() && !$this->softDeleteLess) { $this->conditions[] = ConditionInfo::make(ConditionInfo::CONDITION_AND, WhereConditionBuilder::makeNormal($this->schema->getFieldSymbol(TableSchema::SOFT_DELETE_FIELD, false), '=', 0)); } $selection = SelectionQueryBuilder::toString($context, $this->selectFields) . ' FROM ' . $this->schema->getSymbol(); $join = JoinQueryBuilder::toString($context, $this->joins); $condition = ConditionQueryBuilder::toString($context, $this->conditions); $orders = OrderQueryBuilder::toString($context, $this->orders); $groups = GroupQueryBuilder::toString($context, $this->groups); $havings = HavingQueryBuilder::toString($context, $this->havings); $statements = array($selection); if (isset($join)) { $statements[] = $join; } if (isset($condition)) { $statements[] = "WHERE {$condition}"; } if (isset($orders)) { $statements[] = "ORDER BY {$orders}"; } if (isset($groups)) { $statements[] = "GROUP BY {$groups}"; } if (isset($havings)) { $statements[] = "HAVING ({$havings})"; } if (isset($this->limit)) { if ($this->skipOffset > 0 && $this->takeCount > 0) { $statements[] = "LIMIT {$this->skipOffset},{$this->takeCount}"; } else { if ($this->takeCount > 0) { $statements[] = "LIMIT {$this->takeCount}"; } } } return implode(' ', $statements); }
public function getQueryString(QueryContext $context) { if (!$this->subQuery) { if ($this->subQueryLimit) { throw new QueryException("Must be sub-query in [" . ConditionQueryBuilder::toString($context, $this->conditions) . "]"); } return ConditionQueryBuilder::toString($context, $this->conditions); } else { $context->schema($this->subQueryTableSchema); if (!$this->softDeleteLess && $this->subQueryTableSchema->getSoftDelete()) { $this->addCondition(ConditionInfo::make(ConditionInfo::CONDITION_AND, WhereConditionBuilder::makeNormal($this->subQueryTableSchema->getFieldSymbol(TableSchema::SOFT_DELETE_FIELD, false), '=', 0))); } $statements = array(); $statements[] = SelectionQueryBuilder::toString($context, $this->selectFields); $statements[] = 'FROM ' . $this->subQueryTableSchema->getSymbol(); $condition = ConditionQueryBuilder::toString($context, $this->conditions); if (isset($condition)) { $statements[] = "WHERE " . $condition; } return implode(' ', $statements); } }