Fix database value mapping.

Commit 77482bfc7557a3c886ab63020da69b8b5400cab1 switched percent values
to be interpreted as unsigned int.
Fixup invalid value handling.

Instead of using magic values, use a dedicated validity flag. This
allows setting integer values as invalid; previously the value type was
wrong for invalid integers (the float value NaN was stored instead of an
unsigned int).