[DB-SIG] return value of .fetchall() with an empty result set
Mon, 22 Apr 2002 15:02:19 -0500
I need a clarification on the use of .fetchall(). Which of the below
scenarios is correct?
c.execute("select * from some_table where 1=0")
data = c.fetchall()
(1) raises an Error
(2) data == 
(3) data is None
Under some cases I can not know the number of rows returned in the query
so the user must try one of the fetchXXX methods. I currently implement
zxJDBC as (3) which is probably the most incorrect. I *think* it should
probably return (2) to be more consistent with .fetchmany(). (1) seems
rather harsh to me as this is not really an exceptional case, there's
just no data. Either way it appears I'm not consistent with the API.
How have others implemented this? Is everyone else raising an Error?
Is the preferred method to check the .rowcount attribute and only call
.fetchXXX if it's greater than zero?