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