コード例 #1
0
        protected override byte[] GetSegment()
        {
            short requested     = (short)SegmentSize;
            short segmentLength = 0;

            lock (_db)
            {
                // Clear the status vector
                ClearStatusVector();

                using (MemoryStream segment = new MemoryStream())
                {
                    byte[] tmp = new byte[requested];

                    IntPtr status = _db.FbClient.isc_get_segment(
                        _statusVector,
                        ref _blobHandle,
                        ref segmentLength,
                        requested,
                        tmp);

                    if (segmentLength > 0)
                    {
                        segment.Write(tmp, 0, segmentLength > requested ? requested : segmentLength);
                    }

                    RblRemoveValue(IscCodes.RBL_segment);

                    if (_statusVector[1] == new IntPtr(IscCodes.isc_segstr_eof))
                    {
                        segment.SetLength(0);
                        RblAddValue(IscCodes.RBL_eof_pending);
                    }
                    else
                    {
                        if (status == IntPtr.Zero || _statusVector[1] == new IntPtr(IscCodes.isc_segment))
                        {
                            RblAddValue(IscCodes.RBL_segment);
                        }
                        else
                        {
                            _db.ParseStatusVector(_statusVector);
                        }
                    }

                    return(segment.ToArray());
                }
            }
        }
コード例 #2
0
        public void BeginTransaction(TransactionParameterBuffer tpb)
        {
            if (_state != TransactionState.NoTransaction)
            {
                throw new IscException(IscCodes.isc_arg_gds, IscCodes.isc_tra_state, _handle, "no valid");
            }

            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);

                    int trHandle = _handle;

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

                    _handle = trHandle;

                    // Parse status	vector
                    _db.ParseStatusVector(_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);
                    }
                }
            }
        }
コード例 #3
0
        public override void Prepare(string commandText)
        {
            // Clear data
            ClearAll();

            lock (_db)
            {
                // Clear the status vector
                ClearStatusVector();

                // Allocate the statement if needed
                if (_state == StatementState.Deallocated)
                {
                    Allocate();
                }

                // Marshal structures to pointer
                XsqldaMarshaler marshaler = XsqldaMarshaler.Instance;

                // Setup fields	structure
                _fields = new Descriptor(1);

                IntPtr sqlda      = marshaler.MarshalManagedToNative(_db.Charset, _fields);
                int    trHandle   = _transaction.Handle;
                int    stmtHandle = _handle;

                byte[] buffer = _db.Charset.GetBytes(commandText);

                _db.FbClient.isc_dsql_prepare(
                    _statusVector,
                    ref trHandle,
                    ref stmtHandle,
                    (short)buffer.Length,
                    buffer,
                    _db.Dialect,
                    sqlda);

                // Marshal Pointer
                Descriptor descriptor = marshaler.MarshalNativeToManaged(_db.Charset, sqlda);

                // Free	memory
                marshaler.CleanUpNativeData(ref sqlda);

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

                // Describe	fields
                _fields = descriptor;

                if (_fields.ActualCount > 0 && _fields.ActualCount != _fields.Count)
                {
                    Describe();
                }
                else
                {
                    if (_fields.ActualCount == 0)
                    {
                        _fields = new Descriptor(0);
                    }
                }

                // Reset actual	field values
                _fields.ResetValues();

                // Get Statement type
                _statementType = GetStatementType();

                // Update state
                _state = StatementState.Prepared;
            }
        }