[Libpqxx-general] Transaction status
Jeroen T. Vermeulen
jtv at xs4all.nl
Sun Jul 12 07:07:11 UTC 2009
On Thu, July 9, 2009 19:03, Maxime van Noppen wrote:
> I'm in a situation where I would like to know the status of the
> transaction (aborted, connected, ...). To be more accurate, I'd like a
> status() function returning the m_Status variable of the transaction.
>
> This has two purposes :
>
> - to be able to anticipate usage_error (like committing an aborted
> transaction or so);
> - help writing recovery code
>
> Is there a reason why I shouldn't want this ?
There's a smell of danger to this. The workings of transaction status
isn't always completely obvious, so I'm worried that more people will
shoot themselves in the foot with it than will get real use from it. It
gets worse if the state machine ever needs changing (maybe for a 2pc
implementation or something).
Getting into the details some more, it's not clear to me how you would
anticipate usage_error or how the status would help write recovery code,
beyond what the exceptions already tell you.
I do see how it might sometimes be inconvenient to keep track of status if
you want it in different places than where exception control flow takes
you. Maybe we can help your use case by exposing a simpler subset of
status, e.g. "in error / in doubt / okay"?
But before we get to that, I'd be interested to know a bit more about what
you're trying to do, so that I can see if there is really a sufficient
argument to rely on data flow instead of control flow in the first place.
Jeroen
More information about the Libpqxx-general
mailing list