MySQL 9.1.0
Source Code Documentation
mysql_command_delegates.h
Go to the documentation of this file.
1/* Copyright (c) 2022, 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
25#ifndef MYSQL_COMMAND_DELEGATES_H
26#define MYSQL_COMMAND_DELEGATES_H
27
28#include <include/decimal.h>
29#include <include/my_compiler.h>
30#include <include/mysql.h>
36
38 public:
39 Command_delegate(void *srv, SRV_CTX_H srv_ctx_h);
40 virtual ~Command_delegate();
41
46
48 static const st_command_service_cbs cbs = {
68 nullptr};
69 return &cbs;
70 }
71
72 protected:
73 void *m_srv;
76
77 public:
78 /*** Getting metadata ***/
79 /*
80 Indicates beginning of metadata for the result set
81
82 @param num_cols Number of fields being sent
83 @param flags Flags to alter the metadata sending
84 @param resultcs Charset of the result set
85
86 @returns
87 true an error occurred, server will abort the command
88 false ok
89 */
90 virtual int start_result_metadata(uint32_t num_cols, uint32_t flags,
91 const CHARSET_INFO *resultcs) = 0;
92
93 /*
94 Field metadata is provided via this callback
95
96 @param field Field's metadata (see field.h)
97 @param charset Field's charset
98
99 @returns
100 true an error occurred, server will abort the command
101 false ok
102 */
103 virtual int field_metadata(struct st_send_field *field,
104 const CHARSET_INFO *charset) = 0;
105
106 /*
107 Indicates end of metadata for the result set
108
109 @returns
110 true an error occurred, server will abort the command
111 false ok
112 */
113 virtual int end_result_metadata(uint server_status, uint warn_count) = 0;
114
115 /*
116 Indicates the beginning of a new row in the result set/metadata
117
118 @returns
119 true an error occurred, server will abort the command
120 false ok
121 */
122 virtual int start_row() = 0;
123
124 /*
125 Indicates the end of the current row in the result set/metadata
126
127 @returns
128 true an error occurred, server will abort the command
129 false ok
130 */
131 virtual int end_row() = 0;
132
133 /*
134 An error occurred during execution
135
136 @details This callback indicates that an error occurreded during command
137 execution and the partial row should be dropped. Server will raise error
138 and return.
139
140 @returns
141 true an error occurred, server will abort the command
142 false ok
143 */
144 virtual void abort_row() = 0;
145
146 /*
147 Return client's capabilities (see mysql_com.h, CLIENT_*)
148
149 @return Bitmap of client's capabilities
150 */
151 virtual ulong get_client_capabilities() = 0;
152
153 /****** Getting data ******/
154 /*
155 Receive NULL value from server
156
157 @returns
158 true an error occurred, server will abort the command
159 false ok
160 */
161 virtual int get_null() = 0;
162
163 /*
164 Get TINY/SHORT/LONG value from server
165
166 @param value Value received
167
168 @note In order to know which type exactly was received, the plugin must
169 track the metadata that was sent just prior to the result set.
170
171 @returns
172 true an error occurred, server will abort the command
173 false ok
174 */
175 virtual int get_integer(longlong value) = 0;
176
177 /*
178 Get LONGLONG value from server
179
180 @param value Value received
181 @param unsigned_flag true <=> value is unsigned
182
183 @returns
184 true an error occurred, server will abort the command
185 false ok
186 */
187 virtual int get_longlong(longlong value, uint32_t unsigned_flag) = 0;
188
189 /*
190 Receive DECIMAL value from server
191
192 @param value Value received
193
194 @returns
195 true an error occurred, server will abort the command
196 false ok
197 */
198 virtual int get_decimal(const decimal_t *value) = 0;
199
200 /*
201 Get FLOAT/DOUBLE from server
202
203 @param value Value received
204 @param decimals Number of decimals
205
206 @note In order to know which type exactly was received, the plugin must
207 track the metadata that was sent just prior to the result set.
208
209 @returns
210 true an error occurred, server will abort the command
211 false ok
212 */
213 virtual int get_double(double value, uint32 decimals) = 0;
214
215 /*
216 Get DATE value from server
217
218 @param value Value received
219
220 @returns
221 true an error occurred during storing, server will abort the command
222 false ok
223 */
224 virtual int get_date(const MYSQL_TIME *value) = 0;
225
226 /*
227 Get TIME value from server
228
229 @param value Value received
230 @param decimals Number of decimals
231
232 @returns
233 true an error occurred during storing, server will abort the command
234 false ok
235 */
236 virtual int get_time(const MYSQL_TIME *value, uint decimals) = 0;
237
238 /*
239 Get DATETIME value from server
240
241 @param value Value received
242 @param decimals Number of decimals
243
244 @returns
245 true an error occurred during storing, server will abort the command
246 false ok
247 */
248 virtual int get_datetime(const MYSQL_TIME *value, uint decimals) = 0;
249
250 /*
251 Get STRING value from server
252
253 @param value Value received
254 @param length Value's length
255 @param valuecs Value's charset
256
257 @returns
258 true an error occurred, server will abort the command
259 false ok
260 */
261 virtual int get_string(const char *const value, size_t length,
262 const CHARSET_INFO *const valuecs) = 0;
263
264 /****** Getting execution status ******/
265 /*
266 Command ended with success
267
268 @param server_status Status of server (see mysql_com.h,
269 SERVER_STATUS_*)
270 @param statement_warn_count Number of warnings thrown during execution
271 @param affected_rows Number of rows affected by the command
272 @param last_insert_id Last insert id being assigned during execution
273 @param message A message from server
274 */
275 virtual void handle_ok(unsigned int server_status,
276 unsigned int statement_warn_count,
277 unsigned long long affected_rows,
278 unsigned long long last_insert_id,
279 const char *const message) = 0;
280
281 /*
282 Command ended with ERROR
283
284 @param sql_errno Error code
285 @param err_msg Error message
286 @param sqlstate SQL state correspongin to the error code
287 */
288 virtual void handle_error(uint sql_errno, const char *const err_msg,
289 const char *const sqlstate) = 0;
290 /*
291 Session was shutdown while command was running
292 */
293 virtual void shutdown(int flag [[maybe_unused]]) { return; }
294
295 private:
296 static int call_start_result_metadata(void *ctx, uint num_cols, uint flags,
297 const CHARSET_INFO *resultcs) {
298 assert(ctx);
299 Command_delegate *self = static_cast<Command_delegate *>(ctx);
300 return self->start_result_metadata(num_cols, flags, resultcs);
301 }
302
303 static int call_field_metadata(void *ctx, struct st_send_field *field,
304 const CHARSET_INFO *charset) {
305 assert(ctx);
306 return static_cast<Command_delegate *>(ctx)->field_metadata(field, charset);
307 }
308
309 static int call_end_result_metadata(void *ctx, uint server_status,
310 uint warn_count) {
311 assert(ctx);
312 Command_delegate *self = static_cast<Command_delegate *>(ctx);
313 const int tmp = self->end_result_metadata(server_status, warn_count);
314 return tmp;
315 }
316
317 static int call_start_row(void *ctx) {
318 assert(ctx);
319 Command_delegate *self = static_cast<Command_delegate *>(ctx);
320 return self->start_row();
321 }
322
323 static int call_end_row(void *ctx) {
324 assert(ctx);
325 Command_delegate *self = static_cast<Command_delegate *>(ctx);
326 return self->end_row();
327 }
328
329 static void call_abort_row(void *ctx) {
330 assert(ctx);
331 static_cast<Command_delegate *>(ctx)->abort_row();
332 }
333
334 static ulong call_get_client_capabilities(void *ctx) {
335 assert(ctx);
336 return static_cast<Command_delegate *>(ctx)->get_client_capabilities();
337 }
338
339 static int call_get_null(void *ctx) {
340 assert(ctx);
341 return static_cast<Command_delegate *>(ctx)->get_null();
342 }
343
344 static int call_get_integer(void *ctx, longlong value) {
345 assert(ctx);
346 return static_cast<Command_delegate *>(ctx)->get_integer(value);
347 }
348
349 static int call_get_longlong(void *ctx, longlong value,
350 unsigned int unsigned_flag) {
351 assert(ctx);
352 return static_cast<Command_delegate *>(ctx)->get_longlong(value,
353 unsigned_flag);
354 }
355
356 static int call_get_decimal(void *ctx, const decimal_t *value) {
357 assert(ctx);
358 return static_cast<Command_delegate *>(ctx)->get_decimal(value);
359 }
360
361 static int call_get_double(void *ctx, double value, unsigned int decimals) {
362 assert(ctx);
363 return static_cast<Command_delegate *>(ctx)->get_double(value, decimals);
364 }
365
366 static int call_get_date(void *ctx, const MYSQL_TIME *value) {
367 assert(ctx);
368 return static_cast<Command_delegate *>(ctx)->get_date(value);
369 }
370
371 static int call_get_time(void *ctx, const MYSQL_TIME *value,
372 unsigned int decimals) {
373 assert(ctx);
374 return static_cast<Command_delegate *>(ctx)->get_time(value, decimals);
375 }
376
377 static int call_get_datetime(void *ctx, const MYSQL_TIME *value,
378 unsigned int decimals) {
379 assert(ctx);
380 return static_cast<Command_delegate *>(ctx)->get_datetime(value, decimals);
381 }
382
383 static int call_get_string(void *ctx, const char *const value, size_t length,
384 const CHARSET_INFO *const valuecs) {
385 assert(ctx);
386 return static_cast<Command_delegate *>(ctx)->get_string(value, length,
387 valuecs);
388 }
389
390 static void call_handle_ok(void *ctx, uint server_status,
391 uint statement_warn_count, ulonglong affected_rows,
392 ulonglong last_insert_id,
393 const char *const message) {
394 assert(ctx);
395 auto context = static_cast<Command_delegate *>(ctx);
396 context->handle_ok(server_status, statement_warn_count, affected_rows,
397 last_insert_id, message);
398 }
399
400 static void call_handle_error(void *ctx, uint sql_errno,
401 const char *const err_msg,
402 const char *const sqlstate) {
403 assert(ctx);
404 static_cast<Command_delegate *>(ctx)->handle_error(sql_errno, err_msg,
405 sqlstate);
406 }
407
408 static void call_shutdown(void *ctx, int flag) {
409 assert(ctx);
410 static_cast<Command_delegate *>(ctx)->shutdown(flag);
411 }
412};
413
415 public:
416 Callback_command_delegate(void *srv, SRV_CTX_H srv_ctx_h);
417
418 int start_result_metadata(uint32_t num_cols, uint32_t flags,
419 const CHARSET_INFO *resultcs) override;
420
421 int field_metadata(struct st_send_field *field,
422 const CHARSET_INFO *charset) override;
423
424 int end_result_metadata(uint server_status, uint warn_count) override;
425
428 }
429
430 int start_row() override;
431
432 int end_row() override;
433
434 void abort_row() override;
435
436 ulong get_client_capabilities() override;
437
438 /****** Getting data ******/
439 int get_null() override;
440
441 int get_integer(longlong value) override;
442
443 int get_longlong(longlong value, unsigned int unsigned_flag) override;
444
445 int get_decimal(const decimal_t *value) override;
446
447 int get_double(double value, unsigned int decimals) override;
448
449 int get_date(const MYSQL_TIME *value) override;
450
451 int get_time(const MYSQL_TIME *value, unsigned int decimals) override;
452
453 int get_datetime(const MYSQL_TIME *value, unsigned int decimals) override;
454
455 int get_string(const char *const value, size_t length,
456 const CHARSET_INFO *const valuecs) override;
457
458 void handle_ok(unsigned int server_status, unsigned int statement_warn_count,
459 unsigned long long affected_rows,
460 unsigned long long last_insert_id,
461 const char *const message) override;
462
463 void handle_error(uint sql_errno, const char *const err_msg,
464 const char *const sqlstate) override;
465};
466
467#endif // MYSQL_COMMAND_DELEGATES_H
Definition: mysql_command_delegates.h:414
int start_result_metadata(uint32_t num_cols, uint32_t flags, const CHARSET_INFO *resultcs) override
Definition: mysql_command_delegates.cc:46
int get_string(const char *const value, size_t length, const CHARSET_INFO *const valuecs) override
Definition: mysql_command_delegates.cc:147
enum cs_text_or_binary representation() const
Definition: mysql_command_delegates.h:426
void abort_row() override
Definition: mysql_command_delegates.cc:82
int get_double(double value, unsigned int decimals) override
Definition: mysql_command_delegates.cc:119
ulong get_client_capabilities() override
Definition: mysql_command_delegates.cc:87
int get_datetime(const MYSQL_TIME *value, unsigned int decimals) override
Definition: mysql_command_delegates.cc:139
int get_null() override
Definition: mysql_command_delegates.cc:96
int get_date(const MYSQL_TIME *value) override
Definition: mysql_command_delegates.cc:124
Callback_command_delegate(void *srv, SRV_CTX_H srv_ctx_h)
Definition: mysql_command_delegates.cc:42
int end_row() override
Definition: mysql_command_delegates.cc:77
int get_time(const MYSQL_TIME *value, unsigned int decimals) override
Definition: mysql_command_delegates.cc:131
int start_row() override
Definition: mysql_command_delegates.cc:72
int get_longlong(longlong value, unsigned int unsigned_flag) override
Definition: mysql_command_delegates.cc:106
void handle_ok(unsigned int server_status, unsigned int statement_warn_count, unsigned long long affected_rows, unsigned long long last_insert_id, const char *const message) override
Definition: mysql_command_delegates.cc:154
int get_decimal(const decimal_t *value) override
Definition: mysql_command_delegates.cc:112
int field_metadata(struct st_send_field *field, const CHARSET_INFO *charset) override
Definition: mysql_command_delegates.cc:53
int get_integer(longlong value) override
Definition: mysql_command_delegates.cc:101
void handle_error(uint sql_errno, const char *const err_msg, const char *const sqlstate) override
Definition: mysql_command_delegates.cc:171
int end_result_metadata(uint server_status, uint warn_count) override
Definition: mysql_command_delegates.cc:65
Definition: mysql_command_delegates.h:37
virtual int get_datetime(const MYSQL_TIME *value, uint decimals)=0
virtual int start_result_metadata(uint32_t num_cols, uint32_t flags, const CHARSET_INFO *resultcs)=0
virtual int get_string(const char *const value, size_t length, const CHARSET_INFO *const valuecs)=0
virtual ~Command_delegate()
Definition: mysql_command_delegates.cc:40
virtual void handle_error(uint sql_errno, const char *const err_msg, const char *const sqlstate)=0
static void call_handle_error(void *ctx, uint sql_errno, const char *const err_msg, const char *const sqlstate)
Definition: mysql_command_delegates.h:400
virtual int get_time(const MYSQL_TIME *value, uint decimals)=0
static int call_get_null(void *ctx)
Definition: mysql_command_delegates.h:339
virtual void shutdown(int flag)
Definition: mysql_command_delegates.h:293
virtual int get_integer(longlong value)=0
static int call_get_string(void *ctx, const char *const value, size_t length, const CHARSET_INFO *const valuecs)
Definition: mysql_command_delegates.h:383
Command_delegate & operator=(Command_delegate &&)=default
st_command_service_cbs m_callbacks
Definition: mysql_command_delegates.h:75
virtual int get_null()=0
Command_delegate(Command_delegate &&)=default
static int call_end_result_metadata(void *ctx, uint server_status, uint warn_count)
Definition: mysql_command_delegates.h:309
virtual ulong get_client_capabilities()=0
static void call_shutdown(void *ctx, int flag)
Definition: mysql_command_delegates.h:408
static int call_get_longlong(void *ctx, longlong value, unsigned int unsigned_flag)
Definition: mysql_command_delegates.h:349
virtual int start_row()=0
SRV_CTX_H m_srv_ctx_h
Definition: mysql_command_delegates.h:74
Command_delegate(const Command_delegate &)=default
static int call_field_metadata(void *ctx, struct st_send_field *field, const CHARSET_INFO *charset)
Definition: mysql_command_delegates.h:303
static int call_start_result_metadata(void *ctx, uint num_cols, uint flags, const CHARSET_INFO *resultcs)
Definition: mysql_command_delegates.h:296
virtual int end_row()=0
static ulong call_get_client_capabilities(void *ctx)
Definition: mysql_command_delegates.h:334
static int call_get_integer(void *ctx, longlong value)
Definition: mysql_command_delegates.h:344
virtual void handle_ok(unsigned int server_status, unsigned int statement_warn_count, unsigned long long affected_rows, unsigned long long last_insert_id, const char *const message)=0
static void call_handle_ok(void *ctx, uint server_status, uint statement_warn_count, ulonglong affected_rows, ulonglong last_insert_id, const char *const message)
Definition: mysql_command_delegates.h:390
static int call_get_datetime(void *ctx, const MYSQL_TIME *value, unsigned int decimals)
Definition: mysql_command_delegates.h:377
Command_delegate(void *srv, SRV_CTX_H srv_ctx_h)
Definition: mysql_command_delegates.cc:34
void * m_srv
Definition: mysql_command_delegates.h:73
virtual int get_double(double value, uint32 decimals)=0
const st_command_service_cbs * callbacks() const
Definition: mysql_command_delegates.h:47
static int call_get_double(void *ctx, double value, unsigned int decimals)
Definition: mysql_command_delegates.h:361
static void call_abort_row(void *ctx)
Definition: mysql_command_delegates.h:329
virtual int get_decimal(const decimal_t *value)=0
virtual int get_longlong(longlong value, uint32_t unsigned_flag)=0
static int call_end_row(void *ctx)
Definition: mysql_command_delegates.h:323
static int call_get_date(void *ctx, const MYSQL_TIME *value)
Definition: mysql_command_delegates.h:366
static int call_get_decimal(void *ctx, const decimal_t *value)
Definition: mysql_command_delegates.h:356
virtual int get_date(const MYSQL_TIME *value)=0
virtual int field_metadata(struct st_send_field *field, const CHARSET_INFO *charset)=0
virtual int end_result_metadata(uint server_status, uint warn_count)=0
static int call_start_row(void *ctx)
Definition: mysql_command_delegates.h:317
static int call_get_time(void *ctx, const MYSQL_TIME *value, unsigned int decimals)
Definition: mysql_command_delegates.h:371
virtual void abort_row()=0
Command_delegate & operator=(const Command_delegate &)=default
static int flags[50]
Definition: hp_test1.cc:40
static int flag
Definition: hp_test1.cc:40
A better implementation of the UNIX ctype(3) library.
Header for compiler-dependent features.
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
This file defines the client API to MySQL and also the ABI of the dynamically linked libmysqlclient.
struct SRV_CTX_H_imp * SRV_CTX_H
Definition: mysql_command_consumer.h:31
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
Definition: srv0dynamic_procedures.h:48
Header file for the Command service.
cs_text_or_binary
Definition: service_command.h:389
@ CS_BINARY_REPRESENTATION
Definition: service_command.h:391
Definition: m_ctype.h:421
Definition: mysql_time.h:82
Base struct used to represent decimal data type.
Definition: decimal.h:49
Definition: service_command.h:328
Definition: service_command.h:45