python sqlite3 怎么判断cursor的结果是否为空

len(list(cursor))若是0则为空

举例:

import sqlite3

# CREATE
 db = sqlite3.connect("E:/Pycharm/workspace/django_test/user.db")
 db.execute("create table user(info primary key,flag,result )")
 db.execute("insert into user(info,flag,result) values('RikkaTakanashi','0','DarkFlameMaster')")
 db.commit()
 db.close()
db = sqlite3.connect("E:/Pycharm/workspace/django_test/user.db")
c=db.cursor()
cursor=c.execute("select info,flag,result from user  where info='123'")
print(len(list(cursor)))

结果为0

db = sqlite3.connect("E:/Pycharm/workspace/django_test/user.db")
c=db.cursor()
cursor=c.execute("select info,flag,result from user  where info='RikkaTakanashi'")
print(len(list(cursor)))

结果为1

你可能感兴趣的:(数据库)