7070#define INIT_Q_LINES 1024
7171#define MIN_VAR_ALLOC 32
7272#define BLOCK_STACK_DEPTH 32
73+ #define MAX_EXPECTED_ERRORS 10
7374
7475static int record = 0 , verbose = 0 , silent = 0 , opt_sleep = 0 ;
7576static char * db = 0 , * pass = 0 ;
@@ -88,7 +89,7 @@ static char TMPDIR[FN_REFLEN];
8889
8990static int block_stack [BLOCK_STACK_DEPTH ];
9091static int * cur_block , * block_stack_end ;
91- static uint global_expected_errno = 0 ;
92+ static uint global_expected_errno [ MAX_EXPECTED_ERRORS ] ;
9293
9394DYNAMIC_ARRAY q_lines ;
9495
@@ -132,7 +133,7 @@ struct st_query
132133 char * query , * first_argument ;
133134 int first_word_len ;
134135 my_bool abort_on_error , require_file ;
135- uint expected_errno ;
136+ uint expected_errno [ MAX_EXPECTED_ERRORS ] ;
136137 char record_file [FN_REFLEN ];
137138 /* Add new commands before Q_UNKNOWN */
138139 enum { Q_CONNECTION = 1 , Q_QUERY , Q_CONNECT ,
@@ -542,17 +543,24 @@ static void get_file_name(char *filename, struct st_query* q)
542543}
543544
544545
545- static int get_int ( struct st_query * q )
546+ static void get_ints ( uint * to , struct st_query * q )
546547{
547548 char * p = q -> first_argument ;
548- int res ;
549- DBUG_ENTER ("get_int" );
549+ long val ;
550+ DBUG_ENTER ("get_ints" );
551+
550552 while (* p && isspace (* p )) p ++ ;
551553 if (!* p )
552554 die ("Missing argument in %s\n" , q -> query );
553- res = atoi (p );
554- DBUG_PRINT ("result" ,("res: %d" ,res ));
555- DBUG_RETURN (res );
555+
556+ for (; (p = str2int (p ,10 ,(long ) INT_MIN , (long ) INT_MAX , & val )) ; p ++ )
557+ {
558+ * to ++ = (uint ) val ;
559+ if (* p != ',' )
560+ break ;
561+ }
562+ * to ++ = 0 ; /* End of data */
563+ DBUG_VOID_RETURN ;
556564}
557565
558566
@@ -918,9 +926,10 @@ int read_query(struct st_query** q_ptr)
918926 q -> record_file [0 ] = 0 ;
919927 q -> require_file = 0 ;
920928 q -> first_word_len = 0 ;
921- q -> expected_errno = global_expected_errno ;
922- q -> abort_on_error = global_expected_errno == 0 ;
923- global_expected_errno = 0 ;
929+ memcpy ((gptr ) q -> expected_errno , (gptr ) global_expected_errno ,
930+ sizeof (global_expected_errno ));
931+ q -> abort_on_error = global_expected_errno [0 ] == 0 ;
932+ bzero ((gptr ) global_expected_errno ,sizeof (global_expected_errno ));
924933 q -> type = Q_UNKNOWN ;
925934 q -> query = 0 ;
926935 if (read_line (read_query_buf , sizeof (read_query_buf )))
@@ -947,7 +956,8 @@ int read_query(struct st_query** q_ptr)
947956 p ++ ;
948957 for (;isdigit (* p );p ++ )
949958 expected_errno = expected_errno * 10 + * p - '0' ;
950- q -> expected_errno = expected_errno ;
959+ q -> expected_errno [0 ] = expected_errno ;
960+ q -> expected_errno [1 ] = 0 ;
951961 }
952962 }
953963
@@ -1178,15 +1188,17 @@ int run_query(MYSQL* mysql, struct st_query* q)
11781188 mysql_errno (mysql ), mysql_error (mysql ));
11791189 else
11801190 {
1181- if (q -> expected_errno )
1191+ for (i = 0 ; q -> expected_errno [i ] ; i ++ )
1192+ {
1193+ if ((q -> expected_errno [i ] == mysql_errno (mysql )))
1194+ goto end ; /* Ok */
1195+ }
1196+ if (i )
11821197 {
1183- error = (q -> expected_errno != mysql_errno (mysql ));
1184- if (error )
1185- verbose_msg ("query '%s' failed with wrong errno\
1186- %d instead of %d" , q -> query , mysql_errno (mysql ), q -> expected_errno );
1198+ verbose_msg ("query '%s' failed with wrong errno\
1199+ %d instead of %d..." , q -> query , mysql_errno (mysql ), q -> expected_errno [0 ]);
11871200 goto end ;
11881201 }
1189-
11901202 verbose_msg ("query '%s' failed: %d: %s" , q -> query , mysql_errno (mysql ),
11911203 mysql_error (mysql ));
11921204 /* if we do not abort on error, failure to run the query does
@@ -1196,11 +1208,11 @@ int run_query(MYSQL* mysql, struct st_query* q)
11961208 }
11971209 }
11981210
1199- if (q -> expected_errno )
1211+ if (q -> expected_errno [ 0 ] )
12001212 {
12011213 error = 1 ;
1202- verbose_msg ("query '%s' succeeded - should have failed with errno %d" ,
1203- q -> query , q -> expected_errno );
1214+ verbose_msg ("query '%s' succeeded - should have failed with errno %d... " ,
1215+ q -> query , q -> expected_errno [ 0 ] );
12041216 goto end ;
12051217 }
12061218
@@ -1373,7 +1385,7 @@ int main(int argc, char** argv)
13731385 require_file = 0 ;
13741386 break ;
13751387 case Q_ERROR :
1376- global_expected_errno = get_int ( q );
1388+ get_ints ( global_expected_errno , q );
13771389 break ;
13781390 case Q_REQUIRE :
13791391 get_file_name (save_file ,q );
0 commit comments