[whatwg] SQL API and Transactions

Ian Hickson ian at hixie.ch
Wed Oct 31 17:20:57 PDT 2007


On Wed, 31 Oct 2007, Scott Hess wrote:
> On Oct 26, 2007 3:51 PM, Ian Hickson <ian at hixie.ch> wrote:
> > On Thu, 25 Oct 2007, Brady Eidson wrote:
> > >
> > > Step 9 of the transaction steps stipulates that if the transaction 
> > > fails to commit, the script will get an SQLTransactionErrorCallback 
> > > indicating this failure.  However, there is no final callback 
> > > indicating *success* of the commit.
> 
> I agree with Brady, in many cases it will be essential to know that the 
> transaction has completed successfully.  On the other hand, the system 
> is starting to have sort of a lot of callbacks!  But if it's going to be 
> async, that's sort of the penalty to be paid.

Ok. Done.


> One option would be to change SQLTransactionErrorCallback to 
> SQLTransactionCompletionCallback.  Having a separate callback is 
> probably better if the success-handler always looks materially different 
> from the failure-handler, but I think it's possible that having a single 
> callback with an if() inside might be less confusing than two callbacks.

I'm not sure that's really any better, and it has the problem that you can 
no longer use a single common error handler.


> I think one could work around this within the current spec something 
> like:
> 
> var success = true;
> 
> db.transaction(function (t) {
>   t.executeSql('insert into x values (?)', [y]);
>   db.transaction(function (t) {
>     if (success) {
>       // This should be called after the outer transaction has completed.
>     }
>   }
> }, function (e) {
>   success = false;
> });
> 
> That's awful cumbersome, but if the need is seldom enough, it might be 
> reasonable.

Actually that wouldn't work because nested transactions are completely 
independent of the initial one, so unless the transaction blocked the 
entire database, the nested one above would finish immediately.

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



More information about the whatwg mailing list