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

Commit41bea99

Browse files
committed
Fix assorted places in psql to print version numbers >= 10 in new style.
This is somewhat cosmetic, since as long as you know what you are lookingat, "10.0" is a serviceable substitute for "10". But there is a potentialfor confusion between version numbers with minor numbers and those without--- we don't want people asking "why is psql saying 10.0 when my server is10.2". Therefore, back-patch as far as practical, which turns out to be9.3. I could have redone the patch to use fprintf(stderr) in place ofpsql_error(), but it seems more work than is warranted for branches thatwill be EOL or nearly so by the time v10 comes out.Although only psql seems to contain any code that needs this, I choseto put the support function into fe_utils, since it seems likely we'llneed it in other client programs in future. (In 9.3-9.5, use dumputils.c,the predecessor of fe_utils/string_utils.c.)In HEAD, also fix the backend code that whines about loadable-libraryversion mismatch. I don't see much need to back-patch that.
1 parente8e20aa commit41bea99

File tree

5 files changed

+138
-44
lines changed

5 files changed

+138
-44
lines changed

‎src/bin/pg_dump/dumputils.c

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,44 @@ fmtQualifiedId(int remoteVersion, const char *schema, const char *id)
178178
returnid_return->data;
179179
}
180180

181+
/*
182+
* Format a Postgres version number (in the PG_VERSION_NUM integer format
183+
* returned by PQserverVersion()) as a string. This exists mainly to
184+
* encapsulate knowledge about two-part vs. three-part version numbers.
185+
*
186+
* For re-entrancy, caller must supply the buffer the string is put in.
187+
* Recommended size of the buffer is 32 bytes.
188+
*
189+
* Returns address of 'buf', as a notational convenience.
190+
*/
191+
char*
192+
formatPGVersionNumber(intversion_number,boolinclude_minor,
193+
char*buf,size_tbuflen)
194+
{
195+
if (version_number >=100000)
196+
{
197+
/* New two-part style */
198+
if (include_minor)
199+
snprintf(buf,buflen,"%d.%d",version_number /10000,
200+
version_number %10000);
201+
else
202+
snprintf(buf,buflen,"%d",version_number /10000);
203+
}
204+
else
205+
{
206+
/* Old three-part style */
207+
if (include_minor)
208+
snprintf(buf,buflen,"%d.%d.%d",version_number /10000,
209+
(version_number /100) %100,
210+
version_number %100);
211+
else
212+
snprintf(buf,buflen,"%d.%d",version_number /10000,
213+
(version_number /100) %100);
214+
}
215+
returnbuf;
216+
}
217+
218+
181219
/*
182220
* Convert a string value to an SQL string literal and append it to
183221
* the given buffer. We assume the specified client_encoding and

‎src/bin/pg_dump/dumputils.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ extern PQExpBuffer (*getLocalPQExpBuffer) (void);
3838
externconstchar*fmtId(constchar*identifier);
3939
externconstchar*fmtQualifiedId(intremoteVersion,
4040
constchar*schema,constchar*id);
41+
externchar*formatPGVersionNumber(intversion_number,boolinclude_minor,
42+
char*buf,size_tbuflen);
4143
externvoidappendStringLiteral(PQExpBufferbuf,constchar*str,
4244
intencoding,boolstd_strings);
4345
externvoidappendStringLiteralConn(PQExpBufferbuf,constchar*str,

‎src/bin/psql/command.c

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -589,8 +589,11 @@ exec_command(const char *cmd,
589589

590590
if (pset.sversion<80400)
591591
{
592-
psql_error("The server (version %d.%d) does not support editing function source.\n",
593-
pset.sversion /10000, (pset.sversion /100) %100);
592+
charsverbuf[32];
593+
594+
psql_error("The server (version %s) does not support editing function source.\n",
595+
formatPGVersionNumber(pset.sversion, false,
596+
sverbuf,sizeof(sverbuf)));
594597
status=PSQL_CMD_ERROR;
595598
}
596599
elseif (!query_buf)
@@ -1198,8 +1201,11 @@ exec_command(const char *cmd,
11981201
OT_WHOLE_LINE,NULL, true);
11991202
if (pset.sversion<80400)
12001203
{
1201-
psql_error("The server (version %d.%d) does not support showing function source.\n",
1202-
pset.sversion /10000, (pset.sversion /100) %100);
1204+
charsverbuf[32];
1205+
1206+
psql_error("The server (version %s) does not support showing function source.\n",
1207+
formatPGVersionNumber(pset.sversion, false,
1208+
sverbuf,sizeof(sverbuf)));
12031209
status=PSQL_CMD_ERROR;
12041210
}
12051211
elseif (!func)
@@ -1809,22 +1815,21 @@ connection_warnings(bool in_startup)
18091815
if (!pset.quiet&& !pset.notty)
18101816
{
18111817
intclient_ver=PG_VERSION_NUM;
1818+
charcverbuf[32];
1819+
charsverbuf[32];
18121820

18131821
if (pset.sversion!=client_ver)
18141822
{
18151823
constchar*server_version;
1816-
charserver_ver_str[16];
18171824

18181825
/* Try to get full text form, might include "devel" etc */
18191826
server_version=PQparameterStatus(pset.db,"server_version");
1827+
/* Otherwise fall back on pset.sversion */
18201828
if (!server_version)
18211829
{
1822-
snprintf(server_ver_str,sizeof(server_ver_str),
1823-
"%d.%d.%d",
1824-
pset.sversion /10000,
1825-
(pset.sversion /100) %100,
1826-
pset.sversion %100);
1827-
server_version=server_ver_str;
1830+
formatPGVersionNumber(pset.sversion, true,
1831+
sverbuf,sizeof(sverbuf));
1832+
server_version=sverbuf;
18281833
}
18291834

18301835
printf(_("%s (%s, server %s)\n"),
@@ -1835,10 +1840,13 @@ connection_warnings(bool in_startup)
18351840
printf("%s (%s)\n",pset.progname,PG_VERSION);
18361841

18371842
if (pset.sversion /100>client_ver /100)
1838-
printf(_("WARNING: %s major version %d.%d, server major version %d.%d.\n"
1843+
printf(_("WARNING: %s major version %s, server major version %s.\n"
18391844
" Some psql features might not work.\n"),
1840-
pset.progname,client_ver /10000, (client_ver /100) %100,
1841-
pset.sversion /10000, (pset.sversion /100) %100);
1845+
pset.progname,
1846+
formatPGVersionNumber(client_ver, false,
1847+
cverbuf,sizeof(cverbuf)),
1848+
formatPGVersionNumber(pset.sversion, false,
1849+
sverbuf,sizeof(sverbuf)));
18421850

18431851
#ifdefWIN32
18441852
checkWin32Codepage();

‎src/bin/psql/common.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include"settings.h"
2323
#include"command.h"
2424
#include"copy.h"
25+
#include"dumputils.h"
2526
#include"mbprint.h"
2627

2728

@@ -926,8 +927,11 @@ SendQuery(const char *query)
926927
{
927928
if (on_error_rollback_warning== false&&pset.sversion<80000)
928929
{
929-
psql_error("The server (version %d.%d) does not support savepoints for ON_ERROR_ROLLBACK.\n",
930-
pset.sversion /10000, (pset.sversion /100) %100);
930+
charsverbuf[32];
931+
932+
psql_error("The server (version %s) does not support savepoints for ON_ERROR_ROLLBACK.\n",
933+
formatPGVersionNumber(pset.sversion, false,
934+
sverbuf,sizeof(sverbuf)));
931935
on_error_rollback_warning= true;
932936
}
933937
else

‎src/bin/psql/describe.c

Lines changed: 70 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -134,8 +134,11 @@ describeTablespaces(const char *pattern, bool verbose)
134134

135135
if (pset.sversion<80000)
136136
{
137-
psql_error("The server (version %d.%d) does not support tablespaces.\n",
138-
pset.sversion /10000, (pset.sversion /100) %100);
137+
charsverbuf[32];
138+
139+
psql_error("The server (version %s) does not support tablespaces.\n",
140+
formatPGVersionNumber(pset.sversion, false,
141+
sverbuf,sizeof(sverbuf)));
139142
return true;
140143
}
141144

@@ -227,8 +230,11 @@ describeFunctions(const char *functypes, const char *pattern, bool verbose, bool
227230

228231
if (showWindow&&pset.sversion<80400)
229232
{
230-
psql_error("\\df does not take a \"w\" option with server version %d.%d\n",
231-
pset.sversion /10000, (pset.sversion /100) %100);
233+
charsverbuf[32];
234+
235+
psql_error("\\df does not take a \"w\" option with server version %s\n",
236+
formatPGVersionNumber(pset.sversion, false,
237+
sverbuf,sizeof(sverbuf)));
232238
return true;
233239
}
234240

@@ -806,8 +812,11 @@ listDefaultACLs(const char *pattern)
806812

807813
if (pset.sversion<90000)
808814
{
809-
psql_error("The server (version %d.%d) does not support altering default privileges.\n",
810-
pset.sversion /10000, (pset.sversion /100) %100);
815+
charsverbuf[32];
816+
817+
psql_error("The server (version %s) does not support altering default privileges.\n",
818+
formatPGVersionNumber(pset.sversion, false,
819+
sverbuf,sizeof(sverbuf)));
811820
return true;
812821
}
813822

@@ -3187,8 +3196,11 @@ listCollations(const char *pattern, bool verbose, bool showSystem)
31873196

31883197
if (pset.sversion<90100)
31893198
{
3190-
psql_error("The server (version %d.%d) does not support collations.\n",
3191-
pset.sversion /10000, (pset.sversion /100) %100);
3199+
charsverbuf[32];
3200+
3201+
psql_error("The server (version %s) does not support collations.\n",
3202+
formatPGVersionNumber(pset.sversion, false,
3203+
sverbuf,sizeof(sverbuf)));
31923204
return true;
31933205
}
31943206

@@ -3318,8 +3330,11 @@ listTSParsers(const char *pattern, bool verbose)
33183330

33193331
if (pset.sversion<80300)
33203332
{
3321-
psql_error("The server (version %d.%d) does not support full text search.\n",
3322-
pset.sversion /10000, (pset.sversion /100) %100);
3333+
charsverbuf[32];
3334+
3335+
psql_error("The server (version %s) does not support full text search.\n",
3336+
formatPGVersionNumber(pset.sversion, false,
3337+
sverbuf,sizeof(sverbuf)));
33233338
return true;
33243339
}
33253340

@@ -3551,8 +3566,11 @@ listTSDictionaries(const char *pattern, bool verbose)
35513566

35523567
if (pset.sversion<80300)
35533568
{
3554-
psql_error("The server (version %d.%d) does not support full text search.\n",
3555-
pset.sversion /10000, (pset.sversion /100) %100);
3569+
charsverbuf[32];
3570+
3571+
psql_error("The server (version %s) does not support full text search.\n",
3572+
formatPGVersionNumber(pset.sversion, false,
3573+
sverbuf,sizeof(sverbuf)));
35563574
return true;
35573575
}
35583576

@@ -3619,8 +3637,11 @@ listTSTemplates(const char *pattern, bool verbose)
36193637

36203638
if (pset.sversion<80300)
36213639
{
3622-
psql_error("The server (version %d.%d) does not support full text search.\n",
3623-
pset.sversion /10000, (pset.sversion /100) %100);
3640+
charsverbuf[32];
3641+
3642+
psql_error("The server (version %s) does not support full text search.\n",
3643+
formatPGVersionNumber(pset.sversion, false,
3644+
sverbuf,sizeof(sverbuf)));
36243645
return true;
36253646
}
36263647

@@ -3687,8 +3708,11 @@ listTSConfigs(const char *pattern, bool verbose)
36873708

36883709
if (pset.sversion<80300)
36893710
{
3690-
psql_error("The server (version %d.%d) does not support full text search.\n",
3691-
pset.sversion /10000, (pset.sversion /100) %100);
3711+
charsverbuf[32];
3712+
3713+
psql_error("The server (version %s) does not support full text search.\n",
3714+
formatPGVersionNumber(pset.sversion, false,
3715+
sverbuf,sizeof(sverbuf)));
36923716
return true;
36933717
}
36943718

@@ -3885,8 +3909,11 @@ listForeignDataWrappers(const char *pattern, bool verbose)
38853909

38863910
if (pset.sversion<80400)
38873911
{
3888-
psql_error("The server (version %d.%d) does not support foreign-data wrappers.\n",
3889-
pset.sversion /10000, (pset.sversion /100) %100);
3912+
charsverbuf[32];
3913+
3914+
psql_error("The server (version %s) does not support foreign-data wrappers.\n",
3915+
formatPGVersionNumber(pset.sversion, false,
3916+
sverbuf,sizeof(sverbuf)));
38903917
return true;
38913918
}
38923919

@@ -3965,8 +3992,11 @@ listForeignServers(const char *pattern, bool verbose)
39653992

39663993
if (pset.sversion<80400)
39673994
{
3968-
psql_error("The server (version %d.%d) does not support foreign servers.\n",
3969-
pset.sversion /10000, (pset.sversion /100) %100);
3995+
charsverbuf[32];
3996+
3997+
psql_error("The server (version %s) does not support foreign servers.\n",
3998+
formatPGVersionNumber(pset.sversion, false,
3999+
sverbuf,sizeof(sverbuf)));
39704000
return true;
39714001
}
39724002

@@ -4044,8 +4074,11 @@ listUserMappings(const char *pattern, bool verbose)
40444074

40454075
if (pset.sversion<80400)
40464076
{
4047-
psql_error("The server (version %d.%d) does not support user mappings.\n",
4048-
pset.sversion /10000, (pset.sversion /100) %100);
4077+
charsverbuf[32];
4078+
4079+
psql_error("The server (version %s) does not support user mappings.\n",
4080+
formatPGVersionNumber(pset.sversion, false,
4081+
sverbuf,sizeof(sverbuf)));
40494082
return true;
40504083
}
40514084

@@ -4102,8 +4135,11 @@ listForeignTables(const char *pattern, bool verbose)
41024135

41034136
if (pset.sversion<90100)
41044137
{
4105-
psql_error("The server (version %d.%d) does not support foreign tables.\n",
4106-
pset.sversion /10000, (pset.sversion /100) %100);
4138+
charsverbuf[32];
4139+
4140+
psql_error("The server (version %s) does not support foreign tables.\n",
4141+
formatPGVersionNumber(pset.sversion, false,
4142+
sverbuf,sizeof(sverbuf)));
41074143
return true;
41084144
}
41094145

@@ -4177,8 +4213,11 @@ listExtensions(const char *pattern)
41774213

41784214
if (pset.sversion<90100)
41794215
{
4180-
psql_error("The server (version %d.%d) does not support extensions.\n",
4181-
pset.sversion /10000, (pset.sversion /100) %100);
4216+
charsverbuf[32];
4217+
4218+
psql_error("The server (version %s) does not support extensions.\n",
4219+
formatPGVersionNumber(pset.sversion, false,
4220+
sverbuf,sizeof(sverbuf)));
41824221
return true;
41834222
}
41844223

@@ -4231,8 +4270,11 @@ listExtensionContents(const char *pattern)
42314270

42324271
if (pset.sversion<90100)
42334272
{
4234-
psql_error("The server (version %d.%d) does not support extensions.\n",
4235-
pset.sversion /10000, (pset.sversion /100) %100);
4273+
charsverbuf[32];
4274+
4275+
psql_error("The server (version %s) does not support extensions.\n",
4276+
formatPGVersionNumber(pset.sversion, false,
4277+
sverbuf,sizeof(sverbuf)));
42364278
return true;
42374279
}
42384280

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp