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