LeTadas
LeTadas

Reputation: 3556

How to export SQLite database the right way

So I was reading quite a lot, but still don't understand how to do it. In the location where app database suppose to be located there is three files instead of one .db it has now .db .db-shm and .db-wal so how do I export this database as one file with all its data? Because as far as I understand now all data is located in file .db-wal.

So far I tried to close all connections to database before exporting because in SQL documentation it says that it .db-wal will be merged, but still same scenario

Upvotes: 2

Views: 831

Answers (1)

Tom O
Tom O

Reputation: 2645

This is how I do it (on an ubuntu machine):

  1. Locate adb file in Android/Sdk/platform-tools/
  2. Open command line in this directory
  3. Run the following code, to pull Sqlite database from app to SD card:

    ./adb -d shell "run-as com.example.name.myappname cp /data/data/com.example.name.myappname /databases/database.db /sdcard/database.db"

*Make sure to replace "database.db" and "com.example.name.myappname", by your databasename and app name (found in your manifest).

  1. Run the following code, to pull the Sqlite data from SD card to desktop:

    ./adb -d pull /sdcard/database.db ~/Desktop/database.db

If you want to load your app with this database, I recommend using SQLiteAssetHelper.

Upvotes: 1

Related Questions