internal static bool UnbindFunction(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 funcType = functionAttribute.FuncType; string name = functionAttribute.Name; if (funcType == FunctionType.Collation) { return(sqliteBase.CreateCollation(name, null, null, false) == SQLiteErrorCode.Ok); } bool flag = function is SQLiteFunctionEx; return(sqliteBase.CreateFunction(name, functionAttribute.Arguments, flag, null, null, null, false) == SQLiteErrorCode.Ok); }
public static void RegisterFunction(string name, int argumentCount, FunctionType functionType, Type instanceType, Delegate callback1, Delegate callback2) { SQLiteFunctionAttribute sQLiteFunctionAttribute = new SQLiteFunctionAttribute(name, argumentCount, functionType) { InstanceType = instanceType, Callback1 = callback1, Callback2 = callback2 }; SQLiteFunction.ReplaceFunction(sQLiteFunctionAttribute, null); }
public static void RegisterFunction(Type typ) { object[] customAttributes = typ.GetCustomAttributes(typeof(SQLiteFunctionAttribute), false); for (int i = 0; i < (int)customAttributes.Length; i++) { SQLiteFunctionAttribute sQLiteFunctionAttribute = customAttributes[i] as SQLiteFunctionAttribute; if (sQLiteFunctionAttribute != null) { SQLiteFunction.RegisterFunction(sQLiteFunctionAttribute.Name, sQLiteFunctionAttribute.Arguments, sQLiteFunctionAttribute.FuncType, typ, sQLiteFunctionAttribute.Callback1, sQLiteFunctionAttribute.Callback2); } } }
internal static bool UnbindAllFunctions(SQLiteBase sqlbase, SQLiteConnectionFlags flags, bool registered) { SQLiteFunction sQLiteFunction; if (sqlbase == null) { return(false); } IDictionary <SQLiteFunctionAttribute, SQLiteFunction> functions = sqlbase.Functions; if (functions == null) { return(false); } bool flag = true; if (!registered) { functions = new Dictionary <SQLiteFunctionAttribute, SQLiteFunction>(functions); foreach (KeyValuePair <SQLiteFunctionAttribute, SQLiteFunction> function in functions) { SQLiteFunctionAttribute key = function.Key; if (key == null) { continue; } SQLiteFunction value = function.Value; if (value == null || !SQLiteFunction.UnbindFunction(sqlbase, key, value, flags)) { flag = false; } else { sqlbase.Functions.Remove(key); } } } else { foreach (KeyValuePair <SQLiteFunctionAttribute, object> _registeredFunction in SQLiteFunction._registeredFunctions) { SQLiteFunctionAttribute sQLiteFunctionAttribute = _registeredFunction.Key; if (sQLiteFunctionAttribute == null || functions.TryGetValue(sQLiteFunctionAttribute, out sQLiteFunction) && sQLiteFunction != null && SQLiteFunction.UnbindFunction(sqlbase, sQLiteFunctionAttribute, sQLiteFunction, flags)) { continue; } flag = false; } } return(flag); }
private static bool ReplaceFunction(SQLiteFunctionAttribute at, object newValue) { object obj; if (!SQLiteFunction._registeredFunctions.TryGetValue(at, out obj)) { SQLiteFunction._registeredFunctions.Add(at, newValue); return(false); } IDisposable disposable = obj as IDisposable; if (disposable != null) { disposable.Dispose(); disposable = null; } SQLiteFunction._registeredFunctions[at] = newValue; return(true); }
private static bool CreateFunction(SQLiteFunctionAttribute functionAttribute, out SQLiteFunction function) { if (functionAttribute == null) { function = null; return(false); } if (functionAttribute.Callback1 != null || functionAttribute.Callback2 != null) { function = new SQLiteDelegateFunction(functionAttribute.Callback1, functionAttribute.Callback2); return(true); } if (functionAttribute.InstanceType == null) { function = null; return(false); } function = (SQLiteFunction)Activator.CreateInstance(functionAttribute.InstanceType); return(true); }
internal static IDictionary <SQLiteFunctionAttribute, SQLiteFunction> BindFunctions(SQLiteBase sqlbase, SQLiteConnectionFlags flags) { SQLiteFunction sQLiteFunction; IDictionary <SQLiteFunctionAttribute, SQLiteFunction> sQLiteFunctionAttributes = new Dictionary <SQLiteFunctionAttribute, SQLiteFunction>(); foreach (KeyValuePair <SQLiteFunctionAttribute, object> _registeredFunction in SQLiteFunction._registeredFunctions) { SQLiteFunctionAttribute key = _registeredFunction.Key; if (key == null) { continue; } if (!SQLiteFunction.CreateFunction(key, out sQLiteFunction)) { sQLiteFunctionAttributes[key] = null; } else { SQLiteFunction.BindFunction(sqlbase, key, sQLiteFunction, flags); sQLiteFunctionAttributes[key] = sQLiteFunction; } } return(sQLiteFunctionAttributes); }
//[FileIOPermission(SecurityAction.Assert, AllFiles=FileIOPermissionAccess.PathDiscovery)] static SQLiteFunction() { Type[] types; SQLiteFunction._registeredFunctions = new Dictionary <SQLiteFunctionAttribute, object>(); try { if (UnsafeNativeMethods.GetSettingValue("No_SQLiteFunctions", null) == null) { Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies(); int length = (int)assemblies.Length; AssemblyName name = Assembly.GetExecutingAssembly().GetName(); for (int i = 0; i < length; i++) { bool flag = false; try { AssemblyName[] referencedAssemblies = assemblies[i].GetReferencedAssemblies(); int num = (int)referencedAssemblies.Length; int num1 = 0; while (num1 < num) { if (referencedAssemblies[num1].Name != name.Name) { num1++; } else { flag = true; break; } } if (flag) { types = assemblies[i].GetTypes(); } else { goto Label0; } } catch (ReflectionTypeLoadException reflectionTypeLoadException) { types = reflectionTypeLoadException.Types; } int length1 = (int)types.Length; for (int j = 0; j < length1; j++) { if (types[j] != null) { object[] customAttributes = types[j].GetCustomAttributes(typeof(SQLiteFunctionAttribute), false); int length2 = (int)customAttributes.Length; for (int k = 0; k < length2; k++) { SQLiteFunctionAttribute sQLiteFunctionAttribute = customAttributes[k] as SQLiteFunctionAttribute; if (sQLiteFunctionAttribute != null) { sQLiteFunctionAttribute.InstanceType = types[j]; SQLiteFunction.ReplaceFunction(sQLiteFunctionAttribute, null); } } } } Label0: break; } } } catch { } }
internal static void BindFunction(SQLiteBase sqliteBase, SQLiteFunctionAttribute functionAttribute, SQLiteFunction function, SQLiteConnectionFlags flags) { SQLiteCallback sQLiteCallback; SQLiteCallback sQLiteCallback1; SQLiteFinalCallback sQLiteFinalCallback; SQLiteCollation sQLiteCollation; SQLiteCollation sQLiteCollation1; if (sqliteBase == null) { throw new ArgumentNullException("sqliteBase"); } if (functionAttribute == null) { throw new ArgumentNullException("functionAttribute"); } if (function == null) { throw new ArgumentNullException("function"); } FunctionType funcType = functionAttribute.FuncType; function._base = sqliteBase; function._flags = flags; SQLiteFunction sQLiteFunction = function; if (funcType == FunctionType.Scalar) { sQLiteCallback = new SQLiteCallback(function.ScalarCallback); } else { sQLiteCallback = null; } sQLiteFunction._InvokeFunc = sQLiteCallback; SQLiteFunction sQLiteFunction1 = function; if (funcType == FunctionType.Aggregate) { sQLiteCallback1 = new SQLiteCallback(function.StepCallback); } else { sQLiteCallback1 = null; } sQLiteFunction1._StepFunc = sQLiteCallback1; SQLiteFunction sQLiteFunction2 = function; if (funcType == FunctionType.Aggregate) { sQLiteFinalCallback = new SQLiteFinalCallback(function.FinalCallback); } else { sQLiteFinalCallback = null; } sQLiteFunction2._FinalFunc = sQLiteFinalCallback; SQLiteFunction sQLiteFunction3 = function; if (funcType == FunctionType.Collation) { sQLiteCollation = new SQLiteCollation(function.CompareCallback); } else { sQLiteCollation = null; } sQLiteFunction3._CompareFunc = sQLiteCollation; SQLiteFunction sQLiteFunction4 = function; if (funcType == FunctionType.Collation) { sQLiteCollation1 = new SQLiteCollation(function.CompareCallback16); } else { sQLiteCollation1 = null; } sQLiteFunction4._CompareFunc16 = sQLiteCollation1; string name = functionAttribute.Name; if (funcType == FunctionType.Collation) { sqliteBase.CreateCollation(name, function._CompareFunc, function._CompareFunc16, true); return; } bool flag = function is SQLiteFunctionEx; sqliteBase.CreateFunction(name, functionAttribute.Arguments, flag, function._InvokeFunc, function._StepFunc, function._FinalFunc, true); }
internal abstract bool UnbindFunction(SQLiteFunctionAttribute functionAttribute, SQLiteConnectionFlags flags);
internal abstract void BindFunction(SQLiteFunctionAttribute functionAttribute, SQLiteFunction function, SQLiteConnectionFlags flags);