Doctrine 1
  1. Doctrine 1
  2. DC-181

Exception thrown - nested query in count query

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 1.0.14
    • Component/s: Query
    • Labels:
      None

      Description

      My model is:

      product: [ id, name]
      product_category_ref [product_id, category_id]
      product_category: [id, name]

      I have a query like this:
      $page = 1;
      $ids = array(1,2);
      $query = Doctrine_Query::create()
      ->from('Product p')
      ->innerJoin('p.Categories cat')
      ->andWhere('p.is_active = 1')
      ->andWhereIn('p.id', $ids);

      $pager = new Doctrine_Pager($query, $page, sfConfig::get('app_eshop_pager_limit', 5));

      $pager->execute(array(), Doctrine::HYDRATE_ARRAY);

      throws and exception: SQLSTATE[HY093]: Invalid parameter number: number of bound variables does not match number of tokens

      Stack trace:

      • at ()
        in SF_ROOT_DIR\plugins\sfDoctrinePlugin\lib\doctrine\Doctrine\Connection.php line 1086 ...
        1083.
        1084. $name = 'Doctrine_Connection_' . $this->driverName . '_Exception';
        1085.
        1086. $exc = new $name($e->getMessage(), (int) $e->getCode());
        1087. if ( ! isset($e->errorInfo) || ! is_array($e->errorInfo)) { 1088. $e->errorInfo = array(null, null, null, null); 1089. }
      • at Doctrine_Connection->rethrowException(object('PDOException'), object('Doctrine_Connection_Statement'))
        in SF_ROOT_DIR\plugins\sfDoctrinePlugin\lib\doctrine\Doctrine\Connection\Statement.php line 253 ...
        250. } catch (Doctrine_Adapter_Exception $e) { 251. }

        252.
        253. $this->_conn->rethrowException($e, $this);
        254.
        255. return false;
        256. }

      • at Doctrine_Connection_Statement->execute(array('1', '2', '1', '2'))
        in SF_ROOT_DIR\plugins\sfDoctrinePlugin\lib\doctrine\Doctrine\Connection.php line 1014 ...

      I found a place in Doctrine/Query.php (line 1155), changed line:

      $list = $this->_conn->execute($subquery, $this->getParams($params))->fetchAll(Doctrine::FETCH_COLUMN);

      to

      $list = $this->_conn->execute($subquery, $params)->fetchAll(Doctrine::FETCH_COLUMN);

      and it works ok, im not sure if that brokes anything

        Issue Links

          Activity

          Hide
          Jonathan H. Wage added a comment -

          This is the ticket and fix that caused this issue.

          Show
          Jonathan H. Wage added a comment - This is the ticket and fix that caused this issue.
          Hide
          Jonathan H. Wage added a comment -

          Can you test this change? it should be better now.

          Show
          Jonathan H. Wage added a comment - Can you test this change? it should be better now.
          Hide
          Mishal added a comment -

          It works! Thanks!

          Show
          Mishal added a comment - It works! Thanks!

            People

            • Assignee:
              Jonathan H. Wage
              Reporter:
              Mishal
            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: