@@ -746,16 +746,18 @@ QueryInfo qi;
746746conn = SC_get_conn (self );
747747
748748/*Begin a transaction if one is not already in progress */
749- /*The reason is because we can't use declare/fetch cursors without
750- starting a transaction first.
751-
752- A transaction should be begun if and only if
753- we use declare/fetch and the statement is SELECT
754- or we are not in autocommit state
755- We assume that the Postgres backend has an autocommit
756- feature as default. (Zoltan Kovacs, 04/26/2000)
757- */
758- if ( !self -> internal && !CC_is_in_trans (conn )&& ((globals .use_declarefetch && self -> statement_type == STMT_TYPE_SELECT )|| !CC_is_in_autocommit (conn ))) {
749+ /*
750+ Basically we don't have to begin a transaction in
751+ autocommit mode because Postgres backend runs in
752+ autocomit mode.
753+ We issue "BEGIN" in the following cases.
754+ 1) we use declare/fetch and the statement is SELECT
755+ (because declare/fetch must be called in a transaction).
756+ 2) we are not in autocommit state and the statement
757+ is of type UPDATE.
758+ */
759+ if ( !self -> internal && !CC_is_in_trans (conn )&&
760+ ((globals .use_declarefetch && self -> statement_type == STMT_TYPE_SELECT )|| (!CC_is_in_autocommit (conn )&& STMT_UPDATE (self )))) {
759761
760762mylog (" about to begin a transaction on statement = %u\n" ,self );
761763res = CC_send_query (conn ,"BEGIN" ,NULL );
@@ -802,7 +804,8 @@ QueryInfo qi;
802804/*send the declare/select */
803805self -> result = CC_send_query (conn ,self -> stmt_with_params ,NULL );
804806
805- if (globals .use_declarefetch && self -> result != NULL ) {
807+ if (globals .use_declarefetch && self -> result != NULL &&
808+ QR_command_successful (self -> result )) {
806809
807810QR_Destructor (self -> result );
808811
@@ -834,6 +837,15 @@ QueryInfo qi;
834837/*We shouldn't send COMMIT. Postgres backend does the
835838autocommit if neccessary. (Zoltan, 04/26/2000)
836839*/
840+ /*Even in case of autocommit, started transactions
841+ must be committed. (Hiroshi, 09/02/2001)
842+ */
843+ if ( !self -> internal && CC_is_in_autocommit (conn )&& CC_is_in_trans (conn )&& STMT_UPDATE (self )) {
844+ res = CC_send_query (conn ,"COMMIT" ,NULL );
845+ QR_Destructor (res );
846+ CC_set_no_trans (conn );
847+ }
848+
837849}
838850
839851conn -> status = oldstatus ;
@@ -867,7 +879,9 @@ QueryInfo qi;
867879return SQL_ERROR ;
868880}
869881}
870-
882+ /* in autocommit mode declare/fetch error must be aborted */
883+ if ( !was_ok && !self -> internal && CC_is_in_autocommit (conn )&& CC_is_in_trans (conn ))
884+ CC_abort (conn );
871885}else {/* Bad Error -- The error message will be in the Connection */
872886
873887if (self -> statement_type == STMT_TYPE_CREATE ) {