Transactionalizing the SQL and improving error handling/reporting… (partially complete).