|
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 $ */ |
2 | 2 |
|
3 | 3 | #define POSTGRES_ECPG_INTERNAL
|
4 | 4 | #include "postgres_fe.h"
|
@@ -186,31 +186,35 @@ ECPGtrans(int lineno, const char *connection_name, const char *transaction)
|
186 | 186 | /* if we have no connection we just simulate the command */
|
187 | 187 | if (con && con->connection)
|
188 | 188 | {
|
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. |
192 | 193 | */
|
193 |
| - if (!con->committed || con->autocommit) |
| 194 | + if (con->committed && !con->autocommit && strncmp(transaction, "begin", 5) != 0 && strncmp(transaction, "start", 5) != 0) |
194 | 195 | {
|
195 |
| - if ((res = PQexec(con->connection, transaction)) == NULL) |
| 196 | + res = PQexec(con->connection, "begin transaction"); |
| 197 | + if (res == NULL || PQresultStatus(res) != PGRES_COMMAND_OK) |
196 | 198 | {
|
197 | 199 | ECPGraise(lineno, ECPG_TRANS, ECPG_SQLSTATE_TRANSACTION_RESOLUTION_UNKNOWN, NULL);
|
198 | 200 | return FALSE;
|
199 | 201 | }
|
200 | 202 | PQclear(res);
|
201 | 203 | }
|
| 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); |
202 | 212 | }
|
203 | 213 |
|
204 | 214 | if (strcmp(transaction, "commit") == 0 || strcmp(transaction, "rollback") == 0)
|
205 |
| - { |
206 | 215 | 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; |
214 | 218 |
|
215 | 219 | return true;
|
216 | 220 | }
|
|
0 commit comments