Hello, I created a section in my app to make a backup copy of one of the important databases of the app. The point is that my code only creates a .sqlite database but it turns out that 2 more files are automatically generated. Sqlite-wal and .sqlite-shm. When I consult the database with the extension .sqlite to see the fields saved in it, it shows me an error message and it does not let me show it, but when I show the .sqlite-shm all the data is there. Why have these extra files been generated, what files do I have to make the backup for when I restore the data to reappear correctly? I also pass the code to you because doing the restore does not rescue any data from the .sqlite file.
private void importarDB() {
try {
File sd = Environment.getExternalStorageDirectory();
File data = Environment.getDataDirectory();
if (sd.canWrite()) {
String currentDBPath = "//data//" + getPackageName()
+ "//databases//" + "DBnotas" + EquipoJuntoLayout + ".sqlite";
String backupDBPath = Archivo + EquipoJuntoLayout+".sqlite"; // From SD directory.
File backupDB = new File(data, currentDBPath);
File currentDB = new File(sd, backupDBPath);
FileChannel src = new FileInputStream(backupDB).getChannel();
FileChannel dst = new FileOutputStream(currentDB).getChannel();
dst.transferFrom(src, 0, src.size());
src.close();
dst.close();
ToastPersonalizado miToast = new ToastPersonalizado(this, Toast.LENGTH_SHORT);
miToast.show("Restore realizado con éxito");
}
} catch (Exception e) {
ToastPersonalizado miToast = new ToastPersonalizado(this, Toast.LENGTH_SHORT);
miToast.show("El Restore ha fallado");
}
PasarDatosMeses();
}
private void exportarDB() {
try {
File sd = Environment.getExternalStorageDirectory();
File data = Environment.getDataDirectory();
if (sd.canWrite()) {
String currentDBPath = "//data//" + getPackageName()
+ "//databases//" + "DBnotas" + EquipoJuntoLayout + ".sqlite";
String backupDBPath = Archivo + EquipoJuntoLayout+".sqlite";
File currentDB = new File(data, currentDBPath);
File backupDB = new File(sd, backupDBPath);
FileChannel src = new FileInputStream(currentDB).getChannel();
FileChannel dst = new FileOutputStream(backupDB).getChannel();
dst.transferFrom(src, 0, src.size());
src.close();
dst.close();
ToastPersonalizado miToast = new ToastPersonalizado(this, Toast.LENGTH_SHORT);
miToast.show("Backup realizado con éxito");
}
} catch (Exception e) {
ToastPersonalizado miToast = new ToastPersonalizado(this, Toast.LENGTH_SHORT);
miToast.show("El Backup ha fallado");
}
PasarDatosMeses();
}
I hope you can help me with this question, if you need any further clarification, please say so. I do not know if I will have expressed myself clearly.
Thanks in advance.