繁体   English   中英

如何在 Flutter 中列出 SQFlite 数据库中的表名?

[英]How do I list the table names in a SQFlite Database in Flutter?

我尝试了以下方法,只收到了整个数据库的信息。

listTables() async {
    sqflite.Database dbClient = await this.db;

    List<Map<String, dynamic>> tables = await dbClient
        .query('sqlite_master');

    print(tables);
  }

我正在寻找数据库中存在的表名列表。

正如您在 output 中看到的,架构很简单。 sqlite_master表行具有type = 'table'name列。

调试打印:

(await db.query('sqlite_master', columns: ['type', 'name'])).forEach((row) {
  print(row.values);
});

得到类似的东西:

(table, Product)
(table, Client)
(table, Request)
(index, Request_clientId)
(index, Request_productId)

您可以使用以下代码获取表名:

var tableNames = (await db
        .query('sqlite_master', where: 'type = ?', whereArgs: ['table']))
    .map((row) => row['name'] as String)
    .toList(growable: false);

暂无
暂无

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

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