MySQL 8.0.39
Source Code Documentation
utils.h
Go to the documentation of this file.
1/* Copyright (c) 2014, 2024, Oracle and/or its affiliates.
2
3 This program is free software; you can redistribute it and/or modify
4 it under the terms of the GNU General Public License, version 2.0,
5 as published by the Free Software Foundation.
6
7 This program is designed to work with certain software (including
8 but not limited to OpenSSL) that is licensed under separate terms,
9 as designated in a particular file or component or in included license
10 documentation. The authors of MySQL hereby grant you an additional
11 permission to link the program and your derivative works with the
12 separately licensed software that they have either included with
13 the program or referenced in the documentation.
14
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License, version 2.0, for more details.
19
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
23
24#ifndef DD__UTILS_INCLUDED
25#define DD__UTILS_INCLUDED
26
27#include "sql/dd/string_type.h" // dd::String_type
28#include "sql/tztime.h" // my_tz_OFFSET0
29
30struct CHARSET_INFO;
31
32class THD;
33
34namespace dd {
35/**
36 Create a lex string for the query from the string supplied
37 and execute the query.
38
39 @param thd Thread handle.
40 @param q_buf String containing the query text.
41
42 @retval false Success.
43 @retval true Error.
44*/
45bool execute_query(THD *thd, const dd::String_type &q_buf);
46
47///////////////////////////////////////////////////////////////////////////
48
49class Properties;
50
51/**
52 Escaping of a String_type. Escapable characters are '\', '=' and
53 ';'. Escape character is '\'. Iterate over all characters of src,
54 precede all escapable characters by the escape character and append
55 to dst. The source string is not modified.
56
57 @param[out] dst string to which escaped result will be appended.
58 @param[in] src source string for escaping
59*/
60void escape(String_type *dst, const String_type &src);
61
62/**
63 In place unescaping of String_type. Escapable characters are '\', '='
64 and ';'. Escape character is '\'. Iterate over all characters, remove
65 escape character if it precedes an escapable character.
66
67 @param[in,out] dest source and destination string for escaping
68 @return Operation status
69 @retval true if an escapable character is not escaped
70 @retval false if success
71*/
72bool unescape(String_type &dest);
73
74/**
75 Start at it, iterate until we hit an unescaped c or the end
76 of the string. The stop character c may be ';' or '='. The
77 escape character is '\'. Escapable characters are '\', '='
78 and ';'. Hitting an unescaped '=' while searching for ';' is
79 an error, and also the opposite. Hitting end of string while
80 searching for '=' is an error, but end of string while
81 searching for ';' is ok.
82
83 In the event of success, the iterator will be at the
84 character to be searched for, or at the end of the string.
85
86 @param[in,out] it string iterator
87 @param end iterator pointing to string end
88 @param c character to search for
89
90 @return Operation status
91 @retval true if an error occurred
92 @retval false if success
93*/
94bool eat_to(String_type::const_iterator &it, String_type::const_iterator end,
95 char c);
96
97/**
98 Start at it, find first unescaped occorrence of c, create
99 destination string and copy substring to destination. Unescape
100 the destination string, advance the iterator to get to the
101 next character after c, or to end of string.
102
103 In the event of success, the iterator will be at the next
104 character after the one that was to be searched for, or at the
105 end of the string.
106
107 @param[out] dest destination string
108 @param[in,out] it string iterator
109 @param end iterator pointing to string end
110 @param c character to search for
111
112 @return Operation status
113 @retval true if an error occurred
114 @retval false if success
115*/
116bool eat_str(String_type &dest, String_type::const_iterator &it,
117 String_type::const_iterator end, char c);
118
119/**
120 Start at it, find a key and value separated by an unescaped '='. Value
121 is supposed to be terminated by an unescaped ';' or by the end of the
122 string. Unescape the key and value and add them to the property
123 object. Call recursively to find the remaining pairs.
124
125 @param[in,out] props property object where key and value should be added
126 @param[in,out] it string iterator
127 @param end iterator pointing to string end
128
129 @return Operation status
130 @retval true if an error occurred
131 @retval false if success
132*/
133bool eat_pairs(String_type::const_iterator &it, String_type::const_iterator end,
134 dd::Properties *props);
135
136///////////////////////////////////////////////////////////////////////////
137
138/**
139 Convert seconds since epoch, to a datetime ulonglong using my_tz_OFFSET0
140 suitable for timestamp fields in the DD.
141
142 @param seconds_since_epoch value to convert
143 @return time value converted to datetime ulonglong
144 */
146
147///////////////////////////////////////////////////////////////////////////
148
149/**
150 Method to verify if string is in lowercase.
151
152 @param str String to verify.
153 @param cs Character set.
154
155 @retval true If string is in lowercase.
156 @retval false Otherwise.
157*/
159
160///////////////////////////////////////////////////////////////////////////
161
162/**
163 Helper function to do rollback or commit, depending on
164 error. Also closes tables and releases transactional
165 locks, regardless of error.
166
167 @param thd Thread
168 @param error If true, the transaction will be rolledback.
169 otherwise, it is committed.
170
171 @returns false on success, otherwise true.
172*/
173bool end_transaction(THD *thd, bool error);
174
175} // namespace dd
176
177#endif // DD__UTILS_INCLUDED
For each client connection we create a separate thread with THD serving as a thread/connection descri...
Definition: sql_lexer_thd.h:34
The Properties class defines an interface for storing key=value pairs, where both key and value may b...
Definition: properties.h:74
unsigned long long int ulonglong
Definition: my_inttypes.h:56
int64_t my_time_t
Portable time_t replacement.
Definition: my_time_t.h:32
std::string str(const mysqlrouter::ConfigGenerator::Options::Endpoint &ep)
Definition: config_generator.cc:1052
Definition: commit_order_queue.h:34
The version of the current data dictionary table definitions.
Definition: dictionary_client.h:43
bool eat_to(String_type::const_iterator &it, String_type::const_iterator end, char c)
Start at it, iterate until we hit an unescaped c or the end of the string.
Definition: utils.cc:95
bool unescape(String_type &dest)
In place unescaping of String_type.
Definition: utils.cc:74
bool execute_query(THD *thd, const dd::String_type &q_buf)
Create a lex string for the query from the string supplied and execute the query.
Definition: utils.cc:44
bool end_transaction(THD *thd, bool error)
Helper function to do rollback or commit, depending on error.
Definition: utils.cc:181
bool eat_pairs(String_type::const_iterator &it, String_type::const_iterator end, dd::Properties *props)
Start at it, find a key and value separated by an unescaped '='.
Definition: utils.cc:144
void escape(String_type *sp, const String_type &src)
Escaping of a String_type.
Definition: utils.cc:62
bool eat_str(String_type &dest, String_type::const_iterator &it, String_type::const_iterator end, char c)
Start at it, find first unescaped occorrence of c, create destination string and copy substring to de...
Definition: utils.cc:122
bool is_string_in_lowercase(const String_type &str, const CHARSET_INFO *cs)
Method to verify if string is in lowercase.
Definition: utils.cc:172
Char_string_template< String_type_allocator > String_type
Definition: string_type.h:51
ulonglong my_time_t_to_ull_datetime(my_time_t seconds_since_epoch)
Convert seconds since epoch, to a datetime ulonglong using my_tz_OFFSET0 suitable for timestamp field...
Definition: utils.cc:164
Cursor end()
A past-the-end Cursor.
Definition: rules_table_service.cc:192
Definition: m_ctype.h:385