public function toQueryString(QueryContext $context)
 {
     if (empty($this->conditions)) {
         throw new DataTableException($this->schema->getSymbol(), "Can't execute DELETE query without conditions.");
     }
     $statements = array("DELETE FROM", $this->schema->getSymbol(), "WHERE", ConditionQueryBuilder::toString($context, $this->conditions));
     return implode(' ', $statements);
 }
 public function toQueryString(QueryContext $context)
 {
     $updatetion = UpdatetionQueryBuilder::toString($this->schema, $context, $this->updates);
     $condition = ConditionQueryBuilder::toString($context, $this->conditions);
     $statements = array();
     $statements[] = "UPDATE " . $this->schema->getSymbol();
     $statements[] = $updatetion;
     $statements[] = "WHERE " . $condition;
     return implode(' ', $statements);
 }
 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);
 }
Beispiel #4
0
 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);
     }
 }