コード例 #1
0
        internal static byte[] GetBytesFromBuffer(NativeBuffer buffer, int valueOffset, int lengthOffset, MetaType metaType, OracleConnection connection)
        {
            uint num2;

            OCI.DATATYPE ociType = metaType.OciType;
            short        length  = buffer.ReadInt16(lengthOffset);

            OCI.DATATYPE datatype = ociType;
            if (datatype == OCI.DATATYPE.DATE)
            {
                num2 = 7;
            }
            else if (datatype == OCI.DATATYPE.INT_TIMESTAMP)
            {
                num2 = 11;
            }
            else if (datatype == OCI.DATATYPE.INT_TIMESTAMP_LTZ)
            {
                num2 = 13;
            }
            else
            {
                num2 = 13;
            }
            byte[] destination = new byte[num2];
            buffer.ReadBytes(valueOffset, destination, 0, length);
            if (OCI.DATATYPE.INT_TIMESTAMP_LTZ == ociType)
            {
                TimeSpan serverTimeZoneAdjustmentToUTC = connection.ServerTimeZoneAdjustmentToUTC;
                destination[11] = (byte)(serverTimeZoneAdjustmentToUTC.Hours + 20);
                destination[12] = (byte)(serverTimeZoneAdjustmentToUTC.Minutes + 60);
                return(destination);
            }
            if ((OCI.DATATYPE.INT_TIMESTAMP_TZ == ociType) && (0x80 < destination[11]))
            {
                sbyte num3;
                sbyte num4;
                OciIntervalDescriptor reftz    = new OciIntervalDescriptor(connection.EnvironmentHandle);
                OciDateTimeDescriptor datetime = new OciDateTimeDescriptor(connection.EnvironmentHandle, OCI.HTYPE.OCI_DTYPE_TIMESTAMP_TZ);
                int rc = System.Data.Common.UnsafeNativeMethods.OCIDateTimeFromArray(connection.EnvironmentHandle, connection.ErrorHandle, destination, num2, 0xbc, datetime, reftz, 0);
                if (rc != 0)
                {
                    connection.CheckError(connection.ErrorHandle, rc);
                }
                rc = System.Data.Common.UnsafeNativeMethods.OCIDateTimeGetTimeZoneOffset(connection.EnvironmentHandle, connection.ErrorHandle, datetime, out num4, out num3);
                if (rc != 0)
                {
                    connection.CheckError(connection.ErrorHandle, rc);
                }
                destination[11] = (byte)(num4 + 20);
                destination[12] = (byte)(num3 + 60);
            }
            return(destination);
        }
コード例 #2
0
        internal static byte[] GetBytesFromDescriptor(OciDateTimeDescriptor dateTimeDescriptor, MetaType metaType, OracleConnection connection)
        {
            uint num2;

            OCI.DATATYPE ociType   = metaType.OciType;
            OCI.DATATYPE datatype2 = ociType;
            if (datatype2 == OCI.DATATYPE.INT_TIMESTAMP)
            {
                num2 = 11;
            }
            else if (datatype2 == OCI.DATATYPE.INT_TIMESTAMP_LTZ)
            {
                num2 = 13;
            }
            else
            {
                num2 = 13;
            }
            byte[] outarray             = new byte[num2];
            uint   len                  = num2;
            OciIntervalDescriptor reftz = new OciIntervalDescriptor(connection.EnvironmentHandle);
            int rc = System.Data.Common.UnsafeNativeMethods.OCIDateTimeToArray(connection.EnvironmentHandle, connection.ErrorHandle, dateTimeDescriptor, reftz, outarray, ref len, 9);

            if (rc != 0)
            {
                connection.CheckError(connection.ErrorHandle, rc);
            }
            if (OCI.DATATYPE.INT_TIMESTAMP_LTZ == ociType)
            {
                TimeSpan serverTimeZoneAdjustmentToUTC = connection.ServerTimeZoneAdjustmentToUTC;
                outarray[11] = (byte)(serverTimeZoneAdjustmentToUTC.Hours + 20);
                outarray[12] = (byte)(serverTimeZoneAdjustmentToUTC.Minutes + 60);
                return(outarray);
            }
            if (OCI.DATATYPE.INT_TIMESTAMP_TZ == ociType)
            {
                sbyte num3;
                sbyte num4;
                rc = System.Data.Common.UnsafeNativeMethods.OCIDateTimeGetTimeZoneOffset(connection.EnvironmentHandle, connection.ErrorHandle, dateTimeDescriptor, out num4, out num3);
                if (rc != 0)
                {
                    connection.CheckError(connection.ErrorHandle, rc);
                }
                outarray[11] = (byte)(num4 + 20);
                outarray[12] = (byte)(num3 + 60);
            }
            return(outarray);
        }
コード例 #3
0
 internal OracleLob(OracleConnection connection, OracleType oracleType)
 {
     this._lobLocator = new OciLobLocator(connection, oracleType);
     this._lobType = oracleType;
     this._charsetForm = (OracleType.NClob == this._lobType) ? OCI.CHARSETFORM.SQLCS_NCHAR : OCI.CHARSETFORM.SQLCS_IMPLICIT;
     this._isTemporaryState = 1;
     OCI.LOB_TYPE lobtype = (OracleType.Blob == oracleType) ? OCI.LOB_TYPE.OCI_TEMP_BLOB : OCI.LOB_TYPE.OCI_TEMP_CLOB;
     int rc = TracedNativeMethods.OCILobCreateTemporary(connection.ServiceContextHandle, connection.ErrorHandle, this._lobLocator.Descriptor, 0, this._charsetForm, lobtype, 0, OCI.DURATION.OCI_DURATION_BEGIN);
     if (rc != 0)
     {
         connection.CheckError(this.ErrorHandle, rc);
     }
 }
コード例 #4
0
        internal OracleLob(OracleConnection connection, OracleType oracleType)
        {
            this._lobLocator       = new OciLobLocator(connection, oracleType);
            this._lobType          = oracleType;
            this._charsetForm      = (OracleType.NClob == this._lobType) ? OCI.CHARSETFORM.SQLCS_NCHAR : OCI.CHARSETFORM.SQLCS_IMPLICIT;
            this._isTemporaryState = 1;
            OCI.LOB_TYPE lobtype = (OracleType.Blob == oracleType) ? OCI.LOB_TYPE.OCI_TEMP_BLOB : OCI.LOB_TYPE.OCI_TEMP_CLOB;
            int          rc      = TracedNativeMethods.OCILobCreateTemporary(connection.ServiceContextHandle, connection.ErrorHandle, this._lobLocator.Descriptor, 0, this._charsetForm, lobtype, 0, OCI.DURATION.OCI_DURATION_BEGIN);

            if (rc != 0)
            {
                connection.CheckError(this.ErrorHandle, rc);
            }
        }
コード例 #5
0
        internal static OciDateTimeDescriptor CreateDescriptor(OCI.DATATYPE ociType, OracleConnection connection, object value)
        {
            byte[]       buffer;
            OCI.DATATYPE tIMESTAMP;
            if (value is OracleDateTime)
            {
                buffer = ((OracleDateTime)value)._value;
            }
            else
            {
                DateTime       dt    = (DateTime)value;
                OracleDateTime time2 = new OracleDateTime(dt);
                buffer = time2._value;
            }
            switch (ociType)
            {
            case OCI.DATATYPE.INT_TIMESTAMP:
                tIMESTAMP = OCI.DATATYPE.TIMESTAMP;
                break;

            case OCI.DATATYPE.INT_TIMESTAMP_LTZ:
                tIMESTAMP = OCI.DATATYPE.TIMESTAMP_LTZ;
                break;

            default:
            {
                tIMESTAMP = OCI.DATATYPE.TIMESTAMP_TZ;
                TimeSpan serverTimeZoneAdjustmentToUTC = connection.ServerTimeZoneAdjustmentToUTC;
                if (buffer.Length < 13)
                {
                    byte[] dst = new byte[13];
                    Buffer.BlockCopy(buffer, 0, dst, 0, buffer.Length);
                    buffer     = dst;
                    buffer[11] = (byte)(20 + serverTimeZoneAdjustmentToUTC.Hours);
                    buffer[12] = (byte)(60 + serverTimeZoneAdjustmentToUTC.Minutes);
                }
                break;
            }
            }
            OciDateTimeDescriptor datetime = CreateEmptyDescriptor(ociType, connection);
            OciIntervalDescriptor reftz    = new OciIntervalDescriptor(connection.EnvironmentHandle);
            int rc = System.Data.Common.UnsafeNativeMethods.OCIDateTimeFromArray(connection.EnvironmentHandle, connection.ErrorHandle, buffer, (uint)buffer.Length, (byte)tIMESTAMP, datetime, reftz, 9);

            if (rc != 0)
            {
                connection.CheckError(connection.ErrorHandle, rc);
            }
            return(datetime);
        }
コード例 #6
0
        internal void Bind(
            OciHandle statementHandle,
            NativeBuffer buffer,
            OciHandle errorHandle,
            int rowBufferLength
            )
        {
            //  Binds the buffer for the column to the statement handle specified.

            OciHandle defineHandle = null;
            IntPtr    h;

            OCI.MODE mode = OCI.MODE.OCI_DEFAULT;
            int      bindSize;

            OCI.DATATYPE ociType = _metaType.OciType;

            _rowBuffer = buffer;

            if (_metaType.IsLong)
            {
                mode     = OCI.MODE.OCI_DYNAMIC_FETCH;
                bindSize = Int32.MaxValue;
            }
            else
            {
                bindSize = _size;
            }

            HandleRef indicatorLocation = ADP.NullHandleRef;
            HandleRef lengthLocation    = ADP.NullHandleRef;
            HandleRef valueLocation     = _rowBuffer.PtrOffset(_valueOffset);

            if (-1 != _indicatorOffset)
            {
                indicatorLocation = _rowBuffer.PtrOffset(_indicatorOffset);
            }

            if (-1 != _lengthOffset && !_metaType.IsLong)
            {
                lengthLocation = _rowBuffer.PtrOffset(_lengthOffset);
            }

            try
            {
                try
                {
                    int rc = TracedNativeMethods.OCIDefineByPos(
                        statementHandle,                                    // hndlp
                        out h,                                              // defnpp
                        errorHandle,                                        // errhp
                        _ordinal + 1,                                       // position
                        valueLocation,                                      // valuep
                        bindSize,                                           // value_sz
                        ociType,                                            // htype
                        indicatorLocation,                                  // indp,
                        lengthLocation,                                     // rlenp,
                        ADP.NullHandleRef,                                  // rcodep,
                        mode                                                // mode
                        );
                    if (rc != 0)
                    {
                        _connection.CheckError(errorHandle, rc);
                    }

                    defineHandle = new OciDefineHandle(statementHandle, h);

                    if (0 != rowBufferLength)
                    {
                        int valOffset = rowBufferLength;
                        int indOffset = (-1 != _indicatorOffset) ? rowBufferLength : 0;
                        int lenOffset = (-1 != _lengthOffset && !_metaType.IsLong) ? rowBufferLength : 0;

                        rc = TracedNativeMethods.OCIDefineArrayOfStruct(
                            defineHandle,
                            errorHandle,
                            valOffset,
                            indOffset,
                            lenOffset,
                            0                            // never use rcodep above...
                            );
                        if (rc != 0)
                        {
                            _connection.CheckError(errorHandle, rc);
                        }
                    }

                    if (!_connection.UnicodeEnabled)
                    {
                        if (_metaType.UsesNationalCharacterSet)
                        {
                            Debug.Assert(!_metaType.IsLong, "LONG data may never be bound as NCHAR");
                            // NOTE:    the order is important here; setting charsetForm will
                            //          reset charsetId (I found this out the hard way...)
                            defineHandle.SetAttribute(OCI.ATTR.OCI_ATTR_CHARSET_FORM, (int)OCI.CHARSETFORM.SQLCS_NCHAR, errorHandle);
                        }
                        if (_bindAsUCS2)
                        {
                            // NOTE:    the order is important here; setting charsetForm will
                            //          reset charsetId (I found this out the hard way...)
                            defineHandle.SetAttribute(OCI.ATTR.OCI_ATTR_CHARSET_ID, OCI.OCI_UCS2ID, errorHandle);
                        }
                    }
                    if (_metaType.IsLong)
                    {
                        // Initialize the longBuffer in the rowBuffer to null
                        Marshal.WriteIntPtr((IntPtr)_rowBuffer.PtrOffset(_valueOffset), IntPtr.Zero);

                        if (null != _longBuffer)
                        {
                            _longBuffer.Dispose();
                            _longBuffer = null;
                        }

                        // We require MTxOCI8 to be in the path somewhere for us to handle LONG data
                        if (!OCI.IsNewMtxOci8Installed)
#if EVERETT
                        { throw ADP.MustInstallNewMtxOciLONG(); }
#else //!EVERETT        {
                            throw ADP.MustInstallNewMtxOci();
                        }
#endif //!EVERETT
                        _callback = new OCI.Callback.OCICallbackDefine(_callback_GetColumnPiecewise);

                        rc = TracedNativeMethods.MTxOciDefineDynamic(
                            defineHandle,                               // defnp
                            errorHandle,                                // errhp
                            ADP.NullHandleRef,                          // dvoid *octxp,
                            _callback                                   // OCICallbackDefine ocbfp
                            );
                        if (rc != 0)
                        {
                            _connection.CheckError(errorHandle, rc);
                        }
                    }
                }
                finally
                {
                    // We don't need this any longer, get rid of it.
                    OciHandle.SafeDispose(ref defineHandle);
                }
            }
コード例 #7
0
 internal static OracleString GetPersistedRowid(OracleConnection connection, OciRowidDescriptor rowidHandle)
 {
     OracleString @null = OracleString.Null;
     if (rowidHandle != null)
     {
         OciErrorHandle errorHandle = connection.ErrorHandle;
         NativeBuffer scratchBuffer = connection.GetScratchBuffer(0xf82);
         bool success = false;
         bool flag = false;
         RuntimeHelpers.PrepareConstrainedRegions();
         try
         {
             int num;
             scratchBuffer.DangerousAddRef(ref success);
             if (OCI.ClientVersionAtLeastOracle9i)
             {
                 int length = scratchBuffer.Length;
                 num = TracedNativeMethods.OCIRowidToChar(rowidHandle, scratchBuffer, ref length, errorHandle);
                 if (num != 0)
                 {
                     connection.CheckError(errorHandle, num);
                 }
                 return new OracleString(scratchBuffer.PtrToStringAnsi(0, length));
             }
             rowidHandle.DangerousAddRef(ref flag);
             OciServiceContextHandle serviceContextHandle = connection.ServiceContextHandle;
             OciStatementHandle stmtp = new OciStatementHandle(serviceContextHandle);
             string stmt = "begin :rowid := :rdesc; end;";
             int offset = 0;
             int num6 = 4;
             int num5 = 8;
             int num3 = 12;
             int num2 = 0x10;
             int num4 = 20;
             try
             {
                 IntPtr ptr;
                 IntPtr ptr2;
                 num = TracedNativeMethods.OCIStmtPrepare(stmtp, errorHandle, stmt, OCI.SYNTAX.OCI_NTV_SYNTAX, OCI.MODE.OCI_DEFAULT, connection);
                 if (num != 0)
                 {
                     connection.CheckError(errorHandle, num);
                 }
                 scratchBuffer.WriteIntPtr(num5, rowidHandle.DangerousGetHandle());
                 scratchBuffer.WriteInt32(offset, 0);
                 scratchBuffer.WriteInt32(num6, 4);
                 scratchBuffer.WriteInt32(num3, 0);
                 scratchBuffer.WriteInt32(num2, 0xf6e);
                 num = TracedNativeMethods.OCIBindByName(stmtp, out ptr2, errorHandle, "rowid", 5, scratchBuffer.DangerousGetDataPtr(num4), 0xf6e, OCI.DATATYPE.VARCHAR2, scratchBuffer.DangerousGetDataPtr(num3), scratchBuffer.DangerousGetDataPtr(num2), OCI.MODE.OCI_DEFAULT);
                 if (num != 0)
                 {
                     connection.CheckError(errorHandle, num);
                 }
                 num = TracedNativeMethods.OCIBindByName(stmtp, out ptr, errorHandle, "rdesc", 5, scratchBuffer.DangerousGetDataPtr(num5), 4, OCI.DATATYPE.ROWID_DESC, scratchBuffer.DangerousGetDataPtr(offset), scratchBuffer.DangerousGetDataPtr(num6), OCI.MODE.OCI_DEFAULT);
                 if (num != 0)
                 {
                     connection.CheckError(errorHandle, num);
                 }
                 num = TracedNativeMethods.OCIStmtExecute(serviceContextHandle, stmtp, errorHandle, 1, OCI.MODE.OCI_DEFAULT);
                 if (num != 0)
                 {
                     connection.CheckError(errorHandle, num);
                 }
                 if (scratchBuffer.ReadInt16(num3) == -1)
                 {
                     return @null;
                 }
                 @null = new OracleString(scratchBuffer, num4, num2, MetaType.GetMetaTypeForType(OracleType.RowId), connection, false, true);
                 GC.KeepAlive(rowidHandle);
             }
             finally
             {
                 OciHandle.SafeDispose(ref stmtp);
             }
         }
         finally
         {
             if (flag)
             {
                 rowidHandle.DangerousRelease();
             }
             if (success)
             {
                 scratchBuffer.DangerousRelease();
             }
         }
     }
     return @null;
 }
コード例 #8
0
        internal static OciDateTimeDescriptor CreateDescriptor(OCI.DATATYPE ociType, OracleConnection connection, object value)
        {
            byte[] buffer;
            OCI.DATATYPE tIMESTAMP;
            if (value is OracleDateTime)
            {
                buffer = ((OracleDateTime) value)._value;
            }
            else
            {
                DateTime dt = (DateTime) value;
                OracleDateTime time2 = new OracleDateTime(dt);
                buffer = time2._value;
            }
            switch (ociType)
            {
                case OCI.DATATYPE.INT_TIMESTAMP:
                    tIMESTAMP = OCI.DATATYPE.TIMESTAMP;
                    break;

                case OCI.DATATYPE.INT_TIMESTAMP_LTZ:
                    tIMESTAMP = OCI.DATATYPE.TIMESTAMP_LTZ;
                    break;

                default:
                {
                    tIMESTAMP = OCI.DATATYPE.TIMESTAMP_TZ;
                    TimeSpan serverTimeZoneAdjustmentToUTC = connection.ServerTimeZoneAdjustmentToUTC;
                    if (buffer.Length < 13)
                    {
                        byte[] dst = new byte[13];
                        Buffer.BlockCopy(buffer, 0, dst, 0, buffer.Length);
                        buffer = dst;
                        buffer[11] = (byte) (20 + serverTimeZoneAdjustmentToUTC.Hours);
                        buffer[12] = (byte) (60 + serverTimeZoneAdjustmentToUTC.Minutes);
                    }
                    break;
                }
            }
            OciDateTimeDescriptor datetime = CreateEmptyDescriptor(ociType, connection);
            OciIntervalDescriptor reftz = new OciIntervalDescriptor(connection.EnvironmentHandle);
            int rc = System.Data.Common.UnsafeNativeMethods.OCIDateTimeFromArray(connection.EnvironmentHandle, connection.ErrorHandle, buffer, (uint) buffer.Length, (byte) tIMESTAMP, datetime, reftz, 9);
            if (rc != 0)
            {
                connection.CheckError(connection.ErrorHandle, rc);
            }
            return datetime;
        }
コード例 #9
0
 internal static byte[] GetBytesFromBuffer(NativeBuffer buffer, int valueOffset, int lengthOffset, MetaType metaType, OracleConnection connection)
 {
     uint num2;
     OCI.DATATYPE ociType = metaType.OciType;
     short length = buffer.ReadInt16(lengthOffset);
     OCI.DATATYPE datatype = ociType;
     if (datatype == OCI.DATATYPE.DATE)
     {
         num2 = 7;
     }
     else if (datatype == OCI.DATATYPE.INT_TIMESTAMP)
     {
         num2 = 11;
     }
     else if (datatype == OCI.DATATYPE.INT_TIMESTAMP_LTZ)
     {
         num2 = 13;
     }
     else
     {
         num2 = 13;
     }
     byte[] destination = new byte[num2];
     buffer.ReadBytes(valueOffset, destination, 0, length);
     if (OCI.DATATYPE.INT_TIMESTAMP_LTZ == ociType)
     {
         TimeSpan serverTimeZoneAdjustmentToUTC = connection.ServerTimeZoneAdjustmentToUTC;
         destination[11] = (byte) (serverTimeZoneAdjustmentToUTC.Hours + 20);
         destination[12] = (byte) (serverTimeZoneAdjustmentToUTC.Minutes + 60);
         return destination;
     }
     if ((OCI.DATATYPE.INT_TIMESTAMP_TZ == ociType) && (0x80 < destination[11]))
     {
         sbyte num3;
         sbyte num4;
         OciIntervalDescriptor reftz = new OciIntervalDescriptor(connection.EnvironmentHandle);
         OciDateTimeDescriptor datetime = new OciDateTimeDescriptor(connection.EnvironmentHandle, OCI.HTYPE.OCI_DTYPE_TIMESTAMP_TZ);
         int rc = System.Data.Common.UnsafeNativeMethods.OCIDateTimeFromArray(connection.EnvironmentHandle, connection.ErrorHandle, destination, num2, 0xbc, datetime, reftz, 0);
         if (rc != 0)
         {
             connection.CheckError(connection.ErrorHandle, rc);
         }
         rc = System.Data.Common.UnsafeNativeMethods.OCIDateTimeGetTimeZoneOffset(connection.EnvironmentHandle, connection.ErrorHandle, datetime, out num4, out num3);
         if (rc != 0)
         {
             connection.CheckError(connection.ErrorHandle, rc);
         }
         destination[11] = (byte) (num4 + 20);
         destination[12] = (byte) (num3 + 60);
     }
     return destination;
 }
コード例 #10
0
 internal static byte[] GetBytesFromDescriptor(OciDateTimeDescriptor dateTimeDescriptor, MetaType metaType, OracleConnection connection)
 {
     uint num2;
     OCI.DATATYPE ociType = metaType.OciType;
     OCI.DATATYPE datatype2 = ociType;
     if (datatype2 == OCI.DATATYPE.INT_TIMESTAMP)
     {
         num2 = 11;
     }
     else if (datatype2 == OCI.DATATYPE.INT_TIMESTAMP_LTZ)
     {
         num2 = 13;
     }
     else
     {
         num2 = 13;
     }
     byte[] outarray = new byte[num2];
     uint len = num2;
     OciIntervalDescriptor reftz = new OciIntervalDescriptor(connection.EnvironmentHandle);
     int rc = System.Data.Common.UnsafeNativeMethods.OCIDateTimeToArray(connection.EnvironmentHandle, connection.ErrorHandle, dateTimeDescriptor, reftz, outarray, ref len, 9);
     if (rc != 0)
     {
         connection.CheckError(connection.ErrorHandle, rc);
     }
     if (OCI.DATATYPE.INT_TIMESTAMP_LTZ == ociType)
     {
         TimeSpan serverTimeZoneAdjustmentToUTC = connection.ServerTimeZoneAdjustmentToUTC;
         outarray[11] = (byte) (serverTimeZoneAdjustmentToUTC.Hours + 20);
         outarray[12] = (byte) (serverTimeZoneAdjustmentToUTC.Minutes + 60);
         return outarray;
     }
     if (OCI.DATATYPE.INT_TIMESTAMP_TZ == ociType)
     {
         sbyte num3;
         sbyte num4;
         rc = System.Data.Common.UnsafeNativeMethods.OCIDateTimeGetTimeZoneOffset(connection.EnvironmentHandle, connection.ErrorHandle, dateTimeDescriptor, out num4, out num3);
         if (rc != 0)
         {
             connection.CheckError(connection.ErrorHandle, rc);
         }
         outarray[11] = (byte) (num4 + 20);
         outarray[12] = (byte) (num3 + 60);
     }
     return outarray;
 }
コード例 #11
0
        internal static OracleString GetPersistedRowid(OracleConnection connection, OciRowidDescriptor rowidHandle)
        {
            OracleString @null = OracleString.Null;

            if (rowidHandle != null)
            {
                OciErrorHandle errorHandle   = connection.ErrorHandle;
                NativeBuffer   scratchBuffer = connection.GetScratchBuffer(0xf82);
                bool           success       = false;
                bool           flag          = false;
                RuntimeHelpers.PrepareConstrainedRegions();
                try
                {
                    int num;
                    scratchBuffer.DangerousAddRef(ref success);
                    if (OCI.ClientVersionAtLeastOracle9i)
                    {
                        int length = scratchBuffer.Length;
                        num = TracedNativeMethods.OCIRowidToChar(rowidHandle, scratchBuffer, ref length, errorHandle);
                        if (num != 0)
                        {
                            connection.CheckError(errorHandle, num);
                        }
                        return(new OracleString(scratchBuffer.PtrToStringAnsi(0, length)));
                    }
                    rowidHandle.DangerousAddRef(ref flag);
                    OciServiceContextHandle serviceContextHandle = connection.ServiceContextHandle;
                    OciStatementHandle      stmtp = new OciStatementHandle(serviceContextHandle);
                    string stmt   = "begin :rowid := :rdesc; end;";
                    int    offset = 0;
                    int    num6   = 4;
                    int    num5   = 8;
                    int    num3   = 12;
                    int    num2   = 0x10;
                    int    num4   = 20;
                    try
                    {
                        IntPtr ptr;
                        IntPtr ptr2;
                        num = TracedNativeMethods.OCIStmtPrepare(stmtp, errorHandle, stmt, OCI.SYNTAX.OCI_NTV_SYNTAX, OCI.MODE.OCI_DEFAULT, connection);
                        if (num != 0)
                        {
                            connection.CheckError(errorHandle, num);
                        }
                        scratchBuffer.WriteIntPtr(num5, rowidHandle.DangerousGetHandle());
                        scratchBuffer.WriteInt32(offset, 0);
                        scratchBuffer.WriteInt32(num6, 4);
                        scratchBuffer.WriteInt32(num3, 0);
                        scratchBuffer.WriteInt32(num2, 0xf6e);
                        num = TracedNativeMethods.OCIBindByName(stmtp, out ptr2, errorHandle, "rowid", 5, scratchBuffer.DangerousGetDataPtr(num4), 0xf6e, OCI.DATATYPE.VARCHAR2, scratchBuffer.DangerousGetDataPtr(num3), scratchBuffer.DangerousGetDataPtr(num2), OCI.MODE.OCI_DEFAULT);
                        if (num != 0)
                        {
                            connection.CheckError(errorHandle, num);
                        }
                        num = TracedNativeMethods.OCIBindByName(stmtp, out ptr, errorHandle, "rdesc", 5, scratchBuffer.DangerousGetDataPtr(num5), 4, OCI.DATATYPE.ROWID_DESC, scratchBuffer.DangerousGetDataPtr(offset), scratchBuffer.DangerousGetDataPtr(num6), OCI.MODE.OCI_DEFAULT);
                        if (num != 0)
                        {
                            connection.CheckError(errorHandle, num);
                        }
                        num = TracedNativeMethods.OCIStmtExecute(serviceContextHandle, stmtp, errorHandle, 1, OCI.MODE.OCI_DEFAULT);
                        if (num != 0)
                        {
                            connection.CheckError(errorHandle, num);
                        }
                        if (scratchBuffer.ReadInt16(num3) == -1)
                        {
                            return(@null);
                        }
                        @null = new OracleString(scratchBuffer, num4, num2, MetaType.GetMetaTypeForType(OracleType.RowId), connection, false, true);
                        GC.KeepAlive(rowidHandle);
                    }
                    finally
                    {
                        OciHandle.SafeDispose(ref stmtp);
                    }
                }
                finally
                {
                    if (flag)
                    {
                        rowidHandle.DangerousRelease();
                    }
                    if (success)
                    {
                        scratchBuffer.DangerousRelease();
                    }
                }
            }
            return(@null);
        }
コード例 #12
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);
        }