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