dotConnect for SQLite Documentation
Devart.Data.SQLite Namespace / SQLiteScalarFunction Class
Members Example

In This Topic
    SQLiteScalarFunction Class
    In This Topic
    Base class for user-defined scalar functions.
    Syntax
    'Declaration
     
    Public MustInherit Class SQLiteScalarFunction 
       Inherits SQLiteFunction
       Implements System.IDisposable 
    public abstract class SQLiteScalarFunction : SQLiteFunction, System.IDisposable  
    Remarks

    Use this class to derive classes for user-defined scalar functions from it.

    The scalar function is a simple function, that returns a scalar value and is executed once when called.

    To register the user-defined scalar funtion, create the class, derived from SQLiteScalarFunction and pass its name and number of arguments to the base class constructor.

    You should also override the Invoke method, which should implement the function actions.

    Example
    Here is an example of creating and using of the function, that calculates the square root.
    public class MyFunction : SQLiteScalarFunction {
    
            public MyFunction()
            : base("Sqrt", 1) {
            }
    
            protected override object Execute(object[] args, SQLiteConnection connection) {
    
                    return Math.Sqrt(Convert.ToDouble(args[0]));
            }
    }
    
    ...
    
    SQLiteConnection sqLiteConnection = new SQLiteConnection(@"Data Source=D:\SQLite\test.db");
          sqLiteConnection.Open();
    MyFunction function = new MyFunction();
          sqLiteConnection.RegisterFunction(function);
    SQLiteCommand command = new SQLiteCommand("select sqrt(9.0)", sqLiteConnection);
    double result = (double)command.ExecuteScalar();
          sqLiteConnection.UnRegisterFunction(function);
          sqLiteConnection.Close();
    Inheritance Hierarchy
    Requirements

    Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

    See Also