views:

626

answers:

1

Going off the documentation here: http://docs.djangoproject.com/en/dev/topics/db/sql/

>>>cursor = connection.cursor()
>>>cursor.execute("UPDATE bar SET foo = 1 WHERE baz = %s", [self.baz])
>>>print cursor.fetchone()
None

Does anyone know how to return the modified row count?

(NOTE: I've played around with the placement/order of transaction.commit_unless_managed() and cursor.fetchone() (also cursor.fetchall()) and it doesn't seem to make a difference)

Thanks! -Tom

+4  A: 

An UPDATE statement as you've got in your example doesn't return row results, so fetchone() will always be empty (or might throw an error).

Use cursor.rowcount to get the rows last affected.

Jarret Hardie