mirror of
https://github.com/sqlite/sqlite.git
synced 2025-10-24 09:53:10 +03:00
Move date+time functions to start-time initialization. Additional
start-time function cleanup. (CVS 5585) FossilOrigin-Name: 80d6a31cb3851704c09ac9d99fe4bc241df3c180
This commit is contained in:
79
src/func.c
79
src/func.c
@@ -16,11 +16,8 @@
|
||||
** sqliteRegisterBuildinFunctions() found at the bottom of the file.
|
||||
** All other code has file scope.
|
||||
**
|
||||
** $Id: func.c,v 1.198 2008/08/21 18:49:28 drh Exp $
|
||||
** $Id: func.c,v 1.199 2008/08/21 20:21:35 drh Exp $
|
||||
*/
|
||||
|
||||
#ifndef CREATE_BUILTIN_HASHTABLE
|
||||
|
||||
#include "sqliteInt.h"
|
||||
#include <ctype.h>
|
||||
#include <stdlib.h>
|
||||
@@ -1222,7 +1219,6 @@ void sqlite3RegisterBuiltinFunctions(sqlite3 *db){
|
||||
#ifndef SQLITE_OMIT_PARSER
|
||||
sqlite3AttachFunctions(db);
|
||||
#endif
|
||||
sqlite3RegisterDateTimeFunctions(db);
|
||||
if( !db->mallocFailed ){
|
||||
int rc = sqlite3_overload_function(db, "MATCH", 2);
|
||||
assert( rc==SQLITE_NOMEM || rc==SQLITE_OK );
|
||||
@@ -1301,65 +1297,12 @@ int sqlite3IsLikeFunction(sqlite3 *db, Expr *pExpr, int *pIsNocase, char *aWc){
|
||||
}
|
||||
|
||||
/*
|
||||
** The following three macros, FUNCTION(), LIKEFUNC() and AGGREGATE() are
|
||||
** used to create the literal values used for the FuncDef structures in
|
||||
** the global aBuiltinFunc[] array (see below).
|
||||
** The following array holds FuncDef structures for all of the functions
|
||||
** defined in this file.
|
||||
**
|
||||
** FUNCTION(zName, nArg, iArg, bNC, xFunc)
|
||||
** Used to create a scalar function definition of a function zName
|
||||
** implemented by C function xFunc that accepts nArg arguments. The
|
||||
** value passed as iArg is cast to a (void*) and made available
|
||||
** as the user-data (sqlite3_user_data()) for the function. If
|
||||
** argument bNC is true, then the FuncDef.needCollate flag is set.
|
||||
**
|
||||
** AGGREGATE(zName, nArg, iArg, bNC, xStep, xFinal)
|
||||
** Used to create an aggregate function definition implemented by
|
||||
** the C functions xStep and xFinal. The first four parameters
|
||||
** are interpreted in the same way as the first 4 parameters to
|
||||
** FUNCTION().
|
||||
**
|
||||
** LIKEFUNC(zName, nArg, pArg, flags)
|
||||
** Used to create a scalar function definition of a function zName
|
||||
** that accepts nArg arguments and is implemented by a call to C
|
||||
** function likeFunc. Argument pArg is cast to a (void *) and made
|
||||
** available as the function user-data (sqlite3_user_data()). The
|
||||
** FuncDef.flags variable is set to the value passed as the flags
|
||||
** parameter.
|
||||
**
|
||||
** See below for examples.
|
||||
*/
|
||||
#define FUNCTION(zName, nArg, iArg, bNC, xFunc) \
|
||||
{nArg, SQLITE_UTF8, bNC, 0, SQLITE_INT_TO_PTR(iArg), 0, xFunc, 0, 0, #zName}
|
||||
|
||||
#define LIKEFUNC(zName, nArg, arg, flags) \
|
||||
{nArg, SQLITE_UTF8, 0, flags, (void *)arg, 0, likeFunc, 0, 0, #zName}
|
||||
|
||||
#define AGGREGATE(zName, nArg, arg, nc, xStep, xFinal) \
|
||||
{nArg, SQLITE_UTF8, nc, 0, SQLITE_INT_TO_PTR(arg), 0, 0, xStep,xFinal, #zName}
|
||||
|
||||
#endif
|
||||
|
||||
/*
|
||||
** This array of FuncDef structures contains most of the "built-in" functions
|
||||
** and aggregates. Function users (the other routines in the SQL compiler)
|
||||
** call the following function to access the FuncDef structures stored in
|
||||
** this array:
|
||||
**
|
||||
** int sqlite3GetBuiltinFunction(const char *z, int n, FuncDef **paFunc);
|
||||
**
|
||||
** The caller passes the name of the required function and its length
|
||||
** in parameters z and n, respectively. The value returned is the number
|
||||
** of FuncDef structures found in the aBuiltinFunc[] array that match
|
||||
** the requested name. If no match is found, 0 is returned. *paFunc is
|
||||
** set to point at a static array containing that subset of aBuiltinFunc[]
|
||||
** before returning.
|
||||
**
|
||||
** The implementation of sqlite3GetBuiltinFunction() is generated by
|
||||
** the program found in tool/mkfunction.c, which is compiled and executed
|
||||
** as part of the build process. The routine generated by this program
|
||||
** assumes that if there are two or more entries in the aBuiltinFunc[]
|
||||
** array with the same name (i.e. two versions of the "max" function),
|
||||
** then they must be stored in adjacent slots.
|
||||
** The array cannot be constant since changes are made to the
|
||||
** FuncDef.pHash elements at start-time. The elements of this array
|
||||
** are read-only after initialization is complete.
|
||||
*/
|
||||
static FuncDef aBuiltinFunc[] = {
|
||||
FUNCTION(ltrim, 1, 1, 0, trimFunc ),
|
||||
@@ -1423,12 +1366,16 @@ static FuncDef aBuiltinFunc[] = {
|
||||
};
|
||||
|
||||
/*
|
||||
** Build up the global built-in function table at initialization
|
||||
** time.
|
||||
** All all of the FuncDef structures in the aBuiltinFunc[] array above
|
||||
** to the global function hash table. This occurs at start-time (as
|
||||
** a consequence of calling sqlite3_initialize()).
|
||||
**
|
||||
** After this routine runs
|
||||
*/
|
||||
void sqlite3RegisterGlobalFunctions(void){
|
||||
int i;
|
||||
for(i=0; i<ArraySize(aBuiltinFunc); i++){
|
||||
sqlite3FuncDefInsert(&sqlite3FuncBuiltins, &aBuiltinFunc[i]);
|
||||
sqlite3FuncDefInsert(&sqlite3GlobalFunctions, &aBuiltinFunc[i]);
|
||||
}
|
||||
sqlite3RegisterDateTimeFunctions();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user