/**
  * Make string with conditions for ScalarOperatorNode
  *
  * @param AbstractScalarOperatorNode $node
  * @return string
  * @throws DataStoreException
  */
 public function makeScalarOperator(AbstractScalarOperatorNode $node)
 {
     $nodeName = $node->getNodeName();
     if (!isset($this->literals['ScalarOperator'][$nodeName])) {
         throw new DataStoreException('The Scalar Operator not suppoted: ' . $nodeName);
     }
     $value = $node->getValue() instanceof \DateTime ? $node->getValue()->format("Y-m-d") : $node->getValue();
     $strQuery = $this->literals['ScalarOperator'][$nodeName]['before'] . $this->prepareFieldName($node->getField()) . $this->literals['ScalarOperator'][$nodeName]['between'] . $this->prepareFieldValue($value) . $this->literals['ScalarOperator'][$nodeName]['after'];
     return $strQuery;
 }
Ejemplo n.º 2
0
 /**
  * Make string with conditions for ScalarOperatorNode
  *
  * @param AbstractScalarOperatorNode $node
  * @return string
  * @throws DataStoreException
  */
 public function makeScalarOperator(AbstractScalarOperatorNode $node)
 {
     $nodeName = $node->getNodeName();
     if (!isset($this->literals['ScalarOperator'][$nodeName])) {
         throw new DataStoreException('The Scalar Operator not suppoted: ' . $nodeName);
     }
     $value = $node->getValue() instanceof \DateTime ? $node->getValue()->format("Y-m-d") : $node->getValue();
     $strQuery = $this->literals['ScalarOperator'][$nodeName]['before'] . $this->prepareFieldName($node->getField());
     if (is_null($value)) {
         if ($nodeName === 'eq') {
             $strQuery .= "IS NULL";
         } else {
             if ($nodeName === 'ne') {
                 $strQuery .= "IS NOT NULL";
             } else {
                 throw new DataStoreException("Can't use `null` for " . $nodeName . ". Only for `eq` or `ne`");
             }
         }
     } else {
         $strQuery .= $this->literals['ScalarOperator'][$nodeName]['between'] . $this->prepareFieldValue($value);
     }
     $strQuery .= $this->literals['ScalarOperator'][$nodeName]['after'];
     return $strQuery;
 }
Ejemplo n.º 3
0
 /**
  * Process scalar condition
  *
  * @param AbstractScalarOperatorNode $node Query node
  * @return AbstractScalarOperatorNode
  */
 private function processScalarNode(AbstractScalarOperatorNode $node)
 {
     $copy = clone $node;
     $copy->setValue($this->getDbRefValue($node->getValue()));
     return $copy;
 }
Ejemplo n.º 4
0
 private function visitScalarNode(Node\Query\AbstractScalarOperatorNode $node, SqlBuilder $sqlBuilder)
 {
     static $operators = ['like' => 'LIKE', 'eq' => '=', 'ne' => '<>', 'lt' => '<', 'gt' => '>', 'le' => '<=', 'ge' => '>='];
     if (!isset($operators[$node->getNodeName()])) {
         throw new \LogicException(sprintf('Unknown scalar node "%s"', $node->getNodeName()));
     }
     $value = $node->getValue();
     if ($value instanceof Glob) {
         $value = $value->toLike();
     } elseif ($value instanceof \DateTimeInterface) {
         $value = $value->format(DATE_ISO8601);
     }
     $sqlBuilder->addWhereCondition($node->getField(), $value, $operators[$node->getNodeName()]);
 }