summaryrefslogtreecommitdiff
path: root/client
diff options
context:
space:
mode:
authormonty@mysql.com <>2004-07-07 11:29:39 +0300
committermonty@mysql.com <>2004-07-07 11:29:39 +0300
commit1e311999950833cd81ca0788cd3656585c46d9ae (patch)
treeca8974710746bb69b04a49bc64f938d0b1a8420a /client
parent24a8dc2337a717ff340bac228383ef04437a4666 (diff)
parent8462b8aeb83355fa6c5cb4f45ea0ed63ba9e0712 (diff)
downloadmariadb-git-1e311999950833cd81ca0788cd3656585c46d9ae.tar.gz
Merge with 4.1.3-beta
Diffstat (limited to 'client')
-rw-r--r--client/mysql.cc24
-rw-r--r--client/mysqladmin.c10
-rw-r--r--client/mysqlbinlog.cc1
-rw-r--r--client/mysqldump.c141
-rw-r--r--client/mysqltest.c101
5 files changed, 221 insertions, 56 deletions
diff --git a/client/mysql.cc b/client/mysql.cc
index 01d867cca07..98bc7e750e1 100644
--- a/client/mysql.cc
+++ b/client/mysql.cc
@@ -136,6 +136,7 @@ static my_bool info_flag=0,ignore_errors=0,wait_flag=0,quick=0,
tty_password= 0, opt_nobeep=0, opt_reconnect=1,
default_charset_used= 0, opt_secure_auth= 0,
default_pager_set= 0;
+static ulong opt_max_allowed_packet, opt_net_buffer_length;
static uint verbose=0,opt_silent=0,opt_mysql_port=0, opt_local_infile=0;
static my_string opt_mysql_unix_port=0;
static int connect_flag=CLIENT_INTERACTIVE;
@@ -368,7 +369,7 @@ int main(int argc,char *argv[])
exit(1);
}
if (status.batch && !status.line_buff &&
- !(status.line_buff=batch_readline_init(max_allowed_packet+512,stdin)))
+ !(status.line_buff=batch_readline_init(opt_max_allowed_packet+512,stdin)))
{
free_defaults(defaults_argv);
my_end(0);
@@ -644,12 +645,12 @@ static struct my_option my_long_options[] =
0, 1},
{"max_allowed_packet", OPT_MAX_ALLOWED_PACKET,
"Max packet length to send to, or receive from server",
- (gptr*) &max_allowed_packet, (gptr*) &max_allowed_packet, 0, GET_ULONG,
+ (gptr*) &opt_max_allowed_packet, (gptr*) &opt_max_allowed_packet, 0, GET_ULONG,
REQUIRED_ARG, 16 *1024L*1024L, 4096, (longlong) 2*1024L*1024L*1024L,
MALLOC_OVERHEAD, 1024, 0},
{"net_buffer_length", OPT_NET_BUFFER_LENGTH,
"Buffer for TCP/IP and socket communication",
- (gptr*) &net_buffer_length, (gptr*) &net_buffer_length, 0, GET_ULONG,
+ (gptr*) &opt_net_buffer_length, (gptr*) &opt_net_buffer_length, 0, GET_ULONG,
REQUIRED_ARG, 16384, 1024, 512*1024*1024L, MALLOC_OVERHEAD, 1024, 0},
{"select_limit", OPT_SELECT_LIMIT,
"Automatic limit for SELECT when using --safe-updates",
@@ -839,6 +840,7 @@ static int get_options(int argc, char **argv)
{
char *tmp, *pagpoint;
int ho_error;
+ MYSQL_PARAMETERS *mysql_params= mysql_get_parameters();
tmp= (char *) getenv("MYSQL_HOST");
if (tmp)
@@ -854,9 +856,15 @@ static int get_options(int argc, char **argv)
strmov(pager, pagpoint);
strmov(default_pager, pager);
+ opt_max_allowed_packet= *mysql_params->p_max_allowed_packet;
+ opt_net_buffer_length= *mysql_params->p_net_buffer_length;
+
if ((ho_error=handle_options(&argc, &argv, my_long_options, get_one_option)))
exit(ho_error);
+ *mysql_params->p_max_allowed_packet= opt_max_allowed_packet;
+ *mysql_params->p_net_buffer_length= opt_net_buffer_length;
+
if (status.batch) /* disable pager and outfile in this case */
{
strmov(default_pager, "stdout");
@@ -1864,7 +1872,7 @@ com_go(String *buffer,char *line __attribute__((unused)))
{
*pos++= ',';
*pos++= ' ';
- pos=int2str(warnings, pos, 10);
+ pos=int10_to_str(warnings, pos, 10);
pos=strmov(pos, " warning");
if (warnings != 1)
*pos++= 's';
@@ -2529,7 +2537,7 @@ static int com_source(String *buffer, char *line)
return put_info(buff, INFO_ERROR, 0);
}
- if (!(line_buff=batch_readline_init(max_allowed_packet+512,sql_file)))
+ if (!(line_buff=batch_readline_init(opt_max_allowed_packet+512,sql_file)))
{
my_fclose(sql_file,MYF(0));
return put_info("Can't initialize batch_readline", INFO_ERROR, 0);
@@ -3082,21 +3090,21 @@ static void nice_time(double sec,char *buff,bool part_second)
{
tmp=(ulong) floor(sec/(3600.0*24));
sec-=3600.0*24*tmp;
- buff=int2str((long) tmp,buff,10);
+ buff=int10_to_str((long) tmp, buff, 10);
buff=strmov(buff,tmp > 1 ? " days " : " day ");
}
if (sec >= 3600.0)
{
tmp=(ulong) floor(sec/3600.0);
sec-=3600.0*tmp;
- buff=int2str((long) tmp,buff,10);
+ buff=int10_to_str((long) tmp, buff, 10);
buff=strmov(buff,tmp > 1 ? " hours " : " hour ");
}
if (sec >= 60.0)
{
tmp=(ulong) floor(sec/60.0);
sec-=60.0*tmp;
- buff=int2str((long) tmp,buff,10);
+ buff=int10_to_str((long) tmp, buff, 10);
buff=strmov(buff," min ");
}
if (part_second)
diff --git a/client/mysqladmin.c b/client/mysqladmin.c
index e6e90fc628c..aaed101a83e 100644
--- a/client/mysqladmin.c
+++ b/client/mysqladmin.c
@@ -509,7 +509,7 @@ static int execute_commands(MYSQL *mysql,int argc, char **argv)
!stat(pidfile, &pidfile_status))
last_modified= pidfile_status.st_mtime;
- if (mysql_shutdown(mysql))
+ if (mysql_shutdown(mysql, SHUTDOWN_DEFAULT))
{
my_printf_error(0,"shutdown failed; error: '%s'",MYF(ME_BELL),
mysql_error(mysql));
@@ -961,24 +961,24 @@ static void nice_time(ulong sec,char *buff)
{
tmp=sec/(3600L*24);
sec-=3600L*24*tmp;
- buff=int2str(tmp,buff,10);
+ buff=int10_to_str(tmp, buff, 10);
buff=strmov(buff,tmp > 1 ? " days " : " day ");
}
if (sec >= 3600L)
{
tmp=sec/3600L;
sec-=3600L*tmp;
- buff=int2str(tmp,buff,10);
+ buff=int10_to_str(tmp, buff, 10);
buff=strmov(buff,tmp > 1 ? " hours " : " hour ");
}
if (sec >= 60)
{
tmp=sec/60;
sec-=60*tmp;
- buff=int2str(tmp,buff,10);
+ buff=int10_to_str(tmp, buff, 10);
buff=strmov(buff," min ");
}
- strmov(int2str(sec,buff,10)," sec");
+ strmov(int10_to_str(sec, buff, 10)," sec");
}
diff --git a/client/mysqlbinlog.cc b/client/mysqlbinlog.cc
index 1d042f1a9a1..b1fdb3722d8 100644
--- a/client/mysqlbinlog.cc
+++ b/client/mysqlbinlog.cc
@@ -32,7 +32,6 @@
#undef MYSQL_SERVER
#include "client_priv.h"
#include <time.h>
-#include <assert.h>
#include "log_event.h"
/* That one is necessary for defines of OPTION_NO_FOREIGN_KEY_CHECKS etc */
#include "mysql_priv.h"
diff --git a/client/mysqldump.c b/client/mysqldump.c
index 0366e0da87f..dfac9ea0e7c 100644
--- a/client/mysqldump.c
+++ b/client/mysqldump.c
@@ -43,7 +43,6 @@
#include <my_sys.h>
#include <m_string.h>
#include <m_ctype.h>
-#include <assert.h>
#include "client_priv.h"
#include "mysql.h"
@@ -56,6 +55,7 @@
#define EX_MYSQLERR 2
#define EX_CONSCHECK 3
#define EX_EOM 4
+#define EX_EOF 5 /* ferror for output file was got */
/* index into 'show fields from table' */
@@ -82,7 +82,7 @@ static my_bool verbose=0,tFlag=0,cFlag=0,dFlag=0,quick= 1, extended_insert= 1,
opt_autocommit=0,opt_master_data,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;
-
+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,
*current_host=0,*path=0,*fields_terminated=0,
@@ -95,7 +95,6 @@ static ulong opt_compatible_mode= 0;
static uint opt_mysql_port= 0, err_len= 0;
static my_string opt_mysql_unix_port=0;
static int first_error=0;
-extern ulong net_buffer_length;
static DYNAMIC_STRING extended_row;
#include <sslopt-vars.h>
FILE *md_result_file;
@@ -129,6 +128,9 @@ TYPELIB compatible_mode_typelib= {array_elements(compatible_mode_names) - 1,
static struct my_option my_long_options[] =
{
+ {"all", 'a', "Deprecated. Use --create-options instead.",
+ (gptr*) &create_options, (gptr*) &create_options, 0, GET_BOOL, NO_ARG, 1,
+ 0, 0, 0, 0, 0},
{"all-databases", 'A',
"Dump all the databases. This will be same as --databases with all databases selected.",
(gptr*) &opt_alldbs, (gptr*) &opt_alldbs, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0,
@@ -241,10 +243,10 @@ static struct my_option my_long_options[] =
{"no-data", 'd', "No row information.", (gptr*) &dFlag, (gptr*) &dFlag, 0,
GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
{"no-set-names", 'N',
- "Deprecated, use --set-charset or --skip-set-charset to enable/disable charset settings instead",
+ "Deprecated. Use --skip-set-charset instead.",
0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
{"set-charset", OPT_SET_CHARSET,
- "'SET CHARACTER_SET_CLIENT=default_character_set' will be put in the output",
+ "Add 'SET NAMES default_character_set' to the output. Enabled by default; suppress with --skip-set-charset.",
(gptr*) &opt_set_charset, (gptr*) &opt_set_charset, 0, GET_BOOL, NO_ARG, 1,
0, 0, 0, 0, 0},
{"set-variable", 'O',
@@ -304,11 +306,11 @@ static struct my_option my_long_options[] =
{"xml", 'X', "Dump a database as well formed XML.", 0, 0, 0, GET_NO_ARG,
NO_ARG, 0, 0, 0, 0, 0, 0},
{"max_allowed_packet", OPT_MAX_ALLOWED_PACKET, "",
- (gptr*) &max_allowed_packet, (gptr*) &max_allowed_packet, 0,
+ (gptr*) &opt_max_allowed_packet, (gptr*) &opt_max_allowed_packet, 0,
GET_ULONG, REQUIRED_ARG, 24*1024*1024, 4096,
(longlong) 2L*1024L*1024L*1024L, MALLOC_OVERHEAD, 1024, 0},
{"net_buffer_length", OPT_NET_BUFFER_LENGTH, "",
- (gptr*) &net_buffer_length, (gptr*) &net_buffer_length, 0,
+ (gptr*) &opt_net_buffer_length, (gptr*) &opt_net_buffer_length, 0,
GET_ULONG, REQUIRED_ARG, 1024*1024L-1025, 4096, 16*1024L*1024L,
MALLOC_OVERHEAD-1024, 1024, 0},
{"comments", 'i', "Write additional information.",
@@ -334,6 +336,23 @@ static const char *check_if_ignore_table(const char *table_name);
#include <help_start.h>
+/*
+ exit with message if ferror(file)
+
+ SYNOPSIS
+ check_io()
+ file - checked file
+*/
+
+void check_io(FILE *file)
+{
+ if (ferror(file))
+ {
+ fprintf(stderr, "%s: Got errno %d on write\n", my_progname, errno);
+ safe_exit(EX_EOF);
+ }
+}
+
static void print_version(void)
{
printf("%s Ver %s Distrib %s, for %s (%s)\n",my_progname,DUMP_VERSION,
@@ -380,6 +399,7 @@ static void write_header(FILE *sql_file, char *db_name)
{
fputs("<?xml version=\"1.0\"?>\n", sql_file);
fputs("<mysqldump>\n", sql_file);
+ check_io(sql_file);
}
else if (!opt_compact)
{
@@ -395,7 +415,11 @@ static void write_header(FILE *sql_file, char *db_name)
mysql_get_server_info(&mysql_connection));
}
if (opt_set_charset)
- fprintf(sql_file,"\n/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT, CHARACTER_SET_CLIENT=%s */;\n",default_charset);
+ fprintf(sql_file,
+"\n/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;"
+"\n/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;"
+"\n/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;"
+"\n/*!40101 SET NAMES %s */;\n",default_charset);
if (!path)
{
fprintf(md_result_file,"\
@@ -407,6 +431,7 @@ static void write_header(FILE *sql_file, char *db_name)
"/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE=\"%s%s%s\" */;\n",
path?"":"NO_AUTO_VALUE_ON_ZERO",compatible_mode_normal_str[0]==0?"":",",
compatible_mode_normal_str);
+ check_io(sql_file);
}
} /* write_header */
@@ -414,7 +439,10 @@ static void write_header(FILE *sql_file, char *db_name)
static void write_footer(FILE *sql_file)
{
if (opt_xml)
+ {
fputs("</mysqldump>\n", sql_file);
+ check_io(sql_file);
+ }
else if (!opt_compact)
{
fprintf(sql_file,"\n/*!40101 SET SQL_MODE=@OLD_SQL_MODE */;\n");
@@ -426,8 +454,11 @@ static void write_footer(FILE *sql_file)
}
if (opt_set_charset)
fprintf(sql_file,
- "/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;\n");
+"/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;\n"
+"/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;\n"
+"/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;\n");
fputs("\n", sql_file);
+ check_io(sql_file);
}
} /* write_footer */
@@ -566,6 +597,10 @@ get_one_option(int optid, const struct my_option *opt __attribute__((unused)),
static int get_options(int *argc, char ***argv)
{
int ho_error;
+ MYSQL_PARAMETERS *mysql_params= mysql_get_parameters();
+
+ opt_max_allowed_packet= *mysql_params->p_max_allowed_packet;
+ opt_net_buffer_length= *mysql_params->p_net_buffer_length;
md_result_file= stdout;
load_defaults("my",load_default_groups,argc,argv);
@@ -573,6 +608,9 @@ static int get_options(int *argc, char ***argv)
if ((ho_error=handle_options(argc, argv, my_long_options, get_one_option)))
exit(ho_error);
+ *mysql_params->p_max_allowed_packet= opt_max_allowed_packet;
+ *mysql_params->p_net_buffer_length= opt_net_buffer_length;
+
if (opt_delayed)
opt_lock=0; /* Can't have lock with delayed */
if (!path && (enclosed || opt_enclosed || escaped || lines_terminated ||
@@ -714,6 +752,7 @@ static void unescape(FILE *file,char *pos,uint length)
fputc('\'', file);
fputs(tmp, file);
fputc('\'', file);
+ check_io(file);
my_free(tmp, MYF(MY_WME));
DBUG_VOID_RETURN;
} /* unescape */
@@ -805,6 +844,7 @@ static void print_quoted_xml(FILE *xml_file, const char *str, ulong len)
break;
}
}
+ check_io(xml_file);
}
@@ -838,6 +878,7 @@ static void print_xml_tag1(FILE * xml_file, const char* sbeg,
print_quoted_xml(xml_file, sval, strlen(sval));
fputs("\">", xml_file);
fputs(send, xml_file);
+ check_io(xml_file);
}
@@ -866,6 +907,7 @@ static void print_xml_row(FILE *xml_file, const char *row_name,
ulong *lengths= mysql_fetch_lengths(tableRes);
fprintf(xml_file, "\t\t<%s", row_name);
+ check_io(xml_file);
mysql_field_seek(tableRes, 0);
for (i= 0; (field= mysql_fetch_field(tableRes)); i++)
{
@@ -876,9 +918,11 @@ static void print_xml_row(FILE *xml_file, const char *row_name,
fputs("=\"", xml_file);
print_quoted_xml(xml_file, (*row)[i], lengths[i]);
fputc('"', xml_file);
+ check_io(xml_file);
}
}
fputs(" />\n", xml_file);
+ check_io(xml_file);
}
/*
@@ -945,14 +989,21 @@ static uint getTableStructure(char *table, char* db)
write_header(sql_file, db);
}
if (!opt_xml && opt_comments)
+ {
fprintf(sql_file, "\n--\n-- Table structure for table %s\n--\n\n",
result_table);
+ check_io(sql_file);
+ }
if (opt_drop)
+ {
fprintf(sql_file, "DROP TABLE IF EXISTS %s;\n", opt_quoted_table);
+ check_io(sql_file);
+ }
tableRes=mysql_store_result(sock);
row=mysql_fetch_row(tableRes);
fprintf(sql_file, "%s;\n", row[1]);
+ check_io(sql_file);
mysql_free_result(tableRes);
}
sprintf(insert_pat,"show fields from %s", result_table);
@@ -1032,6 +1083,7 @@ static uint getTableStructure(char *table, char* db)
fprintf(sql_file, "CREATE TABLE %s (\n", result_table);
else
print_xml_tag1(sql_file, "\t", "table_structure name=", table, "\n");
+ check_io(sql_file);
}
if (cFlag)
sprintf(insert_pat, "INSERT %sINTO %s (", delayed, result_table);
@@ -1049,7 +1101,10 @@ static uint getTableStructure(char *table, char* db)
if (init)
{
if (!opt_xml && !tFlag)
+ {
fputs(",\n",sql_file);
+ check_io(sql_file);
+ }
if (cFlag)
strpos=strmov(strpos,", ");
}
@@ -1081,6 +1136,7 @@ static uint getTableStructure(char *table, char* db)
fputs(" NOT NULL", sql_file);
if (row[SHOW_EXTRA][0])
fprintf(sql_file, " %s",row[SHOW_EXTRA]);
+ check_io(sql_file);
}
}
numFields = (uint) mysql_num_rows(tableRes);
@@ -1149,12 +1205,14 @@ static uint getTableStructure(char *table, char* db)
fputs(quote_name(row[4], name_buff, 0), sql_file);
if (row[7])
fprintf(sql_file, " (%s)",row[7]); /* Sub key */
+ check_io(sql_file);
}
if (!opt_xml)
{
if (keynr)
putc(')', sql_file);
fputs("\n)",sql_file);
+ check_io(sql_file);
}
/* Get MySQL specific create options */
@@ -1193,6 +1251,7 @@ static uint getTableStructure(char *table, char* db)
print_value(sql_file,tableRes,row,"","Create_options",0);
print_value(sql_file,tableRes,row,"comment=","Comment",1);
fputs(" */",sql_file);
+ check_io(sql_file);
}
}
mysql_free_result(tableRes); /* Is always safe to free */
@@ -1201,6 +1260,7 @@ static uint getTableStructure(char *table, char* db)
fputs(";\n", sql_file);
else
fputs("\t</table_structure>\n", sql_file);
+ check_io(sql_file);
}
}
if (cFlag)
@@ -1354,19 +1414,28 @@ static void dumpTable(uint numFields, char *table)
else
{
if (!opt_xml && opt_comments)
+ {
fprintf(md_result_file,"\n--\n-- Dumping data for table %s\n--\n",
result_table);
+ check_io(md_result_file);
+ }
sprintf(query, "SELECT /*!40001 SQL_NO_CACHE */ * FROM %s",
result_table);
if (where)
{
if (!opt_xml && opt_comments)
+ {
fprintf(md_result_file,"-- WHERE: %s\n",where);
+ check_io(md_result_file);
+ }
query= alloc_query_str((ulong) (strlen(where) + strlen(query) + 10));
strxmov(query, query_buf, " WHERE ", where, NullS);
}
if (!opt_xml && !opt_compact)
+ {
fputs("\n", md_result_file);
+ check_io(md_result_file);
+ }
if (mysql_query(sock, query))
{
DBerror(sock, "when retrieving data from server");
@@ -1394,12 +1463,18 @@ static void dumpTable(uint numFields, char *table)
}
if (opt_disable_keys)
+ {
fprintf(md_result_file, "\n/*!40000 ALTER TABLE %s DISABLE KEYS */;\n",
opt_quoted_table);
+ check_io(md_result_file);
+ }
if (opt_lock)
+ {
fprintf(md_result_file,"LOCK TABLES %s WRITE;\n", opt_quoted_table);
+ check_io(md_result_file);
+ }
- total_length=net_buffer_length; /* Force row break */
+ total_length= opt_net_buffer_length; /* Force row break */
row_break=0;
rownr=0;
init_length=(uint) strlen(insert_pat)+4;
@@ -1407,7 +1482,10 @@ static void dumpTable(uint numFields, char *table)
print_xml_tag1(md_result_file, "\t", "table_data name=", table, "\n");
if (opt_autocommit)
+ {
fprintf(md_result_file, "set autocommit=0;\n");
+ check_io(md_result_file);
+ }
while ((row=mysql_fetch_row(res)))
{
@@ -1415,11 +1493,17 @@ static void dumpTable(uint numFields, char *table)
ulong *lengths=mysql_fetch_lengths(res);
rownr++;
if (!extended_insert && !opt_xml)
+ {
fputs(insert_pat,md_result_file);
+ check_io(md_result_file);
+ }
mysql_field_seek(res,0);
if (opt_xml)
+ {
fputs("\t<row>\n", md_result_file);
+ check_io(md_result_file);
+ }
for (i = 0; i < mysql_num_fields(res); i++)
{
@@ -1492,7 +1576,10 @@ static void dumpTable(uint numFields, char *table)
else
{
if (i && !opt_xml)
+ {
fputc(',', md_result_file);
+ check_io(md_result_file);
+ }
if (row[i])
{
if (!IS_NUM_FIELD(field))
@@ -1533,18 +1620,24 @@ static void dumpTable(uint numFields, char *table)
fputs(ptr, md_result_file);
}
}
+ else
+ fputs("NULL", md_result_file);
+ check_io(md_result_file);
}
}
if (opt_xml)
+ {
fputs("\t</row>\n", md_result_file);
+ check_io(md_result_file);
+ }
if (extended_insert)
{
ulong row_length;
dynstr_append(&extended_row,")");
row_length = 2 + extended_row.length;
- if (total_length + row_length < net_buffer_length)
+ if (total_length + row_length < opt_net_buffer_length)
{
total_length += row_length;
fputc(',',md_result_file); /* Always row break */
@@ -1560,9 +1653,13 @@ static void dumpTable(uint numFields, char *table)
fputs(extended_row.str,md_result_file);
total_length = row_length+init_length;
}
+ check_io(md_result_file);
}
else if (!opt_xml)
+ {
fputs(");\n", md_result_file);
+ check_io(md_result_file);
+ }
}
/* XML - close table tag and supress regular output */
@@ -1571,6 +1668,7 @@ static void dumpTable(uint numFields, char *table)
else if (extended_insert && row_break)
fputs(";\n", md_result_file); /* If not empty table */
fflush(md_result_file);
+ check_io(md_result_file);
if (mysql_errno(sock))
{
sprintf(query,"%s: Error %d: %s when dumping table %s at row: %ld\n",
@@ -1584,12 +1682,21 @@ static void dumpTable(uint numFields, char *table)
goto err;
}
if (opt_lock)
+ {
fputs("UNLOCK TABLES;\n", md_result_file);
+ check_io(md_result_file);
+ }
if (opt_disable_keys)
+ {
fprintf(md_result_file,"/*!40000 ALTER TABLE %s ENABLE KEYS */;\n",
opt_quoted_table);
+ check_io(md_result_file);
+ }
if (opt_autocommit)
+ {
fprintf(md_result_file, "commit;\n");
+ check_io(md_result_file);
+ }
mysql_free_result(res);
if (query != query_buf)
my_free(query, MYF(MY_ALLOW_ZERO_PTR));
@@ -1680,7 +1787,10 @@ static int init_dumping(char *database)
char quoted_database_buf[64*2+3];
char *qdatabase= quote_name(database,quoted_database_buf,opt_quoted);
if (opt_comments)
+ {
fprintf(md_result_file,"\n--\n-- Current Database: %s\n--\n", qdatabase);
+ check_io(md_result_file);
+ }
if (!opt_create_db)
{
char qbuf[256];
@@ -1707,6 +1817,7 @@ static int init_dumping(char *database)
}
}
fprintf(md_result_file,"\nUSE %s;\n", qdatabase);
+ check_io(md_result_file);
}
}
if (extended_insert && init_dynamic_string(&extended_row, "", 1024, 1024))
@@ -1753,7 +1864,10 @@ static int dump_all_tables_in_db(char *database)
dumpTable(numrows,table);
}
if (opt_xml)
+ {
fputs("</database>\n", md_result_file);
+ check_io(md_result_file);
+ }
if (lock_tables)
mysql_query(sock,"UNLOCK TABLES");
return 0;
@@ -1799,7 +1913,10 @@ static int dump_selected_tables(char *db, char **table_names, int tables)
dumpTable(numrows, *table_names);
}
if (opt_xml)
+ {
fputs("</database>\n", md_result_file);
+ check_io(md_result_file);
+ }
if (lock_tables)
mysql_query(sock,"UNLOCK TABLES");
return 0;
@@ -1868,6 +1985,7 @@ static void print_value(FILE *file, MYSQL_RES *result, MYSQL_ROW row,
unescape(file,row[0],(uint) strlen(row[0]));
else
fputs(row[0], file);
+ check_io(file);
return;
}
}
@@ -2007,6 +2125,7 @@ int main(int argc, char **argv)
fprintf(md_result_file,
"CHANGE MASTER TO MASTER_LOG_FILE='%s', \
MASTER_LOG_POS=%s ;\n",row[0],row[1]);
+ check_io(md_result_file);
}
mysql_free_result(master);
}
diff --git a/client/mysqltest.c b/client/mysqltest.c
index be2270850fa..5ba4ad7336c 100644
--- a/client/mysqltest.c
+++ b/client/mysqltest.c
@@ -59,7 +59,8 @@
#include <sys/stat.h>
#include <violite.h>
-#define MAX_QUERY 65536
+#define MAX_QUERY 131072
+#define MAX_VAR_NAME 256
#define MAX_COLUMNS 256
#define PAD_SIZE 128
#define MAX_CONS 128
@@ -187,7 +188,7 @@ typedef struct
*/
static char *subst_env_var(const char *cmd);
-static int my_popen(const char *cmd, const char *mode);
+static FILE *my_popen(const char *cmd, const char *mode);
#define popen(A,B) my_popen((A),(B))
#endif /* __NETWARE__ */
@@ -223,7 +224,7 @@ Q_ENABLE_QUERY_LOG, Q_DISABLE_QUERY_LOG,
Q_ENABLE_RESULT_LOG, Q_DISABLE_RESULT_LOG,
Q_SERVER_START, Q_SERVER_STOP,Q_REQUIRE_MANAGER,
Q_WAIT_FOR_SLAVE_TO_STOP,
-Q_REQUIRE_VERSION,
+Q_REQUIRE_VERSION, Q_REQUIRE_OS,
Q_ENABLE_WARNINGS, Q_DISABLE_WARNINGS,
Q_ENABLE_INFO, Q_DISABLE_INFO,
Q_ENABLE_METADATA, Q_DISABLE_METADATA,
@@ -297,6 +298,7 @@ const char *command_names[]=
"require_manager",
"wait_for_slave_to_stop",
"require_version",
+ "require_os",
"enable_warnings",
"disable_warnings",
"enable_info",
@@ -318,6 +320,7 @@ TYPELIB command_typelib= {array_elements(command_names),"",
DYNAMIC_STRING ds_res;
static void die(const char *fmt, ...);
static void init_var_hash();
+static VAR* var_from_env(const char *, const char *);
static byte* get_var_key(const byte* rec, uint* len,
my_bool __attribute__((unused)) t);
static VAR* var_init(VAR* v, const char *name, int name_len, const char *val,
@@ -385,6 +388,7 @@ static void do_eval(DYNAMIC_STRING* query_eval, const char* query)
register char c;
register int escaped = 0;
VAR* v;
+ DBUG_ENTER("do_eval");
for (p= query; (c = *p); ++p)
{
@@ -416,6 +420,7 @@ static void do_eval(DYNAMIC_STRING* query_eval, const char* query)
break;
}
}
+ DBUG_VOID_RETURN;
}
@@ -627,6 +632,7 @@ static int check_result(DYNAMIC_STRING* ds, const char* fname,
return error;
}
+
VAR* var_get(const char* var_name, const char** var_name_end, my_bool raw,
my_bool ignore_not_existing)
{
@@ -641,26 +647,26 @@ VAR* var_get(const char* var_name, const char** var_name_end, my_bool raw,
if (!(digit < 10 && digit >= 0))
{
const char* save_var_name = var_name, *end;
+ uint length;
end = (var_name_end) ? *var_name_end : 0;
while (my_isvar(charset_info,*var_name) && var_name != end)
- ++var_name;
+ var_name++;
if (var_name == save_var_name)
{
if (ignore_not_existing)
DBUG_RETURN(0);
die("Empty variable");
}
+ length= (uint) (var_name - save_var_name);
- if (!(v = (VAR*) hash_search(&var_hash, save_var_name,
- var_name - save_var_name)))
+ if (!(v = (VAR*) hash_search(&var_hash, save_var_name, length)) &&
+ length < MAX_VAR_NAME)
{
- if (ignore_not_existing)
- DBUG_RETURN(0);
- if (end)
- *(char*) end = 0;
- die("Variable '%s' used uninitialized", save_var_name);
+ char buff[MAX_VAR_NAME+1];
+ strmake(buff, save_var_name, length);
+ v= var_from_env(buff, "");
}
- --var_name; /* Point at last character */
+ var_name--; /* Point at last character */
}
else
v = var_reg + digit;
@@ -848,6 +854,27 @@ int do_require_version(struct st_query* q)
return 0;
}
+int do_require_os(struct st_query* q)
+{
+ char *p=q->first_argument, *os_arg;
+ DBUG_ENTER("do_require_os");
+
+ if (!*p)
+ die("Missing version argument in require_os\n");
+ os_arg= p;
+ while (*p && !my_isspace(charset_info,*p))
+ p++;
+ *p = 0;
+
+ if (strcmp(os_arg, "unix"))
+ die("For now only testing of os=unix is implemented\n");
+
+#if defined(__NETWARE__) || defined(__WIN__) || defined(__OS2__)
+ abort_not_supported_test();
+#endif
+ DBUG_RETURN(0);
+}
+
int do_source(struct st_query* q)
{
char* p=q->first_argument, *name;
@@ -1737,6 +1764,7 @@ int read_line(char* buf, int size)
enum {R_NORMAL, R_Q1, R_ESC_Q_Q1, R_ESC_Q_Q2,
R_ESC_SLASH_Q1, R_ESC_SLASH_Q2,
R_Q2, R_COMMENT, R_LINE_START} state= R_LINE_START;
+ DBUG_ENTER("read_line");
start_lineno= *lineno;
for (; p < buf_end ;)
@@ -1750,7 +1778,7 @@ int read_line(char* buf, int size)
cur_file--;
lineno--;
if (cur_file == file_stack)
- return 1;
+ DBUG_RETURN(1);
continue;
}
@@ -1760,7 +1788,7 @@ int read_line(char* buf, int size)
if (end_of_query(c))
{
*p= 0;
- return 0;
+ DBUG_RETURN(0);
}
else if (c == '\'')
state = R_Q1;
@@ -1777,7 +1805,7 @@ int read_line(char* buf, int size)
{
*p= 0;
(*lineno)++;
- return 0;
+ DBUG_RETURN(0);
}
break;
case R_LINE_START:
@@ -1795,12 +1823,12 @@ int read_line(char* buf, int size)
{
*buf++= '}';
*buf= 0;
- return 0;
+ DBUG_RETURN(0);
}
else if (end_of_query(c) || c == '{')
{
*p= 0;
- return 0;
+ DBUG_RETURN(0);
}
else if (c == '\'')
state= R_Q1;
@@ -1820,7 +1848,7 @@ int read_line(char* buf, int size)
if (end_of_query(c))
{
*p= 0;
- return 0;
+ DBUG_RETURN(0);
}
if (c != '\'')
state= R_NORMAL;
@@ -1841,7 +1869,7 @@ int read_line(char* buf, int size)
if (end_of_query(c))
{
*p= 0;
- return 0;
+ DBUG_RETURN(0);
}
if (c != '"')
state= R_NORMAL;
@@ -1857,7 +1885,7 @@ int read_line(char* buf, int size)
*p++= c;
}
*p= 0; /* Always end with \0 */
- return feof(*cur_file);
+ DBUG_RETURN(feof(*cur_file));
}
@@ -1892,8 +1920,11 @@ int read_query(struct st_query** q_ptr)
q->type = Q_UNKNOWN;
q->query_buf= q->query= 0;
if (read_line(read_query_buf, sizeof(read_query_buf)))
+ {
+ DBUG_PRINT("warning",("too long query"));
DBUG_RETURN(1);
-
+ }
+ DBUG_PRINT("info", ("query: %s", read_query_buf));
if (*p == '#')
{
q->type = Q_COMMENT;
@@ -2259,6 +2290,7 @@ int run_query(MYSQL* mysql, struct st_query* q, int flags)
char* query;
int query_len, got_error_on_send= 0;
DBUG_ENTER("run_query");
+ DBUG_PRINT("enter",("flags: %d", flags));
if (q->type != Q_EVAL)
{
@@ -2580,7 +2612,7 @@ static void var_free(void *v)
}
-static void var_from_env(const char *name, const char *def_val)
+static VAR* var_from_env(const char *name, const char *def_val)
{
const char *tmp;
VAR *v;
@@ -2589,6 +2621,7 @@ static void var_from_env(const char *name, const char *def_val)
v = var_init(0, name, 0, tmp, 0);
my_hash_insert(&var_hash, (byte*)v);
+ return v;
}
@@ -2599,10 +2632,8 @@ static void init_var_hash(MYSQL *mysql)
if (hash_init(&var_hash, charset_info,
1024, 0, 0, get_var_key, var_free, MYF(0)))
die("Variable hash initialization failed");
- var_from_env("MASTER_MYPORT", "9306");
- var_from_env("SLAVE_MYPORT", "9307");
- var_from_env("MYSQL_TEST_DIR", "/tmp");
- var_from_env("BIG_TEST", opt_big_test ? "1" : "0");
+ if (opt_big_test)
+ my_hash_insert(&var_hash, (byte*) var_init(0,"BIG_TEST", 0, "1",0));
v= var_init(0,"MAX_TABLES", 0, (sizeof(ulong) == 4) ? "31" : "62",0);
my_hash_insert(&var_hash, (byte*) v);
v= var_init(0,"SERVER_VERSION", 0, mysql_get_server_info(mysql), 0);
@@ -2706,6 +2737,7 @@ int main(int argc, char **argv)
case Q_SLEEP: do_sleep(q, 0); break;
case Q_REAL_SLEEP: do_sleep(q, 1); break;
case Q_REQUIRE_VERSION: do_require_version(q); break;
+ case Q_REQUIRE_OS: do_require_os(q); break;
case Q_WAIT_FOR_SLAVE_TO_STOP: do_wait_for_slave_to_stop(q); break;
case Q_REQUIRE_MANAGER: do_require_manager(q); break;
#ifndef EMBEDDED_LIBRARY
@@ -2727,7 +2759,10 @@ int main(int argc, char **argv)
case Q_EVAL_RESULT: eval_result = 1; break;
case Q_EVAL:
if (q->query == q->query_buf)
+ {
q->query= q->first_argument;
+ q->first_word_len= 0;
+ }
/* fall through */
case Q_QUERY_VERTICAL:
case Q_QUERY_HORIZONTAL:
@@ -2737,13 +2772,16 @@ int main(int argc, char **argv)
{
/* This happens when we use 'query_..' on it's own line */
q_send_flag=1;
+ DBUG_PRINT("info",
+ ("query: '%s' first_word_len: %d send_flag=1",
+ q->query, q->first_word_len));
break;
}
/* fix up query pointer if this is * first iteration for this line */
if (q->query == q->query_buf)
q->query += q->first_word_len + 1;
display_result_vertically= (q->type==Q_QUERY_VERTICAL);
- error |= run_query(&cur_con->mysql, q, QUERY_REAP|QUERY_SEND);
+ error|= run_query(&cur_con->mysql, q, QUERY_REAP|QUERY_SEND);
display_result_vertically= old_display_result_vertically;
break;
}
@@ -3710,6 +3748,7 @@ static void get_replace_column(struct st_query *q)
static char *subst_env_var(const char *str)
{
char *result;
+ char *pos;
result= pos= my_malloc(MAX_QUERY, MYF(MY_FAE));
while (*str)
@@ -3729,7 +3768,7 @@ static char *subst_env_var(const char *str)
*str && !isspace(*str) && *str != '\\' && *str != '/' &&
*str != '$';
str++)
- *env_pos++ *str;
+ *env_pos++= *str;
*env_pos= 0;
if (!(subst= getenv(env_var)))
@@ -3772,11 +3811,11 @@ static char *subst_env_var(const char *str)
#undef popen /* Remove wrapper */
-int my_popen(const char *cmd, const char *mode __attribute__((unused)) t)
+FILE *my_popen(const char *cmd, const char *mode __attribute__((unused)))
{
char *subst_cmd;
- int res_file;
-
+ FILE *res_file;
+
subst_cmd= subst_env_var(cmd);
res_file= popen(subst_cmd, "r0");
my_free(subst_cmd, MYF(0));