internal OracleLob(OracleLob lob)
 {
     this._lobLocator = lob._lobLocator.Clone();
     this._lobType = lob._lobLocator.LobType;
     this._charsetForm = lob._charsetForm;
     this._currentPosition = lob._currentPosition;
     this._isTemporaryState = lob._isTemporaryState;
 }
Esempio n. 2
0
        public void SetBinaryData(int id, string fieldName, byte[] data)
        {
            string query = "select " + fieldName +
                           " from PUBLISH_HISTORY " +
                           " where ID  = " + id + " FOR UPDATE";

            using (DBCommandWrapper wrapper = GetSqlStringCommandWrapper(query))
            {
                using (System.Data.IDataReader reader = this.ExecuteReader(wrapper))
                {
                    if (reader.Read())
                    {
                        System.Data.OracleClient.OracleLob clob = ((OracleDataReaderWrapper)reader).InnerReader.GetOracleLob(0);
                        clob.Erase();
                        clob.Write(data, 0, data.Length);
                    }
                }
            }
        }
 public void Append(OracleLob source)
 {
     if (source == null)
     {
         throw System.Data.Common.ADP.ArgumentNull("source");
     }
     this.AssertObjectNotDisposed();
     source.AssertObjectNotDisposed();
     if (this.IsNull)
     {
         throw System.Data.Common.ADP.LobWriteInvalidOnNull();
     }
     if (!source.IsNull)
     {
         this.AssertConnectionIsOpen();
         int rc = TracedNativeMethods.OCILobAppend(this.ServiceContextHandle, this.ErrorHandle, this.Descriptor, source.Descriptor);
         if (rc != 0)
         {
             this.Connection.CheckError(this.ErrorHandle, rc);
         }
     }
 }
        protected void DataList1_SelectedIndexChanged(object sender, EventArgs e)
        {
            int idx = DataList1.SelectedIndex;

            Label lbl = (Label)DataList1.Items[idx].FindControl("Label2");

            System.Data.OracleClient.OracleConnection conn      = new System.Data.OracleClient.OracleConnection(ConfigurationManager.ConnectionStrings["CGConnectionString"].ToString());
            System.Data.OracleClient.OracleCommand    myCommand = new System.Data.OracleClient.OracleCommand("SELECT * FROM wf_cm_images WHERE ID = '" + lbl.Text + "'", conn);
            conn.Open();
            System.Data.OracleClient.OracleDataReader myReader = myCommand.ExecuteReader(System.Data.CommandBehavior.Default);
            try
            {
                while (myReader.Read())
                {
                    System.Data.OracleClient.OracleLob myLob = myReader.GetOracleLob(myReader.GetOrdinal("IMAGE"));
                    if (!myLob.IsNull)
                    {
                        string FN = myReader.GetString(myReader.GetOrdinal("IMAGE_NAME"));


                        //Use buffer to transfer data
                        byte[] b = new byte[myLob.Length];
                        //Read data from database
                        myLob.Read(b, 0, (int)myLob.Length);


                        Response.AddHeader("content-disposition", "attachment;filename=" + FN);
                        Response.ContentType = "application/octectstream";
                        Response.BinaryWrite(b);
                        Response.End();
                    }
                }
            }
            finally
            {
                myReader.Close();
                conn.Close();
            }
        }
Esempio n. 5
0
 public long CopyTo(OracleLob destination, long destinationOffset)
 {
     return(CopyTo(0, destination, destinationOffset, Length));
 }
Esempio n. 6
0
        internal long GetChars(NativeBuffer_RowBuffer buffer, long fieldOffset, char[] destinationBuffer, int destinationOffset, int length)
        {
            int num;

            if (length < 0)
            {
                throw System.Data.Common.ADP.InvalidDataLength((long)length);
            }
            if ((destinationOffset < 0) || ((destinationBuffer != null) && (destinationOffset >= destinationBuffer.Length)))
            {
                throw System.Data.Common.ADP.InvalidDestinationBufferIndex(destinationBuffer.Length, destinationOffset, "bufferoffset");
            }
            if ((0L > fieldOffset) || (0xffffffffL < fieldOffset))
            {
                throw System.Data.Common.ADP.InvalidSourceOffset("fieldOffset", 0L, 0xffffffffL);
            }
            if (this.IsLob)
            {
                System.Data.OracleClient.OracleType oracleType = this._metaType.OracleType;
                if (((System.Data.OracleClient.OracleType.Clob != oracleType) && (System.Data.OracleClient.OracleType.NClob != oracleType)) && (System.Data.OracleClient.OracleType.BFile != oracleType))
                {
                    throw System.Data.Common.ADP.InvalidCast();
                }
                if (this.IsDBNull(buffer))
                {
                    throw System.Data.Common.ADP.DataReaderNoData();
                }
                using (OracleLob lob = new OracleLob(this._lobLocator))
                {
                    string str        = (string)lob.Value;
                    int    maxLen     = str.Length;
                    int    startIndex = (int)fieldOffset;
                    if (startIndex < 0)
                    {
                        throw System.Data.Common.ADP.InvalidSourceBufferIndex(maxLen, (long)startIndex, "fieldOffset");
                    }
                    num = maxLen - startIndex;
                    if (destinationBuffer != null)
                    {
                        num = Math.Min(num, length);
                        if (0 < num)
                        {
                            Buffer.BlockCopy(str.ToCharArray(startIndex, num), 0, destinationBuffer, destinationOffset, num);
                        }
                    }
                    goto Label_0198;
                }
            }
            if ((((System.Data.OracleClient.OracleType.Char != this.OracleType) && (System.Data.OracleClient.OracleType.VarChar != this.OracleType)) && ((System.Data.OracleClient.OracleType.LongVarChar != this.OracleType) && (System.Data.OracleClient.OracleType.NChar != this.OracleType))) && (System.Data.OracleClient.OracleType.NVarChar != this.OracleType))
            {
                throw System.Data.Common.ADP.InvalidCast();
            }
            if (this.IsDBNull(buffer))
            {
                throw System.Data.Common.ADP.DataReaderNoData();
            }
            this.FixupLongValueLength(buffer);
            int num5         = OracleString.GetLength(buffer, this._lengthOffset, this._metaType);
            int sourceOffset = (int)fieldOffset;

            num = num5 - sourceOffset;
            if (destinationBuffer != null)
            {
                num = Math.Min(num, length);
                if (0 < num)
                {
                    OracleString.GetChars(buffer, this._valueOffset, this._lengthOffset, this._metaType, this._connection, this._bindAsUTF16, sourceOffset, destinationBuffer, destinationOffset, num);
                }
            }
Label_0198:
            return((long)Math.Max(0, num));
        }
Esempio n. 7
0
 public long CopyTo(OracleLob destination)
 {
     return(CopyTo(0, destination, 0, Length));
 }
Esempio n. 8
0
        /// <include file='doc\OracleBFile.uex' path='docs/doc[@for="OracleBFile.CopyTo3"]/*' />
        public long CopyTo(
            long sourceOffset,
            OracleLob destination,
            long destinationOffset,
            long amount
            )
        {
            // Copies a range of elements from the lob to a compatible lob, starting at the specified index of the target array.
            AssertInternalLobIsValid();

            if (null == destination)
            {
                throw ADP.ArgumentNull("destination");
            }

            if (destination.IsNull)
            {
                throw ADP.LobWriteInvalidOnNull();
            }

            if (_lob.IsNull)
            {
                return(0);
            }

            _lob.AssertConnectionIsOpen();

            _lob.AssertAmountIsValid(amount, "amount");
            _lob.AssertAmountIsValid(sourceOffset, "sourceOffset");
            _lob.AssertAmountIsValid(destinationOffset, "destinationOffset");

            _lob.AssertTransactionExists();

            int rc;

            _lob.EnsureBuffering(false);
            destination.EnsureBuffering(false);

            long dataCount = Math.Min(Length - sourceOffset, amount);
            long dstOffset = destinationOffset + 1;             // Oracle is 1 based, we are zero based.
            long srcOffset = sourceOffset + 1;                  // Oracle is 1 based, we are zero based.

            if (0 >= dataCount)
            {
                return(0);
            }

            rc = TracedNativeMethods.OCILobLoadFromFile(
                ServiceContextHandle,
                ErrorHandle,
                destination.Descriptor,
                Descriptor,
                (UInt32)dataCount,
                (UInt32)dstOffset,
                (UInt32)srcOffset
                );
            if (0 != rc)
            {
                Connection.CheckError(ErrorHandle, rc);
            }

            // DEVNOTE: Oracle must not do partial copies, because their API doesn't tell you how many bytes were copied.
            return(dataCount);
        }
Esempio n. 9
0
		public long CopyTo (long sourceOffset, OracleLob destination, long destinationOffset, long amount)
		{
			if (destination.IsNull)
				throw new ArgumentNullException ();

			AssertAmountIsValid (sourceOffset, "sourceOffset");
			AssertAmountIsValid (destinationOffset, "destinationOffset");
			AssertAmountIsValid (amount, "amount");
			AssertTransactionExists ();
			AssertConnectionIsOpen ();

			return (long) locator.Copy (destination.Locator, (uint) amount, (uint) destinationOffset + 1, (uint) sourceOffset + 1);
		}
 public long CopyTo(OracleLob destination)
 {
     return(this.CopyTo(0L, destination, 0L, this.Length));
 }
 public long CopyTo(OracleLob destination)
 {
     throw new NotImplementedException();
 }
 public long CopyTo(long sourceOffset, OracleLob destination, long destinationOffset, long amount)
 {
     if (destination == null)
     {
         throw System.Data.Common.ADP.ArgumentNull("destination");
     }
     this.AssertObjectNotDisposed();
     destination.AssertObjectNotDisposed();
     this.AssertAmountIsValid(amount, "amount");
     this.AssertAmountIsValid(sourceOffset, "sourceOffset");
     this.AssertAmountIsValid(destinationOffset, "destinationOffset");
     if (destination.IsNull)
     {
         throw System.Data.Common.ADP.LobWriteInvalidOnNull();
     }
     if (this.IsNull)
     {
         return 0L;
     }
     this.AssertConnectionIsOpen();
     this.AssertTransactionExists();
     long num = this.AdjustOffsetToOracle(Math.Min(this.Length - sourceOffset, amount));
     long num5 = this.AdjustOffsetToOracle(destinationOffset) + 1L;
     long num4 = this.AdjustOffsetToOracle(sourceOffset) + 1L;
     if (0L >= num)
     {
         return 0L;
     }
     int rc = TracedNativeMethods.OCILobCopy(this.ServiceContextHandle, this.ErrorHandle, destination.Descriptor, this.Descriptor, (uint) num, (uint) num5, (uint) num4);
     if (rc != 0)
     {
         this.Connection.CheckError(this.ErrorHandle, rc);
     }
     return this.AdjustOracleToOffset(num);
 }
 public long CopyTo(OracleLob destination, long destinationOffset)
 {
     return(this.CopyTo(0L, destination, destinationOffset, this.Length));
 }
 public long CopyTo(OracleLob destination)
 {
     return this.CopyTo(0L, destination, 0L, this.Length);
 }
 public long CopyTo(OracleLob destination, long destinationOffset)
 {
     return this.CopyTo(0L, destination, destinationOffset, this.Length);
 }
Esempio n. 16
0
 // (internal) Construct from an existing BFile object (copy constructor)
 internal OracleBFile(OracleBFile bfile)
 {
     this._lob            = (OracleLob)bfile._lob.Clone();
     this._fileName       = bfile._fileName;
     this._directoryAlias = bfile._directoryAlias;
 }
Esempio n. 17
0
 // (internal) Construct from a data reader buffer
 internal OracleBFile(OciLobLocator lobLocator)
 {
     _lob = new OracleLob(lobLocator);
 }
Esempio n. 18
0
        ////////////////////////////////////////////////////////////////////////
        ////////////////////////////////////////////////////////////////////////
        //
        // Constructors
        //
        ////////////////////////////////////////////////////////////////////////
        ////////////////////////////////////////////////////////////////////////

        // (internal) Construct a null lob
        internal OracleBFile()
        {
            _lob = OracleLob.Null;
        }
        public override object ExecuteScalar()
        {
            moreResults = -1;
            object output = null;            //if we find nothing we return this

            AssertConnectionIsOpen();
            AssertTransactionMatch();
            AssertCommandTextIsSet();

            if (Transaction != null)
            {
                Transaction.AttachToServiceContext();
            }

            OciStatementHandle statement = GetStatementHandle();

            try {
                if (preparedStatement == null)
                {
                    PrepareStatement(statement);
                }

                bool isNonQuery = IsNonQuery(statement);

                BindParameters(statement);

                if (isNonQuery == true)
                {
                    ExecuteNonQueryInternal(statement, false);
                }
                else
                {
                    statement.ExecuteQuery(false);

                    if (statement.Fetch())
                    {
                        OciDefineHandle defineHandle = (OciDefineHandle)statement.Values [0];
                        if (!defineHandle.IsNull)
                        {
                            switch (defineHandle.DataType)
                            {
                            case OciDataType.Blob:
                            case OciDataType.Clob:
                                OracleLob lob = (OracleLob)defineHandle.GetValue(
                                    Connection.SessionFormatProvider, Connection);
                                lob.connection = Connection;
                                output         = lob.Value;
                                lob.Close();
                                break;

                            default:
                                output = defineHandle.GetValue(
                                    Connection.SessionFormatProvider, Connection);
                                break;
                            }
                        }
                    }
                    UpdateParameterValues();
                }
            } finally {
                SafeDisposeHandle(statement);
            }

            return(output);
        }
Esempio n. 20
0
		public long CopyTo (OracleLob destination, long destinationOffset) {
			throw new NotImplementedException ();
		}
Esempio n. 21
0
        static internal MetaType GetMetaTypeForObject(object value)
        {
            Type dataType;

            if (value is Type)
            {
                dataType = (Type)value;
            }
            else
            {
                dataType = value.GetType();
            }

            switch (Type.GetTypeCode(dataType))
            {
            case TypeCode.Empty:    throw ADP.InvalidDataType(TypeCode.Empty);

            case TypeCode.DBNull:   throw ADP.InvalidDataType(TypeCode.DBNull);

            case TypeCode.Boolean:  return(dbTypeMetaType[(int)DbType.Boolean]);

            case TypeCode.Char:             return(dbTypeMetaType[(int)DbType.Byte]);

            case TypeCode.SByte:    return(dbTypeMetaType[(int)DbType.SByte]);

            case TypeCode.Byte:             return(dbTypeMetaType[(int)DbType.Byte]);

            case TypeCode.Int16:    return(dbTypeMetaType[(int)DbType.Int16]);

            case TypeCode.UInt16:   return(dbTypeMetaType[(int)DbType.UInt16]);

            case TypeCode.Int32:    return(dbTypeMetaType[(int)DbType.Int32]);

            case TypeCode.UInt32:   return(dbTypeMetaType[(int)DbType.UInt32]);

            case TypeCode.Int64:    return(dbTypeMetaType[(int)DbType.Int64]);

            case TypeCode.UInt64:   return(dbTypeMetaType[(int)DbType.UInt64]);

            case TypeCode.Single:   return(dbTypeMetaType[(int)DbType.Single]);

            case TypeCode.Double:   return(dbTypeMetaType[(int)DbType.Double]);

            case TypeCode.Decimal:  return(dbTypeMetaType[(int)DbType.Decimal]);

            case TypeCode.DateTime: return(dbTypeMetaType[(int)DbType.DateTime]);

            case TypeCode.String:   return(dbTypeMetaType[(int)DbType.AnsiString]);

            case TypeCode.Object:
                if (dataType == typeof(System.Byte[]))
                {
                    return(dbTypeMetaType[(int)DbType.Binary]);
                }
                if (dataType == typeof(System.Guid))
                {
                    return(dbTypeMetaType[(int)DbType.Guid]);
                }
                if (dataType == typeof(System.Object))
                {
                    throw ADP.InvalidDataTypeForValue(dataType, Type.GetTypeCode(dataType));
                }

                if (dataType == typeof(OracleBFile))
                {
                    return(oracleTypeMetaType[(int)OracleType.BFile]);
                }
                if (dataType == typeof(OracleBinary))
                {
                    return(oracleTypeMetaType[(int)OracleType.Raw]);
                }
                if (dataType == typeof(OracleDateTime))
                {
                    return(oracleTypeMetaType[(int)OracleType.DateTime]);
                }
                if (dataType == typeof(OracleNumber))
                {
                    return(oracleTypeMetaType[(int)OracleType.Number]);
                }
                if (dataType == typeof(OracleString))
                {
                    return(oracleTypeMetaType[(int)OracleType.VarChar]);
                }

                if (dataType == typeof(OracleLob))
                {
                    OracleLob lob = (OracleLob)value;

                    switch (lob.LobType)
                    {
                    case OracleType.Blob:   return(oracleTypeMetaType[(int)OracleType.Blob]);

                    case OracleType.Clob:   return(oracleTypeMetaType[(int)OracleType.Clob]);

                    case OracleType.NClob:  return(oracleTypeMetaType[(int)OracleType.NClob]);
                    }
                }

                throw ADP.UnknownDataTypeCode(dataType, Type.GetTypeCode(dataType));

            default:                                throw ADP.UnknownDataTypeCode(dataType, Type.GetTypeCode(dataType));
            }
        }
Esempio n. 22
0
		private void GetOutValue (OracleCommand cmd)
		{
			// used to update the parameter value
			// for Output, the output of InputOutput, and Return parameters
			value = DBNull.Value;
			if (Indicator == -1)
				return;

			int rsize = 0;
			IntPtr env = IntPtr.Zero;
			StringBuilder ret = null;

			// FIXME: redo all types - see how Char, Number, and Date are done
			// here and in Bind()

			switch (ociType) {
			case OciDataType.VarChar2:
			case OciDataType.String:
			case OciDataType.VarChar:
			case OciDataType.Char:
			case OciDataType.CharZ:
			case OciDataType.OciString:
			case OciDataType.RowIdDescriptor:
				// Get length of returned string
				rsize = 0;
				env = cmd.Connection.Environment;
				OciCalls.OCICharSetToUnicode (env, null, bytes, out rsize);

				// Get string
				ret = new StringBuilder(rsize);
				OciCalls.OCICharSetToUnicode (env, ret, bytes, out rsize);

				value = ret.ToString ();
				break;
			case OciDataType.Long:
			case OciDataType.LongVarChar:
				int longSize = 0;
				if (BitConverter.IsLittleEndian)
					longSize = BitConverter.ToInt32 (new byte [] {bytes [0], bytes [1], bytes [2], bytes [3]}, 0);
				else
					longSize = BitConverter.ToInt32 (new byte [] {bytes [3], bytes [2], bytes [1], bytes [0]}, 0);

				ASCIIEncoding encoding = new ASCIIEncoding ();
				value = encoding.GetString (bytes, 4, longSize);
				encoding = null;
				break;
			case OciDataType.LongRaw:
			case OciDataType.LongVarRaw:
				int longrawSize = 0;
				if (BitConverter.IsLittleEndian)
					longrawSize = BitConverter.ToInt32 (new byte [] {bytes [0], bytes [1], bytes [2], bytes [3]}, 0);
				else
					longrawSize = BitConverter.ToInt32 (new byte [] {bytes [3], bytes [2], bytes [1], bytes [0]}, 0);

				byte[] longraw_buffer = new byte [longrawSize];
				Array.ConstrainedCopy (bytes, 4, longraw_buffer, 0, longrawSize);
				value = longraw_buffer;
				break;
			case OciDataType.Raw:
			case OciDataType.VarRaw:
				int rawSize = 0;
				if (BitConverter.IsLittleEndian)
					rawSize = (int) BitConverter.ToInt16 (new byte [] {bytes [0], bytes [1]}, 0);
				else
					rawSize = (int) BitConverter.ToInt16 (new byte [] {bytes [1], bytes [0]}, 0);

				byte[] raw_buffer = new byte [rawSize];
				Array.ConstrainedCopy (bytes, 2, raw_buffer, 0, rawSize);
				value = raw_buffer;
				break;
			case OciDataType.Integer:
			case OciDataType.Number:
			case OciDataType.Float:
				rsize = 0;
				env = cmd.Connection.Environment;
				OciCalls.OCICharSetToUnicode (env, null, bytes, out rsize);

				// Get string
				ret = new StringBuilder(rsize);
				OciCalls.OCICharSetToUnicode (env, ret, bytes, out rsize);

				// if not empty, parse string as a decimal using session format
				if (ret.Length > 0) {
					switch (dbType) {
					case DbType.UInt16: 
						value = UInt16.Parse (ret.ToString (), cmd.Connection.SessionFormatProvider);
						break;
					case DbType.UInt32: 
						value = UInt32.Parse (ret.ToString (), cmd.Connection.SessionFormatProvider);
						break;
					case DbType.Int16:
						value = Int16.Parse (ret.ToString (), cmd.Connection.SessionFormatProvider);
						break;							
					case DbType.Int32:
						value = Int32.Parse (ret.ToString (), cmd.Connection.SessionFormatProvider);
						break;
					default:
						value = Decimal.Parse (ret.ToString (), cmd.Connection.SessionFormatProvider);
						break;
					}
				}
				break;
			case OciDataType.TimeStamp:
				value = dateTimeDesc.GetDateTime (connection.Environment, dateTimeDesc.ErrorHandle);
				break;
			case OciDataType.Date:
				value = UnpackDate (bytes);
				break;
			case OciDataType.Blob:
			case OciDataType.Clob:
				if (value != null && value is OracleLob && value != OracleLob.Null) {
					OracleLob lob2 = (OracleLob) value;
					lob2.connection = connection;
				}
				else {
					OracleLob lob = new OracleLob (lobLocator, ociType);
					lob.connection = connection;
					value = lob;
				}
				break;
			case OciDataType.RSet: // REF CURSOR				
				OciStatementHandle cursorStatement = GetOutRefCursor (cmd);
				value = new OracleDataReader (cursorStatement.Command, cursorStatement, true, CommandBehavior.Default);
				break;
			default:
				throw new NotImplementedException ("Data Type not implemented: " + ociType.ToString() + ".");
			}
		}
Esempio n. 23
0
		public long CopyTo (long sourceOffset, OracleLob destination, long destinationOffset, long amount) {
			if (destination.IsNull)
				throw new ArgumentNullException ();

			AssertAmountIsValid (sourceOffset, "sourceOffset");
			AssertAmountIsValid (destinationOffset, "destinationOffset");
			AssertAmountIsValid (amount, "amount");
			AssertTransactionExists ();
			AssertConnectionIsOpen ();

			throw new NotImplementedException ();
		}
Esempio n. 24
0
		public long CopyTo (OracleLob destination)
		{
			return CopyTo (0, destination, 0, Length);
		}
Esempio n. 25
0
 //[MonoTODO]
 public long CopyTo(long sourceOffset, OracleLob destination, long destinationOffset, long amount)
 {
     throw new NotImplementedException();
 }
Esempio n. 26
0
 /// <include file='doc\OracleBFile.uex' path='docs/doc[@for="OracleBFile.CopyTo1"]/*' />
 public long CopyTo(OracleLob destination)
 {
     // Copies the entire lob to a compatible lob, starting at the beginning of the target array.
     return(CopyTo(0, destination, 0, Length));
 }
Esempio n. 27
0
		public long CopyTo (long sourceOffset, OracleLob destination, long destinationOffset, long amount) {
			throw new NotImplementedException ();
		}
Esempio n. 28
0
 void TrySeek(OracleLob lob, long offset, SeekOrigin start, long expected, int id)
 {
         try {
                 lob.Seek (offset, start);
                 Assert.AreEqual (expected, lob.Position, "Lob position was unexpected [" + id + ']');
         }
         catch (ArgumentOutOfRangeException) {
                 Assert.Fail ("Unable to perform a legal seek [" + id + ']');
         }
 }
Esempio n. 29
0
		public void Append (OracleLob source) 
		{
			if (source.IsNull)
				throw new ArgumentNullException ();
			if (Connection.State == ConnectionState.Closed)
				throw new InvalidOperationException ();
			throw new NotImplementedException ();
		}
Esempio n. 30
0
 void TryRead(OracleLob lob, long expectedCount, int id)
 {
         try {
                 long numberRead = lob.Read (new byte [10], 0, 10);
                 Assert.AreEqual (expectedCount, numberRead, "Wrong number of bytes read [" + id + ']');
         }
         catch (OracleException e) {
                 if (e.Code == 24801)
                         Assert.Fail ("Unable to perform a legal read [" + id + ']');
                 else throw;
         }
 }
Esempio n. 31
0
		public long CopyTo (OracleLob destination, long destinationOffset)
		{
			return CopyTo (0, destination, destinationOffset, Length);
		}
        internal static MetaType GetMetaTypeForObject(object value)
        {
            Type type;

            if (value is Type)
            {
                type = (Type)value;
            }
            else
            {
                type = value.GetType();
            }
            switch (Type.GetTypeCode(type))
            {
            case TypeCode.Empty:
                throw System.Data.Common.ADP.InvalidDataType(TypeCode.Empty);

            case TypeCode.Object:
                if (!(type == typeof(byte[])))
                {
                    if (type == typeof(Guid))
                    {
                        return(dbTypeMetaType[9]);
                    }
                    if (type == typeof(object))
                    {
                        throw System.Data.Common.ADP.InvalidDataTypeForValue(type, Type.GetTypeCode(type));
                    }
                    if (type == typeof(OracleBFile))
                    {
                        return(oracleTypeMetaType[1]);
                    }
                    if (type == typeof(OracleBinary))
                    {
                        return(oracleTypeMetaType[15]);
                    }
                    if (type == typeof(OracleDateTime))
                    {
                        return(oracleTypeMetaType[6]);
                    }
                    if (type == typeof(OracleNumber))
                    {
                        return(oracleTypeMetaType[13]);
                    }
                    if (type == typeof(OracleString))
                    {
                        return(oracleTypeMetaType[0x16]);
                    }
                    if (type == typeof(OracleLob))
                    {
                        OracleLob lob = (OracleLob)value;
                        switch (lob.LobType)
                        {
                        case System.Data.OracleClient.OracleType.Blob:
                            return(oracleTypeMetaType[2]);

                        case System.Data.OracleClient.OracleType.Clob:
                            return(oracleTypeMetaType[4]);

                        case System.Data.OracleClient.OracleType.NClob:
                            return(oracleTypeMetaType[12]);
                        }
                    }
                    break;
                }
                return(dbTypeMetaType[1]);

            case TypeCode.DBNull:
                throw System.Data.Common.ADP.InvalidDataType(TypeCode.DBNull);

            case TypeCode.Boolean:
                return(dbTypeMetaType[3]);

            case TypeCode.Char:
                return(dbTypeMetaType[2]);

            case TypeCode.SByte:
                return(dbTypeMetaType[14]);

            case TypeCode.Byte:
                return(dbTypeMetaType[2]);

            case TypeCode.Int16:
                return(dbTypeMetaType[10]);

            case TypeCode.UInt16:
                return(dbTypeMetaType[0x12]);

            case TypeCode.Int32:
                return(dbTypeMetaType[11]);

            case TypeCode.UInt32:
                return(dbTypeMetaType[0x13]);

            case TypeCode.Int64:
                return(dbTypeMetaType[12]);

            case TypeCode.UInt64:
                return(dbTypeMetaType[20]);

            case TypeCode.Single:
                return(dbTypeMetaType[15]);

            case TypeCode.Double:
                return(dbTypeMetaType[8]);

            case TypeCode.Decimal:
                return(dbTypeMetaType[7]);

            case TypeCode.DateTime:
                return(dbTypeMetaType[6]);

            case TypeCode.String:
                return(dbTypeMetaType[0]);

            default:
                throw System.Data.Common.ADP.UnknownDataTypeCode(type, Type.GetTypeCode(type));
            }
            throw System.Data.Common.ADP.UnknownDataTypeCode(type, Type.GetTypeCode(type));
        }
        private OracleLob CreateTemporaryLobForValue(OracleConnection connection, OracleType oracleType, object value)
        {
            switch (oracleType)
            {
                case OracleType.BFile:
                    oracleType = OracleType.Blob;
                    break;

                case OracleType.Blob:
                case OracleType.Clob:
                case OracleType.NClob:
                    break;

                default:
                    throw System.Data.Common.ADP.InvalidLobType(oracleType);
            }
            OracleLob stream = new OracleLob(connection, oracleType);
            byte[] buffer = value as byte[];
            if (buffer != null)
            {
                stream.Write(buffer, 0, buffer.Length);
                return stream;
            }
            Encoding encoding = new UnicodeEncoding(false, false);
            stream.Seek(0L, SeekOrigin.Begin);
            StreamWriter writer = new StreamWriter(stream, encoding);
            writer.Write(value);
            writer.Flush();
            return stream;
        }
Esempio n. 34
0
        internal long GetBytes(NativeBuffer_RowBuffer buffer, long fieldOffset, byte[] destinationBuffer, int destinationOffset, int length)
        {
            int num;

            if (length < 0)
            {
                throw System.Data.Common.ADP.InvalidDataLength((long)length);
            }
            if ((destinationOffset < 0) || ((destinationBuffer != null) && (destinationOffset >= destinationBuffer.Length)))
            {
                throw System.Data.Common.ADP.InvalidDestinationBufferIndex(destinationBuffer.Length, destinationOffset, "bufferoffset");
            }
            if ((0L > fieldOffset) || (0xffffffffL < fieldOffset))
            {
                throw System.Data.Common.ADP.InvalidSourceOffset("fieldOffset", 0L, 0xffffffffL);
            }
            if (this.IsLob)
            {
                System.Data.OracleClient.OracleType oracleType = this._metaType.OracleType;
                if ((System.Data.OracleClient.OracleType.Blob != oracleType) && (System.Data.OracleClient.OracleType.BFile != oracleType))
                {
                    throw System.Data.Common.ADP.InvalidCast();
                }
                if (this.IsDBNull(buffer))
                {
                    throw System.Data.Common.ADP.DataReaderNoData();
                }
                using (OracleLob lob = new OracleLob(this._lobLocator))
                {
                    uint num3 = (uint)lob.Length;
                    uint num2 = (uint)fieldOffset;
                    if (num2 > num3)
                    {
                        throw System.Data.Common.ADP.InvalidSourceBufferIndex((int)num3, (long)num2, "fieldOffset");
                    }
                    num = (int)(num3 - num2);
                    if (destinationBuffer != null)
                    {
                        num = Math.Min(num, length);
                        if (0 < num)
                        {
                            lob.Seek((long)num2, SeekOrigin.Begin);
                            lob.Read(destinationBuffer, destinationOffset, num);
                        }
                    }
                    goto Label_0155;
                }
            }
            if ((System.Data.OracleClient.OracleType.Raw != this.OracleType) && (System.Data.OracleClient.OracleType.LongRaw != this.OracleType))
            {
                throw System.Data.Common.ADP.InvalidCast();
            }
            if (this.IsDBNull(buffer))
            {
                throw System.Data.Common.ADP.DataReaderNoData();
            }
            this.FixupLongValueLength(buffer);
            int num5         = OracleBinary.GetLength(buffer, this._lengthOffset, this._metaType);
            int sourceOffset = (int)fieldOffset;

            num = num5 - sourceOffset;
            if (destinationBuffer != null)
            {
                num = Math.Min(num, length);
                if (0 < num)
                {
                    OracleBinary.GetBytes(buffer, this._valueOffset, this._metaType, sourceOffset, destinationBuffer, destinationOffset, num);
                }
            }
Label_0155:
            return((long)Math.Max(0, num));
        }