HTML5 Database / transaction ordering

View: New views
3 Messages — Rating Filter:   Alert me  

HTML5 Database / transaction ordering

by VictorM :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

As I understand, client database transactions are to be queued and executed sequentially in the order that they are called.
 
This is a useful fact for ordering transaction code without endless chaining of callbacks, for instance in the following example the steps will execute in order 1,2,3,4:

db.transaction(
 function(tx)
 {
  // step 1
  tx.executeSql('...',[],
   function(tx)
   {
    // step 2
   });
 });

db.transaction(
 function(tx)
 {
  // step 3
  tx.executeSql('...',[],
   function(tx)
   {
    // step 4
   });
 });

However, in the following case of nested transactions the execution is perhaps not ideal, running steps in the order 1,2,5,6,3,4:

db.transaction(
 function(tx)
 {
  // step 1
  tx.executeSql('...',[],
   function(tx)
   {
    // step 2
   });

  db.transaction(
  function(tx)
  {
   // step 3
   tx.executeSql('...',[],
    function(tx)
    {
     // step 4
    });
  });
 });

db.transaction(
 function(tx)
 {
  // step 5
  tx.executeSql('...',[],
   function(tx)
   {
    // step 6
   });
 });

For consideration, how about if transactions that are issued from inside other transactions could be queued immediately after, to reliably achieve order 1,2,3,4,5,6?

Thanks,
Victor


Re: HTML5 Database / transaction ordering

by cmate :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

I have the same issue, how can I execute database transactions synchronously so I can for example do an insert, make sure it worked before I continue my code, or execute a query and make sure I actually loaded a value before I continue my code??

Re: HTML5 Database / transaction ordering

by Ian Hickson :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


On Thu, 4 Dec 2008, cmate wrote:
>
> I have the same issue, how can I execute database transactions
> synchronously so I can for example do an insert, make sure it worked
> before I continue my code, or execute a query and make sure I actually
> loaded a value before I continue my code??

Put the continuation of your code in the statement's callback.

--
Ian Hickson               U+1047E                )\._.,--....,'``.    fL
http://ln.hixie.ch/       U+263A                /,   _.. \   _\  ;`._ ,.
Things that are impossible just take longer.   `._.-(,_..'--(,_..'`-.;.'