SQLite4
Check-in [f88d080127]
Not logged in

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

Overview
Comment:Remove the 'encoding' argument from sqlite4_create_function().
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: f88d080127433d005246ccf6f3378313d78ccd6e
User & Date: dan 2013-06-13 15:24:05
Context
2013-06-13
16:32
Remove the no longer required FuncDestructor object. check-in: e5d82c92f0 user: dan tags: trunk
15:24
Remove the 'encoding' argument from sqlite4_create_function(). check-in: f88d080127 user: dan tags: trunk
2013-06-12
19:20
Add file selectF.test. check-in: 9678daa99f user: dan tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/attach.c.

   330    330   ** Called by the parser to compile a DETACH statement.
   331    331   **
   332    332   **     DETACH pDbname
   333    333   */
   334    334   void sqlite4Detach(Parse *pParse, Expr *pDbname){
   335    335     static const FuncDef detach_func = {
   336    336       1,                /* nArg */
   337         -    SQLITE4_UTF8,      /* iPrefEnc */
   338    337       0,                /* flags */
   339    338       0,                /* pUserData */
   340    339       0,                /* pNext */
   341    340       detachFunc,       /* xFunc */
   342    341       0,                /* xStep */
   343    342       0,                /* xFinalize */
   344    343       "sqlite_detach",  /* zName */
................................................................................
   352    351   ** Called by the parser to compile an ATTACH statement.
   353    352   **
   354    353   **     ATTACH p AS pDbname KEY pKey
   355    354   */
   356    355   void sqlite4Attach(Parse *pParse, Expr *p, Expr *pDbname, Expr *pKey){
   357    356     static const FuncDef attach_func = {
   358    357       3,                /* nArg */
   359         -    SQLITE4_UTF8,      /* iPrefEnc */
   360    358       0,                /* flags */
   361    359       0,                /* pUserData */
   362    360       0,                /* pNext */
   363    361       attachFunc,       /* xFunc */
   364    362       0,                /* xStep */
   365    363       0,                /* xFinalize */
   366    364       "sqlite_attach",  /* zName */

Changes to src/callback.c.

   219    219   
   220    220   /* During the search for the best function definition, this procedure
   221    221   ** is called to test how well the function passed as the first argument
   222    222   ** matches the request for a function with nArg arguments in a system
   223    223   ** that uses encoding enc. The value returned indicates how well the
   224    224   ** request is matched. A higher value indicates a better match.
   225    225   **
   226         -** The returned value is always between 0 and 6, as follows:
          226  +** The returned value is as follows:
   227    227   **
   228         -** 0: Not a match, or if nArg<0 and the function is has no implementation.
   229         -** 1: A variable arguments function that prefers UTF-8 when a UTF-16
   230         -**    encoding is requested, or vice versa.
   231         -** 2: A variable arguments function that uses UTF-16BE when UTF-16LE is
   232         -**    requested, or vice versa.
   233         -** 3: A variable arguments function using the same text encoding.
   234         -** 4: A function with the exact number of arguments requested that
   235         -**    prefers UTF-8 when a UTF-16 encoding is requested, or vice versa.
   236         -** 5: A function with the exact number of arguments requested that
   237         -**    prefers UTF-16LE when UTF-16BE is requested, or vice versa.
   238         -** 6: An exact match.
   239         -**
          228  +** 0: Not a match, or nArg<0 and the function has no implementation.
          229  +** 1: A variable arguments function.
          230  +** 2: An exact match.
   240    231   */
   241         -static int matchQuality(FuncDef *p, int nArg, u8 enc){
   242         -  int match = 0;
   243         -  if( p->nArg==-1 || p->nArg==nArg 
   244         -   || (nArg==-1 && (p->xFunc!=0 || p->xStep!=0))
   245         -  ){
   246         -    match = 1;
   247         -    if( p->nArg==nArg || nArg==-1 ){
   248         -      match = 4;
   249         -    }
   250         -    if( enc==p->iPrefEnc ){
   251         -      match += 2;
   252         -    }
   253         -    else if( (enc==SQLITE4_UTF16LE && p->iPrefEnc==SQLITE4_UTF16BE) ||
   254         -             (enc==SQLITE4_UTF16BE && p->iPrefEnc==SQLITE4_UTF16LE) ){
   255         -      match += 1;
   256         -    }
   257         -  }
   258         -  return match;
          232  +static int matchQuality(FuncDef *p, int nArg){
          233  +  if( nArg<0 && (p->xFunc || p->xStep) ) return 2;
          234  +  if( p->nArg==nArg ) return 2;
          235  +  if( p->nArg<0 ) return 1;
          236  +  return 0;
   259    237   }
   260    238   
   261    239   /*
   262    240   ** Search a FuncDefTable for a function with the given name.  Return
   263    241   ** a pointer to the matching FuncDef if found, or 0 if there is no match.
   264    242   */
   265    243   static FuncDef *functionSearch(
................................................................................
   318    296   
   319    297   /*
   320    298   ** Locate a user function given a name, a number of arguments and a flag
   321    299   ** indicating whether the function prefers UTF-16 over UTF-8.  Return a
   322    300   ** pointer to the FuncDef structure that defines that function, or return
   323    301   ** NULL if the function does not exist.
   324    302   **
   325         -** If the createFlag argument is true, then a new (blank) FuncDef
   326         -** structure is created and liked into the "db" structure if a
          303  +** If the createFlag argument is true, then a new (zeroed) FuncDef
          304  +** structure is created and linked into the "db" structure if a
   327    305   ** no matching function previously existed.  When createFlag is true
   328    306   ** and the nArg parameter is -1, then only a function that accepts
   329    307   ** any number of arguments will be returned.
   330    308   **
   331    309   ** If createFlag is false and nArg is -1, then the first valid
   332    310   ** function found is returned.  A function is valid if either xFunc
   333    311   ** or xStep is non-zero.
................................................................................
   337    315   ** match that requested.
   338    316   */
   339    317   FuncDef *sqlite4FindFunction(
   340    318     sqlite4 *db,       /* An open database */
   341    319     const char *zName, /* Name of the function.  Not null-terminated */
   342    320     int nName,         /* Number of characters in the name */
   343    321     int nArg,          /* Number of arguments.  -1 means any number */
   344         -  u8 enc,            /* Preferred text encoding */
   345    322     int createFlag     /* Create new entry if true and does not otherwise exist */
   346    323   ){
   347    324     FuncDef *p;         /* Iterator variable */
   348    325     FuncDef *pBest = 0; /* Best match found so far */
   349    326     int bestScore = 0;  /* Score of best match */
   350    327   
   351         -
   352         -  assert( enc==SQLITE4_UTF8 || enc==SQLITE4_UTF16LE || enc==SQLITE4_UTF16BE );
   353         -
   354    328     /* First search for a match amongst the application-defined functions.
   355    329     */
   356    330     p = functionSearch(&db->aFunc, zName, nName);
   357    331     while( p ){
   358         -    int score = matchQuality(p, nArg, enc);
          332  +    int score = matchQuality(p, nArg);
   359    333       if( score>bestScore ){
   360    334         pBest = p;
   361    335         bestScore = score;
   362    336       }
   363    337       p = p->pSameName;
   364    338     }
   365    339   
................................................................................
   376    350     ** So we must not search for built-ins when creating a new function.
   377    351     */ 
   378    352     if( !createFlag && (pBest==0 || (db->flags & SQLITE4_PreferBuiltin)!=0) ){
   379    353       FuncDefTable *pFuncTab = &db->pEnv->aGlobalFuncs;
   380    354       bestScore = 0;
   381    355       p = functionSearch(pFuncTab, zName, nName);
   382    356       while( p ){
   383         -      int score = matchQuality(p, nArg, enc);
          357  +      int score = matchQuality(p, nArg);
   384    358         if( score>bestScore ){
   385    359           pBest = p;
   386    360           bestScore = score;
   387    361         }
   388    362         p = p->pSameName;
   389    363       }
   390    364     }
   391    365   
   392    366     /* If the createFlag parameter is true and the search did not reveal an
   393    367     ** exact match for the name, number of arguments and encoding, then add a
   394    368     ** new entry to the hash table and return it.
   395    369     */
   396         -  if( createFlag && (bestScore<6 || pBest->nArg!=nArg) && 
          370  +  if( createFlag && (bestScore<2 || pBest->nArg!=nArg) && 
   397    371         (pBest = sqlite4DbMallocZero(db, sizeof(*pBest)+nName+1))!=0 ){
   398    372       pBest->zName = (char *)&pBest[1];
   399    373       pBest->nArg = (u16)nArg;
   400         -    pBest->iPrefEnc = enc;
   401    374       memcpy(pBest->zName, zName, nName);
   402    375       pBest->zName[nName] = 0;
   403    376       sqlite4FuncDefInsert(&db->aFunc, pBest, 0);
   404    377     }
   405    378   
   406    379     if( pBest && (pBest->xStep || pBest->xFunc || createFlag) ){
   407    380       return pBest;

Changes to src/expr.c.

  2487   2487         ExprList *pFarg;       /* List of function arguments */
  2488   2488         int nFarg;             /* Number of function arguments */
  2489   2489         FuncDef *pDef;         /* The function definition object */
  2490   2490         int nId;               /* Length of the function name in bytes */
  2491   2491         const char *zId;       /* The function name */
  2492   2492         int constMask = 0;     /* Mask of function arguments that are constant */
  2493   2493         int i;                 /* Loop counter */
  2494         -      u8 enc = ENC(db);      /* The text encoding used by this database */
  2495   2494         CollSeq *pColl = 0;    /* A collating sequence */
  2496   2495   
  2497   2496         assert( !ExprHasProperty(pExpr, EP_xIsSelect) );
  2498   2497         testcase( op==TK_CONST_FUNC );
  2499   2498         testcase( op==TK_FUNCTION );
  2500   2499         if( ExprHasAnyProperty(pExpr, EP_TokenOnly) ){
  2501   2500           pFarg = 0;
................................................................................
  2502   2501         }else{
  2503   2502           pFarg = pExpr->x.pList;
  2504   2503         }
  2505   2504         nFarg = pFarg ? pFarg->nExpr : 0;
  2506   2505         assert( !ExprHasProperty(pExpr, EP_IntValue) );
  2507   2506         zId = pExpr->u.zToken;
  2508   2507         nId = sqlite4Strlen30(zId);
  2509         -      pDef = sqlite4FindFunction(db, zId, nId, nFarg, enc, 0);
         2508  +      pDef = sqlite4FindFunction(db, zId, nId, nFarg, 0);
  2510   2509         if( pDef==0 ){
  2511   2510           sqlite4ErrorMsg(pParse, "unknown function: %.*s()", nId, zId);
  2512   2511           break;
  2513   2512         }
  2514   2513   
  2515   2514         /* Attempt a direct implementation of the built-in COALESCE() and
  2516   2515         ** IFNULL() functions.  This avoids unnecessary evalation of
................................................................................
  3843   3842             if( sqlite4ExprCompare(pItem->pExpr, pExpr)==0 ){
  3844   3843               break;
  3845   3844             }
  3846   3845           }
  3847   3846           if( i>=pAggInfo->nFunc ){
  3848   3847             /* pExpr is original.  Make a new entry in pAggInfo->aFunc[]
  3849   3848             */
  3850         -          u8 enc = ENC(pParse->db);
  3851   3849             i = addAggInfoFunc(pParse->db, pAggInfo);
  3852   3850             if( i>=0 ){
  3853   3851               assert( !ExprHasProperty(pExpr, EP_xIsSelect) );
  3854   3852               pItem = &pAggInfo->aFunc[i];
  3855   3853               pItem->pExpr = pExpr;
  3856   3854               pItem->iMem = ++pParse->nMem;
  3857   3855               assert( !ExprHasProperty(pExpr, EP_IntValue) );
  3858   3856               pItem->pFunc = sqlite4FindFunction(pParse->db,
  3859   3857                      pExpr->u.zToken, sqlite4Strlen30(pExpr->u.zToken),
  3860         -                   pExpr->x.pList ? pExpr->x.pList->nExpr : 0, enc, 0);
         3858  +                   pExpr->x.pList ? pExpr->x.pList->nExpr : 0, 0);
  3861   3859               if( pExpr->flags & EP_Distinct ){
  3862   3860                 pItem->iDistinct = pParse->nTab++;
  3863   3861               }else{
  3864   3862                 pItem->iDistinct = -1;
  3865   3863               }
  3866   3864             }
  3867   3865           }

Changes to src/fts5.c.

  3407   3407   
  3408   3408   /*
  3409   3409   ** Register the default FTS5 tokenizer and functions with handle db.
  3410   3410   */
  3411   3411   int sqlite4InitFts5(sqlite4 *db){
  3412   3412   #ifdef SQLITE4_TEST
  3413   3413     int rc = sqlite4_create_function(
  3414         -      db, "fts5_parse_expr", 3, SQLITE4_UTF8, 0, fts5_parse_expr, 0, 0, 0
         3414  +      db, "fts5_parse_expr", 3, 0, fts5_parse_expr, 0, 0, 0
  3415   3415     );
  3416   3416     if( rc!=SQLITE4_OK ) return rc;
  3417   3417   #endif
  3418   3418     return sqlite4InitFts5Func(db);
  3419   3419   }

Changes to src/func.c.

  1360   1360   }
  1361   1361   
  1362   1362   /*
  1363   1363   ** Set the LIKEOPT flag on the 2-argument function with the given name.
  1364   1364   */
  1365   1365   static void setLikeOptFlag(sqlite4 *db, const char *zName, u8 flagVal){
  1366   1366     FuncDef *pDef;
  1367         -  pDef = sqlite4FindFunction(db, zName, sqlite4Strlen30(zName),
  1368         -                             2, SQLITE4_UTF8, 0);
         1367  +  pDef = sqlite4FindFunction(db, zName, sqlite4Strlen30(zName), 2, 0);
  1369   1368     if( ALWAYS(pDef) ){
  1370   1369       pDef->flags = flagVal;
  1371   1370     }
  1372   1371   }
  1373   1372   
  1374   1373   /*
  1375   1374   ** Register the built-in LIKE and GLOB functions.  The caseSensitive
................................................................................
  1379   1378   void sqlite4RegisterLikeFunctions(sqlite4 *db, int caseSensitive){
  1380   1379     struct compareInfo *pInfo;
  1381   1380     if( caseSensitive ){
  1382   1381       pInfo = (struct compareInfo*)&likeInfoAlt;
  1383   1382     }else{
  1384   1383       pInfo = (struct compareInfo*)&likeInfoNorm;
  1385   1384     }
  1386         -  sqlite4CreateFunc(db, "like", 2, SQLITE4_UTF8, pInfo, likeFunc, 0, 0, 0);
  1387         -  sqlite4CreateFunc(db, "like", 3, SQLITE4_UTF8, pInfo, likeFunc, 0, 0, 0);
  1388         -  sqlite4CreateFunc(db, "glob", 2, SQLITE4_UTF8, 
         1385  +  sqlite4CreateFunc(db, "like", 2, pInfo, likeFunc, 0, 0, 0);
         1386  +  sqlite4CreateFunc(db, "like", 3, pInfo, likeFunc, 0, 0, 0);
         1387  +  sqlite4CreateFunc(db, "glob", 2, 
  1389   1388         (struct compareInfo*)&globInfo, likeFunc, 0, 0, 0);
  1390   1389     setLikeOptFlag(db, "glob", SQLITE4_FUNC_LIKE | SQLITE4_FUNC_CASE);
  1391   1390     setLikeOptFlag(db, "like", 
  1392   1391         caseSensitive ? (SQLITE4_FUNC_LIKE | SQLITE4_FUNC_CASE) : SQLITE4_FUNC_LIKE);
  1393   1392   }
  1394   1393   
  1395   1394   /*
................................................................................
  1405   1404      || !pExpr->x.pList 
  1406   1405      || pExpr->x.pList->nExpr!=2
  1407   1406     ){
  1408   1407       return 0;
  1409   1408     }
  1410   1409     assert( !ExprHasProperty(pExpr, EP_xIsSelect) );
  1411   1410     pDef = sqlite4FindFunction(db, pExpr->u.zToken, 
  1412         -                             sqlite4Strlen30(pExpr->u.zToken),
  1413         -                             2, SQLITE4_UTF8, 0);
         1411  +                             sqlite4Strlen30(pExpr->u.zToken), 2, 0);
  1414   1412     if( NEVER(pDef==0) || (pDef->flags & SQLITE4_FUNC_LIKE)==0 ){
  1415   1413       return 0;
  1416   1414     }
  1417   1415   
  1418   1416     /* The memcpy() statement assumes that the wildcard characters are
  1419   1417     ** the first three statements in the compareInfo structure.  The
  1420   1418     ** asserts() that follow verify that assumption
................................................................................
  1463   1461       FUNCTION(round,              1, 0, 0, roundFunc        ),
  1464   1462       FUNCTION(round,              2, 0, 0, roundFunc        ),
  1465   1463       FUNCTION(upper,              1, 0, 0, upperFunc        ),
  1466   1464       FUNCTION(lower,              1, 0, 0, lowerFunc        ),
  1467   1465       FUNCTION(coalesce,           1, 0, 0, 0                ),
  1468   1466       FUNCTION(coalesce,           0, 0, 0, 0                ),
  1469   1467   /*  FUNCTION(coalesce,          -1, 0, 0, ifnullFunc       ), */
  1470         -    {-1,SQLITE4_UTF8,SQLITE4_FUNC_COALESCE,0,0,ifnullFunc,0,0,"coalesce",0,0},
         1468  +    {-1,SQLITE4_FUNC_COALESCE,0,0,ifnullFunc,0,0,"coalesce",0,0},
  1471   1469       FUNCTION(hex,                1, 0, 0, hexFunc          ),
  1472   1470   /*  FUNCTION(ifnull,             2, 0, 0, ifnullFunc       ), */
  1473         -    {2,SQLITE4_UTF8,SQLITE4_FUNC_COALESCE,0,0,ifnullFunc,0,0,"ifnull",0,0},
         1471  +    {2,SQLITE4_FUNC_COALESCE,0,0,ifnullFunc,0,0,"ifnull",0,0},
  1474   1472       FUNCTION(random,             0, 0, 0, randomFunc       ),
  1475   1473       FUNCTION(randomblob,         1, 0, 0, randomBlob       ),
  1476   1474       FUNCTION(nullif,             2, 0, 1, nullifFunc       ),
  1477   1475       FUNCTION(sqlite_version,     0, 0, 0, versionFunc      ),
  1478   1476       FUNCTION(sqlite_source_id,   0, 0, 0, sourceidFunc     ),
  1479   1477       FUNCTION(sqlite_log,         2, 0, 0, errlogFunc       ),
  1480   1478   #ifndef SQLITE4_OMIT_COMPILEOPTION_DIAGS
................................................................................
  1492   1490       FUNCTION(load_extension,     1, 0, 0, loadExt          ),
  1493   1491       FUNCTION(load_extension,     2, 0, 0, loadExt          ),
  1494   1492     #endif
  1495   1493       AGGREGATE(sum,               1, 0, 0, sumStep,         sumFinalize    ),
  1496   1494       AGGREGATE(total,             1, 0, 0, sumStep,         totalFinalize    ),
  1497   1495       AGGREGATE(avg,               1, 0, 0, sumStep,         avgFinalize    ),
  1498   1496    /* AGGREGATE(count,             0, 0, 0, countStep,       countFinalize  ), */
  1499         -    {0,SQLITE4_UTF8,SQLITE4_FUNC_COUNT,0,0,0,countStep,countFinalize,"count",0,0},
         1497  +    {0,SQLITE4_FUNC_COUNT,0,0,0,countStep,countFinalize,"count",0,0},
  1500   1498       AGGREGATE(count,             1, 0, 0, countStep,       countFinalize  ),
  1501   1499       AGGREGATE(group_concat,      1, 0, 0, groupConcatStep, groupConcatFinalize),
  1502   1500       AGGREGATE(group_concat,      2, 0, 0, groupConcatStep, groupConcatFinalize),
  1503   1501     
  1504   1502       LIKEFUNC(glob, 2, &globInfo, SQLITE4_FUNC_LIKE|SQLITE4_FUNC_CASE),
  1505   1503     #ifdef SQLITE4_CASE_SENSITIVE_LIKE
  1506   1504       LIKEFUNC(like, 2, &likeInfoAlt, SQLITE4_FUNC_LIKE|SQLITE4_FUNC_CASE),

Changes to src/main.c.

   538    538   ** that if a malloc() fails in sqlite4_create_function(), an error code
   539    539   ** is returned and the mallocFailed flag cleared. 
   540    540   */
   541    541   int sqlite4CreateFunc(
   542    542     sqlite4 *db,
   543    543     const char *zFunctionName,
   544    544     int nArg,
   545         -  int enc,
   546    545     void *pUserData,
   547    546     void (*xFunc)(sqlite4_context*,int,sqlite4_value **),
   548    547     void (*xStep)(sqlite4_context*,int,sqlite4_value **),
   549    548     void (*xFinal)(sqlite4_context*),
   550    549     FuncDestructor *pDestructor
   551    550   ){
   552    551     FuncDef *p;
................................................................................
   558    557         (!xFunc && (xFinal && !xStep)) ||
   559    558         (!xFunc && (!xFinal && xStep)) ||
   560    559         (nArg<-1 || nArg>SQLITE4_MAX_FUNCTION_ARG) ||
   561    560         (255<(nName = sqlite4Strlen30( zFunctionName))) ){
   562    561       return SQLITE4_MISUSE_BKPT;
   563    562     }
   564    563     
   565         -#ifndef SQLITE4_OMIT_UTF16
   566         -  /* If SQLITE4_UTF16 is specified as the encoding type, transform this
   567         -  ** to one of SQLITE4_UTF16LE or SQLITE4_UTF16BE using the
   568         -  ** SQLITE4_UTF16NATIVE macro. SQLITE4_UTF16 is not used internally.
   569         -  **
   570         -  ** If SQLITE4_ANY is specified, add three versions of the function
   571         -  ** to the hash table.
   572         -  */
   573         -  if( enc==SQLITE4_UTF16 ){
   574         -    enc = SQLITE4_UTF16NATIVE;
   575         -  }else if( enc==SQLITE4_ANY ){
   576         -    int rc;
   577         -    rc = sqlite4CreateFunc(db, zFunctionName, nArg, SQLITE4_UTF8,
   578         -         pUserData, xFunc, xStep, xFinal, pDestructor);
   579         -    if( rc==SQLITE4_OK ){
   580         -      rc = sqlite4CreateFunc(db, zFunctionName, nArg, SQLITE4_UTF16LE,
   581         -          pUserData, xFunc, xStep, xFinal, pDestructor);
   582         -    }
   583         -    if( rc!=SQLITE4_OK ){
   584         -      return rc;
   585         -    }
   586         -    enc = SQLITE4_UTF16BE;
   587         -  }
   588         -#else
   589         -  enc = SQLITE4_UTF8;
   590         -#endif
   591         -  
   592    564     /* Check if an existing function is being overridden or deleted. If so,
   593    565     ** and there are active VMs, then return SQLITE4_BUSY. If a function
   594    566     ** is being overridden/deleted but there are no active VMs, allow the
   595    567     ** operation to continue but invalidate all precompiled statements.
   596    568     */
   597         -  p = sqlite4FindFunction(db, zFunctionName, nName, nArg, (u8)enc, 0);
   598         -  if( p && p->iPrefEnc==enc && p->nArg==nArg ){
          569  +  p = sqlite4FindFunction(db, zFunctionName, nName, nArg, 0);
          570  +  if( p && p->nArg==nArg ){
   599    571       if( db->activeVdbeCnt ){
   600    572         sqlite4Error(db, SQLITE4_BUSY, 
   601    573           "unable to delete/modify user-function due to active statements");
   602    574         assert( !db->mallocFailed );
   603    575         return SQLITE4_BUSY;
   604    576       }else{
   605    577         sqlite4ExpirePreparedStatements(db);
   606    578       }
   607    579     }
   608    580   
   609         -  p = sqlite4FindFunction(db, zFunctionName, nName, nArg, (u8)enc, 1);
          581  +  p = sqlite4FindFunction(db, zFunctionName, nName, nArg, 1);
   610    582     assert(p || db->mallocFailed);
   611    583     if( !p ){
   612    584       return SQLITE4_NOMEM;
   613    585     }
   614    586   
   615    587     /* If an older version of the function with a configured destructor is
   616    588     ** being replaced invoke the destructor function here. */
................................................................................
   633    605   ** This function is the same as sqlite4_create_function(), except that
   634    606   ** it does not grab the database handle mutex or call sqlite4ApiExit().
   635    607   */
   636    608   static int createFunctionDestructor(
   637    609     sqlite4 *db,
   638    610     const char *zFunc,
   639    611     int nArg,
   640         -  int enc,
   641    612     void *p,
   642    613     void (*xFunc)(sqlite4_context*,int,sqlite4_value **),
   643    614     void (*xStep)(sqlite4_context*,int,sqlite4_value **),
   644    615     void (*xFinal)(sqlite4_context*),
   645    616     void (*xDestroy)(void *)
   646    617   ){
   647    618     int rc;
................................................................................
   652    623       if( !pArg ){
   653    624         xDestroy(p);
   654    625         return SQLITE4_NOMEM;
   655    626       }
   656    627       pArg->xDestroy = xDestroy;
   657    628       pArg->pUserData = p;
   658    629     }
   659         -  rc = sqlite4CreateFunc(db, zFunc, nArg, enc, p, xFunc, xStep, xFinal, pArg);
          630  +  rc = sqlite4CreateFunc(db, zFunc, nArg, p, xFunc, xStep, xFinal, pArg);
   660    631     if( pArg && pArg->nRef==0 ){
   661    632       assert( rc!=SQLITE4_OK );
   662    633       xDestroy(p);
   663    634       sqlite4DbFree(db, pArg);
   664    635     }
   665    636   
   666    637     return rc;
................................................................................
   669    640   /*
   670    641   ** Create new user functions.
   671    642   */
   672    643   int sqlite4_create_function(
   673    644     sqlite4 *db,
   674    645     const char *zFunc,
   675    646     int nArg,
   676         -  int enc,
   677    647     void *p,
   678    648     void (*xFunc)(sqlite4_context*,int,sqlite4_value **),
   679    649     void (*xStep)(sqlite4_context*,int,sqlite4_value **),
   680    650     void (*xFinal)(sqlite4_context*),
   681    651     void (*xDestroy)(void *)
   682    652   ){
   683    653     int rc;
   684    654     sqlite4_mutex_enter(db->mutex);
   685    655     rc = createFunctionDestructor(
   686         -      db, zFunc, nArg, enc, p, xFunc, xStep, xFinal, xDestroy
          656  +      db, zFunc, nArg, p, xFunc, xStep, xFinal, xDestroy
   687    657     );
   688    658     rc = sqlite4ApiExit(db, rc);
   689    659     sqlite4_mutex_leave(db->mutex);
   690    660     return rc;
   691    661   }
   692    662   
   693    663   int sqlite4_create_mi_function(
................................................................................
   700    670     void (*xDestroy)(void *)
   701    671   ){
   702    672     int rc;
   703    673     int n;
   704    674   
   705    675     n = nArg + (nArg>=0);
   706    676     sqlite4_mutex_enter(db->mutex);
   707         -  rc = sqlite4_create_function(db, zFunc, n, enc, p, xFunc, 0,0, xDestroy);
          677  +  rc = sqlite4_create_function(db, zFunc, n, p, xFunc, 0, 0, xDestroy);
   708    678     if( rc==SQLITE4_OK ){
   709         -    FuncDef *p = sqlite4FindFunction(db, zFunc, -1, n, enc, 0);
          679  +    FuncDef *p = sqlite4FindFunction(db, zFunc, -1, n, 0);
   710    680       p->bMatchinfo = 1;
   711    681     }
   712    682     rc = sqlite4ApiExit(db, rc);
   713    683     sqlite4_mutex_leave(db->mutex);
   714    684     return rc;
   715    685   }
   716    686   
................................................................................
   730    700     sqlite4 *db,
   731    701     const char *zName,
   732    702     int nArg
   733    703   ){
   734    704     int nName = sqlite4Strlen30(zName);
   735    705     int rc = SQLITE4_OK;
   736    706     sqlite4_mutex_enter(db->mutex);
   737         -  if( sqlite4FindFunction(db, zName, nName, nArg, SQLITE4_UTF8, 0)==0 ){
   738         -    rc = sqlite4CreateFunc(db, zName, nArg, SQLITE4_UTF8,
          707  +  if( sqlite4FindFunction(db, zName, nName, nArg, 0)==0 ){
          708  +    rc = sqlite4CreateFunc(db, zName, nArg,
   739    709                              0, sqlite4InvalidFunction, 0, 0, 0);
   740    710     }
   741    711     rc = sqlite4ApiExit(db, rc);
   742    712     sqlite4_mutex_leave(db->mutex);
   743    713     return rc;
   744    714   }
   745    715   

Changes to src/pragma.c.

   746    746               zErr = sqlite4MPrintf(
   747    747                   db, "entry missing from index %s: ", pIdx->zName
   748    748               );
   749    749               sqlite4VdbeAddOp4(v, OP_String8, 0, regTmp, 0, zErr, 0);
   750    750               sqlite4VdbeAddOp3(v, OP_Concat, regTmp, regErrstr, regErrstr);
   751    751               sqlite4VdbeAddOp3(v, OP_Function, 0, regKey, regTmp);
   752    752               sqlite4VdbeChangeP4(v, -1,
   753         -                (char *)sqlite4FindFunction(db, "hex", 3, 1, SQLITE4_UTF8, 0), 
          753  +                (char *)sqlite4FindFunction(db, "hex", 3, 1, 0), 
   754    754                   P4_FUNCDEF
   755    755               );
   756    756               sqlite4VdbeChangeP5(v, 1);
   757    757               sqlite4VdbeAddOp3(v, OP_Concat, regTmp, regErrstr, regErrstr);
   758    758               sqlite4VdbeAddOp4(v, OP_String8, 0, regTmp, 0, "\n", 0);
   759    759               sqlite4VdbeAddOp3(v, OP_Concat, regTmp, regErrstr, regErrstr);
   760    760               sqlite4VdbeJumpHere(v, jmp);
................................................................................
  1378   1378               zErr = sqlite4MPrintf(
  1379   1379                   db, "entry missing from index %s: ", pIdx->zName
  1380   1380               );
  1381   1381               sqlite4VdbeAddOp4(v, OP_String8, 0, regTmp, 0, zErr, 0);
  1382   1382               sqlite4VdbeAddOp3(v, OP_Concat, regTmp, regErrstr, regErrstr);
  1383   1383               sqlite4VdbeAddOp3(v, OP_Function, 0, regKey, regTmp);
  1384   1384               sqlite4VdbeChangeP4(v, -1,
  1385         -                (char *)sqlite4FindFunction(db, "hex", 3, 1, SQLITE4_UTF8, 0), 
         1385  +                (char *)sqlite4FindFunction(db, "hex", 3, 1, 0), 
  1386   1386                   P4_FUNCDEF
  1387   1387               );
  1388   1388               sqlite4VdbeChangeP5(v, 1);
  1389   1389               sqlite4VdbeAddOp3(v, OP_Concat, regTmp, regErrstr, regErrstr);
  1390   1390               sqlite4VdbeAddOp4(v, OP_String8, 0, regTmp, 0, "\n", 0);
  1391   1391               sqlite4VdbeAddOp3(v, OP_Concat, regTmp, regErrstr, regErrstr);
  1392   1392               sqlite4VdbeJumpHere(v, jmp);

Changes to src/resolve.c.

   582    582         FuncDef *pDef;              /* Information about the function */
   583    583         u8 enc = ENC(pParse->db);   /* The database encoding */
   584    584   
   585    585         testcase( pExpr->op==TK_CONST_FUNC );
   586    586         assert( !ExprHasProperty(pExpr, EP_xIsSelect) );
   587    587         zId = pExpr->u.zToken;
   588    588         nId = sqlite4Strlen30(zId);
   589         -      pDef = sqlite4FindFunction(pParse->db, zId, nId, n, enc, 0);
          589  +      pDef = sqlite4FindFunction(pParse->db, zId, nId, n, 0);
   590    590         if( pDef==0 ){
   591         -        pDef = sqlite4FindFunction(pParse->db, zId, nId, -1, enc, 0);
          591  +        pDef = sqlite4FindFunction(pParse->db, zId, nId, -1, 0);
   592    592           if( pDef==0 ){
   593    593             no_such_func = 1;
   594    594           }else{
   595    595             wrong_num_args = 1;
   596    596           }
   597    597         }else{
   598    598           is_agg = pDef->xFunc==0;

Changes to src/shell.c.

  1332   1332   ** the database fails to open, print an error message and exit.
  1333   1333   */
  1334   1334   static void open_db(struct callback_data *p){
  1335   1335     if( p->db==0 ){
  1336   1336       sqlite4_open(0, p->zDbFilename, &p->db, 0);
  1337   1337       db = p->db;
  1338   1338       if( db && sqlite4_errcode(db)==SQLITE4_OK ){
  1339         -      sqlite4_create_function(db, "shellstatic", 0, SQLITE4_UTF8, 0,
         1339  +      sqlite4_create_function(db, "shellstatic", 0, 0,
  1340   1340             shellstaticFunc, 0, 0, 0);
  1341   1341       }
  1342   1342       if( db==0 || SQLITE4_OK!=sqlite4_errcode(db) ){
  1343   1343         fprintf(stderr,"Error: unable to open database \"%s\": %s\n", 
  1344   1344             p->zDbFilename, sqlite4_errmsg(db));
  1345   1345         exit(1);
  1346   1346       }

Changes to src/sqlite.h.in.

  2283   2283   ** ^The third parameter (nArg) is the number of arguments that the SQL 
  2284   2284   ** function or aggregate takes. ^If this parameter is -1, then the SQL 
  2285   2285   ** function or aggregate may take any number of arguments between 0 and 
  2286   2286   ** the limit set by [sqlite4_limit]([SQLITE4_LIMIT_FUNCTION_ARG]).  If 
  2287   2287   ** the third parameter is less than -1 or greater than 127 then the 
  2288   2288   ** behavior is undefined.
  2289   2289   **
  2290         -** ^The fourth parameter, eTextRep, specifies the
  2291         -** [SQLITE4_UTF8 | text encoding] this SQL function prefers for
  2292         -** its parameters.  Every SQL function implementation must be able to work
  2293         -** with UTF-8, UTF-16le, or UTF-16be.  But some implementations may be
  2294         -** more efficient with one encoding than another.  ^An application may
  2295         -** invoke sqlite4_create_function() multiple times with the same function 
  2296         -** but with different values of eTextRep. ^When multiple implementations 
  2297         -** of the same function are available, SQLite will pick the one that 
  2298         -** involves the least amount of data conversion. If there is only a single 
  2299         -** implementation which does not care what text encoding is used, then the 
  2300         -** fourth argument should be [SQLITE4_ANY].
  2301         -**
  2302         -** ^(The fifth parameter is an arbitrary pointer.  The implementation of the
         2290  +** ^(The fourth parameter is a context pointer. The implementation of the
  2303   2291   ** function can gain access to this pointer using [sqlite4_context_appdata()].)^
  2304   2292   **
  2305         -** ^The sixth, seventh and eighth parameters, xFunc, xStep and xFinal, are
         2293  +** ^The fifth, sixth and seventh parameters, xFunc, xStep and xFinal, are
  2306   2294   ** pointers to C-language functions that implement the SQL function or
  2307   2295   ** aggregate. ^A scalar SQL function requires an implementation of the xFunc
  2308   2296   ** callback only; NULL pointers must be passed as the xStep and xFinal
  2309   2297   ** parameters. ^An aggregate SQL function requires an implementation of xStep
  2310   2298   ** and xFinal and NULL pointer must be passed for xFunc. ^To delete an existing
  2311   2299   ** SQL function or aggregate, pass NULL pointers for all three function
  2312   2300   ** callbacks.
  2313   2301   **
  2314         -** ^(If the ninth parameter is not NULL, then it is destructor for the 
         2302  +** ^(If the eighth parameter is not NULL, then it is destructor for the 
  2315   2303   ** application data pointer. The destructor is invoked when the function 
  2316   2304   ** is deleted, either by being overloaded or when the database connection 
  2317   2305   ** closes.)^ ^The destructor is also invoked if the call to
  2318   2306   ** sqlite4_create_function() fails. ^When the destructor callback 
  2319   2307   ** is invoked, it is passed a single argument which is a copy of the 
  2320   2308   ** application data pointer which was the fifth parameter to 
  2321   2309   ** sqlite4_create_function().
  2322   2310   **
  2323   2311   ** ^It is permitted to register multiple implementations of the same
  2324         -** functions with the same name but with either differing numbers of
  2325         -** arguments or differing preferred text encodings.  ^SQLite will use
  2326         -** the implementation that most closely matches the way in which the
         2312  +** functions with the same name but differing numbers of arguments. ^SQLite 
         2313  +** will use the implementation that most closely matches the way in which the
  2327   2314   ** SQL function is used.  ^A function implementation with a non-negative
  2328   2315   ** nArg parameter is a better match than a function implementation with
  2329         -** a negative nArg.  ^A function where the preferred text encoding
  2330         -** matches the database encoding is a better
  2331         -** match than a function where the encoding is different.  
  2332         -** ^A function where the encoding difference is between UTF16le and UTF16be
  2333         -** is a closer match than a function where the encoding difference is
  2334         -** between UTF8 and UTF16.
         2316  +** a negative nArg.
  2335   2317   **
  2336   2318   ** ^Built-in functions may be overloaded by new application-defined functions.
  2337   2319   **
  2338   2320   ** ^An application-defined function is permitted to call other
  2339   2321   ** SQLite interfaces.  However, such calls must not
  2340   2322   ** close the database connection nor finalize or reset the prepared
  2341   2323   ** statement in which the function is running.
  2342   2324   */
  2343   2325   int sqlite4_create_function(
  2344   2326     sqlite4 *db,
  2345   2327     const char *zFunctionName,
  2346   2328     int nArg,
  2347         -  int eTextRep,
  2348   2329     void *pApp,
  2349   2330     void (*xFunc)(sqlite4_context*,int,sqlite4_value**),
  2350   2331     void (*xStep)(sqlite4_context*,int,sqlite4_value**),
  2351   2332     void (*xFinal)(sqlite4_context*),
  2352   2333     void(*xDestroy)(void*)
  2353   2334   );
  2354   2335   

Changes to src/sqliteInt.h.

   636    636   ** Each SQL function is defined by an instance of the following
   637    637   ** structure.  A pointer to this structure is stored in the sqlite.aFunc
   638    638   ** hash table.  When multiple functions have the same name, the hash table
   639    639   ** points to a linked list of these structures.
   640    640   */
   641    641   struct FuncDef {
   642    642     i16 nArg;            /* Number of arguments.  -1 means unlimited */
   643         -  u8 iPrefEnc;         /* Preferred text encoding (SQLITE4_UTF8, 16LE, 16BE) */
   644    643     u8 flags;            /* Some combination of SQLITE4_FUNC_* */
   645    644     void *pUserData;     /* User data parameter */
   646    645     FuncDef *pSameName;  /* Next with a different name but the same hash */
   647    646     void (*xFunc)(sqlite4_context*,int,sqlite4_value**); /* Regular function */
   648    647     void (*xStep)(sqlite4_context*,int,sqlite4_value**); /* Aggregate step */
   649    648     void (*xFinalize)(sqlite4_context*);                /* Aggregate finalizer */
   650    649     char *zName;         /* SQL name of the function. */
................................................................................
   988    987   **     that accepts nArg arguments and is implemented by a call to C 
   989    988   **     function likeFunc. Argument pArg is cast to a (void *) and made
   990    989   **     available as the function user-data (sqlite4_context_appdata()). The
   991    990   **     FuncDef.flags variable is set to the value passed as the flags
   992    991   **     parameter.
   993    992   */
   994    993   #define FUNCTION(zName, nArg, iArg, bNC, xFunc) \
   995         -  {nArg, SQLITE4_UTF8, bNC*SQLITE4_FUNC_NEEDCOLL, \
          994  +  {nArg, bNC*SQLITE4_FUNC_NEEDCOLL, \
   996    995      SQLITE4_INT_TO_PTR(iArg), 0, xFunc, 0, 0, #zName, 0, 0}
   997    996   #define STR_FUNCTION(zName, nArg, pArg, bNC, xFunc) \
   998         -  {nArg, SQLITE4_UTF8, bNC*SQLITE4_FUNC_NEEDCOLL, \
          997  +  {nArg, bNC*SQLITE4_FUNC_NEEDCOLL, \
   999    998      pArg, 0, xFunc, 0, 0, #zName, 0, 0}
  1000    999   #define LIKEFUNC(zName, nArg, arg, flags) \
  1001         -  {nArg, SQLITE4_UTF8, flags, (void *)arg, 0, likeFunc, 0, 0, #zName, 0, 0}
         1000  +  {nArg, flags, (void *)arg, 0, likeFunc, 0, 0, #zName, 0, 0}
  1002   1001   #define AGGREGATE(zName, nArg, arg, nc, xStep, xFinal) \
  1003         -  {nArg, SQLITE4_UTF8, nc*SQLITE4_FUNC_NEEDCOLL, \
         1002  +  {nArg, nc*SQLITE4_FUNC_NEEDCOLL, \
  1004   1003      SQLITE4_INT_TO_PTR(arg), 0, 0, xStep,xFinal,#zName,0,0}
  1005   1004   
  1006   1005   /*
  1007   1006   ** All current savepoints are stored in a linked list starting at
  1008   1007   ** sqlite4.pSavepoint. The first element in the list is the most recently
  1009   1008   ** opened savepoint. Savepoints are added to the list by the vdbe
  1010   1009   ** OP_Savepoint instruction.
................................................................................
  2814   2813   void sqlite4HaltConstraint(Parse*, int, char*, int);
  2815   2814   Expr *sqlite4ExprDup(sqlite4*,Expr*,int);
  2816   2815   ExprList *sqlite4ExprListDup(sqlite4*,ExprList*,int);
  2817   2816   SrcList *sqlite4SrcListDup(sqlite4*,SrcList*,int);
  2818   2817   IdList *sqlite4IdListDup(sqlite4*,IdList*);
  2819   2818   Select *sqlite4SelectDup(sqlite4*,Select*,int);
  2820   2819   void sqlite4FuncDefInsert(FuncDefTable*, FuncDef*, int);
  2821         -FuncDef *sqlite4FindFunction(sqlite4*,const char*,int,int,u8,int);
         2820  +FuncDef *sqlite4FindFunction(sqlite4*,const char*,int,int,int);
  2822   2821   void sqlite4RegisterBuiltinFunctions(sqlite4*);
  2823   2822   void sqlite4RegisterDateTimeFunctions(sqlite4_env*);
  2824   2823   void sqlite4RegisterGlobalFunctions(sqlite4_env*);
  2825   2824   int sqlite4SafetyCheckOk(sqlite4*);
  2826   2825   int sqlite4SafetyCheckSickOrOk(sqlite4*);
  2827   2826   void sqlite4ChangeCookie(Parse*, int);
  2828   2827   
................................................................................
  3015   3014   void sqlite4DefaultRowEst(Index*);
  3016   3015   void sqlite4RegisterLikeFunctions(sqlite4*, int);
  3017   3016   int sqlite4IsLikeFunction(sqlite4*,Expr*,int*,char*);
  3018   3017   void sqlite4SchemaClear(sqlite4_env*,Schema*);
  3019   3018   Schema *sqlite4SchemaGet(sqlite4*);
  3020   3019   int sqlite4SchemaToIndex(sqlite4 *db, Schema *);
  3021   3020   KeyInfo *sqlite4IndexKeyinfo(Parse *, Index *);
  3022         -int sqlite4CreateFunc(sqlite4 *, const char *, int, int, void *, 
         3021  +int sqlite4CreateFunc(sqlite4 *, const char *, int, void *, 
  3023   3022     void (*)(sqlite4_context*,int,sqlite4_value **),
  3024   3023     void (*)(sqlite4_context*,int,sqlite4_value **), void (*)(sqlite4_context*),
  3025   3024     FuncDestructor *pDestructor
  3026   3025   );
  3027   3026   int sqlite4ApiExit(sqlite4 *db, int);
  3028   3027   int sqlite4OpenTempDatabase(Parse *);
  3029   3028   

Changes to src/tclsqlite.c.

  1812   1812       if( pFunc==0 ) return TCL_ERROR;
  1813   1813       if( pFunc->pScript ){
  1814   1814         Tcl_DecrRefCount(pFunc->pScript);
  1815   1815       }
  1816   1816       pFunc->pScript = pScript;
  1817   1817       Tcl_IncrRefCount(pScript);
  1818   1818       pFunc->useEvalObjv = safeToUseEvalObjv(interp, pScript);
  1819         -    rc = sqlite4_create_function(pDb->db, zName, nArg, SQLITE4_UTF8,
         1819  +    rc = sqlite4_create_function(pDb->db, zName, nArg,
  1820   1820           pFunc, tclSqlFunc, 0, 0, 0);
  1821   1821       if( rc!=SQLITE4_OK ){
  1822   1822         rc = TCL_ERROR;
  1823   1823         Tcl_SetResult(interp, (char *)sqlite4_errmsg(pDb->db), TCL_VOLATILE);
  1824   1824       }
  1825   1825       break;
  1826   1826     }
................................................................................
  2712   2712     char zBuf[33];
  2713   2713     p = sqlite4_aggregate_context(context, sizeof(*p));
  2714   2714     MD5Final(digest,p);
  2715   2715     MD5DigestToBase16(digest, zBuf);
  2716   2716     sqlite4_result_text(context, zBuf, -1, SQLITE4_TRANSIENT, 0);
  2717   2717   }
  2718   2718   int Md5_Register(sqlite4 *db){
  2719         -  int rc = sqlite4_create_function(db, "md5sum", -1, SQLITE4_UTF8, 0, 0, 
         2719  +  int rc = sqlite4_create_function(db, "md5sum", -1, 0, 0, 
  2720   2720                                    md5step, md5finalize, 0);
  2721   2721     sqlite4_overload_function(db, "md5sum", -1);  /* To exercise this API */
  2722   2722     return rc;
  2723   2723   }
  2724   2724   #endif /* defined(SQLITE4_TEST) */
  2725   2725   
  2726   2726   

Changes to test/func3.test.

    13     13   # with functions created using sqlite4_create_function_v2() is 
    14     14   # correctly invoked.
    15     15   #
    16     16   set testdir [file dirname $argv0]
    17     17   source $testdir/tester.tcl
    18     18   
    19     19   
    20         -ifcapable utf16 {
    21         -  do_test func3-1.1 {
    22         -    set destroyed 0
    23         -    proc destroy {} { set ::destroyed 1 }
    24         -    sqlite4_create_function_v2 db f2 -1 any -func f2 -destroy destroy
    25         -    set destroyed
    26         -  } 0
    27         -  do_test func3-1.2 {
    28         -    sqlite4_create_function_v2 db f2 -1 utf8 -func f2
    29         -    set destroyed
    30         -  } 0
    31         -  do_test func3-1.3 {
    32         -    sqlite4_create_function_v2 db f2 -1 utf16le -func f2
    33         -    set destroyed
    34         -  } 0
    35         -  do_test func3-1.4 {
    36         -    sqlite4_create_function_v2 db f2 -1 utf16be -func f2
    37         -    set destroyed
    38         -  } 1
    39         -}
    40         -
    41     20   do_test func3-2.1 {
    42     21     set destroyed 0
    43     22     proc destroy {} { set ::destroyed 1 }
    44     23     sqlite4_create_function_v2 db f3 -1 utf8 -func f3 -destroy destroy
    45     24     set destroyed
    46     25   } 0
    47     26   do_test func3-2.2 {

Changes to test/permutations.test.

   187    187     printf.test 
   188    188     quote.test
   189    189   
   190    190     savepoint.test savepoint5.test 
   191    191   
   192    192     select1.test select2.test select3.test select4.test select5.test 
   193    193     select6.test select7.test select8.test select9.test selectA.test 
   194         -  selectB.test selectC.test 
          194  +  selectB.test selectC.test selectF.test
   195    195   
   196    196     sort.test
   197    197     storage1.test
   198    198   
   199    199     subquery.test subquery2.test
   200    200     substr.test 
   201    201   

Changes to test/selectF.test.

    92     92   4 0 "SELECT (a/2) FROM t1 GROUP BY (a/2)" {0 1 2 3}
    93     93   5 0 "SELECT a+b FROM t1 GROUP BY (a+b)" {12 15 18 3 6 9}
    94     94   6 1 "SELECT a+b FROM t1 GROUP BY (a+b) ORDER BY 1" {3 6 9 12 15 18}
    95     95   7 0 "SELECT a*b FROM t1 WHERE (c%2)" {18 2 50}
    96     96   8 0 "SELECT count(*) FROM t1, t1 AS t2 WHERE t1.a=t2.a" {6}
    97     97   9 0 "SELECT * FROM t1 WHERE a=1 AND b=2" {{1 2 3}}
    98     98   10 0 "SELECT * FROM t1 WHERE a>3 AND b<12" {{4 8 12} {5 10 15}}
           99  +
          100  +11 1 "SELECT a FROM t1 ORDER BY a" {1 2 3 4 5 6}
          101  +12 1 "SELECT a FROM t1 ORDER BY +a" {1 2 3 4 5 6}
          102  +13 1 "SELECT a FROM t1 ORDER BY b DESC" {6 5 4 3 2 1}
          103  +
    99    104   }
   100    105   
   101    106   finish_test
   102         -
   103         -
   104         -
   105    107   

Changes to test/test_func.c.

   448    448       { "test_isolation",        2, SQLITE4_UTF8, test_isolation},
   449    449       { "test_counter",          1, SQLITE4_UTF8, counterFunc},
   450    450     };
   451    451     int i;
   452    452   
   453    453     for(i=0; i<sizeof(aFuncs)/sizeof(aFuncs[0]); i++){
   454    454       sqlite4_create_function(db, aFuncs[i].zName, aFuncs[i].nArg,
   455         -        aFuncs[i].eTextRep, 0, aFuncs[i].xFunc, 0, 0, 0);
          455  +        0, aFuncs[i].xFunc, 0, 0, 0);
   456    456     }
   457    457   
   458    458     return SQLITE4_OK;
   459    459   }
   460    460   
   461    461   /*
   462    462   ** A bogus step function and finalizer function.
................................................................................
   481    481     sqlite4 *db;
   482    482     int rc;
   483    483     int mxArg;
   484    484   
   485    485     if( getDbPointer(interp, Tcl_GetString(objv[1]), &db) ) return TCL_ERROR;
   486    486   
   487    487     rc = sqlite4_create_function(
   488         -      db, "tx", 1, SQLITE4_UTF8, 0, tStep, tStep, tFinal, 0);
          488  +      db, "tx", 1, 0, tStep, tStep, tFinal, 0);
   489    489     if( rc!=SQLITE4_MISUSE ) goto abuse_err;
   490    490   
   491         -  rc = sqlite4_create_function(db, "tx", 1, SQLITE4_UTF8, 0, tStep, tStep, 0,0);
          491  +  rc = sqlite4_create_function(db, "tx", 1, 0, tStep, tStep, 0,0);
   492    492     if( rc!=SQLITE4_MISUSE ) goto abuse_err;
   493    493   
   494         -  rc = sqlite4_create_function(db, "tx", 1, SQLITE4_UTF8, 0, tStep, 0,tFinal,0);
          494  +  rc = sqlite4_create_function(db, "tx", 1, 0, tStep, 0,tFinal,0);
   495    495     if( rc!=SQLITE4_MISUSE) goto abuse_err;
   496    496   
   497         -  rc = sqlite4_create_function(db, "tx", 1, SQLITE4_UTF8, 0, 0, 0, tFinal, 0);
          497  +  rc = sqlite4_create_function(db, "tx", 1, 0, 0, 0, tFinal, 0);
          498  +  if( rc!=SQLITE4_MISUSE ) goto abuse_err;
          499  +
          500  +  rc = sqlite4_create_function(db, "tx", 1, 0, 0, tStep, 0, 0);
   498    501     if( rc!=SQLITE4_MISUSE ) goto abuse_err;
   499    502   
   500         -  rc = sqlite4_create_function(db, "tx", 1, SQLITE4_UTF8, 0, 0, tStep, 0, 0);
          503  +  rc = sqlite4_create_function(db, "tx", -2, 0, tStep, 0, 0, 0);
   501    504     if( rc!=SQLITE4_MISUSE ) goto abuse_err;
   502    505   
   503         -  rc = sqlite4_create_function(db, "tx", -2, SQLITE4_UTF8, 0, tStep, 0, 0, 0);
   504         -  if( rc!=SQLITE4_MISUSE ) goto abuse_err;
   505         -
   506         -  rc = sqlite4_create_function(db, "tx", 128, SQLITE4_UTF8, 0, tStep, 0, 0, 0);
          506  +  rc = sqlite4_create_function(db, "tx", 128, 0, tStep, 0, 0, 0);
   507    507     if( rc!=SQLITE4_MISUSE ) goto abuse_err;
   508    508   
   509    509     rc = sqlite4_create_function(db, "funcxx"
   510    510          "_123456789_123456789_123456789_123456789_123456789"
   511    511          "_123456789_123456789_123456789_123456789_123456789"
   512    512          "_123456789_123456789_123456789_123456789_123456789"
   513    513          "_123456789_123456789_123456789_123456789_123456789"
   514    514          "_123456789_123456789_123456789_123456789_123456789",
   515         -       1, SQLITE4_UTF8, 0, tStep, 0, 0, 0);
          515  +       1, 0, tStep, 0, 0, 0);
   516    516     if( rc!=SQLITE4_MISUSE ) goto abuse_err;
   517    517   
   518    518     /* This last function registration should actually work.  Generate
   519    519     ** a no-op function (that always returns NULL) and which has the
   520    520     ** maximum-length function name and the maximum number of parameters.
   521    521     */
   522    522     sqlite4_limit(db, SQLITE4_LIMIT_FUNCTION_ARG, 10000);
................................................................................
   523    523     mxArg = sqlite4_limit(db, SQLITE4_LIMIT_FUNCTION_ARG, -1);
   524    524     rc = sqlite4_create_function(db, "nullx"
   525    525          "_123456789_123456789_123456789_123456789_123456789"
   526    526          "_123456789_123456789_123456789_123456789_123456789"
   527    527          "_123456789_123456789_123456789_123456789_123456789"
   528    528          "_123456789_123456789_123456789_123456789_123456789"
   529    529          "_123456789_123456789_123456789_123456789_123456789",
   530         -       mxArg, SQLITE4_UTF8, 0, tStep, 0, 0, 0);
          530  +       mxArg, 0, tStep, 0, 0, 0);
   531    531     if( rc!=SQLITE4_OK ) goto abuse_err;
   532    532                                   
   533    533     return TCL_OK;
   534    534   
   535    535   abuse_err:
   536    536     Tcl_AppendResult(interp, "sqlite4_create_function abused test failed", 
   537    537                      (char*)0);

Changes to test/test_main.c.

   849    849   
   850    850     if( argc!=2 ){
   851    851       Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
   852    852          " DB\"", 0);
   853    853       return TCL_ERROR;
   854    854     }
   855    855     if( getDbPointer(interp, argv[1], &db) ) return TCL_ERROR;
   856         -  rc = sqlite4_create_function(db, "x_coalesce", -1, SQLITE4_ANY, 0, 
   857         -        t1_ifnullFunc, 0, 0, 0);
          856  +  rc = sqlite4_create_function(db, "x_coalesce", -1, 0, t1_ifnullFunc, 0, 0, 0);
   858    857     if( rc==SQLITE4_OK ){
   859         -    rc = sqlite4_create_function(db, "hex8", 1, SQLITE4_ANY, 0, 
   860         -          hex8Func, 0, 0, 0);
          858  +    rc = sqlite4_create_function(db, "hex8", 1, 0, hex8Func, 0, 0, 0);
   861    859     }
   862    860   #ifndef SQLITE4_OMIT_UTF16
   863    861     if( rc==SQLITE4_OK ){
   864         -    rc = sqlite4_create_function(db, "hex16", 1, SQLITE4_ANY, 0, 
   865         -          hex16Func, 0, 0, 0);
          862  +    rc = sqlite4_create_function(db, "hex16", 1, 0, hex16Func, 0, 0, 0);
   866    863     }
   867    864   #endif
   868    865     if( rc==SQLITE4_OK ){
   869         -    rc = sqlite4_create_function(db, "tkt2213func", 1, SQLITE4_ANY, 0, 
          866  +    rc = sqlite4_create_function(db, "tkt2213func", 1, 0, 
   870    867             tkt2213Function, 0, 0, 0);
   871    868     }
   872    869   
   873    870     if( rc==SQLITE4_OK ){
   874    871       rc = sqlite4_create_function(
   875         -        db, "x_sqlite_exec", 1, SQLITE4_UTF16, db, sqlite4ExecFunc, 0, 0, 0
          872  +        db, "x_sqlite_exec", 1, db, sqlite4ExecFunc, 0, 0, 0
   876    873       );
   877    874     }
   878    875   
   879    876     if( sqlite4TestErrCode(interp, db, rc) ) return TCL_ERROR;
   880    877     Tcl_SetResult(interp, (char *)t1ErrorName(rc), 0);
   881    878     return TCL_OK;
   882    879   }
................................................................................
   959    956     int rc;
   960    957     if( argc!=2 ){
   961    958       Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
   962    959          " FILENAME\"", 0);
   963    960       return TCL_ERROR;
   964    961     }
   965    962     if( getDbPointer(interp, argv[1], &db) ) return TCL_ERROR;
   966         -  rc = sqlite4_create_function(db, "x_count", 0, SQLITE4_UTF8, 0, 0,
          963  +  rc = sqlite4_create_function(db, "x_count", 0, 0, 0,
   967    964         t1CountStep, t1CountFinalize, 0);
   968    965     if( rc==SQLITE4_OK ){
   969         -    rc = sqlite4_create_function(db, "x_count", 1, SQLITE4_UTF8, 0, 0,
          966  +    rc = sqlite4_create_function(db, "x_count", 1, 0, 0,
   970    967           t1CountStep, t1CountFinalize, 0);
   971    968     }
   972    969     if( sqlite4TestErrCode(interp, db, rc) ) return TCL_ERROR;
   973    970     Tcl_SetResult(interp, (char *)t1ErrorName(rc), 0);
   974    971     return TCL_OK;
   975    972   }
   976    973   
................................................................................
  1535   1532     if( p->pDestroy ) p->pDestroy = Tcl_DuplicateObj(p->pDestroy); 
  1536   1533   
  1537   1534     if( p->pFunc ) Tcl_IncrRefCount(p->pFunc); 
  1538   1535     if( p->pStep ) Tcl_IncrRefCount(p->pStep); 
  1539   1536     if( p->pFinal ) Tcl_IncrRefCount(p->pFinal); 
  1540   1537     if( p->pDestroy ) Tcl_IncrRefCount(p->pDestroy); 
  1541   1538   
  1542         -  rc = sqlite4_create_function(db, zFunc, nArg, enc, (void *)p, 
         1539  +  rc = sqlite4_create_function(db, zFunc, nArg, (void *)p, 
  1543   1540         (p->pFunc ? cf2Func : 0),
  1544   1541         (p->pStep ? cf2Step : 0),
  1545   1542         (p->pFinal ? cf2Final : 0),
  1546   1543         cf2Destroy
  1547   1544     );
  1548   1545     if( rc!=SQLITE4_OK ){
  1549   1546       Tcl_ResetResult(interp);
................................................................................
  1630   1627     int rc;
  1631   1628     if( argc!=3 ){
  1632   1629       Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0], 
  1633   1630          " DB FUNCTION-NAME", 0);
  1634   1631       return TCL_ERROR;
  1635   1632     }
  1636   1633     if( getDbPointer(interp, argv[1], &db) ) return TCL_ERROR;
  1637         -  rc = sqlite4_create_function(db, argv[2], -1, SQLITE4_UTF8, 0, 
  1638         -      testFunc, 0, 0, 0);
         1634  +  rc = sqlite4_create_function(db, argv[2], -1, 0, testFunc, 0, 0, 0);
  1639   1635     if( rc!=0 ){
  1640   1636       Tcl_AppendResult(interp, sqlite4ErrStr(rc), 0);
  1641   1637       return TCL_ERROR;
  1642   1638     }
  1643   1639     if( sqlite4TestErrCode(interp, db, rc) ) return TCL_ERROR;
  1644   1640     return TCL_OK;
  1645   1641   }
................................................................................
  2290   2286     int val;
  2291   2287   
  2292   2288     if( objc!=5 ) goto bad_args;
  2293   2289     if( getDbPointer(interp, Tcl_GetString(objv[1]), &db) ) return TCL_ERROR;
  2294   2290   
  2295   2291     if( TCL_OK!=Tcl_GetBooleanFromObj(interp, objv[2], &val) ) return TCL_ERROR;
  2296   2292     if( val ){
  2297         -    sqlite4_create_function(db, "test_function", 1, SQLITE4_UTF8, 
         2293  +    sqlite4_create_function(db, "test_function", 1,
  2298   2294           interp, test_function_utf8, 0, 0, 0);
  2299   2295     }
  2300   2296     if( TCL_OK!=Tcl_GetBooleanFromObj(interp, objv[3], &val) ) return TCL_ERROR;
  2301   2297     if( val ){
  2302         -    sqlite4_create_function(db, "test_function", 1, SQLITE4_UTF16LE, 
         2298  +    sqlite4_create_function(db, "test_function", 1,
  2303   2299           interp, test_function_utf16le, 0, 0, 0);
  2304   2300     }
  2305   2301     if( TCL_OK!=Tcl_GetBooleanFromObj(interp, objv[4], &val) ) return TCL_ERROR;
  2306   2302     if( val ){
  2307         -    sqlite4_create_function(db, "test_function", 1, SQLITE4_UTF16BE, 
         2303  +    sqlite4_create_function(db, "test_function", 1,
  2308   2304           interp, test_function_utf16be, 0, 0, 0);
  2309   2305     }
  2310   2306   
  2311   2307     return TCL_OK;
  2312   2308   bad_args:
  2313   2309     Tcl_AppendResult(interp, "wrong # args: should be \"",
  2314   2310         Tcl_GetStringFromObj(objv[0], 0), " <DB> <utf8> <utf16le> <utf16be>", 0);
................................................................................
  3454   3450     sqlite4 *db;
  3455   3451     if( argc!=3 ){
  3456   3452       Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0], 
  3457   3453           " DB function-name", 0);
  3458   3454       return TCL_ERROR;
  3459   3455     }
  3460   3456     if( getDbPointer(interp, argv[1], &db) ) return TCL_ERROR;
  3461         -  rc = sqlite4_create_function(db, argv[2], -1, SQLITE4_UTF8, 0, 0, 0, 0, 0);
         3457  +  rc = sqlite4_create_function(db, argv[2], -1, 0, 0, 0, 0, 0);
  3462   3458     Tcl_SetResult(interp, (char *)t1ErrorName(rc), TCL_STATIC);
  3463   3459     return TCL_OK;
  3464   3460   }
  3465   3461   
  3466   3462   /*
  3467   3463   ** Usage: sqlite_delete_collation DB collation-name
  3468   3464   **