public function fetchRelatedObjectRefsOfEntity(MySQLi $mySQLi, ObjectEntity $otherEntity, QueryContext $queryContext, Scope $scope, array &$fetchedObjectRefs)
 {
     // Find the corresponding relationship, ignoring link-relationships.
     $hasTerminatedObjects = FALSE;
     foreach ($this->objectEntity->getRelationships() as $relationship) {
         if ($relationship->getOppositeEntity($this->objectEntity) != $otherEntity) {
             continue;
         }
         // Select the id of the related object.
         $objectIdColumnName = $otherEntity->getObjectIdColumnName();
         $query = new QueryRelatedEntity($this->objectEntity, $this->id, $relationship, $queryContext, $scope);
         $query->setPropertyNames(array($objectIdColumnName));
         $queryString = $query->getQueryString();
         $queryResult = $mySQLi->query($queryString);
         if (!$queryResult) {
             throw new Exception("Error fetching ObjectRefs of entity '" . $otherEntity->getName() . "', associated to '" . $this->objectEntity->getName() . "[{$this->id}]' - " . $mySQLi->error . "\n<!--\n{$queryString}\n-->");
         }
         while ($dbObject = $queryResult->fetch_assoc()) {
             $objectRef = new ObjectRef($otherEntity, $dbObject[$objectIdColumnName]);
             if (!$queryContext->getParameterPublished() and isset($dbObject[QueryEntity::ID_TERMINATED])) {
                 $hasTerminatedObjects = TRUE;
             } else {
                 // Always use the objectRef if we're fetching published data or if it's not terminated.
                 $fetchedObjectRefs[] = $objectRef;
             }
         }
         $queryResult->close();
     }
     return $hasTerminatedObjects;
 }
 private static function parseJoinInfo(QueryContext $context, JoinInfo $join)
 {
     $context->schema($join->schema);
     $conditions = array();
     if (isset($join->clause)) {
         $joinQuery = new JoinQuery();
         call_user_func($join->clause, $joinQuery);
         $conditions = $joinQuery->getConditions();
         if (!$joinQuery->getSoftDeleteLess() && $join->schema->getSoftDelete()) {
             $conditions[] = JoinConditionInfo::make(ConditionInfo::CONDITION_AND, TableSchema::SOFT_DELETE_FIELD, '=', 0, false);
         }
     } else {
         $conditions[] = $join->condition;
     }
     $statements = array();
     $statements[] = $join->leftJoin ? "LEFT JOIN" : "JOIN";
     $statements[] = $join->schema->getSymbol();
     if (count($conditions) > 0) {
         $statements[] = "ON (";
         $first = false;
         foreach ($conditions as $item) {
             $items = array();
             /**
              * @var JoinConditionInfo $item
              */
             if (!$first) {
                 $first = true;
             } else {
                 $items[] = $item->orAnd;
             }
             if (!$item->whereCondition) {
                 $field = FieldInfo::make($item->onField);
                 $value = FieldInfo::make($item->onValue);
                 $items[] = $field->getName($context) . " {$item->onOperator} " . $value->getName($context);
             } else {
                 if ($item->onValue instanceof Raw) {
                     $items[] = "{$item->onField} {$item->onOperator} " . $item->onValue->getValue();
                 } else {
                     $items[] = "{$item->onField} {$item->onOperator} ?";
                     $context->param($item->onValue);
                 }
             }
             $statements[] = implode(' ', $items);
         }
         $statements[] = ")";
     }
     return implode(' ', $statements);
 }
Beispiel #3
0
 public function quote($value)
 {
     $this->getContext();
     //context must be available
     if (null === $value) {
         return 'NULL';
     }
     if (is_array($value)) {
         // (a, b) IN ((1, 2), (3, 4))
         return '(' . implode(', ', array_map(array($this, 'quote'), $value)) . ')';
     }
     if ($value instanceof DateTime) {
         return $this->context->getDriver()->formatDateTime($value);
     }
     if (is_float($value)) {
         return sprintf('%F', $value);
         // otherwise depends on setlocale()
     }
     if (is_bool($value)) {
         return $this->context->getDriver()->formatBool($value);
     }
     if (is_int($value) || $value instanceof SqlLiteral) {
         // number or SQL code - for example "NOW()"
         return (string) $value;
     }
     return $this->context->getPreprocessor()->quote($value);
 }
Beispiel #4
0
 public function applyMatcher($expression, QueryContext $context)
 {
     if (empty($this->values)) {
         return '0';
     }
     if (count($this->values) == 1) {
         return $expression . ' = ' . $context->append((string) $this->values[0]);
     }
     $sql = $expression . ' IN (';
     foreach ($this->values as $i => $value) {
         if ($i != 0) {
             $sql .= ', ';
         }
         $sql .= $context->append($value);
     }
     return $sql . ')';
 }
Beispiel #5
0
 public function applyMatcher($expression, QueryContext $context)
 {
     return $expression . ' REGEXP ' . $context->append($this->regex);
 }
Beispiel #6
0
 public function applyMatcher($expression, QueryContext $context)
 {
     return $expression . ' LIKE ' . $context->append($this->pattern);
 }