Added the zend framework 2 library, the path is specified in line no.26 in zend_modul...
[openemr.git] / interface / modules / zend_modules / library / Zend / Db / Sql / Platform / Oracle / SelectDecorator.php
blob660a7e74b3ab46d4e0a2561d162f6d36d2ae78ab
1 <?php
2 /**
3 * Zend Framework (http://framework.zend.com/)
5 * @link http://github.com/zendframework/zf2 for the canonical source repository
6 * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com)
7 * @license http://framework.zend.com/license/new-bsd New BSD License
8 */
10 namespace Zend\Db\Sql\Platform\Oracle;
12 use Zend\Db\Adapter\AdapterInterface;
13 use Zend\Db\Adapter\Driver\DriverInterface;
14 use Zend\Db\Adapter\ParameterContainer;
15 use Zend\Db\Adapter\Platform\PlatformInterface;
16 use Zend\Db\Adapter\StatementContainerInterface;
17 use Zend\Db\Sql\ExpressionInterface;
18 use Zend\Db\Sql\Platform\PlatformDecoratorInterface;
19 use Zend\Db\Sql\Select;
21 class SelectDecorator extends Select implements PlatformDecoratorInterface
24 /**
25 * @var Select
27 protected $select = null;
29 /**
30 * @param Select $select
32 public function setSubject($select)
34 $this->select = $select;
37 /**
38 * @see \Zend\Db\Sql\Select::renderTable
40 protected function renderTable($table, $alias = null)
42 return $table . ' ' . $alias;
45 /**
46 * @param AdapterInterface $adapter
47 * @param StatementContainerInterface $statementContainer
49 public function prepareStatement(AdapterInterface $adapter, StatementContainerInterface $statementContainer)
51 // localize variables
52 foreach (get_object_vars($this->select) as $name => $value) {
53 $this->{$name} = $value;
55 // set specifications
56 unset($this->specifications[self::LIMIT]);
57 unset($this->specifications[self::OFFSET]);
59 $this->specifications['LIMITOFFSET'] = null;
60 parent::prepareStatement($adapter, $statementContainer);
63 /**
64 * @param PlatformInterface $platform
65 * @return string
67 public function getSqlString(PlatformInterface $platform = null)
69 // localize variables
70 foreach (get_object_vars($this->select) as $name => $value) {
71 $this->{$name} = $value;
74 // set specifications
75 unset($this->specifications[self::LIMIT]);
76 unset($this->specifications[self::OFFSET]);
78 $this->specifications['LIMITOFFSET'] = null;
79 return parent::getSqlString($platform);
82 /**
83 * @param PlatformInterface $platform
84 * @param DriverInterface $driver
85 * @param ParameterContainer $parameterContainer
86 * @param $sqls
87 * @param $parameters
88 * @return null
90 protected function processLimitOffset(PlatformInterface $platform, DriverInterface $driver = null, ParameterContainer $parameterContainer = null, &$sqls, &$parameters)
92 if ($this->limit === null && $this->offset === null) {
93 return null;
96 $selectParameters = $parameters[self::SELECT];
98 $starSuffix = $platform->getIdentifierSeparator() . self::SQL_STAR;
99 foreach ($selectParameters[0] as $i => $columnParameters) {
100 if ($columnParameters[0] == self::SQL_STAR || (isset($columnParameters[1]) && $columnParameters[1] == self::SQL_STAR) || strpos($columnParameters[0], $starSuffix)) {
101 $selectParameters[0] = array(array(self::SQL_STAR));
102 break;
104 if (isset($columnParameters[1])) {
105 array_shift($columnParameters);
106 $selectParameters[0][$i] = $columnParameters;
110 if ($this->offset === null) {
111 $this->offset = 0;
114 // first, produce column list without compound names (using the AS portion only)
115 array_unshift($sqls, $this->createSqlFromSpecificationAndParameters(
116 array('SELECT %1$s FROM (SELECT b.%1$s, rownum b_rownum FROM (' => current($this->specifications[self::SELECT])), $selectParameters
119 if ($parameterContainer) {
120 if ($this->limit === null) {
121 array_push($sqls, ') b ) WHERE b_rownum > (:offset)');
122 $parameterContainer->offsetSet('offset', $this->offset, $parameterContainer::TYPE_INTEGER);
123 } else {
124 // create bottom part of query, with offset and limit using row_number
125 array_push($sqls, ') b WHERE rownum <= (:offset+:limit)) WHERE b_rownum >= (:offset + 1)');
126 $parameterContainer->offsetSet('offset', $this->offset, $parameterContainer::TYPE_INTEGER);
127 $parameterContainer->offsetSet('limit', $this->limit, $parameterContainer::TYPE_INTEGER);
129 } else {
130 if ($this->limit === null) {
131 array_push($sqls, ') b ) WHERE b_rownum > ('. (int) $this->offset. ')'
133 } else {
134 array_push($sqls, ') b WHERE rownum <= ('
135 . (int) $this->offset
136 . '+'
137 . (int) $this->limit
138 . ')) WHERE b_rownum >= ('
139 . (int) $this->offset
140 . ' + 1)'
145 $sqls[self::SELECT] = $this->createSqlFromSpecificationAndParameters(
146 $this->specifications[self::SELECT], $parameters[self::SELECT]
151 protected function processJoins(PlatformInterface $platform, DriverInterface $driver = null, ParameterContainer $parameterContainer = null)
153 if (!$this->joins) {
154 return null;
157 // process joins
158 $joinSpecArgArray = array();
159 foreach ($this->joins as $j => $join) {
160 $joinSpecArgArray[$j] = array();
161 // type
162 $joinSpecArgArray[$j][] = strtoupper($join['type']);
163 // table name
164 $joinSpecArgArray[$j][] = (is_array($join['name']))
165 ? $platform->quoteIdentifier(current($join['name'])) . ' ' . $platform->quoteIdentifier(key($join['name']))
166 : $platform->quoteIdentifier($join['name']);
167 // on expression
168 $joinSpecArgArray[$j][] = ($join['on'] instanceof ExpressionInterface)
169 ? $this->processExpression($join['on'], $platform, $driver, $this->processInfo['paramPrefix'] . 'join')
170 : $platform->quoteIdentifierInFragment($join['on'], array('=', 'AND', 'OR', '(', ')', 'BETWEEN')); // on
171 if ($joinSpecArgArray[$j][2] instanceof StatementContainerInterface) {
172 if ($parameterContainer) {
173 $parameterContainer->merge($joinSpecArgArray[$j][2]->getParameterContainer());
175 $joinSpecArgArray[$j][2] = $joinSpecArgArray[$j][2]->getSql();
179 return array($joinSpecArgArray);