列出由用户/开发人员而不是由SQLite本身创建的表

cbjzeqam  于 2022-11-15  发布在  SQLite
关注(0)|答案(1)|浏览(263)

如果我运行以下命令:

select * from sqlite_master where type = \'table\';

我得到了我创建的表,但也得到了类似于android_metadatasqlite_sequence的表。我想在我的应用程序中有一个功能,可以擦除我的表的内容,但我宁愿不碰数据库为自己创建的表。
我列出所有表,提取它们的名称,过滤列表,并调用列表上的delete from $tablename

Future<List<QueryRow>> _getNumberOfExistingTableRows() async {
    List<String> sqliteTableNames = ["android_metadata", "sqlite_sequence"];
    String selectTablesSql = "select * from sqlite_master where type = \'table\';";
    final result = await customWriteReturning(selectTablesSql);
    result.removeWhere((row) => sqliteTableNames.contains(row.data["name"]));
    return result;
  }

   List<String> tableNameList = _queryRowsToTableNames(await _getNumberOfExistingTableRows());
    for (String tableName in tableNameList) {
      await customStatement("delete from $tableName;");
    }

它可以工作,但如果SQLite在未来的版本中为自己创建另一个表,那么它也将擦除该表。

0lvr5msh

0lvr5msh1#

vbl.使用

SELECT * FROM sqlite_master WHERE type = 'table' AND name NOT LIKE 'sqlite_%' AND name NOT LIKE 'android_%';`

应该能行得通。

相关问题