diff options
author | Michael Meskes <meskes@postgresql.org> | 2005-09-12 11:58:33 +0000 |
---|---|---|
committer | Michael Meskes <meskes@postgresql.org> | 2005-09-12 11:58:33 +0000 |
commit | 39f27463b352a32dbb88cb0c3cf89d0a4535d562 (patch) | |
tree | 29fea64bc5ce84acbe5bf52cdc62b4d2133e7162 /src | |
parent | 3e711451f17e12daa15bf492e01dff9e76244e21 (diff) | |
download | postgresql-39f27463b352a32dbb88cb0c3cf89d0a4535d562.tar.gz postgresql-39f27463b352a32dbb88cb0c3cf89d0a4535d562.zip |
Fixed transaction command handling to not ignore savepoints and to correctly check for errors.
Diffstat (limited to 'src')
-rw-r--r-- | src/interfaces/ecpg/ecpglib/misc.c | 32 |
1 files changed, 18 insertions, 14 deletions
diff --git a/src/interfaces/ecpg/ecpglib/misc.c b/src/interfaces/ecpg/ecpglib/misc.c index 709fd56f8ff..a0998c3bda3 100644 --- a/src/interfaces/ecpg/ecpglib/misc.c +++ b/src/interfaces/ecpg/ecpglib/misc.c @@ -1,4 +1,4 @@ -/* $PostgreSQL: pgsql/src/interfaces/ecpg/ecpglib/misc.c,v 1.24 2004/10/14 20:23:46 momjian Exp $ */ +/* $PostgreSQL: pgsql/src/interfaces/ecpg/ecpglib/misc.c,v 1.24.4.1 2005/09/12 11:58:33 meskes Exp $ */ #define POSTGRES_ECPG_INTERNAL #include "postgres_fe.h" @@ -186,31 +186,35 @@ ECPGtrans(int lineno, const char *connection_name, const char *transaction) /* if we have no connection we just simulate the command */ if (con && con->connection) { - /* - * if we are not in autocommit mode, already have committed the - * transaction and get another commit, just ignore it + /* If we got a transaction command but have no open transaction, + * we have to start one, unless we are in autocommit, where the + * developers have to take care themselves. + * However, if the command is a begin statement, we just execute it once. */ - if (!con->committed || con->autocommit) + if (con->committed && !con->autocommit && strncmp(transaction, "begin", 5) != 0 && strncmp(transaction, "start", 5) != 0) { - if ((res = PQexec(con->connection, transaction)) == NULL) + res = PQexec(con->connection, "begin transaction"); + if (res == NULL || PQresultStatus(res) != PGRES_COMMAND_OK) { ECPGraise(lineno, ECPG_TRANS, ECPG_SQLSTATE_TRANSACTION_RESOLUTION_UNKNOWN, NULL); return FALSE; } PQclear(res); } + + res = PQexec(con->connection, transaction); + if (res == NULL || PQresultStatus(res) != PGRES_COMMAND_OK) + { + ECPGraise(lineno, ECPG_TRANS, ECPG_SQLSTATE_TRANSACTION_RESOLUTION_UNKNOWN, NULL); + return FALSE; + } + PQclear(res); } if (strcmp(transaction, "commit") == 0 || strcmp(transaction, "rollback") == 0) - { con->committed = true; - -#if 0 - /* deallocate all prepared statements */ - if (!ECPGdeallocate_all(lineno)) - return false; -#endif - } + else + con->committed = false; return true; } |