Skip to content

Commit

Permalink
Fix pgsql_begin after breaking it in a previous PR (#754)
Browse files Browse the repository at this point in the history
The statement type needs to be set to MULTI before running BEGIN.
  • Loading branch information
JelteF committed Jul 6, 2021
1 parent 093572f commit 0556bf1
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions src/bin/pg_autoctl/pgsql.c
Original file line number Diff line number Diff line change
Expand Up @@ -873,20 +873,24 @@ pgAutoCtlDebugNoticeProcessor(void *arg, const char *message)
bool
pgsql_begin(PGSQL *pgsql)
{
/*
* Indicate that we're running a transaction, so that the connection is not
* closed after each query automatically. It also allows us to detect bugs
* easily. We need to do this before executing BEGIN, because otherwise the
* connection is closed after the BEGIN statement automatically.
*/
pgsql->connectionStatementType = PGSQL_CONNECTION_MULTI_STATEMENT;

if (!pgsql_execute(pgsql, "BEGIN"))
{
/*
* connection is closed by pgsql_execute already, so no need for
* further cleanup.
* We need to manually call pgsql_finish to clean up here in case of
* this failure, because we have set the statement type to MULTI.
*/
pgsql_finish(pgsql);
return false;
}

/*
* Indicate that we're in a transaction so that we can detect bugs easily.
*/
pgsql->connectionStatementType = PGSQL_CONNECTION_MULTI_STATEMENT;

return true;
}

Expand Down

0 comments on commit 0556bf1

Please sign in to comment.