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.