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
Esempio n. 1
0
 internal abstract CollationSequence GetCollationSequence(SqliteFunction func, IntPtr context);
Esempio n. 2
0
 internal override CollationSequence GetCollationSequence(SqliteFunction func, SqliteContextHandle context)
 {
     throw new NotImplementedException();
 }
Esempio n. 3
0
    /// <summary>
    /// 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).
    /// </summary>
    /// <remarks>
    /// The wrapper functions that interop with SQLite will create a unique cookie value, which internally is a pointer to
    /// all the wrapped callback functions.  The interop function uses it to map CDecl callbacks to StdCall callbacks.
    /// </remarks>
    /// <param name="sqlbase">The base object on which the functions are to bind</param>
    /// <returns>Returns an array of functions which the connection object should retain until the connection is closed.</returns>
    internal static SqliteFunction[] BindFunctions(SQLiteBase sqlbase)
    {
      SqliteFunction f;
      List<SqliteFunction> lFunctions = new List<SqliteFunction>();

      foreach (SqliteFunctionAttribute pr in _registeredFunctions)
      {
        f = (SqliteFunction)Activator.CreateInstance(pr._instanceType);
        f._base = sqlbase;
        f._InvokeFunc = (pr.FuncType == FunctionType.Scalar) ? new SQLiteCallback(f.ScalarCallback) : null;
        f._StepFunc = (pr.FuncType == FunctionType.Aggregate) ? new SQLiteCallback(f.StepCallback) : null;
        f._FinalFunc = (pr.FuncType == FunctionType.Aggregate) ? new SQLiteFinalCallback(f.FinalCallback) : null;
        f._CompareFunc = (pr.FuncType == FunctionType.Collation) ? new SQLiteCollation(f.CompareCallback) : null;
        f._CompareFunc16 = (pr.FuncType == FunctionType.Collation) ? new SQLiteCollation(f.CompareCallback16) : null;

        if (pr.FuncType != FunctionType.Collation)
          sqlbase.CreateFunction(pr.Name, pr.Arguments, (f is SqliteFunctionEx), f._InvokeFunc, f._StepFunc, f._FinalFunc);
        else
          sqlbase.CreateCollation(pr.Name, f._CompareFunc, f._CompareFunc16);


        lFunctions.Add(f);
      }

      SqliteFunction[] arFunctions = new SqliteFunction[lFunctions.Count];
      lFunctions.CopyTo(arFunctions, 0);

      return arFunctions;
    }
Esempio n. 4
0
    internal override CollationSequence GetCollationSequence(SqliteFunction func, IntPtr context)
    {
#if !SQLITE_STANDARD
      CollationSequence seq = new CollationSequence();
      int len;
      int type;
      int enc;
      IntPtr p = UnsafeNativeMethods.sqlite3_context_collseq(context, out type, out enc, out len);

      if (p != null) seq.Name = UTF8ToString(p, len);
      seq.Type = (CollationTypeEnum)type;
      seq._func = func;
      seq.Encoding = (CollationEncodingEnum)enc;

      return seq;
#else
      throw new NotImplementedException();
#endif
    }
Esempio n. 5
0
 internal abstract CollationSequence GetCollationSequence(SqliteFunction func, IntPtr context);
Esempio n. 6
0
 internal abstract CollationSequence GetCollationSequence(SqliteFunction func, SqliteContextHandle context);
Esempio n. 7
0
 internal override CollationSequence GetCollationSequence(SqliteFunction func, SqliteContextHandle context)
 {
     throw new NotImplementedException();
 }