MySQL 8.0.40
Source Code Documentation
Protocol_local Class Referencefinal

Protocol_local: a helper class to intercept the result of the data written to the network. More...

Inheritance diagram for Protocol_local:
[legend]

Public Member Functions

 Protocol_local (THD *thd, Ed_connection *ed_connection)
 
 ~Protocol_local () override
 
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...
 
ulong get_client_capabilities () override
 Returns the client capabilities stored on the protocol. More...
 
bool has_client_capability (unsigned long client_capability) override
 Checks if the client capabilities include the one specified as parameter. More...
 
void end_partial_result_set () override
 
int shutdown (bool server_shutdown=false) override
 Thread is being shut down, disconnect and free resources. More...
 
bool connection_alive () const override
 Checks if the protocol's connection with the client is still alive. More...
 
void start_row () override
 Called between two result set rows. More...
 
bool end_row () override
 Add the current row to the result set. More...
 
void abort_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 *charset) override
 Sends field metadata. More...
 
bool flush () override
 Used for the classic protocol. More...
 
bool send_parameters (List< Item_param > *, bool) override
 Sends the OUT-parameters to the client. More...
 
bool store_ps_status (ulong, uint, uint, ulong) override
 Sends prepared statement's id and metadata to the client after prepare. 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...
 
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)
 

Protected Member Functions

bool store_null () override
 Add a NULL column to the current row. More...
 
bool store_tiny (longlong from, uint32) override
 Store a tiny int as is (1 byte) in a result set column. More...
 
bool store_short (longlong from, uint32) override
 Store a short as is (2 bytes, host order) in a result set column. More...
 
bool store_long (longlong from, uint32) override
 Store a "long" as is (4 bytes, host order) in a result set column. More...
 
bool store_longlong (longlong from, bool unsigned_flag, uint32) override
 Store a "longlong" as is (8 bytes, host order) in a result set column. More...
 
bool store_decimal (const my_decimal *, uint, uint) override
 Store a decimal in string format in a result set column. More...
 
bool store_string (const char *from, size_t length, const CHARSET_INFO *cs) override
 Convert to cs_results and store a string. More...
 
bool store_datetime (const MYSQL_TIME &time, uint precision) override
 
bool store_date (const MYSQL_TIME &time) override
 Store MYSQL_TIME (in binary format) More...
 
bool store_time (const MYSQL_TIME &time, uint precision) override
 Store MYSQL_TIME (in binary format) More...
 
bool store_float (float value, uint32 decimals, uint32 zerofill) override
 
bool store_double (double value, uint32 decimals, uint32 zerofill) override
 
bool store_field (const Field *field) override
 
enum enum_protocol_type type () const override
 
enum enum_vio_type connection_type () const override
 
bool send_ok (uint server_status, uint statement_warn_count, ulonglong affected_rows, ulonglong last_insert_id, const char *message) override
 Called for statements that don't have a result set, at statement end. More...
 
bool send_eof (uint server_status, uint statement_warn_count) override
 Called at the end of a result set. More...
 
bool send_error (uint sql_errno, const char *err_msg, const char *sqlstate) override
 Called to send an error to the client at the end of a statement. More...
 

Private Member Functions

bool store_string (const char *str, size_t length, const CHARSET_INFO *src_cs, const CHARSET_INFO *dst_cs)
 Store a string value in a result set column, optionally having converted it to character_set_results. More...
 
bool store_column (const void *data, size_t length)
 A helper method to add any column to the current row in its binary form. More...
 
void opt_add_row_to_rset ()
 A helper function to add the current row to the current result set. More...
 

Private Attributes

Ed_connectionm_connection
 
MEM_ROOT m_rset_root
 
List< Ed_row > * m_rset
 
size_t m_column_count
 
Ed_columnm_current_row
 
Ed_columnm_current_column
 
Ed_rowm_fields
 
bool m_send_metadata
 
THDm_thd
 

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 uint16_t get_default_port (Type type)
 Returns default port for the selected protocol. More...
 

Detailed Description

Protocol_local: a helper class to intercept the result of the data written to the network.

At the start of every result set, start_result_metadata allocates m_rset to prepare for the results. The metadata is stored on m_current_row which will be transferred to m_fields in end_result_metadata. The memory for the metadata is allocated on m_rset_root.

Then, for every row of the result received, each of the fields is stored in m_current_row. Then the row is moved to m_rset and m_current_row is cleared to receive the next row. The memory for all the results are also stored in m_rset_root.

Finally, at the end of the result set, a new instance of Ed_result_set is created on m_rset_root and the result set (m_rset and m_fields) is moved into this instance. The ownership of MEM_ROOT m_rset_root is also transferred to this instance. So, at the end we have a fresh MEM_ROOT, cleared m_rset and m_fields to accept the next result set.

Constructor & Destructor Documentation

◆ Protocol_local()

Protocol_local::Protocol_local ( THD thd,
Ed_connection ed_connection 
)

◆ ~Protocol_local()

Protocol_local::~Protocol_local ( )
inlineoverride

Member Function Documentation

◆ abort_row()

void Protocol_local::abort_row ( )
inlineoverridevirtual

Implements Protocol.

◆ connection_alive()

bool Protocol_local::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_local::connection_type ( ) const
inlineoverrideprotectedvirtual

Implements Protocol.

◆ end_partial_result_set()

void Protocol_local::end_partial_result_set ( )
overridevirtual

Implements Protocol.

◆ end_result_metadata()

bool Protocol_local::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_local::end_row ( )
overridevirtual

Add the current row to the result set.

Implements Protocol.

◆ flush()

bool Protocol_local::flush ( )
inlineoverridevirtual

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_local::get_client_capabilities ( )
overridevirtual

Returns the client capabilities stored on the protocol.

The available capabilities are defined in mysql_com.h

Implements Protocol.

◆ get_command()

int Protocol_local::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_local::get_compression ( )
overridevirtual

Returns if the protocol is compressed or not.

Return values
falseNot compressed
trueCompressed

Implements Protocol.

◆ get_compression_algorithm()

char * Protocol_local::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_local::get_compression_level ( )
overridevirtual

Returns compression level.

Returns
compression level

Implements Protocol.

◆ get_rw_status()

uint Protocol_local::get_rw_status ( )
overridevirtual

Returns the read/writing status.

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

Implements Protocol.

◆ has_client_capability()

bool Protocol_local::has_client_capability ( unsigned long  client_capability)
overridevirtual

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

Return values
trueif it includes the specified capability
falseotherwise

Implements Protocol.

◆ opt_add_row_to_rset()

void Protocol_local::opt_add_row_to_rset ( )
private

A helper function to add the current row to the current result set.

Called in

See also
start_row(), when a new row is started, and in send_eof(), when the result set is finished.

◆ read_packet()

int Protocol_local::read_packet ( )
overridevirtual

Read packet from client.

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

Implements Protocol.

◆ send_eof()

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

Called at the end of a result set.

Append a complete result set to the list in Ed_connection.

Don't send anything to the client, but instead finish building of the result set at hand.

Implements Protocol.

◆ send_error()

bool Protocol_local::send_error ( uint  sql_errno,
const char *  err_msg,
const char *  sqlstate 
)
overrideprotectedvirtual

Called to send an error to the client at the end of a statement.

Implements Protocol.

◆ send_field_metadata()

bool Protocol_local::send_field_metadata ( Send_field field,
const CHARSET_INFO charset 
)
overridevirtual

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

Implements Protocol.

◆ send_ok()

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

Called for statements that don't have a result set, at statement end.

Implements Protocol.

◆ send_parameters()

bool Protocol_local::send_parameters ( List< Item_param > *  parameters,
bool  is_sql_prepare 
)
inlineoverridevirtual

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.

Implements Protocol.

◆ shutdown()

int Protocol_local::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_local::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.

◆ start_row()

void Protocol_local::start_row ( )
overridevirtual

Called between two result set rows.

Prepare structures to fill result set rows. Unfortunately, we can't return an error here. If memory allocation fails, we'll have to return an error later. And so is done in methods such as

See also
store_column().

Implements Protocol.

◆ store_column()

bool Protocol_local::store_column ( const void *  data,
size_t  length 
)
private

A helper method to add any column to the current row in its binary form.

Allocates memory for the data in the result set memory root.

◆ store_date()

bool Protocol_local::store_date ( const MYSQL_TIME time)
overrideprotectedvirtual

Store MYSQL_TIME (in binary format)

Implements Protocol.

◆ store_datetime()

bool Protocol_local::store_datetime ( const MYSQL_TIME time,
uint  precision 
)
overrideprotectedvirtual

Implements Protocol.

◆ store_decimal()

bool Protocol_local::store_decimal ( const my_decimal value,
uint  prec,
uint  dec 
)
overrideprotectedvirtual

Store a decimal in string format in a result set column.

Implements Protocol.

◆ store_double()

bool Protocol_local::store_double ( double  value,
uint32  decimals,
uint32  zerofill 
)
overrideprotectedvirtual

Implements Protocol.

◆ store_field()

bool Protocol_local::store_field ( const Field field)
overrideprotectedvirtual

Implements Protocol.

◆ store_float()

bool Protocol_local::store_float ( float  value,
uint32  decimals,
uint32  zerofill 
)
overrideprotectedvirtual

Implements Protocol.

◆ store_long()

bool Protocol_local::store_long ( longlong  value,
uint32   
)
overrideprotectedvirtual

Store a "long" as is (4 bytes, host order) in a result set column.


Implements Protocol.

◆ store_longlong()

bool Protocol_local::store_longlong ( longlong  from,
bool  unsigned_flag,
uint32   
)
overrideprotectedvirtual

Store a "longlong" as is (8 bytes, host order) in a result set column.

Implements Protocol.

◆ store_null()

bool Protocol_local::store_null ( )
overrideprotectedvirtual

Add a NULL column to the current row.

Implements Protocol.

◆ store_ps_status()

bool Protocol_local::store_ps_status ( ulong  stmt_id,
uint  column_count,
uint  param_count,
ulong  cond_count 
)
inlineoverridevirtual

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_short()

bool Protocol_local::store_short ( longlong  from,
uint32   
)
overrideprotectedvirtual

Store a short as is (2 bytes, host order) in a result set column.

Implements Protocol.

◆ store_string() [1/2]

bool Protocol_local::store_string ( const char *  from,
size_t  length,
const CHARSET_INFO cs 
)
overrideprotectedvirtual

Convert to cs_results and store a string.

Implements Protocol.

◆ store_string() [2/2]

bool Protocol_local::store_string ( const char *  str,
size_t  length,
const CHARSET_INFO src_cs,
const CHARSET_INFO dst_cs 
)
private

Store a string value in a result set column, optionally having converted it to character_set_results.

◆ store_time()

bool Protocol_local::store_time ( const MYSQL_TIME time,
uint  precision 
)
overrideprotectedvirtual

Store MYSQL_TIME (in binary format)

Implements Protocol.

◆ store_tiny()

bool Protocol_local::store_tiny ( longlong  from,
uint32   
)
overrideprotectedvirtual

Store a tiny int as is (1 byte) in a result set column.

Implements Protocol.

◆ type()

enum enum_protocol_type Protocol_local::type ( ) const
inlineoverrideprotectedvirtual

Implements Protocol.

Member Data Documentation

◆ m_column_count

size_t Protocol_local::m_column_count
private

◆ m_connection

Ed_connection* Protocol_local::m_connection
private

◆ m_current_column

Ed_column* Protocol_local::m_current_column
private

◆ m_current_row

Ed_column* Protocol_local::m_current_row
private

◆ m_fields

Ed_row* Protocol_local::m_fields
private

◆ m_rset

List<Ed_row>* Protocol_local::m_rset
private

◆ m_rset_root

MEM_ROOT Protocol_local::m_rset_root
private

◆ m_send_metadata

bool Protocol_local::m_send_metadata
private

◆ m_thd

THD* Protocol_local::m_thd
private

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