2011-09-19 5 views
0

커서의 개념을 이해하고 http://code.google.com/appengine/docs/python/datastore/queryclass.html을 기반으로 한 쿼리를 이해했다고 생각했지만 분명히 코드에서 수행중인 작업을 기반으로하지 않았습니다.with_cursor와 queries를 이해하는 데 도움이 있습니다.

내 데이터 저장소에서 310 개 항목이 내가 100의 작은 배치 크기로 그들을 반복 할 :

나는 100의 일괄 내 모든 법인을 반복 할 수있는 방법
query = Event.all() 
query.order("__key__") 

batch_size = 100; 

# expecting this to return the 1st 100 of the 310 items  
results = query.fetch(limit=batch_size) 

logging.info("count 1: %d, results: %d" % (query.count(), len(results))) 
# reports: count 1: 310, results: 100 

for item in results: 
    print item # this will print items 1-100, which is expected 

# Move to the next batch block 
cursor = query.cursor(); 
query.with_cursor(cursor);    

results = query.fetch(limit=batch_size) 
logging.info("count 2: %d, results: %d" % (query.count(), len(results))) 
# reports: count 2: 0, results: 0 
# but was expecting to move to item 101 

? 'query.cursor()'은 첫 번째 batch_size의 끝 또는 해당 블록의 시작 부분에있는 커서를 반환합니까?

+1

'.count()'가 커서를 엉망으로 만들고 있다고 생각합니다. '.count()'를 호출하기 전에 커서를 가져 오십시오. (그리고 닉 존슨이 나를 괴롭히지 않도록하기 위해서는 아마도 count()를 사용하고 싶지 않을 것이라고 지적해야한다. – geoffspear

+0

나는 count 대신에 len (results)을 사용하여 전체 데이터 세트의 끝을 알린다. –

+0

나는 예측할 수 있습니까? –

답변

2

.count()은 실제로 당신을 싫어합니다. 이유를 확인하려면 두 번째 동일한 쿼리를 만들고 저장된 커서를 적용한 다음 어떻게되는지 확인하십시오.

덧붙여 는 암시 적입니다.

관련 문제