All pages
Powered by GitBook
1 of 1

Loading...

COM_STMT_PREPARE

This command prepares an SQL statement on the server, returning a statement ID and metadata about parameters and columns.

Prepares a statement on the server.

Not all statements can be prepared. See PREPARE for a list of statements that can be prepared.

Implemented by

Fields

  • 0x16 COM_STMT_PREPARE header

  • SQL Statement

Example

Response

If anything goes wrong, the server will send an . If the command succeeds, different packets are received:

  • .

  • If number of parameters (count of '?' placeholders) > 0:

    • For each parameter:

COM_STMT_PREPARE_OK

  • 0x00 COM_STMT_PREPARE_OK header.

  • statement ID.

  • number of columns in the returned result set (or 0 if statement does not return result set).

This page is licensed: CC BY-SA / Gnu FDL

column definition packet.
  • If !DEPRECATE_EOF eof_packet.

  • If prepared statement returns result set and number of result set columns > 0:

    • For each column:

      • column definition packet.

    • If !DEPRECATE_EOF .

  • int<2> number of prepared statement parameters ('?' placeholders).
  • string<1> -not used-

  • int<2> number of warnings.

  • int<1>
    string
    ERR_Packet
    COM_STMT_PREPARE_OK
    int<1>
    int<4>
    int<2>
    1F 00 00 00 16 53 45 4C 45 43 54 20 2A 20 46 52  .....SELECT * FR
    1F 4D 20 74 65 73 74 5F 62 69 6E 64 5F 72 65 73  OM test_bind_res
    75 6C 74                                         ult
    eof_packet
    mariadb_stmt_execute_direct()
    mysql_stmt_prepare()