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

Commitb283096

Browse files
committed
Allow the delay in psql's \watch command to be a fractional second.
Instead of just "2" seconds, allow eg. "2.5" seconds. Per requestfrom Alvaro Herrera. No docs change since the docs didn't say youcouldn't do this already.
1 parentdea2b59 commitb283096

File tree

1 file changed

+15
-10
lines changed

1 file changed

+15
-10
lines changed

‎src/bin/psql/command.c

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ static bool do_edit(const char *filename_arg, PQExpBuffer query_buf,
6666
intlineno,bool*edited);
6767
staticbooldo_connect(char*dbname,char*user,char*host,char*port);
6868
staticbooldo_shell(constchar*command);
69-
staticbooldo_watch(PQExpBufferquery_buf,longsleep);
69+
staticbooldo_watch(PQExpBufferquery_buf,doublesleep);
7070
staticboollookup_object_oid(EditableObjectTypeobj_type,constchar*desc,
7171
Oid*obj_oid);
7272
staticboolget_create_object_cmd(EditableObjectTypeobj_type,Oidoid,
@@ -1577,12 +1577,12 @@ exec_command(const char *cmd,
15771577
{
15781578
char*opt=psql_scan_slash_option(scan_state,
15791579
OT_NORMAL,NULL, true);
1580-
longsleep=2;
1580+
doublesleep=2;
15811581

15821582
/* Convert optional sleep-length argument */
15831583
if (opt)
15841584
{
1585-
sleep=strtol(opt,NULL,10);
1585+
sleep=strtod(opt,NULL);
15861586
if (sleep <=0)
15871587
sleep=1;
15881588
free(opt);
@@ -3017,8 +3017,9 @@ do_shell(const char *command)
30173017
* onto a bunch of exec_command's variables to silence stupider compilers.
30183018
*/
30193019
staticbool
3020-
do_watch(PQExpBufferquery_buf,longsleep)
3020+
do_watch(PQExpBufferquery_buf,doublesleep)
30213021
{
3022+
longsleep_ms= (long) (sleep*1000);
30223023
printQueryOptmyopt=pset.popt;
30233024
constchar*user_title;
30243025
char*title;
@@ -3064,10 +3065,10 @@ do_watch(PQExpBuffer query_buf, long sleep)
30643065
asctimebuf[i]='\0';
30653066

30663067
if (user_title)
3067-
snprintf(title,title_len,_("%s\t%s (every %lds)\n"),
3068+
snprintf(title,title_len,_("%s\t%s (every %gs)\n"),
30683069
user_title,asctimebuf,sleep);
30693070
else
3070-
snprintf(title,title_len,_("%s (every %lds)\n"),
3071+
snprintf(title,title_len,_("%s (every %gs)\n"),
30713072
asctimebuf,sleep);
30723073
myopt.title=title;
30733074

@@ -3091,15 +3092,19 @@ do_watch(PQExpBuffer query_buf, long sleep)
30913092

30923093
/*
30933094
* Enable 'watch' cancellations and wait a while before running the
3094-
* query again. Break the sleep into short intervalssince pg_usleep
3095-
* isn't interruptible on some platforms.
3095+
* query again. Break the sleep into short intervals(at most 1s)
3096+
*since pg_usleepisn't interruptible on some platforms.
30963097
*/
30973098
sigint_interrupt_enabled= true;
3098-
for (i=0;i<sleep;i++)
3099+
i=sleep_ms;
3100+
while (i>0)
30993101
{
3100-
pg_usleep(1000000L);
3102+
longs=Min(i,1000L);
3103+
3104+
pg_usleep(s*1000L);
31013105
if (cancel_pressed)
31023106
break;
3107+
i-=s;
31033108
}
31043109
sigint_interrupt_enabled= false;
31053110
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp