/ Check-in [d3648034]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Modularize the column name resolution code so that it is smaller, faster, and ready for some enhancements that will fix long-standing name resolutions problems. (CVS 1198)
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: d3648034b409822909d79eb5aa4e64cafa986541
User & Date: drh 2004-01-25 22:44:59
Context
2004-01-27
15:58
Add a web page describing when it is appropriate to use SQLite and when it is not. (CVS 1199) check-in: d77e4776 user: drh tags: trunk
2004-01-25
22:44
Modularize the column name resolution code so that it is smaller, faster, and ready for some enhancements that will fix long-standing name resolutions problems. (CVS 1198) check-in: d3648034 user: drh tags: trunk
2004-01-24
20:18
Add the ability to group FROM terms using parentheses. Names of columns in a join no longer include the table name. (CVS 1197) check-in: 3626f6d4 user: drh tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/expr.c.

     8      8   **    May you find forgiveness for yourself and forgive others.
     9      9   **    May you share freely, never taking more than you give.
    10     10   **
    11     11   *************************************************************************
    12     12   ** This file contains routines used for analyzing expressions and
    13     13   ** for generating VDBE code that evaluates expressions in SQLite.
    14     14   **
    15         -** $Id: expr.c,v 1.106 2004/01/16 16:42:54 drh Exp $
           15  +** $Id: expr.c,v 1.107 2004/01/25 22:44:59 drh Exp $
    16     16   */
    17     17   #include "sqliteInt.h"
    18     18   #include <ctype.h>
    19     19   
    20     20   /*
    21     21   ** Construct a new expression node and return a pointer to it.  Memory
    22     22   ** for this node is obtained from sqliteMalloc().  The calling function
................................................................................
   369    369   */
   370    370   int sqliteIsRowid(const char *z){
   371    371     if( sqliteStrICmp(z, "_ROWID_")==0 ) return 1;
   372    372     if( sqliteStrICmp(z, "ROWID")==0 ) return 1;
   373    373     if( sqliteStrICmp(z, "OID")==0 ) return 1;
   374    374     return 0;
   375    375   }
          376  +
          377  +/*
          378  +** Given the name of a column of the form X.Y.Z or Y.Z or just Z, look up
          379  +** that name in the set of source tables in pSrcList and make the pExpr 
          380  +** expression node refer back to that source column.  The following changes
          381  +** are made to pExpr:
          382  +**
          383  +**    pExpr->iDb           Set the index in db->aDb[] of the database holding
          384  +**                         the table.
          385  +**    pExpr->iTable        Set to the cursor number for the table obtained
          386  +**                         from pSrcList.
          387  +**    pExpr->iColumn       Set to the column number within the table.
          388  +**    pExpr->dataType      Set to the appropriate data type for the column.
          389  +**    pExpr->op            Set to TK_COLUMN.
          390  +**    pExpr->pLeft         Any expression this points to is deleted
          391  +**    pExpr->pRight        Any expression this points to is deleted.
          392  +**
          393  +** The pDbToken is the name of the database (the "X").  This value may be
          394  +** NULL meaning that name is of the form Y.Z or Z.  Any available database
          395  +** can be used.  The pTableToken is the name of the table (the "Y").  This
          396  +** value can be NULL if pDbToken is also NULL.  If pTableToken is NULL it
          397  +** means that the form of the name is Z and that columns from any table
          398  +** can be used.
          399  +**
          400  +** If the name cannot be resolved unambiguously, leave an error message
          401  +** in pParse and return non-zero.  Return zero on success.
          402  +*/
          403  +static int lookupName(
          404  +  Parse *pParse,      /* The parsing context */
          405  +  Token *pDbToken,     /* Name of the database containing table, or NULL */
          406  +  Token *pTableToken,  /* Name of table containing column, or NULL */
          407  +  Token *pColumnToken, /* Name of the column. */
          408  +  SrcList *pSrcList,   /* List of tables used to resolve column names */
          409  +  ExprList *pEList,    /* List of expressions used to resolve "AS" */
          410  +  Expr *pExpr          /* Make this EXPR node point to the selected column */
          411  +){
          412  +  char *zDb = 0;       /* Name of the database.  The "X" in X.Y.Z */
          413  +  char *zTab = 0;      /* Name of the table.  The "Y" in X.Y.Z or Y.Z */
          414  +  char *zCol = 0;      /* Name of the column.  The "Z" */
          415  +  int i, j;            /* Loop counters */
          416  +  int cnt = 0;         /* Number of matching column names */
          417  +  int cntTab = 0;      /* Number of matching table names */
          418  +  sqlite *db;          /* The database */
          419  +
          420  +  assert( pColumnToken && pColumnToken->z ); /* The Z in X.Y.Z cannot be NULL */
          421  +  if( pDbToken && pDbToken->z ){
          422  +    zDb = sqliteStrNDup(pDbToken->z, pDbToken->n);
          423  +    sqliteDequote(zDb);
          424  +  }else{
          425  +    zDb = 0;
          426  +  }
          427  +  if( pTableToken && pTableToken->z ){
          428  +    zTab = sqliteStrNDup(pTableToken->z, pTableToken->n);
          429  +    sqliteDequote(zTab);
          430  +  }else{
          431  +    assert( zDb==0 );
          432  +    zTab = 0;
          433  +  }
          434  +  zCol = sqliteStrNDup(pColumnToken->z, pColumnToken->n);
          435  +  sqliteDequote(zCol);
          436  +  if( sqlite_malloc_failed ){
          437  +    return 1;  /* Leak memory (zDb and zTab) if malloc fails */
          438  +  }
          439  +  assert( zTab==0 || pEList==0 );
          440  +
          441  +  pExpr->iTable = -1;
          442  +  for(i=0; i<pSrcList->nSrc; i++){
          443  +    struct SrcList_item *pItem = &pSrcList->a[i];
          444  +    Table *pTab = pItem->pTab;
          445  +    Column *pCol;
          446  +
          447  +    if( pTab==0 ) continue;
          448  +    assert( pTab->nCol>0 );
          449  +    if( zTab ){
          450  +      if( pItem->zAlias ){
          451  +        char *zTabName = pItem->zAlias;
          452  +        if( sqliteStrICmp(zTabName, zTab)!=0 ) continue;
          453  +      }else{
          454  +        char *zTabName = pTab->zName;
          455  +        if( zTabName==0 || sqliteStrICmp(zTabName, zTab)!=0 ) continue;
          456  +        if( zDb!=0 && sqliteStrICmp(db->aDb[pTab->iDb].zName, zDb)!=0 ){
          457  +          continue;
          458  +        }
          459  +      }
          460  +    }
          461  +    if( 0==(cntTab++) ){
          462  +      pExpr->iTable = pItem->iCursor;
          463  +      pExpr->iDb = pTab->iDb;
          464  +    }
          465  +    for(j=0, pCol=pTab->aCol; j<pTab->nCol; j++, pCol++){
          466  +      if( sqliteStrICmp(pCol->zName, zCol)==0 ){
          467  +        cnt++;
          468  +        pExpr->iTable = pItem->iCursor;
          469  +        pExpr->iDb = pTab->iDb;
          470  +        /* Substitute the rowid (column -1) for the INTEGER PRIMARY KEY */
          471  +        pExpr->iColumn = j==pTab->iPKey ? -1 : j;
          472  +        pExpr->dataType = pCol->sortOrder & SQLITE_SO_TYPEMASK;
          473  +        break;
          474  +      }
          475  +    }
          476  +  }
          477  +
          478  +  /* If we have not already resolved the name, then maybe 
          479  +  ** it is a new.* or old.* trigger argument reference
          480  +  */
          481  +  if( zDb==0 && zTab!=0 && cnt==0 && pParse->trigStack!=0 ){
          482  +    TriggerStack *pTriggerStack = pParse->trigStack;
          483  +    Table *pTab = 0;
          484  +    if( pTriggerStack->newIdx != -1 && sqliteStrICmp("new", zTab) == 0 ){
          485  +      pExpr->iTable = pTriggerStack->newIdx;
          486  +      assert( pTriggerStack->pTab );
          487  +      pTab = pTriggerStack->pTab;
          488  +    }else if( pTriggerStack->oldIdx != -1 && sqliteStrICmp("old", zTab) == 0 ){
          489  +      pExpr->iTable = pTriggerStack->oldIdx;
          490  +      assert( pTriggerStack->pTab );
          491  +      pTab = pTriggerStack->pTab;
          492  +    }
          493  +
          494  +    if( pTab ){ 
          495  +      int j;
          496  +      Column *pCol = pTab->aCol;
          497  +      
          498  +      pExpr->iDb = pTab->iDb;
          499  +      cntTab++;
          500  +      for(j=0; j < pTab->nCol; j++, pCol++) {
          501  +        if( sqliteStrICmp(pCol->zName, zCol)==0 ){
          502  +          cnt++;
          503  +          pExpr->iColumn = j==pTab->iPKey ? -1 : j;
          504  +          pExpr->dataType = pCol->sortOrder & SQLITE_SO_TYPEMASK;
          505  +          break;
          506  +        }
          507  +      }
          508  +    }
          509  +  }
          510  +
          511  +  /*
          512  +  ** Perhaps the name is a reference to the ROWID
          513  +  */
          514  +  if( cnt==0 && cntTab==1 && sqliteIsRowid(zCol) ){
          515  +    cnt = 1;
          516  +    pExpr->iColumn = -1;
          517  +    pExpr->dataType = SQLITE_SO_NUM;
          518  +  }
          519  +
          520  +  /*
          521  +  ** If the input is of the form Z (not Y.Z or X.Y.Z) then the name Z
          522  +  ** might refer to an result-set alias.  This happens, for example, when
          523  +  ** we are resolving names in the WHERE clause of the following command:
          524  +  **
          525  +  **     SELECT a+b AS x FROM table WHERE x<10;
          526  +  **
          527  +  ** In cases like this, replace pExpr with a copy of the expression that
          528  +  ** forms the result set entry ("a+b" in the example) and return immediately.
          529  +  ** Note that the expression in the result set should have already been
          530  +  ** resolved by the time the WHERE clause is resolved.
          531  +  */
          532  +  if( cnt==0 && pEList!=0 ){
          533  +    for(j=0; j<pEList->nExpr; j++){
          534  +      char *zAs = pEList->a[j].zName;
          535  +      if( zAs!=0 && sqliteStrICmp(zAs, zCol)==0 ){
          536  +        assert( pExpr->pLeft==0 && pExpr->pRight==0 );
          537  +        pExpr->op = TK_AS;
          538  +        pExpr->iColumn = j;
          539  +        pExpr->pLeft = sqliteExprDup(pEList->a[j].pExpr);
          540  +        sqliteFree(zCol);
          541  +        assert( zTab==0 && zDb==0 );
          542  +        return 0;
          543  +      }
          544  +    } 
          545  +  }
          546  +
          547  +  /*
          548  +  ** If X and Y are NULL (in other words if only the column name Z is
          549  +  ** supplied) and the value of Z is enclosed in double-quotes, then
          550  +  ** Z is a string literal if it doesn't match any column names.  In that
          551  +  ** case, we need to return right away and not make any changes to
          552  +  ** pExpr.
          553  +  */
          554  +  if( cnt==0 && zTab==0 && pColumnToken->z[0]=='"' ){
          555  +    sqliteFree(zCol);
          556  +    return 0;
          557  +  }
          558  +
          559  +  /*
          560  +  ** cnt==0 means there was not match.  cnt>1 means there were two or
          561  +  ** more matches.  Either way, we have an error.
          562  +  */
          563  +  if( cnt!=1 ){
          564  +    char *z = 0;
          565  +    char *zErr;
          566  +    zErr = cnt==0 ? "no such column: %s" : "ambiguous column name: %s";
          567  +    if( zDb ){
          568  +      sqliteSetString(&z, zDb, ".", zTab, ".", zCol, 0);
          569  +    }else if( zTab ){
          570  +      sqliteSetString(&z, zTab, ".", zCol, 0);
          571  +    }else{
          572  +      z = sqliteStrDup(zCol);
          573  +    }
          574  +    sqliteErrorMsg(pParse, zErr, z);
          575  +    sqliteFree(z);
          576  +  }
          577  +
          578  +  /* Clean up and return
          579  +  */
          580  +  sqliteFree(zDb);
          581  +  sqliteFree(zTab);
          582  +  sqliteFree(zCol);
          583  +  sqliteExprDelete(pExpr->pLeft);
          584  +  pExpr->pLeft = 0;
          585  +  sqliteExprDelete(pExpr->pRight);
          586  +  pExpr->pRight = 0;
          587  +  pExpr->op = TK_COLUMN;
          588  +  sqliteAuthRead(pParse, pExpr, pSrcList);
          589  +  return cnt!=1;
          590  +}
   376    591   
   377    592   /*
   378    593   ** This routine walks an expression tree and resolves references to
   379    594   ** table columns.  Nodes of the form ID.ID or ID resolve into an
   380    595   ** index to the table in the table list and a column offset.  The 
   381    596   ** Expr.opcode for such nodes is changed to TK_COLUMN.  The Expr.iTable
   382    597   ** value is changed to the index of the referenced table in pTabList
................................................................................
   403    618   ** into a memory cell.
   404    619   **
   405    620   ** Unknown columns or tables provoke an error.  The function returns
   406    621   ** the number of errors seen and leaves an error message on pParse->zErrMsg.
   407    622   */
   408    623   int sqliteExprResolveIds(
   409    624     Parse *pParse,     /* The parser context */
   410         -  SrcList *pTabList, /* List of tables used to resolve column names */
          625  +  SrcList *pSrcList, /* List of tables used to resolve column names */
   411    626     ExprList *pEList,  /* List of expressions used to resolve "AS" */
   412    627     Expr *pExpr        /* The expression to be analyzed. */
   413    628   ){
   414    629     int i;
   415    630   
   416         -  if( pExpr==0 || pTabList==0 ) return 0;
   417         -  for(i=0; i<pTabList->nSrc; i++){
   418         -    assert( pTabList->a[i].iCursor>=0 && pTabList->a[i].iCursor<pParse->nTab );
          631  +  if( pExpr==0 || pSrcList==0 ) return 0;
          632  +  for(i=0; i<pSrcList->nSrc; i++){
          633  +    assert( pSrcList->a[i].iCursor>=0 && pSrcList->a[i].iCursor<pParse->nTab );
   419    634     }
   420    635     switch( pExpr->op ){
   421    636       /* Double-quoted strings (ex: "abc") are used as identifiers if
   422    637       ** possible.  Otherwise they remain as strings.  Single-quoted
   423    638       ** strings (ex: 'abc') are always string literals.
   424    639       */
   425    640       case TK_STRING: {
   426    641         if( pExpr->token.z[0]=='\'' ) break;
   427    642         /* Fall thru into the TK_ID case if this is a double-quoted string */
   428    643       }
   429         -    /* A lone identifier.  Try and match it as follows:
   430         -    **
   431         -    **     1.  To the name of a column of one of the tables in pTabList
   432         -    **
   433         -    **     2.  To the right side of an AS keyword in the column list of
   434         -    **         a SELECT statement.  (For example, match against 'x' in
   435         -    **         "SELECT a+b AS 'x' FROM t1".)
   436         -    **
   437         -    **     3.  One of the special names "ROWID", "OID", or "_ROWID_".
          644  +    /* A lone identifier is the name of a columnd.
   438    645       */
   439    646       case TK_ID: {
   440         -      int cnt = 0;      /* Number of matches */
   441         -      char *z;
   442         -      int iDb = -1;
   443         -
   444         -      assert( pExpr->token.z );
   445         -      z = sqliteStrNDup(pExpr->token.z, pExpr->token.n);
   446         -      sqliteDequote(z);
   447         -      if( z==0 ) return 1;
   448         -      for(i=0; i<pTabList->nSrc; i++){
   449         -        int j;
   450         -        Table *pTab = pTabList->a[i].pTab;
   451         -        if( pTab==0 ) continue;
   452         -        iDb = pTab->iDb;
   453         -        assert( pTab->nCol>0 );
   454         -        for(j=0; j<pTab->nCol; j++){
   455         -          if( sqliteStrICmp(pTab->aCol[j].zName, z)==0 ){
   456         -            cnt++;
   457         -            pExpr->iTable = pTabList->a[i].iCursor;
   458         -            pExpr->iDb = pTab->iDb;
   459         -            if( j==pTab->iPKey ){
   460         -              /* Substitute the record number for the INTEGER PRIMARY KEY */
   461         -              pExpr->iColumn = -1;
   462         -              pExpr->dataType = SQLITE_SO_NUM;
   463         -            }else{
   464         -              pExpr->iColumn = j;
   465         -              pExpr->dataType = pTab->aCol[j].sortOrder & SQLITE_SO_TYPEMASK;
   466         -            }
   467         -            pExpr->op = TK_COLUMN;
   468         -          }
   469         -        }
   470         -      }
   471         -      if( cnt==0 && pEList!=0 ){
   472         -        int j;
   473         -        for(j=0; j<pEList->nExpr; j++){
   474         -          char *zAs = pEList->a[j].zName;
   475         -          if( zAs!=0 && sqliteStrICmp(zAs, z)==0 ){
   476         -            cnt++;
   477         -            assert( pExpr->pLeft==0 && pExpr->pRight==0 );
   478         -            pExpr->op = TK_AS;
   479         -            pExpr->iColumn = j;
   480         -            pExpr->pLeft = sqliteExprDup(pEList->a[j].pExpr);
   481         -          }
   482         -        } 
   483         -      }
   484         -      if( cnt==0 && iDb>=0 && sqliteIsRowid(z) ){
   485         -        pExpr->iColumn = -1;
   486         -        pExpr->iTable = pTabList->a[0].iCursor;
   487         -        pExpr->iDb = iDb;
   488         -        cnt = 1 + (pTabList->nSrc>1);
   489         -        pExpr->op = TK_COLUMN;
   490         -        pExpr->dataType = SQLITE_SO_NUM;
   491         -      }
   492         -      sqliteFree(z);
   493         -      if( cnt==0 && pExpr->token.z[0]!='"' ){
   494         -        sqliteErrorMsg(pParse, "no such column: %T", &pExpr->token);
          647  +      if( lookupName(pParse, 0, 0, &pExpr->token, pSrcList, pEList, pExpr) ){
   495    648           return 1;
   496         -      }else if( cnt>1 ){
   497         -        sqliteErrorMsg(pParse, "ambiguous column name: %T", &pExpr->token);
   498         -        return 1;
   499         -      }
   500         -      if( pExpr->op==TK_COLUMN ){
   501         -        sqliteAuthRead(pParse, pExpr, pTabList);
   502    649         }
   503    650         break; 
   504    651       }
   505    652     
   506    653       /* A table name and column name:     ID.ID
   507    654       ** Or a database, table and column:  ID.ID.ID
   508    655       */
   509    656       case TK_DOT: {
   510         -      int cnt = 0;             /* Number of matches */
   511         -      int cntTab = 0;          /* Number of matching tables */
   512         -      int i;                   /* Loop counter */
   513         -      Expr *pLeft, *pRight;    /* Left and right subbranches of the expr */
   514         -      char *zLeft, *zRight;    /* Text of an identifier */
   515         -      char *zDb;               /* Name of database holding table */
   516         -      sqlite *db = pParse->db;
          657  +      Token *pColumn;
          658  +      Token *pTable;
          659  +      Token *pDb;
          660  +      Expr *pRight;
   517    661   
   518    662         pRight = pExpr->pRight;
   519    663         if( pRight->op==TK_ID ){
   520         -        pLeft = pExpr->pLeft;
   521         -        zDb = 0;
          664  +        pDb = 0;
          665  +        pTable = &pExpr->pLeft->token;
          666  +        pColumn = &pRight->token;
   522    667         }else{
   523         -        Expr *pDb = pExpr->pLeft;
   524         -        assert( pDb && pDb->op==TK_ID && pDb->token.z );
   525         -        zDb = sqliteStrNDup(pDb->token.z, pDb->token.n);
   526         -        pLeft = pRight->pLeft;
   527         -        pRight = pRight->pRight;
          668  +        assert( pRight->op==TK_DOT );
          669  +        pDb = &pExpr->pLeft->token;
          670  +        pTable = &pRight->pLeft->token;
          671  +        pColumn = &pRight->pRight->token;
   528    672         }
   529         -      assert( pLeft && pLeft->op==TK_ID && pLeft->token.z );
   530         -      assert( pRight && pRight->op==TK_ID && pRight->token.z );
   531         -      zLeft = sqliteStrNDup(pLeft->token.z, pLeft->token.n);
   532         -      zRight = sqliteStrNDup(pRight->token.z, pRight->token.n);
   533         -      if( zLeft==0 || zRight==0 ){
   534         -        sqliteFree(zLeft);
   535         -        sqliteFree(zRight);
   536         -        sqliteFree(zDb);
          673  +      if( lookupName(pParse, pDb, pTable, pColumn, pSrcList, 0, pExpr) ){
   537    674           return 1;
   538    675         }
   539         -      sqliteDequote(zDb);
   540         -      sqliteDequote(zLeft);
   541         -      sqliteDequote(zRight);
   542         -      pExpr->iTable = -1;
   543         -      for(i=0; i<pTabList->nSrc; i++){
   544         -        int j;
   545         -        char *zTab;
   546         -        Table *pTab = pTabList->a[i].pTab;
   547         -        if( pTab==0 ) continue;
   548         -        assert( pTab->nCol>0 );
   549         -        if( pTabList->a[i].zAlias ){
   550         -          zTab = pTabList->a[i].zAlias;
   551         -          if( sqliteStrICmp(zTab, zLeft)!=0 ) continue;
   552         -        }else{
   553         -          zTab = pTab->zName;
   554         -          if( zTab==0 || sqliteStrICmp(zTab, zLeft)!=0 ) continue;
   555         -          if( zDb!=0 && sqliteStrICmp(db->aDb[pTab->iDb].zName, zDb)!=0 ){
   556         -            continue;
   557         -          }
   558         -        }
   559         -        if( 0==(cntTab++) ){
   560         -          pExpr->iTable = pTabList->a[i].iCursor;
   561         -          pExpr->iDb = pTab->iDb;
   562         -        }
   563         -        for(j=0; j<pTab->nCol; j++){
   564         -          if( sqliteStrICmp(pTab->aCol[j].zName, zRight)==0 ){
   565         -            cnt++;
   566         -            pExpr->iTable = pTabList->a[i].iCursor;
   567         -            pExpr->iDb = pTab->iDb;
   568         -            /* Substitute the rowid (column -1) for the INTEGER PRIMARY KEY */
   569         -            pExpr->iColumn = j==pTab->iPKey ? -1 : j;
   570         -            pExpr->dataType = pTab->aCol[j].sortOrder & SQLITE_SO_TYPEMASK;
   571         -          }
   572         -        }
   573         -      }
   574         -
   575         -      /* If we have not already resolved this *.* expression, then maybe 
   576         -       * it is a new.* or old.* trigger argument reference */
   577         -      if( cnt == 0 && pParse->trigStack != 0 ){
   578         -        TriggerStack *pTriggerStack = pParse->trigStack;
   579         -        int t = 0;
   580         -        if( pTriggerStack->newIdx != -1 && sqliteStrICmp("new", zLeft) == 0 ){
   581         -          pExpr->iTable = pTriggerStack->newIdx;
   582         -          assert( pTriggerStack->pTab );
   583         -          pExpr->iDb = pTriggerStack->pTab->iDb;
   584         -          cntTab++;
   585         -          t = 1;
   586         -        }
   587         -        if( pTriggerStack->oldIdx != -1 && sqliteStrICmp("old", zLeft) == 0 ){
   588         -          pExpr->iTable = pTriggerStack->oldIdx;
   589         -          assert( pTriggerStack->pTab );
   590         -          pExpr->iDb = pTriggerStack->pTab->iDb;
   591         -          cntTab++;
   592         -          t = 1;
   593         -        }
   594         -
   595         -        if( t ){ 
   596         -	  int j;
   597         -          Table *pTab = pTriggerStack->pTab;
   598         -          for(j=0; j < pTab->nCol; j++) {
   599         -            if( sqliteStrICmp(pTab->aCol[j].zName, zRight)==0 ){
   600         -              cnt++;
   601         -              pExpr->iColumn = j==pTab->iPKey ? -1 : j;
   602         -              pExpr->dataType = pTab->aCol[j].sortOrder & SQLITE_SO_TYPEMASK;
   603         -            }
   604         -          }
   605         -	}
   606         -      }
   607         -
   608         -      if( cnt==0 && cntTab==1 && sqliteIsRowid(zRight) ){
   609         -        cnt = 1;
   610         -        pExpr->iColumn = -1;
   611         -        pExpr->dataType = SQLITE_SO_NUM;
   612         -      }
   613         -      sqliteFree(zDb);
   614         -      sqliteFree(zLeft);
   615         -      sqliteFree(zRight);
   616         -      if( cnt==0 ){
   617         -        sqliteErrorMsg(pParse, "no such column: %T.%T",
   618         -               &pLeft->token, &pRight->token);
   619         -        return 1;
   620         -      }else if( cnt>1 ){
   621         -        sqliteErrorMsg(pParse, "ambiguous column name: %T.%T",
   622         -          &pLeft->token, &pRight->token);
   623         -        return 1;
   624         -      }
   625         -      sqliteExprDelete(pExpr->pLeft);
   626         -      pExpr->pLeft = 0;
   627         -      sqliteExprDelete(pExpr->pRight);
   628         -      pExpr->pRight = 0;
   629         -      pExpr->op = TK_COLUMN;
   630         -      sqliteAuthRead(pParse, pExpr, pTabList);
   631    676         break;
   632    677       }
   633    678   
   634    679       case TK_IN: {
   635    680         Vdbe *v = sqliteGetVdbe(pParse);
   636    681         if( v==0 ) return 1;
   637         -      if( sqliteExprResolveIds(pParse, pTabList, pEList, pExpr->pLeft) ){
          682  +      if( sqliteExprResolveIds(pParse, pSrcList, pEList, pExpr->pLeft) ){
   638    683           return 1;
   639    684         }
   640    685         if( pExpr->pSelect ){
   641    686           /* Case 1:     expr IN (SELECT ...)
   642    687           **
   643    688           ** Generate code to write the results of the select into a temporary
   644    689           ** table.  The cursor number of the temporary table has already
................................................................................
   700    745         }
   701    746         break;
   702    747       }
   703    748   
   704    749       /* For all else, just recursively walk the tree */
   705    750       default: {
   706    751         if( pExpr->pLeft
   707         -      && sqliteExprResolveIds(pParse, pTabList, pEList, pExpr->pLeft) ){
          752  +      && sqliteExprResolveIds(pParse, pSrcList, pEList, pExpr->pLeft) ){
   708    753           return 1;
   709    754         }
   710    755         if( pExpr->pRight 
   711         -      && sqliteExprResolveIds(pParse, pTabList, pEList, pExpr->pRight) ){
          756  +      && sqliteExprResolveIds(pParse, pSrcList, pEList, pExpr->pRight) ){
   712    757           return 1;
   713    758         }
   714    759         if( pExpr->pList ){
   715    760           int i;
   716    761           ExprList *pList = pExpr->pList;
   717    762           for(i=0; i<pList->nExpr; i++){
   718    763             Expr *pArg = pList->a[i].pExpr;
   719         -          if( sqliteExprResolveIds(pParse, pTabList, pEList, pArg) ){
          764  +          if( sqliteExprResolveIds(pParse, pSrcList, pEList, pArg) ){
   720    765               return 1;
   721    766             }
   722    767           }
   723    768         }
   724    769       }
   725    770     }
   726    771     return 0;