所以我想我想通了。我敢肯定这不是最优雅的解决方案,但这里是:
我运行一个快速查询来检查 Joe 的 count() 以查看有多少记录,并且仅在需要时运行循环。我将最大值设置为 40,000 条记录:
var total_rows_query = "SELECT COUNT() FROM " + tableId + " WHERE 'User' = " + username;
var total_rows = FusionTables.Query.sql(total_rows_query,{hdrs : false}).rows[0][0];
如果总行数大于我想要的,我使用 OFFSET 和 LIMIT 参数来构造查询:
max_rows = 40000;
if(total_rows > max_rows){
var counter = 0;
//adding in a zero to the ranges since the last query will be the offset of 0, meaning all of them
var ranges = [0]
while(counter + chunk_size < total_rows){
counter = counter + chunk_size;
ranges.push(counter)
}
ranges.push(total_rows)
//Now ranges is an array with zero at the beginning, and counting up by the chunk size I want, ending with the total_rows for the user as the last oen
//This is the array that will be output after concating
var output = []
//looping through the array, setting the offset to the first item, and the limit to the next item minus the first
for(i=0;i<ranges.length-1;i++){
var offset = ranges[i]
var limit = ranges[i+1] - offset
var query = "SELECT * FROM " + tableId + " WHERE 'User' = '" + username + "' OFFSET " + offset + " LIMIT " + limit;
output = output.concat(FusionTables.Query.sql(query,{hdrs : false}).rows)
}
}else{
//if the count is less or equal to the chunk size, just run the one query
var query = "SELECT * FROM " + tableId + " WHERE 'User' = " + username;
var output = FusionTables.Query.sql(query,{hdrs : false}).rows
}
最后要注意的是,如果用户名是两个词,例如“John Smith”,您可能需要在用户名周围添加引号,所以不要使用
var total_rows_query = "SELECT COUNT() FROM " + tableId + " WHERE 'User' = " + username;
应该是:
var total_rows_query = "SELECT COUNT() FROM " + tableId + " WHERE 'User' = '" + username + "'";
我花了最后两天试图解决这个问题,所以我希望它可以帮助那里的人!