/ Check-in [5c0eaea6]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Some UPDATE statements now working in WITHOUT ROWID tables.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | omit-rowid
Files: files | file ages | folders
SHA1: 5c0eaea6a26b5c3310d96b3c896ac3068a3ebad1
User & Date: drh 2013-11-01 12:42:21
Context
2013-11-01
14:03
Improved VDBE comments on the constraint checker. Fix a missing write lock in the UPDATE logic. check-in: 3bed599e user: drh tags: omit-rowid
12:42
Some UPDATE statements now working in WITHOUT ROWID tables. check-in: 5c0eaea6 user: drh tags: omit-rowid
01:45
A couple of bug fixes. check-in: cdf00248 user: drh tags: omit-rowid
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/insert.c.

  1470   1470                            regIdx, pIdx->nKeyCol);
  1471   1471       if( HasRowid(pTab) ){
  1472   1472         sqlite3VdbeAddOp2(v, OP_IdxRowid, iThisCur, regR);
  1473   1473         /* Conflict only if the rowid of the existing index entry
  1474   1474         ** is different from old-rowid */
  1475   1475         sqlite3VdbeAddOp3(v, OP_Eq, regR, addrUniqueOk, regOldData);
  1476   1476       }else{
         1477  +      int x;
  1477   1478         /* Extract the PRIMARY KEY from the end of the index entry and
  1478   1479         ** store it in register regR..regR+nPk-1 */
  1479   1480         for(i=0; i<pPk->nKeyCol; i++){
  1480         -        int x = sqlite3ColumnOfIndex(pIdx, pPk->aiColumn[i]);
         1481  +        x = sqlite3ColumnOfIndex(pIdx, pPk->aiColumn[i]);
  1481   1482           sqlite3VdbeAddOp3(v, OP_Column, iThisCur, x, regR+i);
  1482   1483           VdbeComment((v, "%s.%s", pTab->zName,
  1483   1484                        pTab->aCol[pPk->aiColumn[i]].zName));
  1484   1485         }
  1485   1486         if( pIdx->autoIndex==2 ){
  1486   1487           /* For a PRIMARY KEY index on a WITHOUT ROWID table, always conflict
  1487   1488           ** on an INSERT.  On an UPDATE, only conflict if the PRIMARY KEY
  1488   1489           ** has changed. */
  1489   1490           if( isUpdate ){
  1490   1491             int addrPkConflict = sqlite3VdbeCurrentAddr(v)+pPk->nKeyCol;
  1491   1492             for(i=0; i<pPk->nKeyCol-1; i++){
  1492         -            sqlite3VdbeAddOp3(v, OP_Ne, regOldData+pPk->aiColumn[i]+1,
  1493         -                              addrPkConflict, regIdx+i);
         1493  +            x = pPk->aiColumn[i];
         1494  +            sqlite3VdbeAddOp3(v, OP_Ne, regOldData+1+x,
         1495  +                              addrPkConflict, regIdx+x);
  1494   1496             }
  1495         -          sqlite3VdbeAddOp3(v, OP_Eq, regOldData+pPk->aiColumn[i]+1,
  1496         -                            addrUniqueOk, regIdx+i);
         1497  +          x = pPk->aiColumn[i];
         1498  +          sqlite3VdbeAddOp3(v, OP_Eq, regOldData+1+x, addrUniqueOk, regIdx+x);
  1497   1499           }
  1498   1500         }else{
  1499   1501           /* For a UNIQUE index on a WITHOUT ROWID table, conflict only if the
  1500   1502           ** PRIMARY KEY value of the match is different from the old PRIMARY KEY
  1501   1503           ** value from before the update. */
  1502   1504           int addrConflict = sqlite3VdbeCurrentAddr(v)+pPk->nKeyCol;
  1503   1505           assert( pIdx->nKeyCol + pPk->nKeyCol == pIdx->nColumn );

Changes to src/update.c.

   532    532       /* Do FK constraint checks. */
   533    533       if( hasFK ){
   534    534         sqlite3FkCheck(pParse, pTab, regOldRowid, 0, aXRef, chngPk);
   535    535       }
   536    536   
   537    537       /* Delete the index entries associated with the current record.  */
   538    538       if( pPk ){
   539         -      j1 = sqlite3VdbeAddOp3(v, OP_NotFound, iDataCur, 0, regOldRowid);
          539  +      j1 = sqlite3VdbeAddOp4Int(v, OP_NotFound, iDataCur, 0, regKey, 0);
   540    540       }else{
   541    541         j1 = sqlite3VdbeAddOp3(v, OP_NotExists, iDataCur, 0, regOldRowid);
   542    542       }
   543    543       sqlite3GenerateRowIndexDelete(pParse, pTab, iDataCur, iIdxCur, aRegIdx);
   544    544     
   545    545       /* If changing the record number, delete the old record.  */
   546    546       if( hasFK || chngPk ){