25.01.2015 Views

Using Caché Objects - InterSystems Documentation

Using Caché Objects - InterSystems Documentation

Using Caché Objects - InterSystems Documentation

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Streams<br />

Stream data may be stored in either an external file or a <strong>Caché</strong> global, depending on how the<br />

stream property is defined. The %FileCharacterStream and %FileBinaryStream classes are<br />

used for streams stored as external files, while %GlobalCharacterStream and<br />

%GlobalBinaryStream are used for streams stored as globals. All four classes can use the<br />

optional LOCATION parameter to specify a default storage location.<br />

In the following example, the JournalEntry class contains four stream properties (one for each<br />

of the four basic stream classes), and specifies a default storage location for two of them:<br />

Class testPkg.JournalEntry Extends %Persistent<br />

{<br />

Property DailyText As %FileCharacterStream;<br />

Property DailyImage As %FileBinaryStream(LOCATION = "C:/Images");<br />

Property Text As %GlobalCharacterStream(LOCATION = "^MyText");<br />

Property Picture As %GlobalBinaryStream;<br />

}<br />

In this example, data for DailyImage will be stored in a file (with an automatically generated<br />

name) in the C:/Images directory, while the data for the Text property will be stored in a global<br />

named ^MyText.<br />

15.1.1 Projecting Streams to ODBC<br />

Streams are projected to ODBC as BLOBs. Their ODBC type is LONG VARCHAR (or<br />

LONG VARBINARY). The ODBC driver/server uses a special protocol to read/write BLOBs.<br />

Typically you have to write BLOB applications by hand, since the standard reporting tools<br />

do not support them.<br />

15.2 <strong>Using</strong> the Stream Interface<br />

All streams inherit a set of methods and properties used to manipulate the data they contain.<br />

Some commonly used methods include the following:<br />

• Read — Read a specified number of characters starting at the current position in the<br />

stream.<br />

• Write — Append data to the stream, starting at the current position. Overwrites existing<br />

data if the position is not set to the end of the stream.<br />

• Rewind — Move to the beginning of the stream.<br />

• MoveTo — Move to a given position in the stream.<br />

• MoveToEnd — Move to the end of the stream.<br />

134 <strong>Using</strong> <strong>Caché</strong> <strong>Objects</strong>

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!