sql.js报错
最近在d3.js画图的程序,用SQL.js来读本地数据库文件,遇到的问题是:
加载了数据库后可以查询成功几次 然后再查就会报错
Cannot enlarge memory arrays. Either (1) compile with -s TOTAL_MEMORY=X with X higher than the current value 16777216, (2) compile with ALLOW_MEMORY_GROWTH which adjusts the size at runtime but prevents some optimizations, or (3) set Module.TOTAL_MEMORY before the program runs.
使用sql.js读数据库的代码如下
var dbFileElm = document.getElementById('newFile');
var rr = new FileReader();
dbFileElm.onchange = function() {
var f = dbFileElm.files[0];
var r = new FileReader();
r.onload = function() {
rr=r;
};
r.readAsArrayBuffer(f);
};
function selectData(sql) {
var Uints = new Uint8Array(rr.result);
var db = new SQL.Database(Uints);
var contents= db.exec(sql);
Uints=null;
db=null;
return contents
}
调用代码如下
var contents = selectData(sql);