gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-04 10:01:15 26 4
gpt4 key购买 nike

我已经尝试了以下并且只收到了关于整个数据库的信息。

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

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

print(tables);
}

我希望获得数据库中存在的表名列表。

最佳答案

如您在输出中所见,架构很简单。 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);

关于flutter - 如何在 Flutter 中列出 SQFlite 数据库中的表名?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61810611/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com