mirror of
https://github.com/sqlite/sqlite.git
synced 2025-08-07 02:42:48 +03:00
Improvements to the application-defined function mechanism so that it is
more compact and runs faster, especially when the application defines thousands of new SQL functions. FossilOrigin-Name: 3201fbcc5105d23132e6b8b7ac825e66af4f8a39
This commit is contained in:
43
src/main.c
43
src/main.c
@@ -218,7 +218,6 @@ int sqlite3_initialize(void){
|
||||
*/
|
||||
sqlite3_mutex_enter(sqlite3GlobalConfig.pInitMutex);
|
||||
if( sqlite3GlobalConfig.isInit==0 && sqlite3GlobalConfig.inProgress==0 ){
|
||||
FuncDefHash *pHash = &GLOBAL(FuncDefHash, sqlite3GlobalFunctions);
|
||||
sqlite3GlobalConfig.inProgress = 1;
|
||||
#ifdef SQLITE_ENABLE_SQLLOG
|
||||
{
|
||||
@@ -226,8 +225,8 @@ int sqlite3_initialize(void){
|
||||
sqlite3_init_sqllog();
|
||||
}
|
||||
#endif
|
||||
memset(pHash, 0, sizeof(sqlite3GlobalFunctions));
|
||||
sqlite3RegisterGlobalFunctions();
|
||||
memset(&sqlite3BuiltinFunctions, 0, sizeof(sqlite3BuiltinFunctions));
|
||||
sqlite3RegisterBuiltinFunctions();
|
||||
if( sqlite3GlobalConfig.isPCacheInit==0 ){
|
||||
rc = sqlite3PcacheInitialize();
|
||||
}
|
||||
@@ -958,7 +957,7 @@ void sqlite3CloseSavepoints(sqlite3 *db){
|
||||
** with SQLITE_ANY as the encoding.
|
||||
*/
|
||||
static void functionDestroy(sqlite3 *db, FuncDef *p){
|
||||
FuncDestructor *pDestructor = p->pDestructor;
|
||||
FuncDestructor *pDestructor = p->u.pDestructor;
|
||||
if( pDestructor ){
|
||||
pDestructor->nRef--;
|
||||
if( pDestructor->nRef==0 ){
|
||||
@@ -1140,18 +1139,17 @@ void sqlite3LeaveMutexAndCloseZombie(sqlite3 *db){
|
||||
*/
|
||||
sqlite3ConnectionClosed(db);
|
||||
|
||||
for(j=0; j<ArraySize(db->aFunc.a); j++){
|
||||
FuncDef *pNext, *pHash, *p;
|
||||
for(p=db->aFunc.a[j]; p; p=pHash){
|
||||
pHash = p->pHash;
|
||||
while( p ){
|
||||
functionDestroy(db, p);
|
||||
pNext = p->pNext;
|
||||
sqlite3DbFree(db, p);
|
||||
p = pNext;
|
||||
}
|
||||
}
|
||||
for(i=sqliteHashFirst(&db->aFunc); i; i=sqliteHashNext(i)){
|
||||
FuncDef *pNext, *p;
|
||||
p = sqliteHashData(i);
|
||||
do{
|
||||
functionDestroy(db, p);
|
||||
pNext = p->pNext;
|
||||
sqlite3DbFree(db, p);
|
||||
p = pNext;
|
||||
}while( p );
|
||||
}
|
||||
sqlite3HashClear(&db->aFunc);
|
||||
for(i=sqliteHashFirst(&db->aCollSeq); i; i=sqliteHashNext(i)){
|
||||
CollSeq *pColl = (CollSeq *)sqliteHashData(i);
|
||||
/* Invoke any destructors registered for collation sequence user data. */
|
||||
@@ -1630,7 +1628,7 @@ int sqlite3CreateFunc(
|
||||
** is being overridden/deleted but there are no active VMs, allow the
|
||||
** operation to continue but invalidate all precompiled statements.
|
||||
*/
|
||||
p = sqlite3FindFunction(db, zFunctionName, nName, nArg, (u8)enc, 0);
|
||||
p = sqlite3FindFunction(db, zFunctionName, nArg, (u8)enc, 0);
|
||||
if( p && (p->funcFlags & SQLITE_FUNC_ENCMASK)==enc && p->nArg==nArg ){
|
||||
if( db->nVdbeActive ){
|
||||
sqlite3ErrorWithMsg(db, SQLITE_BUSY,
|
||||
@@ -1642,7 +1640,7 @@ int sqlite3CreateFunc(
|
||||
}
|
||||
}
|
||||
|
||||
p = sqlite3FindFunction(db, zFunctionName, nName, nArg, (u8)enc, 1);
|
||||
p = sqlite3FindFunction(db, zFunctionName, nArg, (u8)enc, 1);
|
||||
assert(p || db->mallocFailed);
|
||||
if( !p ){
|
||||
return SQLITE_NOMEM;
|
||||
@@ -1655,7 +1653,7 @@ int sqlite3CreateFunc(
|
||||
if( pDestructor ){
|
||||
pDestructor->nRef++;
|
||||
}
|
||||
p->pDestructor = pDestructor;
|
||||
p->u.pDestructor = pDestructor;
|
||||
p->funcFlags = (p->funcFlags & SQLITE_FUNC_ENCMASK) | extraFlags;
|
||||
testcase( p->funcFlags & SQLITE_DETERMINISTIC );
|
||||
p->xSFunc = xSFunc ? xSFunc : xStep;
|
||||
@@ -1770,7 +1768,6 @@ int sqlite3_overload_function(
|
||||
const char *zName,
|
||||
int nArg
|
||||
){
|
||||
int nName = sqlite3Strlen30(zName);
|
||||
int rc = SQLITE_OK;
|
||||
|
||||
#ifdef SQLITE_ENABLE_API_ARMOR
|
||||
@@ -1779,7 +1776,7 @@ int sqlite3_overload_function(
|
||||
}
|
||||
#endif
|
||||
sqlite3_mutex_enter(db->mutex);
|
||||
if( sqlite3FindFunction(db, zName, nName, nArg, SQLITE_UTF8, 0)==0 ){
|
||||
if( sqlite3FindFunction(db, zName, nArg, SQLITE_UTF8, 0)==0 ){
|
||||
rc = sqlite3CreateFunc(db, zName, nArg, SQLITE_UTF8,
|
||||
0, sqlite3InvalidFunction, 0, 0, 0);
|
||||
}
|
||||
@@ -2361,8 +2358,8 @@ static const int aHardLimit[] = {
|
||||
#if SQLITE_MAX_VDBE_OP<40
|
||||
# error SQLITE_MAX_VDBE_OP must be at least 40
|
||||
#endif
|
||||
#if SQLITE_MAX_FUNCTION_ARG<0 || SQLITE_MAX_FUNCTION_ARG>1000
|
||||
# error SQLITE_MAX_FUNCTION_ARG must be between 0 and 1000
|
||||
#if SQLITE_MAX_FUNCTION_ARG<0 || SQLITE_MAX_FUNCTION_ARG>127
|
||||
# error SQLITE_MAX_FUNCTION_ARG must be between 0 and 127
|
||||
#endif
|
||||
#if SQLITE_MAX_ATTACHED<0 || SQLITE_MAX_ATTACHED>125
|
||||
# error SQLITE_MAX_ATTACHED must be between 0 and 125
|
||||
@@ -2886,7 +2883,7 @@ static int openDatabase(
|
||||
** is accessed.
|
||||
*/
|
||||
sqlite3Error(db, SQLITE_OK);
|
||||
sqlite3RegisterBuiltinFunctions(db);
|
||||
sqlite3RegisterPerConnectionBuiltinFunctions(db);
|
||||
|
||||
/* Load automatic extensions - extensions that have been registered
|
||||
** using the sqlite3_automatic_extension() API.
|
||||
|
Reference in New Issue
Block a user