1/* Copyright (c) 2000, 2017, 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
42extern "C" {
43#endif
44
45#ifndef _global_h /* 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
52typedef 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
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
75#include "my_list.h" /* for LISTs used in 'MYSQL' and 'MYSQL_STMT' */
76
77extern unsigned int mysql_port;
78extern 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/**
87 Returns true if the value is a number which does not need quotes for
88 the sql_lex.cc parser to parse correctly.
89*/
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
94typedef 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
118typedef char **MYSQL_ROW; /* return data as array of strings */
119typedef unsigned int MYSQL_FIELD_OFFSET; /* offset to current field */
120
121#ifndef _global_h
122#if defined(NO_CLIENT_LONG_LONG)
123typedef unsigned long my_ulonglong;
124#elif defined (__WIN__)
125typedef unsigned __int64 my_ulonglong;
126#else
127typedef 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
138typedef 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
144typedef MYSQL_ROWS *MYSQL_ROW_OFFSET; /* offset to current row */
145
146#include "my_alloc.h"
147
148typedef struct embedded_query_result EMBEDDED_QUERY_RESULT;
149typedef 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
159enum 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_ENABLE_CLEARTEXT_PLUGIN,
171 /* Set MYSQL_OPT_SSL_MODE to be the same as in 5.6 (ABI compatibility). */
172 MYSQL_OPT_SSL_MODE= 38
173};
174
175/**
176 @todo remove the "extension", move st_mysql_options completely
177 out of mysql.h
178*/
179struct st_mysql_options_extention;
180
181struct st_mysql_options {
182 unsigned int connect_timeout, read_timeout, write_timeout;
183 unsigned int port, protocol;
184 unsigned long client_flag;
185 char *host,*user,*password,*unix_socket,*db;
186 struct st_dynamic_array *init_commands;
187 char *my_cnf_file,*my_cnf_group, *charset_dir, *charset_name;
188 char *ssl_key; /* PEM key file */
189 char *ssl_cert; /* PEM cert file */
190 char *ssl_ca; /* PEM CA file */
191 char *ssl_capath; /* PEM directory of CA-s? */
192 char *ssl_cipher; /* cipher to use */
193 char *shared_memory_base_name;
194 unsigned long max_allowed_packet;
195 my_bool use_ssl; /* if to use SSL or not */
196 my_bool compress,named_pipe;
197 my_bool unused1;
198 my_bool unused2;
199 my_bool unused3;
200 my_bool unused4;
201 enum mysql_option methods_to_use;
202 char *client_ip;
203 /* Refuse client connecting to server if it uses old (pre-4.1.1) protocol */
204 my_bool secure_auth;
205 /* 0 - never report, 1 - always report (default) */
206 my_bool report_data_truncation;
207
208 /* function pointers for local infile support */
209 int (*local_infile_init)(void **, const char *, void *);
210 int (*local_infile_read)(void *, char *, unsigned int);
211 void (*local_infile_end)(void *);
212 int (*local_infile_error)(void *, char *, unsigned int);
213 void *local_infile_userdata;
214 struct st_mysql_options_extention *extension;
215};
216
217enum mysql_status
218{
219 MYSQL_STATUS_READY, MYSQL_STATUS_GET_RESULT, MYSQL_STATUS_USE_RESULT,
220 MYSQL_STATUS_STATEMENT_GET_RESULT
221};
222
223enum mysql_protocol_type
224{
225 MYSQL_PROTOCOL_DEFAULT, MYSQL_PROTOCOL_TCP, MYSQL_PROTOCOL_SOCKET,
226 MYSQL_PROTOCOL_PIPE, MYSQL_PROTOCOL_MEMORY
227};
228
229enum mysql_ssl_mode
230{
231 SSL_MODE_REQUIRED= 3
232};
233
234typedef struct character_set
235{
236 unsigned int number; /* character set number */
237 unsigned int state; /* character set state */
238 const char *csname; /* collation name */
239 const char *name; /* character set name */
240 const char *comment; /* comment */
241 const char *dir; /* character set directory */
242 unsigned int mbminlen; /* min. length for multibyte strings */
243 unsigned int mbmaxlen; /* max. length for multibyte strings */
244} MY_CHARSET_INFO;
245
246struct st_mysql_methods;
247struct st_mysql_stmt;
248
249typedef struct st_mysql
250{
251 NET net; /* Communication parameters */
252 unsigned char *connector_fd; /* ConnectorFd for SSL */
253 char *host,*user,*passwd,*unix_socket,*server_version,*host_info;
254 char *info, *db;
255 struct charset_info_st *charset;
256 MYSQL_FIELD *fields;
257 MEM_ROOT field_alloc;
258 my_ulonglong affected_rows;
259 my_ulonglong insert_id; /* id if insert on table with NEXTNR */
260 my_ulonglong extra_info; /* Not used */
261 unsigned long thread_id; /* Id for connection in server */
262 unsigned long packet_length;
263 unsigned int port;
264 unsigned long client_flag,server_capabilities;
265 unsigned int protocol_version;
266 unsigned int field_count;
267 unsigned int server_status;
268 unsigned int server_language;
269 unsigned int warning_count;
270 struct st_mysql_options options;
271 enum mysql_status status;
272 my_bool free_me; /* If free in mysql_close */
273 my_bool reconnect; /* set to 1 if automatic reconnect */
274
275 /* session-wide random string */
276 char scramble[SCRAMBLE_LENGTH+1];
277 my_bool unused1;
278 void *unused2, *unused3, *unused4, *unused5;
279
280 LIST *stmts; /* list of all statements */
281 const struct st_mysql_methods *methods;
282 void *thd;
283 /*
284 Points to boolean flag in MYSQL_RES or MYSQL_STMT. We set this flag
285 from mysql_stmt_close if close had to cancel result set of this object.
286 */
287 my_bool *unbuffered_fetch_owner;
288 /* needed for embedded server - no net buffer to store the 'info' */
289 char *info_buffer;
290 void *extension;
291} MYSQL;
292
293
294typedef struct st_mysql_res {
295 my_ulonglong row_count;
296 MYSQL_FIELD *fields;
297 MYSQL_DATA *data;
298 MYSQL_ROWS *data_cursor;
299 unsigned long *lengths; /* column lengths of current row */
300 MYSQL *handle; /* for unbuffered reads */
301 const struct st_mysql_methods *methods;
302 MYSQL_ROW row; /* If unbuffered read */
303 MYSQL_ROW current_row; /* buffer to current row */
304 MEM_ROOT field_alloc;
305 unsigned int field_count, current_field;
306 my_bool eof; /* Used by mysql_fetch_row */
307 /* mysql_stmt_close() had to cancel this result */
308 my_bool unbuffered_fetch_cancelled;
309 void *extension;
310} MYSQL_RES;
311
312
313#if !defined(MYSQL_SERVER) && !defined(MYSQL_CLIENT)
314#define MYSQL_CLIENT
315#endif
316
317
318typedef struct st_mysql_parameters
319{
320 unsigned long *p_max_allowed_packet;
321 unsigned long *p_net_buffer_length;
322 void *extension;
323} MYSQL_PARAMETERS;
324
325#if !defined(MYSQL_SERVER) && !defined(EMBEDDED_LIBRARY)
326#define max_allowed_packet (*mysql_get_parameters()->p_max_allowed_packet)
327#define net_buffer_length (*mysql_get_parameters()->p_net_buffer_length)
328#endif
329
330/*
331 Set up and bring down the server; to ensure that applications will
332 work when linked against either the standard client library or the
333 embedded server library, these functions should be called.
334*/
335int STDCALL mysql_server_init(int argc, char **argv, char **groups);
336void STDCALL mysql_server_end(void);
337
338/*
339 mysql_server_init/end need to be called when using libmysqld or
340 libmysqlclient (exactly, mysql_server_init() is called by mysql_init() so
341 you don't need to call it explicitely; but you need to call
342 mysql_server_end() to free memory). The names are a bit misleading
343 (mysql_SERVER* to be used when using libmysqlCLIENT). So we add more general
344 names which suit well whether you're using libmysqld or libmysqlclient. We
345 intend to promote these aliases over the mysql_server* ones.
346*/
347#define mysql_library_init mysql_server_init
348#define mysql_library_end mysql_server_end
349
350MYSQL_PARAMETERS *STDCALL mysql_get_parameters(void);
351
352/*
353 Set up and bring down a thread; these function should be called
354 for each thread in an application which opens at least one MySQL
355 connection. All uses of the connection(s) should be between these
356 function calls.
357*/
358my_bool STDCALL mysql_thread_init(void);
359void STDCALL mysql_thread_end(void);
360
361/*
362 Functions to get information from the MYSQL and MYSQL_RES structures
363 Should definitely be used if one uses shared libraries.
364*/
365
366my_ulonglong STDCALL mysql_num_rows(MYSQL_RES *res);
367unsigned int STDCALL mysql_num_fields(MYSQL_RES *res);
368my_bool STDCALL mysql_eof(MYSQL_RES *res);
369MYSQL_FIELD *STDCALL mysql_fetch_field_direct(MYSQL_RES *res,
370 unsigned int fieldnr);
371MYSQL_FIELD * STDCALL mysql_fetch_fields(MYSQL_RES *res);
372MYSQL_ROW_OFFSET STDCALL mysql_row_tell(MYSQL_RES *res);
373MYSQL_FIELD_OFFSET STDCALL mysql_field_tell(MYSQL_RES *res);
374
375unsigned int STDCALL mysql_field_count(MYSQL *mysql);
376my_ulonglong STDCALL mysql_affected_rows(MYSQL *mysql);
377my_ulonglong STDCALL mysql_insert_id(MYSQL *mysql);
378unsigned int STDCALL mysql_errno(MYSQL *mysql);
379const char * STDCALL mysql_error(MYSQL *mysql);
380const char *STDCALL mysql_sqlstate(MYSQL *mysql);
381unsigned int STDCALL mysql_warning_count(MYSQL *mysql);
382const char * STDCALL mysql_info(MYSQL *mysql);
383unsigned long STDCALL mysql_thread_id(MYSQL *mysql);
384const char * STDCALL mysql_character_set_name(MYSQL *mysql);
385int STDCALL mysql_set_character_set(MYSQL *mysql, const char *csname);
386
387MYSQL * STDCALL mysql_init(MYSQL *mysql);
388my_bool STDCALL mysql_ssl_set(MYSQL *mysql, const char *key,
389 const char *cert, const char *ca,
390 const char *capath, const char *cipher);
391const char * STDCALL mysql_get_ssl_cipher(MYSQL *mysql);
392my_bool STDCALL mysql_change_user(MYSQL *mysql, const char *user,
393 const char *passwd, const char *db);
394MYSQL * STDCALL mysql_real_connect(MYSQL *mysql, const char *host,
395 const char *user,
396 const char *passwd,
397 const char *db,
398 unsigned int port,
399 const char *unix_socket,
400 unsigned long clientflag);
401int STDCALL mysql_select_db(MYSQL *mysql, const char *db);
402int STDCALL mysql_query(MYSQL *mysql, const char *q);
403int STDCALL mysql_send_query(MYSQL *mysql, const char *q,
404 unsigned long length);
405int STDCALL mysql_real_query(MYSQL *mysql, const char *q,
406 unsigned long length);
407MYSQL_RES * STDCALL mysql_store_result(MYSQL *mysql);
408MYSQL_RES * STDCALL mysql_use_result(MYSQL *mysql);
409
410void STDCALL mysql_get_character_set_info(MYSQL *mysql,
411 MY_CHARSET_INFO *charset);
412
413/* local infile support */
414
415#define LOCAL_INFILE_ERROR_LEN 512
416
417void
418mysql_set_local_infile_handler(MYSQL *mysql,
419 int (*local_infile_init)(void **, const char *,
420 void *),
421 int (*local_infile_read)(void *, char *,
422 unsigned int),
423 void (*local_infile_end)(void *),
424 int (*local_infile_error)(void *, char*,
425 unsigned int),
426 void *);
427
428void
429mysql_set_local_infile_default(MYSQL *mysql);
430
431int STDCALL mysql_shutdown(MYSQL *mysql,
432 enum mysql_enum_shutdown_level
433 shutdown_level);
434int STDCALL mysql_dump_debug_info(MYSQL *mysql);
435int STDCALL mysql_refresh(MYSQL *mysql,
436 unsigned int refresh_options);
437int STDCALL mysql_kill(MYSQL *mysql,unsigned long pid);
438int STDCALL mysql_set_server_option(MYSQL *mysql,
439 enum enum_mysql_set_option
440 option);
441int STDCALL mysql_ping(MYSQL *mysql);
442const char * STDCALL mysql_stat(MYSQL *mysql);
443const char * STDCALL mysql_get_server_info(MYSQL *mysql);
444const char * STDCALL mysql_get_client_info(void);
445unsigned long STDCALL mysql_get_client_version(void);
446const char * STDCALL mysql_get_host_info(MYSQL *mysql);
447unsigned long STDCALL mysql_get_server_version(MYSQL *mysql);
448unsigned int STDCALL mysql_get_proto_info(MYSQL *mysql);
449MYSQL_RES * STDCALL mysql_list_dbs(MYSQL *mysql,const char *wild);
450MYSQL_RES * STDCALL mysql_list_tables(MYSQL *mysql,const char *wild);
451MYSQL_RES * STDCALL mysql_list_processes(MYSQL *mysql);
452int STDCALL mysql_options(MYSQL *mysql,enum mysql_option option,
453 const void *arg);
454void STDCALL mysql_free_result(MYSQL_RES *result);
455void STDCALL mysql_data_seek(MYSQL_RES *result,
456 my_ulonglong offset);
457MYSQL_ROW_OFFSET STDCALL mysql_row_seek(MYSQL_RES *result,
458 MYSQL_ROW_OFFSET offset);
459MYSQL_FIELD_OFFSET STDCALL mysql_field_seek(MYSQL_RES *result,
460 MYSQL_FIELD_OFFSET offset);
461MYSQL_ROW STDCALL mysql_fetch_row(MYSQL_RES *result);
462unsigned long * STDCALL mysql_fetch_lengths(MYSQL_RES *result);
463MYSQL_FIELD * STDCALL mysql_fetch_field(MYSQL_RES *result);
464MYSQL_RES * STDCALL mysql_list_fields(MYSQL *mysql, const char *table,
465 const char *wild);
466unsigned long STDCALL mysql_escape_string(char *to,const char *from,
467 unsigned long from_length);
468unsigned long STDCALL mysql_hex_string(char *to,const char *from,
469 unsigned long from_length);
470unsigned long STDCALL mysql_real_escape_string(MYSQL *mysql,
471 char *to,const char *from,
472 unsigned long length);
473void STDCALL mysql_debug(const char *debug);
474void STDCALL myodbc_remove_escape(MYSQL *mysql,char *name);
475unsigned int STDCALL mysql_thread_safe(void);
476my_bool STDCALL mysql_embedded(void);
477my_bool STDCALL mysql_read_query_result(MYSQL *mysql);
478
479
480/*
481 The following definitions are added for the enhanced
482 client-server protocol
483*/
484
485/* statement state */
486enum enum_mysql_stmt_state
487{
488 MYSQL_STMT_INIT_DONE= 1, MYSQL_STMT_PREPARE_DONE, MYSQL_STMT_EXECUTE_DONE,
489 MYSQL_STMT_FETCH_DONE
490};
491
492
493/*
494 This structure is used to define bind information, and
495 internally by the client library.
496 Public members with their descriptions are listed below
497 (conventionally `On input' refers to the binds given to
498 mysql_stmt_bind_param, `On output' refers to the binds given
499 to mysql_stmt_bind_result):
500
501 buffer_type - One of the MYSQL_* types, used to describe
502 the host language type of buffer.
503 On output: if column type is different from
504 buffer_type, column value is automatically converted
505 to buffer_type before it is stored in the buffer.
506 buffer - On input: points to the buffer with input data.
507 On output: points to the buffer capable to store
508 output data.
509 The type of memory pointed by buffer must correspond
510 to buffer_type. See the correspondence table in
511 the comment to mysql_stmt_bind_param.
512
513 The two above members are mandatory for any kind of bind.
514
515 buffer_length - the length of the buffer. You don't have to set
516 it for any fixed length buffer: float, double,
517 int, etc. It must be set however for variable-length
518 types, such as BLOBs or STRINGs.
519
520 length - On input: in case when lengths of input values
521 are different for each execute, you can set this to
522 point at a variable containining value length. This
523 way the value length can be different in each execute.
524 If length is not NULL, buffer_length is not used.
525 Note, length can even point at buffer_length if
526 you keep bind structures around while fetching:
527 this way you can change buffer_length before
528 each execution, everything will work ok.
529 On output: if length is set, mysql_stmt_fetch will
530 write column length into it.
531
532 is_null - On input: points to a boolean variable that should
533 be set to TRUE for NULL values.
534 This member is useful only if your data may be
535 NULL in some but not all cases.
536 If your data is never NULL, is_null should be set to 0.
537 If your data is always NULL, set buffer_type
538 to MYSQL_TYPE_NULL, and is_null will not be used.
539
540 is_unsigned - On input: used to signify that values provided for one
541 of numeric types are unsigned.
542 On output describes signedness of the output buffer.
543 If, taking into account is_unsigned flag, column data
544 is out of range of the output buffer, data for this column
545 is regarded truncated. Note that this has no correspondence
546 to the sign of result set column, if you need to find it out
547 use mysql_stmt_result_metadata.
548 error - where to write a truncation error if it is present.
549 possible error value is:
550 0 no truncation
551 1 value is out of range or buffer is too small
552
553 Please note that MYSQL_BIND also has internals members.
554*/
555
556typedef struct st_mysql_bind
557{
558 unsigned long *length; /* output length pointer */
559 my_bool *is_null; /* Pointer to null indicator */
560 void *buffer; /* buffer to get/put data */
561 /* set this if you want to track data truncations happened during fetch */
562 my_bool *error;
563 unsigned char *row_ptr; /* for the current data position */
564 void (*store_param_func)(NET *net, struct st_mysql_bind *param);
565 void (*fetch_result)(struct st_mysql_bind *, MYSQL_FIELD *,
566 unsigned char **row);
567 void (*skip_result)(struct st_mysql_bind *, MYSQL_FIELD *,
568 unsigned char **row);
569 /* output buffer length, must be set when fetching str/binary */
570 unsigned long buffer_length;
571 unsigned long offset; /* offset position for char/binary fetch */
572 unsigned long length_value; /* Used if length is 0 */
573 unsigned int param_number; /* For null count and error messages */
574 unsigned int pack_length; /* Internal length for packed data */
575 enum enum_field_types buffer_type; /* buffer type */
576 my_bool error_value; /* used if error is 0 */
577 my_bool is_unsigned; /* set if integer type is unsigned */
578 my_bool long_data_used; /* If used with mysql_send_long_data */
579 my_bool is_null_value; /* Used if is_null is 0 */
580 void *extension;
581} MYSQL_BIND;
582
583
584struct st_mysql_stmt_extension;
585
586/* statement handler */
587typedef struct st_mysql_stmt
588{
589 MEM_ROOT mem_root; /* root allocations */
590 LIST list; /* list to keep track of all stmts */
591 MYSQL *mysql; /* connection handle */
592 MYSQL_BIND *params; /* input parameters */
593 MYSQL_BIND *bind; /* output parameters */
594 MYSQL_FIELD *fields; /* result set metadata */
595 MYSQL_DATA result; /* cached result set */
596 MYSQL_ROWS *data_cursor; /* current row in cached result */
597 /*
598 mysql_stmt_fetch() calls this function to fetch one row (it's different
599 for buffered, unbuffered and cursor fetch).
600 */
601 int (*read_row_func)(struct st_mysql_stmt *stmt,
602 unsigned char **row);
603 /* copy of mysql->affected_rows after statement execution */
604 my_ulonglong affected_rows;
605 my_ulonglong insert_id; /* copy of mysql->insert_id */
606 unsigned long stmt_id; /* Id for prepared statement */
607 unsigned long flags; /* i.e. type of cursor to open */
608 unsigned long prefetch_rows; /* number of rows per one COM_FETCH */
609 /*
610 Copied from mysql->server_status after execute/fetch to know
611 server-side cursor status for this statement.
612 */
613 unsigned int server_status;
614 unsigned int last_errno; /* error code */
615 unsigned int param_count; /* input parameter count */
616 unsigned int field_count; /* number of columns in result set */
617 enum enum_mysql_stmt_state state; /* statement state */
618 char last_error[MYSQL_ERRMSG_SIZE]; /* error message */
619 char sqlstate[SQLSTATE_LENGTH+1];
620 /* Types of input parameters should be sent to server */
621 my_bool send_types_to_server;
622 my_bool bind_param_done; /* input buffers were supplied */
623 unsigned char bind_result_done; /* output buffers were supplied */
624 /* mysql_stmt_close() had to cancel this result */
625 my_bool unbuffered_fetch_cancelled;
626 /*
627 Is set to true if we need to calculate field->max_length for
628 metadata fields when doing mysql_stmt_store_result.
629 */
630 my_bool update_max_length;
631 struct st_mysql_stmt_extension *extension;
632} MYSQL_STMT;
633
634enum enum_stmt_attr_type
635{
636 /*
637 When doing mysql_stmt_store_result calculate max_length attribute
638 of statement metadata. This is to be consistent with the old API,
639 where this was done automatically.
640 In the new API we do that only by request because it slows down
641 mysql_stmt_store_result sufficiently.
642 */
643 STMT_ATTR_UPDATE_MAX_LENGTH,
644 /*
645 unsigned long with combination of cursor flags (read only, for update,
646 etc)
647 */
648 STMT_ATTR_CURSOR_TYPE,
649 /*
650 Amount of rows to retrieve from server per one fetch if using cursors.
651 Accepts unsigned long attribute in the range 1 - ulong_max
652 */
653 STMT_ATTR_PREFETCH_ROWS
654};
655
656
657MYSQL_STMT * STDCALL mysql_stmt_init(MYSQL *mysql);
658int STDCALL mysql_stmt_prepare(MYSQL_STMT *stmt, const char *query,
659 unsigned long length);
660int STDCALL mysql_stmt_execute(MYSQL_STMT *stmt);
661int STDCALL mysql_stmt_fetch(MYSQL_STMT *stmt);
662int STDCALL mysql_stmt_fetch_column(MYSQL_STMT *stmt, MYSQL_BIND *bind_arg,
663 unsigned int column,
664 unsigned long offset);
665int STDCALL mysql_stmt_store_result(MYSQL_STMT *stmt);
666unsigned long STDCALL mysql_stmt_param_count(MYSQL_STMT * stmt);
667my_bool STDCALL mysql_stmt_attr_set(MYSQL_STMT *stmt,
668 enum enum_stmt_attr_type attr_type,
669 const void *attr);
670my_bool STDCALL mysql_stmt_attr_get(MYSQL_STMT *stmt,
671 enum enum_stmt_attr_type attr_type,
672 void *attr);
673my_bool STDCALL mysql_stmt_bind_param(MYSQL_STMT * stmt, MYSQL_BIND * bnd);
674my_bool STDCALL mysql_stmt_bind_result(MYSQL_STMT * stmt, MYSQL_BIND * bnd);
675my_bool STDCALL mysql_stmt_close(MYSQL_STMT * stmt);
676my_bool STDCALL mysql_stmt_reset(MYSQL_STMT * stmt);
677my_bool STDCALL mysql_stmt_free_result(MYSQL_STMT *stmt);
678my_bool STDCALL mysql_stmt_send_long_data(MYSQL_STMT *stmt,
679 unsigned int param_number,
680 const char *data,
681 unsigned long length);
682MYSQL_RES *STDCALL mysql_stmt_result_metadata(MYSQL_STMT *stmt);
683MYSQL_RES *STDCALL mysql_stmt_param_metadata(MYSQL_STMT *stmt);
684unsigned int STDCALL mysql_stmt_errno(MYSQL_STMT * stmt);
685const char *STDCALL mysql_stmt_error(MYSQL_STMT * stmt);
686const char *STDCALL mysql_stmt_sqlstate(MYSQL_STMT * stmt);
687MYSQL_ROW_OFFSET STDCALL mysql_stmt_row_seek(MYSQL_STMT *stmt,
688 MYSQL_ROW_OFFSET offset);
689MYSQL_ROW_OFFSET STDCALL mysql_stmt_row_tell(MYSQL_STMT *stmt);
690void STDCALL mysql_stmt_data_seek(MYSQL_STMT *stmt, my_ulonglong offset);
691my_ulonglong STDCALL mysql_stmt_num_rows(MYSQL_STMT *stmt);
692my_ulonglong STDCALL mysql_stmt_affected_rows(MYSQL_STMT *stmt);
693my_ulonglong STDCALL mysql_stmt_insert_id(MYSQL_STMT *stmt);
694unsigned int STDCALL mysql_stmt_field_count(MYSQL_STMT *stmt);
695
696my_bool STDCALL mysql_commit(MYSQL * mysql);
697my_bool STDCALL mysql_rollback(MYSQL * mysql);
698my_bool STDCALL mysql_autocommit(MYSQL * mysql, my_bool auto_mode);
699my_bool STDCALL mysql_more_results(MYSQL *mysql);
700int STDCALL mysql_next_result(MYSQL *mysql);
701int STDCALL mysql_stmt_next_result(MYSQL_STMT *stmt);
702void STDCALL mysql_close(MYSQL *sock);
703
704
705/* status return codes */
706#define MYSQL_NO_DATA 100
707#define MYSQL_DATA_TRUNCATED 101
708
709#define mysql_reload(mysql) mysql_refresh((mysql),REFRESH_GRANT)
710
711#ifdef USE_OLD_FUNCTIONS
712MYSQL * STDCALL mysql_connect(MYSQL *mysql, const char *host,
713 const char *user, const char *passwd);
714int STDCALL mysql_create_db(MYSQL *mysql, const char *DB);
715int STDCALL mysql_drop_db(MYSQL *mysql, const char *DB);
716#endif
717#define HAVE_MYSQL_REAL_CONNECT
718
719#ifdef __cplusplus
720}
721#endif
722
723#endif /* _mysql_h */
724