MySQL  8.0.26
Source Code Documentation
COM_QUERY

Send a Text Protocol based SQL query

Execution starts immediately.

If the client and server support it, the values for the named parameters of the query are sent (if any) in Binary Protocol Value form. The type of each parameter is made up of two bytes (except for the parameter name):

  • the type as in enum_field_types
  • a flag byte which has the highest bit set if the type is unsigned [80]
Returns
Payload
TypeNameDescription
int<1> command 0x03: COM_QUERY
if CLIENT_QUERY_ATTRIBUTES is set {
int<lenenc> parameter_count Number of parameters
int<lenenc> parameter_set_count Number of parameter sets. Currently always 1
if parameter_count > 0 {
binary<var> null_bitmap NULL bitmap, length= (num_params + 7) / 8
int<1> new_params_bind_flag Always 1. Malformed packet error if not 1
if new_params_bind_flag, for each parameter {
int<2> param_type_and_flag Parameter type (2 bytes). The MSB is reserved for unsigned flag
string<lenenc> parameter name String
}
binary<var> parameter_values value of each parameter: Binary Protocol Value
}
}
string<EOF> query the text of the SQL query to execute
Example
21 00 00 00 03 01 01 00 01 fe 00 01 61 01 31 73 !....... ....a.1s
65 6c 65 63 74 20 40 40 76 65 72 73 69 6f 6e 5f elect @@version_c
63 6f 6d 6d 65 6e 74 20 6c 69 6d 69 74 20 31 omment limit 1

null_bitmap is like the NULL-bitmap for the Binary Protocol Resultset Row just that it has a bit_offset of 0.

See also
Protocol_classic::parse_packet, dispatch_command, dispatch_sql_command, alloc_query, THD::set_query