On Sep 16, 2010, at 11:15 AM, Michael Bayer wrote:

> 
> On Sep 16, 2010, at 10:47 AM, Chris Withers wrote:
> 
>> On 16/09/2010 14:32, Michael Bayer wrote:
>>> 
>>>> session imported from Meta ? If use Meta.Session.execute it's returns
>>>> RowProxy, which has no lastrowid parameter.
>>> 
>>> execute() does not return a RowProxy.   All execute() methods return a 
>>> ResultProxy which consists of metadata about a result as well as an 
>>> interator interface that produces RowProxy instances.
>> 
>> Right, but I wonder if this mirrors what the OP reports:
>> 
>>   return self.cursor.lastrowid
>> AttributeError: 'NoneType' object has no attribute 'lastrowid'
> 
> thats a bug, a regression introduced in 0.6.4.  will fix.

this bug is fixed in r1668e771ad16 .  r.lastrowid should work with 0.6.3 and 
previous, as does "SELECT LAST_INSERT_ID()" if you are correctly calling it on 
the same transaction.  
Here is an example:

from sqlalchemy import *
from sqlalchemy.orm import *

m = MetaData()
t = Table("t", m,
    Column("x", Integer, primary_key=True),
    Column('data', String(50))
)

e = create_engine('mysql://scott:ti...@localhost/test')

t.drop(e)
t.create(e)

s = Session(e)

for i in xrange(10):
    r = s.execute("insert into t (data) values ('foo')")
    print s.scalar("SELECT LAST_INSERT_ID()")

output:

1
2
3
4
5
6
7
8
9
10



> 
> execute() still doenst return a RowProxy tho
> 
> 
>> 
>>>>> type(result)
>> <class 'sqlalchemy.engine.base.ResultProxy'>
>> 
>>>>> session.commit()
>> 2010-09-16 15:43:06,034 INFO sqlalchemy.engine.base.Engine.0x...e610 COMMIT
>>>>> result.lastrowid
>> Traceback (most recent call last):
>> File "<console>", line 1, in <module>
>> File "SQLAlchemy-0.6.4-py2.6.egg/sqlalchemy/engine/base.py", line 2310, in 
>> lastrowid
>>   return self.cursor.lastrowid
>> AttributeError: 'NoneType' object has no attribute 'lastrowid'
>> 
>> I would have thought MySQL would support lastrowid?
>> 
>> Chris
>> 
>> -- 
>> 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.
>> 
> 
> -- 
> 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.
> 

-- 
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