Improve DB handling of duplicate values

Improve the exception thrown for duplicate values by including the
duplicate value.

Fixes #256