2010-12-02 284 views
0

想知道是否有人知道爲什麼在GQLQuery中使用遊標似乎沒有正常工作。GQLQuery with_cursor not working

我正在運行以下內容。

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 

感謝您的幫助。

+0

爲什麼會dataLookup.count()返回350,如果您的查詢限制本身到100? – 2010-12-02 14:07:26

+0

計數仍可以返回總查詢大小。當您執行提取操作時,檢索結果數組爲100.謝謝! – savagepanda 2010-12-02 15:11:08

回答

2

你不應該在你的查詢中使用LIMIT,因爲這隻會返回前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)