On Nov 5, 2010, at 1:04 PM, Lenza McElrath wrote:

> This is happening using MySQLdb 1.2.2 and MySQL server 5.0.87.  Upgrading is 
> not really a viable option.

Wasn't asking you to upgrade.  Only to try a different version of the software 
in an attempt to isolate the issue.


> 
> I guess  you expect cursor.rowcount to be the number of matched rows, not the 
> number of changed rows?  Where is the documentation that says this is what it 
> should be?  Obviously no rows are being updated since you are setting 
> float_value to the exact same value:

That's not how "updated rowcount" usually works.   The standard meaning of 
"rowcount" is how many rows *matched* the update statement, not how many were 
actually modified.  MySQL in fact has two different modes for "rowcount", and 
it usually defaults to the latter, however its very possible that different 
default behaviors across MySQL/MySQLdb versions is why your test works for me 
and not for you.

SQLAlchemy sets this on the MySQLdb DBAPI using the CLIENT_FLAGS.FOUND_ROWS 
bitmask so that it uses the former.   

For some reason, whenI use your test verbatim, the FOUND ROWS behavior works 
consistently with the behavior that SQLA usually sets up, even though your test 
isn't actually configuring it correctly.   This is why some differing of 
default behavior is suggested.

so do this:

    from MySQLdb.constants import CLIENT as CLIENT_FLAGS
    client_flag = CLIENT_FLAGS.FOUND_ROWS

    conn_getter = lambda: MySQLdb.connect(db='test', user='scott', 
host='localhost', passwd='tiger', client_flag=client_flag)

> 
> I have updated the test to use an integer test value and to show what 
> cursor.rowcount is for the query: http://pastebin.com/SR6N4UhL
> 
> The works because SQLAlchemy realizes that the value has not changed so does 
> not even attempt an update.  Here is the relevant output:

but that's not a "fix".    There are other scenarios where an UPDATE statement 
may be emitted redundantly, such as if you set the value of an attribute that 
was expired.  SQLA in the simple case chooses not to expensively load the "old" 
value of an attribute when a change event is received, if the previous value 
wasn't present.  You'd get the same issue in that case.

-- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to sqlalch...@googlegroups.com.
To unsubscribe from this group, send email to 
sqlalchemy+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.

Reply via email to