Annotation of win32/sql/mysql/include/mysql.h, revision 1.2
1.2 ! misha 1: /* Copyright (C) 2000-2003 MySQL AB
1.1 parser 2:
1.2 ! misha 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 .
1.1 parser 24:
1.2 ! misha 25: */
1.1 parser 26:
27: #ifndef _mysql_h
28: #define _mysql_h
29:
1.2 ! misha 30: #ifdef __CYGWIN__ /* CYGWIN implements a UNIX API */
! 31: #undef WIN
! 32: #undef _WIN
! 33: #undef _WIN32
! 34: #undef _WIN64
! 35: #undef __WIN__
! 36: #endif
! 37:
1.1 parser 38: #ifdef __cplusplus
39: extern "C" {
40: #endif
41:
42: #ifndef _global_h /* If not standard header */
43: #include <sys/types.h>
1.2 ! misha 44: #ifdef __LCC__
! 45: #include <winsock.h> /* For windows */
! 46: #endif
1.1 parser 47: typedef char my_bool;
1.2 ! misha 48: #if (defined(_WIN32) || defined(_WIN64)) && !defined(__WIN__)
! 49: #define __WIN__
! 50: #endif
! 51: #if !defined(__WIN__)
1.1 parser 52: #define STDCALL
53: #else
54: #define STDCALL __stdcall
55: #endif
56: typedef char * gptr;
57:
58: #ifndef my_socket_defined
1.2 ! misha 59: #ifdef __WIN__
1.1 parser 60: #define my_socket SOCKET
61: #else
62: typedef int my_socket;
1.2 ! misha 63: #endif /* __WIN__ */
! 64: #endif /* my_socket_defined */
! 65: #endif /* _global_h */
! 66:
! 67: #include "mysql_version.h"
1.1 parser 68: #include "mysql_com.h"
1.2 ! misha 69: #include "mysql_time.h"
! 70: #include "typelib.h"
! 71:
! 72: #include "my_list.h" /* for LISTs used in 'MYSQL' and 'MYSQL_STMT' */
1.1 parser 73:
74: extern unsigned int mysql_port;
75: extern char *mysql_unix_port;
76:
1.2 ! misha 77: #define CLIENT_NET_READ_TIMEOUT 365*24*3600 /* Timeout on read */
! 78: #define CLIENT_NET_WRITE_TIMEOUT 365*24*3600 /* Timeout on write */
! 79:
! 80: #ifdef __NETWARE__
! 81: #pragma pack(push, 8) /* 8 byte alignment */
! 82: #endif
! 83:
1.1 parser 84: #define IS_PRI_KEY(n) ((n) & PRI_KEY_FLAG)
85: #define IS_NOT_NULL(n) ((n) & NOT_NULL_FLAG)
86: #define IS_BLOB(n) ((n) & BLOB_FLAG)
1.2 ! misha 87: #define IS_NUM(t) ((t) <= FIELD_TYPE_INT24 || (t) == FIELD_TYPE_YEAR || (t) == FIELD_TYPE_NEWDECIMAL)
! 88: #define IS_NUM_FIELD(f) ((f)->flags & NUM_FLAG)
! 89: #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)
! 90: #define IS_LONGDATA(t) ((t) >= MYSQL_TYPE_TINY_BLOB && (t) <= MYSQL_TYPE_STRING)
! 91:
1.1 parser 92:
93: typedef struct st_mysql_field {
1.2 ! misha 94: char *name; /* Name of column */
! 95: char *org_name; /* Original column name, if an alias */
! 96: char *table; /* Table of column if column was a field */
! 97: char *org_table; /* Org table name, if table was an alias */
! 98: char *db; /* Database for table */
! 99: char *catalog; /* Catalog for table */
! 100: char *def; /* Default value (set by mysql_list_fields) */
! 101: unsigned long length; /* Width of column (create length) */
! 102: unsigned long max_length; /* Max width for selected set */
! 103: unsigned int name_length;
! 104: unsigned int org_name_length;
! 105: unsigned int table_length;
! 106: unsigned int org_table_length;
! 107: unsigned int db_length;
! 108: unsigned int catalog_length;
! 109: unsigned int def_length;
! 110: unsigned int flags; /* Div flags */
! 111: unsigned int decimals; /* Number of decimals in field */
! 112: unsigned int charsetnr; /* Character set */
! 113: enum enum_field_types type; /* Type of field. See mysql_com.h for types */
1.1 parser 114: } MYSQL_FIELD;
115:
116: typedef char **MYSQL_ROW; /* return data as array of strings */
117: typedef unsigned int MYSQL_FIELD_OFFSET; /* offset to current field */
118:
1.2 ! misha 119: #ifndef _global_h
1.1 parser 120: #if defined(NO_CLIENT_LONG_LONG)
121: typedef unsigned long my_ulonglong;
1.2 ! misha 122: #elif defined (__WIN__)
1.1 parser 123: typedef unsigned __int64 my_ulonglong;
124: #else
125: typedef unsigned long long my_ulonglong;
126: #endif
1.2 ! misha 127: #endif
1.1 parser 128:
129: #define MYSQL_COUNT_ERROR (~(my_ulonglong) 0)
130:
1.2 ! misha 131: /* backward compatibility define - to be removed eventually */
! 132: #define ER_WARN_DATA_TRUNCATED WARN_DATA_TRUNCATED
! 133:
1.1 parser 134: typedef struct st_mysql_rows {
135: struct st_mysql_rows *next; /* list of rows */
136: MYSQL_ROW data;
1.2 ! misha 137: unsigned long length;
1.1 parser 138: } MYSQL_ROWS;
139:
140: typedef MYSQL_ROWS *MYSQL_ROW_OFFSET; /* offset to current row */
141:
1.2 ! misha 142: #include "my_alloc.h"
! 143:
! 144: typedef struct embedded_query_result EMBEDDED_QUERY_RESULT;
1.1 parser 145: typedef struct st_mysql_data {
146: my_ulonglong rows;
147: unsigned int fields;
148: MYSQL_ROWS *data;
149: MEM_ROOT alloc;
1.2 ! misha 150: /* extra info for embedded library */
! 151: struct embedded_query_result *embedded_info;
1.1 parser 152: } MYSQL_DATA;
153:
1.2 ! misha 154: enum mysql_option
! 155: {
! 156: MYSQL_OPT_CONNECT_TIMEOUT, MYSQL_OPT_COMPRESS, MYSQL_OPT_NAMED_PIPE,
! 157: MYSQL_INIT_COMMAND, MYSQL_READ_DEFAULT_FILE, MYSQL_READ_DEFAULT_GROUP,
! 158: MYSQL_SET_CHARSET_DIR, MYSQL_SET_CHARSET_NAME, MYSQL_OPT_LOCAL_INFILE,
! 159: MYSQL_OPT_PROTOCOL, MYSQL_SHARED_MEMORY_BASE_NAME, MYSQL_OPT_READ_TIMEOUT,
! 160: MYSQL_OPT_WRITE_TIMEOUT, MYSQL_OPT_USE_RESULT,
! 161: MYSQL_OPT_USE_REMOTE_CONNECTION, MYSQL_OPT_USE_EMBEDDED_CONNECTION,
! 162: MYSQL_OPT_GUESS_CONNECTION, MYSQL_SET_CLIENT_IP, MYSQL_SECURE_AUTH,
! 163: MYSQL_REPORT_DATA_TRUNCATION, MYSQL_OPT_RECONNECT,
! 164: MYSQL_OPT_SSL_VERIFY_SERVER_CERT
! 165: };
! 166:
1.1 parser 167: struct st_mysql_options {
1.2 ! misha 168: unsigned int connect_timeout, read_timeout, write_timeout;
! 169: unsigned int port, protocol;
! 170: unsigned long client_flag;
! 171: char *host,*user,*password,*unix_socket,*db;
! 172: struct st_dynamic_array *init_commands;
! 173: char *my_cnf_file,*my_cnf_group, *charset_dir, *charset_name;
1.1 parser 174: char *ssl_key; /* PEM key file */
175: char *ssl_cert; /* PEM cert file */
176: char *ssl_ca; /* PEM CA file */
177: char *ssl_capath; /* PEM directory of CA-s? */
1.2 ! misha 178: char *ssl_cipher; /* cipher to use */
! 179: char *shared_memory_base_name;
! 180: unsigned long max_allowed_packet;
! 181: my_bool use_ssl; /* if to use SSL or not */
! 182: my_bool compress,named_pipe;
! 183: /*
! 184: On connect, find out the replication role of the server, and
! 185: establish connections to all the peers
! 186: */
! 187: my_bool rpl_probe;
! 188: /*
! 189: Each call to mysql_real_query() will parse it to tell if it is a read
! 190: or a write, and direct it to the slave or the master
! 191: */
! 192: my_bool rpl_parse;
! 193: /*
! 194: If set, never read from a master, only from slave, when doing
! 195: a read that is replication-aware
! 196: */
! 197: my_bool no_master_reads;
! 198: #if !defined(CHECK_EMBEDDED_DIFFERENCES) || defined(EMBEDDED_LIBRARY)
! 199: my_bool separate_thread;
! 200: #endif
! 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;
1.1 parser 214: };
215:
1.2 ! misha 216: enum mysql_status
! 217: {
! 218: MYSQL_STATUS_READY,MYSQL_STATUS_GET_RESULT,MYSQL_STATUS_USE_RESULT
! 219: };
1.1 parser 220:
1.2 ! misha 221: enum mysql_protocol_type
! 222: {
! 223: MYSQL_PROTOCOL_DEFAULT, MYSQL_PROTOCOL_TCP, MYSQL_PROTOCOL_SOCKET,
! 224: MYSQL_PROTOCOL_PIPE, MYSQL_PROTOCOL_MEMORY
! 225: };
! 226: /*
! 227: There are three types of queries - the ones that have to go to
! 228: the master, the ones that go to a slave, and the adminstrative
! 229: type which must happen on the pivot connectioin
! 230: */
! 231: enum mysql_rpl_type
! 232: {
! 233: MYSQL_RPL_MASTER, MYSQL_RPL_SLAVE, MYSQL_RPL_ADMIN
! 234: };
! 235:
! 236: typedef struct character_set
! 237: {
! 238: unsigned int number; /* character set number */
! 239: unsigned int state; /* character set state */
! 240: const char *csname; /* collation name */
! 241: const char *name; /* character set name */
! 242: const char *comment; /* comment */
! 243: const char *dir; /* character set directory */
! 244: unsigned int mbminlen; /* min. length for multibyte strings */
! 245: unsigned int mbmaxlen; /* max. length for multibyte strings */
! 246: } MY_CHARSET_INFO;
1.1 parser 247:
1.2 ! misha 248: struct st_mysql_methods;
! 249: struct st_mysql_stmt;
! 250:
! 251: typedef struct st_mysql
! 252: {
1.1 parser 253: NET net; /* Communication parameters */
254: gptr connector_fd; /* ConnectorFd for SSL */
1.2 ! misha 255: char *host,*user,*passwd,*unix_socket,*server_version,*host_info,*info;
! 256: char *db;
! 257: struct charset_info_st *charset;
! 258: MYSQL_FIELD *fields;
! 259: MEM_ROOT field_alloc;
1.1 parser 260: my_ulonglong affected_rows;
261: my_ulonglong insert_id; /* id if insert on table with NEXTNR */
1.2 ! misha 262: my_ulonglong extra_info; /* Not used */
! 263: unsigned long thread_id; /* Id for connection in server */
1.1 parser 264: unsigned long packet_length;
1.2 ! misha 265: unsigned int port;
! 266: unsigned long client_flag,server_capabilities;
! 267: unsigned int protocol_version;
! 268: unsigned int field_count;
! 269: unsigned int server_status;
! 270: unsigned int server_language;
! 271: unsigned int warning_count;
! 272: struct st_mysql_options options;
1.1 parser 273: enum mysql_status status;
274: my_bool free_me; /* If free in mysql_close */
275: my_bool reconnect; /* set to 1 if automatic reconnect */
1.2 ! misha 276:
! 277: /* session-wide random string */
! 278: char scramble[SCRAMBLE_LENGTH+1];
! 279:
! 280: /*
! 281: Set if this is the original connection, not a master or a slave we have
! 282: added though mysql_rpl_probe() or mysql_set_master()/ mysql_add_slave()
! 283: */
! 284: my_bool rpl_pivot;
! 285: /*
! 286: Pointers to the master, and the next slave connections, points to
! 287: itself if lone connection.
! 288: */
! 289: struct st_mysql* master, *next_slave;
! 290:
! 291: struct st_mysql* last_used_slave; /* needed for round-robin slave pick */
! 292: /* needed for send/read/store/use result to work correctly with replication */
! 293: struct st_mysql* last_used_con;
! 294:
! 295: LIST *stmts; /* list of all statements */
! 296: const struct st_mysql_methods *methods;
! 297: void *thd;
! 298: /*
! 299: Points to boolean flag in MYSQL_RES or MYSQL_STMT. We set this flag
! 300: from mysql_stmt_close if close had to cancel result set of this object.
! 301: */
! 302: my_bool *unbuffered_fetch_owner;
! 303: #if defined(EMBEDDED_LIBRARY) || defined(EMBEDDED_LIBRARY_COMPATIBLE) || MYSQL_VERSION_ID >= 50100
! 304: /* needed for embedded server - no net buffer to store the 'info' */
! 305: char *info_buffer;
! 306: #endif
1.1 parser 307: } MYSQL;
308:
309: typedef struct st_mysql_res {
310: my_ulonglong row_count;
311: MYSQL_FIELD *fields;
312: MYSQL_DATA *data;
313: MYSQL_ROWS *data_cursor;
1.2 ! misha 314: unsigned long *lengths; /* column lengths of current row */
! 315: MYSQL *handle; /* for unbuffered reads */
1.1 parser 316: MEM_ROOT field_alloc;
1.2 ! misha 317: unsigned int field_count, current_field;
1.1 parser 318: MYSQL_ROW row; /* If unbuffered read */
319: MYSQL_ROW current_row; /* buffer to current row */
1.2 ! misha 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: const struct st_mysql_methods *methods;
1.1 parser 324: } MYSQL_RES;
325:
1.2 ! misha 326: #define MAX_MYSQL_MANAGER_ERR 256
! 327: #define MAX_MYSQL_MANAGER_MSG 256
! 328:
! 329: #define MANAGER_OK 200
! 330: #define MANAGER_INFO 250
! 331: #define MANAGER_ACCESS 401
! 332: #define MANAGER_CLIENT_ERR 450
! 333: #define MANAGER_INTERNAL_ERR 500
! 334:
! 335: #if !defined(MYSQL_SERVER) && !defined(MYSQL_CLIENT)
! 336: #define MYSQL_CLIENT
! 337: #endif
! 338:
! 339:
! 340: typedef struct st_mysql_manager
! 341: {
! 342: NET net;
! 343: char *host,*user,*passwd;
! 344: unsigned int port;
! 345: my_bool free_me;
! 346: my_bool eof;
! 347: int cmd_status;
! 348: int last_errno;
! 349: char* net_buf,*net_buf_pos,*net_data_end;
! 350: int net_buf_size;
! 351: char last_error[MAX_MYSQL_MANAGER_ERR];
! 352: } MYSQL_MANAGER;
! 353:
! 354: typedef struct st_mysql_parameters
! 355: {
! 356: unsigned long *p_max_allowed_packet;
! 357: unsigned long *p_net_buffer_length;
! 358: } MYSQL_PARAMETERS;
! 359:
! 360: #if !defined(MYSQL_SERVER) && !defined(EMBEDDED_LIBRARY)
! 361: #define max_allowed_packet (*mysql_get_parameters()->p_max_allowed_packet)
! 362: #define net_buffer_length (*mysql_get_parameters()->p_net_buffer_length)
! 363: #endif
! 364:
! 365: /*
! 366: Set up and bring down the server; to ensure that applications will
! 367: work when linked against either the standard client library or the
! 368: embedded server library, these functions should be called.
! 369: */
! 370: int STDCALL mysql_server_init(int argc, char **argv, char **groups);
! 371: void STDCALL mysql_server_end(void);
! 372: /*
! 373: mysql_server_init/end need to be called when using libmysqld or
! 374: libmysqlclient (exactly, mysql_server_init() is called by mysql_init() so
! 375: you don't need to call it explicitely; but you need to call
! 376: mysql_server_end() to free memory). The names are a bit misleading
! 377: (mysql_SERVER* to be used when using libmysqlCLIENT). So we add more general
! 378: names which suit well whether you're using libmysqld or libmysqlclient. We
! 379: intend to promote these aliases over the mysql_server* ones.
! 380: */
! 381: #define mysql_library_init mysql_server_init
! 382: #define mysql_library_end mysql_server_end
! 383:
! 384: MYSQL_PARAMETERS *STDCALL mysql_get_parameters(void);
! 385:
! 386: /*
! 387: Set up and bring down a thread; these function should be called
! 388: for each thread in an application which opens at least one MySQL
! 389: connection. All uses of the connection(s) should be between these
! 390: function calls.
! 391: */
! 392: my_bool STDCALL mysql_thread_init(void);
! 393: void STDCALL mysql_thread_end(void);
! 394:
! 395: /*
! 396: Functions to get information from the MYSQL and MYSQL_RES structures
! 397: Should definitely be used if one uses shared libraries.
! 398: */
1.1 parser 399:
400: my_ulonglong STDCALL mysql_num_rows(MYSQL_RES *res);
401: unsigned int STDCALL mysql_num_fields(MYSQL_RES *res);
402: my_bool STDCALL mysql_eof(MYSQL_RES *res);
403: MYSQL_FIELD *STDCALL mysql_fetch_field_direct(MYSQL_RES *res,
404: unsigned int fieldnr);
405: MYSQL_FIELD * STDCALL mysql_fetch_fields(MYSQL_RES *res);
1.2 ! misha 406: MYSQL_ROW_OFFSET STDCALL mysql_row_tell(MYSQL_RES *res);
! 407: MYSQL_FIELD_OFFSET STDCALL mysql_field_tell(MYSQL_RES *res);
1.1 parser 408:
409: unsigned int STDCALL mysql_field_count(MYSQL *mysql);
410: my_ulonglong STDCALL mysql_affected_rows(MYSQL *mysql);
411: my_ulonglong STDCALL mysql_insert_id(MYSQL *mysql);
412: unsigned int STDCALL mysql_errno(MYSQL *mysql);
1.2 ! misha 413: const char * STDCALL mysql_error(MYSQL *mysql);
! 414: const char *STDCALL mysql_sqlstate(MYSQL *mysql);
! 415: unsigned int STDCALL mysql_warning_count(MYSQL *mysql);
! 416: const char * STDCALL mysql_info(MYSQL *mysql);
1.1 parser 417: unsigned long STDCALL mysql_thread_id(MYSQL *mysql);
1.2 ! misha 418: const char * STDCALL mysql_character_set_name(MYSQL *mysql);
! 419: int STDCALL mysql_set_character_set(MYSQL *mysql, const char *csname);
1.1 parser 420:
421: MYSQL * STDCALL mysql_init(MYSQL *mysql);
1.2 ! misha 422: my_bool STDCALL mysql_ssl_set(MYSQL *mysql, const char *key,
1.1 parser 423: const char *cert, const char *ca,
1.2 ! misha 424: const char *capath, const char *cipher);
! 425: const char * STDCALL mysql_get_ssl_cipher(MYSQL *mysql);
1.1 parser 426: my_bool STDCALL mysql_change_user(MYSQL *mysql, const char *user,
427: const char *passwd, const char *db);
428: MYSQL * STDCALL mysql_real_connect(MYSQL *mysql, const char *host,
429: const char *user,
430: const char *passwd,
431: const char *db,
432: unsigned int port,
433: const char *unix_socket,
1.2 ! misha 434: unsigned long clientflag);
1.1 parser 435: int STDCALL mysql_select_db(MYSQL *mysql, const char *db);
436: int STDCALL mysql_query(MYSQL *mysql, const char *q);
1.2 ! misha 437: int STDCALL mysql_send_query(MYSQL *mysql, const char *q,
! 438: unsigned long length);
1.1 parser 439: int STDCALL mysql_real_query(MYSQL *mysql, const char *q,
1.2 ! misha 440: unsigned long length);
! 441: MYSQL_RES * STDCALL mysql_store_result(MYSQL *mysql);
! 442: MYSQL_RES * STDCALL mysql_use_result(MYSQL *mysql);
! 443:
! 444: /* perform query on master */
! 445: my_bool STDCALL mysql_master_query(MYSQL *mysql, const char *q,
! 446: unsigned long length);
! 447: my_bool STDCALL mysql_master_send_query(MYSQL *mysql, const char *q,
! 448: unsigned long length);
! 449: /* perform query on slave */
! 450: my_bool STDCALL mysql_slave_query(MYSQL *mysql, const char *q,
! 451: unsigned long length);
! 452: my_bool STDCALL mysql_slave_send_query(MYSQL *mysql, const char *q,
! 453: unsigned long length);
! 454: void STDCALL mysql_get_character_set_info(MYSQL *mysql,
! 455: MY_CHARSET_INFO *charset);
! 456:
! 457: /* local infile support */
! 458:
! 459: #define LOCAL_INFILE_ERROR_LEN 512
! 460:
! 461: void
! 462: mysql_set_local_infile_handler(MYSQL *mysql,
! 463: int (*local_infile_init)(void **, const char *,
! 464: void *),
! 465: int (*local_infile_read)(void *, char *,
! 466: unsigned int),
! 467: void (*local_infile_end)(void *),
! 468: int (*local_infile_error)(void *, char*,
! 469: unsigned int),
! 470: void *);
! 471:
! 472: void
! 473: mysql_set_local_infile_default(MYSQL *mysql);
! 474:
! 475:
! 476: /*
! 477: enable/disable parsing of all queries to decide if they go on master or
! 478: slave
! 479: */
! 480: void STDCALL mysql_enable_rpl_parse(MYSQL* mysql);
! 481: void STDCALL mysql_disable_rpl_parse(MYSQL* mysql);
! 482: /* get the value of the parse flag */
! 483: int STDCALL mysql_rpl_parse_enabled(MYSQL* mysql);
! 484:
! 485: /* enable/disable reads from master */
! 486: void STDCALL mysql_enable_reads_from_master(MYSQL* mysql);
! 487: void STDCALL mysql_disable_reads_from_master(MYSQL* mysql);
! 488: /* get the value of the master read flag */
! 489: my_bool STDCALL mysql_reads_from_master_enabled(MYSQL* mysql);
! 490:
! 491: enum mysql_rpl_type STDCALL mysql_rpl_query_type(const char* q, int len);
! 492:
! 493: /* discover the master and its slaves */
! 494: my_bool STDCALL mysql_rpl_probe(MYSQL* mysql);
! 495:
! 496: /* set the master, close/free the old one, if it is not a pivot */
! 497: int STDCALL mysql_set_master(MYSQL* mysql, const char* host,
! 498: unsigned int port,
! 499: const char* user,
! 500: const char* passwd);
! 501: int STDCALL mysql_add_slave(MYSQL* mysql, const char* host,
! 502: unsigned int port,
! 503: const char* user,
! 504: const char* passwd);
! 505:
! 506: int STDCALL mysql_shutdown(MYSQL *mysql,
! 507: enum mysql_enum_shutdown_level
! 508: shutdown_level);
1.1 parser 509: int STDCALL mysql_dump_debug_info(MYSQL *mysql);
510: int STDCALL mysql_refresh(MYSQL *mysql,
511: unsigned int refresh_options);
512: int STDCALL mysql_kill(MYSQL *mysql,unsigned long pid);
1.2 ! misha 513: int STDCALL mysql_set_server_option(MYSQL *mysql,
! 514: enum enum_mysql_set_option
! 515: option);
1.1 parser 516: int STDCALL mysql_ping(MYSQL *mysql);
1.2 ! misha 517: const char * STDCALL mysql_stat(MYSQL *mysql);
! 518: const char * STDCALL mysql_get_server_info(MYSQL *mysql);
! 519: const char * STDCALL mysql_get_client_info(void);
! 520: unsigned long STDCALL mysql_get_client_version(void);
! 521: const char * STDCALL mysql_get_host_info(MYSQL *mysql);
! 522: unsigned long STDCALL mysql_get_server_version(MYSQL *mysql);
1.1 parser 523: unsigned int STDCALL mysql_get_proto_info(MYSQL *mysql);
524: MYSQL_RES * STDCALL mysql_list_dbs(MYSQL *mysql,const char *wild);
525: MYSQL_RES * STDCALL mysql_list_tables(MYSQL *mysql,const char *wild);
526: MYSQL_RES * STDCALL mysql_list_processes(MYSQL *mysql);
527: int STDCALL mysql_options(MYSQL *mysql,enum mysql_option option,
528: const char *arg);
529: void STDCALL mysql_free_result(MYSQL_RES *result);
530: void STDCALL mysql_data_seek(MYSQL_RES *result,
531: my_ulonglong offset);
1.2 ! misha 532: MYSQL_ROW_OFFSET STDCALL mysql_row_seek(MYSQL_RES *result,
! 533: MYSQL_ROW_OFFSET offset);
1.1 parser 534: MYSQL_FIELD_OFFSET STDCALL mysql_field_seek(MYSQL_RES *result,
535: MYSQL_FIELD_OFFSET offset);
536: MYSQL_ROW STDCALL mysql_fetch_row(MYSQL_RES *result);
537: unsigned long * STDCALL mysql_fetch_lengths(MYSQL_RES *result);
538: MYSQL_FIELD * STDCALL mysql_fetch_field(MYSQL_RES *result);
1.2 ! misha 539: MYSQL_RES * STDCALL mysql_list_fields(MYSQL *mysql, const char *table,
! 540: const char *wild);
1.1 parser 541: unsigned long STDCALL mysql_escape_string(char *to,const char *from,
542: unsigned long from_length);
1.2 ! misha 543: unsigned long STDCALL mysql_hex_string(char *to,const char *from,
! 544: unsigned long from_length);
! 545: unsigned long STDCALL mysql_real_escape_string(MYSQL *mysql,
! 546: char *to,const char *from,
! 547: unsigned long length);
1.1 parser 548: void STDCALL mysql_debug(const char *debug);
1.2 ! misha 549: char * STDCALL mysql_odbc_escape_string(MYSQL *mysql,
! 550: char *to,
1.1 parser 551: unsigned long to_length,
552: const char *from,
553: unsigned long from_length,
554: void *param,
555: char *
556: (*extend_buffer)
557: (void *, char *to,
558: unsigned long *length));
1.2 ! misha 559: void STDCALL myodbc_remove_escape(MYSQL *mysql,char *name);
! 560: unsigned int STDCALL mysql_thread_safe(void);
! 561: my_bool STDCALL mysql_embedded(void);
! 562: MYSQL_MANAGER* STDCALL mysql_manager_init(MYSQL_MANAGER* con);
! 563: MYSQL_MANAGER* STDCALL mysql_manager_connect(MYSQL_MANAGER* con,
! 564: const char* host,
! 565: const char* user,
! 566: const char* passwd,
! 567: unsigned int port);
! 568: void STDCALL mysql_manager_close(MYSQL_MANAGER* con);
! 569: int STDCALL mysql_manager_command(MYSQL_MANAGER* con,
! 570: const char* cmd, int cmd_len);
! 571: int STDCALL mysql_manager_fetch_line(MYSQL_MANAGER* con,
! 572: char* res_buf,
! 573: int res_buf_size);
! 574: my_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 */
! 583: enum 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:
! 653: typedef 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 */
! 681: typedef 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:
! 727: enum 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:
! 750: typedef 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:
! 782: MYSQL_STMT * STDCALL mysql_stmt_init(MYSQL *mysql);
! 783: int STDCALL mysql_stmt_prepare(MYSQL_STMT *stmt, const char *query,
! 784: unsigned long length);
! 785: int STDCALL mysql_stmt_execute(MYSQL_STMT *stmt);
! 786: int STDCALL mysql_stmt_fetch(MYSQL_STMT *stmt);
! 787: int STDCALL mysql_stmt_fetch_column(MYSQL_STMT *stmt, MYSQL_BIND *bind_arg,
! 788: unsigned int column,
! 789: unsigned long offset);
! 790: int STDCALL mysql_stmt_store_result(MYSQL_STMT *stmt);
! 791: unsigned long STDCALL mysql_stmt_param_count(MYSQL_STMT * stmt);
! 792: my_bool STDCALL mysql_stmt_attr_set(MYSQL_STMT *stmt,
! 793: enum enum_stmt_attr_type attr_type,
! 794: const void *attr);
! 795: my_bool STDCALL mysql_stmt_attr_get(MYSQL_STMT *stmt,
! 796: enum enum_stmt_attr_type attr_type,
! 797: void *attr);
! 798: my_bool STDCALL mysql_stmt_bind_param(MYSQL_STMT * stmt, MYSQL_BIND * bnd);
! 799: my_bool STDCALL mysql_stmt_bind_result(MYSQL_STMT * stmt, MYSQL_BIND * bnd);
! 800: my_bool STDCALL mysql_stmt_close(MYSQL_STMT * stmt);
! 801: my_bool STDCALL mysql_stmt_reset(MYSQL_STMT * stmt);
! 802: my_bool STDCALL mysql_stmt_free_result(MYSQL_STMT *stmt);
! 803: my_bool STDCALL mysql_stmt_send_long_data(MYSQL_STMT *stmt,
! 804: unsigned int param_number,
! 805: const char *data,
! 806: unsigned long length);
! 807: MYSQL_RES *STDCALL mysql_stmt_result_metadata(MYSQL_STMT *stmt);
! 808: MYSQL_RES *STDCALL mysql_stmt_param_metadata(MYSQL_STMT *stmt);
! 809: unsigned int STDCALL mysql_stmt_errno(MYSQL_STMT * stmt);
! 810: const char *STDCALL mysql_stmt_error(MYSQL_STMT * stmt);
! 811: const char *STDCALL mysql_stmt_sqlstate(MYSQL_STMT * stmt);
! 812: MYSQL_ROW_OFFSET STDCALL mysql_stmt_row_seek(MYSQL_STMT *stmt,
! 813: MYSQL_ROW_OFFSET offset);
! 814: MYSQL_ROW_OFFSET STDCALL mysql_stmt_row_tell(MYSQL_STMT *stmt);
! 815: void STDCALL mysql_stmt_data_seek(MYSQL_STMT *stmt, my_ulonglong offset);
! 816: my_ulonglong STDCALL mysql_stmt_num_rows(MYSQL_STMT *stmt);
! 817: my_ulonglong STDCALL mysql_stmt_affected_rows(MYSQL_STMT *stmt);
! 818: my_ulonglong STDCALL mysql_stmt_insert_id(MYSQL_STMT *stmt);
! 819: unsigned int STDCALL mysql_stmt_field_count(MYSQL_STMT *stmt);
! 820:
! 821: my_bool STDCALL mysql_commit(MYSQL * mysql);
! 822: my_bool STDCALL mysql_rollback(MYSQL * mysql);
! 823: my_bool STDCALL mysql_autocommit(MYSQL * mysql, my_bool auto_mode);
! 824: my_bool STDCALL mysql_more_results(MYSQL *mysql);
! 825: int STDCALL mysql_next_result(MYSQL *mysql);
! 826: void STDCALL mysql_close(MYSQL *sock);
! 827:
! 828:
! 829: /* status return codes */
! 830: #define MYSQL_NO_DATA 100
! 831: #define MYSQL_DATA_TRUNCATED 101
1.1 parser 832:
833: #define mysql_reload(mysql) mysql_refresh((mysql),REFRESH_GRANT)
834:
1.2 ! misha 835: #ifdef USE_OLD_FUNCTIONS
! 836: MYSQL * STDCALL mysql_connect(MYSQL *mysql, const char *host,
! 837: const char *user, const char *passwd);
! 838: int STDCALL mysql_create_db(MYSQL *mysql, const char *DB);
! 839: int 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
1.1 parser 843:
1.2 ! misha 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: #pragma pack(pop) /* restore alignment */
! 858: #endif
1.1 parser 859:
860: #ifdef __cplusplus
861: }
862: #endif
1.2 ! misha 863:
! 864: #endif /* _mysql_h */
E-mail: