MySQL database technology (34) [group chart] _ MySQL

Source: Internet
Author: User
MySQL database technology (34) [group chart] 6.6 process queries

We already know how to start and end sessions with the server. now we should look at how to control sessions. This section describes how to communicate with the server to process queries. Each query executed should include the following steps:

1) construct a query. The query structure depends on the query content, especially whether binary data is included.

2) publish the query by sending the query to the server for execution.

3) process the query results. This depends on the release query type. For example, if the SELECT statement returns data rows for processing, the INSERT statement does not. One element of constructing a query is the function used to send the query to the server. The common publish query routine is mysql _ real _ query (). This routine provides a count string (string plus length) for the query ). You must understand the length of the query string and pass them together with the string itself to mysql_real_query (). Because a query is a counting string, its content may be anything, including binary data or null bytes. The query cannot be a null ending string. Another function that publishes a query, mysql _ query (), has more restrictions on the content allowed by the query string, but is easier to use. The query passed to mysql_query () should be a null ending string, which indicates that the query cannot contain null bytes (the query contains null bytes, which may lead to an error interruption, this is shorter than the actual query content ). Generally, if a query contains any binary data, it may contain null bytes. therefore, do not use mysql _ query (). On the other hand, when processing an empty ending string, it is very resource-consuming to construct a query using the familiar standard C library string function, such as strcpy () and sprintf ().

Another element of constructing a query is whether to execute the overflow character operation. This operation is required if binary data or other complex character values are used during query construction, such as quotation marks and backslash. These will be discussed in Section 6.8.2 "encoding data with doubts in queries.

The following is a simple outline for processing queries:

If mysql_query () and mysql_real_query () are queried successfully, a zero value is returned. if the query fails, a non-zero value is returned. If the query is successful, the server determines that the query is valid and accepted and can be executed, not the query result. For example, it is not the row selected by the SELECT query or the row deleted by the DELETE statement. Check whether the actual query result includes other processing items.

The query may fail due to multiple causes, including the following common causes:

■ Contains syntax errors.

■ The semantics is invalid-for example, queries involving columns that do not exist in the table.

■ Insufficient rights to access the referenced data.

Queries can be divided into two categories: queries that do not return results and queries that return results. INSERT, DELETE, UPDATE, and other statements belong to the "no results returned" type query. even if you modify the database query, they do not return any rows. The only information that can be returned is related to the number of affected rows. The SELECT statement and SHOW statement belong to the query of the "return result" class. the purpose of these statements is to return some information. The row set generated by the returned data query is called the result set, which is expressed as the MYSQL_RES data type in MySQL, this is a structure that contains the data values of rows and the metadata about these values (such as the length of column names and data values. Empty result sets (results that contain zero rows) must be separated from "no results.

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.