GQLQuery with_cursor non funziona
-
30-09-2019 - |
Domanda
chiedo se qualcuno sa perché utilizzando i cursori con GQLQuery non sembra funzionare correttamente.
Io corro il seguente.
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
Grazie per tutto il vostro aiuto.
Soluzione
Non dovrebbe usare un limite nella tua ricerca, come che restituire solo i primi 100 risultati, e presumo si desidera che tutti loro, ma vengono trattate in lotti di 100 ogni volta.
Ecco quello che vorrei fare (in base al codice di esempio):
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)
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow