static internal int GetLength(
            NativeBuffer buffer,
            int lengthOffset,
            MetaType metaType
            )
        {
            // Get the length of the data bound
            int length;

            HandleRef lengthBuffer = buffer.PtrOffset(lengthOffset);

            // Oracle only will write two bytes of length, but LONG data types
            // can exceed that amount; our piecewise callbacks will write a
            // full DWORD of length, so we need to get the full length for them,
            // but if we do that for all the other types, we'll be reading
            // un-initialized memory and bad things happen.
            if (metaType.IsLong)
            {
                length = Marshal.ReadInt32((IntPtr)lengthBuffer);
            }
            else
            {
                length = (int)Marshal.ReadInt16((IntPtr)lengthBuffer);
            }

            return(length);
        }
 internal void GetNames()
 {
     this._lob.AssertConnectionIsOpen();
     short num5 = this.Connection.EnvironmentHandle.IsUnicode ? ((short) 2) : ((short) 1);
     ushort num = (ushort) (30 * num5);
     int offset = num;
     ushort num3 = (ushort) (0xff * num5);
     NativeBuffer scratchBuffer = this.Connection.GetScratchBuffer(num + num3);
     bool success = false;
     RuntimeHelpers.PrepareConstrainedRegions();
     try
     {
         scratchBuffer.DangerousAddRef(ref success);
         int rc = TracedNativeMethods.OCILobFileGetName(this.Connection.EnvironmentHandle, this.ErrorHandle, this.Descriptor, scratchBuffer.DangerousGetDataPtr(), ref num, scratchBuffer.DangerousGetDataPtr(offset), ref num3);
         if (rc != 0)
         {
             this.Connection.CheckError(this.ErrorHandle, rc);
         }
         this._directoryAlias = this.Connection.GetString(scratchBuffer.ReadBytes(0, num));
         this._fileName = this.Connection.GetString(scratchBuffer.ReadBytes(offset, num3));
     }
     finally
     {
         if (success)
         {
             scratchBuffer.DangerousRelease();
         }
     }
 }
Example #3
0
        internal void GetNames()
        {
            _lob.AssertConnectionIsOpen();

            int          charSize             = (Connection.EnvironmentHandle.IsUnicode) ? 2 : 1;
            short        directoryAliasLength = (short)(charSize * 30);
            short        fileAliasLength      = (short)(charSize * 255);
            NativeBuffer buffer = Connection.ScratchBuffer;

            Debug.Assert(buffer.Length > (directoryAliasLength + fileAliasLength), "connection's scratch buffer is too small");

            HandleRef directoryAlias = buffer.Ptr;
            HandleRef fileAlias      = buffer.PtrOffset(directoryAliasLength);

            int rc = TracedNativeMethods.OCILobFileGetName(
                Connection.EnvironmentHandle,
                ErrorHandle,
                Descriptor,
                directoryAlias,
                ref directoryAliasLength,
                fileAlias,
                ref fileAliasLength
                );

            if (0 != rc)
            {
                Connection.CheckError(ErrorHandle, rc);
            }

            _directoryAlias = Connection.GetString((IntPtr)directoryAlias, directoryAliasLength, false);
            _fileName       = Connection.GetString((IntPtr)fileAlias, fileAliasLength, false);
            GC.KeepAlive(buffer);
        }
        internal OracleBinary(NativeBuffer buffer, int valueOffset, int lengthOffset, MetaType metaType)
        {
            int byteCount = GetLength(buffer, lengthOffset, metaType);

            this._value = new byte[byteCount];
            GetBytes(buffer, valueOffset, metaType, 0, this._value, 0, byteCount);
        }
Example #5
0
 // (internal) construct from a row/parameter binding
 internal OracleTimeSpan(
     NativeBuffer buffer,
     int valueOffset) : this(true)
 {
     _value = new byte[11];
     Marshal.Copy((IntPtr)buffer.PtrOffset(valueOffset), _value, 0, 11);
 }
        internal static int GetChars(NativeBuffer buffer, int valueOffset, int lengthOffset, MetaType metaType, OracleConnection connection, bool boundAsUCS2, int sourceOffset, char[] destinationBuffer, int destinationOffset, int charCount)
        {
            bool success = false;

            RuntimeHelpers.PrepareConstrainedRegions();
            try
            {
                buffer.DangerousAddRef(ref success);
                if (boundAsUCS2)
                {
                    if (!metaType.IsLong)
                    {
                        Marshal.Copy(buffer.DangerousGetDataPtrWithBaseOffset(valueOffset + (System.Data.Common.ADP.CharSize * sourceOffset)), destinationBuffer, destinationOffset, charCount);
                        return(charCount);
                    }
                    NativeBuffer_LongColumnData.CopyOutOfLineChars(buffer.ReadIntPtr(valueOffset), sourceOffset, destinationBuffer, destinationOffset, charCount);
                    return(charCount);
                }
                string str    = MarshalToString(buffer, valueOffset, lengthOffset, metaType, connection, boundAsUCS2, false);
                int    length = str.Length;
                int    num    = ((sourceOffset + charCount) > length) ? (length - sourceOffset) : charCount;
                Buffer.BlockCopy(str.ToCharArray(sourceOffset, num), 0, destinationBuffer, destinationOffset * System.Data.Common.ADP.CharSize, num * System.Data.Common.ADP.CharSize);
                charCount = num;
            }
            finally
            {
                if (success)
                {
                    buffer.DangerousRelease();
                }
            }
            return(charCount);
        }
Example #7
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 GetLength(NativeBuffer buffer, int lengthOffset, MetaType metaType)
 {
     if (metaType.IsLong)
     {
         return(buffer.ReadInt32(lengthOffset));
     }
     return(buffer.ReadInt16(lengthOffset));
 }
 internal string PtrToString(NativeBuffer buf)
 {
     if (this.IsUnicode)
     {
         return(buf.PtrToStringUni(0));
     }
     return(buf.PtrToStringAnsi(0));
 }
Example #10
0
 // (internal) construct from a row/parameter binding
 internal OracleDateTime(
     NativeBuffer buffer,
     int valueOffset,
     MetaType metaType,
     OracleConnection connection)
 {
     _value = GetBytes(buffer, valueOffset, metaType, connection);
 }
        static internal int GetChars(
            NativeBuffer buffer,
            int valueOffset,
            int lengthOffset,
            MetaType metaType,
            OracleConnection connection,                                        // See MDAC #78258 for reason.
            bool boundAsUCS2,                                                   // See MDAC #78258 for reason.
            int sourceOffset,
            char[]                   destinationBuffer,
            int destinationOffset,
            int charCount
            )
        {
            // This static method allows the GetChars type getter to do it's job
            // without having to marshal the entire value into managed space.

            if (boundAsUCS2)
            {
                HandleRef sourceBuffer;

                if (!metaType.IsLong)
                {
                    sourceBuffer = buffer.PtrOffset(valueOffset + (ADP.CharSize * sourceOffset));
                }
                else
                {
                    // Long values are bound out-of-line, which means we have
                    // to do this the hard way...
                    sourceBuffer = buffer.PtrOffset(valueOffset);
                    IntPtr longBuffer = Marshal.ReadIntPtr((IntPtr)sourceBuffer);

                    if (0 != sourceOffset)
                    {
                        longBuffer = new IntPtr(longBuffer.ToInt64() + (long)(ADP.CharSize * sourceOffset));
                    }

                    HandleRef newSourceBuffer = new HandleRef(sourceBuffer.Wrapper, longBuffer);
                    sourceBuffer = newSourceBuffer;
                }

                Marshal.Copy((IntPtr)sourceBuffer, destinationBuffer, destinationOffset, charCount);
            }
            else
            {
                // In the odd case that we don't have a Unicode value (see MDAC #78258
                // for the reason) we have to do this the hard way -- get the full value,
                // then copy the data...
                string value        = MarshalToString(buffer, valueOffset, lengthOffset, metaType, connection, boundAsUCS2, false);
                int    valueLength  = value.Length;
                int    resultLength = (sourceOffset + charCount) > valueLength ? valueLength - sourceOffset : charCount;
                char[] result       = value.ToCharArray(sourceOffset, resultLength);
                Buffer.BlockCopy(result, 0, destinationBuffer, (destinationOffset * ADP.CharSize), (resultLength * ADP.CharSize));
                charCount = resultLength;
            }
            GC.KeepAlive(buffer);
            return(charCount);
        }
        internal static int MarshalToInt32(NativeBuffer buffer, int valueOffset)
        {
            byte[] buffer2   = buffer.ReadBytes(valueOffset, 5);
            int    num3      = ((((buffer2[0] << 0x18) | (buffer2[1] << 0x10)) | (buffer2[2] << 8)) | buffer2[3]) - ((int)0x80000000L);
            int    num2      = buffer2[4] - 60;
            int    monthSpan = (num3 * 12) + num2;

            AssertValid(monthSpan);
            return(monthSpan);
        }
Example #13
0
 internal void Dispose()
 {
     NativeBuffer.SafeDispose(ref this._longBuffer);
     OciLobLocator.SafeDispose(ref this._lobLocator);
     OciHandle.SafeDispose(ref this._describeHandle);
     this._columnName = null;
     this._metaType   = null;
     this._callback   = null;
     this._connection = null;
 }
 internal static int GetBytes(NativeBuffer buffer, int valueOffset, MetaType metaType, int sourceOffset, byte[] destinationBuffer, int destinationOffset, int byteCount)
 {
     if (!metaType.IsLong)
     {
         buffer.ReadBytes(valueOffset + sourceOffset, destinationBuffer, destinationOffset, byteCount);
         return(byteCount);
     }
     NativeBuffer_LongColumnData.CopyOutOfLineBytes(buffer.ReadIntPtr(valueOffset), sourceOffset, destinationBuffer, destinationOffset, byteCount);
     return(byteCount);
 }
Example #15
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);
        }
Example #16
0
        static internal TimeSpan MarshalToTimeSpan(
            NativeBuffer buffer,
            int valueOffset)
        {
            byte[] rawValue = new byte[11];
            Marshal.Copy((IntPtr)buffer.PtrOffset(valueOffset), rawValue, 0, 11);

            TimeSpan result = ToTimeSpan(rawValue);

            return(result);
        }
Example #17
0
        static internal DateTime MarshalToDateTime(
            NativeBuffer buffer,
            int valueOffset,
            MetaType metaType,
            OracleConnection connection)
        {
            byte[]   rawValue = GetBytes(buffer, valueOffset, metaType, connection);
            DateTime result   = ToDateTime(rawValue);

            return(result);
        }
 // (internal) construct from a row/parameter binding
 internal OracleString(
     NativeBuffer buffer,
     int valueOffset,
     int lengthOffset,
     MetaType metaType,
     OracleConnection connection,                                                // See MDAC #78258 for reason.
     bool boundAsUCS2,                                                           // See MDAC #78258 for reason.
     bool outputParameterBinding                                                 // oracle has inconsistent behavior for output parameters.
     )
 {
     _value = MarshalToString(buffer, valueOffset, lengthOffset, metaType, connection, boundAsUCS2, outputParameterBinding);
 }
Example #19
0
 internal void FixupLongValueLength(NativeBuffer buffer)
 {
     if ((this._longBuffer != null) && (-1 == this._longLength))
     {
         this._longLength = this._longBuffer.TotalLengthInBytes;
         if (this._bindAsUTF16)
         {
             this._longLength /= 2;
         }
         buffer.WriteInt32(this._lengthOffset, this._longLength);
     }
 }
        internal void PostExecute(NativeBuffer parameterBuffer, OracleConnection connection)
        {
            OracleParameter parameter = this.Parameter;

            if (IsDirection(parameter, ParameterDirection.Output) || IsDirection(parameter, ParameterDirection.ReturnValue))
            {
                bool needCLSType = true;
                if (IsDirection(parameter, ParameterDirection.Input) && (parameter.Value is INullable))
                {
                    needCLSType = false;
                }
                parameter.Value = this.GetOutputValue(parameterBuffer, connection, needCLSType);
            }
        }
Example #21
0
        internal static int oermsg(short rcode, NativeBuffer buf)
        {
            if (Bid.AdvancedOn)
            {
                Bid.Trace("<oc.oermsg|ADV|OCI> rcode=%d\n", rcode);
            }
            int num = System.Data.Common.UnsafeNativeMethods.oermsg(rcode, buf);

            if (Bid.AdvancedOn)
            {
                Bid.Trace("<oc.oermsg|ADV|OCI|RET> rc=%d\n", num);
            }
            return(num);
        }
Example #22
0
        internal static int OCIServerVersion(OciHandle hndlp, OciHandle errhp, NativeBuffer bufp)
        {
            if (Bid.AdvancedOn)
            {
                Bid.Trace("<oc.OCIServerVersion|ADV|OCI>        hndlp=0x%-07Ix errhp=0x%-07Ix bufp=0x%-07Ix bufsz=%d hndltype=%d{OCI.HTYPE}\n", OciHandle.HandleValueToTrace(hndlp), OciHandle.HandleValueToTrace(errhp), NativeBuffer.HandleValueToTrace(bufp), bufp.Length, (int)hndlp.HandleType);
            }
            int num = System.Data.Common.UnsafeNativeMethods.OCIServerVersion(hndlp, errhp, bufp, (uint)bufp.Length, (byte)hndlp.HandleType);

            if (Bid.AdvancedOn)
            {
                Bid.Trace("<oc.OCIServerVersion|ADV|OCI|RET>    rc=%d\n%ls\n\n", num, hndlp.PtrToString(bufp));
            }
            return(num);
        }
        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 NativeBuffer GetScratchBuffer(int minSize)
        {
            NativeBuffer buffer = this._scratchBuffer;

            if ((buffer == null) || (buffer.Length < minSize))
            {
                if (buffer != null)
                {
                    buffer.Dispose();
                }
                buffer = new NativeBuffer_ScratchBuffer(minSize);
                this._scratchBuffer = buffer;
            }
            return(buffer);
        }
 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);
        }
Example #27
0
        static internal byte[] GetBytes(
            NativeBuffer buffer,
            int valueOffset,
            MetaType metaType,
            OracleConnection connection)
        {
            // Static method to return the raw data bytes from the row/parameter
            // buffer, taking the binding type into account and adjusting it for
            // the server time zones, as appropriate.

            int ociBytes;

            OCI.DATATYPE ociType = metaType.OciType;

            switch (ociType)
            {
            case OCI.DATATYPE.DATE:
                ociBytes = x_DATE_Length;
                break;

            case OCI.DATATYPE.INT_TIMESTAMP:
                ociBytes = x_TIMESTAMP_Length;
                break;

            case OCI.DATATYPE.INT_TIMESTAMP_LTZ:
                ociBytes = x_TIMESTAMP_WITH_TIMEZONE_Length;
                break;

            default:
                Debug.Assert(OCI.DATATYPE.INT_TIMESTAMP_TZ == ociType, "unrecognized type");
                ociBytes = x_TIMESTAMP_WITH_TIMEZONE_Length;
                break;
            }

            byte[] result = new byte[ociBytes];
            Marshal.Copy((IntPtr)buffer.PtrOffset(valueOffset), result, 0, ociBytes);

            if (OCI.DATATYPE.INT_TIMESTAMP_LTZ == ociType)
            {
                TimeSpan tzadjust = connection.ServerTimeZoneAdjustmentToUTC;
                result[11] = (byte)(tzadjust.Hours + 20);
                result[12] = (byte)(tzadjust.Minutes + 60);
            }

            return(result);
        }
Example #28
0
        internal static int OCIRowidToChar(OciHandle rowidDesc, NativeBuffer outbfp, ref int bufferLength, OciHandle errhp)
        {
            ushort outbflp = (ushort)bufferLength;

            if (Bid.AdvancedOn)
            {
                Bid.Trace("<oc.OCIRowidToChar|ADV|OCI>          rowidDesc=0x%-07Ix outbfp=0x%-07Ix outbflp=%d, errhp=0x%-07Ix\n", OciHandle.HandleValueToTrace(rowidDesc), NativeBuffer.HandleValueToTrace(outbfp), outbfp.Length, OciHandle.HandleValueToTrace(errhp));
            }
            int num = System.Data.Common.UnsafeNativeMethods.OCIRowidToChar(rowidDesc, outbfp, ref outbflp, errhp);

            bufferLength = outbflp;
            if (Bid.AdvancedOn)
            {
                Bid.Trace("<oc.OCIRowidToChar|ADV|OCI|RET>      outbfp='%ls' rc=%d\n", outbfp.PtrToStringAnsi(0, outbflp), num);
            }
            return(num);
        }
        // (internal) construct from a row/parameter binding
        internal OracleBinary(
            NativeBuffer buffer,
            int valueOffset,
            int lengthOffset,
            MetaType metaType)
        {
            int valueLength = GetLength(buffer, lengthOffset, metaType);

            _value = new byte[valueLength];

            GetBytes(buffer,
                     valueOffset,
                     metaType,
                     0,
                     _value,
                     0,
                     valueLength);
        }
Example #30
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);
        }
 public override void Dispose()
 {
     this.Deactivate();
     OciEnlistContext.SafeDispose(ref this._enlistContext);
     OciHandle.SafeDispose(ref this._sessionHandle);
     OciHandle.SafeDispose(ref this._serviceContextHandle);
     OciHandle.SafeDispose(ref this._serverHandle);
     OciHandle.SafeDispose(ref this._errorHandle);
     OciHandle.SafeDispose(ref this._environmentHandle);
     if (this._scratchBuffer != null)
     {
         this._scratchBuffer.Dispose();
     }
     this._scratchBuffer = null;
     this._encodingDatabase = null;
     this._encodingNational = null;
     this._transaction = null;
     this._serverVersionString = null;
     base.Dispose();
 }
 internal NativeBuffer GetScratchBuffer(int minSize)
 {
     NativeBuffer buffer = this._scratchBuffer;
     if ((buffer == null) || (buffer.Length < minSize))
     {
         if (buffer != null)
         {
             buffer.Dispose();
         }
         buffer = new NativeBuffer_ScratchBuffer(minSize);
         this._scratchBuffer = buffer;
     }
     return buffer;
 }