Change SELECT to not trigger "BEGIN" in not autocommit mode.
This commit is contained in:
parent
dfbd5d6532
commit
5a03b0c393
@ -746,16 +746,18 @@ QueryInfo qi;
|
|||||||
conn = SC_get_conn(self);
|
conn = SC_get_conn(self);
|
||||||
|
|
||||||
/* Begin a transaction if one is not already in progress */
|
/* Begin a transaction if one is not already in progress */
|
||||||
/* The reason is because we can't use declare/fetch cursors without
|
/*
|
||||||
starting a transaction first.
|
Basically we don't have to begin a transaction in
|
||||||
|
autocommit mode because Postgres backend runs in
|
||||||
A transaction should be begun if and only if
|
autocomit mode.
|
||||||
we use declare/fetch and the statement is SELECT
|
We issue "BEGIN" in the following cases.
|
||||||
or we are not in autocommit state
|
1) we use declare/fetch and the statement is SELECT
|
||||||
We assume that the Postgres backend has an autocommit
|
(because declare/fetch must be called in a transaction).
|
||||||
feature as default. (Zoltan Kovacs, 04/26/2000)
|
2) we are not in autocommit state and the statement
|
||||||
*/
|
is of type UPDATE.
|
||||||
if ( ! self->internal && ! CC_is_in_trans(conn) && ((globals.use_declarefetch && self->statement_type == STMT_TYPE_SELECT) || ! CC_is_in_autocommit(conn))) {
|
*/
|
||||||
|
if ( ! self->internal && ! CC_is_in_trans(conn) &&
|
||||||
|
((globals.use_declarefetch && self->statement_type == STMT_TYPE_SELECT) || (! CC_is_in_autocommit(conn) && STMT_UPDATE(self)))) {
|
||||||
|
|
||||||
mylog(" about to begin a transaction on statement = %u\n", self);
|
mylog(" about to begin a transaction on statement = %u\n", self);
|
||||||
res = CC_send_query(conn, "BEGIN", NULL);
|
res = CC_send_query(conn, "BEGIN", NULL);
|
||||||
@ -802,7 +804,8 @@ QueryInfo qi;
|
|||||||
/* send the declare/select */
|
/* send the declare/select */
|
||||||
self->result = CC_send_query(conn, self->stmt_with_params, NULL);
|
self->result = CC_send_query(conn, self->stmt_with_params, NULL);
|
||||||
|
|
||||||
if (globals.use_declarefetch && self->result != NULL) {
|
if (globals.use_declarefetch && self->result != NULL &&
|
||||||
|
QR_command_successful(self->result)) {
|
||||||
|
|
||||||
QR_Destructor(self->result);
|
QR_Destructor(self->result);
|
||||||
|
|
||||||
@ -834,6 +837,15 @@ QueryInfo qi;
|
|||||||
/* We shouldn't send COMMIT. Postgres backend does the
|
/* We shouldn't send COMMIT. Postgres backend does the
|
||||||
autocommit if neccessary. (Zoltan, 04/26/2000)
|
autocommit if neccessary. (Zoltan, 04/26/2000)
|
||||||
*/
|
*/
|
||||||
|
/* Even in case of autocommit, started transactions
|
||||||
|
must be committed. (Hiroshi, 09/02/2001)
|
||||||
|
*/
|
||||||
|
if ( ! self->internal && CC_is_in_autocommit(conn) && CC_is_in_trans(conn) && STMT_UPDATE(self)) {
|
||||||
|
res = CC_send_query(conn, "COMMIT", NULL);
|
||||||
|
QR_Destructor(res);
|
||||||
|
CC_set_no_trans(conn);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
conn->status = oldstatus;
|
conn->status = oldstatus;
|
||||||
@ -867,7 +879,9 @@ QueryInfo qi;
|
|||||||
return SQL_ERROR;
|
return SQL_ERROR;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
/* in autocommit mode declare/fetch error must be aborted */
|
||||||
|
if ( ! was_ok && ! self->internal && CC_is_in_autocommit(conn) && CC_is_in_trans(conn))
|
||||||
|
CC_abort(conn);
|
||||||
} else { /* Bad Error -- The error message will be in the Connection */
|
} else { /* Bad Error -- The error message will be in the Connection */
|
||||||
|
|
||||||
if (self->statement_type == STMT_TYPE_CREATE) {
|
if (self->statement_type == STMT_TYPE_CREATE) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user