unit test and refactor database.py part 2

Add unit tests and refactor/fix/document issues related to the database.
(Part 2, because #619 grew too large.)

Related #484
Related #619

Hm. One issue I have caused is the date, starttime, endtime in the talkeditor table are now showing the funky timestamp values instead of human readable times..