Skip Headers

Oracle Data Provider for .NET Developer's Guide
Release 9.2.0.2

Part Number A96160-01
Go To Table Of Contents
Contents
Go To Index
Index

Go to previous page Go to beginning of chapter Go to next page

Oracle.DataAccess.Types Namespace (ODP.NET Types), 15 of 17


OracleBlob Class

An OracleBlob object is an object that has a reference to BLOB data. It provides methods for performing operations on BLOBs.

Class Inheritance

Object

  MarshalByRefObject

    Stream

      OracleBlob

Declaration
// C#
public sealed class OracleBlob : Stream, ICloneable
Thread Safety

All public static methods are thread-safe, although instance methods do not guarantee thread safety.

Example
[C#]
...
// assume: A valid connection is made
OracleBlob oraBlob = new OracleBlob(con);

// Read some data
...
int byteRead = oraBlob.Read(buffer, bufferOffset, amountToBeRead);

// Search for the 2nd occurrence of a byte pattern '123'
// from the oraBlob starting at offset 1
byte[] pattern = new byte[3] { 1,2,3 };
int positionFound = oraBlob.Search(pattern, 1, 2);

// Append 2 bytes {4,5} to the oraBlob
oraBlob.Append(new byte[3] {4,5,6}, 1, 2);

// Write 64 bytes, starting at buffer offset 512
byte[4096] buffer = new byte[4096];
...
oraBlob.Write(buffer, 512, 64);

// Erase 64 bytes of data starting at offset=1024
oraBlob.Erase(1024,64);
...

Requirements

Namespace: Oracle.DataAccess.Types

Assembly: Oracle.DataAccesss.dll

See Also:

OracleBlob Members

OracleBlob members are listed in the following tables:

OracleBlob Constructors

OracleBlob constructors are listed in Table 5-156.

Table 5-156 OracleBlob Constructors  
Constructor Description

OracleBlob Constructors

Creates an instance of the OracleBlob class (Overloaded)

OracleBlob Static Fields

OracleBlob static fields are listed in Table 5-157.

Table 5-157 OracleBlob Static Fields  
Field Description

MaxSize

Holds the maximum number of bytes a BLOB can hold, which is 4,294,967,295 (2^32 - 1) bytes

OracleBlob Static Methods

OracleBlob static methods are listed in Table 5-158.

Table 5-158 OracleBlob Static Methods  
Methods Description

Equals

Inherited from Object (Overloaded)

OracleBlob Instance Properties

OracleBlob instance properties are listed in Table 5-159.

Table 5-159 OracleBlob Instance Properties  
Properties Description

CanRead

Indicates whether the LOB stream can be read

CanSeek

Indicates whether forward and backward seek operations be performed

CanWrite

Indicates whether the LOB object supports writing

Connection

Indicates the OracleConnection that is used to retrieve and write BLOB data

IsEmpty

Indicates whether the BLOB is empty or not

IsInChunkWriteMode

Indicates whether the BLOB has been opened to defer index updates

IsTemporary

Indicates whether or not the current instance is bound to a temporary BLOB

Length

Indicates the size of the BLOB data

OptimumChunkSize

Indicates the minimum number of bytes to retrieve or send from the server during a read or write operation

Position

Indicates the current read or write position in the LOB stream

Value

Returns the data, starting from the first byte in BLOB, as a byte array

OracleBlob Instance Methods

OracleBlob instance methods are listed in Table 5-160.

Table 5-160 OracleBlob Instance Methods  
Methods Description

Append

Appends the supplied data to the current OracleBlob instance (Overloaded)

BeginChunkWrite

Opens the BLOB

BeginRead

Inherited from Stream

BeginWrite

Inherited from Stream

Clone

Creates a copy of an OracleBlob object

Close

Closes the current stream and releases any resources associated with it

Compare

Compares data referenced by the current instance and that of the supplied object

CopyTo

Copies from the current OracleBlob instance to an OracleBlob object (Overloaded)

CreateObjRef

Inherited from MarshalByRefObject

Dispose

Releases resources allocated by this object

EndChunkWrite

Closes the BLOB referenced by the current OracleBlob instance

EndRead

Inherited from Stream

EndWrite

Inherited from Stream

Equals

Inherited from Object (Overloaded)

Erase

Erases data (Overloaded)

Flush

Not supported

GetHashCode

Inherited from Object

GetLifetimeService

Inherited from MarshalByRefObject

GetType

Inherited from Object

InitializedLifetimeService

Inherited from MarshalByRefObject

IsEqual

Compares the LOB data referenced by the two OracleBlobs

Read

Reads a specified amount of bytes from the ODP.NET LOB Type instance and populates the buffer

ReadByte

Inherited from Stream

Search

Searches for a binary pattern in the current instance of an OracleBlob

Seek

Sets the position in the current LOB stream

SetLength

Trims or truncates the BLOB value to the specified length

ToString

Inherited from Object

Write

Writes the supplied buffer into the OracleBlob

WriteByte

Inherited from Stream

See Also:

OracleBlob Constructors

OracleBlob constructors are listed in Table 5-156.

Overload List:

OracleBlob(OracleConnection)

This constructor creates an instance of the OracleBlob class bound to a temporary BLOB with an OracleConnection object.

Declaration
// C#
public OracleBlob(OracleConnection con);
Parameters
Exceptions

InvalidOperationException - The OracleConnection is not opened.

Remarks

The connection must be opened explicitly by the application. OracleBlob does not open the connection implicitly.

The temporary BLOB utilizes the provided connection to store BLOB data. Caching is not turned on by this constructor.

OracleBlob(OracleConnection, bool)

This constructor creates an instance of the OracleBlob class bound to a temporary BLOB with an OracleConnection object and a boolean value for caching.

Declaration
// C#
public OracleBlob(OracleConnection con, bool bCaching);
Parameters
Exceptions

InvalidOperationException - The OracleConnection is not opened.

Remarks

The connection must be opened explicitly by the application. OracleBlob does not open the connection implicitly.

The temporary BLOB uses the provided connection to store BLOB data. The bCaching input parameter determines whether or not server-side caching is used.

OracleBlob Static Fields

OracleBlob static fields are listed in Table 5-161.

Table 5-161 OracleBlob Static Fields  
Field Description

MaxSize

Holds the maximum number of bytes a BLOB can hold, which is 4,294,967,295 (2^32 - 1) bytes

See Also:

MaxSize

The MaxSize field holds the maximum number of bytes a BLOB can hold, which is 4,294,967,295 (2^32 - 1) bytes.

Declaration
// C#
public static readonly Int64 MaxSize = 4294967295;
Remarks

This field can be useful in code that checks whether the operation exceeds the maximum length allowed.

OracleBlob Static Methods

OracleBlob static methods are listed in Table 5-162.

Table 5-162 OracleBlob Static Methods  
Methods Description

Equals

Inherited from Object (Overloaded)

See Also:

OracleBlob Instance Properties

OracleBlob instance properties are listed in Table 5-163.

Table 5-163 OracleBlob Instance Properties  
Properties Description

CanRead

Indicates whether the LOB stream can be read

CanSeek

Indicates whether forward and backward seek operations be performed

CanWrite

Indicates whether the LOB object supports writing

Connection

Indicates the OracleConnection that is used to retrieve and write BLOB data

IsEmpty

Indicates whether the BLOB is empty or not

IsInChunkWriteMode

Indicates whether the BLOB has been opened to defer index updates

IsTemporary

Indicates whether or not the current instance is bound to a temporary BLOB

Length

Indicates the size of the BLOB data

OptimumChunkSize

Indicates the minimum number of bytes to retrieve or send from the server during a read or write operation

Position

Indicates the current read or write position in the LOB stream

Value

Returns the data, starting from the first byte in BLOB, as a byte array

See Also:

CanRead

Overrides Stream

This instance property indicates whether the LOB stream can be read.

Declaration
// C#
public override bool CanRead{get;}
Property Value

If the LOB stream can be read, returns true; otherwise, returns false.

CanSeek

Overrides Stream

This instance property indicates whether forward and backward seek operations can be performed.

Declaration
// C#
public override bool CanSeek{get;}
Property Value

If forward and backward seek operations can be performed, returns true; otherwise, returns false.

CanWrite

Overrides Stream

This instance property indicates whether the LOB object supports writing.

Declaration
// C#
public override bool CanWrite{get;}
Property Value

If the LOB stream can be written, returns true; otherwise, returns false.

Connection

This instance property indicates the OracleConnection that is used to retrieve and write BLOB data.

Declaration
// C#
public OracleConnection Connection {get;}
Property Value

An object of OracleConnection.

Exceptions

ObjectDisposedException - The object is already disposed.

IsEmpty

This instance property indicates whether the BLOB is empty or not.

Declaration
// C#
public bool IsEmpty {get;}
Property Value

A bool that indicates whether the BLOB is empty.

Exceptions

ObjectDisposedException - The object is already disposed.

IsInChunkWriteMode

This instance property indicates whether the BLOB has been opened to defer index updates.

Declaration
// C#
public bool IsInChunkWriteMode{get;}
Property Value

If the BLOB has been opened, returns true; otherwise, returns false.

IsTemporary

This instance property indicates whether or not the current instance is bound to a temporary BLOB.

Declaration
// C#
public bool IsTemporary {get;}
Property Value

bool

Length

Overrides Stream

This instance property indicates the size of the BLOB data in bytes.

Declaration
// C#
public override Int64 Length {get;}
Property Value

A number indicating the size of the BLOB data in bytes.

Exceptions

ObjectDisposedException - The object is already disposed.

InvalidOperationException - The OracleConnection is not open or has been closed during the lifetime of the object.

OptimumChunkSize

This instance property indicates the minimum number of bytes to retrieve or send from the server during a read or write operation.

Declaration
// C#
public int OptimumChunkSize{get;}
Property Value

A number representing the minimum bytes to retrieve or send.

Exceptions

ObjectDisposedException - The object is already disposed.

Position

Overrides Stream

This instance property indicates the current read or write position in the LOB stream.

Declaration
// C#
public override Int64 Position{get; set;}
Property Value

An Int64 that indicates the read or write position.

Exceptions

ObjectDisposedException - The object is already disposed.

InvalidOperationException - The OracleConnection is not open or has been closed during the lifetime of the object.

ArgumentOutOfRangeException - The Position is less than 0.

Value

This instance property returns the data, starting from the first byte in the BLOB, as a byte array.

Declaration
// C#
public Byte[] Value{get;}
Property Value

A byte array.

Exceptions

ObjectDisposedException - The object is already disposed.

InvalidOperationException - The OracleConnection is not open or has been closed during the lifetime of the object.

ArgumentOutOfRangeException - The Value is less than 0.

Remarks

The value of Position is not used or changed by using this property. 2 GB is the maximum byte array length that can be returned by this property.

OracleBlob Instance Methods

OracleBlob instance methods are listed in Table 5-164.

Table 5-164 OracleBlob Instance Methods  
Methods Description

Append

Appends the supplied data to the current OracleBlob instance (Overloaded)

BeginChunkWrite

Opens the BLOB

BeginRead

Inherited from Stream

BeginWrite

Inherited from Stream

Clone

Creates a copy of an OracleBlob object

Close

Closes the current stream and releases any resources associated with it

Compare

Compares data referenced by the current instance and that of the supplied object

CopyTo

Copies from the current OracleBlob instance to an OracleBlob object (Overloaded)

CreateObjRef

Inherited from MarshalByRefObject

Dispose

Releases resources allocated by this object

EndChunkWrite

Closes the BLOB referenced by the current OracleBlob instance

EndRead

Inherited from Stream

EndWrite

Inherited from Stream

Equals

Inherited from Object (Overloaded)

Erase

Erases data (Overloaded)

Flush

Not supported

GetHashCode

Inherited from Object

GetLifetimeService

Inherited from MarshalByRefObject

GetType

Inherited from Object

InitializedLifetimeService

Inherited from MarshalByRefObject

IsEqual

Compares the LOB data referenced by the two OracleBlobs

Read

Reads a specified amount of bytes from the ODP.NET LOB Type instance and populates the buffer

ReadByte

Inherited from Stream

Search

Searches for a binary pattern in the current instance of an OracleBlob

Seek

Sets the position in the current LOB stream

SetLength

Trims or truncates the BLOB value to the specified length

ToString

Inherited from Object

Write

Writes the supplied buffer into the OracleBlob

WriteByte

Inherited from Stream

See Also:

Append

Append appends the supplied data to the end of the current OracleBlob instance.

Overload List:

Append(OracleBlob)

This instance method appends the BLOB data referenced by the provided OracleBlob object to the current OracleBlob instance.

Declaration
// C#
public void Append(OracleBlob obj);
Parameters
Exceptions

ObjectDisposedException - The object is already disposed.

InvalidOperationException - The parameter has a different connection than the object, OracleConnection is not opened, or OracleConnection has been reopened.

Remarks

No character set conversions are made.

The provided object and the current instance must be using the same connection; that is, the same OracleConnection object.

Append(byte[ ], int, int)

This instance method appends data from the supplied byte array buffer to the end of the current OracleBlob instance.

Declaration
// C#
public void Append(byte[] buffer, int offset, int count);
Parameters
Exceptions

ObjectDisposedException - The object is already disposed.

InvalidOperationException - The OracleConnection is not open or has been closed during the lifetime of the object.

Example
// C#
...
// Append 2 bytes {4,5} to the oraBlob
oraBlob.Append(new byte[3] {4,5,6}, 1, 2);
...

See Also:

BeginChunkWrite

This instance method opens the BLOB.

Declaration
// C#
public void BeginChunkWrite();
Exceptions

ObjectDisposedException - The object is already disposed.

InvalidOperationException - The OracleConnection is not open or has been closed during the lifetime of the object.

Remarks

BeginChunkWrite does not need to be called before manipulating the BLOB data. This is provided for performance reasons.

After this method is called, write operations do not cause the domain or function-based index on the column to be updated. Index updates occur only once after EndChunkWrite is called.

Clone

This instance method creates a copy of an OracleBlob object.

Declaration
// C#
public object Clone();
Return Value

An OracleBlob object.

Implements

ICloneable

Exceptions

ObjectDisposedException - The object is already disposed.

InvalidOperationException - The OracleConnection is not open or has been closed during the lifetime of the object.

Remarks

The cloned object has the same property values as that of the object being cloned.

Example
// C#
...
//Need a proper casting for the return value when cloned
OracleBlob oraBlob_cloned = (OracleBlob) oraBlob.Clone();
...

See Also:

Close

Overrides Stream

This instance method closes the current stream and releases any resources associated with it.

Declaration
// C#
public override void Close();

See Also:

Compare

This instance method compares data referenced by the current instance and that of the supplied object.

Declaration
// C#
public int Compare(Int64 src_offset, OracleBlob obj, Int64 dst_offset,
 Int64 amount);
Parameters
Return Value

Returns a value that is:

Exceptions

ObjectDisposedException - The object is already disposed.

InvalidOperationException - The parameter has a different connection than the object, OracleConnection is not opened, or OracleConnection has been reopened.

ArgumentOutOfRangeException - The src_offset, the dst_offset, or the amount parameter is less than 0.

Remarks

The provided object and the current instance must be using the same connection, that is, the same OracleConnection object.

CopyTo

CopyTo copies data from the current instance to the provided OracleBlob object.

Overload List:

CopyTo(OracleBlob)

This instance method copies data from the current instance to the provided OracleBlob object.

Declaration
// C#
public Int64 CopyTo(OracleBlob obj);
Parameters
Return Value

The return value is the amount copied.

Exceptions

ObjectDisposedException - The object is already disposed.

InvalidOperationException - This exception is thrown if any of the following conditions exist:

Remarks

The provided object and the current instance must be using the same connection; that is, the same OracleConnection object.

CopyTo(OracleBlob, Int64)

This instance method copies data from the current OracleBlob instance to the provided OracleBlob object with the specified destination offset.

Declaration
// C#
public Int64 CopyTo(OracleBlob obj, Int64 dst_offset);
Parameters
Return Value

The return value is the amount copied.

Exceptions

ObjectDisposedException - The object is already disposed.

ArgumentOutOfRangeException - The dst_offset is less than 0.

InvalidOperationException - This exception is thrown if any of the following conditions exist:

Remarks

If the dst_offset is beyond the end of the OracleBlob data, spaces are written into the OracleBlob until the dst_offset is met.

The offsets are 0-based. No character conversion is performed by this operation.

The provided object and the current instance must be using the same connection; that is, the same OracleConnection object.

CopyTo(Int64, OracleBlob, Int64, Int64)

This instance method copies data from the current OracleBlob instance to the provided OracleBlob object with the specified source offset, destination offset, and character amounts.

Declaration
// C#
public Int64 CopyTo(Int64 src_offset,OracleBlob obj,Int64 dst_offset,Int64 
amount);
Parameters
Return Value

The return value is the amount copied.

Exceptions

ObjectDisposedException - The object is already disposed.

InvalidOperationException - The parameter has a different connection than the object, OracleConnection is not opened, or OracleConnection has been reopened.

ArgumentOutOfRangeException - The src_offset, the dst_offset, or the amount parameter is less than 0.

Remarks

If the dst_offset is beyond the end of the OracleBlob data, spaces are written into the OracleBlob until the dst_offset is met.

The offsets are 0-based. No character conversion is performed by this operation.

The provided object and the current instance must be using the same connection; that is, the same OracleConnection object.

Example
// C#
...
// Assume you have 2 valid blobs
OracleBlob src_blob = new OracleBlob(con);
OracleBlob target_blob = new OracleBlob(con);

// Copy 1024 bytes from src_blob (begin at offset 10) to target_blob
// (starting at offset 5)
src_blob.CopyTo(10, target_blob, 5, 1024);
...

See Also:

Dispose

This instance method releases resources allocated by this object.

Declaration
// C#
public void Dispose();
Implements

IDisposable

Remarks

Once Dispose() is called, the object of OracleBlob is in an uninitialized state.

Although some properties can still be accessed, their values may not be accountable. Since resources are freed, method calls may lead to exceptions. The object cannot be reused after being disposed.

EndChunkWrite

This instance method closes the BLOB referenced by the current OracleBlob instance.

Declaration
// C#
public void EndChunkWrite();
Exceptions

ObjectDisposedException - The object is already disposed.

InvalidOperationException - The OracleConnection is not open or has been closed during the lifetime of the object.

Remarks

Index updates occur immediately if there is write operation(s) deferred by the BeginChunkWrite method.

Erase

Erase erases a portion or all data.

Overload List:

Erase()

This instance method erases all data.

Declaration
// C#
public Int64 Erase();
Return Value

The number of bytes erased.

Remarks

Erase() replaces all data with zero-byte fillers.

Erase(Int64, Int64)

This instance method erases a specified portion of data.

Declaration
// C#
public Int64 Erase(Int64 offset, Int64 amount);
Parameters
Return Value

The number of bytes erased.

Exceptions

ObjectDisposedException - The object is already disposed.

InvalidOperationException - The OracleConnection is not open or has been closed during the lifetime of the object.

ArgumentOutOfRangeException - The offset or amount parameter is less than 0.

Remarks

Replaces the specified amount of data with zero-byte fillers.

IsEqual

This instance method compares the LOB data referenced by the two OracleBlobs.

Declaration
// C#
public bool IsEqual(OracleBlob obj);
Parameters
Return Value

If the current OracleBlob and the provided OracleBlob refer to the same LOB, returns true. Returns false otherwise.

Exceptions

ObjectDisposedException - The object is already disposed.

InvalidOperationException - The OracleConnection is not open or has been closed during the lifetime of the object.

Remarks

Note that this method can return true even if the two OracleBlob objects return false for == or Equals() because two different OracleBlob instances can refer to the same LOB.

The provided object and the current instance must be using the same connection, that is, the same OracleConnection object.

Read

Overrides Stream

This instance method reads a specified amount of bytes from the ODP.NET LOB instance and populates the buffer.

Declaration
// C#
public override int Read(byte[ ] buffer, int offset, int count);
Parameters
Return Value

The return value indicates the number of bytes read from the LOB.

Exceptions

ObjectDisposedException - The object is already disposed.

InvalidOperationException - The OracleConnection is not open or has been closed during the lifetime of the object.

ArgumentOutOfRangeException - This exception is thrown if any of the following conditions exist:

Remarks

The LOB data is read starting from the position specified by the Position property.

Example
// C#
...
byte buffer         = new byte[1024];
int  bufferOffset   = 10;
int  amountToBeRead = 10;
// Read some data
...
int byteRead = oraBlob.Read(buffer, bufferOffset, amountToBeRead);
...

See Also:

Search

This instance method searches for a binary pattern in the current instance of an OracleBlob.

Declaration
// C#
public Int64 Search(byte[] val, int64 offset, int64 nth);
Parameters
Return Value

Returns the absolute offset of the start of the matched pattern (in bytes) for the nth occurrence of the match. Otherwise, 0 is returned.

Exceptions

ObjectDisposedException - The object is already disposed.

InvalidOperationException - The OracleConnection is not open or has been closed during the lifetime of the object.

ArgumentOutOfRangeException - This exception is thrown if any of the following conditions exist:

Remarks

The limit of the search pattern is 16383 bytes.

Example
// C#
...
// Search for the 2nd occurrence of a byte pattern '123'
// from the oraBlob starting at offset 1
byte[] pattern = new byte[3] { 1,2,3 };
int positionFound = oraBlob.Search(pattern, 1, 2);
...

See Also:

Seek

Overrides Stream

This instance method sets the position on the current LOB stream.

Declaration
// C#
public override Int64(Int64 offset, SeekOrigin origin);
Parameters
Return Value

Returns Int64 for the position.

Exceptions

ObjectDisposedException - The object is already disposed.

InvalidOperationException - The OracleConnection is not open or has been closed during the lifetime of the object.

Remarks

If offset is negative, the new position precedes the position specified by origin by the number of bytes specified by offset.

If offset is zero, the new position is the position specified by origin.

If offset is positive, the new position follows the position specified by origin by the number of bytes specified by offset.

SeekOrigin.Begin specifies the beginning of a stream.

SeekOrigin.Current specifies the current position within a stream.

SeekOrigin.End specifies the end of a stream.

SetLength

Overrides Stream

This instance method trims or truncates the BLOB value to the specified length (in bytes).

Declaration
// C#
public override void SetLength(Int64 newlen);
Parameters
Exceptions

ObjectDisposedException - The object is already disposed.

InvalidOperationException - The OracleConnection is not open or has been closed during the lifetime of the object.

ArgumentOutOfRangeException - The newlen parameter is less than 0.

Write

Overrides Stream

This instance method writes the supplied buffer into the OracleBlob.

Declaration
// C#
public override void Write(byte[ ] buffer, int offset, int count);
Parameters
Exceptions

ObjectDisposedException - The object is already disposed.

InvalidOperationException - The OracleConnection is not open or has been closed during the lifetime of the object.

ArgumentOutOfRangeException - This exception is thrown if any of the following conditions exist:

Remarks

Destination offset in the OracleBlob can be specified by the Position property.

Example
// C#
...
// Begin ChunkWrite to improve performance
// Index updates occur only once after EndChunkWrite
oraBlob.BeginChunkWrite();

// Set the write from the beginning;
oraBlob.Position = 0;

// Write to the oraBlob in chunks of 10, each 1024 bytes
for ( int i=0; i<10; i++ )
{
  byte[1024] b;
  b = b[0];    // some new value to be written
  oraBlob.Write(b, 0, b.Length);
}

oraBlob.EndChunkWrite();
...

See Also:


Go to previous page Go to beginning of chapter Go to next page
Oracle
Copyright © 2002 Oracle Corporation.

All Rights Reserved.
Go To Table Of Contents
Contents
Go To Index
Index