I have a sql statement that returns no hits. For example, \'select * from TAB where 1 = 2\'
.
I want to check how many rows are returned,
cu
MySQLdb will not raise an exception if the result set is empty. Additionally cursor.execute() function will return a long value which is number of rows in the fetched result set. So if you want to check for empty results, your code can be re-written as
rows_count = cursor.execute(query_sql)
if rows_count > 0:
rs = cursor.fetchall()
else:
// handle empty result set