/ Check-in [4ab994a8]
Login
SQLite training in Houston TX on 2019-11-05 (details)
Part of the 2019 Tcl Conference

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

Overview
Comment:Minor code enhancements. (CVS 2642)
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 4ab994a87ee844f453d693555abd61b51bb44a0e
User & Date: drh 2005-08-30 00:54:02
Context
2005-08-30
19:30
Fix printf.c so that it handles 10.0 correctly. (CVS 2643) check-in: 0f7a53f7 user: drh tags: trunk
00:54
Minor code enhancements. (CVS 2642) check-in: 4ab994a8 user: drh tags: trunk
00:10
Update the home page to brag about 150KiB code footprint when optional features are omitted. (CVS 2641) check-in: 0e1ac128 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.221 2005/08/25 12:45:04 drh Exp $
           15  +** $Id: expr.c,v 1.222 2005/08/30 00:54:02 drh Exp $
    16     16   */
    17     17   #include "sqliteInt.h"
    18     18   #include <ctype.h>
    19     19   
    20     20   /*
    21     21   ** Return the 'affinity' of the expression pExpr if any.
    22     22   **
................................................................................
  2067   2067   ** sqlite3ExprAnalyzeAggregates().  See sqlite3ExprAnalyzeAggregates
  2068   2068   ** for additional information.
  2069   2069   **
  2070   2070   ** This routine analyzes the aggregate function at pExpr.
  2071   2071   */
  2072   2072   static int analyzeAggregate(void *pArg, Expr *pExpr){
  2073   2073     int i;
  2074         -  AggExpr *aAgg;
         2074  +  AggExpr *pAgg;
  2075   2075     NameContext *pNC = (NameContext *)pArg;
  2076   2076     Parse *pParse = pNC->pParse;
  2077   2077     SrcList *pSrcList = pNC->pSrcList;
         2078  +  Expr *pAggExpr;
  2078   2079   
  2079   2080     switch( pExpr->op ){
  2080   2081       case TK_COLUMN: {
  2081   2082         for(i=0; pSrcList && i<pSrcList->nSrc; i++){
  2082   2083           if( pExpr->iTable==pSrcList->a[i].iCursor ){
  2083         -          aAgg = pParse->aAgg;
  2084         -          for(i=0; i<pParse->nAgg; i++){
  2085         -            if( aAgg[i].isAgg ) continue;
  2086         -            if( aAgg[i].pExpr->iTable==pExpr->iTable
  2087         -             && aAgg[i].pExpr->iColumn==pExpr->iColumn ){
         2084  +          pAgg = pParse->aAgg;
         2085  +          for(i=0; i<pParse->nAgg; i++, pAgg++){
         2086  +            if( pAgg->isAgg ) continue;
         2087  +            if( (pAggExpr = pAgg->pExpr)->iTable==pExpr->iTable
         2088  +             && pAggExpr->iColumn==pExpr->iColumn ){
  2088   2089                 break;
  2089   2090               }
  2090   2091             }
  2091   2092             if( i>=pParse->nAgg ){
  2092   2093               i = appendAggInfo(pParse);
  2093   2094               if( i<0 ) return 1;
  2094         -            pParse->aAgg[i].isAgg = 0;
  2095         -            pParse->aAgg[i].pExpr = pExpr;
         2095  +            pAgg = &pParse->aAgg[i];
         2096  +            pAgg->isAgg = 0;
         2097  +            pAgg->pExpr = pExpr;
  2096   2098             }
  2097   2099             pExpr->iAgg = i;
  2098   2100             pExpr->iAggCtx = pNC->nDepth;
  2099   2101             return 1;
  2100   2102           }
  2101   2103         }
  2102   2104         return 1;
  2103   2105       }
  2104   2106       case TK_AGG_FUNCTION: {
  2105   2107         if( pNC->nDepth==0 ){
  2106         -        aAgg = pParse->aAgg;
  2107         -        for(i=0; i<pParse->nAgg; i++){
  2108         -          if( !aAgg[i].isAgg ) continue;
  2109         -          if( sqlite3ExprCompare(aAgg[i].pExpr, pExpr) ){
         2108  +        pAgg = pParse->aAgg;
         2109  +        for(i=0; i<pParse->nAgg; i++, pAgg++){
         2110  +          if( !pAgg->isAgg ) continue;
         2111  +          if( sqlite3ExprCompare(pAgg->pExpr, pExpr) ){
  2110   2112               break;
  2111   2113             }
  2112   2114           }
  2113   2115           if( i>=pParse->nAgg ){
  2114   2116             u8 enc = pParse->db->enc;
  2115   2117             i = appendAggInfo(pParse);
  2116   2118             if( i<0 ) return 1;
  2117         -          pParse->aAgg[i].isAgg = 1;
  2118         -          pParse->aAgg[i].pExpr = pExpr;
  2119         -          pParse->aAgg[i].pFunc = sqlite3FindFunction(pParse->db,
         2119  +          pAgg = &pParse->aAgg[i];
         2120  +          pAgg->isAgg = 1;
         2121  +          pAgg->pExpr = pExpr;
         2122  +          pAgg->pFunc = sqlite3FindFunction(pParse->db,
  2120   2123                  pExpr->token.z, pExpr->token.n,
  2121   2124                  pExpr->pList ? pExpr->pList->nExpr : 0, enc, 0);
  2122   2125           }
  2123   2126           pExpr->iAgg = i;
  2124   2127           return 1;
  2125   2128         }
  2126   2129       }
................................................................................
  2145   2148   ** the number of errors.
  2146   2149   */
  2147   2150   int sqlite3ExprAnalyzeAggregates(NameContext *pNC, Expr *pExpr){
  2148   2151     int nErr = pNC->pParse->nErr;
  2149   2152     walkExprTree(pExpr, analyzeAggregate, pNC);
  2150   2153     return pNC->pParse->nErr - nErr;
  2151   2154   }
         2155  +
         2156  +/*
         2157  +** Call sqlite3ExprAnalyzeAggregates() for every expression in an
         2158  +** expression list.  Return the number of errors.
         2159  +**
         2160  +** If an error is found, the analysis is cut short.
         2161  +*/
         2162  +int sqlite3ExprAnalyzeAggList(NameContext *pNC, ExprList *pList){
         2163  +  struct ExprList_item *pItem;
         2164  +  int i;
         2165  +  int nErr = 0;
         2166  +  if( pList ){
         2167  +    for(pItem=pList->a, i=0; nErr==0 && i<pList->nExpr; i++, pItem++){
         2168  +      nErr += sqlite3ExprAnalyzeAggregates(pNC, pItem->pExpr);
         2169  +    }
         2170  +  }
         2171  +  return nErr;
         2172  +}

Changes to src/select.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 C code routines that are called by the parser
    13     13   ** to handle SELECT statements in SQLite.
    14     14   **
    15         -** $Id: select.c,v 1.255 2005/08/28 01:34:22 drh Exp $
           15  +** $Id: select.c,v 1.256 2005/08/30 00:54:03 drh Exp $
    16     16   */
    17     17   #include "sqliteInt.h"
    18     18   
    19     19   
    20     20   /*
    21     21   ** Allocate a new Select structure and return a pointer to that
    22     22   ** structure.
................................................................................
  2628   2628     }
  2629   2629   #endif
  2630   2630   
  2631   2631     /* If there is an ORDER BY clause, resolve any collation sequences
  2632   2632     ** names that have been explicitly specified.
  2633   2633     */
  2634   2634     if( pOrderBy ){
  2635         -    for(i=0; i<pOrderBy->nExpr; i++){
  2636         -      if( pOrderBy->a[i].zName ){
  2637         -        pOrderBy->a[i].pExpr->pColl = 
  2638         -            sqlite3LocateCollSeq(pParse, pOrderBy->a[i].zName, -1);
         2635  +    struct ExprList_item *pTerm;
         2636  +    for(i=0, pTerm=pOrderBy->a; i<pOrderBy->nExpr; i++, pTerm++){
         2637  +      if( pTerm->zName ){
         2638  +        pTerm->pExpr->pColl = sqlite3LocateCollSeq(pParse, pTerm->zName, -1);
  2639   2639         }
  2640   2640       }
  2641   2641       if( pParse->nErr ){
  2642   2642         goto select_end;
  2643   2643       }
  2644   2644     }
  2645   2645   
................................................................................
  2660   2660       NameContext sNC;
  2661   2661       memset(&sNC, 0, sizeof(sNC));
  2662   2662       sNC.pParse = pParse;
  2663   2663       sNC.pSrcList = pTabList;
  2664   2664   
  2665   2665       assert( pParse->nAgg==0 );
  2666   2666       isAgg = 1;
  2667         -    for(i=0; i<pEList->nExpr; i++){
  2668         -      if( sqlite3ExprAnalyzeAggregates(&sNC, pEList->a[i].pExpr) ){
  2669         -        goto select_end;
  2670         -      }
         2667  +    if( sqlite3ExprAnalyzeAggList(&sNC, pEList) ){
         2668  +      goto select_end;
  2671   2669       }
  2672         -    if( pGroupBy ){
  2673         -      for(i=0; i<pGroupBy->nExpr; i++){
  2674         -        if( sqlite3ExprAnalyzeAggregates(&sNC, pGroupBy->a[i].pExpr) ){
  2675         -          goto select_end;
  2676         -        }
  2677         -      }
         2670  +    if( sqlite3ExprAnalyzeAggList(&sNC, pGroupBy) ){
         2671  +      goto select_end;
  2678   2672       }
  2679   2673       if( pHaving && sqlite3ExprAnalyzeAggregates(&sNC, pHaving) ){
  2680   2674         goto select_end;
  2681   2675       }
  2682         -    if( pOrderBy ){
  2683         -      for(i=0; i<pOrderBy->nExpr; i++){
  2684         -        if( sqlite3ExprAnalyzeAggregates(&sNC, pOrderBy->a[i].pExpr) ){
  2685         -          goto select_end;
  2686         -        }
  2687         -      }
         2676  +    if( sqlite3ExprAnalyzeAggList(&sNC, pOrderBy) ){
         2677  +      goto select_end;
  2688   2678       }
  2689   2679     }
  2690   2680   
  2691   2681     /* Reset the aggregator
  2692   2682     */
  2693   2683     if( isAgg ){
  2694   2684       int addr = sqlite3VdbeAddOp(v, OP_AggReset, (pGroupBy?0:1), pParse->nAgg);

Changes to src/sqliteInt.h.

     7      7   **    May you do good and not evil.
     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   ** Internal interface definitions for SQLite.
    13     13   **
    14         -** @(#) $Id: sqliteInt.h,v 1.405 2005/08/29 23:00:04 drh Exp $
           14  +** @(#) $Id: sqliteInt.h,v 1.406 2005/08/30 00:54:03 drh Exp $
    15     15   */
    16     16   #ifndef _SQLITEINT_H_
    17     17   #define _SQLITEINT_H_
    18     18   
    19     19   /*
    20     20   ** These #defines should enable >2GB file support on Posix if the
    21     21   ** underlying operating system supports it.  If the OS lacks
................................................................................
   888    888     int nAlloc;            /* Number of entries allocated below */
   889    889     struct ExprList_item {
   890    890       Expr *pExpr;           /* The list of expressions */
   891    891       char *zName;           /* Token associated with this expression */
   892    892       u8 sortOrder;          /* 1 for DESC or 0 for ASC */
   893    893       u8 isAgg;              /* True if this is an aggregate like count(*) */
   894    894       u8 done;               /* A flag to indicate when processing is finished */
          895  +    u8 orderByDup[2];      /* Corresponding term in OrderBy/GroupBy clause */
   895    896     } *a;                  /* One entry for each expression */
   896    897   };
   897    898   
   898    899   /*
   899    900   ** An instance of this structure can hold a simple list of identifiers,
   900    901   ** such as the list "a,b,c" in the following statements:
   901    902   **
................................................................................
  1448   1449   int sqlite3RunVacuum(char**, sqlite3*);
  1449   1450   char *sqlite3NameFromToken(Token*);
  1450   1451   int sqlite3ExprCheck(Parse*, Expr*, int, int*);
  1451   1452   int sqlite3ExprCompare(Expr*, Expr*);
  1452   1453   int sqliteFuncId(Token*);
  1453   1454   int sqlite3ExprResolveNames(NameContext *, Expr *);
  1454   1455   int sqlite3ExprAnalyzeAggregates(NameContext*, Expr*);
         1456  +int sqlite3ExprAnalyzeAggList(NameContext*,ExprList*);
  1455   1457   Vdbe *sqlite3GetVdbe(Parse*);
  1456   1458   void sqlite3Randomness(int, void*);
  1457   1459   void sqlite3RollbackAll(sqlite3*);
  1458   1460   void sqlite3CodeVerifySchema(Parse*, int);
  1459   1461   void sqlite3BeginTransaction(Parse*, int);
  1460   1462   void sqlite3CommitTransaction(Parse*);
  1461   1463   void sqlite3RollbackTransaction(Parse*);