COM_QUERY
You are viewing an old version of this article. View
the current version here.
With the COM_QUERY command, the client sends the server an SQL statement to be executed immediately.
Fields
- int<1> 0x03 : COM_QUERY header
- string<EOF> SQL statement
SQL statement should be properly escaped. Escape character is usually backslash '\' = 0x5c.
However , if status flag returned by the last OK Packet had NO_BACKSLASH_ESCAPES bit set,
then the escape character is single quote(' = 0x60)
if escape character is backslash, the following characters are escaped:
- single quote (' = 0x60)
- back slash (\ = 0x5c)
- double quote (" = 0x22)
- null character (0x00)
If escape character is single quote, only single quote (' = 0x60) can be escaped.
Response
The server can answer with 4 different responses that can be differentiated by the first byte (packet header):
- 0xFF - ERR_Packet if any error occurs.
- 0x00 - OK_Packet when query execution works without resultset.
- 0xFB - LOCAL_INFILE Packet if query was "LOCAL INFILE ...".
- Or a Resultset, when query returns results (in case of SELECT query for example).
Example
1b 00 00 00 03 44 52 4f 50 20 54 41 42 4c 45 20 | .....DROP TABLE |
49 46 20 45 58 49 53 54 53 20 62 75 6c 6b 31 | IF EXISTS bulk1 |
Comments
Comments loading...
Content reproduced on this site is the property of its respective owners,
and this content is not reviewed in advance by MariaDB. The views, information and opinions
expressed by this content do not necessarily represent those of MariaDB or any other party.