Reputation: 619
I'm processing 31000 Insert SQL statements reading from a file and it takes more than 2 minutes to complete.. need some advice in improving performance..
Here is the code:
while((line=reader.readLine())!=null){
dbs.execSQL(line);
k=(int)(i*0.0032);
if(k%10==0){fdb.publishProgress(k);}
i++;
}
Upvotes: 0
Views: 83
Reputation: 17304
Do a batch insert using technique mentioned here Is it possible to insert multiple rows at a time in an SQLite database?
Please note that you can only insert 500 rows at a time in a query using this technique. So insert 31000 records in queries containing 500 records per query. And you can publish progress after every query i.e. after every 500 inserts.
Upvotes: 1
Reputation: 28484
DO this trick will work;
dbs.beginTransaction();
while((line=reader.readLine())!=null){
dbs.execSQL(line);
k=(int)(i*0.0032);
if(k%10==0){fdb.publishProgress(k);}
i++;
}
dbs.setTransactionSuccessful();
dbs.endTransaction();
Upvotes: 0
Reputation: 33515
m processing 31000 Insert SQL statements reading from a file and it takes more than 2 minutes to complete.. need some advice in improving performance..
All what you are able to do is to use BufferedReader
if you actually not using it for reading from file.
And concerning to SQLite
if you are processing hundreds and thousands of insert, update or delete statements a usage of transaction will rapidly increase speed performance and also it has other benefits like security and there is not danger of losing database integrity.
Upvotes: 1