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