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

Commit9e9a5b7

Browse files
committed
Use psql_error() for most psql error calls, per request from Magnus.
1 parentf6752ee commit9e9a5b7

File tree

4 files changed

+38
-37
lines changed

4 files changed

+38
-37
lines changed

‎src/bin/psql/command.c

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ HandleSlashCmds(PsqlScanState scan_state,
110110
if (status==PSQL_CMD_UNKNOWN)
111111
{
112112
if (pset.cur_cmd_interactive)
113-
fprintf(stderr,_("Invalid command \\%s. Try \\? for help.\n"),cmd);
113+
psql_error("Invalid command \\%s. Try \\? for help.\n",cmd);
114114
else
115115
psql_error("invalid command \\%s\n",cmd);
116116
status=PSQL_CMD_ERROR;
@@ -904,7 +904,7 @@ exec_command(const char *cmd,
904904

905905
if (strcmp(pw1,pw2)!=0)
906906
{
907-
fprintf(stderr,_("Passwords didn't match.\n"));
907+
psql_error("Passwords didn't match.\n");
908908
success= false;
909909
}
910910
else
@@ -922,7 +922,7 @@ exec_command(const char *cmd,
922922

923923
if (!encrypted_password)
924924
{
925-
fprintf(stderr,_("Password encryption failed.\n"));
925+
psql_error("Password encryption failed.\n");
926926
success= false;
927927
}
928928
else
@@ -1441,7 +1441,7 @@ exec_command(const char *cmd,
14411441
while ((value=psql_scan_slash_option(scan_state,
14421442
OT_NORMAL,NULL, true)))
14431443
{
1444-
fprintf(stderr,"+ opt(%d) = |%s|\n",i++,value);
1444+
psql_error("+ opt(%d) = |%s|\n",i++,value);
14451445
free(value);
14461446
}
14471447
}
@@ -1519,7 +1519,8 @@ do_connect(char *dbname, char *user, char *host, char *port)
15191519
*to connect to the wrong database by using defaults, so require
15201520
*all parameters to be specified.
15211521
*/
1522-
fputs(_("All connection parameters must be supplied because no database connection exists\n"),stderr);
1522+
psql_error("All connection parameters must be supplied because no "
1523+
"database connection exists\n");
15231524
return false;
15241525
}
15251526

@@ -1608,7 +1609,7 @@ do_connect(char *dbname, char *user, char *host, char *port)
16081609

16091610
/* pset.db is left unmodified */
16101611
if (o_conn)
1611-
fputs(_("Previous connection kept\n"),stderr);
1612+
psql_error("Previous connection kept\n");
16121613
}
16131614
else
16141615
{

‎src/bin/psql/common.c

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ pg_strdup(const char *string)
4242

4343
if (!string)
4444
{
45-
fprintf(stderr,_("%s: pg_strdup: cannot duplicate null pointer (internal error)\n"),
45+
psql_error("%s: pg_strdup: cannot duplicate null pointer (internal error)\n",
4646
pset.progname);
4747
exit(EXIT_FAILURE);
4848
}
@@ -161,7 +161,7 @@ psql_error(const char *fmt,...)
161161
va_listap;
162162

163163
fflush(stdout);
164-
if (pset.queryFout!=stdout)
164+
if (pset.queryFout&&pset.queryFout!=stdout)
165165
fflush(pset.queryFout);
166166

167167
if (pset.inputfile)
@@ -219,6 +219,7 @@ static PGcancel *volatile cancelConn = NULL;
219219
staticCRITICAL_SECTIONcancelConnLock;
220220
#endif
221221

222+
/* Used from signal handlers, no buffering */
222223
#definewrite_stderr(str)write(fileno(stderr), str, strlen(str))
223224

224225

@@ -350,19 +351,19 @@ CheckConnection(void)
350351
exit(EXIT_BADCONN);
351352
}
352353

353-
fputs(_("The connection to the server was lost. Attempting reset: "),stderr);
354+
psql_error("The connection to the server was lost. Attempting reset: ");
354355
PQreset(pset.db);
355356
OK=ConnectionUp();
356357
if (!OK)
357358
{
358-
fputs(_("Failed.\n"),stderr);
359+
psql_error("Failed.\n");
359360
PQfinish(pset.db);
360361
pset.db=NULL;
361362
ResetCancelConn();
362363
UnsyncVariables();
363364
}
364365
else
365-
fputs(_("Succeeded.\n"),stderr);
366+
psql_error("Succeeded.\n");
366367
}
367368

368369
returnOK;
@@ -910,7 +911,7 @@ SendQuery(const char *query)
910911
{
911912
if (on_error_rollback_warning== false&&pset.sversion<80000)
912913
{
913-
fprintf(stderr,_("The server (version %d.%d) does not support savepoints for ON_ERROR_ROLLBACK.\n"),
914+
psql_error("The server (version %d.%d) does not support savepoints for ON_ERROR_ROLLBACK.\n",
914915
pset.sversion /10000, (pset.sversion /100) %100);
915916
on_error_rollback_warning= true;
916917
}

‎src/bin/psql/describe.c

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ describeTablespaces(const char *pattern, bool verbose)
132132

133133
if (pset.sversion<80000)
134134
{
135-
fprintf(stderr,_("The server (version %d.%d) does not support tablespaces.\n"),
135+
psql_error("The server (version %d.%d) does not support tablespaces.\n",
136136
pset.sversion /10000, (pset.sversion /100) %100);
137137
return true;
138138
}
@@ -219,13 +219,13 @@ describeFunctions(const char *functypes, const char *pattern, bool verbose, bool
219219

220220
if (strlen(functypes)!=strspn(functypes,"antwS+"))
221221
{
222-
fprintf(stderr,_("\\df only takes [antwS+] as options\n"));
222+
psql_error("\\df only takes [antwS+] as options\n");
223223
return true;
224224
}
225225

226226
if (showWindow&&pset.sversion<80400)
227227
{
228-
fprintf(stderr,_("\\df does not take a \"w\" option with server version %d.%d\n"),
228+
psql_error("\\df does not take a \"w\" option with server version %d.%d\n",
229229
pset.sversion /10000, (pset.sversion /100) %100);
230230
return true;
231231
}
@@ -786,7 +786,7 @@ listDefaultACLs(const char *pattern)
786786

787787
if (pset.sversion<90000)
788788
{
789-
fprintf(stderr,_("The server (version %d.%d) does not support altering default privileges.\n"),
789+
psql_error("The server (version %d.%d) does not support altering default privileges.\n",
790790
pset.sversion /10000, (pset.sversion /100) %100);
791791
return true;
792792
}
@@ -1052,7 +1052,7 @@ describeTableDetails(const char *pattern, bool verbose, bool showSystem)
10521052
if (PQntuples(res)==0)
10531053
{
10541054
if (!pset.quiet)
1055-
fprintf(stderr,_("Did not find any relation named \"%s\".\n"),
1055+
psql_error("Did not find any relation named \"%s\".\n",
10561056
pattern);
10571057
PQclear(res);
10581058
return false;
@@ -1225,8 +1225,7 @@ describeOneTableDetails(const char *schemaname,
12251225
if (PQntuples(res)==0)
12261226
{
12271227
if (!pset.quiet)
1228-
fprintf(stderr,_("Did not find any relation with OID %s.\n"),
1229-
oid);
1228+
psql_error("Did not find any relation with OID %s.\n",oid);
12301229
gotoerror_return;
12311230
}
12321231

@@ -3126,7 +3125,7 @@ listCollations(const char *pattern, bool verbose, bool showSystem)
31263125

31273126
if (pset.sversion<90100)
31283127
{
3129-
fprintf(stderr,_("The server (version %d.%d) does not support collations.\n"),
3128+
psql_error("The server (version %d.%d) does not support collations.\n",
31303129
pset.sversion /10000, (pset.sversion /100) %100);
31313130
return true;
31323131
}
@@ -3257,7 +3256,7 @@ listTSParsers(const char *pattern, bool verbose)
32573256

32583257
if (pset.sversion<80300)
32593258
{
3260-
fprintf(stderr,_("The server (version %d.%d) does not support full text search.\n"),
3259+
psql_error("The server (version %d.%d) does not support full text search.\n",
32613260
pset.sversion /10000, (pset.sversion /100) %100);
32623261
return true;
32633262
}
@@ -3334,7 +3333,7 @@ listTSParsersVerbose(const char *pattern)
33343333
if (PQntuples(res)==0)
33353334
{
33363335
if (!pset.quiet)
3337-
fprintf(stderr,_("Did not find any text search parser named \"%s\".\n"),
3336+
psql_error("Did not find any text search parser named \"%s\".\n",
33383337
pattern);
33393338
PQclear(res);
33403339
return false;
@@ -3490,7 +3489,7 @@ listTSDictionaries(const char *pattern, bool verbose)
34903489

34913490
if (pset.sversion<80300)
34923491
{
3493-
fprintf(stderr,_("The server (version %d.%d) does not support full text search.\n"),
3492+
psql_error("The server (version %d.%d) does not support full text search.\n",
34943493
pset.sversion /10000, (pset.sversion /100) %100);
34953494
return true;
34963495
}
@@ -3558,7 +3557,7 @@ listTSTemplates(const char *pattern, bool verbose)
35583557

35593558
if (pset.sversion<80300)
35603559
{
3561-
fprintf(stderr,_("The server (version %d.%d) does not support full text search.\n"),
3560+
psql_error("The server (version %d.%d) does not support full text search.\n",
35623561
pset.sversion /10000, (pset.sversion /100) %100);
35633562
return true;
35643563
}
@@ -3626,7 +3625,7 @@ listTSConfigs(const char *pattern, bool verbose)
36263625

36273626
if (pset.sversion<80300)
36283627
{
3629-
fprintf(stderr,_("The server (version %d.%d) does not support full text search.\n"),
3628+
psql_error("The server (version %d.%d) does not support full text search.\n",
36303629
pset.sversion /10000, (pset.sversion /100) %100);
36313630
return true;
36323631
}
@@ -3704,7 +3703,7 @@ listTSConfigsVerbose(const char *pattern)
37043703
if (PQntuples(res)==0)
37053704
{
37063705
if (!pset.quiet)
3707-
fprintf(stderr,_("Did not find any text search configuration named \"%s\".\n"),
3706+
psql_error("Did not find any text search configuration named \"%s\".\n",
37083707
pattern);
37093708
PQclear(res);
37103709
return false;
@@ -3824,7 +3823,7 @@ listForeignDataWrappers(const char *pattern, bool verbose)
38243823

38253824
if (pset.sversion<80400)
38263825
{
3827-
fprintf(stderr,_("The server (version %d.%d) does not support foreign-data wrappers.\n"),
3826+
psql_error("The server (version %d.%d) does not support foreign-data wrappers.\n",
38283827
pset.sversion /10000, (pset.sversion /100) %100);
38293828
return true;
38303829
}
@@ -3904,7 +3903,7 @@ listForeignServers(const char *pattern, bool verbose)
39043903

39053904
if (pset.sversion<80400)
39063905
{
3907-
fprintf(stderr,_("The server (version %d.%d) does not support foreign servers.\n"),
3906+
psql_error("The server (version %d.%d) does not support foreign servers.\n",
39083907
pset.sversion /10000, (pset.sversion /100) %100);
39093908
return true;
39103909
}
@@ -3983,7 +3982,7 @@ listUserMappings(const char *pattern, bool verbose)
39833982

39843983
if (pset.sversion<80400)
39853984
{
3986-
fprintf(stderr,_("The server (version %d.%d) does not support user mappings.\n"),
3985+
psql_error("The server (version %d.%d) does not support user mappings.\n",
39873986
pset.sversion /10000, (pset.sversion /100) %100);
39883987
return true;
39893988
}
@@ -4041,7 +4040,7 @@ listForeignTables(const char *pattern, bool verbose)
40414040

40424041
if (pset.sversion<90100)
40434042
{
4044-
fprintf(stderr,_("The server (version %d.%d) does not support foreign tables.\n"),
4043+
psql_error("The server (version %d.%d) does not support foreign tables.\n",
40454044
pset.sversion /10000, (pset.sversion /100) %100);
40464045
return true;
40474046
}
@@ -4115,7 +4114,7 @@ listExtensions(const char *pattern)
41154114

41164115
if (pset.sversion<90100)
41174116
{
4118-
fprintf(stderr,_("The server (version %d.%d) does not support extensions.\n"),
4117+
psql_error("The server (version %d.%d) does not support extensions.\n",
41194118
pset.sversion /10000, (pset.sversion /100) %100);
41204119
return true;
41214120
}
@@ -4169,7 +4168,7 @@ listExtensionContents(const char *pattern)
41694168

41704169
if (pset.sversion<90100)
41714170
{
4172-
fprintf(stderr,_("The server (version %d.%d) does not support extensions.\n"),
4171+
psql_error("The server (version %d.%d) does not support extensions.\n",
41734172
pset.sversion /10000, (pset.sversion /100) %100);
41744173
return true;
41754174
}
@@ -4196,10 +4195,10 @@ listExtensionContents(const char *pattern)
41964195
if (!pset.quiet)
41974196
{
41984197
if (pattern)
4199-
fprintf(stderr,_("Did not find any extension named \"%s\".\n"),
4198+
psql_error("Did not find any extension named \"%s\".\n",
42004199
pattern);
42014200
else
4202-
fprintf(stderr,_("Did not find any extensions.\n"));
4201+
psql_error("Did not find any extensions.\n");
42034202
}
42044203
PQclear(res);
42054204
return false;

‎src/bin/psql/large_obj.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ do_lo_export(const char *loid_arg, const char *filename_arg)
155155
/* of course this status is documented nowhere :( */
156156
if (status!=1)
157157
{
158-
fputs(PQerrorMessage(pset.db),stderr);
158+
psql_error("%s",PQerrorMessage(pset.db));
159159
returnfail_lo_xact("\\lo_export",own_transaction);
160160
}
161161

@@ -190,7 +190,7 @@ do_lo_import(const char *filename_arg, const char *comment_arg)
190190

191191
if (loid==InvalidOid)
192192
{
193-
fputs(PQerrorMessage(pset.db),stderr);
193+
psql_error("%s",PQerrorMessage(pset.db));
194194
returnfail_lo_xact("\\lo_import",own_transaction);
195195
}
196196

@@ -252,7 +252,7 @@ do_lo_unlink(const char *loid_arg)
252252

253253
if (status==-1)
254254
{
255-
fputs(PQerrorMessage(pset.db),stderr);
255+
psql_error("%s",PQerrorMessage(pset.db));
256256
returnfail_lo_xact("\\lo_unlink",own_transaction);
257257
}
258258

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp