我有一个问题,我正在尝试通过在python和SQLite中对rowid进行比较来对用户名电子邮件的用户名进行验证,这里是代码:
username = self.txtUsername.GetValue()
email = self.txtEmail.GetValue()
UsernameE = self.conn.execute("SELECT rowid,* FROM tblPlayers WHERE p_Username="
+ username)
EmailU = self.conn.execute("SELECT rowid,* FROM tblPlayers WHERE p_Email=" + email)
错误是:
> UsernameE = self.conn.execute("SELECT rowid,* FROM tblPlayers WHERE p_Username="
+ username)
sqlite3.OperationalError: no such column: "what i inserted in the username"
答案 0 :(得分:1)
您的SQL格式不正确,因为您不会在用户名值后关闭引号。但是你不应该这样做:你应该使用参数:
self.conn.execute("SELECT rowid,* FROM tblPlayers WHERE p_Username=? ", (username,))
另请注意,执行操作不会返回值:您需要获取它,例如使用fetchone()
。
答案 1 :(得分:0)
尝试在用户名中添加引号:
UsernameE = self.conn.execute("SELECT rowid,* FROM tblPlayers WHERE p_Username = '" + username + "'")