My Project
Public Types | Public Member Functions | Protected Member Functions | Protected Attributes
Protocol Class Reference
Inheritance diagram for Protocol:
Protocol_binary Protocol_local Protocol_text

List of all members.

Public Types

enum  { SEND_NUM_ROWS = 1, SEND_DEFAULTS = 2, SEND_EOF = 4 }
enum  enum_protocol_type { PROTOCOL_TEXT = 0, PROTOCOL_BINARY = 1, PROTOCOL_LOCAL = 2 }

Public Member Functions

 Protocol (THD *thd_arg)
void init (THD *thd_arg)
virtual bool send_result_set_metadata (List< Item > *list, uint flags)
bool send_result_set_row (List< Item > *row_items)
bool store (I_List< i_string > *str_list)
bool store (const char *from, const CHARSET_INFO *cs)
Stringstorage_packet ()
void free ()
virtual bool write ()
bool store (int from)
bool store (uint32 from)
bool store (longlong from)
bool store (ulonglong from)
bool store (String *str)
virtual bool prepare_for_send (uint num_columns)
virtual bool flush ()
virtual void end_partial_result_set (THD *thd)
virtual void prepare_for_resend ()=0
virtual bool store_null ()=0
virtual bool store_tiny (longlong from)=0
virtual bool store_short (longlong from)=0
virtual bool store_long (longlong from)=0
virtual bool store_longlong (longlong from, bool unsigned_flag)=0
virtual bool store_decimal (const my_decimal *)=0
virtual bool store (const char *from, size_t length, const CHARSET_INFO *cs)=0
virtual bool store (const char *from, size_t length, const CHARSET_INFO *fromcs, const CHARSET_INFO *tocs)=0
virtual bool store (float from, uint32 decimals, String *buffer)=0
virtual bool store (double from, uint32 decimals, String *buffer)=0
virtual bool store (MYSQL_TIME *time, uint precision)=0
virtual bool store_date (MYSQL_TIME *time)=0
virtual bool store_time (MYSQL_TIME *time, uint precision)=0
virtual bool store (Field *field)=0
virtual bool send_out_parameters (List< Item_param > *sp_params)=0
void remove_last_row ()
virtual enum enum_protocol_type type ()=0
void end_statement ()

Protected Member Functions

bool net_store_data (const uchar *from, size_t length)
bool net_store_data (const uchar *from, size_t length, const CHARSET_INFO *fromcs, const CHARSET_INFO *tocs)
bool store_string_aux (const char *from, size_t length, const CHARSET_INFO *fromcs, const CHARSET_INFO *tocs)
virtual bool send_ok (uint server_status, uint statement_warn_count, ulonglong affected_rows, ulonglong last_insert_id, const char *message)
virtual bool send_eof (uint server_status, uint statement_warn_count)
virtual bool send_error (uint sql_errno, const char *err_msg, const char *sql_state)

Protected Attributes

THD * thd
uint field_pos
enum enum_field_types * field_types
uint field_count

Member Function Documentation

void Protocol::end_partial_result_set ( THD *  thd_arg) [virtual]

Finish the result set with EOF packet, as is expected by the client, if there is an error evaluating the next row and a continue handler for the error.

Send the status of the current statement execution over network.

thdin fact, carries two parameters, NET for the transport and Diagnostics_area as the source of status information.

In MySQL, there are two types of SQL statements: those that return a result set and those that return status information only.

If a statement returns a result set, it consists of 3 parts:

  • result set meta-data
  • variable number of result set rows (can be 0)
  • followed and terminated by EOF or ERROR packet

Once the client has seen the meta-data information, it always expects an EOF or ERROR to terminate the result set. If ERROR is received, the result set rows are normally discarded (this is up to the client implementation, libmysql at least does discard them). EOF, on the contrary, means "successfully evaluated the entire result set". Since we don't know how many rows belong to a result set until it's evaluated, EOF/ERROR is the indicator of the end of the row stream. Note, that we can not buffer result set rows on the server -- there may be an arbitrary number of rows. But we do buffer the last packet (EOF/ERROR) in the Diagnostics_area and delay sending it till the very end of execution (here), to be able to change EOF to an ERROR if commit failed or some other error occurred during the last cleanup steps taken after execution.

A statement that does not return a result set doesn't send result set meta-data either. Instead it returns one of:

  • OK packet
  • ERROR packet. Similarly to the EOF/ERROR of the previous statement type, OK/ERROR packet is "buffered" in the diagnostics area and sent to the client in the end of statement.
This method defines a template, but delegates actual sending of data to virtual Protocol::send_{ok,eof,error}. This allows for implementation of protocols that "intercept" ok/eof/error messages, and store them in memory, etc, instead of sending to the client.
The diagnostics area is assigned or disabled. It can not be empty -- we assume that every SQL statement or COM_* command generates OK, ERROR, or EOF status.
The status information is encoded to protocol format and sent to the client.
We conventionally return void, since the only type of error that can happen here is a NET (transport) error, and that one will become visible when we attempt to read from the NET the next command. Diagnostics_area::is_sent is set for debugging purposes only.
bool Protocol::send_eof ( uint  server_status,
uint  statement_warn_count 
) [protected, virtual]

A default implementation of "EOF" packet response to the client.

Binary and text protocol do not differ in their EOF packet format.

Reimplemented in Protocol_local.

bool Protocol::send_error ( uint  sql_errno,
const char *  err_msg,
const char *  sql_state 
) [protected, virtual]

A default implementation of "ERROR" packet response to the client.

Binary and text protocol do not differ in ERROR packet format.

Reimplemented in Protocol_local.

bool Protocol::send_ok ( uint  server_status,
uint  statement_warn_count,
ulonglong  affected_rows,
ulonglong  last_insert_id,
const char *  message 
) [protected, virtual]

A default implementation of "OK" packet response to the client.

Currently this implementation is re-used by both network-oriented protocols -- the binary and text one. They do not differ in their OK packet format, which allows for a significant simplification on client side.

Reimplemented in Protocol_local.

bool Protocol::send_result_set_metadata ( List< Item > *  list,
uint  flags 
) [virtual]

Send name and type of result to client.

Sum fields has table name empty and field_name.

THDThread data object
listList of items to send to client
flagBit mask with the following functions:
  • 1 send number of rows
  • 2 send default values
  • 4 don't write eof packet
Return values:
1Error (Note that in this case the error is not sent to the client)

Reimplemented in Protocol_local.

bool Protocol::send_result_set_row ( List< Item > *  row_items)

Send one result set row.

row_itemsa collection of column values for that row
Error status.
Return values:
bool Protocol::store ( I_List< i_string > *  str_list)

Send a set of strings as one long string with ',' in between.

bool Protocol::store ( const char *  from,
const CHARSET_INFO *  cs 

Send \0 end terminated string.

fromNullS or \0 terminated string
In most cases one should use store(from, length) instead of this function
Return values:
bool Protocol::store_string_aux ( const char *  from,
size_t  length,
const CHARSET_INFO *  fromcs,
const CHARSET_INFO *  tocs 
) [protected]

Auxilary function to convert string to the given character set and store in network buffer.

The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines