Fix ALTER TABLE RENAME COLUMN in cases where the column being renamed is an
IPK declared with a separate PRIMARY KEY clause - "CREATE TABLE x(y INTEGER, PRIMARY KEY(y))". FossilOrigin-Name: 32ca8418df8735a6c53e53153f733579e514711f091e4e09ecce83db85fe4d85
This commit is contained in:
parent
0a1cc223bd
commit
689b9d269c
18
manifest
18
manifest
@ -1,5 +1,5 @@
|
||||
C Make\sthe\ssqlite_rename_column()\sSQL\sfunction\sresistant\sto\sproblems\scaused\nby\sOOMs\sand/or\smalformed\sparameters\ssubmitted\sby\shostile\sapplication\scode.\nAlso\sadd\sadditional\scomments\sto\sthe\sRENAME\sCOLUMN\slogic.
|
||||
D 2018-08-13T17:02:26.434
|
||||
C Fix\sALTER\sTABLE\sRENAME\sCOLUMN\sin\scases\swhere\sthe\scolumn\sbeing\srenamed\sis\san\nIPK\sdeclared\swith\sa\sseparate\sPRIMARY\sKEY\sclause\s-\s"CREATE\sTABLE\sx(y\sINTEGER,\nPRIMARY\sKEY(y))".
|
||||
D 2018-08-14T16:18:19.678
|
||||
F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1
|
||||
F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea
|
||||
F Makefile.in 0a3a6c81e6fcb969ff9106e882f0a08547014ba463cb6beca4c4efaecc924ee6
|
||||
@ -432,7 +432,7 @@ F spec.template 86a4a43b99ebb3e75e6b9a735d5fd293a24e90ca
|
||||
F sqlite.pc.in 42b7bf0d02e08b9e77734a47798d1a55a9e0716b
|
||||
F sqlite3.1 fc7ad8990fc8409983309bb80de8c811a7506786
|
||||
F sqlite3.pc.in 48fed132e7cb71ab676105d2a4dc77127d8c1f3a
|
||||
F src/alter.c 5367a5483812b08662f17e7eb5e1891cc0996f9b6e297955ce03454c508d3c79
|
||||
F src/alter.c 918b76c607080bc9d8e634d9249ebd5de3f046322a7b7375ec67680909a5bf7e
|
||||
F src/analyze.c 3dc6b98cf007b005af89df165c966baaa48e8124f38c87b4d2b276fe7f0b9eb9
|
||||
F src/attach.c 4bd5b92633671d3e8ce431153ebb1893b50335818423b5373f3f27969f79769a
|
||||
F src/auth.c 32a5bbe3b755169ab6c66311c5225a3cd4f75a46c041f7fb117e0cbb68055114
|
||||
@ -442,7 +442,7 @@ F src/btmutex.c 8acc2f464ee76324bf13310df5692a262b801808984c1b79defb2503bbafadb6
|
||||
F src/btree.c 3f5e1a03db871e627bf5da21092bf7434ecfc5c5980bbd7d45eba13341340173
|
||||
F src/btree.h febb2e817be499570b7a2e32a9bbb4b607a9234f6b84bb9ae84916d4806e96f2
|
||||
F src/btreeInt.h 620ab4c7235f43572cf3ac2ac8723cbdf68073be4d29da24897c7b77dda5fd96
|
||||
F src/build.c a8e71a3cf77ddf953a85d9d2d4c7fbc0a0f70ef4e4515915ad6ff1cdff9c9808
|
||||
F src/build.c a38f9e25a34cd5a8fd46dbb42c4f7a577f4968635021ddd2ebf2dbca59fad8b3
|
||||
F src/callback.c 36caff1e7eb7deb58572d59c41cee8f064a11d00297616995c5050ea0cfc1288
|
||||
F src/complete.c a3634ab1e687055cd002e11b8f43eb75c17da23e
|
||||
F src/ctime.c b157b01081f92442f8b0218ddb93ddce8ebddad36dbddeecfdd771561dd4f387
|
||||
@ -599,7 +599,7 @@ F test/alter.test b820ab9dcf85f8e3a65bc8326accb2f0c7be64ef
|
||||
F test/alter2.test 7ea05c7d92ac99349a802ef7ada17294dd647060
|
||||
F test/alter3.test 4d79934d812eaeacc6f22781a080f8cfe012fdc3
|
||||
F test/alter4.test b6d7b86860111864f6cddb54af313f5862dda23b
|
||||
F test/altercol.test a64f69f67a8ac2ab7fd671b3166ad3454e0fea6bf8c22fdc3630a4b0cdeb57e8
|
||||
F test/altercol.test 65d15800d9f0dffc252927314e02bb572e17422a07e38b963db87bd16d80e469
|
||||
F test/altermalloc.test e81ac9657ed25c6c5bb09bebfa5a047cd8e4acfc
|
||||
F test/amatch1.test b5ae7065f042b7f4c1c922933f4700add50cdb9f
|
||||
F test/analyze.test b3a9c67d00e1df7588a5b7be9a0292899f94fe8cac1f94a017277474ca2e59df
|
||||
@ -1756,7 +1756,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 32edc8920376aabb84ebe1900eaa9512d23f1b44d6459e4916dc6b07db66e27c
|
||||
R dded0a1ea7b07b29f53ec6b813829626
|
||||
U drh
|
||||
Z 21a9b725df605fe8e7c9a80550758727
|
||||
P 87743ddef11749b4017d60abc297abfd673e02a26a2ae45ffec861327578aa30
|
||||
R cfb1823f0505ebc72c2b74bb80660032
|
||||
U dan
|
||||
Z a8c4b40af0e3c17c8355504f43b3338a
|
||||
|
@ -1 +1 @@
|
||||
87743ddef11749b4017d60abc297abfd673e02a26a2ae45ffec861327578aa30
|
||||
32ca8418df8735a6c53e53153f733579e514711f091e4e09ecce83db85fe4d85
|
45
src/alter.c
45
src/alter.c
@ -941,26 +941,26 @@ static void renameTokenFree(sqlite3 *db, RenameToken *pToken){
|
||||
}
|
||||
|
||||
/*
|
||||
** Return the RenameToken object associated with parse tree element pPtr,
|
||||
** or a NULL pointer if not found. The RenameToken object returned is
|
||||
** removed from the list of RenameToken objects attached to the Parse
|
||||
** object and the caller becomes the new owner of the RenameToken object
|
||||
** Hence, the caller assumes responsibility for freeing the returned
|
||||
** RenameToken object.
|
||||
** Search the Parse object passed as the first argument for a RenameToken
|
||||
** object associated with parse tree element pPtr. If found, remove it
|
||||
** from the Parse object and add it to the list maintained by the
|
||||
** RenameCtx object passed as the second argument.
|
||||
*/
|
||||
static RenameToken *renameTokenFind(Parse *pParse, void *pPtr){
|
||||
static void renameTokenFind(Parse *pParse, struct RenameCtx *pCtx, void *pPtr){
|
||||
RenameToken **pp;
|
||||
for(pp=&pParse->pRename; (*pp); pp=&(*pp)->pNext){
|
||||
if( (*pp)->p==pPtr ){
|
||||
RenameToken *pToken = *pp;
|
||||
*pp = pToken->pNext;
|
||||
pToken->pNext = 0;
|
||||
return pToken;
|
||||
pToken->pNext = pCtx->pList;
|
||||
pCtx->pList = pToken;
|
||||
pCtx->nList++;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
** This is a Walker expression callback.
|
||||
**
|
||||
@ -973,12 +973,7 @@ static RenameToken *renameTokenFind(Parse *pParse, void *pPtr){
|
||||
static int renameColumnExprCb(Walker *pWalker, Expr *pExpr){
|
||||
struct RenameCtx *p = pWalker->u.pRename;
|
||||
if( pExpr->op==TK_COLUMN && pExpr->iColumn==p->iCol ){
|
||||
RenameToken *pTok = renameTokenFind(pWalker->pParse, (void*)pExpr);
|
||||
if( pTok ){
|
||||
pTok->pNext = p->pList;
|
||||
p->pList = pTok;
|
||||
p->nList++;
|
||||
}
|
||||
renameTokenFind(pWalker->pParse, p, (void*)pExpr);
|
||||
}
|
||||
return WRC_Continue;
|
||||
}
|
||||
@ -1115,12 +1110,12 @@ static void renameColumnFunc(
|
||||
int bFKOnly = sqlite3_stricmp(zTable, sParse.pNewTable->zName);
|
||||
FKey *pFKey;
|
||||
if( bFKOnly==0 ){
|
||||
sCtx.pList = renameTokenFind(
|
||||
&sParse, (void*)sParse.pNewTable->aCol[sCtx.iCol].zName
|
||||
renameTokenFind(
|
||||
&sParse, &sCtx, (void*)sParse.pNewTable->aCol[sCtx.iCol].zName
|
||||
);
|
||||
sCtx.nList = 1;
|
||||
assert( sCtx.iCol>=0 );
|
||||
if( sParse.pNewTable->iPKey==sCtx.iCol ){
|
||||
renameTokenFind(&sParse, &sCtx, (void*)&sParse.pNewTable->iPKey);
|
||||
sCtx.iCol = -1;
|
||||
}
|
||||
sqlite3WalkExprList(&sWalker, sParse.pNewTable->pCheck);
|
||||
@ -1133,20 +1128,12 @@ static void renameColumnFunc(
|
||||
for(i=0; i<pFKey->nCol; i++){
|
||||
RenameToken *pTok = 0;
|
||||
if( bFKOnly==0 && pFKey->aCol[i].iFrom==sCtx.iCol ){
|
||||
pTok = renameTokenFind(&sParse, (void*)&pFKey->aCol[i]);
|
||||
if( pTok ){
|
||||
pTok->pNext = sCtx.pList;
|
||||
sCtx.pList = pTok;
|
||||
sCtx.nList++;
|
||||
}
|
||||
renameTokenFind(&sParse, &sCtx, (void*)&pFKey->aCol[i]);
|
||||
}
|
||||
if( 0==sqlite3_stricmp(pFKey->zTo, zTable)
|
||||
&& 0==sqlite3_stricmp(pFKey->aCol[i].zCol, zOld)
|
||||
){
|
||||
pTok = renameTokenFind(&sParse, (void*)pFKey->aCol[i].zCol);
|
||||
pTok->pNext = sCtx.pList;
|
||||
sCtx.pList = pTok;
|
||||
sCtx.nList++;
|
||||
renameTokenFind(&sParse, &sCtx, (void*)pFKey->aCol[i].zCol);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1370,6 +1370,9 @@ void sqlite3AddPrimaryKey(
|
||||
&& sqlite3StrICmp(sqlite3ColumnType(pCol,""), "INTEGER")==0
|
||||
&& sortOrder!=SQLITE_SO_DESC
|
||||
){
|
||||
if( IN_RENAME_COLUMN && pList ){
|
||||
sqlite3MoveRenameToken(pParse, &pTab->iPKey, pList->a[0].pExpr);
|
||||
}
|
||||
pTab->iPKey = iCol;
|
||||
pTab->keyConf = (u8)onError;
|
||||
assert( autoInc==0 || autoInc==1 );
|
||||
|
@ -66,6 +66,12 @@ foreach {tn before after} {
|
||||
13 {CREATE TABLE t1(a, b, c, FOREIGN KEY (b) REFERENCES t2)}
|
||||
{CREATE TABLE t1(a, d, c, FOREIGN KEY (d) REFERENCES t2)}
|
||||
|
||||
15 {CREATE TABLE t1(a INTEGER, b INTEGER, c BLOB, PRIMARY KEY(b))}
|
||||
{CREATE TABLE t1(a INTEGER, d INTEGER, c BLOB, PRIMARY KEY(d))}
|
||||
|
||||
16 {CREATE TABLE t1(a INTEGER, b INTEGER PRIMARY KEY, c BLOB)}
|
||||
{CREATE TABLE t1(a INTEGER, d INTEGER PRIMARY KEY, c BLOB)}
|
||||
|
||||
} {
|
||||
reset_db
|
||||
do_execsql_test 1.$tn.0 $before
|
||||
|
Loading…
Reference in New Issue
Block a user