C# 在 System.Data.SQLite 中创建/使用用户定义的函数?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/172735/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Create/Use User-defined functions in System.Data.SQLite?
提问by Ashlocke
User-Defined Functions & Collating Sequences Full support for user-defined functions and collating sequences means that in many cases if SQLite doesn't have a feature, you can write it yourself in your favorite .NET language. Writing UDF's and collating sequences has never been easier
用户定义的函数和整理序列 完全支持用户定义的函数和整理序列意味着在很多情况下,如果 SQLite 没有功能,您可以用自己喜欢的 .NET 语言编写它。编写 UDF 和整理序列从未如此简单
I spotted this bit on the C# SQLite ADO.NETprovider l found here, and was having problems understanding the documentation on how to implement/use user-defined functions.
我在此处找到的 C# SQLite ADO.NET提供程序上发现了这一点,并且在理解有关如何实现/使用用户定义函数的文档时遇到了问题。
Could anyone explain how to, or provide any working examples for this lost newbie?
任何人都可以解释如何,或为这个迷路的新手提供任何可行的例子吗?
采纳答案by Jarrod Dixon
Robert Simpson has a great example of a REGEX function you can use in your sqlite queries:
Robert Simpson 有一个很好的 REGEX 函数示例,您可以在 SQLite 查询中使用它:
// taken from http://sqlite.phxsoftware.com/forums/p/348/1457.aspx#1457
[SQLiteFunction(Name = "REGEXP", Arguments = 2, FuncType = FunctionType.Scalar)]
class MyRegEx : SQLiteFunction
{
public override object Invoke(object[] args)
{
return System.Text.RegularExpressions.Regex.IsMatch(Convert.ToString(args[1]),Convert.ToString(args[0]));
}
}
// example SQL: SELECT * FROM Foo WHERE Foo.Name REGEXP '$bar'