Lastrowid return: "Could not locate column in row for column
'lastrowid'". I try to use transaction:

trans = meta.Session.begin()
try:
    meta.Session.execute("INSERT statement")
    result = meta.Session.execute("SELECT LAST_INSERT_ID()")
    trans.commit()
except:
    trans.rollback()
    raise

Now, I'm testing this, think it helps to stop loosing session between
INSERT and SELECT.

On 15 сен, 21:45, Michael Bayer <mike...@zzzcomputing.com> wrote:
> "SELECT LAST_INSERT_ID()" is ultimately where the value comes from - the raw 
> .lastrowid is present on the ResultProxy for those DBAPIs which support it, 
> so try using that.   Perhaps you're getting "0" because the transaction is 
> going away, in which case .lastrowid should solve that issue.
>
> On Sep 15, 2010, at 12:45 PM, phasma wrote:
>
>
>
> > I've got database with auto increment column called `id` and INSERT
> > query, whom I need to execute without model declaration in project.
> > meta.Session.execute() returns ResultProxy, but last_inserted_ids()
> > doesn't work with execute() and "SELECT LAST_INSERT_ID()" statement
> > sometimes return 0. Is there any other way to fetch last inserted id ?
>
> > --
> > You received this message because you are subscribed to the Google Groups 
> > "sqlalchemy" group.
> > To post to this group, send email to sqlalch...@googlegroups.com.
> > To unsubscribe from this group, send email to 
> > sqlalchemy+unsubscr...@googlegroups.com.
> > For more options, visit this group 
> > athttp://groups.google.com/group/sqlalchemy?hl=en.

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

Reply via email to