首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >GQLQuery with_cursor不工作

GQLQuery with_cursor不工作
EN

Stack Overflow用户
提问于 2010-12-02 21:48:00
回答 1查看 487关注 0票数 0

不知道是否有人知道为什么在GQLQuery中使用游标似乎不能正常工作。

我正在运行以下代码。

代码语言:javascript
复制
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

谢谢你的帮助。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2010-12-02 22:15:34

您不应该在查询中使用限制,因为这将只返回前100个结果,我假设您想要所有结果,但每次以100个为一批来处理它们。

下面是我要做的(基于你的示例代码):

代码语言:javascript
复制
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) 
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/4335677

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档