Extend the upsert syntax to allow a WHERE clause on the UPDATE.
FossilOrigin-Name: e4396c540a22fbc087a01050a32bfad514259d700c2381d7ac912580d7dca00f
This commit is contained in:
parent
6cd7d489db
commit
dab0eb58d7
16
manifest
16
manifest
@ -1,5 +1,5 @@
|
||||
C Update\sthe\supsert\sparsing\sso\sthat\sit\saccepts\sconflict-target\slabels\susing\nthe\sPostgreSQL\ssyntax,\sand\salso\saccepts\sthe\sMySQL\s"ON\sDUPLICATE\sKEY"\nsyntax.
|
||||
D 2018-04-12T15:43:05.435
|
||||
C Extend\sthe\supsert\ssyntax\sto\sallow\sa\sWHERE\sclause\son\sthe\sUPDATE.
|
||||
D 2018-04-12T17:28:06.890
|
||||
F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1
|
||||
F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea
|
||||
F Makefile.in 7016fc56c6b9bfe5daac4f34be8be38d8c0b5fab79ccbfb764d3b23bf1c6fff3
|
||||
@ -435,7 +435,7 @@ F src/btmutex.c 0e9ce2d56159b89b9bc8e197e023ee11e39ff8ca
|
||||
F src/btree.c 9eb9531c65346bbfccf5325384b7db1849daf4db6601dcfe21ba5c5b20623b64
|
||||
F src/btree.h 0866c0a08255142ea0e754aabd211c843cab32045c978a592a43152405ed0c84
|
||||
F src/btreeInt.h 620ab4c7235f43572cf3ac2ac8723cbdf68073be4d29da24897c7b77dda5fd96
|
||||
F src/build.c 6da67b1fbb4ed390fcbcb6b5c0c035ed4ace124b9abcea96a183c4c734d670d2
|
||||
F src/build.c 16cbe486985d0c1649ddfda24dfc25ad92fd74e9561cdd29b6381bcbb23f0657
|
||||
F src/callback.c fe677cb5f5abb02f7a772a62a98c2f516426081df68856e8f2d5f950929b966a
|
||||
F src/complete.c a3634ab1e687055cd002e11b8f43eb75c17da23e
|
||||
F src/ctime.c bd9da3f1ff21b432564a16ef0b154cff03585dc43742842e99c58907c6cb4bef
|
||||
@ -480,7 +480,7 @@ F src/os_win.c eb03c6d52f893bcd7fdd4c6006674c13c1b5e49543fec98d605201af2997171c
|
||||
F src/os_win.h 7b073010f1451abe501be30d12f6bc599824944a
|
||||
F src/pager.c 1bb6a57fa0465296a4d6109a1a64610a0e7adde1f3acf3ef539a9d972908ce8f
|
||||
F src/pager.h c571b064df842ec8f2e90855dead9acf4cbe0d1b2c05afe0ef0d0145f7fd0388
|
||||
F src/parse.y 0345f039b4877e9fce8ef82c7df639ce2af3ac8f95d2004c642275ee81b8f8ca
|
||||
F src/parse.y e2562b4d985c004d07be27ce4680553ac02f15793bf6389b02178e03e2f10eac
|
||||
F src/pcache.c 135ef0bc6fb2e3b7178d49ab5c9176254c8a691832c1bceb1156b2fbdd0869bd
|
||||
F src/pcache.h 072f94d29281cffd99e46c1539849f248c4b56ae7684c1f36626797fee375170
|
||||
F src/pcache1.c 716975564c15eb6679e97f734cec1bfd6c16ac3d4010f05f1f8e509fc7d19880
|
||||
@ -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 8b21b9168989cfac7d54798a6b417493841260ec5a2455bd4e63e4287034839b
|
||||
F src/sqliteInt.h f828216a594f8e1b4e19ebb17e5c6e619b19c00175aca68a5c2af531521cbb0b
|
||||
F src/sqliteLimit.h 1513bfb7b20378aa0041e7022d04acb73525de35b80b252f1b83fedb4de6a76b
|
||||
F src/status.c 46e7aec11f79dad50965a5ca5fa9de009f7d6bde08be2156f1538a0a296d4d0e
|
||||
F src/table.c b46ad567748f24a326d9de40e5b9659f96ffff34
|
||||
@ -1717,7 +1717,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 d83eaed539b274c2abd650d07522f491865d4917acbb64d05d01b3ba5c3cd446
|
||||
R 479e2c0e2cb408787189201f512b77ff
|
||||
P c48f64d8ae2625a19267b02e4a173a07766934235ad3052cd9d38f5ecbcbfbc3
|
||||
R 5f3eb9c7a284b62fc6dc3a835a71fa01
|
||||
U drh
|
||||
Z 336c436d4ba882e148bf060e11472826
|
||||
Z bebabff71801057aabbe7cfa080f554f
|
||||
|
@ -1 +1 @@
|
||||
c48f64d8ae2625a19267b02e4a173a07766934235ad3052cd9d38f5ecbcbfbc3
|
||||
e4396c540a22fbc087a01050a32bfad514259d700c2381d7ac912580d7dca00f
|
23
src/build.c
23
src/build.c
@ -4483,6 +4483,7 @@ void sqlite3UpsertDelete(sqlite3 *db, Upsert *p){
|
||||
Upsert *pNext = p->pUpsertNext;
|
||||
sqlite3ExprListDelete(db, p->pUpsertTarget);
|
||||
sqlite3ExprListDelete(db, p->pUpsertSet);
|
||||
sqlite3ExprDelete(db, p->pUpsertWhere);
|
||||
sqlite3DbFree(db, p);
|
||||
p = pNext;
|
||||
}
|
||||
@ -4491,17 +4492,16 @@ void sqlite3UpsertDelete(sqlite3 *db, Upsert *p){
|
||||
|
||||
#ifndef SQLITE_OMIT_UPSERT
|
||||
/*
|
||||
** Duplicate an Upsert object
|
||||
** Duplicate an Upsert object.
|
||||
*/
|
||||
Upsert *sqlite3UpsertDup(sqlite3 *db, Upsert *p){
|
||||
Upsert *pNew;
|
||||
if( p==0 ) return 0;
|
||||
pNew = sqlite3DbMallocRaw(db, sizeof(Upsert));
|
||||
if( pNew==0 ) return 0;
|
||||
pNew->pUpsertTarget = sqlite3ExprListDup(db, p->pUpsertTarget, 0);
|
||||
pNew->pUpsertSet = sqlite3ExprListDup(db, p->pUpsertSet, 0);
|
||||
pNew->pUpsertNext = sqlite3UpsertDup(db, p->pUpsertNext);
|
||||
return pNew;
|
||||
return sqlite3UpsertNew(db,
|
||||
sqlite3UpsertDup(db, p->pUpsertNext),
|
||||
sqlite3ExprListDup(db, p->pUpsertTarget, 0),
|
||||
sqlite3ExprListDup(db, p->pUpsertSet, 0),
|
||||
sqlite3ExprDup(db, p->pUpsertWhere, 0)
|
||||
);
|
||||
}
|
||||
#endif /* SQLITE_OMIT_UPSERT */
|
||||
|
||||
@ -4511,9 +4511,10 @@ Upsert *sqlite3UpsertDup(sqlite3 *db, Upsert *p){
|
||||
*/
|
||||
Upsert *sqlite3UpsertNew(
|
||||
sqlite3 *db, /* Determines which memory allocator to use */
|
||||
Upsert *pPrior, /* Append new upsert to the end of this one */
|
||||
Upsert *pPrior, /* Append this upsert to the end of the new one */
|
||||
ExprList *pTarget, /* Target argument to ON CONFLICT, or NULL */
|
||||
ExprList *pSet /* UPDATE columns, or NULL for a DO NOTHING */
|
||||
ExprList *pSet, /* UPDATE columns, or NULL for a DO NOTHING */
|
||||
Expr *pWhere /* WHERE clause for the ON CONFLICT UPDATE */
|
||||
){
|
||||
Upsert *pNew;
|
||||
pNew = sqlite3DbMallocRaw(db, sizeof(Upsert));
|
||||
@ -4521,11 +4522,13 @@ Upsert *sqlite3UpsertNew(
|
||||
sqlite3UpsertDelete(db, pPrior);
|
||||
sqlite3ExprListDelete(db, pTarget);
|
||||
sqlite3ExprListDelete(db, pSet);
|
||||
sqlite3ExprDelete(db, pWhere);
|
||||
return 0;
|
||||
}else{
|
||||
pNew->pUpsertTarget = pTarget;
|
||||
pNew->pUpsertSet = pSet;
|
||||
pNew->pUpsertNext = pPrior;
|
||||
pNew->pUpsertWhere = pWhere;
|
||||
}
|
||||
return pNew;
|
||||
}
|
||||
|
13
src/parse.y
13
src/parse.y
@ -870,14 +870,15 @@ cmd ::= with insert_cmd(R) INTO fullname(X) idlist_opt(F) DEFAULT VALUES.
|
||||
%type upsert {Upsert*}
|
||||
%destructor upsert {sqlite3UpsertDelete(pParse->db,$$);}
|
||||
upsert(A) ::= . { A = 0; }
|
||||
upsert(A) ::= upsert(X) ON CONFLICT LP sortlist(Y) RP DO UPDATE SET setlist(Z).
|
||||
{ A = sqlite3UpsertNew(pParse->db,X,Y,Z); /*X-overwrites-A*/ }
|
||||
upsert(A) ::= upsert(X) ON DUPLIATE KEY UPDATE setlist(Z).
|
||||
{ A = sqlite3UpsertNew(pParse->db,X,0,Z); /*X-overwrites-A*/ }
|
||||
upsert(A) ::= upsert(X) ON CONFLICT LP sortlist(Y) RP
|
||||
DO UPDATE SET setlist(Z) where_opt(W).
|
||||
{ A = sqlite3UpsertNew(pParse->db,X,Y,Z,W); /*X-overwrites-A*/ }
|
||||
upsert(A) ::= upsert(X) ON DUPLIATE KEY UPDATE setlist(Z) where_opt(W).
|
||||
{ A = sqlite3UpsertNew(pParse->db,X,0,Z,W); /*X-overwrites-A*/ }
|
||||
upsert(A) ::= upsert(X) ON CONFLICT LP sortlist(Y) RP DO NOTHING.
|
||||
{ A = sqlite3UpsertNew(pParse->db,X,Y,0); /*X-overwrites-A*/ }
|
||||
{ A = sqlite3UpsertNew(pParse->db,X,Y,0,0); /*X-overwrites-A*/ }
|
||||
upsert(A) ::= upsert(X) ON CONFLICT DO NOTHING.
|
||||
{ A = sqlite3UpsertNew(pParse->db,X,0,0); /*X-overwrites-A*/ }
|
||||
{ A = sqlite3UpsertNew(pParse->db,X,0,0,0); /*X-overwrites-A*/ }
|
||||
|
||||
%type insert_cmd {int}
|
||||
insert_cmd(A) ::= INSERT orconf(R). {A = R;}
|
||||
|
@ -2717,6 +2717,7 @@ struct NameContext {
|
||||
struct Upsert {
|
||||
ExprList *pUpsertTarget; /* Optional description of conflicting index */
|
||||
ExprList *pUpsertSet; /* The SET clause from an ON CONFLICT UPDATE */
|
||||
Expr *pUpsertWhere; /* WHERE clause for the ON CONFLICT UPDATE */
|
||||
Upsert *pUpsertNext; /* Next ON CONFLICT clause in the list */
|
||||
};
|
||||
|
||||
@ -4270,11 +4271,11 @@ const char *sqlite3JournalModename(int);
|
||||
#define sqlite3WithDelete(x,y)
|
||||
#endif
|
||||
#ifndef SQLITE_OMIT_UPSERT
|
||||
Upsert *sqlite3UpsertNew(sqlite3*,Upsert*,ExprList*,ExprList*);
|
||||
Upsert *sqlite3UpsertNew(sqlite3*,Upsert*,ExprList*,ExprList*,Expr*);
|
||||
void sqlite3UpsertDelete(sqlite3*,Upsert*);
|
||||
Upsert *sqlite3UpsertDup(sqlite3*,Upsert*);
|
||||
#else
|
||||
#define sqlite3UpsertNew(x,y,z) ((Upsert*)0)
|
||||
#define sqlite3UpsertNew(x,y,z,w) ((Upsert*)0)
|
||||
#define sqlite3UpsertDelete(x,y)
|
||||
#define sqlite3UpsertDup(x,y) ((Upsert*)0)
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user