/ Check-in [af1bc20f50]
Login

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

Overview
Comment:Change the meaning of the SQLITE_SUBTYPE flag so that it indicates that the user-defined function cares about the subtypes of its arguments.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | window-functions-subtype-fix2
Files: files | file ages | folders
SHA3-256: af1bc20f502816db460d2b2d353f715da5cf660e59095de5214c829c1cb20981
User & Date: dan 2019-09-13 17:05:48
Context
2019-09-13
18:27
Add the SQLITE_SUBTYPE flag, which may be passed to sqlite3_create_window_function() to indicate that the window function uses sqlite3_value_subtype() to check the sub-type of its arguments. check-in: ba2ebc3a34 user: dan tags: trunk
17:05
Change the meaning of the SQLITE_SUBTYPE flag so that it indicates that the user-defined function cares about the subtypes of its arguments. Closed-Leaf check-in: af1bc20f50 user: dan tags: window-functions-subtype-fix2
16:19
Merge latest trunk changes with this branch. check-in: 14ef754346 user: dan tags: window-functions-subtype-fix
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to ext/misc/json1.c.

  2500   2500     } aMod[] = {
  2501   2501       { "json_each",            &jsonEachModule               },
  2502   2502       { "json_tree",            &jsonTreeModule               },
  2503   2503     };
  2504   2504   #endif
  2505   2505     for(i=0; i<sizeof(aFunc)/sizeof(aFunc[0]) && rc==SQLITE_OK; i++){
  2506   2506       rc = sqlite3_create_function(db, aFunc[i].zName, aFunc[i].nArg,
  2507         -                        SQLITE_UTF8 | SQLITE_DETERMINISTIC | SQLITE_SUBTYPE, 
  2508         -                        (void*)&aFunc[i].flag,
  2509         -                        aFunc[i].xFunc, 0, 0);
         2507  +                                 SQLITE_UTF8 | SQLITE_DETERMINISTIC,
         2508  +                                 (void*)&aFunc[i].flag,
         2509  +                                 aFunc[i].xFunc, 0, 0);
  2510   2510     }
  2511   2511   #ifndef SQLITE_OMIT_WINDOWFUNC
  2512   2512     for(i=0; i<sizeof(aAgg)/sizeof(aAgg[0]) && rc==SQLITE_OK; i++){
  2513   2513       rc = sqlite3_create_window_function(db, aAgg[i].zName, aAgg[i].nArg,
  2514         -                                 SQLITE_UTF8 | SQLITE_DETERMINISTIC, 0,
         2514  +                SQLITE_SUBTYPE | SQLITE_UTF8 | SQLITE_DETERMINISTIC, 0,
  2515   2515                                    aAgg[i].xStep, aAgg[i].xFinal,
  2516   2516                                    aAgg[i].xValue, jsonGroupInverse, 0);
  2517   2517     }
  2518   2518   #endif
  2519   2519   #ifndef SQLITE_OMIT_VIRTUALTABLE
  2520   2520     for(i=0; i<sizeof(aMod)/sizeof(aMod[0]) && rc==SQLITE_OK; i++){
  2521   2521       rc = sqlite3_create_module(db, aMod[i].zName, aMod[i].pModule, 0);

Changes to src/sqlite.h.in.

  4984   4984   ** The SQLITE_DETERMINISTIC flag means that the new function will always
  4985   4985   ** maps the same inputs into the same output.  The abs() function is
  4986   4986   ** deterministic, for example, but randomblob() is not.
  4987   4987   **
  4988   4988   ** The SQLITE_DIRECTONLY flag means that the function may only be invoked
  4989   4989   ** from top-level SQL, and cannot be used in VIEWs or TRIGGERs.
  4990   4990   **
  4991         -** The SQLITE_SUBTYPE flag indicates to SQLite that the function may call
  4992         -** [sqlite3_result_subtype()] in order to configure its return value with
  4993         -** a sub-type.
         4991  +** The SQLITE_SUBTYPE flag indicates to SQLite that a function may call
         4992  +** [sqlite3_value_subtype()] to inspect the sub-types of its arguments.
         4993  +** Specifying this flag makes no difference for scalar or aggregate user
         4994  +** functions. However, if it is not specified for a user-defined window
         4995  +** function, then any sub-types belonging to arguments passed to the window
         4996  +** function may be discarded before the window function is called (i.e.
         4997  +** sqlite3_value_subtype() will always return 0).
  4994   4998   */
  4995   4999   #define SQLITE_DETERMINISTIC    0x000000800
  4996   5000   #define SQLITE_DIRECTONLY       0x000080000
  4997   5001   #define SQLITE_SUBTYPE          0x000100000
  4998   5002   
  4999   5003   /*
  5000   5004   ** CAPI3REF: Deprecated Functions

Changes to src/window.c.

   864    864     sWalker.u.pRewrite = &sRewrite;
   865    865   
   866    866     (void)sqlite3WalkExprList(&sWalker, pEList);
   867    867   
   868    868     *ppSub = sRewrite.pSub;
   869    869   }
   870    870   
   871         -/*
   872         -** Return true if the top-level of list pList contains an SQL function 
   873         -** with the SQLITE_FUNC_SUBTYPE flag set. Return false otherwise.
   874         -*/
   875         -int exprListContainsSubtype(Parse *pParse, ExprList *pList){
   876         -  if( pList ){
   877         -    sqlite3 *db = pParse->db;
   878         -    int i;
   879         -    for(i=0; i<pList->nExpr; i++){
   880         -      Expr *p = pList->a[i].pExpr;
   881         -      if( p->op==TK_FUNCTION ){
   882         -        FuncDef *pDef;
   883         -        int nArg = 0;
   884         -        if( !ExprHasProperty(p, EP_TokenOnly) && p->x.pList ){
   885         -          nArg = p->x.pList->nExpr;
   886         -        }
   887         -        pDef = sqlite3FindFunction(db, p->u.zToken, nArg, db->enc, 0);
   888         -        if( pDef && (pDef->funcFlags & SQLITE_FUNC_SUBTYPE) ){
   889         -          return 1;
   890         -        }
   891         -      }
   892         -    }
   893         -  }
   894         -  return 0;
   895         -}
   896         -
   897    871   /*
   898    872   ** Append a copy of each expression in expression-list pAppend to
   899    873   ** expression list pList. Return a pointer to the result list.
   900    874   */
   901    875   static ExprList *exprListAppendList(
   902    876     Parse *pParse,          /* Parsing context */
   903    877     ExprList *pList,        /* List to which to append. Might be NULL */
................................................................................
   988    962   
   989    963       /* Append the arguments passed to each window function to the
   990    964       ** sub-select expression list. Also allocate two registers for each
   991    965       ** window function - one for the accumulator, another for interim
   992    966       ** results.  */
   993    967       for(pWin=pMWin; pWin; pWin=pWin->pNextWin){
   994    968         ExprList *pArgs = pWin->pOwner->x.pList;
   995         -      if( exprListContainsSubtype(pParse, pArgs) ){
          969  +      if( pWin->pFunc->funcFlags & SQLITE_FUNC_SUBTYPE ){
   996    970           selectWindowRewriteEList(pParse, pMWin, pSrc, pArgs, pTab, &pSublist);
   997    971           pWin->iArgCol = (pSublist ? pSublist->nExpr : 0);
   998    972           pWin->bExprArgs = 1;
   999    973         }else{
  1000    974           pWin->iArgCol = (pSublist ? pSublist->nExpr : 0);
  1001    975           pSublist = exprListAppendList(pParse, pSublist, pArgs, 0);
  1002    976         }