internal static int GetLength(NativeBuffer buffer, int lengthOffset, MetaType metaType)
 {
     if (metaType.IsLong)
     {
         return(buffer.ReadInt32(lengthOffset));
     }
     return(buffer.ReadInt16(lengthOffset));
 }
Exemple #2
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);
        }
        internal static int GetLength(NativeBuffer buffer, int lengthOffset, MetaType metaType)
        {
            int num;

            if (metaType.IsLong)
            {
                num = buffer.ReadInt32(lengthOffset);
            }
            else
            {
                num = buffer.ReadInt16(lengthOffset);
            }
            GC.KeepAlive(buffer);
            return(num);
        }
        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);
        }
        internal object GetOutputValue(NativeBuffer parameterBuffer, OracleConnection connection, bool needCLSType)
        {
            object obj2;

            if (parameterBuffer.ReadInt16(this._indicatorOffset) == -1)
            {
                return(DBNull.Value);
            }
            switch (this._bindingMetaType.OciType)
            {
            case OCI.DATATYPE.VARCHAR2:
            case OCI.DATATYPE.LONG:
            case OCI.DATATYPE.LONGVARCHAR:
            case OCI.DATATYPE.CHAR:
            {
                obj2 = new OracleString(parameterBuffer, this._valueOffset, this._lengthOffset, this._bindingMetaType, connection, this._bindAsUCS2, true);
                int size = this._parameter.Size;
                if (size != 0)
                {
                    OracleString str4 = (OracleString)obj2;
                    if (size < str4.Length)
                    {
                        OracleString str3 = (OracleString)obj2;
                        string       s    = str3.Value.Substring(0, size);
                        if (needCLSType)
                        {
                            return(s);
                        }
                        return(new OracleString(s));
                    }
                }
                if (needCLSType)
                {
                    OracleString str2 = (OracleString)obj2;
                    obj2 = str2.Value;
                }
                return(obj2);
            }

            case OCI.DATATYPE.INTEGER:
            case OCI.DATATYPE.FLOAT:
            case OCI.DATATYPE.UNSIGNEDINT:
                return(parameterBuffer.PtrToStructure(this._valueOffset, this._bindingMetaType.BaseType));

            case OCI.DATATYPE.VARNUM:
                obj2 = new OracleNumber(parameterBuffer, this._valueOffset);
                if (needCLSType)
                {
                    OracleNumber number = (OracleNumber)obj2;
                    obj2 = number.Value;
                }
                return(obj2);

            case OCI.DATATYPE.DATE:
                obj2 = new OracleDateTime(parameterBuffer, this._valueOffset, this._lengthOffset, this._bindingMetaType, connection);
                if (needCLSType)
                {
                    OracleDateTime time2 = (OracleDateTime)obj2;
                    obj2 = time2.Value;
                }
                return(obj2);

            case OCI.DATATYPE.RAW:
            case OCI.DATATYPE.LONGRAW:
            case OCI.DATATYPE.LONGVARRAW:
                obj2 = new OracleBinary(parameterBuffer, this._valueOffset, this._lengthOffset, this._bindingMetaType);
                if (needCLSType)
                {
                    OracleBinary binary = (OracleBinary)obj2;
                    obj2 = binary.Value;
                }
                return(obj2);

            case OCI.DATATYPE.CLOB:
            case OCI.DATATYPE.BLOB:
                return(new OracleLob(this._locator));

            case OCI.DATATYPE.BFILE:
                return(new OracleBFile(this._locator));

            case OCI.DATATYPE.RSET:
                return(new OracleDataReader(connection, this._descriptor));

            case OCI.DATATYPE.INT_TIMESTAMP:
            case OCI.DATATYPE.INT_TIMESTAMP_TZ:
            case OCI.DATATYPE.INT_TIMESTAMP_LTZ:
                obj2 = new OracleDateTime(this._dateTimeDescriptor, this._bindingMetaType, connection);
                if (needCLSType)
                {
                    OracleDateTime time = (OracleDateTime)obj2;
                    obj2 = time.Value;
                }
                return(obj2);

            case OCI.DATATYPE.INT_INTERVAL_YM:
                obj2 = new OracleMonthSpan(parameterBuffer, this._valueOffset);
                if (needCLSType)
                {
                    OracleMonthSpan span2 = (OracleMonthSpan)obj2;
                    obj2 = span2.Value;
                }
                return(obj2);

            case OCI.DATATYPE.INT_INTERVAL_DS:
                obj2 = new OracleTimeSpan(parameterBuffer, this._valueOffset);
                if (needCLSType)
                {
                    OracleTimeSpan span = (OracleTimeSpan)obj2;
                    obj2 = span.Value;
                }
                return(obj2);
            }
            throw System.Data.Common.ADP.TypeNotSupported(this._bindingMetaType.OciType);
        }