/ Check-in [b7f30a9f]
Login

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

Overview
Comment:Add the experimental SQLITE_ENABLE_UNKNOWN_SQL_FUNCTION compile-time option. When enabled, the "unknown function" error is suppressed for EXPLAIN and a no-op function named "unknown()" is substituted. This facilitiates using the command-line shell to analyze queries from applications that contain many application-defined functions that are not normally available to the shell.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: b7f30a9ff20d580fdaecdcf2b644d09ad6c2575e
User & Date: drh 2016-08-04 12:35:17
Context
2016-08-04
13:23
Revert the SQLITE_APICALL changes for now. That changes needs further research before it is released. Deferred until 3.15. check-in: 9adda385 user: drh tags: trunk
12:35
Add the experimental SQLITE_ENABLE_UNKNOWN_SQL_FUNCTION compile-time option. When enabled, the "unknown function" error is suppressed for EXPLAIN and a no-op function named "unknown()" is substituted. This facilitiates using the command-line shell to analyze queries from applications that contain many application-defined functions that are not normally available to the shell. check-in: b7f30a9f user: drh tags: trunk
09:09
Make sure the ORDER BY LIMIT optimization is not applied if the inner-most loop can only have a single iteration and is hence not really a loop. check-in: 13e3bd3d user: drh tags: trunk
01:47
Add an experimental SQLITE_ENABLE_UNKNOWN_SQL_FUNCTION compile-time option. This changes has been merged into main branches via cherry-pick. Closed-Leaf check-in: 4ada023c user: drh tags: unknown-function
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to Makefile.in.

   554    554   # Standard options to testfixture
   555    555   #
   556    556   TESTOPTS = --verbose=file --output=test-out.txt
   557    557   
   558    558   # Extra compiler options for various shell tools
   559    559   #
   560    560   SHELL_OPT = -DSQLITE_ENABLE_JSON1 -DSQLITE_ENABLE_FTS4
          561  +# SHELL_OPT += -DSQLITE_ENABLE_FTS5
   561    562   SHELL_OPT += -DSQLITE_ENABLE_EXPLAIN_COMMENTS
          563  +SHELL_OPT += -DSQLITE_ENABLE_UNKNOWN_SQL_FUNCTION
   562    564   FUZZERSHELL_OPT = -DSQLITE_ENABLE_JSON1
   563    565   FUZZCHECK_OPT = -DSQLITE_ENABLE_JSON1 -DSQLITE_ENABLE_MEMSYS5
   564    566   
   565    567   # This is the default Makefile target.  The objects listed here
   566    568   # are what get build when you type just "make" with no arguments.
   567    569   #
   568    570   all:	sqlite3.h libsqlite3.la sqlite3$(TEXE) $(HAVE_TCL:1=libtclsqlite3.la)

Changes to Makefile.msc.

  1420   1420     $(TOP)\test\fuzzdata4.db
  1421   1421   # <</mark>>
  1422   1422   
  1423   1423   # Additional compiler options for the shell.  These are only effective
  1424   1424   # when the shell is not being dynamically linked.
  1425   1425   #
  1426   1426   !IF $(DYNAMIC_SHELL)==0 && $(FOR_WIN10)==0
  1427         -SHELL_COMPILE_OPTS = $(SHELL_COMPILE_OPTS) -DSQLITE_SHELL_JSON1 -DSQLITE_ENABLE_FTS4 -DSQLITE_ENABLE_EXPLAIN_COMMENTS
         1427  +SHELL_COMPILE_OPTS = $(SHELL_COMPILE_OPTS) -DSQLITE_SHELL_JSON1 -DSQLITE_ENABLE_FTS4
         1428  +# SHELL_COMPILE_OPTS = $(SHELL_COMPILE_OPTS) -DSQLITE_ENABLE_FTS5
         1429  +SHELL_COMPILE_OPTS = $(SHELL_COMPILE_OPTS) -DSQLITE_ENABLE_EXPLAIN_COMMENTS
         1430  +SHELL_COMPILE_OPTS = $(SHELL_COMPILE_OPTS) -DSQLITE_ENABLE_UNKNOWN_SQL_FUNCTION
  1428   1431   !ENDIF
  1429   1432   
  1430   1433   # <<mark>>
  1431   1434   # Extra compiler options for various test tools.
  1432   1435   #
  1433   1436   MPTESTER_COMPILE_OPTS = -DSQLITE_SHELL_JSON1 -DSQLITE_ENABLE_FTS5
  1434   1437   FUZZERSHELL_COMPILE_OPTS = -DSQLITE_ENABLE_JSON1

Changes to main.mk.

   466    466   # Standard options to testfixture
   467    467   #
   468    468   TESTOPTS = --verbose=file --output=test-out.txt
   469    469   
   470    470   # Extra compiler options for various shell tools
   471    471   #
   472    472   SHELL_OPT = -DSQLITE_ENABLE_JSON1 -DSQLITE_ENABLE_FTS4 -DSQLITE_ENABLE_FTS5
          473  +SHELL_OPT += -DSQLITE_ENABLE_EXPLAIN_COMMENTS
          474  +SHELL_OPT += -DSQLITE_ENABLE_UNKNOWN_SQL_FUNCTION
   473    475   FUZZERSHELL_OPT = -DSQLITE_ENABLE_JSON1
   474    476   FUZZCHECK_OPT = -DSQLITE_ENABLE_JSON1 -DSQLITE_ENABLE_MEMSYS5
   475    477   
   476    478   # This is the default Makefile target.  The objects listed here
   477    479   # are what get build when you type just "make" with no arguments.
   478    480   #
   479    481   all:	sqlite3.h libsqlite3.a sqlite3$(EXE)

Changes to src/expr.c.

  2939   2939         }else{
  2940   2940           pFarg = pExpr->x.pList;
  2941   2941         }
  2942   2942         nFarg = pFarg ? pFarg->nExpr : 0;
  2943   2943         assert( !ExprHasProperty(pExpr, EP_IntValue) );
  2944   2944         zId = pExpr->u.zToken;
  2945   2945         pDef = sqlite3FindFunction(db, zId, nFarg, enc, 0);
         2946  +#ifdef SQLITE_ENABLE_UNKNOWN_SQL_FUNCTION
         2947  +      if( pDef==0 && pParse->explain ){
         2948  +        pDef = sqlite3FindFunction(db, "unknown", nFarg, enc, 0);
         2949  +      }
         2950  +#endif
  2946   2951         if( pDef==0 || pDef->xFinalize!=0 ){
  2947   2952           sqlite3ErrorMsg(pParse, "unknown function: %s()", zId);
  2948   2953           break;
  2949   2954         }
  2950   2955   
  2951   2956         /* Attempt a direct implementation of the built-in COALESCE() and
  2952   2957         ** IFNULL() functions.  This avoids unnecessary evaluation of

Changes to src/func.c.

  1311   1311       if( zCharSet ){
  1312   1312         sqlite3_free(azChar);
  1313   1313       }
  1314   1314     }
  1315   1315     sqlite3_result_text(context, (char*)zIn, nIn, SQLITE_TRANSIENT);
  1316   1316   }
  1317   1317   
         1318  +
         1319  +#ifdef SQLITE_ENABLE_UNKNOWN_SQL_FUNCTION
         1320  +/*
         1321  +** The "unknown" function is automatically substituted in place of
         1322  +** any unrecognized function name when doing an EXPLAIN or EXPLAIN QUERY PLAN
         1323  +** when the SQLITE_ENABLE_UNKNOWN_FUNCTION compile-time option is used.
         1324  +** When the "sqlite3" command-line shell is built using this functionality,
         1325  +** that allows an EXPLAIN or EXPLAIN QUERY PLAN for complex queries
         1326  +** involving application-defined functions to be examined in a generic
         1327  +** sqlite3 shell.
         1328  +*/
         1329  +static void unknownFunc(
         1330  +  sqlite3_context *context,
         1331  +  int argc,
         1332  +  sqlite3_value **argv
         1333  +){
         1334  +  /* no-op */
         1335  +}
         1336  +#endif /*SQLITE_ENABLE_UNKNOWN_SQL_FUNCTION*/
         1337  +
  1318   1338   
  1319   1339   /* IMP: R-25361-16150 This function is omitted from SQLite by default. It
  1320   1340   ** is only available if the SQLITE_SOUNDEX compile-time option is used
  1321   1341   ** when SQLite is built.
  1322   1342   */
  1323   1343   #ifdef SQLITE_SOUNDEX
  1324   1344   /*
................................................................................
  1782   1802       AGGREGATE2(count,            0, 0, 0, countStep,       countFinalize,
  1783   1803                  SQLITE_FUNC_COUNT  ),
  1784   1804       AGGREGATE(count,             1, 0, 0, countStep,       countFinalize  ),
  1785   1805       AGGREGATE(group_concat,      1, 0, 0, groupConcatStep, groupConcatFinalize),
  1786   1806       AGGREGATE(group_concat,      2, 0, 0, groupConcatStep, groupConcatFinalize),
  1787   1807     
  1788   1808       LIKEFUNC(glob, 2, &globInfo, SQLITE_FUNC_LIKE|SQLITE_FUNC_CASE),
  1789         -  #ifdef SQLITE_CASE_SENSITIVE_LIKE
         1809  +#ifdef SQLITE_CASE_SENSITIVE_LIKE
  1790   1810       LIKEFUNC(like, 2, &likeInfoAlt, SQLITE_FUNC_LIKE|SQLITE_FUNC_CASE),
  1791   1811       LIKEFUNC(like, 3, &likeInfoAlt, SQLITE_FUNC_LIKE|SQLITE_FUNC_CASE),
  1792         -  #else
         1812  +#else
  1793   1813       LIKEFUNC(like, 2, &likeInfoNorm, SQLITE_FUNC_LIKE),
  1794   1814       LIKEFUNC(like, 3, &likeInfoNorm, SQLITE_FUNC_LIKE),
  1795         -  #endif
         1815  +#endif
         1816  +#ifdef SQLITE_ENABLE_UNKNOWN_SQL_FUNCTION
         1817  +    FUNCTION(unknown,           -1, 0, 0, unknownFunc      ),
         1818  +#endif
  1796   1819       FUNCTION(coalesce,           1, 0, 0, 0                ),
  1797   1820       FUNCTION(coalesce,           0, 0, 0, 0                ),
  1798   1821       FUNCTION2(coalesce,         -1, 0, 0, noopFunc,  SQLITE_FUNC_COALESCE),
  1799   1822     };
  1800   1823   #ifndef SQLITE_OMIT_ALTERTABLE
  1801   1824     sqlite3AlterFunctions();
  1802   1825   #endif

Changes to src/resolve.c.

   714    714             notValid(pParse, pNC, "non-deterministic functions", NC_IdxExpr);
   715    715           }
   716    716         }
   717    717         if( is_agg && (pNC->ncFlags & NC_AllowAgg)==0 ){
   718    718           sqlite3ErrorMsg(pParse, "misuse of aggregate function %.*s()", nId,zId);
   719    719           pNC->nErr++;
   720    720           is_agg = 0;
   721         -      }else if( no_such_func && pParse->db->init.busy==0 ){
          721  +      }else if( no_such_func && pParse->db->init.busy==0
          722  +#ifdef SQLITE_ENABLE_UNKNOWN_SQL_FUNCTION
          723  +                && pParse->explain==0
          724  +#endif
          725  +      ){
   722    726           sqlite3ErrorMsg(pParse, "no such function: %.*s", nId, zId);
   723    727           pNC->nErr++;
   724    728         }else if( wrong_num_args ){
   725    729           sqlite3ErrorMsg(pParse,"wrong number of arguments to function %.*s()",
   726    730                nId, zId);
   727    731           pNC->nErr++;
   728    732         }