diff options
46 files changed, 977 insertions, 583 deletions
diff --git a/client/mysqldump.c b/client/mysqldump.c index c0a3c55746e..e89e8064c9a 100644 --- a/client/mysqldump.c +++ b/client/mysqldump.c @@ -21,7 +21,7 @@ ** AUTHOR: Igor Romanenko (igor@frog.kiev.ua) ** DATE: December 3, 1994 ** WARRANTY: None, expressed, impressed, implied -** or other +** or other ** STATUS: Public domain ** Adapted and optimized for MySQL by ** Michael Widenius, Sinisa Milivojevic, Jani Tolonen @@ -77,22 +77,22 @@ #define IGNORE_INSERT_DELAYED 0x02 /* table doesn't support INSERT DELAYED */ static char *add_load_option(char *ptr, const char *object, - const char *statement); + const char *statement); static ulong find_set(TYPELIB *lib, const char *x, uint length, - char **err_pos, uint *err_len); + char **err_pos, uint *err_len); 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, - lock_tables=1,ignore_errors=0,flush_logs=0, - opt_drop=1,opt_keywords=0,opt_lock=1,opt_compress=0, + 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, opt_alldbs=0,opt_create_db=0,opt_lock_all_tables=0, opt_set_charset=0, - opt_autocommit=0,opt_disable_keys=1,opt_xml=0, - opt_delete_master_logs=0, tty_password=0, - opt_single_transaction=0, opt_comments= 0, opt_compact= 0, - opt_hex_blob=0, opt_order_by_primary=0, opt_ignore=0, + opt_autocommit=0,opt_disable_keys=1,opt_xml=0, + opt_delete_master_logs=0, tty_password=0, + opt_single_transaction=0, opt_comments= 0, opt_compact= 0, + opt_hex_blob=0, opt_order_by_primary=0, opt_ignore=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; @@ -129,8 +129,8 @@ static const char *mysql_universal_client_charset= static char *default_charset; static CHARSET_INFO *charset_info= &my_charset_latin1; const char *default_dbug_option="d:t:o,/tmp/mysqldump.trace"; -/* do we met VIEWs during tables scaning */ -my_bool was_views= 0; +/* have we seen any VIEWs during table scanning? */ +my_bool seen_views= 0; const char *compatible_mode_names[]= { @@ -149,7 +149,7 @@ const char *compatible_mode_names[]= (1<<10) /* ANSI */\ ) TYPELIB compatible_mode_typelib= {array_elements(compatible_mode_names) - 1, - "", compatible_mode_names, NULL}; + "", compatible_mode_names, NULL}; HASH ignore_table; @@ -276,7 +276,7 @@ static struct my_option my_long_options[] = {"lines-terminated-by", OPT_LTB, "Lines in the i.file are terminated by ...", (gptr*) &lines_terminated, (gptr*) &lines_terminated, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0}, - {"lock-all-tables", 'x', "Locks all tables across all databases. This " + {"lock-all-tables", 'x', "Locks all tables across all databases. This " "is achieved by taking a global read lock for the duration of the whole " "dump. Automatically turns --single-transaction and --lock-tables off.", (gptr*) &opt_lock_all_tables, (gptr*) &opt_lock_all_tables, 0, GET_BOOL, NO_ARG, @@ -297,7 +297,7 @@ static struct my_option my_long_options[] = GET_UINT, OPT_ARG, 0, 0, MYSQL_OPT_MASTER_DATA_COMMENTED_SQL, 0, 0, 0}, {"max_allowed_packet", OPT_MAX_ALLOWED_PACKET, "", (gptr*) &opt_max_allowed_packet, (gptr*) &opt_max_allowed_packet, 0, - GET_ULONG, REQUIRED_ARG, 24*1024*1024, 4096, + GET_ULONG, REQUIRED_ARG, 24*1024*1024, 4096, (longlong) 2L*1024L*1024L*1024L, MALLOC_OVERHEAD, 1024, 0}, {"net_buffer_length", OPT_NET_BUFFER_LENGTH, "", (gptr*) &opt_net_buffer_length, (gptr*) &opt_net_buffer_length, 0, @@ -411,8 +411,8 @@ static const char *load_default_groups[]= { "mysqldump","client",0 }; static void safe_exit(int error); static void write_header(FILE *sql_file, char *db_name); static void print_value(FILE *file, MYSQL_RES *result, MYSQL_ROW row, - const char *prefix,const char *name, - int string_value); + const char *prefix,const char *name, + int string_value); static int dump_selected_tables(char *db, char **table_names, int tables); static int dump_all_tables_in_db(char *db); static int init_dumping(char *); @@ -428,10 +428,10 @@ static my_bool dump_all_views_in_db(char *database); /* exit with message if ferror(file) - + SYNOPSIS check_io() - file - checked file + file - checked file */ void check_io(FILE *file) @@ -456,7 +456,7 @@ static void short_usage_sub(void) { printf("Usage: %s [OPTIONS] database [tables]\n", my_progname); printf("OR %s [OPTIONS] --databases [OPTIONS] DB1 [DB2 DB3...]\n", - my_progname); + my_progname); printf("OR %s [OPTIONS] --all-databases [OPTIONS]\n", my_progname); NETWARE_SET_SCREEN_MODE(1); } @@ -501,12 +501,12 @@ static void write_header(FILE *sql_file, char *db_name) { fprintf(sql_file, "-- MySQL dump %s\n--\n", DUMP_VERSION); fprintf(sql_file, "-- Host: %s Database: %s\n", - current_host ? current_host : "localhost", db_name ? db_name : - ""); + current_host ? current_host : "localhost", db_name ? db_name : + ""); fputs("-- ------------------------------------------------------\n", - sql_file); + sql_file); fprintf(sql_file, "-- Server version\t%s\n", - mysql_get_server_info(&mysql_connection)); + mysql_get_server_info(&mysql_connection)); } if (opt_set_charset) fprintf(sql_file, @@ -529,10 +529,10 @@ static void write_header(FILE *sql_file, char *db_name) "); } fprintf(sql_file, - "/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='%s%s%s' */;\n" - "/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;\n", - path?"":"NO_AUTO_VALUE_ON_ZERO",compatible_mode_normal_str[0]==0?"":",", - compatible_mode_normal_str); + "/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='%s%s%s' */;\n" + "/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;\n", + path?"":"NO_AUTO_VALUE_ON_ZERO",compatible_mode_normal_str[0]==0?"":",", + compatible_mode_normal_str); check_io(sql_file); } } /* write_header */ @@ -563,7 +563,7 @@ static void write_footer(FILE *sql_file) "/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;\n" "/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;\n"); fprintf(sql_file, - "/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;\n"); + "/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;\n"); fputs("\n", sql_file); check_io(sql_file); } @@ -577,7 +577,7 @@ static void free_table_ent(char *key) byte* get_table_key(const char *entry, uint *length, - my_bool not_used __attribute__((unused))) + my_bool not_used __attribute__((unused))) { *length= strlen(entry); return (byte*) entry; @@ -594,7 +594,7 @@ void init_table_rule_hash(HASH* h) static my_bool get_one_option(int optid, const struct my_option *opt __attribute__((unused)), - char *argument) + char *argument) { switch (optid) { #ifdef __NETWARE__ @@ -608,9 +608,9 @@ get_one_option(int optid, const struct my_option *opt __attribute__((unused)), char *start=argument; my_free(opt_password,MYF(MY_ALLOW_ZERO_PTR)); opt_password=my_strdup(argument,MYF(MY_FAE)); - while (*argument) *argument++= 'x'; /* Destroy argument */ + while (*argument) *argument++= 'x'; /* Destroy argument */ if (*start) - start[1]=0; /* Cut length of argument */ + start[1]=0; /* Cut length of argument */ tty_password= 0; } else @@ -618,7 +618,7 @@ get_one_option(int optid, const struct my_option *opt __attribute__((unused)), break; case 'r': if (!(md_result_file = my_fopen(argument, O_WRONLY | FILE_BINARY, - MYF(MY_WME)))) + MYF(MY_WME)))) exit(1); break; case 'W': @@ -639,7 +639,7 @@ get_one_option(int optid, const struct my_option *opt __attribute__((unused)), case 'V': print_version(); exit(0); case 'X': opt_xml = 1; - extended_insert= opt_drop= opt_lock= + extended_insert= opt_drop= opt_lock= opt_disable_keys= opt_autocommit= opt_create_db= 0; break; case 'I': @@ -692,36 +692,36 @@ get_one_option(int optid, const struct my_option *opt __attribute__((unused)), opt_set_charset= 0; opt_compatible_mode_str= argument; opt_compatible_mode= find_set(&compatible_mode_typelib, - argument, strlen(argument), - &err_ptr, &err_len); + argument, strlen(argument), + &err_ptr, &err_len); if (err_len) { - strmake(buff, err_ptr, min(sizeof(buff), err_len)); - fprintf(stderr, "Invalid mode to --compatible: %s\n", buff); - exit(1); + strmake(buff, err_ptr, min(sizeof(buff), err_len)); + fprintf(stderr, "Invalid mode to --compatible: %s\n", buff); + exit(1); } #if !defined(DBUG_OFF) { - uint size_for_sql_mode= 0; - const char **ptr; - for (ptr= compatible_mode_names; *ptr; ptr++) - size_for_sql_mode+= strlen(*ptr); - size_for_sql_mode+= sizeof(compatible_mode_names)-1; - DBUG_ASSERT(sizeof(compatible_mode_normal_str)>=size_for_sql_mode); + uint size_for_sql_mode= 0; + const char **ptr; + for (ptr= compatible_mode_names; *ptr; ptr++) + size_for_sql_mode+= strlen(*ptr); + size_for_sql_mode+= sizeof(compatible_mode_names)-1; + DBUG_ASSERT(sizeof(compatible_mode_normal_str)>=size_for_sql_mode); } #endif mode= opt_compatible_mode; for (i= 0, mode= opt_compatible_mode; mode; mode>>= 1, i++) { - if (mode & 1) - { - end= strmov(end, compatible_mode_names[i]); - end= strmov(end, ","); - } + if (mode & 1) + { + end= strmov(end, compatible_mode_names[i]); + end= strmov(end, ","); + } } if (end!=compatible_mode_normal_str) - end[-1]= 0; - /* + end[-1]= 0; + /* Set charset to the default compiled value if it hasn't been reset yet by --default-character-set=xxx. */ @@ -733,8 +733,8 @@ get_one_option(int optid, const struct my_option *opt __attribute__((unused)), { if ((opt_protocol= find_type(argument, &sql_protocol_typelib,0)) <= 0) { - fprintf(stderr, "Unknown option to protocol: %s\n", argument); - exit(1); + fprintf(stderr, "Unknown option to protocol: %s\n", argument); + exit(1); } break; } @@ -760,12 +760,12 @@ static int get_options(int *argc, char ***argv) *mysql_params->p_net_buffer_length= opt_net_buffer_length; if (opt_delayed) - opt_lock=0; /* Can't have lock with delayed */ + opt_lock=0; /* Can't have lock with delayed */ if (!path && (enclosed || opt_enclosed || escaped || lines_terminated || - fields_terminated)) + fields_terminated)) { fprintf(stderr, - "%s: You must use option --tab with --fields-...\n", my_progname); + "%s: You must use option --tab with --fields-...\n", my_progname); return(1); } @@ -777,7 +777,7 @@ static int get_options(int *argc, char ***argv) fprintf(stderr, "%s: You can't use --single-transaction and " "--lock-all-tables at the same time.\n", my_progname); return(1); - } + } if (opt_master_data) opt_lock_all_tables= !opt_single_transaction; if (opt_single_transaction || opt_lock_all_tables) @@ -790,13 +790,13 @@ static int get_options(int *argc, char ***argv) if ((opt_databases || opt_alldbs) && path) { fprintf(stderr, - "%s: --databases or --all-databases can't be used with --tab.\n", - my_progname); + "%s: --databases or --all-databases can't be used with --tab.\n", + my_progname); return(1); } if (strcmp(default_charset, charset_info->csname) && - !(charset_info= get_charset_by_csname(default_charset, - MY_CS_PRIMARY, MYF(MY_WME)))) + !(charset_info= get_charset_by_csname(default_charset, + MY_CS_PRIMARY, MYF(MY_WME)))) exit(1); if ((*argc < 1 && !opt_alldbs) || (*argc > 0 && opt_alldbs)) { @@ -816,7 +816,7 @@ static void DB_error(MYSQL *mysql, const char *when) { DBUG_ENTER("DB_error"); my_printf_error(0,"Got error: %d: %s %s", MYF(0), - mysql_errno(mysql), mysql_error(mysql), when); + mysql_errno(mysql), mysql_error(mysql), when); safe_exit(EX_MYSQLERR); DBUG_VOID_RETURN; } /* DB_error */ @@ -830,14 +830,14 @@ static void DB_error(MYSQL *mysql, const char *when) mysql_query_with_error_report() mysql_con connection to use res if non zero, result will be put there with - mysql_store_result() + mysql_store_result() query query to send to server RETURN VALUES 0 query sending and (if res!=0) result reading went ok 1 error */ - + static int mysql_query_with_error_report(MYSQL *mysql_con, MYSQL_RES **res, const char *query) { @@ -869,7 +869,7 @@ static FILE* open_sql_file_for_table(const char* table) char filename[FN_REFLEN], tmp_path[FN_REFLEN]; convert_dirname(tmp_path,path,NullS); res= my_fopen(fn_format(filename, table, tmp_path, ".sql", 4), - O_WRONLY, MYF(MY_WME)); + O_WRONLY, MYF(MY_WME)); return res; } @@ -904,7 +904,7 @@ static int dbConnect(char *host, char *user,char *passwd) #ifdef HAVE_OPENSSL if (opt_use_ssl) mysql_ssl_set(&mysql_connection, opt_ssl_key, opt_ssl_cert, opt_ssl_ca, - opt_ssl_capath, opt_ssl_cipher); + opt_ssl_capath, opt_ssl_cipher); mysql_options(&mysql_connection,MYSQL_OPT_SSL_VERIFY_SERVER_CERT, (char*)&opt_ssl_verify_server_cert); #endif @@ -933,7 +933,7 @@ static int dbConnect(char *host, char *user,char *passwd) */ sock->reconnect= 0; my_snprintf(buff, sizeof(buff), "/*!40100 SET @@SQL_MODE='%s' */", - compatible_mode_normal_str); + compatible_mode_normal_str); if (mysql_query_with_error_report(sock, 0, buff)) { mysql_close(sock); @@ -941,7 +941,7 @@ static int dbConnect(char *host, char *user,char *passwd) return 1; } /* - set time_zone to UTC to allow dumping date types between servers with + set time_zone to UTC to allow dumping date types between servers with different time zone settings */ if (opt_tz_utc) @@ -975,8 +975,8 @@ static void unescape(FILE *file,char *pos,uint length) DBUG_ENTER("unescape"); if (!(tmp=(char*) my_malloc(length*2+1, MYF(MY_WME)))) { - ignore_errors=0; /* Fatal error */ - safe_exit(EX_MYSQLERR); /* Force exit */ + ignore_errors=0; /* Fatal error */ + safe_exit(EX_MYSQLERR); /* Force exit */ } mysql_real_escape_string(&mysql_connection, tmp, pos, length); fputc('\'', file); @@ -1003,13 +1003,13 @@ static my_bool test_if_special_chars(const char *str) /* quote_name(name, buff, force) - Quotes char string, taking into account compatible mode + Quotes char string, taking into account compatible mode Args name Unquoted string containing that which will be quoted buff The buffer that contains the quoted value, also returned - force Flag to make it ignore 'test_if_special_chars' + force Flag to make it ignore 'test_if_special_chars' Returns @@ -1082,13 +1082,13 @@ static char *quote_for_like(const char *name, char *buff) /* Quote and print a string. - + SYNOPSIS print_quoted_xml() - output - output file - str - string to print - len - its length - + output - output file + str - string to print + len - its length + DESCRIPTION Quote '<' '>' '&' '\"' chars and print a string to the xml_file. */ @@ -1096,7 +1096,7 @@ static char *quote_for_like(const char *name, char *buff) static void print_quoted_xml(FILE *xml_file, const char *str, ulong len) { const char *end; - + for (end= str + len; str != end; str++) { switch (*str) { @@ -1123,15 +1123,15 @@ static void print_quoted_xml(FILE *xml_file, const char *str, ulong len) /* Print xml tag with one attribute. - + SYNOPSIS print_xml_tag1() - xml_file - output file - sbeg - line beginning - stag_atr - tag and attribute - sval - value of attribute - send - line ending - + xml_file - output file + sbeg - line beginning + stag_atr - tag and attribute + sval - value of attribute + send - line ending + DESCRIPTION Print tag with one attribute to the xml_file. Format is: sbeg<stag_atr="sval">send @@ -1141,8 +1141,8 @@ static void print_quoted_xml(FILE *xml_file, const char *str, ulong len) */ static void print_xml_tag1(FILE * xml_file, const char* sbeg, - const char* stag_atr, const char* sval, - const char* send) + const char* stag_atr, const char* sval, + const char* send) { fputs(sbeg, xml_file); fputs("<", xml_file); @@ -1160,11 +1160,11 @@ static void print_xml_tag1(FILE * xml_file, const char* sbeg, SYNOPSIS print_xml_null_tag() - xml_file - output file - sbeg - line beginning - stag_atr - tag and attribute - sval - value of attribute - send - line ending + xml_file - output file + sbeg - line beginning + stag_atr - tag and attribute + sval - value of attribute + send - line ending DESCRIPTION Print tag with one attribute to the xml_file. Format is: @@ -1194,11 +1194,11 @@ static void print_xml_null_tag(FILE * xml_file, const char* sbeg, SYNOPSIS print_xml_row() - xml_file - output file - row_name - xml tag name - tableRes - query result - row - result row - + xml_file - output file + row_name - xml tag name + tableRes - query result + row - result row + DESCRIPTION Print tag with many attribute to the xml_file. Format is: \t\t<row_name Atr1="Val1" Atr2="Val2"... /> @@ -1207,7 +1207,7 @@ static void print_xml_null_tag(FILE * xml_file, const char* sbeg, */ static void print_xml_row(FILE *xml_file, const char *row_name, - MYSQL_RES *tableRes, MYSQL_ROW *row) + MYSQL_RES *tableRes, MYSQL_ROW *row) { uint i; MYSQL_FIELD *field; @@ -1324,7 +1324,7 @@ static uint dump_routines_for_db(char *db) */ definer_begin= strstr(row[2], " DEFINER"); - + if (definer_begin) { char *definer_end= strstr(definer_begin, " PROCEDURE"); @@ -1388,7 +1388,7 @@ static uint dump_routines_for_db(char *db) ARGS table - table name db - db name - table_type - table type ie "InnoDB" + table_type - table type, e.g. "MyISAM" or "InnoDB", but also "VIEW" ignore_flag - what we must particularly ignore - see IGNORE_ defines above RETURN @@ -1400,10 +1400,10 @@ static uint get_table_structure(char *table, char *db, char *table_type, { my_bool init=0, delayed, write_data, complete_insert; my_ulonglong num_fields; - char *result_table, *opt_quoted_table; + char *result_table, *opt_quoted_table; const char *insert_option; - char name_buff[NAME_LEN+3],table_buff[NAME_LEN*2+3]; - char table_buff2[NAME_LEN*2+3], query_buff[512]; + char name_buff[NAME_LEN+3],table_buff[NAME_LEN*2+3]; + char table_buff2[NAME_LEN*2+3], query_buff[512]; FILE *sql_file = md_result_file; int len; MYSQL_RES *result; @@ -1473,21 +1473,30 @@ static uint get_table_structure(char *table, char *db, char *table_type, { if (!(sql_file= open_sql_file_for_table(table))) { - safe_exit(EX_MYSQLERR); - DBUG_RETURN(0); + safe_exit(EX_MYSQLERR); + DBUG_RETURN(0); } write_header(sql_file, db); } if (!opt_xml && opt_comments) { + if (strcmp (table_type, "VIEW") == 0) /* view */ + fprintf(sql_file, "\n--\n-- Temporary table structure for view %s\n--\n\n", + result_table); + else fprintf(sql_file, "\n--\n-- Table structure for table %s\n--\n\n", - result_table); - check_io(sql_file); + result_table); + check_io(sql_file); } if (opt_drop) { - fprintf(sql_file, "DROP TABLE IF EXISTS %s;\n", opt_quoted_table); - check_io(sql_file); + /* + Even if the "table" is a view, we do a DROP TABLE here. The + view-specific code below fills in the DROP VIEW. + */ + fprintf(sql_file, "DROP TABLE IF EXISTS %s;\n", + opt_quoted_table); + check_io(sql_file); } result= mysql_store_result(sock); @@ -1500,7 +1509,7 @@ static uint get_table_structure(char *table, char *db, char *table_type, mysql_free_result(result); /* - Create a table with the same name as the view and with columns of + Create a table with the same name as the view and with columns of the same name in order to satisfy views that depend on this view. The table will be removed when the actual view is created. @@ -1524,10 +1533,13 @@ static uint get_table_structure(char *table, char *db, char *table_type, { if (opt_drop) { + /* + We have already dropped any table of the same name + above, so here we just drop the view. + */ + fprintf(sql_file, "/*!50001 DROP VIEW IF EXISTS %s*/;\n", opt_quoted_table); - fprintf(sql_file, "/*!50001 DROP TABLE IF EXISTS %s*/;\n", - opt_quoted_table); check_io(sql_file); } @@ -1554,7 +1566,7 @@ static uint get_table_structure(char *table, char *db, char *table_type, } mysql_free_result(result); - was_views= 1; + seen_views= 1; DBUG_RETURN(0); } @@ -1564,11 +1576,11 @@ static uint get_table_structure(char *table, char *db, char *table_type, mysql_free_result(result); } my_snprintf(query_buff, sizeof(query_buff), "show fields from %s", - result_table); + result_table); if (mysql_query_with_error_report(sock, &result, query_buff)) { if (path) - my_fclose(sql_file, MYF(MY_WME)); + my_fclose(sql_file, MYF(MY_WME)); safe_exit(EX_MYSQLERR); DBUG_RETURN(0); } @@ -1621,7 +1633,7 @@ static uint get_table_structure(char *table, char *db, char *table_type, my_progname, mysql_error(sock)); my_snprintf(query_buff, sizeof(query_buff), "show fields from %s", - result_table); + result_table); if (mysql_query_with_error_report(sock, &result, query_buff)) { safe_exit(EX_MYSQLERR); @@ -1635,18 +1647,18 @@ static uint get_table_structure(char *table, char *db, char *table_type, { if (!(sql_file= open_sql_file_for_table(table))) { - safe_exit(EX_MYSQLERR); - DBUG_RETURN(0); + safe_exit(EX_MYSQLERR); + DBUG_RETURN(0); } write_header(sql_file, db); } if (!opt_xml && opt_comments) - fprintf(sql_file, "\n--\n-- Table structure for table %s\n--\n\n", - result_table); + fprintf(sql_file, "\n--\n-- Table structure for table %s\n--\n\n", + result_table); if (opt_drop) fprintf(sql_file, "DROP TABLE IF EXISTS %s;\n", result_table); if (!opt_xml) - fprintf(sql_file, "CREATE TABLE %s (\n", result_table); + fprintf(sql_file, "CREATE TABLE %s (\n", result_table); else print_xml_tag1(sql_file, "\t", "table_structure name=", table, "\n"); check_io(sql_file); @@ -1674,10 +1686,10 @@ static uint get_table_structure(char *table, char *db, char *table_type, if (init) { if (!opt_xml && !tFlag) - { - fputs(",\n",sql_file); - check_io(sql_file); - } + { + fputs(",\n",sql_file); + check_io(sql_file); + } if (complete_insert) dynstr_append_mem(&insert_pat, ", ", 2); } @@ -1687,30 +1699,30 @@ static uint get_table_structure(char *table, char *db, char *table_type, quote_name(row[SHOW_FIELDNAME], name_buff, 0)); if (!tFlag) { - if (opt_xml) - { - print_xml_row(sql_file, "field", result, &row); - continue; - } + if (opt_xml) + { + print_xml_row(sql_file, "field", result, &row); + continue; + } if (opt_keywords) - fprintf(sql_file, " %s.%s %s", result_table, - quote_name(row[SHOW_FIELDNAME],name_buff, 0), - row[SHOW_TYPE]); + fprintf(sql_file, " %s.%s %s", result_table, + quote_name(row[SHOW_FIELDNAME],name_buff, 0), + row[SHOW_TYPE]); else - fprintf(sql_file, " %s %s", quote_name(row[SHOW_FIELDNAME], - name_buff, 0), - row[SHOW_TYPE]); + fprintf(sql_file, " %s %s", quote_name(row[SHOW_FIELDNAME], + name_buff, 0), + row[SHOW_TYPE]); if (row[SHOW_DEFAULT]) { - fputs(" DEFAULT ", sql_file); - unescape(sql_file, row[SHOW_DEFAULT], lengths[SHOW_DEFAULT]); + fputs(" DEFAULT ", sql_file); + unescape(sql_file, row[SHOW_DEFAULT], lengths[SHOW_DEFAULT]); } if (!row[SHOW_NULL][0]) - fputs(" NOT NULL", sql_file); + fputs(" NOT NULL", sql_file); if (row[SHOW_EXTRA][0]) - fprintf(sql_file, " %s",row[SHOW_EXTRA]); - check_io(sql_file); + fprintf(sql_file, " %s",row[SHOW_EXTRA]); + check_io(sql_file); } } num_fields= mysql_num_rows(result); @@ -1730,9 +1742,9 @@ static uint get_table_structure(char *table, char *db, char *table_type, 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(sock)); if (path) - my_fclose(sql_file, MYF(MY_WME)); + my_fclose(sql_file, MYF(MY_WME)); safe_exit(EX_MYSQLERR); DBUG_RETURN(0); } @@ -1744,102 +1756,102 @@ static uint get_table_structure(char *table, char *db, char *table_type, { if (atoi(row[3]) == 1) { - keynr++; + keynr++; #ifdef FORCE_PRIMARY_KEY - if (atoi(row[1]) == 0 && primary_key == INT_MAX) - primary_key=keynr; + if (atoi(row[1]) == 0 && primary_key == INT_MAX) + primary_key=keynr; #endif - if (!strcmp(row[2],"PRIMARY")) - { - primary_key=keynr; - break; - } + if (!strcmp(row[2],"PRIMARY")) + { + primary_key=keynr; + break; + } } } mysql_data_seek(result,0); keynr=0; while ((row= mysql_fetch_row(result))) { - if (opt_xml) - { - print_xml_row(sql_file, "key", result, &row); - continue; - } + if (opt_xml) + { + print_xml_row(sql_file, "key", result, &row); + continue; + } if (atoi(row[3]) == 1) { - if (keynr++) - putc(')', sql_file); - if (atoi(row[1])) /* Test if duplicate key */ - /* Duplicate allowed */ - fprintf(sql_file, ",\n KEY %s (",quote_name(row[2],name_buff,0)); - else if (keynr == primary_key) - fputs(",\n PRIMARY KEY (",sql_file); /* First UNIQUE is primary */ - else - fprintf(sql_file, ",\n UNIQUE %s (",quote_name(row[2],name_buff, - 0)); + if (keynr++) + putc(')', sql_file); + if (atoi(row[1])) /* Test if duplicate key */ + /* Duplicate allowed */ + fprintf(sql_file, ",\n KEY %s (",quote_name(row[2],name_buff,0)); + else if (keynr == primary_key) + fputs(",\n PRIMARY KEY (",sql_file); /* First UNIQUE is primary */ + else + fprintf(sql_file, ",\n UNIQUE %s (",quote_name(row[2],name_buff, + 0)); } else - putc(',', sql_file); + putc(',', sql_file); fputs(quote_name(row[4], name_buff, 0), sql_file); if (row[7]) - fprintf(sql_file, " (%s)",row[7]); /* Sub key */ - check_io(sql_file); + fprintf(sql_file, " (%s)",row[7]); /* Sub key */ + check_io(sql_file); } if (!opt_xml) { - if (keynr) - putc(')', sql_file); - fputs("\n)",sql_file); - check_io(sql_file); + if (keynr) + putc(')', sql_file); + fputs("\n)",sql_file); + check_io(sql_file); } /* Get MySQL specific create options */ if (create_options) { - char show_name_buff[NAME_LEN*2+2+24]; + char show_name_buff[NAME_LEN*2+2+24]; - /* Check memory for quote_for_like() */ + /* Check memory for quote_for_like() */ my_snprintf(buff, sizeof(buff), "show table status like %s", - quote_for_like(table, show_name_buff)); + quote_for_like(table, show_name_buff)); if (mysql_query_with_error_report(sock, &result, buff)) { - 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)); - } + 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)); + } } 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)); + fprintf(stderr, + "Error: Couldn't read status information for table %s (%s)\n", + result_table,mysql_error(sock)); } else { - if (opt_xml) - print_xml_row(sql_file, "options", result, &row); - else - { - fputs("/*!",sql_file); - print_value(sql_file,result,row,"engine=","Engine",0); - print_value(sql_file,result,row,"","Create_options",0); - print_value(sql_file,result,row,"comment=","Comment",1); - fputs(" */",sql_file); - check_io(sql_file); - } + if (opt_xml) + print_xml_row(sql_file, "options", result, &row); + else + { + fputs("/*!",sql_file); + print_value(sql_file,result,row,"engine=","Engine",0); + print_value(sql_file,result,row,"","Create_options",0); + print_value(sql_file,result,row,"comment=","Comment",1); + fputs(" */",sql_file); + check_io(sql_file); + } } - mysql_free_result(result); /* Is always safe to free */ + mysql_free_result(result); /* Is always safe to free */ } continue_xml: if (!opt_xml) - fputs(";\n", sql_file); + fputs(";\n", sql_file); else - fputs("\t</table_structure>\n", sql_file); + fputs("\t</table_structure>\n", sql_file); check_io(sql_file); } } @@ -1871,8 +1883,8 @@ continue_xml: static void dump_triggers_for_table (char *table, char *db) { - char *result_table; - char name_buff[NAME_LEN*4+3], table_buff[NAME_LEN*2+3]; + char *result_table; + char name_buff[NAME_LEN*4+3], table_buff[NAME_LEN*2+3]; char query_buff[512]; uint old_opt_compatible_mode=opt_compatible_mode; FILE *sql_file = md_result_file; @@ -1921,7 +1933,7 @@ DELIMITER ;;\n"); uint host_name_len; char host_name_str[HOSTNAME_LENGTH + 1]; char quoted_host_name_str[HOSTNAME_LENGTH * 2 + 3]; - + parse_user(row[7], strlen(row[7]), user_name_str, &user_name_len, host_name_str, &host_name_len); @@ -1937,7 +1949,7 @@ DELIMITER ;;\n"); row[4], /* Timing */ row[1], /* Event */ result_table, - (strchr(" \t\n\r", *(row[3]))) ? "" : " ", + (strchr(" \t\n\r", *(row[3]))) ? "" : " ", row[3] /* Statement */); } if (mysql_num_rows(result)) @@ -1946,7 +1958,7 @@ DELIMITER ;;\n"); "/*!50003 SET SESSION SQL_MODE=@OLD_SQL_MODE */;\n"); mysql_free_result(result); /* - make sure to set back opt_compatible mode to + make sure to set back opt_compatible mode to original value */ opt_compatible_mode=old_opt_compatible_mode; @@ -1954,7 +1966,7 @@ DELIMITER ;;\n"); } static char *add_load_option(char *ptr,const char *object, - const char *statement) + const char *statement) { if (object) { @@ -1993,7 +2005,7 @@ static char *field_escape(char *to,const char *from,uint length) else { if (*from == '\'' && !end_backslashes) - *to++= *from; /* We want a duplicate of "'" for MySQL */ + *to++= *from; /* We want a duplicate of "'" for MySQL */ end_backslashes=0; } } @@ -2010,8 +2022,8 @@ static char *alloc_query_str(ulong size) if (!(query= (char*) my_malloc(size, MYF(MY_WME)))) { - ignore_errors= 0; /* Fatal error */ - safe_exit(EX_MYSQLERR); /* Force exit */ + ignore_errors= 0; /* Fatal error */ + safe_exit(EX_MYSQLERR); /* Force exit */ } return query; } @@ -2040,11 +2052,11 @@ static void dump_table(char *table, char *db) char *result_table, table_buff2[NAME_LEN*2+3], *opt_quoted_table; char *query= query_buf; int error= 0; - ulong rownr, row_break, total_length, init_length; + ulong rownr, row_break, total_length, init_length; uint num_fields; - MYSQL_RES *res; - MYSQL_FIELD *field; - MYSQL_ROW row; + MYSQL_RES *res; + MYSQL_FIELD *field; + MYSQL_ROW row; DBUG_ENTER("dump_table"); /* @@ -2053,13 +2065,19 @@ static void dump_table(char *table, char *db) */ num_fields= get_table_structure(table, db, table_type, &ignore_flag); + /* + The "table" could be a view. If so, we don't do anything here. + */ + if (strcmp (table_type, "VIEW") == 0) + return; + /* Check --no-data flag */ if (dFlag) { if (verbose) fprintf(stderr, "-- Skipping dump data for table '%s', --no-data was used\n", - table); + table); DBUG_VOID_RETURN; } @@ -2074,8 +2092,8 @@ static void dump_table(char *table, char *db) { if (verbose) fprintf(stderr, - "-- Warning: Skipping data for table '%s' because it's of type %s\n", - table, table_type); + "-- 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 */ @@ -2083,8 +2101,8 @@ static void dump_table(char *table, char *db) { if (verbose) fprintf(stderr, - "-- Skipping dump data for table '%s', it has no fields\n", - table); + "-- Skipping dump data for table '%s', it has no fields\n", + table); DBUG_VOID_RETURN; } @@ -2100,11 +2118,11 @@ static void dump_table(char *table, char *db) my_load_path(tmp_path, tmp_path, NULL); fn_format(filename, table, tmp_path, ".txt", 4); my_delete(filename, MYF(0)); /* 'INTO OUTFILE' doesn't work, if - filename wasn't deleted */ + filename wasn't deleted */ to_unix_path(filename); - my_snprintf(query, QUERY_LENGTH, - "SELECT /*!40001 SQL_NO_CACHE */ * INTO OUTFILE '%s'", - filename); + my_snprintf(query, QUERY_LENGTH, + "SELECT /*!40001 SQL_NO_CACHE */ * INTO OUTFILE '%s'", + filename); end= strend(query); if (fields_terminated || enclosed || opt_enclosed || escaped) @@ -2141,12 +2159,12 @@ static void dump_table(char *table, char *db) if (!opt_xml && opt_comments) { fprintf(md_result_file,"\n--\n-- Dumping data for table %s\n--\n", - result_table); + result_table); check_io(md_result_file); } my_snprintf(query, QUERY_LENGTH, - "SELECT /*!40001 SQL_NO_CACHE */ * FROM %s", - result_table); + "SELECT /*!40001 SQL_NO_CACHE */ * FROM %s", + result_table); if (where || order_by) { query = alloc_query_str((ulong) (strlen(query) + 1 + @@ -2194,7 +2212,7 @@ static void dump_table(char *table, char *db) if (mysql_num_fields(res) != num_fields) { fprintf(stderr,"%s: Error in field count for table: %s ! Aborting.\n", - my_progname, result_table); + my_progname, result_table); error= EX_CONSCHECK; goto err; } @@ -2202,7 +2220,7 @@ static void dump_table(char *table, char *db) if (opt_disable_keys) { fprintf(md_result_file, "\n/*!40000 ALTER TABLE %s DISABLE KEYS */;\n", - opt_quoted_table); + opt_quoted_table); check_io(md_result_file); } if (opt_lock) @@ -2211,7 +2229,7 @@ static void dump_table(char *table, char *db) check_io(md_result_file); } - total_length= opt_net_buffer_length; /* Force row break */ + total_length= opt_net_buffer_length; /* Force row break */ row_break=0; rownr=0; init_length=(uint) insert_pat.length+4; @@ -2231,15 +2249,15 @@ static void dump_table(char *table, char *db) rownr++; if (!extended_insert && !opt_xml) { - fputs(insert_pat.str,md_result_file); - check_io(md_result_file); + fputs(insert_pat.str,md_result_file); + check_io(md_result_file); } mysql_field_seek(res,0); if (opt_xml) { fputs("\t<row>\n", md_result_file); - check_io(md_result_file); + check_io(md_result_file); } for (i = 0; i < mysql_num_fields(res); i++) @@ -2247,21 +2265,21 @@ static void dump_table(char *table, char *db) int is_blob; ulong length= lengths[i]; - if (!(field = mysql_fetch_field(res))) - { - my_snprintf(query, QUERY_LENGTH, - "%s: Not enough fields from table %s! Aborting.\n", - my_progname, result_table); - fputs(query,stderr); - error= EX_CONSCHECK; - goto err; - } - - /* - 63 is my_charset_bin. If charsetnr is not 63, - we have not a BLOB but a TEXT column. - we'll dump in hex only BLOB columns. - */ + if (!(field = mysql_fetch_field(res))) + { + my_snprintf(query, QUERY_LENGTH, + "%s: Not enough fields from table %s! Aborting.\n", + my_progname, result_table); + fputs(query,stderr); + error= EX_CONSCHECK; + goto err; + } + + /* + 63 is my_charset_bin. If charsetnr is not 63, + we have not a BLOB but a TEXT column. + we'll dump in hex only BLOB columns. + */ is_blob= (opt_hex_blob && field->charsetnr == 63 && (field->type == MYSQL_TYPE_BIT || field->type == MYSQL_TYPE_STRING || @@ -2271,36 +2289,36 @@ static void dump_table(char *table, char *db) field->type == MYSQL_TYPE_LONG_BLOB || field->type == MYSQL_TYPE_MEDIUM_BLOB || field->type == MYSQL_TYPE_TINY_BLOB)) ? 1 : 0; - if (extended_insert) - { - if (i == 0) - dynstr_set(&extended_row,"("); - else - dynstr_append(&extended_row,","); - - if (row[i]) - { - if (length) - { - if (!IS_NUM_FIELD(field)) - { - /* - "length * 2 + 2" is OK for both HEX and non-HEX modes: - - In HEX mode we need exactly 2 bytes per character - plus 2 bytes for '0x' prefix. - - In non-HEX mode we need up to 2 bytes per character, - plus 2 bytes for leading and trailing '\'' characters. - */ - if (dynstr_realloc(&extended_row,length * 2+2)) - { - fputs("Aborting dump (out of memory)",stderr); - error= EX_EOM; - goto err; - } + if (extended_insert) + { + if (i == 0) + dynstr_set(&extended_row,"("); + else + dynstr_append(&extended_row,","); + + if (row[i]) + { + if (length) + { + if (!IS_NUM_FIELD(field)) + { + /* + "length * 2 + 2" is OK for both HEX and non-HEX modes: + - In HEX mode we need exactly 2 bytes per character + plus 2 bytes for '0x' prefix. + - In non-HEX mode we need up to 2 bytes per character, + plus 2 bytes for leading and trailing '\'' characters. + */ + if (dynstr_realloc(&extended_row,length * 2+2)) + { + fputs("Aborting dump (out of memory)",stderr); + error= EX_EOM; + goto err; + } if (opt_hex_blob && is_blob) { dynstr_append(&extended_row, "0x"); - extended_row.length+= mysql_hex_string(extended_row.str + + extended_row.length+= mysql_hex_string(extended_row.str + extended_row.length, row[i], length); extended_row.str[extended_row.length]= '\0'; @@ -2315,94 +2333,94 @@ static void dump_table(char *table, char *db) extended_row.str[extended_row.length]='\0'; dynstr_append(&extended_row,"'"); } - } - else - { - /* change any strings ("inf", "-inf", "nan") into NULL */ - char *ptr = row[i]; - if (my_isalpha(charset_info, *ptr) || (*ptr == '-' && - my_isalpha(charset_info, ptr[1]))) - dynstr_append(&extended_row, "NULL"); - else - { - if (field->type == FIELD_TYPE_DECIMAL) - { - /* add " signs around */ - dynstr_append(&extended_row, "'"); - dynstr_append(&extended_row, ptr); - dynstr_append(&extended_row, "'"); - } - else - dynstr_append(&extended_row, ptr); - } - } - } - else - dynstr_append(&extended_row,"''"); - } - else if (dynstr_append(&extended_row,"NULL")) - { - fputs("Aborting dump (out of memory)",stderr); - error= EX_EOM; - goto err; - } - } - else - { - if (i && !opt_xml) - { - fputc(',', md_result_file); - check_io(md_result_file); - } - if (row[i]) - { - if (!IS_NUM_FIELD(field)) - { - if (opt_xml) - { - print_xml_tag1(md_result_file, "\t\t", "field name=", - field->name, ""); - print_quoted_xml(md_result_file, row[i], length); - fputs("</field>\n", md_result_file); - } - else if (opt_hex_blob && is_blob && length) + } + else + { + /* change any strings ("inf", "-inf", "nan") into NULL */ + char *ptr = row[i]; + if (my_isalpha(charset_info, *ptr) || (*ptr == '-' && + my_isalpha(charset_info, ptr[1]))) + dynstr_append(&extended_row, "NULL"); + else + { + if (field->type == FIELD_TYPE_DECIMAL) + { + /* add " signs around */ + dynstr_append(&extended_row, "'"); + dynstr_append(&extended_row, ptr); + dynstr_append(&extended_row, "'"); + } + else + dynstr_append(&extended_row, ptr); + } + } + } + else + dynstr_append(&extended_row,"''"); + } + else if (dynstr_append(&extended_row,"NULL")) + { + fputs("Aborting dump (out of memory)",stderr); + error= EX_EOM; + goto err; + } + } + else + { + if (i && !opt_xml) + { + fputc(',', md_result_file); + check_io(md_result_file); + } + if (row[i]) + { + if (!IS_NUM_FIELD(field)) + { + if (opt_xml) + { + print_xml_tag1(md_result_file, "\t\t", "field name=", + field->name, ""); + print_quoted_xml(md_result_file, row[i], length); + fputs("</field>\n", md_result_file); + } + else if (opt_hex_blob && is_blob && length) { /* sakaik got the idea to to provide blob's in hex notation. */ char *ptr= row[i], *end= ptr + length; fputs("0x", md_result_file); for (; ptr < end ; ptr++) - fprintf(md_result_file, "%02X", *((uchar *)ptr)); + fprintf(md_result_file, "%02X", *((uchar *)ptr)); } else unescape(md_result_file, row[i], length); - } - else - { - /* change any strings ("inf", "-inf", "nan") into NULL */ - char *ptr = row[i]; - if (opt_xml) - { - print_xml_tag1(md_result_file, "\t\t", "field name=", - field->name, ""); - fputs(!my_isalpha(charset_info, *ptr) ? ptr: "NULL", - md_result_file); - fputs("</field>\n", md_result_file); - } - else if (my_isalpha(charset_info, *ptr) || - (*ptr == '-' && my_isalpha(charset_info, ptr[1]))) - fputs("NULL", md_result_file); - else if (field->type == FIELD_TYPE_DECIMAL) - { - /* add " signs around */ - fputc('\'', md_result_file); - fputs(ptr, md_result_file); - fputc('\'', md_result_file); - } - else - fputs(ptr, md_result_file); - } - } - else + } + else + { + /* change any strings ("inf", "-inf", "nan") into NULL */ + char *ptr = row[i]; + if (opt_xml) + { + print_xml_tag1(md_result_file, "\t\t", "field name=", + field->name, ""); + fputs(!my_isalpha(charset_info, *ptr) ? ptr: "NULL", + md_result_file); + fputs("</field>\n", md_result_file); + } + else if (my_isalpha(charset_info, *ptr) || + (*ptr == '-' && my_isalpha(charset_info, ptr[1]))) + fputs("NULL", md_result_file); + else if (field->type == FIELD_TYPE_DECIMAL) + { + /* add " signs around */ + fputc('\'', md_result_file); + fputs(ptr, md_result_file); + fputc('\'', md_result_file); + } + else + fputs(ptr, md_result_file); + } + } + else { /* The field value is NULL */ if (!opt_xml) @@ -2412,61 +2430,61 @@ static void dump_table(char *table, char *db) field->name, "\n"); } check_io(md_result_file); - } + } } if (opt_xml) { fputs("\t</row>\n", md_result_file); - check_io(md_result_file); + check_io(md_result_file); } if (extended_insert) { - ulong row_length; - dynstr_append(&extended_row,")"); + ulong row_length; + dynstr_append(&extended_row,")"); row_length = 2 + extended_row.length; if (total_length + row_length < opt_net_buffer_length) { - total_length += row_length; - fputc(',',md_result_file); /* Always row break */ - fputs(extended_row.str,md_result_file); - } + total_length += row_length; + fputc(',',md_result_file); /* Always row break */ + fputs(extended_row.str,md_result_file); + } else { - if (row_break) - fputs(";\n", md_result_file); - row_break=1; /* This is first row */ + if (row_break) + fputs(";\n", md_result_file); + row_break=1; /* This is first row */ fputs(insert_pat.str,md_result_file); fputs(extended_row.str,md_result_file); - total_length = row_length+init_length; + total_length = row_length+init_length; } - check_io(md_result_file); + check_io(md_result_file); } else if (!opt_xml) { - fputs(");\n", md_result_file); - check_io(md_result_file); + fputs(");\n", md_result_file); + check_io(md_result_file); } } /* XML - close table tag and supress regular output */ if (opt_xml) - fputs("\t</table_data>\n", md_result_file); + fputs("\t</table_data>\n", md_result_file); else if (extended_insert && row_break) - fputs(";\n", md_result_file); /* If not empty table */ + fputs(";\n", md_result_file); /* If not empty table */ fflush(md_result_file); check_io(md_result_file); if (mysql_errno(sock)) { 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), - result_table, - rownr); + "%s: Error %d: %s when dumping table %s at row: %ld\n", + my_progname, + mysql_errno(sock), + mysql_error(sock), + result_table, + rownr); fputs(query,stderr); error= EX_CONSCHECK; goto err; @@ -2479,7 +2497,7 @@ static void dump_table(char *table, char *db) if (opt_disable_keys) { fprintf(md_result_file,"/*!40000 ALTER TABLE %s ENABLE KEYS */;\n", - opt_quoted_table); + opt_quoted_table); check_io(md_result_file); } if (opt_autocommit) @@ -2538,7 +2556,7 @@ static int dump_all_databases() if (dump_all_tables_in_db(row[0])) result=1; } - if (was_views) + if (seen_views) { if (mysql_query(sock, "SHOW DATABASES") || !(tableres = mysql_store_result(sock))) @@ -2567,7 +2585,7 @@ static int dump_databases(char **db_names) if (dump_all_tables_in_db(*db)) result=1; } - if (!result && was_views) + if (!result && seen_views) { for (db= db_names ; *db ; db++) { @@ -2583,26 +2601,26 @@ static int init_dumping(char *database) { if (mysql_get_server_version(sock) >= 50003 && !my_strcasecmp(&my_charset_latin1, database, "information_schema")) - return 1; + return 1; if (mysql_select_db(sock, database)) { DB_error(sock, "when selecting the database"); - return 1; /* If --force */ + return 1; /* If --force */ } if (!path && !opt_xml) { if (opt_databases || opt_alldbs) { /* - length of table name * 2 (if name contains quotes), 2 quotes and 0 + length of table name * 2 (if name contains quotes), 2 quotes and 0 */ char quoted_database_buf[64*2+3]; char *qdatabase= quote_name(database,quoted_database_buf,opt_quoted); if (opt_comments) { - fprintf(md_result_file,"\n--\n-- Current Database: %s\n--\n", qdatabase); - check_io(md_result_file); + fprintf(md_result_file,"\n--\n-- Current Database: %s\n--\n", qdatabase); + check_io(md_result_file); } if (!opt_create_db) { @@ -2610,9 +2628,9 @@ static int init_dumping(char *database) MYSQL_ROW row; MYSQL_RES *dbinfo; - my_snprintf(qbuf, sizeof(qbuf), - "SHOW CREATE DATABASE IF NOT EXISTS %s", - qdatabase); + my_snprintf(qbuf, sizeof(qbuf), + "SHOW CREATE DATABASE IF NOT EXISTS %s", + qdatabase); if (mysql_query(sock, qbuf) || !(dbinfo = mysql_store_result(sock))) { @@ -2621,22 +2639,22 @@ static int init_dumping(char *database) fprintf(md_result_file, "\n/*!40000 DROP DATABASE IF EXISTS %s;*/\n", qdatabase); - fprintf(md_result_file, - "\nCREATE DATABASE /*!32312 IF NOT EXISTS*/ %s;\n", - qdatabase); - } - else + fprintf(md_result_file, + "\nCREATE DATABASE /*!32312 IF NOT EXISTS*/ %s;\n", + qdatabase); + } + else { if (opt_drop_database) fprintf(md_result_file, "\n/*!40000 DROP DATABASE IF EXISTS %s*/;\n", qdatabase); - row = mysql_fetch_row(dbinfo); - if (row[1]) - { - fprintf(md_result_file,"\n%s;\n",row[1]); + row = mysql_fetch_row(dbinfo); + if (row[1]) + { + fprintf(md_result_file,"\n%s;\n",row[1]); } - } + } } fprintf(md_result_file,"\nUSE %s;\n", qdatabase); check_io(md_result_file); @@ -2741,8 +2759,6 @@ static my_bool dump_all_views_in_db(char *database) uint numrows; char table_buff[NAME_LEN*2+3]; - if (init_dumping(database)) - return 1; if (opt_xml) print_xml_tag1(md_result_file, "", "database name=", database, "\n"); if (lock_tables) @@ -2801,7 +2817,7 @@ static char *get_actual_table_name(const char *old_table_name, MEM_ROOT *root) /* Check memory for quote_for_like() */ DBUG_ASSERT(2*sizeof(old_table_name) < sizeof(show_name_buff)); my_snprintf(query, sizeof(query), "SHOW TABLES LIKE %s", - quote_for_like(old_table_name, show_name_buff)); + quote_for_like(old_table_name, show_name_buff)); if (mysql_query_with_error_report(sock, 0, query)) { @@ -2896,7 +2912,7 @@ static int dump_selected_tables(char *db, char **table_names, int tables) } /* Dump each selected view */ - if (was_views) + if (seen_views) { for (pos= dump_tables; pos < end; pos++) get_view_structure(*pos, db); @@ -2946,14 +2962,14 @@ static int do_show_master_status(MYSQL *mysql_con) "recovery from\n--\n\n"); fprintf(md_result_file, "%sCHANGE MASTER TO MASTER_LOG_FILE='%s', MASTER_LOG_POS=%s;\n", - comment_prefix, row[0], row[1]); + comment_prefix, row[0], row[1]); check_io(md_result_file); } else if (!ignore_errors) { /* SHOW MASTER STATUS reports nothing and --force is not enabled */ - my_printf_error(0, "Error: Binlogging on server not active", - MYF(0)); + my_printf_error(0, "Error: Binlogging on server not active", + MYF(0)); mysql_free_result(master); return 1; } @@ -2973,7 +2989,7 @@ static int do_flush_tables_read_lock(MYSQL *mysql_con) and most client connections are stalled. Of course, if a second long update starts between the two FLUSHes, we have that bad stall. */ - return + return ( mysql_query_with_error_report(mysql_con, 0, "FLUSH TABLES") || mysql_query_with_error_report(mysql_con, 0, "FLUSH TABLES WITH READ LOCK") ); @@ -3015,7 +3031,7 @@ static int start_transaction(MYSQL *mysql_con, my_bool consistent_read_now) static ulong find_set(TYPELIB *lib, const char *x, uint length, - char **err_pos, uint *err_len) + char **err_pos, uint *err_len) { const char *end= x + length; ulong found= 0; @@ -3057,10 +3073,10 @@ static ulong find_set(TYPELIB *lib, const char *x, uint length, /* Print a value with a prefix on file */ static void print_value(FILE *file, MYSQL_RES *result, MYSQL_ROW row, - const char *prefix, const char *name, - int string_value) + const char *prefix, const char *name, + int string_value) { - MYSQL_FIELD *field; + MYSQL_FIELD *field; mysql_field_seek(result, 0); for ( ; (field = mysql_fetch_field(result)) ; row++) @@ -3069,18 +3085,18 @@ static void print_value(FILE *file, MYSQL_RES *result, MYSQL_ROW row, { if (row[0] && row[0][0] && strcmp(row[0],"0")) /* Skip default */ { - fputc(' ',file); - fputs(prefix, file); - if (string_value) - unescape(file,row[0],(uint) strlen(row[0])); - else - fputs(row[0], file); - check_io(file); - return; + fputc(' ',file); + fputs(prefix, file); + if (string_value) + unescape(file,row[0],(uint) strlen(row[0])); + else + fputs(row[0], file); + check_io(file); + return; } } } - return; /* This shouldn't happen */ + return; /* This shouldn't happen */ } /* print_value */ @@ -3091,19 +3107,19 @@ static void print_value(FILE *file, MYSQL_RES *result, MYSQL_ROW row, Check if we the table is one of the table types that should be ignored: MRG_ISAM, MRG_MYISAM, if opt_delayed, if that table supports delayed inserts. If the table should be altogether ignored, it returns a TRUE, FALSE if it - should not be ignored. If the user has selected to use INSERT DELAYED, it - sets the value of the bool pointer supports_delayed_inserts to 0 if not + should not be ignored. If the user has selected to use INSERT DELAYED, it + sets the value of the bool pointer supports_delayed_inserts to 0 if not supported, 1 if it is supported. ARGS check_if_ignore_table() - table_name Table name to check + table_name Table name to check table_type Type of table GLOBAL VARIABLES - sock MySQL socket - verbose Write warning messages + sock MySQL socket + verbose Write warning messages RETURN char (bit value) See IGNORE_ values at top @@ -3120,23 +3136,23 @@ char check_if_ignore_table(const char *table_name, char *table_type) /* Check memory for quote_for_like() */ 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)); + quote_for_like(table_name, show_name_buff)); if (mysql_query_with_error_report(sock, &res, buff)) { if (mysql_errno(sock) != ER_PARSE_ERROR) - { /* If old MySQL version */ + { /* If old MySQL version */ if (verbose) - fprintf(stderr, - "-- Warning: Couldn't get status information for table %s (%s)\n", - table_name,mysql_error(sock)); + fprintf(stderr, + "-- Warning: Couldn't get status information for table %s (%s)\n", + table_name,mysql_error(sock)); DBUG_RETURN(result); /* assume table is ok */ } } if (!(row= mysql_fetch_row(res))) { fprintf(stderr, - "Error: Couldn't read status information for table %s (%s)\n", - table_name, mysql_error(sock)); + "Error: Couldn't read status information for table %s (%s)\n", + table_name, mysql_error(sock)); mysql_free_result(res); DBUG_RETURN(result); /* assume table is ok */ } @@ -3199,8 +3215,8 @@ static char *primary_key_fields(const char *table_name) uint result_length = 0; char *result = 0; - my_snprintf(show_keys_buff, sizeof(show_keys_buff), - "SHOW KEYS FROM %s", 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))) { @@ -3276,7 +3292,7 @@ static int replace(DYNAMIC_STRING *ds_str, if (!start) return 1; init_dynamic_string(&ds_tmp, "", - ds_str->length + replace_len, 256); + ds_str->length + replace_len, 256); dynstr_append_mem(&ds_tmp, ds_str->str, start - ds_str->str); dynstr_append_mem(&ds_tmp, replace_str, replace_len); dynstr_append(&ds_tmp, start + search_len); @@ -3304,9 +3320,9 @@ static my_bool get_view_structure(char *table, char* db) MYSQL_RES *table_res; MYSQL_ROW row; MYSQL_FIELD *field; - char *result_table, *opt_quoted_table; - char table_buff[NAME_LEN*2+3]; - char table_buff2[NAME_LEN*2+3]; + char *result_table, *opt_quoted_table; + char table_buff[NAME_LEN*2+3]; + char table_buff2[NAME_LEN*2+3]; char query[QUERY_LENGTH]; FILE *sql_file = md_result_file; DBUG_ENTER("get_view_structure"); @@ -3319,7 +3335,7 @@ static my_bool get_view_structure(char *table, char* db) #ifdef NOT_REALLY_USED_YET sprintf(insert_pat,"SET OPTION SQL_QUOTE_SHOW_CREATE=%d", - (opt_quoted || opt_keywords)); + (opt_quoted || opt_keywords)); #endif result_table= quote_name(table, table_buff, 1); @@ -3354,7 +3370,7 @@ static my_bool get_view_structure(char *table, char* db) if (!opt_xml && opt_comments) { - fprintf(sql_file, "\n--\n-- View structure for view %s\n--\n\n", + fprintf(sql_file, "\n--\n-- Final view structure for view %s\n--\n\n", result_table); check_io(sql_file); } @@ -3435,7 +3451,7 @@ static my_bool get_view_structure(char *table, char* db) char quoted_host_name_str[HOSTNAME_LENGTH * 2 + 3]; parse_user(row[1], lengths[1], user_name_str, &user_name_len, - host_name_str, &host_name_len); + host_name_str, &host_name_len); ptr= search_buf; search_len= diff --git a/innobase/row/row0mysql.c b/innobase/row/row0mysql.c index 89b82882d93..9e922a3e04a 100644 --- a/innobase/row/row0mysql.c +++ b/innobase/row/row0mysql.c @@ -2570,14 +2570,14 @@ do not allow the discard. We also reserve the data dictionary latch. */ } } funct_exit: + trx_commit_for_mysql(trx); + row_mysql_unlock_data_dictionary(trx); if (graph) { que_graph_free(graph); } - trx_commit_for_mysql(trx); - trx->op_info = ""; return((int) err); @@ -2707,10 +2707,10 @@ row_import_tablespace_for_mysql( } funct_exit: - row_mysql_unlock_data_dictionary(trx); - trx_commit_for_mysql(trx); + row_mysql_unlock_data_dictionary(trx); + trx->op_info = ""; return((int) err); @@ -3398,6 +3398,8 @@ fputs(" InnoDB: You are trying to drop table ", stderr); } funct_exit: + trx_commit_for_mysql(trx); + if (locked_dictionary) { row_mysql_unlock_data_dictionary(trx); } @@ -3408,8 +3410,6 @@ funct_exit: que_graph_free(graph); - trx_commit_for_mysql(trx); - trx->op_info = ""; #ifndef UNIV_HOTBACKUP @@ -3488,10 +3488,10 @@ loop: } } - row_mysql_unlock_data_dictionary(trx); - trx_commit_for_mysql(trx); + row_mysql_unlock_data_dictionary(trx); + trx->op_info = ""; return(err); @@ -3905,6 +3905,8 @@ row_rename_table_for_mysql( } } funct_exit: + trx_commit_for_mysql(trx); + if (!recovering_temp_table) { row_mysql_unlock_data_dictionary(trx); } @@ -3917,8 +3919,6 @@ funct_exit: mem_heap_free(heap); } - trx_commit_for_mysql(trx); - trx->op_info = ""; return((int) err); diff --git a/innobase/row/row0sel.c b/innobase/row/row0sel.c index 1402d3aaba6..23971767e7e 100644 --- a/innobase/row/row0sel.c +++ b/innobase/row/row0sel.c @@ -1064,11 +1064,12 @@ row_sel_try_search_shortcut( ut_ad(plan->pcur.latch_mode == node->latch_mode); plan->n_rows_fetched++; + ret = SEL_FOUND; func_exit: if (UNIV_LIKELY_NULL(heap)) { mem_heap_free(heap); } - return(SEL_FOUND); + return(ret); } /************************************************************************* diff --git a/mysql-test/r/func_in.result b/mysql-test/r/func_in.result index f758e2adfd9..e38e2624e19 100644 --- a/mysql-test/r/func_in.result +++ b/mysql-test/r/func_in.result @@ -202,35 +202,6 @@ select count(*) from t1 where id not in (1,2); count(*) 1 drop table t1; -create table t1 (f1 char(1), f2 int); -insert into t1 values (1,0),('a',1),('z',2); -select f1 from t1 where f1 in (1,'z'); -f1 -1 -z -select f2 from t1 where f2 in (1,'z'); -f2 -0 -1 -Warnings: -Warning 1292 Truncated incorrect INTEGER value: 'z' -select f1 from t1 where 'z' in (1,f1); -f1 -z -select * from t1 where 'z' in (f2,f1); -f1 f2 -1 0 -a 1 -z 2 -Warnings: -Warning 1292 Truncated incorrect DOUBLE value: 'z' -Warning 1292 Truncated incorrect DOUBLE value: 'z' -Warning 1292 Truncated incorrect DOUBLE value: 'z' -select * from t1 where 1 in (f2,f1); -f1 f2 -1 0 -a 1 -drop table t1; CREATE TABLE t1 (a int PRIMARY KEY); INSERT INTO t1 VALUES (44), (45), (46); SELECT * FROM t1 WHERE a IN (45); diff --git a/mysql-test/r/func_time.result b/mysql-test/r/func_time.result index f1da903ae98..593ce7b26c8 100644 --- a/mysql-test/r/func_time.result +++ b/mysql-test/r/func_time.result @@ -785,8 +785,8 @@ select f1 from t1 where "2006-1-1" between f1 and 'zzz'; f1 Warnings: Warning 1292 Incorrect date value: 'zzz' for column 'f1' at row 1 -Warning 1292 Truncated incorrect INTEGER value: 'zzz' -Warning 1292 Truncated incorrect INTEGER value: 'zzz' +Warning 1292 Truncated incorrect DOUBLE value: 'zzz' +Warning 1292 Truncated incorrect DOUBLE value: 'zzz' select f1 from t1 where makedate(2006,1) between date(f1) and date(f3); f1 2006-01-01 @@ -794,10 +794,17 @@ select f1 from t1 where makedate(2006,2) between date(f1) and date(f3); f1 2006-01-02 drop table t1; -select now() - now() + 0, curtime() - curtime() + 0, +create table t1 select now() - now(), curtime() - curtime(), sec_to_time(1) + 0, from_unixtime(1) + 0; -now() - now() + 0 curtime() - curtime() + 0 sec_to_time(1) + 0 from_unixtime(1) + 0 -0.000000 0.000000 1.000000 19700101030001.000000 +show create table t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `now() - now()` double(23,6) NOT NULL default '0.000000', + `curtime() - curtime()` double(23,6) NOT NULL default '0.000000', + `sec_to_time(1) + 0` double(23,6) default NULL, + `from_unixtime(1) + 0` double(23,6) default NULL +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +drop table t1; explain extended select timestampdiff(SQL_TSI_WEEK, '2001-02-01', '2001-05-01') as a1, timestampdiff(SQL_TSI_FRAC_SECOND, '2001-02-01 12:59:59.120000', '2001-05-01 12:58:58.119999') as a2; id select_type table type possible_keys key key_len ref rows Extra diff --git a/mysql-test/r/insert_select.result b/mysql-test/r/insert_select.result index 434dddb3049..2cfbb51441d 100644 --- a/mysql-test/r/insert_select.result +++ b/mysql-test/r/insert_select.result @@ -686,3 +686,7 @@ ERROR 42S22: Unknown column 'z' in 'field list' insert into t1(x,y) select x,z from t2 on duplicate key update x=values(t2.x); ERROR 42S22: Unknown column 't2.x' in 'field list' drop table t1,t2; +CREATE TABLE t1 (a int PRIMARY KEY); +INSERT INTO t1 values (1), (2); +INSERT INTO t1 SELECT a + 2 FROM t1 LIMIT 1; +DROP TABLE t1; diff --git a/mysql-test/r/lock_multi.result b/mysql-test/r/lock_multi.result index 2cb122fb988..2188d58e526 100644 --- a/mysql-test/r/lock_multi.result +++ b/mysql-test/r/lock_multi.result @@ -67,3 +67,9 @@ Select_priv N use test; use test; +create table t1 (f1 int(12) unsigned not null auto_increment, primary key(f1)) engine=innodb; +lock tables t1 write; + alter table t1 auto_increment=0; alter table t1 auto_increment=0; alter table t1 auto_increment=0; alter table t1 auto_increment=0; alter table t1 auto_increment=0; // + alter table t1 auto_increment=0; alter table t1 auto_increment=0; alter table t1 auto_increment=0; alter table t1 auto_increment=0; alter table t1 auto_increment=0; // +unlock tables; +drop table t1; diff --git a/mysql-test/r/myisam.result b/mysql-test/r/myisam.result index 6004575a0e4..780287fb807 100644 --- a/mysql-test/r/myisam.result +++ b/mysql-test/r/myisam.result @@ -747,6 +747,19 @@ select count(id1) from t1 where id2 = 10; count(id1) 5 drop table t1; +CREATE TABLE t1(a TINYINT, KEY(a)) ENGINE=MyISAM; +INSERT INTO t1 VALUES(1); +SELECT MAX(a) FROM t1 IGNORE INDEX(a); +MAX(a) +1 +ALTER TABLE t1 DISABLE KEYS; +SELECT MAX(a) FROM t1; +MAX(a) +1 +SELECT MAX(a) FROM t1 IGNORE INDEX(a); +MAX(a) +1 +DROP TABLE t1; CREATE TABLE t1(a CHAR(9), b VARCHAR(7)) ENGINE=MyISAM; INSERT INTO t1(a) VALUES('xxxxxxxxx'),('xxxxxxxxx'); UPDATE t1 AS ta1,t1 AS ta2 SET ta1.b='aaaaaa',ta2.b='bbbbbb'; diff --git a/mysql-test/r/mysqldump.result b/mysql-test/r/mysqldump.result index eff46ecc2d6..e496e1ef35d 100644 --- a/mysql-test/r/mysqldump.result +++ b/mysql-test/r/mysqldump.result @@ -1458,7 +1458,6 @@ UNLOCK TABLES; /*!40000 ALTER TABLE `t2` ENABLE KEYS */; DROP TABLE IF EXISTS `v2`; /*!50001 DROP VIEW IF EXISTS `v2`*/; -/*!50001 DROP TABLE IF EXISTS `v2`*/; /*!50001 CREATE TABLE `v2` ( `a` varchar(30) ) */; @@ -1764,7 +1763,6 @@ UNLOCK TABLES; /*!40000 ALTER TABLE `t1` ENABLE KEYS */; DROP TABLE IF EXISTS `v1`; /*!50001 DROP VIEW IF EXISTS `v1`*/; -/*!50001 DROP TABLE IF EXISTS `v1`*/; /*!50001 CREATE TABLE `v1` ( `a` int(11) ) */; @@ -1822,7 +1820,6 @@ UNLOCK TABLES; /*!40000 ALTER TABLE `t2` ENABLE KEYS */; DROP TABLE IF EXISTS `v2`; /*!50001 DROP VIEW IF EXISTS `v2`*/; -/*!50001 DROP TABLE IF EXISTS `v2`*/; /*!50001 CREATE TABLE `v2` ( `a` varchar(30) ) */; @@ -1915,7 +1912,6 @@ UNLOCK TABLES; /*!40000 ALTER TABLE `t1` ENABLE KEYS */; DROP TABLE IF EXISTS `v1`; /*!50001 DROP VIEW IF EXISTS `v1`*/; -/*!50001 DROP TABLE IF EXISTS `v1`*/; /*!50001 CREATE TABLE `v1` ( `a` int(11), `b` int(11), @@ -1923,13 +1919,11 @@ DROP TABLE IF EXISTS `v1`; ) */; DROP TABLE IF EXISTS `v2`; /*!50001 DROP VIEW IF EXISTS `v2`*/; -/*!50001 DROP TABLE IF EXISTS `v2`*/; /*!50001 CREATE TABLE `v2` ( `a` int(11) ) */; DROP TABLE IF EXISTS `v3`; /*!50001 DROP VIEW IF EXISTS `v3`*/; -/*!50001 DROP TABLE IF EXISTS `v3`*/; /*!50001 CREATE TABLE `v3` ( `a` int(11), `b` int(11), @@ -2490,7 +2484,6 @@ UNLOCK TABLES; /*!40000 ALTER TABLE `t1` ENABLE KEYS */; DROP TABLE IF EXISTS `v0`; /*!50001 DROP VIEW IF EXISTS `v0`*/; -/*!50001 DROP TABLE IF EXISTS `v0`*/; /*!50001 CREATE TABLE `v0` ( `a` int(11), `b` varchar(32), @@ -2498,7 +2491,6 @@ DROP TABLE IF EXISTS `v0`; ) */; DROP TABLE IF EXISTS `v1`; /*!50001 DROP VIEW IF EXISTS `v1`*/; -/*!50001 DROP TABLE IF EXISTS `v1`*/; /*!50001 CREATE TABLE `v1` ( `a` int(11), `b` varchar(32), @@ -2506,16 +2498,11 @@ DROP TABLE IF EXISTS `v1`; ) */; DROP TABLE IF EXISTS `v2`; /*!50001 DROP VIEW IF EXISTS `v2`*/; -/*!50001 DROP TABLE IF EXISTS `v2`*/; /*!50001 CREATE TABLE `v2` ( `a` int(11), `b` varchar(32), `c` varchar(32) ) */; - -CREATE DATABASE /*!32312 IF NOT EXISTS*/ `test` /*!40100 DEFAULT CHARACTER SET latin1 */; - -USE `test`; /*!50001 DROP TABLE IF EXISTS `v0`*/; /*!50001 DROP VIEW IF EXISTS `v0`*/; /*!50001 CREATE ALGORITHM=UNDEFINED */ @@ -2770,3 +2757,62 @@ p CREATE DEFINER=`root`@`localhost` PROCEDURE `p`() select 42 drop function f; drop procedure p; +create database mysqldump_test_db; +use mysqldump_test_db; +create table t1 (id int); +create view v1 as select * from t1; +insert into t1 values (1232131); +insert into t1 values (4711); +insert into t1 values (3231); +insert into t1 values (0815); + +/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */; +/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */; +/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */; +/*!40101 SET NAMES utf8 */; +/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */; +/*!40103 SET TIME_ZONE='+00:00' */; +/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */; +/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */; +/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */; +/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */; + +/*!40000 DROP DATABASE IF EXISTS `mysqldump_test_db`*/; + +CREATE DATABASE /*!32312 IF NOT EXISTS*/ `mysqldump_test_db` /*!40100 DEFAULT CHARACTER SET latin1 */; + +USE `mysqldump_test_db`; +DROP TABLE IF EXISTS `t1`; +CREATE TABLE `t1` ( + `id` int(11) default NULL +) ENGINE=MyISAM DEFAULT CHARSET=latin1; + + +/*!40000 ALTER TABLE `t1` DISABLE KEYS */; +LOCK TABLES `t1` WRITE; +INSERT INTO `t1` VALUES (1232131),(4711),(3231),(815); +UNLOCK TABLES; +/*!40000 ALTER TABLE `t1` ENABLE KEYS */; +DROP TABLE IF EXISTS `v1`; +/*!50001 DROP VIEW IF EXISTS `v1`*/; +/*!50001 CREATE TABLE `v1` ( + `id` int(11) +) */; +/*!50001 DROP TABLE IF EXISTS `v1`*/; +/*!50001 DROP VIEW IF EXISTS `v1`*/; +/*!50001 CREATE ALGORITHM=UNDEFINED */ +/*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ +/*!50001 VIEW `v1` AS select `t1`.`id` AS `id` from `t1` */; +/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */; + +/*!40101 SET SQL_MODE=@OLD_SQL_MODE */; +/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */; +/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */; +/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */; +/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */; +/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; +/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */; + +drop view v1; +drop table t1; +drop database mysqldump_test_db; diff --git a/mysql-test/r/ndb_replace.result b/mysql-test/r/ndb_replace.result index 5d772620b2c..cdfcd6a7a43 100644 --- a/mysql-test/r/ndb_replace.result +++ b/mysql-test/r/ndb_replace.result @@ -1,4 +1,4 @@ -drop table if exists t1; +drop table if exists t1,t2; CREATE TABLE t1 ( gesuchnr int(11) DEFAULT '0' NOT NULL, benutzer_id int(11) DEFAULT '0' NOT NULL, @@ -31,3 +31,24 @@ SELECT * from t1 ORDER BY i; i j k 3 1 42 17 2 24 +CREATE TABLE t2 (a INT(11) NOT NULL, +b INT(11) NOT NULL, +c INT(11) NOT NULL, +x TEXT, +y TEXT, +z TEXT, +id INT(10) unsigned NOT NULL AUTO_INCREMENT, +i INT(11) DEFAULT NULL, +PRIMARY KEY (id), +UNIQUE KEY a (a,b,c) +) ENGINE=ndbcluster; +REPLACE INTO t2 (a,b,c,x,y,z,i) VALUES (1,1,1,'a','a','a',1),(1,1,1,'b','b','b',2), (1,1,1,'c','c','c',3); +SELECT * FROM t2 ORDER BY id; +a b c x y z id i +1 1 1 c c c 3 3 +REPLACE INTO t2(a,b,c,x,y,z,i) values (1,1,1,'a','a','a',1); +REPLACE INTO t2(a,b,c,x,y,z,i) values (1,1,1,'b','b','b',2); +SELECT * FROM t2 ORDER BY id; +a b c x y z id i +1 1 1 b b b 5 2 +DROP TABLE t2; diff --git a/mysql-test/r/rpl_auto_increment_11932.result b/mysql-test/r/rpl_auto_increment_11932.result new file mode 100644 index 00000000000..25eda6ee454 --- /dev/null +++ b/mysql-test/r/rpl_auto_increment_11932.result @@ -0,0 +1,47 @@ +stop slave; +drop table if exists t1,t2,t3,t4,t5,t6,t7,t8,t9; +reset master; +reset slave; +drop table if exists t1,t2,t3,t4,t5,t6,t7,t8,t9; +start slave; +drop database if exists test1; +create database test1; +use test1; +CREATE TABLE `t1` ( +`id` int(10) unsigned NOT NULL auto_increment, +`fname` varchar(100) default NULL, +PRIMARY KEY (`id`) +) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=2 ; +INSERT INTO `t1` VALUES (1, 'blablabla'); +CREATE TABLE `t2` ( +`id` int(10) NOT NULL auto_increment, +`comment` varchar(255) NOT NULL default '', +PRIMARY KEY (`id`) +) ENGINE=MyISAM AUTO_INCREMENT=3 ; +INSERT INTO `t2` VALUES (1, 'testtest 1'); +INSERT INTO `t2` VALUES (2, 'test 2'); +CREATE PROCEDURE simpleproc3 () +NOT DETERMINISTIC +BEGIN +INSERT INTO t1 (fname) (SELECT t2.comment FROM t2 WHERE t2.id = '1'); +INSERT INTO t1 (fname) VALUES('test'); +END +$ +CALL simpleproc3(); +select * from t2; +id comment +1 testtest 1 +2 test 2 +TRUNCATE TABLE `t1`; +CALL simpleproc3(); +select * from t1; +id fname +1 testtest 1 +2 test +use test1; +select * from t1; +id fname +1 testtest 1 +2 test +drop database test1; +drop database test1; diff --git a/mysql-test/r/select.result b/mysql-test/r/select.result index b385c576f2e..e6c590489a0 100644 --- a/mysql-test/r/select.result +++ b/mysql-test/r/select.result @@ -2730,6 +2730,12 @@ ERROR HY000: Key 'a' doesn't exist in table 't1' EXPLAIN SELECT * FROM t1 FORCE INDEX (a); ERROR HY000: Key 'a' doesn't exist in table 't1' DROP TABLE t1; +CREATE TABLE t1 (i BIGINT UNSIGNED NOT NULL); +INSERT INTO t1 VALUES (10); +SELECT i='1e+01',i=1e+01, i in (1e+01,1e+01), i in ('1e+01','1e+01') FROM t1; +i='1e+01' i=1e+01 i in (1e+01,1e+01) i in ('1e+01','1e+01') +0 1 1 1 +DROP TABLE t1; CREATE TABLE t1 ( K2C4 varchar(4) character set latin1 collate latin1_bin NOT NULL default '', K4N4 varchar(4) character set latin1 collate latin1_bin NOT NULL default '0000', diff --git a/mysql-test/r/sql_mode.result b/mysql-test/r/sql_mode.result index b05680f9c54..474659f7dfc 100644 --- a/mysql-test/r/sql_mode.result +++ b/mysql-test/r/sql_mode.result @@ -485,6 +485,10 @@ set sql_mode=2097152; select @@sql_mode; @@sql_mode STRICT_TRANS_TABLES +set sql_mode=4194304; +select @@sql_mode; +@@sql_mode +STRICT_ALL_TABLES set sql_mode=16384+(65536*4); select @@sql_mode; @@sql_mode diff --git a/mysql-test/t/func_in.test b/mysql-test/t/func_in.test index 5a5e3ec798d..8ddf1fbe314 100644 --- a/mysql-test/t/func_in.test +++ b/mysql-test/t/func_in.test @@ -109,18 +109,6 @@ select count(*) from t1 where id not in (1); select count(*) from t1 where id not in (1,2); drop table t1; -# -# Bug#18360 Incorrect type coercion in IN() results in false comparison -# -create table t1 (f1 char(1), f2 int); -insert into t1 values (1,0),('a',1),('z',2); -select f1 from t1 where f1 in (1,'z'); -select f2 from t1 where f2 in (1,'z'); -select f1 from t1 where 'z' in (1,f1); -select * from t1 where 'z' in (f2,f1); -select * from t1 where 1 in (f2,f1); -drop table t1; - # End of 4.1 tests # diff --git a/mysql-test/t/func_time.test b/mysql-test/t/func_time.test index 4032d5a0a5c..d817d016881 100644 --- a/mysql-test/t/func_time.test +++ b/mysql-test/t/func_time.test @@ -392,8 +392,10 @@ drop table t1; # Bug #16546 # -select now() - now() + 0, curtime() - curtime() + 0, - sec_to_time(1) + 0, from_unixtime(1) + 0; +create table t1 select now() - now(), curtime() - curtime(), + sec_to_time(1) + 0, from_unixtime(1) + 0; +show create table t1; +drop table t1; # End of 4.1 tests diff --git a/mysql-test/t/innodb.test b/mysql-test/t/innodb.test index e4c8bf89cca..71b178d0e57 100644 --- a/mysql-test/t/innodb.test +++ b/mysql-test/t/innodb.test @@ -2196,3 +2196,16 @@ drop table t2, t1; # --error ER_TABLE_CANT_HANDLE_SPKEYS create table t1 (g geometry not null, spatial gk(g)) engine=innodb; + +####################################################################### +# # +# Please, DO NOT TOUCH this file as well as the innodb.result file. # +# These files are to be modified ONLY BY INNOBASE guys. # +# # +# Use innodb_mysql.[test|result] files instead. # +# # +# If nevertheless you need to make some changes here, please, forward # +# your commit message To: dev@innodb.com Cc: dev-innodb@mysql.com # +# (otherwise your changes may be erased). # +# # +####################################################################### diff --git a/mysql-test/t/insert_select.test b/mysql-test/t/insert_select.test index 5dd6f338865..0b9a0e86ba9 100644 --- a/mysql-test/t/insert_select.test +++ b/mysql-test/t/insert_select.test @@ -224,4 +224,17 @@ insert into t1(x,y) select x,z from t2 on duplicate key update x=values(z); insert into t1(x,y) select x,z from t2 on duplicate key update x=values(t2.x); drop table t1,t2; +# +# Bug #9676: INSERT INTO x SELECT .. FROM x LIMIT 1; slows down with big +# tables +# + +#Note: not an exsaustive test : just a check of the code path. +CREATE TABLE t1 (a int PRIMARY KEY); +INSERT INTO t1 values (1), (2); + +INSERT INTO t1 SELECT a + 2 FROM t1 LIMIT 1; + +DROP TABLE t1; + # End of 4.1 tests diff --git a/mysql-test/t/lock_multi.test b/mysql-test/t/lock_multi.test index ee03088b8c3..905d0699e6a 100644 --- a/mysql-test/t/lock_multi.test +++ b/mysql-test/t/lock_multi.test @@ -171,4 +171,30 @@ use test; # connection default; +# +# Bug #17264: MySQL Server freeze +# +connection locker; +create table t1 (f1 int(12) unsigned not null auto_increment, primary key(f1)) engine=innodb; +lock tables t1 write; +connection writer; +--sleep 2 +delimiter //; +send alter table t1 auto_increment=0; alter table t1 auto_increment=0; alter table t1 auto_increment=0; alter table t1 auto_increment=0; alter table t1 auto_increment=0; // +delimiter ;// +connection reader; +--sleep 2 +delimiter //; +send alter table t1 auto_increment=0; alter table t1 auto_increment=0; alter table t1 auto_increment=0; alter table t1 auto_increment=0; alter table t1 auto_increment=0; // +delimiter ;// +connection locker; +--sleep 2 +unlock tables; +connection writer; +reap; +connection reader; +reap; +connection locker; +drop table t1; + # End of 5.0 tests diff --git a/mysql-test/t/myisam.test b/mysql-test/t/myisam.test index a30548f46ff..56e799f00b6 100644 --- a/mysql-test/t/myisam.test +++ b/mysql-test/t/myisam.test @@ -698,6 +698,18 @@ select count(id1) from t1 where id2 = 10; drop table t1; # +# BUG##20357 - Got error 124 from storage engine using MIN and MAX functions +# in queries +# +CREATE TABLE t1(a TINYINT, KEY(a)) ENGINE=MyISAM; +INSERT INTO t1 VALUES(1); +SELECT MAX(a) FROM t1 IGNORE INDEX(a); +ALTER TABLE t1 DISABLE KEYS; +SELECT MAX(a) FROM t1; +SELECT MAX(a) FROM t1 IGNORE INDEX(a); +DROP TABLE t1; + +# # BUG#18036 - update of table joined to self reports table as crashed # CREATE TABLE t1(a CHAR(9), b VARCHAR(7)) ENGINE=MyISAM; diff --git a/mysql-test/t/mysqldump.test b/mysql-test/t/mysqldump.test index d53022665a0..ab865594d42 100644 --- a/mysql-test/t/mysqldump.test +++ b/mysql-test/t/mysqldump.test @@ -1161,3 +1161,20 @@ show create procedure p; drop function f; drop procedure p; +# +# BUG#17201 Spurious 'DROP DATABASE' in output, +# also confusion between tables and views. +# Example code from Markus Popp + +create database mysqldump_test_db; +use mysqldump_test_db; +create table t1 (id int); +create view v1 as select * from t1; +insert into t1 values (1232131); +insert into t1 values (4711); +insert into t1 values (3231); +insert into t1 values (0815); +--exec $MYSQL_DUMP --skip-comments --add-drop-database --databases mysqldump_test_db +drop view v1; +drop table t1; +drop database mysqldump_test_db; diff --git a/mysql-test/t/ndb_replace.test b/mysql-test/t/ndb_replace.test index 6cad80ef8ea..94a11f7dfb2 100644 --- a/mysql-test/t/ndb_replace.test +++ b/mysql-test/t/ndb_replace.test @@ -6,7 +6,7 @@ # --disable_warnings -drop table if exists t1; +drop table if exists t1,t2; --enable_warnings CREATE TABLE t1 ( @@ -27,6 +27,8 @@ replace into t1 (gesuchnr,benutzer_id) values (1,1); select * from t1 order by gesuchnr; drop table t1; +# End of 4.1 tests + # bug#17431 CREATE TABLE t1(i INT PRIMARY KEY AUTO_INCREMENT, j INT, @@ -38,4 +40,28 @@ REPLACE INTO t1 (j,k) VALUES (1,42); REPLACE INTO t1 (i,j) VALUES (17,2); SELECT * from t1 ORDER BY i; -# End of 4.1 tests +# bug#19906 +CREATE TABLE t2 (a INT(11) NOT NULL, + b INT(11) NOT NULL, + c INT(11) NOT NULL, + x TEXT, + y TEXT, + z TEXT, + id INT(10) unsigned NOT NULL AUTO_INCREMENT, + i INT(11) DEFAULT NULL, + PRIMARY KEY (id), + UNIQUE KEY a (a,b,c) +) ENGINE=ndbcluster; + +REPLACE INTO t2 (a,b,c,x,y,z,i) VALUES (1,1,1,'a','a','a',1),(1,1,1,'b','b','b',2), (1,1,1,'c','c','c',3); + +SELECT * FROM t2 ORDER BY id; + +REPLACE INTO t2(a,b,c,x,y,z,i) values (1,1,1,'a','a','a',1); +REPLACE INTO t2(a,b,c,x,y,z,i) values (1,1,1,'b','b','b',2); + +SELECT * FROM t2 ORDER BY id; + +DROP TABLE t2; + + diff --git a/mysql-test/t/rpl_auto_increment_11932.test b/mysql-test/t/rpl_auto_increment_11932.test new file mode 100644 index 00000000000..d4b7872fb2b --- /dev/null +++ b/mysql-test/t/rpl_auto_increment_11932.test @@ -0,0 +1,63 @@ +# +# Test of auto_increment +# BUG#11932 +# +# Bug reported that master and slave get out of sync after TRUNCATE +# TABLE. +# +# Test supplied by Are Casilla + +source include/master-slave.inc; +--disable_warnings +connection master; +drop database if exists test1; +--enable_warnings +create database test1; +use test1; + +CREATE TABLE `t1` ( + `id` int(10) unsigned NOT NULL auto_increment, + `fname` varchar(100) default NULL, + PRIMARY KEY (`id`) +) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=2 ; + +INSERT INTO `t1` VALUES (1, 'blablabla'); + +CREATE TABLE `t2` ( + `id` int(10) NOT NULL auto_increment, + `comment` varchar(255) NOT NULL default '', + PRIMARY KEY (`id`) +) ENGINE=MyISAM AUTO_INCREMENT=3 ; + +INSERT INTO `t2` VALUES (1, 'testtest 1'); +INSERT INTO `t2` VALUES (2, 'test 2'); + +DELIMITER $; +CREATE PROCEDURE simpleproc3 () + NOT DETERMINISTIC + BEGIN + INSERT INTO t1 (fname) (SELECT t2.comment FROM t2 WHERE t2.id = '1'); + INSERT INTO t1 (fname) VALUES('test'); + END + $ +DELIMITER ;$ + +CALL simpleproc3(); + +select * from t2; + +TRUNCATE TABLE `t1`; +CALL simpleproc3(); + +select * from t1; + +save_master_pos; +connection slave; +sync_with_master; + +use test1; +select * from t1; + +drop database test1; +connection master; +drop database test1; diff --git a/mysql-test/t/select.test b/mysql-test/t/select.test index ae3981ce47b..b75d0dd8bb6 100644 --- a/mysql-test/t/select.test +++ b/mysql-test/t/select.test @@ -2285,6 +2285,25 @@ EXPLAIN SELECT * FROM t1 FORCE INDEX (a); DROP TABLE t1; +# +# Bug #18759 "Incorrect string to numeric conversion" +# +# This test is here so that the behavior will not be changed to 4.1 +# and not to 5.0 either. In 4.1 and 5.0 sending an integer as a string +# will be converted internally to real (double) value and it is not +# as accurate as bigint (longlong) for integers. Thus the results may +# vary. In 5.1 internally it is decimal, which is a string type and +# will be more accurate. Due to rather big changes needed to fix this +# in 4.1 or 5.0 it is not desired to do it in the stable versions. +# +# This test is here only to make sure that behavior is not changed in +# 4.1 and 5.0 +# +CREATE TABLE t1 (i BIGINT UNSIGNED NOT NULL); +INSERT INTO t1 VALUES (10); +SELECT i='1e+01',i=1e+01, i in (1e+01,1e+01), i in ('1e+01','1e+01') FROM t1; +DROP TABLE t1; + # End of 4.1 tests # diff --git a/mysql-test/t/sql_mode.test b/mysql-test/t/sql_mode.test index b67f1a73db6..2699cb66471 100644 --- a/mysql-test/t/sql_mode.test +++ b/mysql-test/t/sql_mode.test @@ -258,6 +258,9 @@ drop table t1, t2; select @@sql_mode; set sql_mode=2097152; select @@sql_mode; +# BUG#14675 +set sql_mode=4194304; +select @@sql_mode; set sql_mode=16384+(65536*4); select @@sql_mode; --error 1231 diff --git a/mysql-test/valgrind.supp b/mysql-test/valgrind.supp index 65c5a82db36..24426727968 100644 --- a/mysql-test/valgrind.supp +++ b/mysql-test/valgrind.supp @@ -134,6 +134,18 @@ } # +# Warning from my_thread_init becasue mysqld dies before kill thread exists +# + +{ + my_thread_init kill thread memory loss second + Memcheck:Leak + fun:calloc + fun:my_thread_init + fun:kill_server_thread +} + +# # Leaks reported in _dl_* internal functions on Linux amd64 / glibc2.3.2. # diff --git a/ndb/include/util/ConfigValues.hpp b/ndb/include/util/ConfigValues.hpp index 457488e3c42..8dfb3c83df3 100644 --- a/ndb/include/util/ConfigValues.hpp +++ b/ndb/include/util/ConfigValues.hpp @@ -96,6 +96,7 @@ public: public: ConfigValuesFactory(Uint32 keys = 50, Uint32 data = 10); // Initial ConfigValuesFactory(ConfigValues * m_cfg); // + ~ConfigValuesFactory(); ConfigValues * m_cfg; ConfigValues * getConfigValues(); diff --git a/ndb/src/common/transporter/TransporterRegistry.cpp b/ndb/src/common/transporter/TransporterRegistry.cpp index f0e50729f8d..cd78bc52027 100644 --- a/ndb/src/common/transporter/TransporterRegistry.cpp +++ b/ndb/src/common/transporter/TransporterRegistry.cpp @@ -1322,7 +1322,7 @@ TransporterRegistry::start_clients_thread() else { ndbout_c("Management server closed connection early. " - "It is probably being shut down (or has crashed). " + "It is probably being shut down (or has problems). " "We will retry the connection."); } } diff --git a/ndb/src/common/util/ConfigValues.cpp b/ndb/src/common/util/ConfigValues.cpp index 5c4b17c73ca..ae4fbfd2f71 100644 --- a/ndb/src/common/util/ConfigValues.cpp +++ b/ndb/src/common/util/ConfigValues.cpp @@ -294,6 +294,12 @@ ConfigValuesFactory::ConfigValuesFactory(ConfigValues * cfg){ } } +ConfigValuesFactory::~ConfigValuesFactory() +{ + if(m_cfg) + free(m_cfg); +} + ConfigValues * ConfigValuesFactory::create(Uint32 keys, Uint32 data){ Uint32 sz = sizeof(ConfigValues); @@ -528,7 +534,7 @@ ConfigValuesFactory::extractCurrentSection(const ConfigValues::ConstIterator & c } } - ConfigValues * ret = fac->m_cfg; + ConfigValues * ret = fac->getConfigValues(); delete fac; return ret; } diff --git a/ndb/src/kernel/blocks/dbdih/DbdihMain.cpp b/ndb/src/kernel/blocks/dbdih/DbdihMain.cpp index 3ebad7f0cd2..dcb5d201d7f 100644 --- a/ndb/src/kernel/blocks/dbdih/DbdihMain.cpp +++ b/ndb/src/kernel/blocks/dbdih/DbdihMain.cpp @@ -8354,7 +8354,7 @@ Dbdih::resetReplicaSr(TabRecordPtr tabPtr){ *--------_----------------------------------------------------- */ const Uint32 nextCrashed = noCrashedReplicas + 1; replicaPtr.p->noCrashedReplicas = nextCrashed; - arrGuard(nextCrashed, 8); + arrGuardErr(nextCrashed, 8, NDBD_EXIT_MAX_CRASHED_REPLICAS); replicaPtr.p->createGci[nextCrashed] = newestRestorableGCI + 1; ndbrequire(newestRestorableGCI + 1 != 0xF1F1F1F1); replicaPtr.p->replicaLastGci[nextCrashed] = (Uint32)-1; diff --git a/ndb/src/kernel/blocks/dblqh/DblqhMain.cpp b/ndb/src/kernel/blocks/dblqh/DblqhMain.cpp index 19a003f00fc..56e93e6ee01 100644 --- a/ndb/src/kernel/blocks/dblqh/DblqhMain.cpp +++ b/ndb/src/kernel/blocks/dblqh/DblqhMain.cpp @@ -17989,7 +17989,8 @@ void Dblqh::stepAhead(Signal* signal, Uint32 stepAheadWords) logFilePtr.p->currentLogpage = logPagePtr.p->logPageWord[ZNEXT_PAGE]; logPagePtr.i = logPagePtr.p->logPageWord[ZNEXT_PAGE]; logFilePtr.p->currentFilepage++; - ptrCheckGuard(logPagePtr, clogPageFileSize, logPageRecord); + ptrCheckGuardErr(logPagePtr, clogPageFileSize, logPageRecord, + NDBD_EXIT_SR_REDOLOG); logPagePtr.p->logPageWord[ZCURR_PAGE_INDEX] = ZPAGE_HEADER_SIZE; logPartPtr.p->execSrPagesRead--; logPartPtr.p->execSrPagesExecuted++; diff --git a/ndb/src/kernel/error/ndbd_exit_codes.c b/ndb/src/kernel/error/ndbd_exit_codes.c index 6a14d8b7ffd..257af4c5b1b 100644 --- a/ndb/src/kernel/error/ndbd_exit_codes.c +++ b/ndb/src/kernel/error/ndbd_exit_codes.c @@ -51,8 +51,9 @@ static const ErrStruct errArray[] = {NDBD_EXIT_SYSTEM_ERROR, XIE, "System error, node killed during node restart by other node"}, {NDBD_EXIT_INDEX_NOTINRANGE, XIE, "Array index out of range"}, - {NDBD_EXIT_ARBIT_SHUTDOWN, XAE, "Arbitrator shutdown, " - "please investigate error(s) on other node(s)"}, + {NDBD_EXIT_ARBIT_SHUTDOWN, XAE, "Node lost connection to other nodes and " + "can not form a unpartitioned cluster, please investigate if there are " + "error(s) on other node(s)"}, {NDBD_EXIT_POINTER_NOTINRANGE, XIE, "Pointer too large"}, {NDBD_EXIT_SR_OTHERNODEFAILED, XRE, "Another node failed during system " "restart, please investigate error(s) on other node(s)"}, @@ -94,7 +95,7 @@ static const ErrStruct errArray[] = {NDBD_EXIT_WATCHDOG_TERMINATE, XIE, "WatchDog terminate, internal error " "or massive overload on the machine running this node"}, {NDBD_EXIT_SIGNAL_LOST_SEND_BUFFER_FULL, XCR, - "Signal lost, out of send buffer memory, please increase SendBufferMemory"}, + "Signal lost, out of send buffer memory, please increase SendBufferMemory or lower the load"}, {NDBD_EXIT_SIGNAL_LOST, XIE, "Signal lost (unknown reason)"}, {NDBD_EXIT_ILLEGAL_SIGNAL, XIE, "Illegal signal (version mismatch a possibility)"}, diff --git a/ndb/src/mgmapi/mgmapi.cpp b/ndb/src/mgmapi/mgmapi.cpp index 7ad20e504f6..4428b158b6b 100644 --- a/ndb/src/mgmapi/mgmapi.cpp +++ b/ndb/src/mgmapi/mgmapi.cpp @@ -1945,7 +1945,7 @@ ndb_mgm_get_configuration(NdbMgmHandle handle, unsigned int version) { } delete prop; - return (ndb_mgm_configuration*)cvf.m_cfg; + return (ndb_mgm_configuration*)cvf.getConfigValues(); } while(0); delete prop; diff --git a/ndb/src/mgmsrv/ConfigInfo.cpp b/ndb/src/mgmsrv/ConfigInfo.cpp index e9093d59494..dfe4f9aa63e 100644 --- a/ndb/src/mgmsrv/ConfigInfo.cpp +++ b/ndb/src/mgmsrv/ConfigInfo.cpp @@ -2241,11 +2241,11 @@ ConfigInfo::ConfigInfo() if (!m_info.getCopy(param._section, §ion)) { Properties newsection(true); m_info.put(param._section, &newsection); + + // Get copy of section + m_info.getCopy(param._section, §ion); } - - // Get copy of section - m_info.getCopy(param._section, §ion); - + // Create pinfo (parameter info) entry Properties pinfo(true); pinfo.put("Id", param._paramId); @@ -2299,6 +2299,7 @@ ConfigInfo::ConfigInfo() // Replace section with modified section m_info.put(param._section, section, true); + delete section; if(param._type != ConfigInfo::CI_SECTION){ Properties * p; diff --git a/ndb/src/mgmsrv/MgmtSrvr.cpp b/ndb/src/mgmsrv/MgmtSrvr.cpp index 2505515c086..b9466ed1173 100644 --- a/ndb/src/mgmsrv/MgmtSrvr.cpp +++ b/ndb/src/mgmsrv/MgmtSrvr.cpp @@ -1863,7 +1863,7 @@ MgmtSrvr::handleReceivedSignal(NdbApiSignal* signal) break; case GSN_EVENT_REP: { - EventReport *rep = CAST_PTR(EventReport, signal->getDataPtrSend()); + EventReport *rep = (EventReport*) signal->getDataPtr(); if (rep->getNodeId() == 0) rep->setNodeId(refToNode(signal->theSendersBlockRef)); eventReport(signal->getDataPtr()); diff --git a/ndb/src/ndbapi/ndberror.c b/ndb/src/ndbapi/ndberror.c index 62d920755bd..91d58f515aa 100644 --- a/ndb/src/ndbapi/ndberror.c +++ b/ndb/src/ndbapi/ndberror.c @@ -266,6 +266,7 @@ ErrorBundle ErrorCodes[] = { /** * Application error */ + { 763, AE, "Alter table requires cluster nodes to have exact same version" }, { 823, AE, "Too much attrinfo from application in tuple manager" }, { 831, AE, "Too many nullable/bitfields in table definition" }, { 876, AE, "876" }, diff --git a/regex/regexec.c b/regex/regexec.c index b7ad83ba883..88bcc02323d 100644 --- a/regex/regexec.c +++ b/regex/regexec.c @@ -19,7 +19,7 @@ static int nope = 0; /* for use in asserts; shuts lint up */ /* macros for manipulating states, small version */ #define states long -#define states1 states /* for later use in regexec() decision */ +#define states1 long /* for later use in regexec() decision. Ensure Win64 definition is correct.*/ #define CLEAR(v) ((v) = 0) #define SET0(v, n) ((v) &= ~((states) 1 << (n))) #define SET1(v, n) ((v) |= (states) 1 << (n)) diff --git a/sql/field.cc b/sql/field.cc index 33fc5ab3128..7c25e4ad9f7 100644 --- a/sql/field.cc +++ b/sql/field.cc @@ -4566,7 +4566,7 @@ int Field_timestamp::store(const char *from,uint len,CHARSET_INFO *cs) } #ifdef WORDS_BIGENDIAN - if (table->s->db_low_byte_first) + if (table && table->s->db_low_byte_first) { int4store(ptr,tmp); } @@ -4632,7 +4632,7 @@ int Field_timestamp::store(longlong nr, bool unsigned_val) nr, MYSQL_TIMESTAMP_DATETIME, 1); #ifdef WORDS_BIGENDIAN - if (table->s->db_low_byte_first) + if (table && table->s->db_low_byte_first) { int4store(ptr,timestamp); } @@ -4656,7 +4656,7 @@ longlong Field_timestamp::val_int(void) THD *thd= table ? table->in_use : current_thd; #ifdef WORDS_BIGENDIAN - if (table->s->db_low_byte_first) + if (table && table->s->db_low_byte_first) temp=uint4korr(ptr); else #endif @@ -4686,7 +4686,7 @@ String *Field_timestamp::val_str(String *val_buffer, String *val_ptr) val_buffer->length(field_length); #ifdef WORDS_BIGENDIAN - if (table->s->db_low_byte_first) + if (table && table->s->db_low_byte_first) temp=uint4korr(ptr); else #endif @@ -4751,7 +4751,7 @@ bool Field_timestamp::get_date(TIME *ltime, uint fuzzydate) long temp; THD *thd= table ? table->in_use : current_thd; #ifdef WORDS_BIGENDIAN - if (table->s->db_low_byte_first) + if (table && table->s->db_low_byte_first) temp=uint4korr(ptr); else #endif @@ -4788,7 +4788,7 @@ int Field_timestamp::cmp(const char *a_ptr, const char *b_ptr) { int32 a,b; #ifdef WORDS_BIGENDIAN - if (table->s->db_low_byte_first) + if (table && table->s->db_low_byte_first) { a=sint4korr(a_ptr); b=sint4korr(b_ptr); @@ -4806,7 +4806,7 @@ int Field_timestamp::cmp(const char *a_ptr, const char *b_ptr) void Field_timestamp::sort_string(char *to,uint length __attribute__((unused))) { #ifdef WORDS_BIGENDIAN - if (!table->s->db_low_byte_first) + if (!table || !table->s->db_low_byte_first) { to[0] = ptr[0]; to[1] = ptr[1]; @@ -4836,7 +4836,7 @@ void Field_timestamp::set_time() long tmp= (long) thd->query_start(); set_notnull(); #ifdef WORDS_BIGENDIAN - if (table->s->db_low_byte_first) + if (table && table->s->db_low_byte_first) { int4store(ptr,tmp); } @@ -5238,7 +5238,7 @@ int Field_date::store(const char *from, uint len,CHARSET_INFO *cs) from, len, MYSQL_TIMESTAMP_DATE, 1); #ifdef WORDS_BIGENDIAN - if (table->s->db_low_byte_first) + if (table && table->s->db_low_byte_first) { int4store(ptr,tmp); } @@ -5299,7 +5299,7 @@ int Field_date::store(longlong nr, bool unsigned_val) MYSQL_TIMESTAMP_DATETIME, 1); #ifdef WORDS_BIGENDIAN - if (table->s->db_low_byte_first) + if (table && table->s->db_low_byte_first) { int4store(ptr, nr); } @@ -5325,7 +5325,7 @@ double Field_date::val_real(void) { int32 j; #ifdef WORDS_BIGENDIAN - if (table->s->db_low_byte_first) + if (table && table->s->db_low_byte_first) j=sint4korr(ptr); else #endif @@ -5338,7 +5338,7 @@ longlong Field_date::val_int(void) { int32 j; #ifdef WORDS_BIGENDIAN - if (table->s->db_low_byte_first) + if (table && table->s->db_low_byte_first) j=sint4korr(ptr); else #endif @@ -5354,7 +5354,7 @@ String *Field_date::val_str(String *val_buffer, val_buffer->alloc(field_length); int32 tmp; #ifdef WORDS_BIGENDIAN - if (table->s->db_low_byte_first) + if (table && table->s->db_low_byte_first) tmp=sint4korr(ptr); else #endif @@ -5372,7 +5372,7 @@ int Field_date::cmp(const char *a_ptr, const char *b_ptr) { int32 a,b; #ifdef WORDS_BIGENDIAN - if (table->s->db_low_byte_first) + if (table && table->s->db_low_byte_first) { a=sint4korr(a_ptr); b=sint4korr(b_ptr); @@ -5390,7 +5390,7 @@ int Field_date::cmp(const char *a_ptr, const char *b_ptr) void Field_date::sort_string(char *to,uint length __attribute__((unused))) { #ifdef WORDS_BIGENDIAN - if (!table->s->db_low_byte_first) + if (!table || !table->s->db_low_byte_first) { to[0] = ptr[0]; to[1] = ptr[1]; @@ -5630,7 +5630,7 @@ int Field_datetime::store(const char *from,uint len,CHARSET_INFO *cs) from, len, MYSQL_TIMESTAMP_DATETIME, 1); #ifdef WORDS_BIGENDIAN - if (table->s->db_low_byte_first) + if (table && table->s->db_low_byte_first) { int8store(ptr,tmp); } @@ -5683,7 +5683,7 @@ int Field_datetime::store(longlong nr, bool unsigned_val) MYSQL_TIMESTAMP_DATETIME, 1); #ifdef WORDS_BIGENDIAN - if (table->s->db_low_byte_first) + if (table && table->s->db_low_byte_first) { int8store(ptr,nr); } @@ -5712,7 +5712,7 @@ int Field_datetime::store_time(TIME *ltime,timestamp_type type) set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, WARN_DATA_TRUNCATED, 1); } #ifdef WORDS_BIGENDIAN - if (table->s->db_low_byte_first) + if (table && table->s->db_low_byte_first) { int8store(ptr,tmp); } @@ -5739,7 +5739,7 @@ longlong Field_datetime::val_int(void) { longlong j; #ifdef WORDS_BIGENDIAN - if (table->s->db_low_byte_first) + if (table && table->s->db_low_byte_first) j=sint8korr(ptr); else #endif @@ -5759,7 +5759,7 @@ String *Field_datetime::val_str(String *val_buffer, int part3; #ifdef WORDS_BIGENDIAN - if (table->s->db_low_byte_first) + if (table && table->s->db_low_byte_first) tmp=sint8korr(ptr); else #endif @@ -5824,7 +5824,7 @@ int Field_datetime::cmp(const char *a_ptr, const char *b_ptr) { longlong a,b; #ifdef WORDS_BIGENDIAN - if (table->s->db_low_byte_first) + if (table && table->s->db_low_byte_first) { a=sint8korr(a_ptr); b=sint8korr(b_ptr); @@ -5842,7 +5842,7 @@ int Field_datetime::cmp(const char *a_ptr, const char *b_ptr) void Field_datetime::sort_string(char *to,uint length __attribute__((unused))) { #ifdef WORDS_BIGENDIAN - if (!table->s->db_low_byte_first) + if (!table || !table->s->db_low_byte_first) { to[0] = ptr[0]; to[1] = ptr[1]; diff --git a/sql/field.h b/sql/field.h index e7b7aa45c27..ed13372df71 100644 --- a/sql/field.h +++ b/sql/field.h @@ -813,7 +813,7 @@ public: if ((*null_value= is_null())) return 0; #ifdef WORDS_BIGENDIAN - if (table->s->db_low_byte_first) + if (table && table->s->db_low_byte_first) return sint4korr(ptr); #endif long tmp; diff --git a/sql/ha_innodb.cc b/sql/ha_innodb.cc index 28cdfd23b6a..6aadce0191a 100644 --- a/sql/ha_innodb.cc +++ b/sql/ha_innodb.cc @@ -6684,6 +6684,17 @@ ha_innobase::store_lock( && !thd->tablespace_op && thd->lex->sql_command != SQLCOM_TRUNCATE && thd->lex->sql_command != SQLCOM_OPTIMIZE +#ifdef __WIN__ + /* + for alter table on win32 for succesfull operation + completion it is used TL_WRITE(=10) lock instead of + TL_WRITE_ALLOW_READ(=6), however here in innodb handler + TL_WRITE is lifted to TL_WRITE_ALLOW_WRITE, which causes + race condition when several clients do alter table + simultaneously (bug #17264). This fix avoids the problem. + */ + && thd->lex->sql_command != SQLCOM_ALTER_TABLE +#endif && thd->lex->sql_command != SQLCOM_CREATE_TABLE) { lock_type = TL_WRITE_ALLOW_WRITE; diff --git a/sql/ha_ndbcluster.cc b/sql/ha_ndbcluster.cc index 98dd9d5a122..46ab5b88624 100644 --- a/sql/ha_ndbcluster.cc +++ b/sql/ha_ndbcluster.cc @@ -771,10 +771,11 @@ int g_get_ndb_blobs_value(NdbBlob *ndb_blob, void *arg) if (ndb_blob->blobsNextBlob() != NULL) DBUG_RETURN(0); ha_ndbcluster *ha= (ha_ndbcluster *)arg; - DBUG_RETURN(ha->get_ndb_blobs_value(ndb_blob)); + DBUG_RETURN(ha->get_ndb_blobs_value(ndb_blob, ha->m_blobs_offset)); } -int ha_ndbcluster::get_ndb_blobs_value(NdbBlob *last_ndb_blob) +int ha_ndbcluster::get_ndb_blobs_value(NdbBlob *last_ndb_blob, + my_ptrdiff_t ptrdiff) { DBUG_ENTER("get_ndb_blobs_value"); @@ -807,7 +808,10 @@ int ha_ndbcluster::get_ndb_blobs_value(NdbBlob *last_ndb_blob) if (ndb_blob->readData(buf, len) != 0) DBUG_RETURN(-1); DBUG_ASSERT(len == blob_len); + // Ugly hack assumes only ptr needs to be changed + field_blob->ptr+= ptrdiff; field_blob->set_ptr(len, buf); + field_blob->ptr-= ptrdiff; } offset+= blob_size; } @@ -870,6 +874,7 @@ int ha_ndbcluster::get_ndb_value(NdbOperation *ndb_op, Field *field, if (ndb_blob != NULL) { // Set callback + m_blobs_offset= buf - (byte*) table->record[0]; void *arg= (void *)this; DBUG_RETURN(ndb_blob->setActiveHook(g_get_ndb_blobs_value, arg) != 0); } @@ -4584,6 +4589,7 @@ ha_ndbcluster::ha_ndbcluster(TABLE *table_arg): m_ops_pending(0), m_skip_auto_increment(TRUE), m_blobs_pending(0), + m_blobs_offset(0), m_blobs_buffer(0), m_blobs_buffer_size(0), m_dupkey((uint) -1), diff --git a/sql/ha_ndbcluster.h b/sql/ha_ndbcluster.h index e417996a5d9..01950c2b00f 100644 --- a/sql/ha_ndbcluster.h +++ b/sql/ha_ndbcluster.h @@ -629,7 +629,7 @@ private: int set_ndb_value(NdbOperation*, Field *field, uint fieldnr, bool *set_blob_value= 0); int get_ndb_value(NdbOperation*, Field *field, uint fieldnr, byte*); friend int g_get_ndb_blobs_value(NdbBlob *ndb_blob, void *arg); - int get_ndb_blobs_value(NdbBlob *last_ndb_blob); + int get_ndb_blobs_value(NdbBlob *last_ndb_blob, my_ptrdiff_t ptrdiff); int set_primary_key(NdbOperation *op, const byte *key); int set_primary_key_from_record(NdbOperation *op, const byte *record); int set_index_key_from_record(NdbOperation *op, const byte *record, @@ -706,6 +706,7 @@ private: ha_rows m_ops_pending; bool m_skip_auto_increment; bool m_blobs_pending; + my_ptrdiff_t m_blobs_offset; // memory for blobs in one tuple char *m_blobs_buffer; uint32 m_blobs_buffer_size; diff --git a/sql/item_cmpfunc.cc b/sql/item_cmpfunc.cc index 15a05fe7050..80cf756d852 100644 --- a/sql/item_cmpfunc.cc +++ b/sql/item_cmpfunc.cc @@ -80,9 +80,6 @@ static void agg_result_type(Item_result *type, Item **items, uint nitems) NOTES Aggregation rules: - If all items are constants the type will be aggregated from all items. - If there are some non-constant items then only types of non-constant - items will be used for aggregation. If there are DATE/TIME fields/functions in the list and no string fields/functions in the list then: The INT_RESULT type will be used for aggregation instead of original @@ -141,7 +138,8 @@ static void agg_cmp_type(THD *thd, Item_result *type, Item **items, uint nitems) } continue; } - if ((res= items[i]->real_item()->type()) == Item::FIELD_ITEM) + if ((res= items[i]->real_item()->type()) == Item::FIELD_ITEM && + items[i]->result_type() != INT_RESULT) { field= ((Item_field *)items[i]->real_item())->field; break; @@ -169,34 +167,29 @@ static void agg_cmp_type(THD *thd, Item_result *type, Item **items, uint nitems) } } } - /* Reset to 0 on first occurence of non-const item. 1 otherwise */ - bool is_const= items[0]->const_item(); /* If the first item is a date/time function then its result should be compared as int */ if (field) - { - /* Suppose we are comparing dates and some non-constant items are present. */ + /* Suppose we are comparing dates */ type[0]= INT_RESULT; - is_const= 0; - } else type[0]= items[0]->result_type(); for (i= 0; i < nitems ; i++) { - if (!items[i]->const_item()) - { - Item_result result= field && items[i]->result_as_longlong() ? - INT_RESULT : items[i]->result_type(); - type[0]= is_const ? result : item_cmp_type(type[0], result); - is_const= 0; - } - else if (is_const) - type[0]= item_cmp_type(type[0], items[i]->result_type()); - else if (field) - convert_constant_item(thd, field, &items[i]); + Item_result result= items[i]->result_type(); + /* + Use INT_RESULT as result type for DATE/TIME fields/functions and + for constants successfully converted to DATE/TIME + */ + if (field && + ((!items[i]->const_item() && items[i]->result_as_longlong()) || + (items[i]->const_item() && convert_constant_item(thd, field, + &items[i])))) + result= INT_RESULT; + type[0]= item_cmp_type(type[0], result); } if (res == Item::FUNC_ITEM && field) diff --git a/sql/opt_sum.cc b/sql/opt_sum.cc index 22d84d7fb5a..1f6190241a3 100644 --- a/sql/opt_sum.cc +++ b/sql/opt_sum.cc @@ -701,6 +701,12 @@ static bool find_key_for_maxmin(bool max_fl, TABLE_REF *ref, { KEY_PART_INFO *part,*part_end; key_part_map key_part_to_use= 0; + /* + Perform a check if index is not disabled by ALTER TABLE + or IGNORE INDEX. + */ + if (!table->keys_in_use_for_query.is_set(idx)) + continue; uint jdx= 0; *prefix_len= 0; for (part= keyinfo->key_part, part_end= part+keyinfo->key_parts ; diff --git a/sql/sql_select.cc b/sql/sql_select.cc index 96b196e34b0..9f317842d98 100644 --- a/sql/sql_select.cc +++ b/sql/sql_select.cc @@ -1068,8 +1068,9 @@ JOIN::optimize() group_list ? 0 : select_distinct, group_list && simple_group, select_options, - (order == 0 || skip_sort_order) ? select_limit : - HA_POS_ERROR, + (order == 0 || skip_sort_order || + test(select_options & OPTION_BUFFER_RESULT)) ? + select_limit : HA_POS_ERROR, (char *) ""))) DBUG_RETURN(1); @@ -8814,6 +8815,11 @@ create_tmp_table(THD *thd,TMP_TABLE_PARAM *param,List<Item> &fields, keyinfo->key_length+= key_part_info->length; } } + else + { + set_if_smaller(table->s->max_rows, rows_limit); + param->end_write_records= rows_limit; + } if (distinct && field_count != param->hidden_field_count) { diff --git a/support-files/mysql.server.sh b/support-files/mysql.server.sh index 27a1b85a354..d5041f30c0a 100644 --- a/support-files/mysql.server.sh +++ b/support-files/mysql.server.sh @@ -98,6 +98,11 @@ PATH=/sbin:/usr/sbin:/bin:/usr/bin:$basedir/bin export PATH mode=$1 # start or stop +shift +other_args="$*" # uncommon, but needed when called from an RPM upgrade action + # Expected: "--skip-networking --skip-grant-tables" + # They are not checked here, intentionally, as it is the resposibility + # of the "spec" file author to give correct arguments only. case `echo "testing\c"`,`echo -n testing` in *c*,-n*) echo_n= echo_c= ;; @@ -264,6 +269,11 @@ case "$mode" in echo $echo_n "Starting MySQL" if test -x $manager -a "$use_mysqld_safe" = "0" then + if test -n "$other_args" + then + log_failure_msg "MySQL manager does not support options '$other_args'" + exit 1 + fi # Give extra arguments to mysqld with the my.cnf file. This script may # be overwritten at next upgrade. $manager --user=$user --pid-file=$pid_file >/dev/null 2>&1 & @@ -279,7 +289,7 @@ case "$mode" in # Give extra arguments to mysqld with the my.cnf file. This script # may be overwritten at next upgrade. pid_file=$server_pid_file - $bindir/mysqld_safe --datadir=$datadir --pid-file=$server_pid_file >/dev/null 2>&1 & + $bindir/mysqld_safe --datadir=$datadir --pid-file=$server_pid_file $other_args >/dev/null 2>&1 & wait_for_pid created # Make lock for RedHat / SuSE @@ -327,8 +337,8 @@ case "$mode" in 'restart') # Stop the service and regardless of whether it was # running or not, start it again. - $0 stop - $0 start + $0 stop $other_args + $0 start $other_args ;; 'reload') @@ -343,7 +353,7 @@ case "$mode" in *) # usage - echo "Usage: $0 start|stop|restart|reload" + echo "Usage: $0 {start|stop|restart|reload} [ MySQL server options ]" exit 1 ;; esac diff --git a/support-files/mysql.spec.sh b/support-files/mysql.spec.sh index 202910f44e4..abd29b6014a 100644 --- a/support-files/mysql.spec.sh +++ b/support-files/mysql.spec.sh @@ -485,7 +485,16 @@ chown -R %{mysqld_user}:%{mysqld_group} $mysql_datadir %{_bindir}/mysql_install_db --rpm --user=%{mysqld_user} # Upgrade databases if needed -%{_bindir}/mysql_upgrade --user=%{mysqld_user} +# This must be done as database user "root", who should be password-protected, +# but this password is not available here. +# So ensure the server is isolated as much as possible, and start it so that +# passwords are not checked. +# See the related change in the start script "/etc/init.d/mysql". +chmod 700 $mysql_datadir +%{_sysconfdir}/init.d/mysql start --skip-networking --skip-grant-tables +%{_bindir}/mysql_upgrade +%{_sysconfdir}/init.d/mysql stop --skip-networking --skip-grant-tables +chmod 755 $mysql_datadir # Change permissions again to fix any new files. chown -R %{mysqld_user}:%{mysqld_group} $mysql_datadir @@ -723,6 +732,11 @@ fi # itself - note that they must be ordered by date (important when # merging BK trees) %changelog +* Tue Jun 20 2006 Joerg Bruehe <joerg@mysql.com> + +- To run "mysql_upgrade", we need a running server; + start it in isolation and skip password checks. + * Sat May 20 2006 Kent Boortz <kent@mysql.com> - Always compile for PIC, position independent code. |