sqlite - Flutter 从 Dropbox 恢复 SQLite Db
问题描述
我正在尝试为我的应用程序实现一个还原数据库,以涵盖电话续订的情况。
我刚刚将我的 db 文件“database.db”上传到 Dropbox,我设法再次下载该文件,但是每当我在下载后尝试打开 Db 时,我都会遇到异常,并且似乎文件以某种方式被损坏了. 我是否必须将其保存到保管箱或使用某些特定参数下载?
E/SQLiteLog(16429): (26) file is not a database
D/SQLiteConnection(16429): Corruption detected - isPrimary: true, address: @2e80143
E/SQLiteDatabase(16429): Failed to open database '/data/user/0/com.testdropbox.test/app_flutter/database.db'.
E/SQLiteDatabase(16429): android.database.sqlite.SQLiteDatabaseCorruptException: file is not a database (code 26 SQLITE_NOTADB[26]): , while compiling: PRAGMA journal_mode
Future downloadTest() async {
if (await checkAuthorized(authorize: true)) {
Directory docsDirectory =
await pathProvider.getApplicationDocumentsDirectory();
String dbPath = join(docsDirectory.path, DB_NAME);
await _dbService.closeDb();
final result =
await Dropbox.download('/db/$DB_NAME', dbPath, (downloaded, total) {
print('progress $downloaded / $total');
});
print(result);
print(io.File(dbPath).statSync());
await _dbService.openDb();
}
}
Future uploadTest() async {
if (await checkAuthorized(authorize: true)) {
io.Directory docsDirectory =
await pathProvider.getApplicationDocumentsDirectory();
String filepath = join(docsDirectory.path, DB_NAME);
io.File(filepath).writeAsStringSync(
'contents.. from ' + (io.Platform.isIOS ? 'iOS' : 'Android') + '\n');
final result =
await Dropbox.upload(filepath, '/db/$DB_NAME', (uploaded, total) {
print('progress $uploaded / $total');
});
print(result);
var _content = await listFolder('');
print(_content);
}
}
解决方案
好的,我对此表示歉意,我用路径弄乱了变量,并且在这一行中的 dropbol 上传之前写入了文本并覆盖了数据库文件:
io.File(filepath).writeAsStringSync(
'contents.. from ' + (io.Platform.isIOS ? 'iOS' : 'Android') + '\n');
推荐阅读
- maven - Grails 是否使用 Maven 代理设置?
- react-native - 如何等待 setState 完成然后在 React Native 中执行代码?
- java - Kotlin IndexOutOfBoundsException on list to map 转换
- node.js - 如何在 MERN 堆栈应用程序中内联加载图像文件
- asp.net-web-api - SignalR 是否应该在自己的微服务中
- c++ - 带有范围的 std::map::lower_bound
- javascript - 使用 G:用于 Node JS 项目的桌面版 Google Drive(npm 安装错误)
- xcode - 从嵌套的 Swift 包访问资产时,SwiftUI 预览崩溃
- javascript - DataTables 的 TreeGrid 扩展 - 获取选定行的值
- react-router - 类型错误:history__WEBPACK_IMPORTED_MODULE_0__.Action 未定义