DB: add prev_state check to change_state diagnosis

Commit 4a9a141b0c831d8001afc72a5ddd1a1e15c7c1b9 introduced a check
for failure to update a row when changing the state to its current
value.  However when performing this test we also need to be sure
that the reason for failure was not that the previous state did
not match if specified.