Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit8c6eda2

Browse files
committed
pgbench: Improve error-handling in \sleep command.
This commit improves pgbench \sleep command so that it handlesthe following three cases more properly.(1) When only one argument was specified in \sleep command and it's not a number, previously pgbench reported a confusing error message like "unrecognized time unit, must be us, ms or s". This commit fixes this so that more proper error message like "invalid sleep time, must be an integer" is reported.(2) When two arguments were specified in \sleep command and the first argument was not a number, previously pgbench treated that argument as the sleep time 0. No error was reported in this case. This commit fixes this so that an error is thrown in this case.(3) When a variable was specified as the first argument in \sleep command and the variable stored non-digit value, previously pgbench treated that argument as the sleep time 0. No error was reported in this case. This commit fixes this so that an error is thrown in this case.Author: Kota MiyakeReviewed-by: Hayato Kuroda, Alvaro Herrera, Fujii MasaoDiscussion:https://postgr.es/m/23b254daf20cec4332a2d9168505dbc9@oss.nttdata.com
1 parente3f4aec commit8c6eda2

File tree

1 file changed

+38
-5
lines changed

1 file changed

+38
-5
lines changed

‎src/bin/pgbench/pgbench.c

Lines changed: 38 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2953,7 +2953,16 @@ evaluateSleep(CState *st, int argc, char **argv, int *usecs)
29532953
pg_log_error("%s: undefined variable \"%s\"",argv[0],argv[1]+1);
29542954
return false;
29552955
}
2956+
29562957
usec=atoi(var);
2958+
2959+
/* Raise an error if the value of a variable is not a number */
2960+
if (usec==0&& !isdigit((unsignedchar)*var))
2961+
{
2962+
pg_log_error("%s: invalid sleep time \"%s\" for variable \"%s\"",
2963+
argv[0],var,argv[1]+1);
2964+
return false;
2965+
}
29572966
}
29582967
else
29592968
usec=atoi(argv[1]);
@@ -4788,17 +4797,41 @@ process_backslash_command(PsqlScanState sstate, const char *source)
47884797
* will be parsed with atoi, which ignores trailing non-digit
47894798
* characters.
47904799
*/
4791-
if (my_command->argc==2&&my_command->argv[1][0]!=':')
4800+
if (my_command->argv[1][0]!=':')
47924801
{
47934802
char*c=my_command->argv[1];
4803+
boolhave_digit= false;
4804+
4805+
/* Skip sign */
4806+
if (*c=='+'||*c=='-')
4807+
c++;
4808+
4809+
/* Require at least one digit */
4810+
if (*c&&isdigit((unsignedchar)*c))
4811+
have_digit= true;
47944812

4795-
while (isdigit((unsignedchar)*c))
4813+
/* Eat all digits */
4814+
while (*c&&isdigit((unsignedchar)*c))
47964815
c++;
4816+
47974817
if (*c)
47984818
{
4799-
my_command->argv[2]=c;
4800-
offsets[2]=offsets[1]+ (c-my_command->argv[1]);
4801-
my_command->argc=3;
4819+
if (my_command->argc==2&&have_digit)
4820+
{
4821+
my_command->argv[2]=c;
4822+
offsets[2]=offsets[1]+ (c-my_command->argv[1]);
4823+
my_command->argc=3;
4824+
}
4825+
else
4826+
{
4827+
/*
4828+
* Raise an error if argument starts with non-digit
4829+
* character (after sign).
4830+
*/
4831+
syntax_error(source,lineno,my_command->first_line,my_command->argv[0],
4832+
"invalid sleep time, must be an integer",
4833+
my_command->argv[1],offsets[1]-start_offset);
4834+
}
48024835
}
48034836
}
48044837

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp