2

I am using Phonegap(Cordova) with "Good dynamics" in iOS. We have a table with 15 columns and need to insert more than 10000 to 200000 records based on condition at once.

But my app is getting crashed in iPAD when testing for more than 2000 records insertion.

I tried two different bulk insertions as in below link Stack overflow answer(USING UNION ALL and COMMA separated INSERTS)

And also i tried both options:

1) Opening a transaction for each insert.

2) Multiple insertions in single transaction using for loop.

When tested in iOS simulator instruments both are taking more than 1GB memory when inserting more than 5000k records (i suspect which is causing issue).

Can any one suggest better solution for inserting multiple records when table have more columns with out any issues in IOS+SQLlite+PhoneGap+Good Dynamics

Sample code i used:

for(var j=0;j< bulkTransactions.length;j++){
    (function(item,count){
        db.transaction(function(tx){
            if(item){
                var insQuery= item;
                tx.executeSql(insQuery, [],
                    function(tx,results){ //Success
                        if(count == bulkTransactions.length-1) {
                            if(callBackMethod != null)callBackMethod();
                        }
                    },
                    function(tx,e){ 
                        //Handle Error
                    }
                );
            }
        });
    }) (bulkTransactions[j],j);
}

The application is working fine in iOS simulator(even its showing 1GB memory usage) or Chrome Browser, the below image shows memory usage for 12000 records in iOS simulator:

enter image description here

Community
  • 1
  • 1
Kiran
  • 1,107
  • 1
  • 7
  • 19
  • yes even i faced the same issue while inserting more than 20000 records. But i have acheived by splitting 100 records so that it will not consume more memory, apparetly it will take same time. All you need to do is do in background to make sure main UI thread is not blocked (or) set a loader til the process finishes. In my case for insering 10000 it takes 15 seconds. – Mohammed Imran N May 10 '15 at 06:52
  • do you have any sample code can u share? how you are starting process in background – Kiran May 11 '15 at 10:12
  • We followed Mohammed Imran's suggestion above to delay after every 1000 records which is working fine now – Kiran Jul 06 '15 at 04:32
  • Glad that my answer has helped you :) – Mohammed Imran N Jul 06 '15 at 04:51

0 Answers0