Ad-hoc database queries