示例#1
0
        private static void FreeNative(IntPtr pIndex)
        {
            if (pIndex == IntPtr.Zero)
            {
                return;
            }
            int num = 0;

            num = SQLiteMarshal.NextOffsetOf(num, 4, IntPtr.Size);
            IntPtr zero = SQLiteMarshal.ReadIntPtr(pIndex, num);
            int    num1 = num;

            num = SQLiteMarshal.NextOffsetOf(num, IntPtr.Size, 4);
            num = SQLiteMarshal.NextOffsetOf(num, 4, IntPtr.Size);
            IntPtr intPtr = SQLiteMarshal.ReadIntPtr(pIndex, num);
            int    num2   = num;

            num = SQLiteMarshal.NextOffsetOf(num, IntPtr.Size, IntPtr.Size);
            IntPtr zero1 = SQLiteMarshal.ReadIntPtr(pIndex, num);
            int    num3  = num;

            if (zero1 != IntPtr.Zero)
            {
                SQLiteMemory.Free(zero1);
                zero1 = IntPtr.Zero;
                SQLiteMarshal.WriteIntPtr(pIndex, num3, zero1);
            }
            if (intPtr != IntPtr.Zero)
            {
                SQLiteMemory.Free(intPtr);
                intPtr = IntPtr.Zero;
                SQLiteMarshal.WriteIntPtr(pIndex, num2, intPtr);
            }
            if (zero != IntPtr.Zero)
            {
                SQLiteMemory.Free(zero);
                zero = IntPtr.Zero;
                SQLiteMarshal.WriteIntPtr(pIndex, num1, zero);
            }
            if (pIndex != IntPtr.Zero)
            {
                SQLiteMemory.Free(pIndex);
                pIndex = IntPtr.Zero;
            }
        }
示例#2
0
        private static IntPtr AllocateAndInitializeNative(int nConstraint, int nOrderBy)
        {
            int    num;
            int    num1;
            int    num2;
            int    num3;
            IntPtr zero    = IntPtr.Zero;
            IntPtr intPtr  = IntPtr.Zero;
            IntPtr zero1   = IntPtr.Zero;
            IntPtr intPtr1 = IntPtr.Zero;
            IntPtr zero2   = IntPtr.Zero;

            try
            {
                SQLiteIndex.SizeOfNative(out num, out num2, out num1, out num3);
                if (num > 0 && num2 > 0 && num1 > 0 && num3 > 0)
                {
                    intPtr  = SQLiteMemory.Allocate(num);
                    zero1   = SQLiteMemory.Allocate(num2 * nConstraint);
                    intPtr1 = SQLiteMemory.Allocate(num1 * nOrderBy);
                    zero2   = SQLiteMemory.Allocate(num3 * nConstraint);
                    if (intPtr != IntPtr.Zero && zero1 != IntPtr.Zero && intPtr1 != IntPtr.Zero && zero2 != IntPtr.Zero)
                    {
                        int num4 = 0;
                        SQLiteMarshal.WriteInt32(intPtr, num4, nConstraint);
                        num4 = SQLiteMarshal.NextOffsetOf(num4, 4, IntPtr.Size);
                        SQLiteMarshal.WriteIntPtr(intPtr, num4, zero1);
                        num4 = SQLiteMarshal.NextOffsetOf(num4, IntPtr.Size, 4);
                        SQLiteMarshal.WriteInt32(intPtr, num4, nOrderBy);
                        num4 = SQLiteMarshal.NextOffsetOf(num4, 4, IntPtr.Size);
                        SQLiteMarshal.WriteIntPtr(intPtr, num4, intPtr1);
                        num4 = SQLiteMarshal.NextOffsetOf(num4, IntPtr.Size, IntPtr.Size);
                        SQLiteMarshal.WriteIntPtr(intPtr, num4, zero2);
                        zero = intPtr;
                    }
                }
            }
            finally
            {
                if (zero == IntPtr.Zero)
                {
                    if (zero2 != IntPtr.Zero)
                    {
                        SQLiteMemory.Free(zero2);
                        zero2 = IntPtr.Zero;
                    }
                    if (intPtr1 != IntPtr.Zero)
                    {
                        SQLiteMemory.Free(intPtr1);
                        intPtr1 = IntPtr.Zero;
                    }
                    if (zero1 != IntPtr.Zero)
                    {
                        SQLiteMemory.Free(zero1);
                        zero1 = IntPtr.Zero;
                    }
                    if (intPtr != IntPtr.Zero)
                    {
                        SQLiteMemory.Free(intPtr);
                        intPtr = IntPtr.Zero;
                    }
                }
            }
            return(zero);
        }
示例#3
0
        internal static void ToIntPtr(SQLiteIndex index, IntPtr pIndex, bool includeInput)
        {
            if (index == null)
            {
                return;
            }
            SQLiteIndexOutputs outputs = index.Outputs;

            if (outputs == null)
            {
                return;
            }
            SQLiteIndexConstraintUsage[] constraintUsages = outputs.ConstraintUsages;
            if (constraintUsages == null)
            {
                return;
            }
            SQLiteIndexInputs inputs = null;

            SQLiteIndexConstraint[] constraints = null;
            SQLiteIndexOrderBy[]    orderBys    = null;
            if (includeInput)
            {
                inputs = index.Inputs;
                if (inputs == null)
                {
                    return;
                }
                constraints = inputs.Constraints;
                if (constraints == null)
                {
                    return;
                }
                orderBys = inputs.OrderBys;
                if (orderBys == null)
                {
                    return;
                }
            }
            if (pIndex == IntPtr.Zero)
            {
                return;
            }
            int num  = 0;
            int num1 = SQLiteMarshal.ReadInt32(pIndex, num);

            if (includeInput && num1 != (int)constraints.Length)
            {
                return;
            }
            if (num1 != (int)constraintUsages.Length)
            {
                return;
            }
            num = SQLiteMarshal.NextOffsetOf(num, 4, IntPtr.Size);
            if (includeInput)
            {
                IntPtr intPtr = SQLiteMarshal.ReadIntPtr(pIndex, num);
                int    num2   = Marshal.SizeOf(typeof(UnsafeNativeMethods.sqlite3_index_constraint));
                for (int i = 0; i < num1; i++)
                {
                    UnsafeNativeMethods.sqlite3_index_constraint sqlite3IndexConstraint = new UnsafeNativeMethods.sqlite3_index_constraint(constraints[i]);
                    Marshal.StructureToPtr(sqlite3IndexConstraint, SQLiteMarshal.IntPtrForOffset(intPtr, i * num2), false);
                }
            }
            num = SQLiteMarshal.NextOffsetOf(num, IntPtr.Size, 4);
            int num3 = (includeInput ? SQLiteMarshal.ReadInt32(pIndex, num) : 0);

            if (includeInput && num3 != (int)orderBys.Length)
            {
                return;
            }
            num = SQLiteMarshal.NextOffsetOf(num, 4, IntPtr.Size);
            if (includeInput)
            {
                IntPtr intPtr1 = SQLiteMarshal.ReadIntPtr(pIndex, num);
                int    num4    = Marshal.SizeOf(typeof(UnsafeNativeMethods.sqlite3_index_orderby));
                for (int j = 0; j < num3; j++)
                {
                    UnsafeNativeMethods.sqlite3_index_orderby sqlite3IndexOrderby = new UnsafeNativeMethods.sqlite3_index_orderby(orderBys[j]);
                    Marshal.StructureToPtr(sqlite3IndexOrderby, SQLiteMarshal.IntPtrForOffset(intPtr1, j * num4), false);
                }
            }
            num = SQLiteMarshal.NextOffsetOf(num, IntPtr.Size, IntPtr.Size);
            IntPtr intPtr2 = SQLiteMarshal.ReadIntPtr(pIndex, num);
            int    num5    = Marshal.SizeOf(typeof(UnsafeNativeMethods.sqlite3_index_constraint_usage));

            for (int k = 0; k < num1; k++)
            {
                UnsafeNativeMethods.sqlite3_index_constraint_usage sqlite3IndexConstraintUsage = new UnsafeNativeMethods.sqlite3_index_constraint_usage(constraintUsages[k]);
                Marshal.StructureToPtr(sqlite3IndexConstraintUsage, SQLiteMarshal.IntPtrForOffset(intPtr2, k * num5), false);
            }
            num = SQLiteMarshal.NextOffsetOf(num, IntPtr.Size, 4);
            SQLiteMarshal.WriteInt32(pIndex, num, outputs.IndexNumber);
            num = SQLiteMarshal.NextOffsetOf(num, 4, IntPtr.Size);
            SQLiteMarshal.WriteIntPtr(pIndex, num, SQLiteString.Utf8IntPtrFromString(outputs.IndexString));
            num = SQLiteMarshal.NextOffsetOf(num, IntPtr.Size, 4);
            SQLiteMarshal.WriteInt32(pIndex, num, (outputs.NeedToFreeIndexString != 0 ? outputs.NeedToFreeIndexString : 1));
            num = SQLiteMarshal.NextOffsetOf(num, 4, 4);
            SQLiteMarshal.WriteInt32(pIndex, num, outputs.OrderByConsumed);
            num = SQLiteMarshal.NextOffsetOf(num, 4, 8);
            if (outputs.EstimatedCost.HasValue)
            {
                SQLiteMarshal.WriteDouble(pIndex, num, outputs.EstimatedCost.GetValueOrDefault());
            }
            num = SQLiteMarshal.NextOffsetOf(num, 8, 8);
            if (outputs.CanUseEstimatedRows() && outputs.EstimatedRows.HasValue)
            {
                SQLiteMarshal.WriteInt64(pIndex, num, outputs.EstimatedRows.GetValueOrDefault());
            }
            num = SQLiteMarshal.NextOffsetOf(num, 8, 4);
            if (outputs.CanUseIndexFlags() && outputs.IndexFlags.HasValue)
            {
                SQLiteMarshal.WriteInt32(pIndex, num, (int)outputs.IndexFlags.GetValueOrDefault());
            }
            num = SQLiteMarshal.NextOffsetOf(num, 4, 8);
            if (outputs.CanUseColumnsUsed() && outputs.ColumnsUsed.HasValue)
            {
                SQLiteMarshal.WriteInt64(pIndex, num, outputs.ColumnsUsed.GetValueOrDefault());
            }
        }