1 /*
2  * Copyright (c) 2014, 2021, Oracle and/or its affiliates.
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License, version 2.0, as
6  * published by the Free Software Foundation.
7  *
8  * This program is also distributed with certain software (including
9  * but not limited to OpenSSL) that is licensed under separate terms,
10  * as designated in a particular file or component or in included license
11  * documentation.  The authors of MySQL hereby grant you an
12  * additional permission to link the program and your derivative works
13  * with the separately licensed software that they have included with
14  * MySQL.
15  *
16  * Without limiting anything contained in the foregoing, this file,
17  * which is part of MySQL Connector/Python, is also subject to the
18  * Universal FOSS Exception, version 1.0, a copy of which can be found at
19  * http://oss.oracle.com/licenses/universal-foss-exception.
20  *
21  * This program is distributed in the hope that it will be useful, but
22  * WITHOUT ANY WARRANTY; without even the implied warranty of
23  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
24  * See the GNU General Public License, version 2.0, for more details.
25  *
26  * You should have received a copy of the GNU General Public License
27  * along with this program; if not, write to the Free Software Foundation, Inc.,
28  * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA
29  */
30 
31 #ifndef MYCONNPY_MYSQL_CAPI_H
32 #define MYCONNPY_MYSQL_CAPI_H
33 
34 #include <Python.h>
35 #include <mysql.h>
36 #include "structmember.h"
37 
38 #if MYSQL_VERSION_ID >= 80001
39 typedef bool bool_;
40 #else
41 typedef my_bool bool_;
42 #endif
43 
44 /* MySQL */
45 
46 typedef struct {
47     PyObject_HEAD
48     // private
49     MYSQL session;
50     MYSQL_RES *result;
51     unsigned char connected;
52     int result_num_fields;
53     unsigned int use_unicode;
54     PyObject *buffered;
55     PyObject *raw;
56     PyObject *raw_as_string;
57     PyObject *buffered_at_connect;
58     PyObject *raw_at_connect;
59     PyObject *charset_name;
60     PyObject *have_result_set;
61     PyObject *fields;
62     PyObject *auth_plugin;
63     PyObject *plugin_dir;
64     PyObject *converter_str_fallback;
65     MY_CHARSET_INFO cs;
66     unsigned int connection_timeout;
67     // class members
68 
69 } MySQL;
70 
71 void
72 MySQL_dealloc(MySQL *self);
73 
74 PyObject *
75 MySQL_new(PyTypeObject *type, PyObject *args, PyObject *kwds);
76 
77 int
78 MySQL_init(MySQL *self, PyObject *args, PyObject *kwds);
79 
80 PyObject *
81 MySQL_buffered(MySQL *self, PyObject *args);
82 
83 PyObject *
84 MySQL_raw(MySQL *self, PyObject *args);
85 
86 PyObject *
87 MySQL_connected(MySQL *self);
88 
89 PyObject*
90 MySQL_st_affected_rows(MySQL *self);
91 
92 PyObject*
93 MySQL_st_client_flag(MySQL *self);
94 
95 PyObject*
96 MySQL_st_field_count(MySQL *self);
97 
98 PyObject*
99 MySQL_st_insert_id(MySQL *self);
100 
101 PyObject*
102 MySQL_st_server_capabilities(MySQL *self);
103 
104 PyObject*
105 MySQL_st_server_status(MySQL *self);
106 
107 PyObject*
108 MySQL_st_warning_count(MySQL *self);
109 
110 PyObject*
111 MySQL_convert_to_mysql(MySQL *self, PyObject *args);
112 
113 PyObject*
114 MySQL_handle_result(MySQL *self);
115 
116 PyObject*
117 MySQL_consume_result(MySQL *self);
118 
119 PyObject*
120 MySQL_reset_result(MySQL *self);
121 
122 /*
123  * MySQL C API functions mapping
124  */
125 
126 PyObject*
127 MySQL_autocommit(MySQL *self, PyObject *mode);
128 
129 PyObject*
130 MySQL_affected_rows(MySQL *self);
131 
132 PyObject*
133 MySQL_change_user(MySQL *self, PyObject *args, PyObject *kwds);
134 
135 PyObject*
136 MySQL_character_set_name(MySQL *self);
137 
138 PyObject*
139 MySQL_commit(MySQL *self);
140 
141 PyObject*
142 MySQL_connect(MySQL *self, PyObject *args, PyObject *kwds);
143 
144 PyObject*
145 MySQL_close(MySQL *self);
146 
147 PyObject*
148 MySQL_escape_string(MySQL *self, PyObject *value);
149 
150 PyObject*
151 MySQL_fetch_fields(MySQL *self);
152 
153 PyObject*
154 MySQL_fetch_row(MySQL *self);
155 
156 PyObject*
157 MySQL_field_count(MySQL *self);
158 
159 PyObject*
160 MySQL_free_result(MySQL *self);
161 
162 PyObject*
163 MySQL_get_character_set_info(MySQL *self);
164 
165 PyObject*
166 MySQL_get_client_info(MySQL *self);
167 
168 PyObject*
169 MySQL_get_client_version(MySQL *self);
170 
171 PyObject*
172 MySQL_get_host_info(MySQL *self);
173 
174 PyObject*
175 MySQL_get_proto_info(MySQL *self);
176 
177 PyObject*
178 MySQL_get_server_info(MySQL *self);
179 
180 PyObject*
181 MySQL_get_server_version(MySQL *self);
182 
183 PyObject*
184 MySQL_get_ssl_cipher(MySQL *self);
185 
186 PyObject*
187 MySQL_hex_string(MySQL *self, PyObject *value);
188 
189 PyObject*
190 MySQL_insert_id(MySQL *self);
191 
192 PyObject*
193 MySQL_next_result(MySQL *self);
194 
195 PyObject*
196 MySQL_num_fields(MySQL *self);
197 
198 PyObject*
199 MySQL_num_rows(MySQL *self);
200 
201 PyObject*
202 MySQL_more_results(MySQL *self);
203 
204 PyObject*
205 MySQL_ping(MySQL *self);
206 
207 PyObject*
208 MySQL_query(MySQL *self, PyObject *args, PyObject *kwds);
209 
210 PyObject*
211 MySQL_refresh(MySQL *self, PyObject *args);
212 
213 PyObject*
214 MySQL_reset_connection(MySQL *self);
215 
216 PyObject*
217 MySQL_rollback(MySQL *self);
218 
219 PyObject*
220 MySQL_select_db(MySQL *self, PyObject *db);
221 
222 PyObject*
223 MySQL_set_character_set(MySQL *self, PyObject *args);
224 
225 PyObject*
226 MySQL_set_load_data_local_infile_option(MySQL *self, PyObject *args);
227 
228 PyObject*
229 MySQL_shutdown(MySQL *self, PyObject *args);
230 
231 PyObject*
232 MySQL_stat(MySQL *self);
233 
234 PyObject*
235 MySQL_thread_id(MySQL *self);
236 
237 PyObject*
238 MySQL_use_unicode(MySQL *self, PyObject *args);
239 
240 PyObject*
241 MySQL_warning_count(MySQL *self);
242 
243 PyObject*
244 MySQL_create_prep_stmt(MySQL *self);
245 
246 /* MySQLPrepStmt */
247 
248 struct MySQL_binding {
249     PyObject *str_value;
250     union {
251         long l;
252         float f;
253         MYSQL_TIME t;
254     } buffer;
255 };
256 
257 struct column_info {
258     bool_ is_null;
259     bool_ is_error;
260     unsigned long length;
261     union {
262         long l;
263         float f;
264         double d;
265     } small_buffer;
266 };
267 
268 typedef struct {
269     PyObject_HEAD
270     MYSQL_BIND *bind;
271     MYSQL_RES *res;
272     MYSQL_STMT *stmt;
273 	const char *charset;
274     unsigned int use_unicode;
275     unsigned long param_count;
276     unsigned int column_count;
277     struct column_info *cols;
278     PyObject *have_result_set;
279     PyObject *fields;
280     PyObject *converter_str_fallback;
281     MY_CHARSET_INFO cs;
282 } MySQLPrepStmt;
283 
284 PyObject *
285 MySQLPrepStmt_new(PyTypeObject *type, PyObject *args, PyObject *kwds);
286 
287 int
288 MySQLPrepStmt_init(MySQLPrepStmt *self, PyObject *args, PyObject *kwds);
289 
290 void
291 MySQLPrepStmt_dealloc(MySQLPrepStmt *self);
292 
293 PyObject*
294 MySQL_stmt_prepare(MySQL *self, PyObject *stmt);
295 
296 PyObject*
297 MySQLPrepStmt_execute(MySQLPrepStmt *self, PyObject *args);
298 
299 PyObject*
300 MySQLPrepStmt_handle_result(MySQLPrepStmt *self);
301 
302 PyObject*
303 MySQLPrepStmt_fetch_row(MySQLPrepStmt *self);
304 
305 PyObject*
306 MySQLPrepStmt_fetch_fields(MySQLPrepStmt *self);
307 
308 PyObject*
309 MySQLPrepStmt_reset(MySQLPrepStmt *self);
310 
311 PyObject*
312 MySQLPrepStmt_close(MySQLPrepStmt *self);
313 
314 PyObject *
315 MySQLPrepStmt_free_result(MySQLPrepStmt *self);
316 
317 #endif /* MYCONNPY_MYSQL_CAPI_H */
318