为什么颤动无法检测到我的预列SQLite数据库的表? (1)没有这样的桌子
我在应用程序的资产中有一个预先填充的数据库。该应用程序可以正确地与数据库进行连接,但是当我尝试制作一个简单的原始Query时(“从empresa中选择 *”),我给我一个例外,说该表不存在。
什么可以产生这个问题,更重要的是,我该如何解决?
这是我类dbhelper的代码。我只在其他页面中进行此类实例,并且存在错误。
class DBHelper {
static Database? _db;
Future<Database> get db async => _db ??= await initDB();
initDB() async {
Directory documentDirectory = await getApplicationDocumentsDirectory();
String path = join(documentDirectory.path, "ANUARIO.db");
bool dbExists = await File(path).exists();
if (!dbExists) {
try {
ByteData data = await rootBundle.load(join("assets", "ANUARIO.db"));
List<int> bytes = data.buffer.asUint8List(data.offsetInBytes, data.lengthInBytes);
await File(path).writeAsBytes(bytes, flush: true);
} catch (e) {
print(e);
}
}
var theDB = await openDatabase(path);
return theDB;
}
}
I have a prepopulated database in the assets of my app. The app makes the connection with the database properly, but when I try to make a simple rawQuery like ("Select * FROM empresa") it throw me an exception saying the table doesn't exist.
What can generate this problem and more important, how can I fix it?
This is the code of my class DBHelper. I only make an instance of this class in other page and there is the error.
class DBHelper {
static Database? _db;
Future<Database> get db async => _db ??= await initDB();
initDB() async {
Directory documentDirectory = await getApplicationDocumentsDirectory();
String path = join(documentDirectory.path, "ANUARIO.db");
bool dbExists = await File(path).exists();
if (!dbExists) {
try {
ByteData data = await rootBundle.load(join("assets", "ANUARIO.db"));
List<int> bytes = data.buffer.asUint8List(data.offsetInBytes, data.lengthInBytes);
await File(path).writeAsBytes(bytes, flush: true);
} catch (e) {
print(e);
}
}
var theDB = await openDatabase(path);
return theDB;
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
问题
必须共享您的代码才能查看出什么
您 它在不创建新的并进行查询之前创建
,并且您可以使用它可能会有用
sqflite_ffi.dart
u must share ur code to see what go wrong with it
but i think that u create the same data base over every time u run ur function
and for example u must see if there is any database with the same name have been create before and if it create before do not create new one and make query
and u can use this may be helpful
sqflite_ffi.dart