Skip site navigation (1) Skip section navigation (2)

Re: rollback to savepoint leads to transaction already in progress

From: Itagaki Takahiro <itagaki(dot)takahiro(at)gmail(dot)com>
To: David Newall <postgresql(at)davidnewall(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Cc: pgsql-bugs(at)postgresql(dot)org
Subject: Re: rollback to savepoint leads to transaction already in progress
Date: 2010-10-14 01:44:50
Message-ID: AANLkTik91fy2ER0ydxxE4ZJOLXtBbfoDmQ8DQfqF5815@mail.gmail.com (view raw or flat)
Thread:
Lists: pgsql-bugspgsql-hackers
On Mon, Oct 11, 2010 at 7:42 AM, David Newall
<postgresql(at)davidnewall(dot)com> wrote:
> Trivial program to demonstrate problem:
>
> main() {
>    ECPGdebug(1,stderr);
>    exec sql connect to postgres;
>    exec sql set autocommit to off;
>    exec sql start transaction;
>    exec sql savepoint s;
>    exec sql rollback to s;
>    exec sql commit;
>    return 0;
> }
>
> Output:
> [28397]: ECPGdebug: set to 1
> [28397]: ECPGconnect: opening database postgres on <DEFAULT> port <DEFAULT>
> [28397]: ECPGsetcommit on line 4: action "off"; connection "postgres"
> [28397]: ECPGtrans on line 5: action "start transaction"; connection "postgres"
> [28397]: ECPGtrans on line 6: action "savepoint s"; connection "postgres"
> [28397]: ECPGtrans on line 7: action "rollback to s"; connection "postgres"
> [28397]: ECPGtrans on line 8: action "commit"; connection "postgres"
> [28397]: ECPGnoticeReceiver: there is already a transaction in progress
> [28397]: raising sqlcode -603
>
> Problem:
> It shouldn't raise "there is already a transaction in progress" error,
> particularly when doing a commit.  Remove "rollback to s" and no problem.
>
> Environment:
> ecpg (PostgreSQL 8.4.5) 4.5.0
> This appears to be a regression; it doesn't occur with ecpg (PostgreSQL
> 8.3.8) 4.4.1

The bug comes from string-based transaction control in ECPGtrans().
The code cannot distinguish ROLLBACK TRANSACTION and ROLLBACK TO savepoint.
----
if (strncmp(transaction, "commit", 6) == 0 || strncmp(transaction,
"rollback", 8) == 0)
    con->committed = true;
else
    con->committed = false;
----

I think the string-comparison is unreliable. So, I'd like to replace
the code to use PQtransactionStatus(). I have two patches to do it:
The first one (ecpg-trans-quick_20101014.patch) is a quick fix
that replaces only the above test.
The second one (ecpg-trans-full_20101014.patch) replaces all of
struct connection->committed with PQtransactionStatus().

Which solution is better? Or, another idea?

-- 
Itagaki Takahiro

Attachment: ecpg-trans-quick_20101014.patch
Description: application/octet-stream (650 bytes)
Attachment: ecpg-trans-full_20101014.patch
Description: application/octet-stream (5.2 KB)

In response to

Responses

pgsql-hackers by date

Next:From: Itagaki TakahiroDate: 2010-10-14 02:03:16
Subject: Re: string function - "format" function proposal
Previous:From: Andrew GeeryDate: 2010-10-14 01:41:46
Subject: Re: Re: starting to review the Extend NOT NULL representation to pg_constraint patch

pgsql-bugs by date

Next:From: David NewallDate: 2010-10-14 06:52:25
Subject: Re: rollback to savepoint leads to transaction already in progress
Previous:From: Robert HaasDate: 2010-10-14 01:16:03
Subject: Re: BUG #5694: Postgres ODBC SQLTables is not working correctly

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group