[sqlalchemy] Re: Associations in a cleaner way

2007-03-05 Thread King Simon-NFHD78

 
Knut Aksel Røysland wrote:
 
 [snip]
 
 However, an instance of D also needs a reference to an instance of C.
 If the appropriate instance of C exists in the database (or 
 is pending to go into it), I want to pick this one, or 
 otherwise create a new instance of C.
 
 What I am looking for is the most clean way to achieve this. 
 I have run into trouble trying to use session.get(C, c_id) to 
 lookup instances of C that have not been flushed yet. (I 
 guess this might have something to do with primary keys not 
 working before instances have become persistent?)
 
 Furthermore, I want the constructor of D to be where I lookup 
 or create the appropriate instance of P, which seems to 
 require that I pass the session object to the constructor so 
 it can use session.get to look for an existing instance of P. 
 I feel this passing of the session object around, is going to 
 clutter the code, so I am looking for a cleaner way.
 
 [snip]

You may find the UniqueObject recipe useful:

http://www.sqlalchemy.org/trac/wiki/UsageRecipes/UniqueObject

It should help with the 'use-existing-or-create-new' part of your problem. I 
had a few difficulties when I tried to use it, but on reflection I think that 
was because I held references to objects after I had cleared the session. It 
also makes it difficult when you really do want to check whether an object 
exists in the DB without creating it, but it shouldn't be too difficult to 
adapt.

Instead of passing the session object around, you might be able to use the 
object_session function, which returns the session which the object is 
associated with, so in your constructor you could try 'session = 
object_session(self)'

Hope that helps,

Simon

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To post to this group, send email to sqlalchemy@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~--~~~~--~~--~--~---



[sqlalchemy] Re: Support for incomplete dates

2007-03-05 Thread Michael Bayer

in most cases the DBAPI driver, not SA, is the one returning the  
Python datetime objects to you.  also like Rick said most DBs are not  
going to store an invalid date.  so if you arent storing an actual  
date, you probably dont want to declare those columns as Date columns.

On Mar 4, 2007, at 7:00 PM, Mel Collins wrote:


  Hey all,
  I have an application which needs to support 'incomplete' dates -
 those where the month or day are unknown (or even the year, why not?).
  MySQL supports doing this in it's Date column type (I don't know
 about other DBs), so for example I can have a date field containing:
 1998-10-00.
  Unfortunately, python/SA always attempts to read date columns into
 the datetime.date type, which doesn't support incomplete dates, and
 you end up with None.
  I've tried overriding the column definition (I use reflection) in the
 SA table declaration, to make it a String, but it is still read from
 the database into a datetime.date object (which SA then tries to
 decode() unsuccessfully). I guess this means that it's outside of SA
 that the column is made a datetime.date?

  As I haven't yet found any other way around this, my only recourse
 seems to be to split the date columns into three, which just feels
 wrong to me. Can anyone suggest a more elegant solution?

  Takk,
  - Mel C


 


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To post to this group, send email to sqlalchemy@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~--~~~~--~~--~--~---



[sqlalchemy] Re: specifying a primary key, keepinging client/server in sync

2007-03-05 Thread Michael Bayer


On Mar 4, 2007, at 9:58 PM, rgravina wrote:


 I was wondering if it is possible to specify a primary key manually?

sure, just set whatever column-based attributes you like before  
flushing...such as if your table's primary key column is named  
some_id, you could say:

myobject.some_id = 7
session.flush()


 The reason I want to do this is I have a Twisted client/server program
 where the clients have some of the data from the server. I'd like the
 clients to be able to have their own sqlalchemy database with objects
 and relationships which have the same primary keys as on the server.
 That way, when one user updates an object, I can nofity all clients
 that some object has been updated.

 Also, Is there a better way to go about this? Essentially, what I'm
 after is a distributed object database, but I can settle with my
 implementation as above. Could this be implemented with SQLAlchmey/
 Twisted?

well youre saying youve already done it, right ? :)  I did get to  
speak to Glyph at Pycon a little bit but I dont think hes sold on SA  
quite yet.  But at least several people have various combinations of  
Twisted/SA running.   I havent ventured into trying to invent  
strategies for database replication and distribution since theyre  
bound to be incomplete solutions, which id then get stuck with people  
complaining that it doesnt work.  Replication and distribution would  
best be implemented by the RDBMS itself.



--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To post to this group, send email to sqlalchemy@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~--~~~~--~~--~--~---



[sqlalchemy] Re: query on self-referencing polymorphic mapper

2007-03-05 Thread svilen

ok, that solves some things, i won't need those ultra-explicit 
selects() now.
The other problem remains: 
 union's mechanism for corresponding_column() takes ownership of all 
columns mentioned in the WHERE, regardless if they are from a table 
within the union/join, or in alias of that table.
i.e. all columns mentioned in the WHERE become punion.column_name.

  The query itself, if fixed manualy, works:
  SELECT ...
  FROM (...) as pu_human, human as humanalias
  WHERE pu_human.friend_id = humanalias.db_id AND humanalias.age 
  ?
 
  while the SA does:
  SELECT ...
  FROM (...) as pu_human
  WHERE pu_human.friend_id = pu_human.db_id AND pu_human.age  ?
 
  is it some .corresponding_column() taking ownership of too many
  things?

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To post to this group, send email to sqlalchemy@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~--~~~~--~~--~--~---



[sqlalchemy] Ping

2007-03-05 Thread percious

I need to ping the Mysql database to keep it alive.

Is there a simple way to do this with SA?

-chris


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To post to this group, send email to sqlalchemy@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~--~~~~--~~--~--~---



[sqlalchemy] Re: Ping

2007-03-05 Thread Sébastien LELONG

 I need to ping the Mysql database to keep it alive.

 Is there a simple way to do this with SA?

Maybe you'd want to have a look at the pool_recycle argument of 
create_engine. It'll make the connection pool beeing checked if active, and 
potentially recycle the connections if they are too old. Search for MySQL 
has gone away, you'll have different threads talking about that.


Hope it helps.

Seb
-- 
Sébastien LELONG
sebastien.lelong[at]sirloon.net
http://www.sirloon.net

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To post to this group, send email to sqlalchemy@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~--~~~~--~~--~--~---



[sqlalchemy] Re: query on self-referencing polymorphic mapper

2007-03-05 Thread Michael Bayer

On Mar 5, 2007, at 11:58 AM, svilen wrote:


 The other problem remains:
  union's mechanism for corresponding_column() takes ownership of all
 columns mentioned in the WHERE, regardless if they are from a table
 within the union/join, or in alias of that table.
 i.e. all columns mentioned in the WHERE become punion.column_name.


here, play with this patch


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To post to this group, send email to sqlalchemy@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~--~~~~--~~--~--~---



adapts_embedded_only.diff
Description: Binary data



[sqlalchemy] rev2309 breaks some of the A-B ref/inh cases

2007-03-05 Thread Pete Taylor

in regard to post-2309 revisions and the foreignkey keyword deprecation...

I know this conversation seems to have terminated as of 2/21, but it's
the only thread that was tracing through a problem i'm having.  I'm
certain my problem is just one of my own lack of understanding on how
to use foreign_keys now, but I'll lay it out there...

I have a legacy table that, in effect, maps to two classes.  A
container-style class and a line items class, which for convenience
we'll just call Container and LineItem.  A Container has_many
LineItem, as you might imagine.  The issue, however, is that the
Container class is mapped against a select statement from that table,
not the table directly, while the LineItem class is mapped against the
table, largely because there's an incrementing LineItem id that's a
primary key on the table, but has no meaning to the Container.

before 2309, I was able to map the lineItem relationship back to the
container class using an explicit primary join and a foreignkey
statement.

I've read through the self-referential example rather a lot, and the
two mailing list threads, and have tried all the combinations and
permutations of primaryjoin, foreign_keys, and remote_side that I can
think of (obviously not all of them or it would have worked ;) ), from
the mappers and relationships on both classes, and I can't seem to
figure out the right way to make it work.  I can send along a
simplified mockup of the relationships and what I've got currently if
anyone has time to take a look, but I may in fact just be heading the
wrong direction...

Any help would be greatly appreciated!
Pete Taylor

-- 
All guilt is relative, loyalty counts, and never let your conscience
be your guide.
  - Lucas Buck, American Gothic

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To post to this group, send email to sqlalchemy@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~--~~~~--~~--~--~---



[sqlalchemy] Re: rev2309 breaks some of the A-B ref/inh cases

2007-03-05 Thread Michael Bayer

please forward an runnable example test case, preferably a single  
file with 200 lines if possible.

you're also making usage of Column instances directly off the  
selectable youre mapping, right ?


On Mar 5, 2007, at 1:55 PM, Pete Taylor wrote:


 in regard to post-2309 revisions and the foreignkey keyword  
 deprecation...

 I know this conversation seems to have terminated as of 2/21, but it's
 the only thread that was tracing through a problem i'm having.  I'm
 certain my problem is just one of my own lack of understanding on how
 to use foreign_keys now, but I'll lay it out there...

 I have a legacy table that, in effect, maps to two classes.  A
 container-style class and a line items class, which for convenience
 we'll just call Container and LineItem.  A Container has_many
 LineItem, as you might imagine.  The issue, however, is that the
 Container class is mapped against a select statement from that table,
 not the table directly, while the LineItem class is mapped against the
 table, largely because there's an incrementing LineItem id that's a
 primary key on the table, but has no meaning to the Container.

 before 2309, I was able to map the lineItem relationship back to the
 container class using an explicit primary join and a foreignkey
 statement.

 I've read through the self-referential example rather a lot, and the
 two mailing list threads, and have tried all the combinations and
 permutations of primaryjoin, foreign_keys, and remote_side that I can
 think of (obviously not all of them or it would have worked ;) ), from
 the mappers and relationships on both classes, and I can't seem to
 figure out the right way to make it work.  I can send along a
 simplified mockup of the relationships and what I've got currently if
 anyone has time to take a look, but I may in fact just be heading the
 wrong direction...

 Any help would be greatly appreciated!
 Pete Taylor

 -- 
 All guilt is relative, loyalty counts, and never let your conscience
 be your guide.
   - Lucas Buck, American Gothic

 


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To post to this group, send email to sqlalchemy@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~--~~~~--~~--~--~---



[sqlalchemy] Copying from one database format to another

2007-03-05 Thread Adam Peacock

Is there a tool for SA to copy from one database to another?  I'm
looking for a simple way to propogate my testing database (sqlite)
from my production database (postgres), so that I can play with actual
data during testing without worrying about what I'm going to mess up.
Is there an automated way to do this?


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To post to this group, send email to sqlalchemy@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~--~~~~--~~--~--~---



[sqlalchemy] Re: rev2309 breaks some of the A-B ref/inh cases

2007-03-05 Thread Pete Taylor
yessir, when using selectables i always just use selectobj.c.colname...

i've attached a quick test case, and it throws the same error that my
live code does, so it at least proves i can break things the same way
twice :D  i wouldn't be surprised if it's something easy that i'm just
doing wrong, but here it is all the same.

the test case relation for lineItems is the most bare-bones version of
the one's i've tried, but this is the first one I tried...  it merely
substitutes foreign_keys for where, pre-2309, had foreignkey.

Thanks for looking!
Pete

On 3/5/07, Michael Bayer [EMAIL PROTECTED] wrote:

 please forward an runnable example test case, preferably a single
 file with 200 lines if possible.

 you're also making usage of Column instances directly off the
 selectable youre mapping, right ?


 On Mar 5, 2007, at 1:55 PM, Pete Taylor wrote:

 
  in regard to post-2309 revisions and the foreignkey keyword
  deprecation...
 
  I know this conversation seems to have terminated as of 2/21, but it's
  the only thread that was tracing through a problem i'm having.  I'm
  certain my problem is just one of my own lack of understanding on how
  to use foreign_keys now, but I'll lay it out there...
 
  I have a legacy table that, in effect, maps to two classes.  A
  container-style class and a line items class, which for convenience
  we'll just call Container and LineItem.  A Container has_many
  LineItem, as you might imagine.  The issue, however, is that the
  Container class is mapped against a select statement from that table,
  not the table directly, while the LineItem class is mapped against the
  table, largely because there's an incrementing LineItem id that's a
  primary key on the table, but has no meaning to the Container.
 
  before 2309, I was able to map the lineItem relationship back to the
  container class using an explicit primary join and a foreignkey
  statement.
 
  I've read through the self-referential example rather a lot, and the
  two mailing list threads, and have tried all the combinations and
  permutations of primaryjoin, foreign_keys, and remote_side that I can
  think of (obviously not all of them or it would have worked ;) ), from
  the mappers and relationships on both classes, and I can't seem to
  figure out the right way to make it work.  I can send along a
  simplified mockup of the relationships and what I've got currently if
  anyone has time to take a look, but I may in fact just be heading the
  wrong direction...
 
  Any help would be greatly appreciated!
  Pete Taylor
 
  --
  All guilt is relative, loyalty counts, and never let your conscience
  be your guide.
- Lucas Buck, American Gothic
 
  


 



-- 
All guilt is relative, loyalty counts, and never let your conscience
be your guide.
  - Lucas Buck, American Gothic

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To post to this group, send email to sqlalchemy@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~--~~~~--~~--~--~---

#!/usr/bin/env python

import datetime
from sqlalchemy import *

db = create_engine('sqlite:///:memory:')
metadata = BoundMetaData(db)

class Container(object): pass
class LineItem(object): pass

items = Table('items', metadata,
Column('item_policy_num', String(10), primary_key=True, key='policyNum'),
Column('item_policy_eff_date', DateTime, primary_key=True, key='policyEffDate'),
Column('item_type', String(20), primary_key=True, key='type'),
Column('item_id', Integer, primary_key=True, key='id'),
)


container_select = select(
[items.c.policyNum, items.c.policyEffDate, items.c.type],
distinct=True,
).alias('container_select')

LineItem.mapper = mapper(LineItem, items)

Container.mapper = mapper(Container, container_select, order_by=asc(container_select.c.item_type), properties=dict(
lineItems = relation(LineItem, lazy=False, cascade='all, delete-orphan', order_by=asc(items.c.type),
primaryjoin=and_(
container_select.c.item_policy_num==items.c.policyNum,
container_select.c.item_policy_eff_date==items.c.policyEffDate,
container_select.c.item_type==items.c.type
),
foreign_keys=[
items.c.policyNum,
items.c.policyEffDate,
items.c.type,
],
)
))

def main():
metadata.create_all()
session = create_session()
con = Container()
con.policyNum = 99
con.policyEffDate = datetime.date.today()
con.type = TESTER
session.save(con)
for i in range(0, 10):
li = LineItem()
li.id = i
con.lineItems.append(li)
session.save(li)
session.flush()
session.clear()
con = session.query(Container).selectfirst()
print DEBUG: con has %s line 

[sqlalchemy] Re: rev2309 breaks some of the A-B ref/inh cases

2007-03-05 Thread Michael Bayer

no problem, that test uncovered a place I could ratchet things down  
some more so everybody wins.   you want rev 2383.

On Mar 5, 2007, at 3:09 PM, Pete Taylor wrote:

 yessir, when using selectables i always just use  
 selectobj.c.colname...

 i've attached a quick test case, and it throws the same error that my
 live code does, so it at least proves i can break things the same way
 twice :D  i wouldn't be surprised if it's something easy that i'm just
 doing wrong, but here it is all the same.

 the test case relation for lineItems is the most bare-bones version of
 the one's i've tried, but this is the first one I tried...  it merely
 substitutes foreign_keys for where, pre-2309, had foreignkey.

 Thanks for looking!
 Pete

 On 3/5/07, Michael Bayer [EMAIL PROTECTED] wrote:

 please forward an runnable example test case, preferably a single
 file with 200 lines if possible.

 you're also making usage of Column instances directly off the
 selectable youre mapping, right ?


 On Mar 5, 2007, at 1:55 PM, Pete Taylor wrote:


 in regard to post-2309 revisions and the foreignkey keyword
 deprecation...

 I know this conversation seems to have terminated as of 2/21, but  
 it's
 the only thread that was tracing through a problem i'm having.  I'm
 certain my problem is just one of my own lack of understanding on  
 how
 to use foreign_keys now, but I'll lay it out there...

 I have a legacy table that, in effect, maps to two classes.  A
 container-style class and a line items class, which for convenience
 we'll just call Container and LineItem.  A Container has_many
 LineItem, as you might imagine.  The issue, however, is that the
 Container class is mapped against a select statement from that  
 table,
 not the table directly, while the LineItem class is mapped  
 against the
 table, largely because there's an incrementing LineItem id that's a
 primary key on the table, but has no meaning to the Container.

 before 2309, I was able to map the lineItem relationship back to the
 container class using an explicit primary join and a foreignkey
 statement.

 I've read through the self-referential example rather a lot, and the
 two mailing list threads, and have tried all the combinations and
 permutations of primaryjoin, foreign_keys, and remote_side that I  
 can
 think of (obviously not all of them or it would have worked ;) ),  
 from
 the mappers and relationships on both classes, and I can't seem to
 figure out the right way to make it work.  I can send along a
 simplified mockup of the relationships and what I've got  
 currently if
 anyone has time to take a look, but I may in fact just be heading  
 the
 wrong direction...

 Any help would be greatly appreciated!
 Pete Taylor

 --
 All guilt is relative, loyalty counts, and never let your  
 conscience
 be your guide.
   - Lucas Buck, American Gothic








 -- 
 All guilt is relative, loyalty counts, and never let your conscience
 be your guide.
   - Lucas Buck, American Gothic

 
 #!/usr/bin/env python

 import datetime
 from sqlalchemy import *

 db = create_engine('sqlite:///:memory:')
 metadata = BoundMetaData(db)

 class Container(object): pass
 class LineItem(object): pass

 items = Table('items', metadata,
 Column('item_policy_num', String(10), primary_key=True,  
 key='policyNum'),
 Column('item_policy_eff_date', DateTime, primary_key=True,  
 key='policyEffDate'),
 Column('item_type', String(20), primary_key=True, key='type'),
 Column('item_id', Integer, primary_key=True, key='id'),
 )


 container_select = select(
 [items.c.policyNum, items.c.policyEffDate, items.c.type],
 distinct=True,
 ).alias('container_select')

 LineItem.mapper = mapper(LineItem, items)

 Container.mapper = mapper(Container, container_select, order_by=asc 
 (container_select.c.item_type), properties=dict(
 lineItems = relation(LineItem, lazy=False, cascade='all, delete- 
 orphan', order_by=asc(items.c.type),
 primaryjoin=and_(
 container_select.c.item_policy_num==items.c.policyNum,
  
 container_select.c.item_policy_eff_date==items.c.policyEffDate,
 container_select.c.item_type==items.c.type
 ),
 foreign_keys=[
 items.c.policyNum,
 items.c.policyEffDate,
 items.c.type,
 ],
 )
 ))

 def main():
 metadata.create_all()
 session = create_session()
 con = Container()
 con.policyNum = 99
 con.policyEffDate = datetime.date.today()
 con.type = TESTER
 session.save(con)
 for i in range(0, 10):
 li = LineItem()
 li.id = i
 con.lineItems.append(li)
 session.save(li)
 session.flush()
 session.clear()
 con = session.query(Container).selectfirst()
 print DEBUG: con has %s line items % len(con.lineItems)

 if __name__ == __main__:
 main()


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the 

[sqlalchemy] Desktop apps with SQLachemy?

2007-03-05 Thread iainduncan

I'm wondering if anyone can suggest the best tools or way to make python desktop
db apps using sqlalchemy, and in a manner that is as close to turbogears or
pylons as possible. I would like to be able to offer desktop internal apps that
playfair with TG based sites. I use wxWidgets already in some non-db work for
what it's worth.

Thanks
Iain






--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To post to this group, send email to sqlalchemy@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~--~~~~--~~--~--~---



[sqlalchemy] Re: Dynamically building a query with a join

2007-03-05 Thread Michael Bayer

there is append_from()

joins know how to find their components that are already in the  
selectable and replace them.

On Mar 5, 2007, at 4:38 PM, Dennis wrote:


 I'm playing around with dynamically building a query.  I can append
 columns, where clauses, from objects etc... but what about the case
 where I want to modify the from obj with a join?

 For example I can do this:

 sel=select()
 sel.append_from(a)
 sel.append_from(b)
 sel.append_whereclause(a.c.id==b.c.id)

 That won't work for an outerjoin though.  I have a query that works
 like this now:

 select ( [...], from_obj=[a.outerjoin(b)] )

 but I can't figure out a way to add the outerjoin dynamically.  I
 looked at clause visitors but there doesn't seem like a way to
 actually modify an existing join.

 Any thoughts?

 Thanks
 Dennis


 


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To post to this group, send email to sqlalchemy@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~--~~~~--~~--~--~---



[sqlalchemy] Re: Dynamically building a query with a join

2007-03-05 Thread Dennis

Actually, I'm still having a problem because the primary object is
already a join and the next object that I append gets listed twice.

Example

sel=select([a,b], from_obj=[a.outerjoin(b)])
sel.append( a.outerjoin(c,somecriteriaforthejoin))
str(sel)
SELECT ,,, FROM a LEFT OUTER JOIN b ON  , a LEFT OUTER JOIN c
ON ...
sel.execute()
SQLError: (ProgrammingError) table name a specified more than once

What I really need is: a.outerjoin(b).outerjoin(c)
That is what I can't seem to find a way to dynamically generate.

Thanks
-Dennis


On Mar 5, 3:16 pm, Michael Bayer [EMAIL PROTECTED] wrote:
 there is append_from()

 joins know how to find their components that are already in the
 selectable and replace them.

 On Mar 5, 2007, at 4:38 PM, Dennis wrote:



  I'm playing around with dynamically building a query.  I can append
  columns, where clauses, from objects etc... but what about the case
  where I want to modify the from obj with a join?

  For example I can do this:

  sel=select()
  sel.append_from(a)
  sel.append_from(b)
  sel.append_whereclause(a.c.id==b.c.id)

  That won't work for an outerjoin though.  I have a query that works
  like this now:

  select ( [...], from_obj=[a.outerjoin(b)] )

  but I can't figure out a way to add the outerjoin dynamically.  I
  looked at clause visitors but there doesn't seem like a way to
  actually modify an existing join.

  Any thoughts?

  Thanks
  Dennis


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To post to this group, send email to sqlalchemy@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~--~~~~--~~--~--~---



[sqlalchemy] Re: Dynamically building a query with a join

2007-03-05 Thread Dennis

I did find a slight hack:

query.append_from (
 query.froms._list[0].outerjoin( etc ... ) )

-Dennis

On Mar 5, 3:54 pm, Dennis [EMAIL PROTECTED] wrote:
 Actually, I'm still having a problem because the primary object is
 already a join and the next object that I append gets listed twice.

 Example

 sel=select([a,b], from_obj=[a.outerjoin(b)])
 sel.append( a.outerjoin(c,somecriteriaforthejoin))
 str(sel)
 SELECT ,,, FROM a LEFT OUTER JOIN b ON  , a LEFT OUTER JOIN c
 ON ...
 sel.execute()
 SQLError: (ProgrammingError) table name a specified more than once

 What I really need is: a.outerjoin(b).outerjoin(c)
 That is what I can't seem to find a way to dynamically generate.

 Thanks
 -Dennis

 On Mar 5, 3:16 pm, Michael Bayer [EMAIL PROTECTED] wrote:

  there is append_from()

  joins know how to find their components that are already in the
  selectable and replace them.

  On Mar 5, 2007, at 4:38 PM, Dennis wrote:

   I'm playing around with dynamically building a query.  I can append
   columns, where clauses, from objects etc... but what about the case
   where I want to modify the from obj with a join?

   For example I can do this:

   sel=select()
   sel.append_from(a)
   sel.append_from(b)
   sel.append_whereclause(a.c.id==b.c.id)

   That won't work for an outerjoin though.  I have a query that works
   like this now:

   select ( [...], from_obj=[a.outerjoin(b)] )

   but I can't figure out a way to add the outerjoin dynamically.  I
   looked at clause visitors but there doesn't seem like a way to
   actually modify an existing join.

   Any thoughts?

   Thanks
   Dennis


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To post to this group, send email to sqlalchemy@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~--~~~~--~~--~--~---



[sqlalchemy] Polymorphic collections / ticket #500

2007-03-05 Thread Rick Morrison
The fix for ticket #500 breaks a pattern I've been using.

It's most likely an anti-pattern, but I don't see a way to get what I want
in SA otherwise.

I've got a series of entities

class Person():
   pass

class Manager(Person):
   def __init__(self):
   # do manager stuff
 
class Demigod(Person):
   def __init__(self):
   # do demigod stuff

etc.

there are mappers for each of these entities that inherit from Person(), so
all of the normal Person() properties exist, but Person() itself is not
polymorphic. That's on purpose, and because the class hierarchy of
Manager(), etc, is not exhaustive, and I occasionally
 want to save instances of Person() directly.
If I make the Person() class polymorphic on a column of say typ, then SA
clears whatever typ I may have tried to set directly, and seems to make me
specify an exhaustive list of sub-types.

And so I leave Person() as non-polymorphic. I also have a collection of
Person() objects on a different mapper, which can load entity objects of any
type.

Before rev #2382, I could put a Manager() in a Person() collection, and
 it would flush OK. Now it bitches that it wants a real
 polymorphic mapper. I don't want to use a polymorphic
 mapper, because I don't want to specify an exhaustive list
 of every class that I'm ever going to use.

What to do?

Thanks,
Rick

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To post to this group, send email to sqlalchemy@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~--~~~~--~~--~--~---



[sqlalchemy] sa newbie

2007-03-05 Thread dan

I'm trying to track down the syntax for using a 'like' clause with sql
soup.  I'm trying to do something like
select book_sku from books where book_sku like 'abcd%';

best i can tell, my syntax should look something like:
skus = db.books.select(book_skus.like('abcd%'))

but I'm getting an error, so obviously not.  Pointers?

tia,
dan


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To post to this group, send email to sqlalchemy@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~--~~~~--~~--~--~---