'Symfony/Doctrine functional tests using sqlite leads to SQLSTATE[HY000]: General error: 1 near "(": syntax error
I have a Symfony application that uses Doctrine and liip_test_fixtures_bundle.
- PHP Version: 7.4.25
- Symfony Runtime Version: 5.3.11
- Doctrine DBAL: 3.2.0
I set up Doctrine to use a sqlite connection for testing. When running the tests I get the following error:
Doctrine\DBAL\Exception\SyntaxErrorException: An exception occurred while executing a query: SQLSTATE[HY000]: General error: 1 near "(": syntax error
I followed the error to Doctrine\DBAL\Schema\SqliteSchemaManager::_getPortableTableIndexesList where the following query is executed "SELECT * FROM PRAGMA_TABLE_INFO (?)".
Following minimal example reproduces the problem. Note, that it only uses PDO.
<?php
// setup
$pdo = new PDO( 'sqlite:'.__DIR__.'/test.db');
$pdo->exec(<<<SQL
CREATE TABLE `test` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`content` varchar(1000) COLLATE utf8_unicode_ci NOT NULL,
PRIMARY KEY (`id`),
) DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
SQL);
// this line causes the error
$stmt = $pdo->prepare('SELECT * FROM PRAGMA_TABLE_INFO (?)');
if( !$stmt instanceof PDOStatement )
{
echo "Error occured\n";
echo "\n";
echo "Error Code: ".$pdo->errorCode()."\n";
$info = $pdo->errorInfo();
foreach( $info as $k => $v )
{
echo " $k => $v\n";
}
exit(128);
}
echo "No syntax Error detected \n";
/// outputs
Error occured
Error Code: HY000
0 => HY000
1 => 1
2 => near "(": syntax error
Is there some way to configure Doctrine not to use prepared Statements for Sqlite Databases?
Solution 1:[1]
Temporarily fixed the issue by restricting doctrine/dbal to version 3.1.5.
The error - I believe - is caused by this commit: https://github.com/doctrine/dbal/commit/55259d55b3b80ac43c7ff9b592bf5f8c30a4af2e
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | jpgerdeman |
