db.py: added in location, foreign id and output file methods

Also their associated tests in test_db.py