2000-05-29 18:26:00 +04:00
|
|
|
/*
|
2001-09-16 04:13:26 +04:00
|
|
|
** 2001 September 15
|
2000-05-29 18:26:00 +04:00
|
|
|
**
|
2001-09-16 04:13:26 +04:00
|
|
|
** The author disclaims copyright to this source code. In place of
|
|
|
|
** a legal notice, here is a blessing:
|
2000-05-29 18:26:00 +04:00
|
|
|
**
|
2001-09-16 04:13:26 +04:00
|
|
|
** May you do good and not evil.
|
|
|
|
** May you find forgiveness for yourself and forgive others.
|
|
|
|
** May you share freely, never taking more than you give.
|
2000-05-29 18:26:00 +04:00
|
|
|
**
|
|
|
|
*************************************************************************
|
|
|
|
** Main file for the SQLite library. The routines in this file
|
|
|
|
** implement the programmer interface to the library. Routines in
|
|
|
|
** other files are for internal use by SQLite and should not be
|
|
|
|
** accessed by users of the library.
|
|
|
|
*/
|
|
|
|
#include "sqliteInt.h"
|
2008-05-27 00:19:25 +04:00
|
|
|
|
2008-01-31 16:35:48 +03:00
|
|
|
#ifdef SQLITE_ENABLE_FTS3
|
|
|
|
# include "fts3.h"
|
|
|
|
#endif
|
2008-05-27 00:19:25 +04:00
|
|
|
#ifdef SQLITE_ENABLE_RTREE
|
|
|
|
# include "rtree.h"
|
|
|
|
#endif
|
2017-12-08 19:23:38 +03:00
|
|
|
#if defined(SQLITE_ENABLE_ICU) || defined(SQLITE_ENABLE_ICU_COLLATIONS)
|
2008-09-08 12:08:09 +04:00
|
|
|
# include "sqliteicu.h"
|
|
|
|
#endif
|
2015-10-09 02:37:00 +03:00
|
|
|
#ifdef SQLITE_ENABLE_JSON1
|
|
|
|
int sqlite3Json1Init(sqlite3*);
|
|
|
|
#endif
|
2017-06-29 17:33:51 +03:00
|
|
|
#ifdef SQLITE_ENABLE_STMTVTAB
|
|
|
|
int sqlite3StmtVtabInit(sqlite3*);
|
2017-06-28 18:47:29 +03:00
|
|
|
#endif
|
2015-10-09 02:37:00 +03:00
|
|
|
#ifdef SQLITE_ENABLE_FTS5
|
|
|
|
int sqlite3Fts5Init(sqlite3*);
|
|
|
|
#endif
|
2000-05-29 18:26:00 +04:00
|
|
|
|
2008-12-09 00:37:14 +03:00
|
|
|
#ifndef SQLITE_AMALGAMATION
|
2010-08-31 19:27:32 +04:00
|
|
|
/* IMPLEMENTATION-OF: R-46656-45156 The sqlite3_version[] string constant
|
|
|
|
** contains the text of SQLITE_VERSION macro.
|
|
|
|
*/
|
2004-05-10 14:34:34 +04:00
|
|
|
const char sqlite3_version[] = SQLITE_VERSION;
|
2008-12-09 00:37:14 +03:00
|
|
|
#endif
|
2010-08-31 19:27:32 +04:00
|
|
|
|
|
|
|
/* IMPLEMENTATION-OF: R-53536-42575 The sqlite3_libversion() function returns
|
|
|
|
** a pointer to the to the sqlite3_version[] string constant.
|
|
|
|
*/
|
2004-08-28 20:19:00 +04:00
|
|
|
const char *sqlite3_libversion(void){ return sqlite3_version; }
|
2010-08-31 19:27:32 +04:00
|
|
|
|
2017-10-04 21:26:44 +03:00
|
|
|
/* IMPLEMENTATION-OF: R-25063-23286 The sqlite3_sourceid() function returns a
|
2010-08-31 19:27:32 +04:00
|
|
|
** pointer to a string constant whose value is the same as the
|
2017-10-04 21:26:44 +03:00
|
|
|
** SQLITE_SOURCE_ID C preprocessor macro. Except if SQLite is built using
|
|
|
|
** an edited copy of the amalgamation, then the last four characters of
|
|
|
|
** the hash might be different from SQLITE_SOURCE_ID.
|
2010-08-31 19:27:32 +04:00
|
|
|
*/
|
2009-08-14 20:01:24 +04:00
|
|
|
const char *sqlite3_sourceid(void){ return SQLITE_SOURCE_ID; }
|
2010-08-31 19:27:32 +04:00
|
|
|
|
|
|
|
/* IMPLEMENTATION-OF: R-35210-63508 The sqlite3_libversion_number() function
|
|
|
|
** returns an integer equal to SQLITE_VERSION_NUMBER.
|
|
|
|
*/
|
2005-02-05 10:33:34 +03:00
|
|
|
int sqlite3_libversion_number(void){ return SQLITE_VERSION_NUMBER; }
|
2010-08-31 19:27:32 +04:00
|
|
|
|
2012-01-02 19:45:12 +04:00
|
|
|
/* IMPLEMENTATION-OF: R-20790-14025 The sqlite3_threadsafe() function returns
|
2012-01-01 01:51:55 +04:00
|
|
|
** zero if and only if SQLite was compiled with mutexing code omitted due to
|
2010-08-31 19:27:32 +04:00
|
|
|
** the SQLITE_THREADSAFE compile-time option being set to 0.
|
|
|
|
*/
|
2007-08-31 00:09:48 +04:00
|
|
|
int sqlite3_threadsafe(void){ return SQLITE_THREADSAFE; }
|
2000-08-22 17:40:18 +04:00
|
|
|
|
2015-04-02 20:46:52 +03:00
|
|
|
/*
|
|
|
|
** When compiling the test fixture or with debugging enabled (on Win32),
|
|
|
|
** this variable being set to non-zero will cause OSTRACE macros to emit
|
|
|
|
** extra diagnostic information.
|
|
|
|
*/
|
2015-04-16 06:24:38 +03:00
|
|
|
#ifdef SQLITE_HAVE_OS_TRACE
|
2015-04-02 20:46:52 +03:00
|
|
|
# ifndef SQLITE_DEBUG_OS_TRACE
|
|
|
|
# define SQLITE_DEBUG_OS_TRACE 0
|
|
|
|
# endif
|
|
|
|
int sqlite3OSTrace = SQLITE_DEBUG_OS_TRACE;
|
|
|
|
#endif
|
|
|
|
|
2008-05-01 21:03:49 +04:00
|
|
|
#if !defined(SQLITE_OMIT_TRACE) && defined(SQLITE_ENABLE_IOTRACE)
|
2007-02-28 07:47:26 +03:00
|
|
|
/*
|
|
|
|
** If the following function pointer is not NULL and if
|
|
|
|
** SQLITE_ENABLE_IOTRACE is enabled, then messages describing
|
|
|
|
** I/O active are written using this function. These messages
|
|
|
|
** are intended for debugging activity only.
|
|
|
|
*/
|
2015-03-27 03:21:52 +03:00
|
|
|
SQLITE_API void (SQLITE_CDECL *sqlite3IoTrace)(const char*, ...) = 0;
|
2008-05-01 21:03:49 +04:00
|
|
|
#endif
|
2007-02-28 07:47:26 +03:00
|
|
|
|
2007-03-30 15:29:32 +04:00
|
|
|
/*
|
|
|
|
** If the following global variable points to a string which is the
|
|
|
|
** name of a directory, then that directory will be used to store
|
|
|
|
** temporary files.
|
|
|
|
**
|
|
|
|
** See also the "PRAGMA temp_store_directory" SQL command.
|
|
|
|
*/
|
|
|
|
char *sqlite3_temp_directory = 0;
|
|
|
|
|
2012-03-14 04:44:01 +04:00
|
|
|
/*
|
|
|
|
** If the following global variable points to a string which is the
|
|
|
|
** name of a directory, then that directory will be used to store
|
|
|
|
** all database files specified with a relative pathname.
|
|
|
|
**
|
|
|
|
** See also the "PRAGMA data_store_directory" SQL command.
|
|
|
|
*/
|
|
|
|
char *sqlite3_data_directory = 0;
|
|
|
|
|
2008-06-13 22:24:27 +04:00
|
|
|
/*
|
|
|
|
** Initialize SQLite.
|
|
|
|
**
|
|
|
|
** This routine must be called to initialize the memory allocation,
|
2008-08-12 19:21:11 +04:00
|
|
|
** VFS, and mutex subsystems prior to doing any serious work with
|
2008-06-13 22:24:27 +04:00
|
|
|
** SQLite. But as long as you do not compile with SQLITE_OMIT_AUTOINIT
|
|
|
|
** this routine will be called automatically by key routines such as
|
|
|
|
** sqlite3_open().
|
|
|
|
**
|
|
|
|
** This routine is a no-op except on its very first call for the process,
|
|
|
|
** or for the first call after a call to sqlite3_shutdown.
|
2008-08-12 19:21:11 +04:00
|
|
|
**
|
|
|
|
** The first thread to call this routine runs the initialization to
|
|
|
|
** completion. If subsequent threads call this routine before the first
|
|
|
|
** thread has finished the initialization process, then the subsequent
|
|
|
|
** threads must block until the first thread finishes with the initialization.
|
|
|
|
**
|
|
|
|
** The first thread might call this routine recursively. Recursive
|
|
|
|
** calls to this routine should not block, of course. Otherwise the
|
|
|
|
** initialization process would never complete.
|
|
|
|
**
|
|
|
|
** Let X be the first thread to enter this routine. Let Y be some other
|
|
|
|
** thread. Then while the initial invocation of this routine by X is
|
|
|
|
** incomplete, it is required that:
|
|
|
|
**
|
|
|
|
** * Calls to this routine from Y must block until the outer-most
|
|
|
|
** call by X completes.
|
|
|
|
**
|
|
|
|
** * Recursive calls to this routine from thread X return immediately
|
|
|
|
** without blocking.
|
2008-06-13 22:24:27 +04:00
|
|
|
*/
|
|
|
|
int sqlite3_initialize(void){
|
2011-10-15 04:16:30 +04:00
|
|
|
MUTEX_LOGIC( sqlite3_mutex *pMaster; ) /* The main static mutex */
|
2008-09-01 22:34:20 +04:00
|
|
|
int rc; /* Result code */
|
2013-08-08 18:38:45 +04:00
|
|
|
#ifdef SQLITE_EXTRA_INIT
|
|
|
|
int bRunExtraInit = 0; /* Extra initialization needed */
|
|
|
|
#endif
|
2008-09-01 22:34:20 +04:00
|
|
|
|
|
|
|
#ifdef SQLITE_OMIT_WSD
|
2008-09-02 20:22:28 +04:00
|
|
|
rc = sqlite3_wsd_init(4096, 24);
|
2008-09-01 22:34:20 +04:00
|
|
|
if( rc!=SQLITE_OK ){
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
#endif
|
2008-06-26 12:29:34 +04:00
|
|
|
|
2015-03-23 21:52:56 +03:00
|
|
|
/* If the following assert() fails on some obscure processor/compiler
|
|
|
|
** combination, the work-around is to set the correct pointer
|
|
|
|
** size at compile-time using -DSQLITE_PTRSIZE=n compile-time option */
|
|
|
|
assert( SQLITE_PTRSIZE==sizeof(char*) );
|
|
|
|
|
2008-08-12 19:21:11 +04:00
|
|
|
/* If SQLite is already completely initialized, then this call
|
|
|
|
** to sqlite3_initialize() should be a no-op. But the initialization
|
|
|
|
** must be complete. So isInit must not be set until the very end
|
|
|
|
** of this routine.
|
|
|
|
*/
|
2008-09-01 22:34:20 +04:00
|
|
|
if( sqlite3GlobalConfig.isInit ) return SQLITE_OK;
|
2008-06-26 12:29:34 +04:00
|
|
|
|
2008-08-12 19:21:11 +04:00
|
|
|
/* Make sure the mutex subsystem is initialized. If unable to
|
|
|
|
** initialize the mutex subsystem, return early with the error.
|
|
|
|
** If the system is so sick that we are unable to allocate a mutex,
|
|
|
|
** there is not much SQLite is going to be able to do.
|
|
|
|
**
|
|
|
|
** The mutex subsystem must take care of serializing its own
|
|
|
|
** initialization.
|
|
|
|
*/
|
2008-06-18 22:57:42 +04:00
|
|
|
rc = sqlite3MutexInit();
|
2008-08-12 19:21:11 +04:00
|
|
|
if( rc ) return rc;
|
2008-06-26 12:29:34 +04:00
|
|
|
|
2008-08-12 19:21:11 +04:00
|
|
|
/* Initialize the malloc() system and the recursive pInitMutex mutex.
|
|
|
|
** This operation is protected by the STATIC_MASTER mutex. Note that
|
|
|
|
** MutexAlloc() is called for a static mutex prior to initializing the
|
|
|
|
** malloc subsystem - this implies that the allocation of a static
|
|
|
|
** mutex must not require support from the malloc subsystem.
|
|
|
|
*/
|
2011-10-15 04:16:30 +04:00
|
|
|
MUTEX_LOGIC( pMaster = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MASTER); )
|
2008-08-12 19:21:11 +04:00
|
|
|
sqlite3_mutex_enter(pMaster);
|
2009-08-17 19:16:19 +04:00
|
|
|
sqlite3GlobalConfig.isMutexInit = 1;
|
2008-09-01 22:34:20 +04:00
|
|
|
if( !sqlite3GlobalConfig.isMallocInit ){
|
2008-08-12 19:21:11 +04:00
|
|
|
rc = sqlite3MallocInit();
|
|
|
|
}
|
2008-06-13 22:24:27 +04:00
|
|
|
if( rc==SQLITE_OK ){
|
2008-09-01 22:34:20 +04:00
|
|
|
sqlite3GlobalConfig.isMallocInit = 1;
|
|
|
|
if( !sqlite3GlobalConfig.pInitMutex ){
|
2009-08-17 17:42:29 +04:00
|
|
|
sqlite3GlobalConfig.pInitMutex =
|
|
|
|
sqlite3MutexAlloc(SQLITE_MUTEX_RECURSIVE);
|
2008-09-01 22:34:20 +04:00
|
|
|
if( sqlite3GlobalConfig.bCoreMutex && !sqlite3GlobalConfig.pInitMutex ){
|
2016-02-14 02:43:46 +03:00
|
|
|
rc = SQLITE_NOMEM_BKPT;
|
2008-06-13 22:24:27 +04:00
|
|
|
}
|
|
|
|
}
|
2008-09-22 21:22:19 +04:00
|
|
|
}
|
|
|
|
if( rc==SQLITE_OK ){
|
2008-09-01 22:34:20 +04:00
|
|
|
sqlite3GlobalConfig.nRefInitMutex++;
|
2008-08-12 19:21:11 +04:00
|
|
|
}
|
|
|
|
sqlite3_mutex_leave(pMaster);
|
2008-06-26 12:29:34 +04:00
|
|
|
|
2009-08-17 19:16:19 +04:00
|
|
|
/* If rc is not SQLITE_OK at this point, then either the malloc
|
|
|
|
** subsystem could not be initialized or the system failed to allocate
|
|
|
|
** the pInitMutex mutex. Return an error in either case. */
|
2008-08-12 19:21:11 +04:00
|
|
|
if( rc!=SQLITE_OK ){
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Do the rest of the initialization under the recursive mutex so
|
|
|
|
** that we will be able to handle recursive calls into
|
|
|
|
** sqlite3_initialize(). The recursive calls normally come through
|
|
|
|
** sqlite3_os_init() when it invokes sqlite3_vfs_register(), but other
|
|
|
|
** recursive calls might also be possible.
|
2010-09-09 22:25:34 +04:00
|
|
|
**
|
|
|
|
** IMPLEMENTATION-OF: R-00140-37445 SQLite automatically serializes calls
|
|
|
|
** to the xInit method, so the xInit method need not be threadsafe.
|
|
|
|
**
|
|
|
|
** The following mutex is what serializes access to the appdef pcache xInit
|
|
|
|
** methods. The sqlite3_pcache_methods.xInit() all is embedded in the
|
|
|
|
** call to sqlite3PcacheInitialize().
|
2008-08-12 19:21:11 +04:00
|
|
|
*/
|
2008-09-01 22:34:20 +04:00
|
|
|
sqlite3_mutex_enter(sqlite3GlobalConfig.pInitMutex);
|
2008-09-02 18:07:24 +04:00
|
|
|
if( sqlite3GlobalConfig.isInit==0 && sqlite3GlobalConfig.inProgress==0 ){
|
|
|
|
sqlite3GlobalConfig.inProgress = 1;
|
2015-11-13 02:48:08 +03:00
|
|
|
#ifdef SQLITE_ENABLE_SQLLOG
|
2015-11-12 23:12:51 +03:00
|
|
|
{
|
2015-11-13 02:48:08 +03:00
|
|
|
extern void sqlite3_init_sqllog(void);
|
|
|
|
sqlite3_init_sqllog();
|
2015-11-12 23:12:51 +03:00
|
|
|
}
|
|
|
|
#endif
|
2016-02-15 03:34:16 +03:00
|
|
|
memset(&sqlite3BuiltinFunctions, 0, sizeof(sqlite3BuiltinFunctions));
|
|
|
|
sqlite3RegisterBuiltinFunctions();
|
2009-08-17 19:16:19 +04:00
|
|
|
if( sqlite3GlobalConfig.isPCacheInit==0 ){
|
|
|
|
rc = sqlite3PcacheInitialize();
|
|
|
|
}
|
2009-04-17 20:54:22 +04:00
|
|
|
if( rc==SQLITE_OK ){
|
2009-08-17 19:16:19 +04:00
|
|
|
sqlite3GlobalConfig.isPCacheInit = 1;
|
2009-08-17 19:52:25 +04:00
|
|
|
rc = sqlite3OsInit();
|
2009-04-17 20:54:22 +04:00
|
|
|
}
|
2018-03-07 00:43:19 +03:00
|
|
|
#ifdef SQLITE_ENABLE_DESERIALIZE
|
2018-01-03 04:28:46 +03:00
|
|
|
if( rc==SQLITE_OK ){
|
|
|
|
rc = sqlite3MemdbInit();
|
|
|
|
}
|
|
|
|
#endif
|
2008-08-20 18:49:23 +04:00
|
|
|
if( rc==SQLITE_OK ){
|
2008-09-02 13:38:06 +04:00
|
|
|
sqlite3PCacheBufferSetup( sqlite3GlobalConfig.pPage,
|
|
|
|
sqlite3GlobalConfig.szPage, sqlite3GlobalConfig.nPage);
|
2009-04-17 20:54:22 +04:00
|
|
|
sqlite3GlobalConfig.isInit = 1;
|
2013-08-08 18:38:45 +04:00
|
|
|
#ifdef SQLITE_EXTRA_INIT
|
|
|
|
bRunExtraInit = 1;
|
|
|
|
#endif
|
2008-08-20 18:49:23 +04:00
|
|
|
}
|
2008-09-02 18:07:24 +04:00
|
|
|
sqlite3GlobalConfig.inProgress = 0;
|
2008-06-13 22:24:27 +04:00
|
|
|
}
|
2008-09-01 22:34:20 +04:00
|
|
|
sqlite3_mutex_leave(sqlite3GlobalConfig.pInitMutex);
|
2008-08-12 19:21:11 +04:00
|
|
|
|
|
|
|
/* Go back under the static mutex and clean up the recursive
|
|
|
|
** mutex to prevent a resource leak.
|
|
|
|
*/
|
|
|
|
sqlite3_mutex_enter(pMaster);
|
2008-09-01 22:34:20 +04:00
|
|
|
sqlite3GlobalConfig.nRefInitMutex--;
|
|
|
|
if( sqlite3GlobalConfig.nRefInitMutex<=0 ){
|
|
|
|
assert( sqlite3GlobalConfig.nRefInitMutex==0 );
|
|
|
|
sqlite3_mutex_free(sqlite3GlobalConfig.pInitMutex);
|
|
|
|
sqlite3GlobalConfig.pInitMutex = 0;
|
2008-08-12 19:21:11 +04:00
|
|
|
}
|
|
|
|
sqlite3_mutex_leave(pMaster);
|
2008-07-22 09:13:30 +04:00
|
|
|
|
2008-08-12 19:21:11 +04:00
|
|
|
/* The following is just a sanity check to make sure SQLite has
|
|
|
|
** been compiled correctly. It is important to run this code, but
|
|
|
|
** we don't want to run it too often and soak up CPU cycles for no
|
|
|
|
** reason. So we run it once during initialization.
|
|
|
|
*/
|
2008-07-22 09:13:30 +04:00
|
|
|
#ifndef NDEBUG
|
2009-02-04 06:59:25 +03:00
|
|
|
#ifndef SQLITE_OMIT_FLOATING_POINT
|
2008-07-22 09:13:30 +04:00
|
|
|
/* This section of code's only "output" is via assert() statements. */
|
2018-01-03 04:28:46 +03:00
|
|
|
if( rc==SQLITE_OK ){
|
2008-07-22 09:13:30 +04:00
|
|
|
u64 x = (((u64)1)<<63)-1;
|
|
|
|
double y;
|
|
|
|
assert(sizeof(x)==8);
|
|
|
|
assert(sizeof(x)==sizeof(y));
|
|
|
|
memcpy(&y, &x, 8);
|
|
|
|
assert( sqlite3IsNaN(y) );
|
|
|
|
}
|
2009-02-04 06:59:25 +03:00
|
|
|
#endif
|
2008-07-22 09:13:30 +04:00
|
|
|
#endif
|
|
|
|
|
2011-08-25 04:14:41 +04:00
|
|
|
/* Do extra initialization steps requested by the SQLITE_EXTRA_INIT
|
|
|
|
** compile-time option.
|
|
|
|
*/
|
|
|
|
#ifdef SQLITE_EXTRA_INIT
|
2013-08-08 18:38:45 +04:00
|
|
|
if( bRunExtraInit ){
|
2011-12-13 22:22:38 +04:00
|
|
|
int SQLITE_EXTRA_INIT(const char*);
|
|
|
|
rc = SQLITE_EXTRA_INIT(0);
|
2011-08-25 04:14:41 +04:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2008-06-13 22:24:27 +04:00
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
** Undo the effects of sqlite3_initialize(). Must not be called while
|
|
|
|
** there are outstanding database connections or memory allocations or
|
|
|
|
** while any part of SQLite is otherwise in use in any thread. This
|
2009-04-19 16:23:58 +04:00
|
|
|
** routine is not threadsafe. But it is safe to invoke this routine
|
|
|
|
** on when SQLite is already shut down. If SQLite is already shut down
|
|
|
|
** when this routine is invoked, then this routine is a harmless no-op.
|
2008-06-13 22:24:27 +04:00
|
|
|
*/
|
|
|
|
int sqlite3_shutdown(void){
|
2014-12-23 23:42:48 +03:00
|
|
|
#ifdef SQLITE_OMIT_WSD
|
|
|
|
int rc = sqlite3_wsd_init(4096, 24);
|
|
|
|
if( rc!=SQLITE_OK ){
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2008-09-01 22:34:20 +04:00
|
|
|
if( sqlite3GlobalConfig.isInit ){
|
2011-12-13 05:34:21 +04:00
|
|
|
#ifdef SQLITE_EXTRA_SHUTDOWN
|
|
|
|
void SQLITE_EXTRA_SHUTDOWN(void);
|
|
|
|
SQLITE_EXTRA_SHUTDOWN();
|
|
|
|
#endif
|
2009-04-21 16:02:56 +04:00
|
|
|
sqlite3_os_end();
|
2009-04-19 16:23:58 +04:00
|
|
|
sqlite3_reset_auto_extension();
|
2009-08-17 19:16:19 +04:00
|
|
|
sqlite3GlobalConfig.isInit = 0;
|
|
|
|
}
|
|
|
|
if( sqlite3GlobalConfig.isPCacheInit ){
|
|
|
|
sqlite3PcacheShutdown();
|
|
|
|
sqlite3GlobalConfig.isPCacheInit = 0;
|
|
|
|
}
|
|
|
|
if( sqlite3GlobalConfig.isMallocInit ){
|
2009-04-19 16:23:58 +04:00
|
|
|
sqlite3MallocEnd();
|
2009-08-17 19:16:19 +04:00
|
|
|
sqlite3GlobalConfig.isMallocInit = 0;
|
2012-03-18 05:32:44 +04:00
|
|
|
|
|
|
|
#ifndef SQLITE_OMIT_SHUTDOWN_DIRECTORIES
|
|
|
|
/* The heap subsystem has now been shutdown and these values are supposed
|
|
|
|
** to be NULL or point to memory that was obtained from sqlite3_malloc(),
|
|
|
|
** which would rely on that heap subsystem; therefore, make sure these
|
|
|
|
** values cannot refer to heap memory that was just invalidated when the
|
|
|
|
** heap subsystem was shutdown. This is only done if the current call to
|
|
|
|
** this function resulted in the heap subsystem actually being shutdown.
|
|
|
|
*/
|
|
|
|
sqlite3_data_directory = 0;
|
|
|
|
sqlite3_temp_directory = 0;
|
|
|
|
#endif
|
2009-08-17 19:16:19 +04:00
|
|
|
}
|
|
|
|
if( sqlite3GlobalConfig.isMutexInit ){
|
2009-04-19 16:23:58 +04:00
|
|
|
sqlite3MutexEnd();
|
2009-08-17 19:16:19 +04:00
|
|
|
sqlite3GlobalConfig.isMutexInit = 0;
|
2008-07-08 16:02:35 +04:00
|
|
|
}
|
2009-08-17 19:16:19 +04:00
|
|
|
|
2008-06-13 22:24:27 +04:00
|
|
|
return SQLITE_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
** This API allows applications to modify the global configuration of
|
|
|
|
** the SQLite library at run-time.
|
|
|
|
**
|
|
|
|
** This routine should only be called when there are no outstanding
|
|
|
|
** database connections or memory allocations. This routine is not
|
|
|
|
** threadsafe. Failure to heed these warnings can lead to unpredictable
|
|
|
|
** behavior.
|
|
|
|
*/
|
|
|
|
int sqlite3_config(int op, ...){
|
|
|
|
va_list ap;
|
|
|
|
int rc = SQLITE_OK;
|
|
|
|
|
|
|
|
/* sqlite3_config() shall return SQLITE_MISUSE if it is invoked while
|
|
|
|
** the SQLite library is in use. */
|
2010-02-23 23:11:56 +03:00
|
|
|
if( sqlite3GlobalConfig.isInit ) return SQLITE_MISUSE_BKPT;
|
2008-06-13 22:24:27 +04:00
|
|
|
|
|
|
|
va_start(ap, op);
|
|
|
|
switch( op ){
|
2008-10-07 19:25:48 +04:00
|
|
|
|
|
|
|
/* Mutex configuration options are only available in a threadsafe
|
2014-11-01 21:32:18 +03:00
|
|
|
** compile.
|
2008-10-07 19:25:48 +04:00
|
|
|
*/
|
2014-11-01 21:32:18 +03:00
|
|
|
#if defined(SQLITE_THREADSAFE) && SQLITE_THREADSAFE>0 /* IMP: R-54466-46756 */
|
2008-06-13 22:24:27 +04:00
|
|
|
case SQLITE_CONFIG_SINGLETHREAD: {
|
2015-03-05 02:14:14 +03:00
|
|
|
/* EVIDENCE-OF: R-02748-19096 This option sets the threading mode to
|
|
|
|
** Single-thread. */
|
|
|
|
sqlite3GlobalConfig.bCoreMutex = 0; /* Disable mutex on core */
|
|
|
|
sqlite3GlobalConfig.bFullMutex = 0; /* Disable mutex on connections */
|
2008-06-13 22:24:27 +04:00
|
|
|
break;
|
|
|
|
}
|
2014-11-01 21:32:18 +03:00
|
|
|
#endif
|
|
|
|
#if defined(SQLITE_THREADSAFE) && SQLITE_THREADSAFE>0 /* IMP: R-20520-54086 */
|
2008-06-13 22:24:27 +04:00
|
|
|
case SQLITE_CONFIG_MULTITHREAD: {
|
2015-03-05 02:14:14 +03:00
|
|
|
/* EVIDENCE-OF: R-14374-42468 This option sets the threading mode to
|
|
|
|
** Multi-thread. */
|
|
|
|
sqlite3GlobalConfig.bCoreMutex = 1; /* Enable mutex on core */
|
|
|
|
sqlite3GlobalConfig.bFullMutex = 0; /* Disable mutex on connections */
|
2008-06-13 22:24:27 +04:00
|
|
|
break;
|
|
|
|
}
|
2014-11-01 21:32:18 +03:00
|
|
|
#endif
|
|
|
|
#if defined(SQLITE_THREADSAFE) && SQLITE_THREADSAFE>0 /* IMP: R-59593-21810 */
|
2008-06-13 22:24:27 +04:00
|
|
|
case SQLITE_CONFIG_SERIALIZED: {
|
2015-03-05 02:14:14 +03:00
|
|
|
/* EVIDENCE-OF: R-41220-51800 This option sets the threading mode to
|
|
|
|
** Serialized. */
|
|
|
|
sqlite3GlobalConfig.bCoreMutex = 1; /* Enable mutex on core */
|
|
|
|
sqlite3GlobalConfig.bFullMutex = 1; /* Enable mutex on connections */
|
2008-06-13 22:24:27 +04:00
|
|
|
break;
|
|
|
|
}
|
2014-11-01 21:32:18 +03:00
|
|
|
#endif
|
|
|
|
#if defined(SQLITE_THREADSAFE) && SQLITE_THREADSAFE>0 /* IMP: R-63666-48755 */
|
2008-10-07 19:25:48 +04:00
|
|
|
case SQLITE_CONFIG_MUTEX: {
|
|
|
|
/* Specify an alternative mutex implementation */
|
|
|
|
sqlite3GlobalConfig.mutex = *va_arg(ap, sqlite3_mutex_methods*);
|
|
|
|
break;
|
|
|
|
}
|
2014-11-01 21:32:18 +03:00
|
|
|
#endif
|
|
|
|
#if defined(SQLITE_THREADSAFE) && SQLITE_THREADSAFE>0 /* IMP: R-14450-37597 */
|
2008-10-07 19:25:48 +04:00
|
|
|
case SQLITE_CONFIG_GETMUTEX: {
|
|
|
|
/* Retrieve the current mutex implementation */
|
|
|
|
*va_arg(ap, sqlite3_mutex_methods*) = sqlite3GlobalConfig.mutex;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2008-06-13 22:24:27 +04:00
|
|
|
case SQLITE_CONFIG_MALLOC: {
|
2014-11-04 16:41:32 +03:00
|
|
|
/* EVIDENCE-OF: R-55594-21030 The SQLITE_CONFIG_MALLOC option takes a
|
|
|
|
** single argument which is a pointer to an instance of the
|
|
|
|
** sqlite3_mem_methods structure. The argument specifies alternative
|
|
|
|
** low-level memory allocation routines to be used in place of the memory
|
|
|
|
** allocation routines built into SQLite. */
|
2008-09-01 22:34:20 +04:00
|
|
|
sqlite3GlobalConfig.m = *va_arg(ap, sqlite3_mem_methods*);
|
2008-06-13 22:24:27 +04:00
|
|
|
break;
|
|
|
|
}
|
2008-06-18 17:27:46 +04:00
|
|
|
case SQLITE_CONFIG_GETMALLOC: {
|
2014-11-04 16:41:32 +03:00
|
|
|
/* EVIDENCE-OF: R-51213-46414 The SQLITE_CONFIG_GETMALLOC option takes a
|
|
|
|
** single argument which is a pointer to an instance of the
|
|
|
|
** sqlite3_mem_methods structure. The sqlite3_mem_methods structure is
|
|
|
|
** filled with the currently defined memory allocation routines. */
|
2008-09-01 22:34:20 +04:00
|
|
|
if( sqlite3GlobalConfig.m.xMalloc==0 ) sqlite3MemSetDefault();
|
|
|
|
*va_arg(ap, sqlite3_mem_methods*) = sqlite3GlobalConfig.m;
|
2008-06-18 17:27:46 +04:00
|
|
|
break;
|
|
|
|
}
|
2008-06-14 20:56:21 +04:00
|
|
|
case SQLITE_CONFIG_MEMSTATUS: {
|
2014-11-04 16:41:32 +03:00
|
|
|
/* EVIDENCE-OF: R-61275-35157 The SQLITE_CONFIG_MEMSTATUS option takes
|
|
|
|
** single argument of type int, interpreted as a boolean, which enables
|
|
|
|
** or disables the collection of memory allocation statistics. */
|
|
|
|
sqlite3GlobalConfig.bMemstat = va_arg(ap, int);
|
2008-06-13 22:24:27 +04:00
|
|
|
break;
|
|
|
|
}
|
2017-08-28 18:51:35 +03:00
|
|
|
case SQLITE_CONFIG_SMALL_MALLOC: {
|
|
|
|
sqlite3GlobalConfig.bSmallMalloc = va_arg(ap, int);
|
2008-06-18 17:27:46 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case SQLITE_CONFIG_PAGECACHE: {
|
2015-12-04 01:33:55 +03:00
|
|
|
/* EVIDENCE-OF: R-18761-36601 There are three arguments to
|
|
|
|
** SQLITE_CONFIG_PAGECACHE: A pointer to 8-byte aligned memory (pMem),
|
|
|
|
** the size of each page cache line (sz), and the number of cache lines
|
|
|
|
** (N). */
|
2008-09-01 22:34:20 +04:00
|
|
|
sqlite3GlobalConfig.pPage = va_arg(ap, void*);
|
|
|
|
sqlite3GlobalConfig.szPage = va_arg(ap, int);
|
|
|
|
sqlite3GlobalConfig.nPage = va_arg(ap, int);
|
2008-06-18 17:27:46 +04:00
|
|
|
break;
|
|
|
|
}
|
2014-11-04 15:11:23 +03:00
|
|
|
case SQLITE_CONFIG_PCACHE_HDRSZ: {
|
2014-11-04 16:41:32 +03:00
|
|
|
/* EVIDENCE-OF: R-39100-27317 The SQLITE_CONFIG_PCACHE_HDRSZ option takes
|
|
|
|
** a single parameter which is a pointer to an integer and writes into
|
|
|
|
** that integer the number of extra bytes per page required for each page
|
|
|
|
** in SQLITE_CONFIG_PAGECACHE. */
|
2014-11-04 15:11:23 +03:00
|
|
|
*va_arg(ap, int*) =
|
|
|
|
sqlite3HeaderSizeBtree() +
|
|
|
|
sqlite3HeaderSizePcache() +
|
|
|
|
sqlite3HeaderSizePcache1();
|
|
|
|
break;
|
|
|
|
}
|
2008-06-27 17:27:03 +04:00
|
|
|
|
2008-11-13 17:28:28 +03:00
|
|
|
case SQLITE_CONFIG_PCACHE: {
|
2011-11-09 00:08:44 +04:00
|
|
|
/* no-op */
|
2008-11-13 17:28:28 +03:00
|
|
|
break;
|
|
|
|
}
|
2008-11-19 04:20:26 +03:00
|
|
|
case SQLITE_CONFIG_GETPCACHE: {
|
2011-11-09 00:08:44 +04:00
|
|
|
/* now an error */
|
|
|
|
rc = SQLITE_ERROR;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case SQLITE_CONFIG_PCACHE2: {
|
2014-11-04 16:41:32 +03:00
|
|
|
/* EVIDENCE-OF: R-63325-48378 The SQLITE_CONFIG_PCACHE2 option takes a
|
|
|
|
** single argument which is a pointer to an sqlite3_pcache_methods2
|
|
|
|
** object. This object specifies the interface to a custom page cache
|
|
|
|
** implementation. */
|
2011-11-09 00:08:44 +04:00
|
|
|
sqlite3GlobalConfig.pcache2 = *va_arg(ap, sqlite3_pcache_methods2*);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case SQLITE_CONFIG_GETPCACHE2: {
|
2014-11-04 16:41:32 +03:00
|
|
|
/* EVIDENCE-OF: R-22035-46182 The SQLITE_CONFIG_GETPCACHE2 option takes a
|
|
|
|
** single argument which is a pointer to an sqlite3_pcache_methods2
|
|
|
|
** object. SQLite copies of the current page cache implementation into
|
|
|
|
** that object. */
|
2011-11-09 00:08:44 +04:00
|
|
|
if( sqlite3GlobalConfig.pcache2.xInit==0 ){
|
2008-11-19 04:20:26 +03:00
|
|
|
sqlite3PCacheSetDefault();
|
|
|
|
}
|
2011-11-09 00:08:44 +04:00
|
|
|
*va_arg(ap, sqlite3_pcache_methods2*) = sqlite3GlobalConfig.pcache2;
|
2008-11-19 04:20:26 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2014-11-07 04:43:56 +03:00
|
|
|
/* EVIDENCE-OF: R-06626-12911 The SQLITE_CONFIG_HEAP option is only
|
|
|
|
** available if SQLite is compiled with either SQLITE_ENABLE_MEMSYS3 or
|
|
|
|
** SQLITE_ENABLE_MEMSYS5 and returns SQLITE_ERROR if invoked otherwise. */
|
2008-07-15 18:47:18 +04:00
|
|
|
#if defined(SQLITE_ENABLE_MEMSYS3) || defined(SQLITE_ENABLE_MEMSYS5)
|
2008-06-18 17:27:46 +04:00
|
|
|
case SQLITE_CONFIG_HEAP: {
|
2014-11-04 16:41:32 +03:00
|
|
|
/* EVIDENCE-OF: R-19854-42126 There are three arguments to
|
|
|
|
** SQLITE_CONFIG_HEAP: An 8-byte aligned pointer to the memory, the
|
2015-03-03 17:00:11 +03:00
|
|
|
** number of bytes in the memory buffer, and the minimum allocation size.
|
|
|
|
*/
|
2008-09-01 22:34:20 +04:00
|
|
|
sqlite3GlobalConfig.pHeap = va_arg(ap, void*);
|
|
|
|
sqlite3GlobalConfig.nHeap = va_arg(ap, int);
|
|
|
|
sqlite3GlobalConfig.mnReq = va_arg(ap, int);
|
2008-06-27 17:27:03 +04:00
|
|
|
|
2011-03-10 00:36:17 +03:00
|
|
|
if( sqlite3GlobalConfig.mnReq<1 ){
|
|
|
|
sqlite3GlobalConfig.mnReq = 1;
|
|
|
|
}else if( sqlite3GlobalConfig.mnReq>(1<<12) ){
|
|
|
|
/* cap min request size at 2^12 */
|
|
|
|
sqlite3GlobalConfig.mnReq = (1<<12);
|
|
|
|
}
|
|
|
|
|
2008-09-01 22:34:20 +04:00
|
|
|
if( sqlite3GlobalConfig.pHeap==0 ){
|
2014-11-07 04:43:56 +03:00
|
|
|
/* EVIDENCE-OF: R-49920-60189 If the first pointer (the memory pointer)
|
|
|
|
** is NULL, then SQLite reverts to using its default memory allocator
|
|
|
|
** (the system malloc() implementation), undoing any prior invocation of
|
|
|
|
** SQLITE_CONFIG_MALLOC.
|
|
|
|
**
|
|
|
|
** Setting sqlite3GlobalConfig.m to all zeros will cause malloc to
|
|
|
|
** revert to its default implementation when sqlite3_initialize() is run
|
2008-07-10 22:13:42 +04:00
|
|
|
*/
|
2008-09-01 22:34:20 +04:00
|
|
|
memset(&sqlite3GlobalConfig.m, 0, sizeof(sqlite3GlobalConfig.m));
|
2008-07-10 22:13:42 +04:00
|
|
|
}else{
|
2014-11-07 04:43:56 +03:00
|
|
|
/* EVIDENCE-OF: R-61006-08918 If the memory pointer is not NULL then the
|
|
|
|
** alternative memory allocator is engaged to handle all of SQLites
|
|
|
|
** memory allocation needs. */
|
2008-07-10 22:13:42 +04:00
|
|
|
#ifdef SQLITE_ENABLE_MEMSYS3
|
2008-09-01 22:34:20 +04:00
|
|
|
sqlite3GlobalConfig.m = *sqlite3MemGetMemsys3();
|
2008-07-10 22:13:42 +04:00
|
|
|
#endif
|
2008-06-27 17:27:03 +04:00
|
|
|
#ifdef SQLITE_ENABLE_MEMSYS5
|
2008-09-01 22:34:20 +04:00
|
|
|
sqlite3GlobalConfig.m = *sqlite3MemGetMemsys5();
|
2008-07-10 22:13:42 +04:00
|
|
|
#endif
|
|
|
|
}
|
2008-06-18 17:27:46 +04:00
|
|
|
break;
|
|
|
|
}
|
2008-07-15 18:47:18 +04:00
|
|
|
#endif
|
2008-06-27 17:27:03 +04:00
|
|
|
|
2008-07-28 23:34:53 +04:00
|
|
|
case SQLITE_CONFIG_LOOKASIDE: {
|
2008-09-01 22:34:20 +04:00
|
|
|
sqlite3GlobalConfig.szLookaside = va_arg(ap, int);
|
|
|
|
sqlite3GlobalConfig.nLookaside = va_arg(ap, int);
|
2008-07-28 23:34:53 +04:00
|
|
|
break;
|
|
|
|
}
|
2010-02-18 21:45:09 +03:00
|
|
|
|
2013-08-14 02:33:41 +04:00
|
|
|
/* Record a pointer to the logger function and its first argument.
|
2010-02-18 21:45:09 +03:00
|
|
|
** The default is NULL. Logging is disabled if the function pointer is
|
|
|
|
** NULL.
|
|
|
|
*/
|
|
|
|
case SQLITE_CONFIG_LOG: {
|
2010-02-23 23:08:35 +03:00
|
|
|
/* MSVC is picky about pulling func ptrs from va lists.
|
|
|
|
** http://support.microsoft.com/kb/47961
|
|
|
|
** sqlite3GlobalConfig.xLog = va_arg(ap, void(*)(void*,int,const char*));
|
|
|
|
*/
|
|
|
|
typedef void(*LOGFUNC_t)(void*,int,const char*);
|
|
|
|
sqlite3GlobalConfig.xLog = va_arg(ap, LOGFUNC_t);
|
2010-02-18 21:45:09 +03:00
|
|
|
sqlite3GlobalConfig.pLogArg = va_arg(ap, void*);
|
|
|
|
break;
|
|
|
|
}
|
2008-07-28 23:34:53 +04:00
|
|
|
|
2014-10-04 15:59:33 +04:00
|
|
|
/* EVIDENCE-OF: R-55548-33817 The compile-time setting for URI filenames
|
|
|
|
** can be changed at start-time using the
|
|
|
|
** sqlite3_config(SQLITE_CONFIG_URI,1) or
|
|
|
|
** sqlite3_config(SQLITE_CONFIG_URI,0) configuration calls.
|
|
|
|
*/
|
2011-04-22 23:37:32 +04:00
|
|
|
case SQLITE_CONFIG_URI: {
|
2014-11-04 20:23:24 +03:00
|
|
|
/* EVIDENCE-OF: R-25451-61125 The SQLITE_CONFIG_URI option takes a single
|
|
|
|
** argument of type int. If non-zero, then URI handling is globally
|
|
|
|
** enabled. If the parameter is zero, then URI handling is globally
|
|
|
|
** disabled. */
|
2011-04-22 23:37:32 +04:00
|
|
|
sqlite3GlobalConfig.bOpenUri = va_arg(ap, int);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2012-09-18 00:44:46 +04:00
|
|
|
case SQLITE_CONFIG_COVERING_INDEX_SCAN: {
|
2014-11-04 20:23:24 +03:00
|
|
|
/* EVIDENCE-OF: R-36592-02772 The SQLITE_CONFIG_COVERING_INDEX_SCAN
|
|
|
|
** option takes a single integer argument which is interpreted as a
|
|
|
|
** boolean in order to enable or disable the use of covering indices for
|
|
|
|
** full table scans in the query optimizer. */
|
2012-09-18 00:44:46 +04:00
|
|
|
sqlite3GlobalConfig.bUseCis = va_arg(ap, int);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2012-11-26 23:50:41 +04:00
|
|
|
#ifdef SQLITE_ENABLE_SQLLOG
|
|
|
|
case SQLITE_CONFIG_SQLLOG: {
|
|
|
|
typedef void(*SQLLOGFUNC_t)(void*, sqlite3*, const char*, int);
|
|
|
|
sqlite3GlobalConfig.xSqllog = va_arg(ap, SQLLOGFUNC_t);
|
|
|
|
sqlite3GlobalConfig.pSqllogArg = va_arg(ap, void *);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2013-04-15 21:03:42 +04:00
|
|
|
case SQLITE_CONFIG_MMAP_SIZE: {
|
2014-11-04 20:23:24 +03:00
|
|
|
/* EVIDENCE-OF: R-58063-38258 SQLITE_CONFIG_MMAP_SIZE takes two 64-bit
|
|
|
|
** integer (sqlite3_int64) values that are the default mmap size limit
|
|
|
|
** (the default setting for PRAGMA mmap_size) and the maximum allowed
|
|
|
|
** mmap size limit. */
|
2013-04-15 21:03:42 +04:00
|
|
|
sqlite3_int64 szMmap = va_arg(ap, sqlite3_int64);
|
2013-04-02 02:38:06 +04:00
|
|
|
sqlite3_int64 mxMmap = va_arg(ap, sqlite3_int64);
|
2014-11-04 20:23:24 +03:00
|
|
|
/* EVIDENCE-OF: R-53367-43190 If either argument to this option is
|
2014-11-07 04:43:56 +03:00
|
|
|
** negative, then that argument is changed to its compile-time default.
|
|
|
|
**
|
|
|
|
** EVIDENCE-OF: R-34993-45031 The maximum allowed mmap size will be
|
|
|
|
** silently truncated if necessary so that it does not exceed the
|
|
|
|
** compile-time maximum mmap size set by the SQLITE_MAX_MMAP_SIZE
|
|
|
|
** compile-time option.
|
|
|
|
*/
|
2015-03-03 17:00:11 +03:00
|
|
|
if( mxMmap<0 || mxMmap>SQLITE_MAX_MMAP_SIZE ){
|
|
|
|
mxMmap = SQLITE_MAX_MMAP_SIZE;
|
|
|
|
}
|
2013-04-15 21:03:42 +04:00
|
|
|
if( szMmap<0 ) szMmap = SQLITE_DEFAULT_MMAP_SIZE;
|
|
|
|
if( szMmap>mxMmap) szMmap = mxMmap;
|
2014-11-04 20:23:24 +03:00
|
|
|
sqlite3GlobalConfig.mxMmap = mxMmap;
|
2013-04-15 21:03:42 +04:00
|
|
|
sqlite3GlobalConfig.szMmap = szMmap;
|
2013-04-02 02:38:06 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2014-11-04 20:23:24 +03:00
|
|
|
#if SQLITE_OS_WIN && defined(SQLITE_WIN32_MALLOC) /* IMP: R-04780-55815 */
|
2013-11-26 01:49:04 +04:00
|
|
|
case SQLITE_CONFIG_WIN32_HEAPSIZE: {
|
2014-11-04 20:23:24 +03:00
|
|
|
/* EVIDENCE-OF: R-34926-03360 SQLITE_CONFIG_WIN32_HEAPSIZE takes a 32-bit
|
|
|
|
** unsigned integer value that specifies the maximum size of the created
|
|
|
|
** heap. */
|
2013-11-23 04:27:29 +04:00
|
|
|
sqlite3GlobalConfig.nHeap = va_arg(ap, int);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2015-01-02 18:55:29 +03:00
|
|
|
case SQLITE_CONFIG_PMASZ: {
|
|
|
|
sqlite3GlobalConfig.szPma = va_arg(ap, unsigned int);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2016-03-07 20:37:37 +03:00
|
|
|
case SQLITE_CONFIG_STMTJRNL_SPILL: {
|
|
|
|
sqlite3GlobalConfig.nStmtSpill = va_arg(ap, int);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2018-04-17 00:12:42 +03:00
|
|
|
#ifdef SQLITE_ENABLE_SORTER_REFERENCES
|
2018-04-18 17:48:08 +03:00
|
|
|
case SQLITE_CONFIG_SORTERREF_SIZE: {
|
2018-04-17 00:12:42 +03:00
|
|
|
int iVal = va_arg(ap, int);
|
|
|
|
if( iVal<0 ){
|
|
|
|
iVal = SQLITE_DEFAULT_SORTERREF_SIZE;
|
|
|
|
}
|
|
|
|
sqlite3GlobalConfig.szSorterRef = (u32)iVal;
|
|
|
|
break;
|
|
|
|
}
|
2018-04-18 17:48:08 +03:00
|
|
|
#endif /* SQLITE_ENABLE_SORTER_REFERENCES */
|
2018-04-17 00:12:42 +03:00
|
|
|
|
2008-06-13 22:24:27 +04:00
|
|
|
default: {
|
|
|
|
rc = SQLITE_ERROR;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
va_end(ap);
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
2008-07-28 23:34:53 +04:00
|
|
|
/*
|
|
|
|
** Set up the lookaside buffers for a database connection.
|
|
|
|
** Return SQLITE_OK on success.
|
|
|
|
** If lookaside is already active, return SQLITE_BUSY.
|
2008-08-05 00:13:26 +04:00
|
|
|
**
|
|
|
|
** The sz parameter is the number of bytes in each lookaside slot.
|
|
|
|
** The cnt parameter is the number of slots. If pStart is NULL the
|
|
|
|
** space for the lookaside memory is obtained from sqlite3_malloc().
|
|
|
|
** If pStart is not NULL then it is sz*cnt bytes of memory to use for
|
|
|
|
** the lookaside memory.
|
2008-07-28 23:34:53 +04:00
|
|
|
*/
|
2008-08-05 00:13:26 +04:00
|
|
|
static int setupLookaside(sqlite3 *db, void *pBuf, int sz, int cnt){
|
2015-07-23 20:16:27 +03:00
|
|
|
#ifndef SQLITE_OMIT_LOOKASIDE
|
2008-07-28 23:34:53 +04:00
|
|
|
void *pStart;
|
2017-08-29 23:21:12 +03:00
|
|
|
|
|
|
|
if( sqlite3LookasideUsed(db,0)>0 ){
|
2008-07-28 23:34:53 +04:00
|
|
|
return SQLITE_BUSY;
|
|
|
|
}
|
2009-01-30 09:11:54 +03:00
|
|
|
/* Free any existing lookaside buffer for this handle before
|
|
|
|
** allocating a new one so we don't have to have space for
|
|
|
|
** both at the same time.
|
|
|
|
*/
|
|
|
|
if( db->lookaside.bMalloced ){
|
|
|
|
sqlite3_free(db->lookaside.pStart);
|
|
|
|
}
|
2011-11-10 06:39:28 +04:00
|
|
|
/* The size of a lookaside slot after ROUNDDOWN8 needs to be larger
|
|
|
|
** than a pointer to be useful.
|
2009-01-30 09:11:54 +03:00
|
|
|
*/
|
2011-11-10 06:39:28 +04:00
|
|
|
sz = ROUNDDOWN8(sz); /* IMP: R-33038-09382 */
|
2009-02-03 18:50:33 +03:00
|
|
|
if( sz<=(int)sizeof(LookasideSlot*) ) sz = 0;
|
2008-07-28 23:34:53 +04:00
|
|
|
if( cnt<0 ) cnt = 0;
|
2009-01-30 09:11:54 +03:00
|
|
|
if( sz==0 || cnt==0 ){
|
|
|
|
sz = 0;
|
|
|
|
pStart = 0;
|
|
|
|
}else if( pBuf==0 ){
|
2008-08-05 00:13:26 +04:00
|
|
|
sqlite3BeginBenignMalloc();
|
2010-09-03 07:32:46 +04:00
|
|
|
pStart = sqlite3Malloc( sz*cnt ); /* IMP: R-61949-35727 */
|
2008-08-05 00:13:26 +04:00
|
|
|
sqlite3EndBenignMalloc();
|
2011-11-10 06:24:11 +04:00
|
|
|
if( pStart ) cnt = sqlite3MallocSize(pStart)/sz;
|
2008-08-05 00:13:26 +04:00
|
|
|
}else{
|
|
|
|
pStart = pBuf;
|
|
|
|
}
|
2008-08-01 22:47:01 +04:00
|
|
|
db->lookaside.pStart = pStart;
|
2017-08-29 23:21:12 +03:00
|
|
|
db->lookaside.pInit = 0;
|
2008-08-01 22:47:01 +04:00
|
|
|
db->lookaside.pFree = 0;
|
2008-12-11 00:19:56 +03:00
|
|
|
db->lookaside.sz = (u16)sz;
|
2008-07-28 23:34:53 +04:00
|
|
|
if( pStart ){
|
|
|
|
int i;
|
|
|
|
LookasideSlot *p;
|
2009-04-02 21:22:41 +04:00
|
|
|
assert( sz > (int)sizeof(LookasideSlot*) );
|
2017-08-29 23:21:12 +03:00
|
|
|
db->lookaside.nSlot = cnt;
|
2008-07-28 23:34:53 +04:00
|
|
|
p = (LookasideSlot*)pStart;
|
|
|
|
for(i=cnt-1; i>=0; i--){
|
2017-08-29 23:21:12 +03:00
|
|
|
p->pNext = db->lookaside.pInit;
|
|
|
|
db->lookaside.pInit = p;
|
2008-07-28 23:34:53 +04:00
|
|
|
p = (LookasideSlot*)&((u8*)p)[sz];
|
|
|
|
}
|
|
|
|
db->lookaside.pEnd = p;
|
2016-02-05 04:55:27 +03:00
|
|
|
db->lookaside.bDisable = 0;
|
2009-01-30 09:11:54 +03:00
|
|
|
db->lookaside.bMalloced = pBuf==0 ?1:0;
|
2008-08-01 22:47:01 +04:00
|
|
|
}else{
|
2013-12-10 23:49:00 +04:00
|
|
|
db->lookaside.pStart = db;
|
|
|
|
db->lookaside.pEnd = db;
|
2016-02-05 04:55:27 +03:00
|
|
|
db->lookaside.bDisable = 1;
|
2009-01-30 09:11:54 +03:00
|
|
|
db->lookaside.bMalloced = 0;
|
2017-08-29 23:21:12 +03:00
|
|
|
db->lookaside.nSlot = 0;
|
2008-07-28 23:34:53 +04:00
|
|
|
}
|
2015-07-23 20:16:27 +03:00
|
|
|
#endif /* SQLITE_OMIT_LOOKASIDE */
|
2008-07-28 23:34:53 +04:00
|
|
|
return SQLITE_OK;
|
|
|
|
}
|
|
|
|
|
2008-11-04 16:46:27 +03:00
|
|
|
/*
|
|
|
|
** Return the mutex associated with a database connection.
|
|
|
|
*/
|
|
|
|
sqlite3_mutex *sqlite3_db_mutex(sqlite3 *db){
|
2014-10-24 04:35:58 +04:00
|
|
|
#ifdef SQLITE_ENABLE_API_ARMOR
|
|
|
|
if( !sqlite3SafetyCheckOk(db) ){
|
|
|
|
(void)SQLITE_MISUSE_BKPT;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#endif
|
2008-11-04 16:46:27 +03:00
|
|
|
return db->mutex;
|
|
|
|
}
|
|
|
|
|
2011-11-16 23:29:17 +04:00
|
|
|
/*
|
|
|
|
** Free up as much memory as we can from the given database
|
|
|
|
** connection.
|
|
|
|
*/
|
|
|
|
int sqlite3_db_release_memory(sqlite3 *db){
|
|
|
|
int i;
|
2014-10-24 04:35:58 +04:00
|
|
|
|
|
|
|
#ifdef SQLITE_ENABLE_API_ARMOR
|
|
|
|
if( !sqlite3SafetyCheckOk(db) ) return SQLITE_MISUSE_BKPT;
|
|
|
|
#endif
|
2011-12-30 15:43:59 +04:00
|
|
|
sqlite3_mutex_enter(db->mutex);
|
2011-11-16 23:29:17 +04:00
|
|
|
sqlite3BtreeEnterAll(db);
|
|
|
|
for(i=0; i<db->nDb; i++){
|
|
|
|
Btree *pBt = db->aDb[i].pBt;
|
|
|
|
if( pBt ){
|
|
|
|
Pager *pPager = sqlite3BtreePager(pBt);
|
|
|
|
sqlite3PagerShrink(pPager);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
sqlite3BtreeLeaveAll(db);
|
2011-12-30 15:43:59 +04:00
|
|
|
sqlite3_mutex_leave(db->mutex);
|
2011-11-16 23:29:17 +04:00
|
|
|
return SQLITE_OK;
|
|
|
|
}
|
|
|
|
|
2015-10-28 22:46:57 +03:00
|
|
|
/*
|
|
|
|
** Flush any dirty pages in the pager-cache for any attached database
|
|
|
|
** to disk.
|
|
|
|
*/
|
|
|
|
int sqlite3_db_cacheflush(sqlite3 *db){
|
|
|
|
int i;
|
|
|
|
int rc = SQLITE_OK;
|
|
|
|
int bSeenBusy = 0;
|
|
|
|
|
|
|
|
#ifdef SQLITE_ENABLE_API_ARMOR
|
|
|
|
if( !sqlite3SafetyCheckOk(db) ) return SQLITE_MISUSE_BKPT;
|
|
|
|
#endif
|
|
|
|
sqlite3_mutex_enter(db->mutex);
|
|
|
|
sqlite3BtreeEnterAll(db);
|
|
|
|
for(i=0; rc==SQLITE_OK && i<db->nDb; i++){
|
|
|
|
Btree *pBt = db->aDb[i].pBt;
|
|
|
|
if( pBt && sqlite3BtreeIsInTrans(pBt) ){
|
|
|
|
Pager *pPager = sqlite3BtreePager(pBt);
|
|
|
|
rc = sqlite3PagerFlush(pPager);
|
|
|
|
if( rc==SQLITE_BUSY ){
|
|
|
|
bSeenBusy = 1;
|
|
|
|
rc = SQLITE_OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
sqlite3BtreeLeaveAll(db);
|
|
|
|
sqlite3_mutex_leave(db->mutex);
|
|
|
|
return ((rc==SQLITE_OK && bSeenBusy) ? SQLITE_BUSY : rc);
|
|
|
|
}
|
|
|
|
|
2008-07-28 23:34:53 +04:00
|
|
|
/*
|
|
|
|
** Configuration settings for an individual database connection
|
|
|
|
*/
|
|
|
|
int sqlite3_db_config(sqlite3 *db, int op, ...){
|
|
|
|
va_list ap;
|
2008-08-01 20:31:14 +04:00
|
|
|
int rc;
|
2008-07-28 23:34:53 +04:00
|
|
|
va_start(ap, op);
|
|
|
|
switch( op ){
|
2016-08-19 01:44:22 +03:00
|
|
|
case SQLITE_DBCONFIG_MAINDBNAME: {
|
2017-07-14 22:47:32 +03:00
|
|
|
/* IMP: R-06824-28531 */
|
|
|
|
/* IMP: R-36257-52125 */
|
2016-08-19 01:44:22 +03:00
|
|
|
db->aDb[0].zDbSName = va_arg(ap,char*);
|
|
|
|
rc = SQLITE_OK;
|
|
|
|
break;
|
|
|
|
}
|
2008-08-05 00:13:26 +04:00
|
|
|
case SQLITE_DBCONFIG_LOOKASIDE: {
|
2011-04-07 05:14:12 +04:00
|
|
|
void *pBuf = va_arg(ap, void*); /* IMP: R-26835-10964 */
|
2010-09-03 07:32:46 +04:00
|
|
|
int sz = va_arg(ap, int); /* IMP: R-47871-25994 */
|
|
|
|
int cnt = va_arg(ap, int); /* IMP: R-04460-53386 */
|
2008-08-05 00:13:26 +04:00
|
|
|
rc = setupLookaside(db, pBuf, sz, cnt);
|
2008-07-28 23:34:53 +04:00
|
|
|
break;
|
|
|
|
}
|
2008-08-01 20:31:14 +04:00
|
|
|
default: {
|
2011-03-21 20:15:58 +03:00
|
|
|
static const struct {
|
|
|
|
int op; /* The opcode */
|
|
|
|
u32 mask; /* Mask of the bit in sqlite3.flags to set/clear */
|
|
|
|
} aFlagOp[] = {
|
2016-02-26 18:38:24 +03:00
|
|
|
{ SQLITE_DBCONFIG_ENABLE_FKEY, SQLITE_ForeignKeys },
|
|
|
|
{ SQLITE_DBCONFIG_ENABLE_TRIGGER, SQLITE_EnableTrigger },
|
|
|
|
{ SQLITE_DBCONFIG_ENABLE_FTS3_TOKENIZER, SQLITE_Fts3Tokenizer },
|
2016-04-21 04:30:09 +03:00
|
|
|
{ SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION, SQLITE_LoadExtension },
|
2016-10-31 19:16:49 +03:00
|
|
|
{ SQLITE_DBCONFIG_NO_CKPT_ON_CLOSE, SQLITE_NoCkptOnClose },
|
2017-06-26 16:57:49 +03:00
|
|
|
{ SQLITE_DBCONFIG_ENABLE_QPSG, SQLITE_EnableQPSG },
|
2017-12-21 21:23:26 +03:00
|
|
|
{ SQLITE_DBCONFIG_TRIGGER_EQP, SQLITE_TriggerEQP },
|
2018-04-28 15:43:16 +03:00
|
|
|
{ SQLITE_DBCONFIG_RESET_DATABASE, SQLITE_ResetDatabase },
|
2018-11-03 19:09:59 +03:00
|
|
|
{ SQLITE_DBCONFIG_DEFENSIVE, SQLITE_Defensive },
|
2011-03-21 20:15:58 +03:00
|
|
|
};
|
2011-03-24 01:02:23 +03:00
|
|
|
unsigned int i;
|
2010-09-03 07:32:46 +04:00
|
|
|
rc = SQLITE_ERROR; /* IMP: R-42790-23372 */
|
2011-03-21 20:15:58 +03:00
|
|
|
for(i=0; i<ArraySize(aFlagOp); i++){
|
|
|
|
if( aFlagOp[i].op==op ){
|
|
|
|
int onoff = va_arg(ap, int);
|
|
|
|
int *pRes = va_arg(ap, int*);
|
2018-12-06 19:50:55 +03:00
|
|
|
u64 oldFlags = db->flags;
|
2011-03-21 20:15:58 +03:00
|
|
|
if( onoff>0 ){
|
|
|
|
db->flags |= aFlagOp[i].mask;
|
|
|
|
}else if( onoff==0 ){
|
|
|
|
db->flags &= ~aFlagOp[i].mask;
|
|
|
|
}
|
|
|
|
if( oldFlags!=db->flags ){
|
2018-07-25 01:02:12 +03:00
|
|
|
sqlite3ExpirePreparedStatements(db, 0);
|
2011-03-21 20:15:58 +03:00
|
|
|
}
|
|
|
|
if( pRes ){
|
|
|
|
*pRes = (db->flags & aFlagOp[i].mask)!=0;
|
|
|
|
}
|
|
|
|
rc = SQLITE_OK;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2008-08-01 20:31:14 +04:00
|
|
|
break;
|
|
|
|
}
|
2008-07-28 23:34:53 +04:00
|
|
|
}
|
|
|
|
va_end(ap);
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
2007-03-30 15:29:32 +04:00
|
|
|
|
2008-01-21 02:19:56 +03:00
|
|
|
/*
|
|
|
|
** Return true if the buffer z[0..n-1] contains all spaces.
|
|
|
|
*/
|
|
|
|
static int allSpaces(const char *z, int n){
|
2008-04-15 08:02:40 +04:00
|
|
|
while( n>0 && z[n-1]==' ' ){ n--; }
|
2008-01-21 02:19:56 +03:00
|
|
|
return n==0;
|
|
|
|
}
|
|
|
|
|
2004-05-21 02:16:29 +04:00
|
|
|
/*
|
|
|
|
** This is the default collating function named "BINARY" which is always
|
|
|
|
** available.
|
2008-01-21 02:19:56 +03:00
|
|
|
**
|
|
|
|
** If the padFlag argument is not NULL then space padding at the end
|
|
|
|
** of strings is ignored. This implements the RTRIM collation.
|
2004-05-21 02:16:29 +04:00
|
|
|
*/
|
2005-01-13 05:14:23 +03:00
|
|
|
static int binCollFunc(
|
2008-01-21 02:19:56 +03:00
|
|
|
void *padFlag,
|
2004-05-21 02:16:29 +04:00
|
|
|
int nKey1, const void *pKey1,
|
|
|
|
int nKey2, const void *pKey2
|
|
|
|
){
|
|
|
|
int rc, n;
|
|
|
|
n = nKey1<nKey2 ? nKey1 : nKey2;
|
2014-11-20 22:22:26 +03:00
|
|
|
/* EVIDENCE-OF: R-65033-28449 The built-in BINARY collation compares
|
|
|
|
** strings byte by byte using the memcmp() function from the standard C
|
|
|
|
** library. */
|
2017-05-22 11:04:09 +03:00
|
|
|
assert( pKey1 && pKey2 );
|
2004-05-21 02:16:29 +04:00
|
|
|
rc = memcmp(pKey1, pKey2, n);
|
|
|
|
if( rc==0 ){
|
2008-01-21 02:19:56 +03:00
|
|
|
if( padFlag
|
|
|
|
&& allSpaces(((char*)pKey1)+n, nKey1-n)
|
|
|
|
&& allSpaces(((char*)pKey2)+n, nKey2-n)
|
|
|
|
){
|
2014-11-20 22:22:26 +03:00
|
|
|
/* EVIDENCE-OF: R-31624-24737 RTRIM is like BINARY except that extra
|
|
|
|
** spaces at the end of either string do not change the result. In other
|
|
|
|
** words, strings will compare equal to one another as long as they
|
|
|
|
** differ only in the number of spaces at the end.
|
|
|
|
*/
|
2008-01-21 02:19:56 +03:00
|
|
|
}else{
|
|
|
|
rc = nKey1 - nKey2;
|
|
|
|
}
|
2004-05-21 02:16:29 +04:00
|
|
|
}
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
2018-07-27 21:12:40 +03:00
|
|
|
/*
|
|
|
|
** Return true if CollSeq is the default built-in BINARY.
|
|
|
|
*/
|
|
|
|
int sqlite3IsBinary(const CollSeq *p){
|
|
|
|
assert( p==0 || p->xCmp!=binCollFunc || p->pUser!=0
|
|
|
|
|| strcmp(p->zName,"BINARY")==0 );
|
|
|
|
return p==0 || (p->xCmp==binCollFunc && p->pUser==0);
|
|
|
|
}
|
|
|
|
|
2004-06-09 13:55:16 +04:00
|
|
|
/*
|
2004-06-11 14:51:27 +04:00
|
|
|
** Another built-in collating sequence: NOCASE.
|
|
|
|
**
|
2013-05-28 16:11:54 +04:00
|
|
|
** This collating sequence is intended to be used for "case independent
|
2004-06-11 14:51:27 +04:00
|
|
|
** comparison". SQLite's knowledge of upper and lower case equivalents
|
|
|
|
** extends only to the 26 characters used in the English language.
|
|
|
|
**
|
|
|
|
** At the moment there is only a UTF-8 implementation.
|
2004-06-09 13:55:16 +04:00
|
|
|
*/
|
|
|
|
static int nocaseCollatingFunc(
|
|
|
|
void *NotUsed,
|
|
|
|
int nKey1, const void *pKey1,
|
|
|
|
int nKey2, const void *pKey2
|
|
|
|
){
|
|
|
|
int r = sqlite3StrNICmp(
|
2004-08-30 00:08:58 +04:00
|
|
|
(const char *)pKey1, (const char *)pKey2, (nKey1<nKey2)?nKey1:nKey2);
|
2008-11-19 12:05:26 +03:00
|
|
|
UNUSED_PARAMETER(NotUsed);
|
2004-06-09 13:55:16 +04:00
|
|
|
if( 0==r ){
|
|
|
|
r = nKey1-nKey2;
|
|
|
|
}
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
2002-01-17 00:00:27 +03:00
|
|
|
/*
|
|
|
|
** Return the ROWID of the most recent insert
|
|
|
|
*/
|
2004-09-06 21:24:11 +04:00
|
|
|
sqlite_int64 sqlite3_last_insert_rowid(sqlite3 *db){
|
2014-10-24 04:35:58 +04:00
|
|
|
#ifdef SQLITE_ENABLE_API_ARMOR
|
|
|
|
if( !sqlite3SafetyCheckOk(db) ){
|
|
|
|
(void)SQLITE_MISUSE_BKPT;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#endif
|
2002-01-17 00:00:27 +03:00
|
|
|
return db->lastRowid;
|
|
|
|
}
|
|
|
|
|
2017-02-27 17:52:48 +03:00
|
|
|
/*
|
|
|
|
** Set the value returned by the sqlite3_last_insert_rowid() API function.
|
|
|
|
*/
|
|
|
|
void sqlite3_set_last_insert_rowid(sqlite3 *db, sqlite3_int64 iRowid){
|
|
|
|
#ifdef SQLITE_ENABLE_API_ARMOR
|
|
|
|
if( !sqlite3SafetyCheckOk(db) ){
|
|
|
|
(void)SQLITE_MISUSE_BKPT;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
sqlite3_mutex_enter(db->mutex);
|
|
|
|
db->lastRowid = iRowid;
|
|
|
|
sqlite3_mutex_leave(db->mutex);
|
|
|
|
}
|
|
|
|
|
2002-04-12 14:08:59 +04:00
|
|
|
/*
|
2004-05-10 14:34:34 +04:00
|
|
|
** Return the number of changes in the most recent call to sqlite3_exec().
|
2002-04-12 14:08:59 +04:00
|
|
|
*/
|
2004-09-06 21:24:11 +04:00
|
|
|
int sqlite3_changes(sqlite3 *db){
|
2014-10-24 04:35:58 +04:00
|
|
|
#ifdef SQLITE_ENABLE_API_ARMOR
|
|
|
|
if( !sqlite3SafetyCheckOk(db) ){
|
|
|
|
(void)SQLITE_MISUSE_BKPT;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#endif
|
2002-04-12 14:08:59 +04:00
|
|
|
return db->nChange;
|
|
|
|
}
|
|
|
|
|
2004-02-26 01:51:06 +03:00
|
|
|
/*
|
2004-06-21 10:50:26 +04:00
|
|
|
** Return the number of changes since the database handle was opened.
|
2004-02-26 01:51:06 +03:00
|
|
|
*/
|
2004-06-21 10:50:26 +04:00
|
|
|
int sqlite3_total_changes(sqlite3 *db){
|
2014-10-24 04:35:58 +04:00
|
|
|
#ifdef SQLITE_ENABLE_API_ARMOR
|
|
|
|
if( !sqlite3SafetyCheckOk(db) ){
|
|
|
|
(void)SQLITE_MISUSE_BKPT;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#endif
|
2004-06-21 10:50:26 +04:00
|
|
|
return db->nTotalChange;
|
2004-02-21 01:53:38 +03:00
|
|
|
}
|
|
|
|
|
2008-12-17 20:30:26 +03:00
|
|
|
/*
|
|
|
|
** Close all open savepoints. This function only manipulates fields of the
|
|
|
|
** database handle object, it does not close any savepoints that may be open
|
|
|
|
** at the b-tree/pager level.
|
|
|
|
*/
|
|
|
|
void sqlite3CloseSavepoints(sqlite3 *db){
|
|
|
|
while( db->pSavepoint ){
|
|
|
|
Savepoint *pTmp = db->pSavepoint;
|
|
|
|
db->pSavepoint = pTmp->pNext;
|
|
|
|
sqlite3DbFree(db, pTmp);
|
|
|
|
}
|
|
|
|
db->nSavepoint = 0;
|
2009-03-18 13:33:00 +03:00
|
|
|
db->nStatement = 0;
|
2008-12-17 20:30:26 +03:00
|
|
|
db->isTransactionSavepoint = 0;
|
|
|
|
}
|
|
|
|
|
2010-08-27 21:48:52 +04:00
|
|
|
/*
|
|
|
|
** Invoke the destructor function associated with FuncDef p, if any. Except,
|
|
|
|
** if this is not the last copy of the function, do not invoke it. Multiple
|
|
|
|
** copies of a single function are created when create_function() is called
|
|
|
|
** with SQLITE_ANY as the encoding.
|
|
|
|
*/
|
|
|
|
static void functionDestroy(sqlite3 *db, FuncDef *p){
|
2016-02-15 03:34:16 +03:00
|
|
|
FuncDestructor *pDestructor = p->u.pDestructor;
|
2010-08-27 21:48:52 +04:00
|
|
|
if( pDestructor ){
|
|
|
|
pDestructor->nRef--;
|
|
|
|
if( pDestructor->nRef==0 ){
|
|
|
|
pDestructor->xDestroy(pDestructor->pUserData);
|
|
|
|
sqlite3DbFree(db, pDestructor);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-05-15 21:15:34 +04:00
|
|
|
/*
|
|
|
|
** Disconnect all sqlite3_vtab objects that belong to database connection
|
|
|
|
** db. This is called when db is being closed.
|
|
|
|
*/
|
|
|
|
static void disconnectAllVtab(sqlite3 *db){
|
|
|
|
#ifndef SQLITE_OMIT_VIRTUALTABLE
|
|
|
|
int i;
|
2015-08-19 05:32:25 +03:00
|
|
|
HashElem *p;
|
2012-05-15 21:15:34 +04:00
|
|
|
sqlite3BtreeEnterAll(db);
|
|
|
|
for(i=0; i<db->nDb; i++){
|
|
|
|
Schema *pSchema = db->aDb[i].pSchema;
|
2018-08-08 23:46:35 +03:00
|
|
|
if( pSchema ){
|
2012-05-15 21:15:34 +04:00
|
|
|
for(p=sqliteHashFirst(&pSchema->tblHash); p; p=sqliteHashNext(p)){
|
|
|
|
Table *pTab = (Table *)sqliteHashData(p);
|
|
|
|
if( IsVirtual(pTab) ) sqlite3VtabDisconnect(db, pTab);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-08-19 05:32:25 +03:00
|
|
|
for(p=sqliteHashFirst(&db->aModule); p; p=sqliteHashNext(p)){
|
|
|
|
Module *pMod = (Module *)sqliteHashData(p);
|
|
|
|
if( pMod->pEpoTab ){
|
|
|
|
sqlite3VtabDisconnect(db, pMod->pEpoTab);
|
|
|
|
}
|
|
|
|
}
|
2014-03-12 23:38:38 +04:00
|
|
|
sqlite3VtabUnlockList(db);
|
2012-05-15 21:15:34 +04:00
|
|
|
sqlite3BtreeLeaveAll(db);
|
|
|
|
#else
|
|
|
|
UNUSED_PARAMETER(db);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2001-09-15 04:57:28 +04:00
|
|
|
/*
|
2012-06-02 21:09:46 +04:00
|
|
|
** Return TRUE if database connection db has unfinalized prepared
|
|
|
|
** statements or unfinished sqlite3_backup objects.
|
2001-09-15 04:57:28 +04:00
|
|
|
*/
|
2012-06-02 21:09:46 +04:00
|
|
|
static int connectionIsBusy(sqlite3 *db){
|
2003-03-19 06:14:00 +03:00
|
|
|
int j;
|
2012-06-02 21:09:46 +04:00
|
|
|
assert( sqlite3_mutex_held(db->mutex) );
|
|
|
|
if( db->pVdbe ) return 1;
|
|
|
|
for(j=0; j<db->nDb; j++){
|
|
|
|
Btree *pBt = db->aDb[j].pBt;
|
|
|
|
if( pBt && sqlite3BtreeIsInBackup(pBt) ) return 1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
2004-06-16 14:39:23 +04:00
|
|
|
|
2001-09-15 04:57:28 +04:00
|
|
|
/*
|
|
|
|
** Close an existing SQLite database
|
|
|
|
*/
|
2012-06-02 21:09:46 +04:00
|
|
|
static int sqlite3Close(sqlite3 *db, int forceZombie){
|
2004-06-16 14:39:23 +04:00
|
|
|
if( !db ){
|
2014-08-11 19:54:11 +04:00
|
|
|
/* EVIDENCE-OF: R-63257-11740 Calling sqlite3_close() or
|
|
|
|
** sqlite3_close_v2() with a NULL pointer argument is a harmless no-op. */
|
2004-06-19 07:33:57 +04:00
|
|
|
return SQLITE_OK;
|
2004-06-16 14:39:23 +04:00
|
|
|
}
|
2008-01-23 06:03:05 +03:00
|
|
|
if( !sqlite3SafetyCheckSickOrOk(db) ){
|
2010-02-23 23:11:56 +03:00
|
|
|
return SQLITE_MISUSE_BKPT;
|
2004-06-26 13:50:11 +04:00
|
|
|
}
|
2007-08-21 19:13:19 +04:00
|
|
|
sqlite3_mutex_enter(db->mutex);
|
2016-07-14 01:55:01 +03:00
|
|
|
if( db->mTrace & SQLITE_TRACE_CLOSE ){
|
|
|
|
db->xTrace(SQLITE_TRACE_CLOSE, db->pTraceArg, db, 0);
|
|
|
|
}
|
2004-06-26 13:50:11 +04:00
|
|
|
|
2012-05-15 21:15:34 +04:00
|
|
|
/* Force xDisconnect calls on all virtual tables */
|
|
|
|
disconnectAllVtab(db);
|
2007-04-16 19:06:25 +04:00
|
|
|
|
2012-05-15 21:15:34 +04:00
|
|
|
/* If a transaction is open, the disconnectAllVtab() call above
|
2007-04-18 18:24:32 +04:00
|
|
|
** will not have called the xDisconnect() method on any virtual
|
|
|
|
** tables in the db->aVTrans[] array. The following sqlite3VtabRollback()
|
|
|
|
** call will do so. We need to do this before the check for active
|
|
|
|
** SQL statements below, as the v-table implementation may be storing
|
|
|
|
** some prepared statements internally.
|
|
|
|
*/
|
2013-05-15 14:21:50 +04:00
|
|
|
sqlite3VtabRollback(db);
|
2007-04-18 18:24:32 +04:00
|
|
|
|
2012-06-02 21:09:46 +04:00
|
|
|
/* Legacy behavior (sqlite3_close() behavior) is to return
|
|
|
|
** SQLITE_BUSY if the connection can not be closed immediately.
|
|
|
|
*/
|
|
|
|
if( !forceZombie && connectionIsBusy(db) ){
|
2014-08-22 22:00:11 +04:00
|
|
|
sqlite3ErrorWithMsg(db, SQLITE_BUSY, "unable to close due to unfinalized "
|
2012-06-02 21:09:46 +04:00
|
|
|
"statements or unfinished backups");
|
2007-08-22 06:56:42 +04:00
|
|
|
sqlite3_mutex_leave(db->mutex);
|
2004-06-19 07:33:57 +04:00
|
|
|
return SQLITE_BUSY;
|
|
|
|
}
|
2004-06-15 20:51:01 +04:00
|
|
|
|
2012-11-26 23:50:41 +04:00
|
|
|
#ifdef SQLITE_ENABLE_SQLLOG
|
|
|
|
if( sqlite3GlobalConfig.xSqllog ){
|
2012-11-27 14:56:39 +04:00
|
|
|
/* Closing the handle. Fourth parameter is passed the value 2. */
|
|
|
|
sqlite3GlobalConfig.xSqllog(sqlite3GlobalConfig.pSqllogArg, db, 0, 2);
|
2012-11-26 23:50:41 +04:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2012-06-02 21:09:46 +04:00
|
|
|
/* Convert the connection into a zombie and then close it.
|
2012-06-02 18:32:21 +04:00
|
|
|
*/
|
|
|
|
db->magic = SQLITE_MAGIC_ZOMBIE;
|
|
|
|
sqlite3LeaveMutexAndCloseZombie(db);
|
|
|
|
return SQLITE_OK;
|
|
|
|
}
|
|
|
|
|
2012-06-02 21:09:46 +04:00
|
|
|
/*
|
|
|
|
** Two variations on the public interface for closing a database
|
|
|
|
** connection. The sqlite3_close() version returns SQLITE_BUSY and
|
|
|
|
** leaves the connection option if there are unfinalized prepared
|
|
|
|
** statements or unfinished sqlite3_backups. The sqlite3_close_v2()
|
|
|
|
** version forces the connection to become a zombie if there are
|
|
|
|
** unclosed resources, and arranges for deallocation when the last
|
|
|
|
** prepare statement or sqlite3_backup closes.
|
|
|
|
*/
|
|
|
|
int sqlite3_close(sqlite3 *db){ return sqlite3Close(db,0); }
|
|
|
|
int sqlite3_close_v2(sqlite3 *db){ return sqlite3Close(db,1); }
|
|
|
|
|
2012-06-02 18:32:21 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
** Close the mutex on database connection db.
|
|
|
|
**
|
|
|
|
** Furthermore, if database connection db is a zombie (meaning that there
|
2012-06-02 21:09:46 +04:00
|
|
|
** has been a prior call to sqlite3_close(db) or sqlite3_close_v2(db)) and
|
|
|
|
** every sqlite3_stmt has now been finalized and every sqlite3_backup has
|
|
|
|
** finished, then free all resources.
|
2012-06-02 18:32:21 +04:00
|
|
|
*/
|
|
|
|
void sqlite3LeaveMutexAndCloseZombie(sqlite3 *db){
|
|
|
|
HashElem *i; /* Hash table iterator */
|
|
|
|
int j;
|
|
|
|
|
|
|
|
/* If there are outstanding sqlite3_stmt or sqlite3_backup objects
|
2012-06-02 21:09:46 +04:00
|
|
|
** or if the connection has not yet been closed by sqlite3_close_v2(),
|
|
|
|
** then just leave the mutex and return.
|
2012-06-02 18:32:21 +04:00
|
|
|
*/
|
2012-06-02 21:09:46 +04:00
|
|
|
if( db->magic!=SQLITE_MAGIC_ZOMBIE || connectionIsBusy(db) ){
|
2007-08-22 06:56:42 +04:00
|
|
|
sqlite3_mutex_leave(db->mutex);
|
2012-06-02 18:32:21 +04:00
|
|
|
return;
|
2009-02-03 19:51:24 +03:00
|
|
|
}
|
|
|
|
|
2012-06-02 18:32:21 +04:00
|
|
|
/* If we reach this point, it means that the database connection has
|
|
|
|
** closed all sqlite3_stmt and sqlite3_backup objects and has been
|
2013-03-22 01:20:32 +04:00
|
|
|
** passed to sqlite3_close (meaning that it is a zombie). Therefore,
|
2012-06-02 18:32:21 +04:00
|
|
|
** go ahead and free all resources.
|
|
|
|
*/
|
|
|
|
|
2013-05-16 15:57:28 +04:00
|
|
|
/* If a transaction is open, roll it back. This also ensures that if
|
|
|
|
** any database schemas have been modified by an uncommitted transaction
|
|
|
|
** they are reset. And that the required b-tree mutex is held to make
|
|
|
|
** the pager rollback and schema reset an atomic operation. */
|
|
|
|
sqlite3RollbackAll(db, SQLITE_OK);
|
|
|
|
|
2008-12-17 20:30:26 +03:00
|
|
|
/* Free any outstanding Savepoint structures. */
|
|
|
|
sqlite3CloseSavepoints(db);
|
|
|
|
|
2012-05-16 05:24:34 +04:00
|
|
|
/* Close all database connections */
|
2003-03-19 06:14:00 +03:00
|
|
|
for(j=0; j<db->nDb; j++){
|
2004-02-12 21:46:38 +03:00
|
|
|
struct Db *pDb = &db->aDb[j];
|
|
|
|
if( pDb->pBt ){
|
2014-12-05 18:31:33 +03:00
|
|
|
sqlite3BtreeClose(pDb->pBt);
|
|
|
|
pDb->pBt = 0;
|
|
|
|
if( j!=1 ){
|
2006-01-10 10:14:23 +03:00
|
|
|
pDb->pSchema = 0;
|
|
|
|
}
|
2003-03-20 04:16:58 +03:00
|
|
|
}
|
2001-10-08 17:22:32 +04:00
|
|
|
}
|
2012-05-16 05:24:34 +04:00
|
|
|
/* Clear the TEMP schema separately and last */
|
|
|
|
if( db->aDb[1].pSchema ){
|
|
|
|
sqlite3SchemaClear(db->aDb[1].pSchema);
|
|
|
|
}
|
|
|
|
sqlite3VtabUnlockList(db);
|
2012-05-15 21:15:34 +04:00
|
|
|
|
2012-05-16 05:24:34 +04:00
|
|
|
/* Free up the array of auxiliary databases */
|
|
|
|
sqlite3CollapseDatabaseArray(db);
|
2012-05-15 21:15:34 +04:00
|
|
|
assert( db->nDb<=2 );
|
|
|
|
assert( db->aDb==db->aDbStatic );
|
2009-03-16 16:19:36 +03:00
|
|
|
|
|
|
|
/* Tell the code in notify.c that the connection no longer holds any
|
|
|
|
** locks and does not require any further unlock-notify callbacks.
|
|
|
|
*/
|
|
|
|
sqlite3ConnectionClosed(db);
|
|
|
|
|
2016-02-15 03:34:16 +03:00
|
|
|
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);
|
2004-06-12 13:25:12 +04:00
|
|
|
for(i=sqliteHashFirst(&db->aCollSeq); i; i=sqliteHashNext(i)){
|
2004-06-10 06:16:01 +04:00
|
|
|
CollSeq *pColl = (CollSeq *)sqliteHashData(i);
|
2007-05-07 13:32:45 +04:00
|
|
|
/* Invoke any destructors registered for collation sequence user data. */
|
|
|
|
for(j=0; j<3; j++){
|
|
|
|
if( pColl[j].xDel ){
|
|
|
|
pColl[j].xDel(pColl[j].pUser);
|
|
|
|
}
|
|
|
|
}
|
2008-07-28 23:34:53 +04:00
|
|
|
sqlite3DbFree(db, pColl);
|
2004-06-10 06:16:01 +04:00
|
|
|
}
|
2004-06-12 13:25:12 +04:00
|
|
|
sqlite3HashClear(&db->aCollSeq);
|
2006-06-12 03:41:55 +04:00
|
|
|
#ifndef SQLITE_OMIT_VIRTUALTABLE
|
2006-06-15 08:28:13 +04:00
|
|
|
for(i=sqliteHashFirst(&db->aModule); i; i=sqliteHashNext(i)){
|
|
|
|
Module *pMod = (Module *)sqliteHashData(i);
|
2007-06-22 19:21:15 +04:00
|
|
|
if( pMod->xDestroy ){
|
|
|
|
pMod->xDestroy(pMod->pAux);
|
|
|
|
}
|
2015-08-19 05:32:25 +03:00
|
|
|
sqlite3VtabEponymousTableClear(db, pMod);
|
2008-07-28 23:34:53 +04:00
|
|
|
sqlite3DbFree(db, pMod);
|
2006-06-15 08:28:13 +04:00
|
|
|
}
|
2006-06-12 03:41:55 +04:00
|
|
|
sqlite3HashClear(&db->aModule);
|
|
|
|
#endif
|
2004-06-10 06:16:01 +04:00
|
|
|
|
2014-08-22 22:00:11 +04:00
|
|
|
sqlite3Error(db, SQLITE_OK); /* Deallocates any cached error strings. */
|
2013-12-13 20:23:55 +04:00
|
|
|
sqlite3ValueFree(db->pErr);
|
2006-06-08 19:48:00 +04:00
|
|
|
sqlite3CloseExtensions(db);
|
2014-09-09 18:47:53 +04:00
|
|
|
#if SQLITE_USER_AUTHENTICATION
|
|
|
|
sqlite3_free(db->auth.zAuthUser);
|
|
|
|
sqlite3_free(db->auth.zAuthPW);
|
|
|
|
#endif
|
2004-06-19 07:33:57 +04:00
|
|
|
|
|
|
|
db->magic = SQLITE_MAGIC_ERROR;
|
2006-01-10 10:14:23 +03:00
|
|
|
|
|
|
|
/* The temp-database schema is allocated differently from the other schema
|
|
|
|
** objects (using sqliteMalloc() directly, instead of sqlite3BtreeSchema()).
|
|
|
|
** So it needs to be freed here. Todo: Why not roll the temp schema into
|
|
|
|
** the same sqliteMalloc() as the one that allocates the database
|
|
|
|
** structure?
|
|
|
|
*/
|
2008-07-28 23:34:53 +04:00
|
|
|
sqlite3DbFree(db, db->aDb[1].pSchema);
|
2007-08-21 19:13:19 +04:00
|
|
|
sqlite3_mutex_leave(db->mutex);
|
2008-01-23 06:03:05 +03:00
|
|
|
db->magic = SQLITE_MAGIC_CLOSED;
|
2007-08-21 19:13:19 +04:00
|
|
|
sqlite3_mutex_free(db->mutex);
|
2017-08-29 23:21:12 +03:00
|
|
|
assert( sqlite3LookasideUsed(db,0)==0 );
|
2008-08-05 00:13:26 +04:00
|
|
|
if( db->lookaside.bMalloced ){
|
|
|
|
sqlite3_free(db->lookaside.pStart);
|
|
|
|
}
|
2007-08-16 08:30:38 +04:00
|
|
|
sqlite3_free(db);
|
2000-05-29 18:26:00 +04:00
|
|
|
}
|
|
|
|
|
2003-03-19 06:14:00 +03:00
|
|
|
/*
|
2012-02-13 20:43:16 +04:00
|
|
|
** Rollback all database files. If tripCode is not SQLITE_OK, then
|
2014-11-11 04:33:57 +03:00
|
|
|
** any write cursors are invalidated ("tripped" - as in "tripping a circuit
|
2012-02-13 20:43:16 +04:00
|
|
|
** breaker") and made to return tripCode if there are any further
|
2014-11-11 04:33:57 +03:00
|
|
|
** attempts to use that cursor. Read cursors remain open and valid
|
|
|
|
** but are "saved" in case the table pages are moved around.
|
2003-03-19 06:14:00 +03:00
|
|
|
*/
|
2012-02-13 20:43:16 +04:00
|
|
|
void sqlite3RollbackAll(sqlite3 *db, int tripCode){
|
2003-03-19 06:14:00 +03:00
|
|
|
int i;
|
2005-12-16 18:24:28 +03:00
|
|
|
int inTrans = 0;
|
2014-11-11 04:33:57 +03:00
|
|
|
int schemaChange;
|
2007-08-21 20:15:55 +04:00
|
|
|
assert( sqlite3_mutex_held(db->mutex) );
|
2008-06-20 18:59:51 +04:00
|
|
|
sqlite3BeginBenignMalloc();
|
2013-05-16 15:57:28 +04:00
|
|
|
|
|
|
|
/* Obtain all b-tree mutexes before making any calls to BtreeRollback().
|
|
|
|
** This is important in case the transaction being rolled back has
|
|
|
|
** modified the database schema. If the b-tree mutexes are not taken
|
|
|
|
** here, then another shared-cache connection might sneak in between
|
|
|
|
** the database rollback and schema reset, which can cause false
|
|
|
|
** corruption reports in some cases. */
|
2013-05-13 22:23:15 +04:00
|
|
|
sqlite3BtreeEnterAll(db);
|
2017-07-26 22:59:13 +03:00
|
|
|
schemaChange = (db->mDbFlags & DBFLAG_SchemaChange)!=0 && db->init.busy==0;
|
2013-05-16 15:57:28 +04:00
|
|
|
|
2003-03-19 06:14:00 +03:00
|
|
|
for(i=0; i<db->nDb; i++){
|
2012-02-13 20:43:16 +04:00
|
|
|
Btree *p = db->aDb[i].pBt;
|
|
|
|
if( p ){
|
|
|
|
if( sqlite3BtreeIsInTrans(p) ){
|
2005-12-16 18:24:28 +03:00
|
|
|
inTrans = 1;
|
|
|
|
}
|
2014-11-11 04:33:57 +03:00
|
|
|
sqlite3BtreeRollback(p, tripCode, !schemaChange);
|
2003-03-19 06:14:00 +03:00
|
|
|
}
|
|
|
|
}
|
2006-06-22 13:53:48 +04:00
|
|
|
sqlite3VtabRollback(db);
|
2008-06-20 18:59:51 +04:00
|
|
|
sqlite3EndBenignMalloc();
|
2007-10-03 12:46:44 +04:00
|
|
|
|
2018-07-16 14:32:59 +03:00
|
|
|
if( schemaChange ){
|
2018-07-25 01:02:12 +03:00
|
|
|
sqlite3ExpirePreparedStatements(db, 0);
|
2012-05-15 22:28:27 +04:00
|
|
|
sqlite3ResetAllSchemasOfConnection(db);
|
2005-12-16 09:54:01 +03:00
|
|
|
}
|
2013-05-13 22:23:15 +04:00
|
|
|
sqlite3BtreeLeaveAll(db);
|
2005-12-16 09:54:01 +03:00
|
|
|
|
2009-09-19 21:00:31 +04:00
|
|
|
/* Any deferred constraint violations have now been resolved. */
|
|
|
|
db->nDeferredCons = 0;
|
2013-07-11 19:03:32 +04:00
|
|
|
db->nDeferredImmCons = 0;
|
|
|
|
db->flags &= ~SQLITE_DeferFKs;
|
2009-09-19 21:00:31 +04:00
|
|
|
|
2005-12-16 09:54:01 +03:00
|
|
|
/* If one has been configured, invoke the rollback-hook callback */
|
2005-12-16 18:24:28 +03:00
|
|
|
if( db->xRollbackCallback && (inTrans || !db->autoCommit) ){
|
2005-12-16 09:54:01 +03:00
|
|
|
db->xRollbackCallback(db->pRollbackArg);
|
|
|
|
}
|
2003-03-19 06:14:00 +03:00
|
|
|
}
|
|
|
|
|
2013-04-28 05:44:43 +04:00
|
|
|
/*
|
|
|
|
** Return a static string containing the name corresponding to the error code
|
|
|
|
** specified in the argument.
|
|
|
|
*/
|
2015-04-29 02:34:10 +03:00
|
|
|
#if defined(SQLITE_NEED_ERR_NAME)
|
2013-04-28 05:44:43 +04:00
|
|
|
const char *sqlite3ErrName(int rc){
|
|
|
|
const char *zName = 0;
|
2013-04-30 11:54:42 +04:00
|
|
|
int i, origRc = rc;
|
2013-04-28 05:44:43 +04:00
|
|
|
for(i=0; i<2 && zName==0; i++, rc &= 0xff){
|
|
|
|
switch( rc ){
|
|
|
|
case SQLITE_OK: zName = "SQLITE_OK"; break;
|
|
|
|
case SQLITE_ERROR: zName = "SQLITE_ERROR"; break;
|
2018-08-31 22:00:16 +03:00
|
|
|
case SQLITE_ERROR_SNAPSHOT: zName = "SQLITE_ERROR_SNAPSHOT"; break;
|
2013-04-28 05:44:43 +04:00
|
|
|
case SQLITE_INTERNAL: zName = "SQLITE_INTERNAL"; break;
|
|
|
|
case SQLITE_PERM: zName = "SQLITE_PERM"; break;
|
|
|
|
case SQLITE_ABORT: zName = "SQLITE_ABORT"; break;
|
2013-04-29 07:09:10 +04:00
|
|
|
case SQLITE_ABORT_ROLLBACK: zName = "SQLITE_ABORT_ROLLBACK"; break;
|
2013-04-28 05:44:43 +04:00
|
|
|
case SQLITE_BUSY: zName = "SQLITE_BUSY"; break;
|
2013-04-29 07:09:10 +04:00
|
|
|
case SQLITE_BUSY_RECOVERY: zName = "SQLITE_BUSY_RECOVERY"; break;
|
2013-06-27 15:46:27 +04:00
|
|
|
case SQLITE_BUSY_SNAPSHOT: zName = "SQLITE_BUSY_SNAPSHOT"; break;
|
2013-04-28 05:44:43 +04:00
|
|
|
case SQLITE_LOCKED: zName = "SQLITE_LOCKED"; break;
|
|
|
|
case SQLITE_LOCKED_SHAREDCACHE: zName = "SQLITE_LOCKED_SHAREDCACHE";break;
|
|
|
|
case SQLITE_NOMEM: zName = "SQLITE_NOMEM"; break;
|
|
|
|
case SQLITE_READONLY: zName = "SQLITE_READONLY"; break;
|
2013-04-29 07:09:10 +04:00
|
|
|
case SQLITE_READONLY_RECOVERY: zName = "SQLITE_READONLY_RECOVERY"; break;
|
2017-11-08 20:32:12 +03:00
|
|
|
case SQLITE_READONLY_CANTINIT: zName = "SQLITE_READONLY_CANTINIT"; break;
|
2013-04-29 07:09:10 +04:00
|
|
|
case SQLITE_READONLY_ROLLBACK: zName = "SQLITE_READONLY_ROLLBACK"; break;
|
2013-12-06 23:58:32 +04:00
|
|
|
case SQLITE_READONLY_DBMOVED: zName = "SQLITE_READONLY_DBMOVED"; break;
|
2018-01-10 14:56:03 +03:00
|
|
|
case SQLITE_READONLY_DIRECTORY: zName = "SQLITE_READONLY_DIRECTORY";break;
|
2013-04-28 05:44:43 +04:00
|
|
|
case SQLITE_INTERRUPT: zName = "SQLITE_INTERRUPT"; break;
|
|
|
|
case SQLITE_IOERR: zName = "SQLITE_IOERR"; break;
|
2013-04-29 07:09:10 +04:00
|
|
|
case SQLITE_IOERR_READ: zName = "SQLITE_IOERR_READ"; break;
|
|
|
|
case SQLITE_IOERR_SHORT_READ: zName = "SQLITE_IOERR_SHORT_READ"; break;
|
|
|
|
case SQLITE_IOERR_WRITE: zName = "SQLITE_IOERR_WRITE"; break;
|
|
|
|
case SQLITE_IOERR_FSYNC: zName = "SQLITE_IOERR_FSYNC"; break;
|
|
|
|
case SQLITE_IOERR_DIR_FSYNC: zName = "SQLITE_IOERR_DIR_FSYNC"; break;
|
|
|
|
case SQLITE_IOERR_TRUNCATE: zName = "SQLITE_IOERR_TRUNCATE"; break;
|
|
|
|
case SQLITE_IOERR_FSTAT: zName = "SQLITE_IOERR_FSTAT"; break;
|
|
|
|
case SQLITE_IOERR_UNLOCK: zName = "SQLITE_IOERR_UNLOCK"; break;
|
|
|
|
case SQLITE_IOERR_RDLOCK: zName = "SQLITE_IOERR_RDLOCK"; break;
|
|
|
|
case SQLITE_IOERR_DELETE: zName = "SQLITE_IOERR_DELETE"; break;
|
|
|
|
case SQLITE_IOERR_NOMEM: zName = "SQLITE_IOERR_NOMEM"; break;
|
|
|
|
case SQLITE_IOERR_ACCESS: zName = "SQLITE_IOERR_ACCESS"; break;
|
|
|
|
case SQLITE_IOERR_CHECKRESERVEDLOCK:
|
|
|
|
zName = "SQLITE_IOERR_CHECKRESERVEDLOCK"; break;
|
|
|
|
case SQLITE_IOERR_LOCK: zName = "SQLITE_IOERR_LOCK"; break;
|
|
|
|
case SQLITE_IOERR_CLOSE: zName = "SQLITE_IOERR_CLOSE"; break;
|
|
|
|
case SQLITE_IOERR_DIR_CLOSE: zName = "SQLITE_IOERR_DIR_CLOSE"; break;
|
|
|
|
case SQLITE_IOERR_SHMOPEN: zName = "SQLITE_IOERR_SHMOPEN"; break;
|
|
|
|
case SQLITE_IOERR_SHMSIZE: zName = "SQLITE_IOERR_SHMSIZE"; break;
|
|
|
|
case SQLITE_IOERR_SHMLOCK: zName = "SQLITE_IOERR_SHMLOCK"; break;
|
|
|
|
case SQLITE_IOERR_SHMMAP: zName = "SQLITE_IOERR_SHMMAP"; break;
|
|
|
|
case SQLITE_IOERR_SEEK: zName = "SQLITE_IOERR_SEEK"; break;
|
|
|
|
case SQLITE_IOERR_DELETE_NOENT: zName = "SQLITE_IOERR_DELETE_NOENT";break;
|
|
|
|
case SQLITE_IOERR_MMAP: zName = "SQLITE_IOERR_MMAP"; break;
|
2013-08-01 02:27:16 +04:00
|
|
|
case SQLITE_IOERR_GETTEMPPATH: zName = "SQLITE_IOERR_GETTEMPPATH"; break;
|
2013-08-31 01:52:38 +04:00
|
|
|
case SQLITE_IOERR_CONVPATH: zName = "SQLITE_IOERR_CONVPATH"; break;
|
2013-04-28 05:44:43 +04:00
|
|
|
case SQLITE_CORRUPT: zName = "SQLITE_CORRUPT"; break;
|
2013-04-29 07:09:10 +04:00
|
|
|
case SQLITE_CORRUPT_VTAB: zName = "SQLITE_CORRUPT_VTAB"; break;
|
2013-04-28 05:44:43 +04:00
|
|
|
case SQLITE_NOTFOUND: zName = "SQLITE_NOTFOUND"; break;
|
|
|
|
case SQLITE_FULL: zName = "SQLITE_FULL"; break;
|
|
|
|
case SQLITE_CANTOPEN: zName = "SQLITE_CANTOPEN"; break;
|
2013-04-29 07:09:10 +04:00
|
|
|
case SQLITE_CANTOPEN_NOTEMPDIR: zName = "SQLITE_CANTOPEN_NOTEMPDIR";break;
|
|
|
|
case SQLITE_CANTOPEN_ISDIR: zName = "SQLITE_CANTOPEN_ISDIR"; break;
|
|
|
|
case SQLITE_CANTOPEN_FULLPATH: zName = "SQLITE_CANTOPEN_FULLPATH"; break;
|
2013-08-31 01:52:38 +04:00
|
|
|
case SQLITE_CANTOPEN_CONVPATH: zName = "SQLITE_CANTOPEN_CONVPATH"; break;
|
2013-04-28 05:44:43 +04:00
|
|
|
case SQLITE_PROTOCOL: zName = "SQLITE_PROTOCOL"; break;
|
|
|
|
case SQLITE_EMPTY: zName = "SQLITE_EMPTY"; break;
|
|
|
|
case SQLITE_SCHEMA: zName = "SQLITE_SCHEMA"; break;
|
|
|
|
case SQLITE_TOOBIG: zName = "SQLITE_TOOBIG"; break;
|
|
|
|
case SQLITE_CONSTRAINT: zName = "SQLITE_CONSTRAINT"; break;
|
|
|
|
case SQLITE_CONSTRAINT_UNIQUE: zName = "SQLITE_CONSTRAINT_UNIQUE"; break;
|
|
|
|
case SQLITE_CONSTRAINT_TRIGGER: zName = "SQLITE_CONSTRAINT_TRIGGER";break;
|
|
|
|
case SQLITE_CONSTRAINT_FOREIGNKEY:
|
|
|
|
zName = "SQLITE_CONSTRAINT_FOREIGNKEY"; break;
|
|
|
|
case SQLITE_CONSTRAINT_CHECK: zName = "SQLITE_CONSTRAINT_CHECK"; break;
|
|
|
|
case SQLITE_CONSTRAINT_PRIMARYKEY:
|
|
|
|
zName = "SQLITE_CONSTRAINT_PRIMARYKEY"; break;
|
|
|
|
case SQLITE_CONSTRAINT_NOTNULL: zName = "SQLITE_CONSTRAINT_NOTNULL";break;
|
|
|
|
case SQLITE_CONSTRAINT_COMMITHOOK:
|
|
|
|
zName = "SQLITE_CONSTRAINT_COMMITHOOK"; break;
|
|
|
|
case SQLITE_CONSTRAINT_VTAB: zName = "SQLITE_CONSTRAINT_VTAB"; break;
|
|
|
|
case SQLITE_CONSTRAINT_FUNCTION:
|
|
|
|
zName = "SQLITE_CONSTRAINT_FUNCTION"; break;
|
2013-11-05 17:33:55 +04:00
|
|
|
case SQLITE_CONSTRAINT_ROWID: zName = "SQLITE_CONSTRAINT_ROWID"; break;
|
2013-04-28 05:44:43 +04:00
|
|
|
case SQLITE_MISMATCH: zName = "SQLITE_MISMATCH"; break;
|
|
|
|
case SQLITE_MISUSE: zName = "SQLITE_MISUSE"; break;
|
|
|
|
case SQLITE_NOLFS: zName = "SQLITE_NOLFS"; break;
|
|
|
|
case SQLITE_AUTH: zName = "SQLITE_AUTH"; break;
|
|
|
|
case SQLITE_FORMAT: zName = "SQLITE_FORMAT"; break;
|
|
|
|
case SQLITE_RANGE: zName = "SQLITE_RANGE"; break;
|
|
|
|
case SQLITE_NOTADB: zName = "SQLITE_NOTADB"; break;
|
|
|
|
case SQLITE_ROW: zName = "SQLITE_ROW"; break;
|
|
|
|
case SQLITE_NOTICE: zName = "SQLITE_NOTICE"; break;
|
2013-04-29 07:09:10 +04:00
|
|
|
case SQLITE_NOTICE_RECOVER_WAL: zName = "SQLITE_NOTICE_RECOVER_WAL";break;
|
|
|
|
case SQLITE_NOTICE_RECOVER_ROLLBACK:
|
|
|
|
zName = "SQLITE_NOTICE_RECOVER_ROLLBACK"; break;
|
2013-04-28 05:44:43 +04:00
|
|
|
case SQLITE_WARNING: zName = "SQLITE_WARNING"; break;
|
2013-06-29 03:55:45 +04:00
|
|
|
case SQLITE_WARNING_AUTOINDEX: zName = "SQLITE_WARNING_AUTOINDEX"; break;
|
2013-04-28 05:44:43 +04:00
|
|
|
case SQLITE_DONE: zName = "SQLITE_DONE"; break;
|
|
|
|
}
|
|
|
|
}
|
2013-04-30 11:54:42 +04:00
|
|
|
if( zName==0 ){
|
|
|
|
static char zBuf[50];
|
|
|
|
sqlite3_snprintf(sizeof(zBuf), zBuf, "SQLITE_UNKNOWN(%d)", origRc);
|
|
|
|
zName = zBuf;
|
|
|
|
}
|
2013-04-28 05:44:43 +04:00
|
|
|
return zName;
|
|
|
|
}
|
2013-04-30 11:54:42 +04:00
|
|
|
#endif
|
2013-04-28 05:44:43 +04:00
|
|
|
|
2002-05-10 09:44:55 +04:00
|
|
|
/*
|
2002-05-10 17:14:07 +04:00
|
|
|
** Return a static string that describes the kind of error specified in the
|
|
|
|
** argument.
|
2002-05-10 09:44:55 +04:00
|
|
|
*/
|
2004-06-01 03:56:42 +04:00
|
|
|
const char *sqlite3ErrStr(int rc){
|
2009-04-27 22:46:06 +04:00
|
|
|
static const char* const aMsg[] = {
|
|
|
|
/* SQLITE_OK */ "not an error",
|
2017-07-07 22:43:23 +03:00
|
|
|
/* SQLITE_ERROR */ "SQL logic error",
|
2009-04-27 22:46:06 +04:00
|
|
|
/* SQLITE_INTERNAL */ 0,
|
|
|
|
/* SQLITE_PERM */ "access permission denied",
|
2017-07-10 15:07:53 +03:00
|
|
|
/* SQLITE_ABORT */ "query aborted",
|
2009-04-27 22:46:06 +04:00
|
|
|
/* SQLITE_BUSY */ "database is locked",
|
|
|
|
/* SQLITE_LOCKED */ "database table is locked",
|
|
|
|
/* SQLITE_NOMEM */ "out of memory",
|
|
|
|
/* SQLITE_READONLY */ "attempt to write a readonly database",
|
|
|
|
/* SQLITE_INTERRUPT */ "interrupted",
|
|
|
|
/* SQLITE_IOERR */ "disk I/O error",
|
|
|
|
/* SQLITE_CORRUPT */ "database disk image is malformed",
|
2011-01-26 22:46:22 +03:00
|
|
|
/* SQLITE_NOTFOUND */ "unknown operation",
|
2009-04-27 22:46:06 +04:00
|
|
|
/* SQLITE_FULL */ "database or disk is full",
|
|
|
|
/* SQLITE_CANTOPEN */ "unable to open database file",
|
2010-06-04 19:59:58 +04:00
|
|
|
/* SQLITE_PROTOCOL */ "locking protocol",
|
2017-07-10 14:17:51 +03:00
|
|
|
/* SQLITE_EMPTY */ 0,
|
2009-04-27 22:46:06 +04:00
|
|
|
/* SQLITE_SCHEMA */ "database schema has changed",
|
2009-06-25 05:47:11 +04:00
|
|
|
/* SQLITE_TOOBIG */ "string or blob too big",
|
2009-04-27 22:46:06 +04:00
|
|
|
/* SQLITE_CONSTRAINT */ "constraint failed",
|
|
|
|
/* SQLITE_MISMATCH */ "datatype mismatch",
|
2017-07-10 15:07:53 +03:00
|
|
|
/* SQLITE_MISUSE */ "bad parameter or other API misuse",
|
2017-07-10 14:17:51 +03:00
|
|
|
#ifdef SQLITE_DISABLE_LFS
|
2009-04-27 22:46:06 +04:00
|
|
|
/* SQLITE_NOLFS */ "large file support is disabled",
|
2017-07-10 14:17:51 +03:00
|
|
|
#else
|
|
|
|
/* SQLITE_NOLFS */ 0,
|
|
|
|
#endif
|
2009-04-27 22:46:06 +04:00
|
|
|
/* SQLITE_AUTH */ "authorization denied",
|
2017-07-10 14:17:51 +03:00
|
|
|
/* SQLITE_FORMAT */ 0,
|
2017-07-10 15:07:53 +03:00
|
|
|
/* SQLITE_RANGE */ "column index out of range",
|
|
|
|
/* SQLITE_NOTADB */ "file is not a database",
|
2018-02-08 04:00:11 +03:00
|
|
|
/* SQLITE_NOTICE */ "notification message",
|
|
|
|
/* SQLITE_WARNING */ "warning message",
|
2009-04-27 22:46:06 +04:00
|
|
|
};
|
2012-02-13 21:01:51 +04:00
|
|
|
const char *zErr = "unknown error";
|
|
|
|
switch( rc ){
|
|
|
|
case SQLITE_ABORT_ROLLBACK: {
|
|
|
|
zErr = "abort due to ROLLBACK";
|
|
|
|
break;
|
|
|
|
}
|
2018-02-08 04:00:11 +03:00
|
|
|
case SQLITE_ROW: {
|
|
|
|
zErr = "another row available";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case SQLITE_DONE: {
|
|
|
|
zErr = "no more rows available";
|
|
|
|
break;
|
|
|
|
}
|
2012-02-13 21:01:51 +04:00
|
|
|
default: {
|
|
|
|
rc &= 0xff;
|
|
|
|
if( ALWAYS(rc>=0) && rc<ArraySize(aMsg) && aMsg[rc]!=0 ){
|
|
|
|
zErr = aMsg[rc];
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2002-05-10 09:44:55 +04:00
|
|
|
}
|
2012-02-13 21:01:51 +04:00
|
|
|
return zErr;
|
2002-05-10 09:44:55 +04:00
|
|
|
}
|
|
|
|
|
2000-07-28 18:32:48 +04:00
|
|
|
/*
|
|
|
|
** This routine implements a busy callback that sleeps and tries
|
|
|
|
** again until a timeout value is reached. The timeout value is
|
|
|
|
** an integer number of milliseconds passed in as the first
|
|
|
|
** argument.
|
2018-03-26 20:40:53 +03:00
|
|
|
**
|
|
|
|
** Return non-zero to retry the lock. Return zero to stop trying
|
|
|
|
** and cause SQLite to return SQLITE_BUSY.
|
2000-07-28 18:32:48 +04:00
|
|
|
*/
|
2001-04-11 18:28:42 +04:00
|
|
|
static int sqliteDefaultBusyCallback(
|
2018-03-26 20:40:53 +03:00
|
|
|
void *ptr, /* Database connection */
|
|
|
|
int count, /* Number of times table has been busy */
|
|
|
|
sqlite3_file *pFile /* The file on which the lock occurred */
|
2000-07-28 18:32:48 +04:00
|
|
|
){
|
2015-01-10 19:49:23 +03:00
|
|
|
#if SQLITE_OS_WIN || HAVE_USLEEP
|
2018-03-26 20:40:53 +03:00
|
|
|
/* This case is for systems that have support for sleeping for fractions of
|
|
|
|
** a second. Examples: All windows systems, unix systems with usleep() */
|
2005-04-28 16:06:05 +04:00
|
|
|
static const u8 delays[] =
|
|
|
|
{ 1, 2, 5, 10, 15, 20, 25, 25, 25, 50, 50, 100 };
|
|
|
|
static const u8 totals[] =
|
|
|
|
{ 0, 1, 3, 8, 18, 33, 53, 78, 103, 128, 178, 228 };
|
2011-04-06 02:08:24 +04:00
|
|
|
# define NDELAY ArraySize(delays)
|
2007-08-17 19:53:36 +04:00
|
|
|
sqlite3 *db = (sqlite3 *)ptr;
|
2018-03-26 20:40:53 +03:00
|
|
|
int tmout = db->busyTimeout;
|
2005-05-25 00:19:57 +04:00
|
|
|
int delay, prior;
|
2000-07-28 18:32:48 +04:00
|
|
|
|
2018-03-26 20:40:53 +03:00
|
|
|
#ifdef SQLITE_ENABLE_SETLK_TIMEOUT
|
|
|
|
if( sqlite3OsFileControl(pFile,SQLITE_FCNTL_LOCK_TIMEOUT,&tmout)==SQLITE_OK ){
|
|
|
|
if( count ){
|
|
|
|
tmout = 0;
|
|
|
|
sqlite3OsFileControl(pFile, SQLITE_FCNTL_LOCK_TIMEOUT, &tmout);
|
|
|
|
return 0;
|
|
|
|
}else{
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
2018-03-29 00:45:03 +03:00
|
|
|
#else
|
|
|
|
UNUSED_PARAMETER(pFile);
|
2018-03-26 20:40:53 +03:00
|
|
|
#endif
|
2005-04-28 16:06:05 +04:00
|
|
|
assert( count>=0 );
|
|
|
|
if( count < NDELAY ){
|
|
|
|
delay = delays[count];
|
|
|
|
prior = totals[count];
|
2004-01-15 16:29:31 +03:00
|
|
|
}else{
|
|
|
|
delay = delays[NDELAY-1];
|
2005-05-07 02:05:56 +04:00
|
|
|
prior = totals[NDELAY-1] + delay*(count-(NDELAY-1));
|
2000-07-28 18:32:48 +04:00
|
|
|
}
|
2018-03-26 20:40:53 +03:00
|
|
|
if( prior + delay > tmout ){
|
|
|
|
delay = tmout - prior;
|
2000-07-28 18:32:48 +04:00
|
|
|
if( delay<=0 ) return 0;
|
|
|
|
}
|
2007-08-20 20:07:00 +04:00
|
|
|
sqlite3OsSleep(db->pVfs, delay*1000);
|
2000-07-28 18:32:48 +04:00
|
|
|
return 1;
|
|
|
|
#else
|
2018-03-26 20:40:53 +03:00
|
|
|
/* This case for unix systems that lack usleep() support. Sleeping
|
|
|
|
** must be done in increments of whole seconds */
|
2007-08-20 15:12:40 +04:00
|
|
|
sqlite3 *db = (sqlite3 *)ptr;
|
2018-03-26 20:40:53 +03:00
|
|
|
int tmout = ((sqlite3 *)ptr)->busyTimeout;
|
2018-03-29 00:45:03 +03:00
|
|
|
UNUSED_PARAMETER(pFile);
|
2018-03-26 20:40:53 +03:00
|
|
|
if( (count+1)*1000 > tmout ){
|
2000-07-28 18:32:48 +04:00
|
|
|
return 0;
|
|
|
|
}
|
2007-08-20 15:12:40 +04:00
|
|
|
sqlite3OsSleep(db->pVfs, 1000000);
|
2000-07-28 18:32:48 +04:00
|
|
|
return 1;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2005-07-09 06:16:02 +04:00
|
|
|
/*
|
|
|
|
** Invoke the given busy handler.
|
|
|
|
**
|
2018-03-26 20:40:53 +03:00
|
|
|
** This routine is called when an operation failed to acquire a
|
|
|
|
** lock on VFS file pFile.
|
|
|
|
**
|
2005-07-09 06:16:02 +04:00
|
|
|
** If this routine returns non-zero, the lock is retried. If it
|
|
|
|
** returns 0, the operation aborts with an SQLITE_BUSY error.
|
|
|
|
*/
|
2018-03-26 20:40:53 +03:00
|
|
|
int sqlite3InvokeBusyHandler(BusyHandler *p, sqlite3_file *pFile){
|
2005-07-09 06:16:02 +04:00
|
|
|
int rc;
|
2018-03-26 19:37:53 +03:00
|
|
|
if( p->xBusyHandler==0 || p->nBusy<0 ) return 0;
|
2018-03-26 20:40:53 +03:00
|
|
|
if( p->bExtraFileArg ){
|
|
|
|
/* Add an extra parameter with the pFile pointer to the end of the
|
|
|
|
** callback argument list */
|
|
|
|
int (*xTra)(void*,int,sqlite3_file*);
|
|
|
|
xTra = (int(*)(void*,int,sqlite3_file*))p->xBusyHandler;
|
|
|
|
rc = xTra(p->pBusyArg, p->nBusy, pFile);
|
|
|
|
}else{
|
|
|
|
/* Legacy style busy handler callback */
|
|
|
|
rc = p->xBusyHandler(p->pBusyArg, p->nBusy);
|
|
|
|
}
|
2005-07-09 06:16:02 +04:00
|
|
|
if( rc==0 ){
|
|
|
|
p->nBusy = -1;
|
|
|
|
}else{
|
|
|
|
p->nBusy++;
|
|
|
|
}
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
2000-07-28 18:32:48 +04:00
|
|
|
/*
|
|
|
|
** This routine sets the busy callback for an Sqlite database to the
|
|
|
|
** given callback function with the given argument.
|
|
|
|
*/
|
2004-06-19 12:18:07 +04:00
|
|
|
int sqlite3_busy_handler(
|
|
|
|
sqlite3 *db,
|
2004-06-12 05:43:26 +04:00
|
|
|
int (*xBusy)(void*,int),
|
2000-07-28 18:32:48 +04:00
|
|
|
void *pArg
|
|
|
|
){
|
2014-10-24 04:35:58 +04:00
|
|
|
#ifdef SQLITE_ENABLE_API_ARMOR
|
2015-02-13 19:36:14 +03:00
|
|
|
if( !sqlite3SafetyCheckOk(db) ) return SQLITE_MISUSE_BKPT;
|
2014-10-24 04:35:58 +04:00
|
|
|
#endif
|
2007-08-21 20:15:55 +04:00
|
|
|
sqlite3_mutex_enter(db->mutex);
|
2018-03-26 19:37:53 +03:00
|
|
|
db->busyHandler.xBusyHandler = xBusy;
|
|
|
|
db->busyHandler.pBusyArg = pArg;
|
2005-07-09 06:16:02 +04:00
|
|
|
db->busyHandler.nBusy = 0;
|
2018-03-26 20:40:53 +03:00
|
|
|
db->busyHandler.bExtraFileArg = 0;
|
2012-09-07 22:49:57 +04:00
|
|
|
db->busyTimeout = 0;
|
2007-08-21 20:15:55 +04:00
|
|
|
sqlite3_mutex_leave(db->mutex);
|
2004-06-19 12:18:07 +04:00
|
|
|
return SQLITE_OK;
|
2000-07-28 18:32:48 +04:00
|
|
|
}
|
|
|
|
|
2003-10-18 13:37:26 +04:00
|
|
|
#ifndef SQLITE_OMIT_PROGRESS_CALLBACK
|
|
|
|
/*
|
|
|
|
** This routine sets the progress callback for an Sqlite database to the
|
|
|
|
** given callback function with the given argument. The progress callback will
|
|
|
|
** be invoked every nOps opcodes.
|
|
|
|
*/
|
2004-05-10 14:34:34 +04:00
|
|
|
void sqlite3_progress_handler(
|
2004-09-06 21:24:11 +04:00
|
|
|
sqlite3 *db,
|
2003-10-18 13:37:26 +04:00
|
|
|
int nOps,
|
|
|
|
int (*xProgress)(void*),
|
|
|
|
void *pArg
|
|
|
|
){
|
2014-10-24 04:35:58 +04:00
|
|
|
#ifdef SQLITE_ENABLE_API_ARMOR
|
|
|
|
if( !sqlite3SafetyCheckOk(db) ){
|
|
|
|
(void)SQLITE_MISUSE_BKPT;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
#endif
|
2008-07-07 23:52:09 +04:00
|
|
|
sqlite3_mutex_enter(db->mutex);
|
|
|
|
if( nOps>0 ){
|
|
|
|
db->xProgress = xProgress;
|
2013-07-10 22:14:29 +04:00
|
|
|
db->nProgressOps = (unsigned)nOps;
|
2008-07-07 23:52:09 +04:00
|
|
|
db->pProgressArg = pArg;
|
|
|
|
}else{
|
|
|
|
db->xProgress = 0;
|
|
|
|
db->nProgressOps = 0;
|
|
|
|
db->pProgressArg = 0;
|
2003-10-18 13:37:26 +04:00
|
|
|
}
|
2008-07-07 23:52:09 +04:00
|
|
|
sqlite3_mutex_leave(db->mutex);
|
2003-10-18 13:37:26 +04:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2000-07-28 18:32:48 +04:00
|
|
|
/*
|
|
|
|
** This routine installs a default busy handler that waits for the
|
|
|
|
** specified number of milliseconds before returning 0.
|
|
|
|
*/
|
2004-06-19 12:18:07 +04:00
|
|
|
int sqlite3_busy_timeout(sqlite3 *db, int ms){
|
2014-10-24 04:35:58 +04:00
|
|
|
#ifdef SQLITE_ENABLE_API_ARMOR
|
|
|
|
if( !sqlite3SafetyCheckOk(db) ) return SQLITE_MISUSE_BKPT;
|
|
|
|
#endif
|
2000-07-28 18:32:48 +04:00
|
|
|
if( ms>0 ){
|
2018-03-26 20:40:53 +03:00
|
|
|
sqlite3_busy_handler(db, (int(*)(void*,int))sqliteDefaultBusyCallback,
|
|
|
|
(void*)db);
|
2012-09-07 22:49:57 +04:00
|
|
|
db->busyTimeout = ms;
|
2018-03-26 20:40:53 +03:00
|
|
|
db->busyHandler.bExtraFileArg = 1;
|
2000-07-28 18:32:48 +04:00
|
|
|
}else{
|
2004-05-10 14:34:34 +04:00
|
|
|
sqlite3_busy_handler(db, 0, 0);
|
2000-07-28 18:32:48 +04:00
|
|
|
}
|
2004-06-19 12:18:07 +04:00
|
|
|
return SQLITE_OK;
|
2000-07-28 18:32:48 +04:00
|
|
|
}
|
2000-10-17 02:06:40 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
** Cause any pending operation to stop at its earliest opportunity.
|
|
|
|
*/
|
2004-09-06 21:24:11 +04:00
|
|
|
void sqlite3_interrupt(sqlite3 *db){
|
2014-10-24 04:35:58 +04:00
|
|
|
#ifdef SQLITE_ENABLE_API_ARMOR
|
2016-12-27 16:33:52 +03:00
|
|
|
if( !sqlite3SafetyCheckOk(db) && (db==0 || db->magic!=SQLITE_MAGIC_ZOMBIE) ){
|
2014-10-24 04:35:58 +04:00
|
|
|
(void)SQLITE_MISUSE_BKPT;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
#endif
|
2008-07-07 23:52:09 +04:00
|
|
|
db->u1.isInterrupted = 1;
|
2000-10-17 02:06:40 +04:00
|
|
|
}
|
2002-02-02 18:01:15 +03:00
|
|
|
|
|
|
|
|
|
|
|
/*
|
2006-01-17 16:21:40 +03:00
|
|
|
** This function is exactly the same as sqlite3_create_function(), except
|
|
|
|
** that it is designed to be called by internal code. The difference is
|
|
|
|
** that if a malloc() fails in sqlite3_create_function(), an error code
|
|
|
|
** is returned and the mallocFailed flag cleared.
|
2002-02-02 18:01:15 +03:00
|
|
|
*/
|
2006-01-17 16:21:40 +03:00
|
|
|
int sqlite3CreateFunc(
|
2004-05-26 10:18:37 +04:00
|
|
|
sqlite3 *db,
|
|
|
|
const char *zFunctionName,
|
|
|
|
int nArg,
|
2004-06-12 13:25:12 +04:00
|
|
|
int enc,
|
2004-05-26 10:18:37 +04:00
|
|
|
void *pUserData,
|
2016-01-15 01:19:58 +03:00
|
|
|
void (*xSFunc)(sqlite3_context*,int,sqlite3_value **),
|
2004-05-26 10:18:37 +04:00
|
|
|
void (*xStep)(sqlite3_context*,int,sqlite3_value **),
|
2010-08-27 21:48:52 +04:00
|
|
|
void (*xFinal)(sqlite3_context*),
|
2018-06-18 19:55:22 +03:00
|
|
|
void (*xValue)(sqlite3_context*),
|
|
|
|
void (*xInverse)(sqlite3_context*,int,sqlite3_value **),
|
2010-08-27 21:48:52 +04:00
|
|
|
FuncDestructor *pDestructor
|
2002-02-24 02:45:45 +03:00
|
|
|
){
|
2002-02-28 03:41:10 +03:00
|
|
|
FuncDef *p;
|
2002-08-24 22:24:51 +04:00
|
|
|
int nName;
|
2013-12-14 17:44:22 +04:00
|
|
|
int extraFlags;
|
2004-05-26 10:18:37 +04:00
|
|
|
|
2007-08-21 20:15:55 +04:00
|
|
|
assert( sqlite3_mutex_held(db->mutex) );
|
2018-07-09 05:37:12 +03:00
|
|
|
assert( xValue==0 || xSFunc==0 );
|
|
|
|
if( zFunctionName==0 /* Must have a valid name */
|
|
|
|
|| (xSFunc!=0 && xFinal!=0) /* Not both xSFunc and xFinal */
|
|
|
|
|| ((xFinal==0)!=(xStep==0)) /* Both or neither of xFinal and xStep */
|
|
|
|
|| ((xValue==0)!=(xInverse==0)) /* Both or neither of xValue, xInverse */
|
|
|
|
|| (nArg<-1 || nArg>SQLITE_MAX_FUNCTION_ARG)
|
|
|
|
|| (255<(nName = sqlite3Strlen30( zFunctionName)))
|
|
|
|
){
|
2010-02-23 23:11:56 +03:00
|
|
|
return SQLITE_MISUSE_BKPT;
|
2004-05-26 10:18:37 +04:00
|
|
|
}
|
2013-12-14 17:44:22 +04:00
|
|
|
|
|
|
|
assert( SQLITE_FUNC_CONSTANT==SQLITE_DETERMINISTIC );
|
|
|
|
extraFlags = enc & SQLITE_DETERMINISTIC;
|
|
|
|
enc &= (SQLITE_FUNC_ENCMASK|SQLITE_ANY);
|
2004-06-12 13:25:12 +04:00
|
|
|
|
2005-01-21 11:13:14 +03:00
|
|
|
#ifndef SQLITE_OMIT_UTF16
|
2004-06-12 13:25:12 +04:00
|
|
|
/* If SQLITE_UTF16 is specified as the encoding type, transform this
|
|
|
|
** to one of SQLITE_UTF16LE or SQLITE_UTF16BE using the
|
|
|
|
** SQLITE_UTF16NATIVE macro. SQLITE_UTF16 is not used internally.
|
|
|
|
**
|
|
|
|
** If SQLITE_ANY is specified, add three versions of the function
|
|
|
|
** to the hash table.
|
|
|
|
*/
|
|
|
|
if( enc==SQLITE_UTF16 ){
|
|
|
|
enc = SQLITE_UTF16NATIVE;
|
|
|
|
}else if( enc==SQLITE_ANY ){
|
|
|
|
int rc;
|
2013-12-14 17:44:22 +04:00
|
|
|
rc = sqlite3CreateFunc(db, zFunctionName, nArg, SQLITE_UTF8|extraFlags,
|
2018-06-18 19:55:22 +03:00
|
|
|
pUserData, xSFunc, xStep, xFinal, xValue, xInverse, pDestructor);
|
2007-08-21 20:15:55 +04:00
|
|
|
if( rc==SQLITE_OK ){
|
2013-12-14 17:44:22 +04:00
|
|
|
rc = sqlite3CreateFunc(db, zFunctionName, nArg, SQLITE_UTF16LE|extraFlags,
|
2018-06-18 19:55:22 +03:00
|
|
|
pUserData, xSFunc, xStep, xFinal, xValue, xInverse, pDestructor);
|
2007-08-21 20:15:55 +04:00
|
|
|
}
|
|
|
|
if( rc!=SQLITE_OK ){
|
|
|
|
return rc;
|
|
|
|
}
|
2004-06-12 13:25:12 +04:00
|
|
|
enc = SQLITE_UTF16BE;
|
|
|
|
}
|
2005-01-21 11:13:14 +03:00
|
|
|
#else
|
|
|
|
enc = SQLITE_UTF8;
|
|
|
|
#endif
|
2005-01-25 07:27:54 +03:00
|
|
|
|
|
|
|
/* Check if an existing function is being overridden or deleted. If so,
|
|
|
|
** and there are active VMs, then return SQLITE_BUSY. If a function
|
|
|
|
** is being overridden/deleted but there are no active VMs, allow the
|
|
|
|
** operation to continue but invalidate all precompiled statements.
|
|
|
|
*/
|
2016-02-15 03:34:16 +03:00
|
|
|
p = sqlite3FindFunction(db, zFunctionName, nArg, (u8)enc, 0);
|
2018-07-10 01:49:01 +03:00
|
|
|
if( p && (p->funcFlags & SQLITE_FUNC_ENCMASK)==(u32)enc && p->nArg==nArg ){
|
2013-06-28 03:54:02 +04:00
|
|
|
if( db->nVdbeActive ){
|
2014-08-22 22:00:11 +04:00
|
|
|
sqlite3ErrorWithMsg(db, SQLITE_BUSY,
|
2009-02-04 20:40:57 +03:00
|
|
|
"unable to delete/modify user-function due to active statements");
|
2007-08-16 08:30:38 +04:00
|
|
|
assert( !db->mallocFailed );
|
2005-01-25 07:27:54 +03:00
|
|
|
return SQLITE_BUSY;
|
|
|
|
}else{
|
2018-07-25 01:02:12 +03:00
|
|
|
sqlite3ExpirePreparedStatements(db, 0);
|
2005-01-25 07:27:54 +03:00
|
|
|
}
|
|
|
|
}
|
2004-05-26 10:18:37 +04:00
|
|
|
|
2016-02-15 03:34:16 +03:00
|
|
|
p = sqlite3FindFunction(db, zFunctionName, nArg, (u8)enc, 1);
|
2007-09-03 15:04:22 +04:00
|
|
|
assert(p || db->mallocFailed);
|
|
|
|
if( !p ){
|
2016-02-14 02:43:46 +03:00
|
|
|
return SQLITE_NOMEM_BKPT;
|
2006-01-17 16:21:40 +03:00
|
|
|
}
|
2010-08-27 21:48:52 +04:00
|
|
|
|
|
|
|
/* If an older version of the function with a configured destructor is
|
|
|
|
** being replaced invoke the destructor function here. */
|
|
|
|
functionDestroy(db, p);
|
|
|
|
|
|
|
|
if( pDestructor ){
|
|
|
|
pDestructor->nRef++;
|
|
|
|
}
|
2016-02-15 03:34:16 +03:00
|
|
|
p->u.pDestructor = pDestructor;
|
2013-12-14 17:44:22 +04:00
|
|
|
p->funcFlags = (p->funcFlags & SQLITE_FUNC_ENCMASK) | extraFlags;
|
|
|
|
testcase( p->funcFlags & SQLITE_DETERMINISTIC );
|
2016-01-15 01:19:58 +03:00
|
|
|
p->xSFunc = xSFunc ? xSFunc : xStep;
|
2007-09-03 15:04:22 +04:00
|
|
|
p->xFinalize = xFinal;
|
2018-06-18 19:55:22 +03:00
|
|
|
p->xValue = xValue;
|
|
|
|
p->xInverse = xInverse;
|
2007-09-03 15:04:22 +04:00
|
|
|
p->pUserData = pUserData;
|
2008-12-11 00:19:56 +03:00
|
|
|
p->nArg = (u16)nArg;
|
2004-05-26 10:18:37 +04:00
|
|
|
return SQLITE_OK;
|
2002-02-24 02:45:45 +03:00
|
|
|
}
|
2006-01-17 16:21:40 +03:00
|
|
|
|
|
|
|
/*
|
2018-06-18 19:55:22 +03:00
|
|
|
** Worker function used by utf-8 APIs that create new functions:
|
|
|
|
**
|
|
|
|
** sqlite3_create_function()
|
|
|
|
** sqlite3_create_function_v2()
|
|
|
|
** sqlite3_create_window_function()
|
2006-01-17 16:21:40 +03:00
|
|
|
*/
|
2018-06-18 19:55:22 +03:00
|
|
|
static int createFunctionApi(
|
2010-08-27 21:48:52 +04:00
|
|
|
sqlite3 *db,
|
|
|
|
const char *zFunc,
|
|
|
|
int nArg,
|
|
|
|
int enc,
|
|
|
|
void *p,
|
2018-06-18 19:55:22 +03:00
|
|
|
void (*xSFunc)(sqlite3_context*,int,sqlite3_value**),
|
|
|
|
void (*xStep)(sqlite3_context*,int,sqlite3_value**),
|
2010-08-27 21:48:52 +04:00
|
|
|
void (*xFinal)(sqlite3_context*),
|
2018-06-18 19:55:22 +03:00
|
|
|
void (*xValue)(sqlite3_context*),
|
|
|
|
void (*xInverse)(sqlite3_context*,int,sqlite3_value**),
|
|
|
|
void(*xDestroy)(void*)
|
2010-08-27 21:48:52 +04:00
|
|
|
){
|
2010-09-01 06:38:21 +04:00
|
|
|
int rc = SQLITE_ERROR;
|
2010-08-27 21:48:52 +04:00
|
|
|
FuncDestructor *pArg = 0;
|
2014-10-24 04:35:58 +04:00
|
|
|
|
|
|
|
#ifdef SQLITE_ENABLE_API_ARMOR
|
|
|
|
if( !sqlite3SafetyCheckOk(db) ){
|
|
|
|
return SQLITE_MISUSE_BKPT;
|
|
|
|
}
|
|
|
|
#endif
|
2010-08-27 21:48:52 +04:00
|
|
|
sqlite3_mutex_enter(db->mutex);
|
|
|
|
if( xDestroy ){
|
2018-05-26 19:00:26 +03:00
|
|
|
pArg = (FuncDestructor *)sqlite3Malloc(sizeof(FuncDestructor));
|
2010-08-28 22:58:00 +04:00
|
|
|
if( !pArg ){
|
2018-05-26 19:00:26 +03:00
|
|
|
sqlite3OomFault(db);
|
2010-08-28 22:58:00 +04:00
|
|
|
xDestroy(p);
|
|
|
|
goto out;
|
|
|
|
}
|
2018-05-26 19:00:26 +03:00
|
|
|
pArg->nRef = 0;
|
2010-08-27 21:48:52 +04:00
|
|
|
pArg->xDestroy = xDestroy;
|
|
|
|
pArg->pUserData = p;
|
|
|
|
}
|
2018-06-18 19:55:22 +03:00
|
|
|
rc = sqlite3CreateFunc(db, zFunc, nArg, enc, p,
|
|
|
|
xSFunc, xStep, xFinal, xValue, xInverse, pArg
|
|
|
|
);
|
2010-08-27 21:48:52 +04:00
|
|
|
if( pArg && pArg->nRef==0 ){
|
|
|
|
assert( rc!=SQLITE_OK );
|
2010-08-28 22:58:00 +04:00
|
|
|
xDestroy(p);
|
2018-05-26 19:00:26 +03:00
|
|
|
sqlite3_free(pArg);
|
2010-08-27 21:48:52 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
out:
|
2007-08-21 20:15:55 +04:00
|
|
|
rc = sqlite3ApiExit(db, rc);
|
|
|
|
sqlite3_mutex_leave(db->mutex);
|
|
|
|
return rc;
|
2006-01-17 16:21:40 +03:00
|
|
|
}
|
|
|
|
|
2018-06-18 19:55:22 +03:00
|
|
|
/*
|
|
|
|
** Create new user functions.
|
|
|
|
*/
|
|
|
|
int sqlite3_create_function(
|
|
|
|
sqlite3 *db,
|
|
|
|
const char *zFunc,
|
|
|
|
int nArg,
|
|
|
|
int enc,
|
|
|
|
void *p,
|
|
|
|
void (*xSFunc)(sqlite3_context*,int,sqlite3_value **),
|
|
|
|
void (*xStep)(sqlite3_context*,int,sqlite3_value **),
|
|
|
|
void (*xFinal)(sqlite3_context*)
|
|
|
|
){
|
|
|
|
return createFunctionApi(db, zFunc, nArg, enc, p, xSFunc, xStep,
|
|
|
|
xFinal, 0, 0, 0);
|
|
|
|
}
|
|
|
|
int sqlite3_create_function_v2(
|
|
|
|
sqlite3 *db,
|
|
|
|
const char *zFunc,
|
|
|
|
int nArg,
|
|
|
|
int enc,
|
|
|
|
void *p,
|
|
|
|
void (*xSFunc)(sqlite3_context*,int,sqlite3_value **),
|
|
|
|
void (*xStep)(sqlite3_context*,int,sqlite3_value **),
|
|
|
|
void (*xFinal)(sqlite3_context*),
|
|
|
|
void (*xDestroy)(void *)
|
|
|
|
){
|
|
|
|
return createFunctionApi(db, zFunc, nArg, enc, p, xSFunc, xStep,
|
|
|
|
xFinal, 0, 0, xDestroy);
|
|
|
|
}
|
|
|
|
int sqlite3_create_window_function(
|
|
|
|
sqlite3 *db,
|
|
|
|
const char *zFunc,
|
|
|
|
int nArg,
|
|
|
|
int enc,
|
|
|
|
void *p,
|
|
|
|
void (*xStep)(sqlite3_context*,int,sqlite3_value **),
|
|
|
|
void (*xFinal)(sqlite3_context*),
|
|
|
|
void (*xValue)(sqlite3_context*),
|
|
|
|
void (*xInverse)(sqlite3_context*,int,sqlite3_value **),
|
|
|
|
void (*xDestroy)(void *)
|
|
|
|
){
|
|
|
|
return createFunctionApi(db, zFunc, nArg, enc, p, 0, xStep,
|
|
|
|
xFinal, xValue, xInverse, xDestroy);
|
|
|
|
}
|
|
|
|
|
2005-01-21 11:13:14 +03:00
|
|
|
#ifndef SQLITE_OMIT_UTF16
|
2004-05-26 10:18:37 +04:00
|
|
|
int sqlite3_create_function16(
|
|
|
|
sqlite3 *db,
|
|
|
|
const void *zFunctionName,
|
|
|
|
int nArg,
|
|
|
|
int eTextRep,
|
2006-01-17 16:21:40 +03:00
|
|
|
void *p,
|
2016-01-15 01:19:58 +03:00
|
|
|
void (*xSFunc)(sqlite3_context*,int,sqlite3_value**),
|
2004-05-26 10:18:37 +04:00
|
|
|
void (*xStep)(sqlite3_context*,int,sqlite3_value**),
|
|
|
|
void (*xFinal)(sqlite3_context*)
|
2002-02-24 02:45:45 +03:00
|
|
|
){
|
2004-05-26 10:18:37 +04:00
|
|
|
int rc;
|
2005-12-15 06:04:10 +03:00
|
|
|
char *zFunc8;
|
2014-10-24 04:35:58 +04:00
|
|
|
|
|
|
|
#ifdef SQLITE_ENABLE_API_ARMOR
|
|
|
|
if( !sqlite3SafetyCheckOk(db) || zFunctionName==0 ) return SQLITE_MISUSE_BKPT;
|
|
|
|
#endif
|
2007-08-21 20:15:55 +04:00
|
|
|
sqlite3_mutex_enter(db->mutex);
|
2007-08-16 08:30:38 +04:00
|
|
|
assert( !db->mallocFailed );
|
2010-03-05 19:32:12 +03:00
|
|
|
zFunc8 = sqlite3Utf16to8(db, zFunctionName, -1, SQLITE_UTF16NATIVE);
|
2018-06-18 19:55:22 +03:00
|
|
|
rc = sqlite3CreateFunc(db, zFunc8, nArg, eTextRep, p, xSFunc,xStep,xFinal,0,0,0);
|
2008-07-28 23:34:53 +04:00
|
|
|
sqlite3DbFree(db, zFunc8);
|
2007-08-21 20:15:55 +04:00
|
|
|
rc = sqlite3ApiExit(db, rc);
|
|
|
|
sqlite3_mutex_leave(db->mutex);
|
|
|
|
return rc;
|
2002-02-24 02:45:45 +03:00
|
|
|
}
|
2005-01-21 11:13:14 +03:00
|
|
|
#endif
|
2002-06-20 15:36:48 +04:00
|
|
|
|
2006-09-17 01:45:14 +04:00
|
|
|
|
2018-05-26 19:00:26 +03:00
|
|
|
/*
|
|
|
|
** The following is the implementation of an SQL function that always
|
|
|
|
** fails with an error message stating that the function is used in the
|
|
|
|
** wrong context. The sqlite3_overload_function() API might construct
|
|
|
|
** SQL function that use this routine so that the functions will exist
|
|
|
|
** for name resolution but are actually overloaded by the xFindFunction
|
|
|
|
** method of virtual tables.
|
|
|
|
*/
|
|
|
|
static void sqlite3InvalidFunction(
|
|
|
|
sqlite3_context *context, /* The function calling context */
|
|
|
|
int NotUsed, /* Number of arguments to the function */
|
|
|
|
sqlite3_value **NotUsed2 /* Value of each argument */
|
|
|
|
){
|
|
|
|
const char *zName = (const char*)sqlite3_user_data(context);
|
|
|
|
char *zErr;
|
|
|
|
UNUSED_PARAMETER2(NotUsed, NotUsed2);
|
|
|
|
zErr = sqlite3_mprintf(
|
|
|
|
"unable to use function %s in the requested context", zName);
|
|
|
|
sqlite3_result_error(context, zErr, -1);
|
|
|
|
sqlite3_free(zErr);
|
|
|
|
}
|
|
|
|
|
2006-09-17 01:45:14 +04:00
|
|
|
/*
|
|
|
|
** Declare that a function has been overloaded by a virtual table.
|
|
|
|
**
|
|
|
|
** If the function already exists as a regular global function, then
|
|
|
|
** this routine is a no-op. If the function does not exist, then create
|
|
|
|
** a new one that always throws a run-time error.
|
|
|
|
**
|
|
|
|
** When virtual tables intend to provide an overloaded function, they
|
|
|
|
** should call this routine to make sure the global function exists.
|
|
|
|
** A global function must exist in order for name resolution to work
|
|
|
|
** properly.
|
|
|
|
*/
|
|
|
|
int sqlite3_overload_function(
|
|
|
|
sqlite3 *db,
|
|
|
|
const char *zName,
|
|
|
|
int nArg
|
|
|
|
){
|
2018-05-26 19:00:26 +03:00
|
|
|
int rc;
|
|
|
|
char *zCopy;
|
2014-10-24 04:35:58 +04:00
|
|
|
|
|
|
|
#ifdef SQLITE_ENABLE_API_ARMOR
|
|
|
|
if( !sqlite3SafetyCheckOk(db) || zName==0 || nArg<-2 ){
|
|
|
|
return SQLITE_MISUSE_BKPT;
|
|
|
|
}
|
|
|
|
#endif
|
2007-08-21 20:15:55 +04:00
|
|
|
sqlite3_mutex_enter(db->mutex);
|
2018-05-26 19:00:26 +03:00
|
|
|
rc = sqlite3FindFunction(db, zName, nArg, SQLITE_UTF8, 0)!=0;
|
2007-08-21 20:15:55 +04:00
|
|
|
sqlite3_mutex_leave(db->mutex);
|
2018-05-26 19:00:26 +03:00
|
|
|
if( rc ) return SQLITE_OK;
|
|
|
|
zCopy = sqlite3_mprintf(zName);
|
|
|
|
if( zCopy==0 ) return SQLITE_NOMEM;
|
|
|
|
return sqlite3_create_function_v2(db, zName, nArg, SQLITE_UTF8,
|
|
|
|
zCopy, sqlite3InvalidFunction, 0, 0, sqlite3_free);
|
2006-09-17 01:45:14 +04:00
|
|
|
}
|
|
|
|
|
2005-08-30 03:00:03 +04:00
|
|
|
#ifndef SQLITE_OMIT_TRACE
|
2003-01-16 19:28:53 +03:00
|
|
|
/*
|
|
|
|
** Register a trace function. The pArg from the previously registered trace
|
|
|
|
** is returned.
|
|
|
|
**
|
|
|
|
** A NULL trace function means that no tracing is executes. A non-NULL
|
|
|
|
** trace is a pointer to a function that is invoked at the start of each
|
2005-08-30 03:00:03 +04:00
|
|
|
** SQL statement.
|
2003-01-16 19:28:53 +03:00
|
|
|
*/
|
2016-07-14 01:55:01 +03:00
|
|
|
#ifndef SQLITE_OMIT_DEPRECATED
|
2016-07-14 04:09:08 +03:00
|
|
|
void *sqlite3_trace(sqlite3 *db, void(*xTrace)(void*,const char*), void *pArg){
|
2007-08-21 20:15:55 +04:00
|
|
|
void *pOld;
|
2014-10-24 04:35:58 +04:00
|
|
|
|
|
|
|
#ifdef SQLITE_ENABLE_API_ARMOR
|
|
|
|
if( !sqlite3SafetyCheckOk(db) ){
|
|
|
|
(void)SQLITE_MISUSE_BKPT;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#endif
|
2007-08-21 20:15:55 +04:00
|
|
|
sqlite3_mutex_enter(db->mutex);
|
|
|
|
pOld = db->pTraceArg;
|
2016-07-14 02:18:27 +03:00
|
|
|
db->mTrace = xTrace ? SQLITE_TRACE_LEGACY : 0;
|
2016-07-14 04:09:08 +03:00
|
|
|
db->xTrace = (int(*)(u32,void*,void*,void*))xTrace;
|
2003-01-16 19:28:53 +03:00
|
|
|
db->pTraceArg = pArg;
|
2007-08-21 20:15:55 +04:00
|
|
|
sqlite3_mutex_leave(db->mutex);
|
2003-01-16 19:28:53 +03:00
|
|
|
return pOld;
|
2003-04-03 19:46:04 +04:00
|
|
|
}
|
2016-07-14 01:55:01 +03:00
|
|
|
#endif /* SQLITE_OMIT_DEPRECATED */
|
|
|
|
|
|
|
|
/* Register a trace callback using the version-2 interface.
|
|
|
|
*/
|
|
|
|
int sqlite3_trace_v2(
|
2016-07-14 04:09:08 +03:00
|
|
|
sqlite3 *db, /* Trace this connection */
|
|
|
|
unsigned mTrace, /* Mask of events to be traced */
|
|
|
|
int(*xTrace)(unsigned,void*,void*,void*), /* Callback to invoke */
|
|
|
|
void *pArg /* Context */
|
2016-07-14 01:55:01 +03:00
|
|
|
){
|
|
|
|
#ifdef SQLITE_ENABLE_API_ARMOR
|
|
|
|
if( !sqlite3SafetyCheckOk(db) ){
|
2016-07-15 03:39:47 +03:00
|
|
|
return SQLITE_MISUSE_BKPT;
|
2016-07-14 01:55:01 +03:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
sqlite3_mutex_enter(db->mutex);
|
2016-08-26 01:06:37 +03:00
|
|
|
if( mTrace==0 ) xTrace = 0;
|
|
|
|
if( xTrace==0 ) mTrace = 0;
|
2016-07-14 01:55:01 +03:00
|
|
|
db->mTrace = mTrace;
|
|
|
|
db->xTrace = xTrace;
|
|
|
|
db->pTraceArg = pArg;
|
|
|
|
sqlite3_mutex_leave(db->mutex);
|
|
|
|
return SQLITE_OK;
|
|
|
|
}
|
|
|
|
|
2016-07-25 03:05:56 +03:00
|
|
|
#ifndef SQLITE_OMIT_DEPRECATED
|
2005-08-30 03:00:03 +04:00
|
|
|
/*
|
|
|
|
** Register a profile function. The pArg from the previously registered
|
|
|
|
** profile function is returned.
|
|
|
|
**
|
|
|
|
** A NULL profile function means that no profiling is executes. A non-NULL
|
|
|
|
** profile is a pointer to a function that is invoked at the conclusion of
|
|
|
|
** each SQL statement that is run.
|
|
|
|
*/
|
|
|
|
void *sqlite3_profile(
|
|
|
|
sqlite3 *db,
|
|
|
|
void (*xProfile)(void*,const char*,sqlite_uint64),
|
|
|
|
void *pArg
|
|
|
|
){
|
2007-08-21 20:15:55 +04:00
|
|
|
void *pOld;
|
2014-10-24 04:35:58 +04:00
|
|
|
|
|
|
|
#ifdef SQLITE_ENABLE_API_ARMOR
|
|
|
|
if( !sqlite3SafetyCheckOk(db) ){
|
|
|
|
(void)SQLITE_MISUSE_BKPT;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#endif
|
2007-08-21 20:15:55 +04:00
|
|
|
sqlite3_mutex_enter(db->mutex);
|
|
|
|
pOld = db->pProfileArg;
|
2005-08-30 03:00:03 +04:00
|
|
|
db->xProfile = xProfile;
|
|
|
|
db->pProfileArg = pArg;
|
2018-12-04 17:33:02 +03:00
|
|
|
db->mTrace &= SQLITE_TRACE_NONLEGACY_MASK;
|
|
|
|
if( db->xProfile ) db->mTrace |= SQLITE_TRACE_XPROFILE;
|
2007-08-21 20:15:55 +04:00
|
|
|
sqlite3_mutex_leave(db->mutex);
|
2005-08-30 03:00:03 +04:00
|
|
|
return pOld;
|
|
|
|
}
|
2016-07-25 03:05:56 +03:00
|
|
|
#endif /* SQLITE_OMIT_DEPRECATED */
|
2005-08-30 03:00:03 +04:00
|
|
|
#endif /* SQLITE_OMIT_TRACE */
|
2003-04-13 22:26:49 +04:00
|
|
|
|
2012-03-02 01:30:44 +04:00
|
|
|
/*
|
|
|
|
** Register a function to be invoked when a transaction commits.
|
2005-12-16 09:54:01 +03:00
|
|
|
** If the invoked function returns non-zero, then the commit becomes a
|
2004-01-15 05:44:03 +03:00
|
|
|
** rollback.
|
|
|
|
*/
|
2004-05-10 14:34:34 +04:00
|
|
|
void *sqlite3_commit_hook(
|
2004-09-06 21:24:11 +04:00
|
|
|
sqlite3 *db, /* Attach the hook to this database */
|
2004-01-15 05:44:03 +03:00
|
|
|
int (*xCallback)(void*), /* Function to invoke on each commit */
|
|
|
|
void *pArg /* Argument to the function */
|
|
|
|
){
|
2007-08-21 20:15:55 +04:00
|
|
|
void *pOld;
|
2014-10-24 04:35:58 +04:00
|
|
|
|
|
|
|
#ifdef SQLITE_ENABLE_API_ARMOR
|
|
|
|
if( !sqlite3SafetyCheckOk(db) ){
|
|
|
|
(void)SQLITE_MISUSE_BKPT;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#endif
|
2007-08-21 20:15:55 +04:00
|
|
|
sqlite3_mutex_enter(db->mutex);
|
|
|
|
pOld = db->pCommitArg;
|
2004-01-15 05:44:03 +03:00
|
|
|
db->xCommitCallback = xCallback;
|
|
|
|
db->pCommitArg = pArg;
|
2007-08-21 20:15:55 +04:00
|
|
|
sqlite3_mutex_leave(db->mutex);
|
2004-01-15 05:44:03 +03:00
|
|
|
return pOld;
|
|
|
|
}
|
|
|
|
|
2005-12-15 18:22:08 +03:00
|
|
|
/*
|
|
|
|
** Register a callback to be invoked each time a row is updated,
|
|
|
|
** inserted or deleted using this database connection.
|
|
|
|
*/
|
2005-12-16 09:54:01 +03:00
|
|
|
void *sqlite3_update_hook(
|
2005-12-15 18:22:08 +03:00
|
|
|
sqlite3 *db, /* Attach the hook to this database */
|
|
|
|
void (*xCallback)(void*,int,char const *,char const *,sqlite_int64),
|
|
|
|
void *pArg /* Argument to the function */
|
|
|
|
){
|
2007-08-21 20:15:55 +04:00
|
|
|
void *pRet;
|
2014-10-24 04:35:58 +04:00
|
|
|
|
|
|
|
#ifdef SQLITE_ENABLE_API_ARMOR
|
|
|
|
if( !sqlite3SafetyCheckOk(db) ){
|
|
|
|
(void)SQLITE_MISUSE_BKPT;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#endif
|
2007-08-21 20:15:55 +04:00
|
|
|
sqlite3_mutex_enter(db->mutex);
|
|
|
|
pRet = db->pUpdateArg;
|
2005-12-15 18:22:08 +03:00
|
|
|
db->xUpdateCallback = xCallback;
|
|
|
|
db->pUpdateArg = pArg;
|
2007-08-21 20:15:55 +04:00
|
|
|
sqlite3_mutex_leave(db->mutex);
|
2005-12-16 09:54:01 +03:00
|
|
|
return pRet;
|
2005-12-15 18:22:08 +03:00
|
|
|
}
|
|
|
|
|
2005-12-16 09:54:01 +03:00
|
|
|
/*
|
|
|
|
** Register a callback to be invoked each time a transaction is rolled
|
|
|
|
** back by this database connection.
|
|
|
|
*/
|
|
|
|
void *sqlite3_rollback_hook(
|
|
|
|
sqlite3 *db, /* Attach the hook to this database */
|
|
|
|
void (*xCallback)(void*), /* Callback function */
|
|
|
|
void *pArg /* Argument to the function */
|
|
|
|
){
|
2007-08-21 20:15:55 +04:00
|
|
|
void *pRet;
|
2014-10-24 04:35:58 +04:00
|
|
|
|
|
|
|
#ifdef SQLITE_ENABLE_API_ARMOR
|
|
|
|
if( !sqlite3SafetyCheckOk(db) ){
|
|
|
|
(void)SQLITE_MISUSE_BKPT;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#endif
|
2007-08-21 20:15:55 +04:00
|
|
|
sqlite3_mutex_enter(db->mutex);
|
|
|
|
pRet = db->pRollbackArg;
|
2005-12-16 09:54:01 +03:00
|
|
|
db->xRollbackCallback = xCallback;
|
|
|
|
db->pRollbackArg = pArg;
|
2007-08-21 20:15:55 +04:00
|
|
|
sqlite3_mutex_leave(db->mutex);
|
2005-12-16 09:54:01 +03:00
|
|
|
return pRet;
|
|
|
|
}
|
2004-01-15 05:44:03 +03:00
|
|
|
|
2011-03-31 01:04:43 +04:00
|
|
|
#ifdef SQLITE_ENABLE_PREUPDATE_HOOK
|
2011-03-01 21:42:07 +03:00
|
|
|
/*
|
|
|
|
** Register a callback to be invoked each time a row is updated,
|
|
|
|
** inserted or deleted using this database connection.
|
|
|
|
*/
|
|
|
|
void *sqlite3_preupdate_hook(
|
|
|
|
sqlite3 *db, /* Attach the hook to this database */
|
|
|
|
void(*xCallback)( /* Callback function */
|
|
|
|
void*,sqlite3*,int,char const*,char const*,sqlite3_int64,sqlite3_int64),
|
|
|
|
void *pArg /* First callback argument */
|
|
|
|
){
|
|
|
|
void *pRet;
|
|
|
|
sqlite3_mutex_enter(db->mutex);
|
|
|
|
pRet = db->pPreUpdateArg;
|
|
|
|
db->xPreUpdateCallback = xCallback;
|
|
|
|
db->pPreUpdateArg = pArg;
|
|
|
|
sqlite3_mutex_leave(db->mutex);
|
|
|
|
return pRet;
|
|
|
|
}
|
2011-03-31 01:04:43 +04:00
|
|
|
#endif /* SQLITE_ENABLE_PREUPDATE_HOOK */
|
2011-03-01 21:42:07 +03:00
|
|
|
|
2010-05-03 12:04:49 +04:00
|
|
|
#ifndef SQLITE_OMIT_WAL
|
|
|
|
/*
|
|
|
|
** The sqlite3_wal_hook() callback registered by sqlite3_wal_autocheckpoint().
|
2010-05-06 00:00:25 +04:00
|
|
|
** Invoke sqlite3_wal_checkpoint if the number of frames in the log file
|
|
|
|
** is greater than sqlite3.pWalArg cast to an integer (the value configured by
|
2010-05-03 17:37:30 +04:00
|
|
|
** wal_autocheckpoint()).
|
2010-05-03 12:04:49 +04:00
|
|
|
*/
|
2010-05-03 17:37:30 +04:00
|
|
|
int sqlite3WalDefaultHook(
|
2010-05-06 00:00:25 +04:00
|
|
|
void *pClientData, /* Argument */
|
2010-05-03 17:37:30 +04:00
|
|
|
sqlite3 *db, /* Connection */
|
2010-05-06 00:00:25 +04:00
|
|
|
const char *zDb, /* Database */
|
2010-05-03 17:37:30 +04:00
|
|
|
int nFrame /* Size of WAL */
|
|
|
|
){
|
2010-05-06 00:00:25 +04:00
|
|
|
if( nFrame>=SQLITE_PTR_TO_INT(pClientData) ){
|
2010-05-25 00:27:44 +04:00
|
|
|
sqlite3BeginBenignMalloc();
|
2010-05-06 00:00:25 +04:00
|
|
|
sqlite3_wal_checkpoint(db, zDb);
|
2010-05-25 00:27:44 +04:00
|
|
|
sqlite3EndBenignMalloc();
|
2010-05-06 00:00:25 +04:00
|
|
|
}
|
|
|
|
return SQLITE_OK;
|
2010-05-03 12:04:49 +04:00
|
|
|
}
|
2010-05-03 17:37:30 +04:00
|
|
|
#endif /* SQLITE_OMIT_WAL */
|
2010-05-03 12:04:49 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
** Configure an sqlite3_wal_hook() callback to automatically checkpoint
|
|
|
|
** a database after committing a transaction if there are nFrame or
|
|
|
|
** more frames in the log file. Passing zero or a negative value as the
|
|
|
|
** nFrame parameter disables automatic checkpoints entirely.
|
|
|
|
**
|
|
|
|
** The callback registered by this function replaces any existing callback
|
|
|
|
** registered using sqlite3_wal_hook(). Likewise, registering a callback
|
|
|
|
** using sqlite3_wal_hook() disables the automatic checkpoint mechanism
|
|
|
|
** configured by this function.
|
|
|
|
*/
|
|
|
|
int sqlite3_wal_autocheckpoint(sqlite3 *db, int nFrame){
|
2010-09-01 06:38:21 +04:00
|
|
|
#ifdef SQLITE_OMIT_WAL
|
2010-09-03 07:32:46 +04:00
|
|
|
UNUSED_PARAMETER(db);
|
|
|
|
UNUSED_PARAMETER(nFrame);
|
2010-09-01 06:38:21 +04:00
|
|
|
#else
|
2014-10-24 04:35:58 +04:00
|
|
|
#ifdef SQLITE_ENABLE_API_ARMOR
|
|
|
|
if( !sqlite3SafetyCheckOk(db) ) return SQLITE_MISUSE_BKPT;
|
|
|
|
#endif
|
2010-05-03 12:04:49 +04:00
|
|
|
if( nFrame>0 ){
|
2010-05-03 17:37:30 +04:00
|
|
|
sqlite3_wal_hook(db, sqlite3WalDefaultHook, SQLITE_INT_TO_PTR(nFrame));
|
2010-05-03 12:04:49 +04:00
|
|
|
}else{
|
|
|
|
sqlite3_wal_hook(db, 0, 0);
|
|
|
|
}
|
2010-05-03 17:37:30 +04:00
|
|
|
#endif
|
2010-05-03 12:04:49 +04:00
|
|
|
return SQLITE_OK;
|
|
|
|
}
|
|
|
|
|
2010-04-19 22:03:51 +04:00
|
|
|
/*
|
|
|
|
** Register a callback to be invoked each time a transaction is written
|
|
|
|
** into the write-ahead-log by this database connection.
|
|
|
|
*/
|
2010-04-28 18:42:19 +04:00
|
|
|
void *sqlite3_wal_hook(
|
2010-04-19 22:03:51 +04:00
|
|
|
sqlite3 *db, /* Attach the hook to this db handle */
|
|
|
|
int(*xCallback)(void *, sqlite3*, const char*, int),
|
|
|
|
void *pArg /* First argument passed to xCallback() */
|
|
|
|
){
|
2010-05-03 17:37:30 +04:00
|
|
|
#ifndef SQLITE_OMIT_WAL
|
2010-04-19 22:03:51 +04:00
|
|
|
void *pRet;
|
2014-10-24 04:35:58 +04:00
|
|
|
#ifdef SQLITE_ENABLE_API_ARMOR
|
|
|
|
if( !sqlite3SafetyCheckOk(db) ){
|
|
|
|
(void)SQLITE_MISUSE_BKPT;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#endif
|
2010-04-19 22:03:51 +04:00
|
|
|
sqlite3_mutex_enter(db->mutex);
|
2010-04-30 02:34:07 +04:00
|
|
|
pRet = db->pWalArg;
|
|
|
|
db->xWalCallback = xCallback;
|
|
|
|
db->pWalArg = pArg;
|
2010-04-19 22:03:51 +04:00
|
|
|
sqlite3_mutex_leave(db->mutex);
|
|
|
|
return pRet;
|
2010-05-03 17:37:30 +04:00
|
|
|
#else
|
|
|
|
return 0;
|
|
|
|
#endif
|
2010-05-03 12:04:49 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2010-11-18 15:11:05 +03:00
|
|
|
** Checkpoint database zDb.
|
2010-05-03 12:04:49 +04:00
|
|
|
*/
|
2010-11-18 15:11:05 +03:00
|
|
|
int sqlite3_wal_checkpoint_v2(
|
|
|
|
sqlite3 *db, /* Database handle */
|
|
|
|
const char *zDb, /* Name of attached database (or NULL) */
|
|
|
|
int eMode, /* SQLITE_CHECKPOINT_* value */
|
|
|
|
int *pnLog, /* OUT: Size of WAL log in frames */
|
|
|
|
int *pnCkpt /* OUT: Total number of frames checkpointed */
|
|
|
|
){
|
2010-05-03 17:37:30 +04:00
|
|
|
#ifdef SQLITE_OMIT_WAL
|
|
|
|
return SQLITE_OK;
|
|
|
|
#else
|
2010-05-03 12:04:49 +04:00
|
|
|
int rc; /* Return code */
|
2010-05-03 18:05:43 +04:00
|
|
|
int iDb = SQLITE_MAX_ATTACHED; /* sqlite3.aDb[] index of db to checkpoint */
|
2010-05-03 12:04:49 +04:00
|
|
|
|
2014-10-24 04:35:58 +04:00
|
|
|
#ifdef SQLITE_ENABLE_API_ARMOR
|
|
|
|
if( !sqlite3SafetyCheckOk(db) ) return SQLITE_MISUSE_BKPT;
|
|
|
|
#endif
|
|
|
|
|
2011-02-07 18:12:12 +03:00
|
|
|
/* Initialize the output variables to -1 in case an error occurs. */
|
|
|
|
if( pnLog ) *pnLog = -1;
|
|
|
|
if( pnCkpt ) *pnCkpt = -1;
|
|
|
|
|
2014-12-02 22:04:54 +03:00
|
|
|
assert( SQLITE_CHECKPOINT_PASSIVE==0 );
|
|
|
|
assert( SQLITE_CHECKPOINT_FULL==1 );
|
|
|
|
assert( SQLITE_CHECKPOINT_RESTART==2 );
|
|
|
|
assert( SQLITE_CHECKPOINT_TRUNCATE==3 );
|
|
|
|
if( eMode<SQLITE_CHECKPOINT_PASSIVE || eMode>SQLITE_CHECKPOINT_TRUNCATE ){
|
2014-12-03 21:32:47 +03:00
|
|
|
/* EVIDENCE-OF: R-03996-12088 The M parameter must be a valid checkpoint
|
|
|
|
** mode: */
|
2010-11-18 15:11:05 +03:00
|
|
|
return SQLITE_MISUSE;
|
|
|
|
}
|
|
|
|
|
2010-05-03 12:04:49 +04:00
|
|
|
sqlite3_mutex_enter(db->mutex);
|
2010-05-03 19:58:50 +04:00
|
|
|
if( zDb && zDb[0] ){
|
2010-05-03 12:04:49 +04:00
|
|
|
iDb = sqlite3FindDbName(db, zDb);
|
|
|
|
}
|
|
|
|
if( iDb<0 ){
|
|
|
|
rc = SQLITE_ERROR;
|
2014-08-22 22:00:11 +04:00
|
|
|
sqlite3ErrorWithMsg(db, SQLITE_ERROR, "unknown database: %s", zDb);
|
2010-05-03 12:04:49 +04:00
|
|
|
}else{
|
2015-01-29 22:12:12 +03:00
|
|
|
db->busyHandler.nBusy = 0;
|
2010-11-18 15:11:05 +03:00
|
|
|
rc = sqlite3Checkpoint(db, iDb, eMode, pnLog, pnCkpt);
|
2014-08-22 22:00:11 +04:00
|
|
|
sqlite3Error(db, rc);
|
2010-05-03 12:04:49 +04:00
|
|
|
}
|
2010-05-03 17:37:30 +04:00
|
|
|
rc = sqlite3ApiExit(db, rc);
|
2016-08-12 19:21:15 +03:00
|
|
|
|
|
|
|
/* If there are no active statements, clear the interrupt flag at this
|
|
|
|
** point. */
|
|
|
|
if( db->nVdbeActive==0 ){
|
|
|
|
db->u1.isInterrupted = 0;
|
|
|
|
}
|
|
|
|
|
2010-05-03 12:04:49 +04:00
|
|
|
sqlite3_mutex_leave(db->mutex);
|
2010-05-03 17:37:30 +04:00
|
|
|
return rc;
|
|
|
|
#endif
|
2010-05-03 12:04:49 +04:00
|
|
|
}
|
|
|
|
|
2010-11-18 15:11:05 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
** Checkpoint database zDb. If zDb is NULL, or if the buffer zDb points
|
|
|
|
** to contains a zero-length string, all attached databases are
|
|
|
|
** checkpointed.
|
|
|
|
*/
|
|
|
|
int sqlite3_wal_checkpoint(sqlite3 *db, const char *zDb){
|
2014-12-03 21:32:47 +03:00
|
|
|
/* EVIDENCE-OF: R-41613-20553 The sqlite3_wal_checkpoint(D,X) is equivalent to
|
|
|
|
** sqlite3_wal_checkpoint_v2(D,X,SQLITE_CHECKPOINT_PASSIVE,0,0). */
|
|
|
|
return sqlite3_wal_checkpoint_v2(db,zDb,SQLITE_CHECKPOINT_PASSIVE,0,0);
|
2010-11-18 15:11:05 +03:00
|
|
|
}
|
|
|
|
|
2010-05-03 17:37:30 +04:00
|
|
|
#ifndef SQLITE_OMIT_WAL
|
2010-05-03 12:04:49 +04:00
|
|
|
/*
|
|
|
|
** Run a checkpoint on database iDb. This is a no-op if database iDb is
|
|
|
|
** not currently open in WAL mode.
|
|
|
|
**
|
2010-05-03 18:05:43 +04:00
|
|
|
** If a transaction is open on the database being checkpointed, this
|
|
|
|
** function returns SQLITE_LOCKED and a checkpoint is not attempted. If
|
|
|
|
** an error occurs while running the checkpoint, an SQLite error code is
|
|
|
|
** returned (i.e. SQLITE_IOERR). Otherwise, SQLITE_OK.
|
2010-05-03 12:04:49 +04:00
|
|
|
**
|
|
|
|
** The mutex on database handle db should be held by the caller. The mutex
|
|
|
|
** associated with the specific b-tree being checkpointed is taken by
|
|
|
|
** this function while the checkpoint is running.
|
2010-05-03 18:05:43 +04:00
|
|
|
**
|
|
|
|
** If iDb is passed SQLITE_MAX_ATTACHED, then all attached databases are
|
|
|
|
** checkpointed. If an error is encountered it is returned immediately -
|
|
|
|
** no attempt is made to checkpoint any remaining databases.
|
2010-11-16 21:56:51 +03:00
|
|
|
**
|
2017-09-08 20:48:00 +03:00
|
|
|
** Parameter eMode is one of SQLITE_CHECKPOINT_PASSIVE, FULL, RESTART
|
|
|
|
** or TRUNCATE.
|
2010-05-03 12:04:49 +04:00
|
|
|
*/
|
2010-11-18 15:11:05 +03:00
|
|
|
int sqlite3Checkpoint(sqlite3 *db, int iDb, int eMode, int *pnLog, int *pnCkpt){
|
2010-05-03 18:05:43 +04:00
|
|
|
int rc = SQLITE_OK; /* Return code */
|
|
|
|
int i; /* Used to iterate through attached dbs */
|
2010-11-18 22:28:01 +03:00
|
|
|
int bBusy = 0; /* True if SQLITE_BUSY has been encountered */
|
2010-05-03 12:04:49 +04:00
|
|
|
|
|
|
|
assert( sqlite3_mutex_held(db->mutex) );
|
2011-02-07 18:12:12 +03:00
|
|
|
assert( !pnLog || *pnLog==-1 );
|
|
|
|
assert( !pnCkpt || *pnCkpt==-1 );
|
2010-05-03 12:04:49 +04:00
|
|
|
|
2010-05-03 18:05:43 +04:00
|
|
|
for(i=0; i<db->nDb && rc==SQLITE_OK; i++){
|
|
|
|
if( i==iDb || iDb==SQLITE_MAX_ATTACHED ){
|
2010-11-18 15:11:05 +03:00
|
|
|
rc = sqlite3BtreeCheckpoint(db->aDb[i].pBt, eMode, pnLog, pnCkpt);
|
2010-11-18 22:28:01 +03:00
|
|
|
pnLog = 0;
|
|
|
|
pnCkpt = 0;
|
|
|
|
if( rc==SQLITE_BUSY ){
|
|
|
|
bBusy = 1;
|
|
|
|
rc = SQLITE_OK;
|
|
|
|
}
|
2010-05-03 18:05:43 +04:00
|
|
|
}
|
2010-05-03 12:04:49 +04:00
|
|
|
}
|
|
|
|
|
2010-11-18 22:28:01 +03:00
|
|
|
return (rc==SQLITE_OK && bBusy) ? SQLITE_BUSY : rc;
|
2010-05-03 12:04:49 +04:00
|
|
|
}
|
2010-05-03 17:37:30 +04:00
|
|
|
#endif /* SQLITE_OMIT_WAL */
|
2010-04-19 22:03:51 +04:00
|
|
|
|
2009-04-30 13:10:37 +04:00
|
|
|
/*
|
|
|
|
** This function returns true if main-memory should be used instead of
|
|
|
|
** a temporary file for transient pager files and statement journals.
|
|
|
|
** The value returned depends on the value of db->temp_store (runtime
|
|
|
|
** parameter) and the compile time value of SQLITE_TEMP_STORE. The
|
|
|
|
** following table describes the relationship between these two values
|
|
|
|
** and this functions return value.
|
|
|
|
**
|
|
|
|
** SQLITE_TEMP_STORE db->temp_store Location of temporary database
|
|
|
|
** ----------------- -------------- ------------------------------
|
|
|
|
** 0 any file (return 0)
|
|
|
|
** 1 1 file (return 0)
|
|
|
|
** 1 2 memory (return 1)
|
|
|
|
** 1 0 file (return 0)
|
|
|
|
** 2 1 file (return 0)
|
|
|
|
** 2 2 memory (return 1)
|
|
|
|
** 2 0 memory (return 1)
|
|
|
|
** 3 any memory (return 1)
|
|
|
|
*/
|
2009-04-30 16:25:10 +04:00
|
|
|
int sqlite3TempInMemory(const sqlite3 *db){
|
2009-04-30 13:10:37 +04:00
|
|
|
#if SQLITE_TEMP_STORE==1
|
|
|
|
return ( db->temp_store==2 );
|
|
|
|
#endif
|
|
|
|
#if SQLITE_TEMP_STORE==2
|
|
|
|
return ( db->temp_store!=1 );
|
|
|
|
#endif
|
|
|
|
#if SQLITE_TEMP_STORE==3
|
2015-06-15 17:43:25 +03:00
|
|
|
UNUSED_PARAMETER(db);
|
2009-04-30 13:10:37 +04:00
|
|
|
return 1;
|
2009-06-01 20:53:09 +04:00
|
|
|
#endif
|
|
|
|
#if SQLITE_TEMP_STORE<1 || SQLITE_TEMP_STORE>3
|
2015-06-15 17:43:25 +03:00
|
|
|
UNUSED_PARAMETER(db);
|
2009-04-30 13:10:37 +04:00
|
|
|
return 0;
|
2009-05-06 22:57:09 +04:00
|
|
|
#endif
|
2009-04-30 13:10:37 +04:00
|
|
|
}
|
|
|
|
|
2004-05-21 05:47:26 +04:00
|
|
|
/*
|
|
|
|
** Return UTF-8 encoded English language explanation of the most recent
|
|
|
|
** error.
|
|
|
|
*/
|
2004-05-20 15:00:52 +04:00
|
|
|
const char *sqlite3_errmsg(sqlite3 *db){
|
2004-09-30 17:43:13 +04:00
|
|
|
const char *z;
|
2008-12-10 19:45:50 +03:00
|
|
|
if( !db ){
|
2016-02-14 02:43:46 +03:00
|
|
|
return sqlite3ErrStr(SQLITE_NOMEM_BKPT);
|
2004-05-21 05:47:26 +04:00
|
|
|
}
|
2008-07-07 21:53:07 +04:00
|
|
|
if( !sqlite3SafetyCheckSickOrOk(db) ){
|
2010-02-23 23:11:56 +03:00
|
|
|
return sqlite3ErrStr(SQLITE_MISUSE_BKPT);
|
2004-06-26 13:50:11 +04:00
|
|
|
}
|
2007-08-22 06:56:42 +04:00
|
|
|
sqlite3_mutex_enter(db->mutex);
|
2009-03-19 21:51:06 +03:00
|
|
|
if( db->mallocFailed ){
|
2016-02-14 02:43:46 +03:00
|
|
|
z = sqlite3ErrStr(SQLITE_NOMEM_BKPT);
|
2009-03-19 21:51:06 +03:00
|
|
|
}else{
|
2013-12-13 20:23:55 +04:00
|
|
|
testcase( db->pErr==0 );
|
2009-03-19 21:51:06 +03:00
|
|
|
z = (char*)sqlite3_value_text(db->pErr);
|
|
|
|
assert( !db->mallocFailed );
|
|
|
|
if( z==0 ){
|
|
|
|
z = sqlite3ErrStr(db->errCode);
|
|
|
|
}
|
2004-05-20 15:00:52 +04:00
|
|
|
}
|
2007-08-21 20:15:55 +04:00
|
|
|
sqlite3_mutex_leave(db->mutex);
|
2004-09-30 17:43:13 +04:00
|
|
|
return z;
|
2004-05-20 15:00:52 +04:00
|
|
|
}
|
|
|
|
|
2004-11-15 00:56:29 +03:00
|
|
|
#ifndef SQLITE_OMIT_UTF16
|
2004-05-21 05:47:26 +04:00
|
|
|
/*
|
|
|
|
** Return UTF-16 encoded English language explanation of the most recent
|
|
|
|
** error.
|
|
|
|
*/
|
2004-05-20 15:00:52 +04:00
|
|
|
const void *sqlite3_errmsg16(sqlite3 *db){
|
2009-02-23 17:42:53 +03:00
|
|
|
static const u16 outOfMem[] = {
|
|
|
|
'o', 'u', 't', ' ', 'o', 'f', ' ', 'm', 'e', 'm', 'o', 'r', 'y', 0
|
2004-06-18 08:24:54 +04:00
|
|
|
};
|
2009-02-23 17:42:53 +03:00
|
|
|
static const u16 misuse[] = {
|
2017-07-10 15:07:53 +03:00
|
|
|
'b', 'a', 'd', ' ', 'p', 'a', 'r', 'a', 'm', 'e', 't', 'e', 'r', ' ',
|
|
|
|
'o', 'r', ' ', 'o', 't', 'h', 'e', 'r', ' ', 'A', 'P', 'I', ' ',
|
|
|
|
'm', 'i', 's', 'u', 's', 'e', 0
|
2004-06-26 13:50:11 +04:00
|
|
|
};
|
2004-06-18 08:24:54 +04:00
|
|
|
|
2004-09-30 17:43:13 +04:00
|
|
|
const void *z;
|
2007-03-29 19:00:52 +04:00
|
|
|
if( !db ){
|
2009-02-23 17:42:53 +03:00
|
|
|
return (void *)outOfMem;
|
2004-09-30 17:43:13 +04:00
|
|
|
}
|
2008-07-07 21:53:07 +04:00
|
|
|
if( !sqlite3SafetyCheckSickOrOk(db) ){
|
2009-02-23 17:42:53 +03:00
|
|
|
return (void *)misuse;
|
2004-09-30 17:43:13 +04:00
|
|
|
}
|
2007-08-21 20:15:55 +04:00
|
|
|
sqlite3_mutex_enter(db->mutex);
|
2009-03-19 21:51:06 +03:00
|
|
|
if( db->mallocFailed ){
|
|
|
|
z = (void *)outOfMem;
|
|
|
|
}else{
|
2004-09-30 17:43:13 +04:00
|
|
|
z = sqlite3_value_text16(db->pErr);
|
2009-03-19 21:51:06 +03:00
|
|
|
if( z==0 ){
|
2014-08-22 22:00:11 +04:00
|
|
|
sqlite3ErrorWithMsg(db, db->errCode, sqlite3ErrStr(db->errCode));
|
2009-03-19 21:51:06 +03:00
|
|
|
z = sqlite3_value_text16(db->pErr);
|
|
|
|
}
|
|
|
|
/* A malloc() may have failed within the call to sqlite3_value_text16()
|
|
|
|
** above. If this is the case, then the db->mallocFailed flag needs to
|
|
|
|
** be cleared before returning. Do this directly, instead of via
|
|
|
|
** sqlite3ApiExit(), to avoid setting the database handle error message.
|
|
|
|
*/
|
2016-02-05 04:55:27 +03:00
|
|
|
sqlite3OomClear(db);
|
2004-09-30 17:43:13 +04:00
|
|
|
}
|
2007-08-21 20:15:55 +04:00
|
|
|
sqlite3_mutex_leave(db->mutex);
|
2004-09-30 17:43:13 +04:00
|
|
|
return z;
|
2004-05-20 15:00:52 +04:00
|
|
|
}
|
2004-11-15 00:56:29 +03:00
|
|
|
#endif /* SQLITE_OMIT_UTF16 */
|
2004-05-20 15:00:52 +04:00
|
|
|
|
2004-09-30 17:43:13 +04:00
|
|
|
/*
|
2005-12-12 09:53:03 +03:00
|
|
|
** Return the most recent error code generated by an SQLite routine. If NULL is
|
|
|
|
** passed to this function, we assume a malloc() failed during sqlite3_open().
|
2004-09-30 17:43:13 +04:00
|
|
|
*/
|
2004-05-20 15:00:52 +04:00
|
|
|
int sqlite3_errcode(sqlite3 *db){
|
2008-01-31 18:31:01 +03:00
|
|
|
if( db && !sqlite3SafetyCheckSickOrOk(db) ){
|
2010-02-23 23:11:56 +03:00
|
|
|
return SQLITE_MISUSE_BKPT;
|
2004-09-30 17:43:13 +04:00
|
|
|
}
|
2008-01-23 15:52:40 +03:00
|
|
|
if( !db || db->mallocFailed ){
|
2016-02-14 02:43:46 +03:00
|
|
|
return SQLITE_NOMEM_BKPT;
|
2008-01-23 15:52:40 +03:00
|
|
|
}
|
2006-09-15 11:28:50 +04:00
|
|
|
return db->errCode & db->errMask;
|
2004-05-20 15:00:52 +04:00
|
|
|
}
|
2008-10-30 18:03:15 +03:00
|
|
|
int sqlite3_extended_errcode(sqlite3 *db){
|
|
|
|
if( db && !sqlite3SafetyCheckSickOrOk(db) ){
|
2010-02-23 23:11:56 +03:00
|
|
|
return SQLITE_MISUSE_BKPT;
|
2008-10-30 18:03:15 +03:00
|
|
|
}
|
|
|
|
if( !db || db->mallocFailed ){
|
2016-02-14 02:43:46 +03:00
|
|
|
return SQLITE_NOMEM_BKPT;
|
2008-10-30 18:03:15 +03:00
|
|
|
}
|
|
|
|
return db->errCode;
|
|
|
|
}
|
2016-03-17 19:01:23 +03:00
|
|
|
int sqlite3_system_errno(sqlite3 *db){
|
|
|
|
return db ? db->iSysErrno : 0;
|
|
|
|
}
|
2004-05-20 15:00:52 +04:00
|
|
|
|
2012-09-11 06:00:25 +04:00
|
|
|
/*
|
|
|
|
** Return a string that describes the kind of error specified in the
|
|
|
|
** argument. For now, this simply calls the internal sqlite3ErrStr()
|
|
|
|
** function.
|
|
|
|
*/
|
|
|
|
const char *sqlite3_errstr(int rc){
|
|
|
|
return sqlite3ErrStr(rc);
|
|
|
|
}
|
|
|
|
|
2006-02-01 16:50:41 +03:00
|
|
|
/*
|
|
|
|
** Create a new collating function for database "db". The name is zName
|
|
|
|
** and the encoding is enc.
|
|
|
|
*/
|
2006-01-18 07:26:07 +03:00
|
|
|
static int createCollation(
|
2009-08-20 06:49:30 +04:00
|
|
|
sqlite3* db,
|
2006-01-18 07:26:07 +03:00
|
|
|
const char *zName,
|
2009-09-07 08:38:36 +04:00
|
|
|
u8 enc,
|
2006-01-18 07:26:07 +03:00
|
|
|
void* pCtx,
|
2007-05-07 13:32:45 +04:00
|
|
|
int(*xCompare)(void*,int,const void*,int,const void*),
|
|
|
|
void(*xDel)(void*)
|
2006-01-18 07:26:07 +03:00
|
|
|
){
|
|
|
|
CollSeq *pColl;
|
2006-02-16 21:16:36 +03:00
|
|
|
int enc2;
|
2006-01-18 07:26:07 +03:00
|
|
|
|
2007-08-21 20:15:55 +04:00
|
|
|
assert( sqlite3_mutex_held(db->mutex) );
|
2006-01-18 07:26:07 +03:00
|
|
|
|
|
|
|
/* If SQLITE_UTF16 is specified as the encoding type, transform this
|
|
|
|
** to one of SQLITE_UTF16LE or SQLITE_UTF16BE using the
|
|
|
|
** SQLITE_UTF16NATIVE macro. SQLITE_UTF16 is not used internally.
|
|
|
|
*/
|
2009-04-27 22:46:06 +04:00
|
|
|
enc2 = enc;
|
2009-04-28 19:35:38 +04:00
|
|
|
testcase( enc2==SQLITE_UTF16 );
|
|
|
|
testcase( enc2==SQLITE_UTF16_ALIGNED );
|
|
|
|
if( enc2==SQLITE_UTF16 || enc2==SQLITE_UTF16_ALIGNED ){
|
2006-02-16 21:16:36 +03:00
|
|
|
enc2 = SQLITE_UTF16NATIVE;
|
2006-01-18 07:26:07 +03:00
|
|
|
}
|
2009-04-27 22:46:06 +04:00
|
|
|
if( enc2<SQLITE_UTF8 || enc2>SQLITE_UTF16BE ){
|
2010-02-23 23:11:56 +03:00
|
|
|
return SQLITE_MISUSE_BKPT;
|
2006-01-18 07:26:07 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Check if this call is removing or replacing an existing collation
|
|
|
|
** sequence. If so, and there are active VMs, return busy. If there
|
|
|
|
** are no active VMs, invalidate any pre-compiled statements.
|
|
|
|
*/
|
2009-05-12 00:53:28 +04:00
|
|
|
pColl = sqlite3FindCollSeq(db, (u8)enc2, zName, 0);
|
2006-01-18 07:26:07 +03:00
|
|
|
if( pColl && pColl->xCmp ){
|
2013-06-28 03:54:02 +04:00
|
|
|
if( db->nVdbeActive ){
|
2014-08-22 22:00:11 +04:00
|
|
|
sqlite3ErrorWithMsg(db, SQLITE_BUSY,
|
2009-02-04 20:40:57 +03:00
|
|
|
"unable to delete/modify collation sequence due to active statements");
|
2006-01-18 07:26:07 +03:00
|
|
|
return SQLITE_BUSY;
|
|
|
|
}
|
2018-07-25 01:02:12 +03:00
|
|
|
sqlite3ExpirePreparedStatements(db, 0);
|
2007-05-07 13:32:45 +04:00
|
|
|
|
|
|
|
/* If collation sequence pColl was created directly by a call to
|
|
|
|
** sqlite3_create_collation, and not generated by synthCollSeq(),
|
|
|
|
** then any copies made by synthCollSeq() need to be invalidated.
|
|
|
|
** Also, collation destructor - CollSeq.xDel() - function may need
|
|
|
|
** to be called.
|
|
|
|
*/
|
|
|
|
if( (pColl->enc & ~SQLITE_UTF16_ALIGNED)==enc2 ){
|
2014-08-22 00:26:37 +04:00
|
|
|
CollSeq *aColl = sqlite3HashFind(&db->aCollSeq, zName);
|
2007-05-07 13:32:45 +04:00
|
|
|
int j;
|
|
|
|
for(j=0; j<3; j++){
|
|
|
|
CollSeq *p = &aColl[j];
|
|
|
|
if( p->enc==pColl->enc ){
|
|
|
|
if( p->xDel ){
|
|
|
|
p->xDel(p->pUser);
|
|
|
|
}
|
|
|
|
p->xCmp = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2006-01-18 07:26:07 +03:00
|
|
|
}
|
|
|
|
|
2009-05-12 00:53:28 +04:00
|
|
|
pColl = sqlite3FindCollSeq(db, (u8)enc2, zName, 1);
|
2016-02-14 02:43:46 +03:00
|
|
|
if( pColl==0 ) return SQLITE_NOMEM_BKPT;
|
2010-10-11 21:58:21 +04:00
|
|
|
pColl->xCmp = xCompare;
|
|
|
|
pColl->pUser = pCtx;
|
|
|
|
pColl->xDel = xDel;
|
|
|
|
pColl->enc = (u8)(enc2 | (enc & SQLITE_UTF16_ALIGNED));
|
2014-08-22 22:00:11 +04:00
|
|
|
sqlite3Error(db, SQLITE_OK);
|
2006-01-18 07:26:07 +03:00
|
|
|
return SQLITE_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-03-20 17:03:29 +03:00
|
|
|
/*
|
|
|
|
** This array defines hard upper bounds on limit values. The
|
|
|
|
** initializer must be kept in sync with the SQLITE_LIMIT_*
|
|
|
|
** #defines in sqlite3.h.
|
|
|
|
*/
|
2008-03-20 19:30:17 +03:00
|
|
|
static const int aHardLimit[] = {
|
2008-03-20 17:03:29 +03:00
|
|
|
SQLITE_MAX_LENGTH,
|
|
|
|
SQLITE_MAX_SQL_LENGTH,
|
|
|
|
SQLITE_MAX_COLUMN,
|
|
|
|
SQLITE_MAX_EXPR_DEPTH,
|
|
|
|
SQLITE_MAX_COMPOUND_SELECT,
|
|
|
|
SQLITE_MAX_VDBE_OP,
|
|
|
|
SQLITE_MAX_FUNCTION_ARG,
|
|
|
|
SQLITE_MAX_ATTACHED,
|
|
|
|
SQLITE_MAX_LIKE_PATTERN_LENGTH,
|
2014-08-11 21:37:27 +04:00
|
|
|
SQLITE_MAX_VARIABLE_NUMBER, /* IMP: R-38091-32352 */
|
2009-09-07 22:14:02 +04:00
|
|
|
SQLITE_MAX_TRIGGER_DEPTH,
|
2014-08-29 20:20:47 +04:00
|
|
|
SQLITE_MAX_WORKER_THREADS,
|
2008-03-20 17:03:29 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
** Make sure the hard limits are set to reasonable values
|
|
|
|
*/
|
|
|
|
#if SQLITE_MAX_LENGTH<100
|
|
|
|
# error SQLITE_MAX_LENGTH must be at least 100
|
|
|
|
#endif
|
|
|
|
#if SQLITE_MAX_SQL_LENGTH<100
|
|
|
|
# error SQLITE_MAX_SQL_LENGTH must be at least 100
|
|
|
|
#endif
|
|
|
|
#if SQLITE_MAX_SQL_LENGTH>SQLITE_MAX_LENGTH
|
|
|
|
# error SQLITE_MAX_SQL_LENGTH must not be greater than SQLITE_MAX_LENGTH
|
|
|
|
#endif
|
|
|
|
#if SQLITE_MAX_COMPOUND_SELECT<2
|
|
|
|
# error SQLITE_MAX_COMPOUND_SELECT must be at least 2
|
|
|
|
#endif
|
|
|
|
#if SQLITE_MAX_VDBE_OP<40
|
|
|
|
# error SQLITE_MAX_VDBE_OP must be at least 40
|
|
|
|
#endif
|
2016-02-15 03:34:16 +03:00
|
|
|
#if SQLITE_MAX_FUNCTION_ARG<0 || SQLITE_MAX_FUNCTION_ARG>127
|
|
|
|
# error SQLITE_MAX_FUNCTION_ARG must be between 0 and 127
|
2008-03-20 17:03:29 +03:00
|
|
|
#endif
|
2014-07-22 19:33:31 +04:00
|
|
|
#if SQLITE_MAX_ATTACHED<0 || SQLITE_MAX_ATTACHED>125
|
|
|
|
# error SQLITE_MAX_ATTACHED must be between 0 and 125
|
2008-03-20 17:03:29 +03:00
|
|
|
#endif
|
|
|
|
#if SQLITE_MAX_LIKE_PATTERN_LENGTH<1
|
|
|
|
# error SQLITE_MAX_LIKE_PATTERN_LENGTH must be at least 1
|
|
|
|
#endif
|
2008-08-21 22:49:27 +04:00
|
|
|
#if SQLITE_MAX_COLUMN>32767
|
|
|
|
# error SQLITE_MAX_COLUMN must not exceed 32767
|
|
|
|
#endif
|
2009-09-07 22:14:02 +04:00
|
|
|
#if SQLITE_MAX_TRIGGER_DEPTH<1
|
|
|
|
# error SQLITE_MAX_TRIGGER_DEPTH must be at least 1
|
|
|
|
#endif
|
2014-08-29 20:20:47 +04:00
|
|
|
#if SQLITE_MAX_WORKER_THREADS<0 || SQLITE_MAX_WORKER_THREADS>50
|
|
|
|
# error SQLITE_MAX_WORKER_THREADS must be between 0 and 50
|
|
|
|
#endif
|
2008-03-20 17:03:29 +03:00
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
** Change the value of a limit. Report the old value.
|
|
|
|
** If an invalid limit index is supplied, report -1.
|
|
|
|
** Make no changes but still report the old value if the
|
|
|
|
** new limit is negative.
|
|
|
|
**
|
|
|
|
** A new lower limit does not shrink existing constructs.
|
|
|
|
** It merely prevents new constructs that exceed the limit
|
|
|
|
** from forming.
|
|
|
|
*/
|
|
|
|
int sqlite3_limit(sqlite3 *db, int limitId, int newLimit){
|
|
|
|
int oldLimit;
|
2010-09-07 18:59:15 +04:00
|
|
|
|
2014-10-24 04:35:58 +04:00
|
|
|
#ifdef SQLITE_ENABLE_API_ARMOR
|
|
|
|
if( !sqlite3SafetyCheckOk(db) ){
|
|
|
|
(void)SQLITE_MISUSE_BKPT;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
#endif
|
2010-09-07 18:59:15 +04:00
|
|
|
|
|
|
|
/* EVIDENCE-OF: R-30189-54097 For each limit category SQLITE_LIMIT_NAME
|
|
|
|
** there is a hard upper bound set at compile-time by a C preprocessor
|
|
|
|
** macro called SQLITE_MAX_NAME. (The "_LIMIT_" in the name is changed to
|
|
|
|
** "_MAX_".)
|
|
|
|
*/
|
|
|
|
assert( aHardLimit[SQLITE_LIMIT_LENGTH]==SQLITE_MAX_LENGTH );
|
|
|
|
assert( aHardLimit[SQLITE_LIMIT_SQL_LENGTH]==SQLITE_MAX_SQL_LENGTH );
|
|
|
|
assert( aHardLimit[SQLITE_LIMIT_COLUMN]==SQLITE_MAX_COLUMN );
|
|
|
|
assert( aHardLimit[SQLITE_LIMIT_EXPR_DEPTH]==SQLITE_MAX_EXPR_DEPTH );
|
|
|
|
assert( aHardLimit[SQLITE_LIMIT_COMPOUND_SELECT]==SQLITE_MAX_COMPOUND_SELECT);
|
|
|
|
assert( aHardLimit[SQLITE_LIMIT_VDBE_OP]==SQLITE_MAX_VDBE_OP );
|
|
|
|
assert( aHardLimit[SQLITE_LIMIT_FUNCTION_ARG]==SQLITE_MAX_FUNCTION_ARG );
|
|
|
|
assert( aHardLimit[SQLITE_LIMIT_ATTACHED]==SQLITE_MAX_ATTACHED );
|
|
|
|
assert( aHardLimit[SQLITE_LIMIT_LIKE_PATTERN_LENGTH]==
|
|
|
|
SQLITE_MAX_LIKE_PATTERN_LENGTH );
|
|
|
|
assert( aHardLimit[SQLITE_LIMIT_VARIABLE_NUMBER]==SQLITE_MAX_VARIABLE_NUMBER);
|
|
|
|
assert( aHardLimit[SQLITE_LIMIT_TRIGGER_DEPTH]==SQLITE_MAX_TRIGGER_DEPTH );
|
2014-08-29 20:20:47 +04:00
|
|
|
assert( aHardLimit[SQLITE_LIMIT_WORKER_THREADS]==SQLITE_MAX_WORKER_THREADS );
|
|
|
|
assert( SQLITE_LIMIT_WORKER_THREADS==(SQLITE_N_LIMIT-1) );
|
2010-09-07 18:59:15 +04:00
|
|
|
|
|
|
|
|
2008-04-15 06:36:33 +04:00
|
|
|
if( limitId<0 || limitId>=SQLITE_N_LIMIT ){
|
2008-03-20 17:03:29 +03:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
oldLimit = db->aLimit[limitId];
|
2010-09-07 18:59:15 +04:00
|
|
|
if( newLimit>=0 ){ /* IMP: R-52476-28732 */
|
2008-03-20 21:00:49 +03:00
|
|
|
if( newLimit>aHardLimit[limitId] ){
|
2010-09-07 18:59:15 +04:00
|
|
|
newLimit = aHardLimit[limitId]; /* IMP: R-51463-25634 */
|
2008-03-20 17:03:29 +03:00
|
|
|
}
|
|
|
|
db->aLimit[limitId] = newLimit;
|
|
|
|
}
|
2010-09-07 18:59:15 +04:00
|
|
|
return oldLimit; /* IMP: R-53341-35419 */
|
2008-03-20 17:03:29 +03:00
|
|
|
}
|
|
|
|
|
2011-04-22 23:37:32 +04:00
|
|
|
/*
|
2011-05-06 22:34:54 +04:00
|
|
|
** This function is used to parse both URIs and non-URI filenames passed by the
|
|
|
|
** user to API functions sqlite3_open() or sqlite3_open_v2(), and for database
|
|
|
|
** URIs specified as part of ATTACH statements.
|
|
|
|
**
|
|
|
|
** The first argument to this function is the name of the VFS to use (or
|
|
|
|
** a NULL to signify the default VFS) if the URI does not contain a "vfs=xxx"
|
|
|
|
** query parameter. The second argument contains the URI (or non-URI filename)
|
|
|
|
** itself. When this function is called the *pFlags variable should contain
|
|
|
|
** the default flags to open the database handle with. The value stored in
|
|
|
|
** *pFlags may be updated before returning if the URI filename contains
|
|
|
|
** "cache=xxx" or "mode=xxx" query parameters.
|
|
|
|
**
|
|
|
|
** If successful, SQLITE_OK is returned. In this case *ppVfs is set to point to
|
|
|
|
** the VFS that should be used to open the database file. *pzFile is set to
|
|
|
|
** point to a buffer containing the name of the file to open. It is the
|
|
|
|
** responsibility of the caller to eventually call sqlite3_free() to release
|
|
|
|
** this buffer.
|
|
|
|
**
|
|
|
|
** If an error occurs, then an SQLite error code is returned and *pzErrMsg
|
|
|
|
** may be set to point to a buffer containing an English language error
|
|
|
|
** message. It is the responsibility of the caller to eventually release
|
|
|
|
** this buffer by calling sqlite3_free().
|
2011-04-22 23:37:32 +04:00
|
|
|
*/
|
|
|
|
int sqlite3ParseUri(
|
|
|
|
const char *zDefaultVfs, /* VFS to use if no "vfs=xxx" query option */
|
|
|
|
const char *zUri, /* Nul-terminated URI to parse */
|
2011-05-07 18:40:29 +04:00
|
|
|
unsigned int *pFlags, /* IN/OUT: SQLITE_OPEN_XXX flags */
|
2011-04-22 23:37:32 +04:00
|
|
|
sqlite3_vfs **ppVfs, /* OUT: VFS to use */
|
|
|
|
char **pzFile, /* OUT: Filename component of URI */
|
|
|
|
char **pzErrMsg /* OUT: Error message (if rc!=SQLITE_OK) */
|
|
|
|
){
|
2011-05-03 14:22:32 +04:00
|
|
|
int rc = SQLITE_OK;
|
2011-05-07 18:40:29 +04:00
|
|
|
unsigned int flags = *pFlags;
|
2011-04-22 23:37:32 +04:00
|
|
|
const char *zVfs = zDefaultVfs;
|
|
|
|
char *zFile;
|
2011-05-09 23:20:17 +04:00
|
|
|
char c;
|
2011-04-22 23:37:32 +04:00
|
|
|
int nUri = sqlite3Strlen30(zUri);
|
|
|
|
|
|
|
|
assert( *pzErrMsg==0 );
|
|
|
|
|
2014-11-07 04:43:56 +03:00
|
|
|
if( ((flags & SQLITE_OPEN_URI) /* IMP: R-48725-32206 */
|
|
|
|
|| sqlite3GlobalConfig.bOpenUri) /* IMP: R-51689-46548 */
|
2014-10-04 15:59:33 +04:00
|
|
|
&& nUri>=5 && memcmp(zUri, "file:", 5)==0 /* IMP: R-57884-37496 */
|
2011-04-22 23:37:32 +04:00
|
|
|
){
|
2011-04-23 14:12:30 +04:00
|
|
|
char *zOpt;
|
2011-04-22 23:37:32 +04:00
|
|
|
int eState; /* Parser state when parsing URI */
|
|
|
|
int iIn; /* Input character index */
|
|
|
|
int iOut = 0; /* Output character index */
|
2015-04-29 19:50:28 +03:00
|
|
|
u64 nByte = nUri+2; /* Bytes of space to allocate */
|
2011-04-22 23:37:32 +04:00
|
|
|
|
2011-05-06 22:34:54 +04:00
|
|
|
/* Make sure the SQLITE_OPEN_URI flag is set to indicate to the VFS xOpen
|
|
|
|
** method that there may be extra parameters following the file-name. */
|
|
|
|
flags |= SQLITE_OPEN_URI;
|
|
|
|
|
|
|
|
for(iIn=0; iIn<nUri; iIn++) nByte += (zUri[iIn]=='&');
|
2015-04-29 19:50:28 +03:00
|
|
|
zFile = sqlite3_malloc64(nByte);
|
2016-02-14 02:43:46 +03:00
|
|
|
if( !zFile ) return SQLITE_NOMEM_BKPT;
|
2011-04-22 23:37:32 +04:00
|
|
|
|
2013-08-08 03:15:52 +04:00
|
|
|
iIn = 5;
|
2015-03-03 19:58:56 +03:00
|
|
|
#ifdef SQLITE_ALLOW_URI_AUTHORITY
|
|
|
|
if( strncmp(zUri+5, "///", 3)==0 ){
|
|
|
|
iIn = 7;
|
|
|
|
/* The following condition causes URIs with five leading / characters
|
|
|
|
** like file://///host/path to be converted into UNCs like //host/path.
|
|
|
|
** The correct URI for that UNC has only two or four leading / characters
|
|
|
|
** file://host/path or file:////host/path. But 5 leading slashes is a
|
|
|
|
** common error, we are told, so we handle it as a special case. */
|
|
|
|
if( strncmp(zUri+7, "///", 3)==0 ){ iIn++; }
|
|
|
|
}else if( strncmp(zUri+5, "//localhost/", 12)==0 ){
|
|
|
|
iIn = 16;
|
|
|
|
}
|
|
|
|
#else
|
2011-04-22 23:37:32 +04:00
|
|
|
/* Discard the scheme and authority segments of the URI. */
|
|
|
|
if( zUri[5]=='/' && zUri[6]=='/' ){
|
|
|
|
iIn = 7;
|
|
|
|
while( zUri[iIn] && zUri[iIn]!='/' ) iIn++;
|
2011-05-03 15:53:20 +04:00
|
|
|
if( iIn!=7 && (iIn!=16 || memcmp("localhost", &zUri[7], 9)) ){
|
|
|
|
*pzErrMsg = sqlite3_mprintf("invalid uri authority: %.*s",
|
|
|
|
iIn-7, &zUri[7]);
|
|
|
|
rc = SQLITE_ERROR;
|
|
|
|
goto parse_uri_out;
|
|
|
|
}
|
2011-04-22 23:37:32 +04:00
|
|
|
}
|
2013-08-08 03:15:52 +04:00
|
|
|
#endif
|
2011-04-22 23:37:32 +04:00
|
|
|
|
|
|
|
/* Copy the filename and any query parameters into the zFile buffer.
|
|
|
|
** Decode %HH escape codes along the way.
|
|
|
|
**
|
|
|
|
** Within this loop, variable eState may be set to 0, 1 or 2, depending
|
|
|
|
** on the parsing context. As follows:
|
|
|
|
**
|
|
|
|
** 0: Parsing file-name.
|
|
|
|
** 1: Parsing name section of a name=value query parameter.
|
|
|
|
** 2: Parsing value section of a name=value query parameter.
|
|
|
|
*/
|
|
|
|
eState = 0;
|
2011-05-09 23:20:17 +04:00
|
|
|
while( (c = zUri[iIn])!=0 && c!='#' ){
|
|
|
|
iIn++;
|
2011-04-22 23:37:32 +04:00
|
|
|
if( c=='%'
|
|
|
|
&& sqlite3Isxdigit(zUri[iIn])
|
|
|
|
&& sqlite3Isxdigit(zUri[iIn+1])
|
|
|
|
){
|
2011-05-03 19:09:05 +04:00
|
|
|
int octet = (sqlite3HexToInt(zUri[iIn++]) << 4);
|
|
|
|
octet += sqlite3HexToInt(zUri[iIn++]);
|
|
|
|
|
|
|
|
assert( octet>=0 && octet<256 );
|
|
|
|
if( octet==0 ){
|
2016-10-26 15:15:41 +03:00
|
|
|
#ifndef SQLITE_ENABLE_URI_00_ERROR
|
2011-04-23 14:12:30 +04:00
|
|
|
/* This branch is taken when "%00" appears within the URI. In this
|
|
|
|
** case we ignore all text in the remainder of the path, name or
|
|
|
|
** value currently being parsed. So ignore the current character
|
|
|
|
** and skip to the next "?", "=" or "&", as appropriate. */
|
2011-05-09 23:20:17 +04:00
|
|
|
while( (c = zUri[iIn])!=0 && c!='#'
|
|
|
|
&& (eState!=0 || c!='?')
|
|
|
|
&& (eState!=1 || (c!='=' && c!='&'))
|
|
|
|
&& (eState!=2 || c!='&')
|
2011-04-23 14:12:30 +04:00
|
|
|
){
|
|
|
|
iIn++;
|
|
|
|
}
|
|
|
|
continue;
|
2016-10-26 15:15:41 +03:00
|
|
|
#else
|
|
|
|
/* If ENABLE_URI_00_ERROR is defined, "%00" in a URI is an error. */
|
|
|
|
*pzErrMsg = sqlite3_mprintf("unexpected %%00 in uri");
|
|
|
|
rc = SQLITE_ERROR;
|
|
|
|
goto parse_uri_out;
|
|
|
|
#endif
|
2011-04-23 14:12:30 +04:00
|
|
|
}
|
2011-05-03 19:09:05 +04:00
|
|
|
c = octet;
|
2011-04-23 14:12:30 +04:00
|
|
|
}else if( eState==1 && (c=='&' || c=='=') ){
|
|
|
|
if( zFile[iOut-1]==0 ){
|
|
|
|
/* An empty option name. Ignore this option altogether. */
|
|
|
|
while( zUri[iIn] && zUri[iIn]!='#' && zUri[iIn-1]!='&' ) iIn++;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if( c=='&' ){
|
|
|
|
zFile[iOut++] = '\0';
|
|
|
|
}else{
|
|
|
|
eState = 2;
|
2011-04-22 23:37:32 +04:00
|
|
|
}
|
|
|
|
c = 0;
|
2011-04-23 14:12:30 +04:00
|
|
|
}else if( (eState==0 && c=='?') || (eState==2 && c=='&') ){
|
2011-04-22 23:37:32 +04:00
|
|
|
c = 0;
|
2011-04-23 14:12:30 +04:00
|
|
|
eState = 1;
|
2011-04-22 23:37:32 +04:00
|
|
|
}
|
|
|
|
zFile[iOut++] = c;
|
|
|
|
}
|
|
|
|
if( eState==1 ) zFile[iOut++] = '\0';
|
|
|
|
zFile[iOut++] = '\0';
|
|
|
|
zFile[iOut++] = '\0';
|
|
|
|
|
|
|
|
/* Check if there were any options specified that should be interpreted
|
|
|
|
** here. Options that are interpreted here include "vfs" and those that
|
|
|
|
** correspond to flags that may be passed to the sqlite3_open_v2()
|
2011-05-03 14:22:32 +04:00
|
|
|
** method. */
|
2011-04-23 14:12:30 +04:00
|
|
|
zOpt = &zFile[sqlite3Strlen30(zFile)+1];
|
|
|
|
while( zOpt[0] ){
|
|
|
|
int nOpt = sqlite3Strlen30(zOpt);
|
|
|
|
char *zVal = &zOpt[nOpt+1];
|
|
|
|
int nVal = sqlite3Strlen30(zVal);
|
2011-05-03 14:22:32 +04:00
|
|
|
|
2011-05-06 22:34:54 +04:00
|
|
|
if( nOpt==3 && memcmp("vfs", zOpt, 3)==0 ){
|
2011-05-03 14:22:32 +04:00
|
|
|
zVfs = zVal;
|
|
|
|
}else{
|
|
|
|
struct OpenMode {
|
|
|
|
const char *z;
|
|
|
|
int mode;
|
|
|
|
} *aMode = 0;
|
2011-06-03 18:19:10 +04:00
|
|
|
char *zModeType = 0;
|
|
|
|
int mask = 0;
|
|
|
|
int limit = 0;
|
2011-05-03 14:22:32 +04:00
|
|
|
|
2011-05-06 22:34:54 +04:00
|
|
|
if( nOpt==5 && memcmp("cache", zOpt, 5)==0 ){
|
2011-05-03 14:22:32 +04:00
|
|
|
static struct OpenMode aCacheMode[] = {
|
|
|
|
{ "shared", SQLITE_OPEN_SHAREDCACHE },
|
|
|
|
{ "private", SQLITE_OPEN_PRIVATECACHE },
|
|
|
|
{ 0, 0 }
|
|
|
|
};
|
|
|
|
|
|
|
|
mask = SQLITE_OPEN_SHAREDCACHE|SQLITE_OPEN_PRIVATECACHE;
|
|
|
|
aMode = aCacheMode;
|
|
|
|
limit = mask;
|
|
|
|
zModeType = "cache";
|
|
|
|
}
|
2011-05-06 22:34:54 +04:00
|
|
|
if( nOpt==4 && memcmp("mode", zOpt, 4)==0 ){
|
2011-05-03 14:22:32 +04:00
|
|
|
static struct OpenMode aOpenMode[] = {
|
|
|
|
{ "ro", SQLITE_OPEN_READONLY },
|
|
|
|
{ "rw", SQLITE_OPEN_READWRITE },
|
|
|
|
{ "rwc", SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE },
|
2012-06-07 21:16:04 +04:00
|
|
|
{ "memory", SQLITE_OPEN_MEMORY },
|
2011-05-03 14:22:32 +04:00
|
|
|
{ 0, 0 }
|
|
|
|
};
|
|
|
|
|
2012-05-28 17:58:00 +04:00
|
|
|
mask = SQLITE_OPEN_READONLY | SQLITE_OPEN_READWRITE
|
|
|
|
| SQLITE_OPEN_CREATE | SQLITE_OPEN_MEMORY;
|
2011-05-03 14:22:32 +04:00
|
|
|
aMode = aOpenMode;
|
|
|
|
limit = mask & flags;
|
|
|
|
zModeType = "access";
|
|
|
|
}
|
|
|
|
|
|
|
|
if( aMode ){
|
|
|
|
int i;
|
|
|
|
int mode = 0;
|
|
|
|
for(i=0; aMode[i].z; i++){
|
|
|
|
const char *z = aMode[i].z;
|
2011-05-07 18:40:29 +04:00
|
|
|
if( nVal==sqlite3Strlen30(z) && 0==memcmp(zVal, z, nVal) ){
|
2011-05-03 14:22:32 +04:00
|
|
|
mode = aMode[i].mode;
|
|
|
|
break;
|
2011-04-22 23:37:32 +04:00
|
|
|
}
|
|
|
|
}
|
2011-05-03 14:22:32 +04:00
|
|
|
if( mode==0 ){
|
|
|
|
*pzErrMsg = sqlite3_mprintf("no such %s mode: %s", zModeType, zVal);
|
|
|
|
rc = SQLITE_ERROR;
|
|
|
|
goto parse_uri_out;
|
|
|
|
}
|
2012-05-28 17:58:00 +04:00
|
|
|
if( (mode & ~SQLITE_OPEN_MEMORY)>limit ){
|
2011-05-09 23:20:17 +04:00
|
|
|
*pzErrMsg = sqlite3_mprintf("%s mode not allowed: %s",
|
|
|
|
zModeType, zVal);
|
2011-05-03 14:22:32 +04:00
|
|
|
rc = SQLITE_PERM;
|
|
|
|
goto parse_uri_out;
|
|
|
|
}
|
|
|
|
flags = (flags & ~mask) | mode;
|
2011-04-22 23:37:32 +04:00
|
|
|
}
|
|
|
|
}
|
2011-04-23 14:12:30 +04:00
|
|
|
|
|
|
|
zOpt = &zVal[nVal+1];
|
2011-04-22 23:37:32 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
}else{
|
2015-04-29 19:50:28 +03:00
|
|
|
zFile = sqlite3_malloc64(nUri+2);
|
2016-02-14 02:43:46 +03:00
|
|
|
if( !zFile ) return SQLITE_NOMEM_BKPT;
|
2016-12-30 17:15:56 +03:00
|
|
|
if( nUri ){
|
|
|
|
memcpy(zFile, zUri, nUri);
|
|
|
|
}
|
2011-04-22 23:37:32 +04:00
|
|
|
zFile[nUri] = '\0';
|
|
|
|
zFile[nUri+1] = '\0';
|
2012-05-27 00:08:49 +04:00
|
|
|
flags &= ~SQLITE_OPEN_URI;
|
2011-04-22 23:37:32 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
*ppVfs = sqlite3_vfs_find(zVfs);
|
|
|
|
if( *ppVfs==0 ){
|
|
|
|
*pzErrMsg = sqlite3_mprintf("no such vfs: %s", zVfs);
|
2011-05-03 14:22:32 +04:00
|
|
|
rc = SQLITE_ERROR;
|
|
|
|
}
|
|
|
|
parse_uri_out:
|
|
|
|
if( rc!=SQLITE_OK ){
|
2011-04-23 14:12:30 +04:00
|
|
|
sqlite3_free(zFile);
|
2011-05-03 14:22:32 +04:00
|
|
|
zFile = 0;
|
2011-04-22 23:37:32 +04:00
|
|
|
}
|
|
|
|
*pFlags = flags;
|
|
|
|
*pzFile = zFile;
|
2011-05-03 14:22:32 +04:00
|
|
|
return rc;
|
2011-04-22 23:37:32 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-05-21 05:47:26 +04:00
|
|
|
/*
|
|
|
|
** This routine does the work of opening a database on behalf of
|
|
|
|
** sqlite3_open() and sqlite3_open16(). The database filename "zFilename"
|
2005-04-28 16:06:05 +04:00
|
|
|
** is UTF-8 encoded.
|
2004-05-21 05:47:26 +04:00
|
|
|
*/
|
|
|
|
static int openDatabase(
|
|
|
|
const char *zFilename, /* Database filename UTF-8 encoded */
|
2007-08-21 19:13:19 +04:00
|
|
|
sqlite3 **ppDb, /* OUT: Returned database handle */
|
2011-05-07 18:40:29 +04:00
|
|
|
unsigned int flags, /* Operational flags */
|
2007-08-21 19:13:19 +04:00
|
|
|
const char *zVfs /* Name of the VFS to use */
|
2004-05-21 05:47:26 +04:00
|
|
|
){
|
2011-04-22 23:37:32 +04:00
|
|
|
sqlite3 *db; /* Store allocated handle here */
|
|
|
|
int rc; /* Return code */
|
|
|
|
int isThreadsafe; /* True for threadsafe connections */
|
|
|
|
char *zOpen = 0; /* Filename argument to pass to BtreeOpen() */
|
|
|
|
char *zErrMsg = 0; /* Error message from sqlite3ParseUri() */
|
2004-05-21 05:47:26 +04:00
|
|
|
|
2014-10-24 04:35:58 +04:00
|
|
|
#ifdef SQLITE_ENABLE_API_ARMOR
|
|
|
|
if( ppDb==0 ) return SQLITE_MISUSE_BKPT;
|
|
|
|
#endif
|
2009-04-28 08:47:31 +04:00
|
|
|
*ppDb = 0;
|
2008-06-13 22:24:27 +04:00
|
|
|
#ifndef SQLITE_OMIT_AUTOINIT
|
|
|
|
rc = sqlite3_initialize();
|
|
|
|
if( rc ) return rc;
|
|
|
|
#endif
|
|
|
|
|
2008-09-03 04:43:15 +04:00
|
|
|
if( sqlite3GlobalConfig.bCoreMutex==0 ){
|
2008-07-10 21:52:49 +04:00
|
|
|
isThreadsafe = 0;
|
2008-09-03 04:43:15 +04:00
|
|
|
}else if( flags & SQLITE_OPEN_NOMUTEX ){
|
|
|
|
isThreadsafe = 0;
|
|
|
|
}else if( flags & SQLITE_OPEN_FULLMUTEX ){
|
|
|
|
isThreadsafe = 1;
|
|
|
|
}else{
|
|
|
|
isThreadsafe = sqlite3GlobalConfig.bFullMutex;
|
2008-07-10 21:52:49 +04:00
|
|
|
}
|
2017-11-25 20:51:01 +03:00
|
|
|
|
2009-09-09 18:17:52 +04:00
|
|
|
if( flags & SQLITE_OPEN_PRIVATECACHE ){
|
2009-09-09 19:29:41 +04:00
|
|
|
flags &= ~SQLITE_OPEN_SHAREDCACHE;
|
2009-09-09 18:17:52 +04:00
|
|
|
}else if( sqlite3GlobalConfig.sharedCacheEnabled ){
|
|
|
|
flags |= SQLITE_OPEN_SHAREDCACHE;
|
|
|
|
}
|
2008-07-10 21:52:49 +04:00
|
|
|
|
2009-05-12 17:35:11 +04:00
|
|
|
/* Remove harmful bits from the flags parameter
|
|
|
|
**
|
|
|
|
** The SQLITE_OPEN_NOMUTEX and SQLITE_OPEN_FULLMUTEX flags were
|
|
|
|
** dealt with in the previous code block. Besides these, the only
|
|
|
|
** valid input flags for sqlite3_open_v2() are SQLITE_OPEN_READONLY,
|
2011-02-24 01:39:23 +03:00
|
|
|
** SQLITE_OPEN_READWRITE, SQLITE_OPEN_CREATE, SQLITE_OPEN_SHAREDCACHE,
|
|
|
|
** SQLITE_OPEN_PRIVATECACHE, and some reserved bits. Silently mask
|
2009-05-12 17:35:11 +04:00
|
|
|
** off all other flags.
|
|
|
|
*/
|
2008-02-19 18:20:44 +03:00
|
|
|
flags &= ~( SQLITE_OPEN_DELETEONCLOSE |
|
2009-05-12 17:35:11 +04:00
|
|
|
SQLITE_OPEN_EXCLUSIVE |
|
2008-02-19 18:20:44 +03:00
|
|
|
SQLITE_OPEN_MAIN_DB |
|
|
|
|
SQLITE_OPEN_TEMP_DB |
|
|
|
|
SQLITE_OPEN_TRANSIENT_DB |
|
|
|
|
SQLITE_OPEN_MAIN_JOURNAL |
|
|
|
|
SQLITE_OPEN_TEMP_JOURNAL |
|
|
|
|
SQLITE_OPEN_SUBJOURNAL |
|
2008-07-10 21:52:49 +04:00
|
|
|
SQLITE_OPEN_MASTER_JOURNAL |
|
2008-09-03 04:43:15 +04:00
|
|
|
SQLITE_OPEN_NOMUTEX |
|
2010-08-24 22:07:57 +04:00
|
|
|
SQLITE_OPEN_FULLMUTEX |
|
|
|
|
SQLITE_OPEN_WAL
|
2008-02-19 18:20:44 +03:00
|
|
|
);
|
|
|
|
|
2004-05-21 05:47:26 +04:00
|
|
|
/* Allocate the sqlite data structure */
|
2007-08-16 08:30:38 +04:00
|
|
|
db = sqlite3MallocZero( sizeof(sqlite3) );
|
2004-05-21 05:47:26 +04:00
|
|
|
if( db==0 ) goto opendb_out;
|
2017-11-25 20:51:01 +03:00
|
|
|
if( isThreadsafe
|
|
|
|
#ifdef SQLITE_ENABLE_MULTITHREADED_CHECKS
|
|
|
|
|| sqlite3GlobalConfig.bCoreMutex
|
|
|
|
#endif
|
|
|
|
){
|
2008-06-18 21:09:10 +04:00
|
|
|
db->mutex = sqlite3MutexAlloc(SQLITE_MUTEX_RECURSIVE);
|
|
|
|
if( db->mutex==0 ){
|
|
|
|
sqlite3_free(db);
|
|
|
|
db = 0;
|
|
|
|
goto opendb_out;
|
|
|
|
}
|
2017-11-25 20:51:01 +03:00
|
|
|
if( isThreadsafe==0 ){
|
|
|
|
sqlite3MutexWarnOnContention(db->mutex);
|
|
|
|
}
|
2007-08-21 19:13:19 +04:00
|
|
|
}
|
2007-08-22 06:56:42 +04:00
|
|
|
sqlite3_mutex_enter(db->mutex);
|
2006-09-15 11:28:50 +04:00
|
|
|
db->errMask = 0xff;
|
2004-05-21 05:47:26 +04:00
|
|
|
db->nDb = 2;
|
2007-08-24 07:51:33 +04:00
|
|
|
db->magic = SQLITE_MAGIC_BUSY;
|
2004-05-21 05:47:26 +04:00
|
|
|
db->aDb = db->aDbStatic;
|
2018-09-18 20:50:34 +03:00
|
|
|
db->lookaside.bDisable = 1;
|
2008-07-28 23:34:53 +04:00
|
|
|
|
2008-03-20 17:03:29 +03:00
|
|
|
assert( sizeof(db->aLimit)==sizeof(aHardLimit) );
|
|
|
|
memcpy(db->aLimit, aHardLimit, sizeof(db->aLimit));
|
2014-08-29 23:06:07 +04:00
|
|
|
db->aLimit[SQLITE_LIMIT_WORKER_THREADS] = SQLITE_DEFAULT_WORKER_THREADS;
|
2004-05-31 12:26:49 +04:00
|
|
|
db->autoCommit = 1;
|
2007-12-05 04:38:23 +03:00
|
|
|
db->nextAutovac = -1;
|
2013-04-15 21:03:42 +04:00
|
|
|
db->szMmap = sqlite3GlobalConfig.szMmap;
|
2008-03-20 14:04:21 +03:00
|
|
|
db->nextPagesize = 0;
|
2014-04-03 20:25:29 +04:00
|
|
|
db->nMaxSorterMmap = 0x7FFFFFFF;
|
2013-08-17 00:42:20 +04:00
|
|
|
db->flags |= SQLITE_ShortColNames | SQLITE_EnableTrigger | SQLITE_CacheSpill
|
2013-07-25 20:41:39 +04:00
|
|
|
#if !defined(SQLITE_DEFAULT_AUTOMATIC_INDEX) || SQLITE_DEFAULT_AUTOMATIC_INDEX
|
2013-06-29 01:12:20 +04:00
|
|
|
| SQLITE_AutoIndex
|
|
|
|
#endif
|
2015-02-19 03:29:11 +03:00
|
|
|
#if SQLITE_DEFAULT_CKPTFULLFSYNC
|
|
|
|
| SQLITE_CkptFullFSync
|
|
|
|
#endif
|
2006-07-11 18:17:51 +04:00
|
|
|
#if SQLITE_DEFAULT_FILE_FORMAT<4
|
|
|
|
| SQLITE_LegacyFileFmt
|
2007-03-28 02:24:11 +04:00
|
|
|
#endif
|
|
|
|
#ifdef SQLITE_ENABLE_LOAD_EXTENSION
|
|
|
|
| SQLITE_LoadExtension
|
2009-08-30 15:42:51 +04:00
|
|
|
#endif
|
2009-09-01 21:11:07 +04:00
|
|
|
#if SQLITE_DEFAULT_RECURSIVE_TRIGGERS
|
2009-09-01 21:28:29 +04:00
|
|
|
| SQLITE_RecTriggers
|
2010-12-09 22:15:17 +03:00
|
|
|
#endif
|
|
|
|
#if defined(SQLITE_DEFAULT_FOREIGN_KEYS) && SQLITE_DEFAULT_FOREIGN_KEYS
|
|
|
|
| SQLITE_ForeignKeys
|
2014-12-09 18:12:11 +03:00
|
|
|
#endif
|
|
|
|
#if defined(SQLITE_REVERSE_UNORDERED_SELECTS)
|
|
|
|
| SQLITE_ReverseOrder
|
2015-05-27 06:46:18 +03:00
|
|
|
#endif
|
|
|
|
#if defined(SQLITE_ENABLE_OVERSIZE_CELL_CHECK)
|
|
|
|
| SQLITE_CellSizeCk
|
2016-02-26 18:38:24 +03:00
|
|
|
#endif
|
|
|
|
#if defined(SQLITE_ENABLE_FTS3_TOKENIZER)
|
|
|
|
| SQLITE_Fts3Tokenizer
|
2017-06-26 16:57:49 +03:00
|
|
|
#endif
|
|
|
|
#if defined(SQLITE_ENABLE_QPSG)
|
|
|
|
| SQLITE_EnableQPSG
|
2018-11-07 05:17:01 +03:00
|
|
|
#endif
|
|
|
|
#if defined(SQLITE_DEFAULT_DEFENSIVE)
|
|
|
|
| SQLITE_Defensive
|
2006-07-11 18:17:51 +04:00
|
|
|
#endif
|
|
|
|
;
|
2009-05-02 17:29:37 +04:00
|
|
|
sqlite3HashInit(&db->aCollSeq);
|
2006-06-12 03:41:55 +04:00
|
|
|
#ifndef SQLITE_OMIT_VIRTUALTABLE
|
2009-05-02 17:29:37 +04:00
|
|
|
sqlite3HashInit(&db->aModule);
|
2006-06-12 03:41:55 +04:00
|
|
|
#endif
|
2006-01-05 14:34:32 +03:00
|
|
|
|
2004-06-09 13:55:16 +04:00
|
|
|
/* Add the default collation sequence BINARY. BINARY works for both UTF-8
|
|
|
|
** and UTF-16, so add a version for each to avoid any unnecessary
|
|
|
|
** conversions. The only error that can occur here is a malloc() failure.
|
2014-11-20 22:22:26 +03:00
|
|
|
**
|
|
|
|
** EVIDENCE-OF: R-52786-44878 SQLite defines three built-in collating
|
|
|
|
** functions:
|
2004-06-09 13:55:16 +04:00
|
|
|
*/
|
2015-12-30 19:51:20 +03:00
|
|
|
createCollation(db, sqlite3StrBINARY, SQLITE_UTF8, 0, binCollFunc, 0);
|
|
|
|
createCollation(db, sqlite3StrBINARY, SQLITE_UTF16BE, 0, binCollFunc, 0);
|
|
|
|
createCollation(db, sqlite3StrBINARY, SQLITE_UTF16LE, 0, binCollFunc, 0);
|
2014-11-20 22:22:26 +03:00
|
|
|
createCollation(db, "NOCASE", SQLITE_UTF8, 0, nocaseCollatingFunc, 0);
|
2011-11-29 18:46:56 +04:00
|
|
|
createCollation(db, "RTRIM", SQLITE_UTF8, (void*)1, binCollFunc, 0);
|
2008-03-18 16:01:38 +03:00
|
|
|
if( db->mallocFailed ){
|
2004-06-09 13:55:16 +04:00
|
|
|
goto opendb_out;
|
|
|
|
}
|
2014-11-20 22:22:26 +03:00
|
|
|
/* EVIDENCE-OF: R-08308-17224 The default collating function for all
|
|
|
|
** strings is BINARY.
|
|
|
|
*/
|
2015-12-30 19:51:20 +03:00
|
|
|
db->pDfltColl = sqlite3FindCollSeq(db, SQLITE_UTF8, sqlite3StrBINARY, 0);
|
2008-03-18 16:01:38 +03:00
|
|
|
assert( db->pDfltColl!=0 );
|
2004-06-09 13:55:16 +04:00
|
|
|
|
2017-07-10 15:07:53 +03:00
|
|
|
/* Parse the filename/URI argument
|
|
|
|
**
|
|
|
|
** Only allow sensible combinations of bits in the flags argument.
|
|
|
|
** Throw an error if any non-sense combination is used. If we
|
|
|
|
** do not block illegal combinations here, it could trigger
|
|
|
|
** assert() statements in deeper layers. Sensible combinations
|
|
|
|
** are:
|
|
|
|
**
|
|
|
|
** 1: SQLITE_OPEN_READONLY
|
|
|
|
** 2: SQLITE_OPEN_READWRITE
|
|
|
|
** 6: SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE
|
|
|
|
*/
|
2011-05-10 22:39:10 +04:00
|
|
|
db->openFlags = flags;
|
2017-07-10 15:07:53 +03:00
|
|
|
assert( SQLITE_OPEN_READONLY == 0x01 );
|
|
|
|
assert( SQLITE_OPEN_READWRITE == 0x02 );
|
|
|
|
assert( SQLITE_OPEN_CREATE == 0x04 );
|
|
|
|
testcase( (1<<(flags&7))==0x02 ); /* READONLY */
|
|
|
|
testcase( (1<<(flags&7))==0x04 ); /* READWRITE */
|
|
|
|
testcase( (1<<(flags&7))==0x40 ); /* READWRITE | CREATE */
|
|
|
|
if( ((1<<(flags&7)) & 0x46)==0 ){
|
|
|
|
rc = SQLITE_MISUSE_BKPT; /* IMP: R-65497-44594 */
|
|
|
|
}else{
|
|
|
|
rc = sqlite3ParseUri(zVfs, zFilename, &flags, &db->pVfs, &zOpen, &zErrMsg);
|
|
|
|
}
|
2011-04-22 23:37:32 +04:00
|
|
|
if( rc!=SQLITE_OK ){
|
2016-02-05 04:55:27 +03:00
|
|
|
if( rc==SQLITE_NOMEM ) sqlite3OomFault(db);
|
2014-08-22 22:00:11 +04:00
|
|
|
sqlite3ErrorWithMsg(db, rc, zErrMsg ? "%s" : 0, zErrMsg);
|
2011-04-22 23:37:32 +04:00
|
|
|
sqlite3_free(zErrMsg);
|
|
|
|
goto opendb_out;
|
|
|
|
}
|
|
|
|
|
2004-05-21 05:47:26 +04:00
|
|
|
/* Open the backend database driver */
|
2011-04-23 19:54:54 +04:00
|
|
|
rc = sqlite3BtreeOpen(db->pVfs, zOpen, db, &db->aDb[0].pBt, 0,
|
2010-08-30 19:02:28 +04:00
|
|
|
flags | SQLITE_OPEN_MAIN_DB);
|
2004-05-21 05:47:26 +04:00
|
|
|
if( rc!=SQLITE_OK ){
|
2008-09-23 21:39:26 +04:00
|
|
|
if( rc==SQLITE_IOERR_NOMEM ){
|
2016-02-14 02:43:46 +03:00
|
|
|
rc = SQLITE_NOMEM_BKPT;
|
2008-09-23 21:39:26 +04:00
|
|
|
}
|
2014-08-22 22:00:11 +04:00
|
|
|
sqlite3Error(db, rc);
|
2004-05-21 05:47:26 +04:00
|
|
|
goto opendb_out;
|
|
|
|
}
|
2014-12-08 23:20:16 +03:00
|
|
|
sqlite3BtreeEnter(db->aDb[0].pBt);
|
2007-08-16 08:30:38 +04:00
|
|
|
db->aDb[0].pSchema = sqlite3SchemaGet(db, db->aDb[0].pBt);
|
2014-12-13 02:17:54 +03:00
|
|
|
if( !db->mallocFailed ) ENC(db) = SCHEMA_ENC(db);
|
2014-12-08 23:20:16 +03:00
|
|
|
sqlite3BtreeLeave(db->aDb[0].pBt);
|
2007-08-16 08:30:38 +04:00
|
|
|
db->aDb[1].pSchema = sqlite3SchemaGet(db, 0);
|
2006-01-09 19:12:04 +03:00
|
|
|
|
2016-02-22 16:23:16 +03:00
|
|
|
/* The default safety_level for the main database is FULL; for the temp
|
|
|
|
** database it is OFF. This matches the pager layer defaults.
|
2005-03-29 07:10:59 +04:00
|
|
|
*/
|
2016-08-18 17:33:11 +03:00
|
|
|
db->aDb[0].zDbSName = "main";
|
2016-03-08 18:30:01 +03:00
|
|
|
db->aDb[0].safety_level = SQLITE_DEFAULT_SYNCHRONOUS+1;
|
2016-08-18 17:33:11 +03:00
|
|
|
db->aDb[1].zDbSName = "temp";
|
2016-02-22 16:23:16 +03:00
|
|
|
db->aDb[1].safety_level = PAGER_SYNCHRONOUS_OFF;
|
2005-03-29 07:10:59 +04:00
|
|
|
|
2007-06-22 19:21:15 +04:00
|
|
|
db->magic = SQLITE_MAGIC_OPEN;
|
2007-08-16 08:30:38 +04:00
|
|
|
if( db->mallocFailed ){
|
2007-06-22 19:21:15 +04:00
|
|
|
goto opendb_out;
|
|
|
|
}
|
|
|
|
|
2004-06-07 11:52:17 +04:00
|
|
|
/* Register all built-in functions, but do not attempt to read the
|
|
|
|
** database schema yet. This is delayed until the first time the database
|
|
|
|
** is accessed.
|
|
|
|
*/
|
2014-08-22 22:00:11 +04:00
|
|
|
sqlite3Error(db, SQLITE_OK);
|
2016-02-15 03:34:16 +03:00
|
|
|
sqlite3RegisterPerConnectionBuiltinFunctions(db);
|
2016-08-19 21:37:35 +03:00
|
|
|
rc = sqlite3_errcode(db);
|
|
|
|
|
|
|
|
#ifdef SQLITE_ENABLE_FTS5
|
|
|
|
/* Register any built-in FTS5 module before loading the automatic
|
|
|
|
** extensions. This allows automatic extensions to register FTS5
|
|
|
|
** tokenizers and auxiliary functions. */
|
|
|
|
if( !db->mallocFailed && rc==SQLITE_OK ){
|
|
|
|
rc = sqlite3Fts5Init(db);
|
|
|
|
}
|
|
|
|
#endif
|
2004-05-21 05:47:26 +04:00
|
|
|
|
2006-08-24 00:07:20 +04:00
|
|
|
/* Load automatic extensions - extensions that have been registered
|
|
|
|
** using the sqlite3_automatic_extension() API.
|
|
|
|
*/
|
2011-12-13 08:08:36 +04:00
|
|
|
if( rc==SQLITE_OK ){
|
|
|
|
sqlite3AutoLoadExtensions(db);
|
|
|
|
rc = sqlite3_errcode(db);
|
|
|
|
if( rc!=SQLITE_OK ){
|
|
|
|
goto opendb_out;
|
|
|
|
}
|
2007-06-22 19:21:15 +04:00
|
|
|
}
|
2006-08-24 00:07:20 +04:00
|
|
|
|
2006-09-02 17:58:06 +04:00
|
|
|
#ifdef SQLITE_ENABLE_FTS1
|
2007-08-16 08:30:38 +04:00
|
|
|
if( !db->mallocFailed ){
|
2006-09-02 17:58:06 +04:00
|
|
|
extern int sqlite3Fts1Init(sqlite3*);
|
2007-06-22 19:21:15 +04:00
|
|
|
rc = sqlite3Fts1Init(db);
|
2006-09-02 17:58:06 +04:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2006-10-20 00:27:58 +04:00
|
|
|
#ifdef SQLITE_ENABLE_FTS2
|
2007-08-16 08:30:38 +04:00
|
|
|
if( !db->mallocFailed && rc==SQLITE_OK ){
|
2006-10-20 00:27:58 +04:00
|
|
|
extern int sqlite3Fts2Init(sqlite3*);
|
2007-06-22 19:21:15 +04:00
|
|
|
rc = sqlite3Fts2Init(db);
|
2006-10-20 00:27:58 +04:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2015-10-08 22:29:18 +03:00
|
|
|
#ifdef SQLITE_ENABLE_FTS3 /* automatically defined by SQLITE_ENABLE_FTS4 */
|
2007-08-20 21:37:47 +04:00
|
|
|
if( !db->mallocFailed && rc==SQLITE_OK ){
|
|
|
|
rc = sqlite3Fts3Init(db);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2017-12-08 19:23:38 +03:00
|
|
|
#if defined(SQLITE_ENABLE_ICU) || defined(SQLITE_ENABLE_ICU_COLLATIONS)
|
2007-08-16 08:30:38 +04:00
|
|
|
if( !db->mallocFailed && rc==SQLITE_OK ){
|
2007-06-22 19:21:15 +04:00
|
|
|
rc = sqlite3IcuInit(db);
|
2007-05-06 20:04:11 +04:00
|
|
|
}
|
|
|
|
#endif
|
2008-05-26 22:41:54 +04:00
|
|
|
|
|
|
|
#ifdef SQLITE_ENABLE_RTREE
|
|
|
|
if( !db->mallocFailed && rc==SQLITE_OK){
|
|
|
|
rc = sqlite3RtreeInit(db);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2017-10-11 16:48:11 +03:00
|
|
|
#ifdef SQLITE_ENABLE_DBPAGE_VTAB
|
|
|
|
if( !db->mallocFailed && rc==SQLITE_OK){
|
|
|
|
rc = sqlite3DbpageRegister(db);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2015-05-04 23:25:05 +03:00
|
|
|
#ifdef SQLITE_ENABLE_DBSTAT_VTAB
|
|
|
|
if( !db->mallocFailed && rc==SQLITE_OK){
|
2015-05-11 14:59:15 +03:00
|
|
|
rc = sqlite3DbstatRegister(db);
|
2015-05-04 23:25:05 +03:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2015-09-26 20:44:59 +03:00
|
|
|
#ifdef SQLITE_ENABLE_JSON1
|
|
|
|
if( !db->mallocFailed && rc==SQLITE_OK){
|
|
|
|
rc = sqlite3Json1Init(db);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2017-06-29 17:33:51 +03:00
|
|
|
#ifdef SQLITE_ENABLE_STMTVTAB
|
2017-06-28 18:47:29 +03:00
|
|
|
if( !db->mallocFailed && rc==SQLITE_OK){
|
2017-06-29 17:33:51 +03:00
|
|
|
rc = sqlite3StmtVtabInit(db);
|
2017-06-28 18:47:29 +03:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2007-04-02 20:40:37 +04:00
|
|
|
/* -DSQLITE_DEFAULT_LOCKING_MODE=1 makes EXCLUSIVE the default locking
|
|
|
|
** mode. -DSQLITE_DEFAULT_LOCKING_MODE=0 make NORMAL the default locking
|
|
|
|
** mode. Doing nothing at all also makes NORMAL the default.
|
|
|
|
*/
|
|
|
|
#ifdef SQLITE_DEFAULT_LOCKING_MODE
|
|
|
|
db->dfltLockMode = SQLITE_DEFAULT_LOCKING_MODE;
|
|
|
|
sqlite3PagerLockingMode(sqlite3BtreePager(db->aDb[0].pBt),
|
|
|
|
SQLITE_DEFAULT_LOCKING_MODE);
|
|
|
|
#endif
|
|
|
|
|
2014-08-22 22:00:11 +04:00
|
|
|
if( rc ) sqlite3Error(db, rc);
|
2013-12-19 20:26:05 +04:00
|
|
|
|
2008-07-28 23:34:53 +04:00
|
|
|
/* Enable the lookaside-malloc subsystem */
|
2008-10-10 21:41:28 +04:00
|
|
|
setupLookaside(db, 0, sqlite3GlobalConfig.szLookaside,
|
|
|
|
sqlite3GlobalConfig.nLookaside);
|
2008-07-28 23:34:53 +04:00
|
|
|
|
2010-05-03 15:05:08 +04:00
|
|
|
sqlite3_wal_autocheckpoint(db, SQLITE_DEFAULT_WAL_AUTOCHECKPOINT);
|
2010-05-03 12:04:49 +04:00
|
|
|
|
2004-05-21 05:47:26 +04:00
|
|
|
opendb_out:
|
2008-02-21 05:09:45 +03:00
|
|
|
if( db ){
|
2015-03-03 17:00:11 +03:00
|
|
|
assert( db->mutex!=0 || isThreadsafe==0
|
|
|
|
|| sqlite3GlobalConfig.bFullMutex==0 );
|
2007-08-23 00:18:21 +04:00
|
|
|
sqlite3_mutex_leave(db->mutex);
|
|
|
|
}
|
2008-08-27 23:01:57 +04:00
|
|
|
rc = sqlite3_errcode(db);
|
2011-10-15 01:49:18 +04:00
|
|
|
assert( db!=0 || rc==SQLITE_NOMEM );
|
2008-08-27 23:01:57 +04:00
|
|
|
if( rc==SQLITE_NOMEM ){
|
2005-12-12 09:53:03 +03:00
|
|
|
sqlite3_close(db);
|
|
|
|
db = 0;
|
2008-08-27 23:01:57 +04:00
|
|
|
}else if( rc!=SQLITE_OK ){
|
|
|
|
db->magic = SQLITE_MAGIC_SICK;
|
2004-06-30 15:54:06 +04:00
|
|
|
}
|
2004-05-21 05:47:26 +04:00
|
|
|
*ppDb = db;
|
2012-11-26 23:50:41 +04:00
|
|
|
#ifdef SQLITE_ENABLE_SQLLOG
|
|
|
|
if( sqlite3GlobalConfig.xSqllog ){
|
2012-11-27 14:56:39 +04:00
|
|
|
/* Opening a db handle. Fourth parameter is passed 0. */
|
|
|
|
void *pArg = sqlite3GlobalConfig.pSqllogArg;
|
|
|
|
sqlite3GlobalConfig.xSqllog(pArg, db, zFilename, 0);
|
2012-11-26 23:50:41 +04:00
|
|
|
}
|
2015-10-26 17:41:35 +03:00
|
|
|
#endif
|
|
|
|
#if defined(SQLITE_HAS_CODEC)
|
|
|
|
if( rc==SQLITE_OK ){
|
2017-05-03 18:54:53 +03:00
|
|
|
const char *zKey;
|
2017-05-23 03:32:56 +03:00
|
|
|
if( (zKey = sqlite3_uri_parameter(zOpen, "hexkey"))!=0 && zKey[0] ){
|
2015-10-26 17:41:35 +03:00
|
|
|
u8 iByte;
|
|
|
|
int i;
|
2017-05-03 18:54:53 +03:00
|
|
|
char zDecoded[40];
|
|
|
|
for(i=0, iByte=0; i<sizeof(zDecoded)*2 && sqlite3Isxdigit(zKey[i]); i++){
|
|
|
|
iByte = (iByte<<4) + sqlite3HexToInt(zKey[i]);
|
|
|
|
if( (i&1)!=0 ) zDecoded[i/2] = iByte;
|
2015-10-26 17:41:35 +03:00
|
|
|
}
|
2017-05-03 18:54:53 +03:00
|
|
|
sqlite3_key_v2(db, 0, zDecoded, i/2);
|
|
|
|
}else if( (zKey = sqlite3_uri_parameter(zOpen, "key"))!=0 ){
|
|
|
|
sqlite3_key_v2(db, 0, zKey, sqlite3Strlen30(zKey));
|
2015-10-26 17:41:35 +03:00
|
|
|
}
|
|
|
|
}
|
2012-11-26 23:50:41 +04:00
|
|
|
#endif
|
2016-01-16 06:16:19 +03:00
|
|
|
sqlite3_free(zOpen);
|
2015-06-30 06:13:47 +03:00
|
|
|
return rc & 0xff;
|
2004-05-21 05:47:26 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
** Open a new database handle.
|
|
|
|
*/
|
2004-05-22 13:21:21 +04:00
|
|
|
int sqlite3_open(
|
2004-05-21 05:47:26 +04:00
|
|
|
const char *zFilename,
|
2004-06-08 04:02:33 +04:00
|
|
|
sqlite3 **ppDb
|
2004-05-21 05:47:26 +04:00
|
|
|
){
|
2007-08-21 19:13:19 +04:00
|
|
|
return openDatabase(zFilename, ppDb,
|
|
|
|
SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE, 0);
|
|
|
|
}
|
|
|
|
int sqlite3_open_v2(
|
2007-08-30 20:23:19 +04:00
|
|
|
const char *filename, /* Database filename (UTF-8) */
|
2007-08-21 19:13:19 +04:00
|
|
|
sqlite3 **ppDb, /* OUT: SQLite db handle */
|
|
|
|
int flags, /* Flags */
|
|
|
|
const char *zVfs /* Name of VFS module to use */
|
|
|
|
){
|
2011-05-07 18:40:29 +04:00
|
|
|
return openDatabase(filename, ppDb, (unsigned int)flags, zVfs);
|
2004-05-21 15:39:05 +04:00
|
|
|
}
|
|
|
|
|
2004-11-15 00:56:29 +03:00
|
|
|
#ifndef SQLITE_OMIT_UTF16
|
2004-05-21 05:47:26 +04:00
|
|
|
/*
|
|
|
|
** Open a new database handle.
|
|
|
|
*/
|
|
|
|
int sqlite3_open16(
|
|
|
|
const void *zFilename,
|
2004-06-08 04:02:33 +04:00
|
|
|
sqlite3 **ppDb
|
2004-05-21 05:47:26 +04:00
|
|
|
){
|
2004-06-18 08:24:54 +04:00
|
|
|
char const *zFilename8; /* zFilename encoded in UTF-8 instead of UTF-16 */
|
|
|
|
sqlite3_value *pVal;
|
2008-06-13 22:24:27 +04:00
|
|
|
int rc;
|
2004-05-21 05:47:26 +04:00
|
|
|
|
2014-10-24 04:35:58 +04:00
|
|
|
#ifdef SQLITE_ENABLE_API_ARMOR
|
|
|
|
if( ppDb==0 ) return SQLITE_MISUSE_BKPT;
|
|
|
|
#endif
|
2004-06-18 08:24:54 +04:00
|
|
|
*ppDb = 0;
|
2008-06-13 22:24:27 +04:00
|
|
|
#ifndef SQLITE_OMIT_AUTOINIT
|
|
|
|
rc = sqlite3_initialize();
|
|
|
|
if( rc ) return rc;
|
|
|
|
#endif
|
2014-10-24 04:35:58 +04:00
|
|
|
if( zFilename==0 ) zFilename = "\000\000";
|
2007-08-16 14:09:01 +04:00
|
|
|
pVal = sqlite3ValueNew(0);
|
2007-08-21 23:33:56 +04:00
|
|
|
sqlite3ValueSetStr(pVal, -1, zFilename, SQLITE_UTF16NATIVE, SQLITE_STATIC);
|
|
|
|
zFilename8 = sqlite3ValueText(pVal, SQLITE_UTF8);
|
2004-06-18 08:24:54 +04:00
|
|
|
if( zFilename8 ){
|
2007-08-21 19:13:19 +04:00
|
|
|
rc = openDatabase(zFilename8, ppDb,
|
|
|
|
SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE, 0);
|
2008-02-21 05:09:45 +03:00
|
|
|
assert( *ppDb || rc==SQLITE_NOMEM );
|
2008-04-28 20:19:35 +04:00
|
|
|
if( rc==SQLITE_OK && !DbHasProperty(*ppDb, 0, DB_SchemaLoaded) ){
|
2014-12-13 02:17:54 +03:00
|
|
|
SCHEMA_ENC(*ppDb) = ENC(*ppDb) = SQLITE_UTF16NATIVE;
|
2004-06-18 08:24:54 +04:00
|
|
|
}
|
2008-06-13 22:24:27 +04:00
|
|
|
}else{
|
2016-02-14 02:43:46 +03:00
|
|
|
rc = SQLITE_NOMEM_BKPT;
|
2004-05-21 05:47:26 +04:00
|
|
|
}
|
2005-12-12 09:53:03 +03:00
|
|
|
sqlite3ValueFree(pVal);
|
2004-06-07 11:52:17 +04:00
|
|
|
|
2015-06-30 06:13:47 +03:00
|
|
|
return rc & 0xff;
|
2004-05-21 05:47:26 +04:00
|
|
|
}
|
2004-11-15 00:56:29 +03:00
|
|
|
#endif /* SQLITE_OMIT_UTF16 */
|
2004-05-21 05:47:26 +04:00
|
|
|
|
2004-06-12 13:25:12 +04:00
|
|
|
/*
|
|
|
|
** Register a new collation sequence with the database handle db.
|
|
|
|
*/
|
2004-06-09 13:55:16 +04:00
|
|
|
int sqlite3_create_collation(
|
|
|
|
sqlite3* db,
|
|
|
|
const char *zName,
|
2004-06-10 06:16:01 +04:00
|
|
|
int enc,
|
2004-06-09 13:55:16 +04:00
|
|
|
void* pCtx,
|
|
|
|
int(*xCompare)(void*,int,const void*,int,const void*)
|
|
|
|
){
|
2014-10-23 05:01:26 +04:00
|
|
|
return sqlite3_create_collation_v2(db, zName, enc, pCtx, xCompare, 0);
|
2007-05-07 13:32:45 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
** Register a new collation sequence with the database handle db.
|
|
|
|
*/
|
2007-05-07 18:58:53 +04:00
|
|
|
int sqlite3_create_collation_v2(
|
2007-05-07 13:32:45 +04:00
|
|
|
sqlite3* db,
|
|
|
|
const char *zName,
|
|
|
|
int enc,
|
|
|
|
void* pCtx,
|
|
|
|
int(*xCompare)(void*,int,const void*,int,const void*),
|
|
|
|
void(*xDel)(void*)
|
|
|
|
){
|
|
|
|
int rc;
|
2014-10-24 04:35:58 +04:00
|
|
|
|
|
|
|
#ifdef SQLITE_ENABLE_API_ARMOR
|
|
|
|
if( !sqlite3SafetyCheckOk(db) || zName==0 ) return SQLITE_MISUSE_BKPT;
|
|
|
|
#endif
|
2007-08-21 20:15:55 +04:00
|
|
|
sqlite3_mutex_enter(db->mutex);
|
2007-08-16 08:30:38 +04:00
|
|
|
assert( !db->mallocFailed );
|
2011-11-29 18:46:56 +04:00
|
|
|
rc = createCollation(db, zName, (u8)enc, pCtx, xCompare, xDel);
|
2007-08-21 20:15:55 +04:00
|
|
|
rc = sqlite3ApiExit(db, rc);
|
|
|
|
sqlite3_mutex_leave(db->mutex);
|
|
|
|
return rc;
|
2004-06-09 13:55:16 +04:00
|
|
|
}
|
|
|
|
|
2004-11-15 00:56:29 +03:00
|
|
|
#ifndef SQLITE_OMIT_UTF16
|
2004-06-12 13:25:12 +04:00
|
|
|
/*
|
|
|
|
** Register a new collation sequence with the database handle db.
|
|
|
|
*/
|
2004-06-09 13:55:16 +04:00
|
|
|
int sqlite3_create_collation16(
|
|
|
|
sqlite3* db,
|
2008-06-23 15:23:14 +04:00
|
|
|
const void *zName,
|
2004-06-10 06:16:01 +04:00
|
|
|
int enc,
|
2004-06-09 13:55:16 +04:00
|
|
|
void* pCtx,
|
|
|
|
int(*xCompare)(void*,int,const void*,int,const void*)
|
|
|
|
){
|
2006-01-18 07:26:07 +03:00
|
|
|
int rc = SQLITE_OK;
|
2008-01-23 15:52:40 +03:00
|
|
|
char *zName8;
|
2014-10-24 04:35:58 +04:00
|
|
|
|
|
|
|
#ifdef SQLITE_ENABLE_API_ARMOR
|
|
|
|
if( !sqlite3SafetyCheckOk(db) || zName==0 ) return SQLITE_MISUSE_BKPT;
|
|
|
|
#endif
|
2007-08-21 20:15:55 +04:00
|
|
|
sqlite3_mutex_enter(db->mutex);
|
2007-08-16 08:30:38 +04:00
|
|
|
assert( !db->mallocFailed );
|
2010-03-05 19:32:12 +03:00
|
|
|
zName8 = sqlite3Utf16to8(db, zName, -1, SQLITE_UTF16NATIVE);
|
2006-01-18 07:26:07 +03:00
|
|
|
if( zName8 ){
|
2011-11-29 18:46:56 +04:00
|
|
|
rc = createCollation(db, zName8, (u8)enc, pCtx, xCompare, 0);
|
2008-07-28 23:34:53 +04:00
|
|
|
sqlite3DbFree(db, zName8);
|
2006-01-18 07:26:07 +03:00
|
|
|
}
|
2007-08-21 20:15:55 +04:00
|
|
|
rc = sqlite3ApiExit(db, rc);
|
|
|
|
sqlite3_mutex_leave(db->mutex);
|
|
|
|
return rc;
|
2004-06-09 13:55:16 +04:00
|
|
|
}
|
2004-11-15 00:56:29 +03:00
|
|
|
#endif /* SQLITE_OMIT_UTF16 */
|
2004-06-10 14:50:08 +04:00
|
|
|
|
2004-06-12 13:25:12 +04:00
|
|
|
/*
|
|
|
|
** Register a collation sequence factory callback with the database handle
|
|
|
|
** db. Replace any previously installed collation sequence factory.
|
|
|
|
*/
|
2004-06-10 14:50:08 +04:00
|
|
|
int sqlite3_collation_needed(
|
|
|
|
sqlite3 *db,
|
|
|
|
void *pCollNeededArg,
|
|
|
|
void(*xCollNeeded)(void*,sqlite3*,int eTextRep,const char*)
|
|
|
|
){
|
2014-10-24 04:35:58 +04:00
|
|
|
#ifdef SQLITE_ENABLE_API_ARMOR
|
|
|
|
if( !sqlite3SafetyCheckOk(db) ) return SQLITE_MISUSE_BKPT;
|
|
|
|
#endif
|
2007-08-21 20:15:55 +04:00
|
|
|
sqlite3_mutex_enter(db->mutex);
|
2004-06-10 14:50:08 +04:00
|
|
|
db->xCollNeeded = xCollNeeded;
|
|
|
|
db->xCollNeeded16 = 0;
|
|
|
|
db->pCollNeededArg = pCollNeededArg;
|
2007-08-21 20:15:55 +04:00
|
|
|
sqlite3_mutex_leave(db->mutex);
|
2004-06-10 14:50:08 +04:00
|
|
|
return SQLITE_OK;
|
|
|
|
}
|
2004-06-12 13:25:12 +04:00
|
|
|
|
2004-11-15 00:56:29 +03:00
|
|
|
#ifndef SQLITE_OMIT_UTF16
|
2004-06-12 13:25:12 +04:00
|
|
|
/*
|
|
|
|
** Register a collation sequence factory callback with the database handle
|
|
|
|
** db. Replace any previously installed collation sequence factory.
|
|
|
|
*/
|
2004-06-10 14:50:08 +04:00
|
|
|
int sqlite3_collation_needed16(
|
|
|
|
sqlite3 *db,
|
|
|
|
void *pCollNeededArg,
|
|
|
|
void(*xCollNeeded16)(void*,sqlite3*,int eTextRep,const void*)
|
|
|
|
){
|
2014-10-24 04:35:58 +04:00
|
|
|
#ifdef SQLITE_ENABLE_API_ARMOR
|
|
|
|
if( !sqlite3SafetyCheckOk(db) ) return SQLITE_MISUSE_BKPT;
|
|
|
|
#endif
|
2007-08-21 20:15:55 +04:00
|
|
|
sqlite3_mutex_enter(db->mutex);
|
2004-06-10 14:50:08 +04:00
|
|
|
db->xCollNeeded = 0;
|
|
|
|
db->xCollNeeded16 = xCollNeeded16;
|
|
|
|
db->pCollNeededArg = pCollNeededArg;
|
2007-08-21 20:15:55 +04:00
|
|
|
sqlite3_mutex_leave(db->mutex);
|
2004-06-10 14:50:08 +04:00
|
|
|
return SQLITE_OK;
|
|
|
|
}
|
2004-11-15 00:56:29 +03:00
|
|
|
#endif /* SQLITE_OMIT_UTF16 */
|
2005-03-21 07:04:02 +03:00
|
|
|
|
2008-10-12 04:27:53 +04:00
|
|
|
#ifndef SQLITE_OMIT_DEPRECATED
|
2005-03-21 07:04:02 +03:00
|
|
|
/*
|
2005-12-12 09:53:03 +03:00
|
|
|
** This function is now an anachronism. It used to be used to recover from a
|
|
|
|
** malloc() failure, but SQLite now does this automatically.
|
2005-03-21 07:04:02 +03:00
|
|
|
*/
|
2007-10-12 23:35:48 +04:00
|
|
|
int sqlite3_global_recover(void){
|
2005-12-06 15:52:59 +03:00
|
|
|
return SQLITE_OK;
|
2005-03-21 07:04:02 +03:00
|
|
|
}
|
|
|
|
#endif
|
2005-05-26 20:23:34 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
** Test to see whether or not the database connection is in autocommit
|
|
|
|
** mode. Return TRUE if it is and FALSE if not. Autocommit mode is on
|
|
|
|
** by default. Autocommit is disabled by a BEGIN statement and reenabled
|
|
|
|
** by the next COMMIT or ROLLBACK.
|
|
|
|
*/
|
|
|
|
int sqlite3_get_autocommit(sqlite3 *db){
|
2014-10-24 04:35:58 +04:00
|
|
|
#ifdef SQLITE_ENABLE_API_ARMOR
|
|
|
|
if( !sqlite3SafetyCheckOk(db) ){
|
|
|
|
(void)SQLITE_MISUSE_BKPT;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#endif
|
2005-05-26 20:23:34 +04:00
|
|
|
return db->autoCommit;
|
|
|
|
}
|
2005-09-17 19:20:26 +04:00
|
|
|
|
|
|
|
/*
|
2014-09-06 20:39:46 +04:00
|
|
|
** The following routines are substitutes for constants SQLITE_CORRUPT,
|
2016-02-14 03:14:35 +03:00
|
|
|
** SQLITE_MISUSE, SQLITE_CANTOPEN, SQLITE_NOMEM and possibly other error
|
2014-09-06 20:39:46 +04:00
|
|
|
** constants. They serve two purposes:
|
2010-02-23 20:36:32 +03:00
|
|
|
**
|
|
|
|
** 1. Serve as a convenient place to set a breakpoint in a debugger
|
|
|
|
** to detect when version error conditions occurs.
|
|
|
|
**
|
|
|
|
** 2. Invoke sqlite3_log() to provide the source code location where
|
|
|
|
** a low-level error is first detected.
|
2005-09-17 19:20:26 +04:00
|
|
|
*/
|
2017-11-18 20:30:08 +03:00
|
|
|
int sqlite3ReportError(int iErr, int lineno, const char *zType){
|
2016-02-15 21:15:15 +03:00
|
|
|
sqlite3_log(iErr, "%s at line %d of [%.10s]",
|
|
|
|
zType, lineno, 20+sqlite3_sourceid());
|
|
|
|
return iErr;
|
|
|
|
}
|
2010-02-23 20:36:32 +03:00
|
|
|
int sqlite3CorruptError(int lineno){
|
2010-02-25 00:44:07 +03:00
|
|
|
testcase( sqlite3GlobalConfig.xLog!=0 );
|
2017-11-18 20:30:08 +03:00
|
|
|
return sqlite3ReportError(SQLITE_CORRUPT, lineno, "database corruption");
|
2005-09-17 19:20:26 +04:00
|
|
|
}
|
2010-02-23 20:36:32 +03:00
|
|
|
int sqlite3MisuseError(int lineno){
|
2010-02-25 00:44:07 +03:00
|
|
|
testcase( sqlite3GlobalConfig.xLog!=0 );
|
2017-11-18 20:30:08 +03:00
|
|
|
return sqlite3ReportError(SQLITE_MISUSE, lineno, "misuse");
|
2010-02-23 20:36:32 +03:00
|
|
|
}
|
|
|
|
int sqlite3CantopenError(int lineno){
|
2010-02-25 00:44:07 +03:00
|
|
|
testcase( sqlite3GlobalConfig.xLog!=0 );
|
2017-11-18 20:30:08 +03:00
|
|
|
return sqlite3ReportError(SQLITE_CANTOPEN, lineno, "cannot open file");
|
2010-02-23 20:36:32 +03:00
|
|
|
}
|
2016-02-15 21:15:15 +03:00
|
|
|
#ifdef SQLITE_DEBUG
|
2017-06-08 01:32:59 +03:00
|
|
|
int sqlite3CorruptPgnoError(int lineno, Pgno pgno){
|
|
|
|
char zMsg[100];
|
|
|
|
sqlite3_snprintf(sizeof(zMsg), zMsg, "database corruption page %d", pgno);
|
|
|
|
testcase( sqlite3GlobalConfig.xLog!=0 );
|
2017-11-18 20:30:08 +03:00
|
|
|
return sqlite3ReportError(SQLITE_CORRUPT, lineno, zMsg);
|
2017-06-08 01:32:59 +03:00
|
|
|
}
|
2016-02-14 02:43:46 +03:00
|
|
|
int sqlite3NomemError(int lineno){
|
|
|
|
testcase( sqlite3GlobalConfig.xLog!=0 );
|
2017-11-18 20:30:08 +03:00
|
|
|
return sqlite3ReportError(SQLITE_NOMEM, lineno, "OOM");
|
2016-02-14 02:43:46 +03:00
|
|
|
}
|
|
|
|
int sqlite3IoerrnomemError(int lineno){
|
|
|
|
testcase( sqlite3GlobalConfig.xLog!=0 );
|
2017-11-18 20:30:08 +03:00
|
|
|
return sqlite3ReportError(SQLITE_IOERR_NOMEM, lineno, "I/O OOM error");
|
2016-02-14 02:43:46 +03:00
|
|
|
}
|
2016-02-15 21:15:15 +03:00
|
|
|
#endif
|
2006-01-10 16:58:48 +03:00
|
|
|
|
2008-10-12 04:27:53 +04:00
|
|
|
#ifndef SQLITE_OMIT_DEPRECATED
|
2006-01-12 00:41:20 +03:00
|
|
|
/*
|
|
|
|
** This is a convenience routine that makes sure that all thread-specific
|
|
|
|
** data for this thread has been deallocated.
|
2007-08-16 17:01:44 +04:00
|
|
|
**
|
|
|
|
** SQLite no longer uses thread-specific data so this routine is now a
|
|
|
|
** no-op. It is retained for historical compatibility.
|
2006-01-12 00:41:20 +03:00
|
|
|
*/
|
|
|
|
void sqlite3_thread_cleanup(void){
|
|
|
|
}
|
2008-10-12 04:27:53 +04:00
|
|
|
#endif
|
2006-02-09 16:43:28 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
** Return meta information about a specific column of a database table.
|
|
|
|
** See comment in sqlite3.h (sqlite.h.in) for details.
|
|
|
|
*/
|
|
|
|
int sqlite3_table_column_metadata(
|
|
|
|
sqlite3 *db, /* Connection handle */
|
|
|
|
const char *zDbName, /* Database name or NULL */
|
|
|
|
const char *zTableName, /* Table name */
|
|
|
|
const char *zColumnName, /* Column name */
|
|
|
|
char const **pzDataType, /* OUTPUT: Declared data type */
|
|
|
|
char const **pzCollSeq, /* OUTPUT: Collation sequence name */
|
|
|
|
int *pNotNull, /* OUTPUT: True if NOT NULL constraint exists */
|
|
|
|
int *pPrimaryKey, /* OUTPUT: True if column part of PK */
|
2008-06-17 00:51:15 +04:00
|
|
|
int *pAutoinc /* OUTPUT: True if column is auto-increment */
|
2006-02-09 16:43:28 +03:00
|
|
|
){
|
|
|
|
int rc;
|
|
|
|
char *zErrMsg = 0;
|
|
|
|
Table *pTab = 0;
|
|
|
|
Column *pCol = 0;
|
2015-01-12 21:38:02 +03:00
|
|
|
int iCol = 0;
|
2006-02-09 16:43:28 +03:00
|
|
|
char const *zDataType = 0;
|
|
|
|
char const *zCollSeq = 0;
|
|
|
|
int notnull = 0;
|
|
|
|
int primarykey = 0;
|
|
|
|
int autoinc = 0;
|
|
|
|
|
2015-02-13 19:36:14 +03:00
|
|
|
|
|
|
|
#ifdef SQLITE_ENABLE_API_ARMOR
|
|
|
|
if( !sqlite3SafetyCheckOk(db) || zTableName==0 ){
|
|
|
|
return SQLITE_MISUSE_BKPT;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2006-02-09 16:43:28 +03:00
|
|
|
/* Ensure the database schema has been loaded */
|
2007-08-21 20:15:55 +04:00
|
|
|
sqlite3_mutex_enter(db->mutex);
|
2008-03-08 00:37:19 +03:00
|
|
|
sqlite3BtreeEnterAll(db);
|
2006-02-09 16:43:28 +03:00
|
|
|
rc = sqlite3Init(db, &zErrMsg);
|
|
|
|
if( SQLITE_OK!=rc ){
|
|
|
|
goto error_out;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Locate the table in question */
|
|
|
|
pTab = sqlite3FindTable(db, zTableName, zDbName);
|
|
|
|
if( !pTab || pTab->pSelect ){
|
|
|
|
pTab = 0;
|
|
|
|
goto error_out;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Find the column for which info is requested */
|
2014-12-10 01:24:42 +03:00
|
|
|
if( zColumnName==0 ){
|
|
|
|
/* Query for existance of table only */
|
2006-02-09 16:43:28 +03:00
|
|
|
}else{
|
|
|
|
for(iCol=0; iCol<pTab->nCol; iCol++){
|
|
|
|
pCol = &pTab->aCol[iCol];
|
|
|
|
if( 0==sqlite3StrICmp(pCol->zName, zColumnName) ){
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if( iCol==pTab->nCol ){
|
2014-12-10 01:24:42 +03:00
|
|
|
if( HasRowid(pTab) && sqlite3IsRowid(zColumnName) ){
|
|
|
|
iCol = pTab->iPKey;
|
|
|
|
pCol = iCol>=0 ? &pTab->aCol[iCol] : 0;
|
|
|
|
}else{
|
|
|
|
pTab = 0;
|
|
|
|
goto error_out;
|
|
|
|
}
|
2006-02-09 16:43:28 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* The following block stores the meta information that will be returned
|
|
|
|
** to the caller in local variables zDataType, zCollSeq, notnull, primarykey
|
|
|
|
** and autoinc. At this point there are two possibilities:
|
|
|
|
**
|
|
|
|
** 1. The specified column name was rowid", "oid" or "_rowid_"
|
|
|
|
** and there is no explicitly declared IPK column.
|
|
|
|
**
|
|
|
|
** 2. The table is not a view and the column name identified an
|
|
|
|
** explicitly declared column. Copy meta information from *pCol.
|
|
|
|
*/
|
|
|
|
if( pCol ){
|
2016-03-22 23:05:09 +03:00
|
|
|
zDataType = sqlite3ColumnType(pCol,0);
|
2006-02-09 16:43:28 +03:00
|
|
|
zCollSeq = pCol->zColl;
|
2008-06-17 00:51:15 +04:00
|
|
|
notnull = pCol->notNull!=0;
|
2012-09-13 18:22:47 +04:00
|
|
|
primarykey = (pCol->colFlags & COLFLAG_PRIMKEY)!=0;
|
2008-08-20 20:35:10 +04:00
|
|
|
autoinc = pTab->iPKey==iCol && (pTab->tabFlags & TF_Autoincrement)!=0;
|
2006-02-09 16:43:28 +03:00
|
|
|
}else{
|
|
|
|
zDataType = "INTEGER";
|
|
|
|
primarykey = 1;
|
|
|
|
}
|
|
|
|
if( !zCollSeq ){
|
2015-12-30 19:51:20 +03:00
|
|
|
zCollSeq = sqlite3StrBINARY;
|
2006-02-09 16:43:28 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
error_out:
|
2009-02-26 10:15:59 +03:00
|
|
|
sqlite3BtreeLeaveAll(db);
|
2006-02-09 16:43:28 +03:00
|
|
|
|
|
|
|
/* Whether the function call succeeded or failed, set the output parameters
|
|
|
|
** to whatever their local counterparts contain. If an error did occur,
|
|
|
|
** this has the effect of zeroing all output parameters.
|
|
|
|
*/
|
|
|
|
if( pzDataType ) *pzDataType = zDataType;
|
|
|
|
if( pzCollSeq ) *pzCollSeq = zCollSeq;
|
|
|
|
if( pNotNull ) *pNotNull = notnull;
|
|
|
|
if( pPrimaryKey ) *pPrimaryKey = primarykey;
|
|
|
|
if( pAutoinc ) *pAutoinc = autoinc;
|
|
|
|
|
|
|
|
if( SQLITE_OK==rc && !pTab ){
|
2008-07-28 23:34:53 +04:00
|
|
|
sqlite3DbFree(db, zErrMsg);
|
2008-07-16 18:02:32 +04:00
|
|
|
zErrMsg = sqlite3MPrintf(db, "no such table column: %s.%s", zTableName,
|
2008-07-08 23:34:06 +04:00
|
|
|
zColumnName);
|
2006-02-09 16:43:28 +03:00
|
|
|
rc = SQLITE_ERROR;
|
|
|
|
}
|
2014-08-22 22:00:11 +04:00
|
|
|
sqlite3ErrorWithMsg(db, rc, (zErrMsg?"%s":0), zErrMsg);
|
2008-07-28 23:34:53 +04:00
|
|
|
sqlite3DbFree(db, zErrMsg);
|
2007-08-21 20:15:55 +04:00
|
|
|
rc = sqlite3ApiExit(db, rc);
|
|
|
|
sqlite3_mutex_leave(db->mutex);
|
2006-06-28 00:06:44 +04:00
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
** Sleep for a little while. Return the amount of time slept.
|
|
|
|
*/
|
|
|
|
int sqlite3_sleep(int ms){
|
2007-08-17 19:53:36 +04:00
|
|
|
sqlite3_vfs *pVfs;
|
2007-08-21 20:15:55 +04:00
|
|
|
int rc;
|
2007-08-21 02:48:41 +04:00
|
|
|
pVfs = sqlite3_vfs_find(0);
|
2008-06-13 22:24:27 +04:00
|
|
|
if( pVfs==0 ) return 0;
|
2007-08-18 14:59:19 +04:00
|
|
|
|
|
|
|
/* This function works in milliseconds, but the underlying OsSleep()
|
|
|
|
** API uses microseconds. Hence the 1000's.
|
|
|
|
*/
|
2007-08-21 20:15:55 +04:00
|
|
|
rc = (sqlite3OsSleep(pVfs, 1000*ms)/1000);
|
|
|
|
return rc;
|
2006-06-28 00:06:44 +04:00
|
|
|
}
|
2006-09-15 11:28:50 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
** Enable or disable the extended result codes.
|
|
|
|
*/
|
|
|
|
int sqlite3_extended_result_codes(sqlite3 *db, int onoff){
|
2014-10-24 04:35:58 +04:00
|
|
|
#ifdef SQLITE_ENABLE_API_ARMOR
|
|
|
|
if( !sqlite3SafetyCheckOk(db) ) return SQLITE_MISUSE_BKPT;
|
|
|
|
#endif
|
2007-08-21 20:15:55 +04:00
|
|
|
sqlite3_mutex_enter(db->mutex);
|
2006-09-15 11:28:50 +04:00
|
|
|
db->errMask = onoff ? 0xffffffff : 0xff;
|
2007-08-21 20:15:55 +04:00
|
|
|
sqlite3_mutex_leave(db->mutex);
|
2006-09-15 11:28:50 +04:00
|
|
|
return SQLITE_OK;
|
|
|
|
}
|
2007-08-31 20:11:35 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
** Invoke the xFileControl method on a particular database.
|
|
|
|
*/
|
|
|
|
int sqlite3_file_control(sqlite3 *db, const char *zDbName, int op, void *pArg){
|
|
|
|
int rc = SQLITE_ERROR;
|
2012-03-16 01:28:54 +04:00
|
|
|
Btree *pBtree;
|
|
|
|
|
2014-10-24 04:35:58 +04:00
|
|
|
#ifdef SQLITE_ENABLE_API_ARMOR
|
|
|
|
if( !sqlite3SafetyCheckOk(db) ) return SQLITE_MISUSE_BKPT;
|
|
|
|
#endif
|
2007-08-31 20:11:35 +04:00
|
|
|
sqlite3_mutex_enter(db->mutex);
|
2012-03-16 01:28:54 +04:00
|
|
|
pBtree = sqlite3DbNameToBtree(db, zDbName);
|
|
|
|
if( pBtree ){
|
|
|
|
Pager *pPager;
|
|
|
|
sqlite3_file *fd;
|
|
|
|
sqlite3BtreeEnter(pBtree);
|
|
|
|
pPager = sqlite3BtreePager(pBtree);
|
|
|
|
assert( pPager!=0 );
|
|
|
|
fd = sqlite3PagerFile(pPager);
|
|
|
|
assert( fd!=0 );
|
|
|
|
if( op==SQLITE_FCNTL_FILE_POINTER ){
|
|
|
|
*(sqlite3_file**)pArg = fd;
|
|
|
|
rc = SQLITE_OK;
|
2015-11-28 21:06:36 +03:00
|
|
|
}else if( op==SQLITE_FCNTL_VFS_POINTER ){
|
|
|
|
*(sqlite3_vfs**)pArg = sqlite3PagerVfs(pPager);
|
|
|
|
rc = SQLITE_OK;
|
2016-01-08 05:27:01 +03:00
|
|
|
}else if( op==SQLITE_FCNTL_JOURNAL_POINTER ){
|
|
|
|
*(sqlite3_file**)pArg = sqlite3PagerJrnlFile(pPager);
|
|
|
|
rc = SQLITE_OK;
|
2018-07-18 22:09:07 +03:00
|
|
|
}else if( op==SQLITE_FCNTL_DATA_VERSION ){
|
|
|
|
*(unsigned int*)pArg = sqlite3PagerDataVersion(pPager);
|
|
|
|
rc = SQLITE_OK;
|
2012-03-16 01:28:54 +04:00
|
|
|
}else{
|
2018-03-29 16:47:01 +03:00
|
|
|
rc = sqlite3OsFileControl(fd, op, pArg);
|
2007-08-31 20:11:35 +04:00
|
|
|
}
|
2012-03-16 01:28:54 +04:00
|
|
|
sqlite3BtreeLeave(pBtree);
|
2007-08-31 20:11:35 +04:00
|
|
|
}
|
|
|
|
sqlite3_mutex_leave(db->mutex);
|
2015-02-19 03:29:11 +03:00
|
|
|
return rc;
|
2007-08-31 20:11:35 +04:00
|
|
|
}
|
2008-01-31 17:43:24 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
** Interface to the testing logic.
|
|
|
|
*/
|
|
|
|
int sqlite3_test_control(int op, ...){
|
|
|
|
int rc = 0;
|
2016-12-07 18:49:02 +03:00
|
|
|
#ifdef SQLITE_UNTESTABLE
|
2015-06-15 17:43:25 +03:00
|
|
|
UNUSED_PARAMETER(op);
|
|
|
|
#else
|
2008-03-19 17:15:34 +03:00
|
|
|
va_list ap;
|
2008-01-31 17:43:24 +03:00
|
|
|
va_start(ap, op);
|
|
|
|
switch( op ){
|
2008-06-19 22:17:49 +04:00
|
|
|
|
2008-03-19 19:08:53 +03:00
|
|
|
/*
|
|
|
|
** Save the current state of the PRNG.
|
|
|
|
*/
|
2008-03-19 17:15:34 +03:00
|
|
|
case SQLITE_TESTCTRL_PRNG_SAVE: {
|
|
|
|
sqlite3PrngSaveState();
|
|
|
|
break;
|
|
|
|
}
|
2008-03-19 19:08:53 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
** Restore the state of the PRNG to the last state saved using
|
|
|
|
** PRNG_SAVE. If PRNG_SAVE has never before been called, then
|
|
|
|
** this verb acts like PRNG_RESET.
|
|
|
|
*/
|
2008-03-19 17:15:34 +03:00
|
|
|
case SQLITE_TESTCTRL_PRNG_RESTORE: {
|
|
|
|
sqlite3PrngRestoreState();
|
|
|
|
break;
|
|
|
|
}
|
2008-03-19 19:08:53 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
** Reset the PRNG back to its uninitialized state. The next call
|
|
|
|
** to sqlite3_randomness() will reseed the PRNG using a single call
|
|
|
|
** to the xRandomness method of the default VFS.
|
|
|
|
*/
|
2008-03-19 17:15:34 +03:00
|
|
|
case SQLITE_TESTCTRL_PRNG_RESET: {
|
2014-01-01 18:00:13 +04:00
|
|
|
sqlite3_randomness(0,0);
|
2008-03-19 17:15:34 +03:00
|
|
|
break;
|
|
|
|
}
|
2008-03-21 19:45:47 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
** sqlite3_test_control(BITVEC_TEST, size, program)
|
|
|
|
**
|
|
|
|
** Run a test against a Bitvec object of size. The program argument
|
|
|
|
** is an array of integers that defines the test. Return -1 on a
|
|
|
|
** memory allocation error, 0 on success, or non-zero for an error.
|
|
|
|
** See the sqlite3BitvecBuiltinTest() for additional information.
|
|
|
|
*/
|
|
|
|
case SQLITE_TESTCTRL_BITVEC_TEST: {
|
|
|
|
int sz = va_arg(ap, int);
|
|
|
|
int *aProg = va_arg(ap, int*);
|
|
|
|
rc = sqlite3BitvecBuiltinTest(sz, aProg);
|
|
|
|
break;
|
|
|
|
}
|
2008-06-20 18:59:51 +04:00
|
|
|
|
2014-05-16 18:17:01 +04:00
|
|
|
/*
|
|
|
|
** sqlite3_test_control(FAULT_INSTALL, xCallback)
|
|
|
|
**
|
|
|
|
** Arrange to invoke xCallback() whenever sqlite3FaultSim() is called,
|
|
|
|
** if xCallback is not NULL.
|
|
|
|
**
|
|
|
|
** As a test of the fault simulator mechanism itself, sqlite3FaultSim(0)
|
|
|
|
** is called immediately after installing the new callback and the return
|
|
|
|
** value from sqlite3FaultSim(0) becomes the return from
|
|
|
|
** sqlite3_test_control().
|
|
|
|
*/
|
|
|
|
case SQLITE_TESTCTRL_FAULT_INSTALL: {
|
2014-05-17 03:15:50 +04:00
|
|
|
/* MSVC is picky about pulling func ptrs from va lists.
|
|
|
|
** http://support.microsoft.com/kb/47961
|
2014-06-23 14:18:50 +04:00
|
|
|
** sqlite3GlobalConfig.xTestCallback = va_arg(ap, int(*)(int));
|
2014-05-17 03:15:50 +04:00
|
|
|
*/
|
|
|
|
typedef int(*TESTCALLBACKFUNC_t)(int);
|
2014-06-23 14:18:50 +04:00
|
|
|
sqlite3GlobalConfig.xTestCallback = va_arg(ap, TESTCALLBACKFUNC_t);
|
2014-05-16 18:17:01 +04:00
|
|
|
rc = sqlite3FaultSim(0);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2008-06-20 18:59:51 +04:00
|
|
|
/*
|
|
|
|
** sqlite3_test_control(BENIGN_MALLOC_HOOKS, xBegin, xEnd)
|
|
|
|
**
|
|
|
|
** Register hooks to call to indicate which malloc() failures
|
|
|
|
** are benign.
|
|
|
|
*/
|
|
|
|
case SQLITE_TESTCTRL_BENIGN_MALLOC_HOOKS: {
|
2008-06-23 18:15:52 +04:00
|
|
|
typedef void (*void_function)(void);
|
|
|
|
void_function xBenignBegin;
|
|
|
|
void_function xBenignEnd;
|
|
|
|
xBenignBegin = va_arg(ap, void_function);
|
|
|
|
xBenignEnd = va_arg(ap, void_function);
|
2008-06-20 18:59:51 +04:00
|
|
|
sqlite3BenignMallocHooks(xBenignBegin, xBenignEnd);
|
|
|
|
break;
|
|
|
|
}
|
2009-02-05 19:31:45 +03:00
|
|
|
|
|
|
|
/*
|
2009-05-09 22:59:42 +04:00
|
|
|
** sqlite3_test_control(SQLITE_TESTCTRL_PENDING_BYTE, unsigned int X)
|
2009-02-05 19:31:45 +03:00
|
|
|
**
|
|
|
|
** Set the PENDING byte to the value in the argument, if X>0.
|
|
|
|
** Make no changes if X==0. Return the value of the pending byte
|
|
|
|
** as it existing before this routine was called.
|
|
|
|
**
|
|
|
|
** IMPORTANT: Changing the PENDING byte from 0x40000000 results in
|
|
|
|
** an incompatible database file format. Changing the PENDING byte
|
|
|
|
** while any database connection is open results in undefined and
|
2014-09-06 20:39:46 +04:00
|
|
|
** deleterious behavior.
|
2009-02-05 19:31:45 +03:00
|
|
|
*/
|
|
|
|
case SQLITE_TESTCTRL_PENDING_BYTE: {
|
2010-06-03 16:09:52 +04:00
|
|
|
rc = PENDING_BYTE;
|
|
|
|
#ifndef SQLITE_OMIT_WSD
|
|
|
|
{
|
|
|
|
unsigned int newVal = va_arg(ap, unsigned int);
|
|
|
|
if( newVal ) sqlite3PendingByte = newVal;
|
|
|
|
}
|
|
|
|
#endif
|
2009-02-05 19:31:45 +03:00
|
|
|
break;
|
|
|
|
}
|
2009-05-09 22:59:42 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
** sqlite3_test_control(SQLITE_TESTCTRL_ASSERT, int X)
|
|
|
|
**
|
|
|
|
** This action provides a run-time test to see whether or not
|
|
|
|
** assert() was enabled at compile-time. If X is true and assert()
|
|
|
|
** is enabled, then the return value is true. If X is true and
|
|
|
|
** assert() is disabled, then the return value is zero. If X is
|
|
|
|
** false and assert() is enabled, then the assertion fires and the
|
|
|
|
** process aborts. If X is false and assert() is disabled, then the
|
|
|
|
** return value is zero.
|
|
|
|
*/
|
|
|
|
case SQLITE_TESTCTRL_ASSERT: {
|
|
|
|
volatile int x = 0;
|
2016-02-07 01:32:06 +03:00
|
|
|
assert( /*side-effects-ok*/ (x = va_arg(ap,int))!=0 );
|
2009-05-09 22:59:42 +04:00
|
|
|
rc = x;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
** sqlite3_test_control(SQLITE_TESTCTRL_ALWAYS, int X)
|
|
|
|
**
|
|
|
|
** This action provides a run-time test to see how the ALWAYS and
|
|
|
|
** NEVER macros were defined at compile-time.
|
|
|
|
**
|
2017-10-03 20:17:34 +03:00
|
|
|
** The return value is ALWAYS(X) if X is true, or 0 if X is false.
|
2009-05-09 22:59:42 +04:00
|
|
|
**
|
|
|
|
** The recommended test is X==2. If the return value is 2, that means
|
|
|
|
** ALWAYS() and NEVER() are both no-op pass-through macros, which is the
|
|
|
|
** default setting. If the return value is 1, then ALWAYS() is either
|
|
|
|
** hard-coded to true or else it asserts if its argument is false.
|
|
|
|
** The first behavior (hard-coded to true) is the case if
|
|
|
|
** SQLITE_TESTCTRL_ASSERT shows that assert() is disabled and the second
|
|
|
|
** behavior (assert if the argument to ALWAYS() is false) is the case if
|
|
|
|
** SQLITE_TESTCTRL_ASSERT shows that assert() is enabled.
|
|
|
|
**
|
|
|
|
** The run-time test procedure might look something like this:
|
|
|
|
**
|
|
|
|
** if( sqlite3_test_control(SQLITE_TESTCTRL_ALWAYS, 2)==2 ){
|
|
|
|
** // ALWAYS() and NEVER() are no-op pass-through macros
|
|
|
|
** }else if( sqlite3_test_control(SQLITE_TESTCTRL_ASSERT, 1) ){
|
|
|
|
** // ALWAYS(x) asserts that x is true. NEVER(x) asserts x is false.
|
|
|
|
** }else{
|
|
|
|
** // ALWAYS(x) is a constant 1. NEVER(x) is a constant 0.
|
|
|
|
** }
|
|
|
|
*/
|
|
|
|
case SQLITE_TESTCTRL_ALWAYS: {
|
|
|
|
int x = va_arg(ap,int);
|
2017-10-03 20:17:34 +03:00
|
|
|
rc = x ? ALWAYS(x) : 0;
|
2009-05-09 22:59:42 +04:00
|
|
|
break;
|
|
|
|
}
|
2009-07-15 15:26:44 +04:00
|
|
|
|
2014-04-18 04:06:02 +04:00
|
|
|
/*
|
|
|
|
** sqlite3_test_control(SQLITE_TESTCTRL_BYTEORDER);
|
|
|
|
**
|
|
|
|
** The integer returned reveals the byte-order of the computer on which
|
|
|
|
** SQLite is running:
|
|
|
|
**
|
|
|
|
** 1 big-endian, determined at run-time
|
|
|
|
** 10 little-endian, determined at run-time
|
|
|
|
** 432101 big-endian, determined at compile-time
|
|
|
|
** 123410 little-endian, determined at compile-time
|
|
|
|
*/
|
|
|
|
case SQLITE_TESTCTRL_BYTEORDER: {
|
|
|
|
rc = SQLITE_BYTEORDER*100 + SQLITE_LITTLEENDIAN*10 + SQLITE_BIGENDIAN;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2009-07-15 15:26:44 +04:00
|
|
|
/* sqlite3_test_control(SQLITE_TESTCTRL_RESERVE, sqlite3 *db, int N)
|
|
|
|
**
|
|
|
|
** Set the nReserve size to N for the main database on the database
|
|
|
|
** connection db.
|
|
|
|
*/
|
|
|
|
case SQLITE_TESTCTRL_RESERVE: {
|
|
|
|
sqlite3 *db = va_arg(ap, sqlite3*);
|
|
|
|
int x = va_arg(ap,int);
|
|
|
|
sqlite3_mutex_enter(db->mutex);
|
|
|
|
sqlite3BtreeSetPageSize(db->aDb[0].pBt, 0, x, 0);
|
|
|
|
sqlite3_mutex_leave(db->mutex);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2009-12-23 02:52:32 +03:00
|
|
|
/* sqlite3_test_control(SQLITE_TESTCTRL_OPTIMIZATIONS, sqlite3 *db, int N)
|
|
|
|
**
|
|
|
|
** Enable or disable various optimizations for testing purposes. The
|
|
|
|
** argument N is a bitmask of optimizations to be disabled. For normal
|
|
|
|
** operation N should be 0. The idea is that a test program (like the
|
|
|
|
** SQL Logic Test or SLT test module) can run the same SQL multiple times
|
|
|
|
** with various optimizations disabled to verify that the same answer
|
|
|
|
** is obtained in every case.
|
|
|
|
*/
|
|
|
|
case SQLITE_TESTCTRL_OPTIMIZATIONS: {
|
|
|
|
sqlite3 *db = va_arg(ap, sqlite3*);
|
2012-10-30 18:39:12 +04:00
|
|
|
db->dbOptFlags = (u16)(va_arg(ap, int) & 0xffff);
|
2009-12-23 02:52:32 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2011-06-21 16:47:30 +04:00
|
|
|
/* sqlite3_test_control(SQLITE_TESTCTRL_LOCALTIME_FAULT, int onoff);
|
|
|
|
**
|
2018-11-26 21:09:15 +03:00
|
|
|
** If parameter onoff is non-zero, subsequent calls to localtime()
|
|
|
|
** and its variants fail. If onoff is zero, undo this setting.
|
2011-06-21 16:47:30 +04:00
|
|
|
*/
|
|
|
|
case SQLITE_TESTCTRL_LOCALTIME_FAULT: {
|
|
|
|
sqlite3GlobalConfig.bLocaltimeFault = va_arg(ap, int);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2018-11-26 21:09:15 +03:00
|
|
|
/* sqlite3_test_control(SQLITE_TESTCTRL_INTERNAL_FUNCS, int onoff);
|
|
|
|
**
|
|
|
|
** If parameter onoff is non-zero, internal-use-only SQL functions
|
|
|
|
** are visible to ordinary SQL. This is useful for testing but is
|
|
|
|
** unsafe because invalid parameters to those internal-use-only functions
|
|
|
|
** can result in crashes or segfaults.
|
|
|
|
*/
|
|
|
|
case SQLITE_TESTCTRL_INTERNAL_FUNCTIONS: {
|
|
|
|
sqlite3GlobalConfig.bInternalFunctions = va_arg(ap, int);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2013-11-29 19:06:27 +04:00
|
|
|
/* sqlite3_test_control(SQLITE_TESTCTRL_NEVER_CORRUPT, int);
|
|
|
|
**
|
|
|
|
** Set or clear a flag that indicates that the database file is always well-
|
|
|
|
** formed and never corrupt. This flag is clear by default, indicating that
|
|
|
|
** database files might have arbitrary corruption. Setting the flag during
|
|
|
|
** testing causes certain assert() statements in the code to be activated
|
|
|
|
** that demonstrat invariants on well-formed database files.
|
|
|
|
*/
|
|
|
|
case SQLITE_TESTCTRL_NEVER_CORRUPT: {
|
2014-01-28 21:49:13 +04:00
|
|
|
sqlite3GlobalConfig.neverCorrupt = va_arg(ap, int);
|
2013-11-29 19:06:27 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2016-09-18 19:08:10 +03:00
|
|
|
/* Set the threshold at which OP_Once counters reset back to zero.
|
2016-09-20 20:38:27 +03:00
|
|
|
** By default this is 0x7ffffffe (over 2 billion), but that value is
|
2016-09-18 19:08:10 +03:00
|
|
|
** too big to test in a reasonable amount of time, so this control is
|
|
|
|
** provided to set a small and easily reachable reset value.
|
|
|
|
*/
|
|
|
|
case SQLITE_TESTCTRL_ONCE_RESET_THRESHOLD: {
|
|
|
|
sqlite3GlobalConfig.iOnceResetThreshold = va_arg(ap, int);
|
|
|
|
break;
|
|
|
|
}
|
2014-02-18 02:40:43 +04:00
|
|
|
|
|
|
|
/* sqlite3_test_control(SQLITE_TESTCTRL_VDBE_COVERAGE, xCallback, ptr);
|
|
|
|
**
|
|
|
|
** Set the VDBE coverage callback function to xCallback with context
|
|
|
|
** pointer ptr.
|
|
|
|
*/
|
|
|
|
case SQLITE_TESTCTRL_VDBE_COVERAGE: {
|
|
|
|
#ifdef SQLITE_VDBE_COVERAGE
|
2018-07-10 19:04:04 +03:00
|
|
|
typedef void (*branch_callback)(void*,unsigned int,
|
|
|
|
unsigned char,unsigned char);
|
2014-02-18 02:40:43 +04:00
|
|
|
sqlite3GlobalConfig.xVdbeBranch = va_arg(ap,branch_callback);
|
|
|
|
sqlite3GlobalConfig.pVdbeBranchArg = va_arg(ap,void*);
|
|
|
|
#endif
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2014-04-03 20:25:29 +04:00
|
|
|
/* sqlite3_test_control(SQLITE_TESTCTRL_SORTER_MMAP, db, nMax); */
|
|
|
|
case SQLITE_TESTCTRL_SORTER_MMAP: {
|
|
|
|
sqlite3 *db = va_arg(ap, sqlite3*);
|
|
|
|
db->nMaxSorterMmap = va_arg(ap, int);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2014-07-29 18:09:21 +04:00
|
|
|
/* sqlite3_test_control(SQLITE_TESTCTRL_ISINIT);
|
|
|
|
**
|
|
|
|
** Return SQLITE_OK if SQLite has been initialized and SQLITE_ERROR if
|
|
|
|
** not.
|
|
|
|
*/
|
|
|
|
case SQLITE_TESTCTRL_ISINIT: {
|
|
|
|
if( sqlite3GlobalConfig.isInit==0 ) rc = SQLITE_ERROR;
|
|
|
|
break;
|
|
|
|
}
|
2015-01-29 20:54:52 +03:00
|
|
|
|
2015-03-03 17:00:11 +03:00
|
|
|
/* sqlite3_test_control(SQLITE_TESTCTRL_IMPOSTER, db, dbName, onOff, tnum);
|
2015-01-29 20:54:52 +03:00
|
|
|
**
|
2015-01-30 23:59:27 +03:00
|
|
|
** This test control is used to create imposter tables. "db" is a pointer
|
|
|
|
** to the database connection. dbName is the database name (ex: "main" or
|
|
|
|
** "temp") which will receive the imposter. "onOff" turns imposter mode on
|
|
|
|
** or off. "tnum" is the root page of the b-tree to which the imposter
|
|
|
|
** table should connect.
|
|
|
|
**
|
|
|
|
** Enable imposter mode only when the schema has already been parsed. Then
|
2015-03-03 17:00:11 +03:00
|
|
|
** run a single CREATE TABLE statement to construct the imposter table in
|
|
|
|
** the parsed schema. Then turn imposter mode back off again.
|
2015-01-30 23:59:27 +03:00
|
|
|
**
|
|
|
|
** If onOff==0 and tnum>0 then reset the schema for all databases, causing
|
|
|
|
** the schema to be reparsed the next time it is needed. This has the
|
|
|
|
** effect of erasing all imposter tables.
|
2015-01-29 20:54:52 +03:00
|
|
|
*/
|
2015-01-30 23:59:27 +03:00
|
|
|
case SQLITE_TESTCTRL_IMPOSTER: {
|
2015-01-29 20:54:52 +03:00
|
|
|
sqlite3 *db = va_arg(ap, sqlite3*);
|
2015-02-04 23:56:49 +03:00
|
|
|
sqlite3_mutex_enter(db->mutex);
|
2015-01-30 23:59:27 +03:00
|
|
|
db->init.iDb = sqlite3FindDbName(db, va_arg(ap,const char*));
|
|
|
|
db->init.busy = db->init.imposterTable = va_arg(ap,int);
|
2015-01-29 20:54:52 +03:00
|
|
|
db->init.newTnum = va_arg(ap,int);
|
2015-01-30 23:59:27 +03:00
|
|
|
if( db->init.busy==0 && db->init.newTnum>0 ){
|
|
|
|
sqlite3ResetAllSchemasOfConnection(db);
|
|
|
|
}
|
2015-02-04 23:56:49 +03:00
|
|
|
sqlite3_mutex_leave(db->mutex);
|
2015-01-29 20:54:52 +03:00
|
|
|
break;
|
|
|
|
}
|
2017-12-26 21:04:23 +03:00
|
|
|
|
|
|
|
#if defined(YYCOVERAGE)
|
|
|
|
/* sqlite3_test_control(SQLITE_TESTCTRL_PARSER_COVERAGE, FILE *out)
|
|
|
|
**
|
|
|
|
** This test control (only available when SQLite is compiled with
|
|
|
|
** -DYYCOVERAGE) writes a report onto "out" that shows all
|
|
|
|
** state/lookahead combinations in the parser state machine
|
|
|
|
** which are never exercised. If any state is missed, make the
|
|
|
|
** return code SQLITE_ERROR.
|
|
|
|
*/
|
|
|
|
case SQLITE_TESTCTRL_PARSER_COVERAGE: {
|
|
|
|
FILE *out = va_arg(ap, FILE*);
|
|
|
|
if( sqlite3ParserCoverage(out) ) rc = SQLITE_ERROR;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
#endif /* defined(YYCOVERAGE) */
|
2008-01-31 17:43:24 +03:00
|
|
|
}
|
|
|
|
va_end(ap);
|
2016-12-07 18:49:02 +03:00
|
|
|
#endif /* SQLITE_UNTESTABLE */
|
2008-01-31 18:31:01 +03:00
|
|
|
return rc;
|
2008-01-31 17:43:24 +03:00
|
|
|
}
|
2011-05-17 22:53:08 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
** This is a utility routine, useful to VFS implementations, that checks
|
|
|
|
** to see if a database file was a URI that contained a specific query
|
|
|
|
** parameter, and if so obtains the value of the query parameter.
|
|
|
|
**
|
|
|
|
** The zFilename argument is the filename pointer passed into the xOpen()
|
|
|
|
** method of a VFS implementation. The zParam argument is the name of the
|
|
|
|
** query parameter we seek. This routine returns the value of the zParam
|
|
|
|
** parameter if it exists. If the parameter does not exist, this routine
|
|
|
|
** returns a NULL pointer.
|
|
|
|
*/
|
|
|
|
const char *sqlite3_uri_parameter(const char *zFilename, const char *zParam){
|
2014-10-24 04:35:58 +04:00
|
|
|
if( zFilename==0 || zParam==0 ) return 0;
|
2011-05-17 23:43:38 +04:00
|
|
|
zFilename += sqlite3Strlen30(zFilename) + 1;
|
2011-05-17 22:53:08 +04:00
|
|
|
while( zFilename[0] ){
|
|
|
|
int x = strcmp(zFilename, zParam);
|
2011-05-17 23:43:38 +04:00
|
|
|
zFilename += sqlite3Strlen30(zFilename) + 1;
|
2011-05-17 22:53:08 +04:00
|
|
|
if( x==0 ) return zFilename;
|
2011-05-17 23:43:38 +04:00
|
|
|
zFilename += sqlite3Strlen30(zFilename) + 1;
|
2011-05-17 22:53:08 +04:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
2011-11-17 04:56:20 +04:00
|
|
|
|
2011-12-23 04:07:33 +04:00
|
|
|
/*
|
|
|
|
** Return a boolean value for a query parameter.
|
|
|
|
*/
|
|
|
|
int sqlite3_uri_boolean(const char *zFilename, const char *zParam, int bDflt){
|
|
|
|
const char *z = sqlite3_uri_parameter(zFilename, zParam);
|
2012-01-31 18:24:47 +04:00
|
|
|
bDflt = bDflt!=0;
|
|
|
|
return z ? sqlite3GetBoolean(z, bDflt) : bDflt;
|
2011-12-23 04:07:33 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
** Return a 64-bit integer value for a query parameter.
|
|
|
|
*/
|
|
|
|
sqlite3_int64 sqlite3_uri_int64(
|
|
|
|
const char *zFilename, /* Filename as passed to xOpen */
|
|
|
|
const char *zParam, /* URI parameter sought */
|
|
|
|
sqlite3_int64 bDflt /* return if parameter is missing */
|
|
|
|
){
|
|
|
|
const char *z = sqlite3_uri_parameter(zFilename, zParam);
|
|
|
|
sqlite3_int64 v;
|
2017-09-20 13:47:10 +03:00
|
|
|
if( z && sqlite3DecOrHexToI64(z, &v)==0 ){
|
2011-12-23 04:07:33 +04:00
|
|
|
bDflt = v;
|
|
|
|
}
|
|
|
|
return bDflt;
|
|
|
|
}
|
|
|
|
|
2011-11-17 04:56:20 +04:00
|
|
|
/*
|
2012-03-16 01:28:54 +04:00
|
|
|
** Return the Btree pointer identified by zDbName. Return NULL if not found.
|
2011-11-17 04:56:20 +04:00
|
|
|
*/
|
2012-03-16 01:28:54 +04:00
|
|
|
Btree *sqlite3DbNameToBtree(sqlite3 *db, const char *zDbName){
|
2016-12-24 22:37:16 +03:00
|
|
|
int iDb = zDbName ? sqlite3FindDbName(db, zDbName) : 0;
|
|
|
|
return iDb<0 ? 0 : db->aDb[iDb].pBt;
|
2011-11-17 04:56:20 +04:00
|
|
|
}
|
2012-03-16 01:28:54 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
** Return the filename of the database associated with a database
|
|
|
|
** connection.
|
|
|
|
*/
|
|
|
|
const char *sqlite3_db_filename(sqlite3 *db, const char *zDbName){
|
2014-12-21 00:14:14 +03:00
|
|
|
Btree *pBt;
|
2014-10-24 04:35:58 +04:00
|
|
|
#ifdef SQLITE_ENABLE_API_ARMOR
|
|
|
|
if( !sqlite3SafetyCheckOk(db) ){
|
|
|
|
(void)SQLITE_MISUSE_BKPT;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#endif
|
2014-12-21 00:14:14 +03:00
|
|
|
pBt = sqlite3DbNameToBtree(db, zDbName);
|
2012-03-16 01:28:54 +04:00
|
|
|
return pBt ? sqlite3BtreeGetFilename(pBt) : 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
** Return 1 if database is read-only or 0 if read/write. Return -1 if
|
|
|
|
** no such database exists.
|
|
|
|
*/
|
|
|
|
int sqlite3_db_readonly(sqlite3 *db, const char *zDbName){
|
2014-12-21 00:14:14 +03:00
|
|
|
Btree *pBt;
|
2014-10-24 04:35:58 +04:00
|
|
|
#ifdef SQLITE_ENABLE_API_ARMOR
|
|
|
|
if( !sqlite3SafetyCheckOk(db) ){
|
|
|
|
(void)SQLITE_MISUSE_BKPT;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
#endif
|
2014-12-21 00:14:14 +03:00
|
|
|
pBt = sqlite3DbNameToBtree(db, zDbName);
|
2014-05-21 12:21:07 +04:00
|
|
|
return pBt ? sqlite3BtreeIsReadonly(pBt) : -1;
|
2012-03-16 01:28:54 +04:00
|
|
|
}
|
2015-12-05 23:51:54 +03:00
|
|
|
|
|
|
|
#ifdef SQLITE_ENABLE_SNAPSHOT
|
|
|
|
/*
|
|
|
|
** Obtain a snapshot handle for the snapshot of database zDb currently
|
|
|
|
** being read by handle db.
|
|
|
|
*/
|
|
|
|
int sqlite3_snapshot_get(
|
|
|
|
sqlite3 *db,
|
|
|
|
const char *zDb,
|
|
|
|
sqlite3_snapshot **ppSnapshot
|
|
|
|
){
|
|
|
|
int rc = SQLITE_ERROR;
|
|
|
|
#ifndef SQLITE_OMIT_WAL
|
|
|
|
|
|
|
|
#ifdef SQLITE_ENABLE_API_ARMOR
|
|
|
|
if( !sqlite3SafetyCheckOk(db) ){
|
|
|
|
return SQLITE_MISUSE_BKPT;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
sqlite3_mutex_enter(db->mutex);
|
|
|
|
|
2016-11-18 21:43:39 +03:00
|
|
|
if( db->autoCommit==0 ){
|
|
|
|
int iDb = sqlite3FindDbName(db, zDb);
|
|
|
|
if( iDb==0 || iDb>1 ){
|
|
|
|
Btree *pBt = db->aDb[iDb].pBt;
|
|
|
|
if( 0==sqlite3BtreeIsInTrans(pBt) ){
|
2018-06-06 21:50:50 +03:00
|
|
|
rc = sqlite3BtreeBeginTrans(pBt, 0, 0);
|
2016-11-18 21:43:39 +03:00
|
|
|
if( rc==SQLITE_OK ){
|
|
|
|
rc = sqlite3PagerSnapshotGet(sqlite3BtreePager(pBt), ppSnapshot);
|
|
|
|
}
|
2015-12-10 23:03:08 +03:00
|
|
|
}
|
2015-12-05 23:51:54 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
sqlite3_mutex_leave(db->mutex);
|
|
|
|
#endif /* SQLITE_OMIT_WAL */
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
** Open a read-transaction on the snapshot idendified by pSnapshot.
|
|
|
|
*/
|
|
|
|
int sqlite3_snapshot_open(
|
|
|
|
sqlite3 *db,
|
|
|
|
const char *zDb,
|
|
|
|
sqlite3_snapshot *pSnapshot
|
|
|
|
){
|
|
|
|
int rc = SQLITE_ERROR;
|
|
|
|
#ifndef SQLITE_OMIT_WAL
|
|
|
|
|
|
|
|
#ifdef SQLITE_ENABLE_API_ARMOR
|
|
|
|
if( !sqlite3SafetyCheckOk(db) ){
|
|
|
|
return SQLITE_MISUSE_BKPT;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
sqlite3_mutex_enter(db->mutex);
|
|
|
|
if( db->autoCommit==0 ){
|
|
|
|
int iDb;
|
|
|
|
iDb = sqlite3FindDbName(db, zDb);
|
|
|
|
if( iDb==0 || iDb>1 ){
|
|
|
|
Btree *pBt = db->aDb[iDb].pBt;
|
2018-08-06 20:12:36 +03:00
|
|
|
if( sqlite3BtreeIsInTrans(pBt)==0 ){
|
|
|
|
Pager *pPager = sqlite3BtreePager(pBt);
|
|
|
|
int bUnlock = 0;
|
|
|
|
if( sqlite3BtreeIsInReadTrans(pBt) ){
|
|
|
|
if( db->nVdbeActive==0 ){
|
|
|
|
rc = sqlite3PagerSnapshotCheck(pPager, pSnapshot);
|
|
|
|
if( rc==SQLITE_OK ){
|
|
|
|
bUnlock = 1;
|
|
|
|
rc = sqlite3BtreeCommit(pBt);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}else{
|
|
|
|
rc = SQLITE_OK;
|
|
|
|
}
|
|
|
|
if( rc==SQLITE_OK ){
|
|
|
|
rc = sqlite3PagerSnapshotOpen(pPager, pSnapshot);
|
|
|
|
}
|
2015-12-05 23:51:54 +03:00
|
|
|
if( rc==SQLITE_OK ){
|
2018-06-06 21:50:50 +03:00
|
|
|
rc = sqlite3BtreeBeginTrans(pBt, 0, 0);
|
2018-08-06 20:12:36 +03:00
|
|
|
sqlite3PagerSnapshotOpen(pPager, 0);
|
|
|
|
}
|
|
|
|
if( bUnlock ){
|
|
|
|
sqlite3PagerSnapshotUnlock(pPager);
|
2015-12-05 23:51:54 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
sqlite3_mutex_leave(db->mutex);
|
|
|
|
#endif /* SQLITE_OMIT_WAL */
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
2016-11-18 23:49:43 +03:00
|
|
|
/*
|
|
|
|
** Recover as many snapshots as possible from the wal file associated with
|
|
|
|
** schema zDb of database db.
|
|
|
|
*/
|
|
|
|
int sqlite3_snapshot_recover(sqlite3 *db, const char *zDb){
|
|
|
|
int rc = SQLITE_ERROR;
|
|
|
|
int iDb;
|
|
|
|
#ifndef SQLITE_OMIT_WAL
|
|
|
|
|
|
|
|
#ifdef SQLITE_ENABLE_API_ARMOR
|
|
|
|
if( !sqlite3SafetyCheckOk(db) ){
|
|
|
|
return SQLITE_MISUSE_BKPT;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
sqlite3_mutex_enter(db->mutex);
|
|
|
|
iDb = sqlite3FindDbName(db, zDb);
|
|
|
|
if( iDb==0 || iDb>1 ){
|
|
|
|
Btree *pBt = db->aDb[iDb].pBt;
|
|
|
|
if( 0==sqlite3BtreeIsInReadTrans(pBt) ){
|
2018-06-06 21:50:50 +03:00
|
|
|
rc = sqlite3BtreeBeginTrans(pBt, 0, 0);
|
2016-11-19 21:31:37 +03:00
|
|
|
if( rc==SQLITE_OK ){
|
|
|
|
rc = sqlite3PagerSnapshotRecover(sqlite3BtreePager(pBt));
|
|
|
|
sqlite3BtreeCommit(pBt);
|
|
|
|
}
|
2016-11-18 23:49:43 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
sqlite3_mutex_leave(db->mutex);
|
|
|
|
#endif /* SQLITE_OMIT_WAL */
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
2015-12-05 23:51:54 +03:00
|
|
|
/*
|
|
|
|
** Free a snapshot handle obtained from sqlite3_snapshot_get().
|
|
|
|
*/
|
|
|
|
void sqlite3_snapshot_free(sqlite3_snapshot *pSnapshot){
|
|
|
|
sqlite3_free(pSnapshot);
|
|
|
|
}
|
|
|
|
#endif /* SQLITE_ENABLE_SNAPSHOT */
|
2017-06-16 22:51:47 +03:00
|
|
|
|
|
|
|
#ifndef SQLITE_OMIT_COMPILEOPTION_DIAGS
|
|
|
|
/*
|
|
|
|
** Given the name of a compile-time option, return true if that option
|
|
|
|
** was used and false if not.
|
|
|
|
**
|
|
|
|
** The name can optionally begin with "SQLITE_" but the "SQLITE_" prefix
|
|
|
|
** is not required for a match.
|
|
|
|
*/
|
|
|
|
int sqlite3_compileoption_used(const char *zOptName){
|
|
|
|
int i, n;
|
|
|
|
int nOpt;
|
|
|
|
const char **azCompileOpt;
|
|
|
|
|
|
|
|
#if SQLITE_ENABLE_API_ARMOR
|
|
|
|
if( zOptName==0 ){
|
|
|
|
(void)SQLITE_MISUSE_BKPT;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
azCompileOpt = sqlite3CompileOptions(&nOpt);
|
|
|
|
|
|
|
|
if( sqlite3StrNICmp(zOptName, "SQLITE_", 7)==0 ) zOptName += 7;
|
|
|
|
n = sqlite3Strlen30(zOptName);
|
|
|
|
|
|
|
|
/* Since nOpt is normally in single digits, a linear search is
|
|
|
|
** adequate. No need for a binary search. */
|
|
|
|
for(i=0; i<nOpt; i++){
|
|
|
|
if( sqlite3StrNICmp(zOptName, azCompileOpt[i], n)==0
|
|
|
|
&& sqlite3IsIdChar((unsigned char)azCompileOpt[i][n])==0
|
|
|
|
){
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
** Return the N-th compile-time option string. If N is out of range,
|
|
|
|
** return a NULL pointer.
|
|
|
|
*/
|
|
|
|
const char *sqlite3_compileoption_get(int N){
|
|
|
|
int nOpt;
|
|
|
|
const char **azCompileOpt;
|
|
|
|
azCompileOpt = sqlite3CompileOptions(&nOpt);
|
|
|
|
if( N>=0 && N<nOpt ){
|
|
|
|
return azCompileOpt[N];
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#endif /* SQLITE_OMIT_COMPILEOPTION_DIAGS */
|