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

SQLiteScalarFunction Class
Base class for user-defined scalar functions.
Syntax
'Declaration
 
Public MustInherit Class SQLiteScalarFunction 
   Inherits SQLiteFunction
   Implements 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
See Also