Using Basic Client Datasets in the ClientServer Environment

   

Using Basic Client Datasets in the Client/Server Environment

In the client/server environment, client datasets are used as a buffer for records transferred from the provider to client. Typically, you have a TQuery or other TDataSet descendant issuing SQL to the database server, which responds with the appropriate records. Associated with that TDataSet descendant is a TDataSource , linked to various data-aware controls, which, in turn , displays records in the client- user interface.

When using TClientDataSet the association is changed slightly. The TClientDataSet is associated with a TProvider component. The TProvider connects the TClientDataSet with the provider through the TDataSet descendant. The TDataSet descendant simply retrieves records normally, as requested by the client data set. But the TClientDataSet requests records much less frequently than would be the case otherwise .

Figure 9.2 shows a typical TDataModule containing such datasets, providers, client datasets, and data sources.

Figure 9.2. Typical client data set usage in a client/server data module.

graphics/09fig02.gif

Figure 9.3 shows the user interface for a sample program that uses two TDataModules ”one with a client data set and one with a normal data set.

Figure 9.3. User interface for a program using the client data set and normal data modules.

graphics/09fig03.gif

The program provides a user interface with a radio group from which you can select whether to see the datasets from the point of view of the TQuery itself, or from that of a TClientDataSet that uses TQuery through a provider.

Unfortunately, even TClientDataSet components cannot solve the problem of multiple applications modifying the same record. But, when you attempt to post from the TClientDataSet to the underlying dataset, the TClientDataSet sees differences and generates an OnReconcileError . Note that this type of error might not be detected when it occurs in a text blob.

Listing 9.1 shows a simple event handler to deal with a reconcile error. However, keep in mind that this does not cover the various possible causes with their appropriate responses, and that significant experimentation would be needed to properly manage these errors.

Listing 9.1 Event Handler for OnReconcileError
 void __fastcall TTestInterbaseClientDataSetWithCDS::ClientDataSetReconcileError(        TCustomClientDataSet *DataSet, EReconcileError *E,        TUpdateKind UpdateKind, TReconcileAction &Action)  {     ShowMessage(E->Context + " / " + String(E->ErrorCode) + ": " + E->Message);     Action = raCancel;  } 

   
Top


C++ Builder Developers Guide
C++Builder 5 Developers Guide
ISBN: 0672319721
EAN: 2147483647
Year: 2002
Pages: 253

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net