00001 /* Copyright (C) 2000-2003 MySQL AB 00002 00003 This program is free software; you can redistribute it and/or modify 00004 it under the terms of the GNU General Public License as published by 00005 the Free Software Foundation; either version 2 of the License, or 00006 (at your option) any later version. 00007 00008 This program is distributed in the hope that it will be useful, 00009 but WITHOUT ANY WARRANTY; without even the implied warranty of 00010 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00011 GNU General Public License for more details. 00012 00013 You should have received a copy of the GNU General Public License 00014 along with this program; if not, write to the Free Software 00015 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ 00016 00017 #ifndef _mysql_h 00018 #define _mysql_h 00019 00020 #ifdef __CYGWIN__ /* CYGWIN implements a UNIX API */ 00021 #undef WIN 00022 #undef _WIN 00023 #undef _WIN32 00024 #undef _WIN64 00025 #undef __WIN__ 00026 #endif 00027 00028 #ifdef __cplusplus 00029 extern "C" { 00030 #endif 00031 00032 #ifndef _global_h /* If not standard header */ 00033 #include <sys/types.h> 00034 #ifdef __LCC__ 00035 #include <winsock.h> /* For windows */ 00036 #endif 00037 typedef char my_bool; 00038 #if (defined(_WIN32) || defined(_WIN64)) && !defined(__WIN__) 00039 #define __WIN__ 00040 #endif 00041 #if !defined(__WIN__) 00042 #define STDCALL 00043 #else 00044 #define STDCALL __stdcall 00045 #endif 00046 typedef char * gptr; 00047 00048 #ifndef my_socket_defined 00049 #ifdef __WIN__ 00050 #define my_socket SOCKET 00051 #else 00052 typedef int my_socket; 00053 #endif /* __WIN__ */ 00054 #endif /* my_socket_defined */ 00055 #endif /* _global_h */ 00056 00057 #include "mysql_com.h" 00058 #include "mysql_time.h" 00059 #include "mysql_version.h" 00060 #include "typelib.h" 00061 00062 #include "my_list.h" /* for LISTs used in 'MYSQL' and 'MYSQL_STMT' */ 00063 00064 extern unsigned int mysql_port; 00065 extern char *mysql_unix_port; 00066 00067 #define CLIENT_NET_READ_TIMEOUT 365*24*3600 /* Timeout on read */ 00068 #define CLIENT_NET_WRITE_TIMEOUT 365*24*3600 /* Timeout on write */ 00069 00070 #ifdef __NETWARE__ 00071 #pragma pack(push, 8) /* 8 byte alignment */ 00072 #endif 00073 00074 #define IS_PRI_KEY(n) ((n) & PRI_KEY_FLAG) 00075 #define IS_NOT_NULL(n) ((n) & NOT_NULL_FLAG) 00076 #define IS_BLOB(n) ((n) & BLOB_FLAG) 00077 #define IS_NUM(t) ((t) <= FIELD_TYPE_INT24 || (t) == FIELD_TYPE_YEAR || (t) == FIELD_TYPE_NEWDECIMAL) 00078 #define IS_NUM_FIELD(f) ((f)->flags & NUM_FLAG) 00079 #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) 00080 00081 00082 typedef struct st_mysql_field { 00083 char *name; /* Name of column */ 00084 char *org_name; /* Original column name, if an alias */ 00085 char *table; /* Table of column if column was a field */ 00086 char *org_table; /* Org table name, if table was an alias */ 00087 char *db; /* Database for table */ 00088 char *catalog; /* Catalog for table */ 00089 char *def; /* Default value (set by mysql_list_fields) */ 00090 unsigned long length; /* Width of column (create length) */ 00091 unsigned long max_length; /* Max width for selected set */ 00092 unsigned int name_length; 00093 unsigned int org_name_length; 00094 unsigned int table_length; 00095 unsigned int org_table_length; 00096 unsigned int db_length; 00097 unsigned int catalog_length; 00098 unsigned int def_length; 00099 unsigned int flags; /* Div flags */ 00100 unsigned int decimals; /* Number of decimals in field */ 00101 unsigned int charsetnr; /* Character set */ 00102 enum enum_field_types type; /* Type of field. See mysql_com.h for types */ 00103 } MYSQL_FIELD; 00104 00105 typedef char **MYSQL_ROW; /* return data as array of strings */ 00106 typedef unsigned int MYSQL_FIELD_OFFSET; /* offset to current field */ 00107 00108 #ifndef _global_h 00109 #if defined(NO_CLIENT_LONG_LONG) 00110 typedef unsigned long my_ulonglong; 00111 #elif defined (__WIN__) 00112 typedef unsigned __int64 my_ulonglong; 00113 #else 00114 typedef unsigned long long my_ulonglong; 00115 #endif 00116 #endif 00117 00118 #define MYSQL_COUNT_ERROR (~(my_ulonglong) 0) 00119 00120 /* backward compatibility define - to be removed eventually */ 00121 #define ER_WARN_DATA_TRUNCATED WARN_DATA_TRUNCATED 00122 00123 typedef struct st_mysql_rows { 00124 struct st_mysql_rows *next; /* list of rows */ 00125 MYSQL_ROW data; 00126 unsigned long length; 00127 } MYSQL_ROWS; 00128 00129 typedef MYSQL_ROWS *MYSQL_ROW_OFFSET; /* offset to current row */ 00130 00131 #include "my_alloc.h" 00132 00133 typedef struct embedded_query_result EMBEDDED_QUERY_RESULT; 00134 typedef struct st_mysql_data { 00135 my_ulonglong rows; 00136 unsigned int fields; 00137 MYSQL_ROWS *data; 00138 MEM_ROOT alloc; 00139 /* extra info for embedded library */ 00140 struct embedded_query_result *embedded_info; 00141 } MYSQL_DATA; 00142 00143 enum mysql_option 00144 { 00145 MYSQL_OPT_CONNECT_TIMEOUT, MYSQL_OPT_COMPRESS, MYSQL_OPT_NAMED_PIPE, 00146 MYSQL_INIT_COMMAND, MYSQL_READ_DEFAULT_FILE, MYSQL_READ_DEFAULT_GROUP, 00147 MYSQL_SET_CHARSET_DIR, MYSQL_SET_CHARSET_NAME, MYSQL_OPT_LOCAL_INFILE, 00148 MYSQL_OPT_PROTOCOL, MYSQL_SHARED_MEMORY_BASE_NAME, MYSQL_OPT_READ_TIMEOUT, 00149 MYSQL_OPT_WRITE_TIMEOUT, MYSQL_OPT_USE_RESULT, 00150 MYSQL_OPT_USE_REMOTE_CONNECTION, MYSQL_OPT_USE_EMBEDDED_CONNECTION, 00151 MYSQL_OPT_GUESS_CONNECTION, MYSQL_SET_CLIENT_IP, MYSQL_SECURE_AUTH, 00152 MYSQL_REPORT_DATA_TRUNCATION, MYSQL_OPT_RECONNECT, 00153 MYSQL_OPT_SSL_VERIFY_SERVER_CERT 00154 }; 00155 00156 struct st_mysql_options { 00157 unsigned int connect_timeout, read_timeout, write_timeout; 00158 unsigned int port, protocol; 00159 unsigned long client_flag; 00160 char *host,*user,*password,*unix_socket,*db; 00161 struct st_dynamic_array *init_commands; 00162 char *my_cnf_file,*my_cnf_group, *charset_dir, *charset_name; 00163 char *ssl_key; /* PEM key file */ 00164 char *ssl_cert; /* PEM cert file */ 00165 char *ssl_ca; /* PEM CA file */ 00166 char *ssl_capath; /* PEM directory of CA-s? */ 00167 char *ssl_cipher; /* cipher to use */ 00168 my_bool ssl_verify_server_cert; /* if to verify server cert */ 00169 char *shared_memory_base_name; 00170 unsigned long max_allowed_packet; 00171 my_bool use_ssl; /* if to use SSL or not */ 00172 my_bool compress,named_pipe; 00173 /* 00174 On connect, find out the replication role of the server, and 00175 establish connections to all the peers 00176 */ 00177 my_bool rpl_probe; 00178 /* 00179 Each call to mysql_real_query() will parse it to tell if it is a read 00180 or a write, and direct it to the slave or the master 00181 */ 00182 my_bool rpl_parse; 00183 /* 00184 If set, never read from a master, only from slave, when doing 00185 a read that is replication-aware 00186 */ 00187 my_bool no_master_reads; 00188 #if !defined(CHECK_EMBEDDED_DIFFERENCES) || defined(EMBEDDED_LIBRARY) 00189 my_bool separate_thread; 00190 #endif 00191 enum mysql_option methods_to_use; 00192 char *client_ip; 00193 /* Refuse client connecting to server if it uses old (pre-4.1.1) protocol */ 00194 my_bool secure_auth; 00195 /* 0 - never report, 1 - always report (default) */ 00196 my_bool report_data_truncation; 00197 00198 /* function pointers for local infile support */ 00199 int (*local_infile_init)(void **, const char *, void *); 00200 int (*local_infile_read)(void *, char *, unsigned int); 00201 void (*local_infile_end)(void *); 00202 int (*local_infile_error)(void *, char *, unsigned int); 00203 void *local_infile_userdata; 00204 }; 00205 00206 enum mysql_status 00207 { 00208 MYSQL_STATUS_READY,MYSQL_STATUS_GET_RESULT,MYSQL_STATUS_USE_RESULT 00209 }; 00210 00211 enum mysql_protocol_type 00212 { 00213 MYSQL_PROTOCOL_DEFAULT, MYSQL_PROTOCOL_TCP, MYSQL_PROTOCOL_SOCKET, 00214 MYSQL_PROTOCOL_PIPE, MYSQL_PROTOCOL_MEMORY 00215 }; 00216 /* 00217 There are three types of queries - the ones that have to go to 00218 the master, the ones that go to a slave, and the adminstrative 00219 type which must happen on the pivot connectioin 00220 */ 00221 enum mysql_rpl_type 00222 { 00223 MYSQL_RPL_MASTER, MYSQL_RPL_SLAVE, MYSQL_RPL_ADMIN 00224 }; 00225 00226 typedef struct character_set 00227 { 00228 unsigned int number; /* character set number */ 00229 unsigned int state; /* character set state */ 00230 const char *csname; /* collation name */ 00231 const char *name; /* character set name */ 00232 const char *comment; /* comment */ 00233 const char *dir; /* character set directory */ 00234 unsigned int mbminlen; /* min. length for multibyte strings */ 00235 unsigned int mbmaxlen; /* max. length for multibyte strings */ 00236 } MY_CHARSET_INFO; 00237 00238 struct st_mysql_methods; 00239 struct st_mysql_stmt; 00240 00241 typedef struct st_mysql 00242 { 00243 NET net; /* Communication parameters */ 00244 gptr connector_fd; /* ConnectorFd for SSL */ 00245 char *host,*user,*passwd,*unix_socket,*server_version,*host_info,*info; 00246 char *db; 00247 struct charset_info_st *charset; 00248 MYSQL_FIELD *fields; 00249 MEM_ROOT field_alloc; 00250 my_ulonglong affected_rows; 00251 my_ulonglong insert_id; /* id if insert on table with NEXTNR */ 00252 my_ulonglong extra_info; /* Not used */ 00253 unsigned long thread_id; /* Id for connection in server */ 00254 unsigned long packet_length; 00255 unsigned int port; 00256 unsigned long client_flag,server_capabilities; 00257 unsigned int protocol_version; 00258 unsigned int field_count; 00259 unsigned int server_status; 00260 unsigned int server_language; 00261 unsigned int warning_count; 00262 struct st_mysql_options options; 00263 enum mysql_status status; 00264 my_bool free_me; /* If free in mysql_close */ 00265 my_bool reconnect; /* set to 1 if automatic reconnect */ 00266 00267 /* session-wide random string */ 00268 char scramble[SCRAMBLE_LENGTH+1]; 00269 00270 /* 00271 Set if this is the original connection, not a master or a slave we have 00272 added though mysql_rpl_probe() or mysql_set_master()/ mysql_add_slave() 00273 */ 00274 my_bool rpl_pivot; 00275 /* 00276 Pointers to the master, and the next slave connections, points to 00277 itself if lone connection. 00278 */ 00279 struct st_mysql* master, *next_slave; 00280 00281 struct st_mysql* last_used_slave; /* needed for round-robin slave pick */ 00282 /* needed for send/read/store/use result to work correctly with replication */ 00283 struct st_mysql* last_used_con; 00284 00285 LIST *stmts; /* list of all statements */ 00286 const struct st_mysql_methods *methods; 00287 void *thd; 00288 /* 00289 Points to boolean flag in MYSQL_RES or MYSQL_STMT. We set this flag 00290 from mysql_stmt_close if close had to cancel result set of this object. 00291 */ 00292 my_bool *unbuffered_fetch_owner; 00293 #if defined(EMBEDDED_LIBRARY) || defined(EMBEDDED_LIBRARY_COMPATIBLE) || MYSQL_VERSION_ID >= 50100 00294 /* needed for embedded server - no net buffer to store the 'info' */ 00295 char *info_buffer; 00296 #endif 00297 /* 00298 In embedded server it points to the statement that is processed 00299 in the current query. We store some results directly in statement 00300 fields then. 00301 */ 00302 struct st_mysql_stmt *current_stmt; 00303 } MYSQL; 00304 00305 typedef struct st_mysql_res { 00306 my_ulonglong row_count; 00307 MYSQL_FIELD *fields; 00308 MYSQL_DATA *data; 00309 MYSQL_ROWS *data_cursor; 00310 unsigned long *lengths; /* column lengths of current row */ 00311 MYSQL *handle; /* for unbuffered reads */ 00312 MEM_ROOT field_alloc; 00313 unsigned int field_count, current_field; 00314 MYSQL_ROW row; /* If unbuffered read */ 00315 MYSQL_ROW current_row; /* buffer to current row */ 00316 my_bool eof; /* Used by mysql_fetch_row */ 00317 /* mysql_stmt_close() had to cancel this result */ 00318 my_bool unbuffered_fetch_cancelled; 00319 const struct st_mysql_methods *methods; 00320 } MYSQL_RES; 00321 00322 #define MAX_MYSQL_MANAGER_ERR 256 00323 #define MAX_MYSQL_MANAGER_MSG 256 00324 00325 #define MANAGER_OK 200 00326 #define MANAGER_INFO 250 00327 #define MANAGER_ACCESS 401 00328 #define MANAGER_CLIENT_ERR 450 00329 #define MANAGER_INTERNAL_ERR 500 00330 00331 #if !defined(MYSQL_SERVER) && !defined(MYSQL_CLIENT) 00332 #define MYSQL_CLIENT 00333 #endif 00334 00335 00336 typedef struct st_mysql_manager 00337 { 00338 NET net; 00339 char *host,*user,*passwd; 00340 unsigned int port; 00341 my_bool free_me; 00342 my_bool eof; 00343 int cmd_status; 00344 int last_errno; 00345 char* net_buf,*net_buf_pos,*net_data_end; 00346 int net_buf_size; 00347 char last_error[MAX_MYSQL_MANAGER_ERR]; 00348 } MYSQL_MANAGER; 00349 00350 typedef struct st_mysql_parameters 00351 { 00352 unsigned long *p_max_allowed_packet; 00353 unsigned long *p_net_buffer_length; 00354 } MYSQL_PARAMETERS; 00355 00356 #if !defined(MYSQL_SERVER) && !defined(EMBEDDED_LIBRARY) 00357 #define max_allowed_packet (*mysql_get_parameters()->p_max_allowed_packet) 00358 #define net_buffer_length (*mysql_get_parameters()->p_net_buffer_length) 00359 #endif 00360 00361 /* 00362 Set up and bring down the server; to ensure that applications will 00363 work when linked against either the standard client library or the 00364 embedded server library, these functions should be called. 00365 */ 00366 int STDCALL mysql_server_init(int argc, char **argv, char **groups); 00367 void STDCALL mysql_server_end(void); 00368 /* 00369 mysql_server_init/end need to be called when using libmysqld or 00370 libmysqlclient (exactly, mysql_server_init() is called by mysql_init() so 00371 you don't need to call it explicitely; but you need to call 00372 mysql_server_end() to free memory). The names are a bit misleading 00373 (mysql_SERVER* to be used when using libmysqlCLIENT). So we add more general 00374 names which suit well whether you're using libmysqld or libmysqlclient. We 00375 intend to promote these aliases over the mysql_server* ones. 00376 */ 00377 #define mysql_library_init mysql_server_init 00378 #define mysql_library_end mysql_server_end 00379 00380 MYSQL_PARAMETERS *STDCALL mysql_get_parameters(void); 00381 00382 /* 00383 Set up and bring down a thread; these function should be called 00384 for each thread in an application which opens at least one MySQL 00385 connection. All uses of the connection(s) should be between these 00386 function calls. 00387 */ 00388 my_bool STDCALL mysql_thread_init(void); 00389 void STDCALL mysql_thread_end(void); 00390 00391 /* 00392 Functions to get information from the MYSQL and MYSQL_RES structures 00393 Should definitely be used if one uses shared libraries. 00394 */ 00395 00396 my_ulonglong STDCALL mysql_num_rows(MYSQL_RES *res); 00397 unsigned int STDCALL mysql_num_fields(MYSQL_RES *res); 00398 my_bool STDCALL mysql_eof(MYSQL_RES *res); 00399 MYSQL_FIELD *STDCALL mysql_fetch_field_direct(MYSQL_RES *res, 00400 unsigned int fieldnr); 00401 MYSQL_FIELD * STDCALL mysql_fetch_fields(MYSQL_RES *res); 00402 MYSQL_ROW_OFFSET STDCALL mysql_row_tell(MYSQL_RES *res); 00403 MYSQL_FIELD_OFFSET STDCALL mysql_field_tell(MYSQL_RES *res); 00404 00405 unsigned int STDCALL mysql_field_count(MYSQL *mysql); 00406 my_ulonglong STDCALL mysql_affected_rows(MYSQL *mysql); 00407 my_ulonglong STDCALL mysql_insert_id(MYSQL *mysql); 00408 unsigned int STDCALL mysql_errno(MYSQL *mysql); 00409 const char * STDCALL mysql_error(MYSQL *mysql); 00410 const char *STDCALL mysql_sqlstate(MYSQL *mysql); 00411 unsigned int STDCALL mysql_warning_count(MYSQL *mysql); 00412 const char * STDCALL mysql_info(MYSQL *mysql); 00413 unsigned long STDCALL mysql_thread_id(MYSQL *mysql); 00414 const char * STDCALL mysql_character_set_name(MYSQL *mysql); 00415 int STDCALL mysql_set_character_set(MYSQL *mysql, const char *csname); 00416 00417 MYSQL * STDCALL mysql_init(MYSQL *mysql); 00418 my_bool STDCALL mysql_ssl_set(MYSQL *mysql, const char *key, 00419 const char *cert, const char *ca, 00420 const char *capath, const char *cipher); 00421 const char * STDCALL mysql_get_ssl_cipher(MYSQL *mysql); 00422 my_bool STDCALL mysql_change_user(MYSQL *mysql, const char *user, 00423 const char *passwd, const char *db); 00424 MYSQL * STDCALL mysql_real_connect(MYSQL *mysql, const char *host, 00425 const char *user, 00426 const char *passwd, 00427 const char *db, 00428 unsigned int port, 00429 const char *unix_socket, 00430 unsigned long clientflag); 00431 int STDCALL mysql_select_db(MYSQL *mysql, const char *db); 00432 int STDCALL mysql_query(MYSQL *mysql, const char *q); 00433 int STDCALL mysql_send_query(MYSQL *mysql, const char *q, 00434 unsigned long length); 00435 int STDCALL mysql_real_query(MYSQL *mysql, const char *q, 00436 unsigned long length); 00437 MYSQL_RES * STDCALL mysql_store_result(MYSQL *mysql); 00438 MYSQL_RES * STDCALL mysql_use_result(MYSQL *mysql); 00439 00440 /* perform query on master */ 00441 my_bool STDCALL mysql_master_query(MYSQL *mysql, const char *q, 00442 unsigned long length); 00443 my_bool STDCALL mysql_master_send_query(MYSQL *mysql, const char *q, 00444 unsigned long length); 00445 /* perform query on slave */ 00446 my_bool STDCALL mysql_slave_query(MYSQL *mysql, const char *q, 00447 unsigned long length); 00448 my_bool STDCALL mysql_slave_send_query(MYSQL *mysql, const char *q, 00449 unsigned long length); 00450 void STDCALL mysql_get_character_set_info(MYSQL *mysql, 00451 MY_CHARSET_INFO *charset); 00452 00453 /* local infile support */ 00454 00455 #define LOCAL_INFILE_ERROR_LEN 512 00456 00457 void 00458 mysql_set_local_infile_handler(MYSQL *mysql, 00459 int (*local_infile_init)(void **, const char *, 00460 void *), 00461 int (*local_infile_read)(void *, char *, 00462 unsigned int), 00463 void (*local_infile_end)(void *), 00464 int (*local_infile_error)(void *, char*, 00465 unsigned int), 00466 void *); 00467 00468 void 00469 mysql_set_local_infile_default(MYSQL *mysql); 00470 00471 00472 /* 00473 enable/disable parsing of all queries to decide if they go on master or 00474 slave 00475 */ 00476 void STDCALL mysql_enable_rpl_parse(MYSQL* mysql); 00477 void STDCALL mysql_disable_rpl_parse(MYSQL* mysql); 00478 /* get the value of the parse flag */ 00479 int STDCALL mysql_rpl_parse_enabled(MYSQL* mysql); 00480 00481 /* enable/disable reads from master */ 00482 void STDCALL mysql_enable_reads_from_master(MYSQL* mysql); 00483 void STDCALL mysql_disable_reads_from_master(MYSQL* mysql); 00484 /* get the value of the master read flag */ 00485 my_bool STDCALL mysql_reads_from_master_enabled(MYSQL* mysql); 00486 00487 enum mysql_rpl_type STDCALL mysql_rpl_query_type(const char* q, int len); 00488 00489 /* discover the master and its slaves */ 00490 my_bool STDCALL mysql_rpl_probe(MYSQL* mysql); 00491 00492 /* set the master, close/free the old one, if it is not a pivot */ 00493 int STDCALL mysql_set_master(MYSQL* mysql, const char* host, 00494 unsigned int port, 00495 const char* user, 00496 const char* passwd); 00497 int STDCALL mysql_add_slave(MYSQL* mysql, const char* host, 00498 unsigned int port, 00499 const char* user, 00500 const char* passwd); 00501 00502 int STDCALL mysql_shutdown(MYSQL *mysql, 00503 enum mysql_enum_shutdown_level 00504 shutdown_level); 00505 int STDCALL mysql_dump_debug_info(MYSQL *mysql); 00506 int STDCALL mysql_refresh(MYSQL *mysql, 00507 unsigned int refresh_options); 00508 int STDCALL mysql_kill(MYSQL *mysql,unsigned long pid); 00509 int STDCALL mysql_set_server_option(MYSQL *mysql, 00510 enum enum_mysql_set_option 00511 option); 00512 int STDCALL mysql_ping(MYSQL *mysql); 00513 const char * STDCALL mysql_stat(MYSQL *mysql); 00514 const char * STDCALL mysql_get_server_info(MYSQL *mysql); 00515 const char * STDCALL mysql_get_client_info(void); 00516 unsigned long STDCALL mysql_get_client_version(void); 00517 const char * STDCALL mysql_get_host_info(MYSQL *mysql); 00518 unsigned long STDCALL mysql_get_server_version(MYSQL *mysql); 00519 unsigned int STDCALL mysql_get_proto_info(MYSQL *mysql); 00520 MYSQL_RES * STDCALL mysql_list_dbs(MYSQL *mysql,const char *wild); 00521 MYSQL_RES * STDCALL mysql_list_tables(MYSQL *mysql,const char *wild); 00522 MYSQL_RES * STDCALL mysql_list_processes(MYSQL *mysql); 00523 int STDCALL mysql_options(MYSQL *mysql,enum mysql_option option, 00524 const char *arg); 00525 void STDCALL mysql_free_result(MYSQL_RES *result); 00526 void STDCALL mysql_data_seek(MYSQL_RES *result, 00527 my_ulonglong offset); 00528 MYSQL_ROW_OFFSET STDCALL mysql_row_seek(MYSQL_RES *result, 00529 MYSQL_ROW_OFFSET offset); 00530 MYSQL_FIELD_OFFSET STDCALL mysql_field_seek(MYSQL_RES *result, 00531 MYSQL_FIELD_OFFSET offset); 00532 MYSQL_ROW STDCALL mysql_fetch_row(MYSQL_RES *result); 00533 unsigned long * STDCALL mysql_fetch_lengths(MYSQL_RES *result); 00534 MYSQL_FIELD * STDCALL mysql_fetch_field(MYSQL_RES *result); 00535 MYSQL_RES * STDCALL mysql_list_fields(MYSQL *mysql, const char *table, 00536 const char *wild); 00537 unsigned long STDCALL mysql_escape_string(char *to,const char *from, 00538 unsigned long from_length); 00539 unsigned long STDCALL mysql_hex_string(char *to,const char *from, 00540 unsigned long from_length); 00541 unsigned long STDCALL mysql_real_escape_string(MYSQL *mysql, 00542 char *to,const char *from, 00543 unsigned long length); 00544 void STDCALL mysql_debug(const char *debug); 00545 char * STDCALL mysql_odbc_escape_string(MYSQL *mysql, 00546 char *to, 00547 unsigned long to_length, 00548 const char *from, 00549 unsigned long from_length, 00550 void *param, 00551 char * 00552 (*extend_buffer) 00553 (void *, char *to, 00554 unsigned long *length)); 00555 void STDCALL myodbc_remove_escape(MYSQL *mysql,char *name); 00556 unsigned int STDCALL mysql_thread_safe(void); 00557 my_bool STDCALL mysql_embedded(void); 00558 MYSQL_MANAGER* STDCALL mysql_manager_init(MYSQL_MANAGER* con); 00559 MYSQL_MANAGER* STDCALL mysql_manager_connect(MYSQL_MANAGER* con, 00560 const char* host, 00561 const char* user, 00562 const char* passwd, 00563 unsigned int port); 00564 void STDCALL mysql_manager_close(MYSQL_MANAGER* con); 00565 int STDCALL mysql_manager_command(MYSQL_MANAGER* con, 00566 const char* cmd, int cmd_len); 00567 int STDCALL mysql_manager_fetch_line(MYSQL_MANAGER* con, 00568 char* res_buf, 00569 int res_buf_size); 00570 my_bool STDCALL mysql_read_query_result(MYSQL *mysql); 00571 00572 00573 /* 00574 The following definitions are added for the enhanced 00575 client-server protocol 00576 */ 00577 00578 /* statement state */ 00579 enum enum_mysql_stmt_state 00580 { 00581 MYSQL_STMT_INIT_DONE= 1, MYSQL_STMT_PREPARE_DONE, MYSQL_STMT_EXECUTE_DONE, 00582 MYSQL_STMT_FETCH_DONE 00583 }; 00584 00585 00586 /* 00587 This structure is used to define bind information, and 00588 internally by the client library. 00589 Public members with their descriptions are listed below 00590 (conventionally `On input' refers to the binds given to 00591 mysql_stmt_bind_param, `On output' refers to the binds given 00592 to mysql_stmt_bind_result): 00593 00594 buffer_type - One of the MYSQL_* types, used to describe 00595 the host language type of buffer. 00596 On output: if column type is different from 00597 buffer_type, column value is automatically converted 00598 to buffer_type before it is stored in the buffer. 00599 buffer - On input: points to the buffer with input data. 00600 On output: points to the buffer capable to store 00601 output data. 00602 The type of memory pointed by buffer must correspond 00603 to buffer_type. See the correspondence table in 00604 the comment to mysql_stmt_bind_param. 00605 00606 The two above members are mandatory for any kind of bind. 00607 00608 buffer_length - the length of the buffer. You don't have to set 00609 it for any fixed length buffer: float, double, 00610 int, etc. It must be set however for variable-length 00611 types, such as BLOBs or STRINGs. 00612 00613 length - On input: in case when lengths of input values 00614 are different for each execute, you can set this to 00615 point at a variable containining value length. This 00616 way the value length can be different in each execute. 00617 If length is not NULL, buffer_length is not used. 00618 Note, length can even point at buffer_length if 00619 you keep bind structures around while fetching: 00620 this way you can change buffer_length before 00621 each execution, everything will work ok. 00622 On output: if length is set, mysql_stmt_fetch will 00623 write column length into it. 00624 00625 is_null - On input: points to a boolean variable that should 00626 be set to TRUE for NULL values. 00627 This member is useful only if your data may be 00628 NULL in some but not all cases. 00629 If your data is never NULL, is_null should be set to 0. 00630 If your data is always NULL, set buffer_type 00631 to MYSQL_TYPE_NULL, and is_null will not be used. 00632 00633 is_unsigned - On input: used to signify that values provided for one 00634 of numeric types are unsigned. 00635 On output describes signedness of the output buffer. 00636 If, taking into account is_unsigned flag, column data 00637 is out of range of the output buffer, data for this column 00638 is regarded truncated. Note that this has no correspondence 00639 to the sign of result set column, if you need to find it out 00640 use mysql_stmt_result_metadata. 00641 error - where to write a truncation error if it is present. 00642 possible error value is: 00643 0 no truncation 00644 1 value is out of range or buffer is too small 00645 00646 Please note that MYSQL_BIND also has internals members. 00647 */ 00648 00649 typedef struct st_mysql_bind 00650 { 00651 unsigned long *length; /* output length pointer */ 00652 my_bool *is_null; /* Pointer to null indicator */ 00653 void *buffer; /* buffer to get/put data */ 00654 /* set this if you want to track data truncations happened during fetch */ 00655 my_bool *error; 00656 enum enum_field_types buffer_type; /* buffer type */ 00657 /* output buffer length, must be set when fetching str/binary */ 00658 unsigned long buffer_length; 00659 unsigned char *row_ptr; /* for the current data position */ 00660 unsigned long offset; /* offset position for char/binary fetch */ 00661 unsigned long length_value; /* Used if length is 0 */ 00662 unsigned int param_number; /* For null count and error messages */ 00663 unsigned int pack_length; /* Internal length for packed data */ 00664 my_bool error_value; /* used if error is 0 */ 00665 my_bool is_unsigned; /* set if integer type is unsigned */ 00666 my_bool long_data_used; /* If used with mysql_send_long_data */ 00667 my_bool is_null_value; /* Used if is_null is 0 */ 00668 void (*store_param_func)(NET *net, struct st_mysql_bind *param); 00669 void (*fetch_result)(struct st_mysql_bind *, MYSQL_FIELD *, 00670 unsigned char **row); 00671 void (*skip_result)(struct st_mysql_bind *, MYSQL_FIELD *, 00672 unsigned char **row); 00673 } MYSQL_BIND; 00674 00675 00676 /* statement handler */ 00677 typedef struct st_mysql_stmt 00678 { 00679 MEM_ROOT mem_root; /* root allocations */ 00680 LIST list; /* list to keep track of all stmts */ 00681 MYSQL *mysql; /* connection handle */ 00682 MYSQL_BIND *params; /* input parameters */ 00683 MYSQL_BIND *bind; /* output parameters */ 00684 MYSQL_FIELD *fields; /* result set metadata */ 00685 MYSQL_DATA result; /* cached result set */ 00686 MYSQL_ROWS *data_cursor; /* current row in cached result */ 00687 /* copy of mysql->affected_rows after statement execution */ 00688 my_ulonglong affected_rows; 00689 my_ulonglong insert_id; /* copy of mysql->insert_id */ 00690 /* 00691 mysql_stmt_fetch() calls this function to fetch one row (it's different 00692 for buffered, unbuffered and cursor fetch). 00693 */ 00694 int (*read_row_func)(struct st_mysql_stmt *stmt, 00695 unsigned char **row); 00696 unsigned long stmt_id; /* Id for prepared statement */ 00697 unsigned long flags; /* i.e. type of cursor to open */ 00698 unsigned long prefetch_rows; /* number of rows per one COM_FETCH */ 00699 /* 00700 Copied from mysql->server_status after execute/fetch to know 00701 server-side cursor status for this statement. 00702 */ 00703 unsigned int server_status; 00704 unsigned int last_errno; /* error code */ 00705 unsigned int param_count; /* input parameter count */ 00706 unsigned int field_count; /* number of columns in result set */ 00707 enum enum_mysql_stmt_state state; /* statement state */ 00708 char last_error[MYSQL_ERRMSG_SIZE]; /* error message */ 00709 char sqlstate[SQLSTATE_LENGTH+1]; 00710 /* Types of input parameters should be sent to server */ 00711 my_bool send_types_to_server; 00712 my_bool bind_param_done; /* input buffers were supplied */ 00713 unsigned char bind_result_done; /* output buffers were supplied */ 00714 /* mysql_stmt_close() had to cancel this result */ 00715 my_bool unbuffered_fetch_cancelled; 00716 /* 00717 Is set to true if we need to calculate field->max_length for 00718 metadata fields when doing mysql_stmt_store_result. 00719 */ 00720 my_bool update_max_length; 00721 } MYSQL_STMT; 00722 00723 enum enum_stmt_attr_type 00724 { 00725 /* 00726 When doing mysql_stmt_store_result calculate max_length attribute 00727 of statement metadata. This is to be consistent with the old API, 00728 where this was done automatically. 00729 In the new API we do that only by request because it slows down 00730 mysql_stmt_store_result sufficiently. 00731 */ 00732 STMT_ATTR_UPDATE_MAX_LENGTH, 00733 /* 00734 unsigned long with combination of cursor flags (read only, for update, 00735 etc) 00736 */ 00737 STMT_ATTR_CURSOR_TYPE, 00738 /* 00739 Amount of rows to retrieve from server per one fetch if using cursors. 00740 Accepts unsigned long attribute in the range 1 - ulong_max 00741 */ 00742 STMT_ATTR_PREFETCH_ROWS 00743 }; 00744 00745 00746 typedef struct st_mysql_methods 00747 { 00748 my_bool (*read_query_result)(MYSQL *mysql); 00749 my_bool (*advanced_command)(MYSQL *mysql, 00750 enum enum_server_command command, 00751 const char *header, 00752 unsigned long header_length, 00753 const char *arg, 00754 unsigned long arg_length, 00755 my_bool skip_check, 00756 MYSQL_STMT *stmt); 00757 MYSQL_DATA *(*read_rows)(MYSQL *mysql,MYSQL_FIELD *mysql_fields, 00758 unsigned int fields); 00759 MYSQL_RES * (*use_result)(MYSQL *mysql); 00760 void (*fetch_lengths)(unsigned long *to, 00761 MYSQL_ROW column, unsigned int field_count); 00762 void (*flush_use_result)(MYSQL *mysql); 00763 #if !defined(MYSQL_SERVER) || defined(EMBEDDED_LIBRARY) 00764 MYSQL_FIELD * (*list_fields)(MYSQL *mysql); 00765 my_bool (*read_prepare_result)(MYSQL *mysql, MYSQL_STMT *stmt); 00766 int (*stmt_execute)(MYSQL_STMT *stmt); 00767 int (*read_binary_rows)(MYSQL_STMT *stmt); 00768 int (*unbuffered_fetch)(MYSQL *mysql, char **row); 00769 void (*free_embedded_thd)(MYSQL *mysql); 00770 const char *(*read_statistics)(MYSQL *mysql); 00771 my_bool (*next_result)(MYSQL *mysql); 00772 int (*read_change_user_result)(MYSQL *mysql, char *buff, const char *passwd); 00773 int (*read_rows_from_cursor)(MYSQL_STMT *stmt); 00774 #endif 00775 } MYSQL_METHODS; 00776 00777 00778 MYSQL_STMT * STDCALL mysql_stmt_init(MYSQL *mysql); 00779 int STDCALL mysql_stmt_prepare(MYSQL_STMT *stmt, const char *query, 00780 unsigned long length); 00781 int STDCALL mysql_stmt_execute(MYSQL_STMT *stmt); 00782 int STDCALL mysql_stmt_fetch(MYSQL_STMT *stmt); 00783 int STDCALL mysql_stmt_fetch_column(MYSQL_STMT *stmt, MYSQL_BIND *bind, 00784 unsigned int column, 00785 unsigned long offset); 00786 int STDCALL mysql_stmt_store_result(MYSQL_STMT *stmt); 00787 unsigned long STDCALL mysql_stmt_param_count(MYSQL_STMT * stmt); 00788 my_bool STDCALL mysql_stmt_attr_set(MYSQL_STMT *stmt, 00789 enum enum_stmt_attr_type attr_type, 00790 const void *attr); 00791 my_bool STDCALL mysql_stmt_attr_get(MYSQL_STMT *stmt, 00792 enum enum_stmt_attr_type attr_type, 00793 void *attr); 00794 my_bool STDCALL mysql_stmt_bind_param(MYSQL_STMT * stmt, MYSQL_BIND * bnd); 00795 my_bool STDCALL mysql_stmt_bind_result(MYSQL_STMT * stmt, MYSQL_BIND * bnd); 00796 my_bool STDCALL mysql_stmt_close(MYSQL_STMT * stmt); 00797 my_bool STDCALL mysql_stmt_reset(MYSQL_STMT * stmt); 00798 my_bool STDCALL mysql_stmt_free_result(MYSQL_STMT *stmt); 00799 my_bool STDCALL mysql_stmt_send_long_data(MYSQL_STMT *stmt, 00800 unsigned int param_number, 00801 const char *data, 00802 unsigned long length); 00803 MYSQL_RES *STDCALL mysql_stmt_result_metadata(MYSQL_STMT *stmt); 00804 MYSQL_RES *STDCALL mysql_stmt_param_metadata(MYSQL_STMT *stmt); 00805 unsigned int STDCALL mysql_stmt_errno(MYSQL_STMT * stmt); 00806 const char *STDCALL mysql_stmt_error(MYSQL_STMT * stmt); 00807 const char *STDCALL mysql_stmt_sqlstate(MYSQL_STMT * stmt); 00808 MYSQL_ROW_OFFSET STDCALL mysql_stmt_row_seek(MYSQL_STMT *stmt, 00809 MYSQL_ROW_OFFSET offset); 00810 MYSQL_ROW_OFFSET STDCALL mysql_stmt_row_tell(MYSQL_STMT *stmt); 00811 void STDCALL mysql_stmt_data_seek(MYSQL_STMT *stmt, my_ulonglong offset); 00812 my_ulonglong STDCALL mysql_stmt_num_rows(MYSQL_STMT *stmt); 00813 my_ulonglong STDCALL mysql_stmt_affected_rows(MYSQL_STMT *stmt); 00814 my_ulonglong STDCALL mysql_stmt_insert_id(MYSQL_STMT *stmt); 00815 unsigned int STDCALL mysql_stmt_field_count(MYSQL_STMT *stmt); 00816 00817 my_bool STDCALL mysql_commit(MYSQL * mysql); 00818 my_bool STDCALL mysql_rollback(MYSQL * mysql); 00819 my_bool STDCALL mysql_autocommit(MYSQL * mysql, my_bool auto_mode); 00820 my_bool STDCALL mysql_more_results(MYSQL *mysql); 00821 int STDCALL mysql_next_result(MYSQL *mysql); 00822 void STDCALL mysql_close(MYSQL *sock); 00823 00824 00825 /* status return codes */ 00826 #define MYSQL_NO_DATA 100 00827 #define MYSQL_DATA_TRUNCATED 101 00828 00829 #define mysql_reload(mysql) mysql_refresh((mysql),REFRESH_GRANT) 00830 00831 #ifdef USE_OLD_FUNCTIONS 00832 MYSQL * STDCALL mysql_connect(MYSQL *mysql, const char *host, 00833 const char *user, const char *passwd); 00834 int STDCALL mysql_create_db(MYSQL *mysql, const char *DB); 00835 int STDCALL mysql_drop_db(MYSQL *mysql, const char *DB); 00836 #define mysql_reload(mysql) mysql_refresh((mysql),REFRESH_GRANT) 00837 #endif 00838 #define HAVE_MYSQL_REAL_CONNECT 00839 00840 /* 00841 The following functions are mainly exported because of mysqlbinlog; 00842 They are not for general usage 00843 */ 00844 00845 #define simple_command(mysql, command, arg, length, skip_check) \ 00846 (*(mysql)->methods->advanced_command)(mysql, command, NullS, \ 00847 0, arg, length, skip_check, NULL) 00848 #define stmt_command(mysql, command, arg, length, stmt) \ 00849 (*(mysql)->methods->advanced_command)(mysql, command, NullS, \ 00850 0, arg, length, 1, stmt) 00851 00852 #ifdef __NETWARE__ 00853 #pragma pack(pop) /* restore alignment */ 00854 #endif 00855 00856 #ifdef __cplusplus 00857 } 00858 #endif 00859 00860 #endif /* _mysql_h */
1.4.7

