Example #1
0
            internal OleDbHResult Commit()
            {
                Debug.Assert(_mustComplete, "transaction already completed");
                OleDbHResult hr;
                bool         mustRelease = false;

                RuntimeHelpers.PrepareConstrainedRegions();
                try
                {
                    DangerousAddRef(ref mustRelease);
                    RuntimeHelpers.PrepareConstrainedRegions();
                    try
                    { }
                    finally
                    {
                        hr = (OleDbHResult)NativeOledbWrapper.ITransactionCommit(DangerousGetHandle());
                        if ((0 <= (int)hr) || (OleDbHResult.XACT_E_NOTRANSACTION == hr))
                        {
                            _mustComplete = false;
                        }
                    }
                }
                finally
                {
                    if (mustRelease)
                    {
                        DangerousRelease();
                    }
                }
                return(hr);
            }
Example #2
0
            internal OleDbHResult Commit()
            {
                OleDbHResult result;
                bool         success = false;

                RuntimeHelpers.PrepareConstrainedRegions();
                try
                {
                    base.DangerousAddRef(ref success);
                    Bid.Trace("<oledb.ITransactionLocal.Commit|API|OLEDB> handle=%p\n", base.handle);
                    RuntimeHelpers.PrepareConstrainedRegions();
                    try
                    {
                    }
                    finally
                    {
                        result = NativeOledbWrapper.ITransactionCommit(base.DangerousGetHandle());
                        if ((OleDbHResult.S_OK <= result) || (OleDbHResult.XACT_E_NOTRANSACTION == result))
                        {
                            this._mustComplete = false;
                        }
                    }
                    Bid.Trace("<oledb.ITransactionLocal.Commit|API|OLEDB|RET> %08X{HRESULT}\n", result);
                }
                finally
                {
                    if (success)
                    {
                        base.DangerousRelease();
                    }
                }
                return(result);
            }
Example #3
0
            internal OleDbHResult Abort()
            {
                Debug.Assert(_mustComplete, "transaction already completed");
                OleDbHResult hr;
                bool         mustRelease = false;

                RuntimeHelpers.PrepareConstrainedRegions();
                try
                {
                    DangerousAddRef(ref mustRelease);
                    RuntimeHelpers.PrepareConstrainedRegions();
                    try
                    { }
                    finally
                    {
                        hr            = (OleDbHResult)NativeOledbWrapper.ITransactionAbort(DangerousGetHandle());
                        _mustComplete = false;
                    }
                }
                finally
                {
                    if (mustRelease)
                    {
                        DangerousRelease();
                    }
                }
                return(hr);
            }
        internal void SetVariantValue(int offset, object value)
        {
            IntPtr ptrZero = ADP.PtrZero;
            bool   success = false;

            RuntimeHelpers.PrepareConstrainedRegions();
            try
            {
                base.DangerousAddRef(ref success);
                ptrZero = ADP.IntPtrOffset(base.DangerousGetHandle(), offset);
                RuntimeHelpers.PrepareConstrainedRegions();
                try
                {
                    Marshal.GetNativeVariantForObject(value, ptrZero);
                }
                finally
                {
                    NativeOledbWrapper.MemoryCopy(ADP.IntPtrOffset(ptrZero, ODB.SizeOf_Variant), ptrZero, ODB.SizeOf_Variant);
                }
            }
            finally
            {
                if (success)
                {
                    base.DangerousRelease();
                }
            }
        }
Example #5
0
        private static unsafe void FreePropVariant(IntPtr buffer, int valueOffset)
        {
            // two contigous PROPVARIANT structures that need to be freed
            // the second should only be freed if different from the first
            Debug.Assert(0 == (sizeof(PROPVARIANT) % 8), "unexpected PROPVARIANT size mutiplier");
            Debug.Assert(0 == valueOffset % 8, "unexpected unaligned ptr offset");

            IntPtr currentHandle  = ADP.IntPtrOffset(buffer, valueOffset);
            IntPtr originalHandle = ADP.IntPtrOffset(buffer, valueOffset + sizeof(PROPVARIANT));
            bool   different      = NativeOledbWrapper.MemoryCompare(currentHandle, originalHandle, sizeof(PROPVARIANT));

            RuntimeHelpers.PrepareConstrainedRegions();
            try
            { }
            finally
            {
                // always clear the first structure
                Interop.Ole32.PropVariantClear(currentHandle);
                if (different)
                {
                    // second structure different from the first
                    Interop.Ole32.PropVariantClear(originalHandle);
                }
                else
                {
                    // second structure same as the first, just clear the field
                    SafeNativeMethods.ZeroMemory(originalHandle, sizeof(PROPVARIANT));
                }
            }
        }
Example #6
0
        // translate to native
        internal void SetVariantValue(int offset, object value)
        {
            // two contigous VARIANT structures, second should be a binary copy of the first
            Debug.Assert(_needToReset, "data type requires reseting and _needToReset is false");
            Debug.Assert(0 == (ODB.SizeOf_Variant % 8), "unexpected VARIANT size mutiplier");
            Debug.Assert(0 == offset % 8, "invalid alignment");
            ValidateCheck(offset, 2 * ODB.SizeOf_Variant);

            IntPtr buffer      = ADP.PtrZero;
            bool   mustRelease = false;

            RuntimeHelpers.PrepareConstrainedRegions();
            try {
                DangerousAddRef(ref mustRelease);

                buffer = ADP.IntPtrOffset(DangerousGetHandle(), offset);

                RuntimeHelpers.PrepareConstrainedRegions();
                try {
                    // GetNativeVariantForObject must be in try block since it has no reliability contract
                    Marshal.GetNativeVariantForObject(value, buffer);
                }
                finally {
                    // safe to copy memory(dst,src,count), even if GetNativeVariantForObject failed
                    NativeOledbWrapper.MemoryCopy(ADP.IntPtrOffset(buffer, ODB.SizeOf_Variant), buffer, ODB.SizeOf_Variant);
                }
            }
            finally {
                if (mustRelease)
                {
                    DangerousRelease();
                }
            }
        }
Example #7
0
            internal OleDbHResult Commit()
            {
                Debug.Assert(_mustComplete, "transaction already completed");
                OleDbHResult hr;
                bool         mustRelease = false;

                RuntimeHelpers.PrepareConstrainedRegions();
                try {
                    DangerousAddRef(ref mustRelease);

                    Bid.Trace("<oledb.ITransactionLocal.Commit|API|OLEDB> handle=%p\n", base.handle);
                    RuntimeHelpers.PrepareConstrainedRegions();
                    try { } finally {
                        hr = (OleDbHResult)NativeOledbWrapper.ITransactionCommit(DangerousGetHandle());
                        if ((0 <= (int)hr) || (OleDbHResult.XACT_E_NOTRANSACTION == hr))
                        {
                            _mustComplete = false;
                        }
                    }
                    Bid.Trace("<oledb.ITransactionLocal.Commit|API|OLEDB|RET> %08X{HRESULT}\n", hr);
                }
                finally {
                    if (mustRelease)
                    {
                        DangerousRelease();
                    }
                }
                return(hr);
            }
Example #8
0
 protected override bool ReleaseHandle()
 {
     if (_mustComplete && (IntPtr.Zero != base.handle))
     {
         NativeOledbWrapper.ITransactionAbort(base.handle);
         _mustComplete = false;
     }
     return(base.ReleaseHandle());
 }
Example #9
0
 protected override bool ReleaseHandle()
 {
     if (this._mustComplete && (IntPtr.Zero != base.handle))
     {
         Bid.Trace("<oledb.ITransactionLocal.Abort|API|OLEDB|INFO> handle=%p\n", base.handle);
         OleDbHResult result = NativeOledbWrapper.ITransactionAbort(base.handle);
         this._mustComplete = false;
         Bid.Trace("<oledb.ITransactionLocal.Abort|API|OLEDB|INFO|RET> %08X{HRESULT}\n", result);
     }
     return(base.ReleaseHandle());
 }
Example #10
0
        protected override bool ReleaseHandle()
        {
            // NOTE: The SafeHandle class guarantees this will be called exactly once and is non-interrutible.
            IntPtr chapter = _chapterHandle;

            _chapterHandle = IntPtr.Zero;

            if ((IntPtr.Zero != base.handle) && (IntPtr.Zero != chapter))
            {
                OleDbHResult hr = (OleDbHResult)NativeOledbWrapper.IChapteredRowsetReleaseChapter(base.handle, chapter);
            }
            return(base.ReleaseHandle());
        }
        protected override bool ReleaseHandle()
        {
            IntPtr ptr = this._chapterHandle;

            this._chapterHandle = IntPtr.Zero;
            if ((IntPtr.Zero != base.handle) && (IntPtr.Zero != ptr))
            {
                Bid.Trace("<oledb.IChapteredRowset.ReleaseChapter|API|OLEDB> Chapter=%Id\n", ptr);
                OleDbHResult result = NativeOledbWrapper.IChapteredRowsetReleaseChapter(base.handle, ptr);
                Bid.Trace("<oledb.IChapteredRowset.ReleaseChapter|API|OLEDB|RET> %08X{HRESULT}\n", result);
            }
            return(base.ReleaseHandle());
        }
Example #12
0
        protected override bool ReleaseHandle()
        {
            // NOTE: The SafeHandle class guarantees this will be called exactly once and is non-interrutible.
            IntPtr chapter = _chapterHandle;

            _chapterHandle = IntPtr.Zero;

            if ((IntPtr.Zero != base.handle) && (IntPtr.Zero != chapter))
            {
                Bid.Trace("<oledb.IChapteredRowset.ReleaseChapter|API|OLEDB> Chapter=%Id\n", chapter);
                OleDbHResult hr = (OleDbHResult)NativeOledbWrapper.IChapteredRowsetReleaseChapter(base.handle, chapter);
                Bid.Trace("<oledb.IChapteredRowset.ReleaseChapter|API|OLEDB|RET> %08X{HRESULT}\n", hr);
            }
            return(base.ReleaseHandle());
        }
        private static void FreeVariant(IntPtr buffer, int valueOffset)
        {
            IntPtr ptr2 = ADP.IntPtrOffset(buffer, valueOffset);
            IntPtr ptr  = ADP.IntPtrOffset(buffer, valueOffset + ODB.SizeOf_Variant);
            bool   flag = NativeOledbWrapper.MemoryCompare(ptr2, ptr, ODB.SizeOf_Variant);

            RuntimeHelpers.PrepareConstrainedRegions();
            try
            {
            }
            finally
            {
                SafeNativeMethods.VariantClear(ptr2);
                if (flag)
                {
                    SafeNativeMethods.VariantClear(ptr);
                }
                else
                {
                    SafeNativeMethods.ZeroMemory(ptr, (IntPtr)ODB.SizeOf_Variant);
                }
            }
        }