我正在运行 GQLQuery 来查找用户是否输入了正确的凭据:
class User(db.Model):
UserName = db.TextProperty();
Password = db.TextProperty();
Ticket = db.TextProperty();
class Authentication(webapp.RequestHandler):
def post(self):
str_user = self.request.get('user')
str_password = self.request.get('password')
user = db.GqlQuery("SELECT * FROM User WHERE UserName = :1 AND Password = :2",str_user, str_password)
self.response.out.write(str_user)
self.response.out.write(str_password)
self.response.out.write(str([u.UserName for u in user]))
if user.count() > 0:
ticket = str(uuid.uuid4())
user.Ticket = ticket
self.response.out.write(ticket)
else:
self.response.out.write('Not authorized!')
尽管我确信我已经传递了正确的参数,但查询始终返回空结果集(带有“WHERE”子句)。
我尝试连接我自己的查询字符串,但结果保持不变。如果我删除“WHERE”子句,我会获得数据库的所有用户,所以我猜数据库连接没问题。
最佳答案
这可能是因为您在字段上使用了 TextProperty
。 TextProperty
适用于多行文本且未建立索引。您无法在查询中查找非索引值。您应该将 StringProperty
用于单行文本值。
关于python - GQLQuery 检索空结果集,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8037130/