Client/server Remote Data transfer processing skills

Source: Internet
Author: User
Tags data structures one table advantage

In the actual MIS system, remote database access mostly through modem connection, for communication costs and speed considerations, often the first to save the data locally, and then centralized transmission to the remote way. Remote data transfer can have a variety of scenarios, the most common is the first data to be transmitted packaged into a file, in the form of file transfer to the destination, after the destination of data recovery to the local database. This method is widely used in the securities trading system, which has the advantage of fast speed, and can compress the data in advance, and save the transmission time and cost more greatly. But this kind of scheme also has its shortcoming: because of using the file transmission mechanism, the database itself cannot take advantage of the characteristics such as integrity constraints, data consistency, rollback mechanism, etc., so in the more complex database system is less used. Another approach is to process the two ends directly into "client/server" mode, and consider data transfer as submitting data to the server. As this scheme makes full use of the characteristics of the database server, and the actual operation is basically the same as the local area network mode, so this article will introduce this scheme in detail. In addition, some of the content of this article is based on Delphi/cbuilder.

Due to the transmission speed, when the transfer of large amounts of data is absolutely not in favor of record-by-document to the server to submit data, but should be submitted to server in batches, Delphi/cbuilder provides a tbatchmove control dedicated to bulk data transfer, use it can greatly reduce network burden, Increase the speed of transmission. Unfortunately, the Tbatchmove control only provides a simple error-control feature that does not provide significant functionality such as displaying the delivery progress, and terminating the delivery of the user. However, the Tbatchmove relies on BDE to provide a "callback mechanism" that accomplishes both of these functions. The so-called "callback" process is this: when BDE performs some operation, for example, in the process of copying a large amount of data from one table to another, every once in a while (for example, when you need to show the copy progress), BDE calls a function of your own (callback function) to help you control the program more completely. This is a bit of a Dlphi event (event) and incident handler--a specific action action that causes VCL to trigger an event to invoke an event handler that you write well, and different events trigger different handler functions.

In order for BDE to work properly with your function, you must "register" your function to let BDE know that a certain piece of code should be called (callback) when an event occurs. BDE provides a dbiregistercallback registration function, unfortunately, the instructions in BDE's online help are not suitable for delphi/cbuilder, and the program written according to the instructions cannot be compiled at all! The author has found the correct use of the BDE callback function method, the following will be described in detail the use of this mechanism. The BDE callback mechanism consists of the following steps:

1 Write your callback function according to BDE's predetermined format

2 Call the Dbiregistercallback function to register your callback function so that it naturally triggers your callback function when you perform the relevant database operation.

3 Perform relevant database operations, such as Batchmove1->exectue ();

4) Unregister the callback function

The key is to register your callback function correctly, so introduce the second step first. (Registration and logoff call the same function, except that the last parameter is slightly different)

First you should know what kind of "event" occurs when you call your callback function, and secondly you should understand the parameters and data structures associated with the event-all of this happens when you call the Dbiregistercallback function registration. So let me first introduce the correct usage and description of Dbiregistercallback:

In the original BDE help the prototype of the function (C) is this

Dbiresult DBIFN dbiregistercallback (hcursor, Ecbtype, Iclientdata, Icbbuflen, Pcbbuf, PFCB);

To use this function must include a header file, the problem is that the file is not provided at all in Delphi/cbuilder and replaced by "BDE." HPP, but the program still cannot be compiled after the file is included because there is no description of DBIFN in the file. An easy way to do this is to get rid of DBIFN in your code. The arguments in the function are interpreted as follows: Hcursor is a handle to an object in a BDE, and if this argument is null, the registered callback function is appropriate for all BDE tasks, and the second parameter Ecbtype refers to the class of trigger conditions for the callback function, and there are many types to choose from. Where cbgenprogress indicates that the callback function is triggered when the progress of a long operation needs to be displayed; The third parameter iclientdata is a pointer to a data structure passed to the callback function, in our case null The fourth parameter Icbbuflen refers to the size of the callback buffer, which differs from the second parameter, such as sizeof (CBPROGRESSDESC), and the fifth parameter pcbbuf is a pointer to the callback buffer, which changes with the second parameter. For example, the CBGENPROGRESS data structure is CBPROGRESSDESC; the last parameter is the address pointer to the callback function, which indicates that the callback function is logged off when the parameter is null. The callback function is described in more detail later. The following is the format of the callback function that displays progress during the Registrar operation:

int rst=  DbiRegisterCallBack (NULL,
//适合于任何进程
cbGENPROGRESS, //回调类型:显示长操作的进度
NULL, //没有数据
sizeof(CBPROGRESSDesc), //数据结构的大小
&aCBBuf, //数据的内存地址
ApiCallBackFun //回调函数的地址
);

Then you should complete the first step: Write a callback function

In C, the callback function should be declared as follows:

CBRType__stdcallApiCallBackFun(
CBTyp  eecbType,//回调类型
int iClientData,//回调数据(指针)
void *pCbInfo//回调数据结构指针
)

The first parameter is the callback type, the second parameter is the callback data, it interprets the third parameter of the same dbiregistercallback, and the third is a pointer to the callback data, whose structure differs from the type of callback. For example, the progress indicator Cbgenprogress's data structure is CBPROGRESSDESC, which is defined as follows:

struct CBPROGRESSDesc {
short iPercentDone; //进度的百分比
char szMsg[128]; //进度的文本信息
};

The two domains of the structure have only one function at the same time, the first represents the progress percent of the operation, and when it is-1, it indicates that the second field works. The second field represents the progress information in a string, in the form of <string><:><value>, for example: recordscopied:125

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.