Beispiel #1
0
        public void Apply(SessionConflictCallback conflictCallback, SessionTableFilterCallback tableFilterCallback, object clientData)
        {
            this.CheckDisposed();
            SQLiteSessionHelpers.CheckRawData(this.rawData);
            if (conflictCallback == null)
            {
                throw new ArgumentNullException("conflictCallback");
            }
            UnsafeNativeMethods.xSessionFilter   @delegate         = base.GetDelegate(tableFilterCallback, clientData);
            UnsafeNativeMethods.xSessionConflict _xSessionConflict = base.GetDelegate(conflictCallback, clientData);
            IntPtr zero = IntPtr.Zero;

            try
            {
                int num = 0;
                zero = SQLiteBytes.ToIntPtr(this.rawData, ref num);
                SQLiteErrorCode sQLiteErrorCode = UnsafeNativeMethods.sqlite3changeset_apply(base.GetIntPtr(), num, zero, @delegate, _xSessionConflict, IntPtr.Zero);
                if (sQLiteErrorCode != SQLiteErrorCode.Ok)
                {
                    throw new SQLiteException(sQLiteErrorCode, "sqlite3changeset_apply");
                }
            }
            finally
            {
                if (zero != IntPtr.Zero)
                {
                    SQLiteMemory.Free(zero);
                    zero = IntPtr.Zero;
                }
            }
        }
Beispiel #2
0
        public void CreateChangeSet(ref byte[] rawData)
        {
            this.CheckDisposed();
            this.CheckHandle();
            IntPtr zero = IntPtr.Zero;

            try
            {
                int             num             = 0;
                SQLiteErrorCode sQLiteErrorCode = UnsafeNativeMethods.sqlite3changegroup_output(this.changeGroup, ref num, ref zero);
                if (sQLiteErrorCode != SQLiteErrorCode.Ok)
                {
                    throw new SQLiteException(sQLiteErrorCode, "sqlite3changegroup_output");
                }
                rawData = SQLiteBytes.FromIntPtr(zero, num);
            }
            finally
            {
                if (zero != IntPtr.Zero)
                {
                    SQLiteMemory.Free(zero);
                    zero = IntPtr.Zero;
                }
            }
        }
Beispiel #3
0
        public void AddChangeSet(byte[] rawData)
        {
            this.CheckDisposed();
            this.CheckHandle();
            SQLiteSessionHelpers.CheckRawData(rawData);
            IntPtr zero = IntPtr.Zero;

            try
            {
                int num = 0;
                zero = SQLiteBytes.ToIntPtr(rawData, ref num);
                SQLiteErrorCode sQLiteErrorCode = UnsafeNativeMethods.sqlite3changegroup_add(this.changeGroup, num, zero);
                if (sQLiteErrorCode != SQLiteErrorCode.Ok)
                {
                    throw new SQLiteException(sQLiteErrorCode, "sqlite3changegroup_add");
                }
            }
            finally
            {
                if (zero != IntPtr.Zero)
                {
                    SQLiteMemory.Free(zero);
                    zero = IntPtr.Zero;
                }
            }
        }
        public void Lock()
        {
            this.CheckDisposed();
            if (this.statement != IntPtr.Zero)
            {
                return;
            }
            IntPtr zero = IntPtr.Zero;

            try
            {
                int num = 0;
                zero = SQLiteString.Utf8IntPtrFromString("SELECT 1;", ref num);
                IntPtr          intPtr          = IntPtr.Zero;
                int             num1            = 0;
                SQLiteErrorCode sQLiteErrorCode = UnsafeNativeMethods.sqlite3_prepare_interop(this.GetIntPtr(), zero, num, ref this.statement, ref intPtr, ref num1);
                if (sQLiteErrorCode != SQLiteErrorCode.Ok)
                {
                    throw new SQLiteException(sQLiteErrorCode, "sqlite3_prepare_interop");
                }
            }
            finally
            {
                if (zero != IntPtr.Zero)
                {
                    SQLiteMemory.Free(zero);
                    zero = IntPtr.Zero;
                }
            }
        }
Beispiel #5
0
        public ISQLiteChangeSet CombineWith(ISQLiteChangeSet changeSet)
        {
            ISQLiteChangeSet sQLiteMemoryChangeSets;

            this.CheckDisposed();
            SQLiteSessionHelpers.CheckRawData(this.rawData);
            SQLiteMemoryChangeSet sQLiteMemoryChangeSets1 = changeSet as SQLiteMemoryChangeSet;

            if (sQLiteMemoryChangeSets1 == null)
            {
                throw new ArgumentException("not a memory based change set", "changeSet");
            }
            SQLiteSessionHelpers.CheckRawData(sQLiteMemoryChangeSets1.rawData);
            IntPtr zero   = IntPtr.Zero;
            IntPtr intPtr = IntPtr.Zero;
            IntPtr zero1  = IntPtr.Zero;

            try
            {
                int num = 0;
                zero = SQLiteBytes.ToIntPtr(this.rawData, ref num);
                int num1 = 0;
                intPtr = SQLiteBytes.ToIntPtr(sQLiteMemoryChangeSets1.rawData, ref num1);
                int             num2            = 0;
                SQLiteErrorCode sQLiteErrorCode = UnsafeNativeMethods.sqlite3changeset_concat(num, zero, num1, intPtr, ref num2, ref zero1);
                if (sQLiteErrorCode != SQLiteErrorCode.Ok)
                {
                    throw new SQLiteException(sQLiteErrorCode, "sqlite3changeset_concat");
                }
                byte[] numArray = SQLiteBytes.FromIntPtr(zero1, num2);
                sQLiteMemoryChangeSets = new SQLiteMemoryChangeSet(numArray, base.GetHandle(), base.GetFlags());
            }
            finally
            {
                if (zero1 != IntPtr.Zero)
                {
                    SQLiteMemory.Free(zero1);
                    zero1 = IntPtr.Zero;
                }
                if (intPtr != IntPtr.Zero)
                {
                    SQLiteMemory.Free(intPtr);
                    intPtr = IntPtr.Zero;
                }
                if (zero != IntPtr.Zero)
                {
                    SQLiteMemory.Free(zero);
                    zero = IntPtr.Zero;
                }
            }
            return(sQLiteMemoryChangeSets);
        }
Beispiel #6
0
 protected override void Dispose(bool disposing)
 {
     base.Dispose(disposing);
     try
     {
         if (!this.disposed && this.pData != IntPtr.Zero)
         {
             SQLiteMemory.Free(this.pData);
             this.pData = IntPtr.Zero;
         }
     }
     finally
     {
         this.disposed = true;
     }
 }
        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;
            }
        }
        public void LoadDifferencesFromTable(string fromDatabaseName, string tableName)
        {
            this.CheckDisposed();
            this.CheckHandle();
            if (fromDatabaseName == null)
            {
                throw new ArgumentNullException("fromDatabaseName");
            }
            if (tableName == null)
            {
                throw new ArgumentNullException("tableName");
            }
            IntPtr zero = IntPtr.Zero;

            try
            {
                SQLiteErrorCode sQLiteErrorCode = UnsafeNativeMethods.sqlite3session_diff(this.session, SQLiteString.GetUtf8BytesFromString(fromDatabaseName), SQLiteString.GetUtf8BytesFromString(tableName), ref zero);
                if (sQLiteErrorCode != SQLiteErrorCode.Ok)
                {
                    string str = null;
                    if (zero != IntPtr.Zero)
                    {
                        str = SQLiteString.StringFromUtf8IntPtr(zero);
                        if (!string.IsNullOrEmpty(str))
                        {
                            CultureInfo currentCulture = CultureInfo.CurrentCulture;
                            object[]    objArray       = new object[] { str };
                            str = HelperMethods.StringFormat(currentCulture, ": {0}", objArray);
                        }
                    }
                    CultureInfo cultureInfo = CultureInfo.CurrentCulture;
                    object[]    objArray1   = new object[] { "sqlite3session_diff", str };
                    throw new SQLiteException(sQLiteErrorCode, HelperMethods.StringFormat(cultureInfo, "{0}{1}", objArray1));
                }
            }
            finally
            {
                if (zero != IntPtr.Zero)
                {
                    SQLiteMemory.Free(zero);
                    zero = IntPtr.Zero;
                }
            }
        }
Beispiel #9
0
        public static SQLiteMemoryChangeSetIterator Create(byte[] rawData)
        {
            SQLiteSessionHelpers.CheckRawData(rawData);
            SQLiteMemoryChangeSetIterator sQLiteMemoryChangeSetIterator = null;
            IntPtr zero   = IntPtr.Zero;
            IntPtr intPtr = IntPtr.Zero;

            try
            {
                int num = 0;
                zero = SQLiteBytes.ToIntPtr(rawData, ref num);
                if (zero == IntPtr.Zero)
                {
                    throw new SQLiteException(SQLiteErrorCode.NoMem, null);
                }
                SQLiteErrorCode sQLiteErrorCode = UnsafeNativeMethods.sqlite3changeset_start(ref intPtr, num, zero);
                if (sQLiteErrorCode != SQLiteErrorCode.Ok)
                {
                    throw new SQLiteException(sQLiteErrorCode, "sqlite3changeset_start");
                }
                sQLiteMemoryChangeSetIterator = new SQLiteMemoryChangeSetIterator(zero, intPtr, true);
            }
            finally
            {
                if (sQLiteMemoryChangeSetIterator == null)
                {
                    if (intPtr != IntPtr.Zero)
                    {
                        UnsafeNativeMethods.sqlite3changeset_finalize(intPtr);
                        intPtr = IntPtr.Zero;
                    }
                    if (zero != IntPtr.Zero)
                    {
                        SQLiteMemory.Free(zero);
                        zero = IntPtr.Zero;
                    }
                }
            }
            return(sQLiteMemoryChangeSetIterator);
        }
Beispiel #10
0
        public ISQLiteChangeSet Invert()
        {
            ISQLiteChangeSet sQLiteMemoryChangeSets;

            this.CheckDisposed();
            SQLiteSessionHelpers.CheckRawData(this.rawData);
            IntPtr zero   = IntPtr.Zero;
            IntPtr intPtr = IntPtr.Zero;

            try
            {
                int num = 0;
                zero = SQLiteBytes.ToIntPtr(this.rawData, ref num);
                int             num1            = 0;
                SQLiteErrorCode sQLiteErrorCode = UnsafeNativeMethods.sqlite3changeset_invert(num, zero, ref num1, ref intPtr);
                if (sQLiteErrorCode != SQLiteErrorCode.Ok)
                {
                    throw new SQLiteException(sQLiteErrorCode, "sqlite3changeset_invert");
                }
                byte[] numArray = SQLiteBytes.FromIntPtr(intPtr, num1);
                sQLiteMemoryChangeSets = new SQLiteMemoryChangeSet(numArray, base.GetHandle(), base.GetFlags());
            }
            finally
            {
                if (intPtr != IntPtr.Zero)
                {
                    SQLiteMemory.Free(intPtr);
                    intPtr = IntPtr.Zero;
                }
                if (zero != IntPtr.Zero)
                {
                    SQLiteMemory.Free(zero);
                    zero = IntPtr.Zero;
                }
            }
            return(sQLiteMemoryChangeSets);
        }
        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);
        }