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