diff options
author | unknown <vva@genie.(none)> | 2002-11-18 20:53:07 +0400 |
---|---|---|
committer | unknown <vva@genie.(none)> | 2002-11-18 20:53:07 +0400 |
commit | 54c03ff73630ce782d3c982003989b12a3fa5728 (patch) | |
tree | e5198b1d3dc83e00741ff9719e1ff7bdc7b5a023 /client | |
parent | a9c044ac87b5828c07557450baf075550cb60605 (diff) | |
parent | db7357a9e752982c537ee95c0f76a7b4d11669c3 (diff) | |
download | mariadb-git-54c03ff73630ce782d3c982003989b12a3fa5728.tar.gz |
Merge vvagin@work.mysql.com:/home/bk/mysql-4.0
into genie.(none):/home/vva/work/mysqldump_xml/4.0
Diffstat (limited to 'client')
-rw-r--r-- | client/mysqldump.c | 42 |
1 files changed, 27 insertions, 15 deletions
diff --git a/client/mysqldump.c b/client/mysqldump.c index 39e9714660a..a6eaf1794fd 100644 --- a/client/mysqldump.c +++ b/client/mysqldump.c @@ -294,7 +294,10 @@ static void short_usage(void) static void write_header(FILE *sql_file, char *db_name) { if (opt_xml) + { fprintf(sql_file,"<?xml version=\"1.0\"?>\n"); + fprintf(sql_file,"<mysqldump>\n"); + } else { fprintf(sql_file, "-- MySQL dump %s\n--\n", DUMP_VERSION); @@ -308,6 +311,12 @@ static void write_header(FILE *sql_file, char *db_name) return; } /* write_header */ +static void write_footer(FILE *sql_file) +{ + if (opt_xml) + fprintf(sql_file,"</mysqldump>"); + fputs("\n", sql_file); +} /* write_footer */ static my_bool get_one_option(int optid, const struct my_option *opt __attribute__((unused)), @@ -978,7 +987,7 @@ static void dumpTable(uint numFields, char *table) rownr=0; init_length=(uint) strlen(insert_pat)+4; if (opt_xml) - fprintf(md_result_file, "\t<%s>\n", table); + fprintf(md_result_file, "\t<table name=\"%s\">\n", table); if (opt_autocommit) fprintf(md_result_file, "set autocommit=0;\n"); @@ -1067,8 +1076,8 @@ static void dumpTable(uint numFields, char *table) /* change any strings ("inf","nan",..) into NULL */ char *ptr = row[i]; if (opt_xml) - fprintf(md_result_file, "\t\t<%s>%s</%s>\n", - field->name,!isalpha(*ptr) ?ptr: "NULL",field->name); + fprintf(md_result_file, "\t\t<field name=\"%s\">%s</field>\n", + field->name,!isalpha(*ptr) ?ptr: "NULL"); else fputs((!isalpha(*ptr)) ? ptr : "NULL", md_result_file); } @@ -1076,8 +1085,8 @@ static void dumpTable(uint numFields, char *table) else { if (opt_xml) - fprintf(md_result_file, "\t\t<%s>%s</%s>\n", - field->name, "NULL", field->name); + fprintf(md_result_file, "\t\t<field name=\"%s\">%s</field>\n", + field->name, "NULL"); else fputs("NULL", md_result_file); } @@ -1118,7 +1127,7 @@ static void dumpTable(uint numFields, char *table) /* XML - close table tag and supress regular output */ if (opt_xml) - fprintf(md_result_file, "\t</%s>\n", table); + fprintf(md_result_file, "\t</table>\n"); else if (extended_insert && row_break) fputs(";\n", md_result_file); /* If not empty table */ fflush(md_result_file); @@ -1150,7 +1159,7 @@ static void print_quoted_xml(FILE *output, char *fname, char *str, uint len) { const char *end; - fprintf(output, "\t\t<%s>", fname); + fprintf(output, "\t\t<field name=\"%s\">", fname); for (end = str + len; str != end; str++) { if (*str == '<') @@ -1164,7 +1173,7 @@ static void print_quoted_xml(FILE *output, char *fname, char *str, uint len) else fputc(*str, output); } - fprintf(output, "</%s>\n", fname); + fprintf(output, "</field>\n"); } static char *getTableName(int reset) @@ -1219,13 +1228,8 @@ static int dump_databases(char **db_names) int result=0; for ( ; *db_names ; db_names++) { - /* XML edit - add database element */ - if (opt_xml) - fprintf(md_result_file, "<%s>\n", *db_names); if (dump_all_tables_in_db(*db_names)) result=1; - if (opt_xml) - fprintf(md_result_file, "</%s>\n", *db_names); } return result; } /* dump_databases */ @@ -1238,7 +1242,7 @@ static int init_dumping(char *database) DBerror(sock, "when selecting the database"); return 1; /* If --force */ } - if (!path) + if (!path && !opt_xml) { if (opt_databases || opt_alldbs) { @@ -1264,6 +1268,8 @@ static int dump_all_tables_in_db(char *database) if (init_dumping(database)) return 1; + if (opt_xml) + fprintf(md_result_file, "<database name=\"%s\">\n", database); if (lock_tables) { DYNAMIC_STRING query; @@ -1290,6 +1296,8 @@ static int dump_all_tables_in_db(char *database) if (!dFlag && numrows > 0) dumpTable(numrows,table); } + if (opt_xml) + fprintf(md_result_file, "</database>\n"); if (lock_tables) mysql_query(sock,"UNLOCK_TABLES"); return 0; @@ -1326,12 +1334,16 @@ static int dump_selected_tables(char *db, char **table_names, int tables) DBerror(sock, "when doing refresh"); /* We shall countinue here, if --force was given */ } + if (opt_xml) + fprintf(md_result_file, "<database name=\"%s\">\n", db); for (; tables > 0 ; tables-- , table_names++) { numrows = getTableStructure(*table_names, db); if (!dFlag && numrows > 0) dumpTable(numrows, *table_names); } + if (opt_xml) + fprintf(md_result_file, "</database>\n"); if (lock_tables) mysql_query(sock,"UNLOCK_TABLES"); return 0; @@ -1462,7 +1474,7 @@ int main(int argc, char **argv) } } dbDisconnect(current_host); - fputs("\n", md_result_file); + write_footer(md_result_file); if (md_result_file != stdout) my_fclose(md_result_file, MYF(0)); my_free(opt_password, MYF(MY_ALLOW_ZERO_PTR)); |