diff options
author | unknown <jani@hynda.mysql.fi> | 2001-11-05 23:48:03 +0200 |
---|---|---|
committer | unknown <jani@hynda.mysql.fi> | 2001-11-05 23:48:03 +0200 |
commit | a6879a4816de55ef17f9326891f2443b5a3f948b (patch) | |
tree | 008020b20467d6720f9edf373f9b4aa9624c5918 /client | |
parent | 67033f1c5f81ebf3b3bc4e09e855a8af798b99a8 (diff) | |
download | mariadb-git-a6879a4816de55ef17f9326891f2443b5a3f948b.tar.gz |
Added xml patch to mysqldump.
Made innodb to compile more cleanly with debugging options
enabled. Fixed a few bugs and found a few possible bugs, which
I hope Heikki will check. Comments needs to be fixed too. Some
while() functions should be changed to do ... until for documenting
purposes, because some of them must and will be processed at least
once, or a variable would be used uninitialized.
Regards,
Jani
client/mysqldump.c:
Added xml output. Patch originally from Gary Huntress, but needed
a some clean up.
innobase/btr/btr0btr.c:
cleaner compiling
innobase/btr/btr0cur.c:
cleaner compiling
innobase/btr/btr0sea.c:
cleaner compiling / found a bug ??
innobase/buf/buf0buf.c:
Fixed a bug.
innobase/buf/buf0lru.c:
Fixed a bug.
innobase/data/data0data.c:
cleaner compiling
innobase/dict/dict0boot.c:
cleaner compiling
innobase/dict/dict0crea.c:
cleaner compiling
innobase/dict/dict0dict.c:
cleaner compiling
innobase/dict/dict0load.c:
cleaner compiling
innobase/eval/eval0eval.c:
cleaner compiling / found a bug ??
innobase/fil/fil0fil.c:
cleaner compiling
innobase/fsp/fsp0fsp.c:
cleaner compiling
innobase/ibuf/ibuf0ibuf.c:
cleaner compiling
innobase/include/btr0btr.ic:
cleaner compiling
innobase/include/buf0buf.ic:
cleaner compiling
innobase/include/dict0dict.ic:
cleaner compiling
innobase/include/ha0ha.ic:
cleaner compiling
innobase/include/row0mysql.ic:
cleaner compiling
innobase/include/row0vers.ic:
cleaner compiling
innobase/include/sync0rw.ic:
cleaner compiling
innobase/lock/lock0lock.c:
cleaner compiling
innobase/mem/mem0dbg.c:
cleaner compiling
innobase/mtr/mtr0mtr.c:
cleaner compiling
innobase/odbc/odbc0odbc.c:
cleaner compiling
innobase/os/os0thread.c:
cleaner compiling
innobase/page/page0cur.c:
cleaner compiling. while() should be changed to do ... until
for documenting purposes.
innobase/page/page0page.c:
cleaner compiling
innobase/pars/pars0opt.c:
cleaner compiling. while() should be changed to do ... until,
because it will and must be processed at least once (for documenting
purposes)
innobase/pars/pars0pars.c:
cleaner compiling
innobase/que/que0que.c:
cleaner compiling
innobase/rem/rem0cmp.c:
cleaner compiling
innobase/rem/rem0rec.c:
cleaner compiling
innobase/row/row0ins.c:
cleaner compiling
innobase/row/row0mysql.c:
cleaner compiling
innobase/row/row0purge.c:
cleaner compiling
innobase/row/row0sel.c:
cleaner compiling
innobase/row/row0uins.c:
cleaner compiling
innobase/row/row0umod.c:
cleaner compiling
innobase/row/row0upd.c:
cleaner compiling
innobase/srv/srv0srv.c:
cleaner compiling
innobase/srv/srv0start.c:
cleaner compiling
innobase/sync/sync0arr.c:
cleaner compiling
innobase/sync/sync0rw.c:
cleaner compiling
innobase/sync/sync0sync.c:
cleaner compiling
innobase/trx/trx0purge.c:
cleaner compiling. in theory this could also be a bug, although
probably not. But the logic needs to be checked, it could be that
these variables may be used uninitialized.
innobase/trx/trx0rec.c:
cleaner compiling
innobase/trx/trx0roll.c:
cleaner compiling
innobase/trx/trx0trx.c:
cleaner compiling
innobase/trx/trx0undo.c:
cleaner compiling
Diffstat (limited to 'client')
-rw-r--r-- | client/mysqldump.c | 109 |
1 files changed, 79 insertions, 30 deletions
diff --git a/client/mysqldump.c b/client/mysqldump.c index 117c070a936..3741b61d3e0 100644 --- a/client/mysqldump.c +++ b/client/mysqldump.c @@ -31,7 +31,9 @@ ** SSL by ** Andrei Errapart <andreie@no.spam.ee> ** Tõnu Samuel <tonu@please.do.not.remove.this.spam.ee> -**/ +** XML by Gary Huntress <ghuntress@mediaone.net> 10/10/01, cleaned up +** and adapted to mysqldump 05/11/01 by Jani Tolonen +*/ #define DUMP_VERSION "8.18" @@ -70,7 +72,8 @@ static my_bool verbose=0,tFlag=0,cFlag=0,dFlag=0,quick=0, extended_insert = 0, lock_tables=0,ignore_errors=0,flush_logs=0,replace=0, ignore=0,opt_drop=0,opt_keywords=0,opt_lock=0,opt_compress=0, opt_delayed=0,create_options=0,opt_quoted=0,opt_databases=0, - opt_alldbs=0,opt_create_db=0,opt_first_slave=0, opt_autocommit=0, opt_master_data; + opt_alldbs=0,opt_create_db=0,opt_first_slave=0, + opt_autocommit=0, opt_master_data, opt_xml=0; static MYSQL mysql_connection,*sock=0; static char insert_pat[12 * 1024],*opt_password=0,*current_user=0, *current_host=0,*path=0,*fields_terminated=0, @@ -135,6 +138,7 @@ static struct option long_options[] = {"verbose", no_argument, 0, 'v'}, {"version", no_argument, 0, 'V'}, {"where", required_argument, 0, 'w'}, + {"xml", no_argument, 0, 'X'}, {0, 0, 0, 0} }; @@ -248,6 +252,7 @@ puts("\ -v, --verbose Print info about the various stages.\n\ -V, --version Output version information and exit.\n\ -w, --where= dump only selected records; QUOTES mandatory!\n\ + -X, --xml dump a database as well formed XML\n\ -x, --first-slave Locks all tables across all databases.\n\ EXAMPLES: \"--where=user=\'jimf\'\" \"-wuserid>1\" \"-wuserid<1\"\n\ Use -T (--tab=...) with --fields-...\n\ @@ -274,13 +279,18 @@ puts("\ static void write_heder(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 : ""); - fputs("---------------------------------------------------------\n", - sql_file); - fprintf(sql_file, "-- Server version\t%s\n", - mysql_get_server_info(&mysql_connection)); + if (opt_xml) + fprintf(sql_file,"<?xml version=\"1.0\"?>\n"); + else + { + 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 : ""); + fputs("---------------------------------------------------------\n", + sql_file); + fprintf(sql_file, "-- Server version\t%s\n", + mysql_get_server_info(&mysql_connection)); + } return; } /* write_heder */ @@ -294,7 +304,7 @@ static int get_options(int *argc,char ***argv) load_defaults("my",load_default_groups,argc,argv); set_all_changeable_vars(md_changeable_vars); while ((c=getopt_long(*argc,*argv, - "#::p::h:u:O:P:r:S:T:EBaAcCdefFlnqtvVw:?Ix", + "#::p::h:u:O:P:r:S:T:EBaAcCdefFlnqtvVw:?IxX", long_options, &option_index)) != EOF) { switch(c) { @@ -397,6 +407,7 @@ static int get_options(int *argc,char ***argv) case 'w': where=optarg; break; + case 'X': opt_xml = 1; break; case 'x': opt_first_slave=1; break; @@ -563,7 +574,7 @@ static void unescape(FILE *file,char *pos,uint length) ignore_errors=0; /* Fatal error */ safe_exit(EX_MYSQLERR); /* Force exit */ } - mysql_real_escape_string(&mysql_connection,tmp, pos, length); + mysql_real_escape_string(&mysql_connection, tmp, pos, length); fputc('\'', file); fputs(tmp, file); fputc('\'', file); @@ -649,13 +660,16 @@ static uint getTableStructure(char *table, char* db) } write_heder(sql_file, db); } - fprintf(sql_file, "\n--\n-- Table structure for table '%s'\n--\n\n",table); + if (!opt_xml) + fprintf(sql_file, "\n--\n-- Table structure for table '%s'\n--\n\n", + table); if (opt_drop) fprintf(sql_file, "DROP TABLE IF EXISTS %s;\n",table_name); tableRes=mysql_store_result(sock); row=mysql_fetch_row(tableRes); - fprintf(sql_file, "%s;\n", row[1]); + if (!opt_xml) + fprintf(sql_file, "%s;\n", row[1]); mysql_free_result(tableRes); } sprintf(insert_pat,"show fields from %s",table_name); @@ -721,7 +735,9 @@ static uint getTableStructure(char *table, char* db) } write_heder(sql_file, db); } - fprintf(sql_file, "\n--\n-- Table structure for table '%s'\n--\n\n",table); + if (!opt_xml) + fprintf(sql_file, "\n--\n-- Table structure for table '%s'\n--\n\n", + table); if (opt_drop) fprintf(sql_file, "DROP TABLE IF EXISTS %s;\n",table_name); fprintf(sql_file, "CREATE TABLE %s (\n", table_name); @@ -760,7 +776,7 @@ static uint getTableStructure(char *table, char* db) if (row[SHOW_DEFAULT]) { fputs(" DEFAULT ", sql_file); - unescape(sql_file,row[SHOW_DEFAULT],lengths[SHOW_DEFAULT]); + unescape(sql_file, row[SHOW_DEFAULT], lengths[SHOW_DEFAULT]); } if (!row[SHOW_NULL][0]) fputs(" NOT NULL", sql_file); @@ -977,14 +993,18 @@ static void dumpTable(uint numFields, char *table) } else { - fprintf(md_result_file,"\n--\n-- Dumping data for table '%s'\n--\n", table); + if (!opt_xml) + fprintf(md_result_file,"\n--\n-- Dumping data for table '%s'\n--\n", + table); sprintf(query, "SELECT * FROM %s", quote_name(table,table_buff)); if (where) { - fprintf(md_result_file,"-- WHERE: %s\n",where); + if (!opt_xml) + fprintf(md_result_file,"-- WHERE: %s\n",where); strxmov(strend(query), " WHERE ",where,NullS); } - fputs("\n\n", md_result_file); + if (!opt_xml) + fputs("\n\n", md_result_file); if (mysql_query(sock, query)) { DBerror(sock, "when retrieving data from server"); @@ -1017,6 +1037,8 @@ static void dumpTable(uint numFields, char *table) row_break=0; rownr=0; init_length=(uint) strlen(insert_pat)+4; + if (opt_xml) + fprintf(md_result_file, "\t<%s>\n", table); if (opt_autocommit) fprintf(md_result_file, "set autocommit=0;\n"); @@ -1026,7 +1048,7 @@ static void dumpTable(uint numFields, char *table) uint i; ulong *lengths=mysql_fetch_lengths(res); rownr++; - if (!extended_insert) + if (!extended_insert && !opt_xml) fputs(insert_pat,md_result_file); mysql_field_seek(res,0); @@ -1085,22 +1107,36 @@ static void dumpTable(uint numFields, char *table) } else { - if (i) - fputc(',',md_result_file); + if (i && !opt_xml) + fputc(',', md_result_file); if (row[i]) { if (!IS_NUM_FIELD(field)) - unescape(md_result_file, row[i], lengths[i]); + { + if (opt_xml) + fprintf(md_result_file, "\t\t<%s>%s</%s>\n", + field->name, row[i], field->name); + else + unescape(md_result_file, row[i], lengths[i]); + } else { /* change any strings ("inf","nan",..) into NULL */ char *ptr = row[i]; - fputs((!isalpha(*ptr)) ? ptr : "NULL", md_result_file); + if (opt_xml) + fprintf(md_result_file, "\t\t<%s>%s</%s>\n", + field->name,!isalpha(*ptr) ?ptr: "NULL",field->name); + else + fputs((!isalpha(*ptr)) ? ptr : "NULL", md_result_file); } } else { - fputs("NULL",md_result_file); + if (opt_xml) + fprintf(md_result_file, "\t\t<%s>%s</%s>\n", + field->name, "NULL", field->name); + else + fputs("NULL", md_result_file); } } } @@ -1118,18 +1154,26 @@ static void dumpTable(uint numFields, char *table) } else { - if (row_break) + if (row_break && !opt_xml) fputs(";\n", md_result_file); row_break=1; /* This is first row */ - fputs(insert_pat,md_result_file); - fputs(extended_row.str,md_result_file); + + if (!opt_xml) + { + fputs(insert_pat,md_result_file); + fputs(extended_row.str,md_result_file); + } total_length = row_length+init_length; } } - else + else if (!opt_xml) fputs(");\n", md_result_file); } - if (extended_insert && row_break) + + //XML - close table tag and supress regular output + if (opt_xml) + fprintf(md_result_file, "\t</%s>\n", table); + else if (extended_insert && row_break) fputs(";\n", md_result_file); /* If not empty table */ fflush(md_result_file); if (mysql_errno(sock)) @@ -1204,9 +1248,14 @@ 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 */ |