Monday, April 27, 2009

Requesting data from an application server

The following table lists the properties and methods of TClientDataSet that determine how data is fetched from an application server in a multi-tiered application:
FetchOnDemand property
Determines whether or not a client dataset automatically fetches data as needed, or relies on the application to call the client dataset’s GetNextPacket, FetchBlobs, and FetchDetails functions to retrieve additional data.

PacketRecords property
Specifies the type or number of records to return in each data packet.

GetNextPacket method
Fetches the next data packet from the application server.

FetchBlobs method
Fetches any BLOB fields for the current record when the application server does not include BLOB data automatically.

FetchDetails method
Fetches nested detail datasets for the current record when the application server does not include these in data packets automatically.
By default, a client dataset retrieves all records from the application server. You can control how data is retrieved using PacketRecords and FetchOnDemand.
PacketRecords specifies either how many records to fetch at a time, or the type of records to return. By default, PacketRecords is set to -1, which means that all available records are fetched at once, either when the application is first opened, or the application explicitly calls GetNextPacket. When PacketRecords is -1, then after it first fetches data, a client dataset never needs to fetch more data because it already has all available records.

To fetch records in small batches, set PacketRecords to the number of records to fetch. For example, the following statement sets the size of each data packet to ten records:

ClientDataSet1->PacketRecords = 10;

This process of fetching records in batches is called “incremental fetching”. Client datasets use incremental fetching when PacketRecords is greater than zero. By default, the client dataset calls GetNextPacket to fetch data as needed. Newly fetched packets are appended to the end of the data already in the client dataset.
GetNextPacket returns the number of records it fetches. If the return value is the same as PacketRecords, the end of available records was not encountered. If the return value is greater than 0 but less than PacketRecords, the last record was reached during the fetch operation. If GetNextPacket returns 0, then there are no more records to fetch.

Note:Incremental fetching only works if the remote data module preserves state information. That is, you must not be using MTS, and the remote data module must be configured so that each client application has its own data module instance.
You can also use PacketRecords to fetch metadata information about a database from the application server. To retrieve metadata information, set PacketRecords to 0.
Automatic fetching of records is controlled by the FetchOnDemand property. When FetchOnDemand is true (the default), automatic fetching is enabled. To prevent automatic fetching of records as needed, set FetchOnDemand to false. When FetchOnDemand is false, the application must explicitly call GetNextPacket to fetch records.

Applications that need to represent extremely large read-only datasets can turn off FetchOnDemand to ensure that the client datasets do not try to load more data than can fit into memory. Between fetches, the client dataset frees its cache using the EmptyDataSet method. This approach, however, does not work well when the client must post updates to the application server.

1 comment: