コード例 #1
0
        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);
        }