@@ -32,165 +32,165 @@ |
||
| 32 | 32 | |
| 33 | 33 | class OCIExpressionBuilder extends ExpressionBuilder { |
| 34 | 34 | |
| 35 | - /** |
|
| 36 | - * @param mixed $column |
|
| 37 | - * @param mixed|null $type |
|
| 38 | - * @return array|IQueryFunction|string |
|
| 39 | - */ |
|
| 40 | - protected function prepareColumn($column, $type) { |
|
| 41 | - if ($type === IQueryBuilder::PARAM_STR && !is_array($column) && !($column instanceof IParameter) && !($column instanceof ILiteral)) { |
|
| 42 | - $column = $this->castColumn($column, $type); |
|
| 43 | - } else { |
|
| 44 | - $column = $this->helper->quoteColumnNames($column); |
|
| 45 | - } |
|
| 46 | - return $column; |
|
| 47 | - } |
|
| 48 | - |
|
| 49 | - /** |
|
| 50 | - * @inheritdoc |
|
| 51 | - */ |
|
| 52 | - public function comparison($x, $operator, $y, $type = null) { |
|
| 53 | - $x = $this->prepareColumn($x, $type); |
|
| 54 | - $y = $this->prepareColumn($y, $type); |
|
| 55 | - |
|
| 56 | - return $this->expressionBuilder->comparison($x, $operator, $y); |
|
| 57 | - } |
|
| 58 | - |
|
| 59 | - /** |
|
| 60 | - * @inheritdoc |
|
| 61 | - */ |
|
| 62 | - public function eq($x, $y, $type = null) { |
|
| 63 | - $x = $this->prepareColumn($x, $type); |
|
| 64 | - $y = $this->prepareColumn($y, $type); |
|
| 65 | - |
|
| 66 | - return $this->expressionBuilder->eq($x, $y); |
|
| 67 | - } |
|
| 68 | - |
|
| 69 | - /** |
|
| 70 | - * @inheritdoc |
|
| 71 | - */ |
|
| 72 | - public function neq($x, $y, $type = null) { |
|
| 73 | - $x = $this->prepareColumn($x, $type); |
|
| 74 | - $y = $this->prepareColumn($y, $type); |
|
| 75 | - |
|
| 76 | - return $this->expressionBuilder->neq($x, $y); |
|
| 77 | - } |
|
| 78 | - |
|
| 79 | - /** |
|
| 80 | - * @inheritdoc |
|
| 81 | - */ |
|
| 82 | - public function lt($x, $y, $type = null) { |
|
| 83 | - $x = $this->prepareColumn($x, $type); |
|
| 84 | - $y = $this->prepareColumn($y, $type); |
|
| 85 | - |
|
| 86 | - return $this->expressionBuilder->lt($x, $y); |
|
| 87 | - } |
|
| 88 | - |
|
| 89 | - /** |
|
| 90 | - * @inheritdoc |
|
| 91 | - */ |
|
| 92 | - public function lte($x, $y, $type = null) { |
|
| 93 | - $x = $this->prepareColumn($x, $type); |
|
| 94 | - $y = $this->prepareColumn($y, $type); |
|
| 95 | - |
|
| 96 | - return $this->expressionBuilder->lte($x, $y); |
|
| 97 | - } |
|
| 98 | - |
|
| 99 | - /** |
|
| 100 | - * @inheritdoc |
|
| 101 | - */ |
|
| 102 | - public function gt($x, $y, $type = null) { |
|
| 103 | - $x = $this->prepareColumn($x, $type); |
|
| 104 | - $y = $this->prepareColumn($y, $type); |
|
| 105 | - |
|
| 106 | - return $this->expressionBuilder->gt($x, $y); |
|
| 107 | - } |
|
| 108 | - |
|
| 109 | - /** |
|
| 110 | - * @inheritdoc |
|
| 111 | - */ |
|
| 112 | - public function gte($x, $y, $type = null) { |
|
| 113 | - $x = $this->prepareColumn($x, $type); |
|
| 114 | - $y = $this->prepareColumn($y, $type); |
|
| 115 | - |
|
| 116 | - return $this->expressionBuilder->gte($x, $y); |
|
| 117 | - } |
|
| 118 | - |
|
| 119 | - /** |
|
| 120 | - * @inheritdoc |
|
| 121 | - */ |
|
| 122 | - public function in($x, $y, $type = null) { |
|
| 123 | - $x = $this->prepareColumn($x, $type); |
|
| 124 | - $y = $this->prepareColumn($y, $type); |
|
| 125 | - |
|
| 126 | - return $this->expressionBuilder->in($x, $y); |
|
| 127 | - } |
|
| 128 | - |
|
| 129 | - /** |
|
| 130 | - * @inheritdoc |
|
| 131 | - */ |
|
| 132 | - public function notIn($x, $y, $type = null) { |
|
| 133 | - $x = $this->prepareColumn($x, $type); |
|
| 134 | - $y = $this->prepareColumn($y, $type); |
|
| 135 | - |
|
| 136 | - return $this->expressionBuilder->notIn($x, $y); |
|
| 137 | - } |
|
| 138 | - |
|
| 139 | - /** |
|
| 140 | - * Creates a $x = '' statement, because Oracle needs a different check |
|
| 141 | - * |
|
| 142 | - * @param string $x The field in string format to be inspected by the comparison. |
|
| 143 | - * @return string |
|
| 144 | - * @since 13.0.0 |
|
| 145 | - */ |
|
| 146 | - public function emptyString($x) { |
|
| 147 | - return $this->isNull($x); |
|
| 148 | - } |
|
| 149 | - |
|
| 150 | - /** |
|
| 151 | - * Creates a `$x <> ''` statement, because Oracle needs a different check |
|
| 152 | - * |
|
| 153 | - * @param string $x The field in string format to be inspected by the comparison. |
|
| 154 | - * @return string |
|
| 155 | - * @since 13.0.0 |
|
| 156 | - */ |
|
| 157 | - public function nonEmptyString($x) { |
|
| 158 | - return $this->isNotNull($x); |
|
| 159 | - } |
|
| 160 | - |
|
| 161 | - /** |
|
| 162 | - * Returns a IQueryFunction that casts the column to the given type |
|
| 163 | - * |
|
| 164 | - * @param string $column |
|
| 165 | - * @param mixed $type One of IQueryBuilder::PARAM_* |
|
| 166 | - * @return IQueryFunction |
|
| 167 | - */ |
|
| 168 | - public function castColumn($column, $type) { |
|
| 169 | - if ($type === IQueryBuilder::PARAM_STR) { |
|
| 170 | - $column = $this->helper->quoteColumnName($column); |
|
| 171 | - return new QueryFunction('to_char(' . $column . ')'); |
|
| 172 | - } |
|
| 173 | - if ($type === IQueryBuilder::PARAM_INT) { |
|
| 174 | - $column = $this->helper->quoteColumnName($column); |
|
| 175 | - return new QueryFunction('to_number(to_char(' . $column . '))'); |
|
| 176 | - } |
|
| 177 | - |
|
| 178 | - return parent::castColumn($column, $type); |
|
| 179 | - } |
|
| 180 | - |
|
| 181 | - /** |
|
| 182 | - * @inheritdoc |
|
| 183 | - */ |
|
| 184 | - public function like($x, $y, $type = null) { |
|
| 185 | - return parent::like($x, $y, $type) . " ESCAPE '\\'"; |
|
| 186 | - } |
|
| 187 | - |
|
| 188 | - /** |
|
| 189 | - * @inheritdoc |
|
| 190 | - */ |
|
| 191 | - public function iLike($x, $y, $type = null) { |
|
| 192 | - $x = $this->helper->quoteColumnName($x); |
|
| 193 | - $y = $this->helper->quoteColumnName($y); |
|
| 194 | - return new QueryFunction('REGEXP_LIKE(' . $x . ', \'^\' || REPLACE(REPLACE(' . $y . ', \'%\', \'.*\'), \'_\', \'.\') || \'$\', \'i\')'); |
|
| 195 | - } |
|
| 35 | + /** |
|
| 36 | + * @param mixed $column |
|
| 37 | + * @param mixed|null $type |
|
| 38 | + * @return array|IQueryFunction|string |
|
| 39 | + */ |
|
| 40 | + protected function prepareColumn($column, $type) { |
|
| 41 | + if ($type === IQueryBuilder::PARAM_STR && !is_array($column) && !($column instanceof IParameter) && !($column instanceof ILiteral)) { |
|
| 42 | + $column = $this->castColumn($column, $type); |
|
| 43 | + } else { |
|
| 44 | + $column = $this->helper->quoteColumnNames($column); |
|
| 45 | + } |
|
| 46 | + return $column; |
|
| 47 | + } |
|
| 48 | + |
|
| 49 | + /** |
|
| 50 | + * @inheritdoc |
|
| 51 | + */ |
|
| 52 | + public function comparison($x, $operator, $y, $type = null) { |
|
| 53 | + $x = $this->prepareColumn($x, $type); |
|
| 54 | + $y = $this->prepareColumn($y, $type); |
|
| 55 | + |
|
| 56 | + return $this->expressionBuilder->comparison($x, $operator, $y); |
|
| 57 | + } |
|
| 58 | + |
|
| 59 | + /** |
|
| 60 | + * @inheritdoc |
|
| 61 | + */ |
|
| 62 | + public function eq($x, $y, $type = null) { |
|
| 63 | + $x = $this->prepareColumn($x, $type); |
|
| 64 | + $y = $this->prepareColumn($y, $type); |
|
| 65 | + |
|
| 66 | + return $this->expressionBuilder->eq($x, $y); |
|
| 67 | + } |
|
| 68 | + |
|
| 69 | + /** |
|
| 70 | + * @inheritdoc |
|
| 71 | + */ |
|
| 72 | + public function neq($x, $y, $type = null) { |
|
| 73 | + $x = $this->prepareColumn($x, $type); |
|
| 74 | + $y = $this->prepareColumn($y, $type); |
|
| 75 | + |
|
| 76 | + return $this->expressionBuilder->neq($x, $y); |
|
| 77 | + } |
|
| 78 | + |
|
| 79 | + /** |
|
| 80 | + * @inheritdoc |
|
| 81 | + */ |
|
| 82 | + public function lt($x, $y, $type = null) { |
|
| 83 | + $x = $this->prepareColumn($x, $type); |
|
| 84 | + $y = $this->prepareColumn($y, $type); |
|
| 85 | + |
|
| 86 | + return $this->expressionBuilder->lt($x, $y); |
|
| 87 | + } |
|
| 88 | + |
|
| 89 | + /** |
|
| 90 | + * @inheritdoc |
|
| 91 | + */ |
|
| 92 | + public function lte($x, $y, $type = null) { |
|
| 93 | + $x = $this->prepareColumn($x, $type); |
|
| 94 | + $y = $this->prepareColumn($y, $type); |
|
| 95 | + |
|
| 96 | + return $this->expressionBuilder->lte($x, $y); |
|
| 97 | + } |
|
| 98 | + |
|
| 99 | + /** |
|
| 100 | + * @inheritdoc |
|
| 101 | + */ |
|
| 102 | + public function gt($x, $y, $type = null) { |
|
| 103 | + $x = $this->prepareColumn($x, $type); |
|
| 104 | + $y = $this->prepareColumn($y, $type); |
|
| 105 | + |
|
| 106 | + return $this->expressionBuilder->gt($x, $y); |
|
| 107 | + } |
|
| 108 | + |
|
| 109 | + /** |
|
| 110 | + * @inheritdoc |
|
| 111 | + */ |
|
| 112 | + public function gte($x, $y, $type = null) { |
|
| 113 | + $x = $this->prepareColumn($x, $type); |
|
| 114 | + $y = $this->prepareColumn($y, $type); |
|
| 115 | + |
|
| 116 | + return $this->expressionBuilder->gte($x, $y); |
|
| 117 | + } |
|
| 118 | + |
|
| 119 | + /** |
|
| 120 | + * @inheritdoc |
|
| 121 | + */ |
|
| 122 | + public function in($x, $y, $type = null) { |
|
| 123 | + $x = $this->prepareColumn($x, $type); |
|
| 124 | + $y = $this->prepareColumn($y, $type); |
|
| 125 | + |
|
| 126 | + return $this->expressionBuilder->in($x, $y); |
|
| 127 | + } |
|
| 128 | + |
|
| 129 | + /** |
|
| 130 | + * @inheritdoc |
|
| 131 | + */ |
|
| 132 | + public function notIn($x, $y, $type = null) { |
|
| 133 | + $x = $this->prepareColumn($x, $type); |
|
| 134 | + $y = $this->prepareColumn($y, $type); |
|
| 135 | + |
|
| 136 | + return $this->expressionBuilder->notIn($x, $y); |
|
| 137 | + } |
|
| 138 | + |
|
| 139 | + /** |
|
| 140 | + * Creates a $x = '' statement, because Oracle needs a different check |
|
| 141 | + * |
|
| 142 | + * @param string $x The field in string format to be inspected by the comparison. |
|
| 143 | + * @return string |
|
| 144 | + * @since 13.0.0 |
|
| 145 | + */ |
|
| 146 | + public function emptyString($x) { |
|
| 147 | + return $this->isNull($x); |
|
| 148 | + } |
|
| 149 | + |
|
| 150 | + /** |
|
| 151 | + * Creates a `$x <> ''` statement, because Oracle needs a different check |
|
| 152 | + * |
|
| 153 | + * @param string $x The field in string format to be inspected by the comparison. |
|
| 154 | + * @return string |
|
| 155 | + * @since 13.0.0 |
|
| 156 | + */ |
|
| 157 | + public function nonEmptyString($x) { |
|
| 158 | + return $this->isNotNull($x); |
|
| 159 | + } |
|
| 160 | + |
|
| 161 | + /** |
|
| 162 | + * Returns a IQueryFunction that casts the column to the given type |
|
| 163 | + * |
|
| 164 | + * @param string $column |
|
| 165 | + * @param mixed $type One of IQueryBuilder::PARAM_* |
|
| 166 | + * @return IQueryFunction |
|
| 167 | + */ |
|
| 168 | + public function castColumn($column, $type) { |
|
| 169 | + if ($type === IQueryBuilder::PARAM_STR) { |
|
| 170 | + $column = $this->helper->quoteColumnName($column); |
|
| 171 | + return new QueryFunction('to_char(' . $column . ')'); |
|
| 172 | + } |
|
| 173 | + if ($type === IQueryBuilder::PARAM_INT) { |
|
| 174 | + $column = $this->helper->quoteColumnName($column); |
|
| 175 | + return new QueryFunction('to_number(to_char(' . $column . '))'); |
|
| 176 | + } |
|
| 177 | + |
|
| 178 | + return parent::castColumn($column, $type); |
|
| 179 | + } |
|
| 180 | + |
|
| 181 | + /** |
|
| 182 | + * @inheritdoc |
|
| 183 | + */ |
|
| 184 | + public function like($x, $y, $type = null) { |
|
| 185 | + return parent::like($x, $y, $type) . " ESCAPE '\\'"; |
|
| 186 | + } |
|
| 187 | + |
|
| 188 | + /** |
|
| 189 | + * @inheritdoc |
|
| 190 | + */ |
|
| 191 | + public function iLike($x, $y, $type = null) { |
|
| 192 | + $x = $this->helper->quoteColumnName($x); |
|
| 193 | + $y = $this->helper->quoteColumnName($y); |
|
| 194 | + return new QueryFunction('REGEXP_LIKE(' . $x . ', \'^\' || REPLACE(REPLACE(' . $y . ', \'%\', \'.*\'), \'_\', \'.\') || \'$\', \'i\')'); |
|
| 195 | + } |
|
| 196 | 196 | } |
@@ -168,11 +168,11 @@ discard block |
||
| 168 | 168 | public function castColumn($column, $type) { |
| 169 | 169 | if ($type === IQueryBuilder::PARAM_STR) { |
| 170 | 170 | $column = $this->helper->quoteColumnName($column); |
| 171 | - return new QueryFunction('to_char(' . $column . ')'); |
|
| 171 | + return new QueryFunction('to_char('.$column.')'); |
|
| 172 | 172 | } |
| 173 | 173 | if ($type === IQueryBuilder::PARAM_INT) { |
| 174 | 174 | $column = $this->helper->quoteColumnName($column); |
| 175 | - return new QueryFunction('to_number(to_char(' . $column . '))'); |
|
| 175 | + return new QueryFunction('to_number(to_char('.$column.'))'); |
|
| 176 | 176 | } |
| 177 | 177 | |
| 178 | 178 | return parent::castColumn($column, $type); |
@@ -182,7 +182,7 @@ discard block |
||
| 182 | 182 | * @inheritdoc |
| 183 | 183 | */ |
| 184 | 184 | public function like($x, $y, $type = null) { |
| 185 | - return parent::like($x, $y, $type) . " ESCAPE '\\'"; |
|
| 185 | + return parent::like($x, $y, $type)." ESCAPE '\\'"; |
|
| 186 | 186 | } |
| 187 | 187 | |
| 188 | 188 | /** |
@@ -191,6 +191,6 @@ discard block |
||
| 191 | 191 | public function iLike($x, $y, $type = null) { |
| 192 | 192 | $x = $this->helper->quoteColumnName($x); |
| 193 | 193 | $y = $this->helper->quoteColumnName($y); |
| 194 | - return new QueryFunction('REGEXP_LIKE(' . $x . ', \'^\' || REPLACE(REPLACE(' . $y . ', \'%\', \'.*\'), \'_\', \'.\') || \'$\', \'i\')'); |
|
| 194 | + return new QueryFunction('REGEXP_LIKE('.$x.', \'^\' || REPLACE(REPLACE('.$y.', \'%\', \'.*\'), \'_\', \'.\') || \'$\', \'i\')'); |
|
| 195 | 195 | } |
| 196 | 196 | } |