Icon Using Streams with Tables, Views and Query Result Sets

Loading and saving tables, views, and query result sets to and from streams is accomplished through the LoadFromStream and SaveToStream methods of the TEDBTable, TEDBQuery, TEDBScript, and TEDBStoredProc components. A stream is any TStream-descendant object such as TFileStream, TMemoryStream, or even the ElevateDB TEDBBlobStream object used for reading and writing to BLOB columns. Loading a stream copies the entire contents of a stream to an existing table, view, or query result set. When loading a stream, the contents of the stream must have been created using the SaveToStream method or else an EEDBError exception will be raised. The error code given when a load from a stream fails because of an invalid stream is 1003 (EDB_ERROR_STREAM). Saving to a stream copies the contents of a table, view, or query result set to the stream, overwriting the entire contents of the stream. The rows that are copied can be controlled by setting a range or filter on the source table or query result set prior to calling the SaveToStream method. Please see the Setting Ranges on Tables and Setting Filters on Tables and Query Result Sets topics for more information.

Loading Data from a Stream
To load data from a stream into an existing table, view, or query result set, you must open the TEDBTable, TEDBQuery, or TEDBStoredProc component and then call the LoadFromStream method.

The following example shows how to load data from a memory stream (assumed to already be created) into a table using the LoadFromStream method:

begin
   with MyTable do
      begin
      DatabaseName:='SalesDB';
      TableName:='customer';
      Open;
      LoadFromStream(MyMemoryStream);
      end;
end;

Information Tables, views, or query result sets in remote sessions can load data from a local (client-side) stream. However, since the stream contents are sent as one buffer to the ElevateDB Server as part of the load request, it is recommended that you do not load particularly large streams since you will run the risk of exceeding the available memory on the local workstation or ElevateDB Server.

Saving Data to a Stream
To save the data from a table, view, or query result set to a stream, you must open the TEDBTable, TEDBQuery, or TEDBStoredProc component and then call the SaveToStream method.

The following example shows how to save the data from a table to a memory stream (assumed to already be created) using the SaveToStream method of the TEDBTable component:

begin
   with MyTable do
      begin
      DatabaseName:='SalesDB';
      TableName:='customer';
      Open;
      SaveToStream(MyMemoryStream);
      end;
end;

Information When the SaveToStream method is called, the existing position of the stream pointer in the destination stream is not moved, and the size of the destination stream is not changed except in the case where the size must be expanded to accomodate the new stream data being saved from the table, view, or query result set. Therefore, if you wish to overwrite any existing data in the destination stream during the SaveToStream method call, you should use the following code on the stream before calling the SaveToStream method:

begin
   with MyStream do
      begin
      Size:=0;
      Position:=0;
      end;
end;

The reason for this behavior is that it allows the developer the possibility of combining multiple streams from multiple tables, views, or query result sets into one stream.
Image