'Declaration Public MustInherit Class SQLiteAggregateFunction Inherits SQLiteFunction Implements System.IDisposable
public abstract class SQLiteAggregateFunction : SQLiteFunction, System.IDisposable
'Declaration Public MustInherit Class SQLiteAggregateFunction Inherits SQLiteFunction Implements System.IDisposable
public abstract class SQLiteAggregateFunction : SQLiteFunction, System.IDisposable
Use this class to derive classes for user-defined aggregate functions from it.
The result of an aggregate function is a scalar object, but its value is accumulated when processing query result records. It is executed for each record, and its result can be accumulated. Average, Summ, or Count are the examples of such functions.
To register the user-defined aggregate funtion, create the class, derived from SQLiteAggregateFunction and pass its name and number of arguments to the base class constructor.
You should also override Step and Complete methods. Step method should implement the way of acumulating and storing result, and Complete method should process the accumulated value after all records were processed.
public class MyFunction : SQLiteAggregateFunction { private long count; public MyFunction() : base("Average", 1) { count = 0; } protected override void Step(object[] args, SQLiteConnection connection, ref object contextData) { if (contextData == null) contextData = (Int64)0; contextData = (Int64)contextData + (Int64)args[0]; count++; } protected override object Complete(SQLiteConnection connection, object contextData) { return (double)((long)contextData / count); } } ... SQLiteConnection sqLiteConnection = new SQLiteConnection(@"Data Source=D:\SQLite\test.db"); sqLiteConnection.Open(); MyFunction function = new MyFunction(); sqLiteConnection.RegisterFunction(function); SQLiteCommand command = new SQLiteCommand("select Average(deptno) from Dept", sqLiteConnection); double result = (double)command.ExecuteScalar(); sqLiteConnection.UnRegisterFunction(function); sqLiteConnection.Close();
System.Object
Devart.Data.SQLite.SQLiteFunction
Devart.Data.SQLite.SQLiteAggregateFunction
Devart.Data.SQLite.SQLiteAggregateFunction<TResult>
Devart.Data.SQLite.SQLiteAggregateFunction<T1,TResult>
Devart.Data.SQLite.SQLiteAggregateFunction<T1,T2,TResult>
Devart.Data.SQLite.SQLiteAggregateFunction<T1,T2,T3,TResult>
Devart.Data.SQLite.SQLiteAggregateFunction<T1,T2,T3,T4,TResult>
Devart.Data.SQLite.SQLiteAggregateFunction<T1,T2,T3,T4,T5,TResult>
Devart.Data.SQLite.SQLiteAggregateFunction<T1,T2,T3,T4,T5,T6,TResult>
Devart.Data.SQLite.SQLiteAggregateFunction<T1,T2,T3,T4,T5,T6,T7,TResult>
Devart.Data.SQLite.SQLiteAggregateFunction<T1,T2,T3,T4,T5,T6,T7,T8,TResult>
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