开发者

sqlite : downloading a db

I'm new android developer, first thank's for all the answers which helps me every day. My question is: I'm want to use a sqlite to have a db with many thousand rows but inserting this takes in average one second per line : it's too slow; my db must be updated every day so I want to zip this db, downloading in a folder of my application(assets ou raws). Android sdk allows this? I look in many answers but i found nothing. Thank's for all. (excuse my Englis开发者_开发问答h)


The solution to your problem is to use transactions. You say "BEGIN TRANSACTION" to SQLite, then run all your INSERTs, then say "COMMIT TRANSACTION". This is much faster because unless there's started transaction already SQLite runs every query inside a separate transaction (so-called autocommit) and doing "COMMIT TRANSACTION" internall for each INSERT is very slow.


No idea about the android part, but inserts taking 1s is abnormal. If you're going to insert a large number of rows, do it in a transaction.

begin transaction;
insert into mytable values (...);
....
commit;

This will be much faster than just doing the inserts one at a time.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜