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