skip to Main Content

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:

DoctrineDBALExceptionSyntaxErrorException: An exception occurred while executing a query: SQLSTATE[HY000]: General error: 1 near "(": syntax error

I followed the error to DoctrineDBALSchemaSqliteSchemaManager::_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 occuredn";
    echo "n";
    echo "Error Code: ".$pdo->errorCode()."n";
    $info = $pdo->errorInfo();
    foreach( $info as $k => $v )
    {
        echo "   $k => $vn";
    }
    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?

2

Answers


  1. Chosen as BEST ANSWER

    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


  2. I had a similar issue when I switched from PostgreSQL to SQLite for integration testing. At the end of the day I just had to properly escape the order column. XML snippet from the mapping:

    <field name="order" type="integer" column="`order`"/>
    

    As I said, it worked on PostgreSQL without the backticks.

    More information on this kind of issues: https://www.doctrine-project.org/projects/doctrine-orm/en/2.11/reference/limitations-and-known-issues.html#identifier-quoting-and-legacy-databases

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search