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

Commit6f9ee74

Browse files
committed
Improve handling of psql \watch's interval argument
A failure in parsing the interval value defined in the \watch commandwas silently switched to 1s of interval between two queries, which canbe confusing. This commit improves the error handling, and a couple oftests are added to check after:- An incorrect value.- An out-of-range value.- A negative value.A value of zero is able to work now, meaning that there is no intervalof time between two queries in a \watch loop. No backpatch is done, asit could break existing applications.Author: Andrey BorodinReviewed-by: Kyotaro Horiguchi, Nathan Bossart, Michael PaquierDiscussion:https://postgr.es/m/CAAhFRxiZ2-n_L1ErMm9AZjgmUK=qS6VHb+0SaMn8sqqbhF7How@mail.gmail.com
1 parentdccb4d1 commit6f9ee74

File tree

2 files changed

+32
-3
lines changed

2 files changed

+32
-3
lines changed

‎src/bin/psql/command.c

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2776,9 +2776,18 @@ exec_command_watch(PsqlScanState scan_state, bool active_branch,
27762776
/* Convert optional sleep-length argument */
27772777
if (opt)
27782778
{
2779-
sleep=strtod(opt,NULL);
2780-
if (sleep <=0)
2781-
sleep=1;
2779+
char*opt_end;
2780+
2781+
errno=0;
2782+
sleep=strtod(opt,&opt_end);
2783+
if (sleep<0||*opt_end||errno==ERANGE)
2784+
{
2785+
pg_log_error("\\watch: incorrect interval value '%s'",opt);
2786+
free(opt);
2787+
resetPQExpBuffer(query_buf);
2788+
psql_scan_reset(scan_state);
2789+
returnPSQL_CMD_ERROR;
2790+
}
27822791
free(opt);
27832792
}
27842793

@@ -5183,6 +5192,9 @@ do_watch(PQExpBuffer query_buf, double sleep)
51835192
if (pagerpipe&&ferror(pagerpipe))
51845193
break;
51855194

5195+
if (sleep==0)
5196+
continue;
5197+
51865198
#ifdefWIN32
51875199

51885200
/*

‎src/bin/psql/t/001_basic.pl

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -350,4 +350,21 @@ sub psql_fails_like
350350
'\copy from with DEFAULT'
351351
);
352352

353+
# Check \watch errors
354+
psql_fails_like(
355+
$node,
356+
'SELECT 1;\watch -10',
357+
qr/incorrect interval value '-10'/,
358+
'\watch, negative interval');
359+
psql_fails_like(
360+
$node,
361+
'SELECT 1;\watch 10ab',
362+
qr/incorrect interval value '10ab'/,
363+
'\watch incorrect interval');
364+
psql_fails_like(
365+
$node,
366+
'SELECT 1;\watch 10e400',
367+
qr/incorrect interval value '10e400'/,
368+
'\watch out-of-range interval');
369+
353370
done_testing();

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp