if (con->autocommit == true && strncmp(mode, "off", strlen("off")) == 0)
{
- if (con->committed)
+ if (PQtransactionStatus(con->connection) == PQTRANS_IDLE)
{
results = PQexec(con->connection, "begin transaction");
if (!ecpg_check_PQresult(results, lineno, con->connection, ECPG_COMPAT_PGSQL))
return false;
PQclear(results);
- con->committed = false;
}
con->autocommit = false;
}
else if (con->autocommit == false && strncmp(mode, "on", strlen("on")) == 0)
{
- if (!con->committed)
+ if (PQtransactionStatus(con->connection) != PQTRANS_IDLE)
{
results = PQexec(con->connection, "commit");
if (!ecpg_check_PQresult(results, lineno, con->connection, ECPG_COMPAT_PGSQL))
return false;
PQclear(results);
- con->committed = true;
}
con->autocommit = true;
}
pthread_mutex_unlock(&connections_mutex);
#endif
- this->committed = true;
this->autocommit = autocommit;
PQsetNoticeReceiver(this->connection, &ECPGnoticeReceiver, (void *) this);
/* The request has been build. */
- if (stmt->connection->committed && !stmt->connection->autocommit)
+ if (PQtransactionStatus(stmt->connection->connection) == PQTRANS_IDLE && !stmt->connection->autocommit)
{
results = PQexec(stmt->connection->connection, "begin transaction");
if (!ecpg_check_PQresult(results, stmt->lineno, stmt->connection->connection, stmt->compat))
return false;
}
PQclear(results);
- stmt->connection->committed = false;
}
ecpg_log("ecpg_execute on line %d: query: %s; with %d parameter(s) on connection %s\n", stmt->lineno, stmt->command, nParams, stmt->connection->name);
{
char *name;
PGconn *connection;
- bool committed;
int autocommit;
struct ECPGtype_information_cache *cache_head;
struct prepared_statement *prep_stmts;
* developers have to take care themselves. However, if the command is
* a begin statement, we just execute it once.
*/
- if (con->committed && !con->autocommit && strncmp(transaction, "begin", 5) != 0 && strncmp(transaction, "start", 5) != 0)
+ if (PQtransactionStatus(con->connection) == PQTRANS_IDLE && !con->autocommit && strncmp(transaction, "begin", 5) != 0 && strncmp(transaction, "start", 5) != 0)
{
res = PQexec(con->connection, "begin transaction");
if (!ecpg_check_PQresult(res, lineno, con->connection, ECPG_COMPAT_PGSQL))
if (!ecpg_check_PQresult(res, lineno, con->connection, ECPG_COMPAT_PGSQL))
return FALSE;
PQclear(res);
-
- if (strncmp(transaction, "commit", 6) == 0 || strncmp(transaction, "rollback", 8) == 0)
- con->committed = true;
- else
- con->committed = false;
}
return true;