Hello.
Does it seem right to send "COMMIT" without checking whether any of
the queries I've done in the transaction failed?
Here is pseudo code illustrating this behaviour where "COMMIT" is
always sent no matter what result of do_some_queries() was:
some_transaction(Conn)
{
query(Conn, "BEGIN"),
try do_some_queries(Conn)
catch
Reason ->
Reason
after
query(Conn, "COMMIT")
end
}
Is this correct? What if there is a select from non-existing table
inside do_some_queries()? Should I detect it (e.g. by thrown an
exception) and do ROLLBACK as the following code does:
some_transaction(Conn)
{
try query(Conn, "BEGIN"),
do_some_queries(Conn),
query(Conn, "COMMIT")
catch
Reason ->
query(Conn, "ROLLBACK"),
Reason
end
}
First sample seems more elegant, but I'm not sure that it's safe. Will
there be any problems with this in the future?
Thanks.
--
Sergey Samokhin