Add infrastructure for doing an UPDATE as part of an UPSERT. Still no actual

UPDATE code, however.

FossilOrigin-Name: 6d3017f92bce3e50a91fab2f605e2af8b913b1b374adbfd977299eb042683de8
This commit is contained in:
drh 2018-04-13 18:59:17 +00:00
parent 12e40cebb7
commit 9eddacade9
5 changed files with 40 additions and 10 deletions

View File

@ -1,5 +1,5 @@
C Merge\sthe\spreupdate\shook\schange\sfrom\strunk.
D 2018-04-13T16:29:50.650
C Add\sinfrastructure\sfor\sdoing\san\sUPDATE\sas\spart\sof\san\sUPSERT.\s\sStill\sno\sactual\nUPDATE\scode,\showever.
D 2018-04-13T18:59:17.934
F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1
F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea
F Makefile.in 5ce9343cba9c189046f1afe6d2bcc1f68079439febc05267b98aec6ecc752439
@ -452,7 +452,7 @@ F src/hash.c a12580e143f10301ed5166ea4964ae2853d3905a511d4e0c44497245c7ce1f7a
F src/hash.h ab34c5c54a9e9de2e790b24349ba5aab3dbb4fd4
F src/hwtime.h 747c1bbe9df21a92e9c50f3bbec1de841dc5e5da
F src/in-operator.md 10cd8f4bcd225a32518407c2fb2484089112fd71
F src/insert.c 289011fe99770c884ab713f3a77f93d47d4cb749100d42b6ef96f0da977201a9
F src/insert.c a5955b7852bd10a61c5d3d07b48b244463a0647850442bbb1dd195f587db31e0
F src/legacy.c 134ab3e3fae00a0f67a5187981d6935b24b337bcf0f4b3e5c9fa5763da95bf4e
F src/loadext.c f6e4e416a736369f9e80eba609f0acda97148a8b0453784d670c78d3eed2f302
F src/main.c 1648fc7a9bcfdbfd9a9a04af96ff2796c3164b3f3c7e56ed63a3c51cd11d198d
@ -496,7 +496,7 @@ F src/shell.c.in cc960721e56ebc1a78773bb5d2f5608b54275f945cbe49e4afe919d6888062a
F src/sqlite.h.in e0be726ea6e4e6571724d39d242472ecd8bd1ba6f84ade88e1641bde98a6d02b
F src/sqlite3.rc 5121c9e10c3964d5755191c80dd1180c122fc3a8
F src/sqlite3ext.h 83a3c4ce93d650bedfd1aa558cb85a516bd6d094445ee989740827d0d944368d
F src/sqliteInt.h c1df61473de148aa8b54746820e7681baeec5ac8f7108a9fef6a5d7452114db8
F src/sqliteInt.h 063ea084f4409d03e51417bf54e8cac0e8c359e328f9c63f3724a918bc05b360
F src/sqliteLimit.h 1513bfb7b20378aa0041e7022d04acb73525de35b80b252f1b83fedb4de6a76b
F src/status.c 46e7aec11f79dad50965a5ca5fa9de009f7d6bde08be2156f1538a0a296d4d0e
F src/table.c b46ad567748f24a326d9de40e5b9659f96ffff34
@ -557,7 +557,7 @@ F src/tokenize.c 5b0c661a85f783d35b9883830736eeb63be4aefc4f6b7d9cd081d48782c041e
F src/treeview.c 14d5d1254702ec96876aa52642cb31548612384134970409fae333b25b39d6bb
F src/trigger.c 00ef0b16ab3f0063439e6582086f57f3beb93cd7e7ba46569a8bdc490c16283d
F src/update.c f5210fb55d26e20d14d0106c9479a83c63a005b70b1b5291481c48d6dac6fb9f
F src/upsert.c 1535f4270ff200c2ad750c78d95dc377e1b5486f14e5469894ba8cbd85aabf90
F src/upsert.c bd9b5b48dd67e24916d603a86113935a7973632e7b06839d67a1a5574b6d0e47
F src/utf.c 810fbfebe12359f10bc2a011520a6e10879ab2a163bcb26c74768eab82ea62a5
F src/util.c d9eb0a6c4aae1b00a7369eadd7ca0bbe946cb4c953b6751aa20d357c2f482157
F src/vacuum.c 762ee9bbf8733d87d8cd06f58d950e881982e416f8c767334a40ffd341b6bff5
@ -1719,7 +1719,7 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93
F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc
F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e
F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0
P d07f05e98bb9ce0f9b46db159d9df161b7499d6face6a5299ecd2d00a94fb8d0 0ab4518811b23bdb57feba55014cef07de66028f8fcbf8cf0831a712b2954b91
R c5c36ad1c34d1576c6b4d6cddee03ec0
P 7353caabb31803ccff83fe188c4ee65e75c883de2beea79cbe17375a4a98d9ac
R 1071b5501df032634a20ef86d2c223dc
U drh
Z 80469515ff3b27140302095b20f66527
Z be2b8a48aaf0df0cc373eed82b28fb10

View File

@ -1 +1 @@
7353caabb31803ccff83fe188c4ee65e75c883de2beea79cbe17375a4a98d9ac
6d3017f92bce3e50a91fab2f605e2af8b913b1b374adbfd977299eb042683de8

View File

@ -1484,6 +1484,12 @@ void sqlite3GenerateConstraintChecks(
seenReplace = 1;
break;
}
#ifndef SQLITE_OMIT_UPSERT
case OE_Update: {
sqlite3UpsertDoUpdate(pParse, pUpsert, pTab, 0, iDataCur, 0);
/* Fall through */
}
#endif
case OE_Ignore: {
sqlite3VdbeGoto(v, ignoreDest);
break;
@ -1666,7 +1672,7 @@ void sqlite3GenerateConstraintChecks(
/* Generate code that executes if the new index entry is not unique */
assert( onError==OE_Rollback || onError==OE_Abort || onError==OE_Fail
|| onError==OE_Ignore || onError==OE_Replace );
|| onError==OE_Ignore || onError==OE_Replace || onError==OE_Update );
switch( onError ){
case OE_Rollback:
case OE_Abort:
@ -1674,6 +1680,12 @@ void sqlite3GenerateConstraintChecks(
sqlite3UniqueConstraint(pParse, onError, pIdx);
break;
}
#ifndef SQLITE_OMIT_UPSERT
case OE_Update: {
sqlite3UpsertDoUpdate(pParse, pUpsert, pTab, pIdx, iDataCur, iIdxCur);
/* Fall through */
}
#endif
case OE_Ignore: {
sqlite3VdbeGoto(v, ignoreDest);
break;

View File

@ -4284,6 +4284,7 @@ const char *sqlite3JournalModename(int);
void sqlite3UpsertDelete(sqlite3*,Upsert*);
Upsert *sqlite3UpsertDup(sqlite3*,Upsert*);
int sqlite3UpsertAnalyzeTarget(Parse*,SrcList*,Upsert*);
void sqlite3UpsertDoUpdate(Parse*,Upsert*,Table*,Index*,int,int);
#else
#define sqlite3UpsertNew(x,y,z,w) ((Upsert*)0)
#define sqlite3UpsertDelete(x,y)

View File

@ -180,4 +180,21 @@ int sqlite3UpsertAnalyzeTarget(
return SQLITE_ERROR;
}
/*
** Generate bytecode that does an UPDATE as part of an upsert.
*/
void sqlite3UpsertDoUpdate(
Parse *pParse, /* The parsing and code-generating context */
Upsert *pUpsert, /* The ON CONFLICT clause for the upsert */
Table *pTab, /* The table being updated */
Index *pIdx, /* The UNIQUE constraint that failed */
int iDataCur, /* Cursor for the pTab, table being updated */
int iIdxCur /* Cursor for the pIdx */
){
Vdbe *v = pParse->pVdbe;
assert( v!=0 );
VdbeNoopComment((v, "Begin DO UPDATE of UPSERT"));
VdbeNoopComment((v, "End DO UPDATE of UPSERT"));
}
#endif /* SQLITE_OMIT_UPSERT */