MySQL 8.0.40
Source Code Documentation
mysql_command_services.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_SERVICE_H
25#define MYSQL_COMMAND_SERVICE_H
26
29#include <stdint.h>
30
31/* Command service provides mysql query service apis */
32
36
37#define MYSQL_ROW_H char **
38
39/**
40 This enum is used in mysql_service_mysql_command_options service to set the
41 provided option similar to mysql_option api.
42 @note Please take care that MYSQL_COMMAND_CONSUMER_SERVICE value should be
43 greaterthan the last enum value of @ref mysql_option enum.
44*/
46 MYSQL_TEXT_CONSUMER_FACTORY = 1024, // Make sure this number should be
47 // greaterthan enum mysql_option last
48 // option value.
65};
66
67/**
68 @ingroup group_components_services_inventory
69
70 A service that provides the apis for mysql command init, info, connect,
71 reset, close, commit, auto_commit and rollback.
72
73*/
74BEGIN_SERVICE_DEFINITION(mysql_command_factory)
75
76/**
77 Calls mysql_init() api to Gets or initializes a MYSQL_H structure
78
79 @param[out] mysql_h Prepared mysql object from mysql_init call.
80
81 @retval true failure
82 @retval false success
83*/
85
86/**
87 Calls mysql_real_connect api to connects to a MySQL server.
88
89 @param[in] mysql_h A valid mysql object.
90
91 @retval true failure
92 @retval false success
93*/
95
96/**
97 Calls mysql_reset_connection api to resets the connection to
98 clear session state.
99
100 @param[in] mysql_h A valid mysql object.
101
102 @retval true failure
103 @retval false success
104*/
106
107/**
108 Calls mysql_close api to closes a server connection.
109
110 @param[in] mysql_h A valid mysql object.
111
112 @retval true failure
113 @retval false success
114*/
116
117/**
118 Calls mysql_commit api to commits the transaction.
119
120 @param[in] mysql_h A valid mysql object.
121
122 @retval true failure
123 @retval false success
124*/
126
127/**
128 Calls mysql_autocommit api to toggles autocommit mode on/off.
129
130 @param[in] mysql_h A valid mysql object.
131 @param[in] mode Sets autocommit mode on if mode is 1, off
132 if mode is 0.
133
134 @retval true failure
135 @retval false success
136*/
138
139/**
140 Calls mysql_rollback api to rolls back the transaction.
141
142 @param[in] mysql_h A valid mysql object.
143
144 @retval true failure
145 @retval false success
146*/
148END_SERVICE_DEFINITION(mysql_command_factory)
149
150/**
151 @ingroup group_components_services_inventory
152
153 A service that provides the apis for mysql command session thread init and
154 thread end.
155
156*/
157BEGIN_SERVICE_DEFINITION(mysql_command_thread)
158
159/**
160 Calls session init_thread() to initialize a thread to use the session
161 service.
162
163 @retval true failure
164 @retval false success
165 */
167
168/**
169 Calls session deinit_thread() to deinitialize a thread that has been using
170 the session service.
171*/
172DECLARE_METHOD(void, end, (void));
173END_SERVICE_DEFINITION(mysql_command_thread)
174
175/**
176 @ingroup group_components_services_inventory
177
178 A service that provides the apis for mysql command get_option and set_option.
179*/
180BEGIN_SERVICE_DEFINITION(mysql_command_options)
181
182/**
183 Calls mysql_options api to sets connect options for connection-establishment
184 functions such as real_connect().
185
186 @param[in] mysql A valid mysql object.
187 @param[in] option The option argument is the option that you
188 want to set.
189 @param[in] arg The arg argument is the value
190 for the option.
191
192--------------+-------------------------------+--------------------------------+
193 Type | Option |Explanation |
194--------------+-------------------------------+--------------------------------+
195const char * |MYSQL_COMMAND_CONSUMER_SERVICE |The service (implementation) |
196 | |name/prefix to look for in the |
197 | |registry and direct all the |
198 | |calls to. |
199--------------+-------------------------------+--------------------------------+
200MYSQL_THD |MYSQL_COMMAND_LOCAL_THD_HANDLE |The THD to run the query in. |
201 | |If null a new internal THD will |
202 | |be created. |
203--------------+-------------------------------+--------------------------------+
204const char * |MYSQL_COMMAND_PROTOCOL |Could be valid socket meaning co|
205 | |nnect to remote server, could be|
206 | |"local"(default) meaning connect|
207 | |to the current server. |
208--------------+-------------------------------+--------------------------------+
209const char * |MYSQL_COMMAND_USER_NAME |The user name to send to the |
210 | |server/set into the thread's |
211 | |security context. |
212--------------+-------------------------------+--------------------------------+
213const char * |MYSQL_COMMAND_HOST_NAME |The host name to use to |
214 | |connect/set into the thread's |
215 | |security context. |
216--------------+-------------------------------+--------------------------------+
217int |MYSQL_COMMAND_TCPIP_PORT |The port to use to connect. |
218--------------+-------------------------------+--------------------------------+
219
220 @note For the other mysql client options it calls the mysql_options api.
221
222 @retval true failure
223 @retval false success
224*/
225DECLARE_BOOL_METHOD(set, (MYSQL_H mysql, int option, const void *arg));
226
227/**
228 Calls mysql_get_option api to returns the value of a mysql_options() option.
229
230 @param[in] mysql A valid mysql object.
231 @param[in] option The option argument is the option that you
232 want to get.
233 @param[out] arg The arg argument is the value
234 for the option to store.
235
236 @retval true failure
237 @retval false success
238*/
239DECLARE_BOOL_METHOD(get, (MYSQL_H mysql, int option, const void *arg));
240
241END_SERVICE_DEFINITION(mysql_command_options)
242
243/**
244 @ingroup group_components_services_inventory
245
246 A service that provides the apis for mysql command query and
247 affected_rows.
248*/
249BEGIN_SERVICE_DEFINITION(mysql_command_query)
250
251/**
252 Calls mysql_real_query api to executes an SQL query specified
253 as a counted string.
254
255 @param[in] mysql A valid mysql object.
256 @param[in] stmt_str SQL statement which has a query.
257 @param[in] length A string length bytes long.
258
259 @retval true failure
260 @retval false success
261*/
262DECLARE_BOOL_METHOD(query, (MYSQL_H mysql, const char *stmt_str,
263 unsigned long length));
264
265/**
266 Calls mysql_affected_rows api to return the number of rows
267 changed/deleted/inserted by the last UPDATE,DELETE or INSERT query.
268
269 @param[in] mysql A valid mysql object.
270 @param[out] *rows Number of rows affected, for SELECT stmt it tells
271 about number of rows present.
272
273 @retval true failure
274 @retval false success
275*/
276DECLARE_BOOL_METHOD(affected_rows, (MYSQL_H mysql, uint64_t *rows));
277END_SERVICE_DEFINITION(mysql_command_query)
278
279/**
280 @ingroup group_components_services_inventory
281
282 A service that provides the apis for mysql command, store_result,
283 free_result, more_results, next_result, result_metadata and fetch_row.
284*/
285BEGIN_SERVICE_DEFINITION(mysql_command_query_result)
286
287/**
288 Calls mysql_store_result api to retrieves a complete result set.
289
290 @param[in] mysql A valid mysql object.
291 @param[out] *mysql_res An mysql result object to get the result
292 set.
293
294 @retval true failure
295 @retval false success
296*/
297DECLARE_BOOL_METHOD(store_result, (MYSQL_H mysql, MYSQL_RES_H *mysql_res));
298
299/**
300 Calls mysql_free_result api to frees memory used by a result set.
301
302 @param[in] mysql_res An mysql result object to free the result
303 set.
304
305 @retval true failure
306 @retval false success
307*/
308DECLARE_BOOL_METHOD(free_result, (MYSQL_RES_H mysql_res));
309
310/**
311 Calls mysql_more_results api to checks whether any more results exist.
312
313 @param[in] mysql A valid mysql object.
314
315 @retval true failure
316 @retval false success
317*/
319
320/**
321 Calls mysql_next_result api to returns/initiates the next result
322 in multiple-result executions.
323
324 @param[in] mysql A valid mysql object.
325
326 @retval -1 no more results
327 @retval >0 error
328 @retval 0 if yes more results exits(keep looping)
329*/
330DECLARE_METHOD(int, next_result, (MYSQL_H mysql));
331
332/**
333 Calls mysql_result_metadata api to whether a result set has metadata.
334
335 @param[in] res_h An mysql result object to get the metadata
336 info.
337
338 @retval true failure metadata_info not present.
339 @retval false success metadata_info present.
340*/
341DECLARE_BOOL_METHOD(result_metadata, (MYSQL_RES_H res_h));
342
343/**
344 Calls mysql_fetch_row api to fetches the next row from the result set.
345
346 @param[in] res_h An mysql result object to fetch a row from
347 the result set.
348 @param[out] *row To store the fetched row with server's charset.
349
350 @retval true failure
351 @retval false success
352*/
354
355/**
356 Calls mysql_fetch_lengths api to Returns the lengths of all columns
357 in the current row.
358
359 @param[in] res_h An mysql result object to fetch a row from
360 the result set.
361 @param[out] *length lengths of all columns.
362
363 @retval true failure
364 @retval false success
365*/
366DECLARE_BOOL_METHOD(fetch_lengths, (MYSQL_RES_H res_h, ulong **length));
367END_SERVICE_DEFINITION(mysql_command_query_result)
368
369/**
370 @ingroup group_components_services_inventory
371
372 A service that provides the apis for mysql command field info, fetch_field,
373 num_fields, fetch_fields and field_count.
374*/
375BEGIN_SERVICE_DEFINITION(mysql_command_field_info)
376
377/**
378 Calls mysql_fetch_field api to returns the type of next table field.
379
380 @param[in] res_h An mysql result object to return the next table
381 field.
382 @param[out] *field_h Stores the definition of one column of a result
383 set as a MYSQL_FIELD structure
384
385 @retval true failure
386 @retval false success
387*/
388DECLARE_BOOL_METHOD(fetch_field, (MYSQL_RES_H res_h, MYSQL_FIELD_H *field_h));
389
390/**
391 Calls mysql_num_fields api to returns the number of columns in a result set.
392
393 @param[in] res_h A valid mysql result set object.
394 @param[out] *num_fields Stores the number of columns in the result set.
395 @retval true failure
396 @retval false success
397*/
398DECLARE_BOOL_METHOD(num_fields, (MYSQL_RES_H res_h, unsigned int *num_fields));
399
400/**
401 Calls mysql_fetch_fields api to returns an array of all field structures.
402
403 @param[in] res_h A valid mysql result set object.
404 @param[out] **fields_h Stores the array of all fields for a result set.
405 @retval true failure
406 @retval false success
407*/
408DECLARE_BOOL_METHOD(fetch_fields,
409 (MYSQL_RES_H res_h, MYSQL_FIELD_H **fields_h));
410
411/**
412 Calls mysql_field_count api to returns the number of columns for the most
413 resent statement.
414
415 @param[in] mysql_h A valid mysql handle object.
416 @param[out] *num_fields Stores the number of columns for the last stmt.
417 @retval true failure
418 @retval false success
419*/
420DECLARE_BOOL_METHOD(field_count, (MYSQL_H mysql_h, unsigned int *num_fields));
421END_SERVICE_DEFINITION(mysql_command_field_info)
422
423#define MYSQL_COMMAND_FIELD_METADATA_NAME 0
424#define MYSQL_COMMAND_FIELD_METADATA_TABLE_NAME 1
425#define MYSQL_COMMAND_FIELD_METADATA_TABLE_DB_NAME 2
426
427/**
428 @ingroup group_components_services_inventory
429
430 Fetch the metadata of a service.
431
432 Usually used as follows:
433
434*/
435BEGIN_SERVICE_DEFINITION(mysql_command_field_metadata)
436/**
437 Retrieves the metadata for the field.
438
439 @param[in] mysql_field_h A valid mysql field handle object.
440 @param[in] metadata A metadata ID to fetch. Can be one of:
441
442--------------+-------------------------------------------+--------------------------------+
443 Type | Option |Explanation |
444--------------+-------------------------------------------+--------------------------------+
445const char * |MYSQL_COMMAND_FIELD_METADATA_NAME |The field name. |
446--------------+-------------------------------------------+--------------------------------+
447const char * |MYSQL_COMMAND_FIELD_METADATA_TABLE_NAME |The table name. |
448--------------+-------------------------------------------+--------------------------------+
449const char * |MYSQL_COMMAND_FIELD_METADATA_TABLE_DB_NAME |The table database
450name. |
451--------------+-------------------------------------------+--------------------------------+
452
453 @param[out] data A buffer to receive the data fetched.
454 @retval true failure
455 @retval false success
456*/
458 (MYSQL_FIELD_H mysql_field_h, int metadata, void *data));
459END_SERVICE_DEFINITION(mysql_command_field_metadata)
460
461/**
462 @ingroup group_components_services_inventory
463
464 A service that provides the apis for mysql command error info, mysql_errno,
465 error, sqlstate.
466*/
467BEGIN_SERVICE_DEFINITION(mysql_command_error_info)
468
469/**
470 Calls mysql_errno api to return the number of most recently invoked mysql
471 function.
472
473 @param[in] mysql_h A valid mysql handle object.
474 @param[out] *err_no Stores the error number of last mysql function.
475 @retval true failure
476 @retval false success
477*/
478DECLARE_BOOL_METHOD(sql_errno, (MYSQL_H mysql_h, unsigned int *err_no));
479
480/**
481 Calls mysql_error api to return the error message of most recently invoked
482 mysql function.
483
484 @param[in] mysql_h A valid mysql handle object.
485 @param[out] *errmsg Stores the error message of last mysql function.
486 @retval true failure
487 @retval false success
488*/
489DECLARE_BOOL_METHOD(sql_error, (MYSQL_H mysql_h, char **errmsg));
490
491/**
492 Calls mysql_sqlstate api to return the SQLSTATE error code for the last error.
493
494 @param[in] mysql_h A valid mysql handle object.
495 @param[out] *sqlstate_errmsg Stores the SQLSTATE error message of the most
496 recently executed SQL stmt.
497 @retval true failure
498 @retval false success
499*/
500DECLARE_BOOL_METHOD(sql_state, (MYSQL_H mysql_h, char **sqlstate_errmsg));
501END_SERVICE_DEFINITION(mysql_command_error_info)
502
503#endif /* MYSQL_COMMAND_SERVICE_H */
static mysql_service_status_t init()
Component initialization.
Definition: audit_api_message_emit.cc:571
static char * query
Definition: myisam_ftdump.cc:45
mysql_command_option
This enum is used in mysql_service_mysql_command_options service to set the provided option similar t...
Definition: mysql_command_services.h:45
@ MYSQL_COMMAND_TCPIP_PORT
Definition: mysql_command_services.h:64
@ MYSQL_TEXT_CONSUMER_GET_STRING
Definition: mysql_command_services.h:58
@ MYSQL_TEXT_CONSUMER_GET_DECIMAL
Definition: mysql_command_services.h:55
@ MYSQL_TEXT_CONSUMER_FACTORY
Definition: mysql_command_services.h:46
@ MYSQL_TEXT_CONSUMER_GET_NULL
Definition: mysql_command_services.h:52
@ MYSQL_TEXT_CONSUMER_GET_INTEGER
Definition: mysql_command_services.h:53
@ MYSQL_COMMAND_HOST_NAME
Definition: mysql_command_services.h:63
@ MYSQL_TEXT_CONSUMER_ERROR
Definition: mysql_command_services.h:51
@ MYSQL_TEXT_CONSUMER_CLIENT_CAPABILITIES
Definition: mysql_command_services.h:59
@ MYSQL_TEXT_CONSUMER_ROW_FACTORY
Definition: mysql_command_services.h:50
@ MYSQL_TEXT_CONSUMER_GET_LONGLONG
Definition: mysql_command_services.h:54
@ MYSQL_COMMAND_USER_NAME
Definition: mysql_command_services.h:62
@ MYSQL_TEXT_CONSUMER_METADATA
Definition: mysql_command_services.h:49
@ MYSQL_TEXT_CONSUMER_GET_DOUBLE
Definition: mysql_command_services.h:56
@ MYSQL_TEXT_CONSUMER_GET_DATE_TIME
Definition: mysql_command_services.h:57
@ MYSQL_COMMAND_PROTOCOL
Definition: mysql_command_services.h:61
@ MYSQL_COMMAND_LOCAL_THD_HANDLE
Definition: mysql_command_services.h:60
struct MYSQL_H_imp * MYSQL_H
Definition: mysql_command_services.h:33
struct MYSQL_RES_H_imp * MYSQL_RES_H
Definition: mysql_command_services.h:34
struct MYSQL_FIELD_H_imp * MYSQL_FIELD_H
Definition: mysql_command_services.h:35
#define MYSQL_ROW_H
Definition: mysql_command_services.h:37
std::string HARNESS_EXPORT reset()
get 'reset attributes' ESC sequence.
Definition: vt100.cc:37
constexpr value_type autocommit
Definition: classic_protocol_constants.h:152
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: instrumented_condition_variable.h:32
stdx::expected< void, std::error_code > close(file_handle_type native_handle)
close file handle.
Definition: file.h:239
stdx::expected< void, error_type > connect(native_handle_type native_handle, const struct sockaddr *addr, size_t addr_len)
wrap connect() in a portable way.
Definition: socket.h:353
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
mode
Definition: file_handle.h:60
std::set< Key, Compare, ut::allocator< Key > > set
Specialization of set which uses ut_allocator.
Definition: ut0new.h:2883
#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
static bool rollback(THD *thd)
Abort the current statement and transaction.
Definition: sql_cmd_srs.cc:140
static bool commit(THD *thd)
Commit the current statement and transaction.
Definition: sql_cmd_srs.cc:152