--- [EMAIL PROTECTED] wrote:
> Joe Wilson <[EMAIL PROTECTED]> wrote:
> >
> > What is the recommended way to match a TK_COLUMN Expr from
> > a Select's pEList with its corresponding Select.pSrc
> > SrcList_item?
> >
> > Do you forsee any technical problem with recursively descending
> > the entire parse tree and calling sqlite3SelectResolve()
> > on every nested Select prior to any code generation in
> > order to perform high-level AST manipulation?
> >
> > I would like to do a number of AST transformations before any
> > VDBE code is generated, but I still lack a clear understanding
> > of how to reliably map a TK_COLUMN Expr with its associated
> > SrcList_item.
> >
>
> Please explain to me more about what you are doing. What
> is an AST manipulation?
If anyone else is interested in the internal SQLite parse tree
format, this code fragment from select.c confirms my original guess.
To match a (resolved) TK_COLUMN Expr with its table it seems that
you must search all SrcLists in the name context chain in
order to find the SrcList_item entry whose iCursor matches the
TK_COLUMN's pExpr->iTable.
switch( pExpr->op ){
case TK_AGG_COLUMN:
case TK_COLUMN: {
/* The expression is a column. Locate the table the column is being
** extracted from in NameContext.pSrcList. This table may be real
** database table or a subquery.
*/
Table *pTab = 0; /* Table structure column is extracted from */
Select *pS = 0; /* Select the column is extracted from */
int iCol = pExpr->iColumn; /* Index of column in pTab */
while( pNC && !pTab ){
SrcList *pTabList = pNC->pSrcList;
for(j=0;j<pTabList->nSrc && pTabList->a[j].iCursor!=pExpr->iTable;j++);
if( j<pTabList->nSrc ){
pTab = pTabList->a[j].pTab;
pS = pTabList->a[j].pSelect;
}else{
pNC = pNC->pNext;
}
}
I reckon I'll turn this into a function returning pTab.
__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com