MySQL 26.10.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 MYSQL_TEXT_CONSUMER_FACTORY must be greater than the last value
43 of @ref mysql_option.
44*/
46 MYSQL_TEXT_CONSUMER_FACTORY = 1024, // Make sure this number should be
47 // greaterthan enum mysql_option last
48 // option value.
69};
70
71/**
72 @ingroup group_components_services_inventory
73
74 A service that provides the apis for mysql command init, info, connect,
75 reset, close, commit, auto_commit and rollback.
76
77*/
78BEGIN_SERVICE_DEFINITION(mysql_command_factory)
79
80/**
81 Calls mysql_init() api to Gets or initializes a MYSQL_H structure
82
83 @param[out] mysql_h Prepared mysql object from mysql_init call.
84
85 @retval true failure
86 @retval false success
87*/
89
90/**
91 Calls mysql_real_connect api to connects to a MySQL server.
92
93 @param[in] mysql_h A valid mysql object.
94
95 @retval true failure
96 @retval false success
97*/
99
100/**
101 Calls mysql_reset_connection api to resets the connection to
102 clear session state.
103
104 @param[in] mysql_h A valid mysql object.
105
106 @retval true failure
107 @retval false success
108*/
110
111/**
112 Calls mysql_close api to closes a server connection.
113
114 @param[in] mysql_h A valid mysql object.
115
116 @retval true failure
117 @retval false success
118*/
120
121/**
122 Calls mysql_commit api to commits the transaction.
123
124 @param[in] mysql_h A valid mysql object.
125
126 @retval true failure
127 @retval false success
128*/
130
131/**
132 Calls mysql_autocommit api to toggles autocommit mode on/off.
133
134 @param[in] mysql_h A valid mysql object.
135 @param[in] mode Sets autocommit mode on if mode is 1, off
136 if mode is 0.
137
138 @retval true failure
139 @retval false success
140*/
142
143/**
144 Calls mysql_rollback api to rolls back the transaction.
145
146 @param[in] mysql_h A valid mysql object.
147
148 @retval true failure
149 @retval false success
150*/
152END_SERVICE_DEFINITION(mysql_command_factory)
153
154/**
155 @ingroup group_components_services_inventory
156
157 A service that provides the apis for mysql command session thread init and
158 thread end.
159
160*/
161BEGIN_SERVICE_DEFINITION(mysql_command_thread)
162
163/**
164 Calls session init_thread() to initialize a thread to use the session
165 service.
166
167 @retval true failure
168 @retval false success
169 */
171
172/**
173 Calls session deinit_thread() to deinitialize a thread that has been using
174 the session service.
175*/
176DECLARE_METHOD(void, end, (void));
177END_SERVICE_DEFINITION(mysql_command_thread)
178
179/**
180 @ingroup group_components_services_inventory
181
182 A service that provides the apis for mysql command get_option and set_option.
183*/
184BEGIN_SERVICE_DEFINITION(mysql_command_options)
185
186/**
187 Calls mysql_options api to sets connect options for connection-establishment
188 functions such as real_connect().
189
190 @param[in] mysql A valid mysql object.
191 @param[in] option The option argument is the option that you
192 want to set.
193 @param[in] arg The arg argument is the value
194 for the option.
195
196--------------+-------------------------------+--------------------------------+
197 Type | Option |Explanation |
198--------------+-------------------------------+--------------------------------+
199const char * |MYSQL_TEXT_CONSUMER_* |Service implementation name for |
200 | |the selected text consumer. |
201 | |Null selects its default. |
202--------------+-------------------------------+--------------------------------+
203MYSQL_THD |MYSQL_COMMAND_LOCAL_THD_HANDLE |The THD to run the query in. |
204 | |If null a new internal THD will |
205 | |be created. |
206--------------+-------------------------------+--------------------------------+
207const char * |MYSQL_COMMAND_PROTOCOL |Socket/pipe name for |
208 | |authentication. Null or "local" |
209 | |uses defaults; unused by |
210 | |embedded sessions. |
211--------------+-------------------------------+--------------------------------+
212const char * |MYSQL_COMMAND_USER_NAME |The user name to send to the |
213 | |server/set into the thread's |
214 | |security context. |
215--------------+-------------------------------+--------------------------------+
216const char * |MYSQL_COMMAND_HOST_NAME |The host name to use to |
217 | |connect/set into the thread's |
218 | |security context. |
219--------------+-------------------------------+--------------------------------+
220int |MYSQL_COMMAND_TCPIP_PORT |The port to use to connect. |
221--------------+-------------------------------+--------------------------------+
222const void * |MYSQL_NO_LOCK_REGISTRY |Non-null selects the no-lock |
223 | |registry; null selects the |
224 | |regular registry. |
225--------------+-------------------------------+--------------------------------+
226uint32_t |MYSQL_COMMAND_CLIENT_FLAGS |Client flags passed to |
227 | |mysql_real_connect() and exposed|
228 | |by the default capabilities |
229 | |consumer. |
230--------------+-------------------------------+--------------------------------+
231const char * |MYSQL_COMMAND_PASSWORD |Password used to authenticate |
232 | |against the current server. |
233--------------+-------------------------------+--------------------------------+
234bool |MYSQL_COMMAND_BYPASS_MAX_ |Bypass max_connections for new |
235 |CONNECTIONS |embedded sessions. Default: |
236 | |true. |
237--------------+-------------------------------+--------------------------------+
238
239 @note MYSQL_COMMAND_USER_NAME and MYSQL_COMMAND_HOST_NAME are copied by
240 set() and retained across failed connect() attempts until replaced or the
241 handle is closed. These options cannot be changed after an embedded
242 session is created.
243
244 @note MYSQL_COMMAND_PASSWORD is write-only and non-owning. The pointer must
245 remain valid until connect() returns. A non-null pointer, including an empty
246 string, selects normal authentication against the current server. A null
247 pointer selects the embedded backend. After an authenticated connection
248 attempt, close and reinitialize the handle before connecting again.
249
250 @note MYSQL_COMMAND_BYPASS_MAX_CONNECTIONS accepts a non-null bool pointer.
251 The default is true, preserving the connection-limit exemption. When false,
252 embedded sessions created by connect() are subject to max_connections and
253 cannot use the reserved extra connection slot. Both modes contribute to the
254 connection count and preserve the session's SQL privileges.
255 Administrative admission bypasses only the connection limit; other errors
256 can still prevent connection establishment.
257 Set this option before creating a session and only for embedded connections.
258 Normal admission is incompatible with MYSQL_COMMAND_LOCAL_THD_HANDLE and a
259 non-null MYSQL_COMMAND_PASSWORD. The setting survives failed connect()
260 attempts; get() returns the configured boolean.
261
262 @note Authenticated connections are limited to the current server's local
263 socket or named pipe, or loopback TCP endpoint. They are incompatible with
264 MYSQL_COMMAND_LOCAL_THD_HANDLE, MYSQL_NO_LOCK_REGISTRY,
265 MYSQL_TEXT_CONSUMER_* options, and client option-file settings. Loopback TCP
266 supports only literal bind_address values: *, the matching address-family
267 wildcard, or the matching loopback address. Hostname and multi-address
268 values are rejected. Loopback TCP defaults to preferred TLS and permits
269 server public-key retrieval.
270
271 @note For the other mysql client options it calls the mysql_options api.
272
273 @retval true failure
274 @retval false success
275*/
276DECLARE_BOOL_METHOD(set, (MYSQL_H mysql, int option, const void *arg));
277
278/**
279 Calls mysql_get_option api to returns the value of a mysql_options() option.
280
281 @param[in] mysql A valid mysql object.
282 @param[in] option The option argument is the option that you
283 want to get.
284 @param[out] arg The arg argument is the value
285 for the option to store.
286
287 @retval true failure
288 @retval false success
289*/
290DECLARE_BOOL_METHOD(get, (MYSQL_H mysql, int option, const void *arg));
291
292END_SERVICE_DEFINITION(mysql_command_options)
293
294/**
295 @ingroup group_components_services_inventory
296
297 A service that provides the apis for mysql command query and
298 affected_rows.
299*/
300BEGIN_SERVICE_DEFINITION(mysql_command_query)
301
302/**
303 Calls mysql_real_query api to executes an SQL query specified
304 as a counted string.
305
306 @param[in] mysql A valid mysql object.
307 @param[in] stmt_str SQL statement which has a query.
308 @param[in] length A string length bytes long.
309
310 @retval true failure
311 @retval false success
312*/
313DECLARE_BOOL_METHOD(query, (MYSQL_H mysql, const char *stmt_str,
314 unsigned long length));
315
316/**
317 Calls mysql_affected_rows api to return the number of rows
318 changed/deleted/inserted by the last UPDATE,DELETE or INSERT query.
319
320 @param[in] mysql A valid mysql object.
321 @param[out] *rows Number of rows affected, for SELECT stmt it tells
322 about number of rows present.
323
324 @retval true failure
325 @retval false success
326*/
327DECLARE_BOOL_METHOD(affected_rows, (MYSQL_H mysql, uint64_t *rows));
328END_SERVICE_DEFINITION(mysql_command_query)
329
330/**
331 @ingroup group_components_services_inventory
332
333 A service that provides the apis for mysql command, store_result,
334 free_result, more_results, next_result, result_metadata and fetch_row.
335*/
336BEGIN_SERVICE_DEFINITION(mysql_command_query_result)
337
338/**
339 Calls mysql_store_result api to retrieves a complete result set.
340
341 @param[in] mysql A valid mysql object.
342 @param[out] *mysql_res An mysql result object to get the result
343 set.
344
345 @retval true failure
346 @retval false success
347*/
348DECLARE_BOOL_METHOD(store_result, (MYSQL_H mysql, MYSQL_RES_H *mysql_res));
349
350/**
351 Calls mysql_free_result api to frees memory used by a result set.
352
353 @param[in] mysql_res An mysql result object to free the result
354 set.
355
356 @retval true failure
357 @retval false success
358*/
360
361/**
362 Calls mysql_more_results api to checks whether any more results exist.
363
364 @param[in] mysql A valid mysql object.
365
366 @retval true failure
367 @retval false success
368*/
370
371/**
372 Calls mysql_next_result api to returns/initiates the next result
373 in multiple-result executions.
374
375 @param[in] mysql A valid mysql object.
376
377 @retval -1 no more results
378 @retval >0 error
379 @retval 0 if yes more results exits(keep looping)
380*/
381DECLARE_METHOD(int, next_result, (MYSQL_H mysql));
382
383/**
384 Calls mysql_result_metadata api to whether a result set has metadata.
385
386 @param[in] res_h An mysql result object to get the metadata
387 info.
388
389 @retval true failure metadata_info not present.
390 @retval false success metadata_info present.
391*/
392DECLARE_BOOL_METHOD(result_metadata, (MYSQL_RES_H res_h));
393
394/**
395 Calls mysql_fetch_row api to fetches the next row from the result set.
396
397 @param[in] res_h An mysql result object to fetch a row from
398 the result set.
399 @param[out] *row To store the fetched row with server's charset.
400
401 @retval true failure
402 @retval false success
403*/
405
406/**
407 Calls mysql_fetch_lengths api to Returns the lengths of all columns
408 in the current row.
409
410 @param[in] res_h An mysql result object to fetch a row from
411 the result set.
412 @param[out] *length lengths of all columns.
413
414 @retval true failure
415 @retval false success
416*/
417DECLARE_BOOL_METHOD(fetch_lengths, (MYSQL_RES_H res_h, ulong **length));
418END_SERVICE_DEFINITION(mysql_command_query_result)
419
420/**
421 @ingroup group_components_services_inventory
422
423 A service that provides the apis for mysql command field info, fetch_field,
424 num_fields, fetch_fields and field_count.
425*/
426BEGIN_SERVICE_DEFINITION(mysql_command_field_info)
427
428/**
429 Calls mysql_fetch_field api to returns the type of next table field.
430
431 @param[in] res_h An mysql result object to return the next table
432 field.
433 @param[out] *field_h Stores the definition of one column of a result
434 set as a MYSQL_FIELD structure
435
436 @retval true failure
437 @retval false success
438*/
439DECLARE_BOOL_METHOD(fetch_field, (MYSQL_RES_H res_h, MYSQL_FIELD_H *field_h));
440
441/**
442 Calls mysql_num_fields api to returns the number of columns in a result set.
443
444 @param[in] res_h A valid mysql result set object.
445 @param[out] *num_fields Stores the number of columns in the result set.
446 @retval true failure
447 @retval false success
448*/
449DECLARE_BOOL_METHOD(num_fields, (MYSQL_RES_H res_h, unsigned int *num_fields));
450
451/**
452 Calls mysql_fetch_fields api to returns an array of all field structures.
453
454 @param[in] res_h A valid mysql result set object.
455 @param[out] **fields_h Stores the array of all fields for a result set.
456 @retval true failure
457 @retval false success
458*/
459DECLARE_BOOL_METHOD(fetch_fields,
460 (MYSQL_RES_H res_h, MYSQL_FIELD_H **fields_h));
461
462/**
463 Calls mysql_field_count api to returns the number of columns for the most
464 resent statement.
465
466 @param[in] mysql_h A valid mysql handle object.
467 @param[out] *num_fields Stores the number of columns for the last stmt.
468 @retval true failure
469 @retval false success
470*/
471DECLARE_BOOL_METHOD(field_count, (MYSQL_H mysql_h, unsigned int *num_fields));
472END_SERVICE_DEFINITION(mysql_command_field_info)
473
474#define MYSQL_COMMAND_FIELD_METADATA_NAME 0
475#define MYSQL_COMMAND_FIELD_METADATA_TABLE_NAME 1
476#define MYSQL_COMMAND_FIELD_METADATA_TABLE_DB_NAME 2
477
478/**
479 @ingroup group_components_services_inventory
480
481 Fetch the metadata of a service.
482
483 Usually used as follows:
484
485*/
486BEGIN_SERVICE_DEFINITION(mysql_command_field_metadata)
487/**
488 Retrieves the metadata for the field.
489
490 @param[in] mysql_field_h A valid mysql field handle object.
491 @param[in] metadata A metadata ID to fetch. Can be one of:
492
493--------------+-------------------------------------------+--------------------------------+
494 Type | Option |Explanation |
495--------------+-------------------------------------------+--------------------------------+
496const char * |MYSQL_COMMAND_FIELD_METADATA_NAME |The field name. |
497--------------+-------------------------------------------+--------------------------------+
498const char * |MYSQL_COMMAND_FIELD_METADATA_TABLE_NAME |The table name. |
499--------------+-------------------------------------------+--------------------------------+
500const char * |MYSQL_COMMAND_FIELD_METADATA_TABLE_DB_NAME |The table database
501name. |
502--------------+-------------------------------------------+--------------------------------+
503
504 @param[out] data A buffer to receive the data fetched.
505 @retval true failure
506 @retval false success
507*/
509 (MYSQL_FIELD_H mysql_field_h, int metadata, void *data));
510END_SERVICE_DEFINITION(mysql_command_field_metadata)
511
512/**
513 @ingroup group_components_services_inventory
514
515 A service that provides the apis for mysql command error info, mysql_errno,
516 error, sqlstate.
517*/
518BEGIN_SERVICE_DEFINITION(mysql_command_error_info)
519
520/**
521 Calls mysql_errno api to return the number of most recently invoked mysql
522 function.
523
524 @param[in] mysql_h A valid mysql handle object.
525 @param[out] *err_no Stores the error number of last mysql function.
526 @retval true failure
527 @retval false success
528*/
529DECLARE_BOOL_METHOD(sql_errno, (MYSQL_H mysql_h, unsigned int *err_no));
530
531/**
532 Calls mysql_error api to return the error message of most recently invoked
533 mysql function.
534
535 @param[in] mysql_h A valid mysql handle object.
536 @param[out] *errmsg Stores the error message of last mysql function.
537 @retval true failure
538 @retval false success
539*/
540DECLARE_BOOL_METHOD(sql_error, (MYSQL_H mysql_h, char **errmsg));
541
542/**
543 Calls mysql_sqlstate api to return the SQLSTATE error code for the last error.
544
545 @param[in] mysql_h A valid mysql handle object.
546 @param[out] *sqlstate_errmsg Stores the SQLSTATE error message of the most
547 recently executed SQL stmt.
548 @retval true failure
549 @retval false success
550*/
551DECLARE_BOOL_METHOD(sql_state, (MYSQL_H mysql_h, char **sqlstate_errmsg));
552END_SERVICE_DEFINITION(mysql_command_error_info)
553
554#endif /* MYSQL_COMMAND_SERVICE_H */
static mysql_service_status_t init()
Component initialization.
Definition: audit_api_message_emit.cc:575
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_COMMAND_PASSWORD
Definition: mysql_command_services.h:67
@ 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_COMMAND_BYPASS_MAX_CONNECTIONS
Definition: mysql_command_services.h:68
@ 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: system_info_linux.cc:46
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