Пример #1
0
 /**
  * @param Qom\DynamicOperandInterface $operand
  * @param Qom\SourceInterface $source The source
  * @param array &$sql The query parts
  * @return string
  * @throws \InvalidArgumentException
  */
 protected function parseOperand(Qom\DynamicOperandInterface $operand, Qom\SourceInterface $source, array &$sql)
 {
     if ($operand instanceof Qom\LowerCaseInterface) {
         $constraintSQL = 'LOWER(' . $this->parseOperand($operand->getOperand(), $source, $sql) . ')';
     } elseif ($operand instanceof Qom\UpperCaseInterface) {
         $constraintSQL = 'UPPER(' . $this->parseOperand($operand->getOperand(), $source, $sql) . ')';
     } elseif ($operand instanceof Qom\PropertyValueInterface) {
         $propertyName = $operand->getPropertyName();
         $className = '';
         if ($source instanceof Qom\SelectorInterface) {
             // FIXME Only necessary to differ from  Join
             $className = $source->getNodeTypeName();
             $tableName = $this->dataMapper->convertClassNameToTableName($className);
             while (strpos($propertyName, '.') !== FALSE) {
                 $this->addUnionStatement($className, $tableName, $propertyName, $sql);
             }
         } elseif ($source instanceof Qom\JoinInterface) {
             $tableName = $source->getJoinCondition()->getSelector1Name();
         }
         $columnName = $this->dataMapper->convertPropertyNameToColumnName($propertyName, $className);
         $constraintSQL = (!empty($tableName) ? $tableName . '.' : '') . $columnName;
     } else {
         throw new \InvalidArgumentException('Given operand has invalid type "' . get_class($operand) . '".', 1395710211);
     }
     return $constraintSQL;
 }
Пример #2
0
 /**
  * Parse a DynamicOperand into SQL and parameter arrays.
  *
  * @param DynamicOperandInterface $operand
  * @param string $operator One of the JCR_OPERATOR_* constants
  * @param SourceInterface $source The source
  * @param array &$sql The query parts
  * @param array &$parameters The parameters that will replace the markers
  * @param string $valueFunction an optional SQL function to apply to the operand value
  * @return void
  */
 protected function parseDynamicOperand(DynamicOperandInterface $operand, $operator, SourceInterface $source, array &$sql, array &$parameters, $valueFunction = NULL)
 {
     if ($operand instanceof LowerCaseInterface) {
         $this->parseDynamicOperand($operand->getOperand(), $operator, $source, $sql, $parameters, 'LOWER');
     } elseif ($operand instanceof UpperCaseInterface) {
         $this->parseDynamicOperand($operand->getOperand(), $operator, $source, $sql, $parameters, 'UPPER');
     } elseif ($operand instanceof PropertyValueInterface) {
         $propertyName = $operand->getPropertyName();
         // Reset value.
         $this->currentChildTableNameAlias = '';
         if ($source instanceof SelectorInterface) {
             $tableName = $this->query->getType();
             while (strpos($propertyName, '.') !== FALSE) {
                 $this->addUnionStatement($tableName, $propertyName, $sql);
             }
         } elseif ($source instanceof JoinInterface) {
             $tableName = $source->getJoinCondition()->getSelector1Name();
         }
         $columnName = $propertyName;
         $operator = $this->resolveOperator($operator);
         $constraintSQL = '';
         if ($valueFunction === NULL) {
             $constraintSQL .= (!empty($tableName) ? $tableName . '.' : '') . $columnName . ' ' . $operator . ' ?';
         } else {
             $constraintSQL .= $valueFunction . '(' . (!empty($tableName) ? $tableName . '.' : '') . $columnName . ') ' . $operator . ' ?';
         }
         if (isset($tableName) && !empty($this->currentChildTableNameAlias)) {
             $constraintSQL = $this->replaceTableNameByAlias($tableName, $this->currentChildTableNameAlias, $constraintSQL);
         }
         $sql['where'][] = $constraintSQL;
     }
 }