Skip to content

Commit

Permalink
Merge branch '8.x'
Browse files Browse the repository at this point in the history
* 8.x:
  Bump v8.2.2 🚀
  Fix github action error on clone? BadMethodCallException: Call to undefined method Yajra\Oci8\Query\OracleBuilder::clone()
  Fix crossJoinSubs query.
  Apply fixes from StyleCI
  Use protected on unsupported upsert tests.
  Apply fixes from StyleCI
  Add failing test link to issue #586.
  Add all builder possible tests from framework. Add TODO notes on failing tests.
  Fix aggregate tests.
  Fix compileUnionAggregate and update tests.
  Remove unused var.
  Fix from query with alias.
  Fix fromSub query. Add tests.
  Add test for having sql.
  Remove table alias in run pagination count query with group. 8.x version of #614 with tests added.
  • Loading branch information
yajra committed Dec 8, 2020
2 parents 7603d5a + e78d3f9 commit 16d1186
Show file tree
Hide file tree
Showing 7 changed files with 2,833 additions and 839 deletions.
8 changes: 7 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## [Unreleased]

## [v8.2.2] - 2020-12-08

- Query builder fixes and tests. [#615]

## [v8.2.1] - 2020-12-07

- Fix query builder bulk insert. [#612]
Expand Down Expand Up @@ -130,7 +134,8 @@
- Fix [#406], [#404].
- Added more options to Sequence Create Method [#355], credits to [@nikklass].

[Unreleased]: https://github.com/yajra/laravel-oci8/compare/v8.2.1...8.x
[Unreleased]: https://github.com/yajra/laravel-oci8/compare/v8.2.2...8.x
[v8.2.2]: https://github.com/yajra/laravel-oci8/compare/v8.2.1...v8.2.2
[v8.2.1]: https://github.com/yajra/laravel-oci8/compare/v8.2.0...v8.2.1
[v8.2.0]: https://github.com/yajra/laravel-oci8/compare/v8.1.3...v8.2.0
[v8.1.3]: https://github.com/yajra/laravel-oci8/compare/v8.1.2...v8.1.3
Expand Down Expand Up @@ -190,6 +195,7 @@
[#609]: https://github.com/yajra/laravel-oci8/pull/609
[#611]: https://github.com/yajra/laravel-oci8/pull/611
[#612]: https://github.com/yajra/laravel-oci8/pull/612
[#615]: https://github.com/yajra/laravel-oci8/pull/615

[#558]: https://github.com/yajra/laravel-oci8/issue/558
[#563]: https://github.com/yajra/laravel-oci8/issue/563
Expand Down
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"ext-oci8": ">=2.0.0",
"ext-pdo": "*",
"illuminate/database": "^8",
"illuminate/pagination": "^8",
"illuminate/support": "^8",
"illuminate/validation": "^8",
"yajra/laravel-pdo-via-oci8": "^2"
Expand Down
19 changes: 16 additions & 3 deletions src/Oci8/Query/Grammars/OracleGrammar.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,7 @@ protected function compileAnsiOffset(Builder $query, $components)
// We are now ready to build the final SQL query so we'll create a common table
// expression from the query and get the records with row numbers within our
// given limit and offset value that we just put on as a query constraint.
$temp = $this->compileTableExpression($sql, $constraint, $query);

return $temp;
return $this->compileTableExpression($sql, $constraint, $query);
}

/**
Expand Down Expand Up @@ -563,4 +561,19 @@ private function resolveClause($column, $values, $type)

return '(' . $whereClause . ')';
}

/**
* Compile a union aggregate query into SQL.
*
* @param \Illuminate\Database\Query\Builder $query
* @return string
*/
protected function compileUnionAggregate(Builder $query)
{
$sql = $this->compileAggregate($query, $query->aggregate);

$query->aggregate = null;

return $sql.' from ('.$this->compileSelect($query).') '.$this->wrapTable('temp_table');
}
}
84 changes: 80 additions & 4 deletions src/Oci8/Query/OracleBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,36 @@

class OracleBuilder extends Builder
{
/**
* Run a pagination count query.
*
* @param array $columns
* @return array
*/
protected function runPaginationCountQuery($columns = ['*'])
{
if ($this->groups || $this->havings) {
$clone = $this->cloneForPaginationCount();

if (is_null($clone->columns) && ! empty($this->joins)) {
$clone->select($this->from.'.*');
}

return $this->newQuery()
->from(new Expression('('.$clone->toSql().')'))
->mergeBindings($clone)
->setAggregate('count', $this->withoutSelectAliases($columns))
->get()->all();
}

$without = $this->unions ? ['orders', 'limit', 'offset'] : ['columns', 'orders', 'limit', 'offset'];

return $this->cloneWithout($without)
->cloneWithoutBindings($this->unions ? ['order'] : ['select', 'order'])
->setAggregate('count', $this->withoutSelectAliases($columns))
->get()->all();
}

/**
* Get the count of the total records for the paginator.
*
Expand All @@ -21,9 +51,7 @@ public function getCountForPagination($columns = ['*'])
// Once we have run the pagination count query, we will get the resulting count and
// take into account what type of query it was. When there is a group by we will
// just return the count of the entire results set since that will be correct.
if (isset($this->groups)) {
return count($results);
} elseif (! isset($results[0])) {
if (! isset($results[0])) {
return 0;
} elseif (is_object($results[0])) {
return (int) (property_exists($results[0], 'AGGREGATE') ? $results[0]->AGGREGATE : $results[0]->aggregate); // to solve the Oracle issue: auto-convert field to uppercase
Expand Down Expand Up @@ -131,6 +159,24 @@ protected function runSelect()
return $this->connection->select($this->toSql(), $this->getBindings(), ! $this->useWritePdo);
}

/**
* Set the table which the query is targeting.
*
* @param \Closure|\Illuminate\Database\Query\Builder|string $table
* @param string|null $as
* @return $this
*/
public function from($table, $as = null)
{
if ($this->isQueryable($table)) {
return $this->fromSub($table, $as);
}

$this->from = $as ? "{$table} {$as}" : $table;

return $this;
}

/**
* Makes "from" fetch from a subquery.
*
Expand All @@ -144,7 +190,7 @@ public function fromSub($query, $as)
{
[$query, $bindings] = $this->createSub($query);

return $this->fromRaw('('.$query.') '.$this->grammar->wrap($as), $bindings);
return $this->fromRaw('('.$query.') '.$this->grammar->wrapTable($as), $bindings);
}

/**
Expand All @@ -171,4 +217,34 @@ public function joinSub($query, $as, $first, $operator = null, $second = null, $

return $this->join(new Expression($expression), $first, $operator, $second, $type, $where);
}

/**
* Add a subquery cross join to the query.
*
* @param \Closure|\Illuminate\Database\Query\Builder|string $query
* @param string $as
* @return $this
*/
public function crossJoinSub($query, $as)
{
[$query, $bindings] = $this->createSub($query);

$expression = '('.$query.') '.$this->grammar->wrapTable($as);

$this->addBinding($bindings, 'join');

$this->joins[] = $this->newJoinClause($this, 'cross', new Expression($expression));

return $this;
}

/**
* Clone the query.
*
* @return static
*/
public function clone()
{
return clone $this;
}
}
Loading

0 comments on commit 16d1186

Please sign in to comment.