Esempio n. 1
0
        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);
        }
Esempio n. 2
0
        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);
        }
Esempio n. 3
0
        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);
        }
Esempio n. 4
0
        //[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
            {
            }
        }
Esempio n. 5
0
 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);
 }
Esempio n. 6
0
        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 override void Open(string strFilename, string vfsName, SQLiteConnectionFlags connectionFlags, SQLiteOpenFlagsEnum openFlags, int maxPoolSize, bool usePool)
        {
            SQLiteErrorCode sQLiteErrorCode;

            if (this._sql != null)
            {
                this.Close(true);
            }
            if (this._sql != null)
            {
                throw new SQLiteException("connection handle is still active");
            }
            this._usePool  = usePool;
            this._fileName = strFilename;
            this._flags    = connectionFlags;
            if (usePool)
            {
                this._sql = SQLiteConnectionPool.Remove(strFilename, maxPoolSize, out this._poolVersion);
                SQLiteConnectionHandle sQLiteConnectionHandle = this._sql;
                object[] objArray = new object[] { typeof(SQLite3_UTF16), strFilename, vfsName, connectionFlags, openFlags, maxPoolSize, usePool, this._poolVersion };
                SQLiteConnection.OnChanged(null, new ConnectionEventArgs(SQLiteConnectionEventType.OpenedFromPool, null, null, null, null, sQLiteConnectionHandle, strFilename, objArray));
            }
            if (this._sql == null)
            {
                try
                {
                }
                finally
                {
                    IntPtr zero = IntPtr.Zero;
                    int    num  = ((connectionFlags & SQLiteConnectionFlags.NoExtensionFunctions) != SQLiteConnectionFlags.NoExtensionFunctions ? 1 : 0);
                    if (vfsName != null || num != 0)
                    {
                        sQLiteErrorCode = UnsafeNativeMethods.sqlite3_open16_interop(SQLiteConvert.ToUTF8(strFilename), SQLiteConvert.ToUTF8(vfsName), openFlags, num, ref zero);
                    }
                    else
                    {
                        if ((openFlags & SQLiteOpenFlagsEnum.Create) != SQLiteOpenFlagsEnum.Create && !File.Exists(strFilename))
                        {
                            throw new SQLiteException(SQLiteErrorCode.CantOpen, strFilename);
                        }
                        if (vfsName != null)
                        {
                            CultureInfo currentCulture = CultureInfo.CurrentCulture;
                            object[]    objArray1      = new object[] { vfsName };
                            throw new SQLiteException(SQLiteErrorCode.CantOpen, HelperMethods.StringFormat(currentCulture, "cannot open using UTF-16 and VFS \"{0}\": need interop assembly", objArray1));
                        }
                        sQLiteErrorCode = UnsafeNativeMethods.sqlite3_open16(strFilename, ref zero);
                    }
                    if (sQLiteErrorCode != SQLiteErrorCode.Ok)
                    {
                        throw new SQLiteException(sQLiteErrorCode, null);
                    }
                    this._sql = new SQLiteConnectionHandle(zero, true);
                }
                lock (this._sql)
                {
                }
                SQLiteConnectionHandle sQLiteConnectionHandle1 = this._sql;
                object[] objArray2 = new object[] { typeof(SQLite3_UTF16), strFilename, vfsName, connectionFlags, openFlags, maxPoolSize, usePool };
                SQLiteConnection.OnChanged(null, new ConnectionEventArgs(SQLiteConnectionEventType.NewCriticalHandle, null, null, null, null, sQLiteConnectionHandle1, strFilename, objArray2));
            }
            if ((connectionFlags & SQLiteConnectionFlags.NoBindFunctions) != SQLiteConnectionFlags.NoBindFunctions)
            {
                if (this._functions == null)
                {
                    this._functions = new Dictionary <SQLiteFunctionAttribute, SQLiteFunction>();
                }
                foreach (KeyValuePair <SQLiteFunctionAttribute, SQLiteFunction> value in SQLiteFunction.BindFunctions(this, connectionFlags))
                {
                    this._functions[value.Key] = value.Value;
                }
            }
            this.SetTimeout(0);
            GC.KeepAlive(this._sql);
        }
 public override bool FindFunction(SQLiteVirtualTable table, int argumentCount, string name, ref SQLiteFunction function, ref IntPtr pClientData)
 {
     this.CheckDisposed();
     return(this.ResultCodeToFindFunctionResult(this.GetMethodResultCode("FindFunction")));
 }
 internal abstract CollationSequence GetCollationSequence(SQLiteFunction func, IntPtr context);
Esempio n. 10
0
 internal abstract void BindFunction(SQLiteFunctionAttribute functionAttribute, SQLiteFunction function, SQLiteConnectionFlags flags);