Doctrine DBAL
  1. Doctrine DBAL
  2. DBAL-299

Multiple different interspersed named parameters

    Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 2.5
    • Fix Version/s: None
    • Component/s: None
    • Security Level: All
    • Labels:
      None
    • Environment:
      PHP 5.3.9-ZS5.6.0, Ubuntu 10.04.4 LTS on VirtualBox 4.1..18 r78361 on Mac OS X version 10.6.8

      Description

      For this code

      $sql = <<<SQL
      SELECT 1 as id
      WHERE (:foo = 2)
      AND (:bar = 3)
      AND (:foo = 2)
      SQL;
      $rsm = new \Doctrine\Orm\Query\ResultSetMapping();
      $rsm->addScalarResult('id', 'id');

      $query = $em->createNativeQuery($sql, $rsm);
      $query = $query->setParameters(array('foo' => 2, 'bar' => 3));
      $result = $query->getResult();

      Generates the SQL in DBAL\Connection\executeQuery

      SELECT 1 as id
      WHERE (? = 2)
      AN?bar = 3)
      AND (? = 2)

      The problem appears to be in DBAL\SQLParserUtils\expandListParameters.

      When replacing the named parameters with ?'s an offset is kept to keep track of where to insert the next parameter. This is done per named parameter (all of :foo is replaced then all :bar, etc). This will calculate the incorrect offset if a named parameter(e.g. :bar) is in between instances of another named parameter (e.g. :foo) (i.e. :bar in the sql "(:foo = 2) AND (:bar =3) AND (:foo = 2)") since the offset will be for the TOTAL number of instances of the named parameter (e.g. -6) not the number of instances that occur before the needed replacement (e.g. -3).

      This is where the SQL has "AN?bar = 3)" instead of "AND(3 = 3)" the offset is calculated at -6 instead of the proper -3

        Activity

        Spinning Top created issue -
        Show
        Alexander added a comment - Fixed here: https://github.com/doctrine/dbal/commit/78dbf28923059545b24ba753c112560ad59ca89e
        Alexander made changes -
        Field Original Value New Value
        Status Open [ 1 ] Resolved [ 5 ]
        Assignee Benjamin Eberlei [ beberlei ] Alexander [ asm89 ]
        Fix Version/s 2.2.3 [ 10210 ]
        Resolution Fixed [ 1 ]
        Benjamin Eberlei made changes -
        Workflow jira [ 13825 ] jira-feedback2 [ 17845 ]
        Benjamin Eberlei made changes -
        Workflow jira-feedback2 [ 17845 ] jira-feedback3 [ 20200 ]
        Guilherme Blanco made changes -
        Affects Version/s 2.5 [ 10523 ]
        Affects Version/s 2.2.3 [ 10210 ]
        Fix Version/s 2.2.3 [ 10210 ]

        This list may be incomplete, as errors occurred whilst retrieving source from linked applications:

        • Request to http://www.doctrine-project.org/fisheye/ failed: Error in remote call to 'FishEye 0 (http://www.doctrine-project.org/fisheye/)' (http://www.doctrine-project.org/fisheye) [AbstractRestCommand{path='/rest-service-fe/search-v1/crossRepositoryQuery', params={query=DBAL-299, expand=changesets[0:20].revisions[0:29],reviews}, methodType=GET}] : Received status code 503 (Service Temporarily Unavailable)

          People

          • Assignee:
            Alexander
            Reporter:
            Spinning Top
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: