MySQL 8.0.39
Source Code Documentation
mysql_connection_attributes_iterator.h
Go to the documentation of this file.
1/* Copyright (c) 2019, 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_CONNECTION_ATTRIBUTES_ITERATOR_H
25#define MYSQL_CONNECTION_ATTRIBUTES_ITERATOR_H
26
29#include <stddef.h>
30
31/**
32 @ingroup group_components_services_inventory
33
34 A service to read the connection attributes from the current session
35 It provides a read-only iterator over the attributes.
36 This is some example code to use the iterator:
37
38 @code
39
40 // at init time. try to reuse the service handles as much as possible
41
42 my_service<SERVICE_TYPE(mysql_current_thread_reader)> thd_reader(
43 "mysql_current_thread_reader", m_reg_srv);
44 my_service<SERVICE_TYPE(mysql_connection_attributes_iterator)> service(
45 "mysql_connection_attributes_iterator", m_reg_srv);
46
47 if (!service.is_valid() || !thd_reader.is_valid) {
48 return; //error
49 }
50
51 ...
52
53 // at parse time
54
55 MYSQL_THD thd;
56 if (thd_reader->get(&thd))
57 return; //error
58
59 my_h_connection_attributes_iterator iterator;
60
61 MYSQL_LEX_CSTRING name;
62 MYSQL_LEX_CSTRING value;
63 const char *charset_string;
64 const CHARSET_INFO *charset = nullptr;
65
66 my_h_connection_attributes_iterator iterator;
67 if (service->init(thd, &iterator)) return; // error
68
69 while (!service->get(thd, &iterator, &name.str, &name.length, &value.str,
70 &value.length, &charset_string)) {
71 // Do something with name and value
72 }
73
74 service->deinit(iterator);
75
76 @endcode
77*/
78
80
81BEGIN_SERVICE_DEFINITION(mysql_connection_attributes_iterator)
82
83/**
84 Initialize an iterator.
85
86 Also position at the first attribute.
87
88 @param thd The session to operate on. Can be NULL to use the
89 current THD.
90 @param[out] iterator Iterator pointer.
91
92 @return
93 @retval false Succeeded.
94 @retval true Failed.
95
96 @sa mysql_connection_attributes_iterator_imp::init
97*/
100
101/**
102 Deinitialize an iterator.
103
104 @param iterator Iterator pointer.
105
106 @return
107 @retval false Succeeded.
108 @retval true Failed.
109
110 @sa mysql_connection_attributes_iterator_imp::deinit
111*/
113
114/**
115 Fetch the current name/value pair from the iterator and move it forward.
116 Note: the attribute's name and value pointers are valid until the THD object
117 is alive.
118
119 @param thd The session to operate on. Can be NULL to use the
120 current THD.
121 @param iterator Iterator pointer.
122 @param[out] name The attribute name.
123 @param[out] name_length The attribute name's length.
124 @param[out] value The attribute value.
125 @param[out] value_length The attribute value's length.
126 @param[out] client_charset The character set, used for encoding the
127 connection attributes pair
128
129 @return
130 @retval false Succeeded.
131 @retval true Failed.
132
133 @sa mysql_connection_attributes_iterator_imp::get
134*/
136 (MYSQL_THD thd,
138 const char **name, size_t *name_length, const char **value,
139 size_t *value_length, const char **client_charset));
140
141END_SERVICE_DEFINITION(mysql_connection_attributes_iterator)
142
143#endif /* MYSQL_CONNECTION_ATTRIBUTES_ITERATOR_H */
static mysql_service_status_t deinit()
Component deinitialization.
Definition: audit_api_message_emit.cc:580
static mysql_service_status_t init()
Component initialization.
Definition: audit_api_message_emit.cc:571
#define MYSQL_THD
Definition: backup_page_tracker.h:38
const char * my_h_connection_attributes_iterator
A service to read the connection attributes from the current session It provides a read-only iterator...
Definition: mysql_connection_attributes_iterator.h:79
void get(PSI_field *, PSI_longlong *) noexcept
Definition: pfs_plugin_column_bigint_v1_all_empty.cc:32
#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 DECLARE_BOOL_METHOD(name, args)
Declares a method that returns bool as a part of the Service definition.
Definition: service.h:112
case opt name
Definition: sslopt-case.h:33