/ 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 Unified Diffs Ignore Whitespace Patch

Changes to src/insert.c.

1470
1471
1472
1473
1474
1475
1476

1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491

1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
                         regIdx, pIdx->nKeyCol);
    if( HasRowid(pTab) ){
      sqlite3VdbeAddOp2(v, OP_IdxRowid, iThisCur, regR);
      /* Conflict only if the rowid of the existing index entry
      ** is different from old-rowid */
      sqlite3VdbeAddOp3(v, OP_Eq, regR, addrUniqueOk, regOldData);
    }else{

      /* Extract the PRIMARY KEY from the end of the index entry and
      ** store it in register regR..regR+nPk-1 */
      for(i=0; i<pPk->nKeyCol; i++){
        int x = sqlite3ColumnOfIndex(pIdx, pPk->aiColumn[i]);
        sqlite3VdbeAddOp3(v, OP_Column, iThisCur, x, regR+i);
        VdbeComment((v, "%s.%s", pTab->zName,
                     pTab->aCol[pPk->aiColumn[i]].zName));
      }
      if( pIdx->autoIndex==2 ){
        /* For a PRIMARY KEY index on a WITHOUT ROWID table, always conflict
        ** on an INSERT.  On an UPDATE, only conflict if the PRIMARY KEY
        ** has changed. */
        if( isUpdate ){
          int addrPkConflict = sqlite3VdbeCurrentAddr(v)+pPk->nKeyCol;
          for(i=0; i<pPk->nKeyCol-1; i++){

            sqlite3VdbeAddOp3(v, OP_Ne, regOldData+pPk->aiColumn[i]+1,
                              addrPkConflict, regIdx+i);
          }
          sqlite3VdbeAddOp3(v, OP_Eq, regOldData+pPk->aiColumn[i]+1,
                            addrUniqueOk, regIdx+i);
        }
      }else{
        /* For a UNIQUE index on a WITHOUT ROWID table, conflict only if the
        ** PRIMARY KEY value of the match is different from the old PRIMARY KEY
        ** value from before the update. */
        int addrConflict = sqlite3VdbeCurrentAddr(v)+pPk->nKeyCol;
        assert( pIdx->nKeyCol + pPk->nKeyCol == pIdx->nColumn );







>



|











>
|
|

|
|







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

Changes to src/update.c.

532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
    /* Do FK constraint checks. */
    if( hasFK ){
      sqlite3FkCheck(pParse, pTab, regOldRowid, 0, aXRef, chngPk);
    }

    /* Delete the index entries associated with the current record.  */
    if( pPk ){
      j1 = sqlite3VdbeAddOp3(v, OP_NotFound, iDataCur, 0, regOldRowid);
    }else{
      j1 = sqlite3VdbeAddOp3(v, OP_NotExists, iDataCur, 0, regOldRowid);
    }
    sqlite3GenerateRowIndexDelete(pParse, pTab, iDataCur, iIdxCur, aRegIdx);
  
    /* If changing the record number, delete the old record.  */
    if( hasFK || chngPk ){







|







532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
    /* Do FK constraint checks. */
    if( hasFK ){
      sqlite3FkCheck(pParse, pTab, regOldRowid, 0, aXRef, chngPk);
    }

    /* Delete the index entries associated with the current record.  */
    if( pPk ){
      j1 = sqlite3VdbeAddOp4Int(v, OP_NotFound, iDataCur, 0, regKey, 0);
    }else{
      j1 = sqlite3VdbeAddOp3(v, OP_NotExists, iDataCur, 0, regOldRowid);
    }
    sqlite3GenerateRowIndexDelete(pParse, pTab, iDataCur, iIdxCur, aRegIdx);
  
    /* If changing the record number, delete the old record.  */
    if( hasFK || chngPk ){