Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
P
postgres-lambda-diff
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Jakob Huber
postgres-lambda-diff
Commits
0e6d72db
Commit
0e6d72db
authored
25 years ago
by
Tom Lane
Browse files
Options
Downloads
Patches
Plain Diff
Make PSQLexec's behavior on loss of connection more reasonable;
report original error before attempting reset, not after.
parent
19ff2e4d
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/bin/psql/common.c
+36
-25
36 additions, 25 deletions
src/bin/psql/common.c
with
36 additions
and
25 deletions
src/bin/psql/common.c
+
36
−
25
View file @
0e6d72db
...
@@ -364,34 +364,43 @@ PSQLexec(PsqlSettings *pset, const char *query)
...
@@ -364,34 +364,43 @@ PSQLexec(PsqlSettings *pset, const char *query)
pqsignal
(
SIGINT
,
SIG_DFL
);
/* now control-C is back to normal */
pqsignal
(
SIGINT
,
SIG_DFL
);
/* now control-C is back to normal */
if
(
PQstatus
(
pset
->
db
)
==
CONNECTION_BAD
)
if
(
PQstatus
(
pset
->
db
)
==
CONNECTION_OK
)
{
fputs
(
"The connection to the server was lost. Attempting reset: "
,
stderr
);
PQreset
(
pset
->
db
);
if
(
PQstatus
(
pset
->
db
)
==
CONNECTION_BAD
)
{
fputs
(
"Failed.
\n
"
,
stderr
);
PQfinish
(
pset
->
db
);
PQclear
(
res
);
pset
->
db
=
NULL
;
return
NULL
;
}
else
fputs
(
"Succeeded.
\n
"
,
stderr
);
}
if
(
res
&&
(
PQresultStatus
(
res
)
==
PGRES_COMMAND_OK
||
PQresultStatus
(
res
)
==
PGRES_TUPLES_OK
||
PQresultStatus
(
res
)
==
PGRES_COPY_IN
||
PQresultStatus
(
res
)
==
PGRES_COPY_OUT
)
)
return
res
;
else
{
{
if
(
res
&&
(
PQresultStatus
(
res
)
==
PGRES_COMMAND_OK
||
PQresultStatus
(
res
)
==
PGRES_TUPLES_OK
||
PQresultStatus
(
res
)
==
PGRES_COPY_IN
||
PQresultStatus
(
res
)
==
PGRES_COPY_OUT
)
)
return
res
;
/* Normal success case... */
/* Normal failure case --- display error and return NULL */
fputs
(
PQerrorMessage
(
pset
->
db
),
pset
->
queryFout
);
fputs
(
PQerrorMessage
(
pset
->
db
),
pset
->
queryFout
);
PQclear
(
res
);
PQclear
(
res
);
return
NULL
;
return
NULL
;
}
}
/* Lost connection. Report whatever libpq has to say,
* then consider recovery.
*/
fputs
(
PQerrorMessage
(
pset
->
db
),
pset
->
queryFout
);
PQclear
(
res
);
if
(
!
pset
->
cur_cmd_interactive
)
{
fprintf
(
stderr
,
"%s: connection to server was lost
\n
"
,
pset
->
progname
);
exit
(
EXIT_BADCONN
);
}
fputs
(
"The connection to the server was lost. Attempting reset: "
,
stderr
);
fflush
(
stderr
);
PQreset
(
pset
->
db
);
if
(
PQstatus
(
pset
->
db
)
==
CONNECTION_BAD
)
{
fputs
(
"Failed.
\n
"
,
stderr
);
PQfinish
(
pset
->
db
);
pset
->
db
=
NULL
;
}
else
fputs
(
"Succeeded.
\n
"
,
stderr
);
return
NULL
;
}
}
...
@@ -517,17 +526,19 @@ SendQuery(PsqlSettings *pset, const char *query)
...
@@ -517,17 +526,19 @@ SendQuery(PsqlSettings *pset, const char *query)
{
{
if
(
!
pset
->
cur_cmd_interactive
)
if
(
!
pset
->
cur_cmd_interactive
)
{
{
fprintf
(
stderr
,
"%s: connection to server was lost"
,
pset
->
progname
);
fprintf
(
stderr
,
"%s: connection to server was lost
\n
"
,
pset
->
progname
);
exit
(
EXIT_BADCONN
);
exit
(
EXIT_BADCONN
);
}
}
fputs
(
"The connection to the server was lost. Attempting reset: "
,
stderr
);
fputs
(
"The connection to the server was lost. Attempting reset: "
,
stderr
);
fflush
(
stderr
);
PQreset
(
pset
->
db
);
PQreset
(
pset
->
db
);
if
(
PQstatus
(
pset
->
db
)
==
CONNECTION_BAD
)
if
(
PQstatus
(
pset
->
db
)
==
CONNECTION_BAD
)
{
{
fputs
(
"Failed.
\n
"
,
stderr
);
fputs
(
"Failed.
\n
"
,
stderr
);
PQfinish
(
pset
->
db
);
PQfinish
(
pset
->
db
);
PQclear
(
results
);
pset
->
db
=
NULL
;
pset
->
db
=
NULL
;
PQclear
(
results
);
return
false
;
return
false
;
}
}
else
else
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment