Index: src/resolve.c ================================================================== --- src/resolve.c +++ src/resolve.c @@ -224,11 +224,13 @@ sqlite3 *db = pParse->db; /* The database connection */ struct SrcList_item *pItem; /* Use for looping over pSrcList items */ struct SrcList_item *pMatch = 0; /* The matching pSrcList item */ NameContext *pTopNC = pNC; /* First namecontext in the list */ Schema *pSchema = 0; /* Schema of the expression */ - int isTrigger = 0; + int isTrigger = 0; /* True if resolved to a trigger column */ + Table *pTab = 0; /* Table hold the row */ + Column *pCol; /* A column of pTab */ assert( pNC ); /* the name context cannot be NULL. */ assert( zCol ); /* The Z in X.Y.Z cannot be NULL */ assert( !ExprHasProperty(pExpr, EP_TokenOnly|EP_Reduced) ); @@ -265,13 +267,10 @@ ExprList *pEList; SrcList *pSrcList = pNC->pSrcList; if( pSrcList ){ for(i=0, pItem=pSrcList->a; inSrc; i++, pItem++){ - Table *pTab; - Column *pCol; - pTab = pItem->pTab; assert( pTab!=0 && pTab->zName!=0 ); assert( pTab->nCol>0 ); if( pItem->pSelect && (pItem->pSelect->selFlags & SF_NestedFrom)!=0 ){ int hit = 0; @@ -327,13 +326,12 @@ #ifndef SQLITE_OMIT_TRIGGER /* If we have not already resolved the name, then maybe ** it is a new.* or old.* trigger argument reference */ - if( zDb==0 && zTab!=0 && cnt==0 && pParse->pTriggerTab!=0 ){ + if( zDb==0 && zTab!=0 && cntTab==0 && pParse->pTriggerTab!=0 ){ int op = pParse->eTriggerOp; - Table *pTab = 0; assert( op==TK_DELETE || op==TK_UPDATE || op==TK_INSERT ); if( op!=TK_DELETE && sqlite3StrICmp("new",zTab) == 0 ){ pExpr->iTable = 1; pTab = pParse->pTriggerTab; }else if( op!=TK_INSERT && sqlite3StrICmp("old",zTab)==0 ){ @@ -352,11 +350,11 @@ iCol = -1; } break; } } - if( iCol>=pTab->nCol && sqlite3IsRowid(zCol) ){ + if( iCol>=pTab->nCol && sqlite3IsRowid(zCol) && HasRowid(pTab) ){ iCol = -1; /* IMP: R-44911-55124 */ } if( iColnCol ){ cnt++; if( iCol<0 ){ @@ -379,11 +377,12 @@ #endif /* !defined(SQLITE_OMIT_TRIGGER) */ /* ** Perhaps the name is a reference to the ROWID */ - if( cnt==0 && cntTab==1 && sqlite3IsRowid(zCol) ){ + assert( pTab!=0 || cntTab==0 ); + if( cnt==0 && cntTab==1 && sqlite3IsRowid(zCol) && HasRowid(pTab) ){ cnt = 1; pExpr->iColumn = -1; /* IMP: R-44911-55124 */ pExpr->affinity = SQLITE_AFF_INTEGER; } Index: test/tableopts.test ================================================================== --- test/tableopts.test +++ test/tableopts.test @@ -31,10 +31,25 @@ do_execsql_test tableopt-2.1 { CREATE TABLE t1(a, b, c, PRIMARY KEY(a,b)) WITHOUT rowid; INSERT INTO t1 VALUES(1,2,3),(2,3,4); SELECT c FROM t1 WHERE a IN (1,2) ORDER BY b; } {3 4} +do_test tableopt-2.1.1 { + catchsql { + SELECT rowid, * FROM t1; + } +} {1 {no such column: rowid}} +do_test tableopt-2.1.2 { + catchsql { + SELECT _rowid_, * FROM t1; + } +} {1 {no such column: _rowid_}} +do_test tableopt-2.1.3 { + catchsql { + SELECT oid, * FROM t1; + } +} {1 {no such column: oid}} do_execsql_test tableopt-2.2 { VACUUM; SELECT c FROM t1 WHERE a IN (1,2) ORDER BY b; } {3 4} do_test tableopt-2.3 {