Google app engine 光标不工作的GQLQuery
想知道是否有人知道为什么在GQLQuery中使用游标似乎不能正常工作 我正在运行以下程序Google app engine 光标不工作的GQLQuery,google-app-engine,google-cloud-datastore,gql,gqlquery,Google App Engine,Google Cloud Datastore,Gql,Gqlquery,想知道是否有人知道为什么在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: data
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个结果,我假设您需要所有结果,但每次都要以100个为一批处理 下面是我将要做的(基于您的示例代码):
如果查询将自身限制为100,为什么dataLookup.count()会返回350?计数仍然可以返回查询的总大小。当您提取时,检索到的结果数组是100。谢谢谢谢,就这样!稍微修改一下代码,当调用fetch时,它返回一个数组,因此需要从初始GqlQuery中检索游标。再次感谢您的及时回复!
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)