Skip to content

Commit 0556bf1

Browse files
authored
Fix pgsql_begin after breaking it in a previous PR (#754)
The statement type needs to be set to MULTI before running BEGIN.
1 parent 093572f commit 0556bf1

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

src/bin/pg_autoctl/pgsql.c

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -873,20 +873,24 @@ pgAutoCtlDebugNoticeProcessor(void *arg, const char *message)
873873
bool
874874
pgsql_begin(PGSQL *pgsql)
875875
{
876+
/*
877+
* Indicate that we're running a transaction, so that the connection is not
878+
* closed after each query automatically. It also allows us to detect bugs
879+
* easily. We need to do this before executing BEGIN, because otherwise the
880+
* connection is closed after the BEGIN statement automatically.
881+
*/
882+
pgsql->connectionStatementType = PGSQL_CONNECTION_MULTI_STATEMENT;
883+
876884
if (!pgsql_execute(pgsql, "BEGIN"))
877885
{
878886
/*
879-
* connection is closed by pgsql_execute already, so no need for
880-
* further cleanup.
887+
* We need to manually call pgsql_finish to clean up here in case of
888+
* this failure, because we have set the statement type to MULTI.
881889
*/
890+
pgsql_finish(pgsql);
882891
return false;
883892
}
884893

885-
/*
886-
* Indicate that we're in a transaction so that we can detect bugs easily.
887-
*/
888-
pgsql->connectionStatementType = PGSQL_CONNECTION_MULTI_STATEMENT;
889-
890894
return true;
891895
}
892896

0 commit comments

Comments
 (0)