Skip to content

Commit

Permalink
Update readme, fix dialect
Browse files Browse the repository at this point in the history
  • Loading branch information
onezerotrash committed Mar 16, 2023
1 parent 2aa79b3 commit b1726a3
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 20 deletions.
9 changes: 8 additions & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ composer require onezerotrash/laravel-firebird
_The package will automatically register itself._

Declare the connection within your `config/database.php` file by using `firebird` as the
driver:
driver (use `PDO::ATTR_CASE => PDO::CASE_LOWER`):
```php
'connections' => [

Expand All @@ -39,6 +39,13 @@ driver:
'charset' => env('DB_FIREBIRD_CHARSET', 'UTF8'),
'dialect' => env('DB_FIREBIRD_DIALECT', '3'),
'role' => env('DB_FIREBIRD_ROLE', 'NONE'),
'options' => [
PDO::ATTR_CASE => PDO::CASE_LOWER,
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
PDO::ATTR_ORACLE_NULLS => PDO::NULL_NATURAL,
PDO::ATTR_STRINGIFY_FETCHES => false,
PDO::ATTR_EMULATE_PREPARES => false
]
],

],
Expand Down
23 changes: 21 additions & 2 deletions src/FirebirdConnection.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
namespace onezerotrash\Firebird;

use onezerotrash\Firebird\Query\Builder as FirebirdQueryBuilder;
use onezerotrash\Firebird\Query\Grammars\FirebirdGrammar as FirebirdQueryGrammar;
use onezerotrash\Firebird\Query\Grammars\FirebirdGrammarDialect1 as FirebirdQueryGrammarDialect1;
use onezerotrash\Firebird\Query\Grammars\FirebirdGrammarDialect3 as FirebirdQueryGrammarDialect3;
use onezerotrash\Firebird\Query\Processors\FirebirdProcessor as FirebirdQueryProcessor;
use onezerotrash\Firebird\Schema\Builder as FirebirdSchemaBuilder;
use onezerotrash\Firebird\Schema\Grammars\FirebirdGrammar as FirebirdSchemaGrammar;
Expand All @@ -18,7 +19,11 @@ class FirebirdConnection extends DatabaseConnection
*/
protected function getDefaultQueryGrammar()
{
return new FirebirdQueryGrammar;
if ($this->getDialectVersion() == '1') {
return new FirebirdQueryGrammarDialect1;
}

return new FirebirdQueryGrammarDialect3;
}

/**
Expand Down Expand Up @@ -78,4 +83,18 @@ public function executeProcedure($procedure, array $values = [])
{
return $this->query()->fromProcedure($procedure, $values)->get();
}

/**
* Get Firebird dialect version that should be used when compiling queries.
*
* @return string
*/
protected function getDialectVersion()
{
if (! array_key_exists('dialect', $this->config)) {
return '3';
}

return $this->config['dialect'];
}
}
17 changes: 0 additions & 17 deletions src/Query/Grammars/FirebirdGrammarDialect3.php
Original file line number Diff line number Diff line change
Expand Up @@ -153,21 +153,4 @@ public function compileProcedure(Builder $query, $procedure, array $values = nul
return $procedure.' ('.$this->parameterize($values).')';
}

/**
* Compile an aggregated select clause.
*
* @param \Illuminate\Database\Query\Builder $query
* @param array $aggregate
* @return string
*/
protected function compileAggregate(Builder $query, $aggregate)
{
// Wrap `aggregate` in double quotes to ensure the resultset returns the
// column name as a lowercase string. This resolves compatibility with
// the framework's paginator.
return Str::replaceLast(
'as aggregate', 'as "aggregate"', parent::compileAggregate($query, $aggregate)
);
}

}

0 comments on commit b1726a3

Please sign in to comment.