From 3e7a57632a508381f80aba5a503eb4f3fc3babb6 Mon Sep 17 00:00:00 2001 From: unknown Date: Fri, 24 Jun 2005 17:14:16 -0700 Subject: [PATCH 01/18] Fix handling of datadir by mysqld_safe to support specifying a different DATADIR via the command line or during ./configure and still starting up mysqld_safe via a relative path. (Bug #7249) scripts/mysqld_safe.sh: Decouple figuring out which BASEDIR and DATADIR to use so that the only DATADIR we'll try to use without first verifying that it exists is the compiled-in default. --- scripts/mysqld_safe.sh | 40 +++++++++++++++++++++++++++++----------- 1 file changed, 29 insertions(+), 11 deletions(-) diff --git a/scripts/mysqld_safe.sh b/scripts/mysqld_safe.sh index 8a232f4f7f9..d6585f4a552 100644 --- a/scripts/mysqld_safe.sh +++ b/scripts/mysqld_safe.sh @@ -84,31 +84,49 @@ parse_arguments() { } +# +# First, try to find BASEDIR and ledir (where mysqld is) +# + MY_PWD=`pwd` -# Check if we are starting this relative (for the binary release) -if test -f ./share/mysql/english/errmsg.sys -a \ - -x ./bin/mysqld +# Check for the directories we would expect from a binary release install +if test -f ./share/mysql/english/errmsg.sys -a -x ./bin/mysqld then MY_BASEDIR_VERSION=$MY_PWD # Where bin, share and data are ledir=$MY_BASEDIR_VERSION/bin # Where mysqld is - DATADIR=$MY_BASEDIR_VERSION/data - if test -z "$defaults" - then - defaults="--defaults-extra-file=$MY_BASEDIR_VERSION/data/my.cnf" - fi -# Check if this is a 'moved install directory' +# Check for the directories we would expect from a source install elif test -f ./share/mysql/english/errmsg.sys -a \ -x ./libexec/mysqld then MY_BASEDIR_VERSION=$MY_PWD # Where libexec, share and var are ledir=$MY_BASEDIR_VERSION/libexec # Where mysqld is - DATADIR=$MY_BASEDIR_VERSION/var +# Since we didn't find anything, used the compiled-in defaults else MY_BASEDIR_VERSION=@prefix@ - DATADIR=@localstatedir@ ledir=@libexecdir@ fi +# +# Second, try to find the data directory +# + +# Try where the binary installs put it +if test -d $MY_BASEDIR_VERSION/data/mysql +then + DATADIR=$MY_BASEDIR_VERSION/data + if test -z "$defaults" + then + defaults="--defaults-extra-file=$DATADIR/my.cnf" + fi +# Next try where the source installs put it +elif test -d $MY_BASEDIR_VERSION/var/mysql +then + DATADIR=$MY_BASEDIR_VERSION/var +# Or just give up and use our compiled-in default +else + DATADIR=@localstatedir@ +fi + user=@MYSQLD_USER@ niceness=0 From 831e2c7f61f664b606d7702740665402a5a25ac3 Mon Sep 17 00:00:00 2001 From: unknown Date: Tue, 12 Jul 2005 08:35:30 -0600 Subject: [PATCH 02/18] Bug #7142 Show Fields from fails using Borland's dbExpress interface The problem here is that columns that have an especially long type such as an enum type with many options would be longer than 40 chars but the type column returned from show columns always was defined as varchar(40). This is fixed in 5.0 using info schema. mysql-test/r/ps_1general.result: update columns which will now be reported as blobs mysql-test/r/ps_2myisam.result: update columns which will now be reported as blobs mysql-test/r/ps_3innodb.result: update columns which will now be reported as blobs mysql-test/r/ps_4heap.result: update columns which will now be reported as blobs mysql-test/r/ps_5merge.result: update columns which will now be reported as blobs sql/item.cc: report a column as a particular blob type if it's size warrants sql/sql_show.cc: Add function to iterate over all the fields of a table and determine the longest type name. We call this function at the top of our show fields code. We pass in either 40 or max_len whichever is longer to the ctor of Item_empty_string. tests/mysql_client_test.c: update columns which will now be reported as blobs --- mysql-test/r/ps_1general.result | 12 ++++++------ mysql-test/r/ps_2myisam.result | 6 +++--- mysql-test/r/ps_3innodb.result | 6 +++--- mysql-test/r/ps_4heap.result | 6 +++--- mysql-test/r/ps_5merge.result | 12 ++++++------ sql/item.cc | 9 ++++++++- sql/sql_show.cc | 31 ++++++++++++++++++++++++++++++- tests/mysql_client_test.c | 6 +++--- 8 files changed, 62 insertions(+), 26 deletions(-) diff --git a/mysql-test/r/ps_1general.result b/mysql-test/r/ps_1general.result index db8dc2e60af..97af043d4f2 100644 --- a/mysql-test/r/ps_1general.result +++ b/mysql-test/r/ps_1general.result @@ -470,12 +470,12 @@ def id 8 3 1 N 32929 0 63 def select_type 253 19 6 N 1 31 8 def table 253 64 2 Y 0 31 8 def type 253 10 3 Y 0 31 8 -def possible_keys 253 4096 0 Y 0 31 8 +def possible_keys 252 4096 0 Y 0 31 8 def key 253 64 0 Y 0 31 8 def key_len 8 3 0 Y 32928 0 63 -def ref 253 1024 0 Y 0 31 8 +def ref 252 1024 0 Y 0 31 8 def rows 8 10 1 Y 32928 0 63 -def Extra 253 255 14 N 1 31 8 +def Extra 252 255 14 N 1 31 8 id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t1 ALL NULL NULL NULL NULL 4 Using filesort SET @arg00=1 ; @@ -486,12 +486,12 @@ def id 8 3 1 N 32929 0 63 def select_type 253 19 6 N 1 31 8 def table 253 64 2 Y 0 31 8 def type 253 10 5 Y 0 31 8 -def possible_keys 253 4096 7 Y 0 31 8 +def possible_keys 252 4096 7 Y 0 31 8 def key 253 64 7 Y 0 31 8 def key_len 8 3 1 Y 32928 0 63 -def ref 253 1024 0 Y 0 31 8 +def ref 252 1024 0 Y 0 31 8 def rows 8 10 1 Y 32928 0 63 -def Extra 253 255 27 N 1 31 8 +def Extra 252 255 27 N 1 31 8 id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t1 range PRIMARY PRIMARY 4 NULL 3 Using where; Using filesort drop table if exists t2; diff --git a/mysql-test/r/ps_2myisam.result b/mysql-test/r/ps_2myisam.result index c569c9842f7..bae8143b8b5 100644 --- a/mysql-test/r/ps_2myisam.result +++ b/mysql-test/r/ps_2myisam.result @@ -1153,12 +1153,12 @@ def id 8 3 1 N 32929 0 63 def select_type 253 19 6 N 1 31 8 def table 253 64 2 Y 0 31 8 def type 253 10 3 Y 0 31 8 -def possible_keys 253 4096 0 Y 0 31 8 +def possible_keys 252 4096 0 Y 0 31 8 def key 253 64 0 Y 0 31 8 def key_len 8 3 0 Y 32928 0 63 -def ref 253 1024 0 Y 0 31 8 +def ref 252 1024 0 Y 0 31 8 def rows 8 10 1 Y 32928 0 63 -def Extra 253 255 0 N 1 31 8 +def Extra 252 255 0 N 1 31 8 id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t9 ALL NULL NULL NULL NULL 2 drop table if exists t2 ; diff --git a/mysql-test/r/ps_3innodb.result b/mysql-test/r/ps_3innodb.result index 930aea2e381..8acbf070336 100644 --- a/mysql-test/r/ps_3innodb.result +++ b/mysql-test/r/ps_3innodb.result @@ -1153,12 +1153,12 @@ def id 8 3 1 N 32929 0 63 def select_type 253 19 6 N 1 31 8 def table 253 64 2 Y 0 31 8 def type 253 10 3 Y 0 31 8 -def possible_keys 253 4096 0 Y 0 31 8 +def possible_keys 252 4096 0 Y 0 31 8 def key 253 64 0 Y 0 31 8 def key_len 8 3 0 Y 32928 0 63 -def ref 253 1024 0 Y 0 31 8 +def ref 252 1024 0 Y 0 31 8 def rows 8 10 1 Y 32928 0 63 -def Extra 253 255 0 N 1 31 8 +def Extra 252 255 0 N 1 31 8 id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t9 ALL NULL NULL NULL NULL 2 test_sequence diff --git a/mysql-test/r/ps_4heap.result b/mysql-test/r/ps_4heap.result index 083a4b221fe..314e644a675 100644 --- a/mysql-test/r/ps_4heap.result +++ b/mysql-test/r/ps_4heap.result @@ -1154,12 +1154,12 @@ def id 8 3 1 N 32929 0 63 def select_type 253 19 6 N 1 31 8 def table 253 64 2 Y 0 31 8 def type 253 10 3 Y 0 31 8 -def possible_keys 253 4096 0 Y 0 31 8 +def possible_keys 252 4096 0 Y 0 31 8 def key 253 64 0 Y 0 31 8 def key_len 8 3 0 Y 32928 0 63 -def ref 253 1024 0 Y 0 31 8 +def ref 252 1024 0 Y 0 31 8 def rows 8 10 1 Y 32928 0 63 -def Extra 253 255 0 N 1 31 8 +def Extra 252 255 0 N 1 31 8 id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t9 ALL NULL NULL NULL NULL 2 test_sequence diff --git a/mysql-test/r/ps_5merge.result b/mysql-test/r/ps_5merge.result index 1edd617ffc6..9d620290f00 100644 --- a/mysql-test/r/ps_5merge.result +++ b/mysql-test/r/ps_5merge.result @@ -1196,12 +1196,12 @@ def id 8 3 1 N 32929 0 63 def select_type 253 19 6 N 1 31 8 def table 253 64 2 Y 0 31 8 def type 253 10 3 Y 0 31 8 -def possible_keys 253 4096 0 Y 0 31 8 +def possible_keys 252 4096 0 Y 0 31 8 def key 253 64 0 Y 0 31 8 def key_len 8 3 0 Y 32928 0 63 -def ref 253 1024 0 Y 0 31 8 +def ref 252 1024 0 Y 0 31 8 def rows 8 10 1 Y 32928 0 63 -def Extra 253 255 0 N 1 31 8 +def Extra 252 255 0 N 1 31 8 id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t9 ALL NULL NULL NULL NULL 2 test_sequence @@ -4210,12 +4210,12 @@ def id 8 3 1 N 32929 0 63 def select_type 253 19 6 N 1 31 8 def table 253 64 2 Y 0 31 8 def type 253 10 3 Y 0 31 8 -def possible_keys 253 4096 0 Y 0 31 8 +def possible_keys 252 4096 0 Y 0 31 8 def key 253 64 0 Y 0 31 8 def key_len 8 3 0 Y 32928 0 63 -def ref 253 1024 0 Y 0 31 8 +def ref 252 1024 0 Y 0 31 8 def rows 8 10 1 Y 32928 0 63 -def Extra 253 255 0 N 1 31 8 +def Extra 252 255 0 N 1 31 8 id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t9 ALL NULL NULL NULL NULL 2 test_sequence diff --git a/sql/item.cc b/sql/item.cc index c96794ff482..d13127e4952 100644 --- a/sql/item.cc +++ b/sql/item.cc @@ -1768,7 +1768,14 @@ void Item::make_field(Send_field *tmp_field) void Item_empty_string::make_field(Send_field *tmp_field) { - init_make_field(tmp_field,FIELD_TYPE_VAR_STRING); + enum_field_types type = FIELD_TYPE_VAR_STRING; + if (max_length >= 16777216) + type = FIELD_TYPE_LONG_BLOB; + else if (max_length >= 65536) + type = FIELD_TYPE_MEDIUM_BLOB; + else if (max_length >= 256) + type = FIELD_TYPE_BLOB; + init_make_field(tmp_field, type); } diff --git a/sql/sql_show.cc b/sql/sql_show.cc index 7e0ee0dab68..03b12468b92 100644 --- a/sql/sql_show.cc +++ b/sql/sql_show.cc @@ -638,6 +638,30 @@ int mysqld_extend_show_tables(THD *thd,const char *db,const char *wild) DBUG_RETURN(0); } +/* +returns the length of the longest type on the given table. +This is used so that show fields will return the data using the proper +lengths instead of forcing columns such as type to always return with a +given length. +*/ +uint get_longest_type_in_table(TABLE *table, const char *wild) +{ + Field **ptr,*field; + char tmp[MAX_FIELD_WIDTH]; + uint max_len = 0; + + for (ptr=table->field; (field= *ptr); ptr++) + { + if (!wild || !wild[0] || + !wild_case_compare(system_charset_info, field->field_name,wild)) + { + String type(tmp,sizeof(tmp), system_charset_info); + field->sql_type(type); + max_len = max(max_len, type.length()); + } + } + return max_len; +} /*************************************************************************** ** List all columns in a table_list->real_name @@ -667,9 +691,14 @@ mysqld_show_fields(THD *thd, TABLE_LIST *table_list,const char *wild, #ifndef NO_EMBEDDED_ACCESS_CHECKS (void) get_table_grant(thd, table_list); #endif + + /* we scan for the longest since long enum types can exceed 40 */ + uint max_len = get_longest_type_in_table(table, wild); + List field_list; field_list.push_back(new Item_empty_string("Field",NAME_LEN)); - field_list.push_back(new Item_empty_string("Type",40)); + field_list.push_back(new Item_empty_string("Type", + max_len > 40 ? max_len : 40)); if (verbose) field_list.push_back(new Item_empty_string("Collation",40)); field_list.push_back(new Item_empty_string("Null",1)); diff --git a/tests/mysql_client_test.c b/tests/mysql_client_test.c index dbee6e77e4f..b7232565e0b 100644 --- a/tests/mysql_client_test.c +++ b/tests/mysql_client_test.c @@ -7173,7 +7173,7 @@ static void test_explain_bug() verify_prepare_field(result, 3, "type", "", MYSQL_TYPE_VAR_STRING, "", "", "", 10, 0); - verify_prepare_field(result, 4, "possible_keys", "", MYSQL_TYPE_VAR_STRING, + verify_prepare_field(result, 4, "possible_keys", "", MYSQL_TYPE_BLOB, "", "", "", NAME_LEN*64, 0); verify_prepare_field(result, 5, "key", "", MYSQL_TYPE_VAR_STRING, @@ -7186,13 +7186,13 @@ static void test_explain_bug() (mysql_get_server_version(mysql) <= 50000 ? 3 : 4096), 0); - verify_prepare_field(result, 7, "ref", "", MYSQL_TYPE_VAR_STRING, + verify_prepare_field(result, 7, "ref", "", MYSQL_TYPE_BLOB, "", "", "", NAME_LEN*16, 0); verify_prepare_field(result, 8, "rows", "", MYSQL_TYPE_LONGLONG, "", "", "", 10, 0); - verify_prepare_field(result, 9, "Extra", "", MYSQL_TYPE_VAR_STRING, + verify_prepare_field(result, 9, "Extra", "", MYSQL_TYPE_BLOB, "", "", "", 255, 0); mysql_free_result(result); From 5958f22a622bdf62b0a426b4184c20f4c962a7e2 Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 18 Jul 2005 16:12:44 -0700 Subject: [PATCH 03/18] Fix number to date conversion so it always honors the NO_ZERO_DATE, NO_ZERO_IN_DATE, and INVALID_DATES bits of SQL_MODE. (Bug #5906) include/my_time.h: Pass flags to number_to_datetime() so it can check things like NO_ZERO_DATE. libmysql/libmysql.c: Enable fuzzy date handling when converting strings and numbers to datetime fields. mysql-test/r/ps_2myisam.result: Update results mysql-test/r/ps_3innodb.result: Update results mysql-test/r/ps_4heap.result: Update results mysql-test/r/ps_5merge.result: Update results mysql-test/r/ps_6bdb.result: Update results mysql-test/r/ps_7ndb.result: Update results mysql-test/r/strict.result: Update results mysql-test/r/timezone2.result: Update results mysql-test/r/type_datetime.result: Update results mysql-test/t/strict.test: Add new regression test mysql-test/t/timezone2.test: Add new test of timestamp values in DST gap sql-common/my_time.c: Expand check_date() to check NO_ZERO_DATE and NO_ZERO_IN_DATE, and use it from number_to_datetime() as well as str_to_datetime(). Also, make number_to_datetime() return -1 on error so we can distinguish between a violation of NO_ZERO_DATE and other errors. sql/field.cc: Update conversion of numbers to date, datetime, and timestamp to use number_to_datetime() and report errors and warnings correctly and consistently. --- include/my_time.h | 2 +- libmysql/libmysql.c | 5 +- mysql-test/r/ps_2myisam.result | 8 +- mysql-test/r/ps_3innodb.result | 8 +- mysql-test/r/ps_4heap.result | 8 +- mysql-test/r/ps_5merge.result | 16 +-- mysql-test/r/ps_6bdb.result | 8 +- mysql-test/r/ps_7ndb.result | 8 +- mysql-test/r/strict.result | 13 ++ mysql-test/r/timezone2.result | 9 ++ mysql-test/r/type_datetime.result | 12 +- mysql-test/t/strict.test | 15 +++ mysql-test/t/timezone2.test | 5 + sql-common/my_time.c | 89 +++++++------ sql/field.cc | 207 +++++++++++++----------------- 15 files changed, 219 insertions(+), 194 deletions(-) diff --git a/include/my_time.h b/include/my_time.h index 8058df8fe4e..aa68a6f0bbd 100644 --- a/include/my_time.h +++ b/include/my_time.h @@ -53,7 +53,7 @@ enum enum_mysql_timestamp_type str_to_datetime(const char *str, uint length, MYSQL_TIME *l_time, uint flags, int *was_cut); longlong number_to_datetime(longlong nr, MYSQL_TIME *time_res, - my_bool fuzzy_date, int *was_cut); + uint flags, int *was_cut); ulonglong TIME_to_ulonglong_datetime(const MYSQL_TIME *time); ulonglong TIME_to_ulonglong_date(const MYSQL_TIME *time); ulonglong TIME_to_ulonglong_time(const MYSQL_TIME *time); diff --git a/libmysql/libmysql.c b/libmysql/libmysql.c index 2074abd0f85..4127600babc 100644 --- a/libmysql/libmysql.c +++ b/libmysql/libmysql.c @@ -3600,7 +3600,7 @@ static void fetch_string_with_conversion(MYSQL_BIND *param, char *value, case MYSQL_TYPE_TIMESTAMP: { MYSQL_TIME *tm= (MYSQL_TIME *)buffer; - (void) str_to_datetime(value, length, tm, 0, &err); + (void) str_to_datetime(value, length, tm, TIME_FUZZY_DATE, &err); *param->error= test(err) && (param->buffer_type == MYSQL_TYPE_DATE && tm->time_type != MYSQL_TIMESTAMP_DATE); break; @@ -3718,7 +3718,8 @@ static void fetch_long_with_conversion(MYSQL_BIND *param, MYSQL_FIELD *field, case MYSQL_TYPE_DATETIME: { int error; - value= number_to_datetime(value, (MYSQL_TIME *) buffer, 1, &error); + value= number_to_datetime(value, (MYSQL_TIME *) buffer, TIME_FUZZY_DATE, + &error); *param->error= test(error); break; } diff --git a/mysql-test/r/ps_2myisam.result b/mysql-test/r/ps_2myisam.result index a9342636349..4f512f08961 100644 --- a/mysql-test/r/ps_2myisam.result +++ b/mysql-test/r/ps_2myisam.result @@ -2976,25 +2976,25 @@ Warnings: Warning 1265 Data truncated for column 'c17' at row 1 Warnings: Warning 1264 Out of range value adjusted for column 'c13' at row 1 -Warning 1265 Data truncated for column 'c14' at row 1 +Warning 1264 Out of range value adjusted for column 'c14' at row 1 Warning 1265 Data truncated for column 'c15' at row 1 Warning 1264 Out of range value adjusted for column 'c16' at row 1 Warning 1264 Out of range value adjusted for column 'c17' at row 1 Warnings: Warning 1264 Out of range value adjusted for column 'c13' at row 1 -Warning 1265 Data truncated for column 'c14' at row 1 +Warning 1264 Out of range value adjusted for column 'c14' at row 1 Warning 1265 Data truncated for column 'c15' at row 1 Warning 1264 Out of range value adjusted for column 'c16' at row 1 Warning 1264 Out of range value adjusted for column 'c17' at row 1 Warnings: Warning 1264 Out of range value adjusted for column 'c13' at row 1 -Warning 1265 Data truncated for column 'c14' at row 1 +Warning 1264 Out of range value adjusted for column 'c14' at row 1 Warning 1265 Data truncated for column 'c15' at row 1 Warning 1264 Out of range value adjusted for column 'c16' at row 1 Warning 1264 Out of range value adjusted for column 'c17' at row 1 Warnings: Warning 1264 Out of range value adjusted for column 'c13' at row 1 -Warning 1265 Data truncated for column 'c14' at row 1 +Warning 1264 Out of range value adjusted for column 'c14' at row 1 Warning 1265 Data truncated for column 'c15' at row 1 Warning 1264 Out of range value adjusted for column 'c16' at row 1 Warning 1264 Out of range value adjusted for column 'c17' at row 1 diff --git a/mysql-test/r/ps_3innodb.result b/mysql-test/r/ps_3innodb.result index 3a470d218d1..457e19eca5e 100644 --- a/mysql-test/r/ps_3innodb.result +++ b/mysql-test/r/ps_3innodb.result @@ -2959,25 +2959,25 @@ Warnings: Warning 1265 Data truncated for column 'c17' at row 1 Warnings: Warning 1264 Out of range value adjusted for column 'c13' at row 1 -Warning 1265 Data truncated for column 'c14' at row 1 +Warning 1264 Out of range value adjusted for column 'c14' at row 1 Warning 1265 Data truncated for column 'c15' at row 1 Warning 1264 Out of range value adjusted for column 'c16' at row 1 Warning 1264 Out of range value adjusted for column 'c17' at row 1 Warnings: Warning 1264 Out of range value adjusted for column 'c13' at row 1 -Warning 1265 Data truncated for column 'c14' at row 1 +Warning 1264 Out of range value adjusted for column 'c14' at row 1 Warning 1265 Data truncated for column 'c15' at row 1 Warning 1264 Out of range value adjusted for column 'c16' at row 1 Warning 1264 Out of range value adjusted for column 'c17' at row 1 Warnings: Warning 1264 Out of range value adjusted for column 'c13' at row 1 -Warning 1265 Data truncated for column 'c14' at row 1 +Warning 1264 Out of range value adjusted for column 'c14' at row 1 Warning 1265 Data truncated for column 'c15' at row 1 Warning 1264 Out of range value adjusted for column 'c16' at row 1 Warning 1264 Out of range value adjusted for column 'c17' at row 1 Warnings: Warning 1264 Out of range value adjusted for column 'c13' at row 1 -Warning 1265 Data truncated for column 'c14' at row 1 +Warning 1264 Out of range value adjusted for column 'c14' at row 1 Warning 1265 Data truncated for column 'c15' at row 1 Warning 1264 Out of range value adjusted for column 'c16' at row 1 Warning 1264 Out of range value adjusted for column 'c17' at row 1 diff --git a/mysql-test/r/ps_4heap.result b/mysql-test/r/ps_4heap.result index beeaff05ece..614ad09515a 100644 --- a/mysql-test/r/ps_4heap.result +++ b/mysql-test/r/ps_4heap.result @@ -2960,25 +2960,25 @@ Warnings: Warning 1265 Data truncated for column 'c17' at row 1 Warnings: Warning 1264 Out of range value adjusted for column 'c13' at row 1 -Warning 1265 Data truncated for column 'c14' at row 1 +Warning 1264 Out of range value adjusted for column 'c14' at row 1 Warning 1265 Data truncated for column 'c15' at row 1 Warning 1264 Out of range value adjusted for column 'c16' at row 1 Warning 1264 Out of range value adjusted for column 'c17' at row 1 Warnings: Warning 1264 Out of range value adjusted for column 'c13' at row 1 -Warning 1265 Data truncated for column 'c14' at row 1 +Warning 1264 Out of range value adjusted for column 'c14' at row 1 Warning 1265 Data truncated for column 'c15' at row 1 Warning 1264 Out of range value adjusted for column 'c16' at row 1 Warning 1264 Out of range value adjusted for column 'c17' at row 1 Warnings: Warning 1264 Out of range value adjusted for column 'c13' at row 1 -Warning 1265 Data truncated for column 'c14' at row 1 +Warning 1264 Out of range value adjusted for column 'c14' at row 1 Warning 1265 Data truncated for column 'c15' at row 1 Warning 1264 Out of range value adjusted for column 'c16' at row 1 Warning 1264 Out of range value adjusted for column 'c17' at row 1 Warnings: Warning 1264 Out of range value adjusted for column 'c13' at row 1 -Warning 1265 Data truncated for column 'c14' at row 1 +Warning 1264 Out of range value adjusted for column 'c14' at row 1 Warning 1265 Data truncated for column 'c15' at row 1 Warning 1264 Out of range value adjusted for column 'c16' at row 1 Warning 1264 Out of range value adjusted for column 'c17' at row 1 diff --git a/mysql-test/r/ps_5merge.result b/mysql-test/r/ps_5merge.result index fada983a561..d07b84a08a3 100644 --- a/mysql-test/r/ps_5merge.result +++ b/mysql-test/r/ps_5merge.result @@ -2896,25 +2896,25 @@ Warnings: Warning 1265 Data truncated for column 'c17' at row 1 Warnings: Warning 1264 Out of range value adjusted for column 'c13' at row 1 -Warning 1265 Data truncated for column 'c14' at row 1 +Warning 1264 Out of range value adjusted for column 'c14' at row 1 Warning 1265 Data truncated for column 'c15' at row 1 Warning 1264 Out of range value adjusted for column 'c16' at row 1 Warning 1264 Out of range value adjusted for column 'c17' at row 1 Warnings: Warning 1264 Out of range value adjusted for column 'c13' at row 1 -Warning 1265 Data truncated for column 'c14' at row 1 +Warning 1264 Out of range value adjusted for column 'c14' at row 1 Warning 1265 Data truncated for column 'c15' at row 1 Warning 1264 Out of range value adjusted for column 'c16' at row 1 Warning 1264 Out of range value adjusted for column 'c17' at row 1 Warnings: Warning 1264 Out of range value adjusted for column 'c13' at row 1 -Warning 1265 Data truncated for column 'c14' at row 1 +Warning 1264 Out of range value adjusted for column 'c14' at row 1 Warning 1265 Data truncated for column 'c15' at row 1 Warning 1264 Out of range value adjusted for column 'c16' at row 1 Warning 1264 Out of range value adjusted for column 'c17' at row 1 Warnings: Warning 1264 Out of range value adjusted for column 'c13' at row 1 -Warning 1265 Data truncated for column 'c14' at row 1 +Warning 1264 Out of range value adjusted for column 'c14' at row 1 Warning 1265 Data truncated for column 'c15' at row 1 Warning 1264 Out of range value adjusted for column 'c16' at row 1 Warning 1264 Out of range value adjusted for column 'c17' at row 1 @@ -5908,25 +5908,25 @@ Warnings: Warning 1265 Data truncated for column 'c17' at row 1 Warnings: Warning 1264 Out of range value adjusted for column 'c13' at row 1 -Warning 1265 Data truncated for column 'c14' at row 1 +Warning 1264 Out of range value adjusted for column 'c14' at row 1 Warning 1265 Data truncated for column 'c15' at row 1 Warning 1264 Out of range value adjusted for column 'c16' at row 1 Warning 1264 Out of range value adjusted for column 'c17' at row 1 Warnings: Warning 1264 Out of range value adjusted for column 'c13' at row 1 -Warning 1265 Data truncated for column 'c14' at row 1 +Warning 1264 Out of range value adjusted for column 'c14' at row 1 Warning 1265 Data truncated for column 'c15' at row 1 Warning 1264 Out of range value adjusted for column 'c16' at row 1 Warning 1264 Out of range value adjusted for column 'c17' at row 1 Warnings: Warning 1264 Out of range value adjusted for column 'c13' at row 1 -Warning 1265 Data truncated for column 'c14' at row 1 +Warning 1264 Out of range value adjusted for column 'c14' at row 1 Warning 1265 Data truncated for column 'c15' at row 1 Warning 1264 Out of range value adjusted for column 'c16' at row 1 Warning 1264 Out of range value adjusted for column 'c17' at row 1 Warnings: Warning 1264 Out of range value adjusted for column 'c13' at row 1 -Warning 1265 Data truncated for column 'c14' at row 1 +Warning 1264 Out of range value adjusted for column 'c14' at row 1 Warning 1265 Data truncated for column 'c15' at row 1 Warning 1264 Out of range value adjusted for column 'c16' at row 1 Warning 1264 Out of range value adjusted for column 'c17' at row 1 diff --git a/mysql-test/r/ps_6bdb.result b/mysql-test/r/ps_6bdb.result index 404c25c2c37..a8bc8649f6a 100644 --- a/mysql-test/r/ps_6bdb.result +++ b/mysql-test/r/ps_6bdb.result @@ -2959,25 +2959,25 @@ Warnings: Warning 1265 Data truncated for column 'c17' at row 1 Warnings: Warning 1264 Out of range value adjusted for column 'c13' at row 1 -Warning 1265 Data truncated for column 'c14' at row 1 +Warning 1264 Out of range value adjusted for column 'c14' at row 1 Warning 1265 Data truncated for column 'c15' at row 1 Warning 1264 Out of range value adjusted for column 'c16' at row 1 Warning 1264 Out of range value adjusted for column 'c17' at row 1 Warnings: Warning 1264 Out of range value adjusted for column 'c13' at row 1 -Warning 1265 Data truncated for column 'c14' at row 1 +Warning 1264 Out of range value adjusted for column 'c14' at row 1 Warning 1265 Data truncated for column 'c15' at row 1 Warning 1264 Out of range value adjusted for column 'c16' at row 1 Warning 1264 Out of range value adjusted for column 'c17' at row 1 Warnings: Warning 1264 Out of range value adjusted for column 'c13' at row 1 -Warning 1265 Data truncated for column 'c14' at row 1 +Warning 1264 Out of range value adjusted for column 'c14' at row 1 Warning 1265 Data truncated for column 'c15' at row 1 Warning 1264 Out of range value adjusted for column 'c16' at row 1 Warning 1264 Out of range value adjusted for column 'c17' at row 1 Warnings: Warning 1264 Out of range value adjusted for column 'c13' at row 1 -Warning 1265 Data truncated for column 'c14' at row 1 +Warning 1264 Out of range value adjusted for column 'c14' at row 1 Warning 1265 Data truncated for column 'c15' at row 1 Warning 1264 Out of range value adjusted for column 'c16' at row 1 Warning 1264 Out of range value adjusted for column 'c17' at row 1 diff --git a/mysql-test/r/ps_7ndb.result b/mysql-test/r/ps_7ndb.result index ffddec6d5c2..b507064b702 100644 --- a/mysql-test/r/ps_7ndb.result +++ b/mysql-test/r/ps_7ndb.result @@ -2959,25 +2959,25 @@ Warnings: Warning 1265 Data truncated for column 'c17' at row 1 Warnings: Warning 1264 Out of range value adjusted for column 'c13' at row 1 -Warning 1265 Data truncated for column 'c14' at row 1 +Warning 1264 Out of range value adjusted for column 'c14' at row 1 Warning 1265 Data truncated for column 'c15' at row 1 Warning 1264 Out of range value adjusted for column 'c16' at row 1 Warning 1264 Out of range value adjusted for column 'c17' at row 1 Warnings: Warning 1264 Out of range value adjusted for column 'c13' at row 1 -Warning 1265 Data truncated for column 'c14' at row 1 +Warning 1264 Out of range value adjusted for column 'c14' at row 1 Warning 1265 Data truncated for column 'c15' at row 1 Warning 1264 Out of range value adjusted for column 'c16' at row 1 Warning 1264 Out of range value adjusted for column 'c17' at row 1 Warnings: Warning 1264 Out of range value adjusted for column 'c13' at row 1 -Warning 1265 Data truncated for column 'c14' at row 1 +Warning 1264 Out of range value adjusted for column 'c14' at row 1 Warning 1265 Data truncated for column 'c15' at row 1 Warning 1264 Out of range value adjusted for column 'c16' at row 1 Warning 1264 Out of range value adjusted for column 'c17' at row 1 Warnings: Warning 1264 Out of range value adjusted for column 'c13' at row 1 -Warning 1265 Data truncated for column 'c14' at row 1 +Warning 1264 Out of range value adjusted for column 'c14' at row 1 Warning 1265 Data truncated for column 'c15' at row 1 Warning 1264 Out of range value adjusted for column 'c16' at row 1 Warning 1264 Out of range value adjusted for column 'c17' at row 1 diff --git a/mysql-test/r/strict.result b/mysql-test/r/strict.result index d7ad803b828..fa7b86388ef 100644 --- a/mysql-test/r/strict.result +++ b/mysql-test/r/strict.result @@ -1235,3 +1235,16 @@ create table t1(a varchar(65537)); ERROR 42000: Column length too big for column 'a' (max = 65535); use BLOB or TEXT instead create table t1(a varbinary(65537)); ERROR 42000: Column length too big for column 'a' (max = 65535); use BLOB or TEXT instead +set @@sql_mode='traditional'; +create table t1 (d date); +insert into t1 values ('2000-10-00'); +ERROR 22007: Incorrect date value: '2000-10-00' for column 'd' at row 1 +insert into t1 values (1000); +ERROR 22007: Incorrect date value: '1000' for column 'd' at row 1 +insert into t1 values ('2000-10-01'); +update t1 set d = 1100; +ERROR 22007: Incorrect date value: '1100' for column 'd' at row 1 +select * from t1; +d +2000-10-01 +drop table t1; diff --git a/mysql-test/r/timezone2.result b/mysql-test/r/timezone2.result index a90bdf9ad5b..df51a6aac9b 100644 --- a/mysql-test/r/timezone2.result +++ b/mysql-test/r/timezone2.result @@ -40,6 +40,12 @@ insert into t1 (i, ts) values Warnings: Warning 1299 Invalid TIMESTAMP value in column 'ts' at row 2 insert into t1 (i, ts) values +(unix_timestamp(20030330015959),20030330015959), +(unix_timestamp(20030330023000),20030330023000), +(unix_timestamp(20030330030000),20030330030000); +Warnings: +Warning 1299 Invalid TIMESTAMP value in column 'ts' at row 2 +insert into t1 (i, ts) values (unix_timestamp('2003-05-01 00:00:00'),'2003-05-01 00:00:00'); insert into t1 (i, ts) values (unix_timestamp('2003-10-26 01:00:00'),'2003-10-26 01:00:00'), @@ -54,6 +60,9 @@ i ts 1048985999 2003-03-30 00:59:59 1048986000 2003-03-30 01:00:00 1048986000 2003-03-30 01:00:00 +1048985999 2003-03-30 00:59:59 +1048986000 2003-03-30 01:00:00 +1048986000 2003-03-30 01:00:00 1051740000 2003-04-30 22:00:00 1067122800 2003-10-25 23:00:00 1067126400 2003-10-26 00:00:00 diff --git a/mysql-test/r/type_datetime.result b/mysql-test/r/type_datetime.result index 98f7829ca1c..33c7e837997 100644 --- a/mysql-test/r/type_datetime.result +++ b/mysql-test/r/type_datetime.result @@ -100,12 +100,12 @@ create table t1 (t datetime); insert into t1 values (20030102030460),(20030102036301),(20030102240401), (20030132030401),(20031302030401),(100001202030401); Warnings: -Warning 1265 Data truncated for column 't' at row 1 -Warning 1265 Data truncated for column 't' at row 2 -Warning 1265 Data truncated for column 't' at row 3 -Warning 1265 Data truncated for column 't' at row 4 -Warning 1265 Data truncated for column 't' at row 5 -Warning 1265 Data truncated for column 't' at row 6 +Warning 1264 Out of range value adjusted for column 't' at row 1 +Warning 1264 Out of range value adjusted for column 't' at row 2 +Warning 1264 Out of range value adjusted for column 't' at row 3 +Warning 1264 Out of range value adjusted for column 't' at row 4 +Warning 1264 Out of range value adjusted for column 't' at row 5 +Warning 1264 Out of range value adjusted for column 't' at row 6 select * from t1; t 0000-00-00 00:00:00 diff --git a/mysql-test/t/strict.test b/mysql-test/t/strict.test index 302acc9bef2..74c27c488db 100644 --- a/mysql-test/t/strict.test +++ b/mysql-test/t/strict.test @@ -1093,3 +1093,18 @@ set @@sql_mode='traditional'; create table t1(a varchar(65537)); --error 1074 create table t1(a varbinary(65537)); + +# +# Bug #5906: handle invalid date due to conversion +# +set @@sql_mode='traditional'; +create table t1 (d date); +--error 1292 +insert into t1 values ('2000-10-00'); +--error 1292 +insert into t1 values (1000); +insert into t1 values ('2000-10-01'); +--error 1292 +update t1 set d = 1100; +select * from t1; +drop table t1; diff --git a/mysql-test/t/timezone2.test b/mysql-test/t/timezone2.test index 0b5aaed5d30..40fcd153877 100644 --- a/mysql-test/t/timezone2.test +++ b/mysql-test/t/timezone2.test @@ -48,6 +48,11 @@ insert into t1 (i, ts) values (unix_timestamp('2003-03-30 01:59:59'),'2003-03-30 01:59:59'), (unix_timestamp('2003-03-30 02:30:00'),'2003-03-30 02:30:00'), (unix_timestamp('2003-03-30 03:00:00'),'2003-03-30 03:00:00'); +# Values around and in spring time-gap +insert into t1 (i, ts) values + (unix_timestamp(20030330015959),20030330015959), + (unix_timestamp(20030330023000),20030330023000), + (unix_timestamp(20030330030000),20030330030000); # Normal value with DST insert into t1 (i, ts) values (unix_timestamp('2003-05-01 00:00:00'),'2003-05-01 00:00:00'); diff --git a/sql-common/my_time.c b/sql-common/my_time.c index 1078259f15d..c00c0e7be83 100644 --- a/sql-common/my_time.c +++ b/sql-common/my_time.c @@ -56,11 +56,14 @@ uint calc_days_in_year(uint year) } /* - check date. + Check datetime value for validity according to flags. - SYNOPOSIS - bool check_date() - time Date to check. + SYNOPSIS + check_date() + ltime - Date to check. + not_zero_date - ltime is not the zero date + flags - flags to check + was_cut - set to whether the value was truncated NOTES Here we assume that year and month is ok ! @@ -69,18 +72,35 @@ uint calc_days_in_year(uint year) RETURN 0 ok - 1 errro + 1 error */ -bool check_date(MYSQL_TIME *ltime) +bool check_date(const MYSQL_TIME *ltime, bool not_zero_date, ulong flags, + int *was_cut) { - if (ltime->month && ltime->day > days_in_month[ltime->month-1]) + + if (not_zero_date) { - if (ltime->month != 2 || calc_days_in_year(ltime->year) != 366 || - ltime->day != 29) - return 1; + if ((((flags & TIME_NO_ZERO_IN_DATE) || !(flags & TIME_FUZZY_DATE)) && + (ltime->month == 0 || ltime->day == 0)) || + (!(flags & TIME_INVALID_DATES) && + ltime->month && ltime->day > days_in_month[ltime->month-1] && + (ltime->month != 2 || calc_days_in_year(ltime->year) != 366 || + ltime->day != 29))) + { + *was_cut= 2; + return TRUE; + } } - return 0; + else if (flags & TIME_NO_ZERO_DATE) + { + /* + We don't set *was_cut here to signal that the problem was a zero date + and not an invalid date + */ + return TRUE; + } + return FALSE; } @@ -100,7 +120,7 @@ bool check_date(MYSQL_TIME *ltime) TIME_INVALID_DATES Allow 2000-02-31 was_cut 0 Value ok 1 If value was cut during conversion - 2 Date part was withing ranges but date was wrong + 2 Date part was within ranges but date was wrong DESCRIPTION At least the following formats are recogniced (based on number of digits) @@ -168,8 +188,6 @@ str_to_datetime(const char *str, uint length, MYSQL_TIME *l_time, *was_cut= 1; DBUG_RETURN(MYSQL_TIMESTAMP_NONE); } - if (flags & TIME_NO_ZERO_IN_DATE) - flags&= ~TIME_FUZZY_DATE; is_internal_format= 0; /* This has to be changed if want to activate different timestamp formats */ @@ -385,22 +403,10 @@ str_to_datetime(const char *str, uint length, MYSQL_TIME *l_time, if (year_length == 2 && not_zero_date) l_time->year+= (l_time->year < YY_PART_YEAR ? 2000 : 1900); - if (!not_zero_date && (flags & TIME_NO_ZERO_DATE)) - { - /* - We don't set *was_cut here to signal that the problem was a zero date - and not an invalid date - */ - goto err; - } - if (number_of_fields < 3 || l_time->year > 9999 || l_time->month > 12 || l_time->day > 31 || l_time->hour > 23 || - l_time->minute > 59 || l_time->second > 59 || - (!(flags & TIME_FUZZY_DATE) && (l_time->month == 0 || - l_time->day == 0) && - not_zero_date)) + l_time->minute > 59 || l_time->second > 59) { /* Only give warning for a zero date if there is some garbage after */ if (!not_zero_date) /* If zero date */ @@ -418,15 +424,12 @@ str_to_datetime(const char *str, uint length, MYSQL_TIME *l_time, goto err; } + if (check_date(l_time, not_zero_date, flags, was_cut)) + goto err; + l_time->time_type= (number_of_fields <= 3 ? MYSQL_TIMESTAMP_DATE : MYSQL_TIMESTAMP_DATETIME); - if (not_zero_date && !(flags & TIME_INVALID_DATES) && check_date(l_time)) - { - *was_cut= 2; /* Not correct date */ - goto err; - } - for (; str != end ; str++) { if (!my_isspace(&my_charset_latin1,*str)) @@ -881,9 +884,10 @@ int my_TIME_to_str(const MYSQL_TIME *l_time, char *to) number_to_datetime() nr - datetime value as number time_res - pointer for structure for broken-down representation - fuzzy_date - indicates whenever we allow fuzzy dates - was_cut - set ot 1 if there was some kind of error during - conversion or to 0 if everything was OK. + flags - flags to use in validating date, as in str_to_datetime() + was_cut 0 Value ok + 1 If value was cut during conversion + 2 Date part was within ranges but date was wrong DESCRIPTION Convert a datetime value of formats YYMMDD, YYYYMMDD, YYMMDDHHMSS, @@ -893,12 +897,13 @@ int my_TIME_to_str(const MYSQL_TIME *l_time, char *to) This function also checks if datetime value fits in DATETIME range. RETURN VALUE + -1 Timestamp with wrong values + anything else DATETIME as integer in YYYYMMDDHHMMSS format Datetime value in YYYYMMDDHHMMSS format. - If input value is not valid datetime value then 0 is returned. */ longlong number_to_datetime(longlong nr, MYSQL_TIME *time_res, - my_bool fuzzy_date, int *was_cut) + uint flags, int *was_cut) { long part1,part2; @@ -952,13 +957,17 @@ longlong number_to_datetime(longlong nr, MYSQL_TIME *time_res, if (time_res->year <= 9999 && time_res->month <= 12 && time_res->day <= 31 && time_res->hour <= 23 && time_res->minute <= 59 && time_res->second <= 59 && - (fuzzy_date || (time_res->month != 0 && time_res->day != 0) || nr==0)) + !check_date(time_res, (nr != 0), flags, was_cut)) return nr; + /* Don't want to have was_cut get set if NO_ZERO_DATE was violated. */ + if (!nr && flags & TIME_NO_ZERO_DATE) + return LL(-1); + err: *was_cut= 1; - return LL(0); + return LL(-1); } diff --git a/sql/field.cc b/sql/field.cc index 925fca8ac43..7a818fa481d 100644 --- a/sql/field.cc +++ b/sql/field.cc @@ -4469,13 +4469,13 @@ int Field_timestamp::store(const char *from,uint len,CHARSET_INFO *cs) bool in_dst_time_gap; THD *thd= table->in_use; + /* We don't want to store invalid or fuzzy datetime values in TIMESTAMP */ have_smth_to_conv= (str_to_datetime(from, len, &l_time, - ((table->in_use->variables.sql_mode & - MODE_NO_ZERO_DATE) | - MODE_NO_ZERO_IN_DATE), - &error) > + (table->in_use->variables.sql_mode & + MODE_NO_ZERO_DATE) | + MODE_NO_ZERO_IN_DATE, &error) > MYSQL_TIMESTAMP_ERROR); - + if (error || !have_smth_to_conv) { error= 1; @@ -4488,16 +4488,15 @@ int Field_timestamp::store(const char *from,uint len,CHARSET_INFO *cs) { if (!(tmp= TIME_to_timestamp(thd, &l_time, &in_dst_time_gap))) { - set_datetime_warning(MYSQL_ERROR::WARN_LEVEL_WARN, + set_datetime_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, from, len, MYSQL_TIMESTAMP_DATETIME, !error); - error= 1; } else if (in_dst_time_gap) { set_datetime_warning(MYSQL_ERROR::WARN_LEVEL_WARN, - ER_WARN_INVALID_TIMESTAMP, + ER_WARN_INVALID_TIMESTAMP, from, len, MYSQL_TIMESTAMP_DATETIME, !error); error= 1; } @@ -4522,8 +4521,8 @@ int Field_timestamp::store(double nr) int error= 0; if (nr < 0 || nr > 99991231235959.0) { - set_datetime_warning(MYSQL_ERROR::WARN_LEVEL_WARN, - ER_WARN_DATA_OUT_OF_RANGE, + set_datetime_warning(MYSQL_ERROR::WARN_LEVEL_WARN, + ER_WARN_DATA_OUT_OF_RANGE, nr, MYSQL_TIMESTAMP_DATETIME); nr= 0; // Avoid overflow on buff error= 1; @@ -4541,35 +4540,35 @@ int Field_timestamp::store(longlong nr) bool in_dst_time_gap; THD *thd= table->in_use; - if (number_to_datetime(nr, &l_time, 0, &error)) + /* We don't want to store invalid or fuzzy datetime values in TIMESTAMP */ + long tmp= number_to_datetime(nr, &l_time, (thd->variables.sql_mode & + MODE_NO_ZERO_DATE) | + MODE_NO_ZERO_IN_DATE, &error); + if (tmp < 0) + { + error= 2; + } + + if (!error && tmp) { if (!(timestamp= TIME_to_timestamp(thd, &l_time, &in_dst_time_gap))) { - set_datetime_warning(MYSQL_ERROR::WARN_LEVEL_WARN, - ER_WARN_DATA_OUT_OF_RANGE, - nr, MYSQL_TIMESTAMP_DATETIME, 1); + set_datetime_warning(MYSQL_ERROR::WARN_LEVEL_WARN, + ER_WARN_DATA_OUT_OF_RANGE, + nr, MYSQL_TIMESTAMP_DATETIME, 1); error= 1; } - if (in_dst_time_gap) { set_datetime_warning(MYSQL_ERROR::WARN_LEVEL_WARN, - ER_WARN_INVALID_TIMESTAMP, - nr, MYSQL_TIMESTAMP_DATETIME, !error); + ER_WARN_INVALID_TIMESTAMP, + nr, MYSQL_TIMESTAMP_DATETIME, 1); error= 1; } - } - else if (error) - set_datetime_warning(MYSQL_ERROR::WARN_LEVEL_WARN, + } else if (error) + set_datetime_warning(MYSQL_ERROR::WARN_LEVEL_WARN, WARN_DATA_TRUNCATED, nr, MYSQL_TIMESTAMP_DATETIME, 1); - if (!error && timestamp == 0 && - (table->in_use->variables.sql_mode & MODE_NO_ZERO_DATE)) - { - set_datetime_warning(MYSQL_ERROR::WARN_LEVEL_WARN, - WARN_DATA_TRUNCATED, - nr, MYSQL_TIMESTAMP_DATETIME, 1); - } #ifdef WORDS_BIGENDIAN if (table->s->db_low_byte_first) @@ -4579,7 +4578,7 @@ int Field_timestamp::store(longlong nr) else #endif longstore(ptr,(uint32) timestamp); - + return error; } @@ -5152,14 +5151,14 @@ int Field_date::store(const char *from, uint len,CHARSET_INFO *cs) TIME l_time; uint32 tmp; int error; - + if (str_to_datetime(from, len, &l_time, 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) { - tmp=0; + tmp= 0; error= 2; } else @@ -5190,56 +5189,50 @@ int Field_date::store(double nr) if (nr < 0.0 || nr > 99991231.0) { tmp=0L; - set_datetime_warning(MYSQL_ERROR::WARN_LEVEL_WARN, - ER_WARN_DATA_OUT_OF_RANGE, + set_datetime_warning(MYSQL_ERROR::WARN_LEVEL_WARN, + ER_WARN_DATA_OUT_OF_RANGE, nr, MYSQL_TIMESTAMP_DATE); error= 1; } else tmp=(long) rint(nr); - /* - We don't need to check for zero dates here as this date type is only - used in .frm tables from very old MySQL versions - */ - -#ifdef WORDS_BIGENDIAN - if (table->s->db_low_byte_first) - { - int4store(ptr,tmp); - } - else -#endif - longstore(ptr,tmp); - return error; + return Field_date::store(tmp); } int Field_date::store(longlong nr) { - long tmp; - int error= 0; - if (nr >= LL(19000000000000) && nr < LL(99991231235959)) - nr=nr/LL(1000000); // Timestamp to date - if (nr < 0 || nr > LL(99991231)) + TIME not_used; + int error; + longlong initial_nr= nr; + + nr= number_to_datetime(nr, ¬_used, (TIME_FUZZY_DATE | + (table->in_use->variables.sql_mode & + (MODE_NO_ZERO_IN_DATE | + MODE_NO_ZERO_DATE | + MODE_INVALID_DATES))), &error); + + if (nr < 0) { - tmp=0L; - set_datetime_warning(MYSQL_ERROR::WARN_LEVEL_WARN, - ER_WARN_DATA_OUT_OF_RANGE, - nr, MYSQL_TIMESTAMP_DATE, 0); - error= 1; + nr= 0; + error= 2; } - else - tmp=(long) nr; + + if (error) + set_datetime_warning(MYSQL_ERROR::WARN_LEVEL_WARN, + error == 2 ? ER_WARN_DATA_OUT_OF_RANGE : + WARN_DATA_TRUNCATED, initial_nr, + MYSQL_TIMESTAMP_DATETIME, 1); #ifdef WORDS_BIGENDIAN if (table->s->db_low_byte_first) { - int4store(ptr,tmp); + int4store(ptr, nr); } else #endif - longstore(ptr,tmp); + longstore(ptr, nr); return error; } @@ -5363,7 +5356,7 @@ int Field_newdate::store(const char *from,uint len,CHARSET_INFO *cs) MODE_INVALID_DATES))), &error) <= MYSQL_TIMESTAMP_ERROR) { - tmp=0L; + tmp= 0L; error= 2; } else @@ -5372,7 +5365,7 @@ int Field_newdate::store(const char *from,uint len,CHARSET_INFO *cs) if (error) set_datetime_warning(MYSQL_ERROR::WARN_LEVEL_WARN, WARN_DATA_TRUNCATED, from, len, MYSQL_TIMESTAMP_DATE, 1); - + int3store(ptr,tmp); return error; } @@ -5383,7 +5376,7 @@ int Field_newdate::store(double nr) if (nr < 0.0 || nr > 99991231235959.0) { int3store(ptr,(int32) 0); - set_datetime_warning(MYSQL_ERROR::WARN_LEVEL_WARN, + set_datetime_warning(MYSQL_ERROR::WARN_LEVEL_WARN, WARN_DATA_TRUNCATED, nr, MYSQL_TIMESTAMP_DATE); return 1; } @@ -5393,52 +5386,28 @@ int Field_newdate::store(double nr) int Field_newdate::store(longlong nr) { - int32 tmp; - int error= 0; - if (nr >= LL(100000000) && nr <= LL(99991231235959)) - nr=nr/LL(1000000); // Timestamp to date - if (nr < 0L || nr > 99991231L) + TIME l_time; + long tmp; + int error; + if ((tmp= number_to_datetime(nr, &l_time, + (TIME_FUZZY_DATE | + (table->in_use->variables.sql_mode & + (MODE_NO_ZERO_IN_DATE | MODE_NO_ZERO_DATE | + MODE_INVALID_DATES))), + &error) < 0)) { - tmp=0; - set_datetime_warning(MYSQL_ERROR::WARN_LEVEL_WARN, - ER_WARN_DATA_OUT_OF_RANGE, nr, - MYSQL_TIMESTAMP_DATE, 1); - error= 1; + tmp= 0L; + error= 2; } else - { - uint month, day; + tmp= l_time.day + l_time.month*32 + l_time.year*16*32; - tmp=(int32) nr; - if (tmp) - { - if (tmp < YY_PART_YEAR*10000L) // Fix short dates - tmp+= (uint32) 20000000L; - else if (tmp < 999999L) - tmp+= (uint32) 19000000L; + if (error) + set_datetime_warning(MYSQL_ERROR::WARN_LEVEL_WARN, + error == 2 ? ER_WARN_DATA_OUT_OF_RANGE : + WARN_DATA_TRUNCATED,nr,MYSQL_TIMESTAMP_DATE, 1); - month= (uint) ((tmp/100) % 100); - day= (uint) (tmp%100); - if (month > 12 || day > 31) - { - tmp=0L; // Don't allow date to change - set_datetime_warning(MYSQL_ERROR::WARN_LEVEL_WARN, - ER_WARN_DATA_OUT_OF_RANGE, nr, - MYSQL_TIMESTAMP_DATE, 1); - error= 1; - } - else - tmp= day + month*32 + (tmp/10000)*16*32; - } - else if (table->in_use->variables.sql_mode & MODE_NO_ZERO_DATE) - { - set_datetime_warning(MYSQL_ERROR::WARN_LEVEL_WARN, - ER_WARN_DATA_OUT_OF_RANGE, - 0, MYSQL_TIMESTAMP_DATE); - error= 1; - } - } - int3store(ptr, tmp); + int3store(ptr,tmp); return error; } @@ -5565,7 +5534,7 @@ int Field_datetime::store(const char *from,uint len,CHARSET_INFO *cs) int error; ulonglong tmp= 0; enum enum_mysql_timestamp_type func_res; - + func_res= str_to_datetime(from, len, &time_tmp, (TIME_FUZZY_DATE | (table->in_use->variables.sql_mode & @@ -5578,7 +5547,7 @@ int Field_datetime::store(const char *from,uint len,CHARSET_INFO *cs) error= 1; // Fix if invalid zero date if (error) - set_datetime_warning(MYSQL_ERROR::WARN_LEVEL_WARN, + set_datetime_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, from, len, MYSQL_TIMESTAMP_DATETIME, 1); @@ -5615,20 +5584,24 @@ int Field_datetime::store(longlong nr) TIME not_used; int error; longlong initial_nr= nr; - - nr= number_to_datetime(nr, ¬_used, 1, &error); + + nr= number_to_datetime(nr, ¬_used, (TIME_FUZZY_DATE | + (table->in_use->variables.sql_mode & + (MODE_NO_ZERO_IN_DATE | + MODE_NO_ZERO_DATE | + MODE_INVALID_DATES))), &error); + + if (nr < 0) + { + nr= 0; + error= 2; + } if (error) - set_datetime_warning(MYSQL_ERROR::WARN_LEVEL_WARN, - WARN_DATA_TRUNCATED, initial_nr, + set_datetime_warning(MYSQL_ERROR::WARN_LEVEL_WARN, + error == 2 ? ER_WARN_DATA_OUT_OF_RANGE : + WARN_DATA_TRUNCATED, initial_nr, MYSQL_TIMESTAMP_DATETIME, 1); - else if (nr == 0 && table->in_use->variables.sql_mode & MODE_NO_ZERO_DATE) - { - set_datetime_warning(MYSQL_ERROR::WARN_LEVEL_WARN, - ER_WARN_DATA_OUT_OF_RANGE, - initial_nr, MYSQL_TIMESTAMP_DATE, 1); - error= 1; - } #ifdef WORDS_BIGENDIAN if (table->s->db_low_byte_first) From f19af2946ff386748fa8f70af2b2d41c927e389a Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 18 Jul 2005 17:00:37 -0700 Subject: [PATCH 04/18] Handle systems where 127.0.0.1 doesn't always map to 'localhost' first. (Bug #11822) sql/hostname.cc: Short-circuit ip_to_hostname() lookup for INADDR_LOOPBACK to always return 'localhost'. sql/sql_parse.cc: Push special handling of 127.0.0.1 into ip_to_hostname(). --- sql/hostname.cc | 10 +++++++++- sql/sql_parse.cc | 30 ++++++++++-------------------- 2 files changed, 19 insertions(+), 21 deletions(-) diff --git a/sql/hostname.cc b/sql/hostname.cc index 39223556024..12b69a97859 100644 --- a/sql/hostname.cc +++ b/sql/hostname.cc @@ -130,15 +130,23 @@ void reset_host_errors(struct in_addr *in) VOID(pthread_mutex_unlock(&hostname_cache->lock)); } +/* Deal with systems that don't defined INADDR_LOOPBACK */ +#ifndef INADDR_LOOPBACK +#define INADDR_LOOPBACK 0x7f000001UL +#endif my_string ip_to_hostname(struct in_addr *in, uint *errors) { uint i; host_entry *entry; DBUG_ENTER("ip_to_hostname"); + *errors=0; + + /* We always treat the loopback address as "localhost". */ + if (in->s_addr == INADDR_LOOPBACK) + return (char *)my_localhost; /* Check first if we have name in cache */ - *errors=0; if (!(specialflag & SPECIAL_NO_HOST_CACHE)) { VOID(pthread_mutex_lock(&hostname_cache->lock)); diff --git a/sql/sql_parse.cc b/sql/sql_parse.cc index 26f342eac54..6ddddfed1f9 100644 --- a/sql/sql_parse.cc +++ b/sql/sql_parse.cc @@ -775,29 +775,19 @@ static int check_connection(THD *thd) 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")) + if (!(specialflag & SPECIAL_NO_RESOLVE)) { - thd->host= (char*) my_localhost; - thd->host_or_ip= my_localhost; - } - else -#endif - { - if (!(specialflag & SPECIAL_NO_RESOLVE)) + vio_in_addr(net->vio,&thd->remote.sin_addr); + thd->host=ip_to_hostname(&thd->remote.sin_addr,&connect_errors); + /* Cut very long hostnames to avoid possible overflows */ + if (thd->host) { - vio_in_addr(net->vio,&thd->remote.sin_addr); - 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 (thd->host != my_localhost) + 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); } DBUG_PRINT("info",("Host: %s ip: %s", thd->host ? thd->host : "unknown host", From 43ad7dea698c5b8a07226e2cf74455c5930a17b1 Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 18 Jul 2005 18:36:48 -0700 Subject: [PATCH 05/18] Fix default for sql_mode so that proc table is actually created by mysql-test-run.pl. (Bug #11954) mysql-test/lib/init_db.sql: Fix default for sql_mode --- mysql-test/lib/init_db.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mysql-test/lib/init_db.sql b/mysql-test/lib/init_db.sql index 77f9b18cb08..fa02b350425 100644 --- a/mysql-test/lib/init_db.sql +++ b/mysql-test/lib/init_db.sql @@ -553,7 +553,7 @@ CREATE TABLE proc ( 'TRADITIONAL', 'NO_AUTO_CREATE_USER', 'HIGH_NOT_PRECEDENCE' - ) DEFAULT 0 NOT NULL, + ) DEFAULT '' NOT NULL, comment char(64) binary DEFAULT '' NOT NULL, PRIMARY KEY (db,name,type) ) comment='Stored Procedures'; From a3a9d00b3b16fab0ca2f9cfa2a297b2abdcef4c3 Mon Sep 17 00:00:00 2001 From: unknown Date: Tue, 19 Jul 2005 11:52:24 +0200 Subject: [PATCH 06/18] perror.c: BUG#11999, incorrect --help on perror with ndb extra/perror.c: BUG#11999, incorrect --help on perror with ndb --- extra/perror.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/extra/perror.c b/extra/perror.c index 6e632b20d96..69cd6f87aab 100644 --- a/extra/perror.c +++ b/extra/perror.c @@ -41,7 +41,7 @@ static struct my_option my_long_options[] = {"info", 'I', "Synonym for --help.", 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}, #ifdef HAVE_NDBCLUSTER_DB - {"ndb", 0, "Ndbcluster storage engine specific error codes.", (gptr*) &ndb_code, + {"ndb", 257, "Ndbcluster storage engine specific error codes.", (gptr*) &ndb_code, (gptr*) &ndb_code, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0}, #endif #ifdef HAVE_SYS_ERRLIST From 09f19d3bc06b6438295f1c88c9bf786438db9f49 Mon Sep 17 00:00:00 2001 From: unknown Date: Tue, 19 Jul 2005 14:33:38 +0200 Subject: [PATCH 07/18] BUG#12028, cannot use default value for HostName in cluster config + added switch --print-full-config + removed unused REP configuration --- ndb/src/mgmsrv/ConfigInfo.cpp | 176 +++++++++++++--------------------- ndb/src/mgmsrv/main.cpp | 11 ++- 2 files changed, 76 insertions(+), 111 deletions(-) diff --git a/ndb/src/mgmsrv/ConfigInfo.cpp b/ndb/src/mgmsrv/ConfigInfo.cpp index 4612d17c9ce..b5a607bd100 100644 --- a/ndb/src/mgmsrv/ConfigInfo.cpp +++ b/ndb/src/mgmsrv/ConfigInfo.cpp @@ -62,8 +62,6 @@ ConfigInfo::m_sectionNames[]={ DB_TOKEN, MGM_TOKEN, API_TOKEN, - "REP", - "EXTERNAL REP", "TCP", "SCI", @@ -100,6 +98,7 @@ static bool saveInConfigValues(InitConfigFileParser::Context & ctx, const char * static bool fixFileSystemPath(InitConfigFileParser::Context & ctx, const char * data); static bool fixBackupDataDir(InitConfigFileParser::Context & ctx, const char * data); static bool fixShmUniqueId(InitConfigFileParser::Context & ctx, const char * data); +static bool checkLocalhostHostnameMix(InitConfigFileParser::Context & ctx, const char * data); const ConfigInfo::SectionRule ConfigInfo::m_SectionRules[] = { @@ -110,8 +109,6 @@ ConfigInfo::m_SectionRules[] = { { DB_TOKEN, transformNode, 0 }, { API_TOKEN, transformNode, 0 }, { MGM_TOKEN, transformNode, 0 }, - { "REP", transformNode, 0 }, - { "EXTERNAL REP", transformExtNode, 0 }, { MGM_TOKEN, fixShmUniqueId, 0 }, @@ -128,8 +125,6 @@ ConfigInfo::m_SectionRules[] = { { DB_TOKEN, fixNodeHostname, 0 }, { API_TOKEN, fixNodeHostname, 0 }, { MGM_TOKEN, fixNodeHostname, 0 }, - { "REP", fixNodeHostname, 0 }, - //{ "EXTERNAL REP", fixNodeHostname, 0 }, { "TCP", fixNodeId, "NodeId1" }, { "TCP", fixNodeId, "NodeId2" }, @@ -168,6 +163,10 @@ ConfigInfo::m_SectionRules[] = { { "*", fixDepricated, 0 }, { "*", applyDefaultValues, "system" }, + { DB_TOKEN, checkLocalhostHostnameMix, 0 }, + { API_TOKEN, checkLocalhostHostnameMix, 0 }, + { MGM_TOKEN, checkLocalhostHostnameMix, 0 }, + { DB_TOKEN, fixFileSystemPath, 0 }, { DB_TOKEN, fixBackupDataDir, 0 }, @@ -193,7 +192,6 @@ ConfigInfo::m_SectionRules[] = { { DB_TOKEN, saveInConfigValues, 0 }, { API_TOKEN, saveInConfigValues, 0 }, { MGM_TOKEN, saveInConfigValues, 0 }, - { "REP", saveInConfigValues, 0 }, { "TCP", saveInConfigValues, 0 }, { "SHM", saveInConfigValues, 0 }, @@ -344,17 +342,6 @@ const ConfigInfo::ParamInfo ConfigInfo::m_ParamInfo[] = { MANDATORY, 0, 0 }, - { - CFG_SYS_REPLICATION_ROLE, - "ReplicationRole", - "SYSTEM", - "Role in Global Replication (None, Primary, or Standby)", - ConfigInfo::CI_USED, - false, - ConfigInfo::CI_STRING, - UNDEFINED, - 0, 0 }, - { CFG_SYS_PRIMARY_MGM_NODE, "PrimaryMGMNode", @@ -402,7 +389,7 @@ const ConfigInfo::ParamInfo ConfigInfo::m_ParamInfo[] = { ConfigInfo::CI_INTERNAL, false, ConfigInfo::CI_STRING, - UNDEFINED, + "localhost", 0, 0 }, { @@ -1206,78 +1193,6 @@ const ConfigInfo::ParamInfo ConfigInfo::m_ParamInfo[] = { "0", STR_VALUE(MAX_INT_RNIL) }, - /*************************************************************************** - * REP - ***************************************************************************/ - { - CFG_SECTION_NODE, - "REP", - "REP", - "Node section", - ConfigInfo::CI_USED, - false, - ConfigInfo::CI_SECTION, - (const char *)NODE_TYPE_REP, - 0, 0 - }, - - { - CFG_NODE_HOST, - "HostName", - "REP", - "Name of computer for this node", - ConfigInfo::CI_INTERNAL, - false, - ConfigInfo::CI_STRING, - UNDEFINED, - 0, 0 }, - - { - CFG_NODE_SYSTEM, - "System", - "REP", - "Name of system for this node", - ConfigInfo::CI_INTERNAL, - false, - ConfigInfo::CI_STRING, - UNDEFINED, - 0, 0 }, - - { - CFG_NODE_ID, - "Id", - "REP", - "Number identifying replication node (REP)", - ConfigInfo::CI_USED, - false, - ConfigInfo::CI_INT, - MANDATORY, - "1", - STR_VALUE(MAX_NODES) }, - - { - KEY_INTERNAL, - "ExecuteOnComputer", - "REP", - "String referencing an earlier defined COMPUTER", - ConfigInfo::CI_USED, - false, - ConfigInfo::CI_STRING, - MANDATORY, - 0, 0 }, - - { - CFG_REP_HEARTBEAT_INTERVAL, - "HeartbeatIntervalRepRep", - "REP", - "Time between REP-REP heartbeats. Connection closed after 3 missed HBs", - ConfigInfo::CI_USED, - true, - ConfigInfo::CI_INT, - "3000", - "100", - STR_VALUE(MAX_INT_RNIL) }, - /*************************************************************************** * API ***************************************************************************/ @@ -1301,7 +1216,7 @@ const ConfigInfo::ParamInfo ConfigInfo::m_ParamInfo[] = { ConfigInfo::CI_INTERNAL, false, ConfigInfo::CI_STRING, - UNDEFINED, + "", 0, 0 }, { @@ -1421,7 +1336,7 @@ const ConfigInfo::ParamInfo ConfigInfo::m_ParamInfo[] = { ConfigInfo::CI_INTERNAL, false, ConfigInfo::CI_STRING, - UNDEFINED, + "", 0, 0 }, { @@ -2611,7 +2526,7 @@ transformNode(InitConfigFileParser::Context & ctx, const char * data){ return true; } -static bool checkLocalhostHostnameMix(InitConfigFileParser::Context & ctx) +static bool checkLocalhostHostnameMix(InitConfigFileParser::Context & ctx, const char * data) { DBUG_ENTER("checkLocalhostHostnameMix"); const char * hostname= 0; @@ -2640,21 +2555,17 @@ static bool checkLocalhostHostnameMix(InitConfigFileParser::Context & ctx) } bool -fixNodeHostname(InitConfigFileParser::Context & ctx, const char * data){ - +fixNodeHostname(InitConfigFileParser::Context & ctx, const char * data) +{ const char * hostname; + DBUG_ENTER("fixNodeHostname"); + if (ctx.m_currentSection->get("HostName", &hostname)) - return checkLocalhostHostnameMix(ctx); + DBUG_RETURN(checkLocalhostHostnameMix(ctx,0)); const char * compId; - if(!ctx.m_currentSection->get("ExecuteOnComputer", &compId)){ - const char * type; - if(ctx.m_currentSection->get("Type", &type) && strcmp(type,DB_TOKEN) == 0) - require(ctx.m_currentSection->put("HostName", "localhost")); - else - require(ctx.m_currentSection->put("HostName", "")); - return checkLocalhostHostnameMix(ctx); - } + if(!ctx.m_currentSection->get("ExecuteOnComputer", &compId)) + DBUG_RETURN(true); const Properties * computer; char tmp[255]; @@ -2663,18 +2574,18 @@ fixNodeHostname(InitConfigFileParser::Context & ctx, const char * data){ ctx.reportError("Computer \"%s\" not declared" "- [%s] starting at line: %d", compId, ctx.fname, ctx.m_sectionLineno); - return false; + DBUG_RETURN(false); } if(!computer->get("HostName", &hostname)){ ctx.reportError("HostName missing in [COMPUTER] (Id: %d) " " - [%s] starting at line: %d", compId, ctx.fname, ctx.m_sectionLineno); - return false; + DBUG_RETURN(false); } require(ctx.m_currentSection->put("HostName", hostname)); - return checkLocalhostHostnameMix(ctx); + DBUG_RETURN(checkLocalhostHostnameMix(ctx,0)); } bool @@ -2858,7 +2769,7 @@ transformComputer(InitConfigFileParser::Context & ctx, const char * data){ return true; } - return checkLocalhostHostnameMix(ctx); + return checkLocalhostHostnameMix(ctx,0); } /** @@ -2866,7 +2777,9 @@ transformComputer(InitConfigFileParser::Context & ctx, const char * data){ */ void applyDefaultValues(InitConfigFileParser::Context & ctx, - const Properties * defaults){ + const Properties * defaults) +{ + DBUG_ENTER("applyDefaultValues"); if(defaults != NULL){ Properties::Iterator it(defaults); @@ -2879,26 +2792,58 @@ applyDefaultValues(InitConfigFileParser::Context & ctx, Uint32 val = 0; ::require(defaults->get(name, &val)); ctx.m_currentSection->put(name, val); + DBUG_PRINT("info",("%s=%d #default",name,val)); break; } case ConfigInfo::CI_INT64:{ Uint64 val = 0; ::require(defaults->get(name, &val)); ctx.m_currentSection->put64(name, val); + DBUG_PRINT("info",("%s=%lld #default",name,val)); break; } case ConfigInfo::CI_STRING:{ const char * val; ::require(defaults->get(name, &val)); ctx.m_currentSection->put(name, val); + DBUG_PRINT("info",("%s=%s #default",name,val)); break; } case ConfigInfo::CI_SECTION: break; } } +#ifndef DBUG_OFF + else + { + switch (ctx.m_info->getType(ctx.m_currentInfo, name)){ + case ConfigInfo::CI_INT: + case ConfigInfo::CI_BOOL:{ + Uint32 val = 0; + ::require(ctx.m_currentSection->get(name, &val)); + DBUG_PRINT("info",("%s=%d",name,val)); + break; + } + case ConfigInfo::CI_INT64:{ + Uint64 val = 0; + ::require(ctx.m_currentSection->get(name, &val)); + DBUG_PRINT("info",("%s=%lld",name,val)); + break; + } + case ConfigInfo::CI_STRING:{ + const char * val; + ::require(ctx.m_currentSection->get(name, &val)); + DBUG_PRINT("info",("%s=%s",name,val)); + break; + } + case ConfigInfo::CI_SECTION: + break; + } + } +#endif } } + DBUG_VOID_RETURN; } bool @@ -3447,6 +3392,8 @@ fixDepricated(InitConfigFileParser::Context & ctx, const char * data){ return true; } +extern int g_print_full_config; + static bool saveInConfigValues(InitConfigFileParser::Context & ctx, const char * data){ const Properties * sec; @@ -3468,6 +3415,9 @@ saveInConfigValues(InitConfigFileParser::Context & ctx, const char * data){ break; } + if (g_print_full_config) + printf("[%s]\n", ctx.fname); + Uint32 no = 0; ctx.m_userProperties.get("$Section", id, &no); ctx.m_userProperties.put("$Section", id, no+1, true); @@ -3495,18 +3445,24 @@ saveInConfigValues(InitConfigFileParser::Context & ctx, const char * data){ Uint32 val; require(ctx.m_currentSection->get(n, &val)); ok = ctx.m_configValues.put(id, val); + if (g_print_full_config) + printf("%s=%u\n", n, val); break; } case PropertiesType_Uint64:{ Uint64 val; require(ctx.m_currentSection->get(n, &val)); ok = ctx.m_configValues.put64(id, val); + if (g_print_full_config) + printf("%s=%llu\n", n, val); break; } case PropertiesType_char:{ const char * val; require(ctx.m_currentSection->get(n, &val)); ok = ctx.m_configValues.put(id, val); + if (g_print_full_config) + printf("%s=%s\n", n, val); break; } default: diff --git a/ndb/src/mgmsrv/main.cpp b/ndb/src/mgmsrv/main.cpp index ffe58231eb3..01845687ce1 100644 --- a/ndb/src/mgmsrv/main.cpp +++ b/ndb/src/mgmsrv/main.cpp @@ -77,6 +77,7 @@ struct MgmGlobals { }; int g_no_nodeid_checks= 0; +int g_print_full_config; static MgmGlobals *glob= 0; /****************************************************************************** @@ -110,6 +111,9 @@ static struct my_option my_long_options[] = { "config-file", 'f', "Specify cluster configuration file", (gptr*) &opt_config_filename, (gptr*) &opt_config_filename, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0 }, + { "print-full-config", 'P', "Print full config and exit", + (gptr*) &g_print_full_config, (gptr*) &g_print_full_config, 0, + GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0 }, { "daemon", 'd', "Run ndb_mgmd in daemon mode (default)", (gptr*) &opt_daemon, (gptr*) &opt_daemon, 0, GET_BOOL, NO_ARG, 1, 0, 0, 0, 0, 0 }, @@ -188,7 +192,8 @@ int main(int argc, char** argv) exit(ho_error); if (opt_interactive || - opt_non_interactive) { + opt_non_interactive || + g_print_full_config) { opt_daemon= 0; } @@ -200,6 +205,9 @@ int main(int argc, char** argv) opt_config_filename, opt_connect_str); + if (g_print_full_config) + goto the_end; + if (glob->mgmObject->init()) goto error_end; @@ -309,6 +317,7 @@ int main(int argc, char** argv) glob->socketServer->stopServer(); glob->socketServer->stopSessions(true); g_eventLogger.info("Shutdown complete"); + the_end: delete glob; ndb_end(opt_endinfo ? MY_CHECK_ERROR | MY_GIVE_INFO : 0); return 0; From ac2209a1f961b81f398deaf583b9d1831865b6f2 Mon Sep 17 00:00:00 2001 From: unknown Date: Tue, 19 Jul 2005 15:25:55 +0200 Subject: [PATCH 08/18] ConfigInfo.cpp: BUG#12028, cannot use default section for hostname in cluster config made clearer error message ndb/src/mgmsrv/ConfigInfo.cpp: BUG#12028, cannot use default section for hostname in cluster config made clearer error message --- ndb/src/mgmsrv/ConfigInfo.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ndb/src/mgmsrv/ConfigInfo.cpp b/ndb/src/mgmsrv/ConfigInfo.cpp index b5a607bd100..118dd197ce0 100644 --- a/ndb/src/mgmsrv/ConfigInfo.cpp +++ b/ndb/src/mgmsrv/ConfigInfo.cpp @@ -2546,7 +2546,7 @@ static bool checkLocalhostHostnameMix(InitConfigFileParser::Context & ctx, const } if (localhost_used) { - ctx.reportError("Mixing of localhost with other hostname(%s) is illegal", + ctx.reportError("Mixing of localhost (default for [NDBD]HostName) with other hostname(%s) is illegal", hostname); DBUG_RETURN(false); } From 43a550aede1c54423be23a6669c374a7024bb2bd Mon Sep 17 00:00:00 2001 From: unknown Date: Tue, 19 Jul 2005 16:34:56 +0200 Subject: [PATCH 09/18] printout of cluster config to use same tokens as documentation --- ndb/src/mgmsrv/ConfigInfo.cpp | 15 +++++++++++++-- ndb/src/mgmsrv/ConfigInfo.hpp | 3 ++- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/ndb/src/mgmsrv/ConfigInfo.cpp b/ndb/src/mgmsrv/ConfigInfo.cpp index 118dd197ce0..03119ef3609 100644 --- a/ndb/src/mgmsrv/ConfigInfo.cpp +++ b/ndb/src/mgmsrv/ConfigInfo.cpp @@ -2367,7 +2367,15 @@ ConfigInfo::isSection(const char * section) const { } const char* -ConfigInfo::getAlias(const char * section) const { +ConfigInfo::nameToAlias(const char * name) { + for (int i = 0; m_sectionNameAliases[i].name != 0; i++) + if(!strcasecmp(name, m_sectionNameAliases[i].name)) + return m_sectionNameAliases[i].alias; + return 0; +} + +const char* +ConfigInfo::getAlias(const char * section) { for (int i = 0; m_sectionNameAliases[i].name != 0; i++) if(!strcasecmp(section, m_sectionNameAliases[i].alias)) return m_sectionNameAliases[i].name; @@ -3416,7 +3424,10 @@ saveInConfigValues(InitConfigFileParser::Context & ctx, const char * data){ } if (g_print_full_config) - printf("[%s]\n", ctx.fname); + { + const char *alias= ConfigInfo::nameToAlias(ctx.fname); + printf("[%s]\n", alias ? alias : ctx.fname); + } Uint32 no = 0; ctx.m_userProperties.get("$Section", id, &no); diff --git a/ndb/src/mgmsrv/ConfigInfo.hpp b/ndb/src/mgmsrv/ConfigInfo.hpp index dff8b34bf4a..871ee62040e 100644 --- a/ndb/src/mgmsrv/ConfigInfo.hpp +++ b/ndb/src/mgmsrv/ConfigInfo.hpp @@ -105,7 +105,8 @@ public: * @note Result is not defined if section/name are wrong! */ bool verify(const Properties* secti, const char* fname, Uint64 value) const; - const char* getAlias(const char*) const; + static const char* nameToAlias(const char*); + static const char* getAlias(const char*); bool isSection(const char*) const; const char* getDescription(const Properties * sec, const char* fname) const; From 3a31f7b91f9aea5c6bab45157c3a661252720174 Mon Sep 17 00:00:00 2001 From: unknown Date: Tue, 19 Jul 2005 19:25:05 +0300 Subject: [PATCH 10/18] Simple fixes during review of new code include/my_global.h: Added floatget() to read unaligned flaot mysql-test/r/select.result: Added test for found_rows() mysql-test/t/select.test: Added test for found_rows() sql/des_key_file.cc: Moved initalization of LOCK_des_key_file to mysqld to make simpler code and avoid theoretical race condition sql/field_conv.cc: Added optimizzed varsion of do_cut_string (for simple character sets) sql/item_func.cc: Simplify code (and ensure DBUG_ENTER is excuted before main code) sql/item_strfunc.cc: Safe calculation of max_length This was needed as max_length can now be 1<<32-1 (after konstantins recent patch to fix BLOB_LENGTH) Remove init_des_key_file() as this is not initialized in mysqld.cc sql/item_timefunc.cc: Safe calculation of max_length This was needed as max_length can now be 1<<32-1 (after konstantins recent patch to fix BLOB_LENGTH) sql/log_event.cc: Simplify code sql/mysql_priv.h: Moved initalization of LOCK_des_key_file to mysqld to make simpler code and avoid theoretical race condition sql/mysqld.cc: Moved initalization of LOCK_des_key_file to mysqld to make simpler code and avoid theoretical race condition Revert wrong patch of calling close_connection() in first close_connections() loop. (Bug #7403) Instead we now print a warning for closed connections only if mysqld is sarted with --warnings Added comments to make the close_connections() logic clearer sql/sql_prepare.cc: Use floatget() and doubleget() to protect against unaligned data sql/sql_select.cc: Fixed some cases unlikely cases where found_rows() would return wrong for queries that would return 0 or 1 rows --- include/my_global.h | 9 ++-- mysql-test/r/select.result | 19 +++++++ mysql-test/t/select.test | 7 +++ sql/des_key_file.cc | 25 --------- sql/field_conv.cc | 32 ++++++++++- sql/item_func.cc | 5 +- sql/item_strfunc.cc | 106 +++++++++++++++++++------------------ sql/item_timefunc.cc | 2 +- sql/log_event.cc | 22 ++++---- sql/mysql_priv.h | 5 +- sql/mysqld.cc | 37 ++++++++----- sql/sql_prepare.cc | 6 +-- sql/sql_select.cc | 12 +++-- 13 files changed, 169 insertions(+), 118 deletions(-) diff --git a/include/my_global.h b/include/my_global.h index eab6050d2dc..be6e667057d 100644 --- a/include/my_global.h +++ b/include/my_global.h @@ -972,7 +972,8 @@ do { doubleget_union _tmp; \ #define float4get(V,M) do { *((long *) &(V)) = *((long*) (M)); } while(0) #define float8get(V,M) doubleget((V),(M)) #define float4store(V,M) memcpy((byte*) V,(byte*) (&M),sizeof(float)) -#define floatstore(T,V) memcpy((byte*)(T), (byte*)(&V), sizeof(float)) +#define floatstore(T,V) memcpy((byte*)(T), (byte*)(&V),sizeof(float)) +#define floatget(V,M) memcpy((byte*) &V,(byte*) (M),sizeof(float)) #define float8store(V,M) doublestore((V),(M)) #endif /* __i386__ */ @@ -1143,7 +1144,8 @@ do { doubleget_union _tmp; \ *(((char*)T)+1)=(((A) >> 16));\ *(((char*)T)+0)=(((A) >> 24)); } while(0) -#define floatstore(T,V) memcpy_fixed((byte*)(T), (byte*)(&V), sizeof(float)) +#define floatget(V,M) memcpy_fixed((byte*) &V,(byte*) (M),sizeof(float)) +#define floatstore(T,V) memcpy_fixed((byte*) (T),(byte*)(&V),sizeof(float)) #define doubleget(V,M) memcpy_fixed((byte*) &V,(byte*) (M),sizeof(double)) #define doublestore(T,V) memcpy_fixed((byte*) (T),(byte*) &V,sizeof(double)) #define longlongget(V,M) memcpy_fixed((byte*) &V,(byte*) (M),sizeof(ulonglong)) @@ -1158,7 +1160,8 @@ do { doubleget_union _tmp; \ #define shortstore(T,V) int2store(T,V) #define longstore(T,V) int4store(T,V) #ifndef floatstore -#define floatstore(T,V) memcpy_fixed((byte*)(T), (byte*)(&V), sizeof(float)) +#define floatstore(T,V) memcpy_fixed((byte*) (T),(byte*) (&V),sizeof(float)) +#define floatget(V,M) memcpy_fixed((byte*) &V, (byte*) (M), sizeof(float)) #endif #ifndef doubleget #define doubleget(V,M) memcpy_fixed((byte*) &V,(byte*) (M),sizeof(double)) diff --git a/mysql-test/r/select.result b/mysql-test/r/select.result index 2df60944999..993fe7d22f1 100644 --- a/mysql-test/r/select.result +++ b/mysql-test/r/select.result @@ -2594,7 +2594,26 @@ INSERT INTO t1 SELECT 50, 3, 3 FROM DUAL WHERE NOT EXISTS (SELECT * FROM t1 WHERE a = 50 AND b = 3); +select found_rows(); +found_rows() +0 SELECT * FROM t1; a b c 50 3 3 +select count(*) from t1; +count(*) +1 +select found_rows(); +found_rows() +1 +select count(*) from t1 limit 2,3; +count(*) +select found_rows(); +found_rows() +0 +select SQL_CALC_FOUND_ROWS count(*) from t1 limit 2,3; +count(*) +select found_rows(); +found_rows() +1 DROP TABLE t1; diff --git a/mysql-test/t/select.test b/mysql-test/t/select.test index 893b9ba9267..3ae5839cd3c 100644 --- a/mysql-test/t/select.test +++ b/mysql-test/t/select.test @@ -2153,6 +2153,13 @@ INSERT INTO t1 SELECT 50, 3, 3 FROM DUAL WHERE NOT EXISTS (SELECT * FROM t1 WHERE a = 50 AND b = 3); +select found_rows(); SELECT * FROM t1; +select count(*) from t1; +select found_rows(); +select count(*) from t1 limit 2,3; +select found_rows(); +select SQL_CALC_FOUND_ROWS count(*) from t1 limit 2,3; +select found_rows(); DROP TABLE t1; diff --git a/sql/des_key_file.cc b/sql/des_key_file.cc index 558e3f16ad2..342939ad8ba 100644 --- a/sql/des_key_file.cc +++ b/sql/des_key_file.cc @@ -21,18 +21,6 @@ struct st_des_keyschedule des_keyschedule[10]; uint des_default_key; -pthread_mutex_t LOCK_des_key_file; -static int initialized= 0; - -void -init_des_key_file() -{ - if (!initialized) - { - initialized=1; - pthread_mutex_init(&LOCK_des_key_file,MY_MUTEX_INIT_FAST); - } -} /* Function which loads DES keys from plaintext file into memory on MySQL @@ -55,8 +43,6 @@ load_des_key_file(const char *file_name) DBUG_ENTER("load_des_key_file"); DBUG_PRINT("enter",("name: %s",file_name)); - init_des_key_file(); - VOID(pthread_mutex_lock(&LOCK_des_key_file)); if ((file=my_open(file_name,O_RDONLY | O_BINARY ,MYF(MY_WME))) < 0 || init_io_cache(&io, file, IO_SIZE*2, READ_CACHE, 0, 0, MYF(MY_WME))) @@ -113,15 +99,4 @@ error: VOID(pthread_mutex_unlock(&LOCK_des_key_file)); DBUG_RETURN(result); } - - -void free_des_key_file() -{ - if (initialized) - { - initialized= 01; - pthread_mutex_destroy(&LOCK_des_key_file); - } -} - #endif /* HAVE_OPENSSL */ diff --git a/sql/field_conv.cc b/sql/field_conv.cc index a447716a818..7998dd6d5f8 100644 --- a/sql/field_conv.cc +++ b/sql/field_conv.cc @@ -324,7 +324,34 @@ static void do_field_real(Copy_field *copy) } +/* + string copy for single byte characters set when to string is shorter than + from string +*/ + static void do_cut_string(Copy_field *copy) +{ + CHARSET_INFO *cs= copy->from_field->charset(); + memcpy(copy->to_ptr,copy->from_ptr,copy->to_length); + + /* Check if we loosed any important characters */ + if (cs->cset->scan(cs, + copy->from_ptr + copy->to_length, + copy->from_ptr + copy->from_length, + MY_SEQ_SPACES) < copy->from_length - copy->to_length) + { + copy->to_field->set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, + ER_WARN_DATA_TRUNCATED, 1); + } +} + + +/* + string copy for multi byte characters set when to string is shorter than + from string +*/ + +static void do_cut_string_complex(Copy_field *copy) { // Shorter string field int well_formed_error; CHARSET_INFO *cs= copy->from_field->charset(); @@ -351,6 +378,8 @@ static void do_cut_string(Copy_field *copy) } + + static void do_expand_string(Copy_field *copy) { CHARSET_INFO *cs= copy->from_field->charset(); @@ -517,7 +546,8 @@ void (*Copy_field::get_copy_func(Field *to,Field *from))(Copy_field*) from_length) return do_varstring; else if (to_length < from_length) - return do_cut_string; + return (from->charset()->mbmaxlen == 1 ? + do_cut_string : do_cut_string_complex); else if (to_length > from_length) return do_expand_string; } diff --git a/sql/item_func.cc b/sql/item_func.cc index c8f1d209d26..44917eb48e4 100644 --- a/sql/item_func.cc +++ b/sql/item_func.cc @@ -3045,14 +3045,15 @@ Item_func_get_system_var(sys_var *var_arg, enum_var_type var_type_arg, bool Item_func_get_system_var::fix_fields(THD *thd, TABLE_LIST *tables, Item **ref) { - Item *item= var->item(thd, var_type, &component); + Item *item; DBUG_ENTER("Item_func_get_system_var::fix_fields"); + /* Evaluate the system variable and substitute the result (a basic constant) instead of this item. If the variable can not be evaluated, the error is reported in sys_var::item(). */ - if (item == 0) + if (!(item= var->item(thd, var_type, &component))) DBUG_RETURN(1); // Impossible item->set_name(name, 0, system_charset_info); // don't allocate a new name thd->change_item_tree(ref, item); diff --git a/sql/item_strfunc.cc b/sql/item_strfunc.cc index 6a4dd0d7418..3a5ddd583ef 100644 --- a/sql/item_strfunc.cc +++ b/sql/item_strfunc.cc @@ -345,19 +345,20 @@ null: void Item_func_concat::fix_length_and_dec() { - max_length=0; + ulonglong max_result_length= 0; if (agg_arg_charsets(collation, args, arg_count, MY_COLL_ALLOW_CONV)) return; for (uint i=0 ; i < arg_count ; i++) - max_length+=args[i]->max_length; + max_result_length+= args[i]->max_length; - if (max_length > MAX_BLOB_WIDTH) + if (max_result_length >= MAX_BLOB_WIDTH) { - max_length=MAX_BLOB_WIDTH; - maybe_null=1; + max_result_length= MAX_BLOB_WIDTH; + maybe_null= 1; } + max_length= (ulong) max_result_length; } /* @@ -388,9 +389,6 @@ String *Item_func_des_encrypt::val_str(String *str) if (arg_count == 1) { - /* Make sure LOCK_des_key_file was initialized. */ - init_des_key_file(); - /* Protect against someone doing FLUSH DES_KEY_FILE */ VOID(pthread_mutex_lock(&LOCK_des_key_file)); keyschedule= des_keyschedule[key_number=des_default_key]; @@ -401,10 +399,6 @@ String *Item_func_des_encrypt::val_str(String *str) key_number= (uint) args[1]->val_int(); if (key_number > 9) goto error; - - /* Make sure LOCK_des_key_file was initialized. */ - init_des_key_file(); - VOID(pthread_mutex_lock(&LOCK_des_key_file)); keyschedule= des_keyschedule[key_number]; VOID(pthread_mutex_unlock(&LOCK_des_key_file)); @@ -493,9 +487,6 @@ String *Item_func_des_decrypt::val_str(String *str) if (!(current_thd->master_access & SUPER_ACL) || key_number > 9) goto error; - /* Make sure LOCK_des_key_file was initialized. */ - init_des_key_file(); - VOID(pthread_mutex_lock(&LOCK_des_key_file)); keyschedule= des_keyschedule[key_number]; VOID(pthread_mutex_unlock(&LOCK_des_key_file)); @@ -669,7 +660,7 @@ null: void Item_func_concat_ws::fix_length_and_dec() { - max_length=0; + ulonglong max_result_length; if (agg_arg_charsets(collation, args, arg_count, MY_COLL_ALLOW_CONV)) return; @@ -679,15 +670,16 @@ void Item_func_concat_ws::fix_length_and_dec() it is done on parser level in sql_yacc.yy so, (arg_count - 2) is safe here. */ - max_length= args[0]->max_length * (arg_count - 2); + max_result_length= (ulonglong) args[0]->max_length * (arg_count - 2); for (uint i=1 ; i < arg_count ; i++) - max_length+=args[i]->max_length; + max_result_length+=args[i]->max_length; - if (max_length > MAX_BLOB_WIDTH) + if (max_result_length >= MAX_BLOB_WIDTH) { - max_length=MAX_BLOB_WIDTH; - maybe_null=1; + max_result_length= MAX_BLOB_WIDTH; + maybe_null= 1; } + max_length= (ulong) max_result_length; } @@ -866,18 +858,19 @@ null: void Item_func_replace::fix_length_and_dec() { - max_length=args[0]->max_length; + ulonglong max_result_length= args[0]->max_length; int diff=(int) (args[2]->max_length - args[1]->max_length); if (diff > 0 && args[1]->max_length) { // Calculate of maxreplaces - uint max_substrs= max_length/args[1]->max_length; - max_length+= max_substrs * (uint) diff; + ulonglong max_substrs= max_result_length/args[1]->max_length; + max_result_length+= max_substrs * (uint) diff; } - if (max_length > MAX_BLOB_WIDTH) + if (max_result_length >= MAX_BLOB_WIDTH) { - max_length=MAX_BLOB_WIDTH; - maybe_null=1; + max_result_length= MAX_BLOB_WIDTH; + maybe_null= 1; } + max_length= (ulong) max_result_length; if (agg_arg_charsets(collation, args, 3, MY_COLL_CMP_CONV)) return; @@ -925,18 +918,22 @@ null: void Item_func_insert::fix_length_and_dec() { Item *cargs[2]; + ulonglong max_result_length; + cargs[0]= args[0]; cargs[1]= args[3]; if (agg_arg_charsets(collation, cargs, 2, MY_COLL_ALLOW_CONV)) return; args[0]= cargs[0]; args[3]= cargs[1]; - max_length=args[0]->max_length+args[3]->max_length; - if (max_length > MAX_BLOB_WIDTH) + max_result_length= ((ulonglong) args[0]->max_length+ + (ulonglong) args[3]->max_length); + if (max_result_length >= MAX_BLOB_WIDTH) { - max_length=MAX_BLOB_WIDTH; - maybe_null=1; + max_result_length= MAX_BLOB_WIDTH; + maybe_null= 1; } + max_length= (ulong) max_result_length; } @@ -1967,17 +1964,19 @@ void Item_func_repeat::fix_length_and_dec() collation.set(args[0]->collation); if (args[1]->const_item()) { - max_length=(long) (args[0]->max_length * args[1]->val_int()); - if (max_length >= MAX_BLOB_WIDTH) + ulonglong max_result_length= ((ulonglong) args[0]->max_length * + args[1]->val_int()); + if (max_result_length >= MAX_BLOB_WIDTH) { - max_length=MAX_BLOB_WIDTH; - maybe_null=1; + max_result_length= MAX_BLOB_WIDTH; + maybe_null= 1; } + max_length= (ulong) max_result_length; } else { - max_length=MAX_BLOB_WIDTH; - maybe_null=1; + max_length= MAX_BLOB_WIDTH; + maybe_null= 1; } } @@ -2032,6 +2031,7 @@ err: void Item_func_rpad::fix_length_and_dec() { Item *cargs[2]; + cargs[0]= args[0]; cargs[1]= args[2]; if (agg_arg_charsets(collation, cargs, 2, MY_COLL_ALLOW_CONV)) @@ -2040,18 +2040,20 @@ void Item_func_rpad::fix_length_and_dec() args[2]= cargs[1]; if (args[1]->const_item()) { - uint32 length= (uint32) args[1]->val_int() * collation.collation->mbmaxlen; - max_length=max(args[0]->max_length,length); - if (max_length >= MAX_BLOB_WIDTH) + ulonglong length= ((ulonglong) args[1]->val_int() * + collation.collation->mbmaxlen); + length= max((ulonglong) args[0]->max_length, length); + if (length >= MAX_BLOB_WIDTH) { - max_length=MAX_BLOB_WIDTH; - maybe_null=1; + length= MAX_BLOB_WIDTH; + maybe_null= 1; } + max_length= (ulong) length; } else { - max_length=MAX_BLOB_WIDTH; - maybe_null=1; + max_length= MAX_BLOB_WIDTH; + maybe_null= 1; } } @@ -2126,18 +2128,20 @@ void Item_func_lpad::fix_length_and_dec() if (args[1]->const_item()) { - uint32 length= (uint32) args[1]->val_int() * collation.collation->mbmaxlen; - max_length=max(args[0]->max_length,length); - if (max_length >= MAX_BLOB_WIDTH) + ulonglong length= ((ulonglong) args[1]->val_int() * + collation.collation->mbmaxlen); + length= max((ulonglong) args[0]->max_length, length); + if (length >= MAX_BLOB_WIDTH) { - max_length=MAX_BLOB_WIDTH; - maybe_null=1; + length= MAX_BLOB_WIDTH; + maybe_null= 1; } + max_length= (ulong) length; } else { - max_length=MAX_BLOB_WIDTH; - maybe_null=1; + max_length= MAX_BLOB_WIDTH; + maybe_null= 1; } } diff --git a/sql/item_timefunc.cc b/sql/item_timefunc.cc index 0e1a8766e8f..2c53ba82007 100644 --- a/sql/item_timefunc.cc +++ b/sql/item_timefunc.cc @@ -1538,7 +1538,7 @@ void Item_func_date_format::fix_length_and_dec() { fixed_length=0; /* The result is a binary string (no reason to use collation->mbmaxlen */ - max_length=args[1]->max_length*10; + max_length=min(args[1]->max_length,MAX_BLOB_WIDTH) * 10; set_if_smaller(max_length,MAX_BLOB_WIDTH); } maybe_null=1; // If wrong date diff --git a/sql/log_event.cc b/sql/log_event.cc index cda385c911b..4d260763491 100644 --- a/sql/log_event.cc +++ b/sql/log_event.cc @@ -1810,24 +1810,13 @@ int Load_log_event::exec_event(NET* net, struct st_relay_log_info* rli, thd->query= load_data_query; } - /* - We need to set thd->lex->sql_command and thd->lex->duplicates - since InnoDB tests these variables to decide if this is a LOAD - DATA ... REPLACE INTO ... statement even though mysql_parse() - is not called. This is not needed in 5.0 since there the LOAD - DATA ... statement is replicated using mysql_parse(), which - sets the thd->lex fields correctly. - */ - thd->lex->sql_command= SQLCOM_LOAD; if (sql_ex.opt_flags & REPLACE_FLAG) { - thd->lex->duplicates= DUP_REPLACE; handle_dup= DUP_REPLACE; } else if (sql_ex.opt_flags & IGNORE_FLAG) { ignore= 1; - thd->lex->duplicates= DUP_ERROR; handle_dup= DUP_ERROR; } else @@ -1845,9 +1834,18 @@ int Load_log_event::exec_event(NET* net, struct st_relay_log_info* rli, If reading from net (a 3.23 master), mysql_load() will change this to IGNORE. */ - thd->lex->duplicates= DUP_ERROR; handle_dup= DUP_ERROR; } + /* + We need to set thd->lex->sql_command and thd->lex->duplicates + since InnoDB tests these variables to decide if this is a LOAD + DATA ... REPLACE INTO ... statement even though mysql_parse() + is not called. This is not needed in 5.0 since there the LOAD + DATA ... statement is replicated using mysql_parse(), which + sets the thd->lex fields correctly. + */ + thd->lex->sql_command= SQLCOM_LOAD; + thd->lex->duplicates= handle_dup; sql_exchange ex((char*)fname, sql_ex.opt_flags & DUMPFILE_FLAG); String field_term(sql_ex.field_term,sql_ex.field_term_len,log_cs); diff --git a/sql/mysql_priv.h b/sql/mysql_priv.h index 351f12acad2..0bf7a3a7316 100644 --- a/sql/mysql_priv.h +++ b/sql/mysql_priv.h @@ -631,9 +631,7 @@ extern char *des_key_file; extern struct st_des_keyschedule des_keyschedule[10]; extern uint des_default_key; extern pthread_mutex_t LOCK_des_key_file; -void init_des_key_file(); bool load_des_key_file(const char *file_name); -void free_des_key_file(); #endif /* HAVE_OPENSSL */ /* sql_do.cc */ @@ -943,6 +941,9 @@ extern pthread_mutex_t LOCK_mysql_create_db,LOCK_Acl,LOCK_open, LOCK_delayed_status, LOCK_delayed_create, LOCK_crypt, LOCK_timezone, LOCK_slave_list, LOCK_active_mi, LOCK_manager, LOCK_global_system_variables, LOCK_user_conn; +#ifdef HAVE_OPENSSL +extern pthread_mutex_t LOCK_des_key_file; +#endif extern rw_lock_t LOCK_grant, LOCK_sys_init_connect, LOCK_sys_init_slave; extern pthread_cond_t COND_refresh, COND_thread_count, COND_manager; extern pthread_attr_t connection_attrib; diff --git a/sql/mysqld.cc b/sql/mysqld.cc index 3f4b002e369..896114f98c6 100644 --- a/sql/mysqld.cc +++ b/sql/mysqld.cc @@ -417,6 +417,9 @@ pthread_mutex_t LOCK_mysql_create_db, LOCK_Acl, LOCK_open, LOCK_thread_count, LOCK_crypt, LOCK_bytes_sent, LOCK_bytes_received, LOCK_global_system_variables, LOCK_user_conn, LOCK_slave_list, LOCK_active_mi; +#ifdef HAVE_OPENSSL +pthread_mutex_t LOCK_des_key_file; +#endif rw_lock_t LOCK_grant, LOCK_sys_init_connect, LOCK_sys_init_slave; pthread_cond_t COND_refresh,COND_thread_count, COND_slave_stopped, COND_slave_start; @@ -647,7 +650,11 @@ static void close_connections(void) end_thr_alarm(0); // Abort old alarms. end_slave(); - /* First signal all threads that it's time to die */ + /* + First signal all threads that it's time to die + This will give the threads some time to gracefully abort their + statements and inform their clients that the server is about to die. + */ THD *tmp; (void) pthread_mutex_lock(&LOCK_thread_count); // For unlink from list @@ -657,13 +664,7 @@ static void close_connections(void) { DBUG_PRINT("quit",("Informing thread %ld that it's time to die", tmp->thread_id)); - /* - Re: bug 7403 - close_connection will be called mulitple times - bug a wholesale clean up of our network code is a very large - project. This will wake up the socket on Windows and prevent the - printing of the error message that we are force closing a connection. - */ - close_connection(tmp, 0, 0); + tmp->killed= 1; if (tmp->mysys_var) { tmp->mysys_var->abort=1; @@ -680,9 +681,13 @@ static void close_connections(void) (void) pthread_mutex_unlock(&LOCK_thread_count); // For unlink from list if (thread_count) - sleep(1); // Give threads time to die + sleep(2); // Give threads time to die - /* Force remaining threads to die by closing the connection to the client */ + /* + Force remaining threads to die by closing the connection to the client + This will ensure that threads that are waiting for a command from the + client on a blocking read call are aborted. + */ for (;;) { @@ -697,8 +702,9 @@ static void close_connections(void) #ifndef __bsdi__ // Bug in BSDI kernel if (tmp->vio_ok()) { - sql_print_error(ER(ER_FORCING_CLOSE),my_progname, - tmp->thread_id,tmp->user ? tmp->user : ""); + if (global_system_variables.log_warnings) + sql_print_warning(ER(ER_FORCING_CLOSE),my_progname, + tmp->thread_id,tmp->user ? tmp->user : ""); close_connection(tmp,0,0); } #endif @@ -1012,7 +1018,6 @@ void clean_up(bool print_message) #ifdef HAVE_OPENSSL if (ssl_acceptor_fd) my_free((gptr) ssl_acceptor_fd, MYF(MY_ALLOW_ZERO_PTR)); - free_des_key_file(); #endif /* HAVE_OPENSSL */ #ifdef USE_REGEX regex_end(); @@ -1082,6 +1087,9 @@ static void clean_up_mutexes() (void) pthread_mutex_destroy(&LOCK_bytes_sent); (void) pthread_mutex_destroy(&LOCK_bytes_received); (void) pthread_mutex_destroy(&LOCK_user_conn); +#ifdef HAVE_OPENSSL + (void) pthread_mutex_destroy(&LOCK_des_key_file); +#endif #ifdef HAVE_REPLICATION (void) pthread_mutex_destroy(&LOCK_rpl_status); (void) pthread_cond_destroy(&COND_rpl_status); @@ -2585,6 +2593,9 @@ static int init_thread_environment() (void) pthread_mutex_init(&LOCK_active_mi, MY_MUTEX_INIT_FAST); (void) pthread_mutex_init(&LOCK_global_system_variables, MY_MUTEX_INIT_FAST); (void) pthread_mutex_init(&LOCK_uuid_generator, MY_MUTEX_INIT_FAST); +#ifdef HAVE_OPENSSL + (void) pthread_mutex_init(&LOCK_des_key_file,MY_MUTEX_INIT_FAST); +#endif (void) my_rwlock_init(&LOCK_sys_init_connect, NULL); (void) my_rwlock_init(&LOCK_sys_init_slave, NULL); (void) my_rwlock_init(&LOCK_grant, NULL); diff --git a/sql/sql_prepare.cc b/sql/sql_prepare.cc index 60f4e2c86df..6507de37a71 100644 --- a/sql/sql_prepare.cc +++ b/sql/sql_prepare.cc @@ -312,7 +312,7 @@ static void set_param_float(Item_param *param, uchar **pos, ulong len) return; float4get(data,*pos); #else - data= *(float*) *pos; + floatget(data, *pos); #endif param->set_double((double) data); *pos+= 4; @@ -326,7 +326,7 @@ static void set_param_double(Item_param *param, uchar **pos, ulong len) return; float8get(data,*pos); #else - data= *(double*) *pos; + doubleget(data, *pos); #endif param->set_double((double) data); *pos+= 8; @@ -580,10 +580,8 @@ static bool insert_params_withlog(Prepared_statement *stmt, uchar *null_array, Item_param **begin= stmt->param_array; Item_param **end= begin + stmt->param_count; uint32 length= 0; - String str; const String *res; - DBUG_ENTER("insert_params_withlog"); if (query->copy(stmt->query, stmt->query_length, default_charset_info)) diff --git a/sql/sql_select.cc b/sql/sql_select.cc index 5b4eab36dd2..29560e8701b 100644 --- a/sql/sql_select.cc +++ b/sql/sql_select.cc @@ -1081,14 +1081,18 @@ JOIN::exec() else { error= (int) result->send_eof(); - send_records=1; + send_records= ((select_options & OPTION_FOUND_ROWS) ? 1 : + thd->sent_row_count); } } else + { error=(int) result->send_eof(); + send_records= 0; + } } - /* Single select (without union and limit) always returns 1 row */ - thd->limit_found_rows= 1; + /* Single select (without union) always returns 0 or 1 row */ + thd->limit_found_rows= send_records; thd->examined_row_count= 0; DBUG_VOID_RETURN; } @@ -3552,6 +3556,7 @@ static void add_not_null_conds(JOIN *join) if (tab->ref.null_rejecting & (1 << keypart)) { Item *item= tab->ref.items[keypart]; + Item *notnull; DBUG_ASSERT(item->type() == Item::FIELD_ITEM); Item_field *not_null_item= (Item_field*)item; JOIN_TAB *referred_tab= not_null_item->field->table->reginfo.join_tab; @@ -3562,7 +3567,6 @@ static void add_not_null_conds(JOIN *join) */ if (!referred_tab || referred_tab->join != join) continue; - Item *notnull; if (!(notnull= new Item_func_isnotnull(not_null_item))) DBUG_VOID_RETURN; /* From 3d5be6335d5b4a4299ef68a7d66cd3bcfdbf93b1 Mon Sep 17 00:00:00 2001 From: unknown Date: Tue, 19 Jul 2005 19:47:54 +0300 Subject: [PATCH 11/18] Fixed some test cases that was not forgotten in a recent patch sql/sql_show.cc: Cleanup comment Removed extra end space --- mysql-test/r/ps_6bdb.result | 6 +++--- mysql-test/r/ps_7ndb.result | 6 +++--- sql/sql_show.cc | 35 +++++++++++++++++++---------------- 3 files changed, 25 insertions(+), 22 deletions(-) diff --git a/mysql-test/r/ps_6bdb.result b/mysql-test/r/ps_6bdb.result index acd7f45de95..ef74e13a41d 100644 --- a/mysql-test/r/ps_6bdb.result +++ b/mysql-test/r/ps_6bdb.result @@ -1153,12 +1153,12 @@ def id 8 3 1 N 32929 0 63 def select_type 253 19 6 N 1 31 8 def table 253 64 2 Y 0 31 8 def type 253 10 3 Y 0 31 8 -def possible_keys 253 4096 0 Y 0 31 8 +def possible_keys 252 4096 0 Y 0 31 8 def key 253 64 0 Y 0 31 8 def key_len 8 3 0 Y 32928 0 63 -def ref 253 1024 0 Y 0 31 8 +def ref 252 1024 0 Y 0 31 8 def rows 8 10 1 Y 32928 0 63 -def Extra 253 255 0 N 1 31 8 +def Extra 252 255 0 N 1 31 8 id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t9 ALL NULL NULL NULL NULL 3 test_sequence diff --git a/mysql-test/r/ps_7ndb.result b/mysql-test/r/ps_7ndb.result index 27a1ea0925d..e7ffbb7c6ef 100644 --- a/mysql-test/r/ps_7ndb.result +++ b/mysql-test/r/ps_7ndb.result @@ -1153,12 +1153,12 @@ def id 8 3 1 N 32929 0 63 def select_type 253 19 6 N 1 31 8 def table 253 64 2 Y 0 31 8 def type 253 10 3 Y 0 31 8 -def possible_keys 253 4096 0 Y 0 31 8 +def possible_keys 252 4096 0 Y 0 31 8 def key 253 64 0 Y 0 31 8 def key_len 8 3 0 Y 32928 0 63 -def ref 253 1024 0 Y 0 31 8 +def ref 252 1024 0 Y 0 31 8 def rows 8 10 1 Y 32928 0 63 -def Extra 253 255 0 N 1 31 8 +def Extra 252 255 0 N 1 31 8 id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t9 ALL NULL NULL NULL NULL 2 test_sequence diff --git a/sql/sql_show.cc b/sql/sql_show.cc index b33f78cc84a..647dfe2ac4d 100644 --- a/sql/sql_show.cc +++ b/sql/sql_show.cc @@ -639,30 +639,33 @@ int mysqld_extend_show_tables(THD *thd,const char *db,const char *wild) } /* -returns the length of the longest type on the given table. -This is used so that show fields will return the data using the proper -lengths instead of forcing columns such as type to always return with a -given length. + returns the length of the longest type on the given table. + + This is used so that show fields will return the data using the proper + lengths instead of forcing columns such as type to always return with a + given length. */ + uint get_longest_type_in_table(TABLE *table, const char *wild) { - Field **ptr,*field; - char tmp[MAX_FIELD_WIDTH]; - uint max_len = 0; + Field **ptr,*field; + char tmp[MAX_FIELD_WIDTH]; + uint max_len= 0; - for (ptr=table->field; (field= *ptr); ptr++) - { - if (!wild || !wild[0] || - !wild_case_compare(system_charset_info, field->field_name,wild)) + for (ptr=table->field; (field= *ptr); ptr++) + { + if (!wild || !wild[0] || + !wild_case_compare(system_charset_info, field->field_name,wild)) { - String type(tmp,sizeof(tmp), system_charset_info); - field->sql_type(type); - max_len = max(max_len, type.length()); - } - } + String type(tmp,sizeof(tmp), system_charset_info); + field->sql_type(type); + max_len= max(max_len, type.length()); + } + } return max_len; } + /*************************************************************************** ** List all columns in a table_list->real_name ***************************************************************************/ From dbec94d1a4a0653331ea25ead5e88926f24da0e6 Mon Sep 17 00:00:00 2001 From: unknown Date: Tue, 19 Jul 2005 21:55:39 +0200 Subject: [PATCH 12/18] .del-var~62c955ccf2da1a21: Delete: mysql-test/var BitKeeper/deleted/.del-var~62c955ccf2da1a21: Delete: mysql-test/var From a29f6ca1f5bad9c201025dabc6731d7f81f3e5d2 Mon Sep 17 00:00:00 2001 From: unknown Date: Wed, 20 Jul 2005 00:02:49 +0400 Subject: [PATCH 13/18] Ignore mysql-test/var (I'm pushing it for the second time already :(() BitKeeper/etc/ignore: added mysql-test/var --- .bzrignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.bzrignore b/.bzrignore index ca4cade7f09..746f141bd42 100644 --- a/.bzrignore +++ b/.bzrignore @@ -1119,3 +1119,4 @@ vio/viotest-ssl ndb/src/dummy.cpp innobase/mkinstalldirs mkinstalldirs +mysql-test/var From 217f9fa1e63c5ef016f08b7767823cd05ead94b4 Mon Sep 17 00:00:00 2001 From: unknown Date: Tue, 19 Jul 2005 22:04:43 +0200 Subject: [PATCH 14/18] ha_ndbcluster.cc: BUG#12040 Fixed compile failure by using %p instead of %x to print a pointer in DBUG_PRINT sql/ha_ndbcluster.cc: BUG#12040 Fixed compile failure by using %p instead of %x to print a pointer in DBUG_PRINT --- sql/ha_ndbcluster.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sql/ha_ndbcluster.cc b/sql/ha_ndbcluster.cc index 81723690b83..9e6725178d5 100644 --- a/sql/ha_ndbcluster.cc +++ b/sql/ha_ndbcluster.cc @@ -707,8 +707,8 @@ int ha_ndbcluster::set_ndb_value(NdbOperation *ndb_op, Field *field, blob_ptr= (char*)""; } - DBUG_PRINT("value", ("set blob ptr=%x len=%u", - (unsigned)blob_ptr, blob_len)); + DBUG_PRINT("value", ("set blob ptr=%p len=%u", + blob_ptr, blob_len)); DBUG_DUMP("value", (char*)blob_ptr, min(blob_len, 26)); if (set_blob_value) From 9142113cea3c4366074ed9fca69416270e03d586 Mon Sep 17 00:00:00 2001 From: unknown Date: Wed, 20 Jul 2005 01:17:16 +0400 Subject: [PATCH 15/18] Fix a compilation failure. --- sql/ha_blackhole.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sql/ha_blackhole.cc b/sql/ha_blackhole.cc index 856a053db9e..ae6952d4e5b 100644 --- a/sql/ha_blackhole.cc +++ b/sql/ha_blackhole.cc @@ -26,7 +26,7 @@ /* Blackhole storage engine handlerton */ -static handlerton myisam_hton= { +static handlerton blackhole_hton= { "BLACKHOLE", 0, /* slot */ 0, /* savepoint size. */ From ccc3052d1789e04e9914b3fad24213d0655eb10f Mon Sep 17 00:00:00 2001 From: unknown Date: Tue, 19 Jul 2005 16:32:38 -0700 Subject: [PATCH 16/18] Cleanups after merge from 4.1. mysql-test/r/ps_1general.result: Update results mysql-test/r/ps_2myisam.result: Update results mysql-test/r/ps_3innodb.result: Update results mysql-test/r/ps_4heap.result: Update results mysql-test/r/ps_5merge.result: Update results mysql-test/r/ps_6bdb.result: Update results mysql-test/r/ps_7ndb.result: Update results mysql-test/r/select.result: Update results mysql-test/t/disabled.def: Disable ndb_condition_pushdown test mysql-test/t/select.test: Fix bad merge sql/field_conv.cc: Update name of warning message sql/mysqld.cc: Set proper thd->killed tests/mysql_client_test.c: Update test cases, change verify_prepared_field() help function so it is passed the filename and line from where it is called and includes that in the error message. --- mysql-test/r/ps_1general.result | 12 +++++------ mysql-test/r/ps_2myisam.result | 6 +++--- mysql-test/r/ps_3innodb.result | 6 +++--- mysql-test/r/ps_4heap.result | 6 +++--- mysql-test/r/ps_5merge.result | 12 +++++------ mysql-test/r/ps_6bdb.result | 6 +++--- mysql-test/r/ps_7ndb.result | 6 +++--- mysql-test/r/select.result | 38 ++++++++++++++++----------------- mysql-test/t/disabled.def | 1 + mysql-test/t/select.test | 4 ++-- sql/field_conv.cc | 2 +- sql/mysqld.cc | 2 +- tests/mysql_client_test.c | 36 +++++++++++++++++++------------ 13 files changed, 73 insertions(+), 64 deletions(-) diff --git a/mysql-test/r/ps_1general.result b/mysql-test/r/ps_1general.result index de03c662f84..f2d60ac5025 100644 --- a/mysql-test/r/ps_1general.result +++ b/mysql-test/r/ps_1general.result @@ -473,12 +473,12 @@ def id 8 3 1 N 32929 0 63 def select_type 253 19 6 N 1 31 8 def table 253 64 2 Y 0 31 8 def type 253 10 3 Y 0 31 8 -def possible_keys 252 4096 0 Y 0 31 8 +def possible_keys 253 4096 0 Y 0 31 8 def key 253 64 0 Y 0 31 8 def key_len 253 4096 0 Y 128 31 63 -def ref 252 1024 0 Y 0 31 8 +def ref 253 1024 0 Y 0 31 8 def rows 8 10 1 Y 32928 0 63 -def Extra 252 255 14 N 1 31 8 +def Extra 253 255 14 N 1 31 8 id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t1 ALL NULL NULL NULL NULL 4 Using filesort SET @arg00=1 ; @@ -489,12 +489,12 @@ def id 8 3 1 N 32929 0 63 def select_type 253 19 6 N 1 31 8 def table 253 64 2 Y 0 31 8 def type 253 10 5 Y 0 31 8 -def possible_keys 252 4096 7 Y 0 31 8 +def possible_keys 253 4096 7 Y 0 31 8 def key 253 64 7 Y 0 31 8 def key_len 253 4096 1 Y 128 31 63 -def ref 252 1024 0 Y 0 31 8 +def ref 253 1024 0 Y 0 31 8 def rows 8 10 1 Y 32928 0 63 -def Extra 252 255 27 N 1 31 8 +def Extra 253 255 27 N 1 31 8 id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t1 range PRIMARY PRIMARY 4 NULL 3 Using where; Using filesort drop table if exists t2; diff --git a/mysql-test/r/ps_2myisam.result b/mysql-test/r/ps_2myisam.result index 65cede554c0..64dc09f864c 100644 --- a/mysql-test/r/ps_2myisam.result +++ b/mysql-test/r/ps_2myisam.result @@ -1154,12 +1154,12 @@ def id 8 3 1 N 32929 0 63 def select_type 253 19 6 N 1 31 8 def table 253 64 2 Y 0 31 8 def type 253 10 3 Y 0 31 8 -def possible_keys 252 4096 0 Y 0 31 8 +def possible_keys 253 4096 0 Y 0 31 8 def key 253 64 0 Y 0 31 8 def key_len 253 4096 0 Y 128 31 63 -def ref 252 1024 0 Y 0 31 8 +def ref 253 1024 0 Y 0 31 8 def rows 8 10 1 Y 32928 0 63 -def Extra 252 255 0 N 1 31 8 +def Extra 253 255 0 N 1 31 8 id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t9 ALL NULL NULL NULL NULL 2 drop table if exists t2 ; diff --git a/mysql-test/r/ps_3innodb.result b/mysql-test/r/ps_3innodb.result index 7fcd446599e..792d74231f2 100644 --- a/mysql-test/r/ps_3innodb.result +++ b/mysql-test/r/ps_3innodb.result @@ -1154,12 +1154,12 @@ def id 8 3 1 N 32929 0 63 def select_type 253 19 6 N 1 31 8 def table 253 64 2 Y 0 31 8 def type 253 10 3 Y 0 31 8 -def possible_keys 252 4096 0 Y 0 31 8 +def possible_keys 253 4096 0 Y 0 31 8 def key 253 64 0 Y 0 31 8 def key_len 253 4096 0 Y 128 31 63 -def ref 252 1024 0 Y 0 31 8 +def ref 253 1024 0 Y 0 31 8 def rows 8 10 1 Y 32928 0 63 -def Extra 252 255 0 N 1 31 8 +def Extra 253 255 0 N 1 31 8 id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t9 ALL NULL NULL NULL NULL 2 test_sequence diff --git a/mysql-test/r/ps_4heap.result b/mysql-test/r/ps_4heap.result index 59c9c221936..7dcb8546a83 100644 --- a/mysql-test/r/ps_4heap.result +++ b/mysql-test/r/ps_4heap.result @@ -1155,12 +1155,12 @@ def id 8 3 1 N 32929 0 63 def select_type 253 19 6 N 1 31 8 def table 253 64 2 Y 0 31 8 def type 253 10 3 Y 0 31 8 -def possible_keys 252 4096 0 Y 0 31 8 +def possible_keys 253 4096 0 Y 0 31 8 def key 253 64 0 Y 0 31 8 def key_len 253 4096 0 Y 128 31 63 -def ref 252 1024 0 Y 0 31 8 +def ref 253 1024 0 Y 0 31 8 def rows 8 10 1 Y 32928 0 63 -def Extra 252 255 0 N 1 31 8 +def Extra 253 255 0 N 1 31 8 id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t9 ALL NULL NULL NULL NULL 2 test_sequence diff --git a/mysql-test/r/ps_5merge.result b/mysql-test/r/ps_5merge.result index 4efdb7dc9e4..77b1a242452 100644 --- a/mysql-test/r/ps_5merge.result +++ b/mysql-test/r/ps_5merge.result @@ -1197,12 +1197,12 @@ def id 8 3 1 N 32929 0 63 def select_type 253 19 6 N 1 31 8 def table 253 64 2 Y 0 31 8 def type 253 10 3 Y 0 31 8 -def possible_keys 252 4096 0 Y 0 31 8 +def possible_keys 253 4096 0 Y 0 31 8 def key 253 64 0 Y 0 31 8 def key_len 253 4096 0 Y 128 31 63 -def ref 252 1024 0 Y 0 31 8 +def ref 253 1024 0 Y 0 31 8 def rows 8 10 1 Y 32928 0 63 -def Extra 252 255 0 N 1 31 8 +def Extra 253 255 0 N 1 31 8 id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t9 ALL NULL NULL NULL NULL 2 test_sequence @@ -4209,12 +4209,12 @@ def id 8 3 1 N 32929 0 63 def select_type 253 19 6 N 1 31 8 def table 253 64 2 Y 0 31 8 def type 253 10 3 Y 0 31 8 -def possible_keys 252 4096 0 Y 0 31 8 +def possible_keys 253 4096 0 Y 0 31 8 def key 253 64 0 Y 0 31 8 def key_len 253 4096 0 Y 128 31 63 -def ref 252 1024 0 Y 0 31 8 +def ref 253 1024 0 Y 0 31 8 def rows 8 10 1 Y 32928 0 63 -def Extra 252 255 0 N 1 31 8 +def Extra 253 255 0 N 1 31 8 id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t9 ALL NULL NULL NULL NULL 2 test_sequence diff --git a/mysql-test/r/ps_6bdb.result b/mysql-test/r/ps_6bdb.result index dd47e761144..0489c7ef078 100644 --- a/mysql-test/r/ps_6bdb.result +++ b/mysql-test/r/ps_6bdb.result @@ -1154,12 +1154,12 @@ def id 8 3 1 N 32929 0 63 def select_type 253 19 6 N 1 31 8 def table 253 64 2 Y 0 31 8 def type 253 10 3 Y 0 31 8 -def possible_keys 252 4096 0 Y 0 31 8 +def possible_keys 253 4096 0 Y 0 31 8 def key 253 64 0 Y 0 31 8 def key_len 253 4096 0 Y 128 31 63 -def ref 252 1024 0 Y 0 31 8 +def ref 253 1024 0 Y 0 31 8 def rows 8 10 1 Y 32928 0 63 -def Extra 252 255 0 N 1 31 8 +def Extra 253 255 0 N 1 31 8 id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t9 ALL NULL NULL NULL NULL 3 test_sequence diff --git a/mysql-test/r/ps_7ndb.result b/mysql-test/r/ps_7ndb.result index 6bbea79adc0..b0049b3e943 100644 --- a/mysql-test/r/ps_7ndb.result +++ b/mysql-test/r/ps_7ndb.result @@ -1154,12 +1154,12 @@ def id 8 3 1 N 32929 0 63 def select_type 253 19 6 N 1 31 8 def table 253 64 2 Y 0 31 8 def type 253 10 3 Y 0 31 8 -def possible_keys 252 4096 0 Y 0 31 8 +def possible_keys 253 4096 0 Y 0 31 8 def key 253 64 0 Y 0 31 8 def key_len 253 4096 0 Y 128 31 63 -def ref 252 1024 0 Y 0 31 8 +def ref 253 1024 0 Y 0 31 8 def rows 8 10 1 Y 32928 0 63 -def Extra 252 255 0 N 1 31 8 +def Extra 253 255 0 N 1 31 8 id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t9 ALL NULL NULL NULL NULL 2 test_sequence diff --git a/mysql-test/r/select.result b/mysql-test/r/select.result index 25012340639..14c45270b04 100644 --- a/mysql-test/r/select.result +++ b/mysql-test/r/select.result @@ -2579,6 +2579,25 @@ K2C4 K4N4 F2I4 WART 0100 1 WART 0200 1 WART 0300 3 +select found_rows(); +found_rows() +3 +select count(*) from t1; +count(*) +15 +select found_rows(); +found_rows() +1 +select count(*) from t1 limit 2,3; +count(*) +select found_rows(); +found_rows() +0 +select SQL_CALC_FOUND_ROWS count(*) from t1 limit 2,3; +count(*) +select found_rows(); +found_rows() +1 DROP TABLE t1; CREATE TABLE t1 ( a BLOB, INDEX (a(20)) ); CREATE TABLE t2 ( a BLOB, INDEX (a(20)) ); @@ -2781,26 +2800,7 @@ INSERT INTO t1 SELECT 50, 3, 3 FROM DUAL WHERE NOT EXISTS (SELECT * FROM t1 WHERE a = 50 AND b = 3); -select found_rows(); -found_rows() -0 SELECT * FROM t1; a b c 50 3 3 -select count(*) from t1; -count(*) -1 -select found_rows(); -found_rows() -1 -select count(*) from t1 limit 2,3; -count(*) -select found_rows(); -found_rows() -0 -select SQL_CALC_FOUND_ROWS count(*) from t1 limit 2,3; -count(*) -select found_rows(); -found_rows() -1 DROP TABLE t1; diff --git a/mysql-test/t/disabled.def b/mysql-test/t/disabled.def index c5f96ec4201..7d397ff2112 100644 --- a/mysql-test/t/disabled.def +++ b/mysql-test/t/disabled.def @@ -11,3 +11,4 @@ ############################################################################## sp-goto:GOTO is currently is disabled - will be fixed in the future +ndb_condition_pushdown:Bug #12021 diff --git a/mysql-test/t/select.test b/mysql-test/t/select.test index 7b0532d600a..ef26712af06 100644 --- a/mysql-test/t/select.test +++ b/mysql-test/t/select.test @@ -2152,16 +2152,16 @@ INSERT INTO t1 VALUES SELECT K2C4, K4N4, F2I4 FROM t1 WHERE K2C4 = 'WART' AND (F2I4 = 2 AND K2C4 = 'WART' OR (F2I4 = 2 OR K4N4 = '0200')); +SELECT K2C4, K4N4, F2I4 FROM t1 + WHERE K2C4 = 'WART' AND (K2C4 = 'WART' OR K4N4 = '0200'); select found_rows(); -SELECT K2C4, K4N4, F2I4 FROM t1 select count(*) from t1; select found_rows(); select count(*) from t1 limit 2,3; select found_rows(); select SQL_CALC_FOUND_ROWS count(*) from t1 limit 2,3; select found_rows(); - WHERE K2C4 = 'WART' AND (K2C4 = 'WART' OR K4N4 = '0200'); DROP TABLE t1; diff --git a/sql/field_conv.cc b/sql/field_conv.cc index c46e1c08c8b..fc7347ef9af 100644 --- a/sql/field_conv.cc +++ b/sql/field_conv.cc @@ -339,7 +339,7 @@ static void do_cut_string(Copy_field *copy) MY_SEQ_SPACES) < copy->from_length - copy->to_length) { copy->to_field->set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, - ER_WARN_DATA_TRUNCATED, 1); + WARN_DATA_TRUNCATED, 1); } } diff --git a/sql/mysqld.cc b/sql/mysqld.cc index ec0cb3851d6..0f4ed88140d 100644 --- a/sql/mysqld.cc +++ b/sql/mysqld.cc @@ -692,7 +692,7 @@ static void close_connections(void) { DBUG_PRINT("quit",("Informing thread %ld that it's time to die", tmp->thread_id)); - tmp->killed= 1; + tmp->killed= THD::KILL_CONNECTION; if (tmp->mysys_var) { tmp->mysys_var->abort=1; diff --git a/tests/mysql_client_test.c b/tests/mysql_client_test.c index 840ffe0564d..20284924c6c 100644 --- a/tests/mysql_client_test.c +++ b/tests/mysql_client_test.c @@ -666,13 +666,20 @@ static void verify_col_data(const char *table, const char *col, /* Utility function to verify the field members */ -static void verify_prepare_field(MYSQL_RES *result, - unsigned int no, const char *name, - const char *org_name, - enum enum_field_types type, - const char *table, - const char *org_table, const char *db, - unsigned long length, const char *def) +#define verify_prepare_field(result,no,name,org_name,type,table,\ + org_table,db,length,def) \ + do_verify_prepare_field((result),(no),(name),(org_name),(type), \ + (table),(org_table),(db),(length),(def), \ + __FILE__, __LINE__) + +static void do_verify_prepare_field(MYSQL_RES *result, + unsigned int no, const char *name, + const char *org_name, + enum enum_field_types type, + const char *table, + const char *org_table, const char *db, + unsigned long length, const char *def, + const char *file, int line) { MYSQL_FIELD *field; CHARSET_INFO *cs; @@ -719,8 +726,9 @@ static void verify_prepare_field(MYSQL_RES *result, { if (field->type != type) { - fprintf(stderr, "Expected field type: %d, got type: %d\n", - (int) type, (int) field->type); + fprintf(stderr, + "Expected field type: %d, got type: %d in file %s, line %d\n", + (int) type, (int) field->type, file, line); DIE_UNLESS(field->type == type); } } @@ -7402,8 +7410,8 @@ static void test_explain_bug() MYSQL_TYPE_STRING : MYSQL_TYPE_VAR_STRING, 0, 0, "", 64, 0); - verify_prepare_field(result, 1, "Type", "COLUMN_TYPE", - MYSQL_TYPE_BLOB, 0, 0, "", 0, 0); + verify_prepare_field(result, 1, "Type", "COLUMN_TYPE", MYSQL_TYPE_BLOB, + 0, 0, "", 0, 0); verify_prepare_field(result, 2, "Null", "IS_NULLABLE", mysql_get_server_version(mysql) <= 50000 ? @@ -7457,7 +7465,7 @@ static void test_explain_bug() verify_prepare_field(result, 3, "type", "", MYSQL_TYPE_VAR_STRING, "", "", "", 10, 0); - verify_prepare_field(result, 4, "possible_keys", "", MYSQL_TYPE_BLOB, + verify_prepare_field(result, 4, "possible_keys", "", MYSQL_TYPE_VAR_STRING, "", "", "", NAME_LEN*MAX_KEY, 0); verify_prepare_field(result, 5, "key", "", MYSQL_TYPE_VAR_STRING, @@ -7474,13 +7482,13 @@ static void test_explain_bug() "", "", NAME_LEN*MAX_KEY, 0); } - verify_prepare_field(result, 7, "ref", "", MYSQL_TYPE_BLOB, + verify_prepare_field(result, 7, "ref", "", MYSQL_TYPE_VAR_STRING, "", "", "", NAME_LEN*16, 0); verify_prepare_field(result, 8, "rows", "", MYSQL_TYPE_LONGLONG, "", "", "", 10, 0); - verify_prepare_field(result, 9, "Extra", "", MYSQL_TYPE_BLOB, + verify_prepare_field(result, 9, "Extra", "", MYSQL_TYPE_VAR_STRING, "", "", "", 255, 0); mysql_free_result(result); From c816f2971322803bbdbbe5b92a17c892ddd51ced Mon Sep 17 00:00:00 2001 From: unknown Date: Wed, 20 Jul 2005 06:55:51 +0400 Subject: [PATCH 17/18] Fix bug #11760 Typo in Item_func_add_time::print() results in NULLs returned by subtime() in view Item_func_add_time::print() were printing arg[0] instead of arg[1] which results in wrongly created view. Functions addtime() and subtime were affected by this bug. sql/item_timefunc.cc: Fix bug #11760 Typo in Item_func_add_time::print() results in wrongly created view mysql-test/t/view.test: Test case for bug #11760 Typo in Item_func_add_time::print() results in wrongly created view mysql-test/r/view.result: Test case for bug #11760 Typo in Item_func_add_time::print() results in wrongly created view mysql-test/r/date_formats.result: Fixed wrong test result. Affected by bug#11760 --- mysql-test/r/date_formats.result | 2 +- mysql-test/r/view.result | 8 ++++++++ mysql-test/t/view.test | 10 ++++++++++ sql/item_timefunc.cc | 2 +- 4 files changed, 20 insertions(+), 2 deletions(-) diff --git a/mysql-test/r/date_formats.result b/mysql-test/r/date_formats.result index 8217a0e7ba6..74ab1e35534 100644 --- a/mysql-test/r/date_formats.result +++ b/mysql-test/r/date_formats.result @@ -434,7 +434,7 @@ explain extended select makedate(1997,1), addtime("31.12.97 11.59.59.999999 PM", id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE NULL NULL NULL NULL NULL NULL NULL No tables used Warnings: -Note 1003 select makedate(1997,1) AS `makedate(1997,1)`,addtime(_latin1'31.12.97 11.59.59.999999 PM',_latin1'31.12.97 11.59.59.999999 PM') AS `addtime("31.12.97 11.59.59.999999 PM", "1 1.1.1.000002")`,subtime(_latin1'31.12.97 11.59.59.999999 PM',_latin1'31.12.97 11.59.59.999999 PM') AS `subtime("31.12.97 11.59.59.999999 PM", "1 1.1.1.000002")`,timediff(_latin1'01.01.97 11:59:59.000001 PM',_latin1'31.12.95 11:59:59.000002 PM') AS `timediff("01.01.97 11:59:59.000001 PM","31.12.95 11:59:59.000002 PM")`,cast(str_to_date(_latin1'15-01-2001 12:59:59',_latin1'%d-%m-%Y %H:%i:%S') as time) AS `cast(str_to_date("15-01-2001 12:59:59", "%d-%m-%Y %H:%i:%S") as TIME)`,maketime(23,11,12) AS `maketime(23,11,12)`,microsecond(_latin1'1997-12-31 23:59:59.000001') AS `microsecond("1997-12-31 23:59:59.000001")` +Note 1003 select makedate(1997,1) AS `makedate(1997,1)`,addtime(_latin1'31.12.97 11.59.59.999999 PM',_latin1'1 1.1.1.000002') AS `addtime("31.12.97 11.59.59.999999 PM", "1 1.1.1.000002")`,subtime(_latin1'31.12.97 11.59.59.999999 PM',_latin1'1 1.1.1.000002') AS `subtime("31.12.97 11.59.59.999999 PM", "1 1.1.1.000002")`,timediff(_latin1'01.01.97 11:59:59.000001 PM',_latin1'31.12.95 11:59:59.000002 PM') AS `timediff("01.01.97 11:59:59.000001 PM","31.12.95 11:59:59.000002 PM")`,cast(str_to_date(_latin1'15-01-2001 12:59:59',_latin1'%d-%m-%Y %H:%i:%S') as time) AS `cast(str_to_date("15-01-2001 12:59:59", "%d-%m-%Y %H:%i:%S") as TIME)`,maketime(23,11,12) AS `maketime(23,11,12)`,microsecond(_latin1'1997-12-31 23:59:59.000001') AS `microsecond("1997-12-31 23:59:59.000001")` create table t1 (d date); insert into t1 values ('2004-07-14'),('2005-07-14'); select date_format(d,"%d") from t1 order by 1; diff --git a/mysql-test/r/view.result b/mysql-test/r/view.result index a132279c6bc..d4b3bfe4ef1 100644 --- a/mysql-test/r/view.result +++ b/mysql-test/r/view.result @@ -2016,3 +2016,11 @@ CALL p1(); DROP PROCEDURE p1; DROP VIEW v1; DROP TABLE t1; +create table t1(f1 datetime); +insert into t1 values('2005.01.01 12:0:0'); +create view v1 as select f1, subtime(f1, '1:1:1') as sb from t1; +select * from v1; +f1 sb +2005-01-01 12:00:00 2005-01-01 10:58:59 +drop view v1; +drop table t1; diff --git a/mysql-test/t/view.test b/mysql-test/t/view.test index a98ecfe232f..a61e60ef2c9 100644 --- a/mysql-test/t/view.test +++ b/mysql-test/t/view.test @@ -1853,3 +1853,13 @@ CALL p1(); DROP PROCEDURE p1; DROP VIEW v1; DROP TABLE t1; + +# +# Bug #11760 Typo in Item_func_add_time::print() results in NULLs returned +# subtime() in view +create table t1(f1 datetime); +insert into t1 values('2005.01.01 12:0:0'); +create view v1 as select f1, subtime(f1, '1:1:1') as sb from t1; +select * from v1; +drop view v1; +drop table t1; diff --git a/sql/item_timefunc.cc b/sql/item_timefunc.cc index cac9613f1ad..1f9ee3f148c 100644 --- a/sql/item_timefunc.cc +++ b/sql/item_timefunc.cc @@ -2524,7 +2524,7 @@ void Item_func_add_time::print(String *str) } args[0]->print(str); str->append(','); - args[0]->print(str); + args[1]->print(str); str->append(')'); } From f03607ea9e72f726ce11b60826bbf30ebabc2806 Mon Sep 17 00:00:00 2001 From: unknown Date: Tue, 19 Jul 2005 19:59:36 -0700 Subject: [PATCH 18/18] Clean up after merge of bug fixes mysql-test/r/strict.result: Fix results file --- mysql-test/r/strict.result | 2 ++ 1 file changed, 2 insertions(+) diff --git a/mysql-test/r/strict.result b/mysql-test/r/strict.result index 8d167b348ea..49f118b1d96 100644 --- a/mysql-test/r/strict.result +++ b/mysql-test/r/strict.result @@ -1244,6 +1244,8 @@ t1 CREATE TABLE `t1` ( `a` bigint(20) unsigned NOT NULL, `b` date NOT NULL ) ENGINE=MyISAM DEFAULT CHARSET=latin1 +drop table t1; +set @@sql_mode='traditional'; create table t1 (d date); insert into t1 values ('2000-10-00'); ERROR 22007: Incorrect date value: '2000-10-00' for column 'd' at row 1