Skip to content

Commit bb66c80

Browse files
author
sasha@mysql.sashanet.com
committed
client/mysqlmanagerc.c
added support for quiet increased line buffer size client/mysqltest.c fixed memory leak added query logging to result file added error message logging to result file added enable_query_log/disable_query_log mysql-test/mysql-test-run.sh converted tests to use mysqlmanager Updated test results
1 parent 043deed commit bb66c80

File tree

160 files changed

+6687
-81
lines changed

Some content is hidden

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

160 files changed

+6687
-81
lines changed

.bzrignore

+1
Original file line numberDiff line numberDiff line change
@@ -414,3 +414,4 @@ vio/test-sslclient
414414
vio/test-sslserver
415415
vio/viotest-ssl
416416
client/mysqlmanager-pwgen
417+
*.reject

client/mysqlmanagerc.c

+5-2
Original file line numberDiff line numberDiff line change
@@ -169,17 +169,20 @@ int main(int argc, char** argv)
169169
manager->last_errno);
170170
for (;!feof(fp);)
171171
{
172-
char buf[1024];
172+
char buf[4096];
173173
if (!fgets(buf,sizeof(buf),fp))
174174
break;
175+
if (!quiet)
176+
fprintf(fp_out,"<<%s",buf);
175177
if (mysql_manager_command(manager,buf,strlen(buf)))
176178
die("Error in command: %s(%d)",manager->last_error,manager->last_errno);
177179
while (!manager->eof)
178180
{
179181
if (mysql_manager_fetch_line(manager,buf,sizeof(buf)))
180182
die("Error fetching result line: %s(%d)", manager->last_error,
181183
manager->last_errno);
182-
fprintf(fp_out,"%s\n",buf);
184+
if (!quiet)
185+
fprintf(fp_out,">>%s\n",buf);
183186
}
184187
}
185188
mysql_manager_close(manager);

client/mysqltest.c

+39-7
Original file line numberDiff line numberDiff line change
@@ -139,11 +139,13 @@ typedef struct
139139
int int_val;
140140
int alloced_len;
141141
int int_dirty; /* do not update string if int is updated until first read */
142+
int alloced;
142143
} VAR;
143144

144145
VAR var_reg[10];
145146
/*Perl/shell-like variable registers */
146147
HASH var_hash;
148+
int disable_query_log=0;
147149

148150
struct connection cons[MAX_CONS];
149151
struct connection* cur_con, *next_con, *cons_end;
@@ -165,6 +167,7 @@ Q_DIRTY_CLOSE, Q_REPLACE,
165167
Q_PING, Q_EVAL,
166168
Q_RPL_PROBE, Q_ENABLE_RPL_PARSE,
167169
Q_DISABLE_RPL_PARSE, Q_EVAL_RESULT,
170+
Q_ENABLE_QUERY_LOG, Q_DISABLE_QUERY_LOG,
168171
Q_UNKNOWN, /* Unknown command. */
169172
Q_COMMENT, /* Comments, ignored. */
170173
Q_COMMENT_WITH_COMMAND
@@ -196,6 +199,7 @@ const char *command_names[] = {
196199
"ping", "eval",
197200
"rpl_probe", "enable_rpl_parse",
198201
"disable_rpl_parse", "eval_result",
202+
"enable_query_log", "disable_query_log",
199203
0
200204
};
201205

@@ -619,14 +623,26 @@ int var_query_set(VAR* v, const char* p, const char** p_end)
619623
return 0;
620624
}
621625

626+
void var_copy(VAR* dest, VAR* src)
627+
{
628+
dest->int_val=src->int_val;
629+
dest->int_dirty=src->int_dirty;
630+
if (dest->alloced_len < src->alloced_len &&
631+
!(dest->str_val=my_realloc(dest->str_val,src->alloced_len,
632+
MYF(MY_WME))))
633+
die("Out of memory");
634+
dest->str_val_len=src->str_val_len;
635+
memcpy(dest->str_val,src->str_val,src->str_val_len);
636+
}
637+
622638
int eval_expr(VAR* v, const char* p, const char** p_end)
623639
{
624640
VAR* vp;
625641
if (*p == '$')
626642
{
627643
if ((vp = var_get(p,p_end,0)))
628644
{
629-
memcpy(v, vp, sizeof(*v));
645+
var_copy(v, vp);
630646
return 0;
631647
}
632648
}
@@ -699,6 +715,7 @@ int do_system(struct st_query* q)
699715
if (system(expr_buf) && q->abort_on_error)
700716
die("system command '%s' failed", expr_buf);
701717
}
718+
var_free(&v);
702719
return 0;
703720
}
704721

@@ -714,6 +731,7 @@ int do_echo(struct st_query* q)
714731
write(1, v.str_val, v.str_val_len);
715732
}
716733
write(1, "\n", 1);
734+
var_free(&v);
717735
return 0;
718736
}
719737

@@ -1190,10 +1208,10 @@ int do_done(struct st_query* q)
11901208
parser.current_line = *--cur_block;
11911209
}
11921210
else
1193-
{
1194-
++parser.current_line;
1195-
--cur_block;
1196-
}
1211+
{
1212+
++parser.current_line;
1213+
--cur_block;
1214+
}
11971215
return 0;
11981216
}
11991217

@@ -1202,7 +1220,6 @@ int do_while(struct st_query* q)
12021220
char* p=q->first_argument;
12031221
const char* expr_start, *expr_end;
12041222
VAR v;
1205-
var_init(&v,0,0,0,0);
12061223
if (cur_block == block_stack_end)
12071224
die("Nesting too deeply");
12081225
if (!*block_ok)
@@ -1219,6 +1236,7 @@ int do_while(struct st_query* q)
12191236
expr_end = strrchr(expr_start, ')');
12201237
if (!expr_end)
12211238
die("missing ')' in while");
1239+
var_init(&v,0,0,0,0);
12221240
eval_expr(&v, ++expr_start, &expr_end);
12231241
*cur_block++ = parser.current_line++;
12241242
if (!v.int_val)
@@ -1228,6 +1246,7 @@ int do_while(struct st_query* q)
12281246
}
12291247
else
12301248
*++block_ok = 1;
1249+
var_free(&v);
12311250
return 0;
12321251
}
12331252

@@ -1727,6 +1746,11 @@ int run_query(MYSQL* mysql, struct st_query* q, int flags)
17271746

17281747
if ((flags & QUERY_SEND) && mysql_send_query(mysql, query, query_len))
17291748
die("At line %u: unable to send query '%s'", start_lineno, query);
1749+
if ((flags & QUERY_SEND) && !disable_query_log)
1750+
{
1751+
dynstr_append_mem(ds,query,query_len);
1752+
dynstr_append_mem(ds,";\n",2);
1753+
}
17301754
if(!(flags & QUERY_REAP))
17311755
return 0;
17321756

@@ -1743,7 +1767,11 @@ int run_query(MYSQL* mysql, struct st_query* q, int flags)
17431767
for (i=0 ; q->expected_errno[i] ; i++)
17441768
{
17451769
if ((q->expected_errno[i] == mysql_errno(mysql)))
1770+
{
1771+
dynstr_append(ds,mysql_error(mysql));
1772+
dynstr_append_mem(ds,"\n",1);
17461773
goto end; /* Ok */
1774+
}
17471775
}
17481776
if (i)
17491777
{
@@ -1887,6 +1915,7 @@ static VAR* var_init(VAR* v, const char* name, int name_len, const char* val,
18871915
die("Out of memory");
18881916

18891917
tmp_var->name = (name) ? (char*)tmp_var + sizeof(*tmp_var) : 0;
1918+
tmp_var->alloced = (v == 0);
18901919

18911920
if(!(tmp_var->str_val = my_malloc(val_alloc_len, MYF(MY_WME))))
18921921
die("Out of memory");
@@ -1905,7 +1934,8 @@ static VAR* var_init(VAR* v, const char* name, int name_len, const char* val,
19051934
static void var_free(void* v)
19061935
{
19071936
my_free(((VAR*) v)->str_val, MYF(MY_WME));
1908-
my_free((char*) v, MYF(MY_WME));
1937+
if (((VAR*)v)->alloced)
1938+
my_free((char*) v, MYF(MY_WME));
19091939
}
19101940

19111941

@@ -2008,6 +2038,8 @@ int main(int argc, char** argv)
20082038
case Q_RPL_PROBE: do_rpl_probe(q); break;
20092039
case Q_ENABLE_RPL_PARSE: do_enable_rpl_parse(q); break;
20102040
case Q_DISABLE_RPL_PARSE: do_disable_rpl_parse(q); break;
2041+
case Q_ENABLE_QUERY_LOG: disable_query_log=0; break;
2042+
case Q_DISABLE_QUERY_LOG: disable_query_log=1; break;
20112043
case Q_SOURCE: do_source(q); break;
20122044
case Q_SLEEP: do_sleep(q); break;
20132045
case Q_INC: do_inc(q); break;

0 commit comments

Comments
 (0)