Why is PhoneGap Android app crashing while inserting bunch of data into SQL?

后端 未结 3 637
情书的邮戳
情书的邮戳 2021-01-03 10:21

I have PhoneGap app running in Android. When the app starts, it inserts approximately 500 rows into SQL. Table has 10 columns. It\'s not a lot of data, I have a JSON in text

3条回答
  •  温柔的废话
    2021-01-03 10:51

    Maybe you need a recursive callback function like this:

    //too many insert statements
    var sqlits= ["INSERT INTO ...", .. .. .. ,"INSERT INTO ..."];
    
    function populate(){
        db.transaction(function(tx){
            if(sqlits.length > 0){
                sql=sqlits.shift();
                tx.executeSql(sql);
            }else{
                alert('End');
            }
            return true;
        },function(tx,err){ 
            console.log("SQL Error: "+err); 
        },populate);
    };
    
    populate();
    

提交回复
热议问题