From 51690eca7e933f9e4164ec628b8b10419a089711 Mon Sep 17 00:00:00 2001 From: unknown Date: Tue, 29 Mar 2005 12:37:36 +0300 Subject: Cleanups during review ndb/src/ndbapi/DictCache.cpp: Simpler bit handling code sql/sql_acl.cc: Fix for bool parameter sql/sql_yacc.yy: Removed compiler warning --- sql/sql_acl.cc | 9 ++++++--- sql/sql_yacc.yy | 2 +- 2 files changed, 7 insertions(+), 4 deletions(-) (limited to 'sql') diff --git a/sql/sql_acl.cc b/sql/sql_acl.cc index 0a5939428cd..c98c22c3b91 100644 --- a/sql/sql_acl.cc +++ b/sql/sql_acl.cc @@ -2729,7 +2729,8 @@ bool mysql_table_grant(THD *thd, TABLE_LIST *table_list, pthread_mutex_lock(&acl_cache->lock); error=replace_user_table(thd, tables[0].table, *Str, 0, revoke_grant, create_new_users, - thd->variables.sql_mode & MODE_NO_AUTO_CREATE_USER); + test(thd->variables.sql_mode & + MODE_NO_AUTO_CREATE_USER)); pthread_mutex_unlock(&acl_cache->lock); if (error) { @@ -2935,7 +2936,8 @@ bool mysql_procedure_grant(THD *thd, TABLE_LIST *table_list, pthread_mutex_lock(&acl_cache->lock); error=replace_user_table(thd, tables[0].table, *Str, 0, revoke_grant, create_new_users, - thd->variables.sql_mode & MODE_NO_AUTO_CREATE_USER); + test(thd->variables.sql_mode & + MODE_NO_AUTO_CREATE_USER)); pthread_mutex_unlock(&acl_cache->lock); if (error) { @@ -3061,7 +3063,8 @@ bool mysql_grant(THD *thd, const char *db, List &list, } if (replace_user_table(thd, tables[0].table, *Str, (!db ? rights : 0), revoke_grant, create_new_users, - thd->variables.sql_mode & MODE_NO_AUTO_CREATE_USER)) + test(thd->variables.sql_mode & + MODE_NO_AUTO_CREATE_USER))) result= -1; else if (db) { diff --git a/sql/sql_yacc.yy b/sql/sql_yacc.yy index 8141de31275..bfbe8faebd3 100644 --- a/sql/sql_yacc.yy +++ b/sql/sql_yacc.yy @@ -1398,7 +1398,7 @@ create_function_tail: uint unused1= 0; int unused2= 0; - if (!(new_field= new_create_field(YYTHD, "", + if (!(new_field= new_create_field(YYTHD, (char*) "", (enum enum_field_types)$8, lex->length, lex->dec, lex->type, (Item *)0, (Item *) 0, &cmt, 0, -- cgit v1.2.1 From a5b1b9d92474e4e1e30e7b1a3570cf4531533b03 Mon Sep 17 00:00:00 2001 From: unknown Date: Wed, 30 Mar 2005 16:00:31 +0300 Subject: Give warnings if wrong date/time/datetime argument for STR_TO_DATE Small fixes while doing review of new pushed code More test cases for decimal mysql-test/r/date_formats.result: Warnings added for STR_TO_DATE() mysql-test/r/ps_1general.result: Better description for BLACKHOLE mysql-test/r/strict.result: Added tests for STR_TO_DATE mysql-test/r/type_decimal.result: Test to test ranges of DECIMAL mysql-test/t/date_formats.test: More tests mysql-test/t/strict.test: Added tests for STR_TO_DATE mysql-test/t/type_decimal.test: Test to test ranges of DECIMAL sql/field.cc: Simple optimization sql/handler.cc: Better description for BLACKHOLE sql/item_timefunc.cc: Give warnings if wrong date/time/datetime argument for STR_TO_DATE sql/log_event.cc: Indentation fixes sql/log_event.h: #ifdef-ed not used code sql/share/errmsg.txt: New error message sql/sql_show.cc: Ensure that we do a proper restore in case of error --- sql/field.cc | 4 +++- sql/handler.cc | 3 ++- sql/item_timefunc.cc | 32 +++++++++++++++++++++++--------- sql/log_event.cc | 20 +++++++++++--------- sql/log_event.h | 2 ++ sql/share/errmsg.txt | 2 ++ sql/sql_show.cc | 7 ++++--- 7 files changed, 47 insertions(+), 23 deletions(-) (limited to 'sql') diff --git a/sql/field.cc b/sql/field.cc index b8d17f1b7d2..3de839ddc3a 100644 --- a/sql/field.cc +++ b/sql/field.cc @@ -7000,8 +7000,10 @@ longlong Field_bit::val_int(void) { ulonglong bits= 0; if (bit_len) + { bits= get_rec_bits(bit_ptr, bit_ofs, bit_len); - bits<<= (field_length * 8); + bits<<= (field_length * 8); + } switch (field_length) { case 0: return bits; diff --git a/sql/handler.cc b/sql/handler.cc index 4a01003f418..143e56fdc7c 100644 --- a/sql/handler.cc +++ b/sql/handler.cc @@ -107,7 +107,8 @@ struct show_table_type_st sys_table_types[]= {"FEDERATED",&have_federated_db, "Federated MySQL storage engine", DB_TYPE_FEDERATED_DB}, {"BLACKHOLE",&have_blackhole_db, - "Storage engine designed to act as null storage", DB_TYPE_BLACKHOLE_DB}, + "/dev/null storage engine (anything you write to it disappears)", + DB_TYPE_BLACKHOLE_DB}, {NullS, NULL, NullS, DB_TYPE_UNKNOWN} }; diff --git a/sql/item_timefunc.cc b/sql/item_timefunc.cc index 3d1feee1f8c..c603d41fa2e 100644 --- a/sql/item_timefunc.cc +++ b/sql/item_timefunc.cc @@ -160,7 +160,8 @@ static DATE_TIME_FORMAT time_24hrs_format= {{0}, '\0', 0, static bool extract_date_time(DATE_TIME_FORMAT *format, const char *val, uint length, TIME *l_time, timestamp_type cached_timestamp_type, - const char **sub_pattern_end) + const char **sub_pattern_end, + const char *date_time_type) { int weekday= 0, yearday= 0, daypart= 0; int week_number= -1; @@ -188,12 +189,12 @@ static bool extract_date_time(DATE_TIME_FORMAT *format, for (; ptr != end && val != val_end; ptr++) { - if (*ptr == '%' && ptr+1 != end) { int val_len; char *tmp; + error= 0; /* Skip pre-space between each argument */ while (val != val_end && my_isspace(cs, *val)) val++; @@ -343,16 +344,22 @@ static bool extract_date_time(DATE_TIME_FORMAT *format, /* Time in AM/PM notation */ case 'r': - error= extract_date_time(&time_ampm_format, val, - (uint)(val_end - val), l_time, - cached_timestamp_type, &val); + /* + We can't just set error here, as we don't want to generate two + warnings in case of errors + */ + if (extract_date_time(&time_ampm_format, val, + (uint)(val_end - val), l_time, + cached_timestamp_type, &val, "time")) + DBUG_RETURN(1); break; /* Time in 24-hour notation */ case 'T': - error= extract_date_time(&time_24hrs_format, val, - (uint)(val_end - val), l_time, - cached_timestamp_type, &val); + if (extract_date_time(&time_24hrs_format, val, + (uint)(val_end - val), l_time, + cached_timestamp_type, &val, "time")) + DBUG_RETURN(1); break; /* Conversion specifiers that match classes of characters */ @@ -471,6 +478,13 @@ static bool extract_date_time(DATE_TIME_FORMAT *format, DBUG_RETURN(0); err: + { + char buff[128]; + strmake(buff, val_begin, min(length, sizeof(buff)-1)); + push_warning_printf(current_thd, MYSQL_ERROR::WARN_LEVEL_ERROR, + ER_WRONG_VALUE_FOR_TYPE, ER(ER_WRONG_VALUE_FOR_TYPE), + date_time_type, buff, "str_to_time"); + } DBUG_RETURN(1); } @@ -2972,7 +2986,7 @@ bool Item_func_str_to_date::get_date(TIME *ltime, uint fuzzy_date) date_time_format.format.str= (char*) format->ptr(); date_time_format.format.length= format->length(); if (extract_date_time(&date_time_format, val->ptr(), val->length(), - ltime, cached_timestamp_type, 0)) + ltime, cached_timestamp_type, 0, "datetime")) goto null_date; if (cached_timestamp_type == MYSQL_TIMESTAMP_TIME && ltime->day) { diff --git a/sql/log_event.cc b/sql/log_event.cc index cf145e33d1e..f5e39b166fb 100644 --- a/sql/log_event.cc +++ b/sql/log_event.cc @@ -1052,17 +1052,17 @@ bool Query_log_event::write(IO_CACHE* file) of this x>=4 master segfault (expecting a zero when there is none). Remaining compatibility problems are: the older slave will not find the catalog; but it is will not crash, and it's not an issue - that it does not find the catalog as catalogs were not used in these older - MySQL versions (we store it in binlog and read it from relay log but do - nothing useful with it). What is an issue is that the older slave will - stop processing the Q_* blocks (and jumps to the db/query) as soon as it - sees unknown Q_CATALOG_NZ_CODE; so it will not be able to read + that it does not find the catalog as catalogs were not used in these + older MySQL versions (we store it in binlog and read it from relay log + but do nothing useful with it). What is an issue is that the older slave + will stop processing the Q_* blocks (and jumps to the db/query) as soon + as it sees unknown Q_CATALOG_NZ_CODE; so it will not be able to read Q_AUTO_INCREMENT*, Q_CHARSET and so replication will fail silently in various ways. Documented that you should not mix alpha/beta versions if they are not exactly the same version, with example of 5.0.2<->5.0.3 and 5.0.3<->5.0.4. If replication is from older to new, the new won't find the catalog and will have the same problems. - */ + */ } if (auto_increment_increment != 1) { @@ -1264,7 +1264,7 @@ Query_log_event::Query_log_event(const char* buf, uint event_len, } case Q_CATALOG_NZ_CODE: if ((catalog_len= *pos)) - catalog= (char*) pos+1; // Will be copied later + catalog= (char*) pos+1; // Will be copied later pos+= catalog_len+1; break; case Q_AUTO_INCREMENT: @@ -4192,7 +4192,8 @@ int Append_block_log_event::exec_event(struct st_relay_log_info* rli) goto err; } } - else if ((fd = my_open(fname, O_WRONLY|O_APPEND|O_BINARY|O_NOFOLLOW, MYF(MY_WME))) < 0) + else if ((fd = my_open(fname, O_WRONLY | O_APPEND | O_BINARY | O_NOFOLLOW, + MYF(MY_WME))) < 0) { slave_print_error(rli, my_errno, "Error in %s event: could not open file '%s'", @@ -4405,7 +4406,8 @@ int Execute_load_log_event::exec_event(struct st_relay_log_info* rli) Load_log_event* lev = 0; memcpy(p, ".info", 6); - if ((fd = my_open(fname, O_RDONLY|O_BINARY|O_NOFOLLOW, MYF(MY_WME))) < 0 || + if ((fd = my_open(fname, O_RDONLY | O_BINARY | O_NOFOLLOW, + MYF(MY_WME))) < 0 || init_io_cache(&file, fd, IO_SIZE, READ_CACHE, (my_off_t)0, 0, MYF(MY_WME|MY_NABP))) { diff --git a/sql/log_event.h b/sql/log_event.h index ba5d74b1784..1f82f40ed11 100644 --- a/sql/log_event.h +++ b/sql/log_event.h @@ -234,11 +234,13 @@ struct sql_ex_info /* these are codes, not offsets; not more than 256 values (1 byte). */ #define Q_FLAGS2_CODE 0 #define Q_SQL_MODE_CODE 1 +#ifdef TO_BE_DELETED /* Q_CATALOG_CODE is catalog with end zero stored; it is used only by MySQL 5.0.x where 0<=x<=3. */ #define Q_CATALOG_CODE 2 +#endif #define Q_AUTO_INCREMENT 3 #define Q_CHARSET_CODE 4 #define Q_TIME_ZONE_CODE 5 diff --git a/sql/share/errmsg.txt b/sql/share/errmsg.txt index 6b254f47284..82e9bbc1c68 100644 --- a/sql/share/errmsg.txt +++ b/sql/share/errmsg.txt @@ -5334,3 +5334,5 @@ ER_LOAD_FROM_FIXED_SIZE_ROWS_TO_VAR eng "Can't load value from file with fixed size rows to variable" ER_CANT_CREATE_USER_WITH_GRANT 42000 eng "You are not allowed to create a user with GRANT" +ER_WRONG_VALUE_FOR_TYPE + eng "Incorrect %-.32s value: '%-.128s' for function %-.32s" diff --git a/sql/sql_show.cc b/sql/sql_show.cc index bd0b8926c6a..263f907f277 100644 --- a/sql/sql_show.cc +++ b/sql/sql_show.cc @@ -1615,10 +1615,11 @@ typedef struct st_index_field_values SYNOPSIS schema_table_store_record() thd thread handler - table I_S table + table Information schema table to be updated + RETURN - 1 error 0 success + 1 error */ static bool schema_table_store_record(THD *thd, TABLE *table) @@ -1959,7 +1960,7 @@ int get_all_tables(THD *thd, TABLE_LIST *tables, COND *cond) } } if (schema_table_store_record(thd, table)) - DBUG_RETURN(error); + goto err; } else { -- cgit v1.2.1 From a593a0a739e8846de7ea641a144a92f8753c3984 Mon Sep 17 00:00:00 2001 From: unknown Date: Wed, 30 Mar 2005 23:41:42 +0300 Subject: Enabled more tests of STR_TO_DATE() Fixed that datetime gives warning for zero dates in traditional mode mysql-test/r/strict.result: Enabled more tests of STR_TO_DATE() mysql-test/t/strict.test: Enabled more tests of STR_TO_DATE() sql/field.cc: Fixed that datetime gives warning for zero dates in traditional mode sql/log_event.h: Fix wrong ifdef from last push --- sql/field.cc | 18 +++++++++++------- sql/log_event.h | 2 +- 2 files changed, 12 insertions(+), 8 deletions(-) (limited to 'sql') diff --git a/sql/field.cc b/sql/field.cc index 3de839ddc3a..7850daac8c7 100644 --- a/sql/field.cc +++ b/sql/field.cc @@ -4699,15 +4699,19 @@ int Field_datetime::store(const char *from,uint len,CHARSET_INFO *cs) TIME time_tmp; int error; ulonglong tmp= 0; + enum enum_mysql_timestamp_type func_res; - if (str_to_datetime(from, len, &time_tmp, - (TIME_FUZZY_DATE | - (table->in_use->variables.sql_mode & - (MODE_NO_ZERO_IN_DATE | MODE_NO_ZERO_DATE | - MODE_INVALID_DATES))), - &error) > MYSQL_TIMESTAMP_ERROR) + func_res= str_to_datetime(from, len, &time_tmp, + (TIME_FUZZY_DATE | + (table->in_use->variables.sql_mode & + (MODE_NO_ZERO_IN_DATE | MODE_NO_ZERO_DATE | + MODE_INVALID_DATES))), + &error); + if ((int) func_res > (int) MYSQL_TIMESTAMP_ERROR) tmp= TIME_to_ulonglong_datetime(&time_tmp); - + else + error= 1; // Fix if invalid zero date + if (error) set_datetime_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, diff --git a/sql/log_event.h b/sql/log_event.h index 1f82f40ed11..2985fcabb50 100644 --- a/sql/log_event.h +++ b/sql/log_event.h @@ -234,7 +234,7 @@ struct sql_ex_info /* these are codes, not offsets; not more than 256 values (1 byte). */ #define Q_FLAGS2_CODE 0 #define Q_SQL_MODE_CODE 1 -#ifdef TO_BE_DELETED +#ifndef TO_BE_DELETED /* Q_CATALOG_CODE is catalog with end zero stored; it is used only by MySQL 5.0.x where 0<=x<=3. -- cgit v1.2.1