Beispiel #1
0
        public override void BeginTransaction(TransactionParameterBuffer tpb)
        {
            if (_state != TransactionState.NoTransaction)
            {
                throw new InvalidOperationException();
            }

            IscTeb teb     = new IscTeb();
            IntPtr tebData = IntPtr.Zero;

            try
            {
                ClearStatusVector();

                teb.dbb_ptr = Marshal.AllocHGlobal(4);
                Marshal.WriteInt32(teb.dbb_ptr, _db.Handle);

                teb.tpb_len = tpb.Length;

                teb.tpb_ptr = Marshal.AllocHGlobal(tpb.Length);
                Marshal.Copy(tpb.ToArray(), 0, teb.tpb_ptr, tpb.Length);

                int size = Marshal2.SizeOf <IscTeb>();
                tebData = Marshal.AllocHGlobal(size);

                Marshal.StructureToPtr(teb, tebData, true);

                _db.FbClient.isc_start_multiple(
                    _statusVector,
                    ref _handle,
                    1,
                    tebData);

                _db.ProcessStatusVector(_statusVector);

                _state = TransactionState.Active;

                _db.TransactionCount++;
            }
            catch
            {
                throw;
            }
            finally
            {
                if (teb.dbb_ptr != IntPtr.Zero)
                {
                    Marshal.FreeHGlobal(teb.dbb_ptr);
                }
                if (teb.tpb_ptr != IntPtr.Zero)
                {
                    Marshal.FreeHGlobal(teb.tpb_ptr);
                }
                if (tebData != IntPtr.Zero)
                {
                    Marshal2.DestroyStructure <IscTeb>(tebData);
                    Marshal.FreeHGlobal(tebData);
                }
            }
        }
        public static void CleanUpNativeData(ref IntPtr pNativeData)
        {
            if (pNativeData != IntPtr.Zero)
            {
                XSQLDA xsqlda = Marshal2.PtrToStructure <XSQLDA>(pNativeData);

                Marshal2.DestroyStructure <XSQLDA>(pNativeData);

                for (var i = 0; i < xsqlda.sqln; i++)
                {
                    IntPtr ptr = GetIntPtr(pNativeData, ComputeLength(i));

                    var sqlvar = new XSQLVAR();
                    MarshalXSQLVARNativeToManaged(ptr, sqlvar, true);

                    if (sqlvar.sqldata != IntPtr.Zero)
                    {
                        Marshal.FreeHGlobal(sqlvar.sqldata);
                        sqlvar.sqldata = IntPtr.Zero;
                    }

                    if (sqlvar.sqlind != IntPtr.Zero)
                    {
                        Marshal.FreeHGlobal(sqlvar.sqlind);
                        sqlvar.sqlind = IntPtr.Zero;
                    }

                    Marshal2.DestroyStructure <XSQLVAR>(ptr);
                }

                Marshal.FreeHGlobal(pNativeData);

                pNativeData = IntPtr.Zero;
            }
        }
Beispiel #3
0
        public static void CleanUpNativeData(ref IntPtr pNativeData)
        {
            if (pNativeData != IntPtr.Zero)
            {
                Marshal2.DestroyStructure <ArrayDescMarshal>(pNativeData);

                for (int i = 0; i < 16; i++)
                {
                    Marshal2.DestroyStructure <ArrayBoundMarshal>(pNativeData + ArrayDescMarshal.ComputeLength(i));
                }

                Marshal.FreeHGlobal(pNativeData);

                pNativeData = IntPtr.Zero;
            }
        }
        public static void CleanUpNativeData(ref IntPtr pNativeData)
        {
            if (pNativeData != IntPtr.Zero)
            {
                // Obtain XSQLDA information
                XSQLDA xsqlda = Marshal2.PtrToStructure <XSQLDA>(pNativeData);

                // Destroy XSQLDA structure
                Marshal2.DestroyStructure <XSQLDA>(pNativeData);

                // Destroy XSQLVAR structures
                for (var i = 0; i < xsqlda.sqln; i++)
                {
                    IntPtr ptr = GetIntPtr(pNativeData, ComputeLength(i));

                    // Free	sqldata	and	sqlind pointers	if needed
                    var sqlvar = new XSQLVAR();
                    MarshalXSQLVARNativeToManaged(ptr, sqlvar, true);

                    if (sqlvar.sqldata != IntPtr.Zero)
                    {
                        Marshal.FreeHGlobal(sqlvar.sqldata);
                        sqlvar.sqldata = IntPtr.Zero;
                    }

                    if (sqlvar.sqlind != IntPtr.Zero)
                    {
                        Marshal.FreeHGlobal(sqlvar.sqlind);
                        sqlvar.sqlind = IntPtr.Zero;
                    }

                    Marshal2.DestroyStructure <XSQLVAR>(ptr);
                }

                // Free	pointer	memory
                Marshal.FreeHGlobal(pNativeData);

                pNativeData = IntPtr.Zero;
            }
        }