Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
M
mariadb
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
mariadb
Commits
b7977855
Commit
b7977855
authored
Sep 29, 2006
by
msvensson@shellback.(none)
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add possibility to specify which delimiter to read until in "write_file" and "perl" commands
fix memory leaks reported by valgrind
parent
5245254b
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
83 additions
and
19 deletions
+83
-19
client/mysqltest.c
client/mysqltest.c
+53
-19
mysql-test/r/mysqltest.result
mysql-test/r/mysqltest.result
+4
-0
mysql-test/t/mysqltest.test
mysql-test/t/mysqltest.test
+26
-0
No files found.
client/mysqltest.c
View file @
b7977855
...
@@ -16,12 +16,14 @@
...
@@ -16,12 +16,14 @@
/* mysqltest test tool
/* mysqltest test tool
* See the "MySQL Test framework manual" for more information
* See the "MySQL Test framework manual" for more information
* http://dev.mysql.com/doc/mysqltest/en/index.html
*
*
* Written by:
* Written by:
* Sasha Pachev <sasha@mysql.com>
* Sasha Pachev <sasha@mysql.com>
* Matt Wagner <matt@mysql.com>
* Matt Wagner <matt@mysql.com>
* Monty
* Monty
* Jani
* Jani
* Magnus
**/
**/
#define MTEST_VERSION "2.7"
#define MTEST_VERSION "2.7"
...
@@ -1332,6 +1334,7 @@ static void do_exec(struct st_query *query)
...
@@ -1332,6 +1334,7 @@ static void do_exec(struct st_query *query)
query
->
first_argument
,
query
->
expected_errno
[
0
].
code
.
errnum
);
query
->
first_argument
,
query
->
expected_errno
[
0
].
code
.
errnum
);
}
}
dynstr_free
(
&
ds_cmd
);
free_replace
();
free_replace
();
DBUG_VOID_RETURN
;
DBUG_VOID_RETURN
;
}
}
...
@@ -1757,22 +1760,32 @@ static my_bool match_delimiter(int c, const char* delim, uint length)
...
@@ -1757,22 +1760,32 @@ static my_bool match_delimiter(int c, const char* delim, uint length)
}
}
static
void
read_until_EOF
(
DYNAMIC_STRING
*
ds
)
static
void
read_until_delimiter
(
DYNAMIC_STRING
*
ds
,
DYNAMIC_STRING
*
ds_delimiter
)
{
{
int
c
;
int
c
;
DBUG_ENTER
(
"read_until_EOF"
);
DBUG_ENTER
(
"read_until_delimiter"
);
DBUG_PRINT
(
"enter"
,
(
"delimiter: %s, length: %d"
,
ds_delimiter
->
str
,
ds_delimiter
->
length
));
if
(
ds_delimiter
->
length
>
MAX_DELIMITER
)
die
(
"Max delimiter length(%d) exceeded"
,
MAX_DELIMITER
);
/* Read from file until delimiter
EOF
is found */
/* Read from file until delimiter is found */
while
(
1
)
while
(
1
)
{
{
c
=
my_getc
(
cur_file
->
file
);
c
=
my_getc
(
cur_file
->
file
);
if
(
c
==
'\n'
)
cur_file
->
lineno
++
;
if
(
feof
(
cur_file
->
file
))
if
(
feof
(
cur_file
->
file
))
die
(
"End of file encountered before 'EOF' delimiter was found"
);
die
(
"End of file encountered before '%s' delimiter was found"
,
ds_delimiter
->
str
);
if
(
match_delimiter
(
c
,
"EOF"
,
3
))
if
(
match_delimiter
(
c
,
ds_delimiter
->
str
,
ds_delimiter
->
length
))
{
{
DBUG_PRINT
(
"exit"
,
(
"Found
EOF"
));
DBUG_PRINT
(
"exit"
,
(
"Found
delimiter '%s'"
,
ds_delimiter
->
str
));
break
;
break
;
}
}
dynstr_append_mem
(
ds
,
(
const
char
*
)
&
c
,
1
);
dynstr_append_mem
(
ds
,
(
const
char
*
)
&
c
,
1
);
...
@@ -1788,7 +1801,7 @@ static void read_until_EOF(DYNAMIC_STRING* ds)
...
@@ -1788,7 +1801,7 @@ static void read_until_EOF(DYNAMIC_STRING* ds)
command called command
command called command
DESCRIPTION
DESCRIPTION
write_file <file_name>;
write_file <file_name>
[<delimiter>]
;
<what to write line 1>
<what to write line 1>
<...>
<...>
< what to write line n>
< what to write line n>
...
@@ -1800,18 +1813,23 @@ static void read_until_EOF(DYNAMIC_STRING* ds)
...
@@ -1800,18 +1813,23 @@ static void read_until_EOF(DYNAMIC_STRING* ds)
< what to write line n>
< what to write line n>
EOF
EOF
Write everything between the "write_file" command and EOF to "file_name"
Write everything between the "write_file" command and 'delimiter'
to "file_name"
NOTE! Overwrites existing file
NOTE! Overwrites existing file
Default <delimiter> is EOF
*/
*/
static
void
do_write_file
(
struct
st_query
*
command
)
static
void
do_write_file
(
struct
st_query
*
command
)
{
{
DYNAMIC_STRING
ds_content
;
DYNAMIC_STRING
ds_content
;
DYNAMIC_STRING
ds_filename
;
DYNAMIC_STRING
ds_filename
;
DYNAMIC_STRING
ds_delimiter
;
const
struct
command_arg
write_file_args
[]
=
{
const
struct
command_arg
write_file_args
[]
=
{
"filename"
,
ARG_STRING
,
TRUE
,
&
ds_filename
,
"File to write to"
,
"filename"
,
ARG_STRING
,
TRUE
,
&
ds_filename
,
"File to write to"
,
"delimiter"
,
ARG_STRING
,
FALSE
,
&
ds_delimiter
,
"Delimiter to read until"
};
};
DBUG_ENTER
(
"do_write_file"
);
DBUG_ENTER
(
"do_write_file"
);
...
@@ -1820,12 +1838,17 @@ static void do_write_file(struct st_query *command)
...
@@ -1820,12 +1838,17 @@ static void do_write_file(struct st_query *command)
write_file_args
,
write_file_args
,
sizeof
(
write_file_args
)
/
sizeof
(
struct
command_arg
));
sizeof
(
write_file_args
)
/
sizeof
(
struct
command_arg
));
/* If no delimiter was provided, use EOF */
if
(
ds_delimiter
.
length
==
0
)
dynstr_set
(
&
ds_delimiter
,
"EOF"
);
init_dynamic_string
(
&
ds_content
,
""
,
1024
,
1024
);
init_dynamic_string
(
&
ds_content
,
""
,
1024
,
1024
);
read_until_
EOF
(
&
ds_content
);
read_until_
delimiter
(
&
ds_content
,
&
ds_delimiter
);
DBUG_PRINT
(
"info"
,
(
"Writing to file: %s"
,
ds_filename
.
str
));
DBUG_PRINT
(
"info"
,
(
"Writing to file: %s"
,
ds_filename
.
str
));
str_to_file
(
ds_filename
.
str
,
ds_content
.
str
,
ds_content
.
length
);
str_to_file
(
ds_filename
.
str
,
ds_content
.
str
,
ds_content
.
length
);
dynstr_free
(
&
ds_content
);
dynstr_free
(
&
ds_content
);
dynstr_free
(
&
ds_filename
);
dynstr_free
(
&
ds_filename
);
dynstr_free
(
&
ds_delimiter
);
DBUG_VOID_RETURN
;
DBUG_VOID_RETURN
;
}
}
...
@@ -1836,22 +1859,17 @@ static void do_write_file(struct st_query *command)
...
@@ -1836,22 +1859,17 @@ static void do_write_file(struct st_query *command)
command command handle
command command handle
DESCRIPTION
DESCRIPTION
perl;
perl
[<delimiter>]
;
<perlscript line 1>
<perlscript line 1>
<...>
<...>
<perlscript line n>
<perlscript line n>
EOF
EOF
Execute everything after "perl" until
EOF
as perl.
Execute everything after "perl" until
<delimiter>
as perl.
Useful for doing more advanced things
Useful for doing more advanced things
but still being able to execute it on all platforms.
but still being able to execute it on all platforms.
The function sets delimiter to EOF and remembers that this
Default <delimiter> is EOF
is a perl command by setting "perl mode". The following lines
will then be parsed as any normal query, but when searching
for command in get_query_type, this function will be called
again since "perl mode" is on and the perl script can be
executed.
*/
*/
static
void
do_perl
(
struct
st_query
*
command
)
static
void
do_perl
(
struct
st_query
*
command
)
...
@@ -1860,10 +1878,23 @@ static void do_perl(struct st_query *command)
...
@@ -1860,10 +1878,23 @@ static void do_perl(struct st_query *command)
char
buf
[
FN_REFLEN
];
char
buf
[
FN_REFLEN
];
FILE
*
res_file
;
FILE
*
res_file
;
DYNAMIC_STRING
ds_script
;
DYNAMIC_STRING
ds_script
;
DYNAMIC_STRING
ds_delimiter
;
const
struct
command_arg
perl_args
[]
=
{
"delimiter"
,
ARG_STRING
,
FALSE
,
&
ds_delimiter
,
"Delimiter to read until"
};
DBUG_ENTER
(
"do_perl"
);
DBUG_ENTER
(
"do_perl"
);
check_command_args
(
command
,
command
->
first_argument
,
perl_args
,
sizeof
(
perl_args
)
/
sizeof
(
struct
command_arg
));
/* If no delimiter was provided, use EOF */
if
(
ds_delimiter
.
length
==
0
)
dynstr_set
(
&
ds_delimiter
,
"EOF"
);
init_dynamic_string
(
&
ds_script
,
""
,
1024
,
1024
);
init_dynamic_string
(
&
ds_script
,
""
,
1024
,
1024
);
read_until_
EOF
(
&
ds_script
);
read_until_
delimiter
(
&
ds_script
,
&
ds_delimiter
);
DBUG_PRINT
(
"info"
,
(
"Executing perl: %s"
,
ds_script
.
str
));
DBUG_PRINT
(
"info"
,
(
"Executing perl: %s"
,
ds_script
.
str
));
...
@@ -1894,6 +1925,7 @@ static void do_perl(struct st_query *command)
...
@@ -1894,6 +1925,7 @@ static void do_perl(struct st_query *command)
error
=
pclose
(
res_file
);
error
=
pclose
(
res_file
);
handle_command_error
(
command
,
WEXITSTATUS
(
error
));
handle_command_error
(
command
,
WEXITSTATUS
(
error
));
dynstr_free
(
&
ds_script
);
dynstr_free
(
&
ds_script
);
dynstr_free
(
&
ds_delimiter
);
DBUG_VOID_RETURN
;
DBUG_VOID_RETURN
;
}
}
...
@@ -2693,6 +2725,7 @@ static void free_replace_regex()
...
@@ -2693,6 +2725,7 @@ static void free_replace_regex()
{
{
if
(
glob_replace_regex
)
if
(
glob_replace_regex
)
{
{
delete_dynamic
(
&
glob_replace_regex
->
regex_arr
);
my_free
(
glob_replace_regex
->
even_buf
,
MYF
(
MY_ALLOW_ZERO_PTR
));
my_free
(
glob_replace_regex
->
even_buf
,
MYF
(
MY_ALLOW_ZERO_PTR
));
my_free
(
glob_replace_regex
->
odd_buf
,
MYF
(
MY_ALLOW_ZERO_PTR
));
my_free
(
glob_replace_regex
->
odd_buf
,
MYF
(
MY_ALLOW_ZERO_PTR
));
my_free
((
char
*
)
glob_replace_regex
,
MYF
(
0
));
my_free
((
char
*
)
glob_replace_regex
,
MYF
(
0
));
...
@@ -4164,6 +4197,7 @@ static int reg_replace(char** buf_p, int* buf_len_p, char *pattern,
...
@@ -4164,6 +4197,7 @@ static int reg_replace(char** buf_p, int* buf_len_p, char *pattern,
str_p
=
str_end
;
str_p
=
str_end
;
}
}
}
}
my_free
((
gptr
)
subs
,
MYF
(
0
));
my_regfree
(
&
r
);
my_regfree
(
&
r
);
*
res_p
=
0
;
*
res_p
=
0
;
*
buf_p
=
buf
;
*
buf_p
=
buf
;
...
...
mysql-test/r/mysqltest.result
View file @
b7977855
...
@@ -478,3 +478,7 @@ mysqltest: At line 1: Missing required argument 'to_file' to command 'copy_file'
...
@@ -478,3 +478,7 @@ mysqltest: At line 1: Missing required argument 'to_file' to command 'copy_file'
hello
hello
hello
hello
hello
hello
mysqltest: At line 1: Max delimiter length(16) exceeded
hello
hello
End of tests
mysql-test/t/mysqltest.test
View file @
b7977855
...
@@ -1182,6 +1182,18 @@ remove_file non_existing_file;
...
@@ -1182,6 +1182,18 @@ remove_file non_existing_file;
--
error
1
--
error
1
--
exec
echo
"write_file filename
\"
;"
|
$MYSQL_TEST
2
>&
1
--
exec
echo
"write_file filename
\"
;"
|
$MYSQL_TEST
2
>&
1
write_file
$MYSQLTEST_VARDIR
/
tmp
/
test_file1
.
tmp
;
Content
for
test_file1
EOF
file_exists
$MYSQLTEST_VARDIR
/
tmp
/
test_file1
.
tmp
;
remove_file
$MYSQLTEST_VARDIR
/
tmp
/
test_file1
.
tmp
;
write_file
$MYSQLTEST_VARDIR
/
tmp
/
test_file1
.
tmp
END_DELIMITER
;
Content
for
test_file1
contains
EOF
END_DELIMITER
file_exists
$MYSQLTEST_VARDIR
/
tmp
/
test_file1
.
tmp
;
remove_file
$MYSQLTEST_VARDIR
/
tmp
/
test_file1
.
tmp
;
# ----------------------------------------------------------------------------
# ----------------------------------------------------------------------------
# test for file_exist
# test for file_exist
# ----------------------------------------------------------------------------
# ----------------------------------------------------------------------------
...
@@ -1226,6 +1238,17 @@ remove_file $MYSQLTEST_VARDIR/tmp/file2.tmp;
...
@@ -1226,6 +1238,17 @@ remove_file $MYSQLTEST_VARDIR/tmp/file2.tmp;
print
"hello
\n
"
;
print
"hello
\n
"
;
EOF
EOF
--
perl
EOF
print
"hello
\n
"
;
EOF
--
perl
DELIMITER
print
"hello
\n
"
;
DELIMITER
--
error
1
--
exec
echo
"perl TOO_LONG_DELIMITER ;"
|
$MYSQL_TEST
2
>&
1
perl
;
perl
;
print
"hello
\n
"
;
print
"hello
\n
"
;
EOF
EOF
...
@@ -1234,3 +1257,6 @@ perl;
...
@@ -1234,3 +1257,6 @@ perl;
# Print "hello"
# Print "hello"
print
"hello
\n
"
;
print
"hello
\n
"
;
EOF
EOF
--
echo
End
of
tests
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment