SQLite

Check-in [d3c53fd317]
Login

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

Overview
Comment:Get upsert working on WITHOUT ROWID tables.
Downloads: Tarball | ZIP archive
Timelines: family | ancestors | descendants | both | upsert
Files: files | file ages | folders
SHA3-256: d3c53fd3177946f50137d48da871de43d78d10ef9990cc4ea6750f7020f89b6a
User & Date: drh 2018-04-14 22:35:34.588
Context
2018-04-16
10:47
Merge changes from trunk. (check-in: 54d96772e7 user: drh tags: upsert)
2018-04-14
22:35
Get upsert working on WITHOUT ROWID tables. (check-in: d3c53fd317 user: drh tags: upsert)
20:24
Make sure constraint checks occur in the correct order, even in the presence of upserts. (check-in: 07fb30c3de user: drh tags: upsert)
Changes
Unified Diff Ignore Whitespace Patch
Changes to src/upsert.c.
217
218
219
220
221
222
223



























224
225
226
227
228
229
230
231
232
233
234
235
    }
    pE2 = sqlite3ExprAlloc(db, TK_REGISTER, 0, 0);
    if( pE2 ){
      pE2->iTable = regKey;
      pE2->affinity = SQLITE_AFF_INTEGER;
    }
    pWhere = sqlite3ExprAnd(db,pWhere,sqlite3PExpr(pParse, TK_EQ, pE1, pE2));



























    pSrc = sqlite3SrcListDup(db, pUpsert->pUpsertSrc, 0);
    sqlite3Update(pParse, pSrc, 
        sqlite3ExprListDup(db, pUpsert->pUpsertSet, 0),
        pWhere, OE_Abort, 0, 0);
  }else{
    /* a WITHOUT ROWID table */
    sqlite3ExprDelete(db, pWhere);
  }
  VdbeNoopComment((v, "End DO UPDATE of UPSERT"));
}

#endif /* SQLITE_OMIT_UPSERT */







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|
|
|
|
<
<
<
<




217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254




255
256
257
258
    }
    pE2 = sqlite3ExprAlloc(db, TK_REGISTER, 0, 0);
    if( pE2 ){
      pE2->iTable = regKey;
      pE2->affinity = SQLITE_AFF_INTEGER;
    }
    pWhere = sqlite3ExprAnd(db,pWhere,sqlite3PExpr(pParse, TK_EQ, pE1, pE2));
  }else{
    /* a WITHOUT ROWID table */
    int i, j;
    int iTab = pParse->nTab+1;
    Index *pX;
    for(pX=pTab->pIndex; ALWAYS(pX) && !IsPrimaryKeyIndex(pX); pX=pX->pNext){
      iTab++;
    }
    for(i=0; i<pIdx->nKeyCol; i++){
      regKey = ++pParse->nMem;
      sqlite3VdbeAddOp3(v, OP_Column, iDataCur, i, regKey);
      j = pIdx->aiColumn[i];
      VdbeComment((v, "%s", pTab->aCol[j].zName));
      pE1 = sqlite3ExprAlloc(db, TK_COLUMN, 0, 0);
      if( pE1 ){
        pE1->pTab = pTab;
        pE1->iTable = iTab;
        pE1->iColumn = j;
      }
      pE2 = sqlite3ExprAlloc(db, TK_REGISTER, 0, 0);
      if( pE2 ){
        pE2->iTable = regKey;
        pE2->affinity = pTab->zColAff[j];
      }
      pWhere = sqlite3ExprAnd(db,pWhere,sqlite3PExpr(pParse, TK_EQ, pE1, pE2));
    }
  }
  pSrc = sqlite3SrcListDup(db, pUpsert->pUpsertSrc, 0);
  sqlite3Update(pParse, pSrc, 
      sqlite3ExprListDup(db, pUpsert->pUpsertSet, 0),
      pWhere, OE_Abort, 0, 0);




  VdbeNoopComment((v, "End DO UPDATE of UPSERT"));
}

#endif /* SQLITE_OMIT_UPSERT */