简体   繁体   English

试图使用python检查sqlite数据库中是否存在用户名

[英]trying to check if username exists in sqlite database using python

Trying to check if the username is exists in sqlite using python 3 尝试使用python 3检查用户名是否在sqlite中存在

This is what i've tried 这就是我尝试过的

    checkUsername = self.c.execute("SELECT username FROM Login WHERE username = ? AND position = ?",
                   (username, manager))

    if checkUsername != 0:
        print("Wrong username and password")
    else:
        print("correct")

If you're using the sqlite3 module, cursor.execute doesn't return the results. 如果使用sqlite3模块,cursor.execute不会返回结果。 You need to use cursor.fetchone() or cursor.fetchall() to get the results, which come back as a tuple or list of tuples. 您需要使用cursor.fetchone()或cursor.fetchall()来获取结果,这些结果以元组或元组列表的形式返回。

Check the documentation here for some more details. 有关更多详细信息,请参见此处的文档。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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