Reputation: 1905
WebKit (Safari 4+ is my focus) has a feature called Web SQL. Web SQL is specified in the W3C draft. Currently only the asynchronous flavor is supported.
I have a situation where I want to synchronize a few different operations - writing to database (using CREATE TABLE query and then a loop through INSERT queries) and then reading from the database. How do I do this? I googled and read a lot of tutorials, but did not find any explanation of that.
If I can't find answer to this, I shall try the Worker feature and if unsuccessful I plan to store the data in webstorage (localstorage) instead.
Upvotes: 1
Views: 1126
Reputation: 22963
You chain the operations through success callbacks. That way you can be sure of the order of operations. See the example code available in this article.
You can use the callbacks available for the transaction object or the individual queries, tx.executeSql(sql, [], callback, errorCallback)
.
var sql_createTables = "CREATE .....",
sql_inserts= "INSERT .....";
function errorHandler(tx, error) {
//do error handling
}
db.transaction(
function(tx){
tx.executeSql(sql_createTables,[], function(tx, result){
//The table was created
tx.executeSql(sql_inserts,[], function(tx, result){
// Inserts completed
});
},
errorHandler);
}, function(error) { alert("Oh, noes! The whole transaction failed!"); },
function() { alert("Yeah, baby! We did it."); });
WebWorker has nothing to do with this, and will not help you in any way, as a WebWorker
has no access to the DOM, of which localStorage
and WebSql
are parts.
Upvotes: 0
Reputation: 11
I have written a possible solution for this in my blog. Don't know if that would fit your problem, but have a look. http://wander-mind.blogspot.com/2011/03/how-to-synchronize-html5-websql-with.html
Upvotes: 1
Reputation: 1905
Seems that nbody answers this. My current undertanding is that storing a block in localstorage is the best
Upvotes: 0