[英]How do I list the table names in a SQFlite Database in Flutter?
I have tried the following and only received information on the entire database.我尝试了以下方法,只收到了整个数据库的信息。
listTables() async {
sqflite.Database dbClient = await this.db;
List<Map<String, dynamic>> tables = await dbClient
.query('sqlite_master');
print(tables);
}
I am looking to get a list of the table names which exist in the database.我正在寻找数据库中存在的表名列表。
As you see in the output, the schema is simple.正如您在 output 中看到的,架构很简单。 sqlite_master
table rows have type = 'table'
and a name
column. sqlite_master
表行具有type = 'table'
和name
列。
Debug print:调试打印:
(await db.query('sqlite_master', columns: ['type', 'name'])).forEach((row) {
print(row.values);
});
to get something like:得到类似的东西:
(table, Product)
(table, Client)
(table, Request)
(index, Request_clientId)
(index, Request_productId)
You can get the table names with the following code:您可以使用以下代码获取表名:
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.