dimanche 10 janvier 2016

HTML5 SQLITE multiple queries failure

I'm developing a APP using HTML 5 SQLITE which runs on chrome browser. I have a SQL file which contains queries of create table and insert into table. The file size varies from 30 MB to 100 MB. Here is the code that reads the queries from file and execute the query in browser.

I was first executing the bunch of query in single query, suppose 55 queries where executed at once. This works fine when the sql file size around 40 MB, also it works fine for some large file size but for some it fails. SO i thought to split all queries and executed them one after other in loop. So 55 queries executed individually. But the loop stops in between without any error and further queries are not executed. What can be the problem ?

Is there a limitation of query execution in chrome or SQLite ? Or a limitation with sql file size ?

$.ajax({
    url:'http://localhost/myfolder/85-singapore.sql',
    type: "GET",
    contentType: "application/json",
    dataType: "jsonp",
    jsonpCallback:"my",
    success: function(obj){
        html5sql.process(
            "DROP TABLE IF EXISTS poi_data;DROP TABLE IF EXISTS city_data;DROP TABLE IF EXISTS event_data",
            function(){
            var queryArr = obj.sql.split("^::^");
            console.log("total Queries");
            console.log(queryArr.length);
            for(var i=0; i<queryArr.length;i++){
                var islast = false;
                if(i+1 == queryArr.length){ islast = true; }
console.log(i);
                var query = queryArr[i];
myAPP.loadSQL(query,islast);
            }
            },
            function(error, failingQuery){ //Failure
            console.log("DROP SQL Error");
            console.log(error.message);
            if(error.message.indexOf("no such table") != -1){
                var queryArr = obj.sql.split("^::^");
                console.log("total Queries");
                console.log(queryArr.length);
                for(var i=0; i<queryArr.length;i++){
                    var islast = false;
                    if(i+1 == queryArr.length){ islast = true; }
                    //myAPP.loadSQL(queryArr[i],islast);
                }
            }
            }
        );
    },
    error:function(err){
        console.log(err);
    }
});

loadSQL: function(sql,isLast){
    try{
console.log(sql);
        var startTime = new Date();
        html5sql.process(
            sql,
            function(){ //Success
console.log("LOAD SQL success");
            var endTime = new Date();
            console.log("Table with entries created in: " + ((endTime - startTime) / 1000) + "s");
            myAPP.removeLoading();
            if(isLast){
                myAPP.sqlLoaded = true;
            }
            if(myAPP.sqlLoaded){
                myAPP.init();
                myAPP.fetchAll();
            }
            },
            function(error, failingQuery){ //Failure
console.log("LOAD SQL Error");
            myAPP.removeLoading();
            $("#results").text("Error: " + error.message);
console.log(failingQuery);
            }
        );
    }catch(err){
        console.log("loadSQL catch--"+err);
    }
},

Aucun commentaire:

Enregistrer un commentaire