1 /* 2 Copyright (c) 2000, 2012, Oracle and/or its affiliates. 3 Copyright (c) 2012, Monty Program Ab. 4 5 This program is free software; you can redistribute it and/or modify 6 it under the terms of the GNU General Public License as published by 7 the Free Software Foundation; version 2 of the License. 8 9 This program is distributed in the hope that it will be useful, 10 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 GNU General Public License for more details. 13 14 You should have received a copy of the GNU General Public License 15 along with this program; if not, write to the Free Software 16 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1335 USA */ 17 18 /* 19 This file defines the client API to MySQL and also the ABI of the 20 dynamically linked libmysqlclient. 21 22 The ABI should never be changed in a released product of MySQL, 23 thus you need to take great care when changing the file. In case 24 the file is changed so the ABI is broken, you must also update 25 the SHARED_LIB_MAJOR_VERSION in cmake/mysql_version.cmake 26 */ 27 28 #ifndef _mysql_h 29 #define _mysql_h 30 31 #ifdef _AIX /* large-file support will break without this */ 32 #include <standards.h> 33 #endif 34 35 #ifdef __CYGWIN__ /* CYGWIN implements a UNIX API */ 36 #undef WIN 37 #undef _WIN 38 #undef _WIN32 39 #undef _WIN64 40 #undef __WIN__ 41 #endif 42 43 #ifdef __cplusplus 44 extern "C" { 45 #endif 46 47 #ifndef MY_GLOBAL_INCLUDED /* If not standard header */ 48 #ifndef MYSQL_ABI_CHECK 49 #include <sys/types.h> 50 #endif 51 52 #ifndef MYSQL_PLUGIN_INCLUDED 53 typedef char my_bool; 54 #endif 55 56 #if (defined(_WIN32) || defined(_WIN64)) && !defined(__WIN__) 57 #define __WIN__ 58 #endif 59 #if !defined(__WIN__) 60 #define STDCALL 61 #else 62 #define STDCALL __stdcall 63 #endif 64 65 #ifndef my_socket_defined 66 #if defined (_WIN64) 67 #define my_socket unsigned long long 68 #elif defined (_WIN32) 69 #define my_socket unsigned int 70 #else 71 typedef int my_socket; 72 #endif /* _WIN64 */ 73 #endif /* my_socket_defined */ 74 #endif /* MY_GLOBAL_INCLUDED */ 75 76 #include "mysql_version.h" 77 #include "mysql_com.h" 78 #include "mysql_time.h" 79 80 #include "my_list.h" /* for LISTs used in 'MYSQL' and 'MYSQL_STMT' */ 81 82 extern unsigned int mariadb_deinitialize_ssl; 83 extern unsigned int mysql_port; 84 extern char *mysql_unix_port; 85 86 #define CLIENT_NET_READ_TIMEOUT (365*24*3600) /* Timeout on read */ 87 #define CLIENT_NET_WRITE_TIMEOUT (365*24*3600) /* Timeout on write */ 88 89 #define IS_PRI_KEY(n) ((n) & PRI_KEY_FLAG) 90 #define IS_NOT_NULL(n) ((n) & NOT_NULL_FLAG) 91 #define IS_BLOB(n) ((n) & BLOB_FLAG) 92 /** 93 Returns true if the value is a number which does not need quotes for 94 the sql_lex.cc parser to parse correctly. 95 */ 96 #define IS_NUM(t) (((t) <= MYSQL_TYPE_INT24 && (t) != MYSQL_TYPE_TIMESTAMP) || (t) == MYSQL_TYPE_YEAR || (t) == MYSQL_TYPE_NEWDECIMAL) 97 #define IS_LONGDATA(t) ((t) >= MYSQL_TYPE_TINY_BLOB && (t) <= MYSQL_TYPE_STRING) 98 99 100 typedef struct st_mysql_const_lex_string MARIADB_CONST_STRING; 101 102 103 typedef struct st_mysql_field { 104 char *name; /* Name of column */ 105 char *org_name; /* Original column name, if an alias */ 106 char *table; /* Table of column if column was a field */ 107 char *org_table; /* Org table name, if table was an alias */ 108 char *db; /* Database for table */ 109 char *catalog; /* Catalog for table */ 110 char *def; /* Default value (set by mysql_list_fields) */ 111 unsigned long length; /* Width of column (create length) */ 112 unsigned long max_length; /* Max width for selected set */ 113 unsigned int name_length; 114 unsigned int org_name_length; 115 unsigned int table_length; 116 unsigned int org_table_length; 117 unsigned int db_length; 118 unsigned int catalog_length; 119 unsigned int def_length; 120 unsigned int flags; /* Div flags */ 121 unsigned int decimals; /* Number of decimals in field */ 122 unsigned int charsetnr; /* Character set */ 123 enum enum_field_types type; /* Type of field. See mysql_com.h for types */ 124 void *extension; 125 } MYSQL_FIELD; 126 127 typedef char **MYSQL_ROW; /* return data as array of strings */ 128 typedef unsigned int MYSQL_FIELD_OFFSET; /* offset to current field */ 129 130 #ifndef MY_GLOBAL_INCLUDED 131 #if defined(NO_CLIENT_LONG_LONG) 132 typedef unsigned long my_ulonglong; 133 #elif defined (__WIN__) 134 typedef unsigned __int64 my_ulonglong; 135 #else 136 typedef unsigned long long my_ulonglong; 137 #endif 138 #endif 139 140 #include "typelib.h" 141 142 #define MYSQL_COUNT_ERROR (~(my_ulonglong) 0) 143 144 /* backward compatibility define - to be removed eventually */ 145 #define ER_WARN_DATA_TRUNCATED WARN_DATA_TRUNCATED 146 #define WARN_PLUGIN_DELETE_BUILTIN ER_PLUGIN_DELETE_BUILTIN 147 #define ER_FK_DUP_NAME ER_DUP_CONSTRAINT_NAME 148 #define ER_VIRTUAL_COLUMN_FUNCTION_IS_NOT_ALLOWED ER_GENERATED_COLUMN_FUNCTION_IS_NOT_ALLOWED 149 #define ER_PRIMARY_KEY_BASED_ON_VIRTUAL_COLUMN ER_PRIMARY_KEY_BASED_ON_GENERATED_COLUMN 150 #define ER_WRONG_FK_OPTION_FOR_VIRTUAL_COLUMN ER_WRONG_FK_OPTION_FOR_GENERATED_COLUMN 151 #define ER_UNSUPPORTED_ACTION_ON_VIRTUAL_COLUMN ER_UNSUPPORTED_ACTION_ON_GENERATED_COLUMN 152 #define ER_UNSUPPORTED_ENGINE_FOR_VIRTUAL_COLUMNS ER_UNSUPPORTED_ENGINE_FOR_GENERATED_COLUMNS 153 154 typedef struct st_mysql_rows { 155 struct st_mysql_rows *next; /* list of rows */ 156 MYSQL_ROW data; 157 unsigned long length; 158 } MYSQL_ROWS; 159 160 typedef MYSQL_ROWS *MYSQL_ROW_OFFSET; /* offset to current row */ 161 162 #include "my_alloc.h" 163 164 typedef struct embedded_query_result EMBEDDED_QUERY_RESULT; 165 typedef struct st_mysql_data { 166 MYSQL_ROWS *data; 167 struct embedded_query_result *embedded_info; 168 MEM_ROOT alloc; 169 my_ulonglong rows; 170 unsigned int fields; 171 /* extra info for embedded library */ 172 void *extension; 173 } MYSQL_DATA; 174 175 enum mysql_option 176 { 177 MYSQL_OPT_CONNECT_TIMEOUT, MYSQL_OPT_COMPRESS, MYSQL_OPT_NAMED_PIPE, 178 MYSQL_INIT_COMMAND, MYSQL_READ_DEFAULT_FILE, MYSQL_READ_DEFAULT_GROUP, 179 MYSQL_SET_CHARSET_DIR, MYSQL_SET_CHARSET_NAME, MYSQL_OPT_LOCAL_INFILE, 180 MYSQL_OPT_PROTOCOL, MYSQL_SHARED_MEMORY_BASE_NAME, MYSQL_OPT_READ_TIMEOUT, 181 MYSQL_OPT_WRITE_TIMEOUT, MYSQL_OPT_USE_RESULT, 182 MYSQL_OPT_USE_REMOTE_CONNECTION, MYSQL_OPT_USE_EMBEDDED_CONNECTION, 183 MYSQL_OPT_GUESS_CONNECTION, MYSQL_SET_CLIENT_IP, MYSQL_SECURE_AUTH, 184 MYSQL_REPORT_DATA_TRUNCATION, MYSQL_OPT_RECONNECT, 185 MYSQL_OPT_SSL_VERIFY_SERVER_CERT, MYSQL_PLUGIN_DIR, MYSQL_DEFAULT_AUTH, 186 MYSQL_OPT_BIND, 187 MYSQL_OPT_SSL_KEY, MYSQL_OPT_SSL_CERT, 188 MYSQL_OPT_SSL_CA, MYSQL_OPT_SSL_CAPATH, MYSQL_OPT_SSL_CIPHER, 189 MYSQL_OPT_SSL_CRL, MYSQL_OPT_SSL_CRLPATH, 190 MYSQL_OPT_CONNECT_ATTR_RESET, MYSQL_OPT_CONNECT_ATTR_ADD, 191 MYSQL_OPT_CONNECT_ATTR_DELETE, 192 MYSQL_SERVER_PUBLIC_KEY, 193 MYSQL_ENABLE_CLEARTEXT_PLUGIN, 194 MYSQL_OPT_CAN_HANDLE_EXPIRED_PASSWORDS, 195 196 /* MariaDB options */ 197 MYSQL_PROGRESS_CALLBACK=5999, 198 MYSQL_OPT_NONBLOCK, 199 MYSQL_OPT_USE_THREAD_SPECIFIC_MEMORY 200 }; 201 202 /** 203 @todo remove the "extension", move st_mysql_options completely 204 out of mysql.h 205 */ 206 struct st_mysql_options_extention; 207 208 struct st_mysql_options { 209 unsigned int connect_timeout, read_timeout, write_timeout; 210 unsigned int port, protocol; 211 unsigned long client_flag; 212 char *host,*user,*password,*unix_socket,*db; 213 struct st_dynamic_array *init_commands; 214 char *my_cnf_file,*my_cnf_group, *charset_dir, *charset_name; 215 char *ssl_key; /* PEM key file */ 216 char *ssl_cert; /* PEM cert file */ 217 char *ssl_ca; /* PEM CA file */ 218 char *ssl_capath; /* PEM directory of CA-s? */ 219 char *ssl_cipher; /* cipher to use */ 220 char *shared_memory_base_name; 221 unsigned long max_allowed_packet; 222 my_bool use_ssl; /* if to use SSL or not */ 223 my_bool compress,named_pipe; 224 my_bool use_thread_specific_memory; 225 my_bool unused2; 226 my_bool unused3; 227 my_bool unused4; 228 enum mysql_option methods_to_use; 229 char *client_ip; 230 /* Refuse client connecting to server if it uses old (pre-4.1.1) protocol */ 231 my_bool secure_auth; 232 /* 0 - never report, 1 - always report (default) */ 233 my_bool report_data_truncation; 234 235 /* function pointers for local infile support */ 236 int (*local_infile_init)(void **, const char *, void *); 237 int (*local_infile_read)(void *, char *, unsigned int); 238 void (*local_infile_end)(void *); 239 int (*local_infile_error)(void *, char *, unsigned int); 240 void *local_infile_userdata; 241 struct st_mysql_options_extention *extension; 242 }; 243 244 enum mysql_status 245 { 246 MYSQL_STATUS_READY, MYSQL_STATUS_GET_RESULT, MYSQL_STATUS_USE_RESULT, 247 MYSQL_STATUS_STATEMENT_GET_RESULT 248 }; 249 250 enum mysql_protocol_type 251 { 252 MYSQL_PROTOCOL_DEFAULT, MYSQL_PROTOCOL_TCP, MYSQL_PROTOCOL_SOCKET, 253 MYSQL_PROTOCOL_PIPE, MYSQL_PROTOCOL_MEMORY 254 }; 255 256 typedef struct character_set 257 { 258 unsigned int number; /* character set number */ 259 unsigned int state; /* character set state */ 260 const char *csname; /* collation name */ 261 const char *name; /* character set name */ 262 const char *comment; /* comment */ 263 const char *dir; /* character set directory */ 264 unsigned int mbminlen; /* min. length for multibyte strings */ 265 unsigned int mbmaxlen; /* max. length for multibyte strings */ 266 } MY_CHARSET_INFO; 267 268 struct st_mysql_methods; 269 struct st_mysql_stmt; 270 271 typedef struct st_mysql 272 { 273 NET net; /* Communication parameters */ 274 unsigned char *connector_fd; /* ConnectorFd for SSL */ 275 char *host,*user,*passwd,*unix_socket,*server_version,*host_info; 276 char *info, *db; 277 const struct charset_info_st *charset; 278 MYSQL_FIELD *fields; 279 MEM_ROOT field_alloc; 280 my_ulonglong affected_rows; 281 my_ulonglong insert_id; /* id if insert on table with NEXTNR */ 282 my_ulonglong extra_info; /* Not used */ 283 unsigned long thread_id; /* Id for connection in server */ 284 unsigned long packet_length; 285 unsigned int port; 286 unsigned long client_flag,server_capabilities; 287 unsigned int protocol_version; 288 unsigned int field_count; 289 unsigned int server_status; 290 unsigned int server_language; 291 unsigned int warning_count; 292 struct st_mysql_options options; 293 enum mysql_status status; 294 my_bool free_me; /* If free in mysql_close */ 295 my_bool reconnect; /* set to 1 if automatic reconnect */ 296 297 /* session-wide random string */ 298 char scramble[SCRAMBLE_LENGTH+1]; 299 my_bool auto_local_infile; 300 void *unused2, *unused3, *unused4, *unused5; 301 302 LIST *stmts; /* list of all statements */ 303 const struct st_mysql_methods *methods; 304 void *thd; 305 /* 306 Points to boolean flag in MYSQL_RES or MYSQL_STMT. We set this flag 307 from mysql_stmt_close if close had to cancel result set of this object. 308 */ 309 my_bool *unbuffered_fetch_owner; 310 /* needed for embedded server - no net buffer to store the 'info' */ 311 char *info_buffer; 312 void *extension; 313 } MYSQL; 314 315 316 typedef struct st_mysql_res { 317 my_ulonglong row_count; 318 MYSQL_FIELD *fields; 319 MYSQL_DATA *data; 320 MYSQL_ROWS *data_cursor; 321 unsigned long *lengths; /* column lengths of current row */ 322 MYSQL *handle; /* for unbuffered reads */ 323 const struct st_mysql_methods *methods; 324 MYSQL_ROW row; /* If unbuffered read */ 325 MYSQL_ROW current_row; /* buffer to current row */ 326 MEM_ROOT field_alloc; 327 unsigned int field_count, current_field; 328 my_bool eof; /* Used by mysql_fetch_row */ 329 /* mysql_stmt_close() had to cancel this result */ 330 my_bool unbuffered_fetch_cancelled; 331 void *extension; 332 } MYSQL_RES; 333 334 335 #if !defined(MYSQL_SERVER) && !defined(MYSQL_CLIENT) 336 #define MYSQL_CLIENT 337 #endif 338 339 340 typedef struct st_mysql_parameters 341 { 342 unsigned long *p_max_allowed_packet; 343 unsigned long *p_net_buffer_length; 344 void *extension; 345 } MYSQL_PARAMETERS; 346 347 /* 348 Flag bits, the asynchronous methods return a combination of these ORed 349 together to let the application know when to resume the suspended operation. 350 */ 351 352 /* 353 Wait for data to be available on socket to read. 354 mysql_get_socket_fd() will return socket descriptor. 355 */ 356 #define MYSQL_WAIT_READ 1 357 /* Wait for socket to be ready to write data. */ 358 #define MYSQL_WAIT_WRITE 2 359 /* Wait for select() to mark exception on socket. */ 360 #define MYSQL_WAIT_EXCEPT 4 361 /* 362 Wait until timeout occurs. Value of timeout can be obtained from 363 mysql_get_timeout_value(). 364 */ 365 #define MYSQL_WAIT_TIMEOUT 8 366 367 #if !defined(MYSQL_SERVER) && !defined(EMBEDDED_LIBRARY) 368 #define max_allowed_packet (*mysql_get_parameters()->p_max_allowed_packet) 369 #define net_buffer_length (*mysql_get_parameters()->p_net_buffer_length) 370 #endif 371 372 /* 373 Set up and bring down the server; to ensure that applications will 374 work when linked against either the standard client library or the 375 embedded server library, these functions should be called. 376 */ 377 int STDCALL mysql_server_init(int argc, char **argv, char **groups); 378 void STDCALL mysql_server_end(void); 379 380 /* 381 mysql_server_init/end need to be called when using libmysqld or 382 libmysqlclient (exactly, mysql_server_init() is called by mysql_init() so 383 you don't need to call it explicitly; but you need to call 384 mysql_server_end() to free memory). The names are a bit misleading 385 (mysql_SERVER* to be used when using libmysqlCLIENT). So we add more general 386 names which suit well whether you're using libmysqld or libmysqlclient. We 387 intend to promote these aliases over the mysql_server* ones. 388 */ 389 #define mysql_library_init mysql_server_init 390 #define mysql_library_end mysql_server_end 391 392 MYSQL_PARAMETERS *STDCALL mysql_get_parameters(void); 393 394 /* 395 Set up and bring down a thread; these function should be called 396 for each thread in an application which opens at least one MySQL 397 connection. All uses of the connection(s) should be between these 398 function calls. 399 */ 400 my_bool STDCALL mysql_thread_init(void); 401 void STDCALL mysql_thread_end(void); 402 403 /* 404 Functions to get information from the MYSQL and MYSQL_RES structures 405 Should definitely be used if one uses shared libraries. 406 */ 407 408 my_ulonglong STDCALL mysql_num_rows(MYSQL_RES *res); 409 unsigned int STDCALL mysql_num_fields(MYSQL_RES *res); 410 my_bool STDCALL mysql_eof(MYSQL_RES *res); 411 MYSQL_FIELD *STDCALL mysql_fetch_field_direct(MYSQL_RES *res, 412 unsigned int fieldnr); 413 MYSQL_FIELD * STDCALL mysql_fetch_fields(MYSQL_RES *res); 414 MYSQL_ROW_OFFSET STDCALL mysql_row_tell(MYSQL_RES *res); 415 MYSQL_FIELD_OFFSET STDCALL mysql_field_tell(MYSQL_RES *res); 416 417 418 419 420 int STDCALL mariadb_field_attr(MARIADB_CONST_STRING *attr, 421 const MYSQL_FIELD *field, 422 enum mariadb_field_attr_t type); 423 424 425 unsigned int STDCALL mysql_field_count(MYSQL *mysql); 426 my_ulonglong STDCALL mysql_affected_rows(MYSQL *mysql); 427 my_ulonglong STDCALL mysql_insert_id(MYSQL *mysql); 428 unsigned int STDCALL mysql_errno(MYSQL *mysql); 429 const char * STDCALL mysql_error(MYSQL *mysql); 430 const char *STDCALL mysql_sqlstate(MYSQL *mysql); 431 unsigned int STDCALL mysql_warning_count(MYSQL *mysql); 432 const char * STDCALL mysql_info(MYSQL *mysql); 433 unsigned long STDCALL mysql_thread_id(MYSQL *mysql); 434 const char * STDCALL mysql_character_set_name(MYSQL *mysql); 435 int STDCALL mysql_set_character_set(MYSQL *mysql, const char *csname); 436 int STDCALL mysql_set_character_set_start(int *ret, MYSQL *mysql, 437 const char *csname); 438 int STDCALL mysql_set_character_set_cont(int *ret, MYSQL *mysql, 439 int status); 440 441 MYSQL * STDCALL mysql_init(MYSQL *mysql); 442 my_bool STDCALL mysql_ssl_set(MYSQL *mysql, const char *key, 443 const char *cert, const char *ca, 444 const char *capath, const char *cipher); 445 const char * STDCALL mysql_get_ssl_cipher(MYSQL *mysql); 446 my_bool STDCALL mysql_change_user(MYSQL *mysql, const char *user, 447 const char *passwd, const char *db); 448 int STDCALL mysql_change_user_start(my_bool *ret, MYSQL *mysql, 449 const char *user, 450 const char *passwd, 451 const char *db); 452 int STDCALL mysql_change_user_cont(my_bool *ret, MYSQL *mysql, 453 int status); 454 MYSQL * STDCALL mysql_real_connect(MYSQL *mysql, const char *host, 455 const char *user, 456 const char *passwd, 457 const char *db, 458 unsigned int port, 459 const char *unix_socket, 460 unsigned long clientflag); 461 int STDCALL mysql_real_connect_start(MYSQL **ret, MYSQL *mysql, 462 const char *host, 463 const char *user, 464 const char *passwd, 465 const char *db, 466 unsigned int port, 467 const char *unix_socket, 468 unsigned long clientflag); 469 int STDCALL mysql_real_connect_cont(MYSQL **ret, MYSQL *mysql, 470 int status); 471 int STDCALL mysql_select_db(MYSQL *mysql, const char *db); 472 int STDCALL mysql_select_db_start(int *ret, MYSQL *mysql, 473 const char *db); 474 int STDCALL mysql_select_db_cont(int *ret, MYSQL *mysql, 475 int status); 476 int STDCALL mysql_query(MYSQL *mysql, const char *q); 477 int STDCALL mysql_query_start(int *ret, MYSQL *mysql, 478 const char *q); 479 int STDCALL mysql_query_cont(int *ret, MYSQL *mysql, 480 int status); 481 int STDCALL mysql_send_query(MYSQL *mysql, const char *q, 482 unsigned long length); 483 int STDCALL mysql_send_query_start(int *ret, MYSQL *mysql, 484 const char *q, 485 unsigned long length); 486 int STDCALL mysql_send_query_cont(int *ret, MYSQL *mysql, 487 int status); 488 int STDCALL mysql_real_query(MYSQL *mysql, const char *q, 489 unsigned long length); 490 int STDCALL mysql_real_query_start(int *ret, MYSQL *mysql, 491 const char *q, 492 unsigned long length); 493 int STDCALL mysql_real_query_cont(int *ret, MYSQL *mysql, 494 int status); 495 MYSQL_RES * STDCALL mysql_store_result(MYSQL *mysql); 496 int STDCALL mysql_store_result_start(MYSQL_RES **ret, MYSQL *mysql); 497 int STDCALL mysql_store_result_cont(MYSQL_RES **ret, MYSQL *mysql, 498 int status); 499 MYSQL_RES * STDCALL mysql_use_result(MYSQL *mysql); 500 501 void STDCALL mysql_get_character_set_info(MYSQL *mysql, 502 MY_CHARSET_INFO *charset); 503 504 /* local infile support */ 505 506 #define LOCAL_INFILE_ERROR_LEN 512 507 508 void 509 mysql_set_local_infile_handler(MYSQL *mysql, 510 int (*local_infile_init)(void **, const char *, 511 void *), 512 int (*local_infile_read)(void *, char *, 513 unsigned int), 514 void (*local_infile_end)(void *), 515 int (*local_infile_error)(void *, char*, 516 unsigned int), 517 void *); 518 519 void 520 mysql_set_local_infile_default(MYSQL *mysql); 521 522 int STDCALL mysql_shutdown(MYSQL *mysql, 523 enum mysql_enum_shutdown_level 524 shutdown_level); 525 int STDCALL mysql_shutdown_start(int *ret, MYSQL *mysql, 526 enum mysql_enum_shutdown_level 527 shutdown_level); 528 int STDCALL mysql_shutdown_cont(int *ret, MYSQL *mysql, 529 int status); 530 int STDCALL mysql_dump_debug_info(MYSQL *mysql); 531 int STDCALL mysql_dump_debug_info_start(int *ret, MYSQL *mysql); 532 int STDCALL mysql_dump_debug_info_cont(int *ret, MYSQL *mysql, 533 int status); 534 int STDCALL mysql_refresh(MYSQL *mysql, 535 unsigned int refresh_options); 536 int STDCALL mysql_refresh_start(int *ret, MYSQL *mysql, 537 unsigned int refresh_options); 538 int STDCALL mysql_refresh_cont(int *ret, MYSQL *mysql, int status); 539 int STDCALL mysql_kill(MYSQL *mysql,unsigned long pid); 540 int STDCALL mysql_kill_start(int *ret, MYSQL *mysql, 541 unsigned long pid); 542 int STDCALL mysql_kill_cont(int *ret, MYSQL *mysql, int status); 543 int STDCALL mysql_set_server_option(MYSQL *mysql, 544 enum enum_mysql_set_option 545 option); 546 int STDCALL mysql_set_server_option_start(int *ret, MYSQL *mysql, 547 enum enum_mysql_set_option 548 option); 549 int STDCALL mysql_set_server_option_cont(int *ret, MYSQL *mysql, 550 int status); 551 int STDCALL mysql_ping(MYSQL *mysql); 552 int STDCALL mysql_ping_start(int *ret, MYSQL *mysql); 553 int STDCALL mysql_ping_cont(int *ret, MYSQL *mysql, int status); 554 const char * STDCALL mysql_stat(MYSQL *mysql); 555 int STDCALL mysql_stat_start(const char **ret, MYSQL *mysql); 556 int STDCALL mysql_stat_cont(const char **ret, MYSQL *mysql, 557 int status); 558 const char * STDCALL mysql_get_server_info(MYSQL *mysql); 559 const char * STDCALL mysql_get_server_name(MYSQL *mysql); 560 const char * STDCALL mysql_get_client_info(void); 561 unsigned long STDCALL mysql_get_client_version(void); 562 const char * STDCALL mysql_get_host_info(MYSQL *mysql); 563 unsigned long STDCALL mysql_get_server_version(MYSQL *mysql); 564 unsigned int STDCALL mysql_get_proto_info(MYSQL *mysql); 565 MYSQL_RES * STDCALL mysql_list_dbs(MYSQL *mysql,const char *wild); 566 int STDCALL mysql_list_dbs_start(MYSQL_RES **ret, MYSQL *mysql, 567 const char *wild); 568 int STDCALL mysql_list_dbs_cont(MYSQL_RES **ret, MYSQL *mysql, 569 int status); 570 MYSQL_RES * STDCALL mysql_list_tables(MYSQL *mysql,const char *wild); 571 int STDCALL mysql_list_tables_start(MYSQL_RES **ret, MYSQL *mysql, 572 const char *wild); 573 int STDCALL mysql_list_tables_cont(MYSQL_RES **ret, MYSQL *mysql, 574 int status); 575 MYSQL_RES * STDCALL mysql_list_processes(MYSQL *mysql); 576 int STDCALL mysql_list_processes_start(MYSQL_RES **ret, 577 MYSQL *mysql); 578 int STDCALL mysql_list_processes_cont(MYSQL_RES **ret, MYSQL *mysql, 579 int status); 580 int STDCALL mysql_options(MYSQL *mysql,enum mysql_option option, 581 const void *arg); 582 int STDCALL mysql_options4(MYSQL *mysql,enum mysql_option option, 583 const void *arg1, const void *arg2); 584 void STDCALL mysql_free_result(MYSQL_RES *result); 585 int STDCALL mysql_free_result_start(MYSQL_RES *result); 586 int STDCALL mysql_free_result_cont(MYSQL_RES *result, int status); 587 void STDCALL mysql_data_seek(MYSQL_RES *result, 588 my_ulonglong offset); 589 MYSQL_ROW_OFFSET STDCALL mysql_row_seek(MYSQL_RES *result, 590 MYSQL_ROW_OFFSET offset); 591 MYSQL_FIELD_OFFSET STDCALL mysql_field_seek(MYSQL_RES *result, 592 MYSQL_FIELD_OFFSET offset); 593 MYSQL_ROW STDCALL mysql_fetch_row(MYSQL_RES *result); 594 int STDCALL mysql_fetch_row_start(MYSQL_ROW *ret, 595 MYSQL_RES *result); 596 int STDCALL mysql_fetch_row_cont(MYSQL_ROW *ret, MYSQL_RES *result, 597 int status); 598 unsigned long * STDCALL mysql_fetch_lengths(MYSQL_RES *result); 599 MYSQL_FIELD * STDCALL mysql_fetch_field(MYSQL_RES *result); 600 MYSQL_RES * STDCALL mysql_list_fields(MYSQL *mysql, const char *table, 601 const char *wild); 602 int STDCALL mysql_list_fields_start(MYSQL_RES **ret, MYSQL *mysql, 603 const char *table, 604 const char *wild); 605 int STDCALL mysql_list_fields_cont(MYSQL_RES **ret, MYSQL *mysql, 606 int status); 607 unsigned long STDCALL mysql_escape_string(char *to,const char *from, 608 unsigned long from_length); 609 unsigned long STDCALL mysql_hex_string(char *to,const char *from, 610 unsigned long from_length); 611 unsigned long STDCALL mysql_real_escape_string(MYSQL *mysql, 612 char *to,const char *from, 613 unsigned long length); 614 void STDCALL mysql_debug(const char *debug); 615 void STDCALL myodbc_remove_escape(MYSQL *mysql,char *name); 616 unsigned int STDCALL mysql_thread_safe(void); 617 my_bool STDCALL mysql_embedded(void); 618 my_bool STDCALL mariadb_connection(MYSQL *mysql); 619 my_bool STDCALL mysql_read_query_result(MYSQL *mysql); 620 int STDCALL mysql_read_query_result_start(my_bool *ret, 621 MYSQL *mysql); 622 int STDCALL mysql_read_query_result_cont(my_bool *ret, 623 MYSQL *mysql, int status); 624 625 626 /* 627 The following definitions are added for the enhanced 628 client-server protocol 629 */ 630 631 /* statement state */ 632 enum enum_mysql_stmt_state 633 { 634 MYSQL_STMT_INIT_DONE= 1, MYSQL_STMT_PREPARE_DONE, MYSQL_STMT_EXECUTE_DONE, 635 MYSQL_STMT_FETCH_DONE 636 }; 637 638 639 /* 640 This structure is used to define bind information, and 641 internally by the client library. 642 Public members with their descriptions are listed below 643 (conventionally `On input' refers to the binds given to 644 mysql_stmt_bind_param, `On output' refers to the binds given 645 to mysql_stmt_bind_result): 646 647 buffer_type - One of the MYSQL_* types, used to describe 648 the host language type of buffer. 649 On output: if column type is different from 650 buffer_type, column value is automatically converted 651 to buffer_type before it is stored in the buffer. 652 buffer - On input: points to the buffer with input data. 653 On output: points to the buffer capable to store 654 output data. 655 The type of memory pointed by buffer must correspond 656 to buffer_type. See the correspondence table in 657 the comment to mysql_stmt_bind_param. 658 659 The two above members are mandatory for any kind of bind. 660 661 buffer_length - the length of the buffer. You don't have to set 662 it for any fixed length buffer: float, double, 663 int, etc. It must be set however for variable-length 664 types, such as BLOBs or STRINGs. 665 666 length - On input: in case when lengths of input values 667 are different for each execute, you can set this to 668 point at a variable containining value length. This 669 way the value length can be different in each execute. 670 If length is not NULL, buffer_length is not used. 671 Note, length can even point at buffer_length if 672 you keep bind structures around while fetching: 673 this way you can change buffer_length before 674 each execution, everything will work ok. 675 On output: if length is set, mysql_stmt_fetch will 676 write column length into it. 677 678 is_null - On input: points to a boolean variable that should 679 be set to TRUE for NULL values. 680 This member is useful only if your data may be 681 NULL in some but not all cases. 682 If your data is never NULL, is_null should be set to 0. 683 If your data is always NULL, set buffer_type 684 to MYSQL_TYPE_NULL, and is_null will not be used. 685 686 is_unsigned - On input: used to signify that values provided for one 687 of numeric types are unsigned. 688 On output describes signedness of the output buffer. 689 If, taking into account is_unsigned flag, column data 690 is out of range of the output buffer, data for this column 691 is regarded truncated. Note that this has no correspondence 692 to the sign of result set column, if you need to find it out 693 use mysql_stmt_result_metadata. 694 error - where to write a truncation error if it is present. 695 possible error value is: 696 0 no truncation 697 1 value is out of range or buffer is too small 698 699 Please note that MYSQL_BIND also has internals members. 700 */ 701 702 typedef struct st_mysql_bind 703 { 704 unsigned long *length; /* output length pointer */ 705 my_bool *is_null; /* Pointer to null indicator */ 706 void *buffer; /* buffer to get/put data */ 707 /* set this if you want to track data truncations happened during fetch */ 708 my_bool *error; 709 unsigned char *row_ptr; /* for the current data position */ 710 void (*store_param_func)(NET *net, struct st_mysql_bind *param); 711 void (*fetch_result)(struct st_mysql_bind *, MYSQL_FIELD *, 712 unsigned char **row); 713 void (*skip_result)(struct st_mysql_bind *, MYSQL_FIELD *, 714 unsigned char **row); 715 /* output buffer length, must be set when fetching str/binary */ 716 unsigned long buffer_length; 717 unsigned long offset; /* offset position for char/binary fetch */ 718 unsigned long length_value; /* Used if length is 0 */ 719 unsigned int param_number; /* For null count and error messages */ 720 unsigned int pack_length; /* Internal length for packed data */ 721 enum enum_field_types buffer_type; /* buffer type */ 722 my_bool error_value; /* used if error is 0 */ 723 my_bool is_unsigned; /* set if integer type is unsigned */ 724 my_bool long_data_used; /* If used with mysql_send_long_data */ 725 my_bool is_null_value; /* Used if is_null is 0 */ 726 void *extension; 727 } MYSQL_BIND; 728 729 730 struct st_mysql_stmt_extension; 731 732 /* statement handler */ 733 typedef struct st_mysql_stmt 734 { 735 MEM_ROOT mem_root; /* root allocations */ 736 LIST list; /* list to keep track of all stmts */ 737 MYSQL *mysql; /* connection handle */ 738 MYSQL_BIND *params; /* input parameters */ 739 MYSQL_BIND *bind; /* output parameters */ 740 MYSQL_FIELD *fields; /* result set metadata */ 741 MYSQL_DATA result; /* cached result set */ 742 MYSQL_ROWS *data_cursor; /* current row in cached result */ 743 /* 744 mysql_stmt_fetch() calls this function to fetch one row (it's different 745 for buffered, unbuffered and cursor fetch). 746 */ 747 int (*read_row_func)(struct st_mysql_stmt *stmt, 748 unsigned char **row); 749 /* copy of mysql->affected_rows after statement execution */ 750 my_ulonglong affected_rows; 751 my_ulonglong insert_id; /* copy of mysql->insert_id */ 752 unsigned long stmt_id; /* Id for prepared statement */ 753 unsigned long flags; /* i.e. type of cursor to open */ 754 unsigned long prefetch_rows; /* number of rows per one COM_FETCH */ 755 /* 756 Copied from mysql->server_status after execute/fetch to know 757 server-side cursor status for this statement. 758 */ 759 unsigned int server_status; 760 unsigned int last_errno; /* error code */ 761 unsigned int param_count; /* input parameter count */ 762 unsigned int field_count; /* number of columns in result set */ 763 enum enum_mysql_stmt_state state; /* statement state */ 764 char last_error[MYSQL_ERRMSG_SIZE]; /* error message */ 765 char sqlstate[SQLSTATE_LENGTH+1]; 766 /* Types of input parameters should be sent to server */ 767 my_bool send_types_to_server; 768 my_bool bind_param_done; /* input buffers were supplied */ 769 unsigned char bind_result_done; /* output buffers were supplied */ 770 /* mysql_stmt_close() had to cancel this result */ 771 my_bool unbuffered_fetch_cancelled; 772 /* 773 Is set to true if we need to calculate field->max_length for 774 metadata fields when doing mysql_stmt_store_result. 775 */ 776 my_bool update_max_length; 777 struct st_mysql_stmt_extension *extension; 778 } MYSQL_STMT; 779 780 enum enum_stmt_attr_type 781 { 782 /* 783 When doing mysql_stmt_store_result calculate max_length attribute 784 of statement metadata. This is to be consistent with the old API, 785 where this was done automatically. 786 In the new API we do that only by request because it slows down 787 mysql_stmt_store_result sufficiently. 788 */ 789 STMT_ATTR_UPDATE_MAX_LENGTH, 790 /* 791 unsigned long with combination of cursor flags (read only, for update, 792 etc) 793 */ 794 STMT_ATTR_CURSOR_TYPE, 795 /* 796 Amount of rows to retrieve from server per one fetch if using cursors. 797 Accepts unsigned long attribute in the range 1 - ulong_max 798 */ 799 STMT_ATTR_PREFETCH_ROWS 800 }; 801 802 MYSQL_STMT * STDCALL mysql_stmt_init(MYSQL *mysql); 803 int STDCALL mysql_stmt_prepare(MYSQL_STMT *stmt, const char *query, 804 unsigned long length); 805 int STDCALL mysql_stmt_prepare_start(int *ret, MYSQL_STMT *stmt, 806 const char *query, unsigned long length); 807 int STDCALL mysql_stmt_prepare_cont(int *ret, MYSQL_STMT *stmt, int status); 808 int STDCALL mysql_stmt_execute(MYSQL_STMT *stmt); 809 int STDCALL mysql_stmt_execute_start(int *ret, MYSQL_STMT *stmt); 810 int STDCALL mysql_stmt_execute_cont(int *ret, MYSQL_STMT *stmt, int status); 811 int STDCALL mysql_stmt_fetch(MYSQL_STMT *stmt); 812 int STDCALL mysql_stmt_fetch_start(int *ret, MYSQL_STMT *stmt); 813 int STDCALL mysql_stmt_fetch_cont(int *ret, MYSQL_STMT *stmt, int status); 814 int STDCALL mysql_stmt_fetch_column(MYSQL_STMT *stmt, MYSQL_BIND *bind_arg, 815 unsigned int column, 816 unsigned long offset); 817 int STDCALL mysql_stmt_store_result(MYSQL_STMT *stmt); 818 int STDCALL mysql_stmt_store_result_start(int *ret, MYSQL_STMT *stmt); 819 int STDCALL mysql_stmt_store_result_cont(int *ret, MYSQL_STMT *stmt, 820 int status); 821 unsigned long STDCALL mysql_stmt_param_count(MYSQL_STMT * stmt); 822 my_bool STDCALL mysql_stmt_attr_set(MYSQL_STMT *stmt, 823 enum enum_stmt_attr_type attr_type, 824 const void *attr); 825 my_bool STDCALL mysql_stmt_attr_get(MYSQL_STMT *stmt, 826 enum enum_stmt_attr_type attr_type, 827 void *attr); 828 my_bool STDCALL mysql_stmt_bind_param(MYSQL_STMT * stmt, MYSQL_BIND * bnd); 829 my_bool STDCALL mysql_stmt_bind_result(MYSQL_STMT * stmt, MYSQL_BIND * bnd); 830 my_bool STDCALL mysql_stmt_close(MYSQL_STMT * stmt); 831 int STDCALL mysql_stmt_close_start(my_bool *ret, MYSQL_STMT *stmt); 832 int STDCALL mysql_stmt_close_cont(my_bool *ret, MYSQL_STMT * stmt, int status); 833 my_bool STDCALL mysql_stmt_reset(MYSQL_STMT * stmt); 834 int STDCALL mysql_stmt_reset_start(my_bool *ret, MYSQL_STMT * stmt); 835 int STDCALL mysql_stmt_reset_cont(my_bool *ret, MYSQL_STMT *stmt, int status); 836 my_bool STDCALL mysql_stmt_free_result(MYSQL_STMT *stmt); 837 int STDCALL mysql_stmt_free_result_start(my_bool *ret, MYSQL_STMT *stmt); 838 int STDCALL mysql_stmt_free_result_cont(my_bool *ret, MYSQL_STMT *stmt, 839 int status); 840 my_bool STDCALL mysql_stmt_send_long_data(MYSQL_STMT *stmt, 841 unsigned int param_number, 842 const char *data, 843 unsigned long length); 844 int STDCALL mysql_stmt_send_long_data_start(my_bool *ret, MYSQL_STMT *stmt, 845 unsigned int param_number, 846 const char *data, 847 unsigned long len); 848 int STDCALL mysql_stmt_send_long_data_cont(my_bool *ret, MYSQL_STMT *stmt, 849 int status); 850 MYSQL_RES *STDCALL mysql_stmt_result_metadata(MYSQL_STMT *stmt); 851 MYSQL_RES *STDCALL mysql_stmt_param_metadata(MYSQL_STMT *stmt); 852 unsigned int STDCALL mysql_stmt_errno(MYSQL_STMT * stmt); 853 const char *STDCALL mysql_stmt_error(MYSQL_STMT * stmt); 854 const char *STDCALL mysql_stmt_sqlstate(MYSQL_STMT * stmt); 855 MYSQL_ROW_OFFSET STDCALL mysql_stmt_row_seek(MYSQL_STMT *stmt, 856 MYSQL_ROW_OFFSET offset); 857 MYSQL_ROW_OFFSET STDCALL mysql_stmt_row_tell(MYSQL_STMT *stmt); 858 void STDCALL mysql_stmt_data_seek(MYSQL_STMT *stmt, my_ulonglong offset); 859 my_ulonglong STDCALL mysql_stmt_num_rows(MYSQL_STMT *stmt); 860 my_ulonglong STDCALL mysql_stmt_affected_rows(MYSQL_STMT *stmt); 861 my_ulonglong STDCALL mysql_stmt_insert_id(MYSQL_STMT *stmt); 862 unsigned int STDCALL mysql_stmt_field_count(MYSQL_STMT *stmt); 863 864 my_bool STDCALL mysql_commit(MYSQL * mysql); 865 int STDCALL mysql_commit_start(my_bool *ret, MYSQL * mysql); 866 int STDCALL mysql_commit_cont(my_bool *ret, MYSQL * mysql, int status); 867 my_bool STDCALL mysql_rollback(MYSQL * mysql); 868 int STDCALL mysql_rollback_start(my_bool *ret, MYSQL * mysql); 869 int STDCALL mysql_rollback_cont(my_bool *ret, MYSQL * mysql, int status); 870 my_bool STDCALL mysql_autocommit(MYSQL * mysql, my_bool auto_mode); 871 int STDCALL mysql_autocommit_start(my_bool *ret, MYSQL * mysql, 872 my_bool auto_mode); 873 int STDCALL mysql_autocommit_cont(my_bool *ret, MYSQL * mysql, int status); 874 my_bool STDCALL mysql_more_results(MYSQL *mysql); 875 int STDCALL mysql_next_result(MYSQL *mysql); 876 int STDCALL mysql_next_result_start(int *ret, MYSQL *mysql); 877 int STDCALL mysql_next_result_cont(int *ret, MYSQL *mysql, int status); 878 int STDCALL mysql_stmt_next_result(MYSQL_STMT *stmt); 879 int STDCALL mysql_stmt_next_result_start(int *ret, MYSQL_STMT *stmt); 880 int STDCALL mysql_stmt_next_result_cont(int *ret, MYSQL_STMT *stmt, int status); 881 void STDCALL mysql_close_slow_part(MYSQL *mysql); 882 void STDCALL mysql_close(MYSQL *sock); 883 int STDCALL mysql_close_start(MYSQL *sock); 884 int STDCALL mysql_close_cont(MYSQL *sock, int status); 885 my_socket STDCALL mysql_get_socket(const MYSQL *mysql); 886 unsigned int STDCALL mysql_get_timeout_value(const MYSQL *mysql); 887 unsigned int STDCALL mysql_get_timeout_value_ms(const MYSQL *mysql); 888 889 /******************************************************************** 890 mysql_net_ functions - low-level API to MySQL protocol 891 *********************************************************************/ 892 unsigned long STDCALL mysql_net_read_packet(MYSQL *mysql); 893 unsigned long STDCALL mysql_net_field_length(unsigned char **packet); 894 895 /* status return codes */ 896 #define MYSQL_NO_DATA 100 897 #define MYSQL_DATA_TRUNCATED 101 898 899 #define mysql_reload(mysql) mysql_refresh((mysql),REFRESH_GRANT) 900 901 #ifdef USE_OLD_FUNCTIONS 902 MYSQL * STDCALL mysql_connect(MYSQL *mysql, const char *host, 903 const char *user, const char *passwd); 904 int STDCALL mysql_create_db(MYSQL *mysql, const char *DB); 905 int STDCALL mysql_drop_db(MYSQL *mysql, const char *DB); 906 #endif 907 #define HAVE_MYSQL_REAL_CONNECT 908 909 #ifdef __cplusplus 910 } 911 #endif 912 913 #endif /* _mysql_h */ 914