I am developing a mobile application that uses Sqlite and I would like to pull the .db file from the phone and view it in DB Browser for Sqlite.
The issue comes from the fact that when I run the adb commands the .db file I get is empty, even though I have creatd tables and added data to those tables in the database.
In the application I query the database for the inserted records and they are returned. Any thoughts?
adb command: adb exec-out run-as projectname cat databases/my.db > my.db
db creation code:
if(!Sqlite.exists("my.db")){
new Sqlite("my.db")
.then(
(db) => {
//create table here
db.execSQL("CREATE TABLE IF NOT EXISTS Times (Id INTEGER PRIMARY KEY AUTOINCREMENT, clockIn TEXT, clockOut TEXT)")
.then(
() => {
console.log("succcess")
db.execSQL("INSERT INTO Times (clockIn, clockOut) VALUES (?, ?)", ["Nic", "Raboy"]).then(() => {
db.all("SELECT * FROM Times").then((rows) => {
console.log(rows)
})
})
},
(error) => {
console.log('Error occurred creating table');
});
},
(error) => {
console.log("Error creating Database");
});
}
I figured out how to solve this issue. On android 9 you have to include the -wal and -shm files when pulling using adb. Then when the .db file is opened you will see your database as you have built it and not an empty skeleton db.
This may not be the best way of doing this but it will work:
adb exec-out run-as projectname cat databases/my.db > my.db
adb exec-out run-as projectname cat databases/my.db-shm > my.db-shm
adb exec-out run-as projectname cat databases/my.db-wal > my.db-wal
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With