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
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With