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

Commit7f35949

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 parent6356512 commit7f35949

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
@@ -72,6 +72,8 @@ extern PQExpBuffer (*getLocalPQExpBuffer) (void);
7272
externconstchar*fmtId(constchar*identifier);
7373
externconstchar*fmtQualifiedId(intremoteVersion,
7474
constchar*schema,constchar*id);
75+
externchar*formatPGVersionNumber(intversion_number,boolinclude_minor,
76+
char*buf,size_tbuflen);
7577
externvoidappendStringLiteral(PQExpBufferbuf,constchar*str,
7678
intencoding,boolstd_strings);
7779
externvoidappendStringLiteralConn(PQExpBufferbuf,constchar*str,

‎src/bin/psql/command.c

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

609609
if (pset.sversion<80400)
610610
{
611-
psql_error("The server (version %d.%d) does not support editing function source.\n",
612-
pset.sversion /10000, (pset.sversion /100) %100);
611+
charsverbuf[32];
612+
613+
psql_error("The server (version %s) does not support editing function source.\n",
614+
formatPGVersionNumber(pset.sversion, false,
615+
sverbuf,sizeof(sverbuf)));
613616
status=PSQL_CMD_ERROR;
614617
}
615618
elseif (!query_buf)
@@ -1238,8 +1241,11 @@ exec_command(const char *cmd,
12381241
OT_WHOLE_LINE,NULL, true);
12391242
if (pset.sversion<80400)
12401243
{
1241-
psql_error("The server (version %d.%d) does not support showing function source.\n",
1242-
pset.sversion /10000, (pset.sversion /100) %100);
1244+
charsverbuf[32];
1245+
1246+
psql_error("The server (version %s) does not support showing function source.\n",
1247+
formatPGVersionNumber(pset.sversion, false,
1248+
sverbuf,sizeof(sverbuf)));
12431249
status=PSQL_CMD_ERROR;
12441250
}
12451251
elseif (!func)
@@ -1863,22 +1869,21 @@ connection_warnings(bool in_startup)
18631869
if (!pset.quiet&& !pset.notty)
18641870
{
18651871
intclient_ver=PG_VERSION_NUM;
1872+
charcverbuf[32];
1873+
charsverbuf[32];
18661874

18671875
if (pset.sversion!=client_ver)
18681876
{
18691877
constchar*server_version;
1870-
charserver_ver_str[16];
18711878

18721879
/* Try to get full text form, might include "devel" etc */
18731880
server_version=PQparameterStatus(pset.db,"server_version");
1881+
/* Otherwise fall back on pset.sversion */
18741882
if (!server_version)
18751883
{
1876-
snprintf(server_ver_str,sizeof(server_ver_str),
1877-
"%d.%d.%d",
1878-
pset.sversion /10000,
1879-
(pset.sversion /100) %100,
1880-
pset.sversion %100);
1881-
server_version=server_ver_str;
1884+
formatPGVersionNumber(pset.sversion, true,
1885+
sverbuf,sizeof(sverbuf));
1886+
server_version=sverbuf;
18821887
}
18831888

18841889
printf(_("%s (%s, server %s)\n"),
@@ -1889,10 +1894,13 @@ connection_warnings(bool in_startup)
18891894
printf("%s (%s)\n",pset.progname,PG_VERSION);
18901895

18911896
if (pset.sversion /100>client_ver /100)
1892-
printf(_("WARNING: %s major version %d.%d, server major version %d.%d.\n"
1897+
printf(_("WARNING: %s major version %s, server major version %s.\n"
18931898
" Some psql features might not work.\n"),
1894-
pset.progname,client_ver /10000, (client_ver /100) %100,
1895-
pset.sversion /10000, (pset.sversion /100) %100);
1899+
pset.progname,
1900+
formatPGVersionNumber(client_ver, false,
1901+
cverbuf,sizeof(cverbuf)),
1902+
formatPGVersionNumber(pset.sversion, false,
1903+
sverbuf,sizeof(sverbuf)));
18961904

18971905
#ifdefWIN32
18981906
checkWin32Codepage();

‎src/bin/psql/common.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include"settings.h"
2424
#include"command.h"
2525
#include"copy.h"
26+
#include"dumputils.h"
2627
#include"mbprint.h"
2728

2829

@@ -1037,8 +1038,11 @@ SendQuery(const char *query)
10371038
{
10381039
if (on_error_rollback_warning== false&&pset.sversion<80000)
10391040
{
1040-
psql_error("The server (version %d.%d) does not support savepoints for ON_ERROR_ROLLBACK.\n",
1041-
pset.sversion /10000, (pset.sversion /100) %100);
1041+
charsverbuf[32];
1042+
1043+
psql_error("The server (version %s) does not support savepoints for ON_ERROR_ROLLBACK.\n",
1044+
formatPGVersionNumber(pset.sversion, false,
1045+
sverbuf,sizeof(sverbuf)));
10421046
on_error_rollback_warning= true;
10431047
}
10441048
else

‎src/bin/psql/describe.c

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

142142
if (pset.sversion<80000)
143143
{
144-
psql_error("The server (version %d.%d) does not support tablespaces.\n",
145-
pset.sversion /10000, (pset.sversion /100) %100);
144+
charsverbuf[32];
145+
146+
psql_error("The server (version %s) does not support tablespaces.\n",
147+
formatPGVersionNumber(pset.sversion, false,
148+
sverbuf,sizeof(sverbuf)));
146149
return true;
147150
}
148151

@@ -244,8 +247,11 @@ describeFunctions(const char *functypes, const char *pattern, bool verbose, bool
244247

245248
if (showWindow&&pset.sversion<80400)
246249
{
247-
psql_error("\\df does not take a \"w\" option with server version %d.%d\n",
248-
pset.sversion /10000, (pset.sversion /100) %100);
250+
charsverbuf[32];
251+
252+
psql_error("\\df does not take a \"w\" option with server version %s\n",
253+
formatPGVersionNumber(pset.sversion, false,
254+
sverbuf,sizeof(sverbuf)));
249255
return true;
250256
}
251257

@@ -870,8 +876,11 @@ listDefaultACLs(const char *pattern)
870876

871877
if (pset.sversion<90000)
872878
{
873-
psql_error("The server (version %d.%d) does not support altering default privileges.\n",
874-
pset.sversion /10000, (pset.sversion /100) %100);
879+
charsverbuf[32];
880+
881+
psql_error("The server (version %s) does not support altering default privileges.\n",
882+
formatPGVersionNumber(pset.sversion, false,
883+
sverbuf,sizeof(sverbuf)));
875884
return true;
876885
}
877886

@@ -3453,8 +3462,11 @@ listCollations(const char *pattern, bool verbose, bool showSystem)
34533462

34543463
if (pset.sversion<90100)
34553464
{
3456-
psql_error("The server (version %d.%d) does not support collations.\n",
3457-
pset.sversion /10000, (pset.sversion /100) %100);
3465+
charsverbuf[32];
3466+
3467+
psql_error("The server (version %s) does not support collations.\n",
3468+
formatPGVersionNumber(pset.sversion, false,
3469+
sverbuf,sizeof(sverbuf)));
34583470
return true;
34593471
}
34603472

@@ -3585,8 +3597,11 @@ listTSParsers(const char *pattern, bool verbose)
35853597

35863598
if (pset.sversion<80300)
35873599
{
3588-
psql_error("The server (version %d.%d) does not support full text search.\n",
3589-
pset.sversion /10000, (pset.sversion /100) %100);
3600+
charsverbuf[32];
3601+
3602+
psql_error("The server (version %s) does not support full text search.\n",
3603+
formatPGVersionNumber(pset.sversion, false,
3604+
sverbuf,sizeof(sverbuf)));
35903605
return true;
35913606
}
35923607

@@ -3820,8 +3835,11 @@ listTSDictionaries(const char *pattern, bool verbose)
38203835

38213836
if (pset.sversion<80300)
38223837
{
3823-
psql_error("The server (version %d.%d) does not support full text search.\n",
3824-
pset.sversion /10000, (pset.sversion /100) %100);
3838+
charsverbuf[32];
3839+
3840+
psql_error("The server (version %s) does not support full text search.\n",
3841+
formatPGVersionNumber(pset.sversion, false,
3842+
sverbuf,sizeof(sverbuf)));
38253843
return true;
38263844
}
38273845

@@ -3888,8 +3906,11 @@ listTSTemplates(const char *pattern, bool verbose)
38883906

38893907
if (pset.sversion<80300)
38903908
{
3891-
psql_error("The server (version %d.%d) does not support full text search.\n",
3892-
pset.sversion /10000, (pset.sversion /100) %100);
3909+
charsverbuf[32];
3910+
3911+
psql_error("The server (version %s) does not support full text search.\n",
3912+
formatPGVersionNumber(pset.sversion, false,
3913+
sverbuf,sizeof(sverbuf)));
38933914
return true;
38943915
}
38953916

@@ -3956,8 +3977,11 @@ listTSConfigs(const char *pattern, bool verbose)
39563977

39573978
if (pset.sversion<80300)
39583979
{
3959-
psql_error("The server (version %d.%d) does not support full text search.\n",
3960-
pset.sversion /10000, (pset.sversion /100) %100);
3980+
charsverbuf[32];
3981+
3982+
psql_error("The server (version %s) does not support full text search.\n",
3983+
formatPGVersionNumber(pset.sversion, false,
3984+
sverbuf,sizeof(sverbuf)));
39613985
return true;
39623986
}
39633987

@@ -4154,8 +4178,11 @@ listForeignDataWrappers(const char *pattern, bool verbose)
41544178

41554179
if (pset.sversion<80400)
41564180
{
4157-
psql_error("The server (version %d.%d) does not support foreign-data wrappers.\n",
4158-
pset.sversion /10000, (pset.sversion /100) %100);
4181+
charsverbuf[32];
4182+
4183+
psql_error("The server (version %s) does not support foreign-data wrappers.\n",
4184+
formatPGVersionNumber(pset.sversion, false,
4185+
sverbuf,sizeof(sverbuf)));
41594186
return true;
41604187
}
41614188

@@ -4234,8 +4261,11 @@ listForeignServers(const char *pattern, bool verbose)
42344261

42354262
if (pset.sversion<80400)
42364263
{
4237-
psql_error("The server (version %d.%d) does not support foreign servers.\n",
4238-
pset.sversion /10000, (pset.sversion /100) %100);
4264+
charsverbuf[32];
4265+
4266+
psql_error("The server (version %s) does not support foreign servers.\n",
4267+
formatPGVersionNumber(pset.sversion, false,
4268+
sverbuf,sizeof(sverbuf)));
42394269
return true;
42404270
}
42414271

@@ -4313,8 +4343,11 @@ listUserMappings(const char *pattern, bool verbose)
43134343

43144344
if (pset.sversion<80400)
43154345
{
4316-
psql_error("The server (version %d.%d) does not support user mappings.\n",
4317-
pset.sversion /10000, (pset.sversion /100) %100);
4346+
charsverbuf[32];
4347+
4348+
psql_error("The server (version %s) does not support user mappings.\n",
4349+
formatPGVersionNumber(pset.sversion, false,
4350+
sverbuf,sizeof(sverbuf)));
43184351
return true;
43194352
}
43204353

@@ -4371,8 +4404,11 @@ listForeignTables(const char *pattern, bool verbose)
43714404

43724405
if (pset.sversion<90100)
43734406
{
4374-
psql_error("The server (version %d.%d) does not support foreign tables.\n",
4375-
pset.sversion /10000, (pset.sversion /100) %100);
4407+
charsverbuf[32];
4408+
4409+
psql_error("The server (version %s) does not support foreign tables.\n",
4410+
formatPGVersionNumber(pset.sversion, false,
4411+
sverbuf,sizeof(sverbuf)));
43764412
return true;
43774413
}
43784414

@@ -4446,8 +4482,11 @@ listExtensions(const char *pattern)
44464482

44474483
if (pset.sversion<90100)
44484484
{
4449-
psql_error("The server (version %d.%d) does not support extensions.\n",
4450-
pset.sversion /10000, (pset.sversion /100) %100);
4485+
charsverbuf[32];
4486+
4487+
psql_error("The server (version %s) does not support extensions.\n",
4488+
formatPGVersionNumber(pset.sversion, false,
4489+
sverbuf,sizeof(sverbuf)));
44514490
return true;
44524491
}
44534492

@@ -4500,8 +4539,11 @@ listExtensionContents(const char *pattern)
45004539

45014540
if (pset.sversion<90100)
45024541
{
4503-
psql_error("The server (version %d.%d) does not support extensions.\n",
4504-
pset.sversion /10000, (pset.sversion /100) %100);
4542+
charsverbuf[32];
4543+
4544+
psql_error("The server (version %s) does not support extensions.\n",
4545+
formatPGVersionNumber(pset.sversion, false,
4546+
sverbuf,sizeof(sverbuf)));
45054547
return true;
45064548
}
45074549

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp