mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2025-06-24 18:58:46 +02:00
Make filters work on default MySQL servers to by removing the ONLY_FULL_GROUP_BY sql mode
This commit is contained in:
parent
ffa804404c
commit
467687fd0f
2 changed files with 42 additions and 0 deletions
24
src/Doctrine/SetSQLMode/SetSQLModeMiddlewareDriver.php
Normal file
24
src/Doctrine/SetSQLMode/SetSQLModeMiddlewareDriver.php
Normal file
|
@ -0,0 +1,24 @@
|
|||
<?php
|
||||
|
||||
namespace App\Doctrine\SetSQLMode;
|
||||
|
||||
use Doctrine\DBAL\Driver\Middleware\AbstractDriverMiddleware;
|
||||
use Doctrine\DBAL\Platforms\AbstractMySQLPlatform;
|
||||
|
||||
/**
|
||||
* This command sets the initial command parameter for MySQL connections, so we can set the SQL mode
|
||||
* We use this to disable the ONLY_FULL_GROUP_BY mode, which is enabled by default in MySQL 5.7.5 and higher and causes problems with our filters
|
||||
*/
|
||||
class SetSQLModeMiddlewareDriver extends AbstractDriverMiddleware
|
||||
{
|
||||
public function connect(array $params): \Doctrine\DBAL\Driver\Connection
|
||||
{
|
||||
//Only set this on MySQL connections, as other databases don't support this parameter
|
||||
if($this->getDatabasePlatform() instanceof AbstractMySQLPlatform) {
|
||||
//1002 is \PDO::MYSQL_ATTR_INIT_COMMAND constant value
|
||||
$params['driverOptions'][1002] = 'SET SESSION sql_mode=(SELECT REPLACE(@@sql_mode, \'ONLY_FULL_GROUP_BY\', \'\'))';
|
||||
}
|
||||
|
||||
return parent::connect($params);
|
||||
}
|
||||
}
|
18
src/Doctrine/SetSQLMode/SetSQLModeMiddlewareWrapper.php
Normal file
18
src/Doctrine/SetSQLMode/SetSQLModeMiddlewareWrapper.php
Normal file
|
@ -0,0 +1,18 @@
|
|||
<?php
|
||||
|
||||
namespace App\Doctrine\SetSQLMode;
|
||||
|
||||
use Doctrine\DBAL\Driver;
|
||||
use Doctrine\DBAL\Driver\Middleware;
|
||||
|
||||
/**
|
||||
* This class wraps the Doctrine DBAL driver and wraps it into an Midleware driver so we can change the SQL mode
|
||||
*/
|
||||
class SetSQLModeMiddlewareWrapper implements Middleware
|
||||
{
|
||||
|
||||
public function wrap(Driver $driver): Driver
|
||||
{
|
||||
return new SetSQLModeMiddlewareDriver($driver);
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue