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