예제 #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);
                }
            }
        }
예제 #2
0
        public override ValueTask BeginTransactionAsync(TransactionParameterBuffer tpb, CancellationToken cancellationToken = default)
        {
            if (State != TransactionState.NoTransaction)
            {
                throw new InvalidOperationException();
            }

            var teb     = new IscTeb();
            var 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);

                var size = Marshal.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++;
            }
            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)
                {
                    Marshal.DestroyStructure <IscTeb>(tebData);
                    Marshal.FreeHGlobal(tebData);
                }
            }

            return(ValueTask2.CompletedTask);
        }
        public void BeginTransaction(TransactionParameterBuffer tpb)
        {
            if (this.state != TransactionState.NoTransaction)
            {
                throw new IscException(IscCodes.isc_arg_gds, IscCodes.isc_tra_state, this.handle, "no valid");
            }

            lock (this.db)
            {
                IscTeb teb = new IscTeb();
                IntPtr tebData = IntPtr.Zero;

                try
                {
                    // Clear the status vector
                    this.ClearStatusVector();

                    // Set db handle
                    teb.dbb_ptr = Marshal.AllocHGlobal(4);
                    Marshal.WriteInt32(teb.dbb_ptr, this.db.Handle);

                    // Set tpb length
                    teb.tpb_len = tpb.Length;

                    // Set TPB data
                    teb.tpb_ptr = Marshal.AllocHGlobal(tpb.Length);
                    Marshal.Copy(tpb.ToArray(), 0, teb.tpb_ptr, tpb.Length);

                    // Alloc memory	for	the	IscTeb structure
                    int size = Marshal.SizeOf(typeof(IscTeb));
                    tebData = Marshal.AllocHGlobal(size);

                    Marshal.StructureToPtr(teb, tebData, true);

                    int trHandle = this.handle;

                    db.FbClient.isc_start_multiple(
                        this.statusVector,
                        ref	trHandle,
                        1,
                        tebData);

                    this.handle = trHandle;

                    // Parse status	vector
                    this.db.ParseStatusVector(this.statusVector);

                    // Update transaction state
                    this.state = TransactionState.Active;

                    // Update transaction count
                    this.db.TransactionCount++;
                }
                catch (Exception)
                {
                    throw;
                }
                finally
                {
                    // Free	memory
                    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)
                    {
                        Marshal.DestroyStructure(tebData, typeof(IscTeb));
                        Marshal.FreeHGlobal(tebData);
                    }
                }
            }
        }
        public void BeginTransaction(TransactionParameterBuffer tpb)
        {
            if (this.state != TransactionState.NoTransaction)
            {
                throw new IscException(IscCodes.isc_arg_gds, IscCodes.isc_tra_state, this.handle, "no valid");
            }

            lock (this.db)
            {
                IscTeb teb     = new IscTeb();
                IntPtr tebData = IntPtr.Zero;

                try
                {
                    // Clear the status vector
                    this.ClearStatusVector();

                    // Set db handle
                    teb.dbb_ptr = Marshal.AllocHGlobal(4);
                    Marshal.WriteInt32(teb.dbb_ptr, this.db.Handle);

                    // Set tpb length
                    teb.tpb_len = tpb.Length;

                    // Set TPB data
                    teb.tpb_ptr = Marshal.AllocHGlobal(tpb.Length);
                    Marshal.Copy(tpb.ToArray(), 0, teb.tpb_ptr, tpb.Length);

                    // Alloc memory	for	the	IscTeb structure
                    int size = Marshal.SizeOf(typeof(IscTeb));
                    tebData = Marshal.AllocHGlobal(size);

                    Marshal.StructureToPtr(teb, tebData, true);

                    int trHandle = this.handle;

                    db.FbClient.isc_start_multiple(
                        this.statusVector,
                        ref trHandle,
                        1,
                        tebData);

                    this.handle = trHandle;

                    // Parse status	vector
                    this.db.ParseStatusVector(this.statusVector);

                    // Update transaction state
                    this.state = TransactionState.Active;

                    // Update transaction count
                    this.db.TransactionCount++;
                }
                catch (Exception)
                {
                    throw;
                }
                finally
                {
                    // Free	memory
                    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)
                    {
                        Marshal.DestroyStructure(tebData, typeof(IscTeb));
                        Marshal.FreeHGlobal(tebData);
                    }
                }
            }
        }
예제 #5
0
        public override void BeginTransaction(TransactionParameterBuffer tpb)
        {
            if (_state != TransactionState.NoTransaction)
            {
                throw new InvalidOperationException();
            }

            lock (_db)
            {
                IscTeb teb     = new IscTeb();
                IntPtr tebData = IntPtr.Zero;

                try
                {
                    // Clear the status vector
                    ClearStatusVector();

                    // Set db handle
                    teb.dbb_ptr = Marshal.AllocHGlobal(4);
                    Marshal.WriteInt32(teb.dbb_ptr, _db.Handle);

                    // Set tpb length
                    teb.tpb_len = tpb.Length;

                    // Set TPB data
                    teb.tpb_ptr = Marshal.AllocHGlobal(tpb.Length);
                    Marshal.Copy(tpb.ToArray(), 0, teb.tpb_ptr, tpb.Length);

                    // Alloc memory	for	the	IscTeb structure
                    int size = Marshal.SizeOf(typeof(IscTeb));
                    tebData = Marshal.AllocHGlobal(size);

                    Marshal.StructureToPtr(teb, tebData, true);

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

                    // Parse status	vector
                    _db.ProcessStatusVector(_statusVector);

                    // Update transaction state
                    _state = TransactionState.Active;

                    // Update transaction count
                    _db.TransactionCount++;
                }
                catch
                {
                    throw;
                }
                finally
                {
                    // Free	memory
                    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)
                    {
                        Marshal.DestroyStructure(tebData, typeof(IscTeb));
                        Marshal.FreeHGlobal(tebData);
                    }
                }
            }
        }