Doctrine 1
  1. Doctrine 1
  2. DC-972

MySQL field aliases with triple ticks

    Details

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

      Description

      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')
      ->fetchArray();

      MY PROPOSED PATCH:

      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.

        Activity

          People

          • Assignee:
            Guilherme Blanco
            Reporter:
            Roland Huszti
          • Votes:
            1 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated: