diff options
author | unknown <jimw@mysql.com> | 2005-05-18 09:25:06 -0700 |
---|---|---|
committer | unknown <jimw@mysql.com> | 2005-05-18 09:25:06 -0700 |
commit | 0f02da9f4e930580e81d0c72d873d69be22af795 (patch) | |
tree | 43250c110173e76ac09b0a7f7a5271efcca92b9f /client | |
parent | 0a2b07254f85b9e3a1a5a4bc52bb44957006cc31 (diff) | |
parent | eff871bd6ce85c5e4eedcac8bc756f8d1799233b (diff) | |
download | mariadb-git-0f02da9f4e930580e81d0c72d873d69be22af795.tar.gz |
Resolve bugfix merge
client/mysqldump.c:
Merge bug fix
mysql-test/r/mysqldump.result:
Update results
mysql-test/t/mysqldump.test:
Merge bug fix
Diffstat (limited to 'client')
-rw-r--r-- | client/mysqldump.c | 117 |
1 files changed, 71 insertions, 46 deletions
diff --git a/client/mysqldump.c b/client/mysqldump.c index 67b89ea4bc2..493ef57a73b 100644 --- a/client/mysqldump.c +++ b/client/mysqldump.c @@ -75,18 +75,22 @@ static ulong find_set(TYPELIB *lib, const char *x, uint length, char **err_pos, uint *err_len); static char *field_escape(char *to,const char *from,uint length); -static my_bool verbose=0,tFlag=0,cFlag=0,dFlag=0,quick= 1, extended_insert= 1, +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, 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, + 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_hex_blob=0, opt_order_by_primary=0, opt_ignore=0, + opt_complete_insert= 0; static ulong opt_max_allowed_packet, opt_net_buffer_length; static MYSQL mysql_connection,*sock=0; -static char insert_pat[12 * 1024],*opt_password=0,*current_user=0, +static my_bool insert_pat_inited=0; +static DYNAMIC_STRING insert_pat; +static char *opt_password=0,*current_user=0, *current_host=0,*path=0,*fields_terminated=0, *lines_terminated=0, *enclosed=0, *opt_enclosed=0, *escaped=0, *where=0, *order_by=0, @@ -178,8 +182,9 @@ static struct my_option my_long_options[] = "Give less verbose output (useful for debugging). Disables structure comments and header/footer constructs. Enables options --skip-add-drop-table --no-set-names --skip-disable-keys --skip-add-locks", (gptr*) &opt_compact, (gptr*) &opt_compact, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0}, - {"complete-insert", 'c', "Use complete insert statements.", (gptr*) &cFlag, - (gptr*) &cFlag, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0}, + {"complete-insert", 'c', "Use complete insert statements.", + (gptr*) &opt_complete_insert, (gptr*) &opt_complete_insert, 0, GET_BOOL, + NO_ARG, 0, 0, 0, 0, 0, 0}, {"compress", 'C', "Use compression in server/client protocol.", (gptr*) &opt_compress, (gptr*) &opt_compress, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0}, @@ -1085,7 +1090,7 @@ static void print_xml_row(FILE *xml_file, const char *row_name, /* - getStructure -- retrievs database structure, prints out corresponding + getTableStructure -- retrievs database structure, prints out corresponding CREATE statement and fills out insert_pat. RETURN @@ -1098,13 +1103,22 @@ static uint getTableStructure(char *table, char* db) MYSQL_ROW row; my_bool init=0; uint numFields; - char *strpos, *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]; + char query_buff[512]; FILE *sql_file = md_result_file; + int len; DBUG_ENTER("getTableStructure"); + if (!insert_pat_inited) + { + insert_pat_inited= init_dynamic_string(&insert_pat, "", 1024, 1024); + } + else + dynstr_set(&insert_pat, ""); + insert_option= (opt_delayed && opt_ignore) ? " DELAYED IGNORE " : opt_delayed ? " DELAYED " : opt_ignore ? " IGNORE " : ""; @@ -1112,11 +1126,11 @@ static uint getTableStructure(char *table, char* db) if (verbose) fprintf(stderr, "-- Retrieving table structure for table %s...\n", table); - my_snprintf(insert_pat, sizeof(insert_pat), - "SET OPTION SQL_QUOTE_SHOW_CREATE=%d", - (opt_quoted || opt_keywords)); + len= my_snprintf(query_buff, sizeof(query_buff), + "SET OPTION SQL_QUOTE_SHOW_CREATE=%d", + (opt_quoted || opt_keywords)); if (!create_options) - strmov(strend(insert_pat), "/*!40102 ,SQL_MODE=concat(@@sql_mode, _utf8 ',NO_KEY_OPTIONS,NO_TABLE_OPTIONS,NO_FIELD_OPTIONS') */"); + strmov(query_buff+len, "/*!40102 ,SQL_MODE=concat(@@sql_mode, _utf8 ',NO_KEY_OPTIONS,NO_TABLE_OPTIONS,NO_FIELD_OPTIONS') */"); result_table= quote_name(table, table_buff, 1); opt_quoted_table= quote_name(table, table_buff2, 0); @@ -1124,7 +1138,7 @@ static uint getTableStructure(char *table, char* db) if (opt_order_by_primary) order_by = primary_key_fields(opt_quoted_table); - if (!opt_xml && !mysql_query_with_error_report(sock, 0, insert_pat)) + if (!opt_xml && !mysql_query_with_error_report(sock, 0, query_buff)) { /* using SHOW CREATE statement */ if (!tFlag) @@ -1170,9 +1184,9 @@ static uint getTableStructure(char *table, char* db) check_io(sql_file); mysql_free_result(tableRes); } - my_snprintf(insert_pat, sizeof(insert_pat), "show fields from %s", + my_snprintf(query_buff, sizeof(query_buff), "show fields from %s", result_table); - if (mysql_query_with_error_report(sock, &tableRes, insert_pat)) + if (mysql_query_with_error_report(sock, &tableRes, query_buff)) { if (path) my_fclose(sql_file, MYF(MY_WME)); @@ -1180,28 +1194,32 @@ static uint getTableStructure(char *table, char* db) DBUG_RETURN(0); } - if (cFlag) - my_snprintf(insert_pat, sizeof(insert_pat), "INSERT %sINTO %s (", - insert_option, opt_quoted_table); + dynstr_append_mem(&insert_pat, "INSERT ", 7); + dynstr_append(&insert_pat, insert_option); + dynstr_append_mem(&insert_pat, "INTO ", 5); + dynstr_append(&insert_pat, opt_quoted_table); + if (opt_complete_insert) + { + dynstr_append_mem(&insert_pat, " (", 2); + } else { - my_snprintf(insert_pat, sizeof(insert_pat), "INSERT %sINTO %s VALUES ", - insert_option, opt_quoted_table); + dynstr_append_mem(&insert_pat, " VALUES ", 8); if (!extended_insert) - strcat(insert_pat,"("); + dynstr_append_mem(&insert_pat, "(", 1); } - strpos=strend(insert_pat); while ((row=mysql_fetch_row(tableRes))) { if (init) { - if (cFlag) - strpos=strmov(strpos,", "); + if (opt_complete_insert) + dynstr_append_mem(&insert_pat, ", ", 2); } init=1; - if (cFlag) - strpos=strmov(strpos,quote_name(row[SHOW_FIELDNAME], name_buff, 0)); + if (opt_complete_insert) + dynstr_append(&insert_pat, + quote_name(row[SHOW_FIELDNAME], name_buff, 0)); } numFields = (uint) mysql_num_rows(tableRes); mysql_free_result(tableRes); @@ -1213,9 +1231,9 @@ static uint getTableStructure(char *table, char* db) "%s: Warning: Can't set SQL_QUOTE_SHOW_CREATE option (%s)\n", my_progname, mysql_error(sock)); - my_snprintf(insert_pat, sizeof(insert_pat), "show fields from %s", + my_snprintf(query_buff, sizeof(query_buff), "show fields from %s", result_table); - if (mysql_query_with_error_report(sock, &tableRes, insert_pat)) + if (mysql_query_with_error_report(sock, &tableRes, query_buff)) { safe_exit(EX_MYSQLERR); DBUG_RETURN(0); @@ -1248,18 +1266,22 @@ static uint getTableStructure(char *table, char* db) print_xml_tag1(sql_file, "\t", "table_structure name=", table, "\n"); check_io(sql_file); } - if (cFlag) - my_snprintf(insert_pat, sizeof(insert_pat), "INSERT %sINTO %s (", - insert_option, result_table); + + dynstr_append_mem(&insert_pat, "INSERT ", 7); + dynstr_append(&insert_pat, insert_option); + dynstr_append_mem(&insert_pat, "INTO ", 5); + dynstr_append(&insert_pat, result_table); + if (opt_complete_insert) + { + dynstr_append_mem(&insert_pat, " (", 2); + } else { - my_snprintf(insert_pat, sizeof(insert_pat), "INSERT %sINTO %s VALUES ", - insert_option, result_table); + dynstr_append_mem(&insert_pat, " VALUES ", 8); if (!extended_insert) - strcat(insert_pat,"("); + dynstr_append_mem(&insert_pat, "(", 1); } - strpos=strend(insert_pat); while ((row=mysql_fetch_row(tableRes))) { ulong *lengths=mysql_fetch_lengths(tableRes); @@ -1270,12 +1292,13 @@ static uint getTableStructure(char *table, char* db) fputs(",\n",sql_file); check_io(sql_file); } - if (cFlag) - strpos=strmov(strpos,", "); + if (opt_complete_insert) + dynstr_append_mem(&insert_pat, ", ", 2); } init=1; - if (cFlag) - strpos=strmov(strpos,quote_name(row[SHOW_FIELDNAME], name_buff, 0)); + if (opt_complete_insert) + dynstr_append(&insert_pat, + quote_name(row[SHOW_FIELDNAME], name_buff, 0)); if (!tFlag) { if (opt_xml) @@ -1283,7 +1306,7 @@ static uint getTableStructure(char *table, char* db) print_xml_row(sql_file, "field", tableRes, &row); continue; } - + if (opt_keywords) fprintf(sql_file, " %s.%s %s", result_table, quote_name(row[SHOW_FIELDNAME],name_buff, 0), @@ -1428,11 +1451,11 @@ static uint getTableStructure(char *table, char* db) check_io(sql_file); } } - if (cFlag) + if (opt_complete_insert) { - strpos=strmov(strpos,") VALUES "); + dynstr_append_mem(&insert_pat, ") VALUES ", 9); if (!extended_insert) - strpos=strmov(strpos,"("); + dynstr_append_mem(&insert_pat, "(", 1); } if (sql_file != md_result_file) { @@ -1655,7 +1678,7 @@ static void dumpTable(uint numFields, char *table) total_length= opt_net_buffer_length; /* Force row break */ row_break=0; rownr=0; - init_length=(uint) strlen(insert_pat)+4; + init_length=(uint) insert_pat.length+4; if (opt_xml) print_xml_tag1(md_result_file, "\t", "table_data name=", table, "\n"); @@ -1672,7 +1695,7 @@ static void dumpTable(uint numFields, char *table) rownr++; if (!extended_insert && !opt_xml) { - fputs(insert_pat,md_result_file); + fputs(insert_pat.str,md_result_file); check_io(md_result_file); } mysql_field_seek(res,0); @@ -1869,7 +1892,7 @@ static void dumpTable(uint numFields, char *table) fputs(";\n", md_result_file); row_break=1; /* This is first row */ - fputs(insert_pat,md_result_file); + fputs(insert_pat.str,md_result_file); fputs(extended_row.str,md_result_file); total_length = row_length+init_length; } @@ -2562,6 +2585,8 @@ err: my_free(opt_password, MYF(MY_ALLOW_ZERO_PTR)); if (extended_insert) dynstr_free(&extended_row); + if (insert_pat_inited) + dynstr_free(&insert_pat); my_end(0); return(first_error); } /* main */ |