MySQL 8.0.32
Source Code Documentation
protocol_callback.h
Go to the documentation of this file.
1/* Copyright (c) 2015, 2022, Oracle and/or its affiliates.
2
3 This program is free software; you can redistribute it and/or modify
4 it under the terms of the GNU General Public License, version 2.0,
5 as published by the Free Software Foundation.
6
7 This program is also distributed with certain software (including
8 but not limited to OpenSSL) that is licensed under separate terms,
9 as designated in a particular file or component or in included license
10 documentation. The authors of MySQL hereby grant you an additional
11 permission to link the program and your derivative works with the
12 separately licensed software that they have included with MySQL.
13
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License, version 2.0, for more details.
18
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
22
23#ifndef PROTOCOL_CALLBACK_INCLUDED
24#define PROTOCOL_CALLBACK_INCLUDED
25
26/**
27@file
28 Interface of the Protocol_callback class, which is used by the Command
29 service as proxy protocol.
30*/
31
32#include <stddef.h>
33#include <sys/types.h>
34
35#include "m_ctype.h"
36#include "my_command.h"
37#include "my_inttypes.h"
39#include "mysql_time.h"
40#include "sql/protocol.h"
41#include "violite.h"
42
43class Item_param;
44class Send_field;
45class String;
46class my_decimal;
47template <class T>
48class List;
49union COM_DATA;
50
51class Protocol_callback final : public Protocol {
52 public:
54 enum cs_text_or_binary t_or_b, void *cbs_ctx)
55 : callbacks_ctx(cbs_ctx),
56 callbacks(*cbs),
59 text_or_binary(t_or_b),
60 in_meta_sending(false) {}
61
62 /**
63 Forces read of packet from the connection
64
65 @return bytes read
66 @retval -1 failure
67 */
68 int read_packet() override;
69
70 /**
71 Reads from the line and parses the data into union COM_DATA
72
73 @return bytes read
74 @retval -1 failure
75 */
76 int get_command(COM_DATA *com_data, enum_server_command *cmd) override;
77
78 /**
79 Returns the type of the protocol
80
81 @retval false success
82 @retval true failure
83 */
84 enum enum_protocol_type type() const override { return PROTOCOL_PLUGIN; }
85
86 /**
87 Returns the type of the connection
88
89 @return enum enum_vio_type
90 */
91 enum enum_vio_type connection_type() const override;
92
93 /**
94 Sends null value
95
96 @retval false success
97 @retval true failure
98 */
99 bool store_null() override;
100
101 /**
102 Sends TINYINT value
103
104 @param from value
105
106 @retval false success
107 @retval true failure
108 */
109 bool store_tiny(longlong from, uint32) override;
110
111 /**
112 Sends SMALLINT value
113
114 @param from value
115
116 @retval false success
117 @retval true failure
118 */
119 bool store_short(longlong from, uint32) override;
120
121 /**
122 Sends INT/INTEGER value
123
124 @param from value
125
126 @retval false success
127 @retval true failure
128 */
129 bool store_long(longlong from, uint32) override;
130
131 /**
132 Sends BIGINT value
133
134 @param from value
135 @param is_unsigned from is unsigned
136
137 @retval false success
138 @retval true failure
139 */
140 bool store_longlong(longlong from, bool is_unsigned, uint32) override;
141
142 /**
143 Sends DECIMAL value
144
145 @param d value
146
147 @retval false success
148 @retval true failure
149 */
150 bool store_decimal(const my_decimal *d, uint, uint) override;
151
152 /**
153 Sends string (CHAR/VARCHAR/TEXT/BLOB) value
154
155 @retval false success
156 @retval true failure
157 */
158 bool store_string(const char *from, size_t length,
159 const CHARSET_INFO *fromcs) override;
160
161 /**
162 Sends FLOAT value
163
164 @param from value
165 @param decimals number of digits to use after decimal point, unless it is
166 DECIMAL_NOT_SPECIFIED
167
168 @retval false success
169 @retval true failure
170 */
171 bool store_float(float from, uint32 decimals, uint32) override;
172
173 /**
174 Sends DOUBLE value
175
176 @param from value
177 @param decimals number of digits to use after decimal point, unless it is
178 DECIMAL_NOT_SPECIFIED
179
180 @retval false success
181 @retval true failure
182 */
183 bool store_double(double from, uint32 decimals, uint32) override;
184
185 /**
186 Sends DATETIME value
187
188 @param time value
189 @param precision fractional seconds precision. 0 ... DATETIME_MAX_DECIMALS
190
191 @retval false success
192 @retval true failure
193 */
194 bool store_datetime(const MYSQL_TIME &time, uint precision) override;
195
196 /**
197 Sends DATE value
198
199 @param time value
200
201 @retval false success
202 @retval true failure
203 */
204 bool store_date(const MYSQL_TIME &time) override;
205
206 /**
207 Sends TIME value
208
209 @param time value
210 @param precision fractional seconds precision. 0 ... DATETIME_MAX_DECIMALS
211
212 @retval false success
213 @retval true failure
214 */
215 bool store_time(const MYSQL_TIME &time, uint precision) override;
216
217 /**
218 Sends Field
219
220 @param field the field to be sent through the protocol
221
222 @retval false success
223 @retval true failure
224 */
225 bool store_field(const Field *field) override;
226
227 /**
228 Returns the capabilities supported by the protocol
229 */
230 ulong get_client_capabilities() override;
231
232 /**
233 Checks if the protocol supports a capability
234
235 @param capability the capability
236
237 @retval true supports
238 @retval false does not support
239 */
240 bool has_client_capability(unsigned long capability) override;
241
242 /**
243 Called BEFORE sending data row or before field_metadata
244 */
245 void start_row() override;
246
247 /**
248 Called AFTER sending data row or before field_metadata
249 */
250 bool end_row() override;
251
252 /**
253 Called when a row is aborted
254 */
255 void abort_row() override;
256
257 /**
258 Called in case of error while sending data
259 */
260 void end_partial_result_set() override;
261
262 /**
263 Called when the server shuts down the connection (THD is being destroyed).
264 In this regard, this is also called when the server shuts down. The callback
265 implementor can differentiate between those 2 events by inspecting the
266 shutdown_type parameter.
267
268 @param server_shutdown Whether this is a normal connection shutdown (false)
269 or a server shutdown (true).
270
271 @retval 0 success
272 @retval !0 failure
273 */
274 int shutdown(bool server_shutdown = false) override;
275
276 /**
277 This function always returns true as in many places in the server this
278 is a prerequisite for continuing operations.
279
280 @retval true alive
281 */
282 bool connection_alive() const override;
283
284 /**
285 Should return protocol's reading/writing status. Returns 0 (idle) as it
286 this is the best guess that can be made as there is no callback for
287 get_rw_status().
288 */
289 uint get_rw_status() override;
290
291 /**
292 Checks if compression is enabled
293
294 @retval true enabled
295 @retval false disabled
296 */
297 bool get_compression() override;
298
299 /**
300 Checks if compression is enabled and return compression method name
301
302 @return algorithm name if compression is supported else null
303 */
304 char *get_compression_algorithm() override;
305
306 /**
307 Checks if compression is enabled and return compression level.
308
309 @return compression level if compression is supported else 0
310 */
311 uint get_compression_level() override;
312
313 /**
314 Called BEFORE sending metadata
315
316 @param num_cols Number of columns in the result set
317 @param flags flags to be used to alter the way the messages are sent to
318 the client, see Protocol class for SEND_NUM_ROWS, SEND_DEFAULTS,
319 SEND_EOF
320 @param resultcs The character set of the results. Can be different from the
321 one in the field metadata.
322
323 @retval true failure
324 @retval false success
325 */
326 bool start_result_metadata(uint num_cols, uint flags,
327 const CHARSET_INFO *resultcs) override;
328
329 /**
330 Sends metadata of one field. Called for every column in the result set.
331
332 @param field Field's metadata
333 @param cs Charset
334
335 @retval true failure
336 @retval false success
337 */
338 bool send_field_metadata(Send_field *field, const CHARSET_INFO *cs) override;
339
340 /**
341 Called AFTER sending metadata
342
343 @retval true failure
344 @retval false success
345 */
346 bool end_result_metadata() override;
347
348 /**
349 Sends OK
350
351 @param server_status Bit field with different statuses. See SERVER_STATUS_*
352 @param warn_count Warning count from the execution
353 @param affected_rows Rows changed/deleted during the operation
354 @param last_insert_id ID of the last insert row, which has AUTO_INCROMENT
355 column
356 @param message Textual message from the execution. May be NULL.
357
358 @retval true failure
359 @retval false success
360 */
361 bool send_ok(uint server_status, uint warn_count, ulonglong affected_rows,
362 ulonglong last_insert_id, const char *message) override;
363
364 /**
365 Sends end of file.
366
367
368 This will be called once all data has been sent.
369
370 @param server_status Bit field with different statuses. See SERVER_STATUS_*
371 @param warn_count The warning count generated by the execution of the
372 statement.
373
374 @retval true failure
375 @retval false success
376 */
377 bool send_eof(uint server_status, uint warn_count) override;
378
379 /**
380 Sends error
381
382 @param sql_errno Error number, beginning from 1000
383 @param err_msg The error message
384 @param sql_state The SQL state - 5 char string
385
386 @retval true failure
387 @retval false success
388 */
389 bool send_error(uint sql_errno, const char *err_msg,
390 const char *sql_state) override;
391
392 bool store_ps_status(ulong stmt_id, uint column_count, uint param_count,
393 ulong cond_count) override;
394
395 bool send_parameters(List<Item_param> *parameters,
396 bool is_sql_prepare) override;
397 bool flush() override;
398
401
402 private:
403 /**
404 Set output parameters to variables bound at PS execution.
405
406 This method handles the case when preparing and executing was done
407 through SQL (not by COM_STMT_PREPARE/COM_STMT_EXECUTE) in which
408 output parameters are not going to be send to client (or
409 'st_command_service_cbs'), instead they will set concrete session
410 variables.
411
412 @param parameters List of PS/SP parameters (both input and output).
413
414 @retval false success
415 @retval true failure
416 */
418
421 unsigned long client_capabilities;
425};
426
427#endif /* PROTOCOL_CALLBACK_INCLUDED */
Definition: field.h:574
Dynamic parameters used as placeholders ('?') inside prepared statements.
Definition: item.h:4512
Definition: sql_list.h:433
Definition: protocol_callback.h:51
bool store_date(const MYSQL_TIME &time) override
Sends DATE value.
Definition: protocol_callback.cc:153
bool connection_alive() const override
This function always returns true as in many places in the server this is a prerequisite for continui...
Definition: protocol_callback.cc:278
enum enum_vio_type connection_type() const override
Returns the type of the connection.
Definition: protocol_callback.cc:82
Protocol_callback(const struct st_command_service_cbs *cbs, enum cs_text_or_binary t_or_b, void *cbs_ctx)
Definition: protocol_callback.h:53
int read_packet() override
Forces read of packet from the connection.
Definition: protocol_callback.cc:63
bool client_capabilities_set
Definition: protocol_callback.h:422
ulong get_client_capabilities() override
Returns the capabilities supported by the protocol.
Definition: protocol_callback.cc:180
bool send_error(uint sql_errno, const char *err_msg, const char *sql_state) override
Sends error.
Definition: protocol_callback.cc:422
bool store_double(double from, uint32 decimals, uint32) override
Sends DOUBLE value.
Definition: protocol_callback.cc:141
bool set_variables_from_parameters(List< Item_param > *parameters)
Set output parameters to variables bound at PS execution.
Definition: protocol_callback.cc:499
int get_command(COM_DATA *com_data, enum_server_command *cmd) override
Reads from the line and parses the data into union COM_DATA.
Definition: protocol_callback.cc:72
bool send_field_metadata(Send_field *field, const CHARSET_INFO *cs) override
Sends metadata of one field.
Definition: protocol_callback.cc:342
bool store_field(const Field *field) override
Sends Field.
Definition: protocol_callback.cc:164
bool get_compression() override
Checks if compression is enabled.
Definition: protocol_callback.cc:301
bool store_time(const MYSQL_TIME &time, uint precision) override
Sends TIME value.
Definition: protocol_callback.cc:158
bool send_ok(uint server_status, uint warn_count, ulonglong affected_rows, ulonglong last_insert_id, const char *message) override
Sends OK.
Definition: protocol_callback.cc:390
char * get_compression_algorithm() override
Checks if compression is enabled and return compression method name.
Definition: protocol_callback.cc:309
bool end_result_metadata() override
Called AFTER sending metadata.
Definition: protocol_callback.cc:370
bool send_parameters(List< Item_param > *parameters, bool is_sql_prepare) override
Sends the OUT-parameters to the client.
Definition: protocol_callback.cc:451
int shutdown(bool server_shutdown=false) override
Called when the server shuts down the connection (THD is being destroyed).
Definition: protocol_callback.cc:259
void start_row() override
Called BEFORE sending data row or before field_metadata.
Definition: protocol_callback.cc:196
uint get_rw_status() override
Should return protocol's reading/writing status.
Definition: protocol_callback.cc:293
bool send_eof(uint server_status, uint warn_count) override
Sends end of file.
Definition: protocol_callback.cc:408
struct st_command_service_cbs callbacks
Definition: protocol_callback.h:420
bool end_row() override
Called AFTER sending data row or before field_metadata.
Definition: protocol_callback.cc:224
bool start_result_metadata(uint num_cols, uint flags, const CHARSET_INFO *resultcs) override
Called BEFORE sending metadata.
Definition: protocol_callback.cc:326
bool store_longlong(longlong from, bool is_unsigned, uint32) override
Sends BIGINT value.
Definition: protocol_callback.cc:107
enum enum_protocol_type type() const override
Returns the type of the protocol.
Definition: protocol_callback.h:84
uint get_compression_level() override
Checks if compression is enabled and return compression level.
Definition: protocol_callback.cc:317
bool store_datetime(const MYSQL_TIME &time, uint precision) override
Sends DATETIME value.
Definition: protocol_callback.cc:147
bool store_null() override
Sends null value.
Definition: protocol_callback.cc:86
void abort_row() override
Called when a row is aborted.
Definition: protocol_callback.cc:234
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.
Definition: protocol_callback.cc:429
unsigned long client_capabilities
Definition: protocol_callback.h:421
void * callbacks_ctx
Definition: protocol_callback.h:419
bool store_string(const char *from, size_t length, const CHARSET_INFO *fromcs) override
Sends string (CHAR/VARCHAR/TEXT/BLOB) value.
Definition: protocol_callback.cc:128
bool store_float(float from, uint32 decimals, uint32) override
Sends FLOAT value.
Definition: protocol_callback.cc:135
bool in_meta_sending
Definition: protocol_callback.h:424
bool flush() override
Used for the classic protocol.
Definition: protocol_callback.cc:399
bool store_short(longlong from, uint32) override
Sends SMALLINT value.
Definition: protocol_callback.cc:97
enum cs_text_or_binary text_or_binary
Definition: protocol_callback.h:423
void end_partial_result_set() override
Called in case of error while sending data.
Definition: protocol_callback.cc:241
bool store_long(longlong from, uint32) override
Sends INT/INTEGER value.
Definition: protocol_callback.cc:102
bool store_decimal(const my_decimal *d, uint, uint) override
Sends DECIMAL value.
Definition: protocol_callback.cc:123
bool has_client_capability(unsigned long capability) override
Checks if the protocol supports a capability.
Definition: protocol_callback.cc:188
bool store_tiny(longlong from, uint32) override
Sends TINYINT value.
Definition: protocol_callback.cc:92
Definition: protocol.h:32
virtual bool store_short(longlong from, uint32 zerofill)=0
virtual bool store_long(longlong from, uint32 zerofill)=0
enum_protocol_type
Enum used by type() to specify the protocol type.
Definition: protocol.h:98
@ PROTOCOL_PLUGIN
Definition: protocol.h:104
Definition: field.h:4555
Using this class is fraught with peril, and you need to be very careful when doing so.
Definition: sql_string.h:166
my_decimal class limits 'decimal_t' type to what we need in MySQL.
Definition: my_decimal.h:93
static int flags[50]
Definition: hp_test1.cc:39
A better implementation of the UNIX ctype(3) library.
enum_server_command
A list of all MySQL protocol commands.
Definition: my_command.h:47
Some integer typedefs for easier portability.
unsigned long long int ulonglong
Definition: my_inttypes.h:55
long long int longlong
Definition: my_inttypes.h:54
uint32_t uint32
Definition: my_inttypes.h:66
Time declarations shared between the server and client API: you should not add anything to this heade...
constexpr value_type is_unsigned
Definition: classic_protocol_constants.h:270
Definition: commit_order_queue.h:33
bool length(const dd::Spatial_reference_system *srs, const Geometry *g1, double *length, bool *null) noexcept
Computes the length of linestrings and multilinestrings.
Definition: length.cc:75
Header file for the Command service.
cs_text_or_binary
Definition: service_command.h:388
Definition: m_ctype.h:382
Definition: mysql_time.h:81
Definition: service_command.h:327
unsigned int uint
Definition: uca-dump.cc:29
Definition: com_data.h:111
Vio Lite.
enum_vio_type
Definition: violite.h:78