开发者

How to use transactions in Informix CSDK and OIC++

I'开发者_如何学JAVAd need some advice how to handle transactions with Informix CSDK and OIC++.

conn is a open connection object. Select works find. The database here is setup with logging — as I found out while update stmt on its own does nothing.

Here's what I tried:

        conn.SetTransaction( ITConnection::BEGIN );
        qtext = "UPDATE transit_kunde_s SET erledigt='Y' WHERE transitkunde='"+ts+"'";
        cout << qtext << endl;

        code = query_up.ExecForStatus(qtext.c_str());
        cout << "code " << code << endl;
        conn.SetTransaction( ITConnection::COMMIT );


okay once again I answer myself...

from Informix C++ DocNotes

Operations can now be performed on large objects within a fetched row even though the connection is still checked out (locked). A connection is checked out after the ITQuery::ExecForIteration() method returns multiple rows in the result set. It remains checked out until either the last row in the result set has been fetched with ITQuery::NextRow() or the query processing has been terminated by calling ITQuery::Finish(). While a connection is checked out, no other query can be executed on that connection.

So as I am in the while loop of one query result iteration I need for another update query a new connection

// already have 2 connection objects: conn, conn2

ITQuery query(conn);
ITQuery query_up(conn2);

string qtext;
qtext = "SELECT * FROM transit_kunde_s WHERE erledigt='N' ORDER BY transitkunde";
okay = query.ExecForIteration(qtext.c_str());

while (row = query.NextRow()) {
  // do stuff

  // NOW WANT TO DO ANOTHER QUERY? --> NEED ANOTHER CONNECTION!!
  ok_ta = conn2.SetTransaction( ITConnection::BEGIN);
  qtext = "UPDATE transit_kunde_s SET erledigt='Y' WHERE transitkunde='"+ts+"'";
  code = query_up.ExecForStatus(qtext.c_str());
  ok_ta = conn2.SetTransaction( ITConnection::COMMIT );

 }

// we see later the 1st query to be finished here
query.Finish();
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜