My Project
Functions
protocol.cc File Reference
#include "sql_priv.h"
#include "unireg.h"
#include "protocol.h"
#include "sql_class.h"
#include <stdarg.h>

Functions

bool net_send_error_packet (THD *, uint, const char *, const char *)
bool net_send_ok (THD *, uint, uint, ulonglong, ulonglong, const char *)
bool net_send_eof (THD *thd, uint server_status, uint statement_warn_count)
bool net_send_error (THD *thd, uint sql_errno, const char *err, const char *sqlstate)
uchar * net_store_data (uchar *to, const uchar *from, size_t length)
uchar * net_store_data (uchar *to, int32 from)
uchar * net_store_data (uchar *to, longlong from)

Detailed Description

Low level functions for storing data to be send to the MySQL client. The actual communction is handled by the net_xxx functions in net_serv.cc


Function Documentation

bool net_send_eof ( THD *  thd,
uint  server_status,
uint  statement_warn_count 
)

Send eof (= end of result set) to the client.

The eof packet has the following structure:

  • 254 : Marker (1 byte)
  • warning_count : Stored in 2 bytes; New in 4.1 protocol
  • status_flag : Stored in 2 bytes; For flags like SERVER_MORE_RESULTS_EXISTS.

Note that the warning count will not be sent if 'no_flush' is set as we don't want to report the warning count until all data is sent to the client.

Parameters:
thdThread handler
server_statusThe server status
statement_warn_countTotal number of warnings
Returns:
Return values:
FALSEThe message was successfully sent
TRUEAn error occurred and the message wasn't sent properly
bool net_send_error ( THD *  thd,
uint  sql_errno,
const char *  err,
const char *  sqlstate 
)

Send a error string to client.

Design note:

net_printf_error and net_send_error are low-level functions that shall be used only when a new connection is being established or at server startup.

For SIGNAL/RESIGNAL and GET DIAGNOSTICS functionality it's critical that every error that can be intercepted is issued in one place only, my_message_sql.

Parameters:
thdThread handler
sql_errnoThe error code to send
errA pointer to the error message
Returns:
Return values:
FALSEThe message was sent to the client
TRUEAn error occurred and the message wasn't sent properly
bool net_send_error_packet ( THD *  thd,
uint  sql_errno,
const char *  err,
const char *  sqlstate 
)
Parameters:
thdThread handler
sql_errnoThe error code to send
errA pointer to the error message
Returns:
Return values:
FALSEThe message was successfully sent
TRUEAn error occurred and the messages wasn't sent properly
bool net_send_ok ( THD *  thd,
uint  server_status,
uint  statement_warn_count,
ulonglong  affected_rows,
ulonglong  id,
const char *  message 
)

Return ok to the client.

The ok packet has the following structure:

  • 0 : Marker (1 byte)
  • affected_rows : Stored in 1-9 bytes
  • id : Stored in 1-9 bytes
  • server_status : Copy of thd->server_status; Can be used by client to check if we are inside an transaction. New in 4.0 protocol
  • warning_count : Stored in 2 bytes; New in 4.1 protocol
  • message : Stored as packed length (1-9 bytes) + message. Is not stored if no message.
Parameters:
thdThread handler
server_statusThe server status
statement_warn_countTotal number of warnings
affected_rowsNumber of rows changed by statement
idAuto_increment id for first row (if used)
messageMessage to send to the client (Used by mysql_status)
Returns:
Return values:
FALSEThe message was successfully sent
TRUEAn error occurred and the messages wasn't sent properly
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines