HTML5 Web SQL DB - 最大表大小? [英] HTML5 Web SQL DB - Maximum table size?

查看:331
本文介绍了HTML5 Web SQL DB - 最大表大小?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我参与构建了一个相当复杂的HTML5 Web应用程序,它从Web服务中检索其数据以填充Web SQL数据库。



以及测试数据,然后我尝试使用一些真实数据(大约10列和超过180,000行的表),并遇到一些问题。



我正在发送在500个插入的块中执行SQL响应,然后运行一个事务并从Web服务中获取下一个响应。这工作正常,直到表达到约9000行,然后它不再需要。此时数据库文件的大小仍然在2MB以下,我的最大大小设置为20MB,所以我不认为这是问题。



我已经管理用更简单的代码重新创建类似的问题,以便其他人可以看到我在说什么。 (出于某种原因,我无法把它全部留在代码块(对不起))

  // var qsParm = new Array(); 

var bigData = {};
bigData.webdb = {};

var readOnly = false;

bigData.webdb.open = function(){
bigData.webdb.db = null;
var dbSize = 20 * 1024 * 1024; // 20MB
infinity.webdb.db = openDatabase('bigData','','bigData DATA',dbSize);
};

bigData.webdb.onError = function(tx,e){
alert('Something unexpected happened:'+ e.message);
};


bigData.webdb.createTable = function(){
var db = bigData.webdb.db;
db.transaction(函数(tx){
tx.executeSql(CREATE TABLE IF NOT EXISTS [MattTest]([Foo] VARCHAR(32)PRIMARY KEY ASC,[Bar] VARCHAR(20), [Will] VARCHAR(100),[Smith] VARCHAR(100)),[]);

});

db.transaction(function(tx){
var i = 0;
for(i = 0; i <19000; i ++)

tx.executeSql(INSERT INTO [MattTest](Foo,Bar,Will,Smith)VALUES(?,?,?,?),['Foo'+ i,'Bar','现在这个故事全是关于我的生活如何翻转颠倒','我喜欢花一分钟就坐在那里告诉你我是如何成为一个名叫贝莱尔的小镇的王子'的)];
}

});
};

请忽略字符串值,它只是填充varchar大小(SQLite没有出现填充字符类型)。



在上面(或下面的任何数字)的19000迭代中,表格将在Chrome中创建,所有数据都正确输入。数据库将在4MB左右。 Safari会让我添加更多的行,并且我在Safari中拥有大约10MB的数据库大小。



如果我尝试删除表格的内容并增加数字至于20,000次迭代,Chrome并没有完成交易。



有人对此有何看法?



我希望我已经详细解释了这个问题。请随时提出任何问题,如果我过于模糊。



感谢您的帮助。



更新:我已经尝试添加一些错误处理,并且响应是约束失败。我已经对可能造成这种情况的一些研究做了一些研究,但我仍然在努力寻找答案。 解决方案

我认为你正在使用硬编码的5MB WebSQL数据库大小的Chrome浏览器。我可以验证你的代码是否如你所描述的那样失败,就像数据库大小在最新的Chrome浏览器v8.0.552.215上通过5120K一样。



错误消息表明允许内存已被超过,等等。据我所知,Chrome不使用WebSQL数据库大小参数。



有关此



约束错误可能是一个单独的问题,因为您可以通过尝试INSERT来引发这样的错误重复的记录。只需多次运行插入示例代码而不调整迭代初始化和边界参数可能导致此问题。

I'm part way through building a fairly complex HTML5 web app, that retrieves its data from a Web Service to populate the Web SQL databse.

All was going well with the test data, then I tried using some real data (a table with around 10 cols and over 180,000 rows) and ran into some issues.

I am sending the SQL responses in "chunks" of 500 inserts and then running a transaction and grabbing the next response from the Web Service. This works fine, until the table gets to around 9000 rows and then it just won't take any more. At this point the database file size is still under 2MB and I have the max size set to 20MB, so I don't think that is the issue.

I have managed to recreate a similar issue with simpler code, so others can see what I am talking about. (For some reason I can't get it all to stay in the "code block" (sorry))

//var qsParm = new Array();

var bigData = {};
bigData.webdb = {};

var readOnly = false;

bigData.webdb.open = function() {
    bigData.webdb.db = null;
    var dbSize = 20 * 1024 * 1024; // 20MB
    infinity.webdb.db = openDatabase('bigData', '', 'bigData DATA', dbSize);   
};

bigData.webdb.onError = function(tx, e) {
    alert('Something unexpected happened: ' + e.message);
};


bigData.webdb.createTable = function() {
    var db = bigData.webdb.db;
    db.transaction(function(tx) {        
        tx.executeSql("CREATE TABLE IF NOT EXISTS [MattTest] ([Foo] VARCHAR(32) PRIMARY KEY ASC, [Bar] VARCHAR(20), [Will] VARCHAR(100), [Smith] VARCHAR(100))", []);

    });

    db.transaction(function(tx) {
        var i=0;
        for(i=0; i<19000; i++)

            tx.executeSql("INSERT INTO [MattTest] (Foo, Bar, Will, Smith) VALUES (?,?,?,?)", ['Foo' + i, 'Bar', 'Now this is the story all about how My life got flipped turned upside down', 'And Id like to take a minute just sit right there Ill tell you how I became the prince of a town called Bel Air']);
        }

    });
};

Please ignore the string value, its just something to pad out the varchar size (SQLite doesn't appear to pad a char type).

At the "19000" iterations above (or any number below) the table will be created in Chrome, with all of the data entered correctly. The database will be around 4MB. Safari will let me add more rows and I have had the DB size up to around 10MB in Safari.

If I try to delete the contents of the table and increase the number of iterations to 20,000, Chrome does not finish the transaction.

Does anyone have any ideas as to what might be causing this?

I hope I have explained the issue in enough detail. Please feel free to ask any questions, if I have been too vague.

Thanks for your help.

Update: I have tried adding some error handling and the response is "constraint failed". I've done a bit of research into what may be causing this, but I'm still struggling to find an answer.

解决方案

I think you are hitting a hard-coded 5MB WebSQL DB size limit of Chrome. I can verify your code failing as you describe, just as the db size busts through 5120K on (the latest) Chrome v8.0.552.215

The error message indicates that allowed memory has been exceeded, etc. As far as I know Chrome does not utilize the WebSQL DB size params.

More discussion about this on the Chromium group

The constraint error may be a separate issue as you can elicit such an error by attempting to INSERT a duplicate record. Simply running your insert sample code more than once without tweaking the iteration init and bounds params can cause this.

这篇关于HTML5 Web SQL DB - 最大表大小?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆