in

System.Data.SQLite

An open source ADO.NET provider for the SQLite database engine

REGEXP function

Last post 02-26-2010 9:14 AM by ashkulz. 10 replies.
Page 1 of 1 (11 items)
Sort Posts: Previous Next
  • 06-16-2006 8:03 AM

    • jeff
    • Top 500 Contributor
    • Joined on 06-16-2006
    • Posts 7

    REGEXP function

    Would it be possible to add a REGEXP function to the provider?  The SQLIteSpy tool process REGEXP statements, but SQLLite by itself does not.  I think they have done this by adding a user defined functoin, but I don't know how to do this either.

    Thanks

    Jeff
  • 07-01-2006 8:34 PM In reply to

    Re: REGEXP function

    Can you show me some examples of how you use it in SQLiteSpy?

    Robert

     

  • 07-01-2006 9:06 PM In reply to

    Re: REGEXP function

    Here's a quickie example I just made.  Cut and paste it into your code:

    [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]));
     
    }
    }

    And an example SQL statement:  SELECT * FROM Foo WHERE Foo.Name REGEXP '$bar'

     

  • 07-07-2006 5:03 PM In reply to

    • jeff
    • Top 500 Contributor
    • Joined on 06-16-2006
    • Posts 7

    Re: REGEXP function

    Wow!  It works.  That is an amazingly small amount of code to do such a cool and valuable thing.  Thanks.

    Jeff
  • 01-22-2009 9:15 AM In reply to

    • louis
    • Not Ranked
    • Joined on 01-22-2009
    • Posts 2

    Re: REGEXP function

    Hi!

    Do you happen to know how we could do the same in VB.Net? Here is what i tried, i get an error on the line <SQLiteFunction(...  for Name, Arguments and FuncType ex: Name "Arguments" is not defined

    Thank you!

     

    Imports System.Data.SQLite

    <SQLiteFunction(Name = "REGEXP", Arguments = 2, FuncType = FunctionType.Scalar)> _
    Public Class MyRegEx
        Inherits SQLite.SQLiteFunction

        Public Overrides Function Invoke(ByVal args() As Object) As Object
            Return System.Text.RegularExpressions.Regex.IsMatch(Convert.ToString(args(1)), Convert.ToString(args(0)))
        End Function
    End Class

  • 01-22-2009 9:29 AM In reply to

    • louis
    • Not Ranked
    • Joined on 01-22-2009
    • Posts 2

    Re: REGEXP function

    oops ;) i searched a bit more in the forums  and found the answer

    so the line should be:

     <SQLiteFunction(Name:="REGEXP", Arguments:=2, FuncType:= FunctionType.Scalar)> _

     

  • 03-28-2009 8:59 PM In reply to

    • Scott
    • Not Ranked
    • Joined on 03-29-2009
    • Posts 1

    Re: REGEXP function

     Is there any way to make it so you can do "SELECT line  FROM table WHERE 'line here' REGEXP line"?

    I currently do this with LIKE but would rather have more specific wildcards in the table.

  • 12-14-2009 8:44 PM In reply to

    • SC-A9
    • Top 50 Contributor
    • Joined on 10-22-2006
    • Posts 21

    Re: REGEXP function

    I made a console app and created a regex class in a different namespace (same project binary though), running my code makes it say

     

    What did I do wrong?

     Thanks.

    An unhandled exception of type 'System.Data.SQLite.SQLiteException' occurred in System.Data.SQLite.dll
    Additional information: SQLite error
    near "REGEX": syntax error

        static void Main( string[ args )
            {
                SQLiteConnection ObjConnection = new SQLiteConnection( "Data Source=TestFoods.db;" );
                SQLiteCommand ObjCommand = new SQLiteCommand( "SELECT * FROM Foods Where Foods.Name REGEX '$butter' " , ObjConnection );
                ObjCommand.CommandType = CommandType.Text;
                SQLiteDataAdapter ObjDataAdapter = new SQLiteDataAdapter( ObjCommand );
                DataSet dataSet = new DataSet();
                ObjDataAdapter.Fill( dataSet , "Foods" );
                }

  • 12-22-2009 12:05 PM In reply to

    Re: REGEXP function

     i could really use this.

  • 02-17-2010 11:00 AM In reply to

    • Alfred
    • Not Ranked
    • Joined on 02-17-2010
    • Posts 1

    Re: REGEXP function

    I've made a Decimal to Binary Convert user defined Function for SQLite , how to add it to Sqlite ?? public string ConvertToBinary(int num) { return Convert.ToString(num, 2).PadLeft(5, '0'); } is there any way i can add this to sqlite?? or is there any existing function in sqlite that does this??
  • 02-26-2010 9:14 AM In reply to

    • ashkulz
    • Not Ranked
    • Joined on 02-26-2010
    • Mumbai, India
    • Posts 1

    I've added support for implementing this operator in SQLite itself using pcre (which is much faster, and also with caching of the regex) -- the patch files I've attached are for building pcre with vs2008 and against System.Data.SQLite 1.0.65.0. It adds around 150kB to the compiled DLL.

    Hope someone finds it useful -- I don't know whether Robert will want to include it in the official release, although I do hope he will :-)

Page 1 of 1 (11 items)
Powered by Community Server (Commercial Edition), by Telligent Systems