[英]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.