- 
                Notifications
    You must be signed in to change notification settings 
- Fork 32
Open
Description
It looks like a breaking change was implemented in Laravel v12 in this PR: laravel/framework#54487
Any Query Grammar that extends Illuminate\Database\Grammar is now required to pass a connection when instantiated.
In my case I'm using the odbc drivers and the following connection options:
$options = [
  'processor' => \Illuminate\Database\Query\Processors\SqlServerProcessor::class,
  'grammar' => [
      'query' => \Illuminate\Database\Query\Grammars\SqlServerGrammar::class,
      'schema' => \Illuminate\Database\Schema\Grammars\SqlServerGrammar::class,
  ],
]
When trying to run a query, this error it thrown:
Too few arguments to function Illuminate\Database\Grammar::__construct(), 0 passed in vendor\yoramdelangen\laravel-pdo-odbc\src\ODBCConnection.php on line 15 and exactly 1 expected
The issue references the getDefaultQueryGrammar method in ODBCConnection.php
laravel-pdo-odbc/src/ODBCConnection.php
Lines 10 to 19 in e2d2176
| public function getDefaultQueryGrammar() | |
| { | |
| $queryGrammar = $this->getConfig('options.grammar.query'); | |
| if ($queryGrammar) { | |
| return new $queryGrammar(); | |
| } | |
| return parent::getDefaultQueryGrammar(); | |
| } | 
Updating the method to pass $this in line 15 resolved the issue for me.
    public function getDefaultQueryGrammar()
    {
        $queryGrammar = $this->getConfig('options.grammar.query');
        if ($queryGrammar) {
            return new $queryGrammar($this);
        }
        return parent::getDefaultQueryGrammar();
    }
Based on this comment laravel/framework#54487 (comment) the change wouldn't be backwards compatible. Perhaps, something like this is required:
        if ($queryGrammar) {
            return version_compare(app()->version(), '12.0.0', '<')
                ? new $queryGrammar()
                : new $queryGrammar($this);
        }
cimd and gsuero
Metadata
Metadata
Assignees
Labels
No labels