Please provide the following:
- SDK Version: 37
- Platforms(Android/iOS/web/all): Android
Im using expo-sqlite with typeorm, the Error: attempt to write a readonly database (code 1032) occurs when i try to insert / delete in the restored sqlite database file.
My backup / restore process are the following:
// BACKUP
// 1 - close connection
await getConnection().close();
// 2 - copy the sqlite database file
const databaseFileUri = `${FileSystem.documentDirectory}SQLite/database.db`;
const backupFileUri = `${FileSystem.documentDirectory}/backup-database.db`;
await FileSystem.copyAsync({
from: databaseFileUri,
to: backupFileUri,
});
// 3 - open connection
createConnection();
// 4 - upload the copied file to google drive as base64 content in the body
const bdFileBase64 = await FileSystem.readAsStringAsync(backupFileUri , {
encoding: FileSystem.EncodingType.Base64,
});
// RESTORE
// 1 - download file from google drive:
await FileSystem.downloadAsync(
`https://www.googleapis.com/drive/v3/files/${fileId}?alt=media`,
backupUriBase64,
{
headers: {
Authorization: `Bearer ${accessTokenGoogle}`,
},
}
);
// 2 - read the downloaded file base64 content as string
const backupContentBase64 = await FileSystem.readAsStringAsync(
backupUriBase64,
{
encoding: FileSystem.EncodingType.UTF8,
}
);
// 3 - parse base64 content string to binary and write to file
await FileSystem.writeAsStringAsync(destinationUri, backupContentBase64, {
encoding: FileSystem.EncodingType.Base64,
});
// 4 - close connection
// 5 - rename current database file to old.db
// 6 - rename created file with writeAsStringAsync in step 3 to database.db
// 7 - delete old.db file
// 8 - open connection
// 9 - try to insert : Error: attempt to write a readonly database (code 1032)
the strange part is selects still return the previous (and deleted) database file data, is there any cache that expo create for sqlite files?
i dont think its a encode / decode problem because i downloaded the base64 file from drive, manualy decode and i can open it with https://sqlitebrowser.org/ without errors even insert delete