Menu

DictCursor object has no attribute insert_id

Help
2005-03-29
2012-09-19
  • EverCurious

    EverCurious - 2005-03-29

    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!

     
    • Andy Dustman

      Andy Dustman - 2005-03-29

      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.

       
    • EverCurious

      EverCurious - 2005-03-29

      Thank you very much, Andy

       

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.