Uploaded image for project: 'Doctrine 1'
  1. Doctrine 1
  2. DC-972

MySQL field aliases with triple ticks


    • Type: Bug
    • Status: Open
    • Priority: Blocker
    • Resolution: Unresolved
    • Affects Version/s: 1.2.3
    • Fix Version/s: None
    • Component/s: Query
    • Labels:
    • Environment:
      MySQL 5, PHP 5


      In revision 7691 something has happened. Ever since I updated my Doctrine to that revision all my queries having " ... fieldname AS aliasname ... " go crazy and make the PHP to throw an exception, like this:

      'Doctrine_Connection_Mysql_Exception' with message 'SQLSTATE[42S22]: Column not found: 1054 Unknown column 't.`id`' in 'field list'. Failing Query:
      "SELECT `t`.`id` AS `t_id`, `t`.```id``` AS `t0`, `t`.```name``` AS `t1`, `t`.`id` AS `t0`, `t`.`name` AS `t_1` FROM `territoryCombined` `t` ORDER BY `t`.`name` asc"'
      in ...path here.../doctrine/lib/Doctrine/Connection.php:1082

      The problem is that the DQL parser somewhere along the process encapsualtes aliases in ticks, but then it does it again in lib/Doctrine/Formatter.php : quoteIdentifier() , which is called in lib/Doctrine/Connection : quoteIdentifier() , which is called in lib/Doctrine/Query.php : processPendingFields() @ between lines 485 and 512. The problem is that by the time the alias name gets to line 507 it is already encapsualted in ticks, but it does it again. At the end we end up with ```alias``` , which is not good.

      It only happens to aliases. If I say select('*') or select("t.id, t.name") then it executes properly. Only the aliases couse problems.

      A test query:

      $vTerritories = Doctrine_Query::create()
      ->select("t.id as territory_id, t.name as territory_name")
      ->from('TerritoryCombined t')
      ->orderBy('t.name asc')


      If I change the Formatter::quoteIdentifier() to this:

      public function quoteIdentifier($str, $checkOption = true)

      { $tmp = $this->conn->identifier_quoting; // I move up this line to here because I need it if ( (substr($str, 0, 1) == $tmp['start']) && (substr($str, -1) == $tmp['end']) ) return $str; // new line; is it already quoted? if yes, then don't do it again // the rest is unchanged }

      then it works correctly. Please note I only tested that in MySQL, as we use MySQL in all our projects.


        hroland Roland Huszti created issue -
        mishal Mishal added a comment -
        mishal Mishal added a comment - Bringing dead things back to life Fixed in: https://github.com/mishal/doctrine1/commit/aca0a00c2278498aef997d208cc91ecd52a9c0d3

        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={expand=changesets[0:20].revisions[0:29],reviews, query=DC-972}, methodType=GET}] : Received status code 503 (Service Temporarily Unavailable)


          • Assignee:
            guilhermeblanco Guilherme Blanco
            hroland Roland Huszti
          • Votes:
            1 Vote for this issue
            1 Start watching this issue


            • Created: