99c99 < opt_autocommit=0,opt_disable_keys=1,opt_xml=0, --- > opt_autocommit=0,opt_disable_keys=1,opt_xml=0,opt_keys_last=1, 282a283,286 > {"keys-last", 'L', > "'/*!40000 ALTER TABLE tb_name DROP KEY ...*/; and '/*!40000 ALTER " > "TABLE tb_name ADD KEY ... */; will be put in the output.", &opt_keys_last, > &opt_keys_last, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0}, 2225a2230,2331 > int get_item_len(char *start_pos) > { > char *pos= start_pos; > while (*pos != '(') > { > pos++; > } > return pos - start_pos; > } > > void build_index_string(char *result_table, char *create_table_string, int is_add, DYNAMIC_STRING* result) > { > char *pos_start, *pos_end; > const char* key_prefix= "\n KEY `"; > const char* unique_key_prefix= "\n UNIQUE KEY `"; > const char* end_of_line= "\n"; > > const char *opcmd= is_add ? " ADD " : " DROP "; > int has_unique_index= 0; > int has_normal_index= 0; > int last_one; > > pos_start= strstr(create_table_string, unique_key_prefix); > if (pos_start) has_unique_index= 1; > > pos_start= strstr(create_table_string, key_prefix); > if (pos_start) has_normal_index= 1; > > if (has_unique_index || has_normal_index) > { > dynstr_append_checked(result, "ALTER TABLE "); > dynstr_append_checked(result, result_table); > > if (has_unique_index) > { > last_one= 0; > pos_start= strstr(create_table_string, unique_key_prefix); > while (pos_start) > { > pos_end= strstr(pos_start+1, unique_key_prefix); > > if (!pos_end) > { > pos_end= strstr(pos_start+1, end_of_line); > last_one= 1; > } > > dynstr_append_checked(result, opcmd); > > if (is_add) > dynstr_append_mem_checked(result, pos_start+3, pos_end-pos_start-3); > else > { > pos_start+= 9; > dynstr_append_mem_checked(result, pos_start, get_item_len(pos_start)); > dynstr_append_checked(result, ","); > } > > if (last_one) break; > > pos_start= pos_end; > } > } > > if (has_normal_index) > { > last_one= 0; > pos_start= strstr(create_table_string, key_prefix); > while (pos_start) > { > pos_end= strstr(pos_start+1, key_prefix); > > if (!pos_end) > { > pos_end= strstr(pos_start+1, end_of_line); > last_one= 1; > } > > dynstr_append_checked(result, opcmd); > > if (is_add) > dynstr_append_mem_checked(result, pos_start+3, pos_end-pos_start-3); > else > { > pos_start+= 3; > dynstr_append_mem_checked(result, pos_start, get_item_len(pos_start)); > dynstr_append_checked(result, ","); > } > > if (last_one) break; > > pos_start= pos_end; > } > } > > if (result->str[strlen(result->str)-1] == ',') > result->str[strlen(result->str)-1]= ';'; > else > dynstr_append_checked(result, ";"); > } > } > 2242c2348 < char *ignore_flag) --- > char *ignore_flag, DYNAMIC_STRING *drop_index_string, DYNAMIC_STRING* add_index_string) 2466a2573,2580 > > /*build drop and add index string*/ > if (opt_keys_last) > { > build_index_string(result_table, row[1], 0, drop_index_string); > build_index_string(result_table, row[1], 1,add_index_string); > } > 3086a3201,3202 > DYNAMIC_STRING drop_index_string; > DYNAMIC_STRING add_index_string; 3093c3209,3211 < num_fields= get_table_structure(table, db, table_type, &ignore_flag); --- > init_dynamic_string_checked(&drop_index_string, "", 1024, 1024); > init_dynamic_string_checked(&add_index_string, "", 1024, 1024); > num_fields= get_table_structure(table, db, table_type, &ignore_flag, &drop_index_string, &add_index_string); 3284a3403,3408 > if (opt_keys_last) > { > fprintf(md_result_file,"%s\n", > drop_index_string.str); > check_io(md_result_file); > } 3542a3667,3672 > if (opt_keys_last) > { > fprintf(md_result_file,"%s\n", > add_index_string.str); > check_io(md_result_file); > } 3562a3693,3694 > dynstr_free(&drop_index_string); > dynstr_free(&add_index_string); 3566a3699,3700 > dynstr_free(&drop_index_string); > dynstr_free(&add_index_string);