From 537531f0e8990debfb82bdbaac2f237d46098fb1 Mon Sep 17 00:00:00 2001 From: unknown Date: Fri, 11 Feb 2005 21:57:37 +0200 Subject: Fixed mistyping (thnx to Konstantin) sql/sql_cache.cc: Fixed mistyping --- sql/sql_cache.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'sql') diff --git a/sql/sql_cache.cc b/sql/sql_cache.cc index f503a63e752..d729a6cc301 100644 --- a/sql/sql_cache.cc +++ b/sql/sql_cache.cc @@ -1337,7 +1337,7 @@ ulong Query_cache::init_cache() init(); approx_additional_data_size = (sizeof(Query_cache) + sizeof(gptr)*(def_query_hash_size+ - def_query_hash_size)); + def_table_hash_size)); if (query_cache_size < approx_additional_data_size) goto err; -- cgit v1.2.1 From 2d619d7cadf45348614884d4cde7ded316e47412 Mon Sep 17 00:00:00 2001 From: unknown Date: Sat, 12 Feb 2005 16:27:22 +0400 Subject: Bug#8235 Connection collation change & table create with default result in crash mysql-test/r/ctype_ucs.result: Test case mysql-test/t/ctype_ucs.test: Test case sql/field.cc: Fixed minus check to be UCS2-compatible strings/ctype-ucs2.c: Missing my_scan_ucs2() was added. --- sql/field.cc | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'sql') diff --git a/sql/field.cc b/sql/field.cc index e2f75034e52..fa0e202d513 100644 --- a/sql/field.cc +++ b/sql/field.cc @@ -1777,6 +1777,14 @@ void Field_medium::sql_type(String &res) const ****************************************************************************/ +static bool test_if_minus(CHARSET_INFO *cs, + const char *s, const char *e) +{ + my_wc_t wc; + return cs->cset->mb_wc(cs, &wc, (uchar*) s, (uchar*) e) > 0 && wc == '-'; +} + + int Field_long::store(const char *from,uint len,CHARSET_INFO *cs) { long tmp; @@ -1790,7 +1798,7 @@ int Field_long::store(const char *from,uint len,CHARSET_INFO *cs) if (unsigned_flag) { - if (!len || *from == '-') + if (!len || test_if_minus(cs, from, from + len)) { tmp=0; // Set negative to 0 my_errno=ERANGE; @@ -2086,7 +2094,7 @@ int Field_longlong::store(const char *from,uint len,CHARSET_INFO *cs) my_errno=0; if (unsigned_flag) { - if (!len || *from == '-') + if (!len || test_if_minus(cs, from, from + len)) { tmp=0; // Set negative to 0 my_errno= ERANGE; -- cgit v1.2.1 From a8b9f30eb3e5f68a49c6db4476c0ef759ca52157 Mon Sep 17 00:00:00 2001 From: unknown Date: Sat, 12 Feb 2005 19:17:33 +0100 Subject: new static archive_inited variable, so that archive_db_end() will do something only if archive_db_init() was run before (protection against destroying uninited mutex in the case where mysqld fails early at startup (before archive_db_init() was called) and then calls archive_db_end() to clean up). sql/examples/ha_archive.cc: new static archive_inited variable, so that archive_db_end() will do something only if archive_db_init() was run before. --- sql/examples/ha_archive.cc | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'sql') diff --git a/sql/examples/ha_archive.cc b/sql/examples/ha_archive.cc index 491056d0e59..bc4af0c7dc7 100644 --- a/sql/examples/ha_archive.cc +++ b/sql/examples/ha_archive.cc @@ -114,6 +114,8 @@ data - The data is stored in a "row +blobs" format. */ +/* If the archive storage engine has been inited */ +static bool archive_inited= 0; /* Variables for archive share methods */ pthread_mutex_t archive_mutex; static HASH archive_open_tables; @@ -157,6 +159,7 @@ static byte* archive_get_key(ARCHIVE_SHARE *share,uint *length, bool archive_db_init() { + archive_inited= 1; VOID(pthread_mutex_init(&archive_mutex, MY_MUTEX_INIT_FAST)); return (hash_init(&archive_open_tables, system_charset_info, 32, 0, 0, (hash_get_key) archive_get_key, 0, 0)); @@ -176,8 +179,12 @@ bool archive_db_init() bool archive_db_end() { - hash_free(&archive_open_tables); - VOID(pthread_mutex_destroy(&archive_mutex)); + if (archive_inited) + { + hash_free(&archive_open_tables); + VOID(pthread_mutex_destroy(&archive_mutex)); + } + archive_inited= 0; return FALSE; } -- cgit v1.2.1 From a8d2152f973dc56897725356cd0f88310a7689b8 Mon Sep 17 00:00:00 2001 From: unknown Date: Sun, 13 Feb 2005 22:35:52 +0000 Subject: Bug#2435 Alter handling for UNION syntax Tests for UNION and parentheses mysql-test/r/union.result: Bug#2435 Tests for UNION and parentheses mysql-test/t/union.test: Bug#2435 Tests for UNION and parentheses sql/sql_yacc.yy: Bug#2435 Amend handling of UNION with parentheses. --- sql/sql_yacc.yy | 35 ++++++++++++++++++++++++++++------- 1 file changed, 28 insertions(+), 7 deletions(-) (limited to 'sql') diff --git a/sql/sql_yacc.yy b/sql/sql_yacc.yy index e70efe14557..988323811ac 100644 --- a/sql/sql_yacc.yy +++ b/sql/sql_yacc.yy @@ -2389,7 +2389,10 @@ select: select_init: SELECT_SYM select_init2 | - '(' SELECT_SYM select_part2 ')' + '(' select_paren ')' union_opt; + +select_paren: + SELECT_SYM select_part2 { LEX *lex= Lex; SELECT_LEX * sel= lex->current_select; @@ -2408,7 +2411,8 @@ select_init: if (sel->master_unit()->fake_select_lex) sel->master_unit()->global_parameters= sel->master_unit()->fake_select_lex; - } union_opt; + } + | '(' select_paren ')'; select_init2: select_part2 @@ -3404,8 +3408,7 @@ when_list2: }; join_table_list: - '(' join_table_list ')' { $$=$2; } - | join_table { $$=$1; } + join_table { $$=$1; } | join_table_list ',' join_table_list { $$=$3; } | join_table_list normal_join join_table_list { $$=$3; } | join_table_list STRAIGHT_JOIN join_table_list @@ -3482,7 +3485,7 @@ join_table: } | '{' ident join_table LEFT OUTER JOIN_SYM join_table ON expr '}' { add_join_on($7,$9); $7->outer_join|=JOIN_TYPE_LEFT; $$=$7; } - | '(' SELECT_SYM select_derived ')' opt_table_alias + | '(' select_derived union_opt ')' opt_table_alias { LEX *lex=Lex; SELECT_LEX_UNIT *unit= lex->current_select->master_unit(); @@ -3493,9 +3496,27 @@ join_table: (List *)0))) YYABORT; - }; + } + | '(' join_table_list ')' { $$=$2; }; select_derived: + SELECT_SYM select_derived2 + | '(' select_derived ')' + { + LEX *lex= Lex; + SELECT_LEX * sel= lex->current_select; + if (sel->set_braces(1)) + { + yyerror(ER(ER_SYNTAX_ERROR)); + YYABORT; + } + /* select in braces, can't contain global parameters */ + if (sel->master_unit()->fake_select_lex) + sel->master_unit()->global_parameters= + sel->master_unit()->fake_select_lex; + }; + +select_derived2: { LEX *lex= Lex; lex->derived_tables= 1; @@ -3517,7 +3538,7 @@ select_derived: { Select->parsing_place= NO_MATTER; } - opt_select_from union_opt + opt_select_from ; opt_outer: -- cgit v1.2.1 From de109e463bb699305bdcf116280c412dc7da2566 Mon Sep 17 00:00:00 2001 From: unknown Date: Tue, 15 Feb 2005 03:55:44 +0300 Subject: Fix signatures of placement operator delete in places where placement delete is declared. As we don't use exceptions placement delete is never called and the fix only affects numerous warnings when compiling with MS Visual C++. For more info see http://www.gotw.ca/gotw/010.htm. sql/item.h: Fix the signature of placement operator delete for class Item. sql/sql_class.cc: Add placement delete operator to suppress a warning under Windows. sql/sql_lex.h: Fix the signature of placement operator delete for class LEX sql/sql_list.h: Fix the signature of placement operator delete for class Sql_alloc sql/sql_string.h: Fix the signature of placement operator delete for class Sql_string --- sql/item.h | 2 +- sql/sql_class.cc | 2 ++ sql/sql_lex.h | 2 +- sql/sql_list.h | 4 ++-- sql/sql_string.h | 2 +- 5 files changed, 7 insertions(+), 5 deletions(-) (limited to 'sql') diff --git a/sql/item.h b/sql/item.h index a8b892292d3..db5010799fa 100644 --- a/sql/item.h +++ b/sql/item.h @@ -119,7 +119,7 @@ public: static void *operator new(size_t size, MEM_ROOT *mem_root) { return (void*) alloc_root(mem_root, (uint) size); } static void operator delete(void *ptr,size_t size) {} - static void operator delete(void *ptr,size_t size, MEM_ROOT *mem_root) {} + static void operator delete(void *ptr, MEM_ROOT *mem_root) {} enum Type {FIELD_ITEM, FUNC_ITEM, SUM_FUNC_ITEM, STRING_ITEM, INT_ITEM, REAL_ITEM, NULL_ITEM, VARBIN_ITEM, diff --git a/sql/sql_class.cc b/sql/sql_class.cc index e11d8369f57..918e70fbc84 100644 --- a/sql/sql_class.cc +++ b/sql/sql_class.cc @@ -707,6 +707,8 @@ struct Item_change_record: public ilink Item *old_value; /* Placement new was hidden by `new' in ilink (TODO: check): */ static void *operator new(size_t size, void *mem) { return mem; } + static void operator delete(void *ptr, size_t size) {} + static void operator delete(void *ptr, void *mem) { /* never called */ } }; diff --git a/sql/sql_lex.h b/sql/sql_lex.h index 7cb71607edf..3e2f6a3f2b5 100644 --- a/sql/sql_lex.h +++ b/sql/sql_lex.h @@ -241,7 +241,7 @@ public: static void *operator new(size_t size, MEM_ROOT *mem_root) { return (void*) alloc_root(mem_root, (uint) size); } static void operator delete(void *ptr,size_t size) {} - static void operator delete(void *ptr,size_t size, MEM_ROOT *mem_root) {} + static void operator delete(void *ptr, MEM_ROOT *mem_root) {} st_select_lex_node(): linkage(UNSPECIFIED_TYPE) {} virtual ~st_select_lex_node() {} inline st_select_lex_node* get_master() { return master; } diff --git a/sql/sql_list.h b/sql/sql_list.h index a607b31d60c..be3e29b0c62 100644 --- a/sql/sql_list.h +++ b/sql/sql_list.h @@ -41,8 +41,8 @@ public: static void *operator new(size_t size, MEM_ROOT *mem_root) { return (void*) alloc_root(mem_root, (uint) size); } static void operator delete(void *ptr, size_t size) { TRASH(ptr, size); } - static void operator delete(void *ptr, size_t size, MEM_ROOT *mem_root) - { TRASH(ptr, size); } + static void operator delete(void *ptr, MEM_ROOT *mem_root) + { /* never called */ } static void operator delete[](void *ptr, size_t size) { TRASH(ptr, size); } #ifdef HAVE_purify bool dummy; diff --git a/sql/sql_string.h b/sql/sql_string.h index 9136dddbbf2..3ad4689cf36 100644 --- a/sql/sql_string.h +++ b/sql/sql_string.h @@ -73,7 +73,7 @@ public: { return (void*) alloc_root(mem_root, (uint) size); } static void operator delete(void *ptr_arg,size_t size) {} - static void operator delete(void *ptr_arg,size_t size, MEM_ROOT *mem_root) + static void operator delete(void *ptr_arg, MEM_ROOT *mem_root) {} ~String() { free(); } -- cgit v1.2.1 From 1d633f645a7c2c8186a5b605dc1bcaf95787cc7a Mon Sep 17 00:00:00 2001 From: unknown Date: Tue, 15 Feb 2005 15:01:20 +0400 Subject: A fix. "(int) var" type cast doesn't work correctly for uint32 var on some 64-bit platforms (e.g. IRIX, non-debug build). --- sql/item_strfunc.cc | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'sql') diff --git a/sql/item_strfunc.cc b/sql/item_strfunc.cc index a92c4e94c87..bbbcadbb071 100644 --- a/sql/item_strfunc.cc +++ b/sql/item_strfunc.cc @@ -1645,7 +1645,8 @@ String *Item_func_format::val_str(String *str) { DBUG_ASSERT(fixed == 1); double nr =args[0]->val(); - uint32 diff,length,str_length; + int diff; + uint32 length, str_length; uint dec; if ((null_value=args[0]->null_value)) return 0; /* purecov: inspected */ @@ -1670,9 +1671,12 @@ String *Item_func_format::val_str(String *str) pos[0]= pos[-(int) diff]; while (diff) { - pos[0]=pos[-(int) diff]; pos--; - pos[0]=pos[-(int) diff]; pos--; - pos[0]=pos[-(int) diff]; pos--; + *pos= *(pos - diff); + pos--; + *pos= *(pos - diff); + pos--; + *pos= *(pos - diff); + pos--; pos[0]=','; pos--; diff--; -- cgit v1.2.1 From 358cfd6c4220d3d1d1f596f6313fcba1819ff1a6 Mon Sep 17 00:00:00 2001 From: unknown Date: Tue, 15 Feb 2005 14:42:13 +0200 Subject: Better bug fix for #5569: "Incorrect "Access Denied" error with SAME login DIFFERENT host" This fixes also the reverse lookup bug introduced by the previous patch mysql-test/t/group_by.test: Remove empty line vio/viosocket.c: Added function comment --- sql/sql_parse.cc | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) (limited to 'sql') diff --git a/sql/sql_parse.cc b/sql/sql_parse.cc index cd0abafc0c9..613484ebf50 100644 --- a/sql/sql_parse.cc +++ b/sql/sql_parse.cc @@ -504,8 +504,6 @@ check_connections(THD *thd) DBUG_PRINT("info",("New connection received on %s", vio_description(net->vio))); - vio_in_addr(net->vio,&thd->remote.sin_addr); - if (!thd->host) // If TCP/IP connection { char ip[30]; @@ -515,6 +513,7 @@ check_connections(THD *thd) if (!(thd->ip = my_strdup(ip,MYF(0)))) return (ER_OUT_OF_RESOURCES); thd->host_or_ip=thd->ip; + vio_in_addr(net->vio, &thd->remote.sin_addr); #if !defined(HAVE_SYS_UN_H) || defined(HAVE_mit_thread) /* Fast local hostname resolve for Win32 */ if (!strcmp(thd->ip,"127.0.0.1")) @@ -524,17 +523,19 @@ check_connections(THD *thd) } else #endif - if (!(specialflag & SPECIAL_NO_RESOLVE)) { - thd->host=ip_to_hostname(&thd->remote.sin_addr,&connect_errors); - /* Cut very long hostnames to avoid possible overflows */ - if (thd->host) + if (!(specialflag & SPECIAL_NO_RESOLVE)) { - thd->host[min(strlen(thd->host), HOSTNAME_LENGTH)]= 0; - thd->host_or_ip= thd->host; + thd->host=ip_to_hostname(&thd->remote.sin_addr,&connect_errors); + /* Cut very long hostnames to avoid possible overflows */ + if (thd->host) + { + thd->host[min(strlen(thd->host), HOSTNAME_LENGTH)]= 0; + thd->host_or_ip= thd->host; + } + if (connect_errors > max_connect_errors) + return(ER_HOST_IS_BLOCKED); } - if (connect_errors > max_connect_errors) - return(ER_HOST_IS_BLOCKED); } DBUG_PRINT("info",("Host: %s ip: %s", thd->host ? thd->host : "unknown host", @@ -547,6 +548,8 @@ check_connections(THD *thd) DBUG_PRINT("info",("Host: %s",thd->host)); thd->host_or_ip= thd->host; thd->ip= 0; + /* Reset sin_addr */ + bzero((char*) &thd->remote, sizeof(thd->remote)); } vio_keepalive(net->vio, TRUE); -- cgit v1.2.1 From 67b16d202b6e6912d6018685a0f7b0bb55cfbbad Mon Sep 17 00:00:00 2001 From: unknown Date: Tue, 15 Feb 2005 16:45:00 +0200 Subject: Fixed failing test cases 'row.test' when running with --ps-protocol Simple optimzations done while reviewing code client/mysqltest.c: Added options --enable-ps-warnings and --disable-ps-warnings (to fix failing test case) mysql-test/t/row.test: Disable warnings that comes from 'parse' parth sql/field.cc: Removed calls to is_null() in field functions. (Not needed as NULL handling is done on the level above fields) Indentation fixes Removed calls to alloca() as buffer needed was quite small. sql/field.h: Indentation changes and comment fixes sql/filesort.cc: Simple optimization during code review sql/item.cc: Indentation fixes Removed some unnecessary tests (added DBUG_ASSERTS() instead) sql/item_buff.cc: Indentation fixes sql/my_decimal.cc: Indentation fixes Simple optimization Fixed compiler warning sql/sql_update.cc: Removed unnessessary assignment --- sql/field.cc | 58 ++++++++++++++++++++----------------------------- sql/field.h | 8 +++++-- sql/filesort.cc | 65 ++++++++++++++++++++++++++++++------------------------- sql/item.cc | 55 +++++++++++++++++++++------------------------- sql/item_buff.cc | 3 +-- sql/my_decimal.cc | 28 ++++++++++++------------ sql/sql_update.cc | 4 +--- 7 files changed, 106 insertions(+), 115 deletions(-) (limited to 'sql') diff --git a/sql/field.cc b/sql/field.cc index bc95e1dab54..f51b06028f7 100644 --- a/sql/field.cc +++ b/sql/field.cc @@ -572,8 +572,7 @@ my_decimal* Field_num::val_decimal(my_decimal *decimal_value) { DBUG_ASSERT(result_type() == INT_RESULT); longlong nr= val_int(); - if (!is_null()) - int2my_decimal(E_DEC_FATAL_ERROR, nr, unsigned_flag, decimal_value); + int2my_decimal(E_DEC_FATAL_ERROR, nr, unsigned_flag, decimal_value); return decimal_value; } @@ -605,7 +604,7 @@ void Field_num::make_field(Send_field *field) d value for storing NOTE - Field_str is the base class for fields like Field_date, and some + Field_str is the base class for fields like Field_enum, Field_date and some similar. Some dates use fraction and also string value should be converted to floating point value according our rules, so we use double to store value of decimal in string @@ -629,8 +628,7 @@ my_decimal *Field_str::val_decimal(my_decimal *decimal_value) { DBUG_ASSERT(result_type() == INT_RESULT); longlong nr= val_int(); - if (is_null()) - int2my_decimal(E_DEC_FATAL_ERROR, nr, 0, decimal_value); + int2my_decimal(E_DEC_FATAL_ERROR, nr, 0, decimal_value); return decimal_value; } @@ -733,6 +731,7 @@ Field *Field::new_key_field(MEM_ROOT *root, struct st_table *new_table, return tmp; } + /* SYNOPSIS Field::quote_data() @@ -749,44 +748,35 @@ Field *Field::new_key_field(MEM_ROOT *root, struct st_table *new_table, void Upon prepending/appending quotes on each side of variable */ + bool Field::quote_data(String *unquoted_string) { char escaped_string[IO_SIZE]; char *unquoted_string_buffer= (char *)(unquoted_string->ptr()); uint need_quotes; - DBUG_ENTER("Field::quote_data"); + // this is the same call that mysql_real_escape_string() calls escape_string_for_mysql(&my_charset_bin, (char *)escaped_string, unquoted_string->ptr(), unquoted_string->length()); - - if (is_null()) - DBUG_RETURN(0); - need_quotes= needs_quotes(); if (need_quotes == 0) - { DBUG_RETURN(0); - } - else - { - // reset string, then re-append with quotes and escaped values - unquoted_string->length(0); - if (unquoted_string->append("'")) - DBUG_RETURN(1); - if (unquoted_string->append((char *)escaped_string)) - DBUG_RETURN(1); - if (unquoted_string->append("'")) - DBUG_RETURN(1); - } - //DBUG_PRINT("Field::quote_data", - // ("FINAL quote_flag %d unquoted_string %s escaped_string %s", - //needs_quotes, unquoted_string->c_ptr_quick(), escaped_string)); + + // reset string, then re-append with quotes and escaped values + unquoted_string->length(0); + if (unquoted_string->append('\'')) + DBUG_RETURN(1); + if (unquoted_string->append((char *)escaped_string)) + DBUG_RETURN(1); + if (unquoted_string->append('\'')) + DBUG_RETURN(1); DBUG_RETURN(0); } + /* Quote a field type if needed @@ -802,6 +792,7 @@ bool Field::quote_data(String *unquoted_string) 0 if value is of type NOT needing quotes 1 if value is of type needing quotes */ + bool Field::needs_quotes(void) { DBUG_ENTER("Field::type_quote"); @@ -840,9 +831,9 @@ bool Field::needs_quotes(void) default: DBUG_RETURN(0); } DBUG_RETURN(0); - } + /**************************************************************************** Field_null, a field that always return NULL ****************************************************************************/ @@ -4646,8 +4637,6 @@ String *Field_newdate::val_str(String *val_buffer, bool Field_newdate::get_date(TIME *ltime,uint fuzzydate) { - if (is_null()) - return 1; uint32 tmp=(uint32) uint3korr(ptr); ltime->day= tmp & 31; ltime->month= (tmp >> 5) & 15; @@ -5058,17 +5047,16 @@ int Field_string::store(longlong nr) return Field_string::store(buff,(uint)l,cs); } + int Field_longstr::store_decimal(const my_decimal *d) { - uint buf_size= my_decimal_string_length(d); - char *buff= (char *)my_alloca(buf_size); - String str(buff, buf_size, &my_charset_bin); + char buff[DECIMAL_MAX_STR_LENGTH+1]; + String str(buff, sizeof(buff), &my_charset_bin); my_decimal2string(E_DEC_FATAL_ERROR, d, 0, 0, 0, &str); - int result= store(str.ptr(), str.length(), str.charset()); - my_afree(buff); - return result; + return store(str.ptr(), str.length(), str.charset()); } + double Field_string::val_real(void) { int not_used; diff --git a/sql/field.h b/sql/field.h index 327fb4c885b..cfed2eb19e1 100644 --- a/sql/field.h +++ b/sql/field.h @@ -367,7 +367,9 @@ public: my_decimal *val_decimal(my_decimal *); }; -/* base class for Item_string, Item_valstring, Item_blob */ + +/* base class for Field_string, Field_varstring and Field_blob */ + class Field_longstr :public Field_str { public: @@ -1181,7 +1183,9 @@ public: bool has_charset(void) const { return charset() == &my_charset_bin ? FALSE : TRUE; } field_cast_enum field_cast_type() { return FIELD_CAST_BLOB; } - uint32 max_length();}; + uint32 max_length(); +}; + #ifdef HAVE_SPATIAL class Field_geom :public Field_blob { diff --git a/sql/filesort.cc b/sql/filesort.cc index 956ac2ef61b..c05baa7cc04 100644 --- a/sql/filesort.cc +++ b/sql/filesort.cc @@ -619,20 +619,21 @@ static void make_sortkey(register SORTPARAM *param, else { // Item Item *item=sort_field->item; + maybe_null= item->maybe_null; switch (sort_field->result_type) { case STRING_RESULT: { CHARSET_INFO *cs=item->collation.collation; char fill_char= ((cs->state & MY_CS_BINSORT) ? (char) 0 : ' '); - if ((maybe_null=item->maybe_null)) + if (maybe_null) *to++=1; /* All item->str() to use some extra byte for end null.. */ String tmp((char*) to,sort_field->length+4,cs); String *res=item->val_str(&tmp); if (!res) { - if (item->maybe_null) + if (maybe_null) bzero((char*) to-1,sort_field->length+1); else { @@ -672,20 +673,22 @@ static void make_sortkey(register SORTPARAM *param, case INT_RESULT: { longlong value=item->val_int(); - if ((maybe_null=item->maybe_null)) + if (maybe_null) + { *to++=1; /* purecov: inspected */ - if (item->null_value) - { - if (item->maybe_null) - bzero((char*) to-1,sort_field->length+1); - else - { - DBUG_PRINT("warning", - ("Got null on something that shouldn't be null")); - bzero((char*) to,sort_field->length); - } - break; - } + if (item->null_value) + { + if (maybe_null) + bzero((char*) to-1,sort_field->length+1); + else + { + DBUG_PRINT("warning", + ("Got null on something that shouldn't be null")); + bzero((char*) to,sort_field->length); + } + break; + } + } #if SIZEOF_LONG_LONG > 4 to[7]= (uchar) value; to[6]= (uchar) (value >> 8); @@ -706,14 +709,16 @@ static void make_sortkey(register SORTPARAM *param, case DECIMAL_RESULT: { my_decimal dec_buf, *dec_val= item->val_decimal(&dec_buf); - if ((maybe_null=item->null_value)) - { - bzero((char*)to, sort_field->length+1); - to++; - break; - } - if ((maybe_null=item->maybe_null)) + if (maybe_null) + { + if (item->null_value) + { + bzero((char*)to, sort_field->length+1); + to++; + break; + } *to++=1; + } my_decimal2binary(E_DEC_FATAL_ERROR, dec_val, (byte*)to, item->max_length - (item->decimals ? 1:0), item->decimals); @@ -722,14 +727,16 @@ static void make_sortkey(register SORTPARAM *param, case REAL_RESULT: { double value= item->val_real(); - if ((maybe_null=item->null_value)) - { - bzero((char*) to,sort_field->length+1); - to++; - break; - } - if ((maybe_null=item->maybe_null)) + if (maybe_null) + { + if (item->null_value) + { + bzero((char*) to,sort_field->length+1); + to++; + break; + } *to++=1; + } change_double_for_sort(value,(byte*) to); break; } diff --git a/sql/item.cc b/sql/item.cc index 53d9d532b3d..4eb4e017ef2 100644 --- a/sql/item.cc +++ b/sql/item.cc @@ -48,10 +48,10 @@ void item_init(void) /* TODO: make this functions class dependent */ + bool Item::val_bool() { - switch(result_type()) - { + switch(result_type()) { case INT_RESULT: return val_int(); case DECIMAL_RESULT: @@ -68,6 +68,7 @@ bool Item::val_bool() case ROW_RESULT: default: DBUG_ASSERT(0); + return 0; // Wrong (but safe) } } @@ -991,8 +992,7 @@ bool Item_field::val_bool_result() { if ((null_value= result_field->is_null())) return FALSE; - switch (result_field->result_type()) - { + switch (result_field->result_type()) { case INT_RESULT: return result_field->val_int(); case DECIMAL_RESULT: @@ -1060,8 +1060,9 @@ Item *Item_field::get_tmp_table_item(THD *thd) /* - Create an item from a string we KNOW points to a valid longlong/ulonglong - end \0 terminated number string + Create an item from a string we KNOW points to a valid longlong + end \0 terminated number string. + This is always 'signed'. Unsigned values are created with Item_uint() */ Item_int::Item_int(const char *str_arg, uint length) @@ -1071,7 +1072,6 @@ Item_int::Item_int(const char *str_arg, uint length) value= my_strtoll10(str_arg, &end_ptr, &error); max_length= (uint) (end_ptr - str_arg); name= (char*) str_arg; - unsigned_flag= value > 0; fixed= 1; } @@ -2436,8 +2436,8 @@ bool Item_field::fix_fields(THD *thd, TABLE_LIST *tables, Item **reference) rf is Item_ref => never substitute other items (in this case) during fix_fields() => we can use rf after fix_fields() */ - if (!rf->fixed && - rf->fix_fields(thd, tables, reference) || rf->check_cols(1)) + DBUG_ASSERT(!rf->fixed); // Assured by Item_ref() + if (rf->fix_fields(thd, tables, reference) || rf->check_cols(1)) return TRUE; mark_as_dependent(thd, last, current_sel, rf); @@ -2458,8 +2458,8 @@ bool Item_field::fix_fields(THD *thd, TABLE_LIST *tables, Item **reference) rf is Item_ref => never substitute other items (in this case) during fix_fields() => we can use rf after fix_fields() */ - return (!rf->fixed && - rf->fix_fields(thd, tables, reference) || rf->check_cols(1)); + DBUG_ASSERT(!rf->fixed); // Assured by Item_ref() + return (rf->fix_fields(thd, tables, reference) || rf->check_cols(1)); } } } @@ -2706,8 +2706,7 @@ void Item_empty_string::make_field(Send_field *tmp_field) enum_field_types Item::field_type() const { - switch (result_type()) - { + switch (result_type()) { case STRING_RESULT: return MYSQL_TYPE_VARCHAR; case INT_RESULT: return FIELD_TYPE_LONGLONG; case DECIMAL_RESULT: return FIELD_TYPE_NEWDECIMAL; @@ -2715,8 +2714,8 @@ enum_field_types Item::field_type() const case ROW_RESULT: default: DBUG_ASSERT(0); - return FIELD_TYPE_VAR_STRING; - }; + return MYSQL_TYPE_VARCHAR; + } } @@ -3662,18 +3661,17 @@ bool Item_ref::val_bool_result() { if ((null_value= result_field->is_null())) return 0; - switch (result_field->result_type()) - { + switch (result_field->result_type()) { case INT_RESULT: return result_field->val_int(); case DECIMAL_RESULT: - { - my_decimal decimal_value; - my_decimal *val= result_field->val_decimal(&decimal_value); - if (val) - return !my_decimal_is_zero(val); - return 0; - } + { + my_decimal decimal_value; + my_decimal *val= result_field->val_decimal(&decimal_value); + if (val) + return !my_decimal_is_zero(val); + return 0; + } case REAL_RESULT: case STRING_RESULT: return result_field->val_real() != 0.0; @@ -4049,8 +4047,7 @@ void resolve_const_item(THD *thd, Item **ref, Item *comp_item) item->result_type()); char *name=item->name; // Alloced by sql_alloc - switch (res_type) - { + switch (res_type) { case STRING_RESULT: { char buff[MAX_FIELD_WIDTH]; @@ -4146,8 +4143,7 @@ bool field_is_equal_to_item(Field *field,Item *item) Item_cache* Item_cache::get_cache(Item_result type) { - switch (type) - { + switch (type) { case INT_RESULT: return new Item_cache_int(); case REAL_RESULT: @@ -4617,8 +4613,7 @@ uint32 Item_type_holder::real_length(Item *item) if (item->type() == Item::FIELD_ITEM) return ((Item_field *)item)->max_disp_length(); - switch (item->result_type()) - { + switch (item->result_type()) { case STRING_RESULT: case DECIMAL_RESULT: return item->max_length; diff --git a/sql/item_buff.cc b/sql/item_buff.cc index 7c77f7fa3bc..af17d377e31 100644 --- a/sql/item_buff.cc +++ b/sql/item_buff.cc @@ -28,8 +28,7 @@ Item_buff *new_Item_buff(Item *item) if (item->type() == Item::FIELD_ITEM && !(((Item_field *) item)->field->flags & BLOB_FLAG)) return new Item_field_buff((Item_field *) item); - switch (item->result_type()) - { + switch (item->result_type()) { case STRING_RESULT: return new Item_str_buff((Item_field *) item); case INT_RESULT: diff --git a/sql/my_decimal.cc b/sql/my_decimal.cc index 027b33f1d1c..f028b1fa1a1 100644 --- a/sql/my_decimal.cc +++ b/sql/my_decimal.cc @@ -23,16 +23,18 @@ decimal_operation_results() result decimal library return code (E_DEC_* see include/decimal.h) - return + TODO + Fix error messages + + RETURN result */ + int decimal_operation_results(int result) { - switch (result) - { + switch (result) { case E_DEC_OK: break; -//TODO: fix error messages case E_DEC_TRUNCATED: push_warning_printf(current_thd, MYSQL_ERROR::WARN_LEVEL_WARN, WARN_DATA_TRUNCATED, ER(WARN_DATA_TRUNCATED), @@ -78,20 +80,18 @@ int decimal_operation_results(int result) */ int my_decimal2string(uint mask, const my_decimal *d, - int fixed_prec, int fixed_dec, - char filler, String *str) + int fixed_prec, int fixed_dec, + char filler, String *str) { int length= (fixed_prec ? (fixed_prec + 1) : my_decimal_string_length(d)); int result; if (str->alloc(length)) - return check_result(mask, E_DEC_OOM); - char *sptr= (char *)str->ptr(); - int res= decimal2string((decimal *)d, sptr, - &length, fixed_prec, fixed_dec, - filler); - result= check_result(mask, res); + return check_result(mask, E_DEC_OOM); + result= decimal2string((decimal*) d, (char*) str->ptr(), + &length, fixed_prec, fixed_dec, + filler); str->length(length); - return result; + return check_result(mask, result); } @@ -171,7 +171,7 @@ int str2my_decimal(uint mask, const char *from, uint length, } my_decimal_set_zero(decimal_value); err= string2decimal((char *)from, (decimal *)decimal_value, &end); - if ((end-from) != length && !err) + if ((uint) (end-from) != length && !err) err= E_DEC_TRUNCATED; check_result(mask, err); return err; diff --git a/sql/sql_update.cc b/sql/sql_update.cc index f9df1be2abd..17179bf9c5f 100644 --- a/sql/sql_update.cc +++ b/sql/sql_update.cc @@ -264,10 +264,8 @@ int mysql_update(THD *thd, else if ((used_index=table->file->key_used_on_scan) < MAX_KEY) used_key_is_modified=check_if_key_used(table, used_index, fields); else - { used_key_is_modified=0; - used_index= MAX_KEY; - } + if (used_key_is_modified || order) { /* -- cgit v1.2.1 From 6992c010292fb005175a4ee41311742aea20046c Mon Sep 17 00:00:00 2001 From: unknown Date: Tue, 15 Feb 2005 19:25:42 +0200 Subject: After merge fixes mysql-test/r/ctype_ucs.result: Fixed warning after merge sql/field.cc: After merge fix sql/item_cmpfunc.cc: Style & comment changes sql/sql_yacc.yy: After merge fix --- sql/field.cc | 2 +- sql/item_cmpfunc.cc | 44 +++++++++++++++++++++++++++----------------- sql/sql_yacc.yy | 2 +- 3 files changed, 29 insertions(+), 19 deletions(-) (limited to 'sql') diff --git a/sql/field.cc b/sql/field.cc index c1520653084..0be72458701 100644 --- a/sql/field.cc +++ b/sql/field.cc @@ -2452,7 +2452,7 @@ int Field_long::store(const char *from,uint len,CHARSET_INFO *cs) from+= tmp; end= (char*) from+len; - tmp= my_strtoll10(from, &end, &error); + tmp= cs->cset->my_strtoll10(cs, from, &end, &error); if (error != MY_ERRNO_EDOM) { diff --git a/sql/item_cmpfunc.cc b/sql/item_cmpfunc.cc index c26365e3f0e..96e91ea27ad 100644 --- a/sql/item_cmpfunc.cc +++ b/sql/item_cmpfunc.cc @@ -273,8 +273,7 @@ int Arg_comparator::set_compare_func(Item_bool_func2 *item, Item_result type) owner= item; func= comparator_matrix[type] [test(owner->functype() == Item_func::EQUAL_FUNC)]; - switch(type) - { + switch(type) { case ROW_RESULT: { uint n= (*a)->cols(); @@ -877,10 +876,20 @@ void Item_func_interval::fix_length_and_dec() /* - return -1 if null value, - 0 if lower than lowest - 1 - arg_count-1 if between args[n] and args[n+1] - arg_count if higher than biggest argument + Execute Item_func_interval() + + SYNOPSIS + Item_func_interval::val_int() + + NOTES + If we are doing a decimal comparison, we are + evaluating the first item twice. + + RETURN + -1 if null value, + 0 if lower than lowest + 1 - arg_count-1 if between args[n] and args[n+1] + arg_count if higher than biggest argument */ longlong Item_func_interval::val_int() @@ -888,11 +897,10 @@ longlong Item_func_interval::val_int() DBUG_ASSERT(fixed == 1); double value= row->el(0)->val_real(); my_decimal dec_buf, *dec= NULL; + uint i; + if (use_decimal_comparison) - { dec= row->el(0)->val_decimal(&dec_buf); - } - uint i; if (row->el(0)->null_value) return -1; // -1 if null @@ -906,6 +914,11 @@ longlong Item_func_interval::val_int() uint mid= (start + end + 1) / 2; interval_range *range= intervals + mid; my_bool cmp_result; + /* + The values in the range intervall may have different types, + Only do a decimal comparision of the first argument is a decimal + and we are comparing against a decimal + */ if (dec && range->type == DECIMAL_RESULT) cmp_result= my_decimal_cmp(&range->dec, dec) <= 0; else @@ -917,7 +930,7 @@ longlong Item_func_interval::val_int() } interval_range *range= intervals+start; return ((dec && range->type == DECIMAL_RESULT) ? - my_decimal_cmp(dec, &range->dec) < 0 : + my_decimal_cmp(dec, &range->dec) < 0 : value < range->dbl) ? 0 : start + 1; } @@ -932,13 +945,13 @@ longlong Item_func_interval::val_int() if (my_decimal_cmp(e_dec, dec) > 0) return i-1; } - else - if (row->el(i)->val_real() > value) - return i-1; + else if (row->el(i)->val_real() > value) + return i-1; } return i-1; } + void Item_func_between::fix_length_and_dec() { max_length= 1; @@ -1087,8 +1100,7 @@ Item_func_ifnull::fix_length_and_dec() args[1]->max_length - args[1]->decimals) + decimals); agg_result_type(&cached_result_type, args, 2); - switch (cached_result_type) - { + switch (cached_result_type) { case STRING_RESULT: agg_arg_charsets(collation, args, arg_count, MY_COLL_CMP_CONV); break; @@ -1166,7 +1178,6 @@ my_decimal *Item_func_ifnull::val_decimal(my_decimal *decimal_value) } - String * Item_func_ifnull::val_str(String *str) { @@ -1456,7 +1467,6 @@ Item *Item_func_case::find_item(String *str) } - String *Item_func_case::val_str(String *str) { DBUG_ASSERT(fixed == 1); diff --git a/sql/sql_yacc.yy b/sql/sql_yacc.yy index 37e1ef70b84..b3d04333695 100644 --- a/sql/sql_yacc.yy +++ b/sql/sql_yacc.yy @@ -5026,7 +5026,7 @@ select_derived: } ; -select_derived: +select_derived2: { LEX *lex= Lex; lex->derived_tables|= DERIVED_SUBQUERY; -- cgit v1.2.1 From c60b1846293a22ab47c99c7001553e3efc3270a0 Mon Sep 17 00:00:00 2001 From: unknown Date: Tue, 15 Feb 2005 19:35:28 +0200 Subject: Safety fix sql/item_cmpfunc.cc: Safety fix Code cleanup --- sql/item_cmpfunc.cc | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'sql') diff --git a/sql/item_cmpfunc.cc b/sql/item_cmpfunc.cc index 96e91ea27ad..0fa7ffcdda8 100644 --- a/sql/item_cmpfunc.cc +++ b/sql/item_cmpfunc.cc @@ -2047,7 +2047,8 @@ int cmp_item_row::compare(cmp_item *c) void cmp_item_decimal::store_value(Item *item) { my_decimal *val= item->val_decimal(&value); - if (val != &value) + /* val may be zero if item is nnull */ + if (val && val != &value) my_decimal2decimal(val, &value); } @@ -2061,9 +2062,9 @@ int cmp_item_decimal::cmp(Item *arg) } -int cmp_item_decimal::compare(cmp_item *c) +int cmp_item_decimal::compare(cmp_item *arg) { - cmp_item_decimal *cmp= (cmp_item_decimal *)c; + cmp_item_decimal *cmp= (cmp_item_decimal*) arg; return my_decimal_cmp(&value, &cmp->value); } -- cgit v1.2.1 From 8ed7805c24efd429831f8485201908716cb3c7e2 Mon Sep 17 00:00:00 2001 From: unknown Date: Tue, 15 Feb 2005 22:06:55 +0300 Subject: Fixing failing -debug build. Since placement operator delete called only if exception was thrown in constructor and we don't use exceptions in MySQL, there is no sense to do anything in String::delete(void *ptr_arg, MEM_ROOT *mem_root). --- sql/sql_string.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'sql') diff --git a/sql/sql_string.h b/sql/sql_string.h index f9f0b1b6242..2debeb61787 100644 --- a/sql/sql_string.h +++ b/sql/sql_string.h @@ -74,7 +74,7 @@ public: static void operator delete(void *ptr_arg,size_t size) { TRASH(ptr_arg, size); } static void operator delete(void *ptr_arg, MEM_ROOT *mem_root) - { TRASH(ptr_arg, size); } + { /* never called */ } ~String() { free(); } inline void set_charset(CHARSET_INFO *charset) { str_charset= charset; } -- cgit v1.2.1 From 04bae3c0ebe100e78d5e04189df88f972d72b5bd Mon Sep 17 00:00:00 2001 From: unknown Date: Wed, 16 Feb 2005 11:19:47 +0400 Subject: Fix - to not to call val_xxx in Item_func_interval twice sql/item_cmpfunc.cc: code fixed not to call val_x twice --- sql/item_cmpfunc.cc | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) (limited to 'sql') diff --git a/sql/item_cmpfunc.cc b/sql/item_cmpfunc.cc index 0fa7ffcdda8..3884cce8451 100644 --- a/sql/item_cmpfunc.cc +++ b/sql/item_cmpfunc.cc @@ -895,15 +895,24 @@ void Item_func_interval::fix_length_and_dec() longlong Item_func_interval::val_int() { DBUG_ASSERT(fixed == 1); - double value= row->el(0)->val_real(); + double value; my_decimal dec_buf, *dec= NULL; uint i; if (use_decimal_comparison) + { dec= row->el(0)->val_decimal(&dec_buf); + if (row->el(0)->null_value) + return -1; + my_decimal2double(E_DEC_FATAL_ERROR, dec, &value); + } + else + { + value= row->el(0)->val_real(); + if (row->el(0)->null_value) + return -1; + } - if (row->el(0)->null_value) - return -1; // -1 if null if (intervals) { // Use binary search to find interval uint start,end; -- cgit v1.2.1 From bcbc61b1b70232b423b95710d2b729a8881744cb Mon Sep 17 00:00:00 2001 From: unknown Date: Wed, 16 Feb 2005 11:44:34 +0400 Subject: Fix for bug #8534 (Compile errors in Precision Math code on Windows) sql/filesort.cc: Type of the parameter changed sql/my_decimal.cc: type of the parameter changed sql/my_decimal.h: Parameter type changed --- sql/filesort.cc | 2 +- sql/my_decimal.cc | 2 +- sql/my_decimal.h | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) (limited to 'sql') diff --git a/sql/filesort.cc b/sql/filesort.cc index c05baa7cc04..de14287003b 100644 --- a/sql/filesort.cc +++ b/sql/filesort.cc @@ -719,7 +719,7 @@ static void make_sortkey(register SORTPARAM *param, } *to++=1; } - my_decimal2binary(E_DEC_FATAL_ERROR, dec_val, (byte*)to, + my_decimal2binary(E_DEC_FATAL_ERROR, dec_val, (char*)to, item->max_length - (item->decimals ? 1:0), item->decimals); break; diff --git a/sql/my_decimal.cc b/sql/my_decimal.cc index f028b1fa1a1..36229d1c795 100644 --- a/sql/my_decimal.cc +++ b/sql/my_decimal.cc @@ -116,7 +116,7 @@ int my_decimal2string(uint mask, const my_decimal *d, E_DEC_OVERFLOW */ -int my_decimal2binary(uint mask, const my_decimal *d, byte *bin, int prec, +int my_decimal2binary(uint mask, const my_decimal *d, char *bin, int prec, int scale) { int err1= E_DEC_OK, err2; diff --git a/sql/my_decimal.h b/sql/my_decimal.h index 63d3fb7e2e5..f4841418074 100644 --- a/sql/my_decimal.h +++ b/sql/my_decimal.h @@ -150,12 +150,12 @@ void my_decimal2decimal(const my_decimal *from, my_decimal *to) } -int my_decimal2binary(uint mask, const my_decimal *d, byte *bin, int prec, +int my_decimal2binary(uint mask, const my_decimal *d, char *bin, int prec, int scale); inline -int binary2my_decimal(uint mask, const byte *bin, my_decimal *d, int prec, +int binary2my_decimal(uint mask, const char *bin, my_decimal *d, int prec, int scale) { return check_result(mask, bin2decimal((char *)bin, (decimal *)d, prec, -- cgit v1.2.1 From 53944e1c22b1e9729276ba4183e2df0d9478e943 Mon Sep 17 00:00:00 2001 From: unknown Date: Wed, 16 Feb 2005 13:00:03 +0300 Subject: Fix for bug#7915: crash,JOIN VIEW, subquery, SELECT .. FROM INFORMATION_SCHEMA.COLUMNS --- sql/sql_lex.cc | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'sql') diff --git a/sql/sql_lex.cc b/sql/sql_lex.cc index 30c657c3b79..08cf4402b74 100644 --- a/sql/sql_lex.cc +++ b/sql/sql_lex.cc @@ -1733,6 +1733,12 @@ bool st_lex::can_not_use_merged() { case SQLCOM_CREATE_VIEW: case SQLCOM_SHOW_CREATE: + /* + SQLCOM_SHOW_FIELDS is necessary to make + information schema tables working correctly with views. + see get_schema_tables_result function + */ + case SQLCOM_SHOW_FIELDS: return TRUE; default: return FALSE; -- cgit v1.2.1