查询结果过大导致手机推出:从数据库A查询到两万条结果(a),在传到函数funB插入数据库B的过程中程序卡死了,解决办法是循环读取a(每次读取一千条)传到数据库B里。
tx.executesql(sql1,sql11,function(tx,res) { console.log("获得【CIM_LotImgStruc】的记录: " + res.rows.length + "条记录。"); var result = new Array(); var rowsleng = res.rows.length;//数据长度 console.log("rowsleng: " + rowsleng); var r = /^[0-9]*[1-9][0-9]*$/ //正整数 var intK = parseInt(rowsleng/1000); var resultNum; inserNum=0; updateNum=0; deleNum=0; nullNum=0; allNum = rowsleng; for (var i = 0; i < rowsleng; i++) { //result[i] = res.rows.item(i); var intI = i/1000; //console.log("i: " + i +"---------------"); resultNum = 0; if(r.test(intI)){ //console.log("i---: "+i); //sleep(1000); result = new Array(); for(h = (i-1000); h<i; h++){ console.log("h---: "+h); result[resultNum] = res.rows.item(h); //console.log("result["+resultNum+"]---: "+JSON.stringify(result[resultNum])); resultNum++; } sqliteTool.insertStruc(db,result); } resultNum = 0; if(intI==intK){ result = new Array(); for(j = i; j<rowsleng+1; j++){ console.log("j---: "+j); console.log("resultNum---: "+resultNum); result[resultNum] = res.rows.item(j); //console.log("result["+resultNum+"]---: "+JSON.stringify(result[resultNum])); resultNum++; } //console.log("result["+resultNum+"]---: "+JSON.stringify(result[resultNum])); callback(result); } } },function(e) { console.log("ERROR: " + e.message); });原文链接:https://www.f2er.com/sqlite/199906.html