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