MySQL 5.6.14 Source Code Document
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
mysql.h
1 /* Copyright (c) 2000, 2012, Oracle and/or its affiliates. All rights reserved.
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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 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 update
23  the SHARED_LIB_MAJOR_VERSION in cmake/mysql_version.cmake
24 */
25 
26 #ifndef _mysql_h
27 #define _mysql_h
28 
29 #ifdef _AIX /* large-file support will break without this */
30 #include <standards.h>
31 #endif
32 
33 #ifdef __CYGWIN__ /* CYGWIN implements a UNIX API */
34 #undef WIN
35 #undef _WIN
36 #undef _WIN32
37 #undef _WIN64
38 #undef __WIN__
39 #endif
40 
41 #ifdef __cplusplus
42 extern "C" {
43 #endif
44 
45 #ifndef MY_GLOBAL_INCLUDED /* If not standard header */
46 #ifndef MYSQL_ABI_CHECK
47 #include <sys/types.h>
48 #endif
49 #ifdef __LCC__
50 #include <winsock2.h> /* For windows */
51 #endif
52 typedef char my_bool;
53 #if (defined(_WIN32) || defined(_WIN64)) && !defined(__WIN__)
54 #define __WIN__
55 #endif
56 #if !defined(__WIN__)
57 #define STDCALL
58 #else
59 #define STDCALL __stdcall
60 #endif
61 
62 #ifndef my_socket_defined
63 #ifdef __WIN__
64 #define my_socket SOCKET
65 #else
66 typedef int my_socket;
67 #endif /* __WIN__ */
68 #endif /* my_socket_defined */
69 #endif /* MY_GLOBAL_INCLUDED */
70 
71 #include "mysql_version.h"
72 #include "mysql_com.h"
73 #include "mysql_time.h"
74 
75 #include "my_list.h" /* for LISTs used in 'MYSQL' and 'MYSQL_STMT' */
76 
77 extern unsigned int mysql_port;
78 extern char *mysql_unix_port;
79 
80 #define CLIENT_NET_READ_TIMEOUT 365*24*3600 /* Timeout on read */
81 #define CLIENT_NET_WRITE_TIMEOUT 365*24*3600 /* Timeout on write */
82 
83 #define IS_PRI_KEY(n) ((n) & PRI_KEY_FLAG)
84 #define IS_NOT_NULL(n) ((n) & NOT_NULL_FLAG)
85 #define IS_BLOB(n) ((n) & BLOB_FLAG)
86 
90 #define IS_NUM(t) (((t) <= MYSQL_TYPE_INT24 && (t) != MYSQL_TYPE_TIMESTAMP) || (t) == MYSQL_TYPE_YEAR || (t) == MYSQL_TYPE_NEWDECIMAL)
91 #define IS_LONGDATA(t) ((t) >= MYSQL_TYPE_TINY_BLOB && (t) <= MYSQL_TYPE_STRING)
92 
93 
94 typedef struct st_mysql_field {
95  char *name; /* Name of column */
96  char *org_name; /* Original column name, if an alias */
97  char *table; /* Table of column if column was a field */
98  char *org_table; /* Org table name, if table was an alias */
99  char *db; /* Database for table */
100  char *catalog; /* Catalog for table */
101  char *def; /* Default value (set by mysql_list_fields) */
102  unsigned long length; /* Width of column (create length) */
103  unsigned long max_length; /* Max width for selected set */
104  unsigned int name_length;
105  unsigned int org_name_length;
106  unsigned int table_length;
107  unsigned int org_table_length;
108  unsigned int db_length;
109  unsigned int catalog_length;
110  unsigned int def_length;
111  unsigned int flags; /* Div flags */
112  unsigned int decimals; /* Number of decimals in field */
113  unsigned int charsetnr; /* Character set */
114  enum enum_field_types type; /* Type of field. See mysql_com.h for types */
115  void *extension;
116 } MYSQL_FIELD;
117 
118 typedef char **MYSQL_ROW; /* return data as array of strings */
119 typedef unsigned int MYSQL_FIELD_OFFSET; /* offset to current field */
120 
121 #ifndef MY_GLOBAL_INCLUDED
122 #if defined(NO_CLIENT_LONG_LONG)
123 typedef unsigned long my_ulonglong;
124 #elif defined (__WIN__)
125 typedef unsigned __int64 my_ulonglong;
126 #else
127 typedef unsigned long long my_ulonglong;
128 #endif
129 #endif
130 
131 #include "typelib.h"
132 
133 #define MYSQL_COUNT_ERROR (~(my_ulonglong) 0)
134 
135 /* backward compatibility define - to be removed eventually */
136 #define ER_WARN_DATA_TRUNCATED WARN_DATA_TRUNCATED
137 
138 typedef struct st_mysql_rows {
139  struct st_mysql_rows *next; /* list of rows */
140  MYSQL_ROW data;
141  unsigned long length;
142 } MYSQL_ROWS;
143 
144 typedef MYSQL_ROWS *MYSQL_ROW_OFFSET; /* offset to current row */
145 
146 #include "my_alloc.h"
147 
149 typedef struct st_mysql_data {
150  MYSQL_ROWS *data;
151  struct embedded_query_result *embedded_info;
152  MEM_ROOT alloc;
153  my_ulonglong rows;
154  unsigned int fields;
155  /* extra info for embedded library */
156  void *extension;
157 } MYSQL_DATA;
158 
159 enum mysql_option
160 {
161  MYSQL_OPT_CONNECT_TIMEOUT, MYSQL_OPT_COMPRESS, MYSQL_OPT_NAMED_PIPE,
162  MYSQL_INIT_COMMAND, MYSQL_READ_DEFAULT_FILE, MYSQL_READ_DEFAULT_GROUP,
163  MYSQL_SET_CHARSET_DIR, MYSQL_SET_CHARSET_NAME, MYSQL_OPT_LOCAL_INFILE,
164  MYSQL_OPT_PROTOCOL, MYSQL_SHARED_MEMORY_BASE_NAME, MYSQL_OPT_READ_TIMEOUT,
165  MYSQL_OPT_WRITE_TIMEOUT, MYSQL_OPT_USE_RESULT,
166  MYSQL_OPT_USE_REMOTE_CONNECTION, MYSQL_OPT_USE_EMBEDDED_CONNECTION,
167  MYSQL_OPT_GUESS_CONNECTION, MYSQL_SET_CLIENT_IP, MYSQL_SECURE_AUTH,
168  MYSQL_REPORT_DATA_TRUNCATION, MYSQL_OPT_RECONNECT,
169  MYSQL_OPT_SSL_VERIFY_SERVER_CERT, MYSQL_PLUGIN_DIR, MYSQL_DEFAULT_AUTH,
170  MYSQL_OPT_BIND,
171  MYSQL_OPT_SSL_KEY, MYSQL_OPT_SSL_CERT,
172  MYSQL_OPT_SSL_CA, MYSQL_OPT_SSL_CAPATH, MYSQL_OPT_SSL_CIPHER,
173  MYSQL_OPT_SSL_CRL, MYSQL_OPT_SSL_CRLPATH,
174  MYSQL_OPT_CONNECT_ATTR_RESET, MYSQL_OPT_CONNECT_ATTR_ADD,
175  MYSQL_OPT_CONNECT_ATTR_DELETE,
176  MYSQL_SERVER_PUBLIC_KEY,
177  MYSQL_ENABLE_CLEARTEXT_PLUGIN,
178  MYSQL_OPT_CAN_HANDLE_EXPIRED_PASSWORDS
179 };
180 
186 
188  unsigned int connect_timeout, read_timeout, write_timeout;
189  unsigned int port, protocol;
190  unsigned long client_flag;
191  char *host,*user,*password,*unix_socket,*db;
192  struct st_dynamic_array *init_commands;
193  char *my_cnf_file,*my_cnf_group, *charset_dir, *charset_name;
194  char *ssl_key; /* PEM key file */
195  char *ssl_cert; /* PEM cert file */
196  char *ssl_ca; /* PEM CA file */
197  char *ssl_capath; /* PEM directory of CA-s? */
198  char *ssl_cipher; /* cipher to use */
199  char *shared_memory_base_name;
200  unsigned long max_allowed_packet;
201  my_bool use_ssl; /* if to use SSL or not */
202  my_bool compress,named_pipe;
203  my_bool unused1;
204  my_bool unused2;
205  my_bool unused3;
206  my_bool unused4;
207  enum mysql_option methods_to_use;
208  union {
209  /*
210  The ip/hostname to use when authenticating
211  client against embedded server built with
212  grant tables - only used in embedded server
213  */
214  char *client_ip;
215 
216  /*
217  The local address to bind when connecting to
218  remote server - not used in embedded server
219  */
220  char *bind_address;
221  } ci;
222  /* Refuse client connecting to server if it uses old (pre-4.1.1) protocol */
223  my_bool secure_auth;
224  /* 0 - never report, 1 - always report (default) */
225  my_bool report_data_truncation;
226 
227  /* function pointers for local infile support */
228  int (*local_infile_init)(void **, const char *, void *);
229  int (*local_infile_read)(void *, char *, unsigned int);
230  void (*local_infile_end)(void *);
231  int (*local_infile_error)(void *, char *, unsigned int);
232  void *local_infile_userdata;
233  struct st_mysql_options_extention *extension;
234 };
235 
236 enum mysql_status
237 {
238  MYSQL_STATUS_READY, MYSQL_STATUS_GET_RESULT, MYSQL_STATUS_USE_RESULT,
239  MYSQL_STATUS_STATEMENT_GET_RESULT
240 };
241 
242 enum mysql_protocol_type
243 {
244  MYSQL_PROTOCOL_DEFAULT, MYSQL_PROTOCOL_TCP, MYSQL_PROTOCOL_SOCKET,
245  MYSQL_PROTOCOL_PIPE, MYSQL_PROTOCOL_MEMORY
246 };
247 
248 typedef struct character_set
249 {
250  unsigned int number; /* character set number */
251  unsigned int state; /* character set state */
252  const char *csname; /* collation name */
253  const char *name; /* character set name */
254  const char *comment; /* comment */
255  const char *dir; /* character set directory */
256  unsigned int mbminlen; /* min. length for multibyte strings */
257  unsigned int mbmaxlen; /* max. length for multibyte strings */
259 
260 struct st_mysql_methods;
261 struct st_mysql_stmt;
262 
263 typedef struct st_mysql
264 {
265  NET net; /* Communication parameters */
266  unsigned char *connector_fd; /* ConnectorFd for SSL */
267  char *host,*user,*passwd,*unix_socket,*server_version,*host_info;
268  char *info, *db;
269  struct charset_info_st *charset;
270  MYSQL_FIELD *fields;
271  MEM_ROOT field_alloc;
272  my_ulonglong affected_rows;
273  my_ulonglong insert_id; /* id if insert on table with NEXTNR */
274  my_ulonglong extra_info; /* Not used */
275  unsigned long thread_id; /* Id for connection in server */
276  unsigned long packet_length;
277  unsigned int port;
278  unsigned long client_flag,server_capabilities;
279  unsigned int protocol_version;
280  unsigned int field_count;
281  unsigned int server_status;
282  unsigned int server_language;
283  unsigned int warning_count;
284  struct st_mysql_options options;
285  enum mysql_status status;
286  my_bool free_me; /* If free in mysql_close */
287  my_bool reconnect; /* set to 1 if automatic reconnect */
288 
289  /* session-wide random string */
290  char scramble[SCRAMBLE_LENGTH+1];
291  my_bool unused1;
292  void *unused2, *unused3, *unused4, *unused5;
293 
294  LIST *stmts; /* list of all statements */
295  const struct st_mysql_methods *methods;
296  void *thd;
297  /*
298  Points to boolean flag in MYSQL_RES or MYSQL_STMT. We set this flag
299  from mysql_stmt_close if close had to cancel result set of this object.
300  */
301  my_bool *unbuffered_fetch_owner;
302  /* needed for embedded server - no net buffer to store the 'info' */
303  char *info_buffer;
304  void *extension;
305 } MYSQL;
306 
307 
308 typedef struct st_mysql_res {
309  my_ulonglong row_count;
310  MYSQL_FIELD *fields;
311  MYSQL_DATA *data;
312  MYSQL_ROWS *data_cursor;
313  unsigned long *lengths; /* column lengths of current row */
314  MYSQL *handle; /* for unbuffered reads */
315  const struct st_mysql_methods *methods;
316  MYSQL_ROW row; /* If unbuffered read */
317  MYSQL_ROW current_row; /* buffer to current row */
318  MEM_ROOT field_alloc;
319  unsigned int field_count, current_field;
320  my_bool eof; /* Used by mysql_fetch_row */
321  /* mysql_stmt_close() had to cancel this result */
322  my_bool unbuffered_fetch_cancelled;
323  void *extension;
324 } MYSQL_RES;
325 
326 
327 #if !defined(MYSQL_SERVER) && !defined(MYSQL_CLIENT)
328 #define MYSQL_CLIENT
329 #endif
330 
331 
332 typedef struct st_mysql_parameters
333 {
334  unsigned long *p_max_allowed_packet;
335  unsigned long *p_net_buffer_length;
336  void *extension;
338 
339 #if !defined(MYSQL_SERVER) && !defined(EMBEDDED_LIBRARY)
340 #define max_allowed_packet (*mysql_get_parameters()->p_max_allowed_packet)
341 #define net_buffer_length (*mysql_get_parameters()->p_net_buffer_length)
342 #endif
343 
344 /*
345  Set up and bring down the server; to ensure that applications will
346  work when linked against either the standard client library or the
347  embedded server library, these functions should be called.
348 */
349 int STDCALL mysql_server_init(int argc, char **argv, char **groups);
350 void STDCALL mysql_server_end(void);
351 
352 /*
353  mysql_server_init/end need to be called when using libmysqld or
354  libmysqlclient (exactly, mysql_server_init() is called by mysql_init() so
355  you don't need to call it explicitely; but you need to call
356  mysql_server_end() to free memory). The names are a bit misleading
357  (mysql_SERVER* to be used when using libmysqlCLIENT). So we add more general
358  names which suit well whether you're using libmysqld or libmysqlclient. We
359  intend to promote these aliases over the mysql_server* ones.
360 */
361 #define mysql_library_init mysql_server_init
362 #define mysql_library_end mysql_server_end
363 
364 MYSQL_PARAMETERS *STDCALL mysql_get_parameters(void);
365 
366 /*
367  Set up and bring down a thread; these function should be called
368  for each thread in an application which opens at least one MySQL
369  connection. All uses of the connection(s) should be between these
370  function calls.
371 */
372 my_bool STDCALL mysql_thread_init(void);
373 void STDCALL mysql_thread_end(void);
374 
375 /*
376  Functions to get information from the MYSQL and MYSQL_RES structures
377  Should definitely be used if one uses shared libraries.
378 */
379 
380 my_ulonglong STDCALL mysql_num_rows(MYSQL_RES *res);
381 unsigned int STDCALL mysql_num_fields(MYSQL_RES *res);
382 my_bool STDCALL mysql_eof(MYSQL_RES *res);
383 MYSQL_FIELD *STDCALL mysql_fetch_field_direct(MYSQL_RES *res,
384  unsigned int fieldnr);
385 MYSQL_FIELD * STDCALL mysql_fetch_fields(MYSQL_RES *res);
386 MYSQL_ROW_OFFSET STDCALL mysql_row_tell(MYSQL_RES *res);
387 MYSQL_FIELD_OFFSET STDCALL mysql_field_tell(MYSQL_RES *res);
388 
389 unsigned int STDCALL mysql_field_count(MYSQL *mysql);
390 my_ulonglong STDCALL mysql_affected_rows(MYSQL *mysql);
391 my_ulonglong STDCALL mysql_insert_id(MYSQL *mysql);
392 unsigned int STDCALL mysql_errno(MYSQL *mysql);
393 const char * STDCALL mysql_error(MYSQL *mysql);
394 const char *STDCALL mysql_sqlstate(MYSQL *mysql);
395 unsigned int STDCALL mysql_warning_count(MYSQL *mysql);
396 const char * STDCALL mysql_info(MYSQL *mysql);
397 unsigned long STDCALL mysql_thread_id(MYSQL *mysql);
398 const char * STDCALL mysql_character_set_name(MYSQL *mysql);
399 int STDCALL mysql_set_character_set(MYSQL *mysql, const char *csname);
400 
401 MYSQL * STDCALL mysql_init(MYSQL *mysql);
402 my_bool STDCALL mysql_ssl_set(MYSQL *mysql, const char *key,
403  const char *cert, const char *ca,
404  const char *capath, const char *cipher);
405 const char * STDCALL mysql_get_ssl_cipher(MYSQL *mysql);
406 my_bool STDCALL mysql_change_user(MYSQL *mysql, const char *user,
407  const char *passwd, const char *db);
408 MYSQL * STDCALL mysql_real_connect(MYSQL *mysql, const char *host,
409  const char *user,
410  const char *passwd,
411  const char *db,
412  unsigned int port,
413  const char *unix_socket,
414  unsigned long clientflag);
415 int STDCALL mysql_select_db(MYSQL *mysql, const char *db);
416 int STDCALL mysql_query(MYSQL *mysql, const char *q);
417 int STDCALL mysql_send_query(MYSQL *mysql, const char *q,
418  unsigned long length);
419 int STDCALL mysql_real_query(MYSQL *mysql, const char *q,
420  unsigned long length);
421 MYSQL_RES * STDCALL mysql_store_result(MYSQL *mysql);
422 MYSQL_RES * STDCALL mysql_use_result(MYSQL *mysql);
423 
424 void STDCALL mysql_get_character_set_info(MYSQL *mysql,
425  MY_CHARSET_INFO *charset);
426 
427 /* local infile support */
428 
429 #define LOCAL_INFILE_ERROR_LEN 512
430 
431 void
432 mysql_set_local_infile_handler(MYSQL *mysql,
433  int (*local_infile_init)(void **, const char *,
434  void *),
435  int (*local_infile_read)(void *, char *,
436  unsigned int),
437  void (*local_infile_end)(void *),
438  int (*local_infile_error)(void *, char*,
439  unsigned int),
440  void *);
441 
442 void
443 mysql_set_local_infile_default(MYSQL *mysql);
444 
445 int STDCALL mysql_shutdown(MYSQL *mysql,
446  enum mysql_enum_shutdown_level
447  shutdown_level);
448 int STDCALL mysql_dump_debug_info(MYSQL *mysql);
449 int STDCALL mysql_refresh(MYSQL *mysql,
450  unsigned int refresh_options);
451 int STDCALL mysql_kill(MYSQL *mysql,unsigned long pid);
452 int STDCALL mysql_set_server_option(MYSQL *mysql,
453  enum enum_mysql_set_option
454  option);
455 int STDCALL mysql_ping(MYSQL *mysql);
456 const char * STDCALL mysql_stat(MYSQL *mysql);
457 const char * STDCALL mysql_get_server_info(MYSQL *mysql);
458 const char * STDCALL mysql_get_client_info(void);
459 unsigned long STDCALL mysql_get_client_version(void);
460 const char * STDCALL mysql_get_host_info(MYSQL *mysql);
461 unsigned long STDCALL mysql_get_server_version(MYSQL *mysql);
462 unsigned int STDCALL mysql_get_proto_info(MYSQL *mysql);
463 MYSQL_RES * STDCALL mysql_list_dbs(MYSQL *mysql,const char *wild);
464 MYSQL_RES * STDCALL mysql_list_tables(MYSQL *mysql,const char *wild);
465 MYSQL_RES * STDCALL mysql_list_processes(MYSQL *mysql);
466 int STDCALL mysql_options(MYSQL *mysql,enum mysql_option option,
467  const void *arg);
468 int STDCALL mysql_options4(MYSQL *mysql,enum mysql_option option,
469  const void *arg1, const void *arg2);
470 void STDCALL mysql_free_result(MYSQL_RES *result);
471 void STDCALL mysql_data_seek(MYSQL_RES *result,
472  my_ulonglong offset);
473 MYSQL_ROW_OFFSET STDCALL mysql_row_seek(MYSQL_RES *result,
474  MYSQL_ROW_OFFSET offset);
475 MYSQL_FIELD_OFFSET STDCALL mysql_field_seek(MYSQL_RES *result,
476  MYSQL_FIELD_OFFSET offset);
477 MYSQL_ROW STDCALL mysql_fetch_row(MYSQL_RES *result);
478 unsigned long * STDCALL mysql_fetch_lengths(MYSQL_RES *result);
479 MYSQL_FIELD * STDCALL mysql_fetch_field(MYSQL_RES *result);
480 MYSQL_RES * STDCALL mysql_list_fields(MYSQL *mysql, const char *table,
481  const char *wild);
482 unsigned long STDCALL mysql_escape_string(char *to,const char *from,
483  unsigned long from_length);
484 unsigned long STDCALL mysql_hex_string(char *to,const char *from,
485  unsigned long from_length);
486 unsigned long STDCALL mysql_real_escape_string(MYSQL *mysql,
487  char *to,const char *from,
488  unsigned long length);
489 void STDCALL mysql_debug(const char *debug);
490 void STDCALL myodbc_remove_escape(MYSQL *mysql,char *name);
491 unsigned int STDCALL mysql_thread_safe(void);
492 my_bool STDCALL mysql_embedded(void);
493 my_bool STDCALL mysql_read_query_result(MYSQL *mysql);
494 
495 
496 /*
497  The following definitions are added for the enhanced
498  client-server protocol
499 */
500 
501 /* statement state */
502 enum enum_mysql_stmt_state
503 {
504  MYSQL_STMT_INIT_DONE= 1, MYSQL_STMT_PREPARE_DONE, MYSQL_STMT_EXECUTE_DONE,
505  MYSQL_STMT_FETCH_DONE
506 };
507 
508 
509 /*
510  This structure is used to define bind information, and
511  internally by the client library.
512  Public members with their descriptions are listed below
513  (conventionally `On input' refers to the binds given to
514  mysql_stmt_bind_param, `On output' refers to the binds given
515  to mysql_stmt_bind_result):
516 
517  buffer_type - One of the MYSQL_* types, used to describe
518  the host language type of buffer.
519  On output: if column type is different from
520  buffer_type, column value is automatically converted
521  to buffer_type before it is stored in the buffer.
522  buffer - On input: points to the buffer with input data.
523  On output: points to the buffer capable to store
524  output data.
525  The type of memory pointed by buffer must correspond
526  to buffer_type. See the correspondence table in
527  the comment to mysql_stmt_bind_param.
528 
529  The two above members are mandatory for any kind of bind.
530 
531  buffer_length - the length of the buffer. You don't have to set
532  it for any fixed length buffer: float, double,
533  int, etc. It must be set however for variable-length
534  types, such as BLOBs or STRINGs.
535 
536  length - On input: in case when lengths of input values
537  are different for each execute, you can set this to
538  point at a variable containining value length. This
539  way the value length can be different in each execute.
540  If length is not NULL, buffer_length is not used.
541  Note, length can even point at buffer_length if
542  you keep bind structures around while fetching:
543  this way you can change buffer_length before
544  each execution, everything will work ok.
545  On output: if length is set, mysql_stmt_fetch will
546  write column length into it.
547 
548  is_null - On input: points to a boolean variable that should
549  be set to TRUE for NULL values.
550  This member is useful only if your data may be
551  NULL in some but not all cases.
552  If your data is never NULL, is_null should be set to 0.
553  If your data is always NULL, set buffer_type
554  to MYSQL_TYPE_NULL, and is_null will not be used.
555 
556  is_unsigned - On input: used to signify that values provided for one
557  of numeric types are unsigned.
558  On output describes signedness of the output buffer.
559  If, taking into account is_unsigned flag, column data
560  is out of range of the output buffer, data for this column
561  is regarded truncated. Note that this has no correspondence
562  to the sign of result set column, if you need to find it out
563  use mysql_stmt_result_metadata.
564  error - where to write a truncation error if it is present.
565  possible error value is:
566  0 no truncation
567  1 value is out of range or buffer is too small
568 
569  Please note that MYSQL_BIND also has internals members.
570 */
571 
572 typedef struct st_mysql_bind
573 {
574  unsigned long *length; /* output length pointer */
575  my_bool *is_null; /* Pointer to null indicator */
576  void *buffer; /* buffer to get/put data */
577  /* set this if you want to track data truncations happened during fetch */
578  my_bool *error;
579  unsigned char *row_ptr; /* for the current data position */
580  void (*store_param_func)(NET *net, struct st_mysql_bind *param);
581  void (*fetch_result)(struct st_mysql_bind *, MYSQL_FIELD *,
582  unsigned char **row);
583  void (*skip_result)(struct st_mysql_bind *, MYSQL_FIELD *,
584  unsigned char **row);
585  /* output buffer length, must be set when fetching str/binary */
586  unsigned long buffer_length;
587  unsigned long offset; /* offset position for char/binary fetch */
588  unsigned long length_value; /* Used if length is 0 */
589  unsigned int param_number; /* For null count and error messages */
590  unsigned int pack_length; /* Internal length for packed data */
591  enum enum_field_types buffer_type; /* buffer type */
592  my_bool error_value; /* used if error is 0 */
593  my_bool is_unsigned; /* set if integer type is unsigned */
594  my_bool long_data_used; /* If used with mysql_send_long_data */
595  my_bool is_null_value; /* Used if is_null is 0 */
596  void *extension;
597 } MYSQL_BIND;
598 
599 
601 
602 /* statement handler */
603 typedef struct st_mysql_stmt
604 {
605  MEM_ROOT mem_root; /* root allocations */
606  LIST list; /* list to keep track of all stmts */
607  MYSQL *mysql; /* connection handle */
608  MYSQL_BIND *params; /* input parameters */
609  MYSQL_BIND *bind; /* output parameters */
610  MYSQL_FIELD *fields; /* result set metadata */
611  MYSQL_DATA result; /* cached result set */
612  MYSQL_ROWS *data_cursor; /* current row in cached result */
613  /*
614  mysql_stmt_fetch() calls this function to fetch one row (it's different
615  for buffered, unbuffered and cursor fetch).
616  */
617  int (*read_row_func)(struct st_mysql_stmt *stmt,
618  unsigned char **row);
619  /* copy of mysql->affected_rows after statement execution */
620  my_ulonglong affected_rows;
621  my_ulonglong insert_id; /* copy of mysql->insert_id */
622  unsigned long stmt_id; /* Id for prepared statement */
623  unsigned long flags; /* i.e. type of cursor to open */
624  unsigned long prefetch_rows; /* number of rows per one COM_FETCH */
625  /*
626  Copied from mysql->server_status after execute/fetch to know
627  server-side cursor status for this statement.
628  */
629  unsigned int server_status;
630  unsigned int last_errno; /* error code */
631  unsigned int param_count; /* input parameter count */
632  unsigned int field_count; /* number of columns in result set */
633  enum enum_mysql_stmt_state state; /* statement state */
634  char last_error[MYSQL_ERRMSG_SIZE]; /* error message */
635  char sqlstate[SQLSTATE_LENGTH+1];
636  /* Types of input parameters should be sent to server */
637  my_bool send_types_to_server;
638  my_bool bind_param_done; /* input buffers were supplied */
639  unsigned char bind_result_done; /* output buffers were supplied */
640  /* mysql_stmt_close() had to cancel this result */
641  my_bool unbuffered_fetch_cancelled;
642  /*
643  Is set to true if we need to calculate field->max_length for
644  metadata fields when doing mysql_stmt_store_result.
645  */
646  my_bool update_max_length;
647  struct st_mysql_stmt_extension *extension;
648 } MYSQL_STMT;
649 
650 enum enum_stmt_attr_type
651 {
652  /*
653  When doing mysql_stmt_store_result calculate max_length attribute
654  of statement metadata. This is to be consistent with the old API,
655  where this was done automatically.
656  In the new API we do that only by request because it slows down
657  mysql_stmt_store_result sufficiently.
658  */
659  STMT_ATTR_UPDATE_MAX_LENGTH,
660  /*
661  unsigned long with combination of cursor flags (read only, for update,
662  etc)
663  */
664  STMT_ATTR_CURSOR_TYPE,
665  /*
666  Amount of rows to retrieve from server per one fetch if using cursors.
667  Accepts unsigned long attribute in the range 1 - ulong_max
668  */
669  STMT_ATTR_PREFETCH_ROWS
670 };
671 
672 
673 MYSQL_STMT * STDCALL mysql_stmt_init(MYSQL *mysql);
674 int STDCALL mysql_stmt_prepare(MYSQL_STMT *stmt, const char *query,
675  unsigned long length);
676 int STDCALL mysql_stmt_execute(MYSQL_STMT *stmt);
677 int STDCALL mysql_stmt_fetch(MYSQL_STMT *stmt);
678 int STDCALL mysql_stmt_fetch_column(MYSQL_STMT *stmt, MYSQL_BIND *bind_arg,
679  unsigned int column,
680  unsigned long offset);
681 int STDCALL mysql_stmt_store_result(MYSQL_STMT *stmt);
682 unsigned long STDCALL mysql_stmt_param_count(MYSQL_STMT * stmt);
683 my_bool STDCALL mysql_stmt_attr_set(MYSQL_STMT *stmt,
684  enum enum_stmt_attr_type attr_type,
685  const void *attr);
686 my_bool STDCALL mysql_stmt_attr_get(MYSQL_STMT *stmt,
687  enum enum_stmt_attr_type attr_type,
688  void *attr);
689 my_bool STDCALL mysql_stmt_bind_param(MYSQL_STMT * stmt, MYSQL_BIND * bnd);
690 my_bool STDCALL mysql_stmt_bind_result(MYSQL_STMT * stmt, MYSQL_BIND * bnd);
691 my_bool STDCALL mysql_stmt_close(MYSQL_STMT * stmt);
692 my_bool STDCALL mysql_stmt_reset(MYSQL_STMT * stmt);
693 my_bool STDCALL mysql_stmt_free_result(MYSQL_STMT *stmt);
694 my_bool STDCALL mysql_stmt_send_long_data(MYSQL_STMT *stmt,
695  unsigned int param_number,
696  const char *data,
697  unsigned long length);
698 MYSQL_RES *STDCALL mysql_stmt_result_metadata(MYSQL_STMT *stmt);
699 MYSQL_RES *STDCALL mysql_stmt_param_metadata(MYSQL_STMT *stmt);
700 unsigned int STDCALL mysql_stmt_errno(MYSQL_STMT * stmt);
701 const char *STDCALL mysql_stmt_error(MYSQL_STMT * stmt);
702 const char *STDCALL mysql_stmt_sqlstate(MYSQL_STMT * stmt);
703 MYSQL_ROW_OFFSET STDCALL mysql_stmt_row_seek(MYSQL_STMT *stmt,
704  MYSQL_ROW_OFFSET offset);
705 MYSQL_ROW_OFFSET STDCALL mysql_stmt_row_tell(MYSQL_STMT *stmt);
706 void STDCALL mysql_stmt_data_seek(MYSQL_STMT *stmt, my_ulonglong offset);
707 my_ulonglong STDCALL mysql_stmt_num_rows(MYSQL_STMT *stmt);
708 my_ulonglong STDCALL mysql_stmt_affected_rows(MYSQL_STMT *stmt);
709 my_ulonglong STDCALL mysql_stmt_insert_id(MYSQL_STMT *stmt);
710 unsigned int STDCALL mysql_stmt_field_count(MYSQL_STMT *stmt);
711 
712 my_bool STDCALL mysql_commit(MYSQL * mysql);
713 my_bool STDCALL mysql_rollback(MYSQL * mysql);
714 my_bool STDCALL mysql_autocommit(MYSQL * mysql, my_bool auto_mode);
715 my_bool STDCALL mysql_more_results(MYSQL *mysql);
716 int STDCALL mysql_next_result(MYSQL *mysql);
717 int STDCALL mysql_stmt_next_result(MYSQL_STMT *stmt);
718 void STDCALL mysql_close(MYSQL *sock);
719 
720 
721 /* status return codes */
722 #define MYSQL_NO_DATA 100
723 #define MYSQL_DATA_TRUNCATED 101
724 
725 #define mysql_reload(mysql) mysql_refresh((mysql),REFRESH_GRANT)
726 
727 #ifdef USE_OLD_FUNCTIONS
728 MYSQL * STDCALL mysql_connect(MYSQL *mysql, const char *host,
729  const char *user, const char *passwd);
730 int STDCALL mysql_create_db(MYSQL *mysql, const char *DB);
731 int STDCALL mysql_drop_db(MYSQL *mysql, const char *DB);
732 #endif
733 #define HAVE_MYSQL_REAL_CONNECT
734 
735 #ifdef __cplusplus
736 }
737 #endif
738 
739 #endif /* _mysql_h */