java - How to speed up queries in sqlite android in db.execSql -
i have following code use enter data in database.
public static void execsql(sqlitedatabase db, string sql) { string[] parts = sql.split(";"); (string entry : parts) { db.execsql(entry); } }
initially "insert ......" in sql string, execute each insert cycle. total insert 22908. data input 4 minutes, think long time. data 7,95 mb. there way speed introduction , bring seconds ?
insert location ( 'latitude' , 'updated' , 'id' , 'longitude' , 'created' ) values( '213.2000000' , '2014-08-25 11:07:42+00:00' , '1' , '321.0000000' , '2014-08-25 11:07:42+00:00' ); insert location ( 'latitude' , 'updated' , 'id' , 'longitude' , 'created' ) values( '42.7191000' , '2014-09-17 12:53:49+00:00' , '2' , '23.0834000' , '2014-09-17 12:53:49+00:00' ); ......................
here data sql variable.
wrap work in transaction:
db.begintransaction(); try { // sql goes here db.marktransactionsuccessful(); } { db.endtransaction(); }
right now, doing 1 transaction per sql statement, horribly slow. each transaction involves disk i/o, , more efficient 1 larger batch of disk i/o thousands of little ones.
using prepared statements incrementally well.
Comments
Post a Comment