GQLQuery 检索空结果集

发布于 2024-12-14 03:08:35 字数 951 浏览 5 评论 0原文

我正在运行 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

时光无声 2024-12-21 03:08:35

这可能是因为您在字段上使用了 TextPropertyTextProperty 适用于多行文本且未建立索引。您无法在查询中查找非索引值。您应该将 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 use StringProperty for single-line text values.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文