From 6c4102cee2808dc6d661c86a12b726d2457d9796 Mon Sep 17 00:00:00 2001 From: unknown Date: Wed, 7 Jun 2006 14:07:11 +0200 Subject: [PATCH 01/13] Bug#20159 Inconsistant generation of generic error messages - Use hardcoded error message instead of ER_GET_ERRNO sql/sql_udf.cc: Use hardcoded error message "Got unknown error: %d" instead of system error message "Got error %d from storage engine" as the "storage engine" has nothing to do with this. --- sql/sql_udf.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sql/sql_udf.cc b/sql/sql_udf.cc index 6269c0a2eb3..bea3d547f3e 100644 --- a/sql/sql_udf.cc +++ b/sql/sql_udf.cc @@ -237,7 +237,7 @@ void udf_init() } } if (error > 0) - sql_print_error(ER(ER_GET_ERRNO), my_errno); + sql_print_error("Got unknown error: %d", my_errno); end_read_record(&read_record_info); new_thd->version--; // Force close to free memory From f067dfe1c6298985d2c1831c52d9910f233bc5da Mon Sep 17 00:00:00 2001 From: unknown Date: Fri, 9 Jun 2006 19:35:54 +0200 Subject: [PATCH 02/13] Bug #7498 User variable SET saves SIGNED BIGINT as UNSIGNED BIGINT - Add unsigned flag to user_var_entry, used when 'type' is INT_RESULT - Propagate unsigned flag from the query executed by Item_single_row_subselect mysql-test/r/user_var.result: Update test results mysql-test/t/user_var.test: Add test case sql/item_func.cc: Add unsigned_flag to user_var_entry. Used when 'type' is INT_RESULT Pass unsigned_flag to 'update_hash' if type is INT_RESULT sql/item_func.h: Removed unused variable save_buff Add parameter unsigned_arg to 'update_hash' sql/item_subselect.cc: Propagate unsigned_flag to Item_singlerow_subselect from the items in the select to the cached items. sql/sql_class.h: Add unsigned_flag to user_var_entry. Used when 'type' is INT_RESULT --- mysql-test/r/user_var.result | 36 ++++++++++++++++++++++++++++++++++++ mysql-test/t/user_var.test | 31 +++++++++++++++++++++++++++++++ sql/item_func.cc | 24 +++++++++++++++++------- sql/item_func.h | 6 ++---- sql/item_subselect.cc | 1 + sql/sql_class.h | 1 + 6 files changed, 88 insertions(+), 11 deletions(-) diff --git a/mysql-test/r/user_var.result b/mysql-test/r/user_var.result index 7439f9132fb..3a197cd2a47 100644 --- a/mysql-test/r/user_var.result +++ b/mysql-test/r/user_var.result @@ -256,3 +256,39 @@ t1 CREATE TABLE `t1` ( `@first_var` longtext ) ENGINE=MyISAM DEFAULT CHARSET=latin1 drop table t1; +set @a=18446744071710965857; +select @a; +@a +18446744071710965857 +CREATE TABLE `bigfailure` ( +`afield` BIGINT UNSIGNED NOT NULL +); +INSERT INTO `bigfailure` VALUES (18446744071710965857); +SELECT * FROM bigfailure; +afield +18446744071710965857 +select * from (SELECT afield FROM bigfailure) as b; +afield +18446744071710965857 +select * from bigfailure where afield = (SELECT afield FROM bigfailure); +afield +18446744071710965857 +select * from bigfailure where afield = 18446744071710965857; +afield +18446744071710965857 +select * from bigfailure where afield = 18446744071710965856+1; +afield +18446744071710965857 +SET @a := (SELECT afield FROM bigfailure); +SELECT @a; +@a +18446744071710965857 +SET @a := (select afield from (SELECT afield FROM bigfailure) as b); +SELECT @a; +@a +18446744071710965857 +SET @a := (select * from bigfailure where afield = (SELECT afield FROM bigfailure)); +SELECT @a; +@a +18446744071710965857 +drop table bigfailure; diff --git a/mysql-test/t/user_var.test b/mysql-test/t/user_var.test index e1b23a1782f..58c52b59a5a 100644 --- a/mysql-test/t/user_var.test +++ b/mysql-test/t/user_var.test @@ -171,3 +171,34 @@ set @first_var= cast(NULL as CHAR); create table t1 select @first_var; show create table t1; drop table t1; + +# +# Bug #7498 User variable SET saves SIGNED BIGINT as UNSIGNED BIGINT +# + +# First part, set user var to large number and select it +set @a=18446744071710965857; +select @a; + +# Second part, set user var from large number in table +# then select it +CREATE TABLE `bigfailure` ( + `afield` BIGINT UNSIGNED NOT NULL +); +INSERT INTO `bigfailure` VALUES (18446744071710965857); +SELECT * FROM bigfailure; +select * from (SELECT afield FROM bigfailure) as b; +select * from bigfailure where afield = (SELECT afield FROM bigfailure); +select * from bigfailure where afield = 18446744071710965857; +# This is fixed in 5.0, to be uncommented there +#select * from bigfailure where afield = '18446744071710965857'; +select * from bigfailure where afield = 18446744071710965856+1; + +SET @a := (SELECT afield FROM bigfailure); +SELECT @a; +SET @a := (select afield from (SELECT afield FROM bigfailure) as b); +SELECT @a; +SET @a := (select * from bigfailure where afield = (SELECT afield FROM bigfailure)); +SELECT @a; + +drop table bigfailure; diff --git a/sql/item_func.cc b/sql/item_func.cc index 6ec74560b91..7450451b0d0 100644 --- a/sql/item_func.cc +++ b/sql/item_func.cc @@ -3408,6 +3408,7 @@ static user_var_entry *get_variable(HASH *hash, LEX_STRING &name, entry->length=0; entry->update_query_id=0; entry->collation.set(NULL, DERIVATION_IMPLICIT); + entry->unsigned_flag= 0; /* If we are here, we were called from a SET or a query which sets a variable. Imagine it is this: @@ -3494,6 +3495,7 @@ Item_func_set_user_var::fix_length_and_dec() type - type of new value cs - charset info for new value dv - derivation for new value + unsigned_arg - indiates if a value of type INT_RESULT is unsigned RETURN VALUE False - success, True - failure @@ -3501,7 +3503,8 @@ Item_func_set_user_var::fix_length_and_dec() static bool update_hash(user_var_entry *entry, bool set_null, void *ptr, uint length, - Item_result type, CHARSET_INFO *cs, Derivation dv) + Item_result type, CHARSET_INFO *cs, Derivation dv, + bool unsigned_arg) { if (set_null) { @@ -3549,6 +3552,7 @@ update_hash(user_var_entry *entry, bool set_null, void *ptr, uint length, ((my_decimal*)entry->value)->fix_buffer_pointer(); entry->length= length; entry->collation.set(cs, dv); + entry->unsigned_flag= unsigned_arg; } entry->type=type; return 0; @@ -3557,7 +3561,8 @@ update_hash(user_var_entry *entry, bool set_null, void *ptr, uint length, bool Item_func_set_user_var::update_hash(void *ptr, uint length, Item_result type, - CHARSET_INFO *cs, Derivation dv) + CHARSET_INFO *cs, Derivation dv, + bool unsigned_arg) { /* If we set a variable explicitely to NULL then keep the old @@ -3566,7 +3571,7 @@ Item_func_set_user_var::update_hash(void *ptr, uint length, Item_result type, if ((null_value= args[0]->null_value) && null_item) type= entry->type; // Don't change type of item if (::update_hash(entry, (null_value= args[0]->null_value), - ptr, length, type, cs, dv)) + ptr, length, type, cs, dv, unsigned_arg)) { current_thd->fatal_error(); // Probably end of memory null_value= 1; @@ -3648,7 +3653,10 @@ String *user_var_entry::val_str(my_bool *null_value, String *str, str->set(*(double*) value, decimals, &my_charset_bin); break; case INT_RESULT: - str->set(*(longlong*) value, &my_charset_bin); + if (!unsigned_flag) + str->set(*(longlong*) value, &my_charset_bin); + else + str->set(*(ulonglong*) value, &my_charset_bin); break; case DECIMAL_RESULT: my_decimal2string(E_DEC_FATAL_ERROR, (my_decimal *)value, 0, 0, 0, str); @@ -3719,6 +3727,7 @@ Item_func_set_user_var::check() case INT_RESULT: { save_result.vint= args[0]->val_int(); + unsigned_flag= args[0]->unsigned_flag; break; } case STRING_RESULT: @@ -3774,7 +3783,8 @@ Item_func_set_user_var::update() case INT_RESULT: { res= update_hash((void*) &save_result.vint, sizeof(save_result.vint), - INT_RESULT, &my_charset_bin, DERIVATION_IMPLICIT); + INT_RESULT, &my_charset_bin, DERIVATION_IMPLICIT, + unsigned_flag); break; } case STRING_RESULT: @@ -4141,7 +4151,7 @@ bool Item_user_var_as_out_param::fix_fields(THD *thd, Item **ref) void Item_user_var_as_out_param::set_null_value(CHARSET_INFO* cs) { if (::update_hash(entry, TRUE, 0, 0, STRING_RESULT, cs, - DERIVATION_IMPLICIT)) + DERIVATION_IMPLICIT, 0 /* unsigned_arg */)) current_thd->fatal_error(); // Probably end of memory } @@ -4150,7 +4160,7 @@ void Item_user_var_as_out_param::set_value(const char *str, uint length, CHARSET_INFO* cs) { if (::update_hash(entry, FALSE, (void*)str, length, STRING_RESULT, cs, - DERIVATION_IMPLICIT)) + DERIVATION_IMPLICIT, 0 /* unsigned_arg */)) current_thd->fatal_error(); // Probably end of memory } diff --git a/sql/item_func.h b/sql/item_func.h index a91d93be8c6..8f90626ad26 100644 --- a/sql/item_func.h +++ b/sql/item_func.h @@ -1154,8 +1154,6 @@ class Item_func_set_user_var :public Item_func String *vstr; my_decimal *vdec; } save_result; - String save_buff; - public: LEX_STRING name; // keep it public @@ -1166,8 +1164,8 @@ public: longlong val_int(); String *val_str(String *str); my_decimal *val_decimal(my_decimal *); - bool update_hash(void *ptr, uint length, enum Item_result type, - CHARSET_INFO *cs, Derivation dv); + bool update_hash(void *ptr, uint length, enum Item_result type, + CHARSET_INFO *cs, Derivation dv, bool unsigned_arg= 0); bool check(); bool update(); enum Item_result result_type () const { return cached_result_type; } diff --git a/sql/item_subselect.cc b/sql/item_subselect.cc index d93f6501ebb..4e6b168c9e9 100644 --- a/sql/item_subselect.cc +++ b/sql/item_subselect.cc @@ -1497,6 +1497,7 @@ static Item_result set_row(List &item_list, Item *item, item->max_length= sel_item->max_length; res_type= sel_item->result_type(); item->decimals= sel_item->decimals; + item->unsigned_flag= sel_item->unsigned_flag; *maybe_null= sel_item->maybe_null; if (!(row[i]= Item_cache::get_cache(res_type))) return STRING_RESULT; // we should return something diff --git a/sql/sql_class.h b/sql/sql_class.h index 0ddba0e6f05..be13084b1ea 100644 --- a/sql/sql_class.h +++ b/sql/sql_class.h @@ -1954,6 +1954,7 @@ class user_var_entry ulong length; query_id_t update_query_id, used_query_id; Item_result type; + bool unsigned_flag; double val_real(my_bool *null_value); longlong val_int(my_bool *null_value); From d93ec9ee84de8b1c37fa0996a4c6ef6d2f94e033 Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 12 Jun 2006 13:07:40 +0200 Subject: [PATCH 03/13] Bug#19517 No simple way to detect wether server was compiled with libdbug - Define DBUG_ON and DBUG_OFF in config.h configure.in: Define DBUG_ON and DBUG_OFF in config.h instead of in compiler flags dbug/dbug.c: Undef DBUG_OFF if defined when compiling dbug.c, this is done as we always compile dbug.c even when DBUG_OFF is selected. --- configure.in | 15 +++++++++------ dbug/dbug.c | 5 ++++- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/configure.in b/configure.in index 3c335089688..8755fd1a3bb 100644 --- a/configure.in +++ b/configure.in @@ -1651,17 +1651,20 @@ AC_ARG_WITH(debug, if test "$with_debug" = "yes" then # Medium debug. - CFLAGS="$DEBUG_CFLAGS $DEBUG_OPTIMIZE_CC -DDBUG_ON -DSAFE_MUTEX $CFLAGS" - CXXFLAGS="$DEBUG_CXXFLAGS $DEBUG_OPTIMIZE_CXX -DDBUG_ON -DSAFE_MUTEX $CXXFLAGS" + AC_DEFINE([DBUG_ON], [1], [Use libdbug]) + CFLAGS="$DEBUG_CFLAGS $DEBUG_OPTIMIZE_CC -DSAFE_MUTEX $CFLAGS" + CXXFLAGS="$DEBUG_CXXFLAGS $DEBUG_OPTIMIZE_CXX -DSAFE_MUTEX $CXXFLAGS" elif test "$with_debug" = "full" then # Full debug. Very slow in some cases - CFLAGS="$DEBUG_CFLAGS -DDBUG_ON -DSAFE_MUTEX -DSAFEMALLOC $CFLAGS" - CXXFLAGS="$DEBUG_CXXFLAGS -DDBUG_ON -DSAFE_MUTEX -DSAFEMALLOC $CXXFLAGS" + AC_DEFINE([DBUG_ON], [1], [Use libdbug]) + CFLAGS="$DEBUG_CFLAGS -DSAFE_MUTEX -DSAFEMALLOC $CFLAGS" + CXXFLAGS="$DEBUG_CXXFLAGS -DSAFE_MUTEX -DSAFEMALLOC $CXXFLAGS" else # Optimized version. No debug - CFLAGS="$OPTIMIZE_CFLAGS -DDBUG_OFF $CFLAGS" - CXXFLAGS="$OPTIMIZE_CXXFLAGS -DDBUG_OFF $CXXFLAGS" + AC_DEFINE([DBUG_OFF], [1], [Don't use libdbug]) + CFLAGS="$OPTIMIZE_CFLAGS $CFLAGS" + CXXFLAGS="$OPTIMIZE_CXXFLAGS $CXXFLAGS" fi # Force static compilation to avoid linking problems/get more speed diff --git a/dbug/dbug.c b/dbug/dbug.c index c991daf3617..575481305e7 100644 --- a/dbug/dbug.c +++ b/dbug/dbug.c @@ -66,10 +66,13 @@ * Check of malloc on entry/exit (option "S") */ +#include + +/* This file won't compile unless DBUG_OFF is undefined locally */ #ifdef DBUG_OFF #undef DBUG_OFF #endif -#include + #include #include #if defined(MSDOS) || defined(__WIN__) From 8dc1fa1cf1aa8f04d2b52db26512f142bb1156ad Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 10 Jul 2006 19:50:40 -0700 Subject: [PATCH 04/13] Bug #18539: uncompress(d) is null: impossible? The UNCOMPRESS() function was not marked as maybe_null, even though it returns NULL on invalid data. This confused the optimizer. mysql-test/r/func_compress.result: Add new results mysql-test/t/func_compress.test: Add new regression test sql/item_strfunc.h: Set maybe_null within Item_func_uncompress::fix_length_and_dec() --- mysql-test/r/func_compress.result | 28 ++++++++++++++++++++++++++++ mysql-test/t/func_compress.test | 14 ++++++++++++++ sql/item_strfunc.h | 2 +- 3 files changed, 43 insertions(+), 1 deletion(-) diff --git a/mysql-test/r/func_compress.result b/mysql-test/r/func_compress.result index e3d31566741..df8939d98f1 100644 --- a/mysql-test/r/func_compress.result +++ b/mysql-test/r/func_compress.result @@ -79,3 +79,31 @@ uncompress(a) uncompressed_length(a) NULL NULL a 1 drop table t1; +create table t1 (a varchar(32) not null); +insert into t1 values ('foo'); +explain select * from t1 where uncompress(a) is null; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 system NULL NULL NULL NULL 1 +Warnings: +Error 1256 Uncompressed data size too large; the maximum size is 104857600 (probably, length of uncompressed data was corrupted) +select * from t1 where uncompress(a) is null; +a +foo +Warnings: +Error 1256 Uncompressed data size too large; the maximum size is 104857600 (probably, length of uncompressed data was corrupted) +explain select *, uncompress(a) from t1; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 system NULL NULL NULL NULL 1 +select *, uncompress(a) from t1; +a uncompress(a) +foo NULL +Warnings: +Error 1256 Uncompressed data size too large; the maximum size is 104857600 (probably, length of uncompressed data was corrupted) +select *, uncompress(a), uncompress(a) is null from t1; +a uncompress(a) uncompress(a) is null +foo NULL 1 +Warnings: +Error 1256 Uncompressed data size too large; the maximum size is 104857600 (probably, length of uncompressed data was corrupted) +Error 1256 Uncompressed data size too large; the maximum size is 104857600 (probably, length of uncompressed data was corrupted) +drop table t1; +End of 5.0 tests diff --git a/mysql-test/t/func_compress.test b/mysql-test/t/func_compress.test index 4ae749f2343..eeb5d509b94 100644 --- a/mysql-test/t/func_compress.test +++ b/mysql-test/t/func_compress.test @@ -57,3 +57,17 @@ select uncompress(a), uncompressed_length(a) from t1; drop table t1; # End of 4.1 tests + +# +# Bug #18539: uncompress(d) is null: impossible? +# +create table t1 (a varchar(32) not null); +insert into t1 values ('foo'); +explain select * from t1 where uncompress(a) is null; +select * from t1 where uncompress(a) is null; +explain select *, uncompress(a) from t1; +select *, uncompress(a) from t1; +select *, uncompress(a), uncompress(a) is null from t1; +drop table t1; + +--echo End of 5.0 tests diff --git a/sql/item_strfunc.h b/sql/item_strfunc.h index af59b8d740b..d685bd63467 100644 --- a/sql/item_strfunc.h +++ b/sql/item_strfunc.h @@ -784,7 +784,7 @@ class Item_func_uncompress: public Item_str_func String buffer; public: Item_func_uncompress(Item *a): Item_str_func(a){} - void fix_length_and_dec(){max_length= MAX_BLOB_WIDTH;} + void fix_length_and_dec(){ maybe_null= 1; max_length= MAX_BLOB_WIDTH; } const char *func_name() const{return "uncompress";} String *val_str(String *) ZLIB_DEPENDED_FUNCTION }; From 2fc276d54f43ec063019ce261fb9b9a17e484c96 Mon Sep 17 00:00:00 2001 From: unknown Date: Wed, 12 Jul 2006 13:22:38 -0700 Subject: [PATCH 05/13] Bug #17903: cast to char results in binary The character set was not being properly initialized in CAST() with a type like "CHAR(2) BINARY", which resulted in incorrect results or even a crash. mysql-test/r/cast.result: Add new results mysql-test/t/cast.test: Add new regression test sql/sql_yacc.yy: Make sure Lex->charset is set to NULL when nothing follows BINARY in type declaration. --- mysql-test/r/cast.result | 11 +++++++++++ mysql-test/t/cast.test | 14 +++++++++++++- sql/sql_yacc.yy | 2 +- 3 files changed, 25 insertions(+), 2 deletions(-) diff --git a/mysql-test/r/cast.result b/mysql-test/r/cast.result index d60efa083e0..a07ca21652b 100644 --- a/mysql-test/r/cast.result +++ b/mysql-test/r/cast.result @@ -381,3 +381,14 @@ DROP TABLE t1; select cast(NULL as decimal(6)) as t1; t1 NULL +set names latin1; +select hex(cast('a' as char(2) binary)); +hex(cast('a' as char(2) binary)) +61 +select hex(cast('a' as binary(2))); +hex(cast('a' as binary(2))) +6100 +select hex(cast('a' as char(2) binary)); +hex(cast('a' as char(2) binary)) +61 +End of 5.0 tests diff --git a/mysql-test/t/cast.test b/mysql-test/t/cast.test index 533da542855..ecc92ed01d1 100644 --- a/mysql-test/t/cast.test +++ b/mysql-test/t/cast.test @@ -204,7 +204,19 @@ SELECT CAST(v AS DECIMAL), CAST(tt AS DECIMAL), CAST(t AS DECIMAL), CAST(mt AS DECIMAL), CAST(lt AS DECIMAL) from t1; DROP TABLE t1; -# Bug @10237 (CAST(NULL DECIMAL) crashes server) + +# +# Bug #10237 (CAST(NULL DECIMAL) crashes server) # select cast(NULL as decimal(6)) as t1; + +# +# Bug #17903: cast to char results in binary +# +set names latin1; +select hex(cast('a' as char(2) binary)); +select hex(cast('a' as binary(2))); +select hex(cast('a' as char(2) binary)); + +--echo End of 5.0 tests diff --git a/sql/sql_yacc.yy b/sql/sql_yacc.yy index deac9cb5c40..a730e2533b1 100644 --- a/sql/sql_yacc.yy +++ b/sql/sql_yacc.yy @@ -3089,7 +3089,7 @@ opt_bin_mod: | BINARY { Lex->type|= BINCMP_FLAG; }; opt_bin_charset: - /* empty */ { } + /* empty */ { Lex->charset= NULL; } | ASCII_SYM { Lex->charset=&my_charset_latin1; } | UNICODE_SYM { From 7f2140d3ed7a114a42a2ca645608e46ff2768238 Mon Sep 17 00:00:00 2001 From: unknown Date: Tue, 18 Jul 2006 12:41:41 +0200 Subject: [PATCH 06/13] Bug#18539 uncompress(d) is null: impossible? - Add a check that length of field to uncompress is longer than 4 bytes. This can be dones as the length of uncompressed data is written as first four bytes of field and thus it can't be valid compressed data. mysql-test/r/func_compress.result: Update test results sql/item_strfunc.cc: Is size of field is less than or equal to 4 bytes, indicate data is uncompressable/corrupt. --- mysql-test/r/func_compress.result | 10 +++++----- sql/item_strfunc.cc | 10 ++++++++++ 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/mysql-test/r/func_compress.result b/mysql-test/r/func_compress.result index df8939d98f1..00d5ebfc351 100644 --- a/mysql-test/r/func_compress.result +++ b/mysql-test/r/func_compress.result @@ -85,12 +85,12 @@ explain select * from t1 where uncompress(a) is null; id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t1 system NULL NULL NULL NULL 1 Warnings: -Error 1256 Uncompressed data size too large; the maximum size is 104857600 (probably, length of uncompressed data was corrupted) +Error 1259 ZLIB: Input data corrupted select * from t1 where uncompress(a) is null; a foo Warnings: -Error 1256 Uncompressed data size too large; the maximum size is 104857600 (probably, length of uncompressed data was corrupted) +Error 1259 ZLIB: Input data corrupted explain select *, uncompress(a) from t1; id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t1 system NULL NULL NULL NULL 1 @@ -98,12 +98,12 @@ select *, uncompress(a) from t1; a uncompress(a) foo NULL Warnings: -Error 1256 Uncompressed data size too large; the maximum size is 104857600 (probably, length of uncompressed data was corrupted) +Error 1259 ZLIB: Input data corrupted select *, uncompress(a), uncompress(a) is null from t1; a uncompress(a) uncompress(a) is null foo NULL 1 Warnings: -Error 1256 Uncompressed data size too large; the maximum size is 104857600 (probably, length of uncompressed data was corrupted) -Error 1256 Uncompressed data size too large; the maximum size is 104857600 (probably, length of uncompressed data was corrupted) +Error 1259 ZLIB: Input data corrupted +Error 1259 ZLIB: Input data corrupted drop table t1; End of 5.0 tests diff --git a/sql/item_strfunc.cc b/sql/item_strfunc.cc index 97ed15c8bb7..a524e4e3056 100644 --- a/sql/item_strfunc.cc +++ b/sql/item_strfunc.cc @@ -2965,6 +2965,16 @@ String *Item_func_uncompress::val_str(String *str) if (res->is_empty()) return res; + /* If length is less than 4 bytes, data is corrupt */ + if (res->length() <= 4) + { + push_warning_printf(current_thd,MYSQL_ERROR::WARN_LEVEL_ERROR, + ER_ZLIB_Z_DATA_ERROR, + ER(ER_ZLIB_Z_DATA_ERROR)); + goto err; + } + + /* Size of uncompressed data is stored as first 4 bytes of field */ new_size= uint4korr(res->ptr()) & 0x3FFFFFFF; if (new_size > current_thd->variables.max_allowed_packet) { From 63a098f364df4e8d53e447e70ff4ad576c1f8c04 Mon Sep 17 00:00:00 2001 From: unknown Date: Wed, 19 Jul 2006 14:33:56 -0400 Subject: [PATCH 07/13] Bug #14448: delimiter in 'prompt' "I want to have the current delimiter in the prompt so that I can know at a glance which is set." Add a 'l' format specifier that represents the current statement delimiter. client/mysql.cc: Add a 'l' prompt format specifier, which becomes the current delimiter string in the prompt. --- client/mysql.cc | 3 +++ 1 file changed, 3 insertions(+) diff --git a/client/mysql.cc b/client/mysql.cc index 94b43d030e8..22534324aca 100644 --- a/client/mysql.cc +++ b/client/mysql.cc @@ -3724,6 +3724,9 @@ static const char* construct_prompt() case 't': processed_prompt.append('\t'); break; + case 'l': + processed_prompt.append(delimiter_str); + break; default: processed_prompt.append(c); } From 472f61492550ec0e2b6dd739fec4ea7b6db238ec Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 24 Jul 2006 11:51:52 +0200 Subject: [PATCH 08/13] Add function verbose_msg client/mysqldump.c: Add function verbose_msg and use it from all places where messages are printed if --verbose are turned on --- client/mysqldump.c | 94 +++++++++++++++++++++++----------------------- 1 file changed, 48 insertions(+), 46 deletions(-) diff --git a/client/mysqldump.c b/client/mysqldump.c index 4318e4b9528..9350d013c18 100644 --- a/client/mysqldump.c +++ b/client/mysqldump.c @@ -426,6 +426,30 @@ static my_bool dump_all_views_in_db(char *database); #include +/* + Print the supplied message if in verbose mode + + SYNOPSIS + verbose_msg() + fmt format specifier + ... variable number of parameters +*/ + +static void verbose_msg(const char *fmt, ...) +{ + va_list args; + DBUG_ENTER("verbose_msg"); + + if (!verbose) + DBUG_VOID_RETURN; + + va_start(args, fmt); + vfprintf(stderr, fmt, args); + va_end(args); + + DBUG_VOID_RETURN; +} + /* exit with message if ferror(file) @@ -894,10 +918,8 @@ static int dbConnect(char *host, char *user,char *passwd) { char buff[20+FN_REFLEN]; DBUG_ENTER("dbConnect"); - if (verbose) - { - fprintf(stderr, "-- Connecting to %s...\n", host ? host : "localhost"); - } + + verbose_msg("-- Connecting to %s...\n", host ? host : "localhost"); mysql_init(&mysql_connection); if (opt_compress) mysql_options(&mysql_connection,MYSQL_OPT_COMPRESS,NullS); @@ -963,8 +985,7 @@ static int dbConnect(char *host, char *user,char *passwd) */ static void dbDisconnect(char *host) { - if (verbose) - fprintf(stderr, "-- Disconnecting from %s...\n", host ? host : "localhost"); + verbose_msg("-- Disconnecting from %s...\n", host ? host : "localhost"); mysql_close(sock); } /* dbDisconnect */ @@ -1418,10 +1439,8 @@ static uint get_table_structure(char *table, char *db, char *table_type, if (delayed && (*ignore_flag & IGNORE_INSERT_DELAYED)) { delayed= 0; - if (verbose) - fprintf(stderr, - "-- Warning: Unable to use delayed inserts for table '%s' " - "because it's of type %s\n", table, table_type); + verbose_msg("-- Warning: Unable to use delayed inserts for table '%s' " + "because it's of type %s\n", table, table_type); } complete_insert= 0; @@ -1437,8 +1456,7 @@ static uint get_table_structure(char *table, char *db, char *table_type, insert_option= ((delayed && opt_ignore) ? " DELAYED IGNORE " : delayed ? " DELAYED " : opt_ignore ? " IGNORE " : ""); - if (verbose) - fprintf(stderr, "-- Retrieving table structure for table %s...\n", table); + verbose_msg("-- Retrieving table structure for table %s...\n", table); len= my_snprintf(query_buff, sizeof(query_buff), "SET OPTION SQL_QUOTE_SHOW_CREATE=%d", @@ -1505,8 +1523,7 @@ static uint get_table_structure(char *table, char *db, char *table_type, { char *scv_buff = NULL; - if (verbose) - fprintf(stderr, "-- It's a view, create dummy table for view\n"); + verbose_msg("-- It's a view, create dummy table for view\n"); /* save "show create" statement for later */ if ((row= mysql_fetch_row(result)) && (scv_buff=row[1])) @@ -1649,10 +1666,8 @@ static uint get_table_structure(char *table, char *db, char *table_type, } else { - if (verbose) - fprintf(stderr, - "%s: Warning: Can't set SQL_QUOTE_SHOW_CREATE option (%s)\n", - my_progname, mysql_error(sock)); + verbose_msg("%s: Warning: Can't set SQL_QUOTE_SHOW_CREATE option (%s)\n", + my_progname, mysql_error(sock)); my_snprintf(query_buff, sizeof(query_buff), "show fields from %s", result_table); @@ -1841,10 +1856,8 @@ static uint get_table_structure(char *table, char *db, char *table_type, { if (mysql_errno(sock) != ER_PARSE_ERROR) { /* If old MySQL version */ - if (verbose) - fprintf(stderr, - "-- Warning: Couldn't get status information for table %s (%s)\n", - result_table,mysql_error(sock)); + verbose_msg("-- Warning: Couldn't get status information for " \ + "table %s (%s)\n", result_table,mysql_error(sock)); } } else if (!(row= mysql_fetch_row(result))) @@ -2096,10 +2109,8 @@ static void dump_table(char *table, char *db) /* Check --no-data flag */ if (dFlag) { - if (verbose) - fprintf(stderr, - "-- Skipping dump data for table '%s', --no-data was used\n", - table); + verbose_msg("-- Skipping dump data for table '%s', --no-data was used\n", + table); DBUG_VOID_RETURN; } @@ -2112,27 +2123,22 @@ static void dump_table(char *table, char *db) */ if (ignore_flag & IGNORE_DATA) { - if (verbose) - fprintf(stderr, - "-- Warning: Skipping data for table '%s' because it's of type %s\n", - table, table_type); + verbose_msg("-- Warning: Skipping data for table '%s' because " \ + "it's of type %s\n", table, table_type); DBUG_VOID_RETURN; } /* Check that there are any fields in the table */ if (num_fields == 0) { - if (verbose) - fprintf(stderr, - "-- Skipping dump data for table '%s', it has no fields\n", - table); + verbose_msg("-- Skipping dump data for table '%s', it has no fields\n", + table); DBUG_VOID_RETURN; } result_table= quote_name(table,table_buff, 1); opt_quoted_table= quote_name(table, table_buff2, 0); - if (verbose) - fprintf(stderr, "-- Sending SELECT query...\n"); + verbose_msg("-- Sending SELECT query...\n"); if (path) { char filename[FN_REFLEN], tmp_path[FN_REFLEN]; @@ -2229,8 +2235,8 @@ static void dump_table(char *table, char *db) DB_error(sock, "when retrieving data from server"); goto err; } - if (verbose) - fprintf(stderr, "-- Retrieving rows...\n"); + + verbose_msg("-- Retrieving rows...\n"); if (mysql_num_fields(res) != num_fields) { fprintf(stderr,"%s: Error in field count for table: %s ! Aborting.\n", @@ -3172,10 +3178,8 @@ char check_if_ignore_table(const char *table_name, char *table_type) { if (mysql_errno(sock) != ER_PARSE_ERROR) { /* If old MySQL version */ - if (verbose) - fprintf(stderr, - "-- Warning: Couldn't get status information for table %s (%s)\n", - table_name,mysql_error(sock)); + verbose_msg("-- Warning: Couldn't get status information for " \ + "table %s (%s)\n", table_name,mysql_error(sock)); DBUG_RETURN(result); /* assume table is ok */ } } @@ -3361,8 +3365,7 @@ static my_bool get_view_structure(char *table, char* db) if (tFlag) /* Don't write table creation info */ DBUG_RETURN(0); - if (verbose) - fprintf(stderr, "-- Retrieving view structure for table %s...\n", table); + verbose_msg("-- Retrieving view structure for table %s...\n", table); #ifdef NOT_REALLY_USED_YET sprintf(insert_pat,"SET OPTION SQL_QUOTE_SHOW_CREATE=%d", @@ -3383,8 +3386,7 @@ static my_bool get_view_structure(char *table, char* db) field= mysql_fetch_field_direct(table_res, 0); if (strcmp(field->name, "View") != 0) { - if (verbose) - fprintf(stderr, "-- It's base table, skipped\n"); + verbose_msg("-- It's base table, skipped\n"); DBUG_RETURN(0); } From 6bd69b2e6a34313e610162988f5a3902f8a2f973 Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 24 Jul 2006 11:56:01 +0200 Subject: [PATCH 09/13] Change tFlag and dFlag into human readable format tFlag => opt_no_create_info dFlag => opt_no_data --- client/mysqldump.c | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/client/mysqldump.c b/client/mysqldump.c index 9350d013c18..36472364df8 100644 --- a/client/mysqldump.c +++ b/client/mysqldump.c @@ -83,7 +83,8 @@ static ulong find_set(TYPELIB *lib, const char *x, uint length, static char *alloc_query_str(ulong size); static char *field_escape(char *to,const char *from,uint length); -static my_bool verbose=0,tFlag=0,dFlag=0,quick= 1, extended_insert= 1, +static my_bool verbose= 0, opt_no_create_info= 0, opt_no_data= 0, + quick= 1, extended_insert= 1, lock_tables=1,ignore_errors=0,flush_logs=0, opt_drop=1,opt_keywords=0,opt_lock=1,opt_compress=0, opt_delayed=0,create_options=1,opt_quoted=0,opt_databases=0, @@ -312,9 +313,10 @@ static struct my_option my_long_options[] = (gptr*) &opt_create_db, (gptr*) &opt_create_db, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0}, {"no-create-info", 't', "Don't write table creation info.", - (gptr*) &tFlag, (gptr*) &tFlag, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0}, - {"no-data", 'd', "No row information.", (gptr*) &dFlag, (gptr*) &dFlag, 0, - GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0}, + (gptr*) &opt_no_create_info, (gptr*) &opt_no_create_info, 0, GET_BOOL, + NO_ARG, 0, 0, 0, 0, 0, 0}, + {"no-data", 'd', "No row information.", (gptr*) &opt_no_data, + (gptr*) &opt_no_data, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0}, {"no-set-names", 'N', "Deprecated. Use --skip-set-charset instead.", 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}, @@ -1474,7 +1476,7 @@ static uint get_table_structure(char *table, char *db, char *table_type, if (!opt_xml && !mysql_query_with_error_report(sock, 0, query_buff)) { /* using SHOW CREATE statement */ - if (!tFlag) + if (!opt_no_create_info) { /* Make an sql-file, if path was given iow. option -T was given */ char buff[20+FN_REFLEN]; @@ -1678,7 +1680,7 @@ static uint get_table_structure(char *table, char *db, char *table_type, } /* Make an sql-file, if path was given iow. option -T was given */ - if (!tFlag) + if (!opt_no_create_info) { if (path) { @@ -1722,7 +1724,7 @@ static uint get_table_structure(char *table, char *db, char *table_type, ulong *lengths= mysql_fetch_lengths(result); if (init) { - if (!opt_xml && !tFlag) + if (!opt_xml && !opt_no_create_info) { fputs(",\n",sql_file); check_io(sql_file); @@ -1734,7 +1736,7 @@ static uint get_table_structure(char *table, char *db, char *table_type, if (opt_complete_insert) dynstr_append(&insert_pat, quote_name(row[SHOW_FIELDNAME], name_buff, 0)); - if (!tFlag) + if (!opt_no_create_info) { if (opt_xml) { @@ -1764,7 +1766,7 @@ static uint get_table_structure(char *table, char *db, char *table_type, } num_fields= mysql_num_rows(result); mysql_free_result(result); - if (!tFlag) + if (!opt_no_create_info) { /* Make an sql-file, if path was given iow. option -T was given */ char buff[20+FN_REFLEN]; @@ -2107,7 +2109,7 @@ static void dump_table(char *table, char *db) return; /* Check --no-data flag */ - if (dFlag) + if (opt_no_data) { verbose_msg("-- Skipping dump data for table '%s', --no-data was used\n", table); @@ -3215,7 +3217,7 @@ char check_if_ignore_table(const char *table_name, char *table_type) /* If these two types, we do want to skip dumping the table */ - if (!dFlag && + if (!opt_no_data && (!strcmp(table_type,"MRG_MyISAM") || !strcmp(table_type,"MRG_ISAM"))) result= IGNORE_DATA; } @@ -3362,7 +3364,7 @@ static my_bool get_view_structure(char *table, char* db) FILE *sql_file = md_result_file; DBUG_ENTER("get_view_structure"); - if (tFlag) /* Don't write table creation info */ + if (opt_no_create_info) /* Don't write table creation info */ DBUG_RETURN(0); verbose_msg("-- Retrieving view structure for table %s...\n", table); From b8f39f0e174668c99cb7275c662f2159b3851c0a Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 24 Jul 2006 12:00:44 +0200 Subject: [PATCH 10/13] Replace sock -> mysql --- client/mysqldump.c | 183 +++++++++++++++++++++++---------------------- 1 file changed, 92 insertions(+), 91 deletions(-) diff --git a/client/mysqldump.c b/client/mysqldump.c index 36472364df8..7c6d56cb018 100644 --- a/client/mysqldump.c +++ b/client/mysqldump.c @@ -97,7 +97,7 @@ static my_bool verbose= 0, opt_no_create_info= 0, opt_no_data= 0, opt_complete_insert= 0, opt_drop_database= 0, opt_dump_triggers= 0, opt_routines=0, opt_tz_utc=1; static ulong opt_max_allowed_packet, opt_net_buffer_length; -static MYSQL mysql_connection,*sock=0; +static MYSQL mysql_connection,*mysql=0; static my_bool insert_pat_inited=0; static DYNAMIC_STRING insert_pat; static char *opt_password=0,*current_user=0, @@ -906,8 +906,8 @@ static void safe_exit(int error) first_error= error; if (ignore_errors) return; - if (sock) - mysql_close(sock); + if (mysql) + mysql_close(mysql); exit(error); } /* safe_exit */ @@ -939,7 +939,7 @@ static int dbConnect(char *host, char *user,char *passwd) mysql_options(&mysql_connection,MYSQL_SHARED_MEMORY_BASE_NAME,shared_memory_base_name); #endif mysql_options(&mysql_connection, MYSQL_SET_CHARSET_NAME, default_charset); - if (!(sock= mysql_real_connect(&mysql_connection,host,user,passwd, + if (!(mysql= mysql_real_connect(&mysql_connection,host,user,passwd, NULL,opt_mysql_port,opt_mysql_unix_port, 0))) { @@ -955,12 +955,12 @@ static int dbConnect(char *host, char *user,char *passwd) As we're going to set SQL_MODE, it would be lost on reconnect, so we cannot reconnect. */ - sock->reconnect= 0; + mysql->reconnect= 0; my_snprintf(buff, sizeof(buff), "/*!40100 SET @@SQL_MODE='%s' */", compatible_mode_normal_str); - if (mysql_query_with_error_report(sock, 0, buff)) + if (mysql_query_with_error_report(mysql, 0, buff)) { - mysql_close(sock); + mysql_close(mysql); safe_exit(EX_MYSQLERR); return 1; } @@ -971,9 +971,9 @@ static int dbConnect(char *host, char *user,char *passwd) if (opt_tz_utc) { my_snprintf(buff, sizeof(buff), "/*!40103 SET TIME_ZONE='+00:00' */"); - if (mysql_query_with_error_report(sock, 0, buff)) + if (mysql_query_with_error_report(mysql, 0, buff)) { - mysql_close(sock); + mysql_close(mysql); safe_exit(EX_MYSQLERR); return 1; } @@ -988,7 +988,7 @@ static int dbConnect(char *host, char *user,char *passwd) static void dbDisconnect(char *host) { verbose_msg("-- Disconnecting from %s...\n", host ? host : "localhost"); - mysql_close(sock); + mysql_close(mysql); } /* dbDisconnect */ @@ -1281,7 +1281,7 @@ static uint dump_routines_for_db(char *db) DBUG_ENTER("dump_routines_for_db"); DBUG_PRINT("enter", ("db: '%s'", db)); - mysql_real_escape_string(sock, db_name_buff, db, strlen(db)); + mysql_real_escape_string(mysql, db_name_buff, db, strlen(db)); /* nice comments */ if (opt_comments) @@ -1292,7 +1292,7 @@ static uint dump_routines_for_db(char *db) enough privileges to lock mysql.proc. */ if (lock_tables) - mysql_query(sock, "LOCK TABLES mysql.proc READ"); + mysql_query(mysql, "LOCK TABLES mysql.proc READ"); fprintf(sql_file, "DELIMITER ;;\n"); @@ -1303,7 +1303,7 @@ static uint dump_routines_for_db(char *db) "SHOW %s STATUS WHERE Db = '%s'", routine_type[i], db_name_buff); - if (mysql_query_with_error_report(sock, &routine_list_res, query_buff)) + if (mysql_query_with_error_report(mysql, &routine_list_res, query_buff)) DBUG_RETURN(1); if (mysql_num_rows(routine_list_res)) @@ -1317,7 +1317,7 @@ static uint dump_routines_for_db(char *db) my_snprintf(query_buff, sizeof(query_buff), "SHOW CREATE %s %s", routine_type[i], routine_name); - if (mysql_query_with_error_report(sock, &routine_res, query_buff)) + if (mysql_query_with_error_report(mysql, &routine_res, query_buff)) DBUG_RETURN(1); while ((row= mysql_fetch_row(routine_res))) @@ -1399,7 +1399,7 @@ static uint dump_routines_for_db(char *db) fprintf(sql_file, "DELIMITER ;\n"); if (lock_tables) - VOID(mysql_query_with_error_report(sock, 0, "UNLOCK TABLES")); + VOID(mysql_query_with_error_report(mysql, 0, "UNLOCK TABLES")); DBUG_RETURN(0); } @@ -1473,7 +1473,7 @@ static uint get_table_structure(char *table, char *db, char *table_type, if (opt_order_by_primary) order_by = primary_key_fields(result_table); - if (!opt_xml && !mysql_query_with_error_report(sock, 0, query_buff)) + if (!opt_xml && !mysql_query_with_error_report(mysql, 0, query_buff)) { /* using SHOW CREATE statement */ if (!opt_no_create_info) @@ -1483,7 +1483,7 @@ static uint get_table_structure(char *table, char *db, char *table_type, MYSQL_FIELD *field; my_snprintf(buff, sizeof(buff), "show create table %s", result_table); - if (mysql_query_with_error_report(sock, 0, buff)) + if (mysql_query_with_error_report(mysql, 0, buff)) { safe_exit(EX_MYSQLERR); DBUG_RETURN(0); @@ -1519,7 +1519,7 @@ static uint get_table_structure(char *table, char *db, char *table_type, check_io(sql_file); } - result= mysql_store_result(sock); + result= mysql_store_result(mysql); field= mysql_fetch_field_direct(result, 0); if (strcmp(field->name, "View") == 0) { @@ -1546,7 +1546,7 @@ static uint get_table_structure(char *table, char *db, char *table_type, */ my_snprintf(query_buff, sizeof(query_buff), "SHOW FIELDS FROM %s", result_table); - if (mysql_query_with_error_report(sock, 0, query_buff)) + if (mysql_query_with_error_report(mysql, 0, query_buff)) { /* View references invalid or privileged table/col/fun (err 1356), @@ -1554,7 +1554,7 @@ static uint get_table_structure(char *table, char *db, char *table_type, a comment with the view's 'show create' statement. (Bug #17371) */ - if (mysql_errno(sock) == ER_VIEW_INVALID) + if (mysql_errno(mysql) == ER_VIEW_INVALID) fprintf(sql_file, "\n-- failed on view %s: %s\n\n", result_table, scv_buff ? scv_buff : ""); my_free(scv_buff, MYF(MY_ALLOW_ZERO_PTR)); @@ -1565,7 +1565,7 @@ static uint get_table_structure(char *table, char *db, char *table_type, else my_free(scv_buff, MYF(MY_ALLOW_ZERO_PTR)); - if ((result= mysql_store_result(sock))) + if ((result= mysql_store_result(mysql))) { if (mysql_num_rows(result)) { @@ -1618,7 +1618,7 @@ static uint get_table_structure(char *table, char *db, char *table_type, } my_snprintf(query_buff, sizeof(query_buff), "show fields from %s", result_table); - if (mysql_query_with_error_report(sock, &result, query_buff)) + if (mysql_query_with_error_report(mysql, &result, query_buff)) { if (path) my_fclose(sql_file, MYF(MY_WME)); @@ -1669,11 +1669,11 @@ static uint get_table_structure(char *table, char *db, char *table_type, else { verbose_msg("%s: Warning: Can't set SQL_QUOTE_SHOW_CREATE option (%s)\n", - my_progname, mysql_error(sock)); + my_progname, mysql_error(mysql)); my_snprintf(query_buff, sizeof(query_buff), "show fields from %s", result_table); - if (mysql_query_with_error_report(sock, &result, query_buff)) + if (mysql_query_with_error_report(mysql, &result, query_buff)) { safe_exit(EX_MYSQLERR); DBUG_RETURN(0); @@ -1772,16 +1772,16 @@ static uint get_table_structure(char *table, char *db, char *table_type, char buff[20+FN_REFLEN]; uint keynr,primary_key; my_snprintf(buff, sizeof(buff), "show keys from %s", result_table); - if (mysql_query_with_error_report(sock, &result, buff)) + if (mysql_query_with_error_report(mysql, &result, buff)) { - if (mysql_errno(sock) == ER_WRONG_OBJECT) + if (mysql_errno(mysql) == ER_WRONG_OBJECT) { /* it is VIEW */ fputs("\t\t\n", sql_file); goto continue_xml; } fprintf(stderr, "%s: Can't get keys for table %s (%s)\n", - my_progname, result_table, mysql_error(sock)); + my_progname, result_table, mysql_error(mysql)); if (path) my_fclose(sql_file, MYF(MY_WME)); safe_exit(EX_MYSQLERR); @@ -1854,19 +1854,19 @@ static uint get_table_structure(char *table, char *db, char *table_type, my_snprintf(buff, sizeof(buff), "show table status like %s", quote_for_like(table, show_name_buff)); - if (mysql_query_with_error_report(sock, &result, buff)) + if (mysql_query_with_error_report(mysql, &result, buff)) { - if (mysql_errno(sock) != ER_PARSE_ERROR) + if (mysql_errno(mysql) != ER_PARSE_ERROR) { /* If old MySQL version */ verbose_msg("-- Warning: Couldn't get status information for " \ - "table %s (%s)\n", result_table,mysql_error(sock)); + "table %s (%s)\n", result_table,mysql_error(mysql)); } } else if (!(row= mysql_fetch_row(result))) { fprintf(stderr, "Error: Couldn't read status information for table %s (%s)\n", - result_table,mysql_error(sock)); + result_table,mysql_error(mysql)); } else { @@ -1939,7 +1939,7 @@ static void dump_triggers_for_table (char *table, char *db) "SHOW TRIGGERS LIKE %s", quote_for_like(table, name_buff)); - if (mysql_query_with_error_report(sock, &result, query_buff)) + if (mysql_query_with_error_report(mysql, &result, query_buff)) { if (path) my_fclose(sql_file, MYF(MY_WME)); @@ -2178,9 +2178,9 @@ static void dump_table(char *table, char *db) if (order_by) end = strxmov(end, " ORDER BY ", order_by, NullS); } - if (mysql_real_query(sock, query, (uint) (end - query))) + if (mysql_real_query(mysql, query, (uint) (end - query))) { - DB_error(sock, "when executing 'SELECT INTO OUTFILE'"); + DB_error(mysql, "when executing 'SELECT INTO OUTFILE'"); DBUG_VOID_RETURN; } } @@ -2226,15 +2226,15 @@ static void dump_table(char *table, char *db) fputs("\n", md_result_file); check_io(md_result_file); } - if (mysql_query_with_error_report(sock, 0, query)) - DB_error(sock, "when retrieving data from server"); + if (mysql_query_with_error_report(mysql, 0, query)) + DB_error(mysql, "when retrieving data from server"); if (quick) - res=mysql_use_result(sock); + res=mysql_use_result(mysql); else - res=mysql_store_result(sock); + res=mysql_store_result(mysql); if (!res) { - DB_error(sock, "when retrieving data from server"); + DB_error(mysql, "when retrieving data from server"); goto err; } @@ -2507,13 +2507,13 @@ static void dump_table(char *table, char *db) fputs(";\n", md_result_file); /* If not empty table */ fflush(md_result_file); check_io(md_result_file); - if (mysql_errno(sock)) + if (mysql_errno(mysql)) { my_snprintf(query, QUERY_LENGTH, "%s: Error %d: %s when dumping table %s at row: %ld\n", my_progname, - mysql_errno(sock), - mysql_error(sock), + mysql_errno(mysql), + mysql_error(mysql), result_table, rownr); fputs(query,stderr); @@ -2559,7 +2559,7 @@ static char *getTableName(int reset) if (!res) { - if (!(res = mysql_list_tables(sock,NullS))) + if (!(res = mysql_list_tables(mysql,NullS))) return(NULL); } if ((row = mysql_fetch_row(res))) @@ -2582,7 +2582,7 @@ static int dump_all_databases() MYSQL_RES *tableres; int result=0; - if (mysql_query_with_error_report(sock, &tableres, "SHOW DATABASES")) + if (mysql_query_with_error_report(mysql, &tableres, "SHOW DATABASES")) return 1; while ((row = mysql_fetch_row(tableres))) { @@ -2591,11 +2591,11 @@ static int dump_all_databases() } if (seen_views) { - if (mysql_query(sock, "SHOW DATABASES") || - !(tableres = mysql_store_result(sock))) + if (mysql_query(mysql, "SHOW DATABASES") || + !(tableres = mysql_store_result(mysql))) { my_printf_error(0, "Error: Couldn't execute 'SHOW DATABASES': %s", - MYF(0), mysql_error(sock)); + MYF(0), mysql_error(mysql)); return 1; } while ((row = mysql_fetch_row(tableres))) @@ -2632,13 +2632,13 @@ static int dump_databases(char **db_names) static int init_dumping(char *database) { - if (mysql_get_server_version(sock) >= 50003 && + if (mysql_get_server_version(mysql) >= 50003 && !my_strcasecmp(&my_charset_latin1, database, "information_schema")) return 1; - if (mysql_select_db(sock, database)) + if (mysql_select_db(mysql, database)) { - DB_error(sock, "when selecting the database"); + DB_error(mysql, "when selecting the database"); return 1; /* If --force */ } if (!path && !opt_xml) @@ -2665,7 +2665,7 @@ static int init_dumping(char *database) "SHOW CREATE DATABASE IF NOT EXISTS %s", qdatabase); - if (mysql_query(sock, qbuf) || !(dbinfo = mysql_store_result(sock))) + if (mysql_query(mysql, qbuf) || !(dbinfo = mysql_store_result(mysql))) { /* Old server version, dump generic CREATE DATABASE */ if (opt_drop_database) @@ -2733,15 +2733,15 @@ static int dump_all_tables_in_db(char *database) dynstr_append(&query, quote_name(table, table_buff, 1)); dynstr_append(&query, " READ /*!32311 LOCAL */,"); } - if (numrows && mysql_real_query(sock, query.str, query.length-1)) - DB_error(sock, "when using LOCK TABLES"); + if (numrows && mysql_real_query(mysql, query.str, query.length-1)) + DB_error(mysql, "when using LOCK TABLES"); /* We shall continue here, if --force was given */ dynstr_free(&query); } if (flush_logs) { - if (mysql_refresh(sock, REFRESH_LOG)) - DB_error(sock, "when doing refresh"); + if (mysql_refresh(mysql, REFRESH_LOG)) + DB_error(mysql, "when doing refresh"); /* We shall continue here, if --force was given */ } while ((table= getTableName(0))) @@ -2753,12 +2753,12 @@ static int dump_all_tables_in_db(char *database) my_free(order_by, MYF(MY_ALLOW_ZERO_PTR)); order_by= 0; if (opt_dump_triggers && ! opt_xml && - mysql_get_server_version(sock) >= 50009) + mysql_get_server_version(mysql) >= 50009) dump_triggers_for_table(table, database); } } if (opt_routines && !opt_xml && - mysql_get_server_version(sock) >= 50009) + mysql_get_server_version(mysql) >= 50009) { DBUG_PRINT("info", ("Dumping routines for database %s", database)); dump_routines_for_db(database); @@ -2769,7 +2769,7 @@ static int dump_all_tables_in_db(char *database) check_io(md_result_file); } if (lock_tables) - VOID(mysql_query_with_error_report(sock, 0, "UNLOCK TABLES")); + VOID(mysql_query_with_error_report(mysql, 0, "UNLOCK TABLES")); return 0; } /* dump_all_tables_in_db */ @@ -2792,9 +2792,9 @@ static my_bool dump_all_views_in_db(char *database) uint numrows; char table_buff[NAME_LEN*2+3]; - if (mysql_select_db(sock, database)) + if (mysql_select_db(mysql, database)) { - DB_error(sock, "when selecting the database"); + DB_error(mysql, "when selecting the database"); return 1; } @@ -2809,15 +2809,15 @@ static my_bool dump_all_views_in_db(char *database) dynstr_append(&query, quote_name(table, table_buff, 1)); dynstr_append(&query, " READ /*!32311 LOCAL */,"); } - if (numrows && mysql_real_query(sock, query.str, query.length-1)) - DB_error(sock, "when using LOCK TABLES"); + if (numrows && mysql_real_query(mysql, query.str, query.length-1)) + DB_error(mysql, "when using LOCK TABLES"); /* We shall continue here, if --force was given */ dynstr_free(&query); } if (flush_logs) { - if (mysql_refresh(sock, REFRESH_LOG)) - DB_error(sock, "when doing refresh"); + if (mysql_refresh(mysql, REFRESH_LOG)) + DB_error(mysql, "when doing refresh"); /* We shall continue here, if --force was given */ } while ((table= getTableName(0))) @@ -2828,7 +2828,7 @@ static my_bool dump_all_views_in_db(char *database) check_io(md_result_file); } if (lock_tables) - VOID(mysql_query_with_error_report(sock, 0, "UNLOCK TABLES")); + VOID(mysql_query_with_error_report(mysql, 0, "UNLOCK TABLES")); return 0; } /* dump_all_tables_in_db */ @@ -2858,12 +2858,12 @@ static char *get_actual_table_name(const char *old_table_name, MEM_ROOT *root) my_snprintf(query, sizeof(query), "SHOW TABLES LIKE %s", quote_for_like(old_table_name, show_name_buff)); - if (mysql_query_with_error_report(sock, 0, query)) + if (mysql_query_with_error_report(mysql, 0, query)) { safe_exit(EX_MYSQLERR); } - if ((table_res= mysql_store_result(sock))) + if ((table_res= mysql_store_result(mysql))) { my_ulonglong num_rows= mysql_num_rows(table_res); if (num_rows > 0) @@ -2925,16 +2925,16 @@ static int dump_selected_tables(char *db, char **table_names, int tables) if (lock_tables) { - if (mysql_real_query(sock, lock_tables_query.str, + if (mysql_real_query(mysql, lock_tables_query.str, lock_tables_query.length-1)) - DB_error(sock, "when doing LOCK TABLES"); + DB_error(mysql, "when doing LOCK TABLES"); /* We shall countinue here, if --force was given */ } dynstr_free(&lock_tables_query); if (flush_logs) { - if (mysql_refresh(sock, REFRESH_LOG)) - DB_error(sock, "when doing refresh"); + if (mysql_refresh(mysql, REFRESH_LOG)) + DB_error(mysql, "when doing refresh"); /* We shall countinue here, if --force was given */ } if (opt_xml) @@ -2946,7 +2946,7 @@ static int dump_selected_tables(char *db, char **table_names, int tables) DBUG_PRINT("info",("Dumping table %s", *pos)); dump_table(*pos, db); if (opt_dump_triggers && - mysql_get_server_version(sock) >= 50009) + mysql_get_server_version(mysql) >= 50009) dump_triggers_for_table(*pos, db); } @@ -2958,7 +2958,7 @@ static int dump_selected_tables(char *db, char **table_names, int tables) } /* obtain dump of routines (procs/functions) */ if (opt_routines && !opt_xml && - mysql_get_server_version(sock) >= 50009) + mysql_get_server_version(mysql) >= 50009) { DBUG_PRINT("info", ("Dumping routines for database %s", db)); dump_routines_for_db(db); @@ -2972,7 +2972,7 @@ static int dump_selected_tables(char *db, char **table_names, int tables) check_io(md_result_file); } if (lock_tables) - VOID(mysql_query_with_error_report(sock, 0, "UNLOCK TABLES")); + VOID(mysql_query_with_error_report(mysql, 0, "UNLOCK TABLES")); DBUG_RETURN(0); } /* dump_selected_tables */ @@ -3157,7 +3157,7 @@ static void print_value(FILE *file, MYSQL_RES *result, MYSQL_ROW row, table_type Type of table GLOBAL VARIABLES - sock MySQL socket + mysql MySQL connection verbose Write warning messages RETURN @@ -3176,12 +3176,12 @@ char check_if_ignore_table(const char *table_name, char *table_type) DBUG_ASSERT(2*sizeof(table_name) < sizeof(show_name_buff)); my_snprintf(buff, sizeof(buff), "show table status like %s", quote_for_like(table_name, show_name_buff)); - if (mysql_query_with_error_report(sock, &res, buff)) + if (mysql_query_with_error_report(mysql, &res, buff)) { - if (mysql_errno(sock) != ER_PARSE_ERROR) + if (mysql_errno(mysql) != ER_PARSE_ERROR) { /* If old MySQL version */ verbose_msg("-- Warning: Couldn't get status information for " \ - "table %s (%s)\n", table_name,mysql_error(sock)); + "table %s (%s)\n", table_name,mysql_error(mysql)); DBUG_RETURN(result); /* assume table is ok */ } } @@ -3189,7 +3189,7 @@ char check_if_ignore_table(const char *table_name, char *table_type) { fprintf(stderr, "Error: Couldn't read status information for table %s (%s)\n", - table_name, mysql_error(sock)); + table_name, mysql_error(mysql)); mysql_free_result(res); DBUG_RETURN(result); /* assume table is ok */ } @@ -3225,6 +3225,7 @@ char check_if_ignore_table(const char *table_name, char *table_type) DBUG_RETURN(result); } + /* Get string of comma-separated primary key field names @@ -3254,12 +3255,12 @@ static char *primary_key_fields(const char *table_name) my_snprintf(show_keys_buff, sizeof(show_keys_buff), "SHOW KEYS FROM %s", table_name); - if (mysql_query(sock, show_keys_buff) || - !(res = mysql_store_result(sock))) + if (mysql_query(mysql, show_keys_buff) || + !(res = mysql_store_result(mysql))) { fprintf(stderr, "Warning: Couldn't read keys from table %s;" " records are NOT sorted (%s)\n", - table_name, mysql_error(sock)); + table_name, mysql_error(mysql)); /* Don't exit, because it's better to print out unsorted records */ goto cleanup; } @@ -3378,7 +3379,7 @@ static my_bool get_view_structure(char *table, char* db) opt_quoted_table= quote_name(table, table_buff2, 0); my_snprintf(query, sizeof(query), "SHOW CREATE TABLE %s", result_table); - if (mysql_query_with_error_report(sock, &table_res, query)) + if (mysql_query_with_error_report(mysql, &table_res, query)) { safe_exit(EX_MYSQLERR); DBUG_RETURN(0); @@ -3423,7 +3424,7 @@ static my_bool get_view_structure(char *table, char* db) "SELECT CHECK_OPTION, DEFINER, SECURITY_TYPE " \ "FROM information_schema.views " \ "WHERE table_name=\"%s\" AND table_schema=\"%s\"", table, db); - if (mysql_query(sock, query)) + if (mysql_query(mysql, query)) { /* Use the raw output from SHOW CREATE TABLE if @@ -3449,7 +3450,7 @@ static my_bool get_view_structure(char *table, char* db) mysql_free_result(table_res); /* Get the result from "select ... information_schema" */ - if (!(table_res= mysql_store_result(sock)) || + if (!(table_res= mysql_store_result(mysql)) || !(row= mysql_fetch_row(table_res))) { safe_exit(EX_MYSQLERR); @@ -3544,21 +3545,21 @@ int main(int argc, char **argv) write_header(md_result_file, *argv); if ((opt_lock_all_tables || opt_master_data) && - do_flush_tables_read_lock(sock)) + do_flush_tables_read_lock(mysql)) goto err; - if (opt_single_transaction && start_transaction(sock, test(opt_master_data))) + if (opt_single_transaction && start_transaction(mysql, test(opt_master_data))) goto err; - if (opt_delete_master_logs && do_reset_master(sock)) + if (opt_delete_master_logs && do_reset_master(mysql)) goto err; if (opt_lock_all_tables || opt_master_data) { - if (flush_logs && mysql_refresh(sock, REFRESH_LOG)) + if (flush_logs && mysql_refresh(mysql, REFRESH_LOG)) goto err; flush_logs= 0; /* not anymore; that would not be sensible */ } - if (opt_master_data && do_show_master_status(sock)) + if (opt_master_data && do_show_master_status(mysql)) goto err; - if (opt_single_transaction && do_unlock_tables(sock)) /* unlock but no commit! */ + if (opt_single_transaction && do_unlock_tables(mysql)) /* unlock but no commit! */ goto err; if (opt_alldbs) From 2870c7f91f1d93e3774a7d92c901e276c6f0cedd Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 24 Jul 2006 12:43:35 +0200 Subject: [PATCH 11/13] Remove double printout of mysqldump in error message --- client/mysqldump.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/client/mysqldump.c b/client/mysqldump.c index 7c6d56cb018..9eecc23abd9 100644 --- a/client/mysqldump.c +++ b/client/mysqldump.c @@ -870,9 +870,8 @@ static int mysql_query_with_error_report(MYSQL *mysql_con, MYSQL_RES **res, if (mysql_query(mysql_con, query) || (res && !((*res)= mysql_store_result(mysql_con)))) { - my_printf_error(0, "%s: Couldn't execute '%s': %s (%d)", - MYF(0), my_progname, query, - mysql_error(mysql_con), mysql_errno(mysql_con)); + my_printf_error(0, "Couldn't execute '%s': %s (%d)", MYF(0), + query, mysql_error(mysql_con), mysql_errno(mysql_con)); return 1; } return 0; From 6fc7c5d9e021b3e09eae1eeeae04973b7c74e304 Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 24 Jul 2006 12:48:02 +0200 Subject: [PATCH 12/13] Don't close connection to mysql before 'safe_exit', that is done in 'safe_exit' if it decides to exit. --- client/mysqldump.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/client/mysqldump.c b/client/mysqldump.c index 9eecc23abd9..ad350075534 100644 --- a/client/mysqldump.c +++ b/client/mysqldump.c @@ -959,7 +959,6 @@ static int dbConnect(char *host, char *user,char *passwd) compatible_mode_normal_str); if (mysql_query_with_error_report(mysql, 0, buff)) { - mysql_close(mysql); safe_exit(EX_MYSQLERR); return 1; } @@ -972,7 +971,6 @@ static int dbConnect(char *host, char *user,char *passwd) my_snprintf(buff, sizeof(buff), "/*!40103 SET TIME_ZONE='+00:00' */"); if (mysql_query_with_error_report(mysql, 0, buff)) { - mysql_close(mysql); safe_exit(EX_MYSQLERR); return 1; } From a08a1108789da8860bca8a2eaad94fd071b22d88 Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 24 Jul 2006 13:10:24 +0200 Subject: [PATCH 13/13] Bug#21215 mysqldump creating incomplete backups without warning - Add call to 'safe_exit' function when db query fails. client/mysqldump.c: Add a call to 'safe_exit' to remember the error code and exit unless --force was give.n mysql-test/r/mysqldump.result: Add test result mysql-test/t/mysqldump.test: Add test case --- client/mysqldump.c | 1 + mysql-test/r/mysqldump.result | 16 ++++++++++++++ mysql-test/t/mysqldump.test | 40 +++++++++++++++++++++++++++++++++++ 3 files changed, 57 insertions(+) diff --git a/client/mysqldump.c b/client/mysqldump.c index ad350075534..2f4a5b46cd4 100644 --- a/client/mysqldump.c +++ b/client/mysqldump.c @@ -872,6 +872,7 @@ static int mysql_query_with_error_report(MYSQL *mysql_con, MYSQL_RES **res, { my_printf_error(0, "Couldn't execute '%s': %s (%d)", MYF(0), query, mysql_error(mysql_con), mysql_errno(mysql_con)); + safe_exit(EX_MYSQLERR); return 1; } return 0; diff --git a/mysql-test/r/mysqldump.result b/mysql-test/r/mysqldump.result index 118079906bf..49caa096cb8 100644 --- a/mysql-test/r/mysqldump.result +++ b/mysql-test/r/mysqldump.result @@ -2867,3 +2867,19 @@ drop view nasishnasifu; drop database mysqldump_views; drop table mysqldump_tables.basetable; drop database mysqldump_tables; +use test; +create user mysqltest_1; +create table t1(a int, b varchar(34)); +mysqldump: Couldn't execute 'FLUSH TABLES': Access denied; you need the RELOAD privilege for this operation (1227) +mysqldump: Couldn't execute 'FLUSH TABLES': Access denied; you need the RELOAD privilege for this operation (1227) +grant RELOAD on *.* to mysqltest_1@localhost; +mysqldump: Couldn't execute 'SHOW MASTER STATUS': Access denied; you need the SUPER,REPLICATION CLIENT privilege for this operation (1227) +mysqldump: Couldn't execute 'SHOW MASTER STATUS': Access denied; you need the SUPER,REPLICATION CLIENT privilege for this operation (1227) +grant REPLICATION CLIENT on *.* to mysqltest_1@localhost; +CHANGE MASTER TO MASTER_LOG_FILE='master-bin.000003', MASTER_LOG_POS=3784; +CREATE TABLE `t1` ( + `a` int(11) default NULL, + `b` varchar(34) default NULL +) ENGINE=MyISAM DEFAULT CHARSET=latin1; +drop table t1; +drop user mysqltest_1; diff --git a/mysql-test/t/mysqldump.test b/mysql-test/t/mysqldump.test index 858d8910781..e5e83a46a2e 100644 --- a/mysql-test/t/mysqldump.test +++ b/mysql-test/t/mysqldump.test @@ -1228,3 +1228,43 @@ drop view nasishnasifu; drop database mysqldump_views; drop table mysqldump_tables.basetable; drop database mysqldump_tables; + +# +# Bug#21215 mysqldump creating incomplete backups without warning +# +use test; + +# Create user without sufficient privs to perform the requested operation +create user mysqltest_1; +create table t1(a int, b varchar(34)); + +# Execute mysqldump, will fail on FLUSH TABLES +--error 2 +--exec $MYSQL_DUMP --compact --master-data -u mysqltest_1 test 2>&1 + +# Execute mysqldump, will fail on FLUSH TABLES +# use --force, should no affect behaviour +--error 2 +--exec $MYSQL_DUMP --compact --force --master-data -u mysqltest_1 test 2>&1 + +# Add RELOAD grants +grant RELOAD on *.* to mysqltest_1@localhost; + +# Execute mysqldump, will fail on SHOW MASTER STATUS +--error 2 +--exec $MYSQL_DUMP --compact --master-data -u mysqltest_1 test 2>&1 + +# Execute mysqldump, will fail on SHOW MASTER STATUS. +# use --force, should not alter behaviour +--error 2 +--exec $MYSQL_DUMP --compact --force --master-data -u mysqltest_1 test 2>&1 + +# Add REPLICATION CLIENT grants +grant REPLICATION CLIENT on *.* to mysqltest_1@localhost; + +# Execute mysqldump, should now succeed +--exec $MYSQL_DUMP --compact --master-data -u mysqltest_1 test 2>&1 + +# Clean up +drop table t1; +drop user mysqltest_1;