Commit 7be2f16a authored by unknown's avatar unknown

Fixed a problem with option --where, which earlier was not dynamic. One was not able

to use long query strings with it.
Bug#3633


BitKeeper/etc/logging_ok:
  Logging to logging@openlogging.org accepted
parent afb882c4
......@@ -39,6 +39,7 @@ hf@deer.mysql.r18.ru
hf@genie.(none)
igor@hundin.mysql.fi
igor@rurik.mysql.com
jani@a80-186-24-72.elisa-laajakaista.fi
jani@dsl-jkl1657.dial.inet.fi
jani@hynda.(none)
jani@hynda.mysql.fi
......
......@@ -36,7 +36,7 @@
** Added --single-transaction option 06/06/2002 by Peter Zaitsev
*/
#define DUMP_VERSION "9.10"
#define DUMP_VERSION "9.11"
#include <my_global.h>
#include <my_sys.h>
......@@ -938,18 +938,32 @@ static char *field_escape(char *to,const char *from,uint length)
} /* field_escape */
static char *alloc_query_str(ulong size)
{
char *query;
if (!(query= (char*) my_malloc(size, MYF(MY_WME))))
{
ignore_errors= 0; /* Fatal error */
safe_exit(EX_MYSQLERR); /* Force exit */
}
return query;
}
/*
** dumpTable saves database contents as a series of INSERT statements.
*/
static void dumpTable(uint numFields, char *table)
{
char query[QUERY_LENGTH], *end, buff[256],table_buff[NAME_LEN+3];
char query_buf[QUERY_LENGTH], *end, buff[256],table_buff[NAME_LEN+3];
char *result_table, table_buff2[NAME_LEN*2+3], *opt_quoted_table;
char *query= query_buf;
MYSQL_RES *res;
MYSQL_FIELD *field;
MYSQL_ROW row;
ulong rownr, row_break, total_length, init_length;
const char *table_type;
int error= 0;
result_table= quote_name(table,table_buff, 1);
opt_quoted_table= quote_name(table, table_buff2, 0);
......@@ -995,8 +1009,11 @@ static void dumpTable(uint numFields, char *table)
sprintf(buff," FROM %s", result_table);
end= strmov(end,buff);
if (where)
end= strxmov(end, " WHERE ",where,NullS);
if (mysql_query(sock, query))
{
query= alloc_query_str((ulong) (strlen(where) + (end - query) + 10));
end= strxmov(query, query_buf, " WHERE ", where, NullS);
}
if (mysql_real_query(sock, query, (uint) (end - query)))
{
DBerror(sock, "when executing 'SELECT INTO OUTFILE'");
return;
......@@ -1013,14 +1030,16 @@ static void dumpTable(uint numFields, char *table)
{
if (!opt_xml && opt_comments)
fprintf(md_result_file,"-- WHERE: %s\n",where);
strxmov(strend(query), " WHERE ",where,NullS);
query= alloc_query_str((ulong) (strlen(where) + strlen(query) + 10));
strxmov(query, query_buf, " WHERE ", where, NullS);
}
if (!opt_xml)
fputs("\n", md_result_file);
if (mysql_query(sock, query))
{
DBerror(sock, "when retrieving data from server");
return;
error= EX_CONSCHECK;
goto err;
}
if (quick)
res=mysql_use_result(sock);
......@@ -1029,7 +1048,8 @@ static void dumpTable(uint numFields, char *table)
if (!res)
{
DBerror(sock, "when retrieving data from server");
return;
error= EX_CONSCHECK;
goto err;
}
if (verbose)
fprintf(stderr, "-- Retrieving rows...\n");
......@@ -1037,8 +1057,8 @@ static void dumpTable(uint numFields, char *table)
{
fprintf(stderr,"%s: Error in field count for table: %s ! Aborting.\n",
my_progname, result_table);
safe_exit(EX_CONSCHECK);
return;
error= EX_CONSCHECK;
goto err;
}
if (opt_disable_keys)
......@@ -1076,8 +1096,8 @@ static void dumpTable(uint numFields, char *table)
sprintf(query,"%s: Not enough fields from table %s! Aborting.\n",
my_progname, result_table);
fputs(query,stderr);
safe_exit(EX_CONSCHECK);
return;
error= EX_CONSCHECK;
goto err;
}
if (extended_insert)
{
......@@ -1096,7 +1116,8 @@ static void dumpTable(uint numFields, char *table)
if (dynstr_realloc(&extended_row,length * 2+2))
{
fputs("Aborting dump (out of memory)",stderr);
safe_exit(EX_EOM);
error= EX_EOM;
goto err;
}
dynstr_append(&extended_row,"\'");
extended_row.length +=
......@@ -1131,7 +1152,8 @@ static void dumpTable(uint numFields, char *table)
else if (dynstr_append(&extended_row,"NULL"))
{
fputs("Aborting dump (out of memory)",stderr);
safe_exit(EX_EOM);
error= EX_EOM;
goto err;
}
}
else
......@@ -1229,8 +1251,8 @@ static void dumpTable(uint numFields, char *table)
result_table,
rownr);
fputs(query,stderr);
safe_exit(EX_CONSCHECK);
return;
error= EX_CONSCHECK;
goto err;
}
if (opt_lock)
fputs("UNLOCK TABLES;\n", md_result_file);
......@@ -1240,7 +1262,16 @@ static void dumpTable(uint numFields, char *table)
if (opt_autocommit)
fprintf(md_result_file, "commit;\n");
mysql_free_result(res);
if (query != query_buf)
my_free(query, MYF(MY_ALLOW_ZERO_PTR));
}
return;
err:
if (query != query_buf)
my_free(query, MYF(MY_ALLOW_ZERO_PTR));
safe_exit(error);
return;
} /* dumpTable */
......
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