drh | 7589723 | 2000-05-29 14:26:00 +0000 | [diff] [blame] | 1 | /* |
drh | b19a2bc | 2001-09-16 00:13:26 +0000 | [diff] [blame] | 2 | ** 2001 September 15 |
drh | 7589723 | 2000-05-29 14:26:00 +0000 | [diff] [blame] | 3 | ** |
drh | b19a2bc | 2001-09-16 00:13:26 +0000 | [diff] [blame] | 4 | ** The author disclaims copyright to this source code. In place of |
| 5 | ** a legal notice, here is a blessing: |
drh | 7589723 | 2000-05-29 14:26:00 +0000 | [diff] [blame] | 6 | ** |
drh | b19a2bc | 2001-09-16 00:13:26 +0000 | [diff] [blame] | 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. |
drh | 7589723 | 2000-05-29 14:26:00 +0000 | [diff] [blame] | 10 | ** |
| 11 | ************************************************************************* |
| 12 | ** Internal interface definitions for SQLite. |
| 13 | ** |
danielk1977 | d025174 | 2008-06-18 18:57:42 +0000 | [diff] [blame] | 14 | ** @(#) $Id: sqliteInt.h,v 1.715 2008/06/18 18:57:42 danielk1977 Exp $ |
drh | 7589723 | 2000-05-29 14:26:00 +0000 | [diff] [blame] | 15 | */ |
danielk1977 | e302663 | 2004-06-22 11:29:02 +0000 | [diff] [blame] | 16 | #ifndef _SQLITEINT_H_ |
| 17 | #define _SQLITEINT_H_ |
drh | 71674ce | 2007-10-23 15:51:26 +0000 | [diff] [blame] | 18 | |
mlcreech | bd0ae11 | 2008-03-06 09:16:24 +0000 | [diff] [blame] | 19 | /* |
mlcreech | 1e12d43 | 2008-05-07 02:42:01 +0000 | [diff] [blame] | 20 | ** Include the configuration header output by 'configure' if we're using the |
| 21 | ** autoconf-based build |
mlcreech | bd0ae11 | 2008-03-06 09:16:24 +0000 | [diff] [blame] | 22 | */ |
mlcreech | 1e12d43 | 2008-05-07 02:42:01 +0000 | [diff] [blame] | 23 | #ifdef _HAVE_SQLITE_CONFIG_H |
mlcreech | 98dc4b1 | 2008-03-06 16:28:58 +0000 | [diff] [blame] | 24 | #include "config.h" |
mlcreech | 1e12d43 | 2008-05-07 02:42:01 +0000 | [diff] [blame] | 25 | #endif |
| 26 | |
drh | bb4957f | 2008-03-20 14:03:29 +0000 | [diff] [blame] | 27 | #include "sqliteLimit.h" |
mlcreech | 98dc4b1 | 2008-03-06 16:28:58 +0000 | [diff] [blame] | 28 | |
drh | e296582 | 2008-04-10 16:47:41 +0000 | [diff] [blame] | 29 | /* Disable nuisance warnings on Borland compilers */ |
| 30 | #if defined(__BORLANDC__) |
| 31 | #pragma warn -rch /* unreachable code */ |
| 32 | #pragma warn -ccc /* Condition is always true or false */ |
| 33 | #pragma warn -aus /* Assigned value is never used */ |
| 34 | #pragma warn -csu /* Comparing signed and unsigned */ |
| 35 | #pragma warn -spa /* Suspicous pointer arithmetic */ |
| 36 | #endif |
| 37 | |
mlcreech | 98dc4b1 | 2008-03-06 16:28:58 +0000 | [diff] [blame] | 38 | /* Needed for various definitions... */ |
| 39 | #define _GNU_SOURCE |
| 40 | |
| 41 | /* |
drh | 06af763 | 2008-04-28 12:54:15 +0000 | [diff] [blame] | 42 | ** Include standard header files as necessary |
| 43 | */ |
| 44 | #ifdef HAVE_STDINT_H |
| 45 | #include <stdint.h> |
| 46 | #endif |
| 47 | #ifdef HAVE_INTTYPES_H |
| 48 | #include <inttypes.h> |
| 49 | #endif |
| 50 | |
| 51 | /* |
drh | c5499be | 2008-04-01 15:06:33 +0000 | [diff] [blame] | 52 | ** A macro used to aid in coverage testing. When doing coverage |
| 53 | ** testing, the condition inside the argument must be evaluated |
| 54 | ** both true and false in order to get full branch coverage. |
| 55 | ** This macro can be inserted to ensure adequate test coverage |
| 56 | ** in places where simple condition/decision coverage is inadequate. |
| 57 | */ |
| 58 | #ifdef SQLITE_COVERAGE_TEST |
| 59 | void sqlite3Coverage(int); |
| 60 | # define testcase(X) if( X ){ sqlite3Coverage(__LINE__); } |
| 61 | #else |
| 62 | # define testcase(X) |
| 63 | #endif |
| 64 | |
mlcreech | 98dc4b1 | 2008-03-06 16:28:58 +0000 | [diff] [blame] | 65 | |
drh | 71674ce | 2007-10-23 15:51:26 +0000 | [diff] [blame] | 66 | /* |
drh | b6dbc00 | 2007-11-27 02:38:00 +0000 | [diff] [blame] | 67 | ** The macro unlikely() is a hint that surrounds a boolean |
| 68 | ** expression that is usually false. Macro likely() surrounds |
| 69 | ** a boolean expression that is usually true. GCC is able to |
| 70 | ** use these hints to generate better code, sometimes. |
| 71 | */ |
drh | 4bbf464 | 2008-01-30 16:14:23 +0000 | [diff] [blame] | 72 | #if defined(__GNUC__) && 0 |
drh | b6dbc00 | 2007-11-27 02:38:00 +0000 | [diff] [blame] | 73 | # define likely(X) __builtin_expect((X),1) |
| 74 | # define unlikely(X) __builtin_expect((X),0) |
| 75 | #else |
| 76 | # define likely(X) !!(X) |
| 77 | # define unlikely(X) !!(X) |
| 78 | #endif |
| 79 | |
| 80 | |
| 81 | /* |
drh | 71674ce | 2007-10-23 15:51:26 +0000 | [diff] [blame] | 82 | ** These #defines should enable >2GB file support on Posix if the |
| 83 | ** underlying operating system supports it. If the OS lacks |
| 84 | ** large file support, or if the OS is windows, these should be no-ops. |
| 85 | ** |
| 86 | ** Ticket #2739: The _LARGEFILE_SOURCE macro must appear before any |
| 87 | ** system #includes. Hence, this block of code must be the very first |
| 88 | ** code in all source files. |
| 89 | ** |
| 90 | ** Large file support can be disabled using the -DSQLITE_DISABLE_LFS switch |
| 91 | ** on the compiler command line. This is necessary if you are compiling |
| 92 | ** on a recent machine (ex: RedHat 7.2) but you want your code to work |
| 93 | ** on an older machine (ex: RedHat 6.0). If you compile on RedHat 7.2 |
| 94 | ** without this option, LFS is enable. But LFS does not exist in the kernel |
| 95 | ** in RedHat 6.0, so the code won't work. Hence, for maximum binary |
| 96 | ** portability you should omit LFS. |
| 97 | ** |
| 98 | ** Similar is true for MacOS. LFS is only supported on MacOS 9 and later. |
| 99 | */ |
| 100 | #ifndef SQLITE_DISABLE_LFS |
| 101 | # define _LARGE_FILE 1 |
| 102 | # ifndef _FILE_OFFSET_BITS |
| 103 | # define _FILE_OFFSET_BITS 64 |
| 104 | # endif |
| 105 | # define _LARGEFILE_SOURCE 1 |
| 106 | #endif |
| 107 | |
| 108 | |
drh | e5e7a90 | 2007-10-01 17:47:00 +0000 | [diff] [blame] | 109 | /* |
| 110 | ** The SQLITE_THREADSAFE macro must be defined as either 0 or 1. |
| 111 | ** Older versions of SQLite used an optional THREADSAFE macro. |
| 112 | ** We support that for legacy |
| 113 | */ |
| 114 | #if !defined(SQLITE_THREADSAFE) |
| 115 | #if defined(THREADSAFE) |
| 116 | # define SQLITE_THREADSAFE THREADSAFE |
| 117 | #else |
| 118 | # define SQLITE_THREADSAFE 1 |
| 119 | #endif |
| 120 | #endif |
| 121 | |
drh | 6708061 | 2007-10-01 14:30:14 +0000 | [diff] [blame] | 122 | /* |
drh | 0d18020 | 2008-02-14 23:26:56 +0000 | [diff] [blame] | 123 | ** Exactly one of the following macros must be defined in order to |
| 124 | ** specify which memory allocation subsystem to use. |
| 125 | ** |
| 126 | ** SQLITE_SYSTEM_MALLOC // Use normal system malloc() |
| 127 | ** SQLITE_MEMDEBUG // Debugging version of system malloc() |
| 128 | ** SQLITE_MEMORY_SIZE // internal allocator #1 |
| 129 | ** SQLITE_MMAP_HEAP_SIZE // internal mmap() allocator |
| 130 | ** SQLITE_POW2_MEMORY_SIZE // internal power-of-two allocator |
| 131 | ** |
| 132 | ** If none of the above are defined, then set SQLITE_SYSTEM_MALLOC as |
| 133 | ** the default. |
| 134 | */ |
| 135 | #if defined(SQLITE_SYSTEM_MALLOC)+defined(SQLITE_MEMDEBUG)+\ |
| 136 | defined(SQLITE_MEMORY_SIZE)+defined(SQLITE_MMAP_HEAP_SIZE)+\ |
| 137 | defined(SQLITE_POW2_MEMORY_SIZE)>1 |
| 138 | # error "At most one of the following compile-time configuration options\ |
| 139 | is allows: SQLITE_SYSTEM_MALLOC, SQLITE_MEMDEBUG, SQLITE_MEMORY_SIZE,\ |
| 140 | SQLITE_MMAP_HEAP_SIZE, SQLITE_POW2_MEMORY_SIZE" |
| 141 | #endif |
| 142 | #if defined(SQLITE_SYSTEM_MALLOC)+defined(SQLITE_MEMDEBUG)+\ |
| 143 | defined(SQLITE_MEMORY_SIZE)+defined(SQLITE_MMAP_HEAP_SIZE)+\ |
| 144 | defined(SQLITE_POW2_MEMORY_SIZE)==0 |
| 145 | # define SQLITE_SYSTEM_MALLOC 1 |
| 146 | #endif |
| 147 | |
| 148 | /* |
drh | eee4c8c | 2008-02-18 22:24:57 +0000 | [diff] [blame] | 149 | ** If SQLITE_MALLOC_SOFT_LIMIT is defined, then try to keep the |
| 150 | ** sizes of memory allocations below this value where possible. |
| 151 | */ |
| 152 | #if defined(SQLITE_POW2_MEMORY_SIZE) && !defined(SQLITE_MALLOC_SOFT_LIMIT) |
| 153 | # define SQLITE_MALLOC_SOFT_LIMIT 1024 |
| 154 | #endif |
| 155 | |
| 156 | /* |
drh | 6708061 | 2007-10-01 14:30:14 +0000 | [diff] [blame] | 157 | ** We need to define _XOPEN_SOURCE as follows in order to enable |
| 158 | ** recursive mutexes on most unix systems. But Mac OS X is different. |
| 159 | ** The _XOPEN_SOURCE define causes problems for Mac OS X we are told, |
| 160 | ** so it is omitted there. See ticket #2673. |
drh | e5e7a90 | 2007-10-01 17:47:00 +0000 | [diff] [blame] | 161 | ** |
| 162 | ** Later we learn that _XOPEN_SOURCE is poorly or incorrectly |
| 163 | ** implemented on some systems. So we avoid defining it at all |
| 164 | ** if it is already defined or if it is unneeded because we are |
| 165 | ** not doing a threadsafe build. Ticket #2681. |
drh | 9e0ebbf | 2007-10-23 15:59:18 +0000 | [diff] [blame] | 166 | ** |
| 167 | ** See also ticket #2741. |
drh | 6708061 | 2007-10-01 14:30:14 +0000 | [diff] [blame] | 168 | */ |
aswift | ee99b90 | 2008-01-28 22:09:23 +0000 | [diff] [blame] | 169 | #if !defined(_XOPEN_SOURCE) && !defined(__DARWIN__) && !defined(__APPLE__) && SQLITE_THREADSAFE |
drh | 6708061 | 2007-10-01 14:30:14 +0000 | [diff] [blame] | 170 | # define _XOPEN_SOURCE 500 /* Needed to enable pthread recursive mutexes */ |
| 171 | #endif |
danielk1977 | e302663 | 2004-06-22 11:29:02 +0000 | [diff] [blame] | 172 | |
drh | 4f0c587 | 2007-03-26 22:05:01 +0000 | [diff] [blame] | 173 | #if defined(SQLITE_TCL) || defined(TCLSH) |
| 174 | # include <tcl.h> |
drh | 824d7c1 | 2006-01-06 12:03:19 +0000 | [diff] [blame] | 175 | #endif |
| 176 | |
| 177 | /* |
drh | 4b529d9 | 2005-09-13 00:00:00 +0000 | [diff] [blame] | 178 | ** Many people are failing to set -DNDEBUG=1 when compiling SQLite. |
drh | b27795c | 2005-09-13 00:02:16 +0000 | [diff] [blame] | 179 | ** Setting NDEBUG makes the code smaller and run faster. So the following |
drh | 4b529d9 | 2005-09-13 00:00:00 +0000 | [diff] [blame] | 180 | ** lines are added to automatically set NDEBUG unless the -DSQLITE_DEBUG=1 |
| 181 | ** option is set. Thus NDEBUG becomes an opt-in rather than an opt-out |
| 182 | ** feature. |
| 183 | */ |
danielk1977 | 771151b | 2006-01-17 13:21:40 +0000 | [diff] [blame] | 184 | #if !defined(NDEBUG) && !defined(SQLITE_DEBUG) |
drh | 4b529d9 | 2005-09-13 00:00:00 +0000 | [diff] [blame] | 185 | # define NDEBUG 1 |
| 186 | #endif |
| 187 | |
drh | 1d482dd | 2004-05-31 18:23:07 +0000 | [diff] [blame] | 188 | #include "sqlite3.h" |
drh | beae319 | 2001-09-22 18:12:08 +0000 | [diff] [blame] | 189 | #include "hash.h" |
drh | 7589723 | 2000-05-29 14:26:00 +0000 | [diff] [blame] | 190 | #include "parse.h" |
drh | 7589723 | 2000-05-29 14:26:00 +0000 | [diff] [blame] | 191 | #include <stdio.h> |
| 192 | #include <stdlib.h> |
| 193 | #include <string.h> |
| 194 | #include <assert.h> |
drh | 52370e2 | 2005-01-21 21:31:40 +0000 | [diff] [blame] | 195 | #include <stddef.h> |
drh | 7589723 | 2000-05-29 14:26:00 +0000 | [diff] [blame] | 196 | |
drh | 967e8b7 | 2000-06-21 13:59:10 +0000 | [diff] [blame] | 197 | /* |
drh | b37df7b | 2005-10-13 02:09:49 +0000 | [diff] [blame] | 198 | ** If compiling for a processor that lacks floating point support, |
| 199 | ** substitute integer for floating-point |
| 200 | */ |
| 201 | #ifdef SQLITE_OMIT_FLOATING_POINT |
| 202 | # define double sqlite_int64 |
| 203 | # define LONGDOUBLE_TYPE sqlite_int64 |
drh | d116739 | 2006-01-23 13:00:35 +0000 | [diff] [blame] | 204 | # ifndef SQLITE_BIG_DBL |
| 205 | # define SQLITE_BIG_DBL (0x7fffffffffffffff) |
| 206 | # endif |
drh | b37df7b | 2005-10-13 02:09:49 +0000 | [diff] [blame] | 207 | # define SQLITE_OMIT_DATETIME_FUNCS 1 |
| 208 | # define SQLITE_OMIT_TRACE 1 |
drh | 110daac | 2007-05-04 11:59:31 +0000 | [diff] [blame] | 209 | # undef SQLITE_MIXED_ENDIAN_64BIT_FLOAT |
drh | b37df7b | 2005-10-13 02:09:49 +0000 | [diff] [blame] | 210 | #endif |
drh | d116739 | 2006-01-23 13:00:35 +0000 | [diff] [blame] | 211 | #ifndef SQLITE_BIG_DBL |
| 212 | # define SQLITE_BIG_DBL (1e99) |
| 213 | #endif |
drh | b37df7b | 2005-10-13 02:09:49 +0000 | [diff] [blame] | 214 | |
| 215 | /* |
danielk1977 | 53c0f74 | 2005-03-29 03:10:59 +0000 | [diff] [blame] | 216 | ** OMIT_TEMPDB is set to 1 if SQLITE_OMIT_TEMPDB is defined, or 0 |
| 217 | ** afterward. Having this macro allows us to cause the C compiler |
| 218 | ** to omit code used by TEMP tables without messy #ifndef statements. |
| 219 | */ |
| 220 | #ifdef SQLITE_OMIT_TEMPDB |
| 221 | #define OMIT_TEMPDB 1 |
| 222 | #else |
| 223 | #define OMIT_TEMPDB 0 |
| 224 | #endif |
| 225 | |
| 226 | /* |
drh | 0bd1f4e | 2002-06-06 18:54:39 +0000 | [diff] [blame] | 227 | ** If the following macro is set to 1, then NULL values are considered |
drh | 0bd1f4e | 2002-06-06 18:54:39 +0000 | [diff] [blame] | 228 | ** distinct when determining whether or not two entries are the same |
| 229 | ** in a UNIQUE index. This is the way PostgreSQL, Oracle, DB2, MySQL, |
| 230 | ** OCELOT, and Firebird all work. The SQL92 spec explicitly says this |
| 231 | ** is the way things are suppose to work. |
| 232 | ** |
| 233 | ** If the following macro is set to 0, the NULLs are indistinct for |
| 234 | ** a UNIQUE index. In this mode, you can only have a single NULL entry |
| 235 | ** for a column declared UNIQUE. This is the way Informix and SQL Server |
| 236 | ** work. |
| 237 | */ |
| 238 | #define NULL_DISTINCT_FOR_UNIQUE 1 |
| 239 | |
| 240 | /* |
drh | d946db0 | 2005-12-29 19:23:06 +0000 | [diff] [blame] | 241 | ** The "file format" number is an integer that is incremented whenever |
| 242 | ** the VDBE-level file format changes. The following macros define the |
| 243 | ** the default file format for new databases and the maximum file format |
| 244 | ** that the library can read. |
| 245 | */ |
| 246 | #define SQLITE_MAX_FILE_FORMAT 4 |
| 247 | #ifndef SQLITE_DEFAULT_FILE_FORMAT |
drh | 76fe803 | 2006-07-11 14:17:51 +0000 | [diff] [blame] | 248 | # define SQLITE_DEFAULT_FILE_FORMAT 1 |
drh | d946db0 | 2005-12-29 19:23:06 +0000 | [diff] [blame] | 249 | #endif |
| 250 | |
| 251 | /* |
drh | 49766d6 | 2005-01-08 18:42:28 +0000 | [diff] [blame] | 252 | ** Provide a default value for TEMP_STORE in case it is not specified |
| 253 | ** on the command-line |
| 254 | */ |
| 255 | #ifndef TEMP_STORE |
| 256 | # define TEMP_STORE 1 |
| 257 | #endif |
| 258 | |
| 259 | /* |
drh | f197484 | 2004-11-05 03:56:00 +0000 | [diff] [blame] | 260 | ** GCC does not define the offsetof() macro so we'll have to do it |
| 261 | ** ourselves. |
| 262 | */ |
| 263 | #ifndef offsetof |
| 264 | #define offsetof(STRUCTURE,FIELD) ((int)((char*)&((STRUCTURE*)0)->FIELD)) |
| 265 | #endif |
| 266 | |
| 267 | /* |
drh | 9b8f447 | 2006-04-04 01:54:55 +0000 | [diff] [blame] | 268 | ** Check to see if this machine uses EBCDIC. (Yes, believe it or |
| 269 | ** not, there are still machines out there that use EBCDIC.) |
| 270 | */ |
| 271 | #if 'A' == '\301' |
| 272 | # define SQLITE_EBCDIC 1 |
| 273 | #else |
| 274 | # define SQLITE_ASCII 1 |
| 275 | #endif |
| 276 | |
| 277 | /* |
drh | 5a2c2c2 | 2001-11-21 02:21:11 +0000 | [diff] [blame] | 278 | ** Integers of known sizes. These typedefs might change for architectures |
| 279 | ** where the sizes very. Preprocessor macros are available so that the |
| 280 | ** types can be conveniently redefined at compile-type. Like this: |
| 281 | ** |
| 282 | ** cc '-DUINTPTR_TYPE=long long int' ... |
drh | 41a2b48 | 2001-01-20 19:52:49 +0000 | [diff] [blame] | 283 | */ |
drh | 5a2c2c2 | 2001-11-21 02:21:11 +0000 | [diff] [blame] | 284 | #ifndef UINT32_TYPE |
mlcreech | dda5b68 | 2008-03-14 13:02:08 +0000 | [diff] [blame] | 285 | # ifdef HAVE_UINT32_T |
| 286 | # define UINT32_TYPE uint32_t |
| 287 | # else |
| 288 | # define UINT32_TYPE unsigned int |
| 289 | # endif |
drh | 5a2c2c2 | 2001-11-21 02:21:11 +0000 | [diff] [blame] | 290 | #endif |
| 291 | #ifndef UINT16_TYPE |
mlcreech | dda5b68 | 2008-03-14 13:02:08 +0000 | [diff] [blame] | 292 | # ifdef HAVE_UINT16_T |
| 293 | # define UINT16_TYPE uint16_t |
| 294 | # else |
| 295 | # define UINT16_TYPE unsigned short int |
| 296 | # endif |
drh | 5a2c2c2 | 2001-11-21 02:21:11 +0000 | [diff] [blame] | 297 | #endif |
drh | 939a16d | 2004-07-15 13:37:22 +0000 | [diff] [blame] | 298 | #ifndef INT16_TYPE |
mlcreech | dda5b68 | 2008-03-14 13:02:08 +0000 | [diff] [blame] | 299 | # ifdef HAVE_INT16_T |
| 300 | # define INT16_TYPE int16_t |
| 301 | # else |
| 302 | # define INT16_TYPE short int |
| 303 | # endif |
drh | 939a16d | 2004-07-15 13:37:22 +0000 | [diff] [blame] | 304 | #endif |
drh | 5a2c2c2 | 2001-11-21 02:21:11 +0000 | [diff] [blame] | 305 | #ifndef UINT8_TYPE |
mlcreech | dda5b68 | 2008-03-14 13:02:08 +0000 | [diff] [blame] | 306 | # ifdef HAVE_UINT8_T |
| 307 | # define UINT8_TYPE uint8_t |
| 308 | # else |
| 309 | # define UINT8_TYPE unsigned char |
| 310 | # endif |
drh | 5a2c2c2 | 2001-11-21 02:21:11 +0000 | [diff] [blame] | 311 | #endif |
drh | 905793e | 2004-02-21 13:31:09 +0000 | [diff] [blame] | 312 | #ifndef INT8_TYPE |
mlcreech | dda5b68 | 2008-03-14 13:02:08 +0000 | [diff] [blame] | 313 | # ifdef HAVE_INT8_T |
| 314 | # define INT8_TYPE int8_t |
| 315 | # else |
| 316 | # define INT8_TYPE signed char |
| 317 | # endif |
drh | 905793e | 2004-02-21 13:31:09 +0000 | [diff] [blame] | 318 | #endif |
drh | efad999 | 2004-06-22 12:13:55 +0000 | [diff] [blame] | 319 | #ifndef LONGDOUBLE_TYPE |
| 320 | # define LONGDOUBLE_TYPE long double |
| 321 | #endif |
drh | efad999 | 2004-06-22 12:13:55 +0000 | [diff] [blame] | 322 | typedef sqlite_int64 i64; /* 8-byte signed integer */ |
drh | 27436af | 2006-03-28 23:57:17 +0000 | [diff] [blame] | 323 | typedef sqlite_uint64 u64; /* 8-byte unsigned integer */ |
drh | 5a2c2c2 | 2001-11-21 02:21:11 +0000 | [diff] [blame] | 324 | typedef UINT32_TYPE u32; /* 4-byte unsigned integer */ |
| 325 | typedef UINT16_TYPE u16; /* 2-byte unsigned integer */ |
drh | 939a16d | 2004-07-15 13:37:22 +0000 | [diff] [blame] | 326 | typedef INT16_TYPE i16; /* 2-byte signed integer */ |
drh | 5a2c2c2 | 2001-11-21 02:21:11 +0000 | [diff] [blame] | 327 | typedef UINT8_TYPE u8; /* 1-byte unsigned integer */ |
drh | 905793e | 2004-02-21 13:31:09 +0000 | [diff] [blame] | 328 | typedef UINT8_TYPE i8; /* 1-byte signed integer */ |
drh | 5a2c2c2 | 2001-11-21 02:21:11 +0000 | [diff] [blame] | 329 | |
| 330 | /* |
drh | bbd42a6 | 2004-05-22 17:41:58 +0000 | [diff] [blame] | 331 | ** Macros to determine whether the machine is big or little endian, |
| 332 | ** evaluated at runtime. |
| 333 | */ |
drh | 46c99e0 | 2007-08-27 23:26:59 +0000 | [diff] [blame] | 334 | #ifdef SQLITE_AMALGAMATION |
mlcreech | 7ff4a45 | 2008-03-06 09:19:00 +0000 | [diff] [blame] | 335 | const int sqlite3one; |
drh | 46c99e0 | 2007-08-27 23:26:59 +0000 | [diff] [blame] | 336 | #else |
drh | bbd42a6 | 2004-05-22 17:41:58 +0000 | [diff] [blame] | 337 | extern const int sqlite3one; |
drh | 46c99e0 | 2007-08-27 23:26:59 +0000 | [diff] [blame] | 338 | #endif |
drh | 38def05 | 2007-03-31 15:27:59 +0000 | [diff] [blame] | 339 | #if defined(i386) || defined(__i386__) || defined(_M_IX86) |
| 340 | # define SQLITE_BIGENDIAN 0 |
| 341 | # define SQLITE_LITTLEENDIAN 1 |
| 342 | # define SQLITE_UTF16NATIVE SQLITE_UTF16LE |
| 343 | #else |
| 344 | # define SQLITE_BIGENDIAN (*(char *)(&sqlite3one)==0) |
| 345 | # define SQLITE_LITTLEENDIAN (*(char *)(&sqlite3one)==1) |
| 346 | # define SQLITE_UTF16NATIVE (SQLITE_BIGENDIAN?SQLITE_UTF16BE:SQLITE_UTF16LE) |
| 347 | #endif |
drh | bbd42a6 | 2004-05-22 17:41:58 +0000 | [diff] [blame] | 348 | |
| 349 | /* |
drh | 0f05035 | 2008-05-09 18:03:13 +0000 | [diff] [blame] | 350 | ** Constants for the largest and smallest possible 64-bit signed integers. |
| 351 | ** These macros are designed to work correctly on both 32-bit and 64-bit |
| 352 | ** compilers. |
| 353 | */ |
| 354 | #define LARGEST_INT64 (0xffffffff|(((i64)0x7fffffff)<<32)) |
| 355 | #define SMALLEST_INT64 (((i64)-1) - LARGEST_INT64) |
| 356 | |
| 357 | /* |
drh | 90f5ecb | 2004-07-22 01:19:35 +0000 | [diff] [blame] | 358 | ** An instance of the following structure is used to store the busy-handler |
| 359 | ** callback for a given sqlite handle. |
| 360 | ** |
| 361 | ** The sqlite.busyHandler member of the sqlite struct contains the busy |
| 362 | ** callback for the database handle. Each pager opened via the sqlite |
| 363 | ** handle is passed a pointer to sqlite.busyHandler. The busy-handler |
| 364 | ** callback is currently invoked only from within pager.c. |
| 365 | */ |
| 366 | typedef struct BusyHandler BusyHandler; |
| 367 | struct BusyHandler { |
| 368 | int (*xFunc)(void *,int); /* The busy callback */ |
| 369 | void *pArg; /* First arg to busy callback */ |
drh | a4afb65 | 2005-07-09 02:16:02 +0000 | [diff] [blame] | 370 | int nBusy; /* Incremented with each busy call */ |
drh | 90f5ecb | 2004-07-22 01:19:35 +0000 | [diff] [blame] | 371 | }; |
| 372 | |
| 373 | /* |
drh | 7589723 | 2000-05-29 14:26:00 +0000 | [diff] [blame] | 374 | ** Name of the master database table. The master database table |
| 375 | ** is a special table that holds the names and attributes of all |
| 376 | ** user tables and indices. |
| 377 | */ |
drh | e0bc404 | 2002-06-25 01:09:11 +0000 | [diff] [blame] | 378 | #define MASTER_NAME "sqlite_master" |
| 379 | #define TEMP_MASTER_NAME "sqlite_temp_master" |
drh | 7589723 | 2000-05-29 14:26:00 +0000 | [diff] [blame] | 380 | |
| 381 | /* |
danielk1977 | 8e15081 | 2004-05-10 01:17:37 +0000 | [diff] [blame] | 382 | ** The root-page of the master database table. |
| 383 | */ |
| 384 | #define MASTER_ROOT 1 |
| 385 | |
| 386 | /* |
drh | ed6c867 | 2003-01-12 18:02:16 +0000 | [diff] [blame] | 387 | ** The name of the schema table. |
| 388 | */ |
danielk1977 | 53c0f74 | 2005-03-29 03:10:59 +0000 | [diff] [blame] | 389 | #define SCHEMA_TABLE(x) ((!OMIT_TEMPDB)&&(x==1)?TEMP_MASTER_NAME:MASTER_NAME) |
drh | ed6c867 | 2003-01-12 18:02:16 +0000 | [diff] [blame] | 390 | |
| 391 | /* |
drh | 7589723 | 2000-05-29 14:26:00 +0000 | [diff] [blame] | 392 | ** A convenience macro that returns the number of elements in |
| 393 | ** an array. |
| 394 | */ |
| 395 | #define ArraySize(X) (sizeof(X)/sizeof(X[0])) |
| 396 | |
| 397 | /* |
| 398 | ** Forward references to structures |
| 399 | */ |
drh | 1344989 | 2005-09-07 21:22:45 +0000 | [diff] [blame] | 400 | typedef struct AggInfo AggInfo; |
drh | fe05af8 | 2005-07-21 03:14:59 +0000 | [diff] [blame] | 401 | typedef struct AuthContext AuthContext; |
drh | f5e7bb5 | 2008-02-18 14:47:33 +0000 | [diff] [blame] | 402 | typedef struct Bitvec Bitvec; |
drh | fe05af8 | 2005-07-21 03:14:59 +0000 | [diff] [blame] | 403 | typedef struct CollSeq CollSeq; |
drh | 7020f65 | 2000-06-03 18:06:52 +0000 | [diff] [blame] | 404 | typedef struct Column Column; |
drh | fe05af8 | 2005-07-21 03:14:59 +0000 | [diff] [blame] | 405 | typedef struct Db Db; |
danielk1977 | e501b89 | 2006-01-09 06:29:47 +0000 | [diff] [blame] | 406 | typedef struct Schema Schema; |
drh | 7589723 | 2000-05-29 14:26:00 +0000 | [diff] [blame] | 407 | typedef struct Expr Expr; |
| 408 | typedef struct ExprList ExprList; |
drh | c2eef3b | 2002-08-31 18:53:06 +0000 | [diff] [blame] | 409 | typedef struct FKey FKey; |
drh | fe05af8 | 2005-07-21 03:14:59 +0000 | [diff] [blame] | 410 | typedef struct FuncDef FuncDef; |
| 411 | typedef struct IdList IdList; |
| 412 | typedef struct Index Index; |
danielk1977 | 8d05984 | 2004-05-12 11:24:02 +0000 | [diff] [blame] | 413 | typedef struct KeyClass KeyClass; |
drh | d3d39e9 | 2004-05-20 22:16:29 +0000 | [diff] [blame] | 414 | typedef struct KeyInfo KeyInfo; |
danielk1977 | d1ab1ba | 2006-06-15 04:28:13 +0000 | [diff] [blame] | 415 | typedef struct Module Module; |
drh | 626a879 | 2005-01-17 22:08:19 +0000 | [diff] [blame] | 416 | typedef struct NameContext NameContext; |
drh | fe05af8 | 2005-07-21 03:14:59 +0000 | [diff] [blame] | 417 | typedef struct Parse Parse; |
| 418 | typedef struct Select Select; |
| 419 | typedef struct SrcList SrcList; |
drh | ade8648 | 2007-11-28 22:36:40 +0000 | [diff] [blame] | 420 | typedef struct StrAccum StrAccum; |
drh | fe05af8 | 2005-07-21 03:14:59 +0000 | [diff] [blame] | 421 | typedef struct Table Table; |
danielk1977 | c00da10 | 2006-01-07 13:21:04 +0000 | [diff] [blame] | 422 | typedef struct TableLock TableLock; |
drh | fe05af8 | 2005-07-21 03:14:59 +0000 | [diff] [blame] | 423 | typedef struct Token Token; |
| 424 | typedef struct TriggerStack TriggerStack; |
| 425 | typedef struct TriggerStep TriggerStep; |
| 426 | typedef struct Trigger Trigger; |
drh | fe05af8 | 2005-07-21 03:14:59 +0000 | [diff] [blame] | 427 | typedef struct WhereInfo WhereInfo; |
| 428 | typedef struct WhereLevel WhereLevel; |
drh | d3d39e9 | 2004-05-20 22:16:29 +0000 | [diff] [blame] | 429 | |
danielk1977 | 2dca4ac | 2008-01-03 11:50:29 +0000 | [diff] [blame] | 430 | /* |
| 431 | ** Defer sourcing vdbe.h and btree.h until after the "u8" and |
| 432 | ** "BusyHandler" typedefs. vdbe.h also requires a few of the opaque |
| 433 | ** pointer types (i.e. FuncDef) defined above. |
| 434 | */ |
| 435 | #include "btree.h" |
| 436 | #include "vdbe.h" |
| 437 | #include "pager.h" |
| 438 | |
danielk1977 | 1cc5ed8 | 2007-05-16 17:28:43 +0000 | [diff] [blame] | 439 | #include "os.h" |
drh | c7ce76a | 2007-08-30 14:10:30 +0000 | [diff] [blame] | 440 | #include "mutex.h" |
danielk1977 | 1cc5ed8 | 2007-05-16 17:28:43 +0000 | [diff] [blame] | 441 | |
drh | eee4c8c | 2008-02-18 22:24:57 +0000 | [diff] [blame] | 442 | |
drh | 001bbcb | 2003-03-19 03:14:00 +0000 | [diff] [blame] | 443 | /* |
| 444 | ** Each database file to be accessed by the system is an instance |
| 445 | ** of the following structure. There are normally two of these structures |
| 446 | ** in the sqlite.aDb[] array. aDb[0] is the main database file and |
drh | a69d916 | 2003-04-17 22:57:53 +0000 | [diff] [blame] | 447 | ** aDb[1] is the database file used to hold temporary tables. Additional |
| 448 | ** databases may be attached. |
drh | 001bbcb | 2003-03-19 03:14:00 +0000 | [diff] [blame] | 449 | */ |
| 450 | struct Db { |
| 451 | char *zName; /* Name of this database */ |
| 452 | Btree *pBt; /* The B*Tree structure for this database file */ |
danielk1977 | da18423 | 2006-01-05 11:34:32 +0000 | [diff] [blame] | 453 | u8 inTrans; /* 0: not writable. 1: Transaction. 2: Checkpoint */ |
| 454 | u8 safety_level; /* How aggressive at synching data to disk */ |
danielk1977 | da18423 | 2006-01-05 11:34:32 +0000 | [diff] [blame] | 455 | void *pAux; /* Auxiliary data. Usually NULL */ |
| 456 | void (*xFreeAux)(void*); /* Routine to free pAux */ |
danielk1977 | e501b89 | 2006-01-09 06:29:47 +0000 | [diff] [blame] | 457 | Schema *pSchema; /* Pointer to database schema (possibly shared) */ |
danielk1977 | da18423 | 2006-01-05 11:34:32 +0000 | [diff] [blame] | 458 | }; |
| 459 | |
| 460 | /* |
| 461 | ** An instance of the following structure stores a database schema. |
danielk1977 | a04a34f | 2007-04-16 15:06:25 +0000 | [diff] [blame] | 462 | ** |
| 463 | ** If there are no virtual tables configured in this schema, the |
| 464 | ** Schema.db variable is set to NULL. After the first virtual table |
| 465 | ** has been added, it is set to point to the database connection |
| 466 | ** used to create the connection. Once a virtual table has been |
| 467 | ** added to the Schema structure and the Schema.db variable populated, |
| 468 | ** only that database connection may use the Schema to prepare |
| 469 | ** statements. |
danielk1977 | da18423 | 2006-01-05 11:34:32 +0000 | [diff] [blame] | 470 | */ |
danielk1977 | e501b89 | 2006-01-09 06:29:47 +0000 | [diff] [blame] | 471 | struct Schema { |
drh | 001bbcb | 2003-03-19 03:14:00 +0000 | [diff] [blame] | 472 | int schema_cookie; /* Database schema version number for this file */ |
drh | d24cc42 | 2003-03-27 12:51:24 +0000 | [diff] [blame] | 473 | Hash tblHash; /* All tables indexed by name */ |
| 474 | Hash idxHash; /* All (named) indices indexed by name */ |
| 475 | Hash trigHash; /* All triggers indexed by name */ |
| 476 | Hash aFKey; /* Foreign keys indexed by to-table */ |
drh | 4794f73 | 2004-11-05 17:17:50 +0000 | [diff] [blame] | 477 | Table *pSeqTab; /* The sqlite_sequence table used by AUTOINCREMENT */ |
danielk1977 | da18423 | 2006-01-05 11:34:32 +0000 | [diff] [blame] | 478 | u8 file_format; /* Schema format version for this file */ |
drh | 8079a0d | 2006-01-12 17:20:50 +0000 | [diff] [blame] | 479 | u8 enc; /* Text encoding used by this database */ |
danielk1977 | da18423 | 2006-01-05 11:34:32 +0000 | [diff] [blame] | 480 | u16 flags; /* Flags associated with this schema */ |
danielk1977 | 14db266 | 2006-01-09 16:12:04 +0000 | [diff] [blame] | 481 | int cache_size; /* Number of pages to use in the cache */ |
danielk1977 | a04a34f | 2007-04-16 15:06:25 +0000 | [diff] [blame] | 482 | #ifndef SQLITE_OMIT_VIRTUALTABLE |
| 483 | sqlite3 *db; /* "Owner" connection. See comment above */ |
| 484 | #endif |
drh | 001bbcb | 2003-03-19 03:14:00 +0000 | [diff] [blame] | 485 | }; |
drh | 7589723 | 2000-05-29 14:26:00 +0000 | [diff] [blame] | 486 | |
| 487 | /* |
drh | 8bf8dc9 | 2003-05-17 17:35:10 +0000 | [diff] [blame] | 488 | ** These macros can be used to test, set, or clear bits in the |
| 489 | ** Db.flags field. |
| 490 | */ |
danielk1977 | da18423 | 2006-01-05 11:34:32 +0000 | [diff] [blame] | 491 | #define DbHasProperty(D,I,P) (((D)->aDb[I].pSchema->flags&(P))==(P)) |
| 492 | #define DbHasAnyProperty(D,I,P) (((D)->aDb[I].pSchema->flags&(P))!=0) |
| 493 | #define DbSetProperty(D,I,P) (D)->aDb[I].pSchema->flags|=(P) |
| 494 | #define DbClearProperty(D,I,P) (D)->aDb[I].pSchema->flags&=~(P) |
drh | 8bf8dc9 | 2003-05-17 17:35:10 +0000 | [diff] [blame] | 495 | |
| 496 | /* |
| 497 | ** Allowed values for the DB.flags field. |
| 498 | ** |
drh | 8bf8dc9 | 2003-05-17 17:35:10 +0000 | [diff] [blame] | 499 | ** The DB_SchemaLoaded flag is set after the database schema has been |
| 500 | ** read into internal hash tables. |
| 501 | ** |
| 502 | ** DB_UnresetViews means that one or more views have column names that |
| 503 | ** have been filled out. If the schema changes, these column names might |
| 504 | ** changes and so the view will need to be reset. |
| 505 | */ |
drh | 124b27e | 2004-06-19 16:06:10 +0000 | [diff] [blame] | 506 | #define DB_SchemaLoaded 0x0001 /* The schema has been loaded */ |
| 507 | #define DB_UnresetViews 0x0002 /* Some views have defined column names */ |
danielk1977 | b82e7ed | 2006-01-11 14:09:31 +0000 | [diff] [blame] | 508 | #define DB_Empty 0x0004 /* The file is empty (length 0 bytes) */ |
drh | 8bf8dc9 | 2003-05-17 17:35:10 +0000 | [diff] [blame] | 509 | |
drh | caa639f | 2008-03-20 00:32:20 +0000 | [diff] [blame] | 510 | /* |
| 511 | ** The number of different kinds of things that can be limited |
| 512 | ** using the sqlite3_limit() interface. |
| 513 | */ |
| 514 | #define SQLITE_N_LIMIT (SQLITE_LIMIT_VARIABLE_NUMBER+1) |
drh | 8bf8dc9 | 2003-05-17 17:35:10 +0000 | [diff] [blame] | 515 | |
| 516 | /* |
drh | c9b84a1 | 2002-06-20 11:36:48 +0000 | [diff] [blame] | 517 | ** Each database is an instance of the following structure. |
| 518 | ** |
rdc | b0c374f | 2004-02-20 22:53:38 +0000 | [diff] [blame] | 519 | ** The sqlite.lastRowid records the last insert rowid generated by an |
| 520 | ** insert statement. Inserts on views do not affect its value. Each |
| 521 | ** trigger has its own context, so that lastRowid can be updated inside |
| 522 | ** triggers as usual. The previous value will be restored once the trigger |
| 523 | ** exits. Upon entering a before or instead of trigger, lastRowid is no |
| 524 | ** longer (since after version 2.8.12) reset to -1. |
| 525 | ** |
| 526 | ** The sqlite.nChange does not count changes within triggers and keeps no |
danielk1977 | 6f8a503 | 2004-05-10 10:34:51 +0000 | [diff] [blame] | 527 | ** context. It is reset at start of sqlite3_exec. |
rdc | b0c374f | 2004-02-20 22:53:38 +0000 | [diff] [blame] | 528 | ** The sqlite.lsChange represents the number of changes made by the last |
| 529 | ** insert, update, or delete statement. It remains constant throughout the |
| 530 | ** length of a statement and is then updated by OP_SetCounts. It keeps a |
| 531 | ** context stack just like lastRowid so that the count of changes |
| 532 | ** within a trigger is not seen outside the trigger. Changes to views do not |
| 533 | ** affect the value of lsChange. |
| 534 | ** The sqlite.csChange keeps track of the number of current changes (since |
| 535 | ** the last statement) and is used to update sqlite_lsChange. |
danielk1977 | 6622cce | 2004-05-20 11:00:52 +0000 | [diff] [blame] | 536 | ** |
| 537 | ** The member variables sqlite.errCode, sqlite.zErrMsg and sqlite.zErrMsg16 |
| 538 | ** store the most recent error code and, if applicable, string. The |
| 539 | ** internal function sqlite3Error() is used to set these variables |
| 540 | ** consistently. |
drh | 7589723 | 2000-05-29 14:26:00 +0000 | [diff] [blame] | 541 | */ |
drh | 9bb575f | 2004-09-06 17:24:11 +0000 | [diff] [blame] | 542 | struct sqlite3 { |
drh | 90f6a5b | 2007-08-15 13:04:54 +0000 | [diff] [blame] | 543 | sqlite3_vfs *pVfs; /* OS Interface */ |
drh | 001bbcb | 2003-03-19 03:14:00 +0000 | [diff] [blame] | 544 | int nDb; /* Number of backends currently in use */ |
| 545 | Db *aDb; /* All backends */ |
drh | 5e00f6c | 2001-09-13 13:46:56 +0000 | [diff] [blame] | 546 | int flags; /* Miscellanous flags. See below */ |
drh | 33f4e02 | 2007-09-03 15:19:34 +0000 | [diff] [blame] | 547 | int openFlags; /* Flags passed to sqlite3_vfs.xOpen() */ |
drh | fcd35c7 | 2005-05-21 02:48:08 +0000 | [diff] [blame] | 548 | int errCode; /* Most recent error code (SQLITE_*) */ |
drh | 4ac285a | 2006-09-15 07:28:50 +0000 | [diff] [blame] | 549 | int errMask; /* & result codes with this before returning */ |
drh | fcd35c7 | 2005-05-21 02:48:08 +0000 | [diff] [blame] | 550 | u8 autoCommit; /* The auto-commit flag. */ |
drh | 90f5ecb | 2004-07-22 01:19:35 +0000 | [diff] [blame] | 551 | u8 temp_store; /* 1: file 2: memory 0: default */ |
drh | 1743575 | 2007-08-16 04:30:38 +0000 | [diff] [blame] | 552 | u8 mallocFailed; /* True if we have seen a malloc failure */ |
drh | 3b02013 | 2008-04-17 17:02:01 +0000 | [diff] [blame] | 553 | u8 dfltLockMode; /* Default locking-mode for attached dbs */ |
| 554 | u8 dfltJournalMode; /* Default journal mode for attached dbs */ |
drh | 9875715 | 2008-01-09 23:04:12 +0000 | [diff] [blame] | 555 | signed char nextAutovac; /* Autovac setting after VACUUM if >=0 */ |
danielk1977 | f653d78 | 2008-03-20 11:04:21 +0000 | [diff] [blame] | 556 | int nextPagesize; /* Pagesize after VACUUM if >0 */ |
drh | 5e00f6c | 2001-09-13 13:46:56 +0000 | [diff] [blame] | 557 | int nTable; /* Number of tables in the database */ |
drh | d3d39e9 | 2004-05-20 22:16:29 +0000 | [diff] [blame] | 558 | CollSeq *pDfltColl; /* The default collating sequence (BINARY) */ |
drh | f328bc8 | 2004-05-10 23:29:49 +0000 | [diff] [blame] | 559 | i64 lastRowid; /* ROWID of most recent insert (see above) */ |
| 560 | i64 priorNewRowid; /* Last randomly generated ROWID */ |
drh | 247be43 | 2002-05-10 05:44:55 +0000 | [diff] [blame] | 561 | int magic; /* Magic number for detect library misuse */ |
danielk1977 | b28af71 | 2004-06-21 06:50:26 +0000 | [diff] [blame] | 562 | int nChange; /* Value returned by sqlite3_changes() */ |
| 563 | int nTotalChange; /* Value returned by sqlite3_total_changes() */ |
drh | d677b3d | 2007-08-20 22:48:41 +0000 | [diff] [blame] | 564 | sqlite3_mutex *mutex; /* Connection mutex */ |
drh | caa639f | 2008-03-20 00:32:20 +0000 | [diff] [blame] | 565 | int aLimit[SQLITE_N_LIMIT]; /* Limits */ |
danielk1977 | b28af71 | 2004-06-21 06:50:26 +0000 | [diff] [blame] | 566 | struct sqlite3InitInfo { /* Information used during initialization */ |
| 567 | int iDb; /* When back is being initialized */ |
| 568 | int newTnum; /* Rootpage of table being initialized */ |
| 569 | u8 busy; /* TRUE if currently initializing */ |
drh | 1d85d93 | 2004-02-14 23:05:52 +0000 | [diff] [blame] | 570 | } init; |
drh | f1952c5 | 2006-06-08 15:48:00 +0000 | [diff] [blame] | 571 | int nExtension; /* Number of loaded extensions */ |
drh | 761df87 | 2006-12-21 01:29:22 +0000 | [diff] [blame] | 572 | void **aExtension; /* Array of shared libraray handles */ |
drh | 326dce7 | 2003-01-29 14:06:07 +0000 | [diff] [blame] | 573 | struct Vdbe *pVdbe; /* List of active virtual machines */ |
danielk1977 | 1d850a7 | 2004-05-31 08:26:49 +0000 | [diff] [blame] | 574 | int activeVdbeCnt; /* Number of vdbes currently executing */ |
drh | 19e2d37 | 2005-08-29 23:00:03 +0000 | [diff] [blame] | 575 | void (*xTrace)(void*,const char*); /* Trace function */ |
| 576 | void *pTraceArg; /* Argument to the trace function */ |
| 577 | void (*xProfile)(void*,const char*,u64); /* Profiling function */ |
| 578 | void *pProfileArg; /* Argument to profile function */ |
danielk1977 | 71fd80b | 2005-12-16 06:54:01 +0000 | [diff] [blame] | 579 | void *pCommitArg; /* Argument to xCommitCallback() */ |
| 580 | int (*xCommitCallback)(void*); /* Invoked at every commit. */ |
| 581 | void *pRollbackArg; /* Argument to xRollbackCallback() */ |
| 582 | void (*xRollbackCallback)(void*); /* Invoked at every commit. */ |
danielk1977 | 94eb6a1 | 2005-12-15 15:22:08 +0000 | [diff] [blame] | 583 | void *pUpdateArg; |
| 584 | void (*xUpdateCallback)(void*,int, const char*,const char*,sqlite_int64); |
drh | fcd35c7 | 2005-05-21 02:48:08 +0000 | [diff] [blame] | 585 | void(*xCollNeeded)(void*,sqlite3*,int eTextRep,const char*); |
| 586 | void(*xCollNeeded16)(void*,sqlite3*,int eTextRep,const void*); |
| 587 | void *pCollNeededArg; |
drh | fcd35c7 | 2005-05-21 02:48:08 +0000 | [diff] [blame] | 588 | sqlite3_value *pErr; /* Most recent error message */ |
| 589 | char *zErrMsg; /* Most recent error message (UTF-8 encoded) */ |
| 590 | char *zErrMsg16; /* Most recent error message (UTF-16 encoded) */ |
drh | 881feaa | 2006-07-26 01:39:30 +0000 | [diff] [blame] | 591 | union { |
| 592 | int isInterrupted; /* True if sqlite3_interrupt has been called */ |
| 593 | double notUsed1; /* Spacer */ |
| 594 | } u1; |
drh | ed6c867 | 2003-01-12 18:02:16 +0000 | [diff] [blame] | 595 | #ifndef SQLITE_OMIT_AUTHORIZATION |
drh | e22a334 | 2003-04-22 20:30:37 +0000 | [diff] [blame] | 596 | int (*xAuth)(void*,int,const char*,const char*,const char*,const char*); |
| 597 | /* Access authorization function */ |
drh | ed6c867 | 2003-01-12 18:02:16 +0000 | [diff] [blame] | 598 | void *pAuthArg; /* 1st argument to the access auth function */ |
| 599 | #endif |
danielk1977 | 348bb5d | 2003-10-18 09:37:26 +0000 | [diff] [blame] | 600 | #ifndef SQLITE_OMIT_PROGRESS_CALLBACK |
| 601 | int (*xProgress)(void *); /* The progress callback */ |
| 602 | void *pProgressArg; /* Argument to the progress callback */ |
| 603 | int nProgressOps; /* Number of opcodes for progress callback */ |
| 604 | #endif |
drh | b9bb7c1 | 2006-06-11 23:41:55 +0000 | [diff] [blame] | 605 | #ifndef SQLITE_OMIT_VIRTUALTABLE |
| 606 | Hash aModule; /* populated by sqlite3_create_module() */ |
danielk1977 | 7e6ebfb | 2006-06-12 11:24:37 +0000 | [diff] [blame] | 607 | Table *pVTab; /* vtab with active Connect/Create method */ |
danielk1977 | f9e7dda | 2006-06-16 16:08:53 +0000 | [diff] [blame] | 608 | sqlite3_vtab **aVTrans; /* Virtual tables with open transactions */ |
| 609 | int nVTrans; /* Allocated size of aVTrans */ |
danielk1977 | 6b456a2 | 2005-03-21 04:04:02 +0000 | [diff] [blame] | 610 | #endif |
drh | fcd35c7 | 2005-05-21 02:48:08 +0000 | [diff] [blame] | 611 | Hash aFunc; /* All functions that can be in SQL exprs */ |
| 612 | Hash aCollSeq; /* All collating sequences */ |
| 613 | BusyHandler busyHandler; /* Busy callback */ |
drh | b9bb7c1 | 2006-06-11 23:41:55 +0000 | [diff] [blame] | 614 | int busyTimeout; /* Busy handler timeout, in msec */ |
drh | fcd35c7 | 2005-05-21 02:48:08 +0000 | [diff] [blame] | 615 | Db aDbStatic[2]; /* Static space for the 2 default backends */ |
danielk1977 | 7e900ab | 2005-05-23 04:51:01 +0000 | [diff] [blame] | 616 | #ifdef SQLITE_SSE |
| 617 | sqlite3_stmt *pFetch; /* Used by SSE to fetch stored statements */ |
| 618 | #endif |
drh | 7589723 | 2000-05-29 14:26:00 +0000 | [diff] [blame] | 619 | }; |
| 620 | |
drh | 03b808a | 2006-03-13 15:06:05 +0000 | [diff] [blame] | 621 | /* |
| 622 | ** A macro to discover the encoding of a database. |
| 623 | */ |
danielk1977 | 14db266 | 2006-01-09 16:12:04 +0000 | [diff] [blame] | 624 | #define ENC(db) ((db)->aDb[0].pSchema->enc) |
| 625 | |
drh | 7589723 | 2000-05-29 14:26:00 +0000 | [diff] [blame] | 626 | /* |
drh | 8bf8dc9 | 2003-05-17 17:35:10 +0000 | [diff] [blame] | 627 | ** Possible values for the sqlite.flags and or Db.flags fields. |
| 628 | ** |
| 629 | ** On sqlite.flags, the SQLITE_InTrans value means that we have |
| 630 | ** executed a BEGIN. On Db.flags, SQLITE_InTrans means a statement |
| 631 | ** transaction is active on that particular database file. |
drh | 7589723 | 2000-05-29 14:26:00 +0000 | [diff] [blame] | 632 | */ |
drh | 5e00f6c | 2001-09-13 13:46:56 +0000 | [diff] [blame] | 633 | #define SQLITE_VdbeTrace 0x00000001 /* True to trace VDBE execution */ |
drh | 5e00f6c | 2001-09-13 13:46:56 +0000 | [diff] [blame] | 634 | #define SQLITE_InTrans 0x00000008 /* True if in a transaction */ |
| 635 | #define SQLITE_InternChanges 0x00000010 /* Uncommitted Hash table changes */ |
drh | 382c024 | 2001-10-06 16:33:02 +0000 | [diff] [blame] | 636 | #define SQLITE_FullColNames 0x00000020 /* Show full column names on SELECT */ |
drh | fcabd46 | 2004-02-20 14:50:58 +0000 | [diff] [blame] | 637 | #define SQLITE_ShortColNames 0x00000040 /* Show short columns names */ |
| 638 | #define SQLITE_CountRows 0x00000080 /* Count rows changed by INSERT, */ |
drh | 1bee3d7 | 2001-10-15 00:44:35 +0000 | [diff] [blame] | 639 | /* DELETE, or UPDATE and return */ |
| 640 | /* the count using a callback. */ |
drh | fcabd46 | 2004-02-20 14:50:58 +0000 | [diff] [blame] | 641 | #define SQLITE_NullCallback 0x00000100 /* Invoke the callback once if the */ |
drh | 6a53534 | 2001-10-19 16:44:56 +0000 | [diff] [blame] | 642 | /* result set is empty */ |
drh | 35d4c2f | 2004-06-10 01:30:59 +0000 | [diff] [blame] | 643 | #define SQLITE_SqlTrace 0x00000200 /* Debug print SQL as it executes */ |
| 644 | #define SQLITE_VdbeListing 0x00000400 /* Debug listings of VDBE programs */ |
drh | f404083 | 2004-10-22 20:29:21 +0000 | [diff] [blame] | 645 | #define SQLITE_WriteSchema 0x00000800 /* OK to update SQLITE_MASTER */ |
drh | 7bec505 | 2005-02-06 02:45:41 +0000 | [diff] [blame] | 646 | #define SQLITE_NoReadlock 0x00001000 /* Readlocks are omitted when |
| 647 | ** accessing read-only databases */ |
drh | 0cd2d4c | 2005-11-03 02:15:02 +0000 | [diff] [blame] | 648 | #define SQLITE_IgnoreChecks 0x00002000 /* Do not enforce check constraints */ |
drh | c2e87a3 | 2006-06-27 15:16:14 +0000 | [diff] [blame] | 649 | #define SQLITE_ReadUncommitted 0x00004000 /* For shared-cache mode */ |
drh | e321c29 | 2006-01-12 01:56:43 +0000 | [diff] [blame] | 650 | #define SQLITE_LegacyFileFmt 0x00008000 /* Create new databases in format 1 */ |
drh | ac530b1 | 2006-02-11 01:25:50 +0000 | [diff] [blame] | 651 | #define SQLITE_FullFSync 0x00010000 /* Use full fsync on the backend */ |
drh | c2e87a3 | 2006-06-27 15:16:14 +0000 | [diff] [blame] | 652 | #define SQLITE_LoadExtension 0x00020000 /* Enable load_extension */ |
drh | 58b9576 | 2000-06-02 01:17:37 +0000 | [diff] [blame] | 653 | |
danielk1977 | 34c68fb | 2007-03-14 15:37:04 +0000 | [diff] [blame] | 654 | #define SQLITE_RecoveryMode 0x00040000 /* Ignore schema errors */ |
drh | 4a50aac | 2007-08-23 02:47:53 +0000 | [diff] [blame] | 655 | #define SQLITE_SharedCache 0x00080000 /* Cache sharing is enabled */ |
| 656 | #define SQLITE_Vtab 0x00100000 /* There exists a virtual table */ |
danielk1977 | 34c68fb | 2007-03-14 15:37:04 +0000 | [diff] [blame] | 657 | |
drh | 58b9576 | 2000-06-02 01:17:37 +0000 | [diff] [blame] | 658 | /* |
drh | 247be43 | 2002-05-10 05:44:55 +0000 | [diff] [blame] | 659 | ** Possible values for the sqlite.magic field. |
| 660 | ** The numbers are obtained at random and have no special meaning, other |
| 661 | ** than being distinct from one another. |
| 662 | */ |
| 663 | #define SQLITE_MAGIC_OPEN 0xa029a697 /* Database is open */ |
| 664 | #define SQLITE_MAGIC_CLOSED 0x9f3c2d33 /* Database is closed */ |
drh | 7e8b848 | 2008-01-23 03:03:05 +0000 | [diff] [blame] | 665 | #define SQLITE_MAGIC_SICK 0x4b771290 /* Error and awaiting close */ |
drh | 247be43 | 2002-05-10 05:44:55 +0000 | [diff] [blame] | 666 | #define SQLITE_MAGIC_BUSY 0xf03b7906 /* Database currently in use */ |
| 667 | #define SQLITE_MAGIC_ERROR 0xb5357930 /* An SQLITE_MISUSE error occurred */ |
| 668 | |
| 669 | /* |
drh | 0bce835 | 2002-02-28 00:41:10 +0000 | [diff] [blame] | 670 | ** Each SQL function is defined by an instance of the following |
| 671 | ** structure. A pointer to this structure is stored in the sqlite.aFunc |
drh | 8e0a2f9 | 2002-02-23 23:45:45 +0000 | [diff] [blame] | 672 | ** hash table. When multiple functions have the same name, the hash table |
| 673 | ** points to a linked list of these structures. |
drh | 2803757 | 2000-08-02 13:47:41 +0000 | [diff] [blame] | 674 | */ |
drh | 0bce835 | 2002-02-28 00:41:10 +0000 | [diff] [blame] | 675 | struct FuncDef { |
drh | 55ef4d9 | 2005-08-14 01:20:37 +0000 | [diff] [blame] | 676 | i16 nArg; /* Number of arguments. -1 means unlimited */ |
danielk1977 | d812336 | 2004-06-12 09:25:12 +0000 | [diff] [blame] | 677 | u8 iPrefEnc; /* Preferred text encoding (SQLITE_UTF8, 16LE, 16BE) */ |
drh | 55ef4d9 | 2005-08-14 01:20:37 +0000 | [diff] [blame] | 678 | u8 needCollSeq; /* True if sqlite3GetFuncCollSeq() might be called */ |
| 679 | u8 flags; /* Some combination of SQLITE_FUNC_* */ |
drh | f9b596e | 2004-05-26 16:54:42 +0000 | [diff] [blame] | 680 | void *pUserData; /* User data parameter */ |
| 681 | FuncDef *pNext; /* Next function with same name */ |
| 682 | void (*xFunc)(sqlite3_context*,int,sqlite3_value**); /* Regular function */ |
| 683 | void (*xStep)(sqlite3_context*,int,sqlite3_value**); /* Aggregate step */ |
| 684 | void (*xFinalize)(sqlite3_context*); /* Aggregate finializer */ |
drh | 55ef4d9 | 2005-08-14 01:20:37 +0000 | [diff] [blame] | 685 | char zName[1]; /* SQL name of the function. MUST BE LAST */ |
drh | 8e0a2f9 | 2002-02-23 23:45:45 +0000 | [diff] [blame] | 686 | }; |
drh | 2803757 | 2000-08-02 13:47:41 +0000 | [diff] [blame] | 687 | |
| 688 | /* |
danielk1977 | d1ab1ba | 2006-06-15 04:28:13 +0000 | [diff] [blame] | 689 | ** Each SQLite module (virtual table definition) is defined by an |
| 690 | ** instance of the following structure, stored in the sqlite3.aModule |
| 691 | ** hash table. |
| 692 | */ |
| 693 | struct Module { |
| 694 | const sqlite3_module *pModule; /* Callback pointers */ |
| 695 | const char *zName; /* Name passed to create_module() */ |
| 696 | void *pAux; /* pAux passed to create_module() */ |
danielk1977 | 832a58a | 2007-06-22 15:21:15 +0000 | [diff] [blame] | 697 | void (*xDestroy)(void *); /* Module destructor function */ |
danielk1977 | d1ab1ba | 2006-06-15 04:28:13 +0000 | [diff] [blame] | 698 | }; |
| 699 | |
| 700 | /* |
drh | 55ef4d9 | 2005-08-14 01:20:37 +0000 | [diff] [blame] | 701 | ** Possible values for FuncDef.flags |
| 702 | */ |
drh | d64fe2f | 2005-08-28 17:00:23 +0000 | [diff] [blame] | 703 | #define SQLITE_FUNC_LIKE 0x01 /* Candidate for the LIKE optimization */ |
| 704 | #define SQLITE_FUNC_CASE 0x02 /* Case-sensitive LIKE-type function */ |
drh | b7f6f68 | 2006-07-08 17:06:43 +0000 | [diff] [blame] | 705 | #define SQLITE_FUNC_EPHEM 0x04 /* Ephermeral. Delete with VDBE */ |
drh | 55ef4d9 | 2005-08-14 01:20:37 +0000 | [diff] [blame] | 706 | |
| 707 | /* |
drh | 967e8b7 | 2000-06-21 13:59:10 +0000 | [diff] [blame] | 708 | ** information about each column of an SQL table is held in an instance |
drh | 7020f65 | 2000-06-03 18:06:52 +0000 | [diff] [blame] | 709 | ** of this structure. |
| 710 | */ |
| 711 | struct Column { |
drh | 967e8b7 | 2000-06-21 13:59:10 +0000 | [diff] [blame] | 712 | char *zName; /* Name of this column */ |
danielk1977 | 7977a17 | 2004-11-09 12:44:37 +0000 | [diff] [blame] | 713 | Expr *pDflt; /* Default value of this column */ |
drh | 382c024 | 2001-10-06 16:33:02 +0000 | [diff] [blame] | 714 | char *zType; /* Data type for this column */ |
danielk1977 | b3bf556 | 2006-01-10 17:58:23 +0000 | [diff] [blame] | 715 | char *zColl; /* Collating sequence. If NULL, use the default */ |
drh | 4a32431 | 2001-12-21 14:30:42 +0000 | [diff] [blame] | 716 | u8 notNull; /* True if there is a NOT NULL constraint */ |
drh | 78100cc | 2003-08-23 22:40:53 +0000 | [diff] [blame] | 717 | u8 isPrimKey; /* True if this column is part of the PRIMARY KEY */ |
danielk1977 | a37cdde | 2004-05-16 11:15:36 +0000 | [diff] [blame] | 718 | char affinity; /* One of the SQLITE_AFF_... values */ |
danielk1977 | 034ca14 | 2007-06-26 10:38:54 +0000 | [diff] [blame] | 719 | #ifndef SQLITE_OMIT_VIRTUALTABLE |
| 720 | u8 isHidden; /* True if this column is 'hidden' */ |
| 721 | #endif |
drh | 7020f65 | 2000-06-03 18:06:52 +0000 | [diff] [blame] | 722 | }; |
| 723 | |
| 724 | /* |
drh | a9fd84b | 2004-05-18 23:21:35 +0000 | [diff] [blame] | 725 | ** A "Collating Sequence" is defined by an instance of the following |
danielk1977 | 0202b29 | 2004-06-09 09:55:16 +0000 | [diff] [blame] | 726 | ** structure. Conceptually, a collating sequence consists of a name and |
| 727 | ** a comparison routine that defines the order of that sequence. |
drh | a9fd84b | 2004-05-18 23:21:35 +0000 | [diff] [blame] | 728 | ** |
danielk1977 | 0202b29 | 2004-06-09 09:55:16 +0000 | [diff] [blame] | 729 | ** There may two seperate implementations of the collation function, one |
| 730 | ** that processes text in UTF-8 encoding (CollSeq.xCmp) and another that |
| 731 | ** processes text encoded in UTF-16 (CollSeq.xCmp16), using the machine |
| 732 | ** native byte order. When a collation sequence is invoked, SQLite selects |
| 733 | ** the version that will require the least expensive encoding |
danielk1977 | b3bf556 | 2006-01-10 17:58:23 +0000 | [diff] [blame] | 734 | ** translations, if any. |
danielk1977 | 0202b29 | 2004-06-09 09:55:16 +0000 | [diff] [blame] | 735 | ** |
| 736 | ** The CollSeq.pUser member variable is an extra parameter that passed in |
| 737 | ** as the first argument to the UTF-8 comparison function, xCmp. |
| 738 | ** CollSeq.pUser16 is the equivalent for the UTF-16 comparison function, |
| 739 | ** xCmp16. |
| 740 | ** |
| 741 | ** If both CollSeq.xCmp and CollSeq.xCmp16 are NULL, it means that the |
| 742 | ** collating sequence is undefined. Indices built on an undefined |
| 743 | ** collating sequence may not be read or written. |
drh | a9fd84b | 2004-05-18 23:21:35 +0000 | [diff] [blame] | 744 | */ |
| 745 | struct CollSeq { |
danielk1977 | a9808b3 | 2007-05-07 09:32:45 +0000 | [diff] [blame] | 746 | char *zName; /* Name of the collating sequence, UTF-8 encoded */ |
| 747 | u8 enc; /* Text encoding handled by xCmp() */ |
| 748 | u8 type; /* One of the SQLITE_COLL_... values below */ |
| 749 | void *pUser; /* First argument to xCmp() */ |
danielk1977 | 0202b29 | 2004-06-09 09:55:16 +0000 | [diff] [blame] | 750 | int (*xCmp)(void*,int, const void*, int, const void*); |
danielk1977 | a9808b3 | 2007-05-07 09:32:45 +0000 | [diff] [blame] | 751 | void (*xDel)(void*); /* Destructor for pUser */ |
drh | a9fd84b | 2004-05-18 23:21:35 +0000 | [diff] [blame] | 752 | }; |
| 753 | |
| 754 | /* |
drh | d64fe2f | 2005-08-28 17:00:23 +0000 | [diff] [blame] | 755 | ** Allowed values of CollSeq flags: |
| 756 | */ |
| 757 | #define SQLITE_COLL_BINARY 1 /* The default memcmp() collating sequence */ |
| 758 | #define SQLITE_COLL_NOCASE 2 /* The built-in NOCASE collating sequence */ |
| 759 | #define SQLITE_COLL_REVERSE 3 /* The built-in REVERSE collating sequence */ |
| 760 | #define SQLITE_COLL_USER 0 /* Any other user-defined collating sequence */ |
| 761 | |
| 762 | /* |
drh | d3d39e9 | 2004-05-20 22:16:29 +0000 | [diff] [blame] | 763 | ** A sort order can be either ASC or DESC. |
drh | 8e2ca02 | 2002-06-17 17:07:19 +0000 | [diff] [blame] | 764 | */ |
drh | 8e2ca02 | 2002-06-17 17:07:19 +0000 | [diff] [blame] | 765 | #define SQLITE_SO_ASC 0 /* Sort in ascending order */ |
drh | d3d39e9 | 2004-05-20 22:16:29 +0000 | [diff] [blame] | 766 | #define SQLITE_SO_DESC 1 /* Sort in ascending order */ |
drh | 8e2ca02 | 2002-06-17 17:07:19 +0000 | [diff] [blame] | 767 | |
| 768 | /* |
danielk1977 | a37cdde | 2004-05-16 11:15:36 +0000 | [diff] [blame] | 769 | ** Column affinity types. |
drh | 8a51256 | 2005-11-14 22:29:05 +0000 | [diff] [blame] | 770 | ** |
| 771 | ** These used to have mnemonic name like 'i' for SQLITE_AFF_INTEGER and |
| 772 | ** 't' for SQLITE_AFF_TEXT. But we can save a little space and improve |
| 773 | ** the speed a little by number the values consecutively. |
| 774 | ** |
| 775 | ** But rather than start with 0 or 1, we begin with 'a'. That way, |
| 776 | ** when multiple affinity types are concatenated into a string and |
drh | 66a5167 | 2008-01-03 00:01:23 +0000 | [diff] [blame] | 777 | ** used as the P4 operand, they will be more readable. |
drh | 8a51256 | 2005-11-14 22:29:05 +0000 | [diff] [blame] | 778 | ** |
| 779 | ** Note also that the numeric types are grouped together so that testing |
| 780 | ** for a numeric type is a single comparison. |
danielk1977 | a37cdde | 2004-05-16 11:15:36 +0000 | [diff] [blame] | 781 | */ |
drh | 8a51256 | 2005-11-14 22:29:05 +0000 | [diff] [blame] | 782 | #define SQLITE_AFF_TEXT 'a' |
| 783 | #define SQLITE_AFF_NONE 'b' |
| 784 | #define SQLITE_AFF_NUMERIC 'c' |
| 785 | #define SQLITE_AFF_INTEGER 'd' |
| 786 | #define SQLITE_AFF_REAL 'e' |
danielk1977 | a37cdde | 2004-05-16 11:15:36 +0000 | [diff] [blame] | 787 | |
drh | 8a51256 | 2005-11-14 22:29:05 +0000 | [diff] [blame] | 788 | #define sqlite3IsNumericAffinity(X) ((X)>=SQLITE_AFF_NUMERIC) |
danielk1977 | a37cdde | 2004-05-16 11:15:36 +0000 | [diff] [blame] | 789 | |
| 790 | /* |
drh | 3557335 | 2008-01-08 23:54:25 +0000 | [diff] [blame] | 791 | ** The SQLITE_AFF_MASK values masks off the significant bits of an |
| 792 | ** affinity value. |
| 793 | */ |
| 794 | #define SQLITE_AFF_MASK 0x67 |
| 795 | |
| 796 | /* |
| 797 | ** Additional bit values that can be ORed with an affinity without |
| 798 | ** changing the affinity. |
| 799 | */ |
| 800 | #define SQLITE_JUMPIFNULL 0x08 /* jumps if either operand is NULL */ |
| 801 | #define SQLITE_NULLEQUAL 0x10 /* compare NULLs equal */ |
| 802 | #define SQLITE_STOREP2 0x80 /* Store result in reg[P2] rather than jump */ |
| 803 | |
| 804 | /* |
drh | 22f70c3 | 2002-02-18 01:17:00 +0000 | [diff] [blame] | 805 | ** Each SQL table is represented in memory by an instance of the |
| 806 | ** following structure. |
| 807 | ** |
drh | d24cc42 | 2003-03-27 12:51:24 +0000 | [diff] [blame] | 808 | ** Table.zName is the name of the table. The case of the original |
drh | 22f70c3 | 2002-02-18 01:17:00 +0000 | [diff] [blame] | 809 | ** CREATE TABLE statement is stored, but case is not significant for |
| 810 | ** comparisons. |
| 811 | ** |
drh | d24cc42 | 2003-03-27 12:51:24 +0000 | [diff] [blame] | 812 | ** Table.nCol is the number of columns in this table. Table.aCol is a |
drh | 22f70c3 | 2002-02-18 01:17:00 +0000 | [diff] [blame] | 813 | ** pointer to an array of Column structures, one for each column. |
| 814 | ** |
drh | d24cc42 | 2003-03-27 12:51:24 +0000 | [diff] [blame] | 815 | ** If the table has an INTEGER PRIMARY KEY, then Table.iPKey is the index of |
| 816 | ** the column that is that key. Otherwise Table.iPKey is negative. Note |
drh | 22f70c3 | 2002-02-18 01:17:00 +0000 | [diff] [blame] | 817 | ** that the datatype of the PRIMARY KEY must be INTEGER for this field to |
| 818 | ** be set. An INTEGER PRIMARY KEY is used as the rowid for each row of |
| 819 | ** the table. If a table has no INTEGER PRIMARY KEY, then a random rowid |
drh | d24cc42 | 2003-03-27 12:51:24 +0000 | [diff] [blame] | 820 | ** is generated for each row of the table. Table.hasPrimKey is true if |
drh | 22f70c3 | 2002-02-18 01:17:00 +0000 | [diff] [blame] | 821 | ** the table has any PRIMARY KEY, INTEGER or otherwise. |
| 822 | ** |
drh | d24cc42 | 2003-03-27 12:51:24 +0000 | [diff] [blame] | 823 | ** Table.tnum is the page number for the root BTree page of the table in the |
| 824 | ** database file. If Table.iDb is the index of the database table backend |
| 825 | ** in sqlite.aDb[]. 0 is for the main database and 1 is for the file that |
drh | b9bb7c1 | 2006-06-11 23:41:55 +0000 | [diff] [blame] | 826 | ** holds temporary tables and indices. If Table.isEphem |
drh | 22f70c3 | 2002-02-18 01:17:00 +0000 | [diff] [blame] | 827 | ** is true, then the table is stored in a file that is automatically deleted |
drh | d24cc42 | 2003-03-27 12:51:24 +0000 | [diff] [blame] | 828 | ** when the VDBE cursor to the table is closed. In this case Table.tnum |
drh | 22f70c3 | 2002-02-18 01:17:00 +0000 | [diff] [blame] | 829 | ** refers VDBE cursor number that holds the table open, not to the root |
| 830 | ** page number. Transient tables are used to hold the results of a |
| 831 | ** sub-query that appears instead of a real table name in the FROM clause |
| 832 | ** of a SELECT statement. |
drh | 7589723 | 2000-05-29 14:26:00 +0000 | [diff] [blame] | 833 | */ |
| 834 | struct Table { |
drh | 967e8b7 | 2000-06-21 13:59:10 +0000 | [diff] [blame] | 835 | char *zName; /* Name of the table */ |
drh | 967e8b7 | 2000-06-21 13:59:10 +0000 | [diff] [blame] | 836 | int nCol; /* Number of columns in this table */ |
| 837 | Column *aCol; /* Information about each column */ |
drh | c839258 | 2001-12-31 02:48:51 +0000 | [diff] [blame] | 838 | int iPKey; /* If not less then 0, use aCol[iPKey] as the primary key */ |
drh | 967e8b7 | 2000-06-21 13:59:10 +0000 | [diff] [blame] | 839 | Index *pIndex; /* List of SQL indexes on this table. */ |
drh | 22f70c3 | 2002-02-18 01:17:00 +0000 | [diff] [blame] | 840 | int tnum; /* Root BTree node for this table (see note above) */ |
drh | a76b5df | 2002-02-23 02:32:10 +0000 | [diff] [blame] | 841 | Select *pSelect; /* NULL for tables. Points to definition if a view. */ |
drh | ed8a3bb | 2005-06-06 21:19:56 +0000 | [diff] [blame] | 842 | int nRef; /* Number of pointers to this Table */ |
danielk1977 | c3f9bad | 2002-05-15 08:30:12 +0000 | [diff] [blame] | 843 | Trigger *pTrigger; /* List of SQL triggers on this table */ |
drh | c2eef3b | 2002-08-31 18:53:06 +0000 | [diff] [blame] | 844 | FKey *pFKey; /* Linked list of all foreign keys in this table */ |
danielk1977 | 3d1bfea | 2004-05-14 11:00:53 +0000 | [diff] [blame] | 845 | char *zColAff; /* String defining the affinity of each column */ |
drh | ffe07b2 | 2005-11-03 00:41:17 +0000 | [diff] [blame] | 846 | #ifndef SQLITE_OMIT_CHECK |
| 847 | Expr *pCheck; /* The AND of all CHECK constraints */ |
| 848 | #endif |
danielk1977 | 19a8e7e | 2005-03-17 05:03:38 +0000 | [diff] [blame] | 849 | #ifndef SQLITE_OMIT_ALTERTABLE |
| 850 | int addColOffset; /* Offset in CREATE TABLE statement to add a new column */ |
| 851 | #endif |
drh | 1914619 | 2006-06-26 19:10:32 +0000 | [diff] [blame] | 852 | u8 readOnly; /* True if this table should not be written by the user */ |
| 853 | u8 isEphem; /* True if created using OP_OpenEphermeral */ |
| 854 | u8 hasPrimKey; /* True if there exists a primary key */ |
| 855 | u8 keyConf; /* What to do in case of uniqueness conflict on iPKey */ |
| 856 | u8 autoInc; /* True if the integer primary key is autoincrement */ |
drh | e09daa9 | 2006-06-10 13:29:31 +0000 | [diff] [blame] | 857 | #ifndef SQLITE_OMIT_VIRTUALTABLE |
drh | 1914619 | 2006-06-26 19:10:32 +0000 | [diff] [blame] | 858 | u8 isVirtual; /* True if this is a virtual table */ |
| 859 | u8 isCommit; /* True once the CREATE TABLE has been committed */ |
danielk1977 | d1ab1ba | 2006-06-15 04:28:13 +0000 | [diff] [blame] | 860 | Module *pMod; /* Pointer to the implementation of the module */ |
drh | b9bb7c1 | 2006-06-11 23:41:55 +0000 | [diff] [blame] | 861 | sqlite3_vtab *pVtab; /* Pointer to the module instance */ |
| 862 | int nModuleArg; /* Number of arguments to the module */ |
| 863 | char **azModuleArg; /* Text of all module args. [0] is module name */ |
drh | e09daa9 | 2006-06-10 13:29:31 +0000 | [diff] [blame] | 864 | #endif |
drh | 728b577 | 2007-09-18 15:55:07 +0000 | [diff] [blame] | 865 | Schema *pSchema; /* Schema that contains this table */ |
drh | 7589723 | 2000-05-29 14:26:00 +0000 | [diff] [blame] | 866 | }; |
| 867 | |
| 868 | /* |
drh | 4cbdda9 | 2006-06-14 19:00:20 +0000 | [diff] [blame] | 869 | ** Test to see whether or not a table is a virtual table. This is |
| 870 | ** done as a macro so that it will be optimized out when virtual |
| 871 | ** table support is omitted from the build. |
| 872 | */ |
| 873 | #ifndef SQLITE_OMIT_VIRTUALTABLE |
danielk1977 | 034ca14 | 2007-06-26 10:38:54 +0000 | [diff] [blame] | 874 | # define IsVirtual(X) ((X)->isVirtual) |
| 875 | # define IsHiddenColumn(X) ((X)->isHidden) |
drh | 4cbdda9 | 2006-06-14 19:00:20 +0000 | [diff] [blame] | 876 | #else |
danielk1977 | 034ca14 | 2007-06-26 10:38:54 +0000 | [diff] [blame] | 877 | # define IsVirtual(X) 0 |
| 878 | # define IsHiddenColumn(X) 0 |
drh | 4cbdda9 | 2006-06-14 19:00:20 +0000 | [diff] [blame] | 879 | #endif |
| 880 | |
| 881 | /* |
drh | c2eef3b | 2002-08-31 18:53:06 +0000 | [diff] [blame] | 882 | ** Each foreign key constraint is an instance of the following structure. |
| 883 | ** |
| 884 | ** A foreign key is associated with two tables. The "from" table is |
| 885 | ** the table that contains the REFERENCES clause that creates the foreign |
| 886 | ** key. The "to" table is the table that is named in the REFERENCES clause. |
| 887 | ** Consider this example: |
| 888 | ** |
| 889 | ** CREATE TABLE ex1( |
| 890 | ** a INTEGER PRIMARY KEY, |
| 891 | ** b INTEGER CONSTRAINT fk1 REFERENCES ex2(x) |
| 892 | ** ); |
| 893 | ** |
| 894 | ** For foreign key "fk1", the from-table is "ex1" and the to-table is "ex2". |
| 895 | ** |
| 896 | ** Each REFERENCES clause generates an instance of the following structure |
| 897 | ** which is attached to the from-table. The to-table need not exist when |
| 898 | ** the from-table is created. The existance of the to-table is not checked |
| 899 | ** until an attempt is made to insert data into the from-table. |
| 900 | ** |
drh | ea1ba17 | 2003-04-20 00:00:23 +0000 | [diff] [blame] | 901 | ** The sqlite.aFKey hash table stores pointers to this structure |
drh | c2eef3b | 2002-08-31 18:53:06 +0000 | [diff] [blame] | 902 | ** given the name of a to-table. For each to-table, all foreign keys |
| 903 | ** associated with that table are on a linked list using the FKey.pNextTo |
| 904 | ** field. |
| 905 | */ |
| 906 | struct FKey { |
| 907 | Table *pFrom; /* The table that constains the REFERENCES clause */ |
| 908 | FKey *pNextFrom; /* Next foreign key in pFrom */ |
| 909 | char *zTo; /* Name of table that the key points to */ |
| 910 | FKey *pNextTo; /* Next foreign key that points to zTo */ |
| 911 | int nCol; /* Number of columns in this key */ |
| 912 | struct sColMap { /* Mapping of columns in pFrom to columns in zTo */ |
| 913 | int iFrom; /* Index of column in pFrom */ |
| 914 | char *zCol; /* Name of column in zTo. If 0 use PRIMARY KEY */ |
| 915 | } *aCol; /* One entry for each of nCol column s */ |
| 916 | u8 isDeferred; /* True if constraint checking is deferred till COMMIT */ |
| 917 | u8 updateConf; /* How to resolve conflicts that occur on UPDATE */ |
| 918 | u8 deleteConf; /* How to resolve conflicts that occur on DELETE */ |
| 919 | u8 insertConf; /* How to resolve conflicts that occur on INSERT */ |
| 920 | }; |
| 921 | |
| 922 | /* |
danielk1977 | aaa40c1 | 2007-09-21 04:28:16 +0000 | [diff] [blame] | 923 | ** SQLite supports many different ways to resolve a constraint |
drh | 22f70c3 | 2002-02-18 01:17:00 +0000 | [diff] [blame] | 924 | ** error. ROLLBACK processing means that a constraint violation |
drh | 0bd1f4e | 2002-06-06 18:54:39 +0000 | [diff] [blame] | 925 | ** causes the operation in process to fail and for the current transaction |
drh | 1c92853 | 2002-01-31 15:54:21 +0000 | [diff] [blame] | 926 | ** to be rolled back. ABORT processing means the operation in process |
| 927 | ** fails and any prior changes from that one operation are backed out, |
| 928 | ** but the transaction is not rolled back. FAIL processing means that |
| 929 | ** the operation in progress stops and returns an error code. But prior |
| 930 | ** changes due to the same operation are not backed out and no rollback |
| 931 | ** occurs. IGNORE means that the particular row that caused the constraint |
| 932 | ** error is not inserted or updated. Processing continues and no error |
| 933 | ** is returned. REPLACE means that preexisting database rows that caused |
| 934 | ** a UNIQUE constraint violation are removed so that the new insert or |
| 935 | ** update can proceed. Processing continues and no error is reported. |
drh | c2eef3b | 2002-08-31 18:53:06 +0000 | [diff] [blame] | 936 | ** |
| 937 | ** RESTRICT, SETNULL, and CASCADE actions apply only to foreign keys. |
| 938 | ** RESTRICT is the same as ABORT for IMMEDIATE foreign keys and the |
| 939 | ** same as ROLLBACK for DEFERRED keys. SETNULL means that the foreign |
| 940 | ** key is set to NULL. CASCADE means that a DELETE or UPDATE of the |
| 941 | ** referenced table row is propagated into the row that holds the |
| 942 | ** foreign key. |
drh | 1c92853 | 2002-01-31 15:54:21 +0000 | [diff] [blame] | 943 | ** |
drh | 968af52 | 2003-02-11 14:55:40 +0000 | [diff] [blame] | 944 | ** The following symbolic values are used to record which type |
drh | 1c92853 | 2002-01-31 15:54:21 +0000 | [diff] [blame] | 945 | ** of action to take. |
drh | 9cfcf5d | 2002-01-29 18:41:24 +0000 | [diff] [blame] | 946 | */ |
drh | 1c92853 | 2002-01-31 15:54:21 +0000 | [diff] [blame] | 947 | #define OE_None 0 /* There is no constraint to check */ |
| 948 | #define OE_Rollback 1 /* Fail the operation and rollback the transaction */ |
| 949 | #define OE_Abort 2 /* Back out changes but do no rollback transaction */ |
| 950 | #define OE_Fail 3 /* Stop the operation but leave all prior changes */ |
| 951 | #define OE_Ignore 4 /* Ignore the error. Do not do the INSERT or UPDATE */ |
| 952 | #define OE_Replace 5 /* Delete existing record, then do INSERT or UPDATE */ |
drh | c2eef3b | 2002-08-31 18:53:06 +0000 | [diff] [blame] | 953 | |
| 954 | #define OE_Restrict 6 /* OE_Abort for IMMEDIATE, OE_Rollback for DEFERRED */ |
| 955 | #define OE_SetNull 7 /* Set the foreign key value to NULL */ |
| 956 | #define OE_SetDflt 8 /* Set the foreign key value to its default */ |
| 957 | #define OE_Cascade 9 /* Cascade the changes */ |
| 958 | |
| 959 | #define OE_Default 99 /* Do whatever the default action is */ |
drh | 9cfcf5d | 2002-01-29 18:41:24 +0000 | [diff] [blame] | 960 | |
drh | d3d39e9 | 2004-05-20 22:16:29 +0000 | [diff] [blame] | 961 | |
| 962 | /* |
| 963 | ** An instance of the following structure is passed as the first |
| 964 | ** argument to sqlite3VdbeKeyCompare and is used to control the |
| 965 | ** comparison of the two index keys. |
| 966 | ** |
| 967 | ** If the KeyInfo.incrKey value is true and the comparison would |
drh | 7e62779 | 2005-04-29 02:10:00 +0000 | [diff] [blame] | 968 | ** otherwise be equal, then return a result as if the second key |
| 969 | ** were larger. |
drh | d3d39e9 | 2004-05-20 22:16:29 +0000 | [diff] [blame] | 970 | */ |
| 971 | struct KeyInfo { |
drh | b21c8cd | 2007-08-21 19:33:56 +0000 | [diff] [blame] | 972 | sqlite3 *db; /* The database connection */ |
danielk1977 | b1bc953 | 2004-05-22 03:05:33 +0000 | [diff] [blame] | 973 | u8 enc; /* Text encoding - one of the TEXT_Utf* values */ |
drh | d3d39e9 | 2004-05-20 22:16:29 +0000 | [diff] [blame] | 974 | u8 incrKey; /* Increase 2nd key by epsilon before comparison */ |
danielk1977 | 9a96b66 | 2007-11-29 17:05:18 +0000 | [diff] [blame] | 975 | u8 prefixIsEqual; /* Treat a prefix as equal */ |
drh | d3d39e9 | 2004-05-20 22:16:29 +0000 | [diff] [blame] | 976 | int nField; /* Number of entries in aColl[] */ |
drh | d2d4a6b | 2006-01-10 15:18:27 +0000 | [diff] [blame] | 977 | u8 *aSortOrder; /* If defined an aSortOrder[i] is true, sort DESC */ |
drh | d3d39e9 | 2004-05-20 22:16:29 +0000 | [diff] [blame] | 978 | CollSeq *aColl[1]; /* Collating sequence for each term of the key */ |
| 979 | }; |
| 980 | |
drh | 9cfcf5d | 2002-01-29 18:41:24 +0000 | [diff] [blame] | 981 | /* |
drh | 66b89c8 | 2000-11-28 20:47:17 +0000 | [diff] [blame] | 982 | ** Each SQL index is represented in memory by an |
drh | 7589723 | 2000-05-29 14:26:00 +0000 | [diff] [blame] | 983 | ** instance of the following structure. |
drh | 967e8b7 | 2000-06-21 13:59:10 +0000 | [diff] [blame] | 984 | ** |
| 985 | ** The columns of the table that are to be indexed are described |
| 986 | ** by the aiColumn[] field of this structure. For example, suppose |
| 987 | ** we have the following table and index: |
| 988 | ** |
| 989 | ** CREATE TABLE Ex1(c1 int, c2 int, c3 text); |
| 990 | ** CREATE INDEX Ex2 ON Ex1(c3,c1); |
| 991 | ** |
| 992 | ** In the Table structure describing Ex1, nCol==3 because there are |
| 993 | ** three columns in the table. In the Index structure describing |
| 994 | ** Ex2, nColumn==2 since 2 of the 3 columns of Ex1 are indexed. |
| 995 | ** The value of aiColumn is {2, 0}. aiColumn[0]==2 because the |
| 996 | ** first column to be indexed (c3) has an index of 2 in Ex1.aCol[]. |
| 997 | ** The second column to be indexed (c1) has an index of 0 in |
| 998 | ** Ex1.aCol[], hence Ex2.aiColumn[1]==0. |
drh | ea1ba17 | 2003-04-20 00:00:23 +0000 | [diff] [blame] | 999 | ** |
| 1000 | ** The Index.onError field determines whether or not the indexed columns |
| 1001 | ** must be unique and what to do if they are not. When Index.onError=OE_None, |
| 1002 | ** it means this is not a unique index. Otherwise it is a unique index |
| 1003 | ** and the value of Index.onError indicate the which conflict resolution |
| 1004 | ** algorithm to employ whenever an attempt is made to insert a non-unique |
| 1005 | ** element. |
drh | 7589723 | 2000-05-29 14:26:00 +0000 | [diff] [blame] | 1006 | */ |
| 1007 | struct Index { |
drh | 967e8b7 | 2000-06-21 13:59:10 +0000 | [diff] [blame] | 1008 | char *zName; /* Name of this index */ |
drh | 967e8b7 | 2000-06-21 13:59:10 +0000 | [diff] [blame] | 1009 | int nColumn; /* Number of columns in the table used by this index */ |
| 1010 | int *aiColumn; /* Which columns are used by this index. 1st is 0 */ |
drh | 8b3d990 | 2005-08-19 00:14:42 +0000 | [diff] [blame] | 1011 | unsigned *aiRowEst; /* Result of ANALYZE: Est. rows selected by each column */ |
drh | 967e8b7 | 2000-06-21 13:59:10 +0000 | [diff] [blame] | 1012 | Table *pTable; /* The SQL table being indexed */ |
drh | be0072d | 2001-09-13 14:46:09 +0000 | [diff] [blame] | 1013 | int tnum; /* Page containing root of this index in database file */ |
drh | 9cfcf5d | 2002-01-29 18:41:24 +0000 | [diff] [blame] | 1014 | u8 onError; /* OE_Abort, OE_Ignore, OE_Replace, or OE_None */ |
drh | 485b39b | 2002-07-13 03:11:52 +0000 | [diff] [blame] | 1015 | u8 autoIndex; /* True if is automatically created (ex: by UNIQUE) */ |
danielk1977 | a37cdde | 2004-05-16 11:15:36 +0000 | [diff] [blame] | 1016 | char *zColAff; /* String defining the affinity of each column */ |
drh | 967e8b7 | 2000-06-21 13:59:10 +0000 | [diff] [blame] | 1017 | Index *pNext; /* The next index associated with the same table */ |
danielk1977 | b3bf556 | 2006-01-10 17:58:23 +0000 | [diff] [blame] | 1018 | Schema *pSchema; /* Schema containing this index */ |
| 1019 | u8 *aSortOrder; /* Array of size Index.nColumn. True==DESC, False==ASC */ |
| 1020 | char **azColl; /* Array of collation sequence names for index */ |
drh | 7589723 | 2000-05-29 14:26:00 +0000 | [diff] [blame] | 1021 | }; |
| 1022 | |
| 1023 | /* |
| 1024 | ** Each token coming out of the lexer is an instance of |
drh | 4b59ab5 | 2002-08-24 18:24:51 +0000 | [diff] [blame] | 1025 | ** this structure. Tokens are also used as part of an expression. |
drh | 4efc475 | 2004-01-16 15:55:37 +0000 | [diff] [blame] | 1026 | ** |
| 1027 | ** Note if Token.z==0 then Token.dyn and Token.n are undefined and |
| 1028 | ** may contain random values. Do not make any assuptions about Token.dyn |
| 1029 | ** and Token.n when Token.z==0. |
drh | 7589723 | 2000-05-29 14:26:00 +0000 | [diff] [blame] | 1030 | */ |
| 1031 | struct Token { |
drh | 4c755c0 | 2004-08-08 20:22:17 +0000 | [diff] [blame] | 1032 | const unsigned char *z; /* Text of the token. Not NULL-terminated! */ |
| 1033 | unsigned dyn : 1; /* True for malloced memory, false for static */ |
| 1034 | unsigned n : 31; /* Number of characters in this token */ |
drh | 7589723 | 2000-05-29 14:26:00 +0000 | [diff] [blame] | 1035 | }; |
| 1036 | |
| 1037 | /* |
drh | 1344989 | 2005-09-07 21:22:45 +0000 | [diff] [blame] | 1038 | ** An instance of this structure contains information needed to generate |
| 1039 | ** code for a SELECT that contains aggregate functions. |
| 1040 | ** |
| 1041 | ** If Expr.op==TK_AGG_COLUMN or TK_AGG_FUNCTION then Expr.pAggInfo is a |
| 1042 | ** pointer to this structure. The Expr.iColumn field is the index in |
| 1043 | ** AggInfo.aCol[] or AggInfo.aFunc[] of information needed to generate |
| 1044 | ** code for that node. |
| 1045 | ** |
| 1046 | ** AggInfo.pGroupBy and AggInfo.aFunc.pExpr point to fields within the |
| 1047 | ** original Select structure that describes the SELECT statement. These |
| 1048 | ** fields do not need to be freed when deallocating the AggInfo structure. |
| 1049 | */ |
| 1050 | struct AggInfo { |
| 1051 | u8 directMode; /* Direct rendering mode means take data directly |
| 1052 | ** from source tables rather than from accumulators */ |
| 1053 | u8 useSortingIdx; /* In direct mode, reference the sorting index rather |
| 1054 | ** than the source table */ |
| 1055 | int sortingIdx; /* Cursor number of the sorting index */ |
| 1056 | ExprList *pGroupBy; /* The group by clause */ |
| 1057 | int nSortingColumn; /* Number of columns in the sorting index */ |
| 1058 | struct AggInfo_col { /* For each column used in source tables */ |
danielk1977 | 0817d0d | 2007-02-14 09:19:36 +0000 | [diff] [blame] | 1059 | Table *pTab; /* Source table */ |
drh | 1344989 | 2005-09-07 21:22:45 +0000 | [diff] [blame] | 1060 | int iTable; /* Cursor number of the source table */ |
| 1061 | int iColumn; /* Column number within the source table */ |
| 1062 | int iSorterColumn; /* Column number in the sorting index */ |
| 1063 | int iMem; /* Memory location that acts as accumulator */ |
drh | 5774b80 | 2005-09-07 22:48:16 +0000 | [diff] [blame] | 1064 | Expr *pExpr; /* The original expression */ |
drh | 1344989 | 2005-09-07 21:22:45 +0000 | [diff] [blame] | 1065 | } *aCol; |
| 1066 | int nColumn; /* Number of used entries in aCol[] */ |
| 1067 | int nColumnAlloc; /* Number of slots allocated for aCol[] */ |
| 1068 | int nAccumulator; /* Number of columns that show through to the output. |
| 1069 | ** Additional columns are used only as parameters to |
| 1070 | ** aggregate functions */ |
| 1071 | struct AggInfo_func { /* For each aggregate function */ |
| 1072 | Expr *pExpr; /* Expression encoding the function */ |
| 1073 | FuncDef *pFunc; /* The aggregate function implementation */ |
| 1074 | int iMem; /* Memory location that acts as accumulator */ |
drh | b9bb7c1 | 2006-06-11 23:41:55 +0000 | [diff] [blame] | 1075 | int iDistinct; /* Ephermeral table used to enforce DISTINCT */ |
drh | 1344989 | 2005-09-07 21:22:45 +0000 | [diff] [blame] | 1076 | } *aFunc; |
| 1077 | int nFunc; /* Number of entries in aFunc[] */ |
| 1078 | int nFuncAlloc; /* Number of slots allocated for aFunc[] */ |
| 1079 | }; |
| 1080 | |
| 1081 | /* |
drh | 7589723 | 2000-05-29 14:26:00 +0000 | [diff] [blame] | 1082 | ** Each node of an expression in the parse tree is an instance |
drh | 22f70c3 | 2002-02-18 01:17:00 +0000 | [diff] [blame] | 1083 | ** of this structure. |
| 1084 | ** |
| 1085 | ** Expr.op is the opcode. The integer parser token codes are reused |
| 1086 | ** as opcodes here. For example, the parser defines TK_GE to be an integer |
| 1087 | ** code representing the ">=" operator. This same integer code is reused |
| 1088 | ** to represent the greater-than-or-equal-to operator in the expression |
| 1089 | ** tree. |
| 1090 | ** |
| 1091 | ** Expr.pRight and Expr.pLeft are subexpressions. Expr.pList is a list |
| 1092 | ** of argument if the expression is a function. |
| 1093 | ** |
drh | 4b59ab5 | 2002-08-24 18:24:51 +0000 | [diff] [blame] | 1094 | ** Expr.token is the operator token for this node. For some expressions |
| 1095 | ** that have subexpressions, Expr.token can be the complete text that gave |
| 1096 | ** rise to the Expr. In the latter case, the token is marked as being |
| 1097 | ** a compound token. |
drh | 22f70c3 | 2002-02-18 01:17:00 +0000 | [diff] [blame] | 1098 | ** |
| 1099 | ** An expression of the form ID or ID.ID refers to a column in a table. |
| 1100 | ** For such expressions, Expr.op is set to TK_COLUMN and Expr.iTable is |
| 1101 | ** the integer cursor number of a VDBE cursor pointing to that table and |
| 1102 | ** Expr.iColumn is the column number for the specific column. If the |
| 1103 | ** expression is used as a result in an aggregate SELECT, then the |
| 1104 | ** value is also stored in the Expr.iAgg column in the aggregate so that |
| 1105 | ** it can be accessed after all aggregates are computed. |
| 1106 | ** |
| 1107 | ** If the expression is a function, the Expr.iTable is an integer code |
drh | 7c972de | 2003-09-06 22:18:07 +0000 | [diff] [blame] | 1108 | ** representing which function. If the expression is an unbound variable |
| 1109 | ** marker (a question mark character '?' in the original SQL) then the |
| 1110 | ** Expr.iTable holds the index number for that variable. |
drh | 22f70c3 | 2002-02-18 01:17:00 +0000 | [diff] [blame] | 1111 | ** |
drh | 1398ad3 | 2005-01-19 23:24:50 +0000 | [diff] [blame] | 1112 | ** If the expression is a subquery then Expr.iColumn holds an integer |
| 1113 | ** register number containing the result of the subquery. If the |
| 1114 | ** subquery gives a constant result, then iTable is -1. If the subquery |
| 1115 | ** gives a different answer at different times during statement processing |
| 1116 | ** then iTable is the address of a subroutine that computes the subquery. |
| 1117 | ** |
drh | 22f70c3 | 2002-02-18 01:17:00 +0000 | [diff] [blame] | 1118 | ** The Expr.pSelect field points to a SELECT statement. The SELECT might |
| 1119 | ** be the right operand of an IN operator. Or, if a scalar SELECT appears |
| 1120 | ** in an expression the opcode is TK_SELECT and Expr.pSelect is the only |
| 1121 | ** operand. |
danielk1977 | aee18ef | 2005-03-09 12:26:50 +0000 | [diff] [blame] | 1122 | ** |
| 1123 | ** If the Expr is of type OP_Column, and the table it is selecting from |
| 1124 | ** is a disk table or the "old.*" pseudo-table, then pTab points to the |
| 1125 | ** corresponding table definition. |
drh | 7589723 | 2000-05-29 14:26:00 +0000 | [diff] [blame] | 1126 | */ |
| 1127 | struct Expr { |
drh | 1cc093c | 2002-06-24 22:01:57 +0000 | [diff] [blame] | 1128 | u8 op; /* Operation performed by this node */ |
drh | a9fd84b | 2004-05-18 23:21:35 +0000 | [diff] [blame] | 1129 | char affinity; /* The affinity of the column or 0 if not a column */ |
drh | 6a03a1c | 2006-07-08 18:34:59 +0000 | [diff] [blame] | 1130 | u16 flags; /* Various flags. See below */ |
drh | f2bc013 | 2004-10-04 13:19:23 +0000 | [diff] [blame] | 1131 | CollSeq *pColl; /* The collation type of the column or 0 */ |
drh | 7589723 | 2000-05-29 14:26:00 +0000 | [diff] [blame] | 1132 | Expr *pLeft, *pRight; /* Left and right subnodes */ |
drh | d99f706 | 2002-06-08 23:25:08 +0000 | [diff] [blame] | 1133 | ExprList *pList; /* A list of expressions used as function arguments |
| 1134 | ** or in "<expr> IN (<expr-list)" */ |
drh | 7589723 | 2000-05-29 14:26:00 +0000 | [diff] [blame] | 1135 | Token token; /* An operand token */ |
drh | 6977fea | 2002-10-22 23:38:04 +0000 | [diff] [blame] | 1136 | Token span; /* Complete text of the expression */ |
drh | 967e8b7 | 2000-06-21 13:59:10 +0000 | [diff] [blame] | 1137 | int iTable, iColumn; /* When op==TK_COLUMN, then this expr node means the |
drh | 8e2ca02 | 2002-06-17 17:07:19 +0000 | [diff] [blame] | 1138 | ** iColumn-th field of the iTable-th table. */ |
drh | 1344989 | 2005-09-07 21:22:45 +0000 | [diff] [blame] | 1139 | AggInfo *pAggInfo; /* Used by TK_AGG_COLUMN and TK_AGG_FUNCTION */ |
| 1140 | int iAgg; /* Which entry in pAggInfo->aCol[] or ->aFunc[] */ |
drh | 22d6a53 | 2005-09-19 21:05:48 +0000 | [diff] [blame] | 1141 | int iRightJoinTable; /* If EP_FromJoin, the right table of the join */ |
drh | d99f706 | 2002-06-08 23:25:08 +0000 | [diff] [blame] | 1142 | Select *pSelect; /* When the expression is a sub-select. Also the |
| 1143 | ** right side of "<expr> IN (<select>)" */ |
danielk1977 | aee18ef | 2005-03-09 12:26:50 +0000 | [diff] [blame] | 1144 | Table *pTab; /* Table for OP_Column expressions. */ |
drh | 0224d26 | 2008-05-28 13:49:34 +0000 | [diff] [blame] | 1145 | #if SQLITE_MAX_EXPR_DEPTH>0 |
danielk1977 | fc97606 | 2007-05-10 10:46:56 +0000 | [diff] [blame] | 1146 | int nHeight; /* Height of the tree headed by this node */ |
| 1147 | #endif |
drh | 7589723 | 2000-05-29 14:26:00 +0000 | [diff] [blame] | 1148 | }; |
| 1149 | |
| 1150 | /* |
drh | 1f16230 | 2002-10-27 19:35:33 +0000 | [diff] [blame] | 1151 | ** The following are the meanings of bits in the Expr.flags field. |
| 1152 | */ |
drh | 678ccce | 2008-03-31 18:19:54 +0000 | [diff] [blame] | 1153 | #define EP_FromJoin 0x0001 /* Originated in ON or USING clause of a join */ |
| 1154 | #define EP_Agg 0x0002 /* Contains one or more aggregate functions */ |
| 1155 | #define EP_Resolved 0x0004 /* IDs have been resolved to COLUMNs */ |
| 1156 | #define EP_Error 0x0008 /* Expression contains one or more errors */ |
| 1157 | #define EP_Distinct 0x0010 /* Aggregate function with DISTINCT keyword */ |
| 1158 | #define EP_VarSelect 0x0020 /* pSelect is correlated, not constant */ |
| 1159 | #define EP_Dequoted 0x0040 /* True if the string has been dequoted */ |
| 1160 | #define EP_InfixFunc 0x0080 /* True for an infix function: LIKE, GLOB, etc */ |
| 1161 | #define EP_ExpCollate 0x0100 /* Collating sequence specified explicitly */ |
drh | da250ea | 2008-04-01 05:07:14 +0000 | [diff] [blame] | 1162 | #define EP_AnyAff 0x0200 /* Can take a cached column of any affinity */ |
drh | 47de955 | 2008-04-01 18:04:11 +0000 | [diff] [blame] | 1163 | #define EP_FixedDest 0x0400 /* Result needed in a specific register */ |
drh | 1f16230 | 2002-10-27 19:35:33 +0000 | [diff] [blame] | 1164 | |
| 1165 | /* |
| 1166 | ** These macros can be used to test, set, or clear bits in the |
| 1167 | ** Expr.flags field. |
| 1168 | */ |
| 1169 | #define ExprHasProperty(E,P) (((E)->flags&(P))==(P)) |
| 1170 | #define ExprHasAnyProperty(E,P) (((E)->flags&(P))!=0) |
| 1171 | #define ExprSetProperty(E,P) (E)->flags|=(P) |
| 1172 | #define ExprClearProperty(E,P) (E)->flags&=~(P) |
| 1173 | |
| 1174 | /* |
drh | 7589723 | 2000-05-29 14:26:00 +0000 | [diff] [blame] | 1175 | ** A list of expressions. Each expression may optionally have a |
| 1176 | ** name. An expr/name combination can be used in several ways, such |
| 1177 | ** as the list of "expr AS ID" fields following a "SELECT" or in the |
| 1178 | ** list of "ID = expr" items in an UPDATE. A list of expressions can |
drh | ad3cab5 | 2002-05-24 02:04:32 +0000 | [diff] [blame] | 1179 | ** also be used as the argument to a function, in which case the a.zName |
drh | 7589723 | 2000-05-29 14:26:00 +0000 | [diff] [blame] | 1180 | ** field is not used. |
| 1181 | */ |
| 1182 | struct ExprList { |
| 1183 | int nExpr; /* Number of expressions on the list */ |
drh | 4305d10 | 2003-07-30 12:34:12 +0000 | [diff] [blame] | 1184 | int nAlloc; /* Number of entries allocated below */ |
drh | 9d2985c | 2005-09-08 01:58:42 +0000 | [diff] [blame] | 1185 | int iECursor; /* VDBE Cursor associated with this ExprList */ |
drh | 6d4abfb | 2001-10-22 02:58:08 +0000 | [diff] [blame] | 1186 | struct ExprList_item { |
drh | 7589723 | 2000-05-29 14:26:00 +0000 | [diff] [blame] | 1187 | Expr *pExpr; /* The list of expressions */ |
| 1188 | char *zName; /* Token associated with this expression */ |
drh | 8e2ca02 | 2002-06-17 17:07:19 +0000 | [diff] [blame] | 1189 | u8 sortOrder; /* 1 for DESC or 0 for ASC */ |
| 1190 | u8 isAgg; /* True if this is an aggregate like count(*) */ |
| 1191 | u8 done; /* A flag to indicate when processing is finished */ |
drh | 7589723 | 2000-05-29 14:26:00 +0000 | [diff] [blame] | 1192 | } *a; /* One entry for each expression */ |
| 1193 | }; |
| 1194 | |
| 1195 | /* |
drh | ad3cab5 | 2002-05-24 02:04:32 +0000 | [diff] [blame] | 1196 | ** An instance of this structure can hold a simple list of identifiers, |
| 1197 | ** such as the list "a,b,c" in the following statements: |
| 1198 | ** |
| 1199 | ** INSERT INTO t(a,b,c) VALUES ...; |
| 1200 | ** CREATE INDEX idx ON t(a,b,c); |
| 1201 | ** CREATE TRIGGER trig BEFORE UPDATE ON t(a,b,c) ...; |
| 1202 | ** |
| 1203 | ** The IdList.a.idx field is used when the IdList represents the list of |
| 1204 | ** column names after a table name in an INSERT statement. In the statement |
| 1205 | ** |
| 1206 | ** INSERT INTO t(a,b,c) ... |
| 1207 | ** |
| 1208 | ** If "a" is the k-th column of table "t", then IdList.a[0].idx==k. |
drh | 7589723 | 2000-05-29 14:26:00 +0000 | [diff] [blame] | 1209 | */ |
| 1210 | struct IdList { |
drh | 6d4abfb | 2001-10-22 02:58:08 +0000 | [diff] [blame] | 1211 | struct IdList_item { |
drh | ad3cab5 | 2002-05-24 02:04:32 +0000 | [diff] [blame] | 1212 | char *zName; /* Name of the identifier */ |
drh | 967e8b7 | 2000-06-21 13:59:10 +0000 | [diff] [blame] | 1213 | int idx; /* Index in some Table.aCol[] of a column named zName */ |
drh | ad3cab5 | 2002-05-24 02:04:32 +0000 | [diff] [blame] | 1214 | } *a; |
drh | 1344989 | 2005-09-07 21:22:45 +0000 | [diff] [blame] | 1215 | int nId; /* Number of identifiers on the list */ |
| 1216 | int nAlloc; /* Number of entries allocated for a[] below */ |
drh | ad3cab5 | 2002-05-24 02:04:32 +0000 | [diff] [blame] | 1217 | }; |
| 1218 | |
| 1219 | /* |
drh | 5166986 | 2004-12-18 18:40:26 +0000 | [diff] [blame] | 1220 | ** The bitmask datatype defined below is used for various optimizations. |
drh | ca83ac5 | 2007-02-01 01:40:44 +0000 | [diff] [blame] | 1221 | ** |
| 1222 | ** Changing this from a 64-bit to a 32-bit type limits the number of |
| 1223 | ** tables in a join to 32 instead of 64. But it also reduces the size |
| 1224 | ** of the library by 738 bytes on ix86. |
drh | 5166986 | 2004-12-18 18:40:26 +0000 | [diff] [blame] | 1225 | */ |
drh | ca83ac5 | 2007-02-01 01:40:44 +0000 | [diff] [blame] | 1226 | typedef u64 Bitmask; |
drh | 5166986 | 2004-12-18 18:40:26 +0000 | [diff] [blame] | 1227 | |
| 1228 | /* |
drh | ad3cab5 | 2002-05-24 02:04:32 +0000 | [diff] [blame] | 1229 | ** The following structure describes the FROM clause of a SELECT statement. |
| 1230 | ** Each table or subquery in the FROM clause is a separate element of |
| 1231 | ** the SrcList.a[] array. |
drh | d24cc42 | 2003-03-27 12:51:24 +0000 | [diff] [blame] | 1232 | ** |
| 1233 | ** With the addition of multiple database support, the following structure |
| 1234 | ** can also be used to describe a particular table such as the table that |
| 1235 | ** is modified by an INSERT, DELETE, or UPDATE statement. In standard SQL, |
| 1236 | ** such a table must be a simple name: ID. But in SQLite, the table can |
| 1237 | ** now be identified by a database name, a dot, then the table name: ID.ID. |
drh | c49de5d | 2007-01-19 01:06:01 +0000 | [diff] [blame] | 1238 | ** |
| 1239 | ** The jointype starts out showing the join type between the current table |
| 1240 | ** and the next table on the list. The parser builds the list this way. |
| 1241 | ** But sqlite3SrcListShiftJoinType() later shifts the jointypes so that each |
| 1242 | ** jointype expresses the join between the table and the previous table. |
drh | ad3cab5 | 2002-05-24 02:04:32 +0000 | [diff] [blame] | 1243 | */ |
| 1244 | struct SrcList { |
drh | 939a16d | 2004-07-15 13:37:22 +0000 | [diff] [blame] | 1245 | i16 nSrc; /* Number of tables or subqueries in the FROM clause */ |
| 1246 | i16 nAlloc; /* Number of entries allocated in a[] below */ |
drh | ad3cab5 | 2002-05-24 02:04:32 +0000 | [diff] [blame] | 1247 | struct SrcList_item { |
drh | 113088e | 2003-03-20 01:16:58 +0000 | [diff] [blame] | 1248 | char *zDatabase; /* Name of database holding this table */ |
drh | ad3cab5 | 2002-05-24 02:04:32 +0000 | [diff] [blame] | 1249 | char *zName; /* Name of the table */ |
| 1250 | char *zAlias; /* The "B" part of a "A AS B" phrase. zName is the "A" */ |
drh | daffd0e | 2001-04-11 14:28:42 +0000 | [diff] [blame] | 1251 | Table *pTab; /* An SQL table corresponding to zName */ |
| 1252 | Select *pSelect; /* A SELECT statement used in place of a table name */ |
danielk1977 | 1787cca | 2006-02-10 07:07:14 +0000 | [diff] [blame] | 1253 | u8 isPopulated; /* Temporary table associated with SELECT is populated */ |
drh | c49de5d | 2007-01-19 01:06:01 +0000 | [diff] [blame] | 1254 | u8 jointype; /* Type of join between this able and the previous */ |
drh | e68fbe7 | 2007-02-13 12:49:24 +0000 | [diff] [blame] | 1255 | int iCursor; /* The VDBE cursor number used to access this table */ |
drh | ad3cab5 | 2002-05-24 02:04:32 +0000 | [diff] [blame] | 1256 | Expr *pOn; /* The ON clause of a join */ |
| 1257 | IdList *pUsing; /* The USING clause of a join */ |
drh | 5166986 | 2004-12-18 18:40:26 +0000 | [diff] [blame] | 1258 | Bitmask colUsed; /* Bit N (1<<N) set if column N or pTab is used */ |
drh | 113088e | 2003-03-20 01:16:58 +0000 | [diff] [blame] | 1259 | } a[1]; /* One entry for each identifier on the list */ |
drh | 7589723 | 2000-05-29 14:26:00 +0000 | [diff] [blame] | 1260 | }; |
| 1261 | |
| 1262 | /* |
drh | 01f3f25 | 2002-05-24 16:14:15 +0000 | [diff] [blame] | 1263 | ** Permitted values of the SrcList.a.jointype field |
| 1264 | */ |
| 1265 | #define JT_INNER 0x0001 /* Any kind of inner or cross join */ |
drh | 3dec223 | 2005-09-10 15:28:09 +0000 | [diff] [blame] | 1266 | #define JT_CROSS 0x0002 /* Explicit use of the CROSS keyword */ |
| 1267 | #define JT_NATURAL 0x0004 /* True for a "natural" join */ |
| 1268 | #define JT_LEFT 0x0008 /* Left outer join */ |
| 1269 | #define JT_RIGHT 0x0010 /* Right outer join */ |
| 1270 | #define JT_OUTER 0x0020 /* The "OUTER" keyword is present */ |
| 1271 | #define JT_ERROR 0x0040 /* unknown or unsupported join type */ |
drh | 01f3f25 | 2002-05-24 16:14:15 +0000 | [diff] [blame] | 1272 | |
| 1273 | /* |
drh | 6b56344 | 2001-11-07 16:48:26 +0000 | [diff] [blame] | 1274 | ** For each nested loop in a WHERE clause implementation, the WhereInfo |
| 1275 | ** structure contains a single instance of this structure. This structure |
| 1276 | ** is intended to be private the the where.c module and should not be |
| 1277 | ** access or modified by other modules. |
drh | 6d209d8 | 2006-06-27 01:54:26 +0000 | [diff] [blame] | 1278 | ** |
| 1279 | ** The pIdxInfo and pBestIdx fields are used to help pick the best |
| 1280 | ** index on a virtual table. The pIdxInfo pointer contains indexing |
| 1281 | ** information for the i-th table in the FROM clause before reordering. |
| 1282 | ** All the pIdxInfo pointers are freed by whereInfoFree() in where.c. |
| 1283 | ** The pBestIdx pointer is a copy of pIdxInfo for the i-th table after |
| 1284 | ** FROM clause ordering. This is a little confusing so I will repeat |
| 1285 | ** it in different words. WhereInfo.a[i].pIdxInfo is index information |
| 1286 | ** for WhereInfo.pTabList.a[i]. WhereInfo.a[i].pBestInfo is the |
| 1287 | ** index information for the i-th loop of the join. pBestInfo is always |
| 1288 | ** either NULL or a copy of some pIdxInfo. So for cleanup it is |
| 1289 | ** sufficient to free all of the pIdxInfo pointers. |
| 1290 | ** |
drh | 6b56344 | 2001-11-07 16:48:26 +0000 | [diff] [blame] | 1291 | */ |
| 1292 | struct WhereLevel { |
drh | 29dda4a | 2005-07-21 18:23:20 +0000 | [diff] [blame] | 1293 | int iFrom; /* Which entry in the FROM clause */ |
| 1294 | int flags; /* Flags associated with this level */ |
drh | 51147ba | 2005-07-23 22:59:55 +0000 | [diff] [blame] | 1295 | int iMem; /* First memory cell used by this level */ |
drh | 29dda4a | 2005-07-21 18:23:20 +0000 | [diff] [blame] | 1296 | int iLeftJoin; /* Memory cell used to implement LEFT OUTER JOIN */ |
| 1297 | Index *pIdx; /* Index used. NULL if no index */ |
| 1298 | int iTabCur; /* The VDBE cursor used to access the table */ |
| 1299 | int iIdxCur; /* The VDBE cursor used to acesss pIdx */ |
| 1300 | int brk; /* Jump here to break out of the loop */ |
drh | 72e8fa4 | 2007-03-28 14:30:06 +0000 | [diff] [blame] | 1301 | int nxt; /* Jump here to start the next IN combination */ |
drh | 29dda4a | 2005-07-21 18:23:20 +0000 | [diff] [blame] | 1302 | int cont; /* Jump here to continue with the next loop cycle */ |
| 1303 | int top; /* First instruction of interior of the loop */ |
| 1304 | int op, p1, p2; /* Opcode used to terminate the loop */ |
drh | 51147ba | 2005-07-23 22:59:55 +0000 | [diff] [blame] | 1305 | int nEq; /* Number of == or IN constraints on this loop */ |
drh | e23399f | 2005-07-22 00:31:39 +0000 | [diff] [blame] | 1306 | int nIn; /* Number of IN operators constraining this loop */ |
drh | 72e8fa4 | 2007-03-28 14:30:06 +0000 | [diff] [blame] | 1307 | struct InLoop { |
| 1308 | int iCur; /* The VDBE cursor used by this IN operator */ |
| 1309 | int topAddr; /* Top of the IN loop */ |
| 1310 | } *aInLoop; /* Information about each nested IN operator */ |
drh | 6d209d8 | 2006-06-27 01:54:26 +0000 | [diff] [blame] | 1311 | sqlite3_index_info *pBestIdx; /* Index information for this level */ |
| 1312 | |
| 1313 | /* The following field is really not part of the current level. But |
| 1314 | ** we need a place to cache index information for each table in the |
| 1315 | ** FROM clause and the WhereLevel structure is a convenient place. |
| 1316 | */ |
| 1317 | sqlite3_index_info *pIdxInfo; /* Index info for n-th source table */ |
drh | 6b56344 | 2001-11-07 16:48:26 +0000 | [diff] [blame] | 1318 | }; |
| 1319 | |
drh | 08c88eb | 2008-04-10 13:33:18 +0000 | [diff] [blame] | 1320 | /* |
| 1321 | ** Flags appropriate for the wflags parameter of sqlite3WhereBegin(). |
| 1322 | */ |
| 1323 | #define WHERE_ORDERBY_NORMAL 0 /* No-op */ |
| 1324 | #define WHERE_ORDERBY_MIN 1 /* ORDER BY processing for min() func */ |
| 1325 | #define WHERE_ORDERBY_MAX 2 /* ORDER BY processing for max() func */ |
| 1326 | #define WHERE_ONEPASS_DESIRED 4 /* Want to do one-pass UPDATE/DELETE */ |
danielk1977 | a9d1ccb | 2008-01-05 17:39:29 +0000 | [diff] [blame] | 1327 | |
drh | 6b56344 | 2001-11-07 16:48:26 +0000 | [diff] [blame] | 1328 | /* |
drh | 7589723 | 2000-05-29 14:26:00 +0000 | [diff] [blame] | 1329 | ** The WHERE clause processing routine has two halves. The |
| 1330 | ** first part does the start of the WHERE loop and the second |
| 1331 | ** half does the tail of the WHERE loop. An instance of |
| 1332 | ** this structure is returned by the first half and passed |
| 1333 | ** into the second half to give some continuity. |
| 1334 | */ |
| 1335 | struct WhereInfo { |
drh | 08c88eb | 2008-04-10 13:33:18 +0000 | [diff] [blame] | 1336 | Parse *pParse; /* Parsing and code generating context */ |
| 1337 | u8 okOnePass; /* Ok to use one-pass algorithm for UPDATE or DELETE */ |
drh | ad3cab5 | 2002-05-24 02:04:32 +0000 | [diff] [blame] | 1338 | SrcList *pTabList; /* List of tables in the join */ |
drh | 9012bcb | 2004-12-19 00:11:35 +0000 | [diff] [blame] | 1339 | int iTop; /* The very beginning of the WHERE loop */ |
drh | 19a775c | 2000-06-05 18:54:46 +0000 | [diff] [blame] | 1340 | int iContinue; /* Jump here to continue with next record */ |
| 1341 | int iBreak; /* Jump here to break out of the loop */ |
drh | 6b56344 | 2001-11-07 16:48:26 +0000 | [diff] [blame] | 1342 | int nLevel; /* Number of nested loop */ |
drh | 6d209d8 | 2006-06-27 01:54:26 +0000 | [diff] [blame] | 1343 | sqlite3_index_info **apInfo; /* Array of pointers to index info structures */ |
drh | 6b56344 | 2001-11-07 16:48:26 +0000 | [diff] [blame] | 1344 | WhereLevel a[1]; /* Information about each nest loop in the WHERE */ |
drh | 7589723 | 2000-05-29 14:26:00 +0000 | [diff] [blame] | 1345 | }; |
| 1346 | |
| 1347 | /* |
danielk1977 | b3bce66 | 2005-01-29 08:32:43 +0000 | [diff] [blame] | 1348 | ** A NameContext defines a context in which to resolve table and column |
| 1349 | ** names. The context consists of a list of tables (the pSrcList) field and |
| 1350 | ** a list of named expression (pEList). The named expression list may |
| 1351 | ** be NULL. The pSrc corresponds to the FROM clause of a SELECT or |
| 1352 | ** to the table being operated on by INSERT, UPDATE, or DELETE. The |
| 1353 | ** pEList corresponds to the result set of a SELECT and is NULL for |
| 1354 | ** other statements. |
| 1355 | ** |
| 1356 | ** NameContexts can be nested. When resolving names, the inner-most |
| 1357 | ** context is searched first. If no match is found, the next outer |
| 1358 | ** context is checked. If there is still no match, the next context |
| 1359 | ** is checked. This process continues until either a match is found |
| 1360 | ** or all contexts are check. When a match is found, the nRef member of |
| 1361 | ** the context containing the match is incremented. |
| 1362 | ** |
| 1363 | ** Each subquery gets a new NameContext. The pNext field points to the |
| 1364 | ** NameContext in the parent query. Thus the process of scanning the |
| 1365 | ** NameContext list corresponds to searching through successively outer |
| 1366 | ** subqueries looking for a match. |
| 1367 | */ |
| 1368 | struct NameContext { |
| 1369 | Parse *pParse; /* The parser */ |
| 1370 | SrcList *pSrcList; /* One or more tables used to resolve names */ |
| 1371 | ExprList *pEList; /* Optional list of named expressions */ |
| 1372 | int nRef; /* Number of names resolved by this context */ |
| 1373 | int nErr; /* Number of errors encountered while resolving names */ |
| 1374 | u8 allowAgg; /* Aggregate functions allowed here */ |
drh | 1344989 | 2005-09-07 21:22:45 +0000 | [diff] [blame] | 1375 | u8 hasAgg; /* True if aggregates are seen */ |
drh | 06f6541 | 2005-11-03 02:03:13 +0000 | [diff] [blame] | 1376 | u8 isCheck; /* True if resolving names in a CHECK constraint */ |
danielk1977 | b3bce66 | 2005-01-29 08:32:43 +0000 | [diff] [blame] | 1377 | int nDepth; /* Depth of subquery recursion. 1 for no recursion */ |
drh | 1344989 | 2005-09-07 21:22:45 +0000 | [diff] [blame] | 1378 | AggInfo *pAggInfo; /* Information about aggregates at this level */ |
danielk1977 | b3bce66 | 2005-01-29 08:32:43 +0000 | [diff] [blame] | 1379 | NameContext *pNext; /* Next outer name context. NULL for outermost */ |
| 1380 | }; |
| 1381 | |
| 1382 | /* |
drh | 9bb61fe | 2000-06-05 16:01:39 +0000 | [diff] [blame] | 1383 | ** An instance of the following structure contains all information |
| 1384 | ** needed to generate code for a single SELECT statement. |
drh | a76b5df | 2002-02-23 02:32:10 +0000 | [diff] [blame] | 1385 | ** |
drh | d11d382 | 2002-06-21 23:01:49 +0000 | [diff] [blame] | 1386 | ** nLimit is set to -1 if there is no LIMIT clause. nOffset is set to 0. |
| 1387 | ** If there is a LIMIT clause, the parser sets nLimit to the value of the |
| 1388 | ** limit and nOffset to the value of the offset (or 0 if there is not |
| 1389 | ** offset). But later on, nLimit and nOffset become the memory locations |
| 1390 | ** in the VDBE that record the limit and offset counters. |
drh | 0342b1f | 2005-09-01 03:07:44 +0000 | [diff] [blame] | 1391 | ** |
drh | b9bb7c1 | 2006-06-11 23:41:55 +0000 | [diff] [blame] | 1392 | ** addrOpenEphm[] entries contain the address of OP_OpenEphemeral opcodes. |
drh | 0342b1f | 2005-09-01 03:07:44 +0000 | [diff] [blame] | 1393 | ** These addresses must be stored so that we can go back and fill in |
drh | 66a5167 | 2008-01-03 00:01:23 +0000 | [diff] [blame] | 1394 | ** the P4_KEYINFO and P2 parameters later. Neither the KeyInfo nor |
drh | 0342b1f | 2005-09-01 03:07:44 +0000 | [diff] [blame] | 1395 | ** the number of columns in P2 can be computed at the same time |
drh | b9bb7c1 | 2006-06-11 23:41:55 +0000 | [diff] [blame] | 1396 | ** as the OP_OpenEphm instruction is coded because not |
drh | 0342b1f | 2005-09-01 03:07:44 +0000 | [diff] [blame] | 1397 | ** enough information about the compound query is known at that point. |
drh | b9bb7c1 | 2006-06-11 23:41:55 +0000 | [diff] [blame] | 1398 | ** The KeyInfo for addrOpenTran[0] and [1] contains collating sequences |
| 1399 | ** for the result set. The KeyInfo for addrOpenTran[2] contains collating |
drh | 0342b1f | 2005-09-01 03:07:44 +0000 | [diff] [blame] | 1400 | ** sequences for the ORDER BY clause. |
drh | 9bb61fe | 2000-06-05 16:01:39 +0000 | [diff] [blame] | 1401 | */ |
| 1402 | struct Select { |
drh | 9bb61fe | 2000-06-05 16:01:39 +0000 | [diff] [blame] | 1403 | ExprList *pEList; /* The fields of the result */ |
drh | 7b58dae | 2003-07-20 01:16:46 +0000 | [diff] [blame] | 1404 | u8 op; /* One of: TK_UNION TK_ALL TK_INTERSECT TK_EXCEPT */ |
| 1405 | u8 isDistinct; /* True if the DISTINCT keyword is present */ |
drh | 0342b1f | 2005-09-01 03:07:44 +0000 | [diff] [blame] | 1406 | u8 isResolved; /* True once sqlite3SelectResolve() has run. */ |
| 1407 | u8 isAgg; /* True if this is an aggregate query */ |
drh | b9bb7c1 | 2006-06-11 23:41:55 +0000 | [diff] [blame] | 1408 | u8 usesEphm; /* True if uses an OpenEphemeral opcode */ |
drh | 4b14b4d | 2005-09-19 17:35:53 +0000 | [diff] [blame] | 1409 | u8 disallowOrderBy; /* Do not allow an ORDER BY to be attached if TRUE */ |
drh | 6c1426f | 2007-04-12 03:54:38 +0000 | [diff] [blame] | 1410 | char affinity; /* MakeRecord with this affinity for SRT_Set */ |
drh | ad3cab5 | 2002-05-24 02:04:32 +0000 | [diff] [blame] | 1411 | SrcList *pSrc; /* The FROM clause */ |
drh | 9bb61fe | 2000-06-05 16:01:39 +0000 | [diff] [blame] | 1412 | Expr *pWhere; /* The WHERE clause */ |
| 1413 | ExprList *pGroupBy; /* The GROUP BY clause */ |
| 1414 | Expr *pHaving; /* The HAVING clause */ |
| 1415 | ExprList *pOrderBy; /* The ORDER BY clause */ |
drh | 967e8b7 | 2000-06-21 13:59:10 +0000 | [diff] [blame] | 1416 | Select *pPrior; /* Prior select in a compound select statement */ |
drh | 1e28129 | 2007-12-13 03:45:07 +0000 | [diff] [blame] | 1417 | Select *pNext; /* Next select to the left in a compound */ |
drh | 0342b1f | 2005-09-01 03:07:44 +0000 | [diff] [blame] | 1418 | Select *pRightmost; /* Right-most select in a compound select statement */ |
danielk1977 | a2dc3b1 | 2005-02-05 12:48:48 +0000 | [diff] [blame] | 1419 | Expr *pLimit; /* LIMIT expression. NULL means not used. */ |
| 1420 | Expr *pOffset; /* OFFSET expression. NULL means not used. */ |
drh | 7b58dae | 2003-07-20 01:16:46 +0000 | [diff] [blame] | 1421 | int iLimit, iOffset; /* Memory registers holding LIMIT & OFFSET counters */ |
drh | b9bb7c1 | 2006-06-11 23:41:55 +0000 | [diff] [blame] | 1422 | int addrOpenEphm[3]; /* OP_OpenEphem opcodes related to this select */ |
drh | 9bb61fe | 2000-06-05 16:01:39 +0000 | [diff] [blame] | 1423 | }; |
| 1424 | |
| 1425 | /* |
drh | fef5208 | 2000-06-06 01:50:43 +0000 | [diff] [blame] | 1426 | ** The results of a select can be distributed in several ways. |
| 1427 | */ |
drh | 1344989 | 2005-09-07 21:22:45 +0000 | [diff] [blame] | 1428 | #define SRT_Union 1 /* Store result as keys in an index */ |
| 1429 | #define SRT_Except 2 /* Remove result from a UNION index */ |
danielk1977 | 9ed1dfa | 2008-01-02 17:11:14 +0000 | [diff] [blame] | 1430 | #define SRT_Exists 3 /* Store 1 if the result is not empty */ |
| 1431 | #define SRT_Discard 4 /* Do not save the results anywhere */ |
drh | fef5208 | 2000-06-06 01:50:43 +0000 | [diff] [blame] | 1432 | |
drh | 1344989 | 2005-09-07 21:22:45 +0000 | [diff] [blame] | 1433 | /* The ORDER BY clause is ignored for all of the above */ |
danielk1977 | 6c8c8ce | 2008-01-02 16:27:09 +0000 | [diff] [blame] | 1434 | #define IgnorableOrderby(X) ((X->eDest)<=SRT_Discard) |
drh | 1344989 | 2005-09-07 21:22:45 +0000 | [diff] [blame] | 1435 | |
danielk1977 | 9ed1dfa | 2008-01-02 17:11:14 +0000 | [diff] [blame] | 1436 | #define SRT_Callback 5 /* Invoke a callback with each row of result */ |
| 1437 | #define SRT_Mem 6 /* Store result in a memory cell */ |
| 1438 | #define SRT_Set 7 /* Store non-null results as keys in an index */ |
| 1439 | #define SRT_Table 8 /* Store result as data with an automatic rowid */ |
| 1440 | #define SRT_EphemTab 9 /* Create transient tab and store like SRT_Table */ |
| 1441 | #define SRT_Subroutine 10 /* Call a subroutine to handle results */ |
drh | 2282792 | 2000-06-06 17:27:05 +0000 | [diff] [blame] | 1442 | |
| 1443 | /* |
danielk1977 | 6c8c8ce | 2008-01-02 16:27:09 +0000 | [diff] [blame] | 1444 | ** A structure used to customize the behaviour of sqlite3Select(). See |
| 1445 | ** comments above sqlite3Select() for details. |
| 1446 | */ |
| 1447 | typedef struct SelectDest SelectDest; |
| 1448 | struct SelectDest { |
drh | 477df4b | 2008-01-05 18:48:24 +0000 | [diff] [blame] | 1449 | u8 eDest; /* How to dispose of the results */ |
| 1450 | u8 affinity; /* Affinity used when eDest==SRT_Set */ |
danielk1977 | 6c8c8ce | 2008-01-02 16:27:09 +0000 | [diff] [blame] | 1451 | int iParm; /* A parameter used by the eDest disposal method */ |
drh | 2eb9537 | 2008-06-06 15:04:36 +0000 | [diff] [blame] | 1452 | int regReturn; /* Return address register for SRT_Subroutine */ |
drh | 1013c93 | 2008-01-06 00:25:21 +0000 | [diff] [blame] | 1453 | int iMem; /* Base register where results are written */ |
drh | ad27e76 | 2008-03-26 12:46:23 +0000 | [diff] [blame] | 1454 | int nMem; /* Number of registers allocated */ |
danielk1977 | 6c8c8ce | 2008-01-02 16:27:09 +0000 | [diff] [blame] | 1455 | }; |
| 1456 | |
| 1457 | /* |
drh | f57b339 | 2001-10-08 13:22:32 +0000 | [diff] [blame] | 1458 | ** An SQL parser context. A copy of this structure is passed through |
| 1459 | ** the parser and down into all the parser action routine in order to |
| 1460 | ** carry around information that is global to the entire parse. |
drh | f197484 | 2004-11-05 03:56:00 +0000 | [diff] [blame] | 1461 | ** |
| 1462 | ** The structure is divided into two parts. When the parser and code |
| 1463 | ** generate call themselves recursively, the first part of the structure |
| 1464 | ** is constant but the second part is reset at the beginning and end of |
| 1465 | ** each recursion. |
danielk1977 | c00da10 | 2006-01-07 13:21:04 +0000 | [diff] [blame] | 1466 | ** |
| 1467 | ** The nTableLock and aTableLock variables are only used if the shared-cache |
| 1468 | ** feature is enabled (if sqlite3Tsd()->useSharedData is true). They are |
| 1469 | ** used to store the set of table-locks required by the statement being |
| 1470 | ** compiled. Function sqlite3TableLock() is used to add entries to the |
| 1471 | ** list. |
drh | 7589723 | 2000-05-29 14:26:00 +0000 | [diff] [blame] | 1472 | */ |
| 1473 | struct Parse { |
drh | 9bb575f | 2004-09-06 17:24:11 +0000 | [diff] [blame] | 1474 | sqlite3 *db; /* The main database structure */ |
drh | 4c50439 | 2000-10-16 22:06:40 +0000 | [diff] [blame] | 1475 | int rc; /* Return code from execution */ |
drh | 7589723 | 2000-05-29 14:26:00 +0000 | [diff] [blame] | 1476 | char *zErrMsg; /* An error message */ |
drh | 7589723 | 2000-05-29 14:26:00 +0000 | [diff] [blame] | 1477 | Vdbe *pVdbe; /* An engine for executing database bytecode */ |
drh | 836faa4 | 2003-01-11 13:30:57 +0000 | [diff] [blame] | 1478 | u8 colNamesSet; /* TRUE after OP_ColumnName has been issued to pVdbe */ |
drh | e0bc404 | 2002-06-25 01:09:11 +0000 | [diff] [blame] | 1479 | u8 nameClash; /* A permanent table name clashes with temp table name */ |
drh | a6ecd33 | 2004-06-10 00:29:09 +0000 | [diff] [blame] | 1480 | u8 checkSchema; /* Causes schema cookie check after an error */ |
drh | 205f48e | 2004-11-05 00:43:11 +0000 | [diff] [blame] | 1481 | u8 nested; /* Number of nested calls to the parser/code generator */ |
drh | 7e326c0 | 2007-05-15 16:51:37 +0000 | [diff] [blame] | 1482 | u8 parseError; /* True after a parsing error. Ticket #1794 */ |
drh | 892d317 | 2008-01-10 03:46:36 +0000 | [diff] [blame] | 1483 | u8 nTempReg; /* Number of temporary registers in aTempReg[] */ |
drh | 2dcef11 | 2008-01-12 19:03:48 +0000 | [diff] [blame] | 1484 | u8 nTempInUse; /* Number of aTempReg[] currently checked out */ |
drh | 892d317 | 2008-01-10 03:46:36 +0000 | [diff] [blame] | 1485 | int aTempReg[8]; /* Holding area for temporary registers */ |
| 1486 | int nRangeReg; /* Size of the temporary register block */ |
| 1487 | int iRangeReg; /* First register in temporary register block */ |
drh | 7589723 | 2000-05-29 14:26:00 +0000 | [diff] [blame] | 1488 | int nErr; /* Number of errors seen */ |
drh | 832508b | 2002-03-02 17:04:07 +0000 | [diff] [blame] | 1489 | int nTab; /* Number of previously allocated VDBE cursors */ |
drh | 19a775c | 2000-06-05 18:54:46 +0000 | [diff] [blame] | 1490 | int nMem; /* Number of memory cells used so far */ |
drh | fef5208 | 2000-06-06 01:50:43 +0000 | [diff] [blame] | 1491 | int nSet; /* Number of sets used so far */ |
drh | aa9b896 | 2008-01-08 02:57:55 +0000 | [diff] [blame] | 1492 | int ckBase; /* Base register of data during check constraints */ |
drh | e55cbd7 | 2008-03-31 23:48:03 +0000 | [diff] [blame] | 1493 | int disableColCache; /* True to disable adding to column cache */ |
| 1494 | int nColCache; /* Number of entries in the column cache */ |
| 1495 | int iColCache; /* Next entry of the cache to replace */ |
drh | 2f7794c | 2008-04-01 03:27:39 +0000 | [diff] [blame] | 1496 | struct yColCache { |
drh | e55cbd7 | 2008-03-31 23:48:03 +0000 | [diff] [blame] | 1497 | int iTable; /* Table cursor number */ |
| 1498 | int iColumn; /* Table column number */ |
drh | da250ea | 2008-04-01 05:07:14 +0000 | [diff] [blame] | 1499 | char affChange; /* True if this register has had an affinity change */ |
drh | e55cbd7 | 2008-03-31 23:48:03 +0000 | [diff] [blame] | 1500 | int iReg; /* Register holding value of this column */ |
| 1501 | } aColCache[10]; /* One for each valid column cache entry */ |
drh | 8024205 | 2004-06-09 00:48:12 +0000 | [diff] [blame] | 1502 | u32 writeMask; /* Start a write transaction on these databases */ |
drh | fcd35c7 | 2005-05-21 02:48:08 +0000 | [diff] [blame] | 1503 | u32 cookieMask; /* Bitmask of schema verified databases */ |
| 1504 | int cookieGoto; /* Address of OP_Goto to cookie verifier subroutine */ |
drh | c797d4d | 2007-05-08 01:08:49 +0000 | [diff] [blame] | 1505 | int cookieValue[SQLITE_MAX_ATTACHED+2]; /* Values of cookies to verify */ |
danielk1977 | c00da10 | 2006-01-07 13:21:04 +0000 | [diff] [blame] | 1506 | #ifndef SQLITE_OMIT_SHARED_CACHE |
| 1507 | int nTableLock; /* Number of locks in aTableLock */ |
| 1508 | TableLock *aTableLock; /* Required table locks for shared-cache mode */ |
| 1509 | #endif |
danielk1977 | cac336a | 2008-03-08 06:16:29 +0000 | [diff] [blame] | 1510 | int regRowid; /* Register holding rowid of CREATE TABLE entry */ |
| 1511 | int regRoot; /* Register holding root page number for new objects */ |
drh | f197484 | 2004-11-05 03:56:00 +0000 | [diff] [blame] | 1512 | |
| 1513 | /* Above is constant between recursions. Below is reset before and after |
| 1514 | ** each recursion */ |
| 1515 | |
| 1516 | int nVar; /* Number of '?' variables seen in the SQL so far */ |
| 1517 | int nVarExpr; /* Number of used slots in apVarExpr[] */ |
| 1518 | int nVarExprAlloc; /* Number of allocated slots in apVarExpr[] */ |
| 1519 | Expr **apVarExpr; /* Pointers to :aaa and $aaaa wildcard expressions */ |
| 1520 | u8 explain; /* True if the EXPLAIN flag is found on the query */ |
drh | f197484 | 2004-11-05 03:56:00 +0000 | [diff] [blame] | 1521 | Token sErrToken; /* The token at which the error occurred */ |
| 1522 | Token sNameToken; /* Token with unqualified schema object name */ |
| 1523 | Token sLastToken; /* The last token parsed */ |
| 1524 | const char *zSql; /* All SQL text */ |
| 1525 | const char *zTail; /* All SQL text past the last semicolon parsed */ |
| 1526 | Table *pNewTable; /* A table being constructed by CREATE TABLE */ |
| 1527 | Trigger *pNewTrigger; /* Trigger under construct by a CREATE TRIGGER */ |
| 1528 | TriggerStack *trigStack; /* Trigger actions being coded */ |
| 1529 | const char *zAuthContext; /* The 6th parameter to db->xAuth callbacks */ |
drh | b9bb7c1 | 2006-06-11 23:41:55 +0000 | [diff] [blame] | 1530 | #ifndef SQLITE_OMIT_VIRTUALTABLE |
danielk1977 | 33b3933 | 2006-06-24 08:51:05 +0000 | [diff] [blame] | 1531 | Token sArg; /* Complete text of a module argument */ |
danielk1977 | f9e7dda | 2006-06-16 16:08:53 +0000 | [diff] [blame] | 1532 | u8 declareVtab; /* True if inside sqlite3_declare_vtab() */ |
drh | 4f3dd15 | 2008-04-28 18:46:43 +0000 | [diff] [blame] | 1533 | int nVtabLock; /* Number of virtual tables to lock */ |
| 1534 | Table **apVtabLock; /* Pointer to virtual tables needing locking */ |
drh | b9bb7c1 | 2006-06-11 23:41:55 +0000 | [diff] [blame] | 1535 | #endif |
danielk1977 | fc97606 | 2007-05-10 10:46:56 +0000 | [diff] [blame] | 1536 | int nHeight; /* Expression tree height of current sub-select */ |
drh | 7589723 | 2000-05-29 14:26:00 +0000 | [diff] [blame] | 1537 | }; |
| 1538 | |
danielk1977 | 7e6ebfb | 2006-06-12 11:24:37 +0000 | [diff] [blame] | 1539 | #ifdef SQLITE_OMIT_VIRTUALTABLE |
| 1540 | #define IN_DECLARE_VTAB 0 |
| 1541 | #else |
| 1542 | #define IN_DECLARE_VTAB (pParse->declareVtab) |
| 1543 | #endif |
| 1544 | |
danielk1977 | d99bc93 | 2002-05-16 00:13:12 +0000 | [diff] [blame] | 1545 | /* |
drh | 85e2096 | 2003-04-25 17:52:11 +0000 | [diff] [blame] | 1546 | ** An instance of the following structure can be declared on a stack and used |
| 1547 | ** to save the Parse.zAuthContext value so that it can be restored later. |
| 1548 | */ |
| 1549 | struct AuthContext { |
| 1550 | const char *zAuthContext; /* Put saved Parse.zAuthContext here */ |
| 1551 | Parse *pParse; /* The Parse structure */ |
| 1552 | }; |
| 1553 | |
| 1554 | /* |
drh | f0863fe | 2005-06-12 21:35:51 +0000 | [diff] [blame] | 1555 | ** Bitfield flags for P2 value in OP_Insert and OP_Delete |
rdc | b0c374f | 2004-02-20 22:53:38 +0000 | [diff] [blame] | 1556 | */ |
| 1557 | #define OPFLAG_NCHANGE 1 /* Set to update db->nChange */ |
| 1558 | #define OPFLAG_LASTROWID 2 /* Set to update db->lastRowid */ |
danielk1977 | 94eb6a1 | 2005-12-15 15:22:08 +0000 | [diff] [blame] | 1559 | #define OPFLAG_ISUPDATE 4 /* This OP_Insert is an sql UPDATE */ |
drh | e4d9081 | 2007-03-29 05:51:49 +0000 | [diff] [blame] | 1560 | #define OPFLAG_APPEND 8 /* This is likely to be an append */ |
rdc | b0c374f | 2004-02-20 22:53:38 +0000 | [diff] [blame] | 1561 | |
| 1562 | /* |
danielk1977 | d99bc93 | 2002-05-16 00:13:12 +0000 | [diff] [blame] | 1563 | * Each trigger present in the database schema is stored as an instance of |
| 1564 | * struct Trigger. |
| 1565 | * |
| 1566 | * Pointers to instances of struct Trigger are stored in two ways. |
drh | 9bb575f | 2004-09-06 17:24:11 +0000 | [diff] [blame] | 1567 | * 1. In the "trigHash" hash table (part of the sqlite3* that represents the |
danielk1977 | d99bc93 | 2002-05-16 00:13:12 +0000 | [diff] [blame] | 1568 | * database). This allows Trigger structures to be retrieved by name. |
| 1569 | * 2. All triggers associated with a single table form a linked list, using the |
drh | ad3cab5 | 2002-05-24 02:04:32 +0000 | [diff] [blame] | 1570 | * pNext member of struct Trigger. A pointer to the first element of the |
| 1571 | * linked list is stored as the "pTrigger" member of the associated |
| 1572 | * struct Table. |
danielk1977 | d99bc93 | 2002-05-16 00:13:12 +0000 | [diff] [blame] | 1573 | * |
drh | ad3cab5 | 2002-05-24 02:04:32 +0000 | [diff] [blame] | 1574 | * The "step_list" member points to the first element of a linked list |
| 1575 | * containing the SQL statements specified as the trigger program. |
danielk1977 | d99bc93 | 2002-05-16 00:13:12 +0000 | [diff] [blame] | 1576 | */ |
danielk1977 | c3f9bad | 2002-05-15 08:30:12 +0000 | [diff] [blame] | 1577 | struct Trigger { |
drh | dc37945 | 2002-05-15 12:45:43 +0000 | [diff] [blame] | 1578 | char *name; /* The name of the trigger */ |
| 1579 | char *table; /* The table or view to which the trigger applies */ |
drh | f0f258b | 2003-04-21 18:48:45 +0000 | [diff] [blame] | 1580 | u8 op; /* One of TK_DELETE, TK_UPDATE, TK_INSERT */ |
drh | dca7684 | 2004-12-07 14:06:13 +0000 | [diff] [blame] | 1581 | u8 tr_tm; /* One of TRIGGER_BEFORE, TRIGGER_AFTER */ |
drh | dc37945 | 2002-05-15 12:45:43 +0000 | [diff] [blame] | 1582 | Expr *pWhen; /* The WHEN clause of the expresion (may be NULL) */ |
| 1583 | IdList *pColumns; /* If this is an UPDATE OF <column-list> trigger, |
danielk1977 | d99bc93 | 2002-05-16 00:13:12 +0000 | [diff] [blame] | 1584 | the <column-list> is stored here */ |
drh | 4312db5 | 2003-06-03 01:47:11 +0000 | [diff] [blame] | 1585 | Token nameToken; /* Token containing zName. Use during parsing only */ |
danielk1977 | e501b89 | 2006-01-09 06:29:47 +0000 | [diff] [blame] | 1586 | Schema *pSchema; /* Schema containing the trigger */ |
| 1587 | Schema *pTabSchema; /* Schema containing the table */ |
drh | dc37945 | 2002-05-15 12:45:43 +0000 | [diff] [blame] | 1588 | TriggerStep *step_list; /* Link list of trigger program steps */ |
drh | dc37945 | 2002-05-15 12:45:43 +0000 | [diff] [blame] | 1589 | Trigger *pNext; /* Next trigger associated with the table */ |
danielk1977 | c3f9bad | 2002-05-15 08:30:12 +0000 | [diff] [blame] | 1590 | }; |
| 1591 | |
danielk1977 | d99bc93 | 2002-05-16 00:13:12 +0000 | [diff] [blame] | 1592 | /* |
drh | dca7684 | 2004-12-07 14:06:13 +0000 | [diff] [blame] | 1593 | ** A trigger is either a BEFORE or an AFTER trigger. The following constants |
| 1594 | ** determine which. |
| 1595 | ** |
| 1596 | ** If there are multiple triggers, you might of some BEFORE and some AFTER. |
| 1597 | ** In that cases, the constants below can be ORed together. |
| 1598 | */ |
| 1599 | #define TRIGGER_BEFORE 1 |
| 1600 | #define TRIGGER_AFTER 2 |
| 1601 | |
| 1602 | /* |
danielk1977 | d99bc93 | 2002-05-16 00:13:12 +0000 | [diff] [blame] | 1603 | * An instance of struct TriggerStep is used to store a single SQL statement |
| 1604 | * that is a part of a trigger-program. |
| 1605 | * |
| 1606 | * Instances of struct TriggerStep are stored in a singly linked list (linked |
| 1607 | * using the "pNext" member) referenced by the "step_list" member of the |
| 1608 | * associated struct Trigger instance. The first element of the linked list is |
| 1609 | * the first step of the trigger-program. |
| 1610 | * |
| 1611 | * The "op" member indicates whether this is a "DELETE", "INSERT", "UPDATE" or |
| 1612 | * "SELECT" statement. The meanings of the other members is determined by the |
| 1613 | * value of "op" as follows: |
| 1614 | * |
| 1615 | * (op == TK_INSERT) |
| 1616 | * orconf -> stores the ON CONFLICT algorithm |
| 1617 | * pSelect -> If this is an INSERT INTO ... SELECT ... statement, then |
| 1618 | * this stores a pointer to the SELECT statement. Otherwise NULL. |
| 1619 | * target -> A token holding the name of the table to insert into. |
| 1620 | * pExprList -> If this is an INSERT INTO ... VALUES ... statement, then |
| 1621 | * this stores values to be inserted. Otherwise NULL. |
| 1622 | * pIdList -> If this is an INSERT INTO ... (<column-names>) VALUES ... |
drh | ad3cab5 | 2002-05-24 02:04:32 +0000 | [diff] [blame] | 1623 | * statement, then this stores the column-names to be |
| 1624 | * inserted into. |
danielk1977 | d99bc93 | 2002-05-16 00:13:12 +0000 | [diff] [blame] | 1625 | * |
| 1626 | * (op == TK_DELETE) |
| 1627 | * target -> A token holding the name of the table to delete from. |
| 1628 | * pWhere -> The WHERE clause of the DELETE statement if one is specified. |
| 1629 | * Otherwise NULL. |
| 1630 | * |
| 1631 | * (op == TK_UPDATE) |
| 1632 | * target -> A token holding the name of the table to update rows of. |
| 1633 | * pWhere -> The WHERE clause of the UPDATE statement if one is specified. |
| 1634 | * Otherwise NULL. |
| 1635 | * pExprList -> A list of the columns to update and the expressions to update |
danielk1977 | 4adee20 | 2004-05-08 08:23:19 +0000 | [diff] [blame] | 1636 | * them to. See sqlite3Update() documentation of "pChanges" |
drh | ad3cab5 | 2002-05-24 02:04:32 +0000 | [diff] [blame] | 1637 | * argument. |
danielk1977 | d99bc93 | 2002-05-16 00:13:12 +0000 | [diff] [blame] | 1638 | * |
| 1639 | */ |
| 1640 | struct TriggerStep { |
| 1641 | int op; /* One of TK_DELETE, TK_UPDATE, TK_INSERT, TK_SELECT */ |
| 1642 | int orconf; /* OE_Rollback etc. */ |
drh | a69d916 | 2003-04-17 22:57:53 +0000 | [diff] [blame] | 1643 | Trigger *pTrig; /* The trigger that this step is a part of */ |
danielk1977 | c3f9bad | 2002-05-15 08:30:12 +0000 | [diff] [blame] | 1644 | |
danielk1977 | d99bc93 | 2002-05-16 00:13:12 +0000 | [diff] [blame] | 1645 | Select *pSelect; /* Valid for SELECT and sometimes |
drh | fd131da | 2007-08-07 17:13:03 +0000 | [diff] [blame] | 1646 | INSERT steps (when pExprList == 0) */ |
danielk1977 | d99bc93 | 2002-05-16 00:13:12 +0000 | [diff] [blame] | 1647 | Token target; /* Valid for DELETE, UPDATE, INSERT steps */ |
| 1648 | Expr *pWhere; /* Valid for DELETE, UPDATE steps */ |
| 1649 | ExprList *pExprList; /* Valid for UPDATE statements and sometimes |
drh | fd131da | 2007-08-07 17:13:03 +0000 | [diff] [blame] | 1650 | INSERT steps (when pSelect == 0) */ |
danielk1977 | d99bc93 | 2002-05-16 00:13:12 +0000 | [diff] [blame] | 1651 | IdList *pIdList; /* Valid for INSERT statements only */ |
drh | 187e4c6 | 2006-02-27 22:22:27 +0000 | [diff] [blame] | 1652 | TriggerStep *pNext; /* Next in the link-list */ |
| 1653 | TriggerStep *pLast; /* Last element in link-list. Valid for 1st elem only */ |
danielk1977 | d99bc93 | 2002-05-16 00:13:12 +0000 | [diff] [blame] | 1654 | }; |
| 1655 | |
| 1656 | /* |
| 1657 | * An instance of struct TriggerStack stores information required during code |
| 1658 | * generation of a single trigger program. While the trigger program is being |
| 1659 | * coded, its associated TriggerStack instance is pointed to by the |
| 1660 | * "pTriggerStack" member of the Parse structure. |
| 1661 | * |
| 1662 | * The pTab member points to the table that triggers are being coded on. The |
| 1663 | * newIdx member contains the index of the vdbe cursor that points at the temp |
| 1664 | * table that stores the new.* references. If new.* references are not valid |
| 1665 | * for the trigger being coded (for example an ON DELETE trigger), then newIdx |
| 1666 | * is set to -1. The oldIdx member is analogous to newIdx, for old.* references. |
| 1667 | * |
| 1668 | * The ON CONFLICT policy to be used for the trigger program steps is stored |
| 1669 | * as the orconf member. If this is OE_Default, then the ON CONFLICT clause |
| 1670 | * specified for individual triggers steps is used. |
| 1671 | * |
| 1672 | * struct TriggerStack has a "pNext" member, to allow linked lists to be |
| 1673 | * constructed. When coding nested triggers (triggers fired by other triggers) |
| 1674 | * each nested trigger stores its parent trigger's TriggerStack as the "pNext" |
| 1675 | * pointer. Once the nested trigger has been coded, the pNext value is restored |
| 1676 | * to the pTriggerStack member of the Parse stucture and coding of the parent |
| 1677 | * trigger continues. |
| 1678 | * |
| 1679 | * Before a nested trigger is coded, the linked list pointed to by the |
| 1680 | * pTriggerStack is scanned to ensure that the trigger is not about to be coded |
| 1681 | * recursively. If this condition is detected, the nested trigger is not coded. |
| 1682 | */ |
| 1683 | struct TriggerStack { |
| 1684 | Table *pTab; /* Table that triggers are currently being coded on */ |
| 1685 | int newIdx; /* Index of vdbe cursor to "new" temp table */ |
| 1686 | int oldIdx; /* Index of vdbe cursor to "old" temp table */ |
danielk1977 | 8f2c54e | 2008-01-01 19:02:09 +0000 | [diff] [blame] | 1687 | u32 newColMask; |
| 1688 | u32 oldColMask; |
danielk1977 | d99bc93 | 2002-05-16 00:13:12 +0000 | [diff] [blame] | 1689 | int orconf; /* Current orconf policy */ |
danielk1977 | 6f34903 | 2002-06-11 02:25:40 +0000 | [diff] [blame] | 1690 | int ignoreJump; /* where to jump to for a RAISE(IGNORE) */ |
drh | e22a334 | 2003-04-22 20:30:37 +0000 | [diff] [blame] | 1691 | Trigger *pTrigger; /* The trigger currently being coded */ |
| 1692 | TriggerStack *pNext; /* Next trigger down on the trigger stack */ |
danielk1977 | d99bc93 | 2002-05-16 00:13:12 +0000 | [diff] [blame] | 1693 | }; |
| 1694 | |
| 1695 | /* |
drh | f26e09c | 2003-05-31 16:21:12 +0000 | [diff] [blame] | 1696 | ** The following structure contains information used by the sqliteFix... |
| 1697 | ** routines as they walk the parse tree to make database references |
| 1698 | ** explicit. |
| 1699 | */ |
| 1700 | typedef struct DbFixer DbFixer; |
| 1701 | struct DbFixer { |
| 1702 | Parse *pParse; /* The parsing context. Error messages written here */ |
| 1703 | const char *zDb; /* Make sure all objects are contained in this database */ |
| 1704 | const char *zType; /* Type of the container - used for error messages */ |
| 1705 | const Token *pName; /* Name of the container - used for error messages */ |
| 1706 | }; |
| 1707 | |
| 1708 | /* |
drh | ade8648 | 2007-11-28 22:36:40 +0000 | [diff] [blame] | 1709 | ** An objected used to accumulate the text of a string where we |
| 1710 | ** do not necessarily know how big the string will be in the end. |
| 1711 | */ |
| 1712 | struct StrAccum { |
| 1713 | char *zBase; /* A base allocation. Not from malloc. */ |
| 1714 | char *zText; /* The string collected so far */ |
| 1715 | int nChar; /* Length of the string so far */ |
| 1716 | int nAlloc; /* Amount of space allocated in zText */ |
drh | bb4957f | 2008-03-20 14:03:29 +0000 | [diff] [blame] | 1717 | int mxAlloc; /* Maximum allowed string length */ |
drh | ade8648 | 2007-11-28 22:36:40 +0000 | [diff] [blame] | 1718 | u8 mallocFailed; /* Becomes true if any memory allocation fails */ |
| 1719 | u8 useMalloc; /* True if zText is enlargable using realloc */ |
| 1720 | u8 tooBig; /* Becomes true if string size exceeds limits */ |
| 1721 | }; |
| 1722 | |
| 1723 | /* |
drh | 234c39d | 2004-07-24 03:30:47 +0000 | [diff] [blame] | 1724 | ** A pointer to this structure is used to communicate information |
| 1725 | ** from sqlite3Init and OP_ParseSchema into the sqlite3InitCallback. |
| 1726 | */ |
| 1727 | typedef struct { |
drh | 9bb575f | 2004-09-06 17:24:11 +0000 | [diff] [blame] | 1728 | sqlite3 *db; /* The database being initialized */ |
drh | ece3c72 | 2006-09-23 20:36:01 +0000 | [diff] [blame] | 1729 | int iDb; /* 0 for main database. 1 for TEMP, 2.. for ATTACHed */ |
drh | 234c39d | 2004-07-24 03:30:47 +0000 | [diff] [blame] | 1730 | char **pzErrMsg; /* Error message stored here */ |
drh | 15ca1df | 2006-07-26 13:43:30 +0000 | [diff] [blame] | 1731 | int rc; /* Result code stored here */ |
drh | 234c39d | 2004-07-24 03:30:47 +0000 | [diff] [blame] | 1732 | } InitData; |
| 1733 | |
drh | b6c2989 | 2004-11-22 19:12:19 +0000 | [diff] [blame] | 1734 | /* |
drh | 40257ff | 2008-06-13 18:24:27 +0000 | [diff] [blame] | 1735 | ** Structure containing global configuration data for the SQLite library. |
drh | 3358979 | 2008-06-18 13:27:46 +0000 | [diff] [blame] | 1736 | ** |
| 1737 | ** This structure also contains some state information. |
drh | 40257ff | 2008-06-13 18:24:27 +0000 | [diff] [blame] | 1738 | */ |
| 1739 | struct Sqlite3Config { |
drh | fec00ea | 2008-06-14 16:56:21 +0000 | [diff] [blame] | 1740 | int bMemstat; /* True to enable memory status */ |
| 1741 | int bCoreMutex; /* True to enable core mutexing */ |
| 1742 | int bFullMutex; /* True to enable full mutexing */ |
| 1743 | sqlite3_mem_methods m; /* Low-level memory allocation interface */ |
danielk1977 | 6d2ab0e | 2008-06-17 17:21:18 +0000 | [diff] [blame] | 1744 | sqlite3_mutex_methods mutex; /* Low-level mutex interface */ |
drh | 40257ff | 2008-06-13 18:24:27 +0000 | [diff] [blame] | 1745 | void *pHeap; /* Heap storage space */ |
drh | 3358979 | 2008-06-18 13:27:46 +0000 | [diff] [blame] | 1746 | int nHeap; /* Size of pHeap[] */ |
| 1747 | int mnReq, mxReq; /* Min and max heap requests sizes */ |
| 1748 | void *pScratch; /* Scratch memory */ |
| 1749 | int szScratch; /* Size of each scratch buffer */ |
| 1750 | int nScratch; /* Number of scratch buffers */ |
| 1751 | void *pPage; /* Page cache memory */ |
| 1752 | int szPage; /* Size of each page in pPage[] */ |
| 1753 | int nPage; /* Number of pages in pPage[] */ |
drh | 40257ff | 2008-06-13 18:24:27 +0000 | [diff] [blame] | 1754 | }; |
| 1755 | |
| 1756 | /* |
drh | 6615095 | 2007-07-23 19:12:41 +0000 | [diff] [blame] | 1757 | ** Assuming zIn points to the first byte of a UTF-8 character, |
| 1758 | ** advance zIn to point to the first byte of the next UTF-8 character. |
drh | 4a91911 | 2007-05-15 11:55:09 +0000 | [diff] [blame] | 1759 | */ |
drh | 4a91911 | 2007-05-15 11:55:09 +0000 | [diff] [blame] | 1760 | #define SQLITE_SKIP_UTF8(zIn) { \ |
| 1761 | if( (*(zIn++))>=0xc0 ){ \ |
| 1762 | while( (*zIn & 0xc0)==0x80 ){ zIn++; } \ |
| 1763 | } \ |
| 1764 | } |
| 1765 | |
drh | 4a91911 | 2007-05-15 11:55:09 +0000 | [diff] [blame] | 1766 | /* |
drh | 4928570 | 2005-09-17 15:20:26 +0000 | [diff] [blame] | 1767 | ** The SQLITE_CORRUPT_BKPT macro can be either a constant (for production |
| 1768 | ** builds) or a function call (for debugging). If it is a function call, |
| 1769 | ** it allows the operator to set a breakpoint at the spot where database |
| 1770 | ** corruption is first detected. |
| 1771 | */ |
| 1772 | #ifdef SQLITE_DEBUG |
drh | 6e73683 | 2007-05-11 12:30:03 +0000 | [diff] [blame] | 1773 | int sqlite3Corrupt(void); |
drh | 4928570 | 2005-09-17 15:20:26 +0000 | [diff] [blame] | 1774 | # define SQLITE_CORRUPT_BKPT sqlite3Corrupt() |
drh | e5fe690 | 2007-12-07 18:55:28 +0000 | [diff] [blame] | 1775 | # define DEBUGONLY(X) X |
drh | 4928570 | 2005-09-17 15:20:26 +0000 | [diff] [blame] | 1776 | #else |
| 1777 | # define SQLITE_CORRUPT_BKPT SQLITE_CORRUPT |
drh | e5fe690 | 2007-12-07 18:55:28 +0000 | [diff] [blame] | 1778 | # define DEBUGONLY(X) |
drh | 4928570 | 2005-09-17 15:20:26 +0000 | [diff] [blame] | 1779 | #endif |
| 1780 | |
| 1781 | /* |
drh | 7589723 | 2000-05-29 14:26:00 +0000 | [diff] [blame] | 1782 | ** Internal function prototypes |
| 1783 | */ |
danielk1977 | 4adee20 | 2004-05-08 08:23:19 +0000 | [diff] [blame] | 1784 | int sqlite3StrICmp(const char *, const char *); |
| 1785 | int sqlite3StrNICmp(const char *, const char *, int); |
danielk1977 | 8a6b541 | 2004-05-24 07:04:25 +0000 | [diff] [blame] | 1786 | int sqlite3IsNumber(const char*, int*, u8); |
danielk1977 | 2e588c7 | 2005-12-09 14:25:08 +0000 | [diff] [blame] | 1787 | |
drh | 40257ff | 2008-06-13 18:24:27 +0000 | [diff] [blame] | 1788 | int sqlite3MallocInit(void); |
drh | fec00ea | 2008-06-14 16:56:21 +0000 | [diff] [blame] | 1789 | void sqlite3MallocEnd(void); |
| 1790 | void *sqlite3Malloc(int); |
| 1791 | void *sqlite3MallocZero(int); |
| 1792 | void *sqlite3DbMallocZero(sqlite3*, int); |
| 1793 | void *sqlite3DbMallocRaw(sqlite3*, int); |
danielk1977 | 2e588c7 | 2005-12-09 14:25:08 +0000 | [diff] [blame] | 1794 | char *sqlite3StrDup(const char*); |
| 1795 | char *sqlite3StrNDup(const char*, int); |
drh | 1743575 | 2007-08-16 04:30:38 +0000 | [diff] [blame] | 1796 | char *sqlite3DbStrDup(sqlite3*,const char*); |
| 1797 | char *sqlite3DbStrNDup(sqlite3*,const char*, int); |
drh | fec00ea | 2008-06-14 16:56:21 +0000 | [diff] [blame] | 1798 | void *sqlite3Realloc(void*, int); |
drh | 97c8ec3 | 2007-08-27 21:49:34 +0000 | [diff] [blame] | 1799 | void *sqlite3DbReallocOrFree(sqlite3 *, void *, int); |
danielk1977 | a1644fd | 2007-08-29 12:31:25 +0000 | [diff] [blame] | 1800 | void *sqlite3DbRealloc(sqlite3 *, void *, int); |
danielk1977 | a7a8e14 | 2008-02-13 18:25:27 +0000 | [diff] [blame] | 1801 | int sqlite3MallocSize(void *); |
drh | facf030 | 2008-06-17 15:12:00 +0000 | [diff] [blame] | 1802 | void *sqlite3ScratchMalloc(int); |
| 1803 | void sqlite3ScratchFree(void*); |
| 1804 | void *sqlite3PageMalloc(int); |
| 1805 | void sqlite3PageFree(void*); |
drh | fec00ea | 2008-06-14 16:56:21 +0000 | [diff] [blame] | 1806 | void sqlite3MemSetDefault(void); |
danielk1977 | 2e588c7 | 2005-12-09 14:25:08 +0000 | [diff] [blame] | 1807 | |
danielk1977 | 6d2ab0e | 2008-06-17 17:21:18 +0000 | [diff] [blame] | 1808 | sqlite3_mutex_methods *sqlite3DefaultMutex(void); |
danielk1977 | 59f8c08 | 2008-06-18 17:09:10 +0000 | [diff] [blame] | 1809 | sqlite3_mutex *sqlite3MutexAlloc(int); |
danielk1977 | d025174 | 2008-06-18 18:57:42 +0000 | [diff] [blame] | 1810 | int sqlite3MutexInit(void); |
| 1811 | int sqlite3MutexEnd(void); |
danielk1977 | 6d2ab0e | 2008-06-17 17:21:18 +0000 | [diff] [blame] | 1812 | |
drh | 0de3ae9 | 2008-04-28 16:55:26 +0000 | [diff] [blame] | 1813 | int sqlite3IsNaN(double); |
| 1814 | |
drh | 1743575 | 2007-08-16 04:30:38 +0000 | [diff] [blame] | 1815 | char *sqlite3MPrintf(sqlite3*,const char*, ...); |
| 1816 | char *sqlite3VMPrintf(sqlite3*,const char*, va_list); |
drh | 87cc3b3 | 2007-05-08 21:45:27 +0000 | [diff] [blame] | 1817 | #if defined(SQLITE_TEST) || defined(SQLITE_DEBUG) |
| 1818 | void sqlite3DebugPrintf(const char*, ...); |
drh | d919fe1 | 2007-12-11 19:34:44 +0000 | [diff] [blame] | 1819 | #endif |
| 1820 | #if defined(SQLITE_TEST) |
drh | 87cc3b3 | 2007-05-08 21:45:27 +0000 | [diff] [blame] | 1821 | void *sqlite3TextToPtr(const char*); |
| 1822 | #endif |
drh | 41f5852 | 2005-06-06 15:06:39 +0000 | [diff] [blame] | 1823 | void sqlite3SetString(char **, ...); |
danielk1977 | 4adee20 | 2004-05-08 08:23:19 +0000 | [diff] [blame] | 1824 | void sqlite3ErrorMsg(Parse*, const char*, ...); |
drh | a073384 | 2005-12-29 01:11:36 +0000 | [diff] [blame] | 1825 | void sqlite3ErrorClear(Parse*); |
danielk1977 | 4adee20 | 2004-05-08 08:23:19 +0000 | [diff] [blame] | 1826 | void sqlite3Dequote(char*); |
drh | 1743575 | 2007-08-16 04:30:38 +0000 | [diff] [blame] | 1827 | void sqlite3DequoteExpr(sqlite3*, Expr*); |
drh | 2646da7 | 2005-12-09 20:02:05 +0000 | [diff] [blame] | 1828 | int sqlite3KeywordCode(const unsigned char*, int); |
danielk1977 | 4adee20 | 2004-05-08 08:23:19 +0000 | [diff] [blame] | 1829 | int sqlite3RunParser(Parse*, const char*, char **); |
drh | 8024205 | 2004-06-09 00:48:12 +0000 | [diff] [blame] | 1830 | void sqlite3FinishCoding(Parse*); |
drh | 892d317 | 2008-01-10 03:46:36 +0000 | [diff] [blame] | 1831 | int sqlite3GetTempReg(Parse*); |
| 1832 | void sqlite3ReleaseTempReg(Parse*,int); |
| 1833 | int sqlite3GetTempRange(Parse*,int); |
| 1834 | void sqlite3ReleaseTempRange(Parse*,int,int); |
danielk1977 | a1644fd | 2007-08-29 12:31:25 +0000 | [diff] [blame] | 1835 | Expr *sqlite3Expr(sqlite3*, int, Expr*, Expr*, const Token*); |
drh | 1743575 | 2007-08-16 04:30:38 +0000 | [diff] [blame] | 1836 | Expr *sqlite3PExpr(Parse*, int, Expr*, Expr*, const Token*); |
drh | 4e0cff6 | 2004-11-05 05:10:28 +0000 | [diff] [blame] | 1837 | Expr *sqlite3RegisterExpr(Parse*,Token*); |
danielk1977 | 1e53695 | 2007-08-16 10:09:01 +0000 | [diff] [blame] | 1838 | Expr *sqlite3ExprAnd(sqlite3*,Expr*, Expr*); |
danielk1977 | 4adee20 | 2004-05-08 08:23:19 +0000 | [diff] [blame] | 1839 | void sqlite3ExprSpan(Expr*,Token*,Token*); |
drh | 1743575 | 2007-08-16 04:30:38 +0000 | [diff] [blame] | 1840 | Expr *sqlite3ExprFunction(Parse*,ExprList*, Token*); |
drh | fa6bc00 | 2004-09-07 16:19:52 +0000 | [diff] [blame] | 1841 | void sqlite3ExprAssignVarNumber(Parse*, Expr*); |
danielk1977 | 4adee20 | 2004-05-08 08:23:19 +0000 | [diff] [blame] | 1842 | void sqlite3ExprDelete(Expr*); |
drh | 1743575 | 2007-08-16 04:30:38 +0000 | [diff] [blame] | 1843 | ExprList *sqlite3ExprListAppend(Parse*,ExprList*,Expr*,Token*); |
danielk1977 | 4adee20 | 2004-05-08 08:23:19 +0000 | [diff] [blame] | 1844 | void sqlite3ExprListDelete(ExprList*); |
drh | 9bb575f | 2004-09-06 17:24:11 +0000 | [diff] [blame] | 1845 | int sqlite3Init(sqlite3*, char**); |
drh | 234c39d | 2004-07-24 03:30:47 +0000 | [diff] [blame] | 1846 | int sqlite3InitCallback(void*, int, char**, char**); |
danielk1977 | 91cf71b | 2004-06-26 06:37:06 +0000 | [diff] [blame] | 1847 | void sqlite3Pragma(Parse*,Token*,Token*,Token*,int); |
drh | 9bb575f | 2004-09-06 17:24:11 +0000 | [diff] [blame] | 1848 | void sqlite3ResetInternalSchema(sqlite3*, int); |
danielk1977 | 4adee20 | 2004-05-08 08:23:19 +0000 | [diff] [blame] | 1849 | void sqlite3BeginParse(Parse*,int); |
drh | 9bb575f | 2004-09-06 17:24:11 +0000 | [diff] [blame] | 1850 | void sqlite3CommitInternalChanges(sqlite3*); |
danielk1977 | 4adee20 | 2004-05-08 08:23:19 +0000 | [diff] [blame] | 1851 | Table *sqlite3ResultSetOfSelect(Parse*,char*,Select*); |
danielk1977 | c00da10 | 2006-01-07 13:21:04 +0000 | [diff] [blame] | 1852 | void sqlite3OpenMasterTable(Parse *, int); |
danielk1977 | f1a381e | 2006-06-16 08:01:02 +0000 | [diff] [blame] | 1853 | void sqlite3StartTable(Parse*,Token*,Token*,int,int,int,int); |
danielk1977 | 4adee20 | 2004-05-08 08:23:19 +0000 | [diff] [blame] | 1854 | void sqlite3AddColumn(Parse*,Token*); |
| 1855 | void sqlite3AddNotNull(Parse*, int); |
drh | fdd6e85 | 2005-12-16 01:06:16 +0000 | [diff] [blame] | 1856 | void sqlite3AddPrimaryKey(Parse*, ExprList*, int, int, int); |
drh | ffe07b2 | 2005-11-03 00:41:17 +0000 | [diff] [blame] | 1857 | void sqlite3AddCheckConstraint(Parse*, Expr*); |
drh | 487e262 | 2005-06-25 18:42:14 +0000 | [diff] [blame] | 1858 | void sqlite3AddColumnType(Parse*,Token*); |
danielk1977 | 7977a17 | 2004-11-09 12:44:37 +0000 | [diff] [blame] | 1859 | void sqlite3AddDefaultValue(Parse*,Expr*); |
danielk1977 | 3900250 | 2007-11-12 09:50:26 +0000 | [diff] [blame] | 1860 | void sqlite3AddCollateType(Parse*, Token*); |
danielk1977 | 19a8e7e | 2005-03-17 05:03:38 +0000 | [diff] [blame] | 1861 | void sqlite3EndTable(Parse*,Token*,Token*,Select*); |
drh | b7f9164 | 2004-10-31 02:22:47 +0000 | [diff] [blame] | 1862 | |
drh | f5e7bb5 | 2008-02-18 14:47:33 +0000 | [diff] [blame] | 1863 | Bitvec *sqlite3BitvecCreate(u32); |
| 1864 | int sqlite3BitvecTest(Bitvec*, u32); |
| 1865 | int sqlite3BitvecSet(Bitvec*, u32); |
| 1866 | void sqlite3BitvecClear(Bitvec*, u32); |
| 1867 | void sqlite3BitvecDestroy(Bitvec*); |
drh | 3088d59 | 2008-03-21 16:45:47 +0000 | [diff] [blame] | 1868 | int sqlite3BitvecBuiltinTest(int,int*); |
drh | f5e7bb5 | 2008-02-18 14:47:33 +0000 | [diff] [blame] | 1869 | |
drh | fdd48a7 | 2006-09-11 23:45:48 +0000 | [diff] [blame] | 1870 | void sqlite3CreateView(Parse*,Token*,Token*,Token*,Select*,int,int); |
danielk1977 | fe3fcbe2 | 2006-06-12 12:08:45 +0000 | [diff] [blame] | 1871 | |
| 1872 | #if !defined(SQLITE_OMIT_VIEW) || !defined(SQLITE_OMIT_VIRTUALTABLE) |
drh | b7f9164 | 2004-10-31 02:22:47 +0000 | [diff] [blame] | 1873 | int sqlite3ViewGetColumnNames(Parse*,Table*); |
| 1874 | #else |
| 1875 | # define sqlite3ViewGetColumnNames(A,B) 0 |
| 1876 | #endif |
| 1877 | |
drh | a073384 | 2005-12-29 01:11:36 +0000 | [diff] [blame] | 1878 | void sqlite3DropTable(Parse*, SrcList*, int, int); |
danielk1977 | a04a34f | 2007-04-16 15:06:25 +0000 | [diff] [blame] | 1879 | void sqlite3DeleteTable(Table*); |
danielk1977 | 4adee20 | 2004-05-08 08:23:19 +0000 | [diff] [blame] | 1880 | void sqlite3Insert(Parse*, SrcList*, ExprList*, Select*, IdList*, int); |
drh | 1743575 | 2007-08-16 04:30:38 +0000 | [diff] [blame] | 1881 | void *sqlite3ArrayAllocate(sqlite3*,void*,int,int,int*,int*,int*); |
| 1882 | IdList *sqlite3IdListAppend(sqlite3*, IdList*, Token*); |
danielk1977 | 4adee20 | 2004-05-08 08:23:19 +0000 | [diff] [blame] | 1883 | int sqlite3IdListIndex(IdList*,const char*); |
drh | 1743575 | 2007-08-16 04:30:38 +0000 | [diff] [blame] | 1884 | SrcList *sqlite3SrcListAppend(sqlite3*, SrcList*, Token*, Token*); |
| 1885 | SrcList *sqlite3SrcListAppendFromTerm(Parse*, SrcList*, Token*, Token*, Token*, |
drh | 61dfc31 | 2006-12-16 16:25:15 +0000 | [diff] [blame] | 1886 | Select*, Expr*, IdList*); |
| 1887 | void sqlite3SrcListShiftJoinType(SrcList*); |
danielk1977 | 4adee20 | 2004-05-08 08:23:19 +0000 | [diff] [blame] | 1888 | void sqlite3SrcListAssignCursors(Parse*, SrcList*); |
| 1889 | void sqlite3IdListDelete(IdList*); |
| 1890 | void sqlite3SrcListDelete(SrcList*); |
danielk1977 | 0202b29 | 2004-06-09 09:55:16 +0000 | [diff] [blame] | 1891 | void sqlite3CreateIndex(Parse*,Token*,Token*,SrcList*,ExprList*,int,Token*, |
drh | 4d91a70 | 2006-01-04 15:54:36 +0000 | [diff] [blame] | 1892 | Token*, int, int); |
| 1893 | void sqlite3DropIndex(Parse*, SrcList*, int); |
danielk1977 | 6c8c8ce | 2008-01-02 16:27:09 +0000 | [diff] [blame] | 1894 | int sqlite3Select(Parse*, Select*, SelectDest*, Select*, int, int*, char *aff); |
drh | 1743575 | 2007-08-16 04:30:38 +0000 | [diff] [blame] | 1895 | Select *sqlite3SelectNew(Parse*,ExprList*,SrcList*,Expr*,ExprList*, |
| 1896 | Expr*,ExprList*,int,Expr*,Expr*); |
danielk1977 | 4adee20 | 2004-05-08 08:23:19 +0000 | [diff] [blame] | 1897 | void sqlite3SelectDelete(Select*); |
danielk1977 | 4adee20 | 2004-05-08 08:23:19 +0000 | [diff] [blame] | 1898 | Table *sqlite3SrcListLookup(Parse*, SrcList*); |
| 1899 | int sqlite3IsReadOnly(Parse*, Table*, int); |
danielk1977 | c00da10 | 2006-01-07 13:21:04 +0000 | [diff] [blame] | 1900 | void sqlite3OpenTable(Parse*, int iCur, int iDb, Table*, int); |
danielk1977 | 4adee20 | 2004-05-08 08:23:19 +0000 | [diff] [blame] | 1901 | void sqlite3DeleteFrom(Parse*, SrcList*, Expr*); |
| 1902 | void sqlite3Update(Parse*, SrcList*, ExprList*, Expr*, int); |
danielk1977 | a9d1ccb | 2008-01-05 17:39:29 +0000 | [diff] [blame] | 1903 | WhereInfo *sqlite3WhereBegin(Parse*, SrcList*, Expr*, ExprList**, u8); |
danielk1977 | 4adee20 | 2004-05-08 08:23:19 +0000 | [diff] [blame] | 1904 | void sqlite3WhereEnd(WhereInfo*); |
drh | da250ea | 2008-04-01 05:07:14 +0000 | [diff] [blame] | 1905 | int sqlite3ExprCodeGetColumn(Parse*, Table*, int, int, int, int); |
drh | e55cbd7 | 2008-03-31 23:48:03 +0000 | [diff] [blame] | 1906 | void sqlite3ExprCodeMove(Parse*, int, int); |
| 1907 | void sqlite3ExprClearColumnCache(Parse*, int); |
drh | da250ea | 2008-04-01 05:07:14 +0000 | [diff] [blame] | 1908 | void sqlite3ExprCacheAffinityChange(Parse*, int, int); |
drh | 652fbf5 | 2008-04-01 01:42:41 +0000 | [diff] [blame] | 1909 | int sqlite3ExprWritableRegister(Parse*,int,int); |
drh | 191b54c | 2008-04-15 12:14:21 +0000 | [diff] [blame] | 1910 | void sqlite3ExprHardCopy(Parse*,int,int); |
drh | 389a1ad | 2008-01-03 23:44:53 +0000 | [diff] [blame] | 1911 | int sqlite3ExprCode(Parse*, Expr*, int); |
drh | 2dcef11 | 2008-01-12 19:03:48 +0000 | [diff] [blame] | 1912 | int sqlite3ExprCodeTemp(Parse*, Expr*, int*); |
drh | 678ccce | 2008-03-31 18:19:54 +0000 | [diff] [blame] | 1913 | int sqlite3ExprCodeTarget(Parse*, Expr*, int); |
drh | 2dcef11 | 2008-01-12 19:03:48 +0000 | [diff] [blame] | 1914 | int sqlite3ExprCodeAndCache(Parse*, Expr*, int); |
drh | 678ccce | 2008-03-31 18:19:54 +0000 | [diff] [blame] | 1915 | void sqlite3ExprCodeConstants(Parse*, Expr*); |
drh | 191b54c | 2008-04-15 12:14:21 +0000 | [diff] [blame] | 1916 | int sqlite3ExprCodeExprList(Parse*, ExprList*, int, int); |
danielk1977 | 4adee20 | 2004-05-08 08:23:19 +0000 | [diff] [blame] | 1917 | void sqlite3ExprIfTrue(Parse*, Expr*, int, int); |
| 1918 | void sqlite3ExprIfFalse(Parse*, Expr*, int, int); |
drh | 9bb575f | 2004-09-06 17:24:11 +0000 | [diff] [blame] | 1919 | Table *sqlite3FindTable(sqlite3*,const char*, const char*); |
drh | ca42411 | 2008-01-25 15:04:48 +0000 | [diff] [blame] | 1920 | Table *sqlite3LocateTable(Parse*,int isView,const char*, const char*); |
drh | 9bb575f | 2004-09-06 17:24:11 +0000 | [diff] [blame] | 1921 | Index *sqlite3FindIndex(sqlite3*,const char*, const char*); |
| 1922 | void sqlite3UnlinkAndDeleteTable(sqlite3*,int,const char*); |
| 1923 | void sqlite3UnlinkAndDeleteIndex(sqlite3*,int,const char*); |
drh | 7416170 | 2006-02-24 02:53:49 +0000 | [diff] [blame] | 1924 | void sqlite3Vacuum(Parse*); |
drh | 9bb575f | 2004-09-06 17:24:11 +0000 | [diff] [blame] | 1925 | int sqlite3RunVacuum(char**, sqlite3*); |
drh | 1743575 | 2007-08-16 04:30:38 +0000 | [diff] [blame] | 1926 | char *sqlite3NameFromToken(sqlite3*, Token*); |
danielk1977 | 4adee20 | 2004-05-08 08:23:19 +0000 | [diff] [blame] | 1927 | int sqlite3ExprCompare(Expr*, Expr*); |
danielk1977 | b3bce66 | 2005-01-29 08:32:43 +0000 | [diff] [blame] | 1928 | int sqlite3ExprResolveNames(NameContext *, Expr *); |
drh | d2b3e23 | 2008-01-23 14:51:49 +0000 | [diff] [blame] | 1929 | void sqlite3ExprAnalyzeAggregates(NameContext*, Expr*); |
| 1930 | void sqlite3ExprAnalyzeAggList(NameContext*,ExprList*); |
danielk1977 | 4adee20 | 2004-05-08 08:23:19 +0000 | [diff] [blame] | 1931 | Vdbe *sqlite3GetVdbe(Parse*); |
danielk1977 | 1e53695 | 2007-08-16 10:09:01 +0000 | [diff] [blame] | 1932 | Expr *sqlite3CreateIdExpr(Parse *, const char*); |
drh | 2fa1868 | 2008-03-19 14:15:34 +0000 | [diff] [blame] | 1933 | void sqlite3PrngSaveState(void); |
| 1934 | void sqlite3PrngRestoreState(void); |
| 1935 | void sqlite3PrngResetState(void); |
drh | 9bb575f | 2004-09-06 17:24:11 +0000 | [diff] [blame] | 1936 | void sqlite3RollbackAll(sqlite3*); |
danielk1977 | 4adee20 | 2004-05-08 08:23:19 +0000 | [diff] [blame] | 1937 | void sqlite3CodeVerifySchema(Parse*, int); |
drh | 684917c | 2004-10-05 02:41:42 +0000 | [diff] [blame] | 1938 | void sqlite3BeginTransaction(Parse*, int); |
danielk1977 | 4adee20 | 2004-05-08 08:23:19 +0000 | [diff] [blame] | 1939 | void sqlite3CommitTransaction(Parse*); |
| 1940 | void sqlite3RollbackTransaction(Parse*); |
| 1941 | int sqlite3ExprIsConstant(Expr*); |
drh | 0a16837 | 2007-06-08 00:20:47 +0000 | [diff] [blame] | 1942 | int sqlite3ExprIsConstantNotJoin(Expr*); |
drh | eb55bd2 | 2005-06-30 17:04:21 +0000 | [diff] [blame] | 1943 | int sqlite3ExprIsConstantOrFunction(Expr*); |
danielk1977 | 4adee20 | 2004-05-08 08:23:19 +0000 | [diff] [blame] | 1944 | int sqlite3ExprIsInteger(Expr*, int*); |
| 1945 | int sqlite3IsRowid(const char*); |
drh | 2d401ab | 2008-01-10 23:50:11 +0000 | [diff] [blame] | 1946 | void sqlite3GenerateRowDelete(Parse*, Table*, int, int, int); |
| 1947 | void sqlite3GenerateRowIndexDelete(Parse*, Table*, int, int*); |
drh | e14006d | 2008-03-25 17:23:32 +0000 | [diff] [blame] | 1948 | int sqlite3GenerateIndexKey(Parse*, Index*, int, int, int); |
drh | 04adf41 | 2008-01-08 18:57:50 +0000 | [diff] [blame] | 1949 | void sqlite3GenerateConstraintChecks(Parse*,Table*,int,int, |
| 1950 | int*,int,int,int,int); |
| 1951 | void sqlite3CompleteInsertion(Parse*, Table*, int, int, int*,int,int,int,int); |
drh | aa9b896 | 2008-01-08 02:57:55 +0000 | [diff] [blame] | 1952 | int sqlite3OpenTableAndIndices(Parse*, Table*, int, int); |
danielk1977 | 4adee20 | 2004-05-08 08:23:19 +0000 | [diff] [blame] | 1953 | void sqlite3BeginWriteOperation(Parse*, int, int); |
drh | 1743575 | 2007-08-16 04:30:38 +0000 | [diff] [blame] | 1954 | Expr *sqlite3ExprDup(sqlite3*,Expr*); |
| 1955 | void sqlite3TokenCopy(sqlite3*,Token*, Token*); |
| 1956 | ExprList *sqlite3ExprListDup(sqlite3*,ExprList*); |
| 1957 | SrcList *sqlite3SrcListDup(sqlite3*,SrcList*); |
| 1958 | IdList *sqlite3IdListDup(sqlite3*,IdList*); |
| 1959 | Select *sqlite3SelectDup(sqlite3*,Select*); |
drh | 9bb575f | 2004-09-06 17:24:11 +0000 | [diff] [blame] | 1960 | FuncDef *sqlite3FindFunction(sqlite3*,const char*,int,int,u8,int); |
| 1961 | void sqlite3RegisterBuiltinFunctions(sqlite3*); |
| 1962 | void sqlite3RegisterDateTimeFunctions(sqlite3*); |
drh | 7e8b848 | 2008-01-23 03:03:05 +0000 | [diff] [blame] | 1963 | #ifdef SQLITE_DEBUG |
| 1964 | int sqlite3SafetyOn(sqlite3*); |
| 1965 | int sqlite3SafetyOff(sqlite3*); |
| 1966 | #else |
| 1967 | # define sqlite3SafetyOn(A) 0 |
| 1968 | # define sqlite3SafetyOff(A) 0 |
| 1969 | #endif |
| 1970 | int sqlite3SafetyCheckOk(sqlite3*); |
| 1971 | int sqlite3SafetyCheckSickOrOk(sqlite3*); |
drh | 9cbf342 | 2008-01-17 16:22:13 +0000 | [diff] [blame] | 1972 | void sqlite3ChangeCookie(Parse*, int); |
drh | f93d999 | 2008-04-15 14:36:42 +0000 | [diff] [blame] | 1973 | void sqlite3MaterializeView(Parse*, Select*, Expr*, int); |
drh | b7f9164 | 2004-10-31 02:22:47 +0000 | [diff] [blame] | 1974 | |
| 1975 | #ifndef SQLITE_OMIT_TRIGGER |
| 1976 | void sqlite3BeginTrigger(Parse*, Token*,Token*,int,int,IdList*,SrcList*, |
drh | 60218d2 | 2007-04-06 11:26:00 +0000 | [diff] [blame] | 1977 | Expr*,int, int); |
drh | b7f9164 | 2004-10-31 02:22:47 +0000 | [diff] [blame] | 1978 | void sqlite3FinishTrigger(Parse*, TriggerStep*, Token*); |
drh | fdd48a7 | 2006-09-11 23:45:48 +0000 | [diff] [blame] | 1979 | void sqlite3DropTrigger(Parse*, SrcList*, int); |
drh | 7416170 | 2006-02-24 02:53:49 +0000 | [diff] [blame] | 1980 | void sqlite3DropTriggerPtr(Parse*, Trigger*); |
drh | dca7684 | 2004-12-07 14:06:13 +0000 | [diff] [blame] | 1981 | int sqlite3TriggersExist(Parse*, Table*, int, ExprList*); |
drh | b7f9164 | 2004-10-31 02:22:47 +0000 | [diff] [blame] | 1982 | int sqlite3CodeRowTrigger(Parse*, int, ExprList*, int, Table *, int, int, |
danielk1977 | 8f2c54e | 2008-01-01 19:02:09 +0000 | [diff] [blame] | 1983 | int, int, u32*, u32*); |
drh | b7f9164 | 2004-10-31 02:22:47 +0000 | [diff] [blame] | 1984 | void sqliteViewTriggers(Parse*, Table*, Expr*, int, ExprList*); |
| 1985 | void sqlite3DeleteTriggerStep(TriggerStep*); |
drh | 1743575 | 2007-08-16 04:30:38 +0000 | [diff] [blame] | 1986 | TriggerStep *sqlite3TriggerSelectStep(sqlite3*,Select*); |
| 1987 | TriggerStep *sqlite3TriggerInsertStep(sqlite3*,Token*, IdList*, |
| 1988 | ExprList*,Select*,int); |
| 1989 | TriggerStep *sqlite3TriggerUpdateStep(sqlite3*,Token*,ExprList*, Expr*, int); |
| 1990 | TriggerStep *sqlite3TriggerDeleteStep(sqlite3*,Token*, Expr*); |
drh | b7f9164 | 2004-10-31 02:22:47 +0000 | [diff] [blame] | 1991 | void sqlite3DeleteTrigger(Trigger*); |
| 1992 | void sqlite3UnlinkAndDeleteTrigger(sqlite3*,int,const char*); |
| 1993 | #else |
| 1994 | # define sqlite3TriggersExist(A,B,C,D,E,F) 0 |
| 1995 | # define sqlite3DeleteTrigger(A) |
drh | cdd536f | 2006-03-17 00:04:03 +0000 | [diff] [blame] | 1996 | # define sqlite3DropTriggerPtr(A,B) |
drh | b7f9164 | 2004-10-31 02:22:47 +0000 | [diff] [blame] | 1997 | # define sqlite3UnlinkAndDeleteTrigger(A,B,C) |
danielk1977 | 8f2c54e | 2008-01-01 19:02:09 +0000 | [diff] [blame] | 1998 | # define sqlite3CodeRowTrigger(A,B,C,D,E,F,G,H,I,J,K) 0 |
drh | b7f9164 | 2004-10-31 02:22:47 +0000 | [diff] [blame] | 1999 | #endif |
| 2000 | |
danielk1977 | 4adee20 | 2004-05-08 08:23:19 +0000 | [diff] [blame] | 2001 | int sqlite3JoinType(Parse*, Token*, Token*, Token*); |
danielk1977 | 0202b29 | 2004-06-09 09:55:16 +0000 | [diff] [blame] | 2002 | void sqlite3CreateForeignKey(Parse*, ExprList*, Token*, ExprList*, int); |
danielk1977 | 4adee20 | 2004-05-08 08:23:19 +0000 | [diff] [blame] | 2003 | void sqlite3DeferForeignKey(Parse*, int); |
drh | ed6c867 | 2003-01-12 18:02:16 +0000 | [diff] [blame] | 2004 | #ifndef SQLITE_OMIT_AUTHORIZATION |
drh | 728b577 | 2007-09-18 15:55:07 +0000 | [diff] [blame] | 2005 | void sqlite3AuthRead(Parse*,Expr*,Schema*,SrcList*); |
danielk1977 | 4adee20 | 2004-05-08 08:23:19 +0000 | [diff] [blame] | 2006 | int sqlite3AuthCheck(Parse*,int, const char*, const char*, const char*); |
| 2007 | void sqlite3AuthContextPush(Parse*, AuthContext*, const char*); |
| 2008 | void sqlite3AuthContextPop(AuthContext*); |
drh | ed6c867 | 2003-01-12 18:02:16 +0000 | [diff] [blame] | 2009 | #else |
danielk1977 | b5258c3 | 2007-10-04 18:11:15 +0000 | [diff] [blame] | 2010 | # define sqlite3AuthRead(a,b,c,d) |
danielk1977 | 4adee20 | 2004-05-08 08:23:19 +0000 | [diff] [blame] | 2011 | # define sqlite3AuthCheck(a,b,c,d,e) SQLITE_OK |
| 2012 | # define sqlite3AuthContextPush(a,b,c) |
| 2013 | # define sqlite3AuthContextPop(a) ((void)(a)) |
drh | ed6c867 | 2003-01-12 18:02:16 +0000 | [diff] [blame] | 2014 | #endif |
danielk1977 | f744bb5 | 2005-12-06 17:19:11 +0000 | [diff] [blame] | 2015 | void sqlite3Attach(Parse*, Expr*, Expr*, Expr*); |
| 2016 | void sqlite3Detach(Parse*, Expr*); |
drh | 9bb575f | 2004-09-06 17:24:11 +0000 | [diff] [blame] | 2017 | int sqlite3BtreeFactory(const sqlite3 *db, const char *zFilename, |
drh | 33f4e02 | 2007-09-03 15:19:34 +0000 | [diff] [blame] | 2018 | int omitJournal, int nCache, int flags, Btree **ppBtree); |
danielk1977 | 4adee20 | 2004-05-08 08:23:19 +0000 | [diff] [blame] | 2019 | int sqlite3FixInit(DbFixer*, Parse*, int, const char*, const Token*); |
| 2020 | int sqlite3FixSrcList(DbFixer*, SrcList*); |
| 2021 | int sqlite3FixSelect(DbFixer*, Select*); |
| 2022 | int sqlite3FixExpr(DbFixer*, Expr*); |
| 2023 | int sqlite3FixExprList(DbFixer*, ExprList*); |
| 2024 | int sqlite3FixTriggerStep(DbFixer*, TriggerStep*); |
drh | 487e262 | 2005-06-25 18:42:14 +0000 | [diff] [blame] | 2025 | int sqlite3AtoF(const char *z, double*); |
danielk1977 | 6f8a503 | 2004-05-10 10:34:51 +0000 | [diff] [blame] | 2026 | char *sqlite3_snprintf(int,char*,const char*,...); |
drh | fec19aa | 2004-05-19 20:41:03 +0000 | [diff] [blame] | 2027 | int sqlite3GetInt32(const char *, int*); |
drh | 598f134 | 2007-10-23 15:39:45 +0000 | [diff] [blame] | 2028 | int sqlite3FitsIn64Bits(const char *, int); |
drh | ee85813 | 2007-05-08 20:37:38 +0000 | [diff] [blame] | 2029 | int sqlite3Utf16ByteLen(const void *pData, int nChar); |
| 2030 | int sqlite3Utf8CharLen(const char *pData, int nByte); |
drh | 6615095 | 2007-07-23 19:12:41 +0000 | [diff] [blame] | 2031 | int sqlite3Utf8Read(const u8*, const u8*, const u8**); |
shane | 3f8d5cf | 2008-04-24 19:15:09 +0000 | [diff] [blame] | 2032 | |
| 2033 | /* |
| 2034 | ** Routines to read and write variable-length integers. These used to |
| 2035 | ** be defined locally, but now we use the varint routines in the util.c |
shane | 952856a | 2008-04-28 17:41:30 +0000 | [diff] [blame] | 2036 | ** file. Code should use the MACRO forms below, as the Varint32 versions |
| 2037 | ** are coded to assume the single byte case is already handled (which |
| 2038 | ** the MACRO form does). |
shane | 3f8d5cf | 2008-04-24 19:15:09 +0000 | [diff] [blame] | 2039 | */ |
drh | 35b5a33 | 2008-04-05 18:41:42 +0000 | [diff] [blame] | 2040 | int sqlite3PutVarint(unsigned char*, u64); |
| 2041 | int sqlite3PutVarint32(unsigned char*, u32); |
danielk1977 | 90e4d95 | 2004-05-10 10:05:53 +0000 | [diff] [blame] | 2042 | int sqlite3GetVarint(const unsigned char *, u64 *); |
drh | 6d2fb15 | 2004-05-14 16:50:06 +0000 | [diff] [blame] | 2043 | int sqlite3GetVarint32(const unsigned char *, u32 *); |
danielk1977 | 192ac1d | 2004-05-10 07:17:30 +0000 | [diff] [blame] | 2044 | int sqlite3VarintLen(u64 v); |
shane | 3f8d5cf | 2008-04-24 19:15:09 +0000 | [diff] [blame] | 2045 | |
| 2046 | /* |
| 2047 | ** The header of a record consists of a sequence variable-length integers. |
| 2048 | ** These integers are almost always small and are encoded as a single byte. |
| 2049 | ** The following macros take advantage this fact to provide a fast encode |
| 2050 | ** and decode of the integers in a record header. It is faster for the common |
| 2051 | ** case where the integer is a single byte. It is a little slower when the |
| 2052 | ** integer is two or more bytes. But overall it is faster. |
| 2053 | ** |
| 2054 | ** The following expressions are equivalent: |
| 2055 | ** |
| 2056 | ** x = sqlite3GetVarint32( A, &B ); |
| 2057 | ** x = sqlite3PutVarint32( A, B ); |
| 2058 | ** |
| 2059 | ** x = getVarint32( A, B ); |
| 2060 | ** x = putVarint32( A, B ); |
| 2061 | ** |
| 2062 | */ |
| 2063 | #define getVarint32(A,B) ((*(A)<(unsigned char)0x80) ? ((B) = (u32)*(A)),1 : sqlite3GetVarint32((A), &(B))) |
| 2064 | #define putVarint32(A,B) (((B)<(u32)0x80) ? (*(A) = (unsigned char)(B)),1 : sqlite3PutVarint32((A), (B))) |
| 2065 | #define getVarint sqlite3GetVarint |
| 2066 | #define putVarint sqlite3PutVarint |
| 2067 | |
| 2068 | |
danielk1977 | a37cdde | 2004-05-16 11:15:36 +0000 | [diff] [blame] | 2069 | void sqlite3IndexAffinityStr(Vdbe *, Index *); |
| 2070 | void sqlite3TableAffinityStr(Vdbe *, Table *); |
danielk1977 | e014a83 | 2004-05-17 10:48:57 +0000 | [diff] [blame] | 2071 | char sqlite3CompareAffinity(Expr *pExpr, char aff2); |
danielk1977 | e014a83 | 2004-05-17 10:48:57 +0000 | [diff] [blame] | 2072 | int sqlite3IndexAffinityOk(Expr *pExpr, char idx_affinity); |
danielk1977 | bf3b721 | 2004-05-18 10:06:24 +0000 | [diff] [blame] | 2073 | char sqlite3ExprAffinity(Expr *pExpr); |
drh | b6a9ece | 2007-06-26 00:37:27 +0000 | [diff] [blame] | 2074 | int sqlite3Atoi64(const char*, i64*); |
drh | 9bb575f | 2004-09-06 17:24:11 +0000 | [diff] [blame] | 2075 | void sqlite3Error(sqlite3*, int, const char*,...); |
drh | ca48c90 | 2008-01-18 14:08:24 +0000 | [diff] [blame] | 2076 | void *sqlite3HexToBlob(sqlite3*, const char *z, int n); |
danielk1977 | ef2cb63 | 2004-05-29 02:37:19 +0000 | [diff] [blame] | 2077 | int sqlite3TwoPartName(Parse *, Token *, Token *, Token **); |
danielk1977 | f20b21c | 2004-05-31 23:56:42 +0000 | [diff] [blame] | 2078 | const char *sqlite3ErrStr(int); |
danielk1977 | 8a41449 | 2004-06-29 08:59:35 +0000 | [diff] [blame] | 2079 | int sqlite3ReadSchema(Parse *pParse); |
drh | 9bb575f | 2004-09-06 17:24:11 +0000 | [diff] [blame] | 2080 | CollSeq *sqlite3FindCollSeq(sqlite3*,u8 enc, const char *,int,int); |
danielk1977 | 0202b29 | 2004-06-09 09:55:16 +0000 | [diff] [blame] | 2081 | CollSeq *sqlite3LocateCollSeq(Parse *pParse, const char *zName, int nName); |
danielk1977 | 7cedc8d | 2004-06-10 10:50:08 +0000 | [diff] [blame] | 2082 | CollSeq *sqlite3ExprCollSeq(Parse *pParse, Expr *pExpr); |
drh | 8b4c40d | 2007-02-01 23:02:45 +0000 | [diff] [blame] | 2083 | Expr *sqlite3ExprSetColl(Parse *pParse, Expr *, Token *); |
danielk1977 | 7cedc8d | 2004-06-10 10:50:08 +0000 | [diff] [blame] | 2084 | int sqlite3CheckCollSeq(Parse *, CollSeq *); |
danielk1977 | d812336 | 2004-06-12 09:25:12 +0000 | [diff] [blame] | 2085 | int sqlite3CheckObjectName(Parse *, const char *); |
danielk1977 | b28af71 | 2004-06-21 06:50:26 +0000 | [diff] [blame] | 2086 | void sqlite3VdbeSetChanges(sqlite3 *, int); |
danielk1977 | 4e6af13 | 2004-06-10 14:01:08 +0000 | [diff] [blame] | 2087 | |
drh | b21c8cd | 2007-08-21 19:33:56 +0000 | [diff] [blame] | 2088 | const void *sqlite3ValueText(sqlite3_value*, u8); |
| 2089 | int sqlite3ValueBytes(sqlite3_value*, u8); |
| 2090 | void sqlite3ValueSetStr(sqlite3_value*, int, const void *,u8, |
danielk1977 | 1e53695 | 2007-08-16 10:09:01 +0000 | [diff] [blame] | 2091 | void(*)(void*)); |
danielk1977 | 4e6af13 | 2004-06-10 14:01:08 +0000 | [diff] [blame] | 2092 | void sqlite3ValueFree(sqlite3_value*); |
danielk1977 | 1e53695 | 2007-08-16 10:09:01 +0000 | [diff] [blame] | 2093 | sqlite3_value *sqlite3ValueNew(sqlite3 *); |
| 2094 | char *sqlite3Utf16to8(sqlite3 *, const void*, int); |
| 2095 | int sqlite3ValueFromExpr(sqlite3 *, Expr *, u8, u8, sqlite3_value **); |
drh | b21c8cd | 2007-08-21 19:33:56 +0000 | [diff] [blame] | 2096 | void sqlite3ValueApplyAffinity(sqlite3_value *, u8, u8); |
drh | 46c99e0 | 2007-08-27 23:26:59 +0000 | [diff] [blame] | 2097 | #ifndef SQLITE_AMALGAMATION |
drh | 4e5ffc5 | 2004-08-31 00:52:37 +0000 | [diff] [blame] | 2098 | extern const unsigned char sqlite3UpperToLower[]; |
drh | 40257ff | 2008-06-13 18:24:27 +0000 | [diff] [blame] | 2099 | extern struct Sqlite3Config sqlite3Config; |
drh | 46c99e0 | 2007-08-27 23:26:59 +0000 | [diff] [blame] | 2100 | #endif |
danielk1977 | a0bf265 | 2004-11-04 14:30:04 +0000 | [diff] [blame] | 2101 | void sqlite3RootPageMoved(Db*, int, int); |
drh | 4343fea | 2004-11-05 23:46:15 +0000 | [diff] [blame] | 2102 | void sqlite3Reindex(Parse*, Token*, Token*); |
drh | 1f01ec1 | 2005-02-15 21:36:18 +0000 | [diff] [blame] | 2103 | void sqlite3AlterFunctions(sqlite3*); |
danielk1977 | 9fd2a9a | 2004-11-12 13:42:30 +0000 | [diff] [blame] | 2104 | void sqlite3AlterRenameTable(Parse*, SrcList*, Token*); |
| 2105 | int sqlite3GetToken(const unsigned char *, int *); |
drh | 2958a4e | 2004-11-12 03:56:15 +0000 | [diff] [blame] | 2106 | void sqlite3NestedParse(Parse*, const char*, ...); |
drh | d89bd00 | 2005-01-22 03:03:54 +0000 | [diff] [blame] | 2107 | void sqlite3ExpirePreparedStatements(sqlite3*); |
danielk1977 | b3bce66 | 2005-01-29 08:32:43 +0000 | [diff] [blame] | 2108 | void sqlite3CodeSubselect(Parse *, Expr *); |
| 2109 | int sqlite3SelectResolve(Parse *, Select *, NameContext *); |
danielk1977 | aee18ef | 2005-03-09 12:26:50 +0000 | [diff] [blame] | 2110 | void sqlite3ColumnDefault(Vdbe *, Table *, int); |
danielk1977 | 19a8e7e | 2005-03-17 05:03:38 +0000 | [diff] [blame] | 2111 | void sqlite3AlterFinishAddColumn(Parse *, Token *); |
| 2112 | void sqlite3AlterBeginAddColumn(Parse *, SrcList *); |
danielk1977 | 4dade03 | 2005-05-25 10:45:10 +0000 | [diff] [blame] | 2113 | CollSeq *sqlite3GetCollSeq(sqlite3*, CollSeq *, const char *, int); |
drh | 8a51256 | 2005-11-14 22:29:05 +0000 | [diff] [blame] | 2114 | char sqlite3AffinityType(const Token*); |
drh | 9f18e8a | 2005-07-08 12:13:04 +0000 | [diff] [blame] | 2115 | void sqlite3Analyze(Parse*, Token*, Token*); |
drh | a4afb65 | 2005-07-09 02:16:02 +0000 | [diff] [blame] | 2116 | int sqlite3InvokeBusyHandler(BusyHandler*); |
drh | ff2d5ea | 2005-07-23 00:41:48 +0000 | [diff] [blame] | 2117 | int sqlite3FindDb(sqlite3*, Token*); |
drh | cf1be45 | 2007-05-12 12:08:51 +0000 | [diff] [blame] | 2118 | int sqlite3AnalysisLoad(sqlite3*,int iDB); |
drh | 51147ba | 2005-07-23 22:59:55 +0000 | [diff] [blame] | 2119 | void sqlite3DefaultRowEst(Index*); |
drh | 55ef4d9 | 2005-08-14 01:20:37 +0000 | [diff] [blame] | 2120 | void sqlite3RegisterLikeFunctions(sqlite3*, int); |
drh | d64fe2f | 2005-08-28 17:00:23 +0000 | [diff] [blame] | 2121 | int sqlite3IsLikeFunction(sqlite3*,Expr*,int*,char*); |
danielk1977 | f744bb5 | 2005-12-06 17:19:11 +0000 | [diff] [blame] | 2122 | void sqlite3AttachFunctions(sqlite3 *); |
drh | fdd6e85 | 2005-12-16 01:06:16 +0000 | [diff] [blame] | 2123 | void sqlite3MinimumFileFormat(Parse*, int, int); |
danielk1977 | da18423 | 2006-01-05 11:34:32 +0000 | [diff] [blame] | 2124 | void sqlite3SchemaFree(void *); |
danielk1977 | 1e53695 | 2007-08-16 10:09:01 +0000 | [diff] [blame] | 2125 | Schema *sqlite3SchemaGet(sqlite3 *, Btree *); |
danielk1977 | e501b89 | 2006-01-09 06:29:47 +0000 | [diff] [blame] | 2126 | int sqlite3SchemaToIndex(sqlite3 *db, Schema *); |
danielk1977 | b3bf556 | 2006-01-10 17:58:23 +0000 | [diff] [blame] | 2127 | KeyInfo *sqlite3IndexKeyinfo(Parse *, Index *); |
danielk1977 | 771151b | 2006-01-17 13:21:40 +0000 | [diff] [blame] | 2128 | int sqlite3CreateFunc(sqlite3 *, const char *, int, int, void *, |
| 2129 | void (*)(sqlite3_context*,int,sqlite3_value **), |
| 2130 | void (*)(sqlite3_context*,int,sqlite3_value **), void (*)(sqlite3_context*)); |
danielk1977 | 54f0198 | 2006-01-18 15:25:17 +0000 | [diff] [blame] | 2131 | int sqlite3ApiExit(sqlite3 *db, int); |
danielk1977 | ddfb2f0 | 2006-02-17 12:25:14 +0000 | [diff] [blame] | 2132 | int sqlite3OpenTempDatabase(Parse *); |
drh | 69dab1d | 2006-06-27 14:37:20 +0000 | [diff] [blame] | 2133 | |
drh | ade8648 | 2007-11-28 22:36:40 +0000 | [diff] [blame] | 2134 | void sqlite3StrAccumAppend(StrAccum*,const char*,int); |
| 2135 | char *sqlite3StrAccumFinish(StrAccum*); |
| 2136 | void sqlite3StrAccumReset(StrAccum*); |
drh | 1013c93 | 2008-01-06 00:25:21 +0000 | [diff] [blame] | 2137 | void sqlite3SelectDestInit(SelectDest*,int,int); |
danielk1977 | 1e53695 | 2007-08-16 10:09:01 +0000 | [diff] [blame] | 2138 | |
drh | 95bdbbb | 2007-07-23 19:31:16 +0000 | [diff] [blame] | 2139 | /* |
| 2140 | ** The interface to the LEMON-generated parser |
| 2141 | */ |
| 2142 | void *sqlite3ParserAlloc(void*(*)(size_t)); |
| 2143 | void sqlite3ParserFree(void*, void(*)(void*)); |
| 2144 | void sqlite3Parser(void*, int, Token, Parse*); |
| 2145 | |
drh | caa639f | 2008-03-20 00:32:20 +0000 | [diff] [blame] | 2146 | int sqlite3AutoLoadExtensions(sqlite3*); |
drh | 69dab1d | 2006-06-27 14:37:20 +0000 | [diff] [blame] | 2147 | #ifndef SQLITE_OMIT_LOAD_EXTENSION |
| 2148 | void sqlite3CloseExtensions(sqlite3*); |
| 2149 | #else |
| 2150 | # define sqlite3CloseExtensions(X) |
| 2151 | #endif |
danielk1977 | e302663 | 2004-06-22 11:29:02 +0000 | [diff] [blame] | 2152 | |
danielk1977 | c00da10 | 2006-01-07 13:21:04 +0000 | [diff] [blame] | 2153 | #ifndef SQLITE_OMIT_SHARED_CACHE |
| 2154 | void sqlite3TableLock(Parse *, int, int, u8, const char *); |
| 2155 | #else |
| 2156 | #define sqlite3TableLock(v,w,x,y,z) |
| 2157 | #endif |
| 2158 | |
drh | 53c1402 | 2007-05-10 17:23:11 +0000 | [diff] [blame] | 2159 | #ifdef SQLITE_TEST |
| 2160 | int sqlite3Utf8To8(unsigned char*); |
| 2161 | #endif |
| 2162 | |
drh | b9bb7c1 | 2006-06-11 23:41:55 +0000 | [diff] [blame] | 2163 | #ifdef SQLITE_OMIT_VIRTUALTABLE |
| 2164 | # define sqlite3VtabClear(X) |
danielk1977 | f9e7dda | 2006-06-16 16:08:53 +0000 | [diff] [blame] | 2165 | # define sqlite3VtabSync(X,Y) (Y) |
| 2166 | # define sqlite3VtabRollback(X) |
| 2167 | # define sqlite3VtabCommit(X) |
drh | b9bb7c1 | 2006-06-11 23:41:55 +0000 | [diff] [blame] | 2168 | #else |
drh | 707205d | 2006-06-17 10:44:42 +0000 | [diff] [blame] | 2169 | void sqlite3VtabClear(Table*); |
danielk1977 | f9e7dda | 2006-06-16 16:08:53 +0000 | [diff] [blame] | 2170 | int sqlite3VtabSync(sqlite3 *db, int rc); |
| 2171 | int sqlite3VtabRollback(sqlite3 *db); |
| 2172 | int sqlite3VtabCommit(sqlite3 *db); |
drh | b9bb7c1 | 2006-06-11 23:41:55 +0000 | [diff] [blame] | 2173 | #endif |
drh | 4f3dd15 | 2008-04-28 18:46:43 +0000 | [diff] [blame] | 2174 | void sqlite3VtabMakeWritable(Parse*,Table*); |
drh | 189d4af | 2006-09-02 20:57:52 +0000 | [diff] [blame] | 2175 | void sqlite3VtabLock(sqlite3_vtab*); |
danielk1977 | a04a34f | 2007-04-16 15:06:25 +0000 | [diff] [blame] | 2176 | void sqlite3VtabUnlock(sqlite3*, sqlite3_vtab*); |
drh | b9bb7c1 | 2006-06-11 23:41:55 +0000 | [diff] [blame] | 2177 | void sqlite3VtabBeginParse(Parse*, Token*, Token*, Token*); |
| 2178 | void sqlite3VtabFinishParse(Parse*, Token*); |
| 2179 | void sqlite3VtabArgInit(Parse*); |
| 2180 | void sqlite3VtabArgExtend(Parse*, Token*); |
danielk1977 | 78efaba | 2006-06-12 06:09:17 +0000 | [diff] [blame] | 2181 | int sqlite3VtabCallCreate(sqlite3*, int, const char *, char **); |
danielk1977 | 7e6ebfb | 2006-06-12 11:24:37 +0000 | [diff] [blame] | 2182 | int sqlite3VtabCallConnect(Parse*, Table*); |
danielk1977 | 9e39ce8 | 2006-06-12 16:01:21 +0000 | [diff] [blame] | 2183 | int sqlite3VtabCallDestroy(sqlite3*, int, const char *); |
danielk1977 | f9e7dda | 2006-06-16 16:08:53 +0000 | [diff] [blame] | 2184 | int sqlite3VtabBegin(sqlite3 *, sqlite3_vtab *); |
danielk1977 | 1e53695 | 2007-08-16 10:09:01 +0000 | [diff] [blame] | 2185 | FuncDef *sqlite3VtabOverloadFunction(sqlite3 *,FuncDef*, int nArg, Expr*); |
drh | b7481e7 | 2006-09-16 21:45:14 +0000 | [diff] [blame] | 2186 | void sqlite3InvalidFunction(sqlite3_context*,int,sqlite3_value**); |
drh | b900aaf | 2006-11-09 00:24:53 +0000 | [diff] [blame] | 2187 | int sqlite3Reprepare(Vdbe*); |
drh | b1a6c3c | 2008-03-20 16:30:17 +0000 | [diff] [blame] | 2188 | void sqlite3ExprListCheckLength(Parse*, ExprList*, const char*); |
drh | 0a0e131 | 2007-08-07 17:04:59 +0000 | [diff] [blame] | 2189 | CollSeq *sqlite3BinaryCompareCollSeq(Parse *, Expr *, Expr *); |
drh | b9bb7c1 | 2006-06-11 23:41:55 +0000 | [diff] [blame] | 2190 | |
drh | 643167f | 2008-01-22 21:30:53 +0000 | [diff] [blame] | 2191 | |
| 2192 | /* |
| 2193 | ** Available fault injectors. Should be numbered beginning with 0. |
| 2194 | */ |
| 2195 | #define SQLITE_FAULTINJECTOR_MALLOC 0 |
drh | 7e8b848 | 2008-01-23 03:03:05 +0000 | [diff] [blame] | 2196 | #define SQLITE_FAULTINJECTOR_COUNT 1 |
drh | 643167f | 2008-01-22 21:30:53 +0000 | [diff] [blame] | 2197 | |
| 2198 | /* |
| 2199 | ** The interface to the fault injector subsystem. If the fault injector |
| 2200 | ** mechanism is disabled at compile-time then set up macros so that no |
| 2201 | ** unnecessary code is generated. |
| 2202 | */ |
drh | 3088d59 | 2008-03-21 16:45:47 +0000 | [diff] [blame] | 2203 | #ifndef SQLITE_OMIT_BUILTIN_TEST |
drh | 643167f | 2008-01-22 21:30:53 +0000 | [diff] [blame] | 2204 | void sqlite3FaultConfig(int,int,int); |
| 2205 | int sqlite3FaultFailures(int); |
| 2206 | int sqlite3FaultBenignFailures(int); |
| 2207 | int sqlite3FaultPending(int); |
drh | 4873d5f | 2008-05-13 13:27:33 +0000 | [diff] [blame] | 2208 | void sqlite3FaultBeginBenign(int); |
| 2209 | void sqlite3FaultEndBenign(int); |
drh | 643167f | 2008-01-22 21:30:53 +0000 | [diff] [blame] | 2210 | int sqlite3FaultStep(int); |
| 2211 | #else |
| 2212 | # define sqlite3FaultConfig(A,B,C) |
| 2213 | # define sqlite3FaultFailures(A) 0 |
| 2214 | # define sqlite3FaultBenignFailures(A) 0 |
| 2215 | # define sqlite3FaultPending(A) (-1) |
drh | 4873d5f | 2008-05-13 13:27:33 +0000 | [diff] [blame] | 2216 | # define sqlite3FaultBeginBenign(A) |
| 2217 | # define sqlite3FaultEndBenign(A) |
drh | 643167f | 2008-01-22 21:30:53 +0000 | [diff] [blame] | 2218 | # define sqlite3FaultStep(A) 0 |
| 2219 | #endif |
| 2220 | |
| 2221 | |
| 2222 | |
danielk1977 | 9a96b66 | 2007-11-29 17:05:18 +0000 | [diff] [blame] | 2223 | #define IN_INDEX_ROWID 1 |
| 2224 | #define IN_INDEX_EPH 2 |
| 2225 | #define IN_INDEX_INDEX 3 |
| 2226 | int sqlite3FindInIndex(Parse *, Expr *, int); |
| 2227 | |
danielk1977 | c7b6017 | 2007-08-22 11:22:03 +0000 | [diff] [blame] | 2228 | #ifdef SQLITE_ENABLE_ATOMIC_WRITE |
| 2229 | int sqlite3JournalOpen(sqlite3_vfs *, const char *, sqlite3_file *, int, int); |
| 2230 | int sqlite3JournalSize(sqlite3_vfs *); |
danielk1977 | f55b899 | 2007-08-24 08:15:53 +0000 | [diff] [blame] | 2231 | int sqlite3JournalCreate(sqlite3_file *); |
danielk1977 | c7b6017 | 2007-08-22 11:22:03 +0000 | [diff] [blame] | 2232 | #else |
| 2233 | #define sqlite3JournalSize(pVfs) ((pVfs)->szOsFile) |
| 2234 | #endif |
| 2235 | |
drh | 0224d26 | 2008-05-28 13:49:34 +0000 | [diff] [blame] | 2236 | #if SQLITE_MAX_EXPR_DEPTH>0 |
danielk1977 | 4b5255a | 2008-06-05 16:47:39 +0000 | [diff] [blame] | 2237 | void sqlite3ExprSetHeight(Parse *pParse, Expr *p); |
danielk1977 | fc97606 | 2007-05-10 10:46:56 +0000 | [diff] [blame] | 2238 | int sqlite3SelectExprHeight(Select *); |
| 2239 | #else |
danielk1977 | 4b5255a | 2008-06-05 16:47:39 +0000 | [diff] [blame] | 2240 | #define sqlite3ExprSetHeight(x,y) |
drh | 0224d26 | 2008-05-28 13:49:34 +0000 | [diff] [blame] | 2241 | #define sqlite3SelectExprHeight(x) 0 |
danielk1977 | fc97606 | 2007-05-10 10:46:56 +0000 | [diff] [blame] | 2242 | #endif |
| 2243 | |
drh | a315289 | 2007-05-05 11:48:52 +0000 | [diff] [blame] | 2244 | u32 sqlite3Get4byte(const u8*); |
drh | a315289 | 2007-05-05 11:48:52 +0000 | [diff] [blame] | 2245 | void sqlite3Put4byte(u8*, u32); |
| 2246 | |
danielk1977 | fd9a0a4 | 2005-05-24 12:01:00 +0000 | [diff] [blame] | 2247 | #ifdef SQLITE_SSE |
| 2248 | #include "sseInt.h" |
| 2249 | #endif |
| 2250 | |
drh | 6e73683 | 2007-05-11 12:30:03 +0000 | [diff] [blame] | 2251 | #ifdef SQLITE_DEBUG |
| 2252 | void sqlite3ParserTrace(FILE*, char *); |
| 2253 | #endif |
| 2254 | |
drh | b060341 | 2007-02-28 04:47:26 +0000 | [diff] [blame] | 2255 | /* |
| 2256 | ** If the SQLITE_ENABLE IOTRACE exists then the global variable |
mlcreech | 3a00f90 | 2008-03-04 17:45:01 +0000 | [diff] [blame] | 2257 | ** sqlite3IoTrace is a pointer to a printf-like routine used to |
drh | b060341 | 2007-02-28 04:47:26 +0000 | [diff] [blame] | 2258 | ** print I/O tracing messages. |
| 2259 | */ |
| 2260 | #ifdef SQLITE_ENABLE_IOTRACE |
mlcreech | 3a00f90 | 2008-03-04 17:45:01 +0000 | [diff] [blame] | 2261 | # define IOTRACE(A) if( sqlite3IoTrace ){ sqlite3IoTrace A; } |
danielk1977 | b4622b6 | 2007-03-02 06:24:19 +0000 | [diff] [blame] | 2262 | void sqlite3VdbeIOTraceSql(Vdbe*); |
drh | e265b08 | 2008-05-01 17:03:49 +0000 | [diff] [blame] | 2263 | SQLITE_EXTERN void (*sqlite3IoTrace)(const char*,...); |
drh | b060341 | 2007-02-28 04:47:26 +0000 | [diff] [blame] | 2264 | #else |
| 2265 | # define IOTRACE(A) |
danielk1977 | b4622b6 | 2007-03-02 06:24:19 +0000 | [diff] [blame] | 2266 | # define sqlite3VdbeIOTraceSql(X) |
drh | b060341 | 2007-02-28 04:47:26 +0000 | [diff] [blame] | 2267 | #endif |
drh | b060341 | 2007-02-28 04:47:26 +0000 | [diff] [blame] | 2268 | |
danielk1977 | e302663 | 2004-06-22 11:29:02 +0000 | [diff] [blame] | 2269 | #endif |