Unfortunately, with you first suggestion, my create user operation in part of a larger transaction, and I can't commit the transaction at this point because I haven't finished processing stuff yet.  I tried to go the route of you second suggestion, but I'd like to grab the sequence in a little more database invariant manner.  I poked around the code a bit, but I couldn't find a simple way to bump sequence value.  It would be great if there was a next_value() method on the Sequence object.  With this I could:

user = User(userDict)
user.id = User.mapper.c.id.default.next_value()

# do other things....

objectstore.commit()

Is there something similar to next_value() out there to easily grab the next sequence value?

Aaron


On Mar 4, 2006, at 9:08 AM, Alan Franzoni wrote:

Il Sat, 4 Mar 2006 07:54:31 -0500, Aaron Bickell ha scritto:

objectstore.commit().  I need the identifier when I create the object  
for logging, and messaging purposes (amongst others). I don't want to  
commit the transaction at this point, but I would like to have the  
resultant object to be in 'sync' with the object store. This is what  

I can imagine you're using a non-meaningful, integer id connected with a
sequence. In that case, I doubt you can get the id without calling
objectstore.commit(): if you set echo=True in your engine string, you'll
see that the sequence is handled by the database, and asking for the next
sequence value in pgsql has the side-effect of *increasing* the sequence
value itself. So you cannot call that function 'manually', unless you then
use that value to manually override the id provided by the sequence. I
think there're two ways to do what you want:

1) Use a transaction. You'll get your object along with your id, but it
won't really get committed until you call engine.commit()

engine.begin()
u = User()
u.name = "John"
u.surname = "Smith"
objectstore.commit(u)
id = u.id

2) Manualli override your sequence, but remember passing the right id to
the object:

conn = schema.engine.connection()
c = conn.cursor()
c.execute("SELECT nextval('users_id_seq')")
id = c.fetchone()[0]

u = User()
u.id = id
u.name = "John"
u.surname = "Smith"

Of course the string passed to the execute() function will vary depending
on the table and on the db you're using.

-- 
Alan Franzoni <[EMAIL PROTECTED]>
-
Togli .xyz dalla mia email per contattarmi.
To contact me, remove .xyz from my email address.
-
GPG Key Fingerprint:
5C77 9DC3 BD5B 3A28 E7BC 921A 0255 42AA FE06 8F3E



-------------------------------------------------------
This SF.Net email is sponsored by xPML, a groundbreaking scripting language
that extends applications into web and mobile media. Attend the live webcast
and join the prime developer group breaking into this new coding territory!
_______________________________________________
Sqlalchemy-users mailing list

Aaron Bickell
Research & Development
Optio Software, Inc


Reply via email to