Exemplo n.º 1
0
 internal string GetString(NativeBuffer_RowBuffer buffer)
 {
     if (this.IsLob)
     {
         System.Data.OracleClient.OracleType oracleType = this._metaType.OracleType;
         if (((System.Data.OracleClient.OracleType.Clob != oracleType) && (System.Data.OracleClient.OracleType.NClob != oracleType)) && (System.Data.OracleClient.OracleType.BFile != oracleType))
         {
             throw System.Data.Common.ADP.InvalidCast();
         }
         if (this.IsDBNull(buffer))
         {
             throw System.Data.Common.ADP.DataReaderNoData();
         }
         using (OracleLob lob = new OracleLob(this._lobLocator))
         {
             return((string)lob.Value);
         }
     }
     if (typeof(string) != this._metaType.BaseType)
     {
         throw System.Data.Common.ADP.InvalidCast();
     }
     if (this.IsDBNull(buffer))
     {
         throw System.Data.Common.ADP.DataReaderNoData();
     }
     this.FixupLongValueLength(buffer);
     return(OracleString.MarshalToString(buffer, this._valueOffset, this._lengthOffset, this._metaType, this._connection, this._bindAsUTF16, false));
 }
Exemplo n.º 2
0
        internal object GetValue(NativeBuffer_RowBuffer buffer)
        {
            if (this.IsDBNull(buffer))
            {
                return(DBNull.Value);
            }
            switch (this._metaType.OciType)
            {
            case OCI.DATATYPE.VARNUM:
                return(this.GetDecimal(buffer));

            case OCI.DATATYPE.LONG:
            case OCI.DATATYPE.VARCHAR2:
            case OCI.DATATYPE.CHAR:
                return(this.GetString(buffer));

            case OCI.DATATYPE.RAW:
            case OCI.DATATYPE.LONGRAW:
            {
                long   num = this.GetBytes(buffer, 0L, null, 0, 0);
                byte[] destinationBuffer = new byte[num];
                this.GetBytes(buffer, 0L, destinationBuffer, 0, (int)num);
                return(destinationBuffer);
            }

            case OCI.DATATYPE.DATE:
            case OCI.DATATYPE.INT_TIMESTAMP:
            case OCI.DATATYPE.INT_TIMESTAMP_TZ:
            case OCI.DATATYPE.INT_TIMESTAMP_LTZ:
                return(this.GetDateTime(buffer));

            case OCI.DATATYPE.CLOB:
            case OCI.DATATYPE.BLOB:
            {
                using (OracleLob lob = this.GetOracleLob(buffer))
                {
                    return(lob.Value);
                }
            }

            case OCI.DATATYPE.BFILE:
            {
                using (OracleBFile file = this.GetOracleBFile(buffer))
                {
                    return(file.Value);
                }
            }

            case OCI.DATATYPE.INT_INTERVAL_YM:
                return(this.GetInt32(buffer));

            case OCI.DATATYPE.INT_INTERVAL_DS:
                return(this.GetTimeSpan(buffer));
            }
            throw System.Data.Common.ADP.TypeNotSupported(this._metaType.OciType);
        }
Exemplo n.º 3
0
 internal OracleTimeSpan GetOracleTimeSpan(NativeBuffer_RowBuffer buffer)
 {
     if (typeof(OracleTimeSpan) != this._metaType.NoConvertType)
     {
         throw System.Data.Common.ADP.InvalidCast();
     }
     if (this.IsDBNull(buffer))
     {
         return(OracleTimeSpan.Null);
     }
     return(new OracleTimeSpan(buffer, this._valueOffset));
 }
Exemplo n.º 4
0
 internal OracleLob GetOracleLob(NativeBuffer_RowBuffer buffer)
 {
     if (typeof(OracleLob) != this._metaType.NoConvertType)
     {
         throw System.Data.Common.ADP.InvalidCast();
     }
     if (this.IsDBNull(buffer))
     {
         return(OracleLob.Null);
     }
     return(new OracleLob(this._lobLocator));
 }
Exemplo n.º 5
0
 internal OracleDateTime GetOracleDateTime(NativeBuffer_RowBuffer buffer)
 {
     if (typeof(OracleDateTime) != this._metaType.NoConvertType)
     {
         throw System.Data.Common.ADP.InvalidCast();
     }
     if (this.IsDBNull(buffer))
     {
         return(OracleDateTime.Null);
     }
     return(new OracleDateTime(buffer, this._valueOffset, this._lengthOffset, this._metaType, this._connection));
 }
Exemplo n.º 6
0
 internal long GetInt64(NativeBuffer_RowBuffer buffer)
 {
     if (typeof(decimal) != this._metaType.BaseType)
     {
         throw System.Data.Common.ADP.InvalidCast();
     }
     if (this.IsDBNull(buffer))
     {
         throw System.Data.Common.ADP.DataReaderNoData();
     }
     return(OracleNumber.MarshalToInt64(buffer, this._valueOffset, this._connection));
 }
Exemplo n.º 7
0
 internal DateTime GetDateTime(NativeBuffer_RowBuffer buffer)
 {
     if (this.IsDBNull(buffer))
     {
         throw System.Data.Common.ADP.DataReaderNoData();
     }
     if (typeof(DateTime) != this._metaType.BaseType)
     {
         throw System.Data.Common.ADP.InvalidCast();
     }
     return(OracleDateTime.MarshalToDateTime(buffer, this._valueOffset, this._lengthOffset, this._metaType, this._connection));
 }
Exemplo n.º 8
0
 internal TimeSpan GetTimeSpan(NativeBuffer_RowBuffer buffer)
 {
     if (typeof(TimeSpan) != this._metaType.BaseType)
     {
         throw System.Data.Common.ADP.InvalidCast();
     }
     if (this.IsDBNull(buffer))
     {
         throw System.Data.Common.ADP.DataReaderNoData();
     }
     return(OracleTimeSpan.MarshalToTimeSpan(buffer, this._valueOffset));
 }
Exemplo n.º 9
0
 internal OracleString GetOracleString(NativeBuffer_RowBuffer buffer)
 {
     if (typeof(OracleString) != this._metaType.NoConvertType)
     {
         throw System.Data.Common.ADP.InvalidCast();
     }
     if (this.IsDBNull(buffer))
     {
         return(OracleString.Null);
     }
     this.FixupLongValueLength(buffer);
     return(new OracleString(buffer, this._valueOffset, this._lengthOffset, this._metaType, this._connection, this._bindAsUTF16, false));
 }
Exemplo n.º 10
0
 internal OracleBinary GetOracleBinary(NativeBuffer_RowBuffer buffer)
 {
     if (typeof(OracleBinary) != this._metaType.NoConvertType)
     {
         throw System.Data.Common.ADP.InvalidCast();
     }
     this.FixupLongValueLength(buffer);
     if (this.IsDBNull(buffer))
     {
         return(OracleBinary.Null);
     }
     return(new OracleBinary(buffer, this._valueOffset, this._lengthOffset, this._metaType));
 }
Exemplo n.º 11
0
        internal object GetOracleValue(NativeBuffer_RowBuffer buffer)
        {
            switch (this._metaType.OciType)
            {
            case OCI.DATATYPE.VARNUM:
                return(this.GetOracleNumber(buffer));

            case OCI.DATATYPE.LONG:
            case OCI.DATATYPE.VARCHAR2:
            case OCI.DATATYPE.CHAR:
                return(this.GetOracleString(buffer));

            case OCI.DATATYPE.RAW:
            case OCI.DATATYPE.LONGRAW:
                return(this.GetOracleBinary(buffer));

            case OCI.DATATYPE.DATE:
            case OCI.DATATYPE.INT_TIMESTAMP:
            case OCI.DATATYPE.INT_TIMESTAMP_TZ:
            case OCI.DATATYPE.INT_TIMESTAMP_LTZ:
                return(this.GetOracleDateTime(buffer));

            case OCI.DATATYPE.CLOB:
            case OCI.DATATYPE.BLOB:
                return(this.GetOracleLob(buffer));

            case OCI.DATATYPE.BFILE:
                return(this.GetOracleBFile(buffer));

            case OCI.DATATYPE.INT_INTERVAL_YM:
                return(this.GetOracleMonthSpan(buffer));

            case OCI.DATATYPE.INT_INTERVAL_DS:
                return(this.GetOracleTimeSpan(buffer));
            }
            throw System.Data.Common.ADP.TypeNotSupported(this._metaType.OciType);
        }
Exemplo n.º 12
0
 private void Cleanup()
 {
     if (this._buffer != null)
     {
         this._buffer.Dispose();
         this._buffer = null;
     }
     if (this._columnInfo != null)
     {
         if (this._refCursorDataReaders == null)
         {
             int length = this._columnInfo.Length;
             while (--length >= 0)
             {
                 if (this._columnInfo[length] != null)
                 {
                     this._columnInfo[length].Dispose();
                     this._columnInfo[length] = null;
                 }
             }
         }
         this._columnInfo = null;
     }
 }
 private object ExecuteScalarInternal(bool needCLStype, bool needRowid, out OciRowidDescriptor rowidDescriptor)
 {
     OciStatementHandle statementHandle = null;
     object oracleValue = null;
     int rc = 0;
     try
     {
         statementHandle = this.GetStatementHandle();
         ArrayList resultParameterOrdinals = new ArrayList();
         this.Execute(statementHandle, CommandBehavior.Default, needRowid, out rowidDescriptor, out resultParameterOrdinals);
         if (OCI.STMT.OCI_STMT_SELECT != this._statementType)
         {
             return oracleValue;
         }
         OracleColumn column = new OracleColumn(statementHandle, 0, this.ErrorHandle, this._connection);
         int offset = 0;
         bool success = false;
         bool mustRelease = false;
         SafeHandle handleToBind = null;
         column.Describe(ref offset, this._connection, this.ErrorHandle);
         NativeBuffer_RowBuffer buffer = new NativeBuffer_RowBuffer(offset, 1);
         RuntimeHelpers.PrepareConstrainedRegions();
         try
         {
             buffer.DangerousAddRef(ref success);
             column.Bind(statementHandle, buffer, this.ErrorHandle, 0);
             column.Rebind(this._connection, ref mustRelease, ref handleToBind);
             rc = TracedNativeMethods.OCIStmtFetch(statementHandle, this.ErrorHandle, 1, OCI.FETCH.OCI_FETCH_NEXT, OCI.MODE.OCI_DEFAULT);
             if (100 != rc)
             {
                 if (rc != 0)
                 {
                     this.Connection.CheckError(this.ErrorHandle, rc);
                 }
                 if (needCLStype)
                 {
                     oracleValue = column.GetValue(buffer);
                 }
                 else
                 {
                     oracleValue = column.GetOracleValue(buffer);
                 }
             }
         }
         finally
         {
             if (mustRelease)
             {
                 handleToBind.DangerousRelease();
             }
             if (success)
             {
                 buffer.DangerousRelease();
             }
         }
         GC.KeepAlive(column);
     }
     finally
     {
         if (statementHandle != null)
         {
             this.ReleaseStatementHandle(statementHandle);
         }
     }
     return oracleValue;
 }
Exemplo n.º 14
0
        private bool ReadInternal()
        {
            int  num;
            bool flag;

            if (this._endOfData)
            {
                return(false);
            }
            int length = this._columnInfo.Length;
            NativeBuffer_RowBuffer buffer = this._buffer;
            bool success = false;

            bool[]       flagArray   = new bool[length];
            SafeHandle[] handleArray = new SafeHandle[length];
            RuntimeHelpers.PrepareConstrainedRegions();
            try
            {
                if (buffer == null)
                {
                    int rowBufferLength = (this._rowsToPrefetch > 1) ? this._rowBufferLength : 0;
                    buffer = new NativeBuffer_RowBuffer(this._rowBufferLength, this._rowsToPrefetch);
                    buffer.DangerousAddRef(ref success);
                    for (num = 0; num < length; num++)
                    {
                        this._columnInfo[num].Bind(this._statementHandle, buffer, this.ErrorHandle, rowBufferLength);
                    }
                    this._buffer = buffer;
                }
                else
                {
                    buffer.DangerousAddRef(ref success);
                }
                if (buffer.MoveNext())
                {
                    return(true);
                }
                if (this._isLastBuffer)
                {
                    this._endOfData = true;
                    return(false);
                }
                buffer.MoveFirst();
                if (1 == this._rowsToPrefetch)
                {
                    for (num = 0; num < length; num++)
                    {
                        this._columnInfo[num].Rebind(this._connection, ref flagArray[num], ref handleArray[num]);
                    }
                }
                int rc   = TracedNativeMethods.OCIStmtFetch(this._statementHandle, this.ErrorHandle, this._rowsToPrefetch, OCI.FETCH.OCI_FETCH_NEXT, OCI.MODE.OCI_DEFAULT);
                int num5 = this._rowsTotal;
                this._statementHandle.GetAttribute(OCI.ATTR.OCI_ATTR_ROW_COUNT, out this._rowsTotal, this.ErrorHandle);
                if (rc == 0)
                {
                    return(true);
                }
                if (1 == rc)
                {
                    this._connection.CheckError(this.ErrorHandle, rc);
                    return(true);
                }
                if (100 == rc)
                {
                    int num4 = this._rowsTotal - num5;
                    if (num4 == 0)
                    {
                        if (this._rowsTotal == 0)
                        {
                            this._hasRows = 1;
                        }
                        this._endOfData = true;
                        return(false);
                    }
                    buffer.NumberOfRows = num4;
                    this._isLastBuffer  = true;
                    return(true);
                }
                this._endOfData = true;
                this._connection.CheckError(this.ErrorHandle, rc);
                flag = false;
            }
            finally
            {
                if (1 == this._rowsToPrefetch)
                {
                    for (num = 0; num < length; num++)
                    {
                        if (flagArray[num])
                        {
                            handleArray[num].DangerousRelease();
                        }
                    }
                }
                if (success)
                {
                    buffer.DangerousRelease();
                }
            }
            return(flag);
        }
        private object ExecuteScalarInternal(bool needCLStype, bool needRowid, out OciRowidDescriptor rowidDescriptor)
        {
            OciStatementHandle statementHandle = null;
            object             oracleValue     = null;
            int rc = 0;

            try
            {
                statementHandle = this.GetStatementHandle();
                ArrayList resultParameterOrdinals = new ArrayList();
                this.Execute(statementHandle, CommandBehavior.Default, needRowid, out rowidDescriptor, out resultParameterOrdinals);
                if (OCI.STMT.OCI_STMT_SELECT != this._statementType)
                {
                    return(oracleValue);
                }
                OracleColumn column       = new OracleColumn(statementHandle, 0, this.ErrorHandle, this._connection);
                int          offset       = 0;
                bool         success      = false;
                bool         mustRelease  = false;
                SafeHandle   handleToBind = null;
                column.Describe(ref offset, this._connection, this.ErrorHandle);
                NativeBuffer_RowBuffer buffer = new NativeBuffer_RowBuffer(offset, 1);
                RuntimeHelpers.PrepareConstrainedRegions();
                try
                {
                    buffer.DangerousAddRef(ref success);
                    column.Bind(statementHandle, buffer, this.ErrorHandle, 0);
                    column.Rebind(this._connection, ref mustRelease, ref handleToBind);
                    rc = TracedNativeMethods.OCIStmtFetch(statementHandle, this.ErrorHandle, 1, OCI.FETCH.OCI_FETCH_NEXT, OCI.MODE.OCI_DEFAULT);
                    if (100 != rc)
                    {
                        if (rc != 0)
                        {
                            this.Connection.CheckError(this.ErrorHandle, rc);
                        }
                        if (needCLStype)
                        {
                            oracleValue = column.GetValue(buffer);
                        }
                        else
                        {
                            oracleValue = column.GetOracleValue(buffer);
                        }
                    }
                }
                finally
                {
                    if (mustRelease)
                    {
                        handleToBind.DangerousRelease();
                    }
                    if (success)
                    {
                        buffer.DangerousRelease();
                    }
                }
                GC.KeepAlive(column);
            }
            finally
            {
                if (statementHandle != null)
                {
                    this.ReleaseStatementHandle(statementHandle);
                }
            }
            return(oracleValue);
        }
Exemplo n.º 16
0
        private bool ReadInternal()
        {
            if (_endOfData)
            {
                return(false);
            }

            int rc;
            int columnCount = _columnInfo.Length;
            int i;

            // Define each of the column buffers to Oracle, but only if it hasn't
            // been defined before.
            if (null == _buffer)
            {
                int templen = (_rowsToPrefetch > 1) ? _rowBufferLength : 0;  // Only tell oracle about the buffer length if we intend to fetch more rows

                NativeBuffer buffer = new NativeBuffer_RowBuffer(_rowBufferLength);
                buffer.NumberOfRows = _rowsToPrefetch;

                for (i = 0; i < columnCount; ++i)
                {
                    _columnInfo[i].Bind(_statementHandle, buffer, ErrorHandle, templen);
                }

                _buffer = buffer;
            }

            // If we still have more data in the buffers we've pre-fetched, then
            // we'll use it; we don't want to go to the server more than we absolutely
            // have to.
            if (_buffer.MoveNext())
            {
                return(true);
            }

            // If we've read the last buffer, and we've exhausted it, then we're
            // really at the end of the data.
            if (_isLastBuffer)
            {
                _endOfData = true;
                return(false);
            }

            // Reset the buffer back to the beginning.
            _buffer.MoveFirst();

            // For LONG and LOB data, we have to do work to prepare for each row (that's
            // why we don't prefetch rows that have these data types)
            if (1 == _rowsToPrefetch)
            {
                for (i = 0; i < columnCount; ++i)
                {
                    _columnInfo[i].Rebind(_connection);
                }
            }

            // Now fetch the rows required.
            Debug.Assert(0 < _rowsToPrefetch, "fetching 0 rows will cancel the cursor");
            rc = TracedNativeMethods.OCIStmtFetch(
                _statementHandle,                               // stmtp
                ErrorHandle,                                    // errhp
                _rowsToPrefetch,                                // crows
                OCI.FETCH.OCI_FETCH_NEXT,                       // orientation
                OCI.MODE.OCI_DEFAULT                            // mode
                );

            // Keep track of how many rows we actually fetched so far.
            int previousRowsTotal = _rowsTotal;

            _statementHandle.GetAttribute(OCI.ATTR.OCI_ATTR_ROW_COUNT, out _rowsTotal, ErrorHandle);

            if (0 == rc)
            {
                return(true);
            }

            if ((int)OCI.RETURNCODE.OCI_SUCCESS_WITH_INFO == rc)
            {
                _connection.CheckError(ErrorHandle, rc);
                return(true);
            }
            if ((int)OCI.RETURNCODE.OCI_NO_DATA == rc)
            {
                int rowsFetched = _rowsTotal - previousRowsTotal;

                if (0 == rowsFetched)
                {
                    if (0 == _rowsTotal)
                    {
                        _hasRows = x_hasRows_False;
                    }

                    _endOfData = true;
                    return(false);
                }

                _buffer.NumberOfRows = rowsFetched;
                _isLastBuffer        = true;
                return(true);
            }

            _endOfData = true;
            _connection.CheckError(ErrorHandle, rc);
            return(false);
        }
Exemplo n.º 17
0
 internal bool IsDBNull(NativeBuffer_RowBuffer buffer)
 {
     return(this._isNullable && (buffer.ReadInt16(this._indicatorOffset) == -1));
 }
Exemplo n.º 18
0
        internal void Bind(OciStatementHandle statementHandle, NativeBuffer_RowBuffer buffer, OciErrorHandle errorHandle, int rowBufferLength)
        {
            OciDefineHandle defnp = null;
            int             num3;

            OCI.MODE     mode    = OCI.MODE.OCI_DEFAULT;
            OCI.DATATYPE ociType = this._metaType.OciType;
            this._rowBuffer = buffer;
            if (this._metaType.IsLong)
            {
                mode = OCI.MODE.OCI_DATA_AT_EXEC;
                num3 = 0x7fffffff;
            }
            else
            {
                num3 = this._byteSize;
            }
            IntPtr zero    = IntPtr.Zero;
            IntPtr rlenp   = IntPtr.Zero;
            IntPtr dataPtr = this._rowBuffer.DangerousGetDataPtr(this._valueOffset);

            if (-1 != this._indicatorOffset)
            {
                zero = this._rowBuffer.DangerousGetDataPtr(this._indicatorOffset);
            }
            if ((-1 != this._lengthOffset) && !this._metaType.IsLong)
            {
                rlenp = this._rowBuffer.DangerousGetDataPtr(this._lengthOffset);
            }
            try
            {
                IntPtr ptr3;
                int    rc = TracedNativeMethods.OCIDefineByPos(statementHandle, out ptr3, errorHandle, ((uint)this._ordinal) + 1, dataPtr, num3, ociType, zero, rlenp, IntPtr.Zero, mode);
                if (rc != 0)
                {
                    this._connection.CheckError(errorHandle, rc);
                }
                defnp = new OciDefineHandle(statementHandle, ptr3);
                if (rowBufferLength != 0)
                {
                    uint pvskip  = (uint)rowBufferLength;
                    uint indskip = (-1 != this._indicatorOffset) ? pvskip : 0;
                    uint rlskip  = ((-1 != this._lengthOffset) && !this._metaType.IsLong) ? pvskip : 0;
                    rc = TracedNativeMethods.OCIDefineArrayOfStruct(defnp, errorHandle, pvskip, indskip, rlskip, 0);
                    if (rc != 0)
                    {
                        this._connection.CheckError(errorHandle, rc);
                    }
                }
                if (this._metaType.UsesNationalCharacterSet)
                {
                    defnp.SetAttribute(OCI.ATTR.OCI_ATTR_CHARSET_FORM, 2, errorHandle);
                }
                if (!this._connection.UnicodeEnabled && this._bindAsUTF16)
                {
                    defnp.SetAttribute(OCI.ATTR.OCI_ATTR_CHARSET_ID, 0x3e8, errorHandle);
                }
                if (this._metaType.IsLong)
                {
                    this._rowBuffer.WriteIntPtr(this._valueOffset, IntPtr.Zero);
                    this._callback = new OCI.Callback.OCICallbackDefine(this._callback_GetColumnPiecewise);
                    rc             = TracedNativeMethods.OCIDefineDynamic(defnp, errorHandle, IntPtr.Zero, this._callback);
                    if (rc != 0)
                    {
                        this._connection.CheckError(errorHandle, rc);
                    }
                }
            }
            finally
            {
                NativeBuffer.SafeDispose(ref this._longBuffer);
                OciHandle.SafeDispose(ref defnp);
            }
        }
 private void Cleanup()
 {
     if (this._buffer != null)
     {
         this._buffer.Dispose();
         this._buffer = null;
     }
     if (this._columnInfo != null)
     {
         if (this._refCursorDataReaders == null)
         {
             int length = this._columnInfo.Length;
             while (--length >= 0)
             {
                 if (this._columnInfo[length] != null)
                 {
                     this._columnInfo[length].Dispose();
                     this._columnInfo[length] = null;
                 }
             }
         }
         this._columnInfo = null;
     }
 }
Exemplo n.º 20
0
        internal long GetChars(NativeBuffer_RowBuffer buffer, long fieldOffset, char[] destinationBuffer, int destinationOffset, int length)
        {
            int num;

            if (length < 0)
            {
                throw System.Data.Common.ADP.InvalidDataLength((long)length);
            }
            if ((destinationOffset < 0) || ((destinationBuffer != null) && (destinationOffset >= destinationBuffer.Length)))
            {
                throw System.Data.Common.ADP.InvalidDestinationBufferIndex(destinationBuffer.Length, destinationOffset, "bufferoffset");
            }
            if ((0L > fieldOffset) || (0xffffffffL < fieldOffset))
            {
                throw System.Data.Common.ADP.InvalidSourceOffset("fieldOffset", 0L, 0xffffffffL);
            }
            if (this.IsLob)
            {
                System.Data.OracleClient.OracleType oracleType = this._metaType.OracleType;
                if (((System.Data.OracleClient.OracleType.Clob != oracleType) && (System.Data.OracleClient.OracleType.NClob != oracleType)) && (System.Data.OracleClient.OracleType.BFile != oracleType))
                {
                    throw System.Data.Common.ADP.InvalidCast();
                }
                if (this.IsDBNull(buffer))
                {
                    throw System.Data.Common.ADP.DataReaderNoData();
                }
                using (OracleLob lob = new OracleLob(this._lobLocator))
                {
                    string str        = (string)lob.Value;
                    int    maxLen     = str.Length;
                    int    startIndex = (int)fieldOffset;
                    if (startIndex < 0)
                    {
                        throw System.Data.Common.ADP.InvalidSourceBufferIndex(maxLen, (long)startIndex, "fieldOffset");
                    }
                    num = maxLen - startIndex;
                    if (destinationBuffer != null)
                    {
                        num = Math.Min(num, length);
                        if (0 < num)
                        {
                            Buffer.BlockCopy(str.ToCharArray(startIndex, num), 0, destinationBuffer, destinationOffset, num);
                        }
                    }
                    goto Label_0198;
                }
            }
            if ((((System.Data.OracleClient.OracleType.Char != this.OracleType) && (System.Data.OracleClient.OracleType.VarChar != this.OracleType)) && ((System.Data.OracleClient.OracleType.LongVarChar != this.OracleType) && (System.Data.OracleClient.OracleType.NChar != this.OracleType))) && (System.Data.OracleClient.OracleType.NVarChar != this.OracleType))
            {
                throw System.Data.Common.ADP.InvalidCast();
            }
            if (this.IsDBNull(buffer))
            {
                throw System.Data.Common.ADP.DataReaderNoData();
            }
            this.FixupLongValueLength(buffer);
            int num5         = OracleString.GetLength(buffer, this._lengthOffset, this._metaType);
            int sourceOffset = (int)fieldOffset;

            num = num5 - sourceOffset;
            if (destinationBuffer != null)
            {
                num = Math.Min(num, length);
                if (0 < num)
                {
                    OracleString.GetChars(buffer, this._valueOffset, this._lengthOffset, this._metaType, this._connection, this._bindAsUTF16, sourceOffset, destinationBuffer, destinationOffset, num);
                }
            }
Label_0198:
            return((long)Math.Max(0, num));
        }
 private bool ReadInternal()
 {
     int num;
     bool flag;
     if (this._endOfData)
     {
         return false;
     }
     int length = this._columnInfo.Length;
     NativeBuffer_RowBuffer buffer = this._buffer;
     bool success = false;
     bool[] flagArray = new bool[length];
     SafeHandle[] handleArray = new SafeHandle[length];
     RuntimeHelpers.PrepareConstrainedRegions();
     try
     {
         if (buffer == null)
         {
             int rowBufferLength = (this._rowsToPrefetch > 1) ? this._rowBufferLength : 0;
             buffer = new NativeBuffer_RowBuffer(this._rowBufferLength, this._rowsToPrefetch);
             buffer.DangerousAddRef(ref success);
             for (num = 0; num < length; num++)
             {
                 this._columnInfo[num].Bind(this._statementHandle, buffer, this.ErrorHandle, rowBufferLength);
             }
             this._buffer = buffer;
         }
         else
         {
             buffer.DangerousAddRef(ref success);
         }
         if (buffer.MoveNext())
         {
             return true;
         }
         if (this._isLastBuffer)
         {
             this._endOfData = true;
             return false;
         }
         buffer.MoveFirst();
         if (1 == this._rowsToPrefetch)
         {
             for (num = 0; num < length; num++)
             {
                 this._columnInfo[num].Rebind(this._connection, ref flagArray[num], ref handleArray[num]);
             }
         }
         int rc = TracedNativeMethods.OCIStmtFetch(this._statementHandle, this.ErrorHandle, this._rowsToPrefetch, OCI.FETCH.OCI_FETCH_NEXT, OCI.MODE.OCI_DEFAULT);
         int num5 = this._rowsTotal;
         this._statementHandle.GetAttribute(OCI.ATTR.OCI_ATTR_ROW_COUNT, out this._rowsTotal, this.ErrorHandle);
         if (rc == 0)
         {
             return true;
         }
         if (1 == rc)
         {
             this._connection.CheckError(this.ErrorHandle, rc);
             return true;
         }
         if (100 == rc)
         {
             int num4 = this._rowsTotal - num5;
             if (num4 == 0)
             {
                 if (this._rowsTotal == 0)
                 {
                     this._hasRows = 1;
                 }
                 this._endOfData = true;
                 return false;
             }
             buffer.NumberOfRows = num4;
             this._isLastBuffer = true;
             return true;
         }
         this._endOfData = true;
         this._connection.CheckError(this.ErrorHandle, rc);
         flag = false;
     }
     finally
     {
         if (1 == this._rowsToPrefetch)
         {
             for (num = 0; num < length; num++)
             {
                 if (flagArray[num])
                 {
                     handleArray[num].DangerousRelease();
                 }
             }
         }
         if (success)
         {
             buffer.DangerousRelease();
         }
     }
     return flag;
 }
Exemplo n.º 22
0
        internal long GetBytes(NativeBuffer_RowBuffer buffer, long fieldOffset, byte[] destinationBuffer, int destinationOffset, int length)
        {
            int num;

            if (length < 0)
            {
                throw System.Data.Common.ADP.InvalidDataLength((long)length);
            }
            if ((destinationOffset < 0) || ((destinationBuffer != null) && (destinationOffset >= destinationBuffer.Length)))
            {
                throw System.Data.Common.ADP.InvalidDestinationBufferIndex(destinationBuffer.Length, destinationOffset, "bufferoffset");
            }
            if ((0L > fieldOffset) || (0xffffffffL < fieldOffset))
            {
                throw System.Data.Common.ADP.InvalidSourceOffset("fieldOffset", 0L, 0xffffffffL);
            }
            if (this.IsLob)
            {
                System.Data.OracleClient.OracleType oracleType = this._metaType.OracleType;
                if ((System.Data.OracleClient.OracleType.Blob != oracleType) && (System.Data.OracleClient.OracleType.BFile != oracleType))
                {
                    throw System.Data.Common.ADP.InvalidCast();
                }
                if (this.IsDBNull(buffer))
                {
                    throw System.Data.Common.ADP.DataReaderNoData();
                }
                using (OracleLob lob = new OracleLob(this._lobLocator))
                {
                    uint num3 = (uint)lob.Length;
                    uint num2 = (uint)fieldOffset;
                    if (num2 > num3)
                    {
                        throw System.Data.Common.ADP.InvalidSourceBufferIndex((int)num3, (long)num2, "fieldOffset");
                    }
                    num = (int)(num3 - num2);
                    if (destinationBuffer != null)
                    {
                        num = Math.Min(num, length);
                        if (0 < num)
                        {
                            lob.Seek((long)num2, SeekOrigin.Begin);
                            lob.Read(destinationBuffer, destinationOffset, num);
                        }
                    }
                    goto Label_0155;
                }
            }
            if ((System.Data.OracleClient.OracleType.Raw != this.OracleType) && (System.Data.OracleClient.OracleType.LongRaw != this.OracleType))
            {
                throw System.Data.Common.ADP.InvalidCast();
            }
            if (this.IsDBNull(buffer))
            {
                throw System.Data.Common.ADP.DataReaderNoData();
            }
            this.FixupLongValueLength(buffer);
            int num5         = OracleBinary.GetLength(buffer, this._lengthOffset, this._metaType);
            int sourceOffset = (int)fieldOffset;

            num = num5 - sourceOffset;
            if (destinationBuffer != null)
            {
                num = Math.Min(num, length);
                if (0 < num)
                {
                    OracleBinary.GetBytes(buffer, this._valueOffset, this._metaType, sourceOffset, destinationBuffer, destinationOffset, num);
                }
            }
Label_0155:
            return((long)Math.Max(0, num));
        }