Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit c959d37

Browse files
author
Michael Meskes
committed
Fixed transaction command handling to not ignore savepoints and to correctly check for errors.
1 parent 4fe4563 commit c959d37

File tree

2 files changed

+24
-15
lines changed

2 files changed

+24
-15
lines changed

src/interfaces/ecpg/ChangeLog

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1933,8 +1933,13 @@ Thu Jun 2 14:22:32 CEST 2005
19331933
Wed Aug 24 12:17:48 CEST 2005
19341934

19351935
- Check for NULL before checking whether argument is an array.
1936-
- Removed stray character from string quoting.
1936+
- Remove stray character from string quoting.
19371937
- Fixed check to report missing varchar pointer implementation.
1938+
1939+
Mon Sep 12 13:53:35 CEST 2005
1940+
1941+
- Fixed transaction command handling to not ignore savepoints
1942+
and to correctly check for errors.
19381943
- Set ecpg library version to 5.1.
19391944
- Set ecpg version to 4.1.1.
19401945

src/interfaces/ecpg/ecpglib/misc.c

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* $PostgreSQL: pgsql/src/interfaces/ecpg/ecpglib/misc.c,v 1.24 2004/10/14 20:23:46 momjian Exp $ */
1+
/* $PostgreSQL: pgsql/src/interfaces/ecpg/ecpglib/misc.c,v 1.25 2005/09/12 11:57:53 meskes Exp $ */
22

33
#define POSTGRES_ECPG_INTERNAL
44
#include "postgres_fe.h"
@@ -186,31 +186,35 @@ ECPGtrans(int lineno, const char *connection_name, const char *transaction)
186186
/* if we have no connection we just simulate the command */
187187
if (con && con->connection)
188188
{
189-
/*
190-
* if we are not in autocommit mode, already have committed the
191-
* transaction and get another commit, just ignore it
189+
/* If we got a transaction command but have no open transaction,
190+
* we have to start one, unless we are in autocommit, where the
191+
* developers have to take care themselves.
192+
* However, if the command is a begin statement, we just execute it once.
192193
*/
193-
if (!con->committed || con->autocommit)
194+
if (con->committed && !con->autocommit && strncmp(transaction, "begin", 5) != 0 && strncmp(transaction, "start", 5) != 0)
194195
{
195-
if ((res = PQexec(con->connection, transaction)) == NULL)
196+
res = PQexec(con->connection, "begin transaction");
197+
if (res == NULL || PQresultStatus(res) != PGRES_COMMAND_OK)
196198
{
197199
ECPGraise(lineno, ECPG_TRANS, ECPG_SQLSTATE_TRANSACTION_RESOLUTION_UNKNOWN, NULL);
198200
return FALSE;
199201
}
200202
PQclear(res);
201203
}
204+
205+
res = PQexec(con->connection, transaction);
206+
if (res == NULL || PQresultStatus(res) != PGRES_COMMAND_OK)
207+
{
208+
ECPGraise(lineno, ECPG_TRANS, ECPG_SQLSTATE_TRANSACTION_RESOLUTION_UNKNOWN, NULL);
209+
return FALSE;
210+
}
211+
PQclear(res);
202212
}
203213

204214
if (strcmp(transaction, "commit") == 0 || strcmp(transaction, "rollback") == 0)
205-
{
206215
con->committed = true;
207-
208-
#if 0
209-
/* deallocate all prepared statements */
210-
if (!ECPGdeallocate_all(lineno))
211-
return false;
212-
#endif
213-
}
216+
else
217+
con->committed = false;
214218

215219
return true;
216220
}

0 commit comments

Comments
 (0)