Commit 816b008e authored by Michael Meskes's avatar Michael Meskes

Applied patch by Itagaki Takahiro to fix incorrect status calculation in

ecpglib. Instead of parsing the statement just as ask the database server. This
patch removes the whole client side track keeping of the current transaction
status.
parent 1a996d6c
...@@ -167,25 +167,23 @@ ECPGsetcommit(int lineno, const char *mode, const char *connection_name) ...@@ -167,25 +167,23 @@ ECPGsetcommit(int lineno, const char *mode, const char *connection_name)
if (con->autocommit == true && strncmp(mode, "off", strlen("off")) == 0) 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"); results = PQexec(con->connection, "begin transaction");
if (!ecpg_check_PQresult(results, lineno, con->connection, ECPG_COMPAT_PGSQL)) if (!ecpg_check_PQresult(results, lineno, con->connection, ECPG_COMPAT_PGSQL))
return false; return false;
PQclear(results); PQclear(results);
con->committed = false;
} }
con->autocommit = false; con->autocommit = false;
} }
else if (con->autocommit == false && strncmp(mode, "on", strlen("on")) == 0) 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"); results = PQexec(con->connection, "commit");
if (!ecpg_check_PQresult(results, lineno, con->connection, ECPG_COMPAT_PGSQL)) if (!ecpg_check_PQresult(results, lineno, con->connection, ECPG_COMPAT_PGSQL))
return false; return false;
PQclear(results); PQclear(results);
con->committed = true;
} }
con->autocommit = true; con->autocommit = true;
} }
...@@ -540,7 +538,6 @@ ECPGconnect(int lineno, int c, const char *name, const char *user, const char *p ...@@ -540,7 +538,6 @@ ECPGconnect(int lineno, int c, const char *name, const char *user, const char *p
pthread_mutex_unlock(&connections_mutex); pthread_mutex_unlock(&connections_mutex);
#endif #endif
this->committed = true;
this->autocommit = autocommit; this->autocommit = autocommit;
PQsetNoticeReceiver(this->connection, &ECPGnoticeReceiver, (void *) this); PQsetNoticeReceiver(this->connection, &ECPGnoticeReceiver, (void *) this);
......
...@@ -1427,7 +1427,7 @@ ecpg_execute(struct statement * stmt) ...@@ -1427,7 +1427,7 @@ ecpg_execute(struct statement * stmt)
/* The request has been build. */ /* 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"); results = PQexec(stmt->connection->connection, "begin transaction");
if (!ecpg_check_PQresult(results, stmt->lineno, stmt->connection->connection, stmt->compat)) if (!ecpg_check_PQresult(results, stmt->lineno, stmt->connection->connection, stmt->compat))
...@@ -1436,7 +1436,6 @@ ecpg_execute(struct statement * stmt) ...@@ -1436,7 +1436,6 @@ ecpg_execute(struct statement * stmt)
return false; return false;
} }
PQclear(results); 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); 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);
......
...@@ -76,7 +76,6 @@ struct connection ...@@ -76,7 +76,6 @@ struct connection
{ {
char *name; char *name;
PGconn *connection; PGconn *connection;
bool committed;
int autocommit; int autocommit;
struct ECPGtype_information_cache *cache_head; struct ECPGtype_information_cache *cache_head;
struct prepared_statement *prep_stmts; struct prepared_statement *prep_stmts;
......
...@@ -206,7 +206,7 @@ ECPGtrans(int lineno, const char *connection_name, const char *transaction) ...@@ -206,7 +206,7 @@ ECPGtrans(int lineno, const char *connection_name, const char *transaction)
* developers have to take care themselves. However, if the command is * developers have to take care themselves. However, if the command is
* a begin statement, we just execute it once. * 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"); 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))
...@@ -218,11 +218,6 @@ ECPGtrans(int lineno, const char *connection_name, const char *transaction) ...@@ -218,11 +218,6 @@ ECPGtrans(int lineno, const char *connection_name, const char *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; return FALSE;
PQclear(res); PQclear(res);
if (strncmp(transaction, "commit", 6) == 0 || strncmp(transaction, "rollback", 8) == 0)
con->committed = true;
else
con->committed = false;
} }
return true; return true;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment