gqlquery with_cursor不起作用
-
30-09-2019 - |
题
想知道是否有人知道为什么将光标与Gqlquery一起使用似乎无法正常工作。
我正在运行以下内容。
query = "SELECT * FROM myTable WHERE accountId = 'agdwMnBtZXNochALEglTTkFjY291bnQYpQEM' and lastUpdated > DATETIME('0001-01-01 00:00:00') ORDER BY lastUpdated ASC LIMIT 100"
if lastCursor:
dataLookup = GqlQuery(query).with_cursor(lastCursor)
else
dataLookup = GqlQuery(query)
//dataLookup.count() here returns some value like 350
for dataItem in dataLookup:
... do processing ...
myCursor = dataLookup.cursor()
dataLookup2 = GqlQuery(query).with_cursor(myCursor)
//dataLookup2.count() now returns 0, even though previously it indicates many more batches can be returned
感谢你的帮助。
解决方案
您不应在查询中使用限制,因为这只会返回前100个结果,我认为您想要所有结果,而是每次分批处理它们。
这是我要做的(基于您的示例代码):
query = GqlQuery("SELECT * FROM myTable WHERE accountId =
'agdwMnBtZXNochALEglTTkFjY291bnQYpQEM' and
lastUpdated > DATETIME('0001-01-01 00:00:00') ORDER BY lastUpdated ASC")
dataLookup = query.fetch(100) # get first 100 results
for dataItem in dataLookup:
# do processing
myCursor = query.cursor() # returns last entry of previous fetch
if myCursor:
# get next 100 results
dataLookup2 = query.with_cursor(myCursor).fetch(100)
不隶属于 StackOverflow