GQLQuery with_cursor 不起作用

发布于 2024-10-06 08:04:18 字数 702 浏览 0 评论 0原文

想知道是否有人知道为什么在 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

感谢您的帮助。

wondering if anyone knows why using cursors with GQLQuery doesn't seem to be working properly.

I'm running the following.

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

Thanks for all your help.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

溺孤伤于心 2024-10-13 08:04:18

您不应该在查询中使用 LIMIT,因为这只会返回前 100 个结果,我假设您需要所有结果,但每次会以 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) 

You should not use a LIMIT in your query, as that will only return the first 100 results, and I assume you want all of them, but process them in batches of 100 each time.

Here's what I would do (based on your example code):

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