diff options
author | Tom Lane | 2008-08-16 01:36:35 +0000 |
---|---|---|
committer | Tom Lane | 2008-08-16 01:36:35 +0000 |
commit | 4be8ef46108b6b2ab02d4912514bb5cf47d14493 (patch) | |
tree | a057b0a76800ebbc9007bf3639f219d837f7331a | |
parent | 0a358a825b662c051ec0d238723779c77fc2c515 (diff) |
Fix a couple of places where psql might fail to report a suitable error
if PQexec returns NULL. These don't seem significant enough to be worth
back-patching, but they ought to get fixed ...
-rw-r--r-- | src/bin/psql/common.c | 39 | ||||
-rw-r--r-- | src/bin/psql/tab-complete.c | 6 |
2 files changed, 28 insertions, 17 deletions
diff --git a/src/bin/psql/common.c b/src/bin/psql/common.c index ab07516af3..3edf3d1ce1 100644 --- a/src/bin/psql/common.c +++ b/src/bin/psql/common.c @@ -880,16 +880,20 @@ SendQuery(const char *query) /* If we made a temporary savepoint, possibly release/rollback */ if (on_error_rollback_savepoint) { - PGresult *svptres; + const char *svptcmd; transaction_status = PQtransactionStatus(pset.db); - /* We always rollback on an error */ if (transaction_status == PQTRANS_INERROR) - svptres = PQexec(pset.db, "ROLLBACK TO pg_psql_temporary_savepoint"); - /* If they are no longer in a transaction, then do nothing */ + { + /* We always rollback on an error */ + svptcmd = "ROLLBACK TO pg_psql_temporary_savepoint"; + } else if (transaction_status != PQTRANS_INTRANS) - svptres = NULL; + { + /* If they are no longer in a transaction, then do nothing */ + svptcmd = NULL; + } else { /* @@ -901,20 +905,27 @@ SendQuery(const char *query) (strcmp(PQcmdStatus(results), "SAVEPOINT") == 0 || strcmp(PQcmdStatus(results), "RELEASE") == 0 || strcmp(PQcmdStatus(results), "ROLLBACK") == 0)) - svptres = NULL; + svptcmd = NULL; else - svptres = PQexec(pset.db, "RELEASE pg_psql_temporary_savepoint"); + svptcmd = "RELEASE pg_psql_temporary_savepoint"; } - if (svptres && PQresultStatus(svptres) != PGRES_COMMAND_OK) + + if (svptcmd) { - psql_error("%s", PQerrorMessage(pset.db)); - PQclear(results); + PGresult *svptres; + + svptres = PQexec(pset.db, svptcmd); + if (PQresultStatus(svptres) != PGRES_COMMAND_OK) + { + psql_error("%s", PQerrorMessage(pset.db)); + PQclear(svptres); + + PQclear(results); + ResetCancelConn(); + return false; + } PQclear(svptres); - ResetCancelConn(); - return false; } - - PQclear(svptres); } PQclear(results); diff --git a/src/bin/psql/tab-complete.c b/src/bin/psql/tab-complete.c index 5b75081b93..25f5735156 100644 --- a/src/bin/psql/tab-complete.c +++ b/src/bin/psql/tab-complete.c @@ -2577,11 +2577,11 @@ exec_query(const char *query) result = PQexec(pset.db, query); - if (result != NULL && PQresultStatus(result) != PGRES_TUPLES_OK) + if (PQresultStatus(result) != PGRES_TUPLES_OK) { #if 0 - psql_error("tab completion: %s failed - %s\n", - query, PQresStatus(PQresultStatus(result))); + psql_error("tab completion query failed: %s\nQuery was:\n%s\n", + PQerrorMessage(pset.db), query); #endif PQclear(result); result = NULL; |