C# SQLite FTS5表和触发器创建

4dbbbstv  于 12个月前  发布在  SQLite
关注(0)|答案(2)|浏览(140)

我正在使用sqlite fts5创建一个虚拟表,并收到以下错误消息:SQL逻辑错误没有这样的模块:FTS5.下面是我的代码:在VS 2017中使用包管理器,我已经下载了SQLite和SQLite FTS5。

private static void CreateReport()
    {
        try
        {
            using (SQLiteConnection sqliteConnection = new SQLiteConnection(DataSources.LocalConnectionString()))
            {
                sqliteConnection.Open();
                sqliteConnection.EnableExtensions(true);
                string commandText = "CREATE TABLE IF NOT EXISTS JReport(JRId INTEGER PRIMARY KEY, IDId INTEGER, CaseId INTEGER, BoxName TEXT, JRText TEXT, JRFormatted TEXT)";
                string commandText1 = "CREATE VIRTUAL TABLE IF NOT EXISTS DReport USING FTS5(JRId, CaseId, BoxName, CONTENT = 'JReport', CONTENT_ROWID = 'JRId')";
                string commandText2 = "CREATE TRIGGER DocRepo AFTER INSERT ON JReport BEGIN INSERT INTO DReport(RowId, JRId, CaseId, BoxName) VALUES(NEW.JRId, NEW.CaseId, NEW.BoxName) END";
                using (SQLiteCommand sqliteCommand = new SQLiteCommand(commandText, sqliteConnection))
                {
                    sqliteCommand.ExecuteNonQuery();
                    sqliteCommand.Dispose();
                }
                using (SQLiteCommand sqliteCommand = new SQLiteCommand(commandText1, sqliteConnection))
                {
                    sqliteCommand.ExecuteNonQuery();
                    sqliteCommand.Dispose();
                }
                using (SQLiteCommand sqliteCommand = new SQLiteCommand(commandText2, sqliteConnection))
                {
                    sqliteCommand.ExecuteNonQuery();
                    sqliteCommand.Dispose();
                }
                sqliteConnection.Close();
            }
        }
        catch (Exception ex)
        {
            MessageBoxEx.Show("An error has occurred while creating the Report table, the original error is: " +
                ex.Message, "Report", MessageBoxButtons.OK, MessageBoxIcon.Error);
        }
    }
vmdwslir

vmdwslir1#

SQL逻辑错误没有这样的模块:FTS5。
就像错误消息所说的那样,您的sqlite3库没有FTS5模块。在构建库时,它可能没有被配置为将其作为内置库包含在内,因为默认情况下它没有启用。它可能是由配置和构建您正在使用的库的人作为动态可扩展模块提供的。或不.
就我个人而言,我总是在我使用的任何程序中包含一个sqlite3.c的副本,以避免依赖于外部依赖,这样你就可以确保你总是使用一个具有你想要使用的所有功能的版本。不知道你在C#中要做什么才能使用你自己的本地示例,但我相信有一种方法。
将FTS5构建到sqlite3中或作为sqlite3模块的说明。

twh00eeo

twh00eeo2#

我解决了这个错误消息“SQL逻辑错误没有这样的模块:FTS5.”通过使用“LoadExtension”命令:

MyConnection.EnableExtensions(true);
MyConnection.LoadExtension("SQLite.Interop.dll", "sqlite3_fts5_init");

相关问题