0

I want to rename database files. The tasks seems to be easy.

1) I close database 2) rename .db file 3) rename .db-journal file 4) I open database

However what will happen if ex. after the step number 2 and before the step number 3 the system will crash (I know the probabiliby is low, but...)?

I noticed that depending on the Android version sometimes after closing the database .db-journal file has 0 size (ex. android 4.0.4) but sometimes it's quite huge (ex. 50% of .db file size) (ex. android 4.2.2). If size is 0, sure I expect there is no problem (loosing .db-file in the mentionned scenario will probably not cause any missing data). But when the .db-jurnal file is quite huge, does it mean that opening .db file without .db-journal (it will have the old name) will cause any data loss?

Is there any way to rename two files in one "transaction" (either both are renamed either none of them)?

And what if I want to share my database (ex. I want to send it to my friend by e-mail)? Is that a must to send two files .db and .db-journal or only sending .db file is enough?

ligi
  • 39,001
  • 44
  • 144
  • 244
user2707175
  • 1,133
  • 2
  • 17
  • 44
  • The journal is only for transaction / commit. sending the .db file to your friend is enough. As for rename a database let's see if any answers come in. – danny117 Sep 04 '14 at 21:41

1 Answers1

1

The rollback journal file contains information that is need to roll back a transaction.

If the app crashed while a transaction was active, the database will do the rollback automatically the next time the database is opened.

If you have opened a database (and maybe closed it again), and there is no active transaction, and your app has not crashed and is still running, then you know that the database file is in a consistent state and that you can ignore the journal file. (If the journal mode is set to DELETE, there will be no -journal file then.)

(Note: in WAL mode, you cannot ignore the -wal file.)

CL.
  • 173,858
  • 17
  • 217
  • 259
  • I set journal mode to delete, but db-journal file still exist (although with size equal to zero in android 4.0.4, not sure what about 4.2.2 I will check that later). – user2707175 Sep 05 '14 at 21:54