GqlQuery with_cursor no funciona
-
30-09-2019 - |
Pregunta
pregunto si alguien sabe por qué utilizar cursores con GqlQuery no parece estar funcionando correctamente.
estoy ejecutando el siguiente.
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
Gracias por toda su ayuda.
Solución
No se debe utilizar un límite en la consulta, como que sólo devolverá los 100 primeros resultados, y supongo que desea todos ellos, pero ellos procesar en lotes de 100 cada vez.
Esto es lo que yo haría (basado en el código de ejemplo):
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)
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow