Authentication Protocol Security - OK Packet
(Page 5 of 7 )
An OK packet is sent to indicate that the server successfully completed the command. It is sent in response to the following commands:
COM_PING
COM_QUERY if the query does not need to return a result set; for example, INSERT , UPDATE , or ALTER TABLE
COM_REFRESH
This type of packet is appropriate for commands that do not return a result set. Its format, however, permits sending some extra status information, such as the number of modified records, the value of the automatically generated primary key, or a custom status message in a string format. The structure of the packet body is documented in Table 4-8 .
Table 4-8. Format of server’s OK packet
Offset in the body | Length | Description |
0 | 1 | A byte with the value of 0, indicating that the packet has no fields. |
1 | rows_len | The number of records that the query has changed in the field length format described in the "Data Field" section, earlier in this chapter. Its length varies depending on the value. I will refer to its length as rows_lento express the subsequent offsets. |
Table 4-8. Format of server’s OK packet (continued)
Offset in the body | Length | Description |
1 + rows_len | id_len | The value of the generated auto-increment ID for the primary key. Set to 0 if not applicable in the context. The value is stored in the field length format of a data field. I will refer to the length of this value as id_len. |
1 + rows_len + id_len | 2 | Server status bit mask, low byte first. For details on different values, see the macros starting with STATUS_in include/mysql_com.h. In the protocol of version 4.0 and earlier, the status field is present only if it is a nonzero value. In the protocol of version 4.1 and later, it is reported unconditionally. |
3 + rows_len + id_len | 2 | Present only in the protocol of version 4.1 and later. Contains the number of warnings the last command has generated. For example, if the command was COM_QUERY with LOAD DATA INFILE, and some of the fields or lines could not be properly imported, a number of warnings will be generated. The number is stored with the low byte first. |
5 + rows_len + id_lenin version 4.1 and later protocol., 1 +rows_len + id_lenor 3 +rows_len + id_lenin the older protocol, depending on whether the server status bit mask was included. | msg_len | An optional field for the status message if one is present in the standard data field format with the field length followed by field value, which in this case is a character string. |
To send an OK packet from inside the server, you must call send_ok() . In version 4.1 and later, the function is declared in sql/protocol.h, and defined in sql/protocol.cc. In the earlier versions, it is declared in sql/mysql_priv.h and defined in sql/net_pkg.cc.
Next: Error Packet >>
More Database Articles Articles
More By O'Reilly Media
|
This article is excerpted from the book Understanding MySQL Internals, written by Sasha Pachev (O'Reilly, 2007; ISBN: 0596009577). Check it out today at your favorite bookstore. Buy this book now.
|
|