Commit 2c0cf8ed authored by unknown's avatar unknown

New option to mysqldump.


Docs/manual.texi:
  New option, -r, to mysqldump. This is needed in MSDOS mode.
client/mysqldump.c:
  Added option -r for MSDOS mode.
parent 983116d8
......@@ -32515,6 +32515,10 @@ used.)
@item -q, --quick
Don't buffer query, dump directly to stdout. Uses @code{mysql_use_result()}
to do this.
@item -r, --result-file=...
Direct output to a given file. This option should be used in MSDOS,
because it prevents new line '\n' from being converted to '\n\r' (new
line + carriage return).
@item -S /path/to/socket, --socket=/path/to/socket
The socket file to use when connecting to @code{localhost} (which is the
default host).
......@@ -37,7 +37,7 @@
** Tnu Samuel <tonu@please.do.not.remove.this.spam.ee>
**/
#define DUMP_VERSION "8.13"
#define DUMP_VERSION "8.14"
#include <global.h>
#include <my_sys.h>
......@@ -73,7 +73,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_alldbs=0,opt_create_db=0,opt_first_slave=0,
opt_resultfile=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,
......@@ -127,6 +128,7 @@ static struct option long_options[] =
{"port", required_argument, 0, 'P'},
{"quick", no_argument, 0, 'q'},
{"quote-names", no_argument, 0, 'Q'},
{"result-file", required_argument, 0, 'r'},
{"set-variable", required_argument, 0, 'O'},
{"socket", required_argument, 0, 'S'},
#include "sslopt-longopts.h"
......@@ -227,6 +229,10 @@ puts("\
-P, --port=... Port number to use for connection.\n\
-q, --quick Don't buffer query, dump directly to stdout.\n\
-Q, --quote-names Quote table and column names with `\n\
-r, --result-file=... Direct output to a given file. This option should be\n\
used in MSDOS, because it prevents new line '\\n'\n\
from being converted to '\\n\\r' (newline + carriage\n\
return).\n\
-S, --socket=... Socket file to use for connection.\n\
--tables Overrides option --databases (-B).\n");
#include "sslopt-usage.h"
......@@ -283,10 +289,12 @@ static int get_options(int *argc,char ***argv)
{
int c,option_index;
my_bool tty_password=0;
FILE *resultfile;
load_defaults("my",load_default_groups,argc,argv);
set_all_changeable_vars(changeable_vars);
while ((c=getopt_long(*argc,*argv,"#::p::h:u:O:P:S:T:EBaAcCdefFlnqtvVw:?Ix",
while ((c=getopt_long(*argc,*argv,
"#::p::h:u:O:P:r:S:T:EBaAcCdefFlnqtvVw:?Ix",
long_options, &option_index)) != EOF)
{
switch(c) {
......@@ -346,6 +354,15 @@ static int get_options(int *argc,char ***argv)
case 'P':
opt_mysql_port= (unsigned int) atoi(optarg);
break;
case 'r':
if (!(resultfile = my_fopen(optarg, O_WRONLY, MYF(MY_WME))))
{
printf("Couldn't open result-file %s, aborting!\n", optarg);
exit(1);
}
opt_resultfile = 1;
stdout = resultfile;
break;
case 'S':
opt_mysql_unix_port= optarg;
break;
......@@ -737,8 +754,8 @@ static uint getTableStructure(char *table, char* db)
fprintf(sql_file, " %s.%s %s", table_name,
quote_name(row[SHOW_FIELDNAME],name_buff), row[SHOW_TYPE]);
else
fprintf(sql_file, " %s %s", quote_name(row[SHOW_FIELDNAME],name_buff),
row[SHOW_TYPE]);
fprintf(sql_file, " %s %s", quote_name(row[SHOW_FIELDNAME],
name_buff), row[SHOW_TYPE]);
if (row[SHOW_DEFAULT])
{
fputs(" DEFAULT ", sql_file);
......@@ -777,10 +794,10 @@ static uint getTableStructure(char *table, char* db)
if (atoi(row[3]) == 1)
{
keynr++;
#ifdef FORCE_PRIMARY_KEY
#ifdef FORCE_PRIMARY_KEY
if (atoi(row[1]) == 0 && primary_key == INT_MAX)
primary_key=keynr;
#endif
#endif
if (!strcmp(row[2],"PRIMARY"))
{
primary_key=keynr;
......@@ -967,7 +984,7 @@ static void dumpTable(uint numFields, char *table)
printf("# WHERE: %s\n",where);
strxmov(strend(query), " WHERE ",where,NullS);
}
puts("#\n");
fputs("#\n\n", stdout);
if (mysql_query(sock, query))
{
......@@ -1090,7 +1107,7 @@ static void dumpTable(uint numFields, char *table)
else
{
if (row_break)
puts(";");
fputs(";\n", stdout);
row_break=1; /* This is first row */
fputs(insert_pat,stdout);
fputs(extended_row.str,stdout);
......@@ -1098,12 +1115,10 @@ static void dumpTable(uint numFields, char *table)
}
}
else
{
puts(");");
}
fputs(");\n", stdout);
}
if (extended_insert && row_break)
puts(";"); /* If not empty table */
fputs(";\n", stdout); /* If not empty table */
fflush(stdout);
if (mysql_errno(sock))
{
......@@ -1118,7 +1133,7 @@ static void dumpTable(uint numFields, char *table)
return;
}
if (opt_lock)
puts("UNLOCK TABLES;");
fputs("UNLOCK TABLES;\n", stdout);
mysql_free_result(res);
}
} /* dumpTable */
......@@ -1365,7 +1380,9 @@ int main(int argc, char **argv)
}
}
dbDisconnect(current_host);
puts("");
fputs("\n", stdout);
if (opt_resultfile)
my_fclose(stdout, MYF(0));
my_free(opt_password, MYF(MY_ALLOW_ZERO_PTR));
if (extended_insert)
dynstr_free(&extended_row);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment