public override void Write(byte[] buffer, int offset, int count)
        {
            this.AssertObjectNotDisposed();
            this.AssertConnectionIsOpen();
            if (count < 0)
            {
                throw System.Data.Common.ADP.MustBePositive("count");
            }
            if (offset < 0)
            {
                throw System.Data.Common.ADP.MustBePositive("offset");
            }
            if (buffer == null)
            {
                throw System.Data.Common.ADP.ArgumentNull("buffer");
            }
            if (buffer.Length < (offset + count))
            {
                throw System.Data.Common.ADP.BufferExceeded("count");
            }
            this.AssertTransactionExists();
            if (this.IsNull)
            {
                throw System.Data.Common.ADP.LobWriteInvalidOnNull();
            }
            this.AssertAmountIsValid((long)offset, "offset");
            this.AssertAmountIsValid((long)count, "count");
            this.AssertPositionIsValid();
            OCI.CHARSETFORM csfrm = this._charsetForm;
            ushort          csid  = this.IsCharacterLob ? ((ushort)0x3e8) : ((ushort)0);
            int             amtp  = this.AdjustOffsetToOracle(count);
            int             rc    = 0;

            if (amtp != 0)
            {
                GCHandle handle = new GCHandle();
                try
                {
                    handle = GCHandle.Alloc(buffer, GCHandleType.Pinned);
                    IntPtr bufp = new IntPtr(((long)handle.AddrOfPinnedObject()) + offset);
                    rc = TracedNativeMethods.OCILobWrite(this.ServiceContextHandle, this.ErrorHandle, this.Descriptor, ref amtp, this.CurrentOraclePosition, bufp, (uint)count, 0, csid, csfrm);
                }
                finally
                {
                    if (handle.IsAllocated)
                    {
                        handle.Free();
                    }
                }
                if (rc != 0)
                {
                    this.Connection.CheckError(this.ErrorHandle, rc);
                }
                amtp = this.AdjustOracleToOffset(amtp);
                this._currentPosition += amtp;
            }
        }
Example #2
0
        /// <include file='doc\OracleLob.uex' path='docs/doc[@for="OracleLob.Write"]/*' />
        public override void Write(
            byte[] buffer,
            int offset,
            int count
            )
        {
            AssertObjectNotDisposed();
            AssertConnectionIsOpen();

            if (count < 0)
            {
                throw ADP.MustBePositive("count");
            }

            if (offset < 0)
            {
                throw ADP.MustBePositive("offset");
            }

            if (null == buffer)
            {
                throw ADP.ArgumentNull("buffer");
            }

            if ((long)buffer.Length < ((long)offset + (long)count))
            {
                throw ADP.BufferExceeded();
            }

            AssertTransactionExists();

            if (IsNull)
            {
                throw ADP.LobWriteInvalidOnNull();
            }

            AssertAmountIsValid(offset, "offset");
            AssertAmountIsValid(count, "count");
            AssertPositionIsValid();

            OCI.CHARSETFORM charsetForm = _charsetForm;

            short charsetId = IsCharacterLob ? OCI.OCI_UCS2ID : (short)0;
            int   amount    = AdjustOffsetToOracle(count);
            int   rc        = 0;

            if (0 == amount)
            {
                return;
            }

#if EXPOSELOBBUFFERING
            EnsureBuffering(_bufferedRequested);
#endif //EXPOSELOBBUFFERING

            // We need to pin the buffer and get the address of the offset that
            // the user requested; Oracle doesn't allow us to specify an offset
            // into the buffer.
            GCHandle handle = new GCHandle();

            try
            {
                try
                {
                    handle = GCHandle.Alloc(buffer, GCHandleType.Pinned);
                    IntPtr bufferPtr = new IntPtr((long)handle.AddrOfPinnedObject() + offset);

                    rc = TracedNativeMethods.OCILobWrite(
                        ServiceContextHandle,
                        ErrorHandle,
                        Descriptor,
                        ref amount,
                        CurrentOraclePosition,
                        bufferPtr,
                        count,
                        (byte)OCI.PIECE.OCI_ONE_PIECE,
                        ADP.NullHandleRef,
                        ADP.NullHandleRef,
                        charsetId,
                        charsetForm
                        );
                }
                finally
                {
#if EXPOSELOBBUFFERING
                    if (_isCurrentlyBuffered)
                    {
                        _bufferIsDirty = true;
                    }
#endif //EXPOSELOBBUFFERING

                    if (handle.IsAllocated)
                    {
                        handle.Free();                          // Unpin the buffer
                    }
                }
            }
            catch // Prevent exception filters from running in our space
            {
                throw;
            }

            if (0 != rc)
            {
                Connection.CheckError(ErrorHandle, rc);
            }

            amount            = AdjustOracleToOffset(amount);
            _currentPosition += amount;
        }