简体   繁体   English

如何阅读“老”的sqlite?

[英]Howto read “old” sqlite in flutter?

I rewrote my existing android app using flutter. 我用flutter重写了我现有的Android应用程序。

Is it possible to access the old database that my old app created? 是否可以访问我的旧应用程序创建的旧数据库? If i make a SELECT on the old table, i don't get any data. 如果我在旧表上进行SELECT,我不会得到任何数据。

Old app: 旧应用:

private final static String DB_NAME = "oweapp";

new app: 新应用:

String path = join(documentsDirectory.path, "oweapp.db");

If you provide the database in the assets folder you should copy the database to de device first. 如果在assets文件夹中提供数据库,则应首先将数据库复制到de device。 If not, opening a database in the external storage of the device (as you are doing) should work. 如果没有,在设备的外部存储器中打开数据库(正如您所做的那样)应该可以正常工作。

ByteData data = await rootBundle.load("assets/oweapp.db");
List<int> bytes = data.buffer.asUint8List(data.offsetInBytes, data.lengthInBytes);

final directory = await getDatabasesPath();
String dbPath = join(directory, "oweapp.db");
await File(dbPath).writeAsBytes(bytes);

// After that you can do:
var db = await openDatabase(dbPath);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM