Untested refactoring to pull out as much boilerplate as possible for all the sgg-db-* commands.