Checks SQL query results for errors and bails out if it finds one. Avoids some heavy code duplication all over the place.