来自GoogleAppEngine的GqlQuery返回空列表

时间:2011-09-19 14:19:09

标签: python google-app-engine google-cloud-datastore gql gqlquery

这是我的问题:

currentID = 7
deck = range(0,3)
similarIDs = db.GqlQuery('SELECT * FROM itemSet WHERE jokeID=:1 AND position IN :2', currentID, deck[:3]).fetch(100)

这是我的模特:

class itemSet(db.Model):
jokeID = db.IntegerProperty()
jokeID2 = db.IntegerProperty()
position = db.IntegerProperty()

当我在GoogleAppEngine数据查看器中执行查询时,我得到了结果: enter image description here

我错过了什么?

1 个答案:

答案 0 :(得分:1)

以下带有GqlQuery语句的代码适用于我。

    item = itemSet()
    item.jokeID = 7
    item.jokeID2 = 1
    item.position = 0
    item.put()
    item = itemSet()
    item.jokeID = 7
    item.jokeID2 = 2
    item.position = 1
    item.put()

    currentID = 7
    deck = range(0,3)
    similarIDs = db.GqlQuery('SELECT * FROM itemSet \
                             WHERE jokeID=:1 AND position IN :2'
                             , currentID, deck[:3]).fetch(100)
    for item in similarIDs:
        logging.info("%s : %s" % (item.jokeID, item.position))

它返回:

INFO     2011-09-19 18:46:28,299 main.py:47] 7 : 0
INFO     2011-09-19 18:46:28,299 main.py:47] 7 : 1