root/src/mysql/mysql.h @ 25

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