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

Transactions from Visual C++

From: <Christof(dot)Paal(at)nc3a(dot)nato(dot)int>
To: <pgsql-bugs(at)postgresql(dot)org>
Subject: Transactions from Visual C++
Date: 2006-08-23 12:31:17
Message-ID: 0BA4071DEA3E9F4D9F691DB89D3A53E80189E3B8@exchangeth8.nl.nc3a (view raw or flat)
Thread:
Lists: pgsql-bugs
Hi,

I noticed that the database engine does not let you implement your own
transaction logic from Microsoft VC++ applications.
The database automatically rolls back when the first error occurs, not
the way it is programmed.

Consider the following example:

void RunMyQuery(CDatabase* pDB, LPCTSTR lpszSQL)
{
 try { pDB->ExecuteSQL(lpszSQL); } 
 catch (CDBException* pEx)
 { pEx->ReportError(); pEx->Delete(); }
}

void test()
{
 CDatabase* pDB = NULL; // TODO: open connection to postgreSQL here
 pDB->BeginTrans();
 RunMyQuery(pDB,"INSERT INTO mytable (mycol) VALUES ('a');");
 RunMyQuery(pDB,"INSERT INTO mytable (mycol) VALUES ('b');");
 RunMyQuery(pDB,"INSERT INTO mytable (mycol) VALUES ('c');");
 RunMyQuery(pDB,"INSERT INTO mytable (mycol) VALUES ('d');");
 RunMyQuery(pDB,"INSERT INTO mytable (mycol) VALUES ('e');");
 pDB->Rollback();
}

Let us assume that the second statement fails because value 'b' is
illegal.
Either the ODBC driver or the DBMS now rejects all follow-on queries
with the error message:
        Error while executing the query;
        ERROR:  current transaction is aborted, commands ignored until
end of transaction block

I would have expected that it would still be possible to run queries
inside this transaction (in fact, the same code continues to run in
Sybase and MSSQL Server).
Otherwise it is not possible to write your own transaction logic or your
own error handling in this environment.

I am using PostgreSQL 8.1.4 under Windows XP SP 2 and connecting with
the PostgreSQL ANSI ODBC driver.

Regards,

Christof Paal
 
Senior Scientist
Application Developement Branch
Operations Research Division
NATO C3 Agency

Responses

pgsql-bugs by date

Next:From: Evgeny GridasovDate: 2006-08-23 15:13:12
Subject: BUG #2588: rename table and dump bug
Previous:From: Peter EisentrautDate: 2006-08-22 21:30:58
Subject: Re: [BUGS] BUG #2585: Please provide pkg-config support

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