manager.replaceDatabase(arg0, arg1, arg2); //how to use it properly?[ { "_id": 1, "name": "Financial", "description": "Collection of financial books", "Books": { "Rich dad poor dad": { "description":"How to save and invest money" }, "How to stay rich":{ "description":"What you should know about money" } } }, { "_id": 2, "name": "Comics", "description": "Collection of comic books", "Books": { "Superman": { "description":"Undercover journalist" }, "Green hornet":{ "description":"Green guys in a suit" } } }]I'm having hard time to figure out how to fill database with default values when installing application for the first time.
Which program should i use to create pre-defined database (Like "SQLite Expert" for ordinary SQL databases) ?
// create a new databaseDatabase database = null;try { database = manager.getExistingDatabase(dbname); //if this line works, then db already exists} catch (CouchbaseLiteException e) { database = manager.getDatabase(dbname); //exception thrown, need to initialize db //in addition to creating the db: //insertDefaultValuesIntoDB(); //replaceDBWithExistingDB();}/data/data/com.couchbase.cblite.test/files/test
You should then see the following files/folders:
cblite-test
cblite-test.cblite
cblite-test.cblite-journal
cblite-test - contains an attachments subfolder, which will contain attachment binaries if you created any docs with attachments. You will need to copy these off the device/emulator if you have docs in your DB with attachments.
cblite-test.cblite - this is the DB file that your code created, you need to copy this off of the device/emulator and embed it in your App as an asset.
cblite-test.cblite-journal - journal file for your DB, this is not required
/Applications/Android Studio.app/sdk/platform-tools
$ ./adb shell
shell@android:/ $ su
shell@android:/ # cp /data/data/your.package.name/databases/<your_database>.cblite /mnt/shell/emulated/0/Download/<your_database>.cblite
shell@android:/ # exit
shell@android:/ $ exit
localuser:~ localhost$ adb pull /mnt/shell/emulated/0/Download/<your_database>.cblite ~/<your_database>.cblite
What it does is:
1. Connects to the emulator
2. Requests superuser permissions
3. Copies the file that is only available to superuser to a public directory (Downloads in this case)
4. Pulls the file from public folder (Downloads) to your local machine home directory.