MySQL 8.3.0
Source Code Documentation
mysql_command_consumer.h
Go to the documentation of this file.
1/* Copyright (c) 2022, 2023, Oracle and/or its affiliates.
2
3This program is free software; you can redistribute it and/or modify
4it under the terms of the GNU General Public License, version 2.0,
5as published by the Free Software Foundation.
6
7This program is also distributed with certain software (including
8but not limited to OpenSSL) that is licensed under separate terms,
9as designated in a particular file or component or in included license
10documentation. The authors of MySQL hereby grant you an additional
11permission to link the program and your derivative works with the
12separately licensed software that they have included with MySQL.
13
14This program is distributed in the hope that it will be useful,
15but WITHOUT ANY WARRANTY; without even the implied warranty of
16MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17GNU General Public License, version 2.0, for more details.
18
19You should have received a copy of the GNU General Public License
20along with this program; if not, write to the Free Software
21Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
22
23#ifndef MYSQL_COMMAND_CONSUMER_H
24#define MYSQL_COMMAND_CONSUMER_H
25
28#include <cstddef>
29
33
34/**
35 The Field_metadata has the information about the field, which is used
36 by field_metadata() service api.
37*/
39 const char *db_name;
40 const char *table_name;
41 const char *org_table_name;
42 const char *col_name;
43 const char *org_col_name;
44 unsigned long length;
45 unsigned int charsetnr;
46 unsigned int flags;
47 unsigned int decimals;
48 int type;
49};
50
51/**
52 An implementation of these services will be called as the data resulting from
53 calling mysql_query() service are produced by the server.
54
55 Most often the default implementation of this service that will cache the data
56 into a memory structure into the MYSQL handle will be used. But this will only
57 work if the resultset expected is relatively small.
58
59 @note The default implementation will allow accessing the data after the query
60 execution. This will not be possible with a custom method.
61
62 If one wants to avoid the memory caching and process the data SAX style as
63 they are returned by the SQL execution define, they should provide their own
64 implementation of this service that will process the data differently at the
65 time of their production.
66*/
67
68/**
69 @ingroup group_components_services_inventory
70
71 A service that provides the apis for start and end.
72*/
73BEGIN_SERVICE_DEFINITION(mysql_text_consumer_factory_v1)
74
75/**
76 Prepares the data handle(srv_ctx_h), i.e allocates and prepares
77 the Dom_ctx object and assigned to the srv_ctx_h.
78
79 @param[out] srv_ctx_h Dom_ctx data handle.
80 @param mysql_h mysql handle used to prepare srv_ctx_h
81
82 @return status of operation
83 @retval false success. srv_ctx_h was prepared.
84 @retval true failure. OOM or invalid mysql_h.
85*/
86DECLARE_BOOL_METHOD(start, (SRV_CTX_H * srv_ctx_h, MYSQL_H *mysql_h));
87
88/**
89 Deallocates the memory allocated for data handle in start api.
90
91 @param srv_ctx_h dom data handle(Dom_ctx type), which needs to be
92 deallocated.
93
94 @return status of operation
95 @retval void
96*/
97DECLARE_METHOD(void, end, (SRV_CTX_H srv_ctx_h));
98
99END_SERVICE_DEFINITION(mysql_text_consumer_factory_v1)
100
101/**
102 @ingroup group_components_services_inventory
103
104 A service that provides the apis for start_result_metadata, field_metadata,
105 and end_result_metadata.
106*/
107BEGIN_SERVICE_DEFINITION(mysql_text_consumer_metadata_v1)
108
109/**
110 Indicates beginning of metadata for the result set
111
112 @param srv_ctx_h Dom_ctx data handle
113 @param num_cols Number of fields being sent
114 @param flags Flags to alter the metadata sending
115 @param collation_name Charset of the result set
116
117 @return status of operation
118 @retval false success. srv_ctx_h rows were prepared.
119 @retval true failure. OOM or invalid srv_ctx_h.
120*/
121DECLARE_BOOL_METHOD(start_result_metadata,
122 (SRV_CTX_H srv_ctx_h, unsigned int num_cols,
123 unsigned int flags, const char *const collation_name));
124
125/**
126 Field metadata is provided to srv_ctx_h via this service api
127
128 @param srv_ctx_h Dom_ctx data handle
129 @param field Field's metadata (see field.h)
130 @param collation_name Field's charset
131
132 @return status of operation
133 @retval false success. srv_ctx_h field information prepared.
134 @retval true failure. invalid srv_ctx_h.
135*/
136DECLARE_BOOL_METHOD(field_metadata,
137 (SRV_CTX_H srv_ctx_h, struct Field_metadata *field,
138 const char *const collation_name));
139
140/**
141 Indicates end of metadata for the result set
142
143 @param srv_ctx_h Dom_ctx data handle.
144 @param server_status server status.
145 @param warn_count warning count of current stmt.
146
147 @return status of operation
148 @retval false success.
149 @retval true failure.
150*/
151DECLARE_BOOL_METHOD(end_result_metadata,
152 (SRV_CTX_H srv_ctx_h, unsigned int server_status,
153 unsigned warn_count));
154
155END_SERVICE_DEFINITION(mysql_text_consumer_metadata_v1)
156
157/**
158 @ingroup group_components_services_inventory
159
160 A service that provides the apis for start_row, abort_row
161 and end_row.
162*/
163BEGIN_SERVICE_DEFINITION(mysql_text_consumer_row_factory_v1)
164
165/**
166 Indicates the beginning of a new row in the result set/metadata
167
168 @param srv_ctx_h Dom_ctx data handle.
169
170 @return status of operation
171 @retval false success.
172 @retval true failure.
173*/
174DECLARE_BOOL_METHOD(start_row, (SRV_CTX_H srv_ctx_h));
175
176/**
177 An error occurred during execution
178
179 @details This api indicates that an error occurred during command
180 execution and the partial row should be dropped. Server will raise error
181 and return.
182
183 @param srv_ctx_h Dom_ctx data handle.
184
185 @return status of operation
186 @retval false success.
187 @retval true failure.
188*/
189DECLARE_BOOL_METHOD(abort_row, (SRV_CTX_H srv_ctx_h));
190
191/**
192 Indicates the end of the current row in the result set/metadata
193
194 @param srv_ctx_h Dom_ctx data handle.
195
196 @return status of operation
197 @retval false success.
198 @retval true failure.
199*/
200DECLARE_BOOL_METHOD(end_row, (SRV_CTX_H srv_ctx_h));
201END_SERVICE_DEFINITION(mysql_text_consumer_row_factory_v1)
202
203/**
204 @ingroup group_components_services_inventory
205
206 A service that provides the apis for handle_ok, handle_error
207 and error.
208*/
209BEGIN_SERVICE_DEFINITION(mysql_text_consumer_error_v1)
210
211/**
212 Command ended with success
213
214 @param srv_ctx_h Dom_ctx data handle.
215 @param server_status Status of server (see mysql_com.h,
216 SERVER_STATUS_*)
217 @param statement_warn_count Number of warnings thrown during execution
218 @param affected_rows Number of rows affected by the command
219 @param last_insert_id Last insert id being assigned during execution
220 @param message A message from server
221*/
222DECLARE_METHOD(void, handle_ok,
223 (SRV_CTX_H srv_ctx_h, unsigned int server_status,
224 unsigned int statement_warn_count,
225 unsigned long long affected_rows,
226 unsigned long long last_insert_id, const char *const message));
227
228/**
229 Command ended with ERROR, updating the error info into srv_ctx_h.
230
231 @param srv_ctx_h Dom_ctx data handle.
232 @param sql_errno Error code
233 @param err_msg Error message
234 @param sqlstate SQL state corresponding to the error code
235*/
237 (SRV_CTX_H srv_ctx_h, unsigned int sql_errno,
238 const char *const err_msg, const char *const sqlstate));
239/**
240 Getting the error info from srv_ctx_h.
241
242 @param srv_ctx_h Dom_ctx data handle.
243 @param err_num Error code
244 @param error_msg Error message
245
246 @return status of operation
247 @retval false success.
248 @retval true failure.
249*/
250DECLARE_BOOL_METHOD(error, (SRV_CTX_H srv_ctx_h, unsigned int *err_num,
251 const char **error_msg));
252
253END_SERVICE_DEFINITION(mysql_text_consumer_error_v1)
254
255/**
256 @ingroup group_components_services_inventory
257
258 A service that provides the apis for get_null.
259*/
260BEGIN_SERVICE_DEFINITION(mysql_text_consumer_get_null_v1)
261
262/**
263 Receive nullptr value from server and store into srv_ctx_h data.
264
265 @param srv_ctx_h Dom_ctx data handle.
266
267 @return status of operation
268 @retval false success.
269 @retval true failure.
270*/
272
273END_SERVICE_DEFINITION(mysql_text_consumer_get_null_v1)
274
275/**
276 @ingroup group_components_services_inventory
277
278 A service that provides the apis for get_integer.
279*/
280BEGIN_SERVICE_DEFINITION(mysql_text_consumer_get_integer_v1)
281
282/**
283 Get TINY/SHORT/LONG value from server and store into srv_ctx_h data.
284
285 @param srv_ctx_h Dom_ctx data handle.
286 @param value Value received
287
288 @return status of operation
289 @retval false success.
290 @retval true failure.
291*/
292DECLARE_BOOL_METHOD(get, (SRV_CTX_H srv_ctx_h, long long value));
293
294END_SERVICE_DEFINITION(mysql_text_consumer_get_integer_v1)
295
296/**
297 @ingroup group_components_services_inventory
298
299 A service that provides the apis for get_longlong.
300*/
301BEGIN_SERVICE_DEFINITION(mysql_text_consumer_get_longlong_v1)
302
303/**
304 Get LONGLONG value from server and store into srv_ctx_h data.
305
306 @param srv_ctx_h Dom_ctx data handle.
307 @param value Value received
308 @param unsigned_flag true <=> value is unsigned
309
310 @return status of operation
311 @retval false success.
312 @retval true failure.
313*/
314DECLARE_BOOL_METHOD(get, (SRV_CTX_H srv_ctx_h, long long value,
315 unsigned int unsigned_flag));
316
317END_SERVICE_DEFINITION(mysql_text_consumer_get_longlong_v1)
318
319/**
320 @ingroup group_components_services_inventory
321
322 A service that provides the apis for get_decimal.
323*/
324BEGIN_SERVICE_DEFINITION(mysql_text_consumer_get_decimal_v1)
325
326/**
327 Get DECIMAL value from server and store into srv_ctx_h data.
328
329 @param srv_ctx_h Dom_ctx data handle.
330 @param value Value received
331
332 @return status of operation
333 @retval false success.
334 @retval true failure.
335*/
336DECLARE_BOOL_METHOD(get, (SRV_CTX_H srv_ctx_h, const DECIMAL_T_H value));
337
338END_SERVICE_DEFINITION(mysql_text_consumer_get_decimal_v1)
339
340/**
341 @ingroup group_components_services_inventory
342
343 A service that provides the apis for get_double.
344 and error.
345*/
346BEGIN_SERVICE_DEFINITION(mysql_text_consumer_get_double_v1)
347
348/**
349 Get FLOAT/DOUBLE value from server and store into srv_ctx_h data.
350
351 @param srv_ctx_h Dom_ctx data handle.
352 @param value Value received
353 @param decimals Number of decimals
354
355 @return status of operation
356 @retval false success.
357 @retval true failure.
358*/
360 (SRV_CTX_H srv_ctx_h, double value, unsigned int decimals));
361
362END_SERVICE_DEFINITION(mysql_text_consumer_get_double_v1)
363
364/**
365 @ingroup group_components_services_inventory
366
367 A service that provides the apis for get_date, get_time
368 and get_datatime.
369*/
370BEGIN_SERVICE_DEFINITION(mysql_text_consumer_get_date_time_v1)
371
372/**
373 Get DATE value from server and store into srv_ctx_h data.
374
375 @param srv_ctx_h Dom_ctx data handle.
376 @param value Value received
377
378 @return status of operation
379 @retval false success.
380 @retval true failure.
381*/
383
384/**
385 Get TIME value from server and store into srv_ctx_h data.
386
387 @param srv_ctx_h Dom_ctx data handle.
388 @param value Value received
389 @param precision Number of decimals
390
391 @return status of operation
392 @retval false success.
393 @retval true failure.
394*/
395DECLARE_BOOL_METHOD(get_time, (SRV_CTX_H srv_ctx_h, const MYSQL_TIME_H value,
396 unsigned int precision));
397
398/**
399 Get DATETIME value from server and store into srv_ctx_h data.
400
401 @param srv_ctx_h Dom_ctx data handle.
402 @param value Value received
403 @param precision Number of decimals
404
405 @return status of operation
406 @retval false success.
407 @retval true failure.
408*/
409DECLARE_BOOL_METHOD(get_datatime,
410 (SRV_CTX_H srv_ctx_h, const MYSQL_TIME_H value,
411 unsigned int precision));
412
413END_SERVICE_DEFINITION(mysql_text_consumer_get_date_time_v1)
414
415/**
416 @ingroup group_components_services_inventory
417
418 A service that provides the apis for get_string.
419*/
420BEGIN_SERVICE_DEFINITION(mysql_text_consumer_get_string_v1)
421
422/**
423 Get STRING value from server and store into srv_ctx_h data.
424
425 @param srv_ctx_h Dom_ctx data handle.
426 @param value Value received
427 @param length Value's length
428 @param collation_name Value's charset
429
430 @return status of operation
431 @retval false success.
432 @retval true failure.
433*/
435 (SRV_CTX_H srv_ctx_h, const char *const value,
436 size_t length, const char *const collation_name));
437
438END_SERVICE_DEFINITION(mysql_text_consumer_get_string_v1)
439
440/**
441 @ingroup group_components_services_inventory
442
443 A service that provides the apis for client_capabilities.
444*/
445BEGIN_SERVICE_DEFINITION(mysql_text_consumer_client_capabilities_v1)
446
447/*
448 Stores server's capabilities into the OUT param.
449
450 @param srv_ctx_h Dom_ctx data handle.
451 @param[OUT] capabilities contains the server capabilities value.
452*/
453DECLARE_METHOD(void, client_capabilities,
454 (SRV_CTX_H srv_ctx_h, unsigned long *capabilities));
455
456END_SERVICE_DEFINITION(mysql_text_consumer_client_capabilities_v1)
457
458#endif // MYSQL_COMMAND_CONSUMER_H
static int flags[50]
Definition: hp_test1.cc:39
static void start(mysql_harness::PluginFuncEnv *env)
Definition: http_auth_backend_plugin.cc:176
void get_date(char *to, int flag, time_t date)
Store textual representation of date in a character array.
Definition: my_systime.cc:108
struct DECIMAL_T_H_imp * DECIMAL_T_H
Definition: mysql_command_consumer.h:31
struct SRV_CTX_H_imp * SRV_CTX_H
Definition: mysql_command_consumer.h:30
struct MYSQL_TIME_H_imp * MYSQL_TIME_H
Definition: mysql_command_consumer.h:32
struct MYSQL_H_imp * MYSQL_H
Definition: mysql_command_services.h:32
static char * get_string(char **to_ptr, const char **from_ptr, struct st_command *command)
Definition: mysqltest.cc:6242
void handle_error(struct st_command *command, std::uint32_t err_errno, const char *err_error, const char *err_sqlstate, DYNAMIC_STRING *ds)
Handle errors which occurred during execution of a query.
Definition: mysqltest.cc:1292
char * collation_name
Definition: audit_api_message_emit.cc:184
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
void get(PSI_field *, PSI_longlong *) noexcept
Definition: pfs_plugin_column_bigint_v1_all_empty.cc:31
Cursor end()
A past-the-end Cursor.
Definition: rules_table_service.cc:191
#define DECLARE_METHOD(retval, name, args)
Declares a method as a part of the Service definition.
Definition: service.h:102
#define END_SERVICE_DEFINITION(name)
A macro to end the last Service definition started with the BEGIN_SERVICE_DEFINITION macro.
Definition: service.h:90
#define BEGIN_SERVICE_DEFINITION(name)
Declares a new Service.
Definition: service.h:85
#define DEFINE_SERVICE_HANDLE(name)
Defines an object type that is meant for carrying handles to the implementation-specific objects used...
Definition: service.h:128
#define DECLARE_BOOL_METHOD(name, args)
Declares a method that returns bool as a part of the Service definition.
Definition: service.h:111
The Field_metadata has the information about the field, which is used by field_metadata() service api...
Definition: mysql_command_consumer.h:38
unsigned long length
Definition: mysql_command_consumer.h:44
const char * org_table_name
Definition: mysql_command_consumer.h:41
unsigned int charsetnr
Definition: mysql_command_consumer.h:45
const char * db_name
Definition: mysql_command_consumer.h:39
int type
Definition: mysql_command_consumer.h:48
unsigned int decimals
Definition: mysql_command_consumer.h:47
unsigned int flags
Definition: mysql_command_consumer.h:46
const char * table_name
Definition: mysql_command_consumer.h:40
const char * col_name
Definition: mysql_command_consumer.h:42
const char * org_col_name
Definition: mysql_command_consumer.h:43