root/trunk/dep/include/mysql/mysql.h @ 252

Revision 2, 33.1 kB (checked in by yumileroy, 17 years ago)

[svn] * Proper SVN structure

Original author: Neo2003
Date: 2008-10-02 16:23:55-05:00

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