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, |
drh | 1af3fd5 | 2021-03-28 23:37:56 +0000 | [diff] [blame] | 40 | 252,253,254,255, |
drh | 40257ff | 2008-06-13 18:24:27 +0000 | [diff] [blame] | 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 */ |
drh | db222ad | 2015-02-19 17:16:14 +0000 | [diff] [blame] | 49 | 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 */ |
drh | 40257ff | 2008-06-13 18:24:27 +0000 | [diff] [blame] | 51 | 128,129,130,131,132,133,134,135,136,137,138,139,140,141,142,143, /* 8x */ |
drh | db222ad | 2015-02-19 17:16:14 +0000 | [diff] [blame] | 52 | 144,145,146,147,148,149,150,151,152,153,154,155,156,157,158,159, /* 9x */ |
drh | 40257ff | 2008-06-13 18:24:27 +0000 | [diff] [blame] | 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 */ |
drh | db222ad | 2015-02-19 17:16:14 +0000 | [diff] [blame] | 57 | 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 */ |
drh | 40257ff | 2008-06-13 18:24:27 +0000 | [diff] [blame] | 59 | #endif |
drh | 1af3fd5 | 2021-03-28 23:37:56 +0000 | [diff] [blame] | 60 | /* All of the upper-to-lower conversion data is above. The following |
| 61 | ** 18 integers are completely unrelated. They are appended to the |
| 62 | ** sqlite3UpperToLower[] array to avoid UBSAN warnings. Here's what is |
| 63 | ** going on: |
| 64 | ** |
| 65 | ** The SQL comparison operators (<>, =, >, <=, <, and >=) are implemented |
| 66 | ** by invoking sqlite3MemCompare(A,B) which compares values A and B and |
| 67 | ** returns negative, zero, or positive if A is less then, equal to, or |
| 68 | ** greater than B, respectively. Then the true false results is found by |
| 69 | ** consulting sqlite3aLTb[opcode], sqlite3aEQb[opcode], or |
| 70 | ** sqlite3aGTb[opcode] depending on whether the result of compare(A,B) |
| 71 | ** is negative, zero, or positive, where opcode is the specific opcode. |
| 72 | ** The only works because the comparison opcodes are consecutive and in |
| 73 | ** this order: NE EQ GT LE LT GE. Various assert()s throughout the code |
| 74 | ** ensure that is the case. |
| 75 | ** |
| 76 | ** These elements must be appended to another array. Otherwise the |
| 77 | ** index (here shown as [256-OP_Ne]) would be out-of-bounds and thus |
| 78 | ** be undefined behavior. That's goofy, but the C-standards people thought |
| 79 | ** it was a good idea, so here we are. |
| 80 | */ |
| 81 | /* NE EQ GT LE LT GE */ |
| 82 | 1, 0, 0, 1, 1, 0, /* aLTb[]: Use when compare(A,B) less than zero */ |
| 83 | 0, 1, 0, 1, 0, 1, /* aEQb[]: Use when compare(A,B) equals zero */ |
| 84 | 1, 0, 1, 0, 0, 1 /* aGTb[]: Use when compare(A,B) greater than zero*/ |
drh | 40257ff | 2008-06-13 18:24:27 +0000 | [diff] [blame] | 85 | }; |
drh | 1af3fd5 | 2021-03-28 23:37:56 +0000 | [diff] [blame] | 86 | const unsigned char *sqlite3aLTb = &sqlite3UpperToLower[256-OP_Ne]; |
| 87 | const unsigned char *sqlite3aEQb = &sqlite3UpperToLower[256+6-OP_Ne]; |
| 88 | const unsigned char *sqlite3aGTb = &sqlite3UpperToLower[256+12-OP_Ne]; |
drh | 40257ff | 2008-06-13 18:24:27 +0000 | [diff] [blame] | 89 | |
| 90 | /* |
danielk1977 | 78ca0e7 | 2009-01-20 16:53:39 +0000 | [diff] [blame] | 91 | ** The following 256 byte lookup table is used to support SQLites built-in |
| 92 | ** equivalents to the following standard library functions: |
| 93 | ** |
| 94 | ** isspace() 0x01 |
drh | dc86e2b | 2009-01-24 11:30:42 +0000 | [diff] [blame] | 95 | ** isalpha() 0x02 |
danielk1977 | 78ca0e7 | 2009-01-20 16:53:39 +0000 | [diff] [blame] | 96 | ** isdigit() 0x04 |
drh | dc86e2b | 2009-01-24 11:30:42 +0000 | [diff] [blame] | 97 | ** isalnum() 0x06 |
danielk1977 | 78ca0e7 | 2009-01-20 16:53:39 +0000 | [diff] [blame] | 98 | ** isxdigit() 0x08 |
| 99 | ** toupper() 0x20 |
drh | af2b572 | 2009-11-16 15:11:51 +0000 | [diff] [blame] | 100 | ** SQLite identifier character 0x40 |
drh | 244b9d6 | 2016-04-11 19:01:08 +0000 | [diff] [blame] | 101 | ** Quote character 0x80 |
danielk1977 | 78ca0e7 | 2009-01-20 16:53:39 +0000 | [diff] [blame] | 102 | ** |
| 103 | ** Bit 0x20 is set if the mapped character requires translation to upper |
drh | dc86e2b | 2009-01-24 11:30:42 +0000 | [diff] [blame] | 104 | ** case. i.e. if the character is a lower-case ASCII character. |
danielk1977 | 78ca0e7 | 2009-01-20 16:53:39 +0000 | [diff] [blame] | 105 | ** If x is a lower-case ASCII character, then its upper-case equivalent |
| 106 | ** is (x - 0x20). Therefore toupper() can be implemented as: |
| 107 | ** |
| 108 | ** (x & ~(map[x]&0x20)) |
| 109 | ** |
drh | 22fa36d | 2016-09-29 15:53:28 +0000 | [diff] [blame] | 110 | ** The equivalent of tolower() is implemented using the sqlite3UpperToLower[] |
danielk1977 | 78ca0e7 | 2009-01-20 16:53:39 +0000 | [diff] [blame] | 111 | ** array. tolower() is used more often than toupper() by SQLite. |
| 112 | ** |
drh | 22fa36d | 2016-09-29 15:53:28 +0000 | [diff] [blame] | 113 | ** Bit 0x40 is set if the character is non-alphanumeric and can be used in an |
drh | af2b572 | 2009-11-16 15:11:51 +0000 | [diff] [blame] | 114 | ** SQLite identifier. Identifiers are alphanumerics, "_", "$", and any |
| 115 | ** non-ASCII UTF character. Hence the test for whether or not a character is |
| 116 | ** part of an identifier is 0x46. |
danielk1977 | 78ca0e7 | 2009-01-20 16:53:39 +0000 | [diff] [blame] | 117 | */ |
danielk1977 | 78ca0e7 | 2009-01-20 16:53:39 +0000 | [diff] [blame] | 118 | const unsigned char sqlite3CtypeMap[256] = { |
| 119 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 00..07 ........ */ |
| 120 | 0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x00, 0x00, /* 08..0f ........ */ |
| 121 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 10..17 ........ */ |
| 122 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 18..1f ........ */ |
drh | 244b9d6 | 2016-04-11 19:01:08 +0000 | [diff] [blame] | 123 | 0x01, 0x00, 0x80, 0x00, 0x40, 0x00, 0x00, 0x80, /* 20..27 !"#$%&' */ |
danielk1977 | 78ca0e7 | 2009-01-20 16:53:39 +0000 | [diff] [blame] | 124 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 28..2f ()*+,-./ */ |
drh | dc86e2b | 2009-01-24 11:30:42 +0000 | [diff] [blame] | 125 | 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, /* 30..37 01234567 */ |
| 126 | 0x0c, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 38..3f 89:;<=>? */ |
danielk1977 | 78ca0e7 | 2009-01-20 16:53:39 +0000 | [diff] [blame] | 127 | |
| 128 | 0x00, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x02, /* 40..47 @ABCDEFG */ |
| 129 | 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, /* 48..4f HIJKLMNO */ |
| 130 | 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, /* 50..57 PQRSTUVW */ |
drh | 244b9d6 | 2016-04-11 19:01:08 +0000 | [diff] [blame] | 131 | 0x02, 0x02, 0x02, 0x80, 0x00, 0x00, 0x00, 0x40, /* 58..5f XYZ[\]^_ */ |
| 132 | 0x80, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x22, /* 60..67 `abcdefg */ |
danielk1977 | 78ca0e7 | 2009-01-20 16:53:39 +0000 | [diff] [blame] | 133 | 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, /* 68..6f hijklmno */ |
| 134 | 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, /* 70..77 pqrstuvw */ |
| 135 | 0x22, 0x22, 0x22, 0x00, 0x00, 0x00, 0x00, 0x00, /* 78..7f xyz{|}~. */ |
| 136 | |
drh | af2b572 | 2009-11-16 15:11:51 +0000 | [diff] [blame] | 137 | 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, /* 80..87 ........ */ |
| 138 | 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, /* 88..8f ........ */ |
| 139 | 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, /* 90..97 ........ */ |
| 140 | 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, /* 98..9f ........ */ |
| 141 | 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, /* a0..a7 ........ */ |
| 142 | 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, /* a8..af ........ */ |
| 143 | 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, /* b0..b7 ........ */ |
| 144 | 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, /* b8..bf ........ */ |
danielk1977 | 78ca0e7 | 2009-01-20 16:53:39 +0000 | [diff] [blame] | 145 | |
drh | af2b572 | 2009-11-16 15:11:51 +0000 | [diff] [blame] | 146 | 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, /* c0..c7 ........ */ |
| 147 | 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, /* c8..cf ........ */ |
| 148 | 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, /* d0..d7 ........ */ |
| 149 | 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, /* d8..df ........ */ |
| 150 | 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, /* e0..e7 ........ */ |
| 151 | 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, /* e8..ef ........ */ |
| 152 | 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, /* f0..f7 ........ */ |
| 153 | 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40 /* f8..ff ........ */ |
danielk1977 | 78ca0e7 | 2009-01-20 16:53:39 +0000 | [diff] [blame] | 154 | }; |
danielk1977 | 78ca0e7 | 2009-01-20 16:53:39 +0000 | [diff] [blame] | 155 | |
drh | 00729cb | 2014-10-04 11:59:33 +0000 | [diff] [blame] | 156 | /* EVIDENCE-OF: R-02982-34736 In order to maintain full backwards |
| 157 | ** compatibility for legacy applications, the URI filename capability is |
| 158 | ** disabled by default. |
| 159 | ** |
| 160 | ** EVIDENCE-OF: R-38799-08373 URI filenames can be enabled or disabled |
| 161 | ** using the SQLITE_USE_URI=1 or SQLITE_USE_URI=0 compile-time options. |
drh | 4d9f188 | 2014-11-04 17:23:24 +0000 | [diff] [blame] | 162 | ** |
| 163 | ** EVIDENCE-OF: R-43642-56306 By default, URI handling is globally |
| 164 | ** disabled. The default value may be changed by compiling with the |
| 165 | ** SQLITE_USE_URI symbol defined. |
drh | 00729cb | 2014-10-04 11:59:33 +0000 | [diff] [blame] | 166 | */ |
dan | cd74b61 | 2011-04-22 19:37:32 +0000 | [diff] [blame] | 167 | #ifndef SQLITE_USE_URI |
drh | b48c0d5 | 2020-02-07 01:12:53 +0000 | [diff] [blame] | 168 | # define SQLITE_USE_URI 0 |
dan | cd74b61 | 2011-04-22 19:37:32 +0000 | [diff] [blame] | 169 | #endif |
danielk1977 | 78ca0e7 | 2009-01-20 16:53:39 +0000 | [diff] [blame] | 170 | |
drh | 4d9f188 | 2014-11-04 17:23:24 +0000 | [diff] [blame] | 171 | /* EVIDENCE-OF: R-38720-18127 The default setting is determined by the |
| 172 | ** SQLITE_ALLOW_COVERING_INDEX_SCAN compile-time option, or is "on" if |
| 173 | ** that compile-time option is omitted. |
| 174 | */ |
drh | c164cc9 | 2019-06-14 17:37:39 +0000 | [diff] [blame] | 175 | #if !defined(SQLITE_ALLOW_COVERING_INDEX_SCAN) |
drh | de9a7b8 | 2012-09-17 20:44:46 +0000 | [diff] [blame] | 176 | # define SQLITE_ALLOW_COVERING_INDEX_SCAN 1 |
drh | c164cc9 | 2019-06-14 17:37:39 +0000 | [diff] [blame] | 177 | #else |
| 178 | # if !SQLITE_ALLOW_COVERING_INDEX_SCAN |
| 179 | # error "Compile-time disabling of covering index scan using the\ |
| 180 | -DSQLITE_ALLOW_COVERING_INDEX_SCAN=0 option is deprecated.\ |
| 181 | Contact SQLite developers if this is a problem for you, and\ |
| 182 | delete this #error macro to continue with your build." |
| 183 | # endif |
drh | de9a7b8 | 2012-09-17 20:44:46 +0000 | [diff] [blame] | 184 | #endif |
| 185 | |
drh | 3bd1791 | 2015-01-02 15:55:29 +0000 | [diff] [blame] | 186 | /* The minimum PMA size is set to this value multiplied by the database |
| 187 | ** page size in bytes. |
| 188 | */ |
| 189 | #ifndef SQLITE_SORTER_PMASZ |
| 190 | # define SQLITE_SORTER_PMASZ 250 |
| 191 | #endif |
| 192 | |
drh | 8c71a98 | 2016-03-07 17:37:37 +0000 | [diff] [blame] | 193 | /* Statement journals spill to disk when their size exceeds the following |
drh | 22fa36d | 2016-09-29 15:53:28 +0000 | [diff] [blame] | 194 | ** threshold (in bytes). 0 means that statement journals are created and |
drh | 8c71a98 | 2016-03-07 17:37:37 +0000 | [diff] [blame] | 195 | ** written to disk immediately (the default behavior for SQLite versions |
| 196 | ** before 3.12.0). -1 means always keep the entire statement journal in |
| 197 | ** memory. (The statement journal is also always held entirely in memory |
| 198 | ** if journal_mode=MEMORY or if temp_store=MEMORY, regardless of this |
| 199 | ** setting.) |
| 200 | */ |
| 201 | #ifndef SQLITE_STMTJRNL_SPILL |
| 202 | # define SQLITE_STMTJRNL_SPILL (64*1024) |
| 203 | #endif |
| 204 | |
danielk1977 | 78ca0e7 | 2009-01-20 16:53:39 +0000 | [diff] [blame] | 205 | /* |
drh | 56d65cd | 2017-01-02 19:02:20 +0000 | [diff] [blame] | 206 | ** The default lookaside-configuration, the format "SZ,N". SZ is the |
| 207 | ** number of bytes in each lookaside slot (should be a multiple of 8) |
| 208 | ** and N is the number of slots. The lookaside-configuration can be |
| 209 | ** changed as start-time using sqlite3_config(SQLITE_CONFIG_LOOKASIDE) |
| 210 | ** or at run-time for an individual database connection using |
| 211 | ** sqlite3_db_config(db, SQLITE_DBCONFIG_LOOKASIDE); |
drh | d335bc4 | 2019-12-13 16:04:52 +0000 | [diff] [blame] | 212 | ** |
drh | cf014f6 | 2019-12-31 15:12:34 +0000 | [diff] [blame] | 213 | ** With the two-size-lookaside enhancement, less lookaside is required. |
| 214 | ** The default configuration of 1200,40 actually provides 30 1200-byte slots |
| 215 | ** and 93 128-byte slots, which is more lookaside than is available |
| 216 | ** using the older 1200,100 configuration without two-size-lookaside. |
drh | 56d65cd | 2017-01-02 19:02:20 +0000 | [diff] [blame] | 217 | */ |
| 218 | #ifndef SQLITE_DEFAULT_LOOKASIDE |
drh | cf014f6 | 2019-12-31 15:12:34 +0000 | [diff] [blame] | 219 | # ifdef SQLITE_OMIT_TWOSIZE_LOOKASIDE |
drh | d335bc4 | 2019-12-13 16:04:52 +0000 | [diff] [blame] | 220 | # define SQLITE_DEFAULT_LOOKASIDE 1200,100 /* 120KB of memory */ |
| 221 | # else |
| 222 | # define SQLITE_DEFAULT_LOOKASIDE 1200,40 /* 48KB of memory */ |
| 223 | # endif |
drh | 56d65cd | 2017-01-02 19:02:20 +0000 | [diff] [blame] | 224 | #endif |
| 225 | |
| 226 | |
drh | 23a8859 | 2019-01-31 15:38:53 +0000 | [diff] [blame] | 227 | /* The default maximum size of an in-memory database created using |
| 228 | ** sqlite3_deserialize() |
| 229 | */ |
| 230 | #ifndef SQLITE_MEMDB_DEFAULT_MAXSIZE |
| 231 | # define SQLITE_MEMDB_DEFAULT_MAXSIZE 1073741824 |
| 232 | #endif |
| 233 | |
drh | 56d65cd | 2017-01-02 19:02:20 +0000 | [diff] [blame] | 234 | /* |
drh | 40257ff | 2008-06-13 18:24:27 +0000 | [diff] [blame] | 235 | ** The following singleton contains the global configuration for |
| 236 | ** the SQLite library. |
| 237 | */ |
danielk1977 | 075c23a | 2008-09-01 18:34:20 +0000 | [diff] [blame] | 238 | SQLITE_WSD struct Sqlite3Config sqlite3Config = { |
danielk1977 | 0a732f5 | 2008-09-04 17:17:38 +0000 | [diff] [blame] | 239 | SQLITE_DEFAULT_MEMSTATUS, /* bMemstat */ |
| 240 | 1, /* bCoreMutex */ |
| 241 | SQLITE_THREADSAFE==1, /* bFullMutex */ |
dan | cd74b61 | 2011-04-22 19:37:32 +0000 | [diff] [blame] | 242 | SQLITE_USE_URI, /* bOpenUri */ |
drh | de9a7b8 | 2012-09-17 20:44:46 +0000 | [diff] [blame] | 243 | SQLITE_ALLOW_COVERING_INDEX_SCAN, /* bUseCis */ |
drh | b2a0f75 | 2017-08-28 15:51:35 +0000 | [diff] [blame] | 244 | 0, /* bSmallMalloc */ |
drh | 3084299 | 2019-08-12 14:17:43 +0000 | [diff] [blame] | 245 | 1, /* bExtraSchemaChecks */ |
danielk1977 | 0a732f5 | 2008-09-04 17:17:38 +0000 | [diff] [blame] | 246 | 0x7ffffffe, /* mxStrlen */ |
drh | 09fe614 | 2013-11-29 15:06:27 +0000 | [diff] [blame] | 247 | 0, /* neverCorrupt */ |
drh | 56d65cd | 2017-01-02 19:02:20 +0000 | [diff] [blame] | 248 | SQLITE_DEFAULT_LOOKASIDE, /* szLookaside, nLookaside */ |
drh | 8c71a98 | 2016-03-07 17:37:37 +0000 | [diff] [blame] | 249 | SQLITE_STMTJRNL_SPILL, /* nStmtSpill */ |
drh | 1875f7a | 2008-12-08 18:19:17 +0000 | [diff] [blame] | 250 | {0,0,0,0,0,0,0,0}, /* m */ |
| 251 | {0,0,0,0,0,0,0,0,0}, /* mutex */ |
drh | 13e0ea9 | 2011-12-11 02:29:25 +0000 | [diff] [blame] | 252 | {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] | 253 | (void*)0, /* pHeap */ |
| 254 | 0, /* nHeap */ |
| 255 | 0, 0, /* mnHeap, mxHeap */ |
drh | 9b4c59f | 2013-04-15 17:03:42 +0000 | [diff] [blame] | 256 | SQLITE_DEFAULT_MMAP_SIZE, /* szMmap */ |
| 257 | SQLITE_MAX_MMAP_SIZE, /* mxMmap */ |
drh | 1875f7a | 2008-12-08 18:19:17 +0000 | [diff] [blame] | 258 | (void*)0, /* pPage */ |
| 259 | 0, /* szPage */ |
drh | 4297c7c | 2015-07-07 21:14:42 +0000 | [diff] [blame] | 260 | SQLITE_DEFAULT_PCACHE_INITSZ, /* nPage */ |
drh | 1875f7a | 2008-12-08 18:19:17 +0000 | [diff] [blame] | 261 | 0, /* mxParserStack */ |
| 262 | 0, /* sharedCacheEnabled */ |
drh | 3bd1791 | 2015-01-02 15:55:29 +0000 | [diff] [blame] | 263 | SQLITE_SORTER_PMASZ, /* szPma */ |
drh | 9ac0650 | 2009-08-17 13:42:29 +0000 | [diff] [blame] | 264 | /* All the rest should always be initialized to zero */ |
drh | 1875f7a | 2008-12-08 18:19:17 +0000 | [diff] [blame] | 265 | 0, /* isInit */ |
| 266 | 0, /* inProgress */ |
dan | e1ab219 | 2009-08-17 15:16:19 +0000 | [diff] [blame] | 267 | 0, /* isMutexInit */ |
drh | 1875f7a | 2008-12-08 18:19:17 +0000 | [diff] [blame] | 268 | 0, /* isMallocInit */ |
dan | e1ab219 | 2009-08-17 15:16:19 +0000 | [diff] [blame] | 269 | 0, /* isPCacheInit */ |
drh | 1875f7a | 2008-12-08 18:19:17 +0000 | [diff] [blame] | 270 | 0, /* nRefInitMutex */ |
drh | c007f61 | 2014-05-16 14:17:01 +0000 | [diff] [blame] | 271 | 0, /* pInitMutex */ |
drh | 3f28070 | 2010-02-18 18:45:09 +0000 | [diff] [blame] | 272 | 0, /* xLog */ |
| 273 | 0, /* pLogArg */ |
dan | ac45593 | 2012-11-26 19:50:41 +0000 | [diff] [blame] | 274 | #ifdef SQLITE_ENABLE_SQLLOG |
| 275 | 0, /* xSqllog */ |
drh | c007f61 | 2014-05-16 14:17:01 +0000 | [diff] [blame] | 276 | 0, /* pSqllogArg */ |
dan | ac45593 | 2012-11-26 19:50:41 +0000 | [diff] [blame] | 277 | #endif |
drh | c007f61 | 2014-05-16 14:17:01 +0000 | [diff] [blame] | 278 | #ifdef SQLITE_VDBE_COVERAGE |
| 279 | 0, /* xVdbeBranch */ |
| 280 | 0, /* pVbeBranchArg */ |
| 281 | #endif |
drh | 8d889af | 2021-05-08 17:18:23 +0000 | [diff] [blame] | 282 | #ifndef SQLITE_OMIT_DESERIALIZE |
drh | 23a8859 | 2019-01-31 15:38:53 +0000 | [diff] [blame] | 283 | SQLITE_MEMDB_DEFAULT_MAXSIZE, /* mxMemdbSize */ |
| 284 | #endif |
drh | d12602a | 2016-12-07 15:49:02 +0000 | [diff] [blame] | 285 | #ifndef SQLITE_UNTESTABLE |
drh | c007f61 | 2014-05-16 14:17:01 +0000 | [diff] [blame] | 286 | 0, /* xTestCallback */ |
| 287 | #endif |
drh | 9e5eb9c | 2016-09-18 16:08:10 +0000 | [diff] [blame] | 288 | 0, /* bLocaltimeFault */ |
drh | d7e185c | 2022-02-10 21:26:53 +0000 | [diff] [blame] | 289 | 0, /* xAltLocaltime */ |
dan | 2e3a5a8 | 2018-04-16 21:12:42 +0000 | [diff] [blame] | 290 | 0x7ffffffe, /* iOnceResetThreshold */ |
drh | 23a8859 | 2019-01-31 15:38:53 +0000 | [diff] [blame] | 291 | SQLITE_DEFAULT_SORTERREF_SIZE, /* szSorterRef */ |
drh | ade54d6 | 2019-08-02 20:45:04 +0000 | [diff] [blame] | 292 | 0, /* iPrngSeed */ |
drh | 633e6d5 | 2008-07-28 19:34:53 +0000 | [diff] [blame] | 293 | }; |
drh | 70a8ca3 | 2008-08-21 18:49:27 +0000 | [diff] [blame] | 294 | |
drh | 70a8ca3 | 2008-08-21 18:49:27 +0000 | [diff] [blame] | 295 | /* |
| 296 | ** Hash table for global functions - functions common to all |
| 297 | ** database connections. After initialization, this table is |
| 298 | ** read-only. |
| 299 | */ |
drh | 80738d9 | 2016-02-15 00:34:16 +0000 | [diff] [blame] | 300 | FuncDefHash sqlite3BuiltinFunctions; |
drh | c7a3bb9 | 2009-02-05 16:31:45 +0000 | [diff] [blame] | 301 | |
drh | dcf10a1 | 2021-10-22 11:17:29 +0000 | [diff] [blame] | 302 | #if defined(SQLITE_COVERAGE_TEST) || defined(SQLITE_DEBUG) |
drh | 9fdd66e | 2021-10-20 17:58:33 +0000 | [diff] [blame] | 303 | /* |
| 304 | ** Counter used for coverage testing. Does not come into play for |
| 305 | ** release builds. |
drh | dcf10a1 | 2021-10-22 11:17:29 +0000 | [diff] [blame] | 306 | ** |
| 307 | ** Access to this global variable is not mutex protected. This might |
| 308 | ** result in TSAN warnings. But as the variable does not exist in |
| 309 | ** release builds, that should not be a concern. |
drh | 9fdd66e | 2021-10-20 17:58:33 +0000 | [diff] [blame] | 310 | */ |
| 311 | unsigned int sqlite3CoverageCounter; |
drh | dcf10a1 | 2021-10-22 11:17:29 +0000 | [diff] [blame] | 312 | #endif /* SQLITE_COVERAGE_TEST || SQLITE_DEBUG */ |
drh | 9fdd66e | 2021-10-20 17:58:33 +0000 | [diff] [blame] | 313 | |
drh | 35043cc | 2018-02-12 20:27:34 +0000 | [diff] [blame] | 314 | #ifdef VDBE_PROFILE |
| 315 | /* |
| 316 | ** The following performance counter can be used in place of |
| 317 | ** sqlite3Hwtime() for profiling. This is a no-op on standard builds. |
| 318 | */ |
| 319 | sqlite3_uint64 sqlite3NProfileCnt = 0; |
| 320 | #endif |
drh | 094430e | 2010-07-14 18:24:06 +0000 | [diff] [blame] | 321 | |
| 322 | /* |
drh | c7a3bb9 | 2009-02-05 16:31:45 +0000 | [diff] [blame] | 323 | ** The value of the "pending" byte must be 0x40000000 (1 byte past the |
| 324 | ** 1-gibabyte boundary) in a compatible database. SQLite never uses |
| 325 | ** the database page that contains the pending byte. It never attempts |
drh | 22fa36d | 2016-09-29 15:53:28 +0000 | [diff] [blame] | 326 | ** to read or write that page. The pending byte page is set aside |
drh | c7a3bb9 | 2009-02-05 16:31:45 +0000 | [diff] [blame] | 327 | ** for use by the VFS layers as space for managing file locks. |
| 328 | ** |
| 329 | ** During testing, it is often desirable to move the pending byte to |
| 330 | ** a different position in the file. This allows code that has to |
| 331 | ** deal with the pending byte to run on files that are much smaller |
| 332 | ** than 1 GiB. The sqlite3_test_control() interface can be used to |
| 333 | ** move the pending byte. |
| 334 | ** |
| 335 | ** IMPORTANT: Changing the pending byte to any value other than |
| 336 | ** 0x40000000 results in an incompatible database file format! |
drh | 86a11b8 | 2014-11-07 13:24:29 +0000 | [diff] [blame] | 337 | ** Changing the pending byte during operation will result in undefined |
| 338 | ** and incorrect behavior. |
drh | c7a3bb9 | 2009-02-05 16:31:45 +0000 | [diff] [blame] | 339 | */ |
drh | f83dc1e | 2010-06-03 12:09:52 +0000 | [diff] [blame] | 340 | #ifndef SQLITE_OMIT_WSD |
drh | c7a3bb9 | 2009-02-05 16:31:45 +0000 | [diff] [blame] | 341 | int sqlite3PendingByte = 0x40000000; |
drh | f83dc1e | 2010-06-03 12:09:52 +0000 | [diff] [blame] | 342 | #endif |
drh | a6c2ed9 | 2009-11-14 23:22:23 +0000 | [diff] [blame] | 343 | |
drh | 9216de8 | 2020-06-11 00:57:09 +0000 | [diff] [blame] | 344 | /* |
drh | c0622a4 | 2020-12-04 01:17:57 +0000 | [diff] [blame] | 345 | ** Tracing flags set by SQLITE_TESTCTRL_TRACEFLAGS. |
drh | 9216de8 | 2020-06-11 00:57:09 +0000 | [diff] [blame] | 346 | */ |
drh | c0622a4 | 2020-12-04 01:17:57 +0000 | [diff] [blame] | 347 | u32 sqlite3SelectTrace = 0; |
| 348 | u32 sqlite3WhereTrace = 0; |
drh | 9216de8 | 2020-06-11 00:57:09 +0000 | [diff] [blame] | 349 | |
drh | a6c2ed9 | 2009-11-14 23:22:23 +0000 | [diff] [blame] | 350 | #include "opcodes.h" |
| 351 | /* |
| 352 | ** Properties of opcodes. The OPFLG_INITIALIZER macro is |
| 353 | ** created by mkopcodeh.awk during compilation. Data is obtained |
| 354 | ** from the comments following the "case OP_xxxx:" statements in |
| 355 | ** the vdbe.c file. |
| 356 | */ |
| 357 | const unsigned char sqlite3OpcodeProperty[] = OPFLG_INITIALIZER; |
drh | f19aa5f | 2015-12-30 16:51:20 +0000 | [diff] [blame] | 358 | |
| 359 | /* |
| 360 | ** Name of the default collating sequence |
| 361 | */ |
| 362 | const char sqlite3StrBINARY[] = "BINARY"; |
drh | c2df4d6 | 2021-07-30 23:30:30 +0000 | [diff] [blame] | 363 | |
| 364 | /* |
| 365 | ** Standard typenames. These names must match the COLTYPE_* definitions. |
| 366 | ** Adjust the SQLITE_N_STDTYPE value if adding or removing entries. |
drh | 71c770f | 2021-08-19 16:29:33 +0000 | [diff] [blame] | 367 | ** |
| 368 | ** sqlite3StdType[] The actual names of the datatypes. |
| 369 | ** |
| 370 | ** sqlite3StdTypeLen[] The length (in bytes) of each entry |
| 371 | ** in sqlite3StdType[]. |
| 372 | ** |
| 373 | ** sqlite3StdTypeAffinity[] The affinity associated with each entry |
| 374 | ** in sqlite3StdType[]. |
| 375 | ** |
| 376 | ** sqlite3StdTypeMap[] The type value (as returned from |
| 377 | ** sqlite3_column_type() or sqlite3_value_type()) |
| 378 | ** for each entry in sqlite3StdType[]. |
drh | c2df4d6 | 2021-07-30 23:30:30 +0000 | [diff] [blame] | 379 | */ |
drh | b9fd010 | 2021-08-23 10:28:02 +0000 | [diff] [blame] | 380 | const unsigned char sqlite3StdTypeLen[] = { 3, 4, 3, 7, 4, 4 }; |
drh | c2df4d6 | 2021-07-30 23:30:30 +0000 | [diff] [blame] | 381 | const char sqlite3StdTypeAffinity[] = { |
drh | b9fd010 | 2021-08-23 10:28:02 +0000 | [diff] [blame] | 382 | SQLITE_AFF_NUMERIC, |
drh | c2df4d6 | 2021-07-30 23:30:30 +0000 | [diff] [blame] | 383 | SQLITE_AFF_BLOB, |
| 384 | SQLITE_AFF_INTEGER, |
| 385 | SQLITE_AFF_INTEGER, |
| 386 | SQLITE_AFF_REAL, |
| 387 | SQLITE_AFF_TEXT |
| 388 | }; |
drh | 9e1209d | 2021-08-19 02:58:15 +0000 | [diff] [blame] | 389 | const char sqlite3StdTypeMap[] = { |
drh | b9fd010 | 2021-08-23 10:28:02 +0000 | [diff] [blame] | 390 | 0, |
drh | 9e1209d | 2021-08-19 02:58:15 +0000 | [diff] [blame] | 391 | SQLITE_BLOB, |
| 392 | SQLITE_INTEGER, |
| 393 | SQLITE_INTEGER, |
| 394 | SQLITE_FLOAT, |
| 395 | SQLITE_TEXT |
| 396 | }; |
drh | c2df4d6 | 2021-07-30 23:30:30 +0000 | [diff] [blame] | 397 | const char *sqlite3StdType[] = { |
drh | b9fd010 | 2021-08-23 10:28:02 +0000 | [diff] [blame] | 398 | "ANY", |
drh | c2df4d6 | 2021-07-30 23:30:30 +0000 | [diff] [blame] | 399 | "BLOB", |
| 400 | "INT", |
| 401 | "INTEGER", |
| 402 | "REAL", |
| 403 | "TEXT" |
| 404 | }; |