为什么颤动无法检测到我的预列SQLite数据库的表? (1)没有这样的桌子

发布于 2025-02-08 19:07:14 字数 991 浏览 1 评论 0原文

我在应用程序的资产中有一个预先填充的数据库。该应用程序可以正确地与数据库进行连接,但是当我尝试制作一个简单的原始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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

美人如玉 2025-02-15 19:07:14

问题

必须共享您的代码才能查看出什么

您 它在不创建新的并进行查询之前创建

,并且您可以使用它可能会有用

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文