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