I've searched for an answer to this and looked at the source code, but ...
I've recently taken over maintenance of a FreeBSD server containing some programs I didn't author. Upon doing a portupgrade, one CGI program has broken, as follows:
"""
cur = db.cursor(MySQLdb.cursors.DictCursor)
reportdict['id'] = cur.insert_id()
...
<MySQLdb.cursors.DictCursor object>, cur.insert_id undefined
AttributeError: DictCursor object has no attribute 'insert_id"
"""
Has insert_id been recently deprecated or replaced in one of the Mixin classes or something?
I've searched for an answer to this and looked at the source code, but ...
I've recently taken over maintenance of a FreeBSD server containing some programs I didn't author. Upon doing a portupgrade, one CGI program has broken, as follows:
"""
cur = db.cursor(MySQLdb.cursors.DictCursor)
reportdict['id'] = cur.insert_id()
...
<MySQLdb.cursors.DictCursor object>, cur.insert_id undefined
AttributeError: DictCursor object has no attribute 'insert_id"
"""
Has insert_id been recently deprecated or replaced in one of the Mixin classes or something?
py24-MySQLdb-1.2.0-1
mysql-client-4.0.24
mysql-server-4.0.24
Thanks!
cursor.insert_id() is obsolete; it was not removed from the documentation but will be in the next release.
The proper way to do this according to the standard (PEP-249) is to look at cursor.lastrowid.
http://www.python.org/peps/pep-0249.html
Thus, you should change your code to:
reportdict['id'] = cur.lastrowid
This is more portable, should you ever need to switch databases.
Thank you very much, Andy