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

I am still not certain about why the database has ``NULL`` in it instead of ''.

I used ``sqlite3`` on my computer to create a fake table.
```
CREATE TABLE People(Name VARCHAR(25));
```
Then ran: ``INSERT INTO People(Name) VALUES();`` but received a syntax error. So I could only complete the command as ``INSERT INTO People(Name) VALUES('');`` which creates a name with the value '' in the database.