C# Class Mono.Data.Sqlite.SqliteFunction

This abstract class is designed to handle user-defined functions easily. An instance of the derived class is made for each connection to the database.
Although there is one instance of a class derived from SqliteFunction per database connection, the derived class has no access to the underlying connection. This is necessary to deter implementers from thinking it would be a good idea to make database calls during processing. It is important to distinguish between a per-connection instance, and a per-SQL statement context. One instance of this class services all SQL statements being stepped through on that connection, and there can be many. One should never store per-statement information in member variables of user-defined function classes. For aggregate functions, always create and store your per-statement data in the contextData object on the 1st step. This data will be automatically freed for you (and Dispose() called if the item supports IDisposable) when the statement completes.
Inheritance: IDisposable
Afficher le fichier Open project: rubenv/tripod Class Usage Examples

Méthodes publiques

Méthode Description
Compare ( string param1, string param2 ) : int

User-defined collation sequences override this method to provide a custom string sorting algorithm.

Dispose ( ) : void

Disposes of any active contextData variables that were not automatically cleaned up. Sometimes this can happen if someone closes the connection while a DataReader is open.

Final ( object contextData ) : object

Aggregate functions override this method to finish their aggregate processing.

If you implemented your aggregate function properly, you've been recording and keeping track of your data in the contextData object provided, and now at this stage you should have all the information you need in there to figure out what to return. NOTE: It is possible to arrive here without receiving a previous call to Step(), in which case the contextData will be null. This can happen when no rows were returned. You can either return null, or 0 or some other custom return value if that is the case.

Invoke ( object args ) : object

Scalar functions override this method to do their magic.

Parameters passed to functions have only an affinity for a certain data type, there is no underlying schema available to force them into a certain type. Therefore the only types you will ever see as parameters are DBNull.Value, Int64, Double, String or byte[] array.

RegisterFunction ( Type typ ) : void

Manual method of registering a function. The type must still have the SqliteFunctionAttributes in order to work properly, but this is a workaround for the Compact Framework where enumerating assemblies is not currently supported.

Step ( object args, int stepNumber, object &contextData ) : void

Aggregate functions override this method to do their magic.

Typically you'll be updating whatever you've placed in the contextData field and returning as quickly as possible.

Méthodes protégées

Méthode Description
Dispose ( bool disposing ) : void

Placeholder for a user-defined disposal routine

SqliteFunction ( ) : System

Internal constructor, initializes the function's internal variables.

Private Methods

Méthode Description
BindFunctions ( SqliteBase sqlbase ) : Mono.Data.Sqlite.SqliteFunction[]

Called by SqliteBase derived classes, this function binds all user-defined functions to a connection. It is done this way so that all user-defined functions will access the database using the same encoding scheme as the connection (UTF-8 or UTF-16).

CompareCallback ( int len1, IntPtr ptr1, int len2, IntPtr ptr2 ) : int

Internal collation sequence function, which wraps up the raw string pointers and executes the Compare() virtual function.

ConvertParams ( int nArgs, IntPtr argsptr ) : object[]

Converts an IntPtr array of context arguments to an object array containing the resolved parameters the pointers point to.

Parameters passed to functions have only an affinity for a certain data type, there is no underlying schema available to force them into a certain type. Therefore the only types you will ever see as parameters are DBNull.Value, Int64, Double, String or byte[] array.

FinalCallback ( IntPtr context ) : void

An internal aggregate Final function callback, which wraps the context pointer and calls the virtual Final() method.

ScalarCallback ( IntPtr context, int nArgs, IntPtr argsptr ) : void

Internal scalar callback function, which wraps the raw context pointer and calls the virtual Invoke() method.

SetReturnValue ( IntPtr context, object returnValue ) : void

Takes the return value from Invoke() and Final() and figures out how to return it to Sqlite's context.

StepCallback ( IntPtr context, int nArgs, IntPtr argsptr ) : void

The internal aggregate Step function callback, which wraps the raw context pointer and calls the virtual Step() method.

This function takes care of doing the lookups and getting the important information put together to call the Step() function. That includes pulling out the user's contextData and updating it after the call is made. We use a sorted list for this so binary searches can be done to find the data.

Method Details

Compare() public méthode

User-defined collation sequences override this method to provide a custom string sorting algorithm.
public Compare ( string param1, string param2 ) : int
param1 string The first string to compare
param2 string The second strnig to compare
Résultat int

Dispose() public méthode

Disposes of any active contextData variables that were not automatically cleaned up. Sometimes this can happen if someone closes the connection while a DataReader is open.
public Dispose ( ) : void
Résultat void

Dispose() protected méthode

Placeholder for a user-defined disposal routine
protected Dispose ( bool disposing ) : void
disposing bool True if the object is being disposed explicitly
Résultat void

Final() public méthode

Aggregate functions override this method to finish their aggregate processing.
If you implemented your aggregate function properly, you've been recording and keeping track of your data in the contextData object provided, and now at this stage you should have all the information you need in there to figure out what to return. NOTE: It is possible to arrive here without receiving a previous call to Step(), in which case the contextData will be null. This can happen when no rows were returned. You can either return null, or 0 or some other custom return value if that is the case.
public Final ( object contextData ) : object
contextData object Your own assigned contextData, provided for you so you can return your final results.
Résultat object

Invoke() public méthode

Scalar functions override this method to do their magic.
Parameters passed to functions have only an affinity for a certain data type, there is no underlying schema available to force them into a certain type. Therefore the only types you will ever see as parameters are DBNull.Value, Int64, Double, String or byte[] array.
public Invoke ( object args ) : object
args object The arguments for the command to process
Résultat object

RegisterFunction() public static méthode

Manual method of registering a function. The type must still have the SqliteFunctionAttributes in order to work properly, but this is a workaround for the Compact Framework where enumerating assemblies is not currently supported.
public static RegisterFunction ( Type typ ) : void
typ System.Type The type of the function to register
Résultat void

SqliteFunction() protected méthode

Internal constructor, initializes the function's internal variables.
protected SqliteFunction ( ) : System
Résultat System

Step() public méthode

Aggregate functions override this method to do their magic.
Typically you'll be updating whatever you've placed in the contextData field and returning as quickly as possible.
public Step ( object args, int stepNumber, object &contextData ) : void
args object The arguments for the command to process
stepNumber int The 1-based step number. This is incrememted each time the step method is called.
contextData object A placeholder for implementers to store contextual data pertaining to the current context.
Résultat void