move more SQL code to ::DB