/ Check-in [d3c53fd3]
Login

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

Overview
Comment:Get upsert working on WITHOUT ROWID tables.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | upsert
Files: files | file ages | folders
SHA3-256: d3c53fd3177946f50137d48da871de43d78d10ef9990cc4ea6750f7020f89b6a
User & Date: drh 2018-04-14 22:35:34
Context
2018-04-16
10:47
Merge changes from trunk. check-in: 54d96772 user: drh tags: upsert
2018-04-14
22:35
Get upsert working on WITHOUT ROWID tables. check-in: d3c53fd3 user: drh tags: upsert
20:24
Make sure constraint checks occur in the correct order, even in the presence of upserts. check-in: 07fb30c3 user: drh tags: upsert
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/upsert.c.

   217    217       }
   218    218       pE2 = sqlite3ExprAlloc(db, TK_REGISTER, 0, 0);
   219    219       if( pE2 ){
   220    220         pE2->iTable = regKey;
   221    221         pE2->affinity = SQLITE_AFF_INTEGER;
   222    222       }
   223    223       pWhere = sqlite3ExprAnd(db,pWhere,sqlite3PExpr(pParse, TK_EQ, pE1, pE2));
   224         -    pSrc = sqlite3SrcListDup(db, pUpsert->pUpsertSrc, 0);
   225         -    sqlite3Update(pParse, pSrc, 
   226         -        sqlite3ExprListDup(db, pUpsert->pUpsertSet, 0),
   227         -        pWhere, OE_Abort, 0, 0);
   228    224     }else{
   229    225       /* a WITHOUT ROWID table */
   230         -    sqlite3ExprDelete(db, pWhere);
          226  +    int i, j;
          227  +    int iTab = pParse->nTab+1;
          228  +    Index *pX;
          229  +    for(pX=pTab->pIndex; ALWAYS(pX) && !IsPrimaryKeyIndex(pX); pX=pX->pNext){
          230  +      iTab++;
          231  +    }
          232  +    for(i=0; i<pIdx->nKeyCol; i++){
          233  +      regKey = ++pParse->nMem;
          234  +      sqlite3VdbeAddOp3(v, OP_Column, iDataCur, i, regKey);
          235  +      j = pIdx->aiColumn[i];
          236  +      VdbeComment((v, "%s", pTab->aCol[j].zName));
          237  +      pE1 = sqlite3ExprAlloc(db, TK_COLUMN, 0, 0);
          238  +      if( pE1 ){
          239  +        pE1->pTab = pTab;
          240  +        pE1->iTable = iTab;
          241  +        pE1->iColumn = j;
          242  +      }
          243  +      pE2 = sqlite3ExprAlloc(db, TK_REGISTER, 0, 0);
          244  +      if( pE2 ){
          245  +        pE2->iTable = regKey;
          246  +        pE2->affinity = pTab->zColAff[j];
          247  +      }
          248  +      pWhere = sqlite3ExprAnd(db,pWhere,sqlite3PExpr(pParse, TK_EQ, pE1, pE2));
          249  +    }
   231    250     }
          251  +  pSrc = sqlite3SrcListDup(db, pUpsert->pUpsertSrc, 0);
          252  +  sqlite3Update(pParse, pSrc, 
          253  +      sqlite3ExprListDup(db, pUpsert->pUpsertSet, 0),
          254  +      pWhere, OE_Abort, 0, 0);
   232    255     VdbeNoopComment((v, "End DO UPDATE of UPSERT"));
   233    256   }
   234    257   
   235    258   #endif /* SQLITE_OMIT_UPSERT */