diff options
Diffstat (limited to 'include')
33 files changed, 1623 insertions, 433 deletions
diff --git a/include/Makefile.am b/include/Makefile.am index 4b881d0e7ed..2ec06d71fbe 100644 --- a/include/Makefile.am +++ b/include/Makefile.am @@ -16,19 +16,21 @@ # MA 02111-1307, USA BUILT_SOURCES = mysql_version.h m_ctype.h my_config.h -pkginclude_HEADERS = my_dbug.h m_string.h my_sys.h my_list.h \ +pkginclude_HEADERS = my_dbug.h m_string.h my_sys.h my_list.h my_xml.h \ mysql.h mysql_com.h mysqld_error.h mysql_embed.h \ my_semaphore.h my_pthread.h my_no_pthread.h raid.h \ errmsg.h my_global.h my_net.h my_alloc.h \ - my_getopt.h sslopt-longopts.h my_dir.h \ - sslopt-vars.h sslopt-case.h $(BUILT_SOURCES) + my_getopt.h sslopt-longopts.h my_dir.h typelib.h \ + sslopt-vars.h sslopt-case.h sql_common.h \ + sql_state.h $(BUILT_SOURCES) noinst_HEADERS = config-win.h config-os2.h config-netware.h \ nisam.h heap.h merge.h my_bitmap.h\ myisam.h myisampack.h myisammrg.h ft_global.h\ mysys_err.h my_base.h \ my_nosys.h my_alarm.h queues.h rijndael.h sha1.h \ my_aes.h my_tree.h hash.h thr_alarm.h \ - thr_lock.h t_ctype.h violite.h md5.h mysql_version.h.in + thr_lock.h t_ctype.h violite.h md5.h \ + mysql_version.h.in my_handler.h # mysql_version.h are generated SUPERCLEANFILES = mysql_version.h my_config.h @@ -36,16 +38,25 @@ SUPERCLEANFILES = mysql_version.h my_config.h # Some include files that may be moved and patched by configure DISTCLEANFILES = sched.h $(SUPERCLEANFILES) +clean: + $(RM) -f readline/* +distclean: + $(RM) -f readline/* + all-local: my_config.h # Since we include my_config.h it better exist from the beginning link_sources: $(CP) ../config.h my_config.h + $(RM) -f readline/* + @readline_h_ln_cmd@ # Keep automake happy my_config.h: ../config.h $(CP) ../config.h my_config.h + $(RM) -f readline/* + @readline_h_ln_cmd@ # These files should not be included in distributions since they are # generated by configure from the .h.in files diff --git a/include/config-os2.h b/include/config-os2.h index 7e9684ae3f5..0402074acc0 100644 --- a/include/config-os2.h +++ b/include/config-os2.h @@ -463,6 +463,9 @@ typedef unsigned long long os_off_t; /* Define if you have the getwd function. */ #define HAVE_GETWD 1 +/* Define to 1 if you have the `gmtime_r' function. */ +#define HAVE_GMTIME_R 1 + /* Define if you have the index function. */ #define HAVE_INDEX 1 diff --git a/include/config-win.h b/include/config-win.h index 53dff5d63af..4fdbfbbd02f 100644 --- a/include/config-win.h +++ b/include/config-win.h @@ -16,6 +16,12 @@ /* Defines for Win32 to make it compatible for MySQL */ +#ifdef __WIN2000__ +/* We have to do this define before including windows.h to get the AWE API +functions */ +#define _WIN32_WINNT 0x0500 +#endif + #include <sys/locking.h> #include <windows.h> #include <math.h> /* Because of rint() */ @@ -23,6 +29,8 @@ #include <io.h> #include <malloc.h> +#define HAVE_SMEM 1 + #if defined(__NT__) #define SYSTEM_TYPE "NT" #elif defined(__WIN2000__) @@ -163,7 +171,9 @@ typedef uint rf_SetTimer; #define access(A,B) _access(A,B) #endif -#if defined(__cplusplus) +#if !defined(__cplusplus) +#define inline __inline +#endif /* __cplusplus */ inline double rint(double nr) { @@ -186,9 +196,6 @@ inline double ulonglong2double(ulonglong value) } #define my_off_t2double(A) ulonglong2double(A) #endif /* _WIN64 */ -#else -#define inline __inline -#endif /* __cplusplus */ #if SIZEOF_OFF_T > 4 #define lseek(A,B,C) _lseeki64((A),(longlong) (B),(C)) @@ -273,10 +280,10 @@ inline double ulonglong2double(ulonglong value) #define HAVE_CREATESEMAPHORE #define HAVE_ISNAN #define HAVE_FINITE -#define HAVE_ISAM /* We want to have support for ISAM in 4.0 */ #define HAVE_QUERY_CACHE #define SPRINTF_RETURNS_INT #define HAVE_SETFILEPOINTER +#define HAVE_VIO #ifdef NOT_USED #define HAVE_SNPRINTF /* Gave link error */ @@ -328,3 +335,8 @@ inline double ulonglong2double(ulonglong value) #define statistic_add(V,C,L) (V)+=(C) #endif #define statistic_increment(V,L) thread_safe_increment((V),(L)) + +#define shared_memory_buffer_length 16000 +#define default_shared_memory_base_name "MYSQL" +#define MYSQL_DEFAULT_CHARSET_NAME "latin1" +#define MYSQL_DEFAULT_COLLATION_NAME "latin1_swedish_ci" diff --git a/include/errmsg.h b/include/errmsg.h index 5136af5b87a..a354c125e36 100644 --- a/include/errmsg.h +++ b/include/errmsg.h @@ -30,7 +30,7 @@ extern const char *client_errors[]; /* Error messages */ #define CR_MAX_ERROR 2999 #if defined(OS2) && defined(MYSQL_SERVER) #define CER(X) client_errors[(X)-CR_MIN_ERROR] -#else +#elif !defined(ER) #define ER(X) client_errors[(X)-CR_MIN_ERROR] #endif #define CLIENT_ERRMAP 2 /* Errormap used by my_error() */ @@ -64,3 +64,26 @@ extern const char *client_errors[]; /* Error messages */ #define CR_SSL_CONNECTION_ERROR 2026 #define CR_MALFORMED_PACKET 2027 +/* new 4.1 error codes */ +#define CR_NULL_POINTER 2028 +#define CR_NO_PREPARE_STMT 2029 +#define CR_NOT_ALL_PARAMS_BOUND 2030 +#define CR_DATA_TRUNCATED 2031 +#define CR_NO_PARAMETERS_EXISTS 2032 +#define CR_INVALID_PARAMETER_NO 2033 +#define CR_INVALID_BUFFER_USE 2034 +#define CR_UNSUPPORTED_PARAM_TYPE 2035 + +#define CR_SHARED_MEMORY_CONNECTION 2036 +#define CR_SHARED_MEMORY_CONNECT_REQUEST_ERROR 2037 +#define CR_SHARED_MEMORY_CONNECT_ANSWER_ERROR 2038 +#define CR_SHARED_MEMORY_CONNECT_FILE_MAP_ERROR 2039 +#define CR_SHARED_MEMORY_CONNECT_MAP_ERROR 2040 +#define CR_SHARED_MEMORY_FILE_MAP_ERROR 2041 +#define CR_SHARED_MEMORY_MAP_ERROR 2042 +#define CR_SHARED_MEMORY_EVENT_ERROR 2043 +#define CR_SHARED_MEMORY_CONNECT_ABANDODED_ERROR 2044 +#define CR_SHARED_MEMORY_CONNECT_SET_ERROR 2045 +#define CR_CONN_UNKNOW_PROTOCOL 2046 +#define CR_INVALID_CONN_HANDLE 2047 +#define CR_MYSQL_SERVER_INIT_MISSED 2048 diff --git a/include/ft_global.h b/include/ft_global.h index 9acdf6aaaf3..df6860109e4 100644 --- a/include/ft_global.h +++ b/include/ft_global.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2000 MySQL AB +/* Copyright (C) 2000-2003 MySQL AB This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -51,15 +51,18 @@ extern const char *ft_precompiled_stopwords[]; extern ulong ft_min_word_len; extern ulong ft_max_word_len; -extern ulong ft_max_word_len_for_sort; +extern ulong ft_query_expansion_limit; extern const char *ft_boolean_syntax; int ft_init_stopwords(void); void ft_free_stopwords(void); -#define FT_NL 0 -#define FT_BOOL 1 -FT_INFO *ft_init_search(uint,void *, uint, byte *, uint, my_bool); +#define FT_NL 0 +#define FT_BOOL 1 +#define FT_SORTED 2 +#define FT_EXPAND 4 /* query expansion */ + +FT_INFO *ft_init_search(uint,void *, uint, byte *, uint, byte *); #ifdef __cplusplus } diff --git a/include/hash.h b/include/hash.h index e9c8c73c05b..3c2ae32c70e 100644 --- a/include/hash.h +++ b/include/hash.h @@ -25,9 +25,6 @@ extern "C" { typedef byte *(*hash_get_key)(const byte *,uint*,my_bool); typedef void (*hash_free_key)(void *); - /* flags for hash_init */ -#define HASH_CASE_INSENSITIVE 1 - typedef struct st_hash_info { uint next; /* index to next key */ byte *data; /* data for current entry */ @@ -40,18 +37,19 @@ typedef struct st_hash { DYNAMIC_ARRAY array; /* Place for hash_keys */ hash_get_key get_key; void (*free)(void *); - uint (*calc_hashnr)(const byte *key,uint length); + CHARSET_INFO *charset; } HASH; -#define hash_init(A,B,C,D,E,F,G) _hash_init(A,B,C,D,E,F,G CALLER_INFO) -my_bool _hash_init(HASH *hash,uint default_array_elements, uint key_offset, - uint key_length, hash_get_key get_key, - void (*free_element)(void*), uint flags CALLER_INFO_PROTO); +#define hash_init(A,B,C,D,E,F,G,H) _hash_init(A,B,C,D,E,F,G, H CALLER_INFO) +my_bool _hash_init(HASH *hash, CHARSET_INFO *charset, + uint default_array_elements, uint key_offset, + uint key_length, hash_get_key get_key, + void (*free_element)(void*), uint flags CALLER_INFO_PROTO); void hash_free(HASH *tree); byte *hash_element(HASH *hash,uint idx); gptr hash_search(HASH *info,const byte *key,uint length); gptr hash_next(HASH *info,const byte *key,uint length); -my_bool hash_insert(HASH *info,const byte *data); +my_bool my_hash_insert(HASH *info,const byte *data); my_bool hash_delete(HASH *hash,byte *record); my_bool hash_update(HASH *hash,byte *record,byte *old_key,uint old_key_length); void hash_replace(HASH *hash, uint idx, byte *new_row); diff --git a/include/heap.h b/include/heap.h index 02b04e2b3ec..3702d88ac70 100644 --- a/include/heap.h +++ b/include/heap.h @@ -14,7 +14,7 @@ along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -/* This file should be included when using heap_database_funktions */ +/* This file should be included when using heap_database_functions */ /* Author: Michael Widenius */ #ifndef _heap_h @@ -31,6 +31,9 @@ extern "C" { #include <thr_lock.h> #endif +#include "my_handler.h" +#include "my_tree.h" + /* defines used by heap-funktions */ #define HP_MAX_LEVELS 4 /* 128^5 records is enough */ @@ -47,6 +50,7 @@ typedef struct st_heapinfo /* Struct from heap_info */ ulong index_length; uint reclength; /* Length of one record */ int errkey; + ulonglong auto_increment; } HEAPINFO; @@ -73,22 +77,22 @@ typedef struct st_heap_block /* The data is saved in blocks */ ulong last_allocated; /* Blocks allocated, used by keys */ } HP_BLOCK; -typedef struct st_hp_keyseg /* Key-portion */ -{ - uint start; /* Start of key in record (from 0) */ - uint length; /* Keylength */ - uint type; - uint null_bit; /* bit set in row+null_pos */ - uint null_pos; -} HP_KEYSEG; +struct st_heap_info; /* For referense */ typedef struct st_hp_keydef /* Key definition with open */ { uint flag; /* HA_NOSAME | HA_NULL_PART_KEY */ uint keysegs; /* Number of key-segment */ uint length; /* Length of key (automatic) */ - HP_KEYSEG *seg; + uint8 algorithm; /* HASH / BTREE */ + HA_KEYSEG *seg; HP_BLOCK block; /* Where keys are saved */ + TREE rb_tree; + int (*write_key)(struct st_heap_info *info, struct st_hp_keydef *keyinfo, + const byte *record, byte *recpos); + int (*delete_key)(struct st_heap_info *info, struct st_hp_keydef *keyinfo, + const byte *record, byte *recpos, int flag); + uint (*get_key_length)(struct st_hp_keydef *keydef, const byte *key); } HP_KEYDEF; typedef struct st_heap_share @@ -112,6 +116,9 @@ typedef struct st_heap_share #endif my_bool delete_on_close; LIST open_list; + uint auto_key; + uint auto_key_type; /* real type of the auto key segment */ + ulonglong auto_increment; } HP_SHARE; struct st_hp_hash_info; @@ -126,17 +133,27 @@ typedef struct st_heap_info int mode; /* Mode of file (READONLY..) */ uint opt_flag,update; byte *lastkey; /* Last used key with rkey */ + byte *recbuf; /* Record buffer for rb-tree keys */ + enum ha_rkey_function last_find_flag; + TREE_ELEMENT *parents[MAX_TREE_HEIGHT+1]; + TREE_ELEMENT **last_pos; + uint lastkey_len; #ifdef THREAD THR_LOCK_DATA lock; #endif LIST open_list; } HP_INFO; +typedef struct st_heap_create_info +{ + uint auto_key; + uint auto_key_type; + ulonglong auto_increment; +} HP_CREATE_INFO; + /* Prototypes for heap-functions */ -extern HP_INFO* heap_open(const char *name,int mode,uint keys, - HP_KEYDEF *keydef,uint reclength, - ulong max_records,ulong min_reloc); +extern HP_INFO *heap_open(const char *name, int mode); extern int heap_close(HP_INFO *info); extern int heap_write(HP_INFO *info,const byte *buff); extern int heap_update(HP_INFO *info,const byte *old,const byte *newdata); @@ -145,7 +162,9 @@ extern int heap_scan_init(HP_INFO *info); extern int heap_scan(register HP_INFO *info, byte *record); extern int heap_delete(HP_INFO *info,const byte *buff); extern int heap_info(HP_INFO *info,HEAPINFO *x,int flag); -extern int heap_create(const char *name); +extern int heap_create(const char *name, uint keys, HP_KEYDEF *keydef, + uint reclength, ulong max_records, ulong min_records, + HP_CREATE_INFO *create_info); extern int heap_delete_table(const char *name); extern int heap_extra(HP_INFO *info,enum ha_extra_function function); extern int heap_rename(const char *old_name,const char *new_name); @@ -153,10 +172,17 @@ extern int heap_panic(enum ha_panic_function flag); extern int heap_rsame(HP_INFO *info,byte *record,int inx); extern int heap_rnext(HP_INFO *info,byte *record); extern int heap_rprev(HP_INFO *info,byte *record); -extern int heap_rfirst(HP_INFO *info,byte *record); -extern int heap_rlast(HP_INFO *info,byte *record); +extern int heap_rfirst(HP_INFO *info,byte *record,int inx); +extern int heap_rlast(HP_INFO *info,byte *record,int inx); extern void heap_clear(HP_INFO *info); -extern int heap_rkey(HP_INFO *info,byte *record,int inx,const byte *key); +extern void heap_update_auto_increment(HP_INFO *info, const byte *record); +ha_rows hp_rb_records_in_range(HP_INFO *info, int inx, const byte *start_key, + uint start_key_len, + enum ha_rkey_function start_search_flag, + const byte *end_key, uint end_key_len, + enum ha_rkey_function end_search_flag); +int heap_rkey(HP_INFO *info, byte *record, int inx, const byte *key, + uint key_len, enum ha_rkey_function find_flag); extern gptr heap_find(HP_INFO *info,int inx,const byte *key); extern int heap_check_heap(HP_INFO *info, my_bool print_status); extern byte *heap_position(HP_INFO *info); diff --git a/include/m_ctype.h b/include/m_ctype.h index b3e50cec58f..e2b2f7f1668 100644 --- a/include/m_ctype.h +++ b/include/m_ctype.h @@ -26,68 +26,315 @@ extern "C" { #endif +#define MY_CS_NAME_SIZE 32 +#define MY_CS_CTYPE_TABLE_SIZE 257 +#define MY_CS_TO_LOWER_TABLE_SIZE 256 +#define MY_CS_TO_UPPER_TABLE_SIZE 256 +#define MY_CS_SORT_ORDER_TABLE_SIZE 256 +#define MY_CS_TO_UNI_TABLE_SIZE 256 + #define CHARSET_DIR "charsets/" +#define my_wc_t ulong + +typedef struct unicase_info_st +{ + uint16 toupper; + uint16 tolower; + uint16 sort; +} MY_UNICASE_INFO; + +#define MY_CS_ILSEQ 0 +#define MY_CS_ILUNI 0 +#define MY_CS_TOOSMALL -1 +#define MY_CS_TOOFEW(n) (-1-(n)) + +#define MY_SEQ_INTTAIL 1 +#define MY_SEQ_SPACES 2 + + /* My charsets_list flags */ +#define MY_NO_SETS 0 +#define MY_CS_COMPILED 1 /* compiled-in sets */ +#define MY_CS_CONFIG 2 /* sets that have a *.conf file */ +#define MY_CS_INDEX 4 /* sets listed in the Index file */ +#define MY_CS_LOADED 8 /* sets that are currently loaded */ +#define MY_CS_BINSORT 16 /* if binary sort order */ +#define MY_CS_PRIMARY 32 /* if primary collation */ +#define MY_CS_STRNXFRM 64 /* if strnxfrm is used for sort */ +#define MY_CS_UNICODE 128 /* is a charset is full unicode */ +#define MY_CS_NONTEXT 256 /* if a charset is not sprintf() compatible */ +#define MY_CS_AVAILABLE 512 /* If either compiled-in or loaded*/ + +#define MY_CHARSET_UNDEFINED 0 + + +typedef struct my_uni_idx_st +{ + uint16 from; + uint16 to; + uchar *tab; +} MY_UNI_IDX; + +typedef struct +{ + uint beg; + uint end; + uint mblen; +} my_match_t; + +enum my_lex_states +{ + MY_LEX_START, MY_LEX_CHAR, MY_LEX_IDENT, + MY_LEX_IDENT_SEP, MY_LEX_IDENT_START, + MY_LEX_REAL, MY_LEX_HEX_NUMBER, + MY_LEX_CMP_OP, MY_LEX_LONG_CMP_OP, MY_LEX_STRING, MY_LEX_COMMENT, MY_LEX_END, + MY_LEX_OPERATOR_OR_IDENT, MY_LEX_NUMBER_IDENT, MY_LEX_INT_OR_REAL, + MY_LEX_REAL_OR_POINT, MY_LEX_BOOL, MY_LEX_EOL, MY_LEX_ESCAPE, + MY_LEX_LONG_COMMENT, MY_LEX_END_LONG_COMMENT, MY_LEX_COLON, + MY_LEX_SET_VAR, MY_LEX_USER_END, MY_LEX_HOSTNAME, MY_LEX_SKIP, + MY_LEX_USER_VARIABLE_DELIMITER, MY_LEX_SYSTEM_VAR, + MY_LEX_IDENT_OR_KEYWORD, + MY_LEX_IDENT_OR_HEX, MY_LEX_IDENT_OR_BIN, MY_LEX_IDENT_OR_NCHAR, + MY_LEX_STRING_OR_DELIMITER +}; + +struct charset_info_st; + +typedef struct my_collation_handler_st +{ + /* Collation routines */ + int (*strnncoll)(struct charset_info_st *, + const uchar *, uint, const uchar *, uint); + int (*strnncollsp)(struct charset_info_st *, + const uchar *, uint, const uchar *, uint); + int (*strnxfrm)(struct charset_info_st *, + uchar *, uint, const uchar *, uint); + my_bool (*like_range)(struct charset_info_st *, + const char *s, uint s_length, + int w_prefix, int w_one, int w_many, + uint res_length, + char *min_str, char *max_str, + uint *min_len, uint *max_len); + int (*wildcmp)(struct charset_info_st *, + const char *str,const char *str_end, + const char *wildstr,const char *wildend, + int escape,int w_one, int w_many); + + int (*strcasecmp)(struct charset_info_st *, const char *, const char *); + + uint (*instr)(struct charset_info_st *, + const char *b, uint b_length, + const char *s, uint s_length, + my_match_t *match, uint nmatch); + + /* Hash calculation */ + void (*hash_sort)(struct charset_info_st *cs, const uchar *key, uint len, + ulong *nr1, ulong *nr2); +} MY_COLLATION_HANDLER; + +extern MY_COLLATION_HANDLER my_collation_mb_bin_handler; +extern MY_COLLATION_HANDLER my_collation_8bit_bin_handler; +extern MY_COLLATION_HANDLER my_collation_8bit_simple_ci_handler; + + +typedef struct my_charset_handler_st +{ + /* Multibyte routines */ + int (*ismbchar)(struct charset_info_st *, const char *, const char *); + int (*mbcharlen)(struct charset_info_st *, uint); + uint (*numchars)(struct charset_info_st *, const char *b, const char *e); + uint (*charpos)(struct charset_info_st *, const char *b, const char *e, uint pos); + uint (*lengthsp)(struct charset_info_st *, const char *ptr, uint length); + + /* Unicode convertion */ + int (*mb_wc)(struct charset_info_st *cs,my_wc_t *wc, + const unsigned char *s,const unsigned char *e); + int (*wc_mb)(struct charset_info_st *cs,my_wc_t wc, + unsigned char *s,unsigned char *e); + + /* Functions for case and sort convertion */ + void (*caseup_str)(struct charset_info_st *, char *); + void (*casedn_str)(struct charset_info_st *, char *); + void (*caseup)(struct charset_info_st *, char *, uint); + void (*casedn)(struct charset_info_st *, char *, uint); + + /* Charset dependant snprintf() */ + int (*snprintf)(struct charset_info_st *, char *to, uint n, const char *fmt, + ...); + int (*long10_to_str)(struct charset_info_st *, char *to, uint n, int radix, + long int val); + int (*longlong10_to_str)(struct charset_info_st *, char *to, uint n, + int radix, longlong val); + + void (*fill)(struct charset_info_st *, char *to, uint len, int fill); + + /* String-to-number convertion routines */ + long (*strntol)(struct charset_info_st *, const char *s, uint l, + int base, char **e, int *err); + ulong (*strntoul)(struct charset_info_st *, const char *s, uint l, + int base, char **e, int *err); + longlong (*strntoll)(struct charset_info_st *, const char *s, uint l, + int base, char **e, int *err); + ulonglong (*strntoull)(struct charset_info_st *, const char *s, uint l, + int base, char **e, int *err); + double (*strntod)(struct charset_info_st *, char *s, uint l, char **e, + int *err); + + ulong (*scan)(struct charset_info_st *, const char *b, const char *e, + int sq); +} MY_CHARSET_HANDLER; + +extern MY_CHARSET_HANDLER my_charset_8bit_handler; + + + typedef struct charset_info_st { - uint number; - const char *name; - uchar *ctype; - uchar *to_lower; - uchar *to_upper; - uchar *sort_order; - - uint strxfrm_multiply; - int (*strcoll)(const uchar *, const uchar *); - int (*strxfrm)(uchar *, const uchar *, int); - int (*strnncoll)(const uchar *, int, const uchar *, int); - int (*strnxfrm)(uchar *, const uchar *, int, int); - my_bool (*like_range)(const char *, uint, pchar, uint, - char *, char *, uint *, uint *); - - uint mbmaxlen; - int (*ismbchar)(const char *, const char *); - my_bool (*ismbhead)(uint); - int (*mbcharlen)(uint); + uint number; + uint primary_number; + uint binary_number; + uint state; + const char *csname; + const char *name; + const char *comment; + uchar *ctype; + uchar *to_lower; + uchar *to_upper; + uchar *sort_order; + uint16 *tab_to_uni; + MY_UNI_IDX *tab_from_uni; + uchar state_map[256]; + uchar ident_map[256]; + uint strxfrm_multiply; + uint mbmaxlen; + char max_sort_char; /* For LIKE optimization */ + + MY_CHARSET_HANDLER *cset; + MY_COLLATION_HANDLER *coll; + } CHARSET_INFO; -/* strings/ctype.c */ -extern CHARSET_INFO *default_charset_info; -extern CHARSET_INFO *find_compiled_charset(uint cs_number); -extern CHARSET_INFO *find_compiled_charset_by_name(const char *name); -extern CHARSET_INFO compiled_charsets[]; -extern uint compiled_charset_number(const char *name); -extern const char *compiled_charset_name(uint charset_number); -#define MY_CHARSET_UNDEFINED 0 -#define MY_CHARSET_CURRENT (default_charset_info->number) - -/* Don't include std ctype.h when this is included */ -#define _CTYPE_H -#define _CTYPE_H_ -#define _CTYPE_INCLUDED -#define __CTYPE_INCLUDED -#define _CTYPE_USING /* Don't put names in global namespace. */ - -/* Fix things, if ctype.h would have been included before */ -#undef toupper -#undef _toupper -#undef _tolower -#undef toupper -#undef tolower -#undef isalpha -#undef isupper -#undef islower -#undef isdigit -#undef isxdigit -#undef isalnum -#undef isspace -#undef ispunct -#undef isprint -#undef isgraph -#undef iscntrl -#undef isascii -#undef toascii +extern CHARSET_INFO my_charset_bin; +extern CHARSET_INFO my_charset_big5_chinese_ci; +extern CHARSET_INFO my_charset_big5_bin; +extern CHARSET_INFO my_charset_euckr_korean_ci; +extern CHARSET_INFO my_charset_euckr_bin; +extern CHARSET_INFO my_charset_gb2312_chinese_ci; +extern CHARSET_INFO my_charset_gb2312_bin; +extern CHARSET_INFO my_charset_gbk_chinese_ci; +extern CHARSET_INFO my_charset_gbk_bin; +extern CHARSET_INFO my_charset_latin1; +extern CHARSET_INFO my_charset_latin1_german2_ci; +extern CHARSET_INFO my_charset_latin1_bin; +extern CHARSET_INFO my_charset_latin2_czech_ci; +extern CHARSET_INFO my_charset_sjis_japanese_ci; +extern CHARSET_INFO my_charset_sjis_bin; +extern CHARSET_INFO my_charset_tis620_thai_ci; +extern CHARSET_INFO my_charset_tis620_bin; +extern CHARSET_INFO my_charset_ucs2_general_ci; +extern CHARSET_INFO my_charset_ucs2_bin; +extern CHARSET_INFO my_charset_ujis_japanese_ci; +extern CHARSET_INFO my_charset_ujis_bin; +extern CHARSET_INFO my_charset_utf8_general_ci; +extern CHARSET_INFO my_charset_utf8_bin; +extern CHARSET_INFO my_charset_cp1250_czech_ci; + + +/* declarations for simple charsets */ +extern int my_strnxfrm_simple(CHARSET_INFO *, uchar *, uint, const uchar *, + uint); +extern int my_strnncoll_simple(CHARSET_INFO *, const uchar *, uint, + const uchar *, uint); + +extern int my_strnncollsp_simple(CHARSET_INFO *, const uchar *, uint, + const uchar *, uint); + +extern void my_hash_sort_simple(CHARSET_INFO *cs, + const uchar *key, uint len, + ulong *nr1, ulong *nr2); + +extern uint my_lengthsp_8bit(CHARSET_INFO *cs, const char *ptr, uint length); + +extern uint my_instr_simple(struct charset_info_st *, + const char *b, uint b_length, + const char *s, uint s_length, + my_match_t *match, uint nmatch); + + +/* Functions for 8bit */ +extern void my_caseup_str_8bit(CHARSET_INFO *, char *); +extern void my_casedn_str_8bit(CHARSET_INFO *, char *); +extern void my_caseup_8bit(CHARSET_INFO *, char *, uint); +extern void my_casedn_8bit(CHARSET_INFO *, char *, uint); + +extern int my_strcasecmp_8bit(CHARSET_INFO * cs, const char *, const char *); + +int my_mb_wc_8bit(CHARSET_INFO *cs,my_wc_t *wc, const uchar *s,const uchar *e); +int my_wc_mb_8bit(CHARSET_INFO *cs,my_wc_t wc, uchar *s, uchar *e); + +ulong my_scan_8bit(CHARSET_INFO *cs, const char *b, const char *e, int sq); + +int my_snprintf_8bit(struct charset_info_st *, char *to, uint n, + const char *fmt, ...); + +long my_strntol_8bit(CHARSET_INFO *, const char *s, uint l, int base, + char **e, int *err); +ulong my_strntoul_8bit(CHARSET_INFO *, const char *s, uint l, int base, + char **e, int *err); +longlong my_strntoll_8bit(CHARSET_INFO *, const char *s, uint l, int base, + char **e, int *err); +ulonglong my_strntoull_8bit(CHARSET_INFO *, const char *s, uint l, int base, + char **e, int *err); +double my_strntod_8bit(CHARSET_INFO *, char *s, uint l,char **e, + int *err); +int my_long10_to_str_8bit(CHARSET_INFO *, char *to, uint l, int radix, + long int val); +int my_longlong10_to_str_8bit(CHARSET_INFO *, char *to, uint l, int radix, + longlong val); + +void my_fill_8bit(CHARSET_INFO *cs, char* to, uint l, int fill); + +my_bool my_like_range_simple(CHARSET_INFO *cs, + const char *ptr, uint ptr_length, + int escape, int w_one, int w_many, + uint res_length, + char *min_str, char *max_str, + uint *min_length, uint *max_length); + + +int my_wildcmp_8bit(CHARSET_INFO *, + const char *str,const char *str_end, + const char *wildstr,const char *wildend, + int escape, int w_one, int w_many); + +uint my_numchars_8bit(CHARSET_INFO *, const char *b, const char *e); +uint my_charpos_8bit(CHARSET_INFO *, const char *b, const char *e, uint pos); +int my_mbcharlen_8bit(CHARSET_INFO *, uint c); + + +/* Functions for multibyte charsets */ +extern void my_caseup_str_mb(CHARSET_INFO *, char *); +extern void my_casedn_str_mb(CHARSET_INFO *, char *); +extern void my_caseup_mb(CHARSET_INFO *, char *, uint); +extern void my_casedn_mb(CHARSET_INFO *, char *, uint); +extern int my_strcasecmp_mb(CHARSET_INFO * cs,const char *, const char *); + +int my_wildcmp_mb(CHARSET_INFO *, + const char *str,const char *str_end, + const char *wildstr,const char *wildend, + int escape, int w_one, int w_many); +uint my_numchars_mb(CHARSET_INFO *, const char *b, const char *e); +uint my_charpos_mb(CHARSET_INFO *, const char *b, const char *e, uint pos); +uint my_instr_mb(struct charset_info_st *, + const char *b, uint b_length, + const char *s, uint s_length, + my_match_t *match, uint nmatch); + + +extern my_bool my_parse_charset_xml(const char *bug, uint len, + int (*add)(CHARSET_INFO *cs)); + #define _U 01 /* Upper case */ #define _L 02 /* Lower case */ @@ -98,34 +345,13 @@ extern const char *compiled_charset_name(uint charset_number); #define _B 0100 /* Blank */ #define _X 0200 /* heXadecimal digit */ -#define my_ctype (default_charset_info->ctype) -#define my_to_upper (default_charset_info->to_upper) -#define my_to_lower (default_charset_info->to_lower) -#define my_sort_order (default_charset_info->sort_order) - -#define _toupper(c) (char) my_to_upper[(uchar) (c)] -#define _tolower(c) (char) my_to_lower[(uchar) (c)] -#define toupper(c) (char) my_to_upper[(uchar) (c)] -#define tolower(c) (char) my_to_lower[(uchar) (c)] - -#define isalpha(c) ((my_ctype+1)[(uchar) (c)] & (_U | _L)) -#define isupper(c) ((my_ctype+1)[(uchar) (c)] & _U) -#define islower(c) ((my_ctype+1)[(uchar) (c)] & _L) -#define isdigit(c) ((my_ctype+1)[(uchar) (c)] & _NMR) -#define isxdigit(c) ((my_ctype+1)[(uchar) (c)] & _X) -#define isalnum(c) ((my_ctype+1)[(uchar) (c)] & (_U | _L | _NMR)) -#define isspace(c) ((my_ctype+1)[(uchar) (c)] & _SPC) -#define ispunct(c) ((my_ctype+1)[(uchar) (c)] & _PNT) -#define isprint(c) ((my_ctype+1)[(uchar) (c)] & (_PNT | _U | _L | _NMR | _B)) -#define isgraph(c) ((my_ctype+1)[(uchar) (c)] & (_PNT | _U | _L | _NMR)) -#define iscntrl(c) ((my_ctype+1)[(uchar) (c)] & _CTR) -#define isascii(c) (!((c) & ~0177)) -#define toascii(c) ((c) & 0177) - -#ifdef ctype -#undef ctype -#endif /* ctype */ +#define my_isascii(c) (!((c) & ~0177)) +#define my_toascii(c) ((c) & 0177) +#define my_tocntrl(c) ((c) & 31) +#define my_toprint(c) ((c) | 64) +#define my_toupper(s,c) (char) ((s)->to_upper[(uchar) (c)]) +#define my_tolower(s,c) (char) ((s)->to_lower[(uchar) (c)]) #define my_isalpha(s, c) (((s)->ctype+1)[(uchar) (c)] & (_U | _L)) #define my_isupper(s, c) (((s)->ctype+1)[(uchar) (c)] & _U) #define my_islower(s, c) (((s)->ctype+1)[(uchar) (c)] & _L) @@ -138,25 +364,32 @@ extern const char *compiled_charset_name(uint charset_number); #define my_isgraph(s, c) (((s)->ctype+1)[(uchar) (c)] & (_PNT | _U | _L | _NMR)) #define my_iscntrl(s, c) (((s)->ctype+1)[(uchar) (c)] & _CTR) -#define use_strcoll(s) ((s)->strcoll != NULL) -#define MY_STRXFRM_MULTIPLY (default_charset_info->strxfrm_multiply) -#define my_strnxfrm(s, a, b, c, d) ((s)->strnxfrm((a), (b), (c), (d))) -#define my_strnncoll(s, a, b, c, d) ((s)->strnncoll((a), (b), (c), (d))) -#define my_strcoll(s, a, b) ((s)->strcoll((a), (b))) -#define my_like_range(s, a, b, c, d, e, f, g, h) \ - ((s)->like_range((a), (b), (c), (d), (e), (f), (g), (h))) +/* Some macros that should be cleaned up a little */ +#define my_isvar(s,c) (my_isalnum(s,c) || (c) == '_') +#define my_isvar_start(s,c) (my_isalpha(s,c) || (c) == '_') -#define use_mb(s) ((s)->ismbchar != NULL) -#define MBMAXLEN (default_charset_info->mbmaxlen) -#define my_ismbchar(s, a, b) ((s)->ismbchar((a), (b))) -#define my_ismbhead(s, a) ((s)->ismbhead((a))) -#define my_mbcharlen(s, a) ((s)->mbcharlen((a))) +#define use_strnxfrm(s) ((s)->state & MY_CS_STRNXFRM) +#define my_strnxfrm(s, a, b, c, d) ((s)->coll->strnxfrm((s), (a), (b), (c), (d))) +#define my_strnncoll(s, a, b, c, d) ((s)->coll->strnncoll((s), (a), (b), (c), (d))) +#define my_like_range(s, a, b, c, d, e, f, g, h, i, j) \ + ((s)->coll->like_range((s), (a), (b), (c), (d), (e), (f), (g), (h), (i), (j))) +#define my_wildcmp(cs,s,se,w,we,e,o,m) ((cs)->coll->wildcmp((cs),(s),(se),(w),(we),(e),(o),(m))) +#define my_strcasecmp(s, a, b) ((s)->coll->strcasecmp((s), (a), (b))) + +#define use_mb(s) ((s)->cset->ismbchar != NULL) +#define my_ismbchar(s, a, b) ((s)->cset->ismbchar((s), (a), (b))) +#define my_mbcharlen(s, a) ((s)->cset->mbcharlen((s),(a))) + +#define my_caseup(s, a, l) ((s)->cset->caseup((s), (a), (l))) +#define my_casedn(s, a, l) ((s)->cset->casedn((s), (a), (l))) +#define my_caseup_str(s, a) ((s)->cset->caseup_str((s), (a))) +#define my_casedn_str(s, a) ((s)->cset->casedn_str((s), (a))) +#define my_strntol(s, a, b, c, d, e) ((s)->cset->strntol((s),(a),(b),(c),(d),(e))) +#define my_strntoul(s, a, b, c, d, e) ((s)->cset->strntoul((s),(a),(b),(c),(d),(e))) +#define my_strntoll(s, a, b, c, d, e) ((s)->cset->strntoll((s),(a),(b),(c),(d),(e))) +#define my_strntoull(s, a, b, c,d, e) ((s)->cset->strntoull((s),(a),(b),(c),(d),(e))) +#define my_strntod(s, a, b, c, d) ((s)->cset->strntod((s),(a),(b),(c),(d))) -/* Some macros that should be cleaned up a little */ -#define isvar(c) (isalnum(c) || (c) == '_') -#define isvar_start(c) (isalpha(c) || (c) == '_') -#define tocntrl(c) ((c) & 31) -#define toprint(c) ((c) | 64) /* XXX: still need to take care of this one */ #ifdef MY_CHARSET_TIS620 diff --git a/include/m_string.h b/include/m_string.h index eac1552f8c1..d72342fb3c1 100644 --- a/include/m_string.h +++ b/include/m_string.h @@ -31,6 +31,9 @@ #include <string.h> #endif +/* need by my_vsnprintf */ +#include <stdarg.h> + /* Correct some things for UNIXWARE7 */ #ifdef HAVE_UNIXWARE7_THREADS #undef HAVE_STRINGS_H @@ -71,14 +74,14 @@ /* Unixware 7 */ #if !defined(HAVE_BFILL) # define bfill(A,B,C) memset((A),(C),(B)) -# define bmove_allign(A,B,C) memcpy((A),(B),(C)) +# define bmove_align(A,B,C) memcpy((A),(B),(C)) #endif #if !defined(HAVE_BCMP) # define bcopy(s, d, n) memcpy((d), (s), (n)) # define bcmp(A,B,C) memcmp((A),(B),(C)) # define bzero(A,B) memset((A),0,(B)) -# define bmove_allign(A,B,C) memcpy((A),(B),(C)) +# define bmove_align(A,B,C) memcpy((A),(B),(C)) #endif #if defined(__cplusplus) && !defined(OS2) @@ -108,11 +111,11 @@ extern char NEAR _dig_vec[]; /* Declared in int2str() */ #endif #ifdef MSDOS -#undef bmove_allign -#define bmove512(A,B,C) bmove_allign(A,B,C) +#undef bmove_align +#define bmove512(A,B,C) bmove_align(A,B,C) #define my_itoa(A,B,C) itoa(A,B,C) #define my_ltoa(A,B,C) ltoa(A,B,C) -extern void bmove_allign(gptr dst,const gptr src,uint len); +extern void bmove_align(gptr dst,const gptr src,uint len); #endif #if (!defined(USE_BMOVE512) || defined(HAVE_purify)) && !defined(bmove512) @@ -229,6 +232,7 @@ extern char *int2str(long val,char *dst,int radix); extern char *int10_to_str(long val,char *dst,int radix); extern char *str2int(const char *src,int radix,long lower,long upper, long *val); +longlong my_strtoll10(const char *nptr, char **endptr, int *error); #if SIZEOF_LONG == SIZEOF_LONG_LONG #define longlong2str(A,B,C) int2str((A),(B),(C)) #define longlong10_to_str(A,B,C) int10_to_str((A),(B),(C)) @@ -248,6 +252,12 @@ extern ulonglong strtoull(const char *str, char **ptr, int base); #endif #endif +/* my_vsnprintf.c */ + +extern int my_vsnprintf( char *str, size_t n, + const char *format, va_list ap ); +extern int my_snprintf(char* to, size_t n, const char* fmt, ...); + #if defined(__cplusplus) && !defined(OS2) } #endif diff --git a/include/my_base.h b/include/my_base.h index 91a248cd401..4c3e53c4573 100644 --- a/include/my_base.h +++ b/include/my_base.h @@ -46,32 +46,38 @@ #define HA_OPEN_DELAY_KEY_WRITE 8 /* Don't update index */ #define HA_OPEN_ABORT_IF_CRASHED 16 #define HA_OPEN_FOR_REPAIR 32 /* open even if crashed */ +#define HA_OPEN_TO_ASSIGN 64 /* Open for key cache assignment */ /* The following is parameter to ha_rkey() how to use key */ -/* We define a complete-field prefix of a key value as a prefix where the -last included field in the prefix contains the full field, not just some bytes -from the start of the field. A partial-field prefix is allowed to -contain only a few first bytes from the last included field. - -Below HA_READ_KEY_EXACT, ..., HA_READ_BEFORE_KEY can take a -complete-field prefix of a key value as the search key. HA_READ_PREFIX -and HA_READ_PREFIX_LAST could also take a partial-field prefix, but -currently (4.0.10) they are only used with complete-field prefixes. MySQL uses -a padding trick to implement LIKE 'abc%' queries. - -NOTE that in InnoDB HA_READ_PREFIX_LAST will NOT work with a partial-field -prefix because InnoDB currently strips spaces from the end of varchar -fields! */ +/* + We define a complete-field prefix of a key value as a prefix where + the last included field in the prefix contains the full field, not + just some bytes from the start of the field. A partial-field prefix + is allowed to contain only a few first bytes from the last included + field. + + Below HA_READ_KEY_EXACT, ..., HA_READ_BEFORE_KEY can take a + complete-field prefix of a key value as the search + key. HA_READ_PREFIX and HA_READ_PREFIX_LAST could also take a + partial-field prefix, but currently (4.0.10) they are only used with + complete-field prefixes. MySQL uses a padding trick to implement + LIKE 'abc%' queries. + + NOTE that in InnoDB HA_READ_PREFIX_LAST will NOT work with a + partial-field prefix because InnoDB currently strips spaces from the + end of varchar fields! +*/ enum ha_rkey_function { - HA_READ_KEY_EXACT, /* Find first record else error */ - HA_READ_KEY_OR_NEXT, /* Record or next record */ - HA_READ_KEY_OR_PREV, /* Record or previous */ - HA_READ_AFTER_KEY, /* Find next rec. after key-record */ - HA_READ_BEFORE_KEY, /* Find next rec. before key-record */ - HA_READ_PREFIX, /* Key which as same prefix */ - HA_READ_PREFIX_LAST, /* Last key with the same prefix */ + HA_READ_KEY_EXACT, /* Find first record else error */ + HA_READ_KEY_OR_NEXT, /* Record or next record */ + HA_READ_KEY_OR_PREV, /* Record or previous */ + HA_READ_AFTER_KEY, /* Find next rec. after key-record */ + HA_READ_BEFORE_KEY, /* Find next rec. before key-record */ + HA_READ_PREFIX, /* Key which as same prefix */ + HA_READ_PREFIX_LAST, /* Last key with the same prefix */ + HA_READ_PREFIX_LAST_OR_PREV, /* Last or prev key with the same prefix */ HA_READ_MBR_CONTAIN, HA_READ_MBR_INTERSECT, HA_READ_MBR_WITHIN, @@ -81,7 +87,7 @@ enum ha_rkey_function { /* Key algorithm types */ -enum ha_key_alg { +enum ha_key_alg { HA_KEY_ALG_UNDEF= 0, /* Not specified (old file) */ HA_KEY_ALG_BTREE= 1, /* B-tree, default one */ HA_KEY_ALG_RTREE= 2, /* R-tree, for spatial searches */ @@ -120,9 +126,14 @@ enum ha_extra_function { HA_EXTRA_RESET_STATE, /* Reset positions */ HA_EXTRA_IGNORE_DUP_KEY, /* Dup keys don't rollback everything*/ HA_EXTRA_NO_IGNORE_DUP_KEY, - HA_EXTRA_DONT_USE_CURSOR_TO_UPDATE, /* Cursor will not be used for update */ + HA_EXTRA_RETRIEVE_ALL_COLS, /* Instructs InnoDB to retrieve all + columns, not just those where + field->query_id is the same as the + current query id */ HA_EXTRA_PREPARE_FOR_DELETE, - HA_EXTRA_PREPARE_FOR_UPDATE /* Remove read cache if problems */ + HA_EXTRA_PREPARE_FOR_UPDATE, /* Remove read cache if problems */ + HA_EXTRA_PRELOAD_BUFFER_SIZE, /* Set buffer size for preloading */ + HA_EXTRA_SET_KEY_CACHE /* Set ref to assigned key cache */ }; /* The following is parameter to ha_panic() */ @@ -163,9 +174,9 @@ enum ha_base_keytype { #define HA_PACK_KEY 2 /* Pack string key to previous key */ #define HA_AUTO_KEY 16 #define HA_BINARY_PACK_KEY 32 /* Packing of all keys to prev key */ -#define HA_FULLTEXT 128 /* SerG: for full-text search */ +#define HA_FULLTEXT 128 /* For full-text search */ #define HA_UNIQUE_CHECK 256 /* Check the key for uniqueness */ -#define HA_SPATIAL 1024 /* Alex Barkov: for spatial search */ +#define HA_SPATIAL 1024 /* For spatial search */ #define HA_NULL_ARE_EQUAL 2048 /* NULL in key are cmp as equal */ @@ -215,7 +226,7 @@ enum ha_base_keytype { /* Bits in flag to _status */ #define HA_STATUS_POS 1 /* Return position */ -#define HA_STATUS_NO_LOCK 2 /* Don't use external lock */ +#define HA_STATUS_NO_LOCK 2 /* Don't use external lock */ #define HA_STATUS_TIME 4 /* Return update time */ #define HA_STATUS_CONST 8 /* Return constants values */ #define HA_STATUS_VARIABLE 16 @@ -256,6 +267,7 @@ enum ha_base_keytype { #define HA_ERR_NO_REFERENCED_ROW 151 /* Cannot add a child row */ #define HA_ERR_ROW_IS_REFERENCED 152 /* Cannot delete a parent row */ #define HA_ERR_NO_SAVEPOINT 153 /* No savepoint with that name */ +#define HA_ERR_NON_UNIQUE_BLOCK_SIZE 154 /* Non unique key block size */ /* Other constants */ @@ -289,7 +301,7 @@ enum ha_base_keytype { #define READ_CHECK_USED 4 #define KEY_READ_USED 8 #define WRITE_CACHE_USED 16 -#define OPT_NO_ROWS 32 +#define OPT_NO_ROWS 32 /* bits in update */ #define HA_STATE_CHANGED 1 /* Database has changed */ @@ -321,7 +333,7 @@ enum data_file_type { typedef my_off_t ha_rows; #else #define rows2double(A) (double) (A) -typedef ulong ha_rows; +typedef ulong ha_rows; #endif #define HA_POS_ERROR (~ (ha_rows) 0) diff --git a/include/my_bitmap.h b/include/my_bitmap.h index ca0037addfb..5b3da011f54 100644 --- a/include/my_bitmap.h +++ b/include/my_bitmap.h @@ -25,29 +25,36 @@ typedef struct st_bitmap { uchar *bitmap; uint bitmap_size; - my_bool thread_safe; /* set if several threads access the bitmap */ /* mutex will be acquired for the duration of each bitmap operation if - thread_safe flag is set. Otherwise, we optimize by not acquiring the - mutex + thread_safe flag in bitmap_init was set. Otherwise, we optimize by not + acquiring the mutex */ #ifdef THREAD - pthread_mutex_t mutex; + pthread_mutex_t *mutex; #endif } MY_BITMAP; #ifdef __cplusplus extern "C" { #endif - extern my_bool bitmap_init(MY_BITMAP *bitmap, uint bitmap_size, - my_bool thread_safe); - extern void bitmap_free(MY_BITMAP *bitmap); - extern void bitmap_set_bit(MY_BITMAP *bitmap, uint bitmap_bit); - extern uint bitmap_set_next(MY_BITMAP *bitmap); - extern void bitmap_set_all(MY_BITMAP* bitmap); - extern my_bool bitmap_is_set(MY_BITMAP* bitmap, uint bitmap_bit); - extern void bitmap_clear_all(MY_BITMAP* bitmap); - extern void bitmap_clear_bit(MY_BITMAP *bitmap, uint bitmap_bit); +extern my_bool bitmap_cmp(const MY_BITMAP *map1, const MY_BITMAP *map2); +extern my_bool bitmap_init(MY_BITMAP *map, uchar *buf, uint bitmap_size, my_bool thread_safe); +extern my_bool bitmap_is_clear_all(const MY_BITMAP *map); +extern my_bool bitmap_is_prefix(const MY_BITMAP *map, uint prefix_size); +extern my_bool bitmap_is_set(const MY_BITMAP *map, uint bitmap_bit); +extern my_bool bitmap_is_set_all(const MY_BITMAP *map); +extern my_bool bitmap_is_subset(const MY_BITMAP *map1, const MY_BITMAP *map2); +extern uint bitmap_set_next(MY_BITMAP *map); +extern void bitmap_clear_all(MY_BITMAP *map); +extern void bitmap_clear_bit(MY_BITMAP *map, uint bitmap_bit); +extern void bitmap_free(MY_BITMAP *map); +extern void bitmap_intersect(MY_BITMAP *map, const MY_BITMAP *map2); +extern void bitmap_set_all(MY_BITMAP *map); +extern void bitmap_set_bit(MY_BITMAP *map, uint bitmap_bit); +extern void bitmap_set_prefix(MY_BITMAP *map, uint prefix_size); +extern void bitmap_subtract(MY_BITMAP *map, const MY_BITMAP *map2); +extern void bitmap_union(MY_BITMAP *map, const MY_BITMAP *map2); #ifdef __cplusplus } #endif diff --git a/include/my_getopt.h b/include/my_getopt.h index 3b4551b445e..148238f8d1b 100644 --- a/include/my_getopt.h +++ b/include/my_getopt.h @@ -17,7 +17,12 @@ C_MODE_START enum get_opt_var_type { GET_NO_ARG, GET_BOOL, GET_INT, GET_UINT, GET_LONG, - GET_ULONG, GET_LL, GET_ULL, GET_STR, GET_STR_ALLOC }; + GET_ULONG, GET_LL, GET_ULL, GET_STR, GET_STR_ALLOC + }; + +#define GET_ASK_ADDR 128 +#define GET_TYPE_MASK 127 + enum get_opt_arg_type { NO_ARG, OPT_ARG, REQUIRED_ARG }; struct my_option @@ -48,6 +53,8 @@ extern int handle_options (int *argc, char ***argv, char *)); extern void my_print_help(const struct my_option *options); extern void my_print_variables(const struct my_option *options); +extern void my_getopt_register_get_addr(gptr* (*func_addr)(const char *, uint, + const struct my_option *)); ulonglong getopt_ull_limit_value(ulonglong num, const struct my_option *optp); my_bool getopt_compare_strings(const char *s, const char *t, uint length); diff --git a/include/my_global.h b/include/my_global.h index 349ac8ac82e..43cacf8fa65 100644 --- a/include/my_global.h +++ b/include/my_global.h @@ -114,6 +114,26 @@ #define __STDC_EXT__ 1 /* To get large file support on hpux */ #endif +#ifdef HPUX11 +/* + Fix warnings on HPUX11 + There is something really strange with HPUX11 include files as you get + error about wrongly declared symbols or missing defines if you don't + do the following: + */ +#if !defined(_XOPEN_SOURCE_EXTENDED) && ! defined(__cplusplus) +#define _XOPEN_SOURCE_EXTENDED 1 +#endif + +/* Fix type of socklen as this is depending on the above define */ +#undef SOCKET_SIZE_TYPE +#ifdef _XOPEN_SOURCE_EXTENDED +#define SOCKET_SIZE_TYPE socklen_t +#else +#define SOCKET_SIZE_TYPE int +#endif /* _XOPEN_SOURCE_EXTENDED */ +#endif /* HPUX11 */ + #if defined(THREAD) && !defined(__WIN__) && !defined(OS2) #ifndef _POSIX_PTHREAD_SEMANTICS #define _POSIX_PTHREAD_SEMANTICS /* We want posix threads */ @@ -538,6 +558,9 @@ typedef SOCKET_SIZE_TYPE size_socket; #define RECORD_CACHE_SIZE (uint) (64*1024-MALLOC_OVERHEAD) /* Typical key cash */ #define KEY_CACHE_SIZE (uint) (8*1024*1024-MALLOC_OVERHEAD) + /* Default size of a key cache block */ +#define KEY_CACHE_BLOCK_SIZE (uint) 1024 + /* Some things that this system doesn't have */ @@ -714,8 +737,13 @@ typedef long longlong; #endif #endif -/* typedef used for length of string; Should be unsigned! */ -typedef ulong size_str; +#if defined(NO_CLIENT_LONG_LONG) +typedef unsigned long my_ulonglong; +#elif defined (__WIN__) +typedef unsigned __int64 my_ulonglong; +#else +typedef unsigned long long my_ulonglong; +#endif #ifdef USE_RAID /* diff --git a/include/my_handler.h b/include/my_handler.h new file mode 100644 index 00000000000..618d1df1a6e --- /dev/null +++ b/include/my_handler.h @@ -0,0 +1,66 @@ +/* Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this library; if not, write to the Free + Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, + MA 02111-1307, USA */ + +#ifndef _my_handler_h +#define _my_handler_h + +#include "my_global.h" +#include "my_base.h" +#include "m_ctype.h" +#include "myisampack.h" + +typedef struct st_HA_KEYSEG /* Key-portion */ +{ + uint8 type; /* Type of key (for sort) */ + uint8 language; + uint8 null_bit; /* bitmask to test for NULL */ + uint8 bit_start,bit_end; /* if bit field */ + uint16 flag; + uint16 length; /* Keylength */ + uint32 start; /* Start of key in record */ + uint32 null_pos; /* position to NULL indicator */ + CHARSET_INFO *charset; +} HA_KEYSEG; + +#define get_key_length(length,key) \ +{ if ((uchar) *(key) != 255) \ + length= (uint) (uchar) *((key)++); \ + else \ + { length=mi_uint2korr((key)+1); (key)+=3; } \ +} + +#define get_key_length_rdonly(length,key) \ +{ if ((uchar) *(key) != 255) \ + length= ((uint) (uchar) *((key))); \ + else \ + { length=mi_uint2korr((key)+1); } \ +} + +#define get_key_pack_length(length,length_pack,key) \ +{ if ((uchar) *(key) != 255) \ + { length= (uint) (uchar) *((key)++); length_pack=1; }\ + else \ + { length=mi_uint2korr((key)+1); (key)+=3; length_pack=3; } \ +} + +extern int mi_compare_text(CHARSET_INFO *, uchar *, uint, uchar *, uint , + my_bool); +extern int ha_key_cmp(register HA_KEYSEG *keyseg, register uchar *a, + register uchar *b, uint key_length, uint nextflag, + uint *diff_pos); + +#endif /* _my_handler_h */ diff --git a/include/my_list.h b/include/my_list.h index 0f56d4c532b..789bbb50f97 100644 --- a/include/my_list.h +++ b/include/my_list.h @@ -32,8 +32,8 @@ extern LIST *list_add(LIST *root,LIST *element); extern LIST *list_delete(LIST *root,LIST *element); extern LIST *list_cons(void *data,LIST *root); extern LIST *list_reverse(LIST *root); -extern void list_free(LIST *root,pbool free_data); -extern uint list_length(LIST *list); +extern void list_free(LIST *root,unsigned int free_data); +extern unsigned int list_length(LIST *list); extern int list_walk(LIST *list,list_walk_action action,gptr argument); #define rest(a) ((a)->next) diff --git a/include/my_pthread.h b/include/my_pthread.h index 16a14ac5038..a4ea88b20f0 100644 --- a/include/my_pthread.h +++ b/include/my_pthread.h @@ -99,6 +99,8 @@ int pthread_attr_setstacksize(pthread_attr_t *connect_att,DWORD stack); int pthread_attr_setprio(pthread_attr_t *connect_att,int priority); int pthread_attr_destroy(pthread_attr_t *connect_att); struct tm *localtime_r(const time_t *timep,struct tm *tmp); +struct tm *gmtime_r(const time_t *timep,struct tm *tmp); + void pthread_exit(void *a); /* was #define pthread_exit(A) ExitThread(A)*/ @@ -275,6 +277,8 @@ extern int my_pthread_create_detached; #define USE_ALARM_THREAD #undef HAVE_LOCALTIME_R #define HAVE_LOCALTIME_R +#undef HAVE_GMTIME_R +#define HAVE_GMTIME_R #undef HAVE_PTHREAD_ATTR_SETSCOPE #define HAVE_PTHREAD_ATTR_SETSCOPE #undef HAVE_GETHOSTBYNAME_R_GLIBC2_STYLE /* If we are running linux */ @@ -375,6 +379,10 @@ void *my_pthread_getspecific_imp(pthread_key_t key); struct tm *localtime_r(const time_t *clock, struct tm *res); #endif +#ifndef HAVE_GMTIME_R +struct tm *gmtime_r(const time_t *clock, struct tm *res); +#endif + #ifdef HAVE_PTHREAD_CONDATTR_CREATE /* DCE threads on HPUX 10.20 */ #define pthread_condattr_init pthread_condattr_create @@ -623,7 +631,7 @@ extern int pthread_dummy(int); */ #define DEFAULT_THREAD_STACK (192*1024L) #else -#define DEFAULT_THREAD_STACK (192*1024L) +#define DEFAULT_THREAD_STACK (192*1024) #endif struct st_my_thread_var @@ -638,6 +646,8 @@ struct st_my_thread_var int cmp_length; int volatile abort; my_bool init; + struct st_my_thread_var *next,**prev; + void *opt_info; #ifndef DBUG_OFF gptr dbug; char name[THREAD_NAME_SIZE+1]; @@ -660,8 +670,6 @@ extern pthread_t shutdown_th, main_th, signal_th; #define thread_safe_increment(V,L) atomic_add(1,(atomic_t*) &V); #define thread_safe_add(V,C,L) atomic_add((C),(atomic_t*) &V); #define thread_safe_sub(V,C,L) atomic_sub((C),(atomic_t*) &V); -#define statistic_increment(V,L) thread_safe_increment((V),(L)) -#define statistic_add(V,C,L) thread_safe_add((V),(C),(L)) #else #define thread_safe_increment(V,L) \ pthread_mutex_lock((L)); (V)++; pthread_mutex_unlock((L)); @@ -669,6 +677,7 @@ extern pthread_t shutdown_th, main_th, signal_th; pthread_mutex_lock((L)); (V)+=(C); pthread_mutex_unlock((L)); #define thread_safe_sub(V,C,L) \ pthread_mutex_lock((L)); (V)-=(C); pthread_mutex_unlock((L)); +#endif /* HAVE_ATOMIC_ADD */ #ifdef SAFE_STATISTICS #define statistic_increment(V,L) thread_safe_increment((V),(L)) #define statistic_add(V,C,L) thread_safe_add((V),(C),(L)) @@ -676,7 +685,6 @@ extern pthread_t shutdown_th, main_th, signal_th; #define statistic_increment(V,L) (V)++ #define statistic_add(V,C,L) (V)+=(C) #endif /* SAFE_STATISTICS */ -#endif /* HAVE_ATOMIC_ADD */ #endif /* thread_safe_increment */ #ifdef __cplusplus diff --git a/include/my_sys.h b/include/my_sys.h index df8b9759e5d..6082b988822 100644 --- a/include/my_sys.h +++ b/include/my_sys.h @@ -37,6 +37,7 @@ extern int NEAR my_errno; /* Last error in mysys */ #endif #include <stdarg.h> +#include <typelib.h> #define MYSYS_PROGRAM_USES_CURSES() { error_handler_hook = my_message_curses; mysys_uses_curses=1; } #define MYSYS_PROGRAM_DONT_USE_CURSES() { error_handler_hook = my_message_no_curses; mysys_uses_curses=0;} @@ -106,26 +107,20 @@ extern int NEAR my_errno; /* Last error in mysys */ #define MY_SEEK_CUR 1 #define MY_SEEK_END 2 - /* My charsets_list flags */ -#define MY_NO_SETS 0 -#define MY_COMPILED_SETS 1 /* show compiled-in sets */ -#define MY_CONFIG_SETS 2 /* sets that have a *.conf file */ -#define MY_INDEX_SETS 4 /* all sets listed in the Index file */ -#define MY_LOADED_SETS 8 /* the sets that are currently loaded */ - /* Some constants */ #define MY_WAIT_FOR_USER_TO_FIX_PANIC 60 /* in seconds */ #define MY_WAIT_GIVE_USER_A_MESSAGE 10 /* Every 10 times of prev */ #define MIN_COMPRESS_LENGTH 50 /* Don't compress small bl. */ -#define DEFAULT_KEYCACHE_BLOCK_SIZE 1024 -#define MAX_KEYCACHE_BLOCK_SIZE 16384 /* root_alloc flags */ #define MY_KEEP_PREALLOC 1 #define MY_MARK_BLOCKS_FREE 2 /* move used to free list and reuse them */ - /* defines when allocating data */ + /* Internal error numbers (for assembler functions) */ +#define MY_ERRNO_EDOM 33 +#define MY_ERRNO_ERANGE 34 + /* defines when allocating data */ #ifdef SAFEMALLOC #define my_malloc(SZ,FLAG) _mymalloc((SZ), __FILE__, __LINE__, FLAG ) #define my_malloc_ci(SZ,FLAG) _mymalloc((SZ), sFile, uLine, FLAG ) @@ -208,21 +203,28 @@ extern int (*fatal_error_handler_hook)(uint my_err, const char *str, myf MyFlags); /* charsets */ -extern uint get_charset_number(const char *cs_name); +extern CHARSET_INFO *default_charset_info; +extern CHARSET_INFO *all_charsets[256]; +extern CHARSET_INFO compiled_charsets[]; + +extern uint get_charset_number(const char *cs_name, uint cs_flags); +extern uint get_collation_number(const char *name); extern const char *get_charset_name(uint cs_number); + extern CHARSET_INFO *get_charset(uint cs_number, myf flags); -extern my_bool set_default_charset(uint cs, myf flags); extern CHARSET_INFO *get_charset_by_name(const char *cs_name, myf flags); -extern my_bool set_default_charset_by_name(const char *cs_name, myf flags); +extern CHARSET_INFO *get_charset_by_csname(const char *cs_name, + uint cs_flags, myf my_flags); extern void free_charsets(void); -extern char *list_charsets(myf want_flags); /* my_free() this string... */ extern char *get_charsets_dir(char *buf); - +extern my_bool my_charset_same(CHARSET_INFO *cs1, CHARSET_INFO *cs2); +extern my_bool init_compiled_charsets(myf flags); +extern void add_compiled_collation(CHARSET_INFO *cs); /* statistics */ -extern ulong _my_cache_w_requests,_my_cache_write,_my_cache_r_requests, - _my_cache_read; -extern ulong _my_blocks_used,_my_blocks_changed; +extern ulong my_cache_w_requests, my_cache_write, my_cache_r_requests, + my_cache_read; +extern ulong my_blocks_used, my_blocks_changed; extern uint key_cache_block_size; extern ulong my_file_opened,my_stream_opened, my_tmp_file_created; extern my_bool key_cache_inited, my_init_done; @@ -255,12 +257,6 @@ typedef struct wild_file_pack /* Struct to hold info when selecting files */ my_string *wild; /* Pointer to wildcards */ } WF_PACK; -typedef struct st_typelib { /* Different types saved here */ - uint count; /* How many types */ - const char *name; /* Name of typelib */ - const char **type_names; -} TYPELIB; - enum cache_type { READ_CACHE,WRITE_CACHE, @@ -269,7 +265,8 @@ enum cache_type enum flush_type { - FLUSH_KEEP, FLUSH_RELEASE, FLUSH_IGNORE_CHANGED, FLUSH_FORCE_WRITE + FLUSH_KEEP, FLUSH_RELEASE, FLUSH_IGNORE_CHANGED, FLUSH_FORCE_WRITE, + FLUSH_REMOVE }; typedef struct st_record_cache /* Used when cacheing records */ @@ -301,6 +298,14 @@ extern struct my_file_info #endif } my_file_info[MY_NFILE]; +typedef struct st_my_tmpdir +{ + char **list; + uint cur, max; +#ifdef THREAD + pthread_mutex_t mutex; +#endif +} MY_TMPDIR; typedef struct st_dynamic_array { @@ -498,6 +503,46 @@ my_off_t my_b_append_tell(IO_CACHE* info); #define my_b_bytes_in_cache(info) (uint) (*(info)->current_end - \ *(info)->current_pos) +typedef uint32 ha_checksum; + +/* Pointer to a key cache data structure (see the key cache module) */ +typedef struct st_key_cache* KEY_CACHE_HANDLE; + +/* Key cache variable structure */ +/* + The structure contains the parameters of a key cache that can + be set and undated by regular set global statements. + It also contains read-only statistics parameters. + If the corresponding key cache data structure has been already + created the variable contains the key cache handle. + The variables are put into a named list called key_caches. + At present the variables are only added to this list. +*/ +typedef struct st_key_cache_var +{ + ulonglong buff_size; /* size the memory allocated for the cache */ + ulong block_size; /* size of the blocks in the key cache */ + ulong division_limit; /* min. percentage of warm blocks */ + ulong age_threshold; /* determines when hot block is downgraded */ + KEY_CACHE_HANDLE cache; /* handles for the current and registered */ + ulong blocks_used; /* number of currently used blocks */ + ulong blocks_changed; /* number of currently dirty blocks */ + ulong cache_w_requests; /* number of write requests (write hits) */ + ulong cache_write; /* number of writes from the cache to files */ + ulong cache_r_requests; /* number of read requests (read hits) */ + ulong cache_read; /* number of reads from files to the cache */ + int blocks; /* max number of blocks in the cache */ + struct st_key_cache_asmt *assign_list; /* list of assignments to the cache */ + int assignments; /* number of not completed assignments */ + void (*action)(void *); /* optional call back function */ + void *extra_info; /* ptr to extra info */ +} KEY_CACHE_VAR; + +#define DEFAULT_KEY_CACHE_NAME "default" +extern KEY_CACHE_HANDLE *dflt_keycache; +extern KEY_CACHE_VAR dflt_key_cache_var; +#define DFLT_INIT_HITS 3 + #include <my_alloc.h> /* Prototypes for mysys and my_func functions */ @@ -510,6 +555,8 @@ extern int my_setwd(const char *dir,myf MyFlags); extern int my_lock(File fd,int op,my_off_t start, my_off_t length,myf MyFlags); extern gptr my_once_alloc(uint Size,myf MyFlags); extern void my_once_free(void); +extern char *my_once_strdup(const char *src,myf myflags); +extern char *my_once_memdup(const char *src, uint len, myf myflags); extern my_string my_tempnam(const char *dir,const char *pfx,myf MyFlags); extern File my_open(const char *FileName,int Flags,myf MyFlags); extern File my_register_filename(File fd, const char *FileName, @@ -558,6 +605,7 @@ extern char *_my_strdup_with_length(const byte *from, uint length, const char *sFile, uint uLine, myf MyFlag); + #ifndef TERMINATE extern void TERMINATE(FILE *file); #endif @@ -571,9 +619,6 @@ extern int my_error _VARARGS((int nr,myf MyFlags, ...)); extern int my_printf_error _VARARGS((uint my_err, const char *format, myf MyFlags, ...) __attribute__ ((format (printf, 2, 4)))); -extern int my_vsnprintf( char *str, size_t n, - const char *format, va_list ap ); -extern int my_snprintf(char* to, size_t n, const char* fmt, ...); extern int my_message(uint my_err, const char *str,myf MyFlags); extern int my_message_no_curses(uint my_err, const char *str,myf MyFlags); extern int my_message_curses(uint my_err, const char *str,myf MyFlags); @@ -591,12 +636,11 @@ extern void allow_break(void); #define allow_break() #endif +extern my_bool init_tmpdir(MY_TMPDIR *tmpdir, const char *pathlist); +extern char *my_tmpdir(MY_TMPDIR *tmpdir); +extern void free_tmpdir(MY_TMPDIR *tmpdir); + extern void my_remember_signal(int signal_number,sig_handler (*func)(int)); -extern void caseup(my_string str,uint length); -extern void casedn(my_string str,uint length); -extern void caseup_str(my_string str); -extern void casedn_str(my_string str); -extern void case_sort(my_string str,uint length); extern uint dirname_part(my_string to,const char *name); extern uint dirname_length(const char *name); #define base_name(A) (A+dirname_length(A)) @@ -620,19 +664,13 @@ extern my_string my_path(my_string to,const char *progname, const char *own_pathname_part); extern my_string my_load_path(my_string to, const char *path, const char *own_path_prefix); -extern int wild_compare(const char *str,const char *wildstr); -extern my_string my_strcasestr(const char *src,const char *suffix); -extern int my_strcasecmp(const char *s,const char *t); -extern int my_strsortcmp(const char *s,const char *t); -extern int my_casecmp(const char *s,const char *t,uint length); -extern int my_sortcmp(const char *s,const char *t,uint length); -extern int my_sortncmp(const char *s,uint s_len, const char *t,uint t_len); +extern int wild_compare(const char *str,const char *wildstr,pbool str_is_pattern); extern WF_PACK *wf_comp(my_string str); extern int wf_test(struct wild_file_pack *wf_pack,const char *name); extern void wf_end(struct wild_file_pack *buffer); extern size_s strip_sp(my_string str); extern void get_date(my_string to,int timeflag,time_t use_time); -extern void soundex(my_string out_pntr, my_string in_pntr,pbool remove_garbage); +extern void soundex(CHARSET_INFO *, my_string out_pntr, my_string in_pntr,pbool remove_garbage); extern int init_record_cache(RECORD_CACHE *info,uint cachesize,File file, uint reclength,enum cache_type type, pbool use_async_io); @@ -644,14 +682,26 @@ extern int flush_write_cache(RECORD_CACHE *info); extern long my_clock(void); extern sig_handler sigtstp_handler(int signal_number); extern void handle_recived_signals(void); -extern int init_key_cache(ulong use_mem); -extern int resize_key_cache(ulong use_mem); -extern byte *key_cache_read(File file,my_off_t filepos,byte* buff,uint length, +extern int init_key_cache(KEY_CACHE_HANDLE *pkeycache, + uint key_cache_block_size, + ulong use_mem, KEY_CACHE_VAR* env); +extern int resize_key_cache(KEY_CACHE_HANDLE *pkeycache, + uint key_cache_block_size, ulong use_mem); +extern void change_key_cache_param(KEY_CACHE_HANDLE keycache); +extern byte *key_cache_read(KEY_CACHE_HANDLE keycache, + File file, my_off_t filepos, int level, + byte* buff, uint length, uint block_length,int return_buffer); -extern int key_cache_write(File file,my_off_t filepos,byte* buff,uint length, +extern int key_cache_insert(KEY_CACHE_HANDLE keycache, + File file, my_off_t filepos, int level, + byte *buff, uint length); +extern int key_cache_write(KEY_CACHE_HANDLE keycache, + File file, my_off_t filepos, int level, + byte* buff, uint length, uint block_length,int force_write); -extern int flush_key_blocks(int file, enum flush_type type); -extern void end_key_cache(void); +extern int flush_key_blocks(KEY_CACHE_HANDLE keycache, + int file, enum flush_type type); +extern void end_key_cache(KEY_CACHE_HANDLE *pkeycache,my_bool cleanup); extern sig_handler my_set_alarm_variable(int signo); extern void my_string_ptr_sort(void *base,uint items,size_s size); extern void radixsort_for_str_ptr(uchar* base[], uint number_of_elements, @@ -715,10 +765,8 @@ extern void freeze_size(DYNAMIC_ARRAY *array); #define dynamic_array_ptr(array,array_index) ((array)->buffer+(array_index)*(array)->size_of_element) #define dynamic_element(array,array_index,type) ((type)((array)->buffer) +(array_index)) #define push_dynamic(A,B) insert_dynamic(A,B) +#define reset_dynamic(array) ((array)->elements= 0) -extern int find_type(my_string x,TYPELIB *typelib,uint full_name); -extern void make_type(my_string to,uint nr,TYPELIB *typelib); -extern const char *get_type(TYPELIB *typelib,uint nr); extern my_bool init_dynamic_string(DYNAMIC_STRING *str, const char *init_str, uint init_alloc,uint alloc_increment); extern my_bool dynstr_append(DYNAMIC_STRING *str, const char *append); @@ -750,10 +798,11 @@ extern void print_defaults(const char *conf_file, const char **groups); extern my_bool my_compress(byte *, ulong *, ulong *); extern my_bool my_uncompress(byte *, ulong *, ulong *); extern byte *my_compress_alloc(const byte *packet, ulong *len, ulong *complen); -extern ulong checksum(const byte *mem, uint count); +extern ha_checksum my_checksum(ha_checksum crc, const byte *mem, uint count); extern uint my_bit_log2(ulong value); -uint my_count_bits(ulonglong v); +extern uint my_count_bits(ulonglong v); extern void my_sleep(ulong m_seconds); +extern ulong crc32(ulong crc, const uchar *buf, uint len); #ifdef __WIN__ extern my_bool have_tcpip; /* Is set if tcpip is used */ diff --git a/include/my_tree.h b/include/my_tree.h index 7cc7c615ba6..0e705e19bba 100644 --- a/include/my_tree.h +++ b/include/my_tree.h @@ -20,13 +20,17 @@ extern "C" { #endif -#define MAX_TREE_HIGHT 40 /* = max 1048576 leafs in tree */ +#include "my_base.h" /* get 'enum ha_rkey_function' */ + +#define MAX_TREE_HEIGHT 40 /* = max 1048576 leafs in tree */ #define ELEMENT_KEY(tree,element)\ (tree->offset_to_key ? (void*)((byte*) element+tree->offset_to_key) :\ *((void**) (element+1))) #define tree_set_pointer(element,ptr) *((byte **) (element+1))=((byte*) (ptr)) +#define TREE_NO_DUPS 1 + typedef enum { left_root_right, right_root_left } TREE_WALK; typedef uint32 element_count; typedef int (*tree_walk_action)(void *,element_count,void *); @@ -48,15 +52,18 @@ typedef struct st_tree_element { } TREE_ELEMENT; #endif /* MSDOS */ +#define ELEMENT_CHILD(element, offs) (*(TREE_ELEMENT**)((char*)element + offs)) + typedef struct st_tree { TREE_ELEMENT *root,null_element; - TREE_ELEMENT **parents[MAX_TREE_HIGHT]; + TREE_ELEMENT **parents[MAX_TREE_HEIGHT]; uint offset_to_key,elements_in_tree,size_of_element,memory_limit,allocated; qsort_cmp2 compare; - void* custom_arg; + void *custom_arg; MEM_ROOT mem_root; my_bool with_delete; tree_element_free free; + uint flag; } TREE; /* Functions on whole tree */ @@ -70,11 +77,21 @@ void reset_tree(TREE*); #define is_tree_inited(tree) ((tree)->root != 0) /* Functions on leafs */ -TREE_ELEMENT *tree_insert(TREE *tree,void *key,uint key_size); -void *tree_search(TREE *tree,void *key); +TREE_ELEMENT *tree_insert(TREE *tree,void *key, uint key_size, + void *custom_arg); +void *tree_search(TREE *tree, void *key, void *custom_arg); int tree_walk(TREE *tree,tree_walk_action action, void *argument, TREE_WALK visit); -int tree_delete(TREE *tree,void *key); +int tree_delete(TREE *tree, void *key, void *custom_arg); +void *tree_search_key(TREE *tree, const void *key, + TREE_ELEMENT **parents, TREE_ELEMENT ***last_pos, + enum ha_rkey_function flag, void *custom_arg); +void *tree_search_edge(TREE *tree, TREE_ELEMENT **parents, + TREE_ELEMENT ***last_pos, int child_offs); +void *tree_search_next(TREE *tree, TREE_ELEMENT ***last_pos, int l_offs, + int r_offs); +ha_rows tree_record_pos(TREE *tree, const void *key, + enum ha_rkey_function search_flag, void *custom_arg); #define TREE_ELEMENT_EXTRA_SIZE (sizeof(TREE_ELEMENT) + sizeof(void*)) diff --git a/include/my_xml.h b/include/my_xml.h new file mode 100644 index 00000000000..82de995e700 --- /dev/null +++ b/include/my_xml.h @@ -0,0 +1,67 @@ +/* Copyright (C) 2000 MySQL AB + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ + + +#ifndef _my_xml_h +#define _my_xml_h + +#ifdef __cplusplus +extern "C" { +#endif + + +#define MY_XML_OK 0 +#define MY_XML_ERROR 1 + +typedef struct xml_stack_st +{ + char errstr[128]; + char attr[128]; + char *attrend; + const char *beg; + const char *cur; + const char *end; + void *user_data; + int (*enter)(struct xml_stack_st *st,const char *val, uint len); + int (*value)(struct xml_stack_st *st,const char *val, uint len); + int (*leave_xml)(struct xml_stack_st *st,const char *val, uint len); +} MY_XML_PARSER; + +void my_xml_parser_create(MY_XML_PARSER *st); +void my_xml_parser_free(MY_XML_PARSER *st); +int my_xml_parse(MY_XML_PARSER *st,const char *str, uint len); + +void my_xml_set_value_handler(MY_XML_PARSER *st, int (*)(MY_XML_PARSER *, + const char *, + uint len)); +void my_xml_set_enter_handler(MY_XML_PARSER *st, int (*)(MY_XML_PARSER *, + const char *, + uint len)); +void my_xml_set_leave_handler(MY_XML_PARSER *st, int (*)(MY_XML_PARSER *, + const char *, + uint len)); +void my_xml_set_user_data(MY_XML_PARSER *st, void *); + +uint my_xml_error_pos(MY_XML_PARSER *st); +uint my_xml_error_lineno(MY_XML_PARSER *st); + +const char *my_xml_error_string(MY_XML_PARSER *st); + +#ifdef __cplusplus +} +#endif + +#endif /* _my_xml_h */ diff --git a/include/myisam.h b/include/myisam.h index 11dae5f59ba..bf28168b7d7 100644 --- a/include/myisam.h +++ b/include/myisam.h @@ -28,6 +28,7 @@ extern "C" { #ifndef _m_ctype_h #include <m_ctype.h> #endif +#include "my_handler.h" /* defines used by myisam-funktions */ @@ -52,8 +53,6 @@ extern "C" { #define mi_portable_sizeof_char_ptr 8 -typedef uint32 ha_checksum; - /* Param to/from mi_info */ typedef struct st_mi_isaminfo /* Struct from h_info */ @@ -106,20 +105,6 @@ typedef struct st_mi_create_info struct st_myisam_info; /* For referense */ typedef struct st_myisam_info MI_INFO; -typedef struct st_mi_keyseg /* Key-portion */ -{ - uint8 type; /* Type of key (for sort) */ - uint8 language; - uint8 null_bit; /* bitmask to test for NULL */ - uint8 bit_start,bit_end; /* if bit field */ - uint16 flag; - uint16 length; /* Keylength */ - uint32 start; /* Start of key in record */ - uint32 null_pos; /* position to NULL indicator */ - CHARSET_INFO *charset; -} MI_KEYSEG; - - struct st_mi_s_param; typedef struct st_mi_keydef /* Key definition with open & info */ @@ -136,7 +121,7 @@ typedef struct st_mi_keydef /* Key definition with open & info */ uint16 block_size; /* block_size (auto) */ uint32 version; /* For concurrent read/write */ - MI_KEYSEG *seg,*end; + HA_KEYSEG *seg,*end; int (*bin_search)(struct st_myisam_info *info,struct st_mi_keydef *keyinfo, uchar *page,uchar *key, uint key_len,uint comp_flag,uchar * *ret_pos, @@ -148,6 +133,8 @@ typedef struct st_mi_keydef /* Key definition with open & info */ struct st_mi_s_param *s_temp); void (*store_key)(struct st_mi_keydef *keyinfo, uchar *key_pos, struct st_mi_s_param *s_temp); + int (*ck_insert)(struct st_myisam_info *inf, uint k_nr, uchar *k, uint klen); + int (*ck_delete)(struct st_myisam_info *inf, uint k_nr, uchar *k, uint klen); } MI_KEYDEF; @@ -158,7 +145,7 @@ typedef struct st_unique_def /* Segment definition of unique */ uint16 keysegs; /* Number of key-segment */ uchar key; /* Mapped to which key */ uint8 null_are_equal; - MI_KEYSEG *seg,*end; + HA_KEYSEG *seg,*end; } MI_UNIQUEDEF; typedef struct st_mi_decode_tree /* Decode huff-table */ @@ -322,6 +309,7 @@ typedef struct st_sort_key_blocks /* Used when sorting */ int inited; } SORT_KEY_BLOCKS; + typedef struct st_mi_check_param { ulonglong auto_increment_value; @@ -340,7 +328,8 @@ typedef struct st_mi_check_param uint8 language; my_bool using_global_keycache, opt_lock_memory, opt_follow_links; my_bool retry_repair, force_sort, calc_checksum; - char temp_filename[FN_REFLEN],*isam_file_name,*tmpdir; + char temp_filename[FN_REFLEN],*isam_file_name; + MY_TMPDIR *tmpdir; int tmpfile_createflag; myf myf_rw; IO_CACHE read_cache; @@ -352,6 +341,12 @@ typedef struct st_mi_check_param char *op_name; } MI_CHECK; +typedef struct st_sort_ft_buf +{ + uchar *buf, *end; + int count; + uchar lastkey[MI_MAX_KEY_BUFF]; +} SORT_FT_BUF; typedef struct st_sort_info { @@ -364,7 +359,8 @@ typedef struct st_sort_info MI_CHECK *param; char *buff; SORT_KEY_BLOCKS *key_block,*key_block_end; - /* sync things*/ + SORT_FT_BUF *ft_buf; + /* sync things */ uint got_error, threads_running; #ifdef THREAD pthread_mutex_t mutex; @@ -372,33 +368,6 @@ typedef struct st_sort_info #endif } SORT_INFO; - -typedef struct st_mi_sort_param -{ -#ifdef THREAD - pthread_t thr; -#endif - IO_CACHE read_cache, tempfile, tempfile_for_exceptions; - DYNAMIC_ARRAY buffpek; - ulonglong unique[MI_MAX_KEY_SEG+1]; - my_off_t pos,max_pos,filepos,start_recpos; - uint key, key_length,real_key_length,sortbuff_size; - uint maxbuffers, keys, find_length, sort_keys_length; - my_bool fix_datafile, master; - MI_KEYDEF *keyinfo; - SORT_INFO *sort_info; - uchar **sort_keys; - byte *rec_buff; - void *wordlist, *wordptr; - char *record; - char *tmpdir; - int (*key_cmp)(struct st_mi_sort_param *, const void *, const void *); - int (*key_read)(struct st_mi_sort_param *,void *); - int (*key_write)(struct st_mi_sort_param *, const void *); - void (*lock_in_memory)(MI_CHECK *); -} MI_SORT_PARAM; - - /* functions in mi_check */ void myisamchk_init(MI_CHECK *param); int chk_status(MI_CHECK *param, MI_INFO *info); @@ -429,9 +398,7 @@ int filecopy(MI_CHECK *param, File to,File from,my_off_t start, my_off_t length, const char *type); int movepoint(MI_INFO *info,byte *record,my_off_t oldpos, my_off_t newpos, uint prot_key); -int sort_write_record(MI_SORT_PARAM *sort_param); int write_data_suffix(SORT_INFO *sort_info, my_bool fix_datafile); -int _create_index_by_sort(MI_SORT_PARAM *info,my_bool no_messages, ulong); int test_if_almost_full(MI_INFO *info); int recreate_table(MI_CHECK *param, MI_INFO **org_info, char *filename); void mi_disable_non_unique_index(MI_INFO *info, ha_rows rows); @@ -441,6 +408,10 @@ my_bool mi_test_if_sort_rep(MI_INFO *info, ha_rows rows, ulonglong key_map, int mi_init_bulk_insert(MI_INFO *info, ulong cache_size, ha_rows rows); void mi_flush_bulk_insert(MI_INFO *info, uint inx); void mi_end_bulk_insert(MI_INFO *info); +int mi_assign_to_keycache(MI_INFO *info, ulonglong key_map, + KEY_CACHE_VAR *key_cache, + pthread_mutex_t *assign_lock); +int mi_preload(MI_INFO *info, ulonglong key_map, my_bool ignore_leaves); #ifdef __cplusplus } diff --git a/include/myisammrg.h b/include/myisammrg.h index ea882450eef..8b09e1a9231 100644 --- a/include/myisammrg.h +++ b/include/myisammrg.h @@ -86,6 +86,7 @@ extern int myrg_rfirst(MYRG_INFO *file,byte *buf,int inx); extern int myrg_rlast(MYRG_INFO *file,byte *buf,int inx); extern int myrg_rnext(MYRG_INFO *file,byte *buf,int inx); extern int myrg_rprev(MYRG_INFO *file,byte *buf,int inx); +extern int myrg_rnext_same(MYRG_INFO *file,byte *buf); extern int myrg_rkey(MYRG_INFO *file,byte *buf,int inx,const byte *key, uint key_len, enum ha_rkey_function search_flag); extern int myrg_rrnd(MYRG_INFO *file,byte *buf,ulonglong pos); diff --git a/include/myisampack.h b/include/myisampack.h index 6004177cfb0..95793e2aaeb 100644 --- a/include/myisampack.h +++ b/include/myisampack.h @@ -214,7 +214,7 @@ #ifdef BIG_TABLES #define mi_rowstore(T,A) mi_int8store(T,A) -#define mi_rowkorr(T) mi_uint8korr(T) +#define mi_rowkorr(T) mi_uint8korr(T) #else #define mi_rowstore(T,A) { mi_int4store(T,0); mi_int4store(((T)+4),A); } #define mi_rowkorr(T) mi_uint4korr((T)+4) diff --git a/include/mysql.h b/include/mysql.h index 0c91266e19c..f44d515478c 100644 --- a/include/mysql.h +++ b/include/mysql.h @@ -56,6 +56,12 @@ typedef int my_socket; #include "mysql_com.h" #include "mysql_version.h" +#include "typelib.h" +#ifndef DBUG_OFF +#define CHECK_EXTRA_ARGUMENTS +#endif + +#include "my_list.h" /* for LISTs used in 'MYSQL' and 'MYSQL_STMT' */ extern unsigned int mysql_port; extern char *mysql_unix_port; @@ -75,21 +81,32 @@ extern char *mysql_unix_port; #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) typedef struct st_mysql_field { - char *name; /* Name of column */ - char *table; /* Table of column if column was a field */ - char *org_table; /* Org table name if table was an alias */ - char *db; /* Database for table */ - char *def; /* Default value (set by mysql_list_fields) */ - unsigned long length; /* Width of column */ - unsigned long max_length; /* Max width of selected set */ - unsigned int flags; /* Div flags */ - unsigned int decimals; /* Number of decimals in field */ - enum enum_field_types type; /* Type of field. Se mysql_com.h for types */ + char *name; /* Name of column */ + char *org_name; /* Original column name, if an alias */ + char *table; /* Table of column if column was a field */ + char *org_table; /* Org table name, if table was an alias */ + char *db; /* Database for table */ + char *catalog; /* Catalog for table */ + char *def; /* Default value (set by mysql_list_fields) */ + unsigned long length; /* Width of column */ + unsigned long max_length; /* Max width of selected set */ + unsigned int name_length; + unsigned int org_name_length; + unsigned int table_length; + unsigned int org_table_length; + unsigned int db_length; + unsigned int catalog_length; + unsigned int def_length; + unsigned int flags; /* Div flags */ + unsigned int decimals; /* Number of decimals in field */ + unsigned int charsetnr; /* Character set */ + enum enum_field_types type; /* Type of field. Se mysql_com.h for types */ } MYSQL_FIELD; typedef char **MYSQL_ROW; /* return data as array of strings */ typedef unsigned int MYSQL_FIELD_OFFSET; /* offset to current field */ +#ifndef _global_h #if defined(NO_CLIENT_LONG_LONG) typedef unsigned long my_ulonglong; #elif defined (__WIN__) @@ -97,6 +114,7 @@ typedef unsigned __int64 my_ulonglong; #else typedef unsigned long long my_ulonglong; #endif +#endif #define MYSQL_COUNT_ERROR (~(my_ulonglong) 0) @@ -114,18 +132,35 @@ typedef struct st_mysql_data { unsigned int fields; MYSQL_ROWS *data; MEM_ROOT alloc; +#if !defined(CHECK_EMBEDDED_DIFFERENCES) || defined(EMBEDDED_LIBRARY) + MYSQL_ROWS **prev_ptr; +#endif } MYSQL_DATA; +enum mysql_option +{ + MYSQL_OPT_CONNECT_TIMEOUT, MYSQL_OPT_COMPRESS, MYSQL_OPT_NAMED_PIPE, + MYSQL_INIT_COMMAND, MYSQL_READ_DEFAULT_FILE, MYSQL_READ_DEFAULT_GROUP, + MYSQL_SET_CHARSET_DIR, MYSQL_SET_CHARSET_NAME, MYSQL_OPT_LOCAL_INFILE, + MYSQL_OPT_PROTOCOL, MYSQL_SHARED_MEMORY_BASE_NAME, MYSQL_OPT_READ_TIMEOUT, + MYSQL_OPT_WRITE_TIMEOUT, MYSQL_OPT_USE_RESULT, + MYSQL_OPT_USE_REMOTE_CONNECTION, MYSQL_OPT_USE_EMBEDDED_CONNECTION, + MYSQL_OPT_GUESS_CONNECTION, MYSQL_SET_CLIENT_IP +}; + struct st_mysql_options { - unsigned int connect_timeout,client_flag; - unsigned int port; - char *host,*init_command,*user,*password,*unix_socket,*db; + unsigned int connect_timeout, read_timeout, write_timeout; + unsigned int port, protocol; + unsigned long client_flag; + char *host,*user,*password,*unix_socket,*db; + struct st_dynamic_array *init_commands; char *my_cnf_file,*my_cnf_group, *charset_dir, *charset_name; char *ssl_key; /* PEM key file */ char *ssl_cert; /* PEM cert file */ char *ssl_ca; /* PEM CA file */ char *ssl_capath; /* PEM directory of CA-s? */ char *ssl_cipher; /* cipher to use */ + char *shared_memory_base_name; unsigned long max_allowed_packet; my_bool use_ssl; /* if to use SSL or not */ my_bool compress,named_pipe; @@ -144,31 +179,41 @@ struct st_mysql_options { a read that is replication-aware */ my_bool no_master_reads; +#if !defined(CHECK_EMBEDDED_DIFFERENCES) || defined(EMBEDDED_LIBRARY) + my_bool separate_thread; +#endif + enum mysql_option methods_to_use; + char *client_ip; }; -enum mysql_option { MYSQL_OPT_CONNECT_TIMEOUT, MYSQL_OPT_COMPRESS, - MYSQL_OPT_NAMED_PIPE, MYSQL_INIT_COMMAND, - MYSQL_READ_DEFAULT_FILE, MYSQL_READ_DEFAULT_GROUP, - MYSQL_SET_CHARSET_DIR, MYSQL_SET_CHARSET_NAME, - MYSQL_OPT_LOCAL_INFILE}; - -enum mysql_status { MYSQL_STATUS_READY,MYSQL_STATUS_GET_RESULT, - MYSQL_STATUS_USE_RESULT}; +enum mysql_status +{ + MYSQL_STATUS_READY,MYSQL_STATUS_GET_RESULT,MYSQL_STATUS_USE_RESULT +}; +enum mysql_protocol_type +{ + MYSQL_PROTOCOL_DEFAULT, MYSQL_PROTOCOL_TCP, MYSQL_PROTOCOL_SOCKET, + MYSQL_PROTOCOL_PIPE, MYSQL_PROTOCOL_MEMORY +}; /* There are three types of queries - the ones that have to go to the master, the ones that go to a slave, and the adminstrative type which must happen on the pivot connectioin */ -enum mysql_rpl_type { MYSQL_RPL_MASTER, MYSQL_RPL_SLAVE, - MYSQL_RPL_ADMIN }; +enum mysql_rpl_type +{ + MYSQL_RPL_MASTER, MYSQL_RPL_SLAVE, MYSQL_RPL_ADMIN +}; +struct st_mysql_methods; -typedef struct st_mysql { +typedef struct st_mysql +{ NET net; /* Communication parameters */ gptr connector_fd; /* ConnectorFd for SSL */ - char *host,*user,*passwd,*unix_socket,*server_version,*host_info, - *info,*db; + char *host,*user,*passwd,*unix_socket,*server_version,*host_info,*info; + char *db; struct charset_info_st *charset; MYSQL_FIELD *fields; MEM_ROOT field_alloc; @@ -177,16 +222,20 @@ typedef struct st_mysql { my_ulonglong extra_info; /* Used by mysqlshow */ unsigned long thread_id; /* Id for connection in server */ unsigned long packet_length; - unsigned int port,client_flag,server_capabilities; + unsigned int port; + unsigned long client_flag,server_capabilities; unsigned int protocol_version; unsigned int field_count; unsigned int server_status; unsigned int server_language; + unsigned int warning_count; struct st_mysql_options options; enum mysql_status status; my_bool free_me; /* If free in mysql_close */ my_bool reconnect; /* set to 1 if automatic reconnect */ - char scramble_buff[9]; + + /* session-wide random string */ + char scramble[SCRAMBLE_LENGTH+1]; /* Set if this is the original connection, not a master or a slave we have @@ -202,8 +251,11 @@ typedef struct st_mysql { struct st_mysql* last_used_slave; /* needed for round-robin slave pick */ /* needed for send/read/store/use result to work correctly with replication */ struct st_mysql* last_used_con; -} MYSQL; + LIST *stmts; /* list of all statements */ + const struct st_mysql_methods *methods; + void *thd; +} MYSQL; typedef struct st_mysql_res { my_ulonglong row_count; @@ -217,6 +269,7 @@ typedef struct st_mysql_res { MYSQL_ROW row; /* If unbuffered read */ MYSQL_ROW current_row; /* buffer to current row */ my_bool eof; /* Used by mysql_fetch_row */ + const struct st_mysql_methods *methods; } MYSQL_RES; #define MAX_MYSQL_MANAGER_ERR 256 @@ -228,6 +281,10 @@ typedef struct st_mysql_res { #define MANAGER_CLIENT_ERR 450 #define MANAGER_INTERNAL_ERR 500 +#if !defined(MYSQL_SERVER) && !defined(MYSQL_CLIENT) +#define MYSQL_CLIENT +#endif + typedef struct st_mysql_manager @@ -280,12 +337,14 @@ my_ulonglong STDCALL mysql_affected_rows(MYSQL *mysql); my_ulonglong STDCALL mysql_insert_id(MYSQL *mysql); unsigned int STDCALL mysql_errno(MYSQL *mysql); const char * STDCALL mysql_error(MYSQL *mysql); +const char *STDCALL mysql_sqlstate(MYSQL *mysql); +unsigned int STDCALL mysql_warning_count(MYSQL *mysql); const char * STDCALL mysql_info(MYSQL *mysql); unsigned long STDCALL mysql_thread_id(MYSQL *mysql); const char * STDCALL mysql_character_set_name(MYSQL *mysql); MYSQL * STDCALL mysql_init(MYSQL *mysql); -int STDCALL mysql_ssl_set(MYSQL *mysql, const char *key, +my_bool STDCALL mysql_ssl_set(MYSQL *mysql, const char *key, const char *cert, const char *ca, const char *capath, const char *cipher); my_bool STDCALL mysql_change_user(MYSQL *mysql, const char *user, @@ -296,25 +355,26 @@ MYSQL * STDCALL mysql_real_connect(MYSQL *mysql, const char *host, const char *db, unsigned int port, const char *unix_socket, - unsigned int clientflag); -void STDCALL mysql_close(MYSQL *sock); + unsigned long clientflag); int STDCALL mysql_select_db(MYSQL *mysql, const char *db); int STDCALL mysql_query(MYSQL *mysql, const char *q); int STDCALL mysql_send_query(MYSQL *mysql, const char *q, unsigned long length); -int STDCALL mysql_read_query_result(MYSQL *mysql); int STDCALL mysql_real_query(MYSQL *mysql, const char *q, unsigned long length); +MYSQL_RES * STDCALL mysql_store_result(MYSQL *mysql); +MYSQL_RES * STDCALL mysql_use_result(MYSQL *mysql); + /* perform query on master */ -int STDCALL mysql_master_query(MYSQL *mysql, const char *q, - unsigned long length); -int STDCALL mysql_master_send_query(MYSQL *mysql, const char *q, - unsigned long length); +my_bool STDCALL mysql_master_query(MYSQL *mysql, const char *q, + unsigned long length); +my_bool STDCALL mysql_master_send_query(MYSQL *mysql, const char *q, + unsigned long length); /* perform query on slave */ -int STDCALL mysql_slave_query(MYSQL *mysql, const char *q, - unsigned long length); -int STDCALL mysql_slave_send_query(MYSQL *mysql, const char *q, - unsigned long length); +my_bool STDCALL mysql_slave_query(MYSQL *mysql, const char *q, + unsigned long length); +my_bool STDCALL mysql_slave_send_query(MYSQL *mysql, const char *q, + unsigned long length); /* enable/disable parsing of all queries to decide if they go on master or @@ -329,12 +389,12 @@ int STDCALL mysql_rpl_parse_enabled(MYSQL* mysql); void STDCALL mysql_enable_reads_from_master(MYSQL* mysql); void STDCALL mysql_disable_reads_from_master(MYSQL* mysql); /* get the value of the master read flag */ -int STDCALL mysql_reads_from_master_enabled(MYSQL* mysql); +my_bool STDCALL mysql_reads_from_master_enabled(MYSQL* mysql); enum mysql_rpl_type STDCALL mysql_rpl_query_type(const char* q, int len); /* discover the master and its slaves */ -int STDCALL mysql_rpl_probe(MYSQL* mysql); +my_bool STDCALL mysql_rpl_probe(MYSQL* mysql); /* set the master, close/free the old one, if it is not a pivot */ int STDCALL mysql_set_master(MYSQL* mysql, const char* host, @@ -357,14 +417,11 @@ const char * STDCALL mysql_get_server_info(MYSQL *mysql); const char * STDCALL mysql_get_client_info(void); unsigned long STDCALL mysql_get_client_version(void); const char * STDCALL mysql_get_host_info(MYSQL *mysql); +unsigned long STDCALL mysql_get_server_version(MYSQL *mysql); unsigned int STDCALL mysql_get_proto_info(MYSQL *mysql); MYSQL_RES * STDCALL mysql_list_dbs(MYSQL *mysql,const char *wild); MYSQL_RES * STDCALL mysql_list_tables(MYSQL *mysql,const char *wild); -MYSQL_RES * STDCALL mysql_list_fields(MYSQL *mysql, const char *table, - const char *wild); MYSQL_RES * STDCALL mysql_list_processes(MYSQL *mysql); -MYSQL_RES * STDCALL mysql_store_result(MYSQL *mysql); -MYSQL_RES * STDCALL mysql_use_result(MYSQL *mysql); int STDCALL mysql_options(MYSQL *mysql,enum mysql_option option, const char *arg); void STDCALL mysql_free_result(MYSQL_RES *result); @@ -377,6 +434,8 @@ MYSQL_FIELD_OFFSET STDCALL mysql_field_seek(MYSQL_RES *result, MYSQL_ROW STDCALL mysql_fetch_row(MYSQL_RES *result); unsigned long * STDCALL mysql_fetch_lengths(MYSQL_RES *result); MYSQL_FIELD * STDCALL mysql_fetch_field(MYSQL_RES *result); +MYSQL_RES * STDCALL mysql_list_fields(MYSQL *mysql, const char *table, + const char *wild); unsigned long STDCALL mysql_escape_string(char *to,const char *from, unsigned long from_length); unsigned long STDCALL mysql_real_escape_string(MYSQL *mysql, @@ -407,6 +466,153 @@ int STDCALL mysql_manager_command(MYSQL_MANAGER* con, int STDCALL mysql_manager_fetch_line(MYSQL_MANAGER* con, char* res_buf, int res_buf_size); +my_bool STDCALL mysql_read_query_result(MYSQL *mysql); + + +/* + The following definitions are added for the enhanced + client-server protocol +*/ + +/* statement state */ +enum PREP_STMT_STATE { MY_ST_UNKNOWN, MY_ST_PREPARE, MY_ST_EXECUTE }; + +/* + client TIME structure to handle TIME, DATE and TIMESTAMP directly in + binary protocol +*/ +enum mysql_st_timestamp_type { MYSQL_TIMESTAMP_NONE, MYSQL_TIMESTAMP_DATE, + MYSQL_TIMESTAMP_FULL, MYSQL_TIMESTAMP_TIME }; + +typedef struct mysql_st_time +{ + unsigned int year,month,day,hour,minute,second; + unsigned long second_part; + my_bool neg; + + enum mysql_st_timestamp_type time_type; + +} MYSQL_TIME; + + +/* bind structure */ +typedef struct st_mysql_bind +{ + unsigned long *length; /* output length pointer */ + my_bool *is_null; /* Pointer to null indicators */ + char *buffer; /* buffer to get/put data */ + enum enum_field_types buffer_type; /* buffer type */ + unsigned long buffer_length; /* buffer length, must be set for str/binary */ + + /* Following are for internal use. Set by mysql_bind_param */ + unsigned char *inter_buffer; /* for the current data position */ + unsigned long offset; /* offset position for char/binary fetch */ + unsigned long internal_length; /* Used if length is 0 */ + unsigned int param_number; /* For null count and error messages */ + my_bool long_data_used; /* If used with mysql_send_long_data */ + my_bool binary_data; /* data buffer is binary */ + my_bool null_field; /* NULL data cache flag */ + my_bool internal_is_null; /* Used if is_null is 0 */ + void (*store_param_func)(NET *net, struct st_mysql_bind *param); + void (*fetch_result)(struct st_mysql_bind *, unsigned char **row); +} MYSQL_BIND; + + +/* statement handler */ +typedef struct st_mysql_stmt +{ + MYSQL *mysql; /* connection handle */ + MYSQL_BIND *params; /* input parameters */ + MYSQL_RES *result; /* resultset */ + MYSQL_BIND *bind; /* row binding */ + MYSQL_FIELD *fields; /* prepare meta info */ + LIST list; /* list to keep track of all stmts */ + unsigned char *current_row; /* unbuffered row */ + unsigned char *last_fetched_buffer; /* last fetched column buffer */ + char *query; /* query buffer */ + MEM_ROOT mem_root; /* root allocations */ + my_ulonglong last_fetched_column; /* last fetched column */ + unsigned long param_count; /* parameters count */ + unsigned long field_count; /* fields count */ + unsigned long stmt_id; /* Id for prepared statement */ + unsigned int last_errno; /* error code */ + enum PREP_STMT_STATE state; /* statement state */ + char last_error[MYSQL_ERRMSG_SIZE]; /* error message */ + char sqlstate[SQLSTATE_LENGTH+1]; + my_bool long_alloced; /* flag to indicate long alloced */ + my_bool send_types_to_server; /* Types sent to server */ + my_bool param_buffers; /* param bound buffers */ + my_bool res_buffers; /* output bound buffers */ + my_bool result_buffered; /* Results buffered */ +} MYSQL_STMT; + + +typedef struct st_mysql_methods +{ + my_bool (STDCALL *read_query_result)(MYSQL *mysql); + my_bool (STDCALL *advanced_command)(MYSQL *mysql, + enum enum_server_command command, + const char *header, + unsigned long header_length, + const char *arg, + unsigned long arg_length, + my_bool skip_check); + MYSQL_DATA *(STDCALL *read_rows)(MYSQL *mysql,MYSQL_FIELD *mysql_fields, + unsigned int fields); + MYSQL_RES * (STDCALL *use_result)(MYSQL *mysql); + void (STDCALL *fetch_lengths)(unsigned long *to, + MYSQL_ROW column, unsigned int field_count); +#if !defined(MYSQL_SERVER) || defined(EMBEDDED_LIBRARY) + MYSQL_FIELD * (STDCALL *list_fields)(MYSQL *mysql); + my_bool (STDCALL *read_prepare_result)(MYSQL *mysql, MYSQL_STMT *stmt); + int (STDCALL *stmt_execute)(MYSQL_STMT *stmt); + MYSQL_DATA *(STDCALL *read_binary_rows)(MYSQL_STMT *stmt); + int (STDCALL *unbuffered_fetch)(MYSQL *mysql, char **row); + void (STDCALL *free_embedded_thd)(MYSQL *mysql); + const char *(STDCALL *read_statistic)(MYSQL *mysql); +#endif +} MYSQL_METHODS; + +MYSQL_STMT * STDCALL mysql_prepare(MYSQL * mysql, const char *query, + unsigned long length); +int STDCALL mysql_execute(MYSQL_STMT * stmt); +unsigned long STDCALL mysql_param_count(MYSQL_STMT * stmt); +my_bool STDCALL mysql_bind_param(MYSQL_STMT * stmt, MYSQL_BIND * bnd); +my_bool STDCALL mysql_bind_result(MYSQL_STMT * stmt, MYSQL_BIND * bnd); +my_bool STDCALL mysql_stmt_close(MYSQL_STMT * stmt); +my_bool STDCALL mysql_stmt_reset(MYSQL_STMT * stmt); +my_bool STDCALL mysql_stmt_free_result(MYSQL_STMT *stmt); +unsigned int STDCALL mysql_stmt_errno(MYSQL_STMT * stmt); +const char *STDCALL mysql_stmt_error(MYSQL_STMT * stmt); +const char *STDCALL mysql_stmt_sqlstate(MYSQL_STMT * stmt); +my_bool STDCALL mysql_commit(MYSQL * mysql); +my_bool STDCALL mysql_rollback(MYSQL * mysql); +my_bool STDCALL mysql_autocommit(MYSQL * mysql, my_bool auto_mode); +int STDCALL mysql_fetch(MYSQL_STMT *stmt); +int STDCALL mysql_fetch_column(MYSQL_STMT *stmt, MYSQL_BIND *bind, + unsigned int column, + unsigned long offset); +my_bool STDCALL mysql_send_long_data(MYSQL_STMT *stmt, + unsigned int param_number, + const char *data, + unsigned long length); +MYSQL_RES *STDCALL mysql_get_metadata(MYSQL_STMT *stmt); +MYSQL_RES *STDCALL mysql_param_result(MYSQL_STMT *stmt); +my_ulonglong STDCALL mysql_stmt_affected_rows(MYSQL_STMT *stmt); +int STDCALL mysql_stmt_store_result(MYSQL_STMT *stmt); +my_bool STDCALL mysql_more_results(MYSQL *mysql); +my_bool STDCALL mysql_next_result(MYSQL *mysql); +MYSQL_ROW_OFFSET STDCALL mysql_stmt_row_seek(MYSQL_STMT *stmt, + MYSQL_ROW_OFFSET offset); +MYSQL_ROW_OFFSET STDCALL mysql_stmt_row_tell(MYSQL_STMT *stmt); +void STDCALL mysql_stmt_data_seek(MYSQL_STMT *stmt, my_ulonglong offset); +my_ulonglong STDCALL mysql_stmt_num_rows(MYSQL_STMT *stmt); +void STDCALL mysql_close(MYSQL *sock); + + +/* status return codes */ +#define MYSQL_NO_DATA 100 + #define mysql_reload(mysql) mysql_refresh((mysql),REFRESH_GRANT) #ifdef USE_OLD_FUNCTIONS @@ -423,8 +629,9 @@ int STDCALL mysql_drop_db(MYSQL *mysql, const char *DB); They are not for general usage */ -int simple_command(MYSQL *mysql,enum enum_server_command command, - const char *arg, unsigned long length, my_bool skipp_check); +#define simple_command(mysql, command, arg, length, skip_check) \ + (*(mysql)->methods->advanced_command)(mysql, command, \ + NullS, 0, arg, length, skip_check) unsigned long net_safe_read(MYSQL* mysql); void mysql_once_init(void); diff --git a/include/mysql_com.h b/include/mysql_com.h index a874034ba46..f4b6114c8d4 100644 --- a/include/mysql_com.h +++ b/include/mysql_com.h @@ -25,24 +25,41 @@ #define HOSTNAME_LENGTH 60 #define USERNAME_LENGTH 16 #define SERVER_VERSION_LENGTH 60 +#define SQLSTATE_LENGTH 5 #define LOCAL_HOST "localhost" #define LOCAL_HOST_NAMEDPIPE "." + #if defined(__WIN__) && !defined( _CUSTOMCONFIG_) #define MYSQL_NAMEDPIPE "MySQL" #define MYSQL_SERVICENAME "MySQL" #endif /* __WIN__ */ -enum enum_server_command { +enum enum_server_command +{ COM_SLEEP, COM_QUIT, COM_INIT_DB, COM_QUERY, COM_FIELD_LIST, - COM_CREATE_DB, COM_DROP_DB, COM_REFRESH, COM_SHUTDOWN, COM_STATISTICS, + COM_CREATE_DB, COM_DROP_DB, COM_REFRESH, COM_SHUTDOWN, COM_STATISTICS, COM_PROCESS_INFO, COM_CONNECT, COM_PROCESS_KILL, COM_DEBUG, COM_PING, COM_TIME, COM_DELAYED_INSERT, COM_CHANGE_USER, COM_BINLOG_DUMP, - COM_TABLE_DUMP, COM_CONNECT_OUT, COM_REGISTER_SLAVE, - COM_END /* Must be last! */ + COM_TABLE_DUMP, COM_CONNECT_OUT, COM_REGISTER_SLAVE, + COM_PREPARE, COM_EXECUTE, COM_LONG_DATA, COM_CLOSE_STMT, + COM_RESET_STMT, + COM_END /* Must be last */ }; + +/* + Length of random string sent by server on handshake; this is also length of + obfuscated password, recieved from client +*/ +#define SCRAMBLE_LENGTH 20 +#define SCRAMBLE_LENGTH_323 8 +/* length of password stored in the db: new passwords are preceeded with '*' */ +#define SCRAMBLED_PASSWORD_CHAR_LENGTH (SCRAMBLE_LENGTH*2+1) +#define SCRAMBLED_PASSWORD_CHAR_LENGTH_323 (SCRAMBLE_LENGTH_323*2) + + #define NOT_NULL_FLAG 1 /* Field can't be NULL */ #define PRI_KEY_FLAG 2 /* Field is part of a primary key */ #define UNIQUE_KEY_FLAG 4 /* Field is part of a unique key */ @@ -50,7 +67,8 @@ enum enum_server_command { #define BLOB_FLAG 16 /* Field is a blob */ #define UNSIGNED_FLAG 32 /* Field is unsigned */ #define ZEROFILL_FLAG 64 /* Field is zerofill */ -#define BINARY_FLAG 128 +#define BINARY_FLAG 128 /* Field is binary */ + /* The following are only sent to new clients */ #define ENUM_FLAG 256 /* field is an enum */ #define AUTO_INCREMENT_FLAG 512 /* field is a autoincrement field */ @@ -91,15 +109,23 @@ enum enum_server_command { #define CLIENT_ODBC 64 /* Odbc client */ #define CLIENT_LOCAL_FILES 128 /* Can use LOAD DATA LOCAL */ #define CLIENT_IGNORE_SPACE 256 /* Ignore spaces before '(' */ +#define CLIENT_PROTOCOL_41 512 /* New 4.1 protocol */ #define CLIENT_INTERACTIVE 1024 /* This is an interactive client */ -#define CLIENT_SSL 2048 /* Switch to SSL after handshake */ -#define CLIENT_IGNORE_SIGPIPE 4096 /* IGNORE sigpipes */ +#define CLIENT_SSL 2048 /* Switch to SSL after handshake */ +#define CLIENT_IGNORE_SIGPIPE 4096 /* IGNORE sigpipes */ #define CLIENT_TRANSACTIONS 8192 /* Client knows about transactions */ - -#define SERVER_STATUS_IN_TRANS 1 /* Transaction has started */ -#define SERVER_STATUS_AUTOCOMMIT 2 /* Server in auto_commit mode */ - -#define MYSQL_ERRMSG_SIZE 200 +#define CLIENT_RESERVED 16384 /* Old flag for 4.1 protocol */ +#define CLIENT_SECURE_CONNECTION 32768 /* New 4.1 authentication */ +#define CLIENT_MULTI_QUERIES 65536 /* Enable/disable multiquery support */ +#define CLIENT_MULTI_RESULTS 131072 /* Enable/disable multi-results */ +#define CLIENT_REMEMBER_OPTIONS (1L << 31) + +#define SERVER_STATUS_IN_TRANS 1 /* Transaction has started */ +#define SERVER_STATUS_AUTOCOMMIT 2 /* Server in auto_commit mode */ +#define SERVER_STATUS_MORE_RESULTS 4 /* More results on server */ +#define SERVER_MORE_RESULTS_EXISTS 8 /* Multi query - next query exists */ + +#define MYSQL_ERRMSG_SIZE 512 #define NET_READ_TIMEOUT 30 /* Timeout on read */ #define NET_WRITE_TIMEOUT 60 /* Timeout on write */ #define NET_WAIT_TIMEOUT 8*60*60 /* Wait for new query */ @@ -111,16 +137,15 @@ typedef struct st_vio Vio; #define MAX_BLOB_WIDTH 8192 /* Default width for blob */ typedef struct st_net { +#if !defined(CHECK_EMBEDDED_DIFFERENCES) || !defined(EMBEDDED_LIBRARY) Vio* vio; unsigned char *buff,*buff_end,*write_pos,*read_pos; my_socket fd; /* For Perl DBI/dbd */ unsigned long max_packet,max_packet_size; - unsigned int last_errno,pkt_nr,compress_pkt_nr; + unsigned int pkt_nr,compress_pkt_nr; unsigned int write_timeout, read_timeout, retry_count; int fcntl; - char last_error[MYSQL_ERRMSG_SIZE]; - unsigned char error; - my_bool return_errno,compress; + my_bool compress; /* The following variable is set if we are doing several queries in one command ( as in LOAD TABLE ... FROM MASTER ), @@ -131,32 +156,79 @@ typedef struct st_net { unsigned char reading_or_writing; char save_char; my_bool no_send_ok; + /* + Pointer to query object in query cache, do not equal NULL (0) for + queries in cache that have not stored its results yet + */ +#endif + char last_error[MYSQL_ERRMSG_SIZE], sqlstate[SQLSTATE_LENGTH+1]; + unsigned int last_errno; + unsigned char error; gptr query_cache_query; + my_bool report_error; /* We should report error (we have unreported error) */ + my_bool return_errno; } NET; #define packet_error (~(unsigned long) 0) -enum enum_field_types { FIELD_TYPE_DECIMAL, FIELD_TYPE_TINY, - FIELD_TYPE_SHORT, FIELD_TYPE_LONG, - FIELD_TYPE_FLOAT, FIELD_TYPE_DOUBLE, - FIELD_TYPE_NULL, FIELD_TYPE_TIMESTAMP, - FIELD_TYPE_LONGLONG,FIELD_TYPE_INT24, - FIELD_TYPE_DATE, FIELD_TYPE_TIME, - FIELD_TYPE_DATETIME, FIELD_TYPE_YEAR, - FIELD_TYPE_NEWDATE, - FIELD_TYPE_ENUM=247, - FIELD_TYPE_SET=248, - FIELD_TYPE_TINY_BLOB=249, - FIELD_TYPE_MEDIUM_BLOB=250, - FIELD_TYPE_LONG_BLOB=251, - FIELD_TYPE_BLOB=252, - FIELD_TYPE_VAR_STRING=253, - FIELD_TYPE_STRING=254, - FIELD_TYPE_GEOMETRY=255 +enum enum_field_types { MYSQL_TYPE_DECIMAL, MYSQL_TYPE_TINY, + MYSQL_TYPE_SHORT, MYSQL_TYPE_LONG, + MYSQL_TYPE_FLOAT, MYSQL_TYPE_DOUBLE, + MYSQL_TYPE_NULL, MYSQL_TYPE_TIMESTAMP, + MYSQL_TYPE_LONGLONG,MYSQL_TYPE_INT24, + MYSQL_TYPE_DATE, MYSQL_TYPE_TIME, + MYSQL_TYPE_DATETIME, MYSQL_TYPE_YEAR, + MYSQL_TYPE_NEWDATE, + MYSQL_TYPE_ENUM=247, + MYSQL_TYPE_SET=248, + MYSQL_TYPE_TINY_BLOB=249, + MYSQL_TYPE_MEDIUM_BLOB=250, + MYSQL_TYPE_LONG_BLOB=251, + MYSQL_TYPE_BLOB=252, + MYSQL_TYPE_VAR_STRING=253, + MYSQL_TYPE_STRING=254, + MYSQL_TYPE_GEOMETRY=255 + }; -#define FIELD_TYPE_CHAR FIELD_TYPE_TINY /* For compability */ -#define FIELD_TYPE_INTERVAL FIELD_TYPE_ENUM /* For compability */ +/* For backward compatibility */ +#define FIELD_TYPE_DECIMAL MYSQL_TYPE_DECIMAL +#define FIELD_TYPE_TINY MYSQL_TYPE_TINY +#define FIELD_TYPE_SHORT MYSQL_TYPE_SHORT +#define FIELD_TYPE_LONG MYSQL_TYPE_LONG +#define FIELD_TYPE_FLOAT MYSQL_TYPE_FLOAT +#define FIELD_TYPE_DOUBLE MYSQL_TYPE_DOUBLE +#define FIELD_TYPE_NULL MYSQL_TYPE_NULL +#define FIELD_TYPE_TIMESTAMP MYSQL_TYPE_TIMESTAMP +#define FIELD_TYPE_LONGLONG MYSQL_TYPE_LONGLONG +#define FIELD_TYPE_INT24 MYSQL_TYPE_INT24 +#define FIELD_TYPE_DATE MYSQL_TYPE_DATE +#define FIELD_TYPE_TIME MYSQL_TYPE_TIME +#define FIELD_TYPE_DATETIME MYSQL_TYPE_DATETIME +#define FIELD_TYPE_YEAR MYSQL_TYPE_YEAR +#define FIELD_TYPE_NEWDATE MYSQL_TYPE_NEWDATE +#define FIELD_TYPE_ENUM MYSQL_TYPE_ENUM +#define FIELD_TYPE_SET MYSQL_TYPE_SET +#define FIELD_TYPE_TINY_BLOB MYSQL_TYPE_TINY_BLOB +#define FIELD_TYPE_MEDIUM_BLOB MYSQL_TYPE_MEDIUM_BLOB +#define FIELD_TYPE_LONG_BLOB MYSQL_TYPE_LONG_BLOB +#define FIELD_TYPE_BLOB MYSQL_TYPE_BLOB +#define FIELD_TYPE_VAR_STRING MYSQL_TYPE_VAR_STRING +#define FIELD_TYPE_STRING MYSQL_TYPE_STRING +#define FIELD_TYPE_CHAR MYSQL_TYPE_TINY +#define FIELD_TYPE_INTERVAL MYSQL_TYPE_ENUM +#define FIELD_TYPE_GEOMETRY MYSQL_TYPE_GEOMETRY + +#if TO_BE_INCLUDED_LATER +/* For bind applications, to indicate unsigned buffers */ +#define MYSQL_TYPE_UTINY -10 +#define MYSQL_TYPE_USHORT -9 +#define MYSQL_TYPE_ULONG -8 +#define MYSQL_TYPE_UFLOAT -7 +#define MYSQL_TYPE_UDOUBLE -6 +#define MYSQL_TYPE_ULONGLONG -5 +#define MYSQL_TYPE_UINT24 -4 +#endif #define net_new_transaction(net) ((net)->pkt_nr=0) @@ -164,18 +236,29 @@ enum enum_field_types { FIELD_TYPE_DECIMAL, FIELD_TYPE_TINY, extern "C" { #endif -int my_net_init(NET *net, Vio* vio); +my_bool my_net_init(NET *net, Vio* vio); void my_net_local_init(NET *net); void net_end(NET *net); void net_clear(NET *net); -int net_flush(NET *net); -int my_net_write(NET *net,const char *packet,unsigned long len); -int net_write_command(NET *net,unsigned char command,const char *packet, - unsigned long len); +my_bool net_realloc(NET *net, unsigned long length); + +#ifndef EMBEDDED_LIBRARY /* To be removed by HF */ +my_bool net_flush(NET *net); +#else +#define net_flush(A) +#endif + +my_bool my_net_write(NET *net,const char *packet,unsigned long len); +my_bool net_write_command(NET *net,unsigned char command, + const char *header, unsigned long head_len, + const char *packet, unsigned long len); int net_real_write(NET *net,const char *packet,unsigned long len); unsigned long my_net_read(NET *net); -/* The following function is not meant for normal usage */ +/* + The following function is not meant for normal usage + Currently it's used internally by manager.c +*/ struct sockaddr; int my_connect(my_socket s, const struct sockaddr *name, unsigned int namelen, unsigned int timeout); @@ -191,7 +274,7 @@ struct rand_struct { /* The following is for user defined functions */ -enum Item_result {STRING_RESULT,REAL_RESULT,INT_RESULT}; +enum Item_result {STRING_RESULT, REAL_RESULT, INT_RESULT, ROW_RESULT}; typedef struct st_udf_args { @@ -226,18 +309,35 @@ extern "C" { extern unsigned long max_allowed_packet; extern unsigned long net_buffer_length; -void randominit(struct rand_struct *,unsigned long seed1, - unsigned long seed2); +/* + These functions are used for authentication by client and server and + implemented in sql/password.c +*/ + +void randominit(struct rand_struct *, unsigned long seed1, + unsigned long seed2); double my_rnd(struct rand_struct *); -void make_scrambled_password(char *to,const char *password); -void get_salt_from_password(unsigned long *res,const char *password); -void make_password_from_salt(char *to, unsigned long *hash_res); -char *scramble(char *to,const char *message,const char *password, - my_bool old_ver); -my_bool check_scramble(const char *, const char *message, - unsigned long *salt,my_bool old_ver); +void create_random_string(char *to, unsigned int length, struct rand_struct *rand_st); + +void hash_password(unsigned long *to, const char *password, unsigned int password_len); +void make_scrambled_password_323(char *to, const char *password); +void scramble_323(char *to, const char *message, const char *password); +my_bool check_scramble_323(const char *, const char *message, + unsigned long *salt); +void get_salt_from_password_323(unsigned long *res, const char *password); +void make_password_from_salt_323(char *to, const unsigned long *salt); + +void make_scrambled_password(char *to, const char *password); +void scramble(char *to, const char *message, const char *password); +my_bool check_scramble(const char *reply, const char *message, + const unsigned char *hash_stage2); +void get_salt_from_password(unsigned char *res, const char *password); +void make_password_from_salt(char *to, const unsigned char *hash_stage2); + +/* end of password.c */ + char *get_tty_password(char *opt_message); -void hash_password(unsigned long *result, const char *password); +const char *mysql_errno_to_sqlstate(unsigned int mysql_errno); /* Some other useful functions */ @@ -247,10 +347,18 @@ int load_defaults(const char *conf_file, const char **groups, my_bool my_thread_init(void); void my_thread_end(void); +#ifdef _global_h +ulong STDCALL net_field_length(uchar **packet); +my_ulonglong net_field_length_ll(uchar **packet); +char *net_store_length(char *pkg, ulonglong length); +#endif + #ifdef __cplusplus } #endif #define NULL_LENGTH ((unsigned long) ~0) /* For net_store_length */ +#define MYSQL_STMT_HEADER 4 +#define MYSQL_LONG_DATA_HEADER 6 #endif diff --git a/include/mysql_embed.h b/include/mysql_embed.h index bc75c3fbcb8..7a169d4133e 100644 --- a/include/mysql_embed.h +++ b/include/mysql_embed.h @@ -19,12 +19,13 @@ #ifdef EMBEDDED_LIBRARY /* Things we don't need in the embedded version of MySQL */ +/* TODO HF add #undef HAVE_VIO if we don't want client in embedded library */ #undef HAVE_PSTACK /* No stacktrace */ #undef HAVE_DLOPEN /* No udf functions */ #undef HAVE_OPENSSL -#undef HAVE_VIO #undef HAVE_ISAM +#undef HAVE_SMEM /* No shared memory */ #define DONT_USE_RAID diff --git a/include/mysql_version.h.in b/include/mysql_version.h.in index da184665f6e..31bf2bdd00d 100644 --- a/include/mysql_version.h.in +++ b/include/mysql_version.h.in @@ -21,8 +21,5 @@ #define MYSQL_CONFIG_NAME "my" /* mysqld compile time options */ -#ifndef MYSQL_CHARSET -#define MYSQL_CHARSET "@default_charset@" -#endif /* MYSQL_CHARSET */ #endif /* _CUSTOMCONFIG_ */ #endif /* _mysql_version_h */ diff --git a/include/mysqld_error.h b/include/mysqld_error.h index 9d3197c0bd4..91b10ab578a 100644 --- a/include/mysqld_error.h +++ b/include/mysqld_error.h @@ -109,7 +109,7 @@ #define ER_CANT_REMOVE_ALL_FIELDS 1090 #define ER_CANT_DROP_FIELD_OR_KEY 1091 #define ER_INSERT_INFO 1092 -#define ER_INSERT_TABLE_USED 1093 +#define ER_UPDATE_TABLE_USED 1093 #define ER_NO_SUCH_THREAD 1094 #define ER_KILL_DENIED_ERROR 1095 #define ER_NO_TABLES_USED 1096 @@ -230,7 +230,7 @@ #define ER_NO_PERMISSION_TO_CREATE_USER 1211 #define ER_UNION_TABLES_IN_DIFFERENT_DIR 1212 #define ER_LOCK_DEADLOCK 1213 -#define ER_TABLE_CANT_HANDLE_FULLTEXT 1214 +#define ER_TABLE_CANT_HANDLE_FT 1214 #define ER_CANNOT_ADD_FOREIGN 1215 #define ER_NO_REFERENCED_ROW 1216 #define ER_ROW_IS_REFERENCED 1217 @@ -253,5 +253,54 @@ #define ER_CANT_USE_OPTION_HERE 1234 #define ER_NOT_SUPPORTED_YET 1235 #define ER_MASTER_FATAL_ERROR_READING_BINLOG 1236 -#define ER_SLAVE_IGNORED_TABLE 1237 /* only the slave SQL thread can be sent this */ -#define ER_ERROR_MESSAGES 238 +#define ER_SLAVE_IGNORED_TABLE 1237 +#define ER_WRONG_FK_DEF 1238 +#define ER_KEY_REF_DO_NOT_MATCH_TABLE_REF 1239 +#define ER_OPERAND_COLUMNS 1240 +#define ER_SUBQUERY_NO_1_ROW 1241 +#define ER_UNKNOWN_STMT_HANDLER 1242 +#define ER_CORRUPT_HELP_DB 1243 +#define ER_CYCLIC_REFERENCE 1244 +#define ER_AUTO_CONVERT 1245 +#define ER_ILLEGAL_REFERENCE 1246 +#define ER_DERIVED_MUST_HAVE_ALIAS 1247 +#define ER_SELECT_REDUCED 1248 +#define ER_TABLENAME_NOT_ALLOWED_HERE 1249 +#define ER_NOT_SUPPORTED_AUTH_MODE 1250 +#define ER_SPATIAL_CANT_HAVE_NULL 1251 +#define ER_COLLATION_CHARSET_MISMATCH 1252 +#define ER_SLAVE_WAS_RUNNING 1253 +#define ER_SLAVE_WAS_NOT_RUNNING 1254 +#define ER_TOO_BIG_FOR_UNCOMPRESS 1255 +#define ER_ZLIB_Z_MEM_ERROR 1256 +#define ER_ZLIB_Z_BUF_ERROR 1257 +#define ER_ZLIB_Z_DATA_ERROR 1258 +#define ER_CUT_VALUE_GROUP_CONCAT 1259 +#define ER_WARN_TOO_FEW_RECORDS 1260 +#define ER_WARN_TOO_MANY_RECORDS 1261 +#define ER_WARN_NULL_TO_NOTNULL 1262 +#define ER_WARN_DATA_OUT_OF_RANGE 1263 +#define ER_WARN_DATA_TRUNCATED 1264 +#define ER_WARN_USING_OTHER_HANDLER 1265 +#define ER_CANT_AGGREGATE_2COLLATIONS 1266 +#define ER_DROP_USER 1267 +#define ER_REVOKE_GRANTS 1268 +#define ER_CANT_AGGREGATE_3COLLATIONS 1269 +#define ER_CANT_AGGREGATE_NCOLLATIONS 1270 +#define ER_VARIABLE_IS_NOT_STRUCT 1271 +#define ER_UNKNOWN_COLLATION 1272 +#define ER_SLAVE_IGNORED_SSL_PARAMS 1273 +#define ER_SERVER_IS_IN_SECURE_AUTH_MODE 1274 +#define ER_WARN_FIELD_RESOLVED 1275 +#define ER_BAD_SLAVE_UNTIL_COND 1276 +#define ER_MISSING_SKIP_SLAVE 1277 +#define ER_UNTIL_COND_IGNORED 1278 +#define ER_WRONG_NAME 1279 +#define ER_TABLE 1280 +#define ER_DATABASE 1281 +#define ER_COLUMN 1282 +#define ER_INDEX 1283 +#define ER_CATALOG 1284 +#define ER_WARN_QC_RESIZE 1285 +#define ER_BAD_FT_COLUMN 1286 +#define ER_ERROR_MESSAGES 287 diff --git a/include/sql_common.h b/include/sql_common.h new file mode 100644 index 00000000000..1f442339c4f --- /dev/null +++ b/include/sql_common.h @@ -0,0 +1,49 @@ +/* Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ + + +extern const char *unknown_sqlstate; +extern const char *not_error_sqlstate; + +#ifdef __cplusplus +extern "C" { +#endif + +ulong STDCALL net_field_length(uchar **packet); +my_ulonglong net_field_length_ll(uchar **packet); + +MYSQL_FIELD *unpack_fields(MYSQL_DATA *data,MEM_ROOT *alloc,uint fields, + my_bool default_value, uint server_capabilities); +void free_rows(MYSQL_DATA *cur); +my_bool mysql_autenticate(MYSQL *mysql, const char *passwd); +void free_old_query(MYSQL *mysql); +void end_server(MYSQL *mysql); +my_bool mysql_reconnect(MYSQL *mysql); +void mysql_read_default_options(struct st_mysql_options *options, + const char *filename,const char *group); +my_bool STDCALL +cli_advanced_command(MYSQL *mysql, enum enum_server_command command, + const char *header, ulong header_length, + const char *arg, ulong arg_length, my_bool skip_check); + +void set_stmt_errmsg(MYSQL_STMT * stmt, const char *err, int errcode, + const char *sqlstate); +#ifdef __cplusplus +} +#endif + +#define protocol_41(A) ((A)->server_capabilities & CLIENT_PROTOCOL_41) + diff --git a/include/sql_state.h b/include/sql_state.h new file mode 100644 index 00000000000..d55fb137e27 --- /dev/null +++ b/include/sql_state.h @@ -0,0 +1,162 @@ +/* Copyright (C) 2000-2003 MySQL AB + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ + +/* + This file includes a mapping from mysql_errno.h to sql_state (as used by + MyODBC) and jdbc_state. + It's suitable to include into a C struct for further processing + + The first column is the mysqld server error (declared in mysqld_error.h), + the second column is the ODBC state (which the 4.1 server sends out by + default) and the last is the state used by the JDBC driver. + If the last column is "" then it means that the JDBC driver is using the + ODBC state + + The errors in this file is sorted in the same order as in mysqld_error.h + to allow on to do binary searches for the sqlstate. +*/ + +ER_DUP_KEY, "23000", "", +ER_OUTOFMEMORY, "HY001", "S1001", +ER_OUT_OF_SORTMEMORY, "HY001", "S1001", +ER_CON_COUNT_ERROR, "08004", "", +ER_BAD_HOST_ERROR, "08S01", "", +ER_HANDSHAKE_ERROR, "08S01", "", +ER_DBACCESS_DENIED_ERROR, "42000", "", +ER_ACCESS_DENIED_ERROR, "28000", "", +ER_NO_DB_ERROR, "3D000", "", +ER_UNKNOWN_COM_ERROR, "08S01", "", +ER_BAD_NULL_ERROR, "23000", "", +ER_BAD_DB_ERROR, "42000", "", +ER_TABLE_EXISTS_ERROR, "42S01", "", +ER_BAD_TABLE_ERROR, "42S02", "", +ER_NON_UNIQ_ERROR, "23000", "", +ER_SERVER_SHUTDOWN, "08S01", "", +ER_BAD_FIELD_ERROR, "42S22", "S0022", +ER_WRONG_FIELD_WITH_GROUP, "42000", "S1009", +ER_WRONG_GROUP_FIELD, "42000", "S1009", +ER_WRONG_SUM_SELECT, "42000", "S1009", +ER_WRONG_VALUE_COUNT, "21S01", "", +ER_TOO_LONG_IDENT, "42000", "S1009", +ER_DUP_FIELDNAME, "42S21", "S1009", +ER_DUP_KEYNAME, "42000", "S1009", +ER_DUP_ENTRY, "23000", "S1009", +ER_WRONG_FIELD_SPEC, "42000", "S1009", +ER_PARSE_ERROR, "42000", "", +ER_EMPTY_QUERY, "42000" , "", +ER_NONUNIQ_TABLE, "42000", "S1009", +ER_INVALID_DEFAULT, "42000", "S1009", +ER_MULTIPLE_PRI_KEY, "42000", "S1009", +ER_TOO_MANY_KEYS, "42000", "S1009", +ER_TOO_MANY_KEY_PARTS, "42000", "S1009", +ER_TOO_LONG_KEY, "42000", "S1009", +ER_KEY_COLUMN_DOES_NOT_EXITS, "42000", "S1009", +ER_BLOB_USED_AS_KEY, "42000", "S1009", +ER_TOO_BIG_FIELDLENGTH, "42000", "S1009", +ER_WRONG_AUTO_KEY, "42000", "S1009", +ER_FORCING_CLOSE, "08S01", "", +ER_IPSOCK_ERROR, "08S01", "", +ER_NO_SUCH_INDEX, "42S12", "S1009", +ER_WRONG_FIELD_TERMINATORS, "42000", "S1009", +ER_BLOBS_AND_NO_TERMINATED, "42000", "S1009", +ER_CANT_REMOVE_ALL_FIELDS, "42000", "", +ER_CANT_DROP_FIELD_OR_KEY, "42000", "", +ER_BLOB_CANT_HAVE_DEFAULT, "42000", "", +ER_WRONG_DB_NAME, "42000", "", +ER_WRONG_TABLE_NAME, "42000", "", +ER_TOO_BIG_SELECT, "42000", "", +ER_UNKNOWN_PROCEDURE, "42000", "", +ER_WRONG_PARAMCOUNT_TO_PROCEDURE, "42000", "", +ER_UNKNOWN_TABLE, "42S02", "", +ER_FIELD_SPECIFIED_TWICE, "42000", "", +ER_UNSUPPORTED_EXTENSION, "42000", "", +ER_TABLE_MUST_HAVE_COLUMNS, "42000", "", +ER_UNKNOWN_CHARACTER_SET, "42000", "", +ER_TOO_BIG_ROWSIZE, "42000", "", +ER_WRONG_OUTER_JOIN, "42000", "", +ER_NULL_COLUMN_IN_INDEX, "42000", "", +ER_PASSWORD_ANONYMOUS_USER, "42000", "", +ER_PASSWORD_NOT_ALLOWED, "42000", "", +ER_PASSWORD_NO_MATCH, "42000", "", +ER_WRONG_VALUE_COUNT_ON_ROW, "21S01", "", +ER_INVALID_USE_OF_NULL, "42000", "", +ER_REGEXP_ERROR, "42000", "", +ER_MIX_OF_GROUP_FUNC_AND_FIELDS,"42000", "", +ER_NONEXISTING_GRANT, "42000", "", +ER_TABLEACCESS_DENIED_ERROR, "42000", "", +ER_COLUMNACCESS_DENIED_ERROR, "42000", "", +ER_ILLEGAL_GRANT_FOR_TABLE, "42000", "", +ER_GRANT_WRONG_HOST_OR_USER, "42000", "", +ER_NO_SUCH_TABLE, "42S02", "", +ER_NONEXISTING_TABLE_GRANT, "42000", "", +ER_NOT_ALLOWED_COMMAND, "42000", "", +ER_SYNTAX_ERROR, "42000", "", +ER_ABORTING_CONNECTION, "08S01", "", +ER_NET_PACKET_TOO_LARGE, "08S01", "", +ER_NET_READ_ERROR_FROM_PIPE, "08S01", "", +ER_NET_FCNTL_ERROR, "08S01", "", +ER_NET_PACKETS_OUT_OF_ORDER, "08S01", "", +ER_NET_UNCOMPRESS_ERROR, "08S01", "", +ER_NET_READ_ERROR, "08S01", "", +ER_NET_READ_INTERRUPTED, "08S01", "", +ER_NET_ERROR_ON_WRITE, "08S01", "", +ER_NET_WRITE_INTERRUPTED, "08S01", "", +ER_TOO_LONG_STRING, "42000", "", +ER_TABLE_CANT_HANDLE_BLOB, "42000", "", +ER_TABLE_CANT_HANDLE_AUTO_INCREMENT, "42000", "", +ER_WRONG_COLUMN_NAME, "42000", "", +ER_WRONG_KEY_COLUMN, "42000", "", +ER_DUP_UNIQUE, "23000", "", +ER_BLOB_KEY_WITHOUT_LENGTH, "42000", "", +ER_PRIMARY_CANT_HAVE_NULL, "42000", "", +ER_TOO_MANY_ROWS, "42000", "", +ER_REQUIRES_PRIMARY_KEY, "42000", "", +ER_CHECK_NO_SUCH_TABLE, "42000", "", +ER_CHECK_NOT_IMPLEMENTED, "42000", "", +ER_CANT_DO_THIS_DURING_AN_TRANSACTION, "25000", "", +ER_NEW_ABORTING_CONNECTION, "08S01", "", +ER_MASTER_NET_READ, "08S01", "", +ER_MASTER_NET_WRITE, "08S01", "", +ER_TOO_MANY_USER_CONNECTIONS, "42000", "", +ER_READ_ONLY_TRANSACTION, "25000", "", +ER_NO_PERMISSION_TO_CREATE_USER,"42000", "", +ER_LOCK_DEADLOCK, "40001", "", +ER_NO_REFERENCED_ROW, "23000", "", +ER_ROW_IS_REFERENCED, "23000", "", +ER_CONNECT_TO_MASTER, "08S01", "", +ER_WRONG_NUMBER_OF_COLUMNS_IN_SELECT,"21000", "", +ER_USER_LIMIT_REACHED, "42000", "", +ER_NO_DEFAULT, "42000", "", +ER_WRONG_VALUE_FOR_VAR, "42000", "", +ER_WRONG_TYPE_FOR_VAR, "42000", "", +ER_CANT_USE_OPTION_HERE, "42000", "", +ER_NOT_SUPPORTED_YET, "42000", "", +ER_WRONG_FK_DEF, "42000", "", +ER_OPERAND_COLUMNS, "21000", "", +ER_SUBQUERY_NO_1_ROW, "21000", "", +ER_ILLEGAL_REFERENCE, "42S22", "", +ER_DERIVED_MUST_HAVE_ALIAS, "42000", "", +ER_SELECT_REDUCED, "01000", "", +ER_TABLENAME_NOT_ALLOWED_HERE, "42000", "", +ER_NOT_SUPPORTED_AUTH_MODE, "08004", "", +ER_SPATIAL_CANT_HAVE_NULL, "42000", "", +ER_COLLATION_CHARSET_MISMATCH, "42000", "", +ER_WARN_TOO_FEW_RECORDS, "01000", "", +ER_WARN_TOO_MANY_RECORDS, "01000", "", +ER_WARN_NULL_TO_NOTNULL, "01000", "", +ER_WARN_DATA_OUT_OF_RANGE, "01000", "", +ER_WARN_DATA_TRUNCATED, "01000", "", +ER_WRONG_NAME, "42000", "", diff --git a/include/sslopt-longopts.h b/include/sslopt-longopts.h index 397d8baa9d6..dc3b0922327 100644 --- a/include/sslopt-longopts.h +++ b/include/sslopt-longopts.h @@ -17,24 +17,24 @@ #ifdef HAVE_OPENSSL {"ssl", OPT_SSL_SSL, - "Enable SSL for connection (automatically enabled with other flags). Disable with --skip-ssl", + "Enable SSL for connection (automatically enabled with other flags). Disable with --skip-ssl.", (gptr*) &opt_use_ssl, (gptr*) &opt_use_ssl, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0}, - {"ssl-key", OPT_SSL_KEY, "X509 key in PEM format (implies --ssl)", + {"ssl-key", OPT_SSL_KEY, "X509 key in PEM format (implies --ssl).", (gptr*) &opt_ssl_key, (gptr*) &opt_ssl_key, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0}, - {"ssl-cert", OPT_SSL_CERT, "X509 cert in PEM format (implies --ssl)", + {"ssl-cert", OPT_SSL_CERT, "X509 cert in PEM format (implies --ssl).", (gptr*) &opt_ssl_cert, (gptr*) &opt_ssl_cert, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0}, {"ssl-ca", OPT_SSL_CA, - "CA file in PEM format (check OpenSSL docs, implies --ssl)", + "CA file in PEM format (check OpenSSL docs, implies --ssl).", (gptr*) &opt_ssl_ca, (gptr*) &opt_ssl_ca, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0}, {"ssl-capath", OPT_SSL_CAPATH, - "CA directory (check OpenSSL docs, implies --ssl)", + "CA directory (check OpenSSL docs, implies --ssl).", (gptr*) &opt_ssl_capath, (gptr*) &opt_ssl_capath, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0}, - {"ssl-cipher", OPT_SSL_CIPHER, "SSL cipher to use (implies --ssl)", + {"ssl-cipher", OPT_SSL_CIPHER, "SSL cipher to use (implies --ssl).", (gptr*) &opt_ssl_cipher, (gptr*) &opt_ssl_cipher, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0}, diff --git a/include/thr_lock.h b/include/thr_lock.h index f1bda0ce6b4..947b17bf2b6 100644 --- a/include/thr_lock.h +++ b/include/thr_lock.h @@ -74,6 +74,7 @@ typedef struct st_thr_lock_data { enum thr_lock_type type; ulong thread_id; void *status_param; /* Param to status functions */ + void *debug_print_param; } THR_LOCK_DATA; struct st_lock_list { @@ -97,6 +98,9 @@ typedef struct st_thr_lock { } THR_LOCK; +extern LIST *thr_lock_thread_list; +extern pthread_mutex_t THR_LOCK_lock; + my_bool init_thr_lock(void); /* Must be called once/thread */ void thr_lock_init(THR_LOCK *lock); void thr_lock_delete(THR_LOCK *lock); diff --git a/include/typelib.h b/include/typelib.h new file mode 100644 index 00000000000..1b049d19a11 --- /dev/null +++ b/include/typelib.h @@ -0,0 +1,33 @@ +/* Copyright (C) 2000 MySQL AB + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ + + +#ifndef _typelib_h +#define _typelib_h + +typedef struct st_typelib { /* Different types saved here */ + unsigned int count; /* How many types */ + const char *name; /* Name of typelib */ + const char **type_names; +} TYPELIB; + +extern int find_type(char *x,TYPELIB *typelib,unsigned int full_name); +extern void make_type(char *to,unsigned int nr,TYPELIB *typelib); +extern const char *get_type(TYPELIB *typelib,unsigned int nr); + +extern TYPELIB sql_protocol_typelib; + +#endif /* _typelib_h */ diff --git a/include/violite.h b/include/violite.h index 18f862d4b77..37c5abbbe67 100644 --- a/include/violite.h +++ b/include/violite.h @@ -31,17 +31,28 @@ extern "C" { #endif /* __cplusplus */ -enum enum_vio_type { VIO_CLOSED, VIO_TYPE_TCPIP, VIO_TYPE_SOCKET, - VIO_TYPE_NAMEDPIPE, VIO_TYPE_SSL}; - -#ifndef __WIN__ -#define HANDLE void * -#endif +enum enum_vio_type +{ + VIO_CLOSED, VIO_TYPE_TCPIP, VIO_TYPE_SOCKET, VIO_TYPE_NAMEDPIPE, + VIO_TYPE_SSL, VIO_TYPE_SHARED_MEMORY +}; Vio* vio_new(my_socket sd, enum enum_vio_type type, my_bool localhost); #ifdef __WIN__ Vio* vio_new_win32pipe(HANDLE hPipe); -#endif +Vio* vio_new_win32shared_memory(NET *net,HANDLE handle_file_map, + HANDLE handle_map, + HANDLE event_server_wrote, + HANDLE event_server_read, + HANDLE event_client_wrote, + HANDLE event_client_read); +int vio_read_pipe(Vio *vio, gptr buf, int size); +int vio_write_pipe(Vio *vio, const gptr buf, int size); +int vio_close_pipe(Vio * vio); +#else +#define HANDLE void * +#endif /* __WIN__ */ + void vio_delete(Vio* vio); int vio_close(Vio* vio); @@ -67,15 +78,15 @@ const char* vio_description(Vio *vio); /* Return the type of the connection */ enum enum_vio_type vio_type(Vio* vio); /* Return last error number */ -int vio_errno(Vio*vio); +int vio_errno(Vio*vio); /* Get socket number */ my_socket vio_fd(Vio*vio); /* Remote peer's address and name in text form */ -my_bool vio_peer_addr(Vio* vio, char *buf, uint16 *port); +my_bool vio_peer_addr(Vio* vio, char *buf, uint16 *port); /* Remotes in_addr */ -void vio_in_addr(Vio *vio, struct in_addr *in); -my_bool vio_poll_read(Vio *vio,uint timeout); -void vio_timeout(Vio *vio,uint timeout); +void vio_in_addr(Vio *vio, struct in_addr *in); +my_bool vio_poll_read(Vio *vio,uint timeout); +void vio_timeout(Vio *vio,uint timeout); #ifdef HAVE_OPENSSL #define HEADER_DES_LOCL_H dummy_something @@ -109,6 +120,12 @@ struct st_VioSSLAcceptorFd const char *ca_file,const char *ca_path, const char *cipher); Vio *new_VioSSL(struct st_VioSSLAcceptorFd *fd, Vio *sd, int state); +#endif /* HAVE_OPENSSL */ + +#ifdef HAVE_SMEM +int vio_read_shared_memory(Vio *vio, gptr buf, int size); +int vio_write_shared_memory(Vio *vio, const gptr buf, int size); +int vio_close_shared_memory(Vio * vio); #endif #ifdef __cplusplus @@ -142,7 +159,8 @@ enum SSL_type SSL_TYPE_SPECIFIED }; -#ifndef EMBEDDED_LIBRARY + +/* HFTODO - hide this if we don't want client in embedded server */ /* This structure is for every connection on both sides */ struct st_vio { @@ -170,7 +188,17 @@ struct st_vio int (*vioclose)(Vio*); void (*timeout)(Vio*, unsigned int timeout); void *ssl_arg; +#ifdef HAVE_SMEM + HANDLE handle_file_map; + char *handle_map; + HANDLE event_server_wrote; + HANDLE event_server_read; + HANDLE event_client_wrote; + HANDLE event_client_read; + long shared_memory_remain; + char *shared_memory_pos; + NET *net; +#endif /* HAVE_SMEM */ #endif /* HAVE_VIO */ }; -#endif /* EMBEDDED_LIBRARY */ #endif /* vio_violite_h_ */ |