cursor._last_executed

Help
Anonymous
2012-04-30
2012-09-19
  • Anonymous - 2012-04-30

    I am working on a django app, and it's blowing up in this in

    django/db/backends/mysql/base.py:

    def last_executed_query(self, cursor, sql, params):

    With MySQLdb, cursor objects have an (undocumented) "_last_executed"

    attribute where the exact query sent to the database is saved.

    See MySQLdb/cursors.py in the source distribution.

    return cursor._last_executed

    with 'Cursor' object has no attribute '_last_executed'

    Sure enough, it does not:

    $ python

    Python 2.6.7 (r267:88850, Jan 11 2012, 06:42:34)

    on darwin

    Type "help", "copyright", "credits" or "license" for more information.

    import MySQLdb

    conn = MySQLdb.connect(host, user, passwd, db)

    cursor = conn.cursor()

    print cursor._last_executed

    Traceback (most recent call last):

    File "<stdin>", line 1, in <module>

    AttributeError: 'Cursor' object has no attribute '_last_executed'

    print cursor.dict

    {'_result': None, 'description': None, 'rownumber': None, 'messages':

    , '_executed': None, 'errorhandler': <bound method

    Connection.defaulterrorhandler of <_mysql.connection open to

    'localhost' at 889810>>, 'rowcount': -1, 'connection': <weakproxy at

    0x62f630 to Connection at 0x889810>, 'description_flags': None,

    'arraysize': 1, '_info': None, 'lastrowid': None, '_warnings': 0}

    Anyone know anything about this undocumented (and nonexistent) attribute?

    I've asked on the django list, but have not received any replies.

     
  • Andy Dustman

    Andy Dustman - 2012-04-30

    Well... you haven't executed a query, now have you? Arguably though it should
    be initialized to None.

     
  • Anonymous - 2012-04-30

    Ok, in my test, after I execute a query it is set. But in my django app I am
    doing this:

    from django.db import connection

    cursor = connection.cursor()

    cursor.execute(sql)

    and it's getting the no attribute error.

    So I guess this means that the sql isn't getting executed for some reason.
    I'll have to investigate that avenue.

     

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks