Esempio n. 1
0
        /// <include file='doc\OracleBFile.uex' path='docs/doc[@for="OracleBFile.Read"]/*' />
        public override int Read(
            byte[] buffer,
            int offset,
            int count
            )
        {
            AssertInternalLobIsValid();

            if (!IsNull)
            {
                EnsureLobIsOpened();
            }

            int result = _lob.Read(buffer, offset, count);

            return(result);
        }
        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. 3
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. 4
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));
        }