1
0
mirror of https://github.com/sqlite/sqlite.git synced 2025-11-19 21:43:15 +03:00

Fix the foreign key logic to be compatible with generated columns.

FossilOrigin-Name: 3de57145a18c62ff9b556c7218d8b276000d0052e4890212fa9335235f22d03c
This commit is contained in:
drh
2019-10-23 00:31:01 +00:00
parent e70fa7feba
commit a1a01ffb5e
3 changed files with 18 additions and 12 deletions

View File

@@ -349,7 +349,7 @@ static void fkLookupParent(
VdbeCoverage(v);
}
for(i=0; i<pFKey->nCol; i++){
int iReg = aiCol[i] + regData + 1;
int iReg = sqlite3TableColumnToStorage(pFKey->pFrom,aiCol[i]) + regData + 1;
sqlite3VdbeAddOp2(v, OP_IsNull, iReg, iOk); VdbeCoverage(v);
}
@@ -365,7 +365,8 @@ static void fkLookupParent(
** is no matching parent key. Before using MustBeInt, make a copy of
** the value. Otherwise, the value inserted into the child key column
** will have INTEGER affinity applied to it, which may not be correct. */
sqlite3VdbeAddOp2(v, OP_SCopy, aiCol[0]+1+regData, regTemp);
sqlite3VdbeAddOp2(v, OP_SCopy,
sqlite3TableColumnToStorage(pFKey->pFrom,aiCol[0])+1+regData, regTemp);
iMustBeInt = sqlite3VdbeAddOp2(v, OP_MustBeInt, regTemp, 0);
VdbeCoverage(v);
@@ -392,7 +393,9 @@ static void fkLookupParent(
sqlite3VdbeAddOp3(v, OP_OpenRead, iCur, pIdx->tnum, iDb);
sqlite3VdbeSetP4KeyInfo(pParse, pIdx);
for(i=0; i<nCol; i++){
sqlite3VdbeAddOp2(v, OP_Copy, aiCol[i]+1+regData, regTemp+i);
sqlite3VdbeAddOp2(v, OP_Copy,
sqlite3TableColumnToStorage(pFKey->pFrom, aiCol[i])+1+regData,
regTemp+i);
}
/* If the parent table is the same as the child table, and we are about
@@ -408,8 +411,11 @@ static void fkLookupParent(
if( pTab==pFKey->pFrom && nIncr==1 ){
int iJump = sqlite3VdbeCurrentAddr(v) + nCol + 1;
for(i=0; i<nCol; i++){
int iChild = aiCol[i]+1+regData;
int iParent = pIdx->aiColumn[i]+1+regData;
int iChild = sqlite3TableColumnToStorage(pFKey->pFrom,aiCol[i])
+1+regData;
int iParent = 1+regData;
iParent += sqlite3TableColumnToStorage(pIdx->pTable,
pIdx->aiColumn[i]);
assert( pIdx->aiColumn[i]>=0 );
assert( aiCol[i]!=pTab->iPKey );
if( pIdx->aiColumn[i]==pTab->iPKey ){