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" >>>>>