MySQL 8.3.0
Source Code Documentation
protocol_callback.h
Go to the documentation of this file.
1/* Copyright (c) 2015, 2023, 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 "my_command.h"
36#include "my_inttypes.h"
38#include "mysql/strings/dtoa.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:574
Dynamic parameters used as placeholders ('?') inside prepared statements.
Definition: item.h:4757
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: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:54
int read_packet() override
Forces read of packet from the connection.
Definition: protocol_callback.cc:63
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: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:421
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:85
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: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: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:425
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:424
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:100
@ PROTOCOL_PLUGIN
Definition: protocol.h:106
Definition: field.h:4638
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:94
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:272
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:422
Definition: mysql_time.h:81
Definition: service_command.h:327
Definition: com_data.h:96
Vio Lite.
enum_vio_type
Definition: violite.h:78