所以我想我想出来了。我敢肯定这不是最优雅的解决方案,但这里有:
我运行一个快速查询来检查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 + "'";
我花了最近两天试图解决这个问题,所以我希望它可以帮助那些人!