DDC-1095: Selecting Literals will not work, crashing bug #1371

Closed
opened 2026-01-22 13:12:02 +01:00 by admin · 7 comments
Owner

Originally created by @doctrinebot on GitHub (Apr 2, 2011).

Originally assigned to: @beberlei on GitHub.

Jira issue originally created by user dalvarez:

DQL queries selecting String literals like

SELECT '' FROM \Whatever

(empty string) will result in a DQL Parsing error.

DQL queries selecting numeric literals like

SELECT 0 FROM \Whatever

will crash Doctrine 2:

I won't go into the details of how the EBNF definition claims this is possible, because it is quite obvious. Basically, you should be able to select a Literal anywhere a scalar expression is expected. That this is not actually possible sucks, because sometimes it is handy to be able to include placeholder values in generated queries.

Warning: Illegal offset type in /Doctrine/ORM/Query/SqlWalker.php on line 988 Warning: Illegal offset type in isset or empty in /Doctrine/ORM/Query/SqlWalker.php on line 991 Warning: Illegal offset type in /var/www/invoiceCreator/src/thirdPartyComponents/doctrine/Doctrine/ORM/Query/SqlWalker.php on line 992 Notice: Trying to get property of non-object in /Doctrine/ORM/Query/SqlWalker.php on line 997 Warning: Invalid argument supplied for foreach() in /Doctrine/ORM/Query/SqlWalker.php on line 997 Fatal error: Call to a member function isInheritanceTypeSingleTable() on a non-object in /Doctrine/ORM/Query/SqlWalker.php on line 1023

The line numbers in the error message might be different from a vanilla 2.02 release, because I have patched the SQLWalker to include support for multiple FROM clause entries in combination with multiple explicit joins (http://www.doctrine-project.org/jira/browse/DDC-1047).

Here is the code snippet where Doctrine 2 crashes, for your convenience. This should not be affected by the local changes:

        // Add any additional fields of subclasses (excluding inherited fields)
        // 1) on Single Table Inheritance: always, since its marginal overhead
        // 2) on Class Table Inheritance only if partial objects are disallowed,
        //    since it requires outer joining subtables.
        if ($class->isInheritanceTypeSingleTable() || ! $this->*query->getHint(Query::HINT_FORCE_PARTIAL*LOAD)) {
            foreach ($class->subClasses as $subClassName) {
Originally created by @doctrinebot on GitHub (Apr 2, 2011). Originally assigned to: @beberlei on GitHub. Jira issue originally created by user dalvarez: DQL queries selecting String literals like SELECT '' FROM \Whatever (empty string) will result in a DQL Parsing error. DQL queries selecting numeric literals like SELECT 0 FROM \Whatever will crash Doctrine 2: I won't go into the details of how the EBNF definition claims this is possible, because it is quite obvious. Basically, you should be able to select a Literal anywhere a scalar expression is expected. That this is not actually possible sucks, because sometimes it is handy to be able to include placeholder values in generated queries. Warning: Illegal offset type in /Doctrine/ORM/Query/SqlWalker.php on line 988 Warning: Illegal offset type in isset or empty in /Doctrine/ORM/Query/SqlWalker.php on line 991 Warning: Illegal offset type in /var/www/invoiceCreator/src/thirdPartyComponents/doctrine/Doctrine/ORM/Query/SqlWalker.php on line 992 Notice: Trying to get property of non-object in /Doctrine/ORM/Query/SqlWalker.php on line 997 Warning: Invalid argument supplied for foreach() in /Doctrine/ORM/Query/SqlWalker.php on line 997 Fatal error: Call to a member function isInheritanceTypeSingleTable() on a non-object in /Doctrine/ORM/Query/SqlWalker.php on line 1023 The line numbers in the error message might be different from a vanilla 2.02 release, because I have patched the SQLWalker to include support for multiple FROM clause entries in combination with multiple explicit joins (http://www.doctrine-project.org/jira/browse/[DDC-1047](http://www.doctrine-project.org/jira/browse/DDC-1047)). Here is the code snippet where Doctrine 2 crashes, for your convenience. This should not be affected by the local changes: ``` // Add any additional fields of subclasses (excluding inherited fields) // 1) on Single Table Inheritance: always, since its marginal overhead // 2) on Class Table Inheritance only if partial objects are disallowed, // since it requires outer joining subtables. if ($class->isInheritanceTypeSingleTable() || ! $this->*query->getHint(Query::HINT_FORCE_PARTIAL*LOAD)) { foreach ($class->subClasses as $subClassName) { ```
admin added the Bug label 2026-01-22 13:12:02 +01:00
admin closed this issue 2026-01-22 13:12:04 +01:00
Author
Owner

@doctrinebot commented on GitHub (Apr 2, 2011):

@doctrinebot commented on GitHub (Apr 2, 2011): - relates to [DDC-1077: Specifying a constant value in the SELECT clause causes parser error](http://www.doctrine-project.org/jira/browse/DDC-1077)
Author
Owner

@doctrinebot commented on GitHub (Apr 2, 2011):

Comment created by @beberlei:

Are you using the bugfix patch for DDC-1077 also? This fixes the issue for me. DDC-1077 will be included in 2.0.3 which will be released tomorrow.

    /****
     * @group [DDC-1077](http://www.doctrine-project.org/jira/browse/DDC-1077)
     * @group [DDC-1096](http://www.doctrine-project.org/jira/browse/DDC-1096)
     */
    public function testCosntantValueOnlyInSelect()
    {
        $this->assertSqlGeneration(
            "SELECT 'foo' AS bar FROM Doctrine\Tests\Models\CMS\CmsUser u",
            "SELECT 'foo' AS sclr0 FROM cms*users c0*"
        );

        $this->assertSqlGeneration(
            "SELECT '' FROM Doctrine\Tests\Models\CMS\CmsUser u",
            "SELECT '' AS sclr0 FROM cms*users c0*"
        );

        $this->assertSqlGeneration(
            "SELECT 0 FROM Doctrine\Tests\Models\CMS\CmsUser u",
            "SELECT 0 AS sclr0 FROM cms*users c0*"
        );
    }

Does the crash happen in a subselect?

@doctrinebot commented on GitHub (Apr 2, 2011): Comment created by @beberlei: Are you using the bugfix patch for [DDC-1077](http://www.doctrine-project.org/jira/browse/DDC-1077) also? This fixes the issue for me. [DDC-1077](http://www.doctrine-project.org/jira/browse/DDC-1077) will be included in 2.0.3 which will be released tomorrow. ``` /**** * @group [DDC-1077](http://www.doctrine-project.org/jira/browse/DDC-1077) * @group [DDC-1096](http://www.doctrine-project.org/jira/browse/DDC-1096) */ public function testCosntantValueOnlyInSelect() { $this->assertSqlGeneration( "SELECT 'foo' AS bar FROM Doctrine\Tests\Models\CMS\CmsUser u", "SELECT 'foo' AS sclr0 FROM cms*users c0*" ); $this->assertSqlGeneration( "SELECT '' FROM Doctrine\Tests\Models\CMS\CmsUser u", "SELECT '' AS sclr0 FROM cms*users c0*" ); $this->assertSqlGeneration( "SELECT 0 FROM Doctrine\Tests\Models\CMS\CmsUser u", "SELECT 0 AS sclr0 FROM cms*users c0*" ); } ``` Does the crash happen in a subselect?
Author
Owner

@doctrinebot commented on GitHub (Apr 2, 2011):

Comment created by dalvarez:

Apart from the changes regarding DDC-1047 my installation is a vanilla 2.0.2.

The crash happens in a top-level query. In the select expression, regular entity fields get queried, too. I tried to select a literal to pad the query result to a common format, but the change made it crash. After removing the literal (replacing it with some random reference to a regular entity field) it worked again.

@doctrinebot commented on GitHub (Apr 2, 2011): Comment created by dalvarez: Apart from the changes regarding [DDC-1047](http://www.doctrine-project.org/jira/browse/DDC-1047) my installation is a vanilla 2.0.2. The crash happens in a top-level query. In the select expression, regular entity fields get queried, too. I tried to select a literal to pad the query result to a common format, but the change made it crash. After removing the literal (replacing it with some random reference to a regular entity field) it worked again.
Author
Owner

@doctrinebot commented on GitHub (Apr 2, 2011):

Comment created by dalvarez:

No, wait. It is a 2.0.3. I think you mean 2.0.4 will be released tomorrow.

@doctrinebot commented on GitHub (Apr 2, 2011): Comment created by dalvarez: No, wait. It is a 2.0.3. I think you mean 2.0.4 will be released tomorrow.
Author
Owner

@doctrinebot commented on GitHub (Apr 2, 2011):

Comment created by dalvarez:

I think the string literal problem is precisely the same issue as DDC-1077. If the fix also covers numeric literals, this can be closed as fixed. According to your unit test above, numeric literals should be covered.

@doctrinebot commented on GitHub (Apr 2, 2011): Comment created by dalvarez: I think the string literal problem is precisely the same issue as [DDC-1077](http://www.doctrine-project.org/jira/browse/DDC-1077). If the fix also covers numeric literals, this can be closed as fixed. According to your unit test above, numeric literals should be covered.
Author
Owner

@doctrinebot commented on GitHub (Apr 3, 2011):

Comment created by @beberlei:

Duplicate of DDC-1077

@doctrinebot commented on GitHub (Apr 3, 2011): Comment created by @beberlei: Duplicate of [DDC-1077](http://www.doctrine-project.org/jira/browse/DDC-1077)
Author
Owner

@doctrinebot commented on GitHub (Apr 3, 2011):

Issue was closed with resolution "Duplicate"

@doctrinebot commented on GitHub (Apr 3, 2011): Issue was closed with resolution "Duplicate"
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#1371