1 module utile.db.mysql.binding;
2 
3 public import core.stdc.config;
4 
5 enum
6 {
7 	MYSQL_OPT_CONNECT_TIMEOUT,
8 	MYSQL_OPT_COMPRESS,
9 	MYSQL_OPT_NAMED_PIPE,
10 	MYSQL_INIT_COMMAND,
11 	MYSQL_READ_DEFAULT_FILE,
12 	MYSQL_READ_DEFAULT_GROUP,
13 	MYSQL_SET_CHARSET_DIR,
14 	MYSQL_SET_CHARSET_NAME,
15 	MYSQL_OPT_LOCAL_INFILE,
16 	MYSQL_OPT_PROTOCOL,
17 	MYSQL_SHARED_MEMORY_BASE_NAME,
18 	MYSQL_OPT_READ_TIMEOUT,
19 	MYSQL_OPT_WRITE_TIMEOUT,
20 	MYSQL_OPT_USE_RESULT,
21 	MYSQL_OPT_USE_REMOTE_CONNECTION,
22 	MYSQL_OPT_USE_EMBEDDED_CONNECTION,
23 	MYSQL_OPT_GUESS_CONNECTION,
24 	MYSQL_SET_CLIENT_IP,
25 	MYSQL_SECURE_AUTH,
26 	MYSQL_REPORT_DATA_TRUNCATION,
27 	MYSQL_OPT_RECONNECT,
28 	MYSQL_OPT_SSL_VERIFY_SERVER_CERT,
29 	MYSQL_PLUGIN_DIR,
30 	MYSQL_DEFAULT_AUTH,
31 	MYSQL_OPT_BIND,
32 	MYSQL_OPT_SSL_KEY,
33 	MYSQL_OPT_SSL_CERT,
34 	MYSQL_OPT_SSL_CA,
35 	MYSQL_OPT_SSL_CAPATH,
36 	MYSQL_OPT_SSL_CIPHER,
37 	MYSQL_OPT_SSL_CRL,
38 	MYSQL_OPT_SSL_CRLPATH,
39 	MYSQL_OPT_CONNECT_ATTR_RESET,
40 	MYSQL_OPT_CONNECT_ATTR_ADD,
41 	MYSQL_OPT_CONNECT_ATTR_DELETE,
42 	MYSQL_SERVER_PUBLIC_KEY,
43 	MYSQL_ENABLE_CLEARTEXT_PLUGIN,
44 	MYSQL_OPT_CAN_HANDLE_EXPIRED_PASSWORDS,
45 	MYSQL_OPT_SSL_ENFORCE,
46 	MYSQL_OPT_MAX_ALLOWED_PACKET,
47 	MYSQL_OPT_NET_BUFFER_LENGTH,
48 	MYSQL_OPT_TLS_VERSION,
49 	MYSQL_OPT_SSL_MODE
50 }
51 
52 enum
53 {
54 	MYSQL_STATUS_READY,
55 	MYSQL_STATUS_GET_RESULT,
56 	MYSQL_STATUS_USE_RESULT,
57 	MYSQL_STATUS_STATEMENT_GET_RESULT
58 }
59 
60 enum
61 {
62 	MYSQL_PROTOCOL_DEFAULT,
63 	MYSQL_PROTOCOL_TCP,
64 	MYSQL_PROTOCOL_SOCKET,
65 	MYSQL_PROTOCOL_PIPE,
66 	MYSQL_PROTOCOL_MEMORY
67 }
68 
69 enum
70 {
71 	SSL_MODE_DISABLED = 1,
72 	SSL_MODE_PREFERRED,
73 	SSL_MODE_REQUIRED,
74 	SSL_MODE_VERIFY_CA,
75 	SSL_MODE_VERIFY_IDENTITY
76 }
77 
78 enum
79 {
80 	MYSQL_STMT_INIT_DONE = 1,
81 	MYSQL_STMT_PREPARE_DONE,
82 	MYSQL_STMT_EXECUTE_DONE,
83 	MYSQL_STMT_FETCH_DONE
84 }
85 
86 enum
87 {
88 	STMT_ATTR_UPDATE_MAX_LENGTH,
89 	STMT_ATTR_CURSOR_TYPE,
90 	STMT_ATTR_PREFETCH_ROWS
91 }
92 
93 enum
94 {
95 	MYSQL_TYPE_DECIMAL,
96 	MYSQL_TYPE_TINY,
97 	MYSQL_TYPE_SHORT,
98 	MYSQL_TYPE_LONG,
99 	MYSQL_TYPE_FLOAT,
100 	MYSQL_TYPE_DOUBLE,
101 	MYSQL_TYPE_NULL,
102 	MYSQL_TYPE_TIMESTAMP,
103 	MYSQL_TYPE_LONGLONG,
104 	MYSQL_TYPE_INT24,
105 	MYSQL_TYPE_DATE,
106 	MYSQL_TYPE_TIME,
107 	MYSQL_TYPE_DATETIME,
108 	MYSQL_TYPE_YEAR,
109 	MYSQL_TYPE_NEWDATE,
110 	MYSQL_TYPE_VARCHAR,
111 	MYSQL_TYPE_BIT,
112 	MYSQL_TYPE_TIMESTAMP2,
113 	MYSQL_TYPE_DATETIME2,
114 	MYSQL_TYPE_TIME2,
115 	MYSQL_TYPE_JSON = 245,
116 	MYSQL_TYPE_NEWDECIMAL = 246,
117 	MYSQL_TYPE_ENUM = 247,
118 	MYSQL_TYPE_SET = 248,
119 	MYSQL_TYPE_TINY_BLOB = 249,
120 	MYSQL_TYPE_MEDIUM_BLOB = 250,
121 	MYSQL_TYPE_LONG_BLOB = 251,
122 	MYSQL_TYPE_BLOB = 252,
123 	MYSQL_TYPE_VAR_STRING = 253,
124 	MYSQL_TYPE_STRING = 254,
125 	MYSQL_TYPE_GEOMETRY = 255
126 }
127 
128 enum
129 {
130 	MYSQL_NO_DATA = 100,
131 	MYSQL_DATA_TRUNCATED
132 }
133 
134 alias NET = void;
135 alias MYSQL = void;
136 alias MYSQL_ROW = char**;
137 alias MYSQL_FIELD_OFFSET = uint;
138 alias MYSQL_ROW_OFFSET = MYSQL_ROWS*;
139 
140 extern (System):
141 
142 struct MYSQL_FIELD
143 {
144 	char* name;
145 	char* org_name;
146 	char* table;
147 	char* org_table;
148 	char* db;
149 	char* catalog;
150 	char* def;
151 	c_ulong length;
152 	c_ulong max_length;
153 	uint name_length;
154 	uint org_name_length;
155 	uint table_length;
156 	uint org_table_length;
157 	uint db_length;
158 	uint catalog_length;
159 	uint def_length;
160 	uint flags;
161 	uint decimals;
162 	uint charsetnr;
163 	int type;
164 	void* extension;
165 }
166 
167 struct MYSQL_ROWS
168 {
169 	MYSQL_ROWS* next;
170 	MYSQL_ROW data;
171 	c_ulong length;
172 }
173 
174 struct USED_MEM
175 {
176 	USED_MEM* next;
177 	uint left;
178 	uint size;
179 }
180 
181 struct LIST
182 {
183 	LIST* prev, next;
184 	void* data;
185 }
186 
187 struct MEM_ROOT
188 {
189 	USED_MEM* free;
190 	USED_MEM* used;
191 	USED_MEM* pre_alloc;
192 	size_t min_malloc;
193 	size_t block_size;
194 	uint block_num;
195 	uint first_block_usage;
196 
197 	void function() error_handler;
198 
199 	uint m_psi_key;
200 }
201 
202 struct MYSQL_DATA
203 {
204 	MYSQL_ROWS* data;
205 	void* embedded_info;
206 	MEM_ROOT alloc;
207 	ulong rows;
208 	uint fields;
209 	void* extension;
210 }
211 
212 struct MY_CHARSET_INFO
213 {
214 	uint number;
215 	uint state;
216 	const(char)* csname;
217 	const(char)* name;
218 	const(char)* comment;
219 	const(char)* dir;
220 	uint mbminlen;
221 	uint mbmaxlen;
222 }
223 
224 struct MYSQL_RES
225 {
226 	ulong row_count;
227 	MYSQL_FIELD* fields;
228 	MYSQL_DATA* data;
229 	MYSQL_ROWS* data_cursor;
230 	c_ulong* lengths;
231 	MYSQL* handle;
232 	const(void)* methods;
233 	MYSQL_ROW row;
234 	MYSQL_ROW current_row;
235 	MEM_ROOT field_alloc;
236 	uint field_count, current_field;
237 	bool eof;
238 
239 	bool unbuffered_fetch_cancelled;
240 	void* extension;
241 }
242 
243 struct MYSQL_PARAMETERS
244 {
245 	c_ulong* p_max_allowed_packet;
246 	c_ulong* p_net_buffer_length;
247 	void* extension;
248 }
249 
250 struct MYSQL_BIND
251 {
252 	c_ulong* length;
253 	bool* is_null;
254 	void* buffer;
255 
256 	bool* error;
257 	ubyte* row_ptr;
258 
259 	void function(NET* net, MYSQL_BIND* param) store_param_func;
260 	void function(MYSQL_BIND*, MYSQL_FIELD*, ubyte** row) fetch_result;
261 	void function(MYSQL_BIND*, MYSQL_FIELD*, ubyte** row) skip_result;
262 
263 	c_ulong buffer_length;
264 	c_ulong offset;
265 	c_ulong length_value;
266 	uint param_number;
267 	uint pack_length;
268 	int buffer_type;
269 	bool error_value;
270 	bool is_unsigned;
271 	bool long_data_used;
272 	bool is_null_value;
273 	void* extension;
274 }
275 
276 struct MYSQL_STMT
277 {
278 	MEM_ROOT mem_root;
279 	LIST list;
280 	MYSQL* mysql;
281 	MYSQL_BIND* params;
282 	MYSQL_BIND* bind;
283 	MYSQL_FIELD* fields;
284 	MYSQL_DATA result;
285 	MYSQL_ROWS* data_cursor;
286 
287 	int function(MYSQL_STMT* stmt, ubyte** row) read_row_func;
288 
289 	ulong affected_rows;
290 	ulong insert_id;
291 	c_ulong stmt_id;
292 	c_ulong flags;
293 	c_ulong prefetch_rows;
294 
295 	uint server_status;
296 	uint last_errno;
297 	uint param_count;
298 	uint field_count;
299 	int state;
300 	char[512] last_error;
301 	char[5 + 1] sqlstate;
302 
303 	bool send_types_to_server;
304 	bool bind_param_done;
305 	ubyte bind_result_done;
306 
307 	bool unbuffered_fetch_cancelled;
308 	bool update_max_length;
309 	void* extension;
310 }
311 
312 bool my_init();
313 
314 MYSQL_PARAMETERS* mysql_get_parameters();
315 
316 int mysql_server_init(int argc, char** argv, char** groups);
317 void mysql_server_end();
318 
319 bool mysql_thread_init();
320 void mysql_thread_end();
321 
322 ulong mysql_num_rows(MYSQL_RES* res);
323 uint mysql_num_fields(MYSQL_RES* res);
324 bool mysql_eof(MYSQL_RES* res);
325 MYSQL_FIELD* mysql_fetch_field_direct(MYSQL_RES* res, uint fieldnr);
326 MYSQL_FIELD* mysql_fetch_fields(MYSQL_RES* res);
327 MYSQL_ROW_OFFSET mysql_row_tell(MYSQL_RES* res);
328 MYSQL_FIELD_OFFSET mysql_field_tell(MYSQL_RES* res);
329 
330 uint mysql_field_count(MYSQL* mysql);
331 ulong mysql_affected_rows(MYSQL* mysql);
332 ulong mysql_insert_id(MYSQL* mysql);
333 uint mysql_errno(MYSQL* mysql);
334 const(char)* mysql_error(MYSQL* mysql);
335 const(char)* mysql_sqlstate(MYSQL* mysql);
336 uint mysql_warning_count(MYSQL* mysql);
337 const(char)* mysql_info(MYSQL* mysql);
338 c_ulong mysql_thread_id(MYSQL* mysql);
339 const(char)* mysql_character_set_name(MYSQL* mysql);
340 int mysql_set_character_set(MYSQL* mysql, const(char)* csname);
341 
342 MYSQL* mysql_init(MYSQL* mysql);
343 bool mysql_ssl_set(MYSQL* mysql, const(char)* key, const(char)* cert,
344 		const(char)* ca, const(char)* capath, const(char)* cipher);
345 
346 const(char)* mysql_get_ssl_cipher(MYSQL* mysql);
347 bool mysql_change_user(MYSQL* mysql, const(char)* user, const(char)* passwd, const(char)* db);
348 
349 MYSQL* mysql_real_connect(MYSQL* mysql, const(char)* host, const(char)* user,
350 		const(char)* passwd, const(char)* db, uint port,
351 		const(char)* unix_socket, c_ulong clientflag);
352 
353 int mysql_select_db(MYSQL* mysql, const(char)* db);
354 int mysql_query(MYSQL* mysql, const(char)* q);
355 int mysql_send_query(MYSQL* mysql, const(char)* q, c_ulong length);
356 int mysql_real_query(MYSQL* mysql, const(char)* q, c_ulong length);
357 MYSQL_RES* mysql_store_result(MYSQL* mysql);
358 MYSQL_RES* mysql_use_result(MYSQL* mysql);
359 
360 void mysql_get_character_set_info(MYSQL* mysql, MY_CHARSET_INFO* charset);
361 
362 int mysql_session_track_get_first(MYSQL* mysql, int type, const(char)** data, size_t* length);
363 int mysql_session_track_get_next(MYSQL* mysql, int type, const(char)** data, size_t* length);
364 
365 void mysql_set_local_infile_handler(MYSQL* mysql, int function(void**,
366 		const(char)*, void*) local_infile_init, int function(void*, char*, uint) local_infile_read,
367 		void function(void*) local_infile_end, int function(void*, char*,
368 			uint) local_infile_error, void*);
369 
370 void mysql_set_local_infile_default(MYSQL* mysql);
371 
372 int mysql_shutdown(MYSQL* mysql, int shutdown_level);
373 int mysql_dump_debug_info(MYSQL* mysql);
374 int mysql_refresh(MYSQL* mysql, uint refresh_options);
375 int mysql_kill(MYSQL* mysql, c_ulong pid);
376 int mysql_set_server_option(MYSQL* mysql, int option);
377 int mysql_ping(MYSQL* mysql);
378 const(char)* mysql_stat(MYSQL* mysql);
379 const(char)* mysql_get_server_info(MYSQL* mysql);
380 const(char)* mysql_get_client_info();
381 c_ulong mysql_get_client_version();
382 const(char)* mysql_get_host_info(MYSQL* mysql);
383 c_ulong mysql_get_server_version(MYSQL* mysql);
384 uint mysql_get_proto_info(MYSQL* mysql);
385 MYSQL_RES* mysql_list_dbs(MYSQL* mysql, const(char)* wild);
386 MYSQL_RES* mysql_list_tables(MYSQL* mysql, const(char)* wild);
387 MYSQL_RES* mysql_list_processes(MYSQL* mysql);
388 int mysql_options(MYSQL* mysql, int option, const(void)* arg);
389 int mysql_options4(MYSQL* mysql, int option, const(void)* arg1, const(void)* arg2);
390 int mysql_get_option(MYSQL* mysql, int option, const(void)* arg);
391 void mysql_free_result(MYSQL_RES* result);
392 void mysql_data_seek(MYSQL_RES* result, ulong offset);
393 MYSQL_ROW_OFFSET mysql_row_seek(MYSQL_RES* result, MYSQL_ROW_OFFSET offset);
394 MYSQL_FIELD_OFFSET mysql_field_seek(MYSQL_RES* result, MYSQL_FIELD_OFFSET offset);
395 MYSQL_ROW mysql_fetch_row(MYSQL_RES* result);
396 c_ulong* mysql_fetch_lengths(MYSQL_RES* result);
397 MYSQL_FIELD* mysql_fetch_field(MYSQL_RES* result);
398 MYSQL_RES* mysql_list_fields(MYSQL* mysql, const(char)* table, const(char)* wild);
399 c_ulong mysql_escape_string(char* to, const(char)* from, c_ulong from_length);
400 c_ulong mysql_hex_string(char* to, const(char)* from, c_ulong from_length);
401 c_ulong mysql_real_escape_string(MYSQL* mysql, char* to, const(char)* from, c_ulong length);
402 c_ulong mysql_real_escape_string_quote(MYSQL* mysql, char* to,
403 		const(char)* from, c_ulong length, char quote);
404 void mysql_debug(const(char)* debug_);
405 void myodbc_remove_escape(MYSQL* mysql, char* name);
406 uint mysql_thread_safe();
407 bool mysql_embedded();
408 bool mysql_read_query_result(MYSQL* mysql);
409 int mysql_reset_connection(MYSQL* mysql);
410 
411 MYSQL_STMT* mysql_stmt_init(MYSQL* mysql);
412 int mysql_stmt_prepare(MYSQL_STMT* stmt, const(char)* query, c_ulong length);
413 int mysql_stmt_execute(MYSQL_STMT* stmt);
414 int mysql_stmt_fetch(MYSQL_STMT* stmt);
415 int mysql_stmt_fetch_column(MYSQL_STMT* stmt, MYSQL_BIND* bind_arg, uint column, c_ulong offset);
416 int mysql_stmt_store_result(MYSQL_STMT* stmt);
417 c_ulong mysql_stmt_param_count(MYSQL_STMT* stmt);
418 bool mysql_stmt_attr_set(MYSQL_STMT* stmt, int attr_type, const(void)* attr);
419 bool mysql_stmt_attr_get(MYSQL_STMT* stmt, int attr_type, void* attr);
420 bool mysql_stmt_bind_param(MYSQL_STMT* stmt, MYSQL_BIND* bnd);
421 bool mysql_stmt_bind_result(MYSQL_STMT* stmt, MYSQL_BIND* bnd);
422 bool mysql_stmt_close(MYSQL_STMT* stmt);
423 bool mysql_stmt_reset(MYSQL_STMT* stmt);
424 bool mysql_stmt_free_result(MYSQL_STMT* stmt);
425 bool mysql_stmt_send_long_data(MYSQL_STMT* stmt, uint param_number,
426 		const(char)* data, c_ulong length);
427 MYSQL_RES* mysql_stmt_result_metadata(MYSQL_STMT* stmt);
428 MYSQL_RES* mysql_stmt_param_metadata(MYSQL_STMT* stmt);
429 uint mysql_stmt_errno(MYSQL_STMT* stmt);
430 const(char)* mysql_stmt_error(MYSQL_STMT* stmt);
431 const(char)* mysql_stmt_sqlstate(MYSQL_STMT* stmt);
432 MYSQL_ROW_OFFSET mysql_stmt_row_seek(MYSQL_STMT* stmt, MYSQL_ROW_OFFSET offset);
433 MYSQL_ROW_OFFSET mysql_stmt_row_tell(MYSQL_STMT* stmt);
434 void mysql_stmt_data_seek(MYSQL_STMT* stmt, ulong offset);
435 ulong mysql_stmt_num_rows(MYSQL_STMT* stmt);
436 ulong mysql_stmt_affected_rows(MYSQL_STMT* stmt);
437 ulong mysql_stmt_insert_id(MYSQL_STMT* stmt);
438 uint mysql_stmt_field_count(MYSQL_STMT* stmt);
439 
440 bool mysql_commit(MYSQL* mysql);
441 bool mysql_rollback(MYSQL* mysql);
442 bool mysql_autocommit(MYSQL* mysql, bool auto_mode);
443 bool mysql_more_results(MYSQL* mysql);
444 int mysql_next_result(MYSQL* mysql);
445 int mysql_stmt_next_result(MYSQL_STMT* stmt);
446 void mysql_close(MYSQL* sock);