This read-only property returns True when the
result of the executed operation provides rows.
The with_rows property is useful when it is
necessary to determine whether a statement produces a result set
and you need to fetch rows. The following example retrieves the
rows returned by the SELECT
statement, but reports only the affected-rows value for the
UPDATE statement:
import mysql.connector
cnx = mysql.connector.connect(user='scott', database='test')
cursor = cnx.cursor()
operation = 'SELECT 1; UPDATE t1 SET c1 = 2; SELECT 2'
for result in cursor.execute(operation, multi=True):
if result.with_rows:
result.fetchall()
else:
print("Updated row(s): {}".format(result.rowcount))

User Comments
Add your own comment.