[sqlalchemy] Re: delete failure with foreign key relations

2009-01-29 Thread Alex K
Well, this error says that you have rows in other(or same) tables referring to this row you are going to delete, and you should delete referring rows first. If you want SQLA to do it automatically, you need to use sessions and mappers (not raw SQL expression engine), more info here:

[sqlalchemy] Re: joining to child, and using child in relation

2009-01-29 Thread GHZ
Tested with trunk. Works, thanks. On Jan 29, 6:42 am, Michael Bayer mike...@zzzcomputing.com wrote: OK, well that was painful but we are stronger for the effort, thanks   for bringing up the issue.  r5740 of trunk will allow your original   mapper(A.join(B))-mapper(B) to configure properly.

[sqlalchemy] Re: autoflush during instanciation

2009-01-29 Thread GustaV
I quite sure I'm not using it... Look at that code that reproduce the bug http://utilitybase.com/paste/11481 The last line (p2 = Parent(p)) leads to a load of the children, so an autoflush. I have a failure with 0.5.2: sqlalchemy.exc.IntegrityError: (IntegrityError) parent.dumb may not be NULL

[sqlalchemy] Correct way of moving relation

2009-01-29 Thread Werner F. Bruhin
I have some items which are related but I need to change it so they related to another item. Before getting myself in a mess (as I need to do this for a bunch of tables) I wanted to check if the following approach is fine. I am using SA 0.5, ORM and declarative and the model is: class

[sqlalchemy] what is wrong with my update query

2009-01-29 Thread abhi
Hi folks, I have recently started to learn ORM tools in python. I am trying to write an update query based on a where clause. This is the original SQL: UPDATE mail SET fl=20 WHERE f =1 and uid =2 ; This is what I did in SA: flTot = 19 fNo = 2 uidNo = 5 a = column('f') + bindparam('fNo') b =

[sqlalchemy] Re: autoflush during instanciation

2009-01-29 Thread Michael Bayer
that's the cascade of p2 being added to the session upon being associated with the in-session items in p.children. So yes, cascade rules do add things to the session. setting cascade=None on Child.parent would prevent it, or alternatively you can turn off autoflush on the session for

[sqlalchemy] Getting ForeignKey Before Commit

2009-01-29 Thread Dejan Mayo
Hi, My code is like that: try: for some_val in some_values: rec = SomeModel() rec.some_val = some_val session.save(rec) session.commit() except: session.rollback() For each record that I'm creating, I need to send an email right after. And each email

[sqlalchemy] Re: Correct way of moving relation

2009-01-29 Thread Werner F. Bruhin
Werner F. Bruhin wrote: I have some items which are related but I need to change it so they related to another item. Before getting myself in a mess (as I need to do this for a bunch of tables) I wanted to check if the following approach is fine. I am using SA 0.5, ORM and declarative

[sqlalchemy] Re: Correct way of moving relation

2009-01-29 Thread Michael Bayer
On Jan 29, 2009, at 11:32 AM, Werner F. Bruhin wrote: Werner F. Bruhin wrote: I have some items which are related but I need to change it so they related to another item. Before getting myself in a mess (as I need to do this for a bunch of tables) I wanted to check if the following

[sqlalchemy] Re: Correct way of moving relation

2009-01-29 Thread Werner F. Bruhin
Michael, Michael Bayer wrote: ... there's no need to reassign the FK column yourself and the original pattern you're using is correct. that only one item in the list is the exception suggests something else is changing its state again further down the road. Thanks for the quick

[sqlalchemy] Postgres and count() weirdness

2009-01-29 Thread Bob Farrell
Hi, query.count().scalar() This code works fine with sqlite and Oracle, but with PG it goes nuts and complains that an explicit AS must be used in a subselect, i.e. it's doing this: select count(*) as blah from (select ...) But PG wants this: select count(*) as blah from (select

[sqlalchemy] Re: delete failure with foreign key relations

2009-01-29 Thread n00b
sorry. i obviously didn't explain too well. it DOES work with ORM. i don't have a problem at all. however, i can't work with the tables using engine.conect or straight MySQLdb, for that matter. in fact, closer examination suggests that not only are the onupdate, ondelete = CASCADE not set in the

[sqlalchemy] Re: Postgres and count() weirdness

2009-01-29 Thread Michael Bayer
for the SQL expression language we try not to guess things like that. the difference between a select() and an alias() is pretty big. On Jan 29, 2009, at 12:36 PM, Bob Farrell wrote: Hi, query.count().scalar() This code works fine with sqlite and Oracle, but with PG it goes nuts

[sqlalchemy] Re: Correct way of moving relation

2009-01-29 Thread Werner F. Bruhin
Michael, I run the following script and initially had the either my application and/or the IB Expert database tool (for Firebird SQL v 2.1) open at the same time. Now the following tests are done without any other task accessing the database. script: engine = db.sa.create_engine(dburl,

[sqlalchemy] Re: Correct way of moving relation

2009-01-29 Thread az
that sess.fulsh() in the middle there... if u move it up/down/out, will behaviour change? e.g. if u print the things in itemB.purchase just _After that flush - is 80 there or not? On Thursday 29 January 2009 20:19:59 Werner F. Bruhin wrote: Michael, I run the following script and initially

[sqlalchemy] Re: Correct way of moving relation

2009-01-29 Thread Michael Bayer
On Jan 29, 2009, at 1:19 PM, Werner F. Bruhin wrote: Michael, I run the following script and initially had the either my application and/or the IB Expert database tool (for Firebird SQL v 2.1) open at the same time. Now the following tests are done without any other task accessing

[sqlalchemy] Re: Full connection pool close

2009-01-29 Thread Rick Morrison
I worked up a test case that simulates your usage, and checks the number of open MSSQL connections using a call to the system stored proc sp_who, so it can run in a more automated fashion. I originally got mixed results on this, it would pass about 50% of the time and fail about 50% of the time.

[sqlalchemy] Re: Correct way of moving relation

2009-01-29 Thread Werner F. Bruhin
Michael Bayer wrote: .. right there, purchasid 80 is not even in the list of items anymore. This is basically iterate the list, 80 is there, then flush(), then 80 is not there. this is all before anything has been moved. so either the flush() does something, or just the move of

[sqlalchemy] Re: Correct way of moving relation

2009-01-29 Thread Michael Bayer
oh, duh. do it like this: for purchase in list(aItem.purchase): purchase.cbbottle = bItem I leave it to you as an exercise why this is the case. On Jan 29, 2009, at 3:08 PM, Werner F. Bruhin wrote: Michael Bayer wrote: .. right there, purchasid 80 is not even in the list of

[sqlalchemy] Re: Getting ForeignKey Before Commit

2009-01-29 Thread n00b
why don't you work off the las/previous committed rec id? On Jan 29, 4:05 am, Dejan Mayo dejan.m...@gmail.com wrote: Hi, My code is like that: try:     for some_val in some_values:         rec = SomeModel()         rec.some_val = some_val         session.save(rec)     session.commit()