简体   繁体   English

SQLite检查表是否为FTS4

[英]SQLite Check if Table is FTS4

I'm developing an Android app that uses a SQLite database with FTS4 tables. 我正在开发一个使用带有FTS4表的SQLite数据库的Android应用。

In the app there's an option to import a database from the external memory. 在应用程序中,有一个选项可以从外部存储器导入数据库。 This database needs to be checked to confirm that it has all the correct tables and columns. 需要检查该数据库以确认它具有所有正确的表和列。 I already have the code to do that however I don't know how to check if the tables are "normal" or FTS4. 我已经有执行此操作的代码,但是我不知道如何检查表是否“正常”或FTS4。 This will result in problems later on with queries with MATCH on them. 稍后将导致对带有MATCH查询产生问题。

The only way I can think of to check if the tables are FTS4 is to do a random query with MATCH and if it gets an error it's because they are not. 我能想到的检查表是否为FTS4的唯一方法是使用MATCH进行随机查询,如果出现错误,是因为它们不是。

Is there a better way to do this like with just a command? 有没有像使用命令那样更好的方法呢?

Using MATCH on a plain table results in an error message only if the table has at least one row. 仅在表具有至少一行的情况下,在普通表上使用MATCH才会导致错误消息。

FTS table have a virtual column with the same name as the table name. FTS表具有一个虚拟列,其名称与表名称相同。 So you could try a query like SELECT MyTable FROM MyTable . 因此,您可以尝试使用类似SELECT MyTable FROM MyTable的查询。

You could check whether the shadow tables ( MyTable_content , MyTable_segdir , etc.) exist. 您可以检查影子表MyTable_contentMyTable_segdir等)是否存在。

You could check the CREATE TABLE statement in the system table: SELECT sql FROM sqlite_master WHERE type = 'table' AND name = 'MyTable'; 您可以检查系统表中的CREATE TABLE语句: SELECT sql FROM sqlite_master WHERE type = 'table' AND name = 'MyTable';

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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