Index: src/select.c ================================================================== --- src/select.c +++ src/select.c @@ -10,11 +10,11 @@ ** ************************************************************************* ** This file contains C code routines that are called by the parser ** to handle SELECT statements in SQLite. ** -** $Id: select.c,v 1.445 2008/07/01 18:26:50 danielk1977 Exp $ +** $Id: select.c,v 1.446 2008/07/02 13:13:52 danielk1977 Exp $ */ #include "sqliteInt.h" /* @@ -3083,16 +3083,17 @@ ** ** All of the expression analysis must occur on both the outer query and ** the subquery before this routine runs. */ static int flattenSubquery( - sqlite3 *db, /* Database connection */ + Parse *pParse, /* Parsing context */ Select *p, /* The parent or outer SELECT statement */ int iFrom, /* Index in p->pSrc->a[] of the inner subquery */ int isAgg, /* True if outer SELECT uses aggregate functions */ int subqueryIsAgg /* True if the subquery uses aggregate functions */ ){ + const char *zSavedAuthContext = pParse->zAuthContext; Select *pParent; Select *pSub; /* The inner query or "subquery" */ Select *pSub1; /* Pointer to the rightmost select in sub-query */ SrcList *pSrc; /* The FROM clause of the outer query */ SrcList *pSubSrc; /* The FROM clause of the subquery */ @@ -3099,10 +3100,11 @@ ExprList *pList; /* The result set of the outer query */ int iParent; /* VDBE cursor number of the pSub result set temp table */ int i; /* Loop counter */ Expr *pWhere; /* The WHERE clause */ struct SrcList_item *pSubitem; /* The subquery */ + sqlite3 *db = pParse->db; /* Check to see if flattening is permitted. Return 0 if not. */ if( p==0 ) return 0; pSrc = p->pSrc; @@ -3183,10 +3185,14 @@ return 0; } } } + pParse->zAuthContext = pSubitem->zName; + sqlite3AuthCheck(pParse, SQLITE_SELECT, 0, 0, 0); + pParse->zAuthContext = zSavedAuthContext; + /* If the sub-query is a compound SELECT statement, then it must be ** a UNION ALL and the parent query must be of the form: ** ** SELECT FROM () ** @@ -3785,15 +3791,16 @@ for(i=0; !p->pPrior && inSrc; i++){ struct SrcList_item *pItem = &pTabList->a[i]; SelectDest dest; Select *pSub = pItem->pSelect; int isAggSub; + char *zName = pItem->zName; if( pSub==0 || pItem->isPopulated ) continue; - if( pItem->zName!=0 ){ /* An sql view */ + if( zName!=0 ){ /* An sql view */ const char *zSavedAuthContext = pParse->zAuthContext; - pParse->zAuthContext = pItem->zName; + pParse->zAuthContext = zName; rc = sqlite3SelectResolve(pParse, pSub, 0); pParse->zAuthContext = zSavedAuthContext; if( rc ){ goto select_end; } @@ -3808,20 +3815,20 @@ */ pParse->nHeight += sqlite3SelectExprHeight(p); /* Check to see if the subquery can be absorbed into the parent. */ isAggSub = pSub->isAgg; - if( flattenSubquery(db, p, i, isAgg, isAggSub) ){ + if( flattenSubquery(pParse, p, i, isAgg, isAggSub) ){ if( isAggSub ){ p->isAgg = isAgg = 1; } i = -1; }else{ sqlite3SelectDestInit(&dest, SRT_EphemTab, pItem->iCursor); sqlite3Select(pParse, pSub, &dest, p, i, &isAgg, 0); } - if( db->mallocFailed ){ + if( pParse->nErr || db->mallocFailed ){ goto select_end; } pParse->nHeight -= sqlite3SelectExprHeight(p); pTabList = p->pSrc; if( !IgnorableOrderby(pDest) ){ Index: test/auth.test ================================================================== --- test/auth.test +++ test/auth.test @@ -10,11 +10,11 @@ #*********************************************************************** # This file implements regression tests for SQLite library. The # focus of this script is testing the sqlite3_set_authorizer() API # and related functionality. # -# $Id: auth.test,v 1.42 2008/04/15 14:36:42 drh Exp $ +# $Id: auth.test,v 1.43 2008/07/02 13:13:52 danielk1977 Exp $ # set testdir [file dirname $argv0] source $testdir/tester.tcl @@ -2249,11 +2249,11 @@ SQLITE_READ v1 x main r2 \ SQLITE_READ v1 x main r2 \ SQLITE_SELECT {} {} {} v1 \ SQLITE_READ t2 a main v1 \ SQLITE_READ t2 b main v1 \ - SQLITE_SELECT {} {} {} v1 \ + SQLITE_SELECT {} {} {} {} \ SQLITE_READ v1 x main v1 \ ] do_test auth-4.4 { execsql { CREATE TRIGGER r3 INSTEAD OF DELETE ON v1 BEGIN @@ -2273,11 +2273,11 @@ SQLITE_INSERT v1chng {} main r3 \ SQLITE_READ v1 x main r3 \ SQLITE_SELECT {} {} {} v1 \ SQLITE_READ t2 a main v1 \ SQLITE_READ t2 b main v1 \ - SQLITE_SELECT {} {} {} v1 \ + SQLITE_SELECT {} {} {} {} \ SQLITE_READ v1 x main v1 \ ] } ;# ifcapable view && trigger Index: test/auth2.test ================================================================== --- test/auth2.test +++ test/auth2.test @@ -10,11 +10,11 @@ #*********************************************************************** # This file implements regression tests for SQLite library. The # focus of this script is testing the sqlite3_set_authorizer() API # and related functionality. # -# $Id: auth2.test,v 1.2 2007/10/12 20:42:30 drh Exp $ +# $Id: auth2.test,v 1.3 2008/07/02 13:13:53 danielk1977 Exp $ # set testdir [file dirname $argv0] source $testdir/tester.tcl @@ -129,15 +129,15 @@ } set ::authargs } {SQLITE_SELECT {} {} {} {} SQLITE_READ v2 a main {} SQLITE_READ v2 b main {} -SQLITE_SELECT {} {} {} v2 SQLITE_READ t2 x main v2 SQLITE_READ t2 y main v2 SQLITE_READ t2 y main v2 SQLITE_READ t2 z main v2 +SQLITE_SELECT {} {} {} v2 } do_test auth2-2.4 { db2 eval { CREATE TABLE t3(p,q,r); } @@ -147,22 +147,22 @@ } set ::authargs } {SQLITE_SELECT {} {} {} {} SQLITE_READ v2 b main {} SQLITE_READ v2 a main {} -SQLITE_SELECT {} {} {} v2 SQLITE_READ t2 x main v2 SQLITE_READ t2 y main v2 SQLITE_READ t2 y main v2 SQLITE_READ t2 z main v2 +SQLITE_SELECT {} {} {} v2 SQLITE_SELECT {} {} {} {} SQLITE_READ v2 b main {} SQLITE_READ v2 a main {} -SQLITE_SELECT {} {} {} v2 SQLITE_READ t2 x main v2 SQLITE_READ t2 y main v2 SQLITE_READ t2 y main v2 SQLITE_READ t2 z main v2 +SQLITE_SELECT {} {} {} v2 } db2 close finish_test