开发者

How do I dump my sqlite db back into my assets folder

I have succeeded in generating a sqlite3 database in my android app from an initial sqlite3 file in my assets开发者_开发问答 folder. It would be helpful to have a similar routine to dump the modified database back into that folder to a) verify that all updates/inserts/deletes are working correctly and b) as a possible way to pass bulk revisions to another process.

Does anyone have a utility for this?


I don't think so if you can do that. If you want to save data you recently inserted, you can keep it your database in /database folder, in order database not to be rewritten (think of like this: when you start your app, you code again writes the database from your asset folder to /database folder, so you have the old data again) do this

File filedb = new File("data/data/[package-name]/databases/"+DATABASE_NAME);
if( !filedb.exist())
{


   //if the database file does not exist, means that database is not copied for you asset folder to /database folder, so you do the copying, 

}

With this test you have prevented your database in /database folder to be rewriten with the database you have in your asset folder. To verify if inserting/deleting/updateing is working fine, pull out your database file from the emulator and open it with SQLite Browser. Don't forget to put it back in assets ;)

Cheers.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜