我有一个与UWP数据库一起工作的Sqlite项目。我将sqlite-net-pcl添加到我的参考资料中。我想在REGEXP查询中使用select,但它给了我no such function: REGEXP。我搜索了错误,但是结果是关于没有在这里定义的SQLiteFunction的。我该怎么办?
发布于 2017-02-14 15:32:16
如果您可以使用类似于SQLite PCL的功能,您可以执行以下操作(可能与其他PCL一起工作,但不确定):
using System;
using SQLitePCL.pretty;
using System.Text.RegularExpressions;
namespace TestSqlite
{
class Program
{
static void Main(string[] args)
{
Func<ISQLiteValue, ISQLiteValue, ISQLiteValue> regexFunc =
(ISQLiteValue val, ISQLiteValue regexStr) =>
{
if (Regex.IsMatch(Convert.ToString(val), Convert.ToString(regexStr)))
return true.ToSQLiteValue();
return false.ToSQLiteValue();
};
SQLitePCL.Batteries.Init();
SQLiteDatabaseConnection _dbcon = SQLiteDatabaseConnectionBuilder
.InMemory
.WithScalarFunc("REGEXP", regexFunc)
.Build();
string sql = "CREATE TABLE foo (a int, b text);";
_dbcon.ExecuteAll(sql);
_dbcon.ExecuteAll(@"INSERT INTO foo VALUES (1, 'this is me');
INSERT INTO foo VALUES (2, 'that is me');
INSERT INTO foo VALUES (3, 'he is me');");
sql = "SELECT * FROM foo where '\\w{4} is me' REGEXP b;";
foreach (var row in _dbcon.Query(sql)) { Console.WriteLine(row[1].ToString()); }
}
}
}https://stackoverflow.com/questions/40287330
复制相似问题