Typo.
History fixes.

- Error checking for DB->associate.

- Before adding a new history entry, check for an existing one in the
  same transaction.  This avoids a panic when re-adding a history entry
  causes a duplicate in the secondary database. (Unlike normal databases,
  DB_KEYEXIST is not returned in this case.)