MySQL database technology (36) [Photo] 6.8 Other topics
This section contains several topics that are not fully applicable to any section in the development of this chapter from client1 to client5:
■ Use the result set metadata to help verify that the data is suitable for calculation.
■ It is difficult to insert data into the query.
■ How to process graphic data.
■ How to obtain table structure information.
■ Common MySQL program design errors and how to avoid them.
6.8.1 perform computation on the result set
So far, we have concentrated and mainly used the result set meta data to print row data, but it is obvious that in addition to printing, there is also a need to use data to do other things. For example, calculate the statistical information based on data values and apply metadata to ensure that the data meets their needs. What type of requirements? For the startup program, it may be necessary to check whether the column that is about to execute the numerical calculation actually contains numbers!
The following list shows a simple function summary _ stats (), which obtains the result set and column index and generates summary statistics of column values. This function also lists the number of missing values, which are detected by checking NULL. These computations include the requirements that must be met by two data items. summary_stats () uses the result set metadata for verification:
■ The specified column must exist (that is, the column index must be within the range of the result set column value ).
■ This column must contain numeric values.
If these conditions are not met, summary_stats () only prints the error message and returns it. The code is as follows: