1 /* Copyright (c) 2015, 2021, 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 Foundation,
21    51 Franklin Street, Suite 500, Boston, MA 02110-1335 USA */
22 
23 #ifndef SQL_SERVICE_CONTEXT_INCLUDE
24 #define SQL_SERVICE_CONTEXT_INCLUDE
25 
26 #include "sql_service_context_base.h"
27 
28 class Sql_service_context : public Sql_service_context_base
29 {
30 public:
Sql_service_context(Sql_resultset * rset)31   Sql_service_context(Sql_resultset *rset)
32     :resultset(rset)
33   {
34     if (rset != NULL)
35       resultset->clear();
36   }
37 
~Sql_service_context()38   ~Sql_service_context() {}
39 
40 
41   /** Getting metadata **/
42   /**
43     Indicates start of metadata for the result set
44 
45     @param num_cols Number of fields being sent
46     @param flags    Flags to alter the metadata sending
47     @param resultcs Charset of the result set
48 
49     @return
50       @retval 1  Error
51       @retval 0  OK
52   */
53   int start_result_metadata(uint num_cols, uint flags,
54                             const CHARSET_INFO *resultcs);
55 
56   /**
57     Field metadata is provided via this callback
58 
59     @param field   Field's metadata (see field.h)
60     @param charset Field's charset
61 
62     @return
63       @retval 1  Error
64       @retval 0  OK
65   */
66   int field_metadata(struct st_send_field *field,
67                      const CHARSET_INFO *charset);
68 
69   /**
70     Indicates end of metadata for the result set
71 
72     @param server_status   Status of server (see mysql_com.h SERVER_STATUS_*)
73     @param warn_count      Number of warnings thrown during execution
74 
75     @return
76       @retval 1  Error
77       @retval 0  OK
78   */
79   int end_result_metadata(uint server_status,
80                           uint warn_count);
81 
82   /**
83     Indicates the beginning of a new row in the result set/metadata
84 
85     @return
86       @retval 1  Error
87       @retval 0  OK
88   */
89   int start_row();
90 
91   /**
92     Indicates end of the row in the result set/metadata
93 
94     @return
95       @retval 1  Error
96       @retval 0  OK
97   */
98   int end_row();
99 
100   /**
101     An error occured during execution
102 
103     @details This callback indicates that an error occureded during command
104     execution and the partial row should be dropped. Server will raise error
105     and return.
106   */
107   void abort_row();
108 
109   /**
110     Return client's capabilities (see mysql_com.h, CLIENT_*)
111 
112     @return Bitmap of client's capabilities
113   */
114   ulong get_client_capabilities();
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   int get_null();
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   int get_integer(longlong value);
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   int get_longlong(longlong value, uint is_unsigned);
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   int get_decimal(const decimal_t * value);
162 
163   /**
164     Receive DOUBLE value from server
165 
166     @return status
167       @retval 1  Error
168       @retval 0  OK
169   */
170   int get_double(double value, uint32 decimals);
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   int get_date(const MYSQL_TIME * value);
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   int get_time(const MYSQL_TIME * value, uint decimals);
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   int get_datetime(const MYSQL_TIME * value,
206                    uint decimals);
207 
208   /**
209     Get STRING value from server
210 
211     @param value   Value received
212     @param length  Value's length
213     @param valuecs Value's charset
214 
215     @return status
216       @retval 1  Error
217       @retval 0  OK
218   */
219   int get_string(const char * const value,
220                  size_t length, const CHARSET_INFO * const valuecs);
221 
222   /** Getting execution status **/
223   /**
224     Command ended with success
225 
226     @param server_status        Status of server (see mysql_com.h,
227                                 SERVER_STATUS_*)
228     @param statement_warn_count Number of warnings thrown during execution
229     @param affected_rows        Number of rows affected by the command
230     @param last_insert_id       Last insert id being assigned during execution
231     @param message              A message from server
232   */
233   void handle_ok(uint server_status, uint statement_warn_count,
234                  ulonglong affected_rows, ulonglong last_insert_id,
235                  const char * const message);
236 
237   /**
238     Command ended with ERROR
239 
240     @param sql_errno Error code
241     @param err_msg   Error message
242     @param sqlstate  SQL state correspongin to the error code
243   */
244   void handle_error(uint sql_errno,
245                     const char * const err_msg,
246                     const char * const sqlstate);
247 
248   /**
249     Session was shutdown while command was running
250   */
251   void shutdown(int flag);
252 
253 private:
254   /* executed command result store */
255   Sql_resultset *resultset;
256 };
257 
258 #endif //SQL_SERVICE_CONTEXT_INCLUDE
259