On Fri, Oct 05, 2007 at 12:01:35AM +0200, Daniel Fetchinson wrote:
> > > http://sqlobject.gcu.info/trac/ticket/294
> >
> >    If you replace the first join with (replace None with animal table)
> > joins.append( LEFTJOINOn( animal, cage, animal.q.cageID==cage.q.id ) )
> >    would it help?
> 
> Hi Oleg, this thing would be of interest to me as well.
> 
> After doing the change you advised the query runs without an exception
> but prints 0 which is obviously incorrect. I'm on sqlite, maybe
> somebody else could test with other backends?

joins = [ ]
joins.append( LEFTJOINOn( None, cage, animal.q.cageID==cage.q.id ) )
joins.append( LEFTJOINOn( None, zoo, cage.q.zooID==zoo.q.id ) )

print animal.select( zoo.q.name=='myzoo', join=joins ).count( )

   generates the query

SELECT COUNT(*) FROM named LEFT JOIN cage ON ((animal.cage_id) = (cage.id)) 
LEFT JOIN zoo ON ((cage.zoo_id) = (zoo.id))
WHERE (((named.name) = ('myzoo')) AND ((named.child_name) = ('animal')))

   for which SQLite returns the error:

sqlobject.dberrors.OperationalError: no such column: animal.cage_id

   The problem is that there is no table 'animal' in the FROM list. I am
trying to put the table there:

joins = [ ]
joins.append( LEFTJOINOn( animal, cage, animal.q.cageID==cage.q.id ) )
joins.append( LEFTJOINOn( None, zoo, cage.q.zooID==zoo.q.id ) )

print animal.select( zoo.q.name=='myzoo', join=joins ).count( )

   which leads to the query

SELECT COUNT(*) FROM named, animal LEFT JOIN cage ON ((animal.cage_id) = 
(cage.id)) LEFT JOIN zoo ON ((cage.zoo_id) = (zoo.id))
WHERE (((named.name) = ('myzoo')) AND ((named.child_name) = ('animal')))

   The result is '0', though - no rows are found. Now I don't know what
a query you expected.

   PostgreSQL reports exactly the same error:
psycopg2.ProgrammingError: missing FROM-clause entry for table "animal"
   so it's not a backend problem.

Oleg.
-- 
     Oleg Broytmann            http://phd.pp.ru/            [EMAIL PROTECTED]
           Programmers don't die, they just GOSUB without RETURN.

-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >> http://get.splunk.com/
_______________________________________________
sqlobject-discuss mailing list
sqlobject-discuss@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/sqlobject-discuss

Reply via email to