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;
                }
            }
        }
Example #2
0
        public void CreateChangeSet(ref byte[] rawData)
        {
            this.CheckDisposed();
            this.CheckHandle();
            IntPtr zero = IntPtr.Zero;

            try
            {
                int             num             = 0;
                SQLiteErrorCode sQLiteErrorCode = UnsafeNativeMethods.sqlite3session_changeset(this.session, ref num, ref zero);
                if (sQLiteErrorCode != SQLiteErrorCode.Ok)
                {
                    throw new SQLiteException(sQLiteErrorCode, "sqlite3session_changeset");
                }
                rawData = SQLiteBytes.FromIntPtr(zero, num);
            }
            finally
            {
                if (zero != IntPtr.Zero)
                {
                    SQLiteMemory.Free(zero);
                    zero = IntPtr.Zero;
                }
            }
        }
        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;
                }
            }
        }
        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;
                }
            }
        }
        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);
        }
Example #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;
     }
 }
Example #7
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;
            }
        }
Example #8
0
        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;
                }
            }
        }
Example #9
0
        public static IntPtr ToIntPtr(byte[] value, ref int length)
        {
            if (value == null)
            {
                return(IntPtr.Zero);
            }
            length = (int)value.Length;
            if (length == 0)
            {
                return(IntPtr.Zero);
            }
            IntPtr intPtr = SQLiteMemory.Allocate(length);

            if (intPtr == IntPtr.Zero)
            {
                return(IntPtr.Zero);
            }
            Marshal.Copy(value, 0, intPtr, length);
            return(intPtr);
        }
Example #10
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);
        }
        public static IntPtr Utf8IntPtrFromString(string value, ref int length)
        {
            if (value == null)
            {
                return(IntPtr.Zero);
            }
            IntPtr zero = IntPtr.Zero;

            byte[] utf8BytesFromString = SQLiteString.GetUtf8BytesFromString(value);
            if (utf8BytesFromString == null)
            {
                return(IntPtr.Zero);
            }
            length = (int)utf8BytesFromString.Length;
            zero   = SQLiteMemory.Allocate(length + 1);
            if (zero == IntPtr.Zero)
            {
                return(IntPtr.Zero);
            }
            Marshal.Copy(utf8BytesFromString, 0, zero, length);
            Marshal.WriteByte(zero, length, 0);
            return(zero);
        }
        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);
        }
Example #13
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);
        }