Documentation Home
MySQL Connector/Python Developer Guide
Related Documentation Download this Manual
PDF (US Ltr) - 0.7Mb
PDF (A4) - 0.7Mb


10.5.22 MySQLCursor.with_rows Property

Syntax:

boolean = cursor.with_rows

This read-only property returnsTrue orFalse to indicate whether the most recently executed operation could have produced rows.

Thewith_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 theSELECT statements, but reports only the affected-rows value for theUPDATE statement:

import mysql.connectorcnx = 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):  if result.with_rows:    result.fetchall()  else:    print("Number of affected rows: {}".format(result.rowcount))