Hi!

On Sat, Jun 15, 2013 at 10:35:17PM +0400, Oleg Broytman <p...@phdru.name> wrote:
> On Fri, Jun 14, 2013 at 04:57:10PM -0400, Rhubarb Sin <rhubarb...@gmail.com> 
> wrote:
> > I was surprised when I recently discovered I had to add an extra
> > underscore to use a SQLObject class's foreign key ID when using
> > sqlobject.sqlbuilder.Outer. For example, this works:
> > 
> > EXISTS(Select(Foo.q.id, where=Outer(Bar).q.foo_ID == Foo.q.id))
> > 
> > This does not work:
> > 
> > EXISTS(Select(Foo.q.id, where=AND(Outer(Bar).q.fooID == Foo.q.id)))
> 
>    What is going on is this: Outer works only symbolically - it
> generates column names without looking into class definition. That is,
> Outer(Bar).q.foo_ID puts "bar.foo_ID" into an SQL query and
> Outer(Bar).q.fooID generates "bar.fooID" without testing if such columns
> exist. There is no column fooID in table bar, hence the second query
> produces an error. There is a column foo_id, and bar.foo_ID works
> because SQL is case-insensitive language.
> 
>    If you read sqlbuilder.py you can find that Outer implemented using
> Table and Field helper classes. I can replace them with SQLObjectField
> and SQLObjectTable:
> 
> class SQLObjectOuterField(SQLObjectField):
>     def tablesUsedImmediate(self):
>         return []
> 
> class SQLObjectOuterTable(SQLObjectTable):
>     FieldClass = SQLObjectOuterField
> 
> class SQLObjectOuter:
>     def __init__(self, table):
>         self.q = SQLObjectOuterTable(table)
> 
>    Now SQLObjectOuter(Bar).q.foo_ID doesn't work but
> SQLObjectOuter(Bar).q.fooID works exactly as you expected, as well as
> SQLObjectOuter(Bar).q.foo.
> 
>    I think I can change the implementation of Outer in sqlbuilder using
> SQLObjectTable/Field helper but that requires a lot of testing. I doubt
> I will have time for it in June.

   I tested this, it works, so I committed the change at the revision 4613:
http://sourceforge.net/mailarchive/forum.php?thread_name=E1Uwysp-0003DP-4G%40webwareforpython.org&forum_name=sqlobject-cvs

   This is a major API change IMO so I'm cautious and only committed to
the trunk.
   Do you want me to release a beta version so you can test it with your
code?

Oleg.
-- 
     Oleg Broytman            http://phdru.name/            p...@phdru.name
           Programmers don't die, they just GOSUB without RETURN.

------------------------------------------------------------------------------
See everything from the browser to the database with AppDynamics
Get end-to-end visibility with application monitoring from AppDynamics
Isolate bottlenecks and diagnose root cause in seconds.
Start your free trial of AppDynamics Pro today!
http://pubads.g.doubleclick.net/gampad/clk?id=48808831&iu=/4140/ostg.clktrk
_______________________________________________
sqlobject-discuss mailing list
sqlobject-discuss@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/sqlobject-discuss

Reply via email to