@@ -297,7 +297,7 @@ repack_all_databases(const char *orderby)
297
297
}
298
298
}
299
299
300
- PQclear (result );
300
+ CLEARPGRES (result );
301
301
}
302
302
303
303
/* result is not copied */
@@ -403,7 +403,7 @@ repack_one_database(const char *orderby, char *errbuf, size_t errsize)
403
403
}
404
404
goto cleanup ;
405
405
}
406
- PQclear (res );
406
+ CLEARPGRES (res );
407
407
408
408
/* Disable statement timeout. */
409
409
command ("SET statement_timeout = 0" , 0 , NULL );
@@ -528,8 +528,7 @@ repack_one_database(const char *orderby, char *errbuf, size_t errsize)
528
528
ret = true;
529
529
530
530
cleanup :
531
- if (res )
532
- PQclear (res );
531
+ CLEARPGRES (res );
533
532
disconnect ();
534
533
termStringInfo (& sql );
535
534
return ret ;
@@ -554,7 +553,7 @@ apply_log(PGconn *conn, const repack_table *table, int count)
554
553
"SELECT repack.repack_apply($1, $2, $3, $4, $5, $6)" ,
555
554
6 , params );
556
555
result = atoi (PQgetvalue (res , 0 , 0 ));
557
- PQclear (res );
556
+ CLEARPGRES (res );
558
557
559
558
return result ;
560
559
}
@@ -630,11 +629,10 @@ repack_one_table(const repack_table *table, const char *orderby)
630
629
(errcode (E_PG_COMMAND ),
631
630
errmsg ("trigger %s conflicted for %s" ,
632
631
PQgetvalue (res , 0 , 0 ), table -> target_name )));
633
- PQclear (res );
634
632
have_error = true;
635
633
goto cleanup ;
636
634
}
637
- PQclear (res );
635
+ CLEARPGRES (res );
638
636
639
637
command (table -> create_pktype , 0 , NULL );
640
638
command (table -> create_log , 0 , NULL );
@@ -658,13 +656,12 @@ repack_one_table(const repack_table *table, const char *orderby)
658
656
if (PQresultStatus (res ) != PGRES_TUPLES_OK )
659
657
{
660
658
printf ("%s" , PQerrorMessage (conn2 ));
661
- PQclear (res );
662
659
have_error = true;
663
660
goto cleanup ;
664
661
}
665
662
buffer [0 ] = '\0' ;
666
663
strncat (buffer , PQgetvalue (res , 0 , 0 ), sizeof (buffer ) - 1 );
667
- PQclear (res );
664
+ CLEARPGRES (res );
668
665
669
666
/*
670
667
* Not using lock_access_share() here since we know that
@@ -718,11 +715,10 @@ repack_one_table(const repack_table *table, const char *orderby)
718
715
if (PQresultStatus (res ) != PGRES_COMMAND_OK )
719
716
{
720
717
elog (WARNING , "Error with LOCK TABLE: %s" , PQerrorMessage (conn2 ));
721
- PQclear (res );
722
718
have_error = true;
723
719
goto cleanup ;
724
720
}
725
- PQclear (res );
721
+ CLEARPGRES (res );
726
722
}
727
723
728
724
/*
@@ -749,11 +745,10 @@ repack_one_table(const repack_table *table, const char *orderby)
749
745
{
750
746
elog (WARNING , "Unable to allocate vxid, length: %d\n" ,
751
747
PQgetlength (res , 0 , 0 ));
752
- PQclear (res );
753
748
have_error = true;
754
749
goto cleanup ;
755
750
}
756
- PQclear (res );
751
+ CLEARPGRES (res );
757
752
758
753
/* Delete any existing entries in the log table now, since we have not
759
754
* yet run the CREATE TABLE ... AS SELECT, which will take in all existing
@@ -827,7 +822,7 @@ repack_one_table(const repack_table *table, const char *orderby)
827
822
*/
828
823
command (index .create_index , 0 , NULL );
829
824
}
830
- PQclear (res );
825
+ CLEARPGRES (res );
831
826
832
827
/*
833
828
* 4. Apply log to temp table until no tuples are left in the log
@@ -858,15 +853,15 @@ repack_one_table(const repack_table *table, const char *orderby)
858
853
num_waiting = num ;
859
854
}
860
855
861
- PQclear (res );
856
+ CLEARPGRES (res );
862
857
sleep (1 );
863
858
continue ;
864
859
}
865
860
else
866
861
{
867
862
/* All old transactions are finished;
868
863
* go to next step. */
869
- PQclear (res );
864
+ CLEARPGRES (res );
870
865
break ;
871
866
}
872
867
}
@@ -918,6 +913,7 @@ repack_one_table(const repack_table *table, const char *orderby)
918
913
}
919
914
920
915
cleanup :
916
+ CLEARPGRES (res );
921
917
termStringInfo (& sql );
922
918
if (vxid )
923
919
free (vxid );
@@ -959,7 +955,7 @@ kill_ddl(PGconn *conn, Oid relid, bool terminate)
959
955
"Canceled %d unsafe queries. Terminating any remaining PIDs." ,
960
956
PQntuples (res ));
961
957
962
- PQclear (res );
958
+ CLEARPGRES (res );
963
959
printfStringInfo (& sql , KILL_COMPETING_LOCKS , relid );
964
960
res = pgut_execute (conn , sql .data , 0 , NULL );
965
961
if (PQresultStatus (res ) != PGRES_TUPLES_OK )
@@ -974,7 +970,7 @@ kill_ddl(PGconn *conn, Oid relid, bool terminate)
974
970
else
975
971
elog (DEBUG2 , "No competing DDL to cancel." );
976
972
977
- PQclear (res );
973
+ CLEARPGRES (res );
978
974
termStringInfo (& sql );
979
975
980
976
return ret ;
@@ -1034,21 +1030,21 @@ lock_access_share(PGconn *conn, Oid relid, const char *target_name)
1034
1030
res = pgut_execute_elevel (conn , sql .data , 0 , NULL , DEBUG2 );
1035
1031
if (PQresultStatus (res ) == PGRES_COMMAND_OK )
1036
1032
{
1037
- PQclear (res );
1033
+ CLEARPGRES (res );
1038
1034
break ;
1039
1035
}
1040
1036
else if (sqlstate_equals (res , SQLSTATE_QUERY_CANCELED ))
1041
1037
{
1042
1038
/* retry if lock conflicted */
1043
- PQclear (res );
1039
+ CLEARPGRES (res );
1044
1040
pgut_rollback (conn );
1045
1041
continue ;
1046
1042
}
1047
1043
else
1048
1044
{
1049
1045
/* exit otherwise */
1050
1046
elog (WARNING , "%s" , PQerrorMessage (connection ));
1051
- PQclear (res );
1047
+ CLEARPGRES (res );
1052
1048
ret = false;
1053
1049
break ;
1054
1050
}
@@ -1120,21 +1116,21 @@ lock_exclusive(PGconn *conn, const char *relid, const char *lock_query, bool sta
1120
1116
res = pgut_execute_elevel (conn , lock_query , 0 , NULL , DEBUG2 );
1121
1117
if (PQresultStatus (res ) == PGRES_COMMAND_OK )
1122
1118
{
1123
- PQclear (res );
1119
+ CLEARPGRES (res );
1124
1120
break ;
1125
1121
}
1126
1122
else if (sqlstate_equals (res , SQLSTATE_QUERY_CANCELED ))
1127
1123
{
1128
1124
/* retry if lock conflicted */
1129
- PQclear (res );
1125
+ CLEARPGRES (res );
1130
1126
pgut_rollback (conn );
1131
1127
continue ;
1132
1128
}
1133
1129
else
1134
1130
{
1135
1131
/* exit otherwise */
1136
1132
printf ("%s" , PQerrorMessage (connection ));
1137
- PQclear (res );
1133
+ CLEARPGRES (res );
1138
1134
ret = false;
1139
1135
break ;
1140
1136
}
0 commit comments