The problem was that the affinity change from '1' to 1 on the PRIMARY KEY
column was happening on the first constraint check in bytecode order, which
is the UNIQUE constraint.  But the PRIMARY KEY constraint was checked first,
and hence was checked before the affinity change.  The fix was to move the
affinity change to before the branch that reorders the constraint checks
for the UPSERT.