MySQL 9.0.0
Source Code Documentation
Protocol_callback Class Referencefinal

#include <protocol_callback.h>

Inheritance diagram for Protocol_callback:
[legend]

Public Member Functions

 Protocol_callback (const struct st_command_service_cbs *cbs, enum cs_text_or_binary t_or_b, void *cbs_ctx)
 
int read_packet () override
 Forces read of packet from the connection. More...
 
int get_command (COM_DATA *com_data, enum_server_command *cmd) override
 Reads from the line and parses the data into union COM_DATA. More...
 
enum enum_protocol_type type () const override
 Returns the type of the protocol. More...
 
enum enum_vio_type connection_type () const override
 Returns the type of the connection. More...
 
bool store_null () override
 Sends null value. More...
 
bool store_tiny (longlong from, uint32) override
 Sends TINYINT value. More...
 
bool store_short (longlong from, uint32) override
 Sends SMALLINT value. More...
 
bool store_long (longlong from, uint32) override
 Sends INT/INTEGER value. More...
 
bool store_longlong (longlong from, bool is_unsigned, uint32) override
 Sends BIGINT value. More...
 
bool store_decimal (const my_decimal *d, uint, uint) override
 Sends DECIMAL value. More...
 
bool store_string (const char *from, size_t length, const CHARSET_INFO *fromcs) override
 Sends string (CHAR/VARCHAR/TEXT/BLOB) value. More...
 
bool store_float (float from, uint32 decimals, uint32) override
 Sends FLOAT value. More...
 
bool store_double (double from, uint32 decimals, uint32) override
 Sends DOUBLE value. More...
 
bool store_datetime (const MYSQL_TIME &time, uint precision) override
 Sends DATETIME value. More...
 
bool store_date (const MYSQL_TIME &time) override
 Sends DATE value. More...
 
bool store_time (const MYSQL_TIME &time, uint precision) override
 Sends TIME value. More...
 
bool store_field (const Field *field) override
 Sends Field. More...
 
ulong get_client_capabilities () override
 Returns the capabilities supported by the protocol. More...
 
bool has_client_capability (unsigned long capability) override
 Checks if the protocol supports a capability. More...
 
void start_row () override
 Called BEFORE sending data row or before field_metadata. More...
 
bool end_row () override
 Called AFTER sending data row or before field_metadata. More...
 
void abort_row () override
 Called when a row is aborted. More...
 
void end_partial_result_set () override
 Called in case of error while sending data. More...
 
int shutdown (bool server_shutdown=false) override
 Called when the server shuts down the connection (THD is being destroyed). More...
 
bool connection_alive () const override
 This function always returns true as in many places in the server this is a prerequisite for continuing operations. More...
 
uint get_rw_status () override
 Should return protocol's reading/writing status. More...
 
bool get_compression () override
 Checks if compression is enabled. More...
 
char * get_compression_algorithm () override
 Checks if compression is enabled and return compression method name. More...
 
uint get_compression_level () override
 Checks if compression is enabled and return compression level. More...
 
bool start_result_metadata (uint num_cols, uint flags, const CHARSET_INFO *resultcs) override
 Called BEFORE sending metadata. More...
 
bool send_field_metadata (Send_field *field, const CHARSET_INFO *cs) override
 Sends metadata of one field. More...
 
bool end_result_metadata () override
 Called AFTER sending metadata. More...
 
bool send_ok (uint server_status, uint warn_count, ulonglong affected_rows, ulonglong last_insert_id, const char *message) override
 Sends OK. More...
 
bool send_eof (uint server_status, uint warn_count) override
 Sends end of file. More...
 
bool send_error (uint sql_errno, const char *err_msg, const char *sql_state) override
 Sends error. 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...
 
bool send_parameters (List< Item_param > *parameters, bool is_sql_prepare) override
 Sends the OUT-parameters to the client. More...
 
bool flush () override
 Used for the classic protocol. More...
 
virtual bool store_long (longlong from, uint32 zerofill)=0
 
bool store_long (longlong from)
 
virtual bool store_short (longlong from, uint32 zerofill)=0
 
bool store_short (longlong from)
 
- 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)
 

Private Member Functions

bool set_variables_from_parameters (List< Item_param > *parameters)
 Set output parameters to variables bound at PS execution. More...
 

Private Attributes

void * callbacks_ctx
 
struct st_command_service_cbs callbacks
 
unsigned long client_capabilities
 
bool client_capabilities_set
 
enum cs_text_or_binary text_or_binary
 
bool in_meta_sending
 

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

Protocol_callback::Protocol_callback ( const struct st_command_service_cbs cbs,
enum cs_text_or_binary  t_or_b,
void *  cbs_ctx 
)
inline

Member Function Documentation

◆ abort_row()

void Protocol_callback::abort_row ( )
overridevirtual

Called when a row is aborted.

Implements Protocol.

◆ connection_alive()

bool Protocol_callback::connection_alive ( ) const
overridevirtual

This function always returns true as in many places in the server this is a prerequisite for continuing operations.

Returns if the connection is alive or dead.

Return values
truealive
Note
If there's no callback provided, this function always returns true because, in many places in the server, this is a prerequisite for continuing operations. If the user is connection bound, a callback function should be provided, to have a possibility to stop execution of operations when the user disconnected.
Returns
true connected false disconnected

Implements Protocol.

◆ connection_type()

enum enum_vio_type Protocol_callback::connection_type ( ) const
overridevirtual

Returns the type of the connection.

Returns
enum enum_vio_type
VIO_TYPE_PLUGIN

Implements Protocol.

◆ end_partial_result_set()

void Protocol_callback::end_partial_result_set ( )
overridevirtual

Called in case of error while sending data.

Implements Protocol.

◆ end_result_metadata()

bool Protocol_callback::end_result_metadata ( )
overridevirtual

Called AFTER sending metadata.

Return values
truefailure
falsesuccess
Returns
true failure false success

Implements Protocol.

◆ end_row()

bool Protocol_callback::end_row ( )
overridevirtual

Called AFTER sending data row or before field_metadata.

Called AFTER sending all fields of a row, or after field_metadata().

Please read the big comment in start_row() for explanation why in_meta_sending is used.

Returns
true ok false not ok

Implements Protocol.

◆ flush()

bool Protocol_callback::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_callback::get_client_capabilities ( )
overridevirtual

Returns the capabilities supported by the protocol.

Implements Protocol.

◆ get_command()

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

Reads from the line and parses the data into union COM_DATA.

Practically does nothing.

Returns
bytes read
Return values
-1failure

See the comment of read_packet(). Always returns -1.

Returns
-1

Implements Protocol.

◆ get_compression()

bool Protocol_callback::get_compression ( )
overridevirtual

Checks if compression is enabled.

Should check if compression is enabled.

Return values
trueenabled
falsedisabled

Returns always false (no compression)

Returns
false disabled

Implements Protocol.

◆ get_compression_algorithm()

char * Protocol_callback::get_compression_algorithm ( )
overridevirtual

Checks if compression is enabled and return compression method name.

Always returns null.

Returns
algorithm name if compression is supported else null
null compression not supported

Implements Protocol.

◆ get_compression_level()

uint Protocol_callback::get_compression_level ( )
overridevirtual

Checks if compression is enabled and return compression level.

Always returns 0.

Returns
compression level if compression is supported else 0
compression not supported

Implements Protocol.

◆ get_rw_status()

uint Protocol_callback::get_rw_status ( )
overridevirtual

Should return protocol's reading/writing status.

Returns 0 (idle) as it this is the best guess that can be made as there is no callback for get_rw_status().

Returns 0 (idle) as it this is the best guess that can be made as there is no callback for get_rw_status().

Returns
0

Implements Protocol.

◆ has_client_capability()

bool Protocol_callback::has_client_capability ( unsigned long  capability)
overridevirtual

Checks if the protocol supports a capability.

Parameters
capabilitythe capability
Return values
truesupports
falsedoes not support

Implements Protocol.

◆ read_packet()

int Protocol_callback::read_packet ( )
overridevirtual

Forces read of packet from the connection.

Practically does nothing.

Returns
bytes read
Return values
-1failure

Returns -1, error, for the case this will be called. It should happen. read_packet() is called by get_command() which in turn is called by do_command() in sql_parse. After that COM_DATA is filled with proper info that in turn is passed to dispatch_command(). The Command service doesn't use do_command() but dispatch_command() and passes COM_DATA directly from the user(plugin).

Returns
-1 failure

Implements Protocol.

◆ send_eof()

bool Protocol_callback::send_eof ( uint  server_status,
uint  warn_count 
)
overridevirtual

Sends end of file.

This will be called once all data has been sent.

Parameters
server_statusBit field with different statuses. See SERVER_STATUS_*
warn_countThe warning count generated by the execution of the statement.
Return values
truefailure
falsesuccess
Returns
true failure false success

Implements Protocol.

◆ send_error()

bool Protocol_callback::send_error ( uint  sql_errno,
const char *  err_msg,
const char *  sql_state 
)
overridevirtual

Sends error.

Parameters
sql_errnoError number, beginning from 1000
err_msgThe error message
sql_stateThe SQL state - 5 char string
Return values
truefailure
falsesuccess
Returns
true failure false success

Implements Protocol.

◆ send_field_metadata()

bool Protocol_callback::send_field_metadata ( Send_field field,
const CHARSET_INFO cs 
)
overridevirtual

Sends metadata of one field.

Called for every column in the result set.

Parameters
fieldField's metadata
csCharset
Return values
truefailure
falsesuccess

Called for every column in the result set.

Returns
true failure false success

Implements Protocol.

◆ send_ok()

bool Protocol_callback::send_ok ( uint  server_status,
uint  warn_count,
ulonglong  affected_rows,
ulonglong  last_insert_id,
const char *  message 
)
overridevirtual

Sends OK.

Parameters
server_statusBit field with different statuses. See SERVER_STATUS_*
warn_countWarning count from the execution
affected_rowsRows changed/deleted during the operation
last_insert_idID of the last insert row, which has AUTO_INCROMENT column
messageTextual message from the execution. May be NULL.
Return values
truefailure
falsesuccess
Returns
true failure false success

Implements Protocol.

◆ send_parameters()

bool Protocol_callback::send_parameters ( List< Item_param > *  parameters,
bool  is_sql_prepare 
)
overridevirtual

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.

◆ set_variables_from_parameters()

bool Protocol_callback::set_variables_from_parameters ( List< Item_param > *  parameters)
private

Set output parameters to variables bound at PS execution.

This method handles the case when preparing and executing was done through SQL (not by COM_STMT_PREPARE/COM_STMT_EXECUTE) in which output parameters are not going to be send to client (or 'st_command_service_cbs'), instead they will set concrete session variables.

Parameters
parametersList of PS/SP parameters (both input and output).
Return values
falsesuccess
truefailure

◆ shutdown()

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

Called when the server shuts down the connection (THD is being destroyed).

In this regard, this is also called when the server shuts down. The callback implementor can differentiate between those 2 events by inspecting the shutdown_type parameter.

Parameters
server_shutdownWhether this is a normal connection shutdown (false) or a server shutdown (true).
Return values
0success
!0failure

In this regard, this is also called when the server shuts down. The callback implementor can differentiate between those 2 events by inspecting the server_shutdown parameter.

Parameters
server_shutdownWhether this is a normal connection shutdown (false) or a server shutdown (true).
Returns
0 success !0 failure

Implements Protocol.

◆ start_result_metadata()

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

Called BEFORE sending metadata.

Parameters
num_colsNumber of columns in the result set
flagsflags to be used to alter the way the messages are sent to the client, see Protocol class for SEND_NUM_ROWS, SEND_DEFAULTS, SEND_EOF
resultcsThe character set of the results. Can be different from the one in the field metadata.
Return values
truefailure
falsesuccess
Returns
true failure false success

Implements Protocol.

◆ start_row()

void Protocol_callback::start_row ( )
overridevirtual

Called BEFORE sending data row or before field_metadata.

Implements Protocol.

◆ store_date()

bool Protocol_callback::store_date ( const MYSQL_TIME time)
overridevirtual

Sends DATE value.

Parameters
timevalue
Return values
falsesuccess
truefailure

Implements Protocol.

◆ store_datetime()

bool Protocol_callback::store_datetime ( const MYSQL_TIME time,
uint  precision 
)
overridevirtual

Sends DATETIME value.

Parameters
timevalue
precisionfractional seconds precision. 0 ... DATETIME_MAX_DECIMALS
Return values
falsesuccess
truefailure

Implements Protocol.

◆ store_decimal()

bool Protocol_callback::store_decimal ( const my_decimal d,
uint  ,
uint   
)
overridevirtual

Sends DECIMAL value.

Parameters
dvalue
Return values
falsesuccess
truefailure
Parameters
dvalue
Returns
false success true failure

Implements Protocol.

◆ store_double()

bool Protocol_callback::store_double ( double  from,
uint32  decimals,
uint32   
)
overridevirtual

Sends DOUBLE value.

Parameters
fromvalue
decimalsnumber of digits to use after decimal point, unless it is DECIMAL_NOT_SPECIFIED
Return values
falsesuccess
truefailure

Implements Protocol.

◆ store_field()

bool Protocol_callback::store_field ( const Field field)
overridevirtual

Sends Field.

Parameters
fieldthe field to be sent through the protocol
Return values
falsesuccess
truefailure

Implements Protocol.

◆ store_float()

bool Protocol_callback::store_float ( float  from,
uint32  decimals,
uint32   
)
overridevirtual

Sends FLOAT value.

Parameters
fromvalue
decimalsnumber of digits to use after decimal point, unless it is DECIMAL_NOT_SPECIFIED
Return values
falsesuccess
truefailure

Implements Protocol.

◆ store_long() [1/3]

bool Protocol::store_long ( longlong  from)
inline

◆ store_long() [2/3]

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

Implements Protocol.

◆ store_long() [3/3]

bool Protocol_callback::store_long ( longlong  from,
uint32   
)
overridevirtual

Sends INT/INTEGER value.

Parameters
fromvalue
Return values
falsesuccess
truefailure

Implements Protocol.

◆ store_longlong()

bool Protocol_callback::store_longlong ( longlong  from,
bool  is_unsigned,
uint32   
)
overridevirtual

Sends BIGINT value.

Parameters
fromvalue
is_unsignedfrom is unsigned
Return values
falsesuccess
truefailure

Implements Protocol.

◆ store_null()

bool Protocol_callback::store_null ( )
overridevirtual

Sends null value.

Return values
falsesuccess
truefailure

Implements Protocol.

◆ store_ps_status()

bool Protocol_callback::store_ps_status ( ulong  stmt_id,
uint  column_count,
uint  param_count,
ulong  cond_count 
)
overridevirtual

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() [1/3]

bool Protocol::store_short ( longlong  from)
inline

◆ store_short() [2/3]

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

Implements Protocol.

◆ store_short() [3/3]

bool Protocol_callback::store_short ( longlong  from,
uint32   
)
overridevirtual

Sends SMALLINT value.

Parameters
fromvalue
Return values
falsesuccess
truefailure

Implements Protocol.

◆ store_string()

bool Protocol_callback::store_string ( const char *  from,
size_t  length,
const CHARSET_INFO fromcs 
)
overridevirtual

Sends string (CHAR/VARCHAR/TEXT/BLOB) value.

Return values
falsesuccess
truefailure

Implements Protocol.

◆ store_time()

bool Protocol_callback::store_time ( const MYSQL_TIME time,
uint  precision 
)
overridevirtual

Sends TIME value.

Parameters
timevalue
precisionfractional seconds precision. 0 ... DATETIME_MAX_DECIMALS
Return values
falsesuccess
truefailure

Implements Protocol.

◆ store_tiny()

bool Protocol_callback::store_tiny ( longlong  from,
uint32   
)
overridevirtual

Sends TINYINT value.

Parameters
fromvalue
Return values
falsesuccess
truefailure

Implements Protocol.

◆ type()

enum enum_protocol_type Protocol_callback::type ( ) const
inlineoverridevirtual

Returns the type of the protocol.

Return values
falsesuccess
truefailure

Implements Protocol.

Member Data Documentation

◆ callbacks

struct st_command_service_cbs Protocol_callback::callbacks
private

◆ callbacks_ctx

void* Protocol_callback::callbacks_ctx
private

◆ client_capabilities

unsigned long Protocol_callback::client_capabilities
private

◆ client_capabilities_set

bool Protocol_callback::client_capabilities_set
private

◆ in_meta_sending

bool Protocol_callback::in_meta_sending
private

◆ text_or_binary

enum cs_text_or_binary Protocol_callback::text_or_binary
private

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