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