Team Ai
Modelpublic

AryaWu/sqlite

sourceHugging Faceupdated 10mo agoView on Hugging Face
0likes
main.c5175 linesDownload Raw Back to src
1/*2** 2001 September 153**4** The author disclaims copyright to this source code.  In place of5** a legal notice, here is a blessing:6**7**    May you do good and not evil.8**    May you find forgiveness for yourself and forgive others.9**    May you share freely, never taking more than you give.10**11*************************************************************************12** Main file for the SQLite library.  The routines in this file13** implement the programmer interface to the library.  Routines in14** other files are for internal use by SQLite and should not be15** accessed by users of the library.16*/17#include "sqliteInt.h"18 19#ifdef SQLITE_ENABLE_FTS320# include "fts3.h"21#endif22#ifdef SQLITE_ENABLE_RTREE23# include "rtree.h"24#endif25#if defined(SQLITE_ENABLE_ICU) || defined(SQLITE_ENABLE_ICU_COLLATIONS)26# include "sqliteicu.h"27#endif28 29/*30** This is an extension initializer that is a no-op and always31** succeeds, except that it fails if the fault-simulation is set32** to 500.33*/34static int sqlite3TestExtInit(sqlite3 *db){35  (void)db;36  return sqlite3FaultSim(500);37}38 39 40/*41** Forward declarations of external module initializer functions42** for modules that need them.43*/44#ifdef SQLITE_ENABLE_FTS545int sqlite3Fts5Init(sqlite3*);46#endif47#ifdef SQLITE_ENABLE_STMTVTAB48int sqlite3StmtVtabInit(sqlite3*);49#endif50#ifdef SQLITE_EXTRA_AUTOEXT51int SQLITE_EXTRA_AUTOEXT(sqlite3*);52#endif53/*54** An array of pointers to extension initializer functions for55** built-in extensions.56*/57static int (*const sqlite3BuiltinExtensions[])(sqlite3*) = {58#ifdef SQLITE_ENABLE_FTS359  sqlite3Fts3Init,60#endif61#ifdef SQLITE_ENABLE_FTS562  sqlite3Fts5Init,63#endif64#if defined(SQLITE_ENABLE_ICU) || defined(SQLITE_ENABLE_ICU_COLLATIONS)65  sqlite3IcuInit,66#endif67#ifdef SQLITE_ENABLE_RTREE68  sqlite3RtreeInit,69#endif70#ifdef SQLITE_ENABLE_DBPAGE_VTAB71  sqlite3DbpageRegister,72#endif73#ifdef SQLITE_ENABLE_DBSTAT_VTAB74  sqlite3DbstatRegister,75#endif76  sqlite3TestExtInit,77#ifdef SQLITE_ENABLE_STMTVTAB78  sqlite3StmtVtabInit,79#endif80#ifdef SQLITE_ENABLE_BYTECODE_VTAB81  sqlite3VdbeBytecodeVtabInit,82#endif83#ifdef SQLITE_EXTRA_AUTOEXT84  SQLITE_EXTRA_AUTOEXT,85#endif86};87 88#ifndef SQLITE_AMALGAMATION89/* IMPLEMENTATION-OF: R-46656-45156 The sqlite3_version[] string constant90** contains the text of SQLITE_VERSION macro.91*/92const char sqlite3_version[] = SQLITE_VERSION;93#endif94 95/* IMPLEMENTATION-OF: R-53536-42575 The sqlite3_libversion() function returns96** a pointer to the to the sqlite3_version[] string constant.97*/98const char *sqlite3_libversion(void){ return sqlite3_version; }99 100/* IMPLEMENTATION-OF: R-25063-23286 The sqlite3_sourceid() function returns a101** pointer to a string constant whose value is the same as the102** SQLITE_SOURCE_ID C preprocessor macro. Except if SQLite is built using103** an edited copy of the amalgamation, then the last four characters of104** the hash might be different from SQLITE_SOURCE_ID.105*/106const char *sqlite3_sourceid(void){ return SQLITE_SOURCE_ID; }107 108/* IMPLEMENTATION-OF: R-35210-63508 The sqlite3_libversion_number() function109** returns an integer equal to SQLITE_VERSION_NUMBER.110*/111int sqlite3_libversion_number(void){ return SQLITE_VERSION_NUMBER; }112 113/* IMPLEMENTATION-OF: R-20790-14025 The sqlite3_threadsafe() function returns114** zero if and only if SQLite was compiled with mutexing code omitted due to115** the SQLITE_THREADSAFE compile-time option being set to 0.116*/117int sqlite3_threadsafe(void){ return SQLITE_THREADSAFE; }118 119/*120** When compiling the test fixture or with debugging enabled (on Win32),121** this variable being set to non-zero will cause OSTRACE macros to emit122** extra diagnostic information.123*/124#ifdef SQLITE_HAVE_OS_TRACE125# ifndef SQLITE_DEBUG_OS_TRACE126#   define SQLITE_DEBUG_OS_TRACE 0127# endif128  int sqlite3OSTrace = SQLITE_DEBUG_OS_TRACE;129#endif130 131#if !defined(SQLITE_OMIT_TRACE) && defined(SQLITE_ENABLE_IOTRACE)132/*133** If the following function pointer is not NULL and if134** SQLITE_ENABLE_IOTRACE is enabled, then messages describing135** I/O active are written using this function.  These messages136** are intended for debugging activity only.137*/138SQLITE_API void (SQLITE_CDECL *sqlite3IoTrace)(const char*, ...) = 0;139#endif140 141/*142** If the following global variable points to a string which is the143** name of a directory, then that directory will be used to store144** temporary files.145**146** See also the "PRAGMA temp_store_directory" SQL command.147*/148char *sqlite3_temp_directory = 0;149 150/*151** If the following global variable points to a string which is the152** name of a directory, then that directory will be used to store153** all database files specified with a relative pathname.154**155** See also the "PRAGMA data_store_directory" SQL command.156*/157char *sqlite3_data_directory = 0;158 159/*160** Initialize SQLite. 161**162** This routine must be called to initialize the memory allocation,163** VFS, and mutex subsystems prior to doing any serious work with164** SQLite.  But as long as you do not compile with SQLITE_OMIT_AUTOINIT165** this routine will be called automatically by key routines such as166** sqlite3_open(). 167**168** This routine is a no-op except on its very first call for the process,169** or for the first call after a call to sqlite3_shutdown.170**171** The first thread to call this routine runs the initialization to172** completion.  If subsequent threads call this routine before the first173** thread has finished the initialization process, then the subsequent174** threads must block until the first thread finishes with the initialization.175**176** The first thread might call this routine recursively.  Recursive177** calls to this routine should not block, of course.  Otherwise the178** initialization process would never complete.179**180** Let X be the first thread to enter this routine.  Let Y be some other181** thread.  Then while the initial invocation of this routine by X is182** incomplete, it is required that:183**184**    *  Calls to this routine from Y must block until the outer-most185**       call by X completes.186**187**    *  Recursive calls to this routine from thread X return immediately188**       without blocking.189*/190int sqlite3_initialize(void){191  MUTEX_LOGIC( sqlite3_mutex *pMainMtx; )      /* The main static mutex */192  int rc;                                      /* Result code */193#ifdef SQLITE_EXTRA_INIT194  int bRunExtraInit = 0;                       /* Extra initialization needed */195#endif196 197#ifdef SQLITE_OMIT_WSD198  rc = sqlite3_wsd_init(4096, 24);199  if( rc!=SQLITE_OK ){200    return rc;201  }202#endif203 204  /* If the following assert() fails on some obscure processor/compiler205  ** combination, the work-around is to set the correct pointer206  ** size at compile-time using -DSQLITE_PTRSIZE=n compile-time option */207  assert( SQLITE_PTRSIZE==sizeof(char*) );208 209  /* If SQLite is already completely initialized, then this call210  ** to sqlite3_initialize() should be a no-op.  But the initialization211  ** must be complete.  So isInit must not be set until the very end212  ** of this routine.213  */214  if( sqlite3GlobalConfig.isInit ){215    sqlite3MemoryBarrier();216    return SQLITE_OK;217  }218 219  /* Make sure the mutex subsystem is initialized.  If unable to220  ** initialize the mutex subsystem, return early with the error.221  ** If the system is so sick that we are unable to allocate a mutex,222  ** there is not much SQLite is going to be able to do.223  **224  ** The mutex subsystem must take care of serializing its own225  ** initialization.226  */227  rc = sqlite3MutexInit();228  if( rc ) return rc;229 230  /* Initialize the malloc() system and the recursive pInitMutex mutex.231  ** This operation is protected by the STATIC_MAIN mutex.  Note that232  ** MutexAlloc() is called for a static mutex prior to initializing the233  ** malloc subsystem - this implies that the allocation of a static234  ** mutex must not require support from the malloc subsystem.235  */236  MUTEX_LOGIC( pMainMtx = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MAIN); )237  sqlite3_mutex_enter(pMainMtx);238  sqlite3GlobalConfig.isMutexInit = 1;239  if( !sqlite3GlobalConfig.isMallocInit ){240    rc = sqlite3MallocInit();241  }242  if( rc==SQLITE_OK ){243    sqlite3GlobalConfig.isMallocInit = 1;244    if( !sqlite3GlobalConfig.pInitMutex ){245      sqlite3GlobalConfig.pInitMutex =246           sqlite3MutexAlloc(SQLITE_MUTEX_RECURSIVE);247      if( sqlite3GlobalConfig.bCoreMutex && !sqlite3GlobalConfig.pInitMutex ){248        rc = SQLITE_NOMEM_BKPT;249      }250    }251  }252  if( rc==SQLITE_OK ){253    sqlite3GlobalConfig.nRefInitMutex++;254  }255  sqlite3_mutex_leave(pMainMtx);256 257  /* If rc is not SQLITE_OK at this point, then either the malloc258  ** subsystem could not be initialized or the system failed to allocate259  ** the pInitMutex mutex. Return an error in either case.  */260  if( rc!=SQLITE_OK ){261    return rc;262  }263 264  /* Do the rest of the initialization under the recursive mutex so265  ** that we will be able to handle recursive calls into266  ** sqlite3_initialize().  The recursive calls normally come through267  ** sqlite3_os_init() when it invokes sqlite3_vfs_register(), but other268  ** recursive calls might also be possible.269  **270  ** IMPLEMENTATION-OF: R-00140-37445 SQLite automatically serializes calls271  ** to the xInit method, so the xInit method need not be threadsafe.272  **273  ** The following mutex is what serializes access to the appdef pcache xInit274  ** methods.  The sqlite3_pcache_methods.xInit() all is embedded in the275  ** call to sqlite3PcacheInitialize().276  */277  sqlite3_mutex_enter(sqlite3GlobalConfig.pInitMutex);278  if( sqlite3GlobalConfig.isInit==0 && sqlite3GlobalConfig.inProgress==0 ){279    sqlite3GlobalConfig.inProgress = 1;280#ifdef SQLITE_ENABLE_SQLLOG281    {282      extern void sqlite3_init_sqllog(void);283      sqlite3_init_sqllog();284    }285#endif286    memset(&sqlite3BuiltinFunctions, 0, sizeof(sqlite3BuiltinFunctions));287    sqlite3RegisterBuiltinFunctions();288    if( sqlite3GlobalConfig.isPCacheInit==0 ){289      rc = sqlite3PcacheInitialize();290    }291    if( rc==SQLITE_OK ){292      sqlite3GlobalConfig.isPCacheInit = 1;293      rc = sqlite3OsInit();294    }295#ifndef SQLITE_OMIT_DESERIALIZE296    if( rc==SQLITE_OK ){297      rc = sqlite3MemdbInit();298    }299#endif300    if( rc==SQLITE_OK ){301      sqlite3PCacheBufferSetup( sqlite3GlobalConfig.pPage,302          sqlite3GlobalConfig.szPage, sqlite3GlobalConfig.nPage);303#ifdef SQLITE_EXTRA_INIT_MUTEXED304      {305        int SQLITE_EXTRA_INIT_MUTEXED(const char*);306        rc = SQLITE_EXTRA_INIT_MUTEXED(0);307      }308#endif309    }310    if( rc==SQLITE_OK ){311      sqlite3MemoryBarrier();312      sqlite3GlobalConfig.isInit = 1;313#ifdef SQLITE_EXTRA_INIT314      bRunExtraInit = 1;315#endif316    }317    sqlite3GlobalConfig.inProgress = 0;318  }319  sqlite3_mutex_leave(sqlite3GlobalConfig.pInitMutex);320 321  /* Go back under the static mutex and clean up the recursive322  ** mutex to prevent a resource leak.323  */324  sqlite3_mutex_enter(pMainMtx);325  sqlite3GlobalConfig.nRefInitMutex--;326  if( sqlite3GlobalConfig.nRefInitMutex<=0 ){327    assert( sqlite3GlobalConfig.nRefInitMutex==0 );328    sqlite3_mutex_free(sqlite3GlobalConfig.pInitMutex);329    sqlite3GlobalConfig.pInitMutex = 0;330  }331  sqlite3_mutex_leave(pMainMtx);332 333  /* The following is just a sanity check to make sure SQLite has334  ** been compiled correctly.  It is important to run this code, but335  ** we don't want to run it too often and soak up CPU cycles for no336  ** reason.  So we run it once during initialization.337  */338#ifndef NDEBUG339#ifndef SQLITE_OMIT_FLOATING_POINT340  /* This section of code's only "output" is via assert() statements. */341  if( rc==SQLITE_OK ){342    u64 x = (((u64)1)<<63)-1;343    double y;344    assert(sizeof(x)==8);345    assert(sizeof(x)==sizeof(y));346    memcpy(&y, &x, 8);347    assert( sqlite3IsNaN(y) );348  }349#endif350#endif351 352  /* Do extra initialization steps requested by the SQLITE_EXTRA_INIT353  ** compile-time option.354  */355#ifdef SQLITE_EXTRA_INIT356  if( bRunExtraInit ){357    int SQLITE_EXTRA_INIT(const char*);358    rc = SQLITE_EXTRA_INIT(0);359  }360#endif361  return rc;362}363 364/*365** Undo the effects of sqlite3_initialize().  Must not be called while366** there are outstanding database connections or memory allocations or367** while any part of SQLite is otherwise in use in any thread.  This368** routine is not threadsafe.  But it is safe to invoke this routine369** on when SQLite is already shut down.  If SQLite is already shut down370** when this routine is invoked, then this routine is a harmless no-op.371*/372int sqlite3_shutdown(void){373#ifdef SQLITE_OMIT_WSD374  int rc = sqlite3_wsd_init(4096, 24);375  if( rc!=SQLITE_OK ){376    return rc;377  }378#endif379 380  if( sqlite3GlobalConfig.isInit ){381#ifdef SQLITE_EXTRA_SHUTDOWN382    void SQLITE_EXTRA_SHUTDOWN(void);383    SQLITE_EXTRA_SHUTDOWN();384#endif385    sqlite3_os_end();386    sqlite3_reset_auto_extension();387    sqlite3GlobalConfig.isInit = 0;388  }389  if( sqlite3GlobalConfig.isPCacheInit ){390    sqlite3PcacheShutdown();391    sqlite3GlobalConfig.isPCacheInit = 0;392  }393  if( sqlite3GlobalConfig.isMallocInit ){394    sqlite3MallocEnd();395    sqlite3GlobalConfig.isMallocInit = 0;396 397#ifndef SQLITE_OMIT_SHUTDOWN_DIRECTORIES398    /* The heap subsystem has now been shutdown and these values are supposed399    ** to be NULL or point to memory that was obtained from sqlite3_malloc(),400    ** which would rely on that heap subsystem; therefore, make sure these401    ** values cannot refer to heap memory that was just invalidated when the402    ** heap subsystem was shutdown.  This is only done if the current call to403    ** this function resulted in the heap subsystem actually being shutdown.404    */405    sqlite3_data_directory = 0;406    sqlite3_temp_directory = 0;407#endif408  }409  if( sqlite3GlobalConfig.isMutexInit ){410    sqlite3MutexEnd();411    sqlite3GlobalConfig.isMutexInit = 0;412  }413 414  return SQLITE_OK;415}416 417/*418** This API allows applications to modify the global configuration of419** the SQLite library at run-time.420**421** This routine should only be called when there are no outstanding422** database connections or memory allocations.  This routine is not423** threadsafe.  Failure to heed these warnings can lead to unpredictable424** behavior.425*/426int sqlite3_config(int op, ...){427  va_list ap;428  int rc = SQLITE_OK;429 430  /* sqlite3_config() normally returns SQLITE_MISUSE if it is invoked while431  ** the SQLite library is in use.  Except, a few selected opcodes432  ** are allowed.433  */434  if( sqlite3GlobalConfig.isInit ){435    static const u64 mAnytimeConfigOption = 0436       | MASKBIT64( SQLITE_CONFIG_LOG )437       | MASKBIT64( SQLITE_CONFIG_PCACHE_HDRSZ )438    ;439    if( op<0 || op>63 || (MASKBIT64(op) & mAnytimeConfigOption)==0 ){440      return SQLITE_MISUSE_BKPT;441    }442    testcase( op==SQLITE_CONFIG_LOG );443    testcase( op==SQLITE_CONFIG_PCACHE_HDRSZ );444  }445 446  va_start(ap, op);447  switch( op ){448 449    /* Mutex configuration options are only available in a threadsafe450    ** compile.451    */452#if defined(SQLITE_THREADSAFE) && SQLITE_THREADSAFE>0  /* IMP: R-54466-46756 */453    case SQLITE_CONFIG_SINGLETHREAD: {454      /* EVIDENCE-OF: R-02748-19096 This option sets the threading mode to455      ** Single-thread. */456      sqlite3GlobalConfig.bCoreMutex = 0;  /* Disable mutex on core */457      sqlite3GlobalConfig.bFullMutex = 0;  /* Disable mutex on connections */458      break;459    }460#endif461#if defined(SQLITE_THREADSAFE) && SQLITE_THREADSAFE>0 /* IMP: R-20520-54086 */462    case SQLITE_CONFIG_MULTITHREAD: {463      /* EVIDENCE-OF: R-14374-42468 This option sets the threading mode to464      ** Multi-thread. */465      sqlite3GlobalConfig.bCoreMutex = 1;  /* Enable mutex on core */466      sqlite3GlobalConfig.bFullMutex = 0;  /* Disable mutex on connections */467      break;468    }469#endif470#if defined(SQLITE_THREADSAFE) && SQLITE_THREADSAFE>0 /* IMP: R-59593-21810 */471    case SQLITE_CONFIG_SERIALIZED: {472      /* EVIDENCE-OF: R-41220-51800 This option sets the threading mode to473      ** Serialized. */474      sqlite3GlobalConfig.bCoreMutex = 1;  /* Enable mutex on core */475      sqlite3GlobalConfig.bFullMutex = 1;  /* Enable mutex on connections */476      break;477    }478#endif479#if defined(SQLITE_THREADSAFE) && SQLITE_THREADSAFE>0 /* IMP: R-63666-48755 */480    case SQLITE_CONFIG_MUTEX: {481      /* Specify an alternative mutex implementation */482      sqlite3GlobalConfig.mutex = *va_arg(ap, sqlite3_mutex_methods*);483      break;484    }485#endif486#if defined(SQLITE_THREADSAFE) && SQLITE_THREADSAFE>0 /* IMP: R-14450-37597 */487    case SQLITE_CONFIG_GETMUTEX: {488      /* Retrieve the current mutex implementation */489      *va_arg(ap, sqlite3_mutex_methods*) = sqlite3GlobalConfig.mutex;490      break;491    }492#endif493 494    case SQLITE_CONFIG_MALLOC: {495      /* EVIDENCE-OF: R-55594-21030 The SQLITE_CONFIG_MALLOC option takes a496      ** single argument which is a pointer to an instance of the497      ** sqlite3_mem_methods structure. The argument specifies alternative498      ** low-level memory allocation routines to be used in place of the memory499      ** allocation routines built into SQLite. */500      sqlite3GlobalConfig.m = *va_arg(ap, sqlite3_mem_methods*);501      break;502    }503    case SQLITE_CONFIG_GETMALLOC: {504      /* EVIDENCE-OF: R-51213-46414 The SQLITE_CONFIG_GETMALLOC option takes a505      ** single argument which is a pointer to an instance of the506      ** sqlite3_mem_methods structure. The sqlite3_mem_methods structure is507      ** filled with the currently defined memory allocation routines. */508      if( sqlite3GlobalConfig.m.xMalloc==0 ) sqlite3MemSetDefault();509      *va_arg(ap, sqlite3_mem_methods*) = sqlite3GlobalConfig.m;510      break;511    }512    case SQLITE_CONFIG_MEMSTATUS: {513      assert( !sqlite3GlobalConfig.isInit );  /* Cannot change at runtime */514      /* EVIDENCE-OF: R-61275-35157 The SQLITE_CONFIG_MEMSTATUS option takes515      ** single argument of type int, interpreted as a boolean, which enables516      ** or disables the collection of memory allocation statistics. */517      sqlite3GlobalConfig.bMemstat = va_arg(ap, int);518      break;519    }520    case SQLITE_CONFIG_SMALL_MALLOC: {521      sqlite3GlobalConfig.bSmallMalloc = va_arg(ap, int);522      break;523    }524    case SQLITE_CONFIG_PAGECACHE: {525      /* EVIDENCE-OF: R-18761-36601 There are three arguments to526      ** SQLITE_CONFIG_PAGECACHE: A pointer to 8-byte aligned memory (pMem),527      ** the size of each page cache line (sz), and the number of cache lines528      ** (N). */529      sqlite3GlobalConfig.pPage = va_arg(ap, void*);530      sqlite3GlobalConfig.szPage = va_arg(ap, int);531      sqlite3GlobalConfig.nPage = va_arg(ap, int);532      break;533    }534    case SQLITE_CONFIG_PCACHE_HDRSZ: {535      /* EVIDENCE-OF: R-39100-27317 The SQLITE_CONFIG_PCACHE_HDRSZ option takes536      ** a single parameter which is a pointer to an integer and writes into537      ** that integer the number of extra bytes per page required for each page538      ** in SQLITE_CONFIG_PAGECACHE. */539      *va_arg(ap, int*) =540          sqlite3HeaderSizeBtree() +541          sqlite3HeaderSizePcache() +542          sqlite3HeaderSizePcache1();543      break;544    }545 546    case SQLITE_CONFIG_PCACHE: {547      /* no-op */548      break;549    }550    case SQLITE_CONFIG_GETPCACHE: {551      /* now an error */552      rc = SQLITE_ERROR;553      break;554    }555 556    case SQLITE_CONFIG_PCACHE2: {557      /* EVIDENCE-OF: R-63325-48378 The SQLITE_CONFIG_PCACHE2 option takes a558      ** single argument which is a pointer to an sqlite3_pcache_methods2559      ** object. This object specifies the interface to a custom page cache560      ** implementation. */561      sqlite3GlobalConfig.pcache2 = *va_arg(ap, sqlite3_pcache_methods2*);562      break;563    }564    case SQLITE_CONFIG_GETPCACHE2: {565      /* EVIDENCE-OF: R-22035-46182 The SQLITE_CONFIG_GETPCACHE2 option takes a566      ** single argument which is a pointer to an sqlite3_pcache_methods2567      ** object. SQLite copies of the current page cache implementation into568      ** that object. */569      if( sqlite3GlobalConfig.pcache2.xInit==0 ){570        sqlite3PCacheSetDefault();571      }572      *va_arg(ap, sqlite3_pcache_methods2*) = sqlite3GlobalConfig.pcache2;573      break;574    }575 576/* EVIDENCE-OF: R-06626-12911 The SQLITE_CONFIG_HEAP option is only577** available if SQLite is compiled with either SQLITE_ENABLE_MEMSYS3 or578** SQLITE_ENABLE_MEMSYS5 and returns SQLITE_ERROR if invoked otherwise. */579#if defined(SQLITE_ENABLE_MEMSYS3) || defined(SQLITE_ENABLE_MEMSYS5)580    case SQLITE_CONFIG_HEAP: {581      /* EVIDENCE-OF: R-19854-42126 There are three arguments to582      ** SQLITE_CONFIG_HEAP: An 8-byte aligned pointer to the memory, the583      ** number of bytes in the memory buffer, and the minimum allocation size.584      */585      sqlite3GlobalConfig.pHeap = va_arg(ap, void*);586      sqlite3GlobalConfig.nHeap = va_arg(ap, int);587      sqlite3GlobalConfig.mnReq = va_arg(ap, int);588 589      if( sqlite3GlobalConfig.mnReq<1 ){590        sqlite3GlobalConfig.mnReq = 1;591      }else if( sqlite3GlobalConfig.mnReq>(1<<12) ){592        /* cap min request size at 2^12 */593        sqlite3GlobalConfig.mnReq = (1<<12);594      }595 596      if( sqlite3GlobalConfig.pHeap==0 ){597        /* EVIDENCE-OF: R-49920-60189 If the first pointer (the memory pointer)598        ** is NULL, then SQLite reverts to using its default memory allocator599        ** (the system malloc() implementation), undoing any prior invocation of600        ** SQLITE_CONFIG_MALLOC.601        **602        ** Setting sqlite3GlobalConfig.m to all zeros will cause malloc to603        ** revert to its default implementation when sqlite3_initialize() is run604        */605        memset(&sqlite3GlobalConfig.m, 0, sizeof(sqlite3GlobalConfig.m));606      }else{607        /* EVIDENCE-OF: R-61006-08918 If the memory pointer is not NULL then the608        ** alternative memory allocator is engaged to handle all of SQLites609        ** memory allocation needs. */610#ifdef SQLITE_ENABLE_MEMSYS3611        sqlite3GlobalConfig.m = *sqlite3MemGetMemsys3();612#endif613#ifdef SQLITE_ENABLE_MEMSYS5614        sqlite3GlobalConfig.m = *sqlite3MemGetMemsys5();615#endif616      }617      break;618    }619#endif620 621    case SQLITE_CONFIG_LOOKASIDE: {622      sqlite3GlobalConfig.szLookaside = va_arg(ap, int);623      sqlite3GlobalConfig.nLookaside = va_arg(ap, int);624      break;625    }626   627    /* Record a pointer to the logger function and its first argument.628    ** The default is NULL.  Logging is disabled if the function pointer is629    ** NULL.630    */631    case SQLITE_CONFIG_LOG: {632      /* MSVC is picky about pulling func ptrs from va lists.633      ** http://support.microsoft.com/kb/47961634      ** sqlite3GlobalConfig.xLog = va_arg(ap, void(*)(void*,int,const char*));635      */636      typedef void(*LOGFUNC_t)(void*,int,const char*);637      LOGFUNC_t xLog = va_arg(ap, LOGFUNC_t);638      void *pLogArg = va_arg(ap, void*);639      AtomicStore(&sqlite3GlobalConfig.xLog, xLog);640      AtomicStore(&sqlite3GlobalConfig.pLogArg, pLogArg);641      break;642    }643 644    /* EVIDENCE-OF: R-55548-33817 The compile-time setting for URI filenames645    ** can be changed at start-time using the646    ** sqlite3_config(SQLITE_CONFIG_URI,1) or647    ** sqlite3_config(SQLITE_CONFIG_URI,0) configuration calls.648    */649    case SQLITE_CONFIG_URI: {650      /* EVIDENCE-OF: R-25451-61125 The SQLITE_CONFIG_URI option takes a single651      ** argument of type int. If non-zero, then URI handling is globally652      ** enabled. If the parameter is zero, then URI handling is globally653      ** disabled. */654      int bOpenUri = va_arg(ap, int);655      AtomicStore(&sqlite3GlobalConfig.bOpenUri, bOpenUri);656      break;657    }658 659    case SQLITE_CONFIG_COVERING_INDEX_SCAN: {660      /* EVIDENCE-OF: R-36592-02772 The SQLITE_CONFIG_COVERING_INDEX_SCAN661      ** option takes a single integer argument which is interpreted as a662      ** boolean in order to enable or disable the use of covering indices for663      ** full table scans in the query optimizer. */664      sqlite3GlobalConfig.bUseCis = va_arg(ap, int);665      break;666    }667 668#ifdef SQLITE_ENABLE_SQLLOG669    case SQLITE_CONFIG_SQLLOG: {670      typedef void(*SQLLOGFUNC_t)(void*, sqlite3*, const char*, int);671      sqlite3GlobalConfig.xSqllog = va_arg(ap, SQLLOGFUNC_t);672      sqlite3GlobalConfig.pSqllogArg = va_arg(ap, void *);673      break;674    }675#endif676 677    case SQLITE_CONFIG_MMAP_SIZE: {678      /* EVIDENCE-OF: R-58063-38258 SQLITE_CONFIG_MMAP_SIZE takes two 64-bit679      ** integer (sqlite3_int64) values that are the default mmap size limit680      ** (the default setting for PRAGMA mmap_size) and the maximum allowed681      ** mmap size limit. */682      sqlite3_int64 szMmap = va_arg(ap, sqlite3_int64);683      sqlite3_int64 mxMmap = va_arg(ap, sqlite3_int64);684      /* EVIDENCE-OF: R-53367-43190 If either argument to this option is685      ** negative, then that argument is changed to its compile-time default.686      **687      ** EVIDENCE-OF: R-34993-45031 The maximum allowed mmap size will be688      ** silently truncated if necessary so that it does not exceed the689      ** compile-time maximum mmap size set by the SQLITE_MAX_MMAP_SIZE690      ** compile-time option.691      */692      if( mxMmap<0 || mxMmap>SQLITE_MAX_MMAP_SIZE ){693        mxMmap = SQLITE_MAX_MMAP_SIZE;694      }695      if( szMmap<0 ) szMmap = SQLITE_DEFAULT_MMAP_SIZE;696      if( szMmap>mxMmap) szMmap = mxMmap;697      sqlite3GlobalConfig.mxMmap = mxMmap;698      sqlite3GlobalConfig.szMmap = szMmap;699      break;700    }701 702#if SQLITE_OS_WIN && defined(SQLITE_WIN32_MALLOC) /* IMP: R-04780-55815 */703    case SQLITE_CONFIG_WIN32_HEAPSIZE: {704      /* EVIDENCE-OF: R-34926-03360 SQLITE_CONFIG_WIN32_HEAPSIZE takes a 32-bit705      ** unsigned integer value that specifies the maximum size of the created706      ** heap. */707      sqlite3GlobalConfig.nHeap = va_arg(ap, int);708      break;709    }710#endif711 712    case SQLITE_CONFIG_PMASZ: {713      sqlite3GlobalConfig.szPma = va_arg(ap, unsigned int);714      break;715    }716 717    case SQLITE_CONFIG_STMTJRNL_SPILL: {718      sqlite3GlobalConfig.nStmtSpill = va_arg(ap, int);719      break;720    }721 722#ifdef SQLITE_ENABLE_SORTER_REFERENCES723    case SQLITE_CONFIG_SORTERREF_SIZE: {724      int iVal = va_arg(ap, int);725      if( iVal<0 ){726        iVal = SQLITE_DEFAULT_SORTERREF_SIZE;727      }728      sqlite3GlobalConfig.szSorterRef = (u32)iVal;729      break;730    }731#endif /* SQLITE_ENABLE_SORTER_REFERENCES */732 733#ifndef SQLITE_OMIT_DESERIALIZE734    case SQLITE_CONFIG_MEMDB_MAXSIZE: {735      sqlite3GlobalConfig.mxMemdbSize = va_arg(ap, sqlite3_int64);736      break;737    }738#endif /* SQLITE_OMIT_DESERIALIZE */739 740    case SQLITE_CONFIG_ROWID_IN_VIEW: {741      int *pVal = va_arg(ap,int*);742#ifdef SQLITE_ALLOW_ROWID_IN_VIEW743      if( 0==*pVal ) sqlite3GlobalConfig.mNoVisibleRowid = TF_NoVisibleRowid;744      if( 1==*pVal ) sqlite3GlobalConfig.mNoVisibleRowid = 0;745      *pVal = (sqlite3GlobalConfig.mNoVisibleRowid==0);746#else747      *pVal = 0;748#endif749      break;750    }751 752    default: {753      rc = SQLITE_ERROR;754      break;755    }756  }757  va_end(ap);758  return rc;759}760 761/*762** Set up the lookaside buffers for a database connection.763** Return SQLITE_OK on success. 764** If lookaside is already active, return SQLITE_BUSY.765**766** The sz parameter is the number of bytes in each lookaside slot.767** The cnt parameter is the number of slots.  If pBuf is NULL the768** space for the lookaside memory is obtained from sqlite3_malloc()769** or similar.  If pBuf is not NULL then it is sz*cnt bytes of memory770** to use for the lookaside memory.771*/772static int setupLookaside(773  sqlite3 *db,    /* Database connection being configured */774  void *pBuf,     /* Memory to use for lookaside.  May be NULL */775  int sz,         /* Desired size of each lookaside memory slot */776  int cnt         /* Number of slots to allocate */777){778#ifndef SQLITE_OMIT_LOOKASIDE779  void *pStart;          /* Start of the lookaside buffer */780  sqlite3_int64 szAlloc; /* Total space set aside for lookaside memory */781  int nBig;              /* Number of full-size slots */782  int nSm;               /* Number smaller LOOKASIDE_SMALL-byte slots */783 784  if( sqlite3LookasideUsed(db,0)>0 ){785    return SQLITE_BUSY;786  }787  /* Free any existing lookaside buffer for this handle before788  ** allocating a new one so we don't have to have space for789  ** both at the same time.790  */791  if( db->lookaside.bMalloced ){792    sqlite3_free(db->lookaside.pStart);793  }794  /* The size of a lookaside slot after ROUNDDOWN8 needs to be larger795  ** than a pointer and small enough to fit in a u16.796  */797  sz = ROUNDDOWN8(sz);798  if( sz<=(int)sizeof(LookasideSlot*) ) sz = 0;799  if( sz>65528 ) sz = 65528;800  /* Count must be at least 1 to be useful, but not so large as to use801  ** more than 0x7fff0000 total bytes for lookaside. */802  if( cnt<1 ) cnt = 0;803  if( sz>0 && cnt>(0x7fff0000/sz) ) cnt = 0x7fff0000/sz;804  szAlloc = (i64)sz*(i64)cnt;805  if( szAlloc==0 ){806    sz = 0;807    pStart = 0;808  }else if( pBuf==0 ){809    sqlite3BeginBenignMalloc();810    pStart = sqlite3Malloc( szAlloc );811    sqlite3EndBenignMalloc();812    if( pStart ) szAlloc = sqlite3MallocSize(pStart);813  }else{814    pStart = pBuf;815  }816#ifndef SQLITE_OMIT_TWOSIZE_LOOKASIDE817  if( sz>=LOOKASIDE_SMALL*3 ){818    nBig = szAlloc/(3*LOOKASIDE_SMALL+sz);819    nSm = (szAlloc - (i64)sz*(i64)nBig)/LOOKASIDE_SMALL;820  }else if( sz>=LOOKASIDE_SMALL*2 ){821    nBig = szAlloc/(LOOKASIDE_SMALL+sz);822    nSm = (szAlloc - (i64)sz*(i64)nBig)/LOOKASIDE_SMALL;823  }else824#endif /* SQLITE_OMIT_TWOSIZE_LOOKASIDE */825  if( sz>0 ){826    nBig = szAlloc/sz;827    nSm = 0;828  }else{829    nBig = nSm = 0;830  }831  db->lookaside.pStart = pStart;832  db->lookaside.pInit = 0;833  db->lookaside.pFree = 0;834  db->lookaside.sz = (u16)sz;835  db->lookaside.szTrue = (u16)sz;836  if( pStart ){837    int i;838    LookasideSlot *p;839    assert( sz > (int)sizeof(LookasideSlot*) );840    p = (LookasideSlot*)pStart;841    for(i=0; i<nBig; i++){842      p->pNext = db->lookaside.pInit;843      db->lookaside.pInit = p;844      p = (LookasideSlot*)&((u8*)p)[sz];845    }846#ifndef SQLITE_OMIT_TWOSIZE_LOOKASIDE847    db->lookaside.pSmallInit = 0;848    db->lookaside.pSmallFree = 0;849    db->lookaside.pMiddle = p;850    for(i=0; i<nSm; i++){851      p->pNext = db->lookaside.pSmallInit;852      db->lookaside.pSmallInit = p;853      p = (LookasideSlot*)&((u8*)p)[LOOKASIDE_SMALL];854    }855#endif /* SQLITE_OMIT_TWOSIZE_LOOKASIDE */856    assert( ((uptr)p)<=szAlloc + (uptr)pStart );857    db->lookaside.pEnd = p;858    db->lookaside.bDisable = 0;859    db->lookaside.bMalloced = pBuf==0 ?1:0;860    db->lookaside.nSlot = nBig+nSm;861  }else{862    db->lookaside.pStart = 0;863#ifndef SQLITE_OMIT_TWOSIZE_LOOKASIDE864    db->lookaside.pSmallInit = 0;865    db->lookaside.pSmallFree = 0;866    db->lookaside.pMiddle = 0;867#endif /* SQLITE_OMIT_TWOSIZE_LOOKASIDE */868    db->lookaside.pEnd = 0;869    db->lookaside.bDisable = 1;870    db->lookaside.sz = 0;871    db->lookaside.bMalloced = 0;872    db->lookaside.nSlot = 0;873  }874  db->lookaside.pTrueEnd = db->lookaside.pEnd;875  assert( sqlite3LookasideUsed(db,0)==0 );876#endif /* SQLITE_OMIT_LOOKASIDE */877  return SQLITE_OK;878}879 880/*881** Return the mutex associated with a database connection.882*/883sqlite3_mutex *sqlite3_db_mutex(sqlite3 *db){884#ifdef SQLITE_ENABLE_API_ARMOR885  if( !sqlite3SafetyCheckOk(db) ){886    (void)SQLITE_MISUSE_BKPT;887    return 0;888  }889#endif890  return db->mutex;891}892 893/*894** Free up as much memory as we can from the given database895** connection.896*/897int sqlite3_db_release_memory(sqlite3 *db){898  int i;899 900#ifdef SQLITE_ENABLE_API_ARMOR901  if( !sqlite3SafetyCheckOk(db) ) return SQLITE_MISUSE_BKPT;902#endif903  sqlite3_mutex_enter(db->mutex);904  sqlite3BtreeEnterAll(db);905  for(i=0; i<db->nDb; i++){906    Btree *pBt = db->aDb[i].pBt;907    if( pBt ){908      Pager *pPager = sqlite3BtreePager(pBt);909      sqlite3PagerShrink(pPager);910    }911  }912  sqlite3BtreeLeaveAll(db);913  sqlite3_mutex_leave(db->mutex);914  return SQLITE_OK;915}916 917/*918** Flush any dirty pages in the pager-cache for any attached database919** to disk.920*/921int sqlite3_db_cacheflush(sqlite3 *db){922  int i;923  int rc = SQLITE_OK;924  int bSeenBusy = 0;925 926#ifdef SQLITE_ENABLE_API_ARMOR927  if( !sqlite3SafetyCheckOk(db) ) return SQLITE_MISUSE_BKPT;928#endif929  sqlite3_mutex_enter(db->mutex);930  sqlite3BtreeEnterAll(db);931  for(i=0; rc==SQLITE_OK && i<db->nDb; i++){932    Btree *pBt = db->aDb[i].pBt;933    if( pBt && sqlite3BtreeTxnState(pBt)==SQLITE_TXN_WRITE ){934      Pager *pPager = sqlite3BtreePager(pBt);935      rc = sqlite3PagerFlush(pPager);936      if( rc==SQLITE_BUSY ){937        bSeenBusy = 1;938        rc = SQLITE_OK;939      }940    }941  }942  sqlite3BtreeLeaveAll(db);943  sqlite3_mutex_leave(db->mutex);944  return ((rc==SQLITE_OK && bSeenBusy) ? SQLITE_BUSY : rc);945}946 947/*948** Configuration settings for an individual database connection949*/950int sqlite3_db_config(sqlite3 *db, int op, ...){951  va_list ap;952  int rc;953 954#ifdef SQLITE_ENABLE_API_ARMOR955  if( !sqlite3SafetyCheckOk(db) ) return SQLITE_MISUSE_BKPT;956#endif957  sqlite3_mutex_enter(db->mutex);958  va_start(ap, op);959  switch( op ){960    case SQLITE_DBCONFIG_MAINDBNAME: {961      /* IMP: R-06824-28531 */962      /* IMP: R-36257-52125 */963      db->aDb[0].zDbSName = va_arg(ap,char*);964      rc = SQLITE_OK;965      break;966    }967    case SQLITE_DBCONFIG_LOOKASIDE: {968      void *pBuf = va_arg(ap, void*); /* IMP: R-26835-10964 */969      int sz = va_arg(ap, int);       /* IMP: R-47871-25994 */970      int cnt = va_arg(ap, int);      /* IMP: R-04460-53386 */971      rc = setupLookaside(db, pBuf, sz, cnt);972      break;973    }974    default: {975      static const struct {976        int op;      /* The opcode */977        u64 mask;    /* Mask of the bit in sqlite3.flags to set/clear */978      } aFlagOp[] = {979        { SQLITE_DBCONFIG_ENABLE_FKEY,           SQLITE_ForeignKeys    },980        { SQLITE_DBCONFIG_ENABLE_TRIGGER,        SQLITE_EnableTrigger  },981        { SQLITE_DBCONFIG_ENABLE_VIEW,           SQLITE_EnableView     },982        { SQLITE_DBCONFIG_ENABLE_FTS3_TOKENIZER, SQLITE_Fts3Tokenizer  },983        { SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION, SQLITE_LoadExtension  },984        { SQLITE_DBCONFIG_NO_CKPT_ON_CLOSE,      SQLITE_NoCkptOnClose  },985        { SQLITE_DBCONFIG_ENABLE_QPSG,           SQLITE_EnableQPSG     },986        { SQLITE_DBCONFIG_TRIGGER_EQP,           SQLITE_TriggerEQP     },987        { SQLITE_DBCONFIG_RESET_DATABASE,        SQLITE_ResetDatabase  },988        { SQLITE_DBCONFIG_DEFENSIVE,             SQLITE_Defensive      },989        { SQLITE_DBCONFIG_WRITABLE_SCHEMA,       SQLITE_WriteSchema|990                                                 SQLITE_NoSchemaError  },991        { SQLITE_DBCONFIG_LEGACY_ALTER_TABLE,    SQLITE_LegacyAlter    },992        { SQLITE_DBCONFIG_DQS_DDL,               SQLITE_DqsDDL         },993        { SQLITE_DBCONFIG_DQS_DML,               SQLITE_DqsDML         },994        { SQLITE_DBCONFIG_LEGACY_FILE_FORMAT,    SQLITE_LegacyFileFmt  },995        { SQLITE_DBCONFIG_TRUSTED_SCHEMA,        SQLITE_TrustedSchema  },996        { SQLITE_DBCONFIG_STMT_SCANSTATUS,       SQLITE_StmtScanStatus },997        { SQLITE_DBCONFIG_REVERSE_SCANORDER,     SQLITE_ReverseOrder   },998        { SQLITE_DBCONFIG_ENABLE_ATTACH_CREATE,  SQLITE_AttachCreate   },999        { SQLITE_DBCONFIG_ENABLE_ATTACH_WRITE,   SQLITE_AttachWrite    },1000        { SQLITE_DBCONFIG_ENABLE_COMMENTS,       SQLITE_Comments       },1001      };1002      unsigned int i;1003      rc = SQLITE_ERROR; /* IMP: R-42790-23372 */1004      for(i=0; i<ArraySize(aFlagOp); i++){1005        if( aFlagOp[i].op==op ){1006          int onoff = va_arg(ap, int);1007          int *pRes = va_arg(ap, int*);1008          u64 oldFlags = db->flags;1009          if( onoff>0 ){1010            db->flags |= aFlagOp[i].mask;1011          }else if( onoff==0 ){1012            db->flags &= ~(u64)aFlagOp[i].mask;1013          }1014          if( oldFlags!=db->flags ){1015            sqlite3ExpirePreparedStatements(db, 0);1016          }1017          if( pRes ){1018            *pRes = (db->flags & aFlagOp[i].mask)!=0;1019          }1020          rc = SQLITE_OK;1021          break;1022        }1023      }1024      break;1025    }1026  }1027  va_end(ap);1028  sqlite3_mutex_leave(db->mutex);1029  return rc;1030}1031 1032/*1033** This is the default collating function named "BINARY" which is always1034** available.1035*/1036static int binCollFunc(1037  void *NotUsed,1038  int nKey1, const void *pKey1,1039  int nKey2, const void *pKey21040){1041  int rc, n;1042  UNUSED_PARAMETER(NotUsed);1043  n = nKey1<nKey2 ? nKey1 : nKey2;1044  /* EVIDENCE-OF: R-65033-28449 The built-in BINARY collation compares1045  ** strings byte by byte using the memcmp() function from the standard C1046  ** library. */1047  assert( pKey1 && pKey2 );1048  rc = memcmp(pKey1, pKey2, n);1049  if( rc==0 ){1050    rc = nKey1 - nKey2;1051  }1052  return rc;1053}1054 1055/*1056** This is the collating function named "RTRIM" which is always1057** available.  Ignore trailing spaces.1058*/1059static int rtrimCollFunc(1060  void *pUser,1061  int nKey1, const void *pKey1,1062  int nKey2, const void *pKey21063){1064  const u8 *pK1 = (const u8*)pKey1;1065  const u8 *pK2 = (const u8*)pKey2;1066  while( nKey1 && pK1[nKey1-1]==' ' ) nKey1--;1067  while( nKey2 && pK2[nKey2-1]==' ' ) nKey2--;1068  return binCollFunc(pUser, nKey1, pKey1, nKey2, pKey2);1069}1070 1071/*1072** Return true if CollSeq is the default built-in BINARY.1073*/1074int sqlite3IsBinary(const CollSeq *p){1075  assert( p==0 || p->xCmp!=binCollFunc || strcmp(p->zName,"BINARY")==0 );1076  return p==0 || p->xCmp==binCollFunc;1077}1078 1079/*1080** Another built-in collating sequence: NOCASE.1081**1082** This collating sequence is intended to be used for "case independent1083** comparison". SQLite's knowledge of upper and lower case equivalents1084** extends only to the 26 characters used in the English language.1085**1086** At the moment there is only a UTF-8 implementation.1087*/1088static int nocaseCollatingFunc(1089  void *NotUsed,1090  int nKey1, const void *pKey1,1091  int nKey2, const void *pKey21092){1093  int r = sqlite3StrNICmp(1094      (const char *)pKey1, (const char *)pKey2, (nKey1<nKey2)?nKey1:nKey2);1095  UNUSED_PARAMETER(NotUsed);1096  if( 0==r ){1097    r = nKey1-nKey2;1098  }1099  return r;1100}1101 1102/*1103** Return the ROWID of the most recent insert1104*/1105sqlite_int64 sqlite3_last_insert_rowid(sqlite3 *db){1106#ifdef SQLITE_ENABLE_API_ARMOR1107  if( !sqlite3SafetyCheckOk(db) ){1108    (void)SQLITE_MISUSE_BKPT;1109    return 0;1110  }1111#endif1112  return db->lastRowid;1113}1114 1115/*1116** Set the value returned by the sqlite3_last_insert_rowid() API function.1117*/1118void sqlite3_set_last_insert_rowid(sqlite3 *db, sqlite3_int64 iRowid){1119#ifdef SQLITE_ENABLE_API_ARMOR1120  if( !sqlite3SafetyCheckOk(db) ){1121    (void)SQLITE_MISUSE_BKPT;1122    return;1123  }1124#endif1125  sqlite3_mutex_enter(db->mutex);1126  db->lastRowid = iRowid;1127  sqlite3_mutex_leave(db->mutex);1128}1129 1130/*1131** Return the number of changes in the most recent call to sqlite3_exec().1132*/1133sqlite3_int64 sqlite3_changes64(sqlite3 *db){1134#ifdef SQLITE_ENABLE_API_ARMOR1135  if( !sqlite3SafetyCheckOk(db) ){1136    (void)SQLITE_MISUSE_BKPT;1137    return 0;1138  }1139#endif1140  return db->nChange;1141}1142int sqlite3_changes(sqlite3 *db){1143  return (int)sqlite3_changes64(db);1144}1145 1146/*1147** Return the number of changes since the database handle was opened.1148*/1149sqlite3_int64 sqlite3_total_changes64(sqlite3 *db){1150#ifdef SQLITE_ENABLE_API_ARMOR1151  if( !sqlite3SafetyCheckOk(db) ){1152    (void)SQLITE_MISUSE_BKPT;1153    return 0;1154  }1155#endif1156  return db->nTotalChange;1157}1158int sqlite3_total_changes(sqlite3 *db){1159  return (int)sqlite3_total_changes64(db);1160}1161 1162/*1163** Close all open savepoints. This function only manipulates fields of the1164** database handle object, it does not close any savepoints that may be open1165** at the b-tree/pager level.1166*/1167void sqlite3CloseSavepoints(sqlite3 *db){1168  while( db->pSavepoint ){1169    Savepoint *pTmp = db->pSavepoint;1170    db->pSavepoint = pTmp->pNext;1171    sqlite3DbFree(db, pTmp);1172  }1173  db->nSavepoint = 0;1174  db->nStatement = 0;1175  db->isTransactionSavepoint = 0;1176}1177 1178/*1179** Invoke the destructor function associated with FuncDef p, if any. Except,1180** if this is not the last copy of the function, do not invoke it. Multiple1181** copies of a single function are created when create_function() is called1182** with SQLITE_ANY as the encoding.1183*/1184static void functionDestroy(sqlite3 *db, FuncDef *p){1185  FuncDestructor *pDestructor;1186  assert( (p->funcFlags & SQLITE_FUNC_BUILTIN)==0 );1187  pDestructor = p->u.pDestructor;1188  if( pDestructor ){1189    pDestructor->nRef--;1190    if( pDestructor->nRef==0 ){1191      pDestructor->xDestroy(pDestructor->pUserData);1192      sqlite3DbFree(db, pDestructor);1193    }1194  }1195}1196 1197/*1198** Disconnect all sqlite3_vtab objects that belong to database connection1199** db. This is called when db is being closed.1200*/

Showing the first 1,200 of 5175 lines. Download the file for the rest.