[newbie] MySQL : How to check if no row returned?

Jane Doe jane.doe at acme.com
Thu Jul 24 15:00:43 EDT 2003


Hi

(newbie, please don't flame, thank you :-))

I browsed through the archives of this site, but I didn't see how to
check if a SELECT through the MySql module returns an empty set
(whether a row exists or not, the "else" part below is always called).

Here's what I tried (using the CherryPy framework):

CherryClass MyDb2(MySql):
function:
    def __init__(self):
        self.openConnection('localhost', 'root', 'test', 'mydb')

[...]

# txtClient is returned by an HTML form
myarray = myDb2.query("select * from clients where name='" +
kw['txtClient'] + "'")

# Never empty!!!
if myarray == None:
	res+="<td>No client found.</td>"
else:
	res+=self.myview(myarray)

Any tip much appreciated

Thank you
JD.




More information about the Python-list mailing list