/// <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> /// <param name="flags">The flags associated with the parent connection object</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, SQLiteConnectionFlags flags) { SQLiteFunction f; List <SQLiteFunction> lFunctions = new List <SQLiteFunction>(); foreach (SQLiteFunctionAttribute pr in _registeredFunctions) { f = (SQLiteFunction)Activator.CreateInstance(pr._instanceType); f._base = sqlbase; f._flags = flags; 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); }
internal static SQLiteFunction[] BindFunctions(SQLiteBase sqlbase) { List <SQLiteFunction> list = new List <SQLiteFunction>(); foreach (SQLiteFunctionAttribute attribute in _registeredFunctions) { SQLiteFunction item = (SQLiteFunction)Activator.CreateInstance(attribute._instanceType); item._base = sqlbase; item._InvokeFunc = (attribute.FuncType == FunctionType.Scalar) ? new SQLiteCallback(item.ScalarCallback) : null; item._StepFunc = (attribute.FuncType == FunctionType.Aggregate) ? new SQLiteCallback(item.StepCallback) : null; item._FinalFunc = (attribute.FuncType == FunctionType.Aggregate) ? new SQLiteFinalCallback(item.FinalCallback) : null; item._CompareFunc = (attribute.FuncType == FunctionType.Collation) ? new SQLiteCollation(item.CompareCallback) : null; item._CompareFunc16 = (attribute.FuncType == FunctionType.Collation) ? new SQLiteCollation(item.CompareCallback16) : null; if (attribute.FuncType != FunctionType.Collation) { sqlbase.CreateFunction(attribute.Name, attribute.Arguments, item is SQLiteFunctionEx, item._InvokeFunc, item._StepFunc, item._FinalFunc); } else { sqlbase.CreateCollation(attribute.Name, item._CompareFunc, item._CompareFunc16); } list.Add(item); } SQLiteFunction[] array = new SQLiteFunction[list.Count]; list.CopyTo(array, 0); return(array); }
/// <summary> /// This function binds a user-defined functions to a connection. /// </summary> /// <param name="sqliteBase"> /// The <see cref="SQLiteBase" /> object instance associated with the /// <see cref="SQLiteConnection" /> that the function should be bound to. /// </param> /// <param name="functionAttribute"> /// The <see cref="SQLiteFunctionAttribute"/> object instance containing /// the metadata for the function to be bound. /// </param> /// <param name="function"> /// The <see cref="SQLiteFunction"/> object instance that implements the /// function to be bound. /// </param> /// <param name="flags"> /// The flags associated with the parent connection object. /// </param> internal static void BindFunction( SQLiteBase sqliteBase, SQLiteFunctionAttribute functionAttribute, SQLiteFunction function, SQLiteConnectionFlags flags ) { if (sqliteBase == null) { throw new ArgumentNullException("sqliteBase"); } if (functionAttribute == null) { throw new ArgumentNullException("functionAttribute"); } if (function == null) { throw new ArgumentNullException("function"); } FunctionType functionType = functionAttribute.FuncType; function._base = sqliteBase; function._flags = flags; function._InvokeFunc = (functionType == FunctionType.Scalar) ? new SQLiteCallback(function.ScalarCallback) : null; function._StepFunc = (functionType == FunctionType.Aggregate) ? new SQLiteCallback(function.StepCallback) : null; function._FinalFunc = (functionType == FunctionType.Aggregate) ? new SQLiteFinalCallback(function.FinalCallback) : null; function._CompareFunc = (functionType == FunctionType.Collation) ? new SQLiteCollation(function.CompareCallback) : null; function._CompareFunc16 = (functionType == FunctionType.Collation) ? new SQLiteCollation(function.CompareCallback16) : null; string name = functionAttribute.Name; if (functionType != FunctionType.Collation) { bool needCollSeq = (function is SQLiteFunctionEx); sqliteBase.CreateFunction( name, functionAttribute.Arguments, needCollSeq, function._InvokeFunc, function._StepFunc, function._FinalFunc); } else { sqliteBase.CreateCollation( name, function._CompareFunc, function._CompareFunc16); } }
/// <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> /// <param name="flags">The flags associated with the parent connection object</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, SQLiteConnectionFlags flags) { SQLiteFunction f; List<SQLiteFunction> lFunctions = new List<SQLiteFunction>(); foreach (SQLiteFunctionAttribute pr in _registeredFunctions) { f = (SQLiteFunction)Activator.CreateInstance(pr._instanceType); f._base = sqlbase; f._flags = flags; 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; }
/// <summary> /// This function binds a user-defined functions to a connection. /// </summary> /// <param name="sqliteBase"> /// The <see cref="SQLiteBase" /> object instance associated with the /// <see cref="SQLiteConnection" /> that the function should be bound to. /// </param> /// <param name="functionAttribute"> /// The <see cref="SQLiteFunctionAttribute"/> object instance containing /// the metadata for the function to be bound. /// </param> /// <param name="function"> /// The <see cref="SQLiteFunction"/> object instance that implements the /// function to be bound. /// </param> /// <param name="flags"> /// The flags associated with the parent connection object. /// </param> internal static void BindFunction( SQLiteBase sqliteBase, SQLiteFunctionAttribute functionAttribute, SQLiteFunction function, SQLiteConnectionFlags flags ) { if (sqliteBase == null) throw new ArgumentNullException("sqliteBase"); if (functionAttribute == null) throw new ArgumentNullException("functionAttribute"); if (function == null) throw new ArgumentNullException("function"); FunctionType functionType = functionAttribute.FuncType; function._base = sqliteBase; function._flags = flags; function._InvokeFunc = (functionType == FunctionType.Scalar) ? new SQLiteCallback(function.ScalarCallback) : null; function._StepFunc = (functionType == FunctionType.Aggregate) ? new SQLiteCallback(function.StepCallback) : null; function._FinalFunc = (functionType == FunctionType.Aggregate) ? new SQLiteFinalCallback(function.FinalCallback) : null; function._CompareFunc = (functionType == FunctionType.Collation) ? new SQLiteCollation(function.CompareCallback) : null; function._CompareFunc16 = (functionType == FunctionType.Collation) ? new SQLiteCollation(function.CompareCallback16) : null; string name = functionAttribute.Name; if (functionType != FunctionType.Collation) { bool needCollSeq = (function is SQLiteFunctionEx); sqliteBase.CreateFunction( name, functionAttribute.Arguments, needCollSeq, function._InvokeFunc, function._StepFunc, function._FinalFunc); } else { sqliteBase.CreateCollation( name, function._CompareFunc, function._CompareFunc16); } }
/// <summary> /// This function unbinds a user-defined functions from a connection. /// </summary> /// <param name="sqliteBase"> /// The <see cref="SQLiteBase" /> object instance associated with the /// <see cref="SQLiteConnection" /> that the function should be bound to. /// </param> /// <param name="functionAttribute"> /// The <see cref="SQLiteFunctionAttribute"/> object instance containing /// the metadata for the function to be bound. /// </param> /// <param name="function"> /// The <see cref="SQLiteFunction"/> object instance that implements the /// function to be bound. /// </param> /// <param name="flags"> /// The flags associated with the parent connection object. /// </param> /// <returns>Non-zero if the function was unbound.</returns> internal static bool UnbindFunction( SQLiteBase sqliteBase, SQLiteFunctionAttribute functionAttribute, SQLiteFunction function, SQLiteConnectionFlags flags /* NOT USED */ ) { if (sqliteBase == null) throw new ArgumentNullException("sqliteBase"); if (functionAttribute == null) throw new ArgumentNullException("functionAttribute"); if (function == null) throw new ArgumentNullException("function"); FunctionType functionType = functionAttribute.FuncType; string name = functionAttribute.Name; if (functionType != FunctionType.Collation) { bool needCollSeq = (function is SQLiteFunctionEx); return sqliteBase.CreateFunction( name, functionAttribute.Arguments, needCollSeq, null, null, null, false) == SQLiteErrorCode.Ok; } else { return sqliteBase.CreateCollation( name, null, null, false) == SQLiteErrorCode.Ok; } }