[SQLObject] Help with SQLBuilder NOTIN
SQLObject is a Python ORM.
Brought to you by:
ianbicking,
phd
From: Jason H. <jas...@gm...> - 2010-03-30 03:58:42
|
Hi, This is on Python 2.5.5 with SQLObject 0.11.0 and MySQL 5.1.41-3 (on Debian Squeeze). I'm a little mystified about the SQLBuilder subselector NOTIN(). I have the following MySQL query: SELECT db_stock_code FROM stock WHERE (db_stock_code LIKE "XXX%") AND (id NOT IN (SELECT db_stock_id FROM cont_item)); ...which works for me. "stock" is a very simple table (no joins or anything), and "cont_item" is like: class ContItem (SQLObject) : dbCont = ForeignKey('Cont') dbStock = ForeignKey('Stock') dbQuantity = IntCol() (The actual table has "db_stock_id" and "db_cont_id" columns.) I tried to use this SQLBuilder expression: my_selection = dbase.Stock.select( sqlobject.sqlbuilder.AND( dbase.Stock.q.dbStockCode.startswith("XXX"), sqlobject.sqlbuilder.NOTIN( sqlobject.sqlbuilder.Outer(dbase.Stock).q.id, sqlobject.sqlbuilder.Select(dbase.ContItem.q.dbStock, dbase.ContItem))) ...but when it executes, I get: [coming from that last line of my expression above] File "/usr/lib/python2.5/site-packages/sqlobject/main.py", line 1365, in select join=join, forUpdate=forUpdate) File "/usr/lib/python2.5/site-packages/sqlobject/sresults.py", line 36, in __init__ for table in clauseTables: TypeError: iteration over non-sequence I'd like to point out that (a) the whole SELECT statement above returns a few hundred results, and (b) the second clause to AND does exclude some entries. Please CC me on replies :) Cheers, Jason |