SQLite数据库包含一个包含JSON数据的列,如下所示:
MyTable
______________________________________
| specs | name | date
--------------------------------------
| ["foo","bar"] | Test01 | 2018-02-05
| ["foo","bar"] | Test02 | 2018-02-01
| ["foo"] | Test03 | 2018-02-03
的伪代码:
private static SQLiteConnection _sqliteDb;
using (var source = new SQLiteConnection($"Data Source={databasePath};Version=3;"))
{
source.Open();
_sqliteDb = new SQLiteConnection("Data Source=:memory:");
_sqliteDb.Open();
// copy db file to memory
source.BackupDatabase(_sqliteDb, "main", "main", -1, null, 0);
source.Close();
}
var cmd = new SQLiteCommand(query, _sqliteDb);
为了过滤此列,查询如下所示:
var query = "SELECT * FROM MyTable, json_each(MyTable.specs) AS spec WHERE spec.value = 'bar'"
出现此错误:SQLite error (1): no such table: json_each
如何将json1扩展名与System.Data.SQLite.Core一起使用?
答案 0 :(得分:0)
没有加载SQLite扩展程序。
紧接着:
_sqliteDb.Open();
我必须调用以下内容才能使json1
正常工作:
_sqliteDb.EnableExtensions(true);
_sqliteDb.LoadExtension("SQLite.Interop.dll", "sqlite3_json_init");
另请注意,功能是按连接注册的。