Doctrine DBAL
  1. Doctrine DBAL
  2. DBAL-558

Incorrect extracting of placeholder positions from statement

    Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 2.3
    • Fix Version/s: 2.5, 2.4.2
    • Component/s: None
    • Labels:
      None
    • Environment:
      Linux Ubuntu 12.04 x64
      PHP 5.3.10-1ubuntu3.6 with Suhosin-Patch
      PostgreSQL 9.1.9

      Description

      I'm trying to execute statement:

      SELECT Count(*)
      FROM   (SELECT DISTINCT o6_.id                          AS id0,
                              COALESCE(t3_.content, o2_.name) AS name1,
                              o7_.postal_code                 AS postal_code2,
                              CASE
                                WHEN o7_.state_text IS NOT NULL THEN o7_.state_text
                                ELSE COALESCE(t5_.content, o4_.name)
                              END
                              || ''                           AS sclr3,
                              CASE
                                WHEN o6_.id IN ( ? )
                                     AND o6_.id NOT IN ( ? ) THEN true
                                ELSE false
                              END                             AS sclr4
              FROM   orocrm_contact o6_
                     LEFT JOIN orocrm_contact_value o8_
                            ON o6_.id = o8_.entity_id
                     LEFT JOIN oro_flexibleentity_attribute o0_
                            ON o8_.attribute_id = o0_.id
                     LEFT JOIN orocrm_contact_value_option o10_
                            ON o8_.id = o10_.value_id
                     LEFT JOIN oro_flexibleentity_attribute_option o9_
                            ON o9_.id = o10_.option_id
                     LEFT JOIN oro_flexibleentity_attribute_option_value o11_
                            ON o9_.id = o11_.option_id
                     LEFT JOIN orocrm_contact_address o7_
                            ON o6_.id = o7_.owner_id
                               AND ( o7_.is_primary = true )
                     LEFT JOIN orocrm_contact_to_contact_group o13_
                            ON o6_.id = o13_.contact_id
                     LEFT JOIN orocrm_contact_group o12_
                            ON o12_.id = o13_.contact_group_id
                     LEFT JOIN oro_dictionary_country o2_
                            ON o7_.country_code = o2_.iso2_code
                     LEFT JOIN oro_dictionary_region o4_
                            ON o7_.region_code = o4_.combined_code
                     LEFT JOIN oro_flexibleentity_attribute_translation t1_
                            ON t1_.locale = 'ru'
                               AND t1_.field = 'label'
                               AND t1_.object_class =
                                   'Oro\Bundle\FlexibleEntityBundle\Entity\Attribute'
                               AND t1_.foreign_key = o0_.id
                     LEFT JOIN oro_dictionary_country_translation t3_
                            ON t3_.locale = 'ru'
                               AND t3_.field = 'name'
                               AND t3_.object_class =
                                   'Oro\Bundle\AddressBundle\Entity\Country'
                               AND t3_.foreign_key = o2_.iso2_code
                     LEFT JOIN oro_dictionary_region_translation t5_
                            ON t5_.locale = 'ru'
                               AND t5_.field = 'name'
                               AND t5_.object_class =
                                   'Oro\Bundle\AddressBundle\Entity\Region'
                               AND t5_.foreign_key = o4_.combined_code
              WHERE  ( CASE
                         WHEN o6_.id IN ( ? )
                              AND o6_.id NOT IN ( ? ) THEN true
                         ELSE false
                       END <> false )
                     AND CASE
                           WHEN o7_.state_text IS NOT NULL THEN o7_.state_text
                           ELSE COALESCE(t5_.content, o4_.name)
                         END
                         || '' LIKE ?) AS e  
      

      When this statement passes to Doctrine\DBAL\SQLParserUtils::getPlaceholderPositions, it extracts only three placeholder positions instead of five.

      As a result, Doctrine can't map parameters and types properly, so SQL request fails.

      It looks like this unexpected behavior appeared because of regular expression in SQLParserUtils::getUnquotedStatementFragments, that incorrectly extracts unquoted statements.

        Activity

        Hide
        Steve Müller added a comment -
        Show
        Steve Müller added a comment - Patch supplied in PR: https://github.com/doctrine/dbal/pull/480
        Hide
        Doctrine Bot added a comment -

        A related Github Pull-Request [GH-480] was closed:
        https://github.com/doctrine/dbal/pull/480

        Show
        Doctrine Bot added a comment - A related Github Pull-Request [GH-480] was closed: https://github.com/doctrine/dbal/pull/480

          People

          • Assignee:
            Steve Müller
            Reporter:
            Yevhen Shyshkin
          • Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: