Ticket #821 (closed defect: fixed)

Opened 16 months ago

Last modified 16 months ago

Query copy : clone doesn't works correctly

Reported by: cferry Owned by: zYne-
Priority: blocker Milestone: 0.10.3
Component: Query/Hydration Version: 0.10.0
Severity: Keywords:
Cc: Has Test:
Status: Has Patch:

Description

Hi ! Juste updated to 10.2 but it seems a problem in Query::copy.
The new "clone" doesn't works correctly because, it copy alias list, and when i try to getSql, or execute, i get this error :

Duplicate alias n in query.

$query->select('n.*')->from('NewsRecord n');

$query2 = $query->copy();

$this->data = $query->execute();

$query2->limit(0);
$query2->offset(0);
$query2->select('COUNT(n.id) as nb');

echo $query2->getSql(); // <- throw Exception.

Change History

Changed 16 months ago by jwage

  • status changed from new to closed
  • resolution set to worksforme

I just ran a test with the latest 0.10 branch and I was not able to produce the error.

$query = new Doctrine_Query();
$query->select('u.*')->from('User u');

$query2 = $query->copy();

$data = $query->execute();

$query2->limit(0);
$query2->offset(0);
$query2->select('COUNT(u.id) as nb');

echo $query2->getSql();

Changed 16 months ago by cferry

  • status changed from closed to reopened
  • resolution worksforme deleted

I just try again, after update to lastest 10.2 I got the same error, but if a replace clone by the older code (from 10.1) it's works.

the exact code :

        $query = new Doctrine_Query();
        $query->select('u.*')->from('UserRecord u');
        echo $query->getSql();

        $data = $query->execute();
        $query2 = $query->copy();
                
        $query2->limit(0);
        $query2->offset(0);
        $query2->select('COUNT(u.id) as nb');
        echo $query2->getSql();

i get this out :

// this is the "echo" of the first query->getSql()
SELECT u.id AS u__id, u.login AS u__login, u.password AS u__password FROM user_record u 

// this is the error i get on the echo query2->getSql()
Une erreur est survenue.
Fichier : /home/cferry/projects/XXXXX/lib/Doctrine/lib/Doctrine/Query.php
Ligne : 1502
Message : Duplicate alias 'u' in query.
Code Erreur : 0
Trace :
#0 /home/cferry/projects/XXXXX/lib/Doctrine/lib/Doctrine/Query/From.php(82): Doctrine_Query->load('UserRecord u')
#1 /home/cferry/projects/XXXXX/lib/Doctrine/lib/Doctrine/Query/Abstract.php(1718): Doctrine_Query_From->parse('UserRecord u')
#2 /home/cferry/projects/XXXXX/lib/Doctrine/lib/Doctrine/Query.php(1126): Doctrine_Query_Abstract->_processDqlQueryPart('from', Array)
#3 /home/cferry/projects/XXXXX/lib/Doctrine/lib/Doctrine/Query/Abstract.php(1415): Doctrine_Query->getSqlQuery()
#4 /home/cferry/projects/XXXXX/admin/stat/ui/command/TestCommand.php(53): Doctrine_Query_Abstract->getSql()
#5 /home/cferry/projects/XXXXX/admin/stat/ui/HTTPHandler.php(69): TestCommand->process(Array)
#6 /home/cferry/projects/XXXXX/admin/stat/index.php(48): HTTPHandler->handleRequest(Array, Array, Array)
#7 {main}

the UserRecord?

class UserRecord extends Doctrine_Record
{
        public function setTableDefinition()
        {
                $this->setTableName('user_record');
                $this->hasColumn('id', 'integer', 20, array('notnull' => true,
                                              'primary' => true,
                                              'autoincrement' => true));
                
                $this->hasColumn('login','string',64,array('unique' => true));
                $this->hasColumn('password','string',64);
        }
}

Changed 16 months ago by jwage

  • status changed from reopened to closed
  • resolution set to fixed

(In [3947]) fixes #821

Note: See TracTickets for help on using tickets.