| | @@ -1,8 +1,8 @@ |
| 1 | 1 | /****************************************************************************** |
| 2 | 2 | ** This file is an amalgamation of many separate C source files from SQLite |
| 3 | | -** version 3.36.0. By combining all the individual C code files into this |
| 3 | +** version 3.37.0. By combining all the individual C code files into this |
| 4 | 4 | ** single large file, the entire code can be compiled as a single translation |
| 5 | 5 | ** unit. This allows many compilers to do optimizations that would not be |
| 6 | 6 | ** possible if the files were compiled separately. Performance improvements |
| 7 | 7 | ** of 5% or more are commonly seen when SQLite is compiled as a single |
| 8 | 8 | ** translation unit. |
| | @@ -20,797 +20,10 @@ |
| 20 | 20 | #define SQLITE_CORE 1 |
| 21 | 21 | #define SQLITE_AMALGAMATION 1 |
| 22 | 22 | #ifndef SQLITE_PRIVATE |
| 23 | 23 | # define SQLITE_PRIVATE static |
| 24 | 24 | #endif |
| 25 | | -/************** Begin file ctime.c *******************************************/ |
| 26 | | -/* |
| 27 | | -** 2010 February 23 |
| 28 | | -** |
| 29 | | -** The author disclaims copyright to this source code. In place of |
| 30 | | -** a legal notice, here is a blessing: |
| 31 | | -** |
| 32 | | -** May you do good and not evil. |
| 33 | | -** May you find forgiveness for yourself and forgive others. |
| 34 | | -** May you share freely, never taking more than you give. |
| 35 | | -** |
| 36 | | -************************************************************************* |
| 37 | | -** |
| 38 | | -** This file implements routines used to report what compile-time options |
| 39 | | -** SQLite was built with. |
| 40 | | -*/ |
| 41 | | - |
| 42 | | -#ifndef SQLITE_OMIT_COMPILEOPTION_DIAGS /* IMP: R-16824-07538 */ |
| 43 | | - |
| 44 | | -/* |
| 45 | | -** Include the configuration header output by 'configure' if we're using the |
| 46 | | -** autoconf-based build |
| 47 | | -*/ |
| 48 | | -#if defined(_HAVE_SQLITE_CONFIG_H) && !defined(SQLITECONFIG_H) |
| 49 | | -#include "config.h" |
| 50 | | -#define SQLITECONFIG_H 1 |
| 51 | | -#endif |
| 52 | | - |
| 53 | | -/* These macros are provided to "stringify" the value of the define |
| 54 | | -** for those options in which the value is meaningful. */ |
| 55 | | -#define CTIMEOPT_VAL_(opt) #opt |
| 56 | | -#define CTIMEOPT_VAL(opt) CTIMEOPT_VAL_(opt) |
| 57 | | - |
| 58 | | -/* Like CTIMEOPT_VAL, but especially for SQLITE_DEFAULT_LOOKASIDE. This |
| 59 | | -** option requires a separate macro because legal values contain a single |
| 60 | | -** comma. e.g. (-DSQLITE_DEFAULT_LOOKASIDE="100,100") */ |
| 61 | | -#define CTIMEOPT_VAL2_(opt1,opt2) #opt1 "," #opt2 |
| 62 | | -#define CTIMEOPT_VAL2(opt) CTIMEOPT_VAL2_(opt) |
| 63 | | - |
| 64 | | -/* |
| 65 | | -** An array of names of all compile-time options. This array should |
| 66 | | -** be sorted A-Z. |
| 67 | | -** |
| 68 | | -** This array looks large, but in a typical installation actually uses |
| 69 | | -** only a handful of compile-time options, so most times this array is usually |
| 70 | | -** rather short and uses little memory space. |
| 71 | | -*/ |
| 72 | | -static const char * const sqlite3azCompileOpt[] = { |
| 73 | | - |
| 74 | | -/* |
| 75 | | -** BEGIN CODE GENERATED BY tool/mkctime.tcl |
| 76 | | -*/ |
| 77 | | -#if SQLITE_32BIT_ROWID |
| 78 | | - "32BIT_ROWID", |
| 79 | | -#endif |
| 80 | | -#if SQLITE_4_BYTE_ALIGNED_MALLOC |
| 81 | | - "4_BYTE_ALIGNED_MALLOC", |
| 82 | | -#endif |
| 83 | | -#if SQLITE_64BIT_STATS |
| 84 | | - "64BIT_STATS", |
| 85 | | -#endif |
| 86 | | -#ifdef SQLITE_ALLOW_COVERING_INDEX_SCAN |
| 87 | | -# if SQLITE_ALLOW_COVERING_INDEX_SCAN != 1 |
| 88 | | - "ALLOW_COVERING_INDEX_SCAN=" CTIMEOPT_VAL(SQLITE_ALLOW_COVERING_INDEX_SCAN), |
| 89 | | -# endif |
| 90 | | -#endif |
| 91 | | -#if SQLITE_ALLOW_URI_AUTHORITY |
| 92 | | - "ALLOW_URI_AUTHORITY", |
| 93 | | -#endif |
| 94 | | -#ifdef SQLITE_BITMASK_TYPE |
| 95 | | - "BITMASK_TYPE=" CTIMEOPT_VAL(SQLITE_BITMASK_TYPE), |
| 96 | | -#endif |
| 97 | | -#if SQLITE_BUG_COMPATIBLE_20160819 |
| 98 | | - "BUG_COMPATIBLE_20160819", |
| 99 | | -#endif |
| 100 | | -#if SQLITE_CASE_SENSITIVE_LIKE |
| 101 | | - "CASE_SENSITIVE_LIKE", |
| 102 | | -#endif |
| 103 | | -#if SQLITE_CHECK_PAGES |
| 104 | | - "CHECK_PAGES", |
| 105 | | -#endif |
| 106 | | -#if defined(__clang__) && defined(__clang_major__) |
| 107 | | - "COMPILER=clang-" CTIMEOPT_VAL(__clang_major__) "." |
| 108 | | - CTIMEOPT_VAL(__clang_minor__) "." |
| 109 | | - CTIMEOPT_VAL(__clang_patchlevel__), |
| 110 | | -#elif defined(_MSC_VER) |
| 111 | | - "COMPILER=msvc-" CTIMEOPT_VAL(_MSC_VER), |
| 112 | | -#elif defined(__GNUC__) && defined(__VERSION__) |
| 113 | | - "COMPILER=gcc-" __VERSION__, |
| 114 | | -#endif |
| 115 | | -#if SQLITE_COVERAGE_TEST |
| 116 | | - "COVERAGE_TEST", |
| 117 | | -#endif |
| 118 | | -#if SQLITE_DEBUG |
| 119 | | - "DEBUG", |
| 120 | | -#endif |
| 121 | | -#if SQLITE_DEFAULT_AUTOMATIC_INDEX |
| 122 | | - "DEFAULT_AUTOMATIC_INDEX", |
| 123 | | -#endif |
| 124 | | -#if SQLITE_DEFAULT_AUTOVACUUM |
| 125 | | - "DEFAULT_AUTOVACUUM", |
| 126 | | -#endif |
| 127 | | -#ifdef SQLITE_DEFAULT_CACHE_SIZE |
| 128 | | - "DEFAULT_CACHE_SIZE=" CTIMEOPT_VAL(SQLITE_DEFAULT_CACHE_SIZE), |
| 129 | | -#endif |
| 130 | | -#if SQLITE_DEFAULT_CKPTFULLFSYNC |
| 131 | | - "DEFAULT_CKPTFULLFSYNC", |
| 132 | | -#endif |
| 133 | | -#ifdef SQLITE_DEFAULT_FILE_FORMAT |
| 134 | | - "DEFAULT_FILE_FORMAT=" CTIMEOPT_VAL(SQLITE_DEFAULT_FILE_FORMAT), |
| 135 | | -#endif |
| 136 | | -#ifdef SQLITE_DEFAULT_FILE_PERMISSIONS |
| 137 | | - "DEFAULT_FILE_PERMISSIONS=" CTIMEOPT_VAL(SQLITE_DEFAULT_FILE_PERMISSIONS), |
| 138 | | -#endif |
| 139 | | -#if SQLITE_DEFAULT_FOREIGN_KEYS |
| 140 | | - "DEFAULT_FOREIGN_KEYS", |
| 141 | | -#endif |
| 142 | | -#ifdef SQLITE_DEFAULT_JOURNAL_SIZE_LIMIT |
| 143 | | - "DEFAULT_JOURNAL_SIZE_LIMIT=" CTIMEOPT_VAL(SQLITE_DEFAULT_JOURNAL_SIZE_LIMIT), |
| 144 | | -#endif |
| 145 | | -#ifdef SQLITE_DEFAULT_LOCKING_MODE |
| 146 | | - "DEFAULT_LOCKING_MODE=" CTIMEOPT_VAL(SQLITE_DEFAULT_LOCKING_MODE), |
| 147 | | -#endif |
| 148 | | -#ifdef SQLITE_DEFAULT_LOOKASIDE |
| 149 | | - "DEFAULT_LOOKASIDE=" CTIMEOPT_VAL2(SQLITE_DEFAULT_LOOKASIDE), |
| 150 | | -#endif |
| 151 | | -#ifdef SQLITE_DEFAULT_MEMSTATUS |
| 152 | | -# if SQLITE_DEFAULT_MEMSTATUS != 1 |
| 153 | | - "DEFAULT_MEMSTATUS=" CTIMEOPT_VAL(SQLITE_DEFAULT_MEMSTATUS), |
| 154 | | -# endif |
| 155 | | -#endif |
| 156 | | -#ifdef SQLITE_DEFAULT_MMAP_SIZE |
| 157 | | - "DEFAULT_MMAP_SIZE=" CTIMEOPT_VAL(SQLITE_DEFAULT_MMAP_SIZE), |
| 158 | | -#endif |
| 159 | | -#ifdef SQLITE_DEFAULT_PAGE_SIZE |
| 160 | | - "DEFAULT_PAGE_SIZE=" CTIMEOPT_VAL(SQLITE_DEFAULT_PAGE_SIZE), |
| 161 | | -#endif |
| 162 | | -#ifdef SQLITE_DEFAULT_PCACHE_INITSZ |
| 163 | | - "DEFAULT_PCACHE_INITSZ=" CTIMEOPT_VAL(SQLITE_DEFAULT_PCACHE_INITSZ), |
| 164 | | -#endif |
| 165 | | -#ifdef SQLITE_DEFAULT_PROXYDIR_PERMISSIONS |
| 166 | | - "DEFAULT_PROXYDIR_PERMISSIONS=" CTIMEOPT_VAL(SQLITE_DEFAULT_PROXYDIR_PERMISSIONS), |
| 167 | | -#endif |
| 168 | | -#if SQLITE_DEFAULT_RECURSIVE_TRIGGERS |
| 169 | | - "DEFAULT_RECURSIVE_TRIGGERS", |
| 170 | | -#endif |
| 171 | | -#ifdef SQLITE_DEFAULT_ROWEST |
| 172 | | - "DEFAULT_ROWEST=" CTIMEOPT_VAL(SQLITE_DEFAULT_ROWEST), |
| 173 | | -#endif |
| 174 | | -#ifdef SQLITE_DEFAULT_SECTOR_SIZE |
| 175 | | - "DEFAULT_SECTOR_SIZE=" CTIMEOPT_VAL(SQLITE_DEFAULT_SECTOR_SIZE), |
| 176 | | -#endif |
| 177 | | -#ifdef SQLITE_DEFAULT_SYNCHRONOUS |
| 178 | | - "DEFAULT_SYNCHRONOUS=" CTIMEOPT_VAL(SQLITE_DEFAULT_SYNCHRONOUS), |
| 179 | | -#endif |
| 180 | | -#ifdef SQLITE_DEFAULT_WAL_AUTOCHECKPOINT |
| 181 | | - "DEFAULT_WAL_AUTOCHECKPOINT=" CTIMEOPT_VAL(SQLITE_DEFAULT_WAL_AUTOCHECKPOINT), |
| 182 | | -#endif |
| 183 | | -#ifdef SQLITE_DEFAULT_WAL_SYNCHRONOUS |
| 184 | | - "DEFAULT_WAL_SYNCHRONOUS=" CTIMEOPT_VAL(SQLITE_DEFAULT_WAL_SYNCHRONOUS), |
| 185 | | -#endif |
| 186 | | -#ifdef SQLITE_DEFAULT_WORKER_THREADS |
| 187 | | - "DEFAULT_WORKER_THREADS=" CTIMEOPT_VAL(SQLITE_DEFAULT_WORKER_THREADS), |
| 188 | | -#endif |
| 189 | | -#if SQLITE_DIRECT_OVERFLOW_READ |
| 190 | | - "DIRECT_OVERFLOW_READ", |
| 191 | | -#endif |
| 192 | | -#if SQLITE_DISABLE_DIRSYNC |
| 193 | | - "DISABLE_DIRSYNC", |
| 194 | | -#endif |
| 195 | | -#if SQLITE_DISABLE_FTS3_UNICODE |
| 196 | | - "DISABLE_FTS3_UNICODE", |
| 197 | | -#endif |
| 198 | | -#if SQLITE_DISABLE_FTS4_DEFERRED |
| 199 | | - "DISABLE_FTS4_DEFERRED", |
| 200 | | -#endif |
| 201 | | -#if SQLITE_DISABLE_INTRINSIC |
| 202 | | - "DISABLE_INTRINSIC", |
| 203 | | -#endif |
| 204 | | -#if SQLITE_DISABLE_LFS |
| 205 | | - "DISABLE_LFS", |
| 206 | | -#endif |
| 207 | | -#if SQLITE_DISABLE_PAGECACHE_OVERFLOW_STATS |
| 208 | | - "DISABLE_PAGECACHE_OVERFLOW_STATS", |
| 209 | | -#endif |
| 210 | | -#if SQLITE_DISABLE_SKIPAHEAD_DISTINCT |
| 211 | | - "DISABLE_SKIPAHEAD_DISTINCT", |
| 212 | | -#endif |
| 213 | | -#ifdef SQLITE_ENABLE_8_3_NAMES |
| 214 | | - "ENABLE_8_3_NAMES=" CTIMEOPT_VAL(SQLITE_ENABLE_8_3_NAMES), |
| 215 | | -#endif |
| 216 | | -#if SQLITE_ENABLE_API_ARMOR |
| 217 | | - "ENABLE_API_ARMOR", |
| 218 | | -#endif |
| 219 | | -#if SQLITE_ENABLE_ATOMIC_WRITE |
| 220 | | - "ENABLE_ATOMIC_WRITE", |
| 221 | | -#endif |
| 222 | | -#if SQLITE_ENABLE_BATCH_ATOMIC_WRITE |
| 223 | | - "ENABLE_BATCH_ATOMIC_WRITE", |
| 224 | | -#endif |
| 225 | | -#if SQLITE_ENABLE_BYTECODE_VTAB |
| 226 | | - "ENABLE_BYTECODE_VTAB", |
| 227 | | -#endif |
| 228 | | -#ifdef SQLITE_ENABLE_CEROD |
| 229 | | - "ENABLE_CEROD=" CTIMEOPT_VAL(SQLITE_ENABLE_CEROD), |
| 230 | | -#endif |
| 231 | | -#if SQLITE_ENABLE_COLUMN_METADATA |
| 232 | | - "ENABLE_COLUMN_METADATA", |
| 233 | | -#endif |
| 234 | | -#if SQLITE_ENABLE_COLUMN_USED_MASK |
| 235 | | - "ENABLE_COLUMN_USED_MASK", |
| 236 | | -#endif |
| 237 | | -#if SQLITE_ENABLE_COSTMULT |
| 238 | | - "ENABLE_COSTMULT", |
| 239 | | -#endif |
| 240 | | -#if SQLITE_ENABLE_CURSOR_HINTS |
| 241 | | - "ENABLE_CURSOR_HINTS", |
| 242 | | -#endif |
| 243 | | -#if SQLITE_ENABLE_DBPAGE_VTAB |
| 244 | | - "ENABLE_DBPAGE_VTAB", |
| 245 | | -#endif |
| 246 | | -#if SQLITE_ENABLE_DBSTAT_VTAB |
| 247 | | - "ENABLE_DBSTAT_VTAB", |
| 248 | | -#endif |
| 249 | | -#if SQLITE_ENABLE_EXPENSIVE_ASSERT |
| 250 | | - "ENABLE_EXPENSIVE_ASSERT", |
| 251 | | -#endif |
| 252 | | -#if SQLITE_ENABLE_EXPLAIN_COMMENTS |
| 253 | | - "ENABLE_EXPLAIN_COMMENTS", |
| 254 | | -#endif |
| 255 | | -#if SQLITE_ENABLE_FTS3 |
| 256 | | - "ENABLE_FTS3", |
| 257 | | -#endif |
| 258 | | -#if SQLITE_ENABLE_FTS3_PARENTHESIS |
| 259 | | - "ENABLE_FTS3_PARENTHESIS", |
| 260 | | -#endif |
| 261 | | -#if SQLITE_ENABLE_FTS3_TOKENIZER |
| 262 | | - "ENABLE_FTS3_TOKENIZER", |
| 263 | | -#endif |
| 264 | | -#if SQLITE_ENABLE_FTS4 |
| 265 | | - "ENABLE_FTS4", |
| 266 | | -#endif |
| 267 | | -#if SQLITE_ENABLE_FTS5 |
| 268 | | - "ENABLE_FTS5", |
| 269 | | -#endif |
| 270 | | -#if SQLITE_ENABLE_GEOPOLY |
| 271 | | - "ENABLE_GEOPOLY", |
| 272 | | -#endif |
| 273 | | -#if SQLITE_ENABLE_HIDDEN_COLUMNS |
| 274 | | - "ENABLE_HIDDEN_COLUMNS", |
| 275 | | -#endif |
| 276 | | -#if SQLITE_ENABLE_ICU |
| 277 | | - "ENABLE_ICU", |
| 278 | | -#endif |
| 279 | | -#if SQLITE_ENABLE_IOTRACE |
| 280 | | - "ENABLE_IOTRACE", |
| 281 | | -#endif |
| 282 | | -#if SQLITE_ENABLE_JSON1 |
| 283 | | - "ENABLE_JSON1", |
| 284 | | -#endif |
| 285 | | -#if SQLITE_ENABLE_LOAD_EXTENSION |
| 286 | | - "ENABLE_LOAD_EXTENSION", |
| 287 | | -#endif |
| 288 | | -#ifdef SQLITE_ENABLE_LOCKING_STYLE |
| 289 | | - "ENABLE_LOCKING_STYLE=" CTIMEOPT_VAL(SQLITE_ENABLE_LOCKING_STYLE), |
| 290 | | -#endif |
| 291 | | -#if SQLITE_ENABLE_MATH_FUNCTIONS |
| 292 | | - "ENABLE_MATH_FUNCTIONS", |
| 293 | | -#endif |
| 294 | | -#if SQLITE_ENABLE_MEMORY_MANAGEMENT |
| 295 | | - "ENABLE_MEMORY_MANAGEMENT", |
| 296 | | -#endif |
| 297 | | -#if SQLITE_ENABLE_MEMSYS3 |
| 298 | | - "ENABLE_MEMSYS3", |
| 299 | | -#endif |
| 300 | | -#if SQLITE_ENABLE_MEMSYS5 |
| 301 | | - "ENABLE_MEMSYS5", |
| 302 | | -#endif |
| 303 | | -#if SQLITE_ENABLE_MULTIPLEX |
| 304 | | - "ENABLE_MULTIPLEX", |
| 305 | | -#endif |
| 306 | | -#if SQLITE_ENABLE_NORMALIZE |
| 307 | | - "ENABLE_NORMALIZE", |
| 308 | | -#endif |
| 309 | | -#if SQLITE_ENABLE_NULL_TRIM |
| 310 | | - "ENABLE_NULL_TRIM", |
| 311 | | -#endif |
| 312 | | -#if SQLITE_ENABLE_OFFSET_SQL_FUNC |
| 313 | | - "ENABLE_OFFSET_SQL_FUNC", |
| 314 | | -#endif |
| 315 | | -#if SQLITE_ENABLE_OVERSIZE_CELL_CHECK |
| 316 | | - "ENABLE_OVERSIZE_CELL_CHECK", |
| 317 | | -#endif |
| 318 | | -#if SQLITE_ENABLE_PREUPDATE_HOOK |
| 319 | | - "ENABLE_PREUPDATE_HOOK", |
| 320 | | -#endif |
| 321 | | -#if SQLITE_ENABLE_QPSG |
| 322 | | - "ENABLE_QPSG", |
| 323 | | -#endif |
| 324 | | -#if SQLITE_ENABLE_RBU |
| 325 | | - "ENABLE_RBU", |
| 326 | | -#endif |
| 327 | | -#if SQLITE_ENABLE_RTREE |
| 328 | | - "ENABLE_RTREE", |
| 329 | | -#endif |
| 330 | | -#if SQLITE_ENABLE_SELECTTRACE |
| 331 | | - "ENABLE_SELECTTRACE", |
| 332 | | -#endif |
| 333 | | -#if SQLITE_ENABLE_SESSION |
| 334 | | - "ENABLE_SESSION", |
| 335 | | -#endif |
| 336 | | -#if SQLITE_ENABLE_SNAPSHOT |
| 337 | | - "ENABLE_SNAPSHOT", |
| 338 | | -#endif |
| 339 | | -#if SQLITE_ENABLE_SORTER_REFERENCES |
| 340 | | - "ENABLE_SORTER_REFERENCES", |
| 341 | | -#endif |
| 342 | | -#if SQLITE_ENABLE_SQLLOG |
| 343 | | - "ENABLE_SQLLOG", |
| 344 | | -#endif |
| 345 | | -#if SQLITE_ENABLE_STAT4 |
| 346 | | - "ENABLE_STAT4", |
| 347 | | -#endif |
| 348 | | -#if SQLITE_ENABLE_STMTVTAB |
| 349 | | - "ENABLE_STMTVTAB", |
| 350 | | -#endif |
| 351 | | -#if SQLITE_ENABLE_STMT_SCANSTATUS |
| 352 | | - "ENABLE_STMT_SCANSTATUS", |
| 353 | | -#endif |
| 354 | | -#if SQLITE_ENABLE_UNKNOWN_SQL_FUNCTION |
| 355 | | - "ENABLE_UNKNOWN_SQL_FUNCTION", |
| 356 | | -#endif |
| 357 | | -#if SQLITE_ENABLE_UNLOCK_NOTIFY |
| 358 | | - "ENABLE_UNLOCK_NOTIFY", |
| 359 | | -#endif |
| 360 | | -#if SQLITE_ENABLE_UPDATE_DELETE_LIMIT |
| 361 | | - "ENABLE_UPDATE_DELETE_LIMIT", |
| 362 | | -#endif |
| 363 | | -#if SQLITE_ENABLE_URI_00_ERROR |
| 364 | | - "ENABLE_URI_00_ERROR", |
| 365 | | -#endif |
| 366 | | -#if SQLITE_ENABLE_VFSTRACE |
| 367 | | - "ENABLE_VFSTRACE", |
| 368 | | -#endif |
| 369 | | -#if SQLITE_ENABLE_WHERETRACE |
| 370 | | - "ENABLE_WHERETRACE", |
| 371 | | -#endif |
| 372 | | -#if SQLITE_ENABLE_ZIPVFS |
| 373 | | - "ENABLE_ZIPVFS", |
| 374 | | -#endif |
| 375 | | -#if SQLITE_EXPLAIN_ESTIMATED_ROWS |
| 376 | | - "EXPLAIN_ESTIMATED_ROWS", |
| 377 | | -#endif |
| 378 | | -#if SQLITE_EXTRA_IFNULLROW |
| 379 | | - "EXTRA_IFNULLROW", |
| 380 | | -#endif |
| 381 | | -#ifdef SQLITE_EXTRA_INIT |
| 382 | | - "EXTRA_INIT=" CTIMEOPT_VAL(SQLITE_EXTRA_INIT), |
| 383 | | -#endif |
| 384 | | -#ifdef SQLITE_EXTRA_SHUTDOWN |
| 385 | | - "EXTRA_SHUTDOWN=" CTIMEOPT_VAL(SQLITE_EXTRA_SHUTDOWN), |
| 386 | | -#endif |
| 387 | | -#ifdef SQLITE_FTS3_MAX_EXPR_DEPTH |
| 388 | | - "FTS3_MAX_EXPR_DEPTH=" CTIMEOPT_VAL(SQLITE_FTS3_MAX_EXPR_DEPTH), |
| 389 | | -#endif |
| 390 | | -#if SQLITE_FTS5_ENABLE_TEST_MI |
| 391 | | - "FTS5_ENABLE_TEST_MI", |
| 392 | | -#endif |
| 393 | | -#if SQLITE_FTS5_NO_WITHOUT_ROWID |
| 394 | | - "FTS5_NO_WITHOUT_ROWID", |
| 395 | | -#endif |
| 396 | | -#if HAVE_ISNAN || SQLITE_HAVE_ISNAN |
| 397 | | - "HAVE_ISNAN", |
| 398 | | -#endif |
| 399 | | -#ifdef SQLITE_HOMEGROWN_RECURSIVE_MUTEX |
| 400 | | -# if SQLITE_HOMEGROWN_RECURSIVE_MUTEX != 1 |
| 401 | | - "HOMEGROWN_RECURSIVE_MUTEX=" CTIMEOPT_VAL(SQLITE_HOMEGROWN_RECURSIVE_MUTEX), |
| 402 | | -# endif |
| 403 | | -#endif |
| 404 | | -#if SQLITE_IGNORE_AFP_LOCK_ERRORS |
| 405 | | - "IGNORE_AFP_LOCK_ERRORS", |
| 406 | | -#endif |
| 407 | | -#if SQLITE_IGNORE_FLOCK_LOCK_ERRORS |
| 408 | | - "IGNORE_FLOCK_LOCK_ERRORS", |
| 409 | | -#endif |
| 410 | | -#if SQLITE_INLINE_MEMCPY |
| 411 | | - "INLINE_MEMCPY", |
| 412 | | -#endif |
| 413 | | -#if SQLITE_INT64_TYPE |
| 414 | | - "INT64_TYPE", |
| 415 | | -#endif |
| 416 | | -#ifdef SQLITE_INTEGRITY_CHECK_ERROR_MAX |
| 417 | | - "INTEGRITY_CHECK_ERROR_MAX=" CTIMEOPT_VAL(SQLITE_INTEGRITY_CHECK_ERROR_MAX), |
| 418 | | -#endif |
| 419 | | -#if SQLITE_LIKE_DOESNT_MATCH_BLOBS |
| 420 | | - "LIKE_DOESNT_MATCH_BLOBS", |
| 421 | | -#endif |
| 422 | | -#if SQLITE_LOCK_TRACE |
| 423 | | - "LOCK_TRACE", |
| 424 | | -#endif |
| 425 | | -#if SQLITE_LOG_CACHE_SPILL |
| 426 | | - "LOG_CACHE_SPILL", |
| 427 | | -#endif |
| 428 | | -#ifdef SQLITE_MALLOC_SOFT_LIMIT |
| 429 | | - "MALLOC_SOFT_LIMIT=" CTIMEOPT_VAL(SQLITE_MALLOC_SOFT_LIMIT), |
| 430 | | -#endif |
| 431 | | -#ifdef SQLITE_MAX_ATTACHED |
| 432 | | - "MAX_ATTACHED=" CTIMEOPT_VAL(SQLITE_MAX_ATTACHED), |
| 433 | | -#endif |
| 434 | | -#ifdef SQLITE_MAX_COLUMN |
| 435 | | - "MAX_COLUMN=" CTIMEOPT_VAL(SQLITE_MAX_COLUMN), |
| 436 | | -#endif |
| 437 | | -#ifdef SQLITE_MAX_COMPOUND_SELECT |
| 438 | | - "MAX_COMPOUND_SELECT=" CTIMEOPT_VAL(SQLITE_MAX_COMPOUND_SELECT), |
| 439 | | -#endif |
| 440 | | -#ifdef SQLITE_MAX_DEFAULT_PAGE_SIZE |
| 441 | | - "MAX_DEFAULT_PAGE_SIZE=" CTIMEOPT_VAL(SQLITE_MAX_DEFAULT_PAGE_SIZE), |
| 442 | | -#endif |
| 443 | | -#ifdef SQLITE_MAX_EXPR_DEPTH |
| 444 | | - "MAX_EXPR_DEPTH=" CTIMEOPT_VAL(SQLITE_MAX_EXPR_DEPTH), |
| 445 | | -#endif |
| 446 | | -#ifdef SQLITE_MAX_FUNCTION_ARG |
| 447 | | - "MAX_FUNCTION_ARG=" CTIMEOPT_VAL(SQLITE_MAX_FUNCTION_ARG), |
| 448 | | -#endif |
| 449 | | -#ifdef SQLITE_MAX_LENGTH |
| 450 | | - "MAX_LENGTH=" CTIMEOPT_VAL(SQLITE_MAX_LENGTH), |
| 451 | | -#endif |
| 452 | | -#ifdef SQLITE_MAX_LIKE_PATTERN_LENGTH |
| 453 | | - "MAX_LIKE_PATTERN_LENGTH=" CTIMEOPT_VAL(SQLITE_MAX_LIKE_PATTERN_LENGTH), |
| 454 | | -#endif |
| 455 | | -#ifdef SQLITE_MAX_MEMORY |
| 456 | | - "MAX_MEMORY=" CTIMEOPT_VAL(SQLITE_MAX_MEMORY), |
| 457 | | -#endif |
| 458 | | -#ifdef SQLITE_MAX_MMAP_SIZE |
| 459 | | - "MAX_MMAP_SIZE=" CTIMEOPT_VAL(SQLITE_MAX_MMAP_SIZE), |
| 460 | | -#endif |
| 461 | | -#ifdef SQLITE_MAX_MMAP_SIZE_ |
| 462 | | - "MAX_MMAP_SIZE_=" CTIMEOPT_VAL(SQLITE_MAX_MMAP_SIZE_), |
| 463 | | -#endif |
| 464 | | -#ifdef SQLITE_MAX_PAGE_COUNT |
| 465 | | - "MAX_PAGE_COUNT=" CTIMEOPT_VAL(SQLITE_MAX_PAGE_COUNT), |
| 466 | | -#endif |
| 467 | | -#ifdef SQLITE_MAX_PAGE_SIZE |
| 468 | | - "MAX_PAGE_SIZE=" CTIMEOPT_VAL(SQLITE_MAX_PAGE_SIZE), |
| 469 | | -#endif |
| 470 | | -#ifdef SQLITE_MAX_SCHEMA_RETRY |
| 471 | | - "MAX_SCHEMA_RETRY=" CTIMEOPT_VAL(SQLITE_MAX_SCHEMA_RETRY), |
| 472 | | -#endif |
| 473 | | -#ifdef SQLITE_MAX_SQL_LENGTH |
| 474 | | - "MAX_SQL_LENGTH=" CTIMEOPT_VAL(SQLITE_MAX_SQL_LENGTH), |
| 475 | | -#endif |
| 476 | | -#ifdef SQLITE_MAX_TRIGGER_DEPTH |
| 477 | | - "MAX_TRIGGER_DEPTH=" CTIMEOPT_VAL(SQLITE_MAX_TRIGGER_DEPTH), |
| 478 | | -#endif |
| 479 | | -#ifdef SQLITE_MAX_VARIABLE_NUMBER |
| 480 | | - "MAX_VARIABLE_NUMBER=" CTIMEOPT_VAL(SQLITE_MAX_VARIABLE_NUMBER), |
| 481 | | -#endif |
| 482 | | -#ifdef SQLITE_MAX_VDBE_OP |
| 483 | | - "MAX_VDBE_OP=" CTIMEOPT_VAL(SQLITE_MAX_VDBE_OP), |
| 484 | | -#endif |
| 485 | | -#ifdef SQLITE_MAX_WORKER_THREADS |
| 486 | | - "MAX_WORKER_THREADS=" CTIMEOPT_VAL(SQLITE_MAX_WORKER_THREADS), |
| 487 | | -#endif |
| 488 | | -#if SQLITE_MEMDEBUG |
| 489 | | - "MEMDEBUG", |
| 490 | | -#endif |
| 491 | | -#if SQLITE_MIXED_ENDIAN_64BIT_FLOAT |
| 492 | | - "MIXED_ENDIAN_64BIT_FLOAT", |
| 493 | | -#endif |
| 494 | | -#if SQLITE_MMAP_READWRITE |
| 495 | | - "MMAP_READWRITE", |
| 496 | | -#endif |
| 497 | | -#if SQLITE_MUTEX_NOOP |
| 498 | | - "MUTEX_NOOP", |
| 499 | | -#endif |
| 500 | | -#if SQLITE_MUTEX_OMIT |
| 501 | | - "MUTEX_OMIT", |
| 502 | | -#endif |
| 503 | | -#if SQLITE_MUTEX_PTHREADS |
| 504 | | - "MUTEX_PTHREADS", |
| 505 | | -#endif |
| 506 | | -#if SQLITE_MUTEX_W32 |
| 507 | | - "MUTEX_W32", |
| 508 | | -#endif |
| 509 | | -#if SQLITE_NEED_ERR_NAME |
| 510 | | - "NEED_ERR_NAME", |
| 511 | | -#endif |
| 512 | | -#if SQLITE_NOINLINE |
| 513 | | - "NOINLINE", |
| 514 | | -#endif |
| 515 | | -#if SQLITE_NO_SYNC |
| 516 | | - "NO_SYNC", |
| 517 | | -#endif |
| 518 | | -#if SQLITE_OMIT_ALTERTABLE |
| 519 | | - "OMIT_ALTERTABLE", |
| 520 | | -#endif |
| 521 | | -#if SQLITE_OMIT_ANALYZE |
| 522 | | - "OMIT_ANALYZE", |
| 523 | | -#endif |
| 524 | | -#if SQLITE_OMIT_ATTACH |
| 525 | | - "OMIT_ATTACH", |
| 526 | | -#endif |
| 527 | | -#if SQLITE_OMIT_AUTHORIZATION |
| 528 | | - "OMIT_AUTHORIZATION", |
| 529 | | -#endif |
| 530 | | -#if SQLITE_OMIT_AUTOINCREMENT |
| 531 | | - "OMIT_AUTOINCREMENT", |
| 532 | | -#endif |
| 533 | | -#if SQLITE_OMIT_AUTOINIT |
| 534 | | - "OMIT_AUTOINIT", |
| 535 | | -#endif |
| 536 | | -#if SQLITE_OMIT_AUTOMATIC_INDEX |
| 537 | | - "OMIT_AUTOMATIC_INDEX", |
| 538 | | -#endif |
| 539 | | -#if SQLITE_OMIT_AUTORESET |
| 540 | | - "OMIT_AUTORESET", |
| 541 | | -#endif |
| 542 | | -#if SQLITE_OMIT_AUTOVACUUM |
| 543 | | - "OMIT_AUTOVACUUM", |
| 544 | | -#endif |
| 545 | | -#if SQLITE_OMIT_BETWEEN_OPTIMIZATION |
| 546 | | - "OMIT_BETWEEN_OPTIMIZATION", |
| 547 | | -#endif |
| 548 | | -#if SQLITE_OMIT_BLOB_LITERAL |
| 549 | | - "OMIT_BLOB_LITERAL", |
| 550 | | -#endif |
| 551 | | -#if SQLITE_OMIT_CAST |
| 552 | | - "OMIT_CAST", |
| 553 | | -#endif |
| 554 | | -#if SQLITE_OMIT_CHECK |
| 555 | | - "OMIT_CHECK", |
| 556 | | -#endif |
| 557 | | -#if SQLITE_OMIT_COMPLETE |
| 558 | | - "OMIT_COMPLETE", |
| 559 | | -#endif |
| 560 | | -#if SQLITE_OMIT_COMPOUND_SELECT |
| 561 | | - "OMIT_COMPOUND_SELECT", |
| 562 | | -#endif |
| 563 | | -#if SQLITE_OMIT_CONFLICT_CLAUSE |
| 564 | | - "OMIT_CONFLICT_CLAUSE", |
| 565 | | -#endif |
| 566 | | -#if SQLITE_OMIT_CTE |
| 567 | | - "OMIT_CTE", |
| 568 | | -#endif |
| 569 | | -#if defined(SQLITE_OMIT_DATETIME_FUNCS) || defined(SQLITE_OMIT_FLOATING_POINT) |
| 570 | | - "OMIT_DATETIME_FUNCS", |
| 571 | | -#endif |
| 572 | | -#if SQLITE_OMIT_DECLTYPE |
| 573 | | - "OMIT_DECLTYPE", |
| 574 | | -#endif |
| 575 | | -#if SQLITE_OMIT_DEPRECATED |
| 576 | | - "OMIT_DEPRECATED", |
| 577 | | -#endif |
| 578 | | -#if SQLITE_OMIT_DESERIALIZE |
| 579 | | - "OMIT_DESERIALIZE", |
| 580 | | -#endif |
| 581 | | -#if SQLITE_OMIT_DISKIO |
| 582 | | - "OMIT_DISKIO", |
| 583 | | -#endif |
| 584 | | -#if SQLITE_OMIT_EXPLAIN |
| 585 | | - "OMIT_EXPLAIN", |
| 586 | | -#endif |
| 587 | | -#if SQLITE_OMIT_FLAG_PRAGMAS |
| 588 | | - "OMIT_FLAG_PRAGMAS", |
| 589 | | -#endif |
| 590 | | -#if SQLITE_OMIT_FLOATING_POINT |
| 591 | | - "OMIT_FLOATING_POINT", |
| 592 | | -#endif |
| 593 | | -#if SQLITE_OMIT_FOREIGN_KEY |
| 594 | | - "OMIT_FOREIGN_KEY", |
| 595 | | -#endif |
| 596 | | -#if SQLITE_OMIT_GET_TABLE |
| 597 | | - "OMIT_GET_TABLE", |
| 598 | | -#endif |
| 599 | | -#if SQLITE_OMIT_HEX_INTEGER |
| 600 | | - "OMIT_HEX_INTEGER", |
| 601 | | -#endif |
| 602 | | -#if SQLITE_OMIT_INCRBLOB |
| 603 | | - "OMIT_INCRBLOB", |
| 604 | | -#endif |
| 605 | | -#if SQLITE_OMIT_INTEGRITY_CHECK |
| 606 | | - "OMIT_INTEGRITY_CHECK", |
| 607 | | -#endif |
| 608 | | -#if SQLITE_OMIT_INTROSPECTION_PRAGMAS |
| 609 | | - "OMIT_INTROSPECTION_PRAGMAS", |
| 610 | | -#endif |
| 611 | | -#if SQLITE_OMIT_LIKE_OPTIMIZATION |
| 612 | | - "OMIT_LIKE_OPTIMIZATION", |
| 613 | | -#endif |
| 614 | | -#if SQLITE_OMIT_LOAD_EXTENSION |
| 615 | | - "OMIT_LOAD_EXTENSION", |
| 616 | | -#endif |
| 617 | | -#if SQLITE_OMIT_LOCALTIME |
| 618 | | - "OMIT_LOCALTIME", |
| 619 | | -#endif |
| 620 | | -#if SQLITE_OMIT_LOOKASIDE |
| 621 | | - "OMIT_LOOKASIDE", |
| 622 | | -#endif |
| 623 | | -#if SQLITE_OMIT_MEMORYDB |
| 624 | | - "OMIT_MEMORYDB", |
| 625 | | -#endif |
| 626 | | -#if SQLITE_OMIT_OR_OPTIMIZATION |
| 627 | | - "OMIT_OR_OPTIMIZATION", |
| 628 | | -#endif |
| 629 | | -#if SQLITE_OMIT_PAGER_PRAGMAS |
| 630 | | - "OMIT_PAGER_PRAGMAS", |
| 631 | | -#endif |
| 632 | | -#if SQLITE_OMIT_PARSER_TRACE |
| 633 | | - "OMIT_PARSER_TRACE", |
| 634 | | -#endif |
| 635 | | -#if SQLITE_OMIT_POPEN |
| 636 | | - "OMIT_POPEN", |
| 637 | | -#endif |
| 638 | | -#if SQLITE_OMIT_PRAGMA |
| 639 | | - "OMIT_PRAGMA", |
| 640 | | -#endif |
| 641 | | -#if SQLITE_OMIT_PROGRESS_CALLBACK |
| 642 | | - "OMIT_PROGRESS_CALLBACK", |
| 643 | | -#endif |
| 644 | | -#if SQLITE_OMIT_QUICKBALANCE |
| 645 | | - "OMIT_QUICKBALANCE", |
| 646 | | -#endif |
| 647 | | -#if SQLITE_OMIT_REINDEX |
| 648 | | - "OMIT_REINDEX", |
| 649 | | -#endif |
| 650 | | -#if SQLITE_OMIT_SCHEMA_PRAGMAS |
| 651 | | - "OMIT_SCHEMA_PRAGMAS", |
| 652 | | -#endif |
| 653 | | -#if SQLITE_OMIT_SCHEMA_VERSION_PRAGMAS |
| 654 | | - "OMIT_SCHEMA_VERSION_PRAGMAS", |
| 655 | | -#endif |
| 656 | | -#if SQLITE_OMIT_SHARED_CACHE |
| 657 | | - "OMIT_SHARED_CACHE", |
| 658 | | -#endif |
| 659 | | -#if SQLITE_OMIT_SHUTDOWN_DIRECTORIES |
| 660 | | - "OMIT_SHUTDOWN_DIRECTORIES", |
| 661 | | -#endif |
| 662 | | -#if SQLITE_OMIT_SUBQUERY |
| 663 | | - "OMIT_SUBQUERY", |
| 664 | | -#endif |
| 665 | | -#if SQLITE_OMIT_TCL_VARIABLE |
| 666 | | - "OMIT_TCL_VARIABLE", |
| 667 | | -#endif |
| 668 | | -#if SQLITE_OMIT_TEMPDB |
| 669 | | - "OMIT_TEMPDB", |
| 670 | | -#endif |
| 671 | | -#if SQLITE_OMIT_TEST_CONTROL |
| 672 | | - "OMIT_TEST_CONTROL", |
| 673 | | -#endif |
| 674 | | -#ifdef SQLITE_OMIT_TRACE |
| 675 | | -# if SQLITE_OMIT_TRACE != 1 |
| 676 | | - "OMIT_TRACE=" CTIMEOPT_VAL(SQLITE_OMIT_TRACE), |
| 677 | | -# endif |
| 678 | | -#endif |
| 679 | | -#if SQLITE_OMIT_TRIGGER |
| 680 | | - "OMIT_TRIGGER", |
| 681 | | -#endif |
| 682 | | -#if SQLITE_OMIT_TRUNCATE_OPTIMIZATION |
| 683 | | - "OMIT_TRUNCATE_OPTIMIZATION", |
| 684 | | -#endif |
| 685 | | -#if SQLITE_OMIT_UTF16 |
| 686 | | - "OMIT_UTF16", |
| 687 | | -#endif |
| 688 | | -#if SQLITE_OMIT_VACUUM |
| 689 | | - "OMIT_VACUUM", |
| 690 | | -#endif |
| 691 | | -#if SQLITE_OMIT_VIEW |
| 692 | | - "OMIT_VIEW", |
| 693 | | -#endif |
| 694 | | -#if SQLITE_OMIT_VIRTUALTABLE |
| 695 | | - "OMIT_VIRTUALTABLE", |
| 696 | | -#endif |
| 697 | | -#if SQLITE_OMIT_WAL |
| 698 | | - "OMIT_WAL", |
| 699 | | -#endif |
| 700 | | -#if SQLITE_OMIT_WSD |
| 701 | | - "OMIT_WSD", |
| 702 | | -#endif |
| 703 | | -#if SQLITE_OMIT_XFER_OPT |
| 704 | | - "OMIT_XFER_OPT", |
| 705 | | -#endif |
| 706 | | -#if SQLITE_PCACHE_SEPARATE_HEADER |
| 707 | | - "PCACHE_SEPARATE_HEADER", |
| 708 | | -#endif |
| 709 | | -#if SQLITE_PERFORMANCE_TRACE |
| 710 | | - "PERFORMANCE_TRACE", |
| 711 | | -#endif |
| 712 | | -#ifdef SQLITE_POWERSAFE_OVERWRITE |
| 713 | | -# if SQLITE_POWERSAFE_OVERWRITE != 1 |
| 714 | | - "POWERSAFE_OVERWRITE=" CTIMEOPT_VAL(SQLITE_POWERSAFE_OVERWRITE), |
| 715 | | -# endif |
| 716 | | -#endif |
| 717 | | -#if SQLITE_PREFER_PROXY_LOCKING |
| 718 | | - "PREFER_PROXY_LOCKING", |
| 719 | | -#endif |
| 720 | | -#if SQLITE_PROXY_DEBUG |
| 721 | | - "PROXY_DEBUG", |
| 722 | | -#endif |
| 723 | | -#if SQLITE_REVERSE_UNORDERED_SELECTS |
| 724 | | - "REVERSE_UNORDERED_SELECTS", |
| 725 | | -#endif |
| 726 | | -#if SQLITE_RTREE_INT_ONLY |
| 727 | | - "RTREE_INT_ONLY", |
| 728 | | -#endif |
| 729 | | -#if SQLITE_SECURE_DELETE |
| 730 | | - "SECURE_DELETE", |
| 731 | | -#endif |
| 732 | | -#if SQLITE_SMALL_STACK |
| 733 | | - "SMALL_STACK", |
| 734 | | -#endif |
| 735 | | -#ifdef SQLITE_SORTER_PMASZ |
| 736 | | - "SORTER_PMASZ=" CTIMEOPT_VAL(SQLITE_SORTER_PMASZ), |
| 737 | | -#endif |
| 738 | | -#if SQLITE_SOUNDEX |
| 739 | | - "SOUNDEX", |
| 740 | | -#endif |
| 741 | | -#ifdef SQLITE_STAT4_SAMPLES |
| 742 | | - "STAT4_SAMPLES=" CTIMEOPT_VAL(SQLITE_STAT4_SAMPLES), |
| 743 | | -#endif |
| 744 | | -#ifdef SQLITE_STMTJRNL_SPILL |
| 745 | | - "STMTJRNL_SPILL=" CTIMEOPT_VAL(SQLITE_STMTJRNL_SPILL), |
| 746 | | -#endif |
| 747 | | -#if SQLITE_SUBSTR_COMPATIBILITY |
| 748 | | - "SUBSTR_COMPATIBILITY", |
| 749 | | -#endif |
| 750 | | -#if (!defined(SQLITE_WIN32_MALLOC) \ |
| 751 | | - && !defined(SQLITE_ZERO_MALLOC) \ |
| 752 | | - && !defined(SQLITE_MEMDEBUG) \ |
| 753 | | - ) || defined(SQLITE_SYSTEM_MALLOC) |
| 754 | | - "SYSTEM_MALLOC", |
| 755 | | -#endif |
| 756 | | -#if SQLITE_TCL |
| 757 | | - "TCL", |
| 758 | | -#endif |
| 759 | | -#ifdef SQLITE_TEMP_STORE |
| 760 | | - "TEMP_STORE=" CTIMEOPT_VAL(SQLITE_TEMP_STORE), |
| 761 | | -#endif |
| 762 | | -#if SQLITE_TEST |
| 763 | | - "TEST", |
| 764 | | -#endif |
| 765 | | -#if defined(SQLITE_THREADSAFE) |
| 766 | | - "THREADSAFE=" CTIMEOPT_VAL(SQLITE_THREADSAFE), |
| 767 | | -#elif defined(THREADSAFE) |
| 768 | | - "THREADSAFE=" CTIMEOPT_VAL(THREADSAFE), |
| 769 | | -#else |
| 770 | | - "THREADSAFE=1", |
| 771 | | -#endif |
| 772 | | -#if SQLITE_UNLINK_AFTER_CLOSE |
| 773 | | - "UNLINK_AFTER_CLOSE", |
| 774 | | -#endif |
| 775 | | -#if SQLITE_UNTESTABLE |
| 776 | | - "UNTESTABLE", |
| 777 | | -#endif |
| 778 | | -#if SQLITE_USER_AUTHENTICATION |
| 779 | | - "USER_AUTHENTICATION", |
| 780 | | -#endif |
| 781 | | -#if SQLITE_USE_ALLOCA |
| 782 | | - "USE_ALLOCA", |
| 783 | | -#endif |
| 784 | | -#if SQLITE_USE_FCNTL_TRACE |
| 785 | | - "USE_FCNTL_TRACE", |
| 786 | | -#endif |
| 787 | | -#if SQLITE_USE_URI |
| 788 | | - "USE_URI", |
| 789 | | -#endif |
| 790 | | -#if SQLITE_VDBE_COVERAGE |
| 791 | | - "VDBE_COVERAGE", |
| 792 | | -#endif |
| 793 | | -#if SQLITE_WIN32_MALLOC |
| 794 | | - "WIN32_MALLOC", |
| 795 | | -#endif |
| 796 | | -#if SQLITE_ZERO_MALLOC |
| 797 | | - "ZERO_MALLOC", |
| 798 | | -#endif |
| 799 | | -/* |
| 800 | | -** END CODE GENERATED BY tool/mkctime.tcl |
| 801 | | -*/ |
| 802 | | -}; |
| 803 | | - |
| 804 | | -SQLITE_PRIVATE const char **sqlite3CompileOptions(int *pnOpt){ |
| 805 | | - *pnOpt = sizeof(sqlite3azCompileOpt) / sizeof(sqlite3azCompileOpt[0]); |
| 806 | | - return (const char**)sqlite3azCompileOpt; |
| 807 | | -} |
| 808 | | - |
| 809 | | -#endif /* SQLITE_OMIT_COMPILEOPTION_DIAGS */ |
| 810 | | - |
| 811 | | -/************** End of ctime.c ***********************************************/ |
| 812 | 25 | /************** Begin file sqliteInt.h ***************************************/ |
| 813 | 26 | /* |
| 814 | 27 | ** 2001 September 15 |
| 815 | 28 | ** |
| 816 | 29 | ** The author disclaims copyright to this source code. In place of |
| | @@ -1071,10 +284,21 @@ |
| 1071 | 284 | defined(_WIN32) && !defined(_WIN64) && \ |
| 1072 | 285 | defined(__MINGW_MAJOR_VERSION) && __MINGW_MAJOR_VERSION >= 4 && \ |
| 1073 | 286 | defined(__MSVCRT__) |
| 1074 | 287 | # define _USE_32BIT_TIME_T |
| 1075 | 288 | #endif |
| 289 | + |
| 290 | +/* Optionally #include a user-defined header, whereby compilation options |
| 291 | +** may be set prior to where they take effect, but after platform setup. |
| 292 | +** If SQLITE_CUSTOM_INCLUDE=? is defined, its value names the #include |
| 293 | +** file. |
| 294 | +*/ |
| 295 | +#ifdef SQLITE_CUSTOM_INCLUDE |
| 296 | +# define INC_STRINGIFY_(f) #f |
| 297 | +# define INC_STRINGIFY(f) INC_STRINGIFY_(f) |
| 298 | +# include INC_STRINGIFY(SQLITE_CUSTOM_INCLUDE) |
| 299 | +#endif |
| 1076 | 300 | |
| 1077 | 301 | /* The public SQLite interface. The _FILE_OFFSET_BITS macro must appear |
| 1078 | 302 | ** first in QNX. Also, the _USE_32BIT_TIME_T macro must appear first for |
| 1079 | 303 | ** MinGW. |
| 1080 | 304 | */ |
| | @@ -1123,11 +347,34 @@ |
| 1123 | 347 | extern "C" { |
| 1124 | 348 | #endif |
| 1125 | 349 | |
| 1126 | 350 | |
| 1127 | 351 | /* |
| 1128 | | -** Provide the ability to override linkage features of the interface. |
| 352 | +** Facilitate override of interface linkage and calling conventions. |
| 353 | +** Be aware that these macros may not be used within this particular |
| 354 | +** translation of the amalgamation and its associated header file. |
| 355 | +** |
| 356 | +** The SQLITE_EXTERN and SQLITE_API macros are used to instruct the |
| 357 | +** compiler that the target identifier should have external linkage. |
| 358 | +** |
| 359 | +** The SQLITE_CDECL macro is used to set the calling convention for |
| 360 | +** public functions that accept a variable number of arguments. |
| 361 | +** |
| 362 | +** The SQLITE_APICALL macro is used to set the calling convention for |
| 363 | +** public functions that accept a fixed number of arguments. |
| 364 | +** |
| 365 | +** The SQLITE_STDCALL macro is no longer used and is now deprecated. |
| 366 | +** |
| 367 | +** The SQLITE_CALLBACK macro is used to set the calling convention for |
| 368 | +** function pointers. |
| 369 | +** |
| 370 | +** The SQLITE_SYSAPI macro is used to set the calling convention for |
| 371 | +** functions provided by the operating system. |
| 372 | +** |
| 373 | +** Currently, the SQLITE_CDECL, SQLITE_APICALL, SQLITE_CALLBACK, and |
| 374 | +** SQLITE_SYSAPI macros are used only when building for environments |
| 375 | +** that require non-default calling conventions. |
| 1129 | 376 | */ |
| 1130 | 377 | #ifndef SQLITE_EXTERN |
| 1131 | 378 | # define SQLITE_EXTERN extern |
| 1132 | 379 | #endif |
| 1133 | 380 | #ifndef SQLITE_API |
| | @@ -1203,13 +450,13 @@ |
| 1203 | 450 | ** |
| 1204 | 451 | ** See also: [sqlite3_libversion()], |
| 1205 | 452 | ** [sqlite3_libversion_number()], [sqlite3_sourceid()], |
| 1206 | 453 | ** [sqlite_version()] and [sqlite_source_id()]. |
| 1207 | 454 | */ |
| 1208 | | -#define SQLITE_VERSION "3.36.0" |
| 1209 | | -#define SQLITE_VERSION_NUMBER 3036000 |
| 1210 | | -#define SQLITE_SOURCE_ID "2021-06-14 20:41:20 e5a5acd6006133c5da4a7dd79726dbaa41c0d60ebeda890f848a6aafe5f9ef70" |
| 455 | +#define SQLITE_VERSION "3.37.0" |
| 456 | +#define SQLITE_VERSION_NUMBER 3037000 |
| 457 | +#define SQLITE_SOURCE_ID "2021-08-06 20:17:39 087b8b41c6ed76b55c11315e7e95679d67590be20ae21108b593d00bb7d1c57a" |
| 1211 | 458 | |
| 1212 | 459 | /* |
| 1213 | 460 | ** CAPI3REF: Run-Time Library Version Numbers |
| 1214 | 461 | ** KEYWORDS: sqlite3_version sqlite3_sourceid |
| 1215 | 462 | ** |
| | @@ -1596,10 +843,11 @@ |
| 1596 | 843 | #define SQLITE_CANTOPEN_ISDIR (SQLITE_CANTOPEN | (2<<8)) |
| 1597 | 844 | #define SQLITE_CANTOPEN_FULLPATH (SQLITE_CANTOPEN | (3<<8)) |
| 1598 | 845 | #define SQLITE_CANTOPEN_CONVPATH (SQLITE_CANTOPEN | (4<<8)) |
| 1599 | 846 | #define SQLITE_CANTOPEN_DIRTYWAL (SQLITE_CANTOPEN | (5<<8)) /* Not Used */ |
| 1600 | 847 | #define SQLITE_CANTOPEN_SYMLINK (SQLITE_CANTOPEN | (6<<8)) |
| 848 | +#define SQLITE_CANTOPEN_EXISTS (SQLITE_CANTOPEN | (7<<8)) |
| 1601 | 849 | #define SQLITE_CORRUPT_VTAB (SQLITE_CORRUPT | (1<<8)) |
| 1602 | 850 | #define SQLITE_CORRUPT_SEQUENCE (SQLITE_CORRUPT | (2<<8)) |
| 1603 | 851 | #define SQLITE_CORRUPT_INDEX (SQLITE_CORRUPT | (3<<8)) |
| 1604 | 852 | #define SQLITE_READONLY_RECOVERY (SQLITE_READONLY | (1<<8)) |
| 1605 | 853 | #define SQLITE_READONLY_CANTLOCK (SQLITE_READONLY | (2<<8)) |
| | @@ -3544,15 +2792,18 @@ |
| 3544 | 2792 | |
| 3545 | 2793 | /* |
| 3546 | 2794 | ** CAPI3REF: Count The Number Of Rows Modified |
| 3547 | 2795 | ** METHOD: sqlite3 |
| 3548 | 2796 | ** |
| 3549 | | -** ^This function returns the number of rows modified, inserted or |
| 2797 | +** ^These functions return the number of rows modified, inserted or |
| 3550 | 2798 | ** deleted by the most recently completed INSERT, UPDATE or DELETE |
| 3551 | 2799 | ** statement on the database connection specified by the only parameter. |
| 3552 | | -** ^Executing any other type of SQL statement does not modify the value |
| 3553 | | -** returned by this function. |
| 2800 | +** The two functions are identical except for the type of the return value |
| 2801 | +** and that if the number of rows modified by the most recent INSERT, UPDATE |
| 2802 | +** or DELETE is greater than the maximum value supported by type "int", then |
| 2803 | +** the return value of sqlite3_changes() is undefined. ^Executing any other |
| 2804 | +** type of SQL statement does not modify the value returned by these functions. |
| 3554 | 2805 | ** |
| 3555 | 2806 | ** ^Only changes made directly by the INSERT, UPDATE or DELETE statement are |
| 3556 | 2807 | ** considered - auxiliary changes caused by [CREATE TRIGGER | triggers], |
| 3557 | 2808 | ** [foreign key actions] or [REPLACE] constraint resolution are not counted. |
| 3558 | 2809 | ** |
| | @@ -3597,20 +2848,25 @@ |
| 3597 | 2848 | ** <li> the [changes() SQL function] |
| 3598 | 2849 | ** <li> the [data_version pragma] |
| 3599 | 2850 | ** </ul> |
| 3600 | 2851 | */ |
| 3601 | 2852 | SQLITE_API int sqlite3_changes(sqlite3*); |
| 2853 | +SQLITE_API sqlite3_int64 sqlite3_changes64(sqlite3*); |
| 3602 | 2854 | |
| 3603 | 2855 | /* |
| 3604 | 2856 | ** CAPI3REF: Total Number Of Rows Modified |
| 3605 | 2857 | ** METHOD: sqlite3 |
| 3606 | 2858 | ** |
| 3607 | | -** ^This function returns the total number of rows inserted, modified or |
| 2859 | +** ^These functions return the total number of rows inserted, modified or |
| 3608 | 2860 | ** deleted by all [INSERT], [UPDATE] or [DELETE] statements completed |
| 3609 | 2861 | ** since the database connection was opened, including those executed as |
| 3610 | | -** part of trigger programs. ^Executing any other type of SQL statement |
| 3611 | | -** does not affect the value returned by sqlite3_total_changes(). |
| 2862 | +** part of trigger programs. The two functions are identical except for the |
| 2863 | +** type of the return value and that if the number of rows modified by the |
| 2864 | +** connection exceeds the maximum value supported by type "int", then |
| 2865 | +** the return value of sqlite3_total_changes() is undefined. ^Executing |
| 2866 | +** any other type of SQL statement does not affect the value returned by |
| 2867 | +** sqlite3_total_changes(). |
| 3612 | 2868 | ** |
| 3613 | 2869 | ** ^Changes made as part of [foreign key actions] are included in the |
| 3614 | 2870 | ** count, but those made as part of REPLACE constraint resolution are |
| 3615 | 2871 | ** not. ^Changes to a view that are intercepted by INSTEAD OF triggers |
| 3616 | 2872 | ** are not counted. |
| | @@ -3634,10 +2890,11 @@ |
| 3634 | 2890 | ** <li> the [data_version pragma] |
| 3635 | 2891 | ** <li> the [SQLITE_FCNTL_DATA_VERSION] [file control] |
| 3636 | 2892 | ** </ul> |
| 3637 | 2893 | */ |
| 3638 | 2894 | SQLITE_API int sqlite3_total_changes(sqlite3*); |
| 2895 | +SQLITE_API sqlite3_int64 sqlite3_total_changes64(sqlite3*); |
| 3639 | 2896 | |
| 3640 | 2897 | /* |
| 3641 | 2898 | ** CAPI3REF: Interrupt A Long-Running Query |
| 3642 | 2899 | ** METHOD: sqlite3 |
| 3643 | 2900 | ** |
| | @@ -4465,10 +3722,16 @@ |
| 4465 | 3722 | ** the default shared cache setting provided by |
| 4466 | 3723 | ** [sqlite3_enable_shared_cache()].)^ |
| 4467 | 3724 | ** |
| 4468 | 3725 | ** [[OPEN_NOFOLLOW]] ^(<dt>[SQLITE_OPEN_NOFOLLOW]</dt> |
| 4469 | 3726 | ** <dd>The database filename is not allowed to be a symbolic link</dd> |
| 3727 | +** |
| 3728 | +** [[OPEN_EXCLUSIVE]] ^(<dt>[SQLITE_OPEN_EXCLUSIVE]</dt> |
| 3729 | +** <dd>This flag causes the open to fail if the database file already |
| 3730 | +** exists. The open will only be success if this flag is used in combination |
| 3731 | +** with the SQLITE_OPEN_CREATE and SQLITE_OPEN_READWRITE flags and if |
| 3732 | +** the file does not previously exist.</dd> |
| 4470 | 3733 | ** </dl>)^ |
| 4471 | 3734 | ** |
| 4472 | 3735 | ** If the 3rd parameter to sqlite3_open_v2() is not one of the |
| 4473 | 3736 | ** required combinations shown above optionally combined with other |
| 4474 | 3737 | ** [SQLITE_OPEN_READONLY | SQLITE_OPEN_* bits] |
| | @@ -5238,16 +4501,21 @@ |
| 5238 | 4501 | ** |
| 5239 | 4502 | ** ^The strings returned by sqlite3_sql(P) and sqlite3_normalized_sql(P) |
| 5240 | 4503 | ** are managed by SQLite and are automatically freed when the prepared |
| 5241 | 4504 | ** statement is finalized. |
| 5242 | 4505 | ** ^The string returned by sqlite3_expanded_sql(P), on the other hand, |
| 5243 | | -** is obtained from [sqlite3_malloc()] and must be free by the application |
| 4506 | +** is obtained from [sqlite3_malloc()] and must be freed by the application |
| 5244 | 4507 | ** by passing it to [sqlite3_free()]. |
| 4508 | +** |
| 4509 | +** ^The sqlite3_normalized_sql() interface is only available if |
| 4510 | +** the [SQLITE_ENABLE_NORMALIZE] compile-time option is defined. |
| 5245 | 4511 | */ |
| 5246 | 4512 | SQLITE_API const char *sqlite3_sql(sqlite3_stmt *pStmt); |
| 5247 | 4513 | SQLITE_API char *sqlite3_expanded_sql(sqlite3_stmt *pStmt); |
| 4514 | +#ifdef SQLITE_ENABLE_NORMALIZE |
| 5248 | 4515 | SQLITE_API const char *sqlite3_normalized_sql(sqlite3_stmt *pStmt); |
| 4516 | +#endif |
| 5249 | 4517 | |
| 5250 | 4518 | /* |
| 5251 | 4519 | ** CAPI3REF: Determine If An SQL Statement Writes The Database |
| 5252 | 4520 | ** METHOD: sqlite3_stmt |
| 5253 | 4521 | ** |
| | @@ -5458,21 +4726,21 @@ |
| 5458 | 4726 | ** contain embedded NULs. The result of expressions involving strings |
| 5459 | 4727 | ** with embedded NULs is undefined. |
| 5460 | 4728 | ** |
| 5461 | 4729 | ** ^The fifth argument to the BLOB and string binding interfaces controls |
| 5462 | 4730 | ** or indicates the lifetime of the object referenced by the third parameter. |
| 5463 | | -** ^These three options exist: |
| 5464 | | -** ^(1) A destructor to dispose of the BLOB or string after SQLite has finished |
| 4731 | +** These three options exist: |
| 4732 | +** ^ (1) A destructor to dispose of the BLOB or string after SQLite has finished |
| 5465 | 4733 | ** with it may be passed. ^It is called to dispose of the BLOB or string even |
| 5466 | 4734 | ** if the call to the bind API fails, except the destructor is not called if |
| 5467 | 4735 | ** the third parameter is a NULL pointer or the fourth parameter is negative. |
| 5468 | | -** ^(2) The special constant, [SQLITE_STATIC], may be passsed to indicate that |
| 4736 | +** ^ (2) The special constant, [SQLITE_STATIC], may be passsed to indicate that |
| 5469 | 4737 | ** the application remains responsible for disposing of the object. ^In this |
| 5470 | 4738 | ** case, the object and the provided pointer to it must remain valid until |
| 5471 | 4739 | ** either the prepared statement is finalized or the same SQL parameter is |
| 5472 | 4740 | ** bound to something else, whichever occurs sooner. |
| 5473 | | -** ^(3) The constant, [SQLITE_TRANSIENT], may be passed to indicate that the |
| 4741 | +** ^ (3) The constant, [SQLITE_TRANSIENT], may be passed to indicate that the |
| 5474 | 4742 | ** object is to be copied prior to the return from sqlite3_bind_*(). ^The |
| 5475 | 4743 | ** object and pointer to it must remain valid until then. ^SQLite will then |
| 5476 | 4744 | ** manage the lifetime of its private copy. |
| 5477 | 4745 | ** |
| 5478 | 4746 | ** ^The sixth argument to sqlite3_bind_text64() must be one of |
| | @@ -10090,12 +9358,13 @@ |
| 10090 | 9358 | ** that does not correspond to any valid SQLite error code, the results |
| 10091 | 9359 | ** are undefined. |
| 10092 | 9360 | ** |
| 10093 | 9361 | ** A single database handle may have at most a single write-ahead log callback |
| 10094 | 9362 | ** registered at one time. ^Calling [sqlite3_wal_hook()] replaces any |
| 10095 | | -** previously registered write-ahead log callback. ^Note that the |
| 10096 | | -** [sqlite3_wal_autocheckpoint()] interface and the |
| 9363 | +** previously registered write-ahead log callback. ^The return value is |
| 9364 | +** a copy of the third parameter from the previous call, if any, or 0. |
| 9365 | +** ^Note that the [sqlite3_wal_autocheckpoint()] interface and the |
| 10097 | 9366 | ** [wal_autocheckpoint pragma] both invoke [sqlite3_wal_hook()] and will |
| 10098 | 9367 | ** overwrite any prior [sqlite3_wal_hook()] settings. |
| 10099 | 9368 | */ |
| 10100 | 9369 | SQLITE_API void *sqlite3_wal_hook( |
| 10101 | 9370 | sqlite3*, |
| | @@ -10957,10 +10226,14 @@ |
| 10957 | 10226 | ** if writes on the database cause it to grow larger than M bytes. |
| 10958 | 10227 | ** |
| 10959 | 10228 | ** The sqlite3_deserialize() interface will fail with SQLITE_BUSY if the |
| 10960 | 10229 | ** database is currently in a read transaction or is involved in a backup |
| 10961 | 10230 | ** operation. |
| 10231 | +** |
| 10232 | +** It is not possible to deserialized into the TEMP database. If the |
| 10233 | +** S argument to sqlite3_deserialize(D,S,P,N,M,F) is "temp" then the |
| 10234 | +** function returns SQLITE_ERROR. |
| 10962 | 10235 | ** |
| 10963 | 10236 | ** If sqlite3_deserialize(D,S,P,N,M,F) fails for any reason and if the |
| 10964 | 10237 | ** SQLITE_DESERIALIZE_FREEONCLOSE bit is set in argument F, then |
| 10965 | 10238 | ** [sqlite3_free()] is invoked on argument P prior to returning. |
| 10966 | 10239 | ** |
| | @@ -13440,11 +12713,11 @@ |
| 13440 | 12713 | /* |
| 13441 | 12714 | ** Include the configuration header output by 'configure' if we're using the |
| 13442 | 12715 | ** autoconf-based build |
| 13443 | 12716 | */ |
| 13444 | 12717 | #if defined(_HAVE_SQLITE_CONFIG_H) && !defined(SQLITECONFIG_H) |
| 13445 | | -/* #include "config.h" */ |
| 12718 | +#include "config.h" |
| 13446 | 12719 | #define SQLITECONFIG_H 1 |
| 13447 | 12720 | #endif |
| 13448 | 12721 | |
| 13449 | 12722 | /************** Include sqliteLimit.h in the middle of sqliteInt.h ***********/ |
| 13450 | 12723 | /************** Begin file sqliteLimit.h *************************************/ |
| | @@ -13676,15 +12949,16 @@ |
| 13676 | 12949 | ** places. The following macros try to make this explicit. |
| 13677 | 12950 | */ |
| 13678 | 12951 | #ifndef __has_extension |
| 13679 | 12952 | # define __has_extension(x) 0 /* compatibility with non-clang compilers */ |
| 13680 | 12953 | #endif |
| 13681 | | -#if GCC_VERSION>=4007000 || \ |
| 13682 | | - (__has_extension(c_atomic) && __has_extension(c_atomic_store_n)) |
| 12954 | +#if GCC_VERSION>=4007000 || __has_extension(c_atomic) |
| 12955 | +# define SQLITE_ATOMIC_INTRINSICS 1 |
| 13683 | 12956 | # define AtomicLoad(PTR) __atomic_load_n((PTR),__ATOMIC_RELAXED) |
| 13684 | 12957 | # define AtomicStore(PTR,VAL) __atomic_store_n((PTR),(VAL),__ATOMIC_RELAXED) |
| 13685 | 12958 | #else |
| 12959 | +# define SQLITE_ATOMIC_INTRINSICS 0 |
| 13686 | 12960 | # define AtomicLoad(PTR) (*(PTR)) |
| 13687 | 12961 | # define AtomicStore(PTR,VAL) (*(PTR) = (VAL)) |
| 13688 | 12962 | #endif |
| 13689 | 12963 | |
| 13690 | 12964 | /* |
| | @@ -14598,10 +13872,11 @@ |
| 14598 | 13872 | #ifndef SQLITE_PTRSIZE |
| 14599 | 13873 | # if defined(__SIZEOF_POINTER__) |
| 14600 | 13874 | # define SQLITE_PTRSIZE __SIZEOF_POINTER__ |
| 14601 | 13875 | # elif defined(i386) || defined(__i386__) || defined(_M_IX86) || \ |
| 14602 | 13876 | defined(_M_ARM) || defined(__arm__) || defined(__x86) || \ |
| 13877 | + (defined(__APPLE__) && defined(__POWERPC__)) || \ |
| 14603 | 13878 | (defined(__TOS_AIX__) && !defined(__64BIT__)) |
| 14604 | 13879 | # define SQLITE_PTRSIZE 4 |
| 14605 | 13880 | # else |
| 14606 | 13881 | # define SQLITE_PTRSIZE 8 |
| 14607 | 13882 | # endif |
| | @@ -15349,11 +14624,11 @@ |
| 15349 | 14624 | */ |
| 15350 | 14625 | #define BTREE_INTKEY 1 /* Table has only 64-bit signed integer keys */ |
| 15351 | 14626 | #define BTREE_BLOBKEY 2 /* Table has keys only - no data */ |
| 15352 | 14627 | |
| 15353 | 14628 | SQLITE_PRIVATE int sqlite3BtreeDropTable(Btree*, int, int*); |
| 15354 | | -SQLITE_PRIVATE int sqlite3BtreeClearTable(Btree*, int, int*); |
| 14629 | +SQLITE_PRIVATE int sqlite3BtreeClearTable(Btree*, int, i64*); |
| 15355 | 14630 | SQLITE_PRIVATE int sqlite3BtreeClearTableOfCursor(BtCursor*); |
| 15356 | 14631 | SQLITE_PRIVATE int sqlite3BtreeTripAllCursors(Btree*, int, int); |
| 15357 | 14632 | |
| 15358 | 14633 | SQLITE_PRIVATE void sqlite3BtreeGetMeta(Btree *pBtree, int idx, u32 *pValue); |
| 15359 | 14634 | SQLITE_PRIVATE int sqlite3BtreeUpdateMeta(Btree*, int idx, u32 value); |
| | @@ -15473,16 +14748,20 @@ |
| 15473 | 14748 | #ifdef SQLITE_ENABLE_CURSOR_HINTS |
| 15474 | 14749 | SQLITE_PRIVATE void sqlite3BtreeCursorHint(BtCursor*, int, ...); |
| 15475 | 14750 | #endif |
| 15476 | 14751 | |
| 15477 | 14752 | SQLITE_PRIVATE int sqlite3BtreeCloseCursor(BtCursor*); |
| 15478 | | -SQLITE_PRIVATE int sqlite3BtreeMovetoUnpacked( |
| 14753 | +SQLITE_PRIVATE int sqlite3BtreeTableMoveto( |
| 15479 | 14754 | BtCursor*, |
| 15480 | | - UnpackedRecord *pUnKey, |
| 15481 | 14755 | i64 intKey, |
| 15482 | 14756 | int bias, |
| 15483 | 14757 | int *pRes |
| 14758 | +); |
| 14759 | +SQLITE_PRIVATE int sqlite3BtreeIndexMoveto( |
| 14760 | + BtCursor*, |
| 14761 | + UnpackedRecord *pUnKey, |
| 14762 | + int *pRes |
| 15484 | 14763 | ); |
| 15485 | 14764 | SQLITE_PRIVATE int sqlite3BtreeCursorHasMoved(BtCursor*); |
| 15486 | 14765 | SQLITE_PRIVATE int sqlite3BtreeCursorRestore(BtCursor*, int*); |
| 15487 | 14766 | SQLITE_PRIVATE int sqlite3BtreeDelete(BtCursor*, u8 flags); |
| 15488 | 14767 | |
| | @@ -17110,12 +16389,12 @@ |
| 17110 | 16389 | u8 mTrace; /* zero or more SQLITE_TRACE flags */ |
| 17111 | 16390 | u8 noSharedCache; /* True if no shared-cache backends */ |
| 17112 | 16391 | u8 nSqlExec; /* Number of pending OP_SqlExec opcodes */ |
| 17113 | 16392 | int nextPagesize; /* Pagesize after VACUUM if >0 */ |
| 17114 | 16393 | u32 magic; /* Magic number for detect library misuse */ |
| 17115 | | - int nChange; /* Value returned by sqlite3_changes() */ |
| 17116 | | - int nTotalChange; /* Value returned by sqlite3_total_changes() */ |
| 16394 | + i64 nChange; /* Value returned by sqlite3_changes() */ |
| 16395 | + i64 nTotalChange; /* Value returned by sqlite3_total_changes() */ |
| 17117 | 16396 | int aLimit[SQLITE_N_LIMIT]; /* Limits */ |
| 17118 | 16397 | int nMaxSorterMmap; /* Maximum size of regions mapped by sorter */ |
| 17119 | 16398 | struct sqlite3InitInfo { /* Information used during initialization */ |
| 17120 | 16399 | Pgno newTnum; /* Rootpage of table being initialized */ |
| 17121 | 16400 | u8 iDb; /* Which db file is being initialized */ |
| | @@ -17320,10 +16599,12 @@ |
| 17320 | 16599 | #define SQLITE_SimplifyJoin 0x00002000 /* Convert LEFT JOIN to JOIN */ |
| 17321 | 16600 | #define SQLITE_SkipScan 0x00004000 /* Skip-scans */ |
| 17322 | 16601 | #define SQLITE_PropagateConst 0x00008000 /* The constant propagation opt */ |
| 17323 | 16602 | #define SQLITE_MinMaxOpt 0x00010000 /* The min/max optimization */ |
| 17324 | 16603 | #define SQLITE_SeekScan 0x00020000 /* The OP_SeekScan optimization */ |
| 16604 | +#define SQLITE_OmitOrderBy 0x00040000 /* Omit pointless ORDER BY */ |
| 16605 | + /* TH3 expects this value ^^^^^^^^^^ to be 0x40000. Coordinate any change */ |
| 17325 | 16606 | #define SQLITE_AllOpts 0xffffffff /* All optimizations */ |
| 17326 | 16607 | |
| 17327 | 16608 | /* |
| 17328 | 16609 | ** Macros for testing whether or not optimizations are enabled or disabled. |
| 17329 | 16610 | */ |
| | @@ -17399,16 +16680,17 @@ |
| 17399 | 16680 | ** values must correspond to OPFLAG_LENGTHARG and OPFLAG_TYPEOFARG. And |
| 17400 | 16681 | ** SQLITE_FUNC_CONSTANT must be the same as SQLITE_DETERMINISTIC. There |
| 17401 | 16682 | ** are assert() statements in the code to verify this. |
| 17402 | 16683 | ** |
| 17403 | 16684 | ** Value constraints (enforced via assert()): |
| 17404 | | -** SQLITE_FUNC_MINMAX == NC_MinMaxAgg == SF_MinMaxAgg |
| 17405 | | -** SQLITE_FUNC_LENGTH == OPFLAG_LENGTHARG |
| 17406 | | -** SQLITE_FUNC_TYPEOF == OPFLAG_TYPEOFARG |
| 17407 | | -** SQLITE_FUNC_CONSTANT == SQLITE_DETERMINISTIC from the API |
| 17408 | | -** SQLITE_FUNC_DIRECT == SQLITE_DIRECTONLY from the API |
| 17409 | | -** SQLITE_FUNC_UNSAFE == SQLITE_INNOCUOUS |
| 16685 | +** SQLITE_FUNC_MINMAX == NC_MinMaxAgg == SF_MinMaxAgg |
| 16686 | +** SQLITE_FUNC_ANYORDER == NC_OrderAgg == SF_OrderByReqd |
| 16687 | +** SQLITE_FUNC_LENGTH == OPFLAG_LENGTHARG |
| 16688 | +** SQLITE_FUNC_TYPEOF == OPFLAG_TYPEOFARG |
| 16689 | +** SQLITE_FUNC_CONSTANT == SQLITE_DETERMINISTIC from the API |
| 16690 | +** SQLITE_FUNC_DIRECT == SQLITE_DIRECTONLY from the API |
| 16691 | +** SQLITE_FUNC_UNSAFE == SQLITE_INNOCUOUS |
| 17410 | 16692 | ** SQLITE_FUNC_ENCMASK depends on SQLITE_UTF* macros in the API |
| 17411 | 16693 | */ |
| 17412 | 16694 | #define SQLITE_FUNC_ENCMASK 0x0003 /* SQLITE_UTF8, SQLITE_UTF16BE or UTF16LE */ |
| 17413 | 16695 | #define SQLITE_FUNC_LIKE 0x0004 /* Candidate for the LIKE optimization */ |
| 17414 | 16696 | #define SQLITE_FUNC_CASE 0x0008 /* Case-sensitive LIKE-type function */ |
| | @@ -17429,10 +16711,11 @@ |
| 17429 | 16711 | #define SQLITE_FUNC_INTERNAL 0x00040000 /* For use by NestedParse() only */ |
| 17430 | 16712 | #define SQLITE_FUNC_DIRECT 0x00080000 /* Not for use in TRIGGERs or VIEWs */ |
| 17431 | 16713 | #define SQLITE_FUNC_SUBTYPE 0x00100000 /* Result likely to have sub-type */ |
| 17432 | 16714 | #define SQLITE_FUNC_UNSAFE 0x00200000 /* Function has side effects */ |
| 17433 | 16715 | #define SQLITE_FUNC_INLINE 0x00400000 /* Functions implemented in-line */ |
| 16716 | +#define SQLITE_FUNC_ANYORDER 0x08000000 /* count/min/max aggregate */ |
| 17434 | 16717 | |
| 17435 | 16718 | /* Identifier numbers for each in-line function */ |
| 17436 | 16719 | #define INLINEFUNC_coalesce 0 |
| 17437 | 16720 | #define INLINEFUNC_implies_nonnull_row 1 |
| 17438 | 16721 | #define INLINEFUNC_expr_implies_expr 2 |
| | @@ -17599,22 +16882,45 @@ |
| 17599 | 16882 | ** record BLOB generated by the OP_MakeRecord |
| 17600 | 16883 | ** opcode. The storage column index is less than |
| 17601 | 16884 | ** or equal to the table column index. It is |
| 17602 | 16885 | ** equal if and only if there are no VIRTUAL |
| 17603 | 16886 | ** columns to the left. |
| 16887 | +** |
| 16888 | +** Notes on zCnName: |
| 16889 | +** The zCnName field stores the name of the column, the datatype of the |
| 16890 | +** column, and the collating sequence for the column, in that order, all in |
| 16891 | +** a single allocation. Each string is 0x00 terminated. The datatype |
| 16892 | +** is only included if the COLFLAG_HASTYPE bit of colFlags is set and the |
| 16893 | +** collating sequence name is only included if the COLFLAG_HASCOLL bit is |
| 16894 | +** set. |
| 17604 | 16895 | */ |
| 17605 | 16896 | struct Column { |
| 17606 | | - char *zName; /* Name of this column, \000, then the type */ |
| 17607 | | - Expr *pDflt; /* Default value or GENERATED ALWAYS AS value */ |
| 17608 | | - char *zColl; /* Collating sequence. If NULL, use the default */ |
| 17609 | | - u8 notNull; /* An OE_ code for handling a NOT NULL constraint */ |
| 17610 | | - char affinity; /* One of the SQLITE_AFF_... values */ |
| 17611 | | - u8 szEst; /* Estimated size of value in this column. sizeof(INT)==1 */ |
| 17612 | | - u8 hName; /* Column name hash for faster lookup */ |
| 17613 | | - u16 colFlags; /* Boolean properties. See COLFLAG_ defines below */ |
| 16897 | + char *zCnName; /* Name of this column */ |
| 16898 | + unsigned notNull :4; /* An OE_ code for handling a NOT NULL constraint */ |
| 16899 | + unsigned eType :4; /* One of the standard types */ |
| 16900 | + char affinity; /* One of the SQLITE_AFF_... values */ |
| 16901 | + u8 szEst; /* Est size of value in this column. sizeof(INT)==1 */ |
| 16902 | + u8 hName; /* Column name hash for faster lookup */ |
| 16903 | + u16 iDflt; /* 1-based index of DEFAULT. 0 means "none" */ |
| 16904 | + u16 colFlags; /* Boolean properties. See COLFLAG_ defines below */ |
| 17614 | 16905 | }; |
| 17615 | 16906 | |
| 16907 | +/* Allowed values for Column.eType. |
| 16908 | +** |
| 16909 | +** Values must match entries in the global constant arrays |
| 16910 | +** sqlite3StdTypeLen[] and sqlite3StdType[]. Each value is one more |
| 16911 | +** than the offset into these arrays for the corresponding name. |
| 16912 | +** Adjust the SQLITE_N_STDTYPE value if adding or removing entries. |
| 16913 | +*/ |
| 16914 | +#define COLTYPE_CUSTOM 0 /* Type appended to zName */ |
| 16915 | +#define COLTYPE_BLOB 1 |
| 16916 | +#define COLTYPE_INT 2 |
| 16917 | +#define COLTYPE_INTEGER 3 |
| 16918 | +#define COLTYPE_REAL 4 |
| 16919 | +#define COLTYPE_TEXT 5 |
| 16920 | +#define SQLITE_N_STDTYPE 5 /* Number of standard types */ |
| 16921 | + |
| 17616 | 16922 | /* Allowed values for Column.colFlags. |
| 17617 | 16923 | ** |
| 17618 | 16924 | ** Constraints: |
| 17619 | 16925 | ** TF_HasVirtual == COLFLAG_VIRTUAL |
| 17620 | 16926 | ** TF_HasStored == COLFLAG_STORED |
| | @@ -17627,10 +16933,11 @@ |
| 17627 | 16933 | #define COLFLAG_SORTERREF 0x0010 /* Use sorter-refs with this column */ |
| 17628 | 16934 | #define COLFLAG_VIRTUAL 0x0020 /* GENERATED ALWAYS AS ... VIRTUAL */ |
| 17629 | 16935 | #define COLFLAG_STORED 0x0040 /* GENERATED ALWAYS AS ... STORED */ |
| 17630 | 16936 | #define COLFLAG_NOTAVAIL 0x0080 /* STORED column not yet calculated */ |
| 17631 | 16937 | #define COLFLAG_BUSY 0x0100 /* Blocks recursion on GENERATED columns */ |
| 16938 | +#define COLFLAG_HASCOLL 0x0200 /* Has collating sequence name in zCnName */ |
| 17632 | 16939 | #define COLFLAG_GENERATED 0x0060 /* Combo: _STORED, _VIRTUAL */ |
| 17633 | 16940 | #define COLFLAG_NOINSERT 0x0062 /* Combo: _HIDDEN, _STORED, _VIRTUAL */ |
| 17634 | 16941 | |
| 17635 | 16942 | /* |
| 17636 | 16943 | ** A "Collating Sequence" is defined by an instance of the following |
| | @@ -17756,19 +17063,17 @@ |
| 17756 | 17063 | #define SQLITE_VTABRISK_Low 0 |
| 17757 | 17064 | #define SQLITE_VTABRISK_Normal 1 |
| 17758 | 17065 | #define SQLITE_VTABRISK_High 2 |
| 17759 | 17066 | |
| 17760 | 17067 | /* |
| 17761 | | -** The schema for each SQL table and view is represented in memory |
| 17762 | | -** by an instance of the following structure. |
| 17068 | +** The schema for each SQL table, virtual table, and view is represented |
| 17069 | +** in memory by an instance of the following structure. |
| 17763 | 17070 | */ |
| 17764 | 17071 | struct Table { |
| 17765 | 17072 | char *zName; /* Name of the table or view */ |
| 17766 | 17073 | Column *aCol; /* Information about each column */ |
| 17767 | 17074 | Index *pIndex; /* List of SQL indexes on this table. */ |
| 17768 | | - Select *pSelect; /* NULL for tables. Points to definition if a view. */ |
| 17769 | | - FKey *pFKey; /* Linked list of all foreign keys in this table */ |
| 17770 | 17075 | char *zColAff; /* String defining the affinity of each column */ |
| 17771 | 17076 | ExprList *pCheck; /* All CHECK constraints */ |
| 17772 | 17077 | /* ... also used as column name list in a VIEW */ |
| 17773 | 17078 | Pgno tnum; /* Root BTree page for this table */ |
| 17774 | 17079 | u32 nTabRef; /* Number of pointers to this Table */ |
| | @@ -17780,19 +17085,28 @@ |
| 17780 | 17085 | LogEst szTabRow; /* Estimated size of each table row in bytes */ |
| 17781 | 17086 | #ifdef SQLITE_ENABLE_COSTMULT |
| 17782 | 17087 | LogEst costMult; /* Cost multiplier for using this table */ |
| 17783 | 17088 | #endif |
| 17784 | 17089 | u8 keyConf; /* What to do in case of uniqueness conflict on iPKey */ |
| 17785 | | -#ifndef SQLITE_OMIT_ALTERTABLE |
| 17786 | | - int addColOffset; /* Offset in CREATE TABLE stmt to add a new column */ |
| 17787 | | -#endif |
| 17788 | | -#ifndef SQLITE_OMIT_VIRTUALTABLE |
| 17789 | | - int nModuleArg; /* Number of arguments to the module */ |
| 17790 | | - char **azModuleArg; /* 0: module 1: schema 2: vtab name 3...: args */ |
| 17791 | | - VTable *pVTable; /* List of VTable objects. */ |
| 17792 | | -#endif |
| 17793 | | - Trigger *pTrigger; /* List of triggers stored in pSchema */ |
| 17090 | + u8 eTabType; /* 0: normal, 1: virtual, 2: view */ |
| 17091 | + union { |
| 17092 | + struct { /* Used by ordinary tables: */ |
| 17093 | + int addColOffset; /* Offset in CREATE TABLE stmt to add a new column */ |
| 17094 | + FKey *pFKey; /* Linked list of all foreign keys in this table */ |
| 17095 | + ExprList *pDfltList; /* DEFAULT clauses on various columns. |
| 17096 | + ** Or the AS clause for generated columns. */ |
| 17097 | + } tab; |
| 17098 | + struct { /* Used by views: */ |
| 17099 | + Select *pSelect; /* View definition */ |
| 17100 | + } view; |
| 17101 | + struct { /* Used by virtual tables only: */ |
| 17102 | + int nArg; /* Number of arguments to the module */ |
| 17103 | + char **azArg; /* 0: module 1: schema 2: vtab name 3...: args */ |
| 17104 | + VTable *p; /* List of VTable objects. */ |
| 17105 | + } vtab; |
| 17106 | + } u; |
| 17107 | + Trigger *pTrigger; /* List of triggers on this object */ |
| 17794 | 17108 | Schema *pSchema; /* Schema that contains this table */ |
| 17795 | 17109 | }; |
| 17796 | 17110 | |
| 17797 | 17111 | /* |
| 17798 | 17112 | ** Allowed values for Table.tabFlags. |
| | @@ -17807,38 +17121,48 @@ |
| 17807 | 17121 | ** |
| 17808 | 17122 | ** TF_HasVirtual == COLFLAG_VIRTUAL |
| 17809 | 17123 | ** TF_HasStored == COLFLAG_STORED |
| 17810 | 17124 | ** TF_HasHidden == COLFLAG_HIDDEN |
| 17811 | 17125 | */ |
| 17812 | | -#define TF_Readonly 0x0001 /* Read-only system table */ |
| 17813 | | -#define TF_HasHidden 0x0002 /* Has one or more hidden columns */ |
| 17814 | | -#define TF_HasPrimaryKey 0x0004 /* Table has a primary key */ |
| 17815 | | -#define TF_Autoincrement 0x0008 /* Integer primary key is autoincrement */ |
| 17816 | | -#define TF_HasStat1 0x0010 /* nRowLogEst set from sqlite_stat1 */ |
| 17817 | | -#define TF_HasVirtual 0x0020 /* Has one or more VIRTUAL columns */ |
| 17818 | | -#define TF_HasStored 0x0040 /* Has one or more STORED columns */ |
| 17819 | | -#define TF_HasGenerated 0x0060 /* Combo: HasVirtual + HasStored */ |
| 17820 | | -#define TF_WithoutRowid 0x0080 /* No rowid. PRIMARY KEY is the key */ |
| 17821 | | -#define TF_StatsUsed 0x0100 /* Query planner decisions affected by |
| 17126 | +#define TF_Readonly 0x00000001 /* Read-only system table */ |
| 17127 | +#define TF_HasHidden 0x00000002 /* Has one or more hidden columns */ |
| 17128 | +#define TF_HasPrimaryKey 0x00000004 /* Table has a primary key */ |
| 17129 | +#define TF_Autoincrement 0x00000008 /* Integer primary key is autoincrement */ |
| 17130 | +#define TF_HasStat1 0x00000010 /* nRowLogEst set from sqlite_stat1 */ |
| 17131 | +#define TF_HasVirtual 0x00000020 /* Has one or more VIRTUAL columns */ |
| 17132 | +#define TF_HasStored 0x00000040 /* Has one or more STORED columns */ |
| 17133 | +#define TF_HasGenerated 0x00000060 /* Combo: HasVirtual + HasStored */ |
| 17134 | +#define TF_WithoutRowid 0x00000080 /* No rowid. PRIMARY KEY is the key */ |
| 17135 | +#define TF_StatsUsed 0x00000100 /* Query planner decisions affected by |
| 17822 | 17136 | ** Index.aiRowLogEst[] values */ |
| 17823 | | -#define TF_NoVisibleRowid 0x0200 /* No user-visible "rowid" column */ |
| 17824 | | -#define TF_OOOHidden 0x0400 /* Out-of-Order hidden columns */ |
| 17825 | | -#define TF_HasNotNull 0x0800 /* Contains NOT NULL constraints */ |
| 17826 | | -#define TF_Shadow 0x1000 /* True for a shadow table */ |
| 17827 | | -#define TF_HasStat4 0x2000 /* STAT4 info available for this table */ |
| 17828 | | -#define TF_Ephemeral 0x4000 /* An ephemeral table */ |
| 17829 | | -#define TF_Eponymous 0x8000 /* An eponymous virtual table */ |
| 17137 | +#define TF_NoVisibleRowid 0x00000200 /* No user-visible "rowid" column */ |
| 17138 | +#define TF_OOOHidden 0x00000400 /* Out-of-Order hidden columns */ |
| 17139 | +#define TF_HasNotNull 0x00000800 /* Contains NOT NULL constraints */ |
| 17140 | +#define TF_Shadow 0x00001000 /* True for a shadow table */ |
| 17141 | +#define TF_HasStat4 0x00002000 /* STAT4 info available for this table */ |
| 17142 | +#define TF_Ephemeral 0x00004000 /* An ephemeral table */ |
| 17143 | +#define TF_Eponymous 0x00008000 /* An eponymous virtual table */ |
| 17144 | + |
| 17145 | +/* |
| 17146 | +** Allowed values for Table.eTabType |
| 17147 | +*/ |
| 17148 | +#define TABTYP_NORM 0 /* Ordinary table */ |
| 17149 | +#define TABTYP_VTAB 1 /* Virtual table */ |
| 17150 | +#define TABTYP_VIEW 2 /* A view */ |
| 17151 | + |
| 17152 | +#define IsView(X) ((X)->eTabType==TABTYP_VIEW) |
| 17153 | +#define IsOrdinaryTable(X) ((X)->eTabType==TABTYP_NORM) |
| 17830 | 17154 | |
| 17831 | 17155 | /* |
| 17832 | 17156 | ** Test to see whether or not a table is a virtual table. This is |
| 17833 | 17157 | ** done as a macro so that it will be optimized out when virtual |
| 17834 | 17158 | ** table support is omitted from the build. |
| 17835 | 17159 | */ |
| 17836 | 17160 | #ifndef SQLITE_OMIT_VIRTUALTABLE |
| 17837 | | -# define IsVirtual(X) ((X)->nModuleArg) |
| 17161 | +# define IsVirtual(X) ((X)->eTabType==TABTYP_VTAB) |
| 17838 | 17162 | # define ExprIsVtab(X) \ |
| 17839 | | - ((X)->op==TK_COLUMN && (X)->y.pTab!=0 && (X)->y.pTab->nModuleArg) |
| 17163 | + ((X)->op==TK_COLUMN && (X)->y.pTab!=0 && (X)->y.pTab->eTabType==TABTYP_VTAB) |
| 17840 | 17164 | #else |
| 17841 | 17165 | # define IsVirtual(X) 0 |
| 17842 | 17166 | # define ExprIsVtab(X) 0 |
| 17843 | 17167 | #endif |
| 17844 | 17168 | |
| | @@ -18664,35 +17988,37 @@ |
| 18664 | 17988 | |
| 18665 | 17989 | /* |
| 18666 | 17990 | ** Allowed values for the NameContext, ncFlags field. |
| 18667 | 17991 | ** |
| 18668 | 17992 | ** Value constraints (all checked via assert()): |
| 18669 | | -** NC_HasAgg == SF_HasAgg == EP_Agg |
| 18670 | | -** NC_MinMaxAgg == SF_MinMaxAgg == SQLITE_FUNC_MINMAX |
| 17993 | +** NC_HasAgg == SF_HasAgg == EP_Agg |
| 17994 | +** NC_MinMaxAgg == SF_MinMaxAgg == SQLITE_FUNC_MINMAX |
| 17995 | +** NC_OrderAgg == SF_OrderByReqd == SQLITE_FUNC_ANYORDER |
| 18671 | 17996 | ** NC_HasWin == EP_Win |
| 18672 | 17997 | ** |
| 18673 | 17998 | */ |
| 18674 | | -#define NC_AllowAgg 0x00001 /* Aggregate functions are allowed here */ |
| 18675 | | -#define NC_PartIdx 0x00002 /* True if resolving a partial index WHERE */ |
| 18676 | | -#define NC_IsCheck 0x00004 /* True if resolving a CHECK constraint */ |
| 18677 | | -#define NC_GenCol 0x00008 /* True for a GENERATED ALWAYS AS clause */ |
| 18678 | | -#define NC_HasAgg 0x00010 /* One or more aggregate functions seen */ |
| 18679 | | -#define NC_IdxExpr 0x00020 /* True if resolving columns of CREATE INDEX */ |
| 18680 | | -#define NC_SelfRef 0x0002e /* Combo: PartIdx, isCheck, GenCol, and IdxExpr */ |
| 18681 | | -#define NC_VarSelect 0x00040 /* A correlated subquery has been seen */ |
| 18682 | | -#define NC_UEList 0x00080 /* True if uNC.pEList is used */ |
| 18683 | | -#define NC_UAggInfo 0x00100 /* True if uNC.pAggInfo is used */ |
| 18684 | | -#define NC_UUpsert 0x00200 /* True if uNC.pUpsert is used */ |
| 18685 | | -#define NC_UBaseReg 0x00400 /* True if uNC.iBaseReg is used */ |
| 18686 | | -#define NC_MinMaxAgg 0x01000 /* min/max aggregates seen. See note above */ |
| 18687 | | -#define NC_Complex 0x02000 /* True if a function or subquery seen */ |
| 18688 | | -#define NC_AllowWin 0x04000 /* Window functions are allowed here */ |
| 18689 | | -#define NC_HasWin 0x08000 /* One or more window functions seen */ |
| 18690 | | -#define NC_IsDDL 0x10000 /* Resolving names in a CREATE statement */ |
| 18691 | | -#define NC_InAggFunc 0x20000 /* True if analyzing arguments to an agg func */ |
| 18692 | | -#define NC_FromDDL 0x40000 /* SQL text comes from sqlite_schema */ |
| 18693 | | -#define NC_NoSelect 0x80000 /* Do not descend into sub-selects */ |
| 17999 | +#define NC_AllowAgg 0x000001 /* Aggregate functions are allowed here */ |
| 18000 | +#define NC_PartIdx 0x000002 /* True if resolving a partial index WHERE */ |
| 18001 | +#define NC_IsCheck 0x000004 /* True if resolving a CHECK constraint */ |
| 18002 | +#define NC_GenCol 0x000008 /* True for a GENERATED ALWAYS AS clause */ |
| 18003 | +#define NC_HasAgg 0x000010 /* One or more aggregate functions seen */ |
| 18004 | +#define NC_IdxExpr 0x000020 /* True if resolving columns of CREATE INDEX */ |
| 18005 | +#define NC_SelfRef 0x00002e /* Combo: PartIdx, isCheck, GenCol, and IdxExpr */ |
| 18006 | +#define NC_VarSelect 0x000040 /* A correlated subquery has been seen */ |
| 18007 | +#define NC_UEList 0x000080 /* True if uNC.pEList is used */ |
| 18008 | +#define NC_UAggInfo 0x000100 /* True if uNC.pAggInfo is used */ |
| 18009 | +#define NC_UUpsert 0x000200 /* True if uNC.pUpsert is used */ |
| 18010 | +#define NC_UBaseReg 0x000400 /* True if uNC.iBaseReg is used */ |
| 18011 | +#define NC_MinMaxAgg 0x001000 /* min/max aggregates seen. See note above */ |
| 18012 | +#define NC_Complex 0x002000 /* True if a function or subquery seen */ |
| 18013 | +#define NC_AllowWin 0x004000 /* Window functions are allowed here */ |
| 18014 | +#define NC_HasWin 0x008000 /* One or more window functions seen */ |
| 18015 | +#define NC_IsDDL 0x010000 /* Resolving names in a CREATE statement */ |
| 18016 | +#define NC_InAggFunc 0x020000 /* True if analyzing arguments to an agg func */ |
| 18017 | +#define NC_FromDDL 0x040000 /* SQL text comes from sqlite_schema */ |
| 18018 | +#define NC_NoSelect 0x080000 /* Do not descend into sub-selects */ |
| 18019 | +#define NC_OrderAgg 0x8000000 /* Has an aggregate other than count/min/max */ |
| 18694 | 18020 | |
| 18695 | 18021 | /* |
| 18696 | 18022 | ** An instance of the following object describes a single ON CONFLICT |
| 18697 | 18023 | ** clause in an upsert. |
| 18698 | 18024 | ** |
| | @@ -18771,13 +18097,14 @@ |
| 18771 | 18097 | /* |
| 18772 | 18098 | ** Allowed values for Select.selFlags. The "SF" prefix stands for |
| 18773 | 18099 | ** "Select Flag". |
| 18774 | 18100 | ** |
| 18775 | 18101 | ** Value constraints (all checked via assert()) |
| 18776 | | -** SF_HasAgg == NC_HasAgg |
| 18777 | | -** SF_MinMaxAgg == NC_MinMaxAgg == SQLITE_FUNC_MINMAX |
| 18778 | | -** SF_FixedLimit == WHERE_USE_LIMIT |
| 18102 | +** SF_HasAgg == NC_HasAgg |
| 18103 | +** SF_MinMaxAgg == NC_MinMaxAgg == SQLITE_FUNC_MINMAX |
| 18104 | +** SF_OrderByReqd == NC_OrderAgg == SQLITE_FUNC_ANYORDER |
| 18105 | +** SF_FixedLimit == WHERE_USE_LIMIT |
| 18779 | 18106 | */ |
| 18780 | 18107 | #define SF_Distinct 0x0000001 /* Output should be DISTINCT */ |
| 18781 | 18108 | #define SF_All 0x0000002 /* Includes the ALL keyword */ |
| 18782 | 18109 | #define SF_Resolved 0x0000004 /* Identifiers have been resolved */ |
| 18783 | 18110 | #define SF_Aggregate 0x0000008 /* Contains agg functions or a GROUP BY */ |
| | @@ -18798,14 +18125,15 @@ |
| 18798 | 18125 | #define SF_ComplexResult 0x0040000 /* Result contains subquery or function */ |
| 18799 | 18126 | #define SF_WhereBegin 0x0080000 /* Really a WhereBegin() call. Debug Only */ |
| 18800 | 18127 | #define SF_WinRewrite 0x0100000 /* Window function rewrite accomplished */ |
| 18801 | 18128 | #define SF_View 0x0200000 /* SELECT statement is a view */ |
| 18802 | 18129 | #define SF_NoopOrderBy 0x0400000 /* ORDER BY is ignored for this query */ |
| 18803 | | -#define SF_UpdateFrom 0x0800000 /* Statement is an UPDATE...FROM */ |
| 18130 | +#define SF_UFSrcCheck 0x0800000 /* Check pSrc as required by UPDATE...FROM */ |
| 18804 | 18131 | #define SF_PushDown 0x1000000 /* SELECT has be modified by push-down opt */ |
| 18805 | 18132 | #define SF_MultiPart 0x2000000 /* Has multiple incompatible PARTITIONs */ |
| 18806 | 18133 | #define SF_CopyCte 0x4000000 /* SELECT statement is a copy of a CTE */ |
| 18134 | +#define SF_OrderByReqd 0x8000000 /* The ORDER BY clause may not be omitted */ |
| 18807 | 18135 | |
| 18808 | 18136 | /* |
| 18809 | 18137 | ** The results of a SELECT can be distributed in several ways, as defined |
| 18810 | 18138 | ** by one of the following macros. The "SRT" prefix means "SELECT Result |
| 18811 | 18139 | ** Type". |
| | @@ -19884,10 +19212,11 @@ |
| 19884 | 19212 | SQLITE_PRIVATE void sqlite3SetString(char **, sqlite3*, const char*); |
| 19885 | 19213 | SQLITE_PRIVATE void sqlite3ErrorMsg(Parse*, const char*, ...); |
| 19886 | 19214 | SQLITE_PRIVATE int sqlite3ErrorToParser(sqlite3*,int); |
| 19887 | 19215 | SQLITE_PRIVATE void sqlite3Dequote(char*); |
| 19888 | 19216 | SQLITE_PRIVATE void sqlite3DequoteExpr(Expr*); |
| 19217 | +SQLITE_PRIVATE void sqlite3DequoteToken(Token*); |
| 19889 | 19218 | SQLITE_PRIVATE void sqlite3TokenInit(Token*,char*); |
| 19890 | 19219 | SQLITE_PRIVATE int sqlite3KeywordCode(const unsigned char*, int); |
| 19891 | 19220 | SQLITE_PRIVATE int sqlite3RunParser(Parse*, const char*, char **); |
| 19892 | 19221 | SQLITE_PRIVATE void sqlite3FinishCoding(Parse*); |
| 19893 | 19222 | SQLITE_PRIVATE int sqlite3GetTempReg(Parse*); |
| | @@ -19911,10 +19240,11 @@ |
| 19911 | 19240 | SQLITE_PRIVATE void sqlite3ExprDelete(sqlite3*, Expr*); |
| 19912 | 19241 | SQLITE_PRIVATE void sqlite3ExprDeferredDelete(Parse*, Expr*); |
| 19913 | 19242 | SQLITE_PRIVATE void sqlite3ExprUnmapAndDelete(Parse*, Expr*); |
| 19914 | 19243 | SQLITE_PRIVATE ExprList *sqlite3ExprListAppend(Parse*,ExprList*,Expr*); |
| 19915 | 19244 | SQLITE_PRIVATE ExprList *sqlite3ExprListAppendVector(Parse*,ExprList*,IdList*,Expr*); |
| 19245 | +SQLITE_PRIVATE Select *sqlite3ExprListToValues(Parse*, int, ExprList*); |
| 19916 | 19246 | SQLITE_PRIVATE void sqlite3ExprListSetSortOrder(ExprList*,int,int); |
| 19917 | 19247 | SQLITE_PRIVATE void sqlite3ExprListSetName(Parse*,ExprList*,Token*,int); |
| 19918 | 19248 | SQLITE_PRIVATE void sqlite3ExprListSetSpan(Parse*,ExprList*,const char*,const char*); |
| 19919 | 19249 | SQLITE_PRIVATE void sqlite3ExprListDelete(sqlite3*, ExprList*); |
| 19920 | 19250 | SQLITE_PRIVATE u32 sqlite3ExprListFlags(const ExprList*); |
| | @@ -19928,10 +19258,14 @@ |
| 19928 | 19258 | #endif |
| 19929 | 19259 | SQLITE_PRIVATE void sqlite3ResetAllSchemasOfConnection(sqlite3*); |
| 19930 | 19260 | SQLITE_PRIVATE void sqlite3ResetOneSchema(sqlite3*,int); |
| 19931 | 19261 | SQLITE_PRIVATE void sqlite3CollapseDatabaseArray(sqlite3*); |
| 19932 | 19262 | SQLITE_PRIVATE void sqlite3CommitInternalChanges(sqlite3*); |
| 19263 | +SQLITE_PRIVATE void sqlite3ColumnSetExpr(Parse*,Table*,Column*,Expr*); |
| 19264 | +SQLITE_PRIVATE Expr *sqlite3ColumnExpr(Table*,Column*); |
| 19265 | +SQLITE_PRIVATE void sqlite3ColumnSetColl(sqlite3*,Column*,const char*zColl); |
| 19266 | +SQLITE_PRIVATE const char *sqlite3ColumnColl(Column*); |
| 19933 | 19267 | SQLITE_PRIVATE void sqlite3DeleteColumnNames(sqlite3*,Table*); |
| 19934 | 19268 | SQLITE_PRIVATE void sqlite3GenerateColumnNames(Parse *pParse, Select *pSelect); |
| 19935 | 19269 | SQLITE_PRIVATE int sqlite3ColumnsFromExprList(Parse*,ExprList*,i16*,Column**); |
| 19936 | 19270 | SQLITE_PRIVATE void sqlite3SelectAddColumnTypeAndCollation(Parse*,Table*,Select*,char); |
| 19937 | 19271 | SQLITE_PRIVATE Table *sqlite3ResultSetOfSelect(Parse*,Select*,char); |
| | @@ -19949,11 +19283,11 @@ |
| 19949 | 19283 | #if SQLITE_ENABLE_HIDDEN_COLUMNS |
| 19950 | 19284 | SQLITE_PRIVATE void sqlite3ColumnPropertiesFromName(Table*, Column*); |
| 19951 | 19285 | #else |
| 19952 | 19286 | # define sqlite3ColumnPropertiesFromName(T,C) /* no-op */ |
| 19953 | 19287 | #endif |
| 19954 | | -SQLITE_PRIVATE void sqlite3AddColumn(Parse*,Token*,Token*); |
| 19288 | +SQLITE_PRIVATE void sqlite3AddColumn(Parse*,Token,Token); |
| 19955 | 19289 | SQLITE_PRIVATE void sqlite3AddNotNull(Parse*, int); |
| 19956 | 19290 | SQLITE_PRIVATE void sqlite3AddPrimaryKey(Parse*, ExprList*, int, int, int); |
| 19957 | 19291 | SQLITE_PRIVATE void sqlite3AddCheckConstraint(Parse*, Expr*, const char*, const char*); |
| 19958 | 19292 | SQLITE_PRIVATE void sqlite3AddDefaultValue(Parse*,Expr*,const char*,const char*); |
| 19959 | 19293 | SQLITE_PRIVATE void sqlite3AddCollateType(Parse*, Token*); |
| | @@ -20066,11 +19400,11 @@ |
| 20066 | 19400 | SQLITE_PRIVATE int sqlite3ExprCodeGetColumn(Parse*, Table*, int, int, int, u8); |
| 20067 | 19401 | SQLITE_PRIVATE void sqlite3ExprCodeGetColumnOfTable(Vdbe*, Table*, int, int, int); |
| 20068 | 19402 | SQLITE_PRIVATE void sqlite3ExprCodeMove(Parse*, int, int, int); |
| 20069 | 19403 | SQLITE_PRIVATE void sqlite3ExprCode(Parse*, Expr*, int); |
| 20070 | 19404 | #ifndef SQLITE_OMIT_GENERATED_COLUMNS |
| 20071 | | -SQLITE_PRIVATE void sqlite3ExprCodeGeneratedColumn(Parse*, Column*, int); |
| 19405 | +SQLITE_PRIVATE void sqlite3ExprCodeGeneratedColumn(Parse*, Table*, Column*, int); |
| 20072 | 19406 | #endif |
| 20073 | 19407 | SQLITE_PRIVATE void sqlite3ExprCodeCopy(Parse*, Expr*, int); |
| 20074 | 19408 | SQLITE_PRIVATE void sqlite3ExprCodeFactorable(Parse*, Expr*, int); |
| 20075 | 19409 | SQLITE_PRIVATE int sqlite3ExprCodeRunJustOnce(Parse*, Expr*, int); |
| 20076 | 19410 | SQLITE_PRIVATE int sqlite3ExprCodeTemp(Parse*, Expr*, int*); |
| | @@ -20329,11 +19663,11 @@ |
| 20329 | 19663 | SQLITE_PRIVATE Expr *sqlite3ExprSkipCollate(Expr*); |
| 20330 | 19664 | SQLITE_PRIVATE Expr *sqlite3ExprSkipCollateAndLikely(Expr*); |
| 20331 | 19665 | SQLITE_PRIVATE int sqlite3CheckCollSeq(Parse *, CollSeq *); |
| 20332 | 19666 | SQLITE_PRIVATE int sqlite3WritableSchema(sqlite3*); |
| 20333 | 19667 | SQLITE_PRIVATE int sqlite3CheckObjectName(Parse*, const char*,const char*,const char*); |
| 20334 | | -SQLITE_PRIVATE void sqlite3VdbeSetChanges(sqlite3 *, int); |
| 19668 | +SQLITE_PRIVATE void sqlite3VdbeSetChanges(sqlite3 *, i64); |
| 20335 | 19669 | SQLITE_PRIVATE int sqlite3AddInt64(i64*,i64); |
| 20336 | 19670 | SQLITE_PRIVATE int sqlite3SubInt64(i64*,i64); |
| 20337 | 19671 | SQLITE_PRIVATE int sqlite3MulInt64(i64*,i64); |
| 20338 | 19672 | SQLITE_PRIVATE int sqlite3AbsInt32(int); |
| 20339 | 19673 | #ifdef SQLITE_ENABLE_8_3_NAMES |
| | @@ -20359,10 +19693,13 @@ |
| 20359 | 19693 | SQLITE_PRIVATE int sqlite3ValueFromExpr(sqlite3 *, Expr *, u8, u8, sqlite3_value **); |
| 20360 | 19694 | SQLITE_PRIVATE void sqlite3ValueApplyAffinity(sqlite3_value *, u8, u8); |
| 20361 | 19695 | #ifndef SQLITE_AMALGAMATION |
| 20362 | 19696 | SQLITE_PRIVATE const unsigned char sqlite3OpcodeProperty[]; |
| 20363 | 19697 | SQLITE_PRIVATE const char sqlite3StrBINARY[]; |
| 19698 | +SQLITE_PRIVATE const unsigned char sqlite3StdTypeLen[]; |
| 19699 | +SQLITE_PRIVATE const char sqlite3StdTypeAffinity[]; |
| 19700 | +SQLITE_PRIVATE const char *sqlite3StdType[]; |
| 20364 | 19701 | SQLITE_PRIVATE const unsigned char sqlite3UpperToLower[]; |
| 20365 | 19702 | SQLITE_PRIVATE const unsigned char *sqlite3aLTb; |
| 20366 | 19703 | SQLITE_PRIVATE const unsigned char *sqlite3aEQb; |
| 20367 | 19704 | SQLITE_PRIVATE const unsigned char *sqlite3aGTb; |
| 20368 | 19705 | SQLITE_PRIVATE const unsigned char sqlite3CtypeMap[]; |
| | @@ -20779,20 +20116,1004 @@ |
| 20779 | 20116 | #endif |
| 20780 | 20117 | |
| 20781 | 20118 | SQLITE_PRIVATE int sqlite3ExprVectorSize(Expr *pExpr); |
| 20782 | 20119 | SQLITE_PRIVATE int sqlite3ExprIsVector(Expr *pExpr); |
| 20783 | 20120 | SQLITE_PRIVATE Expr *sqlite3VectorFieldSubexpr(Expr*, int); |
| 20784 | | -SQLITE_PRIVATE Expr *sqlite3ExprForVectorField(Parse*,Expr*,int); |
| 20121 | +SQLITE_PRIVATE Expr *sqlite3ExprForVectorField(Parse*,Expr*,int,int); |
| 20785 | 20122 | SQLITE_PRIVATE void sqlite3VectorErrorMsg(Parse*, Expr*); |
| 20786 | 20123 | |
| 20787 | 20124 | #ifndef SQLITE_OMIT_COMPILEOPTION_DIAGS |
| 20788 | 20125 | SQLITE_PRIVATE const char **sqlite3CompileOptions(int *pnOpt); |
| 20789 | 20126 | #endif |
| 20790 | 20127 | |
| 20791 | 20128 | #endif /* SQLITEINT_H */ |
| 20792 | 20129 | |
| 20793 | 20130 | /************** End of sqliteInt.h *******************************************/ |
| 20131 | +/************** Begin file os_common.h ***************************************/ |
| 20132 | +/* |
| 20133 | +** 2004 May 22 |
| 20134 | +** |
| 20135 | +** The author disclaims copyright to this source code. In place of |
| 20136 | +** a legal notice, here is a blessing: |
| 20137 | +** |
| 20138 | +** May you do good and not evil. |
| 20139 | +** May you find forgiveness for yourself and forgive others. |
| 20140 | +** May you share freely, never taking more than you give. |
| 20141 | +** |
| 20142 | +****************************************************************************** |
| 20143 | +** |
| 20144 | +** This file contains macros and a little bit of code that is common to |
| 20145 | +** all of the platform-specific files (os_*.c) and is #included into those |
| 20146 | +** files. |
| 20147 | +** |
| 20148 | +** This file should be #included by the os_*.c files only. It is not a |
| 20149 | +** general purpose header file. |
| 20150 | +*/ |
| 20151 | +#ifndef _OS_COMMON_H_ |
| 20152 | +#define _OS_COMMON_H_ |
| 20153 | + |
| 20154 | +/* |
| 20155 | +** At least two bugs have slipped in because we changed the MEMORY_DEBUG |
| 20156 | +** macro to SQLITE_DEBUG and some older makefiles have not yet made the |
| 20157 | +** switch. The following code should catch this problem at compile-time. |
| 20158 | +*/ |
| 20159 | +#ifdef MEMORY_DEBUG |
| 20160 | +# error "The MEMORY_DEBUG macro is obsolete. Use SQLITE_DEBUG instead." |
| 20161 | +#endif |
| 20162 | + |
| 20163 | +/* |
| 20164 | +** Macros for performance tracing. Normally turned off. Only works |
| 20165 | +** on i486 hardware. |
| 20166 | +*/ |
| 20167 | +#ifdef SQLITE_PERFORMANCE_TRACE |
| 20168 | + |
| 20169 | +/* |
| 20170 | +** hwtime.h contains inline assembler code for implementing |
| 20171 | +** high-performance timing routines. |
| 20172 | +*/ |
| 20173 | +/************** Include hwtime.h in the middle of os_common.h ****************/ |
| 20174 | +/************** Begin file hwtime.h ******************************************/ |
| 20175 | +/* |
| 20176 | +** 2008 May 27 |
| 20177 | +** |
| 20178 | +** The author disclaims copyright to this source code. In place of |
| 20179 | +** a legal notice, here is a blessing: |
| 20180 | +** |
| 20181 | +** May you do good and not evil. |
| 20182 | +** May you find forgiveness for yourself and forgive others. |
| 20183 | +** May you share freely, never taking more than you give. |
| 20184 | +** |
| 20185 | +****************************************************************************** |
| 20186 | +** |
| 20187 | +** This file contains inline asm code for retrieving "high-performance" |
| 20188 | +** counters for x86 and x86_64 class CPUs. |
| 20189 | +*/ |
| 20190 | +#ifndef SQLITE_HWTIME_H |
| 20191 | +#define SQLITE_HWTIME_H |
| 20192 | + |
| 20193 | +/* |
| 20194 | +** The following routine only works on pentium-class (or newer) processors. |
| 20195 | +** It uses the RDTSC opcode to read the cycle count value out of the |
| 20196 | +** processor and returns that value. This can be used for high-res |
| 20197 | +** profiling. |
| 20198 | +*/ |
| 20199 | +#if !defined(__STRICT_ANSI__) && \ |
| 20200 | + (defined(__GNUC__) || defined(_MSC_VER)) && \ |
| 20201 | + (defined(i386) || defined(__i386__) || defined(_M_IX86)) |
| 20202 | + |
| 20203 | + #if defined(__GNUC__) |
| 20204 | + |
| 20205 | + __inline__ sqlite_uint64 sqlite3Hwtime(void){ |
| 20206 | + unsigned int lo, hi; |
| 20207 | + __asm__ __volatile__ ("rdtsc" : "=a" (lo), "=d" (hi)); |
| 20208 | + return (sqlite_uint64)hi << 32 | lo; |
| 20209 | + } |
| 20210 | + |
| 20211 | + #elif defined(_MSC_VER) |
| 20212 | + |
| 20213 | + __declspec(naked) __inline sqlite_uint64 __cdecl sqlite3Hwtime(void){ |
| 20214 | + __asm { |
| 20215 | + rdtsc |
| 20216 | + ret ; return value at EDX:EAX |
| 20217 | + } |
| 20218 | + } |
| 20219 | + |
| 20220 | + #endif |
| 20221 | + |
| 20222 | +#elif !defined(__STRICT_ANSI__) && (defined(__GNUC__) && defined(__x86_64__)) |
| 20223 | + |
| 20224 | + __inline__ sqlite_uint64 sqlite3Hwtime(void){ |
| 20225 | + unsigned long val; |
| 20226 | + __asm__ __volatile__ ("rdtsc" : "=A" (val)); |
| 20227 | + return val; |
| 20228 | + } |
| 20229 | + |
| 20230 | +#elif !defined(__STRICT_ANSI__) && (defined(__GNUC__) && defined(__ppc__)) |
| 20231 | + |
| 20232 | + __inline__ sqlite_uint64 sqlite3Hwtime(void){ |
| 20233 | + unsigned long long retval; |
| 20234 | + unsigned long junk; |
| 20235 | + __asm__ __volatile__ ("\n\ |
| 20236 | + 1: mftbu %1\n\ |
| 20237 | + mftb %L0\n\ |
| 20238 | + mftbu %0\n\ |
| 20239 | + cmpw %0,%1\n\ |
| 20240 | + bne 1b" |
| 20241 | + : "=r" (retval), "=r" (junk)); |
| 20242 | + return retval; |
| 20243 | + } |
| 20244 | + |
| 20245 | +#else |
| 20246 | + |
| 20247 | + /* |
| 20248 | + ** asm() is needed for hardware timing support. Without asm(), |
| 20249 | + ** disable the sqlite3Hwtime() routine. |
| 20250 | + ** |
| 20251 | + ** sqlite3Hwtime() is only used for some obscure debugging |
| 20252 | + ** and analysis configurations, not in any deliverable, so this |
| 20253 | + ** should not be a great loss. |
| 20254 | + */ |
| 20255 | +SQLITE_PRIVATE sqlite_uint64 sqlite3Hwtime(void){ return ((sqlite_uint64)0); } |
| 20256 | + |
| 20257 | +#endif |
| 20258 | + |
| 20259 | +#endif /* !defined(SQLITE_HWTIME_H) */ |
| 20260 | + |
| 20261 | +/************** End of hwtime.h **********************************************/ |
| 20262 | +/************** Continuing where we left off in os_common.h ******************/ |
| 20263 | + |
| 20264 | +static sqlite_uint64 g_start; |
| 20265 | +static sqlite_uint64 g_elapsed; |
| 20266 | +#define TIMER_START g_start=sqlite3Hwtime() |
| 20267 | +#define TIMER_END g_elapsed=sqlite3Hwtime()-g_start |
| 20268 | +#define TIMER_ELAPSED g_elapsed |
| 20269 | +#else |
| 20270 | +#define TIMER_START |
| 20271 | +#define TIMER_END |
| 20272 | +#define TIMER_ELAPSED ((sqlite_uint64)0) |
| 20273 | +#endif |
| 20274 | + |
| 20275 | +/* |
| 20276 | +** If we compile with the SQLITE_TEST macro set, then the following block |
| 20277 | +** of code will give us the ability to simulate a disk I/O error. This |
| 20278 | +** is used for testing the I/O recovery logic. |
| 20279 | +*/ |
| 20280 | +#if defined(SQLITE_TEST) |
| 20281 | +SQLITE_API extern int sqlite3_io_error_hit; |
| 20282 | +SQLITE_API extern int sqlite3_io_error_hardhit; |
| 20283 | +SQLITE_API extern int sqlite3_io_error_pending; |
| 20284 | +SQLITE_API extern int sqlite3_io_error_persist; |
| 20285 | +SQLITE_API extern int sqlite3_io_error_benign; |
| 20286 | +SQLITE_API extern int sqlite3_diskfull_pending; |
| 20287 | +SQLITE_API extern int sqlite3_diskfull; |
| 20288 | +#define SimulateIOErrorBenign(X) sqlite3_io_error_benign=(X) |
| 20289 | +#define SimulateIOError(CODE) \ |
| 20290 | + if( (sqlite3_io_error_persist && sqlite3_io_error_hit) \ |
| 20291 | + || sqlite3_io_error_pending-- == 1 ) \ |
| 20292 | + { local_ioerr(); CODE; } |
| 20293 | +static void local_ioerr(){ |
| 20294 | + IOTRACE(("IOERR\n")); |
| 20295 | + sqlite3_io_error_hit++; |
| 20296 | + if( !sqlite3_io_error_benign ) sqlite3_io_error_hardhit++; |
| 20297 | +} |
| 20298 | +#define SimulateDiskfullError(CODE) \ |
| 20299 | + if( sqlite3_diskfull_pending ){ \ |
| 20300 | + if( sqlite3_diskfull_pending == 1 ){ \ |
| 20301 | + local_ioerr(); \ |
| 20302 | + sqlite3_diskfull = 1; \ |
| 20303 | + sqlite3_io_error_hit = 1; \ |
| 20304 | + CODE; \ |
| 20305 | + }else{ \ |
| 20306 | + sqlite3_diskfull_pending--; \ |
| 20307 | + } \ |
| 20308 | + } |
| 20309 | +#else |
| 20310 | +#define SimulateIOErrorBenign(X) |
| 20311 | +#define SimulateIOError(A) |
| 20312 | +#define SimulateDiskfullError(A) |
| 20313 | +#endif /* defined(SQLITE_TEST) */ |
| 20314 | + |
| 20315 | +/* |
| 20316 | +** When testing, keep a count of the number of open files. |
| 20317 | +*/ |
| 20318 | +#if defined(SQLITE_TEST) |
| 20319 | +SQLITE_API extern int sqlite3_open_file_count; |
| 20320 | +#define OpenCounter(X) sqlite3_open_file_count+=(X) |
| 20321 | +#else |
| 20322 | +#define OpenCounter(X) |
| 20323 | +#endif /* defined(SQLITE_TEST) */ |
| 20324 | + |
| 20325 | +#endif /* !defined(_OS_COMMON_H_) */ |
| 20326 | + |
| 20327 | +/************** End of os_common.h *******************************************/ |
| 20328 | +/************** Begin file ctime.c *******************************************/ |
| 20329 | +/* |
| 20330 | +** 2010 February 23 |
| 20331 | +** |
| 20332 | +** The author disclaims copyright to this source code. In place of |
| 20333 | +** a legal notice, here is a blessing: |
| 20334 | +** |
| 20335 | +** May you do good and not evil. |
| 20336 | +** May you find forgiveness for yourself and forgive others. |
| 20337 | +** May you share freely, never taking more than you give. |
| 20338 | +** |
| 20339 | +************************************************************************* |
| 20340 | +** |
| 20341 | +** This file implements routines used to report what compile-time options |
| 20342 | +** SQLite was built with. |
| 20343 | +*/ |
| 20344 | +#ifndef SQLITE_OMIT_COMPILEOPTION_DIAGS /* IMP: R-16824-07538 */ |
| 20345 | + |
| 20346 | +/* |
| 20347 | +** Include the configuration header output by 'configure' if we're using the |
| 20348 | +** autoconf-based build |
| 20349 | +*/ |
| 20350 | +#if defined(_HAVE_SQLITE_CONFIG_H) && !defined(SQLITECONFIG_H) |
| 20351 | +/* #include "config.h" */ |
| 20352 | +#define SQLITECONFIG_H 1 |
| 20353 | +#endif |
| 20354 | + |
| 20355 | +/* These macros are provided to "stringify" the value of the define |
| 20356 | +** for those options in which the value is meaningful. */ |
| 20357 | +#define CTIMEOPT_VAL_(opt) #opt |
| 20358 | +#define CTIMEOPT_VAL(opt) CTIMEOPT_VAL_(opt) |
| 20359 | + |
| 20360 | +/* Like CTIMEOPT_VAL, but especially for SQLITE_DEFAULT_LOOKASIDE. This |
| 20361 | +** option requires a separate macro because legal values contain a single |
| 20362 | +** comma. e.g. (-DSQLITE_DEFAULT_LOOKASIDE="100,100") */ |
| 20363 | +#define CTIMEOPT_VAL2_(opt1,opt2) #opt1 "," #opt2 |
| 20364 | +#define CTIMEOPT_VAL2(opt) CTIMEOPT_VAL2_(opt) |
| 20365 | +/* #include "sqliteInt.h" */ |
| 20366 | + |
| 20367 | +/* |
| 20368 | +** An array of names of all compile-time options. This array should |
| 20369 | +** be sorted A-Z. |
| 20370 | +** |
| 20371 | +** This array looks large, but in a typical installation actually uses |
| 20372 | +** only a handful of compile-time options, so most times this array is usually |
| 20373 | +** rather short and uses little memory space. |
| 20374 | +*/ |
| 20375 | +static const char * const sqlite3azCompileOpt[] = { |
| 20376 | + |
| 20377 | +/* |
| 20378 | +** BEGIN CODE GENERATED BY tool/mkctime.tcl |
| 20379 | +*/ |
| 20380 | +#ifdef SQLITE_32BIT_ROWID |
| 20381 | + "32BIT_ROWID", |
| 20382 | +#endif |
| 20383 | +#ifdef SQLITE_4_BYTE_ALIGNED_MALLOC |
| 20384 | + "4_BYTE_ALIGNED_MALLOC", |
| 20385 | +#endif |
| 20386 | +#ifdef SQLITE_64BIT_STATS |
| 20387 | + "64BIT_STATS", |
| 20388 | +#endif |
| 20389 | +#ifdef SQLITE_ALLOW_COVERING_INDEX_SCAN |
| 20390 | +# if SQLITE_ALLOW_COVERING_INDEX_SCAN != 1 |
| 20391 | + "ALLOW_COVERING_INDEX_SCAN=" CTIMEOPT_VAL(SQLITE_ALLOW_COVERING_INDEX_SCAN), |
| 20392 | +# endif |
| 20393 | +#endif |
| 20394 | +#ifdef SQLITE_ALLOW_URI_AUTHORITY |
| 20395 | + "ALLOW_URI_AUTHORITY", |
| 20396 | +#endif |
| 20397 | +#ifdef SQLITE_ATOMIC_INTRINSICS |
| 20398 | + "ATOMIC_INTRINSICS=" CTIMEOPT_VAL(SQLITE_ATOMIC_INTRINSICS), |
| 20399 | +#endif |
| 20400 | +#ifdef SQLITE_BITMASK_TYPE |
| 20401 | + "BITMASK_TYPE=" CTIMEOPT_VAL(SQLITE_BITMASK_TYPE), |
| 20402 | +#endif |
| 20403 | +#ifdef SQLITE_BUG_COMPATIBLE_20160819 |
| 20404 | + "BUG_COMPATIBLE_20160819", |
| 20405 | +#endif |
| 20406 | +#ifdef SQLITE_CASE_SENSITIVE_LIKE |
| 20407 | + "CASE_SENSITIVE_LIKE", |
| 20408 | +#endif |
| 20409 | +#ifdef SQLITE_CHECK_PAGES |
| 20410 | + "CHECK_PAGES", |
| 20411 | +#endif |
| 20412 | +#if defined(__clang__) && defined(__clang_major__) |
| 20413 | + "COMPILER=clang-" CTIMEOPT_VAL(__clang_major__) "." |
| 20414 | + CTIMEOPT_VAL(__clang_minor__) "." |
| 20415 | + CTIMEOPT_VAL(__clang_patchlevel__), |
| 20416 | +#elif defined(_MSC_VER) |
| 20417 | + "COMPILER=msvc-" CTIMEOPT_VAL(_MSC_VER), |
| 20418 | +#elif defined(__GNUC__) && defined(__VERSION__) |
| 20419 | + "COMPILER=gcc-" __VERSION__, |
| 20420 | +#endif |
| 20421 | +#ifdef SQLITE_COVERAGE_TEST |
| 20422 | + "COVERAGE_TEST", |
| 20423 | +#endif |
| 20424 | +#ifdef SQLITE_DEBUG |
| 20425 | + "DEBUG", |
| 20426 | +#endif |
| 20427 | +#ifdef SQLITE_DEFAULT_AUTOMATIC_INDEX |
| 20428 | + "DEFAULT_AUTOMATIC_INDEX", |
| 20429 | +#endif |
| 20430 | +#ifdef SQLITE_DEFAULT_AUTOVACUUM |
| 20431 | + "DEFAULT_AUTOVACUUM", |
| 20432 | +#endif |
| 20433 | +#ifdef SQLITE_DEFAULT_CACHE_SIZE |
| 20434 | + "DEFAULT_CACHE_SIZE=" CTIMEOPT_VAL(SQLITE_DEFAULT_CACHE_SIZE), |
| 20435 | +#endif |
| 20436 | +#ifdef SQLITE_DEFAULT_CKPTFULLFSYNC |
| 20437 | + "DEFAULT_CKPTFULLFSYNC", |
| 20438 | +#endif |
| 20439 | +#ifdef SQLITE_DEFAULT_FILE_FORMAT |
| 20440 | + "DEFAULT_FILE_FORMAT=" CTIMEOPT_VAL(SQLITE_DEFAULT_FILE_FORMAT), |
| 20441 | +#endif |
| 20442 | +#ifdef SQLITE_DEFAULT_FILE_PERMISSIONS |
| 20443 | + "DEFAULT_FILE_PERMISSIONS=" CTIMEOPT_VAL(SQLITE_DEFAULT_FILE_PERMISSIONS), |
| 20444 | +#endif |
| 20445 | +#ifdef SQLITE_DEFAULT_FOREIGN_KEYS |
| 20446 | + "DEFAULT_FOREIGN_KEYS", |
| 20447 | +#endif |
| 20448 | +#ifdef SQLITE_DEFAULT_JOURNAL_SIZE_LIMIT |
| 20449 | + "DEFAULT_JOURNAL_SIZE_LIMIT=" CTIMEOPT_VAL(SQLITE_DEFAULT_JOURNAL_SIZE_LIMIT), |
| 20450 | +#endif |
| 20451 | +#ifdef SQLITE_DEFAULT_LOCKING_MODE |
| 20452 | + "DEFAULT_LOCKING_MODE=" CTIMEOPT_VAL(SQLITE_DEFAULT_LOCKING_MODE), |
| 20453 | +#endif |
| 20454 | +#ifdef SQLITE_DEFAULT_LOOKASIDE |
| 20455 | + "DEFAULT_LOOKASIDE=" CTIMEOPT_VAL2(SQLITE_DEFAULT_LOOKASIDE), |
| 20456 | +#endif |
| 20457 | +#ifdef SQLITE_DEFAULT_MEMSTATUS |
| 20458 | +# if SQLITE_DEFAULT_MEMSTATUS != 1 |
| 20459 | + "DEFAULT_MEMSTATUS=" CTIMEOPT_VAL(SQLITE_DEFAULT_MEMSTATUS), |
| 20460 | +# endif |
| 20461 | +#endif |
| 20462 | +#ifdef SQLITE_DEFAULT_MMAP_SIZE |
| 20463 | + "DEFAULT_MMAP_SIZE=" CTIMEOPT_VAL(SQLITE_DEFAULT_MMAP_SIZE), |
| 20464 | +#endif |
| 20465 | +#ifdef SQLITE_DEFAULT_PAGE_SIZE |
| 20466 | + "DEFAULT_PAGE_SIZE=" CTIMEOPT_VAL(SQLITE_DEFAULT_PAGE_SIZE), |
| 20467 | +#endif |
| 20468 | +#ifdef SQLITE_DEFAULT_PCACHE_INITSZ |
| 20469 | + "DEFAULT_PCACHE_INITSZ=" CTIMEOPT_VAL(SQLITE_DEFAULT_PCACHE_INITSZ), |
| 20470 | +#endif |
| 20471 | +#ifdef SQLITE_DEFAULT_PROXYDIR_PERMISSIONS |
| 20472 | + "DEFAULT_PROXYDIR_PERMISSIONS=" CTIMEOPT_VAL(SQLITE_DEFAULT_PROXYDIR_PERMISSIONS), |
| 20473 | +#endif |
| 20474 | +#ifdef SQLITE_DEFAULT_RECURSIVE_TRIGGERS |
| 20475 | + "DEFAULT_RECURSIVE_TRIGGERS", |
| 20476 | +#endif |
| 20477 | +#ifdef SQLITE_DEFAULT_ROWEST |
| 20478 | + "DEFAULT_ROWEST=" CTIMEOPT_VAL(SQLITE_DEFAULT_ROWEST), |
| 20479 | +#endif |
| 20480 | +#ifdef SQLITE_DEFAULT_SECTOR_SIZE |
| 20481 | + "DEFAULT_SECTOR_SIZE=" CTIMEOPT_VAL(SQLITE_DEFAULT_SECTOR_SIZE), |
| 20482 | +#endif |
| 20483 | +#ifdef SQLITE_DEFAULT_SYNCHRONOUS |
| 20484 | + "DEFAULT_SYNCHRONOUS=" CTIMEOPT_VAL(SQLITE_DEFAULT_SYNCHRONOUS), |
| 20485 | +#endif |
| 20486 | +#ifdef SQLITE_DEFAULT_WAL_AUTOCHECKPOINT |
| 20487 | + "DEFAULT_WAL_AUTOCHECKPOINT=" CTIMEOPT_VAL(SQLITE_DEFAULT_WAL_AUTOCHECKPOINT), |
| 20488 | +#endif |
| 20489 | +#ifdef SQLITE_DEFAULT_WAL_SYNCHRONOUS |
| 20490 | + "DEFAULT_WAL_SYNCHRONOUS=" CTIMEOPT_VAL(SQLITE_DEFAULT_WAL_SYNCHRONOUS), |
| 20491 | +#endif |
| 20492 | +#ifdef SQLITE_DEFAULT_WORKER_THREADS |
| 20493 | + "DEFAULT_WORKER_THREADS=" CTIMEOPT_VAL(SQLITE_DEFAULT_WORKER_THREADS), |
| 20494 | +#endif |
| 20495 | +#ifdef SQLITE_DIRECT_OVERFLOW_READ |
| 20496 | + "DIRECT_OVERFLOW_READ", |
| 20497 | +#endif |
| 20498 | +#ifdef SQLITE_DISABLE_DIRSYNC |
| 20499 | + "DISABLE_DIRSYNC", |
| 20500 | +#endif |
| 20501 | +#ifdef SQLITE_DISABLE_FTS3_UNICODE |
| 20502 | + "DISABLE_FTS3_UNICODE", |
| 20503 | +#endif |
| 20504 | +#ifdef SQLITE_DISABLE_FTS4_DEFERRED |
| 20505 | + "DISABLE_FTS4_DEFERRED", |
| 20506 | +#endif |
| 20507 | +#ifdef SQLITE_DISABLE_INTRINSIC |
| 20508 | + "DISABLE_INTRINSIC", |
| 20509 | +#endif |
| 20510 | +#ifdef SQLITE_DISABLE_LFS |
| 20511 | + "DISABLE_LFS", |
| 20512 | +#endif |
| 20513 | +#ifdef SQLITE_DISABLE_PAGECACHE_OVERFLOW_STATS |
| 20514 | + "DISABLE_PAGECACHE_OVERFLOW_STATS", |
| 20515 | +#endif |
| 20516 | +#ifdef SQLITE_DISABLE_SKIPAHEAD_DISTINCT |
| 20517 | + "DISABLE_SKIPAHEAD_DISTINCT", |
| 20518 | +#endif |
| 20519 | +#ifdef SQLITE_ENABLE_8_3_NAMES |
| 20520 | + "ENABLE_8_3_NAMES=" CTIMEOPT_VAL(SQLITE_ENABLE_8_3_NAMES), |
| 20521 | +#endif |
| 20522 | +#ifdef SQLITE_ENABLE_API_ARMOR |
| 20523 | + "ENABLE_API_ARMOR", |
| 20524 | +#endif |
| 20525 | +#ifdef SQLITE_ENABLE_ATOMIC_WRITE |
| 20526 | + "ENABLE_ATOMIC_WRITE", |
| 20527 | +#endif |
| 20528 | +#ifdef SQLITE_ENABLE_BATCH_ATOMIC_WRITE |
| 20529 | + "ENABLE_BATCH_ATOMIC_WRITE", |
| 20530 | +#endif |
| 20531 | +#ifdef SQLITE_ENABLE_BYTECODE_VTAB |
| 20532 | + "ENABLE_BYTECODE_VTAB", |
| 20533 | +#endif |
| 20534 | +#ifdef SQLITE_ENABLE_CEROD |
| 20535 | + "ENABLE_CEROD=" CTIMEOPT_VAL(SQLITE_ENABLE_CEROD), |
| 20536 | +#endif |
| 20537 | +#ifdef SQLITE_ENABLE_COLUMN_METADATA |
| 20538 | + "ENABLE_COLUMN_METADATA", |
| 20539 | +#endif |
| 20540 | +#ifdef SQLITE_ENABLE_COLUMN_USED_MASK |
| 20541 | + "ENABLE_COLUMN_USED_MASK", |
| 20542 | +#endif |
| 20543 | +#ifdef SQLITE_ENABLE_COSTMULT |
| 20544 | + "ENABLE_COSTMULT", |
| 20545 | +#endif |
| 20546 | +#ifdef SQLITE_ENABLE_CURSOR_HINTS |
| 20547 | + "ENABLE_CURSOR_HINTS", |
| 20548 | +#endif |
| 20549 | +#ifdef SQLITE_ENABLE_DBPAGE_VTAB |
| 20550 | + "ENABLE_DBPAGE_VTAB", |
| 20551 | +#endif |
| 20552 | +#ifdef SQLITE_ENABLE_DBSTAT_VTAB |
| 20553 | + "ENABLE_DBSTAT_VTAB", |
| 20554 | +#endif |
| 20555 | +#ifdef SQLITE_ENABLE_EXPENSIVE_ASSERT |
| 20556 | + "ENABLE_EXPENSIVE_ASSERT", |
| 20557 | +#endif |
| 20558 | +#ifdef SQLITE_ENABLE_EXPLAIN_COMMENTS |
| 20559 | + "ENABLE_EXPLAIN_COMMENTS", |
| 20560 | +#endif |
| 20561 | +#ifdef SQLITE_ENABLE_FTS3 |
| 20562 | + "ENABLE_FTS3", |
| 20563 | +#endif |
| 20564 | +#ifdef SQLITE_ENABLE_FTS3_PARENTHESIS |
| 20565 | + "ENABLE_FTS3_PARENTHESIS", |
| 20566 | +#endif |
| 20567 | +#ifdef SQLITE_ENABLE_FTS3_TOKENIZER |
| 20568 | + "ENABLE_FTS3_TOKENIZER", |
| 20569 | +#endif |
| 20570 | +#ifdef SQLITE_ENABLE_FTS4 |
| 20571 | + "ENABLE_FTS4", |
| 20572 | +#endif |
| 20573 | +#ifdef SQLITE_ENABLE_FTS5 |
| 20574 | + "ENABLE_FTS5", |
| 20575 | +#endif |
| 20576 | +#ifdef SQLITE_ENABLE_GEOPOLY |
| 20577 | + "ENABLE_GEOPOLY", |
| 20578 | +#endif |
| 20579 | +#ifdef SQLITE_ENABLE_HIDDEN_COLUMNS |
| 20580 | + "ENABLE_HIDDEN_COLUMNS", |
| 20581 | +#endif |
| 20582 | +#ifdef SQLITE_ENABLE_ICU |
| 20583 | + "ENABLE_ICU", |
| 20584 | +#endif |
| 20585 | +#ifdef SQLITE_ENABLE_IOTRACE |
| 20586 | + "ENABLE_IOTRACE", |
| 20587 | +#endif |
| 20588 | +#ifdef SQLITE_ENABLE_JSON1 |
| 20589 | + "ENABLE_JSON1", |
| 20590 | +#endif |
| 20591 | +#ifdef SQLITE_ENABLE_LOAD_EXTENSION |
| 20592 | + "ENABLE_LOAD_EXTENSION", |
| 20593 | +#endif |
| 20594 | +#ifdef SQLITE_ENABLE_LOCKING_STYLE |
| 20595 | + "ENABLE_LOCKING_STYLE=" CTIMEOPT_VAL(SQLITE_ENABLE_LOCKING_STYLE), |
| 20596 | +#endif |
| 20597 | +#ifdef SQLITE_ENABLE_MATH_FUNCTIONS |
| 20598 | + "ENABLE_MATH_FUNCTIONS", |
| 20599 | +#endif |
| 20600 | +#ifdef SQLITE_ENABLE_MEMORY_MANAGEMENT |
| 20601 | + "ENABLE_MEMORY_MANAGEMENT", |
| 20602 | +#endif |
| 20603 | +#ifdef SQLITE_ENABLE_MEMSYS3 |
| 20604 | + "ENABLE_MEMSYS3", |
| 20605 | +#endif |
| 20606 | +#ifdef SQLITE_ENABLE_MEMSYS5 |
| 20607 | + "ENABLE_MEMSYS5", |
| 20608 | +#endif |
| 20609 | +#ifdef SQLITE_ENABLE_MULTIPLEX |
| 20610 | + "ENABLE_MULTIPLEX", |
| 20611 | +#endif |
| 20612 | +#ifdef SQLITE_ENABLE_NORMALIZE |
| 20613 | + "ENABLE_NORMALIZE", |
| 20614 | +#endif |
| 20615 | +#ifdef SQLITE_ENABLE_NULL_TRIM |
| 20616 | + "ENABLE_NULL_TRIM", |
| 20617 | +#endif |
| 20618 | +#ifdef SQLITE_ENABLE_OFFSET_SQL_FUNC |
| 20619 | + "ENABLE_OFFSET_SQL_FUNC", |
| 20620 | +#endif |
| 20621 | +#ifdef SQLITE_ENABLE_OVERSIZE_CELL_CHECK |
| 20622 | + "ENABLE_OVERSIZE_CELL_CHECK", |
| 20623 | +#endif |
| 20624 | +#ifdef SQLITE_ENABLE_PREUPDATE_HOOK |
| 20625 | + "ENABLE_PREUPDATE_HOOK", |
| 20626 | +#endif |
| 20627 | +#ifdef SQLITE_ENABLE_QPSG |
| 20628 | + "ENABLE_QPSG", |
| 20629 | +#endif |
| 20630 | +#ifdef SQLITE_ENABLE_RBU |
| 20631 | + "ENABLE_RBU", |
| 20632 | +#endif |
| 20633 | +#ifdef SQLITE_ENABLE_RTREE |
| 20634 | + "ENABLE_RTREE", |
| 20635 | +#endif |
| 20636 | +#ifdef SQLITE_ENABLE_SELECTTRACE |
| 20637 | + "ENABLE_SELECTTRACE", |
| 20638 | +#endif |
| 20639 | +#ifdef SQLITE_ENABLE_SESSION |
| 20640 | + "ENABLE_SESSION", |
| 20641 | +#endif |
| 20642 | +#ifdef SQLITE_ENABLE_SNAPSHOT |
| 20643 | + "ENABLE_SNAPSHOT", |
| 20644 | +#endif |
| 20645 | +#ifdef SQLITE_ENABLE_SORTER_REFERENCES |
| 20646 | + "ENABLE_SORTER_REFERENCES", |
| 20647 | +#endif |
| 20648 | +#ifdef SQLITE_ENABLE_SQLLOG |
| 20649 | + "ENABLE_SQLLOG", |
| 20650 | +#endif |
| 20651 | +#ifdef SQLITE_ENABLE_STAT4 |
| 20652 | + "ENABLE_STAT4", |
| 20653 | +#endif |
| 20654 | +#ifdef SQLITE_ENABLE_STMTVTAB |
| 20655 | + "ENABLE_STMTVTAB", |
| 20656 | +#endif |
| 20657 | +#ifdef SQLITE_ENABLE_STMT_SCANSTATUS |
| 20658 | + "ENABLE_STMT_SCANSTATUS", |
| 20659 | +#endif |
| 20660 | +#ifdef SQLITE_ENABLE_UNKNOWN_SQL_FUNCTION |
| 20661 | + "ENABLE_UNKNOWN_SQL_FUNCTION", |
| 20662 | +#endif |
| 20663 | +#ifdef SQLITE_ENABLE_UNLOCK_NOTIFY |
| 20664 | + "ENABLE_UNLOCK_NOTIFY", |
| 20665 | +#endif |
| 20666 | +#ifdef SQLITE_ENABLE_UPDATE_DELETE_LIMIT |
| 20667 | + "ENABLE_UPDATE_DELETE_LIMIT", |
| 20668 | +#endif |
| 20669 | +#ifdef SQLITE_ENABLE_URI_00_ERROR |
| 20670 | + "ENABLE_URI_00_ERROR", |
| 20671 | +#endif |
| 20672 | +#ifdef SQLITE_ENABLE_VFSTRACE |
| 20673 | + "ENABLE_VFSTRACE", |
| 20674 | +#endif |
| 20675 | +#ifdef SQLITE_ENABLE_WHERETRACE |
| 20676 | + "ENABLE_WHERETRACE", |
| 20677 | +#endif |
| 20678 | +#ifdef SQLITE_ENABLE_ZIPVFS |
| 20679 | + "ENABLE_ZIPVFS", |
| 20680 | +#endif |
| 20681 | +#ifdef SQLITE_EXPLAIN_ESTIMATED_ROWS |
| 20682 | + "EXPLAIN_ESTIMATED_ROWS", |
| 20683 | +#endif |
| 20684 | +#ifdef SQLITE_EXTRA_IFNULLROW |
| 20685 | + "EXTRA_IFNULLROW", |
| 20686 | +#endif |
| 20687 | +#ifdef SQLITE_EXTRA_INIT |
| 20688 | + "EXTRA_INIT=" CTIMEOPT_VAL(SQLITE_EXTRA_INIT), |
| 20689 | +#endif |
| 20690 | +#ifdef SQLITE_EXTRA_SHUTDOWN |
| 20691 | + "EXTRA_SHUTDOWN=" CTIMEOPT_VAL(SQLITE_EXTRA_SHUTDOWN), |
| 20692 | +#endif |
| 20693 | +#ifdef SQLITE_FTS3_MAX_EXPR_DEPTH |
| 20694 | + "FTS3_MAX_EXPR_DEPTH=" CTIMEOPT_VAL(SQLITE_FTS3_MAX_EXPR_DEPTH), |
| 20695 | +#endif |
| 20696 | +#ifdef SQLITE_FTS5_ENABLE_TEST_MI |
| 20697 | + "FTS5_ENABLE_TEST_MI", |
| 20698 | +#endif |
| 20699 | +#ifdef SQLITE_FTS5_NO_WITHOUT_ROWID |
| 20700 | + "FTS5_NO_WITHOUT_ROWID", |
| 20701 | +#endif |
| 20702 | +#if HAVE_ISNAN || SQLITE_HAVE_ISNAN |
| 20703 | + "HAVE_ISNAN", |
| 20704 | +#endif |
| 20705 | +#ifdef SQLITE_HOMEGROWN_RECURSIVE_MUTEX |
| 20706 | +# if SQLITE_HOMEGROWN_RECURSIVE_MUTEX != 1 |
| 20707 | + "HOMEGROWN_RECURSIVE_MUTEX=" CTIMEOPT_VAL(SQLITE_HOMEGROWN_RECURSIVE_MUTEX), |
| 20708 | +# endif |
| 20709 | +#endif |
| 20710 | +#ifdef SQLITE_IGNORE_AFP_LOCK_ERRORS |
| 20711 | + "IGNORE_AFP_LOCK_ERRORS", |
| 20712 | +#endif |
| 20713 | +#ifdef SQLITE_IGNORE_FLOCK_LOCK_ERRORS |
| 20714 | + "IGNORE_FLOCK_LOCK_ERRORS", |
| 20715 | +#endif |
| 20716 | +#ifdef SQLITE_INLINE_MEMCPY |
| 20717 | + "INLINE_MEMCPY", |
| 20718 | +#endif |
| 20719 | +#ifdef SQLITE_INT64_TYPE |
| 20720 | + "INT64_TYPE", |
| 20721 | +#endif |
| 20722 | +#ifdef SQLITE_INTEGRITY_CHECK_ERROR_MAX |
| 20723 | + "INTEGRITY_CHECK_ERROR_MAX=" CTIMEOPT_VAL(SQLITE_INTEGRITY_CHECK_ERROR_MAX), |
| 20724 | +#endif |
| 20725 | +#ifdef SQLITE_LIKE_DOESNT_MATCH_BLOBS |
| 20726 | + "LIKE_DOESNT_MATCH_BLOBS", |
| 20727 | +#endif |
| 20728 | +#ifdef SQLITE_LOCK_TRACE |
| 20729 | + "LOCK_TRACE", |
| 20730 | +#endif |
| 20731 | +#ifdef SQLITE_LOG_CACHE_SPILL |
| 20732 | + "LOG_CACHE_SPILL", |
| 20733 | +#endif |
| 20734 | +#ifdef SQLITE_MALLOC_SOFT_LIMIT |
| 20735 | + "MALLOC_SOFT_LIMIT=" CTIMEOPT_VAL(SQLITE_MALLOC_SOFT_LIMIT), |
| 20736 | +#endif |
| 20737 | +#ifdef SQLITE_MAX_ATTACHED |
| 20738 | + "MAX_ATTACHED=" CTIMEOPT_VAL(SQLITE_MAX_ATTACHED), |
| 20739 | +#endif |
| 20740 | +#ifdef SQLITE_MAX_COLUMN |
| 20741 | + "MAX_COLUMN=" CTIMEOPT_VAL(SQLITE_MAX_COLUMN), |
| 20742 | +#endif |
| 20743 | +#ifdef SQLITE_MAX_COMPOUND_SELECT |
| 20744 | + "MAX_COMPOUND_SELECT=" CTIMEOPT_VAL(SQLITE_MAX_COMPOUND_SELECT), |
| 20745 | +#endif |
| 20746 | +#ifdef SQLITE_MAX_DEFAULT_PAGE_SIZE |
| 20747 | + "MAX_DEFAULT_PAGE_SIZE=" CTIMEOPT_VAL(SQLITE_MAX_DEFAULT_PAGE_SIZE), |
| 20748 | +#endif |
| 20749 | +#ifdef SQLITE_MAX_EXPR_DEPTH |
| 20750 | + "MAX_EXPR_DEPTH=" CTIMEOPT_VAL(SQLITE_MAX_EXPR_DEPTH), |
| 20751 | +#endif |
| 20752 | +#ifdef SQLITE_MAX_FUNCTION_ARG |
| 20753 | + "MAX_FUNCTION_ARG=" CTIMEOPT_VAL(SQLITE_MAX_FUNCTION_ARG), |
| 20754 | +#endif |
| 20755 | +#ifdef SQLITE_MAX_LENGTH |
| 20756 | + "MAX_LENGTH=" CTIMEOPT_VAL(SQLITE_MAX_LENGTH), |
| 20757 | +#endif |
| 20758 | +#ifdef SQLITE_MAX_LIKE_PATTERN_LENGTH |
| 20759 | + "MAX_LIKE_PATTERN_LENGTH=" CTIMEOPT_VAL(SQLITE_MAX_LIKE_PATTERN_LENGTH), |
| 20760 | +#endif |
| 20761 | +#ifdef SQLITE_MAX_MEMORY |
| 20762 | + "MAX_MEMORY=" CTIMEOPT_VAL(SQLITE_MAX_MEMORY), |
| 20763 | +#endif |
| 20764 | +#ifdef SQLITE_MAX_MMAP_SIZE |
| 20765 | + "MAX_MMAP_SIZE=" CTIMEOPT_VAL(SQLITE_MAX_MMAP_SIZE), |
| 20766 | +#endif |
| 20767 | +#ifdef SQLITE_MAX_MMAP_SIZE_ |
| 20768 | + "MAX_MMAP_SIZE_=" CTIMEOPT_VAL(SQLITE_MAX_MMAP_SIZE_), |
| 20769 | +#endif |
| 20770 | +#ifdef SQLITE_MAX_PAGE_COUNT |
| 20771 | + "MAX_PAGE_COUNT=" CTIMEOPT_VAL(SQLITE_MAX_PAGE_COUNT), |
| 20772 | +#endif |
| 20773 | +#ifdef SQLITE_MAX_PAGE_SIZE |
| 20774 | + "MAX_PAGE_SIZE=" CTIMEOPT_VAL(SQLITE_MAX_PAGE_SIZE), |
| 20775 | +#endif |
| 20776 | +#ifdef SQLITE_MAX_SCHEMA_RETRY |
| 20777 | + "MAX_SCHEMA_RETRY=" CTIMEOPT_VAL(SQLITE_MAX_SCHEMA_RETRY), |
| 20778 | +#endif |
| 20779 | +#ifdef SQLITE_MAX_SQL_LENGTH |
| 20780 | + "MAX_SQL_LENGTH=" CTIMEOPT_VAL(SQLITE_MAX_SQL_LENGTH), |
| 20781 | +#endif |
| 20782 | +#ifdef SQLITE_MAX_TRIGGER_DEPTH |
| 20783 | + "MAX_TRIGGER_DEPTH=" CTIMEOPT_VAL(SQLITE_MAX_TRIGGER_DEPTH), |
| 20784 | +#endif |
| 20785 | +#ifdef SQLITE_MAX_VARIABLE_NUMBER |
| 20786 | + "MAX_VARIABLE_NUMBER=" CTIMEOPT_VAL(SQLITE_MAX_VARIABLE_NUMBER), |
| 20787 | +#endif |
| 20788 | +#ifdef SQLITE_MAX_VDBE_OP |
| 20789 | + "MAX_VDBE_OP=" CTIMEOPT_VAL(SQLITE_MAX_VDBE_OP), |
| 20790 | +#endif |
| 20791 | +#ifdef SQLITE_MAX_WORKER_THREADS |
| 20792 | + "MAX_WORKER_THREADS=" CTIMEOPT_VAL(SQLITE_MAX_WORKER_THREADS), |
| 20793 | +#endif |
| 20794 | +#ifdef SQLITE_MEMDEBUG |
| 20795 | + "MEMDEBUG", |
| 20796 | +#endif |
| 20797 | +#ifdef SQLITE_MIXED_ENDIAN_64BIT_FLOAT |
| 20798 | + "MIXED_ENDIAN_64BIT_FLOAT", |
| 20799 | +#endif |
| 20800 | +#ifdef SQLITE_MMAP_READWRITE |
| 20801 | + "MMAP_READWRITE", |
| 20802 | +#endif |
| 20803 | +#ifdef SQLITE_MUTEX_NOOP |
| 20804 | + "MUTEX_NOOP", |
| 20805 | +#endif |
| 20806 | +#ifdef SQLITE_MUTEX_OMIT |
| 20807 | + "MUTEX_OMIT", |
| 20808 | +#endif |
| 20809 | +#ifdef SQLITE_MUTEX_PTHREADS |
| 20810 | + "MUTEX_PTHREADS", |
| 20811 | +#endif |
| 20812 | +#ifdef SQLITE_MUTEX_W32 |
| 20813 | + "MUTEX_W32", |
| 20814 | +#endif |
| 20815 | +#ifdef SQLITE_NEED_ERR_NAME |
| 20816 | + "NEED_ERR_NAME", |
| 20817 | +#endif |
| 20818 | +#ifdef SQLITE_NO_SYNC |
| 20819 | + "NO_SYNC", |
| 20820 | +#endif |
| 20821 | +#ifdef SQLITE_OMIT_ALTERTABLE |
| 20822 | + "OMIT_ALTERTABLE", |
| 20823 | +#endif |
| 20824 | +#ifdef SQLITE_OMIT_ANALYZE |
| 20825 | + "OMIT_ANALYZE", |
| 20826 | +#endif |
| 20827 | +#ifdef SQLITE_OMIT_ATTACH |
| 20828 | + "OMIT_ATTACH", |
| 20829 | +#endif |
| 20830 | +#ifdef SQLITE_OMIT_AUTHORIZATION |
| 20831 | + "OMIT_AUTHORIZATION", |
| 20832 | +#endif |
| 20833 | +#ifdef SQLITE_OMIT_AUTOINCREMENT |
| 20834 | + "OMIT_AUTOINCREMENT", |
| 20835 | +#endif |
| 20836 | +#ifdef SQLITE_OMIT_AUTOINIT |
| 20837 | + "OMIT_AUTOINIT", |
| 20838 | +#endif |
| 20839 | +#ifdef SQLITE_OMIT_AUTOMATIC_INDEX |
| 20840 | + "OMIT_AUTOMATIC_INDEX", |
| 20841 | +#endif |
| 20842 | +#ifdef SQLITE_OMIT_AUTORESET |
| 20843 | + "OMIT_AUTORESET", |
| 20844 | +#endif |
| 20845 | +#ifdef SQLITE_OMIT_AUTOVACUUM |
| 20846 | + "OMIT_AUTOVACUUM", |
| 20847 | +#endif |
| 20848 | +#ifdef SQLITE_OMIT_BETWEEN_OPTIMIZATION |
| 20849 | + "OMIT_BETWEEN_OPTIMIZATION", |
| 20850 | +#endif |
| 20851 | +#ifdef SQLITE_OMIT_BLOB_LITERAL |
| 20852 | + "OMIT_BLOB_LITERAL", |
| 20853 | +#endif |
| 20854 | +#ifdef SQLITE_OMIT_CAST |
| 20855 | + "OMIT_CAST", |
| 20856 | +#endif |
| 20857 | +#ifdef SQLITE_OMIT_CHECK |
| 20858 | + "OMIT_CHECK", |
| 20859 | +#endif |
| 20860 | +#ifdef SQLITE_OMIT_COMPLETE |
| 20861 | + "OMIT_COMPLETE", |
| 20862 | +#endif |
| 20863 | +#ifdef SQLITE_OMIT_COMPOUND_SELECT |
| 20864 | + "OMIT_COMPOUND_SELECT", |
| 20865 | +#endif |
| 20866 | +#ifdef SQLITE_OMIT_CONFLICT_CLAUSE |
| 20867 | + "OMIT_CONFLICT_CLAUSE", |
| 20868 | +#endif |
| 20869 | +#ifdef SQLITE_OMIT_CTE |
| 20870 | + "OMIT_CTE", |
| 20871 | +#endif |
| 20872 | +#if defined(SQLITE_OMIT_DATETIME_FUNCS) || defined(SQLITE_OMIT_FLOATING_POINT) |
| 20873 | + "OMIT_DATETIME_FUNCS", |
| 20874 | +#endif |
| 20875 | +#ifdef SQLITE_OMIT_DECLTYPE |
| 20876 | + "OMIT_DECLTYPE", |
| 20877 | +#endif |
| 20878 | +#ifdef SQLITE_OMIT_DEPRECATED |
| 20879 | + "OMIT_DEPRECATED", |
| 20880 | +#endif |
| 20881 | +#ifdef SQLITE_OMIT_DESERIALIZE |
| 20882 | + "OMIT_DESERIALIZE", |
| 20883 | +#endif |
| 20884 | +#ifdef SQLITE_OMIT_DISKIO |
| 20885 | + "OMIT_DISKIO", |
| 20886 | +#endif |
| 20887 | +#ifdef SQLITE_OMIT_EXPLAIN |
| 20888 | + "OMIT_EXPLAIN", |
| 20889 | +#endif |
| 20890 | +#ifdef SQLITE_OMIT_FLAG_PRAGMAS |
| 20891 | + "OMIT_FLAG_PRAGMAS", |
| 20892 | +#endif |
| 20893 | +#ifdef SQLITE_OMIT_FLOATING_POINT |
| 20894 | + "OMIT_FLOATING_POINT", |
| 20895 | +#endif |
| 20896 | +#ifdef SQLITE_OMIT_FOREIGN_KEY |
| 20897 | + "OMIT_FOREIGN_KEY", |
| 20898 | +#endif |
| 20899 | +#ifdef SQLITE_OMIT_GET_TABLE |
| 20900 | + "OMIT_GET_TABLE", |
| 20901 | +#endif |
| 20902 | +#ifdef SQLITE_OMIT_HEX_INTEGER |
| 20903 | + "OMIT_HEX_INTEGER", |
| 20904 | +#endif |
| 20905 | +#ifdef SQLITE_OMIT_INCRBLOB |
| 20906 | + "OMIT_INCRBLOB", |
| 20907 | +#endif |
| 20908 | +#ifdef SQLITE_OMIT_INTEGRITY_CHECK |
| 20909 | + "OMIT_INTEGRITY_CHECK", |
| 20910 | +#endif |
| 20911 | +#ifdef SQLITE_OMIT_INTROSPECTION_PRAGMAS |
| 20912 | + "OMIT_INTROSPECTION_PRAGMAS", |
| 20913 | +#endif |
| 20914 | +#ifdef SQLITE_OMIT_LIKE_OPTIMIZATION |
| 20915 | + "OMIT_LIKE_OPTIMIZATION", |
| 20916 | +#endif |
| 20917 | +#ifdef SQLITE_OMIT_LOAD_EXTENSION |
| 20918 | + "OMIT_LOAD_EXTENSION", |
| 20919 | +#endif |
| 20920 | +#ifdef SQLITE_OMIT_LOCALTIME |
| 20921 | + "OMIT_LOCALTIME", |
| 20922 | +#endif |
| 20923 | +#ifdef SQLITE_OMIT_LOOKASIDE |
| 20924 | + "OMIT_LOOKASIDE", |
| 20925 | +#endif |
| 20926 | +#ifdef SQLITE_OMIT_MEMORYDB |
| 20927 | + "OMIT_MEMORYDB", |
| 20928 | +#endif |
| 20929 | +#ifdef SQLITE_OMIT_OR_OPTIMIZATION |
| 20930 | + "OMIT_OR_OPTIMIZATION", |
| 20931 | +#endif |
| 20932 | +#ifdef SQLITE_OMIT_PAGER_PRAGMAS |
| 20933 | + "OMIT_PAGER_PRAGMAS", |
| 20934 | +#endif |
| 20935 | +#ifdef SQLITE_OMIT_PARSER_TRACE |
| 20936 | + "OMIT_PARSER_TRACE", |
| 20937 | +#endif |
| 20938 | +#ifdef SQLITE_OMIT_POPEN |
| 20939 | + "OMIT_POPEN", |
| 20940 | +#endif |
| 20941 | +#ifdef SQLITE_OMIT_PRAGMA |
| 20942 | + "OMIT_PRAGMA", |
| 20943 | +#endif |
| 20944 | +#ifdef SQLITE_OMIT_PROGRESS_CALLBACK |
| 20945 | + "OMIT_PROGRESS_CALLBACK", |
| 20946 | +#endif |
| 20947 | +#ifdef SQLITE_OMIT_QUICKBALANCE |
| 20948 | + "OMIT_QUICKBALANCE", |
| 20949 | +#endif |
| 20950 | +#ifdef SQLITE_OMIT_REINDEX |
| 20951 | + "OMIT_REINDEX", |
| 20952 | +#endif |
| 20953 | +#ifdef SQLITE_OMIT_SCHEMA_PRAGMAS |
| 20954 | + "OMIT_SCHEMA_PRAGMAS", |
| 20955 | +#endif |
| 20956 | +#ifdef SQLITE_OMIT_SCHEMA_VERSION_PRAGMAS |
| 20957 | + "OMIT_SCHEMA_VERSION_PRAGMAS", |
| 20958 | +#endif |
| 20959 | +#ifdef SQLITE_OMIT_SHARED_CACHE |
| 20960 | + "OMIT_SHARED_CACHE", |
| 20961 | +#endif |
| 20962 | +#ifdef SQLITE_OMIT_SHUTDOWN_DIRECTORIES |
| 20963 | + "OMIT_SHUTDOWN_DIRECTORIES", |
| 20964 | +#endif |
| 20965 | +#ifdef SQLITE_OMIT_SUBQUERY |
| 20966 | + "OMIT_SUBQUERY", |
| 20967 | +#endif |
| 20968 | +#ifdef SQLITE_OMIT_TCL_VARIABLE |
| 20969 | + "OMIT_TCL_VARIABLE", |
| 20970 | +#endif |
| 20971 | +#ifdef SQLITE_OMIT_TEMPDB |
| 20972 | + "OMIT_TEMPDB", |
| 20973 | +#endif |
| 20974 | +#ifdef SQLITE_OMIT_TEST_CONTROL |
| 20975 | + "OMIT_TEST_CONTROL", |
| 20976 | +#endif |
| 20977 | +#ifdef SQLITE_OMIT_TRACE |
| 20978 | +# if SQLITE_OMIT_TRACE != 1 |
| 20979 | + "OMIT_TRACE=" CTIMEOPT_VAL(SQLITE_OMIT_TRACE), |
| 20980 | +# endif |
| 20981 | +#endif |
| 20982 | +#ifdef SQLITE_OMIT_TRIGGER |
| 20983 | + "OMIT_TRIGGER", |
| 20984 | +#endif |
| 20985 | +#ifdef SQLITE_OMIT_TRUNCATE_OPTIMIZATION |
| 20986 | + "OMIT_TRUNCATE_OPTIMIZATION", |
| 20987 | +#endif |
| 20988 | +#ifdef SQLITE_OMIT_UTF16 |
| 20989 | + "OMIT_UTF16", |
| 20990 | +#endif |
| 20991 | +#ifdef SQLITE_OMIT_VACUUM |
| 20992 | + "OMIT_VACUUM", |
| 20993 | +#endif |
| 20994 | +#ifdef SQLITE_OMIT_VIEW |
| 20995 | + "OMIT_VIEW", |
| 20996 | +#endif |
| 20997 | +#ifdef SQLITE_OMIT_VIRTUALTABLE |
| 20998 | + "OMIT_VIRTUALTABLE", |
| 20999 | +#endif |
| 21000 | +#ifdef SQLITE_OMIT_WAL |
| 21001 | + "OMIT_WAL", |
| 21002 | +#endif |
| 21003 | +#ifdef SQLITE_OMIT_WSD |
| 21004 | + "OMIT_WSD", |
| 21005 | +#endif |
| 21006 | +#ifdef SQLITE_OMIT_XFER_OPT |
| 21007 | + "OMIT_XFER_OPT", |
| 21008 | +#endif |
| 21009 | +#ifdef SQLITE_PCACHE_SEPARATE_HEADER |
| 21010 | + "PCACHE_SEPARATE_HEADER", |
| 21011 | +#endif |
| 21012 | +#ifdef SQLITE_PERFORMANCE_TRACE |
| 21013 | + "PERFORMANCE_TRACE", |
| 21014 | +#endif |
| 21015 | +#ifdef SQLITE_POWERSAFE_OVERWRITE |
| 21016 | +# if SQLITE_POWERSAFE_OVERWRITE != 1 |
| 21017 | + "POWERSAFE_OVERWRITE=" CTIMEOPT_VAL(SQLITE_POWERSAFE_OVERWRITE), |
| 21018 | +# endif |
| 21019 | +#endif |
| 21020 | +#ifdef SQLITE_PREFER_PROXY_LOCKING |
| 21021 | + "PREFER_PROXY_LOCKING", |
| 21022 | +#endif |
| 21023 | +#ifdef SQLITE_PROXY_DEBUG |
| 21024 | + "PROXY_DEBUG", |
| 21025 | +#endif |
| 21026 | +#ifdef SQLITE_REVERSE_UNORDERED_SELECTS |
| 21027 | + "REVERSE_UNORDERED_SELECTS", |
| 21028 | +#endif |
| 21029 | +#ifdef SQLITE_RTREE_INT_ONLY |
| 21030 | + "RTREE_INT_ONLY", |
| 21031 | +#endif |
| 21032 | +#ifdef SQLITE_SECURE_DELETE |
| 21033 | + "SECURE_DELETE", |
| 21034 | +#endif |
| 21035 | +#ifdef SQLITE_SMALL_STACK |
| 21036 | + "SMALL_STACK", |
| 21037 | +#endif |
| 21038 | +#ifdef SQLITE_SORTER_PMASZ |
| 21039 | + "SORTER_PMASZ=" CTIMEOPT_VAL(SQLITE_SORTER_PMASZ), |
| 21040 | +#endif |
| 21041 | +#ifdef SQLITE_SOUNDEX |
| 21042 | + "SOUNDEX", |
| 21043 | +#endif |
| 21044 | +#ifdef SQLITE_STAT4_SAMPLES |
| 21045 | + "STAT4_SAMPLES=" CTIMEOPT_VAL(SQLITE_STAT4_SAMPLES), |
| 21046 | +#endif |
| 21047 | +#ifdef SQLITE_STMTJRNL_SPILL |
| 21048 | + "STMTJRNL_SPILL=" CTIMEOPT_VAL(SQLITE_STMTJRNL_SPILL), |
| 21049 | +#endif |
| 21050 | +#ifdef SQLITE_SUBSTR_COMPATIBILITY |
| 21051 | + "SUBSTR_COMPATIBILITY", |
| 21052 | +#endif |
| 21053 | +#if (!defined(SQLITE_WIN32_MALLOC) \ |
| 21054 | + && !defined(SQLITE_ZERO_MALLOC) \ |
| 21055 | + && !defined(SQLITE_MEMDEBUG) \ |
| 21056 | + ) || defined(SQLITE_SYSTEM_MALLOC) |
| 21057 | + "SYSTEM_MALLOC", |
| 21058 | +#endif |
| 21059 | +#ifdef SQLITE_TCL |
| 21060 | + "TCL", |
| 21061 | +#endif |
| 21062 | +#ifdef SQLITE_TEMP_STORE |
| 21063 | + "TEMP_STORE=" CTIMEOPT_VAL(SQLITE_TEMP_STORE), |
| 21064 | +#endif |
| 21065 | +#ifdef SQLITE_TEST |
| 21066 | + "TEST", |
| 21067 | +#endif |
| 21068 | +#if defined(SQLITE_THREADSAFE) |
| 21069 | + "THREADSAFE=" CTIMEOPT_VAL(SQLITE_THREADSAFE), |
| 21070 | +#elif defined(THREADSAFE) |
| 21071 | + "THREADSAFE=" CTIMEOPT_VAL(THREADSAFE), |
| 21072 | +#else |
| 21073 | + "THREADSAFE=1", |
| 21074 | +#endif |
| 21075 | +#ifdef SQLITE_UNLINK_AFTER_CLOSE |
| 21076 | + "UNLINK_AFTER_CLOSE", |
| 21077 | +#endif |
| 21078 | +#ifdef SQLITE_UNTESTABLE |
| 21079 | + "UNTESTABLE", |
| 21080 | +#endif |
| 21081 | +#ifdef SQLITE_USER_AUTHENTICATION |
| 21082 | + "USER_AUTHENTICATION", |
| 21083 | +#endif |
| 21084 | +#ifdef SQLITE_USE_ALLOCA |
| 21085 | + "USE_ALLOCA", |
| 21086 | +#endif |
| 21087 | +#ifdef SQLITE_USE_FCNTL_TRACE |
| 21088 | + "USE_FCNTL_TRACE", |
| 21089 | +#endif |
| 21090 | +#ifdef SQLITE_USE_URI |
| 21091 | + "USE_URI", |
| 21092 | +#endif |
| 21093 | +#ifdef SQLITE_VDBE_COVERAGE |
| 21094 | + "VDBE_COVERAGE", |
| 21095 | +#endif |
| 21096 | +#ifdef SQLITE_WIN32_MALLOC |
| 21097 | + "WIN32_MALLOC", |
| 21098 | +#endif |
| 21099 | +#ifdef SQLITE_ZERO_MALLOC |
| 21100 | + "ZERO_MALLOC", |
| 21101 | +#endif |
| 21102 | +/* |
| 21103 | +** END CODE GENERATED BY tool/mkctime.tcl |
| 21104 | +*/ |
| 21105 | +}; |
| 21106 | + |
| 21107 | +SQLITE_PRIVATE const char **sqlite3CompileOptions(int *pnOpt){ |
| 21108 | + *pnOpt = sizeof(sqlite3azCompileOpt) / sizeof(sqlite3azCompileOpt[0]); |
| 21109 | + return (const char**)sqlite3azCompileOpt; |
| 21110 | +} |
| 21111 | + |
| 21112 | +#endif /* SQLITE_OMIT_COMPILEOPTION_DIAGS */ |
| 21113 | + |
| 21114 | +/************** End of ctime.c ***********************************************/ |
| 20794 | 21115 | /************** Begin file global.c ******************************************/ |
| 20795 | 21116 | /* |
| 20796 | 21117 | ** 2008 June 13 |
| 20797 | 21118 | ** |
| 20798 | 21119 | ** The author disclaims copyright to this source code. In place of |
| | @@ -21139,10 +21460,30 @@ |
| 21139 | 21460 | |
| 21140 | 21461 | /* |
| 21141 | 21462 | ** Name of the default collating sequence |
| 21142 | 21463 | */ |
| 21143 | 21464 | SQLITE_PRIVATE const char sqlite3StrBINARY[] = "BINARY"; |
| 21465 | + |
| 21466 | +/* |
| 21467 | +** Standard typenames. These names must match the COLTYPE_* definitions. |
| 21468 | +** Adjust the SQLITE_N_STDTYPE value if adding or removing entries. |
| 21469 | +*/ |
| 21470 | +SQLITE_PRIVATE const unsigned char sqlite3StdTypeLen[] = { 4, 3, 7, 4, 4 }; |
| 21471 | +SQLITE_PRIVATE const char sqlite3StdTypeAffinity[] = { |
| 21472 | + SQLITE_AFF_BLOB, |
| 21473 | + SQLITE_AFF_INTEGER, |
| 21474 | + SQLITE_AFF_INTEGER, |
| 21475 | + SQLITE_AFF_REAL, |
| 21476 | + SQLITE_AFF_TEXT |
| 21477 | +}; |
| 21478 | +SQLITE_PRIVATE const char *sqlite3StdType[] = { |
| 21479 | + "BLOB", |
| 21480 | + "INT", |
| 21481 | + "INTEGER", |
| 21482 | + "REAL", |
| 21483 | + "TEXT" |
| 21484 | +}; |
| 21144 | 21485 | |
| 21145 | 21486 | /************** End of global.c **********************************************/ |
| 21146 | 21487 | /************** Begin file status.c ******************************************/ |
| 21147 | 21488 | /* |
| 21148 | 21489 | ** 2008 June 18 |
| | @@ -21342,12 +21683,12 @@ |
| 21342 | 21683 | int pc; /* Program Counter in parent (calling) frame */ |
| 21343 | 21684 | int nOp; /* Size of aOp array */ |
| 21344 | 21685 | int nMem; /* Number of entries in aMem */ |
| 21345 | 21686 | int nChildMem; /* Number of memory cells for child frame */ |
| 21346 | 21687 | int nChildCsr; /* Number of cursors for child frame */ |
| 21347 | | - int nChange; /* Statement changes (Vdbe.nChange) */ |
| 21348 | | - int nDbChange; /* Value of db->nChange */ |
| 21688 | + i64 nChange; /* Statement changes (Vdbe.nChange) */ |
| 21689 | + i64 nDbChange; /* Value of db->nChange */ |
| 21349 | 21690 | }; |
| 21350 | 21691 | |
| 21351 | 21692 | /* Magic number for sanity checking on VdbeFrame objects */ |
| 21352 | 21693 | #define SQLITE_FRAME_MAGIC 0x879fb71e |
| 21353 | 21694 | |
| | @@ -21550,11 +21891,11 @@ |
| 21550 | 21891 | int nMem; /* Number of memory locations currently allocated */ |
| 21551 | 21892 | int nCursor; /* Number of slots in apCsr[] */ |
| 21552 | 21893 | u32 cacheCtr; /* VdbeCursor row cache generation counter */ |
| 21553 | 21894 | int pc; /* The program counter */ |
| 21554 | 21895 | int rc; /* Value to return */ |
| 21555 | | - int nChange; /* Number of db changes made since last reset */ |
| 21896 | + i64 nChange; /* Number of db changes made since last reset */ |
| 21556 | 21897 | int iStatement; /* Statement number (or 0 if has no opened stmt) */ |
| 21557 | 21898 | i64 iCurrentTime; /* Value of julianday('now') for this statement */ |
| 21558 | 21899 | i64 nFkConstraint; /* Number of imm. FK constraints this VM */ |
| 21559 | 21900 | i64 nStmtDefCons; /* Number of def. constraints when stmt started */ |
| 21560 | 21901 | i64 nStmtDefImmCons; /* Number of def. imm constraints when stmt started */ |
| | @@ -21695,10 +22036,11 @@ |
| 21695 | 22036 | SQLITE_PRIVATE int sqlite3VdbeMemIsRowSet(const Mem*); |
| 21696 | 22037 | #endif |
| 21697 | 22038 | SQLITE_PRIVATE int sqlite3VdbeMemSetRowSet(Mem*); |
| 21698 | 22039 | SQLITE_PRIVATE int sqlite3VdbeMemMakeWriteable(Mem*); |
| 21699 | 22040 | SQLITE_PRIVATE int sqlite3VdbeMemStringify(Mem*, u8, u8); |
| 22041 | +SQLITE_PRIVATE int sqlite3IntFloatCompare(i64,double); |
| 21700 | 22042 | SQLITE_PRIVATE i64 sqlite3VdbeIntValue(Mem*); |
| 21701 | 22043 | SQLITE_PRIVATE int sqlite3VdbeMemIntegerify(Mem*); |
| 21702 | 22044 | SQLITE_PRIVATE double sqlite3VdbeRealValue(Mem*); |
| 21703 | 22045 | SQLITE_PRIVATE int sqlite3VdbeBooleanValue(Mem*, int ifNull); |
| 21704 | 22046 | SQLITE_PRIVATE void sqlite3VdbeIntegerAffinity(Mem*); |
| | @@ -27108,209 +27450,11 @@ |
| 27108 | 27450 | |
| 27109 | 27451 | #if SQLITE_OS_WIN |
| 27110 | 27452 | /* |
| 27111 | 27453 | ** Include code that is common to all os_*.c files |
| 27112 | 27454 | */ |
| 27113 | | -/************** Include os_common.h in the middle of mutex_w32.c *************/ |
| 27114 | | -/************** Begin file os_common.h ***************************************/ |
| 27115 | | -/* |
| 27116 | | -** 2004 May 22 |
| 27117 | | -** |
| 27118 | | -** The author disclaims copyright to this source code. In place of |
| 27119 | | -** a legal notice, here is a blessing: |
| 27120 | | -** |
| 27121 | | -** May you do good and not evil. |
| 27122 | | -** May you find forgiveness for yourself and forgive others. |
| 27123 | | -** May you share freely, never taking more than you give. |
| 27124 | | -** |
| 27125 | | -****************************************************************************** |
| 27126 | | -** |
| 27127 | | -** This file contains macros and a little bit of code that is common to |
| 27128 | | -** all of the platform-specific files (os_*.c) and is #included into those |
| 27129 | | -** files. |
| 27130 | | -** |
| 27131 | | -** This file should be #included by the os_*.c files only. It is not a |
| 27132 | | -** general purpose header file. |
| 27133 | | -*/ |
| 27134 | | -#ifndef _OS_COMMON_H_ |
| 27135 | | -#define _OS_COMMON_H_ |
| 27136 | | - |
| 27137 | | -/* |
| 27138 | | -** At least two bugs have slipped in because we changed the MEMORY_DEBUG |
| 27139 | | -** macro to SQLITE_DEBUG and some older makefiles have not yet made the |
| 27140 | | -** switch. The following code should catch this problem at compile-time. |
| 27141 | | -*/ |
| 27142 | | -#ifdef MEMORY_DEBUG |
| 27143 | | -# error "The MEMORY_DEBUG macro is obsolete. Use SQLITE_DEBUG instead." |
| 27144 | | -#endif |
| 27145 | | - |
| 27146 | | -/* |
| 27147 | | -** Macros for performance tracing. Normally turned off. Only works |
| 27148 | | -** on i486 hardware. |
| 27149 | | -*/ |
| 27150 | | -#ifdef SQLITE_PERFORMANCE_TRACE |
| 27151 | | - |
| 27152 | | -/* |
| 27153 | | -** hwtime.h contains inline assembler code for implementing |
| 27154 | | -** high-performance timing routines. |
| 27155 | | -*/ |
| 27156 | | -/************** Include hwtime.h in the middle of os_common.h ****************/ |
| 27157 | | -/************** Begin file hwtime.h ******************************************/ |
| 27158 | | -/* |
| 27159 | | -** 2008 May 27 |
| 27160 | | -** |
| 27161 | | -** The author disclaims copyright to this source code. In place of |
| 27162 | | -** a legal notice, here is a blessing: |
| 27163 | | -** |
| 27164 | | -** May you do good and not evil. |
| 27165 | | -** May you find forgiveness for yourself and forgive others. |
| 27166 | | -** May you share freely, never taking more than you give. |
| 27167 | | -** |
| 27168 | | -****************************************************************************** |
| 27169 | | -** |
| 27170 | | -** This file contains inline asm code for retrieving "high-performance" |
| 27171 | | -** counters for x86 and x86_64 class CPUs. |
| 27172 | | -*/ |
| 27173 | | -#ifndef SQLITE_HWTIME_H |
| 27174 | | -#define SQLITE_HWTIME_H |
| 27175 | | - |
| 27176 | | -/* |
| 27177 | | -** The following routine only works on pentium-class (or newer) processors. |
| 27178 | | -** It uses the RDTSC opcode to read the cycle count value out of the |
| 27179 | | -** processor and returns that value. This can be used for high-res |
| 27180 | | -** profiling. |
| 27181 | | -*/ |
| 27182 | | -#if !defined(__STRICT_ANSI__) && \ |
| 27183 | | - (defined(__GNUC__) || defined(_MSC_VER)) && \ |
| 27184 | | - (defined(i386) || defined(__i386__) || defined(_M_IX86)) |
| 27185 | | - |
| 27186 | | - #if defined(__GNUC__) |
| 27187 | | - |
| 27188 | | - __inline__ sqlite_uint64 sqlite3Hwtime(void){ |
| 27189 | | - unsigned int lo, hi; |
| 27190 | | - __asm__ __volatile__ ("rdtsc" : "=a" (lo), "=d" (hi)); |
| 27191 | | - return (sqlite_uint64)hi << 32 | lo; |
| 27192 | | - } |
| 27193 | | - |
| 27194 | | - #elif defined(_MSC_VER) |
| 27195 | | - |
| 27196 | | - __declspec(naked) __inline sqlite_uint64 __cdecl sqlite3Hwtime(void){ |
| 27197 | | - __asm { |
| 27198 | | - rdtsc |
| 27199 | | - ret ; return value at EDX:EAX |
| 27200 | | - } |
| 27201 | | - } |
| 27202 | | - |
| 27203 | | - #endif |
| 27204 | | - |
| 27205 | | -#elif !defined(__STRICT_ANSI__) && (defined(__GNUC__) && defined(__x86_64__)) |
| 27206 | | - |
| 27207 | | - __inline__ sqlite_uint64 sqlite3Hwtime(void){ |
| 27208 | | - unsigned long val; |
| 27209 | | - __asm__ __volatile__ ("rdtsc" : "=A" (val)); |
| 27210 | | - return val; |
| 27211 | | - } |
| 27212 | | - |
| 27213 | | -#elif !defined(__STRICT_ANSI__) && (defined(__GNUC__) && defined(__ppc__)) |
| 27214 | | - |
| 27215 | | - __inline__ sqlite_uint64 sqlite3Hwtime(void){ |
| 27216 | | - unsigned long long retval; |
| 27217 | | - unsigned long junk; |
| 27218 | | - __asm__ __volatile__ ("\n\ |
| 27219 | | - 1: mftbu %1\n\ |
| 27220 | | - mftb %L0\n\ |
| 27221 | | - mftbu %0\n\ |
| 27222 | | - cmpw %0,%1\n\ |
| 27223 | | - bne 1b" |
| 27224 | | - : "=r" (retval), "=r" (junk)); |
| 27225 | | - return retval; |
| 27226 | | - } |
| 27227 | | - |
| 27228 | | -#else |
| 27229 | | - |
| 27230 | | - /* |
| 27231 | | - ** asm() is needed for hardware timing support. Without asm(), |
| 27232 | | - ** disable the sqlite3Hwtime() routine. |
| 27233 | | - ** |
| 27234 | | - ** sqlite3Hwtime() is only used for some obscure debugging |
| 27235 | | - ** and analysis configurations, not in any deliverable, so this |
| 27236 | | - ** should not be a great loss. |
| 27237 | | - */ |
| 27238 | | -SQLITE_PRIVATE sqlite_uint64 sqlite3Hwtime(void){ return ((sqlite_uint64)0); } |
| 27239 | | - |
| 27240 | | -#endif |
| 27241 | | - |
| 27242 | | -#endif /* !defined(SQLITE_HWTIME_H) */ |
| 27243 | | - |
| 27244 | | -/************** End of hwtime.h **********************************************/ |
| 27245 | | -/************** Continuing where we left off in os_common.h ******************/ |
| 27246 | | - |
| 27247 | | -static sqlite_uint64 g_start; |
| 27248 | | -static sqlite_uint64 g_elapsed; |
| 27249 | | -#define TIMER_START g_start=sqlite3Hwtime() |
| 27250 | | -#define TIMER_END g_elapsed=sqlite3Hwtime()-g_start |
| 27251 | | -#define TIMER_ELAPSED g_elapsed |
| 27252 | | -#else |
| 27253 | | -#define TIMER_START |
| 27254 | | -#define TIMER_END |
| 27255 | | -#define TIMER_ELAPSED ((sqlite_uint64)0) |
| 27256 | | -#endif |
| 27257 | | - |
| 27258 | | -/* |
| 27259 | | -** If we compile with the SQLITE_TEST macro set, then the following block |
| 27260 | | -** of code will give us the ability to simulate a disk I/O error. This |
| 27261 | | -** is used for testing the I/O recovery logic. |
| 27262 | | -*/ |
| 27263 | | -#if defined(SQLITE_TEST) |
| 27264 | | -SQLITE_API extern int sqlite3_io_error_hit; |
| 27265 | | -SQLITE_API extern int sqlite3_io_error_hardhit; |
| 27266 | | -SQLITE_API extern int sqlite3_io_error_pending; |
| 27267 | | -SQLITE_API extern int sqlite3_io_error_persist; |
| 27268 | | -SQLITE_API extern int sqlite3_io_error_benign; |
| 27269 | | -SQLITE_API extern int sqlite3_diskfull_pending; |
| 27270 | | -SQLITE_API extern int sqlite3_diskfull; |
| 27271 | | -#define SimulateIOErrorBenign(X) sqlite3_io_error_benign=(X) |
| 27272 | | -#define SimulateIOError(CODE) \ |
| 27273 | | - if( (sqlite3_io_error_persist && sqlite3_io_error_hit) \ |
| 27274 | | - || sqlite3_io_error_pending-- == 1 ) \ |
| 27275 | | - { local_ioerr(); CODE; } |
| 27276 | | -static void local_ioerr(){ |
| 27277 | | - IOTRACE(("IOERR\n")); |
| 27278 | | - sqlite3_io_error_hit++; |
| 27279 | | - if( !sqlite3_io_error_benign ) sqlite3_io_error_hardhit++; |
| 27280 | | -} |
| 27281 | | -#define SimulateDiskfullError(CODE) \ |
| 27282 | | - if( sqlite3_diskfull_pending ){ \ |
| 27283 | | - if( sqlite3_diskfull_pending == 1 ){ \ |
| 27284 | | - local_ioerr(); \ |
| 27285 | | - sqlite3_diskfull = 1; \ |
| 27286 | | - sqlite3_io_error_hit = 1; \ |
| 27287 | | - CODE; \ |
| 27288 | | - }else{ \ |
| 27289 | | - sqlite3_diskfull_pending--; \ |
| 27290 | | - } \ |
| 27291 | | - } |
| 27292 | | -#else |
| 27293 | | -#define SimulateIOErrorBenign(X) |
| 27294 | | -#define SimulateIOError(A) |
| 27295 | | -#define SimulateDiskfullError(A) |
| 27296 | | -#endif /* defined(SQLITE_TEST) */ |
| 27297 | | - |
| 27298 | | -/* |
| 27299 | | -** When testing, keep a count of the number of open files. |
| 27300 | | -*/ |
| 27301 | | -#if defined(SQLITE_TEST) |
| 27302 | | -SQLITE_API extern int sqlite3_open_file_count; |
| 27303 | | -#define OpenCounter(X) sqlite3_open_file_count+=(X) |
| 27304 | | -#else |
| 27305 | | -#define OpenCounter(X) |
| 27306 | | -#endif /* defined(SQLITE_TEST) */ |
| 27307 | | - |
| 27308 | | -#endif /* !defined(_OS_COMMON_H_) */ |
| 27309 | | - |
| 27310 | | -/************** End of os_common.h *******************************************/ |
| 27311 | | -/************** Continuing where we left off in mutex_w32.c ******************/ |
| 27455 | +/* #include "os_common.h" */ |
| 27312 | 27456 | |
| 27313 | 27457 | /* |
| 27314 | 27458 | ** Include the header file for the Windows VFS. |
| 27315 | 27459 | */ |
| 27316 | 27460 | /************** Include os_win.h in the middle of mutex_w32.c ****************/ |
| | @@ -30077,10 +30221,12 @@ |
| 30077 | 30221 | sqlite3_str_appendf(&x, " tab=%Q nCol=%d ptr=%p used=%llx", |
| 30078 | 30222 | pItem->pTab->zName, pItem->pTab->nCol, pItem->pTab, pItem->colUsed); |
| 30079 | 30223 | } |
| 30080 | 30224 | if( pItem->fg.jointype & JT_LEFT ){ |
| 30081 | 30225 | sqlite3_str_appendf(&x, " LEFT-JOIN"); |
| 30226 | + }else if( pItem->fg.jointype & JT_CROSS ){ |
| 30227 | + sqlite3_str_appendf(&x, " CROSS-JOIN"); |
| 30082 | 30228 | } |
| 30083 | 30229 | if( pItem->fg.fromDDL ){ |
| 30084 | 30230 | sqlite3_str_appendf(&x, " DDL"); |
| 30085 | 30231 | } |
| 30086 | 30232 | if( pItem->fg.isCte ){ |
| | @@ -30407,12 +30553,12 @@ |
| 30407 | 30553 | case TK_NULL: { |
| 30408 | 30554 | sqlite3TreeViewLine(pView,"NULL"); |
| 30409 | 30555 | break; |
| 30410 | 30556 | } |
| 30411 | 30557 | case TK_TRUEFALSE: { |
| 30412 | | - sqlite3TreeViewLine(pView, |
| 30413 | | - sqlite3ExprTruthValue(pExpr) ? "TRUE" : "FALSE"); |
| 30558 | + sqlite3TreeViewLine(pView,"%s%s", |
| 30559 | + sqlite3ExprTruthValue(pExpr) ? "TRUE" : "FALSE", zFlgs); |
| 30414 | 30560 | break; |
| 30415 | 30561 | } |
| 30416 | 30562 | #ifndef SQLITE_OMIT_BLOB_LITERAL |
| 30417 | 30563 | case TK_BLOB: { |
| 30418 | 30564 | sqlite3TreeViewLine(pView,"%s", pExpr->u.zToken); |
| | @@ -30632,11 +30778,13 @@ |
| 30632 | 30778 | sqlite3TreeViewBareExprList(pView, pExpr->x.pList, z); |
| 30633 | 30779 | sqlite3_free(z); |
| 30634 | 30780 | break; |
| 30635 | 30781 | } |
| 30636 | 30782 | case TK_SELECT_COLUMN: { |
| 30637 | | - sqlite3TreeViewLine(pView, "SELECT-COLUMN %d", pExpr->iColumn); |
| 30783 | + sqlite3TreeViewLine(pView, "SELECT-COLUMN %d of [0..%d]%s", |
| 30784 | + pExpr->iColumn, pExpr->iTable-1, |
| 30785 | + pExpr->pRight==pExpr->pLeft ? " (SELECT-owner)" : ""); |
| 30638 | 30786 | sqlite3TreeViewSelect(pView, pExpr->pLeft->x.pSelect, 0); |
| 30639 | 30787 | break; |
| 30640 | 30788 | } |
| 30641 | 30789 | case TK_IF_NULL_ROW: { |
| 30642 | 30790 | sqlite3TreeViewLine(pView, "IF-NULL-ROW %d", pExpr->iTable); |
| | @@ -30648,10 +30796,19 @@ |
| 30648 | 30796 | sqlite3TreeViewLine(pView, "ERROR"); |
| 30649 | 30797 | tmp = *pExpr; |
| 30650 | 30798 | tmp.op = pExpr->op2; |
| 30651 | 30799 | sqlite3TreeViewExpr(pView, &tmp, 0); |
| 30652 | 30800 | break; |
| 30801 | + } |
| 30802 | + case TK_ROW: { |
| 30803 | + if( pExpr->iColumn<=0 ){ |
| 30804 | + sqlite3TreeViewLine(pView, "First FROM table rowid"); |
| 30805 | + }else{ |
| 30806 | + sqlite3TreeViewLine(pView, "First FROM table column %d", |
| 30807 | + pExpr->iColumn-1); |
| 30808 | + } |
| 30809 | + break; |
| 30653 | 30810 | } |
| 30654 | 30811 | default: { |
| 30655 | 30812 | sqlite3TreeViewLine(pView, "op=%d", pExpr->op); |
| 30656 | 30813 | break; |
| 30657 | 30814 | } |
| | @@ -30798,15 +30955,20 @@ |
| 30798 | 30955 | ** Nothing in this file or anywhere else in SQLite does any kind of |
| 30799 | 30956 | ** encryption. The RC4 algorithm is being used as a PRNG (pseudo-random |
| 30800 | 30957 | ** number generator) not as an encryption device. |
| 30801 | 30958 | */ |
| 30802 | 30959 | if( !wsdPrng.isInit ){ |
| 30960 | + sqlite3_vfs *pVfs = sqlite3_vfs_find(0); |
| 30803 | 30961 | int i; |
| 30804 | 30962 | char k[256]; |
| 30805 | 30963 | wsdPrng.j = 0; |
| 30806 | 30964 | wsdPrng.i = 0; |
| 30807 | | - sqlite3OsRandomness(sqlite3_vfs_find(0), 256, k); |
| 30965 | + if( NEVER(pVfs==0) ){ |
| 30966 | + memset(k, 0, sizeof(k)); |
| 30967 | + }else{ |
| 30968 | + sqlite3OsRandomness(pVfs, 256, k); |
| 30969 | + } |
| 30808 | 30970 | for(i=0; i<256; i++){ |
| 30809 | 30971 | wsdPrng.s[i] = (u8)i; |
| 30810 | 30972 | } |
| 30811 | 30973 | for(i=0; i<256; i++){ |
| 30812 | 30974 | wsdPrng.j += wsdPrng.s[i] + k[i]; |
| | @@ -31763,12 +31925,18 @@ |
| 31763 | 31925 | ** |
| 31764 | 31926 | ** The column type is an extra string stored after the zero-terminator on |
| 31765 | 31927 | ** the column name if and only if the COLFLAG_HASTYPE flag is set. |
| 31766 | 31928 | */ |
| 31767 | 31929 | SQLITE_PRIVATE char *sqlite3ColumnType(Column *pCol, char *zDflt){ |
| 31768 | | - if( (pCol->colFlags & COLFLAG_HASTYPE)==0 ) return zDflt; |
| 31769 | | - return pCol->zName + strlen(pCol->zName) + 1; |
| 31930 | + if( pCol->colFlags & COLFLAG_HASTYPE ){ |
| 31931 | + return pCol->zCnName + strlen(pCol->zCnName) + 1; |
| 31932 | + }else if( pCol->eType ){ |
| 31933 | + assert( pCol->eType<=SQLITE_N_STDTYPE ); |
| 31934 | + return (char*)sqlite3StdType[pCol->eType-1]; |
| 31935 | + }else{ |
| 31936 | + return zDflt; |
| 31937 | + } |
| 31770 | 31938 | } |
| 31771 | 31939 | |
| 31772 | 31940 | /* |
| 31773 | 31941 | ** Helper function for sqlite3Error() - called rarely. Broken out into |
| 31774 | 31942 | ** a separate routine to avoid unnecessary register saves on entry to |
| | @@ -31939,10 +32107,32 @@ |
| 31939 | 32107 | SQLITE_PRIVATE void sqlite3DequoteExpr(Expr *p){ |
| 31940 | 32108 | assert( sqlite3Isquote(p->u.zToken[0]) ); |
| 31941 | 32109 | p->flags |= p->u.zToken[0]=='"' ? EP_Quoted|EP_DblQuoted : EP_Quoted; |
| 31942 | 32110 | sqlite3Dequote(p->u.zToken); |
| 31943 | 32111 | } |
| 32112 | + |
| 32113 | +/* |
| 32114 | +** If the input token p is quoted, try to adjust the token to remove |
| 32115 | +** the quotes. This is not always possible: |
| 32116 | +** |
| 32117 | +** "abc" -> abc |
| 32118 | +** "ab""cd" -> (not possible because of the interior "") |
| 32119 | +** |
| 32120 | +** Remove the quotes if possible. This is a optimization. The overall |
| 32121 | +** system should still return the correct answer even if this routine |
| 32122 | +** is always a no-op. |
| 32123 | +*/ |
| 32124 | +SQLITE_PRIVATE void sqlite3DequoteToken(Token *p){ |
| 32125 | + unsigned int i; |
| 32126 | + if( p->n<2 ) return; |
| 32127 | + if( !sqlite3Isquote(p->z[0]) ) return; |
| 32128 | + for(i=1; i<p->n-1; i++){ |
| 32129 | + if( sqlite3Isquote(p->z[i]) ) return; |
| 32130 | + } |
| 32131 | + p->n -= 2; |
| 32132 | + p->z++; |
| 32133 | +} |
| 31944 | 32134 | |
| 31945 | 32135 | /* |
| 31946 | 32136 | ** Generate a Token object from a string |
| 31947 | 32137 | */ |
| 31948 | 32138 | SQLITE_PRIVATE void sqlite3TokenInit(Token *p, char *z){ |
| | @@ -34150,209 +34340,11 @@ |
| 34150 | 34340 | #define UNIXFILE_NOLOCK 0x80 /* Do no file locking */ |
| 34151 | 34341 | |
| 34152 | 34342 | /* |
| 34153 | 34343 | ** Include code that is common to all os_*.c files |
| 34154 | 34344 | */ |
| 34155 | | -/************** Include os_common.h in the middle of os_unix.c ***************/ |
| 34156 | | -/************** Begin file os_common.h ***************************************/ |
| 34157 | | -/* |
| 34158 | | -** 2004 May 22 |
| 34159 | | -** |
| 34160 | | -** The author disclaims copyright to this source code. In place of |
| 34161 | | -** a legal notice, here is a blessing: |
| 34162 | | -** |
| 34163 | | -** May you do good and not evil. |
| 34164 | | -** May you find forgiveness for yourself and forgive others. |
| 34165 | | -** May you share freely, never taking more than you give. |
| 34166 | | -** |
| 34167 | | -****************************************************************************** |
| 34168 | | -** |
| 34169 | | -** This file contains macros and a little bit of code that is common to |
| 34170 | | -** all of the platform-specific files (os_*.c) and is #included into those |
| 34171 | | -** files. |
| 34172 | | -** |
| 34173 | | -** This file should be #included by the os_*.c files only. It is not a |
| 34174 | | -** general purpose header file. |
| 34175 | | -*/ |
| 34176 | | -#ifndef _OS_COMMON_H_ |
| 34177 | | -#define _OS_COMMON_H_ |
| 34178 | | - |
| 34179 | | -/* |
| 34180 | | -** At least two bugs have slipped in because we changed the MEMORY_DEBUG |
| 34181 | | -** macro to SQLITE_DEBUG and some older makefiles have not yet made the |
| 34182 | | -** switch. The following code should catch this problem at compile-time. |
| 34183 | | -*/ |
| 34184 | | -#ifdef MEMORY_DEBUG |
| 34185 | | -# error "The MEMORY_DEBUG macro is obsolete. Use SQLITE_DEBUG instead." |
| 34186 | | -#endif |
| 34187 | | - |
| 34188 | | -/* |
| 34189 | | -** Macros for performance tracing. Normally turned off. Only works |
| 34190 | | -** on i486 hardware. |
| 34191 | | -*/ |
| 34192 | | -#ifdef SQLITE_PERFORMANCE_TRACE |
| 34193 | | - |
| 34194 | | -/* |
| 34195 | | -** hwtime.h contains inline assembler code for implementing |
| 34196 | | -** high-performance timing routines. |
| 34197 | | -*/ |
| 34198 | | -/************** Include hwtime.h in the middle of os_common.h ****************/ |
| 34199 | | -/************** Begin file hwtime.h ******************************************/ |
| 34200 | | -/* |
| 34201 | | -** 2008 May 27 |
| 34202 | | -** |
| 34203 | | -** The author disclaims copyright to this source code. In place of |
| 34204 | | -** a legal notice, here is a blessing: |
| 34205 | | -** |
| 34206 | | -** May you do good and not evil. |
| 34207 | | -** May you find forgiveness for yourself and forgive others. |
| 34208 | | -** May you share freely, never taking more than you give. |
| 34209 | | -** |
| 34210 | | -****************************************************************************** |
| 34211 | | -** |
| 34212 | | -** This file contains inline asm code for retrieving "high-performance" |
| 34213 | | -** counters for x86 and x86_64 class CPUs. |
| 34214 | | -*/ |
| 34215 | | -#ifndef SQLITE_HWTIME_H |
| 34216 | | -#define SQLITE_HWTIME_H |
| 34217 | | - |
| 34218 | | -/* |
| 34219 | | -** The following routine only works on pentium-class (or newer) processors. |
| 34220 | | -** It uses the RDTSC opcode to read the cycle count value out of the |
| 34221 | | -** processor and returns that value. This can be used for high-res |
| 34222 | | -** profiling. |
| 34223 | | -*/ |
| 34224 | | -#if !defined(__STRICT_ANSI__) && \ |
| 34225 | | - (defined(__GNUC__) || defined(_MSC_VER)) && \ |
| 34226 | | - (defined(i386) || defined(__i386__) || defined(_M_IX86)) |
| 34227 | | - |
| 34228 | | - #if defined(__GNUC__) |
| 34229 | | - |
| 34230 | | - __inline__ sqlite_uint64 sqlite3Hwtime(void){ |
| 34231 | | - unsigned int lo, hi; |
| 34232 | | - __asm__ __volatile__ ("rdtsc" : "=a" (lo), "=d" (hi)); |
| 34233 | | - return (sqlite_uint64)hi << 32 | lo; |
| 34234 | | - } |
| 34235 | | - |
| 34236 | | - #elif defined(_MSC_VER) |
| 34237 | | - |
| 34238 | | - __declspec(naked) __inline sqlite_uint64 __cdecl sqlite3Hwtime(void){ |
| 34239 | | - __asm { |
| 34240 | | - rdtsc |
| 34241 | | - ret ; return value at EDX:EAX |
| 34242 | | - } |
| 34243 | | - } |
| 34244 | | - |
| 34245 | | - #endif |
| 34246 | | - |
| 34247 | | -#elif !defined(__STRICT_ANSI__) && (defined(__GNUC__) && defined(__x86_64__)) |
| 34248 | | - |
| 34249 | | - __inline__ sqlite_uint64 sqlite3Hwtime(void){ |
| 34250 | | - unsigned long val; |
| 34251 | | - __asm__ __volatile__ ("rdtsc" : "=A" (val)); |
| 34252 | | - return val; |
| 34253 | | - } |
| 34254 | | - |
| 34255 | | -#elif !defined(__STRICT_ANSI__) && (defined(__GNUC__) && defined(__ppc__)) |
| 34256 | | - |
| 34257 | | - __inline__ sqlite_uint64 sqlite3Hwtime(void){ |
| 34258 | | - unsigned long long retval; |
| 34259 | | - unsigned long junk; |
| 34260 | | - __asm__ __volatile__ ("\n\ |
| 34261 | | - 1: mftbu %1\n\ |
| 34262 | | - mftb %L0\n\ |
| 34263 | | - mftbu %0\n\ |
| 34264 | | - cmpw %0,%1\n\ |
| 34265 | | - bne 1b" |
| 34266 | | - : "=r" (retval), "=r" (junk)); |
| 34267 | | - return retval; |
| 34268 | | - } |
| 34269 | | - |
| 34270 | | -#else |
| 34271 | | - |
| 34272 | | - /* |
| 34273 | | - ** asm() is needed for hardware timing support. Without asm(), |
| 34274 | | - ** disable the sqlite3Hwtime() routine. |
| 34275 | | - ** |
| 34276 | | - ** sqlite3Hwtime() is only used for some obscure debugging |
| 34277 | | - ** and analysis configurations, not in any deliverable, so this |
| 34278 | | - ** should not be a great loss. |
| 34279 | | - */ |
| 34280 | | -SQLITE_PRIVATE sqlite_uint64 sqlite3Hwtime(void){ return ((sqlite_uint64)0); } |
| 34281 | | - |
| 34282 | | -#endif |
| 34283 | | - |
| 34284 | | -#endif /* !defined(SQLITE_HWTIME_H) */ |
| 34285 | | - |
| 34286 | | -/************** End of hwtime.h **********************************************/ |
| 34287 | | -/************** Continuing where we left off in os_common.h ******************/ |
| 34288 | | - |
| 34289 | | -static sqlite_uint64 g_start; |
| 34290 | | -static sqlite_uint64 g_elapsed; |
| 34291 | | -#define TIMER_START g_start=sqlite3Hwtime() |
| 34292 | | -#define TIMER_END g_elapsed=sqlite3Hwtime()-g_start |
| 34293 | | -#define TIMER_ELAPSED g_elapsed |
| 34294 | | -#else |
| 34295 | | -#define TIMER_START |
| 34296 | | -#define TIMER_END |
| 34297 | | -#define TIMER_ELAPSED ((sqlite_uint64)0) |
| 34298 | | -#endif |
| 34299 | | - |
| 34300 | | -/* |
| 34301 | | -** If we compile with the SQLITE_TEST macro set, then the following block |
| 34302 | | -** of code will give us the ability to simulate a disk I/O error. This |
| 34303 | | -** is used for testing the I/O recovery logic. |
| 34304 | | -*/ |
| 34305 | | -#if defined(SQLITE_TEST) |
| 34306 | | -SQLITE_API extern int sqlite3_io_error_hit; |
| 34307 | | -SQLITE_API extern int sqlite3_io_error_hardhit; |
| 34308 | | -SQLITE_API extern int sqlite3_io_error_pending; |
| 34309 | | -SQLITE_API extern int sqlite3_io_error_persist; |
| 34310 | | -SQLITE_API extern int sqlite3_io_error_benign; |
| 34311 | | -SQLITE_API extern int sqlite3_diskfull_pending; |
| 34312 | | -SQLITE_API extern int sqlite3_diskfull; |
| 34313 | | -#define SimulateIOErrorBenign(X) sqlite3_io_error_benign=(X) |
| 34314 | | -#define SimulateIOError(CODE) \ |
| 34315 | | - if( (sqlite3_io_error_persist && sqlite3_io_error_hit) \ |
| 34316 | | - || sqlite3_io_error_pending-- == 1 ) \ |
| 34317 | | - { local_ioerr(); CODE; } |
| 34318 | | -static void local_ioerr(){ |
| 34319 | | - IOTRACE(("IOERR\n")); |
| 34320 | | - sqlite3_io_error_hit++; |
| 34321 | | - if( !sqlite3_io_error_benign ) sqlite3_io_error_hardhit++; |
| 34322 | | -} |
| 34323 | | -#define SimulateDiskfullError(CODE) \ |
| 34324 | | - if( sqlite3_diskfull_pending ){ \ |
| 34325 | | - if( sqlite3_diskfull_pending == 1 ){ \ |
| 34326 | | - local_ioerr(); \ |
| 34327 | | - sqlite3_diskfull = 1; \ |
| 34328 | | - sqlite3_io_error_hit = 1; \ |
| 34329 | | - CODE; \ |
| 34330 | | - }else{ \ |
| 34331 | | - sqlite3_diskfull_pending--; \ |
| 34332 | | - } \ |
| 34333 | | - } |
| 34334 | | -#else |
| 34335 | | -#define SimulateIOErrorBenign(X) |
| 34336 | | -#define SimulateIOError(A) |
| 34337 | | -#define SimulateDiskfullError(A) |
| 34338 | | -#endif /* defined(SQLITE_TEST) */ |
| 34339 | | - |
| 34340 | | -/* |
| 34341 | | -** When testing, keep a count of the number of open files. |
| 34342 | | -*/ |
| 34343 | | -#if defined(SQLITE_TEST) |
| 34344 | | -SQLITE_API extern int sqlite3_open_file_count; |
| 34345 | | -#define OpenCounter(X) sqlite3_open_file_count+=(X) |
| 34346 | | -#else |
| 34347 | | -#define OpenCounter(X) |
| 34348 | | -#endif /* defined(SQLITE_TEST) */ |
| 34349 | | - |
| 34350 | | -#endif /* !defined(_OS_COMMON_H_) */ |
| 34351 | | - |
| 34352 | | -/************** End of os_common.h *******************************************/ |
| 34353 | | -/************** Continuing where we left off in os_unix.c ********************/ |
| 34345 | +/* #include "os_common.h" */ |
| 34354 | 34346 | |
| 34355 | 34347 | /* |
| 34356 | 34348 | ** Define various macros that are missing from some systems. |
| 34357 | 34349 | */ |
| 34358 | 34350 | #ifndef O_LARGEFILE |
| | @@ -40236,10 +40228,12 @@ |
| 40236 | 40228 | if( fd<0 ){ |
| 40237 | 40229 | if( isNewJrnl && errno==EACCES && osAccess(zName, F_OK) ){ |
| 40238 | 40230 | /* If unable to create a journal because the directory is not |
| 40239 | 40231 | ** writable, change the error code to indicate that. */ |
| 40240 | 40232 | rc = SQLITE_READONLY_DIRECTORY; |
| 40233 | + }else if( errno==EEXIST ){ |
| 40234 | + rc = SQLITE_CANTOPEN_EXISTS; |
| 40241 | 40235 | }else if( errno!=EISDIR && isReadWrite ){ |
| 40242 | 40236 | /* Failed to open the file for read/write access. Try read-only. */ |
| 40243 | 40237 | flags &= ~(SQLITE_OPEN_READWRITE|SQLITE_OPEN_CREATE); |
| 40244 | 40238 | openFlags &= ~(O_RDWR|O_CREAT); |
| 40245 | 40239 | flags |= SQLITE_OPEN_READONLY; |
| | @@ -42119,10 +42113,11 @@ |
| 42119 | 42113 | for(i=0; i<(sizeof(aVfs)/sizeof(sqlite3_vfs)); i++){ |
| 42120 | 42114 | sqlite3_vfs_register(&aVfs[i], i==0); |
| 42121 | 42115 | } |
| 42122 | 42116 | unixBigLock = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_VFS1); |
| 42123 | 42117 | |
| 42118 | +#ifndef SQLITE_OMIT_WAL |
| 42124 | 42119 | /* Validate lock assumptions */ |
| 42125 | 42120 | assert( SQLITE_SHM_NLOCK==8 ); /* Number of available locks */ |
| 42126 | 42121 | assert( UNIX_SHM_BASE==120 ); /* Start of locking area */ |
| 42127 | 42122 | /* Locks: |
| 42128 | 42123 | ** WRITE UNIX_SHM_BASE 120 |
| | @@ -42134,10 +42129,12 @@ |
| 42134 | 42129 | ** READ-3 UNIX_SHM_BASE+6 126 |
| 42135 | 42130 | ** READ-4 UNIX_SHM_BASE+7 127 |
| 42136 | 42131 | ** DMS UNIX_SHM_BASE+8 128 |
| 42137 | 42132 | */ |
| 42138 | 42133 | assert( UNIX_SHM_DMS==128 ); /* Byte offset of the deadman-switch */ |
| 42134 | +#endif |
| 42135 | + |
| 42139 | 42136 | return SQLITE_OK; |
| 42140 | 42137 | } |
| 42141 | 42138 | |
| 42142 | 42139 | /* |
| 42143 | 42140 | ** Shutdown the operating system interface. |
| | @@ -42173,209 +42170,11 @@ |
| 42173 | 42170 | #if SQLITE_OS_WIN /* This file is used for Windows only */ |
| 42174 | 42171 | |
| 42175 | 42172 | /* |
| 42176 | 42173 | ** Include code that is common to all os_*.c files |
| 42177 | 42174 | */ |
| 42178 | | -/************** Include os_common.h in the middle of os_win.c ****************/ |
| 42179 | | -/************** Begin file os_common.h ***************************************/ |
| 42180 | | -/* |
| 42181 | | -** 2004 May 22 |
| 42182 | | -** |
| 42183 | | -** The author disclaims copyright to this source code. In place of |
| 42184 | | -** a legal notice, here is a blessing: |
| 42185 | | -** |
| 42186 | | -** May you do good and not evil. |
| 42187 | | -** May you find forgiveness for yourself and forgive others. |
| 42188 | | -** May you share freely, never taking more than you give. |
| 42189 | | -** |
| 42190 | | -****************************************************************************** |
| 42191 | | -** |
| 42192 | | -** This file contains macros and a little bit of code that is common to |
| 42193 | | -** all of the platform-specific files (os_*.c) and is #included into those |
| 42194 | | -** files. |
| 42195 | | -** |
| 42196 | | -** This file should be #included by the os_*.c files only. It is not a |
| 42197 | | -** general purpose header file. |
| 42198 | | -*/ |
| 42199 | | -#ifndef _OS_COMMON_H_ |
| 42200 | | -#define _OS_COMMON_H_ |
| 42201 | | - |
| 42202 | | -/* |
| 42203 | | -** At least two bugs have slipped in because we changed the MEMORY_DEBUG |
| 42204 | | -** macro to SQLITE_DEBUG and some older makefiles have not yet made the |
| 42205 | | -** switch. The following code should catch this problem at compile-time. |
| 42206 | | -*/ |
| 42207 | | -#ifdef MEMORY_DEBUG |
| 42208 | | -# error "The MEMORY_DEBUG macro is obsolete. Use SQLITE_DEBUG instead." |
| 42209 | | -#endif |
| 42210 | | - |
| 42211 | | -/* |
| 42212 | | -** Macros for performance tracing. Normally turned off. Only works |
| 42213 | | -** on i486 hardware. |
| 42214 | | -*/ |
| 42215 | | -#ifdef SQLITE_PERFORMANCE_TRACE |
| 42216 | | - |
| 42217 | | -/* |
| 42218 | | -** hwtime.h contains inline assembler code for implementing |
| 42219 | | -** high-performance timing routines. |
| 42220 | | -*/ |
| 42221 | | -/************** Include hwtime.h in the middle of os_common.h ****************/ |
| 42222 | | -/************** Begin file hwtime.h ******************************************/ |
| 42223 | | -/* |
| 42224 | | -** 2008 May 27 |
| 42225 | | -** |
| 42226 | | -** The author disclaims copyright to this source code. In place of |
| 42227 | | -** a legal notice, here is a blessing: |
| 42228 | | -** |
| 42229 | | -** May you do good and not evil. |
| 42230 | | -** May you find forgiveness for yourself and forgive others. |
| 42231 | | -** May you share freely, never taking more than you give. |
| 42232 | | -** |
| 42233 | | -****************************************************************************** |
| 42234 | | -** |
| 42235 | | -** This file contains inline asm code for retrieving "high-performance" |
| 42236 | | -** counters for x86 and x86_64 class CPUs. |
| 42237 | | -*/ |
| 42238 | | -#ifndef SQLITE_HWTIME_H |
| 42239 | | -#define SQLITE_HWTIME_H |
| 42240 | | - |
| 42241 | | -/* |
| 42242 | | -** The following routine only works on pentium-class (or newer) processors. |
| 42243 | | -** It uses the RDTSC opcode to read the cycle count value out of the |
| 42244 | | -** processor and returns that value. This can be used for high-res |
| 42245 | | -** profiling. |
| 42246 | | -*/ |
| 42247 | | -#if !defined(__STRICT_ANSI__) && \ |
| 42248 | | - (defined(__GNUC__) || defined(_MSC_VER)) && \ |
| 42249 | | - (defined(i386) || defined(__i386__) || defined(_M_IX86)) |
| 42250 | | - |
| 42251 | | - #if defined(__GNUC__) |
| 42252 | | - |
| 42253 | | - __inline__ sqlite_uint64 sqlite3Hwtime(void){ |
| 42254 | | - unsigned int lo, hi; |
| 42255 | | - __asm__ __volatile__ ("rdtsc" : "=a" (lo), "=d" (hi)); |
| 42256 | | - return (sqlite_uint64)hi << 32 | lo; |
| 42257 | | - } |
| 42258 | | - |
| 42259 | | - #elif defined(_MSC_VER) |
| 42260 | | - |
| 42261 | | - __declspec(naked) __inline sqlite_uint64 __cdecl sqlite3Hwtime(void){ |
| 42262 | | - __asm { |
| 42263 | | - rdtsc |
| 42264 | | - ret ; return value at EDX:EAX |
| 42265 | | - } |
| 42266 | | - } |
| 42267 | | - |
| 42268 | | - #endif |
| 42269 | | - |
| 42270 | | -#elif !defined(__STRICT_ANSI__) && (defined(__GNUC__) && defined(__x86_64__)) |
| 42271 | | - |
| 42272 | | - __inline__ sqlite_uint64 sqlite3Hwtime(void){ |
| 42273 | | - unsigned long val; |
| 42274 | | - __asm__ __volatile__ ("rdtsc" : "=A" (val)); |
| 42275 | | - return val; |
| 42276 | | - } |
| 42277 | | - |
| 42278 | | -#elif !defined(__STRICT_ANSI__) && (defined(__GNUC__) && defined(__ppc__)) |
| 42279 | | - |
| 42280 | | - __inline__ sqlite_uint64 sqlite3Hwtime(void){ |
| 42281 | | - unsigned long long retval; |
| 42282 | | - unsigned long junk; |
| 42283 | | - __asm__ __volatile__ ("\n\ |
| 42284 | | - 1: mftbu %1\n\ |
| 42285 | | - mftb %L0\n\ |
| 42286 | | - mftbu %0\n\ |
| 42287 | | - cmpw %0,%1\n\ |
| 42288 | | - bne 1b" |
| 42289 | | - : "=r" (retval), "=r" (junk)); |
| 42290 | | - return retval; |
| 42291 | | - } |
| 42292 | | - |
| 42293 | | -#else |
| 42294 | | - |
| 42295 | | - /* |
| 42296 | | - ** asm() is needed for hardware timing support. Without asm(), |
| 42297 | | - ** disable the sqlite3Hwtime() routine. |
| 42298 | | - ** |
| 42299 | | - ** sqlite3Hwtime() is only used for some obscure debugging |
| 42300 | | - ** and analysis configurations, not in any deliverable, so this |
| 42301 | | - ** should not be a great loss. |
| 42302 | | - */ |
| 42303 | | -SQLITE_PRIVATE sqlite_uint64 sqlite3Hwtime(void){ return ((sqlite_uint64)0); } |
| 42304 | | - |
| 42305 | | -#endif |
| 42306 | | - |
| 42307 | | -#endif /* !defined(SQLITE_HWTIME_H) */ |
| 42308 | | - |
| 42309 | | -/************** End of hwtime.h **********************************************/ |
| 42310 | | -/************** Continuing where we left off in os_common.h ******************/ |
| 42311 | | - |
| 42312 | | -static sqlite_uint64 g_start; |
| 42313 | | -static sqlite_uint64 g_elapsed; |
| 42314 | | -#define TIMER_START g_start=sqlite3Hwtime() |
| 42315 | | -#define TIMER_END g_elapsed=sqlite3Hwtime()-g_start |
| 42316 | | -#define TIMER_ELAPSED g_elapsed |
| 42317 | | -#else |
| 42318 | | -#define TIMER_START |
| 42319 | | -#define TIMER_END |
| 42320 | | -#define TIMER_ELAPSED ((sqlite_uint64)0) |
| 42321 | | -#endif |
| 42322 | | - |
| 42323 | | -/* |
| 42324 | | -** If we compile with the SQLITE_TEST macro set, then the following block |
| 42325 | | -** of code will give us the ability to simulate a disk I/O error. This |
| 42326 | | -** is used for testing the I/O recovery logic. |
| 42327 | | -*/ |
| 42328 | | -#if defined(SQLITE_TEST) |
| 42329 | | -SQLITE_API extern int sqlite3_io_error_hit; |
| 42330 | | -SQLITE_API extern int sqlite3_io_error_hardhit; |
| 42331 | | -SQLITE_API extern int sqlite3_io_error_pending; |
| 42332 | | -SQLITE_API extern int sqlite3_io_error_persist; |
| 42333 | | -SQLITE_API extern int sqlite3_io_error_benign; |
| 42334 | | -SQLITE_API extern int sqlite3_diskfull_pending; |
| 42335 | | -SQLITE_API extern int sqlite3_diskfull; |
| 42336 | | -#define SimulateIOErrorBenign(X) sqlite3_io_error_benign=(X) |
| 42337 | | -#define SimulateIOError(CODE) \ |
| 42338 | | - if( (sqlite3_io_error_persist && sqlite3_io_error_hit) \ |
| 42339 | | - || sqlite3_io_error_pending-- == 1 ) \ |
| 42340 | | - { local_ioerr(); CODE; } |
| 42341 | | -static void local_ioerr(){ |
| 42342 | | - IOTRACE(("IOERR\n")); |
| 42343 | | - sqlite3_io_error_hit++; |
| 42344 | | - if( !sqlite3_io_error_benign ) sqlite3_io_error_hardhit++; |
| 42345 | | -} |
| 42346 | | -#define SimulateDiskfullError(CODE) \ |
| 42347 | | - if( sqlite3_diskfull_pending ){ \ |
| 42348 | | - if( sqlite3_diskfull_pending == 1 ){ \ |
| 42349 | | - local_ioerr(); \ |
| 42350 | | - sqlite3_diskfull = 1; \ |
| 42351 | | - sqlite3_io_error_hit = 1; \ |
| 42352 | | - CODE; \ |
| 42353 | | - }else{ \ |
| 42354 | | - sqlite3_diskfull_pending--; \ |
| 42355 | | - } \ |
| 42356 | | - } |
| 42357 | | -#else |
| 42358 | | -#define SimulateIOErrorBenign(X) |
| 42359 | | -#define SimulateIOError(A) |
| 42360 | | -#define SimulateDiskfullError(A) |
| 42361 | | -#endif /* defined(SQLITE_TEST) */ |
| 42362 | | - |
| 42363 | | -/* |
| 42364 | | -** When testing, keep a count of the number of open files. |
| 42365 | | -*/ |
| 42366 | | -#if defined(SQLITE_TEST) |
| 42367 | | -SQLITE_API extern int sqlite3_open_file_count; |
| 42368 | | -#define OpenCounter(X) sqlite3_open_file_count+=(X) |
| 42369 | | -#else |
| 42370 | | -#define OpenCounter(X) |
| 42371 | | -#endif /* defined(SQLITE_TEST) */ |
| 42372 | | - |
| 42373 | | -#endif /* !defined(_OS_COMMON_H_) */ |
| 42374 | | - |
| 42375 | | -/************** End of os_common.h *******************************************/ |
| 42376 | | -/************** Continuing where we left off in os_win.c *********************/ |
| 42175 | +/* #include "os_common.h" */ |
| 42377 | 42176 | |
| 42378 | 42177 | /* |
| 42379 | 42178 | ** Include the header file for the Windows VFS. |
| 42380 | 42179 | */ |
| 42381 | 42180 | /* #include "os_win.h" */ |
| | @@ -49319,11 +49118,12 @@ |
| 49319 | 49118 | #endif |
| 49320 | 49119 | |
| 49321 | 49120 | sqlite3_mutex_enter(db->mutex); |
| 49322 | 49121 | if( zSchema==0 ) zSchema = db->aDb[0].zDbSName; |
| 49323 | 49122 | iDb = sqlite3FindDbName(db, zSchema); |
| 49324 | | - if( iDb<0 ){ |
| 49123 | + testcase( iDb==1 ); |
| 49124 | + if( iDb<2 && iDb!=0 ){ |
| 49325 | 49125 | rc = SQLITE_ERROR; |
| 49326 | 49126 | goto end_deserialize; |
| 49327 | 49127 | } |
| 49328 | 49128 | zSql = sqlite3_mprintf("ATTACH x AS %Q", zSchema); |
| 49329 | 49129 | if( zSql==0 ){ |
| | @@ -49371,11 +49171,13 @@ |
| 49371 | 49171 | ** This routine is called when the extension is loaded. |
| 49372 | 49172 | ** Register the new VFS. |
| 49373 | 49173 | */ |
| 49374 | 49174 | SQLITE_PRIVATE int sqlite3MemdbInit(void){ |
| 49375 | 49175 | sqlite3_vfs *pLower = sqlite3_vfs_find(0); |
| 49376 | | - unsigned int sz = pLower->szOsFile; |
| 49176 | + unsigned int sz; |
| 49177 | + if( NEVER(pLower==0) ) return SQLITE_ERROR; |
| 49178 | + sz = pLower->szOsFile; |
| 49377 | 49179 | memdb_vfs.pAppData = pLower; |
| 49378 | 49180 | /* The following conditional can only be true when compiled for |
| 49379 | 49181 | ** Windows x86 and SQLITE_MAX_MMAP_SIZE=0. We always leave |
| 49380 | 49182 | ** it in, to be safe, but it is marked as NO_TEST since there |
| 49381 | 49183 | ** is no way to reach it under most builds. */ |
| | @@ -60504,11 +60306,14 @@ |
| 60504 | 60306 | ** Each index block except for the first contains information on |
| 60505 | 60307 | ** HASHTABLE_NPAGE frames. The first index block contains information on |
| 60506 | 60308 | ** HASHTABLE_NPAGE_ONE frames. The values of HASHTABLE_NPAGE_ONE and |
| 60507 | 60309 | ** HASHTABLE_NPAGE are selected so that together the wal-index header and |
| 60508 | 60310 | ** first index block are the same size as all other index blocks in the |
| 60509 | | -** wal-index. |
| 60311 | +** wal-index. The values are: |
| 60312 | +** |
| 60313 | +** HASHTABLE_NPAGE 4096 |
| 60314 | +** HASHTABLE_NPAGE_ONE 4062 |
| 60510 | 60315 | ** |
| 60511 | 60316 | ** Each index block contains two sections, a page-mapping that contains the |
| 60512 | 60317 | ** database page number associated with each wal frame, and a hash-table |
| 60513 | 60318 | ** that allows readers to query an index block for a specific page number. |
| 60514 | 60319 | ** The page-mapping is an array of HASHTABLE_NPAGE (or HASHTABLE_NPAGE_ONE |
| | @@ -60740,10 +60545,74 @@ |
| 60740 | 60545 | u32 nBackfillAttempted; /* WAL frames perhaps written, or maybe not */ |
| 60741 | 60546 | u32 notUsed0; /* Available for future enhancements */ |
| 60742 | 60547 | }; |
| 60743 | 60548 | #define READMARK_NOT_USED 0xffffffff |
| 60744 | 60549 | |
| 60550 | +/* |
| 60551 | +** This is a schematic view of the complete 136-byte header of the |
| 60552 | +** wal-index file (also known as the -shm file): |
| 60553 | +** |
| 60554 | +** +-----------------------------+ |
| 60555 | +** 0: | iVersion | \ |
| 60556 | +** +-----------------------------+ | |
| 60557 | +** 4: | (unused padding) | | |
| 60558 | +** +-----------------------------+ | |
| 60559 | +** 8: | iChange | | |
| 60560 | +** +-------+-------+-------------+ | |
| 60561 | +** 12: | bInit | bBig | szPage | | |
| 60562 | +** +-------+-------+-------------+ | |
| 60563 | +** 16: | mxFrame | | First copy of the |
| 60564 | +** +-----------------------------+ | WalIndexHdr object |
| 60565 | +** 20: | nPage | | |
| 60566 | +** +-----------------------------+ | |
| 60567 | +** 24: | aFrameCksum | | |
| 60568 | +** | | | |
| 60569 | +** +-----------------------------+ | |
| 60570 | +** 32: | aSalt | | |
| 60571 | +** | | | |
| 60572 | +** +-----------------------------+ | |
| 60573 | +** 40: | aCksum | | |
| 60574 | +** | | / |
| 60575 | +** +-----------------------------+ |
| 60576 | +** 48: | iVersion | \ |
| 60577 | +** +-----------------------------+ | |
| 60578 | +** 52: | (unused padding) | | |
| 60579 | +** +-----------------------------+ | |
| 60580 | +** 56: | iChange | | |
| 60581 | +** +-------+-------+-------------+ | |
| 60582 | +** 60: | bInit | bBig | szPage | | |
| 60583 | +** +-------+-------+-------------+ | Second copy of the |
| 60584 | +** 64: | mxFrame | | WalIndexHdr |
| 60585 | +** +-----------------------------+ | |
| 60586 | +** 68: | nPage | | |
| 60587 | +** +-----------------------------+ | |
| 60588 | +** 72: | aFrameCksum | | |
| 60589 | +** | | | |
| 60590 | +** +-----------------------------+ | |
| 60591 | +** 80: | aSalt | | |
| 60592 | +** | | | |
| 60593 | +** +-----------------------------+ | |
| 60594 | +** 88: | aCksum | | |
| 60595 | +** | | / |
| 60596 | +** +-----------------------------+ |
| 60597 | +** 96: | nBackfill | |
| 60598 | +** +-----------------------------+ |
| 60599 | +** 100: | 5 read marks | |
| 60600 | +** | | |
| 60601 | +** | | |
| 60602 | +** | | |
| 60603 | +** | | |
| 60604 | +** +-------+-------+------+------+ |
| 60605 | +** 120: | Write | Ckpt | Rcvr | Rd0 | \ |
| 60606 | +** +-------+-------+------+------+ ) 8 lock bytes |
| 60607 | +** | Read1 | Read2 | Rd3 | Rd4 | / |
| 60608 | +** +-------+-------+------+------+ |
| 60609 | +** 128: | nBackfillAttempted | |
| 60610 | +** +-----------------------------+ |
| 60611 | +** 132: | (unused padding) | |
| 60612 | +** +-----------------------------+ |
| 60613 | +*/ |
| 60745 | 60614 | |
| 60746 | 60615 | /* A block of WALINDEX_LOCK_RESERVED bytes beginning at |
| 60747 | 60616 | ** WALINDEX_LOCK_OFFSET is reserved for locks. Since some systems |
| 60748 | 60617 | ** only support mandatory file-locks, we do not read or write data |
| 60749 | 60618 | ** from the region of the file on which locks are applied. |
| | @@ -61752,19 +61621,48 @@ |
| 61752 | 61621 | Wal *pRet; /* Object to allocate and return */ |
| 61753 | 61622 | int flags; /* Flags passed to OsOpen() */ |
| 61754 | 61623 | |
| 61755 | 61624 | assert( zWalName && zWalName[0] ); |
| 61756 | 61625 | assert( pDbFd ); |
| 61626 | + |
| 61627 | + /* Verify the values of various constants. Any changes to the values |
| 61628 | + ** of these constants would result in an incompatible on-disk format |
| 61629 | + ** for the -shm file. Any change that causes one of these asserts to |
| 61630 | + ** fail is a backward compatibility problem, even if the change otherwise |
| 61631 | + ** works. |
| 61632 | + ** |
| 61633 | + ** This table also serves as a helpful cross-reference when trying to |
| 61634 | + ** interpret hex dumps of the -shm file. |
| 61635 | + */ |
| 61636 | + assert( 48 == sizeof(WalIndexHdr) ); |
| 61637 | + assert( 40 == sizeof(WalCkptInfo) ); |
| 61638 | + assert( 120 == WALINDEX_LOCK_OFFSET ); |
| 61639 | + assert( 136 == WALINDEX_HDR_SIZE ); |
| 61640 | + assert( 4096 == HASHTABLE_NPAGE ); |
| 61641 | + assert( 4062 == HASHTABLE_NPAGE_ONE ); |
| 61642 | + assert( 8192 == HASHTABLE_NSLOT ); |
| 61643 | + assert( 383 == HASHTABLE_HASH_1 ); |
| 61644 | + assert( 32768 == WALINDEX_PGSZ ); |
| 61645 | + assert( 8 == SQLITE_SHM_NLOCK ); |
| 61646 | + assert( 5 == WAL_NREADER ); |
| 61647 | + assert( 24 == WAL_FRAME_HDRSIZE ); |
| 61648 | + assert( 32 == WAL_HDRSIZE ); |
| 61649 | + assert( 120 == WALINDEX_LOCK_OFFSET + WAL_WRITE_LOCK ); |
| 61650 | + assert( 121 == WALINDEX_LOCK_OFFSET + WAL_CKPT_LOCK ); |
| 61651 | + assert( 122 == WALINDEX_LOCK_OFFSET + WAL_RECOVER_LOCK ); |
| 61652 | + assert( 123 == WALINDEX_LOCK_OFFSET + WAL_READ_LOCK(0) ); |
| 61653 | + assert( 124 == WALINDEX_LOCK_OFFSET + WAL_READ_LOCK(1) ); |
| 61654 | + assert( 125 == WALINDEX_LOCK_OFFSET + WAL_READ_LOCK(2) ); |
| 61655 | + assert( 126 == WALINDEX_LOCK_OFFSET + WAL_READ_LOCK(3) ); |
| 61656 | + assert( 127 == WALINDEX_LOCK_OFFSET + WAL_READ_LOCK(4) ); |
| 61757 | 61657 | |
| 61758 | 61658 | /* In the amalgamation, the os_unix.c and os_win.c source files come before |
| 61759 | 61659 | ** this source file. Verify that the #defines of the locking byte offsets |
| 61760 | 61660 | ** in os_unix.c and os_win.c agree with the WALINDEX_LOCK_OFFSET value. |
| 61761 | 61661 | ** For that matter, if the lock offset ever changes from its initial design |
| 61762 | 61662 | ** value of 120, we need to know that so there is an assert() to check it. |
| 61763 | 61663 | */ |
| 61764 | | - assert( 120==WALINDEX_LOCK_OFFSET ); |
| 61765 | | - assert( 136==WALINDEX_HDR_SIZE ); |
| 61766 | 61664 | #ifdef WIN_SHM_BASE |
| 61767 | 61665 | assert( WIN_SHM_BASE==WALINDEX_LOCK_OFFSET ); |
| 61768 | 61666 | #endif |
| 61769 | 61667 | #ifdef UNIX_SHM_BASE |
| 61770 | 61668 | assert( UNIX_SHM_BASE==WALINDEX_LOCK_OFFSET ); |
| | @@ -66267,19 +66165,17 @@ |
| 66267 | 66165 | pIdxKey = sqlite3VdbeAllocUnpackedRecord(pKeyInfo); |
| 66268 | 66166 | if( pIdxKey==0 ) return SQLITE_NOMEM_BKPT; |
| 66269 | 66167 | sqlite3VdbeRecordUnpack(pKeyInfo, (int)nKey, pKey, pIdxKey); |
| 66270 | 66168 | if( pIdxKey->nField==0 || pIdxKey->nField>pKeyInfo->nAllField ){ |
| 66271 | 66169 | rc = SQLITE_CORRUPT_BKPT; |
| 66272 | | - goto moveto_done; |
| 66170 | + }else{ |
| 66171 | + rc = sqlite3BtreeIndexMoveto(pCur, pIdxKey, pRes); |
| 66273 | 66172 | } |
| 66173 | + sqlite3DbFree(pCur->pKeyInfo->db, pIdxKey); |
| 66274 | 66174 | }else{ |
| 66275 | 66175 | pIdxKey = 0; |
| 66276 | | - } |
| 66277 | | - rc = sqlite3BtreeMovetoUnpacked(pCur, pIdxKey, nKey, bias, pRes); |
| 66278 | | -moveto_done: |
| 66279 | | - if( pIdxKey ){ |
| 66280 | | - sqlite3DbFree(pCur->pKeyInfo->db, pIdxKey); |
| 66176 | + rc = sqlite3BtreeTableMoveto(pCur, nKey, bias, pRes); |
| 66281 | 66177 | } |
| 66282 | 66178 | return rc; |
| 66283 | 66179 | } |
| 66284 | 66180 | |
| 66285 | 66181 | /* |
| | @@ -67124,11 +67020,11 @@ |
| 67124 | 67020 | u8 *pSpace = pageFindSlot(pPage, nByte, &rc); |
| 67125 | 67021 | if( pSpace ){ |
| 67126 | 67022 | int g2; |
| 67127 | 67023 | assert( pSpace+nByte<=data+pPage->pBt->usableSize ); |
| 67128 | 67024 | *pIdx = g2 = (int)(pSpace-data); |
| 67129 | | - if( NEVER(g2<=gap) ){ |
| 67025 | + if( g2<=gap ){ |
| 67130 | 67026 | return SQLITE_CORRUPT_PAGE(pPage); |
| 67131 | 67027 | }else{ |
| 67132 | 67028 | return SQLITE_OK; |
| 67133 | 67029 | } |
| 67134 | 67030 | }else if( rc ){ |
| | @@ -70861,16 +70757,12 @@ |
| 70861 | 70757 | rc = SQLITE_OK; |
| 70862 | 70758 | } |
| 70863 | 70759 | return rc; |
| 70864 | 70760 | } |
| 70865 | 70761 | |
| 70866 | | -/* Move the cursor so that it points to an entry near the key |
| 70867 | | -** specified by pIdxKey or intKey. Return a success code. |
| 70868 | | -** |
| 70869 | | -** For INTKEY tables, the intKey parameter is used. pIdxKey |
| 70870 | | -** must be NULL. For index tables, pIdxKey is used and intKey |
| 70871 | | -** is ignored. |
| 70762 | +/* Move the cursor so that it points to an entry in a table (a.k.a INTKEY) |
| 70763 | +** table near the key intKey. Return a success code. |
| 70872 | 70764 | ** |
| 70873 | 70765 | ** If an exact match is not found, then the cursor is always |
| 70874 | 70766 | ** left pointing at a leaf page which would hold the entry if it |
| 70875 | 70767 | ** were present. The cursor might point to an entry that comes |
| 70876 | 70768 | ** before or after the key. |
| | @@ -70879,43 +70771,36 @@ |
| 70879 | 70771 | ** comparing the key with the entry to which the cursor is |
| 70880 | 70772 | ** pointing. The meaning of the integer written into |
| 70881 | 70773 | ** *pRes is as follows: |
| 70882 | 70774 | ** |
| 70883 | 70775 | ** *pRes<0 The cursor is left pointing at an entry that |
| 70884 | | -** is smaller than intKey/pIdxKey or if the table is empty |
| 70776 | +** is smaller than intKey or if the table is empty |
| 70885 | 70777 | ** and the cursor is therefore left point to nothing. |
| 70886 | 70778 | ** |
| 70887 | 70779 | ** *pRes==0 The cursor is left pointing at an entry that |
| 70888 | | -** exactly matches intKey/pIdxKey. |
| 70780 | +** exactly matches intKey. |
| 70889 | 70781 | ** |
| 70890 | 70782 | ** *pRes>0 The cursor is left pointing at an entry that |
| 70891 | | -** is larger than intKey/pIdxKey. |
| 70892 | | -** |
| 70893 | | -** For index tables, the pIdxKey->eqSeen field is set to 1 if there |
| 70894 | | -** exists an entry in the table that exactly matches pIdxKey. |
| 70783 | +** is larger than intKey. |
| 70895 | 70784 | */ |
| 70896 | | -SQLITE_PRIVATE int sqlite3BtreeMovetoUnpacked( |
| 70785 | +SQLITE_PRIVATE int sqlite3BtreeTableMoveto( |
| 70897 | 70786 | BtCursor *pCur, /* The cursor to be moved */ |
| 70898 | | - UnpackedRecord *pIdxKey, /* Unpacked index key */ |
| 70899 | 70787 | i64 intKey, /* The table key */ |
| 70900 | 70788 | int biasRight, /* If true, bias the search to the high end */ |
| 70901 | 70789 | int *pRes /* Write search results here */ |
| 70902 | 70790 | ){ |
| 70903 | 70791 | int rc; |
| 70904 | | - RecordCompare xRecordCompare; |
| 70905 | 70792 | |
| 70906 | 70793 | assert( cursorOwnsBtShared(pCur) ); |
| 70907 | 70794 | assert( sqlite3_mutex_held(pCur->pBtree->db->mutex) ); |
| 70908 | 70795 | assert( pRes ); |
| 70909 | | - assert( (pIdxKey==0)==(pCur->pKeyInfo==0) ); |
| 70910 | | - assert( pCur->eState!=CURSOR_VALID || (pIdxKey==0)==(pCur->curIntKey!=0) ); |
| 70796 | + assert( pCur->pKeyInfo==0 ); |
| 70797 | + assert( pCur->eState!=CURSOR_VALID || pCur->curIntKey!=0 ); |
| 70911 | 70798 | |
| 70912 | 70799 | /* If the cursor is already positioned at the point we are trying |
| 70913 | 70800 | ** to move to, then just return without doing any work */ |
| 70914 | | - if( pIdxKey==0 |
| 70915 | | - && pCur->eState==CURSOR_VALID && (pCur->curFlags & BTCF_ValidNKey)!=0 |
| 70916 | | - ){ |
| 70801 | + if( pCur->eState==CURSOR_VALID && (pCur->curFlags & BTCF_ValidNKey)!=0 ){ |
| 70917 | 70802 | if( pCur->info.nKey==intKey ){ |
| 70918 | 70803 | *pRes = 0; |
| 70919 | 70804 | return SQLITE_OK; |
| 70920 | 70805 | } |
| 70921 | 70806 | if( pCur->info.nKey<intKey ){ |
| | @@ -70946,20 +70831,153 @@ |
| 70946 | 70831 | |
| 70947 | 70832 | #ifdef SQLITE_DEBUG |
| 70948 | 70833 | pCur->pBtree->nSeek++; /* Performance measurement during testing */ |
| 70949 | 70834 | #endif |
| 70950 | 70835 | |
| 70951 | | - if( pIdxKey ){ |
| 70952 | | - xRecordCompare = sqlite3VdbeFindCompare(pIdxKey); |
| 70953 | | - pIdxKey->errCode = 0; |
| 70954 | | - assert( pIdxKey->default_rc==1 |
| 70955 | | - || pIdxKey->default_rc==0 |
| 70956 | | - || pIdxKey->default_rc==-1 |
| 70957 | | - ); |
| 70958 | | - }else{ |
| 70959 | | - xRecordCompare = 0; /* All keys are integers */ |
| 70960 | | - } |
| 70836 | + rc = moveToRoot(pCur); |
| 70837 | + if( rc ){ |
| 70838 | + if( rc==SQLITE_EMPTY ){ |
| 70839 | + assert( pCur->pgnoRoot==0 || pCur->pPage->nCell==0 ); |
| 70840 | + *pRes = -1; |
| 70841 | + return SQLITE_OK; |
| 70842 | + } |
| 70843 | + return rc; |
| 70844 | + } |
| 70845 | + assert( pCur->pPage ); |
| 70846 | + assert( pCur->pPage->isInit ); |
| 70847 | + assert( pCur->eState==CURSOR_VALID ); |
| 70848 | + assert( pCur->pPage->nCell > 0 ); |
| 70849 | + assert( pCur->iPage==0 || pCur->apPage[0]->intKey==pCur->curIntKey ); |
| 70850 | + assert( pCur->curIntKey ); |
| 70851 | + |
| 70852 | + for(;;){ |
| 70853 | + int lwr, upr, idx, c; |
| 70854 | + Pgno chldPg; |
| 70855 | + MemPage *pPage = pCur->pPage; |
| 70856 | + u8 *pCell; /* Pointer to current cell in pPage */ |
| 70857 | + |
| 70858 | + /* pPage->nCell must be greater than zero. If this is the root-page |
| 70859 | + ** the cursor would have been INVALID above and this for(;;) loop |
| 70860 | + ** not run. If this is not the root-page, then the moveToChild() routine |
| 70861 | + ** would have already detected db corruption. Similarly, pPage must |
| 70862 | + ** be the right kind (index or table) of b-tree page. Otherwise |
| 70863 | + ** a moveToChild() or moveToRoot() call would have detected corruption. */ |
| 70864 | + assert( pPage->nCell>0 ); |
| 70865 | + assert( pPage->intKey ); |
| 70866 | + lwr = 0; |
| 70867 | + upr = pPage->nCell-1; |
| 70868 | + assert( biasRight==0 || biasRight==1 ); |
| 70869 | + idx = upr>>(1-biasRight); /* idx = biasRight ? upr : (lwr+upr)/2; */ |
| 70870 | + pCur->ix = (u16)idx; |
| 70871 | + for(;;){ |
| 70872 | + i64 nCellKey; |
| 70873 | + pCell = findCellPastPtr(pPage, idx); |
| 70874 | + if( pPage->intKeyLeaf ){ |
| 70875 | + while( 0x80 <= *(pCell++) ){ |
| 70876 | + if( pCell>=pPage->aDataEnd ){ |
| 70877 | + return SQLITE_CORRUPT_PAGE(pPage); |
| 70878 | + } |
| 70879 | + } |
| 70880 | + } |
| 70881 | + getVarint(pCell, (u64*)&nCellKey); |
| 70882 | + if( nCellKey<intKey ){ |
| 70883 | + lwr = idx+1; |
| 70884 | + if( lwr>upr ){ c = -1; break; } |
| 70885 | + }else if( nCellKey>intKey ){ |
| 70886 | + upr = idx-1; |
| 70887 | + if( lwr>upr ){ c = +1; break; } |
| 70888 | + }else{ |
| 70889 | + assert( nCellKey==intKey ); |
| 70890 | + pCur->ix = (u16)idx; |
| 70891 | + if( !pPage->leaf ){ |
| 70892 | + lwr = idx; |
| 70893 | + goto moveto_table_next_layer; |
| 70894 | + }else{ |
| 70895 | + pCur->curFlags |= BTCF_ValidNKey; |
| 70896 | + pCur->info.nKey = nCellKey; |
| 70897 | + pCur->info.nSize = 0; |
| 70898 | + *pRes = 0; |
| 70899 | + return SQLITE_OK; |
| 70900 | + } |
| 70901 | + } |
| 70902 | + assert( lwr+upr>=0 ); |
| 70903 | + idx = (lwr+upr)>>1; /* idx = (lwr+upr)/2; */ |
| 70904 | + } |
| 70905 | + assert( lwr==upr+1 || !pPage->leaf ); |
| 70906 | + assert( pPage->isInit ); |
| 70907 | + if( pPage->leaf ){ |
| 70908 | + assert( pCur->ix<pCur->pPage->nCell ); |
| 70909 | + pCur->ix = (u16)idx; |
| 70910 | + *pRes = c; |
| 70911 | + rc = SQLITE_OK; |
| 70912 | + goto moveto_table_finish; |
| 70913 | + } |
| 70914 | +moveto_table_next_layer: |
| 70915 | + if( lwr>=pPage->nCell ){ |
| 70916 | + chldPg = get4byte(&pPage->aData[pPage->hdrOffset+8]); |
| 70917 | + }else{ |
| 70918 | + chldPg = get4byte(findCell(pPage, lwr)); |
| 70919 | + } |
| 70920 | + pCur->ix = (u16)lwr; |
| 70921 | + rc = moveToChild(pCur, chldPg); |
| 70922 | + if( rc ) break; |
| 70923 | + } |
| 70924 | +moveto_table_finish: |
| 70925 | + pCur->info.nSize = 0; |
| 70926 | + assert( (pCur->curFlags & BTCF_ValidOvfl)==0 ); |
| 70927 | + return rc; |
| 70928 | +} |
| 70929 | + |
| 70930 | +/* Move the cursor so that it points to an entry in an index table |
| 70931 | +** near the key pIdxKey. Return a success code. |
| 70932 | +** |
| 70933 | +** If an exact match is not found, then the cursor is always |
| 70934 | +** left pointing at a leaf page which would hold the entry if it |
| 70935 | +** were present. The cursor might point to an entry that comes |
| 70936 | +** before or after the key. |
| 70937 | +** |
| 70938 | +** An integer is written into *pRes which is the result of |
| 70939 | +** comparing the key with the entry to which the cursor is |
| 70940 | +** pointing. The meaning of the integer written into |
| 70941 | +** *pRes is as follows: |
| 70942 | +** |
| 70943 | +** *pRes<0 The cursor is left pointing at an entry that |
| 70944 | +** is smaller than pIdxKey or if the table is empty |
| 70945 | +** and the cursor is therefore left point to nothing. |
| 70946 | +** |
| 70947 | +** *pRes==0 The cursor is left pointing at an entry that |
| 70948 | +** exactly matches pIdxKey. |
| 70949 | +** |
| 70950 | +** *pRes>0 The cursor is left pointing at an entry that |
| 70951 | +** is larger than pIdxKey. |
| 70952 | +** |
| 70953 | +** The pIdxKey->eqSeen field is set to 1 if there |
| 70954 | +** exists an entry in the table that exactly matches pIdxKey. |
| 70955 | +*/ |
| 70956 | +SQLITE_PRIVATE int sqlite3BtreeIndexMoveto( |
| 70957 | + BtCursor *pCur, /* The cursor to be moved */ |
| 70958 | + UnpackedRecord *pIdxKey, /* Unpacked index key */ |
| 70959 | + int *pRes /* Write search results here */ |
| 70960 | +){ |
| 70961 | + int rc; |
| 70962 | + RecordCompare xRecordCompare; |
| 70963 | + |
| 70964 | + assert( cursorOwnsBtShared(pCur) ); |
| 70965 | + assert( sqlite3_mutex_held(pCur->pBtree->db->mutex) ); |
| 70966 | + assert( pRes ); |
| 70967 | + assert( pCur->pKeyInfo!=0 ); |
| 70968 | + |
| 70969 | +#ifdef SQLITE_DEBUG |
| 70970 | + pCur->pBtree->nSeek++; /* Performance measurement during testing */ |
| 70971 | +#endif |
| 70972 | + |
| 70973 | + xRecordCompare = sqlite3VdbeFindCompare(pIdxKey); |
| 70974 | + pIdxKey->errCode = 0; |
| 70975 | + assert( pIdxKey->default_rc==1 |
| 70976 | + || pIdxKey->default_rc==0 |
| 70977 | + || pIdxKey->default_rc==-1 |
| 70978 | + ); |
| 70961 | 70979 | |
| 70962 | 70980 | rc = moveToRoot(pCur); |
| 70963 | 70981 | if( rc ){ |
| 70964 | 70982 | if( rc==SQLITE_EMPTY ){ |
| 70965 | 70983 | assert( pCur->pgnoRoot==0 || pCur->pPage->nCell==0 ); |
| | @@ -70988,155 +71006,116 @@ |
| 70988 | 71006 | ** a moveToChild() or moveToRoot() call would have detected corruption. */ |
| 70989 | 71007 | assert( pPage->nCell>0 ); |
| 70990 | 71008 | assert( pPage->intKey==(pIdxKey==0) ); |
| 70991 | 71009 | lwr = 0; |
| 70992 | 71010 | upr = pPage->nCell-1; |
| 70993 | | - assert( biasRight==0 || biasRight==1 ); |
| 70994 | | - idx = upr>>(1-biasRight); /* idx = biasRight ? upr : (lwr+upr)/2; */ |
| 70995 | | - pCur->ix = (u16)idx; |
| 70996 | | - if( xRecordCompare==0 ){ |
| 70997 | | - for(;;){ |
| 70998 | | - i64 nCellKey; |
| 70999 | | - pCell = findCellPastPtr(pPage, idx); |
| 71000 | | - if( pPage->intKeyLeaf ){ |
| 71001 | | - while( 0x80 <= *(pCell++) ){ |
| 71002 | | - if( pCell>=pPage->aDataEnd ){ |
| 71003 | | - return SQLITE_CORRUPT_PAGE(pPage); |
| 71004 | | - } |
| 71005 | | - } |
| 71006 | | - } |
| 71007 | | - getVarint(pCell, (u64*)&nCellKey); |
| 71008 | | - if( nCellKey<intKey ){ |
| 71009 | | - lwr = idx+1; |
| 71010 | | - if( lwr>upr ){ c = -1; break; } |
| 71011 | | - }else if( nCellKey>intKey ){ |
| 71012 | | - upr = idx-1; |
| 71013 | | - if( lwr>upr ){ c = +1; break; } |
| 71014 | | - }else{ |
| 71015 | | - assert( nCellKey==intKey ); |
| 71016 | | - pCur->ix = (u16)idx; |
| 71017 | | - if( !pPage->leaf ){ |
| 71018 | | - lwr = idx; |
| 71019 | | - goto moveto_next_layer; |
| 71020 | | - }else{ |
| 71021 | | - pCur->curFlags |= BTCF_ValidNKey; |
| 71022 | | - pCur->info.nKey = nCellKey; |
| 71023 | | - pCur->info.nSize = 0; |
| 71024 | | - *pRes = 0; |
| 71025 | | - return SQLITE_OK; |
| 71026 | | - } |
| 71027 | | - } |
| 71028 | | - assert( lwr+upr>=0 ); |
| 71029 | | - idx = (lwr+upr)>>1; /* idx = (lwr+upr)/2; */ |
| 71030 | | - } |
| 71031 | | - }else{ |
| 71032 | | - for(;;){ |
| 71033 | | - int nCell; /* Size of the pCell cell in bytes */ |
| 71034 | | - pCell = findCellPastPtr(pPage, idx); |
| 71035 | | - |
| 71036 | | - /* The maximum supported page-size is 65536 bytes. This means that |
| 71037 | | - ** the maximum number of record bytes stored on an index B-Tree |
| 71038 | | - ** page is less than 16384 bytes and may be stored as a 2-byte |
| 71039 | | - ** varint. This information is used to attempt to avoid parsing |
| 71040 | | - ** the entire cell by checking for the cases where the record is |
| 71041 | | - ** stored entirely within the b-tree page by inspecting the first |
| 71042 | | - ** 2 bytes of the cell. |
| 71043 | | - */ |
| 71044 | | - nCell = pCell[0]; |
| 71045 | | - if( nCell<=pPage->max1bytePayload ){ |
| 71046 | | - /* This branch runs if the record-size field of the cell is a |
| 71047 | | - ** single byte varint and the record fits entirely on the main |
| 71048 | | - ** b-tree page. */ |
| 71049 | | - testcase( pCell+nCell+1==pPage->aDataEnd ); |
| 71050 | | - c = xRecordCompare(nCell, (void*)&pCell[1], pIdxKey); |
| 71051 | | - }else if( !(pCell[1] & 0x80) |
| 71052 | | - && (nCell = ((nCell&0x7f)<<7) + pCell[1])<=pPage->maxLocal |
| 71053 | | - ){ |
| 71054 | | - /* The record-size field is a 2 byte varint and the record |
| 71055 | | - ** fits entirely on the main b-tree page. */ |
| 71056 | | - testcase( pCell+nCell+2==pPage->aDataEnd ); |
| 71057 | | - c = xRecordCompare(nCell, (void*)&pCell[2], pIdxKey); |
| 71058 | | - }else{ |
| 71059 | | - /* The record flows over onto one or more overflow pages. In |
| 71060 | | - ** this case the whole cell needs to be parsed, a buffer allocated |
| 71061 | | - ** and accessPayload() used to retrieve the record into the |
| 71062 | | - ** buffer before VdbeRecordCompare() can be called. |
| 71063 | | - ** |
| 71064 | | - ** If the record is corrupt, the xRecordCompare routine may read |
| 71065 | | - ** up to two varints past the end of the buffer. An extra 18 |
| 71066 | | - ** bytes of padding is allocated at the end of the buffer in |
| 71067 | | - ** case this happens. */ |
| 71068 | | - void *pCellKey; |
| 71069 | | - u8 * const pCellBody = pCell - pPage->childPtrSize; |
| 71070 | | - const int nOverrun = 18; /* Size of the overrun padding */ |
| 71071 | | - pPage->xParseCell(pPage, pCellBody, &pCur->info); |
| 71072 | | - nCell = (int)pCur->info.nKey; |
| 71073 | | - testcase( nCell<0 ); /* True if key size is 2^32 or more */ |
| 71074 | | - testcase( nCell==0 ); /* Invalid key size: 0x80 0x80 0x00 */ |
| 71075 | | - testcase( nCell==1 ); /* Invalid key size: 0x80 0x80 0x01 */ |
| 71076 | | - testcase( nCell==2 ); /* Minimum legal index key size */ |
| 71077 | | - if( nCell<2 || nCell/pCur->pBt->usableSize>pCur->pBt->nPage ){ |
| 71078 | | - rc = SQLITE_CORRUPT_PAGE(pPage); |
| 71079 | | - goto moveto_finish; |
| 71080 | | - } |
| 71081 | | - pCellKey = sqlite3Malloc( nCell+nOverrun ); |
| 71082 | | - if( pCellKey==0 ){ |
| 71083 | | - rc = SQLITE_NOMEM_BKPT; |
| 71084 | | - goto moveto_finish; |
| 71085 | | - } |
| 71086 | | - pCur->ix = (u16)idx; |
| 71087 | | - rc = accessPayload(pCur, 0, nCell, (unsigned char*)pCellKey, 0); |
| 71088 | | - memset(((u8*)pCellKey)+nCell,0,nOverrun); /* Fix uninit warnings */ |
| 71089 | | - pCur->curFlags &= ~BTCF_ValidOvfl; |
| 71090 | | - if( rc ){ |
| 71091 | | - sqlite3_free(pCellKey); |
| 71092 | | - goto moveto_finish; |
| 71093 | | - } |
| 71094 | | - c = sqlite3VdbeRecordCompare(nCell, pCellKey, pIdxKey); |
| 71095 | | - sqlite3_free(pCellKey); |
| 71096 | | - } |
| 71097 | | - assert( |
| 71098 | | - (pIdxKey->errCode!=SQLITE_CORRUPT || c==0) |
| 71099 | | - && (pIdxKey->errCode!=SQLITE_NOMEM || pCur->pBtree->db->mallocFailed) |
| 71100 | | - ); |
| 71101 | | - if( c<0 ){ |
| 71102 | | - lwr = idx+1; |
| 71103 | | - }else if( c>0 ){ |
| 71104 | | - upr = idx-1; |
| 71105 | | - }else{ |
| 71106 | | - assert( c==0 ); |
| 71107 | | - *pRes = 0; |
| 71108 | | - rc = SQLITE_OK; |
| 71109 | | - pCur->ix = (u16)idx; |
| 71110 | | - if( pIdxKey->errCode ) rc = SQLITE_CORRUPT_BKPT; |
| 71111 | | - goto moveto_finish; |
| 71112 | | - } |
| 71113 | | - if( lwr>upr ) break; |
| 71114 | | - assert( lwr+upr>=0 ); |
| 71115 | | - idx = (lwr+upr)>>1; /* idx = (lwr+upr)/2 */ |
| 71116 | | - } |
| 71011 | + idx = upr>>1; /* idx = (lwr+upr)/2; */ |
| 71012 | + pCur->ix = (u16)idx; |
| 71013 | + for(;;){ |
| 71014 | + int nCell; /* Size of the pCell cell in bytes */ |
| 71015 | + pCell = findCellPastPtr(pPage, idx); |
| 71016 | + |
| 71017 | + /* The maximum supported page-size is 65536 bytes. This means that |
| 71018 | + ** the maximum number of record bytes stored on an index B-Tree |
| 71019 | + ** page is less than 16384 bytes and may be stored as a 2-byte |
| 71020 | + ** varint. This information is used to attempt to avoid parsing |
| 71021 | + ** the entire cell by checking for the cases where the record is |
| 71022 | + ** stored entirely within the b-tree page by inspecting the first |
| 71023 | + ** 2 bytes of the cell. |
| 71024 | + */ |
| 71025 | + nCell = pCell[0]; |
| 71026 | + if( nCell<=pPage->max1bytePayload ){ |
| 71027 | + /* This branch runs if the record-size field of the cell is a |
| 71028 | + ** single byte varint and the record fits entirely on the main |
| 71029 | + ** b-tree page. */ |
| 71030 | + testcase( pCell+nCell+1==pPage->aDataEnd ); |
| 71031 | + c = xRecordCompare(nCell, (void*)&pCell[1], pIdxKey); |
| 71032 | + }else if( !(pCell[1] & 0x80) |
| 71033 | + && (nCell = ((nCell&0x7f)<<7) + pCell[1])<=pPage->maxLocal |
| 71034 | + ){ |
| 71035 | + /* The record-size field is a 2 byte varint and the record |
| 71036 | + ** fits entirely on the main b-tree page. */ |
| 71037 | + testcase( pCell+nCell+2==pPage->aDataEnd ); |
| 71038 | + c = xRecordCompare(nCell, (void*)&pCell[2], pIdxKey); |
| 71039 | + }else{ |
| 71040 | + /* The record flows over onto one or more overflow pages. In |
| 71041 | + ** this case the whole cell needs to be parsed, a buffer allocated |
| 71042 | + ** and accessPayload() used to retrieve the record into the |
| 71043 | + ** buffer before VdbeRecordCompare() can be called. |
| 71044 | + ** |
| 71045 | + ** If the record is corrupt, the xRecordCompare routine may read |
| 71046 | + ** up to two varints past the end of the buffer. An extra 18 |
| 71047 | + ** bytes of padding is allocated at the end of the buffer in |
| 71048 | + ** case this happens. */ |
| 71049 | + void *pCellKey; |
| 71050 | + u8 * const pCellBody = pCell - pPage->childPtrSize; |
| 71051 | + const int nOverrun = 18; /* Size of the overrun padding */ |
| 71052 | + pPage->xParseCell(pPage, pCellBody, &pCur->info); |
| 71053 | + nCell = (int)pCur->info.nKey; |
| 71054 | + testcase( nCell<0 ); /* True if key size is 2^32 or more */ |
| 71055 | + testcase( nCell==0 ); /* Invalid key size: 0x80 0x80 0x00 */ |
| 71056 | + testcase( nCell==1 ); /* Invalid key size: 0x80 0x80 0x01 */ |
| 71057 | + testcase( nCell==2 ); /* Minimum legal index key size */ |
| 71058 | + if( nCell<2 || nCell/pCur->pBt->usableSize>pCur->pBt->nPage ){ |
| 71059 | + rc = SQLITE_CORRUPT_PAGE(pPage); |
| 71060 | + goto moveto_index_finish; |
| 71061 | + } |
| 71062 | + pCellKey = sqlite3Malloc( nCell+nOverrun ); |
| 71063 | + if( pCellKey==0 ){ |
| 71064 | + rc = SQLITE_NOMEM_BKPT; |
| 71065 | + goto moveto_index_finish; |
| 71066 | + } |
| 71067 | + pCur->ix = (u16)idx; |
| 71068 | + rc = accessPayload(pCur, 0, nCell, (unsigned char*)pCellKey, 0); |
| 71069 | + memset(((u8*)pCellKey)+nCell,0,nOverrun); /* Fix uninit warnings */ |
| 71070 | + pCur->curFlags &= ~BTCF_ValidOvfl; |
| 71071 | + if( rc ){ |
| 71072 | + sqlite3_free(pCellKey); |
| 71073 | + goto moveto_index_finish; |
| 71074 | + } |
| 71075 | + c = sqlite3VdbeRecordCompare(nCell, pCellKey, pIdxKey); |
| 71076 | + sqlite3_free(pCellKey); |
| 71077 | + } |
| 71078 | + assert( |
| 71079 | + (pIdxKey->errCode!=SQLITE_CORRUPT || c==0) |
| 71080 | + && (pIdxKey->errCode!=SQLITE_NOMEM || pCur->pBtree->db->mallocFailed) |
| 71081 | + ); |
| 71082 | + if( c<0 ){ |
| 71083 | + lwr = idx+1; |
| 71084 | + }else if( c>0 ){ |
| 71085 | + upr = idx-1; |
| 71086 | + }else{ |
| 71087 | + assert( c==0 ); |
| 71088 | + *pRes = 0; |
| 71089 | + rc = SQLITE_OK; |
| 71090 | + pCur->ix = (u16)idx; |
| 71091 | + if( pIdxKey->errCode ) rc = SQLITE_CORRUPT_BKPT; |
| 71092 | + goto moveto_index_finish; |
| 71093 | + } |
| 71094 | + if( lwr>upr ) break; |
| 71095 | + assert( lwr+upr>=0 ); |
| 71096 | + idx = (lwr+upr)>>1; /* idx = (lwr+upr)/2 */ |
| 71117 | 71097 | } |
| 71118 | 71098 | assert( lwr==upr+1 || (pPage->intKey && !pPage->leaf) ); |
| 71119 | 71099 | assert( pPage->isInit ); |
| 71120 | 71100 | if( pPage->leaf ){ |
| 71121 | 71101 | assert( pCur->ix<pCur->pPage->nCell ); |
| 71122 | 71102 | pCur->ix = (u16)idx; |
| 71123 | 71103 | *pRes = c; |
| 71124 | 71104 | rc = SQLITE_OK; |
| 71125 | | - goto moveto_finish; |
| 71105 | + goto moveto_index_finish; |
| 71126 | 71106 | } |
| 71127 | | -moveto_next_layer: |
| 71128 | 71107 | if( lwr>=pPage->nCell ){ |
| 71129 | 71108 | chldPg = get4byte(&pPage->aData[pPage->hdrOffset+8]); |
| 71130 | 71109 | }else{ |
| 71131 | 71110 | chldPg = get4byte(findCell(pPage, lwr)); |
| 71132 | 71111 | } |
| 71133 | 71112 | pCur->ix = (u16)lwr; |
| 71134 | 71113 | rc = moveToChild(pCur, chldPg); |
| 71135 | 71114 | if( rc ) break; |
| 71136 | 71115 | } |
| 71137 | | -moveto_finish: |
| 71116 | +moveto_index_finish: |
| 71138 | 71117 | pCur->info.nSize = 0; |
| 71139 | 71118 | assert( (pCur->curFlags & BTCF_ValidOvfl)==0 ); |
| 71140 | 71119 | return rc; |
| 71141 | 71120 | } |
| 71142 | 71121 | |
| | @@ -73116,10 +73095,11 @@ |
| 73116 | 73095 | if( rc ){ |
| 73117 | 73096 | memset(apOld, 0, (i)*sizeof(MemPage*)); |
| 73118 | 73097 | goto balance_cleanup; |
| 73119 | 73098 | } |
| 73120 | 73099 | } |
| 73100 | + nMaxCells += apOld[i]->nCell + ArraySize(pParent->apOvfl); |
| 73121 | 73101 | if( (i--)==0 ) break; |
| 73122 | 73102 | |
| 73123 | 73103 | if( pParent->nOverflow && i+nxDiv==pParent->aiOvfl[0] ){ |
| 73124 | 73104 | apDiv[i] = pParent->apOvfl[0]; |
| 73125 | 73105 | pgno = get4byte(apDiv[i]); |
| | @@ -73157,11 +73137,10 @@ |
| 73157 | 73137 | } |
| 73158 | 73138 | } |
| 73159 | 73139 | |
| 73160 | 73140 | /* Make nMaxCells a multiple of 4 in order to preserve 8-byte |
| 73161 | 73141 | ** alignment */ |
| 73162 | | - nMaxCells = nOld*(MX_CELL(pBt) + ArraySize(pParent->apOvfl)); |
| 73163 | 73142 | nMaxCells = (nMaxCells + 3)&~3; |
| 73164 | 73143 | |
| 73165 | 73144 | /* |
| 73166 | 73145 | ** Allocate space for memory structures |
| 73167 | 73146 | */ |
| | @@ -73440,11 +73419,13 @@ |
| 73440 | 73419 | if( i<nOld ){ |
| 73441 | 73420 | pNew = apNew[i] = apOld[i]; |
| 73442 | 73421 | apOld[i] = 0; |
| 73443 | 73422 | rc = sqlite3PagerWrite(pNew->pDbPage); |
| 73444 | 73423 | nNew++; |
| 73445 | | - if( sqlite3PagerPageRefcount(pNew->pDbPage)!=1+(i==(iParentIdx-nxDiv)) ){ |
| 73424 | + if( sqlite3PagerPageRefcount(pNew->pDbPage)!=1+(i==(iParentIdx-nxDiv)) |
| 73425 | + && rc==SQLITE_OK |
| 73426 | + ){ |
| 73446 | 73427 | rc = SQLITE_CORRUPT_BKPT; |
| 73447 | 73428 | } |
| 73448 | 73429 | if( rc ) goto balance_cleanup; |
| 73449 | 73430 | }else{ |
| 73450 | 73431 | assert( i>0 ); |
| | @@ -74238,11 +74219,12 @@ |
| 74238 | 74219 | }else if( loc==0 ){ |
| 74239 | 74220 | /* The cursor is *not* pointing to the cell to be overwritten, nor |
| 74240 | 74221 | ** to an adjacent cell. Move the cursor so that it is pointing either |
| 74241 | 74222 | ** to the cell to be overwritten or an adjacent cell. |
| 74242 | 74223 | */ |
| 74243 | | - rc = sqlite3BtreeMovetoUnpacked(pCur, 0, pX->nKey, flags!=0, &loc); |
| 74224 | + rc = sqlite3BtreeTableMoveto(pCur, pX->nKey, |
| 74225 | + (flags & BTREE_APPEND)!=0, &loc); |
| 74244 | 74226 | if( rc ) return rc; |
| 74245 | 74227 | } |
| 74246 | 74228 | }else{ |
| 74247 | 74229 | /* This is an index or a WITHOUT ROWID table */ |
| 74248 | 74230 | |
| | @@ -74261,17 +74243,15 @@ |
| 74261 | 74243 | UnpackedRecord r; |
| 74262 | 74244 | r.pKeyInfo = pCur->pKeyInfo; |
| 74263 | 74245 | r.aMem = pX->aMem; |
| 74264 | 74246 | r.nField = pX->nMem; |
| 74265 | 74247 | r.default_rc = 0; |
| 74266 | | - r.errCode = 0; |
| 74267 | | - r.r1 = 0; |
| 74268 | | - r.r2 = 0; |
| 74269 | 74248 | r.eqSeen = 0; |
| 74270 | | - rc = sqlite3BtreeMovetoUnpacked(pCur, &r, 0, flags!=0, &loc); |
| 74249 | + rc = sqlite3BtreeIndexMoveto(pCur, &r, &loc); |
| 74271 | 74250 | }else{ |
| 74272 | | - rc = btreeMoveto(pCur, pX->pKey, pX->nKey, flags!=0, &loc); |
| 74251 | + rc = btreeMoveto(pCur, pX->pKey, pX->nKey, |
| 74252 | + (flags & BTREE_APPEND)!=0, &loc); |
| 74273 | 74253 | } |
| 74274 | 74254 | if( rc ) return rc; |
| 74275 | 74255 | } |
| 74276 | 74256 | |
| 74277 | 74257 | /* If the cursor is currently pointing to an entry to be overwritten |
| | @@ -74901,11 +74881,11 @@ |
| 74901 | 74881 | */ |
| 74902 | 74882 | static int clearDatabasePage( |
| 74903 | 74883 | BtShared *pBt, /* The BTree that contains the table */ |
| 74904 | 74884 | Pgno pgno, /* Page number to clear */ |
| 74905 | 74885 | int freePageFlag, /* Deallocate page if true */ |
| 74906 | | - int *pnChange /* Add number of Cells freed to this counter */ |
| 74886 | + i64 *pnChange /* Add number of Cells freed to this counter */ |
| 74907 | 74887 | ){ |
| 74908 | 74888 | MemPage *pPage; |
| 74909 | 74889 | int rc; |
| 74910 | 74890 | unsigned char *pCell; |
| 74911 | 74891 | int i; |
| | @@ -74934,10 +74914,11 @@ |
| 74934 | 74914 | if( rc ) goto cleardatabasepage_out; |
| 74935 | 74915 | } |
| 74936 | 74916 | if( !pPage->leaf ){ |
| 74937 | 74917 | rc = clearDatabasePage(pBt, get4byte(&pPage->aData[hdr+8]), 1, pnChange); |
| 74938 | 74918 | if( rc ) goto cleardatabasepage_out; |
| 74919 | + if( pPage->intKey ) pnChange = 0; |
| 74939 | 74920 | } |
| 74940 | 74921 | if( pnChange ){ |
| 74941 | 74922 | testcase( !pPage->intKey ); |
| 74942 | 74923 | *pnChange += pPage->nCell; |
| 74943 | 74924 | } |
| | @@ -74963,11 +74944,11 @@ |
| 74963 | 74944 | ** root of the table. |
| 74964 | 74945 | ** |
| 74965 | 74946 | ** If pnChange is not NULL, then the integer value pointed to by pnChange |
| 74966 | 74947 | ** is incremented by the number of entries in the table. |
| 74967 | 74948 | */ |
| 74968 | | -SQLITE_PRIVATE int sqlite3BtreeClearTable(Btree *p, int iTable, int *pnChange){ |
| 74949 | +SQLITE_PRIVATE int sqlite3BtreeClearTable(Btree *p, int iTable, i64 *pnChange){ |
| 74969 | 74950 | int rc; |
| 74970 | 74951 | BtShared *pBt = p->pBt; |
| 74971 | 74952 | sqlite3BtreeEnter(p); |
| 74972 | 74953 | assert( p->inTrans==TRANS_WRITE ); |
| 74973 | 74954 | |
| | @@ -80557,11 +80538,11 @@ |
| 80557 | 80538 | } |
| 80558 | 80539 | #endif |
| 80559 | 80540 | case P4_COLLSEQ: { |
| 80560 | 80541 | static const char *const encnames[] = {"?", "8", "16LE", "16BE"}; |
| 80561 | 80542 | CollSeq *pColl = pOp->p4.pColl; |
| 80562 | | - assert( pColl->enc>=0 && pColl->enc<4 ); |
| 80543 | + assert( pColl->enc<4 ); |
| 80563 | 80544 | sqlite3_str_appendf(&x, "%.18s-%s", pColl->zName, |
| 80564 | 80545 | encnames[pColl->enc]); |
| 80565 | 80546 | break; |
| 80566 | 80547 | } |
| 80567 | 80548 | case P4_FUNCDEF: { |
| | @@ -82398,11 +82379,11 @@ |
| 82398 | 82379 | extern int sqlite3_search_count; |
| 82399 | 82380 | #endif |
| 82400 | 82381 | assert( p->deferredMoveto ); |
| 82401 | 82382 | assert( p->isTable ); |
| 82402 | 82383 | assert( p->eCurType==CURTYPE_BTREE ); |
| 82403 | | - rc = sqlite3BtreeMovetoUnpacked(p->uc.pCursor, 0, p->movetoTarget, 0, &res); |
| 82384 | + rc = sqlite3BtreeTableMoveto(p->uc.pCursor, p->movetoTarget, 0, &res); |
| 82404 | 82385 | if( rc ) return rc; |
| 82405 | 82386 | if( res!=0 ) return SQLITE_CORRUPT_BKPT; |
| 82406 | 82387 | #ifdef SQLITE_TEST |
| 82407 | 82388 | sqlite3_search_count++; |
| 82408 | 82389 | #endif |
| | @@ -83182,11 +83163,11 @@ |
| 83182 | 83163 | /* |
| 83183 | 83164 | ** Do a comparison between a 64-bit signed integer and a 64-bit floating-point |
| 83184 | 83165 | ** number. Return negative, zero, or positive if the first (i64) is less than, |
| 83185 | 83166 | ** equal to, or greater than the second (double). |
| 83186 | 83167 | */ |
| 83187 | | -static int sqlite3IntFloatCompare(i64 i, double r){ |
| 83168 | +SQLITE_PRIVATE int sqlite3IntFloatCompare(i64 i, double r){ |
| 83188 | 83169 | if( sizeof(LONGDOUBLE_TYPE)>8 ){ |
| 83189 | 83170 | LONGDOUBLE_TYPE x = (LONGDOUBLE_TYPE)i; |
| 83190 | 83171 | testcase( x<r ); |
| 83191 | 83172 | testcase( x>r ); |
| 83192 | 83173 | testcase( x==r ); |
| | @@ -83906,11 +83887,11 @@ |
| 83906 | 83887 | |
| 83907 | 83888 | /* |
| 83908 | 83889 | ** This routine sets the value to be returned by subsequent calls to |
| 83909 | 83890 | ** sqlite3_changes() on the database handle 'db'. |
| 83910 | 83891 | */ |
| 83911 | | -SQLITE_PRIVATE void sqlite3VdbeSetChanges(sqlite3 *db, int nChange){ |
| 83892 | +SQLITE_PRIVATE void sqlite3VdbeSetChanges(sqlite3 *db, i64 nChange){ |
| 83912 | 83893 | assert( sqlite3_mutex_held(db->mutex) ); |
| 83913 | 83894 | db->nChange = nChange; |
| 83914 | 83895 | db->nTotalChange += nChange; |
| 83915 | 83896 | } |
| 83916 | 83897 | |
| | @@ -87023,100 +87004,11 @@ |
| 87023 | 87004 | |
| 87024 | 87005 | /* |
| 87025 | 87006 | ** hwtime.h contains inline assembler code for implementing |
| 87026 | 87007 | ** high-performance timing routines. |
| 87027 | 87008 | */ |
| 87028 | | -/************** Include hwtime.h in the middle of vdbe.c *********************/ |
| 87029 | | -/************** Begin file hwtime.h ******************************************/ |
| 87030 | | -/* |
| 87031 | | -** 2008 May 27 |
| 87032 | | -** |
| 87033 | | -** The author disclaims copyright to this source code. In place of |
| 87034 | | -** a legal notice, here is a blessing: |
| 87035 | | -** |
| 87036 | | -** May you do good and not evil. |
| 87037 | | -** May you find forgiveness for yourself and forgive others. |
| 87038 | | -** May you share freely, never taking more than you give. |
| 87039 | | -** |
| 87040 | | -****************************************************************************** |
| 87041 | | -** |
| 87042 | | -** This file contains inline asm code for retrieving "high-performance" |
| 87043 | | -** counters for x86 and x86_64 class CPUs. |
| 87044 | | -*/ |
| 87045 | | -#ifndef SQLITE_HWTIME_H |
| 87046 | | -#define SQLITE_HWTIME_H |
| 87047 | | - |
| 87048 | | -/* |
| 87049 | | -** The following routine only works on pentium-class (or newer) processors. |
| 87050 | | -** It uses the RDTSC opcode to read the cycle count value out of the |
| 87051 | | -** processor and returns that value. This can be used for high-res |
| 87052 | | -** profiling. |
| 87053 | | -*/ |
| 87054 | | -#if !defined(__STRICT_ANSI__) && \ |
| 87055 | | - (defined(__GNUC__) || defined(_MSC_VER)) && \ |
| 87056 | | - (defined(i386) || defined(__i386__) || defined(_M_IX86)) |
| 87057 | | - |
| 87058 | | - #if defined(__GNUC__) |
| 87059 | | - |
| 87060 | | - __inline__ sqlite_uint64 sqlite3Hwtime(void){ |
| 87061 | | - unsigned int lo, hi; |
| 87062 | | - __asm__ __volatile__ ("rdtsc" : "=a" (lo), "=d" (hi)); |
| 87063 | | - return (sqlite_uint64)hi << 32 | lo; |
| 87064 | | - } |
| 87065 | | - |
| 87066 | | - #elif defined(_MSC_VER) |
| 87067 | | - |
| 87068 | | - __declspec(naked) __inline sqlite_uint64 __cdecl sqlite3Hwtime(void){ |
| 87069 | | - __asm { |
| 87070 | | - rdtsc |
| 87071 | | - ret ; return value at EDX:EAX |
| 87072 | | - } |
| 87073 | | - } |
| 87074 | | - |
| 87075 | | - #endif |
| 87076 | | - |
| 87077 | | -#elif !defined(__STRICT_ANSI__) && (defined(__GNUC__) && defined(__x86_64__)) |
| 87078 | | - |
| 87079 | | - __inline__ sqlite_uint64 sqlite3Hwtime(void){ |
| 87080 | | - unsigned long val; |
| 87081 | | - __asm__ __volatile__ ("rdtsc" : "=A" (val)); |
| 87082 | | - return val; |
| 87083 | | - } |
| 87084 | | - |
| 87085 | | -#elif !defined(__STRICT_ANSI__) && (defined(__GNUC__) && defined(__ppc__)) |
| 87086 | | - |
| 87087 | | - __inline__ sqlite_uint64 sqlite3Hwtime(void){ |
| 87088 | | - unsigned long long retval; |
| 87089 | | - unsigned long junk; |
| 87090 | | - __asm__ __volatile__ ("\n\ |
| 87091 | | - 1: mftbu %1\n\ |
| 87092 | | - mftb %L0\n\ |
| 87093 | | - mftbu %0\n\ |
| 87094 | | - cmpw %0,%1\n\ |
| 87095 | | - bne 1b" |
| 87096 | | - : "=r" (retval), "=r" (junk)); |
| 87097 | | - return retval; |
| 87098 | | - } |
| 87099 | | - |
| 87100 | | -#else |
| 87101 | | - |
| 87102 | | - /* |
| 87103 | | - ** asm() is needed for hardware timing support. Without asm(), |
| 87104 | | - ** disable the sqlite3Hwtime() routine. |
| 87105 | | - ** |
| 87106 | | - ** sqlite3Hwtime() is only used for some obscure debugging |
| 87107 | | - ** and analysis configurations, not in any deliverable, so this |
| 87108 | | - ** should not be a great loss. |
| 87109 | | - */ |
| 87110 | | -SQLITE_PRIVATE sqlite_uint64 sqlite3Hwtime(void){ return ((sqlite_uint64)0); } |
| 87111 | | - |
| 87112 | | -#endif |
| 87113 | | - |
| 87114 | | -#endif /* !defined(SQLITE_HWTIME_H) */ |
| 87115 | | - |
| 87116 | | -/************** End of hwtime.h **********************************************/ |
| 87117 | | -/************** Continuing where we left off in vdbe.c ***********************/ |
| 87009 | +/* #include "hwtime.h" */ |
| 87118 | 87010 | |
| 87119 | 87011 | #endif |
| 87120 | 87012 | |
| 87121 | 87013 | #ifndef NDEBUG |
| 87122 | 87014 | /* |
| | @@ -90274,10 +90166,12 @@ |
| 90274 | 90166 | assert( pOp->p5==0 || pOp->p5==OPFLAG_SEEKEQ ); |
| 90275 | 90167 | assert( pOp->p4type==P4_KEYINFO ); |
| 90276 | 90168 | pCur = p->apCsr[pOp->p1]; |
| 90277 | 90169 | if( pCur && pCur->pgnoRoot==(u32)pOp->p2 ){ |
| 90278 | 90170 | assert( pCur->iDb==pOp->p3 ); /* Guaranteed by the code generator */ |
| 90171 | + assert( pCur->eCurType==CURTYPE_BTREE ); |
| 90172 | + sqlite3BtreeClearCursor(pCur->uc.pCursor); |
| 90279 | 90173 | goto open_cursor_set_hints; |
| 90280 | 90174 | } |
| 90281 | 90175 | /* If the cursor is not currently open or is open on a different |
| 90282 | 90176 | ** index, then fall through into OP_OpenRead to force a reopen */ |
| 90283 | 90177 | case OP_OpenRead: |
| | @@ -90761,45 +90655,47 @@ |
| 90761 | 90655 | pIn3->flags = flags3; /* But convert the type back to its original */ |
| 90762 | 90656 | |
| 90763 | 90657 | /* If the P3 value could not be converted into an integer without |
| 90764 | 90658 | ** loss of information, then special processing is required... */ |
| 90765 | 90659 | if( (newType & (MEM_Int|MEM_IntReal))==0 ){ |
| 90660 | + int c; |
| 90766 | 90661 | if( (newType & MEM_Real)==0 ){ |
| 90767 | 90662 | if( (newType & MEM_Null) || oc>=OP_SeekGE ){ |
| 90768 | 90663 | VdbeBranchTaken(1,2); |
| 90769 | 90664 | goto jump_to_p2; |
| 90770 | 90665 | }else{ |
| 90771 | 90666 | rc = sqlite3BtreeLast(pC->uc.pCursor, &res); |
| 90772 | 90667 | if( rc!=SQLITE_OK ) goto abort_due_to_error; |
| 90773 | 90668 | goto seek_not_found; |
| 90774 | 90669 | } |
| 90775 | | - }else |
| 90670 | + } |
| 90671 | + c = sqlite3IntFloatCompare(iKey, pIn3->u.r); |
| 90776 | 90672 | |
| 90777 | 90673 | /* If the approximation iKey is larger than the actual real search |
| 90778 | 90674 | ** term, substitute >= for > and < for <=. e.g. if the search term |
| 90779 | 90675 | ** is 4.9 and the integer approximation 5: |
| 90780 | 90676 | ** |
| 90781 | 90677 | ** (x > 4.9) -> (x >= 5) |
| 90782 | 90678 | ** (x <= 4.9) -> (x < 5) |
| 90783 | 90679 | */ |
| 90784 | | - if( pIn3->u.r<(double)iKey ){ |
| 90680 | + if( c>0 ){ |
| 90785 | 90681 | assert( OP_SeekGE==(OP_SeekGT-1) ); |
| 90786 | 90682 | assert( OP_SeekLT==(OP_SeekLE-1) ); |
| 90787 | 90683 | assert( (OP_SeekLE & 0x0001)==(OP_SeekGT & 0x0001) ); |
| 90788 | 90684 | if( (oc & 0x0001)==(OP_SeekGT & 0x0001) ) oc--; |
| 90789 | 90685 | } |
| 90790 | 90686 | |
| 90791 | 90687 | /* If the approximation iKey is smaller than the actual real search |
| 90792 | 90688 | ** term, substitute <= for < and > for >=. */ |
| 90793 | | - else if( pIn3->u.r>(double)iKey ){ |
| 90689 | + else if( c<0 ){ |
| 90794 | 90690 | assert( OP_SeekLE==(OP_SeekLT+1) ); |
| 90795 | 90691 | assert( OP_SeekGT==(OP_SeekGE+1) ); |
| 90796 | 90692 | assert( (OP_SeekLT & 0x0001)==(OP_SeekGE & 0x0001) ); |
| 90797 | 90693 | if( (oc & 0x0001)==(OP_SeekLT & 0x0001) ) oc++; |
| 90798 | 90694 | } |
| 90799 | 90695 | } |
| 90800 | | - rc = sqlite3BtreeMovetoUnpacked(pC->uc.pCursor, 0, (u64)iKey, 0, &res); |
| 90696 | + rc = sqlite3BtreeTableMoveto(pC->uc.pCursor, (u64)iKey, 0, &res); |
| 90801 | 90697 | pC->movetoTarget = iKey; /* Used by OP_Delete */ |
| 90802 | 90698 | if( rc!=SQLITE_OK ){ |
| 90803 | 90699 | goto abort_due_to_error; |
| 90804 | 90700 | } |
| 90805 | 90701 | }else{ |
| | @@ -90842,11 +90738,11 @@ |
| 90842 | 90738 | r.aMem = &aMem[pOp->p3]; |
| 90843 | 90739 | #ifdef SQLITE_DEBUG |
| 90844 | 90740 | { int i; for(i=0; i<r.nField; i++) assert( memIsValid(&r.aMem[i]) ); } |
| 90845 | 90741 | #endif |
| 90846 | 90742 | r.eqSeen = 0; |
| 90847 | | - rc = sqlite3BtreeMovetoUnpacked(pC->uc.pCursor, &r, 0, 0, &res); |
| 90743 | + rc = sqlite3BtreeIndexMoveto(pC->uc.pCursor, &r, &res); |
| 90848 | 90744 | if( rc!=SQLITE_OK ){ |
| 90849 | 90745 | goto abort_due_to_error; |
| 90850 | 90746 | } |
| 90851 | 90747 | if( eqOnly && r.eqSeen==0 ){ |
| 90852 | 90748 | assert( res!=0 ); |
| | @@ -91261,11 +91157,11 @@ |
| 91261 | 91157 | takeJump = 1; |
| 91262 | 91158 | break; |
| 91263 | 91159 | } |
| 91264 | 91160 | } |
| 91265 | 91161 | } |
| 91266 | | - rc = sqlite3BtreeMovetoUnpacked(pC->uc.pCursor, pIdxKey, 0, 0, &res); |
| 91162 | + rc = sqlite3BtreeIndexMoveto(pC->uc.pCursor, pIdxKey, &res); |
| 91267 | 91163 | if( pFree ) sqlite3DbFreeNN(db, pFree); |
| 91268 | 91164 | if( rc!=SQLITE_OK ){ |
| 91269 | 91165 | goto abort_due_to_error; |
| 91270 | 91166 | } |
| 91271 | 91167 | pC->seekResult = res; |
| | @@ -91370,11 +91266,11 @@ |
| 91370 | 91266 | assert( pC->isTable ); |
| 91371 | 91267 | assert( pC->eCurType==CURTYPE_BTREE ); |
| 91372 | 91268 | pCrsr = pC->uc.pCursor; |
| 91373 | 91269 | assert( pCrsr!=0 ); |
| 91374 | 91270 | res = 0; |
| 91375 | | - rc = sqlite3BtreeMovetoUnpacked(pCrsr, 0, iKey, 0, &res); |
| 91271 | + rc = sqlite3BtreeTableMoveto(pCrsr, iKey, 0, &res); |
| 91376 | 91272 | assert( rc==SQLITE_OK || res==0 ); |
| 91377 | 91273 | pC->movetoTarget = iKey; /* Used by OP_Delete */ |
| 91378 | 91274 | pC->nullRow = 0; |
| 91379 | 91275 | pC->cacheStatus = CACHE_STALE; |
| 91380 | 91276 | pC->deferredMoveto = 0; |
| | @@ -91527,11 +91423,11 @@ |
| 91527 | 91423 | ** an AUTOINCREMENT table. */ |
| 91528 | 91424 | cnt = 0; |
| 91529 | 91425 | do{ |
| 91530 | 91426 | sqlite3_randomness(sizeof(v), &v); |
| 91531 | 91427 | v &= (MAX_ROWID>>1); v++; /* Ensure that v is greater than zero */ |
| 91532 | | - }while( ((rc = sqlite3BtreeMovetoUnpacked(pC->uc.pCursor, 0, (u64)v, |
| 91428 | + }while( ((rc = sqlite3BtreeTableMoveto(pC->uc.pCursor, (u64)v, |
| 91533 | 91429 | 0, &res))==SQLITE_OK) |
| 91534 | 91430 | && (res==0) |
| 91535 | 91431 | && (++cnt<100)); |
| 91536 | 91432 | if( rc ) goto abort_due_to_error; |
| 91537 | 91433 | if( res==0 ){ |
| | @@ -92425,11 +92321,11 @@ |
| 92425 | 92321 | assert( pCrsr!=0 ); |
| 92426 | 92322 | r.pKeyInfo = pC->pKeyInfo; |
| 92427 | 92323 | r.nField = (u16)pOp->p3; |
| 92428 | 92324 | r.default_rc = 0; |
| 92429 | 92325 | r.aMem = &aMem[pOp->p2]; |
| 92430 | | - rc = sqlite3BtreeMovetoUnpacked(pCrsr, &r, 0, 0, &res); |
| 92326 | + rc = sqlite3BtreeIndexMoveto(pCrsr, &r, &res); |
| 92431 | 92327 | if( rc ) goto abort_due_to_error; |
| 92432 | 92328 | if( res==0 ){ |
| 92433 | 92329 | rc = sqlite3BtreeDelete(pCrsr, BTREE_AUXDELETE); |
| 92434 | 92330 | if( rc ) goto abort_due_to_error; |
| 92435 | 92331 | }else if( pOp->p5 ){ |
| | @@ -92738,11 +92634,11 @@ |
| 92738 | 92634 | ** by the number of rows in the table being cleared. |
| 92739 | 92635 | ** |
| 92740 | 92636 | ** See also: Destroy |
| 92741 | 92637 | */ |
| 92742 | 92638 | case OP_Clear: { |
| 92743 | | - int nChange; |
| 92639 | + i64 nChange; |
| 92744 | 92640 | |
| 92745 | 92641 | sqlite3VdbeIncrWriteCounter(p, 0); |
| 92746 | 92642 | nChange = 0; |
| 92747 | 92643 | assert( p->readOnly==0 ); |
| 92748 | 92644 | assert( DbMaskTest(p->btreeMask, pOp->p2) ); |
| | @@ -94960,11 +94856,11 @@ |
| 94960 | 94856 | if( pTab && !HasRowid(pTab) ){ |
| 94961 | 94857 | pTab = 0; |
| 94962 | 94858 | sqlite3ErrorMsg(&sParse, "cannot open table without rowid: %s", zTable); |
| 94963 | 94859 | } |
| 94964 | 94860 | #ifndef SQLITE_OMIT_VIEW |
| 94965 | | - if( pTab && pTab->pSelect ){ |
| 94861 | + if( pTab && IsView(pTab) ){ |
| 94966 | 94862 | pTab = 0; |
| 94967 | 94863 | sqlite3ErrorMsg(&sParse, "cannot open view: %s", zTable); |
| 94968 | 94864 | } |
| 94969 | 94865 | #endif |
| 94970 | 94866 | if( !pTab ){ |
| | @@ -94980,11 +94876,11 @@ |
| 94980 | 94876 | pBlob->pTab = pTab; |
| 94981 | 94877 | pBlob->zDb = db->aDb[sqlite3SchemaToIndex(db, pTab->pSchema)].zDbSName; |
| 94982 | 94878 | |
| 94983 | 94879 | /* Now search pTab for the exact column. */ |
| 94984 | 94880 | for(iCol=0; iCol<pTab->nCol; iCol++) { |
| 94985 | | - if( sqlite3StrICmp(pTab->aCol[iCol].zName, zColumn)==0 ){ |
| 94881 | + if( sqlite3StrICmp(pTab->aCol[iCol].zCnName, zColumn)==0 ){ |
| 94986 | 94882 | break; |
| 94987 | 94883 | } |
| 94988 | 94884 | } |
| 94989 | 94885 | if( iCol==pTab->nCol ){ |
| 94990 | 94886 | sqlite3DbFree(db, zErr); |
| | @@ -95005,11 +94901,12 @@ |
| 95005 | 94901 | /* Check that the column is not part of an FK child key definition. It |
| 95006 | 94902 | ** is not necessary to check if it is part of a parent key, as parent |
| 95007 | 94903 | ** key columns must be indexed. The check below will pick up this |
| 95008 | 94904 | ** case. */ |
| 95009 | 94905 | FKey *pFKey; |
| 95010 | | - for(pFKey=pTab->pFKey; pFKey; pFKey=pFKey->pNextFrom){ |
| 94906 | + assert( !IsVirtual(pTab) ); |
| 94907 | + for(pFKey=pTab->u.tab.pFKey; pFKey; pFKey=pFKey->pNextFrom){ |
| 95011 | 94908 | int j; |
| 95012 | 94909 | for(j=0; j<pFKey->nCol; j++){ |
| 95013 | 94910 | if( pFKey->aCol[j].iFrom==iCol ){ |
| 95014 | 94911 | zFault = "foreign key"; |
| 95015 | 94912 | } |
| | @@ -96378,12 +96275,13 @@ |
| 96378 | 96275 | int iTask = (pTask - pTask->pSorter->aTask); |
| 96379 | 96276 | sqlite3OsCurrentTimeInt64(pTask->pSorter->db->pVfs, &t); |
| 96380 | 96277 | fprintf(stderr, "%lld:%d %s\n", t, iTask, zEvent); |
| 96381 | 96278 | } |
| 96382 | 96279 | static void vdbeSorterRewindDebug(const char *zEvent){ |
| 96383 | | - i64 t; |
| 96384 | | - sqlite3OsCurrentTimeInt64(sqlite3_vfs_find(0), &t); |
| 96280 | + i64 t = 0; |
| 96281 | + sqlite3_vfs *pVfs = sqlite3_vfs_find(0); |
| 96282 | + if( ALWAYS(pVfs) ) sqlite3OsCurrentTimeInt64(pVfs, &t); |
| 96385 | 96283 | fprintf(stderr, "%lld:X %s\n", t, zEvent); |
| 96386 | 96284 | } |
| 96387 | 96285 | static void vdbeSorterPopulateDebug( |
| 96388 | 96286 | SortSubtask *pTask, |
| 96389 | 96287 | const char *zEvent |
| | @@ -99500,11 +99398,11 @@ |
| 99500 | 99398 | if( pSrcList ){ |
| 99501 | 99399 | for(i=0, pItem=pSrcList->a; i<pSrcList->nSrc; i++, pItem++){ |
| 99502 | 99400 | u8 hCol; |
| 99503 | 99401 | pTab = pItem->pTab; |
| 99504 | 99402 | assert( pTab!=0 && pTab->zName!=0 ); |
| 99505 | | - assert( pTab->nCol>0 ); |
| 99403 | + assert( pTab->nCol>0 || pParse->nErr ); |
| 99506 | 99404 | if( pItem->pSelect && (pItem->pSelect->selFlags & SF_NestedFrom)!=0 ){ |
| 99507 | 99405 | int hit = 0; |
| 99508 | 99406 | pEList = pItem->pSelect->pEList; |
| 99509 | 99407 | for(j=0; j<pEList->nExpr; j++){ |
| 99510 | 99408 | if( sqlite3MatchEName(&pEList->a[j], zCol, zTab, zDb) ){ |
| | @@ -99528,16 +99426,15 @@ |
| 99528 | 99426 | } |
| 99529 | 99427 | if( IN_RENAME_OBJECT && pItem->zAlias ){ |
| 99530 | 99428 | sqlite3RenameTokenRemap(pParse, 0, (void*)&pExpr->y.pTab); |
| 99531 | 99429 | } |
| 99532 | 99430 | } |
| 99533 | | - if( 0==(cntTab++) ){ |
| 99534 | | - pMatch = pItem; |
| 99535 | | - } |
| 99536 | 99431 | hCol = sqlite3StrIHash(zCol); |
| 99537 | 99432 | for(j=0, pCol=pTab->aCol; j<pTab->nCol; j++, pCol++){ |
| 99538 | | - if( pCol->hName==hCol && sqlite3StrICmp(pCol->zName, zCol)==0 ){ |
| 99433 | + if( pCol->hName==hCol |
| 99434 | + && sqlite3StrICmp(pCol->zCnName, zCol)==0 |
| 99435 | + ){ |
| 99539 | 99436 | /* If there has been exactly one prior match and this match |
| 99540 | 99437 | ** is for the right-hand table of a NATURAL JOIN or is in a |
| 99541 | 99438 | ** USING clause, then skip this match. |
| 99542 | 99439 | */ |
| 99543 | 99440 | if( cnt==1 ){ |
| | @@ -99548,10 +99445,14 @@ |
| 99548 | 99445 | pMatch = pItem; |
| 99549 | 99446 | /* Substitute the rowid (column -1) for the INTEGER PRIMARY KEY */ |
| 99550 | 99447 | pExpr->iColumn = j==pTab->iPKey ? -1 : (i16)j; |
| 99551 | 99448 | break; |
| 99552 | 99449 | } |
| 99450 | + } |
| 99451 | + if( 0==cnt && VisibleRowid(pTab) ){ |
| 99452 | + cntTab++; |
| 99453 | + pMatch = pItem; |
| 99553 | 99454 | } |
| 99554 | 99455 | } |
| 99555 | 99456 | if( pMatch ){ |
| 99556 | 99457 | pExpr->iTable = pMatch->iCursor; |
| 99557 | 99458 | pExpr->y.pTab = pMatch->pTab; |
| | @@ -99606,11 +99507,13 @@ |
| 99606 | 99507 | int iCol; |
| 99607 | 99508 | u8 hCol = sqlite3StrIHash(zCol); |
| 99608 | 99509 | pSchema = pTab->pSchema; |
| 99609 | 99510 | cntTab++; |
| 99610 | 99511 | for(iCol=0, pCol=pTab->aCol; iCol<pTab->nCol; iCol++, pCol++){ |
| 99611 | | - if( pCol->hName==hCol && sqlite3StrICmp(pCol->zName, zCol)==0 ){ |
| 99512 | + if( pCol->hName==hCol |
| 99513 | + && sqlite3StrICmp(pCol->zCnName, zCol)==0 |
| 99514 | + ){ |
| 99612 | 99515 | if( iCol==pTab->iPKey ){ |
| 99613 | 99516 | iCol = -1; |
| 99614 | 99517 | } |
| 99615 | 99518 | break; |
| 99616 | 99519 | } |
| | @@ -99671,11 +99574,11 @@ |
| 99671 | 99574 | if( cnt==0 |
| 99672 | 99575 | && cntTab==1 |
| 99673 | 99576 | && pMatch |
| 99674 | 99577 | && (pNC->ncFlags & (NC_IdxExpr|NC_GenCol))==0 |
| 99675 | 99578 | && sqlite3IsRowid(zCol) |
| 99676 | | - && VisibleRowid(pMatch->pTab) |
| 99579 | + && ALWAYS(VisibleRowid(pMatch->pTab)) |
| 99677 | 99580 | ){ |
| 99678 | 99581 | cnt = 1; |
| 99679 | 99582 | pExpr->iColumn = -1; |
| 99680 | 99583 | pExpr->affExpr = SQLITE_AFF_INTEGER; |
| 99681 | 99584 | } |
| | @@ -100014,10 +99917,11 @@ |
| 100014 | 99917 | for(i=0, p=pNC; p && i<ArraySize(anRef); p=p->pNext, i++){ |
| 100015 | 99918 | anRef[i] = p->nRef; |
| 100016 | 99919 | } |
| 100017 | 99920 | sqlite3WalkExpr(pWalker, pExpr->pLeft); |
| 100018 | 99921 | if( 0==sqlite3ExprCanBeNull(pExpr->pLeft) && !IN_RENAME_OBJECT ){ |
| 99922 | + testcase( ExprHasProperty(pExpr, EP_FromJoin) ); |
| 100019 | 99923 | if( pExpr->op==TK_NOTNULL ){ |
| 100020 | 99924 | pExpr->u.zToken = "true"; |
| 100021 | 99925 | ExprSetProperty(pExpr, EP_IsTrue); |
| 100022 | 99926 | }else{ |
| 100023 | 99927 | pExpr->u.zToken = "false"; |
| | @@ -100283,13 +100187,16 @@ |
| 100283 | 100187 | pNC2 = pNC2->pNext; |
| 100284 | 100188 | } |
| 100285 | 100189 | assert( pDef!=0 || IN_RENAME_OBJECT ); |
| 100286 | 100190 | if( pNC2 && pDef ){ |
| 100287 | 100191 | assert( SQLITE_FUNC_MINMAX==NC_MinMaxAgg ); |
| 100192 | + assert( SQLITE_FUNC_ANYORDER==NC_OrderAgg ); |
| 100288 | 100193 | testcase( (pDef->funcFlags & SQLITE_FUNC_MINMAX)!=0 ); |
| 100289 | | - pNC2->ncFlags |= NC_HasAgg | (pDef->funcFlags & SQLITE_FUNC_MINMAX); |
| 100290 | | - |
| 100194 | + testcase( (pDef->funcFlags & SQLITE_FUNC_ANYORDER)!=0 ); |
| 100195 | + pNC2->ncFlags |= NC_HasAgg |
| 100196 | + | ((pDef->funcFlags^SQLITE_FUNC_ANYORDER) |
| 100197 | + & (SQLITE_FUNC_MINMAX|SQLITE_FUNC_ANYORDER)); |
| 100291 | 100198 | } |
| 100292 | 100199 | } |
| 100293 | 100200 | pNC->ncFlags |= savedAllowFlags; |
| 100294 | 100201 | } |
| 100295 | 100202 | /* FIX ME: Compute pExpr->affinity based on the expected return |
| | @@ -100828,11 +100735,11 @@ |
| 100828 | 100735 | assert( pSub->pPrior && pSub->pOrderBy==0 ); |
| 100829 | 100736 | pSub->pOrderBy = p->pOrderBy; |
| 100830 | 100737 | p->pOrderBy = 0; |
| 100831 | 100738 | } |
| 100832 | 100739 | |
| 100833 | | - /* Recursively resolve names in all subqueries |
| 100740 | + /* Recursively resolve names in all subqueries in the FROM clause |
| 100834 | 100741 | */ |
| 100835 | 100742 | for(i=0; i<p->pSrc->nSrc; i++){ |
| 100836 | 100743 | SrcItem *pItem = &p->pSrc->a[i]; |
| 100837 | 100744 | if( pItem->pSelect && (pItem->pSelect->selFlags & SF_Resolved)==0 ){ |
| 100838 | 100745 | int nRef = pOuterNC ? pOuterNC->nRef : 0; |
| | @@ -100872,11 +100779,12 @@ |
| 100872 | 100779 | */ |
| 100873 | 100780 | assert( (p->selFlags & SF_Aggregate)==0 ); |
| 100874 | 100781 | pGroupBy = p->pGroupBy; |
| 100875 | 100782 | if( pGroupBy || (sNC.ncFlags & NC_HasAgg)!=0 ){ |
| 100876 | 100783 | assert( NC_MinMaxAgg==SF_MinMaxAgg ); |
| 100877 | | - p->selFlags |= SF_Aggregate | (sNC.ncFlags&NC_MinMaxAgg); |
| 100784 | + assert( NC_OrderAgg==SF_OrderByReqd ); |
| 100785 | + p->selFlags |= SF_Aggregate | (sNC.ncFlags&(NC_MinMaxAgg|NC_OrderAgg)); |
| 100878 | 100786 | }else{ |
| 100879 | 100787 | sNC.ncFlags &= ~NC_AllowAgg; |
| 100880 | 100788 | } |
| 100881 | 100789 | |
| 100882 | 100790 | /* Add the output column list to the name-context before parsing the |
| | @@ -101055,12 +100963,12 @@ |
| 101055 | 100963 | ){ |
| 101056 | 100964 | int savedHasAgg; |
| 101057 | 100965 | Walker w; |
| 101058 | 100966 | |
| 101059 | 100967 | if( pExpr==0 ) return SQLITE_OK; |
| 101060 | | - savedHasAgg = pNC->ncFlags & (NC_HasAgg|NC_MinMaxAgg|NC_HasWin); |
| 101061 | | - pNC->ncFlags &= ~(NC_HasAgg|NC_MinMaxAgg|NC_HasWin); |
| 100968 | + savedHasAgg = pNC->ncFlags & (NC_HasAgg|NC_MinMaxAgg|NC_HasWin|NC_OrderAgg); |
| 100969 | + pNC->ncFlags &= ~(NC_HasAgg|NC_MinMaxAgg|NC_HasWin|NC_OrderAgg); |
| 101062 | 100970 | w.pParse = pNC->pParse; |
| 101063 | 100971 | w.xExprCallback = resolveExprStep; |
| 101064 | 100972 | w.xSelectCallback = (pNC->ncFlags & NC_NoSelect) ? 0 : resolveSelectStep; |
| 101065 | 100973 | w.xSelectCallback2 = 0; |
| 101066 | 100974 | w.u.pNC = pNC; |
| | @@ -101099,12 +101007,12 @@ |
| 101099 | 101007 | w.pParse = pNC->pParse; |
| 101100 | 101008 | w.xExprCallback = resolveExprStep; |
| 101101 | 101009 | w.xSelectCallback = resolveSelectStep; |
| 101102 | 101010 | w.xSelectCallback2 = 0; |
| 101103 | 101011 | w.u.pNC = pNC; |
| 101104 | | - savedHasAgg = pNC->ncFlags & (NC_HasAgg|NC_MinMaxAgg|NC_HasWin); |
| 101105 | | - pNC->ncFlags &= ~(NC_HasAgg|NC_MinMaxAgg|NC_HasWin); |
| 101012 | + savedHasAgg = pNC->ncFlags & (NC_HasAgg|NC_MinMaxAgg|NC_HasWin|NC_OrderAgg); |
| 101013 | + pNC->ncFlags &= ~(NC_HasAgg|NC_MinMaxAgg|NC_HasWin|NC_OrderAgg); |
| 101106 | 101014 | for(i=0; i<pList->nExpr; i++){ |
| 101107 | 101015 | Expr *pExpr = pList->a[i].pExpr; |
| 101108 | 101016 | if( pExpr==0 ) continue; |
| 101109 | 101017 | #if SQLITE_MAX_EXPR_DEPTH>0 |
| 101110 | 101018 | w.pParse->nHeight += pExpr->nHeight; |
| | @@ -101118,14 +101026,15 @@ |
| 101118 | 101026 | #endif |
| 101119 | 101027 | assert( EP_Agg==NC_HasAgg ); |
| 101120 | 101028 | assert( EP_Win==NC_HasWin ); |
| 101121 | 101029 | testcase( pNC->ncFlags & NC_HasAgg ); |
| 101122 | 101030 | testcase( pNC->ncFlags & NC_HasWin ); |
| 101123 | | - if( pNC->ncFlags & (NC_HasAgg|NC_MinMaxAgg|NC_HasWin) ){ |
| 101031 | + if( pNC->ncFlags & (NC_HasAgg|NC_MinMaxAgg|NC_HasWin|NC_OrderAgg) ){ |
| 101124 | 101032 | ExprSetProperty(pExpr, pNC->ncFlags & (NC_HasAgg|NC_HasWin) ); |
| 101125 | | - savedHasAgg |= pNC->ncFlags & (NC_HasAgg|NC_MinMaxAgg|NC_HasWin); |
| 101126 | | - pNC->ncFlags &= ~(NC_HasAgg|NC_MinMaxAgg|NC_HasWin); |
| 101033 | + savedHasAgg |= pNC->ncFlags & |
| 101034 | + (NC_HasAgg|NC_MinMaxAgg|NC_HasWin|NC_OrderAgg); |
| 101035 | + pNC->ncFlags &= ~(NC_HasAgg|NC_MinMaxAgg|NC_HasWin|NC_OrderAgg); |
| 101127 | 101036 | } |
| 101128 | 101037 | if( w.pParse->nErr>0 ) return WRC_Abort; |
| 101129 | 101038 | } |
| 101130 | 101039 | pNC->ncFlags |= savedHasAgg; |
| 101131 | 101040 | return WRC_Continue; |
| | @@ -101285,10 +101194,12 @@ |
| 101285 | 101194 | return sqlite3AffinityType(pExpr->u.zToken, 0); |
| 101286 | 101195 | } |
| 101287 | 101196 | #endif |
| 101288 | 101197 | if( op==TK_SELECT_COLUMN ){ |
| 101289 | 101198 | assert( pExpr->pLeft->flags&EP_xIsSelect ); |
| 101199 | + assert( pExpr->iColumn < pExpr->iTable ); |
| 101200 | + assert( pExpr->iTable==pExpr->pLeft->x.pSelect->pEList->nExpr ); |
| 101290 | 101201 | return sqlite3ExprAffinity( |
| 101291 | 101202 | pExpr->pLeft->x.pSelect->pEList->a[pExpr->iColumn].pExpr |
| 101292 | 101203 | ); |
| 101293 | 101204 | } |
| 101294 | 101205 | if( op==TK_VECTOR ){ |
| | @@ -101385,11 +101296,11 @@ |
| 101385 | 101296 | ){ |
| 101386 | 101297 | /* op==TK_REGISTER && p->y.pTab!=0 happens when pExpr was originally |
| 101387 | 101298 | ** a TK_COLUMN but was previously evaluated and cached in a register */ |
| 101388 | 101299 | int j = p->iColumn; |
| 101389 | 101300 | if( j>=0 ){ |
| 101390 | | - const char *zColl = p->y.pTab->aCol[j].zColl; |
| 101301 | + const char *zColl = sqlite3ColumnColl(&p->y.pTab->aCol[j]); |
| 101391 | 101302 | pColl = sqlite3FindCollSeq(db, ENC(db), zColl, 0); |
| 101392 | 101303 | } |
| 101393 | 101304 | break; |
| 101394 | 101305 | } |
| 101395 | 101306 | if( op==TK_CAST || op==TK_UPLUS ){ |
| | @@ -101695,11 +101606,12 @@ |
| 101695 | 101606 | ** of the returned TK_SELECT_COLUMN Expr object. |
| 101696 | 101607 | */ |
| 101697 | 101608 | SQLITE_PRIVATE Expr *sqlite3ExprForVectorField( |
| 101698 | 101609 | Parse *pParse, /* Parsing context */ |
| 101699 | 101610 | Expr *pVector, /* The vector. List of expressions or a sub-SELECT */ |
| 101700 | | - int iField /* Which column of the vector to return */ |
| 101611 | + int iField, /* Which column of the vector to return */ |
| 101612 | + int nField /* Total number of columns in the vector */ |
| 101701 | 101613 | ){ |
| 101702 | 101614 | Expr *pRet; |
| 101703 | 101615 | if( pVector->op==TK_SELECT ){ |
| 101704 | 101616 | assert( pVector->flags & EP_xIsSelect ); |
| 101705 | 101617 | /* The TK_SELECT_COLUMN Expr node: |
| | @@ -101718,14 +101630,14 @@ |
| 101718 | 101630 | ** with the same pLeft pointer to the pVector, but only one of them |
| 101719 | 101631 | ** will own the pVector. |
| 101720 | 101632 | */ |
| 101721 | 101633 | pRet = sqlite3PExpr(pParse, TK_SELECT_COLUMN, 0, 0); |
| 101722 | 101634 | if( pRet ){ |
| 101635 | + pRet->iTable = nField; |
| 101723 | 101636 | pRet->iColumn = iField; |
| 101724 | 101637 | pRet->pLeft = pVector; |
| 101725 | 101638 | } |
| 101726 | | - assert( pRet==0 || pRet->iTable==0 ); |
| 101727 | 101639 | }else{ |
| 101728 | 101640 | if( pVector->op==TK_VECTOR ) pVector = pVector->x.pList->a[iField].pExpr; |
| 101729 | 101641 | pRet = sqlite3ExprDup(pParse->db, pVector, 0); |
| 101730 | 101642 | sqlite3RenameTokenRemap(pParse, pRet, pVector); |
| 101731 | 101643 | } |
| | @@ -102156,10 +102068,60 @@ |
| 102156 | 102068 | assert( pParse->db->mallocFailed ); |
| 102157 | 102069 | sqlite3SelectDelete(pParse->db, pSelect); |
| 102158 | 102070 | } |
| 102159 | 102071 | } |
| 102160 | 102072 | |
| 102073 | +/* |
| 102074 | +** Expression list pEList is a list of vector values. This function |
| 102075 | +** converts the contents of pEList to a VALUES(...) Select statement |
| 102076 | +** returning 1 row for each element of the list. For example, the |
| 102077 | +** expression list: |
| 102078 | +** |
| 102079 | +** ( (1,2), (3,4) (5,6) ) |
| 102080 | +** |
| 102081 | +** is translated to the equivalent of: |
| 102082 | +** |
| 102083 | +** VALUES(1,2), (3,4), (5,6) |
| 102084 | +** |
| 102085 | +** Each of the vector values in pEList must contain exactly nElem terms. |
| 102086 | +** If a list element that is not a vector or does not contain nElem terms, |
| 102087 | +** an error message is left in pParse. |
| 102088 | +** |
| 102089 | +** This is used as part of processing IN(...) expressions with a list |
| 102090 | +** of vectors on the RHS. e.g. "... IN ((1,2), (3,4), (5,6))". |
| 102091 | +*/ |
| 102092 | +SQLITE_PRIVATE Select *sqlite3ExprListToValues(Parse *pParse, int nElem, ExprList *pEList){ |
| 102093 | + int ii; |
| 102094 | + Select *pRet = 0; |
| 102095 | + assert( nElem>1 ); |
| 102096 | + for(ii=0; ii<pEList->nExpr; ii++){ |
| 102097 | + Select *pSel; |
| 102098 | + Expr *pExpr = pEList->a[ii].pExpr; |
| 102099 | + int nExprElem = (pExpr->op==TK_VECTOR ? pExpr->x.pList->nExpr : 1); |
| 102100 | + if( nExprElem!=nElem ){ |
| 102101 | + sqlite3ErrorMsg(pParse, "IN(...) element has %d term%s - expected %d", |
| 102102 | + nExprElem, nExprElem>1?"s":"", nElem |
| 102103 | + ); |
| 102104 | + break; |
| 102105 | + } |
| 102106 | + pSel = sqlite3SelectNew(pParse, pExpr->x.pList, 0, 0, 0, 0, 0, SF_Values,0); |
| 102107 | + pExpr->x.pList = 0; |
| 102108 | + if( pSel ){ |
| 102109 | + if( pRet ){ |
| 102110 | + pSel->op = TK_ALL; |
| 102111 | + pSel->pPrior = pRet; |
| 102112 | + } |
| 102113 | + pRet = pSel; |
| 102114 | + } |
| 102115 | + } |
| 102116 | + |
| 102117 | + if( pRet && pRet->pPrior ){ |
| 102118 | + pRet->selFlags |= SF_MultiValue; |
| 102119 | + } |
| 102120 | + sqlite3ExprListDelete(pParse->db, pEList); |
| 102121 | + return pRet; |
| 102122 | +} |
| 102161 | 102123 | |
| 102162 | 102124 | /* |
| 102163 | 102125 | ** Join two expressions using an AND operator. If either expression is |
| 102164 | 102126 | ** NULL, then just return the other expression. |
| 102165 | 102127 | ** |
| | @@ -102200,11 +102162,14 @@ |
| 102200 | 102162 | pNew = sqlite3ExprAlloc(db, TK_FUNCTION, pToken, 1); |
| 102201 | 102163 | if( pNew==0 ){ |
| 102202 | 102164 | sqlite3ExprListDelete(db, pList); /* Avoid memory leak when malloc fails */ |
| 102203 | 102165 | return 0; |
| 102204 | 102166 | } |
| 102205 | | - if( pList && pList->nExpr > pParse->db->aLimit[SQLITE_LIMIT_FUNCTION_ARG] ){ |
| 102167 | + if( pList |
| 102168 | + && pList->nExpr > pParse->db->aLimit[SQLITE_LIMIT_FUNCTION_ARG] |
| 102169 | + && !pParse->nested |
| 102170 | + ){ |
| 102206 | 102171 | sqlite3ErrorMsg(pParse, "too many arguments on function %T", pToken); |
| 102207 | 102172 | } |
| 102208 | 102173 | pNew->x.pList = pList; |
| 102209 | 102174 | ExprSetProperty(pNew, EP_HasFunc); |
| 102210 | 102175 | assert( !ExprHasProperty(pNew, EP_xIsSelect) ); |
| | @@ -102608,11 +102573,10 @@ |
| 102608 | 102573 | } |
| 102609 | 102574 | }else{ |
| 102610 | 102575 | if( !ExprHasProperty(p, EP_TokenOnly|EP_Leaf) ){ |
| 102611 | 102576 | if( pNew->op==TK_SELECT_COLUMN ){ |
| 102612 | 102577 | pNew->pLeft = p->pLeft; |
| 102613 | | - assert( p->iColumn==0 || p->pRight==0 ); |
| 102614 | 102578 | assert( p->pRight==0 || p->pRight==p->pLeft |
| 102615 | 102579 | || ExprHasProperty(p->pLeft, EP_Subquery) ); |
| 102616 | 102580 | }else{ |
| 102617 | 102581 | pNew->pLeft = sqlite3ExprDup(db, p->pLeft, 0); |
| 102618 | 102582 | } |
| | @@ -102706,11 +102670,12 @@ |
| 102706 | 102670 | } |
| 102707 | 102671 | SQLITE_PRIVATE ExprList *sqlite3ExprListDup(sqlite3 *db, ExprList *p, int flags){ |
| 102708 | 102672 | ExprList *pNew; |
| 102709 | 102673 | struct ExprList_item *pItem, *pOldItem; |
| 102710 | 102674 | int i; |
| 102711 | | - Expr *pPriorSelectCol = 0; |
| 102675 | + Expr *pPriorSelectColOld = 0; |
| 102676 | + Expr *pPriorSelectColNew = 0; |
| 102712 | 102677 | assert( db!=0 ); |
| 102713 | 102678 | if( p==0 ) return 0; |
| 102714 | 102679 | pNew = sqlite3DbMallocRawNN(db, sqlite3DbMallocSize(db, p)); |
| 102715 | 102680 | if( pNew==0 ) return 0; |
| 102716 | 102681 | pNew->nExpr = p->nExpr; |
| | @@ -102723,21 +102688,21 @@ |
| 102723 | 102688 | pItem->pExpr = sqlite3ExprDup(db, pOldExpr, flags); |
| 102724 | 102689 | if( pOldExpr |
| 102725 | 102690 | && pOldExpr->op==TK_SELECT_COLUMN |
| 102726 | 102691 | && (pNewExpr = pItem->pExpr)!=0 |
| 102727 | 102692 | ){ |
| 102728 | | - assert( pNewExpr->iColumn==0 || i>0 ); |
| 102729 | | - if( pNewExpr->iColumn==0 ){ |
| 102730 | | - assert( pOldExpr->pLeft==pOldExpr->pRight |
| 102731 | | - || ExprHasProperty(pOldExpr->pLeft, EP_Subquery) ); |
| 102732 | | - pPriorSelectCol = pNewExpr->pLeft = pNewExpr->pRight; |
| 102693 | + if( pNewExpr->pRight ){ |
| 102694 | + pPriorSelectColOld = pOldExpr->pRight; |
| 102695 | + pPriorSelectColNew = pNewExpr->pRight; |
| 102696 | + pNewExpr->pLeft = pNewExpr->pRight; |
| 102733 | 102697 | }else{ |
| 102734 | | - assert( i>0 ); |
| 102735 | | - assert( pItem[-1].pExpr!=0 ); |
| 102736 | | - assert( pNewExpr->iColumn==pItem[-1].pExpr->iColumn+1 ); |
| 102737 | | - assert( pPriorSelectCol==pItem[-1].pExpr->pLeft ); |
| 102738 | | - pNewExpr->pLeft = pPriorSelectCol; |
| 102698 | + if( pOldExpr->pLeft!=pPriorSelectColOld ){ |
| 102699 | + pPriorSelectColOld = pOldExpr->pLeft; |
| 102700 | + pPriorSelectColNew = sqlite3ExprDup(db, pPriorSelectColOld, flags); |
| 102701 | + pNewExpr->pRight = pPriorSelectColNew; |
| 102702 | + } |
| 102703 | + pNewExpr->pLeft = pPriorSelectColNew; |
| 102739 | 102704 | } |
| 102740 | 102705 | } |
| 102741 | 102706 | pItem->zEName = sqlite3DbStrDup(db, pOldItem->zEName); |
| 102742 | 102707 | pItem->sortFlags = pOldItem->sortFlags; |
| 102743 | 102708 | pItem->eEName = pOldItem->eEName; |
| | @@ -102992,15 +102957,13 @@ |
| 102992 | 102957 | pColumns->nId, n); |
| 102993 | 102958 | goto vector_append_error; |
| 102994 | 102959 | } |
| 102995 | 102960 | |
| 102996 | 102961 | for(i=0; i<pColumns->nId; i++){ |
| 102997 | | - Expr *pSubExpr = sqlite3ExprForVectorField(pParse, pExpr, i); |
| 102962 | + Expr *pSubExpr = sqlite3ExprForVectorField(pParse, pExpr, i, pColumns->nId); |
| 102998 | 102963 | assert( pSubExpr!=0 || db->mallocFailed ); |
| 102999 | | - assert( pSubExpr==0 || pSubExpr->iTable==0 ); |
| 103000 | 102964 | if( pSubExpr==0 ) continue; |
| 103001 | | - pSubExpr->iTable = pColumns->nId; |
| 103002 | 102965 | pList = sqlite3ExprListAppend(pParse, pList, pSubExpr); |
| 103003 | 102966 | if( pList ){ |
| 103004 | 102967 | assert( pList->nExpr==iFirst+i+1 ); |
| 103005 | 102968 | pList->a[pList->nExpr-1].zEName = pColumns->a[i].zName; |
| 103006 | 102969 | pColumns->a[i].zName = 0; |
| | @@ -103673,11 +103636,11 @@ |
| 103673 | 103636 | assert( pSrc!=0 ); |
| 103674 | 103637 | if( pSrc->nSrc!=1 ) return 0; /* Single term in FROM clause */ |
| 103675 | 103638 | if( pSrc->a[0].pSelect ) return 0; /* FROM is not a subquery or view */ |
| 103676 | 103639 | pTab = pSrc->a[0].pTab; |
| 103677 | 103640 | assert( pTab!=0 ); |
| 103678 | | - assert( pTab->pSelect==0 ); /* FROM clause is not a view */ |
| 103641 | + assert( !IsView(pTab) ); /* FROM clause is not a view */ |
| 103679 | 103642 | if( IsVirtual(pTab) ) return 0; /* FROM clause not a virtual table */ |
| 103680 | 103643 | pEList = p->pEList; |
| 103681 | 103644 | assert( pEList!=0 ); |
| 103682 | 103645 | /* All SELECT results must be columns. */ |
| 103683 | 103646 | for(i=0; i<pEList->nExpr; i++){ |
| | @@ -104803,13 +104766,14 @@ |
| 104803 | 104766 | /* |
| 104804 | 104767 | ** Generate code that will compute the value of generated column pCol |
| 104805 | 104768 | ** and store the result in register regOut |
| 104806 | 104769 | */ |
| 104807 | 104770 | SQLITE_PRIVATE void sqlite3ExprCodeGeneratedColumn( |
| 104808 | | - Parse *pParse, |
| 104809 | | - Column *pCol, |
| 104810 | | - int regOut |
| 104771 | + Parse *pParse, /* Parsing context */ |
| 104772 | + Table *pTab, /* Table containing the generated column */ |
| 104773 | + Column *pCol, /* The generated column */ |
| 104774 | + int regOut /* Put the result in this register */ |
| 104811 | 104775 | ){ |
| 104812 | 104776 | int iAddr; |
| 104813 | 104777 | Vdbe *v = pParse->pVdbe; |
| 104814 | 104778 | assert( v!=0 ); |
| 104815 | 104779 | assert( pParse->iSelfTab!=0 ); |
| | @@ -104816,11 +104780,11 @@ |
| 104816 | 104780 | if( pParse->iSelfTab>0 ){ |
| 104817 | 104781 | iAddr = sqlite3VdbeAddOp3(v, OP_IfNullRow, pParse->iSelfTab-1, 0, regOut); |
| 104818 | 104782 | }else{ |
| 104819 | 104783 | iAddr = 0; |
| 104820 | 104784 | } |
| 104821 | | - sqlite3ExprCodeCopy(pParse, pCol->pDflt, regOut); |
| 104785 | + sqlite3ExprCodeCopy(pParse, sqlite3ColumnExpr(pTab,pCol), regOut); |
| 104822 | 104786 | if( pCol->affinity>=SQLITE_AFF_TEXT ){ |
| 104823 | 104787 | sqlite3VdbeAddOp4(v, OP_Affinity, regOut, 1, 0, &pCol->affinity, 1); |
| 104824 | 104788 | } |
| 104825 | 104789 | if( iAddr ) sqlite3VdbeJumpHere(v, iAddr); |
| 104826 | 104790 | } |
| | @@ -104852,16 +104816,17 @@ |
| 104852 | 104816 | x = iCol; |
| 104853 | 104817 | #ifndef SQLITE_OMIT_GENERATED_COLUMNS |
| 104854 | 104818 | }else if( (pCol = &pTab->aCol[iCol])->colFlags & COLFLAG_VIRTUAL ){ |
| 104855 | 104819 | Parse *pParse = sqlite3VdbeParser(v); |
| 104856 | 104820 | if( pCol->colFlags & COLFLAG_BUSY ){ |
| 104857 | | - sqlite3ErrorMsg(pParse, "generated column loop on \"%s\"", pCol->zName); |
| 104821 | + sqlite3ErrorMsg(pParse, "generated column loop on \"%s\"", |
| 104822 | + pCol->zCnName); |
| 104858 | 104823 | }else{ |
| 104859 | 104824 | int savedSelfTab = pParse->iSelfTab; |
| 104860 | 104825 | pCol->colFlags |= COLFLAG_BUSY; |
| 104861 | 104826 | pParse->iSelfTab = iTabCur+1; |
| 104862 | | - sqlite3ExprCodeGeneratedColumn(pParse, pCol, regOut); |
| 104827 | + sqlite3ExprCodeGeneratedColumn(pParse, pTab, pCol, regOut); |
| 104863 | 104828 | pParse->iSelfTab = savedSelfTab; |
| 104864 | 104829 | pCol->colFlags &= ~COLFLAG_BUSY; |
| 104865 | 104830 | } |
| 104866 | 104831 | return; |
| 104867 | 104832 | #endif |
| | @@ -105125,11 +105090,12 @@ |
| 105125 | 105090 | sqlite3VdbeAddOp3(v, OP_Column, pAggInfo->sortingIdxPTab, |
| 105126 | 105091 | pCol->iSorterColumn, target); |
| 105127 | 105092 | if( pCol->iColumn<0 ){ |
| 105128 | 105093 | VdbeComment((v,"%s.rowid",pTab->zName)); |
| 105129 | 105094 | }else{ |
| 105130 | | - VdbeComment((v,"%s.%s",pTab->zName,pTab->aCol[pCol->iColumn].zName)); |
| 105095 | + VdbeComment((v,"%s.%s", |
| 105096 | + pTab->zName, pTab->aCol[pCol->iColumn].zCnName)); |
| 105131 | 105097 | if( pTab->aCol[pCol->iColumn].affinity==SQLITE_AFF_REAL ){ |
| 105132 | 105098 | sqlite3VdbeAddOp1(v, OP_RealAffinity, target); |
| 105133 | 105099 | } |
| 105134 | 105100 | } |
| 105135 | 105101 | return target; |
| | @@ -105186,16 +105152,16 @@ |
| 105186 | 105152 | iSrc = sqlite3TableColumnToStorage(pTab, iCol) - pParse->iSelfTab; |
| 105187 | 105153 | #ifndef SQLITE_OMIT_GENERATED_COLUMNS |
| 105188 | 105154 | if( pCol->colFlags & COLFLAG_GENERATED ){ |
| 105189 | 105155 | if( pCol->colFlags & COLFLAG_BUSY ){ |
| 105190 | 105156 | sqlite3ErrorMsg(pParse, "generated column loop on \"%s\"", |
| 105191 | | - pCol->zName); |
| 105157 | + pCol->zCnName); |
| 105192 | 105158 | return 0; |
| 105193 | 105159 | } |
| 105194 | 105160 | pCol->colFlags |= COLFLAG_BUSY; |
| 105195 | 105161 | if( pCol->colFlags & COLFLAG_NOTAVAIL ){ |
| 105196 | | - sqlite3ExprCodeGeneratedColumn(pParse, pCol, iSrc); |
| 105162 | + sqlite3ExprCodeGeneratedColumn(pParse, pTab, pCol, iSrc); |
| 105197 | 105163 | } |
| 105198 | 105164 | pCol->colFlags &= ~(COLFLAG_BUSY|COLFLAG_NOTAVAIL); |
| 105199 | 105165 | return iSrc; |
| 105200 | 105166 | }else |
| 105201 | 105167 | #endif /* SQLITE_OMIT_GENERATED_COLUMNS */ |
| | @@ -105586,15 +105552,13 @@ |
| 105586 | 105552 | case TK_SELECT_COLUMN: { |
| 105587 | 105553 | int n; |
| 105588 | 105554 | if( pExpr->pLeft->iTable==0 ){ |
| 105589 | 105555 | pExpr->pLeft->iTable = sqlite3CodeSubselect(pParse, pExpr->pLeft); |
| 105590 | 105556 | } |
| 105591 | | - assert( pExpr->iTable==0 || pExpr->pLeft->op==TK_SELECT |
| 105592 | | - || pExpr->pLeft->op==TK_ERROR ); |
| 105593 | | - if( pExpr->iTable!=0 |
| 105594 | | - && pExpr->iTable!=(n = sqlite3ExprVectorSize(pExpr->pLeft)) |
| 105595 | | - ){ |
| 105557 | + assert( pExpr->pLeft->op==TK_SELECT || pExpr->pLeft->op==TK_ERROR ); |
| 105558 | + n = sqlite3ExprVectorSize(pExpr->pLeft); |
| 105559 | + if( pExpr->iTable!=n ){ |
| 105596 | 105560 | sqlite3ErrorMsg(pParse, "%d columns assigned %d values", |
| 105597 | 105561 | pExpr->iTable, n); |
| 105598 | 105562 | } |
| 105599 | 105563 | return pExpr->pLeft->iTable + pExpr->iColumn; |
| 105600 | 105564 | } |
| | @@ -105671,11 +105635,11 @@ |
| 105671 | 105635 | assert( p1>=0 && p1<(pTab->nCol*2+2) ); |
| 105672 | 105636 | |
| 105673 | 105637 | sqlite3VdbeAddOp2(v, OP_Param, p1, target); |
| 105674 | 105638 | VdbeComment((v, "r[%d]=%s.%s", target, |
| 105675 | 105639 | (pExpr->iTable ? "new" : "old"), |
| 105676 | | - (pExpr->iColumn<0 ? "rowid" : pExpr->y.pTab->aCol[iCol].zName) |
| 105640 | + (pExpr->iColumn<0 ? "rowid" : pExpr->y.pTab->aCol[iCol].zCnName) |
| 105677 | 105641 | )); |
| 105678 | 105642 | |
| 105679 | 105643 | #ifndef SQLITE_OMIT_FLOATING_POINT |
| 105680 | 105644 | /* If the column has REAL affinity, it may currently be stored as an |
| 105681 | 105645 | ** integer. Use OP_RealAffinity to make sure it is really real. |
| | @@ -106843,13 +106807,13 @@ |
| 106843 | 106807 | testcase( pExpr->op==TK_LE ); |
| 106844 | 106808 | testcase( pExpr->op==TK_GT ); |
| 106845 | 106809 | testcase( pExpr->op==TK_GE ); |
| 106846 | 106810 | /* The y.pTab=0 assignment in wherecode.c always happens after the |
| 106847 | 106811 | ** impliesNotNullRow() test */ |
| 106848 | | - if( (pLeft->op==TK_COLUMN && ALWAYS(pLeft->y.pTab!=0) |
| 106812 | + if( (pLeft->op==TK_COLUMN && pLeft->y.pTab!=0 |
| 106849 | 106813 | && IsVirtual(pLeft->y.pTab)) |
| 106850 | | - || (pRight->op==TK_COLUMN && ALWAYS(pRight->y.pTab!=0) |
| 106814 | + || (pRight->op==TK_COLUMN && pRight->y.pTab!=0 |
| 106851 | 106815 | && IsVirtual(pRight->y.pTab)) |
| 106852 | 106816 | ){ |
| 106853 | 106817 | return WRC_Prune; |
| 106854 | 106818 | } |
| 106855 | 106819 | /* no break */ deliberate_fall_through |
| | @@ -107524,22 +107488,19 @@ |
| 107524 | 107488 | sqlite3 *db = pParse->db; /* Database connection */ |
| 107525 | 107489 | int nTabName; /* Number of UTF-8 characters in zTabName */ |
| 107526 | 107490 | const char *zTabName; /* Original name of the table */ |
| 107527 | 107491 | Vdbe *v; |
| 107528 | 107492 | VTable *pVTab = 0; /* Non-zero if this is a v-tab with an xRename() */ |
| 107529 | | - u32 savedDbFlags; /* Saved value of db->mDbFlags */ |
| 107530 | 107493 | |
| 107531 | | - savedDbFlags = db->mDbFlags; |
| 107532 | 107494 | if( NEVER(db->mallocFailed) ) goto exit_rename_table; |
| 107533 | 107495 | assert( pSrc->nSrc==1 ); |
| 107534 | 107496 | assert( sqlite3BtreeHoldsAllMutexes(pParse->db) ); |
| 107535 | 107497 | |
| 107536 | 107498 | pTab = sqlite3LocateTableItem(pParse, 0, &pSrc->a[0]); |
| 107537 | 107499 | if( !pTab ) goto exit_rename_table; |
| 107538 | 107500 | iDb = sqlite3SchemaToIndex(pParse->db, pTab->pSchema); |
| 107539 | 107501 | zDb = db->aDb[iDb].zDbSName; |
| 107540 | | - db->mDbFlags |= DBFLAG_PreferBuiltin; |
| 107541 | 107502 | |
| 107542 | 107503 | /* Get a NULL terminated version of the new table name. */ |
| 107543 | 107504 | zName = sqlite3NameFromToken(db, pName); |
| 107544 | 107505 | if( !zName ) goto exit_rename_table; |
| 107545 | 107506 | |
| | @@ -107564,11 +107525,11 @@ |
| 107564 | 107525 | if( SQLITE_OK!=sqlite3CheckObjectName(pParse,zName,"table",zName) ){ |
| 107565 | 107526 | goto exit_rename_table; |
| 107566 | 107527 | } |
| 107567 | 107528 | |
| 107568 | 107529 | #ifndef SQLITE_OMIT_VIEW |
| 107569 | | - if( pTab->pSelect ){ |
| 107530 | + if( IsView(pTab) ){ |
| 107570 | 107531 | sqlite3ErrorMsg(pParse, "view %s may not be altered", pTab->zName); |
| 107571 | 107532 | goto exit_rename_table; |
| 107572 | 107533 | } |
| 107573 | 107534 | #endif |
| 107574 | 107535 | |
| | @@ -107676,11 +107637,10 @@ |
| 107676 | 107637 | renameTestSchema(pParse, zDb, iDb==1, "after rename", 0); |
| 107677 | 107638 | |
| 107678 | 107639 | exit_rename_table: |
| 107679 | 107640 | sqlite3SrcListDelete(db, pSrc); |
| 107680 | 107641 | sqlite3DbFree(db, zName); |
| 107681 | | - db->mDbFlags = savedDbFlags; |
| 107682 | 107642 | } |
| 107683 | 107643 | |
| 107684 | 107644 | /* |
| 107685 | 107645 | ** Write code that will raise an error if the table described by |
| 107686 | 107646 | ** zDb and zTab is not empty. |
| | @@ -107726,11 +107686,11 @@ |
| 107726 | 107686 | assert( sqlite3BtreeHoldsAllMutexes(db) ); |
| 107727 | 107687 | iDb = sqlite3SchemaToIndex(db, pNew->pSchema); |
| 107728 | 107688 | zDb = db->aDb[iDb].zDbSName; |
| 107729 | 107689 | zTab = &pNew->zName[16]; /* Skip the "sqlite_altertab_" prefix on the name */ |
| 107730 | 107690 | pCol = &pNew->aCol[pNew->nCol-1]; |
| 107731 | | - pDflt = pCol->pDflt; |
| 107691 | + pDflt = sqlite3ColumnExpr(pNew, pCol); |
| 107732 | 107692 | pTab = sqlite3FindTable(db, zTab, zDb); |
| 107733 | 107693 | assert( pTab ); |
| 107734 | 107694 | |
| 107735 | 107695 | #ifndef SQLITE_OMIT_AUTHORIZATION |
| 107736 | 107696 | /* Invoke the authorization callback. */ |
| | @@ -107760,11 +107720,11 @@ |
| 107760 | 107720 | */ |
| 107761 | 107721 | assert( pDflt==0 || pDflt->op==TK_SPAN ); |
| 107762 | 107722 | if( pDflt && pDflt->pLeft->op==TK_NULL ){ |
| 107763 | 107723 | pDflt = 0; |
| 107764 | 107724 | } |
| 107765 | | - if( (db->flags&SQLITE_ForeignKeys) && pNew->pFKey && pDflt ){ |
| 107725 | + if( (db->flags&SQLITE_ForeignKeys) && pNew->u.tab.pFKey && pDflt ){ |
| 107766 | 107726 | sqlite3ErrorIfNotEmpty(pParse, zDb, zTab, |
| 107767 | 107727 | "Cannot add a REFERENCES column with non-NULL default value"); |
| 107768 | 107728 | } |
| 107769 | 107729 | if( pCol->notNull && !pDflt ){ |
| 107770 | 107730 | sqlite3ErrorIfNotEmpty(pParse, zDb, zTab, |
| | @@ -107797,47 +107757,60 @@ |
| 107797 | 107757 | |
| 107798 | 107758 | /* Modify the CREATE TABLE statement. */ |
| 107799 | 107759 | zCol = sqlite3DbStrNDup(db, (char*)pColDef->z, pColDef->n); |
| 107800 | 107760 | if( zCol ){ |
| 107801 | 107761 | char *zEnd = &zCol[pColDef->n-1]; |
| 107802 | | - u32 savedDbFlags = db->mDbFlags; |
| 107803 | 107762 | while( zEnd>zCol && (*zEnd==';' || sqlite3Isspace(*zEnd)) ){ |
| 107804 | 107763 | *zEnd-- = '\0'; |
| 107805 | 107764 | } |
| 107806 | | - db->mDbFlags |= DBFLAG_PreferBuiltin; |
| 107807 | 107765 | /* substr() operations on characters, but addColOffset is in bytes. So we |
| 107808 | 107766 | ** have to use printf() to translate between these units: */ |
| 107767 | + assert( !IsVirtual(pTab) ); |
| 107809 | 107768 | sqlite3NestedParse(pParse, |
| 107810 | 107769 | "UPDATE \"%w\"." DFLT_SCHEMA_TABLE " SET " |
| 107811 | 107770 | "sql = printf('%%.%ds, ',sql) || %Q" |
| 107812 | 107771 | " || substr(sql,1+length(printf('%%.%ds',sql))) " |
| 107813 | 107772 | "WHERE type = 'table' AND name = %Q", |
| 107814 | | - zDb, pNew->addColOffset, zCol, pNew->addColOffset, |
| 107773 | + zDb, pNew->u.tab.addColOffset, zCol, pNew->u.tab.addColOffset, |
| 107815 | 107774 | zTab |
| 107816 | 107775 | ); |
| 107817 | 107776 | sqlite3DbFree(db, zCol); |
| 107818 | | - db->mDbFlags = savedDbFlags; |
| 107819 | 107777 | } |
| 107820 | 107778 | |
| 107821 | | - /* Make sure the schema version is at least 3. But do not upgrade |
| 107822 | | - ** from less than 3 to 4, as that will corrupt any preexisting DESC |
| 107823 | | - ** index. |
| 107824 | | - */ |
| 107825 | 107779 | v = sqlite3GetVdbe(pParse); |
| 107826 | 107780 | if( v ){ |
| 107781 | + /* Make sure the schema version is at least 3. But do not upgrade |
| 107782 | + ** from less than 3 to 4, as that will corrupt any preexisting DESC |
| 107783 | + ** index. |
| 107784 | + */ |
| 107827 | 107785 | r1 = sqlite3GetTempReg(pParse); |
| 107828 | 107786 | sqlite3VdbeAddOp3(v, OP_ReadCookie, iDb, r1, BTREE_FILE_FORMAT); |
| 107829 | 107787 | sqlite3VdbeUsesBtree(v, iDb); |
| 107830 | 107788 | sqlite3VdbeAddOp2(v, OP_AddImm, r1, -2); |
| 107831 | 107789 | sqlite3VdbeAddOp2(v, OP_IfPos, r1, sqlite3VdbeCurrentAddr(v)+2); |
| 107832 | 107790 | VdbeCoverage(v); |
| 107833 | 107791 | sqlite3VdbeAddOp3(v, OP_SetCookie, iDb, BTREE_FILE_FORMAT, 3); |
| 107834 | 107792 | sqlite3ReleaseTempReg(pParse, r1); |
| 107793 | + |
| 107794 | + /* Reload the table definition */ |
| 107795 | + renameReloadSchema(pParse, iDb, INITFLAG_AlterRename); |
| 107796 | + |
| 107797 | + /* Verify that constraints are still satisfied */ |
| 107798 | + if( pNew->pCheck!=0 |
| 107799 | + || (pCol->notNull && (pCol->colFlags & COLFLAG_GENERATED)!=0) |
| 107800 | + ){ |
| 107801 | + sqlite3NestedParse(pParse, |
| 107802 | + "SELECT CASE WHEN quick_check GLOB 'CHECK*'" |
| 107803 | + " THEN raise(ABORT,'CHECK constraint failed')" |
| 107804 | + " ELSE raise(ABORT,'NOT NULL constraint failed')" |
| 107805 | + " END" |
| 107806 | + " FROM pragma_quick_check(\"%w\",\"%w\")" |
| 107807 | + " WHERE quick_check GLOB 'CHECK*' OR quick_check GLOB 'NULL*'", |
| 107808 | + zTab, zDb |
| 107809 | + ); |
| 107810 | + } |
| 107835 | 107811 | } |
| 107836 | | - |
| 107837 | | - /* Reload the table definition */ |
| 107838 | | - renameReloadSchema(pParse, iDb, INITFLAG_AlterRename); |
| 107839 | 107812 | } |
| 107840 | 107813 | |
| 107841 | 107814 | /* |
| 107842 | 107815 | ** This function is called by the parser after the table-name in |
| 107843 | 107816 | ** an "ALTER TABLE <table-name> ADD" statement is parsed. Argument |
| | @@ -107874,20 +107847,20 @@ |
| 107874 | 107847 | goto exit_begin_add_column; |
| 107875 | 107848 | } |
| 107876 | 107849 | #endif |
| 107877 | 107850 | |
| 107878 | 107851 | /* Make sure this is not an attempt to ALTER a view. */ |
| 107879 | | - if( pTab->pSelect ){ |
| 107852 | + if( IsView(pTab) ){ |
| 107880 | 107853 | sqlite3ErrorMsg(pParse, "Cannot add a column to a view"); |
| 107881 | 107854 | goto exit_begin_add_column; |
| 107882 | 107855 | } |
| 107883 | 107856 | if( SQLITE_OK!=isAlterableTable(pParse, pTab) ){ |
| 107884 | 107857 | goto exit_begin_add_column; |
| 107885 | 107858 | } |
| 107886 | 107859 | |
| 107887 | 107860 | sqlite3MayAbort(pParse); |
| 107888 | | - assert( pTab->addColOffset>0 ); |
| 107861 | + assert( pTab->u.tab.addColOffset>0 ); |
| 107889 | 107862 | iDb = sqlite3SchemaToIndex(db, pTab->pSchema); |
| 107890 | 107863 | |
| 107891 | 107864 | /* Put a copy of the Table struct in Parse.pNewTable for the |
| 107892 | 107865 | ** sqlite3AddColumn() function and friends to modify. But modify |
| 107893 | 107866 | ** the name by adding an "sqlite_altertab_" prefix. By adding this |
| | @@ -107910,17 +107883,17 @@ |
| 107910 | 107883 | goto exit_begin_add_column; |
| 107911 | 107884 | } |
| 107912 | 107885 | memcpy(pNew->aCol, pTab->aCol, sizeof(Column)*pNew->nCol); |
| 107913 | 107886 | for(i=0; i<pNew->nCol; i++){ |
| 107914 | 107887 | Column *pCol = &pNew->aCol[i]; |
| 107915 | | - pCol->zName = sqlite3DbStrDup(db, pCol->zName); |
| 107916 | | - pCol->hName = sqlite3StrIHash(pCol->zName); |
| 107917 | | - pCol->zColl = 0; |
| 107918 | | - pCol->pDflt = 0; |
| 107888 | + pCol->zCnName = sqlite3DbStrDup(db, pCol->zCnName); |
| 107889 | + pCol->hName = sqlite3StrIHash(pCol->zCnName); |
| 107919 | 107890 | } |
| 107891 | + assert( !IsVirtual(pNew) ); |
| 107892 | + pNew->u.tab.pDfltList = sqlite3ExprListDup(db, pTab->u.tab.pDfltList, 0); |
| 107920 | 107893 | pNew->pSchema = db->aDb[iDb].pSchema; |
| 107921 | | - pNew->addColOffset = pTab->addColOffset; |
| 107894 | + pNew->u.tab.addColOffset = pTab->u.tab.addColOffset; |
| 107922 | 107895 | pNew->nTabRef = 1; |
| 107923 | 107896 | |
| 107924 | 107897 | exit_begin_add_column: |
| 107925 | 107898 | sqlite3SrcListDelete(db, pSrc); |
| 107926 | 107899 | return; |
| | @@ -107936,11 +107909,11 @@ |
| 107936 | 107909 | */ |
| 107937 | 107910 | #if !defined(SQLITE_OMIT_VIEW) || !defined(SQLITE_OMIT_VIRTUALTABLE) |
| 107938 | 107911 | static int isRealTable(Parse *pParse, Table *pTab, int bDrop){ |
| 107939 | 107912 | const char *zType = 0; |
| 107940 | 107913 | #ifndef SQLITE_OMIT_VIEW |
| 107941 | | - if( pTab->pSelect ){ |
| 107914 | + if( IsView(pTab) ){ |
| 107942 | 107915 | zType = "view"; |
| 107943 | 107916 | } |
| 107944 | 107917 | #endif |
| 107945 | 107918 | #ifndef SQLITE_OMIT_VIRTUALTABLE |
| 107946 | 107919 | if( IsVirtual(pTab) ){ |
| | @@ -108003,11 +107976,11 @@ |
| 108003 | 107976 | /* Make sure the old name really is a column name in the table to be |
| 108004 | 107977 | ** altered. Set iCol to be the index of the column being renamed */ |
| 108005 | 107978 | zOld = sqlite3NameFromToken(db, pOld); |
| 108006 | 107979 | if( !zOld ) goto exit_rename_column; |
| 108007 | 107980 | for(iCol=0; iCol<pTab->nCol; iCol++){ |
| 108008 | | - if( 0==sqlite3StrICmp(pTab->aCol[iCol].zName, zOld) ) break; |
| 107981 | + if( 0==sqlite3StrICmp(pTab->aCol[iCol].zCnName, zOld) ) break; |
| 108009 | 107982 | } |
| 108010 | 107983 | if( iCol==pTab->nCol ){ |
| 108011 | 107984 | sqlite3ErrorMsg(pParse, "no such column: \"%s\"", zOld); |
| 108012 | 107985 | goto exit_rename_column; |
| 108013 | 107986 | } |
| | @@ -108240,12 +108213,12 @@ |
| 108240 | 108213 | static int renameUnmapSelectCb(Walker *pWalker, Select *p){ |
| 108241 | 108214 | Parse *pParse = pWalker->pParse; |
| 108242 | 108215 | int i; |
| 108243 | 108216 | if( pParse->nErr ) return WRC_Abort; |
| 108244 | 108217 | if( p->selFlags & (SF_View|SF_CopyCte) ){ |
| 108245 | | - testcase( pSelect->selFlags & SF_View ); |
| 108246 | | - testcase( pSelect->selFlags & SF_CopyCte ); |
| 108218 | + testcase( p->selFlags & SF_View ); |
| 108219 | + testcase( p->selFlags & SF_CopyCte ); |
| 108247 | 108220 | return WRC_Prune; |
| 108248 | 108221 | } |
| 108249 | 108222 | if( ALWAYS(p->pEList) ){ |
| 108250 | 108223 | ExprList *pList = p->pEList; |
| 108251 | 108224 | for(i=0; i<pList->nExpr; i++){ |
| | @@ -108352,12 +108325,12 @@ |
| 108352 | 108325 | ** because without a dummy callback, sqlite3WalkExpr() and similar do not |
| 108353 | 108326 | ** descend into sub-select statements. |
| 108354 | 108327 | */ |
| 108355 | 108328 | static int renameColumnSelectCb(Walker *pWalker, Select *p){ |
| 108356 | 108329 | if( p->selFlags & (SF_View|SF_CopyCte) ){ |
| 108357 | | - testcase( pSelect->selFlags & SF_View ); |
| 108358 | | - testcase( pSelect->selFlags & SF_CopyCte ); |
| 108330 | + testcase( p->selFlags & SF_View ); |
| 108331 | + testcase( p->selFlags & SF_CopyCte ); |
| 108359 | 108332 | return WRC_Prune; |
| 108360 | 108333 | } |
| 108361 | 108334 | renameWalkWith(pWalker, p); |
| 108362 | 108335 | return WRC_Continue; |
| 108363 | 108336 | } |
| | @@ -108549,17 +108522,17 @@ |
| 108549 | 108522 | RenameCtx *pRename, /* Rename context */ |
| 108550 | 108523 | const char *zSql, /* SQL statement to edit */ |
| 108551 | 108524 | const char *zNew, /* New token text */ |
| 108552 | 108525 | int bQuote /* True to always quote token */ |
| 108553 | 108526 | ){ |
| 108554 | | - int nNew = sqlite3Strlen30(zNew); |
| 108555 | | - int nSql = sqlite3Strlen30(zSql); |
| 108527 | + i64 nNew = sqlite3Strlen30(zNew); |
| 108528 | + i64 nSql = sqlite3Strlen30(zSql); |
| 108556 | 108529 | sqlite3 *db = sqlite3_context_db_handle(pCtx); |
| 108557 | 108530 | int rc = SQLITE_OK; |
| 108558 | 108531 | char *zQuot = 0; |
| 108559 | 108532 | char *zOut; |
| 108560 | | - int nQuot = 0; |
| 108533 | + i64 nQuot = 0; |
| 108561 | 108534 | char *zBuf1 = 0; |
| 108562 | 108535 | char *zBuf2 = 0; |
| 108563 | 108536 | |
| 108564 | 108537 | if( zNew ){ |
| 108565 | 108538 | /* Set zQuot to point to a buffer containing a quoted copy of the |
| | @@ -108849,11 +108822,11 @@ |
| 108849 | 108822 | pTab = sqlite3FindTable(db, zTable, zDb); |
| 108850 | 108823 | if( pTab==0 || iCol>=pTab->nCol ){ |
| 108851 | 108824 | sqlite3BtreeLeaveAll(db); |
| 108852 | 108825 | return; |
| 108853 | 108826 | } |
| 108854 | | - zOld = pTab->aCol[iCol].zName; |
| 108827 | + zOld = pTab->aCol[iCol].zCnName; |
| 108855 | 108828 | memset(&sCtx, 0, sizeof(sCtx)); |
| 108856 | 108829 | sCtx.iCol = ((iCol==pTab->iPKey) ? -1 : iCol); |
| 108857 | 108830 | |
| 108858 | 108831 | #ifndef SQLITE_OMIT_AUTHORIZATION |
| 108859 | 108832 | db->xAuth = 0; |
| | @@ -108868,30 +108841,29 @@ |
| 108868 | 108841 | sWalker.u.pRename = &sCtx; |
| 108869 | 108842 | |
| 108870 | 108843 | sCtx.pTab = pTab; |
| 108871 | 108844 | if( rc!=SQLITE_OK ) goto renameColumnFunc_done; |
| 108872 | 108845 | if( sParse.pNewTable ){ |
| 108873 | | - Select *pSelect = sParse.pNewTable->pSelect; |
| 108874 | | - if( pSelect ){ |
| 108846 | + if( IsView(sParse.pNewTable) ){ |
| 108847 | + Select *pSelect = sParse.pNewTable->u.view.pSelect; |
| 108875 | 108848 | pSelect->selFlags &= ~SF_View; |
| 108876 | 108849 | sParse.rc = SQLITE_OK; |
| 108877 | 108850 | sqlite3SelectPrep(&sParse, pSelect, 0); |
| 108878 | 108851 | rc = (db->mallocFailed ? SQLITE_NOMEM : sParse.rc); |
| 108879 | 108852 | if( rc==SQLITE_OK ){ |
| 108880 | 108853 | sqlite3WalkSelect(&sWalker, pSelect); |
| 108881 | 108854 | } |
| 108882 | 108855 | if( rc!=SQLITE_OK ) goto renameColumnFunc_done; |
| 108883 | | - }else{ |
| 108856 | + }else if( ALWAYS(IsOrdinaryTable(sParse.pNewTable)) ){ |
| 108884 | 108857 | /* A regular table */ |
| 108885 | 108858 | int bFKOnly = sqlite3_stricmp(zTable, sParse.pNewTable->zName); |
| 108886 | 108859 | FKey *pFKey; |
| 108887 | | - assert( sParse.pNewTable->pSelect==0 ); |
| 108888 | 108860 | sCtx.pTab = sParse.pNewTable; |
| 108889 | 108861 | if( bFKOnly==0 ){ |
| 108890 | 108862 | if( iCol<sParse.pNewTable->nCol ){ |
| 108891 | 108863 | renameTokenFind( |
| 108892 | | - &sParse, &sCtx, (void*)sParse.pNewTable->aCol[iCol].zName |
| 108864 | + &sParse, &sCtx, (void*)sParse.pNewTable->aCol[iCol].zCnName |
| 108893 | 108865 | ); |
| 108894 | 108866 | } |
| 108895 | 108867 | if( sCtx.iCol<0 ){ |
| 108896 | 108868 | renameTokenFind(&sParse, &sCtx, (void*)&sParse.pNewTable->iPKey); |
| 108897 | 108869 | } |
| | @@ -108902,16 +108874,19 @@ |
| 108902 | 108874 | for(pIdx=sParse.pNewIndex; pIdx; pIdx=pIdx->pNext){ |
| 108903 | 108875 | sqlite3WalkExprList(&sWalker, pIdx->aColExpr); |
| 108904 | 108876 | } |
| 108905 | 108877 | #ifndef SQLITE_OMIT_GENERATED_COLUMNS |
| 108906 | 108878 | for(i=0; i<sParse.pNewTable->nCol; i++){ |
| 108907 | | - sqlite3WalkExpr(&sWalker, sParse.pNewTable->aCol[i].pDflt); |
| 108879 | + Expr *pExpr = sqlite3ColumnExpr(sParse.pNewTable, |
| 108880 | + &sParse.pNewTable->aCol[i]); |
| 108881 | + sqlite3WalkExpr(&sWalker, pExpr); |
| 108908 | 108882 | } |
| 108909 | 108883 | #endif |
| 108910 | 108884 | } |
| 108911 | 108885 | |
| 108912 | | - for(pFKey=sParse.pNewTable->pFKey; pFKey; pFKey=pFKey->pNextFrom){ |
| 108886 | + assert( !IsVirtual(sParse.pNewTable) ); |
| 108887 | + for(pFKey=sParse.pNewTable->u.tab.pFKey; pFKey; pFKey=pFKey->pNextFrom){ |
| 108913 | 108888 | for(i=0; i<pFKey->nCol; i++){ |
| 108914 | 108889 | if( bFKOnly==0 && pFKey->aCol[i].iFrom==iCol ){ |
| 108915 | 108890 | renameTokenFind(&sParse, &sCtx, (void*)&pFKey->aCol[i]); |
| 108916 | 108891 | } |
| 108917 | 108892 | if( 0==sqlite3_stricmp(pFKey->zTo, zTable) |
| | @@ -109073,32 +109048,35 @@ |
| 109073 | 109048 | if( rc==SQLITE_OK ){ |
| 109074 | 109049 | int isLegacy = (db->flags & SQLITE_LegacyAlter); |
| 109075 | 109050 | if( sParse.pNewTable ){ |
| 109076 | 109051 | Table *pTab = sParse.pNewTable; |
| 109077 | 109052 | |
| 109078 | | - if( pTab->pSelect ){ |
| 109053 | + if( IsView(pTab) ){ |
| 109079 | 109054 | if( isLegacy==0 ){ |
| 109080 | | - Select *pSelect = pTab->pSelect; |
| 109055 | + Select *pSelect = pTab->u.view.pSelect; |
| 109081 | 109056 | NameContext sNC; |
| 109082 | 109057 | memset(&sNC, 0, sizeof(sNC)); |
| 109083 | 109058 | sNC.pParse = &sParse; |
| 109084 | 109059 | |
| 109085 | 109060 | assert( pSelect->selFlags & SF_View ); |
| 109086 | 109061 | pSelect->selFlags &= ~SF_View; |
| 109087 | | - sqlite3SelectPrep(&sParse, pTab->pSelect, &sNC); |
| 109062 | + sqlite3SelectPrep(&sParse, pTab->u.view.pSelect, &sNC); |
| 109088 | 109063 | if( sParse.nErr ){ |
| 109089 | 109064 | rc = sParse.rc; |
| 109090 | 109065 | }else{ |
| 109091 | | - sqlite3WalkSelect(&sWalker, pTab->pSelect); |
| 109066 | + sqlite3WalkSelect(&sWalker, pTab->u.view.pSelect); |
| 109092 | 109067 | } |
| 109093 | 109068 | } |
| 109094 | 109069 | }else{ |
| 109095 | 109070 | /* Modify any FK definitions to point to the new table. */ |
| 109096 | 109071 | #ifndef SQLITE_OMIT_FOREIGN_KEY |
| 109097 | | - if( isLegacy==0 || (db->flags & SQLITE_ForeignKeys) ){ |
| 109072 | + if( (isLegacy==0 || (db->flags & SQLITE_ForeignKeys)) |
| 109073 | + && !IsVirtual(pTab) |
| 109074 | + ){ |
| 109098 | 109075 | FKey *pFKey; |
| 109099 | | - for(pFKey=pTab->pFKey; pFKey; pFKey=pFKey->pNextFrom){ |
| 109076 | + assert( !IsVirtual(pTab) ); |
| 109077 | + for(pFKey=pTab->u.tab.pFKey; pFKey; pFKey=pFKey->pNextFrom){ |
| 109100 | 109078 | if( sqlite3_stricmp(pFKey->zTo, zOld)==0 ){ |
| 109101 | 109079 | renameTokenFind(&sParse, &sCtx, (void*)pFKey->zTo); |
| 109102 | 109080 | } |
| 109103 | 109081 | } |
| 109104 | 109082 | } |
| | @@ -109234,12 +109212,12 @@ |
| 109234 | 109212 | sWalker.xExprCallback = renameQuotefixExprCb; |
| 109235 | 109213 | sWalker.xSelectCallback = renameColumnSelectCb; |
| 109236 | 109214 | sWalker.u.pRename = &sCtx; |
| 109237 | 109215 | |
| 109238 | 109216 | if( sParse.pNewTable ){ |
| 109239 | | - Select *pSelect = sParse.pNewTable->pSelect; |
| 109240 | | - if( pSelect ){ |
| 109217 | + if( IsView(sParse.pNewTable) ){ |
| 109218 | + Select *pSelect = sParse.pNewTable->u.view.pSelect; |
| 109241 | 109219 | pSelect->selFlags &= ~SF_View; |
| 109242 | 109220 | sParse.rc = SQLITE_OK; |
| 109243 | 109221 | sqlite3SelectPrep(&sParse, pSelect, 0); |
| 109244 | 109222 | rc = (db->mallocFailed ? SQLITE_NOMEM : sParse.rc); |
| 109245 | 109223 | if( rc==SQLITE_OK ){ |
| | @@ -109248,11 +109226,13 @@ |
| 109248 | 109226 | }else{ |
| 109249 | 109227 | int i; |
| 109250 | 109228 | sqlite3WalkExprList(&sWalker, sParse.pNewTable->pCheck); |
| 109251 | 109229 | #ifndef SQLITE_OMIT_GENERATED_COLUMNS |
| 109252 | 109230 | for(i=0; i<sParse.pNewTable->nCol; i++){ |
| 109253 | | - sqlite3WalkExpr(&sWalker, sParse.pNewTable->aCol[i].pDflt); |
| 109231 | + sqlite3WalkExpr(&sWalker, |
| 109232 | + sqlite3ColumnExpr(sParse.pNewTable, |
| 109233 | + &sParse.pNewTable->aCol[i])); |
| 109254 | 109234 | } |
| 109255 | 109235 | #endif /* SQLITE_OMIT_GENERATED_COLUMNS */ |
| 109256 | 109236 | } |
| 109257 | 109237 | }else if( sParse.pNewIndex ){ |
| 109258 | 109238 | sqlite3WalkExprList(&sWalker, sParse.pNewIndex->aColExpr); |
| | @@ -109331,15 +109311,15 @@ |
| 109331 | 109311 | int flags = db->flags; |
| 109332 | 109312 | if( bNoDQS ) db->flags &= ~(SQLITE_DqsDML|SQLITE_DqsDDL); |
| 109333 | 109313 | rc = renameParseSql(&sParse, zDb, db, zInput, bTemp); |
| 109334 | 109314 | db->flags |= (flags & (SQLITE_DqsDML|SQLITE_DqsDDL)); |
| 109335 | 109315 | if( rc==SQLITE_OK ){ |
| 109336 | | - if( isLegacy==0 && sParse.pNewTable && sParse.pNewTable->pSelect ){ |
| 109316 | + if( isLegacy==0 && sParse.pNewTable && IsView(sParse.pNewTable) ){ |
| 109337 | 109317 | NameContext sNC; |
| 109338 | 109318 | memset(&sNC, 0, sizeof(sNC)); |
| 109339 | 109319 | sNC.pParse = &sParse; |
| 109340 | | - sqlite3SelectPrep(&sParse, sParse.pNewTable->pSelect, &sNC); |
| 109320 | + sqlite3SelectPrep(&sParse, sParse.pNewTable->u.view.pSelect, &sNC); |
| 109341 | 109321 | if( sParse.nErr ) rc = sParse.rc; |
| 109342 | 109322 | } |
| 109343 | 109323 | |
| 109344 | 109324 | else if( sParse.pNewTrigger ){ |
| 109345 | 109325 | if( isLegacy==0 ){ |
| | @@ -109406,17 +109386,18 @@ |
| 109406 | 109386 | /* This can happen if the sqlite_schema table is corrupt */ |
| 109407 | 109387 | rc = SQLITE_CORRUPT_BKPT; |
| 109408 | 109388 | goto drop_column_done; |
| 109409 | 109389 | } |
| 109410 | 109390 | |
| 109411 | | - pCol = renameTokenFind(&sParse, 0, (void*)pTab->aCol[iCol].zName); |
| 109391 | + pCol = renameTokenFind(&sParse, 0, (void*)pTab->aCol[iCol].zCnName); |
| 109412 | 109392 | if( iCol<pTab->nCol-1 ){ |
| 109413 | 109393 | RenameToken *pEnd; |
| 109414 | | - pEnd = renameTokenFind(&sParse, 0, (void*)pTab->aCol[iCol+1].zName); |
| 109394 | + pEnd = renameTokenFind(&sParse, 0, (void*)pTab->aCol[iCol+1].zCnName); |
| 109415 | 109395 | zEnd = (const char*)pEnd->t.z; |
| 109416 | 109396 | }else{ |
| 109417 | | - zEnd = (const char*)&zSql[pTab->addColOffset]; |
| 109397 | + assert( !IsVirtual(pTab) ); |
| 109398 | + zEnd = (const char*)&zSql[pTab->u.tab.addColOffset]; |
| 109418 | 109399 | while( ALWAYS(pCol->t.z[0]!=0) && pCol->t.z[0]!=',' ) pCol->t.z--; |
| 109419 | 109400 | } |
| 109420 | 109401 | |
| 109421 | 109402 | zNew = sqlite3MPrintf(db, "%.*s%s", pCol->t.z-zSql, zSql, zEnd); |
| 109422 | 109403 | sqlite3_result_text(context, zNew, -1, SQLITE_TRANSIENT); |
| | @@ -109547,10 +109528,16 @@ |
| 109547 | 109528 | }else{ |
| 109548 | 109529 | sqlite3ExprCodeGetColumnOfTable(v, pTab, iCur, i, regOut); |
| 109549 | 109530 | } |
| 109550 | 109531 | nField++; |
| 109551 | 109532 | } |
| 109533 | + } |
| 109534 | + if( nField==0 ){ |
| 109535 | + /* dbsqlfuzz 5f09e7bcc78b4954d06bf9f2400d7715f48d1fef */ |
| 109536 | + pParse->nMem++; |
| 109537 | + sqlite3VdbeAddOp2(v, OP_Null, 0, reg+1); |
| 109538 | + nField = 1; |
| 109552 | 109539 | } |
| 109553 | 109540 | sqlite3VdbeAddOp3(v, OP_MakeRecord, reg+1, nField, regRec); |
| 109554 | 109541 | if( pPk ){ |
| 109555 | 109542 | sqlite3VdbeAddOp4Int(v, OP_IdxInsert, iCur, regRec, reg+1, pPk->nKeyCol); |
| 109556 | 109543 | }else{ |
| | @@ -110552,11 +110539,11 @@ |
| 110552 | 110539 | if( NEVER(i==XN_ROWID) ){ |
| 110553 | 110540 | VdbeComment((v,"%s.rowid",pIdx->zName)); |
| 110554 | 110541 | }else if( i==XN_EXPR ){ |
| 110555 | 110542 | VdbeComment((v,"%s.expr(%d)",pIdx->zName, k)); |
| 110556 | 110543 | }else{ |
| 110557 | | - VdbeComment((v,"%s.%s", pIdx->zName, pIdx->pTable->aCol[i].zName)); |
| 110544 | + VdbeComment((v,"%s.%s", pIdx->zName, pIdx->pTable->aCol[i].zCnName)); |
| 110558 | 110545 | } |
| 110559 | 110546 | } |
| 110560 | 110547 | #else |
| 110561 | 110548 | # define analyzeVdbeCommentIndexWithColumnName(a,b,c) |
| 110562 | 110549 | #endif /* SQLITE_DEBUG */ |
| | @@ -112305,14 +112292,14 @@ |
| 112305 | 112292 | iCol = pExpr->iColumn; |
| 112306 | 112293 | if( pTab==0 ) return; |
| 112307 | 112294 | |
| 112308 | 112295 | if( iCol>=0 ){ |
| 112309 | 112296 | assert( iCol<pTab->nCol ); |
| 112310 | | - zCol = pTab->aCol[iCol].zName; |
| 112297 | + zCol = pTab->aCol[iCol].zCnName; |
| 112311 | 112298 | }else if( pTab->iPKey>=0 ){ |
| 112312 | 112299 | assert( pTab->iPKey<pTab->nCol ); |
| 112313 | | - zCol = pTab->aCol[pTab->iPKey].zName; |
| 112300 | + zCol = pTab->aCol[pTab->iPKey].zCnName; |
| 112314 | 112301 | }else{ |
| 112315 | 112302 | zCol = "ROWID"; |
| 112316 | 112303 | } |
| 112317 | 112304 | assert( iDb>=0 && iDb<pParse->db->nDb ); |
| 112318 | 112305 | if( SQLITE_IGNORE==sqlite3AuthReadCol(pParse, pTab->zName, zCol, iDb) ){ |
| | @@ -112686,24 +112673,26 @@ |
| 112686 | 112673 | } |
| 112687 | 112674 | |
| 112688 | 112675 | /* |
| 112689 | 112676 | ** Run the parser and code generator recursively in order to generate |
| 112690 | 112677 | ** code for the SQL statement given onto the end of the pParse context |
| 112691 | | -** currently under construction. When the parser is run recursively |
| 112692 | | -** this way, the final OP_Halt is not appended and other initialization |
| 112693 | | -** and finalization steps are omitted because those are handling by the |
| 112694 | | -** outermost parser. |
| 112678 | +** currently under construction. Notes: |
| 112695 | 112679 | ** |
| 112696 | | -** Not everything is nestable. This facility is designed to permit |
| 112697 | | -** INSERT, UPDATE, and DELETE operations against the schema table. Use |
| 112698 | | -** care if you decide to try to use this routine for some other purposes. |
| 112680 | +** * The final OP_Halt is not appended and other initialization |
| 112681 | +** and finalization steps are omitted because those are handling by the |
| 112682 | +** outermost parser. |
| 112683 | +** |
| 112684 | +** * Built-in SQL functions always take precedence over application-defined |
| 112685 | +** SQL functions. In other words, it is not possible to override a |
| 112686 | +** built-in function. |
| 112699 | 112687 | */ |
| 112700 | 112688 | SQLITE_PRIVATE void sqlite3NestedParse(Parse *pParse, const char *zFormat, ...){ |
| 112701 | 112689 | va_list ap; |
| 112702 | 112690 | char *zSql; |
| 112703 | 112691 | char *zErrMsg = 0; |
| 112704 | 112692 | sqlite3 *db = pParse->db; |
| 112693 | + u32 savedDbFlags = db->mDbFlags; |
| 112705 | 112694 | char saveBuf[PARSE_TAIL_SZ]; |
| 112706 | 112695 | |
| 112707 | 112696 | if( pParse->nErr ) return; |
| 112708 | 112697 | assert( pParse->nested<10 ); /* Nesting should only be of limited depth */ |
| 112709 | 112698 | va_start(ap, zFormat); |
| | @@ -112718,11 +112707,13 @@ |
| 112718 | 112707 | return; |
| 112719 | 112708 | } |
| 112720 | 112709 | pParse->nested++; |
| 112721 | 112710 | memcpy(saveBuf, PARSE_TAIL(pParse), PARSE_TAIL_SZ); |
| 112722 | 112711 | memset(PARSE_TAIL(pParse), 0, PARSE_TAIL_SZ); |
| 112712 | + db->mDbFlags |= DBFLAG_PreferBuiltin; |
| 112723 | 112713 | sqlite3RunParser(pParse, zSql, &zErrMsg); |
| 112714 | + db->mDbFlags = savedDbFlags; |
| 112724 | 112715 | sqlite3DbFree(db, zErrMsg); |
| 112725 | 112716 | sqlite3DbFree(db, zSql); |
| 112726 | 112717 | memcpy(PARSE_TAIL(pParse), saveBuf, PARSE_TAIL_SZ); |
| 112727 | 112718 | pParse->nested--; |
| 112728 | 112719 | } |
| | @@ -112854,10 +112845,11 @@ |
| 112854 | 112845 | Module *pMod = (Module*)sqlite3HashFind(&db->aModule, zName); |
| 112855 | 112846 | if( pMod==0 && sqlite3_strnicmp(zName, "pragma_", 7)==0 ){ |
| 112856 | 112847 | pMod = sqlite3PragmaVtabRegister(db, zName); |
| 112857 | 112848 | } |
| 112858 | 112849 | if( pMod && sqlite3VtabEponymousTableInit(pParse, pMod) ){ |
| 112850 | + testcase( pMod->pEpoTab==0 ); |
| 112859 | 112851 | return pMod->pEpoTab; |
| 112860 | 112852 | } |
| 112861 | 112853 | } |
| 112862 | 112854 | #endif |
| 112863 | 112855 | if( flags & LOCATE_NOERR ) return 0; |
| | @@ -113066,10 +113058,88 @@ |
| 113066 | 113058 | ** This routine is called when a commit occurs. |
| 113067 | 113059 | */ |
| 113068 | 113060 | SQLITE_PRIVATE void sqlite3CommitInternalChanges(sqlite3 *db){ |
| 113069 | 113061 | db->mDbFlags &= ~DBFLAG_SchemaChange; |
| 113070 | 113062 | } |
| 113063 | + |
| 113064 | +/* |
| 113065 | +** Set the expression associated with a column. This is usually |
| 113066 | +** the DEFAULT value, but might also be the expression that computes |
| 113067 | +** the value for a generated column. |
| 113068 | +*/ |
| 113069 | +SQLITE_PRIVATE void sqlite3ColumnSetExpr( |
| 113070 | + Parse *pParse, /* Parsing context */ |
| 113071 | + Table *pTab, /* The table containing the column */ |
| 113072 | + Column *pCol, /* The column to receive the new DEFAULT expression */ |
| 113073 | + Expr *pExpr /* The new default expression */ |
| 113074 | +){ |
| 113075 | + ExprList *pList; |
| 113076 | + assert( !IsVirtual(pTab) ); |
| 113077 | + pList = pTab->u.tab.pDfltList; |
| 113078 | + if( pCol->iDflt==0 |
| 113079 | + || NEVER(pList==0) |
| 113080 | + || NEVER(pList->nExpr<pCol->iDflt) |
| 113081 | + ){ |
| 113082 | + pCol->iDflt = pList==0 ? 1 : pList->nExpr+1; |
| 113083 | + pTab->u.tab.pDfltList = sqlite3ExprListAppend(pParse, pList, pExpr); |
| 113084 | + }else{ |
| 113085 | + sqlite3ExprDelete(pParse->db, pList->a[pCol->iDflt-1].pExpr); |
| 113086 | + pList->a[pCol->iDflt-1].pExpr = pExpr; |
| 113087 | + } |
| 113088 | +} |
| 113089 | + |
| 113090 | +/* |
| 113091 | +** Return the expression associated with a column. The expression might be |
| 113092 | +** the DEFAULT clause or the AS clause of a generated column. |
| 113093 | +** Return NULL if the column has no associated expression. |
| 113094 | +*/ |
| 113095 | +SQLITE_PRIVATE Expr *sqlite3ColumnExpr(Table *pTab, Column *pCol){ |
| 113096 | + if( pCol->iDflt==0 ) return 0; |
| 113097 | + if( NEVER(IsVirtual(pTab)) ) return 0; |
| 113098 | + if( NEVER(pTab->u.tab.pDfltList==0) ) return 0; |
| 113099 | + if( NEVER(pTab->u.tab.pDfltList->nExpr<pCol->iDflt) ) return 0; |
| 113100 | + return pTab->u.tab.pDfltList->a[pCol->iDflt-1].pExpr; |
| 113101 | +} |
| 113102 | + |
| 113103 | +/* |
| 113104 | +** Set the collating sequence name for a column. |
| 113105 | +*/ |
| 113106 | +SQLITE_PRIVATE void sqlite3ColumnSetColl( |
| 113107 | + sqlite3 *db, |
| 113108 | + Column *pCol, |
| 113109 | + const char *zColl |
| 113110 | +){ |
| 113111 | + int nColl; |
| 113112 | + int n; |
| 113113 | + char *zNew; |
| 113114 | + assert( zColl!=0 ); |
| 113115 | + n = sqlite3Strlen30(pCol->zCnName) + 1; |
| 113116 | + if( pCol->colFlags & COLFLAG_HASTYPE ){ |
| 113117 | + n += sqlite3Strlen30(pCol->zCnName+n) + 1; |
| 113118 | + } |
| 113119 | + nColl = sqlite3Strlen30(zColl) + 1; |
| 113120 | + zNew = sqlite3DbRealloc(db, pCol->zCnName, nColl+n); |
| 113121 | + if( zNew ){ |
| 113122 | + pCol->zCnName = zNew; |
| 113123 | + memcpy(pCol->zCnName + n, zColl, nColl); |
| 113124 | + pCol->colFlags |= COLFLAG_HASCOLL; |
| 113125 | + } |
| 113126 | +} |
| 113127 | + |
| 113128 | +/* |
| 113129 | +** Return the collating squence name for a column |
| 113130 | +*/ |
| 113131 | +SQLITE_PRIVATE const char *sqlite3ColumnColl(Column *pCol){ |
| 113132 | + const char *z; |
| 113133 | + if( (pCol->colFlags & COLFLAG_HASCOLL)==0 ) return 0; |
| 113134 | + z = pCol->zCnName; |
| 113135 | + while( *z ){ z++; } |
| 113136 | + if( pCol->colFlags & COLFLAG_HASTYPE ){ |
| 113137 | + do{ z++; }while( *z ); |
| 113138 | + } |
| 113139 | + return z+1; |
| 113140 | +} |
| 113071 | 113141 | |
| 113072 | 113142 | /* |
| 113073 | 113143 | ** Delete memory allocated for the column names of a table or view (the |
| 113074 | 113144 | ** Table.aCol[] array). |
| 113075 | 113145 | */ |
| | @@ -113077,16 +113147,24 @@ |
| 113077 | 113147 | int i; |
| 113078 | 113148 | Column *pCol; |
| 113079 | 113149 | assert( pTable!=0 ); |
| 113080 | 113150 | if( (pCol = pTable->aCol)!=0 ){ |
| 113081 | 113151 | for(i=0; i<pTable->nCol; i++, pCol++){ |
| 113082 | | - assert( pCol->zName==0 || pCol->hName==sqlite3StrIHash(pCol->zName) ); |
| 113083 | | - sqlite3DbFree(db, pCol->zName); |
| 113084 | | - sqlite3ExprDelete(db, pCol->pDflt); |
| 113085 | | - sqlite3DbFree(db, pCol->zColl); |
| 113152 | + assert( pCol->zCnName==0 || pCol->hName==sqlite3StrIHash(pCol->zCnName) ); |
| 113153 | + sqlite3DbFree(db, pCol->zCnName); |
| 113086 | 113154 | } |
| 113087 | 113155 | sqlite3DbFree(db, pTable->aCol); |
| 113156 | + if( !IsVirtual(pTable) ){ |
| 113157 | + sqlite3ExprListDelete(db, pTable->u.tab.pDfltList); |
| 113158 | + } |
| 113159 | + if( db==0 || db->pnBytesFreed==0 ){ |
| 113160 | + pTable->aCol = 0; |
| 113161 | + pTable->nCol = 0; |
| 113162 | + if( !IsVirtual(pTable) ){ |
| 113163 | + pTable->u.tab.pDfltList = 0; |
| 113164 | + } |
| 113165 | + } |
| 113088 | 113166 | } |
| 113089 | 113167 | } |
| 113090 | 113168 | |
| 113091 | 113169 | /* |
| 113092 | 113170 | ** Remove the memory data structures associated with the given |
| | @@ -113134,23 +113212,29 @@ |
| 113134 | 113212 | assert( pOld==pIndex || pOld==0 ); |
| 113135 | 113213 | } |
| 113136 | 113214 | sqlite3FreeIndex(db, pIndex); |
| 113137 | 113215 | } |
| 113138 | 113216 | |
| 113139 | | - /* Delete any foreign keys attached to this table. */ |
| 113140 | | - sqlite3FkDelete(db, pTable); |
| 113217 | + if( IsOrdinaryTable(pTable) ){ |
| 113218 | + sqlite3FkDelete(db, pTable); |
| 113219 | + } |
| 113220 | +#ifndef SQLITE_OMIT_VIRTUAL_TABLE |
| 113221 | + else if( IsVirtual(pTable) ){ |
| 113222 | + sqlite3VtabClear(db, pTable); |
| 113223 | + } |
| 113224 | +#endif |
| 113225 | + else{ |
| 113226 | + assert( IsView(pTable) ); |
| 113227 | + sqlite3SelectDelete(db, pTable->u.view.pSelect); |
| 113228 | + } |
| 113141 | 113229 | |
| 113142 | 113230 | /* Delete the Table structure itself. |
| 113143 | 113231 | */ |
| 113144 | 113232 | sqlite3DeleteColumnNames(db, pTable); |
| 113145 | 113233 | sqlite3DbFree(db, pTable->zName); |
| 113146 | 113234 | sqlite3DbFree(db, pTable->zColAff); |
| 113147 | | - sqlite3SelectDelete(db, pTable->pSelect); |
| 113148 | 113235 | sqlite3ExprListDelete(db, pTable->pCheck); |
| 113149 | | -#ifndef SQLITE_OMIT_VIRTUALTABLE |
| 113150 | | - sqlite3VtabClear(db, pTable); |
| 113151 | | -#endif |
| 113152 | 113236 | sqlite3DbFree(db, pTable); |
| 113153 | 113237 | |
| 113154 | 113238 | /* Verify that no lookaside memory was used by schema tables */ |
| 113155 | 113239 | assert( nLookaside==0 || nLookaside==sqlite3LookasideUsed(db,0) ); |
| 113156 | 113240 | } |
| | @@ -113672,20 +113756,21 @@ |
| 113672 | 113756 | /* Normal (non-error) return. */ |
| 113673 | 113757 | return; |
| 113674 | 113758 | |
| 113675 | 113759 | /* If an error occurs, we jump here */ |
| 113676 | 113760 | begin_table_error: |
| 113761 | + pParse->checkSchema = 1; |
| 113677 | 113762 | sqlite3DbFree(db, zName); |
| 113678 | 113763 | return; |
| 113679 | 113764 | } |
| 113680 | 113765 | |
| 113681 | 113766 | /* Set properties of a table column based on the (magical) |
| 113682 | 113767 | ** name of the column. |
| 113683 | 113768 | */ |
| 113684 | 113769 | #if SQLITE_ENABLE_HIDDEN_COLUMNS |
| 113685 | 113770 | SQLITE_PRIVATE void sqlite3ColumnPropertiesFromName(Table *pTab, Column *pCol){ |
| 113686 | | - if( sqlite3_strnicmp(pCol->zName, "__hidden__", 10)==0 ){ |
| 113771 | + if( sqlite3_strnicmp(pCol->zCnName, "__hidden__", 10)==0 ){ |
| 113687 | 113772 | pCol->colFlags |= COLFLAG_HIDDEN; |
| 113688 | 113773 | if( pTab ) pTab->tabFlags |= TF_HasHidden; |
| 113689 | 113774 | }else if( pTab && pCol!=pTab->aCol && (pCol[-1].colFlags & COLFLAG_HIDDEN) ){ |
| 113690 | 113775 | pTab->tabFlags |= TF_OOOHidden; |
| 113691 | 113776 | } |
| | @@ -113772,67 +113857,108 @@ |
| 113772 | 113857 | ** The parser calls this routine once for each column declaration |
| 113773 | 113858 | ** in a CREATE TABLE statement. sqlite3StartTable() gets called |
| 113774 | 113859 | ** first to get things going. Then this routine is called for each |
| 113775 | 113860 | ** column. |
| 113776 | 113861 | */ |
| 113777 | | -SQLITE_PRIVATE void sqlite3AddColumn(Parse *pParse, Token *pName, Token *pType){ |
| 113862 | +SQLITE_PRIVATE void sqlite3AddColumn(Parse *pParse, Token sName, Token sType){ |
| 113778 | 113863 | Table *p; |
| 113779 | 113864 | int i; |
| 113780 | 113865 | char *z; |
| 113781 | 113866 | char *zType; |
| 113782 | 113867 | Column *pCol; |
| 113783 | 113868 | sqlite3 *db = pParse->db; |
| 113784 | 113869 | u8 hName; |
| 113870 | + Column *aNew; |
| 113871 | + u8 eType = COLTYPE_CUSTOM; |
| 113872 | + u8 szEst = 1; |
| 113873 | + char affinity = SQLITE_AFF_BLOB; |
| 113785 | 113874 | |
| 113786 | 113875 | if( (p = pParse->pNewTable)==0 ) return; |
| 113787 | 113876 | if( p->nCol+1>db->aLimit[SQLITE_LIMIT_COLUMN] ){ |
| 113788 | 113877 | sqlite3ErrorMsg(pParse, "too many columns on %s", p->zName); |
| 113789 | 113878 | return; |
| 113790 | 113879 | } |
| 113791 | | - z = sqlite3DbMallocRaw(db, pName->n + pType->n + 2); |
| 113880 | + if( !IN_RENAME_OBJECT ) sqlite3DequoteToken(&sName); |
| 113881 | + |
| 113882 | + /* Because keywords GENERATE ALWAYS can be converted into indentifiers |
| 113883 | + ** by the parser, we can sometimes end up with a typename that ends |
| 113884 | + ** with "generated always". Check for this case and omit the surplus |
| 113885 | + ** text. */ |
| 113886 | + if( sType.n>=16 |
| 113887 | + && sqlite3_strnicmp(sType.z+(sType.n-6),"always",6)==0 |
| 113888 | + ){ |
| 113889 | + sType.n -= 6; |
| 113890 | + while( ALWAYS(sType.n>0) && sqlite3Isspace(sType.z[sType.n-1]) ) sType.n--; |
| 113891 | + if( sType.n>=9 |
| 113892 | + && sqlite3_strnicmp(sType.z+(sType.n-9),"generated",9)==0 |
| 113893 | + ){ |
| 113894 | + sType.n -= 9; |
| 113895 | + while( sType.n>0 && sqlite3Isspace(sType.z[sType.n-1]) ) sType.n--; |
| 113896 | + } |
| 113897 | + } |
| 113898 | + |
| 113899 | + /* Check for standard typenames. For standard typenames we will |
| 113900 | + ** set the Column.eType field rather than storing the typename after |
| 113901 | + ** the column name, in order to save space. */ |
| 113902 | + if( sType.n>=3 ){ |
| 113903 | + sqlite3DequoteToken(&sType); |
| 113904 | + for(i=0; i<SQLITE_N_STDTYPE; i++){ |
| 113905 | + if( sType.n==sqlite3StdTypeLen[i] |
| 113906 | + && sqlite3_strnicmp(sType.z, sqlite3StdType[i], sType.n)==0 |
| 113907 | + ){ |
| 113908 | + sType.n = 0; |
| 113909 | + eType = i+1; |
| 113910 | + affinity = sqlite3StdTypeAffinity[i]; |
| 113911 | + if( affinity<=SQLITE_AFF_TEXT ) szEst = 5; |
| 113912 | + break; |
| 113913 | + } |
| 113914 | + } |
| 113915 | + } |
| 113916 | + |
| 113917 | + z = sqlite3DbMallocRaw(db, sName.n + 1 + sType.n + (sType.n>0) ); |
| 113792 | 113918 | if( z==0 ) return; |
| 113793 | | - if( IN_RENAME_OBJECT ) sqlite3RenameTokenMap(pParse, (void*)z, pName); |
| 113794 | | - memcpy(z, pName->z, pName->n); |
| 113795 | | - z[pName->n] = 0; |
| 113919 | + if( IN_RENAME_OBJECT ) sqlite3RenameTokenMap(pParse, (void*)z, &sName); |
| 113920 | + memcpy(z, sName.z, sName.n); |
| 113921 | + z[sName.n] = 0; |
| 113796 | 113922 | sqlite3Dequote(z); |
| 113797 | 113923 | hName = sqlite3StrIHash(z); |
| 113798 | 113924 | for(i=0; i<p->nCol; i++){ |
| 113799 | | - if( p->aCol[i].hName==hName && sqlite3StrICmp(z, p->aCol[i].zName)==0 ){ |
| 113925 | + if( p->aCol[i].hName==hName && sqlite3StrICmp(z, p->aCol[i].zCnName)==0 ){ |
| 113800 | 113926 | sqlite3ErrorMsg(pParse, "duplicate column name: %s", z); |
| 113801 | 113927 | sqlite3DbFree(db, z); |
| 113802 | 113928 | return; |
| 113803 | 113929 | } |
| 113804 | 113930 | } |
| 113805 | | - if( (p->nCol & 0x7)==0 ){ |
| 113806 | | - Column *aNew; |
| 113807 | | - aNew = sqlite3DbRealloc(db,p->aCol,(p->nCol+8)*sizeof(p->aCol[0])); |
| 113808 | | - if( aNew==0 ){ |
| 113809 | | - sqlite3DbFree(db, z); |
| 113810 | | - return; |
| 113811 | | - } |
| 113812 | | - p->aCol = aNew; |
| 113813 | | - } |
| 113931 | + aNew = sqlite3DbRealloc(db,p->aCol,(p->nCol+1)*sizeof(p->aCol[0])); |
| 113932 | + if( aNew==0 ){ |
| 113933 | + sqlite3DbFree(db, z); |
| 113934 | + return; |
| 113935 | + } |
| 113936 | + p->aCol = aNew; |
| 113814 | 113937 | pCol = &p->aCol[p->nCol]; |
| 113815 | 113938 | memset(pCol, 0, sizeof(p->aCol[0])); |
| 113816 | | - pCol->zName = z; |
| 113939 | + pCol->zCnName = z; |
| 113817 | 113940 | pCol->hName = hName; |
| 113818 | 113941 | sqlite3ColumnPropertiesFromName(p, pCol); |
| 113819 | 113942 | |
| 113820 | | - if( pType->n==0 ){ |
| 113943 | + if( sType.n==0 ){ |
| 113821 | 113944 | /* If there is no type specified, columns have the default affinity |
| 113822 | 113945 | ** 'BLOB' with a default size of 4 bytes. */ |
| 113823 | | - pCol->affinity = SQLITE_AFF_BLOB; |
| 113824 | | - pCol->szEst = 1; |
| 113946 | + pCol->affinity = affinity; |
| 113947 | + pCol->eType = eType; |
| 113948 | + pCol->szEst = szEst; |
| 113825 | 113949 | #ifdef SQLITE_ENABLE_SORTER_REFERENCES |
| 113826 | | - if( 4>=sqlite3GlobalConfig.szSorterRef ){ |
| 113827 | | - pCol->colFlags |= COLFLAG_SORTERREF; |
| 113950 | + if( affinity==SQLITE_AFF_BLOB ){ |
| 113951 | + if( 4>=sqlite3GlobalConfig.szSorterRef ){ |
| 113952 | + pCol->colFlags |= COLFLAG_SORTERREF; |
| 113953 | + } |
| 113828 | 113954 | } |
| 113829 | 113955 | #endif |
| 113830 | 113956 | }else{ |
| 113831 | 113957 | zType = z + sqlite3Strlen30(z) + 1; |
| 113832 | | - memcpy(zType, pType->z, pType->n); |
| 113833 | | - zType[pType->n] = 0; |
| 113958 | + memcpy(zType, sType.z, sType.n); |
| 113959 | + zType[sType.n] = 0; |
| 113834 | 113960 | sqlite3Dequote(zType); |
| 113835 | 113961 | pCol->affinity = sqlite3AffinityType(zType, pCol); |
| 113836 | 113962 | pCol->colFlags |= COLFLAG_HASTYPE; |
| 113837 | 113963 | } |
| 113838 | 113964 | p->nCol++; |
| | @@ -113983,11 +114109,11 @@ |
| 113983 | 114109 | if( p!=0 ){ |
| 113984 | 114110 | int isInit = db->init.busy && db->init.iDb!=1; |
| 113985 | 114111 | pCol = &(p->aCol[p->nCol-1]); |
| 113986 | 114112 | if( !sqlite3ExprIsConstantOrFunction(pExpr, isInit) ){ |
| 113987 | 114113 | sqlite3ErrorMsg(pParse, "default value of column [%s] is not constant", |
| 113988 | | - pCol->zName); |
| 114114 | + pCol->zCnName); |
| 113989 | 114115 | #ifndef SQLITE_OMIT_GENERATED_COLUMNS |
| 113990 | 114116 | }else if( pCol->colFlags & COLFLAG_GENERATED ){ |
| 113991 | 114117 | testcase( pCol->colFlags & COLFLAG_VIRTUAL ); |
| 113992 | 114118 | testcase( pCol->colFlags & COLFLAG_STORED ); |
| 113993 | 114119 | sqlite3ErrorMsg(pParse, "cannot use DEFAULT on a generated column"); |
| | @@ -113994,19 +114120,19 @@ |
| 113994 | 114120 | #endif |
| 113995 | 114121 | }else{ |
| 113996 | 114122 | /* A copy of pExpr is used instead of the original, as pExpr contains |
| 113997 | 114123 | ** tokens that point to volatile memory. |
| 113998 | 114124 | */ |
| 113999 | | - Expr x; |
| 114000 | | - sqlite3ExprDelete(db, pCol->pDflt); |
| 114125 | + Expr x, *pDfltExpr; |
| 114001 | 114126 | memset(&x, 0, sizeof(x)); |
| 114002 | 114127 | x.op = TK_SPAN; |
| 114003 | 114128 | x.u.zToken = sqlite3DbSpanDup(db, zStart, zEnd); |
| 114004 | 114129 | x.pLeft = pExpr; |
| 114005 | 114130 | x.flags = EP_Skip; |
| 114006 | | - pCol->pDflt = sqlite3ExprDup(db, &x, EXPRDUP_REDUCE); |
| 114131 | + pDfltExpr = sqlite3ExprDup(db, &x, EXPRDUP_REDUCE); |
| 114007 | 114132 | sqlite3DbFree(db, x.u.zToken); |
| 114133 | + sqlite3ColumnSetExpr(pParse, p, pCol, pDfltExpr); |
| 114008 | 114134 | } |
| 114009 | 114135 | } |
| 114010 | 114136 | if( IN_RENAME_OBJECT ){ |
| 114011 | 114137 | sqlite3RenameExprUnmap(pParse, pExpr); |
| 114012 | 114138 | } |
| | @@ -114100,11 +114226,11 @@ |
| 114100 | 114226 | assert( pCExpr!=0 ); |
| 114101 | 114227 | sqlite3StringToId(pCExpr); |
| 114102 | 114228 | if( pCExpr->op==TK_ID ){ |
| 114103 | 114229 | const char *zCName = pCExpr->u.zToken; |
| 114104 | 114230 | for(iCol=0; iCol<pTab->nCol; iCol++){ |
| 114105 | | - if( sqlite3StrICmp(zCName, pTab->aCol[iCol].zName)==0 ){ |
| 114231 | + if( sqlite3StrICmp(zCName, pTab->aCol[iCol].zCnName)==0 ){ |
| 114106 | 114232 | pCol = &pTab->aCol[iCol]; |
| 114107 | 114233 | makeColumnPartOfPrimaryKey(pParse, pCol); |
| 114108 | 114234 | break; |
| 114109 | 114235 | } |
| 114110 | 114236 | } |
| | @@ -114111,11 +114237,11 @@ |
| 114111 | 114237 | } |
| 114112 | 114238 | } |
| 114113 | 114239 | } |
| 114114 | 114240 | if( nTerm==1 |
| 114115 | 114241 | && pCol |
| 114116 | | - && sqlite3StrICmp(sqlite3ColumnType(pCol,""), "INTEGER")==0 |
| 114242 | + && pCol->eType==COLTYPE_INTEGER |
| 114117 | 114243 | && sortOrder!=SQLITE_SO_DESC |
| 114118 | 114244 | ){ |
| 114119 | 114245 | if( IN_RENAME_OBJECT && pList ){ |
| 114120 | 114246 | Expr *pCExpr = sqlite3ExprSkipCollate(pList->a[0].pExpr); |
| 114121 | 114247 | sqlite3RenameTokenRemap(pParse, &pTab->iPKey, pCExpr); |
| | @@ -114191,26 +114317,24 @@ |
| 114191 | 114317 | zColl = sqlite3NameFromToken(db, pToken); |
| 114192 | 114318 | if( !zColl ) return; |
| 114193 | 114319 | |
| 114194 | 114320 | if( sqlite3LocateCollSeq(pParse, zColl) ){ |
| 114195 | 114321 | Index *pIdx; |
| 114196 | | - sqlite3DbFree(db, p->aCol[i].zColl); |
| 114197 | | - p->aCol[i].zColl = zColl; |
| 114322 | + sqlite3ColumnSetColl(db, &p->aCol[i], zColl); |
| 114198 | 114323 | |
| 114199 | 114324 | /* If the column is declared as "<name> PRIMARY KEY COLLATE <type>", |
| 114200 | 114325 | ** then an index may have been created on this column before the |
| 114201 | 114326 | ** collation type was added. Correct this if it is the case. |
| 114202 | 114327 | */ |
| 114203 | 114328 | for(pIdx=p->pIndex; pIdx; pIdx=pIdx->pNext){ |
| 114204 | 114329 | assert( pIdx->nKeyCol==1 ); |
| 114205 | 114330 | if( pIdx->aiColumn[0]==i ){ |
| 114206 | | - pIdx->azColl[0] = p->aCol[i].zColl; |
| 114331 | + pIdx->azColl[0] = sqlite3ColumnColl(&p->aCol[i]); |
| 114207 | 114332 | } |
| 114208 | 114333 | } |
| 114209 | | - }else{ |
| 114210 | | - sqlite3DbFree(db, zColl); |
| 114211 | 114334 | } |
| 114335 | + sqlite3DbFree(db, zColl); |
| 114212 | 114336 | } |
| 114213 | 114337 | |
| 114214 | 114338 | /* Change the most recently parsed column to be a GENERATED ALWAYS AS |
| 114215 | 114339 | ** column. |
| 114216 | 114340 | */ |
| | @@ -114226,11 +114350,11 @@ |
| 114226 | 114350 | pCol = &(pTab->aCol[pTab->nCol-1]); |
| 114227 | 114351 | if( IN_DECLARE_VTAB ){ |
| 114228 | 114352 | sqlite3ErrorMsg(pParse, "virtual tables cannot use computed columns"); |
| 114229 | 114353 | goto generated_done; |
| 114230 | 114354 | } |
| 114231 | | - if( pCol->pDflt ) goto generated_error; |
| 114355 | + if( pCol->iDflt>0 ) goto generated_error; |
| 114232 | 114356 | if( pType ){ |
| 114233 | 114357 | if( pType->n==7 && sqlite3StrNICmp("virtual",pType->z,7)==0 ){ |
| 114234 | 114358 | /* no-op */ |
| 114235 | 114359 | }else if( pType->n==6 && sqlite3StrNICmp("stored",pType->z,6)==0 ){ |
| 114236 | 114360 | eType = COLFLAG_STORED; |
| | @@ -114244,17 +114368,17 @@ |
| 114244 | 114368 | assert( TF_HasStored==COLFLAG_STORED ); |
| 114245 | 114369 | pTab->tabFlags |= eType; |
| 114246 | 114370 | if( pCol->colFlags & COLFLAG_PRIMKEY ){ |
| 114247 | 114371 | makeColumnPartOfPrimaryKey(pParse, pCol); /* For the error message */ |
| 114248 | 114372 | } |
| 114249 | | - pCol->pDflt = pExpr; |
| 114373 | + sqlite3ColumnSetExpr(pParse, pTab, pCol, pExpr); |
| 114250 | 114374 | pExpr = 0; |
| 114251 | 114375 | goto generated_done; |
| 114252 | 114376 | |
| 114253 | 114377 | generated_error: |
| 114254 | 114378 | sqlite3ErrorMsg(pParse, "error in generated column \"%s\"", |
| 114255 | | - pCol->zName); |
| 114379 | + pCol->zCnName); |
| 114256 | 114380 | generated_done: |
| 114257 | 114381 | sqlite3ExprDelete(pParse->db, pExpr); |
| 114258 | 114382 | #else |
| 114259 | 114383 | /* Throw and error for the GENERATED ALWAYS AS clause if the |
| 114260 | 114384 | ** SQLITE_OMIT_GENERATED_COLUMNS compile-time option is used. */ |
| | @@ -114352,11 +114476,11 @@ |
| 114352 | 114476 | char *zStmt; |
| 114353 | 114477 | char *zSep, *zSep2, *zEnd; |
| 114354 | 114478 | Column *pCol; |
| 114355 | 114479 | n = 0; |
| 114356 | 114480 | for(pCol = p->aCol, i=0; i<p->nCol; i++, pCol++){ |
| 114357 | | - n += identLength(pCol->zName) + 5; |
| 114481 | + n += identLength(pCol->zCnName) + 5; |
| 114358 | 114482 | } |
| 114359 | 114483 | n += identLength(p->zName); |
| 114360 | 114484 | if( n<50 ){ |
| 114361 | 114485 | zSep = ""; |
| 114362 | 114486 | zSep2 = ","; |
| | @@ -114388,11 +114512,11 @@ |
| 114388 | 114512 | const char *zType; |
| 114389 | 114513 | |
| 114390 | 114514 | sqlite3_snprintf(n-k, &zStmt[k], zSep); |
| 114391 | 114515 | k += sqlite3Strlen30(&zStmt[k]); |
| 114392 | 114516 | zSep = zSep2; |
| 114393 | | - identPut(zStmt, &k, pCol->zName); |
| 114517 | + identPut(zStmt, &k, pCol->zCnName); |
| 114394 | 114518 | assert( pCol->affinity-SQLITE_AFF_BLOB >= 0 ); |
| 114395 | 114519 | assert( pCol->affinity-SQLITE_AFF_BLOB < ArraySize(azType) ); |
| 114396 | 114520 | testcase( pCol->affinity==SQLITE_AFF_BLOB ); |
| 114397 | 114521 | testcase( pCol->affinity==SQLITE_AFF_TEXT ); |
| 114398 | 114522 | testcase( pCol->affinity==SQLITE_AFF_NUMERIC ); |
| | @@ -114607,11 +114731,11 @@ |
| 114607 | 114731 | ** an INTEGER PRIMARY KEY table, create a new PRIMARY KEY index. |
| 114608 | 114732 | */ |
| 114609 | 114733 | if( pTab->iPKey>=0 ){ |
| 114610 | 114734 | ExprList *pList; |
| 114611 | 114735 | Token ipkToken; |
| 114612 | | - sqlite3TokenInit(&ipkToken, pTab->aCol[pTab->iPKey].zName); |
| 114736 | + sqlite3TokenInit(&ipkToken, pTab->aCol[pTab->iPKey].zCnName); |
| 114613 | 114737 | pList = sqlite3ExprListAppend(pParse, 0, |
| 114614 | 114738 | sqlite3ExprAlloc(db, TK_ID, &ipkToken, 0)); |
| 114615 | 114739 | if( pList==0 ){ |
| 114616 | 114740 | pTab->tabFlags &= ~TF_WithoutRowid; |
| 114617 | 114741 | return; |
| | @@ -114737,11 +114861,11 @@ |
| 114737 | 114861 | |
| 114738 | 114862 | if( !IsVirtual(pTab) ) return 0; |
| 114739 | 114863 | nName = sqlite3Strlen30(pTab->zName); |
| 114740 | 114864 | if( sqlite3_strnicmp(zName, pTab->zName, nName)!=0 ) return 0; |
| 114741 | 114865 | if( zName[nName]!='_' ) return 0; |
| 114742 | | - pMod = (Module*)sqlite3HashFind(&db->aModule, pTab->azModuleArg[0]); |
| 114866 | + pMod = (Module*)sqlite3HashFind(&db->aModule, pTab->u.vtab.azArg[0]); |
| 114743 | 114867 | if( pMod==0 ) return 0; |
| 114744 | 114868 | if( pMod->pModule->iVersion<3 ) return 0; |
| 114745 | 114869 | if( pMod->pModule->xShadowName==0 ) return 0; |
| 114746 | 114870 | return pMod->pModule->xShadowName(zName+nName+1); |
| 114747 | 114871 | } |
| | @@ -114898,22 +115022,22 @@ |
| 114898 | 115022 | testcase( p->tabFlags & TF_HasVirtual ); |
| 114899 | 115023 | testcase( p->tabFlags & TF_HasStored ); |
| 114900 | 115024 | for(ii=0; ii<p->nCol; ii++){ |
| 114901 | 115025 | u32 colFlags = p->aCol[ii].colFlags; |
| 114902 | 115026 | if( (colFlags & COLFLAG_GENERATED)!=0 ){ |
| 114903 | | - Expr *pX = p->aCol[ii].pDflt; |
| 115027 | + Expr *pX = sqlite3ColumnExpr(p, &p->aCol[ii]); |
| 114904 | 115028 | testcase( colFlags & COLFLAG_VIRTUAL ); |
| 114905 | 115029 | testcase( colFlags & COLFLAG_STORED ); |
| 114906 | 115030 | if( sqlite3ResolveSelfReference(pParse, p, NC_GenCol, pX, 0) ){ |
| 114907 | 115031 | /* If there are errors in resolving the expression, change the |
| 114908 | 115032 | ** expression to a NULL. This prevents code generators that operate |
| 114909 | 115033 | ** on the expression from inserting extra parts into the expression |
| 114910 | 115034 | ** tree that have been allocated from lookaside memory, which is |
| 114911 | 115035 | ** illegal in a schema and will lead to errors or heap corruption |
| 114912 | 115036 | ** when the database connection closes. */ |
| 114913 | | - sqlite3ExprDelete(db, pX); |
| 114914 | | - p->aCol[ii].pDflt = sqlite3ExprAlloc(db, TK_NULL, 0, 0); |
| 115037 | + sqlite3ColumnSetExpr(pParse, p, &p->aCol[ii], |
| 115038 | + sqlite3ExprAlloc(db, TK_NULL, 0, 0)); |
| 114915 | 115039 | } |
| 114916 | 115040 | }else{ |
| 114917 | 115041 | nNG++; |
| 114918 | 115042 | } |
| 114919 | 115043 | } |
| | @@ -114949,11 +115073,11 @@ |
| 114949 | 115073 | sqlite3VdbeAddOp1(v, OP_Close, 0); |
| 114950 | 115074 | |
| 114951 | 115075 | /* |
| 114952 | 115076 | ** Initialize zType for the new view or table. |
| 114953 | 115077 | */ |
| 114954 | | - if( p->pSelect==0 ){ |
| 115078 | + if( IsOrdinaryTable(p) ){ |
| 114955 | 115079 | /* A regular table */ |
| 114956 | 115080 | zType = "table"; |
| 114957 | 115081 | zType2 = "TABLE"; |
| 114958 | 115082 | #ifndef SQLITE_OMIT_VIEW |
| 114959 | 115083 | }else{ |
| | @@ -115099,16 +115223,16 @@ |
| 115099 | 115223 | } |
| 115100 | 115224 | #endif |
| 115101 | 115225 | } |
| 115102 | 115226 | |
| 115103 | 115227 | #ifndef SQLITE_OMIT_ALTERTABLE |
| 115104 | | - if( !pSelect && !p->pSelect ){ |
| 115228 | + if( !pSelect && IsOrdinaryTable(p) ){ |
| 115105 | 115229 | assert( pCons && pEnd ); |
| 115106 | 115230 | if( pCons->z==0 ){ |
| 115107 | 115231 | pCons = pEnd; |
| 115108 | 115232 | } |
| 115109 | | - p->addColOffset = 13 + (int)(pCons->z - pParse->sNameToken.z); |
| 115233 | + p->u.tab.addColOffset = 13 + (int)(pCons->z - pParse->sNameToken.z); |
| 115110 | 115234 | } |
| 115111 | 115235 | #endif |
| 115112 | 115236 | } |
| 115113 | 115237 | |
| 115114 | 115238 | #ifndef SQLITE_OMIT_VIEW |
| | @@ -115161,16 +115285,17 @@ |
| 115161 | 115285 | ** allocated rather than point to the input string - which means that |
| 115162 | 115286 | ** they will persist after the current sqlite3_exec() call returns. |
| 115163 | 115287 | */ |
| 115164 | 115288 | pSelect->selFlags |= SF_View; |
| 115165 | 115289 | if( IN_RENAME_OBJECT ){ |
| 115166 | | - p->pSelect = pSelect; |
| 115290 | + p->u.view.pSelect = pSelect; |
| 115167 | 115291 | pSelect = 0; |
| 115168 | 115292 | }else{ |
| 115169 | | - p->pSelect = sqlite3SelectDup(db, pSelect, EXPRDUP_REDUCE); |
| 115293 | + p->u.view.pSelect = sqlite3SelectDup(db, pSelect, EXPRDUP_REDUCE); |
| 115170 | 115294 | } |
| 115171 | 115295 | p->pCheck = sqlite3ExprListDup(db, pCNames, EXPRDUP_REDUCE); |
| 115296 | + p->eTabType = TABTYP_VIEW; |
| 115172 | 115297 | if( db->mallocFailed ) goto create_view_fail; |
| 115173 | 115298 | |
| 115174 | 115299 | /* Locate the end of the CREATE VIEW statement. Make sEnd point to |
| 115175 | 115300 | ** the end. |
| 115176 | 115301 | */ |
| | @@ -115263,12 +115388,12 @@ |
| 115263 | 115388 | ** "*" elements in the results set of the view and will assign cursors |
| 115264 | 115389 | ** to the elements of the FROM clause. But we do not want these changes |
| 115265 | 115390 | ** to be permanent. So the computation is done on a copy of the SELECT |
| 115266 | 115391 | ** statement that defines the view. |
| 115267 | 115392 | */ |
| 115268 | | - assert( pTable->pSelect ); |
| 115269 | | - pSel = sqlite3SelectDup(db, pTable->pSelect, 0); |
| 115393 | + assert( IsView(pTable) ); |
| 115394 | + pSel = sqlite3SelectDup(db, pTable->u.view.pSelect, 0); |
| 115270 | 115395 | if( pSel ){ |
| 115271 | 115396 | u8 eParseMode = pParse->eParseMode; |
| 115272 | 115397 | pParse->eParseMode = PARSE_MODE_NORMAL; |
| 115273 | 115398 | n = pParse->nTab; |
| 115274 | 115399 | sqlite3SrcListAssignCursors(pParse, pSel->pSrc); |
| | @@ -115323,12 +115448,10 @@ |
| 115323 | 115448 | nErr++; |
| 115324 | 115449 | } |
| 115325 | 115450 | pTable->pSchema->schemaFlags |= DB_UnresetViews; |
| 115326 | 115451 | if( db->mallocFailed ){ |
| 115327 | 115452 | sqlite3DeleteColumnNames(db, pTable); |
| 115328 | | - pTable->aCol = 0; |
| 115329 | | - pTable->nCol = 0; |
| 115330 | 115453 | } |
| 115331 | 115454 | #endif /* SQLITE_OMIT_VIEW */ |
| 115332 | 115455 | return nErr; |
| 115333 | 115456 | } |
| 115334 | 115457 | #endif /* !defined(SQLITE_OMIT_VIEW) || !defined(SQLITE_OMIT_VIRTUALTABLE) */ |
| | @@ -115341,14 +115464,12 @@ |
| 115341 | 115464 | HashElem *i; |
| 115342 | 115465 | assert( sqlite3SchemaMutexHeld(db, idx, 0) ); |
| 115343 | 115466 | if( !DbHasProperty(db, idx, DB_UnresetViews) ) return; |
| 115344 | 115467 | for(i=sqliteHashFirst(&db->aDb[idx].pSchema->tblHash); i;i=sqliteHashNext(i)){ |
| 115345 | 115468 | Table *pTab = sqliteHashData(i); |
| 115346 | | - if( pTab->pSelect ){ |
| 115469 | + if( IsView(pTab) ){ |
| 115347 | 115470 | sqlite3DeleteColumnNames(db, pTab); |
| 115348 | | - pTab->aCol = 0; |
| 115349 | | - pTab->nCol = 0; |
| 115350 | 115471 | } |
| 115351 | 115472 | } |
| 115352 | 115473 | DbClearProperty(db, idx, DB_UnresetViews); |
| 115353 | 115474 | } |
| 115354 | 115475 | #else |
| | @@ -115581,10 +115702,11 @@ |
| 115581 | 115702 | SQLITE_PRIVATE int sqlite3ReadOnlyShadowTables(sqlite3 *db){ |
| 115582 | 115703 | #ifndef SQLITE_OMIT_VIRTUALTABLE |
| 115583 | 115704 | if( (db->flags & SQLITE_Defensive)!=0 |
| 115584 | 115705 | && db->pVtabCtx==0 |
| 115585 | 115706 | && db->nVdbeExec==0 |
| 115707 | + && !sqlite3VtabInSync(db) |
| 115586 | 115708 | ){ |
| 115587 | 115709 | return 1; |
| 115588 | 115710 | } |
| 115589 | 115711 | #endif |
| 115590 | 115712 | return 0; |
| | @@ -115684,15 +115806,15 @@ |
| 115684 | 115806 | |
| 115685 | 115807 | #ifndef SQLITE_OMIT_VIEW |
| 115686 | 115808 | /* Ensure DROP TABLE is not used on a view, and DROP VIEW is not used |
| 115687 | 115809 | ** on a table. |
| 115688 | 115810 | */ |
| 115689 | | - if( isView && pTab->pSelect==0 ){ |
| 115811 | + if( isView && !IsView(pTab) ){ |
| 115690 | 115812 | sqlite3ErrorMsg(pParse, "use DROP TABLE to delete table %s", pTab->zName); |
| 115691 | 115813 | goto exit_drop_table; |
| 115692 | 115814 | } |
| 115693 | | - if( !isView && pTab->pSelect ){ |
| 115815 | + if( !isView && IsView(pTab) ){ |
| 115694 | 115816 | sqlite3ErrorMsg(pParse, "use DROP VIEW to delete view %s", pTab->zName); |
| 115695 | 115817 | goto exit_drop_table; |
| 115696 | 115818 | } |
| 115697 | 115819 | #endif |
| 115698 | 115820 | |
| | @@ -115752,11 +115874,11 @@ |
| 115752 | 115874 | int iCol = p->nCol-1; |
| 115753 | 115875 | if( NEVER(iCol<0) ) goto fk_end; |
| 115754 | 115876 | if( pToCol && pToCol->nExpr!=1 ){ |
| 115755 | 115877 | sqlite3ErrorMsg(pParse, "foreign key on %s" |
| 115756 | 115878 | " should reference only one column of table %T", |
| 115757 | | - p->aCol[iCol].zName, pTo); |
| 115879 | + p->aCol[iCol].zCnName, pTo); |
| 115758 | 115880 | goto fk_end; |
| 115759 | 115881 | } |
| 115760 | 115882 | nCol = 1; |
| 115761 | 115883 | }else if( pToCol && pToCol->nExpr!=pFromCol->nExpr ){ |
| 115762 | 115884 | sqlite3ErrorMsg(pParse, |
| | @@ -115775,11 +115897,11 @@ |
| 115775 | 115897 | pFKey = sqlite3DbMallocZero(db, nByte ); |
| 115776 | 115898 | if( pFKey==0 ){ |
| 115777 | 115899 | goto fk_end; |
| 115778 | 115900 | } |
| 115779 | 115901 | pFKey->pFrom = p; |
| 115780 | | - pFKey->pNextFrom = p->pFKey; |
| 115902 | + pFKey->pNextFrom = p->u.tab.pFKey; |
| 115781 | 115903 | z = (char*)&pFKey->aCol[nCol]; |
| 115782 | 115904 | pFKey->zTo = z; |
| 115783 | 115905 | if( IN_RENAME_OBJECT ){ |
| 115784 | 115906 | sqlite3RenameTokenMap(pParse, (void*)z, pTo); |
| 115785 | 115907 | } |
| | @@ -115792,11 +115914,11 @@ |
| 115792 | 115914 | pFKey->aCol[0].iFrom = p->nCol-1; |
| 115793 | 115915 | }else{ |
| 115794 | 115916 | for(i=0; i<nCol; i++){ |
| 115795 | 115917 | int j; |
| 115796 | 115918 | for(j=0; j<p->nCol; j++){ |
| 115797 | | - if( sqlite3StrICmp(p->aCol[j].zName, pFromCol->a[i].zEName)==0 ){ |
| 115919 | + if( sqlite3StrICmp(p->aCol[j].zCnName, pFromCol->a[i].zEName)==0 ){ |
| 115798 | 115920 | pFKey->aCol[i].iFrom = j; |
| 115799 | 115921 | break; |
| 115800 | 115922 | } |
| 115801 | 115923 | } |
| 115802 | 115924 | if( j>=p->nCol ){ |
| | @@ -115840,11 +115962,12 @@ |
| 115840 | 115962 | pNextTo->pPrevTo = pFKey; |
| 115841 | 115963 | } |
| 115842 | 115964 | |
| 115843 | 115965 | /* Link the foreign key to the table as the last step. |
| 115844 | 115966 | */ |
| 115845 | | - p->pFKey = pFKey; |
| 115967 | + assert( !IsVirtual(p) ); |
| 115968 | + p->u.tab.pFKey = pFKey; |
| 115846 | 115969 | pFKey = 0; |
| 115847 | 115970 | |
| 115848 | 115971 | fk_end: |
| 115849 | 115972 | sqlite3DbFree(db, pFKey); |
| 115850 | 115973 | #endif /* !defined(SQLITE_OMIT_FOREIGN_KEY) */ |
| | @@ -115861,11 +115984,13 @@ |
| 115861 | 115984 | */ |
| 115862 | 115985 | SQLITE_PRIVATE void sqlite3DeferForeignKey(Parse *pParse, int isDeferred){ |
| 115863 | 115986 | #ifndef SQLITE_OMIT_FOREIGN_KEY |
| 115864 | 115987 | Table *pTab; |
| 115865 | 115988 | FKey *pFKey; |
| 115866 | | - if( (pTab = pParse->pNewTable)==0 || (pFKey = pTab->pFKey)==0 ) return; |
| 115989 | + if( (pTab = pParse->pNewTable)==0 ) return; |
| 115990 | + if( NEVER(IsVirtual(pTab)) ) return; |
| 115991 | + if( (pFKey = pTab->u.tab.pFKey)==0 ) return; |
| 115867 | 115992 | assert( isDeferred==0 || isDeferred==1 ); /* EV: R-30323-21917 */ |
| 115868 | 115993 | pFKey->isDeferred = (u8)isDeferred; |
| 115869 | 115994 | #endif |
| 115870 | 115995 | } |
| 115871 | 115996 | |
| | @@ -116153,11 +116278,11 @@ |
| 116153 | 116278 | ){ |
| 116154 | 116279 | sqlite3ErrorMsg(pParse, "table %s may not be indexed", pTab->zName); |
| 116155 | 116280 | goto exit_create_index; |
| 116156 | 116281 | } |
| 116157 | 116282 | #ifndef SQLITE_OMIT_VIEW |
| 116158 | | - if( pTab->pSelect ){ |
| 116283 | + if( IsView(pTab) ){ |
| 116159 | 116284 | sqlite3ErrorMsg(pParse, "views may not be indexed"); |
| 116160 | 116285 | goto exit_create_index; |
| 116161 | 116286 | } |
| 116162 | 116287 | #endif |
| 116163 | 116288 | #ifndef SQLITE_OMIT_VIRTUALTABLE |
| | @@ -116244,11 +116369,11 @@ |
| 116244 | 116369 | */ |
| 116245 | 116370 | if( pList==0 ){ |
| 116246 | 116371 | Token prevCol; |
| 116247 | 116372 | Column *pCol = &pTab->aCol[pTab->nCol-1]; |
| 116248 | 116373 | pCol->colFlags |= COLFLAG_UNIQUE; |
| 116249 | | - sqlite3TokenInit(&prevCol, pCol->zName); |
| 116374 | + sqlite3TokenInit(&prevCol, pCol->zCnName); |
| 116250 | 116375 | pList = sqlite3ExprListAppend(pParse, 0, |
| 116251 | 116376 | sqlite3ExprAlloc(db, TK_ID, &prevCol, 0)); |
| 116252 | 116377 | if( pList==0 ) goto exit_create_index; |
| 116253 | 116378 | assert( pList->nExpr==1 ); |
| 116254 | 116379 | sqlite3ExprListSetSortOrder(pList, sortOrder, SQLITE_SO_UNDEFINED); |
| | @@ -116365,11 +116490,11 @@ |
| 116365 | 116490 | memcpy(zExtra, zColl, nColl); |
| 116366 | 116491 | zColl = zExtra; |
| 116367 | 116492 | zExtra += nColl; |
| 116368 | 116493 | nExtra -= nColl; |
| 116369 | 116494 | }else if( j>=0 ){ |
| 116370 | | - zColl = pTab->aCol[j].zColl; |
| 116495 | + zColl = sqlite3ColumnColl(&pTab->aCol[j]); |
| 116371 | 116496 | } |
| 116372 | 116497 | if( !zColl ) zColl = sqlite3StrBINARY; |
| 116373 | 116498 | if( !db->init.busy && !sqlite3LocateCollSeq(pParse, zColl) ){ |
| 116374 | 116499 | goto exit_create_index; |
| 116375 | 116500 | } |
| | @@ -117457,11 +117582,11 @@ |
| 117457 | 117582 | sqlite3_str_appendf(&errMsg, "index '%q'", pIdx->zName); |
| 117458 | 117583 | }else{ |
| 117459 | 117584 | for(j=0; j<pIdx->nKeyCol; j++){ |
| 117460 | 117585 | char *zCol; |
| 117461 | 117586 | assert( pIdx->aiColumn[j]>=0 ); |
| 117462 | | - zCol = pTab->aCol[pIdx->aiColumn[j]].zName; |
| 117587 | + zCol = pTab->aCol[pIdx->aiColumn[j]].zCnName; |
| 117463 | 117588 | if( j ) sqlite3_str_append(&errMsg, ", ", 2); |
| 117464 | 117589 | sqlite3_str_appendall(&errMsg, pTab->zName); |
| 117465 | 117590 | sqlite3_str_append(&errMsg, ".", 1); |
| 117466 | 117591 | sqlite3_str_appendall(&errMsg, zCol); |
| 117467 | 117592 | } |
| | @@ -117484,11 +117609,11 @@ |
| 117484 | 117609 | ){ |
| 117485 | 117610 | char *zMsg; |
| 117486 | 117611 | int rc; |
| 117487 | 117612 | if( pTab->iPKey>=0 ){ |
| 117488 | 117613 | zMsg = sqlite3MPrintf(pParse->db, "%s.%s", pTab->zName, |
| 117489 | | - pTab->aCol[pTab->iPKey].zName); |
| 117614 | + pTab->aCol[pTab->iPKey].zCnName); |
| 117490 | 117615 | rc = SQLITE_CONSTRAINT_PRIMARYKEY; |
| 117491 | 117616 | }else{ |
| 117492 | 117617 | zMsg = sqlite3MPrintf(pParse->db, "%s.rowid", pTab->zName); |
| 117493 | 117618 | rc = SQLITE_CONSTRAINT_ROWID; |
| 117494 | 117619 | } |
| | @@ -118411,11 +118536,11 @@ |
| 118411 | 118536 | if( tabIsReadOnly(pParse, pTab) ){ |
| 118412 | 118537 | sqlite3ErrorMsg(pParse, "table %s may not be modified", pTab->zName); |
| 118413 | 118538 | return 1; |
| 118414 | 118539 | } |
| 118415 | 118540 | #ifndef SQLITE_OMIT_VIEW |
| 118416 | | - if( !viewOk && pTab->pSelect ){ |
| 118541 | + if( !viewOk && IsView(pTab) ){ |
| 118417 | 118542 | sqlite3ErrorMsg(pParse,"cannot modify %s because it is a view",pTab->zName); |
| 118418 | 118543 | return 1; |
| 118419 | 118544 | } |
| 118420 | 118545 | #endif |
| 118421 | 118546 | return 0; |
| | @@ -118515,17 +118640,17 @@ |
| 118515 | 118640 | pParse, 0, sqlite3PExpr(pParse, TK_ROW, 0, 0) |
| 118516 | 118641 | ); |
| 118517 | 118642 | }else{ |
| 118518 | 118643 | Index *pPk = sqlite3PrimaryKeyIndex(pTab); |
| 118519 | 118644 | if( pPk->nKeyCol==1 ){ |
| 118520 | | - const char *zName = pTab->aCol[pPk->aiColumn[0]].zName; |
| 118645 | + const char *zName = pTab->aCol[pPk->aiColumn[0]].zCnName; |
| 118521 | 118646 | pLhs = sqlite3Expr(db, TK_ID, zName); |
| 118522 | 118647 | pEList = sqlite3ExprListAppend(pParse, 0, sqlite3Expr(db, TK_ID, zName)); |
| 118523 | 118648 | }else{ |
| 118524 | 118649 | int i; |
| 118525 | 118650 | for(i=0; i<pPk->nKeyCol; i++){ |
| 118526 | | - Expr *p = sqlite3Expr(db, TK_ID, pTab->aCol[pPk->aiColumn[i]].zName); |
| 118651 | + Expr *p = sqlite3Expr(db, TK_ID, pTab->aCol[pPk->aiColumn[i]].zCnName); |
| 118527 | 118652 | pEList = sqlite3ExprListAppend(pParse, pEList, p); |
| 118528 | 118653 | } |
| 118529 | 118654 | pLhs = sqlite3PExpr(pParse, TK_VECTOR, 0, 0); |
| 118530 | 118655 | if( pLhs ){ |
| 118531 | 118656 | pLhs->x.pList = sqlite3ExprListDup(db, pEList, 0); |
| | @@ -118628,11 +118753,11 @@ |
| 118628 | 118753 | /* Figure out if we have any triggers and if the table being |
| 118629 | 118754 | ** deleted from is a view |
| 118630 | 118755 | */ |
| 118631 | 118756 | #ifndef SQLITE_OMIT_TRIGGER |
| 118632 | 118757 | pTrigger = sqlite3TriggersExist(pParse, pTab, TK_DELETE, 0, 0); |
| 118633 | | - isView = pTab->pSelect!=0; |
| 118758 | + isView = IsView(pTab); |
| 118634 | 118759 | #else |
| 118635 | 118760 | # define pTrigger 0 |
| 118636 | 118761 | # define isView 0 |
| 118637 | 118762 | #endif |
| 118638 | 118763 | bComplex = pTrigger || sqlite3FkRequired(pParse, pTab, 0, 0); |
| | @@ -118878,11 +119003,11 @@ |
| 118878 | 119003 | ** where-clause loop above. |
| 118879 | 119004 | */ |
| 118880 | 119005 | if( eOnePass!=ONEPASS_OFF ){ |
| 118881 | 119006 | assert( nKey==nPk ); /* OP_Found will use an unpacked key */ |
| 118882 | 119007 | if( !IsVirtual(pTab) && aToOpen[iDataCur-iTabCur] ){ |
| 118883 | | - assert( pPk!=0 || pTab->pSelect!=0 ); |
| 119008 | + assert( pPk!=0 || IsView(pTab) ); |
| 118884 | 119009 | sqlite3VdbeAddOp4Int(v, OP_NotFound, iDataCur, addrBypass, iKey, nKey); |
| 118885 | 119010 | VdbeCoverage(v); |
| 118886 | 119011 | } |
| 118887 | 119012 | }else if( pPk ){ |
| 118888 | 119013 | addrLoop = sqlite3VdbeAddOp1(v, OP_Rewind, iEphCur); VdbeCoverage(v); |
| | @@ -119112,11 +119237,11 @@ |
| 119112 | 119237 | ** invoke the update-hook. The pre-update-hook, on the other hand should |
| 119113 | 119238 | ** be invoked unless table pTab is a system table. The difference is that |
| 119114 | 119239 | ** the update-hook is not invoked for rows removed by REPLACE, but the |
| 119115 | 119240 | ** pre-update-hook is. |
| 119116 | 119241 | */ |
| 119117 | | - if( pTab->pSelect==0 ){ |
| 119242 | + if( !IsView(pTab) ){ |
| 119118 | 119243 | u8 p5 = 0; |
| 119119 | 119244 | sqlite3GenerateRowIndexDelete(pParse, pTab, iDataCur, iIdxCur,0,iIdxNoSeek); |
| 119120 | 119245 | sqlite3VdbeAddOp2(v, OP_Delete, iDataCur, (count?OPFLAG_NCHANGE:0)); |
| 119121 | 119246 | if( pParse->nested==0 || 0==sqlite3_stricmp(pTab->zName, "sqlite_stat1") ){ |
| 119122 | 119247 | sqlite3VdbeAppendP4(v, (char*)pTab, P4_TABLE); |
| | @@ -119873,37 +119998,37 @@ |
| 119873 | 119998 | |
| 119874 | 119999 | /* |
| 119875 | 120000 | ** Implementation of the changes() SQL function. |
| 119876 | 120001 | ** |
| 119877 | 120002 | ** IMP: R-62073-11209 The changes() SQL function is a wrapper |
| 119878 | | -** around the sqlite3_changes() C/C++ function and hence follows the same |
| 120003 | +** around the sqlite3_changes64() C/C++ function and hence follows the same |
| 119879 | 120004 | ** rules for counting changes. |
| 119880 | 120005 | */ |
| 119881 | 120006 | static void changes( |
| 119882 | 120007 | sqlite3_context *context, |
| 119883 | 120008 | int NotUsed, |
| 119884 | 120009 | sqlite3_value **NotUsed2 |
| 119885 | 120010 | ){ |
| 119886 | 120011 | sqlite3 *db = sqlite3_context_db_handle(context); |
| 119887 | 120012 | UNUSED_PARAMETER2(NotUsed, NotUsed2); |
| 119888 | | - sqlite3_result_int(context, sqlite3_changes(db)); |
| 120013 | + sqlite3_result_int64(context, sqlite3_changes64(db)); |
| 119889 | 120014 | } |
| 119890 | 120015 | |
| 119891 | 120016 | /* |
| 119892 | 120017 | ** Implementation of the total_changes() SQL function. The return value is |
| 119893 | | -** the same as the sqlite3_total_changes() API function. |
| 120018 | +** the same as the sqlite3_total_changes64() API function. |
| 119894 | 120019 | */ |
| 119895 | 120020 | static void total_changes( |
| 119896 | 120021 | sqlite3_context *context, |
| 119897 | 120022 | int NotUsed, |
| 119898 | 120023 | sqlite3_value **NotUsed2 |
| 119899 | 120024 | ){ |
| 119900 | 120025 | sqlite3 *db = sqlite3_context_db_handle(context); |
| 119901 | 120026 | UNUSED_PARAMETER2(NotUsed, NotUsed2); |
| 119902 | | - /* IMP: R-52756-41993 This function is a wrapper around the |
| 120027 | + /* IMP: R-52756-41993 This function was a wrapper around the |
| 119903 | 120028 | ** sqlite3_total_changes() C/C++ interface. */ |
| 119904 | | - sqlite3_result_int(context, sqlite3_total_changes(db)); |
| 120029 | + sqlite3_result_int64(context, sqlite3_total_changes64(db)); |
| 119905 | 120030 | } |
| 119906 | 120031 | |
| 119907 | 120032 | /* |
| 119908 | 120033 | ** A structure defining how to do GLOB-style comparisons. |
| 119909 | 120034 | */ |
| | @@ -120617,29 +120742,29 @@ |
| 120617 | 120742 | int argc, |
| 120618 | 120743 | sqlite3_value **argv |
| 120619 | 120744 | ){ |
| 120620 | 120745 | const unsigned char *zIn; /* Input string */ |
| 120621 | 120746 | const unsigned char *zCharSet; /* Set of characters to trim */ |
| 120622 | | - int nIn; /* Number of bytes in input */ |
| 120747 | + unsigned int nIn; /* Number of bytes in input */ |
| 120623 | 120748 | int flags; /* 1: trimleft 2: trimright 3: trim */ |
| 120624 | 120749 | int i; /* Loop counter */ |
| 120625 | | - unsigned char *aLen = 0; /* Length of each character in zCharSet */ |
| 120750 | + unsigned int *aLen = 0; /* Length of each character in zCharSet */ |
| 120626 | 120751 | unsigned char **azChar = 0; /* Individual characters in zCharSet */ |
| 120627 | 120752 | int nChar; /* Number of characters in zCharSet */ |
| 120628 | 120753 | |
| 120629 | 120754 | if( sqlite3_value_type(argv[0])==SQLITE_NULL ){ |
| 120630 | 120755 | return; |
| 120631 | 120756 | } |
| 120632 | 120757 | zIn = sqlite3_value_text(argv[0]); |
| 120633 | 120758 | if( zIn==0 ) return; |
| 120634 | | - nIn = sqlite3_value_bytes(argv[0]); |
| 120759 | + nIn = (unsigned)sqlite3_value_bytes(argv[0]); |
| 120635 | 120760 | assert( zIn==sqlite3_value_text(argv[0]) ); |
| 120636 | 120761 | if( argc==1 ){ |
| 120637 | | - static const unsigned char lenOne[] = { 1 }; |
| 120762 | + static const unsigned lenOne[] = { 1 }; |
| 120638 | 120763 | static unsigned char * const azOne[] = { (u8*)" " }; |
| 120639 | 120764 | nChar = 1; |
| 120640 | | - aLen = (u8*)lenOne; |
| 120765 | + aLen = (unsigned*)lenOne; |
| 120641 | 120766 | azChar = (unsigned char **)azOne; |
| 120642 | 120767 | zCharSet = 0; |
| 120643 | 120768 | }else if( (zCharSet = sqlite3_value_text(argv[1]))==0 ){ |
| 120644 | 120769 | return; |
| 120645 | 120770 | }else{ |
| | @@ -120646,27 +120771,28 @@ |
| 120646 | 120771 | const unsigned char *z; |
| 120647 | 120772 | for(z=zCharSet, nChar=0; *z; nChar++){ |
| 120648 | 120773 | SQLITE_SKIP_UTF8(z); |
| 120649 | 120774 | } |
| 120650 | 120775 | if( nChar>0 ){ |
| 120651 | | - azChar = contextMalloc(context, ((i64)nChar)*(sizeof(char*)+1)); |
| 120776 | + azChar = contextMalloc(context, |
| 120777 | + ((i64)nChar)*(sizeof(char*)+sizeof(unsigned))); |
| 120652 | 120778 | if( azChar==0 ){ |
| 120653 | 120779 | return; |
| 120654 | 120780 | } |
| 120655 | | - aLen = (unsigned char*)&azChar[nChar]; |
| 120781 | + aLen = (unsigned*)&azChar[nChar]; |
| 120656 | 120782 | for(z=zCharSet, nChar=0; *z; nChar++){ |
| 120657 | 120783 | azChar[nChar] = (unsigned char *)z; |
| 120658 | 120784 | SQLITE_SKIP_UTF8(z); |
| 120659 | | - aLen[nChar] = (u8)(z - azChar[nChar]); |
| 120785 | + aLen[nChar] = (unsigned)(z - azChar[nChar]); |
| 120660 | 120786 | } |
| 120661 | 120787 | } |
| 120662 | 120788 | } |
| 120663 | 120789 | if( nChar>0 ){ |
| 120664 | 120790 | flags = SQLITE_PTR_TO_INT(sqlite3_user_data(context)); |
| 120665 | 120791 | if( flags & 1 ){ |
| 120666 | 120792 | while( nIn>0 ){ |
| 120667 | | - int len = 0; |
| 120793 | + unsigned int len = 0; |
| 120668 | 120794 | for(i=0; i<nChar; i++){ |
| 120669 | 120795 | len = aLen[i]; |
| 120670 | 120796 | if( len<=nIn && memcmp(zIn, azChar[i], len)==0 ) break; |
| 120671 | 120797 | } |
| 120672 | 120798 | if( i>=nChar ) break; |
| | @@ -120674,11 +120800,11 @@ |
| 120674 | 120800 | nIn -= len; |
| 120675 | 120801 | } |
| 120676 | 120802 | } |
| 120677 | 120803 | if( flags & 2 ){ |
| 120678 | 120804 | while( nIn>0 ){ |
| 120679 | | - int len = 0; |
| 120805 | + unsigned int len = 0; |
| 120680 | 120806 | for(i=0; i<nChar; i++){ |
| 120681 | 120807 | len = aLen[i]; |
| 120682 | 120808 | if( len<=nIn && memcmp(&zIn[nIn-len],azChar[i],len)==0 ) break; |
| 120683 | 120809 | } |
| 120684 | 120810 | if( i>=nChar ) break; |
| | @@ -121460,15 +121586,15 @@ |
| 121460 | 121586 | FUNCTION(trim, 1, 3, 0, trimFunc ), |
| 121461 | 121587 | FUNCTION(trim, 2, 3, 0, trimFunc ), |
| 121462 | 121588 | FUNCTION(min, -1, 0, 1, minmaxFunc ), |
| 121463 | 121589 | FUNCTION(min, 0, 0, 1, 0 ), |
| 121464 | 121590 | WAGGREGATE(min, 1, 0, 1, minmaxStep, minMaxFinalize, minMaxValue, 0, |
| 121465 | | - SQLITE_FUNC_MINMAX ), |
| 121591 | + SQLITE_FUNC_MINMAX|SQLITE_FUNC_ANYORDER ), |
| 121466 | 121592 | FUNCTION(max, -1, 1, 1, minmaxFunc ), |
| 121467 | 121593 | FUNCTION(max, 0, 1, 1, 0 ), |
| 121468 | 121594 | WAGGREGATE(max, 1, 1, 1, minmaxStep, minMaxFinalize, minMaxValue, 0, |
| 121469 | | - SQLITE_FUNC_MINMAX ), |
| 121595 | + SQLITE_FUNC_MINMAX|SQLITE_FUNC_ANYORDER ), |
| 121470 | 121596 | FUNCTION2(typeof, 1, 0, 0, typeofFunc, SQLITE_FUNC_TYPEOF), |
| 121471 | 121597 | FUNCTION2(length, 1, 0, 0, lengthFunc, SQLITE_FUNC_LENGTH), |
| 121472 | 121598 | FUNCTION(instr, 2, 0, 0, instrFunc ), |
| 121473 | 121599 | FUNCTION(printf, -1, 0, 0, printfFunc ), |
| 121474 | 121600 | FUNCTION(unicode, 1, 0, 0, unicodeFunc ), |
| | @@ -121500,13 +121626,14 @@ |
| 121500 | 121626 | FUNCTION(substring, 3, 0, 0, substrFunc ), |
| 121501 | 121627 | WAGGREGATE(sum, 1,0,0, sumStep, sumFinalize, sumFinalize, sumInverse, 0), |
| 121502 | 121628 | WAGGREGATE(total, 1,0,0, sumStep,totalFinalize,totalFinalize,sumInverse, 0), |
| 121503 | 121629 | WAGGREGATE(avg, 1,0,0, sumStep, avgFinalize, avgFinalize, sumInverse, 0), |
| 121504 | 121630 | WAGGREGATE(count, 0,0,0, countStep, |
| 121505 | | - countFinalize, countFinalize, countInverse, SQLITE_FUNC_COUNT ), |
| 121631 | + countFinalize, countFinalize, countInverse, |
| 121632 | + SQLITE_FUNC_COUNT|SQLITE_FUNC_ANYORDER ), |
| 121506 | 121633 | WAGGREGATE(count, 1,0,0, countStep, |
| 121507 | | - countFinalize, countFinalize, countInverse, 0 ), |
| 121634 | + countFinalize, countFinalize, countInverse, SQLITE_FUNC_ANYORDER ), |
| 121508 | 121635 | WAGGREGATE(group_concat, 1, 0, 0, groupConcatStep, |
| 121509 | 121636 | groupConcatFinalize, groupConcatValue, groupConcatInverse, 0), |
| 121510 | 121637 | WAGGREGATE(group_concat, 2, 0, 0, groupConcatStep, |
| 121511 | 121638 | groupConcatFinalize, groupConcatValue, groupConcatInverse, 0), |
| 121512 | 121639 | |
| | @@ -121804,11 +121931,13 @@ |
| 121804 | 121931 | ** 2) The FK is explicitly mapped to a column declared as INTEGER |
| 121805 | 121932 | ** PRIMARY KEY. |
| 121806 | 121933 | */ |
| 121807 | 121934 | if( pParent->iPKey>=0 ){ |
| 121808 | 121935 | if( !zKey ) return 0; |
| 121809 | | - if( !sqlite3StrICmp(pParent->aCol[pParent->iPKey].zName, zKey) ) return 0; |
| 121936 | + if( !sqlite3StrICmp(pParent->aCol[pParent->iPKey].zCnName, zKey) ){ |
| 121937 | + return 0; |
| 121938 | + } |
| 121810 | 121939 | } |
| 121811 | 121940 | }else if( paiCol ){ |
| 121812 | 121941 | assert( nCol>1 ); |
| 121813 | 121942 | aiCol = (int *)sqlite3DbMallocRawNN(pParse->db, nCol*sizeof(int)); |
| 121814 | 121943 | if( !aiCol ) return 1; |
| | @@ -121846,15 +121975,15 @@ |
| 121846 | 121975 | if( iCol<0 ) break; /* No foreign keys against expression indexes */ |
| 121847 | 121976 | |
| 121848 | 121977 | /* If the index uses a collation sequence that is different from |
| 121849 | 121978 | ** the default collation sequence for the column, this index is |
| 121850 | 121979 | ** unusable. Bail out early in this case. */ |
| 121851 | | - zDfltColl = pParent->aCol[iCol].zColl; |
| 121980 | + zDfltColl = sqlite3ColumnColl(&pParent->aCol[iCol]); |
| 121852 | 121981 | if( !zDfltColl ) zDfltColl = sqlite3StrBINARY; |
| 121853 | 121982 | if( sqlite3StrICmp(pIdx->azColl[i], zDfltColl) ) break; |
| 121854 | 121983 | |
| 121855 | | - zIdxCol = pParent->aCol[iCol].zName; |
| 121984 | + zIdxCol = pParent->aCol[iCol].zCnName; |
| 121856 | 121985 | for(j=0; j<nCol; j++){ |
| 121857 | 121986 | if( sqlite3StrICmp(pFKey->aCol[j].zCol, zIdxCol)==0 ){ |
| 121858 | 121987 | if( aiCol ) aiCol[i] = pFKey->aCol[j].iFrom; |
| 121859 | 121988 | break; |
| 121860 | 121989 | } |
| | @@ -122074,11 +122203,11 @@ |
| 122074 | 122203 | if( pExpr ){ |
| 122075 | 122204 | if( iCol>=0 && iCol!=pTab->iPKey ){ |
| 122076 | 122205 | pCol = &pTab->aCol[iCol]; |
| 122077 | 122206 | pExpr->iTable = regBase + sqlite3TableColumnToStorage(pTab,iCol) + 1; |
| 122078 | 122207 | pExpr->affExpr = pCol->affinity; |
| 122079 | | - zColl = pCol->zColl; |
| 122208 | + zColl = sqlite3ColumnColl(pCol); |
| 122080 | 122209 | if( zColl==0 ) zColl = db->pDfltColl->zName; |
| 122081 | 122210 | pExpr = sqlite3ExprAddCollateString(pParse, pExpr, zColl); |
| 122082 | 122211 | }else{ |
| 122083 | 122212 | pExpr->iTable = regBase; |
| 122084 | 122213 | pExpr->affExpr = SQLITE_AFF_INTEGER; |
| | @@ -122183,11 +122312,11 @@ |
| 122183 | 122312 | |
| 122184 | 122313 | iCol = pIdx ? pIdx->aiColumn[i] : -1; |
| 122185 | 122314 | pLeft = exprTableRegister(pParse, pTab, regData, iCol); |
| 122186 | 122315 | iCol = aiCol ? aiCol[i] : pFKey->aCol[0].iFrom; |
| 122187 | 122316 | assert( iCol>=0 ); |
| 122188 | | - zCol = pFKey->pFrom->aCol[iCol].zName; |
| 122317 | + zCol = pFKey->pFrom->aCol[iCol].zCnName; |
| 122189 | 122318 | pRight = sqlite3Expr(db, TK_ID, zCol); |
| 122190 | 122319 | pEq = sqlite3PExpr(pParse, TK_EQ, pLeft, pRight); |
| 122191 | 122320 | pWhere = sqlite3ExprAnd(pParse, pWhere, pEq); |
| 122192 | 122321 | } |
| 122193 | 122322 | |
| | @@ -122218,11 +122347,11 @@ |
| 122218 | 122347 | assert( pIdx!=0 ); |
| 122219 | 122348 | for(i=0; i<pIdx->nKeyCol; i++){ |
| 122220 | 122349 | i16 iCol = pIdx->aiColumn[i]; |
| 122221 | 122350 | assert( iCol>=0 ); |
| 122222 | 122351 | pLeft = exprTableRegister(pParse, pTab, regData, iCol); |
| 122223 | | - pRight = sqlite3Expr(db, TK_ID, pTab->aCol[iCol].zName); |
| 122352 | + pRight = sqlite3Expr(db, TK_ID, pTab->aCol[iCol].zCnName); |
| 122224 | 122353 | pEq = sqlite3PExpr(pParse, TK_IS, pLeft, pRight); |
| 122225 | 122354 | pAll = sqlite3ExprAnd(pParse, pAll, pEq); |
| 122226 | 122355 | } |
| 122227 | 122356 | pNe = sqlite3PExpr(pParse, TK_NOT, pAll, 0); |
| 122228 | 122357 | } |
| | @@ -122312,19 +122441,20 @@ |
| 122312 | 122441 | if( (db->flags&SQLITE_ForeignKeys) && !IsVirtual(pTab) ){ |
| 122313 | 122442 | int iSkip = 0; |
| 122314 | 122443 | Vdbe *v = sqlite3GetVdbe(pParse); |
| 122315 | 122444 | |
| 122316 | 122445 | assert( v ); /* VDBE has already been allocated */ |
| 122317 | | - assert( pTab->pSelect==0 ); /* Not a view */ |
| 122446 | + assert( !IsView(pTab) ); /* Not a view */ |
| 122447 | + assert( !IsVirtual(pTab) ); |
| 122318 | 122448 | if( sqlite3FkReferences(pTab)==0 ){ |
| 122319 | 122449 | /* Search for a deferred foreign key constraint for which this table |
| 122320 | 122450 | ** is the child table. If one cannot be found, return without |
| 122321 | 122451 | ** generating any VDBE code. If one can be found, then jump over |
| 122322 | 122452 | ** the entire DELETE if there are no outstanding deferred constraints |
| 122323 | 122453 | ** when this statement is run. */ |
| 122324 | 122454 | FKey *p; |
| 122325 | | - for(p=pTab->pFKey; p; p=p->pNextFrom){ |
| 122455 | + for(p=pTab->u.tab.pFKey; p; p=p->pNextFrom){ |
| 122326 | 122456 | if( p->isDeferred || (db->flags & SQLITE_DeferFKs) ) break; |
| 122327 | 122457 | } |
| 122328 | 122458 | if( !p ) return; |
| 122329 | 122459 | iSkip = sqlite3VdbeMakeLabel(pParse); |
| 122330 | 122460 | sqlite3VdbeAddOp2(v, OP_FkIfZero, 1, iSkip); VdbeCoverage(v); |
| | @@ -122409,11 +122539,11 @@ |
| 122409 | 122539 | int iKey; |
| 122410 | 122540 | for(iKey=0; iKey<pTab->nCol; iKey++){ |
| 122411 | 122541 | if( aChange[iKey]>=0 || (iKey==pTab->iPKey && bChngRowid) ){ |
| 122412 | 122542 | Column *pCol = &pTab->aCol[iKey]; |
| 122413 | 122543 | if( zKey ){ |
| 122414 | | - if( 0==sqlite3StrICmp(pCol->zName, zKey) ) return 1; |
| 122544 | + if( 0==sqlite3StrICmp(pCol->zCnName, zKey) ) return 1; |
| 122415 | 122545 | }else if( pCol->colFlags & COLFLAG_PRIMKEY ){ |
| 122416 | 122546 | return 1; |
| 122417 | 122547 | } |
| 122418 | 122548 | } |
| 122419 | 122549 | } |
| | @@ -122482,11 +122612,12 @@ |
| 122482 | 122612 | iDb = sqlite3SchemaToIndex(db, pTab->pSchema); |
| 122483 | 122613 | zDb = db->aDb[iDb].zDbSName; |
| 122484 | 122614 | |
| 122485 | 122615 | /* Loop through all the foreign key constraints for which pTab is the |
| 122486 | 122616 | ** child table (the table that the foreign key definition is part of). */ |
| 122487 | | - for(pFKey=pTab->pFKey; pFKey; pFKey=pFKey->pNextFrom){ |
| 122617 | + assert( !IsVirtual(pTab) ); |
| 122618 | + for(pFKey=pTab->u.tab.pFKey; pFKey; pFKey=pFKey->pNextFrom){ |
| 122488 | 122619 | Table *pTo; /* Parent table of foreign key pFKey */ |
| 122489 | 122620 | Index *pIdx = 0; /* Index on key columns in pTo */ |
| 122490 | 122621 | int *aiFree = 0; |
| 122491 | 122622 | int *aiCol; |
| 122492 | 122623 | int iCol; |
| | @@ -122549,11 +122680,11 @@ |
| 122549 | 122680 | /* Request permission to read the parent key columns. If the |
| 122550 | 122681 | ** authorization callback returns SQLITE_IGNORE, behave as if any |
| 122551 | 122682 | ** values read from the parent table are NULL. */ |
| 122552 | 122683 | if( db->xAuth ){ |
| 122553 | 122684 | int rcauth; |
| 122554 | | - char *zCol = pTo->aCol[pIdx ? pIdx->aiColumn[i] : pTo->iPKey].zName; |
| 122685 | + char *zCol = pTo->aCol[pIdx ? pIdx->aiColumn[i] : pTo->iPKey].zCnName; |
| 122555 | 122686 | rcauth = sqlite3AuthReadCol(pParse, pTo->zName, zCol, iDb); |
| 122556 | 122687 | bIgnore = (rcauth==SQLITE_IGNORE); |
| 122557 | 122688 | } |
| 122558 | 122689 | #endif |
| 122559 | 122690 | } |
| | @@ -122667,11 +122798,12 @@ |
| 122667 | 122798 | ){ |
| 122668 | 122799 | u32 mask = 0; |
| 122669 | 122800 | if( pParse->db->flags&SQLITE_ForeignKeys ){ |
| 122670 | 122801 | FKey *p; |
| 122671 | 122802 | int i; |
| 122672 | | - for(p=pTab->pFKey; p; p=p->pNextFrom){ |
| 122803 | + assert( !IsVirtual(pTab) ); |
| 122804 | + for(p=pTab->u.tab.pFKey; p; p=p->pNextFrom){ |
| 122673 | 122805 | for(i=0; i<p->nCol; i++) mask |= COLUMN_MASK(p->aCol[i].iFrom); |
| 122674 | 122806 | } |
| 122675 | 122807 | for(p=sqlite3FkReferences(pTab); p; p=p->pNextTo){ |
| 122676 | 122808 | Index *pIdx = 0; |
| 122677 | 122809 | sqlite3FkLocateIndex(pParse, pTab, p, &pIdx, 0); |
| | @@ -122717,23 +122849,23 @@ |
| 122717 | 122849 | int *aChange, /* Non-NULL for UPDATE operations */ |
| 122718 | 122850 | int chngRowid /* True for UPDATE that affects rowid */ |
| 122719 | 122851 | ){ |
| 122720 | 122852 | int eRet = 1; /* Value to return if bHaveFK is true */ |
| 122721 | 122853 | int bHaveFK = 0; /* If FK processing is required */ |
| 122722 | | - if( pParse->db->flags&SQLITE_ForeignKeys ){ |
| 122854 | + if( pParse->db->flags&SQLITE_ForeignKeys && !IsVirtual(pTab) ){ |
| 122723 | 122855 | if( !aChange ){ |
| 122724 | 122856 | /* A DELETE operation. Foreign key processing is required if the |
| 122725 | 122857 | ** table in question is either the child or parent table for any |
| 122726 | 122858 | ** foreign key constraint. */ |
| 122727 | | - bHaveFK = (sqlite3FkReferences(pTab) || pTab->pFKey); |
| 122859 | + bHaveFK = (sqlite3FkReferences(pTab) || pTab->u.tab.pFKey); |
| 122728 | 122860 | }else{ |
| 122729 | 122861 | /* This is an UPDATE. Foreign key processing is only required if the |
| 122730 | 122862 | ** operation modifies one or more child or parent key columns. */ |
| 122731 | 122863 | FKey *p; |
| 122732 | 122864 | |
| 122733 | 122865 | /* Check if any child key columns are being modified. */ |
| 122734 | | - for(p=pTab->pFKey; p; p=p->pNextFrom){ |
| 122866 | + for(p=pTab->u.tab.pFKey; p; p=p->pNextFrom){ |
| 122735 | 122867 | if( fkChildIsModified(pTab, p, aChange, chngRowid) ){ |
| 122736 | 122868 | if( 0==sqlite3_stricmp(pTab->zName, p->zTo) ) eRet = 2; |
| 122737 | 122869 | bHaveFK = 1; |
| 122738 | 122870 | } |
| 122739 | 122871 | } |
| | @@ -122822,12 +122954,12 @@ |
| 122822 | 122954 | iFromCol = aiCol ? aiCol[i] : pFKey->aCol[0].iFrom; |
| 122823 | 122955 | assert( iFromCol>=0 ); |
| 122824 | 122956 | assert( pIdx!=0 || (pTab->iPKey>=0 && pTab->iPKey<pTab->nCol) ); |
| 122825 | 122957 | assert( pIdx==0 || pIdx->aiColumn[i]>=0 ); |
| 122826 | 122958 | sqlite3TokenInit(&tToCol, |
| 122827 | | - pTab->aCol[pIdx ? pIdx->aiColumn[i] : pTab->iPKey].zName); |
| 122828 | | - sqlite3TokenInit(&tFromCol, pFKey->pFrom->aCol[iFromCol].zName); |
| 122959 | + pTab->aCol[pIdx ? pIdx->aiColumn[i] : pTab->iPKey].zCnName); |
| 122960 | + sqlite3TokenInit(&tFromCol, pFKey->pFrom->aCol[iFromCol].zCnName); |
| 122829 | 122961 | |
| 122830 | 122962 | /* Create the expression "OLD.zToCol = zFromCol". It is important |
| 122831 | 122963 | ** that the "OLD.zToCol" term is on the LHS of the = operator, so |
| 122832 | 122964 | ** that the affinity and collation sequence associated with the |
| 122833 | 122965 | ** parent table are used for the comparison. */ |
| | @@ -122868,11 +123000,11 @@ |
| 122868 | 123000 | if( pCol->colFlags & COLFLAG_GENERATED ){ |
| 122869 | 123001 | testcase( pCol->colFlags & COLFLAG_VIRTUAL ); |
| 122870 | 123002 | testcase( pCol->colFlags & COLFLAG_STORED ); |
| 122871 | 123003 | pDflt = 0; |
| 122872 | 123004 | }else{ |
| 122873 | | - pDflt = pCol->pDflt; |
| 123005 | + pDflt = sqlite3ColumnExpr(pFKey->pFrom, pCol); |
| 122874 | 123006 | } |
| 122875 | 123007 | if( pDflt ){ |
| 122876 | 123008 | pNew = sqlite3ExprDup(db, pDflt, 0); |
| 122877 | 123009 | }else{ |
| 122878 | 123010 | pNew = sqlite3ExprAlloc(db, TK_NULL, 0, 0); |
| | @@ -123005,13 +123137,13 @@ |
| 123005 | 123137 | */ |
| 123006 | 123138 | SQLITE_PRIVATE void sqlite3FkDelete(sqlite3 *db, Table *pTab){ |
| 123007 | 123139 | FKey *pFKey; /* Iterator variable */ |
| 123008 | 123140 | FKey *pNext; /* Copy of pFKey->pNextFrom */ |
| 123009 | 123141 | |
| 123010 | | - assert( db==0 || IsVirtual(pTab) |
| 123011 | | - || sqlite3SchemaMutexHeld(db, 0, pTab->pSchema) ); |
| 123012 | | - for(pFKey=pTab->pFKey; pFKey; pFKey=pNext){ |
| 123142 | + assert( !IsVirtual(pTab) ); |
| 123143 | + for(pFKey=pTab->u.tab.pFKey; pFKey; pFKey=pNext){ |
| 123144 | + assert( db==0 || sqlite3SchemaMutexHeld(db, 0, pTab->pSchema) ); |
| 123013 | 123145 | |
| 123014 | 123146 | /* Remove the FK from the fkeyHash hash table. */ |
| 123015 | 123147 | if( !db || db->pnBytesFreed==0 ){ |
| 123016 | 123148 | if( pFKey->pPrevTo ){ |
| 123017 | 123149 | pFKey->pPrevTo->pNextTo = pFKey->pNextTo; |
| | @@ -123157,11 +123289,11 @@ |
| 123157 | 123289 | |
| 123158 | 123290 | /* |
| 123159 | 123291 | ** Compute the affinity string for table pTab, if it has not already been |
| 123160 | 123292 | ** computed. As an optimization, omit trailing SQLITE_AFF_BLOB affinities. |
| 123161 | 123293 | ** |
| 123162 | | -** If the affinity exists (if it is no entirely SQLITE_AFF_BLOB values) and |
| 123294 | +** If the affinity exists (if it is not entirely SQLITE_AFF_BLOB values) and |
| 123163 | 123295 | ** if iReg>0 then code an OP_Affinity opcode that will set the affinities |
| 123164 | 123296 | ** for register iReg and following. Or if affinities exists and iReg==0, |
| 123165 | 123297 | ** then just set the P4 operand of the previous opcode (which should be |
| 123166 | 123298 | ** an OP_MakeRecord) to the affinity string. |
| 123167 | 123299 | ** |
| | @@ -123337,26 +123469,26 @@ |
| 123337 | 123469 | Column *pCol = pTab->aCol + i; |
| 123338 | 123470 | if( (pCol->colFlags & COLFLAG_NOTAVAIL)!=0 ){ |
| 123339 | 123471 | int x; |
| 123340 | 123472 | pCol->colFlags |= COLFLAG_BUSY; |
| 123341 | 123473 | w.eCode = 0; |
| 123342 | | - sqlite3WalkExpr(&w, pCol->pDflt); |
| 123474 | + sqlite3WalkExpr(&w, sqlite3ColumnExpr(pTab, pCol)); |
| 123343 | 123475 | pCol->colFlags &= ~COLFLAG_BUSY; |
| 123344 | 123476 | if( w.eCode & COLFLAG_NOTAVAIL ){ |
| 123345 | 123477 | pRedo = pCol; |
| 123346 | 123478 | continue; |
| 123347 | 123479 | } |
| 123348 | 123480 | eProgress = 1; |
| 123349 | 123481 | assert( pCol->colFlags & COLFLAG_GENERATED ); |
| 123350 | 123482 | x = sqlite3TableColumnToStorage(pTab, i) + iRegStore; |
| 123351 | | - sqlite3ExprCodeGeneratedColumn(pParse, pCol, x); |
| 123483 | + sqlite3ExprCodeGeneratedColumn(pParse, pTab, pCol, x); |
| 123352 | 123484 | pCol->colFlags &= ~COLFLAG_NOTAVAIL; |
| 123353 | 123485 | } |
| 123354 | 123486 | } |
| 123355 | 123487 | }while( pRedo && eProgress ); |
| 123356 | 123488 | if( pRedo ){ |
| 123357 | | - sqlite3ErrorMsg(pParse, "generated column loop on \"%s\"", pRedo->zName); |
| 123489 | + sqlite3ErrorMsg(pParse, "generated column loop on \"%s\"", pRedo->zCnName); |
| 123358 | 123490 | } |
| 123359 | 123491 | pParse->iSelfTab = 0; |
| 123360 | 123492 | } |
| 123361 | 123493 | #endif /* SQLITE_OMIT_GENERATED_COLUMNS */ |
| 123362 | 123494 | |
| | @@ -123747,11 +123879,11 @@ |
| 123747 | 123879 | /* Figure out if we have any triggers and if the table being |
| 123748 | 123880 | ** inserted into is a view |
| 123749 | 123881 | */ |
| 123750 | 123882 | #ifndef SQLITE_OMIT_TRIGGER |
| 123751 | 123883 | pTrigger = sqlite3TriggersExist(pParse, pTab, TK_INSERT, 0, &tmask); |
| 123752 | | - isView = pTab->pSelect!=0; |
| 123884 | + isView = IsView(pTab); |
| 123753 | 123885 | #else |
| 123754 | 123886 | # define pTrigger 0 |
| 123755 | 123887 | # define tmask 0 |
| 123756 | 123888 | # define isView 0 |
| 123757 | 123889 | #endif |
| | @@ -123838,21 +123970,21 @@ |
| 123838 | 123970 | for(i=0; i<pColumn->nId; i++){ |
| 123839 | 123971 | pColumn->a[i].idx = -1; |
| 123840 | 123972 | } |
| 123841 | 123973 | for(i=0; i<pColumn->nId; i++){ |
| 123842 | 123974 | for(j=0; j<pTab->nCol; j++){ |
| 123843 | | - if( sqlite3StrICmp(pColumn->a[i].zName, pTab->aCol[j].zName)==0 ){ |
| 123975 | + if( sqlite3StrICmp(pColumn->a[i].zName, pTab->aCol[j].zCnName)==0 ){ |
| 123844 | 123976 | pColumn->a[i].idx = j; |
| 123845 | 123977 | if( i!=j ) bIdListInOrder = 0; |
| 123846 | 123978 | if( j==pTab->iPKey ){ |
| 123847 | 123979 | ipkColumn = i; assert( !withoutRowid ); |
| 123848 | 123980 | } |
| 123849 | 123981 | #ifndef SQLITE_OMIT_GENERATED_COLUMNS |
| 123850 | 123982 | if( pTab->aCol[j].colFlags & (COLFLAG_STORED|COLFLAG_VIRTUAL) ){ |
| 123851 | 123983 | sqlite3ErrorMsg(pParse, |
| 123852 | 123984 | "cannot INSERT into generated column \"%s\"", |
| 123853 | | - pTab->aCol[j].zName); |
| 123985 | + pTab->aCol[j].zCnName); |
| 123854 | 123986 | goto insert_cleanup; |
| 123855 | 123987 | } |
| 123856 | 123988 | #endif |
| 123857 | 123989 | break; |
| 123858 | 123990 | } |
| | @@ -124033,11 +124165,11 @@ |
| 124033 | 124165 | if( IsVirtual(pTab) ){ |
| 124034 | 124166 | sqlite3ErrorMsg(pParse, "UPSERT not implemented for virtual table \"%s\"", |
| 124035 | 124167 | pTab->zName); |
| 124036 | 124168 | goto insert_cleanup; |
| 124037 | 124169 | } |
| 124038 | | - if( pTab->pSelect ){ |
| 124170 | + if( IsView(pTab) ){ |
| 124039 | 124171 | sqlite3ErrorMsg(pParse, "cannot UPSERT a view"); |
| 124040 | 124172 | goto insert_cleanup; |
| 124041 | 124173 | } |
| 124042 | 124174 | if( sqlite3HasExplicitNulls(pParse, pUpsert->pUpsertTarget) ){ |
| 124043 | 124175 | goto insert_cleanup; |
| | @@ -124132,26 +124264,32 @@ |
| 124132 | 124264 | } |
| 124133 | 124265 | continue; |
| 124134 | 124266 | }else if( pColumn==0 ){ |
| 124135 | 124267 | /* Hidden columns that are not explicitly named in the INSERT |
| 124136 | 124268 | ** get there default value */ |
| 124137 | | - sqlite3ExprCodeFactorable(pParse, pTab->aCol[i].pDflt, iRegStore); |
| 124269 | + sqlite3ExprCodeFactorable(pParse, |
| 124270 | + sqlite3ColumnExpr(pTab, &pTab->aCol[i]), |
| 124271 | + iRegStore); |
| 124138 | 124272 | continue; |
| 124139 | 124273 | } |
| 124140 | 124274 | } |
| 124141 | 124275 | if( pColumn ){ |
| 124142 | 124276 | for(j=0; j<pColumn->nId && pColumn->a[j].idx!=i; j++){} |
| 124143 | 124277 | if( j>=pColumn->nId ){ |
| 124144 | 124278 | /* A column not named in the insert column list gets its |
| 124145 | 124279 | ** default value */ |
| 124146 | | - sqlite3ExprCodeFactorable(pParse, pTab->aCol[i].pDflt, iRegStore); |
| 124280 | + sqlite3ExprCodeFactorable(pParse, |
| 124281 | + sqlite3ColumnExpr(pTab, &pTab->aCol[i]), |
| 124282 | + iRegStore); |
| 124147 | 124283 | continue; |
| 124148 | 124284 | } |
| 124149 | 124285 | k = j; |
| 124150 | 124286 | }else if( nColumn==0 ){ |
| 124151 | 124287 | /* This is INSERT INTO ... DEFAULT VALUES. Load the default value. */ |
| 124152 | | - sqlite3ExprCodeFactorable(pParse, pTab->aCol[i].pDflt, iRegStore); |
| 124288 | + sqlite3ExprCodeFactorable(pParse, |
| 124289 | + sqlite3ColumnExpr(pTab, &pTab->aCol[i]), |
| 124290 | + iRegStore); |
| 124153 | 124291 | continue; |
| 124154 | 124292 | }else{ |
| 124155 | 124293 | k = i - nHidden; |
| 124156 | 124294 | } |
| 124157 | 124295 | |
| | @@ -124662,11 +124800,11 @@ |
| 124662 | 124800 | |
| 124663 | 124801 | isUpdate = regOldData!=0; |
| 124664 | 124802 | db = pParse->db; |
| 124665 | 124803 | v = pParse->pVdbe; |
| 124666 | 124804 | assert( v!=0 ); |
| 124667 | | - assert( pTab->pSelect==0 ); /* This table is not a VIEW */ |
| 124805 | + assert( !IsView(pTab) ); /* This table is not a VIEW */ |
| 124668 | 124806 | nCol = pTab->nCol; |
| 124669 | 124807 | |
| 124670 | 124808 | /* pPk is the PRIMARY KEY index for WITHOUT ROWID tables and NULL for |
| 124671 | 124809 | ** normal rowid tables. nPkField is the number of key fields in the |
| 124672 | 124810 | ** pPk index or 1 for a rowid table. In other words, nPkField is the |
| | @@ -124713,11 +124851,11 @@ |
| 124713 | 124851 | }else if( onError==OE_Default ){ |
| 124714 | 124852 | onError = OE_Abort; |
| 124715 | 124853 | } |
| 124716 | 124854 | if( onError==OE_Replace ){ |
| 124717 | 124855 | if( b2ndPass /* REPLACE becomes ABORT on the 2nd pass */ |
| 124718 | | - || pCol->pDflt==0 /* REPLACE is ABORT if no DEFAULT value */ |
| 124856 | + || pCol->iDflt==0 /* REPLACE is ABORT if no DEFAULT value */ |
| 124719 | 124857 | ){ |
| 124720 | 124858 | testcase( pCol->colFlags & COLFLAG_VIRTUAL ); |
| 124721 | 124859 | testcase( pCol->colFlags & COLFLAG_STORED ); |
| 124722 | 124860 | testcase( pCol->colFlags & COLFLAG_GENERATED ); |
| 124723 | 124861 | onError = OE_Abort; |
| | @@ -124735,21 +124873,22 @@ |
| 124735 | 124873 | case OE_Replace: { |
| 124736 | 124874 | int addr1 = sqlite3VdbeAddOp1(v, OP_NotNull, iReg); |
| 124737 | 124875 | VdbeCoverage(v); |
| 124738 | 124876 | assert( (pCol->colFlags & COLFLAG_GENERATED)==0 ); |
| 124739 | 124877 | nSeenReplace++; |
| 124740 | | - sqlite3ExprCodeCopy(pParse, pCol->pDflt, iReg); |
| 124878 | + sqlite3ExprCodeCopy(pParse, |
| 124879 | + sqlite3ColumnExpr(pTab, pCol), iReg); |
| 124741 | 124880 | sqlite3VdbeJumpHere(v, addr1); |
| 124742 | 124881 | break; |
| 124743 | 124882 | } |
| 124744 | 124883 | case OE_Abort: |
| 124745 | 124884 | sqlite3MayAbort(pParse); |
| 124746 | 124885 | /* no break */ deliberate_fall_through |
| 124747 | 124886 | case OE_Rollback: |
| 124748 | 124887 | case OE_Fail: { |
| 124749 | 124888 | char *zMsg = sqlite3MPrintf(db, "%s.%s", pTab->zName, |
| 124750 | | - pCol->zName); |
| 124889 | + pCol->zCnName); |
| 124751 | 124890 | sqlite3VdbeAddOp3(v, OP_HaltIfNull, SQLITE_CONSTRAINT_NOTNULL, |
| 124752 | 124891 | onError, iReg); |
| 124753 | 124892 | sqlite3VdbeAppendP4(v, zMsg, P4_DYNAMIC); |
| 124754 | 124893 | sqlite3VdbeChangeP5(v, P5_ConstraintNotNull); |
| 124755 | 124894 | VdbeCoverage(v); |
| | @@ -125163,11 +125302,11 @@ |
| 125163 | 125302 | VdbeComment((v, "rowid")); |
| 125164 | 125303 | }else{ |
| 125165 | 125304 | testcase( sqlite3TableColumnToStorage(pTab, iField)!=iField ); |
| 125166 | 125305 | x = sqlite3TableColumnToStorage(pTab, iField) + regNewData + 1; |
| 125167 | 125306 | sqlite3VdbeAddOp2(v, OP_SCopy, x, regIdx+i); |
| 125168 | | - VdbeComment((v, "%s", pTab->aCol[iField].zName)); |
| 125307 | + VdbeComment((v, "%s", pTab->aCol[iField].zCnName)); |
| 125169 | 125308 | } |
| 125170 | 125309 | } |
| 125171 | 125310 | sqlite3VdbeAddOp3(v, OP_MakeRecord, regIdx, pIdx->nColumn, aRegIdx[ix]); |
| 125172 | 125311 | VdbeComment((v, "for %s", pIdx->zName)); |
| 125173 | 125312 | #ifdef SQLITE_ENABLE_NULL_TRIM |
| | @@ -125222,11 +125361,11 @@ |
| 125222 | 125361 | && pPk==pIdx /* Condition 2 */ |
| 125223 | 125362 | && onError==OE_Replace /* Condition 1 */ |
| 125224 | 125363 | && ( 0==(db->flags&SQLITE_RecTriggers) || /* Condition 4 */ |
| 125225 | 125364 | 0==sqlite3TriggersExist(pParse, pTab, TK_DELETE, 0, 0)) |
| 125226 | 125365 | && ( 0==(db->flags&SQLITE_ForeignKeys) || /* Condition 5 */ |
| 125227 | | - (0==pTab->pFKey && 0==sqlite3FkReferences(pTab))) |
| 125366 | + (0==pTab->u.tab.pFKey && 0==sqlite3FkReferences(pTab))) |
| 125228 | 125367 | ){ |
| 125229 | 125368 | sqlite3VdbeResolveLabel(v, addrUniqueOk); |
| 125230 | 125369 | continue; |
| 125231 | 125370 | } |
| 125232 | 125371 | #endif /* ifndef SQLITE_ENABLE_PREUPDATE_HOOK */ |
| | @@ -125257,11 +125396,11 @@ |
| 125257 | 125396 | for(i=0; i<pPk->nKeyCol; i++){ |
| 125258 | 125397 | assert( pPk->aiColumn[i]>=0 ); |
| 125259 | 125398 | x = sqlite3TableColumnToIndex(pIdx, pPk->aiColumn[i]); |
| 125260 | 125399 | sqlite3VdbeAddOp3(v, OP_Column, iThisCur, x, regR+i); |
| 125261 | 125400 | VdbeComment((v, "%s.%s", pTab->zName, |
| 125262 | | - pTab->aCol[pPk->aiColumn[i]].zName)); |
| 125401 | + pTab->aCol[pPk->aiColumn[i]].zCnName)); |
| 125263 | 125402 | } |
| 125264 | 125403 | } |
| 125265 | 125404 | if( isUpdate ){ |
| 125266 | 125405 | /* If currently processing the PRIMARY KEY of a WITHOUT ROWID |
| 125267 | 125406 | ** table, only conflict if the new PRIMARY KEY values are actually |
| | @@ -125456,11 +125595,11 @@ |
| 125456 | 125595 | /* Records with omitted columns are only allowed for schema format |
| 125457 | 125596 | ** version 2 and later (SQLite version 3.1.4, 2005-02-20). */ |
| 125458 | 125597 | if( pTab->pSchema->file_format<2 ) return; |
| 125459 | 125598 | |
| 125460 | 125599 | for(i=pTab->nCol-1; i>0; i--){ |
| 125461 | | - if( pTab->aCol[i].pDflt!=0 ) break; |
| 125600 | + if( pTab->aCol[i].iDflt!=0 ) break; |
| 125462 | 125601 | if( pTab->aCol[i].colFlags & COLFLAG_PRIMKEY ) break; |
| 125463 | 125602 | } |
| 125464 | 125603 | sqlite3VdbeChangeP5(v, i+1); |
| 125465 | 125604 | } |
| 125466 | 125605 | #endif |
| | @@ -125521,11 +125660,11 @@ |
| 125521 | 125660 | || update_flags==(OPFLAG_ISUPDATE|OPFLAG_SAVEPOSITION) |
| 125522 | 125661 | ); |
| 125523 | 125662 | |
| 125524 | 125663 | v = pParse->pVdbe; |
| 125525 | 125664 | assert( v!=0 ); |
| 125526 | | - assert( pTab->pSelect==0 ); /* This table is not a VIEW */ |
| 125665 | + assert( !IsView(pTab) ); /* This table is not a VIEW */ |
| 125527 | 125666 | for(i=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, i++){ |
| 125528 | 125667 | /* All REPLACE indexes are at the end of the list */ |
| 125529 | 125668 | assert( pIdx->onError!=OE_Replace |
| 125530 | 125669 | || pIdx->pNext==0 |
| 125531 | 125670 | || pIdx->pNext->onError==OE_Replace ); |
| | @@ -125823,17 +125962,12 @@ |
| 125823 | 125962 | return 0; /* tab1 and tab2 may not be the same table */ |
| 125824 | 125963 | } |
| 125825 | 125964 | if( HasRowid(pDest)!=HasRowid(pSrc) ){ |
| 125826 | 125965 | return 0; /* source and destination must both be WITHOUT ROWID or not */ |
| 125827 | 125966 | } |
| 125828 | | -#ifndef SQLITE_OMIT_VIRTUALTABLE |
| 125829 | | - if( IsVirtual(pSrc) ){ |
| 125830 | | - return 0; /* tab2 must not be a virtual table */ |
| 125831 | | - } |
| 125832 | | -#endif |
| 125833 | | - if( pSrc->pSelect ){ |
| 125834 | | - return 0; /* tab2 may not be a view */ |
| 125967 | + if( !IsOrdinaryTable(pSrc) ){ |
| 125968 | + return 0; /* tab2 may not be a view or virtual table */ |
| 125835 | 125969 | } |
| 125836 | 125970 | if( pDest->nCol!=pSrc->nCol ){ |
| 125837 | 125971 | return 0; /* Number of columns must be the same in tab1 and tab2 */ |
| 125838 | 125972 | } |
| 125839 | 125973 | if( pDest->iPKey!=pSrc->iPKey ){ |
| | @@ -125873,33 +126007,38 @@ |
| 125873 | 126007 | /* But the transfer is only allowed if both the source and destination |
| 125874 | 126008 | ** tables have the exact same expressions for generated columns. |
| 125875 | 126009 | ** This requirement could be relaxed for VIRTUAL columns, I suppose. |
| 125876 | 126010 | */ |
| 125877 | 126011 | if( (pDestCol->colFlags & COLFLAG_GENERATED)!=0 ){ |
| 125878 | | - if( sqlite3ExprCompare(0, pSrcCol->pDflt, pDestCol->pDflt, -1)!=0 ){ |
| 126012 | + if( sqlite3ExprCompare(0, |
| 126013 | + sqlite3ColumnExpr(pSrc, pSrcCol), |
| 126014 | + sqlite3ColumnExpr(pDest, pDestCol), -1)!=0 ){ |
| 125879 | 126015 | testcase( pDestCol->colFlags & COLFLAG_VIRTUAL ); |
| 125880 | 126016 | testcase( pDestCol->colFlags & COLFLAG_STORED ); |
| 125881 | 126017 | return 0; /* Different generator expressions */ |
| 125882 | 126018 | } |
| 125883 | 126019 | } |
| 125884 | 126020 | #endif |
| 125885 | 126021 | if( pDestCol->affinity!=pSrcCol->affinity ){ |
| 125886 | 126022 | return 0; /* Affinity must be the same on all columns */ |
| 125887 | 126023 | } |
| 125888 | | - if( sqlite3_stricmp(pDestCol->zColl, pSrcCol->zColl)!=0 ){ |
| 126024 | + if( sqlite3_stricmp(sqlite3ColumnColl(pDestCol), |
| 126025 | + sqlite3ColumnColl(pSrcCol))!=0 ){ |
| 125889 | 126026 | return 0; /* Collating sequence must be the same on all columns */ |
| 125890 | 126027 | } |
| 125891 | 126028 | if( pDestCol->notNull && !pSrcCol->notNull ){ |
| 125892 | 126029 | return 0; /* tab2 must be NOT NULL if tab1 is */ |
| 125893 | 126030 | } |
| 125894 | 126031 | /* Default values for second and subsequent columns need to match. */ |
| 125895 | 126032 | if( (pDestCol->colFlags & COLFLAG_GENERATED)==0 && i>0 ){ |
| 125896 | | - assert( pDestCol->pDflt==0 || pDestCol->pDflt->op==TK_SPAN ); |
| 125897 | | - assert( pSrcCol->pDflt==0 || pSrcCol->pDflt->op==TK_SPAN ); |
| 125898 | | - if( (pDestCol->pDflt==0)!=(pSrcCol->pDflt==0) |
| 125899 | | - || (pDestCol->pDflt && strcmp(pDestCol->pDflt->u.zToken, |
| 125900 | | - pSrcCol->pDflt->u.zToken)!=0) |
| 126033 | + Expr *pDestExpr = sqlite3ColumnExpr(pDest, pDestCol); |
| 126034 | + Expr *pSrcExpr = sqlite3ColumnExpr(pSrc, pSrcCol); |
| 126035 | + assert( pDestExpr==0 || pDestExpr->op==TK_SPAN ); |
| 126036 | + assert( pSrcExpr==0 || pSrcExpr->op==TK_SPAN ); |
| 126037 | + if( (pDestExpr==0)!=(pSrcExpr==0) |
| 126038 | + || (pDestExpr!=0 && strcmp(pDestExpr->u.zToken, |
| 126039 | + pSrcExpr->u.zToken)!=0) |
| 125901 | 126040 | ){ |
| 125902 | 126041 | return 0; /* Default values must be the same for all columns */ |
| 125903 | 126042 | } |
| 125904 | 126043 | } |
| 125905 | 126044 | } |
| | @@ -125932,11 +126071,11 @@ |
| 125932 | 126071 | ** But the main beneficiary of the transfer optimization is the VACUUM |
| 125933 | 126072 | ** command, and the VACUUM command disables foreign key constraints. So |
| 125934 | 126073 | ** the extra complication to make this rule less restrictive is probably |
| 125935 | 126074 | ** not worth the effort. Ticket [6284df89debdfa61db8073e062908af0c9b6118e] |
| 125936 | 126075 | */ |
| 125937 | | - if( (db->flags & SQLITE_ForeignKeys)!=0 && pDest->pFKey!=0 ){ |
| 126076 | + if( (db->flags & SQLITE_ForeignKeys)!=0 && pDest->u.tab.pFKey!=0 ){ |
| 125938 | 126077 | return 0; |
| 125939 | 126078 | } |
| 125940 | 126079 | #endif |
| 125941 | 126080 | if( (db->flags & SQLITE_CountRows)!=0 ){ |
| 125942 | 126081 | return 0; /* xfer opt does not play well with PRAGMA count_changes */ |
| | @@ -126610,10 +126749,13 @@ |
| 126610 | 126749 | int,const char**); |
| 126611 | 126750 | void (*free_filename)(char*); |
| 126612 | 126751 | sqlite3_file *(*database_file_object)(const char*); |
| 126613 | 126752 | /* Version 3.34.0 and later */ |
| 126614 | 126753 | int (*txn_state)(sqlite3*,const char*); |
| 126754 | + /* Version 3.36.1 and later */ |
| 126755 | + sqlite3_int64 (*changes64)(sqlite3*); |
| 126756 | + sqlite3_int64 (*total_changes64)(sqlite3*); |
| 126615 | 126757 | }; |
| 126616 | 126758 | |
| 126617 | 126759 | /* |
| 126618 | 126760 | ** This is the function signature used for all extension entry points. It |
| 126619 | 126761 | ** is also defined in the file "loadext.c". |
| | @@ -127400,10 +127542,13 @@ |
| 127400 | 127542 | sqlite3_create_filename, |
| 127401 | 127543 | sqlite3_free_filename, |
| 127402 | 127544 | sqlite3_database_file_object, |
| 127403 | 127545 | /* Version 3.34.0 and later */ |
| 127404 | 127546 | sqlite3_txn_state, |
| 127547 | + /* Version 3.36.1 and later */ |
| 127548 | + sqlite3_changes64, |
| 127549 | + sqlite3_total_changes64, |
| 127405 | 127550 | }; |
| 127406 | 127551 | |
| 127407 | 127552 | /* True if x is the directory separator character |
| 127408 | 127553 | */ |
| 127409 | 127554 | #if SQLITE_OS_WIN |
| | @@ -128189,11 +128334,11 @@ |
| 128189 | 128334 | /* iArg: */ 1 }, |
| 128190 | 128335 | #endif |
| 128191 | 128336 | #if !defined(SQLITE_OMIT_INTEGRITY_CHECK) |
| 128192 | 128337 | {/* zName: */ "integrity_check", |
| 128193 | 128338 | /* ePragTyp: */ PragTyp_INTEGRITY_CHECK, |
| 128194 | | - /* ePragFlg: */ PragFlg_NeedSchema|PragFlg_Result0|PragFlg_Result1, |
| 128339 | + /* ePragFlg: */ PragFlg_NeedSchema|PragFlg_Result0|PragFlg_Result1|PragFlg_SchemaOpt, |
| 128195 | 128340 | /* ColNames: */ 0, 0, |
| 128196 | 128341 | /* iArg: */ 0 }, |
| 128197 | 128342 | #endif |
| 128198 | 128343 | #if !defined(SQLITE_OMIT_PAGER_PRAGMAS) |
| 128199 | 128344 | {/* zName: */ "journal_mode", |
| | @@ -128297,11 +128442,11 @@ |
| 128297 | 128442 | /* iArg: */ SQLITE_QueryOnly }, |
| 128298 | 128443 | #endif |
| 128299 | 128444 | #if !defined(SQLITE_OMIT_INTEGRITY_CHECK) |
| 128300 | 128445 | {/* zName: */ "quick_check", |
| 128301 | 128446 | /* ePragTyp: */ PragTyp_INTEGRITY_CHECK, |
| 128302 | | - /* ePragFlg: */ PragFlg_NeedSchema|PragFlg_Result0|PragFlg_Result1, |
| 128447 | + /* ePragFlg: */ PragFlg_NeedSchema|PragFlg_Result0|PragFlg_Result1|PragFlg_SchemaOpt, |
| 128303 | 128448 | /* ColNames: */ 0, 0, |
| 128304 | 128449 | /* iArg: */ 0 }, |
| 128305 | 128450 | #endif |
| 128306 | 128451 | #if !defined(SQLITE_OMIT_FLAG_PRAGMAS) |
| 128307 | 128452 | {/* zName: */ "read_uncommitted", |
| | @@ -129616,17 +129761,20 @@ |
| 129616 | 129761 | }else if( pPk==0 ){ |
| 129617 | 129762 | k = 1; |
| 129618 | 129763 | }else{ |
| 129619 | 129764 | for(k=1; k<=pTab->nCol && pPk->aiColumn[k-1]!=i; k++){} |
| 129620 | 129765 | } |
| 129621 | | - assert( pCol->pDflt==0 || pCol->pDflt->op==TK_SPAN || isHidden>=2 ); |
| 129766 | + assert( sqlite3ColumnExpr(pTab,pCol)==0 |
| 129767 | + || sqlite3ColumnExpr(pTab,pCol)->op==TK_SPAN |
| 129768 | + || isHidden>=2 ); |
| 129622 | 129769 | sqlite3VdbeMultiLoad(v, 1, pPragma->iArg ? "issisii" : "issisi", |
| 129623 | 129770 | i-nHidden, |
| 129624 | | - pCol->zName, |
| 129771 | + pCol->zCnName, |
| 129625 | 129772 | sqlite3ColumnType(pCol,""), |
| 129626 | 129773 | pCol->notNull ? 1 : 0, |
| 129627 | | - pCol->pDflt && isHidden<2 ? pCol->pDflt->u.zToken : 0, |
| 129774 | + isHidden>=2 || sqlite3ColumnExpr(pTab,pCol)==0 ? 0 : |
| 129775 | + sqlite3ColumnExpr(pTab,pCol)->u.zToken, |
| 129628 | 129776 | k, |
| 129629 | 129777 | isHidden); |
| 129630 | 129778 | } |
| 129631 | 129779 | } |
| 129632 | 129780 | } |
| | @@ -129689,11 +129837,11 @@ |
| 129689 | 129837 | sqlite3CodeVerifySchema(pParse, iIdxDb); |
| 129690 | 129838 | assert( pParse->nMem<=pPragma->nPragCName ); |
| 129691 | 129839 | for(i=0; i<mx; i++){ |
| 129692 | 129840 | i16 cnum = pIdx->aiColumn[i]; |
| 129693 | 129841 | sqlite3VdbeMultiLoad(v, 1, "iisX", i, cnum, |
| 129694 | | - cnum<0 ? 0 : pTab->aCol[cnum].zName); |
| 129842 | + cnum<0 ? 0 : pTab->aCol[cnum].zCnName); |
| 129695 | 129843 | if( pPragma->iArg ){ |
| 129696 | 129844 | sqlite3VdbeMultiLoad(v, 4, "isiX", |
| 129697 | 129845 | pIdx->aSortOrder[i], |
| 129698 | 129846 | pIdx->azColl[i], |
| 129699 | 129847 | i<pIdx->nKeyCol); |
| | @@ -129796,12 +129944,12 @@ |
| 129796 | 129944 | #ifndef SQLITE_OMIT_FOREIGN_KEY |
| 129797 | 129945 | case PragTyp_FOREIGN_KEY_LIST: if( zRight ){ |
| 129798 | 129946 | FKey *pFK; |
| 129799 | 129947 | Table *pTab; |
| 129800 | 129948 | pTab = sqlite3FindTable(db, zRight, zDb); |
| 129801 | | - if( pTab ){ |
| 129802 | | - pFK = pTab->pFKey; |
| 129949 | + if( pTab && !IsVirtual(pTab) ){ |
| 129950 | + pFK = pTab->u.tab.pFKey; |
| 129803 | 129951 | if( pFK ){ |
| 129804 | 129952 | int iTabDb = sqlite3SchemaToIndex(db, pTab->pSchema); |
| 129805 | 129953 | int i = 0; |
| 129806 | 129954 | pParse->nMem = 8; |
| 129807 | 129955 | sqlite3CodeVerifySchema(pParse, iTabDb); |
| | @@ -129810,11 +129958,11 @@ |
| 129810 | 129958 | for(j=0; j<pFK->nCol; j++){ |
| 129811 | 129959 | sqlite3VdbeMultiLoad(v, 1, "iissssss", |
| 129812 | 129960 | i, |
| 129813 | 129961 | j, |
| 129814 | 129962 | pFK->zTo, |
| 129815 | | - pTab->aCol[pFK->aCol[j].iFrom].zName, |
| 129963 | + pTab->aCol[pFK->aCol[j].iFrom].zCnName, |
| 129816 | 129964 | pFK->aCol[j].zCol, |
| 129817 | 129965 | actionName(pFK->aAction[1]), /* ON UPDATE */ |
| 129818 | 129966 | actionName(pFK->aAction[0]), /* ON DELETE */ |
| 129819 | 129967 | "NONE"); |
| 129820 | 129968 | } |
| | @@ -129856,19 +130004,20 @@ |
| 129856 | 130004 | k = 0; |
| 129857 | 130005 | }else{ |
| 129858 | 130006 | pTab = (Table*)sqliteHashData(k); |
| 129859 | 130007 | k = sqliteHashNext(k); |
| 129860 | 130008 | } |
| 129861 | | - if( pTab==0 || pTab->pFKey==0 ) continue; |
| 130009 | + if( pTab==0 || IsVirtual(pTab) || pTab->u.tab.pFKey==0 ) continue; |
| 129862 | 130010 | iDb = sqlite3SchemaToIndex(db, pTab->pSchema); |
| 129863 | 130011 | zDb = db->aDb[iDb].zDbSName; |
| 129864 | 130012 | sqlite3CodeVerifySchema(pParse, iDb); |
| 129865 | 130013 | sqlite3TableLock(pParse, iDb, pTab->tnum, 0, pTab->zName); |
| 129866 | 130014 | if( pTab->nCol+regRow>pParse->nMem ) pParse->nMem = pTab->nCol + regRow; |
| 129867 | 130015 | sqlite3OpenTable(pParse, 0, iDb, pTab, OP_OpenRead); |
| 129868 | 130016 | sqlite3VdbeLoadString(v, regResult, pTab->zName); |
| 129869 | | - for(i=1, pFK=pTab->pFKey; pFK; i++, pFK=pFK->pNextFrom){ |
| 130017 | + assert( !IsVirtual(pTab) ); |
| 130018 | + for(i=1, pFK=pTab->u.tab.pFKey; pFK; i++, pFK=pFK->pNextFrom){ |
| 129870 | 130019 | pParent = sqlite3FindTable(db, pFK->zTo, zDb); |
| 129871 | 130020 | if( pParent==0 ) continue; |
| 129872 | 130021 | pIdx = 0; |
| 129873 | 130022 | sqlite3TableLock(pParse, iDb, pParent->tnum, 0, pParent->zName); |
| 129874 | 130023 | x = sqlite3FkLocateIndex(pParse, pParent, pFK, &pIdx, 0); |
| | @@ -129886,11 +130035,12 @@ |
| 129886 | 130035 | } |
| 129887 | 130036 | assert( pParse->nErr>0 || pFK==0 ); |
| 129888 | 130037 | if( pFK ) break; |
| 129889 | 130038 | if( pParse->nTab<i ) pParse->nTab = i; |
| 129890 | 130039 | addrTop = sqlite3VdbeAddOp1(v, OP_Rewind, 0); VdbeCoverage(v); |
| 129891 | | - for(i=1, pFK=pTab->pFKey; pFK; i++, pFK=pFK->pNextFrom){ |
| 130040 | + assert( !IsVirtual(pTab) ); |
| 130041 | + for(i=1, pFK=pTab->u.tab.pFKey; pFK; i++, pFK=pFK->pNextFrom){ |
| 129892 | 130042 | pParent = sqlite3FindTable(db, pFK->zTo, zDb); |
| 129893 | 130043 | pIdx = 0; |
| 129894 | 130044 | aiCols = 0; |
| 129895 | 130045 | if( pParent ){ |
| 129896 | 130046 | x = sqlite3FkLocateIndex(pParse, pParent, pFK, &pIdx, &aiCols); |
| | @@ -129900,10 +130050,11 @@ |
| 129900 | 130050 | |
| 129901 | 130051 | /* Generate code to read the child key values into registers |
| 129902 | 130052 | ** regRow..regRow+n. If any of the child key values are NULL, this |
| 129903 | 130053 | ** row cannot cause an FK violation. Jump directly to addrOk in |
| 129904 | 130054 | ** this case. */ |
| 130055 | + if( regRow+pFK->nCol>pParse->nMem ) pParse->nMem = regRow+pFK->nCol; |
| 129905 | 130056 | for(j=0; j<pFK->nCol; j++){ |
| 129906 | 130057 | int iCol = aiCols ? aiCols[j] : pFK->aCol[j].iFrom; |
| 129907 | 130058 | sqlite3ExprCodeGetColumnOfTable(v, pTab, 0, iCol, regRow+j); |
| 129908 | 130059 | sqlite3VdbeAddOp2(v, OP_IsNull, regRow+j, addrOk); VdbeCoverage(v); |
| 129909 | 130060 | } |
| | @@ -130120,11 +130271,11 @@ |
| 130120 | 130271 | if( sqlite3VdbeGetOp(v,-1)->opcode==OP_Column ){ |
| 130121 | 130272 | sqlite3VdbeChangeP5(v, OPFLAG_TYPEOFARG); |
| 130122 | 130273 | } |
| 130123 | 130274 | jmp2 = sqlite3VdbeAddOp1(v, OP_NotNull, 3); VdbeCoverage(v); |
| 130124 | 130275 | zErr = sqlite3MPrintf(db, "NULL value in %s.%s", pTab->zName, |
| 130125 | | - pTab->aCol[j].zName); |
| 130276 | + pTab->aCol[j].zCnName); |
| 130126 | 130277 | sqlite3VdbeAddOp4(v, OP_String8, 0, 3, 0, zErr, P4_DYNAMIC); |
| 130127 | 130278 | integrityCheckResultRow(v); |
| 130128 | 130279 | sqlite3VdbeJumpHere(v, jmp2); |
| 130129 | 130280 | } |
| 130130 | 130281 | /* Verify CHECK constraints */ |
| | @@ -132328,11 +132479,11 @@ |
| 132328 | 132479 | SQLITE_PRIVATE int sqlite3ColumnIndex(Table *pTab, const char *zCol){ |
| 132329 | 132480 | int i; |
| 132330 | 132481 | u8 h = sqlite3StrIHash(zCol); |
| 132331 | 132482 | Column *pCol; |
| 132332 | 132483 | for(pCol=pTab->aCol, i=0; i<pTab->nCol; pCol++, i++){ |
| 132333 | | - if( pCol->hName==h && sqlite3StrICmp(pCol->zName, zCol)==0 ) return i; |
| 132484 | + if( pCol->hName==h && sqlite3StrICmp(pCol->zCnName, zCol)==0 ) return i; |
| 132334 | 132485 | } |
| 132335 | 132486 | return -1; |
| 132336 | 132487 | } |
| 132337 | 132488 | |
| 132338 | 132489 | /* |
| | @@ -132527,11 +132678,11 @@ |
| 132527 | 132678 | char *zName; /* Name of column in the right table */ |
| 132528 | 132679 | int iLeft; /* Matching left table */ |
| 132529 | 132680 | int iLeftCol; /* Matching column in the left table */ |
| 132530 | 132681 | |
| 132531 | 132682 | if( IsHiddenColumn(&pRightTab->aCol[j]) ) continue; |
| 132532 | | - zName = pRightTab->aCol[j].zName; |
| 132683 | + zName = pRightTab->aCol[j].zCnName; |
| 132533 | 132684 | if( tableAndColumnIndex(pSrc, i+1, zName, &iLeft, &iLeftCol, 1) ){ |
| 132534 | 132685 | addWhereTerm(pParse, pSrc, iLeft, iLeftCol, i+1, j, |
| 132535 | 132686 | isOuter, &p->pWhere); |
| 132536 | 132687 | } |
| 132537 | 132688 | } |
| | @@ -132930,11 +133081,13 @@ |
| 132930 | 133081 | Parse *pParse, /* Parsing and code generating context */ |
| 132931 | 133082 | int eTnctType, /* WHERE_DISTINCT_* value */ |
| 132932 | 133083 | int iVal, /* Value returned by codeDistinct() */ |
| 132933 | 133084 | int iOpenEphAddr /* Address of OP_OpenEphemeral instruction for iTab */ |
| 132934 | 133085 | ){ |
| 132935 | | - if( eTnctType==WHERE_DISTINCT_UNIQUE || eTnctType==WHERE_DISTINCT_ORDERED ){ |
| 133086 | + if( pParse->nErr==0 |
| 133087 | + && (eTnctType==WHERE_DISTINCT_UNIQUE || eTnctType==WHERE_DISTINCT_ORDERED) |
| 133088 | + ){ |
| 132936 | 133089 | Vdbe *v = pParse->pVdbe; |
| 132937 | 133090 | sqlite3VdbeChangeToNoop(v, iOpenEphAddr); |
| 132938 | 133091 | if( sqlite3VdbeGetOp(v, iOpenEphAddr+1)->opcode==OP_Explain ){ |
| 132939 | 133092 | sqlite3VdbeChangeToNoop(v, iOpenEphAddr+1); |
| 132940 | 133093 | } |
| | @@ -133892,11 +134045,11 @@ |
| 133892 | 134045 | assert( iCol==XN_ROWID || (iCol>=0 && iCol<pTab->nCol) ); |
| 133893 | 134046 | if( iCol<0 ){ |
| 133894 | 134047 | zType = "INTEGER"; |
| 133895 | 134048 | zOrigCol = "rowid"; |
| 133896 | 134049 | }else{ |
| 133897 | | - zOrigCol = pTab->aCol[iCol].zName; |
| 134050 | + zOrigCol = pTab->aCol[iCol].zCnName; |
| 133898 | 134051 | zType = sqlite3ColumnType(&pTab->aCol[iCol],0); |
| 133899 | 134052 | } |
| 133900 | 134053 | zOrigTab = pTab->zName; |
| 133901 | 134054 | if( pNC->pParse && pTab->pSchema ){ |
| 133902 | 134055 | int iDb = sqlite3SchemaToIndex(pNC->pParse->db, pTab->pSchema); |
| | @@ -134064,11 +134217,11 @@ |
| 134064 | 134217 | if( iCol<0 ) iCol = pTab->iPKey; |
| 134065 | 134218 | assert( iCol==-1 || (iCol>=0 && iCol<pTab->nCol) ); |
| 134066 | 134219 | if( iCol<0 ){ |
| 134067 | 134220 | zCol = "rowid"; |
| 134068 | 134221 | }else{ |
| 134069 | | - zCol = pTab->aCol[iCol].zName; |
| 134222 | + zCol = pTab->aCol[iCol].zCnName; |
| 134070 | 134223 | } |
| 134071 | 134224 | if( fullName ){ |
| 134072 | 134225 | char *zName = 0; |
| 134073 | 134226 | zName = sqlite3MPrintf(db, "%s.%s", pTab->zName, zCol); |
| 134074 | 134227 | sqlite3VdbeSetColName(v, i, COLNAME_NAME, zName, SQLITE_DYNAMIC); |
| | @@ -134149,11 +134302,11 @@ |
| 134149 | 134302 | } |
| 134150 | 134303 | if( pColExpr->op==TK_COLUMN && (pTab = pColExpr->y.pTab)!=0 ){ |
| 134151 | 134304 | /* For columns use the column name name */ |
| 134152 | 134305 | int iCol = pColExpr->iColumn; |
| 134153 | 134306 | if( iCol<0 ) iCol = pTab->iPKey; |
| 134154 | | - zName = iCol>=0 ? pTab->aCol[iCol].zName : "rowid"; |
| 134307 | + zName = iCol>=0 ? pTab->aCol[iCol].zCnName : "rowid"; |
| 134155 | 134308 | }else if( pColExpr->op==TK_ID ){ |
| 134156 | 134309 | assert( !ExprHasProperty(pColExpr, EP_IntValue) ); |
| 134157 | 134310 | zName = pColExpr->u.zToken; |
| 134158 | 134311 | }else{ |
| 134159 | 134312 | /* Use the original text of the column expression as its name */ |
| | @@ -134177,21 +134330,21 @@ |
| 134177 | 134330 | if( zName[j]==':' ) nName = j; |
| 134178 | 134331 | } |
| 134179 | 134332 | zName = sqlite3MPrintf(db, "%.*z:%u", nName, zName, ++cnt); |
| 134180 | 134333 | if( cnt>3 ) sqlite3_randomness(sizeof(cnt), &cnt); |
| 134181 | 134334 | } |
| 134182 | | - pCol->zName = zName; |
| 134335 | + pCol->zCnName = zName; |
| 134183 | 134336 | pCol->hName = sqlite3StrIHash(zName); |
| 134184 | 134337 | sqlite3ColumnPropertiesFromName(0, pCol); |
| 134185 | 134338 | if( zName && sqlite3HashInsert(&ht, zName, pCol)==pCol ){ |
| 134186 | 134339 | sqlite3OomFault(db); |
| 134187 | 134340 | } |
| 134188 | 134341 | } |
| 134189 | 134342 | sqlite3HashClear(&ht); |
| 134190 | 134343 | if( db->mallocFailed ){ |
| 134191 | 134344 | for(j=0; j<i; j++){ |
| 134192 | | - sqlite3DbFree(db, aCol[j].zName); |
| 134345 | + sqlite3DbFree(db, aCol[j].zCnName); |
| 134193 | 134346 | } |
| 134194 | 134347 | sqlite3DbFree(db, aCol); |
| 134195 | 134348 | *paCol = 0; |
| 134196 | 134349 | *pnCol = 0; |
| 134197 | 134350 | return SQLITE_NOMEM_BKPT; |
| | @@ -134239,21 +134392,22 @@ |
| 134239 | 134392 | zType = columnType(&sNC, p, 0, 0, 0); |
| 134240 | 134393 | /* pCol->szEst = ... // Column size est for SELECT tables never used */ |
| 134241 | 134394 | pCol->affinity = sqlite3ExprAffinity(p); |
| 134242 | 134395 | if( zType ){ |
| 134243 | 134396 | m = sqlite3Strlen30(zType); |
| 134244 | | - n = sqlite3Strlen30(pCol->zName); |
| 134245 | | - pCol->zName = sqlite3DbReallocOrFree(db, pCol->zName, n+m+2); |
| 134246 | | - if( pCol->zName ){ |
| 134247 | | - memcpy(&pCol->zName[n+1], zType, m+1); |
| 134397 | + n = sqlite3Strlen30(pCol->zCnName); |
| 134398 | + pCol->zCnName = sqlite3DbReallocOrFree(db, pCol->zCnName, n+m+2); |
| 134399 | + if( pCol->zCnName ){ |
| 134400 | + memcpy(&pCol->zCnName[n+1], zType, m+1); |
| 134248 | 134401 | pCol->colFlags |= COLFLAG_HASTYPE; |
| 134249 | 134402 | } |
| 134250 | 134403 | } |
| 134251 | 134404 | if( pCol->affinity<=SQLITE_AFF_NONE ) pCol->affinity = aff; |
| 134252 | 134405 | pColl = sqlite3ExprCollSeq(pParse, p); |
| 134253 | | - if( pColl && pCol->zColl==0 ){ |
| 134254 | | - pCol->zColl = sqlite3DbStrDup(db, pColl->zName); |
| 134406 | + if( pColl && (pCol->colFlags & COLFLAG_HASCOLL)==0 ){ |
| 134407 | + assert( pTab->pIndex==0 ); |
| 134408 | + sqlite3ColumnSetColl(db, pCol, pColl->zName); |
| 134255 | 134409 | } |
| 134256 | 134410 | } |
| 134257 | 134411 | pTab->szTabRow = 1; /* Any non-zero value works */ |
| 134258 | 134412 | } |
| 134259 | 134413 | |
| | @@ -135811,14 +135965,14 @@ |
| 135811 | 135965 | /* |
| 135812 | 135966 | ** Assign new cursor numbers to each of the items in pSrc. For each |
| 135813 | 135967 | ** new cursor number assigned, set an entry in the aCsrMap[] array |
| 135814 | 135968 | ** to map the old cursor number to the new: |
| 135815 | 135969 | ** |
| 135816 | | -** aCsrMap[iOld] = iNew; |
| 135970 | +** aCsrMap[iOld+1] = iNew; |
| 135817 | 135971 | ** |
| 135818 | 135972 | ** The array is guaranteed by the caller to be large enough for all |
| 135819 | | -** existing cursor numbers in pSrc. |
| 135973 | +** existing cursor numbers in pSrc. aCsrMap[0] is the array size. |
| 135820 | 135974 | ** |
| 135821 | 135975 | ** If pSrc contains any sub-selects, call this routine recursively |
| 135822 | 135976 | ** on the FROM clause of each such sub-select, with iExcept set to -1. |
| 135823 | 135977 | */ |
| 135824 | 135978 | static void srclistRenumberCursors( |
| | @@ -135830,33 +135984,44 @@ |
| 135830 | 135984 | int i; |
| 135831 | 135985 | SrcItem *pItem; |
| 135832 | 135986 | for(i=0, pItem=pSrc->a; i<pSrc->nSrc; i++, pItem++){ |
| 135833 | 135987 | if( i!=iExcept ){ |
| 135834 | 135988 | Select *p; |
| 135835 | | - if( !pItem->fg.isRecursive || aCsrMap[pItem->iCursor]==0 ){ |
| 135836 | | - aCsrMap[pItem->iCursor] = pParse->nTab++; |
| 135989 | + assert( pItem->iCursor < aCsrMap[0] ); |
| 135990 | + if( !pItem->fg.isRecursive || aCsrMap[pItem->iCursor+1]==0 ){ |
| 135991 | + aCsrMap[pItem->iCursor+1] = pParse->nTab++; |
| 135837 | 135992 | } |
| 135838 | | - pItem->iCursor = aCsrMap[pItem->iCursor]; |
| 135993 | + pItem->iCursor = aCsrMap[pItem->iCursor+1]; |
| 135839 | 135994 | for(p=pItem->pSelect; p; p=p->pPrior){ |
| 135840 | 135995 | srclistRenumberCursors(pParse, aCsrMap, p->pSrc, -1); |
| 135841 | 135996 | } |
| 135842 | 135997 | } |
| 135843 | 135998 | } |
| 135844 | 135999 | } |
| 136000 | + |
| 136001 | +/* |
| 136002 | +** *piCursor is a cursor number. Change it if it needs to be mapped. |
| 136003 | +*/ |
| 136004 | +static void renumberCursorDoMapping(Walker *pWalker, int *piCursor){ |
| 136005 | + int *aCsrMap = pWalker->u.aiCol; |
| 136006 | + int iCsr = *piCursor; |
| 136007 | + if( iCsr < aCsrMap[0] && aCsrMap[iCsr+1]>0 ){ |
| 136008 | + *piCursor = aCsrMap[iCsr+1]; |
| 136009 | + } |
| 136010 | +} |
| 135845 | 136011 | |
| 135846 | 136012 | /* |
| 135847 | 136013 | ** Expression walker callback used by renumberCursors() to update |
| 135848 | 136014 | ** Expr objects to match newly assigned cursor numbers. |
| 135849 | 136015 | */ |
| 135850 | 136016 | static int renumberCursorsCb(Walker *pWalker, Expr *pExpr){ |
| 135851 | | - int *aCsrMap = pWalker->u.aiCol; |
| 135852 | 136017 | int op = pExpr->op; |
| 135853 | | - if( (op==TK_COLUMN || op==TK_IF_NULL_ROW) && aCsrMap[pExpr->iTable] ){ |
| 135854 | | - pExpr->iTable = aCsrMap[pExpr->iTable]; |
| 136018 | + if( op==TK_COLUMN || op==TK_IF_NULL_ROW ){ |
| 136019 | + renumberCursorDoMapping(pWalker, &pExpr->iTable); |
| 135855 | 136020 | } |
| 135856 | | - if( ExprHasProperty(pExpr, EP_FromJoin) && aCsrMap[pExpr->iRightJoinTable] ){ |
| 135857 | | - pExpr->iRightJoinTable = aCsrMap[pExpr->iRightJoinTable]; |
| 136021 | + if( ExprHasProperty(pExpr, EP_FromJoin) ){ |
| 136022 | + renumberCursorDoMapping(pWalker, &pExpr->iRightJoinTable); |
| 135858 | 136023 | } |
| 135859 | 136024 | return WRC_Continue; |
| 135860 | 136025 | } |
| 135861 | 136026 | |
| 135862 | 136027 | /* |
| | @@ -136196,11 +136361,12 @@ |
| 136196 | 136361 | /* Restriction (23) */ |
| 136197 | 136362 | if( (p->selFlags & SF_Recursive) ) return 0; |
| 136198 | 136363 | |
| 136199 | 136364 | if( pSrc->nSrc>1 ){ |
| 136200 | 136365 | if( pParse->nSelect>500 ) return 0; |
| 136201 | | - aCsrMap = sqlite3DbMallocZero(db, pParse->nTab*sizeof(int)); |
| 136366 | + aCsrMap = sqlite3DbMallocZero(db, (pParse->nTab+1)*sizeof(int)); |
| 136367 | + if( aCsrMap ) aCsrMap[0] = pParse->nTab; |
| 136202 | 136368 | } |
| 136203 | 136369 | } |
| 136204 | 136370 | |
| 136205 | 136371 | /***** If we reach this point, flattening is permitted. *****/ |
| 136206 | 136372 | SELECTTRACE(1,pParse,p,("flatten %u.%p from term %d\n", |
| | @@ -136976,11 +137142,11 @@ |
| 136976 | 137142 | ){ |
| 136977 | 137143 | return 0; |
| 136978 | 137144 | } |
| 136979 | 137145 | pTab = p->pSrc->a[0].pTab; |
| 136980 | 137146 | pExpr = p->pEList->a[0].pExpr; |
| 136981 | | - assert( pTab && !pTab->pSelect && pExpr ); |
| 137147 | + assert( pTab && !IsView(pTab) && pExpr ); |
| 136982 | 137148 | |
| 136983 | 137149 | if( IsVirtual(pTab) ) return 0; |
| 136984 | 137150 | if( pExpr->op!=TK_AGG_FUNCTION ) return 0; |
| 136985 | 137151 | if( NEVER(pAggInfo->nFunc==0) ) return 0; |
| 136986 | 137152 | if( (pAggInfo->aFunc[0].pFunc->funcFlags&SQLITE_FUNC_COUNT)==0 ) return 0; |
| | @@ -137521,34 +137687,35 @@ |
| 137521 | 137687 | pTab->nTabRef++; |
| 137522 | 137688 | if( !IsVirtual(pTab) && cannotBeFunction(pParse, pFrom) ){ |
| 137523 | 137689 | return WRC_Abort; |
| 137524 | 137690 | } |
| 137525 | 137691 | #if !defined(SQLITE_OMIT_VIEW) || !defined(SQLITE_OMIT_VIRTUALTABLE) |
| 137526 | | - if( IsVirtual(pTab) || pTab->pSelect ){ |
| 137692 | + if( !IsOrdinaryTable(pTab) ){ |
| 137527 | 137693 | i16 nCol; |
| 137528 | 137694 | u8 eCodeOrig = pWalker->eCode; |
| 137529 | 137695 | if( sqlite3ViewGetColumnNames(pParse, pTab) ) return WRC_Abort; |
| 137530 | 137696 | assert( pFrom->pSelect==0 ); |
| 137531 | | - if( pTab->pSelect |
| 137532 | | - && (db->flags & SQLITE_EnableView)==0 |
| 137533 | | - && pTab->pSchema!=db->aDb[1].pSchema |
| 137534 | | - ){ |
| 137535 | | - sqlite3ErrorMsg(pParse, "access to view \"%s\" prohibited", |
| 137536 | | - pTab->zName); |
| 137537 | | - } |
| 137697 | + if( IsView(pTab) ){ |
| 137698 | + if( (db->flags & SQLITE_EnableView)==0 |
| 137699 | + && pTab->pSchema!=db->aDb[1].pSchema |
| 137700 | + ){ |
| 137701 | + sqlite3ErrorMsg(pParse, "access to view \"%s\" prohibited", |
| 137702 | + pTab->zName); |
| 137703 | + } |
| 137704 | + pFrom->pSelect = sqlite3SelectDup(db, pTab->u.view.pSelect, 0); |
| 137705 | + }else |
| 137538 | 137706 | #ifndef SQLITE_OMIT_VIRTUALTABLE |
| 137539 | | - assert( SQLITE_VTABRISK_Normal==1 && SQLITE_VTABRISK_High==2 ); |
| 137540 | | - if( IsVirtual(pTab) |
| 137707 | + if( ALWAYS(IsVirtual(pTab)) |
| 137541 | 137708 | && pFrom->fg.fromDDL |
| 137542 | | - && ALWAYS(pTab->pVTable!=0) |
| 137543 | | - && pTab->pVTable->eVtabRisk > ((db->flags & SQLITE_TrustedSchema)!=0) |
| 137709 | + && ALWAYS(pTab->u.vtab.p!=0) |
| 137710 | + && pTab->u.vtab.p->eVtabRisk > ((db->flags & SQLITE_TrustedSchema)!=0) |
| 137544 | 137711 | ){ |
| 137545 | 137712 | sqlite3ErrorMsg(pParse, "unsafe use of virtual table \"%s\"", |
| 137546 | 137713 | pTab->zName); |
| 137547 | 137714 | } |
| 137715 | + assert( SQLITE_VTABRISK_Normal==1 && SQLITE_VTABRISK_High==2 ); |
| 137548 | 137716 | #endif |
| 137549 | | - pFrom->pSelect = sqlite3SelectDup(db, pTab->pSelect, 0); |
| 137550 | 137717 | nCol = pTab->nCol; |
| 137551 | 137718 | pTab->nCol = -1; |
| 137552 | 137719 | pWalker->eCode = 1; /* Turn on Select.selId renumbering */ |
| 137553 | 137720 | sqlite3WalkSelect(pWalker, pFrom->pSelect); |
| 137554 | 137721 | pWalker->eCode = eCodeOrig; |
| | @@ -137644,11 +137811,11 @@ |
| 137644 | 137811 | } |
| 137645 | 137812 | iDb = sqlite3SchemaToIndex(db, pTab->pSchema); |
| 137646 | 137813 | zSchemaName = iDb>=0 ? db->aDb[iDb].zDbSName : "*"; |
| 137647 | 137814 | } |
| 137648 | 137815 | for(j=0; j<pTab->nCol; j++){ |
| 137649 | | - char *zName = pTab->aCol[j].zName; |
| 137816 | + char *zName = pTab->aCol[j].zCnName; |
| 137650 | 137817 | char *zColname; /* The computed column name */ |
| 137651 | 137818 | char *zToFree; /* Malloced string that needs to be freed */ |
| 137652 | 137819 | Token sColname; /* Computed column name as a token */ |
| 137653 | 137820 | |
| 137654 | 137821 | assert( zName ); |
| | @@ -138076,12 +138243,20 @@ |
| 138076 | 138243 | ** within the HAVING expression with a constant "1". |
| 138077 | 138244 | */ |
| 138078 | 138245 | static int havingToWhereExprCb(Walker *pWalker, Expr *pExpr){ |
| 138079 | 138246 | if( pExpr->op!=TK_AND ){ |
| 138080 | 138247 | Select *pS = pWalker->u.pSelect; |
| 138248 | + /* This routine is called before the HAVING clause of the current |
| 138249 | + ** SELECT is analyzed for aggregates. So if pExpr->pAggInfo is set |
| 138250 | + ** here, it indicates that the expression is a correlated reference to a |
| 138251 | + ** column from an outer aggregate query, or an aggregate function that |
| 138252 | + ** belongs to an outer query. Do not move the expression to the WHERE |
| 138253 | + ** clause in this obscure case, as doing so may corrupt the outer Select |
| 138254 | + ** statements AggInfo structure. */ |
| 138081 | 138255 | if( sqlite3ExprIsConstantOrGroupBy(pWalker->pParse, pExpr, pS->pGroupBy) |
| 138082 | 138256 | && ExprAlwaysFalse(pExpr)==0 |
| 138257 | + && pExpr->pAggInfo==0 |
| 138083 | 138258 | ){ |
| 138084 | 138259 | sqlite3 *db = pWalker->pParse->db; |
| 138085 | 138260 | Expr *pNew = sqlite3Expr(db, TK_INTEGER, "1"); |
| 138086 | 138261 | if( pNew ){ |
| 138087 | 138262 | Expr *pWhere = pS->pWhere; |
| | @@ -138343,15 +138518,20 @@ |
| 138343 | 138518 | SELECTTRACE(0x104,pParse,p, ("after name resolution:\n")); |
| 138344 | 138519 | sqlite3TreeViewSelect(0, p, 0); |
| 138345 | 138520 | } |
| 138346 | 138521 | #endif |
| 138347 | 138522 | |
| 138348 | | - /* If the SF_UpdateFrom flag is set, then this function is being called |
| 138523 | + /* If the SF_UFSrcCheck flag is set, then this function is being called |
| 138349 | 138524 | ** as part of populating the temp table for an UPDATE...FROM statement. |
| 138350 | 138525 | ** In this case, it is an error if the target object (pSrc->a[0]) name |
| 138351 | | - ** or alias is duplicated within FROM clause (pSrc->a[1..n]). */ |
| 138352 | | - if( p->selFlags & SF_UpdateFrom ){ |
| 138526 | + ** or alias is duplicated within FROM clause (pSrc->a[1..n]). |
| 138527 | + ** |
| 138528 | + ** Postgres disallows this case too. The reason is that some other |
| 138529 | + ** systems handle this case differently, and not all the same way, |
| 138530 | + ** which is just confusing. To avoid this, we follow PG's lead and |
| 138531 | + ** disallow it altogether. */ |
| 138532 | + if( p->selFlags & SF_UFSrcCheck ){ |
| 138353 | 138533 | SrcItem *p0 = &p->pSrc->a[0]; |
| 138354 | 138534 | for(i=1; i<p->pSrc->nSrc; i++){ |
| 138355 | 138535 | SrcItem *p1 = &p->pSrc->a[i]; |
| 138356 | 138536 | if( p0->pTab==p1->pTab && 0==sqlite3_stricmp(p0->zAlias, p1->zAlias) ){ |
| 138357 | 138537 | sqlite3ErrorMsg(pParse, |
| | @@ -138359,10 +138539,16 @@ |
| 138359 | 138539 | p0->zAlias ? p0->zAlias : p0->pTab->zName |
| 138360 | 138540 | ); |
| 138361 | 138541 | goto select_end; |
| 138362 | 138542 | } |
| 138363 | 138543 | } |
| 138544 | + |
| 138545 | + /* Clear the SF_UFSrcCheck flag. The check has already been performed, |
| 138546 | + ** and leaving this flag set can cause errors if a compound sub-query |
| 138547 | + ** in p->pSrc is flattened into this query and this function called |
| 138548 | + ** again as part of compound SELECT processing. */ |
| 138549 | + p->selFlags &= ~SF_UFSrcCheck; |
| 138364 | 138550 | } |
| 138365 | 138551 | |
| 138366 | 138552 | if( pDest->eDest==SRT_Output ){ |
| 138367 | 138553 | sqlite3GenerateColumnNames(pParse, p); |
| 138368 | 138554 | } |
| | @@ -138429,10 +138615,43 @@ |
| 138429 | 138615 | ** will be implemented as a co-routine and there is no advantage to |
| 138430 | 138616 | ** flattening in that case. |
| 138431 | 138617 | */ |
| 138432 | 138618 | if( (pSub->selFlags & SF_Aggregate)!=0 ) continue; |
| 138433 | 138619 | assert( pSub->pGroupBy==0 ); |
| 138620 | + |
| 138621 | + /* If a FROM-clause subquery has an ORDER BY clause that is not |
| 138622 | + ** really doing anything, then delete it now so that it does not |
| 138623 | + ** interfere with query flattening. See the discussion at |
| 138624 | + ** https://sqlite.org/forum/forumpost/2d76f2bcf65d256a |
| 138625 | + ** |
| 138626 | + ** Beware of these cases where the ORDER BY clause may not be safely |
| 138627 | + ** omitted: |
| 138628 | + ** |
| 138629 | + ** (1) There is also a LIMIT clause |
| 138630 | + ** (2) The subquery was added to help with window-function |
| 138631 | + ** processing |
| 138632 | + ** (3) The subquery is in the FROM clause of an UPDATE |
| 138633 | + ** (4) The outer query uses an aggregate function other than |
| 138634 | + ** the built-in count(), min(), or max(). |
| 138635 | + ** (5) The ORDER BY isn't going to accomplish anything because |
| 138636 | + ** one of: |
| 138637 | + ** (a) The outer query has a different ORDER BY clause |
| 138638 | + ** (b) The subquery is part of a join |
| 138639 | + ** See forum post 062d576715d277c8 |
| 138640 | + */ |
| 138641 | + if( pSub->pOrderBy!=0 |
| 138642 | + && (p->pOrderBy!=0 || pTabList->nSrc>1) /* Condition (5) */ |
| 138643 | + && pSub->pLimit==0 /* Condition (1) */ |
| 138644 | + && (pSub->selFlags & SF_OrderByReqd)==0 /* Condition (2) */ |
| 138645 | + && (p->selFlags & SF_OrderByReqd)==0 /* Condition (3) and (4) */ |
| 138646 | + && OptimizationEnabled(db, SQLITE_OmitOrderBy) |
| 138647 | + ){ |
| 138648 | + SELECTTRACE(0x100,pParse,p, |
| 138649 | + ("omit superfluous ORDER BY on %r FROM-clause subquery\n",i+1)); |
| 138650 | + sqlite3ExprListDelete(db, pSub->pOrderBy); |
| 138651 | + pSub->pOrderBy = 0; |
| 138652 | + } |
| 138434 | 138653 | |
| 138435 | 138654 | /* If the outer query contains a "complex" result set (that is, |
| 138436 | 138655 | ** if the result set of the outer query uses functions or subqueries) |
| 138437 | 138656 | ** and if the subquery contains an ORDER BY clause and if |
| 138438 | 138657 | ** it will be implemented as a co-routine, then do not flatten. This |
| | @@ -139877,16 +140096,16 @@ |
| 139877 | 140096 | } |
| 139878 | 140097 | |
| 139879 | 140098 | /* INSTEAD of triggers are only for views and views only support INSTEAD |
| 139880 | 140099 | ** of triggers. |
| 139881 | 140100 | */ |
| 139882 | | - if( pTab->pSelect && tr_tm!=TK_INSTEAD ){ |
| 140101 | + if( IsView(pTab) && tr_tm!=TK_INSTEAD ){ |
| 139883 | 140102 | sqlite3ErrorMsg(pParse, "cannot create %s trigger on view: %S", |
| 139884 | 140103 | (tr_tm == TK_BEFORE)?"BEFORE":"AFTER", pTableName->a); |
| 139885 | 140104 | goto trigger_orphan_error; |
| 139886 | 140105 | } |
| 139887 | | - if( !pTab->pSelect && tr_tm==TK_INSTEAD ){ |
| 140106 | + if( !IsView(pTab) && tr_tm==TK_INSTEAD ){ |
| 139888 | 140107 | sqlite3ErrorMsg(pParse, "cannot create INSTEAD OF" |
| 139889 | 140108 | " trigger on table: %S", pTableName->a); |
| 139890 | 140109 | goto trigger_orphan_error; |
| 139891 | 140110 | } |
| 139892 | 140111 | |
| | @@ -140535,15 +140754,15 @@ |
| 140535 | 140754 | if( isAsteriskTerm(pParse, pOldExpr) ){ |
| 140536 | 140755 | int jj; |
| 140537 | 140756 | for(jj=0; jj<pTab->nCol; jj++){ |
| 140538 | 140757 | Expr *pNewExpr; |
| 140539 | 140758 | if( IsHiddenColumn(pTab->aCol+jj) ) continue; |
| 140540 | | - pNewExpr = sqlite3Expr(db, TK_ID, pTab->aCol[jj].zName); |
| 140759 | + pNewExpr = sqlite3Expr(db, TK_ID, pTab->aCol[jj].zCnName); |
| 140541 | 140760 | pNew = sqlite3ExprListAppend(pParse, pNew, pNewExpr); |
| 140542 | 140761 | if( !db->mallocFailed ){ |
| 140543 | 140762 | struct ExprList_item *pItem = &pNew->a[pNew->nExpr-1]; |
| 140544 | | - pItem->zEName = sqlite3DbStrDup(db, pTab->aCol[jj].zName); |
| 140763 | + pItem->zEName = sqlite3DbStrDup(db, pTab->aCol[jj].zCnName); |
| 140545 | 140764 | pItem->eEName = ENAME_NAME; |
| 140546 | 140765 | } |
| 140547 | 140766 | } |
| 140548 | 140767 | }else{ |
| 140549 | 140768 | Expr *pNewExpr = sqlite3ExprDup(db, pOldExpr, 0); |
| | @@ -140584,10 +140803,11 @@ |
| 140584 | 140803 | memset(&sFrom, 0, sizeof(sFrom)); |
| 140585 | 140804 | sSelect.pEList = sqlite3ExprListDup(db, pReturning->pReturnEL, 0); |
| 140586 | 140805 | sSelect.pSrc = &sFrom; |
| 140587 | 140806 | sFrom.nSrc = 1; |
| 140588 | 140807 | sFrom.a[0].pTab = pTab; |
| 140808 | + sFrom.a[0].iCursor = -1; |
| 140589 | 140809 | sqlite3SelectPrep(pParse, &sSelect, 0); |
| 140590 | 140810 | if( db->mallocFailed==0 && pParse->nErr==0 ){ |
| 140591 | 140811 | sqlite3GenerateColumnNames(pParse, &sSelect); |
| 140592 | 140812 | } |
| 140593 | 140813 | sqlite3ExprListDelete(db, sSelect.pEList); |
| | @@ -141139,17 +141359,18 @@ |
| 141139 | 141359 | ** integer. In that case, add an OP_RealAffinity opcode to make sure |
| 141140 | 141360 | ** it has been converted into REAL. |
| 141141 | 141361 | */ |
| 141142 | 141362 | SQLITE_PRIVATE void sqlite3ColumnDefault(Vdbe *v, Table *pTab, int i, int iReg){ |
| 141143 | 141363 | assert( pTab!=0 ); |
| 141144 | | - if( !pTab->pSelect ){ |
| 141364 | + if( !IsView(pTab) ){ |
| 141145 | 141365 | sqlite3_value *pValue = 0; |
| 141146 | 141366 | u8 enc = ENC(sqlite3VdbeDb(v)); |
| 141147 | 141367 | Column *pCol = &pTab->aCol[i]; |
| 141148 | | - VdbeComment((v, "%s.%s", pTab->zName, pCol->zName)); |
| 141368 | + VdbeComment((v, "%s.%s", pTab->zName, pCol->zCnName)); |
| 141149 | 141369 | assert( i<pTab->nCol ); |
| 141150 | | - sqlite3ValueFromExpr(sqlite3VdbeDb(v), pCol->pDflt, enc, |
| 141370 | + sqlite3ValueFromExpr(sqlite3VdbeDb(v), |
| 141371 | + sqlite3ColumnExpr(pTab,pCol), enc, |
| 141151 | 141372 | pCol->affinity, &pValue); |
| 141152 | 141373 | if( pValue ){ |
| 141153 | 141374 | sqlite3VdbeAppendP4(v, pValue, P4_MEM); |
| 141154 | 141375 | } |
| 141155 | 141376 | } |
| | @@ -141315,11 +141536,11 @@ |
| 141315 | 141536 | } |
| 141316 | 141537 | #endif |
| 141317 | 141538 | pList = sqlite3ExprListAppend(pParse, pList, pNew); |
| 141318 | 141539 | } |
| 141319 | 141540 | eDest = IsVirtual(pTab) ? SRT_Table : SRT_Upfrom; |
| 141320 | | - }else if( pTab->pSelect ){ |
| 141541 | + }else if( IsView(pTab) ){ |
| 141321 | 141542 | for(i=0; i<pTab->nCol; i++){ |
| 141322 | 141543 | pList = sqlite3ExprListAppend(pParse, pList, exprRowColumn(pParse, i)); |
| 141323 | 141544 | } |
| 141324 | 141545 | eDest = SRT_Table; |
| 141325 | 141546 | }else{ |
| | @@ -141338,12 +141559,13 @@ |
| 141338 | 141559 | sqlite3ExprDup(db, pChanges->a[i].pExpr, 0) |
| 141339 | 141560 | ); |
| 141340 | 141561 | } |
| 141341 | 141562 | } |
| 141342 | 141563 | pSelect = sqlite3SelectNew(pParse, pList, |
| 141343 | | - pSrc, pWhere2, pGrp, 0, pOrderBy2, SF_UpdateFrom|SF_IncludeHidden, pLimit2 |
| 141564 | + pSrc, pWhere2, pGrp, 0, pOrderBy2, SF_UFSrcCheck|SF_IncludeHidden, pLimit2 |
| 141344 | 141565 | ); |
| 141566 | + if( pSelect ) pSelect->selFlags |= SF_OrderByReqd; |
| 141345 | 141567 | sqlite3SelectDestInit(&dest, eDest, iEph); |
| 141346 | 141568 | dest.iSDParm2 = (pPk ? pPk->nKeyCol : -1); |
| 141347 | 141569 | sqlite3Select(pParse, pSelect, &dest); |
| 141348 | 141570 | sqlite3SelectDelete(db, pSelect); |
| 141349 | 141571 | } |
| | @@ -141439,11 +141661,11 @@ |
| 141439 | 141661 | /* Figure out if we have any triggers and if the table being |
| 141440 | 141662 | ** updated is a view. |
| 141441 | 141663 | */ |
| 141442 | 141664 | #ifndef SQLITE_OMIT_TRIGGER |
| 141443 | 141665 | pTrigger = sqlite3TriggersExist(pParse, pTab, TK_UPDATE, pChanges, &tmask); |
| 141444 | | - isView = pTab->pSelect!=0; |
| 141666 | + isView = IsView(pTab); |
| 141445 | 141667 | assert( pTrigger || tmask==0 ); |
| 141446 | 141668 | #else |
| 141447 | 141669 | # define pTrigger 0 |
| 141448 | 141670 | # define isView 0 |
| 141449 | 141671 | # define tmask 0 |
| | @@ -141528,17 +141750,20 @@ |
| 141528 | 141750 | ** column to be updated, make sure we have authorization to change |
| 141529 | 141751 | ** that column. |
| 141530 | 141752 | */ |
| 141531 | 141753 | chngRowid = chngPk = 0; |
| 141532 | 141754 | for(i=0; i<pChanges->nExpr; i++){ |
| 141755 | + u8 hCol = sqlite3StrIHash(pChanges->a[i].zEName); |
| 141533 | 141756 | /* If this is an UPDATE with a FROM clause, do not resolve expressions |
| 141534 | 141757 | ** here. The call to sqlite3Select() below will do that. */ |
| 141535 | 141758 | if( nChangeFrom==0 && sqlite3ResolveExprNames(&sNC, pChanges->a[i].pExpr) ){ |
| 141536 | 141759 | goto update_cleanup; |
| 141537 | 141760 | } |
| 141538 | 141761 | for(j=0; j<pTab->nCol; j++){ |
| 141539 | | - if( sqlite3StrICmp(pTab->aCol[j].zName, pChanges->a[i].zEName)==0 ){ |
| 141762 | + if( pTab->aCol[j].hName==hCol |
| 141763 | + && sqlite3StrICmp(pTab->aCol[j].zCnName, pChanges->a[i].zEName)==0 |
| 141764 | + ){ |
| 141540 | 141765 | if( j==pTab->iPKey ){ |
| 141541 | 141766 | chngRowid = 1; |
| 141542 | 141767 | pRowidExpr = pChanges->a[i].pExpr; |
| 141543 | 141768 | iRowidExpr = i; |
| 141544 | 141769 | }else if( pPk && (pTab->aCol[j].colFlags & COLFLAG_PRIMKEY)!=0 ){ |
| | @@ -141548,11 +141773,11 @@ |
| 141548 | 141773 | else if( pTab->aCol[j].colFlags & COLFLAG_GENERATED ){ |
| 141549 | 141774 | testcase( pTab->aCol[j].colFlags & COLFLAG_VIRTUAL ); |
| 141550 | 141775 | testcase( pTab->aCol[j].colFlags & COLFLAG_STORED ); |
| 141551 | 141776 | sqlite3ErrorMsg(pParse, |
| 141552 | 141777 | "cannot UPDATE generated column \"%s\"", |
| 141553 | | - pTab->aCol[j].zName); |
| 141778 | + pTab->aCol[j].zCnName); |
| 141554 | 141779 | goto update_cleanup; |
| 141555 | 141780 | } |
| 141556 | 141781 | #endif |
| 141557 | 141782 | aXRef[j] = i; |
| 141558 | 141783 | break; |
| | @@ -141572,11 +141797,11 @@ |
| 141572 | 141797 | } |
| 141573 | 141798 | #ifndef SQLITE_OMIT_AUTHORIZATION |
| 141574 | 141799 | { |
| 141575 | 141800 | int rc; |
| 141576 | 141801 | rc = sqlite3AuthCheck(pParse, SQLITE_UPDATE, pTab->zName, |
| 141577 | | - j<0 ? "ROWID" : pTab->aCol[j].zName, |
| 141802 | + j<0 ? "ROWID" : pTab->aCol[j].zCnName, |
| 141578 | 141803 | db->aDb[iDb].zDbSName); |
| 141579 | 141804 | if( rc==SQLITE_DENY ){ |
| 141580 | 141805 | goto update_cleanup; |
| 141581 | 141806 | }else if( rc==SQLITE_IGNORE ){ |
| 141582 | 141807 | aXRef[j] = -1; |
| | @@ -141604,12 +141829,14 @@ |
| 141604 | 141829 | do{ |
| 141605 | 141830 | bProgress = 0; |
| 141606 | 141831 | for(i=0; i<pTab->nCol; i++){ |
| 141607 | 141832 | if( aXRef[i]>=0 ) continue; |
| 141608 | 141833 | if( (pTab->aCol[i].colFlags & COLFLAG_GENERATED)==0 ) continue; |
| 141609 | | - if( sqlite3ExprReferencesUpdatedColumn(pTab->aCol[i].pDflt, |
| 141610 | | - aXRef, chngRowid) ){ |
| 141834 | + if( sqlite3ExprReferencesUpdatedColumn( |
| 141835 | + sqlite3ColumnExpr(pTab, &pTab->aCol[i]), |
| 141836 | + aXRef, chngRowid) |
| 141837 | + ){ |
| 141611 | 141838 | aXRef[i] = 99999; |
| 141612 | 141839 | bProgress = 1; |
| 141613 | 141840 | } |
| 141614 | 141841 | } |
| 141615 | 141842 | }while( bProgress ); |
| | @@ -142697,11 +142924,11 @@ |
| 142697 | 142924 | int k; |
| 142698 | 142925 | assert( pPk->aiColumn[i]>=0 ); |
| 142699 | 142926 | k = sqlite3TableColumnToIndex(pIdx, pPk->aiColumn[i]); |
| 142700 | 142927 | sqlite3VdbeAddOp3(v, OP_Column, iCur, k, iPk+i); |
| 142701 | 142928 | VdbeComment((v, "%s.%s", pIdx->zName, |
| 142702 | | - pTab->aCol[pPk->aiColumn[i]].zName)); |
| 142929 | + pTab->aCol[pPk->aiColumn[i]].zCnName)); |
| 142703 | 142930 | } |
| 142704 | 142931 | sqlite3VdbeVerifyAbortable(v, OE_Abort); |
| 142705 | 142932 | i = sqlite3VdbeAddOp4Int(v, OP_Found, iDataCur, 0, iPk, nPk); |
| 142706 | 142933 | VdbeCoverage(v); |
| 142707 | 142934 | sqlite3VdbeAddOp4(v, OP_Halt, SQLITE_CORRUPT, OE_Abort, 0, |
| | @@ -142879,12 +143106,12 @@ |
| 142879 | 143106 | int rc = SQLITE_OK; /* Return code from service routines */ |
| 142880 | 143107 | Btree *pMain; /* The database being vacuumed */ |
| 142881 | 143108 | Btree *pTemp; /* The temporary database we vacuum into */ |
| 142882 | 143109 | u32 saved_mDbFlags; /* Saved value of db->mDbFlags */ |
| 142883 | 143110 | u64 saved_flags; /* Saved value of db->flags */ |
| 142884 | | - int saved_nChange; /* Saved value of db->nChange */ |
| 142885 | | - int saved_nTotalChange; /* Saved value of db->nTotalChange */ |
| 143111 | + i64 saved_nChange; /* Saved value of db->nChange */ |
| 143112 | + i64 saved_nTotalChange; /* Saved value of db->nTotalChange */ |
| 142886 | 143113 | u32 saved_openFlags; /* Saved value of db->openFlags */ |
| 142887 | 143114 | u8 saved_mTrace; /* Saved trace settings */ |
| 142888 | 143115 | Db *pDb = 0; /* Database to detach at end of vacuum */ |
| 142889 | 143116 | int isMemDb; /* True if vacuuming a :memory: database */ |
| 142890 | 143117 | int nRes; /* Bytes of reserved space at the end of each page */ |
| | @@ -143327,11 +143554,11 @@ |
| 143327 | 143554 | ** this virtual-table, if one has been created, or NULL otherwise. |
| 143328 | 143555 | */ |
| 143329 | 143556 | SQLITE_PRIVATE VTable *sqlite3GetVTable(sqlite3 *db, Table *pTab){ |
| 143330 | 143557 | VTable *pVtab; |
| 143331 | 143558 | assert( IsVirtual(pTab) ); |
| 143332 | | - for(pVtab=pTab->pVTable; pVtab && pVtab->db!=db; pVtab=pVtab->pNext); |
| 143559 | + for(pVtab=pTab->u.vtab.p; pVtab && pVtab->db!=db; pVtab=pVtab->pNext); |
| 143333 | 143560 | return pVtab; |
| 143334 | 143561 | } |
| 143335 | 143562 | |
| 143336 | 143563 | /* |
| 143337 | 143564 | ** Decrement the ref-count on a virtual table object. When the ref-count |
| | @@ -143355,35 +143582,35 @@ |
| 143355 | 143582 | } |
| 143356 | 143583 | } |
| 143357 | 143584 | |
| 143358 | 143585 | /* |
| 143359 | 143586 | ** Table p is a virtual table. This function moves all elements in the |
| 143360 | | -** p->pVTable list to the sqlite3.pDisconnect lists of their associated |
| 143587 | +** p->u.vtab.p list to the sqlite3.pDisconnect lists of their associated |
| 143361 | 143588 | ** database connections to be disconnected at the next opportunity. |
| 143362 | 143589 | ** Except, if argument db is not NULL, then the entry associated with |
| 143363 | | -** connection db is left in the p->pVTable list. |
| 143590 | +** connection db is left in the p->u.vtab.p list. |
| 143364 | 143591 | */ |
| 143365 | 143592 | static VTable *vtabDisconnectAll(sqlite3 *db, Table *p){ |
| 143366 | 143593 | VTable *pRet = 0; |
| 143367 | | - VTable *pVTable = p->pVTable; |
| 143368 | | - p->pVTable = 0; |
| 143594 | + VTable *pVTable = p->u.vtab.p; |
| 143595 | + p->u.vtab.p = 0; |
| 143369 | 143596 | |
| 143370 | 143597 | /* Assert that the mutex (if any) associated with the BtShared database |
| 143371 | 143598 | ** that contains table p is held by the caller. See header comments |
| 143372 | 143599 | ** above function sqlite3VtabUnlockList() for an explanation of why |
| 143373 | 143600 | ** this makes it safe to access the sqlite3.pDisconnect list of any |
| 143374 | | - ** database connection that may have an entry in the p->pVTable list. |
| 143601 | + ** database connection that may have an entry in the p->u.vtab.p list. |
| 143375 | 143602 | */ |
| 143376 | 143603 | assert( db==0 || sqlite3SchemaMutexHeld(db, 0, p->pSchema) ); |
| 143377 | 143604 | |
| 143378 | 143605 | while( pVTable ){ |
| 143379 | 143606 | sqlite3 *db2 = pVTable->db; |
| 143380 | 143607 | VTable *pNext = pVTable->pNext; |
| 143381 | 143608 | assert( db2 ); |
| 143382 | 143609 | if( db2==db ){ |
| 143383 | 143610 | pRet = pVTable; |
| 143384 | | - p->pVTable = pRet; |
| 143611 | + p->u.vtab.p = pRet; |
| 143385 | 143612 | pRet->pNext = 0; |
| 143386 | 143613 | }else{ |
| 143387 | 143614 | pVTable->pNext = db2->pDisconnect; |
| 143388 | 143615 | db2->pDisconnect = pVTable; |
| 143389 | 143616 | } |
| | @@ -143407,11 +143634,11 @@ |
| 143407 | 143634 | |
| 143408 | 143635 | assert( IsVirtual(p) ); |
| 143409 | 143636 | assert( sqlite3BtreeHoldsAllMutexes(db) ); |
| 143410 | 143637 | assert( sqlite3_mutex_held(db->mutex) ); |
| 143411 | 143638 | |
| 143412 | | - for(ppVTab=&p->pVTable; *ppVTab; ppVTab=&(*ppVTab)->pNext){ |
| 143639 | + for(ppVTab=&p->u.vtab.p; *ppVTab; ppVTab=&(*ppVTab)->pNext){ |
| 143413 | 143640 | if( (*ppVTab)->db==db ){ |
| 143414 | 143641 | VTable *pVTab = *ppVTab; |
| 143415 | 143642 | *ppVTab = pVTab->pNext; |
| 143416 | 143643 | sqlite3VtabUnlock(pVTab); |
| 143417 | 143644 | break; |
| | @@ -143471,40 +143698,40 @@ |
| 143471 | 143698 | ** in the list are moved to the sqlite3.pDisconnect list of the associated |
| 143472 | 143699 | ** database connection. |
| 143473 | 143700 | */ |
| 143474 | 143701 | SQLITE_PRIVATE void sqlite3VtabClear(sqlite3 *db, Table *p){ |
| 143475 | 143702 | if( !db || db->pnBytesFreed==0 ) vtabDisconnectAll(0, p); |
| 143476 | | - if( p->azModuleArg ){ |
| 143703 | + if( p->u.vtab.azArg ){ |
| 143477 | 143704 | int i; |
| 143478 | | - for(i=0; i<p->nModuleArg; i++){ |
| 143479 | | - if( i!=1 ) sqlite3DbFree(db, p->azModuleArg[i]); |
| 143705 | + for(i=0; i<p->u.vtab.nArg; i++){ |
| 143706 | + if( i!=1 ) sqlite3DbFree(db, p->u.vtab.azArg[i]); |
| 143480 | 143707 | } |
| 143481 | | - sqlite3DbFree(db, p->azModuleArg); |
| 143708 | + sqlite3DbFree(db, p->u.vtab.azArg); |
| 143482 | 143709 | } |
| 143483 | 143710 | } |
| 143484 | 143711 | |
| 143485 | 143712 | /* |
| 143486 | | -** Add a new module argument to pTable->azModuleArg[]. |
| 143713 | +** Add a new module argument to pTable->u.vtab.azArg[]. |
| 143487 | 143714 | ** The string is not copied - the pointer is stored. The |
| 143488 | 143715 | ** string will be freed automatically when the table is |
| 143489 | 143716 | ** deleted. |
| 143490 | 143717 | */ |
| 143491 | 143718 | static void addModuleArgument(Parse *pParse, Table *pTable, char *zArg){ |
| 143492 | | - sqlite3_int64 nBytes = sizeof(char *)*(2+pTable->nModuleArg); |
| 143719 | + sqlite3_int64 nBytes = sizeof(char *)*(2+pTable->u.vtab.nArg); |
| 143493 | 143720 | char **azModuleArg; |
| 143494 | 143721 | sqlite3 *db = pParse->db; |
| 143495 | | - if( pTable->nModuleArg+3>=db->aLimit[SQLITE_LIMIT_COLUMN] ){ |
| 143722 | + if( pTable->u.vtab.nArg+3>=db->aLimit[SQLITE_LIMIT_COLUMN] ){ |
| 143496 | 143723 | sqlite3ErrorMsg(pParse, "too many columns on %s", pTable->zName); |
| 143497 | 143724 | } |
| 143498 | | - azModuleArg = sqlite3DbRealloc(db, pTable->azModuleArg, nBytes); |
| 143725 | + azModuleArg = sqlite3DbRealloc(db, pTable->u.vtab.azArg, nBytes); |
| 143499 | 143726 | if( azModuleArg==0 ){ |
| 143500 | 143727 | sqlite3DbFree(db, zArg); |
| 143501 | 143728 | }else{ |
| 143502 | | - int i = pTable->nModuleArg++; |
| 143729 | + int i = pTable->u.vtab.nArg++; |
| 143503 | 143730 | azModuleArg[i] = zArg; |
| 143504 | 143731 | azModuleArg[i+1] = 0; |
| 143505 | | - pTable->azModuleArg = azModuleArg; |
| 143732 | + pTable->u.vtab.azArg = azModuleArg; |
| 143506 | 143733 | } |
| 143507 | 143734 | } |
| 143508 | 143735 | |
| 143509 | 143736 | /* |
| 143510 | 143737 | ** The parser calls this routine when it first sees a CREATE VIRTUAL TABLE |
| | @@ -143523,14 +143750,15 @@ |
| 143523 | 143750 | |
| 143524 | 143751 | sqlite3StartTable(pParse, pName1, pName2, 0, 0, 1, ifNotExists); |
| 143525 | 143752 | pTable = pParse->pNewTable; |
| 143526 | 143753 | if( pTable==0 ) return; |
| 143527 | 143754 | assert( 0==pTable->pIndex ); |
| 143755 | + pTable->eTabType = TABTYP_VTAB; |
| 143528 | 143756 | |
| 143529 | 143757 | db = pParse->db; |
| 143530 | 143758 | |
| 143531 | | - assert( pTable->nModuleArg==0 ); |
| 143759 | + assert( pTable->u.vtab.nArg==0 ); |
| 143532 | 143760 | addModuleArgument(pParse, pTable, sqlite3NameFromToken(db, pModuleName)); |
| 143533 | 143761 | addModuleArgument(pParse, pTable, 0); |
| 143534 | 143762 | addModuleArgument(pParse, pTable, sqlite3DbStrDup(db, pTable->zName)); |
| 143535 | 143763 | assert( (pParse->sNameToken.z==pName2->z && pName2->z!=0) |
| 143536 | 143764 | || (pParse->sNameToken.z==pName1->z && pName2->z==0) |
| | @@ -143543,15 +143771,15 @@ |
| 143543 | 143771 | /* Creating a virtual table invokes the authorization callback twice. |
| 143544 | 143772 | ** The first invocation, to obtain permission to INSERT a row into the |
| 143545 | 143773 | ** sqlite_schema table, has already been made by sqlite3StartTable(). |
| 143546 | 143774 | ** The second call, to obtain permission to create the table, is made now. |
| 143547 | 143775 | */ |
| 143548 | | - if( pTable->azModuleArg ){ |
| 143776 | + if( pTable->u.vtab.azArg ){ |
| 143549 | 143777 | int iDb = sqlite3SchemaToIndex(db, pTable->pSchema); |
| 143550 | 143778 | assert( iDb>=0 ); /* The database the table is being created in */ |
| 143551 | 143779 | sqlite3AuthCheck(pParse, SQLITE_CREATE_VTABLE, pTable->zName, |
| 143552 | | - pTable->azModuleArg[0], pParse->db->aDb[iDb].zDbSName); |
| 143780 | + pTable->u.vtab.azArg[0], pParse->db->aDb[iDb].zDbSName); |
| 143553 | 143781 | } |
| 143554 | 143782 | #endif |
| 143555 | 143783 | } |
| 143556 | 143784 | |
| 143557 | 143785 | /* |
| | @@ -143577,11 +143805,11 @@ |
| 143577 | 143805 | sqlite3 *db = pParse->db; /* The database connection */ |
| 143578 | 143806 | |
| 143579 | 143807 | if( pTab==0 ) return; |
| 143580 | 143808 | addArgumentToVtab(pParse); |
| 143581 | 143809 | pParse->sArg.z = 0; |
| 143582 | | - if( pTab->nModuleArg<1 ) return; |
| 143810 | + if( pTab->u.vtab.nArg<1 ) return; |
| 143583 | 143811 | |
| 143584 | 143812 | /* If the CREATE VIRTUAL TABLE statement is being entered for the |
| 143585 | 143813 | ** first time (in other words if the virtual table is actually being |
| 143586 | 143814 | ** created now instead of just being read out of sqlite_schema) then |
| 143587 | 143815 | ** do additional initialization work and store the statement text |
| | @@ -143692,12 +143920,12 @@ |
| 143692 | 143920 | char **pzErr |
| 143693 | 143921 | ){ |
| 143694 | 143922 | VtabCtx sCtx; |
| 143695 | 143923 | VTable *pVTable; |
| 143696 | 143924 | int rc; |
| 143697 | | - const char *const*azArg = (const char *const*)pTab->azModuleArg; |
| 143698 | | - int nArg = pTab->nModuleArg; |
| 143925 | + const char *const*azArg = (const char *const*)pTab->u.vtab.azArg; |
| 143926 | + int nArg = pTab->u.vtab.nArg; |
| 143699 | 143927 | char *zErr = 0; |
| 143700 | 143928 | char *zModuleName; |
| 143701 | 143929 | int iDb; |
| 143702 | 143930 | VtabCtx *pCtx; |
| 143703 | 143931 | |
| | @@ -143725,11 +143953,11 @@ |
| 143725 | 143953 | pVTable->db = db; |
| 143726 | 143954 | pVTable->pMod = pMod; |
| 143727 | 143955 | pVTable->eVtabRisk = SQLITE_VTABRISK_Normal; |
| 143728 | 143956 | |
| 143729 | 143957 | iDb = sqlite3SchemaToIndex(db, pTab->pSchema); |
| 143730 | | - pTab->azModuleArg[1] = db->aDb[iDb].zDbSName; |
| 143958 | + pTab->u.vtab.azArg[1] = db->aDb[iDb].zDbSName; |
| 143731 | 143959 | |
| 143732 | 143960 | /* Invoke the virtual table constructor */ |
| 143733 | 143961 | assert( &db->pVtabCtx ); |
| 143734 | 143962 | assert( xConstruct ); |
| 143735 | 143963 | sCtx.pTab = pTab; |
| | @@ -143764,16 +143992,16 @@ |
| 143764 | 143992 | rc = SQLITE_ERROR; |
| 143765 | 143993 | }else{ |
| 143766 | 143994 | int iCol; |
| 143767 | 143995 | u16 oooHidden = 0; |
| 143768 | 143996 | /* If everything went according to plan, link the new VTable structure |
| 143769 | | - ** into the linked list headed by pTab->pVTable. Then loop through the |
| 143997 | + ** into the linked list headed by pTab->u.vtab.p. Then loop through the |
| 143770 | 143998 | ** columns of the table to see if any of them contain the token "hidden". |
| 143771 | 143999 | ** If so, set the Column COLFLAG_HIDDEN flag and remove the token from |
| 143772 | 144000 | ** the type string. */ |
| 143773 | | - pVTable->pNext = pTab->pVTable; |
| 143774 | | - pTab->pVTable = pVTable; |
| 144001 | + pVTable->pNext = pTab->u.vtab.p; |
| 144002 | + pTab->u.vtab.p = pVTable; |
| 143775 | 144003 | |
| 143776 | 144004 | for(iCol=0; iCol<pTab->nCol; iCol++){ |
| 143777 | 144005 | char *zType = sqlite3ColumnType(&pTab->aCol[iCol], ""); |
| 143778 | 144006 | int nType; |
| 143779 | 144007 | int i = 0; |
| | @@ -143827,15 +144055,15 @@ |
| 143827 | 144055 | if( !IsVirtual(pTab) || sqlite3GetVTable(db, pTab) ){ |
| 143828 | 144056 | return SQLITE_OK; |
| 143829 | 144057 | } |
| 143830 | 144058 | |
| 143831 | 144059 | /* Locate the required virtual table module */ |
| 143832 | | - zMod = pTab->azModuleArg[0]; |
| 144060 | + zMod = pTab->u.vtab.azArg[0]; |
| 143833 | 144061 | pMod = (Module*)sqlite3HashFind(&db->aModule, zMod); |
| 143834 | 144062 | |
| 143835 | 144063 | if( !pMod ){ |
| 143836 | | - const char *zModule = pTab->azModuleArg[0]; |
| 144064 | + const char *zModule = pTab->u.vtab.azArg[0]; |
| 143837 | 144065 | sqlite3ErrorMsg(pParse, "no such module: %s", zModule); |
| 143838 | 144066 | rc = SQLITE_ERROR; |
| 143839 | 144067 | }else{ |
| 143840 | 144068 | char *zErr = 0; |
| 143841 | 144069 | rc = vtabCallConstructor(db, pTab, pMod, pMod->pModule->xConnect, &zErr); |
| | @@ -143894,14 +144122,14 @@ |
| 143894 | 144122 | Table *pTab; |
| 143895 | 144123 | Module *pMod; |
| 143896 | 144124 | const char *zMod; |
| 143897 | 144125 | |
| 143898 | 144126 | pTab = sqlite3FindTable(db, zTab, db->aDb[iDb].zDbSName); |
| 143899 | | - assert( pTab && IsVirtual(pTab) && !pTab->pVTable ); |
| 144127 | + assert( pTab && IsVirtual(pTab) && !pTab->u.vtab.p ); |
| 143900 | 144128 | |
| 143901 | 144129 | /* Locate the required virtual table module */ |
| 143902 | | - zMod = pTab->azModuleArg[0]; |
| 144130 | + zMod = pTab->u.vtab.azArg[0]; |
| 143903 | 144131 | pMod = (Module*)sqlite3HashFind(&db->aModule, zMod); |
| 143904 | 144132 | |
| 143905 | 144133 | /* If the module has been registered and includes a Create method, |
| 143906 | 144134 | ** invoke it now. If the module has not been registered, return an |
| 143907 | 144135 | ** error. Otherwise, do nothing. |
| | @@ -143957,17 +144185,17 @@ |
| 143957 | 144185 | sParse.db = db; |
| 143958 | 144186 | sParse.nQueryLoop = 1; |
| 143959 | 144187 | if( SQLITE_OK==sqlite3RunParser(&sParse, zCreateTable, &zErr) |
| 143960 | 144188 | && sParse.pNewTable |
| 143961 | 144189 | && !db->mallocFailed |
| 143962 | | - && !sParse.pNewTable->pSelect |
| 143963 | | - && !IsVirtual(sParse.pNewTable) |
| 144190 | + && IsOrdinaryTable(sParse.pNewTable) |
| 143964 | 144191 | ){ |
| 143965 | 144192 | if( !pTab->aCol ){ |
| 143966 | 144193 | Table *pNew = sParse.pNewTable; |
| 143967 | 144194 | Index *pIdx; |
| 143968 | 144195 | pTab->aCol = pNew->aCol; |
| 144196 | + sqlite3ExprListDelete(db, pNew->u.tab.pDfltList); |
| 143969 | 144197 | pTab->nNVCol = pTab->nCol = pNew->nCol; |
| 143970 | 144198 | pTab->tabFlags |= pNew->tabFlags & (TF_WithoutRowid|TF_NoVisibleRowid); |
| 143971 | 144199 | pNew->nCol = 0; |
| 143972 | 144200 | pNew->aCol = 0; |
| 143973 | 144201 | assert( pTab->pIndex==0 ); |
| | @@ -144018,14 +144246,14 @@ |
| 144018 | 144246 | SQLITE_PRIVATE int sqlite3VtabCallDestroy(sqlite3 *db, int iDb, const char *zTab){ |
| 144019 | 144247 | int rc = SQLITE_OK; |
| 144020 | 144248 | Table *pTab; |
| 144021 | 144249 | |
| 144022 | 144250 | pTab = sqlite3FindTable(db, zTab, db->aDb[iDb].zDbSName); |
| 144023 | | - if( pTab!=0 && ALWAYS(pTab->pVTable!=0) ){ |
| 144251 | + if( pTab!=0 && ALWAYS(pTab->u.vtab.p!=0) ){ |
| 144024 | 144252 | VTable *p; |
| 144025 | 144253 | int (*xDestroy)(sqlite3_vtab *); |
| 144026 | | - for(p=pTab->pVTable; p; p=p->pNext){ |
| 144254 | + for(p=pTab->u.vtab.p; p; p=p->pNext){ |
| 144027 | 144255 | assert( p->pVtab ); |
| 144028 | 144256 | if( p->pVtab->nRef>0 ){ |
| 144029 | 144257 | return SQLITE_LOCKED; |
| 144030 | 144258 | } |
| 144031 | 144259 | } |
| | @@ -144035,13 +144263,13 @@ |
| 144035 | 144263 | assert( xDestroy!=0 ); |
| 144036 | 144264 | pTab->nTabRef++; |
| 144037 | 144265 | rc = xDestroy(p->pVtab); |
| 144038 | 144266 | /* Remove the sqlite3_vtab* from the aVTrans[] array, if applicable */ |
| 144039 | 144267 | if( rc==SQLITE_OK ){ |
| 144040 | | - assert( pTab->pVTable==p && p->pNext==0 ); |
| 144268 | + assert( pTab->u.vtab.p==p && p->pNext==0 ); |
| 144041 | 144269 | p->pVtab = 0; |
| 144042 | | - pTab->pVTable = 0; |
| 144270 | + pTab->u.vtab.p = 0; |
| 144043 | 144271 | sqlite3VtabUnlock(p); |
| 144044 | 144272 | } |
| 144045 | 144273 | sqlite3DeleteTable(db, pTab); |
| 144046 | 144274 | } |
| 144047 | 144275 | |
| | @@ -144325,12 +144553,13 @@ |
| 144325 | 144553 | } |
| 144326 | 144554 | |
| 144327 | 144555 | /* |
| 144328 | 144556 | ** Check to see if virtual table module pMod can be have an eponymous |
| 144329 | 144557 | ** virtual table instance. If it can, create one if one does not already |
| 144330 | | -** exist. Return non-zero if the eponymous virtual table instance exists |
| 144331 | | -** when this routine returns, and return zero if it does not exist. |
| 144558 | +** exist. Return non-zero if either the eponymous virtual table instance |
| 144559 | +** exists when this routine returns or if an attempt to create it failed |
| 144560 | +** and an error message was left in pParse. |
| 144332 | 144561 | ** |
| 144333 | 144562 | ** An eponymous virtual table instance is one that is named after its |
| 144334 | 144563 | ** module, and more importantly, does not require a CREATE VIRTUAL TABLE |
| 144335 | 144564 | ** statement in order to come into existance. Eponymous virtual table |
| 144336 | 144565 | ** instances always exist. They cannot be DROP-ed. |
| | @@ -144353,12 +144582,13 @@ |
| 144353 | 144582 | sqlite3DbFree(db, pTab); |
| 144354 | 144583 | return 0; |
| 144355 | 144584 | } |
| 144356 | 144585 | pMod->pEpoTab = pTab; |
| 144357 | 144586 | pTab->nTabRef = 1; |
| 144587 | + pTab->eTabType = TABTYP_VTAB; |
| 144358 | 144588 | pTab->pSchema = db->aDb[0].pSchema; |
| 144359 | | - assert( pTab->nModuleArg==0 ); |
| 144589 | + assert( pTab->u.vtab.nArg==0 ); |
| 144360 | 144590 | pTab->iPKey = -1; |
| 144361 | 144591 | pTab->tabFlags |= TF_Eponymous; |
| 144362 | 144592 | addModuleArgument(pParse, pTab, sqlite3DbStrDup(db, pTab->zName)); |
| 144363 | 144593 | addModuleArgument(pParse, pTab, 0); |
| 144364 | 144594 | addModuleArgument(pParse, pTab, sqlite3DbStrDup(db, pTab->zName)); |
| | @@ -144365,11 +144595,10 @@ |
| 144365 | 144595 | rc = vtabCallConstructor(db, pTab, pMod, pModule->xConnect, &zErr); |
| 144366 | 144596 | if( rc ){ |
| 144367 | 144597 | sqlite3ErrorMsg(pParse, "%s", zErr); |
| 144368 | 144598 | sqlite3DbFree(db, zErr); |
| 144369 | 144599 | sqlite3VtabEponymousTableClear(db, pMod); |
| 144370 | | - return 0; |
| 144371 | 144600 | } |
| 144372 | 144601 | return 1; |
| 144373 | 144602 | } |
| 144374 | 144603 | |
| 144375 | 144604 | /* |
| | @@ -145099,11 +145328,11 @@ |
| 145099 | 145328 | */ |
| 145100 | 145329 | static const char *explainIndexColumnName(Index *pIdx, int i){ |
| 145101 | 145330 | i = pIdx->aiColumn[i]; |
| 145102 | 145331 | if( i==XN_EXPR ) return "<expr>"; |
| 145103 | 145332 | if( i==XN_ROWID ) return "rowid"; |
| 145104 | | - return pIdx->pTable->aCol[i].zName; |
| 145333 | + return pIdx->pTable->aCol[i].zCnName; |
| 145105 | 145334 | } |
| 145106 | 145335 | |
| 145107 | 145336 | /* |
| 145108 | 145337 | ** This routine is a helper for explainIndexRange() below |
| 145109 | 145338 | ** |
| | @@ -146311,12 +146540,13 @@ |
| 146311 | 146540 | if( sqlite3ExprIsConstant(x.pIdxExpr) ) continue; |
| 146312 | 146541 | w.xExprCallback = whereIndexExprTransNode; |
| 146313 | 146542 | #ifndef SQLITE_OMIT_GENERATED_COLUMNS |
| 146314 | 146543 | }else if( iRef>=0 |
| 146315 | 146544 | && (pTab->aCol[iRef].colFlags & COLFLAG_VIRTUAL)!=0 |
| 146316 | | - && (pTab->aCol[iRef].zColl==0 |
| 146317 | | - || sqlite3StrICmp(pTab->aCol[iRef].zColl, sqlite3StrBINARY)==0) |
| 146545 | + && ((pTab->aCol[iRef].colFlags & COLFLAG_HASCOLL)==0 |
| 146546 | + || sqlite3StrICmp(sqlite3ColumnColl(&pTab->aCol[iRef]), |
| 146547 | + sqlite3StrBINARY)==0) |
| 146318 | 146548 | ){ |
| 146319 | 146549 | /* Check to see if there are direct references to generated columns |
| 146320 | 146550 | ** that are contained in the index. Pulling the generated column |
| 146321 | 146551 | ** out of the index is an optimization only - the main table is always |
| 146322 | 146552 | ** available if the index cannot be used. To avoid unnecessary |
| | @@ -148731,11 +148961,15 @@ |
| 148731 | 148961 | pNew->u.x.leftColumn = aiCurCol[1]; |
| 148732 | 148962 | testcase( (prereqLeft | extraRight) != prereqLeft ); |
| 148733 | 148963 | pNew->prereqRight = prereqLeft | extraRight; |
| 148734 | 148964 | pNew->prereqAll = prereqAll; |
| 148735 | 148965 | pNew->eOperator = (operatorMask(pDup->op) + eExtraOp) & opMask; |
| 148736 | | - }else if( op==TK_ISNULL && 0==sqlite3ExprCanBeNull(pLeft) ){ |
| 148966 | + }else |
| 148967 | + if( op==TK_ISNULL |
| 148968 | + && !ExprHasProperty(pExpr,EP_FromJoin) |
| 148969 | + && 0==sqlite3ExprCanBeNull(pLeft) |
| 148970 | + ){ |
| 148737 | 148971 | pExpr->op = TK_TRUEFALSE; |
| 148738 | 148972 | pExpr->u.zToken = "false"; |
| 148739 | 148973 | ExprSetProperty(pExpr, EP_IsFalse); |
| 148740 | 148974 | pTerm->prereqAll = 0; |
| 148741 | 148975 | pTerm->eOperator = 0; |
| | @@ -148928,12 +149162,12 @@ |
| 148928 | 149162 | ){ |
| 148929 | 149163 | int i; |
| 148930 | 149164 | for(i=0; i<nLeft; i++){ |
| 148931 | 149165 | int idxNew; |
| 148932 | 149166 | Expr *pNew; |
| 148933 | | - Expr *pLeft = sqlite3ExprForVectorField(pParse, pExpr->pLeft, i); |
| 148934 | | - Expr *pRight = sqlite3ExprForVectorField(pParse, pExpr->pRight, i); |
| 149167 | + Expr *pLeft = sqlite3ExprForVectorField(pParse, pExpr->pLeft, i, nLeft); |
| 149168 | + Expr *pRight = sqlite3ExprForVectorField(pParse, pExpr->pRight, i, nLeft); |
| 148935 | 149169 | |
| 148936 | 149170 | pNew = sqlite3PExpr(pParse, pExpr->op, pLeft, pRight); |
| 148937 | 149171 | transferJoinMarkings(pNew, pExpr); |
| 148938 | 149172 | idxNew = whereClauseInsert(pWC, pNew, TERM_DYNAMIC); |
| 148939 | 149173 | exprAnalyze(pSrc, pWC, idxNew); |
| | @@ -150018,11 +150252,11 @@ |
| 150018 | 150252 | testcase( iCol==BMS ); |
| 150019 | 150253 | testcase( iCol==BMS-1 ); |
| 150020 | 150254 | if( !sentWarning ){ |
| 150021 | 150255 | sqlite3_log(SQLITE_WARNING_AUTOINDEX, |
| 150022 | 150256 | "automatic index on %s(%s)", pTable->zName, |
| 150023 | | - pTable->aCol[iCol].zName); |
| 150257 | + pTable->aCol[iCol].zCnName); |
| 150024 | 150258 | sentWarning = 1; |
| 150025 | 150259 | } |
| 150026 | 150260 | if( (idxCols & cMask)==0 ){ |
| 150027 | 150261 | if( whereLoopResize(pParse->db, pLoop, nKeyCol+1) ){ |
| 150028 | 150262 | goto end_auto_index_create; |
| | @@ -151932,11 +152166,11 @@ |
| 151932 | 152166 | }else{ |
| 151933 | 152167 | #ifdef SQLITE_ENABLE_STAT4 |
| 151934 | 152168 | tRowcnt nOut = 0; |
| 151935 | 152169 | if( nInMul==0 |
| 151936 | 152170 | && pProbe->nSample |
| 151937 | | - && pNew->u.btree.nEq<=pProbe->nSampleCol |
| 152171 | + && ALWAYS(pNew->u.btree.nEq<=pProbe->nSampleCol) |
| 151938 | 152172 | && ((eOp & WO_IN)==0 || !ExprHasProperty(pTerm->pExpr, EP_xIsSelect)) |
| 151939 | 152173 | && OptimizationEnabled(db, SQLITE_Stat4) |
| 151940 | 152174 | ){ |
| 151941 | 152175 | Expr *pExpr = pTerm->pExpr; |
| 151942 | 152176 | if( (eOp & (WO_EQ|WO_ISNULL|WO_IS))!=0 ){ |
| | @@ -152197,11 +152431,10 @@ |
| 152197 | 152431 | WhereLoop *pNew; /* Template WhereLoop object */ |
| 152198 | 152432 | int rc = SQLITE_OK; /* Return code */ |
| 152199 | 152433 | int iSortIdx = 1; /* Index number */ |
| 152200 | 152434 | int b; /* A boolean value */ |
| 152201 | 152435 | LogEst rSize; /* number of rows in the table */ |
| 152202 | | - LogEst rLogSize; /* Logarithm of the number of rows in the table */ |
| 152203 | 152436 | WhereClause *pWC; /* The parsed WHERE clause */ |
| 152204 | 152437 | Table *pTab; /* Table being queried */ |
| 152205 | 152438 | |
| 152206 | 152439 | pNew = pBuilder->pNew; |
| 152207 | 152440 | pWInfo = pBuilder->pWInfo; |
| | @@ -152240,11 +152473,10 @@ |
| 152240 | 152473 | sPk.pNext = pFirst; |
| 152241 | 152474 | } |
| 152242 | 152475 | pProbe = &sPk; |
| 152243 | 152476 | } |
| 152244 | 152477 | rSize = pTab->nRowLogEst; |
| 152245 | | - rLogSize = estLog(rSize); |
| 152246 | 152478 | |
| 152247 | 152479 | #ifndef SQLITE_OMIT_AUTOMATIC_INDEX |
| 152248 | 152480 | /* Automatic indexes */ |
| 152249 | 152481 | if( !pBuilder->pOrSet /* Not part of an OR optimization */ |
| 152250 | 152482 | && (pWInfo->wctrlFlags & WHERE_OR_SUBCLAUSE)==0 |
| | @@ -152254,12 +152486,14 @@ |
| 152254 | 152486 | && HasRowid(pTab) /* Not WITHOUT ROWID table. (FIXME: Why not?) */ |
| 152255 | 152487 | && !pSrc->fg.isCorrelated /* Not a correlated subquery */ |
| 152256 | 152488 | && !pSrc->fg.isRecursive /* Not a recursive common table expression. */ |
| 152257 | 152489 | ){ |
| 152258 | 152490 | /* Generate auto-index WhereLoops */ |
| 152491 | + LogEst rLogSize; /* Logarithm of the number of rows in the table */ |
| 152259 | 152492 | WhereTerm *pTerm; |
| 152260 | 152493 | WhereTerm *pWCEnd = pWC->a + pWC->nTerm; |
| 152494 | + rLogSize = estLog(rSize); |
| 152261 | 152495 | for(pTerm=pWC->a; rc==SQLITE_OK && pTerm<pWCEnd; pTerm++){ |
| 152262 | 152496 | if( pTerm->prereqRight & pNew->maskSelf ) continue; |
| 152263 | 152497 | if( termCanDriveIndex(pTerm, pSrc, 0) ){ |
| 152264 | 152498 | pNew->u.btree.nEq = 1; |
| 152265 | 152499 | pNew->nSkip = 0; |
| | @@ -152273,11 +152507,11 @@ |
| 152273 | 152507 | ** of X is smaller for views and subqueries so that the query planner |
| 152274 | 152508 | ** will be more aggressive about generating automatic indexes for |
| 152275 | 152509 | ** those objects, since there is no opportunity to add schema |
| 152276 | 152510 | ** indexes on subqueries and views. */ |
| 152277 | 152511 | pNew->rSetup = rLogSize + rSize; |
| 152278 | | - if( pTab->pSelect==0 && (pTab->tabFlags & TF_Ephemeral)==0 ){ |
| 152512 | + if( !IsView(pTab) && (pTab->tabFlags & TF_Ephemeral)==0 ){ |
| 152279 | 152513 | pNew->rSetup += 28; |
| 152280 | 152514 | }else{ |
| 152281 | 152515 | pNew->rSetup -= 10; |
| 152282 | 152516 | } |
| 152283 | 152517 | ApplyCostMultiplier(pNew->rSetup, pTab->costMult); |
| | @@ -154424,11 +154658,11 @@ |
| 154424 | 154658 | |
| 154425 | 154659 | pTabItem = &pTabList->a[pLevel->iFrom]; |
| 154426 | 154660 | pTab = pTabItem->pTab; |
| 154427 | 154661 | iDb = sqlite3SchemaToIndex(db, pTab->pSchema); |
| 154428 | 154662 | pLoop = pLevel->pWLoop; |
| 154429 | | - if( (pTab->tabFlags & TF_Ephemeral)!=0 || pTab->pSelect ){ |
| 154663 | + if( (pTab->tabFlags & TF_Ephemeral)!=0 || IsView(pTab) ){ |
| 154430 | 154664 | /* Do nothing */ |
| 154431 | 154665 | }else |
| 154432 | 154666 | #ifndef SQLITE_OMIT_VIRTUALTABLE |
| 154433 | 154667 | if( (pLoop->wsFlags & WHERE_VIRTUALTABLE)!=0 ){ |
| 154434 | 154668 | const char *pVTab = (const char *)sqlite3GetVTable(db, pTab); |
| | @@ -154741,10 +154975,16 @@ |
| 154741 | 154975 | sqlite3VdbeAddOp1(v, OP_NullRow, pLevel->iTabCur); |
| 154742 | 154976 | } |
| 154743 | 154977 | if( (ws & WHERE_INDEXED) |
| 154744 | 154978 | || ((ws & WHERE_MULTI_OR) && pLevel->u.pCovidx) |
| 154745 | 154979 | ){ |
| 154980 | + if( ws & WHERE_MULTI_OR ){ |
| 154981 | + Index *pIx = pLevel->u.pCovidx; |
| 154982 | + int iDb = sqlite3SchemaToIndex(db, pIx->pSchema); |
| 154983 | + sqlite3VdbeAddOp3(v, OP_ReopenIdx, pLevel->iIdxCur, pIx->tnum, iDb); |
| 154984 | + sqlite3VdbeSetP4KeyInfo(pParse, pIx); |
| 154985 | + } |
| 154746 | 154986 | sqlite3VdbeAddOp1(v, OP_NullRow, pLevel->iIdxCur); |
| 154747 | 154987 | } |
| 154748 | 154988 | if( pLevel->op==OP_Return ){ |
| 154749 | 154989 | sqlite3VdbeAddOp2(v, OP_Gosub, pLevel->p1, pLevel->addrFirst); |
| 154750 | 154990 | }else{ |
| | @@ -154787,11 +155027,11 @@ |
| 154787 | 155027 | ** Except, do not close cursors that will be reused by the OR optimization |
| 154788 | 155028 | ** (WHERE_OR_SUBCLAUSE). And do not close the OP_OpenWrite cursors |
| 154789 | 155029 | ** created for the ONEPASS optimization. |
| 154790 | 155030 | */ |
| 154791 | 155031 | if( (pTab->tabFlags & TF_Ephemeral)==0 |
| 154792 | | - && pTab->pSelect==0 |
| 155032 | + && !IsView(pTab) |
| 154793 | 155033 | && (pWInfo->wctrlFlags & WHERE_OR_SUBCLAUSE)==0 |
| 154794 | 155034 | ){ |
| 154795 | 155035 | int ws = pLoop->wsFlags; |
| 154796 | 155036 | if( pWInfo->eOnePass==ONEPASS_OFF && (ws & WHERE_IDX_ONLY)==0 ){ |
| 154797 | 155037 | sqlite3VdbeAddOp1(v, OP_Close, pTabItem->iCursor); |
| | @@ -155805,13 +156045,11 @@ |
| 155805 | 156045 | break; |
| 155806 | 156046 | } |
| 155807 | 156047 | if( bIntToNull ){ |
| 155808 | 156048 | int iDummy; |
| 155809 | 156049 | Expr *pSub; |
| 155810 | | - for(pSub=pDup; ExprHasProperty(pSub, EP_Skip); pSub=pSub->pLeft){ |
| 155811 | | - assert( pSub ); |
| 155812 | | - } |
| 156050 | + pSub = sqlite3ExprSkipCollateAndLikely(pDup); |
| 155813 | 156051 | if( sqlite3ExprIsInteger(pSub, &iDummy) ){ |
| 155814 | 156052 | pSub->op = TK_NULL; |
| 155815 | 156053 | pSub->flags &= ~(EP_IntValue|EP_IsTrue|EP_IsFalse); |
| 155816 | 156054 | pSub->u.zToken = 0; |
| 155817 | 156055 | } |
| | @@ -155969,11 +156207,11 @@ |
| 155969 | 156207 | p->pSrc = sqlite3SrcListAppend(pParse, 0, 0, 0); |
| 155970 | 156208 | if( p->pSrc ){ |
| 155971 | 156209 | Table *pTab2; |
| 155972 | 156210 | p->pSrc->a[0].pSelect = pSub; |
| 155973 | 156211 | sqlite3SrcListAssignCursors(pParse, p->pSrc); |
| 155974 | | - pSub->selFlags |= SF_Expanded; |
| 156212 | + pSub->selFlags |= SF_Expanded|SF_OrderByReqd; |
| 155975 | 156213 | pTab2 = sqlite3ResultSetOfSelect(pParse, pSub, SQLITE_AFF_NONE); |
| 155976 | 156214 | pSub->selFlags |= (selFlags & SF_Aggregate); |
| 155977 | 156215 | if( pTab2==0 ){ |
| 155978 | 156216 | /* Might actually be some other kind of error, but in that case |
| 155979 | 156217 | ** pParse->nErr will be set, so if SQLITE_NOMEM is set, we will get |
| | @@ -161615,11 +161853,11 @@ |
| 161615 | 161853 | sqlite3ErrorMsg(pParse, "unknown table option: %.*s", yymsp[0].minor.yy0.n, yymsp[0].minor.yy0.z); |
| 161616 | 161854 | } |
| 161617 | 161855 | } |
| 161618 | 161856 | break; |
| 161619 | 161857 | case 23: /* columnname ::= nm typetoken */ |
| 161620 | | -{sqlite3AddColumn(pParse,&yymsp[-1].minor.yy0,&yymsp[0].minor.yy0);} |
| 161858 | +{sqlite3AddColumn(pParse,yymsp[-1].minor.yy0,yymsp[0].minor.yy0);} |
| 161621 | 161859 | break; |
| 161622 | 161860 | case 24: /* typetoken ::= */ |
| 161623 | 161861 | case 63: /* conslist_opt ::= */ yytestcase(yyruleno==63); |
| 161624 | 161862 | case 102: /* as ::= */ yytestcase(yyruleno==102); |
| 161625 | 161863 | {yymsp[1].minor.yy0.n = 0; yymsp[1].minor.yy0.z = 0;} |
| | @@ -162419,24 +162657,32 @@ |
| 162419 | 162657 | ** simplify to constants 0 (false) and 1 (true), respectively, |
| 162420 | 162658 | ** regardless of the value of expr1. |
| 162421 | 162659 | */ |
| 162422 | 162660 | sqlite3ExprUnmapAndDelete(pParse, yymsp[-4].minor.yy404); |
| 162423 | 162661 | yymsp[-4].minor.yy404 = sqlite3Expr(pParse->db, TK_INTEGER, yymsp[-3].minor.yy376 ? "1" : "0"); |
| 162424 | | - }else if( yymsp[-1].minor.yy70->nExpr==1 && sqlite3ExprIsConstant(yymsp[-1].minor.yy70->a[0].pExpr) ){ |
| 162662 | + }else{ |
| 162425 | 162663 | Expr *pRHS = yymsp[-1].minor.yy70->a[0].pExpr; |
| 162426 | | - yymsp[-1].minor.yy70->a[0].pExpr = 0; |
| 162427 | | - sqlite3ExprListDelete(pParse->db, yymsp[-1].minor.yy70); |
| 162428 | | - pRHS = sqlite3PExpr(pParse, TK_UPLUS, pRHS, 0); |
| 162429 | | - yymsp[-4].minor.yy404 = sqlite3PExpr(pParse, TK_EQ, yymsp[-4].minor.yy404, pRHS); |
| 162430 | | - if( yymsp[-3].minor.yy376 ) yymsp[-4].minor.yy404 = sqlite3PExpr(pParse, TK_NOT, yymsp[-4].minor.yy404, 0); |
| 162431 | | - }else{ |
| 162432 | | - yymsp[-4].minor.yy404 = sqlite3PExpr(pParse, TK_IN, yymsp[-4].minor.yy404, 0); |
| 162433 | | - if( yymsp[-4].minor.yy404 ){ |
| 162434 | | - yymsp[-4].minor.yy404->x.pList = yymsp[-1].minor.yy70; |
| 162435 | | - sqlite3ExprSetHeightAndFlags(pParse, yymsp[-4].minor.yy404); |
| 162436 | | - }else{ |
| 162437 | | - sqlite3ExprListDelete(pParse->db, yymsp[-1].minor.yy70); |
| 162664 | + if( yymsp[-1].minor.yy70->nExpr==1 && sqlite3ExprIsConstant(pRHS) && yymsp[-4].minor.yy404->op!=TK_VECTOR ){ |
| 162665 | + yymsp[-1].minor.yy70->a[0].pExpr = 0; |
| 162666 | + sqlite3ExprListDelete(pParse->db, yymsp[-1].minor.yy70); |
| 162667 | + pRHS = sqlite3PExpr(pParse, TK_UPLUS, pRHS, 0); |
| 162668 | + yymsp[-4].minor.yy404 = sqlite3PExpr(pParse, TK_EQ, yymsp[-4].minor.yy404, pRHS); |
| 162669 | + }else{ |
| 162670 | + yymsp[-4].minor.yy404 = sqlite3PExpr(pParse, TK_IN, yymsp[-4].minor.yy404, 0); |
| 162671 | + if( yymsp[-4].minor.yy404==0 ){ |
| 162672 | + sqlite3ExprListDelete(pParse->db, yymsp[-1].minor.yy70); |
| 162673 | + }else if( yymsp[-4].minor.yy404->pLeft->op==TK_VECTOR ){ |
| 162674 | + int nExpr = yymsp[-4].minor.yy404->pLeft->x.pList->nExpr; |
| 162675 | + Select *pSelectRHS = sqlite3ExprListToValues(pParse, nExpr, yymsp[-1].minor.yy70); |
| 162676 | + if( pSelectRHS ){ |
| 162677 | + parserDoubleLinkSelect(pParse, pSelectRHS); |
| 162678 | + sqlite3PExprAddSelect(pParse, yymsp[-4].minor.yy404, pSelectRHS); |
| 162679 | + } |
| 162680 | + }else{ |
| 162681 | + yymsp[-4].minor.yy404->x.pList = yymsp[-1].minor.yy70; |
| 162682 | + sqlite3ExprSetHeightAndFlags(pParse, yymsp[-4].minor.yy404); |
| 162683 | + } |
| 162438 | 162684 | } |
| 162439 | 162685 | if( yymsp[-3].minor.yy376 ) yymsp[-4].minor.yy404 = sqlite3PExpr(pParse, TK_NOT, yymsp[-4].minor.yy404, 0); |
| 162440 | 162686 | } |
| 162441 | 162687 | } |
| 162442 | 162688 | break; |
| | @@ -166151,31 +166397,37 @@ |
| 166151 | 166397 | } |
| 166152 | 166398 | |
| 166153 | 166399 | /* |
| 166154 | 166400 | ** Return the number of changes in the most recent call to sqlite3_exec(). |
| 166155 | 166401 | */ |
| 166156 | | -SQLITE_API int sqlite3_changes(sqlite3 *db){ |
| 166402 | +SQLITE_API sqlite3_int64 sqlite3_changes64(sqlite3 *db){ |
| 166157 | 166403 | #ifdef SQLITE_ENABLE_API_ARMOR |
| 166158 | 166404 | if( !sqlite3SafetyCheckOk(db) ){ |
| 166159 | 166405 | (void)SQLITE_MISUSE_BKPT; |
| 166160 | 166406 | return 0; |
| 166161 | 166407 | } |
| 166162 | 166408 | #endif |
| 166163 | 166409 | return db->nChange; |
| 166164 | 166410 | } |
| 166411 | +SQLITE_API int sqlite3_changes(sqlite3 *db){ |
| 166412 | + return (int)sqlite3_changes64(db); |
| 166413 | +} |
| 166165 | 166414 | |
| 166166 | 166415 | /* |
| 166167 | 166416 | ** Return the number of changes since the database handle was opened. |
| 166168 | 166417 | */ |
| 166169 | | -SQLITE_API int sqlite3_total_changes(sqlite3 *db){ |
| 166418 | +SQLITE_API sqlite3_int64 sqlite3_total_changes64(sqlite3 *db){ |
| 166170 | 166419 | #ifdef SQLITE_ENABLE_API_ARMOR |
| 166171 | 166420 | if( !sqlite3SafetyCheckOk(db) ){ |
| 166172 | 166421 | (void)SQLITE_MISUSE_BKPT; |
| 166173 | 166422 | return 0; |
| 166174 | 166423 | } |
| 166175 | 166424 | #endif |
| 166176 | 166425 | return db->nTotalChange; |
| 166426 | +} |
| 166427 | +SQLITE_API int sqlite3_total_changes(sqlite3 *db){ |
| 166428 | + return (int)sqlite3_total_changes64(db); |
| 166177 | 166429 | } |
| 166178 | 166430 | |
| 166179 | 166431 | /* |
| 166180 | 166432 | ** Close all open savepoints. This function only manipulates fields of the |
| 166181 | 166433 | ** database handle object, it does not close any savepoints that may be open |
| | @@ -166913,26 +167165,37 @@ |
| 166913 | 167165 | ** SQLITE_UTF16NATIVE macro. SQLITE_UTF16 is not used internally. |
| 166914 | 167166 | ** |
| 166915 | 167167 | ** If SQLITE_ANY is specified, add three versions of the function |
| 166916 | 167168 | ** to the hash table. |
| 166917 | 167169 | */ |
| 166918 | | - if( enc==SQLITE_UTF16 ){ |
| 166919 | | - enc = SQLITE_UTF16NATIVE; |
| 166920 | | - }else if( enc==SQLITE_ANY ){ |
| 166921 | | - int rc; |
| 166922 | | - rc = sqlite3CreateFunc(db, zFunctionName, nArg, |
| 166923 | | - (SQLITE_UTF8|extraFlags)^SQLITE_FUNC_UNSAFE, |
| 166924 | | - pUserData, xSFunc, xStep, xFinal, xValue, xInverse, pDestructor); |
| 166925 | | - if( rc==SQLITE_OK ){ |
| 166926 | | - rc = sqlite3CreateFunc(db, zFunctionName, nArg, |
| 166927 | | - (SQLITE_UTF16LE|extraFlags)^SQLITE_FUNC_UNSAFE, |
| 166928 | | - pUserData, xSFunc, xStep, xFinal, xValue, xInverse, pDestructor); |
| 166929 | | - } |
| 166930 | | - if( rc!=SQLITE_OK ){ |
| 166931 | | - return rc; |
| 166932 | | - } |
| 166933 | | - enc = SQLITE_UTF16BE; |
| 167170 | + switch( enc ){ |
| 167171 | + case SQLITE_UTF16: |
| 167172 | + enc = SQLITE_UTF16NATIVE; |
| 167173 | + break; |
| 167174 | + case SQLITE_ANY: { |
| 167175 | + int rc; |
| 167176 | + rc = sqlite3CreateFunc(db, zFunctionName, nArg, |
| 167177 | + (SQLITE_UTF8|extraFlags)^SQLITE_FUNC_UNSAFE, |
| 167178 | + pUserData, xSFunc, xStep, xFinal, xValue, xInverse, pDestructor); |
| 167179 | + if( rc==SQLITE_OK ){ |
| 167180 | + rc = sqlite3CreateFunc(db, zFunctionName, nArg, |
| 167181 | + (SQLITE_UTF16LE|extraFlags)^SQLITE_FUNC_UNSAFE, |
| 167182 | + pUserData, xSFunc, xStep, xFinal, xValue, xInverse, pDestructor); |
| 167183 | + } |
| 167184 | + if( rc!=SQLITE_OK ){ |
| 167185 | + return rc; |
| 167186 | + } |
| 167187 | + enc = SQLITE_UTF16BE; |
| 167188 | + break; |
| 167189 | + } |
| 167190 | + case SQLITE_UTF8: |
| 167191 | + case SQLITE_UTF16LE: |
| 167192 | + case SQLITE_UTF16BE: |
| 167193 | + break; |
| 167194 | + default: |
| 167195 | + enc = SQLITE_UTF8; |
| 167196 | + break; |
| 166934 | 167197 | } |
| 166935 | 167198 | #else |
| 166936 | 167199 | enc = SQLITE_UTF8; |
| 166937 | 167200 | #endif |
| 166938 | 167201 | |
| | @@ -167025,11 +167288,11 @@ |
| 167025 | 167288 | } |
| 167026 | 167289 | rc = sqlite3CreateFunc(db, zFunc, nArg, enc, p, |
| 167027 | 167290 | xSFunc, xStep, xFinal, xValue, xInverse, pArg |
| 167028 | 167291 | ); |
| 167029 | 167292 | if( pArg && pArg->nRef==0 ){ |
| 167030 | | - assert( rc!=SQLITE_OK ); |
| 167293 | + assert( rc!=SQLITE_OK || (xStep==0 && xFinal==0) ); |
| 167031 | 167294 | xDestroy(p); |
| 167032 | 167295 | sqlite3_free(pArg); |
| 167033 | 167296 | } |
| 167034 | 167297 | |
| 167035 | 167298 | out: |
| | @@ -168208,11 +168471,10 @@ |
| 168208 | 168471 | ** SQLITE_OPEN_READWRITE, SQLITE_OPEN_CREATE, SQLITE_OPEN_SHAREDCACHE, |
| 168209 | 168472 | ** SQLITE_OPEN_PRIVATECACHE, and some reserved bits. Silently mask |
| 168210 | 168473 | ** off all other flags. |
| 168211 | 168474 | */ |
| 168212 | 168475 | flags &= ~( SQLITE_OPEN_DELETEONCLOSE | |
| 168213 | | - SQLITE_OPEN_EXCLUSIVE | |
| 168214 | 168476 | SQLITE_OPEN_MAIN_DB | |
| 168215 | 168477 | SQLITE_OPEN_TEMP_DB | |
| 168216 | 168478 | SQLITE_OPEN_TRANSIENT_DB | |
| 168217 | 168479 | SQLITE_OPEN_MAIN_JOURNAL | |
| 168218 | 168480 | SQLITE_OPEN_TEMP_JOURNAL | |
| | @@ -168780,11 +169042,11 @@ |
| 168780 | 169042 | goto error_out; |
| 168781 | 169043 | } |
| 168782 | 169044 | |
| 168783 | 169045 | /* Locate the table in question */ |
| 168784 | 169046 | pTab = sqlite3FindTable(db, zTableName, zDbName); |
| 168785 | | - if( !pTab || pTab->pSelect ){ |
| 169047 | + if( !pTab || IsView(pTab) ){ |
| 168786 | 169048 | pTab = 0; |
| 168787 | 169049 | goto error_out; |
| 168788 | 169050 | } |
| 168789 | 169051 | |
| 168790 | 169052 | /* Find the column for which info is requested */ |
| | @@ -168791,11 +169053,11 @@ |
| 168791 | 169053 | if( zColumnName==0 ){ |
| 168792 | 169054 | /* Query for existance of table only */ |
| 168793 | 169055 | }else{ |
| 168794 | 169056 | for(iCol=0; iCol<pTab->nCol; iCol++){ |
| 168795 | 169057 | pCol = &pTab->aCol[iCol]; |
| 168796 | | - if( 0==sqlite3StrICmp(pCol->zName, zColumnName) ){ |
| 169058 | + if( 0==sqlite3StrICmp(pCol->zCnName, zColumnName) ){ |
| 168797 | 169059 | break; |
| 168798 | 169060 | } |
| 168799 | 169061 | } |
| 168800 | 169062 | if( iCol==pTab->nCol ){ |
| 168801 | 169063 | if( HasRowid(pTab) && sqlite3IsRowid(zColumnName) ){ |
| | @@ -168818,11 +169080,11 @@ |
| 168818 | 169080 | ** 2. The table is not a view and the column name identified an |
| 168819 | 169081 | ** explicitly declared column. Copy meta information from *pCol. |
| 168820 | 169082 | */ |
| 168821 | 169083 | if( pCol ){ |
| 168822 | 169084 | zDataType = sqlite3ColumnType(pCol,0); |
| 168823 | | - zCollSeq = pCol->zColl; |
| 169085 | + zCollSeq = sqlite3ColumnColl(pCol); |
| 168824 | 169086 | notnull = pCol->notNull!=0; |
| 168825 | 169087 | primarykey = (pCol->colFlags & COLFLAG_PRIMKEY)!=0; |
| 168826 | 169088 | autoinc = pTab->iPKey==iCol && (pTab->tabFlags & TF_Autoincrement)!=0; |
| 168827 | 169089 | }else{ |
| 168828 | 169090 | zDataType = "INTEGER"; |
| | @@ -169349,11 +169611,11 @@ |
| 169349 | 169611 | case 3: sqlite3WhereTrace = *ptr; break; |
| 169350 | 169612 | } |
| 169351 | 169613 | break; |
| 169352 | 169614 | } |
| 169353 | 169615 | |
| 169354 | | -#ifdef SQLITE_DEBUG |
| 169616 | +#if defined(SQLITE_DEBUG) && !defined(SQLITE_OMIT_WSD) |
| 169355 | 169617 | /* sqlite3_test_control(SQLITE_TESTCTRL_TUNE, id, *piValue) |
| 169356 | 169618 | ** |
| 169357 | 169619 | ** If "id" is an integer between 1 and SQLITE_NTUNE then set the value |
| 169358 | 169620 | ** of the id-th tuning parameter to *piValue. If "id" is between -1 |
| 169359 | 169621 | ** and -SQLITE_NTUNE, then write the current value of the (-id)-th |
| | @@ -201251,11 +201513,13 @@ |
| 201251 | 201513 | *piPk = 0; |
| 201252 | 201514 | |
| 201253 | 201515 | assert( p->rc==SQLITE_OK ); |
| 201254 | 201516 | p->rc = prepareFreeAndCollectError(p->dbMain, &aStmt[0], &p->zErrmsg, |
| 201255 | 201517 | sqlite3_mprintf( |
| 201256 | | - "SELECT (sql LIKE 'create virtual%%'), rootpage" |
| 201518 | + "SELECT " |
| 201519 | + " (sql COLLATE nocase BETWEEN 'CREATE VIRTUAL' AND 'CREATE VIRTUAM')," |
| 201520 | + " rootpage" |
| 201257 | 201521 | " FROM sqlite_schema" |
| 201258 | 201522 | " WHERE name=%Q", zTab |
| 201259 | 201523 | )); |
| 201260 | 201524 | if( p->rc!=SQLITE_OK || sqlite3_step(aStmt[0])!=SQLITE_ROW ){ |
| 201261 | 201525 | /* Either an error, or no such table. */ |
| | @@ -202784,11 +203048,11 @@ |
| 202784 | 203048 | case RBU_STATE_COOKIE: |
| 202785 | 203049 | pRet->iCookie = (u32)sqlite3_column_int64(pStmt, 1); |
| 202786 | 203050 | break; |
| 202787 | 203051 | |
| 202788 | 203052 | case RBU_STATE_OALSZ: |
| 202789 | | - pRet->iOalSz = (u32)sqlite3_column_int64(pStmt, 1); |
| 203053 | + pRet->iOalSz = sqlite3_column_int64(pStmt, 1); |
| 202790 | 203054 | break; |
| 202791 | 203055 | |
| 202792 | 203056 | case RBU_STATE_PHASEONESTEP: |
| 202793 | 203057 | pRet->nPhaseOneStep = sqlite3_column_int64(pStmt, 1); |
| 202794 | 203058 | break; |
| | @@ -213428,10 +213692,13 @@ |
| 213428 | 213692 | /* |
| 213429 | 213693 | ** This interface is used by the fts5vocab module. |
| 213430 | 213694 | */ |
| 213431 | 213695 | static const char *sqlite3Fts5IterTerm(Fts5IndexIter*, int*); |
| 213432 | 213696 | static int sqlite3Fts5IterNextScan(Fts5IndexIter*); |
| 213697 | +static void *sqlite3Fts5StructureRef(Fts5Index*); |
| 213698 | +static void sqlite3Fts5StructureRelease(void*); |
| 213699 | +static int sqlite3Fts5StructureTest(Fts5Index*, void*); |
| 213433 | 213700 | |
| 213434 | 213701 | |
| 213435 | 213702 | /* |
| 213436 | 213703 | ** Insert or remove data to or from the index. Each time a document is |
| 213437 | 213704 | ** added to or removed from the index, this function is called one or more |
| | @@ -216223,20 +216490,21 @@ |
| 216223 | 216490 | /* EOF */ |
| 216224 | 216491 | *piOff = -1; |
| 216225 | 216492 | return 1; |
| 216226 | 216493 | }else{ |
| 216227 | 216494 | i64 iOff = *piOff; |
| 216228 | | - int iVal; |
| 216495 | + u32 iVal; |
| 216229 | 216496 | fts5FastGetVarint32(a, i, iVal); |
| 216230 | 216497 | assert( iVal>=0 ); |
| 216231 | 216498 | if( iVal<=1 ){ |
| 216232 | 216499 | if( iVal==0 ){ |
| 216233 | 216500 | *pi = i; |
| 216234 | 216501 | return 0; |
| 216235 | 216502 | } |
| 216236 | 216503 | fts5FastGetVarint32(a, i, iVal); |
| 216237 | 216504 | iOff = ((i64)iVal) << 32; |
| 216505 | + assert( iOff>=0 ); |
| 216238 | 216506 | fts5FastGetVarint32(a, i, iVal); |
| 216239 | 216507 | if( iVal<2 ){ |
| 216240 | 216508 | /* This is a corrupt record. So stop parsing it here. */ |
| 216241 | 216509 | *piOff = -1; |
| 216242 | 216510 | return 1; |
| | @@ -216244,11 +216512,11 @@ |
| 216244 | 216512 | *piOff = iOff + ((iVal-2) & 0x7FFFFFFF); |
| 216245 | 216513 | }else{ |
| 216246 | 216514 | *piOff = (iOff & (i64)0x7FFFFFFF<<32)+((iOff + (iVal-2)) & 0x7FFFFFFF); |
| 216247 | 216515 | } |
| 216248 | 216516 | *pi = i; |
| 216249 | | - assert( *piOff>=iOff ); |
| 216517 | + assert_nc( *piOff>=iOff ); |
| 216250 | 216518 | return 0; |
| 216251 | 216519 | } |
| 216252 | 216520 | } |
| 216253 | 216521 | |
| 216254 | 216522 | |
| | @@ -217553,10 +217821,11 @@ |
| 217553 | 217821 | |
| 217554 | 217822 | static void sqlite3Fts5ParseError(Fts5Parse *pParse, const char *zFmt, ...){ |
| 217555 | 217823 | va_list ap; |
| 217556 | 217824 | va_start(ap, zFmt); |
| 217557 | 217825 | if( pParse->rc==SQLITE_OK ){ |
| 217826 | + assert( pParse->zErr==0 ); |
| 217558 | 217827 | pParse->zErr = sqlite3_vmprintf(zFmt, ap); |
| 217559 | 217828 | pParse->rc = SQLITE_ERROR; |
| 217560 | 217829 | } |
| 217561 | 217830 | va_end(ap); |
| 217562 | 217831 | } |
| | @@ -219562,13 +219831,12 @@ |
| 219562 | 219831 | Fts5ExprNode *pExpr, |
| 219563 | 219832 | Fts5Colset *pColset |
| 219564 | 219833 | ){ |
| 219565 | 219834 | Fts5Colset *pFree = pColset; |
| 219566 | 219835 | if( pParse->pConfig->eDetail==FTS5_DETAIL_NONE ){ |
| 219567 | | - pParse->rc = SQLITE_ERROR; |
| 219568 | | - pParse->zErr = sqlite3_mprintf( |
| 219569 | | - "fts5: column queries are not supported (detail=none)" |
| 219836 | + sqlite3Fts5ParseError(pParse, |
| 219837 | + "fts5: column queries are not supported (detail=none)" |
| 219570 | 219838 | ); |
| 219571 | 219839 | }else{ |
| 219572 | 219840 | fts5ParseSetColset(pParse, pExpr, pColset, &pFree); |
| 219573 | 219841 | } |
| 219574 | 219842 | sqlite3_free(pFree); |
| | @@ -219738,17 +220006,14 @@ |
| 219738 | 220006 | Fts5ExprPhrase *pPhrase = pNear->apPhrase[0]; |
| 219739 | 220007 | if( pNear->nPhrase!=1 |
| 219740 | 220008 | || pPhrase->nTerm>1 |
| 219741 | 220009 | || (pPhrase->nTerm>0 && pPhrase->aTerm[0].bFirst) |
| 219742 | 220010 | ){ |
| 219743 | | - assert( pParse->rc==SQLITE_OK ); |
| 219744 | | - pParse->rc = SQLITE_ERROR; |
| 219745 | | - assert( pParse->zErr==0 ); |
| 219746 | | - pParse->zErr = sqlite3_mprintf( |
| 220011 | + sqlite3Fts5ParseError(pParse, |
| 219747 | 220012 | "fts5: %s queries are not supported (detail!=full)", |
| 219748 | 220013 | pNear->nPhrase==1 ? "phrase": "NEAR" |
| 219749 | | - ); |
| 220014 | + ); |
| 219750 | 220015 | sqlite3_free(pRet); |
| 219751 | 220016 | pRet = 0; |
| 219752 | 220017 | } |
| 219753 | 220018 | } |
| 219754 | 220019 | }else{ |
| | @@ -221861,10 +222126,26 @@ |
| 221861 | 222126 | } |
| 221862 | 222127 | |
| 221863 | 222128 | static void fts5StructureRef(Fts5Structure *pStruct){ |
| 221864 | 222129 | pStruct->nRef++; |
| 221865 | 222130 | } |
| 222131 | + |
| 222132 | +static void *sqlite3Fts5StructureRef(Fts5Index *p){ |
| 222133 | + fts5StructureRef(p->pStruct); |
| 222134 | + return (void*)p->pStruct; |
| 222135 | +} |
| 222136 | +static void sqlite3Fts5StructureRelease(void *p){ |
| 222137 | + if( p ){ |
| 222138 | + fts5StructureRelease((Fts5Structure*)p); |
| 222139 | + } |
| 222140 | +} |
| 222141 | +static int sqlite3Fts5StructureTest(Fts5Index *p, void *pStruct){ |
| 222142 | + if( p->pStruct!=(Fts5Structure*)pStruct ){ |
| 222143 | + return SQLITE_ABORT; |
| 222144 | + } |
| 222145 | + return SQLITE_OK; |
| 222146 | +} |
| 221866 | 222147 | |
| 221867 | 222148 | /* |
| 221868 | 222149 | ** Deserialize and return the structure record currently stored in serialized |
| 221869 | 222150 | ** form within buffer pData/nData. |
| 221870 | 222151 | ** |
| | @@ -230568,11 +230849,11 @@ |
| 230568 | 230849 | int nArg, /* Number of args */ |
| 230569 | 230850 | sqlite3_value **apUnused /* Function arguments */ |
| 230570 | 230851 | ){ |
| 230571 | 230852 | assert( nArg==0 ); |
| 230572 | 230853 | UNUSED_PARAM2(nArg, apUnused); |
| 230573 | | - sqlite3_result_text(pCtx, "fts5: 2021-06-14 20:41:20 e5a5acd6006133c5da4a7dd79726dbaa41c0d60ebeda890f848a6aafe5f9ef70", -1, SQLITE_TRANSIENT); |
| 230854 | + sqlite3_result_text(pCtx, "fts5: 2021-08-06 20:17:39 087b8b41c6ed76b55c11315e7e95679d67590be20ae21108b593d00bb7d1c57a", -1, SQLITE_TRANSIENT); |
| 230574 | 230855 | } |
| 230575 | 230856 | |
| 230576 | 230857 | /* |
| 230577 | 230858 | ** Return true if zName is the extension on one of the shadow tables used |
| 230578 | 230859 | ** by this module. |
| | @@ -234464,10 +234745,11 @@ |
| 234464 | 234745 | sqlite3_stmt *pStmt; /* Statement holding lock on pIndex */ |
| 234465 | 234746 | Fts5Table *pFts5; /* Associated FTS5 table */ |
| 234466 | 234747 | |
| 234467 | 234748 | int bEof; /* True if this cursor is at EOF */ |
| 234468 | 234749 | Fts5IndexIter *pIter; /* Term/rowid iterator object */ |
| 234750 | + void *pStruct; /* From sqlite3Fts5StructureRef() */ |
| 234469 | 234751 | |
| 234470 | 234752 | int nLeTerm; /* Size of zLeTerm in bytes */ |
| 234471 | 234753 | char *zLeTerm; /* (term <= $zLeTerm) paramater, or NULL */ |
| 234472 | 234754 | |
| 234473 | 234755 | /* These are used by 'col' tables only */ |
| | @@ -234797,10 +235079,12 @@ |
| 234797 | 235079 | } |
| 234798 | 235080 | |
| 234799 | 235081 | static void fts5VocabResetCursor(Fts5VocabCursor *pCsr){ |
| 234800 | 235082 | pCsr->rowid = 0; |
| 234801 | 235083 | sqlite3Fts5IterClose(pCsr->pIter); |
| 235084 | + sqlite3Fts5StructureRelease(pCsr->pStruct); |
| 235085 | + pCsr->pStruct = 0; |
| 234802 | 235086 | pCsr->pIter = 0; |
| 234803 | 235087 | sqlite3_free(pCsr->zLeTerm); |
| 234804 | 235088 | pCsr->nLeTerm = -1; |
| 234805 | 235089 | pCsr->zLeTerm = 0; |
| 234806 | 235090 | pCsr->bEof = 0; |
| | @@ -234874,13 +235158,15 @@ |
| 234874 | 235158 | ** Advance the cursor to the next row in the table. |
| 234875 | 235159 | */ |
| 234876 | 235160 | static int fts5VocabNextMethod(sqlite3_vtab_cursor *pCursor){ |
| 234877 | 235161 | Fts5VocabCursor *pCsr = (Fts5VocabCursor*)pCursor; |
| 234878 | 235162 | Fts5VocabTable *pTab = (Fts5VocabTable*)pCursor->pVtab; |
| 234879 | | - int rc = SQLITE_OK; |
| 234880 | 235163 | int nCol = pCsr->pFts5->pConfig->nCol; |
| 235164 | + int rc; |
| 234881 | 235165 | |
| 235166 | + rc = sqlite3Fts5StructureTest(pCsr->pFts5->pIndex, pCsr->pStruct); |
| 235167 | + if( rc!=SQLITE_OK ) return rc; |
| 234882 | 235168 | pCsr->rowid++; |
| 234883 | 235169 | |
| 234884 | 235170 | if( pTab->eType==FTS5_VOCAB_INSTANCE ){ |
| 234885 | 235171 | return fts5VocabInstanceNext(pCsr); |
| 234886 | 235172 | } |
| | @@ -235050,10 +235336,13 @@ |
| 235050 | 235336 | } |
| 235051 | 235337 | |
| 235052 | 235338 | if( rc==SQLITE_OK ){ |
| 235053 | 235339 | Fts5Index *pIndex = pCsr->pFts5->pIndex; |
| 235054 | 235340 | rc = sqlite3Fts5IndexQuery(pIndex, zTerm, nTerm, f, 0, &pCsr->pIter); |
| 235341 | + if( rc==SQLITE_OK ){ |
| 235342 | + pCsr->pStruct = sqlite3Fts5StructureRef(pIndex); |
| 235343 | + } |
| 235055 | 235344 | } |
| 235056 | 235345 | if( rc==SQLITE_OK && eType==FTS5_VOCAB_INSTANCE ){ |
| 235057 | 235346 | rc = fts5VocabInstanceNewTerm(pCsr); |
| 235058 | 235347 | } |
| 235059 | 235348 | if( rc==SQLITE_OK && !pCsr->bEof |
| | @@ -235494,12 +235783,8 @@ |
| 235494 | 235783 | } |
| 235495 | 235784 | #endif /* SQLITE_CORE */ |
| 235496 | 235785 | #endif /* !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_STMTVTAB) */ |
| 235497 | 235786 | |
| 235498 | 235787 | /************** End of stmt.c ************************************************/ |
| 235499 | | -#if __LINE__!=235499 |
| 235500 | | -#undef SQLITE_SOURCE_ID |
| 235501 | | -#define SQLITE_SOURCE_ID "2021-06-14 20:41:20 e5a5acd6006133c5da4a7dd79726dbaa41c0d60ebeda890f848a6aafe5f9alt2" |
| 235502 | | -#endif |
| 235503 | 235788 | /* Return the source-id for this library */ |
| 235504 | 235789 | SQLITE_API const char *sqlite3_sourceid(void){ return SQLITE_SOURCE_ID; } |
| 235505 | 235790 | /************************** End of sqlite3.c ******************************/ |
| 235506 | 235791 | |