From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Victor Costan Date: Fri, 11 Jan 2019 03:45:18 -0800 Subject: [PATCH 11/17] Fix detection of self-referencing rows in foreign key processing. This backports https://www.sqlite.org/src/info/16fff05347f42fe9 Bug: 916478 --- third_party/sqlite/src/src/fkey.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/third_party/sqlite/src/src/fkey.c b/third_party/sqlite/src/src/fkey.c index 71e55adaf8ab..b9aad0c96588 100644 --- a/third_party/sqlite/src/src/fkey.c +++ b/third_party/sqlite/src/src/fkey.c @@ -602,8 +602,11 @@ static void fkScanChildren( ** NOT( $current_a==a AND $current_b==b AND ... ) ** ** The first form is used for rowid tables. The second form is used - ** for WITHOUT ROWID tables. In the second form, the primary key is - ** (a,b,...) + ** for WITHOUT ROWID tables. In the second form, the *parent* key is + ** (a,b,...). Either the parent or primary key could be used to + ** uniquely identify the current row, but the parent key is more convenient + ** as the required values have already been loaded into registers + ** by the caller. */ if( pTab==pFKey->pFrom && nIncr>0 ){ Expr *pNe; /* Expression (pLeft != pRight) */ @@ -617,12 +620,12 @@ static void fkScanChildren( Expr *pEq, *pAll = 0; Index *pPk = sqlite3PrimaryKeyIndex(pTab); assert( pIdx!=0 ); - for(i=0; inKeyCol; i++){ + for(i=0; inKeyCol; i++){ i16 iCol = pIdx->aiColumn[i]; assert( iCol>=0 ); pLeft = exprTableRegister(pParse, pTab, regData, iCol); - pRight = exprTableColumn(db, pTab, pSrc->a[0].iCursor, iCol); - pEq = sqlite3PExpr(pParse, TK_EQ, pLeft, pRight); + pRight = sqlite3Expr(db, TK_ID, pTab->aCol[iCol].zName); + pEq = sqlite3PExpr(pParse, TK_IS, pLeft, pRight); pAll = sqlite3ExprAnd(db, pAll, pEq); } pNe = sqlite3PExpr(pParse, TK_NOT, pAll, 0); -- 2.18.0