在 System.Data.SQLite 中创建/使用用户定义的函数? [英] Create/Use User-defined functions in System.Data.SQLite?

查看:27
本文介绍了在 System.Data.SQLite 中创建/使用用户定义的函数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

用户定义的函数 &整理序列完全支持用户定义的函数和整理序列意味着在很多情况下,如果 SQLite 没有功能,您可以用自己喜欢的 .NET 语言编写它.编写 UDF 和整理序列从未如此简单

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

我在 C# SQLite ADO.NET 提供程序在这里找到,并且在理解有关如何实现/使用用户定义函数的文档时遇到问题.

I spotted this bit on the C# SQLite ADO.NET provider l found here, and was having problems understanding the documentation on how to implement/use user-defined functions.

谁能为这个迷路的新手解释如何做,或提供任何可行的例子?

Could anyone explain how to, or provide any working examples for this lost newbie?

推荐答案

Robert Simpson 有一个很好的 REGEX 函数示例,您可以在 SQLite 查询中使用它:

Robert Simpson has a great example of a REGEX function you can use in your sqlite queries:

// 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'

这篇关于在 System.Data.SQLite 中创建/使用用户定义的函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆