internal static void SafeDispose(ref OciDateTimeDescriptor handle)
 {
     if (handle != null)
     {
         handle.Dispose();
     }
     handle = null;
 }
Exemplo n.º 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);
        }
Exemplo n.º 3
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);
        }
Exemplo n.º 4
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);
        }
        internal int PutOracleValue(object value, NativeBuffer buffer, int bufferOffset, MetaType metaType, OracleConnection connection, ref SafeHandle handleToBind)
        {
            handleToBind = null;
            OCI.DATATYPE ociType = metaType.OciType;
            OracleParameter parameter = this.Parameter;
            switch (ociType)
            {
                case OCI.DATATYPE.VARCHAR2:
                case OCI.DATATYPE.LONG:
                case OCI.DATATYPE.LONGVARCHAR:
                case OCI.DATATYPE.CHAR:
                    return OracleString.MarshalToNative(value, parameter.Offset, parameter.GetActualSize(), buffer, bufferOffset, ociType, this._bindAsUCS2);

                case OCI.DATATYPE.INTEGER:
                case OCI.DATATYPE.FLOAT:
                case OCI.DATATYPE.UNSIGNEDINT:
                    buffer.StructureToPtr(bufferOffset, value);
                    return metaType.BindSize;

                case OCI.DATATYPE.VARNUM:
                    return OracleNumber.MarshalToNative(value, buffer, bufferOffset, connection);

                case OCI.DATATYPE.DATE:
                    return OracleDateTime.MarshalDateToNative(value, buffer, bufferOffset, ociType, connection);

                case OCI.DATATYPE.RAW:
                case OCI.DATATYPE.LONGRAW:
                case OCI.DATATYPE.LONGVARRAW:
                {
                    int num;
                    byte[] buffer2;
                    if (this._coercedValue is OracleBinary)
                    {
                        OracleBinary binary = (OracleBinary) this._coercedValue;
                        buffer2 = binary.Value;
                    }
                    else
                    {
                        buffer2 = (byte[]) this._coercedValue;
                    }
                    int num2 = buffer2.Length - parameter.Offset;
                    int actualSize = parameter.GetActualSize();
                    if (actualSize != 0)
                    {
                        num2 = Math.Min(num2, actualSize);
                    }
                    if (OCI.DATATYPE.LONGVARRAW == ociType)
                    {
                        buffer.WriteInt32(bufferOffset, num2);
                        bufferOffset += 4;
                        num = num2 + 4;
                    }
                    else
                    {
                        num = num2;
                    }
                    buffer.WriteBytes(bufferOffset, buffer2, parameter.Offset, num2);
                    return num;
                }
                case OCI.DATATYPE.CLOB:
                case OCI.DATATYPE.BLOB:
                    if (!(value is OracleLob))
                    {
                        throw System.Data.Common.ADP.BadBindValueType(value.GetType(), metaType.OracleType);
                    }
                    handleToBind = ((OracleLob) value).Descriptor;
                    return IntPtr.Size;

                case OCI.DATATYPE.BFILE:
                    if (!(value is OracleBFile))
                    {
                        throw System.Data.Common.ADP.BadBindValueType(value.GetType(), metaType.OracleType);
                    }
                    handleToBind = ((OracleBFile) value).Descriptor;
                    return IntPtr.Size;

                case OCI.DATATYPE.INT_TIMESTAMP:
                case OCI.DATATYPE.INT_TIMESTAMP_LTZ:
                    if (value is OracleDateTime)
                    {
                        OracleDateTime time = (OracleDateTime) value;
                        if (!time.HasTimeInfo)
                        {
                            throw System.Data.Common.ADP.UnsupportedOracleDateTimeBinding(metaType.OracleType);
                        }
                    }
                    this._dateTimeDescriptor = OracleDateTime.CreateDescriptor(ociType, connection, value);
                    handleToBind = this._dateTimeDescriptor;
                    return IntPtr.Size;

                case OCI.DATATYPE.INT_TIMESTAMP_TZ:
                    if (value is OracleDateTime)
                    {
                        OracleDateTime time2 = (OracleDateTime) value;
                        if (!time2.HasTimeZoneInfo)
                        {
                            throw System.Data.Common.ADP.UnsupportedOracleDateTimeBinding(OracleType.TimestampWithTZ);
                        }
                    }
                    this._dateTimeDescriptor = OracleDateTime.CreateDescriptor(ociType, connection, value);
                    handleToBind = this._dateTimeDescriptor;
                    return IntPtr.Size;

                case OCI.DATATYPE.INT_INTERVAL_YM:
                    return OracleMonthSpan.MarshalToNative(value, buffer, bufferOffset);

                case OCI.DATATYPE.INT_INTERVAL_DS:
                    return OracleTimeSpan.MarshalToNative(value, buffer, bufferOffset);
            }
            throw System.Data.Common.ADP.TypeNotSupported(ociType);
        }
        internal void Bind(OciStatementHandle statementHandle, NativeBuffer parameterBuffer, OracleConnection connection, ref bool mustRelease, ref SafeHandle handleToBind)
        {
            if (IsDirection(this.Parameter, ParameterDirection.Output) || (this.Parameter.Value != null))
            {
                int num2;
                IntPtr ptr2;
                string parameterName = this.Parameter.ParameterName;
                OciErrorHandle errorHandle = connection.ErrorHandle;
                OciServiceContextHandle serviceContextHandle = connection.ServiceContextHandle;
                int num = 0;
                OCI.INDICATOR oK = OCI.INDICATOR.OK;
                OCI.DATATYPE ociType = this._bindingMetaType.OciType;
                IntPtr dataPtr = parameterBuffer.DangerousGetDataPtr(this._indicatorOffset);
                IntPtr alenp = parameterBuffer.DangerousGetDataPtr(this._lengthOffset);
                IntPtr valuep = parameterBuffer.DangerousGetDataPtr(this._valueOffset);
                OciHandle.SafeDispose(ref this._dateTimeDescriptor);
                if (IsDirection(this.Parameter, ParameterDirection.Input))
                {
                    if (System.Data.Common.ADP.IsNull(this._coercedValue))
                    {
                        oK = OCI.INDICATOR.ISNULL;
                        switch (ociType)
                        {
                            case OCI.DATATYPE.INT_TIMESTAMP:
                            case OCI.DATATYPE.INT_TIMESTAMP_TZ:
                            case OCI.DATATYPE.INT_TIMESTAMP_LTZ:
                                this._dateTimeDescriptor = OracleDateTime.CreateEmptyDescriptor(ociType, connection);
                                handleToBind = this._dateTimeDescriptor;
                                break;
                        }
                    }
                    else
                    {
                        num = this.PutOracleValue(this._coercedValue, parameterBuffer, this._valueOffset, this._bindingMetaType, connection, ref handleToBind);
                    }
                }
                else
                {
                    if (this._bindingMetaType.IsVariableLength)
                    {
                        num = 0;
                    }
                    else
                    {
                        num = this._bufferLength;
                    }
                    OciLobLocator.SafeDispose(ref this._locator);
                    OciHandle.SafeDispose(ref this._descriptor);
                    switch (ociType)
                    {
                        case OCI.DATATYPE.CLOB:
                        case OCI.DATATYPE.BLOB:
                        case OCI.DATATYPE.BFILE:
                            this._locator = new OciLobLocator(connection, this._bindingMetaType.OracleType);
                            handleToBind = this._locator.Descriptor;
                            break;

                        case OCI.DATATYPE.RSET:
                            this._descriptor = new OciStatementHandle(serviceContextHandle);
                            handleToBind = this._descriptor;
                            break;

                        case OCI.DATATYPE.INT_TIMESTAMP:
                        case OCI.DATATYPE.INT_TIMESTAMP_TZ:
                        case OCI.DATATYPE.INT_TIMESTAMP_LTZ:
                            this._dateTimeDescriptor = OracleDateTime.CreateEmptyDescriptor(ociType, connection);
                            handleToBind = this._dateTimeDescriptor;
                            break;
                    }
                }
                if (handleToBind != null)
                {
                    handleToBind.DangerousAddRef(ref mustRelease);
                    parameterBuffer.WriteIntPtr(this._valueOffset, handleToBind.DangerousGetHandle());
                }
                parameterBuffer.WriteInt16(this._indicatorOffset, (short) oK);
                if ((OCI.DATATYPE.LONGVARCHAR == ociType) || (OCI.DATATYPE.LONGVARRAW == ociType))
                {
                    alenp = IntPtr.Zero;
                }
                else if (this._bindAsUCS2)
                {
                    parameterBuffer.WriteInt32(this._lengthOffset, num / System.Data.Common.ADP.CharSize);
                }
                else
                {
                    parameterBuffer.WriteInt32(this._lengthOffset, num);
                }
                if (IsDirection(this.Parameter, ParameterDirection.Output))
                {
                    num2 = this._bufferLength;
                }
                else
                {
                    num2 = num;
                }
                OCI.DATATYPE dty = ociType;
                switch (ociType)
                {
                    case OCI.DATATYPE.INT_TIMESTAMP:
                        dty = OCI.DATATYPE.TIMESTAMP;
                        break;

                    case OCI.DATATYPE.INT_TIMESTAMP_TZ:
                        dty = OCI.DATATYPE.TIMESTAMP_TZ;
                        break;

                    case OCI.DATATYPE.INT_TIMESTAMP_LTZ:
                        dty = OCI.DATATYPE.TIMESTAMP_LTZ;
                        break;
                }
                int rc = TracedNativeMethods.OCIBindByName(statementHandle, out ptr2, errorHandle, parameterName, parameterName.Length, valuep, num2, dty, dataPtr, alenp, OCI.MODE.OCI_DEFAULT);
                if (rc != 0)
                {
                    this._command.Connection.CheckError(errorHandle, rc);
                }
                this._bindHandle = new OciBindHandle(statementHandle, ptr2);
                if (this._bindingMetaType.IsCharacterType)
                {
                    if (OCI.ClientVersionAtLeastOracle9i && IsDirection(this.Parameter, ParameterDirection.Output))
                    {
                        this._bindHandle.SetAttribute(OCI.ATTR.OCI_ATTR_MAXCHAR_SIZE, this._bindSize, errorHandle);
                    }
                    if ((num2 > (this._bindingMetaType.MaxBindSize / System.Data.Common.ADP.CharSize)) || (!OCI.ClientVersionAtLeastOracle9i && this._bindingMetaType.UsesNationalCharacterSet))
                    {
                        this._bindHandle.SetAttribute(OCI.ATTR.OCI_ATTR_MAXDATA_SIZE, this._bindingMetaType.MaxBindSize, errorHandle);
                    }
                    if (this._bindingMetaType.UsesNationalCharacterSet)
                    {
                        this._bindHandle.SetAttribute(OCI.ATTR.OCI_ATTR_CHARSET_FORM, 2, errorHandle);
                    }
                    if (this._bindAsUCS2)
                    {
                        this._bindHandle.SetAttribute(OCI.ATTR.OCI_ATTR_CHARSET_ID, 0x3e8, errorHandle);
                    }
                }
                GC.KeepAlive(parameterBuffer);
            }
        }
Exemplo n.º 7
0
 internal OracleDateTime(OciDateTimeDescriptor dateTimeDescriptor, MetaType metaType, OracleConnection connection)
 {
     this._value = GetBytesFromDescriptor(dateTimeDescriptor, metaType, connection);
 }
Exemplo n.º 8
0
 internal static DateTime MarshalTimestampToDateTime(OciDateTimeDescriptor dateTimeDescriptor, MetaType metaType, OracleConnection connection)
 {
     return(ToDateTime(GetBytesFromDescriptor(dateTimeDescriptor, metaType, connection)));
 }
 internal OracleDateTime(OciDateTimeDescriptor dateTimeDescriptor, MetaType metaType, OracleConnection connection)
 {
     this._value = GetBytesFromDescriptor(dateTimeDescriptor, metaType, connection);
 }
 internal static DateTime MarshalTimestampToDateTime(OciDateTimeDescriptor dateTimeDescriptor, MetaType metaType, OracleConnection connection)
 {
     return ToDateTime(GetBytesFromDescriptor(dateTimeDescriptor, metaType, connection));
 }
 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 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;
 }
        internal int PutOracleValue(object value, NativeBuffer buffer, int bufferOffset, MetaType metaType, OracleConnection connection, ref SafeHandle handleToBind)
        {
            handleToBind = null;
            OCI.DATATYPE    ociType   = metaType.OciType;
            OracleParameter parameter = this.Parameter;

            switch (ociType)
            {
            case OCI.DATATYPE.VARCHAR2:
            case OCI.DATATYPE.LONG:
            case OCI.DATATYPE.LONGVARCHAR:
            case OCI.DATATYPE.CHAR:
                return(OracleString.MarshalToNative(value, parameter.Offset, parameter.GetActualSize(), buffer, bufferOffset, ociType, this._bindAsUCS2));

            case OCI.DATATYPE.INTEGER:
            case OCI.DATATYPE.FLOAT:
            case OCI.DATATYPE.UNSIGNEDINT:
                buffer.StructureToPtr(bufferOffset, value);
                return(metaType.BindSize);

            case OCI.DATATYPE.VARNUM:
                return(OracleNumber.MarshalToNative(value, buffer, bufferOffset, connection));

            case OCI.DATATYPE.DATE:
                return(OracleDateTime.MarshalDateToNative(value, buffer, bufferOffset, ociType, connection));

            case OCI.DATATYPE.RAW:
            case OCI.DATATYPE.LONGRAW:
            case OCI.DATATYPE.LONGVARRAW:
            {
                int    num;
                byte[] buffer2;
                if (this._coercedValue is OracleBinary)
                {
                    OracleBinary binary = (OracleBinary)this._coercedValue;
                    buffer2 = binary.Value;
                }
                else
                {
                    buffer2 = (byte[])this._coercedValue;
                }
                int num2       = buffer2.Length - parameter.Offset;
                int actualSize = parameter.GetActualSize();
                if (actualSize != 0)
                {
                    num2 = Math.Min(num2, actualSize);
                }
                if (OCI.DATATYPE.LONGVARRAW == ociType)
                {
                    buffer.WriteInt32(bufferOffset, num2);
                    bufferOffset += 4;
                    num           = num2 + 4;
                }
                else
                {
                    num = num2;
                }
                buffer.WriteBytes(bufferOffset, buffer2, parameter.Offset, num2);
                return(num);
            }

            case OCI.DATATYPE.CLOB:
            case OCI.DATATYPE.BLOB:
                if (!(value is OracleLob))
                {
                    throw System.Data.Common.ADP.BadBindValueType(value.GetType(), metaType.OracleType);
                }
                handleToBind = ((OracleLob)value).Descriptor;
                return(IntPtr.Size);

            case OCI.DATATYPE.BFILE:
                if (!(value is OracleBFile))
                {
                    throw System.Data.Common.ADP.BadBindValueType(value.GetType(), metaType.OracleType);
                }
                handleToBind = ((OracleBFile)value).Descriptor;
                return(IntPtr.Size);

            case OCI.DATATYPE.INT_TIMESTAMP:
            case OCI.DATATYPE.INT_TIMESTAMP_LTZ:
                if (value is OracleDateTime)
                {
                    OracleDateTime time = (OracleDateTime)value;
                    if (!time.HasTimeInfo)
                    {
                        throw System.Data.Common.ADP.UnsupportedOracleDateTimeBinding(metaType.OracleType);
                    }
                }
                this._dateTimeDescriptor = OracleDateTime.CreateDescriptor(ociType, connection, value);
                handleToBind             = this._dateTimeDescriptor;
                return(IntPtr.Size);

            case OCI.DATATYPE.INT_TIMESTAMP_TZ:
                if (value is OracleDateTime)
                {
                    OracleDateTime time2 = (OracleDateTime)value;
                    if (!time2.HasTimeZoneInfo)
                    {
                        throw System.Data.Common.ADP.UnsupportedOracleDateTimeBinding(OracleType.TimestampWithTZ);
                    }
                }
                this._dateTimeDescriptor = OracleDateTime.CreateDescriptor(ociType, connection, value);
                handleToBind             = this._dateTimeDescriptor;
                return(IntPtr.Size);

            case OCI.DATATYPE.INT_INTERVAL_YM:
                return(OracleMonthSpan.MarshalToNative(value, buffer, bufferOffset));

            case OCI.DATATYPE.INT_INTERVAL_DS:
                return(OracleTimeSpan.MarshalToNative(value, buffer, bufferOffset));
            }
            throw System.Data.Common.ADP.TypeNotSupported(ociType);
        }
        internal void Bind(OciStatementHandle statementHandle, NativeBuffer parameterBuffer, OracleConnection connection, ref bool mustRelease, ref SafeHandle handleToBind)
        {
            if (IsDirection(this.Parameter, ParameterDirection.Output) || (this.Parameter.Value != null))
            {
                int                     num2;
                IntPtr                  ptr2;
                string                  parameterName        = this.Parameter.ParameterName;
                OciErrorHandle          errorHandle          = connection.ErrorHandle;
                OciServiceContextHandle serviceContextHandle = connection.ServiceContextHandle;
                int                     num     = 0;
                OCI.INDICATOR           oK      = OCI.INDICATOR.OK;
                OCI.DATATYPE            ociType = this._bindingMetaType.OciType;
                IntPtr                  dataPtr = parameterBuffer.DangerousGetDataPtr(this._indicatorOffset);
                IntPtr                  alenp   = parameterBuffer.DangerousGetDataPtr(this._lengthOffset);
                IntPtr                  valuep  = parameterBuffer.DangerousGetDataPtr(this._valueOffset);
                OciHandle.SafeDispose(ref this._dateTimeDescriptor);
                if (IsDirection(this.Parameter, ParameterDirection.Input))
                {
                    if (System.Data.Common.ADP.IsNull(this._coercedValue))
                    {
                        oK = OCI.INDICATOR.ISNULL;
                        switch (ociType)
                        {
                        case OCI.DATATYPE.INT_TIMESTAMP:
                        case OCI.DATATYPE.INT_TIMESTAMP_TZ:
                        case OCI.DATATYPE.INT_TIMESTAMP_LTZ:
                            this._dateTimeDescriptor = OracleDateTime.CreateEmptyDescriptor(ociType, connection);
                            handleToBind             = this._dateTimeDescriptor;
                            break;
                        }
                    }
                    else
                    {
                        num = this.PutOracleValue(this._coercedValue, parameterBuffer, this._valueOffset, this._bindingMetaType, connection, ref handleToBind);
                    }
                }
                else
                {
                    if (this._bindingMetaType.IsVariableLength)
                    {
                        num = 0;
                    }
                    else
                    {
                        num = this._bufferLength;
                    }
                    OciLobLocator.SafeDispose(ref this._locator);
                    OciHandle.SafeDispose(ref this._descriptor);
                    switch (ociType)
                    {
                    case OCI.DATATYPE.CLOB:
                    case OCI.DATATYPE.BLOB:
                    case OCI.DATATYPE.BFILE:
                        this._locator = new OciLobLocator(connection, this._bindingMetaType.OracleType);
                        handleToBind  = this._locator.Descriptor;
                        break;

                    case OCI.DATATYPE.RSET:
                        this._descriptor = new OciStatementHandle(serviceContextHandle);
                        handleToBind     = this._descriptor;
                        break;

                    case OCI.DATATYPE.INT_TIMESTAMP:
                    case OCI.DATATYPE.INT_TIMESTAMP_TZ:
                    case OCI.DATATYPE.INT_TIMESTAMP_LTZ:
                        this._dateTimeDescriptor = OracleDateTime.CreateEmptyDescriptor(ociType, connection);
                        handleToBind             = this._dateTimeDescriptor;
                        break;
                    }
                }
                if (handleToBind != null)
                {
                    handleToBind.DangerousAddRef(ref mustRelease);
                    parameterBuffer.WriteIntPtr(this._valueOffset, handleToBind.DangerousGetHandle());
                }
                parameterBuffer.WriteInt16(this._indicatorOffset, (short)oK);
                if ((OCI.DATATYPE.LONGVARCHAR == ociType) || (OCI.DATATYPE.LONGVARRAW == ociType))
                {
                    alenp = IntPtr.Zero;
                }
                else if (this._bindAsUCS2)
                {
                    parameterBuffer.WriteInt32(this._lengthOffset, num / System.Data.Common.ADP.CharSize);
                }
                else
                {
                    parameterBuffer.WriteInt32(this._lengthOffset, num);
                }
                if (IsDirection(this.Parameter, ParameterDirection.Output))
                {
                    num2 = this._bufferLength;
                }
                else
                {
                    num2 = num;
                }
                OCI.DATATYPE dty = ociType;
                switch (ociType)
                {
                case OCI.DATATYPE.INT_TIMESTAMP:
                    dty = OCI.DATATYPE.TIMESTAMP;
                    break;

                case OCI.DATATYPE.INT_TIMESTAMP_TZ:
                    dty = OCI.DATATYPE.TIMESTAMP_TZ;
                    break;

                case OCI.DATATYPE.INT_TIMESTAMP_LTZ:
                    dty = OCI.DATATYPE.TIMESTAMP_LTZ;
                    break;
                }
                int rc = TracedNativeMethods.OCIBindByName(statementHandle, out ptr2, errorHandle, parameterName, parameterName.Length, valuep, num2, dty, dataPtr, alenp, OCI.MODE.OCI_DEFAULT);
                if (rc != 0)
                {
                    this._command.Connection.CheckError(errorHandle, rc);
                }
                this._bindHandle = new OciBindHandle(statementHandle, ptr2);
                if (this._bindingMetaType.IsCharacterType)
                {
                    if (OCI.ClientVersionAtLeastOracle9i && IsDirection(this.Parameter, ParameterDirection.Output))
                    {
                        this._bindHandle.SetAttribute(OCI.ATTR.OCI_ATTR_MAXCHAR_SIZE, this._bindSize, errorHandle);
                    }
                    if ((num2 > (this._bindingMetaType.MaxBindSize / System.Data.Common.ADP.CharSize)) || (!OCI.ClientVersionAtLeastOracle9i && this._bindingMetaType.UsesNationalCharacterSet))
                    {
                        this._bindHandle.SetAttribute(OCI.ATTR.OCI_ATTR_MAXDATA_SIZE, this._bindingMetaType.MaxBindSize, errorHandle);
                    }
                    if (this._bindingMetaType.UsesNationalCharacterSet)
                    {
                        this._bindHandle.SetAttribute(OCI.ATTR.OCI_ATTR_CHARSET_FORM, 2, errorHandle);
                    }
                    if (this._bindAsUCS2)
                    {
                        this._bindHandle.SetAttribute(OCI.ATTR.OCI_ATTR_CHARSET_ID, 0x3e8, errorHandle);
                    }
                }
                GC.KeepAlive(parameterBuffer);
            }
        }