CustomerServer Remote Data Transfer Processing Skills

xiaoxiao2021-03-06  20

---- In the actual MIS system, remote database access is mostly through the MODEM connection, for communication costs and speed considerations, often saved the data in the local, and then centrally transferred to the remote approach. Remote data transfer can have multiple programs, the most common is to package the data to be transmitted into a file, transferred to the destination in the form of file transfer, and add it to the local database after the destination is restored. This approach is generally applied to the securities trading system, which has the advantage of being fast and can save data compression, greater limitations in advance. However, this solution also has its shortcomings: Due to the use of document transport mechanism, the characteristics of the database itself such as integrity constraints, data consistency, rollback mechanism, etc., therefore less adopted in a more complex database system. Another method is to directly process the two ends into a "client / server" mode, and the data transmission is regarded as submitting data to the Server. Since this solution makes full use of the characteristics of the database server, and the actual operation is basically consistent with the local area network, this document will be described in detail. In addition, some of this content is based on Delphi / CBuilder. ---- Due to the transmission speed, it is absolutely disapproved to the server when transmitting a large amount of data, and it should be submitted to the Server, and a TBATCHMOVE control is provided in Delphi / CBuilder for mass transfer data. Using it can greatly reduce the network burden and improve the transmission speed. Unfortunately, the TBATCHMOVE control only provides a simple error control function, no important functions such as display transmission progress, user termination transfer. However, the BDE depends on TBATCHMOVE provides a "callback mechanism" to complete the above two functions. The so-called "callback" process is this: When the BDE performs some operation,, for example, copying a large amount of data from one table, every time (if you need to display copy progress), BDE will call A function (callback function) you write, to help you control the program more complete. This approach is a bit for Event (event) and event handler function in DLPHI - a specific operation action will let VCL trigger an event, thereby calling a section of the event handler, different events trigger different Processing function. ---- In order to make BDE work together correctly with your function, you must "register" your function in advance, let BDE know (callback) your code when a event occurs. BDE provides a DBiregisterCallback registration function. Unfortunately, the instructions in BDE online help cannot be suitable for Delphi / CBuilder, follow the programs written in this instructions Can't compile! The author found the method of using the BDE callback function by practicing, the use of this mechanism will be described in detail below. The BDE callback mechanism contains the following steps: ---- 1) Write your callback function in a schedule format in BDE ---- 2) call the dbiregisterCallback function to register your callback function, so when you perform related database operations Trigger your callback function. ---- 3) Perform related database operations, such as BatchMove1-> EXECTUE (); ---- 4) Logout the callback function ---- The most critical is to register your callback function correctly, so first introduce the second step.

(Registration and logout call the same function, only the last parameter is slightly different) ---- First you should know which "event" calls your callback function when you call you, second you should understand the parameters related to the event and Data Structure - All occurs when calling the DBiregisterCallback function to register, so let's introduce the correct usage of DbireGisterCallback and instructions: ---- In the original BDE help (c) This function is like this DBIRESULT DBIFN DBIREGISTERCALLBACK (hcursor, ECBTYPE, ICLIENTDATA, ICBBBBUFLEN, PCBBUF, PFCB); ---- To use this function must include header file, the problem is that Delphi / CBuilder does not provide this file at all, replaced by "BDE.HPP", but in the included After the file, the program still cannot be compiled because there is no description of DBIFN or the like in this file. A simple method is to remove DBIFN in the code. Interpretation of each parameter is as follows: Hcursor is a handle of an object in a BDE. If this parameter is null, the registered callback function is suitable for all BDE tasks; the second parameter ECBTYPE means the category of the trigger condition of the callback function, there is Many types can be selected, where CBgenProgress means triggering this callback function when you need to display a long operation; the third parameter iClientData is a pointer to a data structure that passes to the callback function, null in our example; Four parameters ICBBUFLEN refer to the size of the buffer, which varies with the second parameter, such as SIZEOF (CBProgressDesc); the fifth parameter PCBBUF is a pointer to the buffer, which changes the second parameter, For example, the data structure of CBGENProgress is CBProgressDesc; the last parameter is an address pointer of the callback function, indicating the callback function of the type when the parameter is NULL. About the callback function will be described in detail later. The following is the format of the callback function that displays the progress when the execution is registered: int RST = DBIREGISTERCALLBACK (null, // is suitable for any process CBGROGRESS, // Tune type: Display long operating progress null, // No data SIZEOF (CBProgressDesc) , // data structure size & acbbuf, // data memory address ApicallbackFun // callback function's address); ---- Next, complete the first step: Write a callback function ---- in C, callback function The following statement should be declared: CBRTYPE__STDCALLLAPICALLBACKFUN (CBTYP EECBTYPE, // Tune Type IclientData, // Tune Data (Pointer) VOID * PCBINFO // Tune Data Structure Pointer) ---- The first parameter is a callback type; the second parameter is The callback data explained to the third parameter of DBIREGisterCallback; the third is a pointer to the callback data, and the structure of the data is different from the type of callback. For example, the progress indicating that the data structure of CBGENProgress is CBProgressDesc, which is defined as follows: struct cbprogressdesc {short iprogressdone; // Progress percentage CHAR SZMSG [128]; // Progress text information}; ---- Two domains of this structure There is only one role, the first representation of the progress of the operation, which means that the second domain is active when it is -1.

The second domain represents progress information with a string, its format is <: , such as: Recordscopied: 125 ---- This article is mainly completed in the callback function: ---- 1) Display data copy (BatchMove) progress ---- 2) Provide a mechanism for users to terminate for a long time - display copy progress The code is as follows: cbrtype __stdcall apicallbackfun (CBType Ecbtype, // Callback Type InetData, // Client Callback data void * pcbinfo // call back info / client) {ansistring str; if (ecbtype == cbgenprogress) {Int j = start ((cbProgressDesc *) PCBINFO) -> ipercentddone); if (j <0) // If IPercentDone is -1, the information of SZMSG is analyzed {str = ((cbProgressDesc *) PCBINFO) -> szmsg; int pos = str.ansipos (":") 1; // Extract the number of records // below Code is used to display copy progress and copy quantity in a form1-> label2-> caption = str.substring (pOS, 100); FORM1-> label2-> update (); form1-> progressbar1-> position = int ((Str.Substring (POS, 100). Todouble () / form1-> transnum) * 100); Form1-> Progressbar1-> Update ();} else {form1-> progressbar1-> position = j; form1-> ProgressBar1-> update ();} return-cbrContinue; // must return CBRCONTINUE to let BatchMove continue // If you return CBRabort, terminate the copy} ---- Everything is completed, whenever you call long BDE operation (such as BatchMove1-> EXECTUE ()) When the callback function is triggered, pay attention to "log out" callback function when not needed. ---- If the batch transfer data time is long, you must provide the user to provide the opportunity to terminate the operation, mention, if the callback function returns CBRABORT, the BatchMove process is terminated immediately. You can add a "stop" button and a global Boolean variable ISCONTINUE on the Form. When the copy is started, the variable is true. When the button is pressed, the variable is set to false, check the value of IsContinue each time the callback function is called. If the callback function returns CBRCONTINUE for True, let copies continue, otherwise returns CBRabort termination copy. However, the problem is that once the copy process begins, all messages in this process will be blocked, and the application does not have the opportunity to respond to all messages such as the keyboard, the mouse before the application, and even the screen refresh can not be completed, so it is necessary to find a way to avoid message blocking. .

转载请注明原文地址:https://www.9cbs.com/read-43779.html

New Post(0)