MySQL Getting Started series: Client program 5-mysql Interactive Query Program

Source: Internet
Author: User
Tags mysql mysql client query client

6.7 Client program 5-Interactive Query program

Let's sort through the many things we've studied so far and write a simple interactive client program. Its functionality includes the ability to enter queries, execute queries with a generic target query handler process_query, and display the query results Process_result_set () with the previously studied display format.

Client program 5 is similar in some respects to MySQL, although it differs in several features. The client program 5 has several constraints on the input:

Each input line must include a complete query.

The query will not terminate with a semicolon or ' G '.

Do not recognize commands like quit, but end the program with control-d. The writing of client program 5 is almost entirely trivial (less than 10 lines of new code). The client program framework (CLIENT4.C) and other written code provide almost everything that is required, and the only thing we want to add is to collect input rows and execute their loops. To build client program 5, first copy the client program framework client4.c into CLIENT5.C, and then add the code to process _ query (), Process_result_set (), and print_dashes (). Finally, in the main () of client5.c, look for lines marked with the following characters:

* Do "real work" here * *

Then replace it with the following loop:

  

Compile client5.c to generate client 5. O, connect client5.c to COMMON.O and client libraries, generating client program 5, which is all done. You have an interactive MySQL client program that can perform arbitrary queries and display results.

   See the full set of "MySQL Starter series tutorials" >>>>>

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.