Client Program 5-MYSQL interactive query program [figure] 6.7 client Program 5-Interactive query program
Let's sort out a lot of research so far and write a simple interactive client program. Its functions include entering the query, executing the query with the general target query handler process_query, and displaying the query result with the display format process_result_set () previously studied.
Client Program 5 is similar to mysql in some aspects, although it is still different in several features. Client Program 5 has several constraints on input:
■ Each input line must contain a complete query.
■ The query will not end with a semicolon or '/g.
■ Do not recognize commands similar to quit, but end the program with Control-D. Writing client Program 5 is almost trivial (less than 10 lines of new code ). The client program framework (client4.c) and other written code provide almost everything we need. The only thing we need to add is to collect input rows and execute them in a loop. To build client Program 5, first copy client program framework client4.c to client5.c, and then add the code to process _ query (), process_result_set (), and print_dashes, finally, find the lines marked with the following characters in main () of client5.c:
/* Do the 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 library, and generate client Program 5. this completes all. You have an interactive MySQL client program that can execute any query and display results.