English 中文(简体)
synchronizing executeSql in Safari (WebKit) Web Sql database
原标题:

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.

问题回答

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

Seems that nbody answers this. My current undertanding is that storing a block in localstorage is the best

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.





相关问题
CSS working only in Firefox

I am trying to create a search text-field like on the Apple website. The HTML looks like this: <div class="frm-search"> <div> <input class="btn" type="image" src="http://www....

image changed but appears the same in browser

I m writing a php script to crop an image. The script overwrites the old image with the new one, but when I reload the page (which is supposed to pickup the new image) I still see the old one. ...

Firefox background image horizontal centering oddity

I am building some basic HTML code for a CMS. One of the page-related options in the CMS is "background image" and "stretch page width / height to background image width / height." so that with large ...

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!

热门标签