0
0
mirror of https://github.com/sqlite/sqlite.git synced 2024-11-22 03:40:55 +01:00

Fix UPDATE FROM statements on virtual tables that are declared WITHOUT ROWID.

FossilOrigin-Name: bcb0bc6a7b7006f07adb7266b1fecca39bf85a0adea6d78a341623a3546f2c2a
This commit is contained in:
dan 2020-10-12 14:29:11 +00:00
parent 1ca037f41e
commit 4d906f1b5a
4 changed files with 56 additions and 14 deletions

View File

@ -1,5 +1,5 @@
C Fix\sBEGIN\sIMMEDIATE\sand\sBEGIN\sEXCLUSIVE\sso\sthat\sthey\swork\seven\sif\sone\sor\nmore\sof\sthe\sdatabase\sfiles\sin\sthe\sconnection\sare\sread-only.\s\sTest\scases\nfor\sthis\sare\sin\sTH3.
D 2020-10-12T13:24:00.371
C Fix\sUPDATE\sFROM\sstatements\son\svirtual\stables\sthat\sare\sdeclared\sWITHOUT\sROWID.
D 2020-10-12T14:29:11.485
F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1
F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea
F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724
@ -604,7 +604,7 @@ F src/threads.c 4ae07fa022a3dc7c5beb373cf744a85d3c5c6c3c
F src/tokenize.c 4dc01b267593537e2a0d0efe9f80dabe24c5b6f7627bc6971c487fa6a1dacbbf
F src/treeview.c 4b92992176fb2caefbe06ba5bd06e0e0ebcde3d5564758da672631f17aa51cda
F src/trigger.c ef67bde309a831515dc3c2173d792574309f2f42d45f8c078743fae9f7f98c75
F src/update.c 55a6203008d033fc1a9c125d7a0a61efdb79bbb2e6db427b917d1d427b4639be
F src/update.c 1f6167d4acff9f2ae800f7dade84877afbd595c155cdeb7d56f08165d75570c4
F src/upsert.c 2920de71b20f04fe25eb00b655d086f0ba60ea133c59d7fa3325c49838818e78
F src/utf.c ee39565f0843775cc2c81135751ddd93eceb91a673ea2c57f61c76f288b041a0
F src/util.c c0c7977de7ef9b8cb10f6c85f2d0557889a658f817b0455909a49179ba4c8002
@ -1670,7 +1670,7 @@ F test/vtabE.test 2a143fe75a11275781d1fd1988d86b66a3f69cb98f4add62e3da8fd0f637b4
F test/vtabF.test 1918844c7c902f6a16c8dacf1ec8f84886d6e78b
F test/vtabH.test 2efb5a24b0bb50796b21eca23032cfb77abfa4b0c03938e38ce5897abac404ca
F test/vtabI.test 751b07636700dbdea328e4265b6077ccd6811a3f
F test/vtabJ.test d7b73675708cf63cfcb9d443bb451fc01a028347275b7311e51f9fdf3ca6757f
F test/vtabJ.test a6aef49d558af90fae10565b29501f82a95781cb4f797f2d13e2d19f9b6bc77b
F test/vtab_alter.test 736e66fb5ec7b4fee58229aa3ada2f27ec58bc58c00edae4836890c3784c6783
F test/vtab_err.test dcc8b7b9cb67522b3fe7a272c73856829dae4ab7fdb30399aea1b6981bda2b65
F test/vtab_shared.test 5253bff2355a9a3f014c15337da7e177ab0ef8ad
@ -1882,7 +1882,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 54b54f02c66c5aeaa3504c52a04614e2fb4d7260da8367840d5ea5a71cdc2fda
R 136690972287e409358f9a15fd758fa2
U drh
Z 67c8eebb36eba61692c9bc6ff7a9e864
P 2fa08c3963f008d4723c3f4f4496abcb6d4b575c85ba4a911a6aed5730b5948b
R 4adac9b4db7e03c92d090aed7f955e15
U dan
Z 19d12d0c4b93853846f6dfc4a111d566

View File

@ -1 +1 @@
2fa08c3963f008d4723c3f4f4496abcb6d4b575c85ba4a911a6aed5730b5948b
bcb0bc6a7b7006f07adb7266b1fecca39bf85a0adea6d78a341623a3546f2c2a

View File

@ -234,7 +234,7 @@ static void updateFromSelect(
#endif
pList = sqlite3ExprListAppend(pParse, pList, pNew);
}
eDest = SRT_Upfrom;
eDest = IsVirtual(pTab) ? SRT_Table : SRT_Upfrom;
}else if( pTab->pSelect ){
for(i=0; i<pTab->nCol; i++){
pList = sqlite3ExprListAppend(pParse, pList, exprRowColumn(pParse, i));
@ -1187,12 +1187,26 @@ static void updateVirtualTable(
regArg = pParse->nMem + 1;
pParse->nMem += nArg;
if( pSrc->nSrc>1 ){
Index *pPk = 0;
Expr *pRow;
ExprList *pList;
if( pRowid ){
pRow = sqlite3ExprDup(db, pRowid, 0);
if( HasRowid(pTab) ){
if( pRowid ){
pRow = sqlite3ExprDup(db, pRowid, 0);
}else{
pRow = sqlite3PExpr(pParse, TK_ROW, 0, 0);
}
}else{
pRow = sqlite3PExpr(pParse, TK_ROW, 0, 0);
i16 iPk; /* PRIMARY KEY column */
pPk = sqlite3PrimaryKeyIndex(pTab);
assert( pPk!=0 );
assert( pPk->nKeyCol==1 );
iPk = pPk->aiColumn[0];
if( aXRef[iPk]>=0 ){
pRow = sqlite3ExprDup(db, pChanges->a[aXRef[iPk]].pExpr, 0);
}else{
pRow = exprRowColumn(pParse, iPk);
}
}
pList = sqlite3ExprListAppend(pParse, 0, pRow);
@ -1206,7 +1220,7 @@ static void updateVirtualTable(
}
}
updateFromSelect(pParse, ephemTab, 0, pList, pSrc, pWhere, 0, 0);
updateFromSelect(pParse, ephemTab, pPk, pList, pSrc, pWhere, 0, 0);
sqlite3ExprListDelete(db, pList);
eOnePass = ONEPASS_OFF;
}else{

View File

@ -122,5 +122,33 @@ do_execsql_test 181 {
SELECT name, value FROM tclvar where name = 'xx';
} {}
#-------------------------------------------------------------------------
do_execsql_test 200 {
CREATE TABLE var(k TEXT, v TEXT);
INSERT INTO var VALUES('testvar1', 10);
INSERT INTO var VALUES('testvar2', 20);
INSERT INTO var VALUES('testvar3', 30);
}
do_test 210 {
foreach {testvar1 testvar2 testvar3} {1 2 3} {}
execsql {
UPDATE tclvar SET value = var.v FROM var WHERE name = var.k;
}
list $testvar1 $testvar2 $testvar3
} {10 20 30}
do_test 220 {
execsql {
CREATE TABLE nam(k TEXT, v TEXT);
INSERT INTO nam VALUES('testvar1', 'tv1');
INSERT INTO nam VALUES('testvar2', 'tv2');
INSERT INTO nam VALUES('testvar3', 'tv3');
UPDATE tclvar SET fullname = nam.v FROM nam WHERE name = nam.k;
}
list $tv1 $tv2 $tv3
} {10 20 30}
finish_test