开发者

writing too many times in a database

开发者 https://www.devze.com 2023-02-20 15:46 出处:网络
I\'m tryingto store in a database some GPS data that I get from a KML file using DDMS, the problem is that every time I run my program 开发者_运维百科I store this data. This means that I have it store

I'm trying to store in a database some GPS data that I get from a KML file using DDMS, the problem is that every time I run my program 开发者_运维百科I store this data. This means that I have it stored for couple of times. After that I have to create a route based on this GPS data stored in in Sqlite.

Now the problem is that I can't have this route right because in my database is a mess. So much data stored for too many times.Does anyone have an idea of how can I get this done right. I'm running on android 2.1


Rewrite the data base initialization logic so that it stores an indicator that the data base has been initialized. (SharedPreferences is good for this.) Then test for the indicator and skip the data base initialization at start-up if the indicator shows it has already been done.


If you are simply INSERTing the data each time, you could switch to REPLACE instead. This will then replace the existing data (if the data matches). Personally, I'd change your database setup code, though.

One easy thing to use is the user_version pragma. This allows you to get or set a database "version" for your database. It defaults to 0, so you could check it at app start and if it is 0, initialize the DB and then set it to 1. Subsequent app starts would then skip the database initialization.

PRAGMA user_version
PRAGMA user_version = 1
0

精彩评论

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