MySQL 9.1.0
Source Code Documentation
service_command.h
Go to the documentation of this file.
1#ifndef MYSQL_SERVICE_COMMAND_INCLUDED
2#define MYSQL_SERVICE_COMMAND_INCLUDED
3/* Copyright (c) 2015, 2024, Oracle and/or its affiliates.
4
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License, version 2.0,
7 as published by the Free Software Foundation.
8
9 This program is designed to work with certain software (including
10 but not limited to OpenSSL) that is licensed under separate terms,
11 as designated in a particular file or component or in included license
12 documentation. The authors of MySQL hereby grant you an additional
13 permission to link the program and your derivative works with the
14 separately licensed software that they have either included with
15 the program or referenced in the documentation.
16
17 This program is distributed in the hope that it will be useful,
18 but WITHOUT ANY WARRANTY; without even the implied warranty of
19 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 GNU General Public License, version 2.0, for more details.
21
22 You should have received a copy of the GNU General Public License
23 along with this program; if not, write to the Free Software
24 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
25
26/**
27 @file include/mysql/service_command.h
28 Header file for the Command service. This service is to provide means
29 of executing different commands, like COM_QUERY, COM_STMT_PREPARE,
30 in the server.
31*/
32
33#include "mysql/com_data.h"
35
36#include "decimal.h"
37#include "mysql_time.h"
38#ifndef MYSQL_ABI_CHECK
39#include <stdint.h> /* uint32_t */
40#include "field_types.h"
42#endif
43
44/* POD structure for the field metadata from the server */
46 const char *db_name;
47 const char *table_name;
48 const char *org_table_name;
49 const char *col_name;
50 const char *org_col_name;
51 unsigned long length;
52 unsigned int charsetnr;
53 unsigned int flags;
54 unsigned int decimals;
56};
57
58/**
59 Indicates beginning of metadata for the result set
60
61 @param ctx Plugin's context
62 @param num_cols Number of fields being sent
63 @param flags Flags to alter the metadata sending
64 @param resultcs Charset of the result set
65
66 @note resultcs is the charset in which the data should be encoded before
67 sent to the client. This is the value of the session variable
68 character_set_results. The implementor most probably will need to save
69 this value in the context and use it as "to" charset in get_string().
70
71 In case of CS_BINARY_REPRESENTATION, get_string() receives as a parameter
72 the charset of the string, as it is stored on disk.
73
74 In case of CS_TEXT_REPRESENTATION, the string value might be already a
75 stringified value or non-string data, which is in character_set_results.
76
77 @returns
78 1 an error occurred, server will abort the command
79 0 ok
80*/
81typedef int (*start_result_metadata_t)(void *ctx, uint num_cols, uint flags,
82 const CHARSET_INFO *resultcs);
83
84/**
85 Field metadata is provided via this callback
86
87 @param ctx Plugin's context
88 @param field Field's metadata (see field.h)
89 @param charset Field's charset
90
91 @returns
92 1 an error occurred, server will abort the command
93 0 ok
94*/
95typedef int (*field_metadata_t)(void *ctx, struct st_send_field *field,
96 const CHARSET_INFO *charset);
97
98/**
99 Indicates end of metadata for the result set
100
101 @param ctx Plugin's context
102 @param server_status Status of server (see mysql_com.h, SERVER_STATUS_*)
103 @param warn_count Number of warnings generated during execution to the
104 moment when the metadata is sent.
105 @returns
106 1 an error occurred, server will abort the command
107 0 ok
108*/
109typedef int (*end_result_metadata_t)(void *ctx, uint server_status,
110 uint warn_count);
111
112/**
113 Indicates the beginning of a new row in the result set/metadata
114
115 @param ctx Plugin's context
116
117 @returns
118 1 an error occurred, server will abort the command
119 0 ok
120*/
121typedef int (*start_row_t)(void *ctx);
122
123/**
124 Indicates the end of the current row in the result set/metadata
125
126 @param ctx Plugin's context
127
128 @returns
129 1 an error occurred, server will abort the command
130 0 ok
131*/
132typedef int (*end_row_t)(void *ctx);
133
134/**
135 An error occurred during execution
136
137 This callback indicates that an error occurred during command
138 execution and the partial row should be dropped. Server will raise error
139 and return.
140
141 @param ctx Plugin's context
142*/
143typedef void (*abort_row_t)(void *ctx);
144
145/**
146 Return client's capabilities (see mysql_com.h, CLIENT_*)
147
148 @param ctx Plugin's context
149
150 @return Bitmap of client's capabilities
151*/
152typedef ulong (*get_client_capabilities_t)(void *ctx);
153
154/**
155 Receive NULL value from server
156
157 @param ctx Plugin's context
158
159 @returns
160 1 an error occurred, server will abort the command
161 0 ok
162*/
163typedef int (*get_null_t)(void *ctx);
164
165/**
166 Receive TINY/SHORT/LONG value from server
167
168 @param ctx Plugin's context
169 @param value Value received
170
171 @note In order to know which type exactly was received, the plugin must
172 track the metadata that was sent just prior to the result set.
173
174 @returns
175 1 an error occurred, server will abort the command
176 0 ok
177*/
178typedef int (*get_integer_t)(void *ctx, longlong value);
179
180/**
181 Get LONGLONG value from server
182
183 @param ctx Plugin's context
184 @param value Value received
185 @param is_unsigned TRUE <=> value is unsigned
186
187 @returns
188 1 an error occurred, server will abort the command
189 0 ok
190*/
191typedef int (*get_longlong_t)(void *ctx, longlong value, uint is_unsigned);
192
193/**
194 Receive DECIMAL value from server
195
196 @param ctx Plugin's context
197 @param value Value received
198
199 @returns
200 1 an error occurred, server will abort the command
201 0 ok
202*/
203typedef int (*get_decimal_t)(void *ctx, const decimal_t *value);
204
205/**
206 Receive FLOAT/DOUBLE from server
207
208 @param ctx Plugin's context
209 @param value Value received
210 @param decimals Number of decimals
211
212 @note In order to know which type exactly was received, the plugin must
213 track the metadata that was sent just prior to the result set.
214
215 @returns
216 1 an error occurred, server will abort the command
217 0 ok
218*/
219typedef int (*get_double_t)(void *ctx, double value, uint32_t decimals);
220
221/**
222 Get DATE value from server
223
224 @param ctx Plugin's context
225 @param value Value received
226
227 @returns
228 1 an error occurred during storing, server will abort the command
229 0 ok
230*/
231typedef int (*get_date_t)(void *ctx, const MYSQL_TIME *value);
232
233/**
234 Receive TIME value from server
235
236 @param ctx Plugin's context
237 @param value Value received
238 @param decimals Number of decimals
239
240 @returns
241 1 an error occurred during storing, server will abort the command
242 0 ok
243*/
244typedef int (*get_time_t)(void *ctx, const MYSQL_TIME *value, uint decimals);
245
246/**
247 Receive DATETIME value from server
248
249 @param ctx Plugin's context
250 @param value Value received
251 @param decimals Number of decimals
252
253 @returns
254 1 an error occurred during storing, server will abort the command
255 0 ok
256*/
257typedef int (*get_datetime_t)(void *ctx, const MYSQL_TIME *value,
258 uint decimals);
259
260/**
261 Get STRING value from server
262
263 @param ctx Plugin's context
264 @param value Data
265 @param length Data length
266 @param valuecs Data charset
267
268 @note In case of CS_BINARY_REPRESENTATION, get_string() receives as
269 a parameter the charset of the string, as it is stored on disk.
270
271 In case of CS_TEXT_REPRESENTATION, the string value might be already a
272 stringified value or non-string data, which is in character_set_results.
273
274 @see start_result_metadata()
275
276 @returns
277 1 an error occurred, server will abort the command
278 0 ok
279*/
280typedef int (*get_string_t)(void *ctx, const char *value, size_t length,
281 const CHARSET_INFO *valuecs);
282
283/**
284 Command ended with success
285
286 @param ctx Plugin's context
287 @param server_status Status of server (see mysql_com.h,
288 SERVER_STATUS_*)
289 @param statement_warn_count Number of warnings thrown during execution
290 @param affected_rows Number of rows affected by the command
291 @param last_insert_id Last insert id being assigned during execution
292 @param message A message from server
293*/
294typedef void (*handle_ok_t)(void *ctx, uint server_status,
295 uint statement_warn_count, ulonglong affected_rows,
296 ulonglong last_insert_id, const char *message);
297
298/**
299 Command ended with ERROR
300
301 @param ctx Plugin's context
302 @param sql_errno Error code
303 @param err_msg Error message
304 @param sqlstate SQL state corresponding to the error code
305*/
306typedef void (*handle_error_t)(void *ctx, uint sql_errno, const char *err_msg,
307 const char *sqlstate);
308
309/**
310 Callback for shutdown notification from the server.
311
312 @param ctx Plugin's context
313 @param server_shutdown Whether this is a normal connection shutdown (0) or
314 server shutdown (1).
315*/
316typedef void (*shutdown_t)(void *ctx, int server_shutdown);
317
318/**
319 If the user of the srv_service is bound to a connection,
320 this callback makes it possible to check if the connection is still alive.
321 It should always return true unless the client closed the connection.
322 @returns
323 true if the connection is still alive
324 false otherwise
325 */
326typedef bool (*connection_alive_t)(void *ctx);
327
329 /*
330 For a statement that returns a result, the flow of called callbacks will be:
331
332 start_result_metadata()
333 field_metadata()
334 ....
335 end_result_metadata() (in the classic protocol this generates an EOF packet)
336 start_row()
337 get_xxx()
338 ...
339 end_row()
340 start_row()
341 get_xxx()
342 ...
343 end_row()
344 handle_ok() (with data for an EOF packet)
345
346 For a statement that does NOT return a result, but only status, like
347 INSERT, UPDATE, DELETE, REPLACE, TRUNCATE, CREATE, DROP, ALTER, etc. only
348 handle_ok() will be invoked, in case of success.
349
350 All statements that result in an error will invoke handle_error().
351
352 For statements that return a result set, handle_error() might be invoked
353 even after metadata was sent. This will indicate an error during the
354 execution of the statement.
355 */
356
357 /* Getting metadata */
358
366
367 /* Getting data */
368
378
379 /* Getting execution status */
380
384
385 /* Connection status */
387};
388
390 CS_TEXT_REPRESENTATION = 1, /* Let the server convert everything to string */
391 CS_BINARY_REPRESENTATION = 2, /* Let the server use native types */
392};
393
394extern "C" struct command_service_st {
396 const union COM_DATA *data, const CHARSET_INFO *client_cs,
397 const struct st_command_service_cbs *callbacks,
398 enum cs_text_or_binary text_or_binary,
399 void *service_callbacks_ctx);
401
402#ifdef MYSQL_DYNAMIC_PLUGIN
403
404#define command_service_run_command(t, command, data, cset, cbs, t_or_b, ctx) \
405 command_service->run_command((t), (command), (data), (cset), (cbs), \
406 (t_or_b), (ctx))
407#else
408
409/**
410 Executes a server command in a session.
411
412
413 There are two cases. Execution in a physical thread :
414 1. initialized by the srv_session service
415 2. NOT initialized by the srv_session service
416
417 In case of 1, if there is currently attached session, and it is
418 different from the passed one, the former will be automatically
419 detached. The session to be used for the execution will then be
420 attached. After the command is executed, the attached session will
421 not be detached. It will be detached by a next call to run_command()
422 with another session as parameter. In other words, for all sessions
423 used in a physical thread, there will be at most one in attached
424 state.
425
426 In case of 2, the current state (current_thd) will be
427 preserved. Then the given session will move to attached state and
428 the command will be executed. After the execution the state of the
429 session will be changed to detached and the preserved state
430 (current_thd) will be restored.
431
432 The client charset is used for commands like COM_QUERY and
433 COM_STMT_PREPARE to know how to threat the char* fields. This
434 charset will be used until the next call of run_command when it may
435 be changed again.
436
437 @param session The session
438 @param command The command to be executed.
439 @param data The data needed for the command to be executed
440 @param client_cs The charset for the string data input(COM_QUERY for example)
441 @param callbacks Callbacks to be used by the server to encode data and
442 to communicate with the client (plugin) side.
443 @param text_or_binary Select which representation the server will use for the
444 data passed to the callbacks. For more information
445 @see cs_text_or_binary enum
446 @param service_callbacks_ctx Context passed to the command service callbacks
447
448 @return
449 0 success
450 1 failure
451*/
454 const union COM_DATA *data,
455 const CHARSET_INFO *client_cs,
456 const struct st_command_service_cbs *callbacks,
457 enum cs_text_or_binary text_or_binary,
458 void *service_callbacks_ctx);
459
460#endif /* MYSQL_DYNAMIC_PLUGIN */
461
462#endif
Definition of COM_DATA to be used with the Command service as data input structure.
This file contains the field type.
enum_field_types
Column types for MySQL Note: Keep include/mysql/components/services/bits/stored_program_bits....
Definition: field_types.h:55
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
unsigned long long int ulonglong
Definition: my_inttypes.h:56
long long int longlong
Definition: my_inttypes.h:55
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
const std::string charset("charset")
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
int(* get_double_t)(void *ctx, double value, uint32_t decimals)
Receive FLOAT/DOUBLE from server.
Definition: service_command.h:219
int(* end_result_metadata_t)(void *ctx, uint server_status, uint warn_count)
Indicates end of metadata for the result set.
Definition: service_command.h:109
int(* start_row_t)(void *ctx)
Indicates the beginning of a new row in the result set/metadata.
Definition: service_command.h:121
ulong(* get_client_capabilities_t)(void *ctx)
Return client's capabilities (see mysql_com.h, CLIENT_*)
Definition: service_command.h:152
int(* get_integer_t)(void *ctx, longlong value)
Receive TINY/SHORT/LONG value from server.
Definition: service_command.h:178
bool(* connection_alive_t)(void *ctx)
If the user of the srv_service is bound to a connection, this callback makes it possible to check if ...
Definition: service_command.h:326
int(* end_row_t)(void *ctx)
Indicates the end of the current row in the result set/metadata.
Definition: service_command.h:132
int(* get_time_t)(void *ctx, const MYSQL_TIME *value, uint decimals)
Receive TIME value from server.
Definition: service_command.h:244
struct command_service_st * command_service
int command_service_run_command(MYSQL_SESSION session, enum enum_server_command command, const union COM_DATA *data, const CHARSET_INFO *client_cs, const struct st_command_service_cbs *callbacks, enum cs_text_or_binary text_or_binary, void *service_callbacks_ctx)
Executes a server command in a session.
int(* start_result_metadata_t)(void *ctx, uint num_cols, uint flags, const CHARSET_INFO *resultcs)
Indicates beginning of metadata for the result set.
Definition: service_command.h:81
int(* get_date_t)(void *ctx, const MYSQL_TIME *value)
Get DATE value from server.
Definition: service_command.h:231
cs_text_or_binary
Definition: service_command.h:389
@ CS_BINARY_REPRESENTATION
Definition: service_command.h:391
@ CS_TEXT_REPRESENTATION
Definition: service_command.h:390
int(* get_datetime_t)(void *ctx, const MYSQL_TIME *value, uint decimals)
Receive DATETIME value from server.
Definition: service_command.h:257
void(* handle_error_t)(void *ctx, uint sql_errno, const char *err_msg, const char *sqlstate)
Command ended with ERROR.
Definition: service_command.h:306
int(* get_string_t)(void *ctx, const char *value, size_t length, const CHARSET_INFO *valuecs)
Get STRING value from server.
Definition: service_command.h:280
void(* abort_row_t)(void *ctx)
An error occurred during execution.
Definition: service_command.h:143
void(* handle_ok_t)(void *ctx, uint server_status, uint statement_warn_count, ulonglong affected_rows, ulonglong last_insert_id, const char *message)
Command ended with success.
Definition: service_command.h:294
int(* get_null_t)(void *ctx)
Receive NULL value from server.
Definition: service_command.h:163
void(* shutdown_t)(void *ctx, int server_shutdown)
Callback for shutdown notification from the server.
Definition: service_command.h:316
int(* get_longlong_t)(void *ctx, longlong value, uint is_unsigned)
Get LONGLONG value from server.
Definition: service_command.h:191
int(* get_decimal_t)(void *ctx, const decimal_t *value)
Receive DECIMAL value from server.
Definition: service_command.h:203
int(* field_metadata_t)(void *ctx, struct st_send_field *field, const CHARSET_INFO *charset)
Field metadata is provided via this callback.
Definition: service_command.h:95
Header file for the Server session service.
class Srv_session * MYSQL_SESSION
Definition: service_srv_session_bits.h:37
Definition: m_ctype.h:421
Definition: mysql_time.h:82
Definition: service_command.h:394
int(* run_command)(MYSQL_SESSION session, enum enum_server_command command, const union COM_DATA *data, const CHARSET_INFO *client_cs, const struct st_command_service_cbs *callbacks, enum cs_text_or_binary text_or_binary, void *service_callbacks_ctx)
Definition: service_command.h:395
Base struct used to represent decimal data type.
Definition: decimal.h:49
Definition: service_command.h:328
field_metadata_t field_metadata
Definition: service_command.h:360
get_time_t get_time
Definition: service_command.h:375
handle_error_t handle_error
Definition: service_command.h:382
get_longlong_t get_longlong
Definition: service_command.h:371
get_string_t get_string
Definition: service_command.h:377
get_client_capabilities_t get_client_capabilities
Definition: service_command.h:365
get_null_t get_null
Definition: service_command.h:369
get_integer_t get_integer
Definition: service_command.h:370
start_row_t start_row
Definition: service_command.h:362
end_row_t end_row
Definition: service_command.h:363
start_result_metadata_t start_result_metadata
Definition: service_command.h:359
abort_row_t abort_row
Definition: service_command.h:364
get_date_t get_date
Definition: service_command.h:374
get_datetime_t get_datetime
Definition: service_command.h:376
get_decimal_t get_decimal
Definition: service_command.h:372
end_result_metadata_t end_result_metadata
Definition: service_command.h:361
connection_alive_t connection_alive
Definition: service_command.h:386
handle_ok_t handle_ok
Definition: service_command.h:381
shutdown_t shutdown
Definition: service_command.h:383
get_double_t get_double
Definition: service_command.h:373
Definition: service_command.h:45
unsigned int charsetnr
Definition: service_command.h:52
enum_field_types type
Definition: service_command.h:55
const char * table_name
Definition: service_command.h:47
unsigned int flags
Definition: service_command.h:53
unsigned int decimals
Definition: service_command.h:54
const char * org_col_name
Definition: service_command.h:50
const char * org_table_name
Definition: service_command.h:48
unsigned long length
Definition: service_command.h:51
const char * col_name
Definition: service_command.h:49
const char * db_name
Definition: service_command.h:46
Definition: com_data.h:104
command
Definition: version_token.cc:280