Exemple #1
0
 protected function processHaving(PlatformInterface $platform, Adapter $adapter = null, ParameterContainer $parameterContainer = null)
 {
     if ($this->having->count() == 0) {
         return null;
     }
     $whereParts = $this->processExpression($this->having, $platform, $adapter, $this->processInfo['paramPrefix'] . 'having');
     if ($parameterContainer) {
         $parameterContainer->merge($whereParts->getParameterContainer());
     }
     return array($whereParts->getSql());
 }
 protected function processSubSelect(Select $subselect, PlatformInterface $platform, DriverInterface $driver = null, ParameterContainer $parameterContainer = null)
 {
     if ($driver) {
         $stmtContainer = new StatementContainer();
         // Track subselect prefix and count for parameters
         $this->processInfo['subselectCount']++;
         $subselect->processInfo['subselectCount'] = $this->processInfo['subselectCount'];
         $subselect->processInfo['paramPrefix'] = 'subselect' . $subselect->processInfo['subselectCount'];
         // call subselect
         $subselect->prepareStatement(new \Zend\Db\Adapter\Adapter($driver, $platform), $stmtContainer);
         // copy count
         $this->processInfo['subselectCount'] = $subselect->processInfo['subselectCount'];
         $parameterContainer->merge($stmtContainer->getParameterContainer()->getNamedArray());
         $sql = $stmtContainer->getSql();
     } else {
         $sql = $subselect->getSqlString($platform);
     }
     return $sql;
 }
Exemple #3
0
 protected function processOrder(PlatformInterface $platform, Adapter $adapter = null, ParameterContainer $parameterContainer = null)
 {
     if (empty($this->order)) {
         return null;
     }
     $orders = array();
     foreach ($this->order as $k => $v) {
         if ($v instanceof Expression) {
             /** @var $orderParts \Zend\Db\Adapter\StatementContainer */
             $orderParts = $this->processExpression($v, $platform, $adapter);
             if ($parameterContainer) {
                 $parameterContainer->merge($orderParts->getParameterContainer());
             }
             $orders[] = array($orderParts->getSql());
             continue;
         }
         if (is_int($k)) {
             if (strpos($v, ' ') !== false) {
                 list($k, $v) = preg_split('# #', $v, 2);
             } else {
                 $k = $v;
                 $v = self::ORDER_ASCENDING;
             }
         }
         if (strtoupper($v) == self::ORDER_DESCENDING) {
             $orders[] = array($platform->quoteIdentifierInFragment($k), self::ORDER_DESCENDING);
         } else {
             $orders[] = array($platform->quoteIdentifierInFragment($k), self::ORDER_ASCENDING);
         }
     }
     return array($orders);
 }
Exemple #4
0
 protected function processHaving(PlatformInterface $platform, Adapter $adapter = null, ParameterContainer $parameterContainer = null)
 {
     if ($this->having->count() == 0) {
         return null;
     }
     $whereParts = $this->processExpression($this->having, $platform, $adapter ? $adapter->getDriver() : null, 'having');
     if (count($whereParts['parameters']) > 0) {
         $parameterContainer->merge($whereParts['parameters']);
     }
     return array($whereParts['sql']);
 }
 protected function processJoins(PlatformInterface $platform, DriverInterface $driver = null, ParameterContainer $parameterContainer = null)
 {
     if (!$this->joins) {
         return null;
     }
     // process joins
     $joinSpecArgArray = array();
     foreach ($this->joins as $j => $join) {
         $joinSpecArgArray[$j] = array();
         // type
         $joinSpecArgArray[$j][] = strtoupper($join['type']);
         // table name
         $joinSpecArgArray[$j][] = is_array($join['name']) ? $platform->quoteIdentifier(current($join['name'])) . ' ' . $platform->quoteIdentifier(key($join['name'])) : $platform->quoteIdentifier($join['name']);
         // on expression
         $joinSpecArgArray[$j][] = $join['on'] instanceof ExpressionInterface ? $this->processExpression($join['on'], $platform, $driver, $this->processInfo['paramPrefix'] . 'join') : $platform->quoteIdentifierInFragment($join['on'], array('=', 'AND', 'OR', '(', ')', 'BETWEEN'));
         // on
         if ($joinSpecArgArray[$j][2] instanceof StatementContainerInterface) {
             if ($parameterContainer) {
                 $parameterContainer->merge($joinSpecArgArray[$j][2]->getParameterContainer());
             }
             $joinSpecArgArray[$j][2] = $joinSpecArgArray[$j][2]->getSql();
         }
     }
     return array($joinSpecArgArray);
 }
Exemple #6
0
 protected function processOption(PlatformInterface $platform, DriverInterface $driver = null, ParameterContainer $parameterContainer = null)
 {
     if (empty($this->option)) {
         return null;
     }
     // process options
     $options = array();
     foreach ($this->option as $optName => $optValue) {
         $optionSql = '';
         if ($optValue instanceof Expression) {
             $parameterPrefix = $this->processInfo['paramPrefix'] . 'option';
             $optionParts = $this->processExpression($optValue, $platform, $driver, $parameterPrefix);
             if ($parameterContainer) {
                 $parameterContainer->merge($optionParts->getParameterContainer());
             }
             $optionSql .= $optionParts->getSql();
         } else {
             if ($driver && $parameterContainer) {
                 $parameterContainer->offsetSet('option_' . $optName, $optValue);
                 $optionSql .= $driver->formatParameterName('option_' . $optName);
             } else {
                 $optionSql .= $platform->quoteValue($optValue);
             }
         }
         $options[] = array($platform->quoteIdentifier($optName), $optionSql);
     }
     return array($options);
 }
Exemple #7
0
 protected function processSubSelect(Select $subselect, PlatformInterface $platform, DriverInterface $driver = null, ParameterContainer $parameterContainer = null)
 {
     if ($driver) {
         $stmtContainer = new StatementContainer();
         // Track subselect prefix and count for parameters
         $this->processInfo['subselectCount']++;
         $subselect->processInfo['subselectCount'] = $this->processInfo['subselectCount'];
         $subselect->processInfo['paramPrefix'] = 'subselect' . $subselect->processInfo['subselectCount'];
         // call subselect
         if ($this instanceof PlatformDecoratorInterface) {
             /** @var Select|PlatformDecoratorInterface $subselectDecorator */
             $subselectDecorator = clone $this;
             $subselectDecorator->setSubject($subselect);
             $subselectDecorator->prepareStatement(new Adapter($driver, $platform), $stmtContainer);
         } else {
             $subselect->prepareStatement(new Adapter($driver, $platform), $stmtContainer);
         }
         // copy count
         $this->processInfo['subselectCount'] = $subselect->processInfo['subselectCount'];
         $parameterContainer->merge($stmtContainer->getParameterContainer()->getNamedArray());
         $sql = $stmtContainer->getSql();
     } else {
         if ($this instanceof PlatformDecoratorInterface) {
             $subselectDecorator = clone $this;
             $subselectDecorator->setSubject($subselect);
             $sql = $subselectDecorator->getSqlString($platform);
         } else {
             $sql = $subselect->getSqlString($platform);
         }
     }
     return $sql;
 }