/ Check-in [a7acc787]
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:Correctly handle empty function argument lists on table-valued functions.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: a7acc7878b8bb8e27a0da67b2dbb7bd51df4859b
User & Date: drh 2015-08-20 20:13:37
Context
2015-08-20
20:21
Fix stray variable declaration for C89. check-in: 17eb7f18 user: mistachkin tags: trunk
20:13
Correctly handle empty function argument lists on table-valued functions. check-in: a7acc787 user: drh tags: trunk
19:55
Add support for table-valued functions in the FROM clause implemented as virtual tables. check-in: 9b718b06 user: drh tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/build.c.

  3798   3798   }
  3799   3799   
  3800   3800   /*
  3801   3801   ** Add the list of function arguments to the SrcList entry for a
  3802   3802   ** table-valued-function.
  3803   3803   */
  3804   3804   void sqlite3SrcListFuncArgs(Parse *pParse, SrcList *p, ExprList *pList){
  3805         -  if( p && ALWAYS(p->nSrc>0) ){
         3805  +  if( p && ALWAYS(p->nSrc>0) && pList ){
  3806   3806       struct SrcList_item *pItem = &p->a[p->nSrc-1];
  3807   3807       assert( pItem->fg.notIndexed==0 );
  3808   3808       assert( pItem->fg.isIndexedBy==0 );
  3809   3809       assert( pItem->fg.isTabFunc==0 );
  3810   3810       pItem->u1.pFuncArg = pList;
  3811   3811       pItem->fg.isTabFunc = 1;
  3812   3812     }

Changes to src/resolve.c.

  1447   1447   ** just like sqlite3ResolveExprNames() except that it works for an expression
  1448   1448   ** list rather than a single expression.
  1449   1449   */
  1450   1450   int sqlite3ResolveExprListNames( 
  1451   1451     NameContext *pNC,       /* Namespace to resolve expressions in. */
  1452   1452     ExprList *pList         /* The expression list to be analyzed. */
  1453   1453   ){
  1454         -  int i;
  1455         -  for(i=0; i<pList->nExpr; i++){
  1456         -    if( sqlite3ResolveExprNames(pNC, pList->a[i].pExpr) ) return WRC_Abort;
         1454  +  if( pList ){
         1455  +    int i;
         1456  +    for(i=0; i<pList->nExpr; i++){
         1457  +      if( sqlite3ResolveExprNames(pNC, pList->a[i].pExpr) ) return WRC_Abort;
         1458  +    }
  1457   1459     }
  1458   1460     return WRC_Continue;
  1459   1461   }
  1460   1462   
  1461   1463   /*
  1462   1464   ** Resolve all names in all expressions of a SELECT and in all
  1463   1465   ** decendents of the SELECT, including compounds off of p->pPrior,

Changes to test/tabfunc01.test.

    56     56   } {7 30 6 25 5 20 4 15 3 10 2 5 1 0}
    57     57   
    58     58   do_execsql_test tabfunc01-2.1 {
    59     59     CREATE TABLE t1(x);
    60     60     INSERT INTO t1(x) VALUES(2),(3);
    61     61     SELECT *, '|' FROM t1, generate_series(1,x) ORDER BY 1, 2
    62     62   } {2 1 | 2 2 | 3 1 | 3 2 | 3 3 |}
           63  +
           64  +do_execsql_test tabfunc01-2.2 {
           65  +  SELECT * FROM generate_series() LIMIT 5;
           66  +} {0 1 2 3 4}
           67  +
    63     68   
    64     69   finish_test