MySQL 8.0.37
Source Code Documentation
sql_service_context_base.h
Go to the documentation of this file.
1/* Copyright (c) 2015, 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 SQL_SERVICE_CONTEXT_BASE_INCLUDE
25#define SQL_SERVICE_CONTEXT_BASE_INCLUDE
26
27#include <mysql/plugin.h>
29
30#include "my_inttypes.h"
32
34 public:
35 /** The sql service callbacks that will call the below virtual methods*/
37
38 /**
39 Sql_service_context_base constructor
40 resets all variables
41 */
43
44 virtual ~Sql_service_context_base() = default;
45
46 /** Getting metadata **/
47 /**
48 Indicates start of metadata for the result set
49
50 @param num_cols Number of fields being sent
51 @param flags Flags to alter the metadata sending
52 @param resultcs Charset of the result set
53
54 @retval 1 Error
55 @retval 0 OK
56 */
57 virtual int start_result_metadata(uint num_cols, uint flags,
58 const CHARSET_INFO *resultcs) = 0;
59
60 /**
61 Field metadata is provided via this callback
62
63 @param field Field's metadata (see field.h)
64 @param charset Field's charset
65
66 @retval 1 Error
67 @retval 0 OK
68 */
69 virtual int field_metadata(struct st_send_field *field,
70 const CHARSET_INFO *charset) = 0;
71
72 /**
73 Indicates end of metadata for the result set
74
75 @param server_status Status of server (see mysql_com.h SERVER_STATUS_*)
76 @param warn_count Number of warnings thrown during execution
77
78 @retval 1 Error
79 @retval 0 OK
80 */
81 virtual int end_result_metadata(uint server_status, uint warn_count) = 0;
82
83 /**
84 Indicates the beginning of a new row in the result set/metadata
85
86 @retval 1 Error
87 @retval 0 OK
88 */
89 virtual int start_row() = 0;
90
91 /**
92 Indicates end of the row in the result set/metadata
93
94 @retval 1 Error
95 @retval 0 OK
96 */
97 virtual int end_row() = 0;
98
99 /**
100 An error occurred during execution
101
102 @details This callback indicates that an error occurreded during command
103 execution and the partial row should be dropped. Server will raise error
104 and return.
105 */
106 virtual void abort_row() = 0;
107
108 /**
109 Return client's capabilities (see mysql_com.h, CLIENT_*)
110
111 @return Bitmap of client's capabilities
112 */
113 virtual ulong get_client_capabilities() = 0;
114
115 /** Getting data **/
116 /**
117 Receive NULL value from server
118
119 @return status
120 @retval 1 Error
121 @retval 0 OK
122 */
123 virtual int get_null() = 0;
124
125 /**
126 Get TINY/SHORT/LONG value from server
127
128 @param value Value received
129
130 @note In order to know which type exactly was received, the plugin must
131 track the metadata that was sent just prior to the result set.
132
133 @return status
134 @retval 1 Error
135 @retval 0 OK
136 */
137 virtual int get_integer(longlong value) = 0;
138
139 /**
140 Get LONGLONG value from server
141
142 @param value Value received
143 @param is_unsigned TRUE <=> value is unsigned
144
145 @return status
146 @retval 1 Error
147 @retval 0 OK
148 */
149 virtual int get_longlong(longlong value, uint is_unsigned) = 0;
150
151 /**
152 Receive DECIMAL value from server
153
154 @param value Value received
155
156 @return status
157 @retval 1 Error
158 @retval 0 OK
159 */
160 virtual int get_decimal(const decimal_t *value) = 0;
161
162 /**
163
164 @return status
165 @retval 1 Error
166 @retval 0 OK
167 */
168 virtual int get_double(double value, uint32 decimals) = 0;
169
170 /**
171 Get DATE value from server
172
173 @param value Value received
174
175 @return status
176 @retval 1 Error
177 @retval 0 OK
178 */
179 virtual int get_date(const MYSQL_TIME *value) = 0;
180
181 /**
182 Get TIME value from server
183
184 @param value Value received
185 @param decimals Number of decimals
186
187 @return status
188 @retval 1 Error
189 @retval 0 OK
190 */
191 virtual int get_time(const MYSQL_TIME *value, uint decimals) = 0;
192
193 /**
194 Get DATETIME value from server
195
196 @param value Value received
197 @param decimals Number of decimals
198
199 @return status
200 @retval 1 Error
201 @retval 0 OK
202 */
203 virtual int get_datetime(const MYSQL_TIME *value, uint decimals) = 0;
204
205 /**
206 Get STRING value from server
207
208 @param value Value received
209 @param length Value's length
210 @param valuecs Value's charset
211
212 @return status
213 @retval 1 Error
214 @retval 0 OK
215 */
216 virtual int get_string(const char *const value, size_t length,
217 const CHARSET_INFO *const valuecs) = 0;
218
219 /** Getting execution status **/
220 /**
221 Command ended with success
222
223 @param server_status Status of server (see mysql_com.h,
224 SERVER_STATUS_*)
225 @param statement_warn_count Number of warnings thrown during execution
226 @param affected_rows Number of rows affected by the command
227 @param last_insert_id Last insert id being assigned during execution
228 @param message A message from server
229 */
230 virtual void handle_ok(uint server_status, uint statement_warn_count,
231 ulonglong affected_rows, ulonglong last_insert_id,
232 const char *const message) = 0;
233
234 /**
235 Command ended with ERROR
236
237 @param sql_errno Error code
238 @param err_msg Error message
239 @param sqlstate SQL state corresponding to the error code
240 */
241 virtual void handle_error(uint sql_errno, const char *const err_msg,
242 const char *const sqlstate) = 0;
243
244 /**
245 Session was shutdown while command was running
246 */
247 virtual void shutdown(int flag) = 0;
248
249 /**
250 Check if the connection is still alive.
251 It should always return true unless the protocol closed the connection.
252 */
253 virtual bool connection_alive() = 0;
254
255 private:
256 static int sql_start_result_metadata(void *ctx, uint num_cols, uint flags,
257 const CHARSET_INFO *resultcs) {
258 return ((Sql_service_context_base *)ctx)
259 ->start_result_metadata(num_cols, flags, resultcs);
260 }
261
262 static int sql_field_metadata(void *ctx, struct st_send_field *field,
263 const CHARSET_INFO *charset) {
264 return ((Sql_service_context_base *)ctx)->field_metadata(field, charset);
265 }
266
267 static int sql_end_result_metadata(void *ctx, uint server_status,
268 uint warn_count) {
269 return ((Sql_service_context_base *)ctx)
270 ->end_result_metadata(server_status, warn_count);
271 }
272
273 static int sql_start_row(void *ctx) {
274 return ((Sql_service_context_base *)ctx)->start_row();
275 }
276
277 static int sql_end_row(void *ctx) {
278 return ((Sql_service_context_base *)ctx)->end_row();
279 }
280
281 static void sql_abort_row(void *ctx) {
282 return ((Sql_service_context_base *)ctx)
283 ->abort_row(); /* purecov: inspected */
284 }
285
286 static ulong sql_get_client_capabilities(void *ctx) {
287 return ((Sql_service_context_base *)ctx)->get_client_capabilities();
288 }
289
290 static int sql_get_null(void *ctx) {
291 return ((Sql_service_context_base *)ctx)->get_null();
292 }
293
294 static int sql_get_integer(void *ctx, longlong value) {
295 return ((Sql_service_context_base *)ctx)->get_integer(value);
296 }
297
298 static int sql_get_longlong(void *ctx, longlong value, uint is_unsigned) {
299 return ((Sql_service_context_base *)ctx)->get_longlong(value, is_unsigned);
300 }
301
302 static int sql_get_decimal(void *ctx, const decimal_t *value) {
303 return ((Sql_service_context_base *)ctx)->get_decimal(value);
304 }
305
306 static int sql_get_double(void *ctx, double value, uint32 decimals) {
307 return ((Sql_service_context_base *)ctx)->get_double(value, decimals);
308 }
309
310 static int sql_get_date(void *ctx, const MYSQL_TIME *value) {
311 return ((Sql_service_context_base *)ctx)->get_date(value);
312 }
313
314 static int sql_get_time(void *ctx, const MYSQL_TIME *value, uint decimals) {
315 return ((Sql_service_context_base *)ctx)->get_time(value, decimals);
316 }
317
318 static int sql_get_datetime(void *ctx, const MYSQL_TIME *value,
319 uint decimals) {
320 return ((Sql_service_context_base *)ctx)->get_datetime(value, decimals);
321 }
322
323 static int sql_get_string(void *ctx, const char *const value, size_t length,
324 const CHARSET_INFO *const valuecs) {
325 return ((Sql_service_context_base *)ctx)
326 ->get_string(value, length, valuecs);
327 }
328
329 static void sql_handle_ok(void *ctx, uint server_status,
330 uint statement_warn_count, ulonglong affected_rows,
331 ulonglong last_insert_id,
332 const char *const message) {
333 return ((Sql_service_context_base *)ctx)
334 ->handle_ok(server_status, statement_warn_count, affected_rows,
335 last_insert_id, message);
336 }
337
338 static void sql_handle_error(void *ctx, uint sql_errno,
339 const char *const err_msg,
340 const char *const sqlstate) {
341 return ((Sql_service_context_base *)ctx)
342 ->handle_error(sql_errno, err_msg, sqlstate);
343 }
344
345 static void sql_shutdown(void *ctx, int flag) {
346 return ((Sql_service_context_base *)ctx)->shutdown(flag);
347 }
348
349 static bool sql_connection_alive(void *ctx) {
350 return ((Sql_service_context_base *)ctx)->connection_alive();
351 }
352};
353
354#endif // SQL_SERVICE_CONTEXT_BASE_INCLUDE
Definition: sql_service_context_base.h:33
virtual int start_row()=0
Indicates the beginning of a new row in the result set/metadata.
virtual int end_row()=0
Indicates end of the row in the result set/metadata.
static ulong sql_get_client_capabilities(void *ctx)
Definition: sql_service_context_base.h:286
virtual int get_null()=0
Getting data.
virtual void abort_row()=0
An error occurred during execution.
virtual void shutdown(int flag)=0
Session was shutdown while command was running.
virtual int get_datetime(const MYSQL_TIME *value, uint decimals)=0
Get DATETIME value from server.
virtual ulong get_client_capabilities()=0
Return client's capabilities (see mysql_com.h, CLIENT_*)
virtual int get_time(const MYSQL_TIME *value, uint decimals)=0
Get TIME value from server.
static int sql_get_date(void *ctx, const MYSQL_TIME *value)
Definition: sql_service_context_base.h:310
virtual int end_result_metadata(uint server_status, uint warn_count)=0
Indicates end of metadata for the result set.
static int sql_end_row(void *ctx)
Definition: sql_service_context_base.h:277
virtual void handle_ok(uint server_status, uint statement_warn_count, ulonglong affected_rows, ulonglong last_insert_id, const char *const message)=0
Getting execution status.
static int sql_get_integer(void *ctx, longlong value)
Definition: sql_service_context_base.h:294
static void sql_abort_row(void *ctx)
Definition: sql_service_context_base.h:281
virtual int get_integer(longlong value)=0
Get TINY/SHORT/LONG value from server.
static int sql_get_datetime(void *ctx, const MYSQL_TIME *value, uint decimals)
Definition: sql_service_context_base.h:318
Sql_service_context_base()=default
Sql_service_context_base constructor resets all variables.
virtual int get_double(double value, uint32 decimals)=0
static int sql_end_result_metadata(void *ctx, uint server_status, uint warn_count)
Definition: sql_service_context_base.h:267
virtual bool connection_alive()=0
Check if the connection is still alive.
static void sql_shutdown(void *ctx, int flag)
Definition: sql_service_context_base.h:345
virtual int start_result_metadata(uint num_cols, uint flags, const CHARSET_INFO *resultcs)=0
Getting metadata.
virtual ~Sql_service_context_base()=default
static bool sql_connection_alive(void *ctx)
Definition: sql_service_context_base.h:349
static int sql_get_longlong(void *ctx, longlong value, uint is_unsigned)
Definition: sql_service_context_base.h:298
virtual int get_string(const char *const value, size_t length, const CHARSET_INFO *const valuecs)=0
Get STRING value from server.
virtual int get_date(const MYSQL_TIME *value)=0
Get DATE value from server.
static int sql_get_double(void *ctx, double value, uint32 decimals)
Definition: sql_service_context_base.h:306
static int sql_start_row(void *ctx)
Definition: sql_service_context_base.h:273
static int sql_field_metadata(void *ctx, struct st_send_field *field, const CHARSET_INFO *charset)
Definition: sql_service_context_base.h:262
static int sql_get_string(void *ctx, const char *const value, size_t length, const CHARSET_INFO *const valuecs)
Definition: sql_service_context_base.h:323
virtual int get_decimal(const decimal_t *value)=0
Receive DECIMAL value from server.
static int sql_get_time(void *ctx, const MYSQL_TIME *value, uint decimals)
Definition: sql_service_context_base.h:314
virtual int field_metadata(struct st_send_field *field, const CHARSET_INFO *charset)=0
Field metadata is provided via this callback.
static int sql_get_decimal(void *ctx, const decimal_t *value)
Definition: sql_service_context_base.h:302
static void sql_handle_error(void *ctx, uint sql_errno, const char *const err_msg, const char *const sqlstate)
Definition: sql_service_context_base.h:338
static int sql_get_null(void *ctx)
Definition: sql_service_context_base.h:290
static const st_command_service_cbs sql_service_callbacks
The sql service callbacks that will call the below virtual methods.
Definition: sql_service_context_base.h:36
virtual void handle_error(uint sql_errno, const char *const err_msg, const char *const sqlstate)=0
Command ended with ERROR.
static int sql_start_result_metadata(void *ctx, uint num_cols, uint flags, const CHARSET_INFO *resultcs)
Definition: sql_service_context_base.h:256
virtual int get_longlong(longlong value, uint is_unsigned)=0
Get LONGLONG value from server.
static void sql_handle_ok(void *ctx, uint server_status, uint statement_warn_count, ulonglong affected_rows, ulonglong last_insert_id, const char *const message)
Definition: sql_service_context_base.h:329
static int flags[50]
Definition: hp_test1.cc:40
static int flag
Definition: hp_test1.cc:40
Some integer typedefs for easier portability.
unsigned long long int ulonglong
Definition: my_inttypes.h:56
long long int longlong
Definition: my_inttypes.h:55
uint32_t uint32
Definition: my_inttypes.h:67
constexpr value_type is_unsigned
Definition: classic_protocol_constants.h:273
const std::string charset("charset")
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
Header file for the Command service.
Definition: m_ctype.h:385
Definition: mysql_time.h:82
intg is the number of decimal digits (NOT number of decimal_digit_t's !) before the point frac is the...
Definition: decimal.h:52
Definition: service_command.h:328
Definition: service_command.h:45
unsigned int uint
Definition: uca9-dump.cc:75