MySQL 8.3.0
Source Code Documentation
Protocol Class Referencefinalabstract

#include <protocol.h>

Inheritance diagram for Protocol:
[legend]

Public Types

enum  enum_protocol_type {
  PROTOCOL_TEXT = 0 , PROTOCOL_BINARY = 1 , PROTOCOL_LOCAL = 2 , PROTOCOL_ERROR = 3 ,
  PROTOCOL_PLUGIN = 4
}
 Enum used by type() to specify the protocol type. More...
 
enum  { SEND_NUM_ROWS = 1 , SEND_DEFAULTS = 2 , SEND_EOF = 4 }
 Flags available to alter the way the messages are sent to the client. More...
 
using Type = BaseProtocol::Type
 

Public Member Functions

virtual ~Protocol ()=default
 
Protocolpop_protocol ()
 Remove the reference to the previous protocol and return it. More...
 
void push_protocol (Protocol *protocol)
 Set reference to "this" as the previous protocol on the protocol provided as argument. More...
 
virtual int read_packet ()=0
 Read packet from client. More...
 
virtual int get_command (COM_DATA *com_data, enum_server_command *cmd)=0
 Reads the command from the protocol and creates a command. More...
 
virtual enum enum_protocol_type type () const =0
 
virtual enum enum_vio_type connection_type () const =0
 
virtual bool store_null ()=0
 
virtual bool store_tiny (longlong from, uint32 zerofill)=0
 
virtual bool store_short (longlong from, uint32 zerofill)=0
 
virtual bool store_long (longlong from, uint32 zerofill)=0
 
virtual bool store_longlong (longlong from, bool unsigned_flag, uint32 zerofill)=0
 
virtual bool store_decimal (const my_decimal *, uint, uint)=0
 
virtual bool store_string (const char *from, size_t length, const CHARSET_INFO *fromcs)=0
 
virtual bool store_float (float from, uint32 decimals, uint32 zerofill)=0
 
virtual bool store_double (double from, uint32 decimals, uint32 zerofill)=0
 
virtual bool store_datetime (const MYSQL_TIME &time, uint precision)=0
 
virtual bool store_date (const MYSQL_TIME &time)=0
 
virtual bool store_time (const MYSQL_TIME &time, uint precision)=0
 
virtual bool store_field (const Field *field)=0
 
bool store (int from)
 
bool store (uint32 from)
 
bool store (longlong from)
 
bool store (ulonglong from)
 
bool store_tiny (longlong from)
 
bool store_short (longlong from)
 
bool store_long (longlong from)
 
bool store_longlong (longlong from, bool unsigned_flag)
 
bool store (const char *from, const CHARSET_INFO *fromcs)
 Send \0 end terminated string. More...
 
bool store (String *str)
 
bool store (const LEX_STRING &s, const CHARSET_INFO *cs)
 
virtual ulong get_client_capabilities ()=0
 Returns the client capabilities stored on the protocol. More...
 
virtual bool has_client_capability (unsigned long client_capability)=0
 Checks if the client capabilities include the one specified as parameter. More...
 
virtual bool connection_alive () const =0
 Checks if the protocol's connection with the client is still alive. More...
 
virtual void start_row ()=0
 Result set sending functions. More...
 
virtual bool end_row ()=0
 
virtual void abort_row ()=0
 
virtual void end_partial_result_set ()=0
 
virtual int shutdown (bool server_shutdown=false)=0
 Thread is being shut down, disconnect and free resources. More...
 
virtual uint get_rw_status ()=0
 Returns the read/writing status. More...
 
virtual bool get_compression ()=0
 Returns if the protocol is compressed or not. More...
 
virtual char * get_compression_algorithm ()=0
 Returns compression algorithm name. More...
 
virtual uint get_compression_level ()=0
 Returns compression level. More...
 
virtual bool start_result_metadata (uint num_cols, uint flags, const CHARSET_INFO *resultcs)=0
 Prepares the server for metadata sending. More...
 
virtual bool send_field_metadata (Send_field *field, const CHARSET_INFO *charset)=0
 Sends field metadata. More...
 
virtual bool end_result_metadata ()=0
 Signals the client that the metadata sending is done. More...
 
virtual bool send_ok (uint server_status, uint statement_warn_count, ulonglong affected_rows, ulonglong last_insert_id, const char *message)=0
 Send ok message to the client. More...
 
virtual bool send_eof (uint server_status, uint statement_warn_count)=0
 Send eof message to the client. More...
 
virtual bool send_error (uint sql_errno, const char *err_msg, const char *sql_state)=0
 Send error message to the client. More...
 
virtual bool flush ()=0
 Used for the classic protocol. More...
 
virtual bool store_ps_status (ulong stmt_id, uint column_count, uint param_count, ulong cond_count)=0
 Sends prepared statement's id and metadata to the client after prepare. More...
 
virtual bool send_parameters (List< Item_param > *parameters, bool is_sql_prepare)=0
 Sends the OUT-parameters to the client. More...
 

Static Public Member Functions

static Type get_default ()
 
static Type get_by_name (const std::string &name)
 Returns type of the protocol by its name. More...
 
static uint16_t get_default_port (Type type)
 Returns default port for the selected protocol. More...
 

Private Attributes

Protocolm_previous_protocol = nullptr
 Pointer to the Protocol below on the stack. More...
 

Static Private Attributes

static constexpr uint16_t kClassicProtocolDefaultPort {3306}
 default server ports for supported protocols More...
 
static constexpr uint16_t kXProtocolDefaultPort {33060}
 

Member Typedef Documentation

◆ Type

Member Enumeration Documentation

◆ anonymous enum

anonymous enum

Flags available to alter the way the messages are sent to the client.

Enumerator
SEND_NUM_ROWS 
SEND_DEFAULTS 
SEND_EOF 

◆ enum_protocol_type

Enum used by type() to specify the protocol type.

Enumerator
PROTOCOL_TEXT 
PROTOCOL_BINARY 
PROTOCOL_LOCAL 
PROTOCOL_ERROR 
PROTOCOL_PLUGIN 

Constructor & Destructor Documentation

◆ ~Protocol()

virtual Protocol::~Protocol ( )
virtualdefault

Member Function Documentation

◆ abort_row()

virtual void Protocol::abort_row ( )
pure virtual

◆ connection_alive()

virtual bool Protocol::connection_alive ( ) const
pure virtual

Checks if the protocol's connection with the client is still alive.

It should always return true unless the protocol closed the connection.

Return values
trueif the connection is still alive
falseotherwise

Implemented in Protocol_callback, Protocol_classic, and Protocol_local.

◆ connection_type()

virtual enum enum_vio_type Protocol::connection_type ( ) const
pure virtual

◆ end_partial_result_set()

virtual void Protocol::end_partial_result_set ( )
pure virtual

◆ end_result_metadata()

virtual bool Protocol::end_result_metadata ( )
pure virtual

Signals the client that the metadata sending is done.

Clears the server after sending the metadata.

Return values
falseOk
trueAn error occurred

Implemented in Protocol_callback, Protocol_classic, and Protocol_local.

◆ end_row()

virtual bool Protocol::end_row ( )
pure virtual

◆ flush()

virtual bool Protocol::flush ( )
pure virtual

Used for the classic protocol.

Makes the protocol send the messages/data to the client.

Return values
falseThe flush was successful.
trueAn error occurred.

Implemented in Protocol_callback, Protocol_classic, and Protocol_local.

◆ get_by_name()

static Type Protocol::get_by_name ( const std::string &  name)
inlinestatic

Returns type of the protocol by its name.

◆ get_client_capabilities()

virtual ulong Protocol::get_client_capabilities ( )
pure virtual

Returns the client capabilities stored on the protocol.

The available capabilities are defined in mysql_com.h

Implemented in Protocol_callback, Protocol_classic, and Protocol_local.

◆ get_command()

virtual int Protocol::get_command ( COM_DATA com_data,
enum_server_command cmd 
)
pure virtual

Reads the command from the protocol and creates a command.

Parameters
com_dataout parameter
cmdout parameter
Returns
-1 fatal protocol error 0 ok 1 non-fatal protocol or parsing error

Implemented in Protocol_callback, Protocol_classic, and Protocol_local.

◆ get_compression()

virtual bool Protocol::get_compression ( )
pure virtual

Returns if the protocol is compressed or not.

Return values
falseNot compressed
trueCompressed

Implemented in Protocol_callback, Protocol_classic, and Protocol_local.

◆ get_compression_algorithm()

virtual char * Protocol::get_compression_algorithm ( )
pure virtual

Returns compression algorithm name.

Return values
stringcompression method name
NULLif no compression is enabled

Implemented in Protocol_callback, Protocol_classic, and Protocol_local.

◆ get_compression_level()

virtual uint Protocol::get_compression_level ( )
pure virtual

Returns compression level.

Returns
compression level

Implemented in Protocol_callback, Protocol_classic, and Protocol_local.

◆ get_default()

static Type Protocol::get_default ( )
inlinestatic

◆ get_default_port()

static uint16_t Protocol::get_default_port ( Type  type)
inlinestatic

Returns default port for the selected protocol.

◆ get_rw_status()

virtual uint Protocol::get_rw_status ( )
pure virtual

Returns the read/writing status.

Return values
1Read
2Write
0Other(Idle, Killed)

Implemented in Protocol_callback, Protocol_classic, and Protocol_local.

◆ has_client_capability()

virtual bool Protocol::has_client_capability ( unsigned long  client_capability)
pure virtual

Checks if the client capabilities include the one specified as parameter.

Return values
trueif it includes the specified capability
falseotherwise

Implemented in Protocol_callback, Protocol_classic, and Protocol_local.

◆ pop_protocol()

Protocol * Protocol::pop_protocol ( )
inline

Remove the reference to the previous protocol and return it.

Returns
The new top of the Protocol stack.

◆ push_protocol()

void Protocol::push_protocol ( Protocol protocol)
inline

Set reference to "this" as the previous protocol on the protocol provided as argument.

Parameters
protocolProtocol to become the top of Protocol stack.

◆ read_packet()

virtual int Protocol::read_packet ( )
pure virtual

Read packet from client.

Return values
-1fatal error
0ok
1non-fatal error

Implemented in Protocol_callback, Protocol_classic, and Protocol_local.

◆ send_eof()

virtual bool Protocol::send_eof ( uint  server_status,
uint  statement_warn_count 
)
pure virtual

Send eof message to the client.

Parameters
server_statusThe server status
statement_warn_countTotal number of warnings
Return values
falseThe message was successfully sent
trueAn error occurred and the messages wasn't sent properly

Implemented in Protocol_classic, Protocol_local, and Protocol_callback.

◆ send_error()

virtual bool Protocol::send_error ( uint  sql_errno,
const char *  err_msg,
const char *  sql_state 
)
pure virtual

Send error message to the client.

Parameters
sql_errnoThe error code to send
err_msgA pointer to the error message
sql_stateSQL state
Return values
falseThe message was successfully sent
trueAn error occurred and the messages wasn't sent properly

Implemented in Protocol_callback, Protocol_classic, and Protocol_local.

◆ send_field_metadata()

virtual bool Protocol::send_field_metadata ( Send_field field,
const CHARSET_INFO charset 
)
pure virtual

Sends field metadata.

Parameters
fieldField metadata to be send to the client
charsetField's charset: in case it is different than the one used by the connection it will be used to convert the value to the connection's charset
Return values
falseThe metadata was successfully sent
trueAn error occurred

Implemented in Protocol_local, Protocol_callback, and Protocol_classic.

◆ send_ok()

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

Send ok message to the client.

Parameters
server_statusThe server status
statement_warn_countTotal number of warnings
affected_rowsNumber of rows changed by statement
last_insert_idLast insert id (Auto_increment id for first row if used)
messageMessage to send to the client
Return values
falseThe message was successfully sent
trueAn error occurred and the messages wasn't sent properly

Implemented in Protocol_classic, Protocol_local, and Protocol_callback.

◆ send_parameters()

virtual bool Protocol::send_parameters ( List< Item_param > *  parameters,
bool  is_sql_prepare 
)
pure virtual

Sends the OUT-parameters to the client.

Parameters
parametersList of PS/SP parameters (both input and output).
is_sql_prepareUsed for the legacy protocol. If we're dealing with sql prepare then text protocol will be used.
Returns
Error status.
Return values
falseSuccess.
trueError.

Implemented in Protocol_local, Protocol_callback, Protocol_binary, and Protocol_text.

◆ shutdown()

virtual int Protocol::shutdown ( bool  server_shutdown = false)
pure virtual

Thread is being shut down, disconnect and free resources.

Parameters
server_shutdownIf false then this is normal thread shutdown. If true then the server is shutting down.

Implemented in Protocol_callback, Protocol_classic, and Protocol_local.

◆ start_result_metadata()

virtual bool Protocol::start_result_metadata ( uint  num_cols,
uint  flags,
const CHARSET_INFO resultcs 
)
pure virtual

Prepares the server for metadata sending.

Notifies the client that the metadata sending will start.

Parameters
num_colsNumber of columns that will be sent
flagsFlags to alter the metadata sending Can be any of the following: SEND_NUM_ROWS, SEND_DEFAULTS, SEND_EOF
resultcsCharset to convert to
Return values
falseOk
trueAn error occurred

Implemented in Protocol_callback, Protocol_classic, Protocol_binary, and Protocol_local.

◆ start_row()

virtual void Protocol::start_row ( )
pure virtual

Result set sending functions.

Server uses following schema to send result: ... sending metadata ... | start_result_metadata(...) | start_row() | send_field_metadata(...) | end_row() ... same for each field sent ... | end_result_metadata(...) | ... sending result ... | start_row(...) | store_xxx(...) ... store_xxx(..) is called for each field ... | end_row(...) ... same for each row, until all rows are sent ... | send_ok/eof/error(...) However, a protocol implementation might use different schema. For example, Protocol_callback ignores start/end_row when metadata is being sent.

Implemented in Protocol_callback, Protocol_text, Protocol_binary, and Protocol_local.

◆ store() [1/7]

bool Protocol::store ( const char *  from,
const CHARSET_INFO fromcs 
)
inline

Send \0 end terminated string.

Parameters
fromNullS or \0 terminated string.
fromcsCharacter set of the from string.
Note
In most cases one should use store(from, length, cs) instead of this function
Return values
falseok
trueerror

◆ store() [2/7]

bool Protocol::store ( const LEX_STRING s,
const CHARSET_INFO cs 
)
inline

◆ store() [3/7]

bool Protocol::store ( int  from)
inline

◆ store() [4/7]

bool Protocol::store ( longlong  from)
inline

◆ store() [5/7]

bool Protocol::store ( String str)
inline

◆ store() [6/7]

bool Protocol::store ( uint32  from)
inline

◆ store() [7/7]

bool Protocol::store ( ulonglong  from)
inline

◆ store_date()

virtual bool Protocol::store_date ( const MYSQL_TIME time)
pure virtual

◆ store_datetime()

virtual bool Protocol::store_datetime ( const MYSQL_TIME time,
uint  precision 
)
pure virtual

◆ store_decimal()

virtual bool Protocol::store_decimal ( const my_decimal ,
uint  ,
uint   
)
pure virtual

◆ store_double()

virtual bool Protocol::store_double ( double  from,
uint32  decimals,
uint32  zerofill 
)
pure virtual

◆ store_field()

virtual bool Protocol::store_field ( const Field field)
pure virtual

◆ store_float()

virtual bool Protocol::store_float ( float  from,
uint32  decimals,
uint32  zerofill 
)
pure virtual

◆ store_long() [1/2]

bool Protocol::store_long ( longlong  from)
inline

◆ store_long() [2/2]

virtual bool Protocol::store_long ( longlong  from,
uint32  zerofill 
)
pure virtual

◆ store_longlong() [1/2]

bool Protocol::store_longlong ( longlong  from,
bool  unsigned_flag 
)
inline

◆ store_longlong() [2/2]

virtual bool Protocol::store_longlong ( longlong  from,
bool  unsigned_flag,
uint32  zerofill 
)
pure virtual

◆ store_null()

virtual bool Protocol::store_null ( )
pure virtual

◆ store_ps_status()

virtual bool Protocol::store_ps_status ( ulong  stmt_id,
uint  column_count,
uint  param_count,
ulong  cond_count 
)
pure virtual

Sends prepared statement's id and metadata to the client after prepare.

Parameters
stmt_idStatement id.
column_countNumber of columns.
param_countNumber of parameters.
cond_countNumber of conditions raised by the current statement.
Returns
Error status.
Return values
falseThe send was successful.
trueAn error occurred.

Implemented in Protocol_callback, Protocol_classic, and Protocol_local.

◆ store_short() [1/2]

bool Protocol::store_short ( longlong  from)
inline

◆ store_short() [2/2]

virtual bool Protocol::store_short ( longlong  from,
uint32  zerofill 
)
pure virtual

◆ store_string()

virtual bool Protocol::store_string ( const char *  from,
size_t  length,
const CHARSET_INFO fromcs 
)
pure virtual

◆ store_time()

virtual bool Protocol::store_time ( const MYSQL_TIME time,
uint  precision 
)
pure virtual

◆ store_tiny() [1/2]

bool Protocol::store_tiny ( longlong  from)
inline

◆ store_tiny() [2/2]

virtual bool Protocol::store_tiny ( longlong  from,
uint32  zerofill 
)
pure virtual

◆ type()

virtual enum enum_protocol_type Protocol::type ( ) const
pure virtual

Member Data Documentation

◆ kClassicProtocolDefaultPort

constexpr uint16_t Protocol::kClassicProtocolDefaultPort {3306}
staticconstexprprivate

default server ports for supported protocols

◆ kXProtocolDefaultPort

constexpr uint16_t Protocol::kXProtocolDefaultPort {33060}
staticconstexprprivate

◆ m_previous_protocol

Protocol* Protocol::m_previous_protocol = nullptr
private

Pointer to the Protocol below on the stack.


The documentation for this class was generated from the following files: