drh | 40257ff | 2008-06-13 18:24:27 +0000 | [diff] [blame] | 1 | /* |
| 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.reid | 60ec914 | 2014-09-06 16:39:46 +0000 | [diff] [blame] | 13 | ** This file contains definitions of global variables and constants. |
drh | 40257ff | 2008-06-13 18:24:27 +0000 | [diff] [blame] | 14 | */ |
| 15 | #include "sqliteInt.h" |
| 16 | |
drh | 40257ff | 2008-06-13 18:24:27 +0000 | [diff] [blame] | 17 | /* 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 | */ |
| 24 | const 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 */ |
| 49 | 96, 97, 66, 67, 68, 69, 70, 71, 72, 73,106,107,108,109,110,111, /* 6x */ |
| 50 | 112, 81, 82, 83, 84, 85, 86, 87, 88, 89,122,123,124,125,126,127, /* 7x */ |
| 51 | 128,129,130,131,132,133,134,135,136,137,138,139,140,141,142,143, /* 8x */ |
| 52 | 144,145,146,147,148,149,150,151,152,153,154,155,156,157,156,159, /* 9x */ |
| 53 | 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 */ |
| 57 | 224,225,162,163,164,165,166,167,168,169,232,203,204,205,206,207, /* Ex */ |
| 58 | 239,240,241,242,243,244,245,246,247,248,249,219,220,221,222,255, /* Fx */ |
| 59 | #endif |
| 60 | }; |
| 61 | |
| 62 | /* |
danielk1977 | 78ca0e7 | 2009-01-20 16:53:39 +0000 | [diff] [blame] | 63 | ** 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 |
drh | dc86e2b | 2009-01-24 11:30:42 +0000 | [diff] [blame] | 67 | ** isalpha() 0x02 |
danielk1977 | 78ca0e7 | 2009-01-20 16:53:39 +0000 | [diff] [blame] | 68 | ** isdigit() 0x04 |
drh | dc86e2b | 2009-01-24 11:30:42 +0000 | [diff] [blame] | 69 | ** isalnum() 0x06 |
danielk1977 | 78ca0e7 | 2009-01-20 16:53:39 +0000 | [diff] [blame] | 70 | ** isxdigit() 0x08 |
| 71 | ** toupper() 0x20 |
drh | af2b572 | 2009-11-16 15:11:51 +0000 | [diff] [blame] | 72 | ** SQLite identifier character 0x40 |
danielk1977 | 78ca0e7 | 2009-01-20 16:53:39 +0000 | [diff] [blame] | 73 | ** |
| 74 | ** Bit 0x20 is set if the mapped character requires translation to upper |
drh | dc86e2b | 2009-01-24 11:30:42 +0000 | [diff] [blame] | 75 | ** case. i.e. if the character is a lower-case ASCII character. |
danielk1977 | 78ca0e7 | 2009-01-20 16:53:39 +0000 | [diff] [blame] | 76 | ** If x is a lower-case ASCII character, then its upper-case equivalent |
| 77 | ** is (x - 0x20). Therefore toupper() can be implemented as: |
| 78 | ** |
| 79 | ** (x & ~(map[x]&0x20)) |
| 80 | ** |
| 81 | ** Standard function tolower() is implemented using the sqlite3UpperToLower[] |
| 82 | ** array. tolower() is used more often than toupper() by SQLite. |
| 83 | ** |
drh | af2b572 | 2009-11-16 15:11:51 +0000 | [diff] [blame] | 84 | ** Bit 0x40 is set if the character non-alphanumeric and can be used in an |
| 85 | ** SQLite identifier. Identifiers are alphanumerics, "_", "$", and any |
| 86 | ** non-ASCII UTF character. Hence the test for whether or not a character is |
| 87 | ** part of an identifier is 0x46. |
| 88 | ** |
danielk1977 | 78ca0e7 | 2009-01-20 16:53:39 +0000 | [diff] [blame] | 89 | ** SQLite's versions are identical to the standard versions assuming a |
| 90 | ** locale of "C". They are implemented as macros in sqliteInt.h. |
| 91 | */ |
| 92 | #ifdef SQLITE_ASCII |
| 93 | const unsigned char sqlite3CtypeMap[256] = { |
| 94 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 00..07 ........ */ |
| 95 | 0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x00, 0x00, /* 08..0f ........ */ |
| 96 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 10..17 ........ */ |
| 97 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 18..1f ........ */ |
drh | af2b572 | 2009-11-16 15:11:51 +0000 | [diff] [blame] | 98 | 0x01, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, /* 20..27 !"#$%&' */ |
danielk1977 | 78ca0e7 | 2009-01-20 16:53:39 +0000 | [diff] [blame] | 99 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 28..2f ()*+,-./ */ |
drh | dc86e2b | 2009-01-24 11:30:42 +0000 | [diff] [blame] | 100 | 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, /* 30..37 01234567 */ |
| 101 | 0x0c, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 38..3f 89:;<=>? */ |
danielk1977 | 78ca0e7 | 2009-01-20 16:53:39 +0000 | [diff] [blame] | 102 | |
| 103 | 0x00, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x02, /* 40..47 @ABCDEFG */ |
| 104 | 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, /* 48..4f HIJKLMNO */ |
| 105 | 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, /* 50..57 PQRSTUVW */ |
drh | af2b572 | 2009-11-16 15:11:51 +0000 | [diff] [blame] | 106 | 0x02, 0x02, 0x02, 0x00, 0x00, 0x00, 0x00, 0x40, /* 58..5f XYZ[\]^_ */ |
danielk1977 | 78ca0e7 | 2009-01-20 16:53:39 +0000 | [diff] [blame] | 107 | 0x00, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x22, /* 60..67 `abcdefg */ |
| 108 | 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, /* 68..6f hijklmno */ |
| 109 | 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, /* 70..77 pqrstuvw */ |
| 110 | 0x22, 0x22, 0x22, 0x00, 0x00, 0x00, 0x00, 0x00, /* 78..7f xyz{|}~. */ |
| 111 | |
drh | af2b572 | 2009-11-16 15:11:51 +0000 | [diff] [blame] | 112 | 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, /* 80..87 ........ */ |
| 113 | 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, /* 88..8f ........ */ |
| 114 | 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, /* 90..97 ........ */ |
| 115 | 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, /* 98..9f ........ */ |
| 116 | 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, /* a0..a7 ........ */ |
| 117 | 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, /* a8..af ........ */ |
| 118 | 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, /* b0..b7 ........ */ |
| 119 | 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, /* b8..bf ........ */ |
danielk1977 | 78ca0e7 | 2009-01-20 16:53:39 +0000 | [diff] [blame] | 120 | |
drh | af2b572 | 2009-11-16 15:11:51 +0000 | [diff] [blame] | 121 | 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, /* c0..c7 ........ */ |
| 122 | 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, /* c8..cf ........ */ |
| 123 | 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, /* d0..d7 ........ */ |
| 124 | 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, /* d8..df ........ */ |
| 125 | 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, /* e0..e7 ........ */ |
| 126 | 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, /* e8..ef ........ */ |
| 127 | 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, /* f0..f7 ........ */ |
| 128 | 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40 /* f8..ff ........ */ |
danielk1977 | 78ca0e7 | 2009-01-20 16:53:39 +0000 | [diff] [blame] | 129 | }; |
| 130 | #endif |
| 131 | |
drh | 00729cb | 2014-10-04 11:59:33 +0000 | [diff] [blame^] | 132 | /* EVIDENCE-OF: R-02982-34736 In order to maintain full backwards |
| 133 | ** compatibility for legacy applications, the URI filename capability is |
| 134 | ** disabled by default. |
| 135 | ** |
| 136 | ** EVIDENCE-OF: R-38799-08373 URI filenames can be enabled or disabled |
| 137 | ** using the SQLITE_USE_URI=1 or SQLITE_USE_URI=0 compile-time options. |
| 138 | */ |
dan | cd74b61 | 2011-04-22 19:37:32 +0000 | [diff] [blame] | 139 | #ifndef SQLITE_USE_URI |
| 140 | # define SQLITE_USE_URI 0 |
| 141 | #endif |
danielk1977 | 78ca0e7 | 2009-01-20 16:53:39 +0000 | [diff] [blame] | 142 | |
drh | de9a7b8 | 2012-09-17 20:44:46 +0000 | [diff] [blame] | 143 | #ifndef SQLITE_ALLOW_COVERING_INDEX_SCAN |
| 144 | # define SQLITE_ALLOW_COVERING_INDEX_SCAN 1 |
| 145 | #endif |
| 146 | |
danielk1977 | 78ca0e7 | 2009-01-20 16:53:39 +0000 | [diff] [blame] | 147 | /* |
drh | 40257ff | 2008-06-13 18:24:27 +0000 | [diff] [blame] | 148 | ** The following singleton contains the global configuration for |
| 149 | ** the SQLite library. |
| 150 | */ |
danielk1977 | 075c23a | 2008-09-01 18:34:20 +0000 | [diff] [blame] | 151 | SQLITE_WSD struct Sqlite3Config sqlite3Config = { |
danielk1977 | 0a732f5 | 2008-09-04 17:17:38 +0000 | [diff] [blame] | 152 | SQLITE_DEFAULT_MEMSTATUS, /* bMemstat */ |
| 153 | 1, /* bCoreMutex */ |
| 154 | SQLITE_THREADSAFE==1, /* bFullMutex */ |
dan | cd74b61 | 2011-04-22 19:37:32 +0000 | [diff] [blame] | 155 | SQLITE_USE_URI, /* bOpenUri */ |
drh | de9a7b8 | 2012-09-17 20:44:46 +0000 | [diff] [blame] | 156 | SQLITE_ALLOW_COVERING_INDEX_SCAN, /* bUseCis */ |
danielk1977 | 0a732f5 | 2008-09-04 17:17:38 +0000 | [diff] [blame] | 157 | 0x7ffffffe, /* mxStrlen */ |
drh | 09fe614 | 2013-11-29 15:06:27 +0000 | [diff] [blame] | 158 | 0, /* neverCorrupt */ |
drh | 432e0bc | 2011-09-19 13:01:53 +0000 | [diff] [blame] | 159 | 128, /* szLookaside */ |
danielk1977 | 0a732f5 | 2008-09-04 17:17:38 +0000 | [diff] [blame] | 160 | 500, /* nLookaside */ |
drh | 1875f7a | 2008-12-08 18:19:17 +0000 | [diff] [blame] | 161 | {0,0,0,0,0,0,0,0}, /* m */ |
| 162 | {0,0,0,0,0,0,0,0,0}, /* mutex */ |
drh | 13e0ea9 | 2011-12-11 02:29:25 +0000 | [diff] [blame] | 163 | {0,0,0,0,0,0,0,0,0,0,0,0,0},/* pcache2 */ |
drh | 1875f7a | 2008-12-08 18:19:17 +0000 | [diff] [blame] | 164 | (void*)0, /* pHeap */ |
| 165 | 0, /* nHeap */ |
| 166 | 0, 0, /* mnHeap, mxHeap */ |
drh | 9b4c59f | 2013-04-15 17:03:42 +0000 | [diff] [blame] | 167 | SQLITE_DEFAULT_MMAP_SIZE, /* szMmap */ |
| 168 | SQLITE_MAX_MMAP_SIZE, /* mxMmap */ |
drh | 1875f7a | 2008-12-08 18:19:17 +0000 | [diff] [blame] | 169 | (void*)0, /* pScratch */ |
| 170 | 0, /* szScratch */ |
| 171 | 0, /* nScratch */ |
| 172 | (void*)0, /* pPage */ |
| 173 | 0, /* szPage */ |
| 174 | 0, /* nPage */ |
| 175 | 0, /* mxParserStack */ |
| 176 | 0, /* sharedCacheEnabled */ |
drh | 9ac0650 | 2009-08-17 13:42:29 +0000 | [diff] [blame] | 177 | /* All the rest should always be initialized to zero */ |
drh | 1875f7a | 2008-12-08 18:19:17 +0000 | [diff] [blame] | 178 | 0, /* isInit */ |
| 179 | 0, /* inProgress */ |
dan | e1ab219 | 2009-08-17 15:16:19 +0000 | [diff] [blame] | 180 | 0, /* isMutexInit */ |
drh | 1875f7a | 2008-12-08 18:19:17 +0000 | [diff] [blame] | 181 | 0, /* isMallocInit */ |
dan | e1ab219 | 2009-08-17 15:16:19 +0000 | [diff] [blame] | 182 | 0, /* isPCacheInit */ |
drh | 1875f7a | 2008-12-08 18:19:17 +0000 | [diff] [blame] | 183 | 0, /* nRefInitMutex */ |
drh | c007f61 | 2014-05-16 14:17:01 +0000 | [diff] [blame] | 184 | 0, /* pInitMutex */ |
drh | 3f28070 | 2010-02-18 18:45:09 +0000 | [diff] [blame] | 185 | 0, /* xLog */ |
| 186 | 0, /* pLogArg */ |
dan | ac45593 | 2012-11-26 19:50:41 +0000 | [diff] [blame] | 187 | #ifdef SQLITE_ENABLE_SQLLOG |
| 188 | 0, /* xSqllog */ |
drh | c007f61 | 2014-05-16 14:17:01 +0000 | [diff] [blame] | 189 | 0, /* pSqllogArg */ |
dan | ac45593 | 2012-11-26 19:50:41 +0000 | [diff] [blame] | 190 | #endif |
drh | c007f61 | 2014-05-16 14:17:01 +0000 | [diff] [blame] | 191 | #ifdef SQLITE_VDBE_COVERAGE |
| 192 | 0, /* xVdbeBranch */ |
| 193 | 0, /* pVbeBranchArg */ |
| 194 | #endif |
| 195 | #ifndef SQLITE_OMIT_BUILTIN_TEST |
| 196 | 0, /* xTestCallback */ |
| 197 | #endif |
| 198 | 0 /* bLocaltimeFault */ |
drh | 633e6d5 | 2008-07-28 19:34:53 +0000 | [diff] [blame] | 199 | }; |
drh | 70a8ca3 | 2008-08-21 18:49:27 +0000 | [diff] [blame] | 200 | |
drh | 70a8ca3 | 2008-08-21 18:49:27 +0000 | [diff] [blame] | 201 | /* |
| 202 | ** Hash table for global functions - functions common to all |
| 203 | ** database connections. After initialization, this table is |
| 204 | ** read-only. |
| 205 | */ |
danielk1977 | 075c23a | 2008-09-01 18:34:20 +0000 | [diff] [blame] | 206 | SQLITE_WSD FuncDefHash sqlite3GlobalFunctions; |
drh | c7a3bb9 | 2009-02-05 16:31:45 +0000 | [diff] [blame] | 207 | |
| 208 | /* |
drh | 094430e | 2010-07-14 18:24:06 +0000 | [diff] [blame] | 209 | ** Constant tokens for values 0 and 1. |
| 210 | */ |
| 211 | const Token sqlite3IntTokens[] = { |
| 212 | { "0", 1 }, |
| 213 | { "1", 1 } |
| 214 | }; |
| 215 | |
| 216 | |
| 217 | /* |
drh | c7a3bb9 | 2009-02-05 16:31:45 +0000 | [diff] [blame] | 218 | ** The value of the "pending" byte must be 0x40000000 (1 byte past the |
| 219 | ** 1-gibabyte boundary) in a compatible database. SQLite never uses |
| 220 | ** the database page that contains the pending byte. It never attempts |
| 221 | ** to read or write that page. The pending byte page is set assign |
| 222 | ** for use by the VFS layers as space for managing file locks. |
| 223 | ** |
| 224 | ** During testing, it is often desirable to move the pending byte to |
| 225 | ** a different position in the file. This allows code that has to |
| 226 | ** deal with the pending byte to run on files that are much smaller |
| 227 | ** than 1 GiB. The sqlite3_test_control() interface can be used to |
| 228 | ** move the pending byte. |
| 229 | ** |
| 230 | ** IMPORTANT: Changing the pending byte to any value other than |
| 231 | ** 0x40000000 results in an incompatible database file format! |
| 232 | ** Changing the pending byte during operating results in undefined |
| 233 | ** and dileterious behavior. |
| 234 | */ |
drh | f83dc1e | 2010-06-03 12:09:52 +0000 | [diff] [blame] | 235 | #ifndef SQLITE_OMIT_WSD |
drh | c7a3bb9 | 2009-02-05 16:31:45 +0000 | [diff] [blame] | 236 | int sqlite3PendingByte = 0x40000000; |
drh | f83dc1e | 2010-06-03 12:09:52 +0000 | [diff] [blame] | 237 | #endif |
drh | a6c2ed9 | 2009-11-14 23:22:23 +0000 | [diff] [blame] | 238 | |
| 239 | #include "opcodes.h" |
| 240 | /* |
| 241 | ** Properties of opcodes. The OPFLG_INITIALIZER macro is |
| 242 | ** created by mkopcodeh.awk during compilation. Data is obtained |
| 243 | ** from the comments following the "case OP_xxxx:" statements in |
| 244 | ** the vdbe.c file. |
| 245 | */ |
| 246 | const unsigned char sqlite3OpcodeProperty[] = OPFLG_INITIALIZER; |