Not able to get populated sqlite db from the android emulator

298 views Asked by At

Using react-native-sqlite-storage for the first time, I was able to create an sqlite db file in the Android emulator, created a table in it and inserted a row successfully. After that on a button click, I also verified by a select that the row was inserted.

Then I used Android Studio's "device file explorer" to locate the test.db file in the data\data<apppkg>\databases folder and used "save as" to copy it to the PC's folder. Now when I open the test.db file in the browser utility, it's empty! There is no table in it.

Suspecting a "flush" problem, I also tried a db.close() in the app. But still I'm not able to get the populated database copy from the Android emulator. What am I doing wrong?

Update: I noticed that on the android emulator, there are 2 more files with the database file--an shm and a wal file. Reading some other threads, it seems they are keeping the journal so it seems the data is not committed yet. Those threads mention closing the cursor. But there is no such mention in the storage library docs. How do I ensure a cursor close from the App other than calling the close() that does not really close it and commit the data.

1

There are 1 answers

0
user173399 On BEST ANSWER

Finally, for my simple, single table requirement, I ended up calling executeSql on the db object instead of doing it through a transaction. That solved the problem and on close, it's always a single file. Somehow, when you use a transaction, the other files linger around even if you close the db.