Fix the handling of "PRAGMA count_changes=ON" with UPSERT. Also improved