Thanks for the Sybase syntax.
There's no execuse to not wrap your database modifying statements inside a transaction, and to not rollback on failure.
Nonetheless, I'll give you some.
I had error checking and transaction support in my test script, but I removed them on purpose.
- This post is focused on idioms, and I didn't want to burden the examples with something that doesn't belong there.
- Error checking is an idiom in itself. You can check for errors by testing the object, by creating a handle sub, by using eval. Depending on your needs, the error checking could take several shapes, and I have approached this subject elsewhere.
- Transactions are not a mandatory DBI feature. The DBI can deal with the big boys (Oracle, MS SQL, IBM DB2, and so on) but it can also handle DBF files, Excel spreadsheets, CSV files, and others where transactions are not supported.
- When transactions are supported, while it is true that every update BELONGS TO a transaction, it is not true that every update IS a transaction (Update meaning that the transaction-related code could be around a group of statements rather than around a single one.) So, in addition to my goal of keeping the code focused on the example, I didn't want to give the impression that the transaction code is necessary for that particular idiom to work.
_ _ _ _
(_|| | |(_|><