简体   繁体   中英

Why is the returned value is none in this Python/MySQL search

I have this little code

cquery = "SELECT * FROM `workers` WHERE `Username` = (%s)"
cvalue = (usernameR,)
flash(cquery)
flash(cvalue)
x = c1.execute(cquery, cvalue)
flash(x)

usernameR is a string variable I got it's value from a form

x supposed to be the number of rows or some value but it returns none I need it's value for one if.

I tested it with a value that is in the table in one row so thats not the case the the value is not there or something. But if it's not there in that case the x should return 0 or something.

I cant work out what's the problem after several hours.

value of cvalue:

('Csabatron99',)

Edit for solution:

I needed to add the rowcount and fetchall to the code like this:

cquery = "SELECT * FROM `workers` WHERE `Username` = (%s)"
cvalue = (usernameR,)
flash(cquery)
flash(cvalue)
c1.execute(cquery, cvalue)
c1.fetchall()
a = c1.rowcount

cursor.execute() doesn't return anything in the normal case. If you use the multi=True argument, it returns an iterator used to get results from each of the multiple queries.

To get the number of rows returned by the query, use the rowcount attribute.

c1.execute(cquery, cvalue)
flash(c1.rowcount)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM