Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue with the new rawSql Laravel feature #47

Closed
dannewnsjump24 opened this issue Jul 12, 2023 · 2 comments
Closed

Issue with the new rawSql Laravel feature #47

dannewnsjump24 opened this issue Jul 12, 2023 · 2 comments

Comments

@dannewnsjump24
Copy link

dannewnsjump24 commented Jul 12, 2023

Hi Firstly let me say a huge thanks for creating this brilliant package, we've been using it on a build and was looking forward to using the new toRawSql feature that was merged in this week. After updating our code base and trying to use the method we get an error being thrown

The database driver's grammar implementation does not support escaping values.

After digging in and looking at the work that went into the Laravel PR I can see that there has been some updates to the way the grammar classes now set and how they use the current connection.

Dumping out the code just before it breaks in the new method I can see that the Laravel CTE Grammar class doesnt have a connection set.

Staudenmeir\LaravelCte\Query\Grammars\MySqlGrammar {#1741 ▼ // vendor/laravel/framework/src/Illuminate/Database/Query/Builder.php:2644
  #connection: null
  #tablePrefix: ""
  #operators: array:1 [▶]
  #bitwiseOperators: []
  #selectComponents: array:14 [▶]
}

after a quick look into this packages code I can see if I update the BuildsExpressionQueries Trait in particular this method

 protected function getQueryGrammar(Connection $connection)
    {
        $driver = $connection->getDriverName();

        switch ($driver) {
            case 'mysql':
                return (new MySqlGrammar())->setConnection($connection);
            case 'pgsql':
                return new PostgresGrammar();
            case 'sqlite':
                return new SQLiteGrammar();
            case 'sqlsrv':
                return new SqlServerGrammar();
        }

        throw new RuntimeException('This database is not supported.'); // @codeCoverageIgnore
    }

    ```
    
    and use the new `setConnection` method this error then goes away and I can use the new method perfectly. I thought I would just let you know about the issue. Hopefully ive managed to explain the problem ok
@staudenmeir
Copy link
Owner

Hi @dannewnsjump24,
Thanks, I released a new version that resolves this.

@dannewnsjump24
Copy link
Author

my word thank you so much @staudenmeir for tackling it so quickly!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants