Index: src/insert.c ================================================================== --- src/insert.c +++ src/insert.c @@ -1433,16 +1433,18 @@ /* Create a record for this index entry as it should appear after ** the insert or update. */ regIdx = sqlite3GetTempRange(pParse, pIdx->nColumn); for(i=0; inColumn; i++){ int iField = pIdx->aiColumn[i]; + int x; if( iField<0 || iField==pTab->iPKey ){ - iField = regNewData; + x = regNewData; }else{ - iField += regNewData + 1; + x = iField + regNewData + 1; } - sqlite3VdbeAddOp2(v, OP_SCopy, iField, regIdx+i); + sqlite3VdbeAddOp2(v, OP_SCopy, x, regIdx+i); + VdbeComment((v, "%s", iField<0 ? "rowid" : pTab->aCol[iField].zName)); } sqlite3VdbeAddOp3(v, OP_MakeRecord, regIdx, pIdx->nColumn, aRegIdx[ix]); sqlite3VdbeChangeP4(v, -1, sqlite3IndexAffinityStr(v, pIdx), P4_TRANSIENT); VdbeComment((v, "for %s", pIdx->zName)); sqlite3ExprCacheAffinityChange(pParse, regIdx, pIdx->nColumn); Index: src/update.c ================================================================== --- src/update.c +++ src/update.c @@ -385,10 +385,11 @@ ** to be deleting some records. */ if( !okOnePass && HasRowid(pTab) ){ sqlite3OpenTable(pParse, iDataCur, iDb, pTab, OP_OpenWrite); } + sqlite3TableLock(pParse, iDb, pTab->tnum, 1, pTab->zName); if( onError==OE_Replace ){ openAll = 1; }else{ openAll = 0; for(pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext){