From fb7bc161a72ee54d5c158675452cda746ea5e32a Mon Sep 17 00:00:00 2001 From: Douglas Resende Date: Tue, 28 Apr 2020 11:22:53 -0300 Subject: [PATCH] version support -added grammar support for firebird 1.5 -main version is 2.* (if has no information about grammar 2.* is default) --- src/Firebird/Connection.php | 18 ++- .../Query/Grammars/Firebird15Grammar.php | 112 ++++++++++++++++++ 2 files changed, 125 insertions(+), 5 deletions(-) create mode 100644 src/Firebird/Query/Grammars/Firebird15Grammar.php diff --git a/src/Firebird/Connection.php b/src/Firebird/Connection.php index 198f8df..b636414 100644 --- a/src/Firebird/Connection.php +++ b/src/Firebird/Connection.php @@ -3,7 +3,8 @@ namespace Firebird; use Firebird\Query\Builder as QueryBuilder; -use Firebird\Query\Grammars\Firebird25Grammar as QueryGrammar; +use Firebird\Query\Grammars\Firebird15Grammar as QueryGrammar10; +use Firebird\Query\Grammars\Firebird25Grammar as QueryGrammar20; use Firebird\Query\Grammars\Firebird30Grammar as QueryGrammar30; use Firebird\Query\Processors\FirebirdProcessor as Processor; use Firebird\Schema\Builder as SchemaBuilder; @@ -56,14 +57,21 @@ protected function getMajorEngineVersion() /** * Get the default query grammar instance * - * @return Query\Grammars\Firebird25Grammar + * @return QueryGrammar10|QueryGrammar20|QueryGrammar30 */ protected function getDefaultQueryGrammar() { - if ($this->getMajorEngineVersion() >= 3) { - return new QueryGrammar30; + switch ($this->getMajorEngineVersion()){ + case 1: + return new QueryGrammar10; + break; + case 3: + return new QueryGrammar30; + break; + default: + return new QueryGrammar20; + break; } - return new QueryGrammar; } /** diff --git a/src/Firebird/Query/Grammars/Firebird15Grammar.php b/src/Firebird/Query/Grammars/Firebird15Grammar.php new file mode 100644 index 0000000..00f60b8 --- /dev/null +++ b/src/Firebird/Query/Grammars/Firebird15Grammar.php @@ -0,0 +1,112 @@ +aggregate)) return; + $select = ''; + if (count($columns) > 0 && $query->limit == null && $query->aggregate == null) + { + $select = $query->distinct ? 'select distinct ' : 'select '; + } + + return $select.$this->columnize($columns); + } + + /** + * Compile a select query into SQL. + * + * @param Illuminate\Database\Query\Builder + * + * @return string + */ + public function compileSelect(Builder $query) + { + if (is_null($query->columns)) $query->columns = array('*'); + + return trim($this->concatenate($this->compileComponents($query))); + } + + /** + * Compile an aggregated select clause. + * + * @param \Illuminate\Database\Query\Builder $query + * @param array $aggregate + * @return string + */ + protected function compileAggregate(Builder $query, $aggregate) + { + $column = $this->columnize($aggregate['columns']); + + // If the query has a "distinct" constraint and we're not asking for all columns + // we need to prepend "distinct" onto the column name so that the query takes + // it into account when it performs the aggregating operations on the data. + if ($query->distinct && $column !== '*') + { + $column = 'distinct '.$column; + } + + return 'select '.$aggregate['function'].'('.$column.') as aggregate'; + } + + /** + * Compile first instead of limit + * + * @param \Illuminate\Database\Query\Builder $query + * @param int $limit + * @return string + */ + protected function compileLimit(Builder $query, $limit) + { + return 'select first '.(int) $limit; + } + + /** + * Compile skip instead of offset + * + * @param \Illuminate\Database\Query\Builder $query + * @param int $limit + * @return string + */ + protected function compileOffset(Builder $query, $limit) + { + return 'skip '.(int) $limit; + } + +}