Exemple #1
0
 internal static int MarshalToNative(object value, NativeBuffer buffer, int offset, OracleConnection connection)
 {
     byte[] buffer2;
     if (value is OracleNumber)
     {
         buffer2 = ((OracleNumber)value)._value;
     }
     else
     {
         OciErrorHandle errorHandle = connection.ErrorHandle;
         buffer2 = new byte[0x16];
         if (value is decimal)
         {
             FromDecimal(errorHandle, (decimal)value, buffer2);
         }
         else if (value is int)
         {
             FromInt32(errorHandle, (int)value, buffer2);
         }
         else if (value is long)
         {
             FromInt64(errorHandle, (long)value, buffer2);
         }
         else
         {
             FromDouble(errorHandle, (double)value, buffer2);
         }
     }
     buffer.WriteBytes(offset, buffer2, 0, 0x16);
     return(0x16);
 }
 internal static int MarshalToNative(object value, NativeBuffer buffer, int offset)
 {
     byte[] buffer2;
     if (value is OracleTimeSpan)
     {
         buffer2 = ((OracleTimeSpan)value)._value;
     }
     else
     {
         TimeSpan span = (TimeSpan)value;
         buffer2 = new byte[11];
         Pack(buffer2, span.Days, span.Hours, span.Minutes, span.Seconds, ((int)(span.Ticks % 0x989680L)) * 100);
     }
     buffer.WriteBytes(offset, buffer2, 0, 11);
     return(11);
 }
        internal static int MarshalToNative(object value, int offset, int size, NativeBuffer buffer, int bufferOffset, OCI.DATATYPE ociType, bool bindAsUCS2)
        {
            string   str;
            string   str2;
            Encoding encoding = bindAsUCS2 ? Encoding.Unicode : Encoding.UTF8;

            if (value is OracleString)
            {
                str = ((OracleString)value)._value;
            }
            else
            {
                str = (string)value;
            }
            if ((offset == 0) && (size == 0))
            {
                str2 = str;
            }
            else if ((size == 0) || ((offset + size) > str.Length))
            {
                str2 = str.Substring(offset);
            }
            else
            {
                str2 = str.Substring(offset, size);
            }
            byte[] bytes  = encoding.GetBytes(str2);
            int    length = bytes.Length;
            int    num3   = length;

            if (length != 0)
            {
                int num2 = length;
                if (bindAsUCS2)
                {
                    num2 /= 2;
                }
                if (OCI.DATATYPE.LONGVARCHAR == ociType)
                {
                    buffer.WriteInt32(bufferOffset, num2);
                    bufferOffset += 4;
                    num3         += 4;
                }
                buffer.WriteBytes(bufferOffset, bytes, 0, length);
            }
            return(num3);
        }
Exemple #4
0
        internal static int MarshalDateToNative(object value, NativeBuffer buffer, int offset, OCI.DATATYPE ociType, OracleConnection connection)
        {
            byte[] buffer2;
            if (value is OracleDateTime)
            {
                buffer2 = ((OracleDateTime)value)._value;
            }
            else
            {
                DateTime time = (DateTime)value;
                buffer2 = new byte[11];
                Pack(buffer2, time.Year, time.Month, time.Day, time.Hour, time.Minute, time.Second, 0);
            }
            int length = 7;

            buffer.WriteBytes(offset, buffer2, 0, length);
            return(length);
        }
        internal static int MarshalToNative(object value, NativeBuffer buffer, int offset)
        {
            int num2;

            if (value is OracleMonthSpan)
            {
                num2 = ((OracleMonthSpan)value)._value;
            }
            else
            {
                num2 = (int)value;
            }
            byte[] source = new byte[5];
            int    num    = (num2 / 12) + ((int)0x80000000L);
            int    num3   = num2 % 12;

            source[0] = (byte)(num >> 0x18);
            source[1] = (byte)((num >> 0x10) & 0xff);
            source[2] = (byte)((num >> 8) & 0xff);
            source[3] = (byte)(num & 0xff);
            source[4] = (byte)(num3 + 60);
            buffer.WriteBytes(offset, source, 0, 5);
            return(5);
        }
        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);
        }