db.insert_id() is always returning 0 for me, while "SELECT LAST_INSERT_ID()" is returning the correct value. I would rather not do a whole other query. Has anyone else seen that?
Thanks.
Red Hat RHEL4
mysql-4.1.7
python-2.3.4-14
MySQL-python-1.2.0
(No, I can't upgrade any of these. My client needs this specific set of packages.)
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Cursor Attribute .lastrowid
This read-only attribute provides the rowid of the last
modified row (most databases return a rowid only when a single
INSERT operation is performed). If the operation does not set
a rowid or if the database does not support rowids, this
attribute should be set to None.
The semantics of .lastrowid are undefined in case the last
executed statement modified more than one row, e.g. when
using INSERT with .executemany().
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Thanks! I'm fixing someone else's code, as well as porting it from Windows to Linux, and they were using insert_id(). Sorry I didn't see this one in the docs. Serves me right for trusting Google first.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
db.insert_id() is always returning 0 for me, while "SELECT LAST_INSERT_ID()" is returning the correct value. I would rather not do a whole other query. Has anyone else seen that?
Thanks.
Red Hat RHEL4
mysql-4.1.7
python-2.3.4-14
MySQL-python-1.2.0
(No, I can't upgrade any of these. My client needs this specific set of packages.)
Don't use db.insert_id(); that's used internally. Instead:
http://www.python.org/dev/peps/pep-0249/
Thanks! I'm fixing someone else's code, as well as porting it from Windows to Linux, and they were using insert_id(). Sorry I didn't see this one in the docs. Serves me right for trusting Google first.