Skip to content

Commit c0f40d1

Browse files
author
monty@donna.mysql.com
committed
Added support for hex strings to mysqlimport
A lot of new tests to mysqltest Fixed bug with BDB tables and autocommit
1 parent 361067e commit c0f40d1

File tree

215 files changed

+8596
-528
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

215 files changed

+8596
-528
lines changed

Docs/manual.texi

+3
Original file line numberDiff line numberDiff line change
@@ -40050,6 +40050,9 @@ though, so Version 3.23 is not released as a stable version yet.
4005040050
@appendixsubsec Changes in release 3.23.30
4005140051
@itemize @bullet
4005240052
@item
40053+
Allow hex constants in the @code{--fields-*-by} and
40054+
@code{--lines-terminated-by} options to @code{mysqldump}. By Paul DuBois.
40055+
@item
4005340056
Added option @code{--safe-show-databases}.
4005440057
@item
4005540058
Added @code{have_bdb}, @code{have_gemini}, @code{have_innobase},

client/mysqlimport.c

+8-3
Original file line numberDiff line numberDiff line change
@@ -456,9 +456,14 @@ static char *add_load_option(char *ptr,const char *object,const char *statement)
456456
{
457457
if (object)
458458
{
459-
ptr= strxmov(ptr," ",statement," '",NullS);
460-
ptr= field_escape(ptr,object,(uint) strlen(object));
461-
*ptr++= '\'';
459+
if (!strncasecmp(object,"0x",2)) /* hex constant; don't escape */
460+
ptr= strxmov(ptr," ",statement," ",object,NullS);
461+
else /* char constant; escape */
462+
{
463+
ptr= strxmov(ptr," ",statement," '",NullS);
464+
ptr= field_escape(ptr,object,(uint) strlen(object));
465+
*ptr++= '\'';
466+
}
462467
}
463468
return ptr;
464469
}

client/mysqltest.c

+44-24
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@
2020
* Written by:
2121
* Sasha Pachev <sasha@mysql.com>
2222
* Matt Wagner <matt@mysql.com>
23-
*
23+
* Monty
2424
**/
2525

26-
#define MTEST_VERSION "1.1"
26+
#define MTEST_VERSION "1.2"
2727

2828
#include "global.h"
2929
#include "my_sys.h"
@@ -41,7 +41,7 @@
4141
#include <unistd.h>
4242
#include <errno.h>
4343

44-
#define MAX_QUERY 16384
44+
#define MAX_QUERY 65536
4545
#define PAD_SIZE 128
4646
#define MAX_CONS 1024
4747
#define MAX_INCLUDE_DEPTH 16
@@ -51,15 +51,17 @@
5151
#define BLOCK_STACK_DEPTH 32
5252

5353
int record = 0, verbose = 0, silent = 0;
54-
const char* record_mode = "r";
5554
static char *db = 0, *pass=0;
5655
const char* user = 0, *host = 0, *unix_sock = 0;
5756
int port = 0;
57+
static uint start_lineno, *lineno;
58+
5859
static const char *load_default_groups[]= { "mysqltest","client",0 };
5960

6061
FILE* file_stack[MAX_INCLUDE_DEPTH];
6162
FILE** cur_file;
6263
FILE** file_stack_end;
64+
uint lineno_stack[MAX_INCLUDE_DEPTH];
6365

6466
int block_stack[BLOCK_STACK_DEPTH];
6567
int *cur_block, *block_stack_end;
@@ -182,7 +184,7 @@ static void verbose_msg(const char* fmt, ...)
182184

183185
va_start(args, fmt);
184186

185-
fprintf(stderr, "%s: ", my_progname);
187+
fprintf(stderr, "%s: At line %u: ", my_progname, start_lineno);
186188
vfprintf(stderr, fmt, args);
187189
fprintf(stderr, "\n");
188190
va_end(args);
@@ -365,6 +367,7 @@ int open_file(const char* name)
365367
die("Source directives are nesting too deep");
366368
if (!(*cur_file = my_fopen(name, O_RDONLY, MYF(MY_WME))))
367369
die("Could not read '%s': errno %d\n", name, errno);
370+
*++lineno=1;
368371

369372
return 0;
370373
}
@@ -751,6 +754,7 @@ int read_line(char* buf, int size)
751754
R_ESC_SLASH_Q1, R_ESC_SLASH_Q2,
752755
R_Q2, R_COMMENT, R_LINE_START} state = R_LINE_START;
753756

757+
start_lineno= *lineno;
754758
for (; p < buf_end ;)
755759
{
756760
no_save = 0;
@@ -764,15 +768,15 @@ int read_line(char* buf, int size)
764768
else
765769
{
766770
cur_file--;
771+
lineno--;
767772
continue;
768773
}
769774
}
770775

771776
switch(state) {
772777
case R_NORMAL:
773-
if (c == ';' || c == '{') /* '{' allows some interesting syntax
774-
* but we don't care, as long as the
775-
* correct sytnax gets parsed right */
778+
/* Only accept '{' in the beginning of a line */
779+
if (c == ';')
776780
{
777781
*p = 0;
778782
return 0;
@@ -782,13 +786,16 @@ int read_line(char* buf, int size)
782786
else if (c == '"')
783787
state = R_Q2;
784788
else if (c == '\n')
789+
{
785790
state = R_LINE_START;
786-
791+
(*lineno)++;
792+
}
787793
break;
788794
case R_COMMENT:
789795
if (c == '\n')
790796
{
791797
*p=0;
798+
(*lineno)++;
792799
return 0;
793800
}
794801
break;
@@ -798,7 +805,11 @@ int read_line(char* buf, int size)
798805
state = R_COMMENT;
799806
}
800807
else if (isspace(c))
808+
{
809+
if (c == '\n')
810+
start_lineno= ++*lineno; /* Query hasn't started yet */
801811
no_save = 1;
812+
}
802813
else if (c == '}')
803814
{
804815
*buf++ = '}';
@@ -828,6 +839,8 @@ int read_line(char* buf, int size)
828839
}
829840
if (c != '\'')
830841
state = R_NORMAL;
842+
else
843+
state = R_Q1;
831844
break;
832845
case R_ESC_SLASH_Q1:
833846
state = R_Q1;
@@ -847,6 +860,8 @@ int read_line(char* buf, int size)
847860
}
848861
if (c != '"')
849862
state = R_NORMAL;
863+
else
864+
state = R_Q2;
850865
break;
851866
case R_ESC_SLASH_Q2:
852867
state = R_Q2;
@@ -860,12 +875,14 @@ int read_line(char* buf, int size)
860875
return feof(*cur_file);
861876
}
862877

878+
static char read_query_buf[MAX_QUERY];
879+
863880
int read_query(struct query** q_ptr)
864881
{
865-
char buf[MAX_QUERY];
866-
char* p = buf,* p1 ;
882+
char* p = read_query_buf, * p1 ;
867883
int c, expected_errno;
868884
struct query* q;
885+
869886
if (parser.current_line < parser.read_lines)
870887
{
871888
get_dynamic(&q_lines, (gptr)q_ptr, parser.current_line) ;
@@ -882,7 +899,7 @@ int read_query(struct query** q_ptr)
882899
q->first_word_len = 0;
883900
q->expected_errno = 0;
884901
q->type = Q_UNKNOWN;
885-
if (read_line(buf, sizeof(buf)))
902+
if (read_line(read_query_buf, sizeof(read_query_buf)))
886903
return 1;
887904

888905
if (*p == '#')
@@ -961,7 +978,7 @@ static void print_version(void)
961978
void usage()
962979
{
963980
print_version();
964-
printf("MySQL AB, by Sasha & Matt\n");
981+
printf("MySQL AB, by Sasha, Matt & Monty\n");
965982
printf("This software comes with ABSOLUTELY NO WARRANTY\n\n");
966983
printf("Runs a test against the mysql server and compares output with a results file.\n\n");
967984
printf("Usage: %s [OPTIONS] [database] < test_file\n", my_progname);
@@ -975,7 +992,7 @@ void usage()
975992
-P, --port=... Port number to use for connection.\n\
976993
-S, --socket=... Socket file to use for connection.\n\
977994
-r, --record Record output of test_file into result file.\n\
978-
-R, --result-file=... Store result in this file\n\
995+
-R, --result-file=... Read/Store result from/in this file\n\
979996
-v, --verbose Write more.\n\
980997
-q, --quiet, --silent Suppress all normal output.\n\
981998
-V, --version Output version information and exit.\n\n");
@@ -997,7 +1014,6 @@ int parse_args(int argc, char **argv)
9971014
break;
9981015
case 'r':
9991016
record = 1;
1000-
record_mode = "w";
10011017
break;
10021018
case 'u':
10031019
user = optarg;
@@ -1069,7 +1085,8 @@ char* safe_str_append(char* buf, const char* str, int size)
10691085
void str_to_file(const char* fname, char* str, int size)
10701086
{
10711087
int fd;
1072-
if ((fd = my_open(fname, O_WRONLY|O_CREAT, MYF(MY_WME | MY_FFNF))) < 0)
1088+
if ((fd = my_open(fname, O_WRONLY | O_CREAT | O_TRUNC,
1089+
MYF(MY_WME | MY_FFNF))) < 0)
10731090
die("Could not open %s: errno = %d", fname, errno);
10741091
if (my_write(fd, (byte*)str, size, MYF(MY_WME|MY_FNABP)))
10751092
die("write failed");
@@ -1079,8 +1096,6 @@ void str_to_file(const char* fname, char* str, int size)
10791096
void reject_dump(const char* record_file, char* buf, int size)
10801097
{
10811098
char reject_file[FN_REFLEN];
1082-
char* p;
1083-
10841099
if (strlen(record_file) >= FN_REFLEN-8)
10851100
die("too long path name for reject");
10861101
strmov(strmov(reject_file, record_file),".reject");
@@ -1111,7 +1126,8 @@ int run_query(MYSQL* mysql, struct query* q)
11111126
if (q->require_file)
11121127
abort_not_supported_test();
11131128
if (q->abort_on_error)
1114-
die("query '%s' failed: %s", q->q, mysql_error(mysql));
1129+
die("At line %u: query '%s' failed: %d: %s", start_lineno, q->q,
1130+
mysql_errno(mysql), mysql_error(mysql));
11151131
else
11161132
{
11171133
if (q->expected_errno)
@@ -1123,7 +1139,8 @@ int run_query(MYSQL* mysql, struct query* q)
11231139
goto end;
11241140
}
11251141

1126-
verbose_msg("query '%s' failed: %s", q->q, mysql_error(mysql));
1142+
verbose_msg("query '%s' failed: %d: %s", q->q, mysql_errno(mysql),
1143+
mysql_error(mysql));
11271144
/* if we do not abort on error, failure to run the query does
11281145
not fail the whole test case
11291146
*/
@@ -1145,10 +1162,12 @@ int run_query(MYSQL* mysql, struct query* q)
11451162
if (q->require_file)
11461163
abort_not_supported_test();
11471164
if (q->abort_on_error)
1148-
die("failed in mysql_store_result for query '%s'", q->q);
1165+
die("At line %u: Failed in mysql_store_result for query '%s' (%d)",
1166+
start_lineno, q->q, mysql_errno(mysql));
11491167
else
11501168
{
1151-
verbose_msg("failed in mysql_store_result for query '%s'", q->q);
1169+
verbose_msg("failed in mysql_store_result for query '%s' (%d)", q->q,
1170+
mysql_errno(mysql));
11521171
error = 1;
11531172
goto end;
11541173
}
@@ -1193,7 +1212,7 @@ int run_query(MYSQL* mysql, struct query* q)
11931212
if (record)
11941213
{
11951214
if (!q->record_file[0] && !result_file)
1196-
die("Missing result file");
1215+
die("At line %u: Missing result file", start_lineno);
11971216
if (!result_file)
11981217
str_to_file(q->record_file, ds->str, ds->len);
11991218
}
@@ -1247,6 +1266,7 @@ int main(int argc, char** argv)
12471266
memset(file_stack, 0, sizeof(file_stack));
12481267
file_stack_end = file_stack + MAX_INCLUDE_DEPTH;
12491268
cur_file = file_stack;
1269+
lineno = lineno_stack;
12501270
init_dynamic_array(&q_lines, sizeof(struct query*), INIT_Q_LINES,
12511271
INIT_Q_LINES);
12521272
memset(block_stack, 0, sizeof(block_stack));
@@ -1256,7 +1276,7 @@ int main(int argc, char** argv)
12561276
parse_args(argc, argv);
12571277
if (!*cur_file)
12581278
*cur_file = stdin;
1259-
1279+
*lineno=1;
12601280

12611281
if (!( mysql_init(&cur_con->mysql)))
12621282
die("Failed in mysql_init()");

mysql-test/mysql-test-run.sh

+5-3
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
DB=test
1010
DBUSER=test
1111
DBPASSWD=
12+
VERBOSE=""
1213

1314
# Are we on source or binary distribution?
1415

@@ -140,6 +141,7 @@ while test $# -gt 0; do
140141
case "$1" in
141142
--force ) FORCE=1 ;;
142143
--record ) RECORD=1 ;;
144+
--verbose) MYSQL_TEST="$MYSQL_TEST -v";;
143145
--gcov )
144146
if [ x$BINARY_DIST = x1 ] ; then
145147
echo "Cannot do coverage test without the source - please use source dist"
@@ -447,7 +449,7 @@ run_testcase ()
447449
< $tf 2> $TIMEFILE`
448450
res=$?
449451

450-
if [ $res != 1 ]; then
452+
if [ $res == 0 ]; then
451453
mytime=`$CAT $TIMEFILE | $TR '\n' '-'`
452454

453455
USERT=`$ECHO $mytime | $CUT -d - -f 2 | $CUT -d ' ' -f 2`
@@ -503,7 +505,7 @@ run_testcase ()
503505

504506
[ "$DO_GCOV" ] && gcov_prepare
505507

506-
echo "Installing test databases"
508+
echo "Installing test databases"
507509
mysql_install_db
508510

509511
#do not automagically start deamons if we are in gdb or running only one test
@@ -546,7 +548,7 @@ fi
546548
$ECHO $DASH72
547549
$ECHO
548550
$ECHO "Ending Tests for MySQL daemon"
549-
$RM $TIMEFILE
551+
$RM -f $TIMEFILE
550552

551553
if [ -z "$DO_GDB" ] ;
552554
then

mysql-test/r/alt000001.result

-5
This file was deleted.

mysql-test/r/alter_table.result

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
bandID payoutID new_col
2+
6 1 NULL
3+
3 4 NULL
4+
1 6 NULL
5+
2 6 NULL
6+
4 9 NULL
7+
5 10 NULL
8+
7 12 NULL
9+
8 12 NULL
10+
bandID payoutID new_col
11+
1 6 NULL
12+
2 6 NULL
13+
3 4 NULL
14+
4 9 NULL
15+
5 10 NULL
16+
6 1 NULL
17+
7 12 NULL
18+
8 12 NULL
19+
Field Type Null Key Default Extra Privileges
20+
GROUP_ID int(10) unsigned PRI 0 select,insert,update,references
21+
LANG_ID smallint(5) unsigned PRI 0 select,insert,update,references
22+
NAME char(80) MUL select,insert,update,references
23+
n
24+
3
25+
9
26+
10
27+
12

mysql-test/r/analyse.result

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
Field_name Min_value Max_value Min_length Max_length Empties_or_zeros Nulls Avg_value_or_avg_length Std Optimal_fieldtype
2+
t1.i 1 7 1 1 0 0 4.0000 2.2361 ENUM('1','3','5','7') NOT NULL
3+
t1.j 2 8 1 1 0 0 5.0000 2.2361 ENUM('2','4','6','8') NOT NULL
4+
Field_name Min_value Max_value Min_length Max_length Empties_or_zeros Nulls Avg_value_or_avg_length Std Optimal_fieldtype
5+
t1.i 1 7 1 1 0 0 4.0000 2.2361 ENUM('1','3','5','7') NOT NULL
6+
t1.j 2 8 1 1 0 0 5.0000 2.2361 ENUM('2','4','6','8') NOT NULL

0 commit comments

Comments
 (0)