[英]Parsing the return of SQLite Query in Python
我在 Flask (Python) web 应用程序中有一个 SQLite 数据库,这是我的代码,用于查看 Z0C83F57C2AB 是否已经注册7836AB78360 如果存在与否,它分别返回 boolean(1 或 0)。
exists = db.execute("SELECT EXISTS(SELECT 1 FROM people WHERE email in (?))", (email@domain.com))
print(exists[0])
print(exists)
返回的地方:
[{"EXISTS(SELECT 1 FROM people WHERE email in ('email@domain.com'))": 1}]
简而言之,我得到了所需的结果(使用未注册和注册的电子邮件进行测试),但我不知道如何访问这个值 1 或 0。
非常感谢任何想法。
尝试为 select 查询的存在部分起别名
exists = db.execute("SELECT EXISTS(SELECT 1 FROM people WHERE email in (?)) as email_exists", (email@domain.com))
print(exists[0])
那么您应该能够通过exists[0]['email_exists']
访问该值。 这将为您提供1
或0
,您接下来可以将其转换为bool
。
exists = db.execute("SELECT EXISTS(SELECT 1 FROM people WHERE email in (?)) as email_exists", (email@domain.com))
print(bool(exists[0]['email_exists']))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.