GQLQuery 检索空结果集
我正在运行 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”子句,我会获得数据库的所有用户,所以我猜数据库连接没问题。
I'm running a GQLQuery to lookup if a user entered the correct credentials:
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!')
The query always return an empty result set (with the "WHERE"-clause) although I'm sure that I've passed the correct parameters.
I've tried to concat my own query string but the result remains the same. If I remove the "WHERE"-clause i get all the users of the db, so I guess the db-connection is okay.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这可能是因为您在字段上使用了
TextProperty
。TextProperty
适用于多行文本且未建立索引。您无法在查询中查找非索引值。您应该将StringProperty
用于单行文本值。This is probably because you use
TextProperty
on your fields.TextProperty
is for multi-line texts and is not indexed. You can't lookup for non-indexed values in query. You should useStringProperty
for single-line text values.