Google App Engine里面的select count(*)

因为GAE规定了返回的条数不能超过1000条,所以只能分两种做法:

当记录的条数小于1000的时候:
PersistenceManager pm = getPersistenceManager(); 
Query query = pm.newQuery(Chapter.class); 
query.setResult("count(this)"); 
int count = 0; 
try { 
  count = (Integer) query.execute(); 
} finally { 
  pm.close(); 
} 


当记录的条数大于1000的时候:
最有效的方法是新建一个表,一个counter字段来记录总记录数目。(原话:the most efficient solution would be incrementing a
counter with every write and just reading this value when it's needed)

你可能感兴趣的:(Google,GAE)