MySQL 9.1.0
Source Code Documentation
Protocol_classic Class Reference

#include <protocol_classic.h>

Inheritance diagram for Protocol_classic:
[legend]

Public Member Functions

 Protocol_classic ()
 
 Protocol_classic (THD *thd)
 
void init (THD *thd_arg)
 
bool store_field (const Field *field) final
 
bool store_string (const char *from, size_t length, const CHARSET_INFO *cs) final
 
int read_packet () override
 Read packet from client. More...
 
int get_command (COM_DATA *com_data, enum_server_command *cmd) override
 Reads the command from the protocol and creates a command. More...
 
bool create_command (COM_DATA *com_data, enum_server_command cmd, uchar *pkt, size_t length)
 Parses the passed parameters and creates a command. More...
 
bool flush () override
 Used for the classic protocol. More...
 
void end_partial_result_set () override
 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. More...
 
bool end_row () override
 
uint get_rw_status () override
 Returns the read/writing status. More...
 
bool get_compression () override
 Returns if the protocol is compressed or not. More...
 
char * get_compression_algorithm () override
 Returns compression algorithm name. More...
 
uint get_compression_level () override
 Returns compression level. More...
 
bool start_result_metadata (uint num_cols, uint flags, const CHARSET_INFO *resultcs) override
 Prepares the server for metadata sending. More...
 
bool end_result_metadata () override
 Signals the client that the metadata sending is done. More...
 
bool send_field_metadata (Send_field *field, const CHARSET_INFO *item_charset) override
 Sends a single column metadata. More...
 
void abort_row () override
 
enum enum_vio_type connection_type () const override
 Returns the type of the connection. More...
 
my_socket get_socket ()
 
bool init_net (Vio *vio)
 
void claim_memory_ownership (bool claim)
 
void end_net ()
 
bool write (const uchar *ptr, size_t len)
 
uchar get_error ()
 
void set_max_packet_size (ulong max_packet_size)
 
int shutdown (bool server_shutdown=false) override
 Thread is being shut down, disconnect and free resources. More...
 
void wipe_net ()
 
bool connection_alive () const override
 Checks if the protocol's connection with the client is still alive. More...
 
ulong get_client_capabilities () override
 Returns the client capabilities stored on the protocol. More...
 
void set_client_capabilities (ulong client_capabilities)
 
void add_client_capability (ulong client_capability)
 
void remove_client_capability (unsigned long capability)
 
bool has_client_capability (unsigned long client_capability) override
 Checks if the client capabilities include the one specified as parameter. More...
 
NETget_net ()
 
Vioget_vio ()
 
const Vioget_vio () const
 
void set_vio (Vio *vio)
 
void set_output_pkt_nr (uint pkt_nr)
 
uint get_output_pkt_nr ()
 
Stringget_output_packet ()
 
ulong get_packet_length ()
 
ucharget_raw_packet ()
 
virtual void set_read_timeout (ulong read_timeout, bool on_full_packet=false)
 
virtual void set_write_timeout (ulong write_timeout)
 
void set_result_character_set (const CHARSET_INFO *charset)
 Sets the character set expected by the client. More...
 
- Public Member Functions inherited from Protocol
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 enum enum_protocol_type 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_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
 
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 void start_row ()=0
 Result set sending functions. More...
 
virtual bool send_parameters (List< Item_param > *parameters, bool is_sql_prepare)=0
 Sends the OUT-parameters to the client. More...
 

Public Attributes

bool bad_packet
 

Protected Member Functions

bool send_ok (uint server_status, uint statement_warn_count, ulonglong affected_rows, ulonglong last_insert_id, const char *message) override
 A default implementation of "OK" packet response to the client. More...
 
bool send_eof (uint server_status, uint statement_warn_count) override
 A default implementation of "EOF" packet response to the client. More...
 
bool send_error (uint sql_errno, const char *err_msg, const char *sql_state) override
 A default implementation of "ERROR" packet response to the client. More...
 
bool store_ps_status (ulong stmt_id, uint column_count, uint param_count, ulong cond_count) override
 Sends prepared statement's id and metadata to the client after prepare. More...
 

Protected Attributes

THDm_thd
 
Stringpacket
 
String convert
 
uint field_pos
 
bool send_metadata
 
enum enum_field_typesfield_types
 
uint count
 
uint field_count
 
uint sending_flags
 
ulong input_packet_length
 
ucharinput_raw_packet
 
const CHARSET_INFOresult_cs
 

Private Member Functions

bool parse_packet (union COM_DATA *data, enum_server_command cmd)
 
bool net_store_data_with_conversion (const uchar *from, size_t length, const CHARSET_INFO *fromcs, const CHARSET_INFO *tocs)
 net_store_data() - extended version with character set conversion. More...
 

Private Attributes

ulong m_client_capabilities
 

Additional Inherited Members

- Public Types inherited from Protocol
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
 
- Static Public Member Functions inherited from Protocol
static Type get_default ()
 
static Type get_by_name (const std::string &name)
 Returns type of the protocol by its name. More...
 
static std::string to_string (const Type &type)
 
static uint16_t get_default_port (Type type)
 Returns default port for the selected protocol. More...
 

Constructor & Destructor Documentation

◆ Protocol_classic() [1/2]

Protocol_classic::Protocol_classic ( )
inline

◆ Protocol_classic() [2/2]

Protocol_classic::Protocol_classic ( THD thd)
inline

Member Function Documentation

◆ abort_row()

void Protocol_classic::abort_row ( )
inlineoverridevirtual

Implements Protocol.

◆ add_client_capability()

void Protocol_classic::add_client_capability ( ulong  client_capability)
inline

◆ claim_memory_ownership()

void Protocol_classic::claim_memory_ownership ( bool  claim)

◆ connection_alive()

bool Protocol_classic::connection_alive ( ) const
overridevirtual

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

Implements Protocol.

◆ connection_type()

enum enum_vio_type Protocol_classic::connection_type ( ) const
inlineoverridevirtual

Returns the type of the connection.

Returns
enum enum_vio_type

Implements Protocol.

◆ create_command()

bool Protocol_classic::create_command ( COM_DATA com_data,
enum_server_command  cmd,
uchar pkt,
size_t  length 
)

Parses the passed parameters and creates a command.

Parameters
com_dataout parameter
cmdin parameter
pktpacket to be parsed
lengthsize of the packet
Return values
falseok
trueerror

◆ end_net()

void Protocol_classic::end_net ( )

◆ end_partial_result_set()

void Protocol_classic::end_partial_result_set ( )
overridevirtual

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.

Implements Protocol.

◆ end_result_metadata()

bool Protocol_classic::end_result_metadata ( )
overridevirtual

Signals the client that the metadata sending is done.

Clears the server after sending the metadata.

Return values
falseOk
trueAn error occurred

Implements Protocol.

◆ end_row()

bool Protocol_classic::end_row ( )
overridevirtual

Implements Protocol.

◆ flush()

bool Protocol_classic::flush ( )
overridevirtual

Used for the classic protocol.

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

Return values
falseThe flush was successful.
trueAn error occurred.

Implements Protocol.

◆ get_client_capabilities()

ulong Protocol_classic::get_client_capabilities ( )
inlineoverridevirtual

Returns the client capabilities stored on the protocol.

The available capabilities are defined in mysql_com.h

Implements Protocol.

◆ get_command()

int Protocol_classic::get_command ( COM_DATA com_data,
enum_server_command cmd 
)
overridevirtual

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

Implements Protocol.

◆ get_compression()

bool Protocol_classic::get_compression ( )
overridevirtual

Returns if the protocol is compressed or not.

Return values
falseNot compressed
trueCompressed

Implements Protocol.

◆ get_compression_algorithm()

char * Protocol_classic::get_compression_algorithm ( )
overridevirtual

Returns compression algorithm name.

Return values
stringcompression method name
NULLif no compression is enabled

Implements Protocol.

◆ get_compression_level()

uint Protocol_classic::get_compression_level ( )
overridevirtual

Returns compression level.

Returns
compression level

Implements Protocol.

◆ get_error()

uchar Protocol_classic::get_error ( )

◆ get_net()

NET * Protocol_classic::get_net ( )

◆ get_output_packet()

String * Protocol_classic::get_output_packet ( )

◆ get_output_pkt_nr()

uint Protocol_classic::get_output_pkt_nr ( )

◆ get_packet_length()

ulong Protocol_classic::get_packet_length ( )
inline

◆ get_raw_packet()

uchar * Protocol_classic::get_raw_packet ( )
inline

◆ get_rw_status()

uint Protocol_classic::get_rw_status ( )
overridevirtual

Returns the read/writing status.

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

Implements Protocol.

◆ get_socket()

my_socket Protocol_classic::get_socket ( )
Returns
: the file descriptor of the socket.

◆ get_vio() [1/2]

Vio * Protocol_classic::get_vio ( )

◆ get_vio() [2/2]

const Vio * Protocol_classic::get_vio ( ) const

◆ has_client_capability()

bool Protocol_classic::has_client_capability ( unsigned long  client_capability)
inlineoverridevirtual

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

Return values
trueif it includes the specified capability
falseotherwise

Implements Protocol.

◆ init()

void Protocol_classic::init ( THD thd_arg)

◆ init_net()

bool Protocol_classic::init_net ( Vio vio)

◆ net_store_data_with_conversion()

bool Protocol_classic::net_store_data_with_conversion ( const uchar from,
size_t  length,
const CHARSET_INFO from_cs,
const CHARSET_INFO to_cs 
)
private

net_store_data() - extended version with character set conversion.

It is optimized for short strings whose length after conversion is guaranteed to be less than 251, which occupies exactly one byte to store length. It allows not to use the "convert" member as a temporary buffer, conversion is done directly to the "packet" member. The limit 251 is good enough to optimize send_result_set_metadata() because column, table, database names fit into this limit.

◆ parse_packet()

bool Protocol_classic::parse_packet ( union COM_DATA data,
enum_server_command  cmd 
)
private

◆ read_packet()

int Protocol_classic::read_packet ( )
overridevirtual

Read packet from client.

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

Implements Protocol.

◆ remove_client_capability()

void Protocol_classic::remove_client_capability ( unsigned long  capability)
inline

◆ send_eof()

bool Protocol_classic::send_eof ( uint  server_status,
uint  statement_warn_count 
)
overrideprotectedvirtual

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

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

Implements Protocol.

◆ send_error()

bool Protocol_classic::send_error ( uint  sql_errno,
const char *  err_msg,
const char *  sql_state 
)
overrideprotectedvirtual

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

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

Implements Protocol.

◆ send_field_metadata()

bool Protocol_classic::send_field_metadata ( Send_field field,
const CHARSET_INFO item_charset 
)
overridevirtual

Sends a single column metadata.

Parameters
fieldField description
item_charsetCharacter set to use
Return values
falsesuccess
trueerror

See Column Definition for the format

Implements Protocol.

◆ send_ok()

bool Protocol_classic::send_ok ( uint  server_status,
uint  statement_warn_count,
ulonglong  affected_rows,
ulonglong  last_insert_id,
const char *  message 
)
overrideprotectedvirtual

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.

Implements Protocol.

◆ set_client_capabilities()

void Protocol_classic::set_client_capabilities ( ulong  client_capabilities)
inline

◆ set_max_packet_size()

void Protocol_classic::set_max_packet_size ( ulong  max_packet_size)

◆ set_output_pkt_nr()

void Protocol_classic::set_output_pkt_nr ( uint  pkt_nr)

◆ set_read_timeout()

void Protocol_classic::set_read_timeout ( ulong  read_timeout,
bool  on_full_packet = false 
)
virtual

◆ set_result_character_set()

void Protocol_classic::set_result_character_set ( const CHARSET_INFO charset)
inline

Sets the character set expected by the client.

This function is for unit tests. It should usually be set by calling start_result_metadata().

◆ set_vio()

void Protocol_classic::set_vio ( Vio vio)

◆ set_write_timeout()

void Protocol_classic::set_write_timeout ( ulong  write_timeout)
virtual

◆ shutdown()

int Protocol_classic::shutdown ( bool  server_shutdown = false)
overridevirtual

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.

Implements Protocol.

◆ start_result_metadata()

bool Protocol_classic::start_result_metadata ( uint  num_cols,
uint  flags,
const CHARSET_INFO resultcs 
)
overridevirtual

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

Implements Protocol.

Reimplemented in Protocol_binary.

◆ store_field()

bool Protocol_classic::store_field ( const Field field)
finalvirtual

Implements Protocol.

◆ store_ps_status()

bool Protocol_classic::store_ps_status ( ulong  stmt_id,
uint  column_count,
uint  param_count,
ulong  cond_count 
)
overrideprotectedvirtual

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.

Implements Protocol.

◆ store_string()

bool Protocol_classic::store_string ( const char *  from,
size_t  length,
const CHARSET_INFO cs 
)
finalvirtual

Implements Protocol.

◆ wipe_net()

void Protocol_classic::wipe_net ( )

◆ write()

bool Protocol_classic::write ( const uchar ptr,
size_t  len 
)

Member Data Documentation

◆ bad_packet

bool Protocol_classic::bad_packet

◆ convert

String Protocol_classic::convert
protected

◆ count

uint Protocol_classic::count
protected

◆ field_count

uint Protocol_classic::field_count
protected

◆ field_pos

uint Protocol_classic::field_pos
protected

◆ field_types

enum enum_field_types* Protocol_classic::field_types
protected

◆ input_packet_length

ulong Protocol_classic::input_packet_length
protected

◆ input_raw_packet

uchar* Protocol_classic::input_raw_packet
protected

◆ m_client_capabilities

ulong Protocol_classic::m_client_capabilities
private

◆ m_thd

THD* Protocol_classic::m_thd
protected

◆ packet

String* Protocol_classic::packet
protected

◆ result_cs

const CHARSET_INFO* Protocol_classic::result_cs
protected

◆ send_metadata

bool Protocol_classic::send_metadata
protected

◆ sending_flags

uint Protocol_classic::sending_flags
protected

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