/* ** While a SrcList can in general represent multiple tables and subqueries ** (as in the FROM clause of a SELECT statement) in this case it contains ** the name of a single table, as one might find in an INSERT, DELETE, ** or UPDATE statement. Look up that table in the symbol table and ** return a pointer. Set an error message and return NULL if the table ** name is not found or if any other error occurs. ** ** The following fields are initialized appropriate in pSrc: ** ** pSrc->a[0].pTab Pointer to the Table object ** pSrc->a[0].pIndex Pointer to the INDEXED BY index, if there is one ** */ Table *sqlite3SrcListLookup(Parse *pParse, SrcList *pSrc){ struct SrcList_item *pItem = pSrc->a; Table *pTab; assert( pItem && pSrc->nSrc==1 ); pTab = sqlite3LocateTableItem(pParse, 0, pItem); sqlite3DeleteTable(pParse->db, pItem->pTab); pItem->pTab = pTab; if( pTab ){ pTab->nRef++; } if( sqlite3IndexedByLookup(pParse, pItem) ){ pTab = 0; } return pTab; }
/* ** While a SrcList can in general represent multiple tables and subqueries ** (as in the FROM clause of a SELECT statement) in this case it contains ** the name of a single table, as one might find in an INSERT, DELETE, ** or UPDATE statement. Look up that table in the symbol table and ** return a pointer. Set an error message and return NULL if the table ** name is not found or if any other error occurs. **而SrcList可以在代表多个表和子查询(如在从SELECT语句的子句)在此情况下,它含有(如在FROM SELECT语句的子句)在此情况下,它包含单个表的名称,因为可能会发现一个INSERT,DELETE或UPDATE语句。查找该表中的符号表,并返回一个指针。设置一个错误信息,如果表名没有找到返回NULL,或如果发生任何错误。 ** The following fields are initialized appropriate in pSrc: **在pSrc初始化以下字段: ** pSrc->a[0].pTab Pointer to the Table object 指向目标表 ** pSrc->a[0].pIndex Pointer to the INDEXED BY index, if there is one 有INDEXED BY语句的指向INDEXED BY 索引 ** */ Table *sqlite3SrcListLookup(Parse *pParse, SrcList *pSrc){ //函数的作用查找所有名字为pSrc的表,如果没有找到任何表,添加一个错误消息pParse - > zErrMsg并返回NULL。如果所有的表都找到,返回一个指针,指向最后一个表。 struct SrcList_item *pItem = pSrc->a; Table *pTab; assert( pItem && pSrc->nSrc==1 ); pTab = sqlite3LocateTable(pParse, 0, pItem->zName, pItem->zDatabase); //这个函数定位pItem所指的表所在的数据库,表的名字,并用指针pTab指向该定位的表 sqlite3DeleteTable(pParse->db, pItem->pTab); //功能:删除该表 ,但是还没有调用该函数 pItem->pTab = pTab; if( pTab ){//如果这个表存在,则逐一检查这个表中的参数 pTab->nRef++; } if( sqlite3IndexedByLookup(pParse, pItem) ){//如果通过查找索引和该表匹配,则0表示要找的就是这个表 pTab = 0; } return pTab; }