Message interaction process between C language programs and databases in non-direct connection mode, and language program process

Source: Internet
Author: User

Message interaction process between C language programs and databases in non-direct connection mode, and language program process

Abstr]

In "how to execute SQL statements in C language?" (Http://www.zhouzhaoxiong.com/116.html) in the article, I introduced the direct connection mode under the C language program dealing with the database process.

This article briefly introduces the process of message interaction between C language programs and databases in non-direct connection mode for your reference.

 

1. Overall message interaction process

Non-direct connection mode, also called asynchronous mode. As the name suggests, in this way, C programs do not directly deal with databases, but communicate with databases through an independent third-party module. The overall process of message interaction 1 is shown.


Figure 1 overall message interaction process

This method has the following advantages:

First, the C program does not have to wait until the database returns the result, but can continue to execute the subsequent process, which improves the execution efficiency of the program to a certain extent.

Second, the C program only needs to send messages containing SQL statements to a third-party module, without the need to connect to the database and execute SQL statements in the database, this simplifies the operation process of the C program to a certain extent.

The disadvantages of this method are as follows:

First, the system architecture is complex. It is necessary to accurately configure the links between the C program and the third-party modules, and ensure the normality of the functions of the third-party modules.

Second, the C program must accurately define and parse the message serial number (session number). Otherwise, the results returned by the third-party module may be chaotic, which increases the complexity of the C program timing processing.

 

Ii. Message interaction process

The C program sends messages to a third-party module.


Figure 2 process for C program to send messages to a third-party module

From figure 2, we can see that:

First, the SQL statements sent by the C program to the third-party module must comply with the syntax rules. Otherwise, even if the message is successfully sent, no correct execution results will be returned.

Second, in order to correctly receive the messages returned by the third-party module, the C program must define the message event number (the third-party module will return the event number as is when returning the execution result ), at the same time, the session number should be allocated (the session number will be returned by the third-party module when the execution result is returned ). In this way, the parsing correctness of the messages returned by the third-party module can be ensured by the C program.

Third, when the function sending messages to a third-party module fails to execute, do not continue the subsequent process, and print detailed failure logs for viewing the problem.

Fourth, after the function sending messages to a third-party module is successfully executed, the C program can continue the subsequent process, but do not release the assigned session number.

 

The process for C program to receive messages returned by a third-party module is shown in step 3.


Figure 3 Process for C program to receive messages returned by a third-party module

From figure 3, we can see that:

First, the session number is the key to ensuring the processing sequence of the C program. In a program, session numbers are generally stored in the global session cache.

Second, the C program can process a message only when the session number sent to the third-party module is the same as the session number returned by the third-party module. After the execution result of the SQL statement is completed by the C program, the session number must be released.

Third, program C processes the corresponding process according to the event number. To ensure the correctness of the process, when sending messages to a third-party module, you must define clear and easy-to-distinguish event numbers.

 

Iii. Summary

In actual software development projects, it is common to deal with C language programs and databases. Is direct connection selected? Or select a non-direct connection method? This requires a reasonable selection based on the actual situation of the project and the installation of existing modules.

This article introduces the process of interaction between C language programs and databases in non-direct connection mode, which provides a useful reference for the smooth development of related software.

 

 

 

(My microblogging: http://weibo.com/zhouzxi? Topnav = 1 & wvr = 5, No.: 245924426, welcome !)

Related Article

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.