WebSql: transaction does rollback if size limit is reached

↘锁芯ラ 提交于 2019-12-12 05:39:23

问题


I just noticed that if you're inserting data into WebSQL, and je hit the maximum size-limit, the iPad will popup the user with an alert asking if you want to increase the size. However, even if you approve, the current transaction will rollback. I was wondering if there is anything that can be done to prevent the rolling back, so you can just continue ?

Here is the test code. The code that actually does the rollback is

db.transaction(function (tx) {
    ... // create the table // ...
    for( var i = 0; i < 10000; i++ ) {
        insertData(tx) ;
    }
},
function() {
    console.log("Transaction error -> rollback") ;
},
function() {
    console.log("transaction is ready") ;
}) ;

Any suggestions ?

Cheers


回答1:


A way to handle an out-of-space situation with WebSQL is detailed in my blog post. Basically, you do not have power to refuse the browser to prompt the user, so you must handle the situation. The simple thing to do is just inform the user that you need more space, and just force a re-prompt to increase the size, where the success callback of the transaction calls your original code.

If what you really intended to say was that you wanted to keep all the code up-until you ran out of space, you can keep an external index of how far you managed to go before the transaction rolled back, and then redo the transaction with the previous limit. That way all the data that was possible to cram in will be there (and the rest will never be written).



来源:https://stackoverflow.com/questions/15066203/websql-transaction-does-rollback-if-size-limit-is-reached

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!