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

Commit9901d8a

Browse files
committed
Use strftime("%c") to format timestamps in psql's \watch command.
This allows the timestamps to follow local conventions (in particular,they respond to the LC_TIME environment setting). In C locale you getthe same results as before. It seems like a good idea to do this now notlater because we already changed the format of \watch headers for 9.6.Also, increase the buffer sizes a tad to ensure there's enough space fortranslated strings.Discussion: <20160612145532.GA22965@postgresql.kr>
1 parent12f8620 commit9901d8a

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
@@ -3066,6 +3066,7 @@ do_watch(PQExpBuffer query_buf, double sleep)
30663066
{
30673067
longsleep_ms= (long) (sleep*1000);
30683068
printQueryOptmyopt=pset.popt;
3069+
constchar*strftime_fmt;
30693070
constchar*user_title;
30703071
char*title;
30713072
inttitle_len;
@@ -3077,6 +3078,13 @@ do_watch(PQExpBuffer query_buf, double sleep)
30773078
return false;
30783079
}
30793080

3081+
/*
3082+
* Choose format for timestamps. We might eventually make this a \pset
3083+
* option. In the meantime, using a variable for the format suppresses
3084+
* overly-anal-retentive gcc warnings about %c being Y2K sensitive.
3085+
*/
3086+
strftime_fmt="%c";
3087+
30803088
/*
30813089
* Set up rendering options, in particular, disable the pager, because
30823090
* nobody wants to be prompted while watching the output of 'watch'.
@@ -3085,16 +3093,17 @@ do_watch(PQExpBuffer query_buf, double sleep)
30853093

30863094
/*
30873095
* If there's a title in the user configuration, make sure we have room
3088-
* for it in the title buffer.
3096+
* for it in the title buffer. Allow 128 bytes for the timestamp plus 128
3097+
* bytes for the rest.
30893098
*/
30903099
user_title=myopt.title;
3091-
title_len= (user_title ?strlen(user_title) :0)+100;
3100+
title_len= (user_title ?strlen(user_title) :0)+256;
30923101
title=pg_malloc(title_len);
30933102

30943103
for (;;)
30953104
{
30963105
time_ttimer;
3097-
charasctimebuf[64];
3106+
chartimebuf[128];
30983107
longi;
30993108

31003109
/*
@@ -3103,18 +3112,14 @@ do_watch(PQExpBuffer query_buf, double sleep)
31033112
* makes for reasonably nicely formatted output in simple cases.
31043113
*/
31053114
timer=time(NULL);
3106-
strlcpy(asctimebuf,asctime(localtime(&timer)),sizeof(asctimebuf));
3107-
/* strip trailing newline from asctime's output */
3108-
i=strlen(asctimebuf);
3109-
while (i>0&&asctimebuf[--i]=='\n')
3110-
asctimebuf[i]='\0';
3115+
strftime(timebuf,sizeof(timebuf),strftime_fmt,localtime(&timer));
31113116

31123117
if (user_title)
31133118
snprintf(title,title_len,_("%s\t%s (every %gs)\n"),
3114-
user_title,asctimebuf,sleep);
3119+
user_title,timebuf,sleep);
31153120
else
31163121
snprintf(title,title_len,_("%s (every %gs)\n"),
3117-
asctimebuf,sleep);
3122+
timebuf,sleep);
31183123
myopt.title=title;
31193124

31203125
/* Run the query and print out the results */

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp