python - GQLQuery 检索空结果集

标签 python google-app-engine google-cloud-datastore

我正在运行 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”子句,我会获得数据库的所有用户,所以我猜数据库连接没问题。

最佳答案

这可能是因为您在字段上使用了 TextPropertyTextProperty 适用于多行文本且未建立索引。您无法在查询中查找非索引值。您应该将 StringProperty 用于单行文本值。

关于python - GQLQuery 检索空结果集,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8037130/

相关文章:

python-2.7 - apache beam 2.7.0 在 utf-8 编码法语字符中崩溃

node.js - 我可以浏览 node.js 项目的本地 Google Datastore 模拟器数据吗?

python - 包含 2 个元素的列表到 csv

python - 如何在 Google App Engine 中获取最后插入的项目 key

python - 匹配数字时,我似乎没有在 python 的正则表达式中得到正确的结果

php - 如何构建 app.yaml 文件?

java - Appengine java.lang.IllegalAccessError 与 ArrayElementNodeProperty

google-app-engine - 如何解决 "no matching index found."错误

javascript - 在 React Native 上使用 Ajax

python - 如何使用索引找到整个二维数组中的最大值