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!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=110944&bid=241720&dat=121642
_______________________________________________
Sqlalchemy-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/sqlalchemy-users