patch mysql driver rowcounting strategy

Issue #396 resolved
Former user created an issue

The default MySQL rowcounting strategy returns only a count of rows that changed, not those that matched a WHERE clause. This breaks version_id_col among other things.

This behavior is configurable at connect() time; attached is a patch to allow MySQLDialect.supports_sane_rowcount() to return True.

Comments (5)

  1. Mike Bayer repo owner

    thanks very much for this patch. its committed in changeset:2159.

    however, I realized that the current unittest isnt testing the condition anyway, since its issuing UPDATEs that do modify the row. so i have yet to create a test that confirms the correct behavior of mysql rowcount (going on faith for now).

    also, i removed the change you had in do_executemany() (cursor.rowcount = cursor.executemany()) since I dont understand it; we get the rowcount by calling cursor.rowcount, not using the return value of executemany(). According to pep249, the return value of execute()/executemany() is undefined. Additionally, the cursor.rowcount value is typically incorrect for executemany() calls, such as in postgres where I unfortunately break the executemany into individual execute() calls so that i can get an accurate rowcount (i should probably look into optimizing that better). do we know the exact behavior for executemany with mysqldb ?

  2. jek

    I exercised the MySQLdb code directly; it did behave properly for updates and deletes. I could probably reshape the testing scripts into a unittest. Maybe even using sa's sql support.

    The behavior of rowcount and executemany() was similar to postgres- rowcount returns the total for the last statement executed. For statements that can roll up it's correct, for statements executed by iteration it is not.

    MySQLdb's executemany() returns the correct rowcount directly to the caller. The patch simply updates the cursor's rowcount property with the correct total. Various tests depended on rowcount being correct, e.g. in deleting a set of objects.

  3. Mike Bayer repo owner
    • removed status
    • changed status to open

    im running it here locally and i realized that its not working for me. many unittests fail now with MySQL reporting that the rowcounts are not correct. I also have the most recent version of MySQLDB and am using MySQL5. I need to roll these changes back for now; what versions of MySQLDB and MySQL are you using ?

  4. Mike Bayer repo owner

    Ok nevermind, i see the issue, MySQLdb has totally undocumented behavior that its executemany() method returns the total rowcount, and ive leveraged that in the latest checkin (changeset:2162) which also integrates your unit test (recreates the data for each test so they work together).

  5. Log in to comment