33 *
44 * Copyright (c) 2000-2008, PostgreSQL Global Development Group
55 *
6- * $PostgreSQL: pgsql/src/bin/psql/common.c,v 1.139 2008/05/14 19:10:29 tgl Exp $
6+ * $PostgreSQL: pgsql/src/bin/psql/common.c,v 1.140 2008/08/16 01:36:35 tgl Exp $
77 */
88#include "postgres_fe.h"
99#include "common.h"
@@ -880,16 +880,20 @@ SendQuery(const char *query)
880880/* If we made a temporary savepoint, possibly release/rollback */
881881if (on_error_rollback_savepoint )
882882{
883- PGresult * svptres ;
883+ const char * svptcmd ;
884884
885885transaction_status = PQtransactionStatus (pset .db );
886886
887- /* We always rollback on an error */
888887if (transaction_status == PQTRANS_INERROR )
889- svptres = PQexec (pset .db ,"ROLLBACK TO pg_psql_temporary_savepoint" );
890- /* If they are no longer in a transaction, then do nothing */
888+ {
889+ /* We always rollback on an error */
890+ svptcmd = "ROLLBACK TO pg_psql_temporary_savepoint" ;
891+ }
891892else if (transaction_status != PQTRANS_INTRANS )
892- svptres = NULL ;
893+ {
894+ /* If they are no longer in a transaction, then do nothing */
895+ svptcmd = NULL ;
896+ }
893897else
894898{
895899/*
@@ -901,20 +905,27 @@ SendQuery(const char *query)
901905(strcmp (PQcmdStatus (results ),"SAVEPOINT" )== 0 ||
902906strcmp (PQcmdStatus (results ),"RELEASE" )== 0 ||
903907strcmp (PQcmdStatus (results ),"ROLLBACK" )== 0 ))
904- svptres = NULL ;
908+ svptcmd = NULL ;
905909else
906- svptres = PQexec ( pset . db , "RELEASE pg_psql_temporary_savepoint" ) ;
910+ svptcmd = "RELEASE pg_psql_temporary_savepoint" ;
907911}
908- if (svptres && PQresultStatus (svptres )!= PGRES_COMMAND_OK )
912+
913+ if (svptcmd )
909914{
910- psql_error ("%s" ,PQerrorMessage (pset .db ));
911- PQclear (results );
915+ PGresult * svptres ;
916+
917+ svptres = PQexec (pset .db ,svptcmd );
918+ if (PQresultStatus (svptres )!= PGRES_COMMAND_OK )
919+ {
920+ psql_error ("%s" ,PQerrorMessage (pset .db ));
921+ PQclear (svptres );
922+
923+ PQclear (results );
924+ ResetCancelConn ();
925+ return false;
926+ }
912927PQclear (svptres );
913- ResetCancelConn ();
914- return false;
915928}
916-
917- PQclear (svptres );
918929}
919930
920931PQclear (results );