z.nordine
z.nordine

Reputation: 1

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 English)

Upvotes: 0

Views: 78

Answers (2)

Mat
Mat

Reputation: 206659

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.

Upvotes: 0

sharptooth
sharptooth

Reputation: 170479

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.

Upvotes: 1

Related Questions