X-Original-To: pgsql-odbc-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 234409DC9E2 for ; Fri, 20 Jan 2006 09:23:46 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 64137-09 for ; Fri, 20 Jan 2006 09:23:48 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from smtp.pzkagis.cz (gis6.netbox.cz [83.240.30.214]) by postgresql.org (Postfix) with ESMTP id C8F3B9DC820 for ; Fri, 20 Jan 2006 09:23:42 -0400 (AST) Received: from soptik.pzkagis.cz (localhost.localdomain [127.0.0.1]) by smtp.pzkagis.cz (8.13.1/8.13.1) with ESMTP id k0KDMwok019872; Fri, 20 Jan 2006 14:22:58 +0100 Received: (from luf@localhost) by soptik.pzkagis.cz (8.13.1/8.13.1/Submit) id k0KDMvMw019871; Fri, 20 Jan 2006 14:22:57 +0100 Date: Fri, 20 Jan 2006 14:22:57 +0100 From: Ludek Finstrle To: Marc Herbert Cc: pgsql-odbc@postgresql.org Subject: patch: BEGIN and autocommit(false) Message-ID: <20060120132257.GA19840@soptik.pzkagis.cz> References: <43CF0B0B.6000101@necas.nec.com.cn> <20060119111957.GA31571@soptik.pzkagis.cz> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="x+6KMIRAuhnl3hBn" Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.4.1i X-Virus-Scanned: ClamAV version 0.87.1, clamav-milter version 0.87 on smtp.pzkagis.cz X-Virus-Status: Clean X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.081 required=5 tests=[AWL=0.081] X-Spam-Score: 0.081 X-Spam-Level: X-Archive-Number: 200601/197 X-Sequence-Number: 7012 --x+6KMIRAuhnl3hBn Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Thu, Jan 19, 2006 at 03:03:54PM +0100, Marc Herbert wrote: > Ludek Finstrle writes: > >> 1. set SQL_AUTOCOMMIT_OFF > > > > Yes you do ... When you use autocommit = off you have to start and end > > transaction manually. > > Wrong: in ODBC, you just have to "end" transactions manually, you > don't have to start them, they are implicitely started when the > previous one ends. > > In ODBC (and JDBC), you are ALWAYS inside a transaction, there is no > such thing as a transactional "no man's land" from an ODBC interface > point of view (internal, hidden implementation details may differ). I hope I solve this issue in psqlodbc driver. Thank you Marc for pointing me the right way. Patch attached (it's created againist 08.01.0107 development snapshot, not againist CVS). This patch depend on psqlodbc-implicit_rollback.diff one. Please review and comment Luf --x+6KMIRAuhnl3hBn Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="psqlodbc-autocommit_off_begin.diff" diff -c psqlodbc.orig\statement.c psqlodbc\statement.c *** psqlodbc.orig\statement.c Fri Jan 20 14:09:35 2006 --- psqlodbc\statement.c Fri Jan 20 15:15:06 2006 *************** *** 71,76 **** --- 71,79 ---- STMT_TYPE_LOCK, "LOCK" }, { + STMT_TYPE_BEGIN, "BEGIN" + }, + { 0, NULL } }; *************** *** 423,428 **** --- 426,441 ---- if (!strnicmp(statement, Statement_Type[i].s, strlen(Statement_Type[i].s))) return Statement_Type[i].type; + /* determine START TRANSACTION */ + if (!strnicmp(statement, "START", 5)) + { + statement += 5; + /* ignore whitespace in query string */ + while (*statement && isspace((UCHAR) *statement)) + statement++; + if (!strnicmp(statement, "TRANSACTION", 11)) + return STMT_TYPE_BEGIN; + } return STMT_TYPE_OTHER; } *************** *** 1148,1154 **** QueryInfo qi; ConnInfo *ci; UDWORD qflag = 0; ! BOOL auto_begin = FALSE, is_in_trans; int func_cs_count = 0; --- 1161,1167 ---- QueryInfo qi; ConnInfo *ci; UDWORD qflag = 0; ! BOOL is_in_trans; int func_cs_count = 0; *************** *** 1175,1184 **** is_in_trans = CC_is_in_trans(conn); if (!self->internal && !is_in_trans && (SC_is_fetchcursor(self) || ! (!CC_is_in_autocommit(conn) && self->statement_type != STMT_TYPE_OTHER))) { mylog(" about to begin a transaction on statement = %u\n", self); - auto_begin = TRUE; if (PG_VERSION_GE(conn, 7.1)) qflag |= GO_INTO_TRANSACTION; else if (!CC_begin(conn)) --- 1188,1196 ---- is_in_trans = CC_is_in_trans(conn); if (!self->internal && !is_in_trans && (SC_is_fetchcursor(self) || ! (!CC_is_in_autocommit(conn) && self->statement_type != STMT_TYPE_BEGIN))) { mylog(" about to begin a transaction on statement = %u\n", self); if (PG_VERSION_GE(conn, 7.1)) qflag |= GO_INTO_TRANSACTION; else if (!CC_begin(conn)) *************** *** 1252,1258 **** */ if (CC_is_in_trans(conn)) { ! if (!is_in_trans && !auto_begin) CC_set_in_manual_trans(conn); if (!self->internal && CC_is_in_autocommit(conn) && !CC_is_in_manual_trans(conn)) CC_commit(conn); --- 1264,1270 ---- */ if (CC_is_in_trans(conn)) { ! if (!is_in_trans) CC_set_in_manual_trans(conn); if (!self->internal && CC_is_in_autocommit(conn) && !CC_is_in_manual_trans(conn)) CC_commit(conn); diff -c psqlodbc.orig\statement.h psqlodbc\statement.h *** psqlodbc.orig\statement.h Wed Nov 30 13:44:37 2005 --- psqlodbc\statement.h Fri Jan 20 15:07:21 2006 *************** *** 96,102 **** STMT_TYPE_GRANT, STMT_TYPE_REVOKE, STMT_TYPE_PROCCALL, ! STMT_TYPE_LOCK }; #define STMT_UPDATE(stmt) (stmt->statement_type > STMT_TYPE_SELECT) --- 96,103 ---- STMT_TYPE_GRANT, STMT_TYPE_REVOKE, STMT_TYPE_PROCCALL, ! STMT_TYPE_LOCK, ! STMT_TYPE_BEGIN }; #define STMT_UPDATE(stmt) (stmt->statement_type > STMT_TYPE_SELECT) --x+6KMIRAuhnl3hBn--