HTML5 Web SQL Transactions skipped without error when touch triggered in IOS

前端 未结 2 1199
梦如初夏
梦如初夏 2020-12-15 10:12

I\'m experiencing problems making database transactions on IOS devices. If the user doesn\'t touch the phone, everything works like expected. If the user taps/scrolls/touche

2条回答
  •  一个人的身影
    2020-12-15 10:32

    Web Workers and OpenDatabaseSync fix the same problem on my site. Except web workers are not supported on iOS4.x and Android so we can implement the old way for those and web workers on iOS5.

    The very basic example below uses a loop to do a single insert 500 times writing to the screen after each insert. At the end a query is made to return the number of rows in the table. Now we can see transactions are not skipped even with a lot of scrolling.

    This example is designed so you can test the resilience to scrolling during the inserts on iPhone or iPad.

    Two pages are required, an html page and separate javascript file for the worker. So for the html page;

    
    
        
        
        
        
        
        
        
    
    
    
        

    and worker1.js ;

    var wdb = {};
    wdb.db = openDatabaseSync('test', '1.0', 'DB test', 1024);
    
    doQuery("CREATE TABLE IF NOT EXISTS test(abc INTEGER PRIMARY KEY);");
    doQuery("DELETE FROM test"); // optional
    
    for (var i = 0; i < 500; i++) {
        doQuery("INSERT INTO test(abc) VALUES( " + i + " );");
        postMessage({ message: "Inserted " + i.toString(), complete: false });
    }
    
    var summary= doQuery("SELECT COUNT(*) AS Total FROM test;");
    postMessage({ message: "Found " + summary.item(0).Total.toString() + " rows", complete: true });
    
    function doQuery(sql) {
        wdb.db.transaction(function (tx) {
        rs = tx.executeSql(sql, []);
        });
        return rs.rows;
    }
    

提交回复
热议问题