Method write_all to write items to the DB

- untested in GUI
- various tests fail: unwritten sanity checks
- exceptions in write_all may have side-effects down the road (should
  use transactions)
A section belongs to a chapter in the DB
Added sanity-checks for writing data to the DB