1 /*
2    Copyright (c) 2000, 2012, Oracle and/or its affiliates.
3    Copyright (c) 2012, Monty Program Ab.
4 
5    This program is free software; you can redistribute it and/or modify
6    it under the terms of the GNU General Public License as published by
7    the Free Software Foundation; version 2 of the License.
8 
9    This program is distributed in the hope that it will be useful,
10    but WITHOUT ANY WARRANTY; without even the implied warranty of
11    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12    GNU General Public License for more details.
13 
14    You should have received a copy of the GNU General Public License
15    along with this program; if not, write to the Free Software
16    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1335  USA */
17 
18 /*
19   This file defines the client API to MySQL and also the ABI of the
20   dynamically linked libmysqlclient.
21 
22   The ABI should never be changed in a released product of MySQL,
23   thus you need to take great care when changing the file. In case
24   the file is changed so the ABI is broken, you must also update
25   the SHARED_LIB_MAJOR_VERSION in cmake/mysql_version.cmake
26 */
27 
28 #ifndef _mysql_h
29 #define _mysql_h
30 
31 #ifdef _AIX           /* large-file support will break without this */
32 #include <standards.h>
33 #endif
34 
35 #ifdef __CYGWIN__     /* CYGWIN implements a UNIX API */
36 #undef WIN
37 #undef _WIN
38 #undef _WIN32
39 #undef _WIN64
40 #undef __WIN__
41 #endif
42 
43 #ifdef	__cplusplus
44 extern "C" {
45 #endif
46 
47 #ifndef MY_GLOBAL_INCLUDED				/* If not standard header */
48 #ifndef MYSQL_ABI_CHECK
49 #include <sys/types.h>
50 #endif
51 
52 #ifndef MYSQL_PLUGIN_INCLUDED
53 typedef char my_bool;
54 #endif
55 
56 #if (defined(_WIN32) || defined(_WIN64)) && !defined(__WIN__)
57 #define __WIN__
58 #endif
59 #if !defined(__WIN__)
60 #define STDCALL
61 #else
62 #define STDCALL __stdcall
63 #endif
64 
65 #ifndef my_socket_defined
66 #if defined (_WIN64)
67 #define my_socket unsigned long long
68 #elif defined (_WIN32)
69 #define my_socket unsigned int
70 #else
71 typedef int my_socket;
72 #endif /* _WIN64 */
73 #endif /* my_socket_defined */
74 #endif /* MY_GLOBAL_INCLUDED */
75 
76 #include "mysql_version.h"
77 #include "mysql_com.h"
78 #include "mysql_time.h"
79 
80 #include "my_list.h" /* for LISTs used in 'MYSQL' and 'MYSQL_STMT' */
81 
82 extern unsigned int mariadb_deinitialize_ssl;
83 extern unsigned int mysql_port;
84 extern char *mysql_unix_port;
85 
86 #define CLIENT_NET_READ_TIMEOUT		(365*24*3600)	/* Timeout on read */
87 #define CLIENT_NET_WRITE_TIMEOUT	(365*24*3600)	/* Timeout on write */
88 
89 #define IS_PRI_KEY(n)	((n) & PRI_KEY_FLAG)
90 #define IS_NOT_NULL(n)	((n) & NOT_NULL_FLAG)
91 #define IS_BLOB(n)	((n) & BLOB_FLAG)
92 /**
93    Returns true if the value is a number which does not need quotes for
94    the sql_lex.cc parser to parse correctly.
95 */
96 #define IS_NUM(t)	(((t) <= MYSQL_TYPE_INT24 && (t) != MYSQL_TYPE_TIMESTAMP) || (t) == MYSQL_TYPE_YEAR || (t) == MYSQL_TYPE_NEWDECIMAL)
97 #define IS_LONGDATA(t) ((t) >= MYSQL_TYPE_TINY_BLOB && (t) <= MYSQL_TYPE_STRING)
98 
99 
100 typedef struct st_mysql_field {
101   char *name;                 /* Name of column */
102   char *org_name;             /* Original column name, if an alias */
103   char *table;                /* Table of column if column was a field */
104   char *org_table;            /* Org table name, if table was an alias */
105   char *db;                   /* Database for table */
106   char *catalog;	      /* Catalog for table */
107   char *def;                  /* Default value (set by mysql_list_fields) */
108   unsigned long length;       /* Width of column (create length) */
109   unsigned long max_length;   /* Max width for selected set */
110   unsigned int name_length;
111   unsigned int org_name_length;
112   unsigned int table_length;
113   unsigned int org_table_length;
114   unsigned int db_length;
115   unsigned int catalog_length;
116   unsigned int def_length;
117   unsigned int flags;         /* Div flags */
118   unsigned int decimals;      /* Number of decimals in field */
119   unsigned int charsetnr;     /* Character set */
120   enum enum_field_types type; /* Type of field. See mysql_com.h for types */
121   void *extension;
122 } MYSQL_FIELD;
123 
124 typedef char **MYSQL_ROW;		/* return data as array of strings */
125 typedef unsigned int MYSQL_FIELD_OFFSET; /* offset to current field */
126 
127 #ifndef MY_GLOBAL_INCLUDED
128 #if defined(NO_CLIENT_LONG_LONG)
129 typedef unsigned long my_ulonglong;
130 #elif defined (__WIN__)
131 typedef unsigned __int64 my_ulonglong;
132 #else
133 typedef unsigned long long my_ulonglong;
134 #endif
135 #endif
136 
137 #include "typelib.h"
138 
139 #define MYSQL_COUNT_ERROR (~(my_ulonglong) 0)
140 
141 /* backward compatibility define - to be removed eventually */
142 #define ER_WARN_DATA_TRUNCATED WARN_DATA_TRUNCATED
143 #define WARN_PLUGIN_DELETE_BUILTIN ER_PLUGIN_DELETE_BUILTIN
144 #define ER_FK_DUP_NAME ER_DUP_CONSTRAINT_NAME
145 #define ER_VIRTUAL_COLUMN_FUNCTION_IS_NOT_ALLOWED ER_GENERATED_COLUMN_FUNCTION_IS_NOT_ALLOWED
146 #define ER_PRIMARY_KEY_BASED_ON_VIRTUAL_COLUMN ER_PRIMARY_KEY_BASED_ON_GENERATED_COLUMN
147 #define ER_WRONG_FK_OPTION_FOR_VIRTUAL_COLUMN ER_WRONG_FK_OPTION_FOR_GENERATED_COLUMN
148 #define ER_UNSUPPORTED_ACTION_ON_VIRTUAL_COLUMN ER_UNSUPPORTED_ACTION_ON_GENERATED_COLUMN
149 #define ER_UNSUPPORTED_ENGINE_FOR_VIRTUAL_COLUMNS ER_UNSUPPORTED_ENGINE_FOR_GENERATED_COLUMNS
150 
151 typedef struct st_mysql_rows {
152   struct st_mysql_rows *next;		/* list of rows */
153   MYSQL_ROW data;
154   unsigned long length;
155 } MYSQL_ROWS;
156 
157 typedef MYSQL_ROWS *MYSQL_ROW_OFFSET;	/* offset to current row */
158 
159 #include "my_alloc.h"
160 
161 typedef struct embedded_query_result EMBEDDED_QUERY_RESULT;
162 typedef struct st_mysql_data {
163   MYSQL_ROWS *data;
164   struct embedded_query_result *embedded_info;
165   MEM_ROOT alloc;
166   my_ulonglong rows;
167   unsigned int fields;
168   /* extra info for embedded library */
169   void *extension;
170 } MYSQL_DATA;
171 
172 enum mysql_option
173 {
174   MYSQL_OPT_CONNECT_TIMEOUT, MYSQL_OPT_COMPRESS, MYSQL_OPT_NAMED_PIPE,
175   MYSQL_INIT_COMMAND, MYSQL_READ_DEFAULT_FILE, MYSQL_READ_DEFAULT_GROUP,
176   MYSQL_SET_CHARSET_DIR, MYSQL_SET_CHARSET_NAME, MYSQL_OPT_LOCAL_INFILE,
177   MYSQL_OPT_PROTOCOL, MYSQL_SHARED_MEMORY_BASE_NAME, MYSQL_OPT_READ_TIMEOUT,
178   MYSQL_OPT_WRITE_TIMEOUT, MYSQL_OPT_USE_RESULT,
179   MYSQL_OPT_USE_REMOTE_CONNECTION, MYSQL_OPT_USE_EMBEDDED_CONNECTION,
180   MYSQL_OPT_GUESS_CONNECTION, MYSQL_SET_CLIENT_IP, MYSQL_SECURE_AUTH,
181   MYSQL_REPORT_DATA_TRUNCATION, MYSQL_OPT_RECONNECT,
182   MYSQL_OPT_SSL_VERIFY_SERVER_CERT, MYSQL_PLUGIN_DIR, MYSQL_DEFAULT_AUTH,
183   MYSQL_OPT_BIND,
184   MYSQL_OPT_SSL_KEY, MYSQL_OPT_SSL_CERT,
185   MYSQL_OPT_SSL_CA, MYSQL_OPT_SSL_CAPATH, MYSQL_OPT_SSL_CIPHER,
186   MYSQL_OPT_SSL_CRL, MYSQL_OPT_SSL_CRLPATH,
187   MYSQL_OPT_CONNECT_ATTR_RESET, MYSQL_OPT_CONNECT_ATTR_ADD,
188   MYSQL_OPT_CONNECT_ATTR_DELETE,
189   MYSQL_SERVER_PUBLIC_KEY,
190   MYSQL_ENABLE_CLEARTEXT_PLUGIN,
191   MYSQL_OPT_CAN_HANDLE_EXPIRED_PASSWORDS,
192 
193   /* MariaDB options */
194   MYSQL_PROGRESS_CALLBACK=5999,
195   MYSQL_OPT_NONBLOCK,
196   MYSQL_OPT_USE_THREAD_SPECIFIC_MEMORY
197 };
198 
199 /**
200   @todo remove the "extension", move st_mysql_options completely
201   out of mysql.h
202 */
203 struct st_mysql_options_extention;
204 
205 struct st_mysql_options {
206   unsigned int connect_timeout, read_timeout, write_timeout;
207   unsigned int port, protocol;
208   unsigned long client_flag;
209   char *host,*user,*password,*unix_socket,*db;
210   struct st_dynamic_array *init_commands;
211   char *my_cnf_file,*my_cnf_group, *charset_dir, *charset_name;
212   char *ssl_key;				/* PEM key file */
213   char *ssl_cert;				/* PEM cert file */
214   char *ssl_ca;					/* PEM CA file */
215   char *ssl_capath;				/* PEM directory of CA-s? */
216   char *ssl_cipher;				/* cipher to use */
217   char *shared_memory_base_name;
218   unsigned long max_allowed_packet;
219   my_bool use_ssl;				/* if to use SSL or not */
220   my_bool compress,named_pipe;
221   my_bool use_thread_specific_memory;
222   my_bool unused2;
223   my_bool unused3;
224   my_bool unused4;
225   enum mysql_option methods_to_use;
226   char *client_ip;
227   /* Refuse client connecting to server if it uses old (pre-4.1.1) protocol */
228   my_bool secure_auth;
229   /* 0 - never report, 1 - always report (default) */
230   my_bool report_data_truncation;
231 
232   /* function pointers for local infile support */
233   int (*local_infile_init)(void **, const char *, void *);
234   int (*local_infile_read)(void *, char *, unsigned int);
235   void (*local_infile_end)(void *);
236   int (*local_infile_error)(void *, char *, unsigned int);
237   void *local_infile_userdata;
238   struct st_mysql_options_extention *extension;
239 };
240 
241 enum mysql_status
242 {
243   MYSQL_STATUS_READY, MYSQL_STATUS_GET_RESULT, MYSQL_STATUS_USE_RESULT,
244   MYSQL_STATUS_STATEMENT_GET_RESULT
245 };
246 
247 enum mysql_protocol_type
248 {
249   MYSQL_PROTOCOL_DEFAULT, MYSQL_PROTOCOL_TCP, MYSQL_PROTOCOL_SOCKET,
250   MYSQL_PROTOCOL_PIPE, MYSQL_PROTOCOL_MEMORY
251 };
252 
253 typedef struct character_set
254 {
255   unsigned int      number;     /* character set number              */
256   unsigned int      state;      /* character set state               */
257   const char        *csname;    /* collation name                    */
258   const char        *name;      /* character set name                */
259   const char        *comment;   /* comment                           */
260   const char        *dir;       /* character set directory           */
261   unsigned int      mbminlen;   /* min. length for multibyte strings */
262   unsigned int      mbmaxlen;   /* max. length for multibyte strings */
263 } MY_CHARSET_INFO;
264 
265 struct st_mysql_methods;
266 struct st_mysql_stmt;
267 
268 typedef struct st_mysql
269 {
270   NET		net;			/* Communication parameters */
271   unsigned char	*connector_fd;		/* ConnectorFd for SSL */
272   char		*host,*user,*passwd,*unix_socket,*server_version,*host_info;
273   char          *info, *db;
274   const struct charset_info_st *charset;
275   MYSQL_FIELD	*fields;
276   MEM_ROOT	field_alloc;
277   my_ulonglong affected_rows;
278   my_ulonglong insert_id;		/* id if insert on table with NEXTNR */
279   my_ulonglong extra_info;		/* Not used */
280   unsigned long thread_id;		/* Id for connection in server */
281   unsigned long packet_length;
282   unsigned int	port;
283   unsigned long client_flag,server_capabilities;
284   unsigned int	protocol_version;
285   unsigned int	field_count;
286   unsigned int 	server_status;
287   unsigned int  server_language;
288   unsigned int	warning_count;
289   struct st_mysql_options options;
290   enum mysql_status status;
291   my_bool	free_me;		/* If free in mysql_close */
292   my_bool	reconnect;		/* set to 1 if automatic reconnect */
293 
294   /* session-wide random string */
295   char	        scramble[SCRAMBLE_LENGTH+1];
296   my_bool       auto_local_infile;
297   void *unused2, *unused3, *unused4, *unused5;
298 
299   LIST  *stmts;                     /* list of all statements */
300   const struct st_mysql_methods *methods;
301   void *thd;
302   /*
303     Points to boolean flag in MYSQL_RES  or MYSQL_STMT. We set this flag
304     from mysql_stmt_close if close had to cancel result set of this object.
305   */
306   my_bool *unbuffered_fetch_owner;
307   /* needed for embedded server - no net buffer to store the 'info' */
308   char *info_buffer;
309   void *extension;
310 } MYSQL;
311 
312 
313 typedef struct st_mysql_res {
314   my_ulonglong  row_count;
315   MYSQL_FIELD	*fields;
316   MYSQL_DATA	*data;
317   MYSQL_ROWS	*data_cursor;
318   unsigned long *lengths;		/* column lengths of current row */
319   MYSQL		*handle;		/* for unbuffered reads */
320   const struct st_mysql_methods *methods;
321   MYSQL_ROW	row;			/* If unbuffered read */
322   MYSQL_ROW	current_row;		/* buffer to current row */
323   MEM_ROOT	field_alloc;
324   unsigned int	field_count, current_field;
325   my_bool	eof;			/* Used by mysql_fetch_row */
326   /* mysql_stmt_close() had to cancel this result */
327   my_bool       unbuffered_fetch_cancelled;
328   void *extension;
329 } MYSQL_RES;
330 
331 
332 #if !defined(MYSQL_SERVER) && !defined(MYSQL_CLIENT)
333 #define MYSQL_CLIENT
334 #endif
335 
336 
337 typedef struct st_mysql_parameters
338 {
339   unsigned long *p_max_allowed_packet;
340   unsigned long *p_net_buffer_length;
341   void *extension;
342 } MYSQL_PARAMETERS;
343 
344 /*
345   Flag bits, the asynchronous methods return a combination of these ORed
346   together to let the application know when to resume the suspended operation.
347 */
348 
349 /*
350   Wait for data to be available on socket to read.
351   mysql_get_socket_fd() will return socket descriptor.
352 */
353 #define MYSQL_WAIT_READ 1
354 /* Wait for socket to be ready to write data. */
355 #define MYSQL_WAIT_WRITE  2
356 /* Wait for select() to mark exception on socket. */
357 #define MYSQL_WAIT_EXCEPT 4
358 /*
359   Wait until timeout occurs. Value of timeout can be obtained from
360   mysql_get_timeout_value().
361 */
362 #define MYSQL_WAIT_TIMEOUT 8
363 
364 #if !defined(MYSQL_SERVER) && !defined(EMBEDDED_LIBRARY)
365 #define max_allowed_packet (*mysql_get_parameters()->p_max_allowed_packet)
366 #define net_buffer_length (*mysql_get_parameters()->p_net_buffer_length)
367 #endif
368 
369 /*
370   Set up and bring down the server; to ensure that applications will
371   work when linked against either the standard client library or the
372   embedded server library, these functions should be called.
373 */
374 int STDCALL mysql_server_init(int argc, char **argv, char **groups);
375 void STDCALL mysql_server_end(void);
376 
377 /*
378   mysql_server_init/end need to be called when using libmysqld or
379   libmysqlclient (exactly, mysql_server_init() is called by mysql_init() so
380   you don't need to call it explicitly; but you need to call
381   mysql_server_end() to free memory). The names are a bit misleading
382   (mysql_SERVER* to be used when using libmysqlCLIENT). So we add more general
383   names which suit well whether you're using libmysqld or libmysqlclient. We
384   intend to promote these aliases over the mysql_server* ones.
385 */
386 #define mysql_library_init mysql_server_init
387 #define mysql_library_end mysql_server_end
388 
389 MYSQL_PARAMETERS *STDCALL mysql_get_parameters(void);
390 
391 /*
392   Set up and bring down a thread; these function should be called
393   for each thread in an application which opens at least one MySQL
394   connection.  All uses of the connection(s) should be between these
395   function calls.
396 */
397 my_bool STDCALL mysql_thread_init(void);
398 void STDCALL mysql_thread_end(void);
399 
400 /*
401   Functions to get information from the MYSQL and MYSQL_RES structures
402   Should definitely be used if one uses shared libraries.
403 */
404 
405 my_ulonglong STDCALL mysql_num_rows(MYSQL_RES *res);
406 unsigned int STDCALL mysql_num_fields(MYSQL_RES *res);
407 my_bool STDCALL mysql_eof(MYSQL_RES *res);
408 MYSQL_FIELD *STDCALL mysql_fetch_field_direct(MYSQL_RES *res,
409 					      unsigned int fieldnr);
410 MYSQL_FIELD * STDCALL mysql_fetch_fields(MYSQL_RES *res);
411 MYSQL_ROW_OFFSET STDCALL mysql_row_tell(MYSQL_RES *res);
412 MYSQL_FIELD_OFFSET STDCALL mysql_field_tell(MYSQL_RES *res);
413 
414 unsigned int STDCALL mysql_field_count(MYSQL *mysql);
415 my_ulonglong STDCALL mysql_affected_rows(MYSQL *mysql);
416 my_ulonglong STDCALL mysql_insert_id(MYSQL *mysql);
417 unsigned int STDCALL mysql_errno(MYSQL *mysql);
418 const char * STDCALL mysql_error(MYSQL *mysql);
419 const char *STDCALL mysql_sqlstate(MYSQL *mysql);
420 unsigned int STDCALL mysql_warning_count(MYSQL *mysql);
421 const char * STDCALL mysql_info(MYSQL *mysql);
422 unsigned long STDCALL mysql_thread_id(MYSQL *mysql);
423 const char * STDCALL mysql_character_set_name(MYSQL *mysql);
424 int          STDCALL mysql_set_character_set(MYSQL *mysql, const char *csname);
425 int          STDCALL mysql_set_character_set_start(int *ret, MYSQL *mysql,
426                                                    const char *csname);
427 int          STDCALL mysql_set_character_set_cont(int *ret, MYSQL *mysql,
428                                                   int status);
429 
430 MYSQL *		STDCALL mysql_init(MYSQL *mysql);
431 my_bool		STDCALL mysql_ssl_set(MYSQL *mysql, const char *key,
432 				      const char *cert, const char *ca,
433 				      const char *capath, const char *cipher);
434 const char *    STDCALL mysql_get_ssl_cipher(MYSQL *mysql);
435 my_bool		STDCALL mysql_change_user(MYSQL *mysql, const char *user,
436 					  const char *passwd, const char *db);
437 int             STDCALL mysql_change_user_start(my_bool *ret, MYSQL *mysql,
438                                                 const char *user,
439                                                 const char *passwd,
440                                                 const char *db);
441 int             STDCALL mysql_change_user_cont(my_bool *ret, MYSQL *mysql,
442                                                int status);
443 MYSQL *		STDCALL mysql_real_connect(MYSQL *mysql, const char *host,
444 					   const char *user,
445 					   const char *passwd,
446 					   const char *db,
447 					   unsigned int port,
448 					   const char *unix_socket,
449 					   unsigned long clientflag);
450 int             STDCALL mysql_real_connect_start(MYSQL **ret, MYSQL *mysql,
451                                                  const char *host,
452                                                  const char *user,
453                                                  const char *passwd,
454                                                  const char *db,
455                                                  unsigned int port,
456                                                  const char *unix_socket,
457                                                  unsigned long clientflag);
458 int             STDCALL mysql_real_connect_cont(MYSQL **ret, MYSQL *mysql,
459                                                 int status);
460 int		STDCALL mysql_select_db(MYSQL *mysql, const char *db);
461 int             STDCALL mysql_select_db_start(int *ret, MYSQL *mysql,
462                                               const char *db);
463 int             STDCALL mysql_select_db_cont(int *ret, MYSQL *mysql,
464                                              int status);
465 int		STDCALL mysql_query(MYSQL *mysql, const char *q);
466 int             STDCALL mysql_query_start(int *ret, MYSQL *mysql,
467                                           const char *q);
468 int             STDCALL mysql_query_cont(int *ret, MYSQL *mysql,
469                                          int status);
470 int		STDCALL mysql_send_query(MYSQL *mysql, const char *q,
471 					 unsigned long length);
472 int             STDCALL mysql_send_query_start(int *ret, MYSQL *mysql,
473                                                const char *q,
474                                                unsigned long length);
475 int             STDCALL mysql_send_query_cont(int *ret, MYSQL *mysql,
476                                               int status);
477 int		STDCALL mysql_real_query(MYSQL *mysql, const char *q,
478 					unsigned long length);
479 int             STDCALL mysql_real_query_start(int *ret, MYSQL *mysql,
480                                                const char *q,
481                                                unsigned long length);
482 int             STDCALL mysql_real_query_cont(int *ret, MYSQL *mysql,
483                                               int status);
484 MYSQL_RES *     STDCALL mysql_store_result(MYSQL *mysql);
485 int             STDCALL mysql_store_result_start(MYSQL_RES **ret, MYSQL *mysql);
486 int             STDCALL mysql_store_result_cont(MYSQL_RES **ret, MYSQL *mysql,
487                                                 int status);
488 MYSQL_RES *     STDCALL mysql_use_result(MYSQL *mysql);
489 
490 void        STDCALL mysql_get_character_set_info(MYSQL *mysql,
491                            MY_CHARSET_INFO *charset);
492 
493 /* local infile support */
494 
495 #define LOCAL_INFILE_ERROR_LEN 512
496 
497 void
498 mysql_set_local_infile_handler(MYSQL *mysql,
499                                int (*local_infile_init)(void **, const char *,
500                             void *),
501                                int (*local_infile_read)(void *, char *,
502 							unsigned int),
503                                void (*local_infile_end)(void *),
504                                int (*local_infile_error)(void *, char*,
505 							 unsigned int),
506                                void *);
507 
508 void
509 mysql_set_local_infile_default(MYSQL *mysql);
510 
511 int		STDCALL mysql_shutdown(MYSQL *mysql,
512                                        enum mysql_enum_shutdown_level
513                                        shutdown_level);
514 int             STDCALL mysql_shutdown_start(int *ret, MYSQL *mysql,
515                                              enum mysql_enum_shutdown_level
516                                              shutdown_level);
517 int             STDCALL mysql_shutdown_cont(int *ret, MYSQL *mysql,
518                                             int status);
519 int		STDCALL mysql_dump_debug_info(MYSQL *mysql);
520 int             STDCALL mysql_dump_debug_info_start(int *ret, MYSQL *mysql);
521 int             STDCALL mysql_dump_debug_info_cont(int *ret, MYSQL *mysql,
522                                                    int status);
523 int		STDCALL mysql_refresh(MYSQL *mysql,
524 				     unsigned int refresh_options);
525 int             STDCALL mysql_refresh_start(int *ret, MYSQL *mysql,
526                                             unsigned int refresh_options);
527 int             STDCALL mysql_refresh_cont(int *ret, MYSQL *mysql, int status);
528 int		STDCALL mysql_kill(MYSQL *mysql,unsigned long pid);
529 int             STDCALL mysql_kill_start(int *ret, MYSQL *mysql,
530                                          unsigned long pid);
531 int             STDCALL mysql_kill_cont(int *ret, MYSQL *mysql, int status);
532 int		STDCALL mysql_set_server_option(MYSQL *mysql,
533 						enum enum_mysql_set_option
534 						option);
535 int             STDCALL mysql_set_server_option_start(int *ret, MYSQL *mysql,
536                                                       enum enum_mysql_set_option
537                                                       option);
538 int             STDCALL mysql_set_server_option_cont(int *ret, MYSQL *mysql,
539                                                      int status);
540 int		STDCALL mysql_ping(MYSQL *mysql);
541 int             STDCALL mysql_ping_start(int *ret, MYSQL *mysql);
542 int             STDCALL mysql_ping_cont(int *ret, MYSQL *mysql, int status);
543 const char *	STDCALL mysql_stat(MYSQL *mysql);
544 int             STDCALL mysql_stat_start(const char **ret, MYSQL *mysql);
545 int             STDCALL mysql_stat_cont(const char **ret, MYSQL *mysql,
546                                         int status);
547 const char *	STDCALL mysql_get_server_info(MYSQL *mysql);
548 const char *	STDCALL mysql_get_server_name(MYSQL *mysql);
549 const char *	STDCALL mysql_get_client_info(void);
550 unsigned long	STDCALL mysql_get_client_version(void);
551 const char *	STDCALL mysql_get_host_info(MYSQL *mysql);
552 unsigned long	STDCALL mysql_get_server_version(MYSQL *mysql);
553 unsigned int	STDCALL mysql_get_proto_info(MYSQL *mysql);
554 MYSQL_RES *	STDCALL mysql_list_dbs(MYSQL *mysql,const char *wild);
555 int             STDCALL mysql_list_dbs_start(MYSQL_RES **ret, MYSQL *mysql,
556                                              const char *wild);
557 int             STDCALL mysql_list_dbs_cont(MYSQL_RES **ret, MYSQL *mysql,
558                                             int status);
559 MYSQL_RES *	STDCALL mysql_list_tables(MYSQL *mysql,const char *wild);
560 int             STDCALL mysql_list_tables_start(MYSQL_RES **ret, MYSQL *mysql,
561                                                 const char *wild);
562 int             STDCALL mysql_list_tables_cont(MYSQL_RES **ret, MYSQL *mysql,
563                                                int status);
564 MYSQL_RES *	STDCALL mysql_list_processes(MYSQL *mysql);
565 int             STDCALL mysql_list_processes_start(MYSQL_RES **ret,
566                                                    MYSQL *mysql);
567 int             STDCALL mysql_list_processes_cont(MYSQL_RES **ret, MYSQL *mysql,
568                                                   int status);
569 int		STDCALL mysql_options(MYSQL *mysql,enum mysql_option option,
570 				      const void *arg);
571 int             STDCALL mysql_options4(MYSQL *mysql,enum mysql_option option,
572                                        const void *arg1, const void *arg2);
573 void		STDCALL mysql_free_result(MYSQL_RES *result);
574 int             STDCALL mysql_free_result_start(MYSQL_RES *result);
575 int             STDCALL mysql_free_result_cont(MYSQL_RES *result, int status);
576 void		STDCALL mysql_data_seek(MYSQL_RES *result,
577 					my_ulonglong offset);
578 MYSQL_ROW_OFFSET STDCALL mysql_row_seek(MYSQL_RES *result,
579 						MYSQL_ROW_OFFSET offset);
580 MYSQL_FIELD_OFFSET STDCALL mysql_field_seek(MYSQL_RES *result,
581 					   MYSQL_FIELD_OFFSET offset);
582 MYSQL_ROW	STDCALL mysql_fetch_row(MYSQL_RES *result);
583 int             STDCALL mysql_fetch_row_start(MYSQL_ROW *ret,
584                                               MYSQL_RES *result);
585 int             STDCALL mysql_fetch_row_cont(MYSQL_ROW *ret, MYSQL_RES *result,
586                                              int status);
587 unsigned long * STDCALL mysql_fetch_lengths(MYSQL_RES *result);
588 MYSQL_FIELD *	STDCALL mysql_fetch_field(MYSQL_RES *result);
589 MYSQL_RES *     STDCALL mysql_list_fields(MYSQL *mysql, const char *table,
590 					  const char *wild);
591 int             STDCALL mysql_list_fields_start(MYSQL_RES **ret, MYSQL *mysql,
592                                                 const char *table,
593                                                 const char *wild);
594 int             STDCALL mysql_list_fields_cont(MYSQL_RES **ret, MYSQL *mysql,
595                                                int status);
596 unsigned long	STDCALL mysql_escape_string(char *to,const char *from,
597 					    unsigned long from_length);
598 unsigned long	STDCALL mysql_hex_string(char *to,const char *from,
599                                          unsigned long from_length);
600 unsigned long STDCALL mysql_real_escape_string(MYSQL *mysql,
601 					       char *to,const char *from,
602 					       unsigned long length);
603 void		STDCALL mysql_debug(const char *debug);
604 void 		STDCALL myodbc_remove_escape(MYSQL *mysql,char *name);
605 unsigned int	STDCALL mysql_thread_safe(void);
606 my_bool		STDCALL mysql_embedded(void);
607 my_bool		STDCALL mariadb_connection(MYSQL *mysql);
608 my_bool         STDCALL mysql_read_query_result(MYSQL *mysql);
609 int             STDCALL mysql_read_query_result_start(my_bool *ret,
610                                                       MYSQL *mysql);
611 int             STDCALL mysql_read_query_result_cont(my_bool *ret,
612                                                      MYSQL *mysql, int status);
613 
614 
615 /*
616   The following definitions are added for the enhanced
617   client-server protocol
618 */
619 
620 /* statement state */
621 enum enum_mysql_stmt_state
622 {
623   MYSQL_STMT_INIT_DONE= 1, MYSQL_STMT_PREPARE_DONE, MYSQL_STMT_EXECUTE_DONE,
624   MYSQL_STMT_FETCH_DONE
625 };
626 
627 
628 /*
629   This structure is used to define bind information, and
630   internally by the client library.
631   Public members with their descriptions are listed below
632   (conventionally `On input' refers to the binds given to
633   mysql_stmt_bind_param, `On output' refers to the binds given
634   to mysql_stmt_bind_result):
635 
636   buffer_type    - One of the MYSQL_* types, used to describe
637                    the host language type of buffer.
638                    On output: if column type is different from
639                    buffer_type, column value is automatically converted
640                    to buffer_type before it is stored in the buffer.
641   buffer         - On input: points to the buffer with input data.
642                    On output: points to the buffer capable to store
643                    output data.
644                    The type of memory pointed by buffer must correspond
645                    to buffer_type. See the correspondence table in
646                    the comment to mysql_stmt_bind_param.
647 
648   The two above members are mandatory for any kind of bind.
649 
650   buffer_length  - the length of the buffer. You don't have to set
651                    it for any fixed length buffer: float, double,
652                    int, etc. It must be set however for variable-length
653                    types, such as BLOBs or STRINGs.
654 
655   length         - On input: in case when lengths of input values
656                    are different for each execute, you can set this to
657                    point at a variable containining value length. This
658                    way the value length can be different in each execute.
659                    If length is not NULL, buffer_length is not used.
660                    Note, length can even point at buffer_length if
661                    you keep bind structures around while fetching:
662                    this way you can change buffer_length before
663                    each execution, everything will work ok.
664                    On output: if length is set, mysql_stmt_fetch will
665                    write column length into it.
666 
667   is_null        - On input: points to a boolean variable that should
668                    be set to TRUE for NULL values.
669                    This member is useful only if your data may be
670                    NULL in some but not all cases.
671                    If your data is never NULL, is_null should be set to 0.
672                    If your data is always NULL, set buffer_type
673                    to MYSQL_TYPE_NULL, and is_null will not be used.
674 
675   is_unsigned    - On input: used to signify that values provided for one
676                    of numeric types are unsigned.
677                    On output describes signedness of the output buffer.
678                    If, taking into account is_unsigned flag, column data
679                    is out of range of the output buffer, data for this column
680                    is regarded truncated. Note that this has no correspondence
681                    to the sign of result set column, if you need to find it out
682                    use mysql_stmt_result_metadata.
683   error          - where to write a truncation error if it is present.
684                    possible error value is:
685                    0  no truncation
686                    1  value is out of range or buffer is too small
687 
688   Please note that MYSQL_BIND also has internals members.
689 */
690 
691 typedef struct st_mysql_bind
692 {
693   unsigned long	*length;          /* output length pointer */
694   my_bool       *is_null;	  /* Pointer to null indicator */
695   void		*buffer;	  /* buffer to get/put data */
696   /* set this if you want to track data truncations happened during fetch */
697   my_bool       *error;
698   unsigned char *row_ptr;         /* for the current data position */
699   void (*store_param_func)(NET *net, struct st_mysql_bind *param);
700   void (*fetch_result)(struct st_mysql_bind *, MYSQL_FIELD *,
701                        unsigned char **row);
702   void (*skip_result)(struct st_mysql_bind *, MYSQL_FIELD *,
703 		      unsigned char **row);
704   /* output buffer length, must be set when fetching str/binary */
705   unsigned long buffer_length;
706   unsigned long offset;           /* offset position for char/binary fetch */
707   unsigned long	length_value;     /* Used if length is 0 */
708   unsigned int	param_number;	  /* For null count and error messages */
709   unsigned int  pack_length;	  /* Internal length for packed data */
710   enum enum_field_types buffer_type;	/* buffer type */
711   my_bool       error_value;      /* used if error is 0 */
712   my_bool       is_unsigned;      /* set if integer type is unsigned */
713   my_bool	long_data_used;	  /* If used with mysql_send_long_data */
714   my_bool	is_null_value;    /* Used if is_null is 0 */
715   void *extension;
716 } MYSQL_BIND;
717 
718 
719 struct st_mysql_stmt_extension;
720 
721 /* statement handler */
722 typedef struct st_mysql_stmt
723 {
724   MEM_ROOT       mem_root;             /* root allocations */
725   LIST           list;                 /* list to keep track of all stmts */
726   MYSQL          *mysql;               /* connection handle */
727   MYSQL_BIND     *params;              /* input parameters */
728   MYSQL_BIND     *bind;                /* output parameters */
729   MYSQL_FIELD    *fields;              /* result set metadata */
730   MYSQL_DATA     result;               /* cached result set */
731   MYSQL_ROWS     *data_cursor;         /* current row in cached result */
732   /*
733     mysql_stmt_fetch() calls this function to fetch one row (it's different
734     for buffered, unbuffered and cursor fetch).
735   */
736   int            (*read_row_func)(struct st_mysql_stmt *stmt,
737                                   unsigned char **row);
738   /* copy of mysql->affected_rows after statement execution */
739   my_ulonglong   affected_rows;
740   my_ulonglong   insert_id;            /* copy of mysql->insert_id */
741   unsigned long	 stmt_id;	       /* Id for prepared statement */
742   unsigned long  flags;                /* i.e. type of cursor to open */
743   unsigned long  prefetch_rows;        /* number of rows per one COM_FETCH */
744   /*
745     Copied from mysql->server_status after execute/fetch to know
746     server-side cursor status for this statement.
747   */
748   unsigned int   server_status;
749   unsigned int	 last_errno;	       /* error code */
750   unsigned int   param_count;          /* input parameter count */
751   unsigned int   field_count;          /* number of columns in result set */
752   enum enum_mysql_stmt_state state;    /* statement state */
753   char		 last_error[MYSQL_ERRMSG_SIZE]; /* error message */
754   char		 sqlstate[SQLSTATE_LENGTH+1];
755   /* Types of input parameters should be sent to server */
756   my_bool        send_types_to_server;
757   my_bool        bind_param_done;      /* input buffers were supplied */
758   unsigned char  bind_result_done;     /* output buffers were supplied */
759   /* mysql_stmt_close() had to cancel this result */
760   my_bool       unbuffered_fetch_cancelled;
761   /*
762     Is set to true if we need to calculate field->max_length for
763     metadata fields when doing mysql_stmt_store_result.
764   */
765   my_bool       update_max_length;
766   struct st_mysql_stmt_extension *extension;
767 } MYSQL_STMT;
768 
769 enum enum_stmt_attr_type
770 {
771   /*
772     When doing mysql_stmt_store_result calculate max_length attribute
773     of statement metadata. This is to be consistent with the old API,
774     where this was done automatically.
775     In the new API we do that only by request because it slows down
776     mysql_stmt_store_result sufficiently.
777   */
778   STMT_ATTR_UPDATE_MAX_LENGTH,
779   /*
780     unsigned long with combination of cursor flags (read only, for update,
781     etc)
782   */
783   STMT_ATTR_CURSOR_TYPE,
784   /*
785     Amount of rows to retrieve from server per one fetch if using cursors.
786     Accepts unsigned long attribute in the range 1 - ulong_max
787   */
788   STMT_ATTR_PREFETCH_ROWS
789 };
790 
791 MYSQL_STMT * STDCALL mysql_stmt_init(MYSQL *mysql);
792 int STDCALL mysql_stmt_prepare(MYSQL_STMT *stmt, const char *query,
793                                unsigned long length);
794 int STDCALL mysql_stmt_prepare_start(int *ret, MYSQL_STMT *stmt,
795                                      const char *query, unsigned long length);
796 int STDCALL mysql_stmt_prepare_cont(int *ret, MYSQL_STMT *stmt, int status);
797 int STDCALL mysql_stmt_execute(MYSQL_STMT *stmt);
798 int STDCALL mysql_stmt_execute_start(int *ret, MYSQL_STMT *stmt);
799 int STDCALL mysql_stmt_execute_cont(int *ret, MYSQL_STMT *stmt, int status);
800 int STDCALL mysql_stmt_fetch(MYSQL_STMT *stmt);
801 int STDCALL mysql_stmt_fetch_start(int *ret, MYSQL_STMT *stmt);
802 int STDCALL mysql_stmt_fetch_cont(int *ret, MYSQL_STMT *stmt, int status);
803 int STDCALL mysql_stmt_fetch_column(MYSQL_STMT *stmt, MYSQL_BIND *bind_arg,
804                                     unsigned int column,
805                                     unsigned long offset);
806 int STDCALL mysql_stmt_store_result(MYSQL_STMT *stmt);
807 int STDCALL mysql_stmt_store_result_start(int *ret, MYSQL_STMT *stmt);
808 int STDCALL mysql_stmt_store_result_cont(int *ret, MYSQL_STMT *stmt,
809                                          int status);
810 unsigned long STDCALL mysql_stmt_param_count(MYSQL_STMT * stmt);
811 my_bool STDCALL mysql_stmt_attr_set(MYSQL_STMT *stmt,
812                                     enum enum_stmt_attr_type attr_type,
813                                     const void *attr);
814 my_bool STDCALL mysql_stmt_attr_get(MYSQL_STMT *stmt,
815                                     enum enum_stmt_attr_type attr_type,
816                                     void *attr);
817 my_bool STDCALL mysql_stmt_bind_param(MYSQL_STMT * stmt, MYSQL_BIND * bnd);
818 my_bool STDCALL mysql_stmt_bind_result(MYSQL_STMT * stmt, MYSQL_BIND * bnd);
819 my_bool STDCALL mysql_stmt_close(MYSQL_STMT * stmt);
820 int STDCALL mysql_stmt_close_start(my_bool *ret, MYSQL_STMT *stmt);
821 int STDCALL mysql_stmt_close_cont(my_bool *ret, MYSQL_STMT * stmt, int status);
822 my_bool STDCALL mysql_stmt_reset(MYSQL_STMT * stmt);
823 int STDCALL mysql_stmt_reset_start(my_bool *ret, MYSQL_STMT * stmt);
824 int STDCALL mysql_stmt_reset_cont(my_bool *ret, MYSQL_STMT *stmt, int status);
825 my_bool STDCALL mysql_stmt_free_result(MYSQL_STMT *stmt);
826 int STDCALL mysql_stmt_free_result_start(my_bool *ret, MYSQL_STMT *stmt);
827 int STDCALL mysql_stmt_free_result_cont(my_bool *ret, MYSQL_STMT *stmt,
828                                         int status);
829 my_bool STDCALL mysql_stmt_send_long_data(MYSQL_STMT *stmt,
830                                           unsigned int param_number,
831                                           const char *data,
832                                           unsigned long length);
833 int STDCALL mysql_stmt_send_long_data_start(my_bool *ret, MYSQL_STMT *stmt,
834                                             unsigned int param_number,
835                                             const char *data,
836                                             unsigned long len);
837 int STDCALL mysql_stmt_send_long_data_cont(my_bool *ret, MYSQL_STMT *stmt,
838                                            int status);
839 MYSQL_RES *STDCALL mysql_stmt_result_metadata(MYSQL_STMT *stmt);
840 MYSQL_RES *STDCALL mysql_stmt_param_metadata(MYSQL_STMT *stmt);
841 unsigned int STDCALL mysql_stmt_errno(MYSQL_STMT * stmt);
842 const char *STDCALL mysql_stmt_error(MYSQL_STMT * stmt);
843 const char *STDCALL mysql_stmt_sqlstate(MYSQL_STMT * stmt);
844 MYSQL_ROW_OFFSET STDCALL mysql_stmt_row_seek(MYSQL_STMT *stmt,
845                                              MYSQL_ROW_OFFSET offset);
846 MYSQL_ROW_OFFSET STDCALL mysql_stmt_row_tell(MYSQL_STMT *stmt);
847 void STDCALL mysql_stmt_data_seek(MYSQL_STMT *stmt, my_ulonglong offset);
848 my_ulonglong STDCALL mysql_stmt_num_rows(MYSQL_STMT *stmt);
849 my_ulonglong STDCALL mysql_stmt_affected_rows(MYSQL_STMT *stmt);
850 my_ulonglong STDCALL mysql_stmt_insert_id(MYSQL_STMT *stmt);
851 unsigned int STDCALL mysql_stmt_field_count(MYSQL_STMT *stmt);
852 
853 my_bool STDCALL mysql_commit(MYSQL * mysql);
854 int STDCALL mysql_commit_start(my_bool *ret, MYSQL * mysql);
855 int STDCALL mysql_commit_cont(my_bool *ret, MYSQL * mysql, int status);
856 my_bool STDCALL mysql_rollback(MYSQL * mysql);
857 int STDCALL mysql_rollback_start(my_bool *ret, MYSQL * mysql);
858 int STDCALL mysql_rollback_cont(my_bool *ret, MYSQL * mysql, int status);
859 my_bool STDCALL mysql_autocommit(MYSQL * mysql, my_bool auto_mode);
860 int STDCALL mysql_autocommit_start(my_bool *ret, MYSQL * mysql,
861                                    my_bool auto_mode);
862 int STDCALL mysql_autocommit_cont(my_bool *ret, MYSQL * mysql, int status);
863 my_bool STDCALL mysql_more_results(MYSQL *mysql);
864 int STDCALL mysql_next_result(MYSQL *mysql);
865 int STDCALL mysql_next_result_start(int *ret, MYSQL *mysql);
866 int STDCALL mysql_next_result_cont(int *ret, MYSQL *mysql, int status);
867 int STDCALL mysql_stmt_next_result(MYSQL_STMT *stmt);
868 int STDCALL mysql_stmt_next_result_start(int *ret, MYSQL_STMT *stmt);
869 int STDCALL mysql_stmt_next_result_cont(int *ret, MYSQL_STMT *stmt, int status);
870 void STDCALL mysql_close_slow_part(MYSQL *mysql);
871 void STDCALL mysql_close(MYSQL *sock);
872 int STDCALL mysql_close_start(MYSQL *sock);
873 int STDCALL mysql_close_cont(MYSQL *sock, int status);
874 my_socket STDCALL mysql_get_socket(const MYSQL *mysql);
875 unsigned int STDCALL mysql_get_timeout_value(const MYSQL *mysql);
876 unsigned int STDCALL mysql_get_timeout_value_ms(const MYSQL *mysql);
877 
878 /********************************************************************
879   mysql_net_ functions - low-level API to MySQL protocol
880 *********************************************************************/
881 unsigned long STDCALL mysql_net_read_packet(MYSQL *mysql);
882 unsigned long STDCALL mysql_net_field_length(unsigned char **packet);
883 
884 /* status return codes */
885 #define MYSQL_NO_DATA        100
886 #define MYSQL_DATA_TRUNCATED 101
887 
888 #define mysql_reload(mysql) mysql_refresh((mysql),REFRESH_GRANT)
889 
890 #ifdef USE_OLD_FUNCTIONS
891 MYSQL *		STDCALL mysql_connect(MYSQL *mysql, const char *host,
892 				      const char *user, const char *passwd);
893 int		STDCALL mysql_create_db(MYSQL *mysql, const char *DB);
894 int		STDCALL mysql_drop_db(MYSQL *mysql, const char *DB);
895 #endif
896 #define HAVE_MYSQL_REAL_CONNECT
897 
898 #ifdef	__cplusplus
899 }
900 #endif
901 
902 #endif /* _mysql_h */
903