diff options
Diffstat (limited to 'src/expr.c')
-rw-r--r-- | src/expr.c | 26 |
1 files changed, 18 insertions, 8 deletions
diff --git a/src/expr.c b/src/expr.c index 6ad789a3d..1b18828dd 100644 --- a/src/expr.c +++ b/src/expr.c @@ -1877,18 +1877,30 @@ SrcList *sqlite3SrcListDup(sqlite3 *db, const SrcList *p, int flags){ SrcItem *pNewItem = &pNew->a[i]; const SrcItem *pOldItem = &p->a[i]; Table *pTab; - if( pOldItem->fg.fixedSchema ){ + pNewItem->fg = pOldItem->fg; + if( pOldItem->fg.isSubquery ){ + Subquery *pNewSubq = sqlite3DbMallocRaw(db, sizeof(Subquery)); + if( pNewSubq==0 ){ + assert( db->mallocFailed ); + pNewItem->fg.isSubquery = 0; + }else{ + memcpy(pNewSubq, pOldItem->u4.pSubq, sizeof(*pNewSubq)); + pNewSubq->pSelect = sqlite3SelectDup(db, pNewSubq->pSelect, flags); + if( pNewSubq->pSelect==0 ){ + sqlite3DbFree(db, pNewSubq); + pNewSubq = 0; + pNewItem->fg.isSubquery = 0; + } + } + pNewItem->u4.pSubq = pNewSubq; + }else if( pOldItem->fg.fixedSchema ){ pNewItem->u4.pSchema = pOldItem->u4.pSchema; }else{ pNewItem->u4.zDatabase = sqlite3DbStrDup(db, pOldItem->u4.zDatabase); } pNewItem->zName = sqlite3DbStrDup(db, pOldItem->zName); pNewItem->zAlias = sqlite3DbStrDup(db, pOldItem->zAlias); - pNewItem->fg = pOldItem->fg; pNewItem->iCursor = pOldItem->iCursor; - pNewItem->sq.addrFillSub = pOldItem->sq.addrFillSub; - pNewItem->sq.regReturn = pOldItem->sq.regReturn; - pNewItem->sq.regResult = pOldItem->sq.regResult; if( pNewItem->fg.isIndexedBy ){ pNewItem->u1.zIndexedBy = sqlite3DbStrDup(db, pOldItem->u1.zIndexedBy); }else if( pNewItem->fg.isTabFunc ){ @@ -1905,7 +1917,6 @@ SrcList *sqlite3SrcListDup(sqlite3 *db, const SrcList *p, int flags){ if( pTab ){ pTab->nTabRef++; } - pNewItem->sq.pSelect = sqlite3SelectDup(db, pOldItem->sq.pSelect, flags); if( pOldItem->fg.isUsing ){ assert( pNewItem->fg.isUsing ); pNewItem->u3.pUsing = sqlite3IdListDup(db, pOldItem->u3.pUsing); @@ -1979,7 +1990,6 @@ Select *sqlite3SelectDup(sqlite3 *db, const Select *pDup, int flags){ pp = &pNew->pPrior; pNext = pNew; } - return pRet; } #else @@ -2999,7 +3009,7 @@ static Select *isCandidateForInOpt(const Expr *pX){ pSrc = p->pSrc; assert( pSrc!=0 ); if( pSrc->nSrc!=1 ) return 0; /* Single term in FROM clause */ - if( pSrc->a[0].sq.pSelect ) return 0; /* FROM is not a subquery or view */ + if( pSrc->a[0].fg.isSubquery) return 0;/* FROM is not a subquery or view */ pTab = pSrc->a[0].pSTab; assert( pTab!=0 ); assert( !IsView(pTab) ); /* FROM clause is not a view */ |