33 *
44 * Copyright (c) 2000-2006, PostgreSQL Global Development Group
55 *
6- * $PostgreSQL: pgsql/src/bin/psql/common.c,v 1.119 2006/06/14 16:49:02 tgl Exp $
6+ * $PostgreSQL: pgsql/src/bin/psql/common.c,v 1.120 2006/06/30 15:06:05 alvherre Exp $
77 */
88#include "postgres_fe.h"
99#include "common.h"
@@ -875,19 +875,19 @@ SendQuery(const char *query)
875875if (OK )
876876OK = PrintQueryResults (results );
877877
878- PQclear (results );
879-
880878/* If we made a temporary savepoint, possibly release/rollback */
881879if (on_error_rollback_savepoint )
882880{
881+ PGresult * svptres ;
882+
883883transaction_status = PQtransactionStatus (pset .db );
884884
885885/* We always rollback on an error */
886886if (transaction_status == PQTRANS_INERROR )
887- results = PQexec (pset .db ,"ROLLBACK TO pg_psql_temporary_savepoint" );
887+ svptres = PQexec (pset .db ,"ROLLBACK TO pg_psql_temporary_savepoint" );
888888/* If they are no longer in a transaction, then do nothing */
889889else if (transaction_status != PQTRANS_INTRANS )
890- results = NULL ;
890+ svptres = NULL ;
891891else
892892{
893893/*
@@ -898,20 +898,22 @@ SendQuery(const char *query)
898898if (strcmp (PQcmdStatus (results ),"SAVEPOINT" )== 0 ||
899899strcmp (PQcmdStatus (results ),"RELEASE" )== 0 ||
900900strcmp (PQcmdStatus (results ),"ROLLBACK" )== 0 )
901- results = NULL ;
901+ svptres = NULL ;
902902else
903- results = PQexec (pset .db ,"RELEASE pg_psql_temporary_savepoint" );
903+ svptres = PQexec (pset .db ,"RELEASE pg_psql_temporary_savepoint" );
904904}
905- if (PQresultStatus (results )!= PGRES_COMMAND_OK )
905+ if (svptres && PQresultStatus (svptres )!= PGRES_COMMAND_OK )
906906{
907907psql_error ("%s" ,PQerrorMessage (pset .db ));
908908PQclear (results );
909+ PQclear (svptres );
909910ResetCancelConn ();
910911return false;
911912}
912- PQclear (results );
913913}
914914
915+ PQclear (results );
916+
915917/* Possible microtiming output */
916918if (OK && pset .timing )
917919printf (_ ("Time: %.3f ms\n" ),DIFF_MSEC (& after ,& before ));