سؤال

أتساءل عما إذا كان أي شخص يعرف لماذا يبدو أن استخدام المؤشرات مع 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

شكرا لجميع التعليمات الخاصة بك.

هل كانت مفيدة؟

المحلول

يجب ألا تستخدم حد في استعلامك ، لأن ذلك سيعيد فقط 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) 
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top