blob: a2c51f41fb28d767388f45d42c6242edb2f6532d [file] [log] [blame]
drh40257ff2008-06-13 18:24:27 +00001/*
2** 2008 June 13
3**
4** The author disclaims copyright to this source code. In place of
5** a legal notice, here is a blessing:
6**
7** May you do good and not evil.
8** May you find forgiveness for yourself and forgive others.
9** May you share freely, never taking more than you give.
10**
11*************************************************************************
12**
peter.d.reid60ec9142014-09-06 16:39:46 +000013** This file contains definitions of global variables and constants.
drh40257ff2008-06-13 18:24:27 +000014*/
15#include "sqliteInt.h"
16
drh40257ff2008-06-13 18:24:27 +000017/* An array to map all upper-case characters into their corresponding
18** lower-case character.
19**
20** SQLite only considers US-ASCII (or EBCDIC) characters. We do not
21** handle case conversions for the UTF character set since the tables
22** involved are nearly as big or bigger than SQLite itself.
23*/
24const unsigned char sqlite3UpperToLower[] = {
25#ifdef SQLITE_ASCII
26 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17,
27 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35,
28 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53,
29 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 97, 98, 99,100,101,102,103,
30 104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,120,121,
31 122, 91, 92, 93, 94, 95, 96, 97, 98, 99,100,101,102,103,104,105,106,107,
32 108,109,110,111,112,113,114,115,116,117,118,119,120,121,122,123,124,125,
33 126,127,128,129,130,131,132,133,134,135,136,137,138,139,140,141,142,143,
34 144,145,146,147,148,149,150,151,152,153,154,155,156,157,158,159,160,161,
35 162,163,164,165,166,167,168,169,170,171,172,173,174,175,176,177,178,179,
36 180,181,182,183,184,185,186,187,188,189,190,191,192,193,194,195,196,197,
37 198,199,200,201,202,203,204,205,206,207,208,209,210,211,212,213,214,215,
38 216,217,218,219,220,221,222,223,224,225,226,227,228,229,230,231,232,233,
39 234,235,236,237,238,239,240,241,242,243,244,245,246,247,248,249,250,251,
40 252,253,254,255
41#endif
42#ifdef SQLITE_EBCDIC
43 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, /* 0x */
44 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, /* 1x */
45 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, /* 2x */
46 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, /* 3x */
47 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, /* 4x */
48 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, /* 5x */
drhdb222ad2015-02-19 17:16:14 +000049 96, 97, 98, 99,100,101,102,103,104,105,106,107,108,109,110,111, /* 6x */
50 112,113,114,115,116,117,118,119,120,121,122,123,124,125,126,127, /* 7x */
drh40257ff2008-06-13 18:24:27 +000051 128,129,130,131,132,133,134,135,136,137,138,139,140,141,142,143, /* 8x */
drhdb222ad2015-02-19 17:16:14 +000052 144,145,146,147,148,149,150,151,152,153,154,155,156,157,158,159, /* 9x */
drh40257ff2008-06-13 18:24:27 +000053 160,161,162,163,164,165,166,167,168,169,170,171,140,141,142,175, /* Ax */
54 176,177,178,179,180,181,182,183,184,185,186,187,188,189,190,191, /* Bx */
55 192,129,130,131,132,133,134,135,136,137,202,203,204,205,206,207, /* Cx */
56 208,145,146,147,148,149,150,151,152,153,218,219,220,221,222,223, /* Dx */
drhdb222ad2015-02-19 17:16:14 +000057 224,225,162,163,164,165,166,167,168,169,234,235,236,237,238,239, /* Ex */
58 240,241,242,243,244,245,246,247,248,249,250,251,252,253,254,255, /* Fx */
drh40257ff2008-06-13 18:24:27 +000059#endif
60};
61
62/*
danielk197778ca0e72009-01-20 16:53:39 +000063** The following 256 byte lookup table is used to support SQLites built-in
64** equivalents to the following standard library functions:
65**
66** isspace() 0x01
drhdc86e2b2009-01-24 11:30:42 +000067** isalpha() 0x02
danielk197778ca0e72009-01-20 16:53:39 +000068** isdigit() 0x04
drhdc86e2b2009-01-24 11:30:42 +000069** isalnum() 0x06
danielk197778ca0e72009-01-20 16:53:39 +000070** isxdigit() 0x08
71** toupper() 0x20
drhaf2b5722009-11-16 15:11:51 +000072** SQLite identifier character 0x40
drh244b9d62016-04-11 19:01:08 +000073** Quote character 0x80
danielk197778ca0e72009-01-20 16:53:39 +000074**
75** Bit 0x20 is set if the mapped character requires translation to upper
drhdc86e2b2009-01-24 11:30:42 +000076** case. i.e. if the character is a lower-case ASCII character.
danielk197778ca0e72009-01-20 16:53:39 +000077** If x is a lower-case ASCII character, then its upper-case equivalent
78** is (x - 0x20). Therefore toupper() can be implemented as:
79**
80** (x & ~(map[x]&0x20))
81**
drh22fa36d2016-09-29 15:53:28 +000082** The equivalent of tolower() is implemented using the sqlite3UpperToLower[]
danielk197778ca0e72009-01-20 16:53:39 +000083** array. tolower() is used more often than toupper() by SQLite.
84**
drh22fa36d2016-09-29 15:53:28 +000085** Bit 0x40 is set if the character is non-alphanumeric and can be used in an
drhaf2b5722009-11-16 15:11:51 +000086** SQLite identifier. Identifiers are alphanumerics, "_", "$", and any
87** non-ASCII UTF character. Hence the test for whether or not a character is
88** part of an identifier is 0x46.
danielk197778ca0e72009-01-20 16:53:39 +000089*/
danielk197778ca0e72009-01-20 16:53:39 +000090const unsigned char sqlite3CtypeMap[256] = {
91 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 00..07 ........ */
92 0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x00, 0x00, /* 08..0f ........ */
93 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 10..17 ........ */
94 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 18..1f ........ */
drh244b9d62016-04-11 19:01:08 +000095 0x01, 0x00, 0x80, 0x00, 0x40, 0x00, 0x00, 0x80, /* 20..27 !"#$%&' */
danielk197778ca0e72009-01-20 16:53:39 +000096 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 28..2f ()*+,-./ */
drhdc86e2b2009-01-24 11:30:42 +000097 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, /* 30..37 01234567 */
98 0x0c, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 38..3f 89:;<=>? */
danielk197778ca0e72009-01-20 16:53:39 +000099
100 0x00, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x02, /* 40..47 @ABCDEFG */
101 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, /* 48..4f HIJKLMNO */
102 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, /* 50..57 PQRSTUVW */
drh244b9d62016-04-11 19:01:08 +0000103 0x02, 0x02, 0x02, 0x80, 0x00, 0x00, 0x00, 0x40, /* 58..5f XYZ[\]^_ */
104 0x80, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x22, /* 60..67 `abcdefg */
danielk197778ca0e72009-01-20 16:53:39 +0000105 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, /* 68..6f hijklmno */
106 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, /* 70..77 pqrstuvw */
107 0x22, 0x22, 0x22, 0x00, 0x00, 0x00, 0x00, 0x00, /* 78..7f xyz{|}~. */
108
drhaf2b5722009-11-16 15:11:51 +0000109 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, /* 80..87 ........ */
110 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, /* 88..8f ........ */
111 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, /* 90..97 ........ */
112 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, /* 98..9f ........ */
113 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, /* a0..a7 ........ */
114 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, /* a8..af ........ */
115 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, /* b0..b7 ........ */
116 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, /* b8..bf ........ */
danielk197778ca0e72009-01-20 16:53:39 +0000117
drhaf2b5722009-11-16 15:11:51 +0000118 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, /* c0..c7 ........ */
119 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, /* c8..cf ........ */
120 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, /* d0..d7 ........ */
121 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, /* d8..df ........ */
122 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, /* e0..e7 ........ */
123 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, /* e8..ef ........ */
124 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, /* f0..f7 ........ */
125 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40 /* f8..ff ........ */
danielk197778ca0e72009-01-20 16:53:39 +0000126};
danielk197778ca0e72009-01-20 16:53:39 +0000127
drh00729cb2014-10-04 11:59:33 +0000128/* EVIDENCE-OF: R-02982-34736 In order to maintain full backwards
129** compatibility for legacy applications, the URI filename capability is
130** disabled by default.
131**
132** EVIDENCE-OF: R-38799-08373 URI filenames can be enabled or disabled
133** using the SQLITE_USE_URI=1 or SQLITE_USE_URI=0 compile-time options.
drh4d9f1882014-11-04 17:23:24 +0000134**
135** EVIDENCE-OF: R-43642-56306 By default, URI handling is globally
136** disabled. The default value may be changed by compiling with the
137** SQLITE_USE_URI symbol defined.
drhad012d02017-05-03 15:54:53 +0000138**
139** URI filenames are enabled by default if SQLITE_HAS_CODEC is
140** enabled.
drh00729cb2014-10-04 11:59:33 +0000141*/
dancd74b612011-04-22 19:37:32 +0000142#ifndef SQLITE_USE_URI
drhad012d02017-05-03 15:54:53 +0000143# ifdef SQLITE_HAS_CODEC
144# define SQLITE_USE_URI 1
145# else
146# define SQLITE_USE_URI 0
147# endif
dancd74b612011-04-22 19:37:32 +0000148#endif
danielk197778ca0e72009-01-20 16:53:39 +0000149
drh4d9f1882014-11-04 17:23:24 +0000150/* EVIDENCE-OF: R-38720-18127 The default setting is determined by the
151** SQLITE_ALLOW_COVERING_INDEX_SCAN compile-time option, or is "on" if
152** that compile-time option is omitted.
153*/
drhc164cc92019-06-14 17:37:39 +0000154#if !defined(SQLITE_ALLOW_COVERING_INDEX_SCAN)
drhde9a7b82012-09-17 20:44:46 +0000155# define SQLITE_ALLOW_COVERING_INDEX_SCAN 1
drhc164cc92019-06-14 17:37:39 +0000156#else
157# if !SQLITE_ALLOW_COVERING_INDEX_SCAN
158# error "Compile-time disabling of covering index scan using the\
159 -DSQLITE_ALLOW_COVERING_INDEX_SCAN=0 option is deprecated.\
160 Contact SQLite developers if this is a problem for you, and\
161 delete this #error macro to continue with your build."
162# endif
drhde9a7b82012-09-17 20:44:46 +0000163#endif
164
drh3bd17912015-01-02 15:55:29 +0000165/* The minimum PMA size is set to this value multiplied by the database
166** page size in bytes.
167*/
168#ifndef SQLITE_SORTER_PMASZ
169# define SQLITE_SORTER_PMASZ 250
170#endif
171
drh8c71a982016-03-07 17:37:37 +0000172/* Statement journals spill to disk when their size exceeds the following
drh22fa36d2016-09-29 15:53:28 +0000173** threshold (in bytes). 0 means that statement journals are created and
drh8c71a982016-03-07 17:37:37 +0000174** written to disk immediately (the default behavior for SQLite versions
175** before 3.12.0). -1 means always keep the entire statement journal in
176** memory. (The statement journal is also always held entirely in memory
177** if journal_mode=MEMORY or if temp_store=MEMORY, regardless of this
178** setting.)
179*/
180#ifndef SQLITE_STMTJRNL_SPILL
181# define SQLITE_STMTJRNL_SPILL (64*1024)
182#endif
183
danielk197778ca0e72009-01-20 16:53:39 +0000184/*
drh56d65cd2017-01-02 19:02:20 +0000185** The default lookaside-configuration, the format "SZ,N". SZ is the
186** number of bytes in each lookaside slot (should be a multiple of 8)
187** and N is the number of slots. The lookaside-configuration can be
188** changed as start-time using sqlite3_config(SQLITE_CONFIG_LOOKASIDE)
189** or at run-time for an individual database connection using
190** sqlite3_db_config(db, SQLITE_DBCONFIG_LOOKASIDE);
drhd335bc42019-12-13 16:04:52 +0000191**
drhcf014f62019-12-31 15:12:34 +0000192** With the two-size-lookaside enhancement, less lookaside is required.
193** The default configuration of 1200,40 actually provides 30 1200-byte slots
194** and 93 128-byte slots, which is more lookaside than is available
195** using the older 1200,100 configuration without two-size-lookaside.
drh56d65cd2017-01-02 19:02:20 +0000196*/
197#ifndef SQLITE_DEFAULT_LOOKASIDE
drhcf014f62019-12-31 15:12:34 +0000198# ifdef SQLITE_OMIT_TWOSIZE_LOOKASIDE
drhd335bc42019-12-13 16:04:52 +0000199# define SQLITE_DEFAULT_LOOKASIDE 1200,100 /* 120KB of memory */
200# else
201# define SQLITE_DEFAULT_LOOKASIDE 1200,40 /* 48KB of memory */
202# endif
drh56d65cd2017-01-02 19:02:20 +0000203#endif
204
205
drh23a88592019-01-31 15:38:53 +0000206/* The default maximum size of an in-memory database created using
207** sqlite3_deserialize()
208*/
209#ifndef SQLITE_MEMDB_DEFAULT_MAXSIZE
210# define SQLITE_MEMDB_DEFAULT_MAXSIZE 1073741824
211#endif
212
drh56d65cd2017-01-02 19:02:20 +0000213/*
drh40257ff2008-06-13 18:24:27 +0000214** The following singleton contains the global configuration for
215** the SQLite library.
216*/
danielk1977075c23a2008-09-01 18:34:20 +0000217SQLITE_WSD struct Sqlite3Config sqlite3Config = {
danielk19770a732f52008-09-04 17:17:38 +0000218 SQLITE_DEFAULT_MEMSTATUS, /* bMemstat */
219 1, /* bCoreMutex */
220 SQLITE_THREADSAFE==1, /* bFullMutex */
dancd74b612011-04-22 19:37:32 +0000221 SQLITE_USE_URI, /* bOpenUri */
drhde9a7b82012-09-17 20:44:46 +0000222 SQLITE_ALLOW_COVERING_INDEX_SCAN, /* bUseCis */
drhb2a0f752017-08-28 15:51:35 +0000223 0, /* bSmallMalloc */
drh30842992019-08-12 14:17:43 +0000224 1, /* bExtraSchemaChecks */
danielk19770a732f52008-09-04 17:17:38 +0000225 0x7ffffffe, /* mxStrlen */
drh09fe6142013-11-29 15:06:27 +0000226 0, /* neverCorrupt */
drh56d65cd2017-01-02 19:02:20 +0000227 SQLITE_DEFAULT_LOOKASIDE, /* szLookaside, nLookaside */
drh8c71a982016-03-07 17:37:37 +0000228 SQLITE_STMTJRNL_SPILL, /* nStmtSpill */
drh1875f7a2008-12-08 18:19:17 +0000229 {0,0,0,0,0,0,0,0}, /* m */
230 {0,0,0,0,0,0,0,0,0}, /* mutex */
drh13e0ea92011-12-11 02:29:25 +0000231 {0,0,0,0,0,0,0,0,0,0,0,0,0},/* pcache2 */
drh1875f7a2008-12-08 18:19:17 +0000232 (void*)0, /* pHeap */
233 0, /* nHeap */
234 0, 0, /* mnHeap, mxHeap */
drh9b4c59f2013-04-15 17:03:42 +0000235 SQLITE_DEFAULT_MMAP_SIZE, /* szMmap */
236 SQLITE_MAX_MMAP_SIZE, /* mxMmap */
drh1875f7a2008-12-08 18:19:17 +0000237 (void*)0, /* pPage */
238 0, /* szPage */
drh4297c7c2015-07-07 21:14:42 +0000239 SQLITE_DEFAULT_PCACHE_INITSZ, /* nPage */
drh1875f7a2008-12-08 18:19:17 +0000240 0, /* mxParserStack */
241 0, /* sharedCacheEnabled */
drh3bd17912015-01-02 15:55:29 +0000242 SQLITE_SORTER_PMASZ, /* szPma */
drh9ac06502009-08-17 13:42:29 +0000243 /* All the rest should always be initialized to zero */
drh1875f7a2008-12-08 18:19:17 +0000244 0, /* isInit */
245 0, /* inProgress */
dane1ab2192009-08-17 15:16:19 +0000246 0, /* isMutexInit */
drh1875f7a2008-12-08 18:19:17 +0000247 0, /* isMallocInit */
dane1ab2192009-08-17 15:16:19 +0000248 0, /* isPCacheInit */
drh1875f7a2008-12-08 18:19:17 +0000249 0, /* nRefInitMutex */
drhc007f612014-05-16 14:17:01 +0000250 0, /* pInitMutex */
drh3f280702010-02-18 18:45:09 +0000251 0, /* xLog */
252 0, /* pLogArg */
danac455932012-11-26 19:50:41 +0000253#ifdef SQLITE_ENABLE_SQLLOG
254 0, /* xSqllog */
drhc007f612014-05-16 14:17:01 +0000255 0, /* pSqllogArg */
danac455932012-11-26 19:50:41 +0000256#endif
drhc007f612014-05-16 14:17:01 +0000257#ifdef SQLITE_VDBE_COVERAGE
258 0, /* xVdbeBranch */
259 0, /* pVbeBranchArg */
260#endif
drh23a88592019-01-31 15:38:53 +0000261#ifdef SQLITE_ENABLE_DESERIALIZE
262 SQLITE_MEMDB_DEFAULT_MAXSIZE, /* mxMemdbSize */
263#endif
drhd12602a2016-12-07 15:49:02 +0000264#ifndef SQLITE_UNTESTABLE
drhc007f612014-05-16 14:17:01 +0000265 0, /* xTestCallback */
266#endif
drh9e5eb9c2016-09-18 16:08:10 +0000267 0, /* bLocaltimeFault */
dan2e3a5a82018-04-16 21:12:42 +0000268 0x7ffffffe, /* iOnceResetThreshold */
drh23a88592019-01-31 15:38:53 +0000269 SQLITE_DEFAULT_SORTERREF_SIZE, /* szSorterRef */
drhade54d62019-08-02 20:45:04 +0000270 0, /* iPrngSeed */
drh633e6d52008-07-28 19:34:53 +0000271};
drh70a8ca32008-08-21 18:49:27 +0000272
drh70a8ca32008-08-21 18:49:27 +0000273/*
274** Hash table for global functions - functions common to all
275** database connections. After initialization, this table is
276** read-only.
277*/
drh80738d92016-02-15 00:34:16 +0000278FuncDefHash sqlite3BuiltinFunctions;
drhc7a3bb92009-02-05 16:31:45 +0000279
drh35043cc2018-02-12 20:27:34 +0000280#ifdef VDBE_PROFILE
281/*
282** The following performance counter can be used in place of
283** sqlite3Hwtime() for profiling. This is a no-op on standard builds.
284*/
285sqlite3_uint64 sqlite3NProfileCnt = 0;
286#endif
drh094430e2010-07-14 18:24:06 +0000287
288/*
drhc7a3bb92009-02-05 16:31:45 +0000289** The value of the "pending" byte must be 0x40000000 (1 byte past the
290** 1-gibabyte boundary) in a compatible database. SQLite never uses
291** the database page that contains the pending byte. It never attempts
drh22fa36d2016-09-29 15:53:28 +0000292** to read or write that page. The pending byte page is set aside
drhc7a3bb92009-02-05 16:31:45 +0000293** for use by the VFS layers as space for managing file locks.
294**
295** During testing, it is often desirable to move the pending byte to
296** a different position in the file. This allows code that has to
297** deal with the pending byte to run on files that are much smaller
298** than 1 GiB. The sqlite3_test_control() interface can be used to
299** move the pending byte.
300**
301** IMPORTANT: Changing the pending byte to any value other than
302** 0x40000000 results in an incompatible database file format!
drh86a11b82014-11-07 13:24:29 +0000303** Changing the pending byte during operation will result in undefined
304** and incorrect behavior.
drhc7a3bb92009-02-05 16:31:45 +0000305*/
drhf83dc1e2010-06-03 12:09:52 +0000306#ifndef SQLITE_OMIT_WSD
drhc7a3bb92009-02-05 16:31:45 +0000307int sqlite3PendingByte = 0x40000000;
drhf83dc1e2010-06-03 12:09:52 +0000308#endif
drha6c2ed92009-11-14 23:22:23 +0000309
310#include "opcodes.h"
311/*
312** Properties of opcodes. The OPFLG_INITIALIZER macro is
313** created by mkopcodeh.awk during compilation. Data is obtained
314** from the comments following the "case OP_xxxx:" statements in
315** the vdbe.c file.
316*/
317const unsigned char sqlite3OpcodeProperty[] = OPFLG_INITIALIZER;
drhf19aa5f2015-12-30 16:51:20 +0000318
319/*
320** Name of the default collating sequence
321*/
322const char sqlite3StrBINARY[] = "BINARY";