简体   繁体   中英

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. sqlite_master table rows have type = 'table' and a name column.

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);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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