Fossil SCM

Update SQLite to the latest code (just prior to 3.6.8).

drh 2009-01-10 13:16 trunk
Commit ed28f6e76d46cb8503f050e71d8e8c44b5468ac3
2 files changed +6835 -4821 +5 -4
+6835 -4821
--- src/sqlite3.c
+++ src/sqlite3.c
@@ -1,8 +1,8 @@
11
/******************************************************************************
22
** This file is an amalgamation of many separate C source files from SQLite
3
-** version 3.6.7. By combining all the individual C code files into this
3
+** version 3.6.8. By combining all the individual C code files into this
44
** single large file, the entire code can be compiled as a one translation
55
** unit. This allows many compilers to do optimizations that would not be
66
** possible if the files were compiled separately. Performance improvements
77
** of 5% are more are commonly seen when SQLite is compiled as a single
88
** translation unit.
@@ -9,17 +9,17 @@
99
**
1010
** This file is all you need to compile SQLite. To use SQLite in other
1111
** programs, you need this file and the "sqlite3.h" header file that defines
1212
** the programming interface to the SQLite library. (If you do not have
1313
** the "sqlite3.h" header file at hand, you will find a copy in the first
14
-** 6735 lines past this header comment.) Additional code files may be
14
+** 6736 lines past this header comment.) Additional code files may be
1515
** needed if you want a wrapper to interface SQLite with your choice of
1616
** programming language. The code for the "sqlite3" command-line shell
1717
** is also in a separate file. This file contains only code for the core
1818
** SQLite library.
1919
**
20
-** This amalgamation was generated on 2008-12-16 18:01:52 UTC.
20
+** This amalgamation was generated on 2009-01-10 13:14:08 UTC.
2121
*/
2222
#define SQLITE_CORE 1
2323
#define SQLITE_AMALGAMATION 1
2424
#ifndef SQLITE_PRIVATE
2525
# define SQLITE_PRIVATE static
@@ -39,11 +39,11 @@
3939
** May you share freely, never taking more than you give.
4040
**
4141
*************************************************************************
4242
** Internal interface definitions for SQLite.
4343
**
44
-** @(#) $Id: sqliteInt.h,v 1.809 2008/12/10 21:19:57 drh Exp $
44
+** @(#) $Id: sqliteInt.h,v 1.821 2009/01/09 14:11:05 drh Exp $
4545
*/
4646
#ifndef _SQLITEINT_H_
4747
#define _SQLITEINT_H_
4848
4949
/*
@@ -68,11 +68,11 @@
6868
**
6969
*************************************************************************
7070
**
7171
** This file defines various limits of what SQLite can process.
7272
**
73
-** @(#) $Id: sqliteLimit.h,v 1.8 2008/03/26 15:56:22 drh Exp $
73
+** @(#) $Id: sqliteLimit.h,v 1.9 2009/01/07 16:15:43 danielk1977 Exp $
7474
*/
7575
7676
/*
7777
** The maximum length of a TEXT or BLOB in bytes. This also
7878
** limits the size of a row in a table or index.
@@ -152,11 +152,11 @@
152152
153153
/*
154154
** The maximum number of arguments to an SQL function.
155155
*/
156156
#ifndef SQLITE_MAX_FUNCTION_ARG
157
-# define SQLITE_MAX_FUNCTION_ARG 100
157
+# define SQLITE_MAX_FUNCTION_ARG 127
158158
#endif
159159
160160
/*
161161
** The maximum number of in-memory pages to use for the main database
162162
** table and for temporary tables. The SQLITE_DEFAULT_CACHE_SIZE
@@ -275,12 +275,14 @@
275275
** in places where simple condition/decision coverage is inadequate.
276276
*/
277277
#ifdef SQLITE_COVERAGE_TEST
278278
SQLITE_PRIVATE void sqlite3Coverage(int);
279279
# define testcase(X) if( X ){ sqlite3Coverage(__LINE__); }
280
+# define TESTONLY(X) X
280281
#else
281282
# define testcase(X)
283
+# define TESTONLY(X)
282284
#endif
283285
284286
/*
285287
** The ALWAYS and NEVER macros surround boolean expressions which
286288
** are intended to always be true or false, respectively. Such
@@ -451,10 +453,24 @@
451453
*/
452454
#if !defined(NDEBUG) && !defined(SQLITE_DEBUG)
453455
# define NDEBUG 1
454456
#endif
455457
458
+/*
459
+** Sometimes we need a small amount of code such as a variable initialization
460
+** to setup for a later assert() statement. We do not want this code to
461
+** appear when assert() is disabled. The following macro is therefore
462
+** used to contain that setup code. The "VVA" acronym stands for
463
+** "Verification, Validation, and Accreditation". In other words, the
464
+** code within VVA_ONLY() will only run during verification processes.
465
+*/
466
+#ifndef NDEBUG
467
+# define VVA_ONLY(X) X
468
+#else
469
+# define VVA_ONLY(X)
470
+#endif
471
+
456472
/************** Include sqlite3.h in the middle of sqliteInt.h ***************/
457473
/************** Begin file sqlite3.h *****************************************/
458474
/*
459475
** 2001 September 15
460476
**
@@ -485,11 +501,11 @@
485501
** The name of this file under configuration management is "sqlite.h.in".
486502
** The makefile makes some minor changes to this file (such as inserting
487503
** the version number) and changes its name to "sqlite3.h" as
488504
** part of the build process.
489505
**
490
-** @(#) $Id: sqlite.h.in,v 1.420 2008/12/16 13:46:30 drh Exp $
506
+** @(#) $Id: sqlite.h.in,v 1.421 2008/12/30 06:24:58 danielk1977 Exp $
491507
*/
492508
#ifndef _SQLITE3_H_
493509
#define _SQLITE3_H_
494510
#include <stdarg.h> /* Needed for the definition of va_list */
495511
@@ -562,12 +578,12 @@
562578
**
563579
** {H10014} The SQLITE_VERSION_NUMBER #define shall resolve to an integer
564580
** with the value (X*1000000 + Y*1000 + Z) where X, Y, and Z
565581
** are the major version, minor version, and release number.
566582
*/
567
-#define SQLITE_VERSION "3.6.7"
568
-#define SQLITE_VERSION_NUMBER 3006007
583
+#define SQLITE_VERSION "3.6.8"
584
+#define SQLITE_VERSION_NUMBER 3006008
569585
570586
/*
571587
** CAPI3REF: Run-Time Library Version Numbers {H10020} <S60100>
572588
** KEYWORDS: sqlite3_version
573589
**
@@ -2852,20 +2868,21 @@
28522868
#define SQLITE_DROP_VIEW 17 /* View Name NULL */
28532869
#define SQLITE_INSERT 18 /* Table Name NULL */
28542870
#define SQLITE_PRAGMA 19 /* Pragma Name 1st arg or NULL */
28552871
#define SQLITE_READ 20 /* Table Name Column Name */
28562872
#define SQLITE_SELECT 21 /* NULL NULL */
2857
-#define SQLITE_TRANSACTION 22 /* NULL NULL */
2873
+#define SQLITE_TRANSACTION 22 /* Operation NULL */
28582874
#define SQLITE_UPDATE 23 /* Table Name Column Name */
28592875
#define SQLITE_ATTACH 24 /* Filename NULL */
28602876
#define SQLITE_DETACH 25 /* Database Name NULL */
28612877
#define SQLITE_ALTER_TABLE 26 /* Database Name Table Name */
28622878
#define SQLITE_REINDEX 27 /* Index Name NULL */
28632879
#define SQLITE_ANALYZE 28 /* Table Name NULL */
28642880
#define SQLITE_CREATE_VTABLE 29 /* Table Name Module Name */
28652881
#define SQLITE_DROP_VTABLE 30 /* Table Name Module Name */
28662882
#define SQLITE_FUNCTION 31 /* NULL Function Name */
2883
+#define SQLITE_SAVEPOINT 32 /* Operation Savepoint Name */
28672884
#define SQLITE_COPY 0 /* No longer used */
28682885
28692886
/*
28702887
** CAPI3REF: Tracing And Profiling Functions {H12280} <S60400>
28712888
** EXPERIMENTAL
@@ -7297,150 +7314,152 @@
72977314
#define TK_IMMEDIATE 8
72987315
#define TK_EXCLUSIVE 9
72997316
#define TK_COMMIT 10
73007317
#define TK_END 11
73017318
#define TK_ROLLBACK 12
7302
-#define TK_CREATE 13
7303
-#define TK_TABLE 14
7304
-#define TK_IF 15
7305
-#define TK_NOT 16
7306
-#define TK_EXISTS 17
7307
-#define TK_TEMP 18
7308
-#define TK_LP 19
7309
-#define TK_RP 20
7310
-#define TK_AS 21
7311
-#define TK_COMMA 22
7312
-#define TK_ID 23
7313
-#define TK_ABORT 24
7314
-#define TK_AFTER 25
7315
-#define TK_ANALYZE 26
7316
-#define TK_ASC 27
7317
-#define TK_ATTACH 28
7318
-#define TK_BEFORE 29
7319
-#define TK_CASCADE 30
7320
-#define TK_CAST 31
7321
-#define TK_CONFLICT 32
7322
-#define TK_DATABASE 33
7323
-#define TK_DESC 34
7324
-#define TK_DETACH 35
7325
-#define TK_EACH 36
7326
-#define TK_FAIL 37
7327
-#define TK_FOR 38
7328
-#define TK_IGNORE 39
7329
-#define TK_INITIALLY 40
7330
-#define TK_INSTEAD 41
7331
-#define TK_LIKE_KW 42
7332
-#define TK_MATCH 43
7333
-#define TK_KEY 44
7334
-#define TK_OF 45
7335
-#define TK_OFFSET 46
7336
-#define TK_PRAGMA 47
7337
-#define TK_RAISE 48
7338
-#define TK_REPLACE 49
7339
-#define TK_RESTRICT 50
7340
-#define TK_ROW 51
7341
-#define TK_TRIGGER 52
7342
-#define TK_VACUUM 53
7343
-#define TK_VIEW 54
7344
-#define TK_VIRTUAL 55
7345
-#define TK_REINDEX 56
7346
-#define TK_RENAME 57
7347
-#define TK_CTIME_KW 58
7348
-#define TK_ANY 59
7349
-#define TK_OR 60
7350
-#define TK_AND 61
7351
-#define TK_IS 62
7352
-#define TK_BETWEEN 63
7353
-#define TK_IN 64
7354
-#define TK_ISNULL 65
7355
-#define TK_NOTNULL 66
7356
-#define TK_NE 67
7357
-#define TK_EQ 68
7358
-#define TK_GT 69
7359
-#define TK_LE 70
7360
-#define TK_LT 71
7361
-#define TK_GE 72
7362
-#define TK_ESCAPE 73
7363
-#define TK_BITAND 74
7364
-#define TK_BITOR 75
7365
-#define TK_LSHIFT 76
7366
-#define TK_RSHIFT 77
7367
-#define TK_PLUS 78
7368
-#define TK_MINUS 79
7369
-#define TK_STAR 80
7370
-#define TK_SLASH 81
7371
-#define TK_REM 82
7372
-#define TK_CONCAT 83
7373
-#define TK_COLLATE 84
7374
-#define TK_UMINUS 85
7375
-#define TK_UPLUS 86
7376
-#define TK_BITNOT 87
7377
-#define TK_STRING 88
7378
-#define TK_JOIN_KW 89
7379
-#define TK_CONSTRAINT 90
7380
-#define TK_DEFAULT 91
7381
-#define TK_NULL 92
7382
-#define TK_PRIMARY 93
7383
-#define TK_UNIQUE 94
7384
-#define TK_CHECK 95
7385
-#define TK_REFERENCES 96
7386
-#define TK_AUTOINCR 97
7387
-#define TK_ON 98
7388
-#define TK_DELETE 99
7389
-#define TK_UPDATE 100
7390
-#define TK_INSERT 101
7391
-#define TK_SET 102
7392
-#define TK_DEFERRABLE 103
7393
-#define TK_FOREIGN 104
7394
-#define TK_DROP 105
7395
-#define TK_UNION 106
7396
-#define TK_ALL 107
7397
-#define TK_EXCEPT 108
7398
-#define TK_INTERSECT 109
7399
-#define TK_SELECT 110
7400
-#define TK_DISTINCT 111
7401
-#define TK_DOT 112
7402
-#define TK_FROM 113
7403
-#define TK_JOIN 114
7404
-#define TK_INDEXED 115
7405
-#define TK_BY 116
7406
-#define TK_USING 117
7407
-#define TK_ORDER 118
7408
-#define TK_GROUP 119
7409
-#define TK_HAVING 120
7410
-#define TK_LIMIT 121
7411
-#define TK_WHERE 122
7412
-#define TK_INTO 123
7413
-#define TK_VALUES 124
7414
-#define TK_INTEGER 125
7415
-#define TK_FLOAT 126
7416
-#define TK_BLOB 127
7417
-#define TK_REGISTER 128
7418
-#define TK_VARIABLE 129
7419
-#define TK_CASE 130
7420
-#define TK_WHEN 131
7421
-#define TK_THEN 132
7422
-#define TK_ELSE 133
7423
-#define TK_INDEX 134
7424
-#define TK_ALTER 135
7425
-#define TK_TO 136
7426
-#define TK_ADD 137
7427
-#define TK_COLUMNKW 138
7428
-#define TK_TO_TEXT 139
7429
-#define TK_TO_BLOB 140
7430
-#define TK_TO_NUMERIC 141
7431
-#define TK_TO_INT 142
7432
-#define TK_TO_REAL 143
7433
-#define TK_END_OF_FILE 144
7434
-#define TK_ILLEGAL 145
7435
-#define TK_SPACE 146
7436
-#define TK_UNCLOSED_STRING 147
7437
-#define TK_FUNCTION 148
7438
-#define TK_COLUMN 149
7439
-#define TK_AGG_FUNCTION 150
7440
-#define TK_AGG_COLUMN 151
7441
-#define TK_CONST_FUNC 152
7319
+#define TK_SAVEPOINT 13
7320
+#define TK_RELEASE 14
7321
+#define TK_TO 15
7322
+#define TK_CREATE 16
7323
+#define TK_TABLE 17
7324
+#define TK_IF 18
7325
+#define TK_NOT 19
7326
+#define TK_EXISTS 20
7327
+#define TK_TEMP 21
7328
+#define TK_LP 22
7329
+#define TK_RP 23
7330
+#define TK_AS 24
7331
+#define TK_COMMA 25
7332
+#define TK_ID 26
7333
+#define TK_ABORT 27
7334
+#define TK_AFTER 28
7335
+#define TK_ANALYZE 29
7336
+#define TK_ASC 30
7337
+#define TK_ATTACH 31
7338
+#define TK_BEFORE 32
7339
+#define TK_CASCADE 33
7340
+#define TK_CAST 34
7341
+#define TK_CONFLICT 35
7342
+#define TK_DATABASE 36
7343
+#define TK_DESC 37
7344
+#define TK_DETACH 38
7345
+#define TK_EACH 39
7346
+#define TK_FAIL 40
7347
+#define TK_FOR 41
7348
+#define TK_IGNORE 42
7349
+#define TK_INITIALLY 43
7350
+#define TK_INSTEAD 44
7351
+#define TK_LIKE_KW 45
7352
+#define TK_MATCH 46
7353
+#define TK_KEY 47
7354
+#define TK_OF 48
7355
+#define TK_OFFSET 49
7356
+#define TK_PRAGMA 50
7357
+#define TK_RAISE 51
7358
+#define TK_REPLACE 52
7359
+#define TK_RESTRICT 53
7360
+#define TK_ROW 54
7361
+#define TK_TRIGGER 55
7362
+#define TK_VACUUM 56
7363
+#define TK_VIEW 57
7364
+#define TK_VIRTUAL 58
7365
+#define TK_REINDEX 59
7366
+#define TK_RENAME 60
7367
+#define TK_CTIME_KW 61
7368
+#define TK_ANY 62
7369
+#define TK_OR 63
7370
+#define TK_AND 64
7371
+#define TK_IS 65
7372
+#define TK_BETWEEN 66
7373
+#define TK_IN 67
7374
+#define TK_ISNULL 68
7375
+#define TK_NOTNULL 69
7376
+#define TK_NE 70
7377
+#define TK_EQ 71
7378
+#define TK_GT 72
7379
+#define TK_LE 73
7380
+#define TK_LT 74
7381
+#define TK_GE 75
7382
+#define TK_ESCAPE 76
7383
+#define TK_BITAND 77
7384
+#define TK_BITOR 78
7385
+#define TK_LSHIFT 79
7386
+#define TK_RSHIFT 80
7387
+#define TK_PLUS 81
7388
+#define TK_MINUS 82
7389
+#define TK_STAR 83
7390
+#define TK_SLASH 84
7391
+#define TK_REM 85
7392
+#define TK_CONCAT 86
7393
+#define TK_COLLATE 87
7394
+#define TK_UMINUS 88
7395
+#define TK_UPLUS 89
7396
+#define TK_BITNOT 90
7397
+#define TK_STRING 91
7398
+#define TK_JOIN_KW 92
7399
+#define TK_CONSTRAINT 93
7400
+#define TK_DEFAULT 94
7401
+#define TK_NULL 95
7402
+#define TK_PRIMARY 96
7403
+#define TK_UNIQUE 97
7404
+#define TK_CHECK 98
7405
+#define TK_REFERENCES 99
7406
+#define TK_AUTOINCR 100
7407
+#define TK_ON 101
7408
+#define TK_DELETE 102
7409
+#define TK_UPDATE 103
7410
+#define TK_INSERT 104
7411
+#define TK_SET 105
7412
+#define TK_DEFERRABLE 106
7413
+#define TK_FOREIGN 107
7414
+#define TK_DROP 108
7415
+#define TK_UNION 109
7416
+#define TK_ALL 110
7417
+#define TK_EXCEPT 111
7418
+#define TK_INTERSECT 112
7419
+#define TK_SELECT 113
7420
+#define TK_DISTINCT 114
7421
+#define TK_DOT 115
7422
+#define TK_FROM 116
7423
+#define TK_JOIN 117
7424
+#define TK_INDEXED 118
7425
+#define TK_BY 119
7426
+#define TK_USING 120
7427
+#define TK_ORDER 121
7428
+#define TK_GROUP 122
7429
+#define TK_HAVING 123
7430
+#define TK_LIMIT 124
7431
+#define TK_WHERE 125
7432
+#define TK_INTO 126
7433
+#define TK_VALUES 127
7434
+#define TK_INTEGER 128
7435
+#define TK_FLOAT 129
7436
+#define TK_BLOB 130
7437
+#define TK_REGISTER 131
7438
+#define TK_VARIABLE 132
7439
+#define TK_CASE 133
7440
+#define TK_WHEN 134
7441
+#define TK_THEN 135
7442
+#define TK_ELSE 136
7443
+#define TK_INDEX 137
7444
+#define TK_ALTER 138
7445
+#define TK_ADD 139
7446
+#define TK_COLUMNKW 140
7447
+#define TK_TO_TEXT 141
7448
+#define TK_TO_BLOB 142
7449
+#define TK_TO_NUMERIC 143
7450
+#define TK_TO_INT 144
7451
+#define TK_TO_REAL 145
7452
+#define TK_END_OF_FILE 146
7453
+#define TK_ILLEGAL 147
7454
+#define TK_SPACE 148
7455
+#define TK_UNCLOSED_STRING 149
7456
+#define TK_FUNCTION 150
7457
+#define TK_COLUMN 151
7458
+#define TK_AGG_FUNCTION 152
7459
+#define TK_AGG_COLUMN 153
7460
+#define TK_CONST_FUNC 154
74427461
74437462
/************** End of parse.h ***********************************************/
74447463
/************** Continuing where we left off in sqliteInt.h ******************/
74457464
#include <stdio.h>
74467465
#include <stdlib.h>
@@ -7723,10 +7742,11 @@
77237742
typedef struct Lookaside Lookaside;
77247743
typedef struct LookasideSlot LookasideSlot;
77257744
typedef struct Module Module;
77267745
typedef struct NameContext NameContext;
77277746
typedef struct Parse Parse;
7747
+typedef struct Savepoint Savepoint;
77287748
typedef struct Select Select;
77297749
typedef struct SrcList SrcList;
77307750
typedef struct StrAccum StrAccum;
77317751
typedef struct Table Table;
77327752
typedef struct TableLock TableLock;
@@ -7734,10 +7754,11 @@
77347754
typedef struct TriggerStack TriggerStack;
77357755
typedef struct TriggerStep TriggerStep;
77367756
typedef struct Trigger Trigger;
77377757
typedef struct UnpackedRecord UnpackedRecord;
77387758
typedef struct Walker Walker;
7759
+typedef struct WherePlan WherePlan;
77397760
typedef struct WhereInfo WhereInfo;
77407761
typedef struct WhereLevel WhereLevel;
77417762
77427763
/*
77437764
** Defer sourcing vdbe.h and btree.h until after the "u8" and
@@ -7759,11 +7780,11 @@
77597780
*************************************************************************
77607781
** This header file defines the interface that the sqlite B-Tree file
77617782
** subsystem. See comments in the source code for a detailed description
77627783
** of what each interface routine does.
77637784
**
7764
-** @(#) $Id: btree.h,v 1.105 2008/10/27 13:59:34 danielk1977 Exp $
7785
+** @(#) $Id: btree.h,v 1.106 2008/12/17 17:30:26 danielk1977 Exp $
77657786
*/
77667787
#ifndef _BTREE_H_
77677788
#define _BTREE_H_
77687789
77697790
/* TODO: This definition is just included so other modules compile. It
@@ -7847,10 +7868,11 @@
78477868
SQLITE_PRIVATE int sqlite3BtreeIsInStmt(Btree*);
78487869
SQLITE_PRIVATE int sqlite3BtreeIsInReadTrans(Btree*);
78497870
SQLITE_PRIVATE void *sqlite3BtreeSchema(Btree *, int, void(*)(void *));
78507871
SQLITE_PRIVATE int sqlite3BtreeSchemaLocked(Btree *);
78517872
SQLITE_PRIVATE int sqlite3BtreeLockTable(Btree *, int, u8);
7873
+SQLITE_PRIVATE int sqlite3BtreeSavepoint(Btree *, int, int);
78527874
78537875
SQLITE_PRIVATE const char *sqlite3BtreeGetFilename(Btree *);
78547876
SQLITE_PRIVATE const char *sqlite3BtreeGetDirname(Btree *);
78557877
SQLITE_PRIVATE const char *sqlite3BtreeGetJournalname(Btree *);
78567878
SQLITE_PRIVATE int sqlite3BtreeCopyFile(Btree *, Btree *);
@@ -8122,155 +8144,157 @@
81228144
*/
81238145
/************** Include opcodes.h in the middle of vdbe.h ********************/
81248146
/************** Begin file opcodes.h *****************************************/
81258147
/* Automatically generated. Do not edit */
81268148
/* See the mkopcodeh.awk script for details */
8127
-#define OP_VNext 1
8128
-#define OP_Affinity 2
8129
-#define OP_Column 3
8130
-#define OP_SetCookie 4
8131
-#define OP_Seek 5
8132
-#define OP_Real 126 /* same as TK_FLOAT */
8133
-#define OP_Sequence 6
8134
-#define OP_Ge 72 /* same as TK_GE */
8135
-#define OP_RowKey 7
8136
-#define OP_SCopy 8
8137
-#define OP_Eq 68 /* same as TK_EQ */
8138
-#define OP_OpenWrite 9
8139
-#define OP_NotNull 66 /* same as TK_NOTNULL */
8140
-#define OP_If 10
8141
-#define OP_ToInt 142 /* same as TK_TO_INT */
8142
-#define OP_String8 88 /* same as TK_STRING */
8143
-#define OP_VRowid 11
8144
-#define OP_CollSeq 12
8145
-#define OP_OpenRead 13
8146
-#define OP_Expire 14
8147
-#define OP_AutoCommit 15
8148
-#define OP_Gt 69 /* same as TK_GT */
8149
-#define OP_Pagecount 17
8150
-#define OP_IntegrityCk 18
8151
-#define OP_Sort 19
8152
-#define OP_Copy 20
8149
+#define OP_VCreate 1
8150
+#define OP_MemMax 2
8151
+#define OP_LoadAnalysis 3
8152
+#define OP_RowData 4
8153
+#define OP_CreateIndex 5
8154
+#define OP_Variable 6
8155
+#define OP_SeekGt 7
8156
+#define OP_SeekLe 8
8157
+#define OP_IfNeg 9
8158
+#define OP_Clear 10
8159
+#define OP_Last 11
8160
+#define OP_Add 81 /* same as TK_PLUS */
8161
+#define OP_Savepoint 12
8162
+#define OP_Sequence 13
8163
+#define OP_Int64 14
8164
+#define OP_VBegin 15
8165
+#define OP_RowKey 16
8166
+#define OP_Divide 84 /* same as TK_SLASH */
8167
+#define OP_SCopy 17
8168
+#define OP_ResetCount 18
8169
+#define OP_Delete 20
81538170
#define OP_Trace 21
8154
-#define OP_Function 22
8155
-#define OP_IfNeg 23
8156
-#define OP_And 61 /* same as TK_AND */
8157
-#define OP_Subtract 79 /* same as TK_MINUS */
8158
-#define OP_Noop 24
8159
-#define OP_Return 25
8160
-#define OP_Remainder 82 /* same as TK_REM */
8161
-#define OP_NewRowid 26
8162
-#define OP_Multiply 80 /* same as TK_STAR */
8163
-#define OP_Variable 27
8164
-#define OP_String 28
8165
-#define OP_RealAffinity 29
8166
-#define OP_VRename 30
8167
-#define OP_ParseSchema 31
8168
-#define OP_VOpen 32
8169
-#define OP_Close 33
8170
-#define OP_CreateIndex 34
8171
-#define OP_IsUnique 35
8172
-#define OP_NotFound 36
8173
-#define OP_Int64 37
8174
-#define OP_MustBeInt 38
8175
-#define OP_Halt 39
8176
-#define OP_Rowid 40
8177
-#define OP_IdxLT 41
8178
-#define OP_AddImm 42
8179
-#define OP_Statement 43
8180
-#define OP_RowData 44
8181
-#define OP_MemMax 45
8182
-#define OP_Or 60 /* same as TK_OR */
8183
-#define OP_NotExists 46
8184
-#define OP_Gosub 47
8185
-#define OP_Divide 81 /* same as TK_SLASH */
8186
-#define OP_Integer 48
8187
-#define OP_ToNumeric 141 /* same as TK_TO_NUMERIC*/
8188
-#define OP_Prev 49
8189
-#define OP_RowSetRead 50
8190
-#define OP_Concat 83 /* same as TK_CONCAT */
8191
-#define OP_RowSetAdd 51
8192
-#define OP_BitAnd 74 /* same as TK_BITAND */
8193
-#define OP_VColumn 52
8194
-#define OP_CreateTable 53
8195
-#define OP_Last 54
8196
-#define OP_SeekLe 55
8197
-#define OP_IsNull 65 /* same as TK_ISNULL */
8198
-#define OP_IncrVacuum 56
8199
-#define OP_IdxRowid 57
8200
-#define OP_ShiftRight 77 /* same as TK_RSHIFT */
8201
-#define OP_ResetCount 58
8202
-#define OP_ContextPush 59
8203
-#define OP_Yield 62
8204
-#define OP_DropTrigger 63
8205
-#define OP_DropIndex 64
8206
-#define OP_IdxGE 73
8207
-#define OP_IdxDelete 84
8208
-#define OP_Vacuum 85
8209
-#define OP_IfNot 86
8210
-#define OP_DropTable 89
8211
-#define OP_SeekLt 90
8212
-#define OP_MakeRecord 91
8213
-#define OP_ToBlob 140 /* same as TK_TO_BLOB */
8214
-#define OP_ResultRow 92
8215
-#define OP_Delete 93
8216
-#define OP_AggFinal 94
8217
-#define OP_Compare 95
8218
-#define OP_ShiftLeft 76 /* same as TK_LSHIFT */
8219
-#define OP_Goto 96
8220
-#define OP_TableLock 97
8221
-#define OP_Clear 98
8222
-#define OP_Le 70 /* same as TK_LE */
8223
-#define OP_VerifyCookie 99
8224
-#define OP_AggStep 100
8225
-#define OP_ToText 139 /* same as TK_TO_TEXT */
8226
-#define OP_Not 16 /* same as TK_NOT */
8227
-#define OP_ToReal 143 /* same as TK_TO_REAL */
8228
-#define OP_SetNumColumns 101
8229
-#define OP_Transaction 102
8230
-#define OP_VFilter 103
8231
-#define OP_Ne 67 /* same as TK_NE */
8232
-#define OP_VDestroy 104
8233
-#define OP_ContextPop 105
8234
-#define OP_BitOr 75 /* same as TK_BITOR */
8235
-#define OP_Next 106
8236
-#define OP_IdxInsert 107
8237
-#define OP_Lt 71 /* same as TK_LT */
8238
-#define OP_SeekGe 108
8239
-#define OP_Insert 109
8240
-#define OP_Destroy 110
8241
-#define OP_ReadCookie 111
8242
-#define OP_LoadAnalysis 112
8243
-#define OP_Explain 113
8244
-#define OP_OpenPseudo 114
8245
-#define OP_OpenEphemeral 115
8246
-#define OP_Null 116
8247
-#define OP_Move 117
8248
-#define OP_Blob 118
8249
-#define OP_Add 78 /* same as TK_PLUS */
8250
-#define OP_Rewind 119
8251
-#define OP_SeekGt 120
8252
-#define OP_VBegin 121
8253
-#define OP_VUpdate 122
8254
-#define OP_IfZero 123
8255
-#define OP_BitNot 87 /* same as TK_BITNOT */
8256
-#define OP_VCreate 124
8257
-#define OP_Found 125
8171
+#define OP_Rowid 22
8172
+#define OP_OpenRead 23
8173
+#define OP_Sort 24
8174
+#define OP_VerifyCookie 25
8175
+#define OP_VColumn 26
8176
+#define OP_Next 27
8177
+#define OP_Insert 28
8178
+#define OP_Prev 29
8179
+#define OP_IdxGE 30
8180
+#define OP_Not 19 /* same as TK_NOT */
8181
+#define OP_Ge 75 /* same as TK_GE */
8182
+#define OP_VRename 31
8183
+#define OP_DropTable 32
8184
+#define OP_MakeRecord 33
8185
+#define OP_Null 34
8186
+#define OP_IdxInsert 35
8187
+#define OP_SeekLt 36
8188
+#define OP_ReadCookie 37
8189
+#define OP_VDestroy 38
8190
+#define OP_DropIndex 39
8191
+#define OP_IsNull 68 /* same as TK_ISNULL */
8192
+#define OP_MustBeInt 40
8193
+#define OP_IntegrityCk 41
8194
+#define OP_CollSeq 42
8195
+#define OP_ResultRow 43
8196
+#define OP_Yield 44
8197
+#define OP_OpenEphemeral 45
8198
+#define OP_VNext 46
8199
+#define OP_Seek 47
8200
+#define OP_Eq 71 /* same as TK_EQ */
8201
+#define OP_String8 91 /* same as TK_STRING */
8202
+#define OP_Found 48
8203
+#define OP_If 49
8204
+#define OP_ToBlob 142 /* same as TK_TO_BLOB */
8205
+#define OP_Multiply 83 /* same as TK_STAR */
8206
+#define OP_IfZero 50
8207
+#define OP_ShiftRight 80 /* same as TK_RSHIFT */
8208
+#define OP_Goto 51
8209
+#define OP_Function 52
8210
+#define OP_Copy 53
8211
+#define OP_Jump 54
8212
+#define OP_Blob 55
8213
+#define OP_BitNot 90 /* same as TK_BITNOT */
8214
+#define OP_Gt 72 /* same as TK_GT */
8215
+#define OP_Le 73 /* same as TK_LE */
8216
+#define OP_NullRow 56
8217
+#define OP_Transaction 57
8218
+#define OP_VUpdate 58
8219
+#define OP_TableLock 59
8220
+#define OP_IdxRowid 60
8221
+#define OP_SetCookie 61
8222
+#define OP_And 64 /* same as TK_AND */
8223
+#define OP_ToNumeric 143 /* same as TK_TO_NUMERIC*/
8224
+#define OP_ToText 141 /* same as TK_TO_TEXT */
8225
+#define OP_ContextPush 62
8226
+#define OP_DropTrigger 65
8227
+#define OP_AutoCommit 66
8228
+#define OP_Column 67
8229
+#define OP_AddImm 76
8230
+#define OP_Remainder 85 /* same as TK_REM */
8231
+#define OP_ContextPop 87
8232
+#define OP_IdxDelete 88
8233
+#define OP_Ne 70 /* same as TK_NE */
8234
+#define OP_ToInt 144 /* same as TK_TO_INT */
8235
+#define OP_IncrVacuum 89
8236
+#define OP_AggFinal 92
8237
+#define OP_RealAffinity 93
8238
+#define OP_Concat 86 /* same as TK_CONCAT */
8239
+#define OP_Return 94
8240
+#define OP_Expire 95
8241
+#define OP_Rewind 96
8242
+#define OP_Statement 97
8243
+#define OP_BitOr 78 /* same as TK_BITOR */
8244
+#define OP_Integer 98
8245
+#define OP_Compare 99
8246
+#define OP_Destroy 100
8247
+#define OP_IdxLT 101
8248
+#define OP_Affinity 102
8249
+#define OP_Lt 74 /* same as TK_LT */
8250
+#define OP_Subtract 82 /* same as TK_MINUS */
8251
+#define OP_Vacuum 103
8252
+#define OP_IfNot 104
8253
+#define OP_Move 105
8254
+#define OP_Explain 106
8255
+#define OP_ParseSchema 107
8256
+#define OP_NewRowid 108
8257
+#define OP_SetNumColumns 109
8258
+#define OP_BitAnd 77 /* same as TK_BITAND */
8259
+#define OP_String 110
8260
+#define OP_AggStep 111
8261
+#define OP_VRowid 112
8262
+#define OP_VOpen 113
8263
+#define OP_NotExists 114
8264
+#define OP_Close 115
8265
+#define OP_Halt 116
8266
+#define OP_Noop 117
8267
+#define OP_SeekGe 118
8268
+#define OP_VFilter 119
8269
+#define OP_OpenPseudo 120
8270
+#define OP_Or 63 /* same as TK_OR */
8271
+#define OP_ShiftLeft 79 /* same as TK_LSHIFT */
8272
+#define OP_ToReal 145 /* same as TK_TO_REAL */
8273
+#define OP_RowSetRead 121
8274
+#define OP_RowSetAdd 122
8275
+#define OP_IsUnique 123
8276
+#define OP_OpenWrite 124
8277
+#define OP_Permutation 125
8278
+#define OP_Gosub 126
82588279
#define OP_IfPos 127
8259
-#define OP_NullRow 128
8260
-#define OP_Jump 129
8261
-#define OP_Permutation 130
8280
+#define OP_Real 129 /* same as TK_FLOAT */
8281
+#define OP_NotNull 69 /* same as TK_NOTNULL */
8282
+#define OP_Pagecount 128
8283
+#define OP_NotFound 130
8284
+#define OP_CreateTable 131
82628285
82638286
/* The following opcode values are never used */
8264
-#define OP_NotUsed_131 131
82658287
#define OP_NotUsed_132 132
82668288
#define OP_NotUsed_133 133
82678289
#define OP_NotUsed_134 134
82688290
#define OP_NotUsed_135 135
82698291
#define OP_NotUsed_136 136
82708292
#define OP_NotUsed_137 137
82718293
#define OP_NotUsed_138 138
8294
+#define OP_NotUsed_139 139
8295
+#define OP_NotUsed_140 140
82728296
82738297
82748298
/* Properties such as "out2" or "jump" that are specified in
82758299
** comments following the "case" for each opcode in the vdbe.c
82768300
** are encoded into bitvectors as follows:
@@ -8280,29 +8304,29 @@
82808304
#define OPFLG_IN1 0x0004 /* in1: P1 is an input */
82818305
#define OPFLG_IN2 0x0008 /* in2: P2 is an input */
82828306
#define OPFLG_IN3 0x0010 /* in3: P3 is an input */
82838307
#define OPFLG_OUT3 0x0020 /* out3: P3 is an output */
82848308
#define OPFLG_INITIALIZER {\
8285
-/* 0 */ 0x00, 0x01, 0x00, 0x00, 0x10, 0x08, 0x02, 0x00,\
8286
-/* 8 */ 0x00, 0x00, 0x05, 0x02, 0x00, 0x00, 0x00, 0x00,\
8287
-/* 16 */ 0x04, 0x02, 0x00, 0x01, 0x00, 0x00, 0x00, 0x05,\
8288
-/* 24 */ 0x00, 0x04, 0x02, 0x02, 0x02, 0x04, 0x00, 0x00,\
8289
-/* 32 */ 0x00, 0x00, 0x02, 0x11, 0x11, 0x02, 0x05, 0x00,\
8290
-/* 40 */ 0x02, 0x11, 0x04, 0x00, 0x00, 0x0c, 0x11, 0x01,\
8291
-/* 48 */ 0x02, 0x01, 0x21, 0x08, 0x00, 0x02, 0x01, 0x11,\
8292
-/* 56 */ 0x01, 0x02, 0x00, 0x00, 0x2c, 0x2c, 0x00, 0x00,\
8293
-/* 64 */ 0x00, 0x05, 0x05, 0x15, 0x15, 0x15, 0x15, 0x15,\
8294
-/* 72 */ 0x15, 0x11, 0x2c, 0x2c, 0x2c, 0x2c, 0x2c, 0x2c,\
8295
-/* 80 */ 0x2c, 0x2c, 0x2c, 0x2c, 0x00, 0x00, 0x05, 0x04,\
8296
-/* 88 */ 0x02, 0x00, 0x11, 0x00, 0x00, 0x00, 0x00, 0x00,\
8297
-/* 96 */ 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,\
8298
-/* 104 */ 0x00, 0x00, 0x01, 0x08, 0x11, 0x00, 0x02, 0x02,\
8299
-/* 112 */ 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x02, 0x01,\
8300
-/* 120 */ 0x11, 0x00, 0x00, 0x05, 0x00, 0x11, 0x02, 0x05,\
8301
-/* 128 */ 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\
8302
-/* 136 */ 0x00, 0x00, 0x00, 0x04, 0x04, 0x04, 0x04, 0x04,\
8303
-}
8309
+/* 0 */ 0x00, 0x00, 0x0c, 0x00, 0x00, 0x02, 0x02, 0x11,\
8310
+/* 8 */ 0x11, 0x05, 0x00, 0x01, 0x00, 0x02, 0x02, 0x00,\
8311
+/* 16 */ 0x00, 0x04, 0x00, 0x04, 0x00, 0x00, 0x02, 0x00,\
8312
+/* 24 */ 0x01, 0x00, 0x00, 0x01, 0x00, 0x01, 0x11, 0x00,\
8313
+/* 32 */ 0x00, 0x00, 0x02, 0x08, 0x11, 0x02, 0x00, 0x00,\
8314
+/* 40 */ 0x05, 0x00, 0x00, 0x00, 0x04, 0x00, 0x01, 0x08,\
8315
+/* 48 */ 0x11, 0x05, 0x05, 0x01, 0x00, 0x04, 0x01, 0x02,\
8316
+/* 56 */ 0x00, 0x00, 0x00, 0x00, 0x02, 0x10, 0x00, 0x2c,\
8317
+/* 64 */ 0x2c, 0x00, 0x00, 0x00, 0x05, 0x05, 0x15, 0x15,\
8318
+/* 72 */ 0x15, 0x15, 0x15, 0x15, 0x04, 0x2c, 0x2c, 0x2c,\
8319
+/* 80 */ 0x2c, 0x2c, 0x2c, 0x2c, 0x2c, 0x2c, 0x2c, 0x00,\
8320
+/* 88 */ 0x00, 0x01, 0x04, 0x02, 0x00, 0x04, 0x04, 0x00,\
8321
+/* 96 */ 0x01, 0x00, 0x02, 0x00, 0x02, 0x11, 0x00, 0x00,\
8322
+/* 104 */ 0x05, 0x00, 0x00, 0x00, 0x02, 0x00, 0x02, 0x00,\
8323
+/* 112 */ 0x02, 0x00, 0x11, 0x00, 0x00, 0x00, 0x11, 0x01,\
8324
+/* 120 */ 0x00, 0x21, 0x08, 0x11, 0x00, 0x00, 0x01, 0x05,\
8325
+/* 128 */ 0x02, 0x02, 0x11, 0x02, 0x00, 0x00, 0x00, 0x00,\
8326
+/* 136 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x04, 0x04,\
8327
+/* 144 */ 0x04, 0x04,}
83048328
83058329
/************** End of opcodes.h *********************************************/
83068330
/************** Continuing where we left off in vdbe.h ***********************/
83078331
83088332
/*
@@ -8381,11 +8405,11 @@
83818405
*************************************************************************
83828406
** This header file defines the interface that the sqlite page cache
83838407
** subsystem. The page cache subsystem reads and writes a file a page
83848408
** at a time and provides a journal for rollback.
83858409
**
8386
-** @(#) $Id: pager.h,v 1.88 2008/12/10 16:45:51 drh Exp $
8410
+** @(#) $Id: pager.h,v 1.93 2009/01/07 15:18:21 danielk1977 Exp $
83878411
*/
83888412
83898413
#ifndef _PAGER_H_
83908414
#define _PAGER_H_
83918415
@@ -8456,19 +8480,15 @@
84568480
SQLITE_PRIVATE int sqlite3PagerPageRefcount(DbPage*);
84578481
SQLITE_PRIVATE int sqlite3PagerRef(DbPage*);
84588482
SQLITE_PRIVATE int sqlite3PagerUnref(DbPage*);
84598483
SQLITE_PRIVATE int sqlite3PagerWrite(DbPage*);
84608484
SQLITE_PRIVATE int sqlite3PagerPagecount(Pager*, int*);
8461
-SQLITE_PRIVATE int sqlite3PagerTruncate(Pager*,Pgno);
84628485
SQLITE_PRIVATE int sqlite3PagerBegin(DbPage*, int exFlag);
8463
-SQLITE_PRIVATE int sqlite3PagerCommitPhaseOne(Pager*,const char *zMaster, Pgno, int);
8486
+SQLITE_PRIVATE int sqlite3PagerCommitPhaseOne(Pager*,const char *zMaster, int);
84648487
SQLITE_PRIVATE int sqlite3PagerCommitPhaseTwo(Pager*);
84658488
SQLITE_PRIVATE int sqlite3PagerRollback(Pager*);
84668489
SQLITE_PRIVATE u8 sqlite3PagerIsreadonly(Pager*);
8467
-SQLITE_PRIVATE int sqlite3PagerStmtBegin(Pager*);
8468
-SQLITE_PRIVATE int sqlite3PagerStmtCommit(Pager*);
8469
-SQLITE_PRIVATE int sqlite3PagerStmtRollback(Pager*);
84708490
SQLITE_PRIVATE void sqlite3PagerDontRollback(DbPage*);
84718491
SQLITE_PRIVATE int sqlite3PagerDontWrite(DbPage*);
84728492
SQLITE_PRIVATE int sqlite3PagerRefcount(Pager*);
84738493
SQLITE_PRIVATE void sqlite3PagerSetSafetyLevel(Pager*,int,int);
84748494
SQLITE_PRIVATE const char *sqlite3PagerFilename(Pager*);
@@ -8483,10 +8503,18 @@
84838503
SQLITE_PRIVATE int sqlite3PagerLockingMode(Pager *, int);
84848504
SQLITE_PRIVATE int sqlite3PagerJournalMode(Pager *, int);
84858505
SQLITE_PRIVATE i64 sqlite3PagerJournalSizeLimit(Pager *, i64);
84868506
SQLITE_PRIVATE void *sqlite3PagerTempSpace(Pager*);
84878507
SQLITE_PRIVATE int sqlite3PagerSync(Pager *pPager);
8508
+
8509
+SQLITE_PRIVATE int sqlite3PagerOpenSavepoint(Pager *pPager, int n);
8510
+SQLITE_PRIVATE int sqlite3PagerSavepoint(Pager *pPager, int op, int iSavepoint);
8511
+
8512
+#ifndef SQLITE_OMIT_AUTOVACUUM
8513
+SQLITE_PRIVATE void sqlite3PagerTruncateImage(Pager*,Pgno);
8514
+SQLITE_PRIVATE Pgno sqlite3PagerImageSize(Pager *);
8515
+#endif
84888516
84898517
#ifdef SQLITE_HAS_CODEC
84908518
SQLITE_PRIVATE void sqlite3PagerSetCodec(Pager*,void*(*)(void*,void*,Pgno,int),void*);
84918519
#endif
84928520
@@ -9249,10 +9277,13 @@
92499277
int busyTimeout; /* Busy handler timeout, in msec */
92509278
Db aDbStatic[2]; /* Static space for the 2 default backends */
92519279
#ifdef SQLITE_SSE
92529280
sqlite3_stmt *pFetch; /* Used by SSE to fetch stored statements */
92539281
#endif
9282
+ Savepoint *pSavepoint; /* List of active savepoints */
9283
+ int nSavepoint; /* Number of non-transaction savepoints */
9284
+ u8 isTransactionSavepoint; /* True if the outermost savepoint is a TS */
92549285
};
92559286
92569287
/*
92579288
** A macro to discover the encoding of a database.
92589289
*/
@@ -9287,10 +9318,11 @@
92879318
#define SQLITE_LoadExtension 0x00020000 /* Enable load_extension */
92889319
92899320
#define SQLITE_RecoveryMode 0x00040000 /* Ignore schema errors */
92909321
#define SQLITE_SharedCache 0x00080000 /* Cache sharing is enabled */
92919322
#define SQLITE_Vtab 0x00100000 /* There exists a virtual table */
9323
+#define SQLITE_CommitBusy 0x00200000 /* In the process of committing */
92929324
92939325
/*
92949326
** Possible values for the sqlite.magic field.
92959327
** The numbers are obtained at random and have no special meaning, other
92969328
** than being distinct from one another.
@@ -9360,10 +9392,29 @@
93609392
#define LIKEFUNC(zName, nArg, arg, flags) \
93619393
{nArg, SQLITE_UTF8, flags, (void *)arg, 0, likeFunc, 0, 0, #zName, 0}
93629394
#define AGGREGATE(zName, nArg, arg, nc, xStep, xFinal) \
93639395
{nArg, SQLITE_UTF8, nc*8, SQLITE_INT_TO_PTR(arg), 0, 0, xStep,xFinal,#zName,0}
93649396
9397
+/*
9398
+** All current savepoints are stored in a linked list starting at
9399
+** sqlite3.pSavepoint. The first element in the list is the most recently
9400
+** opened savepoint. Savepoints are added to the list by the vdbe
9401
+** OP_Savepoint instruction.
9402
+*/
9403
+struct Savepoint {
9404
+ char *zName; /* Savepoint name (nul-terminated) */
9405
+ Savepoint *pNext; /* Parent savepoint (if any) */
9406
+};
9407
+
9408
+/*
9409
+** The following are used as the second parameter to sqlite3Savepoint(),
9410
+** and as the P1 argument to the OP_Savepoint instruction.
9411
+*/
9412
+#define SAVEPOINT_BEGIN 0
9413
+#define SAVEPOINT_RELEASE 1
9414
+#define SAVEPOINT_ROLLBACK 2
9415
+
93659416
93669417
/*
93679418
** Each SQLite module (virtual table definition) is defined by an
93689419
** instance of the following structure, stored in the sqlite3.aModule
93699420
** hash table.
@@ -9959,15 +10010,15 @@
995910010
char *zAlias; /* The "B" part of a "A AS B" phrase. zName is the "A" */
996010011
Table *pTab; /* An SQL table corresponding to zName */
996110012
Select *pSelect; /* A SELECT statement used in place of a table name */
996210013
u8 isPopulated; /* Temporary table associated with SELECT is populated */
996310014
u8 jointype; /* Type of join between this able and the previous */
10015
+ u8 notIndexed; /* True if there is a NOT INDEXED clause */
996410016
int iCursor; /* The VDBE cursor number used to access this table */
996510017
Expr *pOn; /* The ON clause of a join */
996610018
IdList *pUsing; /* The USING clause of a join */
9967
- Bitmask colUsed; /* Bit N (1<<N) set if column N or pTab is used */
9968
- u8 notIndexed; /* True if there is a NOT INDEXED clause */
10019
+ Bitmask colUsed; /* Bit N (1<<N) set if column N of pTab is used */
996910020
char *zIndex; /* Identifier from "INDEXED BY <zIndex>" clause */
997010021
Index *pIndex; /* Index structure corresponding to zIndex, if any */
997110022
} a[1]; /* One entry for each identifier on the list */
997210023
};
997310024
@@ -9980,65 +10031,92 @@
998010031
#define JT_LEFT 0x0008 /* Left outer join */
998110032
#define JT_RIGHT 0x0010 /* Right outer join */
998210033
#define JT_OUTER 0x0020 /* The "OUTER" keyword is present */
998310034
#define JT_ERROR 0x0040 /* unknown or unsupported join type */
998410035
10036
+
10037
+/*
10038
+** A WherePlan object holds information that describes a lookup
10039
+** strategy.
10040
+**
10041
+** This object is intended to be opaque outside of the where.c module.
10042
+** It is included here only so that that compiler will know how big it
10043
+** is. None of the fields in this object should be used outside of
10044
+** the where.c module.
10045
+**
10046
+** Within the union, pIdx is only used when wsFlags&WHERE_INDEXED is true.
10047
+** pTerm is only used when wsFlags&WHERE_MULTI_OR is true. And pVtabIdx
10048
+** is only used when wsFlags&WHERE_VIRTUALTABLE is true. It is never the
10049
+** case that more than one of these conditions is true.
10050
+*/
10051
+struct WherePlan {
10052
+ u32 wsFlags; /* WHERE_* flags that describe the strategy */
10053
+ u32 nEq; /* Number of == constraints */
10054
+ union {
10055
+ Index *pIdx; /* Index when WHERE_INDEXED is true */
10056
+ struct WhereTerm *pTerm; /* WHERE clause term for OR-search */
10057
+ sqlite3_index_info *pVtabIdx; /* Virtual table index to use */
10058
+ } u;
10059
+};
10060
+
998510061
/*
998610062
** For each nested loop in a WHERE clause implementation, the WhereInfo
998710063
** structure contains a single instance of this structure. This structure
998810064
** is intended to be private the the where.c module and should not be
998910065
** access or modified by other modules.
999010066
**
9991
-** The pIdxInfo and pBestIdx fields are used to help pick the best
9992
-** index on a virtual table. The pIdxInfo pointer contains indexing
10067
+** The pIdxInfo field is used to help pick the best index on a
10068
+** virtual table. The pIdxInfo pointer contains indexing
999310069
** information for the i-th table in the FROM clause before reordering.
999410070
** All the pIdxInfo pointers are freed by whereInfoFree() in where.c.
9995
-** The pBestIdx pointer is a copy of pIdxInfo for the i-th table after
9996
-** FROM clause ordering. This is a little confusing so I will repeat
9997
-** it in different words. WhereInfo.a[i].pIdxInfo is index information
9998
-** for WhereInfo.pTabList.a[i]. WhereInfo.a[i].pBestInfo is the
9999
-** index information for the i-th loop of the join. pBestInfo is always
10000
-** either NULL or a copy of some pIdxInfo. So for cleanup it is
10001
-** sufficient to free all of the pIdxInfo pointers.
10002
-**
10071
+** All other information in the i-th WhereLevel object for the i-th table
10072
+** after FROM clause ordering.
1000310073
*/
1000410074
struct WhereLevel {
10005
- int iFrom; /* Which entry in the FROM clause */
10006
- int wsFlags; /* "Where-Scan" flags show the choosen scan strategy */
10007
- int iMem; /* First memory cell used by this level */
10075
+ WherePlan plan; /* query plan for this element of the FROM clause */
1000810076
int iLeftJoin; /* Memory cell used to implement LEFT OUTER JOIN */
10009
- Index *pIdx; /* Index used. NULL if no index */
1001010077
int iTabCur; /* The VDBE cursor used to access the table */
1001110078
int iIdxCur; /* The VDBE cursor used to access pIdx */
1001210079
int addrBrk; /* Jump here to break out of the loop */
1001310080
int addrNxt; /* Jump here to start the next IN combination */
1001410081
int addrCont; /* Jump here to continue with the next loop cycle */
1001510082
int addrFirst; /* First instruction of interior of the loop */
10016
- int op, p1, p2; /* Opcode used to terminate the loop */
10017
- u8 p5; /* P5 operand of the opcode that terminates the loop */
10018
- int nEq; /* Number of == or IN constraints on this loop */
10019
- int nIn; /* Number of IN operators constraining this loop */
10020
- struct InLoop {
10021
- int iCur; /* The VDBE cursor used by this IN operator */
10022
- int addrInTop; /* Top of the IN loop */
10023
- } *aInLoop; /* Information about each nested IN operator */
10024
- sqlite3_index_info *pBestIdx; /* Index information for this level */
10083
+ u8 iFrom; /* Which entry in the FROM clause */
10084
+ u8 op, p5; /* Opcode and P5 of the opcode that ends the loop */
10085
+ int p1, p2; /* Operands of the opcode used to ends the loop */
10086
+ union { /* Information that depends on plan.wsFlags */
10087
+ struct {
10088
+ int nIn; /* Number of entries in aInLoop[] */
10089
+ struct InLoop {
10090
+ int iCur; /* The VDBE cursor used by this IN operator */
10091
+ int addrInTop; /* Top of the IN loop */
10092
+ } *aInLoop; /* Information about each nested IN operator */
10093
+ } in; /* Used when plan.wsFlags&WHERE_IN_ABLE */
10094
+ struct {
10095
+ WherePlan *aPlan; /* Plans for each term of the WHERE clause */
10096
+ } or; /* Used when plan.wsFlags&WHERE_MULTI_OR */
10097
+ } u;
1002510098
1002610099
/* The following field is really not part of the current level. But
10027
- ** we need a place to cache index information for each table in the
10028
- ** FROM clause and the WhereLevel structure is a convenient place.
10100
+ ** we need a place to cache virtual table index information for each
10101
+ ** virtual table in the FROM clause and the WhereLevel structure is
10102
+ ** a convenient place since there is one WhereLevel for each FROM clause
10103
+ ** element.
1002910104
*/
1003010105
sqlite3_index_info *pIdxInfo; /* Index info for n-th source table */
1003110106
};
1003210107
1003310108
/*
1003410109
** Flags appropriate for the wctrlFlags parameter of sqlite3WhereBegin().
1003510110
*/
10036
-#define WHERE_ORDERBY_NORMAL 0 /* No-op */
10037
-#define WHERE_ORDERBY_MIN 1 /* ORDER BY processing for min() func */
10038
-#define WHERE_ORDERBY_MAX 2 /* ORDER BY processing for max() func */
10039
-#define WHERE_ONEPASS_DESIRED 4 /* Want to do one-pass UPDATE/DELETE */
10111
+#define WHERE_ORDERBY_NORMAL 0x0000 /* No-op */
10112
+#define WHERE_ORDERBY_MIN 0x0001 /* ORDER BY processing for min() func */
10113
+#define WHERE_ORDERBY_MAX 0x0002 /* ORDER BY processing for max() func */
10114
+#define WHERE_ONEPASS_DESIRED 0x0004 /* Want to do one-pass UPDATE/DELETE */
10115
+#define WHERE_FILL_ROWSET 0x0008 /* Save results in a RowSet object */
10116
+#define WHERE_OMIT_OPEN 0x0010 /* Table cursor are already open */
10117
+#define WHERE_OMIT_CLOSE 0x0020 /* Omit close of table & index cursors */
1004010118
1004110119
/*
1004210120
** The WHERE clause processing routine has two halves. The
1004310121
** first part does the start of the WHERE loop and the second
1004410122
** half does the tail of the WHERE loop. An instance of
@@ -10045,18 +10123,20 @@
1004510123
** this structure is returned by the first half and passed
1004610124
** into the second half to give some continuity.
1004710125
*/
1004810126
struct WhereInfo {
1004910127
Parse *pParse; /* Parsing and code generating context */
10128
+ u16 wctrlFlags; /* Flags originally passed to sqlite3WhereBegin() */
1005010129
u8 okOnePass; /* Ok to use one-pass algorithm for UPDATE or DELETE */
10051
- SrcList *pTabList; /* List of tables in the join */
10052
- int iTop; /* The very beginning of the WHERE loop */
10053
- int iContinue; /* Jump here to continue with next record */
10054
- int iBreak; /* Jump here to break out of the loop */
10055
- int nLevel; /* Number of nested loop */
10056
- sqlite3_index_info **apInfo; /* Array of pointers to index info structures */
10057
- WhereLevel a[1]; /* Information about each nest loop in the WHERE */
10130
+ int regRowSet; /* Store rowids in this rowset if >=0 */
10131
+ SrcList *pTabList; /* List of tables in the join */
10132
+ int iTop; /* The very beginning of the WHERE loop */
10133
+ int iContinue; /* Jump here to continue with next record */
10134
+ int iBreak; /* Jump here to break out of the loop */
10135
+ int nLevel; /* Number of nested loop */
10136
+ struct WhereClause *pWC; /* Decomposition of the WHERE clause */
10137
+ WhereLevel a[1]; /* Information about each nest loop in WHERE */
1005810138
};
1005910139
1006010140
/*
1006110141
** A NameContext defines a context in which to resolve table and column
1006210142
** names. The context consists of a list of tables (the pSrcList) field and
@@ -10695,11 +10775,11 @@
1069510775
#if defined(SQLITE_ENABLE_UPDATE_DELETE_LIMIT) && !defined(SQLITE_OMIT_SUBQUERY)
1069610776
SQLITE_PRIVATE Expr *sqlite3LimitWhere(Parse *, SrcList *, Expr *, ExprList *, Expr *, Expr *, char *);
1069710777
#endif
1069810778
SQLITE_PRIVATE void sqlite3DeleteFrom(Parse*, SrcList*, Expr*);
1069910779
SQLITE_PRIVATE void sqlite3Update(Parse*, SrcList*, ExprList*, Expr*, int);
10700
-SQLITE_PRIVATE WhereInfo *sqlite3WhereBegin(Parse*, SrcList*, Expr*, ExprList**, u8);
10780
+SQLITE_PRIVATE WhereInfo *sqlite3WhereBegin(Parse*, SrcList*, Expr*, ExprList**, u8, int);
1070110781
SQLITE_PRIVATE void sqlite3WhereEnd(WhereInfo*);
1070210782
SQLITE_PRIVATE int sqlite3ExprCodeGetColumn(Parse*, Table*, int, int, int, int);
1070310783
SQLITE_PRIVATE void sqlite3ExprCodeMove(Parse*, int, int, int);
1070410784
SQLITE_PRIVATE void sqlite3ExprCodeCopy(Parse*, int, int, int);
1070510785
SQLITE_PRIVATE void sqlite3ExprClearColumnCache(Parse*, int);
@@ -10733,10 +10813,12 @@
1073310813
SQLITE_PRIVATE void sqlite3RollbackAll(sqlite3*);
1073410814
SQLITE_PRIVATE void sqlite3CodeVerifySchema(Parse*, int);
1073510815
SQLITE_PRIVATE void sqlite3BeginTransaction(Parse*, int);
1073610816
SQLITE_PRIVATE void sqlite3CommitTransaction(Parse*);
1073710817
SQLITE_PRIVATE void sqlite3RollbackTransaction(Parse*);
10818
+SQLITE_PRIVATE void sqlite3Savepoint(Parse*, int, Token*);
10819
+SQLITE_PRIVATE void sqlite3CloseSavepoints(sqlite3 *);
1073810820
SQLITE_PRIVATE int sqlite3ExprIsConstant(Expr*);
1073910821
SQLITE_PRIVATE int sqlite3ExprIsConstantNotJoin(Expr*);
1074010822
SQLITE_PRIVATE int sqlite3ExprIsConstantOrFunction(Expr*);
1074110823
SQLITE_PRIVATE int sqlite3ExprIsInteger(Expr*, int*);
1074210824
SQLITE_PRIVATE int sqlite3IsRowid(const char*);
@@ -11031,11 +11113,11 @@
1103111113
#else
1103211114
#define sqlite3JournalSize(pVfs) ((pVfs)->szOsFile)
1103311115
#endif
1103411116
1103511117
SQLITE_PRIVATE void sqlite3MemJournalOpen(sqlite3_file *);
11036
-SQLITE_PRIVATE int sqlite3MemJournalSize();
11118
+SQLITE_PRIVATE int sqlite3MemJournalSize(void);
1103711119
SQLITE_PRIVATE int sqlite3IsMemJournal(sqlite3_file *);
1103811120
1103911121
#if SQLITE_MAX_EXPR_DEPTH>0
1104011122
SQLITE_PRIVATE void sqlite3ExprSetHeight(Parse *pParse, Expr *p);
1104111123
SQLITE_PRIVATE int sqlite3SelectExprHeight(Select *);
@@ -11321,11 +11403,11 @@
1132111403
**
1132211404
** There is only one exported symbol in this file - the function
1132311405
** sqlite3RegisterDateTimeFunctions() found at the bottom of the file.
1132411406
** All other code has file scope.
1132511407
**
11326
-** $Id: date.c,v 1.98 2008/12/10 22:30:25 shane Exp $
11408
+** $Id: date.c,v 1.99 2008/12/20 13:18:50 drh Exp $
1132711409
**
1132811410
** SQLite processes all times and dates as Julian Day numbers. The
1132911411
** dates and times are stored as the number of days since noon
1133011412
** in Greenwich on November 24, 4714 B.C. according to the Gregorian
1133111413
** calendar system.
@@ -11750,11 +11832,11 @@
1175011832
x.s = s;
1175111833
}
1175211834
x.tz = 0;
1175311835
x.validJD = 0;
1175411836
computeJD(&x);
11755
- t = x.iJD/1000 - 210866760000LL;
11837
+ t = x.iJD/1000 - 21086676*(i64)10000;
1175611838
#ifdef HAVE_LOCALTIME_R
1175711839
{
1175811840
struct tm sLocal;
1175911841
localtime_r(&t, &sLocal);
1176011842
y.Y = sLocal.tm_year + 1900;
@@ -11852,11 +11934,11 @@
1185211934
**
1185311935
** Treat the current value of p->iJD as the number of
1185411936
** seconds since 1970. Convert to a real julian day number.
1185511937
*/
1185611938
if( strcmp(z, "unixepoch")==0 && p->validJD ){
11857
- p->iJD = p->iJD/86400 + 210866760000000LL;
11939
+ p->iJD = p->iJD/86400 + 21086676*(i64)10000000;
1185811940
clearYMD_HMS_TZ(p);
1185911941
rc = 0;
1186011942
}
1186111943
#ifndef SQLITE_OMIT_LOCALTIME
1186211944
else if( strcmp(z, "utc")==0 ){
@@ -17728,11 +17810,11 @@
1772817810
** VDBE. This information used to all be at the top of the single
1772917811
** source code file "vdbe.c". When that file became too big (over
1773017812
** 6000 lines long) it was split up into several smaller files and
1773117813
** this header information was factored out.
1773217814
**
17733
-** $Id: vdbeInt.h,v 1.160 2008/12/09 02:51:24 drh Exp $
17815
+** $Id: vdbeInt.h,v 1.161 2009/01/05 18:02:27 drh Exp $
1773417816
*/
1773517817
#ifndef _VDBEINT_H_
1773617818
#define _VDBEINT_H_
1773717819
1773817820
/*
@@ -17886,11 +17968,12 @@
1788617968
1788717969
1788817970
/*
1788917971
** Clear any existing type flags from a Mem and replace them with f
1789017972
*/
17891
-#define MemSetTypeFlag(p, f) ((p)->flags = ((p)->flags&~(MEM_TypeMask))|f)
17973
+#define MemSetTypeFlag(p, f) \
17974
+ ((p)->flags = ((p)->flags&~(MEM_TypeMask|MEM_Zero))|f)
1789217975
1789317976
1789417977
/* A VdbeFunc is just a FuncDef (defined in sqliteInt.h) that contains
1789517978
** additional information about auxiliary information bound to arguments
1789617979
** of the function. This is used to implement the sqlite3_get_auxdata()
@@ -19589,11 +19672,11 @@
1958919672
**
1959019673
*************************************************************************
1959119674
** This is the implementation of generic hash-tables
1959219675
** used in SQLite.
1959319676
**
19594
-** $Id: hash.c,v 1.32 2008/12/10 19:26:24 drh Exp $
19677
+** $Id: hash.c,v 1.33 2009/01/09 01:12:28 drh Exp $
1959519678
*/
1959619679
1959719680
/* Turn bulk memory into a hash table object by initializing the
1959819681
** fields of the Hash structure.
1959919682
**
@@ -19623,11 +19706,11 @@
1962319706
sqlite3_free(pH->ht);
1962419707
pH->ht = 0;
1962519708
pH->htsize = 0;
1962619709
while( elem ){
1962719710
HashElem *next_elem = elem->next;
19628
- if( pH->copyKey && elem->pKey ){
19711
+ if( pH->copyKey ){
1962919712
sqlite3_free(elem->pKey);
1963019713
}
1963119714
sqlite3_free(elem);
1963219715
elem = next_elem;
1963319716
}
@@ -19884,153 +19967,155 @@
1988419967
/* Automatically generated. Do not edit */
1988519968
/* See the mkopcodec.awk script for details. */
1988619969
#if !defined(SQLITE_OMIT_EXPLAIN) || !defined(NDEBUG) || defined(VDBE_PROFILE) || defined(SQLITE_DEBUG)
1988719970
SQLITE_PRIVATE const char *sqlite3OpcodeName(int i){
1988819971
static const char *const azName[] = { "?",
19889
- /* 1 */ "VNext",
19890
- /* 2 */ "Affinity",
19891
- /* 3 */ "Column",
19892
- /* 4 */ "SetCookie",
19893
- /* 5 */ "Seek",
19894
- /* 6 */ "Sequence",
19895
- /* 7 */ "RowKey",
19896
- /* 8 */ "SCopy",
19897
- /* 9 */ "OpenWrite",
19898
- /* 10 */ "If",
19899
- /* 11 */ "VRowid",
19900
- /* 12 */ "CollSeq",
19901
- /* 13 */ "OpenRead",
19902
- /* 14 */ "Expire",
19903
- /* 15 */ "AutoCommit",
19904
- /* 16 */ "Not",
19905
- /* 17 */ "Pagecount",
19906
- /* 18 */ "IntegrityCk",
19907
- /* 19 */ "Sort",
19908
- /* 20 */ "Copy",
19972
+ /* 1 */ "VCreate",
19973
+ /* 2 */ "MemMax",
19974
+ /* 3 */ "LoadAnalysis",
19975
+ /* 4 */ "RowData",
19976
+ /* 5 */ "CreateIndex",
19977
+ /* 6 */ "Variable",
19978
+ /* 7 */ "SeekGt",
19979
+ /* 8 */ "SeekLe",
19980
+ /* 9 */ "IfNeg",
19981
+ /* 10 */ "Clear",
19982
+ /* 11 */ "Last",
19983
+ /* 12 */ "Savepoint",
19984
+ /* 13 */ "Sequence",
19985
+ /* 14 */ "Int64",
19986
+ /* 15 */ "VBegin",
19987
+ /* 16 */ "RowKey",
19988
+ /* 17 */ "SCopy",
19989
+ /* 18 */ "ResetCount",
19990
+ /* 19 */ "Not",
19991
+ /* 20 */ "Delete",
1990919992
/* 21 */ "Trace",
19910
- /* 22 */ "Function",
19911
- /* 23 */ "IfNeg",
19912
- /* 24 */ "Noop",
19913
- /* 25 */ "Return",
19914
- /* 26 */ "NewRowid",
19915
- /* 27 */ "Variable",
19916
- /* 28 */ "String",
19917
- /* 29 */ "RealAffinity",
19918
- /* 30 */ "VRename",
19919
- /* 31 */ "ParseSchema",
19920
- /* 32 */ "VOpen",
19921
- /* 33 */ "Close",
19922
- /* 34 */ "CreateIndex",
19923
- /* 35 */ "IsUnique",
19924
- /* 36 */ "NotFound",
19925
- /* 37 */ "Int64",
19926
- /* 38 */ "MustBeInt",
19927
- /* 39 */ "Halt",
19928
- /* 40 */ "Rowid",
19929
- /* 41 */ "IdxLT",
19930
- /* 42 */ "AddImm",
19931
- /* 43 */ "Statement",
19932
- /* 44 */ "RowData",
19933
- /* 45 */ "MemMax",
19934
- /* 46 */ "NotExists",
19935
- /* 47 */ "Gosub",
19936
- /* 48 */ "Integer",
19937
- /* 49 */ "Prev",
19938
- /* 50 */ "RowSetRead",
19939
- /* 51 */ "RowSetAdd",
19940
- /* 52 */ "VColumn",
19941
- /* 53 */ "CreateTable",
19942
- /* 54 */ "Last",
19943
- /* 55 */ "SeekLe",
19944
- /* 56 */ "IncrVacuum",
19945
- /* 57 */ "IdxRowid",
19946
- /* 58 */ "ResetCount",
19947
- /* 59 */ "ContextPush",
19948
- /* 60 */ "Or",
19949
- /* 61 */ "And",
19950
- /* 62 */ "Yield",
19951
- /* 63 */ "DropTrigger",
19952
- /* 64 */ "DropIndex",
19953
- /* 65 */ "IsNull",
19954
- /* 66 */ "NotNull",
19955
- /* 67 */ "Ne",
19956
- /* 68 */ "Eq",
19957
- /* 69 */ "Gt",
19958
- /* 70 */ "Le",
19959
- /* 71 */ "Lt",
19960
- /* 72 */ "Ge",
19961
- /* 73 */ "IdxGE",
19962
- /* 74 */ "BitAnd",
19963
- /* 75 */ "BitOr",
19964
- /* 76 */ "ShiftLeft",
19965
- /* 77 */ "ShiftRight",
19966
- /* 78 */ "Add",
19967
- /* 79 */ "Subtract",
19968
- /* 80 */ "Multiply",
19969
- /* 81 */ "Divide",
19970
- /* 82 */ "Remainder",
19971
- /* 83 */ "Concat",
19972
- /* 84 */ "IdxDelete",
19973
- /* 85 */ "Vacuum",
19974
- /* 86 */ "IfNot",
19975
- /* 87 */ "BitNot",
19976
- /* 88 */ "String8",
19977
- /* 89 */ "DropTable",
19978
- /* 90 */ "SeekLt",
19979
- /* 91 */ "MakeRecord",
19980
- /* 92 */ "ResultRow",
19981
- /* 93 */ "Delete",
19982
- /* 94 */ "AggFinal",
19983
- /* 95 */ "Compare",
19984
- /* 96 */ "Goto",
19985
- /* 97 */ "TableLock",
19986
- /* 98 */ "Clear",
19987
- /* 99 */ "VerifyCookie",
19988
- /* 100 */ "AggStep",
19989
- /* 101 */ "SetNumColumns",
19990
- /* 102 */ "Transaction",
19991
- /* 103 */ "VFilter",
19992
- /* 104 */ "VDestroy",
19993
- /* 105 */ "ContextPop",
19994
- /* 106 */ "Next",
19995
- /* 107 */ "IdxInsert",
19996
- /* 108 */ "SeekGe",
19997
- /* 109 */ "Insert",
19998
- /* 110 */ "Destroy",
19999
- /* 111 */ "ReadCookie",
20000
- /* 112 */ "LoadAnalysis",
20001
- /* 113 */ "Explain",
20002
- /* 114 */ "OpenPseudo",
20003
- /* 115 */ "OpenEphemeral",
20004
- /* 116 */ "Null",
20005
- /* 117 */ "Move",
20006
- /* 118 */ "Blob",
20007
- /* 119 */ "Rewind",
20008
- /* 120 */ "SeekGt",
20009
- /* 121 */ "VBegin",
20010
- /* 122 */ "VUpdate",
20011
- /* 123 */ "IfZero",
20012
- /* 124 */ "VCreate",
20013
- /* 125 */ "Found",
20014
- /* 126 */ "Real",
19993
+ /* 22 */ "Rowid",
19994
+ /* 23 */ "OpenRead",
19995
+ /* 24 */ "Sort",
19996
+ /* 25 */ "VerifyCookie",
19997
+ /* 26 */ "VColumn",
19998
+ /* 27 */ "Next",
19999
+ /* 28 */ "Insert",
20000
+ /* 29 */ "Prev",
20001
+ /* 30 */ "IdxGE",
20002
+ /* 31 */ "VRename",
20003
+ /* 32 */ "DropTable",
20004
+ /* 33 */ "MakeRecord",
20005
+ /* 34 */ "Null",
20006
+ /* 35 */ "IdxInsert",
20007
+ /* 36 */ "SeekLt",
20008
+ /* 37 */ "ReadCookie",
20009
+ /* 38 */ "VDestroy",
20010
+ /* 39 */ "DropIndex",
20011
+ /* 40 */ "MustBeInt",
20012
+ /* 41 */ "IntegrityCk",
20013
+ /* 42 */ "CollSeq",
20014
+ /* 43 */ "ResultRow",
20015
+ /* 44 */ "Yield",
20016
+ /* 45 */ "OpenEphemeral",
20017
+ /* 46 */ "VNext",
20018
+ /* 47 */ "Seek",
20019
+ /* 48 */ "Found",
20020
+ /* 49 */ "If",
20021
+ /* 50 */ "IfZero",
20022
+ /* 51 */ "Goto",
20023
+ /* 52 */ "Function",
20024
+ /* 53 */ "Copy",
20025
+ /* 54 */ "Jump",
20026
+ /* 55 */ "Blob",
20027
+ /* 56 */ "NullRow",
20028
+ /* 57 */ "Transaction",
20029
+ /* 58 */ "VUpdate",
20030
+ /* 59 */ "TableLock",
20031
+ /* 60 */ "IdxRowid",
20032
+ /* 61 */ "SetCookie",
20033
+ /* 62 */ "ContextPush",
20034
+ /* 63 */ "Or",
20035
+ /* 64 */ "And",
20036
+ /* 65 */ "DropTrigger",
20037
+ /* 66 */ "AutoCommit",
20038
+ /* 67 */ "Column",
20039
+ /* 68 */ "IsNull",
20040
+ /* 69 */ "NotNull",
20041
+ /* 70 */ "Ne",
20042
+ /* 71 */ "Eq",
20043
+ /* 72 */ "Gt",
20044
+ /* 73 */ "Le",
20045
+ /* 74 */ "Lt",
20046
+ /* 75 */ "Ge",
20047
+ /* 76 */ "AddImm",
20048
+ /* 77 */ "BitAnd",
20049
+ /* 78 */ "BitOr",
20050
+ /* 79 */ "ShiftLeft",
20051
+ /* 80 */ "ShiftRight",
20052
+ /* 81 */ "Add",
20053
+ /* 82 */ "Subtract",
20054
+ /* 83 */ "Multiply",
20055
+ /* 84 */ "Divide",
20056
+ /* 85 */ "Remainder",
20057
+ /* 86 */ "Concat",
20058
+ /* 87 */ "ContextPop",
20059
+ /* 88 */ "IdxDelete",
20060
+ /* 89 */ "IncrVacuum",
20061
+ /* 90 */ "BitNot",
20062
+ /* 91 */ "String8",
20063
+ /* 92 */ "AggFinal",
20064
+ /* 93 */ "RealAffinity",
20065
+ /* 94 */ "Return",
20066
+ /* 95 */ "Expire",
20067
+ /* 96 */ "Rewind",
20068
+ /* 97 */ "Statement",
20069
+ /* 98 */ "Integer",
20070
+ /* 99 */ "Compare",
20071
+ /* 100 */ "Destroy",
20072
+ /* 101 */ "IdxLT",
20073
+ /* 102 */ "Affinity",
20074
+ /* 103 */ "Vacuum",
20075
+ /* 104 */ "IfNot",
20076
+ /* 105 */ "Move",
20077
+ /* 106 */ "Explain",
20078
+ /* 107 */ "ParseSchema",
20079
+ /* 108 */ "NewRowid",
20080
+ /* 109 */ "SetNumColumns",
20081
+ /* 110 */ "String",
20082
+ /* 111 */ "AggStep",
20083
+ /* 112 */ "VRowid",
20084
+ /* 113 */ "VOpen",
20085
+ /* 114 */ "NotExists",
20086
+ /* 115 */ "Close",
20087
+ /* 116 */ "Halt",
20088
+ /* 117 */ "Noop",
20089
+ /* 118 */ "SeekGe",
20090
+ /* 119 */ "VFilter",
20091
+ /* 120 */ "OpenPseudo",
20092
+ /* 121 */ "RowSetRead",
20093
+ /* 122 */ "RowSetAdd",
20094
+ /* 123 */ "IsUnique",
20095
+ /* 124 */ "OpenWrite",
20096
+ /* 125 */ "Permutation",
20097
+ /* 126 */ "Gosub",
2001520098
/* 127 */ "IfPos",
20016
- /* 128 */ "NullRow",
20017
- /* 129 */ "Jump",
20018
- /* 130 */ "Permutation",
20019
- /* 131 */ "NotUsed_131",
20099
+ /* 128 */ "Pagecount",
20100
+ /* 129 */ "Real",
20101
+ /* 130 */ "NotFound",
20102
+ /* 131 */ "CreateTable",
2002020103
/* 132 */ "NotUsed_132",
2002120104
/* 133 */ "NotUsed_133",
2002220105
/* 134 */ "NotUsed_134",
2002320106
/* 135 */ "NotUsed_135",
2002420107
/* 136 */ "NotUsed_136",
2002520108
/* 137 */ "NotUsed_137",
2002620109
/* 138 */ "NotUsed_138",
20027
- /* 139 */ "ToText",
20028
- /* 140 */ "ToBlob",
20029
- /* 141 */ "ToNumeric",
20030
- /* 142 */ "ToInt",
20031
- /* 143 */ "ToReal",
20110
+ /* 139 */ "NotUsed_139",
20111
+ /* 140 */ "NotUsed_140",
20112
+ /* 141 */ "ToText",
20113
+ /* 142 */ "ToBlob",
20114
+ /* 143 */ "ToNumeric",
20115
+ /* 144 */ "ToInt",
20116
+ /* 145 */ "ToReal",
2003220117
};
2003320118
return azName[i];
2003420119
}
2003520120
#endif
2003620121
@@ -21440,11 +21525,11 @@
2144021525
** * sqlite3_vfs method implementations.
2144121526
** * Locking primitives for the proxy uber-locking-method. (MacOSX only)
2144221527
** * Definitions of sqlite3_vfs objects for all locking methods
2144321528
** plus implementations of sqlite3_os_init() and sqlite3_os_end().
2144421529
**
21445
-** $Id: os_unix.c,v 1.232 2008/12/11 02:56:07 drh Exp $
21530
+** $Id: os_unix.c,v 1.235 2009/01/09 21:41:17 drh Exp $
2144621531
*/
2144721532
#if SQLITE_OS_UNIX /* This file is used on unix only */
2144821533
2144921534
/*
2145021535
** There are various methods for file locking used for concurrency
@@ -21462,11 +21547,11 @@
2146221547
** is defined to 1. The SQLITE_ENABLE_LOCKING_STYLE also enables automatic
2146321548
** selection of the appropriate locking style based on the filesystem
2146421549
** where the database is located.
2146521550
*/
2146621551
#if !defined(SQLITE_ENABLE_LOCKING_STYLE)
21467
-# if defined(__DARWIN__)
21552
+# if defined(__APPLE__)
2146821553
# define SQLITE_ENABLE_LOCKING_STYLE 1
2146921554
# else
2147021555
# define SQLITE_ENABLE_LOCKING_STYLE 0
2147121556
# endif
2147221557
#endif
@@ -23800,11 +23885,11 @@
2380023885
**
2380123886
** Third-party implementations of AFP are available. But this code here
2380223887
** only works on OSX.
2380323888
*/
2380423889
23805
-#if defined(__DARWIN__) && SQLITE_ENABLE_LOCKING_STYLE
23890
+#if defined(__APPLE__) && SQLITE_ENABLE_LOCKING_STYLE
2380623891
/*
2380723892
** The afpLockingContext structure contains all afp lock specific state
2380823893
*/
2380923894
typedef struct afpLockingContext afpLockingContext;
2381023895
struct afpLockingContext {
@@ -24183,11 +24268,11 @@
2418324268
unixLeaveMutex();
2418424269
}
2418524270
return SQLITE_OK;
2418624271
}
2418724272
24188
-#endif /* defined(__DARWIN__) && SQLITE_ENABLE_LOCKING_STYLE */
24273
+#endif /* defined(__APPLE__) && SQLITE_ENABLE_LOCKING_STYLE */
2418924274
/*
2419024275
** The code above is the AFP lock implementation. The code is specific
2419124276
** to MacOSX and does not work on other unix platforms. No alternative
2419224277
** is available. If you don't compile for a mac, then the "unix-afp"
2419324278
** VFS is not available.
@@ -24562,11 +24647,11 @@
2456224647
2456324648
2456424649
return SQLITE_OK;
2456524650
}
2456624651
24567
-#if SQLITE_ENABLE_LOCKING_STYLE && defined(__DARWIN__)
24652
+#if SQLITE_ENABLE_LOCKING_STYLE && defined(__APPLE__)
2456824653
/*
2456924654
** Handler for proxy-locking file-control verbs. Defined below in the
2457024655
** proxying locking division.
2457124656
*/
2457224657
static int proxyFileControl(sqlite3_file*,int,void*);
@@ -24584,16 +24669,16 @@
2458424669
}
2458524670
case SQLITE_LAST_ERRNO: {
2458624671
*(int*)pArg = ((unixFile*)id)->lastErrno;
2458724672
return SQLITE_OK;
2458824673
}
24589
-#if SQLITE_ENABLE_LOCKING_STYLE && defined(__DARWIN__)
24674
+#if SQLITE_ENABLE_LOCKING_STYLE && defined(__APPLE__)
2459024675
case SQLITE_SET_LOCKPROXYFILE:
2459124676
case SQLITE_GET_LOCKPROXYFILE: {
2459224677
return proxyFileControl(id,op,pArg);
2459324678
}
24594
-#endif /* SQLITE_ENABLE_LOCKING_STYLE && defined(__DARWIN__) */
24679
+#endif /* SQLITE_ENABLE_LOCKING_STYLE && defined(__APPLE__) */
2459524680
}
2459624681
return SQLITE_ERROR;
2459724682
}
2459824683
2459924684
/*
@@ -24732,11 +24817,11 @@
2473224817
semUnlock, /* xUnlock method */
2473324818
semCheckReservedLock /* xCheckReservedLock method */
2473424819
)
2473524820
#endif
2473624821
24737
-#if defined(__DARWIN__) && SQLITE_ENABLE_LOCKING_STYLE
24822
+#if defined(__APPLE__) && SQLITE_ENABLE_LOCKING_STYLE
2473824823
IOMETHODS(
2473924824
afpIoFinder, /* Finder function name */
2474024825
afpIoMethods, /* sqlite3_io_methods object name */
2474124826
afpClose, /* xClose method */
2474224827
afpLock, /* xLock method */
@@ -24752,11 +24837,11 @@
2475224837
** secondary files. For this reason, the division that implements
2475324838
** proxy locking is located much further down in the file. But we need
2475424839
** to go ahead and define the sqlite3_io_methods and finder function
2475524840
** for proxy locking here. So we forward declare the I/O methods.
2475624841
*/
24757
-#if defined(__DARWIN__) && SQLITE_ENABLE_LOCKING_STYLE
24842
+#if defined(__APPLE__) && SQLITE_ENABLE_LOCKING_STYLE
2475824843
static int proxyClose(sqlite3_file*);
2475924844
static int proxyLock(sqlite3_file*, int);
2476024845
static int proxyUnlock(sqlite3_file*, int);
2476124846
static int proxyCheckReservedLock(sqlite3_file*, int*);
2476224847
IOMETHODS(
@@ -24768,11 +24853,11 @@
2476824853
proxyCheckReservedLock /* xCheckReservedLock method */
2476924854
)
2477024855
#endif
2477124856
2477224857
24773
-#if defined(__DARWIN__) && SQLITE_ENABLE_LOCKING_STYLE
24858
+#if defined(__APPLE__) && SQLITE_ENABLE_LOCKING_STYLE
2477424859
/*
2477524860
** This "finder" function attempts to determine the best locking strategy
2477624861
** for the database file "filePath". It then returns the sqlite3_io_methods
2477724862
** object that implements that strategy.
2477824863
**
@@ -24829,14 +24914,14 @@
2482924914
return &posixIoMethods;
2483024915
}else{
2483124916
return &dotlockIoMethods;
2483224917
}
2483324918
}
24834
-static const sqlite3_io_methods (*const autolockIoFinder)(const char*,int)
24919
+static const sqlite3_io_methods *(*const autolockIoFinder)(const char*,int)
2483524920
= autolockIoFinderImpl;
2483624921
24837
-#endif /* defined(__DARWIN__) && SQLITE_ENABLE_LOCKING_STYLE */
24922
+#endif /* defined(__APPLE__) && SQLITE_ENABLE_LOCKING_STYLE */
2483824923
2483924924
/*
2484024925
** An abstract type for a pointer to a IO method finder function:
2484124926
*/
2484224927
typedef const sqlite3_io_methods *(*finder_type)(const char*,int);
@@ -24905,11 +24990,11 @@
2490524990
unixEnterMutex();
2490624991
rc = findLockInfo(pNew, &pNew->pLock, &pNew->pOpen);
2490724992
unixLeaveMutex();
2490824993
}
2490924994
24910
-#if SQLITE_ENABLE_LOCKING_STYLE && defined(__DARWIN__)
24995
+#if SQLITE_ENABLE_LOCKING_STYLE && defined(__APPLE__)
2491124996
else if( pLockingStyle == &afpIoMethods ){
2491224997
/* AFP locking uses the file path so it needs to be included in
2491324998
** the afpLockingContext.
2491424999
*/
2491525000
afpLockingContext *pCtx;
@@ -25001,11 +25086,11 @@
2500125086
int ii;
2500225087
int fd = -1;
2500325088
char zDirname[MAX_PATHNAME+1];
2500425089
2500525090
sqlite3_snprintf(MAX_PATHNAME, zDirname, "%s", zFilename);
25006
- for(ii=(int)strlen(zDirname); ii>=0 && zDirname[ii]!='/'; ii--);
25091
+ for(ii=(int)strlen(zDirname); ii>1 && zDirname[ii]!='/'; ii--);
2500725092
if( ii>0 ){
2500825093
zDirname[ii] = '\0';
2500925094
fd = open(zDirname, O_RDONLY|O_BINARY, 0);
2501025095
if( fd>=0 ){
2501125096
#ifdef FD_CLOEXEC
@@ -25077,11 +25162,11 @@
2507725162
zBuf[j] = 0;
2507825163
}while( access(zBuf,0)==0 );
2507925164
return SQLITE_OK;
2508025165
}
2508125166
25082
-#if SQLITE_ENABLE_LOCKING_STYLE && defined(__DARWIN__)
25167
+#if SQLITE_ENABLE_LOCKING_STYLE && defined(__APPLE__)
2508325168
/*
2508425169
** Routine to transform a unixFile into a proxy-locking unixFile.
2508525170
** Implementation in the proxy-lock division, but used by unixOpen()
2508625171
** if SQLITE_PREFER_PROXY_LOCKING is defined.
2508725172
*/
@@ -25724,11 +25809,11 @@
2572425809
*/
2572525810
2572625811
/*
2572725812
** Proxy locking is only available on MacOSX
2572825813
*/
25729
-#if defined(__DARWIN__) && SQLITE_ENABLE_LOCKING_STYLE
25814
+#if defined(__APPLE__) && SQLITE_ENABLE_LOCKING_STYLE
2573025815
2573125816
#ifdef SQLITE_TEST
2573225817
/* simulate multiple hosts by creating unique hostid file paths */
2573325818
SQLITE_API int sqlite3_hostid_num = 0;
2573425819
#endif
@@ -26214,11 +26299,11 @@
2621426299
**
2621526300
** This routine find the filename associated with pFile and writes it
2621626301
** int dbPath.
2621726302
*/
2621826303
static int proxyGetDbPathForUnixFile(unixFile *pFile, char *dbPath){
26219
-#if defined(__DARWIN__)
26304
+#if defined(__APPLE__)
2622026305
if( pFile->pMethod == &afpIoMethods ){
2622126306
/* afp style keeps a reference to the db path in the filePath field
2622226307
** of the struct */
2622326308
assert( (int)strlen((char*)pFile->lockingContext)<=MAXPATHLEN );
2622426309
strcpy(dbPath, ((afpLockingContext *)pFile->lockingContext)->dbPath);
@@ -26483,11 +26568,11 @@
2648326568
return SQLITE_OK;
2648426569
}
2648526570
2648626571
2648726572
26488
-#endif /* defined(__DARWIN__) && SQLITE_ENABLE_LOCKING_STYLE */
26573
+#endif /* defined(__APPLE__) && SQLITE_ENABLE_LOCKING_STYLE */
2648926574
/*
2649026575
** The proxy locking style is intended for use with AFP filesystems.
2649126576
** And since AFP is only supported on MacOSX, the proxy locking is also
2649226577
** restricted to MacOSX.
2649326578
**
@@ -26556,11 +26641,11 @@
2655626641
** Note that the sqlite3_vfs.pNext field of the VFS object is modified
2655726642
** by the SQLite core when the VFS is registered. So the following
2655826643
** array cannot be const.
2655926644
*/
2656026645
static sqlite3_vfs aVfs[] = {
26561
-#if SQLITE_ENABLE_LOCKING_STYLE && defined(__DARWIN__)
26646
+#if SQLITE_ENABLE_LOCKING_STYLE && defined(__APPLE__)
2656226647
UNIXVFS("unix", autolockIoFinder ),
2656326648
#else
2656426649
UNIXVFS("unix", posixIoFinder ),
2656526650
#endif
2656626651
UNIXVFS("unix-none", nolockIoFinder ),
@@ -26570,11 +26655,11 @@
2657026655
#endif
2657126656
#if SQLITE_ENABLE_LOCKING_STYLE
2657226657
UNIXVFS("unix-posix", posixIoFinder ),
2657326658
UNIXVFS("unix-flock", flockIoFinder ),
2657426659
#endif
26575
-#if SQLITE_ENABLE_LOCKING_STYLE && defined(__DARWIN__)
26660
+#if SQLITE_ENABLE_LOCKING_STYLE && defined(__APPLE__)
2657626661
UNIXVFS("unix-afp", afpIoFinder ),
2657726662
UNIXVFS("unix-proxy", proxyIoFinder ),
2657826663
#endif
2657926664
};
2658026665
unsigned int i; /* Loop counter */
@@ -28592,11 +28677,11 @@
2859228677
** sometimes grow into tens of thousands or larger. The size of the
2859328678
** Bitvec object is the number of pages in the database file at the
2859428679
** start of a transaction, and is thus usually less than a few thousand,
2859528680
** but can be as large as 2 billion for a really big database.
2859628681
**
28597
-** @(#) $Id: bitvec.c,v 1.9 2008/11/19 18:30:35 shane Exp $
28682
+** @(#) $Id: bitvec.c,v 1.10 2009/01/02 21:39:39 drh Exp $
2859828683
*/
2859928684
2860028685
/* Size of the Bitvec structure in bytes. */
2860128686
#define BITVEC_SZ 512
2860228687
@@ -28731,13 +28816,11 @@
2873128816
i--;
2873228817
while((p->iSize > BITVEC_NBIT) && p->iDivisor) {
2873328818
u32 bin = i/p->iDivisor;
2873428819
i = i%p->iDivisor;
2873528820
if( p->u.apSub[bin]==0 ){
28736
- sqlite3BeginBenignMalloc();
2873728821
p->u.apSub[bin] = sqlite3BitvecCreate( p->iDivisor );
28738
- sqlite3EndBenignMalloc();
2873928822
if( p->u.apSub[bin]==0 ) return SQLITE_NOMEM;
2874028823
}
2874128824
p = p->u.apSub[bin];
2874228825
}
2874328826
if( p->iSize<=BITVEC_NBIT ){
@@ -29546,11 +29629,11 @@
2954629629
** sqlite3_pcache interface). It also contains part of the implementation
2954729630
** of the SQLITE_CONFIG_PAGECACHE and sqlite3_release_memory() features.
2954829631
** If the default page cache implementation is overriden, then neither of
2954929632
** these two features are available.
2955029633
**
29551
-** @(#) $Id: pcache1.c,v 1.6 2008/12/10 18:03:46 drh Exp $
29634
+** @(#) $Id: pcache1.c,v 1.7 2009/01/07 15:18:21 danielk1977 Exp $
2955229635
*/
2955329636
2955429637
2955529638
typedef struct PCache1 PCache1;
2955629639
typedef struct PgHdr1 PgHdr1;
@@ -29576,10 +29659,12 @@
2957629659
*/
2957729660
unsigned int nRecyclable; /* Number of pages in the LRU list */
2957829661
unsigned int nPage; /* Total number of pages in apHash */
2957929662
unsigned int nHash; /* Number of slots in apHash[] */
2958029663
PgHdr1 **apHash; /* Hash table for fast lookup by key */
29664
+
29665
+ unsigned int iMaxKey; /* Largest key seen since xTruncate() */
2958129666
};
2958229667
2958329668
/*
2958429669
** Each cache entry is represented by an instance of the following
2958529670
** structure. A buffer of PgHdr1.pCache->szPage bytes is allocated
@@ -30086,10 +30171,13 @@
3008630171
pPage->pCache = pCache;
3008730172
pCache->apHash[h] = pPage;
3008830173
}
3008930174
3009030175
fetch_out:
30176
+ if( pPage && iKey>pCache->iMaxKey ){
30177
+ pCache->iMaxKey = iKey;
30178
+ }
3009130179
if( createFlag==1 ) sqlite3EndBenignMalloc();
3009230180
pcache1LeaveMutex();
3009330181
return (pPage ? PGHDR1_TO_PAGE(pPage) : 0);
3009430182
}
3009530183
@@ -30160,10 +30248,14 @@
3016030248
3016130249
h = iNew%pCache->nHash;
3016230250
pPage->iKey = iNew;
3016330251
pPage->pNext = pCache->apHash[h];
3016430252
pCache->apHash[h] = pPage;
30253
+
30254
+ if( iNew>pCache->iMaxKey ){
30255
+ pCache->iMaxKey = iNew;
30256
+ }
3016530257
3016630258
pcache1LeaveMutex();
3016730259
}
3016830260
3016930261
/*
@@ -30174,11 +30266,14 @@
3017430266
** equal to or greater than iLimit are implicitly unpinned.
3017530267
*/
3017630268
static void pcache1Truncate(sqlite3_pcache *p, unsigned int iLimit){
3017730269
PCache1 *pCache = (PCache1 *)p;
3017830270
pcache1EnterMutex();
30179
- pcache1TruncateUnsafe(pCache, iLimit);
30271
+ if( iLimit<=pCache->iMaxKey ){
30272
+ pcache1TruncateUnsafe(pCache, iLimit);
30273
+ pCache->iMaxKey = iLimit-1;
30274
+ }
3018030275
pcache1LeaveMutex();
3018130276
}
3018230277
3018330278
/*
3018430279
** Implementation of the sqlite3_pcache.xDestroy method.
@@ -30343,29 +30438,27 @@
3034330438
** Turn bulk memory into a RowSet object. N bytes of memory
3034430439
** are available at pSpace. The db pointer is used as a memory context
3034530440
** for any subsequent allocations that need to occur.
3034630441
** Return a pointer to the new RowSet object.
3034730442
**
30348
-** If N is not sufficient memory to make even a minimum RowSet,
30349
-** then return NULL. If N is larger than the minimum, use
30350
-** the surplus as an initial allocation of entries available to
30351
-** be filled.
30443
+** It must be the case that N is sufficient to make a Rowset. If not
30444
+** an assertion fault occurs.
30445
+**
30446
+** If N is larger than the minimum, use the surplus as an initial
30447
+** allocation of entries available to be filled.
3035230448
*/
3035330449
SQLITE_PRIVATE RowSet *sqlite3RowSetInit(sqlite3 *db, void *pSpace, unsigned int N){
3035430450
RowSet *p;
30355
- if( N<sizeof(*p) ){
30356
- p = 0;
30357
- }else{
30358
- p = pSpace;
30359
- p->pChunk = 0;
30360
- p->db = db;
30361
- p->pEntry = 0;
30362
- p->pLast = 0;
30363
- p->pFresh = (struct RowSetEntry*)&p[1];
30364
- p->nFresh = (u16)((N - sizeof(*p))/sizeof(struct RowSetEntry));
30365
- p->isSorted = 1;
30366
- }
30451
+ assert( N >= sizeof(*p) );
30452
+ p = pSpace;
30453
+ p->pChunk = 0;
30454
+ p->db = db;
30455
+ p->pEntry = 0;
30456
+ p->pLast = 0;
30457
+ p->pFresh = (struct RowSetEntry*)&p[1];
30458
+ p->nFresh = (u16)((N - sizeof(*p))/sizeof(struct RowSetEntry));
30459
+ p->isSorted = 1;
3036730460
return p;
3036830461
}
3036930462
3037030463
/*
3037130464
** Deallocate all chunks from a RowSet.
@@ -30529,34 +30622,27 @@
3052930622
** is separate from the database file. The pager also implements file
3053030623
** locking to prevent two processes from writing the same database
3053130624
** file simultaneously, or one process from reading the database while
3053230625
** another is writing.
3053330626
**
30534
-** @(#) $Id: pager.c,v 1.514 2008/12/10 22:15:00 drh Exp $
30627
+** @(#) $Id: pager.c,v 1.544 2009/01/09 17:11:05 danielk1977 Exp $
3053530628
*/
3053630629
#ifndef SQLITE_OMIT_DISKIO
3053730630
3053830631
/*
3053930632
** Macros for troubleshooting. Normally turned off
3054030633
*/
3054130634
#if 0
30635
+int sqlite3PagerTrace=1; /* True to enable tracing */
3054230636
#define sqlite3DebugPrintf printf
30543
-#define PAGERTRACE1(X) sqlite3DebugPrintf(X)
30544
-#define PAGERTRACE2(X,Y) sqlite3DebugPrintf(X,Y)
30545
-#define PAGERTRACE3(X,Y,Z) sqlite3DebugPrintf(X,Y,Z)
30546
-#define PAGERTRACE4(X,Y,Z,W) sqlite3DebugPrintf(X,Y,Z,W)
30547
-#define PAGERTRACE5(X,Y,Z,W,V) sqlite3DebugPrintf(X,Y,Z,W,V)
30637
+#define PAGERTRACE(X) if( sqlite3PagerTrace ){ sqlite3DebugPrintf X; }
3054830638
#else
30549
-#define PAGERTRACE1(X)
30550
-#define PAGERTRACE2(X,Y)
30551
-#define PAGERTRACE3(X,Y,Z)
30552
-#define PAGERTRACE4(X,Y,Z,W)
30553
-#define PAGERTRACE5(X,Y,Z,W,V)
30639
+#define PAGERTRACE(X)
3055430640
#endif
3055530641
3055630642
/*
30557
-** The following two macros are used within the PAGERTRACEX() macros above
30643
+** The following two macros are used within the PAGERTRACE() macros above
3055830644
** to print out file-descriptors.
3055930645
**
3056030646
** PAGERID() takes a pointer to a Pager struct as its argument. The
3056130647
** associated file-descriptor is returned. FILEHANDLEID() takes an sqlite3_file
3056230648
** struct as its argument.
@@ -30616,27 +30702,10 @@
3061630702
#define PAGER_SHARED 1 /* same as SHARED_LOCK */
3061730703
#define PAGER_RESERVED 2 /* same as RESERVED_LOCK */
3061830704
#define PAGER_EXCLUSIVE 4 /* same as EXCLUSIVE_LOCK */
3061930705
#define PAGER_SYNCED 5
3062030706
30621
-/*
30622
-** If the SQLITE_BUSY_RESERVED_LOCK macro is set to true at compile-time,
30623
-** then failed attempts to get a reserved lock will invoke the busy callback.
30624
-** This is off by default. To see why, consider the following scenario:
30625
-**
30626
-** Suppose thread A already has a shared lock and wants a reserved lock.
30627
-** Thread B already has a reserved lock and wants an exclusive lock. If
30628
-** both threads are using their busy callbacks, it might be a long time
30629
-** be for one of the threads give up and allows the other to proceed.
30630
-** But if the thread trying to get the reserved lock gives up quickly
30631
-** (if it never invokes its busy callback) then the contention will be
30632
-** resolved quickly.
30633
-*/
30634
-#ifndef SQLITE_BUSY_RESERVED_LOCK
30635
-# define SQLITE_BUSY_RESERVED_LOCK 0
30636
-#endif
30637
-
3063830707
/*
3063930708
** This macro rounds values up so that if the value is an address it
3064030709
** is guaranteed to be an address that is aligned to an 8-byte boundary.
3064130710
*/
3064230711
#define FORCE_ALIGNMENT(X) (((X)+7)&~7)
@@ -30650,10 +30719,32 @@
3065030719
#else
3065130720
# define CODEC1(P,D,N,X) /* NO-OP */
3065230721
# define CODEC2(P,D,N,X) ((char*)D)
3065330722
#endif
3065430723
30724
+/*
30725
+** An instance of the following structure is allocated for each active
30726
+** savepoint and statement transaction in the system. All such structures
30727
+** are stored in the Pager.aSavepoint[] array, which is allocated and
30728
+** resized using sqlite3Realloc().
30729
+**
30730
+** When a savepoint is created, the PagerSavepoint.iHdrOffset field is
30731
+** set to 0. If a journal-header is written into the main journal while
30732
+** the savepoint is active, then iHdrOffset is set to the byte offset
30733
+** immediately following the last journal record written into the main
30734
+** journal before the journal-header. This is required during savepoint
30735
+** rollback (see pagerPlaybackSavepoint()).
30736
+*/
30737
+typedef struct PagerSavepoint PagerSavepoint;
30738
+struct PagerSavepoint {
30739
+ i64 iOffset; /* Starting offset in main journal */
30740
+ i64 iHdrOffset; /* See above */
30741
+ Bitvec *pInSavepoint; /* Set of pages in this savepoint */
30742
+ Pgno nOrig; /* Original number of pages in file */
30743
+ Pgno iSubRec; /* Index of first record in sub-journal */
30744
+};
30745
+
3065530746
/*
3065630747
** A open page cache is an instance of the following structure.
3065730748
**
3065830749
** Pager.errCode may be set to SQLITE_IOERR, SQLITE_CORRUPT, or
3065930750
** or SQLITE_FULL. Once one of the first three errors occurs, it persists
@@ -30660,20 +30751,29 @@
3066030751
** and is returned as the result of every major pager API call. The
3066130752
** SQLITE_FULL return code is slightly different. It persists only until the
3066230753
** next successful rollback is performed on the pager cache. Also,
3066330754
** SQLITE_FULL does not affect the sqlite3PagerGet() and sqlite3PagerLookup()
3066430755
** APIs, they may still be used successfully.
30756
+**
30757
+** Managing the size of the database file in pages is a little complicated.
30758
+** The variable Pager.dbSize contains the number of pages that the database
30759
+** image currently contains. As the database image grows or shrinks this
30760
+** variable is updated. The variable Pager.dbFileSize contains the number
30761
+** of pages in the database file. This may be different from Pager.dbSize
30762
+** if some pages have been appended to the database image but not yet written
30763
+** out from the cache to the actual file on disk. Or if the image has been
30764
+** truncated by an incremental-vacuum operation. The Pager.dbOrigSize variable
30765
+** contains the number of pages in the database image when the current
30766
+** transaction was opened. The contents of all three of these variables is
30767
+** only guaranteed to be correct if the boolean Pager.dbSizeValid is true.
3066530768
*/
3066630769
struct Pager {
3066730770
sqlite3_vfs *pVfs; /* OS functions to use for IO */
3066830771
u8 journalOpen; /* True if journal file descriptors is valid */
3066930772
u8 journalStarted; /* True if header of journal is synced */
3067030773
u8 useJournal; /* Use a rollback journal on this file */
3067130774
u8 noReadlock; /* Do not bother to obtain readlocks */
30672
- u8 stmtOpen; /* True if the statement subjournal is open */
30673
- u8 stmtInUse; /* True we are in a statement subtransaction */
30674
- u8 stmtAutoopen; /* Open stmt journal when main journal is opened*/
3067530775
u8 noSync; /* Do not sync the journal if true */
3067630776
u8 fullSync; /* Do extra syncs of the journal for robustness */
3067730777
u8 sync_flags; /* One of SYNC_NORMAL or SYNC_FULL */
3067830778
u8 state; /* PAGER_UNLOCK, _SHARED, _RESERVED, etc. */
3067930779
u8 tempFile; /* zFilename is a temporary file */
@@ -30687,38 +30787,34 @@
3068730787
u8 exclusiveMode; /* Boolean. True if locking_mode==EXCLUSIVE */
3068830788
u8 journalMode; /* On of the PAGER_JOURNALMODE_* values */
3068930789
u8 dbModified; /* True if there are any changes to the Db */
3069030790
u8 changeCountDone; /* Set after incrementing the change-counter */
3069130791
u8 dbSizeValid; /* Set when dbSize is correct */
30792
+ Pgno dbSize; /* Number of pages in the database */
30793
+ Pgno dbOrigSize; /* dbSize before the current transaction */
30794
+ Pgno dbFileSize; /* Number of pages in the database file */
3069230795
u32 vfsFlags; /* Flags for sqlite3_vfs.xOpen() */
3069330796
int errCode; /* One of several kinds of errors */
30694
- Pgno dbSize; /* Number of pages in the file */
30695
- Pgno origDbSize; /* dbSize before the current change */
30696
- Pgno stmtSize; /* Size of database (in pages) at stmt_begin() */
3069730797
int nRec; /* Number of pages written to the journal */
3069830798
u32 cksumInit; /* Quasi-random value added to every checksum */
3069930799
int stmtNRec; /* Number of records in stmt subjournal */
3070030800
int nExtra; /* Add this many bytes to each in-memory page */
3070130801
int pageSize; /* Number of bytes in a page */
3070230802
int nPage; /* Total number of in-memory pages */
3070330803
int mxPage; /* Maximum number of pages to hold in cache */
3070430804
Pgno mxPgno; /* Maximum allowed size of the database */
3070530805
Bitvec *pInJournal; /* One bit for each page in the database file */
30706
- Bitvec *pInStmt; /* One bit for each page in the database */
3070730806
Bitvec *pAlwaysRollback; /* One bit for each page marked always-rollback */
3070830807
char *zFilename; /* Name of the database file */
3070930808
char *zJournal; /* Name of the journal file */
3071030809
char *zDirectory; /* Directory hold database and journal files */
3071130810
sqlite3_file *fd, *jfd; /* File descriptors for database and journal */
30712
- sqlite3_file *stfd; /* File descriptor for the statement subjournal*/
30811
+ sqlite3_file *sjfd; /* File descriptor for the sub-journal*/
3071330812
int (*xBusyHandler)(void*); /* Function to call when busy */
3071430813
void *pBusyHandlerArg; /* Context argument for xBusyHandler */
3071530814
i64 journalOff; /* Current byte offset in the journal file */
3071630815
i64 journalHdr; /* Byte offset to previous journal header */
30717
- i64 stmtHdrOff; /* First journal header written this statement */
30718
- i64 stmtCksum; /* cksumInit when statement was started */
30719
- i64 stmtJSize; /* Size of journal at stmt_begin() */
3072030816
u32 sectorSize; /* Assumed sector size during rollback */
3072130817
#ifdef SQLITE_TEST
3072230818
int nHit, nMiss; /* Cache hits and missing */
3072330819
int nRead, nWrite; /* Database pages read/written */
3072430820
#endif
@@ -30729,10 +30825,12 @@
3072930825
#endif
3073030826
char *pTmpSpace; /* Pager.pageSize bytes of space for tmp use */
3073130827
char dbFileVers[16]; /* Changes whenever database file changes */
3073230828
i64 journalSizeLimit; /* Size limit for persistent journal files */
3073330829
PCache *pPCache; /* Pointer to page cache object */
30830
+ PagerSavepoint *aSavepoint; /* Array of active savepoints */
30831
+ int nSavepoint; /* Number of elements in aSavepoint[] */
3073430832
};
3073530833
3073630834
/*
3073730835
** The following global variables hold counters used for
3073830836
** testing purposes only. These variables do not exist in
@@ -30752,11 +30850,11 @@
3075230850
/*
3075330851
** Journal files begin with the following magic string. The data
3075430852
** was obtained from /dev/random. It is used only as a sanity check.
3075530853
**
3075630854
** Since version 2.8.0, the journal format contains additional sanity
30757
-** checking information. If the power fails while the journal is begin
30855
+** checking information. If the power fails while the journal is being
3075830856
** written, semi-random garbage data might appear in the journal
3075930857
** file after power is restored. If an attempt is then made
3076030858
** to roll the journal back, the database could be corrupted. The additional
3076130859
** sanity checking data is an attempt to discover the garbage in the
3076230860
** journal and ignore it.
@@ -30815,19 +30913,34 @@
3081530913
** The maximum legal page number is (2^31 - 1).
3081630914
*/
3081730915
#define PAGER_MAX_PGNO 2147483647
3081830916
3081930917
/*
30820
-** Return true if page *pPg has already been written to the statement
30821
-** journal (or statement snapshot has been created, if *pPg is part
30822
-** of an in-memory database).
30918
+** Return true if it is necessary to write page *pPg into the sub-journal.
30919
+** A page needs to be written into the sub-journal if there exists one
30920
+** or more open savepoints for which:
30921
+**
30922
+** * The page-number is less than or equal to PagerSavepoint.nOrig, and
30923
+** * The bit corresponding to the page-number is not set in
30924
+** PagerSavepoint.pInSavepoint.
3082330925
*/
30824
-static int pageInStatement(PgHdr *pPg){
30926
+static int subjRequiresPage(PgHdr *pPg){
30927
+ Pgno pgno = pPg->pgno;
3082530928
Pager *pPager = pPg->pPager;
30826
- return sqlite3BitvecTest(pPager->pInStmt, pPg->pgno);
30929
+ int i;
30930
+ for(i=0; i<pPager->nSavepoint; i++){
30931
+ PagerSavepoint *p = &pPager->aSavepoint[i];
30932
+ if( p->nOrig>=pgno && 0==sqlite3BitvecTest(p->pInSavepoint, pgno) ){
30933
+ return 1;
30934
+ }
30935
+ }
30936
+ return 0;
3082730937
}
3082830938
30939
+/*
30940
+** Return true if the page is already in the journal file.
30941
+*/
3082930942
static int pageInJournal(PgHdr *pPg){
3083030943
return sqlite3BitvecTest(pPg->pPager->pInJournal, pPg->pgno);
3083130944
}
3083230945
3083330946
/*
@@ -31070,20 +31183,23 @@
3107031183
** 512 512
3107131184
** 100 512
3107231185
** 2000 2048
3107331186
**
3107431187
*/
31075
-static void seekJournalHdr(Pager *pPager){
31188
+static i64 journalHdrOffset(Pager *pPager){
3107631189
i64 offset = 0;
3107731190
i64 c = pPager->journalOff;
3107831191
if( c ){
3107931192
offset = ((c-1)/JOURNAL_HDR_SZ(pPager) + 1) * JOURNAL_HDR_SZ(pPager);
3108031193
}
3108131194
assert( offset%JOURNAL_HDR_SZ(pPager)==0 );
3108231195
assert( offset>=c );
3108331196
assert( (offset-c)<JOURNAL_HDR_SZ(pPager) );
31084
- pPager->journalOff = offset;
31197
+ return offset;
31198
+}
31199
+static void seekJournalHdr(Pager *pPager){
31200
+ pPager->journalOff = journalHdrOffset(pPager);
3108531201
}
3108631202
3108731203
/*
3108831204
** Write zeros over the header of the journal file. This has the
3108931205
** effect of invalidating the journal file and committing the
@@ -31141,17 +31257,24 @@
3114131257
static int writeJournalHdr(Pager *pPager){
3114231258
int rc = SQLITE_OK;
3114331259
char *zHeader = pPager->pTmpSpace;
3114431260
u32 nHeader = pPager->pageSize;
3114531261
u32 nWrite;
31262
+ int ii;
3114631263
3114731264
if( nHeader>JOURNAL_HDR_SZ(pPager) ){
3114831265
nHeader = JOURNAL_HDR_SZ(pPager);
3114931266
}
3115031267
31151
- if( pPager->stmtHdrOff==0 ){
31152
- pPager->stmtHdrOff = pPager->journalOff;
31268
+ /* If there are active savepoints and any of them were created since the
31269
+ ** most recent journal header was written, update the PagerSavepoint.iHdrOff
31270
+ ** fields now.
31271
+ */
31272
+ for(ii=0; ii<pPager->nSavepoint; ii++){
31273
+ if( pPager->aSavepoint[ii].iHdrOffset==0 ){
31274
+ pPager->aSavepoint[ii].iHdrOffset = pPager->journalOff;
31275
+ }
3115331276
}
3115431277
3115531278
seekJournalHdr(pPager);
3115631279
pPager->journalHdr = pPager->journalOff;
3115731280
@@ -31188,11 +31311,11 @@
3118831311
3118931312
/* The random check-hash initialiser */
3119031313
sqlite3_randomness(sizeof(pPager->cksumInit), &pPager->cksumInit);
3119131314
put32bits(&zHeader[sizeof(aJournalMagic)+4], pPager->cksumInit);
3119231315
/* The initial database size */
31193
- put32bits(&zHeader[sizeof(aJournalMagic)+8], pPager->dbSize);
31316
+ put32bits(&zHeader[sizeof(aJournalMagic)+8], pPager->dbOrigSize);
3119431317
/* The assumed sector size for this process */
3119531318
put32bits(&zHeader[sizeof(aJournalMagic)+12], pPager->sectorSize);
3119631319
3119731320
/* Initializing the tail of the buffer is not necessary. Everything
3119831321
** works find if the following memset() is omitted. But initializing
@@ -31217,21 +31340,22 @@
3121731340
}
3121831341
3121931342
/*
3122031343
** The journal file must be open when this is called. A journal header file
3122131344
** (JOURNAL_HDR_SZ bytes) is read from the current location in the journal
31222
-** file. See comments above function writeJournalHdr() for a description of
31223
-** the journal header format.
31345
+** file. The current location in the journal file is given by
31346
+** pPager->journalOff. See comments above function writeJournalHdr() for
31347
+** a description of the journal header format.
3122431348
**
3122531349
** If the header is read successfully, *nRec is set to the number of
3122631350
** page records following this header and *dbSize is set to the size of the
3122731351
** database before the transaction began, in pages. Also, pPager->cksumInit
3122831352
** is set to the value read from the journal header. SQLITE_OK is returned
3122931353
** in this case.
3123031354
**
3123131355
** If the journal header file appears to be corrupted, SQLITE_DONE is
31232
-** returned and *nRec and *dbSize are not set. If JOURNAL_HDR_SZ bytes
31356
+** returned and *nRec and *dbSize are undefined. If JOURNAL_HDR_SZ bytes
3123331357
** cannot be read from the journal file an error code is returned.
3123431358
*/
3123531359
static int readJournalHdr(
3123631360
Pager *pPager,
3123731361
i64 journalSize,
@@ -31394,10 +31518,47 @@
3139431518
*/
3139531519
static void pager_reset(Pager *pPager){
3139631520
if( pPager->errCode ) return;
3139731521
sqlite3PcacheClear(pPager->pPCache);
3139831522
}
31523
+
31524
+/*
31525
+** Free all structures in the Pager.aSavepoint[] array and set both
31526
+** Pager.aSavepoint and Pager.nSavepoint to zero. Close the sub-journal
31527
+** if it is open and the pager is not in exclusive mode.
31528
+*/
31529
+static void releaseAllSavepoint(Pager *pPager){
31530
+ int ii;
31531
+ for(ii=0; ii<pPager->nSavepoint; ii++){
31532
+ sqlite3BitvecDestroy(pPager->aSavepoint[ii].pInSavepoint);
31533
+ }
31534
+ if( !pPager->exclusiveMode ){
31535
+ sqlite3OsClose(pPager->sjfd);
31536
+ }
31537
+ sqlite3_free(pPager->aSavepoint);
31538
+ pPager->aSavepoint = 0;
31539
+ pPager->nSavepoint = 0;
31540
+ pPager->stmtNRec = 0;
31541
+}
31542
+
31543
+/*
31544
+** Set the bit number pgno in the PagerSavepoint.pInSavepoint bitvecs of
31545
+** all open savepoints.
31546
+*/
31547
+static int addToSavepointBitvecs(Pager *pPager, Pgno pgno){
31548
+ int ii; /* Loop counter */
31549
+ int rc = SQLITE_OK; /* Result code */
31550
+
31551
+ for(ii=0; ii<pPager->nSavepoint; ii++){
31552
+ PagerSavepoint *p = &pPager->aSavepoint[ii];
31553
+ if( pgno<=p->nOrig ){
31554
+ rc |= sqlite3BitvecSet(p->pInSavepoint, pgno);
31555
+ assert( rc==SQLITE_OK || rc==SQLITE_NOMEM );
31556
+ }
31557
+ }
31558
+ return rc;
31559
+}
3139931560
3140031561
/*
3140131562
** Unlock the database file.
3140231563
**
3140331564
** If the pager is currently in error state, discard the contents of
@@ -31431,21 +31592,14 @@
3143131592
** cache can be discarded and the error code safely cleared.
3143231593
*/
3143331594
if( pPager->errCode ){
3143431595
if( rc==SQLITE_OK ) pPager->errCode = SQLITE_OK;
3143531596
pager_reset(pPager);
31436
- if( pPager->stmtOpen ){
31437
- sqlite3OsClose(pPager->stfd);
31438
- sqlite3BitvecDestroy(pPager->pInStmt);
31439
- pPager->pInStmt = 0;
31440
- }
31441
- pPager->stmtOpen = 0;
31442
- pPager->stmtInUse = 0;
31597
+ releaseAllSavepoint(pPager);
3144331598
pPager->journalOff = 0;
3144431599
pPager->journalStarted = 0;
31445
- pPager->stmtAutoopen = 0;
31446
- pPager->origDbSize = 0;
31600
+ pPager->dbOrigSize = 0;
3144731601
}
3144831602
3144931603
pPager->state = PAGER_UNLOCK;
3145031604
pPager->changeCountDone = 0;
3145131605
}
@@ -31486,15 +31640,11 @@
3148631640
int rc = SQLITE_OK;
3148731641
int rc2 = SQLITE_OK;
3148831642
if( pPager->state<PAGER_RESERVED ){
3148931643
return SQLITE_OK;
3149031644
}
31491
- sqlite3PagerStmtCommit(pPager);
31492
- if( pPager->stmtOpen && !pPager->exclusiveMode ){
31493
- sqlite3OsClose(pPager->stfd);
31494
- pPager->stmtOpen = 0;
31495
- }
31645
+ releaseAllSavepoint(pPager);
3149631646
if( pPager->journalOpen ){
3149731647
if( pPager->journalMode==PAGER_JOURNALMODE_MEMORY ){
3149831648
int isMemoryJournal = sqlite3IsMemJournal(pPager->jfd);
3149931649
sqlite3OsClose(pPager->jfd);
3150031650
pPager->journalOpen = 0;
@@ -31538,14 +31688,15 @@
3153831688
rc2 = osUnlock(pPager->fd, SHARED_LOCK);
3153931689
pPager->state = PAGER_SHARED;
3154031690
}else if( pPager->state==PAGER_SYNCED ){
3154131691
pPager->state = PAGER_EXCLUSIVE;
3154231692
}
31543
- pPager->origDbSize = 0;
31693
+ pPager->dbOrigSize = 0;
3154431694
pPager->setMaster = 0;
3154531695
pPager->needSync = 0;
3154631696
/* lruListSetFirstSynced(pPager); */
31697
+ sqlite3PcacheTruncate(pPager->pPCache, pPager->dbSize);
3154731698
if( !MEMDB ){
3154831699
pPager->dbSizeValid = 0;
3154931700
}
3155031701
pPager->dbModified = 0;
3155131702
@@ -31581,59 +31732,75 @@
3158131732
}
3158231733
return cksum;
3158331734
}
3158431735
3158531736
/*
31586
-** Read a single page from the journal file opened on file descriptor
31587
-** jfd. Playback this one page.
31737
+** Read a single page from either the journal file (if isMainJrnl==1) or
31738
+** from the sub-journal (if isMainJrnl==0) and playback that page.
31739
+** The page begins at offset *pOffset into the file. The *pOffset
31740
+** value is increased to the start of the next page in the journal.
3158831741
**
3158931742
** The isMainJrnl flag is true if this is the main rollback journal and
3159031743
** false for the statement journal. The main rollback journal uses
3159131744
** checksums - the statement journal does not.
31745
+**
31746
+** If pDone is not NULL, then it is a record of pages that have already
31747
+** been played back. If the page at *pOffset has already been played back
31748
+** (if the corresponding pDone bit is set) then skip the playback.
31749
+** Make sure the pDone bit corresponding to the *pOffset page is set
31750
+** prior to returning.
3159231751
*/
3159331752
static int pager_playback_one_page(
31594
- Pager *pPager, /* The pager being played back */
31595
- sqlite3_file *jfd, /* The file that is the journal being rolled back */
31596
- i64 offset, /* Offset of the page within the journal */
31597
- int isMainJrnl /* True for main rollback journal. False for Stmt jrnl */
31753
+ Pager *pPager, /* The pager being played back */
31754
+ int isMainJrnl, /* 1 -> main journal. 0 -> sub-journal. */
31755
+ i64 *pOffset, /* Offset of record to playback */
31756
+ int isSavepnt, /* True for a savepoint rollback */
31757
+ Bitvec *pDone /* Bitvec of pages already played back */
3159831758
){
3159931759
int rc;
3160031760
PgHdr *pPg; /* An existing page in the cache */
3160131761
Pgno pgno; /* The page number of a page in journal */
3160231762
u32 cksum; /* Checksum used for sanity checking */
31603
- u8 *aData = (u8 *)pPager->pTmpSpace; /* Temp storage for a page */
31604
-
31605
- /* isMainJrnl should be true for the main journal and false for
31606
- ** statement journals. Verify that this is always the case
31607
- */
31608
- assert( jfd == (isMainJrnl ? pPager->jfd : pPager->stfd) );
31609
- assert( aData );
31610
-
31611
- rc = read32bits(jfd, offset, &pgno);
31612
- if( rc!=SQLITE_OK ) return rc;
31613
- rc = sqlite3OsRead(jfd, aData, pPager->pageSize, offset+4);
31614
- if( rc!=SQLITE_OK ) return rc;
31615
- pPager->journalOff += pPager->pageSize + 4;
31763
+ u8 *aData; /* Temporary storage for the page */
31764
+ sqlite3_file *jfd; /* The file descriptor for the journal file */
31765
+
31766
+ assert( (isMainJrnl&~1)==0 ); /* isMainJrnl is 0 or 1 */
31767
+ assert( (isSavepnt&~1)==0 ); /* isSavepnt is 0 or 1 */
31768
+ assert( isMainJrnl || pDone ); /* pDone always used on sub-journals */
31769
+ assert( isSavepnt || pDone==0 ); /* pDone never used on non-savepoint */
31770
+
31771
+ aData = (u8*)pPager->pTmpSpace;
31772
+ assert( aData ); /* Temp storage must have already been allocated */
31773
+
31774
+ jfd = isMainJrnl ? pPager->jfd : pPager->sjfd;
31775
+
31776
+ rc = read32bits(jfd, *pOffset, &pgno);
31777
+ if( rc!=SQLITE_OK ) return rc;
31778
+ rc = sqlite3OsRead(jfd, aData, pPager->pageSize, (*pOffset)+4);
31779
+ if( rc!=SQLITE_OK ) return rc;
31780
+ *pOffset += pPager->pageSize + 4 + isMainJrnl*4;
3161631781
3161731782
/* Sanity checking on the page. This is more important that I originally
3161831783
** thought. If a power failure occurs while the journal is being written,
3161931784
** it could cause invalid data to be written into the journal. We need to
3162031785
** detect this invalid data (with high probability) and ignore it.
3162131786
*/
3162231787
if( pgno==0 || pgno==PAGER_MJ_PGNO(pPager) ){
3162331788
return SQLITE_DONE;
3162431789
}
31625
- if( pgno>(unsigned)pPager->dbSize ){
31790
+ if( pgno>(Pgno)pPager->dbSize || sqlite3BitvecTest(pDone, pgno) ){
3162631791
return SQLITE_OK;
3162731792
}
3162831793
if( isMainJrnl ){
31629
- rc = read32bits(jfd, offset+pPager->pageSize+4, &cksum);
31794
+ rc = read32bits(jfd, (*pOffset)-4, &cksum);
3163031795
if( rc ) return rc;
31631
- pPager->journalOff += 4;
31632
- if( pager_cksum(pPager, aData)!=cksum ){
31796
+ if( !isSavepnt && pager_cksum(pPager, aData)!=cksum ){
3163331797
return SQLITE_DONE;
3163431798
}
31799
+ }
31800
+ if( pDone && (rc = sqlite3BitvecSet(pDone, pgno)) ){
31801
+ return rc;
3163531802
}
3163631803
3163731804
assert( pPager->state==PAGER_RESERVED || pPager->state>=PAGER_EXCLUSIVE );
3163831805
3163931806
/* If the pager is in RESERVED state, then there must be a copy of this
@@ -31667,18 +31834,46 @@
3166731834
** 2008-04-14: When attempting to vacuum a corrupt database file, it
3166831835
** is possible to fail a statement on a database that does not yet exist.
3166931836
** Do not attempt to write if database file has never been opened.
3167031837
*/
3167131838
pPg = pager_lookup(pPager, pgno);
31672
- PAGERTRACE4("PLAYBACK %d page %d hash(%08x)\n",
31673
- PAGERID(pPager), pgno, pager_datahash(pPager->pageSize, aData));
31839
+ PAGERTRACE(("PLAYBACK %d page %d hash(%08x) %s\n",
31840
+ PAGERID(pPager), pgno, pager_datahash(pPager->pageSize, aData),
31841
+ (isMainJrnl?"main-journal":"sub-journal")
31842
+ ));
3167431843
if( (pPager->state>=PAGER_EXCLUSIVE)
3167531844
&& (pPg==0 || 0==(pPg->flags&PGHDR_NEED_SYNC))
3167631845
&& (pPager->fd->pMethods)
3167731846
){
3167831847
i64 ofst = (pgno-1)*(i64)pPager->pageSize;
3167931848
rc = sqlite3OsWrite(pPager->fd, aData, pPager->pageSize, ofst);
31849
+ if( pgno>pPager->dbFileSize ){
31850
+ pPager->dbFileSize = pgno;
31851
+ }
31852
+ }else if( !isMainJrnl && pPg==0 ){
31853
+ /* If this is a rollback of a savepoint and data was not written to
31854
+ ** the database and the page is not in-memory, there is a potential
31855
+ ** problem. When the page is next fetched by the b-tree layer, it
31856
+ ** will be read from the database file, which may or may not be
31857
+ ** current.
31858
+ **
31859
+ ** There are a couple of different ways this can happen. All are quite
31860
+ ** obscure. When running in synchronous mode, this can only happen
31861
+ ** if the page is on the free-list at the start of the transaction, then
31862
+ ** populated, then moved using sqlite3PagerMovepage().
31863
+ **
31864
+ ** The solution is to add an in-memory page to the cache containing
31865
+ ** the data just read from the sub-journal. Mark the page as dirty
31866
+ ** and if the pager requires a journal-sync, then mark the page as
31867
+ ** requiring a journal-sync before it is written.
31868
+ */
31869
+ assert( isSavepnt );
31870
+ if( (rc = sqlite3PagerAcquire(pPager, pgno, &pPg, 1)) ){
31871
+ return rc;
31872
+ }
31873
+ pPg->flags &= ~PGHDR_NEED_READ;
31874
+ sqlite3PcacheMakeDirty(pPg);
3168031875
}
3168131876
if( pPg ){
3168231877
/* No page should ever be explicitly rolled back that is in use, except
3168331878
** for page 1 which is held in use in order to keep the lock on the
3168431879
** database active. However such a page may be rolled back as a result
@@ -31689,11 +31884,29 @@
3168931884
pData = pPg->pData;
3169031885
memcpy(pData, aData, pPager->pageSize);
3169131886
if( pPager->xReiniter ){
3169231887
pPager->xReiniter(pPg);
3169331888
}
31694
- if( isMainJrnl ){
31889
+ if( isMainJrnl && (!isSavepnt || pPager->journalOff<=pPager->journalHdr) ){
31890
+ /* If the contents of this page were just restored from the main
31891
+ ** journal file, then its content must be as they were when the
31892
+ ** transaction was first opened. In this case we can mark the page
31893
+ ** as clean, since there will be no need to write it out to the.
31894
+ **
31895
+ ** There is one exception to this rule. If the page is being rolled
31896
+ ** back as part of a savepoint (or statement) rollback from an
31897
+ ** unsynced portion of the main journal file, then it is not safe
31898
+ ** to mark the page as clean. This is because marking the page as
31899
+ ** clean will clear the PGHDR_NEED_SYNC flag. Since the page is
31900
+ ** already in the journal file (recorded in Pager.pInJournal) and
31901
+ ** the PGHDR_NEED_SYNC flag is cleared, if the page is written to
31902
+ ** again within this transaction, it will be marked as dirty but
31903
+ ** the PGHDR_NEED_SYNC flag will not be set. It could then potentially
31904
+ ** be written out into the database file before its journal file
31905
+ ** segment is synced. If a crash occurs during or following this,
31906
+ ** database corruption may ensue.
31907
+ */
3169531908
sqlite3PcacheMakeClean(pPg);
3169631909
}
3169731910
#ifdef SQLITE_CHECK_PAGES
3169831911
pPg->pageHash = pager_pagehash(pPg);
3169931912
#endif
@@ -31708,10 +31921,50 @@
3170831921
sqlite3PcacheRelease(pPg);
3170931922
}
3171031923
return rc;
3171131924
}
3171231925
31926
+#if !defined(NDEBUG) || defined(SQLITE_COVERAGE_TEST)
31927
+/*
31928
+** This routine looks ahead into the main journal file and determines
31929
+** whether or not the next record (the record that begins at file
31930
+** offset pPager->journalOff) is a well-formed page record consisting
31931
+** of a valid page number, pPage->pageSize bytes of content, followed
31932
+** by a valid checksum.
31933
+**
31934
+** The pager never needs to know this in order to do its job. This
31935
+** routine is only used from with assert() and testcase() macros.
31936
+*/
31937
+static int pagerNextJournalPageIsValid(Pager *pPager){
31938
+ Pgno pgno; /* The page number of the page */
31939
+ u32 cksum; /* The page checksum */
31940
+ int rc; /* Return code from read operations */
31941
+ sqlite3_file *fd; /* The file descriptor from which we are reading */
31942
+ u8 *aData; /* Content of the page */
31943
+
31944
+ /* Read the page number header */
31945
+ fd = pPager->jfd;
31946
+ rc = read32bits(fd, pPager->journalOff, &pgno);
31947
+ if( rc!=SQLITE_OK ){ return 0; } /*NO_TEST*/
31948
+ if( pgno==0 || pgno==PAGER_MJ_PGNO(pPager) ){ return 0; } /*NO_TEST*/
31949
+ if( pgno>(Pgno)pPager->dbSize ){ return 0; } /*NO_TEST*/
31950
+
31951
+ /* Read the checksum */
31952
+ rc = read32bits(fd, pPager->journalOff+pPager->pageSize+4, &cksum);
31953
+ if( rc!=SQLITE_OK ){ return 0; } /*NO_TEST*/
31954
+
31955
+ /* Read the data and verify the checksum */
31956
+ aData = (u8*)pPager->pTmpSpace;
31957
+ rc = sqlite3OsRead(fd, aData, pPager->pageSize, pPager->journalOff+4);
31958
+ if( rc!=SQLITE_OK ){ return 0; } /*NO_TEST*/
31959
+ if( pager_cksum(pPager, aData)!=cksum ){ return 0; } /*NO_TEST*/
31960
+
31961
+ /* Reach this point only if the page is valid */
31962
+ return 1;
31963
+}
31964
+#endif /* !defined(NDEBUG) || defined(SQLITE_COVERAGE_TEST) */
31965
+
3171331966
/*
3171431967
** Parameter zMaster is the name of a master journal file. A single journal
3171531968
** file that referred to the master journal file has just been rolled back.
3171631969
** This routine checks if it is possible to delete the master journal file,
3171731970
** and does so if it is.
@@ -31815,17 +32068,16 @@
3181532068
sqlite3_free(pMaster);
3181632069
return rc;
3181732070
}
3181832071
3181932072
31820
-static void pager_truncate_cache(Pager *pPager);
31821
-
3182232073
/*
31823
-** Truncate the main file of the given pager to the number of pages
31824
-** indicated. Also truncate the cached representation of the file.
32074
+** If the main database file is open and an exclusive lock is held,
32075
+** truncate the main file of the given pager to the specified number
32076
+** of pages.
3182532077
**
31826
-** Might might be the case that the file on disk is smaller than nPage.
32078
+** It might might be the case that the file on disk is smaller than nPage.
3182732079
** This can happen, for example, if we are in the middle of a transaction
3182832080
** which has extended the file size and the new pages are still all held
3182932081
** in cache, then an INSERT or UPDATE does a statement rollback. Some
3183032082
** operating system implementations can get confused if you try to
3183132083
** truncate a file to some size that is larger than it currently is,
@@ -31842,16 +32094,15 @@
3184232094
if( currentSize>newSize ){
3184332095
rc = sqlite3OsTruncate(pPager->fd, newSize);
3184432096
}else{
3184532097
rc = sqlite3OsWrite(pPager->fd, "", 1, newSize-1);
3184632098
}
32099
+ if( rc==SQLITE_OK ){
32100
+ pPager->dbFileSize = nPage;
32101
+ }
3184732102
}
3184832103
}
31849
- if( rc==SQLITE_OK ){
31850
- pPager->dbSize = nPage;
31851
- pager_truncate_cache(pPager);
31852
- }
3185332104
return rc;
3185432105
}
3185532106
3185632107
/*
3185732108
** Set the sectorSize for the given pager.
@@ -31996,11 +32247,22 @@
3199632247
** that this part of the journal was being filled but has not yet been
3199732248
** synced to disk. Compute the number of pages based on the remaining
3199832249
** size of the file.
3199932250
**
3200032251
** The third term of the test was added to fix ticket #2565.
32252
+ ** When rolling back a hot journal, nRec==0 always means that the next
32253
+ ** chunk of the journal contains zero pages to be rolled back. But
32254
+ ** when doing a ROLLBACK and the nRec==0 chunk is the last chunk in
32255
+ ** the journal, it means that the journal might contain additional
32256
+ ** pages that need to be rolled back and that the number of pages
32257
+ ** should be computed based on the journal file size.
3200132258
*/
32259
+ testcase( nRec==0 && !isHot
32260
+ && pPager->journalHdr+JOURNAL_HDR_SZ(pPager)!=pPager->journalOff
32261
+ && ((szJ - pPager->journalOff) / JOURNAL_PG_SZ(pPager))>0
32262
+ && pagerNextJournalPageIsValid(pPager)
32263
+ );
3200232264
if( nRec==0 && !isHot &&
3200332265
pPager->journalHdr+JOURNAL_HDR_SZ(pPager)==pPager->journalOff ){
3200432266
nRec = (int)((szJ - pPager->journalOff) / JOURNAL_PG_SZ(pPager));
3200532267
}
3200632268
@@ -32010,16 +32272,17 @@
3201032272
if( pPager->journalOff==JOURNAL_HDR_SZ(pPager) ){
3201132273
rc = pager_truncate(pPager, mxPg);
3201232274
if( rc!=SQLITE_OK ){
3201332275
goto end_playback;
3201432276
}
32277
+ pPager->dbSize = mxPg;
3201532278
}
3201632279
3201732280
/* Copy original pages out of the journal and back into the database file.
3201832281
*/
3201932282
for(u=0; u<nRec; u++){
32020
- rc = pager_playback_one_page(pPager, pPager->jfd, pPager->journalOff, 1);
32283
+ rc = pager_playback_one_page(pPager, 1, &pPager->journalOff, 0, 0);
3202132284
if( rc!=SQLITE_OK ){
3202232285
if( rc==SQLITE_DONE ){
3202332286
rc = SQLITE_OK;
3202432287
pPager->journalOff = szJ;
3202532288
break;
@@ -32059,105 +32322,111 @@
3205932322
setSectorSize(pPager);
3206032323
return rc;
3206132324
}
3206232325
3206332326
/*
32064
-** Playback the statement journal.
32065
-**
32066
-** This is similar to playing back the transaction journal but with
32067
-** a few extra twists.
32068
-**
32069
-** (1) The number of pages in the database file at the start of
32070
-** the statement is stored in pPager->stmtSize, not in the
32071
-** journal file itself.
32072
-**
32073
-** (2) In addition to playing back the statement journal, also
32074
-** playback all pages of the transaction journal beginning
32075
-** at offset pPager->stmtJSize.
32076
-*/
32077
-static int pager_stmt_playback(Pager *pPager){
32078
- i64 szJ; /* Size of the full journal */
32079
- i64 hdrOff;
32080
- int nRec; /* Number of Records */
32081
- int i; /* Loop counter */
32082
- int rc;
32083
-
32084
- szJ = pPager->journalOff;
32085
-
32086
- /* Set hdrOff to be the offset just after the end of the last journal
32087
- ** page written before the first journal-header for this statement
32088
- ** transaction was written, or the end of the file if no journal
32089
- ** header was written.
32090
- */
32091
- hdrOff = pPager->stmtHdrOff;
32092
- assert( pPager->fullSync || !hdrOff );
32093
- if( !hdrOff ){
32094
- hdrOff = szJ;
32095
- }
32096
-
32097
- /* Truncate the database back to its original size.
32098
- */
32099
- rc = pager_truncate(pPager, pPager->stmtSize);
32327
+** Playback savepoint pSavepoint. Or, if pSavepoint==NULL, then playback
32328
+** the entire master journal file.
32329
+**
32330
+** The case pSavepoint==NULL occurs when a ROLLBACK TO command is invoked
32331
+** on a SAVEPOINT that is a transaction savepoint.
32332
+*/
32333
+static int pagerPlaybackSavepoint(Pager *pPager, PagerSavepoint *pSavepoint){
32334
+ i64 szJ; /* Effective size of the main journal */
32335
+ i64 iHdrOff; /* End of first segment of main-journal records */
32336
+ Pgno ii; /* Loop counter */
32337
+ int rc = SQLITE_OK; /* Return code */
32338
+ Bitvec *pDone = 0; /* Bitvec to ensure pages played back only once */
32339
+
32340
+ /* Allocate a bitvec to use to store the set of pages rolled back */
32341
+ if( pSavepoint ){
32342
+ pDone = sqlite3BitvecCreate(pSavepoint->nOrig);
32343
+ if( !pDone ){
32344
+ return SQLITE_NOMEM;
32345
+ }
32346
+ }
32347
+
32348
+ /* Truncate the database back to the size it was before the
32349
+ ** savepoint being reverted was opened.
32350
+ */
32351
+ pPager->dbSize = pSavepoint ? pSavepoint->nOrig : pPager->dbOrigSize;
3210032352
assert( pPager->state>=PAGER_SHARED );
3210132353
32102
- /* Figure out how many records are in the statement journal.
32103
- */
32104
- assert( pPager->stmtInUse && pPager->journalOpen );
32105
- nRec = pPager->stmtNRec;
32106
-
32107
- /* Copy original pages out of the statement journal and back into the
32108
- ** database file. Note that the statement journal omits checksums from
32109
- ** each record since power-failure recovery is not important to statement
32110
- ** journals.
32111
- */
32112
- for(i=0; i<nRec; i++){
32113
- i64 offset = i*(4+pPager->pageSize);
32114
- rc = pager_playback_one_page(pPager, pPager->stfd, offset, 0);
32115
- assert( rc!=SQLITE_DONE );
32116
- if( rc!=SQLITE_OK ) goto end_stmt_playback;
32117
- }
32118
-
32119
- /* Now roll some pages back from the transaction journal. Pager.stmtJSize
32120
- ** was the size of the journal file when this statement was started, so
32121
- ** everything after that needs to be rolled back, either into the
32122
- ** database, the memory cache, or both.
32123
- **
32124
- ** If it is not zero, then Pager.stmtHdrOff is the offset to the start
32125
- ** of the first journal header written during this statement transaction.
32126
- */
32127
- pPager->journalOff = pPager->stmtJSize;
32128
- pPager->cksumInit = (int)(pPager->stmtCksum & 0xffffffff);
32129
- while( pPager->journalOff < hdrOff ){
32130
- rc = pager_playback_one_page(pPager, pPager->jfd, pPager->journalOff, 1);
32131
- assert( rc!=SQLITE_DONE );
32132
- if( rc!=SQLITE_OK ) goto end_stmt_playback;
32133
- }
32134
-
32135
- while( pPager->journalOff < szJ ){
32136
- u32 nJRec; /* Number of Journal Records */
32354
+ /* Use pPager->journalOff as the effective size of the main rollback
32355
+ ** journal. The actual file might be larger than this in
32356
+ ** PAGER_JOURNALMODE_TRUNCATE or PAGER_JOURNALMODE_PERSIST. But anything
32357
+ ** past pPager->journalOff is off-limits to us.
32358
+ */
32359
+ szJ = pPager->journalOff;
32360
+
32361
+ /* Begin by rolling back records from the main journal starting at
32362
+ ** PagerSavepoint.iOffset and continuing to the next journal header.
32363
+ ** There might be records in the main journal that have a page number
32364
+ ** greater than the current database size (pPager->dbSize) but those
32365
+ ** will be skipped automatically. Pages are added to pDone as they
32366
+ ** are played back.
32367
+ */
32368
+ if( pSavepoint ){
32369
+ iHdrOff = pSavepoint->iHdrOffset ? pSavepoint->iHdrOffset : szJ;
32370
+ pPager->journalOff = pSavepoint->iOffset;
32371
+ while( rc==SQLITE_OK && pPager->journalOff<iHdrOff ){
32372
+ rc = pager_playback_one_page(pPager, 1, &pPager->journalOff, 1, pDone);
32373
+ assert( rc!=SQLITE_DONE );
32374
+ }
32375
+ }else{
32376
+ pPager->journalOff = 0;
32377
+ }
32378
+
32379
+ /* Continue rolling back records out of the main journal starting at
32380
+ ** the first journal header seen and continuing until the effective end
32381
+ ** of the main journal file. Continue to skip out-of-range pages and
32382
+ ** continue adding pages rolled back to pDone.
32383
+ */
32384
+ while( rc==SQLITE_OK && pPager->journalOff<szJ ){
32385
+ u32 nJRec = 0; /* Number of Journal Records */
3213732386
u32 dummy;
3213832387
rc = readJournalHdr(pPager, szJ, &nJRec, &dummy);
32139
- if( rc!=SQLITE_OK ){
32140
- assert( rc!=SQLITE_DONE );
32141
- goto end_stmt_playback;
32142
- }
32143
- if( nJRec==0 ){
32144
- nJRec = (int)((szJ - pPager->journalOff) / (pPager->pageSize+8));
32145
- }
32146
- for(i=nJRec-1; i>=0 && pPager->journalOff < szJ; i--){
32147
- rc = pager_playback_one_page(pPager, pPager->jfd, pPager->journalOff, 1);
32148
- assert( rc!=SQLITE_DONE );
32149
- if( rc!=SQLITE_OK ) goto end_stmt_playback;
32150
- }
32151
- }
32152
-
32153
- pPager->journalOff = szJ;
32154
-
32155
-end_stmt_playback:
32156
- if( rc==SQLITE_OK) {
32157
- pPager->journalOff = szJ;
32158
- /* pager_reload_cache(pPager); */
32388
+ assert( rc!=SQLITE_DONE );
32389
+
32390
+ /*
32391
+ ** The "pPager->journalHdr+JOURNAL_HDR_SZ(pPager)==pPager->journalOff"
32392
+ ** test is related to ticket #2565. See the discussion in the
32393
+ ** pager_playback() function for additional information.
32394
+ */
32395
+ assert( !(nJRec==0
32396
+ && pPager->journalHdr+JOURNAL_HDR_SZ(pPager)!=pPager->journalOff
32397
+ && ((szJ - pPager->journalOff) / JOURNAL_PG_SZ(pPager))>0
32398
+ && pagerNextJournalPageIsValid(pPager))
32399
+ );
32400
+ if( nJRec==0
32401
+ && pPager->journalHdr+JOURNAL_HDR_SZ(pPager)==pPager->journalOff
32402
+ ){
32403
+ nJRec = (szJ - pPager->journalOff)/JOURNAL_PG_SZ(pPager);
32404
+ }
32405
+ for(ii=0; rc==SQLITE_OK && ii<nJRec && pPager->journalOff<szJ; ii++){
32406
+ rc = pager_playback_one_page(pPager, 1, &pPager->journalOff, 1, pDone);
32407
+ assert( rc!=SQLITE_DONE );
32408
+ }
32409
+ }
32410
+ assert( rc!=SQLITE_OK || pPager->journalOff==szJ );
32411
+
32412
+ /* Finally, rollback pages from the sub-journal. Page that were
32413
+ ** previously rolled back out of the main journal (and are hence in pDone)
32414
+ ** will be skipped. Out-of-range pages are also skipped.
32415
+ */
32416
+ if( pSavepoint ){
32417
+ i64 offset = pSavepoint->iSubRec*(4+pPager->pageSize);
32418
+ for(ii=pSavepoint->iSubRec; rc==SQLITE_OK&&ii<(u32)pPager->stmtNRec; ii++){
32419
+ assert( offset == ii*(4+pPager->pageSize) );
32420
+ rc = pager_playback_one_page(pPager, 0, &offset, 1, pDone);
32421
+ assert( rc!=SQLITE_DONE );
32422
+ }
32423
+ }
32424
+
32425
+ sqlite3BitvecDestroy(pDone);
32426
+ if( rc==SQLITE_OK ){
32427
+ pPager->journalOff = szJ;
3215932428
}
3216032429
return rc;
3216132430
}
3216232431
3216332432
/*
@@ -32325,11 +32594,11 @@
3232532594
}
3232632595
pPager->pPCache = (PCache *)&pPager[1];
3232732596
pPtr = ((u8 *)&pPager[1]) + pcacheSize;
3232832597
pPager->vfsFlags = vfsFlags;
3232932598
pPager->fd = (sqlite3_file*)&pPtr[pVfs->szOsFile*0];
32330
- pPager->stfd = (sqlite3_file*)&pPtr[pVfs->szOsFile];
32599
+ pPager->sjfd = (sqlite3_file*)&pPtr[pVfs->szOsFile];
3233132600
pPager->jfd = (sqlite3_file*)&pPtr[pVfs->szOsFile+journalFileSize];
3233232601
pPager->zFilename = (char*)&pPtr[pVfs->szOsFile+2*journalFileSize];
3233332602
pPager->zDirectory = &pPager->zFilename[nPathname+1];
3233432603
pPager->zJournal = &pPager->zDirectory[nPathname+1];
3233532604
pPager->pVfs = pVfs;
@@ -32408,11 +32677,11 @@
3240832677
}
3240932678
nExtra = FORCE_ALIGNMENT(nExtra);
3241032679
sqlite3PcacheOpen(szPageDflt, nExtra, !memDb,
3241132680
!memDb?pagerStress:0, (void *)pPager, pPager->pPCache);
3241232681
32413
- PAGERTRACE3("OPEN %d %s\n", FILEHANDLEID(pPager->fd), pPager->zFilename);
32682
+ PAGERTRACE(("OPEN %d %s\n", FILEHANDLEID(pPager->fd), pPager->zFilename));
3241432683
IOTRACE(("OPEN %p %s\n", pPager, pPager->zFilename))
3241532684
3241632685
/* Fill in Pager.zDirectory[] */
3241732686
memcpy(pPager->zDirectory, pPager->zFilename, nPathname+1);
3241832687
for(i=sqlite3Strlen30(pPager->zDirectory);
@@ -32630,11 +32899,12 @@
3263032899
n = 1;
3263132900
}else{
3263232901
n /= pPager->pageSize;
3263332902
}
3263432903
if( pPager->state!=PAGER_UNLOCK ){
32635
- pPager->dbSize = (int)n;
32904
+ pPager->dbSize = (Pgno)n;
32905
+ pPager->dbFileSize = (Pgno)n;
3263632906
pPager->dbSizeValid = 1;
3263732907
}
3263832908
}
3263932909
if( n==(PENDING_BYTE/pPager->pageSize) ){
3264032910
n++;
@@ -32651,26 +32921,10 @@
3265132921
/*
3265232922
** Forward declaration
3265332923
*/
3265432924
static int syncJournal(Pager*);
3265532925
32656
-/*
32657
-** This routine is used to truncate the cache when a database
32658
-** is truncated. Drop from the cache all pages whose pgno is
32659
-** larger than pPager->dbSize and is unreferenced.
32660
-**
32661
-** Referenced pages larger than pPager->dbSize are zeroed.
32662
-**
32663
-** Actually, at the point this routine is called, it would be
32664
-** an error to have a referenced page. But rather than delete
32665
-** that page and guarantee a subsequent segfault, it seems better
32666
-** to zero it and hope that we error out sanely.
32667
-*/
32668
-static void pager_truncate_cache(Pager *pPager){
32669
- sqlite3PcacheTruncate(pPager->pPCache, pPager->dbSize);
32670
-}
32671
-
3267232926
/*
3267332927
** Try to obtain a lock on a file. Invoke the busy callback if the lock
3267432928
** is currently not available. Repeat until the busy callback returns
3267532929
** false or until the lock succeeds.
3267632930
**
@@ -32700,33 +32954,38 @@
3270032954
}
3270132955
}
3270232956
return rc;
3270332957
}
3270432958
32959
+#ifndef SQLITE_OMIT_AUTOVACUUM
3270532960
/*
32706
-** Truncate the file to the number of pages specified.
32961
+** Truncate the in-memory database file image to nPage pages. This
32962
+** function does not actually modify the database file on disk. It
32963
+** just sets the internal state of the pager object so that the
32964
+** truncation will be done when the current transaction is committed.
3270732965
*/
32708
-SQLITE_PRIVATE int sqlite3PagerTruncate(Pager *pPager, Pgno nPage){
32709
- int rc = SQLITE_OK;
32710
- assert( pPager->state>=PAGER_SHARED );
32711
-
32712
- sqlite3PagerPagecount(pPager, 0);
32713
- if( pPager->errCode ){
32714
- rc = pPager->errCode;
32715
- }else if( nPage<pPager->dbSize ){
32716
- rc = syncJournal(pPager);
32717
- if( rc==SQLITE_OK ){
32718
- /* Get an exclusive lock on the database before truncating. */
32719
- rc = pager_wait_on_lock(pPager, EXCLUSIVE_LOCK);
32720
- }
32721
- if( rc==SQLITE_OK ){
32722
- rc = pager_truncate(pPager, nPage);
32723
- }
32724
- }
32725
-
32726
- return rc;
32727
-}
32966
+SQLITE_PRIVATE void sqlite3PagerTruncateImage(Pager *pPager, Pgno nPage){
32967
+ assert( pPager->dbSizeValid );
32968
+ assert( pPager->dbSize>=nPage );
32969
+ pPager->dbSize = nPage;
32970
+}
32971
+
32972
+/*
32973
+** Return the current size of the database file image in pages. This
32974
+** function differs from sqlite3PagerPagecount() in two ways:
32975
+**
32976
+** a) It may only be called when at least one reference to a database
32977
+** page is held. This guarantees that the database size is already
32978
+** known and a call to sqlite3OsFileSize() is not required.
32979
+**
32980
+** b) The return value is not adjusted for the locking page.
32981
+*/
32982
+SQLITE_PRIVATE Pgno sqlite3PagerImageSize(Pager *pPager){
32983
+ assert( pPager->dbSizeValid );
32984
+ return pPager->dbSize;
32985
+}
32986
+#endif /* ifndef SQLITE_OMIT_AUTOVACUUM */
3272832987
3272932988
/*
3273032989
** Shutdown the page cache. Free all memory and close all files.
3273132990
**
3273232991
** If a transaction was in progress when this routine is called, that
@@ -32746,24 +33005,29 @@
3274633005
sqlite3BeginBenignMalloc();
3274733006
pPager->errCode = 0;
3274833007
pPager->exclusiveMode = 0;
3274933008
pager_reset(pPager);
3275033009
if( !MEMDB ){
33010
+ /* Set Pager.journalHdr to -1 for the benefit of the pager_playback()
33011
+ ** call which may be made from within pagerUnlockAndRollback(). If it
33012
+ ** is not -1, then the unsynced portion of an open journal file may
33013
+ ** be played back into the database. If a power failure occurs while
33014
+ ** this is happening, the database may become corrupt.
33015
+ */
33016
+ pPager->journalHdr = -1;
3275133017
pagerUnlockAndRollback(pPager);
3275233018
}
3275333019
enable_simulated_io_errors();
3275433020
sqlite3EndBenignMalloc();
32755
- PAGERTRACE2("CLOSE %d\n", PAGERID(pPager));
33021
+ PAGERTRACE(("CLOSE %d\n", PAGERID(pPager)));
3275633022
IOTRACE(("CLOSE %p\n", pPager))
3275733023
if( pPager->journalOpen ){
3275833024
sqlite3OsClose(pPager->jfd);
3275933025
}
3276033026
sqlite3BitvecDestroy(pPager->pInJournal);
3276133027
sqlite3BitvecDestroy(pPager->pAlwaysRollback);
32762
- if( pPager->stmtOpen ){
32763
- sqlite3OsClose(pPager->stfd);
32764
- }
33028
+ releaseAllSavepoint(pPager);
3276533029
sqlite3OsClose(pPager->fd);
3276633030
/* Temp files are automatically deleted by the OS
3276733031
** if( pPager->tempFile ){
3276833032
** sqlite3OsDelete(pPager->zFilename);
3276933033
** }
@@ -32829,10 +33093,39 @@
3282933093
if( pPager->journalMode!=PAGER_JOURNALMODE_MEMORY ){
3283033094
int iDc = sqlite3OsDeviceCharacteristics(pPager->fd);
3283133095
assert( pPager->journalOpen );
3283233096
3283333097
if( 0==(iDc&SQLITE_IOCAP_SAFE_APPEND) ){
33098
+ i64 jrnlOff = journalHdrOffset(pPager);
33099
+ u8 zMagic[8];
33100
+
33101
+ /* This block deals with an obscure problem. If the last connection
33102
+ ** that wrote to this database was operating in persistent-journal
33103
+ ** mode, then the journal file may at this point actually be larger
33104
+ ** than Pager.journalOff bytes. If the next thing in the journal
33105
+ ** file happens to be a journal-header (written as part of the
33106
+ ** previous connections transaction), and a crash or power-failure
33107
+ ** occurs after nRec is updated but before this connection writes
33108
+ ** anything else to the journal file (or commits/rolls back its
33109
+ ** transaction), then SQLite may become confused when doing the
33110
+ ** hot-journal rollback following recovery. It may roll back all
33111
+ ** of this connections data, then proceed to rolling back the old,
33112
+ ** out-of-date data that follows it. Database corruption.
33113
+ **
33114
+ ** To work around this, if the journal file does appear to contain
33115
+ ** a valid header following Pager.journalOff, then write a 0x00
33116
+ ** byte to the start of it to prevent it from being recognized.
33117
+ */
33118
+ rc = sqlite3OsRead(pPager->jfd, zMagic, 8, jrnlOff);
33119
+ if( rc==SQLITE_OK && 0==memcmp(zMagic, aJournalMagic, 8) ){
33120
+ static const u8 zerobyte = 0;
33121
+ rc = sqlite3OsWrite(pPager->jfd, &zerobyte, 1, jrnlOff);
33122
+ }
33123
+ if( rc!=SQLITE_OK && rc!=SQLITE_IOERR_SHORT_READ ){
33124
+ return rc;
33125
+ }
33126
+
3283433127
/* Write the nRec value into the journal file header. If in
3283533128
** full-synchronous mode, sync the journal first. This ensures that
3283633129
** all data has really hit the disk before nRec is updated to mark
3283733130
** it as a candidate for rollback.
3283833131
**
@@ -32840,13 +33133,12 @@
3284033133
** SAFE_APPEND property. Because in this case it is not possible
3284133134
** for garbage data to be appended to the file, the nRec field
3284233135
** is populated with 0xFFFFFFFF when the journal header is written
3284333136
** and never needs to be updated.
3284433137
*/
32845
- i64 jrnlOff;
3284633138
if( pPager->fullSync && 0==(iDc&SQLITE_IOCAP_SEQUENTIAL) ){
32847
- PAGERTRACE2("SYNC journal of %d\n", PAGERID(pPager));
33139
+ PAGERTRACE(("SYNC journal of %d\n", PAGERID(pPager)));
3284833140
IOTRACE(("JSYNC %p\n", pPager))
3284933141
rc = sqlite3OsSync(pPager->jfd, pPager->sync_flags);
3285033142
if( rc!=0 ) return rc;
3285133143
}
3285233144
@@ -32854,11 +33146,11 @@
3285433146
IOTRACE(("JHDR %p %lld %d\n", pPager, jrnlOff, 4));
3285533147
rc = write32bits(pPager->jfd, jrnlOff, pPager->nRec);
3285633148
if( rc ) return rc;
3285733149
}
3285833150
if( 0==(iDc&SQLITE_IOCAP_SEQUENTIAL) ){
32859
- PAGERTRACE2("SYNC journal of %d\n", PAGERID(pPager));
33151
+ PAGERTRACE(("SYNC journal of %d\n", PAGERID(pPager)));
3286033152
IOTRACE(("JSYNC %p\n", pPager))
3286133153
rc = sqlite3OsSync(pPager->jfd, pPager->sync_flags|
3286233154
(pPager->sync_flags==SQLITE_SYNC_FULL?SQLITE_SYNC_DATAONLY:0)
3286333155
);
3286433156
if( rc!=0 ) return rc;
@@ -32918,30 +33210,34 @@
3291833210
rc = sqlite3PagerOpentemp(pPager, pPager->fd, pPager->vfsFlags);
3291933211
if( rc ) return rc;
3292033212
}
3292133213
3292233214
/* If there are dirty pages in the page cache with page numbers greater
32923
- ** than Pager.dbSize, this means sqlite3PagerTruncate() was called to
33215
+ ** than Pager.dbSize, this means sqlite3PagerTruncateImage() was called to
3292433216
** make the file smaller (presumably by auto-vacuum code). Do not write
3292533217
** any such pages to the file.
3292633218
*/
3292733219
if( pList->pgno<=pPager->dbSize && 0==(pList->flags&PGHDR_DONT_WRITE) ){
3292833220
i64 offset = (pList->pgno-1)*(i64)pPager->pageSize;
3292933221
char *pData = CODEC2(pPager, pList->pData, pList->pgno, 6);
32930
- PAGERTRACE4("STORE %d page %d hash(%08x)\n",
32931
- PAGERID(pPager), pList->pgno, pager_pagehash(pList));
33222
+
33223
+ PAGERTRACE(("STORE %d page %d hash(%08x)\n",
33224
+ PAGERID(pPager), pList->pgno, pager_pagehash(pList)));
3293233225
IOTRACE(("PGOUT %p %d\n", pPager, pList->pgno));
3293333226
rc = sqlite3OsWrite(pPager->fd, pData, pPager->pageSize, offset);
3293433227
PAGER_INCR(sqlite3_pager_writedb_count);
3293533228
PAGER_INCR(pPager->nWrite);
3293633229
if( pList->pgno==1 ){
3293733230
memcpy(&pPager->dbFileVers, &pData[24], sizeof(pPager->dbFileVers));
3293833231
}
33232
+ if( pList->pgno>pPager->dbFileSize ){
33233
+ pPager->dbFileSize = pList->pgno;
33234
+ }
3293933235
}
3294033236
#ifndef NDEBUG
3294133237
else{
32942
- PAGERTRACE3("NOSTORE %d page %d\n", PAGERID(pPager), pList->pgno);
33238
+ PAGERTRACE(("NOSTORE %d page %d\n", PAGERID(pPager), pList->pgno));
3294333239
}
3294433240
#endif
3294533241
if( rc ) return rc;
3294633242
#ifdef SQLITE_CHECK_PAGES
3294733243
pList->pageHash = pager_pagehash(pList);
@@ -32949,10 +33245,38 @@
3294933245
pList = pList->pDirty;
3295033246
}
3295133247
3295233248
return SQLITE_OK;
3295333249
}
33250
+
33251
+/*
33252
+** Add the page to the sub-journal. It is the callers responsibility to
33253
+** use subjRequiresPage() to check that it is really required before
33254
+** calling this function.
33255
+*/
33256
+static int subjournalPage(PgHdr *pPg){
33257
+ int rc;
33258
+ void *pData = pPg->pData;
33259
+ Pager *pPager = pPg->pPager;
33260
+ i64 offset = pPager->stmtNRec*(4+pPager->pageSize);
33261
+ char *pData2 = CODEC2(pPager, pData, pPg->pgno, 7);
33262
+
33263
+ PAGERTRACE(("STMT-JOURNAL %d page %d\n", PAGERID(pPager), pPg->pgno));
33264
+
33265
+ assert( pageInJournal(pPg) || pPg->pgno>pPager->dbOrigSize );
33266
+ rc = write32bits(pPager->sjfd, offset, pPg->pgno);
33267
+ if( rc==SQLITE_OK ){
33268
+ rc = sqlite3OsWrite(pPager->sjfd, pData2, pPager->pageSize, offset+4);
33269
+ }
33270
+ if( rc==SQLITE_OK ){
33271
+ pPager->stmtNRec++;
33272
+ assert( pPager->nSavepoint>0 );
33273
+ rc = addToSavepointBitvecs(pPager, pPg->pgno);
33274
+ }
33275
+ return rc;
33276
+}
33277
+
3295433278
3295533279
/*
3295633280
** This function is called by the pcache layer when it has reached some
3295733281
** soft memory limit. The argument is a pointer to a purgeable Pager
3295833282
** object. This function attempts to make a single dirty page that has no
@@ -32979,18 +33303,24 @@
3297933303
rc = writeJournalHdr(pPager);
3298033304
}
3298133305
}
3298233306
if( rc==SQLITE_OK ){
3298333307
pPg->pDirty = 0;
32984
- rc = pager_write_pagelist(pPg);
33308
+ if( pPg->pgno>pPager->dbSize && subjRequiresPage(pPg) ){
33309
+ rc = subjournalPage(pPg);
33310
+ }
33311
+ if( rc==SQLITE_OK ){
33312
+ rc = pager_write_pagelist(pPg);
33313
+ }
3298533314
}
3298633315
if( rc!=SQLITE_OK ){
3298733316
pager_error(pPager, rc);
3298833317
}
3298933318
}
3299033319
3299133320
if( rc==SQLITE_OK ){
33321
+ PAGERTRACE(("STRESS %d page %d\n", PAGERID(pPager), pPg->pgno));
3299233322
sqlite3PcacheMakeClean(pPg);
3299333323
}
3299433324
return rc;
3299533325
}
3299633326
@@ -33060,12 +33390,12 @@
3306033390
if( pgno==1 ){
3306133391
memcpy(&pPager->dbFileVers, &((u8*)pPg->pData)[24],
3306233392
sizeof(pPager->dbFileVers));
3306333393
}
3306433394
CODEC1(pPager, pPg->pData, pPg->pgno, 3);
33065
- PAGERTRACE4("FETCH %d page %d hash(%08x)\n",
33066
- PAGERID(pPager), pPg->pgno, pager_pagehash(pPg));
33395
+ PAGERTRACE(("FETCH %d page %d hash(%08x)\n",
33396
+ PAGERID(pPager), pPg->pgno, pager_pagehash(pPg)));
3306733397
return rc;
3306833398
}
3306933399
3307033400
3307133401
/*
@@ -33113,12 +33443,14 @@
3311333443
rc = pager_wait_on_lock(pPager, SHARED_LOCK);
3311433444
if( rc!=SQLITE_OK ){
3311533445
assert( pPager->state==PAGER_UNLOCK );
3311633446
return pager_error(pPager, rc);
3311733447
}
33118
- assert( pPager->state>=SHARED_LOCK );
33448
+ }else if( pPager->state==PAGER_UNLOCK ){
33449
+ pPager->state = PAGER_SHARED;
3311933450
}
33451
+ assert( pPager->state>=SHARED_LOCK );
3312033452
3312133453
/* If a journal file exists, and there is no RESERVED lock on the
3312233454
** database file, then it either needs to be played back or deleted.
3312333455
*/
3312433456
if( !isErrorReset ){
@@ -33183,12 +33515,15 @@
3318333515
pPager->journalOff = 0;
3318433516
pPager->setMaster = 0;
3318533517
pPager->journalHdr = 0;
3318633518
3318733519
/* Playback and delete the journal. Drop the database write
33188
- ** lock and reacquire the read lock.
33520
+ ** lock and reacquire the read lock. Purge the cache before
33521
+ ** playing back the hot-journal so that we don't end up with
33522
+ ** an inconsistent cache.
3318933523
*/
33524
+ sqlite3PcacheClear(pPager->pPCache);
3319033525
rc = pager_playback(pPager, 1);
3319133526
if( rc!=SQLITE_OK ){
3319233527
rc = pager_error(pPager, rc);
3319333528
goto failed;
3319433529
}
@@ -33235,14 +33570,11 @@
3323533570
3323633571
if( memcmp(pPager->dbFileVers, dbFileVers, sizeof(dbFileVers))!=0 ){
3323733572
pager_reset(pPager);
3323833573
}
3323933574
}
33240
- assert( pPager->exclusiveMode || pPager->state<=PAGER_SHARED );
33241
- if( pPager->state==PAGER_UNLOCK ){
33242
- pPager->state = PAGER_SHARED;
33243
- }
33575
+ assert( pPager->exclusiveMode || pPager->state==PAGER_SHARED );
3324433576
}
3324533577
3324633578
failed:
3324733579
if( rc!=SQLITE_OK ){
3324833580
/* pager_unlock() is a no-op for exclusive mode and in-memory databases. */
@@ -33458,10 +33790,31 @@
3345833790
sqlite3PcacheRelease(pPg);
3345933791
pagerUnlockIfUnused(pPager);
3346033792
}
3346133793
return SQLITE_OK;
3346233794
}
33795
+
33796
+/*
33797
+** If the main journal file has already been opened, ensure that the
33798
+** sub-journal file is open too. If the main journal is not open,
33799
+** this function is a no-op.
33800
+**
33801
+** SQLITE_OK is returned if everything goes according to plan. An
33802
+** SQLITE_IOERR_XXX error code is returned if the call to
33803
+** sqlite3OsOpen() fails.
33804
+*/
33805
+static int openSubJournal(Pager *pPager){
33806
+ int rc = SQLITE_OK;
33807
+ if( pPager->journalOpen && !pPager->sjfd->pMethods ){
33808
+ if( pPager->journalMode==PAGER_JOURNALMODE_MEMORY ){
33809
+ sqlite3MemJournalOpen(pPager->sjfd);
33810
+ }else{
33811
+ rc = sqlite3PagerOpentemp(pPager, pPager->sjfd, SQLITE_OPEN_SUBJOURNAL);
33812
+ }
33813
+ }
33814
+ return rc;
33815
+}
3346333816
3346433817
/*
3346533818
** Create a journal file for pPager. There should already be a RESERVED
3346633819
** or EXCLUSIVE lock on the database file when this routine is called.
3346733820
**
@@ -33518,16 +33871,16 @@
3351833871
pPager->nRec = 0;
3351933872
if( pPager->errCode ){
3352033873
rc = pPager->errCode;
3352133874
goto failed_to_open_journal;
3352233875
}
33523
- pPager->origDbSize = pPager->dbSize;
33876
+ pPager->dbOrigSize = pPager->dbSize;
3352433877
3352533878
rc = writeJournalHdr(pPager);
3352633879
33527
- if( pPager->stmtAutoopen && rc==SQLITE_OK ){
33528
- rc = sqlite3PagerStmtBegin(pPager);
33880
+ if( pPager->nSavepoint && rc==SQLITE_OK ){
33881
+ rc = openSubJournal(pPager);
3352933882
}
3353033883
if( rc!=SQLITE_OK && rc!=SQLITE_NOMEM && rc!=SQLITE_IOERR_NOMEM ){
3353133884
rc = pager_end_transaction(pPager, 0);
3353233885
if( rc==SQLITE_OK ){
3353333886
rc = SQLITE_FULL;
@@ -33585,11 +33938,11 @@
3358533938
}
3358633939
if( rc!=SQLITE_OK ){
3358733940
return rc;
3358833941
}
3358933942
pPager->dirtyCache = 0;
33590
- PAGERTRACE2("TRANSACTION %d\n", PAGERID(pPager));
33943
+ PAGERTRACE(("TRANSACTION %d\n", PAGERID(pPager)));
3359133944
if( pPager->useJournal && !pPager->tempFile
3359233945
&& pPager->journalMode!=PAGER_JOURNALMODE_OFF ){
3359333946
rc = pager_open_journal(pPager);
3359433947
}
3359533948
}else if( pPager->journalOpen && pPager->journalOff==0 ){
@@ -33598,18 +33951,18 @@
3359833951
** by this connection. Instead of deleting the journal file it was
3359933952
** kept open and either was truncated to 0 bytes or its header was
3360033953
** overwritten with zeros.
3360133954
*/
3360233955
assert( pPager->nRec==0 );
33603
- assert( pPager->origDbSize==0 );
33956
+ assert( pPager->dbOrigSize==0 );
3360433957
assert( pPager->pInJournal==0 );
3360533958
sqlite3PagerPagecount(pPager, 0);
3360633959
pPager->pInJournal = sqlite3BitvecCreate( pPager->dbSize );
3360733960
if( !pPager->pInJournal ){
3360833961
rc = SQLITE_NOMEM;
3360933962
}else{
33610
- pPager->origDbSize = pPager->dbSize;
33963
+ pPager->dbOrigSize = pPager->dbSize;
3361133964
rc = writeJournalHdr(pPager);
3361233965
}
3361333966
}
3361433967
assert( !pPager->journalOpen || pPager->journalOff>0 || rc!=SQLITE_OK );
3361533968
return rc;
@@ -33665,11 +34018,11 @@
3366534018
3366634019
/* Mark the page as dirty. If the page has already been written
3366734020
** to the journal then we can return right away.
3366834021
*/
3366934022
sqlite3PcacheMakeDirty(pPg);
33670
- if( pageInJournal(pPg) && (pageInStatement(pPg) || pPager->stmtInUse==0) ){
34023
+ if( pageInJournal(pPg) && !subjRequiresPage(pPg) ){
3367134024
pPager->dirtyCache = 1;
3367234025
pPager->dbModified = 1;
3367334026
}else{
3367434027
3367534028
/* If we get this far, it means that the page needs to be
@@ -33696,11 +34049,11 @@
3369634049
/* The transaction journal now exists and we have a RESERVED or an
3369734050
** EXCLUSIVE lock on the main database file. Write the current page to
3369834051
** the transaction journal if it is not there already.
3369934052
*/
3370034053
if( !pageInJournal(pPg) && pPager->journalOpen ){
33701
- if( pPg->pgno<=pPager->origDbSize ){
34054
+ if( pPg->pgno<=pPager->dbOrigSize ){
3370234055
u32 cksum;
3370334056
char *pData2;
3370434057
3370534058
/* We should never write to the journal file the page that
3370634059
** contains the database locks. The following assert verifies
@@ -33719,13 +34072,25 @@
3371934072
pPager->journalOff += 4;
3372034073
}
3372134074
IOTRACE(("JOUT %p %d %lld %d\n", pPager, pPg->pgno,
3372234075
pPager->journalOff, pPager->pageSize));
3372334076
PAGER_INCR(sqlite3_pager_writej_count);
33724
- PAGERTRACE5("JOURNAL %d page %d needSync=%d hash(%08x)\n",
34077
+ PAGERTRACE(("JOURNAL %d page %d needSync=%d hash(%08x)\n",
3372534078
PAGERID(pPager), pPg->pgno,
33726
- ((pPg->flags&PGHDR_NEED_SYNC)?1:0), pager_pagehash(pPg));
34079
+ ((pPg->flags&PGHDR_NEED_SYNC)?1:0), pager_pagehash(pPg)));
34080
+
34081
+ /* Even if an IO or diskfull error occurred while journalling the
34082
+ ** page in the block above, set the need-sync flag for the page.
34083
+ ** Otherwise, when the transaction is rolled back, the logic in
34084
+ ** playback_one_page() will think that the page needs to be restored
34085
+ ** in the database file. And if an IO error occurs while doing so,
34086
+ ** then corruption may follow.
34087
+ */
34088
+ if( !pPager->noSync ){
34089
+ pPg->flags |= PGHDR_NEED_SYNC;
34090
+ pPager->needSync = 1;
34091
+ }
3372734092
3372834093
/* An error has occured writing to the journal file. The
3372934094
** transaction will be rolled back by the layer above.
3373034095
*/
3373134096
if( rc!=SQLITE_OK ){
@@ -33732,53 +34097,36 @@
3373234097
return rc;
3373334098
}
3373434099
3373534100
pPager->nRec++;
3373634101
assert( pPager->pInJournal!=0 );
33737
- sqlite3BitvecSet(pPager->pInJournal, pPg->pgno);
33738
- if( !pPager->noSync ){
33739
- pPg->flags |= PGHDR_NEED_SYNC;
33740
- }
33741
- if( pPager->stmtInUse ){
33742
- sqlite3BitvecSet(pPager->pInStmt, pPg->pgno);
34102
+ rc = sqlite3BitvecSet(pPager->pInJournal, pPg->pgno);
34103
+ testcase( rc==SQLITE_NOMEM );
34104
+ assert( rc==SQLITE_OK || rc==SQLITE_NOMEM );
34105
+ rc |= addToSavepointBitvecs(pPager, pPg->pgno);
34106
+ if( rc!=SQLITE_OK ){
34107
+ assert( rc==SQLITE_NOMEM );
34108
+ return rc;
3374334109
}
3374434110
}else{
3374534111
if( !pPager->journalStarted && !pPager->noSync ){
3374634112
pPg->flags |= PGHDR_NEED_SYNC;
34113
+ pPager->needSync = 1;
3374734114
}
33748
- PAGERTRACE4("APPEND %d page %d needSync=%d\n",
34115
+ PAGERTRACE(("APPEND %d page %d needSync=%d\n",
3374934116
PAGERID(pPager), pPg->pgno,
33750
- ((pPg->flags&PGHDR_NEED_SYNC)?1:0));
33751
- }
33752
- if( pPg->flags&PGHDR_NEED_SYNC ){
33753
- pPager->needSync = 1;
34117
+ ((pPg->flags&PGHDR_NEED_SYNC)?1:0)));
3375434118
}
3375534119
}
3375634120
3375734121
/* If the statement journal is open and the page is not in it,
3375834122
** then write the current page to the statement journal. Note that
3375934123
** the statement journal format differs from the standard journal format
3376034124
** in that it omits the checksums and the header.
3376134125
*/
33762
- if( pPager->stmtInUse
33763
- && !pageInStatement(pPg)
33764
- && pPg->pgno<=pPager->stmtSize
33765
- ){
33766
- i64 offset = pPager->stmtNRec*(4+pPager->pageSize);
33767
- char *pData2 = CODEC2(pPager, pData, pPg->pgno, 7);
33768
- assert( pageInJournal(pPg) || pPg->pgno>pPager->origDbSize );
33769
- rc = write32bits(pPager->stfd, offset, pPg->pgno);
33770
- if( rc==SQLITE_OK ){
33771
- rc = sqlite3OsWrite(pPager->stfd, pData2, pPager->pageSize, offset+4);
33772
- }
33773
- PAGERTRACE3("STMT-JOURNAL %d page %d\n", PAGERID(pPager), pPg->pgno);
33774
- if( rc!=SQLITE_OK ){
33775
- return rc;
33776
- }
33777
- pPager->stmtNRec++;
33778
- assert( pPager->pInStmt!=0 );
33779
- sqlite3BitvecSet(pPager->pInStmt, pPg->pgno);
34126
+ if( subjRequiresPage(pPg) ){
34127
+ rc = subjournalPage(pPg);
3378034128
}
3378134129
}
3378234130
3378334131
/* Update the database size and return.
3378434132
*/
@@ -33849,10 +34197,11 @@
3384934197
rc = sqlite3PagerGet(pPager, pg, &pPage);
3385034198
if( rc==SQLITE_OK ){
3385134199
rc = pager_write(pPage);
3385234200
if( pPage->flags&PGHDR_NEED_SYNC ){
3385334201
needSync = 1;
34202
+ assert(pPager->needSync);
3385434203
}
3385534204
sqlite3PagerUnref(pPage);
3385634205
}
3385734206
}
3385834207
}else if( (pPage = pager_lookup(pPager, pg))!=0 ){
@@ -33861,22 +34210,31 @@
3386134210
}
3386234211
sqlite3PagerUnref(pPage);
3386334212
}
3386434213
}
3386534214
33866
- /* If the PgHdr.needSync flag is set for any of the nPage pages
34215
+ /* If the PGHDR_NEED_SYNC flag is set for any of the nPage pages
3386734216
** starting at pg1, then it needs to be set for all of them. Because
3386834217
** writing to any of these nPage pages may damage the others, the
3386934218
** journal file must contain sync()ed copies of all of them
3387034219
** before any of them can be written out to the database file.
34220
+ **
34221
+ ** 2009-01-07: This block of code appears to be a no-op. I do not
34222
+ ** believe it is possible for any page on the sector to not have
34223
+ ** the PGHDR_NEED_SYNC flag set. The "pPage->flags |= PGHDR_NEED_SYNC"
34224
+ ** line below does nothing, I think. But it does no harm to leave
34225
+ ** this code in place until we can definitively prove this is the case.
3387134226
*/
3387234227
if( needSync ){
3387334228
assert( !MEMDB && pPager->noSync==0 );
3387434229
for(ii=0; ii<nPage && needSync; ii++){
3387534230
PgHdr *pPage = pager_lookup(pPager, pg1+ii);
33876
- if( pPage ) pPage->flags |= PGHDR_NEED_SYNC;
33877
- sqlite3PagerUnref(pPage);
34231
+ if( pPage ){
34232
+ assert( pPage->flags & PGHDR_NEED_SYNC ); /* 2009-01-07 conjecture */
34233
+ pPage->flags |= PGHDR_NEED_SYNC;
34234
+ sqlite3PagerUnref(pPage);
34235
+ }
3387834236
}
3387934237
assert(pPager->needSync);
3388034238
}
3388134239
3388234240
assert( pPager->doNotSync==1 );
@@ -33927,35 +34285,35 @@
3392734285
SQLITE_PRIVATE int sqlite3PagerDontWrite(DbPage *pDbPage){
3392834286
PgHdr *pPg = pDbPage;
3392934287
Pager *pPager = pPg->pPager;
3393034288
int rc;
3393134289
33932
- if( pPg->pgno>pPager->origDbSize ){
34290
+ if( pPg->pgno>pPager->dbOrigSize ){
3393334291
return SQLITE_OK;
3393434292
}
3393534293
if( pPager->pAlwaysRollback==0 ){
3393634294
assert( pPager->pInJournal );
33937
- pPager->pAlwaysRollback = sqlite3BitvecCreate(pPager->origDbSize);
34295
+ pPager->pAlwaysRollback = sqlite3BitvecCreate(pPager->dbOrigSize);
3393834296
if( !pPager->pAlwaysRollback ){
3393934297
return SQLITE_NOMEM;
3394034298
}
3394134299
}
3394234300
rc = sqlite3BitvecSet(pPager->pAlwaysRollback, pPg->pgno);
3394334301
33944
- if( rc==SQLITE_OK && (pPg->flags&PGHDR_DIRTY) && !pPager->stmtInUse ){
34302
+ if( rc==SQLITE_OK && (pPg->flags&PGHDR_DIRTY) && pPager->nSavepoint==0 ){
3394534303
assert( pPager->state>=PAGER_SHARED );
33946
- if( pPager->dbSize==pPg->pgno && pPager->origDbSize<pPager->dbSize ){
34304
+ if( pPager->dbSize==pPg->pgno && pPager->dbOrigSize<pPager->dbSize ){
3394734305
/* If this pages is the last page in the file and the file has grown
3394834306
** during the current transaction, then do NOT mark the page as clean.
3394934307
** When the database file grows, we must make sure that the last page
3395034308
** gets written at least once so that the disk file will be the correct
3395134309
** size. If you do not write this page and the size of the file
3395234310
** on the disk ends up being too small, that can lead to database
3395334311
** corruption during the next transaction.
3395434312
*/
3395534313
}else{
33956
- PAGERTRACE3("DONT_WRITE page %d of %d\n", pPg->pgno, PAGERID(pPager));
34314
+ PAGERTRACE(("DONT_WRITE page %d of %d\n", pPg->pgno, PAGERID(pPager)));
3395734315
IOTRACE(("CLEAN %p %d\n", pPager, pPg->pgno))
3395834316
pPg->flags |= PGHDR_DONT_WRITE;
3395934317
#ifdef SQLITE_CHECK_PAGES
3396034318
pPg->pageHash = pager_pagehash(pPg);
3396134319
#endif
@@ -33975,27 +34333,28 @@
3397534333
** that we will never need to read the page content in the future.
3397634334
** so the needRead flag can be cleared at this point.
3397734335
*/
3397834336
SQLITE_PRIVATE void sqlite3PagerDontRollback(DbPage *pPg){
3397934337
Pager *pPager = pPg->pPager;
34338
+ TESTONLY( int rc; ) /* Return value from sqlite3BitvecSet() */
3398034339
3398134340
assert( pPager->state>=PAGER_RESERVED );
3398234341
3398334342
/* If the journal file is not open, or DontWrite() has been called on
3398434343
** this page (DontWrite() sets the alwaysRollback flag), then this
3398534344
** function is a no-op.
3398634345
*/
3398734346
if( pPager->journalOpen==0
3398834347
|| sqlite3BitvecTest(pPager->pAlwaysRollback, pPg->pgno)
33989
- || pPg->pgno>pPager->origDbSize
34348
+ || pPg->pgno>pPager->dbOrigSize
3399034349
){
3399134350
return;
3399234351
}
3399334352
3399434353
#ifdef SQLITE_SECURE_DELETE
3399534354
if( sqlite3BitvecTest(pPager->pInJournal, pPg->pgno)!=0
33996
- || pPg->pgno>pPager->origDbSize ){
34355
+ || pPg->pgno>pPager->dbOrigSize ){
3399734356
return;
3399834357
}
3399934358
#endif
3400034359
3400134360
/* If SECURE_DELETE is disabled, then there is no way that this
@@ -34006,20 +34365,30 @@
3400634365
**
3400734366
** (Later:) Not true. If the database is corrupted by having duplicate
3400834367
** pages on the freelist (ex: corrupt9.test) then the following is not
3400934368
** necessarily true:
3401034369
*/
34011
- /* assert( !pPg->inJournal && (int)pPg->pgno <= pPager->origDbSize ); */
34370
+ /* assert( !pPg->inJournal && (int)pPg->pgno <= pPager->dbOrigSize ); */
3401234371
3401334372
assert( pPager->pInJournal!=0 );
34014
- sqlite3BitvecSet(pPager->pInJournal, pPg->pgno);
3401534373
pPg->flags &= ~PGHDR_NEED_READ;
34016
- if( pPager->stmtInUse ){
34017
- assert( pPager->stmtSize >= pPager->origDbSize );
34018
- sqlite3BitvecSet(pPager->pInStmt, pPg->pgno);
34019
- }
34020
- PAGERTRACE3("DONT_ROLLBACK page %d of %d\n", pPg->pgno, PAGERID(pPager));
34374
+
34375
+ /* Failure to set the bits in the InJournal bit-vectors is benign.
34376
+ ** It merely means that we might do some extra work to journal a page
34377
+ ** that does not need to be journaled. Nevertheless, be sure to test the
34378
+ ** case where a malloc error occurs while trying to set a bit in a
34379
+ ** bit vector.
34380
+ */
34381
+ sqlite3BeginBenignMalloc();
34382
+ TESTONLY( rc = ) sqlite3BitvecSet(pPager->pInJournal, pPg->pgno);
34383
+ testcase( rc==SQLITE_NOMEM );
34384
+ TESTONLY( rc = ) addToSavepointBitvecs(pPager, pPg->pgno);
34385
+ testcase( rc==SQLITE_NOMEM );
34386
+ sqlite3EndBenignMalloc();
34387
+
34388
+
34389
+ PAGERTRACE(("DONT_ROLLBACK page %d of %d\n", pPg->pgno, PAGERID(pPager)));
3402134390
IOTRACE(("GARBAGE %p %d\n", pPager, pPg->pgno))
3402234391
}
3402334392
3402434393
3402534394
/*
@@ -34032,11 +34401,11 @@
3403234401
int rc = SQLITE_OK;
3403334402
3403434403
#ifndef SQLITE_ENABLE_ATOMIC_WRITE
3403534404
assert( isDirect==0 ); /* isDirect is only true for atomic writes */
3403634405
#endif
34037
- if( !pPager->changeCountDone ){
34406
+ if( !pPager->changeCountDone && pPager->dbSize>0 ){
3403834407
/* Open page 1 of the file for writing. */
3403934408
rc = sqlite3PagerGet(pPager, 1, &pPgHdr);
3404034409
if( rc!=SQLITE_OK ) return rc;
3404134410
3404234411
if( !isDirect ){
@@ -34053,10 +34422,11 @@
3405334422
put32bits(((char*)pPgHdr->pData)+24, change_counter);
3405434423
3405534424
#ifdef SQLITE_ENABLE_ATOMIC_WRITE
3405634425
if( isDirect && pPager->fd->pMethods ){
3405734426
const void *zBuf = pPgHdr->pData;
34427
+ assert( pPager->dbFileSize>0 );
3405834428
rc = sqlite3OsWrite(pPager->fd, zBuf, pPager->pageSize, 0);
3405934429
}
3406034430
#endif
3406134431
3406234432
/* Release the page reference. */
@@ -34091,22 +34461,18 @@
3409134461
** master journal file if specified).
3409234462
**
3409334463
** Note that if zMaster==NULL, this does not overwrite a previous value
3409434464
** passed to an sqlite3PagerCommitPhaseOne() call.
3409534465
**
34096
-** If parameter nTrunc is non-zero, then the pager file is truncated to
34097
-** nTrunc pages (this is used by auto-vacuum databases).
34098
-**
3409934466
** If the final parameter - noSync - is true, then the database file itself
3410034467
** is not synced. The caller must call sqlite3PagerSync() directly to
3410134468
** sync the database file before calling CommitPhaseTwo() to delete the
3410234469
** journal file in this case.
3410334470
*/
3410434471
SQLITE_PRIVATE int sqlite3PagerCommitPhaseOne(
3410534472
Pager *pPager,
3410634473
const char *zMaster,
34107
- Pgno nTrunc,
3410834474
int noSync
3410934475
){
3411034476
int rc = SQLITE_OK;
3411134477
3411234478
if( pPager->errCode ){
@@ -34120,12 +34486,12 @@
3412034486
pPager->exclusiveMode!=0) ){
3412134487
assert( pPager->dirtyCache==0 || pPager->journalOpen==0 );
3412234488
return SQLITE_OK;
3412334489
}
3412434490
34125
- PAGERTRACE4("DATABASE SYNC: File=%s zMaster=%s nTrunc=%d\n",
34126
- pPager->zFilename, zMaster, nTrunc);
34491
+ PAGERTRACE(("DATABASE SYNC: File=%s zMaster=%s nSize=%d\n",
34492
+ pPager->zFilename, zMaster, pPager->dbSize));
3412734493
3412834494
/* If this is an in-memory db, or no pages have been written to, or this
3412934495
** function has already been called, it is a no-op.
3413034496
*/
3413134497
if( pPager->state!=PAGER_SYNCED && !MEMDB && pPager->dirtyCache ){
@@ -34147,11 +34513,11 @@
3414734513
pPg = sqlite3PcacheDirtyList(pPager->pPCache);
3414834514
useAtomicWrite = (
3414934515
!zMaster &&
3415034516
pPager->journalOpen &&
3415134517
pPager->journalOff==jrnlBufferSize(pPager) &&
34152
- nTrunc==0 &&
34518
+ pPager->dbSize>=pPager->dbFileSize &&
3415334519
(pPg==0 || pPg->pDirty==0)
3415434520
);
3415534521
assert( pPager->journalOpen || pPager->journalMode==PAGER_JOURNALMODE_OFF );
3415634522
if( useAtomicWrite ){
3415734523
/* Update the nRec field in the journal file. */
@@ -34184,42 +34550,38 @@
3418434550
if( !pPager->setMaster ){
3418534551
rc = pager_incr_changecounter(pPager, 0);
3418634552
if( rc!=SQLITE_OK ) goto sync_exit;
3418734553
if( pPager->journalMode!=PAGER_JOURNALMODE_OFF ){
3418834554
#ifndef SQLITE_OMIT_AUTOVACUUM
34189
- if( nTrunc!=0 ){
34555
+ if( pPager->dbSize<pPager->dbOrigSize ){
3419034556
/* If this transaction has made the database smaller, then all pages
3419134557
** being discarded by the truncation must be written to the journal
3419234558
** file.
3419334559
*/
3419434560
Pgno i;
3419534561
Pgno iSkip = PAGER_MJ_PGNO(pPager);
34196
- for( i=nTrunc+1; i<=pPager->origDbSize; i++ ){
34562
+ Pgno dbSize = pPager->dbSize;
34563
+ pPager->dbSize = pPager->dbOrigSize;
34564
+ for( i=dbSize+1; i<=pPager->dbOrigSize; i++ ){
3419734565
if( !sqlite3BitvecTest(pPager->pInJournal, i) && i!=iSkip ){
3419834566
rc = sqlite3PagerGet(pPager, i, &pPg);
3419934567
if( rc!=SQLITE_OK ) goto sync_exit;
3420034568
rc = sqlite3PagerWrite(pPg);
3420134569
sqlite3PagerUnref(pPg);
3420234570
if( rc!=SQLITE_OK ) goto sync_exit;
3420334571
}
3420434572
}
34573
+ pPager->dbSize = dbSize;
3420534574
}
3420634575
#endif
3420734576
rc = writeMasterJournal(pPager, zMaster);
3420834577
if( rc!=SQLITE_OK ) goto sync_exit;
3420934578
rc = syncJournal(pPager);
3421034579
}
3421134580
}
3421234581
if( rc!=SQLITE_OK ) goto sync_exit;
3421334582
34214
-#ifndef SQLITE_OMIT_AUTOVACUUM
34215
- if( nTrunc!=0 ){
34216
- rc = sqlite3PagerTruncate(pPager, nTrunc);
34217
- if( rc!=SQLITE_OK ) goto sync_exit;
34218
- }
34219
-#endif
34220
-
3422134583
/* Write all dirty pages to the database file */
3422234584
pPg = sqlite3PcacheDirtyList(pPager->pPCache);
3422334585
rc = pager_write_pagelist(pPg);
3422434586
if( rc!=SQLITE_OK ){
3422534587
assert( rc!=SQLITE_IOERR_BLOCKED );
@@ -34231,20 +34593,24 @@
3423134593
** is made to use an invalid dirty list.
3423234594
*/
3423334595
goto sync_exit;
3423434596
}
3423534597
sqlite3PcacheCleanAll(pPager->pPCache);
34598
+
34599
+ if( pPager->dbSize<pPager->dbFileSize ){
34600
+ assert( pPager->state>=PAGER_EXCLUSIVE );
34601
+ rc = pager_truncate(pPager, pPager->dbSize);
34602
+ if( rc!=SQLITE_OK ) goto sync_exit;
34603
+ }
3423634604
3423734605
/* Sync the database file. */
3423834606
if( !pPager->noSync && !noSync ){
3423934607
rc = sqlite3OsSync(pPager->fd, pPager->sync_flags);
3424034608
}
3424134609
IOTRACE(("DBSYNC %p\n", pPager))
3424234610
3424334611
pPager->state = PAGER_SYNCED;
34244
- }else if( MEMDB && nTrunc!=0 ){
34245
- rc = sqlite3PagerTruncate(pPager, nTrunc);
3424634612
}
3424734613
3424834614
sync_exit:
3424934615
if( rc==SQLITE_IOERR_BLOCKED ){
3425034616
/* pager_incr_changecounter() may attempt to obtain an exclusive
@@ -34278,11 +34644,11 @@
3427834644
(pPager->journalMode!=PAGER_JOURNALMODE_DELETE ||
3427934645
pPager->exclusiveMode!=0) ){
3428034646
assert( pPager->dirtyCache==0 || pPager->journalOpen==0 );
3428134647
return SQLITE_OK;
3428234648
}
34283
- PAGERTRACE2("COMMIT %d\n", PAGERID(pPager));
34649
+ PAGERTRACE(("COMMIT %d\n", PAGERID(pPager)));
3428434650
assert( pPager->state==PAGER_SYNCED || MEMDB || !pPager->dirtyCache );
3428534651
rc = pager_end_transaction(pPager, pPager->setMaster);
3428634652
rc = pager_error(pPager, rc);
3428734653
return rc;
3428834654
}
@@ -34299,11 +34665,11 @@
3429934665
** codes are returned for all these occasions. Otherwise,
3430034666
** SQLITE_OK is returned.
3430134667
*/
3430234668
SQLITE_PRIVATE int sqlite3PagerRollback(Pager *pPager){
3430334669
int rc = SQLITE_OK;
34304
- PAGERTRACE2("ROLLBACK %d\n", PAGERID(pPager));
34670
+ PAGERTRACE(("ROLLBACK %d\n", PAGERID(pPager)));
3430534671
if( !pPager->dirtyCache || !pPager->journalOpen ){
3430634672
rc = pager_end_transaction(pPager, pPager->setMaster);
3430734673
}else if( pPager->errCode && pPager->errCode!=SQLITE_FULL ){
3430834674
if( pPager->state>=PAGER_EXCLUSIVE ){
3430934675
pager_playback(pPager, 0);
@@ -34379,96 +34745,101 @@
3437934745
return MEMDB;
3438034746
}
3438134747
#endif
3438234748
3438334749
/*
34384
-** Set the statement rollback point.
34385
-**
34386
-** This routine should be called with the transaction journal already
34387
-** open. A new statement journal is created that can be used to rollback
34388
-** changes of a single SQL command within a larger transaction.
34389
-*/
34390
-static int pagerStmtBegin(Pager *pPager){
34391
- int rc;
34392
- assert( !pPager->stmtInUse );
34393
- assert( pPager->state>=PAGER_SHARED );
34394
- assert( pPager->dbSizeValid );
34395
- PAGERTRACE2("STMT-BEGIN %d\n", PAGERID(pPager));
34396
- if( !pPager->journalOpen ){
34397
- pPager->stmtAutoopen = 1;
34398
- return SQLITE_OK;
34399
- }
34400
- assert( pPager->journalOpen );
34401
- assert( pPager->pInStmt==0 );
34402
- pPager->pInStmt = sqlite3BitvecCreate(pPager->dbSize);
34403
- if( pPager->pInStmt==0 ){
34404
- /* sqlite3OsLock(pPager->fd, SHARED_LOCK); */
34405
- return SQLITE_NOMEM;
34406
- }
34407
- pPager->stmtJSize = pPager->journalOff;
34408
- pPager->stmtSize = pPager->dbSize;
34409
- pPager->stmtHdrOff = 0;
34410
- pPager->stmtCksum = pPager->cksumInit;
34411
- if( !pPager->stmtOpen ){
34412
- if( pPager->journalMode==PAGER_JOURNALMODE_MEMORY ){
34413
- sqlite3MemJournalOpen(pPager->stfd);
34414
- }else{
34415
- rc = sqlite3PagerOpentemp(pPager, pPager->stfd, SQLITE_OPEN_SUBJOURNAL);
34416
- if( rc ){
34417
- goto stmt_begin_failed;
34418
- }
34419
- }
34420
- pPager->stmtOpen = 1;
34421
- pPager->stmtNRec = 0;
34422
- }
34423
- pPager->stmtInUse = 1;
34424
- return SQLITE_OK;
34425
-
34426
-stmt_begin_failed:
34427
- if( pPager->pInStmt ){
34428
- sqlite3BitvecDestroy(pPager->pInStmt);
34429
- pPager->pInStmt = 0;
34430
- }
34431
- return rc;
34432
-}
34433
-SQLITE_PRIVATE int sqlite3PagerStmtBegin(Pager *pPager){
34434
- int rc;
34435
- rc = pagerStmtBegin(pPager);
34436
- return rc;
34437
-}
34438
-
34439
-/*
34440
-** Commit a statement.
34441
-*/
34442
-SQLITE_PRIVATE int sqlite3PagerStmtCommit(Pager *pPager){
34443
- if( pPager->stmtInUse ){
34444
- PAGERTRACE2("STMT-COMMIT %d\n", PAGERID(pPager));
34445
- sqlite3BitvecDestroy(pPager->pInStmt);
34446
- pPager->pInStmt = 0;
34447
- pPager->stmtNRec = 0;
34448
- pPager->stmtInUse = 0;
34449
- if( sqlite3IsMemJournal(pPager->stfd) ){
34450
- sqlite3OsTruncate(pPager->stfd, 0);
34451
- }
34452
- }
34453
- pPager->stmtAutoopen = 0;
34454
- return SQLITE_OK;
34455
-}
34456
-
34457
-/*
34458
-** Rollback a statement.
34459
-*/
34460
-SQLITE_PRIVATE int sqlite3PagerStmtRollback(Pager *pPager){
34461
- int rc;
34462
- if( pPager->stmtInUse ){
34463
- PAGERTRACE2("STMT-ROLLBACK %d\n", PAGERID(pPager));
34464
- rc = pager_stmt_playback(pPager);
34465
- sqlite3PagerStmtCommit(pPager);
34466
- }else{
34467
- rc = SQLITE_OK;
34468
- }
34469
- pPager->stmtAutoopen = 0;
34750
+** Ensure that there are at least nSavepoint savepoints open.
34751
+*/
34752
+SQLITE_PRIVATE int sqlite3PagerOpenSavepoint(Pager *pPager, int nSavepoint){
34753
+ int rc = SQLITE_OK;
34754
+
34755
+ if( nSavepoint>pPager->nSavepoint && pPager->useJournal ){
34756
+ int ii;
34757
+ PagerSavepoint *aNew;
34758
+
34759
+ /* Either the sub-journal is open or there are no active savepoints. */
34760
+ assert( pPager->nSavepoint==0 || pPager->sjfd->pMethods );
34761
+
34762
+ /* Grow the Pager.aSavepoint array using realloc(). Return SQLITE_NOMEM
34763
+ ** if the allocation fails. Otherwise, zero the new portion in case a
34764
+ ** malloc failure occurs while populating it in the for(...) loop below.
34765
+ */
34766
+ aNew = (PagerSavepoint *)sqlite3Realloc(
34767
+ pPager->aSavepoint, sizeof(PagerSavepoint)*nSavepoint
34768
+ );
34769
+ if( !aNew ){
34770
+ return SQLITE_NOMEM;
34771
+ }
34772
+ memset(&aNew[pPager->nSavepoint], 0,
34773
+ (nSavepoint - pPager->nSavepoint) * sizeof(PagerSavepoint)
34774
+ );
34775
+ pPager->aSavepoint = aNew;
34776
+ ii = pPager->nSavepoint;
34777
+ pPager->nSavepoint = nSavepoint;
34778
+
34779
+ /* Populate the PagerSavepoint structures just allocated. */
34780
+ for(/* no-op */; ii<nSavepoint; ii++){
34781
+ assert( pPager->dbSizeValid );
34782
+ aNew[ii].nOrig = pPager->dbSize;
34783
+ if( pPager->journalOpen && pPager->journalOff>0 ){
34784
+ aNew[ii].iOffset = pPager->journalOff;
34785
+ }else{
34786
+ aNew[ii].iOffset = JOURNAL_HDR_SZ(pPager);
34787
+ }
34788
+ aNew[ii].iSubRec = pPager->stmtNRec;
34789
+ aNew[ii].pInSavepoint = sqlite3BitvecCreate(pPager->dbSize);
34790
+ if( !aNew[ii].pInSavepoint ){
34791
+ return SQLITE_NOMEM;
34792
+ }
34793
+ }
34794
+
34795
+ /* Open the sub-journal, if it is not already opened. */
34796
+ rc = openSubJournal(pPager);
34797
+ }
34798
+
34799
+ return rc;
34800
+}
34801
+
34802
+/*
34803
+** Parameter op is always either SAVEPOINT_ROLLBACK or SAVEPOINT_RELEASE.
34804
+** If it is SAVEPOINT_RELEASE, then release and destroy the savepoint with
34805
+** index iSavepoint. If it is SAVEPOINT_ROLLBACK, then rollback all changes
34806
+** that have occured since savepoint iSavepoint was created.
34807
+**
34808
+** In either case, all savepoints with an index greater than iSavepoint
34809
+** are destroyed.
34810
+**
34811
+** If there are less than (iSavepoint+1) active savepoints when this
34812
+** function is called it is a no-op.
34813
+*/
34814
+SQLITE_PRIVATE int sqlite3PagerSavepoint(Pager *pPager, int op, int iSavepoint){
34815
+ int rc = SQLITE_OK;
34816
+
34817
+ assert( op==SAVEPOINT_RELEASE || op==SAVEPOINT_ROLLBACK );
34818
+
34819
+ if( iSavepoint<pPager->nSavepoint ){
34820
+ int ii;
34821
+ int nNew = iSavepoint + (op==SAVEPOINT_ROLLBACK);
34822
+ for(ii=nNew; ii<pPager->nSavepoint; ii++){
34823
+ sqlite3BitvecDestroy(pPager->aSavepoint[ii].pInSavepoint);
34824
+ }
34825
+ pPager->nSavepoint = nNew;
34826
+
34827
+ if( op==SAVEPOINT_ROLLBACK && pPager->jfd->pMethods ){
34828
+ PagerSavepoint *pSavepoint = (nNew==0)?0:&pPager->aSavepoint[nNew-1];
34829
+ rc = pagerPlaybackSavepoint(pPager, pSavepoint);
34830
+ assert(rc!=SQLITE_DONE);
34831
+ }
34832
+
34833
+ /* If this is a release of the outermost savepoint, truncate
34834
+ ** the sub-journal. */
34835
+ if( nNew==0 && op==SAVEPOINT_RELEASE && pPager->sjfd->pMethods ){
34836
+ assert( rc==SQLITE_OK );
34837
+ rc = sqlite3OsTruncate(pPager->sjfd, 0);
34838
+ pPager->stmtNRec = 0;
34839
+ }
34840
+ }
3447034841
return rc;
3447134842
}
3447234843
3447334844
/*
3447434845
** Return the full pathname of the database file.
@@ -34553,15 +34924,37 @@
3455334924
** pPg refers to will not be written to again within this transaction.
3455434925
*/
3455534926
SQLITE_PRIVATE int sqlite3PagerMovepage(Pager *pPager, DbPage *pPg, Pgno pgno, int isCommit){
3455634927
PgHdr *pPgOld; /* The page being overwritten. */
3455734928
Pgno needSyncPgno = 0;
34929
+ int rc;
3455834930
3455934931
assert( pPg->nRef>0 );
3456034932
34561
- PAGERTRACE5("MOVE %d page %d (needSync=%d) moves to %d\n",
34562
- PAGERID(pPager), pPg->pgno, (pPg->flags&PGHDR_NEED_SYNC)?1:0, pgno);
34933
+ /* If the page being moved is dirty and has not been saved by the latest
34934
+ ** savepoint, then save the current contents of the page into the
34935
+ ** sub-journal now. This is required to handle the following scenario:
34936
+ **
34937
+ ** BEGIN;
34938
+ ** <journal page X, then modify it in memory>
34939
+ ** SAVEPOINT one;
34940
+ ** <Move page X to location Y>
34941
+ ** ROLLBACK TO one;
34942
+ **
34943
+ ** If page X were not written to the sub-journal here, it would not
34944
+ ** be possible to restore its contents when the "ROLLBACK TO one"
34945
+ ** statement were processed.
34946
+ */
34947
+ if( pPg->flags&PGHDR_DIRTY
34948
+ && subjRequiresPage(pPg)
34949
+ && SQLITE_OK!=(rc = subjournalPage(pPg))
34950
+ ){
34951
+ return rc;
34952
+ }
34953
+
34954
+ PAGERTRACE(("MOVE %d page %d (needSync=%d) moves to %d\n",
34955
+ PAGERID(pPager), pPg->pgno, (pPg->flags&PGHDR_NEED_SYNC)?1:0, pgno));
3456334956
IOTRACE(("MOVE %p %d %d\n", pPager, pPg->pgno, pgno))
3456434957
3456534958
pager_get_content(pPg);
3456634959
3456734960
/* If the journal needs to be sync()ed before page pPg->pgno can
@@ -34571,11 +34964,11 @@
3457134964
** the journal needs to be sync()ed before database page pPg->pgno
3457234965
** can be written to. The caller has already promised not to write to it.
3457334966
*/
3457434967
if( (pPg->flags&PGHDR_NEED_SYNC) && !isCommit ){
3457534968
needSyncPgno = pPg->pgno;
34576
- assert( pageInJournal(pPg) || pPg->pgno>pPager->origDbSize );
34969
+ assert( pageInJournal(pPg) || pPg->pgno>pPager->dbOrigSize );
3457734970
assert( pPg->flags&PGHDR_DIRTY );
3457834971
assert( pPager->needSync );
3457934972
}
3458034973
3458134974
/* If the cache contains a page with page-number pgno, remove it
@@ -34615,16 +35008,15 @@
3461535008
** the journal file twice, but that is not a problem.
3461635009
**
3461735010
** The sqlite3PagerGet() call may cause the journal to sync. So make
3461835011
** sure the Pager.needSync flag is set too.
3461935012
*/
34620
- int rc;
3462135013
PgHdr *pPgHdr;
3462235014
assert( pPager->needSync );
3462335015
rc = sqlite3PagerGet(pPager, needSyncPgno, &pPgHdr);
3462435016
if( rc!=SQLITE_OK ){
34625
- if( pPager->pInJournal && needSyncPgno<=pPager->origDbSize ){
35017
+ if( pPager->pInJournal && needSyncPgno<=pPager->dbOrigSize ){
3462635018
sqlite3BitvecClear(pPager->pInJournal, needSyncPgno);
3462735019
}
3462835020
return rc;
3462935021
}
3463035022
pPager->needSync = 1;
@@ -34754,11 +35146,11 @@
3475435146
** May you do good and not evil.
3475535147
** May you find forgiveness for yourself and forgive others.
3475635148
** May you share freely, never taking more than you give.
3475735149
**
3475835150
*************************************************************************
34759
-** $Id: btreeInt.h,v 1.37 2008/12/10 16:45:51 drh Exp $
35151
+** $Id: btreeInt.h,v 1.38 2008/12/27 15:23:13 danielk1977 Exp $
3476035152
**
3476135153
** This file implements a external (disk-based) database using BTrees.
3476235154
** For a detailed discussion of BTrees, refer to
3476335155
**
3476435156
** Donald E. Knuth, THE ART OF COMPUTER PROGRAMMING, Volume 3:
@@ -35111,11 +35503,10 @@
3511135503
u8 readOnly; /* True if the underlying file is readonly */
3511235504
u8 pageSizeFixed; /* True if the page size can no longer be changed */
3511335505
#ifndef SQLITE_OMIT_AUTOVACUUM
3511435506
u8 autoVacuum; /* True if auto-vacuum is enabled */
3511535507
u8 incrVacuum; /* True if incr-vacuum is enabled */
35116
- Pgno nTrunc; /* Non-zero if the db will be truncated (incr vacuum) */
3511735508
#endif
3511835509
u16 pageSize; /* Total number of bytes on a page */
3511935510
u16 usableSize; /* Number of usable bytes on each page */
3512035511
u16 maxLocal; /* Maximum local payload in non-LEAFDATA tables */
3512135512
u16 minLocal; /* Minimum local payload in non-LEAFDATA tables */
@@ -35687,11 +36078,11 @@
3568736078
** May you do good and not evil.
3568836079
** May you find forgiveness for yourself and forgive others.
3568936080
** May you share freely, never taking more than you give.
3569036081
**
3569136082
*************************************************************************
35692
-** $Id: btree.c,v 1.548 2008/12/16 13:46:30 drh Exp $
36083
+** $Id: btree.c,v 1.557 2009/01/09 14:11:05 drh Exp $
3569336084
**
3569436085
** This file implements a external (disk-based) database using BTrees.
3569536086
** See the header comment on "btreeInt.h" for additional information.
3569636087
** Including a description of file format and an overview of operation.
3569736088
*/
@@ -35711,24 +36102,10 @@
3571136102
# define TRACE(X) if(sqlite3BtreeTrace){printf X;fflush(stdout);}
3571236103
#else
3571336104
# define TRACE(X)
3571436105
#endif
3571536106
35716
-/*
35717
-** Sometimes we need a small amount of code such as a variable initialization
35718
-** to setup for a later assert() statement. We do not want this code to
35719
-** appear when assert() is disabled. The following macro is therefore
35720
-** used to contain that setup code. The "VVA" acronym stands for
35721
-** "Verification, Validation, and Accreditation". In other words, the
35722
-** code within VVA_ONLY() will only run during verification processes.
35723
-*/
35724
-#ifndef NDEBUG
35725
-# define VVA_ONLY(X) X
35726
-#else
35727
-# define VVA_ONLY(X)
35728
-#endif
35729
-
3573036107
3573136108
3573236109
#ifndef SQLITE_OMIT_SHARED_CACHE
3573336110
/*
3573436111
** A list of BtShared objects that are eligible for participation
@@ -36858,10 +37235,11 @@
3685837235
** Release a MemPage. This should be called once for each prior
3685937236
** call to sqlite3BtreeGetPage.
3686037237
*/
3686137238
static void releasePage(MemPage *pPage){
3686237239
if( pPage ){
37240
+ assert( pPage->nOverflow==0 || sqlite3PagerPageRefcount(pPage->pDbPage)>1 );
3686337241
assert( pPage->aData );
3686437242
assert( pPage->pBt );
3686537243
assert( sqlite3PagerGetExtra(pPage->pDbPage) == (void*)pPage );
3686637244
assert( sqlite3PagerGetData(pPage->pDbPage)==pPage->aData );
3686737245
assert( sqlite3_mutex_held(pPage->pBt->mutex) );
@@ -37736,10 +38114,18 @@
3773638114
#endif
3773738115
}
3773838116
3773938117
3774038118
trans_begun:
38119
+ if( rc==SQLITE_OK && wrflag ){
38120
+ /* This call makes sure that the pager has the correct number of
38121
+ ** open savepoints. If the second parameter is greater than 0 and
38122
+ ** the sub-journal is not already open, then it will be opened here.
38123
+ */
38124
+ rc = sqlite3PagerOpenSavepoint(pBt->pPager, p->db->nSavepoint);
38125
+ }
38126
+
3774138127
btreeIntegrity(p);
3774238128
sqlite3BtreeLeave(p);
3774338129
return rc;
3774438130
}
3774538131
@@ -37948,19 +38334,14 @@
3794838334
** that the caller will keep calling incrVacuumStep() until
3794938335
** it returns SQLITE_DONE or an error, and that nFin is the
3795038336
** number of pages the database file will contain after this
3795138337
** process is complete.
3795238338
*/
37953
-static int incrVacuumStep(BtShared *pBt, Pgno nFin){
37954
- Pgno iLastPg; /* Last page in the database */
38339
+static int incrVacuumStep(BtShared *pBt, Pgno nFin, Pgno iLastPg){
3795538340
Pgno nFreeList; /* Number of pages still on the free-list */
3795638341
3795738342
assert( sqlite3_mutex_held(pBt->mutex) );
37958
- iLastPg = pBt->nTrunc;
37959
- if( iLastPg==0 ){
37960
- iLastPg = pagerPagecount(pBt);
37961
- }
3796238343
3796338344
if( !PTRMAP_ISPAGE(pBt, iLastPg) && iLastPg!=PENDING_BYTE_PAGE(pBt) ){
3796438345
int rc;
3796538346
u8 eType;
3796638347
Pgno iPtrPage;
@@ -38030,13 +38411,16 @@
3803038411
return rc;
3803138412
}
3803238413
}
3803338414
}
3803438415
38035
- pBt->nTrunc = iLastPg - 1;
38036
- while( pBt->nTrunc==PENDING_BYTE_PAGE(pBt)||PTRMAP_ISPAGE(pBt, pBt->nTrunc) ){
38037
- pBt->nTrunc--;
38416
+ if( nFin==0 ){
38417
+ iLastPg--;
38418
+ while( iLastPg==PENDING_BYTE_PAGE(pBt)||PTRMAP_ISPAGE(pBt, iLastPg) ){
38419
+ iLastPg--;
38420
+ }
38421
+ sqlite3PagerTruncateImage(pBt->pPager, iLastPg);
3803838422
}
3803938423
return SQLITE_OK;
3804038424
}
3804138425
3804238426
/*
@@ -38056,11 +38440,11 @@
3805638440
assert( pBt->inTransaction==TRANS_WRITE && p->inTrans==TRANS_WRITE );
3805738441
if( !pBt->autoVacuum ){
3805838442
rc = SQLITE_DONE;
3805938443
}else{
3806038444
invalidateAllOverflowCache(pBt);
38061
- rc = incrVacuumStep(pBt, 0);
38445
+ rc = incrVacuumStep(pBt, 0, sqlite3PagerImageSize(pBt->pPager));
3806238446
}
3806338447
sqlite3BtreeLeave(p);
3806438448
return rc;
3806538449
}
3806638450
@@ -38071,66 +38455,57 @@
3807138455
** If SQLITE_OK is returned, then *pnTrunc is set to the number of pages
3807238456
** the database file should be truncated to during the commit process.
3807338457
** i.e. the database has been reorganized so that only the first *pnTrunc
3807438458
** pages are in use.
3807538459
*/
38076
-static int autoVacuumCommit(BtShared *pBt, Pgno *pnTrunc){
38460
+static int autoVacuumCommit(BtShared *pBt){
3807738461
int rc = SQLITE_OK;
3807838462
Pager *pPager = pBt->pPager;
3807938463
VVA_ONLY( int nRef = sqlite3PagerRefcount(pPager) );
3808038464
3808138465
assert( sqlite3_mutex_held(pBt->mutex) );
3808238466
invalidateAllOverflowCache(pBt);
3808338467
assert(pBt->autoVacuum);
3808438468
if( !pBt->incrVacuum ){
38085
- Pgno nFin = 0;
38086
-
38087
- if( pBt->nTrunc==0 ){
38088
- Pgno nFree;
38089
- Pgno nPtrmap;
38090
- const int pgsz = pBt->pageSize;
38091
- Pgno nOrig = pagerPagecount(pBt);
38092
-
38093
- if( PTRMAP_ISPAGE(pBt, nOrig) ){
38094
- return SQLITE_CORRUPT_BKPT;
38095
- }
38096
- if( nOrig==PENDING_BYTE_PAGE(pBt) ){
38097
- nOrig--;
38098
- }
38099
- nFree = get4byte(&pBt->pPage1->aData[36]);
38100
- nPtrmap = (nFree-nOrig+PTRMAP_PAGENO(pBt, nOrig)+pgsz/5)/(pgsz/5);
38101
- nFin = nOrig - nFree - nPtrmap;
38102
- if( nOrig>PENDING_BYTE_PAGE(pBt) && nFin<=PENDING_BYTE_PAGE(pBt) ){
38103
- nFin--;
38104
- }
38105
- while( PTRMAP_ISPAGE(pBt, nFin) || nFin==PENDING_BYTE_PAGE(pBt) ){
38106
- nFin--;
38107
- }
38108
- }
38109
-
38110
- while( rc==SQLITE_OK ){
38111
- rc = incrVacuumStep(pBt, nFin);
38112
- }
38113
- if( rc==SQLITE_DONE ){
38114
- assert(nFin==0 || pBt->nTrunc==0 || nFin<=pBt->nTrunc);
38469
+ Pgno nFin;
38470
+ Pgno nFree;
38471
+ Pgno nPtrmap;
38472
+ Pgno iFree;
38473
+ const int pgsz = pBt->pageSize;
38474
+ Pgno nOrig = pagerPagecount(pBt);
38475
+
38476
+ if( PTRMAP_ISPAGE(pBt, nOrig) ){
38477
+ return SQLITE_CORRUPT_BKPT;
38478
+ }
38479
+ if( nOrig==PENDING_BYTE_PAGE(pBt) ){
38480
+ nOrig--;
38481
+ }
38482
+ nFree = get4byte(&pBt->pPage1->aData[36]);
38483
+ nPtrmap = (nFree-nOrig+PTRMAP_PAGENO(pBt, nOrig)+pgsz/5)/(pgsz/5);
38484
+ nFin = nOrig - nFree - nPtrmap;
38485
+ if( nOrig>PENDING_BYTE_PAGE(pBt) && nFin<=PENDING_BYTE_PAGE(pBt) ){
38486
+ nFin--;
38487
+ }
38488
+ while( PTRMAP_ISPAGE(pBt, nFin) || nFin==PENDING_BYTE_PAGE(pBt) ){
38489
+ nFin--;
38490
+ }
38491
+
38492
+ for(iFree=nOrig; iFree>nFin && rc==SQLITE_OK; iFree--){
38493
+ rc = incrVacuumStep(pBt, nFin, iFree);
38494
+ }
38495
+ if( (rc==SQLITE_DONE || rc==SQLITE_OK) && nFree>0 ){
3811538496
rc = SQLITE_OK;
38116
- if( pBt->nTrunc && nFin ){
38117
- rc = sqlite3PagerWrite(pBt->pPage1->pDbPage);
38118
- put4byte(&pBt->pPage1->aData[32], 0);
38119
- put4byte(&pBt->pPage1->aData[36], 0);
38120
- pBt->nTrunc = nFin;
38121
- }
38497
+ rc = sqlite3PagerWrite(pBt->pPage1->pDbPage);
38498
+ put4byte(&pBt->pPage1->aData[32], 0);
38499
+ put4byte(&pBt->pPage1->aData[36], 0);
38500
+ sqlite3PagerTruncateImage(pBt->pPager, nFin);
3812238501
}
3812338502
if( rc!=SQLITE_OK ){
3812438503
sqlite3PagerRollback(pPager);
3812538504
}
3812638505
}
3812738506
38128
- if( rc==SQLITE_OK ){
38129
- *pnTrunc = pBt->nTrunc;
38130
- pBt->nTrunc = 0;
38131
- }
3813238507
assert( nRef==sqlite3PagerRefcount(pPager) );
3813338508
return rc;
3813438509
}
3813538510
3813638511
#endif /* ifndef SQLITE_OMIT_AUTOVACUUM */
@@ -38163,23 +38538,22 @@
3816338538
*/
3816438539
SQLITE_PRIVATE int sqlite3BtreeCommitPhaseOne(Btree *p, const char *zMaster){
3816538540
int rc = SQLITE_OK;
3816638541
if( p->inTrans==TRANS_WRITE ){
3816738542
BtShared *pBt = p->pBt;
38168
- Pgno nTrunc = 0;
3816938543
sqlite3BtreeEnter(p);
3817038544
pBt->db = p->db;
3817138545
#ifndef SQLITE_OMIT_AUTOVACUUM
3817238546
if( pBt->autoVacuum ){
38173
- rc = autoVacuumCommit(pBt, &nTrunc);
38547
+ rc = autoVacuumCommit(pBt);
3817438548
if( rc!=SQLITE_OK ){
3817538549
sqlite3BtreeLeave(p);
3817638550
return rc;
3817738551
}
3817838552
}
3817938553
#endif
38180
- rc = sqlite3PagerCommitPhaseOne(pBt->pPager, zMaster, nTrunc, 0);
38554
+ rc = sqlite3PagerCommitPhaseOne(pBt->pPager, zMaster, 0);
3818138555
sqlite3BtreeLeave(p);
3818238556
}
3818338557
return rc;
3818438558
}
3818538559
@@ -38345,14 +38719,10 @@
3834538719
unlockAllTables(p);
3834638720
3834738721
if( p->inTrans==TRANS_WRITE ){
3834838722
int rc2;
3834938723
38350
-#ifndef SQLITE_OMIT_AUTOVACUUM
38351
- pBt->nTrunc = 0;
38352
-#endif
38353
-
3835438724
assert( TRANS_WRITE==pBt->inTransaction );
3835538725
rc2 = sqlite3PagerRollback(pBt->pPager);
3835638726
if( rc2!=SQLITE_OK ){
3835738727
rc = rc2;
3835838728
}
@@ -38402,21 +38772,28 @@
3840238772
SQLITE_PRIVATE int sqlite3BtreeBeginStmt(Btree *p){
3840338773
int rc;
3840438774
BtShared *pBt = p->pBt;
3840538775
sqlite3BtreeEnter(p);
3840638776
pBt->db = p->db;
38407
- if( (p->inTrans!=TRANS_WRITE) || pBt->inStmt ){
38408
- rc = pBt->readOnly ? SQLITE_READONLY : SQLITE_ERROR;
38777
+ assert( p->inTrans==TRANS_WRITE );
38778
+ assert( !pBt->inStmt );
38779
+ assert( pBt->readOnly==0 );
38780
+ if( NEVER(p->inTrans!=TRANS_WRITE || pBt->inStmt || pBt->readOnly) ){
38781
+ rc = SQLITE_INTERNAL;
3840938782
}else{
3841038783
assert( pBt->inTransaction==TRANS_WRITE );
38411
- rc = pBt->readOnly ? SQLITE_OK : sqlite3PagerStmtBegin(pBt->pPager);
38784
+ /* At the pager level, a statement transaction is a savepoint with
38785
+ ** an index greater than all savepoints created explicitly using
38786
+ ** SQL statements. It is illegal to open, release or rollback any
38787
+ ** such savepoints while the statement transaction savepoint is active.
38788
+ */
38789
+ rc = sqlite3PagerOpenSavepoint(pBt->pPager, p->db->nSavepoint+1);
3841238790
pBt->inStmt = 1;
3841338791
}
3841438792
sqlite3BtreeLeave(p);
3841538793
return rc;
3841638794
}
38417
-
3841838795
3841938796
/*
3842038797
** Commit the statment subtransaction currently in progress. If no
3842138798
** subtransaction is active, this is a no-op.
3842238799
*/
@@ -38423,12 +38800,14 @@
3842338800
SQLITE_PRIVATE int sqlite3BtreeCommitStmt(Btree *p){
3842438801
int rc;
3842538802
BtShared *pBt = p->pBt;
3842638803
sqlite3BtreeEnter(p);
3842738804
pBt->db = p->db;
38428
- if( pBt->inStmt && !pBt->readOnly ){
38429
- rc = sqlite3PagerStmtCommit(pBt->pPager);
38805
+ assert( pBt->readOnly==0 );
38806
+ if( pBt->inStmt ){
38807
+ int iStmtpoint = p->db->nSavepoint;
38808
+ rc = sqlite3PagerSavepoint(pBt->pPager, SAVEPOINT_RELEASE, iStmtpoint);
3843038809
}else{
3843138810
rc = SQLITE_OK;
3843238811
}
3843338812
pBt->inStmt = 0;
3843438813
sqlite3BtreeLeave(p);
@@ -38446,17 +38825,52 @@
3844638825
SQLITE_PRIVATE int sqlite3BtreeRollbackStmt(Btree *p){
3844738826
int rc = SQLITE_OK;
3844838827
BtShared *pBt = p->pBt;
3844938828
sqlite3BtreeEnter(p);
3845038829
pBt->db = p->db;
38451
- if( pBt->inStmt && !pBt->readOnly ){
38452
- rc = sqlite3PagerStmtRollback(pBt->pPager);
38830
+ assert( pBt->readOnly==0 );
38831
+ if( pBt->inStmt ){
38832
+ int iStmtpoint = p->db->nSavepoint;
38833
+ rc = sqlite3PagerSavepoint(pBt->pPager, SAVEPOINT_ROLLBACK, iStmtpoint);
38834
+ if( rc==SQLITE_OK ){
38835
+ rc = sqlite3PagerSavepoint(pBt->pPager, SAVEPOINT_RELEASE, iStmtpoint);
38836
+ }
3845338837
pBt->inStmt = 0;
3845438838
}
3845538839
sqlite3BtreeLeave(p);
3845638840
return rc;
3845738841
}
38842
+
38843
+/*
38844
+** The second argument to this function, op, is always SAVEPOINT_ROLLBACK
38845
+** or SAVEPOINT_RELEASE. This function either releases or rolls back the
38846
+** savepoint identified by parameter iSavepoint, depending on the value
38847
+** of op.
38848
+**
38849
+** Normally, iSavepoint is greater than or equal to zero. However, if op is
38850
+** SAVEPOINT_ROLLBACK, then iSavepoint may also be -1. In this case the
38851
+** contents of the entire transaction are rolled back. This is different
38852
+** from a normal transaction rollback, as no locks are released and the
38853
+** transaction remains open.
38854
+*/
38855
+SQLITE_PRIVATE int sqlite3BtreeSavepoint(Btree *p, int op, int iSavepoint){
38856
+ int rc = SQLITE_OK;
38857
+ if( p && p->inTrans==TRANS_WRITE ){
38858
+ BtShared *pBt = p->pBt;
38859
+ assert( pBt->inStmt==0 );
38860
+ assert( op==SAVEPOINT_RELEASE || op==SAVEPOINT_ROLLBACK );
38861
+ assert( iSavepoint>=0 || (iSavepoint==-1 && op==SAVEPOINT_ROLLBACK) );
38862
+ sqlite3BtreeEnter(p);
38863
+ pBt->db = p->db;
38864
+ rc = sqlite3PagerSavepoint(pBt->pPager, op, iSavepoint);
38865
+ if( rc==SQLITE_OK ){
38866
+ rc = newDatabase(pBt);
38867
+ }
38868
+ sqlite3BtreeLeave(p);
38869
+ }
38870
+ return rc;
38871
+}
3845838872
3845938873
/*
3846038874
** Create a new cursor for the BTree whose root is on the page
3846138875
** iTable. The act of acquiring a cursor gets a read lock on
3846238876
** the database file.
@@ -38498,11 +38912,12 @@
3849838912
BtShared *pBt = p->pBt;
3849938913
3850038914
assert( sqlite3BtreeHoldsMutex(p) );
3850138915
assert( wrFlag==0 || wrFlag==1 );
3850238916
if( wrFlag ){
38503
- if( pBt->readOnly ){
38917
+ assert( !pBt->readOnly );
38918
+ if( NEVER(pBt->readOnly) ){
3850438919
return SQLITE_READONLY;
3850538920
}
3850638921
if( checkReadLocks(p, iTable, 0, 0) ){
3850738922
return SQLITE_LOCKED;
3850838923
}
@@ -38511,13 +38926,10 @@
3851138926
if( pBt->pPage1==0 ){
3851238927
rc = lockBtreeWithRetry(p);
3851338928
if( rc!=SQLITE_OK ){
3851438929
return rc;
3851538930
}
38516
- if( pBt->readOnly && wrFlag ){
38517
- return SQLITE_READONLY;
38518
- }
3851938931
}
3852038932
pCur->pgnoRoot = (Pgno)iTable;
3852138933
rc = sqlite3PagerPagecount(pBt->pPager, (int *)&nPage);
3852238934
if( rc!=SQLITE_OK ){
3852338935
return rc;
@@ -39394,23 +39806,24 @@
3939439806
** If an exact match is not found, then the cursor is always
3939539807
** left pointing at a leaf page which would hold the entry if it
3939639808
** were present. The cursor might point to an entry that comes
3939739809
** before or after the key.
3939839810
**
39399
-** The result of comparing the key with the entry to which the
39400
-** cursor is written to *pRes if pRes!=NULL. The meaning of
39401
-** this value is as follows:
39811
+** An integer is written into *pRes which is the result of
39812
+** comparing the key with the entry to which the cursor is
39813
+** pointing. The meaning of the integer written into
39814
+** *pRes is as follows:
3940239815
**
3940339816
** *pRes<0 The cursor is left pointing at an entry that
39404
-** is smaller than pKey or if the table is empty
39817
+** is smaller than intKey/pIdxKey or if the table is empty
3940539818
** and the cursor is therefore left point to nothing.
3940639819
**
3940739820
** *pRes==0 The cursor is left pointing at an entry that
39408
-** exactly matches pKey.
39821
+** exactly matches intKey/pIdxKey.
3940939822
**
3941039823
** *pRes>0 The cursor is left pointing at an entry that
39411
-** is larger than pKey.
39824
+** is larger than intKey/pIdxKey.
3941239825
**
3941339826
*/
3941439827
SQLITE_PRIVATE int sqlite3BtreeMovetoUnpacked(
3941539828
BtCursor *pCur, /* The cursor to be moved */
3941639829
UnpackedRecord *pIdxKey, /* Unpacked index key */
@@ -39455,20 +39868,20 @@
3945539868
Pgno chldPg;
3945639869
MemPage *pPage = pCur->apPage[pCur->iPage];
3945739870
int c = -1; /* pRes return if table is empty must be -1 */
3945839871
lwr = 0;
3945939872
upr = pPage->nCell-1;
39460
- if( !pPage->intKey && pIdxKey==0 ){
39873
+ if( (!pPage->intKey && pIdxKey==0) || upr<0 ){
3946139874
rc = SQLITE_CORRUPT_BKPT;
3946239875
goto moveto_finish;
3946339876
}
3946439877
if( biasRight ){
3946539878
pCur->aiIdx[pCur->iPage] = (u16)upr;
3946639879
}else{
3946739880
pCur->aiIdx[pCur->iPage] = (u16)((upr+lwr)/2);
3946839881
}
39469
- if( lwr<=upr ) for(;;){
39882
+ for(;;){
3947039883
void *pCellKey;
3947139884
i64 nCellKey;
3947239885
int idx = pCur->aiIdx[pCur->iPage];
3947339886
pCur->info.nSize = 0;
3947439887
pCur->validNKey = 1;
@@ -39511,11 +39924,11 @@
3951139924
if( pPage->intKey && !pPage->leaf ){
3951239925
lwr = idx;
3951339926
upr = lwr - 1;
3951439927
break;
3951539928
}else{
39516
- if( pRes ) *pRes = 0;
39929
+ *pRes = 0;
3951739930
rc = SQLITE_OK;
3951839931
goto moveto_finish;
3951939932
}
3952039933
}
3952139934
if( c<0 ){
@@ -39957,20 +40370,10 @@
3995740370
** end of the file */
3995840371
int nPage = pagerPagecount(pBt);
3995940372
*pPgno = nPage + 1;
3996040373
3996140374
#ifndef SQLITE_OMIT_AUTOVACUUM
39962
- if( pBt->nTrunc ){
39963
- /* An incr-vacuum has already run within this transaction. So the
39964
- ** page to allocate is not from the physical end of the file, but
39965
- ** at pBt->nTrunc.
39966
- */
39967
- *pPgno = pBt->nTrunc+1;
39968
- if( *pPgno==PENDING_BYTE_PAGE(pBt) ){
39969
- (*pPgno)++;
39970
- }
39971
- }
3997240375
if( pBt->autoVacuum && PTRMAP_ISPAGE(pBt, *pPgno) ){
3997340376
/* If *pPgno refers to a pointer-map page, allocate two new pages
3997440377
** at the end of the file instead of one. The first allocated page
3997540378
** becomes a new pointer-map page, the second is used by the caller.
3997640379
*/
@@ -39977,13 +40380,10 @@
3997740380
TRACE(("ALLOCATE: %d from end of file (pointer-map page)\n", *pPgno));
3997840381
assert( *pPgno!=PENDING_BYTE_PAGE(pBt) );
3997940382
(*pPgno)++;
3998040383
if( *pPgno==PENDING_BYTE_PAGE(pBt) ){ (*pPgno)++; }
3998140384
}
39982
- if( pBt->nTrunc ){
39983
- pBt->nTrunc = *pPgno;
39984
- }
3998540385
#endif
3998640386
3998740387
assert( *pPgno!=PENDING_BYTE_PAGE(pBt) );
3998840388
rc = sqlite3BtreeGetPage(pBt, *pPgno, ppPage, 0);
3998940389
if( rc ) return rc;
@@ -40606,10 +41006,11 @@
4060641006
** it will not be rolled back and so it is important to make sure that
4060741007
** the page data and contents of MemPage are consistent.
4060841008
*/
4060941009
pPage->isInit = 0;
4061041010
sqlite3BtreeInitPage(pPage);
41011
+ assert( pPage->nOverflow==0 );
4061141012
4061241013
/* If everything else succeeded, balance the parent page, in
4061341014
** case the divider cell inserted caused it to become overfull.
4061441015
*/
4061541016
if( rc==SQLITE_OK ){
@@ -40654,12 +41055,12 @@
4065441055
MemPage *pPage; /* The over or underfull page to balance */
4065541056
MemPage *pParent; /* The parent of pPage */
4065641057
BtShared *pBt; /* The whole database */
4065741058
int nCell = 0; /* Number of cells in apCell[] */
4065841059
int nMaxCells = 0; /* Allocated size of apCell, szCell, aFrom. */
40659
- int nOld; /* Number of pages in apOld[] */
40660
- int nNew; /* Number of pages in apNew[] */
41060
+ int nOld = 0; /* Number of pages in apOld[] */
41061
+ int nNew = 0; /* Number of pages in apNew[] */
4066141062
int nDiv; /* Number of cells in apDiv[] */
4066241063
int i, j, k; /* Loop counters */
4066341064
int idx; /* Index of pPage in pParent->aCell[] */
4066441065
int nxDiv; /* Next divider slot in pParent->aCell[] */
4066541066
int rc; /* The return code */
@@ -40698,11 +41099,11 @@
4069841099
assert( sqlite3PagerIswriteable(pPage->pDbPage) || pPage->nOverflow==1 );
4069941100
pBt = pPage->pBt;
4070041101
pParent = pCur->apPage[pCur->iPage-1];
4070141102
assert( pParent );
4070241103
if( SQLITE_OK!=(rc = sqlite3PagerWrite(pParent->pDbPage)) ){
40703
- return rc;
41104
+ goto balance_cleanup;
4070441105
}
4070541106
4070641107
TRACE(("BALANCE: begin page %d child of %d\n", pPage->pgno, pParent->pgno));
4070741108
4070841109
#ifndef SQLITE_OMIT_QUICKBALANCE
@@ -40729,11 +41130,11 @@
4072941130
return balance_quick(pCur);
4073041131
}
4073141132
#endif
4073241133
4073341134
if( SQLITE_OK!=(rc = sqlite3PagerWrite(pPage->pDbPage)) ){
40734
- return rc;
41135
+ goto balance_cleanup;
4073541136
}
4073641137
4073741138
/*
4073841139
** Find the cell in the parent page whose left child points back
4073941140
** to pPage. The "idx" variable is the index of that cell. If pPage
@@ -40740,16 +41141,10 @@
4074041141
** is the rightmost child of pParent then set idx to pParent->nCell
4074141142
*/
4074241143
idx = pCur->aiIdx[pCur->iPage-1];
4074341144
assertParentIndex(pParent, idx, pPage->pgno);
4074441145
40745
- /*
40746
- ** Initialize variables so that it will be safe to jump
40747
- ** directly to balance_cleanup at any moment.
40748
- */
40749
- nOld = nNew = 0;
40750
-
4075141146
/*
4075241147
** Find sibling pages to pPage and the cells in pParent that divide
4075341148
** the siblings. An attempt is made to find NN siblings on either
4075441149
** side of pPage. More siblings are taken from one side, however, if
4075541150
** pPage there are fewer than NN siblings on the other side. If pParent
@@ -41207,10 +41602,13 @@
4120741602
** But the parent page will always be initialized.
4120841603
*/
4120941604
assert( pParent->isInit );
4121041605
sqlite3ScratchFree(apCell);
4121141606
apCell = 0;
41607
+ TRACE(("BALANCE: finished with %d: old=%d new=%d cells=%d\n",
41608
+ pPage->pgno, nOld, nNew, nCell));
41609
+ pPage->nOverflow = 0;
4121241610
releasePage(pPage);
4121341611
pCur->iPage--;
4121441612
rc = balance(pCur, 0);
4121541613
4121641614
/*
@@ -41223,15 +41621,11 @@
4122341621
releasePage(apOld[i]);
4122441622
}
4122541623
for(i=0; i<nNew; i++){
4122641624
releasePage(apNew[i]);
4122741625
}
41228
- pPage->nOverflow = 0;
41229
-
41230
- /* releasePage(pParent); */
41231
- TRACE(("BALANCE: finished with %d: old=%d new=%d cells=%d\n",
41232
- pPage->pgno, nOld, nNew, nCell));
41626
+ pCur->apPage[pCur->iPage]->nOverflow = 0;
4123341627
4123441628
return rc;
4123541629
}
4123641630
4123741631
/*
@@ -41387,10 +41781,13 @@
4138741781
rc = ptrmapPut(pBt, pChild->pgno, PTRMAP_BTREE, pPage->pgno);
4138841782
#ifndef SQLITE_OMIT_AUTOVACUUM
4138941783
if( rc==SQLITE_OK ){
4139041784
rc = setChildPtrmaps(pChild);
4139141785
}
41786
+ if( rc ){
41787
+ pChild->nOverflow = 0;
41788
+ }
4139241789
#endif
4139341790
}
4139441791
}
4139541792
4139641793
if( rc==SQLITE_OK ){
@@ -41421,21 +41818,22 @@
4142141818
assert( sqlite3_mutex_held(pPage->pBt->mutex) );
4142241819
if( pCur->iPage==0 ){
4142341820
rc = sqlite3PagerWrite(pPage->pDbPage);
4142441821
if( rc==SQLITE_OK && pPage->nOverflow>0 ){
4142541822
rc = balance_deeper(pCur);
41823
+ assert( pCur->apPage[0]==pPage );
4142641824
assert( pPage->nOverflow==0 || rc!=SQLITE_OK );
4142741825
}
4142841826
if( rc==SQLITE_OK && pPage->nCell==0 ){
4142941827
rc = balance_shallower(pCur);
41828
+ assert( pCur->apPage[0]==pPage );
4143041829
assert( pPage->nOverflow==0 || rc!=SQLITE_OK );
4143141830
}
4143241831
}else{
4143341832
if( pPage->nOverflow>0 ||
4143441833
(!isInsert && pPage->nFree>pPage->pBt->usableSize*2/3) ){
4143541834
rc = balance_nonroot(pCur);
41436
- assert( pPage->nOverflow==0 || rc!=SQLITE_OK );
4143741835
}
4143841836
}
4143941837
return rc;
4144041838
}
4144141839
@@ -41533,19 +41931,13 @@
4153341931
BtShared *pBt = p->pBt;
4153441932
unsigned char *oldCell;
4153541933
unsigned char *newCell = 0;
4153641934
4153741935
assert( cursorHoldsMutex(pCur) );
41538
- if( pBt->inTransaction!=TRANS_WRITE ){
41539
- /* Must start a transaction before doing an insert */
41540
- rc = pBt->readOnly ? SQLITE_READONLY : SQLITE_ERROR;
41541
- return rc;
41542
- }
41936
+ assert( pBt->inTransaction==TRANS_WRITE );
4154341937
assert( !pBt->readOnly );
41544
- if( !pCur->wrFlag ){
41545
- return SQLITE_PERM; /* Cursor not open for writing */
41546
- }
41938
+ assert( pCur->wrFlag );
4154741939
if( checkReadLocks(pCur->pBtree, pCur->pgnoRoot, pCur, nKey) ){
4154841940
return SQLITE_LOCKED; /* The table pCur points to has a read lock */
4154941941
}
4155041942
if( pCur->eState==CURSOR_FAULT ){
4155141943
return pCur->skip;
@@ -41606,12 +41998,11 @@
4160641998
rc = balance(pCur, 1);
4160741999
}
4160842000
4160942001
/* Must make sure nOverflow is reset to zero even if the balance()
4161042002
** fails. Internal data structure corruption will result otherwise. */
41611
- assert( pPage->nOverflow==0 || rc!=SQLITE_OK );
41612
- pPage->nOverflow = 0;
42003
+ pCur->apPage[pCur->iPage]->nOverflow = 0;
4161342004
4161442005
if( rc==SQLITE_OK ){
4161542006
moveToRoot(pCur);
4161642007
}
4161742008
end_insert:
@@ -41631,25 +42022,19 @@
4163142022
Btree *p = pCur->pBtree;
4163242023
BtShared *pBt = p->pBt;
4163342024
4163442025
assert( cursorHoldsMutex(pCur) );
4163542026
assert( pPage->isInit );
41636
- if( pBt->inTransaction!=TRANS_WRITE ){
41637
- /* Must start a transaction before doing a delete */
41638
- rc = pBt->readOnly ? SQLITE_READONLY : SQLITE_ERROR;
41639
- return rc;
41640
- }
42027
+ assert( pBt->inTransaction==TRANS_WRITE );
4164142028
assert( !pBt->readOnly );
4164242029
if( pCur->eState==CURSOR_FAULT ){
4164342030
return pCur->skip;
4164442031
}
41645
- if( pCur->aiIdx[pCur->iPage]>=pPage->nCell ){
42032
+ if( NEVER(pCur->aiIdx[pCur->iPage]>=pPage->nCell) ){
4164642033
return SQLITE_ERROR; /* The cursor is not pointing to anything */
4164742034
}
41648
- if( !pCur->wrFlag ){
41649
- return SQLITE_PERM; /* Did not open this cursor for writing */
41650
- }
42035
+ assert( pCur->wrFlag );
4165142036
if( checkReadLocks(pCur->pBtree, pCur->pgnoRoot, pCur, pCur->info.nKey) ){
4165242037
return SQLITE_LOCKED; /* The table pCur points to has a read lock */
4165342038
}
4165442039
4165542040
/* Restore the current cursor position (a no-op if the cursor is not in
@@ -41840,15 +42225,11 @@
4184042225
MemPage *pRoot;
4184142226
Pgno pgnoRoot;
4184242227
int rc;
4184342228
4184442229
assert( sqlite3BtreeHoldsMutex(p) );
41845
- if( pBt->inTransaction!=TRANS_WRITE ){
41846
- /* Must start a transaction first */
41847
- rc = pBt->readOnly ? SQLITE_READONLY : SQLITE_ERROR;
41848
- return rc;
41849
- }
42230
+ assert( pBt->inTransaction==TRANS_WRITE );
4185042231
assert( !pBt->readOnly );
4185142232
4185242233
#ifdef SQLITE_OMIT_AUTOVACUUM
4185342234
rc = allocateBtreePage(pBt, &pRoot, &pgnoRoot, 1, 0);
4185442235
if( rc ){
@@ -42040,13 +42421,12 @@
4204042421
SQLITE_PRIVATE int sqlite3BtreeClearTable(Btree *p, int iTable, int *pnChange){
4204142422
int rc;
4204242423
BtShared *pBt = p->pBt;
4204342424
sqlite3BtreeEnter(p);
4204442425
pBt->db = p->db;
42045
- if( p->inTrans!=TRANS_WRITE ){
42046
- rc = pBt->readOnly ? SQLITE_READONLY : SQLITE_ERROR;
42047
- }else if( (rc = checkReadLocks(p, iTable, 0, 1))!=SQLITE_OK ){
42426
+ assert( p->inTrans==TRANS_WRITE );
42427
+ if( (rc = checkReadLocks(p, iTable, 0, 1))!=SQLITE_OK ){
4204842428
/* nothing to do */
4204942429
}else if( SQLITE_OK!=(rc = saveAllCursors(pBt, iTable, 0)) ){
4205042430
/* nothing to do */
4205142431
}else{
4205242432
rc = clearDatabasePage(pBt, (Pgno)iTable, 0, pnChange);
@@ -42079,13 +42459,11 @@
4207942459
int rc;
4208042460
MemPage *pPage = 0;
4208142461
BtShared *pBt = p->pBt;
4208242462
4208342463
assert( sqlite3BtreeHoldsMutex(p) );
42084
- if( p->inTrans!=TRANS_WRITE ){
42085
- return pBt->readOnly ? SQLITE_READONLY : SQLITE_ERROR;
42086
- }
42464
+ assert( p->inTrans==TRANS_WRITE );
4208742465
4208842466
/* It is illegal to drop a table if any cursors are open on the
4208942467
** database. This is because in auto-vacuum mode the backend may
4209042468
** need to move another root-page to fill a gap left by the deleted
4209142469
** root page. If an open cursor was using this page a problem would
@@ -42272,26 +42650,23 @@
4227242650
unsigned char *pP1;
4227342651
int rc;
4227442652
assert( idx>=1 && idx<=15 );
4227542653
sqlite3BtreeEnter(p);
4227642654
pBt->db = p->db;
42277
- if( p->inTrans!=TRANS_WRITE ){
42278
- rc = pBt->readOnly ? SQLITE_READONLY : SQLITE_ERROR;
42279
- }else{
42280
- assert( pBt->pPage1!=0 );
42281
- pP1 = pBt->pPage1->aData;
42282
- rc = sqlite3PagerWrite(pBt->pPage1->pDbPage);
42283
- if( rc==SQLITE_OK ){
42284
- put4byte(&pP1[36 + idx*4], iMeta);
42655
+ assert( p->inTrans==TRANS_WRITE );
42656
+ assert( pBt->pPage1!=0 );
42657
+ pP1 = pBt->pPage1->aData;
42658
+ rc = sqlite3PagerWrite(pBt->pPage1->pDbPage);
42659
+ if( rc==SQLITE_OK ){
42660
+ put4byte(&pP1[36 + idx*4], iMeta);
4228542661
#ifndef SQLITE_OMIT_AUTOVACUUM
42286
- if( idx==7 ){
42287
- assert( pBt->autoVacuum || iMeta==0 );
42288
- assert( iMeta==0 || iMeta==1 );
42289
- pBt->incrVacuum = (u8)iMeta;
42290
- }
42662
+ if( idx==7 ){
42663
+ assert( pBt->autoVacuum || iMeta==0 );
42664
+ assert( iMeta==0 || iMeta==1 );
42665
+ pBt->incrVacuum = (u8)iMeta;
42666
+ }
4229142667
#endif
42292
- }
4229342668
}
4229442669
sqlite3BtreeLeave(p);
4229542670
return rc;
4229642671
}
4229742672
@@ -42305,12 +42680,13 @@
4230542680
*/
4230642681
MemPage *pPage;
4230742682
restoreCursorPosition(pCur);
4230842683
pPage = pCur->apPage[pCur->iPage];
4230942684
assert( cursorHoldsMutex(pCur) );
42685
+ assert( pPage!=0 );
4231042686
assert( pPage->pBt==pCur->pBt );
42311
- return pPage ? pPage->aData[pPage->hdrOffset] : 0;
42687
+ return pPage->aData[pPage->hdrOffset];
4231242688
}
4231342689
4231442690
4231542691
/*
4231642692
** Return the pager associated with a BTree. This routine is used for
@@ -42521,11 +42897,11 @@
4252142897
checkAppendMsg(pCheck, zContext,
4252242898
"unable to get the page. error code=%d", rc);
4252342899
return 0;
4252442900
}
4252542901
if( (rc = sqlite3BtreeInitPage(pPage))!=0 ){
42526
- if( rc==SQLITE_NOMEM ) pCheck->mallocFailed = 1;
42902
+ assert( rc==SQLITE_CORRUPT ); /* The only possible error from InitPage */
4252742903
checkAppendMsg(pCheck, zContext,
4252842904
"sqlite3BtreeInitPage() returns error code %d", rc);
4252942905
releasePage(pPage);
4253042906
return 0;
4253142907
}
@@ -42690,15 +43066,10 @@
4269043066
sCheck.nPage = pagerPagecount(sCheck.pBt);
4269143067
sCheck.mxErr = mxErr;
4269243068
sCheck.nErr = 0;
4269343069
sCheck.mallocFailed = 0;
4269443070
*pnErr = 0;
42695
-#ifndef SQLITE_OMIT_AUTOVACUUM
42696
- if( pBt->nTrunc!=0 ){
42697
- sCheck.nPage = pBt->nTrunc;
42698
- }
42699
-#endif
4270043071
if( sCheck.nPage==0 ){
4270143072
unlockBtreeIfUnused(pBt);
4270243073
sqlite3BtreeLeave(p);
4270343074
return 0;
4270443075
}
@@ -42753,14 +43124,16 @@
4275343124
checkAppendMsg(&sCheck, 0, "Pointer map page %d is referenced", i);
4275443125
}
4275543126
#endif
4275643127
}
4275743128
42758
- /* Make sure this analysis did not leave any unref() pages
43129
+ /* Make sure this analysis did not leave any unref() pages.
43130
+ ** This is an internal consistency check; an integrity check
43131
+ ** of the integrity check.
4275943132
*/
4276043133
unlockBtreeIfUnused(pBt);
42761
- if( nRef != sqlite3PagerRefcount(pBt->pPager) ){
43134
+ if( NEVER(nRef != sqlite3PagerRefcount(pBt->pPager)) ){
4276243135
checkAppendMsg(&sCheck, 0,
4276343136
"Outstanding page count goes from %d to %d during this analysis",
4276443137
nRef, sqlite3PagerRefcount(pBt->pPager)
4276543138
);
4276643139
}
@@ -42845,14 +43218,13 @@
4284543218
pBtFrom->db = pFrom->db;
4284643219
4284743220
nToPageSize = pBtTo->pageSize;
4284843221
nFromPageSize = pBtFrom->pageSize;
4284943222
42850
- if( pTo->inTrans!=TRANS_WRITE || pFrom->inTrans!=TRANS_WRITE ){
42851
- return SQLITE_ERROR;
42852
- }
42853
- if( pBtTo->pCursor ){
43223
+ assert( pTo->inTrans==TRANS_WRITE );
43224
+ assert( pFrom->inTrans==TRANS_WRITE );
43225
+ if( NEVER(pBtTo->pCursor) ){
4285443226
return SQLITE_BUSY;
4285543227
}
4285643228
4285743229
nToPage = pagerPagecount(pBtTo);
4285843230
nFromPage = pagerPagecount(pBtFrom);
@@ -42952,80 +43324,74 @@
4295243324
** For example, say the page-size of pTo is 2048 bytes and the original
4295343325
** number of pages is 5 (10 KB file). If pFrom has a page size of 1024
4295443326
** bytes and 9 pages, then the file needs to be truncated to 9KB.
4295543327
*/
4295643328
if( rc==SQLITE_OK ){
42957
- if( nFromPageSize!=nToPageSize ){
42958
- sqlite3_file *pFile = sqlite3PagerFile(pBtTo->pPager);
42959
- i64 iSize = (i64)nFromPageSize * (i64)nFromPage;
42960
- i64 iNow = (i64)((nToPage>nNewPage)?nToPage:nNewPage) * (i64)nToPageSize;
42961
- i64 iPending = ((i64)PENDING_BYTE_PAGE(pBtTo)-1) *(i64)nToPageSize;
42962
-
42963
- assert( iSize<=iNow );
42964
-
42965
- /* Commit phase one syncs the journal file associated with pTo
42966
- ** containing the original data. It does not sync the database file
42967
- ** itself. After doing this it is safe to use OsTruncate() and other
42968
- ** file APIs on the database file directly.
42969
- */
42970
- pBtTo->db = pTo->db;
42971
- rc = sqlite3PagerCommitPhaseOne(pBtTo->pPager, 0, 0, 1);
42972
- if( iSize<iNow && rc==SQLITE_OK ){
42973
- rc = sqlite3OsTruncate(pFile, iSize);
42974
- }
42975
-
42976
- /* The loop that copied data from database pFrom to pTo did not
42977
- ** populate the locking page of database pTo. If the page-size of
42978
- ** pFrom is smaller than that of pTo, this means some data will
42979
- ** not have been copied.
42980
- **
42981
- ** This block copies the missing data from database pFrom to pTo
42982
- ** using file APIs. This is safe because at this point we know that
42983
- ** all of the original data from pTo has been synced into the
42984
- ** journal file. At this point it would be safe to do anything at
42985
- ** all to the database file except truncate it to zero bytes.
42986
- */
42987
- if( rc==SQLITE_OK && nFromPageSize<nToPageSize && iSize>iPending){
42988
- i64 iOff;
42989
- for(
42990
- iOff=iPending;
42991
- rc==SQLITE_OK && iOff<(iPending+nToPageSize);
42992
- iOff += nFromPageSize
42993
- ){
42994
- DbPage *pFromPage = 0;
42995
- Pgno iFrom = (Pgno)(iOff/nFromPageSize)+1;
42996
-
42997
- if( iFrom==PENDING_BYTE_PAGE(pBtFrom) || iFrom>nFromPage ){
42998
- continue;
42999
- }
43000
-
43001
- rc = sqlite3PagerGet(pBtFrom->pPager, iFrom, &pFromPage);
43002
- if( rc==SQLITE_OK ){
43003
- char *zFrom = sqlite3PagerGetData(pFromPage);
43004
- rc = sqlite3OsWrite(pFile, zFrom, nFromPageSize, iOff);
43005
- sqlite3PagerUnref(pFromPage);
43006
- }
43007
- }
43008
- }
43009
-
43010
- /* Sync the database file */
43011
- if( rc==SQLITE_OK ){
43012
- rc = sqlite3PagerSync(pBtTo->pPager);
43013
- }
43014
- }else{
43015
- rc = sqlite3PagerTruncate(pBtTo->pPager, nNewPage);
43016
- }
43017
- if( rc==SQLITE_OK ){
43018
- pBtTo->pageSizeFixed = 0;
43019
- }
43020
- }
43021
-
43022
- if( rc ){
43329
+ sqlite3_file *pFile = sqlite3PagerFile(pBtTo->pPager);
43330
+ i64 iSize = (i64)nFromPageSize * (i64)nFromPage;
43331
+ i64 iNow = (i64)((nToPage>nNewPage)?nToPage:nNewPage) * (i64)nToPageSize;
43332
+ i64 iPending = ((i64)PENDING_BYTE_PAGE(pBtTo)-1) *(i64)nToPageSize;
43333
+
43334
+ assert( iSize<=iNow );
43335
+
43336
+ /* Commit phase one syncs the journal file associated with pTo
43337
+ ** containing the original data. It does not sync the database file
43338
+ ** itself. After doing this it is safe to use OsTruncate() and other
43339
+ ** file APIs on the database file directly.
43340
+ */
43341
+ pBtTo->db = pTo->db;
43342
+ rc = sqlite3PagerCommitPhaseOne(pBtTo->pPager, 0, 1);
43343
+ if( iSize<iNow && rc==SQLITE_OK ){
43344
+ rc = sqlite3OsTruncate(pFile, iSize);
43345
+ }
43346
+
43347
+ /* The loop that copied data from database pFrom to pTo did not
43348
+ ** populate the locking page of database pTo. If the page-size of
43349
+ ** pFrom is smaller than that of pTo, this means some data will
43350
+ ** not have been copied.
43351
+ **
43352
+ ** This block copies the missing data from database pFrom to pTo
43353
+ ** using file APIs. This is safe because at this point we know that
43354
+ ** all of the original data from pTo has been synced into the
43355
+ ** journal file. At this point it would be safe to do anything at
43356
+ ** all to the database file except truncate it to zero bytes.
43357
+ */
43358
+ if( rc==SQLITE_OK && nFromPageSize<nToPageSize && iSize>iPending){
43359
+ i64 iOff;
43360
+ for(
43361
+ iOff=iPending;
43362
+ rc==SQLITE_OK && iOff<(iPending+nToPageSize);
43363
+ iOff += nFromPageSize
43364
+ ){
43365
+ DbPage *pFromPage = 0;
43366
+ Pgno iFrom = (Pgno)(iOff/nFromPageSize)+1;
43367
+
43368
+ if( iFrom==PENDING_BYTE_PAGE(pBtFrom) || iFrom>nFromPage ){
43369
+ continue;
43370
+ }
43371
+
43372
+ rc = sqlite3PagerGet(pBtFrom->pPager, iFrom, &pFromPage);
43373
+ if( rc==SQLITE_OK ){
43374
+ char *zFrom = sqlite3PagerGetData(pFromPage);
43375
+ rc = sqlite3OsWrite(pFile, zFrom, nFromPageSize, iOff);
43376
+ sqlite3PagerUnref(pFromPage);
43377
+ }
43378
+ }
43379
+ }
43380
+ }
43381
+
43382
+ /* Sync the database file */
43383
+ if( rc==SQLITE_OK ){
43384
+ rc = sqlite3PagerSync(pBtTo->pPager);
43385
+ }
43386
+ if( rc==SQLITE_OK ){
43387
+ pBtTo->pageSizeFixed = 0;
43388
+ }else{
4302343389
sqlite3BtreeRollback(pTo);
4302443390
}
4302543391
43026
- return rc;
43392
+ return rc;
4302743393
}
4302843394
SQLITE_PRIVATE int sqlite3BtreeCopyFile(Btree *pTo, Btree *pFrom){
4302943395
int rc;
4303043396
sqlite3BtreeEnter(pTo);
4303143397
sqlite3BtreeEnter(pFrom);
@@ -43048,19 +43414,21 @@
4304843414
/*
4304943415
** Return non-zero if a statement transaction is active.
4305043416
*/
4305143417
SQLITE_PRIVATE int sqlite3BtreeIsInStmt(Btree *p){
4305243418
assert( sqlite3BtreeHoldsMutex(p) );
43053
- return (p->pBt && p->pBt->inStmt);
43419
+ assert( p->pBt );
43420
+ return ALWAYS(p->pBt) && p->pBt->inStmt;
4305443421
}
4305543422
4305643423
/*
4305743424
** Return non-zero if a read (or write) transaction is active.
4305843425
*/
4305943426
SQLITE_PRIVATE int sqlite3BtreeIsInReadTrans(Btree *p){
43427
+ assert( p );
4306043428
assert( sqlite3_mutex_held(p->db->mutex) );
43061
- return (p && (p->inTrans!=TRANS_NONE));
43429
+ return p->inTrans!=TRANS_NONE;
4306243430
}
4306343431
4306443432
/*
4306543433
** This function returns a pointer to a blob of memory associated with
4306643434
** a single shared-btree. The memory is used by client code for its own
@@ -43204,11 +43572,11 @@
4320443572
** This file contains code use to manipulate "Mem" structure. A "Mem"
4320543573
** stores a single value in the VDBE. Mem is an opaque structure visible
4320643574
** only within the VDBE. Interface routines refer to a Mem using the
4320743575
** name sqlite_value
4320843576
**
43209
-** $Id: vdbemem.c,v 1.133 2008/12/10 19:26:24 drh Exp $
43577
+** $Id: vdbemem.c,v 1.134 2009/01/05 22:30:39 drh Exp $
4321043578
*/
4321143579
4321243580
/*
4321343581
** Call sqlite3VdbeMemExpandBlob() on the supplied value (type Mem*)
4321443582
** P if required.
@@ -43650,11 +44018,10 @@
4365044018
** Delete any previous value and set the value to be a BLOB of length
4365144019
** n containing all zeros.
4365244020
*/
4365344021
SQLITE_PRIVATE void sqlite3VdbeMemSetZeroBlob(Mem *pMem, int n){
4365444022
sqlite3VdbeMemRelease(pMem);
43655
- MemSetTypeFlag(pMem, MEM_Blob);
4365644023
pMem->flags = MEM_Blob|MEM_Zero;
4365744024
pMem->type = SQLITE_BLOB;
4365844025
pMem->n = 0;
4365944026
if( n<0 ) n = 0;
4366044027
pMem->u.nZero = n;
@@ -44292,11 +44659,11 @@
4429244659
** This file contains code used for creating, destroying, and populating
4429344660
** a VDBE (or an "sqlite3_stmt" as it is known to the outside world.) Prior
4429444661
** to version 2.8.7, all this code was combined into the vdbe.c source file.
4429544662
** But that file was getting too big so this subroutines were split out.
4429644663
**
44297
-** $Id: vdbeaux.c,v 1.428 2008/12/16 17:20:38 shane Exp $
44664
+** $Id: vdbeaux.c,v 1.430 2009/01/07 08:12:16 danielk1977 Exp $
4429844665
*/
4429944666
4430044667
4430144668
4430244669
/*
@@ -45551,13 +45918,16 @@
4555145918
}
4555245919
}
4555345920
4555445921
/* If there are any write-transactions at all, invoke the commit hook */
4555545922
if( needXcommit && db->xCommitCallback ){
45923
+ assert( (db->flags & SQLITE_CommitBusy)==0 );
45924
+ db->flags |= SQLITE_CommitBusy;
4555645925
(void)sqlite3SafetyOff(db);
4555745926
rc = db->xCommitCallback(db->pCommitArg);
4555845927
(void)sqlite3SafetyOn(db);
45928
+ db->flags &= ~SQLITE_CommitBusy;
4555945929
if( rc ){
4556045930
return SQLITE_CONSTRAINT;
4556145931
}
4556245932
}
4556345933
@@ -45855,10 +46225,11 @@
4585546225
/* We are forced to roll back the active transaction. Before doing
4585646226
** so, abort any other statements this handle currently has active.
4585746227
*/
4585846228
invalidateCursorsOnModifiedBtrees(db);
4585946229
sqlite3RollbackAll(db);
46230
+ sqlite3CloseSavepoints(db);
4586046231
db->autoCommit = 1;
4586146232
}
4586246233
}
4586346234
}
4586446235
@@ -45869,10 +46240,11 @@
4586946240
** above has occurred.
4587046241
*/
4587146242
if( !sqlite3VtabInSync(db)
4587246243
&& db->autoCommit
4587346244
&& db->writeVdbeCnt==(p->readOnly==0)
46245
+ && (db->flags & SQLITE_CommitBusy)==0
4587446246
){
4587546247
if( p->rc==SQLITE_OK || (p->errorAction==OE_Fail && !isSpecialError) ){
4587646248
/* The auto-commit flag is true, and the vdbe program was
4587746249
** successful or hit an 'OR FAIL' constraint. This means a commit
4587846250
** is required.
@@ -45898,10 +46270,11 @@
4589846270
}else if( p->errorAction==OE_Abort ){
4589946271
xFunc = sqlite3BtreeRollbackStmt;
4590046272
}else{
4590146273
invalidateCursorsOnModifiedBtrees(db);
4590246274
sqlite3RollbackAll(db);
46275
+ sqlite3CloseSavepoints(db);
4590346276
db->autoCommit = 1;
4590446277
}
4590546278
}
4590646279
4590746280
/* If xFunc is not NULL, then it is one of sqlite3BtreeRollbackStmt or
@@ -48171,11 +48544,11 @@
4817148544
** documentation, headers files, or other derived files. The formatting
4817248545
** of the code in this file is, therefore, important. See other comments
4817348546
** in this file for details. If in doubt, do not deviate from existing
4817448547
** commenting and indentation practices when changing or adding code.
4817548548
**
48176
-** $Id: vdbe.c,v 1.803 2008/12/15 15:27:52 drh Exp $
48549
+** $Id: vdbe.c,v 1.810 2009/01/05 22:30:39 drh Exp $
4817748550
*/
4817848551
4817948552
/*
4818048553
** The following global variable is incremented every time a cursor
4818148554
** moves, either by the OP_SeekXX, OP_Next, or OP_Prev opcodes. The test
@@ -48715,10 +49088,30 @@
4871549088
rc = sqlite3OsAccess(db->pVfs, zFile, SQLITE_ACCESS_EXISTS, &res);
4871649089
return (res && rc==SQLITE_OK);
4871749090
}
4871849091
#endif
4871949092
49093
+#ifndef NDEBUG
49094
+/*
49095
+** This function is only called from within an assert() expression. It
49096
+** checks that the sqlite3.nTransaction variable is correctly set to
49097
+** the number of non-transaction savepoints currently in the
49098
+** linked list starting at sqlite3.pSavepoint.
49099
+**
49100
+** Usage:
49101
+**
49102
+** assert( checkSavepointCount(db) );
49103
+*/
49104
+static int checkSavepointCount(sqlite3 *db){
49105
+ int n = 0;
49106
+ Savepoint *p;
49107
+ for(p=db->pSavepoint; p; p=p->pNext) n++;
49108
+ assert( n==(db->nSavepoint + db->isTransactionSavepoint) );
49109
+ return 1;
49110
+}
49111
+#endif
49112
+
4872049113
/*
4872149114
** Execute as much of a VDBE program as we can then return.
4872249115
**
4872349116
** sqlite3VdbeMakeReady() must be called before this routine in order to
4872449117
** close the program with a final OP_Halt and to set up the callbacks
@@ -49005,15 +49398,12 @@
4900549398
4900649399
/* Opcode: Yield P1 * * * *
4900749400
**
4900849401
** Swap the program counter with the value in register P1.
4900949402
*/
49010
-case OP_Yield: {
49403
+case OP_Yield: { /* in1 */
4901149404
int pcDest;
49012
- assert( pOp->p1>0 );
49013
- assert( pOp->p1<=p->nMem );
49014
- pIn1 = &p->aMem[pOp->p1];
4901549405
assert( (pIn1->flags & MEM_Dyn)==0 );
4901649406
pIn1->flags = MEM_Int;
4901749407
pcDest = (int)pIn1->u.i;
4901849408
pIn1->u.i = pc;
4901949409
REGISTER_TRACE(pOp->p1, pIn1);
@@ -49229,14 +49619,11 @@
4922949619
** Make a copy of register P1 into register P2.
4923049620
**
4923149621
** This instruction makes a deep copy of the value. A duplicate
4923249622
** is made of any string or blob constant. See also OP_SCopy.
4923349623
*/
49234
-case OP_Copy: {
49235
- assert( pOp->p1>0 );
49236
- assert( pOp->p1<=p->nMem );
49237
- pIn1 = &p->aMem[pOp->p1];
49624
+case OP_Copy: { /* in1 */
4923849625
assert( pOp->p2>0 );
4923949626
assert( pOp->p2<=p->nMem );
4924049627
pOut = &p->aMem[pOp->p2];
4924149628
assert( pOut!=pIn1 );
4924249629
sqlite3VdbeMemShallowCopy(pOut, pIn1, MEM_Ephem);
@@ -49255,14 +49642,11 @@
4925549642
** Worse, if the original is deallocated, the copy becomes invalid.
4925649643
** Thus the program must guarantee that the original will not change
4925749644
** during the lifetime of the copy. Use OP_Copy to make a complete
4925849645
** copy.
4925949646
*/
49260
-case OP_SCopy: {
49261
- assert( pOp->p1>0 );
49262
- assert( pOp->p1<=p->nMem );
49263
- pIn1 = &p->aMem[pOp->p1];
49647
+case OP_SCopy: { /* in1 */
4926449648
REGISTER_TRACE(pOp->p1, pIn1);
4926549649
assert( pOp->p2>0 );
4926649650
assert( pOp->p2<=p->nMem );
4926749651
pOut = &p->aMem[pOp->p2];
4926849652
assert( pOut!=pIn1 );
@@ -49708,11 +50092,11 @@
4970850092
assert( MEM_Str==(MEM_Blob>>3) );
4970950093
pIn1->flags |= (pIn1->flags&MEM_Blob)>>3;
4971050094
applyAffinity(pIn1, SQLITE_AFF_TEXT, encoding);
4971150095
rc = ExpandBlob(pIn1);
4971250096
assert( pIn1->flags & MEM_Str || db->mallocFailed );
49713
- pIn1->flags &= ~(MEM_Int|MEM_Real|MEM_Blob);
50097
+ pIn1->flags &= ~(MEM_Int|MEM_Real|MEM_Blob|MEM_Zero);
4971450098
UPDATE_MAX_BLOBSIZE(pIn1);
4971550099
break;
4971650100
}
4971750101
4971850102
/* Opcode: ToBlob P1 * * * *
@@ -49727,12 +50111,14 @@
4972750111
case OP_ToBlob: { /* same as TK_TO_BLOB, in1 */
4972850112
if( pIn1->flags & MEM_Null ) break;
4972950113
if( (pIn1->flags & MEM_Blob)==0 ){
4973050114
applyAffinity(pIn1, SQLITE_AFF_TEXT, encoding);
4973150115
assert( pIn1->flags & MEM_Str || db->mallocFailed );
50116
+ MemSetTypeFlag(pIn1, MEM_Blob);
50117
+ }else{
50118
+ pIn1->flags &= ~(MEM_TypeMask&~MEM_Blob);
4973250119
}
49733
- MemSetTypeFlag(pIn1, MEM_Blob);
4973450120
UPDATE_MAX_BLOBSIZE(pIn1);
4973550121
break;
4973650122
}
4973750123
4973850124
/* Opcode: ToNumeric P1 * * * *
@@ -50571,10 +50957,144 @@
5057150957
p->openedStatement = 1;
5057250958
}
5057350959
}
5057450960
break;
5057550961
}
50962
+
50963
+/* Opcode: Savepoint P1 * * P4 *
50964
+**
50965
+** Open, release or rollback the savepoint named by parameter P4, depending
50966
+** on the value of P1. To open a new savepoint, P1==0. To release (commit) an
50967
+** existing savepoint, P1==1, or to rollback an existing savepoint P1==2.
50968
+*/
50969
+case OP_Savepoint: {
50970
+ int p1 = pOp->p1;
50971
+ char *zName = pOp->p4.z; /* Name of savepoint */
50972
+
50973
+ /* Assert that the p1 parameter is valid. Also that if there is no open
50974
+ ** transaction, then there cannot be any savepoints.
50975
+ */
50976
+ assert( db->pSavepoint==0 || db->autoCommit==0 );
50977
+ assert( p1==SAVEPOINT_BEGIN||p1==SAVEPOINT_RELEASE||p1==SAVEPOINT_ROLLBACK );
50978
+ assert( db->pSavepoint || db->isTransactionSavepoint==0 );
50979
+ assert( checkSavepointCount(db) );
50980
+
50981
+ if( p1==SAVEPOINT_BEGIN ){
50982
+ if( db->writeVdbeCnt>0 ){
50983
+ /* A new savepoint cannot be created if there are active write
50984
+ ** statements (i.e. open read/write incremental blob handles).
50985
+ */
50986
+ sqlite3SetString(&p->zErrMsg, db, "cannot open savepoint - "
50987
+ "SQL statements in progress");
50988
+ rc = SQLITE_BUSY;
50989
+ }else{
50990
+ int nName = sqlite3Strlen30(zName);
50991
+ Savepoint *pNew;
50992
+
50993
+ /* Create a new savepoint structure. */
50994
+ pNew = sqlite3DbMallocRaw(db, sizeof(Savepoint)+nName+1);
50995
+ if( pNew ){
50996
+ pNew->zName = (char *)&pNew[1];
50997
+ memcpy(pNew->zName, zName, nName+1);
50998
+
50999
+ /* If there is no open transaction, then mark this as a special
51000
+ ** "transaction savepoint". */
51001
+ if( db->autoCommit ){
51002
+ db->autoCommit = 0;
51003
+ db->isTransactionSavepoint = 1;
51004
+ }else{
51005
+ db->nSavepoint++;
51006
+ }
51007
+
51008
+ /* Link the new savepoint into the database handle's list. */
51009
+ pNew->pNext = db->pSavepoint;
51010
+ db->pSavepoint = pNew;
51011
+ }
51012
+ }
51013
+ }else{
51014
+ Savepoint *pSavepoint;
51015
+ int iSavepoint = 0;
51016
+
51017
+ /* Find the named savepoint. If there is no such savepoint, then an
51018
+ ** an error is returned to the user. */
51019
+ for(
51020
+ pSavepoint=db->pSavepoint;
51021
+ pSavepoint && sqlite3StrICmp(pSavepoint->zName, zName);
51022
+ pSavepoint=pSavepoint->pNext
51023
+ ){
51024
+ iSavepoint++;
51025
+ }
51026
+ if( !pSavepoint ){
51027
+ sqlite3SetString(&p->zErrMsg, db, "no such savepoint: %s", zName);
51028
+ rc = SQLITE_ERROR;
51029
+ }else if(
51030
+ db->writeVdbeCnt>0 || (p1==SAVEPOINT_ROLLBACK && db->activeVdbeCnt>1)
51031
+ ){
51032
+ /* It is not possible to release (commit) a savepoint if there are
51033
+ ** active write statements. It is not possible to rollback a savepoint
51034
+ ** if there are any active statements at all.
51035
+ */
51036
+ sqlite3SetString(&p->zErrMsg, db,
51037
+ "cannot %s savepoint - SQL statements in progress",
51038
+ (p1==SAVEPOINT_ROLLBACK ? "rollback": "release")
51039
+ );
51040
+ rc = SQLITE_BUSY;
51041
+ }else{
51042
+
51043
+ /* Determine whether or not this is a transaction savepoint. If so,
51044
+ ** and this is a RELEASE command, then the current transaction
51045
+ ** is committed.
51046
+ */
51047
+ int isTransaction = pSavepoint->pNext==0 && db->isTransactionSavepoint;
51048
+ if( isTransaction && p1==SAVEPOINT_RELEASE ){
51049
+ db->autoCommit = 1;
51050
+ if( sqlite3VdbeHalt(p)==SQLITE_BUSY ){
51051
+ p->pc = pc;
51052
+ db->autoCommit = 0;
51053
+ p->rc = rc = SQLITE_BUSY;
51054
+ goto vdbe_return;
51055
+ }
51056
+ db->isTransactionSavepoint = 0;
51057
+ rc = p->rc;
51058
+ }else{
51059
+ int ii;
51060
+ iSavepoint = db->nSavepoint - iSavepoint - 1;
51061
+ for(ii=0; ii<db->nDb; ii++){
51062
+ rc = sqlite3BtreeSavepoint(db->aDb[ii].pBt, p1, iSavepoint);
51063
+ if( rc!=SQLITE_OK ){
51064
+ goto abort_due_to_error;
51065
+ }
51066
+ }
51067
+ if( p1==SAVEPOINT_ROLLBACK && (db->flags&SQLITE_InternChanges)!=0 ){
51068
+ sqlite3ExpirePreparedStatements(db);
51069
+ sqlite3ResetInternalSchema(db, 0);
51070
+ }
51071
+ }
51072
+
51073
+ /* Regardless of whether this is a RELEASE or ROLLBACK, destroy all
51074
+ ** savepoints nested inside of the savepoint being operated on. */
51075
+ while( db->pSavepoint!=pSavepoint ){
51076
+ Savepoint *pTmp = db->pSavepoint;
51077
+ db->pSavepoint = pTmp->pNext;
51078
+ sqlite3DbFree(db, pTmp);
51079
+ db->nSavepoint--;
51080
+ }
51081
+
51082
+ /* If it is a RELEASE, then destroy the savepoint being operated on too */
51083
+ if( p1==SAVEPOINT_RELEASE ){
51084
+ assert( pSavepoint==db->pSavepoint );
51085
+ db->pSavepoint = pSavepoint->pNext;
51086
+ sqlite3DbFree(db, pSavepoint);
51087
+ if( !isTransaction ){
51088
+ db->nSavepoint--;
51089
+ }
51090
+ }
51091
+ }
51092
+ }
51093
+
51094
+ break;
51095
+}
5057651096
5057751097
/* Opcode: AutoCommit P1 P2 * * *
5057851098
**
5057951099
** Set the database auto-commit flag to P1 (1 or 0). If P2 is true, roll
5058051100
** back any currently active btree transactions. If there are any active
@@ -50606,11 +51126,11 @@
5060651126
*/
5060751127
sqlite3SetString(&p->zErrMsg, db, "cannot commit transaction - "
5060851128
"SQL statements in progress");
5060951129
rc = SQLITE_BUSY;
5061051130
}else if( desiredAutoCommit!=db->autoCommit ){
50611
- if( pOp->p2 ){
51131
+ if( rollback ){
5061251132
assert( desiredAutoCommit==1 );
5061351133
sqlite3RollbackAll(db);
5061451134
db->autoCommit = 1;
5061551135
}else{
5061651136
db->autoCommit = (u8)desiredAutoCommit;
@@ -50619,10 +51139,11 @@
5061951139
db->autoCommit = (u8)(1-desiredAutoCommit);
5062051140
p->rc = rc = SQLITE_BUSY;
5062151141
goto vdbe_return;
5062251142
}
5062351143
}
51144
+ sqlite3CloseSavepoints(db);
5062451145
if( p->rc==SQLITE_OK ){
5062551146
rc = SQLITE_DONE;
5062651147
}else{
5062751148
rc = SQLITE_ERROR;
5062851149
}
@@ -52569,20 +53090,20 @@
5256953090
Mem *pIdx;
5257053091
i64 val;
5257153092
assert( pOp->p1>0 && pOp->p1<=p->nMem );
5257253093
CHECK_FOR_INTERRUPT;
5257353094
pIdx = &p->aMem[pOp->p1];
53095
+ pOut = &p->aMem[pOp->p3];
5257453096
if( (pIdx->flags & MEM_RowSet)==0
5257553097
|| sqlite3RowSetNext(pIdx->u.pRowSet, &val)==0
5257653098
){
5257753099
/* The boolean index is empty */
5257853100
sqlite3VdbeMemSetNull(pIdx);
5257953101
pc = pOp->p2 - 1;
5258053102
}else{
5258153103
/* A value was pulled from the index */
5258253104
assert( pOp->p3>0 && pOp->p3<=p->nMem );
52583
- pOut = &p->aMem[pOp->p3];
5258453105
sqlite3VdbeMemSetInt64(pOut, val);
5258553106
}
5258653107
break;
5258753108
}
5258853109
@@ -54011,11 +54532,11 @@
5401154532
**
5401254533
** This file contains code use to implement an in-memory rollback journal.
5401354534
** The in-memory rollback journal is used to journal transactions for
5401454535
** ":memory:" databases and when the journal_mode=MEMORY pragma is used.
5401554536
**
54016
-** @(#) $Id: memjournal.c,v 1.7 2008/12/10 21:19:57 drh Exp $
54537
+** @(#) $Id: memjournal.c,v 1.8 2008/12/20 02:14:40 drh Exp $
5401754538
*/
5401854539
5401954540
/* Forward references to internal structures */
5402054541
typedef struct MemJournal MemJournal;
5402154542
typedef struct FilePoint FilePoint;
@@ -54236,11 +54757,11 @@
5423654757
5423754758
/*
5423854759
** Return the number of bytes required to store a MemJournal that uses vfs
5423954760
** pVfs to create the underlying on-disk files.
5424054761
*/
54241
-SQLITE_PRIVATE int sqlite3MemJournalSize(){
54762
+SQLITE_PRIVATE int sqlite3MemJournalSize(void){
5424254763
return sizeof(MemJournal);
5424354764
}
5424454765
5424554766
/************** End of memjournal.c ******************************************/
5424654767
/************** Begin file walker.c ******************************************/
@@ -60509,11 +61030,11 @@
6050961030
** creating ID lists
6051061031
** BEGIN TRANSACTION
6051161032
** COMMIT
6051261033
** ROLLBACK
6051361034
**
60514
-** $Id: build.c,v 1.508 2008/12/10 22:30:25 shane Exp $
61035
+** $Id: build.c,v 1.511 2008/12/30 06:24:58 danielk1977 Exp $
6051561036
*/
6051661037
6051761038
/*
6051861039
** This routine is called when a new SQL statement is beginning to
6051961040
** be parsed. Initialize the pParse structure as needed.
@@ -61440,11 +61961,11 @@
6144061961
if( p->nCol+1>db->aLimit[SQLITE_LIMIT_COLUMN] ){
6144161962
sqlite3ErrorMsg(pParse, "too many columns on %s", p->zName);
6144261963
return;
6144361964
}
6144461965
#endif
61445
- z = sqlite3NameFromToken(pParse->db, pName);
61966
+ z = sqlite3NameFromToken(db, pName);
6144661967
if( z==0 ) return;
6144761968
for(i=0; i<p->nCol; i++){
6144861969
if( STRICMP(z, p->aCol[i].zName) ){
6144961970
sqlite3ErrorMsg(pParse, "duplicate column name: %s", z);
6145061971
sqlite3DbFree(db, z);
@@ -61451,11 +61972,11 @@
6145161972
return;
6145261973
}
6145361974
}
6145461975
if( (p->nCol & 0x7)==0 ){
6145561976
Column *aNew;
61456
- aNew = sqlite3DbRealloc(pParse->db,p->aCol,(p->nCol+8)*sizeof(p->aCol[0]));
61977
+ aNew = sqlite3DbRealloc(db,p->aCol,(p->nCol+8)*sizeof(p->aCol[0]));
6145761978
if( aNew==0 ){
6145861979
sqlite3DbFree(db, z);
6145961980
return;
6146061981
}
6146161982
p->aCol = aNew;
@@ -63795,10 +64316,30 @@
6379564316
v = sqlite3GetVdbe(pParse);
6379664317
if( v ){
6379764318
sqlite3VdbeAddOp2(v, OP_AutoCommit, 1, 1);
6379864319
}
6379964320
}
64321
+
64322
+/*
64323
+** This function is called by the parser when it parses a command to create,
64324
+** release or rollback an SQL savepoint.
64325
+*/
64326
+SQLITE_PRIVATE void sqlite3Savepoint(Parse *pParse, int op, Token *pName){
64327
+ char *zName = sqlite3NameFromToken(pParse->db, pName);
64328
+ if( zName ){
64329
+ Vdbe *v = sqlite3GetVdbe(pParse);
64330
+#ifndef SQLITE_OMIT_AUTHORIZATION
64331
+ static const char *az[] = { "BEGIN", "RELEASE", "ROLLBACK" };
64332
+ assert( !SAVEPOINT_BEGIN && SAVEPOINT_RELEASE==1 && SAVEPOINT_ROLLBACK==2 );
64333
+#endif
64334
+ if( !v || sqlite3AuthCheck(pParse, SQLITE_SAVEPOINT, az[op], zName, 0) ){
64335
+ sqlite3DbFree(pParse->db, zName);
64336
+ return;
64337
+ }
64338
+ sqlite3VdbeAddOp4(v, OP_Savepoint, op, 0, 0, zName, P4_DYNAMIC);
64339
+ }
64340
+}
6380064341
6380164342
/*
6380264343
** Make sure the TEMP database is open and available for use. Return
6380364344
** the number of errors. Leave any error messages in the pParse structure.
6380464345
*/
@@ -64540,11 +65081,11 @@
6454065081
**
6454165082
*************************************************************************
6454265083
** This file contains C code routines that are called by the parser
6454365084
** in order to generate code for DELETE FROM statements.
6454465085
**
64545
-** $Id: delete.c,v 1.190 2008/12/10 21:19:57 drh Exp $
65086
+** $Id: delete.c,v 1.191 2008/12/23 23:56:22 drh Exp $
6454665087
*/
6454765088
6454865089
/*
6454965090
** Look up every table that is named in pSrc. If any table is not found,
6455065091
** add an error message to pParse->zErrMsg and return NULL. If all tables
@@ -64919,25 +65460,19 @@
6491965460
*/
6492065461
{
6492165462
int iRowid = ++pParse->nMem; /* Used for storing rowid values. */
6492265463
int iRowSet = ++pParse->nMem; /* Register for rowset of rows to delete */
6492365464
64924
- /* Begin the database scan
64925
- */
64926
- pWInfo = sqlite3WhereBegin(pParse, pTabList, pWhere, 0, 0);
64927
- if( pWInfo==0 ) goto delete_from_cleanup;
64928
-
64929
- /* Remember the rowid of every item to be deleted.
64930
- */
64931
- sqlite3VdbeAddOp2(v, IsVirtual(pTab) ? OP_VRowid : OP_Rowid, iCur, iRowid);
64932
- sqlite3VdbeAddOp2(v, OP_RowSetAdd, iRowSet, iRowid);
65465
+ /* Collect rowids of every row to be deleted.
65466
+ */
65467
+ sqlite3VdbeAddOp2(v, OP_Null, 0, iRowSet);
65468
+ pWInfo = sqlite3WhereBegin(pParse, pTabList, pWhere, 0,
65469
+ WHERE_FILL_ROWSET, iRowSet);
65470
+ if( pWInfo==0 ) goto delete_from_cleanup;
6493365471
if( db->flags & SQLITE_CountRows ){
6493465472
sqlite3VdbeAddOp2(v, OP_AddImm, memCnt, 1);
6493565473
}
64936
-
64937
- /* End the database scan loop.
64938
- */
6493965474
sqlite3WhereEnd(pWInfo);
6494065475
6494165476
/* Open the pseudo-table used to store OLD if there are triggers.
6494265477
*/
6494365478
if( triggers_exist ){
@@ -69450,11 +69985,11 @@
6945069985
** May you share freely, never taking more than you give.
6945169986
**
6945269987
*************************************************************************
6945369988
** This file contains code used to implement the PRAGMA command.
6945469989
**
69455
-** $Id: pragma.c,v 1.199 2008/12/10 23:04:13 drh Exp $
69990
+** $Id: pragma.c,v 1.200 2009/01/09 21:41:17 drh Exp $
6945669991
*/
6945769992
6945869993
/* Ignore this whole file if pragmas are disabled
6945969994
*/
6946069995
#if !defined(SQLITE_OMIT_PRAGMA) && !defined(SQLITE_OMIT_PARSER)
@@ -69633,11 +70168,12 @@
6963370168
for(i=0, p=aPragma; i<ArraySize(aPragma); i++, p++){
6963470169
if( sqlite3StrICmp(zLeft, p->zName)==0 ){
6963570170
sqlite3 *db = pParse->db;
6963670171
Vdbe *v;
6963770172
v = sqlite3GetVdbe(pParse);
69638
- if( v ){
70173
+ assert( v!=0 ); /* Already allocated by sqlite3Pragma() */
70174
+ if( ALWAYS(v) ){
6963970175
if( zRight==0 ){
6964070176
returnSingleInt(pParse, p->zName, (db->flags & p->mask)!=0 );
6964170177
}else{
6964270178
if( getBoolean(zRight) ){
6964370179
db->flags |= p->mask;
@@ -69658,18 +70194,23 @@
6965870194
}
6965970195
return 0;
6966070196
}
6966170197
#endif /* SQLITE_OMIT_FLAG_PRAGMAS */
6966270198
70199
+/*
70200
+** Return a human-readable name for a constraint resolution action.
70201
+*/
6966370202
static const char *actionName(u8 action){
70203
+ const char *zName;
6966470204
switch( action ){
69665
- case OE_SetNull: return "SET NULL";
69666
- case OE_SetDflt: return "SET DEFAULT";
69667
- case OE_Restrict: return "RESTRICT";
69668
- case OE_Cascade: return "CASCADE";
70205
+ case OE_SetNull: zName = "SET NULL"; break;
70206
+ case OE_SetDflt: zName = "SET DEFAULT"; break;
70207
+ case OE_Cascade: zName = "CASCADE"; break;
70208
+ default: zName = "RESTRICT";
70209
+ assert( action==OE_Restrict ); break;
6966970210
}
69670
- return "";
70211
+ return zName;
6967170212
}
6967270213
6967370214
/*
6967470215
** Process a pragma statement.
6967570216
**
@@ -69722,11 +70263,12 @@
6972270263
zRight = sqlite3MPrintf(db, "-%T", pValue);
6972370264
}else{
6972470265
zRight = sqlite3NameFromToken(db, pValue);
6972570266
}
6972670267
69727
- zDb = ((pId2 && pId2->n>0)?pDb->zName:0);
70268
+ assert( pId2 );
70269
+ zDb = pId2->n>0 ? pDb->zName : 0;
6972870270
if( sqlite3AuthCheck(pParse, SQLITE_PRAGMA, zLeft, zRight, zDb) ){
6972970271
goto pragma_out;
6973070272
}
6973170273
6973270274
#ifndef SQLITE_OMIT_PAGER_PRAGMAS
@@ -69790,12 +70332,13 @@
6979070332
** database page size value. The value can only be set if
6979170333
** the database has not yet been created.
6979270334
*/
6979370335
if( sqlite3StrICmp(zLeft,"page_size")==0 ){
6979470336
Btree *pBt = pDb->pBt;
70337
+ assert( pBt!=0 );
6979570338
if( !zRight ){
69796
- int size = pBt ? sqlite3BtreeGetPageSize(pBt) : 0;
70339
+ int size = ALWAYS(pBt) ? sqlite3BtreeGetPageSize(pBt) : 0;
6979770340
returnSingleInt(pParse, "page_size", size);
6979870341
}else{
6979970342
/* Malloc may fail when setting the page-size, as there is an internal
6980070343
** buffer that the pager module resizes using sqlite3_realloc().
6980170344
*/
@@ -69816,14 +70359,15 @@
6981670359
** forms return the current setting.
6981770360
*/
6981870361
if( sqlite3StrICmp(zLeft,"max_page_count")==0 ){
6981970362
Btree *pBt = pDb->pBt;
6982070363
int newMax = 0;
70364
+ assert( pBt!=0 );
6982170365
if( zRight ){
6982270366
newMax = atoi(zRight);
6982370367
}
69824
- if( pBt ){
70368
+ if( ALWAYS(pBt) ){
6982570369
newMax = sqlite3BtreeMaxPageCount(pBt, newMax);
6982670370
}
6982770371
returnSingleInt(pParse, "max_page_count", newMax);
6982870372
}else
6982970373
@@ -69832,11 +70376,11 @@
6983270376
**
6983370377
** Return the number of pages in the specified database.
6983470378
*/
6983570379
if( sqlite3StrICmp(zLeft,"page_count")==0 ){
6983670380
int iReg;
69837
- if( !v || sqlite3ReadSchema(pParse) ) goto pragma_out;
70381
+ if( sqlite3ReadSchema(pParse) ) goto pragma_out;
6983870382
sqlite3CodeVerifySchema(pParse, iDb);
6983970383
iReg = ++pParse->nMem;
6984070384
sqlite3VdbeAddOp2(v, OP_Pagecount, iDb, iReg);
6984170385
sqlite3VdbeAddOp2(v, OP_ResultRow, iReg, 1);
6984270386
sqlite3VdbeSetNumCols(v, 1);
@@ -69980,21 +70524,27 @@
6998070524
** Get or set the (boolean) value of the database 'auto-vacuum' parameter.
6998170525
*/
6998270526
#ifndef SQLITE_OMIT_AUTOVACUUM
6998370527
if( sqlite3StrICmp(zLeft,"auto_vacuum")==0 ){
6998470528
Btree *pBt = pDb->pBt;
70529
+ assert( pBt!=0 );
6998570530
if( sqlite3ReadSchema(pParse) ){
6998670531
goto pragma_out;
6998770532
}
6998870533
if( !zRight ){
69989
- int auto_vacuum =
69990
- pBt ? sqlite3BtreeGetAutoVacuum(pBt) : SQLITE_DEFAULT_AUTOVACUUM;
70534
+ int auto_vacuum;
70535
+ if( ALWAYS(pBt) ){
70536
+ auto_vacuum = sqlite3BtreeGetAutoVacuum(pBt);
70537
+ }else{
70538
+ auto_vacuum = SQLITE_DEFAULT_AUTOVACUUM;
70539
+ }
6999170540
returnSingleInt(pParse, "auto_vacuum", auto_vacuum);
6999270541
}else{
6999370542
int eAuto = getAutoVacuum(zRight);
70543
+ assert( eAuto>=0 && eAuto<=2 );
6999470544
db->nextAutovac = (u8)eAuto;
69995
- if( eAuto>=0 ){
70545
+ if( ALWAYS(eAuto>=0) ){
6999670546
/* Call SetAutoVacuum() to set initialize the internal auto and
6999770547
** incr-vacuum flags. This is required in case this connection
6999870548
** creates the database file. It is important that it is created
6999970549
** as an auto-vacuum capable db.
7000070550
*/
@@ -70141,10 +70691,18 @@
7014170691
}
7014270692
#endif /* SQLITE_OMIT_WSD */
7014370693
}
7014470694
}else
7014570695
70696
+#if !defined(SQLITE_ENABLE_LOCKING_STYLE)
70697
+# if defined(__APPLE__)
70698
+# define SQLITE_ENABLE_LOCKING_STYLE 1
70699
+# else
70700
+# define SQLITE_ENABLE_LOCKING_STYLE 0
70701
+# endif
70702
+#endif
70703
+#if SQLITE_ENABLE_LOCKING_STYLE
7014670704
/*
7014770705
** PRAGMA [database.]lock_proxy_file
7014870706
** PRAGMA [database.]lock_proxy_file = ":auto:"|"lock_file_path"
7014970707
**
7015070708
** Return or set the value of the lock_proxy_file flag. Changing
@@ -70181,11 +70739,11 @@
7018170739
sqlite3ErrorMsg(pParse, "failed to set lock proxy file");
7018270740
goto pragma_out;
7018370741
}
7018470742
}
7018570743
}else
70186
-
70744
+#endif /* SQLITE_ENABLE_LOCKING_STYLE */
7018770745
7018870746
/*
7018970747
** PRAGMA [database.]synchronous
7019070748
** PRAGMA [database.]synchronous=OFF|ON|NORMAL|FULL
7019170749
**
@@ -70255,11 +70813,13 @@
7025570813
sqlite3VdbeAddOp2(v, OP_Integer, i-nHidden, 1);
7025670814
sqlite3VdbeAddOp4(v, OP_String8, 0, 2, 0, pCol->zName, 0);
7025770815
sqlite3VdbeAddOp4(v, OP_String8, 0, 3, 0,
7025870816
pCol->zType ? pCol->zType : "", 0);
7025970817
sqlite3VdbeAddOp2(v, OP_Integer, (pCol->notNull ? 1 : 0), 4);
70260
- if( pCol->pDflt && (pDflt = &pCol->pDflt->span)->z ){
70818
+ if( pCol->pDflt ){
70819
+ pDflt = &pCol->pDflt->span;
70820
+ assert( pDflt->z );
7026170821
sqlite3VdbeAddOp4(v, OP_String8, 0, 5, 0, (char*)pDflt->z, pDflt->n);
7026270822
}else{
7026370823
sqlite3VdbeAddOp2(v, OP_Null, 0, 5);
7026470824
}
7026570825
sqlite3VdbeAddOp2(v, OP_Integer, pCol->isPrimKey, 6);
@@ -70615,15 +71175,15 @@
7061571175
if( sqlite3StrICmp(zLeft, "encoding")==0 ){
7061671176
static const struct EncName {
7061771177
char *zName;
7061871178
u8 enc;
7061971179
} encnames[] = {
70620
- { "UTF-8", SQLITE_UTF8 },
7062171180
{ "UTF8", SQLITE_UTF8 },
70622
- { "UTF-16le", SQLITE_UTF16LE },
71181
+ { "UTF-8", SQLITE_UTF8 }, /* Must be element [1] */
71182
+ { "UTF-16le", SQLITE_UTF16LE }, /* Must be element [2] */
71183
+ { "UTF-16be", SQLITE_UTF16BE }, /* Must be element [3] */
7062371184
{ "UTF16le", SQLITE_UTF16LE },
70624
- { "UTF-16be", SQLITE_UTF16BE },
7062571185
{ "UTF16be", SQLITE_UTF16BE },
7062671186
{ "UTF-16", 0 }, /* SQLITE_UTF16NATIVE */
7062771187
{ "UTF16", 0 }, /* SQLITE_UTF16NATIVE */
7062871188
{ 0, 0 }
7062971189
};
@@ -70631,16 +71191,14 @@
7063171191
if( !zRight ){ /* "PRAGMA encoding" */
7063271192
if( sqlite3ReadSchema(pParse) ) goto pragma_out;
7063371193
sqlite3VdbeSetNumCols(v, 1);
7063471194
sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "encoding", SQLITE_STATIC);
7063571195
sqlite3VdbeAddOp2(v, OP_String8, 0, 1);
70636
- for(pEnc=&encnames[0]; pEnc->zName; pEnc++){
70637
- if( pEnc->enc==ENC(pParse->db) ){
70638
- sqlite3VdbeChangeP4(v, -1, pEnc->zName, P4_STATIC);
70639
- break;
70640
- }
70641
- }
71196
+ assert( encnames[SQLITE_UTF8].enc==SQLITE_UTF8 );
71197
+ assert( encnames[SQLITE_UTF16LE].enc==SQLITE_UTF16LE );
71198
+ assert( encnames[SQLITE_UTF16BE].enc==SQLITE_UTF16BE );
71199
+ sqlite3VdbeChangeP4(v, -1, encnames[ENC(pParse->db)].zName, P4_STATIC);
7064271200
sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 1);
7064371201
}else{ /* "PRAGMA encoding = XXX" */
7064471202
/* Only change the value of sqlite.enc if the database handle is not
7064571203
** initialized. If the main database exists, the new sqlite.enc value
7064671204
** will be overwritten when the schema is next loaded. If it does not
@@ -70781,12 +71339,30 @@
7078171339
sqlite3CreateStatementsTable(pParse);
7078271340
}else
7078371341
#endif
7078471342
7078571343
#if SQLITE_HAS_CODEC
70786
- if( sqlite3StrICmp(zLeft, "key")==0 ){
71344
+ if( sqlite3StrICmp(zLeft, "key")==0 && zRight ){
7078771345
sqlite3_key(db, zRight, sqlite3Strlen30(zRight));
71346
+ }else
71347
+ if( sqlite3StrICmp(zLeft, "rekey")==0 && zRight ){
71348
+ sqlite3_rekey(db, zRight, sqlite3Strlen30(zRight));
71349
+ }else
71350
+ if( zRight && (sqlite3StrICmp(zLeft, "hexkey")==0 ||
71351
+ sqlite3StrICmp(zLeft, "hexrekey")==0) ){
71352
+ int i, h1, h2;
71353
+ char zKey[40];
71354
+ for(i=0; (h1 = zRight[i])!=0 && (h2 = zRight[i+1])!=0; i+=2){
71355
+ h1 += 9*(1&(h1>>6));
71356
+ h2 += 9*(1&(h2>>6));
71357
+ zKey[i/2] = (h2 & 0x0f) | ((h1 & 0xf)<<4);
71358
+ }
71359
+ if( (zLeft[3] & 0xf)==0xb ){
71360
+ sqlite3_key(db, zKey, i/2);
71361
+ }else{
71362
+ sqlite3_rekey(db, zKey, i/2);
71363
+ }
7078871364
}else
7078971365
#endif
7079071366
#if SQLITE_HAS_CODEC || defined(SQLITE_ENABLE_CEROD)
7079171367
if( sqlite3StrICmp(zLeft, "activate_extensions")==0 ){
7079271368
#if SQLITE_HAS_CODEC
@@ -70799,33 +71375,32 @@
7079971375
if( sqlite3StrNICmp(zRight, "cerod-", 6)==0 ){
7080071376
extern void sqlite3_activate_cerod(const char*);
7080171377
sqlite3_activate_cerod(&zRight[6]);
7080271378
}
7080371379
#endif
70804
- }
71380
+ }else
7080571381
#endif
7080671382
70807
- {}
70808
-
70809
- if( v ){
70810
- /* Code an OP_Expire at the end of each PRAGMA program to cause
70811
- ** the VDBE implementing the pragma to expire. Most (all?) pragmas
70812
- ** are only valid for a single execution.
70813
- */
70814
- sqlite3VdbeAddOp2(v, OP_Expire, 1, 0);
70815
-
70816
- /*
70817
- ** Reset the safety level, in case the fullfsync flag or synchronous
70818
- ** setting changed.
70819
- */
71383
+
71384
+ {/* Empty ELSE clause */}
71385
+
71386
+ /* Code an OP_Expire at the end of each PRAGMA program to cause
71387
+ ** the VDBE implementing the pragma to expire. Most (all?) pragmas
71388
+ ** are only valid for a single execution.
71389
+ */
71390
+ sqlite3VdbeAddOp2(v, OP_Expire, 1, 0);
71391
+
71392
+ /*
71393
+ ** Reset the safety level, in case the fullfsync flag or synchronous
71394
+ ** setting changed.
71395
+ */
7082071396
#ifndef SQLITE_OMIT_PAGER_PRAGMAS
70821
- if( db->autoCommit ){
70822
- sqlite3BtreeSetSafetyLevel(pDb->pBt, pDb->safety_level,
70823
- (db->flags&SQLITE_FullFSync)!=0);
70824
- }
71397
+ if( db->autoCommit ){
71398
+ sqlite3BtreeSetSafetyLevel(pDb->pBt, pDb->safety_level,
71399
+ (db->flags&SQLITE_FullFSync)!=0);
71400
+ }
7082571401
#endif
70826
- }
7082771402
pragma_out:
7082871403
sqlite3DbFree(db, zLeft);
7082971404
sqlite3DbFree(db, zRight);
7083071405
}
7083171406
@@ -70846,11 +71421,11 @@
7084671421
*************************************************************************
7084771422
** This file contains the implementation of the sqlite3_prepare()
7084871423
** interface, and routines that contribute to loading the database schema
7084971424
** from disk.
7085071425
**
70851
-** $Id: prepare.c,v 1.103 2008/12/10 19:26:24 drh Exp $
71426
+** $Id: prepare.c,v 1.104 2009/01/09 02:49:32 drh Exp $
7085271427
*/
7085371428
7085471429
/*
7085571430
** Fill the InitData structure with an error message that indicates
7085671431
** that the database is corrupt.
@@ -71332,22 +71907,22 @@
7133271907
** expr.c is trying to resolve a reference to a transient table (i.e. one
7133371908
** created by a sub-select). In this case the return value of this
7133471909
** function should never be used.
7133571910
**
7133671911
** We return -1000000 instead of the more usual -1 simply because using
71337
- ** -1000000 as incorrectly using -1000000 index into db->aDb[] is much
71912
+ ** -1000000 as the incorrect index into db->aDb[] is much
7133871913
** more likely to cause a segfault than -1 (of course there are assert()
7133971914
** statements too, but it never hurts to play the odds).
7134071915
*/
7134171916
assert( sqlite3_mutex_held(db->mutex) );
7134271917
if( pSchema ){
71343
- for(i=0; i<db->nDb; i++){
71918
+ for(i=0; ALWAYS(i<db->nDb); i++){
7134471919
if( db->aDb[i].pSchema==pSchema ){
7134571920
break;
7134671921
}
7134771922
}
71348
- assert( i>=0 &&i>=0 && i<db->nDb );
71923
+ assert( i>=0 && i<db->nDb );
7134971924
}
7135071925
return i;
7135171926
}
7135271927
7135371928
/*
@@ -71657,11 +72232,11 @@
7165772232
**
7165872233
*************************************************************************
7165972234
** This file contains C code routines that are called by the parser
7166072235
** to handle SELECT statements in SQLite.
7166172236
**
71662
-** $Id: select.c,v 1.494 2008/12/10 22:15:00 drh Exp $
72237
+** $Id: select.c,v 1.498 2009/01/09 02:49:32 drh Exp $
7166372238
*/
7166472239
7166572240
7166672241
/*
7166772242
** Delete all the content of a Select structure but do not deallocate
@@ -71986,11 +72561,11 @@
7198672561
for(i=0; i<pSrc->nSrc-1; i++, pRight++, pLeft++){
7198772562
Table *pLeftTab = pLeft->pTab;
7198872563
Table *pRightTab = pRight->pTab;
7198972564
int isOuter;
7199072565
71991
- if( pLeftTab==0 || pRightTab==0 ) continue;
72566
+ if( NEVER(pLeftTab==0 || pRightTab==0) ) continue;
7199272567
isOuter = (pRight->jointype & JT_OUTER)!=0;
7199372568
7199472569
/* When the NATURAL keyword is present, add WHERE clause terms for
7199572570
** every column that the two tables have in common.
7199672571
*/
@@ -72186,11 +72761,12 @@
7218672761
int regResult; /* Start of memory holding result set */
7218772762
int eDest = pDest->eDest; /* How to dispose of results */
7218872763
int iParm = pDest->iParm; /* First argument to disposal method */
7218972764
int nResultCol; /* Number of result columns */
7219072765
72191
- if( v==0 ) return;
72766
+ assert( v );
72767
+ if( NEVER(v==0) ) return;
7219272768
assert( pEList!=0 );
7219372769
hasDistinct = distinct>=0;
7219472770
if( pOrderBy==0 && !hasDistinct ){
7219572771
codeOffset(v, p, iContinue);
7219672772
}
@@ -72204,15 +72780,12 @@
7220472780
}
7220572781
if( pDest->iMem==0 ){
7220672782
pDest->iMem = pParse->nMem+1;
7220772783
pDest->nMem = nResultCol;
7220872784
pParse->nMem += nResultCol;
72209
- }else if( pDest->nMem!=nResultCol ){
72210
- /* This happens when two SELECTs of a compound SELECT have differing
72211
- ** numbers of result columns. The error message will be generated by
72212
- ** a higher-level routine. */
72213
- return;
72785
+ }else{
72786
+ assert( pDest->nMem==nResultCol );
7221472787
}
7221572788
regResult = pDest->iMem;
7221672789
if( nColumn>0 ){
7221772790
for(i=0; i<nColumn; i++){
7221872791
sqlite3VdbeAddOp3(v, OP_Column, srcTab, i, regResult+i);
@@ -72457,10 +73030,12 @@
7245773030
regRowid = sqlite3GetTempReg(pParse);
7245873031
sqlite3VdbeAddOp3(v, OP_Column, iTab, pOrderBy->nExpr + 1, regRow);
7245973032
switch( eDest ){
7246073033
case SRT_Table:
7246173034
case SRT_EphemTab: {
73035
+ testcase( eDest==SRT_Table );
73036
+ testcase( eDest==SRT_EphemTab );
7246273037
sqlite3VdbeAddOp2(v, OP_NewRowid, iParm, regRowid);
7246373038
sqlite3VdbeAddOp3(v, OP_Insert, iParm, regRow, regRowid);
7246473039
sqlite3VdbeChangeP5(v, OPFLAG_APPEND);
7246573040
break;
7246673041
}
@@ -72480,10 +73055,12 @@
7248073055
}
7248173056
#endif
7248273057
case SRT_Output:
7248373058
case SRT_Coroutine: {
7248473059
int i;
73060
+ testcase( eDest==SRT_Output );
73061
+ testcase( eDest==SRT_Coroutine );
7248573062
sqlite3VdbeAddOp2(v, OP_Integer, 1, regRowid);
7248673063
sqlite3VdbeAddOp3(v, OP_Insert, pseudoTab, regRow, regRowid);
7248773064
for(i=0; i<nColumn; i++){
7248873065
assert( regRow!=pDest->iMem+i );
7248973066
sqlite3VdbeAddOp3(v, OP_Column, pseudoTab, i, pDest->iMem+i);
@@ -72590,11 +73167,11 @@
7259073167
if( pS ){
7259173168
/* The "table" is actually a sub-select or a view in the FROM clause
7259273169
** of the SELECT statement. Return the declaration type and origin
7259373170
** data for the result-set column of the sub-select.
7259473171
*/
72595
- if( iCol>=0 && iCol<pS->pEList->nExpr ){
73172
+ if( ALWAYS(iCol>=0 && iCol<pS->pEList->nExpr) ){
7259673173
/* If iCol is less than zero, then the expression requests the
7259773174
** rowid of the sub-select or view. This expression is legal (see
7259873175
** test case misc2.2.2) - it always evaluates to NULL.
7259973176
*/
7260073177
NameContext sNC;
@@ -72602,11 +73179,11 @@
7260273179
sNC.pSrcList = pS->pSrc;
7260373180
sNC.pNext = 0;
7260473181
sNC.pParse = pNC->pParse;
7260573182
zType = columnType(&sNC, p, &zOriginDb, &zOriginTab, &zOriginCol);
7260673183
}
72607
- }else if( pTab->pSchema ){
73184
+ }else if( ALWAYS(pTab->pSchema) ){
7260873185
/* A real table */
7260973186
assert( !pS );
7261073187
if( iCol<0 ) iCol = pTab->iPKey;
7261173188
assert( iCol==-1 || (iCol>=0 && iCol<pTab->nCol) );
7261273189
if( iCol<0 ){
@@ -72711,11 +73288,11 @@
7271173288
return;
7271273289
}
7271373290
#endif
7271473291
7271573292
assert( v!=0 );
72716
- if( pParse->colNamesSet || v==0 || db->mallocFailed ) return;
73293
+ if( pParse->colNamesSet || NEVER(v==0) || db->mallocFailed ) return;
7271773294
pParse->colNamesSet = 1;
7271873295
fullNames = (db->flags & SQLITE_FullColNames)!=0;
7271973296
shortNames = (db->flags & SQLITE_ShortColNames)!=0;
7272073297
sqlite3VdbeSetNumCols(v, pEList->nExpr);
7272173298
for(i=0; i<pEList->nExpr; i++){
@@ -72727,11 +73304,13 @@
7272773304
sqlite3VdbeSetColName(v, i, COLNAME_NAME, zName, SQLITE_TRANSIENT);
7272873305
}else if( (p->op==TK_COLUMN || p->op==TK_AGG_COLUMN) && pTabList ){
7272973306
Table *pTab;
7273073307
char *zCol;
7273173308
int iCol = p->iColumn;
72732
- for(j=0; j<pTabList->nSrc && pTabList->a[j].iCursor!=p->iTable; j++){}
73309
+ for(j=0; ALWAYS(j<pTabList->nSrc); j++){
73310
+ if( pTabList->a[j].iCursor==p->iTable ) break;
73311
+ }
7273373312
assert( j<pTabList->nSrc );
7273473313
pTab = pTabList->a[j].pTab;
7273573314
if( iCol<0 ) iCol = pTab->iPKey;
7273673315
assert( iCol==-1 || (iCol>=0 && iCol<pTab->nCol) );
7273773316
if( iCol<0 ){
@@ -72740,17 +73319,13 @@
7274073319
zCol = pTab->aCol[iCol].zName;
7274173320
}
7274273321
if( !shortNames && !fullNames ){
7274373322
sqlite3VdbeSetColName(v, i, COLNAME_NAME,
7274473323
sqlite3DbStrNDup(db, (char*)p->span.z, p->span.n), SQLITE_DYNAMIC);
72745
- }else if( fullNames || (!shortNames && pTabList->nSrc>1) ){
73324
+ }else if( fullNames ){
7274673325
char *zName = 0;
72747
- char *zTab;
72748
-
72749
- zTab = pTabList->a[j].zAlias;
72750
- if( fullNames || zTab==0 ) zTab = pTab->zName;
72751
- zName = sqlite3MPrintf(db, "%s.%s", zTab, zCol);
73326
+ zName = sqlite3MPrintf(db, "%s.%s", pTab->zName, zCol);
7275273327
sqlite3VdbeSetColName(v, i, COLNAME_NAME, zName, SQLITE_DYNAMIC);
7275373328
}else{
7275473329
sqlite3VdbeSetColName(v, i, COLNAME_NAME, zCol, SQLITE_TRANSIENT);
7275573330
}
7275673331
}else{
@@ -73189,14 +73764,18 @@
7318973764
Expr *pLimit, *pOffset; /* Saved values of p->nLimit and p->nOffset */
7319073765
int addr;
7319173766
SelectDest uniondest;
7319273767
7319373768
priorOp = SRT_Union;
73194
- if( dest.eDest==priorOp && !p->pLimit && !p->pOffset ){
73769
+ if( dest.eDest==priorOp && ALWAYS(!p->pLimit &&!p->pOffset) ){
7319573770
/* We can reuse a temporary table generated by a SELECT to our
7319673771
** right.
7319773772
*/
73773
+ assert( p->pRightmost!=p ); /* Can only happen for leftward elements
73774
+ ** of a 3-way or more compound */
73775
+ assert( p->pLimit==0 ); /* Not allowed on leftward elements */
73776
+ assert( p->pOffset==0 ); /* Not allowed on leftward elements */
7319873777
unionTab = dest.iParm;
7319973778
}else{
7320073779
/* We will need to create our own temporary table to hold the
7320173780
** intermediate results.
7320273781
*/
@@ -74050,10 +74629,12 @@
7405074629
pExpr->iAgg = pNew->iAgg;
7405174630
sqlite3TokenCopy(db, &pExpr->token, &pNew->token);
7405274631
sqlite3TokenCopy(db, &pExpr->span, &pNew->span);
7405374632
pExpr->pSelect = sqlite3SelectDup(db, pNew->pSelect);
7405474633
pExpr->flags = pNew->flags;
74634
+ pExpr->pAggInfo = pNew->pAggInfo;
74635
+ pNew->pAggInfo = 0;
7405574636
}
7405674637
}else{
7405774638
substExpr(db, pExpr->pLeft, iTable, pEList);
7405874639
substExpr(db, pExpr->pRight, iTable, pEList);
7405974640
substSelect(db, pExpr->pSelect, iTable, pEList);
@@ -74087,11 +74668,12 @@
7408774668
substExprList(db, p->pOrderBy, iTable, pEList);
7408874669
substExpr(db, p->pHaving, iTable, pEList);
7408974670
substExpr(db, p->pWhere, iTable, pEList);
7409074671
substSelect(db, p->pPrior, iTable, pEList);
7409174672
pSrc = p->pSrc;
74092
- if( pSrc ){
74673
+ assert( pSrc ); /* Even for (SELECT 1) we have: pSrc!=0 but pSrc->nSrc==0 */
74674
+ if( ALWAYS(pSrc) ){
7409374675
for(i=pSrc->nSrc, pItem=pSrc->a; i>0; i--, pItem++){
7409474676
substSelect(db, pItem->pSelect, iTable, pEList);
7409574677
}
7409674678
}
7409774679
}
@@ -74219,11 +74801,10 @@
7421974801
sqlite3 *db = pParse->db;
7422074802
7422174803
/* Check to see if flattening is permitted. Return 0 if not.
7422274804
*/
7422374805
assert( p!=0 );
74224
- if( p==0 ) return 0;
7422574806
assert( p->pPrior==0 ); /* Unable to flatten compound queries */
7422674807
pSrc = p->pSrc;
7422774808
assert( pSrc && iFrom>=0 && iFrom<pSrc->nSrc );
7422874809
pSubitem = &pSrc->a[iFrom];
7422974810
iParent = pSubitem->iCursor;
@@ -74297,11 +74878,11 @@
7429774878
** use only the UNION ALL operator. And none of the simple select queries
7429874879
** that make up the compound SELECT are allowed to be aggregate or distinct
7429974880
** queries.
7430074881
*/
7430174882
if( pSub->pPrior ){
74302
- if( p->pPrior || isAgg || (p->selFlags & SF_Distinct)!=0 || pSrc->nSrc!=1 ){
74883
+ if( isAgg || (p->selFlags & SF_Distinct)!=0 || pSrc->nSrc!=1 ){
7430374884
return 0;
7430474885
}
7430574886
for(pSub1=pSub; pSub1; pSub1=pSub1->pPrior){
7430674887
if( (pSub1->selFlags & (SF_Distinct|SF_Aggregate))!=0
7430774888
|| (pSub1->pPrior && pSub1->op!=TK_ALL)
@@ -75349,11 +75930,11 @@
7534975930
/* Aggregate and non-aggregate queries are handled differently */
7535075931
if( !isAgg && pGroupBy==0 ){
7535175932
/* This case is for non-aggregate queries
7535275933
** Begin the database scan
7535375934
*/
75354
- pWInfo = sqlite3WhereBegin(pParse, pTabList, pWhere, &pOrderBy, 0);
75935
+ pWInfo = sqlite3WhereBegin(pParse, pTabList, pWhere, &pOrderBy, 0, 0);
7535575936
if( pWInfo==0 ) goto select_end;
7535675937
7535775938
/* If sorting index that was created by a prior OP_OpenEphemeral
7535875939
** instruction ended up not being needed, then change the OP_OpenEphemeral
7535975940
** into an OP_Noop.
@@ -75470,11 +76051,11 @@
7547076051
** This might involve two separate loops with an OP_Sort in between, or
7547176052
** it might be a single loop that uses an index to extract information
7547276053
** in the right order to begin with.
7547376054
*/
7547476055
sqlite3VdbeAddOp2(v, OP_Gosub, regReset, addrReset);
75475
- pWInfo = sqlite3WhereBegin(pParse, pTabList, pWhere, &pGroupBy, 0);
76056
+ pWInfo = sqlite3WhereBegin(pParse, pTabList, pWhere, &pGroupBy, 0, 0);
7547676057
if( pWInfo==0 ) goto select_end;
7547776058
if( pGroupBy==0 ){
7547876059
/* The optimizer is able to deliver rows in group by order so
7547976060
** we do not have to sort. The OP_OpenEphemeral table will be
7548076061
** cancelled later because we still need to use the pKeyInfo
@@ -75668,11 +76249,11 @@
7566876249
/* This case runs if the aggregate has no GROUP BY clause. The
7566976250
** processing is much simpler since there is only a single row
7567076251
** of output.
7567176252
*/
7567276253
resetAccumulator(pParse, &sAggInfo);
75673
- pWInfo = sqlite3WhereBegin(pParse, pTabList, pWhere, &pMinMax, flag);
76254
+ pWInfo = sqlite3WhereBegin(pParse, pTabList, pWhere, &pMinMax, flag, 0);
7567476255
if( pWInfo==0 ){
7567576256
sqlite3ExprListDelete(db, pDel);
7567676257
goto select_end;
7567776258
}
7567876259
updateAccumulator(pParse, &sAggInfo);
@@ -76036,11 +76617,11 @@
7603676617
** May you share freely, never taking more than you give.
7603776618
**
7603876619
*************************************************************************
7603976620
**
7604076621
**
76041
-** $Id: trigger.c,v 1.132 2008/12/10 19:26:24 drh Exp $
76622
+** $Id: trigger.c,v 1.133 2008/12/26 07:56:39 danielk1977 Exp $
7604276623
*/
7604376624
7604476625
#ifndef SQLITE_OMIT_TRIGGER
7604576626
/*
7604676627
** Delete a linked list of TriggerStep structures.
@@ -76697,10 +77278,11 @@
7669777278
assert( pTriggerStep!=0 );
7669877279
assert( v!=0 );
7669977280
sqlite3VdbeAddOp2(v, OP_ContextPush, 0, 0);
7670077281
VdbeComment((v, "begin trigger %s", pStepList->pTrig->name));
7670177282
while( pTriggerStep ){
77283
+ sqlite3ExprClearColumnCache(pParse, -1);
7670277284
orconf = (orconfin == OE_Default)?pTriggerStep->orconf:orconfin;
7670377285
pParse->trigStack->orconf = orconf;
7670477286
switch( pTriggerStep->op ){
7670577287
case TK_SELECT: {
7670677288
Select *ss = sqlite3SelectDup(db, pTriggerStep->pSelect);
@@ -76894,11 +77476,11 @@
7689477476
**
7689577477
*************************************************************************
7689677478
** This file contains C code routines that are called by the parser
7689777479
** to handle UPDATE statements.
7689877480
**
76899
-** $Id: update.c,v 1.190 2008/12/10 22:15:00 drh Exp $
77481
+** $Id: update.c,v 1.191 2008/12/23 23:56:22 drh Exp $
7690077482
*/
7690177483
7690277484
#ifndef SQLITE_OMIT_VIRTUALTABLE
7690377485
/* Forward declaration */
7690477486
static void updateVirtualTable(
@@ -77227,11 +77809,11 @@
7722777809
7722877810
/* Begin the database scan
7722977811
*/
7723077812
sqlite3VdbeAddOp2(v, OP_Null, 0, regOldRowid);
7723177813
pWInfo = sqlite3WhereBegin(pParse, pTabList, pWhere, 0,
77232
- WHERE_ONEPASS_DESIRED);
77814
+ WHERE_ONEPASS_DESIRED, 0);
7723377815
if( pWInfo==0 ) goto update_cleanup;
7723477816
okOnePass = pWInfo->okOnePass;
7723577817
7723677818
/* Remember the rowid of every item to be updated.
7723777819
*/
@@ -78731,11 +79313,11 @@
7873179313
** generating the code that loops through a table looking for applicable
7873279314
** rows. Indices are selected and used to speed the search when doing
7873379315
** so is applicable. Because this module is responsible for selecting
7873479316
** indices, you might also think of this module as the "query optimizer".
7873579317
**
78736
-** $Id: where.c,v 1.337 2008/12/12 17:56:16 drh Exp $
79318
+** $Id: where.c,v 1.362 2009/01/09 02:49:32 drh Exp $
7873779319
*/
7873879320
7873979321
/*
7874079322
** Trace output macros
7874179323
*/
@@ -78749,11 +79331,14 @@
7874979331
#endif
7875079332
7875179333
/* Forward reference
7875279334
*/
7875379335
typedef struct WhereClause WhereClause;
78754
-typedef struct ExprMaskSet ExprMaskSet;
79336
+typedef struct WhereMaskSet WhereMaskSet;
79337
+typedef struct WhereOrInfo WhereOrInfo;
79338
+typedef struct WhereAndInfo WhereAndInfo;
79339
+typedef struct WhereCost WhereCost;
7875579340
7875679341
/*
7875779342
** The query generator uses an array of instances of this structure to
7875879343
** help it analyze the subexpressions of the WHERE clause. Each WHERE
7875979344
** clause subexpression is separated from the others by AND operators.
@@ -78769,23 +79354,36 @@
7876979354
** When a term is of the form:
7877079355
**
7877179356
** X <op> <expr>
7877279357
**
7877379358
** where X is a column name and <op> is one of certain operators,
78774
-** then WhereTerm.leftCursor and WhereTerm.leftColumn record the
78775
-** cursor number and column number for X. WhereTerm.operator records
79359
+** then WhereTerm.leftCursor and WhereTerm.u.leftColumn record the
79360
+** cursor number and column number for X. WhereTerm.eOperator records
7877679361
** the <op> using a bitmask encoding defined by WO_xxx below. The
7877779362
** use of a bitmask encoding for the operator allows us to search
7877879363
** quickly for terms that match any of several different operators.
7877979364
**
78780
-** prereqRight and prereqAll record sets of cursor numbers,
78781
-** but they do so indirectly. A single ExprMaskSet structure translates
79365
+** A WhereTerm might also be two or more subterms connected by OR:
79366
+**
79367
+** (t1.X <op> <expr>) OR (t1.Y <op> <expr>) OR ....
79368
+**
79369
+** In this second case, wtFlag as the TERM_ORINFO set and eOperator==WO_OR
79370
+** and the WhereTerm.u.pOrInfo field points to auxiliary information that
79371
+** is collected about the
79372
+**
79373
+** If a term in the WHERE clause does not match either of the two previous
79374
+** categories, then eOperator==0. The WhereTerm.pExpr field is still set
79375
+** to the original subexpression content and wtFlags is set up appropriately
79376
+** but no other fields in the WhereTerm object are meaningful.
79377
+**
79378
+** When eOperator!=0, prereqRight and prereqAll record sets of cursor numbers,
79379
+** but they do so indirectly. A single WhereMaskSet structure translates
7878279380
** cursor number into bits and the translated bit is stored in the prereq
7878379381
** fields. The translation is used in order to maximize the number of
7878479382
** bits that will fit in a Bitmask. The VDBE cursor numbers might be
7878579383
** spread out over the non-negative integers. For example, the cursor
78786
-** numbers might be 3, 8, 9, 10, 20, 23, 41, and 45. The ExprMaskSet
79384
+** numbers might be 3, 8, 9, 10, 20, 23, 41, and 45. The WhereMaskSet
7878779385
** translates these sparse cursor numbers into consecutive integers
7878879386
** beginning with 0 in order to make the best possible use of the available
7878979387
** bits in the Bitmask. So, in the example above, the cursor numbers
7879079388
** would be mapped into integers 0 through 7.
7879179389
**
@@ -78796,11 +79394,15 @@
7879679394
typedef struct WhereTerm WhereTerm;
7879779395
struct WhereTerm {
7879879396
Expr *pExpr; /* Pointer to the subexpression that is this term */
7879979397
int iParent; /* Disable pWC->a[iParent] when this term disabled */
7880079398
int leftCursor; /* Cursor number of X in "X <op> <expr>" */
78801
- int leftColumn; /* Column number of X in "X <op> <expr>" */
79399
+ union {
79400
+ int leftColumn; /* Column number of X in "X <op> <expr>" */
79401
+ WhereOrInfo *pOrInfo; /* Extra information if eOperator==WO_OR */
79402
+ WhereAndInfo *pAndInfo; /* Extra information if eOperator==WO_AND */
79403
+ } u;
7880279404
u16 eOperator; /* A WO_xx value describing <op> */
7880379405
u8 wtFlags; /* TERM_xxx bit flags. See below */
7880479406
u8 nChild; /* Number of children that must disable us */
7880579407
WhereClause *pWC; /* The clause this term is part of */
7880679408
Bitmask prereqRight; /* Bitmask of tables used by pExpr->pRight */
@@ -78812,24 +79414,44 @@
7881279414
*/
7881379415
#define TERM_DYNAMIC 0x01 /* Need to call sqlite3ExprDelete(db, pExpr) */
7881479416
#define TERM_VIRTUAL 0x02 /* Added by the optimizer. Do not code */
7881579417
#define TERM_CODED 0x04 /* This term is already coded */
7881679418
#define TERM_COPIED 0x08 /* Has a child */
78817
-#define TERM_OR_OK 0x10 /* Used during OR-clause processing */
79419
+#define TERM_ORINFO 0x10 /* Need to free the WhereTerm.u.pOrInfo object */
79420
+#define TERM_ANDINFO 0x20 /* Need to free the WhereTerm.u.pAndInfo obj */
79421
+#define TERM_OR_OK 0x40 /* Used during OR-clause processing */
7881879422
7881979423
/*
7882079424
** An instance of the following structure holds all information about a
7882179425
** WHERE clause. Mostly this is a container for one or more WhereTerms.
7882279426
*/
7882379427
struct WhereClause {
7882479428
Parse *pParse; /* The parser context */
78825
- ExprMaskSet *pMaskSet; /* Mapping of table indices to bitmasks */
79429
+ WhereMaskSet *pMaskSet; /* Mapping of table cursor numbers to bitmasks */
79430
+ u8 op; /* Split operator. TK_AND or TK_OR */
7882679431
int nTerm; /* Number of terms */
7882779432
int nSlot; /* Number of entries in a[] */
7882879433
WhereTerm *a; /* Each a[] describes a term of the WHERE cluase */
7882979434
WhereTerm aStatic[4]; /* Initial static space for a[] */
7883079435
};
79436
+
79437
+/*
79438
+** A WhereTerm with eOperator==WO_OR has its u.pOrInfo pointer set to
79439
+** a dynamically allocated instance of the following structure.
79440
+*/
79441
+struct WhereOrInfo {
79442
+ WhereClause wc; /* Decomposition into subterms */
79443
+ Bitmask indexable; /* Bitmask of all indexable tables in the clause */
79444
+};
79445
+
79446
+/*
79447
+** A WhereTerm with eOperator==WO_AND has its u.pAndInfo pointer set to
79448
+** a dynamically allocated instance of the following structure.
79449
+*/
79450
+struct WhereAndInfo {
79451
+ WhereClause wc; /* The subexpression broken out */
79452
+};
7883179453
7883279454
/*
7883379455
** An instance of the following structure keeps track of a mapping
7883479456
** between VDBE cursor numbers and bits of the bitmasks in WhereTerm.
7883579457
**
@@ -78839,29 +79461,38 @@
7883979461
** contain gaps in the numbering sequence. But we want to make maximum
7884079462
** use of the bits in our bitmasks. This structure provides a mapping
7884179463
** from the sparse cursor numbers into consecutive integers beginning
7884279464
** with 0.
7884379465
**
78844
-** If ExprMaskSet.ix[A]==B it means that The A-th bit of a Bitmask
79466
+** If WhereMaskSet.ix[A]==B it means that The A-th bit of a Bitmask
7884579467
** corresponds VDBE cursor number B. The A-th bit of a bitmask is 1<<A.
7884679468
**
7884779469
** For example, if the WHERE clause expression used these VDBE
78848
-** cursors: 4, 5, 8, 29, 57, 73. Then the ExprMaskSet structure
79470
+** cursors: 4, 5, 8, 29, 57, 73. Then the WhereMaskSet structure
7884979471
** would map those cursor numbers into bits 0 through 5.
7885079472
**
7885179473
** Note that the mapping is not necessarily ordered. In the example
7885279474
** above, the mapping might go like this: 4->3, 5->1, 8->2, 29->0,
7885379475
** 57->5, 73->4. Or one of 719 other combinations might be used. It
7885479476
** does not really matter. What is important is that sparse cursor
7885579477
** numbers all get mapped into bit numbers that begin with 0 and contain
7885679478
** no gaps.
7885779479
*/
78858
-struct ExprMaskSet {
79480
+struct WhereMaskSet {
7885979481
int n; /* Number of assigned cursor values */
7886079482
int ix[BMS]; /* Cursor assigned to each bit */
7886179483
};
7886279484
79485
+/*
79486
+** A WhereCost object records a lookup strategy and the estimated
79487
+** cost of pursuing that strategy.
79488
+*/
79489
+struct WhereCost {
79490
+ WherePlan plan; /* The lookup strategy */
79491
+ double rCost; /* Overall cost of pursuing this search strategy */
79492
+ double nRow; /* Estimated number of output rows */
79493
+};
7886379494
7886479495
/*
7886579496
** Bitmasks for the operators that indices are able to exploit. An
7886679497
** OR-ed combination of these values can be used when searching for
7886779498
** terms in the where clause.
@@ -78872,31 +79503,36 @@
7887279503
#define WO_LE (WO_EQ<<(TK_LE-TK_EQ))
7887379504
#define WO_GT (WO_EQ<<(TK_GT-TK_EQ))
7887479505
#define WO_GE (WO_EQ<<(TK_GE-TK_EQ))
7887579506
#define WO_MATCH 0x040
7887679507
#define WO_ISNULL 0x080
78877
-#define WO_OR 0x100
79508
+#define WO_OR 0x100 /* Two or more OR-connected terms */
79509
+#define WO_AND 0x200 /* Two or more AND-connected terms */
7887879510
7887979511
#define WO_ALL 0xfff /* Mask of all possible WO_* values */
79512
+#define WO_SINGLE 0x0ff /* Mask of all non-compound WO_* values */
7888079513
7888179514
/*
78882
-** Value for wsFlags returned by bestIndex(). These flags determine which
78883
-** search strategies are appropriate.
79515
+** Value for wsFlags returned by bestIndex() and stored in
79516
+** WhereLevel.wsFlags. These flags determine which search
79517
+** strategies are appropriate.
7888479518
**
7888579519
** The least significant 12 bits is reserved as a mask for WO_ values above.
78886
-** The WhereLevel.wtFlags field is usually set to WO_IN|WO_EQ|WO_ISNULL.
78887
-** But if the table is the right table of a left join, WhereLevel.wtFlags
78888
-** is set to WO_IN|WO_EQ. The WhereLevel.wtFlags field can then be used as
79520
+** The WhereLevel.wsFlags field is usually set to WO_IN|WO_EQ|WO_ISNULL.
79521
+** But if the table is the right table of a left join, WhereLevel.wsFlags
79522
+** is set to WO_IN|WO_EQ. The WhereLevel.wsFlags field can then be used as
7888979523
** the "op" parameter to findTerm when we are resolving equality constraints.
7889079524
** ISNULL constraints will then not be used on the right table of a left
7889179525
** join. Tickets #2177 and #2189.
7889279526
*/
7889379527
#define WHERE_ROWID_EQ 0x00001000 /* rowid=EXPR or rowid IN (...) */
7889479528
#define WHERE_ROWID_RANGE 0x00002000 /* rowid<EXPR and/or rowid>EXPR */
7889579529
#define WHERE_COLUMN_EQ 0x00010000 /* x=EXPR or x IN (...) */
7889679530
#define WHERE_COLUMN_RANGE 0x00020000 /* x<EXPR and/or x>EXPR */
7889779531
#define WHERE_COLUMN_IN 0x00040000 /* x IN (...) */
79532
+#define WHERE_INDEXED 0x00070000 /* Anything that uses an index */
79533
+#define WHERE_IN_ABLE 0x00071000 /* Able to support an IN operator */
7889879534
#define WHERE_TOP_LIMIT 0x00100000 /* x<EXPR or x<=EXPR constraint */
7889979535
#define WHERE_BTM_LIMIT 0x00200000 /* x>EXPR or x>=EXPR constraint */
7890079536
#define WHERE_IDX_ONLY 0x00800000 /* Use index only - omit table */
7890179537
#define WHERE_ORDERBY 0x01000000 /* Output will appear in correct order */
7890279538
#define WHERE_REVERSE 0x02000000 /* Scan in reverse order */
@@ -78908,18 +79544,37 @@
7890879544
** Initialize a preallocated WhereClause structure.
7890979545
*/
7891079546
static void whereClauseInit(
7891179547
WhereClause *pWC, /* The WhereClause to be initialized */
7891279548
Parse *pParse, /* The parsing context */
78913
- ExprMaskSet *pMaskSet /* Mapping from table indices to bitmasks */
79549
+ WhereMaskSet *pMaskSet /* Mapping from table cursor numbers to bitmasks */
7891479550
){
7891579551
pWC->pParse = pParse;
7891679552
pWC->pMaskSet = pMaskSet;
7891779553
pWC->nTerm = 0;
7891879554
pWC->nSlot = ArraySize(pWC->aStatic);
7891979555
pWC->a = pWC->aStatic;
7892079556
}
79557
+
79558
+/* Forward reference */
79559
+static void whereClauseClear(WhereClause*);
79560
+
79561
+/*
79562
+** Deallocate all memory associated with a WhereOrInfo object.
79563
+*/
79564
+static void whereOrInfoDelete(sqlite3 *db, WhereOrInfo *p){
79565
+ whereClauseClear(&p->wc);
79566
+ sqlite3DbFree(db, p);
79567
+}
79568
+
79569
+/*
79570
+** Deallocate all memory associated with a WhereAndInfo object.
79571
+*/
79572
+static void whereAndInfoDelete(sqlite3 *db, WhereAndInfo *p){
79573
+ whereClauseClear(&p->wc);
79574
+ sqlite3DbFree(db, p);
79575
+}
7892179576
7892279577
/*
7892379578
** Deallocate a WhereClause structure. The WhereClause structure
7892479579
** itself is not freed. This routine is the inverse of whereClauseInit().
7892579580
*/
@@ -78929,10 +79584,15 @@
7892979584
sqlite3 *db = pWC->pParse->db;
7893079585
for(i=pWC->nTerm-1, a=pWC->a; i>=0; i--, a++){
7893179586
if( a->wtFlags & TERM_DYNAMIC ){
7893279587
sqlite3ExprDelete(db, a->pExpr);
7893379588
}
79589
+ if( a->wtFlags & TERM_ORINFO ){
79590
+ whereOrInfoDelete(db, a->u.pOrInfo);
79591
+ }else if( a->wtFlags & TERM_ANDINFO ){
79592
+ whereAndInfoDelete(db, a->u.pAndInfo);
79593
+ }
7893479594
}
7893579595
if( pWC->a!=pWC->aStatic ){
7893679596
sqlite3DbFree(db, pWC->a);
7893779597
}
7893879598
}
@@ -79000,10 +79660,11 @@
7900079660
** In the previous sentence and in the diagram, "slot[]" refers to
7900179661
** the WhereClause.a[] array. The slot[] array grows as needed to contain
7900279662
** all terms of the WHERE clause.
7900379663
*/
7900479664
static void whereSplit(WhereClause *pWC, Expr *pExpr, int op){
79665
+ pWC->op = (u8)op;
7900579666
if( pExpr==0 ) return;
7900679667
if( pExpr->op!=op ){
7900779668
whereClauseInsert(pWC, pExpr, 0);
7900879669
}else{
7900979670
whereSplit(pWC, pExpr->pLeft, op);
@@ -79018,11 +79679,11 @@
7901879679
7901979680
/*
7902079681
** Return the bitmask for the given cursor number. Return 0 if
7902179682
** iCursor is not in the set.
7902279683
*/
79023
-static Bitmask getMask(ExprMaskSet *pMaskSet, int iCursor){
79684
+static Bitmask getMask(WhereMaskSet *pMaskSet, int iCursor){
7902479685
int i;
7902579686
for(i=0; i<pMaskSet->n; i++){
7902679687
if( pMaskSet->ix[i]==iCursor ){
7902779688
return ((Bitmask)1)<<i;
7902879689
}
@@ -79036,11 +79697,11 @@
7903679697
** There is one cursor per table in the FROM clause. The number of
7903779698
** tables in the FROM clause is limited by a test early in the
7903879699
** sqlite3WhereBegin() routine. So we know that the pMaskSet->ix[]
7903979700
** array will never overflow.
7904079701
*/
79041
-static void createMask(ExprMaskSet *pMaskSet, int iCursor){
79702
+static void createMask(WhereMaskSet *pMaskSet, int iCursor){
7904279703
assert( pMaskSet->n < ArraySize(pMaskSet->ix) );
7904379704
pMaskSet->ix[pMaskSet->n++] = iCursor;
7904479705
}
7904579706
7904679707
/*
@@ -79055,13 +79716,13 @@
7905579716
** sets their opcodes to TK_COLUMN and their Expr.iTable fields to
7905679717
** the VDBE cursor number of the table. This routine just has to
7905779718
** translate the cursor numbers into bitmask values and OR all
7905879719
** the bitmasks together.
7905979720
*/
79060
-static Bitmask exprListTableUsage(ExprMaskSet*, ExprList*);
79061
-static Bitmask exprSelectTableUsage(ExprMaskSet*, Select*);
79062
-static Bitmask exprTableUsage(ExprMaskSet *pMaskSet, Expr *p){
79721
+static Bitmask exprListTableUsage(WhereMaskSet*, ExprList*);
79722
+static Bitmask exprSelectTableUsage(WhereMaskSet*, Select*);
79723
+static Bitmask exprTableUsage(WhereMaskSet *pMaskSet, Expr *p){
7906379724
Bitmask mask = 0;
7906479725
if( p==0 ) return 0;
7906579726
if( p->op==TK_COLUMN ){
7906679727
mask = getMask(pMaskSet, p->iTable);
7906779728
return mask;
@@ -79070,21 +79731,21 @@
7907079731
mask |= exprTableUsage(pMaskSet, p->pLeft);
7907179732
mask |= exprListTableUsage(pMaskSet, p->pList);
7907279733
mask |= exprSelectTableUsage(pMaskSet, p->pSelect);
7907379734
return mask;
7907479735
}
79075
-static Bitmask exprListTableUsage(ExprMaskSet *pMaskSet, ExprList *pList){
79736
+static Bitmask exprListTableUsage(WhereMaskSet *pMaskSet, ExprList *pList){
7907679737
int i;
7907779738
Bitmask mask = 0;
7907879739
if( pList ){
7907979740
for(i=0; i<pList->nExpr; i++){
7908079741
mask |= exprTableUsage(pMaskSet, pList->a[i].pExpr);
7908179742
}
7908279743
}
7908379744
return mask;
7908479745
}
79085
-static Bitmask exprSelectTableUsage(ExprMaskSet *pMaskSet, Select *pS){
79746
+static Bitmask exprSelectTableUsage(WhereMaskSet *pMaskSet, Select *pS){
7908679747
Bitmask mask = 0;
7908779748
while( pS ){
7908879749
mask |= exprListTableUsage(pMaskSet, pS->pEList);
7908979750
mask |= exprListTableUsage(pMaskSet, pS->pGroupBy);
7909079751
mask |= exprListTableUsage(pMaskSet, pS->pOrderBy);
@@ -79153,18 +79814,15 @@
7915379814
assert( allowedOp(op) );
7915479815
if( op==TK_IN ){
7915579816
c = WO_IN;
7915679817
}else if( op==TK_ISNULL ){
7915779818
c = WO_ISNULL;
79158
- }else if( op==TK_OR ){
79159
- c = WO_OR;
7916079819
}else{
7916179820
assert( (WO_EQ<<(op-TK_EQ)) < 0x7fff );
7916279821
c = (u16)(WO_EQ<<(op-TK_EQ));
7916379822
}
7916479823
assert( op!=TK_ISNULL || c==WO_ISNULL );
79165
- assert( op!=TK_OR || c==WO_OR );
7916679824
assert( op!=TK_IN || c==WO_IN );
7916779825
assert( op!=TK_EQ || c==WO_EQ );
7916879826
assert( op!=TK_LT || c==WO_LT );
7916979827
assert( op!=TK_LE || c==WO_LE );
7917079828
assert( op!=TK_GT || c==WO_GT );
@@ -79191,11 +79849,11 @@
7919179849
assert( iCur>=0 );
7919279850
op &= WO_ALL;
7919379851
for(pTerm=pWC->a, k=pWC->nTerm; k; k--, pTerm++){
7919479852
if( pTerm->leftCursor==iCur
7919579853
&& (pTerm->prereqRight & notReady)==0
79196
- && pTerm->leftColumn==iColumn
79854
+ && pTerm->u.leftColumn==iColumn
7919779855
&& (pTerm->eOperator & op)!=0
7919879856
){
7919979857
if( pIdx && pTerm->eOperator!=WO_ISNULL ){
7920079858
Expr *pX = pTerm->pExpr;
7920179859
CollSeq *pColl;
@@ -79210,18 +79868,16 @@
7921079868
** it to be useful for optimising expression pX. Store this
7921179869
** value in variable pColl.
7921279870
*/
7921379871
assert(pX->pLeft);
7921479872
pColl = sqlite3BinaryCompareCollSeq(pParse, pX->pLeft, pX->pRight);
79215
- if( !pColl ){
79216
- pColl = pParse->db->pDfltColl;
79217
- }
79873
+ assert(pColl || pParse->nErr);
7921879874
7921979875
for(j=0; pIdx->aiColumn[j]!=iColumn; j++){
7922079876
if( NEVER(j>=pIdx->nColumn) ) return 0;
7922179877
}
79222
- if( sqlite3StrICmp(pColl->zName, pIdx->azColl[j]) ) continue;
79878
+ if( pColl && sqlite3StrICmp(pColl->zName, pIdx->azColl[j]) ) continue;
7922379879
}
7922479880
return pTerm;
7922579881
}
7922679882
}
7922779883
return 0;
@@ -79259,28 +79915,28 @@
7925979915
Expr *pExpr, /* Test this expression */
7926079916
int *pnPattern, /* Number of non-wildcard prefix characters */
7926179917
int *pisComplete, /* True if the only wildcard is % in the last character */
7926279918
int *pnoCase /* True if uppercase is equivalent to lowercase */
7926379919
){
79264
- const char *z;
79265
- Expr *pRight, *pLeft;
79266
- ExprList *pList;
79267
- int c, cnt;
79268
- char wc[3];
79269
- CollSeq *pColl;
79270
- sqlite3 *db = pParse->db;
79920
+ const char *z; /* String on RHS of LIKE operator */
79921
+ Expr *pRight, *pLeft; /* Right and left size of LIKE operator */
79922
+ ExprList *pList; /* List of operands to the LIKE operator */
79923
+ int c; /* One character in z[] */
79924
+ int cnt; /* Number of non-wildcard prefix characters */
79925
+ char wc[3]; /* Wildcard characters */
79926
+ CollSeq *pColl; /* Collating sequence for LHS */
79927
+ sqlite3 *db = pParse->db; /* Database connection */
7927179928
7927279929
if( !sqlite3IsLikeFunction(db, pExpr, pnoCase, wc) ){
7927379930
return 0;
7927479931
}
7927579932
#ifdef SQLITE_EBCDIC
7927679933
if( *pnoCase ) return 0;
7927779934
#endif
7927879935
pList = pExpr->pList;
7927979936
pRight = pList->a[0].pExpr;
79280
- if( pRight->op!=TK_STRING
79281
- && (pRight->op!=TK_REGISTER || pRight->iColumn!=TK_STRING) ){
79937
+ if( pRight->op!=TK_STRING ){
7928279938
return 0;
7928379939
}
7928479940
pLeft = pList->a[1].pExpr;
7928579941
if( pLeft->op!=TK_COLUMN ){
7928679942
return 0;
@@ -79299,11 +79955,11 @@
7929979955
z = (char *)pRight->token.z;
7930079956
cnt = 0;
7930179957
if( z ){
7930279958
while( (c=z[cnt])!=0 && c!=wc[0] && c!=wc[1] && c!=wc[2] ){ cnt++; }
7930379959
}
79304
- if( cnt==0 || 255==(u8)z[cnt] ){
79960
+ if( cnt==0 || 255==(u8)z[cnt-1] ){
7930579961
return 0;
7930679962
}
7930779963
*pisComplete = z[cnt]==wc[0] && z[cnt+1]==0;
7930879964
*pnPattern = cnt;
7930979965
return 1;
@@ -79351,124 +80007,312 @@
7935180007
pDerived->iRightJoinTable = pBase->iRightJoinTable;
7935280008
}
7935380009
7935480010
#if !defined(SQLITE_OMIT_OR_OPTIMIZATION) && !defined(SQLITE_OMIT_SUBQUERY)
7935580011
/*
79356
-** Return TRUE if the given term of an OR clause can be converted
79357
-** into an IN clause. The iCursor and iColumn define the left-hand
79358
-** side of the IN clause.
79359
-**
79360
-** The context is that we have multiple OR-connected equality terms
79361
-** like this:
79362
-**
79363
-** a=<expr1> OR a=<expr2> OR b=<expr3> OR ...
79364
-**
79365
-** The pOrTerm input to this routine corresponds to a single term of
79366
-** this OR clause. In order for the term to be a candidate for
79367
-** conversion to an IN operator, the following must be true:
79368
-**
79369
-** * The left-hand side of the term must be the column which
79370
-** is identified by iCursor and iColumn.
79371
-**
79372
-** * If the right-hand side is also a column, then the affinities
79373
-** of both right and left sides must be such that no type
79374
-** conversions are required on the right. (Ticket #2249)
79375
-**
79376
-** If both of these conditions are true, then return true. Otherwise
79377
-** return false.
79378
-*/
79379
-static int orTermIsOptCandidate(WhereTerm *pOrTerm, int iCursor, int iColumn){
79380
- int affLeft, affRight;
79381
- assert( pOrTerm->eOperator==WO_EQ );
79382
- if( pOrTerm->leftCursor!=iCursor ){
79383
- return 0;
79384
- }
79385
- if( pOrTerm->leftColumn!=iColumn ){
79386
- return 0;
79387
- }
79388
- affRight = sqlite3ExprAffinity(pOrTerm->pExpr->pRight);
79389
- if( affRight==0 ){
79390
- return 1;
79391
- }
79392
- affLeft = sqlite3ExprAffinity(pOrTerm->pExpr->pLeft);
79393
- if( affRight!=affLeft ){
79394
- return 0;
79395
- }
79396
- return 1;
79397
-}
79398
-
79399
-/*
79400
-** Return true if the given term of an OR clause can be ignored during
79401
-** a check to make sure all OR terms are candidates for optimization.
79402
-** In other words, return true if a call to the orTermIsOptCandidate()
79403
-** above returned false but it is not necessary to disqualify the
79404
-** optimization.
79405
-**
79406
-** Suppose the original OR phrase was this:
79407
-**
79408
-** a=4 OR a=11 OR a=b
79409
-**
79410
-** During analysis, the third term gets flipped around and duplicate
79411
-** so that we are left with this:
79412
-**
79413
-** a=4 OR a=11 OR a=b OR b=a
79414
-**
79415
-** Since the last two terms are duplicates, only one of them
79416
-** has to qualify in order for the whole phrase to qualify. When
79417
-** this routine is called, we know that pOrTerm did not qualify.
79418
-** This routine merely checks to see if pOrTerm has a duplicate that
79419
-** might qualify. If there is a duplicate that has not yet been
79420
-** disqualified, then return true. If there are no duplicates, or
79421
-** the duplicate has also been disqualified, return false.
79422
-*/
79423
-static int orTermHasOkDuplicate(WhereClause *pOr, WhereTerm *pOrTerm){
79424
- if( pOrTerm->wtFlags & TERM_COPIED ){
79425
- /* This is the original term. The duplicate is to the left had
79426
- ** has not yet been analyzed and thus has not yet been disqualified. */
79427
- return 1;
79428
- }
79429
- if( (pOrTerm->wtFlags & TERM_VIRTUAL)!=0
79430
- && (pOr->a[pOrTerm->iParent].wtFlags & TERM_OR_OK)!=0 ){
79431
- /* This is a duplicate term. The original qualified so this one
79432
- ** does not have to. */
79433
- return 1;
79434
- }
79435
- /* This is either a singleton term or else it is a duplicate for
79436
- ** which the original did not qualify. Either way we are done for. */
79437
- return 0;
80012
+** Analyze a term that consists of two or more OR-connected
80013
+** subterms. So in:
80014
+**
80015
+** ... WHERE (a=5) AND (b=7 OR c=9 OR d=13) AND (d=13)
80016
+** ^^^^^^^^^^^^^^^^^^^^
80017
+**
80018
+** This routine analyzes terms such as the middle term in the above example.
80019
+** A WhereOrTerm object is computed and attached to the term under
80020
+** analysis, regardless of the outcome of the analysis. Hence:
80021
+**
80022
+** WhereTerm.wtFlags |= TERM_ORINFO
80023
+** WhereTerm.u.pOrInfo = a dynamically allocated WhereOrTerm object
80024
+**
80025
+** The term being analyzed must have two or more of OR-connected subterms.
80026
+** A single subterm might be a set of AND-connected sub-subterms.
80027
+** Examples of terms under analysis:
80028
+**
80029
+** (A) t1.x=t2.y OR t1.x=t2.z OR t1.y=15 OR t1.z=t3.a+5
80030
+** (B) x=expr1 OR expr2=x OR x=expr3
80031
+** (C) t1.x=t2.y OR (t1.x=t2.z AND t1.y=15)
80032
+** (D) x=expr1 OR (y>11 AND y<22 AND z LIKE '*hello*')
80033
+** (E) (p.a=1 AND q.b=2 AND r.c=3) OR (p.x=4 AND q.y=5 AND r.z=6)
80034
+**
80035
+** CASE 1:
80036
+**
80037
+** If all subterms are of the form T.C=expr for some single column of C
80038
+** a single table T (as shown in example B above) then create a new virtual
80039
+** term that is an equivalent IN expression. In other words, if the term
80040
+** being analyzed is:
80041
+**
80042
+** x = expr1 OR expr2 = x OR x = expr3
80043
+**
80044
+** then create a new virtual term like this:
80045
+**
80046
+** x IN (expr1,expr2,expr3)
80047
+**
80048
+** CASE 2:
80049
+**
80050
+** If all subterms are indexable by a single table T, then set
80051
+**
80052
+** WhereTerm.eOperator = WO_OR
80053
+** WhereTerm.u.pOrInfo->indexable |= the cursor number for table T
80054
+**
80055
+** A subterm is "indexable" if it is of the form
80056
+** "T.C <op> <expr>" where C is any column of table T and
80057
+** <op> is one of "=", "<", "<=", ">", ">=", "IS NULL", or "IN".
80058
+** A subterm is also indexable if it is an AND of two or more
80059
+** subsubterms at least one of which is indexable. Indexable AND
80060
+** subterms have their eOperator set to WO_AND and they have
80061
+** u.pAndInfo set to a dynamically allocated WhereAndTerm object.
80062
+**
80063
+** From another point of view, "indexable" means that the subterm could
80064
+** potentially be used with an index if an appropriate index exists.
80065
+** This analysis does not consider whether or not the index exists; that
80066
+** is something the bestIndex() routine will determine. This analysis
80067
+** only looks at whether subterms appropriate for indexing exist.
80068
+**
80069
+** All examples A through E above all satisfy case 2. But if a term
80070
+** also statisfies case 1 (such as B) we know that the optimizer will
80071
+** always prefer case 1, so in that case we pretend that case 2 is not
80072
+** satisfied.
80073
+**
80074
+** It might be the case that multiple tables are indexable. For example,
80075
+** (E) above is indexable on tables P, Q, and R.
80076
+**
80077
+** Terms that satisfy case 2 are candidates for lookup by using
80078
+** separate indices to find rowids for each subterm and composing
80079
+** the union of all rowids using a RowSet object. This is similar
80080
+** to "bitmap indices" in other database engines.
80081
+**
80082
+** OTHERWISE:
80083
+**
80084
+** If neither case 1 nor case 2 apply, then leave the eOperator set to
80085
+** zero. This term is not useful for search.
80086
+*/
80087
+static void exprAnalyzeOrTerm(
80088
+ SrcList *pSrc, /* the FROM clause */
80089
+ WhereClause *pWC, /* the complete WHERE clause */
80090
+ int idxTerm /* Index of the OR-term to be analyzed */
80091
+){
80092
+ Parse *pParse = pWC->pParse; /* Parser context */
80093
+ sqlite3 *db = pParse->db; /* Database connection */
80094
+ WhereTerm *pTerm = &pWC->a[idxTerm]; /* The term to be analyzed */
80095
+ Expr *pExpr = pTerm->pExpr; /* The expression of the term */
80096
+ WhereMaskSet *pMaskSet = pWC->pMaskSet; /* Table use masks */
80097
+ int i; /* Loop counters */
80098
+ WhereClause *pOrWc; /* Breakup of pTerm into subterms */
80099
+ WhereTerm *pOrTerm; /* A Sub-term within the pOrWc */
80100
+ WhereOrInfo *pOrInfo; /* Additional information associated with pTerm */
80101
+ Bitmask chngToIN; /* Tables that might satisfy case 1 */
80102
+ Bitmask indexable; /* Tables that are indexable, satisfying case 2 */
80103
+
80104
+ /*
80105
+ ** Break the OR clause into its separate subterms. The subterms are
80106
+ ** stored in a WhereClause structure containing within the WhereOrInfo
80107
+ ** object that is attached to the original OR clause term.
80108
+ */
80109
+ assert( (pTerm->wtFlags & (TERM_DYNAMIC|TERM_ORINFO|TERM_ANDINFO))==0 );
80110
+ assert( pExpr->op==TK_OR );
80111
+ pTerm->u.pOrInfo = pOrInfo = sqlite3DbMallocZero(db, sizeof(*pOrInfo));
80112
+ if( pOrInfo==0 ) return;
80113
+ pTerm->wtFlags |= TERM_ORINFO;
80114
+ pOrWc = &pOrInfo->wc;
80115
+ whereClauseInit(pOrWc, pWC->pParse, pMaskSet);
80116
+ whereSplit(pOrWc, pExpr, TK_OR);
80117
+ exprAnalyzeAll(pSrc, pOrWc);
80118
+ if( db->mallocFailed ) return;
80119
+ assert( pOrWc->nTerm>=2 );
80120
+
80121
+ /*
80122
+ ** Compute the set of tables that might satisfy cases 1 or 2.
80123
+ */
80124
+ indexable = chngToIN = ~(Bitmask)0;
80125
+ for(i=pOrWc->nTerm-1, pOrTerm=pOrWc->a; i>=0 && indexable; i--, pOrTerm++){
80126
+ if( (pOrTerm->eOperator & WO_SINGLE)==0 ){
80127
+ WhereAndInfo *pAndInfo;
80128
+ assert( pOrTerm->eOperator==0 );
80129
+ assert( (pOrTerm->wtFlags & (TERM_ANDINFO|TERM_ORINFO))==0 );
80130
+ chngToIN = 0;
80131
+ pAndInfo = sqlite3DbMallocRaw(db, sizeof(*pAndInfo));
80132
+ if( pAndInfo ){
80133
+ WhereClause *pAndWC;
80134
+ WhereTerm *pAndTerm;
80135
+ int j;
80136
+ Bitmask b = 0;
80137
+ pOrTerm->u.pAndInfo = pAndInfo;
80138
+ pOrTerm->wtFlags |= TERM_ANDINFO;
80139
+ pOrTerm->eOperator = WO_AND;
80140
+ pAndWC = &pAndInfo->wc;
80141
+ whereClauseInit(pAndWC, pWC->pParse, pMaskSet);
80142
+ whereSplit(pAndWC, pOrTerm->pExpr, TK_AND);
80143
+ exprAnalyzeAll(pSrc, pAndWC);
80144
+ testcase( db->mallocFailed );
80145
+ for(j=0, pAndTerm=pAndWC->a; j<pAndWC->nTerm; j++, pAndTerm++){
80146
+ assert( pAndTerm->pExpr );
80147
+ if( allowedOp(pAndTerm->pExpr->op) ){
80148
+ b |= getMask(pMaskSet, pAndTerm->leftCursor);
80149
+ }
80150
+ }
80151
+ indexable &= b;
80152
+ }
80153
+ }else if( pOrTerm->wtFlags & TERM_COPIED ){
80154
+ /* Skip this term for now. We revisit it when we process the
80155
+ ** corresponding TERM_VIRTUAL term */
80156
+ }else{
80157
+ Bitmask b;
80158
+ b = getMask(pMaskSet, pOrTerm->leftCursor);
80159
+ if( pOrTerm->wtFlags & TERM_VIRTUAL ){
80160
+ WhereTerm *pOther = &pOrWc->a[pOrTerm->iParent];
80161
+ b |= getMask(pMaskSet, pOther->leftCursor);
80162
+ }
80163
+ indexable &= b;
80164
+ if( pOrTerm->eOperator!=WO_EQ ){
80165
+ chngToIN = 0;
80166
+ }else{
80167
+ chngToIN &= b;
80168
+ }
80169
+ }
80170
+ }
80171
+
80172
+ /*
80173
+ ** Record the set of tables that satisfy case 2. The set might be
80174
+ ** empty.
80175
+ */
80176
+ pOrInfo->indexable = indexable;
80177
+ pTerm->eOperator = indexable==0 ? 0 : WO_OR;
80178
+
80179
+ /*
80180
+ ** chngToIN holds a set of tables that *might* satisfy case 1. But
80181
+ ** we have to do some additional checking to see if case 1 really
80182
+ ** is satisfied.
80183
+ */
80184
+ if( chngToIN ){
80185
+ int okToChngToIN = 0; /* True if the conversion to IN is valid */
80186
+ int iColumn = -1; /* Column index on lhs of IN operator */
80187
+ int iCursor; /* Table cursor common to all terms */
80188
+ int j = 0; /* Loop counter */
80189
+
80190
+ /* Search for a table and column that appears on one side or the
80191
+ ** other of the == operator in every subterm. That table and column
80192
+ ** will be recorded in iCursor and iColumn. There might not be any
80193
+ ** such table and column. Set okToChngToIN if an appropriate table
80194
+ ** and column is found but leave okToChngToIN false if not found.
80195
+ */
80196
+ for(j=0; j<2 && !okToChngToIN; j++){
80197
+ pOrTerm = pOrWc->a;
80198
+ for(i=pOrWc->nTerm-1; i>=0; i--, pOrTerm++){
80199
+ assert( pOrTerm->eOperator==WO_EQ );
80200
+ pOrTerm->wtFlags &= ~TERM_OR_OK;
80201
+ if( pOrTerm->leftCursor==iColumn ) continue;
80202
+ if( (chngToIN & getMask(pMaskSet, pOrTerm->leftCursor))==0 ) continue;
80203
+ iColumn = pOrTerm->u.leftColumn;
80204
+ iCursor = pOrTerm->leftCursor;
80205
+ break;
80206
+ }
80207
+ if( i<0 ){
80208
+ assert( j==1 );
80209
+ assert( (chngToIN&(chngToIN-1))==0 );
80210
+ assert( chngToIN==getMask(pMaskSet, iColumn) );
80211
+ break;
80212
+ }
80213
+ okToChngToIN = 1;
80214
+ for(; i>=0 && okToChngToIN; i--, pOrTerm++){
80215
+ assert( pOrTerm->eOperator==WO_EQ );
80216
+ if( pOrTerm->leftCursor!=iCursor ){
80217
+ pOrTerm->wtFlags &= ~TERM_OR_OK;
80218
+ }else if( pOrTerm->u.leftColumn!=iColumn ){
80219
+ okToChngToIN = 0;
80220
+ }else{
80221
+ int affLeft, affRight;
80222
+ /* If the right-hand side is also a column, then the affinities
80223
+ ** of both right and left sides must be such that no type
80224
+ ** conversions are required on the right. (Ticket #2249)
80225
+ */
80226
+ affRight = sqlite3ExprAffinity(pOrTerm->pExpr->pRight);
80227
+ affLeft = sqlite3ExprAffinity(pOrTerm->pExpr->pLeft);
80228
+ if( affRight!=0 && affRight!=affLeft ){
80229
+ okToChngToIN = 0;
80230
+ }else{
80231
+ pOrTerm->wtFlags |= TERM_OR_OK;
80232
+ }
80233
+ }
80234
+ }
80235
+ }
80236
+
80237
+ /* At this point, okToChngToIN is true if original pTerm satisfies
80238
+ ** case 1. In that case, construct a new virtual term that is
80239
+ ** pTerm converted into an IN operator.
80240
+ */
80241
+ if( okToChngToIN ){
80242
+ Expr *pDup; /* A transient duplicate expression */
80243
+ ExprList *pList = 0; /* The RHS of the IN operator */
80244
+ Expr *pLeft = 0; /* The LHS of the IN operator */
80245
+ Expr *pNew; /* The complete IN operator */
80246
+
80247
+ for(i=pOrWc->nTerm-1, pOrTerm=pOrWc->a; i>=0; i--, pOrTerm++){
80248
+ if( (pOrTerm->wtFlags & TERM_OR_OK)==0 ) continue;
80249
+ assert( pOrTerm->eOperator==WO_EQ );
80250
+ assert( pOrTerm->leftCursor==iCursor );
80251
+ assert( pOrTerm->u.leftColumn==iColumn );
80252
+ pDup = sqlite3ExprDup(db, pOrTerm->pExpr->pRight);
80253
+ pList = sqlite3ExprListAppend(pWC->pParse, pList, pDup, 0);
80254
+ pLeft = pOrTerm->pExpr->pLeft;
80255
+ }
80256
+ assert( pLeft!=0 );
80257
+ pDup = sqlite3ExprDup(db, pLeft);
80258
+ pNew = sqlite3Expr(db, TK_IN, pDup, 0, 0);
80259
+ if( pNew ){
80260
+ int idxNew;
80261
+ transferJoinMarkings(pNew, pExpr);
80262
+ pNew->pList = pList;
80263
+ idxNew = whereClauseInsert(pWC, pNew, TERM_VIRTUAL|TERM_DYNAMIC);
80264
+ testcase( idxNew==0 );
80265
+ exprAnalyze(pSrc, pWC, idxNew);
80266
+ pTerm = &pWC->a[idxTerm];
80267
+ pWC->a[idxNew].iParent = idxTerm;
80268
+ pTerm->nChild = 1;
80269
+ }else{
80270
+ sqlite3ExprListDelete(db, pList);
80271
+ }
80272
+ pTerm->eOperator = 0; /* case 1 trumps case 2 */
80273
+ }
80274
+ }
7943880275
}
7943980276
#endif /* !SQLITE_OMIT_OR_OPTIMIZATION && !SQLITE_OMIT_SUBQUERY */
80277
+
7944080278
7944180279
/*
7944280280
** The input to this routine is an WhereTerm structure with only the
7944380281
** "pExpr" field filled in. The job of this routine is to analyze the
7944480282
** subexpression and populate all the other fields of the WhereTerm
7944580283
** structure.
7944680284
**
7944780285
** If the expression is of the form "<expr> <op> X" it gets commuted
79448
-** to the standard form of "X <op> <expr>". If the expression is of
79449
-** the form "X <op> Y" where both X and Y are columns, then the original
79450
-** expression is unchanged and a new virtual expression of the form
79451
-** "Y <op> X" is added to the WHERE clause and analyzed separately.
80286
+** to the standard form of "X <op> <expr>".
80287
+**
80288
+** If the expression is of the form "X <op> Y" where both X and Y are
80289
+** columns, then the original expression is unchanged and a new virtual
80290
+** term of the form "Y <op> X" is added to the WHERE clause and
80291
+** analyzed separately. The original term is marked with TERM_COPIED
80292
+** and the new term is marked with TERM_DYNAMIC (because it's pExpr
80293
+** needs to be freed with the WhereClause) and TERM_VIRTUAL (because it
80294
+** is a commuted copy of a prior term.) The original term has nChild=1
80295
+** and the copy has idxParent set to the index of the original term.
7945280296
*/
7945380297
static void exprAnalyze(
7945480298
SrcList *pSrc, /* the FROM clause */
7945580299
WhereClause *pWC, /* the WHERE clause */
7945680300
int idxTerm /* Index of the term to be analyzed */
7945780301
){
79458
- WhereTerm *pTerm;
79459
- ExprMaskSet *pMaskSet;
79460
- Expr *pExpr;
79461
- Bitmask prereqLeft;
79462
- Bitmask prereqAll;
80302
+ WhereTerm *pTerm; /* The term to be analyzed */
80303
+ WhereMaskSet *pMaskSet; /* Set of table index masks */
80304
+ Expr *pExpr; /* The expression to be analyzed */
80305
+ Bitmask prereqLeft; /* Prerequesites of the pExpr->pLeft */
80306
+ Bitmask prereqAll; /* Prerequesites of pExpr */
7946380307
Bitmask extraRight = 0;
7946480308
int nPattern;
7946580309
int isComplete;
7946680310
int noCase;
79467
- int op;
79468
- Parse *pParse = pWC->pParse;
79469
- sqlite3 *db = pParse->db;
80311
+ int op; /* Top-level operator. pExpr->op */
80312
+ Parse *pParse = pWC->pParse; /* Parsing context */
80313
+ sqlite3 *db = pParse->db; /* Database connection */
7947080314
7947180315
if( db->mallocFailed ){
7947280316
return;
7947380317
}
7947480318
pTerm = &pWC->a[idxTerm];
@@ -79499,11 +80343,11 @@
7949980343
if( allowedOp(op) && (pTerm->prereqRight & prereqLeft)==0 ){
7950080344
Expr *pLeft = pExpr->pLeft;
7950180345
Expr *pRight = pExpr->pRight;
7950280346
if( pLeft->op==TK_COLUMN ){
7950380347
pTerm->leftCursor = pLeft->iTable;
79504
- pTerm->leftColumn = pLeft->iColumn;
80348
+ pTerm->u.leftColumn = pLeft->iColumn;
7950580349
pTerm->eOperator = operatorMask(op);
7950680350
}
7950780351
if( pRight && pRight->op==TK_COLUMN ){
7950880352
WhereTerm *pNew;
7950980353
Expr *pDup;
@@ -79526,22 +80370,34 @@
7952680370
pNew = pTerm;
7952780371
}
7952880372
exprCommute(pParse, pDup);
7952980373
pLeft = pDup->pLeft;
7953080374
pNew->leftCursor = pLeft->iTable;
79531
- pNew->leftColumn = pLeft->iColumn;
80375
+ pNew->u.leftColumn = pLeft->iColumn;
7953280376
pNew->prereqRight = prereqLeft;
7953380377
pNew->prereqAll = prereqAll;
7953480378
pNew->eOperator = operatorMask(pDup->op);
7953580379
}
7953680380
}
7953780381
7953880382
#ifndef SQLITE_OMIT_BETWEEN_OPTIMIZATION
7953980383
/* If a term is the BETWEEN operator, create two new virtual terms
79540
- ** that define the range that the BETWEEN implements.
80384
+ ** that define the range that the BETWEEN implements. For example:
80385
+ **
80386
+ ** a BETWEEN b AND c
80387
+ **
80388
+ ** is converted into:
80389
+ **
80390
+ ** (a BETWEEN b AND c) AND (a>=b) AND (a<=c)
80391
+ **
80392
+ ** The two new terms are added onto the end of the WhereClause object.
80393
+ ** The new terms are "dynamic" and are children of the original BETWEEN
80394
+ ** term. That means that if the BETWEEN term is coded, the children are
80395
+ ** skipped. Or, if the children are satisfied by an index, the original
80396
+ ** BETWEEN term is skipped.
7954180397
*/
79542
- else if( pExpr->op==TK_BETWEEN ){
80398
+ else if( pExpr->op==TK_BETWEEN && pWC->op==TK_AND ){
7954380399
ExprList *pList = pExpr->pList;
7954480400
int i;
7954580401
static const u8 ops[] = {TK_GE, TK_LE};
7954680402
assert( pList!=0 );
7954780403
assert( pList->nExpr==2 );
@@ -79559,83 +80415,16 @@
7955980415
pTerm->nChild = 2;
7956080416
}
7956180417
#endif /* SQLITE_OMIT_BETWEEN_OPTIMIZATION */
7956280418
7956380419
#if !defined(SQLITE_OMIT_OR_OPTIMIZATION) && !defined(SQLITE_OMIT_SUBQUERY)
79564
- /* Attempt to convert OR-connected terms into an IN operator so that
79565
- ** they can make use of indices. Example:
79566
- **
79567
- ** x = expr1 OR expr2 = x OR x = expr3
79568
- **
79569
- ** is converted into
79570
- **
79571
- ** x IN (expr1,expr2,expr3)
79572
- **
79573
- ** This optimization must be omitted if OMIT_SUBQUERY is defined because
79574
- ** the compiler for the the IN operator is part of sub-queries.
80420
+ /* Analyze a term that is composed of two or more subterms connected by
80421
+ ** an OR operator.
7957580422
*/
7957680423
else if( pExpr->op==TK_OR ){
79577
- int ok;
79578
- int i, j;
79579
- int iColumn, iCursor;
79580
- WhereClause sOr;
79581
- WhereTerm *pOrTerm;
79582
-
79583
- assert( (pTerm->wtFlags & TERM_DYNAMIC)==0 );
79584
- whereClauseInit(&sOr, pWC->pParse, pMaskSet);
79585
- whereSplit(&sOr, pExpr, TK_OR);
79586
- exprAnalyzeAll(pSrc, &sOr);
79587
- assert( sOr.nTerm>=2 );
79588
- j = 0;
79589
- if( db->mallocFailed ) goto or_not_possible;
79590
- do{
79591
- assert( j<sOr.nTerm );
79592
- iColumn = sOr.a[j].leftColumn;
79593
- iCursor = sOr.a[j].leftCursor;
79594
- ok = iCursor>=0;
79595
- for(i=sOr.nTerm-1, pOrTerm=sOr.a; i>=0 && ok; i--, pOrTerm++){
79596
- if( pOrTerm->eOperator!=WO_EQ ){
79597
- goto or_not_possible;
79598
- }
79599
- if( orTermIsOptCandidate(pOrTerm, iCursor, iColumn) ){
79600
- pOrTerm->wtFlags |= TERM_OR_OK;
79601
- }else if( orTermHasOkDuplicate(&sOr, pOrTerm) ){
79602
- pOrTerm->wtFlags &= ~TERM_OR_OK;
79603
- }else{
79604
- ok = 0;
79605
- }
79606
- }
79607
- }while( !ok && (sOr.a[j++].wtFlags & TERM_COPIED)!=0 && j<2 );
79608
- if( ok ){
79609
- ExprList *pList = 0;
79610
- Expr *pNew, *pDup;
79611
- Expr *pLeft = 0;
79612
- for(i=sOr.nTerm-1, pOrTerm=sOr.a; i>=0; i--, pOrTerm++){
79613
- if( (pOrTerm->wtFlags & TERM_OR_OK)==0 ) continue;
79614
- pDup = sqlite3ExprDup(db, pOrTerm->pExpr->pRight);
79615
- pList = sqlite3ExprListAppend(pWC->pParse, pList, pDup, 0);
79616
- pLeft = pOrTerm->pExpr->pLeft;
79617
- }
79618
- assert( pLeft!=0 );
79619
- pDup = sqlite3ExprDup(db, pLeft);
79620
- pNew = sqlite3Expr(db, TK_IN, pDup, 0, 0);
79621
- if( pNew ){
79622
- int idxNew;
79623
- transferJoinMarkings(pNew, pExpr);
79624
- pNew->pList = pList;
79625
- idxNew = whereClauseInsert(pWC, pNew, TERM_VIRTUAL|TERM_DYNAMIC);
79626
- testcase( idxNew==0 );
79627
- exprAnalyze(pSrc, pWC, idxNew);
79628
- pTerm = &pWC->a[idxTerm];
79629
- pWC->a[idxNew].iParent = idxTerm;
79630
- pTerm->nChild = 1;
79631
- }else{
79632
- sqlite3ExprListDelete(db, pList);
79633
- }
79634
- }
79635
-or_not_possible:
79636
- whereClauseClear(&sOr);
80424
+ assert( pWC->op==TK_AND );
80425
+ exprAnalyzeOrTerm(pSrc, pWC, idxTerm);
7963780426
}
7963880427
#endif /* SQLITE_OMIT_OR_OPTIMIZATION */
7963980428
7964080429
#ifndef SQLITE_OMIT_LIKE_OPTIMIZATION
7964180430
/* Add constraints to reduce the search space on a LIKE or GLOB
@@ -79646,11 +80435,12 @@
7964680435
** x>='abc' AND x<'abd' AND x LIKE 'abc%'
7964780436
**
7964880437
** The last character of the prefix "abc" is incremented to form the
7964980438
** termination condition "abd".
7965080439
*/
79651
- if( isLikeOrGlob(pParse, pExpr, &nPattern, &isComplete, &noCase) ){
80440
+ if( isLikeOrGlob(pParse, pExpr, &nPattern, &isComplete, &noCase)
80441
+ && pWC->op==TK_AND ){
7965280442
Expr *pLeft, *pRight;
7965380443
Expr *pStr1, *pStr2;
7965480444
Expr *pNewExpr1, *pNewExpr2;
7965580445
int idxNew1, idxNew2;
7965680446
@@ -79714,11 +80504,11 @@
7971480504
idxNew = whereClauseInsert(pWC, pNewExpr, TERM_VIRTUAL|TERM_DYNAMIC);
7971580505
testcase( idxNew==0 );
7971680506
pNewTerm = &pWC->a[idxNew];
7971780507
pNewTerm->prereqRight = prereqExpr;
7971880508
pNewTerm->leftCursor = pLeft->iTable;
79719
- pNewTerm->leftColumn = pLeft->iColumn;
80509
+ pNewTerm->u.leftColumn = pLeft->iColumn;
7972080510
pNewTerm->eOperator = WO_MATCH;
7972180511
pNewTerm->iParent = idxTerm;
7972280512
pTerm = &pWC->a[idxTerm];
7972380513
pTerm->nChild = 1;
7972480514
pTerm->wtFlags |= TERM_COPIED;
@@ -79737,11 +80527,11 @@
7973780527
** Return TRUE if any of the expressions in pList->a[iFirst...] contain
7973880528
** a reference to any table other than the iBase table.
7973980529
*/
7974080530
static int referencesOtherTables(
7974180531
ExprList *pList, /* Search expressions in ths list */
79742
- ExprMaskSet *pMaskSet, /* Mapping from tables to bitmaps */
80532
+ WhereMaskSet *pMaskSet, /* Mapping from tables to bitmaps */
7974380533
int iFirst, /* Be searching with the iFirst-th expression */
7974480534
int iBase /* Ignore references to this table */
7974580535
){
7974680536
Bitmask allowed = ~getMask(pMaskSet, iBase);
7974780537
while( iFirst<pList->nExpr ){
@@ -79772,11 +80562,11 @@
7977280562
** set to 1 if the ORDER BY clause is all DESC and it is set to 0 if
7977380563
** the ORDER BY clause is all ASC.
7977480564
*/
7977580565
static int isSortingIndex(
7977680566
Parse *pParse, /* Parsing context */
79777
- ExprMaskSet *pMaskSet, /* Mapping from table indices to bitmaps */
80567
+ WhereMaskSet *pMaskSet, /* Mapping from table cursor numbers to bitmaps */
7977880568
Index *pIdx, /* The index we are testing */
7977980569
int base, /* Cursor number for the table to be sorted */
7978080570
ExprList *pOrderBy, /* The ORDER BY clause */
7978180571
int nEqCol, /* Number of index columns with == constraints */
7978280572
int *pbRev /* Set to 1 if ORDER BY is DESC */
@@ -79895,11 +80685,11 @@
7989580685
** true for reverse ROWID and false for forward ROWID order.
7989680686
*/
7989780687
static int sortableByRowid(
7989880688
int base, /* Cursor number for table to be sorted */
7989980689
ExprList *pOrderBy, /* The ORDER BY clause */
79900
- ExprMaskSet *pMaskSet, /* Mapping from tables to bitmaps */
80690
+ WhereMaskSet *pMaskSet, /* Mapping from table cursors to bitmaps */
7990180691
int *pbRev /* Set to 1 if ORDER BY is DESC */
7990280692
){
7990380693
Expr *p;
7990480694
7990580695
assert( pOrderBy!=0 );
@@ -80076,11 +80866,11 @@
8007680866
if( pTerm->leftCursor != pSrc->iCursor ) continue;
8007780867
assert( (pTerm->eOperator&(pTerm->eOperator-1))==0 );
8007880868
testcase( pTerm->eOperator==WO_IN );
8007980869
testcase( pTerm->eOperator==WO_ISNULL );
8008080870
if( pTerm->eOperator & (WO_IN|WO_ISNULL) ) continue;
80081
- pIdxCons[j].iColumn = pTerm->leftColumn;
80871
+ pIdxCons[j].iColumn = pTerm->u.leftColumn;
8008280872
pIdxCons[j].iTermOffset = i;
8008380873
pIdxCons[j].op = (u8)pTerm->eOperator;
8008480874
/* The direct assignment in the previous line is possible only because
8008580875
** the WO_ and SQLITE_INDEX_CONSTRAINT_ codes are identical. The
8008680876
** following asserts verify this fact. */
@@ -80193,16 +80983,16 @@
8019380983
return pIdxInfo->estimatedCost;
8019480984
}
8019580985
#endif /* SQLITE_OMIT_VIRTUALTABLE */
8019680986
8019780987
/*
80198
-** Find the best index for accessing a particular table. Return a pointer
80199
-** to the index, flags that describe how the index should be used, the
80200
-** number of equality constraints, and the "cost" for this index.
80988
+** Find the query plan for accessing a particular table. Write the
80989
+** best query plan and its cost into the WhereCost object supplied as the
80990
+** last parameter.
8020180991
**
80202
-** The lowest cost index wins. The cost is an estimate of the amount of
80203
-** CPU and disk I/O need to process the request using the selected index.
80992
+** The lowest cost plan wins. The cost is an estimate of the amount of
80993
+** CPU and disk I/O need to process the request using the selected plan.
8020480994
** Factors that influence cost include:
8020580995
**
8020680996
** * The estimated number of rows that will be retrieved. (The
8020780997
** fewer the better.)
8020880998
**
@@ -80210,45 +81000,41 @@
8021081000
**
8021181001
** * Whether or not there must be separate lookups in the
8021281002
** index and in the main table.
8021381003
**
8021481004
** If there was an INDEXED BY clause attached to the table in the SELECT
80215
-** statement, then this function only considers strategies using the
81005
+** statement, then this function only considers plans using the
8021681006
** named index. If one cannot be found, then the returned cost is
80217
-** SQLITE_BIG_DBL. If a strategy can be found that uses the named index,
81007
+** SQLITE_BIG_DBL. If a plan can be found that uses the named index,
8021881008
** then the cost is calculated in the usual way.
8021981009
**
8022081010
** If a NOT INDEXED clause was attached to the table in the SELECT
8022181011
** statement, then no indexes are considered. However, the selected
80222
-** stategy may still take advantage of the tables built-in rowid
81012
+** plan may still take advantage of the tables built-in rowid
8022381013
** index.
8022481014
*/
80225
-static double bestIndex(
81015
+static void bestIndex(
8022681016
Parse *pParse, /* The parsing context */
8022781017
WhereClause *pWC, /* The WHERE clause */
8022881018
struct SrcList_item *pSrc, /* The FROM clause term to search */
8022981019
Bitmask notReady, /* Mask of cursors that are not available */
80230
- ExprList *pOrderBy, /* The order by clause */
80231
- Index **ppIndex, /* Make *ppIndex point to the best index */
80232
- int *pWsFlags, /* Put wsFlags describing scan strategy here */
80233
- int *pnEq /* Put the number of == or IN constraints here */
81020
+ ExprList *pOrderBy, /* The ORDER BY clause */
81021
+ WhereCost *pCost /* Lowest cost query plan */
8023481022
){
80235
- WhereTerm *pTerm;
80236
- Index *bestIdx = 0; /* Index that gives the lowest cost */
80237
- double lowestCost; /* The cost of using bestIdx */
80238
- int bestWsFlags = 0; /* Flags associated with bestIdx */
80239
- int bestNEq = 0; /* Best value for nEq */
81023
+ WhereTerm *pTerm; /* A single term of the WHERE clause */
8024081024
int iCur = pSrc->iCursor; /* The cursor of the table to be accessed */
8024181025
Index *pProbe; /* An index we are evaluating */
8024281026
int rev; /* True to scan in reverse order */
8024381027
int wsFlags; /* Flags associated with pProbe */
8024481028
int nEq; /* Number of == or IN constraints */
8024581029
int eqTermMask; /* Mask of valid equality operators */
8024681030
double cost; /* Cost of using pProbe */
81031
+ double nRow; /* Estimated number of rows in result set */
81032
+ int i; /* Loop counter */
81033
+ Bitmask maskSrc; /* Bitmask for the pSrc table */
8024781034
8024881035
WHERETRACE(("bestIndex: tbl=%s notReady=%llx\n", pSrc->pTab->zName,notReady));
80249
- lowestCost = SQLITE_BIG_DBL;
8025081036
pProbe = pSrc->pTab->pIndex;
8025181037
if( pSrc->notIndexed ){
8025281038
pProbe = 0;
8025381039
}
8025481040
@@ -80256,47 +81042,48 @@
8025681042
** clause that refer to the ROWID, then we will never be able to do
8025781043
** anything other than a full table scan on this table. We might as
8025881044
** well put it first in the join order. That way, perhaps it can be
8025981045
** referenced by other tables in the join.
8026081046
*/
81047
+ memset(pCost, 0, sizeof(*pCost));
8026181048
if( pProbe==0 &&
8026281049
findTerm(pWC, iCur, -1, 0, WO_EQ|WO_IN|WO_LT|WO_LE|WO_GT|WO_GE,0)==0 &&
8026381050
(pOrderBy==0 || !sortableByRowid(iCur, pOrderBy, pWC->pMaskSet, &rev)) ){
80264
- *pWsFlags = 0;
80265
- *ppIndex = 0;
80266
- *pnEq = 0;
80267
- return 0.0;
81051
+ return;
8026881052
}
81053
+ pCost->rCost = SQLITE_BIG_DBL;
8026981054
8027081055
/* Check for a rowid=EXPR or rowid IN (...) constraints. If there was
8027181056
** an INDEXED BY clause attached to this table, skip this step.
8027281057
*/
8027381058
if( !pSrc->pIndex ){
8027481059
pTerm = findTerm(pWC, iCur, -1, notReady, WO_EQ|WO_IN, 0);
8027581060
if( pTerm ){
8027681061
Expr *pExpr;
80277
- *ppIndex = 0;
80278
- bestWsFlags = WHERE_ROWID_EQ;
81062
+ pCost->plan.wsFlags = WHERE_ROWID_EQ;
8027981063
if( pTerm->eOperator & WO_EQ ){
8028081064
/* Rowid== is always the best pick. Look no further. Because only
8028181065
** a single row is generated, output is always in sorted order */
80282
- *pWsFlags = WHERE_ROWID_EQ | WHERE_UNIQUE;
80283
- *pnEq = 1;
81066
+ pCost->plan.wsFlags = WHERE_ROWID_EQ | WHERE_UNIQUE;
81067
+ pCost->plan.nEq = 1;
8028481068
WHERETRACE(("... best is rowid\n"));
80285
- return 0.0;
81069
+ pCost->rCost = 0;
81070
+ pCost->nRow = 1;
81071
+ return;
8028681072
}else if( (pExpr = pTerm->pExpr)->pList!=0 ){
8028781073
/* Rowid IN (LIST): cost is NlogN where N is the number of list
8028881074
** elements. */
80289
- lowestCost = pExpr->pList->nExpr;
80290
- lowestCost *= estLog(lowestCost);
81075
+ pCost->rCost = pCost->nRow = pExpr->pList->nExpr;
81076
+ pCost->rCost *= estLog(pCost->rCost);
8029181077
}else{
8029281078
/* Rowid IN (SELECT): cost is NlogN where N is the number of rows
8029381079
** in the result of the inner select. We have no way to estimate
8029481080
** that value so make a wild guess. */
80295
- lowestCost = 200;
81081
+ pCost->nRow = 100;
81082
+ pCost->rCost = 200;
8029681083
}
80297
- WHERETRACE(("... rowid IN cost: %.9g\n", lowestCost));
81084
+ WHERETRACE(("... rowid IN cost: %.9g\n", pCost->rCost));
8029881085
}
8029981086
8030081087
/* Estimate the cost of a table scan. If we do not know how many
8030181088
** entries are in the table, use 1 million as a guess.
8030281089
*/
@@ -80308,20 +81095,21 @@
8030881095
*/
8030981096
pTerm = findTerm(pWC, iCur, -1, notReady, WO_LT|WO_LE|WO_GT|WO_GE, 0);
8031081097
if( pTerm ){
8031181098
if( findTerm(pWC, iCur, -1, notReady, WO_LT|WO_LE, 0) ){
8031281099
wsFlags |= WHERE_TOP_LIMIT;
80313
- cost /= 3; /* Guess that rowid<EXPR eliminates two-thirds or rows */
81100
+ cost /= 3; /* Guess that rowid<EXPR eliminates two-thirds of rows */
8031481101
}
8031581102
if( findTerm(pWC, iCur, -1, notReady, WO_GT|WO_GE, 0) ){
8031681103
wsFlags |= WHERE_BTM_LIMIT;
8031781104
cost /= 3; /* Guess that rowid>EXPR eliminates two-thirds of rows */
8031881105
}
8031981106
WHERETRACE(("... rowid range reduces cost to %.9g\n", cost));
8032081107
}else{
8032181108
wsFlags = 0;
8032281109
}
81110
+ nRow = cost;
8032381111
8032481112
/* If the table scan does not satisfy the ORDER BY clause, increase
8032581113
** the cost by NlogN to cover the expense of sorting. */
8032681114
if( pOrderBy ){
8032781115
if( sortableByRowid(iCur, pOrderBy, pWC->pMaskSet, &rev) ){
@@ -80332,16 +81120,67 @@
8033281120
}else{
8033381121
cost += cost*estLog(cost);
8033481122
WHERETRACE(("... sorting increases cost to %.9g\n", cost));
8033581123
}
8033681124
}
80337
- if( cost<lowestCost ){
80338
- lowestCost = cost;
80339
- bestWsFlags = wsFlags;
81125
+ if( cost<pCost->rCost ){
81126
+ pCost->rCost = cost;
81127
+ pCost->nRow = nRow;
81128
+ pCost->plan.wsFlags = wsFlags;
8034081129
}
8034181130
}
8034281131
81132
+#ifndef SQLITE_OMIT_OR_OPTIMIZATION
81133
+ /* Search for an OR-clause that can be used to look up the table.
81134
+ */
81135
+ maskSrc = getMask(pWC->pMaskSet, iCur);
81136
+ for(i=0, pTerm=pWC->a; i<pWC->nTerm; i++, pTerm++){
81137
+ WhereClause tempWC;
81138
+ tempWC = *pWC;
81139
+ if( pTerm->eOperator==WO_OR
81140
+ && ((pTerm->prereqAll & ~maskSrc) & notReady)==0
81141
+ && (pTerm->u.pOrInfo->indexable & maskSrc)!=0 ){
81142
+ WhereClause *pOrWC = &pTerm->u.pOrInfo->wc;
81143
+ WhereTerm *pOrTerm;
81144
+ int j;
81145
+ double rTotal = 0;
81146
+ nRow = 0;
81147
+ for(j=0, pOrTerm=pOrWC->a; j<pOrWC->nTerm; j++, pOrTerm++){
81148
+ WhereCost sTermCost;
81149
+ WHERETRACE(("... Multi-index OR testing for term %d of %d....\n", j,i));
81150
+ if( pOrTerm->eOperator==WO_AND ){
81151
+ WhereClause *pAndWC = &pOrTerm->u.pAndInfo->wc;
81152
+ bestIndex(pParse, pAndWC, pSrc, notReady, 0, &sTermCost);
81153
+ }else if( pOrTerm->leftCursor==iCur ){
81154
+ tempWC.a = pOrTerm;
81155
+ tempWC.nTerm = 1;
81156
+ bestIndex(pParse, &tempWC, pSrc, notReady, 0, &sTermCost);
81157
+ }else{
81158
+ continue;
81159
+ }
81160
+ rTotal += sTermCost.rCost;
81161
+ nRow += sTermCost.nRow;
81162
+ if( rTotal>=pCost->rCost ) break;
81163
+ }
81164
+ WHERETRACE(("... multi-index OR cost=%.9g nrow=%.9g\n",
81165
+ rTotal, nRow));
81166
+ if( rTotal<pCost->rCost ){
81167
+ pCost->rCost = rTotal;
81168
+ pCost->nRow = nRow;
81169
+ pCost->plan.wsFlags = WHERE_MULTI_OR;
81170
+ pCost->plan.u.pTerm = pTerm;
81171
+ if( pOrderBy!=0
81172
+ && sortableByRowid(iCur, pOrderBy, pWC->pMaskSet, &rev)
81173
+ && !rev
81174
+ ){
81175
+ pCost->plan.wsFlags = WHERE_ORDERBY|WHERE_MULTI_OR;
81176
+ }
81177
+ }
81178
+ }
81179
+ }
81180
+#endif /* SQLITE_OMIT_OR_OPTIMIZATION */
81181
+
8034381182
/* If the pSrc table is the right table of a LEFT JOIN then we may not
8034481183
** use an index to satisfy IS NULL constraints on that table. This is
8034581184
** because columns might end up being NULL if the table does not match -
8034681185
** a circumstance which the index cannot help us discover. Ticket #2177.
8034781186
*/
@@ -80355,11 +81194,10 @@
8035581194
*/
8035681195
if( pSrc->pIndex ){
8035781196
pProbe = pSrc->pIndex;
8035881197
}
8035981198
for(; pProbe; pProbe=(pSrc->pIndex ? 0 : pProbe->pNext)){
80360
- int i; /* Loop counter */
8036181199
double inMultiplier = 1;
8036281200
8036381201
WHERETRACE(("... index %s:\n", pProbe->zName));
8036481202
8036581203
/* Count the number of columns in the index that are satisfied
@@ -80379,11 +81217,12 @@
8037981217
}else if( ALWAYS(pExpr->pList) ){
8038081218
inMultiplier *= pExpr->pList->nExpr + 1;
8038181219
}
8038281220
}
8038381221
}
80384
- cost = pProbe->aiRowEst[i] * inMultiplier * estLog(inMultiplier);
81222
+ nRow = pProbe->aiRowEst[i] * inMultiplier;
81223
+ cost = nRow * estLog(inMultiplier);
8038581224
nEq = i;
8038681225
if( pProbe->onError!=OE_None && (wsFlags & WHERE_COLUMN_IN)==0
8038781226
&& nEq==pProbe->nColumn ){
8038881227
wsFlags |= WHERE_UNIQUE;
8038981228
}
@@ -80397,14 +81236,16 @@
8039781236
if( pTerm ){
8039881237
wsFlags |= WHERE_COLUMN_RANGE;
8039981238
if( findTerm(pWC, iCur, j, notReady, WO_LT|WO_LE, pProbe) ){
8040081239
wsFlags |= WHERE_TOP_LIMIT;
8040181240
cost /= 3;
81241
+ nRow /= 3;
8040281242
}
8040381243
if( findTerm(pWC, iCur, j, notReady, WO_GT|WO_GE, pProbe) ){
8040481244
wsFlags |= WHERE_BTM_LIMIT;
8040581245
cost /= 3;
81246
+ nRow /= 3;
8040681247
}
8040781248
WHERETRACE(("...... range reduces cost to %.9g\n", cost));
8040881249
}
8040981250
}
8041081251
@@ -80446,26 +81287,27 @@
8044681287
}
8044781288
}
8044881289
8044981290
/* If this index has achieved the lowest cost so far, then use it.
8045081291
*/
80451
- if( wsFlags && cost < lowestCost ){
80452
- bestIdx = pProbe;
80453
- lowestCost = cost;
80454
- bestWsFlags = wsFlags;
80455
- bestNEq = nEq;
81292
+ if( wsFlags!=0 && cost < pCost->rCost ){
81293
+ pCost->rCost = cost;
81294
+ pCost->nRow = nRow;
81295
+ pCost->plan.wsFlags = wsFlags;
81296
+ pCost->plan.nEq = nEq;
81297
+ assert( pCost->plan.wsFlags & WHERE_INDEXED );
81298
+ pCost->plan.u.pIdx = pProbe;
8045681299
}
8045781300
}
8045881301
8045981302
/* Report the best result
8046081303
*/
80461
- *ppIndex = bestIdx;
80462
- WHERETRACE(("best index is %s, cost=%.9g, wsFlags=%x, nEq=%d\n",
80463
- bestIdx ? bestIdx->zName : "(none)", lowestCost, bestWsFlags, bestNEq));
80464
- *pWsFlags = bestWsFlags | eqTermMask;
80465
- *pnEq = bestNEq;
80466
- return lowestCost;
81304
+ pCost->plan.wsFlags |= eqTermMask;
81305
+ WHERETRACE(("best index is %s, cost=%.9g, nrow=%.9g, wsFlags=%x, nEq=%d\n",
81306
+ (pCost->plan.wsFlags & WHERE_INDEXED)!=0 ?
81307
+ pCost->plan.u.pIdx->zName : "(none)", pCost->nRow,
81308
+ pCost->rCost, pCost->plan.wsFlags, pCost->plan.nEq));
8046781309
}
8046881310
8046981311
8047081312
/*
8047181313
** Disable a term in the WHERE clause. Except, do not disable the term
@@ -80557,28 +81399,30 @@
8055781399
iReg = iTarget;
8055881400
eType = sqlite3FindInIndex(pParse, pX, 0);
8055981401
iTab = pX->iTable;
8056081402
sqlite3VdbeAddOp2(v, OP_Rewind, iTab, 0);
8056181403
VdbeComment((v, "%.*s", pX->span.n, pX->span.z));
80562
- if( pLevel->nIn==0 ){
81404
+ assert( pLevel->plan.wsFlags & WHERE_IN_ABLE );
81405
+ if( pLevel->u.in.nIn==0 ){
8056381406
pLevel->addrNxt = sqlite3VdbeMakeLabel(v);
8056481407
}
80565
- pLevel->nIn++;
80566
- pLevel->aInLoop = sqlite3DbReallocOrFree(pParse->db, pLevel->aInLoop,
80567
- sizeof(pLevel->aInLoop[0])*pLevel->nIn);
80568
- pIn = pLevel->aInLoop;
81408
+ pLevel->u.in.nIn++;
81409
+ pLevel->u.in.aInLoop =
81410
+ sqlite3DbReallocOrFree(pParse->db, pLevel->u.in.aInLoop,
81411
+ sizeof(pLevel->u.in.aInLoop[0])*pLevel->u.in.nIn);
81412
+ pIn = pLevel->u.in.aInLoop;
8056981413
if( pIn ){
80570
- pIn += pLevel->nIn - 1;
81414
+ pIn += pLevel->u.in.nIn - 1;
8057181415
pIn->iCur = iTab;
8057281416
if( eType==IN_INDEX_ROWID ){
8057381417
pIn->addrInTop = sqlite3VdbeAddOp2(v, OP_Rowid, iTab, iReg);
8057481418
}else{
8057581419
pIn->addrInTop = sqlite3VdbeAddOp3(v, OP_Column, iTab, 0, iReg);
8057681420
}
8057781421
sqlite3VdbeAddOp1(v, OP_IsNull, iReg);
8057881422
}else{
80579
- pLevel->nIn = 0;
81423
+ pLevel->u.in.nIn = 0;
8058081424
}
8058181425
#endif
8058281426
}
8058381427
disableTerm(pLevel, pTerm);
8058481428
return iReg;
@@ -80591,20 +81435,20 @@
8059181435
** For example, consider table t1(a,b,c,d,e,f) with index i1(a,b,c).
8059281436
** Suppose the WHERE clause is this: a==5 AND b IN (1,2,3) AND c>5 AND c<10
8059381437
** The index has as many as three equality constraints, but in this
8059481438
** example, the third "c" value is an inequality. So only two
8059581439
** constraints are coded. This routine will generate code to evaluate
80596
-** a==5 and b IN (1,2,3). The current values for a and b will be left
80597
-** on the stack - a is the deepest and b the shallowest.
81440
+** a==5 and b IN (1,2,3). The current values for a and b will be stored
81441
+** in consecutive registers and the index of the first register is returned.
8059881442
**
8059981443
** In the example above nEq==2. But this subroutine works for any value
8060081444
** of nEq including 0. If nEq==0, this routine is nearly a no-op.
8060181445
** The only thing it does is allocate the pLevel->iMem memory cell.
8060281446
**
80603
-** This routine always allocates at least one memory cell and puts
80604
-** the address of that memory cell in pLevel->iMem. The code that
80605
-** calls this routine will use pLevel->iMem to store the termination
81447
+** This routine always allocates at least one memory cell and returns
81448
+** the index of that memory cell. The code that
81449
+** calls this routine will use that memory cell to store the termination
8060681450
** key value of the loop. If one or more IN operators appear, then
8060781451
** this routine allocates an additional nEq memory cells for internal
8060881452
** use.
8060981453
*/
8061081454
static int codeAllEqualityTerms(
@@ -80612,48 +81456,649 @@
8061281456
WhereLevel *pLevel, /* Which nested loop of the FROM we are coding */
8061381457
WhereClause *pWC, /* The WHERE clause */
8061481458
Bitmask notReady, /* Which parts of FROM have not yet been coded */
8061581459
int nExtraReg /* Number of extra registers to allocate */
8061681460
){
80617
- int nEq = pLevel->nEq; /* The number of == or IN constraints to code */
80618
- Vdbe *v = pParse->pVdbe; /* The virtual machine under construction */
80619
- Index *pIdx = pLevel->pIdx; /* The index being used for this loop */
81461
+ int nEq = pLevel->plan.nEq; /* The number of == or IN constraints to code */
81462
+ Vdbe *v = pParse->pVdbe; /* The vm under construction */
81463
+ Index *pIdx; /* The index being used for this loop */
8062081464
int iCur = pLevel->iTabCur; /* The cursor of the table */
8062181465
WhereTerm *pTerm; /* A single constraint term */
8062281466
int j; /* Loop counter */
8062381467
int regBase; /* Base register */
81468
+ int nReg; /* Number of registers to allocate */
81469
+
81470
+ /* This module is only called on query plans that use an index. */
81471
+ assert( pLevel->plan.wsFlags & WHERE_INDEXED );
81472
+ pIdx = pLevel->plan.u.pIdx;
8062481473
8062581474
/* Figure out how many memory cells we will need then allocate them.
80626
- ** We always need at least one used to store the loop terminator
80627
- ** value. If there are IN operators we'll need one for each == or
80628
- ** IN constraint.
8062981475
*/
80630
- pLevel->iMem = pParse->nMem + 1;
80631
- regBase = pParse->nMem + 2;
80632
- pParse->nMem += pLevel->nEq + 2 + nExtraReg;
81476
+ regBase = pParse->nMem + 1;
81477
+ nReg = pLevel->plan.nEq + nExtraReg;
81478
+ pParse->nMem += nReg;
8063381479
8063481480
/* Evaluate the equality constraints
8063581481
*/
8063681482
assert( pIdx->nColumn>=nEq );
8063781483
for(j=0; j<nEq; j++){
8063881484
int r1;
8063981485
int k = pIdx->aiColumn[j];
80640
- pTerm = findTerm(pWC, iCur, k, notReady, pLevel->wsFlags, pIdx);
81486
+ pTerm = findTerm(pWC, iCur, k, notReady, pLevel->plan.wsFlags, pIdx);
8064181487
if( NEVER(pTerm==0) ) break;
8064281488
assert( (pTerm->wtFlags & TERM_CODED)==0 );
8064381489
r1 = codeEqualityTerm(pParse, pTerm, pLevel, regBase+j);
8064481490
if( r1!=regBase+j ){
80645
- sqlite3VdbeAddOp2(v, OP_SCopy, r1, regBase+j);
81491
+ if( nReg==1 ){
81492
+ sqlite3ReleaseTempReg(pParse, regBase);
81493
+ regBase = r1;
81494
+ }else{
81495
+ sqlite3VdbeAddOp2(v, OP_SCopy, r1, regBase+j);
81496
+ }
8064681497
}
8064781498
testcase( pTerm->eOperator & WO_ISNULL );
8064881499
testcase( pTerm->eOperator & WO_IN );
8064981500
if( (pTerm->eOperator & (WO_ISNULL|WO_IN))==0 ){
8065081501
sqlite3VdbeAddOp2(v, OP_IsNull, regBase+j, pLevel->addrBrk);
8065181502
}
8065281503
}
8065381504
return regBase;
8065481505
}
81506
+
81507
+/*
81508
+** Return TRUE if the WhereClause pWC contains no terms that
81509
+** are not virtual and which have not been coded.
81510
+**
81511
+** To put it another way, return TRUE if no additional WHERE clauses
81512
+** tests are required in order to establish that the current row
81513
+** should go to output and return FALSE if there are some terms of
81514
+** the WHERE clause that need to be validated before outputing the row.
81515
+*/
81516
+static int whereRowReadyForOutput(WhereClause *pWC){
81517
+ WhereTerm *pTerm;
81518
+ int j;
81519
+
81520
+ for(pTerm=pWC->a, j=pWC->nTerm; j>0; j--, pTerm++){
81521
+ if( (pTerm->wtFlags & (TERM_VIRTUAL|TERM_CODED))==0 ) return 0;
81522
+ }
81523
+ return 1;
81524
+}
81525
+
81526
+/*
81527
+** Generate code for the start of the iLevel-th loop in the WHERE clause
81528
+** implementation described by pWInfo.
81529
+*/
81530
+static Bitmask codeOneLoopStart(
81531
+ WhereInfo *pWInfo, /* Complete information about the WHERE clause */
81532
+ int iLevel, /* Which level of pWInfo->a[] should be coded */
81533
+ u8 wctrlFlags, /* One of the WHERE_* flags defined in sqliteInt.h */
81534
+ Bitmask notReady /* Which tables are currently available */
81535
+){
81536
+ int j, k; /* Loop counters */
81537
+ int iCur; /* The VDBE cursor for the table */
81538
+ int addrNxt; /* Where to jump to continue with the next IN case */
81539
+ int omitTable; /* True if we use the index only */
81540
+ int bRev; /* True if we need to scan in reverse order */
81541
+ WhereLevel *pLevel; /* The where level to be coded */
81542
+ WhereClause *pWC; /* Decomposition of the entire WHERE clause */
81543
+ WhereTerm *pTerm; /* A WHERE clause term */
81544
+ Parse *pParse; /* Parsing context */
81545
+ Vdbe *v; /* The prepared stmt under constructions */
81546
+ struct SrcList_item *pTabItem; /* FROM clause term being coded */
81547
+ int addrBrk; /* Jump here to break out of the loop */
81548
+ int addrCont; /* Jump here to continue with next cycle */
81549
+ int regRowSet; /* Write rowids to this RowSet if non-negative */
81550
+ int codeRowSetEarly; /* True if index fully constrains the search */
81551
+
81552
+
81553
+ pParse = pWInfo->pParse;
81554
+ v = pParse->pVdbe;
81555
+ pWC = pWInfo->pWC;
81556
+ pLevel = &pWInfo->a[iLevel];
81557
+ pTabItem = &pWInfo->pTabList->a[pLevel->iFrom];
81558
+ iCur = pTabItem->iCursor;
81559
+ bRev = (pLevel->plan.wsFlags & WHERE_REVERSE)!=0;
81560
+ omitTable = (pLevel->plan.wsFlags & WHERE_IDX_ONLY)!=0;
81561
+ regRowSet = pWInfo->regRowSet;
81562
+ codeRowSetEarly = 0;
81563
+
81564
+ /* Create labels for the "break" and "continue" instructions
81565
+ ** for the current loop. Jump to addrBrk to break out of a loop.
81566
+ ** Jump to cont to go immediately to the next iteration of the
81567
+ ** loop.
81568
+ **
81569
+ ** When there is an IN operator, we also have a "addrNxt" label that
81570
+ ** means to continue with the next IN value combination. When
81571
+ ** there are no IN operators in the constraints, the "addrNxt" label
81572
+ ** is the same as "addrBrk".
81573
+ */
81574
+ addrBrk = pLevel->addrBrk = pLevel->addrNxt = sqlite3VdbeMakeLabel(v);
81575
+ addrCont = pLevel->addrCont = sqlite3VdbeMakeLabel(v);
81576
+
81577
+ /* If this is the right table of a LEFT OUTER JOIN, allocate and
81578
+ ** initialize a memory cell that records if this table matches any
81579
+ ** row of the left table of the join.
81580
+ */
81581
+ if( pLevel->iFrom>0 && (pTabItem[0].jointype & JT_LEFT)!=0 ){
81582
+ pLevel->iLeftJoin = ++pParse->nMem;
81583
+ sqlite3VdbeAddOp2(v, OP_Integer, 0, pLevel->iLeftJoin);
81584
+ VdbeComment((v, "init LEFT JOIN no-match flag"));
81585
+ }
81586
+
81587
+#ifndef SQLITE_OMIT_VIRTUALTABLE
81588
+ if( (pLevel->plan.wsFlags & WHERE_VIRTUALTABLE)!=0 ){
81589
+ /* Case 0: The table is a virtual-table. Use the VFilter and VNext
81590
+ ** to access the data.
81591
+ */
81592
+ int iReg; /* P3 Value for OP_VFilter */
81593
+ sqlite3_index_info *pVtabIdx = pLevel->plan.u.pVtabIdx;
81594
+ int nConstraint = pVtabIdx->nConstraint;
81595
+ struct sqlite3_index_constraint_usage *aUsage =
81596
+ pVtabIdx->aConstraintUsage;
81597
+ const struct sqlite3_index_constraint *aConstraint =
81598
+ pVtabIdx->aConstraint;
81599
+
81600
+ iReg = sqlite3GetTempRange(pParse, nConstraint+2);
81601
+ pParse->disableColCache++;
81602
+ for(j=1; j<=nConstraint; j++){
81603
+ for(k=0; k<nConstraint; k++){
81604
+ if( aUsage[k].argvIndex==j ){
81605
+ int iTerm = aConstraint[k].iTermOffset;
81606
+ assert( pParse->disableColCache );
81607
+ sqlite3ExprCode(pParse, pWC->a[iTerm].pExpr->pRight, iReg+j+1);
81608
+ break;
81609
+ }
81610
+ }
81611
+ if( k==nConstraint ) break;
81612
+ }
81613
+ assert( pParse->disableColCache );
81614
+ pParse->disableColCache--;
81615
+ sqlite3VdbeAddOp2(v, OP_Integer, pVtabIdx->idxNum, iReg);
81616
+ sqlite3VdbeAddOp2(v, OP_Integer, j-1, iReg+1);
81617
+ sqlite3VdbeAddOp4(v, OP_VFilter, iCur, addrBrk, iReg, pVtabIdx->idxStr,
81618
+ pVtabIdx->needToFreeIdxStr ? P4_MPRINTF : P4_STATIC);
81619
+ pVtabIdx->needToFreeIdxStr = 0;
81620
+ for(j=0; j<nConstraint; j++){
81621
+ if( aUsage[j].omit ){
81622
+ int iTerm = aConstraint[j].iTermOffset;
81623
+ disableTerm(pLevel, &pWC->a[iTerm]);
81624
+ }
81625
+ }
81626
+ pLevel->op = OP_VNext;
81627
+ pLevel->p1 = iCur;
81628
+ pLevel->p2 = sqlite3VdbeCurrentAddr(v);
81629
+ codeRowSetEarly = regRowSet>=0 ? whereRowReadyForOutput(pWC) : 0;
81630
+ if( codeRowSetEarly ){
81631
+ sqlite3VdbeAddOp2(v, OP_VRowid, iCur, iReg);
81632
+ sqlite3VdbeAddOp2(v, OP_RowSetAdd, regRowSet, iReg);
81633
+ }
81634
+ sqlite3ReleaseTempRange(pParse, iReg, nConstraint+2);
81635
+ }else
81636
+#endif /* SQLITE_OMIT_VIRTUALTABLE */
81637
+
81638
+ if( pLevel->plan.wsFlags & WHERE_ROWID_EQ ){
81639
+ /* Case 1: We can directly reference a single row using an
81640
+ ** equality comparison against the ROWID field. Or
81641
+ ** we reference multiple rows using a "rowid IN (...)"
81642
+ ** construct.
81643
+ */
81644
+ int r1;
81645
+ int rtmp = sqlite3GetTempReg(pParse);
81646
+ pTerm = findTerm(pWC, iCur, -1, notReady, WO_EQ|WO_IN, 0);
81647
+ assert( pTerm!=0 );
81648
+ assert( pTerm->pExpr!=0 );
81649
+ assert( pTerm->leftCursor==iCur );
81650
+ assert( omitTable==0 );
81651
+ r1 = codeEqualityTerm(pParse, pTerm, pLevel, rtmp);
81652
+ addrNxt = pLevel->addrNxt;
81653
+ sqlite3VdbeAddOp2(v, OP_MustBeInt, r1, addrNxt);
81654
+ sqlite3VdbeAddOp3(v, OP_NotExists, iCur, addrNxt, r1);
81655
+ codeRowSetEarly = (pWC->nTerm==1 && regRowSet>=0) ?1:0;
81656
+ if( codeRowSetEarly ){
81657
+ sqlite3VdbeAddOp2(v, OP_RowSetAdd, regRowSet, r1);
81658
+ }
81659
+ sqlite3ReleaseTempReg(pParse, rtmp);
81660
+ VdbeComment((v, "pk"));
81661
+ pLevel->op = OP_Noop;
81662
+ }else if( pLevel->plan.wsFlags & WHERE_ROWID_RANGE ){
81663
+ /* Case 2: We have an inequality comparison against the ROWID field.
81664
+ */
81665
+ int testOp = OP_Noop;
81666
+ int start;
81667
+ int memEndValue = 0;
81668
+ WhereTerm *pStart, *pEnd;
81669
+
81670
+ assert( omitTable==0 );
81671
+ pStart = findTerm(pWC, iCur, -1, notReady, WO_GT|WO_GE, 0);
81672
+ pEnd = findTerm(pWC, iCur, -1, notReady, WO_LT|WO_LE, 0);
81673
+ if( bRev ){
81674
+ pTerm = pStart;
81675
+ pStart = pEnd;
81676
+ pEnd = pTerm;
81677
+ }
81678
+ if( pStart ){
81679
+ Expr *pX; /* The expression that defines the start bound */
81680
+ int r1, rTemp; /* Registers for holding the start boundary */
81681
+
81682
+ /* The following constant maps TK_xx codes into corresponding
81683
+ ** seek opcodes. It depends on a particular ordering of TK_xx
81684
+ */
81685
+ const u8 aMoveOp[] = {
81686
+ /* TK_GT */ OP_SeekGt,
81687
+ /* TK_LE */ OP_SeekLe,
81688
+ /* TK_LT */ OP_SeekLt,
81689
+ /* TK_GE */ OP_SeekGe
81690
+ };
81691
+ assert( TK_LE==TK_GT+1 ); /* Make sure the ordering.. */
81692
+ assert( TK_LT==TK_GT+2 ); /* ... of the TK_xx values... */
81693
+ assert( TK_GE==TK_GT+3 ); /* ... is correcct. */
81694
+
81695
+ pX = pStart->pExpr;
81696
+ assert( pX!=0 );
81697
+ assert( pStart->leftCursor==iCur );
81698
+ r1 = sqlite3ExprCodeTemp(pParse, pX->pRight, &rTemp);
81699
+ sqlite3VdbeAddOp3(v, aMoveOp[pX->op-TK_GT], iCur, addrBrk, r1);
81700
+ VdbeComment((v, "pk"));
81701
+ sqlite3ExprCacheAffinityChange(pParse, r1, 1);
81702
+ sqlite3ReleaseTempReg(pParse, rTemp);
81703
+ disableTerm(pLevel, pStart);
81704
+ }else{
81705
+ sqlite3VdbeAddOp2(v, bRev ? OP_Last : OP_Rewind, iCur, addrBrk);
81706
+ }
81707
+ if( pEnd ){
81708
+ Expr *pX;
81709
+ pX = pEnd->pExpr;
81710
+ assert( pX!=0 );
81711
+ assert( pEnd->leftCursor==iCur );
81712
+ memEndValue = ++pParse->nMem;
81713
+ sqlite3ExprCode(pParse, pX->pRight, memEndValue);
81714
+ if( pX->op==TK_LT || pX->op==TK_GT ){
81715
+ testOp = bRev ? OP_Le : OP_Ge;
81716
+ }else{
81717
+ testOp = bRev ? OP_Lt : OP_Gt;
81718
+ }
81719
+ disableTerm(pLevel, pEnd);
81720
+ }
81721
+ start = sqlite3VdbeCurrentAddr(v);
81722
+ pLevel->op = bRev ? OP_Prev : OP_Next;
81723
+ pLevel->p1 = iCur;
81724
+ pLevel->p2 = start;
81725
+ pLevel->p5 = (pStart==0 && pEnd==0) ?1:0;
81726
+ codeRowSetEarly = regRowSet>=0 ? whereRowReadyForOutput(pWC) : 0;
81727
+ if( codeRowSetEarly || testOp!=OP_Noop ){
81728
+ int r1 = sqlite3GetTempReg(pParse);
81729
+ sqlite3VdbeAddOp2(v, OP_Rowid, iCur, r1);
81730
+ if( testOp!=OP_Noop ){
81731
+ sqlite3VdbeAddOp3(v, testOp, memEndValue, addrBrk, r1);
81732
+ sqlite3VdbeChangeP5(v, SQLITE_AFF_NUMERIC | SQLITE_JUMPIFNULL);
81733
+ }
81734
+ if( codeRowSetEarly ){
81735
+ sqlite3VdbeAddOp2(v, OP_RowSetAdd, regRowSet, r1);
81736
+ }
81737
+ sqlite3ReleaseTempReg(pParse, r1);
81738
+ }
81739
+ }else if( pLevel->plan.wsFlags & (WHERE_COLUMN_RANGE|WHERE_COLUMN_EQ) ){
81740
+ /* Case 3: A scan using an index.
81741
+ **
81742
+ ** The WHERE clause may contain zero or more equality
81743
+ ** terms ("==" or "IN" operators) that refer to the N
81744
+ ** left-most columns of the index. It may also contain
81745
+ ** inequality constraints (>, <, >= or <=) on the indexed
81746
+ ** column that immediately follows the N equalities. Only
81747
+ ** the right-most column can be an inequality - the rest must
81748
+ ** use the "==" and "IN" operators. For example, if the
81749
+ ** index is on (x,y,z), then the following clauses are all
81750
+ ** optimized:
81751
+ **
81752
+ ** x=5
81753
+ ** x=5 AND y=10
81754
+ ** x=5 AND y<10
81755
+ ** x=5 AND y>5 AND y<10
81756
+ ** x=5 AND y=5 AND z<=10
81757
+ **
81758
+ ** The z<10 term of the following cannot be used, only
81759
+ ** the x=5 term:
81760
+ **
81761
+ ** x=5 AND z<10
81762
+ **
81763
+ ** N may be zero if there are inequality constraints.
81764
+ ** If there are no inequality constraints, then N is at
81765
+ ** least one.
81766
+ **
81767
+ ** This case is also used when there are no WHERE clause
81768
+ ** constraints but an index is selected anyway, in order
81769
+ ** to force the output order to conform to an ORDER BY.
81770
+ */
81771
+ int aStartOp[] = {
81772
+ 0,
81773
+ 0,
81774
+ OP_Rewind, /* 2: (!start_constraints && startEq && !bRev) */
81775
+ OP_Last, /* 3: (!start_constraints && startEq && bRev) */
81776
+ OP_SeekGt, /* 4: (start_constraints && !startEq && !bRev) */
81777
+ OP_SeekLt, /* 5: (start_constraints && !startEq && bRev) */
81778
+ OP_SeekGe, /* 6: (start_constraints && startEq && !bRev) */
81779
+ OP_SeekLe /* 7: (start_constraints && startEq && bRev) */
81780
+ };
81781
+ int aEndOp[] = {
81782
+ OP_Noop, /* 0: (!end_constraints) */
81783
+ OP_IdxGE, /* 1: (end_constraints && !bRev) */
81784
+ OP_IdxLT /* 2: (end_constraints && bRev) */
81785
+ };
81786
+ int nEq = pLevel->plan.nEq;
81787
+ int isMinQuery = 0; /* If this is an optimized SELECT min(x).. */
81788
+ int regBase; /* Base register holding constraint values */
81789
+ int r1; /* Temp register */
81790
+ WhereTerm *pRangeStart = 0; /* Inequality constraint at range start */
81791
+ WhereTerm *pRangeEnd = 0; /* Inequality constraint at range end */
81792
+ int startEq; /* True if range start uses ==, >= or <= */
81793
+ int endEq; /* True if range end uses ==, >= or <= */
81794
+ int start_constraints; /* Start of range is constrained */
81795
+ int nConstraint; /* Number of constraint terms */
81796
+ Index *pIdx; /* The index we will be using */
81797
+ int iIdxCur; /* The VDBE cursor for the index */
81798
+ int nExtraReg = 0; /* Number of extra registers needed */
81799
+ int op; /* Instruction opcode */
81800
+
81801
+ pIdx = pLevel->plan.u.pIdx;
81802
+ iIdxCur = pLevel->iIdxCur;
81803
+ k = pIdx->aiColumn[nEq]; /* Column for inequality constraints */
81804
+
81805
+ /* If this loop satisfies a sort order (pOrderBy) request that
81806
+ ** was passed to this function to implement a "SELECT min(x) ..."
81807
+ ** query, then the caller will only allow the loop to run for
81808
+ ** a single iteration. This means that the first row returned
81809
+ ** should not have a NULL value stored in 'x'. If column 'x' is
81810
+ ** the first one after the nEq equality constraints in the index,
81811
+ ** this requires some special handling.
81812
+ */
81813
+ if( (wctrlFlags&WHERE_ORDERBY_MIN)!=0
81814
+ && (pLevel->plan.wsFlags&WHERE_ORDERBY)
81815
+ && (pIdx->nColumn>nEq)
81816
+ ){
81817
+ /* assert( pOrderBy->nExpr==1 ); */
81818
+ /* assert( pOrderBy->a[0].pExpr->iColumn==pIdx->aiColumn[nEq] ); */
81819
+ isMinQuery = 1;
81820
+ nExtraReg = 1;
81821
+ }
81822
+
81823
+ /* Find any inequality constraint terms for the start and end
81824
+ ** of the range.
81825
+ */
81826
+ if( pLevel->plan.wsFlags & WHERE_TOP_LIMIT ){
81827
+ pRangeEnd = findTerm(pWC, iCur, k, notReady, (WO_LT|WO_LE), pIdx);
81828
+ nExtraReg = 1;
81829
+ }
81830
+ if( pLevel->plan.wsFlags & WHERE_BTM_LIMIT ){
81831
+ pRangeStart = findTerm(pWC, iCur, k, notReady, (WO_GT|WO_GE), pIdx);
81832
+ nExtraReg = 1;
81833
+ }
81834
+
81835
+ /* Generate code to evaluate all constraint terms using == or IN
81836
+ ** and store the values of those terms in an array of registers
81837
+ ** starting at regBase.
81838
+ */
81839
+ regBase = codeAllEqualityTerms(pParse, pLevel, pWC, notReady, nExtraReg);
81840
+ addrNxt = pLevel->addrNxt;
81841
+
81842
+
81843
+ /* If we are doing a reverse order scan on an ascending index, or
81844
+ ** a forward order scan on a descending index, interchange the
81845
+ ** start and end terms (pRangeStart and pRangeEnd).
81846
+ */
81847
+ if( bRev==(pIdx->aSortOrder[nEq]==SQLITE_SO_ASC) ){
81848
+ SWAP(WhereTerm *, pRangeEnd, pRangeStart);
81849
+ }
81850
+
81851
+ testcase( pRangeStart && pRangeStart->eOperator & WO_LE );
81852
+ testcase( pRangeStart && pRangeStart->eOperator & WO_GE );
81853
+ testcase( pRangeEnd && pRangeEnd->eOperator & WO_LE );
81854
+ testcase( pRangeEnd && pRangeEnd->eOperator & WO_GE );
81855
+ startEq = !pRangeStart || pRangeStart->eOperator & (WO_LE|WO_GE);
81856
+ endEq = !pRangeEnd || pRangeEnd->eOperator & (WO_LE|WO_GE);
81857
+ start_constraints = pRangeStart || nEq>0;
81858
+
81859
+ /* Seek the index cursor to the start of the range. */
81860
+ nConstraint = nEq;
81861
+ if( pRangeStart ){
81862
+ int dcc = pParse->disableColCache;
81863
+ if( pRangeEnd ){
81864
+ pParse->disableColCache++;
81865
+ }
81866
+ sqlite3ExprCode(pParse, pRangeStart->pExpr->pRight, regBase+nEq);
81867
+ pParse->disableColCache = dcc;
81868
+ sqlite3VdbeAddOp2(v, OP_IsNull, regBase+nEq, addrNxt);
81869
+ nConstraint++;
81870
+ }else if( isMinQuery ){
81871
+ sqlite3VdbeAddOp2(v, OP_Null, 0, regBase+nEq);
81872
+ nConstraint++;
81873
+ startEq = 0;
81874
+ start_constraints = 1;
81875
+ }
81876
+ codeApplyAffinity(pParse, regBase, nConstraint, pIdx);
81877
+ op = aStartOp[(start_constraints<<2) + (startEq<<1) + bRev];
81878
+ assert( op!=0 );
81879
+ testcase( op==OP_Rewind );
81880
+ testcase( op==OP_Last );
81881
+ testcase( op==OP_SeekGt );
81882
+ testcase( op==OP_SeekGe );
81883
+ testcase( op==OP_SeekLe );
81884
+ testcase( op==OP_SeekLt );
81885
+ sqlite3VdbeAddOp4(v, op, iIdxCur, addrNxt, regBase,
81886
+ SQLITE_INT_TO_PTR(nConstraint), P4_INT32);
81887
+
81888
+ /* Load the value for the inequality constraint at the end of the
81889
+ ** range (if any).
81890
+ */
81891
+ nConstraint = nEq;
81892
+ if( pRangeEnd ){
81893
+ sqlite3ExprCode(pParse, pRangeEnd->pExpr->pRight, regBase+nEq);
81894
+ sqlite3VdbeAddOp2(v, OP_IsNull, regBase+nEq, addrNxt);
81895
+ codeApplyAffinity(pParse, regBase, nEq+1, pIdx);
81896
+ nConstraint++;
81897
+ }
81898
+
81899
+ /* Top of the loop body */
81900
+ pLevel->p2 = sqlite3VdbeCurrentAddr(v);
81901
+
81902
+ /* Check if the index cursor is past the end of the range. */
81903
+ op = aEndOp[(pRangeEnd || nEq) * (1 + bRev)];
81904
+ testcase( op==OP_Noop );
81905
+ testcase( op==OP_IdxGE );
81906
+ testcase( op==OP_IdxLT );
81907
+ if( op!=OP_Noop ){
81908
+ sqlite3VdbeAddOp4(v, op, iIdxCur, addrNxt, regBase,
81909
+ SQLITE_INT_TO_PTR(nConstraint), P4_INT32);
81910
+ sqlite3VdbeChangeP5(v, endEq!=bRev ?1:0);
81911
+ }
81912
+
81913
+ /* If there are inequality constraints, check that the value
81914
+ ** of the table column that the inequality contrains is not NULL.
81915
+ ** If it is, jump to the next iteration of the loop.
81916
+ */
81917
+ r1 = sqlite3GetTempReg(pParse);
81918
+ testcase( pLevel->plan.wsFlags & WHERE_BTM_LIMIT );
81919
+ testcase( pLevel->plan.wsFlags & WHERE_TOP_LIMIT );
81920
+ if( pLevel->plan.wsFlags & (WHERE_BTM_LIMIT|WHERE_TOP_LIMIT) ){
81921
+ sqlite3VdbeAddOp3(v, OP_Column, iIdxCur, nEq, r1);
81922
+ sqlite3VdbeAddOp2(v, OP_IsNull, r1, addrCont);
81923
+ }
81924
+
81925
+ /* Seek the table cursor, if required */
81926
+ disableTerm(pLevel, pRangeStart);
81927
+ disableTerm(pLevel, pRangeEnd);
81928
+ codeRowSetEarly = regRowSet>=0 ? whereRowReadyForOutput(pWC) : 0;
81929
+ if( !omitTable || codeRowSetEarly ){
81930
+ sqlite3VdbeAddOp2(v, OP_IdxRowid, iIdxCur, r1);
81931
+ if( codeRowSetEarly ){
81932
+ sqlite3VdbeAddOp2(v, OP_RowSetAdd, regRowSet, r1);
81933
+ }else{
81934
+ sqlite3VdbeAddOp2(v, OP_Seek, iCur, r1); /* Deferred seek */
81935
+ }
81936
+ }
81937
+ sqlite3ReleaseTempReg(pParse, r1);
81938
+
81939
+ /* Record the instruction used to terminate the loop. Disable
81940
+ ** WHERE clause terms made redundant by the index range scan.
81941
+ */
81942
+ pLevel->op = bRev ? OP_Prev : OP_Next;
81943
+ pLevel->p1 = iIdxCur;
81944
+ }else
81945
+
81946
+#ifndef SQLITE_OMIT_OR_OPTIMIZATION
81947
+ if( pLevel->plan.wsFlags & WHERE_MULTI_OR ){
81948
+ /* Case 4: Two or more separately indexed terms connected by OR
81949
+ **
81950
+ ** Example:
81951
+ **
81952
+ ** CREATE TABLE t1(a,b,c,d);
81953
+ ** CREATE INDEX i1 ON t1(a);
81954
+ ** CREATE INDEX i2 ON t1(b);
81955
+ ** CREATE INDEX i3 ON t1(c);
81956
+ **
81957
+ ** SELECT * FROM t1 WHERE a=5 OR b=7 OR (c=11 AND d=13)
81958
+ **
81959
+ ** In the example, there are three indexed terms connected by OR.
81960
+ ** The top of the loop is constructed by creating a RowSet object
81961
+ ** and populating it. Then looping over elements of the rowset.
81962
+ **
81963
+ ** Null 1
81964
+ ** # fill RowSet 1 with entries where a=5 using i1
81965
+ ** # fill Rowset 1 with entries where b=7 using i2
81966
+ ** # fill Rowset 1 with entries where c=11 and d=13 i3 and t1
81967
+ ** A: RowSetRead 1, B, 2
81968
+ ** Seek i, 2
81969
+ **
81970
+ ** The bottom of the loop looks like this:
81971
+ **
81972
+ ** Goto 0, A
81973
+ ** B:
81974
+ */
81975
+ int regOrRowset; /* Register holding the RowSet object */
81976
+ int regNextRowid; /* Register holding next rowid */
81977
+ WhereClause *pOrWc; /* The OR-clause broken out into subterms */
81978
+ WhereTerm *pOrTerm; /* A single subterm within the OR-clause */
81979
+ SrcList oneTab; /* Shortened table list */
81980
+
81981
+ pTerm = pLevel->plan.u.pTerm;
81982
+ assert( pTerm!=0 );
81983
+ assert( pTerm->eOperator==WO_OR );
81984
+ assert( (pTerm->wtFlags & TERM_ORINFO)!=0 );
81985
+ pOrWc = &pTerm->u.pOrInfo->wc;
81986
+ codeRowSetEarly = (regRowSet>=0 && pWC->nTerm==1) ?1:0;
81987
+
81988
+ if( codeRowSetEarly ){
81989
+ regOrRowset = regRowSet;
81990
+ }else{
81991
+ regOrRowset = sqlite3GetTempReg(pParse);
81992
+ sqlite3VdbeAddOp2(v, OP_Null, 0, regOrRowset);
81993
+ }
81994
+ oneTab.nSrc = 1;
81995
+ oneTab.nAlloc = 1;
81996
+ oneTab.a[0] = *pTabItem;
81997
+ for(j=0, pOrTerm=pOrWc->a; j<pOrWc->nTerm; j++, pOrTerm++){
81998
+ WhereInfo *pSubWInfo;
81999
+ if( pOrTerm->leftCursor!=iCur && pOrTerm->eOperator!=WO_AND ) continue;
82000
+ pSubWInfo = sqlite3WhereBegin(pParse, &oneTab, pOrTerm->pExpr, 0,
82001
+ WHERE_FILL_ROWSET | WHERE_OMIT_OPEN | WHERE_OMIT_CLOSE,
82002
+ regOrRowset);
82003
+ if( pSubWInfo ){
82004
+ sqlite3WhereEnd(pSubWInfo);
82005
+ }
82006
+ }
82007
+ sqlite3VdbeResolveLabel(v, addrCont);
82008
+ if( !codeRowSetEarly ){
82009
+ regNextRowid = sqlite3GetTempReg(pParse);
82010
+ addrCont =
82011
+ sqlite3VdbeAddOp3(v, OP_RowSetRead, regOrRowset,addrBrk,regNextRowid);
82012
+ sqlite3VdbeAddOp2(v, OP_Seek, iCur, regNextRowid);
82013
+ sqlite3ReleaseTempReg(pParse, regNextRowid);
82014
+ /* sqlite3ReleaseTempReg(pParse, regOrRowset); // Preserve the RowSet */
82015
+ pLevel->op = OP_Goto;
82016
+ pLevel->p2 = addrCont;
82017
+ }else{
82018
+ pLevel->op = OP_Noop;
82019
+ }
82020
+ disableTerm(pLevel, pTerm);
82021
+ }else
82022
+#endif /* SQLITE_OMIT_OR_OPTIMIZATION */
82023
+
82024
+ {
82025
+ /* Case 5: There is no usable index. We must do a complete
82026
+ ** scan of the entire table.
82027
+ */
82028
+ assert( omitTable==0 );
82029
+ assert( bRev==0 );
82030
+ pLevel->op = OP_Next;
82031
+ pLevel->p1 = iCur;
82032
+ pLevel->p2 = 1 + sqlite3VdbeAddOp2(v, OP_Rewind, iCur, addrBrk);
82033
+ pLevel->p5 = SQLITE_STMTSTATUS_FULLSCAN_STEP;
82034
+ codeRowSetEarly = 0;
82035
+ }
82036
+ notReady &= ~getMask(pWC->pMaskSet, iCur);
82037
+
82038
+ /* Insert code to test every subexpression that can be completely
82039
+ ** computed using the current set of tables.
82040
+ */
82041
+ k = 0;
82042
+ for(pTerm=pWC->a, j=pWC->nTerm; j>0; j--, pTerm++){
82043
+ Expr *pE;
82044
+ testcase( pTerm->wtFlags & TERM_VIRTUAL );
82045
+ testcase( pTerm->wtFlags & TERM_CODED );
82046
+ if( pTerm->wtFlags & (TERM_VIRTUAL|TERM_CODED) ) continue;
82047
+ if( (pTerm->prereqAll & notReady)!=0 ) continue;
82048
+ pE = pTerm->pExpr;
82049
+ assert( pE!=0 );
82050
+ if( pLevel->iLeftJoin && !ExprHasProperty(pE, EP_FromJoin) ){
82051
+ continue;
82052
+ }
82053
+ pParse->disableColCache += k;
82054
+ sqlite3ExprIfFalse(pParse, pE, addrCont, SQLITE_JUMPIFNULL);
82055
+ pParse->disableColCache -= k;
82056
+ k = 1;
82057
+ pTerm->wtFlags |= TERM_CODED;
82058
+ }
82059
+
82060
+ /* For a LEFT OUTER JOIN, generate code that will record the fact that
82061
+ ** at least one row of the right table has matched the left table.
82062
+ */
82063
+ if( pLevel->iLeftJoin ){
82064
+ pLevel->addrFirst = sqlite3VdbeCurrentAddr(v);
82065
+ sqlite3VdbeAddOp2(v, OP_Integer, 1, pLevel->iLeftJoin);
82066
+ VdbeComment((v, "record LEFT JOIN hit"));
82067
+ sqlite3ExprClearColumnCache(pParse, pLevel->iTabCur);
82068
+ sqlite3ExprClearColumnCache(pParse, pLevel->iIdxCur);
82069
+ for(pTerm=pWC->a, j=0; j<pWC->nTerm; j++, pTerm++){
82070
+ testcase( pTerm->wtFlags & TERM_VIRTUAL );
82071
+ testcase( pTerm->wtFlags & TERM_CODED );
82072
+ if( pTerm->wtFlags & (TERM_VIRTUAL|TERM_CODED) ) continue;
82073
+ if( (pTerm->prereqAll & notReady)!=0 ) continue;
82074
+ assert( pTerm->pExpr );
82075
+ sqlite3ExprIfFalse(pParse, pTerm->pExpr, addrCont, SQLITE_JUMPIFNULL);
82076
+ pTerm->wtFlags |= TERM_CODED;
82077
+ }
82078
+ }
82079
+
82080
+ /*
82081
+ ** If it was requested to store the results in a rowset and that has
82082
+ ** not already been do, then do so now.
82083
+ */
82084
+ if( regRowSet>=0 && !codeRowSetEarly ){
82085
+ int r1 = sqlite3GetTempReg(pParse);
82086
+#ifndef SQLITE_OMIT_VIRTUALTABLE
82087
+ if( (pLevel->plan.wsFlags & WHERE_VIRTUALTABLE)!=0 ){
82088
+ sqlite3VdbeAddOp2(v, OP_VRowid, iCur, r1);
82089
+ }else
82090
+#endif
82091
+ {
82092
+ sqlite3VdbeAddOp2(v, OP_Rowid, iCur, r1);
82093
+ }
82094
+ sqlite3VdbeAddOp2(v, OP_RowSetAdd, regRowSet, r1);
82095
+ sqlite3ReleaseTempReg(pParse, r1);
82096
+ }
82097
+
82098
+ return notReady;
82099
+}
8065582100
8065682101
#if defined(SQLITE_TEST)
8065782102
/*
8065882103
** The following variable holds a text description of query plan generated
8065982104
** by the most recent call to sqlite3WhereBegin(). Each call to WhereBegin
@@ -80673,14 +82118,18 @@
8067382118
if( pWInfo ){
8067482119
int i;
8067582120
for(i=0; i<pWInfo->nLevel; i++){
8067682121
sqlite3_index_info *pInfo = pWInfo->a[i].pIdxInfo;
8067782122
if( pInfo ){
80678
- assert( pInfo->needToFreeIdxStr==0 );
82123
+ assert( pInfo->needToFreeIdxStr==0 || db->mallocFailed );
82124
+ if( pInfo->needToFreeIdxStr ){
82125
+ sqlite3_free(pInfo->idxStr);
82126
+ }
8067982127
sqlite3DbFree(db, pInfo);
8068082128
}
8068182129
}
82130
+ whereClauseClear(pWInfo->pWC);
8068282131
sqlite3DbFree(db, pWInfo);
8068382132
}
8068482133
}
8068582134
8068682135
@@ -80775,24 +82224,23 @@
8077582224
SQLITE_PRIVATE WhereInfo *sqlite3WhereBegin(
8077682225
Parse *pParse, /* The parser context */
8077782226
SrcList *pTabList, /* A list of all tables to be scanned */
8077882227
Expr *pWhere, /* The WHERE clause */
8077982228
ExprList **ppOrderBy, /* An ORDER BY clause, or NULL */
80780
- u8 wctrlFlags /* One of the WHERE_* flags defined in sqliteInt.h */
82229
+ u8 wctrlFlags, /* One of the WHERE_* flags defined in sqliteInt.h */
82230
+ int regRowSet /* Register hold RowSet if WHERE_FILL_ROWSET is set */
8078182231
){
8078282232
int i; /* Loop counter */
8078382233
WhereInfo *pWInfo; /* Will become the return value of this function */
8078482234
Vdbe *v = pParse->pVdbe; /* The virtual database engine */
80785
- int addrBrk, addrCont = 0; /* Addresses used during code generation */
8078682235
Bitmask notReady; /* Cursors that are not yet positioned */
80787
- WhereTerm *pTerm; /* A single term in the WHERE clause */
80788
- ExprMaskSet maskSet; /* The expression mask set */
80789
- WhereClause wc; /* The WHERE clause is divided into these terms */
82236
+ WhereMaskSet *pMaskSet; /* The expression mask set */
82237
+ WhereClause *pWC; /* Decomposition of the WHERE clause */
8079082238
struct SrcList_item *pTabItem; /* A single entry from pTabList */
8079182239
WhereLevel *pLevel; /* A single level in the pWInfo list */
8079282240
int iFrom; /* First unused FROM clause element */
80793
- int andFlags; /* AND-ed combination of all wc.a[].wtFlags */
82241
+ int andFlags; /* AND-ed combination of all pWC->a[].wtFlags */
8079482242
sqlite3 *db; /* Database connection */
8079582243
ExprList *pOrderBy = 0;
8079682244
8079782245
/* The number of tables in the FROM clause is limited by the number of
8079882246
** bits in a Bitmask
@@ -80804,32 +82252,40 @@
8080482252
8080582253
if( ppOrderBy ){
8080682254
pOrderBy = *ppOrderBy;
8080782255
}
8080882256
80809
- /* Split the WHERE clause into separate subexpressions where each
80810
- ** subexpression is separated by an AND operator.
80811
- */
80812
- initMaskSet(&maskSet);
80813
- whereClauseInit(&wc, pParse, &maskSet);
80814
- sqlite3ExprCodeConstants(pParse, pWhere);
80815
- whereSplit(&wc, pWhere, TK_AND);
80816
-
8081782257
/* Allocate and initialize the WhereInfo structure that will become the
8081882258
** return value.
8081982259
*/
8082082260
db = pParse->db;
8082182261
pWInfo = sqlite3DbMallocZero(db,
80822
- sizeof(WhereInfo) + pTabList->nSrc*sizeof(WhereLevel));
82262
+ sizeof(WhereInfo)
82263
+ + (pTabList->nSrc-1)*sizeof(WhereLevel)
82264
+ + sizeof(WhereClause)
82265
+ + sizeof(WhereMaskSet)
82266
+ );
8082382267
if( db->mallocFailed ){
8082482268
goto whereBeginError;
8082582269
}
8082682270
pWInfo->nLevel = pTabList->nSrc;
8082782271
pWInfo->pParse = pParse;
8082882272
pWInfo->pTabList = pTabList;
8082982273
pWInfo->iBreak = sqlite3VdbeMakeLabel(v);
82274
+ pWInfo->regRowSet = (wctrlFlags & WHERE_FILL_ROWSET) ? regRowSet : -1;
82275
+ pWInfo->pWC = pWC = (WhereClause*)&pWInfo->a[pWInfo->nLevel];
82276
+ pWInfo->wctrlFlags = wctrlFlags;
82277
+ pMaskSet = (WhereMaskSet*)&pWC[1];
8083082278
82279
+ /* Split the WHERE clause into separate subexpressions where each
82280
+ ** subexpression is separated by an AND operator.
82281
+ */
82282
+ initMaskSet(pMaskSet);
82283
+ whereClauseInit(pWC, pParse, pMaskSet);
82284
+ sqlite3ExprCodeConstants(pParse, pWhere);
82285
+ whereSplit(pWC, pWhere, TK_AND);
82286
+
8083182287
/* Special case: a WHERE clause that is constant. Evaluate the
8083282288
** expression and either jump over all of the code or fall thru.
8083382289
*/
8083482290
if( pWhere && (pTabList->nSrc==0 || sqlite3ExprIsConstantNotJoin(pWhere)) ){
8083582291
sqlite3ExprIfFalse(pParse, pWhere, pWInfo->iBreak, SQLITE_JUMPIFNULL);
@@ -80846,17 +82302,17 @@
8084682302
** of the join. Subtracting one from the right table bitmask gives a
8084782303
** bitmask for all tables to the left of the join. Knowing the bitmask
8084882304
** for all tables to the left of a left join is important. Ticket #3015.
8084982305
*/
8085082306
for(i=0; i<pTabList->nSrc; i++){
80851
- createMask(&maskSet, pTabList->a[i].iCursor);
82307
+ createMask(pMaskSet, pTabList->a[i].iCursor);
8085282308
}
8085382309
#ifndef NDEBUG
8085482310
{
8085582311
Bitmask toTheLeft = 0;
8085682312
for(i=0; i<pTabList->nSrc; i++){
80857
- Bitmask m = getMask(&maskSet, pTabList->a[i].iCursor);
82313
+ Bitmask m = getMask(pMaskSet, pTabList->a[i].iCursor);
8085882314
assert( (m-1)==toTheLeft );
8085982315
toTheLeft |= m;
8086082316
}
8086182317
}
8086282318
#endif
@@ -80864,11 +82320,11 @@
8086482320
/* Analyze all of the subexpressions. Note that exprAnalyze() might
8086582321
** add new virtual terms onto the end of the WHERE clause. We do not
8086682322
** want to analyze these virtual terms, so start analyzing at the end
8086782323
** and work forward so that the added virtual terms are never processed.
8086882324
*/
80869
- exprAnalyzeAll(pTabList, &wc);
82325
+ exprAnalyzeAll(pTabList, pWC);
8087082326
if( db->mallocFailed ){
8087182327
goto whereBeginError;
8087282328
}
8087382329
8087482330
/* Chose the best index to use for each table in the FROM clause.
@@ -80879,10 +82335,11 @@
8087982335
** pWInfo->a[].wsFlags WHERE_xxx flags associated with pIdx
8088082336
** pWInfo->a[].nEq The number of == and IN constraints
8088182337
** pWInfo->a[].iFrom Which term of the FROM clause is being coded
8088282338
** pWInfo->a[].iTabCur The VDBE cursor for the database table
8088382339
** pWInfo->a[].iIdxCur The VDBE cursor for the index
82340
+ ** pWInfo->a[].pTerm When wsFlags==WO_OR, the OR-clause term
8088482341
**
8088582342
** This loop also figures out the nesting order of tables in the FROM
8088682343
** clause.
8088782344
*/
8088882345
notReady = ~(Bitmask)0;
@@ -80889,108 +82346,103 @@
8088982346
pTabItem = pTabList->a;
8089082347
pLevel = pWInfo->a;
8089182348
andFlags = ~0;
8089282349
WHERETRACE(("*** Optimizer Start ***\n"));
8089382350
for(i=iFrom=0, pLevel=pWInfo->a; i<pTabList->nSrc; i++, pLevel++){
82351
+ WhereCost bestPlan; /* Most efficient plan seen so far */
8089482352
Index *pIdx; /* Index for FROM table at pTabItem */
80895
- int wsFlags; /* Flags describing scan strategy */
80896
- int nEq; /* Number of == or IN constraints */
80897
- double cost; /* The cost for pIdx */
8089882353
int j; /* For looping over FROM tables */
80899
- Index *pBest = 0; /* The best index seen so far */
80900
- int bestWsFlags = 0; /* Flags associated with pBest */
80901
- int bestNEq = 0; /* nEq associated with pBest */
80902
- double lowestCost; /* Cost of the pBest */
8090382354
int bestJ = 0; /* The value of j */
8090482355
Bitmask m; /* Bitmask value for j or bestJ */
8090582356
int once = 0; /* True when first table is seen */
80906
- sqlite3_index_info *pIndex; /* Current virtual index */
8090782357
80908
- lowestCost = SQLITE_BIG_DBL;
82358
+ memset(&bestPlan, 0, sizeof(bestPlan));
82359
+ bestPlan.rCost = SQLITE_BIG_DBL;
8090982360
for(j=iFrom, pTabItem=&pTabList->a[j]; j<pTabList->nSrc; j++, pTabItem++){
8091082361
int doNotReorder; /* True if this table should not be reordered */
82362
+ WhereCost sCost; /* Cost information from bestIndex() */
8091182363
8091282364
doNotReorder = (pTabItem->jointype & (JT_LEFT|JT_CROSS))!=0;
8091382365
if( once && doNotReorder ) break;
80914
- m = getMask(&maskSet, pTabItem->iCursor);
82366
+ m = getMask(pMaskSet, pTabItem->iCursor);
8091582367
if( (m & notReady)==0 ){
8091682368
if( j==iFrom ) iFrom++;
8091782369
continue;
8091882370
}
8091982371
assert( pTabItem->pTab );
8092082372
#ifndef SQLITE_OMIT_VIRTUALTABLE
8092182373
if( IsVirtual(pTabItem->pTab) ){
82374
+ sqlite3_index_info *pVtabIdx; /* Current virtual index */
8092282375
sqlite3_index_info **ppIdxInfo = &pWInfo->a[j].pIdxInfo;
80923
- cost = bestVirtualIndex(pParse, &wc, pTabItem, notReady,
80924
- ppOrderBy ? *ppOrderBy : 0, i==0,
80925
- ppIdxInfo);
80926
- wsFlags = WHERE_VIRTUALTABLE;
80927
- pIndex = *ppIdxInfo;
80928
- if( pIndex && pIndex->orderByConsumed ){
80929
- wsFlags = WHERE_VIRTUALTABLE | WHERE_ORDERBY;
80930
- }
80931
- pIdx = 0;
80932
- nEq = 0;
80933
- if( (SQLITE_BIG_DBL/2.0)<cost ){
82376
+ sCost.rCost = bestVirtualIndex(pParse, pWC, pTabItem, notReady,
82377
+ ppOrderBy ? *ppOrderBy : 0, i==0,
82378
+ ppIdxInfo);
82379
+ sCost.plan.wsFlags = WHERE_VIRTUALTABLE;
82380
+ sCost.plan.u.pVtabIdx = pVtabIdx = *ppIdxInfo;
82381
+ if( pVtabIdx && pVtabIdx->orderByConsumed ){
82382
+ sCost.plan.wsFlags = WHERE_VIRTUALTABLE | WHERE_ORDERBY;
82383
+ }
82384
+ sCost.plan.nEq = 0;
82385
+ if( (SQLITE_BIG_DBL/2.0)<sCost.rCost ){
8093482386
/* The cost is not allowed to be larger than SQLITE_BIG_DBL (the
8093582387
** inital value of lowestCost in this loop. If it is, then
80936
- ** the (cost<lowestCost) test below will never be true and
80937
- ** pLevel->pBestIdx never set.
82388
+ ** the (cost<lowestCost) test below will never be true.
8093882389
*/
80939
- cost = (SQLITE_BIG_DBL/2.0);
82390
+ sCost.rCost = (SQLITE_BIG_DBL/2.0);
8094082391
}
8094182392
}else
8094282393
#endif
8094382394
{
80944
- cost = bestIndex(pParse, &wc, pTabItem, notReady,
80945
- (i==0 && ppOrderBy) ? *ppOrderBy : 0,
80946
- &pIdx, &wsFlags, &nEq);
80947
- pIndex = 0;
82395
+ bestIndex(pParse, pWC, pTabItem, notReady,
82396
+ (i==0 && ppOrderBy) ? *ppOrderBy : 0, &sCost);
8094882397
}
80949
- if( cost<lowestCost ){
82398
+ if( once==0 || sCost.rCost<bestPlan.rCost ){
8095082399
once = 1;
80951
- lowestCost = cost;
80952
- pBest = pIdx;
80953
- bestWsFlags = wsFlags;
80954
- bestNEq = nEq;
82400
+ bestPlan = sCost;
8095582401
bestJ = j;
80956
- pLevel->pBestIdx = pIndex;
8095782402
}
8095882403
if( doNotReorder ) break;
8095982404
}
82405
+ assert( once );
82406
+ assert( notReady & getMask(pMaskSet, pTabList->a[bestJ].iCursor) );
8096082407
WHERETRACE(("*** Optimizer selects table %d for loop %d\n", bestJ,
8096182408
pLevel-pWInfo->a));
80962
- if( (bestWsFlags & WHERE_ORDERBY)!=0 ){
82409
+ if( (bestPlan.plan.wsFlags & WHERE_ORDERBY)!=0 ){
8096382410
*ppOrderBy = 0;
8096482411
}
80965
- andFlags &= bestWsFlags;
80966
- pLevel->wsFlags = bestWsFlags;
80967
- pLevel->pIdx = pBest;
80968
- pLevel->nEq = bestNEq;
80969
- pLevel->aInLoop = 0;
80970
- pLevel->nIn = 0;
80971
- if( pBest ){
82412
+ andFlags &= bestPlan.plan.wsFlags;
82413
+ pLevel->plan = bestPlan.plan;
82414
+ if( bestPlan.plan.wsFlags & WHERE_INDEXED ){
8097282415
pLevel->iIdxCur = pParse->nTab++;
8097382416
}else{
8097482417
pLevel->iIdxCur = -1;
8097582418
}
80976
- notReady &= ~getMask(&maskSet, pTabList->a[bestJ].iCursor);
82419
+ notReady &= ~getMask(pMaskSet, pTabList->a[bestJ].iCursor);
8097782420
pLevel->iFrom = bestJ;
8097882421
8097982422
/* Check that if the table scanned by this loop iteration had an
8098082423
** INDEXED BY clause attached to it, that the named index is being
8098182424
** used for the scan. If not, then query compilation has failed.
8098282425
** Return an error.
8098382426
*/
8098482427
pIdx = pTabList->a[bestJ].pIndex;
80985
- assert( !pIdx || !pBest || pIdx==pBest );
80986
- if( pIdx && pBest!=pIdx ){
80987
- sqlite3ErrorMsg(pParse, "cannot use index: %s", pIdx->zName);
80988
- goto whereBeginError;
82428
+ if( pIdx ){
82429
+ if( (bestPlan.plan.wsFlags & WHERE_INDEXED)==0 ){
82430
+ sqlite3ErrorMsg(pParse, "cannot use index: %s", pIdx->zName);
82431
+ goto whereBeginError;
82432
+ }else{
82433
+ /* If an INDEXED BY clause is used, the bestIndex() function is
82434
+ ** guaranteed to find the index specified in the INDEXED BY clause
82435
+ ** if it find an index at all. */
82436
+ assert( bestPlan.plan.u.pIdx==pIdx );
82437
+ }
8098982438
}
8099082439
}
8099182440
WHERETRACE(("*** Optimizer Finished ***\n"));
82441
+ if( db->mallocFailed ){
82442
+ goto whereBeginError;
82443
+ }
8099282444
8099382445
/* If the total query only selects a single row, then the ORDER BY
8099482446
** clause is irrelevant.
8099582447
*/
8099682448
if( (andFlags & WHERE_UNIQUE)!=0 && ppOrderBy ){
@@ -81003,44 +82455,45 @@
8100382455
** the statement to update a single row.
8100482456
*/
8100582457
assert( (wctrlFlags & WHERE_ONEPASS_DESIRED)==0 || pWInfo->nLevel==1 );
8100682458
if( (wctrlFlags & WHERE_ONEPASS_DESIRED)!=0 && (andFlags & WHERE_UNIQUE)!=0 ){
8100782459
pWInfo->okOnePass = 1;
81008
- pWInfo->a[0].wsFlags &= ~WHERE_IDX_ONLY;
82460
+ pWInfo->a[0].plan.wsFlags &= ~WHERE_IDX_ONLY;
8100982461
}
8101082462
8101182463
/* Open all tables in the pTabList and any indices selected for
8101282464
** searching those tables.
8101382465
*/
8101482466
sqlite3CodeVerifySchema(pParse, -1); /* Insert the cookie verifier Goto */
8101582467
for(i=0, pLevel=pWInfo->a; i<pTabList->nSrc; i++, pLevel++){
8101682468
Table *pTab; /* Table to open */
81017
- Index *pIx; /* Index used to access pTab (if any) */
8101882469
int iDb; /* Index of database containing table/index */
81019
- int iIdxCur = pLevel->iIdxCur;
8102082470
8102182471
#ifndef SQLITE_OMIT_EXPLAIN
8102282472
if( pParse->explain==2 ){
8102382473
char *zMsg;
8102482474
struct SrcList_item *pItem = &pTabList->a[pLevel->iFrom];
8102582475
zMsg = sqlite3MPrintf(db, "TABLE %s", pItem->zName);
8102682476
if( pItem->zAlias ){
8102782477
zMsg = sqlite3MAppendf(db, zMsg, "%s AS %s", zMsg, pItem->zAlias);
8102882478
}
81029
- if( (pIx = pLevel->pIdx)!=0 ){
81030
- zMsg = sqlite3MAppendf(db, zMsg, "%s WITH INDEX %s", zMsg, pIx->zName);
81031
- }else if( pLevel->wsFlags & (WHERE_ROWID_EQ|WHERE_ROWID_RANGE) ){
82479
+ if( (pLevel->plan.wsFlags & WHERE_INDEXED)!=0 ){
82480
+ zMsg = sqlite3MAppendf(db, zMsg, "%s WITH INDEX %s",
82481
+ zMsg, pLevel->plan.u.pIdx->zName);
82482
+ }else if( pLevel->plan.wsFlags & WHERE_MULTI_OR ){
82483
+ zMsg = sqlite3MAppendf(db, zMsg, "%s VIA MULTI-INDEX UNION", zMsg);
82484
+ }else if( pLevel->plan.wsFlags & (WHERE_ROWID_EQ|WHERE_ROWID_RANGE) ){
8103282485
zMsg = sqlite3MAppendf(db, zMsg, "%s USING PRIMARY KEY", zMsg);
8103382486
}
8103482487
#ifndef SQLITE_OMIT_VIRTUALTABLE
81035
- else if( pLevel->pBestIdx ){
81036
- sqlite3_index_info *pBestIdx = pLevel->pBestIdx;
82488
+ else if( (pLevel->plan.wsFlags & WHERE_VIRTUALTABLE)!=0 ){
82489
+ sqlite3_index_info *pVtabIdx = pLevel->plan.u.pVtabIdx;
8103782490
zMsg = sqlite3MAppendf(db, zMsg, "%s VIRTUAL TABLE INDEX %d:%s", zMsg,
81038
- pBestIdx->idxNum, pBestIdx->idxStr);
82491
+ pVtabIdx->idxNum, pVtabIdx->idxStr);
8103982492
}
8104082493
#endif
81041
- if( pLevel->wsFlags & WHERE_ORDERBY ){
82494
+ if( pLevel->plan.wsFlags & WHERE_ORDERBY ){
8104282495
zMsg = sqlite3MAppendf(db, zMsg, "%s ORDER BY", zMsg);
8104382496
}
8104482497
sqlite3VdbeAddOp4(v, OP_Explain, i, pLevel->iFrom, 0, zMsg, P4_DYNAMIC);
8104582498
}
8104682499
#endif /* SQLITE_OMIT_EXPLAIN */
@@ -81047,17 +82500,18 @@
8104782500
pTabItem = &pTabList->a[pLevel->iFrom];
8104882501
pTab = pTabItem->pTab;
8104982502
iDb = sqlite3SchemaToIndex(pParse->db, pTab->pSchema);
8105082503
if( (pTab->tabFlags & TF_Ephemeral)!=0 || pTab->pSelect ) continue;
8105182504
#ifndef SQLITE_OMIT_VIRTUALTABLE
81052
- if( pLevel->pBestIdx ){
82505
+ if( (pLevel->plan.wsFlags & WHERE_VIRTUALTABLE)!=0 ){
8105382506
int iCur = pTabItem->iCursor;
8105482507
sqlite3VdbeAddOp4(v, OP_VOpen, iCur, 0, 0,
8105582508
(const char*)pTab->pVtab, P4_VTAB);
8105682509
}else
8105782510
#endif
81058
- if( (pLevel->wsFlags & WHERE_IDX_ONLY)==0 ){
82511
+ if( (pLevel->plan.wsFlags & WHERE_IDX_ONLY)==0
82512
+ && (wctrlFlags & WHERE_OMIT_OPEN)==0 ){
8105982513
int op = pWInfo->okOnePass ? OP_OpenWrite : OP_OpenRead;
8106082514
sqlite3OpenTable(pParse, pTabItem->iCursor, iDb, pTab, op);
8106182515
if( !pWInfo->okOnePass && pTab->nCol<BMS ){
8106282516
Bitmask b = pTabItem->colUsed;
8106382517
int n = 0;
@@ -81067,13 +82521,16 @@
8106782521
}
8106882522
}else{
8106982523
sqlite3TableLock(pParse, iDb, pTab->tnum, 0, pTab->zName);
8107082524
}
8107182525
pLevel->iTabCur = pTabItem->iCursor;
81072
- if( (pIx = pLevel->pIdx)!=0 ){
82526
+ if( (pLevel->plan.wsFlags & WHERE_INDEXED)!=0 ){
82527
+ Index *pIx = pLevel->plan.u.pIdx;
8107382528
KeyInfo *pKey = sqlite3IndexKeyinfo(pParse, pIx);
82529
+ int iIdxCur = pLevel->iIdxCur;
8107482530
assert( pIx->pSchema==pTab->pSchema );
82531
+ assert( iIdxCur>=0 );
8107582532
sqlite3VdbeAddOp2(v, OP_SetNumColumns, 0, pIx->nColumn+1);
8107682533
sqlite3VdbeAddOp4(v, OP_OpenRead, iIdxCur, pIx->tnum, iDb,
8107782534
(char*)pKey, P4_KEYINFO_HANDOFF);
8107882535
VdbeComment((v, "%s", pIx->zName));
8107982536
}
@@ -81084,428 +82541,13 @@
8108482541
/* Generate the code to do the search. Each iteration of the for
8108582542
** loop below generates code for a single nested loop of the VM
8108682543
** program.
8108782544
*/
8108882545
notReady = ~(Bitmask)0;
81089
- for(i=0, pLevel=pWInfo->a; i<pTabList->nSrc; i++, pLevel++){
81090
- int j, k;
81091
- int iCur = pTabItem->iCursor; /* The VDBE cursor for the table */
81092
- Index *pIdx; /* The index we will be using */
81093
- int addrNxt; /* Where to jump to continue with the next IN case */
81094
- int iIdxCur; /* The VDBE cursor for the index */
81095
- int omitTable; /* True if we use the index only */
81096
- int bRev; /* True if we need to scan in reverse order */
81097
-
81098
- pTabItem = &pTabList->a[pLevel->iFrom];
81099
- iCur = pTabItem->iCursor;
81100
- pIdx = pLevel->pIdx;
81101
- iIdxCur = pLevel->iIdxCur;
81102
- bRev = (pLevel->wsFlags & WHERE_REVERSE)!=0;
81103
- omitTable = (pLevel->wsFlags & WHERE_IDX_ONLY)!=0;
81104
-
81105
- /* Create labels for the "break" and "continue" instructions
81106
- ** for the current loop. Jump to addrBrk to break out of a loop.
81107
- ** Jump to cont to go immediately to the next iteration of the
81108
- ** loop.
81109
- **
81110
- ** When there is an IN operator, we also have a "addrNxt" label that
81111
- ** means to continue with the next IN value combination. When
81112
- ** there are no IN operators in the constraints, the "addrNxt" label
81113
- ** is the same as "addrBrk".
81114
- */
81115
- addrBrk = pLevel->addrBrk = pLevel->addrNxt = sqlite3VdbeMakeLabel(v);
81116
- addrCont = pLevel->addrCont = sqlite3VdbeMakeLabel(v);
81117
-
81118
- /* If this is the right table of a LEFT OUTER JOIN, allocate and
81119
- ** initialize a memory cell that records if this table matches any
81120
- ** row of the left table of the join.
81121
- */
81122
- if( pLevel->iFrom>0 && (pTabItem[0].jointype & JT_LEFT)!=0 ){
81123
- pLevel->iLeftJoin = ++pParse->nMem;
81124
- sqlite3VdbeAddOp2(v, OP_Integer, 0, pLevel->iLeftJoin);
81125
- VdbeComment((v, "init LEFT JOIN no-match flag"));
81126
- }
81127
-
81128
-#ifndef SQLITE_OMIT_VIRTUALTABLE
81129
- if( pLevel->pBestIdx ){
81130
- /* Case 0: The table is a virtual-table. Use the VFilter and VNext
81131
- ** to access the data.
81132
- */
81133
- int iReg; /* P3 Value for OP_VFilter */
81134
- sqlite3_index_info *pBestIdx = pLevel->pBestIdx;
81135
- int nConstraint = pBestIdx->nConstraint;
81136
- struct sqlite3_index_constraint_usage *aUsage =
81137
- pBestIdx->aConstraintUsage;
81138
- const struct sqlite3_index_constraint *aConstraint =
81139
- pBestIdx->aConstraint;
81140
-
81141
- iReg = sqlite3GetTempRange(pParse, nConstraint+2);
81142
- pParse->disableColCache++;
81143
- for(j=1; j<=nConstraint; j++){
81144
- for(k=0; k<nConstraint; k++){
81145
- if( aUsage[k].argvIndex==j ){
81146
- int iTerm = aConstraint[k].iTermOffset;
81147
- assert( pParse->disableColCache );
81148
- sqlite3ExprCode(pParse, wc.a[iTerm].pExpr->pRight, iReg+j+1);
81149
- break;
81150
- }
81151
- }
81152
- if( k==nConstraint ) break;
81153
- }
81154
- assert( pParse->disableColCache );
81155
- pParse->disableColCache--;
81156
- sqlite3VdbeAddOp2(v, OP_Integer, pBestIdx->idxNum, iReg);
81157
- sqlite3VdbeAddOp2(v, OP_Integer, j-1, iReg+1);
81158
- sqlite3VdbeAddOp4(v, OP_VFilter, iCur, addrBrk, iReg, pBestIdx->idxStr,
81159
- pBestIdx->needToFreeIdxStr ? P4_MPRINTF : P4_STATIC);
81160
- sqlite3ReleaseTempRange(pParse, iReg, nConstraint+2);
81161
- pBestIdx->needToFreeIdxStr = 0;
81162
- for(j=0; j<nConstraint; j++){
81163
- if( aUsage[j].omit ){
81164
- int iTerm = aConstraint[j].iTermOffset;
81165
- disableTerm(pLevel, &wc.a[iTerm]);
81166
- }
81167
- }
81168
- pLevel->op = OP_VNext;
81169
- pLevel->p1 = iCur;
81170
- pLevel->p2 = sqlite3VdbeCurrentAddr(v);
81171
- }else
81172
-#endif /* SQLITE_OMIT_VIRTUALTABLE */
81173
-
81174
- if( pLevel->wsFlags & WHERE_ROWID_EQ ){
81175
- /* Case 1: We can directly reference a single row using an
81176
- ** equality comparison against the ROWID field. Or
81177
- ** we reference multiple rows using a "rowid IN (...)"
81178
- ** construct.
81179
- */
81180
- int r1;
81181
- int rtmp = sqlite3GetTempReg(pParse);
81182
- pTerm = findTerm(&wc, iCur, -1, notReady, WO_EQ|WO_IN, 0);
81183
- assert( pTerm!=0 );
81184
- assert( pTerm->pExpr!=0 );
81185
- assert( pTerm->leftCursor==iCur );
81186
- assert( omitTable==0 );
81187
- r1 = codeEqualityTerm(pParse, pTerm, pLevel, rtmp);
81188
- addrNxt = pLevel->addrNxt;
81189
- sqlite3VdbeAddOp2(v, OP_MustBeInt, r1, addrNxt);
81190
- sqlite3VdbeAddOp3(v, OP_NotExists, iCur, addrNxt, r1);
81191
- sqlite3ReleaseTempReg(pParse, rtmp);
81192
- VdbeComment((v, "pk"));
81193
- pLevel->op = OP_Noop;
81194
- }else if( pLevel->wsFlags & WHERE_ROWID_RANGE ){
81195
- /* Case 2: We have an inequality comparison against the ROWID field.
81196
- */
81197
- int testOp = OP_Noop;
81198
- int start;
81199
- WhereTerm *pStart, *pEnd;
81200
-
81201
- assert( omitTable==0 );
81202
- pStart = findTerm(&wc, iCur, -1, notReady, WO_GT|WO_GE, 0);
81203
- pEnd = findTerm(&wc, iCur, -1, notReady, WO_LT|WO_LE, 0);
81204
- if( bRev ){
81205
- pTerm = pStart;
81206
- pStart = pEnd;
81207
- pEnd = pTerm;
81208
- }
81209
- if( pStart ){
81210
- Expr *pX; /* The expression that defines the start bound */
81211
- int r1, rTemp; /* Registers for holding the start boundary */
81212
-
81213
- /* The following constant maps TK_xx codes into corresponding
81214
- ** seek opcodes. It depends on a particular ordering of TK_xx
81215
- */
81216
- const u8 aMoveOp[] = {
81217
- /* TK_GT */ OP_SeekGt,
81218
- /* TK_LE */ OP_SeekLe,
81219
- /* TK_LT */ OP_SeekLt,
81220
- /* TK_GE */ OP_SeekGe
81221
- };
81222
- assert( TK_LE==TK_GT+1 ); /* Make sure the ordering.. */
81223
- assert( TK_LT==TK_GT+2 ); /* ... of the TK_xx values... */
81224
- assert( TK_GE==TK_GT+3 ); /* ... is correcct. */
81225
-
81226
- pX = pStart->pExpr;
81227
- assert( pX!=0 );
81228
- assert( pStart->leftCursor==iCur );
81229
- r1 = sqlite3ExprCodeTemp(pParse, pX->pRight, &rTemp);
81230
- sqlite3VdbeAddOp3(v, aMoveOp[pX->op-TK_GT], iCur, addrBrk, r1);
81231
- VdbeComment((v, "pk"));
81232
- sqlite3ExprCacheAffinityChange(pParse, r1, 1);
81233
- sqlite3ReleaseTempReg(pParse, rTemp);
81234
- disableTerm(pLevel, pStart);
81235
- }else{
81236
- sqlite3VdbeAddOp2(v, bRev ? OP_Last : OP_Rewind, iCur, addrBrk);
81237
- }
81238
- if( pEnd ){
81239
- Expr *pX;
81240
- pX = pEnd->pExpr;
81241
- assert( pX!=0 );
81242
- assert( pEnd->leftCursor==iCur );
81243
- pLevel->iMem = ++pParse->nMem;
81244
- sqlite3ExprCode(pParse, pX->pRight, pLevel->iMem);
81245
- if( pX->op==TK_LT || pX->op==TK_GT ){
81246
- testOp = bRev ? OP_Le : OP_Ge;
81247
- }else{
81248
- testOp = bRev ? OP_Lt : OP_Gt;
81249
- }
81250
- disableTerm(pLevel, pEnd);
81251
- }
81252
- start = sqlite3VdbeCurrentAddr(v);
81253
- pLevel->op = bRev ? OP_Prev : OP_Next;
81254
- pLevel->p1 = iCur;
81255
- pLevel->p2 = start;
81256
- if( testOp!=OP_Noop ){
81257
- int r1 = sqlite3GetTempReg(pParse);
81258
- sqlite3VdbeAddOp2(v, OP_Rowid, iCur, r1);
81259
- /* sqlite3VdbeAddOp2(v, OP_SCopy, pLevel->iMem, 0); */
81260
- sqlite3VdbeAddOp3(v, testOp, pLevel->iMem, addrBrk, r1);
81261
- sqlite3VdbeChangeP5(v, SQLITE_AFF_NUMERIC | SQLITE_JUMPIFNULL);
81262
- sqlite3ReleaseTempReg(pParse, r1);
81263
- }
81264
- }else if( pLevel->wsFlags & (WHERE_COLUMN_RANGE|WHERE_COLUMN_EQ) ){
81265
- /* Case 3: A scan using an index.
81266
- **
81267
- ** The WHERE clause may contain zero or more equality
81268
- ** terms ("==" or "IN" operators) that refer to the N
81269
- ** left-most columns of the index. It may also contain
81270
- ** inequality constraints (>, <, >= or <=) on the indexed
81271
- ** column that immediately follows the N equalities. Only
81272
- ** the right-most column can be an inequality - the rest must
81273
- ** use the "==" and "IN" operators. For example, if the
81274
- ** index is on (x,y,z), then the following clauses are all
81275
- ** optimized:
81276
- **
81277
- ** x=5
81278
- ** x=5 AND y=10
81279
- ** x=5 AND y<10
81280
- ** x=5 AND y>5 AND y<10
81281
- ** x=5 AND y=5 AND z<=10
81282
- **
81283
- ** The z<10 term of the following cannot be used, only
81284
- ** the x=5 term:
81285
- **
81286
- ** x=5 AND z<10
81287
- **
81288
- ** N may be zero if there are inequality constraints.
81289
- ** If there are no inequality constraints, then N is at
81290
- ** least one.
81291
- **
81292
- ** This case is also used when there are no WHERE clause
81293
- ** constraints but an index is selected anyway, in order
81294
- ** to force the output order to conform to an ORDER BY.
81295
- */
81296
- int aStartOp[] = {
81297
- 0,
81298
- 0,
81299
- OP_Rewind, /* 2: (!start_constraints && startEq && !bRev) */
81300
- OP_Last, /* 3: (!start_constraints && startEq && bRev) */
81301
- OP_SeekGt, /* 4: (start_constraints && !startEq && !bRev) */
81302
- OP_SeekLt, /* 5: (start_constraints && !startEq && bRev) */
81303
- OP_SeekGe, /* 6: (start_constraints && startEq && !bRev) */
81304
- OP_SeekLe /* 7: (start_constraints && startEq && bRev) */
81305
- };
81306
- int aEndOp[] = {
81307
- OP_Noop, /* 0: (!end_constraints) */
81308
- OP_IdxGE, /* 1: (end_constraints && !bRev) */
81309
- OP_IdxLT /* 2: (end_constraints && bRev) */
81310
- };
81311
- int nEq = pLevel->nEq;
81312
- int isMinQuery = 0; /* If this is an optimized SELECT min(x).. */
81313
- int regBase; /* Base register holding constraint values */
81314
- int r1; /* Temp register */
81315
- WhereTerm *pRangeStart = 0; /* Inequality constraint at range start */
81316
- WhereTerm *pRangeEnd = 0; /* Inequality constraint at range end */
81317
- int startEq; /* True if range start uses ==, >= or <= */
81318
- int endEq; /* True if range end uses ==, >= or <= */
81319
- int start_constraints; /* Start of range is constrained */
81320
- int nConstraint; /* Number of constraint terms */
81321
- int op;
81322
-
81323
- k = pIdx->aiColumn[nEq]; /* Column for inequality constraints */
81324
-
81325
- /* Generate code to evaluate all constraint terms using == or IN
81326
- ** and store the values of those terms in an array of registers
81327
- ** starting at regBase.
81328
- */
81329
- regBase = codeAllEqualityTerms(pParse, pLevel, &wc, notReady, 2);
81330
- addrNxt = pLevel->addrNxt;
81331
-
81332
- /* If this loop satisfies a sort order (pOrderBy) request that
81333
- ** was passed to this function to implement a "SELECT min(x) ..."
81334
- ** query, then the caller will only allow the loop to run for
81335
- ** a single iteration. This means that the first row returned
81336
- ** should not have a NULL value stored in 'x'. If column 'x' is
81337
- ** the first one after the nEq equality constraints in the index,
81338
- ** this requires some special handling.
81339
- */
81340
- if( (wctrlFlags&WHERE_ORDERBY_MIN)!=0
81341
- && (pLevel->wsFlags&WHERE_ORDERBY)
81342
- && (pIdx->nColumn>nEq)
81343
- ){
81344
- assert( pOrderBy->nExpr==1 );
81345
- assert( pOrderBy->a[0].pExpr->iColumn==pIdx->aiColumn[nEq] );
81346
- isMinQuery = 1;
81347
- }
81348
-
81349
- /* Find any inequality constraint terms for the start and end
81350
- ** of the range.
81351
- */
81352
- if( pLevel->wsFlags & WHERE_TOP_LIMIT ){
81353
- pRangeEnd = findTerm(&wc, iCur, k, notReady, (WO_LT|WO_LE), pIdx);
81354
- }
81355
- if( pLevel->wsFlags & WHERE_BTM_LIMIT ){
81356
- pRangeStart = findTerm(&wc, iCur, k, notReady, (WO_GT|WO_GE), pIdx);
81357
- }
81358
-
81359
- /* If we are doing a reverse order scan on an ascending index, or
81360
- ** a forward order scan on a descending index, interchange the
81361
- ** start and end terms (pRangeStart and pRangeEnd).
81362
- */
81363
- if( bRev==(pIdx->aSortOrder[nEq]==SQLITE_SO_ASC) ){
81364
- SWAP(WhereTerm *, pRangeEnd, pRangeStart);
81365
- }
81366
-
81367
- testcase( pRangeStart && pRangeStart->eOperator & WO_LE );
81368
- testcase( pRangeStart && pRangeStart->eOperator & WO_GE );
81369
- testcase( pRangeEnd && pRangeEnd->eOperator & WO_LE );
81370
- testcase( pRangeEnd && pRangeEnd->eOperator & WO_GE );
81371
- startEq = !pRangeStart || pRangeStart->eOperator & (WO_LE|WO_GE);
81372
- endEq = !pRangeEnd || pRangeEnd->eOperator & (WO_LE|WO_GE);
81373
- start_constraints = pRangeStart || nEq>0;
81374
-
81375
- /* Seek the index cursor to the start of the range. */
81376
- nConstraint = nEq;
81377
- if( pRangeStart ){
81378
- int dcc = pParse->disableColCache;
81379
- if( pRangeEnd ){
81380
- pParse->disableColCache++;
81381
- }
81382
- sqlite3ExprCode(pParse, pRangeStart->pExpr->pRight, regBase+nEq);
81383
- pParse->disableColCache = dcc;
81384
- sqlite3VdbeAddOp2(v, OP_IsNull, regBase+nEq, addrNxt);
81385
- nConstraint++;
81386
- }else if( isMinQuery ){
81387
- sqlite3VdbeAddOp2(v, OP_Null, 0, regBase+nEq);
81388
- nConstraint++;
81389
- startEq = 0;
81390
- start_constraints = 1;
81391
- }
81392
- codeApplyAffinity(pParse, regBase, nConstraint, pIdx);
81393
- op = aStartOp[(start_constraints<<2) + (startEq<<1) + bRev];
81394
- assert( op!=0 );
81395
- testcase( op==OP_Rewind );
81396
- testcase( op==OP_Last );
81397
- testcase( op==OP_SeekGt );
81398
- testcase( op==OP_SeekGe );
81399
- testcase( op==OP_SeekLe );
81400
- testcase( op==OP_SeekLt );
81401
- sqlite3VdbeAddOp4(v, op, iIdxCur, addrNxt, regBase,
81402
- SQLITE_INT_TO_PTR(nConstraint), P4_INT32);
81403
-
81404
- /* Load the value for the inequality constraint at the end of the
81405
- ** range (if any).
81406
- */
81407
- nConstraint = nEq;
81408
- if( pRangeEnd ){
81409
- sqlite3ExprCode(pParse, pRangeEnd->pExpr->pRight, regBase+nEq);
81410
- sqlite3VdbeAddOp2(v, OP_IsNull, regBase+nEq, addrNxt);
81411
- codeApplyAffinity(pParse, regBase, nEq+1, pIdx);
81412
- nConstraint++;
81413
- }
81414
-
81415
- /* Top of the loop body */
81416
- pLevel->p2 = sqlite3VdbeCurrentAddr(v);
81417
-
81418
- /* Check if the index cursor is past the end of the range. */
81419
- op = aEndOp[(pRangeEnd || nEq) * (1 + bRev)];
81420
- testcase( op==OP_Noop );
81421
- testcase( op==OP_IdxGE );
81422
- testcase( op==OP_IdxLT );
81423
- sqlite3VdbeAddOp4(v, op, iIdxCur, addrNxt, regBase,
81424
- SQLITE_INT_TO_PTR(nConstraint), P4_INT32);
81425
- sqlite3VdbeChangeP5(v, endEq!=bRev ?1:0);
81426
-
81427
- /* If there are inequality constraints, check that the value
81428
- ** of the table column that the inequality contrains is not NULL.
81429
- ** If it is, jump to the next iteration of the loop.
81430
- */
81431
- r1 = sqlite3GetTempReg(pParse);
81432
- testcase( pLevel->wsFlags & WHERE_BTM_LIMIT );
81433
- testcase( pLevel->wsFlags & WHERE_TOP_LIMIT );
81434
- if( pLevel->wsFlags & (WHERE_BTM_LIMIT|WHERE_TOP_LIMIT) ){
81435
- sqlite3VdbeAddOp3(v, OP_Column, iIdxCur, nEq, r1);
81436
- sqlite3VdbeAddOp2(v, OP_IsNull, r1, addrCont);
81437
- }
81438
-
81439
- /* Seek the table cursor, if required */
81440
- if( !omitTable ){
81441
- sqlite3VdbeAddOp2(v, OP_IdxRowid, iIdxCur, r1);
81442
- sqlite3VdbeAddOp2(v, OP_Seek, iCur, r1); /* Deferred seek */
81443
- }
81444
- sqlite3ReleaseTempReg(pParse, r1);
81445
-
81446
- /* Record the instruction used to terminate the loop. Disable
81447
- ** WHERE clause terms made redundant by the index range scan.
81448
- */
81449
- pLevel->op = bRev ? OP_Prev : OP_Next;
81450
- pLevel->p1 = iIdxCur;
81451
- disableTerm(pLevel, pRangeStart);
81452
- disableTerm(pLevel, pRangeEnd);
81453
- }else{
81454
- /* Case 4: There is no usable index. We must do a complete
81455
- ** scan of the entire table.
81456
- */
81457
- assert( omitTable==0 );
81458
- assert( bRev==0 );
81459
- pLevel->op = OP_Next;
81460
- pLevel->p1 = iCur;
81461
- pLevel->p2 = 1 + sqlite3VdbeAddOp2(v, OP_Rewind, iCur, addrBrk);
81462
- pLevel->p5 = SQLITE_STMTSTATUS_FULLSCAN_STEP;
81463
- }
81464
- notReady &= ~getMask(&maskSet, iCur);
81465
-
81466
- /* Insert code to test every subexpression that can be completely
81467
- ** computed using the current set of tables.
81468
- */
81469
- k = 0;
81470
- for(pTerm=wc.a, j=wc.nTerm; j>0; j--, pTerm++){
81471
- Expr *pE;
81472
- testcase( pTerm->wtFlags & TERM_VIRTUAL );
81473
- testcase( pTerm->wtFlags & TERM_CODED );
81474
- if( pTerm->wtFlags & (TERM_VIRTUAL|TERM_CODED) ) continue;
81475
- if( (pTerm->prereqAll & notReady)!=0 ) continue;
81476
- pE = pTerm->pExpr;
81477
- assert( pE!=0 );
81478
- if( pLevel->iLeftJoin && !ExprHasProperty(pE, EP_FromJoin) ){
81479
- continue;
81480
- }
81481
- pParse->disableColCache += k;
81482
- sqlite3ExprIfFalse(pParse, pE, addrCont, SQLITE_JUMPIFNULL);
81483
- pParse->disableColCache -= k;
81484
- k = 1;
81485
- pTerm->wtFlags |= TERM_CODED;
81486
- }
81487
-
81488
- /* For a LEFT OUTER JOIN, generate code that will record the fact that
81489
- ** at least one row of the right table has matched the left table.
81490
- */
81491
- if( pLevel->iLeftJoin ){
81492
- pLevel->addrFirst = sqlite3VdbeCurrentAddr(v);
81493
- sqlite3VdbeAddOp2(v, OP_Integer, 1, pLevel->iLeftJoin);
81494
- VdbeComment((v, "record LEFT JOIN hit"));
81495
- sqlite3ExprClearColumnCache(pParse, pLevel->iTabCur);
81496
- sqlite3ExprClearColumnCache(pParse, pLevel->iIdxCur);
81497
- for(pTerm=wc.a, j=0; j<wc.nTerm; j++, pTerm++){
81498
- testcase( pTerm->wtFlags & TERM_VIRTUAL );
81499
- testcase( pTerm->wtFlags & TERM_CODED );
81500
- if( pTerm->wtFlags & (TERM_VIRTUAL|TERM_CODED) ) continue;
81501
- if( (pTerm->prereqAll & notReady)!=0 ) continue;
81502
- assert( pTerm->pExpr );
81503
- sqlite3ExprIfFalse(pParse, pTerm->pExpr, addrCont, SQLITE_JUMPIFNULL);
81504
- pTerm->wtFlags |= TERM_CODED;
81505
- }
81506
- }
82546
+ for(i=0; i<pTabList->nSrc; i++){
82547
+ notReady = codeOneLoopStart(pWInfo, i, wctrlFlags, notReady);
82548
+ pWInfo->iContinue = pWInfo->a[i].addrCont;
8150782549
}
8150882550
8150982551
#ifdef SQLITE_TEST /* For testing and debugging use only */
8151082552
/* Record in the query plan information about the current table
8151182553
** and the index used to access it (if any). If the table itself
@@ -81520,34 +82562,34 @@
8152082562
pTabItem = &pTabList->a[pLevel->iFrom];
8152182563
z = pTabItem->zAlias;
8152282564
if( z==0 ) z = pTabItem->pTab->zName;
8152382565
n = sqlite3Strlen30(z);
8152482566
if( n+nQPlan < sizeof(sqlite3_query_plan)-10 ){
81525
- if( pLevel->wsFlags & WHERE_IDX_ONLY ){
82567
+ if( pLevel->plan.wsFlags & WHERE_IDX_ONLY ){
8152682568
memcpy(&sqlite3_query_plan[nQPlan], "{}", 2);
8152782569
nQPlan += 2;
8152882570
}else{
8152982571
memcpy(&sqlite3_query_plan[nQPlan], z, n);
8153082572
nQPlan += n;
8153182573
}
8153282574
sqlite3_query_plan[nQPlan++] = ' ';
8153382575
}
81534
- testcase( pLevel->wsFlags & WHERE_ROWID_EQ );
81535
- testcase( pLevel->wsFlags & WHERE_ROWID_RANGE );
81536
- if( pLevel->wsFlags & (WHERE_ROWID_EQ|WHERE_ROWID_RANGE) ){
82576
+ testcase( pLevel->plan.wsFlags & WHERE_ROWID_EQ );
82577
+ testcase( pLevel->plan.wsFlags & WHERE_ROWID_RANGE );
82578
+ if( pLevel->plan.wsFlags & (WHERE_ROWID_EQ|WHERE_ROWID_RANGE) ){
8153782579
memcpy(&sqlite3_query_plan[nQPlan], "* ", 2);
8153882580
nQPlan += 2;
81539
- }else if( pLevel->pIdx==0 ){
81540
- memcpy(&sqlite3_query_plan[nQPlan], "{} ", 3);
81541
- nQPlan += 3;
81542
- }else{
81543
- n = sqlite3Strlen30(pLevel->pIdx->zName);
82581
+ }else if( (pLevel->plan.wsFlags & WHERE_INDEXED)!=0 ){
82582
+ n = sqlite3Strlen30(pLevel->plan.u.pIdx->zName);
8154482583
if( n+nQPlan < sizeof(sqlite3_query_plan)-2 ){
81545
- memcpy(&sqlite3_query_plan[nQPlan], pLevel->pIdx->zName, n);
82584
+ memcpy(&sqlite3_query_plan[nQPlan], pLevel->plan.u.pIdx->zName, n);
8154682585
nQPlan += n;
8154782586
sqlite3_query_plan[nQPlan++] = ' ';
8154882587
}
82588
+ }else{
82589
+ memcpy(&sqlite3_query_plan[nQPlan], "{} ", 3);
82590
+ nQPlan += 3;
8154982591
}
8155082592
}
8155182593
while( nQPlan>0 && sqlite3_query_plan[nQPlan-1]==' ' ){
8155282594
sqlite3_query_plan[--nQPlan] = 0;
8155382595
}
@@ -81556,17 +82598,14 @@
8155682598
#endif /* SQLITE_TEST // Testing and debugging use only */
8155782599
8155882600
/* Record the continuation address in the WhereInfo structure. Then
8155982601
** clean up and return.
8156082602
*/
81561
- pWInfo->iContinue = addrCont;
81562
- whereClauseClear(&wc);
8156382603
return pWInfo;
8156482604
8156582605
/* Jump here if malloc fails */
8156682606
whereBeginError:
81567
- whereClauseClear(&wc);
8156882607
whereInfoFree(db, pWInfo);
8156982608
return 0;
8157082609
}
8157182610
8157282611
/*
@@ -81589,20 +82628,20 @@
8158982628
sqlite3VdbeResolveLabel(v, pLevel->addrCont);
8159082629
if( pLevel->op!=OP_Noop ){
8159182630
sqlite3VdbeAddOp2(v, pLevel->op, pLevel->p1, pLevel->p2);
8159282631
sqlite3VdbeChangeP5(v, pLevel->p5);
8159382632
}
81594
- if( pLevel->nIn ){
82633
+ if( pLevel->plan.wsFlags & WHERE_IN_ABLE && pLevel->u.in.nIn>0 ){
8159582634
struct InLoop *pIn;
8159682635
int j;
8159782636
sqlite3VdbeResolveLabel(v, pLevel->addrNxt);
81598
- for(j=pLevel->nIn, pIn=&pLevel->aInLoop[j-1]; j>0; j--, pIn--){
82637
+ for(j=pLevel->u.in.nIn, pIn=&pLevel->u.in.aInLoop[j-1]; j>0; j--, pIn--){
8159982638
sqlite3VdbeJumpHere(v, pIn->addrInTop+1);
8160082639
sqlite3VdbeAddOp2(v, OP_Next, pIn->iCur, pIn->addrInTop);
8160182640
sqlite3VdbeJumpHere(v, pIn->addrInTop-1);
8160282641
}
81603
- sqlite3DbFree(db, pLevel->aInLoop);
82642
+ sqlite3DbFree(db, pLevel->u.in.aInLoop);
8160482643
}
8160582644
sqlite3VdbeResolveLabel(v, pLevel->addrBrk);
8160682645
if( pLevel->iLeftJoin ){
8160782646
int addr;
8160882647
addr = sqlite3VdbeAddOp1(v, OP_IfPos, pLevel->iLeftJoin);
@@ -81625,15 +82664,17 @@
8162582664
for(i=0, pLevel=pWInfo->a; i<pTabList->nSrc; i++, pLevel++){
8162682665
struct SrcList_item *pTabItem = &pTabList->a[pLevel->iFrom];
8162782666
Table *pTab = pTabItem->pTab;
8162882667
assert( pTab!=0 );
8162982668
if( (pTab->tabFlags & TF_Ephemeral)!=0 || pTab->pSelect ) continue;
81630
- if( !pWInfo->okOnePass && (pLevel->wsFlags & WHERE_IDX_ONLY)==0 ){
81631
- sqlite3VdbeAddOp1(v, OP_Close, pTabItem->iCursor);
81632
- }
81633
- if( pLevel->pIdx!=0 ){
81634
- sqlite3VdbeAddOp1(v, OP_Close, pLevel->iIdxCur);
82669
+ if( (pWInfo->wctrlFlags & WHERE_OMIT_CLOSE)==0 ){
82670
+ if( !pWInfo->okOnePass && (pLevel->plan.wsFlags & WHERE_IDX_ONLY)==0 ){
82671
+ sqlite3VdbeAddOp1(v, OP_Close, pTabItem->iCursor);
82672
+ }
82673
+ if( (pLevel->plan.wsFlags & WHERE_INDEXED)!=0 ){
82674
+ sqlite3VdbeAddOp1(v, OP_Close, pLevel->iIdxCur);
82675
+ }
8163582676
}
8163682677
8163782678
/* If this scan uses an index, make code substitutions to read data
8163882679
** from the index in preference to the table. Sometimes, this means
8163982680
** the table need never be read from. This is a performance boost,
@@ -81645,15 +82686,15 @@
8164582686
** sqlite3WhereEnd will have created code that references the table
8164682687
** directly. This loop scans all that code looking for opcodes
8164782688
** that reference the table and converts them into opcodes that
8164882689
** reference the index.
8164982690
*/
81650
- if( pLevel->pIdx ){
82691
+ if( (pLevel->plan.wsFlags & WHERE_INDEXED)!=0 ){
8165182692
int k, j, last;
8165282693
VdbeOp *pOp;
81653
- Index *pIdx = pLevel->pIdx;
81654
- int useIndexOnly = pLevel->wsFlags & WHERE_IDX_ONLY;
82694
+ Index *pIdx = pLevel->plan.u.pIdx;
82695
+ int useIndexOnly = pLevel->plan.wsFlags & WHERE_IDX_ONLY;
8165582696
8165682697
assert( pIdx!=0 );
8165782698
pOp = sqlite3VdbeGetOp(v, pWInfo->iTop);
8165882699
last = sqlite3VdbeCurrentAddr(v);
8165982700
for(k=pWInfo->iTop; k<last; k++, pOp++){
@@ -81774,38 +82815,38 @@
8177482815
** YYNRULE the number of rules in the grammar
8177582816
** YYERRORSYMBOL is the code number of the error symbol. If not
8177682817
** defined, then do no error processing.
8177782818
*/
8177882819
#define YYCODETYPE unsigned char
81779
-#define YYNOCODE 248
82820
+#define YYNOCODE 251
8178082821
#define YYACTIONTYPE unsigned short int
81781
-#define YYWILDCARD 59
82822
+#define YYWILDCARD 62
8178282823
#define sqlite3ParserTOKENTYPE Token
8178382824
typedef union {
8178482825
int yyinit;
8178582826
sqlite3ParserTOKENTYPE yy0;
81786
- int yy46;
81787
- struct LikeOp yy72;
81788
- Expr* yy172;
81789
- ExprList* yy174;
81790
- Select* yy219;
81791
- struct LimitVal yy234;
81792
- TriggerStep* yy243;
81793
- struct TrigEvent yy370;
81794
- SrcList* yy373;
81795
- struct {int value; int mask;} yy405;
81796
- IdList* yy432;
82827
+ struct LimitVal yy64;
82828
+ Expr* yy122;
82829
+ Select* yy159;
82830
+ IdList* yy180;
82831
+ struct {int value; int mask;} yy207;
82832
+ struct LikeOp yy318;
82833
+ TriggerStep* yy327;
82834
+ SrcList* yy347;
82835
+ int yy392;
82836
+ struct TrigEvent yy410;
82837
+ ExprList* yy442;
8179782838
} YYMINORTYPE;
8179882839
#ifndef YYSTACKDEPTH
8179982840
#define YYSTACKDEPTH 100
8180082841
#endif
8180182842
#define sqlite3ParserARG_SDECL Parse *pParse;
8180282843
#define sqlite3ParserARG_PDECL ,Parse *pParse
8180382844
#define sqlite3ParserARG_FETCH Parse *pParse = yypParser->pParse
8180482845
#define sqlite3ParserARG_STORE yypParser->pParse = pParse
81805
-#define YYNSTATE 601
81806
-#define YYNRULE 314
82846
+#define YYNSTATE 610
82847
+#define YYNRULE 319
8180782848
#define YYFALLBACK 1
8180882849
#define YY_NO_ACTION (YYNSTATE+YYNRULE+2)
8180982850
#define YY_ACCEPT_ACTION (YYNSTATE+YYNRULE+1)
8181082851
#define YY_ERROR_ACTION (YYNSTATE+YYNRULE)
8181182852
@@ -81860,427 +82901,431 @@
8186082901
** yy_reduce_ofst[] For each state, the offset into yy_action for
8186182902
** shifting non-terminals after a reduce.
8186282903
** yy_default[] Default action for each state.
8186382904
*/
8186482905
static const YYACTIONTYPE yy_action[] = {
81865
- /* 0 */ 299, 916, 120, 600, 2, 175, 427, 427, 62, 62,
81866
- /* 10 */ 62, 62, 487, 64, 64, 64, 64, 65, 65, 66,
81867
- /* 20 */ 66, 66, 67, 213, 400, 397, 434, 440, 69, 64,
81868
- /* 30 */ 64, 64, 64, 65, 65, 66, 66, 66, 67, 213,
81869
- /* 40 */ 460, 458, 330, 171, 61, 60, 304, 444, 445, 441,
81870
- /* 50 */ 441, 63, 63, 62, 62, 62, 62, 259, 64, 64,
81871
- /* 60 */ 64, 64, 65, 65, 66, 66, 66, 67, 213, 299,
81872
- /* 70 */ 501, 427, 427, 306, 429, 83, 68, 471, 70, 155,
81873
- /* 80 */ 64, 64, 64, 64, 65, 65, 66, 66, 66, 67,
81874
- /* 90 */ 213, 68, 310, 70, 155, 434, 440, 456, 215, 59,
81875
- /* 100 */ 65, 65, 66, 66, 66, 67, 213, 431, 431, 431,
81876
- /* 110 */ 211, 586, 299, 61, 60, 304, 444, 445, 441, 441,
81877
- /* 120 */ 63, 63, 62, 62, 62, 62, 324, 64, 64, 64,
81878
- /* 130 */ 64, 65, 65, 66, 66, 66, 67, 213, 434, 440,
81879
- /* 140 */ 95, 320, 402, 483, 598, 907, 210, 907, 423, 35,
81880
- /* 150 */ 57, 67, 213, 203, 419, 271, 61, 60, 304, 444,
81881
- /* 160 */ 445, 441, 441, 63, 63, 62, 62, 62, 62, 213,
81882
- /* 170 */ 64, 64, 64, 64, 65, 65, 66, 66, 66, 67,
81883
- /* 180 */ 213, 299, 492, 535, 595, 584, 109, 424, 465, 460,
81884
- /* 190 */ 338, 500, 416, 20, 522, 348, 272, 405, 324, 68,
81885
- /* 200 */ 466, 70, 155, 583, 582, 542, 517, 434, 440, 150,
81886
- /* 210 */ 151, 388, 541, 467, 523, 334, 152, 544, 271, 501,
81887
- /* 220 */ 423, 42, 502, 429, 299, 61, 60, 304, 444, 445,
81888
- /* 230 */ 441, 441, 63, 63, 62, 62, 62, 62, 396, 64,
81889
- /* 240 */ 64, 64, 64, 65, 65, 66, 66, 66, 67, 213,
81890
- /* 250 */ 434, 440, 456, 601, 400, 397, 431, 431, 431, 569,
81891
- /* 260 */ 561, 217, 406, 407, 579, 214, 309, 299, 61, 60,
81892
- /* 270 */ 304, 444, 445, 441, 441, 63, 63, 62, 62, 62,
81893
- /* 280 */ 62, 324, 64, 64, 64, 64, 65, 65, 66, 66,
81894
- /* 290 */ 66, 67, 213, 434, 440, 405, 543, 307, 560, 505,
81895
- /* 300 */ 506, 560, 536, 423, 36, 195, 66, 66, 66, 67,
81896
- /* 310 */ 213, 61, 60, 304, 444, 445, 441, 441, 63, 63,
81897
- /* 320 */ 62, 62, 62, 62, 183, 64, 64, 64, 64, 65,
81898
- /* 330 */ 65, 66, 66, 66, 67, 213, 417, 533, 584, 424,
81899
- /* 340 */ 78, 271, 299, 259, 307, 530, 496, 236, 381, 277,
81900
- /* 350 */ 276, 381, 277, 276, 553, 242, 583, 153, 552, 211,
81901
- /* 360 */ 406, 407, 211, 379, 68, 225, 70, 155, 434, 440,
81902
- /* 370 */ 370, 167, 114, 251, 351, 256, 352, 178, 226, 175,
81903
- /* 380 */ 17, 427, 393, 81, 260, 382, 61, 60, 304, 444,
81904
- /* 390 */ 445, 441, 441, 63, 63, 62, 62, 62, 62, 514,
81905
- /* 400 */ 64, 64, 64, 64, 65, 65, 66, 66, 66, 67,
81906
- /* 410 */ 213, 299, 225, 558, 506, 499, 405, 391, 214, 114,
81907
- /* 420 */ 251, 351, 256, 352, 178, 184, 324, 418, 353, 356,
81908
- /* 430 */ 357, 260, 395, 378, 156, 530, 405, 434, 440, 358,
81909
- /* 440 */ 184, 535, 243, 353, 356, 357, 427, 235, 423, 35,
81910
- /* 450 */ 545, 20, 399, 2, 358, 61, 60, 304, 444, 445,
81911
- /* 460 */ 441, 441, 63, 63, 62, 62, 62, 62, 424, 64,
81912
- /* 470 */ 64, 64, 64, 65, 65, 66, 66, 66, 67, 213,
81913
- /* 480 */ 299, 406, 407, 184, 516, 503, 353, 356, 357, 204,
81914
- /* 490 */ 338, 456, 215, 324, 420, 337, 422, 358, 227, 324,
81915
- /* 500 */ 421, 406, 407, 195, 535, 335, 434, 440, 305, 451,
81916
- /* 510 */ 452, 580, 581, 591, 20, 423, 42, 329, 451, 452,
81917
- /* 520 */ 162, 423, 35, 424, 61, 60, 304, 444, 445, 441,
81918
- /* 530 */ 441, 63, 63, 62, 62, 62, 62, 424, 64, 64,
81919
- /* 540 */ 64, 64, 65, 65, 66, 66, 66, 67, 213, 299,
81920
- /* 550 */ 324, 495, 465, 263, 424, 340, 218, 160, 154, 324,
81921
- /* 560 */ 343, 379, 448, 342, 466, 324, 163, 161, 461, 435,
81922
- /* 570 */ 436, 214, 423, 28, 21, 434, 440, 467, 427, 507,
81923
- /* 580 */ 214, 423, 50, 375, 408, 409, 410, 423, 50, 508,
81924
- /* 590 */ 438, 439, 424, 61, 60, 304, 444, 445, 441, 441,
81925
- /* 600 */ 63, 63, 62, 62, 62, 62, 347, 64, 64, 64,
81926
- /* 610 */ 64, 65, 65, 66, 66, 66, 67, 213, 299, 437,
81927
- /* 620 */ 281, 294, 555, 94, 458, 534, 171, 315, 423, 3,
81928
- /* 630 */ 1, 594, 298, 316, 405, 598, 906, 327, 906, 447,
81929
- /* 640 */ 447, 244, 212, 427, 434, 440, 123, 477, 327, 56,
81930
- /* 650 */ 447, 447, 174, 161, 327, 325, 447, 447, 284, 383,
81931
- /* 660 */ 282, 299, 61, 60, 304, 444, 445, 441, 441, 63,
81932
- /* 670 */ 63, 62, 62, 62, 62, 595, 64, 64, 64, 64,
81933
- /* 680 */ 65, 65, 66, 66, 66, 67, 213, 434, 440, 551,
81934
- /* 690 */ 368, 551, 124, 327, 478, 447, 447, 483, 557, 406,
81935
- /* 700 */ 407, 265, 302, 483, 299, 61, 60, 304, 444, 445,
81936
- /* 710 */ 441, 441, 63, 63, 62, 62, 62, 62, 405, 64,
81937
- /* 720 */ 64, 64, 64, 65, 65, 66, 66, 66, 67, 213,
81938
- /* 730 */ 434, 440, 327, 404, 447, 447, 219, 271, 839, 269,
81939
- /* 740 */ 283, 267, 247, 180, 181, 182, 483, 299, 61, 71,
81940
- /* 750 */ 304, 444, 445, 441, 441, 63, 63, 62, 62, 62,
81941
- /* 760 */ 62, 159, 64, 64, 64, 64, 65, 65, 66, 66,
81942
- /* 770 */ 66, 67, 213, 434, 440, 494, 371, 211, 571, 231,
81943
- /* 780 */ 271, 374, 346, 406, 407, 249, 478, 259, 271, 259,
81944
- /* 790 */ 299, 380, 60, 304, 444, 445, 441, 441, 63, 63,
81945
- /* 800 */ 62, 62, 62, 62, 349, 64, 64, 64, 64, 65,
81946
- /* 810 */ 65, 66, 66, 66, 67, 213, 434, 440, 405, 23,
81947
- /* 820 */ 405, 572, 311, 405, 312, 115, 487, 271, 259, 573,
81948
- /* 830 */ 5, 422, 19, 478, 145, 421, 304, 444, 445, 441,
81949
- /* 840 */ 441, 63, 63, 62, 62, 62, 62, 324, 64, 64,
81950
- /* 850 */ 64, 64, 65, 65, 66, 66, 66, 67, 213, 73,
81951
- /* 860 */ 331, 430, 4, 313, 271, 457, 303, 271, 228, 423,
81952
- /* 870 */ 29, 324, 361, 324, 328, 73, 331, 77, 4, 79,
81953
- /* 880 */ 324, 345, 303, 406, 407, 406, 407, 369, 406, 407,
81954
- /* 890 */ 328, 333, 336, 423, 24, 423, 33, 324, 378, 179,
81955
- /* 900 */ 159, 460, 423, 54, 324, 229, 324, 333, 287, 479,
81956
- /* 910 */ 179, 480, 476, 487, 168, 318, 119, 460, 324, 423,
81957
- /* 920 */ 53, 76, 75, 469, 199, 478, 423, 99, 423, 97,
81958
- /* 930 */ 74, 322, 323, 454, 454, 429, 473, 76, 75, 493,
81959
- /* 940 */ 423, 102, 390, 474, 324, 365, 74, 322, 323, 73,
81960
- /* 950 */ 331, 429, 4, 211, 301, 324, 303, 324, 424, 260,
81961
- /* 960 */ 324, 211, 157, 230, 328, 301, 423, 103, 431, 431,
81962
- /* 970 */ 431, 432, 433, 11, 314, 389, 186, 423, 108, 423,
81963
- /* 980 */ 110, 333, 423, 16, 431, 431, 431, 432, 433, 11,
81964
- /* 990 */ 326, 460, 189, 165, 197, 324, 424, 596, 232, 233,
81965
- /* 1000 */ 234, 105, 449, 148, 22, 324, 482, 635, 324, 486,
81966
- /* 1010 */ 424, 76, 75, 485, 208, 176, 289, 423, 100, 488,
81967
- /* 1020 */ 74, 322, 323, 290, 324, 429, 424, 423, 34, 324,
81968
- /* 1030 */ 423, 98, 324, 18, 324, 206, 597, 560, 511, 512,
81969
- /* 1040 */ 257, 205, 324, 519, 207, 324, 423, 25, 324, 518,
81970
- /* 1050 */ 324, 423, 55, 324, 423, 111, 423, 112, 431, 431,
81971
- /* 1060 */ 431, 432, 433, 11, 423, 113, 442, 423, 26, 324,
81972
- /* 1070 */ 423, 37, 423, 38, 258, 423, 27, 324, 524, 324,
81973
- /* 1080 */ 521, 520, 8, 526, 324, 183, 324, 386, 286, 276,
81974
- /* 1090 */ 324, 423, 39, 300, 85, 324, 525, 324, 211, 423,
81975
- /* 1100 */ 40, 423, 41, 324, 537, 324, 423, 43, 423, 44,
81976
- /* 1110 */ 264, 252, 423, 45, 262, 324, 183, 423, 30, 423,
81977
- /* 1120 */ 31, 324, 253, 392, 266, 423, 46, 423, 47, 324,
81978
- /* 1130 */ 360, 324, 183, 324, 556, 324, 183, 423, 48, 564,
81979
- /* 1140 */ 565, 176, 92, 423, 49, 268, 576, 593, 92, 297,
81980
- /* 1150 */ 270, 423, 32, 423, 10, 423, 51, 423, 52, 192,
81981
- /* 1160 */ 275, 373, 147, 376, 377, 278, 279, 428, 280, 568,
81982
- /* 1170 */ 578, 288, 291, 292, 590, 453, 332, 414, 237, 455,
81983
- /* 1180 */ 472, 475, 254, 245, 517, 355, 563, 166, 403, 575,
81984
- /* 1190 */ 411, 528, 412, 413, 531, 285, 7, 387, 85, 321,
81985
- /* 1200 */ 425, 527, 341, 529, 84, 339, 58, 173, 80, 216,
81986
- /* 1210 */ 470, 121, 308, 86, 344, 350, 125, 223, 514, 362,
81987
- /* 1220 */ 187, 504, 509, 546, 255, 222, 515, 513, 238, 224,
81988
- /* 1230 */ 239, 510, 240, 538, 241, 295, 426, 539, 540, 532,
81989
- /* 1240 */ 188, 190, 296, 364, 246, 191, 484, 490, 248, 548,
81990
- /* 1250 */ 366, 193, 117, 250, 89, 491, 372, 559, 196, 133,
81991
- /* 1260 */ 384, 385, 134, 135, 566, 317, 136, 137, 587, 588,
81992
- /* 1270 */ 592, 139, 401, 101, 221, 574, 104, 143, 589, 142,
81993
- /* 1280 */ 415, 636, 637, 169, 446, 170, 443, 72, 144, 273,
81994
- /* 1290 */ 450, 549, 459, 462, 158, 172, 463, 464, 468, 6,
81995
- /* 1300 */ 13, 82, 12, 481, 122, 164, 177, 497, 93, 498,
81996
- /* 1310 */ 489, 220, 87, 116, 126, 185, 261, 127, 96, 88,
81997
- /* 1320 */ 128, 253, 107, 363, 146, 547, 129, 354, 359, 194,
81998
- /* 1330 */ 367, 176, 274, 130, 118, 554, 131, 550, 9, 319,
81999
- /* 1340 */ 562, 132, 90, 198, 14, 200, 567, 202, 201, 570,
82000
- /* 1350 */ 138, 140, 141, 209, 15, 106, 585, 577, 293, 91,
82001
- /* 1360 */ 398, 394, 149, 599,
82906
+ /* 0 */ 304, 930, 120, 609, 1, 178, 214, 436, 62, 62,
82907
+ /* 10 */ 62, 62, 216, 64, 64, 64, 64, 65, 65, 66,
82908
+ /* 20 */ 66, 66, 67, 216, 406, 403, 443, 449, 69, 64,
82909
+ /* 30 */ 64, 64, 64, 65, 65, 66, 66, 66, 67, 216,
82910
+ /* 40 */ 469, 467, 336, 174, 61, 60, 309, 453, 454, 450,
82911
+ /* 50 */ 450, 63, 63, 62, 62, 62, 62, 200, 64, 64,
82912
+ /* 60 */ 64, 64, 65, 65, 66, 66, 66, 67, 216, 304,
82913
+ /* 70 */ 510, 312, 436, 509, 438, 83, 64, 64, 64, 64,
82914
+ /* 80 */ 65, 65, 66, 66, 66, 67, 216, 65, 65, 66,
82915
+ /* 90 */ 66, 66, 67, 216, 511, 443, 449, 325, 408, 59,
82916
+ /* 100 */ 465, 218, 57, 213, 411, 496, 428, 440, 440, 440,
82917
+ /* 110 */ 206, 67, 216, 61, 60, 309, 453, 454, 450, 450,
82918
+ /* 120 */ 63, 63, 62, 62, 62, 62, 552, 64, 64, 64,
82919
+ /* 130 */ 64, 65, 65, 66, 66, 66, 67, 216, 304, 228,
82920
+ /* 140 */ 186, 469, 544, 312, 433, 170, 114, 256, 357, 261,
82921
+ /* 150 */ 358, 181, 425, 20, 426, 542, 153, 85, 265, 465,
82922
+ /* 160 */ 218, 150, 151, 539, 443, 449, 95, 311, 394, 412,
82923
+ /* 170 */ 413, 510, 276, 427, 436, 438, 152, 553, 545, 589,
82924
+ /* 180 */ 590, 539, 61, 60, 309, 453, 454, 450, 450, 63,
82925
+ /* 190 */ 63, 62, 62, 62, 62, 402, 64, 64, 64, 64,
82926
+ /* 200 */ 65, 65, 66, 66, 66, 67, 216, 304, 440, 440,
82927
+ /* 210 */ 440, 228, 109, 411, 399, 523, 593, 330, 114, 256,
82928
+ /* 220 */ 357, 261, 358, 181, 187, 330, 485, 359, 362, 363,
82929
+ /* 230 */ 265, 593, 241, 443, 449, 592, 591, 248, 364, 436,
82930
+ /* 240 */ 432, 35, 492, 66, 66, 66, 67, 216, 432, 42,
82931
+ /* 250 */ 592, 61, 60, 309, 453, 454, 450, 450, 63, 63,
82932
+ /* 260 */ 62, 62, 62, 62, 401, 64, 64, 64, 64, 65,
82933
+ /* 270 */ 65, 66, 66, 66, 67, 216, 304, 570, 412, 413,
82934
+ /* 280 */ 187, 501, 344, 359, 362, 363, 215, 354, 346, 221,
82935
+ /* 290 */ 330, 341, 330, 56, 364, 569, 588, 217, 68, 156,
82936
+ /* 300 */ 70, 155, 443, 449, 68, 187, 70, 155, 359, 362,
82937
+ /* 310 */ 363, 397, 217, 432, 35, 432, 36, 148, 569, 364,
82938
+ /* 320 */ 61, 60, 309, 453, 454, 450, 450, 63, 63, 62,
82939
+ /* 330 */ 62, 62, 62, 433, 64, 64, 64, 64, 65, 65,
82940
+ /* 340 */ 66, 66, 66, 67, 216, 387, 282, 281, 330, 304,
82941
+ /* 350 */ 474, 68, 480, 70, 155, 344, 214, 154, 299, 330,
82942
+ /* 360 */ 343, 467, 543, 174, 384, 475, 257, 247, 387, 282,
82943
+ /* 370 */ 281, 432, 28, 411, 160, 443, 449, 258, 476, 214,
82944
+ /* 380 */ 516, 496, 432, 42, 198, 492, 68, 162, 70, 155,
82945
+ /* 390 */ 517, 433, 78, 61, 60, 309, 453, 454, 450, 450,
82946
+ /* 400 */ 63, 63, 62, 62, 62, 62, 595, 64, 64, 64,
82947
+ /* 410 */ 64, 65, 65, 66, 66, 66, 67, 216, 433, 367,
82948
+ /* 420 */ 349, 433, 304, 220, 222, 544, 505, 330, 465, 330,
82949
+ /* 430 */ 230, 330, 240, 163, 161, 554, 20, 431, 412, 413,
82950
+ /* 440 */ 2, 430, 385, 375, 411, 198, 182, 249, 443, 449,
82951
+ /* 450 */ 432, 35, 432, 50, 432, 50, 310, 460, 461, 17,
82952
+ /* 460 */ 207, 335, 460, 461, 388, 81, 61, 60, 309, 453,
82953
+ /* 470 */ 454, 450, 450, 63, 63, 62, 62, 62, 62, 433,
82954
+ /* 480 */ 64, 64, 64, 64, 65, 65, 66, 66, 66, 67,
82955
+ /* 490 */ 216, 304, 348, 504, 433, 508, 531, 486, 320, 353,
82956
+ /* 500 */ 321, 306, 457, 385, 23, 331, 265, 470, 411, 412,
82957
+ /* 510 */ 413, 444, 445, 551, 526, 307, 532, 443, 449, 217,
82958
+ /* 520 */ 550, 496, 432, 3, 217, 381, 607, 921, 333, 921,
82959
+ /* 530 */ 456, 456, 447, 448, 276, 61, 60, 309, 453, 454,
82960
+ /* 540 */ 450, 450, 63, 63, 62, 62, 62, 62, 410, 64,
82961
+ /* 550 */ 64, 64, 64, 65, 65, 66, 66, 66, 67, 216,
82962
+ /* 560 */ 304, 446, 607, 920, 525, 920, 604, 264, 314, 474,
82963
+ /* 570 */ 411, 123, 411, 412, 413, 124, 277, 487, 234, 333,
82964
+ /* 580 */ 411, 456, 456, 319, 475, 411, 443, 449, 333, 377,
82965
+ /* 590 */ 456, 456, 286, 333, 380, 456, 456, 476, 178, 340,
82966
+ /* 600 */ 436, 420, 604, 315, 61, 60, 309, 453, 454, 450,
82967
+ /* 610 */ 450, 63, 63, 62, 62, 62, 62, 330, 64, 64,
82968
+ /* 620 */ 64, 64, 65, 65, 66, 66, 66, 67, 216, 304,
82969
+ /* 630 */ 289, 5, 287, 268, 466, 412, 413, 412, 413, 396,
82970
+ /* 640 */ 432, 29, 503, 330, 159, 412, 413, 610, 406, 403,
82971
+ /* 650 */ 412, 413, 414, 415, 416, 443, 449, 333, 214, 456,
82972
+ /* 660 */ 456, 488, 276, 489, 21, 436, 432, 24, 436, 487,
82973
+ /* 670 */ 514, 515, 395, 61, 60, 309, 453, 454, 450, 450,
82974
+ /* 680 */ 63, 63, 62, 62, 62, 62, 330, 64, 64, 64,
82975
+ /* 690 */ 64, 65, 65, 66, 66, 66, 67, 216, 304, 560,
82976
+ /* 700 */ 374, 560, 352, 94, 578, 330, 567, 515, 330, 432,
82977
+ /* 710 */ 33, 330, 288, 330, 562, 330, 544, 330, 561, 183,
82978
+ /* 720 */ 184, 185, 603, 303, 443, 449, 600, 20, 432, 54,
82979
+ /* 730 */ 376, 432, 53, 436, 432, 99, 432, 97, 432, 102,
82980
+ /* 740 */ 432, 103, 61, 60, 309, 453, 454, 450, 450, 63,
82981
+ /* 750 */ 63, 62, 62, 62, 62, 330, 64, 64, 64, 64,
82982
+ /* 760 */ 65, 65, 66, 66, 66, 67, 216, 304, 330, 405,
82983
+ /* 770 */ 1, 202, 330, 512, 330, 214, 330, 171, 432, 108,
82984
+ /* 780 */ 330, 421, 429, 330, 487, 342, 330, 384, 19, 386,
82985
+ /* 790 */ 145, 432, 110, 443, 449, 432, 16, 432, 100, 432,
82986
+ /* 800 */ 34, 351, 270, 432, 98, 433, 432, 25, 276, 432,
82987
+ /* 810 */ 55, 61, 60, 309, 453, 454, 450, 450, 63, 63,
82988
+ /* 820 */ 62, 62, 62, 62, 330, 64, 64, 64, 64, 65,
82989
+ /* 830 */ 65, 66, 66, 66, 67, 216, 304, 330, 323, 119,
82990
+ /* 840 */ 274, 330, 272, 330, 355, 330, 422, 432, 111, 330,
82991
+ /* 850 */ 580, 159, 115, 233, 330, 177, 161, 439, 463, 463,
82992
+ /* 860 */ 432, 112, 443, 449, 432, 113, 432, 26, 432, 37,
82993
+ /* 870 */ 649, 431, 432, 38, 492, 430, 487, 432, 27, 264,
82994
+ /* 880 */ 61, 71, 309, 453, 454, 450, 450, 63, 63, 62,
82995
+ /* 890 */ 62, 62, 62, 330, 64, 64, 64, 64, 65, 65,
82996
+ /* 900 */ 66, 66, 66, 67, 216, 304, 330, 264, 264, 528,
82997
+ /* 910 */ 330, 157, 330, 252, 330, 229, 432, 39, 330, 482,
82998
+ /* 920 */ 332, 478, 77, 330, 79, 330, 483, 520, 521, 432,
82999
+ /* 930 */ 40, 443, 449, 432, 41, 432, 43, 432, 44, 492,
83000
+ /* 940 */ 491, 432, 45, 316, 317, 433, 432, 30, 432, 31,
83001
+ /* 950 */ 60, 309, 453, 454, 450, 450, 63, 63, 62, 62,
83002
+ /* 960 */ 62, 62, 330, 64, 64, 64, 64, 65, 65, 66,
83003
+ /* 970 */ 66, 66, 67, 216, 304, 330, 264, 564, 254, 330,
83004
+ /* 980 */ 458, 330, 22, 330, 495, 432, 46, 330, 494, 535,
83005
+ /* 990 */ 179, 186, 330, 267, 330, 186, 451, 497, 432, 47,
83006
+ /* 1000 */ 443, 449, 432, 48, 432, 49, 432, 32, 182, 262,
83007
+ /* 1010 */ 432, 10, 318, 276, 389, 432, 51, 432, 52, 276,
83008
+ /* 1020 */ 309, 453, 454, 450, 450, 63, 63, 62, 62, 62,
83009
+ /* 1030 */ 62, 276, 64, 64, 64, 64, 65, 65, 66, 66,
83010
+ /* 1040 */ 66, 67, 216, 165, 276, 276, 189, 192, 235, 236,
83011
+ /* 1050 */ 237, 168, 239, 566, 105, 581, 18, 530, 529, 73,
83012
+ /* 1060 */ 337, 582, 4, 306, 605, 527, 308, 211, 366, 294,
83013
+ /* 1070 */ 186, 263, 533, 231, 334, 565, 295, 186, 534, 546,
83014
+ /* 1080 */ 433, 433, 573, 574, 179, 92, 232, 292, 209, 269,
83015
+ /* 1090 */ 569, 339, 271, 853, 208, 273, 275, 210, 585, 195,
83016
+ /* 1100 */ 92, 469, 371, 606, 602, 8, 302, 423, 280, 379,
83017
+ /* 1110 */ 382, 383, 147, 242, 283, 437, 462, 284, 285, 577,
83018
+ /* 1120 */ 338, 76, 75, 587, 293, 296, 297, 599, 481, 464,
83019
+ /* 1130 */ 74, 328, 329, 250, 526, 438, 572, 166, 290, 393,
83020
+ /* 1140 */ 392, 291, 281, 409, 537, 584, 305, 484, 259, 540,
83021
+ /* 1150 */ 417, 214, 418, 214, 536, 326, 538, 419, 361, 167,
83022
+ /* 1160 */ 73, 337, 169, 4, 7, 327, 347, 308, 440, 440,
83023
+ /* 1170 */ 440, 441, 442, 11, 85, 334, 398, 84, 434, 345,
83024
+ /* 1180 */ 243, 58, 244, 73, 337, 80, 4, 245, 435, 246,
83025
+ /* 1190 */ 308, 176, 339, 479, 86, 121, 356, 350, 334, 493,
83026
+ /* 1200 */ 251, 253, 469, 499, 255, 513, 500, 518, 313, 519,
83027
+ /* 1210 */ 260, 523, 125, 522, 226, 339, 219, 524, 368, 190,
83028
+ /* 1220 */ 191, 300, 76, 75, 502, 469, 225, 227, 547, 541,
83029
+ /* 1230 */ 548, 74, 328, 329, 301, 555, 438, 549, 370, 193,
83030
+ /* 1240 */ 372, 194, 557, 89, 196, 76, 75, 278, 378, 117,
83031
+ /* 1250 */ 558, 568, 133, 390, 74, 328, 329, 199, 391, 438,
83032
+ /* 1260 */ 322, 134, 135, 136, 575, 143, 583, 596, 139, 440,
83033
+ /* 1270 */ 440, 440, 441, 442, 11, 597, 598, 601, 137, 142,
83034
+ /* 1280 */ 101, 224, 104, 407, 238, 424, 650, 651, 93, 172,
83035
+ /* 1290 */ 96, 173, 440, 440, 440, 441, 442, 11, 452, 455,
83036
+ /* 1300 */ 72, 471, 459, 468, 472, 144, 158, 6, 473, 490,
83037
+ /* 1310 */ 107, 175, 477, 82, 13, 122, 12, 180, 506, 118,
83038
+ /* 1320 */ 498, 164, 507, 324, 223, 87, 126, 116, 266, 127,
83039
+ /* 1330 */ 88, 128, 188, 258, 360, 369, 146, 556, 129, 373,
83040
+ /* 1340 */ 179, 365, 279, 197, 131, 130, 563, 9, 571, 132,
83041
+ /* 1350 */ 559, 201, 14, 576, 203, 204, 205, 579, 140, 138,
83042
+ /* 1360 */ 141, 15, 586, 594, 212, 106, 400, 298, 149, 404,
83043
+ /* 1370 */ 931, 608, 90, 91,
8200283044
};
8200383045
static const YYCODETYPE yy_lookahead[] = {
82004
- /* 0 */ 16, 140, 141, 142, 143, 21, 23, 23, 69, 70,
82005
- /* 10 */ 71, 72, 148, 74, 75, 76, 77, 78, 79, 80,
82006
- /* 20 */ 81, 82, 83, 84, 1, 2, 42, 43, 73, 74,
82007
- /* 30 */ 75, 76, 77, 78, 79, 80, 81, 82, 83, 84,
82008
- /* 40 */ 58, 162, 163, 164, 60, 61, 62, 63, 64, 65,
82009
- /* 50 */ 66, 67, 68, 69, 70, 71, 72, 148, 74, 75,
82010
- /* 60 */ 76, 77, 78, 79, 80, 81, 82, 83, 84, 16,
82011
- /* 70 */ 88, 88, 88, 209, 92, 22, 218, 219, 220, 221,
82012
- /* 80 */ 74, 75, 76, 77, 78, 79, 80, 81, 82, 83,
82013
- /* 90 */ 84, 218, 183, 220, 221, 42, 43, 78, 79, 46,
82014
- /* 100 */ 78, 79, 80, 81, 82, 83, 84, 125, 126, 127,
82015
- /* 110 */ 110, 238, 16, 60, 61, 62, 63, 64, 65, 66,
82016
- /* 120 */ 67, 68, 69, 70, 71, 72, 148, 74, 75, 76,
82017
- /* 130 */ 77, 78, 79, 80, 81, 82, 83, 84, 42, 43,
82018
- /* 140 */ 44, 144, 145, 162, 19, 20, 149, 22, 170, 171,
82019
- /* 150 */ 19, 83, 84, 156, 23, 148, 60, 61, 62, 63,
82020
- /* 160 */ 64, 65, 66, 67, 68, 69, 70, 71, 72, 84,
82021
- /* 170 */ 74, 75, 76, 77, 78, 79, 80, 81, 82, 83,
82022
- /* 180 */ 84, 16, 201, 148, 59, 148, 21, 190, 12, 58,
82023
- /* 190 */ 212, 170, 157, 158, 30, 217, 189, 23, 148, 218,
82024
- /* 200 */ 24, 220, 221, 166, 167, 177, 178, 42, 43, 78,
82025
- /* 210 */ 79, 214, 184, 37, 50, 39, 181, 182, 148, 88,
82026
- /* 220 */ 170, 171, 170, 92, 16, 60, 61, 62, 63, 64,
82027
- /* 230 */ 65, 66, 67, 68, 69, 70, 71, 72, 241, 74,
82028
- /* 240 */ 75, 76, 77, 78, 79, 80, 81, 82, 83, 84,
82029
- /* 250 */ 42, 43, 78, 0, 1, 2, 125, 126, 127, 189,
82030
- /* 260 */ 11, 211, 88, 89, 227, 228, 102, 16, 60, 61,
82031
- /* 270 */ 62, 63, 64, 65, 66, 67, 68, 69, 70, 71,
82032
- /* 280 */ 72, 148, 74, 75, 76, 77, 78, 79, 80, 81,
82033
- /* 290 */ 82, 83, 84, 42, 43, 23, 182, 16, 49, 186,
82034
- /* 300 */ 187, 49, 182, 170, 171, 156, 80, 81, 82, 83,
82035
- /* 310 */ 84, 60, 61, 62, 63, 64, 65, 66, 67, 68,
82036
- /* 320 */ 69, 70, 71, 72, 22, 74, 75, 76, 77, 78,
82037
- /* 330 */ 79, 80, 81, 82, 83, 84, 168, 169, 148, 190,
82038
- /* 340 */ 132, 148, 16, 148, 16, 177, 20, 191, 99, 100,
82039
- /* 350 */ 101, 99, 100, 101, 25, 222, 166, 22, 29, 110,
82040
- /* 360 */ 88, 89, 110, 214, 218, 84, 220, 221, 42, 43,
82041
- /* 370 */ 41, 90, 91, 92, 93, 94, 95, 96, 183, 21,
82042
- /* 380 */ 231, 23, 189, 132, 103, 236, 60, 61, 62, 63,
82043
- /* 390 */ 64, 65, 66, 67, 68, 69, 70, 71, 72, 97,
82044
- /* 400 */ 74, 75, 76, 77, 78, 79, 80, 81, 82, 83,
82045
- /* 410 */ 84, 16, 84, 186, 187, 20, 23, 227, 228, 91,
82046
- /* 420 */ 92, 93, 94, 95, 96, 90, 148, 169, 93, 94,
82047
- /* 430 */ 95, 103, 239, 148, 156, 177, 23, 42, 43, 104,
82048
- /* 440 */ 90, 148, 148, 93, 94, 95, 88, 154, 170, 171,
82049
- /* 450 */ 157, 158, 142, 143, 104, 60, 61, 62, 63, 64,
82050
- /* 460 */ 65, 66, 67, 68, 69, 70, 71, 72, 190, 74,
82051
- /* 470 */ 75, 76, 77, 78, 79, 80, 81, 82, 83, 84,
82052
- /* 480 */ 16, 88, 89, 90, 20, 161, 93, 94, 95, 156,
82053
- /* 490 */ 212, 78, 79, 148, 170, 217, 107, 104, 213, 148,
82054
- /* 500 */ 111, 88, 89, 156, 148, 187, 42, 43, 165, 166,
82055
- /* 510 */ 167, 98, 99, 157, 158, 170, 171, 165, 166, 167,
82056
- /* 520 */ 156, 170, 171, 190, 60, 61, 62, 63, 64, 65,
82057
- /* 530 */ 66, 67, 68, 69, 70, 71, 72, 190, 74, 75,
82058
- /* 540 */ 76, 77, 78, 79, 80, 81, 82, 83, 84, 16,
82059
- /* 550 */ 148, 20, 12, 20, 190, 210, 211, 148, 156, 148,
82060
- /* 560 */ 148, 214, 20, 212, 24, 148, 202, 203, 20, 42,
82061
- /* 570 */ 43, 228, 170, 171, 19, 42, 43, 37, 23, 39,
82062
- /* 580 */ 228, 170, 171, 236, 7, 8, 9, 170, 171, 49,
82063
- /* 590 */ 63, 64, 190, 60, 61, 62, 63, 64, 65, 66,
82064
- /* 600 */ 67, 68, 69, 70, 71, 72, 148, 74, 75, 76,
82065
- /* 610 */ 77, 78, 79, 80, 81, 82, 83, 84, 16, 92,
82066
- /* 620 */ 14, 159, 18, 21, 162, 163, 164, 216, 170, 171,
82067
- /* 630 */ 19, 244, 245, 216, 23, 19, 20, 106, 22, 108,
82068
- /* 640 */ 109, 148, 193, 88, 42, 43, 20, 204, 106, 200,
82069
- /* 650 */ 108, 109, 202, 203, 106, 148, 108, 109, 52, 55,
82070
- /* 660 */ 54, 16, 60, 61, 62, 63, 64, 65, 66, 67,
82071
- /* 670 */ 68, 69, 70, 71, 72, 59, 74, 75, 76, 77,
82072
- /* 680 */ 78, 79, 80, 81, 82, 83, 84, 42, 43, 99,
82073
- /* 690 */ 100, 101, 20, 106, 22, 108, 109, 162, 94, 88,
82074
- /* 700 */ 89, 14, 151, 162, 16, 60, 61, 62, 63, 64,
82075
- /* 710 */ 65, 66, 67, 68, 69, 70, 71, 72, 23, 74,
82076
- /* 720 */ 75, 76, 77, 78, 79, 80, 81, 82, 83, 84,
82077
- /* 730 */ 42, 43, 106, 148, 108, 109, 201, 148, 134, 52,
82078
- /* 740 */ 134, 54, 201, 99, 100, 101, 162, 16, 60, 61,
82079
- /* 750 */ 62, 63, 64, 65, 66, 67, 68, 69, 70, 71,
82080
- /* 760 */ 72, 89, 74, 75, 76, 77, 78, 79, 80, 81,
82081
- /* 770 */ 82, 83, 84, 42, 43, 80, 225, 110, 189, 146,
82082
- /* 780 */ 148, 230, 16, 88, 89, 201, 114, 148, 148, 148,
82083
- /* 790 */ 16, 124, 61, 62, 63, 64, 65, 66, 67, 68,
82084
- /* 800 */ 69, 70, 71, 72, 80, 74, 75, 76, 77, 78,
82085
- /* 810 */ 79, 80, 81, 82, 83, 84, 42, 43, 23, 19,
82086
- /* 820 */ 23, 189, 183, 23, 183, 148, 148, 148, 148, 189,
82087
- /* 830 */ 192, 107, 19, 22, 21, 111, 62, 63, 64, 65,
82088
- /* 840 */ 66, 67, 68, 69, 70, 71, 72, 148, 74, 75,
82089
- /* 850 */ 76, 77, 78, 79, 80, 81, 82, 83, 84, 16,
82090
- /* 860 */ 17, 148, 19, 183, 148, 162, 23, 148, 189, 170,
82091
- /* 870 */ 171, 148, 16, 148, 31, 16, 17, 131, 19, 133,
82092
- /* 880 */ 148, 115, 23, 88, 89, 88, 89, 209, 88, 89,
82093
- /* 890 */ 31, 48, 148, 170, 171, 170, 171, 148, 148, 43,
82094
- /* 900 */ 89, 58, 170, 171, 148, 189, 148, 48, 189, 114,
82095
- /* 910 */ 43, 114, 22, 148, 19, 242, 243, 58, 148, 170,
82096
- /* 920 */ 171, 78, 79, 148, 156, 114, 170, 171, 170, 171,
82097
- /* 930 */ 87, 88, 89, 125, 126, 92, 27, 78, 79, 80,
82098
- /* 940 */ 170, 171, 91, 34, 148, 233, 87, 88, 89, 16,
82099
- /* 950 */ 17, 92, 19, 110, 98, 148, 23, 148, 190, 103,
82100
- /* 960 */ 148, 110, 156, 213, 31, 98, 170, 171, 125, 126,
82101
- /* 970 */ 127, 128, 129, 130, 209, 124, 156, 170, 171, 170,
82102
- /* 980 */ 171, 48, 170, 171, 125, 126, 127, 128, 129, 130,
82103
- /* 990 */ 16, 58, 156, 5, 22, 148, 190, 20, 10, 11,
82104
- /* 1000 */ 12, 13, 20, 113, 22, 148, 148, 112, 148, 148,
82105
- /* 1010 */ 190, 78, 79, 20, 26, 22, 28, 170, 171, 148,
82106
- /* 1020 */ 87, 88, 89, 35, 148, 92, 190, 170, 171, 148,
82107
- /* 1030 */ 170, 171, 148, 19, 148, 47, 59, 49, 7, 8,
82108
- /* 1040 */ 148, 53, 148, 179, 56, 148, 170, 171, 148, 148,
82109
- /* 1050 */ 148, 170, 171, 148, 170, 171, 170, 171, 125, 126,
82110
- /* 1060 */ 127, 128, 129, 130, 170, 171, 92, 170, 171, 148,
82111
- /* 1070 */ 170, 171, 170, 171, 148, 170, 171, 148, 179, 148,
82112
- /* 1080 */ 91, 92, 68, 20, 148, 22, 148, 99, 100, 101,
82113
- /* 1090 */ 148, 170, 171, 105, 122, 148, 179, 148, 110, 170,
82114
- /* 1100 */ 171, 170, 171, 148, 148, 148, 170, 171, 170, 171,
82115
- /* 1110 */ 148, 92, 170, 171, 20, 148, 22, 170, 171, 170,
82116
- /* 1120 */ 171, 148, 103, 135, 148, 170, 171, 170, 171, 148,
82117
- /* 1130 */ 20, 148, 22, 148, 20, 148, 22, 170, 171, 20,
82118
- /* 1140 */ 20, 22, 22, 170, 171, 148, 20, 20, 22, 22,
82119
- /* 1150 */ 148, 170, 171, 170, 171, 170, 171, 170, 171, 232,
82120
- /* 1160 */ 148, 148, 192, 148, 148, 148, 148, 162, 148, 148,
82121
- /* 1170 */ 148, 148, 148, 148, 148, 229, 224, 150, 194, 229,
82122
- /* 1180 */ 173, 173, 173, 205, 178, 174, 195, 6, 147, 195,
82123
- /* 1190 */ 147, 162, 147, 147, 162, 205, 22, 205, 122, 155,
82124
- /* 1200 */ 190, 173, 119, 173, 120, 118, 121, 112, 131, 223,
82125
- /* 1210 */ 153, 153, 40, 98, 117, 98, 19, 84, 97, 15,
82126
- /* 1220 */ 152, 172, 172, 153, 172, 226, 172, 174, 195, 226,
82127
- /* 1230 */ 196, 180, 197, 172, 198, 175, 199, 172, 172, 180,
82128
- /* 1240 */ 152, 152, 175, 153, 206, 153, 207, 207, 206, 153,
82129
- /* 1250 */ 38, 152, 60, 206, 131, 207, 153, 185, 185, 19,
82130
- /* 1260 */ 153, 15, 188, 188, 195, 153, 188, 188, 33, 153,
82131
- /* 1270 */ 138, 185, 1, 160, 176, 195, 176, 215, 153, 215,
82132
- /* 1280 */ 20, 112, 112, 112, 107, 112, 92, 19, 19, 234,
82133
- /* 1290 */ 20, 235, 20, 11, 19, 22, 20, 20, 20, 116,
82134
- /* 1300 */ 116, 22, 22, 114, 19, 112, 116, 20, 237, 20,
82135
- /* 1310 */ 115, 44, 19, 32, 19, 96, 20, 19, 237, 19,
82136
- /* 1320 */ 19, 103, 240, 16, 21, 17, 98, 44, 44, 98,
82137
- /* 1330 */ 36, 22, 134, 45, 243, 45, 19, 51, 5, 246,
82138
- /* 1340 */ 1, 102, 68, 123, 19, 113, 1, 117, 14, 17,
82139
- /* 1350 */ 113, 102, 123, 136, 19, 14, 20, 124, 137, 68,
82140
- /* 1360 */ 3, 57, 19, 4,
83046
+ /* 0 */ 19, 142, 143, 144, 145, 24, 113, 26, 72, 73,
83047
+ /* 10 */ 74, 75, 87, 77, 78, 79, 80, 81, 82, 83,
83048
+ /* 20 */ 84, 85, 86, 87, 1, 2, 45, 46, 76, 77,
83049
+ /* 30 */ 78, 79, 80, 81, 82, 83, 84, 85, 86, 87,
83050
+ /* 40 */ 61, 165, 166, 167, 63, 64, 65, 66, 67, 68,
83051
+ /* 50 */ 69, 70, 71, 72, 73, 74, 75, 25, 77, 78,
83052
+ /* 60 */ 79, 80, 81, 82, 83, 84, 85, 86, 87, 19,
83053
+ /* 70 */ 91, 19, 91, 173, 95, 25, 77, 78, 79, 80,
83054
+ /* 80 */ 81, 82, 83, 84, 85, 86, 87, 81, 82, 83,
83055
+ /* 90 */ 84, 85, 86, 87, 173, 45, 46, 146, 147, 49,
83056
+ /* 100 */ 81, 82, 22, 152, 26, 150, 26, 128, 129, 130,
83057
+ /* 110 */ 159, 86, 87, 63, 64, 65, 66, 67, 68, 69,
83058
+ /* 120 */ 70, 71, 72, 73, 74, 75, 185, 77, 78, 79,
83059
+ /* 130 */ 80, 81, 82, 83, 84, 85, 86, 87, 19, 87,
83060
+ /* 140 */ 25, 61, 150, 19, 193, 93, 94, 95, 96, 97,
83061
+ /* 150 */ 98, 99, 160, 161, 171, 172, 25, 125, 106, 81,
83062
+ /* 160 */ 82, 81, 82, 180, 45, 46, 47, 212, 217, 91,
83063
+ /* 170 */ 92, 91, 150, 172, 26, 95, 184, 185, 185, 101,
83064
+ /* 180 */ 102, 180, 63, 64, 65, 66, 67, 68, 69, 70,
83065
+ /* 190 */ 71, 72, 73, 74, 75, 244, 77, 78, 79, 80,
83066
+ /* 200 */ 81, 82, 83, 84, 85, 86, 87, 19, 128, 129,
83067
+ /* 210 */ 130, 87, 24, 26, 192, 100, 150, 150, 94, 95,
83068
+ /* 220 */ 96, 97, 98, 99, 93, 150, 25, 96, 97, 98,
83069
+ /* 230 */ 106, 150, 194, 45, 46, 169, 170, 150, 107, 91,
83070
+ /* 240 */ 173, 174, 165, 83, 84, 85, 86, 87, 173, 174,
83071
+ /* 250 */ 169, 63, 64, 65, 66, 67, 68, 69, 70, 71,
83072
+ /* 260 */ 72, 73, 74, 75, 242, 77, 78, 79, 80, 81,
83073
+ /* 270 */ 82, 83, 84, 85, 86, 87, 19, 11, 91, 92,
83074
+ /* 280 */ 93, 204, 215, 96, 97, 98, 196, 220, 213, 214,
83075
+ /* 290 */ 150, 190, 150, 203, 107, 52, 230, 231, 221, 159,
83076
+ /* 300 */ 223, 224, 45, 46, 221, 93, 223, 224, 96, 97,
83077
+ /* 310 */ 98, 230, 231, 173, 174, 173, 174, 116, 52, 107,
83078
+ /* 320 */ 63, 64, 65, 66, 67, 68, 69, 70, 71, 72,
83079
+ /* 330 */ 73, 74, 75, 193, 77, 78, 79, 80, 81, 82,
83080
+ /* 340 */ 83, 84, 85, 86, 87, 102, 103, 104, 150, 19,
83081
+ /* 350 */ 12, 221, 222, 223, 224, 215, 113, 159, 162, 150,
83082
+ /* 360 */ 220, 165, 166, 167, 150, 27, 95, 225, 102, 103,
83083
+ /* 370 */ 104, 173, 174, 26, 150, 45, 46, 106, 40, 113,
83084
+ /* 380 */ 42, 150, 173, 174, 159, 165, 221, 159, 223, 224,
83085
+ /* 390 */ 52, 193, 135, 63, 64, 65, 66, 67, 68, 69,
83086
+ /* 400 */ 70, 71, 72, 73, 74, 75, 241, 77, 78, 79,
83087
+ /* 410 */ 80, 81, 82, 83, 84, 85, 86, 87, 193, 19,
83088
+ /* 420 */ 150, 193, 19, 214, 204, 150, 23, 150, 81, 150,
83089
+ /* 430 */ 216, 150, 157, 205, 206, 160, 161, 110, 91, 92,
83090
+ /* 440 */ 22, 114, 217, 212, 26, 159, 46, 150, 45, 46,
83091
+ /* 450 */ 173, 174, 173, 174, 173, 174, 168, 169, 170, 234,
83092
+ /* 460 */ 159, 168, 169, 170, 239, 135, 63, 64, 65, 66,
83093
+ /* 470 */ 67, 68, 69, 70, 71, 72, 73, 74, 75, 193,
83094
+ /* 480 */ 77, 78, 79, 80, 81, 82, 83, 84, 85, 86,
83095
+ /* 490 */ 87, 19, 215, 23, 193, 23, 33, 207, 219, 150,
83096
+ /* 500 */ 219, 101, 23, 217, 22, 150, 106, 23, 26, 91,
83097
+ /* 510 */ 92, 45, 46, 180, 181, 154, 53, 45, 46, 231,
83098
+ /* 520 */ 187, 150, 173, 174, 231, 239, 22, 23, 109, 25,
83099
+ /* 530 */ 111, 112, 66, 67, 150, 63, 64, 65, 66, 67,
83100
+ /* 540 */ 68, 69, 70, 71, 72, 73, 74, 75, 150, 77,
83101
+ /* 550 */ 78, 79, 80, 81, 82, 83, 84, 85, 86, 87,
83102
+ /* 560 */ 19, 95, 22, 23, 23, 25, 62, 150, 105, 12,
83103
+ /* 570 */ 26, 23, 26, 91, 92, 23, 192, 25, 148, 109,
83104
+ /* 580 */ 26, 111, 112, 212, 27, 26, 45, 46, 109, 228,
83105
+ /* 590 */ 111, 112, 17, 109, 233, 111, 112, 40, 24, 42,
83106
+ /* 600 */ 26, 150, 62, 186, 63, 64, 65, 66, 67, 68,
83107
+ /* 610 */ 69, 70, 71, 72, 73, 74, 75, 150, 77, 78,
83108
+ /* 620 */ 79, 80, 81, 82, 83, 84, 85, 86, 87, 19,
83109
+ /* 630 */ 55, 195, 57, 23, 165, 91, 92, 91, 92, 94,
83110
+ /* 640 */ 173, 174, 83, 150, 92, 91, 92, 0, 1, 2,
83111
+ /* 650 */ 91, 92, 7, 8, 9, 45, 46, 109, 113, 111,
83112
+ /* 660 */ 112, 117, 150, 117, 22, 91, 173, 174, 26, 117,
83113
+ /* 670 */ 189, 190, 127, 63, 64, 65, 66, 67, 68, 69,
83114
+ /* 680 */ 70, 71, 72, 73, 74, 75, 150, 77, 78, 79,
83115
+ /* 690 */ 80, 81, 82, 83, 84, 85, 86, 87, 19, 102,
83116
+ /* 700 */ 103, 104, 19, 24, 192, 150, 189, 190, 150, 173,
83117
+ /* 710 */ 174, 150, 137, 150, 28, 150, 150, 150, 32, 102,
83118
+ /* 720 */ 103, 104, 247, 248, 45, 46, 160, 161, 173, 174,
83119
+ /* 730 */ 44, 173, 174, 91, 173, 174, 173, 174, 173, 174,
83120
+ /* 740 */ 173, 174, 63, 64, 65, 66, 67, 68, 69, 70,
83121
+ /* 750 */ 71, 72, 73, 74, 75, 150, 77, 78, 79, 80,
83122
+ /* 760 */ 81, 82, 83, 84, 85, 86, 87, 19, 150, 144,
83123
+ /* 770 */ 145, 159, 150, 164, 150, 113, 150, 22, 173, 174,
83124
+ /* 780 */ 150, 150, 173, 150, 25, 150, 150, 150, 22, 127,
83125
+ /* 790 */ 24, 173, 174, 45, 46, 173, 174, 173, 174, 173,
83126
+ /* 800 */ 174, 118, 17, 173, 174, 193, 173, 174, 150, 173,
83127
+ /* 810 */ 174, 63, 64, 65, 66, 67, 68, 69, 70, 71,
83128
+ /* 820 */ 72, 73, 74, 75, 150, 77, 78, 79, 80, 81,
83129
+ /* 830 */ 82, 83, 84, 85, 86, 87, 19, 150, 245, 246,
83130
+ /* 840 */ 55, 150, 57, 150, 83, 150, 150, 173, 174, 150,
83131
+ /* 850 */ 192, 92, 150, 216, 150, 205, 206, 150, 128, 129,
83132
+ /* 860 */ 173, 174, 45, 46, 173, 174, 173, 174, 173, 174,
83133
+ /* 870 */ 115, 110, 173, 174, 165, 114, 117, 173, 174, 150,
83134
+ /* 880 */ 63, 64, 65, 66, 67, 68, 69, 70, 71, 72,
83135
+ /* 890 */ 73, 74, 75, 150, 77, 78, 79, 80, 81, 82,
83136
+ /* 900 */ 83, 84, 85, 86, 87, 19, 150, 150, 150, 182,
83137
+ /* 910 */ 150, 159, 150, 204, 150, 186, 173, 174, 150, 30,
83138
+ /* 920 */ 19, 150, 134, 150, 136, 150, 37, 7, 8, 173,
83139
+ /* 930 */ 174, 45, 46, 173, 174, 173, 174, 173, 174, 165,
83140
+ /* 940 */ 150, 173, 174, 186, 186, 193, 173, 174, 173, 174,
83141
+ /* 950 */ 64, 65, 66, 67, 68, 69, 70, 71, 72, 73,
83142
+ /* 960 */ 74, 75, 150, 77, 78, 79, 80, 81, 82, 83,
83143
+ /* 970 */ 84, 85, 86, 87, 19, 150, 150, 21, 204, 150,
83144
+ /* 980 */ 23, 150, 25, 150, 150, 173, 174, 150, 23, 23,
83145
+ /* 990 */ 25, 25, 150, 23, 150, 25, 95, 150, 173, 174,
83146
+ /* 1000 */ 45, 46, 173, 174, 173, 174, 173, 174, 46, 150,
83147
+ /* 1010 */ 173, 174, 186, 150, 58, 173, 174, 173, 174, 150,
83148
+ /* 1020 */ 65, 66, 67, 68, 69, 70, 71, 72, 73, 74,
83149
+ /* 1030 */ 75, 150, 77, 78, 79, 80, 81, 82, 83, 84,
83150
+ /* 1040 */ 85, 86, 87, 5, 150, 150, 159, 159, 10, 11,
83151
+ /* 1050 */ 12, 13, 14, 97, 16, 192, 22, 94, 95, 19,
83152
+ /* 1060 */ 20, 192, 22, 101, 23, 150, 26, 29, 23, 31,
83153
+ /* 1070 */ 25, 150, 182, 192, 34, 23, 38, 25, 182, 150,
83154
+ /* 1080 */ 193, 193, 23, 23, 25, 25, 192, 192, 50, 150,
83155
+ /* 1090 */ 52, 51, 150, 137, 56, 150, 150, 59, 23, 235,
83156
+ /* 1100 */ 25, 61, 236, 62, 23, 71, 25, 153, 150, 150,
83157
+ /* 1110 */ 150, 150, 195, 197, 150, 165, 232, 150, 150, 150,
83158
+ /* 1120 */ 227, 81, 82, 150, 150, 150, 150, 150, 176, 232,
83159
+ /* 1130 */ 90, 91, 92, 208, 181, 95, 198, 6, 208, 208,
83160
+ /* 1140 */ 102, 103, 104, 149, 165, 198, 108, 176, 176, 165,
83161
+ /* 1150 */ 149, 113, 149, 113, 176, 149, 176, 13, 177, 151,
83162
+ /* 1160 */ 19, 20, 151, 22, 25, 158, 122, 26, 128, 129,
83163
+ /* 1170 */ 130, 131, 132, 133, 125, 34, 138, 123, 193, 121,
83164
+ /* 1180 */ 198, 124, 199, 19, 20, 134, 22, 200, 202, 201,
83165
+ /* 1190 */ 26, 115, 51, 156, 101, 156, 101, 120, 34, 210,
83166
+ /* 1200 */ 209, 209, 61, 210, 209, 175, 210, 175, 43, 183,
83167
+ /* 1210 */ 175, 100, 22, 177, 87, 51, 226, 175, 18, 155,
83168
+ /* 1220 */ 155, 178, 81, 82, 83, 61, 229, 229, 175, 183,
83169
+ /* 1230 */ 175, 90, 91, 92, 178, 156, 95, 175, 156, 155,
83170
+ /* 1240 */ 41, 156, 156, 134, 155, 81, 82, 237, 156, 63,
83171
+ /* 1250 */ 238, 188, 22, 156, 90, 91, 92, 188, 18, 95,
83172
+ /* 1260 */ 156, 191, 191, 191, 198, 218, 198, 36, 188, 128,
83173
+ /* 1270 */ 129, 130, 131, 132, 133, 156, 156, 140, 191, 218,
83174
+ /* 1280 */ 163, 179, 179, 1, 15, 23, 115, 115, 240, 115,
83175
+ /* 1290 */ 240, 115, 128, 129, 130, 131, 132, 133, 95, 110,
83176
+ /* 1300 */ 22, 11, 23, 23, 23, 22, 22, 119, 23, 117,
83177
+ /* 1310 */ 243, 25, 23, 25, 119, 22, 25, 119, 23, 246,
83178
+ /* 1320 */ 118, 115, 23, 249, 47, 22, 22, 35, 23, 22,
83179
+ /* 1330 */ 22, 22, 99, 106, 47, 19, 24, 20, 101, 39,
83180
+ /* 1340 */ 25, 47, 137, 101, 22, 48, 48, 5, 1, 105,
83181
+ /* 1350 */ 54, 126, 22, 1, 116, 17, 120, 20, 105, 116,
83182
+ /* 1360 */ 126, 22, 127, 23, 15, 17, 60, 139, 22, 3,
83183
+ /* 1370 */ 250, 4, 71, 71,
8214183184
};
82142
-#define YY_SHIFT_USE_DFLT (-62)
82143
-#define YY_SHIFT_MAX 398
83185
+#define YY_SHIFT_USE_DFLT (-108)
83186
+#define YY_SHIFT_MAX 404
8214483187
static const short yy_shift_ofst[] = {
82145
- /* 0 */ 23, 843, 988, -16, 843, 933, 933, 393, 413, 252,
82146
- /* 10 */ 96, 933, 933, 933, 933, 933, -45, 249, 174, 272,
82147
- /* 20 */ -17, 19, 19, 0, 53, 165, 208, 251, 326, 395,
82148
- /* 30 */ 464, 533, 602, 645, 688, 645, 645, 645, 645, 645,
82149
- /* 40 */ 645, 645, 645, 645, 645, 645, 645, 645, 645, 645,
82150
- /* 50 */ 645, 645, 645, 731, 774, 774, 859, 933, 933, 933,
82151
- /* 60 */ 933, 933, 933, 933, 933, 933, 933, 933, 933, 933,
82152
- /* 70 */ 933, 933, 933, 933, 933, 933, 933, 933, 933, 933,
82153
- /* 80 */ 933, 933, 933, 933, 933, 933, 933, 933, 933, 933,
82154
- /* 90 */ 933, 933, 933, 933, 933, 933, 933, -61, -61, 6,
82155
- /* 100 */ 6, 281, 22, 226, 856, 604, 272, 272, 68, -17,
82156
- /* 110 */ 85, -62, -62, -62, 131, 328, 540, 540, 125, 616,
82157
- /* 120 */ 253, 358, 272, 358, 358, 272, 272, 272, 272, 272,
82158
- /* 130 */ 272, 272, 272, 272, 272, 272, 272, 272, 272, 272,
82159
- /* 140 */ 272, 272, 851, 667, 0, 0, 0, -62, -62, -62,
82160
- /* 150 */ -18, -18, 335, 350, 531, 611, 542, 548, 176, 795,
82161
- /* 160 */ 797, 800, 626, 672, 695, 577, 272, 272, 724, 272,
82162
- /* 170 */ 272, 555, 272, 272, 811, 272, 272, 272, 272, 272,
82163
- /* 180 */ 164, 164, 164, 272, 272, 272, 587, 272, 272, 587,
82164
- /* 190 */ 272, 329, 590, 272, 272, 587, 272, 272, 272, 587,
82165
- /* 200 */ 272, 272, 272, 587, 587, 272, 272, 272, 272, 272,
82166
- /* 210 */ 813, 389, 890, -17, 808, 808, 746, 909, 909, 766,
82167
- /* 220 */ 909, 867, 909, -17, 909, -17, 302, 972, 766, 766,
82168
- /* 230 */ 972, 1181, 1181, 1181, 1181, 1174, 0, 1076, 1083, 1084,
82169
- /* 240 */ 1087, 1085, 1077, 1095, 1095, 1115, 1097, 1115, 1097, 1115,
82170
- /* 250 */ 1097, 1117, 1117, 1172, 1117, 1121, 1117, 1197, 1133, 1133,
82171
- /* 260 */ 1172, 1117, 1117, 1117, 1197, 1204, 1095, 1204, 1095, 1204,
82172
- /* 270 */ 1095, 1095, 1212, 1123, 1204, 1095, 1192, 1192, 1240, 1076,
82173
- /* 280 */ 1095, 1246, 1246, 1246, 1246, 1076, 1192, 1240, 1095, 1235,
82174
- /* 290 */ 1235, 1095, 1095, 1132, -62, -62, -62, -62, -62, 527,
82175
- /* 300 */ 606, 644, 687, 895, 974, 982, 993, 1019, 1031, 989,
82176
- /* 310 */ 1063, 1094, 1110, 1114, 1119, 1120, 1126, 1014, 1127, 977,
82177
- /* 320 */ 1271, 1260, 1169, 1170, 1171, 1173, 1194, 1177, 1268, 1270,
82178
- /* 330 */ 1272, 1269, 1282, 1275, 1276, 1273, 1277, 1278, 1279, 1183,
82179
- /* 340 */ 1280, 1184, 1279, 1189, 1285, 1190, 1195, 1193, 1287, 1289,
82180
- /* 350 */ 1281, 1267, 1293, 1283, 1295, 1296, 1298, 1300, 1284, 1301,
82181
- /* 360 */ 1219, 1218, 1307, 1308, 1303, 1228, 1294, 1286, 1288, 1309,
82182
- /* 370 */ 1290, 1198, 1231, 1317, 1333, 1339, 1239, 1274, 1291, 1220,
82183
- /* 380 */ 1325, 1232, 1345, 1334, 1230, 1332, 1237, 1249, 1229, 1335,
82184
- /* 390 */ 1233, 1336, 1341, 1304, 1217, 1221, 1343, 1357, 1359,
83188
+ /* 0 */ 23, 1038, 1040, -19, 1040, 1164, 1164, 187, 78, 243,
83189
+ /* 10 */ 119, 1164, 1164, 1164, 1164, 1164, -48, 266, 347, 554,
83190
+ /* 20 */ 148, 19, 19, -107, 50, 188, 257, 330, 403, 472,
83191
+ /* 30 */ 541, 610, 679, 748, 817, 748, 748, 748, 748, 748,
83192
+ /* 40 */ 748, 748, 748, 748, 748, 748, 748, 748, 748, 748,
83193
+ /* 50 */ 748, 748, 748, 886, 955, 955, 1141, 1164, 1164, 1164,
83194
+ /* 60 */ 1164, 1164, 1164, 1164, 1164, 1164, 1164, 1164, 1164, 1164,
83195
+ /* 70 */ 1164, 1164, 1164, 1164, 1164, 1164, 1164, 1164, 1164, 1164,
83196
+ /* 80 */ 1164, 1164, 1164, 1164, 1164, 1164, 1164, 1164, 1164, 1164,
83197
+ /* 90 */ 1164, 1164, 1164, 1164, 1164, 1164, 1164, -64, -64, -1,
83198
+ /* 100 */ -1, 52, 6, 160, 400, 956, 554, 554, 25, 148,
83199
+ /* 110 */ -75, -108, -108, -108, 80, 124, 338, 338, 504, 540,
83200
+ /* 120 */ 647, 574, 554, 574, 574, 554, 554, 554, 554, 554,
83201
+ /* 130 */ 554, 554, 554, 554, 554, 554, 554, 554, 554, 554,
83202
+ /* 140 */ 554, 554, 545, 662, -107, -107, -107, -108, -108, -108,
83203
+ /* 150 */ -21, -21, 131, 212, 470, 418, 479, 484, 557, 544,
83204
+ /* 160 */ 546, 482, 548, 552, 559, 645, 554, 554, 554, 554,
83205
+ /* 170 */ 554, 761, 554, 554, 642, 554, 554, 759, 554, 554,
83206
+ /* 180 */ 554, 554, 554, 463, 463, 463, 554, 554, 554, 419,
83207
+ /* 190 */ 554, 554, 419, 554, 686, 597, 554, 554, 419, 554,
83208
+ /* 200 */ 554, 554, 419, 554, 554, 554, 419, 419, 554, 554,
83209
+ /* 210 */ 554, 554, 554, 766, 327, 201, 148, 730, 730, 788,
83210
+ /* 220 */ 889, 889, 683, 889, 962, 889, 148, 889, 148, 115,
83211
+ /* 230 */ 32, 683, 683, 32, 1131, 1131, 1131, 1131, 1144, 1144,
83212
+ /* 240 */ 1139, -107, 1049, 1044, 1054, 1058, 1057, 1051, 1076, 1076,
83213
+ /* 250 */ 1093, 1077, 1093, 1077, 1093, 1077, 1095, 1095, 1165, 1095,
83214
+ /* 260 */ 1111, 1095, 1190, 1127, 1127, 1165, 1095, 1095, 1095, 1190,
83215
+ /* 270 */ 1200, 1076, 1200, 1076, 1200, 1076, 1076, 1199, 1109, 1200,
83216
+ /* 280 */ 1076, 1186, 1186, 1230, 1049, 1076, 1240, 1240, 1240, 1240,
83217
+ /* 290 */ 1049, 1186, 1230, 1076, 1231, 1231, 1076, 1076, 1137, -108,
83218
+ /* 300 */ -108, -108, -108, -108, 466, 575, 617, 785, 755, 901,
83219
+ /* 310 */ 957, 965, 271, 920, 963, 966, 970, 1045, 1052, 1059,
83220
+ /* 320 */ 1060, 1075, 1034, 1081, 1041, 1282, 1269, 1262, 1171, 1172,
83221
+ /* 330 */ 1174, 1176, 1203, 1189, 1278, 1279, 1280, 1283, 1290, 1284,
83222
+ /* 340 */ 1281, 1286, 1285, 1289, 1288, 1188, 1291, 1195, 1288, 1192,
83223
+ /* 350 */ 1293, 1198, 1202, 1206, 1295, 1299, 1292, 1277, 1303, 1287,
83224
+ /* 360 */ 1304, 1305, 1307, 1308, 1294, 1309, 1233, 1227, 1316, 1317,
83225
+ /* 370 */ 1312, 1237, 1300, 1296, 1297, 1315, 1298, 1205, 1242, 1322,
83226
+ /* 380 */ 1342, 1347, 1244, 1301, 1302, 1225, 1330, 1238, 1352, 1338,
83227
+ /* 390 */ 1236, 1337, 1243, 1253, 1234, 1339, 1235, 1340, 1348, 1306,
83228
+ /* 400 */ 1349, 1228, 1346, 1366, 1367,
8218583229
};
82186
-#define YY_REDUCE_USE_DFLT (-143)
82187
-#define YY_REDUCE_MAX 298
83230
+#define YY_REDUCE_USE_DFLT (-142)
83231
+#define YY_REDUCE_MAX 303
8218883232
static const short yy_reduce_ofst[] = {
82189
- /* 0 */ -139, 278, -3, -19, 402, -22, 345, 35, 37, 149,
82190
- /* 10 */ -127, 133, 50, 351, 411, 417, -142, 347, 190, 293,
82191
- /* 20 */ 462, 343, 352, 364, 146, 146, 146, 146, 146, 146,
82192
- /* 30 */ 146, 146, 146, 146, 146, 146, 146, 146, 146, 146,
82193
- /* 40 */ 146, 146, 146, 146, 146, 146, 146, 146, 146, 146,
82194
- /* 50 */ 146, 146, 146, 146, 146, 146, 458, 699, 723, 725,
82195
- /* 60 */ 732, 749, 756, 758, 770, 796, 807, 809, 812, 847,
82196
- /* 70 */ 857, 860, 876, 881, 884, 886, 894, 897, 900, 902,
82197
- /* 80 */ 905, 921, 929, 931, 936, 938, 942, 947, 949, 955,
82198
- /* 90 */ 957, 967, 973, 981, 983, 985, 987, 146, 146, 146,
82199
- /* 100 */ 146, 168, 146, 146, 28, 551, 193, 356, 146, -121,
82200
- /* 110 */ 146, 146, 146, 146, 324, 258, 113, 227, 387, 387,
82201
- /* 120 */ 310, 535, -136, 541, 584, -91, 195, 639, 641, 7,
82202
- /* 130 */ 678, 680, 285, 765, 70, 589, 632, 640, 679, 716,
82203
- /* 140 */ 750, 719, 333, 768, 806, 820, 836, 449, 450, 673,
82204
- /* 150 */ 21, 52, 114, 120, 156, 294, 156, 156, 318, 409,
82205
- /* 160 */ 412, 493, 156, 443, 507, 633, 585, 677, 638, 507,
82206
- /* 170 */ 713, 703, 744, 775, 443, 858, 861, 871, 892, 901,
82207
- /* 180 */ 864, 899, 917, 926, 956, 962, 156, 976, 997, 156,
82208
- /* 190 */ 1002, 927, 712, 1012, 1013, 156, 1015, 1016, 1017, 156,
82209
- /* 200 */ 1018, 1020, 1021, 156, 156, 1022, 1023, 1024, 1025, 1026,
82210
- /* 210 */ 1027, 970, 984, 1005, 946, 950, 952, 1007, 1008, 978,
82211
- /* 220 */ 1009, 1006, 1028, 1029, 1030, 1032, 1011, 991, 990, 992,
82212
- /* 230 */ 994, 1041, 1043, 1045, 1046, 1044, 1010, 1033, 1034, 1035,
82213
- /* 240 */ 1036, 1037, 986, 1057, 1058, 1038, 1039, 1042, 1040, 1047,
82214
- /* 250 */ 1048, 1049, 1050, 1051, 1052, 1053, 1054, 1060, 999, 1003,
82215
- /* 260 */ 1059, 1061, 1065, 1066, 1067, 1068, 1070, 1088, 1090, 1089,
82216
- /* 270 */ 1092, 1096, 1055, 1056, 1099, 1103, 1072, 1073, 1062, 1069,
82217
- /* 280 */ 1107, 1074, 1075, 1078, 1079, 1080, 1086, 1064, 1112, 1071,
82218
- /* 290 */ 1081, 1116, 1125, 1082, 1113, 1098, 1100, 1091, 1093,
83233
+ /* 0 */ -141, -49, 140, 77, 198, 67, 75, -8, 66, 225,
83234
+ /* 10 */ 165, 142, 209, 277, 279, 281, 130, 286, 81, 275,
83235
+ /* 20 */ 196, 288, 293, 228, 83, 83, 83, 83, 83, 83,
83236
+ /* 30 */ 83, 83, 83, 83, 83, 83, 83, 83, 83, 83,
83237
+ /* 40 */ 83, 83, 83, 83, 83, 83, 83, 83, 83, 83,
83238
+ /* 50 */ 83, 83, 83, 83, 83, 83, 349, 467, 493, 536,
83239
+ /* 60 */ 555, 558, 561, 563, 565, 567, 605, 618, 622, 624,
83240
+ /* 70 */ 626, 630, 633, 636, 674, 687, 691, 693, 695, 699,
83241
+ /* 80 */ 704, 743, 756, 760, 762, 764, 768, 773, 775, 812,
83242
+ /* 90 */ 825, 829, 831, 833, 837, 842, 844, 83, 83, 83,
83243
+ /* 100 */ 83, -17, 83, 83, 333, 361, 22, 566, 83, -124,
83244
+ /* 110 */ 83, 83, 83, 83, 609, 1, 481, 517, 475, 475,
83245
+ /* 120 */ 625, 220, -45, 709, 774, 417, 729, 757, 758, 384,
83246
+ /* 130 */ 231, 826, 214, 371, 512, 658, 863, 869, 881, 894,
83247
+ /* 140 */ 637, 895, 301, 612, 752, 887, 888, 90, 650, 593,
83248
+ /* 150 */ -100, -79, -59, -7, 38, 87, 38, 38, 101, 224,
83249
+ /* 160 */ 270, 297, 38, 290, 355, 430, 398, 451, 631, 696,
83250
+ /* 170 */ 702, 436, 355, 707, 469, 635, 771, 290, 790, 834,
83251
+ /* 180 */ 847, 859, 915, 727, 890, 896, 921, 929, 939, 38,
83252
+ /* 190 */ 942, 945, 38, 946, 864, 866, 958, 959, 38, 960,
83253
+ /* 200 */ 961, 964, 38, 967, 968, 969, 38, 38, 973, 974,
83254
+ /* 210 */ 975, 976, 977, 954, 917, 916, 950, 884, 897, 893,
83255
+ /* 220 */ 952, 971, 925, 972, 953, 978, 979, 980, 984, 981,
83256
+ /* 230 */ 938, 930, 931, 947, 994, 1001, 1003, 1006, 1008, 1011,
83257
+ /* 240 */ 1007, 985, 982, 983, 987, 988, 986, 990, 1037, 1039,
83258
+ /* 250 */ 991, 989, 992, 993, 995, 996, 1030, 1032, 1026, 1035,
83259
+ /* 260 */ 1036, 1042, 1043, 997, 998, 1046, 1053, 1055, 1062, 1056,
83260
+ /* 270 */ 1064, 1079, 1065, 1082, 1084, 1085, 1086, 1010, 1012, 1089,
83261
+ /* 280 */ 1092, 1063, 1069, 1047, 1066, 1097, 1070, 1071, 1072, 1087,
83262
+ /* 290 */ 1068, 1080, 1061, 1104, 1048, 1050, 1119, 1120, 1067, 1117,
83263
+ /* 300 */ 1102, 1103, 1073, 1074,
8221983264
};
8222083265
static const YYACTIONTYPE yy_default[] = {
82221
- /* 0 */ 606, 834, 915, 722, 915, 834, 915, 915, 861, 915,
82222
- /* 10 */ 890, 832, 915, 915, 915, 915, 806, 915, 861, 915,
82223
- /* 20 */ 638, 861, 861, 726, 757, 915, 915, 915, 915, 915,
82224
- /* 30 */ 915, 915, 915, 758, 915, 836, 831, 827, 829, 828,
82225
- /* 40 */ 835, 759, 748, 755, 762, 737, 874, 764, 765, 771,
82226
- /* 50 */ 772, 891, 889, 794, 793, 812, 915, 915, 915, 915,
82227
- /* 60 */ 915, 915, 915, 915, 915, 915, 915, 915, 915, 915,
82228
- /* 70 */ 915, 915, 915, 915, 915, 915, 915, 915, 915, 915,
82229
- /* 80 */ 915, 915, 915, 915, 915, 915, 915, 915, 915, 915,
82230
- /* 90 */ 915, 915, 915, 915, 915, 915, 915, 796, 818, 795,
82231
- /* 100 */ 805, 631, 797, 798, 691, 626, 915, 915, 799, 915,
82232
- /* 110 */ 800, 813, 814, 815, 915, 915, 915, 915, 915, 915,
82233
- /* 120 */ 606, 722, 915, 722, 722, 915, 915, 915, 915, 915,
82234
- /* 130 */ 915, 915, 915, 915, 915, 915, 915, 915, 915, 915,
82235
- /* 140 */ 915, 915, 915, 915, 915, 915, 915, 716, 726, 908,
82236
- /* 150 */ 915, 915, 682, 915, 915, 915, 915, 915, 915, 915,
82237
- /* 160 */ 915, 915, 915, 915, 915, 614, 612, 915, 714, 915,
82238
- /* 170 */ 915, 640, 915, 915, 724, 915, 915, 915, 915, 915,
82239
- /* 180 */ 915, 915, 915, 915, 915, 915, 628, 915, 915, 703,
82240
- /* 190 */ 915, 867, 915, 915, 915, 881, 915, 915, 915, 879,
82241
- /* 200 */ 915, 915, 915, 705, 767, 847, 915, 894, 896, 915,
82242
- /* 210 */ 915, 714, 723, 915, 915, 915, 830, 751, 751, 739,
82243
- /* 220 */ 751, 661, 751, 915, 751, 915, 664, 761, 739, 739,
82244
- /* 230 */ 761, 611, 611, 611, 611, 681, 915, 761, 752, 754,
82245
- /* 240 */ 744, 756, 915, 730, 730, 738, 743, 738, 743, 738,
82246
- /* 250 */ 743, 693, 693, 678, 693, 664, 693, 840, 844, 844,
82247
- /* 260 */ 678, 693, 693, 693, 840, 623, 730, 623, 730, 623,
82248
- /* 270 */ 730, 730, 871, 873, 623, 730, 695, 695, 773, 761,
82249
- /* 280 */ 730, 702, 702, 702, 702, 761, 695, 773, 730, 893,
82250
- /* 290 */ 893, 730, 730, 901, 648, 666, 666, 908, 913, 915,
82251
- /* 300 */ 915, 915, 915, 780, 915, 915, 915, 915, 915, 915,
82252
- /* 310 */ 915, 915, 915, 915, 915, 915, 915, 854, 915, 915,
82253
- /* 320 */ 915, 915, 785, 781, 915, 782, 915, 708, 915, 915,
82254
- /* 330 */ 915, 915, 915, 915, 915, 915, 915, 915, 833, 915,
82255
- /* 340 */ 745, 915, 753, 915, 915, 915, 915, 915, 915, 915,
82256
- /* 350 */ 915, 915, 915, 915, 915, 915, 915, 915, 915, 915,
82257
- /* 360 */ 915, 915, 915, 915, 915, 915, 915, 915, 869, 870,
82258
- /* 370 */ 915, 915, 915, 915, 915, 915, 915, 915, 915, 915,
82259
- /* 380 */ 915, 915, 915, 915, 915, 915, 915, 915, 915, 915,
82260
- /* 390 */ 915, 915, 915, 900, 915, 915, 903, 607, 915, 602,
82261
- /* 400 */ 604, 605, 609, 610, 613, 635, 636, 637, 615, 616,
82262
- /* 410 */ 617, 618, 619, 620, 621, 627, 629, 647, 649, 633,
82263
- /* 420 */ 651, 712, 713, 777, 706, 707, 711, 634, 788, 779,
82264
- /* 430 */ 783, 784, 786, 787, 801, 802, 804, 810, 817, 820,
82265
- /* 440 */ 803, 808, 809, 811, 816, 819, 709, 710, 823, 641,
82266
- /* 450 */ 642, 645, 646, 857, 859, 858, 860, 644, 643, 789,
82267
- /* 460 */ 792, 825, 826, 882, 883, 884, 885, 886, 821, 731,
82268
- /* 470 */ 824, 807, 746, 749, 750, 747, 715, 725, 733, 734,
82269
- /* 480 */ 735, 736, 720, 721, 727, 742, 775, 776, 740, 741,
82270
- /* 490 */ 728, 729, 717, 718, 719, 822, 778, 790, 791, 652,
82271
- /* 500 */ 653, 785, 654, 655, 656, 694, 697, 698, 699, 657,
82272
- /* 510 */ 676, 679, 680, 658, 665, 659, 660, 667, 668, 669,
82273
- /* 520 */ 672, 673, 674, 675, 670, 671, 841, 842, 845, 843,
82274
- /* 530 */ 662, 663, 677, 650, 639, 632, 683, 686, 687, 688,
82275
- /* 540 */ 689, 690, 692, 684, 685, 630, 622, 624, 732, 863,
82276
- /* 550 */ 872, 868, 864, 865, 866, 625, 837, 838, 696, 769,
82277
- /* 560 */ 770, 862, 875, 877, 774, 878, 880, 876, 905, 700,
82278
- /* 570 */ 701, 704, 846, 887, 760, 763, 766, 768, 848, 849,
82279
- /* 580 */ 850, 851, 852, 855, 856, 853, 888, 892, 895, 897,
82280
- /* 590 */ 898, 899, 902, 904, 909, 910, 911, 914, 912, 608,
82281
- /* 600 */ 603,
83266
+ /* 0 */ 615, 929, 848, 736, 929, 848, 929, 929, 875, 929,
83267
+ /* 10 */ 904, 846, 929, 929, 929, 929, 820, 929, 875, 929,
83268
+ /* 20 */ 652, 875, 875, 740, 771, 929, 929, 929, 929, 929,
83269
+ /* 30 */ 929, 929, 929, 772, 929, 850, 845, 841, 843, 842,
83270
+ /* 40 */ 849, 773, 762, 769, 776, 751, 888, 778, 779, 785,
83271
+ /* 50 */ 786, 905, 903, 808, 807, 826, 929, 929, 929, 929,
83272
+ /* 60 */ 929, 929, 929, 929, 929, 929, 929, 929, 929, 929,
83273
+ /* 70 */ 929, 929, 929, 929, 929, 929, 929, 929, 929, 929,
83274
+ /* 80 */ 929, 929, 929, 929, 929, 929, 929, 929, 929, 929,
83275
+ /* 90 */ 929, 929, 929, 929, 929, 929, 929, 810, 832, 809,
83276
+ /* 100 */ 819, 645, 811, 812, 705, 640, 929, 929, 813, 929,
83277
+ /* 110 */ 814, 827, 828, 829, 929, 929, 929, 929, 929, 929,
83278
+ /* 120 */ 615, 736, 929, 736, 736, 929, 929, 929, 929, 929,
83279
+ /* 130 */ 929, 929, 929, 929, 929, 929, 929, 929, 929, 929,
83280
+ /* 140 */ 929, 929, 929, 929, 929, 929, 929, 730, 740, 922,
83281
+ /* 150 */ 929, 929, 696, 929, 929, 929, 929, 929, 929, 929,
83282
+ /* 160 */ 929, 929, 929, 929, 929, 623, 621, 929, 929, 929,
83283
+ /* 170 */ 929, 728, 929, 929, 654, 929, 929, 738, 929, 929,
83284
+ /* 180 */ 929, 929, 929, 929, 929, 929, 929, 929, 929, 642,
83285
+ /* 190 */ 929, 929, 717, 929, 881, 929, 929, 929, 895, 929,
83286
+ /* 200 */ 929, 929, 893, 929, 929, 929, 719, 781, 861, 929,
83287
+ /* 210 */ 908, 910, 929, 929, 728, 737, 929, 929, 929, 844,
83288
+ /* 220 */ 765, 765, 753, 765, 675, 765, 929, 765, 929, 678,
83289
+ /* 230 */ 775, 753, 753, 775, 620, 620, 620, 620, 631, 631,
83290
+ /* 240 */ 695, 929, 775, 766, 768, 758, 770, 929, 744, 744,
83291
+ /* 250 */ 752, 757, 752, 757, 752, 757, 707, 707, 692, 707,
83292
+ /* 260 */ 678, 707, 854, 858, 858, 692, 707, 707, 707, 854,
83293
+ /* 270 */ 637, 744, 637, 744, 637, 744, 744, 885, 887, 637,
83294
+ /* 280 */ 744, 709, 709, 787, 775, 744, 716, 716, 716, 716,
83295
+ /* 290 */ 775, 709, 787, 744, 907, 907, 744, 744, 915, 662,
83296
+ /* 300 */ 680, 680, 922, 927, 929, 929, 929, 929, 794, 929,
83297
+ /* 310 */ 929, 929, 929, 929, 929, 929, 929, 929, 929, 929,
83298
+ /* 320 */ 929, 929, 868, 929, 929, 929, 629, 929, 799, 795,
83299
+ /* 330 */ 929, 796, 929, 722, 929, 929, 929, 929, 929, 929,
83300
+ /* 340 */ 929, 929, 929, 929, 847, 929, 759, 929, 767, 929,
83301
+ /* 350 */ 929, 929, 929, 929, 929, 929, 929, 929, 929, 929,
83302
+ /* 360 */ 929, 929, 929, 929, 929, 929, 929, 929, 929, 929,
83303
+ /* 370 */ 929, 929, 929, 929, 883, 884, 929, 929, 929, 929,
83304
+ /* 380 */ 929, 929, 929, 929, 929, 929, 929, 929, 929, 929,
83305
+ /* 390 */ 929, 929, 929, 929, 929, 929, 929, 929, 929, 914,
83306
+ /* 400 */ 929, 929, 917, 616, 929, 611, 613, 614, 618, 619,
83307
+ /* 410 */ 622, 649, 650, 651, 624, 625, 626, 627, 628, 630,
83308
+ /* 420 */ 634, 632, 633, 635, 641, 643, 661, 663, 647, 665,
83309
+ /* 430 */ 726, 727, 791, 720, 721, 725, 648, 802, 793, 797,
83310
+ /* 440 */ 798, 800, 801, 815, 816, 818, 824, 831, 834, 817,
83311
+ /* 450 */ 822, 823, 825, 830, 833, 723, 724, 837, 655, 656,
83312
+ /* 460 */ 659, 660, 871, 873, 872, 874, 658, 657, 803, 806,
83313
+ /* 470 */ 839, 840, 896, 897, 898, 899, 900, 835, 745, 838,
83314
+ /* 480 */ 821, 760, 763, 764, 761, 729, 739, 747, 748, 749,
83315
+ /* 490 */ 750, 734, 735, 741, 756, 789, 790, 754, 755, 742,
83316
+ /* 500 */ 743, 731, 732, 733, 836, 792, 804, 805, 666, 667,
83317
+ /* 510 */ 799, 668, 669, 670, 708, 711, 712, 713, 671, 690,
83318
+ /* 520 */ 693, 694, 672, 679, 673, 674, 681, 682, 683, 686,
83319
+ /* 530 */ 687, 688, 689, 684, 685, 855, 856, 859, 857, 676,
83320
+ /* 540 */ 677, 691, 664, 653, 646, 697, 700, 701, 702, 703,
83321
+ /* 550 */ 704, 706, 698, 699, 644, 636, 638, 746, 877, 886,
83322
+ /* 560 */ 882, 878, 879, 880, 639, 851, 852, 710, 783, 784,
83323
+ /* 570 */ 876, 889, 891, 788, 892, 894, 890, 919, 714, 715,
83324
+ /* 580 */ 718, 860, 901, 774, 777, 780, 782, 862, 863, 864,
83325
+ /* 590 */ 865, 866, 869, 870, 867, 902, 906, 909, 911, 912,
83326
+ /* 600 */ 913, 916, 918, 923, 924, 925, 928, 926, 617, 612,
8228283327
};
8228383328
#define YY_SZ_ACTTAB (int)(sizeof(yy_action)/sizeof(yy_action[0]))
8228483329
8228583330
/* The next table maps tokens into fallback tokens. If a construct
8228683331
** like the following:
@@ -82294,67 +83339,70 @@
8229483339
*/
8229583340
#ifdef YYFALLBACK
8229683341
static const YYCODETYPE yyFallback[] = {
8229783342
0, /* $ => nothing */
8229883343
0, /* SEMI => nothing */
82299
- 23, /* EXPLAIN => ID */
82300
- 23, /* QUERY => ID */
82301
- 23, /* PLAN => ID */
82302
- 23, /* BEGIN => ID */
83344
+ 26, /* EXPLAIN => ID */
83345
+ 26, /* QUERY => ID */
83346
+ 26, /* PLAN => ID */
83347
+ 26, /* BEGIN => ID */
8230383348
0, /* TRANSACTION => nothing */
82304
- 23, /* DEFERRED => ID */
82305
- 23, /* IMMEDIATE => ID */
82306
- 23, /* EXCLUSIVE => ID */
83349
+ 26, /* DEFERRED => ID */
83350
+ 26, /* IMMEDIATE => ID */
83351
+ 26, /* EXCLUSIVE => ID */
8230783352
0, /* COMMIT => nothing */
82308
- 23, /* END => ID */
83353
+ 26, /* END => ID */
8230983354
0, /* ROLLBACK => nothing */
83355
+ 0, /* SAVEPOINT => nothing */
83356
+ 0, /* RELEASE => nothing */
83357
+ 0, /* TO => nothing */
8231083358
0, /* CREATE => nothing */
8231183359
0, /* TABLE => nothing */
82312
- 23, /* IF => ID */
83360
+ 26, /* IF => ID */
8231383361
0, /* NOT => nothing */
8231483362
0, /* EXISTS => nothing */
82315
- 23, /* TEMP => ID */
83363
+ 26, /* TEMP => ID */
8231683364
0, /* LP => nothing */
8231783365
0, /* RP => nothing */
8231883366
0, /* AS => nothing */
8231983367
0, /* COMMA => nothing */
8232083368
0, /* ID => nothing */
82321
- 23, /* ABORT => ID */
82322
- 23, /* AFTER => ID */
82323
- 23, /* ANALYZE => ID */
82324
- 23, /* ASC => ID */
82325
- 23, /* ATTACH => ID */
82326
- 23, /* BEFORE => ID */
82327
- 23, /* CASCADE => ID */
82328
- 23, /* CAST => ID */
82329
- 23, /* CONFLICT => ID */
82330
- 23, /* DATABASE => ID */
82331
- 23, /* DESC => ID */
82332
- 23, /* DETACH => ID */
82333
- 23, /* EACH => ID */
82334
- 23, /* FAIL => ID */
82335
- 23, /* FOR => ID */
82336
- 23, /* IGNORE => ID */
82337
- 23, /* INITIALLY => ID */
82338
- 23, /* INSTEAD => ID */
82339
- 23, /* LIKE_KW => ID */
82340
- 23, /* MATCH => ID */
82341
- 23, /* KEY => ID */
82342
- 23, /* OF => ID */
82343
- 23, /* OFFSET => ID */
82344
- 23, /* PRAGMA => ID */
82345
- 23, /* RAISE => ID */
82346
- 23, /* REPLACE => ID */
82347
- 23, /* RESTRICT => ID */
82348
- 23, /* ROW => ID */
82349
- 23, /* TRIGGER => ID */
82350
- 23, /* VACUUM => ID */
82351
- 23, /* VIEW => ID */
82352
- 23, /* VIRTUAL => ID */
82353
- 23, /* REINDEX => ID */
82354
- 23, /* RENAME => ID */
82355
- 23, /* CTIME_KW => ID */
83369
+ 26, /* ABORT => ID */
83370
+ 26, /* AFTER => ID */
83371
+ 26, /* ANALYZE => ID */
83372
+ 26, /* ASC => ID */
83373
+ 26, /* ATTACH => ID */
83374
+ 26, /* BEFORE => ID */
83375
+ 26, /* CASCADE => ID */
83376
+ 26, /* CAST => ID */
83377
+ 26, /* CONFLICT => ID */
83378
+ 26, /* DATABASE => ID */
83379
+ 26, /* DESC => ID */
83380
+ 26, /* DETACH => ID */
83381
+ 26, /* EACH => ID */
83382
+ 26, /* FAIL => ID */
83383
+ 26, /* FOR => ID */
83384
+ 26, /* IGNORE => ID */
83385
+ 26, /* INITIALLY => ID */
83386
+ 26, /* INSTEAD => ID */
83387
+ 26, /* LIKE_KW => ID */
83388
+ 26, /* MATCH => ID */
83389
+ 26, /* KEY => ID */
83390
+ 26, /* OF => ID */
83391
+ 26, /* OFFSET => ID */
83392
+ 26, /* PRAGMA => ID */
83393
+ 26, /* RAISE => ID */
83394
+ 26, /* REPLACE => ID */
83395
+ 26, /* RESTRICT => ID */
83396
+ 26, /* ROW => ID */
83397
+ 26, /* TRIGGER => ID */
83398
+ 26, /* VACUUM => ID */
83399
+ 26, /* VIEW => ID */
83400
+ 26, /* VIRTUAL => ID */
83401
+ 26, /* REINDEX => ID */
83402
+ 26, /* RENAME => ID */
83403
+ 26, /* CTIME_KW => ID */
8235683404
0, /* ANY => nothing */
8235783405
0, /* OR => nothing */
8235883406
0, /* AND => nothing */
8235983407
0, /* IS => nothing */
8236083408
0, /* BETWEEN => nothing */
@@ -82428,11 +83476,10 @@
8242883476
0, /* WHEN => nothing */
8242983477
0, /* THEN => nothing */
8243083478
0, /* ELSE => nothing */
8243183479
0, /* INDEX => nothing */
8243283480
0, /* ALTER => nothing */
82433
- 0, /* TO => nothing */
8243483481
0, /* ADD => nothing */
8243583482
0, /* COLUMNKW => nothing */
8243683483
};
8243783484
#endif /* YYFALLBACK */
8243883485
@@ -82511,69 +83558,70 @@
8251183558
** are required. The following table supplies these names */
8251283559
static const char *const yyTokenName[] = {
8251383560
"$", "SEMI", "EXPLAIN", "QUERY",
8251483561
"PLAN", "BEGIN", "TRANSACTION", "DEFERRED",
8251583562
"IMMEDIATE", "EXCLUSIVE", "COMMIT", "END",
82516
- "ROLLBACK", "CREATE", "TABLE", "IF",
82517
- "NOT", "EXISTS", "TEMP", "LP",
82518
- "RP", "AS", "COMMA", "ID",
82519
- "ABORT", "AFTER", "ANALYZE", "ASC",
82520
- "ATTACH", "BEFORE", "CASCADE", "CAST",
82521
- "CONFLICT", "DATABASE", "DESC", "DETACH",
82522
- "EACH", "FAIL", "FOR", "IGNORE",
82523
- "INITIALLY", "INSTEAD", "LIKE_KW", "MATCH",
82524
- "KEY", "OF", "OFFSET", "PRAGMA",
82525
- "RAISE", "REPLACE", "RESTRICT", "ROW",
82526
- "TRIGGER", "VACUUM", "VIEW", "VIRTUAL",
82527
- "REINDEX", "RENAME", "CTIME_KW", "ANY",
82528
- "OR", "AND", "IS", "BETWEEN",
82529
- "IN", "ISNULL", "NOTNULL", "NE",
82530
- "EQ", "GT", "LE", "LT",
82531
- "GE", "ESCAPE", "BITAND", "BITOR",
82532
- "LSHIFT", "RSHIFT", "PLUS", "MINUS",
82533
- "STAR", "SLASH", "REM", "CONCAT",
82534
- "COLLATE", "UMINUS", "UPLUS", "BITNOT",
82535
- "STRING", "JOIN_KW", "CONSTRAINT", "DEFAULT",
82536
- "NULL", "PRIMARY", "UNIQUE", "CHECK",
82537
- "REFERENCES", "AUTOINCR", "ON", "DELETE",
82538
- "UPDATE", "INSERT", "SET", "DEFERRABLE",
82539
- "FOREIGN", "DROP", "UNION", "ALL",
82540
- "EXCEPT", "INTERSECT", "SELECT", "DISTINCT",
82541
- "DOT", "FROM", "JOIN", "INDEXED",
82542
- "BY", "USING", "ORDER", "GROUP",
82543
- "HAVING", "LIMIT", "WHERE", "INTO",
82544
- "VALUES", "INTEGER", "FLOAT", "BLOB",
82545
- "REGISTER", "VARIABLE", "CASE", "WHEN",
82546
- "THEN", "ELSE", "INDEX", "ALTER",
82547
- "TO", "ADD", "COLUMNKW", "error",
82548
- "input", "cmdlist", "ecmd", "explain",
82549
- "cmdx", "cmd", "transtype", "trans_opt",
82550
- "nm", "create_table", "create_table_args", "temp",
82551
- "ifnotexists", "dbnm", "columnlist", "conslist_opt",
82552
- "select", "column", "columnid", "type",
82553
- "carglist", "id", "ids", "typetoken",
82554
- "typename", "signed", "plus_num", "minus_num",
82555
- "carg", "ccons", "term", "expr",
82556
- "onconf", "sortorder", "autoinc", "idxlist_opt",
82557
- "refargs", "defer_subclause", "refarg", "refact",
82558
- "init_deferred_pred_opt", "conslist", "tcons", "idxlist",
82559
- "defer_subclause_opt", "orconf", "resolvetype", "raisetype",
82560
- "ifexists", "fullname", "oneselect", "multiselect_op",
82561
- "distinct", "selcollist", "from", "where_opt",
82562
- "groupby_opt", "having_opt", "orderby_opt", "limit_opt",
82563
- "sclp", "as", "seltablist", "stl_prefix",
82564
- "joinop", "indexed_opt", "on_opt", "using_opt",
82565
- "joinop2", "inscollist", "sortlist", "sortitem",
82566
- "nexprlist", "setlist", "insert_cmd", "inscollist_opt",
82567
- "itemlist", "exprlist", "likeop", "escape",
82568
- "between_op", "in_op", "case_operand", "case_exprlist",
82569
- "case_else", "uniqueflag", "collate", "nmnum",
82570
- "plus_opt", "number", "trigger_decl", "trigger_cmd_list",
82571
- "trigger_time", "trigger_event", "foreach_clause", "when_clause",
82572
- "trigger_cmd", "database_kw_opt", "key_opt", "add_column_fullname",
82573
- "kwcolumn_opt", "create_vtab", "vtabarglist", "vtabarg",
82574
- "vtabargtoken", "lp", "anylist",
83563
+ "ROLLBACK", "SAVEPOINT", "RELEASE", "TO",
83564
+ "CREATE", "TABLE", "IF", "NOT",
83565
+ "EXISTS", "TEMP", "LP", "RP",
83566
+ "AS", "COMMA", "ID", "ABORT",
83567
+ "AFTER", "ANALYZE", "ASC", "ATTACH",
83568
+ "BEFORE", "CASCADE", "CAST", "CONFLICT",
83569
+ "DATABASE", "DESC", "DETACH", "EACH",
83570
+ "FAIL", "FOR", "IGNORE", "INITIALLY",
83571
+ "INSTEAD", "LIKE_KW", "MATCH", "KEY",
83572
+ "OF", "OFFSET", "PRAGMA", "RAISE",
83573
+ "REPLACE", "RESTRICT", "ROW", "TRIGGER",
83574
+ "VACUUM", "VIEW", "VIRTUAL", "REINDEX",
83575
+ "RENAME", "CTIME_KW", "ANY", "OR",
83576
+ "AND", "IS", "BETWEEN", "IN",
83577
+ "ISNULL", "NOTNULL", "NE", "EQ",
83578
+ "GT", "LE", "LT", "GE",
83579
+ "ESCAPE", "BITAND", "BITOR", "LSHIFT",
83580
+ "RSHIFT", "PLUS", "MINUS", "STAR",
83581
+ "SLASH", "REM", "CONCAT", "COLLATE",
83582
+ "UMINUS", "UPLUS", "BITNOT", "STRING",
83583
+ "JOIN_KW", "CONSTRAINT", "DEFAULT", "NULL",
83584
+ "PRIMARY", "UNIQUE", "CHECK", "REFERENCES",
83585
+ "AUTOINCR", "ON", "DELETE", "UPDATE",
83586
+ "INSERT", "SET", "DEFERRABLE", "FOREIGN",
83587
+ "DROP", "UNION", "ALL", "EXCEPT",
83588
+ "INTERSECT", "SELECT", "DISTINCT", "DOT",
83589
+ "FROM", "JOIN", "INDEXED", "BY",
83590
+ "USING", "ORDER", "GROUP", "HAVING",
83591
+ "LIMIT", "WHERE", "INTO", "VALUES",
83592
+ "INTEGER", "FLOAT", "BLOB", "REGISTER",
83593
+ "VARIABLE", "CASE", "WHEN", "THEN",
83594
+ "ELSE", "INDEX", "ALTER", "ADD",
83595
+ "COLUMNKW", "error", "input", "cmdlist",
83596
+ "ecmd", "explain", "cmdx", "cmd",
83597
+ "transtype", "trans_opt", "nm", "savepoint_opt",
83598
+ "create_table", "create_table_args", "temp", "ifnotexists",
83599
+ "dbnm", "columnlist", "conslist_opt", "select",
83600
+ "column", "columnid", "type", "carglist",
83601
+ "id", "ids", "typetoken", "typename",
83602
+ "signed", "plus_num", "minus_num", "carg",
83603
+ "ccons", "term", "expr", "onconf",
83604
+ "sortorder", "autoinc", "idxlist_opt", "refargs",
83605
+ "defer_subclause", "refarg", "refact", "init_deferred_pred_opt",
83606
+ "conslist", "tcons", "idxlist", "defer_subclause_opt",
83607
+ "orconf", "resolvetype", "raisetype", "ifexists",
83608
+ "fullname", "oneselect", "multiselect_op", "distinct",
83609
+ "selcollist", "from", "where_opt", "groupby_opt",
83610
+ "having_opt", "orderby_opt", "limit_opt", "sclp",
83611
+ "as", "seltablist", "stl_prefix", "joinop",
83612
+ "indexed_opt", "on_opt", "using_opt", "joinop2",
83613
+ "inscollist", "sortlist", "sortitem", "nexprlist",
83614
+ "setlist", "insert_cmd", "inscollist_opt", "itemlist",
83615
+ "exprlist", "likeop", "escape", "between_op",
83616
+ "in_op", "case_operand", "case_exprlist", "case_else",
83617
+ "uniqueflag", "collate", "nmnum", "plus_opt",
83618
+ "number", "trigger_decl", "trigger_cmd_list", "trigger_time",
83619
+ "trigger_event", "foreach_clause", "when_clause", "trigger_cmd",
83620
+ "database_kw_opt", "key_opt", "add_column_fullname", "kwcolumn_opt",
83621
+ "create_vtab", "vtabarglist", "vtabarg", "vtabargtoken",
83622
+ "lp", "anylist",
8257583623
};
8257683624
#endif /* NDEBUG */
8257783625
8257883626
#ifndef NDEBUG
8257983627
/* For tracing reduce actions, the names of all rules are required.
@@ -82597,304 +83645,309 @@
8259783645
/* 15 */ "transtype ::= IMMEDIATE",
8259883646
/* 16 */ "transtype ::= EXCLUSIVE",
8259983647
/* 17 */ "cmd ::= COMMIT trans_opt",
8260083648
/* 18 */ "cmd ::= END trans_opt",
8260183649
/* 19 */ "cmd ::= ROLLBACK trans_opt",
82602
- /* 20 */ "cmd ::= create_table create_table_args",
82603
- /* 21 */ "create_table ::= CREATE temp TABLE ifnotexists nm dbnm",
82604
- /* 22 */ "ifnotexists ::=",
82605
- /* 23 */ "ifnotexists ::= IF NOT EXISTS",
82606
- /* 24 */ "temp ::= TEMP",
82607
- /* 25 */ "temp ::=",
82608
- /* 26 */ "create_table_args ::= LP columnlist conslist_opt RP",
82609
- /* 27 */ "create_table_args ::= AS select",
82610
- /* 28 */ "columnlist ::= columnlist COMMA column",
82611
- /* 29 */ "columnlist ::= column",
82612
- /* 30 */ "column ::= columnid type carglist",
82613
- /* 31 */ "columnid ::= nm",
82614
- /* 32 */ "id ::= ID",
82615
- /* 33 */ "ids ::= ID|STRING",
82616
- /* 34 */ "nm ::= ID",
82617
- /* 35 */ "nm ::= STRING",
82618
- /* 36 */ "nm ::= JOIN_KW",
82619
- /* 37 */ "type ::=",
82620
- /* 38 */ "type ::= typetoken",
82621
- /* 39 */ "typetoken ::= typename",
82622
- /* 40 */ "typetoken ::= typename LP signed RP",
82623
- /* 41 */ "typetoken ::= typename LP signed COMMA signed RP",
82624
- /* 42 */ "typename ::= ids",
82625
- /* 43 */ "typename ::= typename ids",
82626
- /* 44 */ "signed ::= plus_num",
82627
- /* 45 */ "signed ::= minus_num",
82628
- /* 46 */ "carglist ::= carglist carg",
82629
- /* 47 */ "carglist ::=",
82630
- /* 48 */ "carg ::= CONSTRAINT nm ccons",
82631
- /* 49 */ "carg ::= ccons",
82632
- /* 50 */ "ccons ::= DEFAULT term",
82633
- /* 51 */ "ccons ::= DEFAULT LP expr RP",
82634
- /* 52 */ "ccons ::= DEFAULT PLUS term",
82635
- /* 53 */ "ccons ::= DEFAULT MINUS term",
82636
- /* 54 */ "ccons ::= DEFAULT id",
82637
- /* 55 */ "ccons ::= NULL onconf",
82638
- /* 56 */ "ccons ::= NOT NULL onconf",
82639
- /* 57 */ "ccons ::= PRIMARY KEY sortorder onconf autoinc",
82640
- /* 58 */ "ccons ::= UNIQUE onconf",
82641
- /* 59 */ "ccons ::= CHECK LP expr RP",
82642
- /* 60 */ "ccons ::= REFERENCES nm idxlist_opt refargs",
82643
- /* 61 */ "ccons ::= defer_subclause",
82644
- /* 62 */ "ccons ::= COLLATE ids",
82645
- /* 63 */ "autoinc ::=",
82646
- /* 64 */ "autoinc ::= AUTOINCR",
82647
- /* 65 */ "refargs ::=",
82648
- /* 66 */ "refargs ::= refargs refarg",
82649
- /* 67 */ "refarg ::= MATCH nm",
82650
- /* 68 */ "refarg ::= ON DELETE refact",
82651
- /* 69 */ "refarg ::= ON UPDATE refact",
82652
- /* 70 */ "refarg ::= ON INSERT refact",
82653
- /* 71 */ "refact ::= SET NULL",
82654
- /* 72 */ "refact ::= SET DEFAULT",
82655
- /* 73 */ "refact ::= CASCADE",
82656
- /* 74 */ "refact ::= RESTRICT",
82657
- /* 75 */ "defer_subclause ::= NOT DEFERRABLE init_deferred_pred_opt",
82658
- /* 76 */ "defer_subclause ::= DEFERRABLE init_deferred_pred_opt",
82659
- /* 77 */ "init_deferred_pred_opt ::=",
82660
- /* 78 */ "init_deferred_pred_opt ::= INITIALLY DEFERRED",
82661
- /* 79 */ "init_deferred_pred_opt ::= INITIALLY IMMEDIATE",
82662
- /* 80 */ "conslist_opt ::=",
82663
- /* 81 */ "conslist_opt ::= COMMA conslist",
82664
- /* 82 */ "conslist ::= conslist COMMA tcons",
82665
- /* 83 */ "conslist ::= conslist tcons",
82666
- /* 84 */ "conslist ::= tcons",
82667
- /* 85 */ "tcons ::= CONSTRAINT nm",
82668
- /* 86 */ "tcons ::= PRIMARY KEY LP idxlist autoinc RP onconf",
82669
- /* 87 */ "tcons ::= UNIQUE LP idxlist RP onconf",
82670
- /* 88 */ "tcons ::= CHECK LP expr RP onconf",
82671
- /* 89 */ "tcons ::= FOREIGN KEY LP idxlist RP REFERENCES nm idxlist_opt refargs defer_subclause_opt",
82672
- /* 90 */ "defer_subclause_opt ::=",
82673
- /* 91 */ "defer_subclause_opt ::= defer_subclause",
82674
- /* 92 */ "onconf ::=",
82675
- /* 93 */ "onconf ::= ON CONFLICT resolvetype",
82676
- /* 94 */ "orconf ::=",
82677
- /* 95 */ "orconf ::= OR resolvetype",
82678
- /* 96 */ "resolvetype ::= raisetype",
82679
- /* 97 */ "resolvetype ::= IGNORE",
82680
- /* 98 */ "resolvetype ::= REPLACE",
82681
- /* 99 */ "cmd ::= DROP TABLE ifexists fullname",
82682
- /* 100 */ "ifexists ::= IF EXISTS",
82683
- /* 101 */ "ifexists ::=",
82684
- /* 102 */ "cmd ::= CREATE temp VIEW ifnotexists nm dbnm AS select",
82685
- /* 103 */ "cmd ::= DROP VIEW ifexists fullname",
82686
- /* 104 */ "cmd ::= select",
82687
- /* 105 */ "select ::= oneselect",
82688
- /* 106 */ "select ::= select multiselect_op oneselect",
82689
- /* 107 */ "multiselect_op ::= UNION",
82690
- /* 108 */ "multiselect_op ::= UNION ALL",
82691
- /* 109 */ "multiselect_op ::= EXCEPT|INTERSECT",
82692
- /* 110 */ "oneselect ::= SELECT distinct selcollist from where_opt groupby_opt having_opt orderby_opt limit_opt",
82693
- /* 111 */ "distinct ::= DISTINCT",
82694
- /* 112 */ "distinct ::= ALL",
82695
- /* 113 */ "distinct ::=",
82696
- /* 114 */ "sclp ::= selcollist COMMA",
82697
- /* 115 */ "sclp ::=",
82698
- /* 116 */ "selcollist ::= sclp expr as",
82699
- /* 117 */ "selcollist ::= sclp STAR",
82700
- /* 118 */ "selcollist ::= sclp nm DOT STAR",
82701
- /* 119 */ "as ::= AS nm",
82702
- /* 120 */ "as ::= ids",
82703
- /* 121 */ "as ::=",
82704
- /* 122 */ "from ::=",
82705
- /* 123 */ "from ::= FROM seltablist",
82706
- /* 124 */ "stl_prefix ::= seltablist joinop",
82707
- /* 125 */ "stl_prefix ::=",
82708
- /* 126 */ "seltablist ::= stl_prefix nm dbnm as indexed_opt on_opt using_opt",
82709
- /* 127 */ "seltablist ::= stl_prefix LP select RP as on_opt using_opt",
82710
- /* 128 */ "seltablist ::= stl_prefix LP seltablist RP as on_opt using_opt",
82711
- /* 129 */ "dbnm ::=",
82712
- /* 130 */ "dbnm ::= DOT nm",
82713
- /* 131 */ "fullname ::= nm dbnm",
82714
- /* 132 */ "joinop ::= COMMA|JOIN",
82715
- /* 133 */ "joinop ::= JOIN_KW JOIN",
82716
- /* 134 */ "joinop ::= JOIN_KW nm JOIN",
82717
- /* 135 */ "joinop ::= JOIN_KW nm nm JOIN",
82718
- /* 136 */ "on_opt ::= ON expr",
82719
- /* 137 */ "on_opt ::=",
82720
- /* 138 */ "indexed_opt ::=",
82721
- /* 139 */ "indexed_opt ::= INDEXED BY nm",
82722
- /* 140 */ "indexed_opt ::= NOT INDEXED",
82723
- /* 141 */ "using_opt ::= USING LP inscollist RP",
82724
- /* 142 */ "using_opt ::=",
82725
- /* 143 */ "orderby_opt ::=",
82726
- /* 144 */ "orderby_opt ::= ORDER BY sortlist",
82727
- /* 145 */ "sortlist ::= sortlist COMMA sortitem sortorder",
82728
- /* 146 */ "sortlist ::= sortitem sortorder",
82729
- /* 147 */ "sortitem ::= expr",
82730
- /* 148 */ "sortorder ::= ASC",
82731
- /* 149 */ "sortorder ::= DESC",
82732
- /* 150 */ "sortorder ::=",
82733
- /* 151 */ "groupby_opt ::=",
82734
- /* 152 */ "groupby_opt ::= GROUP BY nexprlist",
82735
- /* 153 */ "having_opt ::=",
82736
- /* 154 */ "having_opt ::= HAVING expr",
82737
- /* 155 */ "limit_opt ::=",
82738
- /* 156 */ "limit_opt ::= LIMIT expr",
82739
- /* 157 */ "limit_opt ::= LIMIT expr OFFSET expr",
82740
- /* 158 */ "limit_opt ::= LIMIT expr COMMA expr",
82741
- /* 159 */ "cmd ::= DELETE FROM fullname indexed_opt where_opt",
82742
- /* 160 */ "where_opt ::=",
82743
- /* 161 */ "where_opt ::= WHERE expr",
82744
- /* 162 */ "cmd ::= UPDATE orconf fullname indexed_opt SET setlist where_opt",
82745
- /* 163 */ "setlist ::= setlist COMMA nm EQ expr",
82746
- /* 164 */ "setlist ::= nm EQ expr",
82747
- /* 165 */ "cmd ::= insert_cmd INTO fullname inscollist_opt VALUES LP itemlist RP",
82748
- /* 166 */ "cmd ::= insert_cmd INTO fullname inscollist_opt select",
82749
- /* 167 */ "cmd ::= insert_cmd INTO fullname inscollist_opt DEFAULT VALUES",
82750
- /* 168 */ "insert_cmd ::= INSERT orconf",
82751
- /* 169 */ "insert_cmd ::= REPLACE",
82752
- /* 170 */ "itemlist ::= itemlist COMMA expr",
82753
- /* 171 */ "itemlist ::= expr",
82754
- /* 172 */ "inscollist_opt ::=",
82755
- /* 173 */ "inscollist_opt ::= LP inscollist RP",
82756
- /* 174 */ "inscollist ::= inscollist COMMA nm",
82757
- /* 175 */ "inscollist ::= nm",
82758
- /* 176 */ "expr ::= term",
82759
- /* 177 */ "expr ::= LP expr RP",
82760
- /* 178 */ "term ::= NULL",
82761
- /* 179 */ "expr ::= ID",
82762
- /* 180 */ "expr ::= JOIN_KW",
82763
- /* 181 */ "expr ::= nm DOT nm",
82764
- /* 182 */ "expr ::= nm DOT nm DOT nm",
82765
- /* 183 */ "term ::= INTEGER|FLOAT|BLOB",
82766
- /* 184 */ "term ::= STRING",
82767
- /* 185 */ "expr ::= REGISTER",
82768
- /* 186 */ "expr ::= VARIABLE",
82769
- /* 187 */ "expr ::= expr COLLATE ids",
82770
- /* 188 */ "expr ::= CAST LP expr AS typetoken RP",
82771
- /* 189 */ "expr ::= ID LP distinct exprlist RP",
82772
- /* 190 */ "expr ::= ID LP STAR RP",
82773
- /* 191 */ "term ::= CTIME_KW",
82774
- /* 192 */ "expr ::= expr AND expr",
82775
- /* 193 */ "expr ::= expr OR expr",
82776
- /* 194 */ "expr ::= expr LT|GT|GE|LE expr",
82777
- /* 195 */ "expr ::= expr EQ|NE expr",
82778
- /* 196 */ "expr ::= expr BITAND|BITOR|LSHIFT|RSHIFT expr",
82779
- /* 197 */ "expr ::= expr PLUS|MINUS expr",
82780
- /* 198 */ "expr ::= expr STAR|SLASH|REM expr",
82781
- /* 199 */ "expr ::= expr CONCAT expr",
82782
- /* 200 */ "likeop ::= LIKE_KW",
82783
- /* 201 */ "likeop ::= NOT LIKE_KW",
82784
- /* 202 */ "likeop ::= MATCH",
82785
- /* 203 */ "likeop ::= NOT MATCH",
82786
- /* 204 */ "escape ::= ESCAPE expr",
82787
- /* 205 */ "escape ::=",
82788
- /* 206 */ "expr ::= expr likeop expr escape",
82789
- /* 207 */ "expr ::= expr ISNULL|NOTNULL",
82790
- /* 208 */ "expr ::= expr IS NULL",
82791
- /* 209 */ "expr ::= expr NOT NULL",
82792
- /* 210 */ "expr ::= expr IS NOT NULL",
82793
- /* 211 */ "expr ::= NOT expr",
82794
- /* 212 */ "expr ::= BITNOT expr",
82795
- /* 213 */ "expr ::= MINUS expr",
82796
- /* 214 */ "expr ::= PLUS expr",
82797
- /* 215 */ "between_op ::= BETWEEN",
82798
- /* 216 */ "between_op ::= NOT BETWEEN",
82799
- /* 217 */ "expr ::= expr between_op expr AND expr",
82800
- /* 218 */ "in_op ::= IN",
82801
- /* 219 */ "in_op ::= NOT IN",
82802
- /* 220 */ "expr ::= expr in_op LP exprlist RP",
82803
- /* 221 */ "expr ::= LP select RP",
82804
- /* 222 */ "expr ::= expr in_op LP select RP",
82805
- /* 223 */ "expr ::= expr in_op nm dbnm",
82806
- /* 224 */ "expr ::= EXISTS LP select RP",
82807
- /* 225 */ "expr ::= CASE case_operand case_exprlist case_else END",
82808
- /* 226 */ "case_exprlist ::= case_exprlist WHEN expr THEN expr",
82809
- /* 227 */ "case_exprlist ::= WHEN expr THEN expr",
82810
- /* 228 */ "case_else ::= ELSE expr",
82811
- /* 229 */ "case_else ::=",
82812
- /* 230 */ "case_operand ::= expr",
82813
- /* 231 */ "case_operand ::=",
82814
- /* 232 */ "exprlist ::= nexprlist",
82815
- /* 233 */ "exprlist ::=",
82816
- /* 234 */ "nexprlist ::= nexprlist COMMA expr",
82817
- /* 235 */ "nexprlist ::= expr",
82818
- /* 236 */ "cmd ::= CREATE uniqueflag INDEX ifnotexists nm dbnm ON nm LP idxlist RP",
82819
- /* 237 */ "uniqueflag ::= UNIQUE",
82820
- /* 238 */ "uniqueflag ::=",
82821
- /* 239 */ "idxlist_opt ::=",
82822
- /* 240 */ "idxlist_opt ::= LP idxlist RP",
82823
- /* 241 */ "idxlist ::= idxlist COMMA nm collate sortorder",
82824
- /* 242 */ "idxlist ::= nm collate sortorder",
82825
- /* 243 */ "collate ::=",
82826
- /* 244 */ "collate ::= COLLATE ids",
82827
- /* 245 */ "cmd ::= DROP INDEX ifexists fullname",
82828
- /* 246 */ "cmd ::= VACUUM",
82829
- /* 247 */ "cmd ::= VACUUM nm",
82830
- /* 248 */ "cmd ::= PRAGMA nm dbnm EQ nmnum",
82831
- /* 249 */ "cmd ::= PRAGMA nm dbnm EQ ON",
82832
- /* 250 */ "cmd ::= PRAGMA nm dbnm EQ DELETE",
82833
- /* 251 */ "cmd ::= PRAGMA nm dbnm EQ minus_num",
82834
- /* 252 */ "cmd ::= PRAGMA nm dbnm LP nmnum RP",
82835
- /* 253 */ "cmd ::= PRAGMA nm dbnm",
82836
- /* 254 */ "nmnum ::= plus_num",
82837
- /* 255 */ "nmnum ::= nm",
82838
- /* 256 */ "plus_num ::= plus_opt number",
82839
- /* 257 */ "minus_num ::= MINUS number",
82840
- /* 258 */ "number ::= INTEGER|FLOAT",
82841
- /* 259 */ "plus_opt ::= PLUS",
82842
- /* 260 */ "plus_opt ::=",
82843
- /* 261 */ "cmd ::= CREATE trigger_decl BEGIN trigger_cmd_list END",
82844
- /* 262 */ "trigger_decl ::= temp TRIGGER ifnotexists nm dbnm trigger_time trigger_event ON fullname foreach_clause when_clause",
82845
- /* 263 */ "trigger_time ::= BEFORE",
82846
- /* 264 */ "trigger_time ::= AFTER",
82847
- /* 265 */ "trigger_time ::= INSTEAD OF",
82848
- /* 266 */ "trigger_time ::=",
82849
- /* 267 */ "trigger_event ::= DELETE|INSERT",
82850
- /* 268 */ "trigger_event ::= UPDATE",
82851
- /* 269 */ "trigger_event ::= UPDATE OF inscollist",
82852
- /* 270 */ "foreach_clause ::=",
82853
- /* 271 */ "foreach_clause ::= FOR EACH ROW",
82854
- /* 272 */ "when_clause ::=",
82855
- /* 273 */ "when_clause ::= WHEN expr",
82856
- /* 274 */ "trigger_cmd_list ::= trigger_cmd_list trigger_cmd SEMI",
82857
- /* 275 */ "trigger_cmd_list ::= trigger_cmd SEMI",
82858
- /* 276 */ "trigger_cmd ::= UPDATE orconf nm SET setlist where_opt",
82859
- /* 277 */ "trigger_cmd ::= insert_cmd INTO nm inscollist_opt VALUES LP itemlist RP",
82860
- /* 278 */ "trigger_cmd ::= insert_cmd INTO nm inscollist_opt select",
82861
- /* 279 */ "trigger_cmd ::= DELETE FROM nm where_opt",
82862
- /* 280 */ "trigger_cmd ::= select",
82863
- /* 281 */ "expr ::= RAISE LP IGNORE RP",
82864
- /* 282 */ "expr ::= RAISE LP raisetype COMMA nm RP",
82865
- /* 283 */ "raisetype ::= ROLLBACK",
82866
- /* 284 */ "raisetype ::= ABORT",
82867
- /* 285 */ "raisetype ::= FAIL",
82868
- /* 286 */ "cmd ::= DROP TRIGGER ifexists fullname",
82869
- /* 287 */ "cmd ::= ATTACH database_kw_opt expr AS expr key_opt",
82870
- /* 288 */ "cmd ::= DETACH database_kw_opt expr",
82871
- /* 289 */ "key_opt ::=",
82872
- /* 290 */ "key_opt ::= KEY expr",
82873
- /* 291 */ "database_kw_opt ::= DATABASE",
82874
- /* 292 */ "database_kw_opt ::=",
82875
- /* 293 */ "cmd ::= REINDEX",
82876
- /* 294 */ "cmd ::= REINDEX nm dbnm",
82877
- /* 295 */ "cmd ::= ANALYZE",
82878
- /* 296 */ "cmd ::= ANALYZE nm dbnm",
82879
- /* 297 */ "cmd ::= ALTER TABLE fullname RENAME TO nm",
82880
- /* 298 */ "cmd ::= ALTER TABLE add_column_fullname ADD kwcolumn_opt column",
82881
- /* 299 */ "add_column_fullname ::= fullname",
82882
- /* 300 */ "kwcolumn_opt ::=",
82883
- /* 301 */ "kwcolumn_opt ::= COLUMNKW",
82884
- /* 302 */ "cmd ::= create_vtab",
82885
- /* 303 */ "cmd ::= create_vtab LP vtabarglist RP",
82886
- /* 304 */ "create_vtab ::= CREATE VIRTUAL TABLE nm dbnm USING nm",
82887
- /* 305 */ "vtabarglist ::= vtabarg",
82888
- /* 306 */ "vtabarglist ::= vtabarglist COMMA vtabarg",
82889
- /* 307 */ "vtabarg ::=",
82890
- /* 308 */ "vtabarg ::= vtabarg vtabargtoken",
82891
- /* 309 */ "vtabargtoken ::= ANY",
82892
- /* 310 */ "vtabargtoken ::= lp anylist RP",
82893
- /* 311 */ "lp ::= LP",
82894
- /* 312 */ "anylist ::=",
82895
- /* 313 */ "anylist ::= anylist ANY",
83650
+ /* 20 */ "savepoint_opt ::= SAVEPOINT",
83651
+ /* 21 */ "savepoint_opt ::=",
83652
+ /* 22 */ "cmd ::= SAVEPOINT nm",
83653
+ /* 23 */ "cmd ::= RELEASE savepoint_opt nm",
83654
+ /* 24 */ "cmd ::= ROLLBACK trans_opt TO savepoint_opt nm",
83655
+ /* 25 */ "cmd ::= create_table create_table_args",
83656
+ /* 26 */ "create_table ::= CREATE temp TABLE ifnotexists nm dbnm",
83657
+ /* 27 */ "ifnotexists ::=",
83658
+ /* 28 */ "ifnotexists ::= IF NOT EXISTS",
83659
+ /* 29 */ "temp ::= TEMP",
83660
+ /* 30 */ "temp ::=",
83661
+ /* 31 */ "create_table_args ::= LP columnlist conslist_opt RP",
83662
+ /* 32 */ "create_table_args ::= AS select",
83663
+ /* 33 */ "columnlist ::= columnlist COMMA column",
83664
+ /* 34 */ "columnlist ::= column",
83665
+ /* 35 */ "column ::= columnid type carglist",
83666
+ /* 36 */ "columnid ::= nm",
83667
+ /* 37 */ "id ::= ID",
83668
+ /* 38 */ "ids ::= ID|STRING",
83669
+ /* 39 */ "nm ::= ID",
83670
+ /* 40 */ "nm ::= STRING",
83671
+ /* 41 */ "nm ::= JOIN_KW",
83672
+ /* 42 */ "type ::=",
83673
+ /* 43 */ "type ::= typetoken",
83674
+ /* 44 */ "typetoken ::= typename",
83675
+ /* 45 */ "typetoken ::= typename LP signed RP",
83676
+ /* 46 */ "typetoken ::= typename LP signed COMMA signed RP",
83677
+ /* 47 */ "typename ::= ids",
83678
+ /* 48 */ "typename ::= typename ids",
83679
+ /* 49 */ "signed ::= plus_num",
83680
+ /* 50 */ "signed ::= minus_num",
83681
+ /* 51 */ "carglist ::= carglist carg",
83682
+ /* 52 */ "carglist ::=",
83683
+ /* 53 */ "carg ::= CONSTRAINT nm ccons",
83684
+ /* 54 */ "carg ::= ccons",
83685
+ /* 55 */ "ccons ::= DEFAULT term",
83686
+ /* 56 */ "ccons ::= DEFAULT LP expr RP",
83687
+ /* 57 */ "ccons ::= DEFAULT PLUS term",
83688
+ /* 58 */ "ccons ::= DEFAULT MINUS term",
83689
+ /* 59 */ "ccons ::= DEFAULT id",
83690
+ /* 60 */ "ccons ::= NULL onconf",
83691
+ /* 61 */ "ccons ::= NOT NULL onconf",
83692
+ /* 62 */ "ccons ::= PRIMARY KEY sortorder onconf autoinc",
83693
+ /* 63 */ "ccons ::= UNIQUE onconf",
83694
+ /* 64 */ "ccons ::= CHECK LP expr RP",
83695
+ /* 65 */ "ccons ::= REFERENCES nm idxlist_opt refargs",
83696
+ /* 66 */ "ccons ::= defer_subclause",
83697
+ /* 67 */ "ccons ::= COLLATE ids",
83698
+ /* 68 */ "autoinc ::=",
83699
+ /* 69 */ "autoinc ::= AUTOINCR",
83700
+ /* 70 */ "refargs ::=",
83701
+ /* 71 */ "refargs ::= refargs refarg",
83702
+ /* 72 */ "refarg ::= MATCH nm",
83703
+ /* 73 */ "refarg ::= ON DELETE refact",
83704
+ /* 74 */ "refarg ::= ON UPDATE refact",
83705
+ /* 75 */ "refarg ::= ON INSERT refact",
83706
+ /* 76 */ "refact ::= SET NULL",
83707
+ /* 77 */ "refact ::= SET DEFAULT",
83708
+ /* 78 */ "refact ::= CASCADE",
83709
+ /* 79 */ "refact ::= RESTRICT",
83710
+ /* 80 */ "defer_subclause ::= NOT DEFERRABLE init_deferred_pred_opt",
83711
+ /* 81 */ "defer_subclause ::= DEFERRABLE init_deferred_pred_opt",
83712
+ /* 82 */ "init_deferred_pred_opt ::=",
83713
+ /* 83 */ "init_deferred_pred_opt ::= INITIALLY DEFERRED",
83714
+ /* 84 */ "init_deferred_pred_opt ::= INITIALLY IMMEDIATE",
83715
+ /* 85 */ "conslist_opt ::=",
83716
+ /* 86 */ "conslist_opt ::= COMMA conslist",
83717
+ /* 87 */ "conslist ::= conslist COMMA tcons",
83718
+ /* 88 */ "conslist ::= conslist tcons",
83719
+ /* 89 */ "conslist ::= tcons",
83720
+ /* 90 */ "tcons ::= CONSTRAINT nm",
83721
+ /* 91 */ "tcons ::= PRIMARY KEY LP idxlist autoinc RP onconf",
83722
+ /* 92 */ "tcons ::= UNIQUE LP idxlist RP onconf",
83723
+ /* 93 */ "tcons ::= CHECK LP expr RP onconf",
83724
+ /* 94 */ "tcons ::= FOREIGN KEY LP idxlist RP REFERENCES nm idxlist_opt refargs defer_subclause_opt",
83725
+ /* 95 */ "defer_subclause_opt ::=",
83726
+ /* 96 */ "defer_subclause_opt ::= defer_subclause",
83727
+ /* 97 */ "onconf ::=",
83728
+ /* 98 */ "onconf ::= ON CONFLICT resolvetype",
83729
+ /* 99 */ "orconf ::=",
83730
+ /* 100 */ "orconf ::= OR resolvetype",
83731
+ /* 101 */ "resolvetype ::= raisetype",
83732
+ /* 102 */ "resolvetype ::= IGNORE",
83733
+ /* 103 */ "resolvetype ::= REPLACE",
83734
+ /* 104 */ "cmd ::= DROP TABLE ifexists fullname",
83735
+ /* 105 */ "ifexists ::= IF EXISTS",
83736
+ /* 106 */ "ifexists ::=",
83737
+ /* 107 */ "cmd ::= CREATE temp VIEW ifnotexists nm dbnm AS select",
83738
+ /* 108 */ "cmd ::= DROP VIEW ifexists fullname",
83739
+ /* 109 */ "cmd ::= select",
83740
+ /* 110 */ "select ::= oneselect",
83741
+ /* 111 */ "select ::= select multiselect_op oneselect",
83742
+ /* 112 */ "multiselect_op ::= UNION",
83743
+ /* 113 */ "multiselect_op ::= UNION ALL",
83744
+ /* 114 */ "multiselect_op ::= EXCEPT|INTERSECT",
83745
+ /* 115 */ "oneselect ::= SELECT distinct selcollist from where_opt groupby_opt having_opt orderby_opt limit_opt",
83746
+ /* 116 */ "distinct ::= DISTINCT",
83747
+ /* 117 */ "distinct ::= ALL",
83748
+ /* 118 */ "distinct ::=",
83749
+ /* 119 */ "sclp ::= selcollist COMMA",
83750
+ /* 120 */ "sclp ::=",
83751
+ /* 121 */ "selcollist ::= sclp expr as",
83752
+ /* 122 */ "selcollist ::= sclp STAR",
83753
+ /* 123 */ "selcollist ::= sclp nm DOT STAR",
83754
+ /* 124 */ "as ::= AS nm",
83755
+ /* 125 */ "as ::= ids",
83756
+ /* 126 */ "as ::=",
83757
+ /* 127 */ "from ::=",
83758
+ /* 128 */ "from ::= FROM seltablist",
83759
+ /* 129 */ "stl_prefix ::= seltablist joinop",
83760
+ /* 130 */ "stl_prefix ::=",
83761
+ /* 131 */ "seltablist ::= stl_prefix nm dbnm as indexed_opt on_opt using_opt",
83762
+ /* 132 */ "seltablist ::= stl_prefix LP select RP as on_opt using_opt",
83763
+ /* 133 */ "seltablist ::= stl_prefix LP seltablist RP as on_opt using_opt",
83764
+ /* 134 */ "dbnm ::=",
83765
+ /* 135 */ "dbnm ::= DOT nm",
83766
+ /* 136 */ "fullname ::= nm dbnm",
83767
+ /* 137 */ "joinop ::= COMMA|JOIN",
83768
+ /* 138 */ "joinop ::= JOIN_KW JOIN",
83769
+ /* 139 */ "joinop ::= JOIN_KW nm JOIN",
83770
+ /* 140 */ "joinop ::= JOIN_KW nm nm JOIN",
83771
+ /* 141 */ "on_opt ::= ON expr",
83772
+ /* 142 */ "on_opt ::=",
83773
+ /* 143 */ "indexed_opt ::=",
83774
+ /* 144 */ "indexed_opt ::= INDEXED BY nm",
83775
+ /* 145 */ "indexed_opt ::= NOT INDEXED",
83776
+ /* 146 */ "using_opt ::= USING LP inscollist RP",
83777
+ /* 147 */ "using_opt ::=",
83778
+ /* 148 */ "orderby_opt ::=",
83779
+ /* 149 */ "orderby_opt ::= ORDER BY sortlist",
83780
+ /* 150 */ "sortlist ::= sortlist COMMA sortitem sortorder",
83781
+ /* 151 */ "sortlist ::= sortitem sortorder",
83782
+ /* 152 */ "sortitem ::= expr",
83783
+ /* 153 */ "sortorder ::= ASC",
83784
+ /* 154 */ "sortorder ::= DESC",
83785
+ /* 155 */ "sortorder ::=",
83786
+ /* 156 */ "groupby_opt ::=",
83787
+ /* 157 */ "groupby_opt ::= GROUP BY nexprlist",
83788
+ /* 158 */ "having_opt ::=",
83789
+ /* 159 */ "having_opt ::= HAVING expr",
83790
+ /* 160 */ "limit_opt ::=",
83791
+ /* 161 */ "limit_opt ::= LIMIT expr",
83792
+ /* 162 */ "limit_opt ::= LIMIT expr OFFSET expr",
83793
+ /* 163 */ "limit_opt ::= LIMIT expr COMMA expr",
83794
+ /* 164 */ "cmd ::= DELETE FROM fullname indexed_opt where_opt",
83795
+ /* 165 */ "where_opt ::=",
83796
+ /* 166 */ "where_opt ::= WHERE expr",
83797
+ /* 167 */ "cmd ::= UPDATE orconf fullname indexed_opt SET setlist where_opt",
83798
+ /* 168 */ "setlist ::= setlist COMMA nm EQ expr",
83799
+ /* 169 */ "setlist ::= nm EQ expr",
83800
+ /* 170 */ "cmd ::= insert_cmd INTO fullname inscollist_opt VALUES LP itemlist RP",
83801
+ /* 171 */ "cmd ::= insert_cmd INTO fullname inscollist_opt select",
83802
+ /* 172 */ "cmd ::= insert_cmd INTO fullname inscollist_opt DEFAULT VALUES",
83803
+ /* 173 */ "insert_cmd ::= INSERT orconf",
83804
+ /* 174 */ "insert_cmd ::= REPLACE",
83805
+ /* 175 */ "itemlist ::= itemlist COMMA expr",
83806
+ /* 176 */ "itemlist ::= expr",
83807
+ /* 177 */ "inscollist_opt ::=",
83808
+ /* 178 */ "inscollist_opt ::= LP inscollist RP",
83809
+ /* 179 */ "inscollist ::= inscollist COMMA nm",
83810
+ /* 180 */ "inscollist ::= nm",
83811
+ /* 181 */ "expr ::= term",
83812
+ /* 182 */ "expr ::= LP expr RP",
83813
+ /* 183 */ "term ::= NULL",
83814
+ /* 184 */ "expr ::= ID",
83815
+ /* 185 */ "expr ::= JOIN_KW",
83816
+ /* 186 */ "expr ::= nm DOT nm",
83817
+ /* 187 */ "expr ::= nm DOT nm DOT nm",
83818
+ /* 188 */ "term ::= INTEGER|FLOAT|BLOB",
83819
+ /* 189 */ "term ::= STRING",
83820
+ /* 190 */ "expr ::= REGISTER",
83821
+ /* 191 */ "expr ::= VARIABLE",
83822
+ /* 192 */ "expr ::= expr COLLATE ids",
83823
+ /* 193 */ "expr ::= CAST LP expr AS typetoken RP",
83824
+ /* 194 */ "expr ::= ID LP distinct exprlist RP",
83825
+ /* 195 */ "expr ::= ID LP STAR RP",
83826
+ /* 196 */ "term ::= CTIME_KW",
83827
+ /* 197 */ "expr ::= expr AND expr",
83828
+ /* 198 */ "expr ::= expr OR expr",
83829
+ /* 199 */ "expr ::= expr LT|GT|GE|LE expr",
83830
+ /* 200 */ "expr ::= expr EQ|NE expr",
83831
+ /* 201 */ "expr ::= expr BITAND|BITOR|LSHIFT|RSHIFT expr",
83832
+ /* 202 */ "expr ::= expr PLUS|MINUS expr",
83833
+ /* 203 */ "expr ::= expr STAR|SLASH|REM expr",
83834
+ /* 204 */ "expr ::= expr CONCAT expr",
83835
+ /* 205 */ "likeop ::= LIKE_KW",
83836
+ /* 206 */ "likeop ::= NOT LIKE_KW",
83837
+ /* 207 */ "likeop ::= MATCH",
83838
+ /* 208 */ "likeop ::= NOT MATCH",
83839
+ /* 209 */ "escape ::= ESCAPE expr",
83840
+ /* 210 */ "escape ::=",
83841
+ /* 211 */ "expr ::= expr likeop expr escape",
83842
+ /* 212 */ "expr ::= expr ISNULL|NOTNULL",
83843
+ /* 213 */ "expr ::= expr IS NULL",
83844
+ /* 214 */ "expr ::= expr NOT NULL",
83845
+ /* 215 */ "expr ::= expr IS NOT NULL",
83846
+ /* 216 */ "expr ::= NOT expr",
83847
+ /* 217 */ "expr ::= BITNOT expr",
83848
+ /* 218 */ "expr ::= MINUS expr",
83849
+ /* 219 */ "expr ::= PLUS expr",
83850
+ /* 220 */ "between_op ::= BETWEEN",
83851
+ /* 221 */ "between_op ::= NOT BETWEEN",
83852
+ /* 222 */ "expr ::= expr between_op expr AND expr",
83853
+ /* 223 */ "in_op ::= IN",
83854
+ /* 224 */ "in_op ::= NOT IN",
83855
+ /* 225 */ "expr ::= expr in_op LP exprlist RP",
83856
+ /* 226 */ "expr ::= LP select RP",
83857
+ /* 227 */ "expr ::= expr in_op LP select RP",
83858
+ /* 228 */ "expr ::= expr in_op nm dbnm",
83859
+ /* 229 */ "expr ::= EXISTS LP select RP",
83860
+ /* 230 */ "expr ::= CASE case_operand case_exprlist case_else END",
83861
+ /* 231 */ "case_exprlist ::= case_exprlist WHEN expr THEN expr",
83862
+ /* 232 */ "case_exprlist ::= WHEN expr THEN expr",
83863
+ /* 233 */ "case_else ::= ELSE expr",
83864
+ /* 234 */ "case_else ::=",
83865
+ /* 235 */ "case_operand ::= expr",
83866
+ /* 236 */ "case_operand ::=",
83867
+ /* 237 */ "exprlist ::= nexprlist",
83868
+ /* 238 */ "exprlist ::=",
83869
+ /* 239 */ "nexprlist ::= nexprlist COMMA expr",
83870
+ /* 240 */ "nexprlist ::= expr",
83871
+ /* 241 */ "cmd ::= CREATE uniqueflag INDEX ifnotexists nm dbnm ON nm LP idxlist RP",
83872
+ /* 242 */ "uniqueflag ::= UNIQUE",
83873
+ /* 243 */ "uniqueflag ::=",
83874
+ /* 244 */ "idxlist_opt ::=",
83875
+ /* 245 */ "idxlist_opt ::= LP idxlist RP",
83876
+ /* 246 */ "idxlist ::= idxlist COMMA nm collate sortorder",
83877
+ /* 247 */ "idxlist ::= nm collate sortorder",
83878
+ /* 248 */ "collate ::=",
83879
+ /* 249 */ "collate ::= COLLATE ids",
83880
+ /* 250 */ "cmd ::= DROP INDEX ifexists fullname",
83881
+ /* 251 */ "cmd ::= VACUUM",
83882
+ /* 252 */ "cmd ::= VACUUM nm",
83883
+ /* 253 */ "cmd ::= PRAGMA nm dbnm EQ nmnum",
83884
+ /* 254 */ "cmd ::= PRAGMA nm dbnm EQ ON",
83885
+ /* 255 */ "cmd ::= PRAGMA nm dbnm EQ DELETE",
83886
+ /* 256 */ "cmd ::= PRAGMA nm dbnm EQ minus_num",
83887
+ /* 257 */ "cmd ::= PRAGMA nm dbnm LP nmnum RP",
83888
+ /* 258 */ "cmd ::= PRAGMA nm dbnm",
83889
+ /* 259 */ "nmnum ::= plus_num",
83890
+ /* 260 */ "nmnum ::= nm",
83891
+ /* 261 */ "plus_num ::= plus_opt number",
83892
+ /* 262 */ "minus_num ::= MINUS number",
83893
+ /* 263 */ "number ::= INTEGER|FLOAT",
83894
+ /* 264 */ "plus_opt ::= PLUS",
83895
+ /* 265 */ "plus_opt ::=",
83896
+ /* 266 */ "cmd ::= CREATE trigger_decl BEGIN trigger_cmd_list END",
83897
+ /* 267 */ "trigger_decl ::= temp TRIGGER ifnotexists nm dbnm trigger_time trigger_event ON fullname foreach_clause when_clause",
83898
+ /* 268 */ "trigger_time ::= BEFORE",
83899
+ /* 269 */ "trigger_time ::= AFTER",
83900
+ /* 270 */ "trigger_time ::= INSTEAD OF",
83901
+ /* 271 */ "trigger_time ::=",
83902
+ /* 272 */ "trigger_event ::= DELETE|INSERT",
83903
+ /* 273 */ "trigger_event ::= UPDATE",
83904
+ /* 274 */ "trigger_event ::= UPDATE OF inscollist",
83905
+ /* 275 */ "foreach_clause ::=",
83906
+ /* 276 */ "foreach_clause ::= FOR EACH ROW",
83907
+ /* 277 */ "when_clause ::=",
83908
+ /* 278 */ "when_clause ::= WHEN expr",
83909
+ /* 279 */ "trigger_cmd_list ::= trigger_cmd_list trigger_cmd SEMI",
83910
+ /* 280 */ "trigger_cmd_list ::= trigger_cmd SEMI",
83911
+ /* 281 */ "trigger_cmd ::= UPDATE orconf nm SET setlist where_opt",
83912
+ /* 282 */ "trigger_cmd ::= insert_cmd INTO nm inscollist_opt VALUES LP itemlist RP",
83913
+ /* 283 */ "trigger_cmd ::= insert_cmd INTO nm inscollist_opt select",
83914
+ /* 284 */ "trigger_cmd ::= DELETE FROM nm where_opt",
83915
+ /* 285 */ "trigger_cmd ::= select",
83916
+ /* 286 */ "expr ::= RAISE LP IGNORE RP",
83917
+ /* 287 */ "expr ::= RAISE LP raisetype COMMA nm RP",
83918
+ /* 288 */ "raisetype ::= ROLLBACK",
83919
+ /* 289 */ "raisetype ::= ABORT",
83920
+ /* 290 */ "raisetype ::= FAIL",
83921
+ /* 291 */ "cmd ::= DROP TRIGGER ifexists fullname",
83922
+ /* 292 */ "cmd ::= ATTACH database_kw_opt expr AS expr key_opt",
83923
+ /* 293 */ "cmd ::= DETACH database_kw_opt expr",
83924
+ /* 294 */ "key_opt ::=",
83925
+ /* 295 */ "key_opt ::= KEY expr",
83926
+ /* 296 */ "database_kw_opt ::= DATABASE",
83927
+ /* 297 */ "database_kw_opt ::=",
83928
+ /* 298 */ "cmd ::= REINDEX",
83929
+ /* 299 */ "cmd ::= REINDEX nm dbnm",
83930
+ /* 300 */ "cmd ::= ANALYZE",
83931
+ /* 301 */ "cmd ::= ANALYZE nm dbnm",
83932
+ /* 302 */ "cmd ::= ALTER TABLE fullname RENAME TO nm",
83933
+ /* 303 */ "cmd ::= ALTER TABLE add_column_fullname ADD kwcolumn_opt column",
83934
+ /* 304 */ "add_column_fullname ::= fullname",
83935
+ /* 305 */ "kwcolumn_opt ::=",
83936
+ /* 306 */ "kwcolumn_opt ::= COLUMNKW",
83937
+ /* 307 */ "cmd ::= create_vtab",
83938
+ /* 308 */ "cmd ::= create_vtab LP vtabarglist RP",
83939
+ /* 309 */ "create_vtab ::= CREATE VIRTUAL TABLE nm dbnm USING nm",
83940
+ /* 310 */ "vtabarglist ::= vtabarg",
83941
+ /* 311 */ "vtabarglist ::= vtabarglist COMMA vtabarg",
83942
+ /* 312 */ "vtabarg ::=",
83943
+ /* 313 */ "vtabarg ::= vtabarg vtabargtoken",
83944
+ /* 314 */ "vtabargtoken ::= ANY",
83945
+ /* 315 */ "vtabargtoken ::= lp anylist RP",
83946
+ /* 316 */ "lp ::= LP",
83947
+ /* 317 */ "anylist ::=",
83948
+ /* 318 */ "anylist ::= anylist ANY",
8289683949
};
8289783950
#endif /* NDEBUG */
8289883951
8289983952
8290083953
#if YYSTACKDEPTH<=0
@@ -82969,71 +84022,71 @@
8296984022
**
8297084023
** Note: during a reduce, the only symbols destroyed are those
8297184024
** which appear on the RHS of the rule, but which are not used
8297284025
** inside the C code.
8297384026
*/
82974
- case 156: /* select */
82975
- case 190: /* oneselect */
82976
-{
82977
-sqlite3SelectDelete(pParse->db, (yypminor->yy219));
82978
-}
82979
- break;
82980
- case 170: /* term */
82981
- case 171: /* expr */
82982
- case 195: /* where_opt */
82983
- case 197: /* having_opt */
82984
- case 206: /* on_opt */
82985
- case 211: /* sortitem */
82986
- case 219: /* escape */
82987
- case 222: /* case_operand */
82988
- case 224: /* case_else */
82989
- case 235: /* when_clause */
82990
- case 238: /* key_opt */
82991
-{
82992
-sqlite3ExprDelete(pParse->db, (yypminor->yy172));
82993
-}
82994
- break;
82995
- case 175: /* idxlist_opt */
82996
- case 183: /* idxlist */
82997
- case 193: /* selcollist */
82998
- case 196: /* groupby_opt */
82999
- case 198: /* orderby_opt */
83000
- case 200: /* sclp */
83001
- case 210: /* sortlist */
83002
- case 212: /* nexprlist */
83003
- case 213: /* setlist */
83004
- case 216: /* itemlist */
83005
- case 217: /* exprlist */
83006
- case 223: /* case_exprlist */
83007
-{
83008
-sqlite3ExprListDelete(pParse->db, (yypminor->yy174));
83009
-}
83010
- break;
83011
- case 189: /* fullname */
83012
- case 194: /* from */
83013
- case 202: /* seltablist */
83014
- case 203: /* stl_prefix */
83015
-{
83016
-sqlite3SrcListDelete(pParse->db, (yypminor->yy373));
83017
-}
83018
- break;
83019
- case 207: /* using_opt */
83020
- case 209: /* inscollist */
83021
- case 215: /* inscollist_opt */
83022
-{
83023
-sqlite3IdListDelete(pParse->db, (yypminor->yy432));
83024
-}
83025
- break;
83026
- case 231: /* trigger_cmd_list */
83027
- case 236: /* trigger_cmd */
83028
-{
83029
-sqlite3DeleteTriggerStep(pParse->db, (yypminor->yy243));
83030
-}
83031
- break;
83032
- case 233: /* trigger_event */
83033
-{
83034
-sqlite3IdListDelete(pParse->db, (yypminor->yy370).b);
84027
+ case 159: /* select */
84028
+ case 193: /* oneselect */
84029
+{
84030
+sqlite3SelectDelete(pParse->db, (yypminor->yy159));
84031
+}
84032
+ break;
84033
+ case 173: /* term */
84034
+ case 174: /* expr */
84035
+ case 198: /* where_opt */
84036
+ case 200: /* having_opt */
84037
+ case 209: /* on_opt */
84038
+ case 214: /* sortitem */
84039
+ case 222: /* escape */
84040
+ case 225: /* case_operand */
84041
+ case 227: /* case_else */
84042
+ case 238: /* when_clause */
84043
+ case 241: /* key_opt */
84044
+{
84045
+sqlite3ExprDelete(pParse->db, (yypminor->yy122));
84046
+}
84047
+ break;
84048
+ case 178: /* idxlist_opt */
84049
+ case 186: /* idxlist */
84050
+ case 196: /* selcollist */
84051
+ case 199: /* groupby_opt */
84052
+ case 201: /* orderby_opt */
84053
+ case 203: /* sclp */
84054
+ case 213: /* sortlist */
84055
+ case 215: /* nexprlist */
84056
+ case 216: /* setlist */
84057
+ case 219: /* itemlist */
84058
+ case 220: /* exprlist */
84059
+ case 226: /* case_exprlist */
84060
+{
84061
+sqlite3ExprListDelete(pParse->db, (yypminor->yy442));
84062
+}
84063
+ break;
84064
+ case 192: /* fullname */
84065
+ case 197: /* from */
84066
+ case 205: /* seltablist */
84067
+ case 206: /* stl_prefix */
84068
+{
84069
+sqlite3SrcListDelete(pParse->db, (yypminor->yy347));
84070
+}
84071
+ break;
84072
+ case 210: /* using_opt */
84073
+ case 212: /* inscollist */
84074
+ case 218: /* inscollist_opt */
84075
+{
84076
+sqlite3IdListDelete(pParse->db, (yypminor->yy180));
84077
+}
84078
+ break;
84079
+ case 234: /* trigger_cmd_list */
84080
+ case 239: /* trigger_cmd */
84081
+{
84082
+sqlite3DeleteTriggerStep(pParse->db, (yypminor->yy327));
84083
+}
84084
+ break;
84085
+ case 236: /* trigger_event */
84086
+{
84087
+sqlite3IdListDelete(pParse->db, (yypminor->yy410).b);
8303584088
}
8303684089
break;
8303784090
default: break; /* If no destructor action specified: do nothing */
8303884091
}
8303984092
}
@@ -83262,324 +84315,329 @@
8326284315
*/
8326384316
static const struct {
8326484317
YYCODETYPE lhs; /* Symbol on the left-hand side of the rule */
8326584318
unsigned char nrhs; /* Number of right-hand side symbols in the rule */
8326684319
} yyRuleInfo[] = {
83267
- { 140, 1 },
83268
- { 141, 2 },
83269
- { 141, 1 },
83270
- { 142, 1 },
83271
- { 142, 3 },
83272
- { 143, 0 },
83273
- { 143, 1 },
83274
- { 143, 3 },
83275
- { 144, 1 },
83276
- { 145, 3 },
83277
- { 147, 0 },
83278
- { 147, 1 },
83279
- { 147, 2 },
83280
- { 146, 0 },
83281
- { 146, 1 },
83282
- { 146, 1 },
83283
- { 146, 1 },
83284
- { 145, 2 },
83285
- { 145, 2 },
83286
- { 145, 2 },
83287
- { 145, 2 },
83288
- { 149, 6 },
83289
- { 152, 0 },
83290
- { 152, 3 },
83291
- { 151, 1 },
83292
- { 151, 0 },
83293
- { 150, 4 },
83294
- { 150, 2 },
83295
- { 154, 3 },
83296
- { 154, 1 },
83297
- { 157, 3 },
83298
- { 158, 1 },
83299
- { 161, 1 },
83300
- { 162, 1 },
84320
+ { 142, 1 },
84321
+ { 143, 2 },
84322
+ { 143, 1 },
84323
+ { 144, 1 },
84324
+ { 144, 3 },
84325
+ { 145, 0 },
84326
+ { 145, 1 },
84327
+ { 145, 3 },
84328
+ { 146, 1 },
84329
+ { 147, 3 },
84330
+ { 149, 0 },
84331
+ { 149, 1 },
84332
+ { 149, 2 },
84333
+ { 148, 0 },
8330184334
{ 148, 1 },
8330284335
{ 148, 1 },
8330384336
{ 148, 1 },
83304
- { 159, 0 },
83305
- { 159, 1 },
83306
- { 163, 1 },
83307
- { 163, 4 },
83308
- { 163, 6 },
83309
- { 164, 1 },
83310
- { 164, 2 },
83311
- { 165, 1 },
83312
- { 165, 1 },
83313
- { 160, 2 },
83314
- { 160, 0 },
83315
- { 168, 3 },
83316
- { 168, 1 },
83317
- { 169, 2 },
83318
- { 169, 4 },
83319
- { 169, 3 },
83320
- { 169, 3 },
83321
- { 169, 2 },
83322
- { 169, 2 },
83323
- { 169, 3 },
83324
- { 169, 5 },
83325
- { 169, 2 },
83326
- { 169, 4 },
83327
- { 169, 4 },
83328
- { 169, 1 },
83329
- { 169, 2 },
83330
- { 174, 0 },
83331
- { 174, 1 },
83332
- { 176, 0 },
83333
- { 176, 2 },
83334
- { 178, 2 },
83335
- { 178, 3 },
83336
- { 178, 3 },
83337
- { 178, 3 },
83338
- { 179, 2 },
83339
- { 179, 2 },
83340
- { 179, 1 },
83341
- { 179, 1 },
83342
- { 177, 3 },
83343
- { 177, 2 },
83344
- { 180, 0 },
83345
- { 180, 2 },
83346
- { 180, 2 },
83347
- { 155, 0 },
83348
- { 155, 2 },
83349
- { 181, 3 },
84337
+ { 147, 2 },
84338
+ { 147, 2 },
84339
+ { 147, 2 },
84340
+ { 151, 1 },
84341
+ { 151, 0 },
84342
+ { 147, 2 },
84343
+ { 147, 3 },
84344
+ { 147, 5 },
84345
+ { 147, 2 },
84346
+ { 152, 6 },
84347
+ { 155, 0 },
84348
+ { 155, 3 },
84349
+ { 154, 1 },
84350
+ { 154, 0 },
84351
+ { 153, 4 },
84352
+ { 153, 2 },
84353
+ { 157, 3 },
84354
+ { 157, 1 },
84355
+ { 160, 3 },
84356
+ { 161, 1 },
84357
+ { 164, 1 },
84358
+ { 165, 1 },
84359
+ { 150, 1 },
84360
+ { 150, 1 },
84361
+ { 150, 1 },
84362
+ { 162, 0 },
84363
+ { 162, 1 },
84364
+ { 166, 1 },
84365
+ { 166, 4 },
84366
+ { 166, 6 },
84367
+ { 167, 1 },
84368
+ { 167, 2 },
84369
+ { 168, 1 },
84370
+ { 168, 1 },
84371
+ { 163, 2 },
84372
+ { 163, 0 },
84373
+ { 171, 3 },
84374
+ { 171, 1 },
84375
+ { 172, 2 },
84376
+ { 172, 4 },
84377
+ { 172, 3 },
84378
+ { 172, 3 },
84379
+ { 172, 2 },
84380
+ { 172, 2 },
84381
+ { 172, 3 },
84382
+ { 172, 5 },
84383
+ { 172, 2 },
84384
+ { 172, 4 },
84385
+ { 172, 4 },
84386
+ { 172, 1 },
84387
+ { 172, 2 },
84388
+ { 177, 0 },
84389
+ { 177, 1 },
84390
+ { 179, 0 },
84391
+ { 179, 2 },
8335084392
{ 181, 2 },
83351
- { 181, 1 },
84393
+ { 181, 3 },
84394
+ { 181, 3 },
84395
+ { 181, 3 },
84396
+ { 182, 2 },
8335284397
{ 182, 2 },
83353
- { 182, 7 },
83354
- { 182, 5 },
83355
- { 182, 5 },
83356
- { 182, 10 },
83357
- { 184, 0 },
84398
+ { 182, 1 },
84399
+ { 182, 1 },
84400
+ { 180, 3 },
84401
+ { 180, 2 },
84402
+ { 183, 0 },
84403
+ { 183, 2 },
84404
+ { 183, 2 },
84405
+ { 158, 0 },
84406
+ { 158, 2 },
84407
+ { 184, 3 },
84408
+ { 184, 2 },
8335884409
{ 184, 1 },
83359
- { 172, 0 },
83360
- { 172, 3 },
83361
- { 185, 0 },
8336284410
{ 185, 2 },
83363
- { 186, 1 },
83364
- { 186, 1 },
83365
- { 186, 1 },
83366
- { 145, 4 },
83367
- { 188, 2 },
84411
+ { 185, 7 },
84412
+ { 185, 5 },
84413
+ { 185, 5 },
84414
+ { 185, 10 },
84415
+ { 187, 0 },
84416
+ { 187, 1 },
84417
+ { 175, 0 },
84418
+ { 175, 3 },
8336884419
{ 188, 0 },
83369
- { 145, 8 },
83370
- { 145, 4 },
83371
- { 145, 1 },
83372
- { 156, 1 },
83373
- { 156, 3 },
83374
- { 191, 1 },
84420
+ { 188, 2 },
84421
+ { 189, 1 },
84422
+ { 189, 1 },
84423
+ { 189, 1 },
84424
+ { 147, 4 },
8337584425
{ 191, 2 },
83376
- { 191, 1 },
83377
- { 190, 9 },
83378
- { 192, 1 },
83379
- { 192, 1 },
83380
- { 192, 0 },
83381
- { 200, 2 },
83382
- { 200, 0 },
83383
- { 193, 3 },
83384
- { 193, 2 },
83385
- { 193, 4 },
83386
- { 201, 2 },
83387
- { 201, 1 },
83388
- { 201, 0 },
83389
- { 194, 0 },
84426
+ { 191, 0 },
84427
+ { 147, 8 },
84428
+ { 147, 4 },
84429
+ { 147, 1 },
84430
+ { 159, 1 },
84431
+ { 159, 3 },
84432
+ { 194, 1 },
8339084433
{ 194, 2 },
84434
+ { 194, 1 },
84435
+ { 193, 9 },
84436
+ { 195, 1 },
84437
+ { 195, 1 },
84438
+ { 195, 0 },
8339184439
{ 203, 2 },
8339284440
{ 203, 0 },
83393
- { 202, 7 },
83394
- { 202, 7 },
83395
- { 202, 7 },
83396
- { 153, 0 },
83397
- { 153, 2 },
83398
- { 189, 2 },
84441
+ { 196, 3 },
84442
+ { 196, 2 },
84443
+ { 196, 4 },
84444
+ { 204, 2 },
8339984445
{ 204, 1 },
83400
- { 204, 2 },
83401
- { 204, 3 },
83402
- { 204, 4 },
83403
- { 206, 2 },
83404
- { 206, 0 },
83405
- { 205, 0 },
83406
- { 205, 3 },
83407
- { 205, 2 },
83408
- { 207, 4 },
83409
- { 207, 0 },
83410
- { 198, 0 },
83411
- { 198, 3 },
83412
- { 210, 4 },
83413
- { 210, 2 },
83414
- { 211, 1 },
83415
- { 173, 1 },
83416
- { 173, 1 },
83417
- { 173, 0 },
83418
- { 196, 0 },
83419
- { 196, 3 },
84446
+ { 204, 0 },
8342084447
{ 197, 0 },
8342184448
{ 197, 2 },
83422
- { 199, 0 },
83423
- { 199, 2 },
83424
- { 199, 4 },
83425
- { 199, 4 },
83426
- { 145, 5 },
83427
- { 195, 0 },
83428
- { 195, 2 },
83429
- { 145, 7 },
83430
- { 213, 5 },
83431
- { 213, 3 },
83432
- { 145, 8 },
83433
- { 145, 5 },
83434
- { 145, 6 },
83435
- { 214, 2 },
84449
+ { 206, 2 },
84450
+ { 206, 0 },
84451
+ { 205, 7 },
84452
+ { 205, 7 },
84453
+ { 205, 7 },
84454
+ { 156, 0 },
84455
+ { 156, 2 },
84456
+ { 192, 2 },
84457
+ { 207, 1 },
84458
+ { 207, 2 },
84459
+ { 207, 3 },
84460
+ { 207, 4 },
84461
+ { 209, 2 },
84462
+ { 209, 0 },
84463
+ { 208, 0 },
84464
+ { 208, 3 },
84465
+ { 208, 2 },
84466
+ { 210, 4 },
84467
+ { 210, 0 },
84468
+ { 201, 0 },
84469
+ { 201, 3 },
84470
+ { 213, 4 },
84471
+ { 213, 2 },
8343684472
{ 214, 1 },
84473
+ { 176, 1 },
84474
+ { 176, 1 },
84475
+ { 176, 0 },
84476
+ { 199, 0 },
84477
+ { 199, 3 },
84478
+ { 200, 0 },
84479
+ { 200, 2 },
84480
+ { 202, 0 },
84481
+ { 202, 2 },
84482
+ { 202, 4 },
84483
+ { 202, 4 },
84484
+ { 147, 5 },
84485
+ { 198, 0 },
84486
+ { 198, 2 },
84487
+ { 147, 7 },
84488
+ { 216, 5 },
8343784489
{ 216, 3 },
83438
- { 216, 1 },
83439
- { 215, 0 },
83440
- { 215, 3 },
83441
- { 209, 3 },
83442
- { 209, 1 },
83443
- { 171, 1 },
83444
- { 171, 3 },
83445
- { 170, 1 },
83446
- { 171, 1 },
83447
- { 171, 1 },
83448
- { 171, 3 },
83449
- { 171, 5 },
83450
- { 170, 1 },
83451
- { 170, 1 },
83452
- { 171, 1 },
83453
- { 171, 1 },
83454
- { 171, 3 },
83455
- { 171, 6 },
83456
- { 171, 5 },
83457
- { 171, 4 },
83458
- { 170, 1 },
83459
- { 171, 3 },
83460
- { 171, 3 },
83461
- { 171, 3 },
83462
- { 171, 3 },
83463
- { 171, 3 },
83464
- { 171, 3 },
83465
- { 171, 3 },
83466
- { 171, 3 },
83467
- { 218, 1 },
83468
- { 218, 2 },
83469
- { 218, 1 },
83470
- { 218, 2 },
83471
- { 219, 2 },
83472
- { 219, 0 },
83473
- { 171, 4 },
83474
- { 171, 2 },
83475
- { 171, 3 },
83476
- { 171, 3 },
83477
- { 171, 4 },
83478
- { 171, 2 },
83479
- { 171, 2 },
83480
- { 171, 2 },
83481
- { 171, 2 },
83482
- { 220, 1 },
83483
- { 220, 2 },
83484
- { 171, 5 },
84490
+ { 147, 8 },
84491
+ { 147, 5 },
84492
+ { 147, 6 },
84493
+ { 217, 2 },
84494
+ { 217, 1 },
84495
+ { 219, 3 },
84496
+ { 219, 1 },
84497
+ { 218, 0 },
84498
+ { 218, 3 },
84499
+ { 212, 3 },
84500
+ { 212, 1 },
84501
+ { 174, 1 },
84502
+ { 174, 3 },
84503
+ { 173, 1 },
84504
+ { 174, 1 },
84505
+ { 174, 1 },
84506
+ { 174, 3 },
84507
+ { 174, 5 },
84508
+ { 173, 1 },
84509
+ { 173, 1 },
84510
+ { 174, 1 },
84511
+ { 174, 1 },
84512
+ { 174, 3 },
84513
+ { 174, 6 },
84514
+ { 174, 5 },
84515
+ { 174, 4 },
84516
+ { 173, 1 },
84517
+ { 174, 3 },
84518
+ { 174, 3 },
84519
+ { 174, 3 },
84520
+ { 174, 3 },
84521
+ { 174, 3 },
84522
+ { 174, 3 },
84523
+ { 174, 3 },
84524
+ { 174, 3 },
84525
+ { 221, 1 },
84526
+ { 221, 2 },
8348584527
{ 221, 1 },
8348684528
{ 221, 2 },
83487
- { 171, 5 },
83488
- { 171, 3 },
83489
- { 171, 5 },
83490
- { 171, 4 },
83491
- { 171, 4 },
83492
- { 171, 5 },
83493
- { 223, 5 },
83494
- { 223, 4 },
84529
+ { 222, 2 },
84530
+ { 222, 0 },
84531
+ { 174, 4 },
84532
+ { 174, 2 },
84533
+ { 174, 3 },
84534
+ { 174, 3 },
84535
+ { 174, 4 },
84536
+ { 174, 2 },
84537
+ { 174, 2 },
84538
+ { 174, 2 },
84539
+ { 174, 2 },
84540
+ { 223, 1 },
84541
+ { 223, 2 },
84542
+ { 174, 5 },
84543
+ { 224, 1 },
8349584544
{ 224, 2 },
83496
- { 224, 0 },
83497
- { 222, 1 },
83498
- { 222, 0 },
83499
- { 217, 1 },
83500
- { 217, 0 },
83501
- { 212, 3 },
83502
- { 212, 1 },
83503
- { 145, 11 },
84545
+ { 174, 5 },
84546
+ { 174, 3 },
84547
+ { 174, 5 },
84548
+ { 174, 4 },
84549
+ { 174, 4 },
84550
+ { 174, 5 },
84551
+ { 226, 5 },
84552
+ { 226, 4 },
84553
+ { 227, 2 },
84554
+ { 227, 0 },
8350484555
{ 225, 1 },
8350584556
{ 225, 0 },
83506
- { 175, 0 },
83507
- { 175, 3 },
83508
- { 183, 5 },
83509
- { 183, 3 },
83510
- { 226, 0 },
83511
- { 226, 2 },
83512
- { 145, 4 },
83513
- { 145, 1 },
83514
- { 145, 2 },
83515
- { 145, 5 },
83516
- { 145, 5 },
83517
- { 145, 5 },
83518
- { 145, 5 },
83519
- { 145, 6 },
83520
- { 145, 3 },
83521
- { 227, 1 },
83522
- { 227, 1 },
83523
- { 166, 2 },
83524
- { 167, 2 },
83525
- { 229, 1 },
84557
+ { 220, 1 },
84558
+ { 220, 0 },
84559
+ { 215, 3 },
84560
+ { 215, 1 },
84561
+ { 147, 11 },
8352684562
{ 228, 1 },
8352784563
{ 228, 0 },
83528
- { 145, 5 },
83529
- { 230, 11 },
83530
- { 232, 1 },
83531
- { 232, 1 },
83532
- { 232, 2 },
83533
- { 232, 0 },
83534
- { 233, 1 },
83535
- { 233, 1 },
83536
- { 233, 3 },
83537
- { 234, 0 },
83538
- { 234, 3 },
83539
- { 235, 0 },
84564
+ { 178, 0 },
84565
+ { 178, 3 },
84566
+ { 186, 5 },
84567
+ { 186, 3 },
84568
+ { 229, 0 },
84569
+ { 229, 2 },
84570
+ { 147, 4 },
84571
+ { 147, 1 },
84572
+ { 147, 2 },
84573
+ { 147, 5 },
84574
+ { 147, 5 },
84575
+ { 147, 5 },
84576
+ { 147, 5 },
84577
+ { 147, 6 },
84578
+ { 147, 3 },
84579
+ { 230, 1 },
84580
+ { 230, 1 },
84581
+ { 169, 2 },
84582
+ { 170, 2 },
84583
+ { 232, 1 },
84584
+ { 231, 1 },
84585
+ { 231, 0 },
84586
+ { 147, 5 },
84587
+ { 233, 11 },
84588
+ { 235, 1 },
84589
+ { 235, 1 },
8354084590
{ 235, 2 },
83541
- { 231, 3 },
83542
- { 231, 2 },
83543
- { 236, 6 },
83544
- { 236, 8 },
83545
- { 236, 5 },
83546
- { 236, 4 },
84591
+ { 235, 0 },
84592
+ { 236, 1 },
8354784593
{ 236, 1 },
83548
- { 171, 4 },
83549
- { 171, 6 },
83550
- { 187, 1 },
83551
- { 187, 1 },
83552
- { 187, 1 },
83553
- { 145, 4 },
83554
- { 145, 6 },
83555
- { 145, 3 },
84594
+ { 236, 3 },
84595
+ { 237, 0 },
84596
+ { 237, 3 },
8355684597
{ 238, 0 },
8355784598
{ 238, 2 },
83558
- { 237, 1 },
83559
- { 237, 0 },
83560
- { 145, 1 },
83561
- { 145, 3 },
83562
- { 145, 1 },
83563
- { 145, 3 },
83564
- { 145, 6 },
83565
- { 145, 6 },
84599
+ { 234, 3 },
84600
+ { 234, 2 },
84601
+ { 239, 6 },
84602
+ { 239, 8 },
84603
+ { 239, 5 },
84604
+ { 239, 4 },
8356684605
{ 239, 1 },
83567
- { 240, 0 },
84606
+ { 174, 4 },
84607
+ { 174, 6 },
84608
+ { 190, 1 },
84609
+ { 190, 1 },
84610
+ { 190, 1 },
84611
+ { 147, 4 },
84612
+ { 147, 6 },
84613
+ { 147, 3 },
84614
+ { 241, 0 },
84615
+ { 241, 2 },
8356884616
{ 240, 1 },
83569
- { 145, 1 },
83570
- { 145, 4 },
83571
- { 241, 7 },
84617
+ { 240, 0 },
84618
+ { 147, 1 },
84619
+ { 147, 3 },
84620
+ { 147, 1 },
84621
+ { 147, 3 },
84622
+ { 147, 6 },
84623
+ { 147, 6 },
8357284624
{ 242, 1 },
83573
- { 242, 3 },
8357484625
{ 243, 0 },
83575
- { 243, 2 },
83576
- { 244, 1 },
83577
- { 244, 3 },
84626
+ { 243, 1 },
84627
+ { 147, 1 },
84628
+ { 147, 4 },
84629
+ { 244, 7 },
8357884630
{ 245, 1 },
84631
+ { 245, 3 },
8357984632
{ 246, 0 },
8358084633
{ 246, 2 },
84634
+ { 247, 1 },
84635
+ { 247, 3 },
84636
+ { 248, 1 },
84637
+ { 249, 0 },
84638
+ { 249, 2 },
8358184639
};
8358284640
8358384641
static void yy_accept(yyParser*); /* Forward Declaration */
8358484642
8358584643
/*
@@ -83638,37 +84696,39 @@
8363884696
case 3: /* ecmd ::= SEMI */
8363984697
case 4: /* ecmd ::= explain cmdx SEMI */
8364084698
case 10: /* trans_opt ::= */
8364184699
case 11: /* trans_opt ::= TRANSACTION */
8364284700
case 12: /* trans_opt ::= TRANSACTION nm */
83643
- case 20: /* cmd ::= create_table create_table_args */
83644
- case 28: /* columnlist ::= columnlist COMMA column */
83645
- case 29: /* columnlist ::= column */
83646
- case 37: /* type ::= */
83647
- case 44: /* signed ::= plus_num */
83648
- case 45: /* signed ::= minus_num */
83649
- case 46: /* carglist ::= carglist carg */
83650
- case 47: /* carglist ::= */
83651
- case 48: /* carg ::= CONSTRAINT nm ccons */
83652
- case 49: /* carg ::= ccons */
83653
- case 55: /* ccons ::= NULL onconf */
83654
- case 82: /* conslist ::= conslist COMMA tcons */
83655
- case 83: /* conslist ::= conslist tcons */
83656
- case 84: /* conslist ::= tcons */
83657
- case 85: /* tcons ::= CONSTRAINT nm */
83658
- case 259: /* plus_opt ::= PLUS */
83659
- case 260: /* plus_opt ::= */
83660
- case 270: /* foreach_clause ::= */
83661
- case 271: /* foreach_clause ::= FOR EACH ROW */
83662
- case 291: /* database_kw_opt ::= DATABASE */
83663
- case 292: /* database_kw_opt ::= */
83664
- case 300: /* kwcolumn_opt ::= */
83665
- case 301: /* kwcolumn_opt ::= COLUMNKW */
83666
- case 305: /* vtabarglist ::= vtabarg */
83667
- case 306: /* vtabarglist ::= vtabarglist COMMA vtabarg */
83668
- case 308: /* vtabarg ::= vtabarg vtabargtoken */
83669
- case 312: /* anylist ::= */
84701
+ case 20: /* savepoint_opt ::= SAVEPOINT */
84702
+ case 21: /* savepoint_opt ::= */
84703
+ case 25: /* cmd ::= create_table create_table_args */
84704
+ case 33: /* columnlist ::= columnlist COMMA column */
84705
+ case 34: /* columnlist ::= column */
84706
+ case 42: /* type ::= */
84707
+ case 49: /* signed ::= plus_num */
84708
+ case 50: /* signed ::= minus_num */
84709
+ case 51: /* carglist ::= carglist carg */
84710
+ case 52: /* carglist ::= */
84711
+ case 53: /* carg ::= CONSTRAINT nm ccons */
84712
+ case 54: /* carg ::= ccons */
84713
+ case 60: /* ccons ::= NULL onconf */
84714
+ case 87: /* conslist ::= conslist COMMA tcons */
84715
+ case 88: /* conslist ::= conslist tcons */
84716
+ case 89: /* conslist ::= tcons */
84717
+ case 90: /* tcons ::= CONSTRAINT nm */
84718
+ case 264: /* plus_opt ::= PLUS */
84719
+ case 265: /* plus_opt ::= */
84720
+ case 275: /* foreach_clause ::= */
84721
+ case 276: /* foreach_clause ::= FOR EACH ROW */
84722
+ case 296: /* database_kw_opt ::= DATABASE */
84723
+ case 297: /* database_kw_opt ::= */
84724
+ case 305: /* kwcolumn_opt ::= */
84725
+ case 306: /* kwcolumn_opt ::= COLUMNKW */
84726
+ case 310: /* vtabarglist ::= vtabarg */
84727
+ case 311: /* vtabarglist ::= vtabarglist COMMA vtabarg */
84728
+ case 313: /* vtabarg ::= vtabarg vtabargtoken */
84729
+ case 317: /* anylist ::= */
8367084730
{
8367184731
}
8367284732
break;
8367384733
case 5: /* explain ::= */
8367484734
{ sqlite3BeginParse(pParse, 0); }
@@ -83681,953 +84741,968 @@
8368184741
break;
8368284742
case 8: /* cmdx ::= cmd */
8368384743
{ sqlite3FinishCoding(pParse); }
8368484744
break;
8368584745
case 9: /* cmd ::= BEGIN transtype trans_opt */
83686
-{sqlite3BeginTransaction(pParse, yymsp[-1].minor.yy46);}
84746
+{sqlite3BeginTransaction(pParse, yymsp[-1].minor.yy392);}
8368784747
break;
8368884748
case 13: /* transtype ::= */
83689
-{yygotominor.yy46 = TK_DEFERRED;}
84749
+{yygotominor.yy392 = TK_DEFERRED;}
8369084750
break;
8369184751
case 14: /* transtype ::= DEFERRED */
8369284752
case 15: /* transtype ::= IMMEDIATE */
8369384753
case 16: /* transtype ::= EXCLUSIVE */
83694
- case 107: /* multiselect_op ::= UNION */
83695
- case 109: /* multiselect_op ::= EXCEPT|INTERSECT */
83696
-{yygotominor.yy46 = yymsp[0].major;}
84754
+ case 112: /* multiselect_op ::= UNION */
84755
+ case 114: /* multiselect_op ::= EXCEPT|INTERSECT */
84756
+{yygotominor.yy392 = yymsp[0].major;}
8369784757
break;
8369884758
case 17: /* cmd ::= COMMIT trans_opt */
8369984759
case 18: /* cmd ::= END trans_opt */
8370084760
{sqlite3CommitTransaction(pParse);}
8370184761
break;
8370284762
case 19: /* cmd ::= ROLLBACK trans_opt */
8370384763
{sqlite3RollbackTransaction(pParse);}
8370484764
break;
83705
- case 21: /* create_table ::= CREATE temp TABLE ifnotexists nm dbnm */
83706
-{
83707
- sqlite3StartTable(pParse,&yymsp[-1].minor.yy0,&yymsp[0].minor.yy0,yymsp[-4].minor.yy46,0,0,yymsp[-2].minor.yy46);
83708
-}
83709
- break;
83710
- case 22: /* ifnotexists ::= */
83711
- case 25: /* temp ::= */
83712
- case 63: /* autoinc ::= */
83713
- case 77: /* init_deferred_pred_opt ::= */
83714
- case 79: /* init_deferred_pred_opt ::= INITIALLY IMMEDIATE */
83715
- case 90: /* defer_subclause_opt ::= */
83716
- case 101: /* ifexists ::= */
83717
- case 112: /* distinct ::= ALL */
83718
- case 113: /* distinct ::= */
83719
- case 215: /* between_op ::= BETWEEN */
83720
- case 218: /* in_op ::= IN */
83721
-{yygotominor.yy46 = 0;}
83722
- break;
83723
- case 23: /* ifnotexists ::= IF NOT EXISTS */
83724
- case 24: /* temp ::= TEMP */
83725
- case 64: /* autoinc ::= AUTOINCR */
83726
- case 78: /* init_deferred_pred_opt ::= INITIALLY DEFERRED */
83727
- case 100: /* ifexists ::= IF EXISTS */
83728
- case 111: /* distinct ::= DISTINCT */
83729
- case 216: /* between_op ::= NOT BETWEEN */
83730
- case 219: /* in_op ::= NOT IN */
83731
-{yygotominor.yy46 = 1;}
83732
- break;
83733
- case 26: /* create_table_args ::= LP columnlist conslist_opt RP */
84765
+ case 22: /* cmd ::= SAVEPOINT nm */
84766
+{
84767
+ sqlite3Savepoint(pParse, SAVEPOINT_BEGIN, &yymsp[0].minor.yy0);
84768
+}
84769
+ break;
84770
+ case 23: /* cmd ::= RELEASE savepoint_opt nm */
84771
+{
84772
+ sqlite3Savepoint(pParse, SAVEPOINT_RELEASE, &yymsp[0].minor.yy0);
84773
+}
84774
+ break;
84775
+ case 24: /* cmd ::= ROLLBACK trans_opt TO savepoint_opt nm */
84776
+{
84777
+ sqlite3Savepoint(pParse, SAVEPOINT_ROLLBACK, &yymsp[0].minor.yy0);
84778
+}
84779
+ break;
84780
+ case 26: /* create_table ::= CREATE temp TABLE ifnotexists nm dbnm */
84781
+{
84782
+ sqlite3StartTable(pParse,&yymsp[-1].minor.yy0,&yymsp[0].minor.yy0,yymsp[-4].minor.yy392,0,0,yymsp[-2].minor.yy392);
84783
+}
84784
+ break;
84785
+ case 27: /* ifnotexists ::= */
84786
+ case 30: /* temp ::= */
84787
+ case 68: /* autoinc ::= */
84788
+ case 82: /* init_deferred_pred_opt ::= */
84789
+ case 84: /* init_deferred_pred_opt ::= INITIALLY IMMEDIATE */
84790
+ case 95: /* defer_subclause_opt ::= */
84791
+ case 106: /* ifexists ::= */
84792
+ case 117: /* distinct ::= ALL */
84793
+ case 118: /* distinct ::= */
84794
+ case 220: /* between_op ::= BETWEEN */
84795
+ case 223: /* in_op ::= IN */
84796
+{yygotominor.yy392 = 0;}
84797
+ break;
84798
+ case 28: /* ifnotexists ::= IF NOT EXISTS */
84799
+ case 29: /* temp ::= TEMP */
84800
+ case 69: /* autoinc ::= AUTOINCR */
84801
+ case 83: /* init_deferred_pred_opt ::= INITIALLY DEFERRED */
84802
+ case 105: /* ifexists ::= IF EXISTS */
84803
+ case 116: /* distinct ::= DISTINCT */
84804
+ case 221: /* between_op ::= NOT BETWEEN */
84805
+ case 224: /* in_op ::= NOT IN */
84806
+{yygotominor.yy392 = 1;}
84807
+ break;
84808
+ case 31: /* create_table_args ::= LP columnlist conslist_opt RP */
8373484809
{
8373584810
sqlite3EndTable(pParse,&yymsp[-1].minor.yy0,&yymsp[0].minor.yy0,0);
8373684811
}
8373784812
break;
83738
- case 27: /* create_table_args ::= AS select */
84813
+ case 32: /* create_table_args ::= AS select */
8373984814
{
83740
- sqlite3EndTable(pParse,0,0,yymsp[0].minor.yy219);
83741
- sqlite3SelectDelete(pParse->db, yymsp[0].minor.yy219);
84815
+ sqlite3EndTable(pParse,0,0,yymsp[0].minor.yy159);
84816
+ sqlite3SelectDelete(pParse->db, yymsp[0].minor.yy159);
8374284817
}
8374384818
break;
83744
- case 30: /* column ::= columnid type carglist */
84819
+ case 35: /* column ::= columnid type carglist */
8374584820
{
8374684821
yygotominor.yy0.z = yymsp[-2].minor.yy0.z;
8374784822
yygotominor.yy0.n = (int)(pParse->sLastToken.z-yymsp[-2].minor.yy0.z) + pParse->sLastToken.n;
8374884823
}
8374984824
break;
83750
- case 31: /* columnid ::= nm */
84825
+ case 36: /* columnid ::= nm */
8375184826
{
8375284827
sqlite3AddColumn(pParse,&yymsp[0].minor.yy0);
8375384828
yygotominor.yy0 = yymsp[0].minor.yy0;
8375484829
}
8375584830
break;
83756
- case 32: /* id ::= ID */
83757
- case 33: /* ids ::= ID|STRING */
83758
- case 34: /* nm ::= ID */
83759
- case 35: /* nm ::= STRING */
83760
- case 36: /* nm ::= JOIN_KW */
83761
- case 39: /* typetoken ::= typename */
83762
- case 42: /* typename ::= ids */
83763
- case 119: /* as ::= AS nm */
83764
- case 120: /* as ::= ids */
83765
- case 130: /* dbnm ::= DOT nm */
83766
- case 139: /* indexed_opt ::= INDEXED BY nm */
83767
- case 244: /* collate ::= COLLATE ids */
83768
- case 254: /* nmnum ::= plus_num */
83769
- case 255: /* nmnum ::= nm */
83770
- case 256: /* plus_num ::= plus_opt number */
83771
- case 257: /* minus_num ::= MINUS number */
83772
- case 258: /* number ::= INTEGER|FLOAT */
84831
+ case 37: /* id ::= ID */
84832
+ case 38: /* ids ::= ID|STRING */
84833
+ case 39: /* nm ::= ID */
84834
+ case 40: /* nm ::= STRING */
84835
+ case 41: /* nm ::= JOIN_KW */
84836
+ case 44: /* typetoken ::= typename */
84837
+ case 47: /* typename ::= ids */
84838
+ case 124: /* as ::= AS nm */
84839
+ case 125: /* as ::= ids */
84840
+ case 135: /* dbnm ::= DOT nm */
84841
+ case 144: /* indexed_opt ::= INDEXED BY nm */
84842
+ case 249: /* collate ::= COLLATE ids */
84843
+ case 259: /* nmnum ::= plus_num */
84844
+ case 260: /* nmnum ::= nm */
84845
+ case 261: /* plus_num ::= plus_opt number */
84846
+ case 262: /* minus_num ::= MINUS number */
84847
+ case 263: /* number ::= INTEGER|FLOAT */
8377384848
{yygotominor.yy0 = yymsp[0].minor.yy0;}
8377484849
break;
83775
- case 38: /* type ::= typetoken */
84850
+ case 43: /* type ::= typetoken */
8377684851
{sqlite3AddColumnType(pParse,&yymsp[0].minor.yy0);}
8377784852
break;
83778
- case 40: /* typetoken ::= typename LP signed RP */
84853
+ case 45: /* typetoken ::= typename LP signed RP */
8377984854
{
8378084855
yygotominor.yy0.z = yymsp[-3].minor.yy0.z;
8378184856
yygotominor.yy0.n = (int)(&yymsp[0].minor.yy0.z[yymsp[0].minor.yy0.n] - yymsp[-3].minor.yy0.z);
8378284857
}
8378384858
break;
83784
- case 41: /* typetoken ::= typename LP signed COMMA signed RP */
84859
+ case 46: /* typetoken ::= typename LP signed COMMA signed RP */
8378584860
{
8378684861
yygotominor.yy0.z = yymsp[-5].minor.yy0.z;
8378784862
yygotominor.yy0.n = (int)(&yymsp[0].minor.yy0.z[yymsp[0].minor.yy0.n] - yymsp[-5].minor.yy0.z);
8378884863
}
8378984864
break;
83790
- case 43: /* typename ::= typename ids */
84865
+ case 48: /* typename ::= typename ids */
8379184866
{yygotominor.yy0.z=yymsp[-1].minor.yy0.z; yygotominor.yy0.n=yymsp[0].minor.yy0.n+(int)(yymsp[0].minor.yy0.z-yymsp[-1].minor.yy0.z);}
8379284867
break;
83793
- case 50: /* ccons ::= DEFAULT term */
83794
- case 52: /* ccons ::= DEFAULT PLUS term */
83795
-{sqlite3AddDefaultValue(pParse,yymsp[0].minor.yy172);}
83796
- break;
83797
- case 51: /* ccons ::= DEFAULT LP expr RP */
83798
-{sqlite3AddDefaultValue(pParse,yymsp[-1].minor.yy172);}
83799
- break;
83800
- case 53: /* ccons ::= DEFAULT MINUS term */
83801
-{
83802
- Expr *p = sqlite3PExpr(pParse, TK_UMINUS, yymsp[0].minor.yy172, 0, 0);
83803
- sqlite3ExprSpan(p,&yymsp[-1].minor.yy0,&yymsp[0].minor.yy172->span);
84868
+ case 55: /* ccons ::= DEFAULT term */
84869
+ case 57: /* ccons ::= DEFAULT PLUS term */
84870
+{sqlite3AddDefaultValue(pParse,yymsp[0].minor.yy122);}
84871
+ break;
84872
+ case 56: /* ccons ::= DEFAULT LP expr RP */
84873
+{sqlite3AddDefaultValue(pParse,yymsp[-1].minor.yy122);}
84874
+ break;
84875
+ case 58: /* ccons ::= DEFAULT MINUS term */
84876
+{
84877
+ Expr *p = sqlite3PExpr(pParse, TK_UMINUS, yymsp[0].minor.yy122, 0, 0);
84878
+ sqlite3ExprSpan(p,&yymsp[-1].minor.yy0,&yymsp[0].minor.yy122->span);
8380484879
sqlite3AddDefaultValue(pParse,p);
8380584880
}
8380684881
break;
83807
- case 54: /* ccons ::= DEFAULT id */
84882
+ case 59: /* ccons ::= DEFAULT id */
8380884883
{
8380984884
Expr *p = sqlite3PExpr(pParse, TK_STRING, 0, 0, &yymsp[0].minor.yy0);
8381084885
sqlite3AddDefaultValue(pParse,p);
8381184886
}
8381284887
break;
83813
- case 56: /* ccons ::= NOT NULL onconf */
83814
-{sqlite3AddNotNull(pParse, yymsp[0].minor.yy46);}
83815
- break;
83816
- case 57: /* ccons ::= PRIMARY KEY sortorder onconf autoinc */
83817
-{sqlite3AddPrimaryKey(pParse,0,yymsp[-1].minor.yy46,yymsp[0].minor.yy46,yymsp[-2].minor.yy46);}
83818
- break;
83819
- case 58: /* ccons ::= UNIQUE onconf */
83820
-{sqlite3CreateIndex(pParse,0,0,0,0,yymsp[0].minor.yy46,0,0,0,0);}
83821
- break;
83822
- case 59: /* ccons ::= CHECK LP expr RP */
83823
-{sqlite3AddCheckConstraint(pParse,yymsp[-1].minor.yy172);}
83824
- break;
83825
- case 60: /* ccons ::= REFERENCES nm idxlist_opt refargs */
83826
-{sqlite3CreateForeignKey(pParse,0,&yymsp[-2].minor.yy0,yymsp[-1].minor.yy174,yymsp[0].minor.yy46);}
83827
- break;
83828
- case 61: /* ccons ::= defer_subclause */
83829
-{sqlite3DeferForeignKey(pParse,yymsp[0].minor.yy46);}
83830
- break;
83831
- case 62: /* ccons ::= COLLATE ids */
84888
+ case 61: /* ccons ::= NOT NULL onconf */
84889
+{sqlite3AddNotNull(pParse, yymsp[0].minor.yy392);}
84890
+ break;
84891
+ case 62: /* ccons ::= PRIMARY KEY sortorder onconf autoinc */
84892
+{sqlite3AddPrimaryKey(pParse,0,yymsp[-1].minor.yy392,yymsp[0].minor.yy392,yymsp[-2].minor.yy392);}
84893
+ break;
84894
+ case 63: /* ccons ::= UNIQUE onconf */
84895
+{sqlite3CreateIndex(pParse,0,0,0,0,yymsp[0].minor.yy392,0,0,0,0);}
84896
+ break;
84897
+ case 64: /* ccons ::= CHECK LP expr RP */
84898
+{sqlite3AddCheckConstraint(pParse,yymsp[-1].minor.yy122);}
84899
+ break;
84900
+ case 65: /* ccons ::= REFERENCES nm idxlist_opt refargs */
84901
+{sqlite3CreateForeignKey(pParse,0,&yymsp[-2].minor.yy0,yymsp[-1].minor.yy442,yymsp[0].minor.yy392);}
84902
+ break;
84903
+ case 66: /* ccons ::= defer_subclause */
84904
+{sqlite3DeferForeignKey(pParse,yymsp[0].minor.yy392);}
84905
+ break;
84906
+ case 67: /* ccons ::= COLLATE ids */
8383284907
{sqlite3AddCollateType(pParse, &yymsp[0].minor.yy0);}
8383384908
break;
83834
- case 65: /* refargs ::= */
83835
-{ yygotominor.yy46 = OE_Restrict * 0x010101; }
83836
- break;
83837
- case 66: /* refargs ::= refargs refarg */
83838
-{ yygotominor.yy46 = (yymsp[-1].minor.yy46 & ~yymsp[0].minor.yy405.mask) | yymsp[0].minor.yy405.value; }
83839
- break;
83840
- case 67: /* refarg ::= MATCH nm */
83841
-{ yygotominor.yy405.value = 0; yygotominor.yy405.mask = 0x000000; }
83842
- break;
83843
- case 68: /* refarg ::= ON DELETE refact */
83844
-{ yygotominor.yy405.value = yymsp[0].minor.yy46; yygotominor.yy405.mask = 0x0000ff; }
83845
- break;
83846
- case 69: /* refarg ::= ON UPDATE refact */
83847
-{ yygotominor.yy405.value = yymsp[0].minor.yy46<<8; yygotominor.yy405.mask = 0x00ff00; }
83848
- break;
83849
- case 70: /* refarg ::= ON INSERT refact */
83850
-{ yygotominor.yy405.value = yymsp[0].minor.yy46<<16; yygotominor.yy405.mask = 0xff0000; }
83851
- break;
83852
- case 71: /* refact ::= SET NULL */
83853
-{ yygotominor.yy46 = OE_SetNull; }
83854
- break;
83855
- case 72: /* refact ::= SET DEFAULT */
83856
-{ yygotominor.yy46 = OE_SetDflt; }
83857
- break;
83858
- case 73: /* refact ::= CASCADE */
83859
-{ yygotominor.yy46 = OE_Cascade; }
83860
- break;
83861
- case 74: /* refact ::= RESTRICT */
83862
-{ yygotominor.yy46 = OE_Restrict; }
83863
- break;
83864
- case 75: /* defer_subclause ::= NOT DEFERRABLE init_deferred_pred_opt */
83865
- case 76: /* defer_subclause ::= DEFERRABLE init_deferred_pred_opt */
83866
- case 91: /* defer_subclause_opt ::= defer_subclause */
83867
- case 93: /* onconf ::= ON CONFLICT resolvetype */
83868
- case 95: /* orconf ::= OR resolvetype */
83869
- case 96: /* resolvetype ::= raisetype */
83870
- case 168: /* insert_cmd ::= INSERT orconf */
83871
-{yygotominor.yy46 = yymsp[0].minor.yy46;}
83872
- break;
83873
- case 80: /* conslist_opt ::= */
84909
+ case 70: /* refargs ::= */
84910
+{ yygotominor.yy392 = OE_Restrict * 0x010101; }
84911
+ break;
84912
+ case 71: /* refargs ::= refargs refarg */
84913
+{ yygotominor.yy392 = (yymsp[-1].minor.yy392 & ~yymsp[0].minor.yy207.mask) | yymsp[0].minor.yy207.value; }
84914
+ break;
84915
+ case 72: /* refarg ::= MATCH nm */
84916
+{ yygotominor.yy207.value = 0; yygotominor.yy207.mask = 0x000000; }
84917
+ break;
84918
+ case 73: /* refarg ::= ON DELETE refact */
84919
+{ yygotominor.yy207.value = yymsp[0].minor.yy392; yygotominor.yy207.mask = 0x0000ff; }
84920
+ break;
84921
+ case 74: /* refarg ::= ON UPDATE refact */
84922
+{ yygotominor.yy207.value = yymsp[0].minor.yy392<<8; yygotominor.yy207.mask = 0x00ff00; }
84923
+ break;
84924
+ case 75: /* refarg ::= ON INSERT refact */
84925
+{ yygotominor.yy207.value = yymsp[0].minor.yy392<<16; yygotominor.yy207.mask = 0xff0000; }
84926
+ break;
84927
+ case 76: /* refact ::= SET NULL */
84928
+{ yygotominor.yy392 = OE_SetNull; }
84929
+ break;
84930
+ case 77: /* refact ::= SET DEFAULT */
84931
+{ yygotominor.yy392 = OE_SetDflt; }
84932
+ break;
84933
+ case 78: /* refact ::= CASCADE */
84934
+{ yygotominor.yy392 = OE_Cascade; }
84935
+ break;
84936
+ case 79: /* refact ::= RESTRICT */
84937
+{ yygotominor.yy392 = OE_Restrict; }
84938
+ break;
84939
+ case 80: /* defer_subclause ::= NOT DEFERRABLE init_deferred_pred_opt */
84940
+ case 81: /* defer_subclause ::= DEFERRABLE init_deferred_pred_opt */
84941
+ case 96: /* defer_subclause_opt ::= defer_subclause */
84942
+ case 98: /* onconf ::= ON CONFLICT resolvetype */
84943
+ case 100: /* orconf ::= OR resolvetype */
84944
+ case 101: /* resolvetype ::= raisetype */
84945
+ case 173: /* insert_cmd ::= INSERT orconf */
84946
+{yygotominor.yy392 = yymsp[0].minor.yy392;}
84947
+ break;
84948
+ case 85: /* conslist_opt ::= */
8387484949
{yygotominor.yy0.n = 0; yygotominor.yy0.z = 0;}
8387584950
break;
83876
- case 81: /* conslist_opt ::= COMMA conslist */
84951
+ case 86: /* conslist_opt ::= COMMA conslist */
8387784952
{yygotominor.yy0 = yymsp[-1].minor.yy0;}
8387884953
break;
83879
- case 86: /* tcons ::= PRIMARY KEY LP idxlist autoinc RP onconf */
83880
-{sqlite3AddPrimaryKey(pParse,yymsp[-3].minor.yy174,yymsp[0].minor.yy46,yymsp[-2].minor.yy46,0);}
83881
- break;
83882
- case 87: /* tcons ::= UNIQUE LP idxlist RP onconf */
83883
-{sqlite3CreateIndex(pParse,0,0,0,yymsp[-2].minor.yy174,yymsp[0].minor.yy46,0,0,0,0);}
83884
- break;
83885
- case 88: /* tcons ::= CHECK LP expr RP onconf */
83886
-{sqlite3AddCheckConstraint(pParse,yymsp[-2].minor.yy172);}
83887
- break;
83888
- case 89: /* tcons ::= FOREIGN KEY LP idxlist RP REFERENCES nm idxlist_opt refargs defer_subclause_opt */
83889
-{
83890
- sqlite3CreateForeignKey(pParse, yymsp[-6].minor.yy174, &yymsp[-3].minor.yy0, yymsp[-2].minor.yy174, yymsp[-1].minor.yy46);
83891
- sqlite3DeferForeignKey(pParse, yymsp[0].minor.yy46);
83892
-}
83893
- break;
83894
- case 92: /* onconf ::= */
83895
- case 94: /* orconf ::= */
83896
-{yygotominor.yy46 = OE_Default;}
83897
- break;
83898
- case 97: /* resolvetype ::= IGNORE */
83899
-{yygotominor.yy46 = OE_Ignore;}
83900
- break;
83901
- case 98: /* resolvetype ::= REPLACE */
83902
- case 169: /* insert_cmd ::= REPLACE */
83903
-{yygotominor.yy46 = OE_Replace;}
83904
- break;
83905
- case 99: /* cmd ::= DROP TABLE ifexists fullname */
83906
-{
83907
- sqlite3DropTable(pParse, yymsp[0].minor.yy373, 0, yymsp[-1].minor.yy46);
83908
-}
83909
- break;
83910
- case 102: /* cmd ::= CREATE temp VIEW ifnotexists nm dbnm AS select */
83911
-{
83912
- sqlite3CreateView(pParse, &yymsp[-7].minor.yy0, &yymsp[-3].minor.yy0, &yymsp[-2].minor.yy0, yymsp[0].minor.yy219, yymsp[-6].minor.yy46, yymsp[-4].minor.yy46);
83913
-}
83914
- break;
83915
- case 103: /* cmd ::= DROP VIEW ifexists fullname */
83916
-{
83917
- sqlite3DropTable(pParse, yymsp[0].minor.yy373, 1, yymsp[-1].minor.yy46);
83918
-}
83919
- break;
83920
- case 104: /* cmd ::= select */
84954
+ case 91: /* tcons ::= PRIMARY KEY LP idxlist autoinc RP onconf */
84955
+{sqlite3AddPrimaryKey(pParse,yymsp[-3].minor.yy442,yymsp[0].minor.yy392,yymsp[-2].minor.yy392,0);}
84956
+ break;
84957
+ case 92: /* tcons ::= UNIQUE LP idxlist RP onconf */
84958
+{sqlite3CreateIndex(pParse,0,0,0,yymsp[-2].minor.yy442,yymsp[0].minor.yy392,0,0,0,0);}
84959
+ break;
84960
+ case 93: /* tcons ::= CHECK LP expr RP onconf */
84961
+{sqlite3AddCheckConstraint(pParse,yymsp[-2].minor.yy122);}
84962
+ break;
84963
+ case 94: /* tcons ::= FOREIGN KEY LP idxlist RP REFERENCES nm idxlist_opt refargs defer_subclause_opt */
84964
+{
84965
+ sqlite3CreateForeignKey(pParse, yymsp[-6].minor.yy442, &yymsp[-3].minor.yy0, yymsp[-2].minor.yy442, yymsp[-1].minor.yy392);
84966
+ sqlite3DeferForeignKey(pParse, yymsp[0].minor.yy392);
84967
+}
84968
+ break;
84969
+ case 97: /* onconf ::= */
84970
+ case 99: /* orconf ::= */
84971
+{yygotominor.yy392 = OE_Default;}
84972
+ break;
84973
+ case 102: /* resolvetype ::= IGNORE */
84974
+{yygotominor.yy392 = OE_Ignore;}
84975
+ break;
84976
+ case 103: /* resolvetype ::= REPLACE */
84977
+ case 174: /* insert_cmd ::= REPLACE */
84978
+{yygotominor.yy392 = OE_Replace;}
84979
+ break;
84980
+ case 104: /* cmd ::= DROP TABLE ifexists fullname */
84981
+{
84982
+ sqlite3DropTable(pParse, yymsp[0].minor.yy347, 0, yymsp[-1].minor.yy392);
84983
+}
84984
+ break;
84985
+ case 107: /* cmd ::= CREATE temp VIEW ifnotexists nm dbnm AS select */
84986
+{
84987
+ sqlite3CreateView(pParse, &yymsp[-7].minor.yy0, &yymsp[-3].minor.yy0, &yymsp[-2].minor.yy0, yymsp[0].minor.yy159, yymsp[-6].minor.yy392, yymsp[-4].minor.yy392);
84988
+}
84989
+ break;
84990
+ case 108: /* cmd ::= DROP VIEW ifexists fullname */
84991
+{
84992
+ sqlite3DropTable(pParse, yymsp[0].minor.yy347, 1, yymsp[-1].minor.yy392);
84993
+}
84994
+ break;
84995
+ case 109: /* cmd ::= select */
8392184996
{
8392284997
SelectDest dest = {SRT_Output, 0, 0, 0, 0};
83923
- sqlite3Select(pParse, yymsp[0].minor.yy219, &dest);
83924
- sqlite3SelectDelete(pParse->db, yymsp[0].minor.yy219);
83925
-}
83926
- break;
83927
- case 105: /* select ::= oneselect */
83928
-{yygotominor.yy219 = yymsp[0].minor.yy219;}
83929
- break;
83930
- case 106: /* select ::= select multiselect_op oneselect */
83931
-{
83932
- if( yymsp[0].minor.yy219 ){
83933
- yymsp[0].minor.yy219->op = (u8)yymsp[-1].minor.yy46;
83934
- yymsp[0].minor.yy219->pPrior = yymsp[-2].minor.yy219;
84998
+ sqlite3Select(pParse, yymsp[0].minor.yy159, &dest);
84999
+ sqlite3SelectDelete(pParse->db, yymsp[0].minor.yy159);
85000
+}
85001
+ break;
85002
+ case 110: /* select ::= oneselect */
85003
+{yygotominor.yy159 = yymsp[0].minor.yy159;}
85004
+ break;
85005
+ case 111: /* select ::= select multiselect_op oneselect */
85006
+{
85007
+ if( yymsp[0].minor.yy159 ){
85008
+ yymsp[0].minor.yy159->op = (u8)yymsp[-1].minor.yy392;
85009
+ yymsp[0].minor.yy159->pPrior = yymsp[-2].minor.yy159;
8393585010
}else{
83936
- sqlite3SelectDelete(pParse->db, yymsp[-2].minor.yy219);
83937
- }
83938
- yygotominor.yy219 = yymsp[0].minor.yy219;
83939
-}
83940
- break;
83941
- case 108: /* multiselect_op ::= UNION ALL */
83942
-{yygotominor.yy46 = TK_ALL;}
83943
- break;
83944
- case 110: /* oneselect ::= SELECT distinct selcollist from where_opt groupby_opt having_opt orderby_opt limit_opt */
83945
-{
83946
- yygotominor.yy219 = sqlite3SelectNew(pParse,yymsp[-6].minor.yy174,yymsp[-5].minor.yy373,yymsp[-4].minor.yy172,yymsp[-3].minor.yy174,yymsp[-2].minor.yy172,yymsp[-1].minor.yy174,yymsp[-7].minor.yy46,yymsp[0].minor.yy234.pLimit,yymsp[0].minor.yy234.pOffset);
83947
-}
83948
- break;
83949
- case 114: /* sclp ::= selcollist COMMA */
83950
- case 240: /* idxlist_opt ::= LP idxlist RP */
83951
-{yygotominor.yy174 = yymsp[-1].minor.yy174;}
83952
- break;
83953
- case 115: /* sclp ::= */
83954
- case 143: /* orderby_opt ::= */
83955
- case 151: /* groupby_opt ::= */
83956
- case 233: /* exprlist ::= */
83957
- case 239: /* idxlist_opt ::= */
83958
-{yygotominor.yy174 = 0;}
83959
- break;
83960
- case 116: /* selcollist ::= sclp expr as */
83961
-{
83962
- yygotominor.yy174 = sqlite3ExprListAppend(pParse,yymsp[-2].minor.yy174,yymsp[-1].minor.yy172,yymsp[0].minor.yy0.n?&yymsp[0].minor.yy0:0);
83963
-}
83964
- break;
83965
- case 117: /* selcollist ::= sclp STAR */
85011
+ sqlite3SelectDelete(pParse->db, yymsp[-2].minor.yy159);
85012
+ }
85013
+ yygotominor.yy159 = yymsp[0].minor.yy159;
85014
+}
85015
+ break;
85016
+ case 113: /* multiselect_op ::= UNION ALL */
85017
+{yygotominor.yy392 = TK_ALL;}
85018
+ break;
85019
+ case 115: /* oneselect ::= SELECT distinct selcollist from where_opt groupby_opt having_opt orderby_opt limit_opt */
85020
+{
85021
+ yygotominor.yy159 = sqlite3SelectNew(pParse,yymsp[-6].minor.yy442,yymsp[-5].minor.yy347,yymsp[-4].minor.yy122,yymsp[-3].minor.yy442,yymsp[-2].minor.yy122,yymsp[-1].minor.yy442,yymsp[-7].minor.yy392,yymsp[0].minor.yy64.pLimit,yymsp[0].minor.yy64.pOffset);
85022
+}
85023
+ break;
85024
+ case 119: /* sclp ::= selcollist COMMA */
85025
+ case 245: /* idxlist_opt ::= LP idxlist RP */
85026
+{yygotominor.yy442 = yymsp[-1].minor.yy442;}
85027
+ break;
85028
+ case 120: /* sclp ::= */
85029
+ case 148: /* orderby_opt ::= */
85030
+ case 156: /* groupby_opt ::= */
85031
+ case 238: /* exprlist ::= */
85032
+ case 244: /* idxlist_opt ::= */
85033
+{yygotominor.yy442 = 0;}
85034
+ break;
85035
+ case 121: /* selcollist ::= sclp expr as */
85036
+{
85037
+ yygotominor.yy442 = sqlite3ExprListAppend(pParse,yymsp[-2].minor.yy442,yymsp[-1].minor.yy122,yymsp[0].minor.yy0.n?&yymsp[0].minor.yy0:0);
85038
+}
85039
+ break;
85040
+ case 122: /* selcollist ::= sclp STAR */
8396685041
{
8396785042
Expr *p = sqlite3PExpr(pParse, TK_ALL, 0, 0, 0);
83968
- yygotominor.yy174 = sqlite3ExprListAppend(pParse, yymsp[-1].minor.yy174, p, 0);
85043
+ yygotominor.yy442 = sqlite3ExprListAppend(pParse, yymsp[-1].minor.yy442, p, 0);
8396985044
}
8397085045
break;
83971
- case 118: /* selcollist ::= sclp nm DOT STAR */
85046
+ case 123: /* selcollist ::= sclp nm DOT STAR */
8397285047
{
8397385048
Expr *pRight = sqlite3PExpr(pParse, TK_ALL, 0, 0, &yymsp[0].minor.yy0);
8397485049
Expr *pLeft = sqlite3PExpr(pParse, TK_ID, 0, 0, &yymsp[-2].minor.yy0);
8397585050
Expr *pDot = sqlite3PExpr(pParse, TK_DOT, pLeft, pRight, 0);
83976
- yygotominor.yy174 = sqlite3ExprListAppend(pParse,yymsp[-3].minor.yy174, pDot, 0);
85051
+ yygotominor.yy442 = sqlite3ExprListAppend(pParse,yymsp[-3].minor.yy442, pDot, 0);
8397785052
}
8397885053
break;
83979
- case 121: /* as ::= */
85054
+ case 126: /* as ::= */
8398085055
{yygotominor.yy0.n = 0;}
8398185056
break;
83982
- case 122: /* from ::= */
83983
-{yygotominor.yy373 = sqlite3DbMallocZero(pParse->db, sizeof(*yygotominor.yy373));}
83984
- break;
83985
- case 123: /* from ::= FROM seltablist */
83986
-{
83987
- yygotominor.yy373 = yymsp[0].minor.yy373;
83988
- sqlite3SrcListShiftJoinType(yygotominor.yy373);
83989
-}
83990
- break;
83991
- case 124: /* stl_prefix ::= seltablist joinop */
83992
-{
83993
- yygotominor.yy373 = yymsp[-1].minor.yy373;
83994
- if( yygotominor.yy373 && yygotominor.yy373->nSrc>0 ) yygotominor.yy373->a[yygotominor.yy373->nSrc-1].jointype = (u8)yymsp[0].minor.yy46;
83995
-}
83996
- break;
83997
- case 125: /* stl_prefix ::= */
83998
-{yygotominor.yy373 = 0;}
83999
- break;
84000
- case 126: /* seltablist ::= stl_prefix nm dbnm as indexed_opt on_opt using_opt */
84001
-{
84002
- yygotominor.yy373 = sqlite3SrcListAppendFromTerm(pParse,yymsp[-6].minor.yy373,&yymsp[-5].minor.yy0,&yymsp[-4].minor.yy0,&yymsp[-3].minor.yy0,0,yymsp[-1].minor.yy172,yymsp[0].minor.yy432);
84003
- sqlite3SrcListIndexedBy(pParse, yygotominor.yy373, &yymsp[-2].minor.yy0);
84004
-}
84005
- break;
84006
- case 127: /* seltablist ::= stl_prefix LP select RP as on_opt using_opt */
84007
-{
84008
- yygotominor.yy373 = sqlite3SrcListAppendFromTerm(pParse,yymsp[-6].minor.yy373,0,0,&yymsp[-2].minor.yy0,yymsp[-4].minor.yy219,yymsp[-1].minor.yy172,yymsp[0].minor.yy432);
84009
- }
84010
- break;
84011
- case 128: /* seltablist ::= stl_prefix LP seltablist RP as on_opt using_opt */
84012
-{
84013
- if( yymsp[-6].minor.yy373==0 && yymsp[-2].minor.yy0.n==0 && yymsp[-1].minor.yy172==0 && yymsp[0].minor.yy432==0 ){
84014
- yygotominor.yy373 = yymsp[-4].minor.yy373;
85057
+ case 127: /* from ::= */
85058
+{yygotominor.yy347 = sqlite3DbMallocZero(pParse->db, sizeof(*yygotominor.yy347));}
85059
+ break;
85060
+ case 128: /* from ::= FROM seltablist */
85061
+{
85062
+ yygotominor.yy347 = yymsp[0].minor.yy347;
85063
+ sqlite3SrcListShiftJoinType(yygotominor.yy347);
85064
+}
85065
+ break;
85066
+ case 129: /* stl_prefix ::= seltablist joinop */
85067
+{
85068
+ yygotominor.yy347 = yymsp[-1].minor.yy347;
85069
+ if( yygotominor.yy347 && yygotominor.yy347->nSrc>0 ) yygotominor.yy347->a[yygotominor.yy347->nSrc-1].jointype = (u8)yymsp[0].minor.yy392;
85070
+}
85071
+ break;
85072
+ case 130: /* stl_prefix ::= */
85073
+{yygotominor.yy347 = 0;}
85074
+ break;
85075
+ case 131: /* seltablist ::= stl_prefix nm dbnm as indexed_opt on_opt using_opt */
85076
+{
85077
+ yygotominor.yy347 = sqlite3SrcListAppendFromTerm(pParse,yymsp[-6].minor.yy347,&yymsp[-5].minor.yy0,&yymsp[-4].minor.yy0,&yymsp[-3].minor.yy0,0,yymsp[-1].minor.yy122,yymsp[0].minor.yy180);
85078
+ sqlite3SrcListIndexedBy(pParse, yygotominor.yy347, &yymsp[-2].minor.yy0);
85079
+}
85080
+ break;
85081
+ case 132: /* seltablist ::= stl_prefix LP select RP as on_opt using_opt */
85082
+{
85083
+ yygotominor.yy347 = sqlite3SrcListAppendFromTerm(pParse,yymsp[-6].minor.yy347,0,0,&yymsp[-2].minor.yy0,yymsp[-4].minor.yy159,yymsp[-1].minor.yy122,yymsp[0].minor.yy180);
85084
+ }
85085
+ break;
85086
+ case 133: /* seltablist ::= stl_prefix LP seltablist RP as on_opt using_opt */
85087
+{
85088
+ if( yymsp[-6].minor.yy347==0 && yymsp[-2].minor.yy0.n==0 && yymsp[-1].minor.yy122==0 && yymsp[0].minor.yy180==0 ){
85089
+ yygotominor.yy347 = yymsp[-4].minor.yy347;
8401585090
}else{
8401685091
Select *pSubquery;
84017
- sqlite3SrcListShiftJoinType(yymsp[-4].minor.yy373);
84018
- pSubquery = sqlite3SelectNew(pParse,0,yymsp[-4].minor.yy373,0,0,0,0,0,0,0);
84019
- yygotominor.yy373 = sqlite3SrcListAppendFromTerm(pParse,yymsp[-6].minor.yy373,0,0,&yymsp[-2].minor.yy0,pSubquery,yymsp[-1].minor.yy172,yymsp[0].minor.yy432);
85092
+ sqlite3SrcListShiftJoinType(yymsp[-4].minor.yy347);
85093
+ pSubquery = sqlite3SelectNew(pParse,0,yymsp[-4].minor.yy347,0,0,0,0,0,0,0);
85094
+ yygotominor.yy347 = sqlite3SrcListAppendFromTerm(pParse,yymsp[-6].minor.yy347,0,0,&yymsp[-2].minor.yy0,pSubquery,yymsp[-1].minor.yy122,yymsp[0].minor.yy180);
8402085095
}
8402185096
}
8402285097
break;
84023
- case 129: /* dbnm ::= */
84024
- case 138: /* indexed_opt ::= */
85098
+ case 134: /* dbnm ::= */
85099
+ case 143: /* indexed_opt ::= */
8402585100
{yygotominor.yy0.z=0; yygotominor.yy0.n=0;}
8402685101
break;
84027
- case 131: /* fullname ::= nm dbnm */
84028
-{yygotominor.yy373 = sqlite3SrcListAppend(pParse->db,0,&yymsp[-1].minor.yy0,&yymsp[0].minor.yy0);}
84029
- break;
84030
- case 132: /* joinop ::= COMMA|JOIN */
84031
-{ yygotominor.yy46 = JT_INNER; }
84032
- break;
84033
- case 133: /* joinop ::= JOIN_KW JOIN */
84034
-{ yygotominor.yy46 = sqlite3JoinType(pParse,&yymsp[-1].minor.yy0,0,0); }
84035
- break;
84036
- case 134: /* joinop ::= JOIN_KW nm JOIN */
84037
-{ yygotominor.yy46 = sqlite3JoinType(pParse,&yymsp[-2].minor.yy0,&yymsp[-1].minor.yy0,0); }
84038
- break;
84039
- case 135: /* joinop ::= JOIN_KW nm nm JOIN */
84040
-{ yygotominor.yy46 = sqlite3JoinType(pParse,&yymsp[-3].minor.yy0,&yymsp[-2].minor.yy0,&yymsp[-1].minor.yy0); }
84041
- break;
84042
- case 136: /* on_opt ::= ON expr */
84043
- case 147: /* sortitem ::= expr */
84044
- case 154: /* having_opt ::= HAVING expr */
84045
- case 161: /* where_opt ::= WHERE expr */
84046
- case 176: /* expr ::= term */
84047
- case 204: /* escape ::= ESCAPE expr */
84048
- case 228: /* case_else ::= ELSE expr */
84049
- case 230: /* case_operand ::= expr */
84050
-{yygotominor.yy172 = yymsp[0].minor.yy172;}
84051
- break;
84052
- case 137: /* on_opt ::= */
84053
- case 153: /* having_opt ::= */
84054
- case 160: /* where_opt ::= */
84055
- case 205: /* escape ::= */
84056
- case 229: /* case_else ::= */
84057
- case 231: /* case_operand ::= */
84058
-{yygotominor.yy172 = 0;}
84059
- break;
84060
- case 140: /* indexed_opt ::= NOT INDEXED */
85102
+ case 136: /* fullname ::= nm dbnm */
85103
+{yygotominor.yy347 = sqlite3SrcListAppend(pParse->db,0,&yymsp[-1].minor.yy0,&yymsp[0].minor.yy0);}
85104
+ break;
85105
+ case 137: /* joinop ::= COMMA|JOIN */
85106
+{ yygotominor.yy392 = JT_INNER; }
85107
+ break;
85108
+ case 138: /* joinop ::= JOIN_KW JOIN */
85109
+{ yygotominor.yy392 = sqlite3JoinType(pParse,&yymsp[-1].minor.yy0,0,0); }
85110
+ break;
85111
+ case 139: /* joinop ::= JOIN_KW nm JOIN */
85112
+{ yygotominor.yy392 = sqlite3JoinType(pParse,&yymsp[-2].minor.yy0,&yymsp[-1].minor.yy0,0); }
85113
+ break;
85114
+ case 140: /* joinop ::= JOIN_KW nm nm JOIN */
85115
+{ yygotominor.yy392 = sqlite3JoinType(pParse,&yymsp[-3].minor.yy0,&yymsp[-2].minor.yy0,&yymsp[-1].minor.yy0); }
85116
+ break;
85117
+ case 141: /* on_opt ::= ON expr */
85118
+ case 152: /* sortitem ::= expr */
85119
+ case 159: /* having_opt ::= HAVING expr */
85120
+ case 166: /* where_opt ::= WHERE expr */
85121
+ case 181: /* expr ::= term */
85122
+ case 209: /* escape ::= ESCAPE expr */
85123
+ case 233: /* case_else ::= ELSE expr */
85124
+ case 235: /* case_operand ::= expr */
85125
+{yygotominor.yy122 = yymsp[0].minor.yy122;}
85126
+ break;
85127
+ case 142: /* on_opt ::= */
85128
+ case 158: /* having_opt ::= */
85129
+ case 165: /* where_opt ::= */
85130
+ case 210: /* escape ::= */
85131
+ case 234: /* case_else ::= */
85132
+ case 236: /* case_operand ::= */
85133
+{yygotominor.yy122 = 0;}
85134
+ break;
85135
+ case 145: /* indexed_opt ::= NOT INDEXED */
8406185136
{yygotominor.yy0.z=0; yygotominor.yy0.n=1;}
8406285137
break;
84063
- case 141: /* using_opt ::= USING LP inscollist RP */
84064
- case 173: /* inscollist_opt ::= LP inscollist RP */
84065
-{yygotominor.yy432 = yymsp[-1].minor.yy432;}
84066
- break;
84067
- case 142: /* using_opt ::= */
84068
- case 172: /* inscollist_opt ::= */
84069
-{yygotominor.yy432 = 0;}
84070
- break;
84071
- case 144: /* orderby_opt ::= ORDER BY sortlist */
84072
- case 152: /* groupby_opt ::= GROUP BY nexprlist */
84073
- case 232: /* exprlist ::= nexprlist */
84074
-{yygotominor.yy174 = yymsp[0].minor.yy174;}
84075
- break;
84076
- case 145: /* sortlist ::= sortlist COMMA sortitem sortorder */
84077
-{
84078
- yygotominor.yy174 = sqlite3ExprListAppend(pParse,yymsp[-3].minor.yy174,yymsp[-1].minor.yy172,0);
84079
- if( yygotominor.yy174 ) yygotominor.yy174->a[yygotominor.yy174->nExpr-1].sortOrder = (u8)yymsp[0].minor.yy46;
84080
-}
84081
- break;
84082
- case 146: /* sortlist ::= sortitem sortorder */
84083
-{
84084
- yygotominor.yy174 = sqlite3ExprListAppend(pParse,0,yymsp[-1].minor.yy172,0);
84085
- if( yygotominor.yy174 && yygotominor.yy174->a ) yygotominor.yy174->a[0].sortOrder = (u8)yymsp[0].minor.yy46;
84086
-}
84087
- break;
84088
- case 148: /* sortorder ::= ASC */
84089
- case 150: /* sortorder ::= */
84090
-{yygotominor.yy46 = SQLITE_SO_ASC;}
84091
- break;
84092
- case 149: /* sortorder ::= DESC */
84093
-{yygotominor.yy46 = SQLITE_SO_DESC;}
84094
- break;
84095
- case 155: /* limit_opt ::= */
84096
-{yygotominor.yy234.pLimit = 0; yygotominor.yy234.pOffset = 0;}
84097
- break;
84098
- case 156: /* limit_opt ::= LIMIT expr */
84099
-{yygotominor.yy234.pLimit = yymsp[0].minor.yy172; yygotominor.yy234.pOffset = 0;}
84100
- break;
84101
- case 157: /* limit_opt ::= LIMIT expr OFFSET expr */
84102
-{yygotominor.yy234.pLimit = yymsp[-2].minor.yy172; yygotominor.yy234.pOffset = yymsp[0].minor.yy172;}
84103
- break;
84104
- case 158: /* limit_opt ::= LIMIT expr COMMA expr */
84105
-{yygotominor.yy234.pOffset = yymsp[-2].minor.yy172; yygotominor.yy234.pLimit = yymsp[0].minor.yy172;}
84106
- break;
84107
- case 159: /* cmd ::= DELETE FROM fullname indexed_opt where_opt */
84108
-{
84109
- sqlite3SrcListIndexedBy(pParse, yymsp[-2].minor.yy373, &yymsp[-1].minor.yy0);
84110
- sqlite3DeleteFrom(pParse,yymsp[-2].minor.yy373,yymsp[0].minor.yy172);
84111
-}
84112
- break;
84113
- case 162: /* cmd ::= UPDATE orconf fullname indexed_opt SET setlist where_opt */
84114
-{
84115
- sqlite3SrcListIndexedBy(pParse, yymsp[-4].minor.yy373, &yymsp[-3].minor.yy0);
84116
- sqlite3ExprListCheckLength(pParse,yymsp[-1].minor.yy174,"set list");
84117
- sqlite3Update(pParse,yymsp[-4].minor.yy373,yymsp[-1].minor.yy174,yymsp[0].minor.yy172,yymsp[-5].minor.yy46);
84118
-}
84119
- break;
84120
- case 163: /* setlist ::= setlist COMMA nm EQ expr */
84121
-{yygotominor.yy174 = sqlite3ExprListAppend(pParse,yymsp[-4].minor.yy174,yymsp[0].minor.yy172,&yymsp[-2].minor.yy0);}
84122
- break;
84123
- case 164: /* setlist ::= nm EQ expr */
84124
-{yygotominor.yy174 = sqlite3ExprListAppend(pParse,0,yymsp[0].minor.yy172,&yymsp[-2].minor.yy0);}
84125
- break;
84126
- case 165: /* cmd ::= insert_cmd INTO fullname inscollist_opt VALUES LP itemlist RP */
84127
-{sqlite3Insert(pParse, yymsp[-5].minor.yy373, yymsp[-1].minor.yy174, 0, yymsp[-4].minor.yy432, yymsp[-7].minor.yy46);}
84128
- break;
84129
- case 166: /* cmd ::= insert_cmd INTO fullname inscollist_opt select */
84130
-{sqlite3Insert(pParse, yymsp[-2].minor.yy373, 0, yymsp[0].minor.yy219, yymsp[-1].minor.yy432, yymsp[-4].minor.yy46);}
84131
- break;
84132
- case 167: /* cmd ::= insert_cmd INTO fullname inscollist_opt DEFAULT VALUES */
84133
-{sqlite3Insert(pParse, yymsp[-3].minor.yy373, 0, 0, yymsp[-2].minor.yy432, yymsp[-5].minor.yy46);}
84134
- break;
84135
- case 170: /* itemlist ::= itemlist COMMA expr */
84136
- case 234: /* nexprlist ::= nexprlist COMMA expr */
84137
-{yygotominor.yy174 = sqlite3ExprListAppend(pParse,yymsp[-2].minor.yy174,yymsp[0].minor.yy172,0);}
84138
- break;
84139
- case 171: /* itemlist ::= expr */
84140
- case 235: /* nexprlist ::= expr */
84141
-{yygotominor.yy174 = sqlite3ExprListAppend(pParse,0,yymsp[0].minor.yy172,0);}
84142
- break;
84143
- case 174: /* inscollist ::= inscollist COMMA nm */
84144
-{yygotominor.yy432 = sqlite3IdListAppend(pParse->db,yymsp[-2].minor.yy432,&yymsp[0].minor.yy0);}
84145
- break;
84146
- case 175: /* inscollist ::= nm */
84147
-{yygotominor.yy432 = sqlite3IdListAppend(pParse->db,0,&yymsp[0].minor.yy0);}
84148
- break;
84149
- case 177: /* expr ::= LP expr RP */
84150
-{yygotominor.yy172 = yymsp[-1].minor.yy172; sqlite3ExprSpan(yygotominor.yy172,&yymsp[-2].minor.yy0,&yymsp[0].minor.yy0); }
84151
- break;
84152
- case 178: /* term ::= NULL */
84153
- case 183: /* term ::= INTEGER|FLOAT|BLOB */
84154
- case 184: /* term ::= STRING */
84155
-{yygotominor.yy172 = sqlite3PExpr(pParse, yymsp[0].major, 0, 0, &yymsp[0].minor.yy0);}
84156
- break;
84157
- case 179: /* expr ::= ID */
84158
- case 180: /* expr ::= JOIN_KW */
84159
-{yygotominor.yy172 = sqlite3PExpr(pParse, TK_ID, 0, 0, &yymsp[0].minor.yy0);}
84160
- break;
84161
- case 181: /* expr ::= nm DOT nm */
85138
+ case 146: /* using_opt ::= USING LP inscollist RP */
85139
+ case 178: /* inscollist_opt ::= LP inscollist RP */
85140
+{yygotominor.yy180 = yymsp[-1].minor.yy180;}
85141
+ break;
85142
+ case 147: /* using_opt ::= */
85143
+ case 177: /* inscollist_opt ::= */
85144
+{yygotominor.yy180 = 0;}
85145
+ break;
85146
+ case 149: /* orderby_opt ::= ORDER BY sortlist */
85147
+ case 157: /* groupby_opt ::= GROUP BY nexprlist */
85148
+ case 237: /* exprlist ::= nexprlist */
85149
+{yygotominor.yy442 = yymsp[0].minor.yy442;}
85150
+ break;
85151
+ case 150: /* sortlist ::= sortlist COMMA sortitem sortorder */
85152
+{
85153
+ yygotominor.yy442 = sqlite3ExprListAppend(pParse,yymsp[-3].minor.yy442,yymsp[-1].minor.yy122,0);
85154
+ if( yygotominor.yy442 ) yygotominor.yy442->a[yygotominor.yy442->nExpr-1].sortOrder = (u8)yymsp[0].minor.yy392;
85155
+}
85156
+ break;
85157
+ case 151: /* sortlist ::= sortitem sortorder */
85158
+{
85159
+ yygotominor.yy442 = sqlite3ExprListAppend(pParse,0,yymsp[-1].minor.yy122,0);
85160
+ if( yygotominor.yy442 && yygotominor.yy442->a ) yygotominor.yy442->a[0].sortOrder = (u8)yymsp[0].minor.yy392;
85161
+}
85162
+ break;
85163
+ case 153: /* sortorder ::= ASC */
85164
+ case 155: /* sortorder ::= */
85165
+{yygotominor.yy392 = SQLITE_SO_ASC;}
85166
+ break;
85167
+ case 154: /* sortorder ::= DESC */
85168
+{yygotominor.yy392 = SQLITE_SO_DESC;}
85169
+ break;
85170
+ case 160: /* limit_opt ::= */
85171
+{yygotominor.yy64.pLimit = 0; yygotominor.yy64.pOffset = 0;}
85172
+ break;
85173
+ case 161: /* limit_opt ::= LIMIT expr */
85174
+{yygotominor.yy64.pLimit = yymsp[0].minor.yy122; yygotominor.yy64.pOffset = 0;}
85175
+ break;
85176
+ case 162: /* limit_opt ::= LIMIT expr OFFSET expr */
85177
+{yygotominor.yy64.pLimit = yymsp[-2].minor.yy122; yygotominor.yy64.pOffset = yymsp[0].minor.yy122;}
85178
+ break;
85179
+ case 163: /* limit_opt ::= LIMIT expr COMMA expr */
85180
+{yygotominor.yy64.pOffset = yymsp[-2].minor.yy122; yygotominor.yy64.pLimit = yymsp[0].minor.yy122;}
85181
+ break;
85182
+ case 164: /* cmd ::= DELETE FROM fullname indexed_opt where_opt */
85183
+{
85184
+ sqlite3SrcListIndexedBy(pParse, yymsp[-2].minor.yy347, &yymsp[-1].minor.yy0);
85185
+ sqlite3DeleteFrom(pParse,yymsp[-2].minor.yy347,yymsp[0].minor.yy122);
85186
+}
85187
+ break;
85188
+ case 167: /* cmd ::= UPDATE orconf fullname indexed_opt SET setlist where_opt */
85189
+{
85190
+ sqlite3SrcListIndexedBy(pParse, yymsp[-4].minor.yy347, &yymsp[-3].minor.yy0);
85191
+ sqlite3ExprListCheckLength(pParse,yymsp[-1].minor.yy442,"set list");
85192
+ sqlite3Update(pParse,yymsp[-4].minor.yy347,yymsp[-1].minor.yy442,yymsp[0].minor.yy122,yymsp[-5].minor.yy392);
85193
+}
85194
+ break;
85195
+ case 168: /* setlist ::= setlist COMMA nm EQ expr */
85196
+{yygotominor.yy442 = sqlite3ExprListAppend(pParse,yymsp[-4].minor.yy442,yymsp[0].minor.yy122,&yymsp[-2].minor.yy0);}
85197
+ break;
85198
+ case 169: /* setlist ::= nm EQ expr */
85199
+{yygotominor.yy442 = sqlite3ExprListAppend(pParse,0,yymsp[0].minor.yy122,&yymsp[-2].minor.yy0);}
85200
+ break;
85201
+ case 170: /* cmd ::= insert_cmd INTO fullname inscollist_opt VALUES LP itemlist RP */
85202
+{sqlite3Insert(pParse, yymsp[-5].minor.yy347, yymsp[-1].minor.yy442, 0, yymsp[-4].minor.yy180, yymsp[-7].minor.yy392);}
85203
+ break;
85204
+ case 171: /* cmd ::= insert_cmd INTO fullname inscollist_opt select */
85205
+{sqlite3Insert(pParse, yymsp[-2].minor.yy347, 0, yymsp[0].minor.yy159, yymsp[-1].minor.yy180, yymsp[-4].minor.yy392);}
85206
+ break;
85207
+ case 172: /* cmd ::= insert_cmd INTO fullname inscollist_opt DEFAULT VALUES */
85208
+{sqlite3Insert(pParse, yymsp[-3].minor.yy347, 0, 0, yymsp[-2].minor.yy180, yymsp[-5].minor.yy392);}
85209
+ break;
85210
+ case 175: /* itemlist ::= itemlist COMMA expr */
85211
+ case 239: /* nexprlist ::= nexprlist COMMA expr */
85212
+{yygotominor.yy442 = sqlite3ExprListAppend(pParse,yymsp[-2].minor.yy442,yymsp[0].minor.yy122,0);}
85213
+ break;
85214
+ case 176: /* itemlist ::= expr */
85215
+ case 240: /* nexprlist ::= expr */
85216
+{yygotominor.yy442 = sqlite3ExprListAppend(pParse,0,yymsp[0].minor.yy122,0);}
85217
+ break;
85218
+ case 179: /* inscollist ::= inscollist COMMA nm */
85219
+{yygotominor.yy180 = sqlite3IdListAppend(pParse->db,yymsp[-2].minor.yy180,&yymsp[0].minor.yy0);}
85220
+ break;
85221
+ case 180: /* inscollist ::= nm */
85222
+{yygotominor.yy180 = sqlite3IdListAppend(pParse->db,0,&yymsp[0].minor.yy0);}
85223
+ break;
85224
+ case 182: /* expr ::= LP expr RP */
85225
+{yygotominor.yy122 = yymsp[-1].minor.yy122; sqlite3ExprSpan(yygotominor.yy122,&yymsp[-2].minor.yy0,&yymsp[0].minor.yy0); }
85226
+ break;
85227
+ case 183: /* term ::= NULL */
85228
+ case 188: /* term ::= INTEGER|FLOAT|BLOB */
85229
+ case 189: /* term ::= STRING */
85230
+{yygotominor.yy122 = sqlite3PExpr(pParse, yymsp[0].major, 0, 0, &yymsp[0].minor.yy0);}
85231
+ break;
85232
+ case 184: /* expr ::= ID */
85233
+ case 185: /* expr ::= JOIN_KW */
85234
+{yygotominor.yy122 = sqlite3PExpr(pParse, TK_ID, 0, 0, &yymsp[0].minor.yy0);}
85235
+ break;
85236
+ case 186: /* expr ::= nm DOT nm */
8416285237
{
8416385238
Expr *temp1 = sqlite3PExpr(pParse, TK_ID, 0, 0, &yymsp[-2].minor.yy0);
8416485239
Expr *temp2 = sqlite3PExpr(pParse, TK_ID, 0, 0, &yymsp[0].minor.yy0);
84165
- yygotominor.yy172 = sqlite3PExpr(pParse, TK_DOT, temp1, temp2, 0);
85240
+ yygotominor.yy122 = sqlite3PExpr(pParse, TK_DOT, temp1, temp2, 0);
8416685241
}
8416785242
break;
84168
- case 182: /* expr ::= nm DOT nm DOT nm */
85243
+ case 187: /* expr ::= nm DOT nm DOT nm */
8416985244
{
8417085245
Expr *temp1 = sqlite3PExpr(pParse, TK_ID, 0, 0, &yymsp[-4].minor.yy0);
8417185246
Expr *temp2 = sqlite3PExpr(pParse, TK_ID, 0, 0, &yymsp[-2].minor.yy0);
8417285247
Expr *temp3 = sqlite3PExpr(pParse, TK_ID, 0, 0, &yymsp[0].minor.yy0);
8417385248
Expr *temp4 = sqlite3PExpr(pParse, TK_DOT, temp2, temp3, 0);
84174
- yygotominor.yy172 = sqlite3PExpr(pParse, TK_DOT, temp1, temp4, 0);
85249
+ yygotominor.yy122 = sqlite3PExpr(pParse, TK_DOT, temp1, temp4, 0);
8417585250
}
8417685251
break;
84177
- case 185: /* expr ::= REGISTER */
84178
-{yygotominor.yy172 = sqlite3RegisterExpr(pParse, &yymsp[0].minor.yy0);}
85252
+ case 190: /* expr ::= REGISTER */
85253
+{yygotominor.yy122 = sqlite3RegisterExpr(pParse, &yymsp[0].minor.yy0);}
8417985254
break;
84180
- case 186: /* expr ::= VARIABLE */
85255
+ case 191: /* expr ::= VARIABLE */
8418185256
{
8418285257
Token *pToken = &yymsp[0].minor.yy0;
84183
- Expr *pExpr = yygotominor.yy172 = sqlite3PExpr(pParse, TK_VARIABLE, 0, 0, pToken);
85258
+ Expr *pExpr = yygotominor.yy122 = sqlite3PExpr(pParse, TK_VARIABLE, 0, 0, pToken);
8418485259
sqlite3ExprAssignVarNumber(pParse, pExpr);
8418585260
}
8418685261
break;
84187
- case 187: /* expr ::= expr COLLATE ids */
84188
-{
84189
- yygotominor.yy172 = sqlite3ExprSetColl(pParse, yymsp[-2].minor.yy172, &yymsp[0].minor.yy0);
84190
-}
84191
- break;
84192
- case 188: /* expr ::= CAST LP expr AS typetoken RP */
84193
-{
84194
- yygotominor.yy172 = sqlite3PExpr(pParse, TK_CAST, yymsp[-3].minor.yy172, 0, &yymsp[-1].minor.yy0);
84195
- sqlite3ExprSpan(yygotominor.yy172,&yymsp[-5].minor.yy0,&yymsp[0].minor.yy0);
84196
-}
84197
- break;
84198
- case 189: /* expr ::= ID LP distinct exprlist RP */
84199
-{
84200
- if( yymsp[-1].minor.yy174 && yymsp[-1].minor.yy174->nExpr>SQLITE_MAX_FUNCTION_ARG ){
85262
+ case 192: /* expr ::= expr COLLATE ids */
85263
+{
85264
+ yygotominor.yy122 = sqlite3ExprSetColl(pParse, yymsp[-2].minor.yy122, &yymsp[0].minor.yy0);
85265
+}
85266
+ break;
85267
+ case 193: /* expr ::= CAST LP expr AS typetoken RP */
85268
+{
85269
+ yygotominor.yy122 = sqlite3PExpr(pParse, TK_CAST, yymsp[-3].minor.yy122, 0, &yymsp[-1].minor.yy0);
85270
+ sqlite3ExprSpan(yygotominor.yy122,&yymsp[-5].minor.yy0,&yymsp[0].minor.yy0);
85271
+}
85272
+ break;
85273
+ case 194: /* expr ::= ID LP distinct exprlist RP */
85274
+{
85275
+ if( yymsp[-1].minor.yy442 && yymsp[-1].minor.yy442->nExpr>SQLITE_MAX_FUNCTION_ARG ){
8420185276
sqlite3ErrorMsg(pParse, "too many arguments on function %T", &yymsp[-4].minor.yy0);
8420285277
}
84203
- yygotominor.yy172 = sqlite3ExprFunction(pParse, yymsp[-1].minor.yy174, &yymsp[-4].minor.yy0);
84204
- sqlite3ExprSpan(yygotominor.yy172,&yymsp[-4].minor.yy0,&yymsp[0].minor.yy0);
84205
- if( yymsp[-2].minor.yy46 && yygotominor.yy172 ){
84206
- yygotominor.yy172->flags |= EP_Distinct;
84207
- }
84208
-}
84209
- break;
84210
- case 190: /* expr ::= ID LP STAR RP */
84211
-{
84212
- yygotominor.yy172 = sqlite3ExprFunction(pParse, 0, &yymsp[-3].minor.yy0);
84213
- sqlite3ExprSpan(yygotominor.yy172,&yymsp[-3].minor.yy0,&yymsp[0].minor.yy0);
84214
-}
84215
- break;
84216
- case 191: /* term ::= CTIME_KW */
85278
+ yygotominor.yy122 = sqlite3ExprFunction(pParse, yymsp[-1].minor.yy442, &yymsp[-4].minor.yy0);
85279
+ sqlite3ExprSpan(yygotominor.yy122,&yymsp[-4].minor.yy0,&yymsp[0].minor.yy0);
85280
+ if( yymsp[-2].minor.yy392 && yygotominor.yy122 ){
85281
+ yygotominor.yy122->flags |= EP_Distinct;
85282
+ }
85283
+}
85284
+ break;
85285
+ case 195: /* expr ::= ID LP STAR RP */
85286
+{
85287
+ yygotominor.yy122 = sqlite3ExprFunction(pParse, 0, &yymsp[-3].minor.yy0);
85288
+ sqlite3ExprSpan(yygotominor.yy122,&yymsp[-3].minor.yy0,&yymsp[0].minor.yy0);
85289
+}
85290
+ break;
85291
+ case 196: /* term ::= CTIME_KW */
8421785292
{
8421885293
/* The CURRENT_TIME, CURRENT_DATE, and CURRENT_TIMESTAMP values are
8421985294
** treated as functions that return constants */
84220
- yygotominor.yy172 = sqlite3ExprFunction(pParse, 0,&yymsp[0].minor.yy0);
84221
- if( yygotominor.yy172 ){
84222
- yygotominor.yy172->op = TK_CONST_FUNC;
84223
- yygotominor.yy172->span = yymsp[0].minor.yy0;
84224
- }
84225
-}
84226
- break;
84227
- case 192: /* expr ::= expr AND expr */
84228
- case 193: /* expr ::= expr OR expr */
84229
- case 194: /* expr ::= expr LT|GT|GE|LE expr */
84230
- case 195: /* expr ::= expr EQ|NE expr */
84231
- case 196: /* expr ::= expr BITAND|BITOR|LSHIFT|RSHIFT expr */
84232
- case 197: /* expr ::= expr PLUS|MINUS expr */
84233
- case 198: /* expr ::= expr STAR|SLASH|REM expr */
84234
- case 199: /* expr ::= expr CONCAT expr */
84235
-{yygotominor.yy172 = sqlite3PExpr(pParse,yymsp[-1].major,yymsp[-2].minor.yy172,yymsp[0].minor.yy172,0);}
84236
- break;
84237
- case 200: /* likeop ::= LIKE_KW */
84238
- case 202: /* likeop ::= MATCH */
84239
-{yygotominor.yy72.eOperator = yymsp[0].minor.yy0; yygotominor.yy72.not = 0;}
84240
- break;
84241
- case 201: /* likeop ::= NOT LIKE_KW */
84242
- case 203: /* likeop ::= NOT MATCH */
84243
-{yygotominor.yy72.eOperator = yymsp[0].minor.yy0; yygotominor.yy72.not = 1;}
84244
- break;
84245
- case 206: /* expr ::= expr likeop expr escape */
85295
+ yygotominor.yy122 = sqlite3ExprFunction(pParse, 0,&yymsp[0].minor.yy0);
85296
+ if( yygotominor.yy122 ){
85297
+ yygotominor.yy122->op = TK_CONST_FUNC;
85298
+ yygotominor.yy122->span = yymsp[0].minor.yy0;
85299
+ }
85300
+}
85301
+ break;
85302
+ case 197: /* expr ::= expr AND expr */
85303
+ case 198: /* expr ::= expr OR expr */
85304
+ case 199: /* expr ::= expr LT|GT|GE|LE expr */
85305
+ case 200: /* expr ::= expr EQ|NE expr */
85306
+ case 201: /* expr ::= expr BITAND|BITOR|LSHIFT|RSHIFT expr */
85307
+ case 202: /* expr ::= expr PLUS|MINUS expr */
85308
+ case 203: /* expr ::= expr STAR|SLASH|REM expr */
85309
+ case 204: /* expr ::= expr CONCAT expr */
85310
+{yygotominor.yy122 = sqlite3PExpr(pParse,yymsp[-1].major,yymsp[-2].minor.yy122,yymsp[0].minor.yy122,0);}
85311
+ break;
85312
+ case 205: /* likeop ::= LIKE_KW */
85313
+ case 207: /* likeop ::= MATCH */
85314
+{yygotominor.yy318.eOperator = yymsp[0].minor.yy0; yygotominor.yy318.not = 0;}
85315
+ break;
85316
+ case 206: /* likeop ::= NOT LIKE_KW */
85317
+ case 208: /* likeop ::= NOT MATCH */
85318
+{yygotominor.yy318.eOperator = yymsp[0].minor.yy0; yygotominor.yy318.not = 1;}
85319
+ break;
85320
+ case 211: /* expr ::= expr likeop expr escape */
8424685321
{
8424785322
ExprList *pList;
84248
- pList = sqlite3ExprListAppend(pParse,0, yymsp[-1].minor.yy172, 0);
84249
- pList = sqlite3ExprListAppend(pParse,pList, yymsp[-3].minor.yy172, 0);
84250
- if( yymsp[0].minor.yy172 ){
84251
- pList = sqlite3ExprListAppend(pParse,pList, yymsp[0].minor.yy172, 0);
84252
- }
84253
- yygotominor.yy172 = sqlite3ExprFunction(pParse, pList, &yymsp[-2].minor.yy72.eOperator);
84254
- if( yymsp[-2].minor.yy72.not ) yygotominor.yy172 = sqlite3PExpr(pParse, TK_NOT, yygotominor.yy172, 0, 0);
84255
- sqlite3ExprSpan(yygotominor.yy172, &yymsp[-3].minor.yy172->span, &yymsp[-1].minor.yy172->span);
84256
- if( yygotominor.yy172 ) yygotominor.yy172->flags |= EP_InfixFunc;
84257
-}
84258
- break;
84259
- case 207: /* expr ::= expr ISNULL|NOTNULL */
84260
-{
84261
- yygotominor.yy172 = sqlite3PExpr(pParse, yymsp[0].major, yymsp[-1].minor.yy172, 0, 0);
84262
- sqlite3ExprSpan(yygotominor.yy172,&yymsp[-1].minor.yy172->span,&yymsp[0].minor.yy0);
84263
-}
84264
- break;
84265
- case 208: /* expr ::= expr IS NULL */
84266
-{
84267
- yygotominor.yy172 = sqlite3PExpr(pParse, TK_ISNULL, yymsp[-2].minor.yy172, 0, 0);
84268
- sqlite3ExprSpan(yygotominor.yy172,&yymsp[-2].minor.yy172->span,&yymsp[0].minor.yy0);
84269
-}
84270
- break;
84271
- case 209: /* expr ::= expr NOT NULL */
84272
-{
84273
- yygotominor.yy172 = sqlite3PExpr(pParse, TK_NOTNULL, yymsp[-2].minor.yy172, 0, 0);
84274
- sqlite3ExprSpan(yygotominor.yy172,&yymsp[-2].minor.yy172->span,&yymsp[0].minor.yy0);
84275
-}
84276
- break;
84277
- case 210: /* expr ::= expr IS NOT NULL */
84278
-{
84279
- yygotominor.yy172 = sqlite3PExpr(pParse, TK_NOTNULL, yymsp[-3].minor.yy172, 0, 0);
84280
- sqlite3ExprSpan(yygotominor.yy172,&yymsp[-3].minor.yy172->span,&yymsp[0].minor.yy0);
84281
-}
84282
- break;
84283
- case 211: /* expr ::= NOT expr */
84284
- case 212: /* expr ::= BITNOT expr */
84285
-{
84286
- yygotominor.yy172 = sqlite3PExpr(pParse, yymsp[-1].major, yymsp[0].minor.yy172, 0, 0);
84287
- sqlite3ExprSpan(yygotominor.yy172,&yymsp[-1].minor.yy0,&yymsp[0].minor.yy172->span);
84288
-}
84289
- break;
84290
- case 213: /* expr ::= MINUS expr */
84291
-{
84292
- yygotominor.yy172 = sqlite3PExpr(pParse, TK_UMINUS, yymsp[0].minor.yy172, 0, 0);
84293
- sqlite3ExprSpan(yygotominor.yy172,&yymsp[-1].minor.yy0,&yymsp[0].minor.yy172->span);
84294
-}
84295
- break;
84296
- case 214: /* expr ::= PLUS expr */
84297
-{
84298
- yygotominor.yy172 = sqlite3PExpr(pParse, TK_UPLUS, yymsp[0].minor.yy172, 0, 0);
84299
- sqlite3ExprSpan(yygotominor.yy172,&yymsp[-1].minor.yy0,&yymsp[0].minor.yy172->span);
84300
-}
84301
- break;
84302
- case 217: /* expr ::= expr between_op expr AND expr */
84303
-{
84304
- ExprList *pList = sqlite3ExprListAppend(pParse,0, yymsp[-2].minor.yy172, 0);
84305
- pList = sqlite3ExprListAppend(pParse,pList, yymsp[0].minor.yy172, 0);
84306
- yygotominor.yy172 = sqlite3PExpr(pParse, TK_BETWEEN, yymsp[-4].minor.yy172, 0, 0);
84307
- if( yygotominor.yy172 ){
84308
- yygotominor.yy172->pList = pList;
85323
+ pList = sqlite3ExprListAppend(pParse,0, yymsp[-1].minor.yy122, 0);
85324
+ pList = sqlite3ExprListAppend(pParse,pList, yymsp[-3].minor.yy122, 0);
85325
+ if( yymsp[0].minor.yy122 ){
85326
+ pList = sqlite3ExprListAppend(pParse,pList, yymsp[0].minor.yy122, 0);
85327
+ }
85328
+ yygotominor.yy122 = sqlite3ExprFunction(pParse, pList, &yymsp[-2].minor.yy318.eOperator);
85329
+ if( yymsp[-2].minor.yy318.not ) yygotominor.yy122 = sqlite3PExpr(pParse, TK_NOT, yygotominor.yy122, 0, 0);
85330
+ sqlite3ExprSpan(yygotominor.yy122, &yymsp[-3].minor.yy122->span, &yymsp[-1].minor.yy122->span);
85331
+ if( yygotominor.yy122 ) yygotominor.yy122->flags |= EP_InfixFunc;
85332
+}
85333
+ break;
85334
+ case 212: /* expr ::= expr ISNULL|NOTNULL */
85335
+{
85336
+ yygotominor.yy122 = sqlite3PExpr(pParse, yymsp[0].major, yymsp[-1].minor.yy122, 0, 0);
85337
+ sqlite3ExprSpan(yygotominor.yy122,&yymsp[-1].minor.yy122->span,&yymsp[0].minor.yy0);
85338
+}
85339
+ break;
85340
+ case 213: /* expr ::= expr IS NULL */
85341
+{
85342
+ yygotominor.yy122 = sqlite3PExpr(pParse, TK_ISNULL, yymsp[-2].minor.yy122, 0, 0);
85343
+ sqlite3ExprSpan(yygotominor.yy122,&yymsp[-2].minor.yy122->span,&yymsp[0].minor.yy0);
85344
+}
85345
+ break;
85346
+ case 214: /* expr ::= expr NOT NULL */
85347
+{
85348
+ yygotominor.yy122 = sqlite3PExpr(pParse, TK_NOTNULL, yymsp[-2].minor.yy122, 0, 0);
85349
+ sqlite3ExprSpan(yygotominor.yy122,&yymsp[-2].minor.yy122->span,&yymsp[0].minor.yy0);
85350
+}
85351
+ break;
85352
+ case 215: /* expr ::= expr IS NOT NULL */
85353
+{
85354
+ yygotominor.yy122 = sqlite3PExpr(pParse, TK_NOTNULL, yymsp[-3].minor.yy122, 0, 0);
85355
+ sqlite3ExprSpan(yygotominor.yy122,&yymsp[-3].minor.yy122->span,&yymsp[0].minor.yy0);
85356
+}
85357
+ break;
85358
+ case 216: /* expr ::= NOT expr */
85359
+ case 217: /* expr ::= BITNOT expr */
85360
+{
85361
+ yygotominor.yy122 = sqlite3PExpr(pParse, yymsp[-1].major, yymsp[0].minor.yy122, 0, 0);
85362
+ sqlite3ExprSpan(yygotominor.yy122,&yymsp[-1].minor.yy0,&yymsp[0].minor.yy122->span);
85363
+}
85364
+ break;
85365
+ case 218: /* expr ::= MINUS expr */
85366
+{
85367
+ yygotominor.yy122 = sqlite3PExpr(pParse, TK_UMINUS, yymsp[0].minor.yy122, 0, 0);
85368
+ sqlite3ExprSpan(yygotominor.yy122,&yymsp[-1].minor.yy0,&yymsp[0].minor.yy122->span);
85369
+}
85370
+ break;
85371
+ case 219: /* expr ::= PLUS expr */
85372
+{
85373
+ yygotominor.yy122 = sqlite3PExpr(pParse, TK_UPLUS, yymsp[0].minor.yy122, 0, 0);
85374
+ sqlite3ExprSpan(yygotominor.yy122,&yymsp[-1].minor.yy0,&yymsp[0].minor.yy122->span);
85375
+}
85376
+ break;
85377
+ case 222: /* expr ::= expr between_op expr AND expr */
85378
+{
85379
+ ExprList *pList = sqlite3ExprListAppend(pParse,0, yymsp[-2].minor.yy122, 0);
85380
+ pList = sqlite3ExprListAppend(pParse,pList, yymsp[0].minor.yy122, 0);
85381
+ yygotominor.yy122 = sqlite3PExpr(pParse, TK_BETWEEN, yymsp[-4].minor.yy122, 0, 0);
85382
+ if( yygotominor.yy122 ){
85383
+ yygotominor.yy122->pList = pList;
8430985384
}else{
8431085385
sqlite3ExprListDelete(pParse->db, pList);
8431185386
}
84312
- if( yymsp[-3].minor.yy46 ) yygotominor.yy172 = sqlite3PExpr(pParse, TK_NOT, yygotominor.yy172, 0, 0);
84313
- sqlite3ExprSpan(yygotominor.yy172,&yymsp[-4].minor.yy172->span,&yymsp[0].minor.yy172->span);
84314
-}
84315
- break;
84316
- case 220: /* expr ::= expr in_op LP exprlist RP */
84317
-{
84318
- yygotominor.yy172 = sqlite3PExpr(pParse, TK_IN, yymsp[-4].minor.yy172, 0, 0);
84319
- if( yygotominor.yy172 ){
84320
- yygotominor.yy172->pList = yymsp[-1].minor.yy174;
84321
- sqlite3ExprSetHeight(pParse, yygotominor.yy172);
84322
- }else{
84323
- sqlite3ExprListDelete(pParse->db, yymsp[-1].minor.yy174);
84324
- }
84325
- if( yymsp[-3].minor.yy46 ) yygotominor.yy172 = sqlite3PExpr(pParse, TK_NOT, yygotominor.yy172, 0, 0);
84326
- sqlite3ExprSpan(yygotominor.yy172,&yymsp[-4].minor.yy172->span,&yymsp[0].minor.yy0);
84327
- }
84328
- break;
84329
- case 221: /* expr ::= LP select RP */
84330
-{
84331
- yygotominor.yy172 = sqlite3PExpr(pParse, TK_SELECT, 0, 0, 0);
84332
- if( yygotominor.yy172 ){
84333
- yygotominor.yy172->pSelect = yymsp[-1].minor.yy219;
84334
- sqlite3ExprSetHeight(pParse, yygotominor.yy172);
84335
- }else{
84336
- sqlite3SelectDelete(pParse->db, yymsp[-1].minor.yy219);
84337
- }
84338
- sqlite3ExprSpan(yygotominor.yy172,&yymsp[-2].minor.yy0,&yymsp[0].minor.yy0);
84339
- }
84340
- break;
84341
- case 222: /* expr ::= expr in_op LP select RP */
84342
-{
84343
- yygotominor.yy172 = sqlite3PExpr(pParse, TK_IN, yymsp[-4].minor.yy172, 0, 0);
84344
- if( yygotominor.yy172 ){
84345
- yygotominor.yy172->pSelect = yymsp[-1].minor.yy219;
84346
- sqlite3ExprSetHeight(pParse, yygotominor.yy172);
84347
- }else{
84348
- sqlite3SelectDelete(pParse->db, yymsp[-1].minor.yy219);
84349
- }
84350
- if( yymsp[-3].minor.yy46 ) yygotominor.yy172 = sqlite3PExpr(pParse, TK_NOT, yygotominor.yy172, 0, 0);
84351
- sqlite3ExprSpan(yygotominor.yy172,&yymsp[-4].minor.yy172->span,&yymsp[0].minor.yy0);
84352
- }
84353
- break;
84354
- case 223: /* expr ::= expr in_op nm dbnm */
85387
+ if( yymsp[-3].minor.yy392 ) yygotominor.yy122 = sqlite3PExpr(pParse, TK_NOT, yygotominor.yy122, 0, 0);
85388
+ sqlite3ExprSpan(yygotominor.yy122,&yymsp[-4].minor.yy122->span,&yymsp[0].minor.yy122->span);
85389
+}
85390
+ break;
85391
+ case 225: /* expr ::= expr in_op LP exprlist RP */
85392
+{
85393
+ yygotominor.yy122 = sqlite3PExpr(pParse, TK_IN, yymsp[-4].minor.yy122, 0, 0);
85394
+ if( yygotominor.yy122 ){
85395
+ yygotominor.yy122->pList = yymsp[-1].minor.yy442;
85396
+ sqlite3ExprSetHeight(pParse, yygotominor.yy122);
85397
+ }else{
85398
+ sqlite3ExprListDelete(pParse->db, yymsp[-1].minor.yy442);
85399
+ }
85400
+ if( yymsp[-3].minor.yy392 ) yygotominor.yy122 = sqlite3PExpr(pParse, TK_NOT, yygotominor.yy122, 0, 0);
85401
+ sqlite3ExprSpan(yygotominor.yy122,&yymsp[-4].minor.yy122->span,&yymsp[0].minor.yy0);
85402
+ }
85403
+ break;
85404
+ case 226: /* expr ::= LP select RP */
85405
+{
85406
+ yygotominor.yy122 = sqlite3PExpr(pParse, TK_SELECT, 0, 0, 0);
85407
+ if( yygotominor.yy122 ){
85408
+ yygotominor.yy122->pSelect = yymsp[-1].minor.yy159;
85409
+ sqlite3ExprSetHeight(pParse, yygotominor.yy122);
85410
+ }else{
85411
+ sqlite3SelectDelete(pParse->db, yymsp[-1].minor.yy159);
85412
+ }
85413
+ sqlite3ExprSpan(yygotominor.yy122,&yymsp[-2].minor.yy0,&yymsp[0].minor.yy0);
85414
+ }
85415
+ break;
85416
+ case 227: /* expr ::= expr in_op LP select RP */
85417
+{
85418
+ yygotominor.yy122 = sqlite3PExpr(pParse, TK_IN, yymsp[-4].minor.yy122, 0, 0);
85419
+ if( yygotominor.yy122 ){
85420
+ yygotominor.yy122->pSelect = yymsp[-1].minor.yy159;
85421
+ sqlite3ExprSetHeight(pParse, yygotominor.yy122);
85422
+ }else{
85423
+ sqlite3SelectDelete(pParse->db, yymsp[-1].minor.yy159);
85424
+ }
85425
+ if( yymsp[-3].minor.yy392 ) yygotominor.yy122 = sqlite3PExpr(pParse, TK_NOT, yygotominor.yy122, 0, 0);
85426
+ sqlite3ExprSpan(yygotominor.yy122,&yymsp[-4].minor.yy122->span,&yymsp[0].minor.yy0);
85427
+ }
85428
+ break;
85429
+ case 228: /* expr ::= expr in_op nm dbnm */
8435585430
{
8435685431
SrcList *pSrc = sqlite3SrcListAppend(pParse->db, 0,&yymsp[-1].minor.yy0,&yymsp[0].minor.yy0);
84357
- yygotominor.yy172 = sqlite3PExpr(pParse, TK_IN, yymsp[-3].minor.yy172, 0, 0);
84358
- if( yygotominor.yy172 ){
84359
- yygotominor.yy172->pSelect = sqlite3SelectNew(pParse, 0,pSrc,0,0,0,0,0,0,0);
84360
- sqlite3ExprSetHeight(pParse, yygotominor.yy172);
85432
+ yygotominor.yy122 = sqlite3PExpr(pParse, TK_IN, yymsp[-3].minor.yy122, 0, 0);
85433
+ if( yygotominor.yy122 ){
85434
+ yygotominor.yy122->pSelect = sqlite3SelectNew(pParse, 0,pSrc,0,0,0,0,0,0,0);
85435
+ sqlite3ExprSetHeight(pParse, yygotominor.yy122);
8436185436
}else{
8436285437
sqlite3SrcListDelete(pParse->db, pSrc);
8436385438
}
84364
- if( yymsp[-2].minor.yy46 ) yygotominor.yy172 = sqlite3PExpr(pParse, TK_NOT, yygotominor.yy172, 0, 0);
84365
- sqlite3ExprSpan(yygotominor.yy172,&yymsp[-3].minor.yy172->span,yymsp[0].minor.yy0.z?&yymsp[0].minor.yy0:&yymsp[-1].minor.yy0);
85439
+ if( yymsp[-2].minor.yy392 ) yygotominor.yy122 = sqlite3PExpr(pParse, TK_NOT, yygotominor.yy122, 0, 0);
85440
+ sqlite3ExprSpan(yygotominor.yy122,&yymsp[-3].minor.yy122->span,yymsp[0].minor.yy0.z?&yymsp[0].minor.yy0:&yymsp[-1].minor.yy0);
8436685441
}
8436785442
break;
84368
- case 224: /* expr ::= EXISTS LP select RP */
85443
+ case 229: /* expr ::= EXISTS LP select RP */
8436985444
{
84370
- Expr *p = yygotominor.yy172 = sqlite3PExpr(pParse, TK_EXISTS, 0, 0, 0);
85445
+ Expr *p = yygotominor.yy122 = sqlite3PExpr(pParse, TK_EXISTS, 0, 0, 0);
8437185446
if( p ){
84372
- p->pSelect = yymsp[-1].minor.yy219;
85447
+ p->pSelect = yymsp[-1].minor.yy159;
8437385448
sqlite3ExprSpan(p,&yymsp[-3].minor.yy0,&yymsp[0].minor.yy0);
84374
- sqlite3ExprSetHeight(pParse, yygotominor.yy172);
84375
- }else{
84376
- sqlite3SelectDelete(pParse->db, yymsp[-1].minor.yy219);
84377
- }
84378
- }
84379
- break;
84380
- case 225: /* expr ::= CASE case_operand case_exprlist case_else END */
84381
-{
84382
- yygotominor.yy172 = sqlite3PExpr(pParse, TK_CASE, yymsp[-3].minor.yy172, yymsp[-1].minor.yy172, 0);
84383
- if( yygotominor.yy172 ){
84384
- yygotominor.yy172->pList = yymsp[-2].minor.yy174;
84385
- sqlite3ExprSetHeight(pParse, yygotominor.yy172);
84386
- }else{
84387
- sqlite3ExprListDelete(pParse->db, yymsp[-2].minor.yy174);
84388
- }
84389
- sqlite3ExprSpan(yygotominor.yy172, &yymsp[-4].minor.yy0, &yymsp[0].minor.yy0);
84390
-}
84391
- break;
84392
- case 226: /* case_exprlist ::= case_exprlist WHEN expr THEN expr */
84393
-{
84394
- yygotominor.yy174 = sqlite3ExprListAppend(pParse,yymsp[-4].minor.yy174, yymsp[-2].minor.yy172, 0);
84395
- yygotominor.yy174 = sqlite3ExprListAppend(pParse,yygotominor.yy174, yymsp[0].minor.yy172, 0);
84396
-}
84397
- break;
84398
- case 227: /* case_exprlist ::= WHEN expr THEN expr */
84399
-{
84400
- yygotominor.yy174 = sqlite3ExprListAppend(pParse,0, yymsp[-2].minor.yy172, 0);
84401
- yygotominor.yy174 = sqlite3ExprListAppend(pParse,yygotominor.yy174, yymsp[0].minor.yy172, 0);
84402
-}
84403
- break;
84404
- case 236: /* cmd ::= CREATE uniqueflag INDEX ifnotexists nm dbnm ON nm LP idxlist RP */
85449
+ sqlite3ExprSetHeight(pParse, yygotominor.yy122);
85450
+ }else{
85451
+ sqlite3SelectDelete(pParse->db, yymsp[-1].minor.yy159);
85452
+ }
85453
+ }
85454
+ break;
85455
+ case 230: /* expr ::= CASE case_operand case_exprlist case_else END */
85456
+{
85457
+ yygotominor.yy122 = sqlite3PExpr(pParse, TK_CASE, yymsp[-3].minor.yy122, yymsp[-1].minor.yy122, 0);
85458
+ if( yygotominor.yy122 ){
85459
+ yygotominor.yy122->pList = yymsp[-2].minor.yy442;
85460
+ sqlite3ExprSetHeight(pParse, yygotominor.yy122);
85461
+ }else{
85462
+ sqlite3ExprListDelete(pParse->db, yymsp[-2].minor.yy442);
85463
+ }
85464
+ sqlite3ExprSpan(yygotominor.yy122, &yymsp[-4].minor.yy0, &yymsp[0].minor.yy0);
85465
+}
85466
+ break;
85467
+ case 231: /* case_exprlist ::= case_exprlist WHEN expr THEN expr */
85468
+{
85469
+ yygotominor.yy442 = sqlite3ExprListAppend(pParse,yymsp[-4].minor.yy442, yymsp[-2].minor.yy122, 0);
85470
+ yygotominor.yy442 = sqlite3ExprListAppend(pParse,yygotominor.yy442, yymsp[0].minor.yy122, 0);
85471
+}
85472
+ break;
85473
+ case 232: /* case_exprlist ::= WHEN expr THEN expr */
85474
+{
85475
+ yygotominor.yy442 = sqlite3ExprListAppend(pParse,0, yymsp[-2].minor.yy122, 0);
85476
+ yygotominor.yy442 = sqlite3ExprListAppend(pParse,yygotominor.yy442, yymsp[0].minor.yy122, 0);
85477
+}
85478
+ break;
85479
+ case 241: /* cmd ::= CREATE uniqueflag INDEX ifnotexists nm dbnm ON nm LP idxlist RP */
8440585480
{
8440685481
sqlite3CreateIndex(pParse, &yymsp[-6].minor.yy0, &yymsp[-5].minor.yy0,
84407
- sqlite3SrcListAppend(pParse->db,0,&yymsp[-3].minor.yy0,0), yymsp[-1].minor.yy174, yymsp[-9].minor.yy46,
84408
- &yymsp[-10].minor.yy0, &yymsp[0].minor.yy0, SQLITE_SO_ASC, yymsp[-7].minor.yy46);
85482
+ sqlite3SrcListAppend(pParse->db,0,&yymsp[-3].minor.yy0,0), yymsp[-1].minor.yy442, yymsp[-9].minor.yy392,
85483
+ &yymsp[-10].minor.yy0, &yymsp[0].minor.yy0, SQLITE_SO_ASC, yymsp[-7].minor.yy392);
85484
+}
85485
+ break;
85486
+ case 242: /* uniqueflag ::= UNIQUE */
85487
+ case 289: /* raisetype ::= ABORT */
85488
+{yygotominor.yy392 = OE_Abort;}
85489
+ break;
85490
+ case 243: /* uniqueflag ::= */
85491
+{yygotominor.yy392 = OE_None;}
85492
+ break;
85493
+ case 246: /* idxlist ::= idxlist COMMA nm collate sortorder */
85494
+{
85495
+ Expr *p = 0;
85496
+ if( yymsp[-1].minor.yy0.n>0 ){
85497
+ p = sqlite3PExpr(pParse, TK_COLUMN, 0, 0, 0);
85498
+ sqlite3ExprSetColl(pParse, p, &yymsp[-1].minor.yy0);
85499
+ }
85500
+ yygotominor.yy442 = sqlite3ExprListAppend(pParse,yymsp[-4].minor.yy442, p, &yymsp[-2].minor.yy0);
85501
+ sqlite3ExprListCheckLength(pParse, yygotominor.yy442, "index");
85502
+ if( yygotominor.yy442 ) yygotominor.yy442->a[yygotominor.yy442->nExpr-1].sortOrder = (u8)yymsp[0].minor.yy392;
8440985503
}
8441085504
break;
84411
- case 237: /* uniqueflag ::= UNIQUE */
84412
- case 284: /* raisetype ::= ABORT */
84413
-{yygotominor.yy46 = OE_Abort;}
84414
- break;
84415
- case 238: /* uniqueflag ::= */
84416
-{yygotominor.yy46 = OE_None;}
84417
- break;
84418
- case 241: /* idxlist ::= idxlist COMMA nm collate sortorder */
85505
+ case 247: /* idxlist ::= nm collate sortorder */
8441985506
{
8442085507
Expr *p = 0;
8442185508
if( yymsp[-1].minor.yy0.n>0 ){
8442285509
p = sqlite3PExpr(pParse, TK_COLUMN, 0, 0, 0);
8442385510
sqlite3ExprSetColl(pParse, p, &yymsp[-1].minor.yy0);
8442485511
}
84425
- yygotominor.yy174 = sqlite3ExprListAppend(pParse,yymsp[-4].minor.yy174, p, &yymsp[-2].minor.yy0);
84426
- sqlite3ExprListCheckLength(pParse, yygotominor.yy174, "index");
84427
- if( yygotominor.yy174 ) yygotominor.yy174->a[yygotominor.yy174->nExpr-1].sortOrder = (u8)yymsp[0].minor.yy46;
84428
-}
84429
- break;
84430
- case 242: /* idxlist ::= nm collate sortorder */
84431
-{
84432
- Expr *p = 0;
84433
- if( yymsp[-1].minor.yy0.n>0 ){
84434
- p = sqlite3PExpr(pParse, TK_COLUMN, 0, 0, 0);
84435
- sqlite3ExprSetColl(pParse, p, &yymsp[-1].minor.yy0);
84436
- }
84437
- yygotominor.yy174 = sqlite3ExprListAppend(pParse,0, p, &yymsp[-2].minor.yy0);
84438
- sqlite3ExprListCheckLength(pParse, yygotominor.yy174, "index");
84439
- if( yygotominor.yy174 ) yygotominor.yy174->a[yygotominor.yy174->nExpr-1].sortOrder = (u8)yymsp[0].minor.yy46;
84440
-}
84441
- break;
84442
- case 243: /* collate ::= */
85512
+ yygotominor.yy442 = sqlite3ExprListAppend(pParse,0, p, &yymsp[-2].minor.yy0);
85513
+ sqlite3ExprListCheckLength(pParse, yygotominor.yy442, "index");
85514
+ if( yygotominor.yy442 ) yygotominor.yy442->a[yygotominor.yy442->nExpr-1].sortOrder = (u8)yymsp[0].minor.yy392;
85515
+}
85516
+ break;
85517
+ case 248: /* collate ::= */
8444385518
{yygotominor.yy0.z = 0; yygotominor.yy0.n = 0;}
8444485519
break;
84445
- case 245: /* cmd ::= DROP INDEX ifexists fullname */
84446
-{sqlite3DropIndex(pParse, yymsp[0].minor.yy373, yymsp[-1].minor.yy46);}
85520
+ case 250: /* cmd ::= DROP INDEX ifexists fullname */
85521
+{sqlite3DropIndex(pParse, yymsp[0].minor.yy347, yymsp[-1].minor.yy392);}
8444785522
break;
84448
- case 246: /* cmd ::= VACUUM */
84449
- case 247: /* cmd ::= VACUUM nm */
85523
+ case 251: /* cmd ::= VACUUM */
85524
+ case 252: /* cmd ::= VACUUM nm */
8445085525
{sqlite3Vacuum(pParse);}
8445185526
break;
84452
- case 248: /* cmd ::= PRAGMA nm dbnm EQ nmnum */
84453
- case 249: /* cmd ::= PRAGMA nm dbnm EQ ON */
84454
- case 250: /* cmd ::= PRAGMA nm dbnm EQ DELETE */
85527
+ case 253: /* cmd ::= PRAGMA nm dbnm EQ nmnum */
85528
+ case 254: /* cmd ::= PRAGMA nm dbnm EQ ON */
85529
+ case 255: /* cmd ::= PRAGMA nm dbnm EQ DELETE */
8445585530
{sqlite3Pragma(pParse,&yymsp[-3].minor.yy0,&yymsp[-2].minor.yy0,&yymsp[0].minor.yy0,0);}
8445685531
break;
84457
- case 251: /* cmd ::= PRAGMA nm dbnm EQ minus_num */
85532
+ case 256: /* cmd ::= PRAGMA nm dbnm EQ minus_num */
8445885533
{
8445985534
sqlite3Pragma(pParse,&yymsp[-3].minor.yy0,&yymsp[-2].minor.yy0,&yymsp[0].minor.yy0,1);
8446085535
}
8446185536
break;
84462
- case 252: /* cmd ::= PRAGMA nm dbnm LP nmnum RP */
85537
+ case 257: /* cmd ::= PRAGMA nm dbnm LP nmnum RP */
8446385538
{sqlite3Pragma(pParse,&yymsp[-4].minor.yy0,&yymsp[-3].minor.yy0,&yymsp[-1].minor.yy0,0);}
8446485539
break;
84465
- case 253: /* cmd ::= PRAGMA nm dbnm */
85540
+ case 258: /* cmd ::= PRAGMA nm dbnm */
8446685541
{sqlite3Pragma(pParse,&yymsp[-1].minor.yy0,&yymsp[0].minor.yy0,0,0);}
8446785542
break;
84468
- case 261: /* cmd ::= CREATE trigger_decl BEGIN trigger_cmd_list END */
85543
+ case 266: /* cmd ::= CREATE trigger_decl BEGIN trigger_cmd_list END */
8446985544
{
8447085545
Token all;
8447185546
all.z = yymsp[-3].minor.yy0.z;
8447285547
all.n = (int)(yymsp[0].minor.yy0.z - yymsp[-3].minor.yy0.z) + yymsp[0].minor.yy0.n;
84473
- sqlite3FinishTrigger(pParse, yymsp[-1].minor.yy243, &all);
85548
+ sqlite3FinishTrigger(pParse, yymsp[-1].minor.yy327, &all);
8447485549
}
8447585550
break;
84476
- case 262: /* trigger_decl ::= temp TRIGGER ifnotexists nm dbnm trigger_time trigger_event ON fullname foreach_clause when_clause */
85551
+ case 267: /* trigger_decl ::= temp TRIGGER ifnotexists nm dbnm trigger_time trigger_event ON fullname foreach_clause when_clause */
8447785552
{
84478
- sqlite3BeginTrigger(pParse, &yymsp[-7].minor.yy0, &yymsp[-6].minor.yy0, yymsp[-5].minor.yy46, yymsp[-4].minor.yy370.a, yymsp[-4].minor.yy370.b, yymsp[-2].minor.yy373, yymsp[0].minor.yy172, yymsp[-10].minor.yy46, yymsp[-8].minor.yy46);
85553
+ sqlite3BeginTrigger(pParse, &yymsp[-7].minor.yy0, &yymsp[-6].minor.yy0, yymsp[-5].minor.yy392, yymsp[-4].minor.yy410.a, yymsp[-4].minor.yy410.b, yymsp[-2].minor.yy347, yymsp[0].minor.yy122, yymsp[-10].minor.yy392, yymsp[-8].minor.yy392);
8447985554
yygotominor.yy0 = (yymsp[-6].minor.yy0.n==0?yymsp[-7].minor.yy0:yymsp[-6].minor.yy0);
8448085555
}
8448185556
break;
84482
- case 263: /* trigger_time ::= BEFORE */
84483
- case 266: /* trigger_time ::= */
84484
-{ yygotominor.yy46 = TK_BEFORE; }
84485
- break;
84486
- case 264: /* trigger_time ::= AFTER */
84487
-{ yygotominor.yy46 = TK_AFTER; }
84488
- break;
84489
- case 265: /* trigger_time ::= INSTEAD OF */
84490
-{ yygotominor.yy46 = TK_INSTEAD;}
84491
- break;
84492
- case 267: /* trigger_event ::= DELETE|INSERT */
84493
- case 268: /* trigger_event ::= UPDATE */
84494
-{yygotominor.yy370.a = yymsp[0].major; yygotominor.yy370.b = 0;}
84495
- break;
84496
- case 269: /* trigger_event ::= UPDATE OF inscollist */
84497
-{yygotominor.yy370.a = TK_UPDATE; yygotominor.yy370.b = yymsp[0].minor.yy432;}
84498
- break;
84499
- case 272: /* when_clause ::= */
84500
- case 289: /* key_opt ::= */
84501
-{ yygotominor.yy172 = 0; }
84502
- break;
84503
- case 273: /* when_clause ::= WHEN expr */
84504
- case 290: /* key_opt ::= KEY expr */
84505
-{ yygotominor.yy172 = yymsp[0].minor.yy172; }
84506
- break;
84507
- case 274: /* trigger_cmd_list ::= trigger_cmd_list trigger_cmd SEMI */
84508
-{
84509
-/*
84510
- if( yymsp[-2].minor.yy243 ){
84511
- yymsp[-2].minor.yy243->pLast->pNext = yymsp[-1].minor.yy243;
84512
- }else{
84513
- yymsp[-2].minor.yy243 = yymsp[-1].minor.yy243;
84514
- }
84515
-*/
84516
- assert( yymsp[-2].minor.yy243!=0 );
84517
- yymsp[-2].minor.yy243->pLast->pNext = yymsp[-1].minor.yy243;
84518
- yymsp[-2].minor.yy243->pLast = yymsp[-1].minor.yy243;
84519
- yygotominor.yy243 = yymsp[-2].minor.yy243;
84520
-}
84521
- break;
84522
- case 275: /* trigger_cmd_list ::= trigger_cmd SEMI */
84523
-{
84524
- /* if( yymsp[-1].minor.yy243 ) */
84525
- assert( yymsp[-1].minor.yy243!=0 );
84526
- yymsp[-1].minor.yy243->pLast = yymsp[-1].minor.yy243;
84527
- yygotominor.yy243 = yymsp[-1].minor.yy243;
84528
-}
84529
- break;
84530
- case 276: /* trigger_cmd ::= UPDATE orconf nm SET setlist where_opt */
84531
-{ yygotominor.yy243 = sqlite3TriggerUpdateStep(pParse->db, &yymsp[-3].minor.yy0, yymsp[-1].minor.yy174, yymsp[0].minor.yy172, yymsp[-4].minor.yy46); }
84532
- break;
84533
- case 277: /* trigger_cmd ::= insert_cmd INTO nm inscollist_opt VALUES LP itemlist RP */
84534
-{yygotominor.yy243 = sqlite3TriggerInsertStep(pParse->db, &yymsp[-5].minor.yy0, yymsp[-4].minor.yy432, yymsp[-1].minor.yy174, 0, yymsp[-7].minor.yy46);}
84535
- break;
84536
- case 278: /* trigger_cmd ::= insert_cmd INTO nm inscollist_opt select */
84537
-{yygotominor.yy243 = sqlite3TriggerInsertStep(pParse->db, &yymsp[-2].minor.yy0, yymsp[-1].minor.yy432, 0, yymsp[0].minor.yy219, yymsp[-4].minor.yy46);}
84538
- break;
84539
- case 279: /* trigger_cmd ::= DELETE FROM nm where_opt */
84540
-{yygotominor.yy243 = sqlite3TriggerDeleteStep(pParse->db, &yymsp[-1].minor.yy0, yymsp[0].minor.yy172);}
84541
- break;
84542
- case 280: /* trigger_cmd ::= select */
84543
-{yygotominor.yy243 = sqlite3TriggerSelectStep(pParse->db, yymsp[0].minor.yy219); }
84544
- break;
84545
- case 281: /* expr ::= RAISE LP IGNORE RP */
84546
-{
84547
- yygotominor.yy172 = sqlite3PExpr(pParse, TK_RAISE, 0, 0, 0);
84548
- if( yygotominor.yy172 ){
84549
- yygotominor.yy172->iColumn = OE_Ignore;
84550
- sqlite3ExprSpan(yygotominor.yy172, &yymsp[-3].minor.yy0, &yymsp[0].minor.yy0);
84551
- }
84552
-}
84553
- break;
84554
- case 282: /* expr ::= RAISE LP raisetype COMMA nm RP */
84555
-{
84556
- yygotominor.yy172 = sqlite3PExpr(pParse, TK_RAISE, 0, 0, &yymsp[-1].minor.yy0);
84557
- if( yygotominor.yy172 ) {
84558
- yygotominor.yy172->iColumn = yymsp[-3].minor.yy46;
84559
- sqlite3ExprSpan(yygotominor.yy172, &yymsp[-5].minor.yy0, &yymsp[0].minor.yy0);
84560
- }
84561
-}
84562
- break;
84563
- case 283: /* raisetype ::= ROLLBACK */
84564
-{yygotominor.yy46 = OE_Rollback;}
84565
- break;
84566
- case 285: /* raisetype ::= FAIL */
84567
-{yygotominor.yy46 = OE_Fail;}
84568
- break;
84569
- case 286: /* cmd ::= DROP TRIGGER ifexists fullname */
84570
-{
84571
- sqlite3DropTrigger(pParse,yymsp[0].minor.yy373,yymsp[-1].minor.yy46);
84572
-}
84573
- break;
84574
- case 287: /* cmd ::= ATTACH database_kw_opt expr AS expr key_opt */
84575
-{
84576
- sqlite3Attach(pParse, yymsp[-3].minor.yy172, yymsp[-1].minor.yy172, yymsp[0].minor.yy172);
84577
-}
84578
- break;
84579
- case 288: /* cmd ::= DETACH database_kw_opt expr */
84580
-{
84581
- sqlite3Detach(pParse, yymsp[0].minor.yy172);
84582
-}
84583
- break;
84584
- case 293: /* cmd ::= REINDEX */
85557
+ case 268: /* trigger_time ::= BEFORE */
85558
+ case 271: /* trigger_time ::= */
85559
+{ yygotominor.yy392 = TK_BEFORE; }
85560
+ break;
85561
+ case 269: /* trigger_time ::= AFTER */
85562
+{ yygotominor.yy392 = TK_AFTER; }
85563
+ break;
85564
+ case 270: /* trigger_time ::= INSTEAD OF */
85565
+{ yygotominor.yy392 = TK_INSTEAD;}
85566
+ break;
85567
+ case 272: /* trigger_event ::= DELETE|INSERT */
85568
+ case 273: /* trigger_event ::= UPDATE */
85569
+{yygotominor.yy410.a = yymsp[0].major; yygotominor.yy410.b = 0;}
85570
+ break;
85571
+ case 274: /* trigger_event ::= UPDATE OF inscollist */
85572
+{yygotominor.yy410.a = TK_UPDATE; yygotominor.yy410.b = yymsp[0].minor.yy180;}
85573
+ break;
85574
+ case 277: /* when_clause ::= */
85575
+ case 294: /* key_opt ::= */
85576
+{ yygotominor.yy122 = 0; }
85577
+ break;
85578
+ case 278: /* when_clause ::= WHEN expr */
85579
+ case 295: /* key_opt ::= KEY expr */
85580
+{ yygotominor.yy122 = yymsp[0].minor.yy122; }
85581
+ break;
85582
+ case 279: /* trigger_cmd_list ::= trigger_cmd_list trigger_cmd SEMI */
85583
+{
85584
+/*
85585
+ if( yymsp[-2].minor.yy327 ){
85586
+ yymsp[-2].minor.yy327->pLast->pNext = yymsp[-1].minor.yy327;
85587
+ }else{
85588
+ yymsp[-2].minor.yy327 = yymsp[-1].minor.yy327;
85589
+ }
85590
+*/
85591
+ assert( yymsp[-2].minor.yy327!=0 );
85592
+ yymsp[-2].minor.yy327->pLast->pNext = yymsp[-1].minor.yy327;
85593
+ yymsp[-2].minor.yy327->pLast = yymsp[-1].minor.yy327;
85594
+ yygotominor.yy327 = yymsp[-2].minor.yy327;
85595
+}
85596
+ break;
85597
+ case 280: /* trigger_cmd_list ::= trigger_cmd SEMI */
85598
+{
85599
+ /* if( yymsp[-1].minor.yy327 ) */
85600
+ assert( yymsp[-1].minor.yy327!=0 );
85601
+ yymsp[-1].minor.yy327->pLast = yymsp[-1].minor.yy327;
85602
+ yygotominor.yy327 = yymsp[-1].minor.yy327;
85603
+}
85604
+ break;
85605
+ case 281: /* trigger_cmd ::= UPDATE orconf nm SET setlist where_opt */
85606
+{ yygotominor.yy327 = sqlite3TriggerUpdateStep(pParse->db, &yymsp[-3].minor.yy0, yymsp[-1].minor.yy442, yymsp[0].minor.yy122, yymsp[-4].minor.yy392); }
85607
+ break;
85608
+ case 282: /* trigger_cmd ::= insert_cmd INTO nm inscollist_opt VALUES LP itemlist RP */
85609
+{yygotominor.yy327 = sqlite3TriggerInsertStep(pParse->db, &yymsp[-5].minor.yy0, yymsp[-4].minor.yy180, yymsp[-1].minor.yy442, 0, yymsp[-7].minor.yy392);}
85610
+ break;
85611
+ case 283: /* trigger_cmd ::= insert_cmd INTO nm inscollist_opt select */
85612
+{yygotominor.yy327 = sqlite3TriggerInsertStep(pParse->db, &yymsp[-2].minor.yy0, yymsp[-1].minor.yy180, 0, yymsp[0].minor.yy159, yymsp[-4].minor.yy392);}
85613
+ break;
85614
+ case 284: /* trigger_cmd ::= DELETE FROM nm where_opt */
85615
+{yygotominor.yy327 = sqlite3TriggerDeleteStep(pParse->db, &yymsp[-1].minor.yy0, yymsp[0].minor.yy122);}
85616
+ break;
85617
+ case 285: /* trigger_cmd ::= select */
85618
+{yygotominor.yy327 = sqlite3TriggerSelectStep(pParse->db, yymsp[0].minor.yy159); }
85619
+ break;
85620
+ case 286: /* expr ::= RAISE LP IGNORE RP */
85621
+{
85622
+ yygotominor.yy122 = sqlite3PExpr(pParse, TK_RAISE, 0, 0, 0);
85623
+ if( yygotominor.yy122 ){
85624
+ yygotominor.yy122->iColumn = OE_Ignore;
85625
+ sqlite3ExprSpan(yygotominor.yy122, &yymsp[-3].minor.yy0, &yymsp[0].minor.yy0);
85626
+ }
85627
+}
85628
+ break;
85629
+ case 287: /* expr ::= RAISE LP raisetype COMMA nm RP */
85630
+{
85631
+ yygotominor.yy122 = sqlite3PExpr(pParse, TK_RAISE, 0, 0, &yymsp[-1].minor.yy0);
85632
+ if( yygotominor.yy122 ) {
85633
+ yygotominor.yy122->iColumn = yymsp[-3].minor.yy392;
85634
+ sqlite3ExprSpan(yygotominor.yy122, &yymsp[-5].minor.yy0, &yymsp[0].minor.yy0);
85635
+ }
85636
+}
85637
+ break;
85638
+ case 288: /* raisetype ::= ROLLBACK */
85639
+{yygotominor.yy392 = OE_Rollback;}
85640
+ break;
85641
+ case 290: /* raisetype ::= FAIL */
85642
+{yygotominor.yy392 = OE_Fail;}
85643
+ break;
85644
+ case 291: /* cmd ::= DROP TRIGGER ifexists fullname */
85645
+{
85646
+ sqlite3DropTrigger(pParse,yymsp[0].minor.yy347,yymsp[-1].minor.yy392);
85647
+}
85648
+ break;
85649
+ case 292: /* cmd ::= ATTACH database_kw_opt expr AS expr key_opt */
85650
+{
85651
+ sqlite3Attach(pParse, yymsp[-3].minor.yy122, yymsp[-1].minor.yy122, yymsp[0].minor.yy122);
85652
+}
85653
+ break;
85654
+ case 293: /* cmd ::= DETACH database_kw_opt expr */
85655
+{
85656
+ sqlite3Detach(pParse, yymsp[0].minor.yy122);
85657
+}
85658
+ break;
85659
+ case 298: /* cmd ::= REINDEX */
8458585660
{sqlite3Reindex(pParse, 0, 0);}
8458685661
break;
84587
- case 294: /* cmd ::= REINDEX nm dbnm */
85662
+ case 299: /* cmd ::= REINDEX nm dbnm */
8458885663
{sqlite3Reindex(pParse, &yymsp[-1].minor.yy0, &yymsp[0].minor.yy0);}
8458985664
break;
84590
- case 295: /* cmd ::= ANALYZE */
85665
+ case 300: /* cmd ::= ANALYZE */
8459185666
{sqlite3Analyze(pParse, 0, 0);}
8459285667
break;
84593
- case 296: /* cmd ::= ANALYZE nm dbnm */
85668
+ case 301: /* cmd ::= ANALYZE nm dbnm */
8459485669
{sqlite3Analyze(pParse, &yymsp[-1].minor.yy0, &yymsp[0].minor.yy0);}
8459585670
break;
84596
- case 297: /* cmd ::= ALTER TABLE fullname RENAME TO nm */
85671
+ case 302: /* cmd ::= ALTER TABLE fullname RENAME TO nm */
8459785672
{
84598
- sqlite3AlterRenameTable(pParse,yymsp[-3].minor.yy373,&yymsp[0].minor.yy0);
85673
+ sqlite3AlterRenameTable(pParse,yymsp[-3].minor.yy347,&yymsp[0].minor.yy0);
8459985674
}
8460085675
break;
84601
- case 298: /* cmd ::= ALTER TABLE add_column_fullname ADD kwcolumn_opt column */
85676
+ case 303: /* cmd ::= ALTER TABLE add_column_fullname ADD kwcolumn_opt column */
8460285677
{
8460385678
sqlite3AlterFinishAddColumn(pParse, &yymsp[0].minor.yy0);
8460485679
}
8460585680
break;
84606
- case 299: /* add_column_fullname ::= fullname */
85681
+ case 304: /* add_column_fullname ::= fullname */
8460785682
{
84608
- sqlite3AlterBeginAddColumn(pParse, yymsp[0].minor.yy373);
85683
+ sqlite3AlterBeginAddColumn(pParse, yymsp[0].minor.yy347);
8460985684
}
8461085685
break;
84611
- case 302: /* cmd ::= create_vtab */
85686
+ case 307: /* cmd ::= create_vtab */
8461285687
{sqlite3VtabFinishParse(pParse,0);}
8461385688
break;
84614
- case 303: /* cmd ::= create_vtab LP vtabarglist RP */
85689
+ case 308: /* cmd ::= create_vtab LP vtabarglist RP */
8461585690
{sqlite3VtabFinishParse(pParse,&yymsp[0].minor.yy0);}
8461685691
break;
84617
- case 304: /* create_vtab ::= CREATE VIRTUAL TABLE nm dbnm USING nm */
85692
+ case 309: /* create_vtab ::= CREATE VIRTUAL TABLE nm dbnm USING nm */
8461885693
{
8461985694
sqlite3VtabBeginParse(pParse, &yymsp[-3].minor.yy0, &yymsp[-2].minor.yy0, &yymsp[0].minor.yy0);
8462085695
}
8462185696
break;
84622
- case 307: /* vtabarg ::= */
85697
+ case 312: /* vtabarg ::= */
8462385698
{sqlite3VtabArgInit(pParse);}
8462485699
break;
84625
- case 309: /* vtabargtoken ::= ANY */
84626
- case 310: /* vtabargtoken ::= lp anylist RP */
84627
- case 311: /* lp ::= LP */
84628
- case 313: /* anylist ::= anylist ANY */
85700
+ case 314: /* vtabargtoken ::= ANY */
85701
+ case 315: /* vtabargtoken ::= lp anylist RP */
85702
+ case 316: /* lp ::= LP */
85703
+ case 318: /* anylist ::= anylist ANY */
8462985704
{sqlite3VtabArgExtend(pParse,&yymsp[0].minor.yy0);}
8463085705
break;
8463185706
};
8463285707
yygoto = yyRuleInfo[yyruleno].lhs;
8463385708
yysize = yyRuleInfo[yyruleno].nrhs;
@@ -84938,141 +86013,264 @@
8493886013
/************** Begin file keywordhash.h *************************************/
8493986014
/***** This file contains automatically generated code ******
8494086015
**
8494186016
** The code in this file has been automatically generated by
8494286017
**
84943
-** $Header: /sqlite/sqlite/tool/mkkeywordhash.c,v 1.34 2008/12/10 20:11:01 shane Exp $
86018
+** $Header: /sqlite/sqlite/tool/mkkeywordhash.c,v 1.36 2008/12/31 21:52:41 drh Exp $
8494486019
**
8494586020
** The code in this file implements a function that determines whether
8494686021
** or not a given identifier is really an SQL keyword. The same thing
8494786022
** might be implemented more directly using a hand-written hash table.
8494886023
** But by using this automatically generated code, the size of the code
8494986024
** is substantially reduced. This is important for embedded applications
8495086025
** on platforms with limited memory.
8495186026
*/
84952
-/* Hash score: 167 */
86027
+/* Hash score: 171 */
8495386028
static int keywordCode(const char *z, int n){
84954
- /* zText[] encodes 783 bytes of keywords in 528 bytes */
86029
+ /* zText[] encodes 801 bytes of keywords in 541 bytes */
8495586030
/* REINDEXEDESCAPEACHECKEYBEFOREIGNOREGEXPLAINSTEADDATABASELECT */
8495686031
/* ABLEFTHENDEFERRABLELSEXCEPTRANSACTIONATURALTERAISEXCLUSIVE */
84957
- /* XISTSCONSTRAINTERSECTRIGGEREFERENCESUNIQUERYATTACHAVINGROUP */
84958
- /* DATEMPORARYBEGINNERENAMEBETWEENOTNULLIKECASCADELETECASECOLLATE */
84959
- /* CREATECURRENT_DATEDETACHIMMEDIATEJOINSERTMATCHPLANALYZEPRAGMA */
84960
- /* BORTVALUESVIRTUALIMITWHENWHEREPLACEAFTERESTRICTANDEFAULT */
84961
- /* AUTOINCREMENTCASTCOLUMNCOMMITCONFLICTCROSSCURRENT_TIMESTAMP */
84962
- /* RIMARYDEFERREDISTINCTDROPFAILFROMFULLGLOBYIFINTOFFSETISNULL */
84963
- /* ORDERIGHTOUTEROLLBACKROWUNIONUSINGVACUUMVIEWINITIALLY */
84964
- static const char zText[528] = {
86032
+ /* XISTSAVEPOINTERSECTRIGGEREFERENCESCONSTRAINTOFFSETEMPORARY */
86033
+ /* UNIQUERYATTACHAVINGROUPDATEBEGINNERELEASEBETWEENOTNULLIKE */
86034
+ /* CASCADELETECASECOLLATECREATECURRENT_DATEDETACHIMMEDIATEJOIN */
86035
+ /* SERTMATCHPLANALYZEPRAGMABORTVALUESVIRTUALIMITWHENWHERENAME */
86036
+ /* AFTEREPLACEANDEFAULTAUTOINCREMENTCASTCOLUMNCOMMITCONFLICTCROSS */
86037
+ /* CURRENT_TIMESTAMPRIMARYDEFERREDISTINCTDROPFAILFROMFULLGLOBYIF */
86038
+ /* ISNULLORDERESTRICTOUTERIGHTROLLBACKROWUNIONUSINGVACUUMVIEW */
86039
+ /* INITIALLY */
86040
+ static const char zText[540] = {
8496586041
'R','E','I','N','D','E','X','E','D','E','S','C','A','P','E','A','C','H',
8496686042
'E','C','K','E','Y','B','E','F','O','R','E','I','G','N','O','R','E','G',
8496786043
'E','X','P','L','A','I','N','S','T','E','A','D','D','A','T','A','B','A',
8496886044
'S','E','L','E','C','T','A','B','L','E','F','T','H','E','N','D','E','F',
8496986045
'E','R','R','A','B','L','E','L','S','E','X','C','E','P','T','R','A','N',
8497086046
'S','A','C','T','I','O','N','A','T','U','R','A','L','T','E','R','A','I',
84971
- 'S','E','X','C','L','U','S','I','V','E','X','I','S','T','S','C','O','N',
84972
- 'S','T','R','A','I','N','T','E','R','S','E','C','T','R','I','G','G','E',
84973
- 'R','E','F','E','R','E','N','C','E','S','U','N','I','Q','U','E','R','Y',
84974
- 'A','T','T','A','C','H','A','V','I','N','G','R','O','U','P','D','A','T',
84975
- 'E','M','P','O','R','A','R','Y','B','E','G','I','N','N','E','R','E','N',
84976
- 'A','M','E','B','E','T','W','E','E','N','O','T','N','U','L','L','I','K',
84977
- 'E','C','A','S','C','A','D','E','L','E','T','E','C','A','S','E','C','O',
84978
- 'L','L','A','T','E','C','R','E','A','T','E','C','U','R','R','E','N','T',
84979
- '_','D','A','T','E','D','E','T','A','C','H','I','M','M','E','D','I','A',
84980
- 'T','E','J','O','I','N','S','E','R','T','M','A','T','C','H','P','L','A',
84981
- 'N','A','L','Y','Z','E','P','R','A','G','M','A','B','O','R','T','V','A',
84982
- 'L','U','E','S','V','I','R','T','U','A','L','I','M','I','T','W','H','E',
84983
- 'N','W','H','E','R','E','P','L','A','C','E','A','F','T','E','R','E','S',
84984
- 'T','R','I','C','T','A','N','D','E','F','A','U','L','T','A','U','T','O',
84985
- 'I','N','C','R','E','M','E','N','T','C','A','S','T','C','O','L','U','M',
84986
- 'N','C','O','M','M','I','T','C','O','N','F','L','I','C','T','C','R','O',
84987
- 'S','S','C','U','R','R','E','N','T','_','T','I','M','E','S','T','A','M',
84988
- 'P','R','I','M','A','R','Y','D','E','F','E','R','R','E','D','I','S','T',
84989
- 'I','N','C','T','D','R','O','P','F','A','I','L','F','R','O','M','F','U',
84990
- 'L','L','G','L','O','B','Y','I','F','I','N','T','O','F','F','S','E','T',
84991
- 'I','S','N','U','L','L','O','R','D','E','R','I','G','H','T','O','U','T',
84992
- 'E','R','O','L','L','B','A','C','K','R','O','W','U','N','I','O','N','U',
84993
- 'S','I','N','G','V','A','C','U','U','M','V','I','E','W','I','N','I','T',
84994
- 'I','A','L','L','Y',0
86047
+ 'S','E','X','C','L','U','S','I','V','E','X','I','S','T','S','A','V','E',
86048
+ 'P','O','I','N','T','E','R','S','E','C','T','R','I','G','G','E','R','E',
86049
+ 'F','E','R','E','N','C','E','S','C','O','N','S','T','R','A','I','N','T',
86050
+ 'O','F','F','S','E','T','E','M','P','O','R','A','R','Y','U','N','I','Q',
86051
+ 'U','E','R','Y','A','T','T','A','C','H','A','V','I','N','G','R','O','U',
86052
+ 'P','D','A','T','E','B','E','G','I','N','N','E','R','E','L','E','A','S',
86053
+ 'E','B','E','T','W','E','E','N','O','T','N','U','L','L','I','K','E','C',
86054
+ 'A','S','C','A','D','E','L','E','T','E','C','A','S','E','C','O','L','L',
86055
+ 'A','T','E','C','R','E','A','T','E','C','U','R','R','E','N','T','_','D',
86056
+ 'A','T','E','D','E','T','A','C','H','I','M','M','E','D','I','A','T','E',
86057
+ 'J','O','I','N','S','E','R','T','M','A','T','C','H','P','L','A','N','A',
86058
+ 'L','Y','Z','E','P','R','A','G','M','A','B','O','R','T','V','A','L','U',
86059
+ 'E','S','V','I','R','T','U','A','L','I','M','I','T','W','H','E','N','W',
86060
+ 'H','E','R','E','N','A','M','E','A','F','T','E','R','E','P','L','A','C',
86061
+ 'E','A','N','D','E','F','A','U','L','T','A','U','T','O','I','N','C','R',
86062
+ 'E','M','E','N','T','C','A','S','T','C','O','L','U','M','N','C','O','M',
86063
+ 'M','I','T','C','O','N','F','L','I','C','T','C','R','O','S','S','C','U',
86064
+ 'R','R','E','N','T','_','T','I','M','E','S','T','A','M','P','R','I','M',
86065
+ 'A','R','Y','D','E','F','E','R','R','E','D','I','S','T','I','N','C','T',
86066
+ 'D','R','O','P','F','A','I','L','F','R','O','M','F','U','L','L','G','L',
86067
+ 'O','B','Y','I','F','I','S','N','U','L','L','O','R','D','E','R','E','S',
86068
+ 'T','R','I','C','T','O','U','T','E','R','I','G','H','T','R','O','L','L',
86069
+ 'B','A','C','K','R','O','W','U','N','I','O','N','U','S','I','N','G','V',
86070
+ 'A','C','U','U','M','V','I','E','W','I','N','I','T','I','A','L','L','Y',
8499586071
};
8499686072
static const unsigned char aHash[127] = {
84997
- 65, 94, 110, 63, 0, 44, 0, 0, 71, 0, 66, 0, 0,
84998
- 104, 12, 67, 15, 0, 108, 74, 105, 101, 0, 19, 0, 0,
84999
- 114, 0, 112, 78, 0, 22, 82, 0, 9, 0, 0, 59, 60,
85000
- 0, 58, 6, 0, 39, 79, 91, 0, 111, 90, 0, 0, 45,
85001
- 0, 92, 24, 0, 17, 0, 115, 40, 23, 0, 5, 99, 25,
85002
- 85, 0, 0, 117, 95, 50, 116, 47, 7, 42, 0, 80, 0,
85003
- 89, 26, 0, 88, 0, 0, 0, 84, 81, 86, 77, 98, 14,
85004
- 34, 97, 0, 70, 0, 18, 76, 100, 31, 0, 113, 69, 106,
85005
- 52, 46, 73, 0, 0, 83, 102, 0, 109, 0, 35, 0, 0,
85006
- 28, 0, 75, 48, 53, 0, 20, 51, 0, 43,
86073
+ 70, 99, 112, 68, 0, 43, 0, 0, 76, 0, 71, 0, 0,
86074
+ 41, 12, 72, 15, 0, 111, 79, 49, 106, 0, 19, 0, 0,
86075
+ 116, 0, 114, 109, 0, 22, 87, 0, 9, 0, 0, 64, 65,
86076
+ 0, 63, 6, 0, 47, 84, 96, 0, 113, 95, 0, 0, 44,
86077
+ 0, 97, 24, 0, 17, 0, 117, 48, 23, 0, 5, 104, 25,
86078
+ 90, 0, 0, 119, 100, 55, 118, 52, 7, 50, 0, 85, 0,
86079
+ 94, 26, 0, 93, 0, 0, 0, 89, 86, 91, 82, 103, 14,
86080
+ 38, 102, 0, 75, 0, 18, 83, 105, 31, 0, 115, 74, 107,
86081
+ 57, 45, 78, 0, 0, 88, 39, 0, 110, 0, 35, 0, 0,
86082
+ 28, 0, 80, 53, 58, 0, 20, 56, 0, 51,
8500786083
};
85008
- static const unsigned char aNext[117] = {
86084
+ static const unsigned char aNext[119] = {
8500986085
0, 0, 0, 0, 4, 0, 0, 0, 0, 0, 0, 0, 0,
8501086086
0, 2, 0, 0, 0, 0, 0, 0, 13, 0, 0, 0, 0,
8501186087
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
85012
- 0, 0, 3, 38, 0, 32, 21, 0, 0, 0, 0, 29, 0,
85013
- 0, 37, 0, 0, 0, 1, 55, 0, 0, 56, 0, 0, 0,
85014
- 0, 0, 0, 0, 0, 0, 54, 0, 0, 0, 0, 30, 0,
85015
- 16, 33, 10, 0, 0, 0, 0, 0, 0, 0, 11, 61, 68,
85016
- 0, 8, 0, 93, 87, 0, 96, 0, 49, 0, 0, 64, 0,
85017
- 41, 103, 0, 27, 107, 36, 62, 72, 0, 0, 57, 0, 0,
86088
+ 0, 0, 0, 0, 32, 21, 0, 0, 0, 42, 3, 46, 0,
86089
+ 0, 0, 0, 29, 0, 0, 37, 0, 0, 0, 1, 60, 0,
86090
+ 0, 61, 0, 40, 0, 0, 0, 0, 0, 0, 0, 59, 0,
86091
+ 0, 0, 0, 30, 54, 16, 33, 10, 0, 0, 0, 0, 0,
86092
+ 0, 0, 11, 66, 73, 0, 8, 0, 98, 92, 0, 101, 0,
86093
+ 81, 0, 69, 0, 0, 108, 27, 36, 67, 77, 0, 34, 62,
86094
+ 0, 0,
8501886095
};
85019
- static const unsigned char aLen[117] = {
86096
+ static const unsigned char aLen[119] = {
8502086097
7, 7, 5, 4, 6, 4, 5, 3, 6, 7, 3, 6, 6,
8502186098
7, 7, 3, 8, 2, 6, 5, 4, 4, 3, 10, 4, 6,
85022
- 11, 2, 7, 5, 5, 9, 6, 10, 9, 7, 10, 6, 5,
85023
- 6, 6, 5, 6, 4, 9, 2, 5, 5, 6, 7, 7, 3,
85024
- 4, 4, 7, 3, 6, 4, 7, 6, 12, 6, 9, 4, 6,
85025
- 5, 4, 7, 6, 5, 6, 7, 5, 4, 5, 7, 5, 8,
85026
- 3, 7, 13, 2, 2, 4, 6, 6, 8, 5, 17, 12, 7,
85027
- 8, 8, 2, 4, 4, 4, 4, 4, 2, 2, 4, 6, 2,
85028
- 3, 6, 5, 5, 5, 8, 3, 5, 5, 6, 4, 9, 3,
86099
+ 11, 2, 7, 5, 5, 9, 6, 9, 9, 7, 10, 10, 4,
86100
+ 6, 2, 3, 4, 9, 2, 6, 5, 6, 6, 5, 6, 5,
86101
+ 5, 7, 7, 7, 3, 4, 4, 7, 3, 6, 4, 7, 6,
86102
+ 12, 6, 9, 4, 6, 5, 4, 7, 6, 5, 6, 7, 5,
86103
+ 4, 5, 6, 5, 7, 3, 7, 13, 2, 2, 4, 6, 6,
86104
+ 8, 5, 17, 12, 7, 8, 8, 2, 4, 4, 4, 4, 4,
86105
+ 2, 2, 6, 5, 8, 5, 5, 8, 3, 5, 5, 6, 4,
86106
+ 9, 3,
8502986107
};
85030
- static const unsigned short int aOffset[117] = {
86108
+ static const unsigned short int aOffset[119] = {
8503186109
0, 2, 2, 8, 9, 14, 16, 20, 23, 25, 25, 29, 33,
8503286110
36, 41, 46, 48, 53, 54, 59, 62, 65, 67, 69, 78, 81,
85033
- 86, 95, 96, 101, 105, 109, 117, 123, 130, 138, 144, 154, 157,
85034
- 162, 167, 172, 175, 179, 179, 183, 188, 191, 195, 201, 207, 207,
85035
- 210, 213, 217, 218, 222, 228, 232, 239, 245, 257, 263, 272, 274,
85036
- 280, 285, 287, 294, 299, 304, 310, 316, 321, 325, 328, 335, 339,
85037
- 347, 349, 356, 358, 360, 369, 373, 379, 385, 393, 398, 398, 414,
85038
- 421, 428, 429, 436, 440, 444, 448, 452, 455, 457, 459, 462, 462,
85039
- 465, 468, 474, 478, 483, 487, 495, 498, 503, 508, 514, 518, 523,
86111
+ 86, 95, 96, 101, 105, 109, 117, 122, 128, 136, 142, 152, 159,
86112
+ 162, 162, 165, 167, 167, 171, 176, 179, 184, 189, 194, 197, 203,
86113
+ 206, 210, 217, 223, 223, 226, 229, 233, 234, 238, 244, 248, 255,
86114
+ 261, 273, 279, 288, 290, 296, 301, 303, 310, 315, 320, 326, 332,
86115
+ 337, 341, 344, 350, 354, 361, 363, 370, 372, 374, 383, 387, 393,
86116
+ 399, 407, 412, 412, 428, 435, 442, 443, 450, 454, 458, 462, 466,
86117
+ 469, 471, 473, 479, 483, 491, 495, 500, 508, 511, 516, 521, 527,
86118
+ 531, 536,
8504086119
};
85041
- static const unsigned char aCode[117] = {
86120
+ static const unsigned char aCode[119] = {
8504286121
TK_REINDEX, TK_INDEXED, TK_INDEX, TK_DESC, TK_ESCAPE,
8504386122
TK_EACH, TK_CHECK, TK_KEY, TK_BEFORE, TK_FOREIGN,
8504486123
TK_FOR, TK_IGNORE, TK_LIKE_KW, TK_EXPLAIN, TK_INSTEAD,
8504586124
TK_ADD, TK_DATABASE, TK_AS, TK_SELECT, TK_TABLE,
8504686125
TK_JOIN_KW, TK_THEN, TK_END, TK_DEFERRABLE, TK_ELSE,
8504786126
TK_EXCEPT, TK_TRANSACTION,TK_ON, TK_JOIN_KW, TK_ALTER,
85048
- TK_RAISE, TK_EXCLUSIVE, TK_EXISTS, TK_CONSTRAINT, TK_INTERSECT,
85049
- TK_TRIGGER, TK_REFERENCES, TK_UNIQUE, TK_QUERY, TK_ATTACH,
85050
- TK_HAVING, TK_GROUP, TK_UPDATE, TK_TEMP, TK_TEMP,
85051
- TK_OR, TK_BEGIN, TK_JOIN_KW, TK_RENAME, TK_BETWEEN,
86127
+ TK_RAISE, TK_EXCLUSIVE, TK_EXISTS, TK_SAVEPOINT, TK_INTERSECT,
86128
+ TK_TRIGGER, TK_REFERENCES, TK_CONSTRAINT, TK_INTO, TK_OFFSET,
86129
+ TK_OF, TK_SET, TK_TEMP, TK_TEMP, TK_OR,
86130
+ TK_UNIQUE, TK_QUERY, TK_ATTACH, TK_HAVING, TK_GROUP,
86131
+ TK_UPDATE, TK_BEGIN, TK_JOIN_KW, TK_RELEASE, TK_BETWEEN,
8505286132
TK_NOTNULL, TK_NOT, TK_NULL, TK_LIKE_KW, TK_CASCADE,
8505386133
TK_ASC, TK_DELETE, TK_CASE, TK_COLLATE, TK_CREATE,
8505486134
TK_CTIME_KW, TK_DETACH, TK_IMMEDIATE, TK_JOIN, TK_INSERT,
8505586135
TK_MATCH, TK_PLAN, TK_ANALYZE, TK_PRAGMA, TK_ABORT,
8505686136
TK_VALUES, TK_VIRTUAL, TK_LIMIT, TK_WHEN, TK_WHERE,
85057
- TK_REPLACE, TK_AFTER, TK_RESTRICT, TK_AND, TK_DEFAULT,
86137
+ TK_RENAME, TK_AFTER, TK_REPLACE, TK_AND, TK_DEFAULT,
8505886138
TK_AUTOINCR, TK_TO, TK_IN, TK_CAST, TK_COLUMNKW,
8505986139
TK_COMMIT, TK_CONFLICT, TK_JOIN_KW, TK_CTIME_KW, TK_CTIME_KW,
8506086140
TK_PRIMARY, TK_DEFERRED, TK_DISTINCT, TK_IS, TK_DROP,
8506186141
TK_FAIL, TK_FROM, TK_JOIN_KW, TK_LIKE_KW, TK_BY,
85062
- TK_IF, TK_INTO, TK_OFFSET, TK_OF, TK_SET,
85063
- TK_ISNULL, TK_ORDER, TK_JOIN_KW, TK_JOIN_KW, TK_ROLLBACK,
85064
- TK_ROW, TK_UNION, TK_USING, TK_VACUUM, TK_VIEW,
85065
- TK_INITIALLY, TK_ALL,
86142
+ TK_IF, TK_ISNULL, TK_ORDER, TK_RESTRICT, TK_JOIN_KW,
86143
+ TK_JOIN_KW, TK_ROLLBACK, TK_ROW, TK_UNION, TK_USING,
86144
+ TK_VACUUM, TK_VIEW, TK_INITIALLY, TK_ALL,
8506686145
};
8506786146
int h, i;
8506886147
if( n<2 ) return TK_ID;
8506986148
h = ((charMap(z[0])*4) ^
8507086149
(charMap(z[n-1])*3) ^
8507186150
n) % 127;
8507286151
for(i=((int)aHash[h])-1; i>=0; i=((int)aNext[i])-1){
8507386152
if( aLen[i]==n && sqlite3StrNICmp(&zText[aOffset[i]],z,n)==0 ){
86153
+ testcase( i==0 ); /* TK_REINDEX */
86154
+ testcase( i==1 ); /* TK_INDEXED */
86155
+ testcase( i==2 ); /* TK_INDEX */
86156
+ testcase( i==3 ); /* TK_DESC */
86157
+ testcase( i==4 ); /* TK_ESCAPE */
86158
+ testcase( i==5 ); /* TK_EACH */
86159
+ testcase( i==6 ); /* TK_CHECK */
86160
+ testcase( i==7 ); /* TK_KEY */
86161
+ testcase( i==8 ); /* TK_BEFORE */
86162
+ testcase( i==9 ); /* TK_FOREIGN */
86163
+ testcase( i==10 ); /* TK_FOR */
86164
+ testcase( i==11 ); /* TK_IGNORE */
86165
+ testcase( i==12 ); /* TK_LIKE_KW */
86166
+ testcase( i==13 ); /* TK_EXPLAIN */
86167
+ testcase( i==14 ); /* TK_INSTEAD */
86168
+ testcase( i==15 ); /* TK_ADD */
86169
+ testcase( i==16 ); /* TK_DATABASE */
86170
+ testcase( i==17 ); /* TK_AS */
86171
+ testcase( i==18 ); /* TK_SELECT */
86172
+ testcase( i==19 ); /* TK_TABLE */
86173
+ testcase( i==20 ); /* TK_JOIN_KW */
86174
+ testcase( i==21 ); /* TK_THEN */
86175
+ testcase( i==22 ); /* TK_END */
86176
+ testcase( i==23 ); /* TK_DEFERRABLE */
86177
+ testcase( i==24 ); /* TK_ELSE */
86178
+ testcase( i==25 ); /* TK_EXCEPT */
86179
+ testcase( i==26 ); /* TK_TRANSACTION */
86180
+ testcase( i==27 ); /* TK_ON */
86181
+ testcase( i==28 ); /* TK_JOIN_KW */
86182
+ testcase( i==29 ); /* TK_ALTER */
86183
+ testcase( i==30 ); /* TK_RAISE */
86184
+ testcase( i==31 ); /* TK_EXCLUSIVE */
86185
+ testcase( i==32 ); /* TK_EXISTS */
86186
+ testcase( i==33 ); /* TK_SAVEPOINT */
86187
+ testcase( i==34 ); /* TK_INTERSECT */
86188
+ testcase( i==35 ); /* TK_TRIGGER */
86189
+ testcase( i==36 ); /* TK_REFERENCES */
86190
+ testcase( i==37 ); /* TK_CONSTRAINT */
86191
+ testcase( i==38 ); /* TK_INTO */
86192
+ testcase( i==39 ); /* TK_OFFSET */
86193
+ testcase( i==40 ); /* TK_OF */
86194
+ testcase( i==41 ); /* TK_SET */
86195
+ testcase( i==42 ); /* TK_TEMP */
86196
+ testcase( i==43 ); /* TK_TEMP */
86197
+ testcase( i==44 ); /* TK_OR */
86198
+ testcase( i==45 ); /* TK_UNIQUE */
86199
+ testcase( i==46 ); /* TK_QUERY */
86200
+ testcase( i==47 ); /* TK_ATTACH */
86201
+ testcase( i==48 ); /* TK_HAVING */
86202
+ testcase( i==49 ); /* TK_GROUP */
86203
+ testcase( i==50 ); /* TK_UPDATE */
86204
+ testcase( i==51 ); /* TK_BEGIN */
86205
+ testcase( i==52 ); /* TK_JOIN_KW */
86206
+ testcase( i==53 ); /* TK_RELEASE */
86207
+ testcase( i==54 ); /* TK_BETWEEN */
86208
+ testcase( i==55 ); /* TK_NOTNULL */
86209
+ testcase( i==56 ); /* TK_NOT */
86210
+ testcase( i==57 ); /* TK_NULL */
86211
+ testcase( i==58 ); /* TK_LIKE_KW */
86212
+ testcase( i==59 ); /* TK_CASCADE */
86213
+ testcase( i==60 ); /* TK_ASC */
86214
+ testcase( i==61 ); /* TK_DELETE */
86215
+ testcase( i==62 ); /* TK_CASE */
86216
+ testcase( i==63 ); /* TK_COLLATE */
86217
+ testcase( i==64 ); /* TK_CREATE */
86218
+ testcase( i==65 ); /* TK_CTIME_KW */
86219
+ testcase( i==66 ); /* TK_DETACH */
86220
+ testcase( i==67 ); /* TK_IMMEDIATE */
86221
+ testcase( i==68 ); /* TK_JOIN */
86222
+ testcase( i==69 ); /* TK_INSERT */
86223
+ testcase( i==70 ); /* TK_MATCH */
86224
+ testcase( i==71 ); /* TK_PLAN */
86225
+ testcase( i==72 ); /* TK_ANALYZE */
86226
+ testcase( i==73 ); /* TK_PRAGMA */
86227
+ testcase( i==74 ); /* TK_ABORT */
86228
+ testcase( i==75 ); /* TK_VALUES */
86229
+ testcase( i==76 ); /* TK_VIRTUAL */
86230
+ testcase( i==77 ); /* TK_LIMIT */
86231
+ testcase( i==78 ); /* TK_WHEN */
86232
+ testcase( i==79 ); /* TK_WHERE */
86233
+ testcase( i==80 ); /* TK_RENAME */
86234
+ testcase( i==81 ); /* TK_AFTER */
86235
+ testcase( i==82 ); /* TK_REPLACE */
86236
+ testcase( i==83 ); /* TK_AND */
86237
+ testcase( i==84 ); /* TK_DEFAULT */
86238
+ testcase( i==85 ); /* TK_AUTOINCR */
86239
+ testcase( i==86 ); /* TK_TO */
86240
+ testcase( i==87 ); /* TK_IN */
86241
+ testcase( i==88 ); /* TK_CAST */
86242
+ testcase( i==89 ); /* TK_COLUMNKW */
86243
+ testcase( i==90 ); /* TK_COMMIT */
86244
+ testcase( i==91 ); /* TK_CONFLICT */
86245
+ testcase( i==92 ); /* TK_JOIN_KW */
86246
+ testcase( i==93 ); /* TK_CTIME_KW */
86247
+ testcase( i==94 ); /* TK_CTIME_KW */
86248
+ testcase( i==95 ); /* TK_PRIMARY */
86249
+ testcase( i==96 ); /* TK_DEFERRED */
86250
+ testcase( i==97 ); /* TK_DISTINCT */
86251
+ testcase( i==98 ); /* TK_IS */
86252
+ testcase( i==99 ); /* TK_DROP */
86253
+ testcase( i==100 ); /* TK_FAIL */
86254
+ testcase( i==101 ); /* TK_FROM */
86255
+ testcase( i==102 ); /* TK_JOIN_KW */
86256
+ testcase( i==103 ); /* TK_LIKE_KW */
86257
+ testcase( i==104 ); /* TK_BY */
86258
+ testcase( i==105 ); /* TK_IF */
86259
+ testcase( i==106 ); /* TK_ISNULL */
86260
+ testcase( i==107 ); /* TK_ORDER */
86261
+ testcase( i==108 ); /* TK_RESTRICT */
86262
+ testcase( i==109 ); /* TK_JOIN_KW */
86263
+ testcase( i==110 ); /* TK_JOIN_KW */
86264
+ testcase( i==111 ); /* TK_ROLLBACK */
86265
+ testcase( i==112 ); /* TK_ROW */
86266
+ testcase( i==113 ); /* TK_UNION */
86267
+ testcase( i==114 ); /* TK_USING */
86268
+ testcase( i==115 ); /* TK_VACUUM */
86269
+ testcase( i==116 ); /* TK_VIEW */
86270
+ testcase( i==117 ); /* TK_INITIALLY */
86271
+ testcase( i==118 ); /* TK_ALL */
8507486272
return aCode[i];
8507586273
}
8507686274
}
8507786275
return TK_ID;
8507886276
}
@@ -85826,11 +87024,11 @@
8582687024
** Main file for the SQLite library. The routines in this file
8582787025
** implement the programmer interface to the library. Routines in
8582887026
** other files are for internal use by SQLite and should not be
8582987027
** accessed by users of the library.
8583087028
**
85831
-** $Id: main.c,v 1.519 2008/12/10 23:04:13 drh Exp $
87029
+** $Id: main.c,v 1.520 2008/12/17 17:30:26 danielk1977 Exp $
8583287030
*/
8583387031
8583487032
#ifdef SQLITE_ENABLE_FTS3
8583587033
/************** Include fts3.h in the middle of main.c ***********************/
8583687034
/************** Begin file fts3.h ********************************************/
@@ -86442,10 +87640,25 @@
8644287640
** Return the number of changes since the database handle was opened.
8644387641
*/
8644487642
SQLITE_API int sqlite3_total_changes(sqlite3 *db){
8644587643
return db->nTotalChange;
8644687644
}
87645
+
87646
+/*
87647
+** Close all open savepoints. This function only manipulates fields of the
87648
+** database handle object, it does not close any savepoints that may be open
87649
+** at the b-tree/pager level.
87650
+*/
87651
+SQLITE_PRIVATE void sqlite3CloseSavepoints(sqlite3 *db){
87652
+ while( db->pSavepoint ){
87653
+ Savepoint *pTmp = db->pSavepoint;
87654
+ db->pSavepoint = pTmp->pNext;
87655
+ sqlite3DbFree(db, pTmp);
87656
+ }
87657
+ db->nSavepoint = 0;
87658
+ db->isTransactionSavepoint = 0;
87659
+}
8644787660
8644887661
/*
8644987662
** Close an existing SQLite database
8645087663
*/
8645187664
SQLITE_API int sqlite3_close(sqlite3 *db){
@@ -86484,10 +87697,13 @@
8648487697
"Unable to close due to unfinalised statements");
8648587698
sqlite3_mutex_leave(db->mutex);
8648687699
return SQLITE_BUSY;
8648787700
}
8648887701
assert( sqlite3SafetyCheckSickOrOk(db) );
87702
+
87703
+ /* Free any outstanding Savepoint structures. */
87704
+ sqlite3CloseSavepoints(db);
8648987705
8649087706
for(j=0; j<db->nDb; j++){
8649187707
struct Db *pDb = &db->aDb[j];
8649287708
if( pDb->pBt ){
8649387709
sqlite3BtreeClose(pDb->pBt);
@@ -88306,126 +89522,27 @@
8830689522
#if defined(SQLITE_ENABLE_FTS3) && !defined(SQLITE_CORE)
8830789523
# define SQLITE_CORE 1
8830889524
#endif
8830989525
8831089526
88311
-/************** Include fts3_hash.h in the middle of fts3.c ******************/
88312
-/************** Begin file fts3_hash.h ***************************************/
89527
+/************** Include fts3_expr.h in the middle of fts3.c ******************/
89528
+/************** Begin file fts3_expr.h ***************************************/
8831389529
/*
88314
-** 2001 September 22
89530
+** 2008 Nov 28
8831589531
**
8831689532
** The author disclaims copyright to this source code. In place of
8831789533
** a legal notice, here is a blessing:
8831889534
**
8831989535
** May you do good and not evil.
8832089536
** May you find forgiveness for yourself and forgive others.
8832189537
** May you share freely, never taking more than you give.
8832289538
**
88323
-*************************************************************************
88324
-** This is the header file for the generic hash-table implemenation
88325
-** used in SQLite. We've modified it slightly to serve as a standalone
88326
-** hash table implementation for the full-text indexing module.
88327
-**
88328
-*/
88329
-#ifndef _FTS3_HASH_H_
88330
-#define _FTS3_HASH_H_
88331
-
88332
-/* Forward declarations of structures. */
88333
-typedef struct fts3Hash fts3Hash;
88334
-typedef struct fts3HashElem fts3HashElem;
88335
-
88336
-/* A complete hash table is an instance of the following structure.
88337
-** The internals of this structure are intended to be opaque -- client
88338
-** code should not attempt to access or modify the fields of this structure
88339
-** directly. Change this structure only by using the routines below.
88340
-** However, many of the "procedures" and "functions" for modifying and
88341
-** accessing this structure are really macros, so we can't really make
88342
-** this structure opaque.
88343
-*/
88344
-struct fts3Hash {
88345
- char keyClass; /* HASH_INT, _POINTER, _STRING, _BINARY */
88346
- char copyKey; /* True if copy of key made on insert */
88347
- int count; /* Number of entries in this table */
88348
- fts3HashElem *first; /* The first element of the array */
88349
- int htsize; /* Number of buckets in the hash table */
88350
- struct _fts3ht { /* the hash table */
88351
- int count; /* Number of entries with this hash */
88352
- fts3HashElem *chain; /* Pointer to first entry with this hash */
88353
- } *ht;
88354
-};
88355
-
88356
-/* Each element in the hash table is an instance of the following
88357
-** structure. All elements are stored on a single doubly-linked list.
88358
-**
88359
-** Again, this structure is intended to be opaque, but it can't really
88360
-** be opaque because it is used by macros.
88361
-*/
88362
-struct fts3HashElem {
88363
- fts3HashElem *next, *prev; /* Next and previous elements in the table */
88364
- void *data; /* Data associated with this element */
88365
- void *pKey; int nKey; /* Key associated with this element */
88366
-};
88367
-
88368
-/*
88369
-** There are 2 different modes of operation for a hash table:
88370
-**
88371
-** FTS3_HASH_STRING pKey points to a string that is nKey bytes long
88372
-** (including the null-terminator, if any). Case
88373
-** is respected in comparisons.
88374
-**
88375
-** FTS3_HASH_BINARY pKey points to binary data nKey bytes long.
88376
-** memcmp() is used to compare keys.
88377
-**
88378
-** A copy of the key is made if the copyKey parameter to fts3HashInit is 1.
88379
-*/
88380
-#define FTS3_HASH_STRING 1
88381
-#define FTS3_HASH_BINARY 2
88382
-
88383
-/*
88384
-** Access routines. To delete, insert a NULL pointer.
88385
-*/
88386
-SQLITE_PRIVATE void sqlite3Fts3HashInit(fts3Hash*, int keytype, int copyKey);
88387
-SQLITE_PRIVATE void *sqlite3Fts3HashInsert(fts3Hash*, const void *pKey, int nKey, void *pData);
88388
-SQLITE_PRIVATE void *sqlite3Fts3HashFind(const fts3Hash*, const void *pKey, int nKey);
88389
-SQLITE_PRIVATE void sqlite3Fts3HashClear(fts3Hash*);
88390
-
88391
-/*
88392
-** Shorthand for the functions above
88393
-*/
88394
-#define fts3HashInit sqlite3Fts3HashInit
88395
-#define fts3HashInsert sqlite3Fts3HashInsert
88396
-#define fts3HashFind sqlite3Fts3HashFind
88397
-#define fts3HashClear sqlite3Fts3HashClear
88398
-
88399
-/*
88400
-** Macros for looping over all elements of a hash table. The idiom is
88401
-** like this:
88402
-**
88403
-** fts3Hash h;
88404
-** fts3HashElem *p;
88405
-** ...
88406
-** for(p=fts3HashFirst(&h); p; p=fts3HashNext(p)){
88407
-** SomeStructure *pData = fts3HashData(p);
88408
-** // do something with pData
88409
-** }
88410
-*/
88411
-#define fts3HashFirst(H) ((H)->first)
88412
-#define fts3HashNext(E) ((E)->next)
88413
-#define fts3HashData(E) ((E)->data)
88414
-#define fts3HashKey(E) ((E)->pKey)
88415
-#define fts3HashKeysize(E) ((E)->nKey)
88416
-
88417
-/*
88418
-** Number of entries in a hash table
88419
-*/
88420
-#define fts3HashCount(H) ((H)->count)
88421
-
88422
-#endif /* _FTS3_HASH_H_ */
88423
-
88424
-/************** End of fts3_hash.h *******************************************/
88425
-/************** Continuing where we left off in fts3.c ***********************/
88426
-/************** Include fts3_tokenizer.h in the middle of fts3.c *************/
89539
+******************************************************************************
89540
+**
89541
+*/
89542
+
89543
+/************** Include fts3_tokenizer.h in the middle of fts3_expr.h ********/
8842789544
/************** Begin file fts3_tokenizer.h **********************************/
8842889545
/*
8842989546
** 2006 July 10
8843089547
**
8843189548
** The author disclaims copyright to this source code.
@@ -88569,10 +89686,208 @@
8856989686
};
8857089687
8857189688
#endif /* _FTS3_TOKENIZER_H_ */
8857289689
8857389690
/************** End of fts3_tokenizer.h **************************************/
89691
+/************** Continuing where we left off in fts3_expr.h ******************/
89692
+
89693
+/*
89694
+** The following describes the syntax supported by the fts3 MATCH
89695
+** operator in a similar format to that used by the lemon parser
89696
+** generator. This module does not use actually lemon, it uses a
89697
+** custom parser.
89698
+**
89699
+** query ::= andexpr (OR andexpr)*.
89700
+**
89701
+** andexpr ::= notexpr (AND? notexpr)*.
89702
+**
89703
+** notexpr ::= nearexpr (NOT nearexpr|-TOKEN)*.
89704
+** notexpr ::= LP query RP.
89705
+**
89706
+** nearexpr ::= phrase (NEAR distance_opt nearexpr)*.
89707
+**
89708
+** distance_opt ::= .
89709
+** distance_opt ::= / INTEGER.
89710
+**
89711
+** phrase ::= TOKEN.
89712
+** phrase ::= COLUMN:TOKEN.
89713
+** phrase ::= "TOKEN TOKEN TOKEN...".
89714
+*/
89715
+
89716
+typedef struct Fts3Expr Fts3Expr;
89717
+typedef struct Fts3Phrase Fts3Phrase;
89718
+
89719
+/*
89720
+** A "phrase" is a sequence of one or more tokens that must match in
89721
+** sequence. A single token is the base case and the most common case.
89722
+** For a sequence of tokens contained in "...", nToken will be the number
89723
+** of tokens in the string.
89724
+*/
89725
+struct Fts3Phrase {
89726
+ int nToken; /* Number of tokens in the phrase */
89727
+ int iColumn; /* Index of column this phrase must match */
89728
+ int isNot; /* Phrase prefixed by unary not (-) operator */
89729
+ struct PhraseToken {
89730
+ char *z; /* Text of the token */
89731
+ int n; /* Number of bytes in buffer pointed to by z */
89732
+ int isPrefix; /* True if token ends in with a "*" character */
89733
+ } aToken[1]; /* One entry for each token in the phrase */
89734
+};
89735
+
89736
+/*
89737
+** A tree of these objects forms the RHS of a MATCH operator.
89738
+*/
89739
+struct Fts3Expr {
89740
+ int eType; /* One of the FTSQUERY_XXX values defined below */
89741
+ int nNear; /* Valid if eType==FTSQUERY_NEAR */
89742
+ Fts3Expr *pParent; /* pParent->pLeft==this or pParent->pRight==this */
89743
+ Fts3Expr *pLeft; /* Left operand */
89744
+ Fts3Expr *pRight; /* Right operand */
89745
+ Fts3Phrase *pPhrase; /* Valid if eType==FTSQUERY_PHRASE */
89746
+};
89747
+
89748
+SQLITE_PRIVATE int sqlite3Fts3ExprParse(sqlite3_tokenizer *, char **, int, int,
89749
+ const char *, int, Fts3Expr **);
89750
+SQLITE_PRIVATE void sqlite3Fts3ExprFree(Fts3Expr *);
89751
+
89752
+/*
89753
+** Candidate values for Fts3Query.eType. Note that the order of the first
89754
+** four values is in order of precedence when parsing expressions. For
89755
+** example, the following:
89756
+**
89757
+** "a OR b AND c NOT d NEAR e"
89758
+**
89759
+** is equivalent to:
89760
+**
89761
+** "a OR (b AND (c NOT (d NEAR e)))"
89762
+*/
89763
+#define FTSQUERY_NEAR 1
89764
+#define FTSQUERY_NOT 2
89765
+#define FTSQUERY_AND 3
89766
+#define FTSQUERY_OR 4
89767
+#define FTSQUERY_PHRASE 5
89768
+
89769
+#ifdef SQLITE_TEST
89770
+SQLITE_PRIVATE void sqlite3Fts3ExprInitTestInterface(sqlite3 *db);
89771
+#endif
89772
+
89773
+/************** End of fts3_expr.h *******************************************/
89774
+/************** Continuing where we left off in fts3.c ***********************/
89775
+/************** Include fts3_hash.h in the middle of fts3.c ******************/
89776
+/************** Begin file fts3_hash.h ***************************************/
89777
+/*
89778
+** 2001 September 22
89779
+**
89780
+** The author disclaims copyright to this source code. In place of
89781
+** a legal notice, here is a blessing:
89782
+**
89783
+** May you do good and not evil.
89784
+** May you find forgiveness for yourself and forgive others.
89785
+** May you share freely, never taking more than you give.
89786
+**
89787
+*************************************************************************
89788
+** This is the header file for the generic hash-table implemenation
89789
+** used in SQLite. We've modified it slightly to serve as a standalone
89790
+** hash table implementation for the full-text indexing module.
89791
+**
89792
+*/
89793
+#ifndef _FTS3_HASH_H_
89794
+#define _FTS3_HASH_H_
89795
+
89796
+/* Forward declarations of structures. */
89797
+typedef struct fts3Hash fts3Hash;
89798
+typedef struct fts3HashElem fts3HashElem;
89799
+
89800
+/* A complete hash table is an instance of the following structure.
89801
+** The internals of this structure are intended to be opaque -- client
89802
+** code should not attempt to access or modify the fields of this structure
89803
+** directly. Change this structure only by using the routines below.
89804
+** However, many of the "procedures" and "functions" for modifying and
89805
+** accessing this structure are really macros, so we can't really make
89806
+** this structure opaque.
89807
+*/
89808
+struct fts3Hash {
89809
+ char keyClass; /* HASH_INT, _POINTER, _STRING, _BINARY */
89810
+ char copyKey; /* True if copy of key made on insert */
89811
+ int count; /* Number of entries in this table */
89812
+ fts3HashElem *first; /* The first element of the array */
89813
+ int htsize; /* Number of buckets in the hash table */
89814
+ struct _fts3ht { /* the hash table */
89815
+ int count; /* Number of entries with this hash */
89816
+ fts3HashElem *chain; /* Pointer to first entry with this hash */
89817
+ } *ht;
89818
+};
89819
+
89820
+/* Each element in the hash table is an instance of the following
89821
+** structure. All elements are stored on a single doubly-linked list.
89822
+**
89823
+** Again, this structure is intended to be opaque, but it can't really
89824
+** be opaque because it is used by macros.
89825
+*/
89826
+struct fts3HashElem {
89827
+ fts3HashElem *next, *prev; /* Next and previous elements in the table */
89828
+ void *data; /* Data associated with this element */
89829
+ void *pKey; int nKey; /* Key associated with this element */
89830
+};
89831
+
89832
+/*
89833
+** There are 2 different modes of operation for a hash table:
89834
+**
89835
+** FTS3_HASH_STRING pKey points to a string that is nKey bytes long
89836
+** (including the null-terminator, if any). Case
89837
+** is respected in comparisons.
89838
+**
89839
+** FTS3_HASH_BINARY pKey points to binary data nKey bytes long.
89840
+** memcmp() is used to compare keys.
89841
+**
89842
+** A copy of the key is made if the copyKey parameter to fts3HashInit is 1.
89843
+*/
89844
+#define FTS3_HASH_STRING 1
89845
+#define FTS3_HASH_BINARY 2
89846
+
89847
+/*
89848
+** Access routines. To delete, insert a NULL pointer.
89849
+*/
89850
+SQLITE_PRIVATE void sqlite3Fts3HashInit(fts3Hash*, int keytype, int copyKey);
89851
+SQLITE_PRIVATE void *sqlite3Fts3HashInsert(fts3Hash*, const void *pKey, int nKey, void *pData);
89852
+SQLITE_PRIVATE void *sqlite3Fts3HashFind(const fts3Hash*, const void *pKey, int nKey);
89853
+SQLITE_PRIVATE void sqlite3Fts3HashClear(fts3Hash*);
89854
+
89855
+/*
89856
+** Shorthand for the functions above
89857
+*/
89858
+#define fts3HashInit sqlite3Fts3HashInit
89859
+#define fts3HashInsert sqlite3Fts3HashInsert
89860
+#define fts3HashFind sqlite3Fts3HashFind
89861
+#define fts3HashClear sqlite3Fts3HashClear
89862
+
89863
+/*
89864
+** Macros for looping over all elements of a hash table. The idiom is
89865
+** like this:
89866
+**
89867
+** fts3Hash h;
89868
+** fts3HashElem *p;
89869
+** ...
89870
+** for(p=fts3HashFirst(&h); p; p=fts3HashNext(p)){
89871
+** SomeStructure *pData = fts3HashData(p);
89872
+** // do something with pData
89873
+** }
89874
+*/
89875
+#define fts3HashFirst(H) ((H)->first)
89876
+#define fts3HashNext(E) ((E)->next)
89877
+#define fts3HashData(E) ((E)->data)
89878
+#define fts3HashKey(E) ((E)->pKey)
89879
+#define fts3HashKeysize(E) ((E)->nKey)
89880
+
89881
+/*
89882
+** Number of entries in a hash table
89883
+*/
89884
+#define fts3HashCount(H) ((H)->count)
89885
+
89886
+#endif /* _FTS3_HASH_H_ */
89887
+
89888
+/************** End of fts3_hash.h *******************************************/
8857489889
/************** Continuing where we left off in fts3.c ***********************/
8857589890
#ifndef SQLITE_CORE
8857689891
SQLITE_EXTENSION_INIT1
8857789892
#endif
8857889893
@@ -88594,15 +89909,10 @@
8859489909
# define FTSTRACE(A) printf A; fflush(stdout)
8859589910
#else
8859689911
# define FTSTRACE(A)
8859789912
#endif
8859889913
88599
-/*
88600
-** Default span for NEAR operators.
88601
-*/
88602
-#define SQLITE_FTS3_DEFAULT_NEAR_PARAM 10
88603
-
8860489914
/* It is not safe to call isspace(), tolower(), or isalnum() on
8860589915
** hi-bit-set characters. This is the same solution used in the
8860689916
** tokenizer.
8860789917
*/
8860889918
/* TODO(shess) The snippet-generation code should be using the
@@ -90069,94 +91379,10 @@
9006991379
9007091380
/* end utility functions */
9007191381
9007291382
/* Forward reference */
9007391383
typedef struct fulltext_vtab fulltext_vtab;
90074
-
90075
-/* A single term in a query is represented by an instances of
90076
-** the following structure. Each word which may match against
90077
-** document content is a term. Operators, like NEAR or OR, are
90078
-** not terms. Query terms are organized as a flat list stored
90079
-** in the Query.pTerms array.
90080
-**
90081
-** If the QueryTerm.nPhrase variable is non-zero, then the QueryTerm
90082
-** is the first in a contiguous string of terms that are either part
90083
-** of the same phrase, or connected by the NEAR operator.
90084
-**
90085
-** If the QueryTerm.nNear variable is non-zero, then the token is followed
90086
-** by a NEAR operator with span set to (nNear-1). For example, the
90087
-** following query:
90088
-**
90089
-** The QueryTerm.iPhrase variable stores the index of the token within
90090
-** its phrase, indexed starting at 1, or 1 if the token is not part
90091
-** of any phrase.
90092
-**
90093
-** For example, the data structure used to represent the following query:
90094
-**
90095
-** ... MATCH 'sqlite NEAR/5 google NEAR/2 "search engine"'
90096
-**
90097
-** is:
90098
-**
90099
-** {nPhrase=4, iPhrase=1, nNear=6, pTerm="sqlite"},
90100
-** {nPhrase=0, iPhrase=1, nNear=3, pTerm="google"},
90101
-** {nPhrase=0, iPhrase=1, nNear=0, pTerm="search"},
90102
-** {nPhrase=0, iPhrase=2, nNear=0, pTerm="engine"},
90103
-**
90104
-** compiling the FTS3 syntax to Query structures is done by the parseQuery()
90105
-** function.
90106
-*/
90107
-typedef struct QueryTerm {
90108
- short int nPhrase; /* How many following terms are part of the same phrase */
90109
- short int iPhrase; /* This is the i-th term of a phrase. */
90110
- short int iColumn; /* Column of the index that must match this term */
90111
- short int nNear; /* term followed by a NEAR operator with span=(nNear-1) */
90112
- signed char isOr; /* this term is preceded by "OR" */
90113
- signed char isNot; /* this term is preceded by "-" */
90114
- signed char isPrefix; /* this term is followed by "*" */
90115
- char *pTerm; /* text of the term. '\000' terminated. malloced */
90116
- int nTerm; /* Number of bytes in pTerm[] */
90117
-} QueryTerm;
90118
-
90119
-
90120
-/* A query string is parsed into a Query structure.
90121
- *
90122
- * We could, in theory, allow query strings to be complicated
90123
- * nested expressions with precedence determined by parentheses.
90124
- * But none of the major search engines do this. (Perhaps the
90125
- * feeling is that an parenthesized expression is two complex of
90126
- * an idea for the average user to grasp.) Taking our lead from
90127
- * the major search engines, we will allow queries to be a list
90128
- * of terms (with an implied AND operator) or phrases in double-quotes,
90129
- * with a single optional "-" before each non-phrase term to designate
90130
- * negation and an optional OR connector.
90131
- *
90132
- * OR binds more tightly than the implied AND, which is what the
90133
- * major search engines seem to do. So, for example:
90134
- *
90135
- * [one two OR three] ==> one AND (two OR three)
90136
- * [one OR two three] ==> (one OR two) AND three
90137
- *
90138
- * A "-" before a term matches all entries that lack that term.
90139
- * The "-" must occur immediately before the term with in intervening
90140
- * space. This is how the search engines do it.
90141
- *
90142
- * A NOT term cannot be the right-hand operand of an OR. If this
90143
- * occurs in the query string, the NOT is ignored:
90144
- *
90145
- * [one OR -two] ==> one OR two
90146
- *
90147
- */
90148
-typedef struct Query {
90149
- fulltext_vtab *pFts; /* The full text index */
90150
- int nTerms; /* Number of terms in the query */
90151
- QueryTerm *pTerms; /* Array of terms. Space obtained from malloc() */
90152
- int nextIsOr; /* Set the isOr flag on the next inserted term */
90153
- int nextIsNear; /* Set the isOr flag on the next inserted term */
90154
- int nextColumn; /* Next word parsed must be in this column */
90155
- int dfltColumn; /* The default column */
90156
-} Query;
90157
-
9015891384
9015991385
/*
9016091386
** An instance of the following structure keeps track of generated
9016191387
** matching-word offset information and snippets.
9016291388
*/
@@ -90304,18 +91530,18 @@
9030491530
typedef struct fulltext_cursor {
9030591531
sqlite3_vtab_cursor base; /* Base class used by SQLite core */
9030691532
QueryType iCursorType; /* Copy of sqlite3_index_info.idxNum */
9030791533
sqlite3_stmt *pStmt; /* Prepared statement in use by the cursor */
9030891534
int eof; /* True if at End Of Results */
90309
- Query q; /* Parsed query string */
91535
+ Fts3Expr *pExpr; /* Parsed MATCH query string */
9031091536
Snippet snippet; /* Cached snippet for the current row */
9031191537
int iColumn; /* Column being searched */
9031291538
DataBuffer result; /* Doclist results from fulltextQuery */
9031391539
DLReader reader; /* Result reader if result not empty */
9031491540
} fulltext_cursor;
9031591541
90316
-static struct fulltext_vtab *cursor_vtab(fulltext_cursor *c){
91542
+static fulltext_vtab *cursor_vtab(fulltext_cursor *c){
9031791543
return (fulltext_vtab *) c->base.pVtab;
9031891544
}
9031991545
9032091546
static const sqlite3_module fts3Module; /* forward declaration */
9032191547
@@ -91459,31 +92685,20 @@
9145992685
}else{
9146092686
return SQLITE_NOMEM;
9146192687
}
9146292688
}
9146392689
91464
-
91465
-/* Free all of the dynamically allocated memory held by *q
91466
-*/
91467
-static void queryClear(Query *q){
91468
- int i;
91469
- for(i = 0; i < q->nTerms; ++i){
91470
- sqlite3_free(q->pTerms[i].pTerm);
91471
- }
91472
- sqlite3_free(q->pTerms);
91473
- CLEAR(q);
91474
-}
91475
-
9147692690
/* Free all of the dynamically allocated memory held by the
9147792691
** Snippet
9147892692
*/
9147992693
static void snippetClear(Snippet *p){
9148092694
sqlite3_free(p->aMatch);
9148192695
sqlite3_free(p->zOffset);
9148292696
sqlite3_free(p->zSnippet);
9148392697
CLEAR(p);
9148492698
}
92699
+
9148592700
/*
9148692701
** Append a single entry to the p->aMatch[] log.
9148792702
*/
9148892703
static void snippetAppendMatch(
9148992704
Snippet *p, /* Append the entry to this snippet */
@@ -91514,29 +92729,88 @@
9151492729
/*
9151592730
** Sizing information for the circular buffer used in snippetOffsetsOfColumn()
9151692731
*/
9151792732
#define FTS3_ROTOR_SZ (32)
9151892733
#define FTS3_ROTOR_MASK (FTS3_ROTOR_SZ-1)
92734
+
92735
+/*
92736
+** Function to iterate through the tokens of a compiled expression.
92737
+**
92738
+** Except, skip all tokens on the right-hand side of a NOT operator.
92739
+** This function is used to find tokens as part of snippet and offset
92740
+** generation and we do nt want snippets and offsets to report matches
92741
+** for tokens on the RHS of a NOT.
92742
+*/
92743
+static int fts3NextExprToken(Fts3Expr **ppExpr, int *piToken){
92744
+ Fts3Expr *p = *ppExpr;
92745
+ int iToken = *piToken;
92746
+ if( iToken<0 ){
92747
+ /* In this case the expression p is the root of an expression tree.
92748
+ ** Move to the first token in the expression tree.
92749
+ */
92750
+ while( p->pLeft ){
92751
+ p = p->pLeft;
92752
+ }
92753
+ iToken = 0;
92754
+ }else{
92755
+ assert(p && p->eType==FTSQUERY_PHRASE );
92756
+ if( iToken<(p->pPhrase->nToken-1) ){
92757
+ iToken++;
92758
+ }else{
92759
+ iToken = 0;
92760
+ while( p->pParent && p->pParent->pLeft!=p ){
92761
+ assert( p->pParent->pRight==p );
92762
+ p = p->pParent;
92763
+ }
92764
+ p = p->pParent;
92765
+ if( p ){
92766
+ assert( p->pRight!=0 );
92767
+ p = p->pRight;
92768
+ while( p->pLeft ){
92769
+ p = p->pLeft;
92770
+ }
92771
+ }
92772
+ }
92773
+ }
92774
+
92775
+ *ppExpr = p;
92776
+ *piToken = iToken;
92777
+ return p?1:0;
92778
+}
92779
+
92780
+/*
92781
+** Return TRUE if the expression node pExpr is located beneath the
92782
+** RHS of a NOT operator.
92783
+*/
92784
+static int fts3ExprBeneathNot(Fts3Expr *p){
92785
+ Fts3Expr *pParent;
92786
+ while( p ){
92787
+ pParent = p->pParent;
92788
+ if( pParent && pParent->eType==FTSQUERY_NOT && pParent->pRight==p ){
92789
+ return 1;
92790
+ }
92791
+ p = pParent;
92792
+ }
92793
+ return 0;
92794
+}
9151992795
9152092796
/*
9152192797
** Add entries to pSnippet->aMatch[] for every match that occurs against
9152292798
** document zDoc[0..nDoc-1] which is stored in column iColumn.
9152392799
*/
9152492800
static void snippetOffsetsOfColumn(
91525
- Query *pQuery,
91526
- Snippet *pSnippet,
91527
- int iColumn,
91528
- const char *zDoc,
91529
- int nDoc
92801
+ fulltext_cursor *pCur, /* The fulltest search cursor */
92802
+ Snippet *pSnippet, /* The Snippet object to be filled in */
92803
+ int iColumn, /* Index of fulltext table column */
92804
+ const char *zDoc, /* Text of the fulltext table column */
92805
+ int nDoc /* Length of zDoc in bytes */
9153092806
){
9153192807
const sqlite3_tokenizer_module *pTModule; /* The tokenizer module */
9153292808
sqlite3_tokenizer *pTokenizer; /* The specific tokenizer */
9153392809
sqlite3_tokenizer_cursor *pTCursor; /* Tokenizer cursor */
9153492810
fulltext_vtab *pVtab; /* The full text index */
9153592811
int nColumn; /* Number of columns in the index */
91536
- const QueryTerm *aTerm; /* Query string terms */
91537
- int nTerm; /* Number of query string terms */
9153892812
int i, j; /* Loop counters */
9153992813
int rc; /* Return code */
9154092814
unsigned int match, prevMatch; /* Phrase search bitmasks */
9154192815
const char *zToken; /* Next token from the tokenizer */
9154292816
int nToken; /* Size of zToken */
@@ -91546,41 +92820,43 @@
9154692820
** few tokens */
9154792821
unsigned int iRotor = 0; /* Index of current token */
9154892822
int iRotorBegin[FTS3_ROTOR_SZ]; /* Beginning offset of token */
9154992823
int iRotorLen[FTS3_ROTOR_SZ]; /* Length of token */
9155092824
91551
- pVtab = pQuery->pFts;
92825
+ pVtab = cursor_vtab(pCur);
9155292826
nColumn = pVtab->nColumn;
9155392827
pTokenizer = pVtab->pTokenizer;
9155492828
pTModule = pTokenizer->pModule;
9155592829
rc = pTModule->xOpen(pTokenizer, zDoc, nDoc, &pTCursor);
9155692830
if( rc ) return;
9155792831
pTCursor->pTokenizer = pTokenizer;
91558
- aTerm = pQuery->pTerms;
91559
- nTerm = pQuery->nTerms;
91560
- if( nTerm>=FTS3_ROTOR_SZ ){
91561
- nTerm = FTS3_ROTOR_SZ - 1;
91562
- }
92832
+
9156392833
prevMatch = 0;
91564
- while(1){
91565
- rc = pTModule->xNext(pTCursor, &zToken, &nToken, &iBegin, &iEnd, &iPos);
91566
- if( rc ) break;
92834
+ while( !pTModule->xNext(pTCursor, &zToken, &nToken, &iBegin, &iEnd, &iPos) ){
92835
+ Fts3Expr *pIter = pCur->pExpr;
92836
+ int iIter = -1;
9156792837
iRotorBegin[iRotor&FTS3_ROTOR_MASK] = iBegin;
9156892838
iRotorLen[iRotor&FTS3_ROTOR_MASK] = iEnd-iBegin;
9156992839
match = 0;
91570
- for(i=0; i<nTerm; i++){
91571
- int iCol;
91572
- iCol = aTerm[i].iColumn;
92840
+ for(i=0; i<(FTS3_ROTOR_SZ-1) && fts3NextExprToken(&pIter, &iIter); i++){
92841
+ int nPhrase; /* Number of tokens in current phrase */
92842
+ struct PhraseToken *pToken; /* Current token */
92843
+ int iCol; /* Column index */
92844
+
92845
+ if( fts3ExprBeneathNot(pIter) ) continue;
92846
+ nPhrase = pIter->pPhrase->nToken;
92847
+ pToken = &pIter->pPhrase->aToken[iIter];
92848
+ iCol = pIter->pPhrase->iColumn;
9157392849
if( iCol>=0 && iCol<nColumn && iCol!=iColumn ) continue;
91574
- if( aTerm[i].nTerm>nToken ) continue;
91575
- if( !aTerm[i].isPrefix && aTerm[i].nTerm<nToken ) continue;
91576
- assert( aTerm[i].nTerm<=nToken );
91577
- if( memcmp(aTerm[i].pTerm, zToken, aTerm[i].nTerm) ) continue;
91578
- if( aTerm[i].iPhrase>1 && (prevMatch & (1<<i))==0 ) continue;
92850
+ if( pToken->n>nToken ) continue;
92851
+ if( !pToken->isPrefix && pToken->n<nToken ) continue;
92852
+ assert( pToken->n<=nToken );
92853
+ if( memcmp(pToken->z, zToken, pToken->n) ) continue;
92854
+ if( iIter>0 && (prevMatch & (1<<i))==0 ) continue;
9157992855
match |= 1<<i;
91580
- if( i==nTerm-1 || aTerm[i+1].iPhrase==1 ){
91581
- for(j=aTerm[i].iPhrase-1; j>=0; j--){
92856
+ if( i==(FTS3_ROTOR_SZ-2) || nPhrase==iIter+1 ){
92857
+ for(j=nPhrase-1; j>=0; j--){
9158292858
int k = (iRotor-j) & FTS3_ROTOR_MASK;
9158392859
snippetAppendMatch(pSnippet, iColumn, i-j, iPos-j,
9158492860
iRotorBegin[k], iRotorLen[k]);
9158592861
}
9158692862
}
@@ -91606,90 +92882,119 @@
9160692882
** A NEAR/0 E
9160792883
**
9160892884
** then when this function is called the Snippet contains token offsets
9160992885
** 0, 4 and 5. This function removes the "0" entry (because the first A
9161092886
** is not near enough to an E).
91611
-*/
91612
-static void trimSnippetOffsetsForNear(Query *pQuery, Snippet *pSnippet){
91613
- int ii;
91614
- int iDir = 1;
91615
-
91616
- while(iDir>-2) {
91617
- assert( iDir==1 || iDir==-1 );
91618
- for(ii=0; ii<pSnippet->nMatch; ii++){
91619
- int jj;
91620
- int nNear;
91621
- struct snippetMatch *pMatch = &pSnippet->aMatch[ii];
91622
- QueryTerm *pQueryTerm = &pQuery->pTerms[pMatch->iTerm];
91623
-
91624
- if( (pMatch->iTerm+iDir)<0
91625
- || (pMatch->iTerm+iDir)>=pQuery->nTerms
91626
- ){
91627
- continue;
91628
- }
91629
-
91630
- nNear = pQueryTerm->nNear;
91631
- if( iDir<0 ){
91632
- nNear = pQueryTerm[-1].nNear;
91633
- }
91634
-
91635
- if( pMatch->iTerm>=0 && nNear ){
91636
- int isOk = 0;
91637
- int iNextTerm = pMatch->iTerm+iDir;
91638
- int iPrevTerm = iNextTerm;
91639
-
91640
- int iEndToken;
91641
- int iStartToken;
91642
-
91643
- if( iDir<0 ){
91644
- int nPhrase = 1;
91645
- iStartToken = pMatch->iToken;
91646
- while( (pMatch->iTerm+nPhrase)<pQuery->nTerms
91647
- && pQuery->pTerms[pMatch->iTerm+nPhrase].iPhrase>1
91648
- ){
91649
- nPhrase++;
91650
- }
91651
- iEndToken = iStartToken + nPhrase - 1;
91652
- }else{
91653
- iEndToken = pMatch->iToken;
91654
- iStartToken = pMatch->iToken+1-pQueryTerm->iPhrase;
91655
- }
91656
-
91657
- while( pQuery->pTerms[iNextTerm].iPhrase>1 ){
91658
- iNextTerm--;
91659
- }
91660
- while( (iPrevTerm+1)<pQuery->nTerms &&
91661
- pQuery->pTerms[iPrevTerm+1].iPhrase>1
91662
- ){
91663
- iPrevTerm++;
91664
- }
91665
-
91666
- for(jj=0; isOk==0 && jj<pSnippet->nMatch; jj++){
91667
- struct snippetMatch *p = &pSnippet->aMatch[jj];
91668
- if( p->iCol==pMatch->iCol && ((
91669
- p->iTerm==iNextTerm &&
91670
- p->iToken>iEndToken &&
91671
- p->iToken<=iEndToken+nNear
91672
- ) || (
91673
- p->iTerm==iPrevTerm &&
91674
- p->iToken<iStartToken &&
91675
- p->iToken>=iStartToken-nNear
91676
- ))){
91677
- isOk = 1;
91678
- }
91679
- }
91680
- if( !isOk ){
91681
- for(jj=1-pQueryTerm->iPhrase; jj<=0; jj++){
91682
- pMatch[jj].iTerm = -1;
91683
- }
91684
- ii = -1;
91685
- iDir = 1;
91686
- }
91687
- }
91688
- }
91689
- iDir -= 2;
91690
- }
92887
+**
92888
+** When this function is called, the value pointed to by parameter piLeft is
92889
+** the integer id of the left-most token in the expression tree headed by
92890
+** pExpr. This function increments *piLeft by the total number of tokens
92891
+** in the expression tree headed by pExpr.
92892
+**
92893
+** Return 1 if any trimming occurs. Return 0 if no trimming is required.
92894
+*/
92895
+static int trimSnippetOffsets(
92896
+ Fts3Expr *pExpr, /* The search expression */
92897
+ Snippet *pSnippet, /* The set of snippet offsets to be trimmed */
92898
+ int *piLeft /* Index of left-most token in pExpr */
92899
+){
92900
+ if( pExpr ){
92901
+ if( trimSnippetOffsets(pExpr->pLeft, pSnippet, piLeft) ){
92902
+ return 1;
92903
+ }
92904
+
92905
+ switch( pExpr->eType ){
92906
+ case FTSQUERY_PHRASE:
92907
+ *piLeft += pExpr->pPhrase->nToken;
92908
+ break;
92909
+ case FTSQUERY_NEAR: {
92910
+ /* The right-hand-side of a NEAR operator is always a phrase. The
92911
+ ** left-hand-side is either a phrase or an expression tree that is
92912
+ ** itself headed by a NEAR operator. The following initializations
92913
+ ** set local variable iLeft to the token number of the left-most
92914
+ ** token in the right-hand phrase, and iRight to the right most
92915
+ ** token in the same phrase. For example, if we had:
92916
+ **
92917
+ ** <col> MATCH '"abc def" NEAR/2 "ghi jkl"'
92918
+ **
92919
+ ** then iLeft will be set to 2 (token number of ghi) and nToken will
92920
+ ** be set to 4.
92921
+ */
92922
+ Fts3Expr *pLeft = pExpr->pLeft;
92923
+ Fts3Expr *pRight = pExpr->pRight;
92924
+ int iLeft = *piLeft;
92925
+ int nNear = pExpr->nNear;
92926
+ int nToken = pRight->pPhrase->nToken;
92927
+ int jj, ii;
92928
+ if( pLeft->eType==FTSQUERY_NEAR ){
92929
+ pLeft = pLeft->pRight;
92930
+ }
92931
+ assert( pRight->eType==FTSQUERY_PHRASE );
92932
+ assert( pLeft->eType==FTSQUERY_PHRASE );
92933
+ nToken += pLeft->pPhrase->nToken;
92934
+
92935
+ for(ii=0; ii<pSnippet->nMatch; ii++){
92936
+ struct snippetMatch *p = &pSnippet->aMatch[ii];
92937
+ if( p->iTerm==iLeft ){
92938
+ int isOk = 0;
92939
+ /* Snippet ii is an occurence of query term iLeft in the document.
92940
+ ** It occurs at position (p->iToken) of the document. We now
92941
+ ** search for an instance of token (iLeft-1) somewhere in the
92942
+ ** range (p->iToken - nNear)...(p->iToken + nNear + nToken) within
92943
+ ** the set of snippetMatch structures. If one is found, proceed.
92944
+ ** If one cannot be found, then remove snippets ii..(ii+N-1)
92945
+ ** from the matching snippets, where N is the number of tokens
92946
+ ** in phrase pRight->pPhrase.
92947
+ */
92948
+ for(jj=0; isOk==0 && jj<pSnippet->nMatch; jj++){
92949
+ struct snippetMatch *p2 = &pSnippet->aMatch[jj];
92950
+ if( p2->iTerm==(iLeft-1) ){
92951
+ if( p2->iToken>=(p->iToken-nNear-1)
92952
+ && p2->iToken<(p->iToken+nNear+nToken)
92953
+ ){
92954
+ isOk = 1;
92955
+ }
92956
+ }
92957
+ }
92958
+ if( !isOk ){
92959
+ int kk;
92960
+ for(kk=0; kk<pRight->pPhrase->nToken; kk++){
92961
+ pSnippet->aMatch[kk+ii].iTerm = -2;
92962
+ }
92963
+ return 1;
92964
+ }
92965
+ }
92966
+ if( p->iTerm==(iLeft-1) ){
92967
+ int isOk = 0;
92968
+ for(jj=0; isOk==0 && jj<pSnippet->nMatch; jj++){
92969
+ struct snippetMatch *p2 = &pSnippet->aMatch[jj];
92970
+ if( p2->iTerm==iLeft ){
92971
+ if( p2->iToken<=(p->iToken+nNear+1)
92972
+ && p2->iToken>(p->iToken-nNear-nToken)
92973
+ ){
92974
+ isOk = 1;
92975
+ }
92976
+ }
92977
+ }
92978
+ if( !isOk ){
92979
+ int kk;
92980
+ for(kk=0; kk<pLeft->pPhrase->nToken; kk++){
92981
+ pSnippet->aMatch[ii-kk].iTerm = -2;
92982
+ }
92983
+ return 1;
92984
+ }
92985
+ }
92986
+ }
92987
+ break;
92988
+ }
92989
+ }
92990
+
92991
+ if( trimSnippetOffsets(pExpr->pRight, pSnippet, piLeft) ){
92992
+ return 1;
92993
+ }
92994
+ }
92995
+ return 0;
9169192996
}
9169292997
9169392998
/*
9169492999
** Compute all offsets for the current row of the query.
9169593000
** If the offsets have already been computed, this routine is a no-op.
@@ -91696,38 +93001,44 @@
9169693001
*/
9169793002
static void snippetAllOffsets(fulltext_cursor *p){
9169893003
int nColumn;
9169993004
int iColumn, i;
9170093005
int iFirst, iLast;
91701
- fulltext_vtab *pFts;
93006
+ int iTerm = 0;
93007
+ fulltext_vtab *pFts = cursor_vtab(p);
9170293008
91703
- if( p->snippet.nMatch ) return;
91704
- if( p->q.nTerms==0 ) return;
91705
- pFts = p->q.pFts;
93009
+ if( p->snippet.nMatch || p->pExpr==0 ){
93010
+ return;
93011
+ }
9170693012
nColumn = pFts->nColumn;
9170793013
iColumn = (p->iCursorType - QUERY_FULLTEXT);
9170893014
if( iColumn<0 || iColumn>=nColumn ){
93015
+ /* Look for matches over all columns of the full-text index */
9170993016
iFirst = 0;
9171093017
iLast = nColumn-1;
9171193018
}else{
93019
+ /* Look for matches in the iColumn-th column of the index only */
9171293020
iFirst = iColumn;
9171393021
iLast = iColumn;
9171493022
}
9171593023
for(i=iFirst; i<=iLast; i++){
9171693024
const char *zDoc;
9171793025
int nDoc;
9171893026
zDoc = (const char*)sqlite3_column_text(p->pStmt, i+1);
9171993027
nDoc = sqlite3_column_bytes(p->pStmt, i+1);
91720
- snippetOffsetsOfColumn(&p->q, &p->snippet, i, zDoc, nDoc);
93028
+ snippetOffsetsOfColumn(p, &p->snippet, i, zDoc, nDoc);
9172193029
}
9172293030
91723
- trimSnippetOffsetsForNear(&p->q, &p->snippet);
93031
+ while( trimSnippetOffsets(p->pExpr, &p->snippet, &iTerm) ){
93032
+ iTerm = 0;
93033
+ }
9172493034
}
9172593035
9172693036
/*
9172793037
** Convert the information in the aMatch[] array of the snippet
91728
-** into the string zOffset[0..nOffset-1].
93038
+** into the string zOffset[0..nOffset-1]. This string is used as
93039
+** the return of the SQL offsets() function.
9172993040
*/
9173093041
static void snippetOffsetText(Snippet *p){
9173193042
int i;
9173293043
int cnt = 0;
9173393044
StringBuffer sb;
@@ -91838,11 +93149,11 @@
9183893149
9183993150
for(i=0; i<nMatch; i++){
9184093151
aMatch[i].snStatus = SNIPPET_IGNORE;
9184193152
}
9184293153
nDesired = 0;
91843
- for(i=0; i<pCursor->q.nTerms; i++){
93154
+ for(i=0; i<FTS3_ROTOR_SZ; i++){
9184493155
for(j=0; j<nMatch; j++){
9184593156
if( aMatch[j].iTerm==i ){
9184693157
aMatch[j].snStatus = SNIPPET_DESIRED;
9184793158
nDesired++;
9184893159
break;
@@ -91926,13 +93237,15 @@
9192693237
*/
9192793238
static int fulltextClose(sqlite3_vtab_cursor *pCursor){
9192893239
fulltext_cursor *c = (fulltext_cursor *) pCursor;
9192993240
FTSTRACE(("FTS3 Close %p\n", c));
9193093241
sqlite3_finalize(c->pStmt);
91931
- queryClear(&c->q);
93242
+ sqlite3Fts3ExprFree(c->pExpr);
9193293243
snippetClear(&c->snippet);
91933
- if( c->result.nData!=0 ) dlrDestroy(&c->reader);
93244
+ if( c->result.nData!=0 ){
93245
+ dlrDestroy(&c->reader);
93246
+ }
9193493247
dataBufferDestroy(&c->result);
9193593248
sqlite3_free(c);
9193693249
return SQLITE_OK;
9193793250
}
9193893251
@@ -91985,259 +93298,131 @@
9198593298
*/
9198693299
static int termSelect(fulltext_vtab *v, int iColumn,
9198793300
const char *pTerm, int nTerm, int isPrefix,
9198893301
DocListType iType, DataBuffer *out);
9198993302
91990
-/* Return a DocList corresponding to the query term *pTerm. If *pTerm
91991
-** is the first term of a phrase query, go ahead and evaluate the phrase
91992
-** query and return the doclist for the entire phrase query.
93303
+/*
93304
+** Return a DocList corresponding to the phrase *pPhrase.
9199393305
**
9199493306
** The resulting DL_DOCIDS doclist is stored in pResult, which is
9199593307
** overwritten.
9199693308
*/
91997
-static int docListOfTerm(
91998
- fulltext_vtab *v, /* The full text index */
91999
- int iColumn, /* column to restrict to. No restriction if >=nColumn */
92000
- QueryTerm *pQTerm, /* Term we are looking for, or 1st term of a phrase */
92001
- DataBuffer *pResult /* Write the result here */
93309
+static int docListOfPhrase(
93310
+ fulltext_vtab *pTab, /* The full text index */
93311
+ Fts3Phrase *pPhrase, /* Phrase to return a doclist corresponding to */
93312
+ DocListType eListType, /* Either DL_DOCIDS or DL_POSITIONS */
93313
+ DataBuffer *pResult /* Write the result here */
9200293314
){
92003
- DataBuffer left, right, new;
92004
- int i, rc;
92005
-
92006
- /* No phrase search if no position info. */
92007
- assert( pQTerm->nPhrase==0 || DL_DEFAULT!=DL_DOCIDS );
93315
+ int ii;
93316
+ int rc = SQLITE_OK;
93317
+ int iCol = pPhrase->iColumn;
93318
+ DocListType eType = eListType;
93319
+ assert( eType==DL_POSITIONS || eType==DL_DOCIDS );
93320
+ if( pPhrase->nToken>1 ){
93321
+ eType = DL_POSITIONS;
93322
+ }
9200893323
9200993324
/* This code should never be called with buffered updates. */
92010
- assert( v->nPendingData<0 );
92011
-
92012
- dataBufferInit(&left, 0);
92013
- rc = termSelect(v, iColumn, pQTerm->pTerm, pQTerm->nTerm, pQTerm->isPrefix,
92014
- (0<pQTerm->nPhrase ? DL_POSITIONS : DL_DOCIDS), &left);
92015
- if( rc ) return rc;
92016
- for(i=1; i<=pQTerm->nPhrase && left.nData>0; i++){
92017
- /* If this token is connected to the next by a NEAR operator, and
92018
- ** the next token is the start of a phrase, then set nPhraseRight
92019
- ** to the number of tokens in the phrase. Otherwise leave it at 1.
92020
- */
92021
- int nPhraseRight = 1;
92022
- while( (i+nPhraseRight)<=pQTerm->nPhrase
92023
- && pQTerm[i+nPhraseRight].nNear==0
92024
- ){
92025
- nPhraseRight++;
92026
- }
92027
-
92028
- dataBufferInit(&right, 0);
92029
- rc = termSelect(v, iColumn, pQTerm[i].pTerm, pQTerm[i].nTerm,
92030
- pQTerm[i].isPrefix, DL_POSITIONS, &right);
92031
- if( rc ){
92032
- dataBufferDestroy(&left);
92033
- return rc;
92034
- }
92035
- dataBufferInit(&new, 0);
92036
- docListPhraseMerge(left.pData, left.nData, right.pData, right.nData,
92037
- pQTerm[i-1].nNear, pQTerm[i-1].iPhrase + nPhraseRight,
92038
- ((i<pQTerm->nPhrase) ? DL_POSITIONS : DL_DOCIDS),
92039
- &new);
92040
- dataBufferDestroy(&left);
92041
- dataBufferDestroy(&right);
92042
- left = new;
92043
- }
92044
- *pResult = left;
92045
- return SQLITE_OK;
92046
-}
92047
-
92048
-/* Add a new term pTerm[0..nTerm-1] to the query *q.
92049
-*/
92050
-static void queryAdd(Query *q, const char *pTerm, int nTerm){
92051
- QueryTerm *t;
92052
- ++q->nTerms;
92053
- q->pTerms = sqlite3_realloc(q->pTerms, q->nTerms * sizeof(q->pTerms[0]));
92054
- if( q->pTerms==0 ){
92055
- q->nTerms = 0;
92056
- return;
92057
- }
92058
- t = &q->pTerms[q->nTerms - 1];
92059
- CLEAR(t);
92060
- t->pTerm = sqlite3_malloc(nTerm+1);
92061
- memcpy(t->pTerm, pTerm, nTerm);
92062
- t->pTerm[nTerm] = 0;
92063
- t->nTerm = nTerm;
92064
- t->isOr = q->nextIsOr;
92065
- t->isPrefix = 0;
92066
- q->nextIsOr = 0;
92067
- t->iColumn = q->nextColumn;
92068
- q->nextColumn = q->dfltColumn;
92069
-}
92070
-
92071
-/*
92072
-** Check to see if the string zToken[0...nToken-1] matches any
92073
-** column name in the virtual table. If it does,
92074
-** return the zero-indexed column number. If not, return -1.
92075
-*/
92076
-static int checkColumnSpecifier(
92077
- fulltext_vtab *pVtab, /* The virtual table */
92078
- const char *zToken, /* Text of the token */
92079
- int nToken /* Number of characters in the token */
92080
-){
92081
- int i;
92082
- for(i=0; i<pVtab->nColumn; i++){
92083
- if( memcmp(pVtab->azColumn[i], zToken, nToken)==0
92084
- && pVtab->azColumn[i][nToken]==0 ){
92085
- return i;
92086
- }
92087
- }
92088
- return -1;
92089
-}
92090
-
92091
-/*
92092
-** Parse the text at zSegment[0..nSegment-1]. Add additional terms
92093
-** to the query being assemblied in pQuery.
92094
-**
92095
-** inPhrase is true if zSegment[0..nSegement-1] is contained within
92096
-** double-quotes. If inPhrase is true, then the first term
92097
-** is marked with the number of terms in the phrase less one and
92098
-** OR and "-" syntax is ignored. If inPhrase is false, then every
92099
-** term found is marked with nPhrase=0 and OR and "-" syntax is significant.
92100
-*/
92101
-static int tokenizeSegment(
92102
- sqlite3_tokenizer *pTokenizer, /* The tokenizer to use */
92103
- const char *zSegment, int nSegment, /* Query expression being parsed */
92104
- int inPhrase, /* True if within "..." */
92105
- Query *pQuery /* Append results here */
92106
-){
92107
- const sqlite3_tokenizer_module *pModule = pTokenizer->pModule;
92108
- sqlite3_tokenizer_cursor *pCursor;
92109
- int firstIndex = pQuery->nTerms;
92110
- int iCol;
92111
- int nTerm = 1;
92112
-
92113
- int rc = pModule->xOpen(pTokenizer, zSegment, nSegment, &pCursor);
92114
- if( rc!=SQLITE_OK ) return rc;
92115
- pCursor->pTokenizer = pTokenizer;
92116
-
92117
- while( 1 ){
92118
- const char *zToken;
92119
- int nToken, iBegin, iEnd, iPos;
92120
-
92121
- rc = pModule->xNext(pCursor,
92122
- &zToken, &nToken,
92123
- &iBegin, &iEnd, &iPos);
92124
- if( rc!=SQLITE_OK ) break;
92125
- if( !inPhrase &&
92126
- zSegment[iEnd]==':' &&
92127
- (iCol = checkColumnSpecifier(pQuery->pFts, zToken, nToken))>=0 ){
92128
- pQuery->nextColumn = iCol;
92129
- continue;
92130
- }
92131
- if( !inPhrase && pQuery->nTerms>0 && nToken==2
92132
- && zSegment[iBegin+0]=='O'
92133
- && zSegment[iBegin+1]=='R'
92134
- ){
92135
- pQuery->nextIsOr = 1;
92136
- continue;
92137
- }
92138
- if( !inPhrase && pQuery->nTerms>0 && !pQuery->nextIsOr && nToken==4
92139
- && memcmp(&zSegment[iBegin], "NEAR", 4)==0
92140
- ){
92141
- QueryTerm *pTerm = &pQuery->pTerms[pQuery->nTerms-1];
92142
- if( (iBegin+6)<nSegment
92143
- && zSegment[iBegin+4] == '/'
92144
- && isdigit(zSegment[iBegin+5])
92145
- ){
92146
- int k;
92147
- pTerm->nNear = 0;
92148
- for(k=5; (iBegin+k)<=nSegment && isdigit(zSegment[iBegin+k]); k++){
92149
- pTerm->nNear = pTerm->nNear*10 + (zSegment[iBegin+k] - '0');
92150
- }
92151
- pModule->xNext(pCursor, &zToken, &nToken, &iBegin, &iEnd, &iPos);
92152
- } else {
92153
- pTerm->nNear = SQLITE_FTS3_DEFAULT_NEAR_PARAM;
92154
- }
92155
- pTerm->nNear++;
92156
- continue;
92157
- }
92158
-
92159
- queryAdd(pQuery, zToken, nToken);
92160
- if( !inPhrase && iBegin>0 && zSegment[iBegin-1]=='-' ){
92161
- pQuery->pTerms[pQuery->nTerms-1].isNot = 1;
92162
- }
92163
- if( iEnd<nSegment && zSegment[iEnd]=='*' ){
92164
- pQuery->pTerms[pQuery->nTerms-1].isPrefix = 1;
92165
- }
92166
- pQuery->pTerms[pQuery->nTerms-1].iPhrase = nTerm;
92167
- if( inPhrase ){
92168
- nTerm++;
92169
- }
92170
- }
92171
-
92172
- if( inPhrase && pQuery->nTerms>firstIndex ){
92173
- pQuery->pTerms[firstIndex].nPhrase = pQuery->nTerms - firstIndex - 1;
92174
- }
92175
-
92176
- return pModule->xClose(pCursor);
92177
-}
92178
-
92179
-/* Parse a query string, yielding a Query object pQuery.
92180
-**
92181
-** The calling function will need to queryClear() to clean up
92182
-** the dynamically allocated memory held by pQuery.
92183
-*/
92184
-static int parseQuery(
92185
- fulltext_vtab *v, /* The fulltext index */
92186
- const char *zInput, /* Input text of the query string */
92187
- int nInput, /* Size of the input text */
92188
- int dfltColumn, /* Default column of the index to match against */
92189
- Query *pQuery /* Write the parse results here. */
92190
-){
92191
- int iInput, inPhrase = 0;
92192
- int ii;
92193
- QueryTerm *aTerm;
92194
-
92195
- if( zInput==0 ) nInput = 0;
92196
- if( nInput<0 ) nInput = strlen(zInput);
92197
- pQuery->nTerms = 0;
92198
- pQuery->pTerms = NULL;
92199
- pQuery->nextIsOr = 0;
92200
- pQuery->nextColumn = dfltColumn;
92201
- pQuery->dfltColumn = dfltColumn;
92202
- pQuery->pFts = v;
92203
-
92204
- for(iInput=0; iInput<nInput; ++iInput){
92205
- int i;
92206
- for(i=iInput; i<nInput && zInput[i]!='"'; ++i){}
92207
- if( i>iInput ){
92208
- tokenizeSegment(v->pTokenizer, zInput+iInput, i-iInput, inPhrase,
92209
- pQuery);
92210
- }
92211
- iInput = i;
92212
- if( i<nInput ){
92213
- assert( zInput[i]=='"' );
92214
- inPhrase = !inPhrase;
92215
- }
92216
- }
92217
-
92218
- if( inPhrase ){
92219
- /* unmatched quote */
92220
- queryClear(pQuery);
92221
- return SQLITE_ERROR;
92222
- }
92223
-
92224
- /* Modify the values of the QueryTerm.nPhrase variables to account for
92225
- ** the NEAR operator. For the purposes of QueryTerm.nPhrase, phrases
92226
- ** and tokens connected by the NEAR operator are handled as a single
92227
- ** phrase. See comments above the QueryTerm structure for details.
92228
- */
92229
- aTerm = pQuery->pTerms;
92230
- for(ii=0; ii<pQuery->nTerms; ii++){
92231
- if( aTerm[ii].nNear || aTerm[ii].nPhrase ){
92232
- while (aTerm[ii+aTerm[ii].nPhrase].nNear) {
92233
- aTerm[ii].nPhrase += (1 + aTerm[ii+aTerm[ii].nPhrase+1].nPhrase);
92234
- }
92235
- }
92236
- }
92237
-
92238
- return SQLITE_OK;
93325
+ assert( pTab->nPendingData<0 );
93326
+
93327
+ for(ii=0; rc==SQLITE_OK && ii<pPhrase->nToken; ii++){
93328
+ DataBuffer tmp;
93329
+ struct PhraseToken *p = &pPhrase->aToken[ii];
93330
+ rc = termSelect(pTab, iCol, p->z, p->n, p->isPrefix, eType, &tmp);
93331
+ if( rc==SQLITE_OK ){
93332
+ if( ii==0 ){
93333
+ *pResult = tmp;
93334
+ }else{
93335
+ DataBuffer res = *pResult;
93336
+ dataBufferInit(pResult, 0);
93337
+ if( ii==(pPhrase->nToken-1) ){
93338
+ eType = eListType;
93339
+ }
93340
+ docListPhraseMerge(
93341
+ res.pData, res.nData, tmp.pData, tmp.nData, 0, 0, eType, pResult
93342
+ );
93343
+ dataBufferDestroy(&res);
93344
+ dataBufferDestroy(&tmp);
93345
+ }
93346
+ }
93347
+ }
93348
+
93349
+ return rc;
93350
+}
93351
+
93352
+/*
93353
+** Evaluate the full-text expression pExpr against fts3 table pTab. Write
93354
+** the results into pRes.
93355
+*/
93356
+static int evalFts3Expr(
93357
+ fulltext_vtab *pTab, /* Fts3 Virtual table object */
93358
+ Fts3Expr *pExpr, /* Parsed fts3 expression */
93359
+ DataBuffer *pRes /* OUT: Write results of the expression here */
93360
+){
93361
+ int rc = SQLITE_OK;
93362
+
93363
+ /* Initialize the output buffer. If this is an empty query (pExpr==0),
93364
+ ** this is all that needs to be done. Empty queries produce empty
93365
+ ** result sets.
93366
+ */
93367
+ dataBufferInit(pRes, 0);
93368
+
93369
+ if( pExpr ){
93370
+ if( pExpr->eType==FTSQUERY_PHRASE ){
93371
+ DocListType eType = DL_DOCIDS;
93372
+ if( pExpr->pParent && pExpr->pParent->eType==FTSQUERY_NEAR ){
93373
+ eType = DL_POSITIONS;
93374
+ }
93375
+ rc = docListOfPhrase(pTab, pExpr->pPhrase, eType, pRes);
93376
+ }else{
93377
+ DataBuffer lhs;
93378
+ DataBuffer rhs;
93379
+
93380
+ dataBufferInit(&rhs, 0);
93381
+ if( SQLITE_OK==(rc = evalFts3Expr(pTab, pExpr->pLeft, &lhs))
93382
+ && SQLITE_OK==(rc = evalFts3Expr(pTab, pExpr->pRight, &rhs))
93383
+ ){
93384
+ switch( pExpr->eType ){
93385
+ case FTSQUERY_NEAR: {
93386
+ int nToken;
93387
+ Fts3Expr *pLeft;
93388
+ DocListType eType = DL_DOCIDS;
93389
+ if( pExpr->pParent && pExpr->pParent->eType==FTSQUERY_NEAR ){
93390
+ eType = DL_POSITIONS;
93391
+ }
93392
+ pLeft = pExpr->pLeft;
93393
+ while( pLeft->eType==FTSQUERY_NEAR ){
93394
+ pLeft=pLeft->pRight;
93395
+ }
93396
+ assert( pExpr->pRight->eType==FTSQUERY_PHRASE );
93397
+ assert( pLeft->eType==FTSQUERY_PHRASE );
93398
+ nToken = pLeft->pPhrase->nToken + pExpr->pRight->pPhrase->nToken;
93399
+ docListPhraseMerge(lhs.pData, lhs.nData, rhs.pData, rhs.nData,
93400
+ pExpr->nNear+1, nToken, eType, pRes
93401
+ );
93402
+ break;
93403
+ }
93404
+ case FTSQUERY_NOT: {
93405
+ docListExceptMerge(lhs.pData, lhs.nData, rhs.pData, rhs.nData,pRes);
93406
+ break;
93407
+ }
93408
+ case FTSQUERY_AND: {
93409
+ docListAndMerge(lhs.pData, lhs.nData, rhs.pData, rhs.nData, pRes);
93410
+ break;
93411
+ }
93412
+ case FTSQUERY_OR: {
93413
+ docListOrMerge(lhs.pData, lhs.nData, rhs.pData, rhs.nData, pRes);
93414
+ break;
93415
+ }
93416
+ }
93417
+ }
93418
+ dataBufferDestroy(&lhs);
93419
+ dataBufferDestroy(&rhs);
93420
+ }
93421
+ }
93422
+
93423
+ return rc;
9223993424
}
9224093425
9224193426
/* TODO(shess) Refactor the code to remove this forward decl. */
9224293427
static int flushPendingTerms(fulltext_vtab *v);
9224393428
@@ -92252,16 +93437,13 @@
9225293437
fulltext_vtab *v, /* The full text index */
9225393438
int iColumn, /* Match against this column by default */
9225493439
const char *zInput, /* The query string */
9225593440
int nInput, /* Number of bytes in zInput[] */
9225693441
DataBuffer *pResult, /* Write the result doclist here */
92257
- Query *pQuery /* Put parsed query string here */
93442
+ Fts3Expr **ppExpr /* Put parsed query string here */
9225893443
){
92259
- int i, iNext, rc;
92260
- DataBuffer left, right, or, new;
92261
- int nNot = 0;
92262
- QueryTerm *aTerm;
93444
+ int rc;
9226393445
9226493446
/* TODO(shess) Instead of flushing pendingTerms, we could query for
9226593447
** the relevant term and merge the doclist into what we receive from
9226693448
** the database. Wait and see if this is a common issue, first.
9226793449
**
@@ -92269,90 +93451,24 @@
9226993451
** error codes from here.
9227093452
*/
9227193453
9227293454
/* Flush any buffered updates before executing the query. */
9227393455
rc = flushPendingTerms(v);
92274
- if( rc!=SQLITE_OK ) return rc;
92275
-
92276
- /* TODO(shess) I think that the queryClear() calls below are not
92277
- ** necessary, because fulltextClose() already clears the query.
92278
- */
92279
- rc = parseQuery(v, zInput, nInput, iColumn, pQuery);
92280
- if( rc!=SQLITE_OK ) return rc;
92281
-
92282
- /* Empty or NULL queries return no results. */
92283
- if( pQuery->nTerms==0 ){
92284
- dataBufferInit(pResult, 0);
92285
- return SQLITE_OK;
92286
- }
92287
-
92288
- /* Merge AND terms. */
92289
- /* TODO(shess) I think we can early-exit if( i>nNot && left.nData==0 ). */
92290
- aTerm = pQuery->pTerms;
92291
- for(i = 0; i<pQuery->nTerms; i=iNext){
92292
- if( aTerm[i].isNot ){
92293
- /* Handle all NOT terms in a separate pass */
92294
- nNot++;
92295
- iNext = i + aTerm[i].nPhrase+1;
92296
- continue;
92297
- }
92298
- iNext = i + aTerm[i].nPhrase + 1;
92299
- rc = docListOfTerm(v, aTerm[i].iColumn, &aTerm[i], &right);
92300
- if( rc ){
92301
- if( i!=nNot ) dataBufferDestroy(&left);
92302
- queryClear(pQuery);
92303
- return rc;
92304
- }
92305
- while( iNext<pQuery->nTerms && aTerm[iNext].isOr ){
92306
- rc = docListOfTerm(v, aTerm[iNext].iColumn, &aTerm[iNext], &or);
92307
- iNext += aTerm[iNext].nPhrase + 1;
92308
- if( rc ){
92309
- if( i!=nNot ) dataBufferDestroy(&left);
92310
- dataBufferDestroy(&right);
92311
- queryClear(pQuery);
92312
- return rc;
92313
- }
92314
- dataBufferInit(&new, 0);
92315
- docListOrMerge(right.pData, right.nData, or.pData, or.nData, &new);
92316
- dataBufferDestroy(&right);
92317
- dataBufferDestroy(&or);
92318
- right = new;
92319
- }
92320
- if( i==nNot ){ /* first term processed. */
92321
- left = right;
92322
- }else{
92323
- dataBufferInit(&new, 0);
92324
- docListAndMerge(left.pData, left.nData, right.pData, right.nData, &new);
92325
- dataBufferDestroy(&right);
92326
- dataBufferDestroy(&left);
92327
- left = new;
92328
- }
92329
- }
92330
-
92331
- if( nNot==pQuery->nTerms ){
92332
- /* We do not yet know how to handle a query of only NOT terms */
92333
- return SQLITE_ERROR;
92334
- }
92335
-
92336
- /* Do the EXCEPT terms */
92337
- for(i=0; i<pQuery->nTerms; i += aTerm[i].nPhrase + 1){
92338
- if( !aTerm[i].isNot ) continue;
92339
- rc = docListOfTerm(v, aTerm[i].iColumn, &aTerm[i], &right);
92340
- if( rc ){
92341
- queryClear(pQuery);
92342
- dataBufferDestroy(&left);
92343
- return rc;
92344
- }
92345
- dataBufferInit(&new, 0);
92346
- docListExceptMerge(left.pData, left.nData, right.pData, right.nData, &new);
92347
- dataBufferDestroy(&right);
92348
- dataBufferDestroy(&left);
92349
- left = new;
92350
- }
92351
-
92352
- *pResult = left;
92353
- return rc;
93456
+ if( rc!=SQLITE_OK ){
93457
+ return rc;
93458
+ }
93459
+
93460
+ /* Parse the query passed to the MATCH operator. */
93461
+ rc = sqlite3Fts3ExprParse(v->pTokenizer,
93462
+ v->azColumn, v->nColumn, iColumn, zInput, nInput, ppExpr
93463
+ );
93464
+ if( rc!=SQLITE_OK ){
93465
+ assert( 0==(*ppExpr) );
93466
+ return rc;
93467
+ }
93468
+
93469
+ return evalFts3Expr(v, *ppExpr, pResult);
9235493470
}
9235593471
9235693472
/*
9235793473
** This is the xFilter interface for the virtual table. See
9235893474
** the virtual table xFilter method documentation for additional
@@ -92428,22 +93544,22 @@
9242893544
if( rc!=SQLITE_OK ) return rc;
9242993545
break;
9243093546
9243193547
default: /* full-text search */
9243293548
{
93549
+ int iCol = idxNum-QUERY_FULLTEXT;
9243393550
const char *zQuery = (const char *)sqlite3_value_text(argv[0]);
9243493551
assert( idxNum<=QUERY_FULLTEXT+v->nColumn);
9243593552
assert( argc==1 );
92436
- queryClear(&c->q);
9243793553
if( c->result.nData!=0 ){
9243893554
/* This case happens if the same cursor is used repeatedly. */
9243993555
dlrDestroy(&c->reader);
9244093556
dataBufferReset(&c->result);
9244193557
}else{
9244293558
dataBufferInit(&c->result, 0);
9244393559
}
92444
- rc = fulltextQuery(v, idxNum-QUERY_FULLTEXT, zQuery, -1, &c->result, &c->q);
93560
+ rc = fulltextQuery(v, iCol, zQuery, -1, &c->result, &c->pExpr);
9244593561
if( rc!=SQLITE_OK ) return rc;
9244693562
if( c->result.nData!=0 ){
9244793563
dlrInit(&c->reader, DL_DOCIDS, c->result.pData, c->result.nData);
9244893564
}
9244993565
break;
@@ -94323,22 +95439,28 @@
9432395439
}
9432495440
9432595441
/* Scan the database and merge together the posting lists for the term
9432695442
** into *out.
9432795443
*/
94328
-static int termSelect(fulltext_vtab *v, int iColumn,
94329
- const char *pTerm, int nTerm, int isPrefix,
94330
- DocListType iType, DataBuffer *out){
95444
+static int termSelect(
95445
+ fulltext_vtab *v,
95446
+ int iColumn,
95447
+ const char *pTerm, int nTerm, /* Term to query for */
95448
+ int isPrefix, /* True for a prefix search */
95449
+ DocListType iType,
95450
+ DataBuffer *out /* Write results here */
95451
+){
9433195452
DataBuffer doclist;
9433295453
sqlite3_stmt *s;
9433395454
int rc = sql_get_statement(v, SEGDIR_SELECT_ALL_STMT, &s);
9433495455
if( rc!=SQLITE_OK ) return rc;
9433595456
9433695457
/* This code should never be called with buffered updates. */
9433795458
assert( v->nPendingData<0 );
9433895459
9433995460
dataBufferInit(&doclist, 0);
95461
+ dataBufferInit(out, 0);
9434095462
9434195463
/* Traverse the segments from oldest to newest so that newer doclist
9434295464
** elements for given docids overwrite older elements.
9434395465
*/
9434495466
while( (rc = sqlite3_step(s))==SQLITE_ROW ){
@@ -95451,10 +96573,14 @@
9545196573
|| (pIcu && sqlite3Fts3HashInsert(pHash, "icu", 4, (void *)pIcu))
9545296574
){
9545396575
rc = SQLITE_NOMEM;
9545496576
}
9545596577
}
96578
+
96579
+#ifdef SQLITE_TEST
96580
+ sqlite3Fts3ExprInitTestInterface(db);
96581
+#endif
9545696582
9545796583
/* Create the virtual table wrapper around the hash-table and overload
9545896584
** the two scalar functions. If this is successful, register the
9545996585
** module with sqlite.
9546096586
*/
@@ -95494,10 +96620,897 @@
9549496620
#endif
9549596621
9549696622
#endif /* !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_FTS3) */
9549796623
9549896624
/************** End of fts3.c ************************************************/
96625
+/************** Begin file fts3_expr.c ***************************************/
96626
+/*
96627
+** 2008 Nov 28
96628
+**
96629
+** The author disclaims copyright to this source code. In place of
96630
+** a legal notice, here is a blessing:
96631
+**
96632
+** May you do good and not evil.
96633
+** May you find forgiveness for yourself and forgive others.
96634
+** May you share freely, never taking more than you give.
96635
+**
96636
+******************************************************************************
96637
+**
96638
+** This module contains code that implements a parser for fts3 query strings
96639
+** (the right-hand argument to the MATCH operator). Because the supported
96640
+** syntax is relatively simple, the whole tokenizer/parser system is
96641
+** hand-coded. The public interface to this module is declared in source
96642
+** code file "fts3_expr.h".
96643
+*/
96644
+#if !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_FTS3)
96645
+
96646
+/*
96647
+** By default, this module parses the legacy syntax that has been
96648
+** traditionally used by fts3. Or, if SQLITE_ENABLE_FTS3_PARENTHESIS
96649
+** is defined, then it uses the new syntax. The differences between
96650
+** the new and the old syntaxes are:
96651
+**
96652
+** a) The new syntax supports parenthesis. The old does not.
96653
+**
96654
+** b) The new syntax supports the AND and NOT operators. The old does not.
96655
+**
96656
+** c) The old syntax supports the "-" token qualifier. This is not
96657
+** supported by the new syntax (it is replaced by the NOT operator).
96658
+**
96659
+** d) When using the old syntax, the OR operator has a greater precedence
96660
+** than an implicit AND. When using the new, both implicity and explicit
96661
+** AND operators have a higher precedence than OR.
96662
+**
96663
+** If compiled with SQLITE_TEST defined, then this module exports the
96664
+** symbol "int sqlite3_fts3_enable_parentheses". Setting this variable
96665
+** to zero causes the module to use the old syntax. If it is set to
96666
+** non-zero the new syntax is activated. This is so both syntaxes can
96667
+** be tested using a single build of testfixture.
96668
+*/
96669
+#ifdef SQLITE_TEST
96670
+SQLITE_API int sqlite3_fts3_enable_parentheses = 0;
96671
+#else
96672
+# ifdef SQLITE_ENABLE_FTS3_PARENTHESIS
96673
+# define sqlite3_fts3_enable_parentheses 1
96674
+# else
96675
+# define sqlite3_fts3_enable_parentheses 0
96676
+# endif
96677
+#endif
96678
+
96679
+/*
96680
+** Default span for NEAR operators.
96681
+*/
96682
+#define SQLITE_FTS3_DEFAULT_NEAR_PARAM 10
96683
+
96684
+
96685
+typedef struct ParseContext ParseContext;
96686
+struct ParseContext {
96687
+ sqlite3_tokenizer *pTokenizer; /* Tokenizer module */
96688
+ const char **azCol; /* Array of column names for fts3 table */
96689
+ int nCol; /* Number of entries in azCol[] */
96690
+ int iDefaultCol; /* Default column to query */
96691
+ sqlite3_context *pCtx; /* Write error message here */
96692
+ int nNest; /* Number of nested brackets */
96693
+};
96694
+
96695
+/*
96696
+** This function is equivalent to the standard isspace() function.
96697
+**
96698
+** The standard isspace() can be awkward to use safely, because although it
96699
+** is defined to accept an argument of type int, its behaviour when passed
96700
+** an integer that falls outside of the range of the unsigned char type
96701
+** is undefined (and sometimes, "undefined" means segfault). This wrapper
96702
+** is defined to accept an argument of type char, and always returns 0 for
96703
+** any values that fall outside of the range of the unsigned char type (i.e.
96704
+** negative values).
96705
+*/
96706
+static int fts3isspace(char c){
96707
+ return (c&0x80)==0 ? isspace(c) : 0;
96708
+}
96709
+
96710
+/*
96711
+** Extract the next token from buffer z (length n) using the tokenizer
96712
+** and other information (column names etc.) in pParse. Create an Fts3Expr
96713
+** structure of type FTSQUERY_PHRASE containing a phrase consisting of this
96714
+** single token and set *ppExpr to point to it. If the end of the buffer is
96715
+** reached before a token is found, set *ppExpr to zero. It is the
96716
+** responsibility of the caller to eventually deallocate the allocated
96717
+** Fts3Expr structure (if any) by passing it to sqlite3_free().
96718
+**
96719
+** Return SQLITE_OK if successful, or SQLITE_NOMEM if a memory allocation
96720
+** fails.
96721
+*/
96722
+static int getNextToken(
96723
+ ParseContext *pParse, /* fts3 query parse context */
96724
+ int iCol, /* Value for Fts3Phrase.iColumn */
96725
+ const char *z, int n, /* Input string */
96726
+ Fts3Expr **ppExpr, /* OUT: expression */
96727
+ int *pnConsumed /* OUT: Number of bytes consumed */
96728
+){
96729
+ sqlite3_tokenizer *pTokenizer = pParse->pTokenizer;
96730
+ sqlite3_tokenizer_module const *pModule = pTokenizer->pModule;
96731
+ int rc;
96732
+ sqlite3_tokenizer_cursor *pCursor;
96733
+ Fts3Expr *pRet = 0;
96734
+ int nConsumed = 0;
96735
+
96736
+ rc = pModule->xOpen(pTokenizer, z, n, &pCursor);
96737
+ if( rc==SQLITE_OK ){
96738
+ const char *zToken;
96739
+ int nToken, iStart, iEnd, iPosition;
96740
+ int nByte; /* total space to allocate */
96741
+
96742
+ pCursor->pTokenizer = pTokenizer;
96743
+ rc = pModule->xNext(pCursor, &zToken, &nToken, &iStart, &iEnd, &iPosition);
96744
+
96745
+ if( rc==SQLITE_OK ){
96746
+ nByte = sizeof(Fts3Expr) + sizeof(Fts3Phrase) + nToken;
96747
+ pRet = (Fts3Expr *)sqlite3_malloc(nByte);
96748
+ if( !pRet ){
96749
+ rc = SQLITE_NOMEM;
96750
+ }else{
96751
+ memset(pRet, 0, nByte);
96752
+ pRet->eType = FTSQUERY_PHRASE;
96753
+ pRet->pPhrase = (Fts3Phrase *)&pRet[1];
96754
+ pRet->pPhrase->nToken = 1;
96755
+ pRet->pPhrase->iColumn = iCol;
96756
+ pRet->pPhrase->aToken[0].n = nToken;
96757
+ pRet->pPhrase->aToken[0].z = (char *)&pRet->pPhrase[1];
96758
+ memcpy(pRet->pPhrase->aToken[0].z, zToken, nToken);
96759
+
96760
+ if( iEnd<n && z[iEnd]=='*' ){
96761
+ pRet->pPhrase->aToken[0].isPrefix = 1;
96762
+ iEnd++;
96763
+ }
96764
+ if( !sqlite3_fts3_enable_parentheses && iStart>0 && z[iStart-1]=='-' ){
96765
+ pRet->pPhrase->isNot = 1;
96766
+ }
96767
+ }
96768
+ }
96769
+ nConsumed = iEnd;
96770
+
96771
+ pModule->xClose(pCursor);
96772
+ }
96773
+
96774
+ *pnConsumed = nConsumed;
96775
+ *ppExpr = pRet;
96776
+ return rc;
96777
+}
96778
+
96779
+
96780
+/*
96781
+** Enlarge a memory allocation. If an out-of-memory allocation occurs,
96782
+** then free the old allocation.
96783
+*/
96784
+void *fts3ReallocOrFree(void *pOrig, int nNew){
96785
+ void *pRet = sqlite3_realloc(pOrig, nNew);
96786
+ if( !pRet ){
96787
+ sqlite3_free(pOrig);
96788
+ }
96789
+ return pRet;
96790
+}
96791
+
96792
+/*
96793
+** Buffer zInput, length nInput, contains the contents of a quoted string
96794
+** that appeared as part of an fts3 query expression. Neither quote character
96795
+** is included in the buffer. This function attempts to tokenize the entire
96796
+** input buffer and create an Fts3Expr structure of type FTSQUERY_PHRASE
96797
+** containing the results.
96798
+**
96799
+** If successful, SQLITE_OK is returned and *ppExpr set to point at the
96800
+** allocated Fts3Expr structure. Otherwise, either SQLITE_NOMEM (out of memory
96801
+** error) or SQLITE_ERROR (tokenization error) is returned and *ppExpr set
96802
+** to 0.
96803
+*/
96804
+static int getNextString(
96805
+ ParseContext *pParse, /* fts3 query parse context */
96806
+ const char *zInput, int nInput, /* Input string */
96807
+ Fts3Expr **ppExpr /* OUT: expression */
96808
+){
96809
+ sqlite3_tokenizer *pTokenizer = pParse->pTokenizer;
96810
+ sqlite3_tokenizer_module const *pModule = pTokenizer->pModule;
96811
+ int rc;
96812
+ Fts3Expr *p = 0;
96813
+ sqlite3_tokenizer_cursor *pCursor = 0;
96814
+ char *zTemp = 0;
96815
+ int nTemp = 0;
96816
+
96817
+ rc = pModule->xOpen(pTokenizer, zInput, nInput, &pCursor);
96818
+ if( rc==SQLITE_OK ){
96819
+ int ii;
96820
+ pCursor->pTokenizer = pTokenizer;
96821
+ for(ii=0; rc==SQLITE_OK; ii++){
96822
+ const char *zToken;
96823
+ int nToken, iBegin, iEnd, iPos;
96824
+ rc = pModule->xNext(pCursor, &zToken, &nToken, &iBegin, &iEnd, &iPos);
96825
+ if( rc==SQLITE_OK ){
96826
+ int nByte = sizeof(Fts3Expr) + sizeof(Fts3Phrase);
96827
+ p = fts3ReallocOrFree(p, nByte+ii*sizeof(struct PhraseToken));
96828
+ zTemp = fts3ReallocOrFree(zTemp, nTemp + nToken);
96829
+ if( !p || !zTemp ){
96830
+ goto no_mem;
96831
+ }
96832
+ if( ii==0 ){
96833
+ memset(p, 0, nByte);
96834
+ p->pPhrase = (Fts3Phrase *)&p[1];
96835
+ p->eType = FTSQUERY_PHRASE;
96836
+ p->pPhrase->iColumn = pParse->iDefaultCol;
96837
+ }
96838
+ p->pPhrase = (Fts3Phrase *)&p[1];
96839
+ p->pPhrase->nToken = ii+1;
96840
+ p->pPhrase->aToken[ii].n = nToken;
96841
+ memcpy(&zTemp[nTemp], zToken, nToken);
96842
+ nTemp += nToken;
96843
+ if( iEnd<nInput && zInput[iEnd]=='*' ){
96844
+ p->pPhrase->aToken[ii].isPrefix = 1;
96845
+ }else{
96846
+ p->pPhrase->aToken[ii].isPrefix = 0;
96847
+ }
96848
+ }
96849
+ }
96850
+
96851
+ pModule->xClose(pCursor);
96852
+ pCursor = 0;
96853
+ }
96854
+
96855
+ if( rc==SQLITE_DONE ){
96856
+ int jj;
96857
+ char *zNew;
96858
+ int nNew = 0;
96859
+ int nByte = sizeof(Fts3Expr) + sizeof(Fts3Phrase);
96860
+ nByte += (p->pPhrase->nToken-1) * sizeof(struct PhraseToken);
96861
+ p = fts3ReallocOrFree(p, nByte + nTemp);
96862
+ if( !p ){
96863
+ goto no_mem;
96864
+ }
96865
+ p->pPhrase = (Fts3Phrase *)&p[1];
96866
+ zNew = &(((char *)p)[nByte]);
96867
+ memcpy(zNew, zTemp, nTemp);
96868
+ for(jj=0; jj<p->pPhrase->nToken; jj++){
96869
+ p->pPhrase->aToken[jj].z = &zNew[nNew];
96870
+ nNew += p->pPhrase->aToken[jj].n;
96871
+ }
96872
+ sqlite3_free(zTemp);
96873
+ rc = SQLITE_OK;
96874
+ }
96875
+
96876
+ *ppExpr = p;
96877
+ return rc;
96878
+no_mem:
96879
+
96880
+ if( pCursor ){
96881
+ pModule->xClose(pCursor);
96882
+ }
96883
+ sqlite3_free(zTemp);
96884
+ sqlite3_free(p);
96885
+ *ppExpr = 0;
96886
+ return SQLITE_NOMEM;
96887
+}
96888
+
96889
+/*
96890
+** Function getNextNode(), which is called by fts3ExprParse(), may itself
96891
+** call fts3ExprParse(). So this forward declaration is required.
96892
+*/
96893
+static int fts3ExprParse(ParseContext *, const char *, int, Fts3Expr **, int *);
96894
+
96895
+/*
96896
+** The output variable *ppExpr is populated with an allocated Fts3Expr
96897
+** structure, or set to 0 if the end of the input buffer is reached.
96898
+**
96899
+** Returns an SQLite error code. SQLITE_OK if everything works, SQLITE_NOMEM
96900
+** if a malloc failure occurs, or SQLITE_ERROR if a parse error is encountered.
96901
+** If SQLITE_ERROR is returned, pContext is populated with an error message.
96902
+*/
96903
+static int getNextNode(
96904
+ ParseContext *pParse, /* fts3 query parse context */
96905
+ const char *z, int n, /* Input string */
96906
+ Fts3Expr **ppExpr, /* OUT: expression */
96907
+ int *pnConsumed /* OUT: Number of bytes consumed */
96908
+){
96909
+ static const struct Fts3Keyword {
96910
+ char z[4]; /* Keyword text */
96911
+ unsigned char n; /* Length of the keyword */
96912
+ unsigned char parenOnly; /* Only valid in paren mode */
96913
+ unsigned char eType; /* Keyword code */
96914
+ } aKeyword[] = {
96915
+ { "OR" , 2, 0, FTSQUERY_OR },
96916
+ { "AND", 3, 1, FTSQUERY_AND },
96917
+ { "NOT", 3, 1, FTSQUERY_NOT },
96918
+ { "NEAR", 4, 0, FTSQUERY_NEAR }
96919
+ };
96920
+ int ii;
96921
+ int iCol;
96922
+ int iColLen;
96923
+ int rc;
96924
+ Fts3Expr *pRet = 0;
96925
+
96926
+ const char *zInput = z;
96927
+ int nInput = n;
96928
+
96929
+ /* Skip over any whitespace before checking for a keyword, an open or
96930
+ ** close bracket, or a quoted string.
96931
+ */
96932
+ while( nInput>0 && fts3isspace(*zInput) ){
96933
+ nInput--;
96934
+ zInput++;
96935
+ }
96936
+ if( nInput==0 ){
96937
+ return SQLITE_DONE;
96938
+ }
96939
+
96940
+ /* See if we are dealing with a keyword. */
96941
+ for(ii=0; ii<(int)(sizeof(aKeyword)/sizeof(struct Fts3Keyword)); ii++){
96942
+ const struct Fts3Keyword *pKey = &aKeyword[ii];
96943
+
96944
+ if( (pKey->parenOnly & ~sqlite3_fts3_enable_parentheses)!=0 ){
96945
+ continue;
96946
+ }
96947
+
96948
+ if( nInput>=pKey->n && 0==memcmp(zInput, pKey->z, pKey->n) ){
96949
+ int nNear = SQLITE_FTS3_DEFAULT_NEAR_PARAM;
96950
+ int nKey = pKey->n;
96951
+ char cNext;
96952
+
96953
+ /* If this is a "NEAR" keyword, check for an explicit nearness. */
96954
+ if( pKey->eType==FTSQUERY_NEAR ){
96955
+ assert( nKey==4 );
96956
+ if( zInput[4]=='/' && zInput[5]>='0' && zInput[5]<='9' ){
96957
+ nNear = 0;
96958
+ for(nKey=5; zInput[nKey]>='0' && zInput[nKey]<='9'; nKey++){
96959
+ nNear = nNear * 10 + (zInput[nKey] - '0');
96960
+ }
96961
+ }
96962
+ }
96963
+
96964
+ /* At this point this is probably a keyword. But for that to be true,
96965
+ ** the next byte must contain either whitespace, an open or close
96966
+ ** parenthesis, a quote character, or EOF.
96967
+ */
96968
+ cNext = zInput[nKey];
96969
+ if( fts3isspace(cNext)
96970
+ || cNext=='"' || cNext=='(' || cNext==')' || cNext==0
96971
+ ){
96972
+ pRet = (Fts3Expr *)sqlite3_malloc(sizeof(Fts3Expr));
96973
+ memset(pRet, 0, sizeof(Fts3Expr));
96974
+ pRet->eType = pKey->eType;
96975
+ pRet->nNear = nNear;
96976
+ *ppExpr = pRet;
96977
+ *pnConsumed = (zInput - z) + nKey;
96978
+ return SQLITE_OK;
96979
+ }
96980
+
96981
+ /* Turns out that wasn't a keyword after all. This happens if the
96982
+ ** user has supplied a token such as "ORacle". Continue.
96983
+ */
96984
+ }
96985
+ }
96986
+
96987
+ /* Check for an open bracket. */
96988
+ if( sqlite3_fts3_enable_parentheses ){
96989
+ if( *zInput=='(' ){
96990
+ int nConsumed;
96991
+ int rc;
96992
+ pParse->nNest++;
96993
+ rc = fts3ExprParse(pParse, &zInput[1], nInput-1, ppExpr, &nConsumed);
96994
+ if( rc==SQLITE_OK && !*ppExpr ){
96995
+ rc = SQLITE_DONE;
96996
+ }
96997
+ *pnConsumed = (zInput - z) + 1 + nConsumed;
96998
+ return rc;
96999
+ }
97000
+
97001
+ /* Check for a close bracket. */
97002
+ if( *zInput==')' ){
97003
+ pParse->nNest--;
97004
+ *pnConsumed = (zInput - z) + 1;
97005
+ return SQLITE_DONE;
97006
+ }
97007
+ }
97008
+
97009
+ /* See if we are dealing with a quoted phrase. If this is the case, then
97010
+ ** search for the closing quote and pass the whole string to getNextString()
97011
+ ** for processing. This is easy to do, as fts3 has no syntax for escaping
97012
+ ** a quote character embedded in a string.
97013
+ */
97014
+ if( *zInput=='"' ){
97015
+ for(ii=1; ii<nInput && zInput[ii]!='"'; ii++);
97016
+ *pnConsumed = (zInput - z) + ii + 1;
97017
+ if( ii==nInput ){
97018
+ return SQLITE_ERROR;
97019
+ }
97020
+ return getNextString(pParse, &zInput[1], ii-1, ppExpr);
97021
+ }
97022
+
97023
+
97024
+ /* If control flows to this point, this must be a regular token, or
97025
+ ** the end of the input. Read a regular token using the sqlite3_tokenizer
97026
+ ** interface. Before doing so, figure out if there is an explicit
97027
+ ** column specifier for the token.
97028
+ **
97029
+ ** TODO: Strangely, it is not possible to associate a column specifier
97030
+ ** with a quoted phrase, only with a single token. Not sure if this was
97031
+ ** an implementation artifact or an intentional decision when fts3 was
97032
+ ** first implemented. Whichever it was, this module duplicates the
97033
+ ** limitation.
97034
+ */
97035
+ iCol = pParse->iDefaultCol;
97036
+ iColLen = 0;
97037
+ for(ii=0; ii<pParse->nCol; ii++){
97038
+ const char *zStr = pParse->azCol[ii];
97039
+ int nStr = strlen(zStr);
97040
+ if( nInput>nStr && zInput[nStr]==':' && memcmp(zStr, zInput, nStr)==0 ){
97041
+ iCol = ii;
97042
+ iColLen = ((zInput - z) + nStr + 1);
97043
+ break;
97044
+ }
97045
+ }
97046
+ rc = getNextToken(pParse, iCol, &z[iColLen], n-iColLen, ppExpr, pnConsumed);
97047
+ *pnConsumed += iColLen;
97048
+ return rc;
97049
+}
97050
+
97051
+/*
97052
+** The argument is an Fts3Expr structure for a binary operator (any type
97053
+** except an FTSQUERY_PHRASE). Return an integer value representing the
97054
+** precedence of the operator. Lower values have a higher precedence (i.e.
97055
+** group more tightly). For example, in the C language, the == operator
97056
+** groups more tightly than ||, and would therefore have a higher precedence.
97057
+**
97058
+** When using the new fts3 query syntax (when SQLITE_ENABLE_FTS3_PARENTHESIS
97059
+** is defined), the order of the operators in precedence from highest to
97060
+** lowest is:
97061
+**
97062
+** NEAR
97063
+** NOT
97064
+** AND (including implicit ANDs)
97065
+** OR
97066
+**
97067
+** Note that when using the old query syntax, the OR operator has a higher
97068
+** precedence than the AND operator.
97069
+*/
97070
+static int opPrecedence(Fts3Expr *p){
97071
+ assert( p->eType!=FTSQUERY_PHRASE );
97072
+ if( sqlite3_fts3_enable_parentheses ){
97073
+ return p->eType;
97074
+ }else if( p->eType==FTSQUERY_NEAR ){
97075
+ return 1;
97076
+ }else if( p->eType==FTSQUERY_OR ){
97077
+ return 2;
97078
+ }
97079
+ assert( p->eType==FTSQUERY_AND );
97080
+ return 3;
97081
+}
97082
+
97083
+/*
97084
+** Argument ppHead contains a pointer to the current head of a query
97085
+** expression tree being parsed. pPrev is the expression node most recently
97086
+** inserted into the tree. This function adds pNew, which is always a binary
97087
+** operator node, into the expression tree based on the relative precedence
97088
+** of pNew and the existing nodes of the tree. This may result in the head
97089
+** of the tree changing, in which case *ppHead is set to the new root node.
97090
+*/
97091
+static void insertBinaryOperator(
97092
+ Fts3Expr **ppHead, /* Pointer to the root node of a tree */
97093
+ Fts3Expr *pPrev, /* Node most recently inserted into the tree */
97094
+ Fts3Expr *pNew /* New binary node to insert into expression tree */
97095
+){
97096
+ Fts3Expr *pSplit = pPrev;
97097
+ while( pSplit->pParent && opPrecedence(pSplit->pParent)<=opPrecedence(pNew) ){
97098
+ pSplit = pSplit->pParent;
97099
+ }
97100
+
97101
+ if( pSplit->pParent ){
97102
+ assert( pSplit->pParent->pRight==pSplit );
97103
+ pSplit->pParent->pRight = pNew;
97104
+ pNew->pParent = pSplit->pParent;
97105
+ }else{
97106
+ *ppHead = pNew;
97107
+ }
97108
+ pNew->pLeft = pSplit;
97109
+ pSplit->pParent = pNew;
97110
+}
97111
+
97112
+/*
97113
+** Parse the fts3 query expression found in buffer z, length n. This function
97114
+** returns either when the end of the buffer is reached or an unmatched
97115
+** closing bracket - ')' - is encountered.
97116
+**
97117
+** If successful, SQLITE_OK is returned, *ppExpr is set to point to the
97118
+** parsed form of the expression and *pnConsumed is set to the number of
97119
+** bytes read from buffer z. Otherwise, *ppExpr is set to 0 and SQLITE_NOMEM
97120
+** (out of memory error) or SQLITE_ERROR (parse error) is returned.
97121
+*/
97122
+static int fts3ExprParse(
97123
+ ParseContext *pParse, /* fts3 query parse context */
97124
+ const char *z, int n, /* Text of MATCH query */
97125
+ Fts3Expr **ppExpr, /* OUT: Parsed query structure */
97126
+ int *pnConsumed /* OUT: Number of bytes consumed */
97127
+){
97128
+ Fts3Expr *pRet = 0;
97129
+ Fts3Expr *pPrev = 0;
97130
+ Fts3Expr *pNotBranch = 0; /* Only used in legacy parse mode */
97131
+ int nIn = n;
97132
+ const char *zIn = z;
97133
+ int rc = SQLITE_OK;
97134
+ int isRequirePhrase = 1;
97135
+
97136
+ while( rc==SQLITE_OK ){
97137
+ Fts3Expr *p = 0;
97138
+ int nByte = 0;
97139
+ rc = getNextNode(pParse, zIn, nIn, &p, &nByte);
97140
+ if( rc==SQLITE_OK ){
97141
+ int isPhrase;
97142
+
97143
+ if( !sqlite3_fts3_enable_parentheses
97144
+ && p->eType==FTSQUERY_PHRASE && p->pPhrase->isNot
97145
+ ){
97146
+ /* Create an implicit NOT operator. */
97147
+ Fts3Expr *pNot = sqlite3_malloc(sizeof(Fts3Expr));
97148
+ if( !pNot ){
97149
+ sqlite3Fts3ExprFree(p);
97150
+ rc = SQLITE_NOMEM;
97151
+ goto exprparse_out;
97152
+ }
97153
+ memset(pNot, 0, sizeof(Fts3Expr));
97154
+ pNot->eType = FTSQUERY_NOT;
97155
+ pNot->pRight = p;
97156
+ if( pNotBranch ){
97157
+ pNotBranch->pLeft = p;
97158
+ pNot->pRight = pNotBranch;
97159
+ }
97160
+ pNotBranch = pNot;
97161
+ }else{
97162
+ int eType = p->eType;
97163
+ assert( eType!=FTSQUERY_PHRASE || !p->pPhrase->isNot );
97164
+ isPhrase = (eType==FTSQUERY_PHRASE || p->pLeft);
97165
+
97166
+ /* The isRequirePhrase variable is set to true if a phrase or
97167
+ ** an expression contained in parenthesis is required. If a
97168
+ ** binary operator (AND, OR, NOT or NEAR) is encounted when
97169
+ ** isRequirePhrase is set, this is a syntax error.
97170
+ */
97171
+ if( !isPhrase && isRequirePhrase ){
97172
+ sqlite3Fts3ExprFree(p);
97173
+ rc = SQLITE_ERROR;
97174
+ goto exprparse_out;
97175
+ }
97176
+
97177
+ if( isPhrase && !isRequirePhrase ){
97178
+ /* Insert an implicit AND operator. */
97179
+ Fts3Expr *pAnd;
97180
+ assert( pRet && pPrev );
97181
+ pAnd = sqlite3_malloc(sizeof(Fts3Expr));
97182
+ if( !pAnd ){
97183
+ sqlite3Fts3ExprFree(p);
97184
+ rc = SQLITE_NOMEM;
97185
+ goto exprparse_out;
97186
+ }
97187
+ memset(pAnd, 0, sizeof(Fts3Expr));
97188
+ pAnd->eType = FTSQUERY_AND;
97189
+ insertBinaryOperator(&pRet, pPrev, pAnd);
97190
+ pPrev = pAnd;
97191
+ }
97192
+
97193
+ /* This test catches attempts to make either operand of a NEAR
97194
+ ** operator something other than a phrase. For example, either of
97195
+ ** the following:
97196
+ **
97197
+ ** (bracketed expression) NEAR phrase
97198
+ ** phrase NEAR (bracketed expression)
97199
+ **
97200
+ ** Return an error in either case.
97201
+ */
97202
+ if( pPrev && (
97203
+ (eType==FTSQUERY_NEAR && !isPhrase && pPrev->eType!=FTSQUERY_PHRASE)
97204
+ || (eType!=FTSQUERY_PHRASE && isPhrase && pPrev->eType==FTSQUERY_NEAR)
97205
+ )){
97206
+ sqlite3Fts3ExprFree(p);
97207
+ rc = SQLITE_ERROR;
97208
+ goto exprparse_out;
97209
+ }
97210
+
97211
+ if( isPhrase ){
97212
+ if( pRet ){
97213
+ assert( pPrev && pPrev->pLeft && pPrev->pRight==0 );
97214
+ pPrev->pRight = p;
97215
+ p->pParent = pPrev;
97216
+ }else{
97217
+ pRet = p;
97218
+ }
97219
+ }else{
97220
+ insertBinaryOperator(&pRet, pPrev, p);
97221
+ }
97222
+ isRequirePhrase = !isPhrase;
97223
+ }
97224
+ assert( nByte>0 );
97225
+ }
97226
+ assert( rc!=SQLITE_OK || (nByte>0 && nByte<=nIn) );
97227
+ nIn -= nByte;
97228
+ zIn += nByte;
97229
+ pPrev = p;
97230
+ }
97231
+
97232
+ if( rc==SQLITE_DONE && pRet && isRequirePhrase ){
97233
+ rc = SQLITE_ERROR;
97234
+ }
97235
+
97236
+ if( rc==SQLITE_DONE ){
97237
+ rc = SQLITE_OK;
97238
+ if( !sqlite3_fts3_enable_parentheses && pNotBranch ){
97239
+ if( !pRet ){
97240
+ rc = SQLITE_ERROR;
97241
+ }else{
97242
+ pNotBranch->pLeft = pRet;
97243
+ pRet = pNotBranch;
97244
+ }
97245
+ }
97246
+ }
97247
+ *pnConsumed = n - nIn;
97248
+
97249
+exprparse_out:
97250
+ if( rc!=SQLITE_OK ){
97251
+ sqlite3Fts3ExprFree(pRet);
97252
+ sqlite3Fts3ExprFree(pNotBranch);
97253
+ pRet = 0;
97254
+ }
97255
+ *ppExpr = pRet;
97256
+ return rc;
97257
+}
97258
+
97259
+/*
97260
+** Parameters z and n contain a pointer to and length of a buffer containing
97261
+** an fts3 query expression, respectively. This function attempts to parse the
97262
+** query expression and create a tree of Fts3Expr structures representing the
97263
+** parsed expression. If successful, *ppExpr is set to point to the head
97264
+** of the parsed expression tree and SQLITE_OK is returned. If an error
97265
+** occurs, either SQLITE_NOMEM (out-of-memory error) or SQLITE_ERROR (parse
97266
+** error) is returned and *ppExpr is set to 0.
97267
+**
97268
+** If parameter n is a negative number, then z is assumed to point to a
97269
+** nul-terminated string and the length is determined using strlen().
97270
+**
97271
+** The first parameter, pTokenizer, is passed the fts3 tokenizer module to
97272
+** use to normalize query tokens while parsing the expression. The azCol[]
97273
+** array, which is assumed to contain nCol entries, should contain the names
97274
+** of each column in the target fts3 table, in order from left to right.
97275
+** Column names must be nul-terminated strings.
97276
+**
97277
+** The iDefaultCol parameter should be passed the index of the table column
97278
+** that appears on the left-hand-side of the MATCH operator (the default
97279
+** column to match against for tokens for which a column name is not explicitly
97280
+** specified as part of the query string), or -1 if tokens may by default
97281
+** match any table column.
97282
+*/
97283
+SQLITE_PRIVATE int sqlite3Fts3ExprParse(
97284
+ sqlite3_tokenizer *pTokenizer, /* Tokenizer module */
97285
+ char **azCol, /* Array of column names for fts3 table */
97286
+ int nCol, /* Number of entries in azCol[] */
97287
+ int iDefaultCol, /* Default column to query */
97288
+ const char *z, int n, /* Text of MATCH query */
97289
+ Fts3Expr **ppExpr /* OUT: Parsed query structure */
97290
+){
97291
+ int nParsed;
97292
+ int rc;
97293
+ ParseContext sParse;
97294
+ sParse.pTokenizer = pTokenizer;
97295
+ sParse.azCol = (const char **)azCol;
97296
+ sParse.nCol = nCol;
97297
+ sParse.iDefaultCol = iDefaultCol;
97298
+ sParse.nNest = 0;
97299
+ if( z==0 ){
97300
+ *ppExpr = 0;
97301
+ return SQLITE_OK;
97302
+ }
97303
+ if( n<0 ){
97304
+ n = strlen(z);
97305
+ }
97306
+ rc = fts3ExprParse(&sParse, z, n, ppExpr, &nParsed);
97307
+
97308
+ /* Check for mismatched parenthesis */
97309
+ if( rc==SQLITE_OK && sParse.nNest ){
97310
+ rc = SQLITE_ERROR;
97311
+ sqlite3Fts3ExprFree(*ppExpr);
97312
+ *ppExpr = 0;
97313
+ }
97314
+
97315
+ return rc;
97316
+}
97317
+
97318
+/*
97319
+** Free a parsed fts3 query expression allocated by sqlite3Fts3ExprParse().
97320
+*/
97321
+SQLITE_PRIVATE void sqlite3Fts3ExprFree(Fts3Expr *p){
97322
+ if( p ){
97323
+ sqlite3Fts3ExprFree(p->pLeft);
97324
+ sqlite3Fts3ExprFree(p->pRight);
97325
+ sqlite3_free(p);
97326
+ }
97327
+}
97328
+
97329
+/****************************************************************************
97330
+*****************************************************************************
97331
+** Everything after this point is just test code.
97332
+*/
97333
+
97334
+#ifdef SQLITE_TEST
97335
+
97336
+
97337
+/*
97338
+** Function to query the hash-table of tokenizers (see README.tokenizers).
97339
+*/
97340
+static int queryTestTokenizer(
97341
+ sqlite3 *db,
97342
+ const char *zName,
97343
+ const sqlite3_tokenizer_module **pp
97344
+){
97345
+ int rc;
97346
+ sqlite3_stmt *pStmt;
97347
+ const char zSql[] = "SELECT fts3_tokenizer(?)";
97348
+
97349
+ *pp = 0;
97350
+ rc = sqlite3_prepare_v2(db, zSql, -1, &pStmt, 0);
97351
+ if( rc!=SQLITE_OK ){
97352
+ return rc;
97353
+ }
97354
+
97355
+ sqlite3_bind_text(pStmt, 1, zName, -1, SQLITE_STATIC);
97356
+ if( SQLITE_ROW==sqlite3_step(pStmt) ){
97357
+ if( sqlite3_column_type(pStmt, 0)==SQLITE_BLOB ){
97358
+ memcpy(pp, sqlite3_column_blob(pStmt, 0), sizeof(*pp));
97359
+ }
97360
+ }
97361
+
97362
+ return sqlite3_finalize(pStmt);
97363
+}
97364
+
97365
+/*
97366
+** This function is part of the test interface for the query parser. It
97367
+** writes a text representation of the query expression pExpr into the
97368
+** buffer pointed to by argument zBuf. It is assumed that zBuf is large
97369
+** enough to store the required text representation.
97370
+*/
97371
+static void exprToString(Fts3Expr *pExpr, char *zBuf){
97372
+ switch( pExpr->eType ){
97373
+ case FTSQUERY_PHRASE: {
97374
+ Fts3Phrase *pPhrase = pExpr->pPhrase;
97375
+ int i;
97376
+ zBuf += sprintf(zBuf, "PHRASE %d %d", pPhrase->iColumn, pPhrase->isNot);
97377
+ for(i=0; i<pPhrase->nToken; i++){
97378
+ zBuf += sprintf(zBuf," %.*s",pPhrase->aToken[i].n,pPhrase->aToken[i].z);
97379
+ zBuf += sprintf(zBuf,"%s", (pPhrase->aToken[i].isPrefix?"+":""));
97380
+ }
97381
+ return;
97382
+ }
97383
+
97384
+ case FTSQUERY_NEAR:
97385
+ zBuf += sprintf(zBuf, "NEAR/%d ", pExpr->nNear);
97386
+ break;
97387
+ case FTSQUERY_NOT:
97388
+ zBuf += sprintf(zBuf, "NOT ");
97389
+ break;
97390
+ case FTSQUERY_AND:
97391
+ zBuf += sprintf(zBuf, "AND ");
97392
+ break;
97393
+ case FTSQUERY_OR:
97394
+ zBuf += sprintf(zBuf, "OR ");
97395
+ break;
97396
+ }
97397
+
97398
+ zBuf += sprintf(zBuf, "{");
97399
+ exprToString(pExpr->pLeft, zBuf);
97400
+ zBuf += strlen(zBuf);
97401
+ zBuf += sprintf(zBuf, "} ");
97402
+
97403
+ zBuf += sprintf(zBuf, "{");
97404
+ exprToString(pExpr->pRight, zBuf);
97405
+ zBuf += strlen(zBuf);
97406
+ zBuf += sprintf(zBuf, "}");
97407
+}
97408
+
97409
+/*
97410
+** This is the implementation of a scalar SQL function used to test the
97411
+** expression parser. It should be called as follows:
97412
+**
97413
+** fts3_exprtest(<tokenizer>, <expr>, <column 1>, ...);
97414
+**
97415
+** The first argument, <tokenizer>, is the name of the fts3 tokenizer used
97416
+** to parse the query expression (see README.tokenizers). The second argument
97417
+** is the query expression to parse. Each subsequent argument is the name
97418
+** of a column of the fts3 table that the query expression may refer to.
97419
+** For example:
97420
+**
97421
+** SELECT fts3_exprtest('simple', 'Bill col2:Bloggs', 'col1', 'col2');
97422
+*/
97423
+static void fts3ExprTest(
97424
+ sqlite3_context *context,
97425
+ int argc,
97426
+ sqlite3_value **argv
97427
+){
97428
+ sqlite3_tokenizer_module const *pModule = 0;
97429
+ sqlite3_tokenizer *pTokenizer = 0;
97430
+ int rc;
97431
+ char **azCol = 0;
97432
+ const char *zExpr;
97433
+ int nExpr;
97434
+ int nCol;
97435
+ int ii;
97436
+ Fts3Expr *pExpr;
97437
+ sqlite3 *db = sqlite3_context_db_handle(context);
97438
+
97439
+ if( argc<3 ){
97440
+ sqlite3_result_error(context,
97441
+ "Usage: fts3_exprtest(tokenizer, expr, col1, ...", -1
97442
+ );
97443
+ return;
97444
+ }
97445
+
97446
+ rc = queryTestTokenizer(db,
97447
+ (const char *)sqlite3_value_text(argv[0]), &pModule);
97448
+ if( rc==SQLITE_NOMEM ){
97449
+ sqlite3_result_error_nomem(context);
97450
+ goto exprtest_out;
97451
+ }else if( !pModule ){
97452
+ sqlite3_result_error(context, "No such tokenizer module", -1);
97453
+ goto exprtest_out;
97454
+ }
97455
+
97456
+ rc = pModule->xCreate(0, 0, &pTokenizer);
97457
+ assert( rc==SQLITE_NOMEM || rc==SQLITE_OK );
97458
+ if( rc==SQLITE_NOMEM ){
97459
+ sqlite3_result_error_nomem(context);
97460
+ goto exprtest_out;
97461
+ }
97462
+ pTokenizer->pModule = pModule;
97463
+
97464
+ zExpr = (const char *)sqlite3_value_text(argv[1]);
97465
+ nExpr = sqlite3_value_bytes(argv[1]);
97466
+ nCol = argc-2;
97467
+ azCol = (char **)sqlite3_malloc(nCol*sizeof(char *));
97468
+ if( !azCol ){
97469
+ sqlite3_result_error_nomem(context);
97470
+ goto exprtest_out;
97471
+ }
97472
+ for(ii=0; ii<nCol; ii++){
97473
+ azCol[ii] = (char *)sqlite3_value_text(argv[ii+2]);
97474
+ }
97475
+
97476
+ rc = sqlite3Fts3ExprParse(
97477
+ pTokenizer, azCol, nCol, nCol, zExpr, nExpr, &pExpr
97478
+ );
97479
+ if( rc==SQLITE_NOMEM ){
97480
+ sqlite3_result_error_nomem(context);
97481
+ goto exprtest_out;
97482
+ }else if( rc==SQLITE_OK ){
97483
+ char zBuf[4096];
97484
+ exprToString(pExpr, zBuf);
97485
+ sqlite3_result_text(context, zBuf, -1, SQLITE_TRANSIENT);
97486
+ sqlite3Fts3ExprFree(pExpr);
97487
+ }else{
97488
+ sqlite3_result_error(context, "Error parsing expression", -1);
97489
+ }
97490
+
97491
+exprtest_out:
97492
+ if( pModule && pTokenizer ){
97493
+ rc = pModule->xDestroy(pTokenizer);
97494
+ }
97495
+ sqlite3_free(azCol);
97496
+}
97497
+
97498
+/*
97499
+** Register the query expression parser test function fts3_exprtest()
97500
+** with database connection db.
97501
+*/
97502
+SQLITE_PRIVATE void sqlite3Fts3ExprInitTestInterface(sqlite3* db){
97503
+ sqlite3_create_function(
97504
+ db, "fts3_exprtest", -1, SQLITE_UTF8, 0, fts3ExprTest, 0, 0
97505
+ );
97506
+}
97507
+
97508
+#endif
97509
+#endif /* !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_FTS3) */
97510
+
97511
+/************** End of fts3_expr.c *******************************************/
9549997512
/************** Begin file fts3_hash.c ***************************************/
9550097513
/*
9550197514
** 2001 September 22
9550297515
**
9550397516
** The author disclaims copyright to this source code. In place of
@@ -97114,11 +99127,11 @@
9711499127
**
9711599128
*************************************************************************
9711699129
** This file contains code for implementations of the r-tree and r*-tree
9711799130
** algorithms packaged as an SQLite virtual table module.
9711899131
**
97119
-** $Id: rtree.c,v 1.11 2008/11/12 15:24:27 drh Exp $
99132
+** $Id: rtree.c,v 1.12 2008/12/22 15:04:32 danielk1977 Exp $
9712099133
*/
9712199134
9712299135
#if !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_RTREE)
9712399136
9712499137
/*
@@ -97498,11 +99511,12 @@
9749899511
/* Check if the requested node is already in the hash table. If so,
9749999512
** increase its reference count and return it.
9750099513
*/
9750199514
if( (pNode = nodeHashLookup(pRtree, iNode)) ){
9750299515
assert( !pParent || !pNode->pParent || pNode->pParent==pParent );
97503
- if( pParent ){
99516
+ if( pParent && !pNode->pParent ){
99517
+ nodeReference(pParent);
9750499518
pNode->pParent = pParent;
9750599519
}
9750699520
pNode->nRef++;
9750799521
*ppNode = pNode;
9750899522
return SQLITE_OK;
9750999523
--- src/sqlite3.c
+++ src/sqlite3.c
@@ -1,8 +1,8 @@
1 /******************************************************************************
2 ** This file is an amalgamation of many separate C source files from SQLite
3 ** version 3.6.7. By combining all the individual C code files into this
4 ** single large file, the entire code can be compiled as a one translation
5 ** unit. This allows many compilers to do optimizations that would not be
6 ** possible if the files were compiled separately. Performance improvements
7 ** of 5% are more are commonly seen when SQLite is compiled as a single
8 ** translation unit.
@@ -9,17 +9,17 @@
9 **
10 ** This file is all you need to compile SQLite. To use SQLite in other
11 ** programs, you need this file and the "sqlite3.h" header file that defines
12 ** the programming interface to the SQLite library. (If you do not have
13 ** the "sqlite3.h" header file at hand, you will find a copy in the first
14 ** 6735 lines past this header comment.) Additional code files may be
15 ** needed if you want a wrapper to interface SQLite with your choice of
16 ** programming language. The code for the "sqlite3" command-line shell
17 ** is also in a separate file. This file contains only code for the core
18 ** SQLite library.
19 **
20 ** This amalgamation was generated on 2008-12-16 18:01:52 UTC.
21 */
22 #define SQLITE_CORE 1
23 #define SQLITE_AMALGAMATION 1
24 #ifndef SQLITE_PRIVATE
25 # define SQLITE_PRIVATE static
@@ -39,11 +39,11 @@
39 ** May you share freely, never taking more than you give.
40 **
41 *************************************************************************
42 ** Internal interface definitions for SQLite.
43 **
44 ** @(#) $Id: sqliteInt.h,v 1.809 2008/12/10 21:19:57 drh Exp $
45 */
46 #ifndef _SQLITEINT_H_
47 #define _SQLITEINT_H_
48
49 /*
@@ -68,11 +68,11 @@
68 **
69 *************************************************************************
70 **
71 ** This file defines various limits of what SQLite can process.
72 **
73 ** @(#) $Id: sqliteLimit.h,v 1.8 2008/03/26 15:56:22 drh Exp $
74 */
75
76 /*
77 ** The maximum length of a TEXT or BLOB in bytes. This also
78 ** limits the size of a row in a table or index.
@@ -152,11 +152,11 @@
152
153 /*
154 ** The maximum number of arguments to an SQL function.
155 */
156 #ifndef SQLITE_MAX_FUNCTION_ARG
157 # define SQLITE_MAX_FUNCTION_ARG 100
158 #endif
159
160 /*
161 ** The maximum number of in-memory pages to use for the main database
162 ** table and for temporary tables. The SQLITE_DEFAULT_CACHE_SIZE
@@ -275,12 +275,14 @@
275 ** in places where simple condition/decision coverage is inadequate.
276 */
277 #ifdef SQLITE_COVERAGE_TEST
278 SQLITE_PRIVATE void sqlite3Coverage(int);
279 # define testcase(X) if( X ){ sqlite3Coverage(__LINE__); }
 
280 #else
281 # define testcase(X)
 
282 #endif
283
284 /*
285 ** The ALWAYS and NEVER macros surround boolean expressions which
286 ** are intended to always be true or false, respectively. Such
@@ -451,10 +453,24 @@
451 */
452 #if !defined(NDEBUG) && !defined(SQLITE_DEBUG)
453 # define NDEBUG 1
454 #endif
455
 
 
 
 
 
 
 
 
 
 
 
 
 
 
456 /************** Include sqlite3.h in the middle of sqliteInt.h ***************/
457 /************** Begin file sqlite3.h *****************************************/
458 /*
459 ** 2001 September 15
460 **
@@ -485,11 +501,11 @@
485 ** The name of this file under configuration management is "sqlite.h.in".
486 ** The makefile makes some minor changes to this file (such as inserting
487 ** the version number) and changes its name to "sqlite3.h" as
488 ** part of the build process.
489 **
490 ** @(#) $Id: sqlite.h.in,v 1.420 2008/12/16 13:46:30 drh Exp $
491 */
492 #ifndef _SQLITE3_H_
493 #define _SQLITE3_H_
494 #include <stdarg.h> /* Needed for the definition of va_list */
495
@@ -562,12 +578,12 @@
562 **
563 ** {H10014} The SQLITE_VERSION_NUMBER #define shall resolve to an integer
564 ** with the value (X*1000000 + Y*1000 + Z) where X, Y, and Z
565 ** are the major version, minor version, and release number.
566 */
567 #define SQLITE_VERSION "3.6.7"
568 #define SQLITE_VERSION_NUMBER 3006007
569
570 /*
571 ** CAPI3REF: Run-Time Library Version Numbers {H10020} <S60100>
572 ** KEYWORDS: sqlite3_version
573 **
@@ -2852,20 +2868,21 @@
2852 #define SQLITE_DROP_VIEW 17 /* View Name NULL */
2853 #define SQLITE_INSERT 18 /* Table Name NULL */
2854 #define SQLITE_PRAGMA 19 /* Pragma Name 1st arg or NULL */
2855 #define SQLITE_READ 20 /* Table Name Column Name */
2856 #define SQLITE_SELECT 21 /* NULL NULL */
2857 #define SQLITE_TRANSACTION 22 /* NULL NULL */
2858 #define SQLITE_UPDATE 23 /* Table Name Column Name */
2859 #define SQLITE_ATTACH 24 /* Filename NULL */
2860 #define SQLITE_DETACH 25 /* Database Name NULL */
2861 #define SQLITE_ALTER_TABLE 26 /* Database Name Table Name */
2862 #define SQLITE_REINDEX 27 /* Index Name NULL */
2863 #define SQLITE_ANALYZE 28 /* Table Name NULL */
2864 #define SQLITE_CREATE_VTABLE 29 /* Table Name Module Name */
2865 #define SQLITE_DROP_VTABLE 30 /* Table Name Module Name */
2866 #define SQLITE_FUNCTION 31 /* NULL Function Name */
 
2867 #define SQLITE_COPY 0 /* No longer used */
2868
2869 /*
2870 ** CAPI3REF: Tracing And Profiling Functions {H12280} <S60400>
2871 ** EXPERIMENTAL
@@ -7297,150 +7314,152 @@
7297 #define TK_IMMEDIATE 8
7298 #define TK_EXCLUSIVE 9
7299 #define TK_COMMIT 10
7300 #define TK_END 11
7301 #define TK_ROLLBACK 12
7302 #define TK_CREATE 13
7303 #define TK_TABLE 14
7304 #define TK_IF 15
7305 #define TK_NOT 16
7306 #define TK_EXISTS 17
7307 #define TK_TEMP 18
7308 #define TK_LP 19
7309 #define TK_RP 20
7310 #define TK_AS 21
7311 #define TK_COMMA 22
7312 #define TK_ID 23
7313 #define TK_ABORT 24
7314 #define TK_AFTER 25
7315 #define TK_ANALYZE 26
7316 #define TK_ASC 27
7317 #define TK_ATTACH 28
7318 #define TK_BEFORE 29
7319 #define TK_CASCADE 30
7320 #define TK_CAST 31
7321 #define TK_CONFLICT 32
7322 #define TK_DATABASE 33
7323 #define TK_DESC 34
7324 #define TK_DETACH 35
7325 #define TK_EACH 36
7326 #define TK_FAIL 37
7327 #define TK_FOR 38
7328 #define TK_IGNORE 39
7329 #define TK_INITIALLY 40
7330 #define TK_INSTEAD 41
7331 #define TK_LIKE_KW 42
7332 #define TK_MATCH 43
7333 #define TK_KEY 44
7334 #define TK_OF 45
7335 #define TK_OFFSET 46
7336 #define TK_PRAGMA 47
7337 #define TK_RAISE 48
7338 #define TK_REPLACE 49
7339 #define TK_RESTRICT 50
7340 #define TK_ROW 51
7341 #define TK_TRIGGER 52
7342 #define TK_VACUUM 53
7343 #define TK_VIEW 54
7344 #define TK_VIRTUAL 55
7345 #define TK_REINDEX 56
7346 #define TK_RENAME 57
7347 #define TK_CTIME_KW 58
7348 #define TK_ANY 59
7349 #define TK_OR 60
7350 #define TK_AND 61
7351 #define TK_IS 62
7352 #define TK_BETWEEN 63
7353 #define TK_IN 64
7354 #define TK_ISNULL 65
7355 #define TK_NOTNULL 66
7356 #define TK_NE 67
7357 #define TK_EQ 68
7358 #define TK_GT 69
7359 #define TK_LE 70
7360 #define TK_LT 71
7361 #define TK_GE 72
7362 #define TK_ESCAPE 73
7363 #define TK_BITAND 74
7364 #define TK_BITOR 75
7365 #define TK_LSHIFT 76
7366 #define TK_RSHIFT 77
7367 #define TK_PLUS 78
7368 #define TK_MINUS 79
7369 #define TK_STAR 80
7370 #define TK_SLASH 81
7371 #define TK_REM 82
7372 #define TK_CONCAT 83
7373 #define TK_COLLATE 84
7374 #define TK_UMINUS 85
7375 #define TK_UPLUS 86
7376 #define TK_BITNOT 87
7377 #define TK_STRING 88
7378 #define TK_JOIN_KW 89
7379 #define TK_CONSTRAINT 90
7380 #define TK_DEFAULT 91
7381 #define TK_NULL 92
7382 #define TK_PRIMARY 93
7383 #define TK_UNIQUE 94
7384 #define TK_CHECK 95
7385 #define TK_REFERENCES 96
7386 #define TK_AUTOINCR 97
7387 #define TK_ON 98
7388 #define TK_DELETE 99
7389 #define TK_UPDATE 100
7390 #define TK_INSERT 101
7391 #define TK_SET 102
7392 #define TK_DEFERRABLE 103
7393 #define TK_FOREIGN 104
7394 #define TK_DROP 105
7395 #define TK_UNION 106
7396 #define TK_ALL 107
7397 #define TK_EXCEPT 108
7398 #define TK_INTERSECT 109
7399 #define TK_SELECT 110
7400 #define TK_DISTINCT 111
7401 #define TK_DOT 112
7402 #define TK_FROM 113
7403 #define TK_JOIN 114
7404 #define TK_INDEXED 115
7405 #define TK_BY 116
7406 #define TK_USING 117
7407 #define TK_ORDER 118
7408 #define TK_GROUP 119
7409 #define TK_HAVING 120
7410 #define TK_LIMIT 121
7411 #define TK_WHERE 122
7412 #define TK_INTO 123
7413 #define TK_VALUES 124
7414 #define TK_INTEGER 125
7415 #define TK_FLOAT 126
7416 #define TK_BLOB 127
7417 #define TK_REGISTER 128
7418 #define TK_VARIABLE 129
7419 #define TK_CASE 130
7420 #define TK_WHEN 131
7421 #define TK_THEN 132
7422 #define TK_ELSE 133
7423 #define TK_INDEX 134
7424 #define TK_ALTER 135
7425 #define TK_TO 136
7426 #define TK_ADD 137
7427 #define TK_COLUMNKW 138
7428 #define TK_TO_TEXT 139
7429 #define TK_TO_BLOB 140
7430 #define TK_TO_NUMERIC 141
7431 #define TK_TO_INT 142
7432 #define TK_TO_REAL 143
7433 #define TK_END_OF_FILE 144
7434 #define TK_ILLEGAL 145
7435 #define TK_SPACE 146
7436 #define TK_UNCLOSED_STRING 147
7437 #define TK_FUNCTION 148
7438 #define TK_COLUMN 149
7439 #define TK_AGG_FUNCTION 150
7440 #define TK_AGG_COLUMN 151
7441 #define TK_CONST_FUNC 152
 
 
7442
7443 /************** End of parse.h ***********************************************/
7444 /************** Continuing where we left off in sqliteInt.h ******************/
7445 #include <stdio.h>
7446 #include <stdlib.h>
@@ -7723,10 +7742,11 @@
7723 typedef struct Lookaside Lookaside;
7724 typedef struct LookasideSlot LookasideSlot;
7725 typedef struct Module Module;
7726 typedef struct NameContext NameContext;
7727 typedef struct Parse Parse;
 
7728 typedef struct Select Select;
7729 typedef struct SrcList SrcList;
7730 typedef struct StrAccum StrAccum;
7731 typedef struct Table Table;
7732 typedef struct TableLock TableLock;
@@ -7734,10 +7754,11 @@
7734 typedef struct TriggerStack TriggerStack;
7735 typedef struct TriggerStep TriggerStep;
7736 typedef struct Trigger Trigger;
7737 typedef struct UnpackedRecord UnpackedRecord;
7738 typedef struct Walker Walker;
 
7739 typedef struct WhereInfo WhereInfo;
7740 typedef struct WhereLevel WhereLevel;
7741
7742 /*
7743 ** Defer sourcing vdbe.h and btree.h until after the "u8" and
@@ -7759,11 +7780,11 @@
7759 *************************************************************************
7760 ** This header file defines the interface that the sqlite B-Tree file
7761 ** subsystem. See comments in the source code for a detailed description
7762 ** of what each interface routine does.
7763 **
7764 ** @(#) $Id: btree.h,v 1.105 2008/10/27 13:59:34 danielk1977 Exp $
7765 */
7766 #ifndef _BTREE_H_
7767 #define _BTREE_H_
7768
7769 /* TODO: This definition is just included so other modules compile. It
@@ -7847,10 +7868,11 @@
7847 SQLITE_PRIVATE int sqlite3BtreeIsInStmt(Btree*);
7848 SQLITE_PRIVATE int sqlite3BtreeIsInReadTrans(Btree*);
7849 SQLITE_PRIVATE void *sqlite3BtreeSchema(Btree *, int, void(*)(void *));
7850 SQLITE_PRIVATE int sqlite3BtreeSchemaLocked(Btree *);
7851 SQLITE_PRIVATE int sqlite3BtreeLockTable(Btree *, int, u8);
 
7852
7853 SQLITE_PRIVATE const char *sqlite3BtreeGetFilename(Btree *);
7854 SQLITE_PRIVATE const char *sqlite3BtreeGetDirname(Btree *);
7855 SQLITE_PRIVATE const char *sqlite3BtreeGetJournalname(Btree *);
7856 SQLITE_PRIVATE int sqlite3BtreeCopyFile(Btree *, Btree *);
@@ -8122,155 +8144,157 @@
8122 */
8123 /************** Include opcodes.h in the middle of vdbe.h ********************/
8124 /************** Begin file opcodes.h *****************************************/
8125 /* Automatically generated. Do not edit */
8126 /* See the mkopcodeh.awk script for details */
8127 #define OP_VNext 1
8128 #define OP_Affinity 2
8129 #define OP_Column 3
8130 #define OP_SetCookie 4
8131 #define OP_Seek 5
8132 #define OP_Real 126 /* same as TK_FLOAT */
8133 #define OP_Sequence 6
8134 #define OP_Ge 72 /* same as TK_GE */
8135 #define OP_RowKey 7
8136 #define OP_SCopy 8
8137 #define OP_Eq 68 /* same as TK_EQ */
8138 #define OP_OpenWrite 9
8139 #define OP_NotNull 66 /* same as TK_NOTNULL */
8140 #define OP_If 10
8141 #define OP_ToInt 142 /* same as TK_TO_INT */
8142 #define OP_String8 88 /* same as TK_STRING */
8143 #define OP_VRowid 11
8144 #define OP_CollSeq 12
8145 #define OP_OpenRead 13
8146 #define OP_Expire 14
8147 #define OP_AutoCommit 15
8148 #define OP_Gt 69 /* same as TK_GT */
8149 #define OP_Pagecount 17
8150 #define OP_IntegrityCk 18
8151 #define OP_Sort 19
8152 #define OP_Copy 20
8153 #define OP_Trace 21
8154 #define OP_Function 22
8155 #define OP_IfNeg 23
8156 #define OP_And 61 /* same as TK_AND */
8157 #define OP_Subtract 79 /* same as TK_MINUS */
8158 #define OP_Noop 24
8159 #define OP_Return 25
8160 #define OP_Remainder 82 /* same as TK_REM */
8161 #define OP_NewRowid 26
8162 #define OP_Multiply 80 /* same as TK_STAR */
8163 #define OP_Variable 27
8164 #define OP_String 28
8165 #define OP_RealAffinity 29
8166 #define OP_VRename 30
8167 #define OP_ParseSchema 31
8168 #define OP_VOpen 32
8169 #define OP_Close 33
8170 #define OP_CreateIndex 34
8171 #define OP_IsUnique 35
8172 #define OP_NotFound 36
8173 #define OP_Int64 37
8174 #define OP_MustBeInt 38
8175 #define OP_Halt 39
8176 #define OP_Rowid 40
8177 #define OP_IdxLT 41
8178 #define OP_AddImm 42
8179 #define OP_Statement 43
8180 #define OP_RowData 44
8181 #define OP_MemMax 45
8182 #define OP_Or 60 /* same as TK_OR */
8183 #define OP_NotExists 46
8184 #define OP_Gosub 47
8185 #define OP_Divide 81 /* same as TK_SLASH */
8186 #define OP_Integer 48
8187 #define OP_ToNumeric 141 /* same as TK_TO_NUMERIC*/
8188 #define OP_Prev 49
8189 #define OP_RowSetRead 50
8190 #define OP_Concat 83 /* same as TK_CONCAT */
8191 #define OP_RowSetAdd 51
8192 #define OP_BitAnd 74 /* same as TK_BITAND */
8193 #define OP_VColumn 52
8194 #define OP_CreateTable 53
8195 #define OP_Last 54
8196 #define OP_SeekLe 55
8197 #define OP_IsNull 65 /* same as TK_ISNULL */
8198 #define OP_IncrVacuum 56
8199 #define OP_IdxRowid 57
8200 #define OP_ShiftRight 77 /* same as TK_RSHIFT */
8201 #define OP_ResetCount 58
8202 #define OP_ContextPush 59
8203 #define OP_Yield 62
8204 #define OP_DropTrigger 63
8205 #define OP_DropIndex 64
8206 #define OP_IdxGE 73
8207 #define OP_IdxDelete 84
8208 #define OP_Vacuum 85
8209 #define OP_IfNot 86
8210 #define OP_DropTable 89
8211 #define OP_SeekLt 90
8212 #define OP_MakeRecord 91
8213 #define OP_ToBlob 140 /* same as TK_TO_BLOB */
8214 #define OP_ResultRow 92
8215 #define OP_Delete 93
8216 #define OP_AggFinal 94
8217 #define OP_Compare 95
8218 #define OP_ShiftLeft 76 /* same as TK_LSHIFT */
8219 #define OP_Goto 96
8220 #define OP_TableLock 97
8221 #define OP_Clear 98
8222 #define OP_Le 70 /* same as TK_LE */
8223 #define OP_VerifyCookie 99
8224 #define OP_AggStep 100
8225 #define OP_ToText 139 /* same as TK_TO_TEXT */
8226 #define OP_Not 16 /* same as TK_NOT */
8227 #define OP_ToReal 143 /* same as TK_TO_REAL */
8228 #define OP_SetNumColumns 101
8229 #define OP_Transaction 102
8230 #define OP_VFilter 103
8231 #define OP_Ne 67 /* same as TK_NE */
8232 #define OP_VDestroy 104
8233 #define OP_ContextPop 105
8234 #define OP_BitOr 75 /* same as TK_BITOR */
8235 #define OP_Next 106
8236 #define OP_IdxInsert 107
8237 #define OP_Lt 71 /* same as TK_LT */
8238 #define OP_SeekGe 108
8239 #define OP_Insert 109
8240 #define OP_Destroy 110
8241 #define OP_ReadCookie 111
8242 #define OP_LoadAnalysis 112
8243 #define OP_Explain 113
8244 #define OP_OpenPseudo 114
8245 #define OP_OpenEphemeral 115
8246 #define OP_Null 116
8247 #define OP_Move 117
8248 #define OP_Blob 118
8249 #define OP_Add 78 /* same as TK_PLUS */
8250 #define OP_Rewind 119
8251 #define OP_SeekGt 120
8252 #define OP_VBegin 121
8253 #define OP_VUpdate 122
8254 #define OP_IfZero 123
8255 #define OP_BitNot 87 /* same as TK_BITNOT */
8256 #define OP_VCreate 124
8257 #define OP_Found 125
 
 
 
 
8258 #define OP_IfPos 127
8259 #define OP_NullRow 128
8260 #define OP_Jump 129
8261 #define OP_Permutation 130
 
 
8262
8263 /* The following opcode values are never used */
8264 #define OP_NotUsed_131 131
8265 #define OP_NotUsed_132 132
8266 #define OP_NotUsed_133 133
8267 #define OP_NotUsed_134 134
8268 #define OP_NotUsed_135 135
8269 #define OP_NotUsed_136 136
8270 #define OP_NotUsed_137 137
8271 #define OP_NotUsed_138 138
 
 
8272
8273
8274 /* Properties such as "out2" or "jump" that are specified in
8275 ** comments following the "case" for each opcode in the vdbe.c
8276 ** are encoded into bitvectors as follows:
@@ -8280,29 +8304,29 @@
8280 #define OPFLG_IN1 0x0004 /* in1: P1 is an input */
8281 #define OPFLG_IN2 0x0008 /* in2: P2 is an input */
8282 #define OPFLG_IN3 0x0010 /* in3: P3 is an input */
8283 #define OPFLG_OUT3 0x0020 /* out3: P3 is an output */
8284 #define OPFLG_INITIALIZER {\
8285 /* 0 */ 0x00, 0x01, 0x00, 0x00, 0x10, 0x08, 0x02, 0x00,\
8286 /* 8 */ 0x00, 0x00, 0x05, 0x02, 0x00, 0x00, 0x00, 0x00,\
8287 /* 16 */ 0x04, 0x02, 0x00, 0x01, 0x00, 0x00, 0x00, 0x05,\
8288 /* 24 */ 0x00, 0x04, 0x02, 0x02, 0x02, 0x04, 0x00, 0x00,\
8289 /* 32 */ 0x00, 0x00, 0x02, 0x11, 0x11, 0x02, 0x05, 0x00,\
8290 /* 40 */ 0x02, 0x11, 0x04, 0x00, 0x00, 0x0c, 0x11, 0x01,\
8291 /* 48 */ 0x02, 0x01, 0x21, 0x08, 0x00, 0x02, 0x01, 0x11,\
8292 /* 56 */ 0x01, 0x02, 0x00, 0x00, 0x2c, 0x2c, 0x00, 0x00,\
8293 /* 64 */ 0x00, 0x05, 0x05, 0x15, 0x15, 0x15, 0x15, 0x15,\
8294 /* 72 */ 0x15, 0x11, 0x2c, 0x2c, 0x2c, 0x2c, 0x2c, 0x2c,\
8295 /* 80 */ 0x2c, 0x2c, 0x2c, 0x2c, 0x00, 0x00, 0x05, 0x04,\
8296 /* 88 */ 0x02, 0x00, 0x11, 0x00, 0x00, 0x00, 0x00, 0x00,\
8297 /* 96 */ 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,\
8298 /* 104 */ 0x00, 0x00, 0x01, 0x08, 0x11, 0x00, 0x02, 0x02,\
8299 /* 112 */ 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x02, 0x01,\
8300 /* 120 */ 0x11, 0x00, 0x00, 0x05, 0x00, 0x11, 0x02, 0x05,\
8301 /* 128 */ 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\
8302 /* 136 */ 0x00, 0x00, 0x00, 0x04, 0x04, 0x04, 0x04, 0x04,\
8303 }
8304
8305 /************** End of opcodes.h *********************************************/
8306 /************** Continuing where we left off in vdbe.h ***********************/
8307
8308 /*
@@ -8381,11 +8405,11 @@
8381 *************************************************************************
8382 ** This header file defines the interface that the sqlite page cache
8383 ** subsystem. The page cache subsystem reads and writes a file a page
8384 ** at a time and provides a journal for rollback.
8385 **
8386 ** @(#) $Id: pager.h,v 1.88 2008/12/10 16:45:51 drh Exp $
8387 */
8388
8389 #ifndef _PAGER_H_
8390 #define _PAGER_H_
8391
@@ -8456,19 +8480,15 @@
8456 SQLITE_PRIVATE int sqlite3PagerPageRefcount(DbPage*);
8457 SQLITE_PRIVATE int sqlite3PagerRef(DbPage*);
8458 SQLITE_PRIVATE int sqlite3PagerUnref(DbPage*);
8459 SQLITE_PRIVATE int sqlite3PagerWrite(DbPage*);
8460 SQLITE_PRIVATE int sqlite3PagerPagecount(Pager*, int*);
8461 SQLITE_PRIVATE int sqlite3PagerTruncate(Pager*,Pgno);
8462 SQLITE_PRIVATE int sqlite3PagerBegin(DbPage*, int exFlag);
8463 SQLITE_PRIVATE int sqlite3PagerCommitPhaseOne(Pager*,const char *zMaster, Pgno, int);
8464 SQLITE_PRIVATE int sqlite3PagerCommitPhaseTwo(Pager*);
8465 SQLITE_PRIVATE int sqlite3PagerRollback(Pager*);
8466 SQLITE_PRIVATE u8 sqlite3PagerIsreadonly(Pager*);
8467 SQLITE_PRIVATE int sqlite3PagerStmtBegin(Pager*);
8468 SQLITE_PRIVATE int sqlite3PagerStmtCommit(Pager*);
8469 SQLITE_PRIVATE int sqlite3PagerStmtRollback(Pager*);
8470 SQLITE_PRIVATE void sqlite3PagerDontRollback(DbPage*);
8471 SQLITE_PRIVATE int sqlite3PagerDontWrite(DbPage*);
8472 SQLITE_PRIVATE int sqlite3PagerRefcount(Pager*);
8473 SQLITE_PRIVATE void sqlite3PagerSetSafetyLevel(Pager*,int,int);
8474 SQLITE_PRIVATE const char *sqlite3PagerFilename(Pager*);
@@ -8483,10 +8503,18 @@
8483 SQLITE_PRIVATE int sqlite3PagerLockingMode(Pager *, int);
8484 SQLITE_PRIVATE int sqlite3PagerJournalMode(Pager *, int);
8485 SQLITE_PRIVATE i64 sqlite3PagerJournalSizeLimit(Pager *, i64);
8486 SQLITE_PRIVATE void *sqlite3PagerTempSpace(Pager*);
8487 SQLITE_PRIVATE int sqlite3PagerSync(Pager *pPager);
 
 
 
 
 
 
 
 
8488
8489 #ifdef SQLITE_HAS_CODEC
8490 SQLITE_PRIVATE void sqlite3PagerSetCodec(Pager*,void*(*)(void*,void*,Pgno,int),void*);
8491 #endif
8492
@@ -9249,10 +9277,13 @@
9249 int busyTimeout; /* Busy handler timeout, in msec */
9250 Db aDbStatic[2]; /* Static space for the 2 default backends */
9251 #ifdef SQLITE_SSE
9252 sqlite3_stmt *pFetch; /* Used by SSE to fetch stored statements */
9253 #endif
 
 
 
9254 };
9255
9256 /*
9257 ** A macro to discover the encoding of a database.
9258 */
@@ -9287,10 +9318,11 @@
9287 #define SQLITE_LoadExtension 0x00020000 /* Enable load_extension */
9288
9289 #define SQLITE_RecoveryMode 0x00040000 /* Ignore schema errors */
9290 #define SQLITE_SharedCache 0x00080000 /* Cache sharing is enabled */
9291 #define SQLITE_Vtab 0x00100000 /* There exists a virtual table */
 
9292
9293 /*
9294 ** Possible values for the sqlite.magic field.
9295 ** The numbers are obtained at random and have no special meaning, other
9296 ** than being distinct from one another.
@@ -9360,10 +9392,29 @@
9360 #define LIKEFUNC(zName, nArg, arg, flags) \
9361 {nArg, SQLITE_UTF8, flags, (void *)arg, 0, likeFunc, 0, 0, #zName, 0}
9362 #define AGGREGATE(zName, nArg, arg, nc, xStep, xFinal) \
9363 {nArg, SQLITE_UTF8, nc*8, SQLITE_INT_TO_PTR(arg), 0, 0, xStep,xFinal,#zName,0}
9364
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9365
9366 /*
9367 ** Each SQLite module (virtual table definition) is defined by an
9368 ** instance of the following structure, stored in the sqlite3.aModule
9369 ** hash table.
@@ -9959,15 +10010,15 @@
9959 char *zAlias; /* The "B" part of a "A AS B" phrase. zName is the "A" */
9960 Table *pTab; /* An SQL table corresponding to zName */
9961 Select *pSelect; /* A SELECT statement used in place of a table name */
9962 u8 isPopulated; /* Temporary table associated with SELECT is populated */
9963 u8 jointype; /* Type of join between this able and the previous */
 
9964 int iCursor; /* The VDBE cursor number used to access this table */
9965 Expr *pOn; /* The ON clause of a join */
9966 IdList *pUsing; /* The USING clause of a join */
9967 Bitmask colUsed; /* Bit N (1<<N) set if column N or pTab is used */
9968 u8 notIndexed; /* True if there is a NOT INDEXED clause */
9969 char *zIndex; /* Identifier from "INDEXED BY <zIndex>" clause */
9970 Index *pIndex; /* Index structure corresponding to zIndex, if any */
9971 } a[1]; /* One entry for each identifier on the list */
9972 };
9973
@@ -9980,65 +10031,92 @@
9980 #define JT_LEFT 0x0008 /* Left outer join */
9981 #define JT_RIGHT 0x0010 /* Right outer join */
9982 #define JT_OUTER 0x0020 /* The "OUTER" keyword is present */
9983 #define JT_ERROR 0x0040 /* unknown or unsupported join type */
9984
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9985 /*
9986 ** For each nested loop in a WHERE clause implementation, the WhereInfo
9987 ** structure contains a single instance of this structure. This structure
9988 ** is intended to be private the the where.c module and should not be
9989 ** access or modified by other modules.
9990 **
9991 ** The pIdxInfo and pBestIdx fields are used to help pick the best
9992 ** index on a virtual table. The pIdxInfo pointer contains indexing
9993 ** information for the i-th table in the FROM clause before reordering.
9994 ** All the pIdxInfo pointers are freed by whereInfoFree() in where.c.
9995 ** The pBestIdx pointer is a copy of pIdxInfo for the i-th table after
9996 ** FROM clause ordering. This is a little confusing so I will repeat
9997 ** it in different words. WhereInfo.a[i].pIdxInfo is index information
9998 ** for WhereInfo.pTabList.a[i]. WhereInfo.a[i].pBestInfo is the
9999 ** index information for the i-th loop of the join. pBestInfo is always
10000 ** either NULL or a copy of some pIdxInfo. So for cleanup it is
10001 ** sufficient to free all of the pIdxInfo pointers.
10002 **
10003 */
10004 struct WhereLevel {
10005 int iFrom; /* Which entry in the FROM clause */
10006 int wsFlags; /* "Where-Scan" flags show the choosen scan strategy */
10007 int iMem; /* First memory cell used by this level */
10008 int iLeftJoin; /* Memory cell used to implement LEFT OUTER JOIN */
10009 Index *pIdx; /* Index used. NULL if no index */
10010 int iTabCur; /* The VDBE cursor used to access the table */
10011 int iIdxCur; /* The VDBE cursor used to access pIdx */
10012 int addrBrk; /* Jump here to break out of the loop */
10013 int addrNxt; /* Jump here to start the next IN combination */
10014 int addrCont; /* Jump here to continue with the next loop cycle */
10015 int addrFirst; /* First instruction of interior of the loop */
10016 int op, p1, p2; /* Opcode used to terminate the loop */
10017 u8 p5; /* P5 operand of the opcode that terminates the loop */
10018 int nEq; /* Number of == or IN constraints on this loop */
10019 int nIn; /* Number of IN operators constraining this loop */
10020 struct InLoop {
10021 int iCur; /* The VDBE cursor used by this IN operator */
10022 int addrInTop; /* Top of the IN loop */
10023 } *aInLoop; /* Information about each nested IN operator */
10024 sqlite3_index_info *pBestIdx; /* Index information for this level */
 
 
 
 
 
 
10025
10026 /* The following field is really not part of the current level. But
10027 ** we need a place to cache index information for each table in the
10028 ** FROM clause and the WhereLevel structure is a convenient place.
 
 
10029 */
10030 sqlite3_index_info *pIdxInfo; /* Index info for n-th source table */
10031 };
10032
10033 /*
10034 ** Flags appropriate for the wctrlFlags parameter of sqlite3WhereBegin().
10035 */
10036 #define WHERE_ORDERBY_NORMAL 0 /* No-op */
10037 #define WHERE_ORDERBY_MIN 1 /* ORDER BY processing for min() func */
10038 #define WHERE_ORDERBY_MAX 2 /* ORDER BY processing for max() func */
10039 #define WHERE_ONEPASS_DESIRED 4 /* Want to do one-pass UPDATE/DELETE */
 
 
 
10040
10041 /*
10042 ** The WHERE clause processing routine has two halves. The
10043 ** first part does the start of the WHERE loop and the second
10044 ** half does the tail of the WHERE loop. An instance of
@@ -10045,18 +10123,20 @@
10045 ** this structure is returned by the first half and passed
10046 ** into the second half to give some continuity.
10047 */
10048 struct WhereInfo {
10049 Parse *pParse; /* Parsing and code generating context */
 
10050 u8 okOnePass; /* Ok to use one-pass algorithm for UPDATE or DELETE */
10051 SrcList *pTabList; /* List of tables in the join */
10052 int iTop; /* The very beginning of the WHERE loop */
10053 int iContinue; /* Jump here to continue with next record */
10054 int iBreak; /* Jump here to break out of the loop */
10055 int nLevel; /* Number of nested loop */
10056 sqlite3_index_info **apInfo; /* Array of pointers to index info structures */
10057 WhereLevel a[1]; /* Information about each nest loop in the WHERE */
 
10058 };
10059
10060 /*
10061 ** A NameContext defines a context in which to resolve table and column
10062 ** names. The context consists of a list of tables (the pSrcList) field and
@@ -10695,11 +10775,11 @@
10695 #if defined(SQLITE_ENABLE_UPDATE_DELETE_LIMIT) && !defined(SQLITE_OMIT_SUBQUERY)
10696 SQLITE_PRIVATE Expr *sqlite3LimitWhere(Parse *, SrcList *, Expr *, ExprList *, Expr *, Expr *, char *);
10697 #endif
10698 SQLITE_PRIVATE void sqlite3DeleteFrom(Parse*, SrcList*, Expr*);
10699 SQLITE_PRIVATE void sqlite3Update(Parse*, SrcList*, ExprList*, Expr*, int);
10700 SQLITE_PRIVATE WhereInfo *sqlite3WhereBegin(Parse*, SrcList*, Expr*, ExprList**, u8);
10701 SQLITE_PRIVATE void sqlite3WhereEnd(WhereInfo*);
10702 SQLITE_PRIVATE int sqlite3ExprCodeGetColumn(Parse*, Table*, int, int, int, int);
10703 SQLITE_PRIVATE void sqlite3ExprCodeMove(Parse*, int, int, int);
10704 SQLITE_PRIVATE void sqlite3ExprCodeCopy(Parse*, int, int, int);
10705 SQLITE_PRIVATE void sqlite3ExprClearColumnCache(Parse*, int);
@@ -10733,10 +10813,12 @@
10733 SQLITE_PRIVATE void sqlite3RollbackAll(sqlite3*);
10734 SQLITE_PRIVATE void sqlite3CodeVerifySchema(Parse*, int);
10735 SQLITE_PRIVATE void sqlite3BeginTransaction(Parse*, int);
10736 SQLITE_PRIVATE void sqlite3CommitTransaction(Parse*);
10737 SQLITE_PRIVATE void sqlite3RollbackTransaction(Parse*);
 
 
10738 SQLITE_PRIVATE int sqlite3ExprIsConstant(Expr*);
10739 SQLITE_PRIVATE int sqlite3ExprIsConstantNotJoin(Expr*);
10740 SQLITE_PRIVATE int sqlite3ExprIsConstantOrFunction(Expr*);
10741 SQLITE_PRIVATE int sqlite3ExprIsInteger(Expr*, int*);
10742 SQLITE_PRIVATE int sqlite3IsRowid(const char*);
@@ -11031,11 +11113,11 @@
11031 #else
11032 #define sqlite3JournalSize(pVfs) ((pVfs)->szOsFile)
11033 #endif
11034
11035 SQLITE_PRIVATE void sqlite3MemJournalOpen(sqlite3_file *);
11036 SQLITE_PRIVATE int sqlite3MemJournalSize();
11037 SQLITE_PRIVATE int sqlite3IsMemJournal(sqlite3_file *);
11038
11039 #if SQLITE_MAX_EXPR_DEPTH>0
11040 SQLITE_PRIVATE void sqlite3ExprSetHeight(Parse *pParse, Expr *p);
11041 SQLITE_PRIVATE int sqlite3SelectExprHeight(Select *);
@@ -11321,11 +11403,11 @@
11321 **
11322 ** There is only one exported symbol in this file - the function
11323 ** sqlite3RegisterDateTimeFunctions() found at the bottom of the file.
11324 ** All other code has file scope.
11325 **
11326 ** $Id: date.c,v 1.98 2008/12/10 22:30:25 shane Exp $
11327 **
11328 ** SQLite processes all times and dates as Julian Day numbers. The
11329 ** dates and times are stored as the number of days since noon
11330 ** in Greenwich on November 24, 4714 B.C. according to the Gregorian
11331 ** calendar system.
@@ -11750,11 +11832,11 @@
11750 x.s = s;
11751 }
11752 x.tz = 0;
11753 x.validJD = 0;
11754 computeJD(&x);
11755 t = x.iJD/1000 - 210866760000LL;
11756 #ifdef HAVE_LOCALTIME_R
11757 {
11758 struct tm sLocal;
11759 localtime_r(&t, &sLocal);
11760 y.Y = sLocal.tm_year + 1900;
@@ -11852,11 +11934,11 @@
11852 **
11853 ** Treat the current value of p->iJD as the number of
11854 ** seconds since 1970. Convert to a real julian day number.
11855 */
11856 if( strcmp(z, "unixepoch")==0 && p->validJD ){
11857 p->iJD = p->iJD/86400 + 210866760000000LL;
11858 clearYMD_HMS_TZ(p);
11859 rc = 0;
11860 }
11861 #ifndef SQLITE_OMIT_LOCALTIME
11862 else if( strcmp(z, "utc")==0 ){
@@ -17728,11 +17810,11 @@
17728 ** VDBE. This information used to all be at the top of the single
17729 ** source code file "vdbe.c". When that file became too big (over
17730 ** 6000 lines long) it was split up into several smaller files and
17731 ** this header information was factored out.
17732 **
17733 ** $Id: vdbeInt.h,v 1.160 2008/12/09 02:51:24 drh Exp $
17734 */
17735 #ifndef _VDBEINT_H_
17736 #define _VDBEINT_H_
17737
17738 /*
@@ -17886,11 +17968,12 @@
17886
17887
17888 /*
17889 ** Clear any existing type flags from a Mem and replace them with f
17890 */
17891 #define MemSetTypeFlag(p, f) ((p)->flags = ((p)->flags&~(MEM_TypeMask))|f)
 
17892
17893
17894 /* A VdbeFunc is just a FuncDef (defined in sqliteInt.h) that contains
17895 ** additional information about auxiliary information bound to arguments
17896 ** of the function. This is used to implement the sqlite3_get_auxdata()
@@ -19589,11 +19672,11 @@
19589 **
19590 *************************************************************************
19591 ** This is the implementation of generic hash-tables
19592 ** used in SQLite.
19593 **
19594 ** $Id: hash.c,v 1.32 2008/12/10 19:26:24 drh Exp $
19595 */
19596
19597 /* Turn bulk memory into a hash table object by initializing the
19598 ** fields of the Hash structure.
19599 **
@@ -19623,11 +19706,11 @@
19623 sqlite3_free(pH->ht);
19624 pH->ht = 0;
19625 pH->htsize = 0;
19626 while( elem ){
19627 HashElem *next_elem = elem->next;
19628 if( pH->copyKey && elem->pKey ){
19629 sqlite3_free(elem->pKey);
19630 }
19631 sqlite3_free(elem);
19632 elem = next_elem;
19633 }
@@ -19884,153 +19967,155 @@
19884 /* Automatically generated. Do not edit */
19885 /* See the mkopcodec.awk script for details. */
19886 #if !defined(SQLITE_OMIT_EXPLAIN) || !defined(NDEBUG) || defined(VDBE_PROFILE) || defined(SQLITE_DEBUG)
19887 SQLITE_PRIVATE const char *sqlite3OpcodeName(int i){
19888 static const char *const azName[] = { "?",
19889 /* 1 */ "VNext",
19890 /* 2 */ "Affinity",
19891 /* 3 */ "Column",
19892 /* 4 */ "SetCookie",
19893 /* 5 */ "Seek",
19894 /* 6 */ "Sequence",
19895 /* 7 */ "RowKey",
19896 /* 8 */ "SCopy",
19897 /* 9 */ "OpenWrite",
19898 /* 10 */ "If",
19899 /* 11 */ "VRowid",
19900 /* 12 */ "CollSeq",
19901 /* 13 */ "OpenRead",
19902 /* 14 */ "Expire",
19903 /* 15 */ "AutoCommit",
19904 /* 16 */ "Not",
19905 /* 17 */ "Pagecount",
19906 /* 18 */ "IntegrityCk",
19907 /* 19 */ "Sort",
19908 /* 20 */ "Copy",
19909 /* 21 */ "Trace",
19910 /* 22 */ "Function",
19911 /* 23 */ "IfNeg",
19912 /* 24 */ "Noop",
19913 /* 25 */ "Return",
19914 /* 26 */ "NewRowid",
19915 /* 27 */ "Variable",
19916 /* 28 */ "String",
19917 /* 29 */ "RealAffinity",
19918 /* 30 */ "VRename",
19919 /* 31 */ "ParseSchema",
19920 /* 32 */ "VOpen",
19921 /* 33 */ "Close",
19922 /* 34 */ "CreateIndex",
19923 /* 35 */ "IsUnique",
19924 /* 36 */ "NotFound",
19925 /* 37 */ "Int64",
19926 /* 38 */ "MustBeInt",
19927 /* 39 */ "Halt",
19928 /* 40 */ "Rowid",
19929 /* 41 */ "IdxLT",
19930 /* 42 */ "AddImm",
19931 /* 43 */ "Statement",
19932 /* 44 */ "RowData",
19933 /* 45 */ "MemMax",
19934 /* 46 */ "NotExists",
19935 /* 47 */ "Gosub",
19936 /* 48 */ "Integer",
19937 /* 49 */ "Prev",
19938 /* 50 */ "RowSetRead",
19939 /* 51 */ "RowSetAdd",
19940 /* 52 */ "VColumn",
19941 /* 53 */ "CreateTable",
19942 /* 54 */ "Last",
19943 /* 55 */ "SeekLe",
19944 /* 56 */ "IncrVacuum",
19945 /* 57 */ "IdxRowid",
19946 /* 58 */ "ResetCount",
19947 /* 59 */ "ContextPush",
19948 /* 60 */ "Or",
19949 /* 61 */ "And",
19950 /* 62 */ "Yield",
19951 /* 63 */ "DropTrigger",
19952 /* 64 */ "DropIndex",
19953 /* 65 */ "IsNull",
19954 /* 66 */ "NotNull",
19955 /* 67 */ "Ne",
19956 /* 68 */ "Eq",
19957 /* 69 */ "Gt",
19958 /* 70 */ "Le",
19959 /* 71 */ "Lt",
19960 /* 72 */ "Ge",
19961 /* 73 */ "IdxGE",
19962 /* 74 */ "BitAnd",
19963 /* 75 */ "BitOr",
19964 /* 76 */ "ShiftLeft",
19965 /* 77 */ "ShiftRight",
19966 /* 78 */ "Add",
19967 /* 79 */ "Subtract",
19968 /* 80 */ "Multiply",
19969 /* 81 */ "Divide",
19970 /* 82 */ "Remainder",
19971 /* 83 */ "Concat",
19972 /* 84 */ "IdxDelete",
19973 /* 85 */ "Vacuum",
19974 /* 86 */ "IfNot",
19975 /* 87 */ "BitNot",
19976 /* 88 */ "String8",
19977 /* 89 */ "DropTable",
19978 /* 90 */ "SeekLt",
19979 /* 91 */ "MakeRecord",
19980 /* 92 */ "ResultRow",
19981 /* 93 */ "Delete",
19982 /* 94 */ "AggFinal",
19983 /* 95 */ "Compare",
19984 /* 96 */ "Goto",
19985 /* 97 */ "TableLock",
19986 /* 98 */ "Clear",
19987 /* 99 */ "VerifyCookie",
19988 /* 100 */ "AggStep",
19989 /* 101 */ "SetNumColumns",
19990 /* 102 */ "Transaction",
19991 /* 103 */ "VFilter",
19992 /* 104 */ "VDestroy",
19993 /* 105 */ "ContextPop",
19994 /* 106 */ "Next",
19995 /* 107 */ "IdxInsert",
19996 /* 108 */ "SeekGe",
19997 /* 109 */ "Insert",
19998 /* 110 */ "Destroy",
19999 /* 111 */ "ReadCookie",
20000 /* 112 */ "LoadAnalysis",
20001 /* 113 */ "Explain",
20002 /* 114 */ "OpenPseudo",
20003 /* 115 */ "OpenEphemeral",
20004 /* 116 */ "Null",
20005 /* 117 */ "Move",
20006 /* 118 */ "Blob",
20007 /* 119 */ "Rewind",
20008 /* 120 */ "SeekGt",
20009 /* 121 */ "VBegin",
20010 /* 122 */ "VUpdate",
20011 /* 123 */ "IfZero",
20012 /* 124 */ "VCreate",
20013 /* 125 */ "Found",
20014 /* 126 */ "Real",
20015 /* 127 */ "IfPos",
20016 /* 128 */ "NullRow",
20017 /* 129 */ "Jump",
20018 /* 130 */ "Permutation",
20019 /* 131 */ "NotUsed_131",
20020 /* 132 */ "NotUsed_132",
20021 /* 133 */ "NotUsed_133",
20022 /* 134 */ "NotUsed_134",
20023 /* 135 */ "NotUsed_135",
20024 /* 136 */ "NotUsed_136",
20025 /* 137 */ "NotUsed_137",
20026 /* 138 */ "NotUsed_138",
20027 /* 139 */ "ToText",
20028 /* 140 */ "ToBlob",
20029 /* 141 */ "ToNumeric",
20030 /* 142 */ "ToInt",
20031 /* 143 */ "ToReal",
 
 
20032 };
20033 return azName[i];
20034 }
20035 #endif
20036
@@ -21440,11 +21525,11 @@
21440 ** * sqlite3_vfs method implementations.
21441 ** * Locking primitives for the proxy uber-locking-method. (MacOSX only)
21442 ** * Definitions of sqlite3_vfs objects for all locking methods
21443 ** plus implementations of sqlite3_os_init() and sqlite3_os_end().
21444 **
21445 ** $Id: os_unix.c,v 1.232 2008/12/11 02:56:07 drh Exp $
21446 */
21447 #if SQLITE_OS_UNIX /* This file is used on unix only */
21448
21449 /*
21450 ** There are various methods for file locking used for concurrency
@@ -21462,11 +21547,11 @@
21462 ** is defined to 1. The SQLITE_ENABLE_LOCKING_STYLE also enables automatic
21463 ** selection of the appropriate locking style based on the filesystem
21464 ** where the database is located.
21465 */
21466 #if !defined(SQLITE_ENABLE_LOCKING_STYLE)
21467 # if defined(__DARWIN__)
21468 # define SQLITE_ENABLE_LOCKING_STYLE 1
21469 # else
21470 # define SQLITE_ENABLE_LOCKING_STYLE 0
21471 # endif
21472 #endif
@@ -23800,11 +23885,11 @@
23800 **
23801 ** Third-party implementations of AFP are available. But this code here
23802 ** only works on OSX.
23803 */
23804
23805 #if defined(__DARWIN__) && SQLITE_ENABLE_LOCKING_STYLE
23806 /*
23807 ** The afpLockingContext structure contains all afp lock specific state
23808 */
23809 typedef struct afpLockingContext afpLockingContext;
23810 struct afpLockingContext {
@@ -24183,11 +24268,11 @@
24183 unixLeaveMutex();
24184 }
24185 return SQLITE_OK;
24186 }
24187
24188 #endif /* defined(__DARWIN__) && SQLITE_ENABLE_LOCKING_STYLE */
24189 /*
24190 ** The code above is the AFP lock implementation. The code is specific
24191 ** to MacOSX and does not work on other unix platforms. No alternative
24192 ** is available. If you don't compile for a mac, then the "unix-afp"
24193 ** VFS is not available.
@@ -24562,11 +24647,11 @@
24562
24563
24564 return SQLITE_OK;
24565 }
24566
24567 #if SQLITE_ENABLE_LOCKING_STYLE && defined(__DARWIN__)
24568 /*
24569 ** Handler for proxy-locking file-control verbs. Defined below in the
24570 ** proxying locking division.
24571 */
24572 static int proxyFileControl(sqlite3_file*,int,void*);
@@ -24584,16 +24669,16 @@
24584 }
24585 case SQLITE_LAST_ERRNO: {
24586 *(int*)pArg = ((unixFile*)id)->lastErrno;
24587 return SQLITE_OK;
24588 }
24589 #if SQLITE_ENABLE_LOCKING_STYLE && defined(__DARWIN__)
24590 case SQLITE_SET_LOCKPROXYFILE:
24591 case SQLITE_GET_LOCKPROXYFILE: {
24592 return proxyFileControl(id,op,pArg);
24593 }
24594 #endif /* SQLITE_ENABLE_LOCKING_STYLE && defined(__DARWIN__) */
24595 }
24596 return SQLITE_ERROR;
24597 }
24598
24599 /*
@@ -24732,11 +24817,11 @@
24732 semUnlock, /* xUnlock method */
24733 semCheckReservedLock /* xCheckReservedLock method */
24734 )
24735 #endif
24736
24737 #if defined(__DARWIN__) && SQLITE_ENABLE_LOCKING_STYLE
24738 IOMETHODS(
24739 afpIoFinder, /* Finder function name */
24740 afpIoMethods, /* sqlite3_io_methods object name */
24741 afpClose, /* xClose method */
24742 afpLock, /* xLock method */
@@ -24752,11 +24837,11 @@
24752 ** secondary files. For this reason, the division that implements
24753 ** proxy locking is located much further down in the file. But we need
24754 ** to go ahead and define the sqlite3_io_methods and finder function
24755 ** for proxy locking here. So we forward declare the I/O methods.
24756 */
24757 #if defined(__DARWIN__) && SQLITE_ENABLE_LOCKING_STYLE
24758 static int proxyClose(sqlite3_file*);
24759 static int proxyLock(sqlite3_file*, int);
24760 static int proxyUnlock(sqlite3_file*, int);
24761 static int proxyCheckReservedLock(sqlite3_file*, int*);
24762 IOMETHODS(
@@ -24768,11 +24853,11 @@
24768 proxyCheckReservedLock /* xCheckReservedLock method */
24769 )
24770 #endif
24771
24772
24773 #if defined(__DARWIN__) && SQLITE_ENABLE_LOCKING_STYLE
24774 /*
24775 ** This "finder" function attempts to determine the best locking strategy
24776 ** for the database file "filePath". It then returns the sqlite3_io_methods
24777 ** object that implements that strategy.
24778 **
@@ -24829,14 +24914,14 @@
24829 return &posixIoMethods;
24830 }else{
24831 return &dotlockIoMethods;
24832 }
24833 }
24834 static const sqlite3_io_methods (*const autolockIoFinder)(const char*,int)
24835 = autolockIoFinderImpl;
24836
24837 #endif /* defined(__DARWIN__) && SQLITE_ENABLE_LOCKING_STYLE */
24838
24839 /*
24840 ** An abstract type for a pointer to a IO method finder function:
24841 */
24842 typedef const sqlite3_io_methods *(*finder_type)(const char*,int);
@@ -24905,11 +24990,11 @@
24905 unixEnterMutex();
24906 rc = findLockInfo(pNew, &pNew->pLock, &pNew->pOpen);
24907 unixLeaveMutex();
24908 }
24909
24910 #if SQLITE_ENABLE_LOCKING_STYLE && defined(__DARWIN__)
24911 else if( pLockingStyle == &afpIoMethods ){
24912 /* AFP locking uses the file path so it needs to be included in
24913 ** the afpLockingContext.
24914 */
24915 afpLockingContext *pCtx;
@@ -25001,11 +25086,11 @@
25001 int ii;
25002 int fd = -1;
25003 char zDirname[MAX_PATHNAME+1];
25004
25005 sqlite3_snprintf(MAX_PATHNAME, zDirname, "%s", zFilename);
25006 for(ii=(int)strlen(zDirname); ii>=0 && zDirname[ii]!='/'; ii--);
25007 if( ii>0 ){
25008 zDirname[ii] = '\0';
25009 fd = open(zDirname, O_RDONLY|O_BINARY, 0);
25010 if( fd>=0 ){
25011 #ifdef FD_CLOEXEC
@@ -25077,11 +25162,11 @@
25077 zBuf[j] = 0;
25078 }while( access(zBuf,0)==0 );
25079 return SQLITE_OK;
25080 }
25081
25082 #if SQLITE_ENABLE_LOCKING_STYLE && defined(__DARWIN__)
25083 /*
25084 ** Routine to transform a unixFile into a proxy-locking unixFile.
25085 ** Implementation in the proxy-lock division, but used by unixOpen()
25086 ** if SQLITE_PREFER_PROXY_LOCKING is defined.
25087 */
@@ -25724,11 +25809,11 @@
25724 */
25725
25726 /*
25727 ** Proxy locking is only available on MacOSX
25728 */
25729 #if defined(__DARWIN__) && SQLITE_ENABLE_LOCKING_STYLE
25730
25731 #ifdef SQLITE_TEST
25732 /* simulate multiple hosts by creating unique hostid file paths */
25733 SQLITE_API int sqlite3_hostid_num = 0;
25734 #endif
@@ -26214,11 +26299,11 @@
26214 **
26215 ** This routine find the filename associated with pFile and writes it
26216 ** int dbPath.
26217 */
26218 static int proxyGetDbPathForUnixFile(unixFile *pFile, char *dbPath){
26219 #if defined(__DARWIN__)
26220 if( pFile->pMethod == &afpIoMethods ){
26221 /* afp style keeps a reference to the db path in the filePath field
26222 ** of the struct */
26223 assert( (int)strlen((char*)pFile->lockingContext)<=MAXPATHLEN );
26224 strcpy(dbPath, ((afpLockingContext *)pFile->lockingContext)->dbPath);
@@ -26483,11 +26568,11 @@
26483 return SQLITE_OK;
26484 }
26485
26486
26487
26488 #endif /* defined(__DARWIN__) && SQLITE_ENABLE_LOCKING_STYLE */
26489 /*
26490 ** The proxy locking style is intended for use with AFP filesystems.
26491 ** And since AFP is only supported on MacOSX, the proxy locking is also
26492 ** restricted to MacOSX.
26493 **
@@ -26556,11 +26641,11 @@
26556 ** Note that the sqlite3_vfs.pNext field of the VFS object is modified
26557 ** by the SQLite core when the VFS is registered. So the following
26558 ** array cannot be const.
26559 */
26560 static sqlite3_vfs aVfs[] = {
26561 #if SQLITE_ENABLE_LOCKING_STYLE && defined(__DARWIN__)
26562 UNIXVFS("unix", autolockIoFinder ),
26563 #else
26564 UNIXVFS("unix", posixIoFinder ),
26565 #endif
26566 UNIXVFS("unix-none", nolockIoFinder ),
@@ -26570,11 +26655,11 @@
26570 #endif
26571 #if SQLITE_ENABLE_LOCKING_STYLE
26572 UNIXVFS("unix-posix", posixIoFinder ),
26573 UNIXVFS("unix-flock", flockIoFinder ),
26574 #endif
26575 #if SQLITE_ENABLE_LOCKING_STYLE && defined(__DARWIN__)
26576 UNIXVFS("unix-afp", afpIoFinder ),
26577 UNIXVFS("unix-proxy", proxyIoFinder ),
26578 #endif
26579 };
26580 unsigned int i; /* Loop counter */
@@ -28592,11 +28677,11 @@
28592 ** sometimes grow into tens of thousands or larger. The size of the
28593 ** Bitvec object is the number of pages in the database file at the
28594 ** start of a transaction, and is thus usually less than a few thousand,
28595 ** but can be as large as 2 billion for a really big database.
28596 **
28597 ** @(#) $Id: bitvec.c,v 1.9 2008/11/19 18:30:35 shane Exp $
28598 */
28599
28600 /* Size of the Bitvec structure in bytes. */
28601 #define BITVEC_SZ 512
28602
@@ -28731,13 +28816,11 @@
28731 i--;
28732 while((p->iSize > BITVEC_NBIT) && p->iDivisor) {
28733 u32 bin = i/p->iDivisor;
28734 i = i%p->iDivisor;
28735 if( p->u.apSub[bin]==0 ){
28736 sqlite3BeginBenignMalloc();
28737 p->u.apSub[bin] = sqlite3BitvecCreate( p->iDivisor );
28738 sqlite3EndBenignMalloc();
28739 if( p->u.apSub[bin]==0 ) return SQLITE_NOMEM;
28740 }
28741 p = p->u.apSub[bin];
28742 }
28743 if( p->iSize<=BITVEC_NBIT ){
@@ -29546,11 +29629,11 @@
29546 ** sqlite3_pcache interface). It also contains part of the implementation
29547 ** of the SQLITE_CONFIG_PAGECACHE and sqlite3_release_memory() features.
29548 ** If the default page cache implementation is overriden, then neither of
29549 ** these two features are available.
29550 **
29551 ** @(#) $Id: pcache1.c,v 1.6 2008/12/10 18:03:46 drh Exp $
29552 */
29553
29554
29555 typedef struct PCache1 PCache1;
29556 typedef struct PgHdr1 PgHdr1;
@@ -29576,10 +29659,12 @@
29576 */
29577 unsigned int nRecyclable; /* Number of pages in the LRU list */
29578 unsigned int nPage; /* Total number of pages in apHash */
29579 unsigned int nHash; /* Number of slots in apHash[] */
29580 PgHdr1 **apHash; /* Hash table for fast lookup by key */
 
 
29581 };
29582
29583 /*
29584 ** Each cache entry is represented by an instance of the following
29585 ** structure. A buffer of PgHdr1.pCache->szPage bytes is allocated
@@ -30086,10 +30171,13 @@
30086 pPage->pCache = pCache;
30087 pCache->apHash[h] = pPage;
30088 }
30089
30090 fetch_out:
 
 
 
30091 if( createFlag==1 ) sqlite3EndBenignMalloc();
30092 pcache1LeaveMutex();
30093 return (pPage ? PGHDR1_TO_PAGE(pPage) : 0);
30094 }
30095
@@ -30160,10 +30248,14 @@
30160
30161 h = iNew%pCache->nHash;
30162 pPage->iKey = iNew;
30163 pPage->pNext = pCache->apHash[h];
30164 pCache->apHash[h] = pPage;
 
 
 
 
30165
30166 pcache1LeaveMutex();
30167 }
30168
30169 /*
@@ -30174,11 +30266,14 @@
30174 ** equal to or greater than iLimit are implicitly unpinned.
30175 */
30176 static void pcache1Truncate(sqlite3_pcache *p, unsigned int iLimit){
30177 PCache1 *pCache = (PCache1 *)p;
30178 pcache1EnterMutex();
30179 pcache1TruncateUnsafe(pCache, iLimit);
 
 
 
30180 pcache1LeaveMutex();
30181 }
30182
30183 /*
30184 ** Implementation of the sqlite3_pcache.xDestroy method.
@@ -30343,29 +30438,27 @@
30343 ** Turn bulk memory into a RowSet object. N bytes of memory
30344 ** are available at pSpace. The db pointer is used as a memory context
30345 ** for any subsequent allocations that need to occur.
30346 ** Return a pointer to the new RowSet object.
30347 **
30348 ** If N is not sufficient memory to make even a minimum RowSet,
30349 ** then return NULL. If N is larger than the minimum, use
30350 ** the surplus as an initial allocation of entries available to
30351 ** be filled.
 
30352 */
30353 SQLITE_PRIVATE RowSet *sqlite3RowSetInit(sqlite3 *db, void *pSpace, unsigned int N){
30354 RowSet *p;
30355 if( N<sizeof(*p) ){
30356 p = 0;
30357 }else{
30358 p = pSpace;
30359 p->pChunk = 0;
30360 p->db = db;
30361 p->pEntry = 0;
30362 p->pLast = 0;
30363 p->pFresh = (struct RowSetEntry*)&p[1];
30364 p->nFresh = (u16)((N - sizeof(*p))/sizeof(struct RowSetEntry));
30365 p->isSorted = 1;
30366 }
30367 return p;
30368 }
30369
30370 /*
30371 ** Deallocate all chunks from a RowSet.
@@ -30529,34 +30622,27 @@
30529 ** is separate from the database file. The pager also implements file
30530 ** locking to prevent two processes from writing the same database
30531 ** file simultaneously, or one process from reading the database while
30532 ** another is writing.
30533 **
30534 ** @(#) $Id: pager.c,v 1.514 2008/12/10 22:15:00 drh Exp $
30535 */
30536 #ifndef SQLITE_OMIT_DISKIO
30537
30538 /*
30539 ** Macros for troubleshooting. Normally turned off
30540 */
30541 #if 0
 
30542 #define sqlite3DebugPrintf printf
30543 #define PAGERTRACE1(X) sqlite3DebugPrintf(X)
30544 #define PAGERTRACE2(X,Y) sqlite3DebugPrintf(X,Y)
30545 #define PAGERTRACE3(X,Y,Z) sqlite3DebugPrintf(X,Y,Z)
30546 #define PAGERTRACE4(X,Y,Z,W) sqlite3DebugPrintf(X,Y,Z,W)
30547 #define PAGERTRACE5(X,Y,Z,W,V) sqlite3DebugPrintf(X,Y,Z,W,V)
30548 #else
30549 #define PAGERTRACE1(X)
30550 #define PAGERTRACE2(X,Y)
30551 #define PAGERTRACE3(X,Y,Z)
30552 #define PAGERTRACE4(X,Y,Z,W)
30553 #define PAGERTRACE5(X,Y,Z,W,V)
30554 #endif
30555
30556 /*
30557 ** The following two macros are used within the PAGERTRACEX() macros above
30558 ** to print out file-descriptors.
30559 **
30560 ** PAGERID() takes a pointer to a Pager struct as its argument. The
30561 ** associated file-descriptor is returned. FILEHANDLEID() takes an sqlite3_file
30562 ** struct as its argument.
@@ -30616,27 +30702,10 @@
30616 #define PAGER_SHARED 1 /* same as SHARED_LOCK */
30617 #define PAGER_RESERVED 2 /* same as RESERVED_LOCK */
30618 #define PAGER_EXCLUSIVE 4 /* same as EXCLUSIVE_LOCK */
30619 #define PAGER_SYNCED 5
30620
30621 /*
30622 ** If the SQLITE_BUSY_RESERVED_LOCK macro is set to true at compile-time,
30623 ** then failed attempts to get a reserved lock will invoke the busy callback.
30624 ** This is off by default. To see why, consider the following scenario:
30625 **
30626 ** Suppose thread A already has a shared lock and wants a reserved lock.
30627 ** Thread B already has a reserved lock and wants an exclusive lock. If
30628 ** both threads are using their busy callbacks, it might be a long time
30629 ** be for one of the threads give up and allows the other to proceed.
30630 ** But if the thread trying to get the reserved lock gives up quickly
30631 ** (if it never invokes its busy callback) then the contention will be
30632 ** resolved quickly.
30633 */
30634 #ifndef SQLITE_BUSY_RESERVED_LOCK
30635 # define SQLITE_BUSY_RESERVED_LOCK 0
30636 #endif
30637
30638 /*
30639 ** This macro rounds values up so that if the value is an address it
30640 ** is guaranteed to be an address that is aligned to an 8-byte boundary.
30641 */
30642 #define FORCE_ALIGNMENT(X) (((X)+7)&~7)
@@ -30650,10 +30719,32 @@
30650 #else
30651 # define CODEC1(P,D,N,X) /* NO-OP */
30652 # define CODEC2(P,D,N,X) ((char*)D)
30653 #endif
30654
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
30655 /*
30656 ** A open page cache is an instance of the following structure.
30657 **
30658 ** Pager.errCode may be set to SQLITE_IOERR, SQLITE_CORRUPT, or
30659 ** or SQLITE_FULL. Once one of the first three errors occurs, it persists
@@ -30660,20 +30751,29 @@
30660 ** and is returned as the result of every major pager API call. The
30661 ** SQLITE_FULL return code is slightly different. It persists only until the
30662 ** next successful rollback is performed on the pager cache. Also,
30663 ** SQLITE_FULL does not affect the sqlite3PagerGet() and sqlite3PagerLookup()
30664 ** APIs, they may still be used successfully.
 
 
 
 
 
 
 
 
 
 
 
 
30665 */
30666 struct Pager {
30667 sqlite3_vfs *pVfs; /* OS functions to use for IO */
30668 u8 journalOpen; /* True if journal file descriptors is valid */
30669 u8 journalStarted; /* True if header of journal is synced */
30670 u8 useJournal; /* Use a rollback journal on this file */
30671 u8 noReadlock; /* Do not bother to obtain readlocks */
30672 u8 stmtOpen; /* True if the statement subjournal is open */
30673 u8 stmtInUse; /* True we are in a statement subtransaction */
30674 u8 stmtAutoopen; /* Open stmt journal when main journal is opened*/
30675 u8 noSync; /* Do not sync the journal if true */
30676 u8 fullSync; /* Do extra syncs of the journal for robustness */
30677 u8 sync_flags; /* One of SYNC_NORMAL or SYNC_FULL */
30678 u8 state; /* PAGER_UNLOCK, _SHARED, _RESERVED, etc. */
30679 u8 tempFile; /* zFilename is a temporary file */
@@ -30687,38 +30787,34 @@
30687 u8 exclusiveMode; /* Boolean. True if locking_mode==EXCLUSIVE */
30688 u8 journalMode; /* On of the PAGER_JOURNALMODE_* values */
30689 u8 dbModified; /* True if there are any changes to the Db */
30690 u8 changeCountDone; /* Set after incrementing the change-counter */
30691 u8 dbSizeValid; /* Set when dbSize is correct */
 
 
 
30692 u32 vfsFlags; /* Flags for sqlite3_vfs.xOpen() */
30693 int errCode; /* One of several kinds of errors */
30694 Pgno dbSize; /* Number of pages in the file */
30695 Pgno origDbSize; /* dbSize before the current change */
30696 Pgno stmtSize; /* Size of database (in pages) at stmt_begin() */
30697 int nRec; /* Number of pages written to the journal */
30698 u32 cksumInit; /* Quasi-random value added to every checksum */
30699 int stmtNRec; /* Number of records in stmt subjournal */
30700 int nExtra; /* Add this many bytes to each in-memory page */
30701 int pageSize; /* Number of bytes in a page */
30702 int nPage; /* Total number of in-memory pages */
30703 int mxPage; /* Maximum number of pages to hold in cache */
30704 Pgno mxPgno; /* Maximum allowed size of the database */
30705 Bitvec *pInJournal; /* One bit for each page in the database file */
30706 Bitvec *pInStmt; /* One bit for each page in the database */
30707 Bitvec *pAlwaysRollback; /* One bit for each page marked always-rollback */
30708 char *zFilename; /* Name of the database file */
30709 char *zJournal; /* Name of the journal file */
30710 char *zDirectory; /* Directory hold database and journal files */
30711 sqlite3_file *fd, *jfd; /* File descriptors for database and journal */
30712 sqlite3_file *stfd; /* File descriptor for the statement subjournal*/
30713 int (*xBusyHandler)(void*); /* Function to call when busy */
30714 void *pBusyHandlerArg; /* Context argument for xBusyHandler */
30715 i64 journalOff; /* Current byte offset in the journal file */
30716 i64 journalHdr; /* Byte offset to previous journal header */
30717 i64 stmtHdrOff; /* First journal header written this statement */
30718 i64 stmtCksum; /* cksumInit when statement was started */
30719 i64 stmtJSize; /* Size of journal at stmt_begin() */
30720 u32 sectorSize; /* Assumed sector size during rollback */
30721 #ifdef SQLITE_TEST
30722 int nHit, nMiss; /* Cache hits and missing */
30723 int nRead, nWrite; /* Database pages read/written */
30724 #endif
@@ -30729,10 +30825,12 @@
30729 #endif
30730 char *pTmpSpace; /* Pager.pageSize bytes of space for tmp use */
30731 char dbFileVers[16]; /* Changes whenever database file changes */
30732 i64 journalSizeLimit; /* Size limit for persistent journal files */
30733 PCache *pPCache; /* Pointer to page cache object */
 
 
30734 };
30735
30736 /*
30737 ** The following global variables hold counters used for
30738 ** testing purposes only. These variables do not exist in
@@ -30752,11 +30850,11 @@
30752 /*
30753 ** Journal files begin with the following magic string. The data
30754 ** was obtained from /dev/random. It is used only as a sanity check.
30755 **
30756 ** Since version 2.8.0, the journal format contains additional sanity
30757 ** checking information. If the power fails while the journal is begin
30758 ** written, semi-random garbage data might appear in the journal
30759 ** file after power is restored. If an attempt is then made
30760 ** to roll the journal back, the database could be corrupted. The additional
30761 ** sanity checking data is an attempt to discover the garbage in the
30762 ** journal and ignore it.
@@ -30815,19 +30913,34 @@
30815 ** The maximum legal page number is (2^31 - 1).
30816 */
30817 #define PAGER_MAX_PGNO 2147483647
30818
30819 /*
30820 ** Return true if page *pPg has already been written to the statement
30821 ** journal (or statement snapshot has been created, if *pPg is part
30822 ** of an in-memory database).
 
 
 
 
30823 */
30824 static int pageInStatement(PgHdr *pPg){
 
30825 Pager *pPager = pPg->pPager;
30826 return sqlite3BitvecTest(pPager->pInStmt, pPg->pgno);
 
 
 
 
 
 
 
30827 }
30828
 
 
 
30829 static int pageInJournal(PgHdr *pPg){
30830 return sqlite3BitvecTest(pPg->pPager->pInJournal, pPg->pgno);
30831 }
30832
30833 /*
@@ -31070,20 +31183,23 @@
31070 ** 512 512
31071 ** 100 512
31072 ** 2000 2048
31073 **
31074 */
31075 static void seekJournalHdr(Pager *pPager){
31076 i64 offset = 0;
31077 i64 c = pPager->journalOff;
31078 if( c ){
31079 offset = ((c-1)/JOURNAL_HDR_SZ(pPager) + 1) * JOURNAL_HDR_SZ(pPager);
31080 }
31081 assert( offset%JOURNAL_HDR_SZ(pPager)==0 );
31082 assert( offset>=c );
31083 assert( (offset-c)<JOURNAL_HDR_SZ(pPager) );
31084 pPager->journalOff = offset;
 
 
 
31085 }
31086
31087 /*
31088 ** Write zeros over the header of the journal file. This has the
31089 ** effect of invalidating the journal file and committing the
@@ -31141,17 +31257,24 @@
31141 static int writeJournalHdr(Pager *pPager){
31142 int rc = SQLITE_OK;
31143 char *zHeader = pPager->pTmpSpace;
31144 u32 nHeader = pPager->pageSize;
31145 u32 nWrite;
 
31146
31147 if( nHeader>JOURNAL_HDR_SZ(pPager) ){
31148 nHeader = JOURNAL_HDR_SZ(pPager);
31149 }
31150
31151 if( pPager->stmtHdrOff==0 ){
31152 pPager->stmtHdrOff = pPager->journalOff;
 
 
 
 
 
 
31153 }
31154
31155 seekJournalHdr(pPager);
31156 pPager->journalHdr = pPager->journalOff;
31157
@@ -31188,11 +31311,11 @@
31188
31189 /* The random check-hash initialiser */
31190 sqlite3_randomness(sizeof(pPager->cksumInit), &pPager->cksumInit);
31191 put32bits(&zHeader[sizeof(aJournalMagic)+4], pPager->cksumInit);
31192 /* The initial database size */
31193 put32bits(&zHeader[sizeof(aJournalMagic)+8], pPager->dbSize);
31194 /* The assumed sector size for this process */
31195 put32bits(&zHeader[sizeof(aJournalMagic)+12], pPager->sectorSize);
31196
31197 /* Initializing the tail of the buffer is not necessary. Everything
31198 ** works find if the following memset() is omitted. But initializing
@@ -31217,21 +31340,22 @@
31217 }
31218
31219 /*
31220 ** The journal file must be open when this is called. A journal header file
31221 ** (JOURNAL_HDR_SZ bytes) is read from the current location in the journal
31222 ** file. See comments above function writeJournalHdr() for a description of
31223 ** the journal header format.
 
31224 **
31225 ** If the header is read successfully, *nRec is set to the number of
31226 ** page records following this header and *dbSize is set to the size of the
31227 ** database before the transaction began, in pages. Also, pPager->cksumInit
31228 ** is set to the value read from the journal header. SQLITE_OK is returned
31229 ** in this case.
31230 **
31231 ** If the journal header file appears to be corrupted, SQLITE_DONE is
31232 ** returned and *nRec and *dbSize are not set. If JOURNAL_HDR_SZ bytes
31233 ** cannot be read from the journal file an error code is returned.
31234 */
31235 static int readJournalHdr(
31236 Pager *pPager,
31237 i64 journalSize,
@@ -31394,10 +31518,47 @@
31394 */
31395 static void pager_reset(Pager *pPager){
31396 if( pPager->errCode ) return;
31397 sqlite3PcacheClear(pPager->pPCache);
31398 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
31399
31400 /*
31401 ** Unlock the database file.
31402 **
31403 ** If the pager is currently in error state, discard the contents of
@@ -31431,21 +31592,14 @@
31431 ** cache can be discarded and the error code safely cleared.
31432 */
31433 if( pPager->errCode ){
31434 if( rc==SQLITE_OK ) pPager->errCode = SQLITE_OK;
31435 pager_reset(pPager);
31436 if( pPager->stmtOpen ){
31437 sqlite3OsClose(pPager->stfd);
31438 sqlite3BitvecDestroy(pPager->pInStmt);
31439 pPager->pInStmt = 0;
31440 }
31441 pPager->stmtOpen = 0;
31442 pPager->stmtInUse = 0;
31443 pPager->journalOff = 0;
31444 pPager->journalStarted = 0;
31445 pPager->stmtAutoopen = 0;
31446 pPager->origDbSize = 0;
31447 }
31448
31449 pPager->state = PAGER_UNLOCK;
31450 pPager->changeCountDone = 0;
31451 }
@@ -31486,15 +31640,11 @@
31486 int rc = SQLITE_OK;
31487 int rc2 = SQLITE_OK;
31488 if( pPager->state<PAGER_RESERVED ){
31489 return SQLITE_OK;
31490 }
31491 sqlite3PagerStmtCommit(pPager);
31492 if( pPager->stmtOpen && !pPager->exclusiveMode ){
31493 sqlite3OsClose(pPager->stfd);
31494 pPager->stmtOpen = 0;
31495 }
31496 if( pPager->journalOpen ){
31497 if( pPager->journalMode==PAGER_JOURNALMODE_MEMORY ){
31498 int isMemoryJournal = sqlite3IsMemJournal(pPager->jfd);
31499 sqlite3OsClose(pPager->jfd);
31500 pPager->journalOpen = 0;
@@ -31538,14 +31688,15 @@
31538 rc2 = osUnlock(pPager->fd, SHARED_LOCK);
31539 pPager->state = PAGER_SHARED;
31540 }else if( pPager->state==PAGER_SYNCED ){
31541 pPager->state = PAGER_EXCLUSIVE;
31542 }
31543 pPager->origDbSize = 0;
31544 pPager->setMaster = 0;
31545 pPager->needSync = 0;
31546 /* lruListSetFirstSynced(pPager); */
 
31547 if( !MEMDB ){
31548 pPager->dbSizeValid = 0;
31549 }
31550 pPager->dbModified = 0;
31551
@@ -31581,59 +31732,75 @@
31581 }
31582 return cksum;
31583 }
31584
31585 /*
31586 ** Read a single page from the journal file opened on file descriptor
31587 ** jfd. Playback this one page.
 
 
31588 **
31589 ** The isMainJrnl flag is true if this is the main rollback journal and
31590 ** false for the statement journal. The main rollback journal uses
31591 ** checksums - the statement journal does not.
 
 
 
 
 
 
31592 */
31593 static int pager_playback_one_page(
31594 Pager *pPager, /* The pager being played back */
31595 sqlite3_file *jfd, /* The file that is the journal being rolled back */
31596 i64 offset, /* Offset of the page within the journal */
31597 int isMainJrnl /* True for main rollback journal. False for Stmt jrnl */
 
31598 ){
31599 int rc;
31600 PgHdr *pPg; /* An existing page in the cache */
31601 Pgno pgno; /* The page number of a page in journal */
31602 u32 cksum; /* Checksum used for sanity checking */
31603 u8 *aData = (u8 *)pPager->pTmpSpace; /* Temp storage for a page */
31604
31605 /* isMainJrnl should be true for the main journal and false for
31606 ** statement journals. Verify that this is always the case
31607 */
31608 assert( jfd == (isMainJrnl ? pPager->jfd : pPager->stfd) );
31609 assert( aData );
31610
31611 rc = read32bits(jfd, offset, &pgno);
31612 if( rc!=SQLITE_OK ) return rc;
31613 rc = sqlite3OsRead(jfd, aData, pPager->pageSize, offset+4);
31614 if( rc!=SQLITE_OK ) return rc;
31615 pPager->journalOff += pPager->pageSize + 4;
 
 
 
 
 
31616
31617 /* Sanity checking on the page. This is more important that I originally
31618 ** thought. If a power failure occurs while the journal is being written,
31619 ** it could cause invalid data to be written into the journal. We need to
31620 ** detect this invalid data (with high probability) and ignore it.
31621 */
31622 if( pgno==0 || pgno==PAGER_MJ_PGNO(pPager) ){
31623 return SQLITE_DONE;
31624 }
31625 if( pgno>(unsigned)pPager->dbSize ){
31626 return SQLITE_OK;
31627 }
31628 if( isMainJrnl ){
31629 rc = read32bits(jfd, offset+pPager->pageSize+4, &cksum);
31630 if( rc ) return rc;
31631 pPager->journalOff += 4;
31632 if( pager_cksum(pPager, aData)!=cksum ){
31633 return SQLITE_DONE;
31634 }
 
 
 
31635 }
31636
31637 assert( pPager->state==PAGER_RESERVED || pPager->state>=PAGER_EXCLUSIVE );
31638
31639 /* If the pager is in RESERVED state, then there must be a copy of this
@@ -31667,18 +31834,46 @@
31667 ** 2008-04-14: When attempting to vacuum a corrupt database file, it
31668 ** is possible to fail a statement on a database that does not yet exist.
31669 ** Do not attempt to write if database file has never been opened.
31670 */
31671 pPg = pager_lookup(pPager, pgno);
31672 PAGERTRACE4("PLAYBACK %d page %d hash(%08x)\n",
31673 PAGERID(pPager), pgno, pager_datahash(pPager->pageSize, aData));
 
 
31674 if( (pPager->state>=PAGER_EXCLUSIVE)
31675 && (pPg==0 || 0==(pPg->flags&PGHDR_NEED_SYNC))
31676 && (pPager->fd->pMethods)
31677 ){
31678 i64 ofst = (pgno-1)*(i64)pPager->pageSize;
31679 rc = sqlite3OsWrite(pPager->fd, aData, pPager->pageSize, ofst);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
31680 }
31681 if( pPg ){
31682 /* No page should ever be explicitly rolled back that is in use, except
31683 ** for page 1 which is held in use in order to keep the lock on the
31684 ** database active. However such a page may be rolled back as a result
@@ -31689,11 +31884,29 @@
31689 pData = pPg->pData;
31690 memcpy(pData, aData, pPager->pageSize);
31691 if( pPager->xReiniter ){
31692 pPager->xReiniter(pPg);
31693 }
31694 if( isMainJrnl ){
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
31695 sqlite3PcacheMakeClean(pPg);
31696 }
31697 #ifdef SQLITE_CHECK_PAGES
31698 pPg->pageHash = pager_pagehash(pPg);
31699 #endif
@@ -31708,10 +31921,50 @@
31708 sqlite3PcacheRelease(pPg);
31709 }
31710 return rc;
31711 }
31712
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
31713 /*
31714 ** Parameter zMaster is the name of a master journal file. A single journal
31715 ** file that referred to the master journal file has just been rolled back.
31716 ** This routine checks if it is possible to delete the master journal file,
31717 ** and does so if it is.
@@ -31815,17 +32068,16 @@
31815 sqlite3_free(pMaster);
31816 return rc;
31817 }
31818
31819
31820 static void pager_truncate_cache(Pager *pPager);
31821
31822 /*
31823 ** Truncate the main file of the given pager to the number of pages
31824 ** indicated. Also truncate the cached representation of the file.
 
31825 **
31826 ** Might might be the case that the file on disk is smaller than nPage.
31827 ** This can happen, for example, if we are in the middle of a transaction
31828 ** which has extended the file size and the new pages are still all held
31829 ** in cache, then an INSERT or UPDATE does a statement rollback. Some
31830 ** operating system implementations can get confused if you try to
31831 ** truncate a file to some size that is larger than it currently is,
@@ -31842,16 +32094,15 @@
31842 if( currentSize>newSize ){
31843 rc = sqlite3OsTruncate(pPager->fd, newSize);
31844 }else{
31845 rc = sqlite3OsWrite(pPager->fd, "", 1, newSize-1);
31846 }
 
 
 
31847 }
31848 }
31849 if( rc==SQLITE_OK ){
31850 pPager->dbSize = nPage;
31851 pager_truncate_cache(pPager);
31852 }
31853 return rc;
31854 }
31855
31856 /*
31857 ** Set the sectorSize for the given pager.
@@ -31996,11 +32247,22 @@
31996 ** that this part of the journal was being filled but has not yet been
31997 ** synced to disk. Compute the number of pages based on the remaining
31998 ** size of the file.
31999 **
32000 ** The third term of the test was added to fix ticket #2565.
 
 
 
 
 
 
32001 */
 
 
 
 
 
32002 if( nRec==0 && !isHot &&
32003 pPager->journalHdr+JOURNAL_HDR_SZ(pPager)==pPager->journalOff ){
32004 nRec = (int)((szJ - pPager->journalOff) / JOURNAL_PG_SZ(pPager));
32005 }
32006
@@ -32010,16 +32272,17 @@
32010 if( pPager->journalOff==JOURNAL_HDR_SZ(pPager) ){
32011 rc = pager_truncate(pPager, mxPg);
32012 if( rc!=SQLITE_OK ){
32013 goto end_playback;
32014 }
 
32015 }
32016
32017 /* Copy original pages out of the journal and back into the database file.
32018 */
32019 for(u=0; u<nRec; u++){
32020 rc = pager_playback_one_page(pPager, pPager->jfd, pPager->journalOff, 1);
32021 if( rc!=SQLITE_OK ){
32022 if( rc==SQLITE_DONE ){
32023 rc = SQLITE_OK;
32024 pPager->journalOff = szJ;
32025 break;
@@ -32059,105 +32322,111 @@
32059 setSectorSize(pPager);
32060 return rc;
32061 }
32062
32063 /*
32064 ** Playback the statement journal.
32065 **
32066 ** This is similar to playing back the transaction journal but with
32067 ** a few extra twists.
32068 **
32069 ** (1) The number of pages in the database file at the start of
32070 ** the statement is stored in pPager->stmtSize, not in the
32071 ** journal file itself.
32072 **
32073 ** (2) In addition to playing back the statement journal, also
32074 ** playback all pages of the transaction journal beginning
32075 ** at offset pPager->stmtJSize.
32076 */
32077 static int pager_stmt_playback(Pager *pPager){
32078 i64 szJ; /* Size of the full journal */
32079 i64 hdrOff;
32080 int nRec; /* Number of Records */
32081 int i; /* Loop counter */
32082 int rc;
32083
32084 szJ = pPager->journalOff;
32085
32086 /* Set hdrOff to be the offset just after the end of the last journal
32087 ** page written before the first journal-header for this statement
32088 ** transaction was written, or the end of the file if no journal
32089 ** header was written.
32090 */
32091 hdrOff = pPager->stmtHdrOff;
32092 assert( pPager->fullSync || !hdrOff );
32093 if( !hdrOff ){
32094 hdrOff = szJ;
32095 }
32096
32097 /* Truncate the database back to its original size.
32098 */
32099 rc = pager_truncate(pPager, pPager->stmtSize);
32100 assert( pPager->state>=PAGER_SHARED );
32101
32102 /* Figure out how many records are in the statement journal.
32103 */
32104 assert( pPager->stmtInUse && pPager->journalOpen );
32105 nRec = pPager->stmtNRec;
32106
32107 /* Copy original pages out of the statement journal and back into the
32108 ** database file. Note that the statement journal omits checksums from
32109 ** each record since power-failure recovery is not important to statement
32110 ** journals.
32111 */
32112 for(i=0; i<nRec; i++){
32113 i64 offset = i*(4+pPager->pageSize);
32114 rc = pager_playback_one_page(pPager, pPager->stfd, offset, 0);
32115 assert( rc!=SQLITE_DONE );
32116 if( rc!=SQLITE_OK ) goto end_stmt_playback;
32117 }
32118
32119 /* Now roll some pages back from the transaction journal. Pager.stmtJSize
32120 ** was the size of the journal file when this statement was started, so
32121 ** everything after that needs to be rolled back, either into the
32122 ** database, the memory cache, or both.
32123 **
32124 ** If it is not zero, then Pager.stmtHdrOff is the offset to the start
32125 ** of the first journal header written during this statement transaction.
32126 */
32127 pPager->journalOff = pPager->stmtJSize;
32128 pPager->cksumInit = (int)(pPager->stmtCksum & 0xffffffff);
32129 while( pPager->journalOff < hdrOff ){
32130 rc = pager_playback_one_page(pPager, pPager->jfd, pPager->journalOff, 1);
32131 assert( rc!=SQLITE_DONE );
32132 if( rc!=SQLITE_OK ) goto end_stmt_playback;
32133 }
32134
32135 while( pPager->journalOff < szJ ){
32136 u32 nJRec; /* Number of Journal Records */
32137 u32 dummy;
32138 rc = readJournalHdr(pPager, szJ, &nJRec, &dummy);
32139 if( rc!=SQLITE_OK ){
32140 assert( rc!=SQLITE_DONE );
32141 goto end_stmt_playback;
32142 }
32143 if( nJRec==0 ){
32144 nJRec = (int)((szJ - pPager->journalOff) / (pPager->pageSize+8));
32145 }
32146 for(i=nJRec-1; i>=0 && pPager->journalOff < szJ; i--){
32147 rc = pager_playback_one_page(pPager, pPager->jfd, pPager->journalOff, 1);
32148 assert( rc!=SQLITE_DONE );
32149 if( rc!=SQLITE_OK ) goto end_stmt_playback;
32150 }
32151 }
32152
32153 pPager->journalOff = szJ;
32154
32155 end_stmt_playback:
32156 if( rc==SQLITE_OK) {
32157 pPager->journalOff = szJ;
32158 /* pager_reload_cache(pPager); */
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
32159 }
32160 return rc;
32161 }
32162
32163 /*
@@ -32325,11 +32594,11 @@
32325 }
32326 pPager->pPCache = (PCache *)&pPager[1];
32327 pPtr = ((u8 *)&pPager[1]) + pcacheSize;
32328 pPager->vfsFlags = vfsFlags;
32329 pPager->fd = (sqlite3_file*)&pPtr[pVfs->szOsFile*0];
32330 pPager->stfd = (sqlite3_file*)&pPtr[pVfs->szOsFile];
32331 pPager->jfd = (sqlite3_file*)&pPtr[pVfs->szOsFile+journalFileSize];
32332 pPager->zFilename = (char*)&pPtr[pVfs->szOsFile+2*journalFileSize];
32333 pPager->zDirectory = &pPager->zFilename[nPathname+1];
32334 pPager->zJournal = &pPager->zDirectory[nPathname+1];
32335 pPager->pVfs = pVfs;
@@ -32408,11 +32677,11 @@
32408 }
32409 nExtra = FORCE_ALIGNMENT(nExtra);
32410 sqlite3PcacheOpen(szPageDflt, nExtra, !memDb,
32411 !memDb?pagerStress:0, (void *)pPager, pPager->pPCache);
32412
32413 PAGERTRACE3("OPEN %d %s\n", FILEHANDLEID(pPager->fd), pPager->zFilename);
32414 IOTRACE(("OPEN %p %s\n", pPager, pPager->zFilename))
32415
32416 /* Fill in Pager.zDirectory[] */
32417 memcpy(pPager->zDirectory, pPager->zFilename, nPathname+1);
32418 for(i=sqlite3Strlen30(pPager->zDirectory);
@@ -32630,11 +32899,12 @@
32630 n = 1;
32631 }else{
32632 n /= pPager->pageSize;
32633 }
32634 if( pPager->state!=PAGER_UNLOCK ){
32635 pPager->dbSize = (int)n;
 
32636 pPager->dbSizeValid = 1;
32637 }
32638 }
32639 if( n==(PENDING_BYTE/pPager->pageSize) ){
32640 n++;
@@ -32651,26 +32921,10 @@
32651 /*
32652 ** Forward declaration
32653 */
32654 static int syncJournal(Pager*);
32655
32656 /*
32657 ** This routine is used to truncate the cache when a database
32658 ** is truncated. Drop from the cache all pages whose pgno is
32659 ** larger than pPager->dbSize and is unreferenced.
32660 **
32661 ** Referenced pages larger than pPager->dbSize are zeroed.
32662 **
32663 ** Actually, at the point this routine is called, it would be
32664 ** an error to have a referenced page. But rather than delete
32665 ** that page and guarantee a subsequent segfault, it seems better
32666 ** to zero it and hope that we error out sanely.
32667 */
32668 static void pager_truncate_cache(Pager *pPager){
32669 sqlite3PcacheTruncate(pPager->pPCache, pPager->dbSize);
32670 }
32671
32672 /*
32673 ** Try to obtain a lock on a file. Invoke the busy callback if the lock
32674 ** is currently not available. Repeat until the busy callback returns
32675 ** false or until the lock succeeds.
32676 **
@@ -32700,33 +32954,38 @@
32700 }
32701 }
32702 return rc;
32703 }
32704
 
32705 /*
32706 ** Truncate the file to the number of pages specified.
 
 
 
32707 */
32708 SQLITE_PRIVATE int sqlite3PagerTruncate(Pager *pPager, Pgno nPage){
32709 int rc = SQLITE_OK;
32710 assert( pPager->state>=PAGER_SHARED );
32711
32712 sqlite3PagerPagecount(pPager, 0);
32713 if( pPager->errCode ){
32714 rc = pPager->errCode;
32715 }else if( nPage<pPager->dbSize ){
32716 rc = syncJournal(pPager);
32717 if( rc==SQLITE_OK ){
32718 /* Get an exclusive lock on the database before truncating. */
32719 rc = pager_wait_on_lock(pPager, EXCLUSIVE_LOCK);
32720 }
32721 if( rc==SQLITE_OK ){
32722 rc = pager_truncate(pPager, nPage);
32723 }
32724 }
32725
32726 return rc;
32727 }
 
32728
32729 /*
32730 ** Shutdown the page cache. Free all memory and close all files.
32731 **
32732 ** If a transaction was in progress when this routine is called, that
@@ -32746,24 +33005,29 @@
32746 sqlite3BeginBenignMalloc();
32747 pPager->errCode = 0;
32748 pPager->exclusiveMode = 0;
32749 pager_reset(pPager);
32750 if( !MEMDB ){
 
 
 
 
 
 
 
32751 pagerUnlockAndRollback(pPager);
32752 }
32753 enable_simulated_io_errors();
32754 sqlite3EndBenignMalloc();
32755 PAGERTRACE2("CLOSE %d\n", PAGERID(pPager));
32756 IOTRACE(("CLOSE %p\n", pPager))
32757 if( pPager->journalOpen ){
32758 sqlite3OsClose(pPager->jfd);
32759 }
32760 sqlite3BitvecDestroy(pPager->pInJournal);
32761 sqlite3BitvecDestroy(pPager->pAlwaysRollback);
32762 if( pPager->stmtOpen ){
32763 sqlite3OsClose(pPager->stfd);
32764 }
32765 sqlite3OsClose(pPager->fd);
32766 /* Temp files are automatically deleted by the OS
32767 ** if( pPager->tempFile ){
32768 ** sqlite3OsDelete(pPager->zFilename);
32769 ** }
@@ -32829,10 +33093,39 @@
32829 if( pPager->journalMode!=PAGER_JOURNALMODE_MEMORY ){
32830 int iDc = sqlite3OsDeviceCharacteristics(pPager->fd);
32831 assert( pPager->journalOpen );
32832
32833 if( 0==(iDc&SQLITE_IOCAP_SAFE_APPEND) ){
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
32834 /* Write the nRec value into the journal file header. If in
32835 ** full-synchronous mode, sync the journal first. This ensures that
32836 ** all data has really hit the disk before nRec is updated to mark
32837 ** it as a candidate for rollback.
32838 **
@@ -32840,13 +33133,12 @@
32840 ** SAFE_APPEND property. Because in this case it is not possible
32841 ** for garbage data to be appended to the file, the nRec field
32842 ** is populated with 0xFFFFFFFF when the journal header is written
32843 ** and never needs to be updated.
32844 */
32845 i64 jrnlOff;
32846 if( pPager->fullSync && 0==(iDc&SQLITE_IOCAP_SEQUENTIAL) ){
32847 PAGERTRACE2("SYNC journal of %d\n", PAGERID(pPager));
32848 IOTRACE(("JSYNC %p\n", pPager))
32849 rc = sqlite3OsSync(pPager->jfd, pPager->sync_flags);
32850 if( rc!=0 ) return rc;
32851 }
32852
@@ -32854,11 +33146,11 @@
32854 IOTRACE(("JHDR %p %lld %d\n", pPager, jrnlOff, 4));
32855 rc = write32bits(pPager->jfd, jrnlOff, pPager->nRec);
32856 if( rc ) return rc;
32857 }
32858 if( 0==(iDc&SQLITE_IOCAP_SEQUENTIAL) ){
32859 PAGERTRACE2("SYNC journal of %d\n", PAGERID(pPager));
32860 IOTRACE(("JSYNC %p\n", pPager))
32861 rc = sqlite3OsSync(pPager->jfd, pPager->sync_flags|
32862 (pPager->sync_flags==SQLITE_SYNC_FULL?SQLITE_SYNC_DATAONLY:0)
32863 );
32864 if( rc!=0 ) return rc;
@@ -32918,30 +33210,34 @@
32918 rc = sqlite3PagerOpentemp(pPager, pPager->fd, pPager->vfsFlags);
32919 if( rc ) return rc;
32920 }
32921
32922 /* If there are dirty pages in the page cache with page numbers greater
32923 ** than Pager.dbSize, this means sqlite3PagerTruncate() was called to
32924 ** make the file smaller (presumably by auto-vacuum code). Do not write
32925 ** any such pages to the file.
32926 */
32927 if( pList->pgno<=pPager->dbSize && 0==(pList->flags&PGHDR_DONT_WRITE) ){
32928 i64 offset = (pList->pgno-1)*(i64)pPager->pageSize;
32929 char *pData = CODEC2(pPager, pList->pData, pList->pgno, 6);
32930 PAGERTRACE4("STORE %d page %d hash(%08x)\n",
32931 PAGERID(pPager), pList->pgno, pager_pagehash(pList));
 
32932 IOTRACE(("PGOUT %p %d\n", pPager, pList->pgno));
32933 rc = sqlite3OsWrite(pPager->fd, pData, pPager->pageSize, offset);
32934 PAGER_INCR(sqlite3_pager_writedb_count);
32935 PAGER_INCR(pPager->nWrite);
32936 if( pList->pgno==1 ){
32937 memcpy(&pPager->dbFileVers, &pData[24], sizeof(pPager->dbFileVers));
32938 }
 
 
 
32939 }
32940 #ifndef NDEBUG
32941 else{
32942 PAGERTRACE3("NOSTORE %d page %d\n", PAGERID(pPager), pList->pgno);
32943 }
32944 #endif
32945 if( rc ) return rc;
32946 #ifdef SQLITE_CHECK_PAGES
32947 pList->pageHash = pager_pagehash(pList);
@@ -32949,10 +33245,38 @@
32949 pList = pList->pDirty;
32950 }
32951
32952 return SQLITE_OK;
32953 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
32954
32955 /*
32956 ** This function is called by the pcache layer when it has reached some
32957 ** soft memory limit. The argument is a pointer to a purgeable Pager
32958 ** object. This function attempts to make a single dirty page that has no
@@ -32979,18 +33303,24 @@
32979 rc = writeJournalHdr(pPager);
32980 }
32981 }
32982 if( rc==SQLITE_OK ){
32983 pPg->pDirty = 0;
32984 rc = pager_write_pagelist(pPg);
 
 
 
 
 
32985 }
32986 if( rc!=SQLITE_OK ){
32987 pager_error(pPager, rc);
32988 }
32989 }
32990
32991 if( rc==SQLITE_OK ){
 
32992 sqlite3PcacheMakeClean(pPg);
32993 }
32994 return rc;
32995 }
32996
@@ -33060,12 +33390,12 @@
33060 if( pgno==1 ){
33061 memcpy(&pPager->dbFileVers, &((u8*)pPg->pData)[24],
33062 sizeof(pPager->dbFileVers));
33063 }
33064 CODEC1(pPager, pPg->pData, pPg->pgno, 3);
33065 PAGERTRACE4("FETCH %d page %d hash(%08x)\n",
33066 PAGERID(pPager), pPg->pgno, pager_pagehash(pPg));
33067 return rc;
33068 }
33069
33070
33071 /*
@@ -33113,12 +33443,14 @@
33113 rc = pager_wait_on_lock(pPager, SHARED_LOCK);
33114 if( rc!=SQLITE_OK ){
33115 assert( pPager->state==PAGER_UNLOCK );
33116 return pager_error(pPager, rc);
33117 }
33118 assert( pPager->state>=SHARED_LOCK );
 
33119 }
 
33120
33121 /* If a journal file exists, and there is no RESERVED lock on the
33122 ** database file, then it either needs to be played back or deleted.
33123 */
33124 if( !isErrorReset ){
@@ -33183,12 +33515,15 @@
33183 pPager->journalOff = 0;
33184 pPager->setMaster = 0;
33185 pPager->journalHdr = 0;
33186
33187 /* Playback and delete the journal. Drop the database write
33188 ** lock and reacquire the read lock.
 
 
33189 */
 
33190 rc = pager_playback(pPager, 1);
33191 if( rc!=SQLITE_OK ){
33192 rc = pager_error(pPager, rc);
33193 goto failed;
33194 }
@@ -33235,14 +33570,11 @@
33235
33236 if( memcmp(pPager->dbFileVers, dbFileVers, sizeof(dbFileVers))!=0 ){
33237 pager_reset(pPager);
33238 }
33239 }
33240 assert( pPager->exclusiveMode || pPager->state<=PAGER_SHARED );
33241 if( pPager->state==PAGER_UNLOCK ){
33242 pPager->state = PAGER_SHARED;
33243 }
33244 }
33245
33246 failed:
33247 if( rc!=SQLITE_OK ){
33248 /* pager_unlock() is a no-op for exclusive mode and in-memory databases. */
@@ -33458,10 +33790,31 @@
33458 sqlite3PcacheRelease(pPg);
33459 pagerUnlockIfUnused(pPager);
33460 }
33461 return SQLITE_OK;
33462 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
33463
33464 /*
33465 ** Create a journal file for pPager. There should already be a RESERVED
33466 ** or EXCLUSIVE lock on the database file when this routine is called.
33467 **
@@ -33518,16 +33871,16 @@
33518 pPager->nRec = 0;
33519 if( pPager->errCode ){
33520 rc = pPager->errCode;
33521 goto failed_to_open_journal;
33522 }
33523 pPager->origDbSize = pPager->dbSize;
33524
33525 rc = writeJournalHdr(pPager);
33526
33527 if( pPager->stmtAutoopen && rc==SQLITE_OK ){
33528 rc = sqlite3PagerStmtBegin(pPager);
33529 }
33530 if( rc!=SQLITE_OK && rc!=SQLITE_NOMEM && rc!=SQLITE_IOERR_NOMEM ){
33531 rc = pager_end_transaction(pPager, 0);
33532 if( rc==SQLITE_OK ){
33533 rc = SQLITE_FULL;
@@ -33585,11 +33938,11 @@
33585 }
33586 if( rc!=SQLITE_OK ){
33587 return rc;
33588 }
33589 pPager->dirtyCache = 0;
33590 PAGERTRACE2("TRANSACTION %d\n", PAGERID(pPager));
33591 if( pPager->useJournal && !pPager->tempFile
33592 && pPager->journalMode!=PAGER_JOURNALMODE_OFF ){
33593 rc = pager_open_journal(pPager);
33594 }
33595 }else if( pPager->journalOpen && pPager->journalOff==0 ){
@@ -33598,18 +33951,18 @@
33598 ** by this connection. Instead of deleting the journal file it was
33599 ** kept open and either was truncated to 0 bytes or its header was
33600 ** overwritten with zeros.
33601 */
33602 assert( pPager->nRec==0 );
33603 assert( pPager->origDbSize==0 );
33604 assert( pPager->pInJournal==0 );
33605 sqlite3PagerPagecount(pPager, 0);
33606 pPager->pInJournal = sqlite3BitvecCreate( pPager->dbSize );
33607 if( !pPager->pInJournal ){
33608 rc = SQLITE_NOMEM;
33609 }else{
33610 pPager->origDbSize = pPager->dbSize;
33611 rc = writeJournalHdr(pPager);
33612 }
33613 }
33614 assert( !pPager->journalOpen || pPager->journalOff>0 || rc!=SQLITE_OK );
33615 return rc;
@@ -33665,11 +34018,11 @@
33665
33666 /* Mark the page as dirty. If the page has already been written
33667 ** to the journal then we can return right away.
33668 */
33669 sqlite3PcacheMakeDirty(pPg);
33670 if( pageInJournal(pPg) && (pageInStatement(pPg) || pPager->stmtInUse==0) ){
33671 pPager->dirtyCache = 1;
33672 pPager->dbModified = 1;
33673 }else{
33674
33675 /* If we get this far, it means that the page needs to be
@@ -33696,11 +34049,11 @@
33696 /* The transaction journal now exists and we have a RESERVED or an
33697 ** EXCLUSIVE lock on the main database file. Write the current page to
33698 ** the transaction journal if it is not there already.
33699 */
33700 if( !pageInJournal(pPg) && pPager->journalOpen ){
33701 if( pPg->pgno<=pPager->origDbSize ){
33702 u32 cksum;
33703 char *pData2;
33704
33705 /* We should never write to the journal file the page that
33706 ** contains the database locks. The following assert verifies
@@ -33719,13 +34072,25 @@
33719 pPager->journalOff += 4;
33720 }
33721 IOTRACE(("JOUT %p %d %lld %d\n", pPager, pPg->pgno,
33722 pPager->journalOff, pPager->pageSize));
33723 PAGER_INCR(sqlite3_pager_writej_count);
33724 PAGERTRACE5("JOURNAL %d page %d needSync=%d hash(%08x)\n",
33725 PAGERID(pPager), pPg->pgno,
33726 ((pPg->flags&PGHDR_NEED_SYNC)?1:0), pager_pagehash(pPg));
 
 
 
 
 
 
 
 
 
 
 
 
33727
33728 /* An error has occured writing to the journal file. The
33729 ** transaction will be rolled back by the layer above.
33730 */
33731 if( rc!=SQLITE_OK ){
@@ -33732,53 +34097,36 @@
33732 return rc;
33733 }
33734
33735 pPager->nRec++;
33736 assert( pPager->pInJournal!=0 );
33737 sqlite3BitvecSet(pPager->pInJournal, pPg->pgno);
33738 if( !pPager->noSync ){
33739 pPg->flags |= PGHDR_NEED_SYNC;
33740 }
33741 if( pPager->stmtInUse ){
33742 sqlite3BitvecSet(pPager->pInStmt, pPg->pgno);
 
33743 }
33744 }else{
33745 if( !pPager->journalStarted && !pPager->noSync ){
33746 pPg->flags |= PGHDR_NEED_SYNC;
 
33747 }
33748 PAGERTRACE4("APPEND %d page %d needSync=%d\n",
33749 PAGERID(pPager), pPg->pgno,
33750 ((pPg->flags&PGHDR_NEED_SYNC)?1:0));
33751 }
33752 if( pPg->flags&PGHDR_NEED_SYNC ){
33753 pPager->needSync = 1;
33754 }
33755 }
33756
33757 /* If the statement journal is open and the page is not in it,
33758 ** then write the current page to the statement journal. Note that
33759 ** the statement journal format differs from the standard journal format
33760 ** in that it omits the checksums and the header.
33761 */
33762 if( pPager->stmtInUse
33763 && !pageInStatement(pPg)
33764 && pPg->pgno<=pPager->stmtSize
33765 ){
33766 i64 offset = pPager->stmtNRec*(4+pPager->pageSize);
33767 char *pData2 = CODEC2(pPager, pData, pPg->pgno, 7);
33768 assert( pageInJournal(pPg) || pPg->pgno>pPager->origDbSize );
33769 rc = write32bits(pPager->stfd, offset, pPg->pgno);
33770 if( rc==SQLITE_OK ){
33771 rc = sqlite3OsWrite(pPager->stfd, pData2, pPager->pageSize, offset+4);
33772 }
33773 PAGERTRACE3("STMT-JOURNAL %d page %d\n", PAGERID(pPager), pPg->pgno);
33774 if( rc!=SQLITE_OK ){
33775 return rc;
33776 }
33777 pPager->stmtNRec++;
33778 assert( pPager->pInStmt!=0 );
33779 sqlite3BitvecSet(pPager->pInStmt, pPg->pgno);
33780 }
33781 }
33782
33783 /* Update the database size and return.
33784 */
@@ -33849,10 +34197,11 @@
33849 rc = sqlite3PagerGet(pPager, pg, &pPage);
33850 if( rc==SQLITE_OK ){
33851 rc = pager_write(pPage);
33852 if( pPage->flags&PGHDR_NEED_SYNC ){
33853 needSync = 1;
 
33854 }
33855 sqlite3PagerUnref(pPage);
33856 }
33857 }
33858 }else if( (pPage = pager_lookup(pPager, pg))!=0 ){
@@ -33861,22 +34210,31 @@
33861 }
33862 sqlite3PagerUnref(pPage);
33863 }
33864 }
33865
33866 /* If the PgHdr.needSync flag is set for any of the nPage pages
33867 ** starting at pg1, then it needs to be set for all of them. Because
33868 ** writing to any of these nPage pages may damage the others, the
33869 ** journal file must contain sync()ed copies of all of them
33870 ** before any of them can be written out to the database file.
 
 
 
 
 
 
33871 */
33872 if( needSync ){
33873 assert( !MEMDB && pPager->noSync==0 );
33874 for(ii=0; ii<nPage && needSync; ii++){
33875 PgHdr *pPage = pager_lookup(pPager, pg1+ii);
33876 if( pPage ) pPage->flags |= PGHDR_NEED_SYNC;
33877 sqlite3PagerUnref(pPage);
 
 
 
33878 }
33879 assert(pPager->needSync);
33880 }
33881
33882 assert( pPager->doNotSync==1 );
@@ -33927,35 +34285,35 @@
33927 SQLITE_PRIVATE int sqlite3PagerDontWrite(DbPage *pDbPage){
33928 PgHdr *pPg = pDbPage;
33929 Pager *pPager = pPg->pPager;
33930 int rc;
33931
33932 if( pPg->pgno>pPager->origDbSize ){
33933 return SQLITE_OK;
33934 }
33935 if( pPager->pAlwaysRollback==0 ){
33936 assert( pPager->pInJournal );
33937 pPager->pAlwaysRollback = sqlite3BitvecCreate(pPager->origDbSize);
33938 if( !pPager->pAlwaysRollback ){
33939 return SQLITE_NOMEM;
33940 }
33941 }
33942 rc = sqlite3BitvecSet(pPager->pAlwaysRollback, pPg->pgno);
33943
33944 if( rc==SQLITE_OK && (pPg->flags&PGHDR_DIRTY) && !pPager->stmtInUse ){
33945 assert( pPager->state>=PAGER_SHARED );
33946 if( pPager->dbSize==pPg->pgno && pPager->origDbSize<pPager->dbSize ){
33947 /* If this pages is the last page in the file and the file has grown
33948 ** during the current transaction, then do NOT mark the page as clean.
33949 ** When the database file grows, we must make sure that the last page
33950 ** gets written at least once so that the disk file will be the correct
33951 ** size. If you do not write this page and the size of the file
33952 ** on the disk ends up being too small, that can lead to database
33953 ** corruption during the next transaction.
33954 */
33955 }else{
33956 PAGERTRACE3("DONT_WRITE page %d of %d\n", pPg->pgno, PAGERID(pPager));
33957 IOTRACE(("CLEAN %p %d\n", pPager, pPg->pgno))
33958 pPg->flags |= PGHDR_DONT_WRITE;
33959 #ifdef SQLITE_CHECK_PAGES
33960 pPg->pageHash = pager_pagehash(pPg);
33961 #endif
@@ -33975,27 +34333,28 @@
33975 ** that we will never need to read the page content in the future.
33976 ** so the needRead flag can be cleared at this point.
33977 */
33978 SQLITE_PRIVATE void sqlite3PagerDontRollback(DbPage *pPg){
33979 Pager *pPager = pPg->pPager;
 
33980
33981 assert( pPager->state>=PAGER_RESERVED );
33982
33983 /* If the journal file is not open, or DontWrite() has been called on
33984 ** this page (DontWrite() sets the alwaysRollback flag), then this
33985 ** function is a no-op.
33986 */
33987 if( pPager->journalOpen==0
33988 || sqlite3BitvecTest(pPager->pAlwaysRollback, pPg->pgno)
33989 || pPg->pgno>pPager->origDbSize
33990 ){
33991 return;
33992 }
33993
33994 #ifdef SQLITE_SECURE_DELETE
33995 if( sqlite3BitvecTest(pPager->pInJournal, pPg->pgno)!=0
33996 || pPg->pgno>pPager->origDbSize ){
33997 return;
33998 }
33999 #endif
34000
34001 /* If SECURE_DELETE is disabled, then there is no way that this
@@ -34006,20 +34365,30 @@
34006 **
34007 ** (Later:) Not true. If the database is corrupted by having duplicate
34008 ** pages on the freelist (ex: corrupt9.test) then the following is not
34009 ** necessarily true:
34010 */
34011 /* assert( !pPg->inJournal && (int)pPg->pgno <= pPager->origDbSize ); */
34012
34013 assert( pPager->pInJournal!=0 );
34014 sqlite3BitvecSet(pPager->pInJournal, pPg->pgno);
34015 pPg->flags &= ~PGHDR_NEED_READ;
34016 if( pPager->stmtInUse ){
34017 assert( pPager->stmtSize >= pPager->origDbSize );
34018 sqlite3BitvecSet(pPager->pInStmt, pPg->pgno);
34019 }
34020 PAGERTRACE3("DONT_ROLLBACK page %d of %d\n", pPg->pgno, PAGERID(pPager));
 
 
 
 
 
 
 
 
 
 
 
34021 IOTRACE(("GARBAGE %p %d\n", pPager, pPg->pgno))
34022 }
34023
34024
34025 /*
@@ -34032,11 +34401,11 @@
34032 int rc = SQLITE_OK;
34033
34034 #ifndef SQLITE_ENABLE_ATOMIC_WRITE
34035 assert( isDirect==0 ); /* isDirect is only true for atomic writes */
34036 #endif
34037 if( !pPager->changeCountDone ){
34038 /* Open page 1 of the file for writing. */
34039 rc = sqlite3PagerGet(pPager, 1, &pPgHdr);
34040 if( rc!=SQLITE_OK ) return rc;
34041
34042 if( !isDirect ){
@@ -34053,10 +34422,11 @@
34053 put32bits(((char*)pPgHdr->pData)+24, change_counter);
34054
34055 #ifdef SQLITE_ENABLE_ATOMIC_WRITE
34056 if( isDirect && pPager->fd->pMethods ){
34057 const void *zBuf = pPgHdr->pData;
 
34058 rc = sqlite3OsWrite(pPager->fd, zBuf, pPager->pageSize, 0);
34059 }
34060 #endif
34061
34062 /* Release the page reference. */
@@ -34091,22 +34461,18 @@
34091 ** master journal file if specified).
34092 **
34093 ** Note that if zMaster==NULL, this does not overwrite a previous value
34094 ** passed to an sqlite3PagerCommitPhaseOne() call.
34095 **
34096 ** If parameter nTrunc is non-zero, then the pager file is truncated to
34097 ** nTrunc pages (this is used by auto-vacuum databases).
34098 **
34099 ** If the final parameter - noSync - is true, then the database file itself
34100 ** is not synced. The caller must call sqlite3PagerSync() directly to
34101 ** sync the database file before calling CommitPhaseTwo() to delete the
34102 ** journal file in this case.
34103 */
34104 SQLITE_PRIVATE int sqlite3PagerCommitPhaseOne(
34105 Pager *pPager,
34106 const char *zMaster,
34107 Pgno nTrunc,
34108 int noSync
34109 ){
34110 int rc = SQLITE_OK;
34111
34112 if( pPager->errCode ){
@@ -34120,12 +34486,12 @@
34120 pPager->exclusiveMode!=0) ){
34121 assert( pPager->dirtyCache==0 || pPager->journalOpen==0 );
34122 return SQLITE_OK;
34123 }
34124
34125 PAGERTRACE4("DATABASE SYNC: File=%s zMaster=%s nTrunc=%d\n",
34126 pPager->zFilename, zMaster, nTrunc);
34127
34128 /* If this is an in-memory db, or no pages have been written to, or this
34129 ** function has already been called, it is a no-op.
34130 */
34131 if( pPager->state!=PAGER_SYNCED && !MEMDB && pPager->dirtyCache ){
@@ -34147,11 +34513,11 @@
34147 pPg = sqlite3PcacheDirtyList(pPager->pPCache);
34148 useAtomicWrite = (
34149 !zMaster &&
34150 pPager->journalOpen &&
34151 pPager->journalOff==jrnlBufferSize(pPager) &&
34152 nTrunc==0 &&
34153 (pPg==0 || pPg->pDirty==0)
34154 );
34155 assert( pPager->journalOpen || pPager->journalMode==PAGER_JOURNALMODE_OFF );
34156 if( useAtomicWrite ){
34157 /* Update the nRec field in the journal file. */
@@ -34184,42 +34550,38 @@
34184 if( !pPager->setMaster ){
34185 rc = pager_incr_changecounter(pPager, 0);
34186 if( rc!=SQLITE_OK ) goto sync_exit;
34187 if( pPager->journalMode!=PAGER_JOURNALMODE_OFF ){
34188 #ifndef SQLITE_OMIT_AUTOVACUUM
34189 if( nTrunc!=0 ){
34190 /* If this transaction has made the database smaller, then all pages
34191 ** being discarded by the truncation must be written to the journal
34192 ** file.
34193 */
34194 Pgno i;
34195 Pgno iSkip = PAGER_MJ_PGNO(pPager);
34196 for( i=nTrunc+1; i<=pPager->origDbSize; i++ ){
 
 
34197 if( !sqlite3BitvecTest(pPager->pInJournal, i) && i!=iSkip ){
34198 rc = sqlite3PagerGet(pPager, i, &pPg);
34199 if( rc!=SQLITE_OK ) goto sync_exit;
34200 rc = sqlite3PagerWrite(pPg);
34201 sqlite3PagerUnref(pPg);
34202 if( rc!=SQLITE_OK ) goto sync_exit;
34203 }
34204 }
 
34205 }
34206 #endif
34207 rc = writeMasterJournal(pPager, zMaster);
34208 if( rc!=SQLITE_OK ) goto sync_exit;
34209 rc = syncJournal(pPager);
34210 }
34211 }
34212 if( rc!=SQLITE_OK ) goto sync_exit;
34213
34214 #ifndef SQLITE_OMIT_AUTOVACUUM
34215 if( nTrunc!=0 ){
34216 rc = sqlite3PagerTruncate(pPager, nTrunc);
34217 if( rc!=SQLITE_OK ) goto sync_exit;
34218 }
34219 #endif
34220
34221 /* Write all dirty pages to the database file */
34222 pPg = sqlite3PcacheDirtyList(pPager->pPCache);
34223 rc = pager_write_pagelist(pPg);
34224 if( rc!=SQLITE_OK ){
34225 assert( rc!=SQLITE_IOERR_BLOCKED );
@@ -34231,20 +34593,24 @@
34231 ** is made to use an invalid dirty list.
34232 */
34233 goto sync_exit;
34234 }
34235 sqlite3PcacheCleanAll(pPager->pPCache);
 
 
 
 
 
 
34236
34237 /* Sync the database file. */
34238 if( !pPager->noSync && !noSync ){
34239 rc = sqlite3OsSync(pPager->fd, pPager->sync_flags);
34240 }
34241 IOTRACE(("DBSYNC %p\n", pPager))
34242
34243 pPager->state = PAGER_SYNCED;
34244 }else if( MEMDB && nTrunc!=0 ){
34245 rc = sqlite3PagerTruncate(pPager, nTrunc);
34246 }
34247
34248 sync_exit:
34249 if( rc==SQLITE_IOERR_BLOCKED ){
34250 /* pager_incr_changecounter() may attempt to obtain an exclusive
@@ -34278,11 +34644,11 @@
34278 (pPager->journalMode!=PAGER_JOURNALMODE_DELETE ||
34279 pPager->exclusiveMode!=0) ){
34280 assert( pPager->dirtyCache==0 || pPager->journalOpen==0 );
34281 return SQLITE_OK;
34282 }
34283 PAGERTRACE2("COMMIT %d\n", PAGERID(pPager));
34284 assert( pPager->state==PAGER_SYNCED || MEMDB || !pPager->dirtyCache );
34285 rc = pager_end_transaction(pPager, pPager->setMaster);
34286 rc = pager_error(pPager, rc);
34287 return rc;
34288 }
@@ -34299,11 +34665,11 @@
34299 ** codes are returned for all these occasions. Otherwise,
34300 ** SQLITE_OK is returned.
34301 */
34302 SQLITE_PRIVATE int sqlite3PagerRollback(Pager *pPager){
34303 int rc = SQLITE_OK;
34304 PAGERTRACE2("ROLLBACK %d\n", PAGERID(pPager));
34305 if( !pPager->dirtyCache || !pPager->journalOpen ){
34306 rc = pager_end_transaction(pPager, pPager->setMaster);
34307 }else if( pPager->errCode && pPager->errCode!=SQLITE_FULL ){
34308 if( pPager->state>=PAGER_EXCLUSIVE ){
34309 pager_playback(pPager, 0);
@@ -34379,96 +34745,101 @@
34379 return MEMDB;
34380 }
34381 #endif
34382
34383 /*
34384 ** Set the statement rollback point.
34385 **
34386 ** This routine should be called with the transaction journal already
34387 ** open. A new statement journal is created that can be used to rollback
34388 ** changes of a single SQL command within a larger transaction.
34389 */
34390 static int pagerStmtBegin(Pager *pPager){
34391 int rc;
34392 assert( !pPager->stmtInUse );
34393 assert( pPager->state>=PAGER_SHARED );
34394 assert( pPager->dbSizeValid );
34395 PAGERTRACE2("STMT-BEGIN %d\n", PAGERID(pPager));
34396 if( !pPager->journalOpen ){
34397 pPager->stmtAutoopen = 1;
34398 return SQLITE_OK;
34399 }
34400 assert( pPager->journalOpen );
34401 assert( pPager->pInStmt==0 );
34402 pPager->pInStmt = sqlite3BitvecCreate(pPager->dbSize);
34403 if( pPager->pInStmt==0 ){
34404 /* sqlite3OsLock(pPager->fd, SHARED_LOCK); */
34405 return SQLITE_NOMEM;
34406 }
34407 pPager->stmtJSize = pPager->journalOff;
34408 pPager->stmtSize = pPager->dbSize;
34409 pPager->stmtHdrOff = 0;
34410 pPager->stmtCksum = pPager->cksumInit;
34411 if( !pPager->stmtOpen ){
34412 if( pPager->journalMode==PAGER_JOURNALMODE_MEMORY ){
34413 sqlite3MemJournalOpen(pPager->stfd);
34414 }else{
34415 rc = sqlite3PagerOpentemp(pPager, pPager->stfd, SQLITE_OPEN_SUBJOURNAL);
34416 if( rc ){
34417 goto stmt_begin_failed;
34418 }
34419 }
34420 pPager->stmtOpen = 1;
34421 pPager->stmtNRec = 0;
34422 }
34423 pPager->stmtInUse = 1;
34424 return SQLITE_OK;
34425
34426 stmt_begin_failed:
34427 if( pPager->pInStmt ){
34428 sqlite3BitvecDestroy(pPager->pInStmt);
34429 pPager->pInStmt = 0;
34430 }
34431 return rc;
34432 }
34433 SQLITE_PRIVATE int sqlite3PagerStmtBegin(Pager *pPager){
34434 int rc;
34435 rc = pagerStmtBegin(pPager);
34436 return rc;
34437 }
34438
34439 /*
34440 ** Commit a statement.
34441 */
34442 SQLITE_PRIVATE int sqlite3PagerStmtCommit(Pager *pPager){
34443 if( pPager->stmtInUse ){
34444 PAGERTRACE2("STMT-COMMIT %d\n", PAGERID(pPager));
34445 sqlite3BitvecDestroy(pPager->pInStmt);
34446 pPager->pInStmt = 0;
34447 pPager->stmtNRec = 0;
34448 pPager->stmtInUse = 0;
34449 if( sqlite3IsMemJournal(pPager->stfd) ){
34450 sqlite3OsTruncate(pPager->stfd, 0);
34451 }
34452 }
34453 pPager->stmtAutoopen = 0;
34454 return SQLITE_OK;
34455 }
34456
34457 /*
34458 ** Rollback a statement.
34459 */
34460 SQLITE_PRIVATE int sqlite3PagerStmtRollback(Pager *pPager){
34461 int rc;
34462 if( pPager->stmtInUse ){
34463 PAGERTRACE2("STMT-ROLLBACK %d\n", PAGERID(pPager));
34464 rc = pager_stmt_playback(pPager);
34465 sqlite3PagerStmtCommit(pPager);
34466 }else{
34467 rc = SQLITE_OK;
34468 }
34469 pPager->stmtAutoopen = 0;
 
 
 
 
 
34470 return rc;
34471 }
34472
34473 /*
34474 ** Return the full pathname of the database file.
@@ -34553,15 +34924,37 @@
34553 ** pPg refers to will not be written to again within this transaction.
34554 */
34555 SQLITE_PRIVATE int sqlite3PagerMovepage(Pager *pPager, DbPage *pPg, Pgno pgno, int isCommit){
34556 PgHdr *pPgOld; /* The page being overwritten. */
34557 Pgno needSyncPgno = 0;
 
34558
34559 assert( pPg->nRef>0 );
34560
34561 PAGERTRACE5("MOVE %d page %d (needSync=%d) moves to %d\n",
34562 PAGERID(pPager), pPg->pgno, (pPg->flags&PGHDR_NEED_SYNC)?1:0, pgno);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
34563 IOTRACE(("MOVE %p %d %d\n", pPager, pPg->pgno, pgno))
34564
34565 pager_get_content(pPg);
34566
34567 /* If the journal needs to be sync()ed before page pPg->pgno can
@@ -34571,11 +34964,11 @@
34571 ** the journal needs to be sync()ed before database page pPg->pgno
34572 ** can be written to. The caller has already promised not to write to it.
34573 */
34574 if( (pPg->flags&PGHDR_NEED_SYNC) && !isCommit ){
34575 needSyncPgno = pPg->pgno;
34576 assert( pageInJournal(pPg) || pPg->pgno>pPager->origDbSize );
34577 assert( pPg->flags&PGHDR_DIRTY );
34578 assert( pPager->needSync );
34579 }
34580
34581 /* If the cache contains a page with page-number pgno, remove it
@@ -34615,16 +35008,15 @@
34615 ** the journal file twice, but that is not a problem.
34616 **
34617 ** The sqlite3PagerGet() call may cause the journal to sync. So make
34618 ** sure the Pager.needSync flag is set too.
34619 */
34620 int rc;
34621 PgHdr *pPgHdr;
34622 assert( pPager->needSync );
34623 rc = sqlite3PagerGet(pPager, needSyncPgno, &pPgHdr);
34624 if( rc!=SQLITE_OK ){
34625 if( pPager->pInJournal && needSyncPgno<=pPager->origDbSize ){
34626 sqlite3BitvecClear(pPager->pInJournal, needSyncPgno);
34627 }
34628 return rc;
34629 }
34630 pPager->needSync = 1;
@@ -34754,11 +35146,11 @@
34754 ** May you do good and not evil.
34755 ** May you find forgiveness for yourself and forgive others.
34756 ** May you share freely, never taking more than you give.
34757 **
34758 *************************************************************************
34759 ** $Id: btreeInt.h,v 1.37 2008/12/10 16:45:51 drh Exp $
34760 **
34761 ** This file implements a external (disk-based) database using BTrees.
34762 ** For a detailed discussion of BTrees, refer to
34763 **
34764 ** Donald E. Knuth, THE ART OF COMPUTER PROGRAMMING, Volume 3:
@@ -35111,11 +35503,10 @@
35111 u8 readOnly; /* True if the underlying file is readonly */
35112 u8 pageSizeFixed; /* True if the page size can no longer be changed */
35113 #ifndef SQLITE_OMIT_AUTOVACUUM
35114 u8 autoVacuum; /* True if auto-vacuum is enabled */
35115 u8 incrVacuum; /* True if incr-vacuum is enabled */
35116 Pgno nTrunc; /* Non-zero if the db will be truncated (incr vacuum) */
35117 #endif
35118 u16 pageSize; /* Total number of bytes on a page */
35119 u16 usableSize; /* Number of usable bytes on each page */
35120 u16 maxLocal; /* Maximum local payload in non-LEAFDATA tables */
35121 u16 minLocal; /* Minimum local payload in non-LEAFDATA tables */
@@ -35687,11 +36078,11 @@
35687 ** May you do good and not evil.
35688 ** May you find forgiveness for yourself and forgive others.
35689 ** May you share freely, never taking more than you give.
35690 **
35691 *************************************************************************
35692 ** $Id: btree.c,v 1.548 2008/12/16 13:46:30 drh Exp $
35693 **
35694 ** This file implements a external (disk-based) database using BTrees.
35695 ** See the header comment on "btreeInt.h" for additional information.
35696 ** Including a description of file format and an overview of operation.
35697 */
@@ -35711,24 +36102,10 @@
35711 # define TRACE(X) if(sqlite3BtreeTrace){printf X;fflush(stdout);}
35712 #else
35713 # define TRACE(X)
35714 #endif
35715
35716 /*
35717 ** Sometimes we need a small amount of code such as a variable initialization
35718 ** to setup for a later assert() statement. We do not want this code to
35719 ** appear when assert() is disabled. The following macro is therefore
35720 ** used to contain that setup code. The "VVA" acronym stands for
35721 ** "Verification, Validation, and Accreditation". In other words, the
35722 ** code within VVA_ONLY() will only run during verification processes.
35723 */
35724 #ifndef NDEBUG
35725 # define VVA_ONLY(X) X
35726 #else
35727 # define VVA_ONLY(X)
35728 #endif
35729
35730
35731
35732 #ifndef SQLITE_OMIT_SHARED_CACHE
35733 /*
35734 ** A list of BtShared objects that are eligible for participation
@@ -36858,10 +37235,11 @@
36858 ** Release a MemPage. This should be called once for each prior
36859 ** call to sqlite3BtreeGetPage.
36860 */
36861 static void releasePage(MemPage *pPage){
36862 if( pPage ){
 
36863 assert( pPage->aData );
36864 assert( pPage->pBt );
36865 assert( sqlite3PagerGetExtra(pPage->pDbPage) == (void*)pPage );
36866 assert( sqlite3PagerGetData(pPage->pDbPage)==pPage->aData );
36867 assert( sqlite3_mutex_held(pPage->pBt->mutex) );
@@ -37736,10 +38114,18 @@
37736 #endif
37737 }
37738
37739
37740 trans_begun:
 
 
 
 
 
 
 
 
37741 btreeIntegrity(p);
37742 sqlite3BtreeLeave(p);
37743 return rc;
37744 }
37745
@@ -37948,19 +38334,14 @@
37948 ** that the caller will keep calling incrVacuumStep() until
37949 ** it returns SQLITE_DONE or an error, and that nFin is the
37950 ** number of pages the database file will contain after this
37951 ** process is complete.
37952 */
37953 static int incrVacuumStep(BtShared *pBt, Pgno nFin){
37954 Pgno iLastPg; /* Last page in the database */
37955 Pgno nFreeList; /* Number of pages still on the free-list */
37956
37957 assert( sqlite3_mutex_held(pBt->mutex) );
37958 iLastPg = pBt->nTrunc;
37959 if( iLastPg==0 ){
37960 iLastPg = pagerPagecount(pBt);
37961 }
37962
37963 if( !PTRMAP_ISPAGE(pBt, iLastPg) && iLastPg!=PENDING_BYTE_PAGE(pBt) ){
37964 int rc;
37965 u8 eType;
37966 Pgno iPtrPage;
@@ -38030,13 +38411,16 @@
38030 return rc;
38031 }
38032 }
38033 }
38034
38035 pBt->nTrunc = iLastPg - 1;
38036 while( pBt->nTrunc==PENDING_BYTE_PAGE(pBt)||PTRMAP_ISPAGE(pBt, pBt->nTrunc) ){
38037 pBt->nTrunc--;
 
 
 
38038 }
38039 return SQLITE_OK;
38040 }
38041
38042 /*
@@ -38056,11 +38440,11 @@
38056 assert( pBt->inTransaction==TRANS_WRITE && p->inTrans==TRANS_WRITE );
38057 if( !pBt->autoVacuum ){
38058 rc = SQLITE_DONE;
38059 }else{
38060 invalidateAllOverflowCache(pBt);
38061 rc = incrVacuumStep(pBt, 0);
38062 }
38063 sqlite3BtreeLeave(p);
38064 return rc;
38065 }
38066
@@ -38071,66 +38455,57 @@
38071 ** If SQLITE_OK is returned, then *pnTrunc is set to the number of pages
38072 ** the database file should be truncated to during the commit process.
38073 ** i.e. the database has been reorganized so that only the first *pnTrunc
38074 ** pages are in use.
38075 */
38076 static int autoVacuumCommit(BtShared *pBt, Pgno *pnTrunc){
38077 int rc = SQLITE_OK;
38078 Pager *pPager = pBt->pPager;
38079 VVA_ONLY( int nRef = sqlite3PagerRefcount(pPager) );
38080
38081 assert( sqlite3_mutex_held(pBt->mutex) );
38082 invalidateAllOverflowCache(pBt);
38083 assert(pBt->autoVacuum);
38084 if( !pBt->incrVacuum ){
38085 Pgno nFin = 0;
38086
38087 if( pBt->nTrunc==0 ){
38088 Pgno nFree;
38089 Pgno nPtrmap;
38090 const int pgsz = pBt->pageSize;
38091 Pgno nOrig = pagerPagecount(pBt);
38092
38093 if( PTRMAP_ISPAGE(pBt, nOrig) ){
38094 return SQLITE_CORRUPT_BKPT;
38095 }
38096 if( nOrig==PENDING_BYTE_PAGE(pBt) ){
38097 nOrig--;
38098 }
38099 nFree = get4byte(&pBt->pPage1->aData[36]);
38100 nPtrmap = (nFree-nOrig+PTRMAP_PAGENO(pBt, nOrig)+pgsz/5)/(pgsz/5);
38101 nFin = nOrig - nFree - nPtrmap;
38102 if( nOrig>PENDING_BYTE_PAGE(pBt) && nFin<=PENDING_BYTE_PAGE(pBt) ){
38103 nFin--;
38104 }
38105 while( PTRMAP_ISPAGE(pBt, nFin) || nFin==PENDING_BYTE_PAGE(pBt) ){
38106 nFin--;
38107 }
38108 }
38109
38110 while( rc==SQLITE_OK ){
38111 rc = incrVacuumStep(pBt, nFin);
38112 }
38113 if( rc==SQLITE_DONE ){
38114 assert(nFin==0 || pBt->nTrunc==0 || nFin<=pBt->nTrunc);
38115 rc = SQLITE_OK;
38116 if( pBt->nTrunc && nFin ){
38117 rc = sqlite3PagerWrite(pBt->pPage1->pDbPage);
38118 put4byte(&pBt->pPage1->aData[32], 0);
38119 put4byte(&pBt->pPage1->aData[36], 0);
38120 pBt->nTrunc = nFin;
38121 }
38122 }
38123 if( rc!=SQLITE_OK ){
38124 sqlite3PagerRollback(pPager);
38125 }
38126 }
38127
38128 if( rc==SQLITE_OK ){
38129 *pnTrunc = pBt->nTrunc;
38130 pBt->nTrunc = 0;
38131 }
38132 assert( nRef==sqlite3PagerRefcount(pPager) );
38133 return rc;
38134 }
38135
38136 #endif /* ifndef SQLITE_OMIT_AUTOVACUUM */
@@ -38163,23 +38538,22 @@
38163 */
38164 SQLITE_PRIVATE int sqlite3BtreeCommitPhaseOne(Btree *p, const char *zMaster){
38165 int rc = SQLITE_OK;
38166 if( p->inTrans==TRANS_WRITE ){
38167 BtShared *pBt = p->pBt;
38168 Pgno nTrunc = 0;
38169 sqlite3BtreeEnter(p);
38170 pBt->db = p->db;
38171 #ifndef SQLITE_OMIT_AUTOVACUUM
38172 if( pBt->autoVacuum ){
38173 rc = autoVacuumCommit(pBt, &nTrunc);
38174 if( rc!=SQLITE_OK ){
38175 sqlite3BtreeLeave(p);
38176 return rc;
38177 }
38178 }
38179 #endif
38180 rc = sqlite3PagerCommitPhaseOne(pBt->pPager, zMaster, nTrunc, 0);
38181 sqlite3BtreeLeave(p);
38182 }
38183 return rc;
38184 }
38185
@@ -38345,14 +38719,10 @@
38345 unlockAllTables(p);
38346
38347 if( p->inTrans==TRANS_WRITE ){
38348 int rc2;
38349
38350 #ifndef SQLITE_OMIT_AUTOVACUUM
38351 pBt->nTrunc = 0;
38352 #endif
38353
38354 assert( TRANS_WRITE==pBt->inTransaction );
38355 rc2 = sqlite3PagerRollback(pBt->pPager);
38356 if( rc2!=SQLITE_OK ){
38357 rc = rc2;
38358 }
@@ -38402,21 +38772,28 @@
38402 SQLITE_PRIVATE int sqlite3BtreeBeginStmt(Btree *p){
38403 int rc;
38404 BtShared *pBt = p->pBt;
38405 sqlite3BtreeEnter(p);
38406 pBt->db = p->db;
38407 if( (p->inTrans!=TRANS_WRITE) || pBt->inStmt ){
38408 rc = pBt->readOnly ? SQLITE_READONLY : SQLITE_ERROR;
 
 
 
38409 }else{
38410 assert( pBt->inTransaction==TRANS_WRITE );
38411 rc = pBt->readOnly ? SQLITE_OK : sqlite3PagerStmtBegin(pBt->pPager);
 
 
 
 
 
38412 pBt->inStmt = 1;
38413 }
38414 sqlite3BtreeLeave(p);
38415 return rc;
38416 }
38417
38418
38419 /*
38420 ** Commit the statment subtransaction currently in progress. If no
38421 ** subtransaction is active, this is a no-op.
38422 */
@@ -38423,12 +38800,14 @@
38423 SQLITE_PRIVATE int sqlite3BtreeCommitStmt(Btree *p){
38424 int rc;
38425 BtShared *pBt = p->pBt;
38426 sqlite3BtreeEnter(p);
38427 pBt->db = p->db;
38428 if( pBt->inStmt && !pBt->readOnly ){
38429 rc = sqlite3PagerStmtCommit(pBt->pPager);
 
 
38430 }else{
38431 rc = SQLITE_OK;
38432 }
38433 pBt->inStmt = 0;
38434 sqlite3BtreeLeave(p);
@@ -38446,17 +38825,52 @@
38446 SQLITE_PRIVATE int sqlite3BtreeRollbackStmt(Btree *p){
38447 int rc = SQLITE_OK;
38448 BtShared *pBt = p->pBt;
38449 sqlite3BtreeEnter(p);
38450 pBt->db = p->db;
38451 if( pBt->inStmt && !pBt->readOnly ){
38452 rc = sqlite3PagerStmtRollback(pBt->pPager);
 
 
 
 
 
38453 pBt->inStmt = 0;
38454 }
38455 sqlite3BtreeLeave(p);
38456 return rc;
38457 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
38458
38459 /*
38460 ** Create a new cursor for the BTree whose root is on the page
38461 ** iTable. The act of acquiring a cursor gets a read lock on
38462 ** the database file.
@@ -38498,11 +38912,12 @@
38498 BtShared *pBt = p->pBt;
38499
38500 assert( sqlite3BtreeHoldsMutex(p) );
38501 assert( wrFlag==0 || wrFlag==1 );
38502 if( wrFlag ){
38503 if( pBt->readOnly ){
 
38504 return SQLITE_READONLY;
38505 }
38506 if( checkReadLocks(p, iTable, 0, 0) ){
38507 return SQLITE_LOCKED;
38508 }
@@ -38511,13 +38926,10 @@
38511 if( pBt->pPage1==0 ){
38512 rc = lockBtreeWithRetry(p);
38513 if( rc!=SQLITE_OK ){
38514 return rc;
38515 }
38516 if( pBt->readOnly && wrFlag ){
38517 return SQLITE_READONLY;
38518 }
38519 }
38520 pCur->pgnoRoot = (Pgno)iTable;
38521 rc = sqlite3PagerPagecount(pBt->pPager, (int *)&nPage);
38522 if( rc!=SQLITE_OK ){
38523 return rc;
@@ -39394,23 +39806,24 @@
39394 ** If an exact match is not found, then the cursor is always
39395 ** left pointing at a leaf page which would hold the entry if it
39396 ** were present. The cursor might point to an entry that comes
39397 ** before or after the key.
39398 **
39399 ** The result of comparing the key with the entry to which the
39400 ** cursor is written to *pRes if pRes!=NULL. The meaning of
39401 ** this value is as follows:
 
39402 **
39403 ** *pRes<0 The cursor is left pointing at an entry that
39404 ** is smaller than pKey or if the table is empty
39405 ** and the cursor is therefore left point to nothing.
39406 **
39407 ** *pRes==0 The cursor is left pointing at an entry that
39408 ** exactly matches pKey.
39409 **
39410 ** *pRes>0 The cursor is left pointing at an entry that
39411 ** is larger than pKey.
39412 **
39413 */
39414 SQLITE_PRIVATE int sqlite3BtreeMovetoUnpacked(
39415 BtCursor *pCur, /* The cursor to be moved */
39416 UnpackedRecord *pIdxKey, /* Unpacked index key */
@@ -39455,20 +39868,20 @@
39455 Pgno chldPg;
39456 MemPage *pPage = pCur->apPage[pCur->iPage];
39457 int c = -1; /* pRes return if table is empty must be -1 */
39458 lwr = 0;
39459 upr = pPage->nCell-1;
39460 if( !pPage->intKey && pIdxKey==0 ){
39461 rc = SQLITE_CORRUPT_BKPT;
39462 goto moveto_finish;
39463 }
39464 if( biasRight ){
39465 pCur->aiIdx[pCur->iPage] = (u16)upr;
39466 }else{
39467 pCur->aiIdx[pCur->iPage] = (u16)((upr+lwr)/2);
39468 }
39469 if( lwr<=upr ) for(;;){
39470 void *pCellKey;
39471 i64 nCellKey;
39472 int idx = pCur->aiIdx[pCur->iPage];
39473 pCur->info.nSize = 0;
39474 pCur->validNKey = 1;
@@ -39511,11 +39924,11 @@
39511 if( pPage->intKey && !pPage->leaf ){
39512 lwr = idx;
39513 upr = lwr - 1;
39514 break;
39515 }else{
39516 if( pRes ) *pRes = 0;
39517 rc = SQLITE_OK;
39518 goto moveto_finish;
39519 }
39520 }
39521 if( c<0 ){
@@ -39957,20 +40370,10 @@
39957 ** end of the file */
39958 int nPage = pagerPagecount(pBt);
39959 *pPgno = nPage + 1;
39960
39961 #ifndef SQLITE_OMIT_AUTOVACUUM
39962 if( pBt->nTrunc ){
39963 /* An incr-vacuum has already run within this transaction. So the
39964 ** page to allocate is not from the physical end of the file, but
39965 ** at pBt->nTrunc.
39966 */
39967 *pPgno = pBt->nTrunc+1;
39968 if( *pPgno==PENDING_BYTE_PAGE(pBt) ){
39969 (*pPgno)++;
39970 }
39971 }
39972 if( pBt->autoVacuum && PTRMAP_ISPAGE(pBt, *pPgno) ){
39973 /* If *pPgno refers to a pointer-map page, allocate two new pages
39974 ** at the end of the file instead of one. The first allocated page
39975 ** becomes a new pointer-map page, the second is used by the caller.
39976 */
@@ -39977,13 +40380,10 @@
39977 TRACE(("ALLOCATE: %d from end of file (pointer-map page)\n", *pPgno));
39978 assert( *pPgno!=PENDING_BYTE_PAGE(pBt) );
39979 (*pPgno)++;
39980 if( *pPgno==PENDING_BYTE_PAGE(pBt) ){ (*pPgno)++; }
39981 }
39982 if( pBt->nTrunc ){
39983 pBt->nTrunc = *pPgno;
39984 }
39985 #endif
39986
39987 assert( *pPgno!=PENDING_BYTE_PAGE(pBt) );
39988 rc = sqlite3BtreeGetPage(pBt, *pPgno, ppPage, 0);
39989 if( rc ) return rc;
@@ -40606,10 +41006,11 @@
40606 ** it will not be rolled back and so it is important to make sure that
40607 ** the page data and contents of MemPage are consistent.
40608 */
40609 pPage->isInit = 0;
40610 sqlite3BtreeInitPage(pPage);
 
40611
40612 /* If everything else succeeded, balance the parent page, in
40613 ** case the divider cell inserted caused it to become overfull.
40614 */
40615 if( rc==SQLITE_OK ){
@@ -40654,12 +41055,12 @@
40654 MemPage *pPage; /* The over or underfull page to balance */
40655 MemPage *pParent; /* The parent of pPage */
40656 BtShared *pBt; /* The whole database */
40657 int nCell = 0; /* Number of cells in apCell[] */
40658 int nMaxCells = 0; /* Allocated size of apCell, szCell, aFrom. */
40659 int nOld; /* Number of pages in apOld[] */
40660 int nNew; /* Number of pages in apNew[] */
40661 int nDiv; /* Number of cells in apDiv[] */
40662 int i, j, k; /* Loop counters */
40663 int idx; /* Index of pPage in pParent->aCell[] */
40664 int nxDiv; /* Next divider slot in pParent->aCell[] */
40665 int rc; /* The return code */
@@ -40698,11 +41099,11 @@
40698 assert( sqlite3PagerIswriteable(pPage->pDbPage) || pPage->nOverflow==1 );
40699 pBt = pPage->pBt;
40700 pParent = pCur->apPage[pCur->iPage-1];
40701 assert( pParent );
40702 if( SQLITE_OK!=(rc = sqlite3PagerWrite(pParent->pDbPage)) ){
40703 return rc;
40704 }
40705
40706 TRACE(("BALANCE: begin page %d child of %d\n", pPage->pgno, pParent->pgno));
40707
40708 #ifndef SQLITE_OMIT_QUICKBALANCE
@@ -40729,11 +41130,11 @@
40729 return balance_quick(pCur);
40730 }
40731 #endif
40732
40733 if( SQLITE_OK!=(rc = sqlite3PagerWrite(pPage->pDbPage)) ){
40734 return rc;
40735 }
40736
40737 /*
40738 ** Find the cell in the parent page whose left child points back
40739 ** to pPage. The "idx" variable is the index of that cell. If pPage
@@ -40740,16 +41141,10 @@
40740 ** is the rightmost child of pParent then set idx to pParent->nCell
40741 */
40742 idx = pCur->aiIdx[pCur->iPage-1];
40743 assertParentIndex(pParent, idx, pPage->pgno);
40744
40745 /*
40746 ** Initialize variables so that it will be safe to jump
40747 ** directly to balance_cleanup at any moment.
40748 */
40749 nOld = nNew = 0;
40750
40751 /*
40752 ** Find sibling pages to pPage and the cells in pParent that divide
40753 ** the siblings. An attempt is made to find NN siblings on either
40754 ** side of pPage. More siblings are taken from one side, however, if
40755 ** pPage there are fewer than NN siblings on the other side. If pParent
@@ -41207,10 +41602,13 @@
41207 ** But the parent page will always be initialized.
41208 */
41209 assert( pParent->isInit );
41210 sqlite3ScratchFree(apCell);
41211 apCell = 0;
 
 
 
41212 releasePage(pPage);
41213 pCur->iPage--;
41214 rc = balance(pCur, 0);
41215
41216 /*
@@ -41223,15 +41621,11 @@
41223 releasePage(apOld[i]);
41224 }
41225 for(i=0; i<nNew; i++){
41226 releasePage(apNew[i]);
41227 }
41228 pPage->nOverflow = 0;
41229
41230 /* releasePage(pParent); */
41231 TRACE(("BALANCE: finished with %d: old=%d new=%d cells=%d\n",
41232 pPage->pgno, nOld, nNew, nCell));
41233
41234 return rc;
41235 }
41236
41237 /*
@@ -41387,10 +41781,13 @@
41387 rc = ptrmapPut(pBt, pChild->pgno, PTRMAP_BTREE, pPage->pgno);
41388 #ifndef SQLITE_OMIT_AUTOVACUUM
41389 if( rc==SQLITE_OK ){
41390 rc = setChildPtrmaps(pChild);
41391 }
 
 
 
41392 #endif
41393 }
41394 }
41395
41396 if( rc==SQLITE_OK ){
@@ -41421,21 +41818,22 @@
41421 assert( sqlite3_mutex_held(pPage->pBt->mutex) );
41422 if( pCur->iPage==0 ){
41423 rc = sqlite3PagerWrite(pPage->pDbPage);
41424 if( rc==SQLITE_OK && pPage->nOverflow>0 ){
41425 rc = balance_deeper(pCur);
 
41426 assert( pPage->nOverflow==0 || rc!=SQLITE_OK );
41427 }
41428 if( rc==SQLITE_OK && pPage->nCell==0 ){
41429 rc = balance_shallower(pCur);
 
41430 assert( pPage->nOverflow==0 || rc!=SQLITE_OK );
41431 }
41432 }else{
41433 if( pPage->nOverflow>0 ||
41434 (!isInsert && pPage->nFree>pPage->pBt->usableSize*2/3) ){
41435 rc = balance_nonroot(pCur);
41436 assert( pPage->nOverflow==0 || rc!=SQLITE_OK );
41437 }
41438 }
41439 return rc;
41440 }
41441
@@ -41533,19 +41931,13 @@
41533 BtShared *pBt = p->pBt;
41534 unsigned char *oldCell;
41535 unsigned char *newCell = 0;
41536
41537 assert( cursorHoldsMutex(pCur) );
41538 if( pBt->inTransaction!=TRANS_WRITE ){
41539 /* Must start a transaction before doing an insert */
41540 rc = pBt->readOnly ? SQLITE_READONLY : SQLITE_ERROR;
41541 return rc;
41542 }
41543 assert( !pBt->readOnly );
41544 if( !pCur->wrFlag ){
41545 return SQLITE_PERM; /* Cursor not open for writing */
41546 }
41547 if( checkReadLocks(pCur->pBtree, pCur->pgnoRoot, pCur, nKey) ){
41548 return SQLITE_LOCKED; /* The table pCur points to has a read lock */
41549 }
41550 if( pCur->eState==CURSOR_FAULT ){
41551 return pCur->skip;
@@ -41606,12 +41998,11 @@
41606 rc = balance(pCur, 1);
41607 }
41608
41609 /* Must make sure nOverflow is reset to zero even if the balance()
41610 ** fails. Internal data structure corruption will result otherwise. */
41611 assert( pPage->nOverflow==0 || rc!=SQLITE_OK );
41612 pPage->nOverflow = 0;
41613
41614 if( rc==SQLITE_OK ){
41615 moveToRoot(pCur);
41616 }
41617 end_insert:
@@ -41631,25 +42022,19 @@
41631 Btree *p = pCur->pBtree;
41632 BtShared *pBt = p->pBt;
41633
41634 assert( cursorHoldsMutex(pCur) );
41635 assert( pPage->isInit );
41636 if( pBt->inTransaction!=TRANS_WRITE ){
41637 /* Must start a transaction before doing a delete */
41638 rc = pBt->readOnly ? SQLITE_READONLY : SQLITE_ERROR;
41639 return rc;
41640 }
41641 assert( !pBt->readOnly );
41642 if( pCur->eState==CURSOR_FAULT ){
41643 return pCur->skip;
41644 }
41645 if( pCur->aiIdx[pCur->iPage]>=pPage->nCell ){
41646 return SQLITE_ERROR; /* The cursor is not pointing to anything */
41647 }
41648 if( !pCur->wrFlag ){
41649 return SQLITE_PERM; /* Did not open this cursor for writing */
41650 }
41651 if( checkReadLocks(pCur->pBtree, pCur->pgnoRoot, pCur, pCur->info.nKey) ){
41652 return SQLITE_LOCKED; /* The table pCur points to has a read lock */
41653 }
41654
41655 /* Restore the current cursor position (a no-op if the cursor is not in
@@ -41840,15 +42225,11 @@
41840 MemPage *pRoot;
41841 Pgno pgnoRoot;
41842 int rc;
41843
41844 assert( sqlite3BtreeHoldsMutex(p) );
41845 if( pBt->inTransaction!=TRANS_WRITE ){
41846 /* Must start a transaction first */
41847 rc = pBt->readOnly ? SQLITE_READONLY : SQLITE_ERROR;
41848 return rc;
41849 }
41850 assert( !pBt->readOnly );
41851
41852 #ifdef SQLITE_OMIT_AUTOVACUUM
41853 rc = allocateBtreePage(pBt, &pRoot, &pgnoRoot, 1, 0);
41854 if( rc ){
@@ -42040,13 +42421,12 @@
42040 SQLITE_PRIVATE int sqlite3BtreeClearTable(Btree *p, int iTable, int *pnChange){
42041 int rc;
42042 BtShared *pBt = p->pBt;
42043 sqlite3BtreeEnter(p);
42044 pBt->db = p->db;
42045 if( p->inTrans!=TRANS_WRITE ){
42046 rc = pBt->readOnly ? SQLITE_READONLY : SQLITE_ERROR;
42047 }else if( (rc = checkReadLocks(p, iTable, 0, 1))!=SQLITE_OK ){
42048 /* nothing to do */
42049 }else if( SQLITE_OK!=(rc = saveAllCursors(pBt, iTable, 0)) ){
42050 /* nothing to do */
42051 }else{
42052 rc = clearDatabasePage(pBt, (Pgno)iTable, 0, pnChange);
@@ -42079,13 +42459,11 @@
42079 int rc;
42080 MemPage *pPage = 0;
42081 BtShared *pBt = p->pBt;
42082
42083 assert( sqlite3BtreeHoldsMutex(p) );
42084 if( p->inTrans!=TRANS_WRITE ){
42085 return pBt->readOnly ? SQLITE_READONLY : SQLITE_ERROR;
42086 }
42087
42088 /* It is illegal to drop a table if any cursors are open on the
42089 ** database. This is because in auto-vacuum mode the backend may
42090 ** need to move another root-page to fill a gap left by the deleted
42091 ** root page. If an open cursor was using this page a problem would
@@ -42272,26 +42650,23 @@
42272 unsigned char *pP1;
42273 int rc;
42274 assert( idx>=1 && idx<=15 );
42275 sqlite3BtreeEnter(p);
42276 pBt->db = p->db;
42277 if( p->inTrans!=TRANS_WRITE ){
42278 rc = pBt->readOnly ? SQLITE_READONLY : SQLITE_ERROR;
42279 }else{
42280 assert( pBt->pPage1!=0 );
42281 pP1 = pBt->pPage1->aData;
42282 rc = sqlite3PagerWrite(pBt->pPage1->pDbPage);
42283 if( rc==SQLITE_OK ){
42284 put4byte(&pP1[36 + idx*4], iMeta);
42285 #ifndef SQLITE_OMIT_AUTOVACUUM
42286 if( idx==7 ){
42287 assert( pBt->autoVacuum || iMeta==0 );
42288 assert( iMeta==0 || iMeta==1 );
42289 pBt->incrVacuum = (u8)iMeta;
42290 }
42291 #endif
42292 }
42293 }
42294 sqlite3BtreeLeave(p);
42295 return rc;
42296 }
42297
@@ -42305,12 +42680,13 @@
42305 */
42306 MemPage *pPage;
42307 restoreCursorPosition(pCur);
42308 pPage = pCur->apPage[pCur->iPage];
42309 assert( cursorHoldsMutex(pCur) );
 
42310 assert( pPage->pBt==pCur->pBt );
42311 return pPage ? pPage->aData[pPage->hdrOffset] : 0;
42312 }
42313
42314
42315 /*
42316 ** Return the pager associated with a BTree. This routine is used for
@@ -42521,11 +42897,11 @@
42521 checkAppendMsg(pCheck, zContext,
42522 "unable to get the page. error code=%d", rc);
42523 return 0;
42524 }
42525 if( (rc = sqlite3BtreeInitPage(pPage))!=0 ){
42526 if( rc==SQLITE_NOMEM ) pCheck->mallocFailed = 1;
42527 checkAppendMsg(pCheck, zContext,
42528 "sqlite3BtreeInitPage() returns error code %d", rc);
42529 releasePage(pPage);
42530 return 0;
42531 }
@@ -42690,15 +43066,10 @@
42690 sCheck.nPage = pagerPagecount(sCheck.pBt);
42691 sCheck.mxErr = mxErr;
42692 sCheck.nErr = 0;
42693 sCheck.mallocFailed = 0;
42694 *pnErr = 0;
42695 #ifndef SQLITE_OMIT_AUTOVACUUM
42696 if( pBt->nTrunc!=0 ){
42697 sCheck.nPage = pBt->nTrunc;
42698 }
42699 #endif
42700 if( sCheck.nPage==0 ){
42701 unlockBtreeIfUnused(pBt);
42702 sqlite3BtreeLeave(p);
42703 return 0;
42704 }
@@ -42753,14 +43124,16 @@
42753 checkAppendMsg(&sCheck, 0, "Pointer map page %d is referenced", i);
42754 }
42755 #endif
42756 }
42757
42758 /* Make sure this analysis did not leave any unref() pages
 
 
42759 */
42760 unlockBtreeIfUnused(pBt);
42761 if( nRef != sqlite3PagerRefcount(pBt->pPager) ){
42762 checkAppendMsg(&sCheck, 0,
42763 "Outstanding page count goes from %d to %d during this analysis",
42764 nRef, sqlite3PagerRefcount(pBt->pPager)
42765 );
42766 }
@@ -42845,14 +43218,13 @@
42845 pBtFrom->db = pFrom->db;
42846
42847 nToPageSize = pBtTo->pageSize;
42848 nFromPageSize = pBtFrom->pageSize;
42849
42850 if( pTo->inTrans!=TRANS_WRITE || pFrom->inTrans!=TRANS_WRITE ){
42851 return SQLITE_ERROR;
42852 }
42853 if( pBtTo->pCursor ){
42854 return SQLITE_BUSY;
42855 }
42856
42857 nToPage = pagerPagecount(pBtTo);
42858 nFromPage = pagerPagecount(pBtFrom);
@@ -42952,80 +43324,74 @@
42952 ** For example, say the page-size of pTo is 2048 bytes and the original
42953 ** number of pages is 5 (10 KB file). If pFrom has a page size of 1024
42954 ** bytes and 9 pages, then the file needs to be truncated to 9KB.
42955 */
42956 if( rc==SQLITE_OK ){
42957 if( nFromPageSize!=nToPageSize ){
42958 sqlite3_file *pFile = sqlite3PagerFile(pBtTo->pPager);
42959 i64 iSize = (i64)nFromPageSize * (i64)nFromPage;
42960 i64 iNow = (i64)((nToPage>nNewPage)?nToPage:nNewPage) * (i64)nToPageSize;
42961 i64 iPending = ((i64)PENDING_BYTE_PAGE(pBtTo)-1) *(i64)nToPageSize;
42962
42963 assert( iSize<=iNow );
42964
42965 /* Commit phase one syncs the journal file associated with pTo
42966 ** containing the original data. It does not sync the database file
42967 ** itself. After doing this it is safe to use OsTruncate() and other
42968 ** file APIs on the database file directly.
42969 */
42970 pBtTo->db = pTo->db;
42971 rc = sqlite3PagerCommitPhaseOne(pBtTo->pPager, 0, 0, 1);
42972 if( iSize<iNow && rc==SQLITE_OK ){
42973 rc = sqlite3OsTruncate(pFile, iSize);
42974 }
42975
42976 /* The loop that copied data from database pFrom to pTo did not
42977 ** populate the locking page of database pTo. If the page-size of
42978 ** pFrom is smaller than that of pTo, this means some data will
42979 ** not have been copied.
42980 **
42981 ** This block copies the missing data from database pFrom to pTo
42982 ** using file APIs. This is safe because at this point we know that
42983 ** all of the original data from pTo has been synced into the
42984 ** journal file. At this point it would be safe to do anything at
42985 ** all to the database file except truncate it to zero bytes.
42986 */
42987 if( rc==SQLITE_OK && nFromPageSize<nToPageSize && iSize>iPending){
42988 i64 iOff;
42989 for(
42990 iOff=iPending;
42991 rc==SQLITE_OK && iOff<(iPending+nToPageSize);
42992 iOff += nFromPageSize
42993 ){
42994 DbPage *pFromPage = 0;
42995 Pgno iFrom = (Pgno)(iOff/nFromPageSize)+1;
42996
42997 if( iFrom==PENDING_BYTE_PAGE(pBtFrom) || iFrom>nFromPage ){
42998 continue;
42999 }
43000
43001 rc = sqlite3PagerGet(pBtFrom->pPager, iFrom, &pFromPage);
43002 if( rc==SQLITE_OK ){
43003 char *zFrom = sqlite3PagerGetData(pFromPage);
43004 rc = sqlite3OsWrite(pFile, zFrom, nFromPageSize, iOff);
43005 sqlite3PagerUnref(pFromPage);
43006 }
43007 }
43008 }
43009
43010 /* Sync the database file */
43011 if( rc==SQLITE_OK ){
43012 rc = sqlite3PagerSync(pBtTo->pPager);
43013 }
43014 }else{
43015 rc = sqlite3PagerTruncate(pBtTo->pPager, nNewPage);
43016 }
43017 if( rc==SQLITE_OK ){
43018 pBtTo->pageSizeFixed = 0;
43019 }
43020 }
43021
43022 if( rc ){
43023 sqlite3BtreeRollback(pTo);
43024 }
43025
43026 return rc;
43027 }
43028 SQLITE_PRIVATE int sqlite3BtreeCopyFile(Btree *pTo, Btree *pFrom){
43029 int rc;
43030 sqlite3BtreeEnter(pTo);
43031 sqlite3BtreeEnter(pFrom);
@@ -43048,19 +43414,21 @@
43048 /*
43049 ** Return non-zero if a statement transaction is active.
43050 */
43051 SQLITE_PRIVATE int sqlite3BtreeIsInStmt(Btree *p){
43052 assert( sqlite3BtreeHoldsMutex(p) );
43053 return (p->pBt && p->pBt->inStmt);
 
43054 }
43055
43056 /*
43057 ** Return non-zero if a read (or write) transaction is active.
43058 */
43059 SQLITE_PRIVATE int sqlite3BtreeIsInReadTrans(Btree *p){
 
43060 assert( sqlite3_mutex_held(p->db->mutex) );
43061 return (p && (p->inTrans!=TRANS_NONE));
43062 }
43063
43064 /*
43065 ** This function returns a pointer to a blob of memory associated with
43066 ** a single shared-btree. The memory is used by client code for its own
@@ -43204,11 +43572,11 @@
43204 ** This file contains code use to manipulate "Mem" structure. A "Mem"
43205 ** stores a single value in the VDBE. Mem is an opaque structure visible
43206 ** only within the VDBE. Interface routines refer to a Mem using the
43207 ** name sqlite_value
43208 **
43209 ** $Id: vdbemem.c,v 1.133 2008/12/10 19:26:24 drh Exp $
43210 */
43211
43212 /*
43213 ** Call sqlite3VdbeMemExpandBlob() on the supplied value (type Mem*)
43214 ** P if required.
@@ -43650,11 +44018,10 @@
43650 ** Delete any previous value and set the value to be a BLOB of length
43651 ** n containing all zeros.
43652 */
43653 SQLITE_PRIVATE void sqlite3VdbeMemSetZeroBlob(Mem *pMem, int n){
43654 sqlite3VdbeMemRelease(pMem);
43655 MemSetTypeFlag(pMem, MEM_Blob);
43656 pMem->flags = MEM_Blob|MEM_Zero;
43657 pMem->type = SQLITE_BLOB;
43658 pMem->n = 0;
43659 if( n<0 ) n = 0;
43660 pMem->u.nZero = n;
@@ -44292,11 +44659,11 @@
44292 ** This file contains code used for creating, destroying, and populating
44293 ** a VDBE (or an "sqlite3_stmt" as it is known to the outside world.) Prior
44294 ** to version 2.8.7, all this code was combined into the vdbe.c source file.
44295 ** But that file was getting too big so this subroutines were split out.
44296 **
44297 ** $Id: vdbeaux.c,v 1.428 2008/12/16 17:20:38 shane Exp $
44298 */
44299
44300
44301
44302 /*
@@ -45551,13 +45918,16 @@
45551 }
45552 }
45553
45554 /* If there are any write-transactions at all, invoke the commit hook */
45555 if( needXcommit && db->xCommitCallback ){
 
 
45556 (void)sqlite3SafetyOff(db);
45557 rc = db->xCommitCallback(db->pCommitArg);
45558 (void)sqlite3SafetyOn(db);
 
45559 if( rc ){
45560 return SQLITE_CONSTRAINT;
45561 }
45562 }
45563
@@ -45855,10 +46225,11 @@
45855 /* We are forced to roll back the active transaction. Before doing
45856 ** so, abort any other statements this handle currently has active.
45857 */
45858 invalidateCursorsOnModifiedBtrees(db);
45859 sqlite3RollbackAll(db);
 
45860 db->autoCommit = 1;
45861 }
45862 }
45863 }
45864
@@ -45869,10 +46240,11 @@
45869 ** above has occurred.
45870 */
45871 if( !sqlite3VtabInSync(db)
45872 && db->autoCommit
45873 && db->writeVdbeCnt==(p->readOnly==0)
 
45874 ){
45875 if( p->rc==SQLITE_OK || (p->errorAction==OE_Fail && !isSpecialError) ){
45876 /* The auto-commit flag is true, and the vdbe program was
45877 ** successful or hit an 'OR FAIL' constraint. This means a commit
45878 ** is required.
@@ -45898,10 +46270,11 @@
45898 }else if( p->errorAction==OE_Abort ){
45899 xFunc = sqlite3BtreeRollbackStmt;
45900 }else{
45901 invalidateCursorsOnModifiedBtrees(db);
45902 sqlite3RollbackAll(db);
 
45903 db->autoCommit = 1;
45904 }
45905 }
45906
45907 /* If xFunc is not NULL, then it is one of sqlite3BtreeRollbackStmt or
@@ -48171,11 +48544,11 @@
48171 ** documentation, headers files, or other derived files. The formatting
48172 ** of the code in this file is, therefore, important. See other comments
48173 ** in this file for details. If in doubt, do not deviate from existing
48174 ** commenting and indentation practices when changing or adding code.
48175 **
48176 ** $Id: vdbe.c,v 1.803 2008/12/15 15:27:52 drh Exp $
48177 */
48178
48179 /*
48180 ** The following global variable is incremented every time a cursor
48181 ** moves, either by the OP_SeekXX, OP_Next, or OP_Prev opcodes. The test
@@ -48715,10 +49088,30 @@
48715 rc = sqlite3OsAccess(db->pVfs, zFile, SQLITE_ACCESS_EXISTS, &res);
48716 return (res && rc==SQLITE_OK);
48717 }
48718 #endif
48719
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
48720 /*
48721 ** Execute as much of a VDBE program as we can then return.
48722 **
48723 ** sqlite3VdbeMakeReady() must be called before this routine in order to
48724 ** close the program with a final OP_Halt and to set up the callbacks
@@ -49005,15 +49398,12 @@
49005
49006 /* Opcode: Yield P1 * * * *
49007 **
49008 ** Swap the program counter with the value in register P1.
49009 */
49010 case OP_Yield: {
49011 int pcDest;
49012 assert( pOp->p1>0 );
49013 assert( pOp->p1<=p->nMem );
49014 pIn1 = &p->aMem[pOp->p1];
49015 assert( (pIn1->flags & MEM_Dyn)==0 );
49016 pIn1->flags = MEM_Int;
49017 pcDest = (int)pIn1->u.i;
49018 pIn1->u.i = pc;
49019 REGISTER_TRACE(pOp->p1, pIn1);
@@ -49229,14 +49619,11 @@
49229 ** Make a copy of register P1 into register P2.
49230 **
49231 ** This instruction makes a deep copy of the value. A duplicate
49232 ** is made of any string or blob constant. See also OP_SCopy.
49233 */
49234 case OP_Copy: {
49235 assert( pOp->p1>0 );
49236 assert( pOp->p1<=p->nMem );
49237 pIn1 = &p->aMem[pOp->p1];
49238 assert( pOp->p2>0 );
49239 assert( pOp->p2<=p->nMem );
49240 pOut = &p->aMem[pOp->p2];
49241 assert( pOut!=pIn1 );
49242 sqlite3VdbeMemShallowCopy(pOut, pIn1, MEM_Ephem);
@@ -49255,14 +49642,11 @@
49255 ** Worse, if the original is deallocated, the copy becomes invalid.
49256 ** Thus the program must guarantee that the original will not change
49257 ** during the lifetime of the copy. Use OP_Copy to make a complete
49258 ** copy.
49259 */
49260 case OP_SCopy: {
49261 assert( pOp->p1>0 );
49262 assert( pOp->p1<=p->nMem );
49263 pIn1 = &p->aMem[pOp->p1];
49264 REGISTER_TRACE(pOp->p1, pIn1);
49265 assert( pOp->p2>0 );
49266 assert( pOp->p2<=p->nMem );
49267 pOut = &p->aMem[pOp->p2];
49268 assert( pOut!=pIn1 );
@@ -49708,11 +50092,11 @@
49708 assert( MEM_Str==(MEM_Blob>>3) );
49709 pIn1->flags |= (pIn1->flags&MEM_Blob)>>3;
49710 applyAffinity(pIn1, SQLITE_AFF_TEXT, encoding);
49711 rc = ExpandBlob(pIn1);
49712 assert( pIn1->flags & MEM_Str || db->mallocFailed );
49713 pIn1->flags &= ~(MEM_Int|MEM_Real|MEM_Blob);
49714 UPDATE_MAX_BLOBSIZE(pIn1);
49715 break;
49716 }
49717
49718 /* Opcode: ToBlob P1 * * * *
@@ -49727,12 +50111,14 @@
49727 case OP_ToBlob: { /* same as TK_TO_BLOB, in1 */
49728 if( pIn1->flags & MEM_Null ) break;
49729 if( (pIn1->flags & MEM_Blob)==0 ){
49730 applyAffinity(pIn1, SQLITE_AFF_TEXT, encoding);
49731 assert( pIn1->flags & MEM_Str || db->mallocFailed );
 
 
 
49732 }
49733 MemSetTypeFlag(pIn1, MEM_Blob);
49734 UPDATE_MAX_BLOBSIZE(pIn1);
49735 break;
49736 }
49737
49738 /* Opcode: ToNumeric P1 * * * *
@@ -50571,10 +50957,144 @@
50571 p->openedStatement = 1;
50572 }
50573 }
50574 break;
50575 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
50576
50577 /* Opcode: AutoCommit P1 P2 * * *
50578 **
50579 ** Set the database auto-commit flag to P1 (1 or 0). If P2 is true, roll
50580 ** back any currently active btree transactions. If there are any active
@@ -50606,11 +51126,11 @@
50606 */
50607 sqlite3SetString(&p->zErrMsg, db, "cannot commit transaction - "
50608 "SQL statements in progress");
50609 rc = SQLITE_BUSY;
50610 }else if( desiredAutoCommit!=db->autoCommit ){
50611 if( pOp->p2 ){
50612 assert( desiredAutoCommit==1 );
50613 sqlite3RollbackAll(db);
50614 db->autoCommit = 1;
50615 }else{
50616 db->autoCommit = (u8)desiredAutoCommit;
@@ -50619,10 +51139,11 @@
50619 db->autoCommit = (u8)(1-desiredAutoCommit);
50620 p->rc = rc = SQLITE_BUSY;
50621 goto vdbe_return;
50622 }
50623 }
 
50624 if( p->rc==SQLITE_OK ){
50625 rc = SQLITE_DONE;
50626 }else{
50627 rc = SQLITE_ERROR;
50628 }
@@ -52569,20 +53090,20 @@
52569 Mem *pIdx;
52570 i64 val;
52571 assert( pOp->p1>0 && pOp->p1<=p->nMem );
52572 CHECK_FOR_INTERRUPT;
52573 pIdx = &p->aMem[pOp->p1];
 
52574 if( (pIdx->flags & MEM_RowSet)==0
52575 || sqlite3RowSetNext(pIdx->u.pRowSet, &val)==0
52576 ){
52577 /* The boolean index is empty */
52578 sqlite3VdbeMemSetNull(pIdx);
52579 pc = pOp->p2 - 1;
52580 }else{
52581 /* A value was pulled from the index */
52582 assert( pOp->p3>0 && pOp->p3<=p->nMem );
52583 pOut = &p->aMem[pOp->p3];
52584 sqlite3VdbeMemSetInt64(pOut, val);
52585 }
52586 break;
52587 }
52588
@@ -54011,11 +54532,11 @@
54011 **
54012 ** This file contains code use to implement an in-memory rollback journal.
54013 ** The in-memory rollback journal is used to journal transactions for
54014 ** ":memory:" databases and when the journal_mode=MEMORY pragma is used.
54015 **
54016 ** @(#) $Id: memjournal.c,v 1.7 2008/12/10 21:19:57 drh Exp $
54017 */
54018
54019 /* Forward references to internal structures */
54020 typedef struct MemJournal MemJournal;
54021 typedef struct FilePoint FilePoint;
@@ -54236,11 +54757,11 @@
54236
54237 /*
54238 ** Return the number of bytes required to store a MemJournal that uses vfs
54239 ** pVfs to create the underlying on-disk files.
54240 */
54241 SQLITE_PRIVATE int sqlite3MemJournalSize(){
54242 return sizeof(MemJournal);
54243 }
54244
54245 /************** End of memjournal.c ******************************************/
54246 /************** Begin file walker.c ******************************************/
@@ -60509,11 +61030,11 @@
60509 ** creating ID lists
60510 ** BEGIN TRANSACTION
60511 ** COMMIT
60512 ** ROLLBACK
60513 **
60514 ** $Id: build.c,v 1.508 2008/12/10 22:30:25 shane Exp $
60515 */
60516
60517 /*
60518 ** This routine is called when a new SQL statement is beginning to
60519 ** be parsed. Initialize the pParse structure as needed.
@@ -61440,11 +61961,11 @@
61440 if( p->nCol+1>db->aLimit[SQLITE_LIMIT_COLUMN] ){
61441 sqlite3ErrorMsg(pParse, "too many columns on %s", p->zName);
61442 return;
61443 }
61444 #endif
61445 z = sqlite3NameFromToken(pParse->db, pName);
61446 if( z==0 ) return;
61447 for(i=0; i<p->nCol; i++){
61448 if( STRICMP(z, p->aCol[i].zName) ){
61449 sqlite3ErrorMsg(pParse, "duplicate column name: %s", z);
61450 sqlite3DbFree(db, z);
@@ -61451,11 +61972,11 @@
61451 return;
61452 }
61453 }
61454 if( (p->nCol & 0x7)==0 ){
61455 Column *aNew;
61456 aNew = sqlite3DbRealloc(pParse->db,p->aCol,(p->nCol+8)*sizeof(p->aCol[0]));
61457 if( aNew==0 ){
61458 sqlite3DbFree(db, z);
61459 return;
61460 }
61461 p->aCol = aNew;
@@ -63795,10 +64316,30 @@
63795 v = sqlite3GetVdbe(pParse);
63796 if( v ){
63797 sqlite3VdbeAddOp2(v, OP_AutoCommit, 1, 1);
63798 }
63799 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
63800
63801 /*
63802 ** Make sure the TEMP database is open and available for use. Return
63803 ** the number of errors. Leave any error messages in the pParse structure.
63804 */
@@ -64540,11 +65081,11 @@
64540 **
64541 *************************************************************************
64542 ** This file contains C code routines that are called by the parser
64543 ** in order to generate code for DELETE FROM statements.
64544 **
64545 ** $Id: delete.c,v 1.190 2008/12/10 21:19:57 drh Exp $
64546 */
64547
64548 /*
64549 ** Look up every table that is named in pSrc. If any table is not found,
64550 ** add an error message to pParse->zErrMsg and return NULL. If all tables
@@ -64919,25 +65460,19 @@
64919 */
64920 {
64921 int iRowid = ++pParse->nMem; /* Used for storing rowid values. */
64922 int iRowSet = ++pParse->nMem; /* Register for rowset of rows to delete */
64923
64924 /* Begin the database scan
64925 */
64926 pWInfo = sqlite3WhereBegin(pParse, pTabList, pWhere, 0, 0);
64927 if( pWInfo==0 ) goto delete_from_cleanup;
64928
64929 /* Remember the rowid of every item to be deleted.
64930 */
64931 sqlite3VdbeAddOp2(v, IsVirtual(pTab) ? OP_VRowid : OP_Rowid, iCur, iRowid);
64932 sqlite3VdbeAddOp2(v, OP_RowSetAdd, iRowSet, iRowid);
64933 if( db->flags & SQLITE_CountRows ){
64934 sqlite3VdbeAddOp2(v, OP_AddImm, memCnt, 1);
64935 }
64936
64937 /* End the database scan loop.
64938 */
64939 sqlite3WhereEnd(pWInfo);
64940
64941 /* Open the pseudo-table used to store OLD if there are triggers.
64942 */
64943 if( triggers_exist ){
@@ -69450,11 +69985,11 @@
69450 ** May you share freely, never taking more than you give.
69451 **
69452 *************************************************************************
69453 ** This file contains code used to implement the PRAGMA command.
69454 **
69455 ** $Id: pragma.c,v 1.199 2008/12/10 23:04:13 drh Exp $
69456 */
69457
69458 /* Ignore this whole file if pragmas are disabled
69459 */
69460 #if !defined(SQLITE_OMIT_PRAGMA) && !defined(SQLITE_OMIT_PARSER)
@@ -69633,11 +70168,12 @@
69633 for(i=0, p=aPragma; i<ArraySize(aPragma); i++, p++){
69634 if( sqlite3StrICmp(zLeft, p->zName)==0 ){
69635 sqlite3 *db = pParse->db;
69636 Vdbe *v;
69637 v = sqlite3GetVdbe(pParse);
69638 if( v ){
 
69639 if( zRight==0 ){
69640 returnSingleInt(pParse, p->zName, (db->flags & p->mask)!=0 );
69641 }else{
69642 if( getBoolean(zRight) ){
69643 db->flags |= p->mask;
@@ -69658,18 +70194,23 @@
69658 }
69659 return 0;
69660 }
69661 #endif /* SQLITE_OMIT_FLAG_PRAGMAS */
69662
 
 
 
69663 static const char *actionName(u8 action){
 
69664 switch( action ){
69665 case OE_SetNull: return "SET NULL";
69666 case OE_SetDflt: return "SET DEFAULT";
69667 case OE_Restrict: return "RESTRICT";
69668 case OE_Cascade: return "CASCADE";
 
69669 }
69670 return "";
69671 }
69672
69673 /*
69674 ** Process a pragma statement.
69675 **
@@ -69722,11 +70263,12 @@
69722 zRight = sqlite3MPrintf(db, "-%T", pValue);
69723 }else{
69724 zRight = sqlite3NameFromToken(db, pValue);
69725 }
69726
69727 zDb = ((pId2 && pId2->n>0)?pDb->zName:0);
 
69728 if( sqlite3AuthCheck(pParse, SQLITE_PRAGMA, zLeft, zRight, zDb) ){
69729 goto pragma_out;
69730 }
69731
69732 #ifndef SQLITE_OMIT_PAGER_PRAGMAS
@@ -69790,12 +70332,13 @@
69790 ** database page size value. The value can only be set if
69791 ** the database has not yet been created.
69792 */
69793 if( sqlite3StrICmp(zLeft,"page_size")==0 ){
69794 Btree *pBt = pDb->pBt;
 
69795 if( !zRight ){
69796 int size = pBt ? sqlite3BtreeGetPageSize(pBt) : 0;
69797 returnSingleInt(pParse, "page_size", size);
69798 }else{
69799 /* Malloc may fail when setting the page-size, as there is an internal
69800 ** buffer that the pager module resizes using sqlite3_realloc().
69801 */
@@ -69816,14 +70359,15 @@
69816 ** forms return the current setting.
69817 */
69818 if( sqlite3StrICmp(zLeft,"max_page_count")==0 ){
69819 Btree *pBt = pDb->pBt;
69820 int newMax = 0;
 
69821 if( zRight ){
69822 newMax = atoi(zRight);
69823 }
69824 if( pBt ){
69825 newMax = sqlite3BtreeMaxPageCount(pBt, newMax);
69826 }
69827 returnSingleInt(pParse, "max_page_count", newMax);
69828 }else
69829
@@ -69832,11 +70376,11 @@
69832 **
69833 ** Return the number of pages in the specified database.
69834 */
69835 if( sqlite3StrICmp(zLeft,"page_count")==0 ){
69836 int iReg;
69837 if( !v || sqlite3ReadSchema(pParse) ) goto pragma_out;
69838 sqlite3CodeVerifySchema(pParse, iDb);
69839 iReg = ++pParse->nMem;
69840 sqlite3VdbeAddOp2(v, OP_Pagecount, iDb, iReg);
69841 sqlite3VdbeAddOp2(v, OP_ResultRow, iReg, 1);
69842 sqlite3VdbeSetNumCols(v, 1);
@@ -69980,21 +70524,27 @@
69980 ** Get or set the (boolean) value of the database 'auto-vacuum' parameter.
69981 */
69982 #ifndef SQLITE_OMIT_AUTOVACUUM
69983 if( sqlite3StrICmp(zLeft,"auto_vacuum")==0 ){
69984 Btree *pBt = pDb->pBt;
 
69985 if( sqlite3ReadSchema(pParse) ){
69986 goto pragma_out;
69987 }
69988 if( !zRight ){
69989 int auto_vacuum =
69990 pBt ? sqlite3BtreeGetAutoVacuum(pBt) : SQLITE_DEFAULT_AUTOVACUUM;
 
 
 
 
69991 returnSingleInt(pParse, "auto_vacuum", auto_vacuum);
69992 }else{
69993 int eAuto = getAutoVacuum(zRight);
 
69994 db->nextAutovac = (u8)eAuto;
69995 if( eAuto>=0 ){
69996 /* Call SetAutoVacuum() to set initialize the internal auto and
69997 ** incr-vacuum flags. This is required in case this connection
69998 ** creates the database file. It is important that it is created
69999 ** as an auto-vacuum capable db.
70000 */
@@ -70141,10 +70691,18 @@
70141 }
70142 #endif /* SQLITE_OMIT_WSD */
70143 }
70144 }else
70145
 
 
 
 
 
 
 
 
70146 /*
70147 ** PRAGMA [database.]lock_proxy_file
70148 ** PRAGMA [database.]lock_proxy_file = ":auto:"|"lock_file_path"
70149 **
70150 ** Return or set the value of the lock_proxy_file flag. Changing
@@ -70181,11 +70739,11 @@
70181 sqlite3ErrorMsg(pParse, "failed to set lock proxy file");
70182 goto pragma_out;
70183 }
70184 }
70185 }else
70186
70187
70188 /*
70189 ** PRAGMA [database.]synchronous
70190 ** PRAGMA [database.]synchronous=OFF|ON|NORMAL|FULL
70191 **
@@ -70255,11 +70813,13 @@
70255 sqlite3VdbeAddOp2(v, OP_Integer, i-nHidden, 1);
70256 sqlite3VdbeAddOp4(v, OP_String8, 0, 2, 0, pCol->zName, 0);
70257 sqlite3VdbeAddOp4(v, OP_String8, 0, 3, 0,
70258 pCol->zType ? pCol->zType : "", 0);
70259 sqlite3VdbeAddOp2(v, OP_Integer, (pCol->notNull ? 1 : 0), 4);
70260 if( pCol->pDflt && (pDflt = &pCol->pDflt->span)->z ){
 
 
70261 sqlite3VdbeAddOp4(v, OP_String8, 0, 5, 0, (char*)pDflt->z, pDflt->n);
70262 }else{
70263 sqlite3VdbeAddOp2(v, OP_Null, 0, 5);
70264 }
70265 sqlite3VdbeAddOp2(v, OP_Integer, pCol->isPrimKey, 6);
@@ -70615,15 +71175,15 @@
70615 if( sqlite3StrICmp(zLeft, "encoding")==0 ){
70616 static const struct EncName {
70617 char *zName;
70618 u8 enc;
70619 } encnames[] = {
70620 { "UTF-8", SQLITE_UTF8 },
70621 { "UTF8", SQLITE_UTF8 },
70622 { "UTF-16le", SQLITE_UTF16LE },
 
 
70623 { "UTF16le", SQLITE_UTF16LE },
70624 { "UTF-16be", SQLITE_UTF16BE },
70625 { "UTF16be", SQLITE_UTF16BE },
70626 { "UTF-16", 0 }, /* SQLITE_UTF16NATIVE */
70627 { "UTF16", 0 }, /* SQLITE_UTF16NATIVE */
70628 { 0, 0 }
70629 };
@@ -70631,16 +71191,14 @@
70631 if( !zRight ){ /* "PRAGMA encoding" */
70632 if( sqlite3ReadSchema(pParse) ) goto pragma_out;
70633 sqlite3VdbeSetNumCols(v, 1);
70634 sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "encoding", SQLITE_STATIC);
70635 sqlite3VdbeAddOp2(v, OP_String8, 0, 1);
70636 for(pEnc=&encnames[0]; pEnc->zName; pEnc++){
70637 if( pEnc->enc==ENC(pParse->db) ){
70638 sqlite3VdbeChangeP4(v, -1, pEnc->zName, P4_STATIC);
70639 break;
70640 }
70641 }
70642 sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 1);
70643 }else{ /* "PRAGMA encoding = XXX" */
70644 /* Only change the value of sqlite.enc if the database handle is not
70645 ** initialized. If the main database exists, the new sqlite.enc value
70646 ** will be overwritten when the schema is next loaded. If it does not
@@ -70781,12 +71339,30 @@
70781 sqlite3CreateStatementsTable(pParse);
70782 }else
70783 #endif
70784
70785 #if SQLITE_HAS_CODEC
70786 if( sqlite3StrICmp(zLeft, "key")==0 ){
70787 sqlite3_key(db, zRight, sqlite3Strlen30(zRight));
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
70788 }else
70789 #endif
70790 #if SQLITE_HAS_CODEC || defined(SQLITE_ENABLE_CEROD)
70791 if( sqlite3StrICmp(zLeft, "activate_extensions")==0 ){
70792 #if SQLITE_HAS_CODEC
@@ -70799,33 +71375,32 @@
70799 if( sqlite3StrNICmp(zRight, "cerod-", 6)==0 ){
70800 extern void sqlite3_activate_cerod(const char*);
70801 sqlite3_activate_cerod(&zRight[6]);
70802 }
70803 #endif
70804 }
70805 #endif
70806
70807 {}
70808
70809 if( v ){
70810 /* Code an OP_Expire at the end of each PRAGMA program to cause
70811 ** the VDBE implementing the pragma to expire. Most (all?) pragmas
70812 ** are only valid for a single execution.
70813 */
70814 sqlite3VdbeAddOp2(v, OP_Expire, 1, 0);
70815
70816 /*
70817 ** Reset the safety level, in case the fullfsync flag or synchronous
70818 ** setting changed.
70819 */
70820 #ifndef SQLITE_OMIT_PAGER_PRAGMAS
70821 if( db->autoCommit ){
70822 sqlite3BtreeSetSafetyLevel(pDb->pBt, pDb->safety_level,
70823 (db->flags&SQLITE_FullFSync)!=0);
70824 }
70825 #endif
70826 }
70827 pragma_out:
70828 sqlite3DbFree(db, zLeft);
70829 sqlite3DbFree(db, zRight);
70830 }
70831
@@ -70846,11 +71421,11 @@
70846 *************************************************************************
70847 ** This file contains the implementation of the sqlite3_prepare()
70848 ** interface, and routines that contribute to loading the database schema
70849 ** from disk.
70850 **
70851 ** $Id: prepare.c,v 1.103 2008/12/10 19:26:24 drh Exp $
70852 */
70853
70854 /*
70855 ** Fill the InitData structure with an error message that indicates
70856 ** that the database is corrupt.
@@ -71332,22 +71907,22 @@
71332 ** expr.c is trying to resolve a reference to a transient table (i.e. one
71333 ** created by a sub-select). In this case the return value of this
71334 ** function should never be used.
71335 **
71336 ** We return -1000000 instead of the more usual -1 simply because using
71337 ** -1000000 as incorrectly using -1000000 index into db->aDb[] is much
71338 ** more likely to cause a segfault than -1 (of course there are assert()
71339 ** statements too, but it never hurts to play the odds).
71340 */
71341 assert( sqlite3_mutex_held(db->mutex) );
71342 if( pSchema ){
71343 for(i=0; i<db->nDb; i++){
71344 if( db->aDb[i].pSchema==pSchema ){
71345 break;
71346 }
71347 }
71348 assert( i>=0 &&i>=0 && i<db->nDb );
71349 }
71350 return i;
71351 }
71352
71353 /*
@@ -71657,11 +72232,11 @@
71657 **
71658 *************************************************************************
71659 ** This file contains C code routines that are called by the parser
71660 ** to handle SELECT statements in SQLite.
71661 **
71662 ** $Id: select.c,v 1.494 2008/12/10 22:15:00 drh Exp $
71663 */
71664
71665
71666 /*
71667 ** Delete all the content of a Select structure but do not deallocate
@@ -71986,11 +72561,11 @@
71986 for(i=0; i<pSrc->nSrc-1; i++, pRight++, pLeft++){
71987 Table *pLeftTab = pLeft->pTab;
71988 Table *pRightTab = pRight->pTab;
71989 int isOuter;
71990
71991 if( pLeftTab==0 || pRightTab==0 ) continue;
71992 isOuter = (pRight->jointype & JT_OUTER)!=0;
71993
71994 /* When the NATURAL keyword is present, add WHERE clause terms for
71995 ** every column that the two tables have in common.
71996 */
@@ -72186,11 +72761,12 @@
72186 int regResult; /* Start of memory holding result set */
72187 int eDest = pDest->eDest; /* How to dispose of results */
72188 int iParm = pDest->iParm; /* First argument to disposal method */
72189 int nResultCol; /* Number of result columns */
72190
72191 if( v==0 ) return;
 
72192 assert( pEList!=0 );
72193 hasDistinct = distinct>=0;
72194 if( pOrderBy==0 && !hasDistinct ){
72195 codeOffset(v, p, iContinue);
72196 }
@@ -72204,15 +72780,12 @@
72204 }
72205 if( pDest->iMem==0 ){
72206 pDest->iMem = pParse->nMem+1;
72207 pDest->nMem = nResultCol;
72208 pParse->nMem += nResultCol;
72209 }else if( pDest->nMem!=nResultCol ){
72210 /* This happens when two SELECTs of a compound SELECT have differing
72211 ** numbers of result columns. The error message will be generated by
72212 ** a higher-level routine. */
72213 return;
72214 }
72215 regResult = pDest->iMem;
72216 if( nColumn>0 ){
72217 for(i=0; i<nColumn; i++){
72218 sqlite3VdbeAddOp3(v, OP_Column, srcTab, i, regResult+i);
@@ -72457,10 +73030,12 @@
72457 regRowid = sqlite3GetTempReg(pParse);
72458 sqlite3VdbeAddOp3(v, OP_Column, iTab, pOrderBy->nExpr + 1, regRow);
72459 switch( eDest ){
72460 case SRT_Table:
72461 case SRT_EphemTab: {
 
 
72462 sqlite3VdbeAddOp2(v, OP_NewRowid, iParm, regRowid);
72463 sqlite3VdbeAddOp3(v, OP_Insert, iParm, regRow, regRowid);
72464 sqlite3VdbeChangeP5(v, OPFLAG_APPEND);
72465 break;
72466 }
@@ -72480,10 +73055,12 @@
72480 }
72481 #endif
72482 case SRT_Output:
72483 case SRT_Coroutine: {
72484 int i;
 
 
72485 sqlite3VdbeAddOp2(v, OP_Integer, 1, regRowid);
72486 sqlite3VdbeAddOp3(v, OP_Insert, pseudoTab, regRow, regRowid);
72487 for(i=0; i<nColumn; i++){
72488 assert( regRow!=pDest->iMem+i );
72489 sqlite3VdbeAddOp3(v, OP_Column, pseudoTab, i, pDest->iMem+i);
@@ -72590,11 +73167,11 @@
72590 if( pS ){
72591 /* The "table" is actually a sub-select or a view in the FROM clause
72592 ** of the SELECT statement. Return the declaration type and origin
72593 ** data for the result-set column of the sub-select.
72594 */
72595 if( iCol>=0 && iCol<pS->pEList->nExpr ){
72596 /* If iCol is less than zero, then the expression requests the
72597 ** rowid of the sub-select or view. This expression is legal (see
72598 ** test case misc2.2.2) - it always evaluates to NULL.
72599 */
72600 NameContext sNC;
@@ -72602,11 +73179,11 @@
72602 sNC.pSrcList = pS->pSrc;
72603 sNC.pNext = 0;
72604 sNC.pParse = pNC->pParse;
72605 zType = columnType(&sNC, p, &zOriginDb, &zOriginTab, &zOriginCol);
72606 }
72607 }else if( pTab->pSchema ){
72608 /* A real table */
72609 assert( !pS );
72610 if( iCol<0 ) iCol = pTab->iPKey;
72611 assert( iCol==-1 || (iCol>=0 && iCol<pTab->nCol) );
72612 if( iCol<0 ){
@@ -72711,11 +73288,11 @@
72711 return;
72712 }
72713 #endif
72714
72715 assert( v!=0 );
72716 if( pParse->colNamesSet || v==0 || db->mallocFailed ) return;
72717 pParse->colNamesSet = 1;
72718 fullNames = (db->flags & SQLITE_FullColNames)!=0;
72719 shortNames = (db->flags & SQLITE_ShortColNames)!=0;
72720 sqlite3VdbeSetNumCols(v, pEList->nExpr);
72721 for(i=0; i<pEList->nExpr; i++){
@@ -72727,11 +73304,13 @@
72727 sqlite3VdbeSetColName(v, i, COLNAME_NAME, zName, SQLITE_TRANSIENT);
72728 }else if( (p->op==TK_COLUMN || p->op==TK_AGG_COLUMN) && pTabList ){
72729 Table *pTab;
72730 char *zCol;
72731 int iCol = p->iColumn;
72732 for(j=0; j<pTabList->nSrc && pTabList->a[j].iCursor!=p->iTable; j++){}
 
 
72733 assert( j<pTabList->nSrc );
72734 pTab = pTabList->a[j].pTab;
72735 if( iCol<0 ) iCol = pTab->iPKey;
72736 assert( iCol==-1 || (iCol>=0 && iCol<pTab->nCol) );
72737 if( iCol<0 ){
@@ -72740,17 +73319,13 @@
72740 zCol = pTab->aCol[iCol].zName;
72741 }
72742 if( !shortNames && !fullNames ){
72743 sqlite3VdbeSetColName(v, i, COLNAME_NAME,
72744 sqlite3DbStrNDup(db, (char*)p->span.z, p->span.n), SQLITE_DYNAMIC);
72745 }else if( fullNames || (!shortNames && pTabList->nSrc>1) ){
72746 char *zName = 0;
72747 char *zTab;
72748
72749 zTab = pTabList->a[j].zAlias;
72750 if( fullNames || zTab==0 ) zTab = pTab->zName;
72751 zName = sqlite3MPrintf(db, "%s.%s", zTab, zCol);
72752 sqlite3VdbeSetColName(v, i, COLNAME_NAME, zName, SQLITE_DYNAMIC);
72753 }else{
72754 sqlite3VdbeSetColName(v, i, COLNAME_NAME, zCol, SQLITE_TRANSIENT);
72755 }
72756 }else{
@@ -73189,14 +73764,18 @@
73189 Expr *pLimit, *pOffset; /* Saved values of p->nLimit and p->nOffset */
73190 int addr;
73191 SelectDest uniondest;
73192
73193 priorOp = SRT_Union;
73194 if( dest.eDest==priorOp && !p->pLimit && !p->pOffset ){
73195 /* We can reuse a temporary table generated by a SELECT to our
73196 ** right.
73197 */
 
 
 
 
73198 unionTab = dest.iParm;
73199 }else{
73200 /* We will need to create our own temporary table to hold the
73201 ** intermediate results.
73202 */
@@ -74050,10 +74629,12 @@
74050 pExpr->iAgg = pNew->iAgg;
74051 sqlite3TokenCopy(db, &pExpr->token, &pNew->token);
74052 sqlite3TokenCopy(db, &pExpr->span, &pNew->span);
74053 pExpr->pSelect = sqlite3SelectDup(db, pNew->pSelect);
74054 pExpr->flags = pNew->flags;
 
 
74055 }
74056 }else{
74057 substExpr(db, pExpr->pLeft, iTable, pEList);
74058 substExpr(db, pExpr->pRight, iTable, pEList);
74059 substSelect(db, pExpr->pSelect, iTable, pEList);
@@ -74087,11 +74668,12 @@
74087 substExprList(db, p->pOrderBy, iTable, pEList);
74088 substExpr(db, p->pHaving, iTable, pEList);
74089 substExpr(db, p->pWhere, iTable, pEList);
74090 substSelect(db, p->pPrior, iTable, pEList);
74091 pSrc = p->pSrc;
74092 if( pSrc ){
 
74093 for(i=pSrc->nSrc, pItem=pSrc->a; i>0; i--, pItem++){
74094 substSelect(db, pItem->pSelect, iTable, pEList);
74095 }
74096 }
74097 }
@@ -74219,11 +74801,10 @@
74219 sqlite3 *db = pParse->db;
74220
74221 /* Check to see if flattening is permitted. Return 0 if not.
74222 */
74223 assert( p!=0 );
74224 if( p==0 ) return 0;
74225 assert( p->pPrior==0 ); /* Unable to flatten compound queries */
74226 pSrc = p->pSrc;
74227 assert( pSrc && iFrom>=0 && iFrom<pSrc->nSrc );
74228 pSubitem = &pSrc->a[iFrom];
74229 iParent = pSubitem->iCursor;
@@ -74297,11 +74878,11 @@
74297 ** use only the UNION ALL operator. And none of the simple select queries
74298 ** that make up the compound SELECT are allowed to be aggregate or distinct
74299 ** queries.
74300 */
74301 if( pSub->pPrior ){
74302 if( p->pPrior || isAgg || (p->selFlags & SF_Distinct)!=0 || pSrc->nSrc!=1 ){
74303 return 0;
74304 }
74305 for(pSub1=pSub; pSub1; pSub1=pSub1->pPrior){
74306 if( (pSub1->selFlags & (SF_Distinct|SF_Aggregate))!=0
74307 || (pSub1->pPrior && pSub1->op!=TK_ALL)
@@ -75349,11 +75930,11 @@
75349 /* Aggregate and non-aggregate queries are handled differently */
75350 if( !isAgg && pGroupBy==0 ){
75351 /* This case is for non-aggregate queries
75352 ** Begin the database scan
75353 */
75354 pWInfo = sqlite3WhereBegin(pParse, pTabList, pWhere, &pOrderBy, 0);
75355 if( pWInfo==0 ) goto select_end;
75356
75357 /* If sorting index that was created by a prior OP_OpenEphemeral
75358 ** instruction ended up not being needed, then change the OP_OpenEphemeral
75359 ** into an OP_Noop.
@@ -75470,11 +76051,11 @@
75470 ** This might involve two separate loops with an OP_Sort in between, or
75471 ** it might be a single loop that uses an index to extract information
75472 ** in the right order to begin with.
75473 */
75474 sqlite3VdbeAddOp2(v, OP_Gosub, regReset, addrReset);
75475 pWInfo = sqlite3WhereBegin(pParse, pTabList, pWhere, &pGroupBy, 0);
75476 if( pWInfo==0 ) goto select_end;
75477 if( pGroupBy==0 ){
75478 /* The optimizer is able to deliver rows in group by order so
75479 ** we do not have to sort. The OP_OpenEphemeral table will be
75480 ** cancelled later because we still need to use the pKeyInfo
@@ -75668,11 +76249,11 @@
75668 /* This case runs if the aggregate has no GROUP BY clause. The
75669 ** processing is much simpler since there is only a single row
75670 ** of output.
75671 */
75672 resetAccumulator(pParse, &sAggInfo);
75673 pWInfo = sqlite3WhereBegin(pParse, pTabList, pWhere, &pMinMax, flag);
75674 if( pWInfo==0 ){
75675 sqlite3ExprListDelete(db, pDel);
75676 goto select_end;
75677 }
75678 updateAccumulator(pParse, &sAggInfo);
@@ -76036,11 +76617,11 @@
76036 ** May you share freely, never taking more than you give.
76037 **
76038 *************************************************************************
76039 **
76040 **
76041 ** $Id: trigger.c,v 1.132 2008/12/10 19:26:24 drh Exp $
76042 */
76043
76044 #ifndef SQLITE_OMIT_TRIGGER
76045 /*
76046 ** Delete a linked list of TriggerStep structures.
@@ -76697,10 +77278,11 @@
76697 assert( pTriggerStep!=0 );
76698 assert( v!=0 );
76699 sqlite3VdbeAddOp2(v, OP_ContextPush, 0, 0);
76700 VdbeComment((v, "begin trigger %s", pStepList->pTrig->name));
76701 while( pTriggerStep ){
 
76702 orconf = (orconfin == OE_Default)?pTriggerStep->orconf:orconfin;
76703 pParse->trigStack->orconf = orconf;
76704 switch( pTriggerStep->op ){
76705 case TK_SELECT: {
76706 Select *ss = sqlite3SelectDup(db, pTriggerStep->pSelect);
@@ -76894,11 +77476,11 @@
76894 **
76895 *************************************************************************
76896 ** This file contains C code routines that are called by the parser
76897 ** to handle UPDATE statements.
76898 **
76899 ** $Id: update.c,v 1.190 2008/12/10 22:15:00 drh Exp $
76900 */
76901
76902 #ifndef SQLITE_OMIT_VIRTUALTABLE
76903 /* Forward declaration */
76904 static void updateVirtualTable(
@@ -77227,11 +77809,11 @@
77227
77228 /* Begin the database scan
77229 */
77230 sqlite3VdbeAddOp2(v, OP_Null, 0, regOldRowid);
77231 pWInfo = sqlite3WhereBegin(pParse, pTabList, pWhere, 0,
77232 WHERE_ONEPASS_DESIRED);
77233 if( pWInfo==0 ) goto update_cleanup;
77234 okOnePass = pWInfo->okOnePass;
77235
77236 /* Remember the rowid of every item to be updated.
77237 */
@@ -78731,11 +79313,11 @@
78731 ** generating the code that loops through a table looking for applicable
78732 ** rows. Indices are selected and used to speed the search when doing
78733 ** so is applicable. Because this module is responsible for selecting
78734 ** indices, you might also think of this module as the "query optimizer".
78735 **
78736 ** $Id: where.c,v 1.337 2008/12/12 17:56:16 drh Exp $
78737 */
78738
78739 /*
78740 ** Trace output macros
78741 */
@@ -78749,11 +79331,14 @@
78749 #endif
78750
78751 /* Forward reference
78752 */
78753 typedef struct WhereClause WhereClause;
78754 typedef struct ExprMaskSet ExprMaskSet;
 
 
 
78755
78756 /*
78757 ** The query generator uses an array of instances of this structure to
78758 ** help it analyze the subexpressions of the WHERE clause. Each WHERE
78759 ** clause subexpression is separated from the others by AND operators.
@@ -78769,23 +79354,36 @@
78769 ** When a term is of the form:
78770 **
78771 ** X <op> <expr>
78772 **
78773 ** where X is a column name and <op> is one of certain operators,
78774 ** then WhereTerm.leftCursor and WhereTerm.leftColumn record the
78775 ** cursor number and column number for X. WhereTerm.operator records
78776 ** the <op> using a bitmask encoding defined by WO_xxx below. The
78777 ** use of a bitmask encoding for the operator allows us to search
78778 ** quickly for terms that match any of several different operators.
78779 **
78780 ** prereqRight and prereqAll record sets of cursor numbers,
78781 ** but they do so indirectly. A single ExprMaskSet structure translates
 
 
 
 
 
 
 
 
 
 
 
 
 
78782 ** cursor number into bits and the translated bit is stored in the prereq
78783 ** fields. The translation is used in order to maximize the number of
78784 ** bits that will fit in a Bitmask. The VDBE cursor numbers might be
78785 ** spread out over the non-negative integers. For example, the cursor
78786 ** numbers might be 3, 8, 9, 10, 20, 23, 41, and 45. The ExprMaskSet
78787 ** translates these sparse cursor numbers into consecutive integers
78788 ** beginning with 0 in order to make the best possible use of the available
78789 ** bits in the Bitmask. So, in the example above, the cursor numbers
78790 ** would be mapped into integers 0 through 7.
78791 **
@@ -78796,11 +79394,15 @@
78796 typedef struct WhereTerm WhereTerm;
78797 struct WhereTerm {
78798 Expr *pExpr; /* Pointer to the subexpression that is this term */
78799 int iParent; /* Disable pWC->a[iParent] when this term disabled */
78800 int leftCursor; /* Cursor number of X in "X <op> <expr>" */
78801 int leftColumn; /* Column number of X in "X <op> <expr>" */
 
 
 
 
78802 u16 eOperator; /* A WO_xx value describing <op> */
78803 u8 wtFlags; /* TERM_xxx bit flags. See below */
78804 u8 nChild; /* Number of children that must disable us */
78805 WhereClause *pWC; /* The clause this term is part of */
78806 Bitmask prereqRight; /* Bitmask of tables used by pExpr->pRight */
@@ -78812,24 +79414,44 @@
78812 */
78813 #define TERM_DYNAMIC 0x01 /* Need to call sqlite3ExprDelete(db, pExpr) */
78814 #define TERM_VIRTUAL 0x02 /* Added by the optimizer. Do not code */
78815 #define TERM_CODED 0x04 /* This term is already coded */
78816 #define TERM_COPIED 0x08 /* Has a child */
78817 #define TERM_OR_OK 0x10 /* Used during OR-clause processing */
 
 
78818
78819 /*
78820 ** An instance of the following structure holds all information about a
78821 ** WHERE clause. Mostly this is a container for one or more WhereTerms.
78822 */
78823 struct WhereClause {
78824 Parse *pParse; /* The parser context */
78825 ExprMaskSet *pMaskSet; /* Mapping of table indices to bitmasks */
 
78826 int nTerm; /* Number of terms */
78827 int nSlot; /* Number of entries in a[] */
78828 WhereTerm *a; /* Each a[] describes a term of the WHERE cluase */
78829 WhereTerm aStatic[4]; /* Initial static space for a[] */
78830 };
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
78831
78832 /*
78833 ** An instance of the following structure keeps track of a mapping
78834 ** between VDBE cursor numbers and bits of the bitmasks in WhereTerm.
78835 **
@@ -78839,29 +79461,38 @@
78839 ** contain gaps in the numbering sequence. But we want to make maximum
78840 ** use of the bits in our bitmasks. This structure provides a mapping
78841 ** from the sparse cursor numbers into consecutive integers beginning
78842 ** with 0.
78843 **
78844 ** If ExprMaskSet.ix[A]==B it means that The A-th bit of a Bitmask
78845 ** corresponds VDBE cursor number B. The A-th bit of a bitmask is 1<<A.
78846 **
78847 ** For example, if the WHERE clause expression used these VDBE
78848 ** cursors: 4, 5, 8, 29, 57, 73. Then the ExprMaskSet structure
78849 ** would map those cursor numbers into bits 0 through 5.
78850 **
78851 ** Note that the mapping is not necessarily ordered. In the example
78852 ** above, the mapping might go like this: 4->3, 5->1, 8->2, 29->0,
78853 ** 57->5, 73->4. Or one of 719 other combinations might be used. It
78854 ** does not really matter. What is important is that sparse cursor
78855 ** numbers all get mapped into bit numbers that begin with 0 and contain
78856 ** no gaps.
78857 */
78858 struct ExprMaskSet {
78859 int n; /* Number of assigned cursor values */
78860 int ix[BMS]; /* Cursor assigned to each bit */
78861 };
78862
 
 
 
 
 
 
 
 
 
78863
78864 /*
78865 ** Bitmasks for the operators that indices are able to exploit. An
78866 ** OR-ed combination of these values can be used when searching for
78867 ** terms in the where clause.
@@ -78872,31 +79503,36 @@
78872 #define WO_LE (WO_EQ<<(TK_LE-TK_EQ))
78873 #define WO_GT (WO_EQ<<(TK_GT-TK_EQ))
78874 #define WO_GE (WO_EQ<<(TK_GE-TK_EQ))
78875 #define WO_MATCH 0x040
78876 #define WO_ISNULL 0x080
78877 #define WO_OR 0x100
 
78878
78879 #define WO_ALL 0xfff /* Mask of all possible WO_* values */
 
78880
78881 /*
78882 ** Value for wsFlags returned by bestIndex(). These flags determine which
78883 ** search strategies are appropriate.
 
78884 **
78885 ** The least significant 12 bits is reserved as a mask for WO_ values above.
78886 ** The WhereLevel.wtFlags field is usually set to WO_IN|WO_EQ|WO_ISNULL.
78887 ** But if the table is the right table of a left join, WhereLevel.wtFlags
78888 ** is set to WO_IN|WO_EQ. The WhereLevel.wtFlags field can then be used as
78889 ** the "op" parameter to findTerm when we are resolving equality constraints.
78890 ** ISNULL constraints will then not be used on the right table of a left
78891 ** join. Tickets #2177 and #2189.
78892 */
78893 #define WHERE_ROWID_EQ 0x00001000 /* rowid=EXPR or rowid IN (...) */
78894 #define WHERE_ROWID_RANGE 0x00002000 /* rowid<EXPR and/or rowid>EXPR */
78895 #define WHERE_COLUMN_EQ 0x00010000 /* x=EXPR or x IN (...) */
78896 #define WHERE_COLUMN_RANGE 0x00020000 /* x<EXPR and/or x>EXPR */
78897 #define WHERE_COLUMN_IN 0x00040000 /* x IN (...) */
 
 
78898 #define WHERE_TOP_LIMIT 0x00100000 /* x<EXPR or x<=EXPR constraint */
78899 #define WHERE_BTM_LIMIT 0x00200000 /* x>EXPR or x>=EXPR constraint */
78900 #define WHERE_IDX_ONLY 0x00800000 /* Use index only - omit table */
78901 #define WHERE_ORDERBY 0x01000000 /* Output will appear in correct order */
78902 #define WHERE_REVERSE 0x02000000 /* Scan in reverse order */
@@ -78908,18 +79544,37 @@
78908 ** Initialize a preallocated WhereClause structure.
78909 */
78910 static void whereClauseInit(
78911 WhereClause *pWC, /* The WhereClause to be initialized */
78912 Parse *pParse, /* The parsing context */
78913 ExprMaskSet *pMaskSet /* Mapping from table indices to bitmasks */
78914 ){
78915 pWC->pParse = pParse;
78916 pWC->pMaskSet = pMaskSet;
78917 pWC->nTerm = 0;
78918 pWC->nSlot = ArraySize(pWC->aStatic);
78919 pWC->a = pWC->aStatic;
78920 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
78921
78922 /*
78923 ** Deallocate a WhereClause structure. The WhereClause structure
78924 ** itself is not freed. This routine is the inverse of whereClauseInit().
78925 */
@@ -78929,10 +79584,15 @@
78929 sqlite3 *db = pWC->pParse->db;
78930 for(i=pWC->nTerm-1, a=pWC->a; i>=0; i--, a++){
78931 if( a->wtFlags & TERM_DYNAMIC ){
78932 sqlite3ExprDelete(db, a->pExpr);
78933 }
 
 
 
 
 
78934 }
78935 if( pWC->a!=pWC->aStatic ){
78936 sqlite3DbFree(db, pWC->a);
78937 }
78938 }
@@ -79000,10 +79660,11 @@
79000 ** In the previous sentence and in the diagram, "slot[]" refers to
79001 ** the WhereClause.a[] array. The slot[] array grows as needed to contain
79002 ** all terms of the WHERE clause.
79003 */
79004 static void whereSplit(WhereClause *pWC, Expr *pExpr, int op){
 
79005 if( pExpr==0 ) return;
79006 if( pExpr->op!=op ){
79007 whereClauseInsert(pWC, pExpr, 0);
79008 }else{
79009 whereSplit(pWC, pExpr->pLeft, op);
@@ -79018,11 +79679,11 @@
79018
79019 /*
79020 ** Return the bitmask for the given cursor number. Return 0 if
79021 ** iCursor is not in the set.
79022 */
79023 static Bitmask getMask(ExprMaskSet *pMaskSet, int iCursor){
79024 int i;
79025 for(i=0; i<pMaskSet->n; i++){
79026 if( pMaskSet->ix[i]==iCursor ){
79027 return ((Bitmask)1)<<i;
79028 }
@@ -79036,11 +79697,11 @@
79036 ** There is one cursor per table in the FROM clause. The number of
79037 ** tables in the FROM clause is limited by a test early in the
79038 ** sqlite3WhereBegin() routine. So we know that the pMaskSet->ix[]
79039 ** array will never overflow.
79040 */
79041 static void createMask(ExprMaskSet *pMaskSet, int iCursor){
79042 assert( pMaskSet->n < ArraySize(pMaskSet->ix) );
79043 pMaskSet->ix[pMaskSet->n++] = iCursor;
79044 }
79045
79046 /*
@@ -79055,13 +79716,13 @@
79055 ** sets their opcodes to TK_COLUMN and their Expr.iTable fields to
79056 ** the VDBE cursor number of the table. This routine just has to
79057 ** translate the cursor numbers into bitmask values and OR all
79058 ** the bitmasks together.
79059 */
79060 static Bitmask exprListTableUsage(ExprMaskSet*, ExprList*);
79061 static Bitmask exprSelectTableUsage(ExprMaskSet*, Select*);
79062 static Bitmask exprTableUsage(ExprMaskSet *pMaskSet, Expr *p){
79063 Bitmask mask = 0;
79064 if( p==0 ) return 0;
79065 if( p->op==TK_COLUMN ){
79066 mask = getMask(pMaskSet, p->iTable);
79067 return mask;
@@ -79070,21 +79731,21 @@
79070 mask |= exprTableUsage(pMaskSet, p->pLeft);
79071 mask |= exprListTableUsage(pMaskSet, p->pList);
79072 mask |= exprSelectTableUsage(pMaskSet, p->pSelect);
79073 return mask;
79074 }
79075 static Bitmask exprListTableUsage(ExprMaskSet *pMaskSet, ExprList *pList){
79076 int i;
79077 Bitmask mask = 0;
79078 if( pList ){
79079 for(i=0; i<pList->nExpr; i++){
79080 mask |= exprTableUsage(pMaskSet, pList->a[i].pExpr);
79081 }
79082 }
79083 return mask;
79084 }
79085 static Bitmask exprSelectTableUsage(ExprMaskSet *pMaskSet, Select *pS){
79086 Bitmask mask = 0;
79087 while( pS ){
79088 mask |= exprListTableUsage(pMaskSet, pS->pEList);
79089 mask |= exprListTableUsage(pMaskSet, pS->pGroupBy);
79090 mask |= exprListTableUsage(pMaskSet, pS->pOrderBy);
@@ -79153,18 +79814,15 @@
79153 assert( allowedOp(op) );
79154 if( op==TK_IN ){
79155 c = WO_IN;
79156 }else if( op==TK_ISNULL ){
79157 c = WO_ISNULL;
79158 }else if( op==TK_OR ){
79159 c = WO_OR;
79160 }else{
79161 assert( (WO_EQ<<(op-TK_EQ)) < 0x7fff );
79162 c = (u16)(WO_EQ<<(op-TK_EQ));
79163 }
79164 assert( op!=TK_ISNULL || c==WO_ISNULL );
79165 assert( op!=TK_OR || c==WO_OR );
79166 assert( op!=TK_IN || c==WO_IN );
79167 assert( op!=TK_EQ || c==WO_EQ );
79168 assert( op!=TK_LT || c==WO_LT );
79169 assert( op!=TK_LE || c==WO_LE );
79170 assert( op!=TK_GT || c==WO_GT );
@@ -79191,11 +79849,11 @@
79191 assert( iCur>=0 );
79192 op &= WO_ALL;
79193 for(pTerm=pWC->a, k=pWC->nTerm; k; k--, pTerm++){
79194 if( pTerm->leftCursor==iCur
79195 && (pTerm->prereqRight & notReady)==0
79196 && pTerm->leftColumn==iColumn
79197 && (pTerm->eOperator & op)!=0
79198 ){
79199 if( pIdx && pTerm->eOperator!=WO_ISNULL ){
79200 Expr *pX = pTerm->pExpr;
79201 CollSeq *pColl;
@@ -79210,18 +79868,16 @@
79210 ** it to be useful for optimising expression pX. Store this
79211 ** value in variable pColl.
79212 */
79213 assert(pX->pLeft);
79214 pColl = sqlite3BinaryCompareCollSeq(pParse, pX->pLeft, pX->pRight);
79215 if( !pColl ){
79216 pColl = pParse->db->pDfltColl;
79217 }
79218
79219 for(j=0; pIdx->aiColumn[j]!=iColumn; j++){
79220 if( NEVER(j>=pIdx->nColumn) ) return 0;
79221 }
79222 if( sqlite3StrICmp(pColl->zName, pIdx->azColl[j]) ) continue;
79223 }
79224 return pTerm;
79225 }
79226 }
79227 return 0;
@@ -79259,28 +79915,28 @@
79259 Expr *pExpr, /* Test this expression */
79260 int *pnPattern, /* Number of non-wildcard prefix characters */
79261 int *pisComplete, /* True if the only wildcard is % in the last character */
79262 int *pnoCase /* True if uppercase is equivalent to lowercase */
79263 ){
79264 const char *z;
79265 Expr *pRight, *pLeft;
79266 ExprList *pList;
79267 int c, cnt;
79268 char wc[3];
79269 CollSeq *pColl;
79270 sqlite3 *db = pParse->db;
 
79271
79272 if( !sqlite3IsLikeFunction(db, pExpr, pnoCase, wc) ){
79273 return 0;
79274 }
79275 #ifdef SQLITE_EBCDIC
79276 if( *pnoCase ) return 0;
79277 #endif
79278 pList = pExpr->pList;
79279 pRight = pList->a[0].pExpr;
79280 if( pRight->op!=TK_STRING
79281 && (pRight->op!=TK_REGISTER || pRight->iColumn!=TK_STRING) ){
79282 return 0;
79283 }
79284 pLeft = pList->a[1].pExpr;
79285 if( pLeft->op!=TK_COLUMN ){
79286 return 0;
@@ -79299,11 +79955,11 @@
79299 z = (char *)pRight->token.z;
79300 cnt = 0;
79301 if( z ){
79302 while( (c=z[cnt])!=0 && c!=wc[0] && c!=wc[1] && c!=wc[2] ){ cnt++; }
79303 }
79304 if( cnt==0 || 255==(u8)z[cnt] ){
79305 return 0;
79306 }
79307 *pisComplete = z[cnt]==wc[0] && z[cnt+1]==0;
79308 *pnPattern = cnt;
79309 return 1;
@@ -79351,124 +80007,312 @@
79351 pDerived->iRightJoinTable = pBase->iRightJoinTable;
79352 }
79353
79354 #if !defined(SQLITE_OMIT_OR_OPTIMIZATION) && !defined(SQLITE_OMIT_SUBQUERY)
79355 /*
79356 ** Return TRUE if the given term of an OR clause can be converted
79357 ** into an IN clause. The iCursor and iColumn define the left-hand
79358 ** side of the IN clause.
79359 **
79360 ** The context is that we have multiple OR-connected equality terms
79361 ** like this:
79362 **
79363 ** a=<expr1> OR a=<expr2> OR b=<expr3> OR ...
79364 **
79365 ** The pOrTerm input to this routine corresponds to a single term of
79366 ** this OR clause. In order for the term to be a candidate for
79367 ** conversion to an IN operator, the following must be true:
79368 **
79369 ** * The left-hand side of the term must be the column which
79370 ** is identified by iCursor and iColumn.
79371 **
79372 ** * If the right-hand side is also a column, then the affinities
79373 ** of both right and left sides must be such that no type
79374 ** conversions are required on the right. (Ticket #2249)
79375 **
79376 ** If both of these conditions are true, then return true. Otherwise
79377 ** return false.
79378 */
79379 static int orTermIsOptCandidate(WhereTerm *pOrTerm, int iCursor, int iColumn){
79380 int affLeft, affRight;
79381 assert( pOrTerm->eOperator==WO_EQ );
79382 if( pOrTerm->leftCursor!=iCursor ){
79383 return 0;
79384 }
79385 if( pOrTerm->leftColumn!=iColumn ){
79386 return 0;
79387 }
79388 affRight = sqlite3ExprAffinity(pOrTerm->pExpr->pRight);
79389 if( affRight==0 ){
79390 return 1;
79391 }
79392 affLeft = sqlite3ExprAffinity(pOrTerm->pExpr->pLeft);
79393 if( affRight!=affLeft ){
79394 return 0;
79395 }
79396 return 1;
79397 }
79398
79399 /*
79400 ** Return true if the given term of an OR clause can be ignored during
79401 ** a check to make sure all OR terms are candidates for optimization.
79402 ** In other words, return true if a call to the orTermIsOptCandidate()
79403 ** above returned false but it is not necessary to disqualify the
79404 ** optimization.
79405 **
79406 ** Suppose the original OR phrase was this:
79407 **
79408 ** a=4 OR a=11 OR a=b
79409 **
79410 ** During analysis, the third term gets flipped around and duplicate
79411 ** so that we are left with this:
79412 **
79413 ** a=4 OR a=11 OR a=b OR b=a
79414 **
79415 ** Since the last two terms are duplicates, only one of them
79416 ** has to qualify in order for the whole phrase to qualify. When
79417 ** this routine is called, we know that pOrTerm did not qualify.
79418 ** This routine merely checks to see if pOrTerm has a duplicate that
79419 ** might qualify. If there is a duplicate that has not yet been
79420 ** disqualified, then return true. If there are no duplicates, or
79421 ** the duplicate has also been disqualified, return false.
79422 */
79423 static int orTermHasOkDuplicate(WhereClause *pOr, WhereTerm *pOrTerm){
79424 if( pOrTerm->wtFlags & TERM_COPIED ){
79425 /* This is the original term. The duplicate is to the left had
79426 ** has not yet been analyzed and thus has not yet been disqualified. */
79427 return 1;
79428 }
79429 if( (pOrTerm->wtFlags & TERM_VIRTUAL)!=0
79430 && (pOr->a[pOrTerm->iParent].wtFlags & TERM_OR_OK)!=0 ){
79431 /* This is a duplicate term. The original qualified so this one
79432 ** does not have to. */
79433 return 1;
79434 }
79435 /* This is either a singleton term or else it is a duplicate for
79436 ** which the original did not qualify. Either way we are done for. */
79437 return 0;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
79438 }
79439 #endif /* !SQLITE_OMIT_OR_OPTIMIZATION && !SQLITE_OMIT_SUBQUERY */
 
79440
79441 /*
79442 ** The input to this routine is an WhereTerm structure with only the
79443 ** "pExpr" field filled in. The job of this routine is to analyze the
79444 ** subexpression and populate all the other fields of the WhereTerm
79445 ** structure.
79446 **
79447 ** If the expression is of the form "<expr> <op> X" it gets commuted
79448 ** to the standard form of "X <op> <expr>". If the expression is of
79449 ** the form "X <op> Y" where both X and Y are columns, then the original
79450 ** expression is unchanged and a new virtual expression of the form
79451 ** "Y <op> X" is added to the WHERE clause and analyzed separately.
 
 
 
 
 
 
79452 */
79453 static void exprAnalyze(
79454 SrcList *pSrc, /* the FROM clause */
79455 WhereClause *pWC, /* the WHERE clause */
79456 int idxTerm /* Index of the term to be analyzed */
79457 ){
79458 WhereTerm *pTerm;
79459 ExprMaskSet *pMaskSet;
79460 Expr *pExpr;
79461 Bitmask prereqLeft;
79462 Bitmask prereqAll;
79463 Bitmask extraRight = 0;
79464 int nPattern;
79465 int isComplete;
79466 int noCase;
79467 int op;
79468 Parse *pParse = pWC->pParse;
79469 sqlite3 *db = pParse->db;
79470
79471 if( db->mallocFailed ){
79472 return;
79473 }
79474 pTerm = &pWC->a[idxTerm];
@@ -79499,11 +80343,11 @@
79499 if( allowedOp(op) && (pTerm->prereqRight & prereqLeft)==0 ){
79500 Expr *pLeft = pExpr->pLeft;
79501 Expr *pRight = pExpr->pRight;
79502 if( pLeft->op==TK_COLUMN ){
79503 pTerm->leftCursor = pLeft->iTable;
79504 pTerm->leftColumn = pLeft->iColumn;
79505 pTerm->eOperator = operatorMask(op);
79506 }
79507 if( pRight && pRight->op==TK_COLUMN ){
79508 WhereTerm *pNew;
79509 Expr *pDup;
@@ -79526,22 +80370,34 @@
79526 pNew = pTerm;
79527 }
79528 exprCommute(pParse, pDup);
79529 pLeft = pDup->pLeft;
79530 pNew->leftCursor = pLeft->iTable;
79531 pNew->leftColumn = pLeft->iColumn;
79532 pNew->prereqRight = prereqLeft;
79533 pNew->prereqAll = prereqAll;
79534 pNew->eOperator = operatorMask(pDup->op);
79535 }
79536 }
79537
79538 #ifndef SQLITE_OMIT_BETWEEN_OPTIMIZATION
79539 /* If a term is the BETWEEN operator, create two new virtual terms
79540 ** that define the range that the BETWEEN implements.
 
 
 
 
 
 
 
 
 
 
 
 
79541 */
79542 else if( pExpr->op==TK_BETWEEN ){
79543 ExprList *pList = pExpr->pList;
79544 int i;
79545 static const u8 ops[] = {TK_GE, TK_LE};
79546 assert( pList!=0 );
79547 assert( pList->nExpr==2 );
@@ -79559,83 +80415,16 @@
79559 pTerm->nChild = 2;
79560 }
79561 #endif /* SQLITE_OMIT_BETWEEN_OPTIMIZATION */
79562
79563 #if !defined(SQLITE_OMIT_OR_OPTIMIZATION) && !defined(SQLITE_OMIT_SUBQUERY)
79564 /* Attempt to convert OR-connected terms into an IN operator so that
79565 ** they can make use of indices. Example:
79566 **
79567 ** x = expr1 OR expr2 = x OR x = expr3
79568 **
79569 ** is converted into
79570 **
79571 ** x IN (expr1,expr2,expr3)
79572 **
79573 ** This optimization must be omitted if OMIT_SUBQUERY is defined because
79574 ** the compiler for the the IN operator is part of sub-queries.
79575 */
79576 else if( pExpr->op==TK_OR ){
79577 int ok;
79578 int i, j;
79579 int iColumn, iCursor;
79580 WhereClause sOr;
79581 WhereTerm *pOrTerm;
79582
79583 assert( (pTerm->wtFlags & TERM_DYNAMIC)==0 );
79584 whereClauseInit(&sOr, pWC->pParse, pMaskSet);
79585 whereSplit(&sOr, pExpr, TK_OR);
79586 exprAnalyzeAll(pSrc, &sOr);
79587 assert( sOr.nTerm>=2 );
79588 j = 0;
79589 if( db->mallocFailed ) goto or_not_possible;
79590 do{
79591 assert( j<sOr.nTerm );
79592 iColumn = sOr.a[j].leftColumn;
79593 iCursor = sOr.a[j].leftCursor;
79594 ok = iCursor>=0;
79595 for(i=sOr.nTerm-1, pOrTerm=sOr.a; i>=0 && ok; i--, pOrTerm++){
79596 if( pOrTerm->eOperator!=WO_EQ ){
79597 goto or_not_possible;
79598 }
79599 if( orTermIsOptCandidate(pOrTerm, iCursor, iColumn) ){
79600 pOrTerm->wtFlags |= TERM_OR_OK;
79601 }else if( orTermHasOkDuplicate(&sOr, pOrTerm) ){
79602 pOrTerm->wtFlags &= ~TERM_OR_OK;
79603 }else{
79604 ok = 0;
79605 }
79606 }
79607 }while( !ok && (sOr.a[j++].wtFlags & TERM_COPIED)!=0 && j<2 );
79608 if( ok ){
79609 ExprList *pList = 0;
79610 Expr *pNew, *pDup;
79611 Expr *pLeft = 0;
79612 for(i=sOr.nTerm-1, pOrTerm=sOr.a; i>=0; i--, pOrTerm++){
79613 if( (pOrTerm->wtFlags & TERM_OR_OK)==0 ) continue;
79614 pDup = sqlite3ExprDup(db, pOrTerm->pExpr->pRight);
79615 pList = sqlite3ExprListAppend(pWC->pParse, pList, pDup, 0);
79616 pLeft = pOrTerm->pExpr->pLeft;
79617 }
79618 assert( pLeft!=0 );
79619 pDup = sqlite3ExprDup(db, pLeft);
79620 pNew = sqlite3Expr(db, TK_IN, pDup, 0, 0);
79621 if( pNew ){
79622 int idxNew;
79623 transferJoinMarkings(pNew, pExpr);
79624 pNew->pList = pList;
79625 idxNew = whereClauseInsert(pWC, pNew, TERM_VIRTUAL|TERM_DYNAMIC);
79626 testcase( idxNew==0 );
79627 exprAnalyze(pSrc, pWC, idxNew);
79628 pTerm = &pWC->a[idxTerm];
79629 pWC->a[idxNew].iParent = idxTerm;
79630 pTerm->nChild = 1;
79631 }else{
79632 sqlite3ExprListDelete(db, pList);
79633 }
79634 }
79635 or_not_possible:
79636 whereClauseClear(&sOr);
79637 }
79638 #endif /* SQLITE_OMIT_OR_OPTIMIZATION */
79639
79640 #ifndef SQLITE_OMIT_LIKE_OPTIMIZATION
79641 /* Add constraints to reduce the search space on a LIKE or GLOB
@@ -79646,11 +80435,12 @@
79646 ** x>='abc' AND x<'abd' AND x LIKE 'abc%'
79647 **
79648 ** The last character of the prefix "abc" is incremented to form the
79649 ** termination condition "abd".
79650 */
79651 if( isLikeOrGlob(pParse, pExpr, &nPattern, &isComplete, &noCase) ){
 
79652 Expr *pLeft, *pRight;
79653 Expr *pStr1, *pStr2;
79654 Expr *pNewExpr1, *pNewExpr2;
79655 int idxNew1, idxNew2;
79656
@@ -79714,11 +80504,11 @@
79714 idxNew = whereClauseInsert(pWC, pNewExpr, TERM_VIRTUAL|TERM_DYNAMIC);
79715 testcase( idxNew==0 );
79716 pNewTerm = &pWC->a[idxNew];
79717 pNewTerm->prereqRight = prereqExpr;
79718 pNewTerm->leftCursor = pLeft->iTable;
79719 pNewTerm->leftColumn = pLeft->iColumn;
79720 pNewTerm->eOperator = WO_MATCH;
79721 pNewTerm->iParent = idxTerm;
79722 pTerm = &pWC->a[idxTerm];
79723 pTerm->nChild = 1;
79724 pTerm->wtFlags |= TERM_COPIED;
@@ -79737,11 +80527,11 @@
79737 ** Return TRUE if any of the expressions in pList->a[iFirst...] contain
79738 ** a reference to any table other than the iBase table.
79739 */
79740 static int referencesOtherTables(
79741 ExprList *pList, /* Search expressions in ths list */
79742 ExprMaskSet *pMaskSet, /* Mapping from tables to bitmaps */
79743 int iFirst, /* Be searching with the iFirst-th expression */
79744 int iBase /* Ignore references to this table */
79745 ){
79746 Bitmask allowed = ~getMask(pMaskSet, iBase);
79747 while( iFirst<pList->nExpr ){
@@ -79772,11 +80562,11 @@
79772 ** set to 1 if the ORDER BY clause is all DESC and it is set to 0 if
79773 ** the ORDER BY clause is all ASC.
79774 */
79775 static int isSortingIndex(
79776 Parse *pParse, /* Parsing context */
79777 ExprMaskSet *pMaskSet, /* Mapping from table indices to bitmaps */
79778 Index *pIdx, /* The index we are testing */
79779 int base, /* Cursor number for the table to be sorted */
79780 ExprList *pOrderBy, /* The ORDER BY clause */
79781 int nEqCol, /* Number of index columns with == constraints */
79782 int *pbRev /* Set to 1 if ORDER BY is DESC */
@@ -79895,11 +80685,11 @@
79895 ** true for reverse ROWID and false for forward ROWID order.
79896 */
79897 static int sortableByRowid(
79898 int base, /* Cursor number for table to be sorted */
79899 ExprList *pOrderBy, /* The ORDER BY clause */
79900 ExprMaskSet *pMaskSet, /* Mapping from tables to bitmaps */
79901 int *pbRev /* Set to 1 if ORDER BY is DESC */
79902 ){
79903 Expr *p;
79904
79905 assert( pOrderBy!=0 );
@@ -80076,11 +80866,11 @@
80076 if( pTerm->leftCursor != pSrc->iCursor ) continue;
80077 assert( (pTerm->eOperator&(pTerm->eOperator-1))==0 );
80078 testcase( pTerm->eOperator==WO_IN );
80079 testcase( pTerm->eOperator==WO_ISNULL );
80080 if( pTerm->eOperator & (WO_IN|WO_ISNULL) ) continue;
80081 pIdxCons[j].iColumn = pTerm->leftColumn;
80082 pIdxCons[j].iTermOffset = i;
80083 pIdxCons[j].op = (u8)pTerm->eOperator;
80084 /* The direct assignment in the previous line is possible only because
80085 ** the WO_ and SQLITE_INDEX_CONSTRAINT_ codes are identical. The
80086 ** following asserts verify this fact. */
@@ -80193,16 +80983,16 @@
80193 return pIdxInfo->estimatedCost;
80194 }
80195 #endif /* SQLITE_OMIT_VIRTUALTABLE */
80196
80197 /*
80198 ** Find the best index for accessing a particular table. Return a pointer
80199 ** to the index, flags that describe how the index should be used, the
80200 ** number of equality constraints, and the "cost" for this index.
80201 **
80202 ** The lowest cost index wins. The cost is an estimate of the amount of
80203 ** CPU and disk I/O need to process the request using the selected index.
80204 ** Factors that influence cost include:
80205 **
80206 ** * The estimated number of rows that will be retrieved. (The
80207 ** fewer the better.)
80208 **
@@ -80210,45 +81000,41 @@
80210 **
80211 ** * Whether or not there must be separate lookups in the
80212 ** index and in the main table.
80213 **
80214 ** If there was an INDEXED BY clause attached to the table in the SELECT
80215 ** statement, then this function only considers strategies using the
80216 ** named index. If one cannot be found, then the returned cost is
80217 ** SQLITE_BIG_DBL. If a strategy can be found that uses the named index,
80218 ** then the cost is calculated in the usual way.
80219 **
80220 ** If a NOT INDEXED clause was attached to the table in the SELECT
80221 ** statement, then no indexes are considered. However, the selected
80222 ** stategy may still take advantage of the tables built-in rowid
80223 ** index.
80224 */
80225 static double bestIndex(
80226 Parse *pParse, /* The parsing context */
80227 WhereClause *pWC, /* The WHERE clause */
80228 struct SrcList_item *pSrc, /* The FROM clause term to search */
80229 Bitmask notReady, /* Mask of cursors that are not available */
80230 ExprList *pOrderBy, /* The order by clause */
80231 Index **ppIndex, /* Make *ppIndex point to the best index */
80232 int *pWsFlags, /* Put wsFlags describing scan strategy here */
80233 int *pnEq /* Put the number of == or IN constraints here */
80234 ){
80235 WhereTerm *pTerm;
80236 Index *bestIdx = 0; /* Index that gives the lowest cost */
80237 double lowestCost; /* The cost of using bestIdx */
80238 int bestWsFlags = 0; /* Flags associated with bestIdx */
80239 int bestNEq = 0; /* Best value for nEq */
80240 int iCur = pSrc->iCursor; /* The cursor of the table to be accessed */
80241 Index *pProbe; /* An index we are evaluating */
80242 int rev; /* True to scan in reverse order */
80243 int wsFlags; /* Flags associated with pProbe */
80244 int nEq; /* Number of == or IN constraints */
80245 int eqTermMask; /* Mask of valid equality operators */
80246 double cost; /* Cost of using pProbe */
 
 
 
80247
80248 WHERETRACE(("bestIndex: tbl=%s notReady=%llx\n", pSrc->pTab->zName,notReady));
80249 lowestCost = SQLITE_BIG_DBL;
80250 pProbe = pSrc->pTab->pIndex;
80251 if( pSrc->notIndexed ){
80252 pProbe = 0;
80253 }
80254
@@ -80256,47 +81042,48 @@
80256 ** clause that refer to the ROWID, then we will never be able to do
80257 ** anything other than a full table scan on this table. We might as
80258 ** well put it first in the join order. That way, perhaps it can be
80259 ** referenced by other tables in the join.
80260 */
 
80261 if( pProbe==0 &&
80262 findTerm(pWC, iCur, -1, 0, WO_EQ|WO_IN|WO_LT|WO_LE|WO_GT|WO_GE,0)==0 &&
80263 (pOrderBy==0 || !sortableByRowid(iCur, pOrderBy, pWC->pMaskSet, &rev)) ){
80264 *pWsFlags = 0;
80265 *ppIndex = 0;
80266 *pnEq = 0;
80267 return 0.0;
80268 }
 
80269
80270 /* Check for a rowid=EXPR or rowid IN (...) constraints. If there was
80271 ** an INDEXED BY clause attached to this table, skip this step.
80272 */
80273 if( !pSrc->pIndex ){
80274 pTerm = findTerm(pWC, iCur, -1, notReady, WO_EQ|WO_IN, 0);
80275 if( pTerm ){
80276 Expr *pExpr;
80277 *ppIndex = 0;
80278 bestWsFlags = WHERE_ROWID_EQ;
80279 if( pTerm->eOperator & WO_EQ ){
80280 /* Rowid== is always the best pick. Look no further. Because only
80281 ** a single row is generated, output is always in sorted order */
80282 *pWsFlags = WHERE_ROWID_EQ | WHERE_UNIQUE;
80283 *pnEq = 1;
80284 WHERETRACE(("... best is rowid\n"));
80285 return 0.0;
 
 
80286 }else if( (pExpr = pTerm->pExpr)->pList!=0 ){
80287 /* Rowid IN (LIST): cost is NlogN where N is the number of list
80288 ** elements. */
80289 lowestCost = pExpr->pList->nExpr;
80290 lowestCost *= estLog(lowestCost);
80291 }else{
80292 /* Rowid IN (SELECT): cost is NlogN where N is the number of rows
80293 ** in the result of the inner select. We have no way to estimate
80294 ** that value so make a wild guess. */
80295 lowestCost = 200;
 
80296 }
80297 WHERETRACE(("... rowid IN cost: %.9g\n", lowestCost));
80298 }
80299
80300 /* Estimate the cost of a table scan. If we do not know how many
80301 ** entries are in the table, use 1 million as a guess.
80302 */
@@ -80308,20 +81095,21 @@
80308 */
80309 pTerm = findTerm(pWC, iCur, -1, notReady, WO_LT|WO_LE|WO_GT|WO_GE, 0);
80310 if( pTerm ){
80311 if( findTerm(pWC, iCur, -1, notReady, WO_LT|WO_LE, 0) ){
80312 wsFlags |= WHERE_TOP_LIMIT;
80313 cost /= 3; /* Guess that rowid<EXPR eliminates two-thirds or rows */
80314 }
80315 if( findTerm(pWC, iCur, -1, notReady, WO_GT|WO_GE, 0) ){
80316 wsFlags |= WHERE_BTM_LIMIT;
80317 cost /= 3; /* Guess that rowid>EXPR eliminates two-thirds of rows */
80318 }
80319 WHERETRACE(("... rowid range reduces cost to %.9g\n", cost));
80320 }else{
80321 wsFlags = 0;
80322 }
 
80323
80324 /* If the table scan does not satisfy the ORDER BY clause, increase
80325 ** the cost by NlogN to cover the expense of sorting. */
80326 if( pOrderBy ){
80327 if( sortableByRowid(iCur, pOrderBy, pWC->pMaskSet, &rev) ){
@@ -80332,16 +81120,67 @@
80332 }else{
80333 cost += cost*estLog(cost);
80334 WHERETRACE(("... sorting increases cost to %.9g\n", cost));
80335 }
80336 }
80337 if( cost<lowestCost ){
80338 lowestCost = cost;
80339 bestWsFlags = wsFlags;
 
80340 }
80341 }
80342
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
80343 /* If the pSrc table is the right table of a LEFT JOIN then we may not
80344 ** use an index to satisfy IS NULL constraints on that table. This is
80345 ** because columns might end up being NULL if the table does not match -
80346 ** a circumstance which the index cannot help us discover. Ticket #2177.
80347 */
@@ -80355,11 +81194,10 @@
80355 */
80356 if( pSrc->pIndex ){
80357 pProbe = pSrc->pIndex;
80358 }
80359 for(; pProbe; pProbe=(pSrc->pIndex ? 0 : pProbe->pNext)){
80360 int i; /* Loop counter */
80361 double inMultiplier = 1;
80362
80363 WHERETRACE(("... index %s:\n", pProbe->zName));
80364
80365 /* Count the number of columns in the index that are satisfied
@@ -80379,11 +81217,12 @@
80379 }else if( ALWAYS(pExpr->pList) ){
80380 inMultiplier *= pExpr->pList->nExpr + 1;
80381 }
80382 }
80383 }
80384 cost = pProbe->aiRowEst[i] * inMultiplier * estLog(inMultiplier);
 
80385 nEq = i;
80386 if( pProbe->onError!=OE_None && (wsFlags & WHERE_COLUMN_IN)==0
80387 && nEq==pProbe->nColumn ){
80388 wsFlags |= WHERE_UNIQUE;
80389 }
@@ -80397,14 +81236,16 @@
80397 if( pTerm ){
80398 wsFlags |= WHERE_COLUMN_RANGE;
80399 if( findTerm(pWC, iCur, j, notReady, WO_LT|WO_LE, pProbe) ){
80400 wsFlags |= WHERE_TOP_LIMIT;
80401 cost /= 3;
 
80402 }
80403 if( findTerm(pWC, iCur, j, notReady, WO_GT|WO_GE, pProbe) ){
80404 wsFlags |= WHERE_BTM_LIMIT;
80405 cost /= 3;
 
80406 }
80407 WHERETRACE(("...... range reduces cost to %.9g\n", cost));
80408 }
80409 }
80410
@@ -80446,26 +81287,27 @@
80446 }
80447 }
80448
80449 /* If this index has achieved the lowest cost so far, then use it.
80450 */
80451 if( wsFlags && cost < lowestCost ){
80452 bestIdx = pProbe;
80453 lowestCost = cost;
80454 bestWsFlags = wsFlags;
80455 bestNEq = nEq;
 
 
80456 }
80457 }
80458
80459 /* Report the best result
80460 */
80461 *ppIndex = bestIdx;
80462 WHERETRACE(("best index is %s, cost=%.9g, wsFlags=%x, nEq=%d\n",
80463 bestIdx ? bestIdx->zName : "(none)", lowestCost, bestWsFlags, bestNEq));
80464 *pWsFlags = bestWsFlags | eqTermMask;
80465 *pnEq = bestNEq;
80466 return lowestCost;
80467 }
80468
80469
80470 /*
80471 ** Disable a term in the WHERE clause. Except, do not disable the term
@@ -80557,28 +81399,30 @@
80557 iReg = iTarget;
80558 eType = sqlite3FindInIndex(pParse, pX, 0);
80559 iTab = pX->iTable;
80560 sqlite3VdbeAddOp2(v, OP_Rewind, iTab, 0);
80561 VdbeComment((v, "%.*s", pX->span.n, pX->span.z));
80562 if( pLevel->nIn==0 ){
 
80563 pLevel->addrNxt = sqlite3VdbeMakeLabel(v);
80564 }
80565 pLevel->nIn++;
80566 pLevel->aInLoop = sqlite3DbReallocOrFree(pParse->db, pLevel->aInLoop,
80567 sizeof(pLevel->aInLoop[0])*pLevel->nIn);
80568 pIn = pLevel->aInLoop;
 
80569 if( pIn ){
80570 pIn += pLevel->nIn - 1;
80571 pIn->iCur = iTab;
80572 if( eType==IN_INDEX_ROWID ){
80573 pIn->addrInTop = sqlite3VdbeAddOp2(v, OP_Rowid, iTab, iReg);
80574 }else{
80575 pIn->addrInTop = sqlite3VdbeAddOp3(v, OP_Column, iTab, 0, iReg);
80576 }
80577 sqlite3VdbeAddOp1(v, OP_IsNull, iReg);
80578 }else{
80579 pLevel->nIn = 0;
80580 }
80581 #endif
80582 }
80583 disableTerm(pLevel, pTerm);
80584 return iReg;
@@ -80591,20 +81435,20 @@
80591 ** For example, consider table t1(a,b,c,d,e,f) with index i1(a,b,c).
80592 ** Suppose the WHERE clause is this: a==5 AND b IN (1,2,3) AND c>5 AND c<10
80593 ** The index has as many as three equality constraints, but in this
80594 ** example, the third "c" value is an inequality. So only two
80595 ** constraints are coded. This routine will generate code to evaluate
80596 ** a==5 and b IN (1,2,3). The current values for a and b will be left
80597 ** on the stack - a is the deepest and b the shallowest.
80598 **
80599 ** In the example above nEq==2. But this subroutine works for any value
80600 ** of nEq including 0. If nEq==0, this routine is nearly a no-op.
80601 ** The only thing it does is allocate the pLevel->iMem memory cell.
80602 **
80603 ** This routine always allocates at least one memory cell and puts
80604 ** the address of that memory cell in pLevel->iMem. The code that
80605 ** calls this routine will use pLevel->iMem to store the termination
80606 ** key value of the loop. If one or more IN operators appear, then
80607 ** this routine allocates an additional nEq memory cells for internal
80608 ** use.
80609 */
80610 static int codeAllEqualityTerms(
@@ -80612,48 +81456,649 @@
80612 WhereLevel *pLevel, /* Which nested loop of the FROM we are coding */
80613 WhereClause *pWC, /* The WHERE clause */
80614 Bitmask notReady, /* Which parts of FROM have not yet been coded */
80615 int nExtraReg /* Number of extra registers to allocate */
80616 ){
80617 int nEq = pLevel->nEq; /* The number of == or IN constraints to code */
80618 Vdbe *v = pParse->pVdbe; /* The virtual machine under construction */
80619 Index *pIdx = pLevel->pIdx; /* The index being used for this loop */
80620 int iCur = pLevel->iTabCur; /* The cursor of the table */
80621 WhereTerm *pTerm; /* A single constraint term */
80622 int j; /* Loop counter */
80623 int regBase; /* Base register */
 
 
 
 
 
80624
80625 /* Figure out how many memory cells we will need then allocate them.
80626 ** We always need at least one used to store the loop terminator
80627 ** value. If there are IN operators we'll need one for each == or
80628 ** IN constraint.
80629 */
80630 pLevel->iMem = pParse->nMem + 1;
80631 regBase = pParse->nMem + 2;
80632 pParse->nMem += pLevel->nEq + 2 + nExtraReg;
80633
80634 /* Evaluate the equality constraints
80635 */
80636 assert( pIdx->nColumn>=nEq );
80637 for(j=0; j<nEq; j++){
80638 int r1;
80639 int k = pIdx->aiColumn[j];
80640 pTerm = findTerm(pWC, iCur, k, notReady, pLevel->wsFlags, pIdx);
80641 if( NEVER(pTerm==0) ) break;
80642 assert( (pTerm->wtFlags & TERM_CODED)==0 );
80643 r1 = codeEqualityTerm(pParse, pTerm, pLevel, regBase+j);
80644 if( r1!=regBase+j ){
80645 sqlite3VdbeAddOp2(v, OP_SCopy, r1, regBase+j);
 
 
 
 
 
80646 }
80647 testcase( pTerm->eOperator & WO_ISNULL );
80648 testcase( pTerm->eOperator & WO_IN );
80649 if( (pTerm->eOperator & (WO_ISNULL|WO_IN))==0 ){
80650 sqlite3VdbeAddOp2(v, OP_IsNull, regBase+j, pLevel->addrBrk);
80651 }
80652 }
80653 return regBase;
80654 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
80655
80656 #if defined(SQLITE_TEST)
80657 /*
80658 ** The following variable holds a text description of query plan generated
80659 ** by the most recent call to sqlite3WhereBegin(). Each call to WhereBegin
@@ -80673,14 +82118,18 @@
80673 if( pWInfo ){
80674 int i;
80675 for(i=0; i<pWInfo->nLevel; i++){
80676 sqlite3_index_info *pInfo = pWInfo->a[i].pIdxInfo;
80677 if( pInfo ){
80678 assert( pInfo->needToFreeIdxStr==0 );
 
 
 
80679 sqlite3DbFree(db, pInfo);
80680 }
80681 }
 
80682 sqlite3DbFree(db, pWInfo);
80683 }
80684 }
80685
80686
@@ -80775,24 +82224,23 @@
80775 SQLITE_PRIVATE WhereInfo *sqlite3WhereBegin(
80776 Parse *pParse, /* The parser context */
80777 SrcList *pTabList, /* A list of all tables to be scanned */
80778 Expr *pWhere, /* The WHERE clause */
80779 ExprList **ppOrderBy, /* An ORDER BY clause, or NULL */
80780 u8 wctrlFlags /* One of the WHERE_* flags defined in sqliteInt.h */
 
80781 ){
80782 int i; /* Loop counter */
80783 WhereInfo *pWInfo; /* Will become the return value of this function */
80784 Vdbe *v = pParse->pVdbe; /* The virtual database engine */
80785 int addrBrk, addrCont = 0; /* Addresses used during code generation */
80786 Bitmask notReady; /* Cursors that are not yet positioned */
80787 WhereTerm *pTerm; /* A single term in the WHERE clause */
80788 ExprMaskSet maskSet; /* The expression mask set */
80789 WhereClause wc; /* The WHERE clause is divided into these terms */
80790 struct SrcList_item *pTabItem; /* A single entry from pTabList */
80791 WhereLevel *pLevel; /* A single level in the pWInfo list */
80792 int iFrom; /* First unused FROM clause element */
80793 int andFlags; /* AND-ed combination of all wc.a[].wtFlags */
80794 sqlite3 *db; /* Database connection */
80795 ExprList *pOrderBy = 0;
80796
80797 /* The number of tables in the FROM clause is limited by the number of
80798 ** bits in a Bitmask
@@ -80804,32 +82252,40 @@
80804
80805 if( ppOrderBy ){
80806 pOrderBy = *ppOrderBy;
80807 }
80808
80809 /* Split the WHERE clause into separate subexpressions where each
80810 ** subexpression is separated by an AND operator.
80811 */
80812 initMaskSet(&maskSet);
80813 whereClauseInit(&wc, pParse, &maskSet);
80814 sqlite3ExprCodeConstants(pParse, pWhere);
80815 whereSplit(&wc, pWhere, TK_AND);
80816
80817 /* Allocate and initialize the WhereInfo structure that will become the
80818 ** return value.
80819 */
80820 db = pParse->db;
80821 pWInfo = sqlite3DbMallocZero(db,
80822 sizeof(WhereInfo) + pTabList->nSrc*sizeof(WhereLevel));
 
 
 
 
80823 if( db->mallocFailed ){
80824 goto whereBeginError;
80825 }
80826 pWInfo->nLevel = pTabList->nSrc;
80827 pWInfo->pParse = pParse;
80828 pWInfo->pTabList = pTabList;
80829 pWInfo->iBreak = sqlite3VdbeMakeLabel(v);
 
 
 
 
80830
 
 
 
 
 
 
 
 
80831 /* Special case: a WHERE clause that is constant. Evaluate the
80832 ** expression and either jump over all of the code or fall thru.
80833 */
80834 if( pWhere && (pTabList->nSrc==0 || sqlite3ExprIsConstantNotJoin(pWhere)) ){
80835 sqlite3ExprIfFalse(pParse, pWhere, pWInfo->iBreak, SQLITE_JUMPIFNULL);
@@ -80846,17 +82302,17 @@
80846 ** of the join. Subtracting one from the right table bitmask gives a
80847 ** bitmask for all tables to the left of the join. Knowing the bitmask
80848 ** for all tables to the left of a left join is important. Ticket #3015.
80849 */
80850 for(i=0; i<pTabList->nSrc; i++){
80851 createMask(&maskSet, pTabList->a[i].iCursor);
80852 }
80853 #ifndef NDEBUG
80854 {
80855 Bitmask toTheLeft = 0;
80856 for(i=0; i<pTabList->nSrc; i++){
80857 Bitmask m = getMask(&maskSet, pTabList->a[i].iCursor);
80858 assert( (m-1)==toTheLeft );
80859 toTheLeft |= m;
80860 }
80861 }
80862 #endif
@@ -80864,11 +82320,11 @@
80864 /* Analyze all of the subexpressions. Note that exprAnalyze() might
80865 ** add new virtual terms onto the end of the WHERE clause. We do not
80866 ** want to analyze these virtual terms, so start analyzing at the end
80867 ** and work forward so that the added virtual terms are never processed.
80868 */
80869 exprAnalyzeAll(pTabList, &wc);
80870 if( db->mallocFailed ){
80871 goto whereBeginError;
80872 }
80873
80874 /* Chose the best index to use for each table in the FROM clause.
@@ -80879,10 +82335,11 @@
80879 ** pWInfo->a[].wsFlags WHERE_xxx flags associated with pIdx
80880 ** pWInfo->a[].nEq The number of == and IN constraints
80881 ** pWInfo->a[].iFrom Which term of the FROM clause is being coded
80882 ** pWInfo->a[].iTabCur The VDBE cursor for the database table
80883 ** pWInfo->a[].iIdxCur The VDBE cursor for the index
 
80884 **
80885 ** This loop also figures out the nesting order of tables in the FROM
80886 ** clause.
80887 */
80888 notReady = ~(Bitmask)0;
@@ -80889,108 +82346,103 @@
80889 pTabItem = pTabList->a;
80890 pLevel = pWInfo->a;
80891 andFlags = ~0;
80892 WHERETRACE(("*** Optimizer Start ***\n"));
80893 for(i=iFrom=0, pLevel=pWInfo->a; i<pTabList->nSrc; i++, pLevel++){
 
80894 Index *pIdx; /* Index for FROM table at pTabItem */
80895 int wsFlags; /* Flags describing scan strategy */
80896 int nEq; /* Number of == or IN constraints */
80897 double cost; /* The cost for pIdx */
80898 int j; /* For looping over FROM tables */
80899 Index *pBest = 0; /* The best index seen so far */
80900 int bestWsFlags = 0; /* Flags associated with pBest */
80901 int bestNEq = 0; /* nEq associated with pBest */
80902 double lowestCost; /* Cost of the pBest */
80903 int bestJ = 0; /* The value of j */
80904 Bitmask m; /* Bitmask value for j or bestJ */
80905 int once = 0; /* True when first table is seen */
80906 sqlite3_index_info *pIndex; /* Current virtual index */
80907
80908 lowestCost = SQLITE_BIG_DBL;
 
80909 for(j=iFrom, pTabItem=&pTabList->a[j]; j<pTabList->nSrc; j++, pTabItem++){
80910 int doNotReorder; /* True if this table should not be reordered */
 
80911
80912 doNotReorder = (pTabItem->jointype & (JT_LEFT|JT_CROSS))!=0;
80913 if( once && doNotReorder ) break;
80914 m = getMask(&maskSet, pTabItem->iCursor);
80915 if( (m & notReady)==0 ){
80916 if( j==iFrom ) iFrom++;
80917 continue;
80918 }
80919 assert( pTabItem->pTab );
80920 #ifndef SQLITE_OMIT_VIRTUALTABLE
80921 if( IsVirtual(pTabItem->pTab) ){
 
80922 sqlite3_index_info **ppIdxInfo = &pWInfo->a[j].pIdxInfo;
80923 cost = bestVirtualIndex(pParse, &wc, pTabItem, notReady,
80924 ppOrderBy ? *ppOrderBy : 0, i==0,
80925 ppIdxInfo);
80926 wsFlags = WHERE_VIRTUALTABLE;
80927 pIndex = *ppIdxInfo;
80928 if( pIndex && pIndex->orderByConsumed ){
80929 wsFlags = WHERE_VIRTUALTABLE | WHERE_ORDERBY;
80930 }
80931 pIdx = 0;
80932 nEq = 0;
80933 if( (SQLITE_BIG_DBL/2.0)<cost ){
80934 /* The cost is not allowed to be larger than SQLITE_BIG_DBL (the
80935 ** inital value of lowestCost in this loop. If it is, then
80936 ** the (cost<lowestCost) test below will never be true and
80937 ** pLevel->pBestIdx never set.
80938 */
80939 cost = (SQLITE_BIG_DBL/2.0);
80940 }
80941 }else
80942 #endif
80943 {
80944 cost = bestIndex(pParse, &wc, pTabItem, notReady,
80945 (i==0 && ppOrderBy) ? *ppOrderBy : 0,
80946 &pIdx, &wsFlags, &nEq);
80947 pIndex = 0;
80948 }
80949 if( cost<lowestCost ){
80950 once = 1;
80951 lowestCost = cost;
80952 pBest = pIdx;
80953 bestWsFlags = wsFlags;
80954 bestNEq = nEq;
80955 bestJ = j;
80956 pLevel->pBestIdx = pIndex;
80957 }
80958 if( doNotReorder ) break;
80959 }
 
 
80960 WHERETRACE(("*** Optimizer selects table %d for loop %d\n", bestJ,
80961 pLevel-pWInfo->a));
80962 if( (bestWsFlags & WHERE_ORDERBY)!=0 ){
80963 *ppOrderBy = 0;
80964 }
80965 andFlags &= bestWsFlags;
80966 pLevel->wsFlags = bestWsFlags;
80967 pLevel->pIdx = pBest;
80968 pLevel->nEq = bestNEq;
80969 pLevel->aInLoop = 0;
80970 pLevel->nIn = 0;
80971 if( pBest ){
80972 pLevel->iIdxCur = pParse->nTab++;
80973 }else{
80974 pLevel->iIdxCur = -1;
80975 }
80976 notReady &= ~getMask(&maskSet, pTabList->a[bestJ].iCursor);
80977 pLevel->iFrom = bestJ;
80978
80979 /* Check that if the table scanned by this loop iteration had an
80980 ** INDEXED BY clause attached to it, that the named index is being
80981 ** used for the scan. If not, then query compilation has failed.
80982 ** Return an error.
80983 */
80984 pIdx = pTabList->a[bestJ].pIndex;
80985 assert( !pIdx || !pBest || pIdx==pBest );
80986 if( pIdx && pBest!=pIdx ){
80987 sqlite3ErrorMsg(pParse, "cannot use index: %s", pIdx->zName);
80988 goto whereBeginError;
 
 
 
 
 
 
80989 }
80990 }
80991 WHERETRACE(("*** Optimizer Finished ***\n"));
 
 
 
80992
80993 /* If the total query only selects a single row, then the ORDER BY
80994 ** clause is irrelevant.
80995 */
80996 if( (andFlags & WHERE_UNIQUE)!=0 && ppOrderBy ){
@@ -81003,44 +82455,45 @@
81003 ** the statement to update a single row.
81004 */
81005 assert( (wctrlFlags & WHERE_ONEPASS_DESIRED)==0 || pWInfo->nLevel==1 );
81006 if( (wctrlFlags & WHERE_ONEPASS_DESIRED)!=0 && (andFlags & WHERE_UNIQUE)!=0 ){
81007 pWInfo->okOnePass = 1;
81008 pWInfo->a[0].wsFlags &= ~WHERE_IDX_ONLY;
81009 }
81010
81011 /* Open all tables in the pTabList and any indices selected for
81012 ** searching those tables.
81013 */
81014 sqlite3CodeVerifySchema(pParse, -1); /* Insert the cookie verifier Goto */
81015 for(i=0, pLevel=pWInfo->a; i<pTabList->nSrc; i++, pLevel++){
81016 Table *pTab; /* Table to open */
81017 Index *pIx; /* Index used to access pTab (if any) */
81018 int iDb; /* Index of database containing table/index */
81019 int iIdxCur = pLevel->iIdxCur;
81020
81021 #ifndef SQLITE_OMIT_EXPLAIN
81022 if( pParse->explain==2 ){
81023 char *zMsg;
81024 struct SrcList_item *pItem = &pTabList->a[pLevel->iFrom];
81025 zMsg = sqlite3MPrintf(db, "TABLE %s", pItem->zName);
81026 if( pItem->zAlias ){
81027 zMsg = sqlite3MAppendf(db, zMsg, "%s AS %s", zMsg, pItem->zAlias);
81028 }
81029 if( (pIx = pLevel->pIdx)!=0 ){
81030 zMsg = sqlite3MAppendf(db, zMsg, "%s WITH INDEX %s", zMsg, pIx->zName);
81031 }else if( pLevel->wsFlags & (WHERE_ROWID_EQ|WHERE_ROWID_RANGE) ){
 
 
 
81032 zMsg = sqlite3MAppendf(db, zMsg, "%s USING PRIMARY KEY", zMsg);
81033 }
81034 #ifndef SQLITE_OMIT_VIRTUALTABLE
81035 else if( pLevel->pBestIdx ){
81036 sqlite3_index_info *pBestIdx = pLevel->pBestIdx;
81037 zMsg = sqlite3MAppendf(db, zMsg, "%s VIRTUAL TABLE INDEX %d:%s", zMsg,
81038 pBestIdx->idxNum, pBestIdx->idxStr);
81039 }
81040 #endif
81041 if( pLevel->wsFlags & WHERE_ORDERBY ){
81042 zMsg = sqlite3MAppendf(db, zMsg, "%s ORDER BY", zMsg);
81043 }
81044 sqlite3VdbeAddOp4(v, OP_Explain, i, pLevel->iFrom, 0, zMsg, P4_DYNAMIC);
81045 }
81046 #endif /* SQLITE_OMIT_EXPLAIN */
@@ -81047,17 +82500,18 @@
81047 pTabItem = &pTabList->a[pLevel->iFrom];
81048 pTab = pTabItem->pTab;
81049 iDb = sqlite3SchemaToIndex(pParse->db, pTab->pSchema);
81050 if( (pTab->tabFlags & TF_Ephemeral)!=0 || pTab->pSelect ) continue;
81051 #ifndef SQLITE_OMIT_VIRTUALTABLE
81052 if( pLevel->pBestIdx ){
81053 int iCur = pTabItem->iCursor;
81054 sqlite3VdbeAddOp4(v, OP_VOpen, iCur, 0, 0,
81055 (const char*)pTab->pVtab, P4_VTAB);
81056 }else
81057 #endif
81058 if( (pLevel->wsFlags & WHERE_IDX_ONLY)==0 ){
 
81059 int op = pWInfo->okOnePass ? OP_OpenWrite : OP_OpenRead;
81060 sqlite3OpenTable(pParse, pTabItem->iCursor, iDb, pTab, op);
81061 if( !pWInfo->okOnePass && pTab->nCol<BMS ){
81062 Bitmask b = pTabItem->colUsed;
81063 int n = 0;
@@ -81067,13 +82521,16 @@
81067 }
81068 }else{
81069 sqlite3TableLock(pParse, iDb, pTab->tnum, 0, pTab->zName);
81070 }
81071 pLevel->iTabCur = pTabItem->iCursor;
81072 if( (pIx = pLevel->pIdx)!=0 ){
 
81073 KeyInfo *pKey = sqlite3IndexKeyinfo(pParse, pIx);
 
81074 assert( pIx->pSchema==pTab->pSchema );
 
81075 sqlite3VdbeAddOp2(v, OP_SetNumColumns, 0, pIx->nColumn+1);
81076 sqlite3VdbeAddOp4(v, OP_OpenRead, iIdxCur, pIx->tnum, iDb,
81077 (char*)pKey, P4_KEYINFO_HANDOFF);
81078 VdbeComment((v, "%s", pIx->zName));
81079 }
@@ -81084,428 +82541,13 @@
81084 /* Generate the code to do the search. Each iteration of the for
81085 ** loop below generates code for a single nested loop of the VM
81086 ** program.
81087 */
81088 notReady = ~(Bitmask)0;
81089 for(i=0, pLevel=pWInfo->a; i<pTabList->nSrc; i++, pLevel++){
81090 int j, k;
81091 int iCur = pTabItem->iCursor; /* The VDBE cursor for the table */
81092 Index *pIdx; /* The index we will be using */
81093 int addrNxt; /* Where to jump to continue with the next IN case */
81094 int iIdxCur; /* The VDBE cursor for the index */
81095 int omitTable; /* True if we use the index only */
81096 int bRev; /* True if we need to scan in reverse order */
81097
81098 pTabItem = &pTabList->a[pLevel->iFrom];
81099 iCur = pTabItem->iCursor;
81100 pIdx = pLevel->pIdx;
81101 iIdxCur = pLevel->iIdxCur;
81102 bRev = (pLevel->wsFlags & WHERE_REVERSE)!=0;
81103 omitTable = (pLevel->wsFlags & WHERE_IDX_ONLY)!=0;
81104
81105 /* Create labels for the "break" and "continue" instructions
81106 ** for the current loop. Jump to addrBrk to break out of a loop.
81107 ** Jump to cont to go immediately to the next iteration of the
81108 ** loop.
81109 **
81110 ** When there is an IN operator, we also have a "addrNxt" label that
81111 ** means to continue with the next IN value combination. When
81112 ** there are no IN operators in the constraints, the "addrNxt" label
81113 ** is the same as "addrBrk".
81114 */
81115 addrBrk = pLevel->addrBrk = pLevel->addrNxt = sqlite3VdbeMakeLabel(v);
81116 addrCont = pLevel->addrCont = sqlite3VdbeMakeLabel(v);
81117
81118 /* If this is the right table of a LEFT OUTER JOIN, allocate and
81119 ** initialize a memory cell that records if this table matches any
81120 ** row of the left table of the join.
81121 */
81122 if( pLevel->iFrom>0 && (pTabItem[0].jointype & JT_LEFT)!=0 ){
81123 pLevel->iLeftJoin = ++pParse->nMem;
81124 sqlite3VdbeAddOp2(v, OP_Integer, 0, pLevel->iLeftJoin);
81125 VdbeComment((v, "init LEFT JOIN no-match flag"));
81126 }
81127
81128 #ifndef SQLITE_OMIT_VIRTUALTABLE
81129 if( pLevel->pBestIdx ){
81130 /* Case 0: The table is a virtual-table. Use the VFilter and VNext
81131 ** to access the data.
81132 */
81133 int iReg; /* P3 Value for OP_VFilter */
81134 sqlite3_index_info *pBestIdx = pLevel->pBestIdx;
81135 int nConstraint = pBestIdx->nConstraint;
81136 struct sqlite3_index_constraint_usage *aUsage =
81137 pBestIdx->aConstraintUsage;
81138 const struct sqlite3_index_constraint *aConstraint =
81139 pBestIdx->aConstraint;
81140
81141 iReg = sqlite3GetTempRange(pParse, nConstraint+2);
81142 pParse->disableColCache++;
81143 for(j=1; j<=nConstraint; j++){
81144 for(k=0; k<nConstraint; k++){
81145 if( aUsage[k].argvIndex==j ){
81146 int iTerm = aConstraint[k].iTermOffset;
81147 assert( pParse->disableColCache );
81148 sqlite3ExprCode(pParse, wc.a[iTerm].pExpr->pRight, iReg+j+1);
81149 break;
81150 }
81151 }
81152 if( k==nConstraint ) break;
81153 }
81154 assert( pParse->disableColCache );
81155 pParse->disableColCache--;
81156 sqlite3VdbeAddOp2(v, OP_Integer, pBestIdx->idxNum, iReg);
81157 sqlite3VdbeAddOp2(v, OP_Integer, j-1, iReg+1);
81158 sqlite3VdbeAddOp4(v, OP_VFilter, iCur, addrBrk, iReg, pBestIdx->idxStr,
81159 pBestIdx->needToFreeIdxStr ? P4_MPRINTF : P4_STATIC);
81160 sqlite3ReleaseTempRange(pParse, iReg, nConstraint+2);
81161 pBestIdx->needToFreeIdxStr = 0;
81162 for(j=0; j<nConstraint; j++){
81163 if( aUsage[j].omit ){
81164 int iTerm = aConstraint[j].iTermOffset;
81165 disableTerm(pLevel, &wc.a[iTerm]);
81166 }
81167 }
81168 pLevel->op = OP_VNext;
81169 pLevel->p1 = iCur;
81170 pLevel->p2 = sqlite3VdbeCurrentAddr(v);
81171 }else
81172 #endif /* SQLITE_OMIT_VIRTUALTABLE */
81173
81174 if( pLevel->wsFlags & WHERE_ROWID_EQ ){
81175 /* Case 1: We can directly reference a single row using an
81176 ** equality comparison against the ROWID field. Or
81177 ** we reference multiple rows using a "rowid IN (...)"
81178 ** construct.
81179 */
81180 int r1;
81181 int rtmp = sqlite3GetTempReg(pParse);
81182 pTerm = findTerm(&wc, iCur, -1, notReady, WO_EQ|WO_IN, 0);
81183 assert( pTerm!=0 );
81184 assert( pTerm->pExpr!=0 );
81185 assert( pTerm->leftCursor==iCur );
81186 assert( omitTable==0 );
81187 r1 = codeEqualityTerm(pParse, pTerm, pLevel, rtmp);
81188 addrNxt = pLevel->addrNxt;
81189 sqlite3VdbeAddOp2(v, OP_MustBeInt, r1, addrNxt);
81190 sqlite3VdbeAddOp3(v, OP_NotExists, iCur, addrNxt, r1);
81191 sqlite3ReleaseTempReg(pParse, rtmp);
81192 VdbeComment((v, "pk"));
81193 pLevel->op = OP_Noop;
81194 }else if( pLevel->wsFlags & WHERE_ROWID_RANGE ){
81195 /* Case 2: We have an inequality comparison against the ROWID field.
81196 */
81197 int testOp = OP_Noop;
81198 int start;
81199 WhereTerm *pStart, *pEnd;
81200
81201 assert( omitTable==0 );
81202 pStart = findTerm(&wc, iCur, -1, notReady, WO_GT|WO_GE, 0);
81203 pEnd = findTerm(&wc, iCur, -1, notReady, WO_LT|WO_LE, 0);
81204 if( bRev ){
81205 pTerm = pStart;
81206 pStart = pEnd;
81207 pEnd = pTerm;
81208 }
81209 if( pStart ){
81210 Expr *pX; /* The expression that defines the start bound */
81211 int r1, rTemp; /* Registers for holding the start boundary */
81212
81213 /* The following constant maps TK_xx codes into corresponding
81214 ** seek opcodes. It depends on a particular ordering of TK_xx
81215 */
81216 const u8 aMoveOp[] = {
81217 /* TK_GT */ OP_SeekGt,
81218 /* TK_LE */ OP_SeekLe,
81219 /* TK_LT */ OP_SeekLt,
81220 /* TK_GE */ OP_SeekGe
81221 };
81222 assert( TK_LE==TK_GT+1 ); /* Make sure the ordering.. */
81223 assert( TK_LT==TK_GT+2 ); /* ... of the TK_xx values... */
81224 assert( TK_GE==TK_GT+3 ); /* ... is correcct. */
81225
81226 pX = pStart->pExpr;
81227 assert( pX!=0 );
81228 assert( pStart->leftCursor==iCur );
81229 r1 = sqlite3ExprCodeTemp(pParse, pX->pRight, &rTemp);
81230 sqlite3VdbeAddOp3(v, aMoveOp[pX->op-TK_GT], iCur, addrBrk, r1);
81231 VdbeComment((v, "pk"));
81232 sqlite3ExprCacheAffinityChange(pParse, r1, 1);
81233 sqlite3ReleaseTempReg(pParse, rTemp);
81234 disableTerm(pLevel, pStart);
81235 }else{
81236 sqlite3VdbeAddOp2(v, bRev ? OP_Last : OP_Rewind, iCur, addrBrk);
81237 }
81238 if( pEnd ){
81239 Expr *pX;
81240 pX = pEnd->pExpr;
81241 assert( pX!=0 );
81242 assert( pEnd->leftCursor==iCur );
81243 pLevel->iMem = ++pParse->nMem;
81244 sqlite3ExprCode(pParse, pX->pRight, pLevel->iMem);
81245 if( pX->op==TK_LT || pX->op==TK_GT ){
81246 testOp = bRev ? OP_Le : OP_Ge;
81247 }else{
81248 testOp = bRev ? OP_Lt : OP_Gt;
81249 }
81250 disableTerm(pLevel, pEnd);
81251 }
81252 start = sqlite3VdbeCurrentAddr(v);
81253 pLevel->op = bRev ? OP_Prev : OP_Next;
81254 pLevel->p1 = iCur;
81255 pLevel->p2 = start;
81256 if( testOp!=OP_Noop ){
81257 int r1 = sqlite3GetTempReg(pParse);
81258 sqlite3VdbeAddOp2(v, OP_Rowid, iCur, r1);
81259 /* sqlite3VdbeAddOp2(v, OP_SCopy, pLevel->iMem, 0); */
81260 sqlite3VdbeAddOp3(v, testOp, pLevel->iMem, addrBrk, r1);
81261 sqlite3VdbeChangeP5(v, SQLITE_AFF_NUMERIC | SQLITE_JUMPIFNULL);
81262 sqlite3ReleaseTempReg(pParse, r1);
81263 }
81264 }else if( pLevel->wsFlags & (WHERE_COLUMN_RANGE|WHERE_COLUMN_EQ) ){
81265 /* Case 3: A scan using an index.
81266 **
81267 ** The WHERE clause may contain zero or more equality
81268 ** terms ("==" or "IN" operators) that refer to the N
81269 ** left-most columns of the index. It may also contain
81270 ** inequality constraints (>, <, >= or <=) on the indexed
81271 ** column that immediately follows the N equalities. Only
81272 ** the right-most column can be an inequality - the rest must
81273 ** use the "==" and "IN" operators. For example, if the
81274 ** index is on (x,y,z), then the following clauses are all
81275 ** optimized:
81276 **
81277 ** x=5
81278 ** x=5 AND y=10
81279 ** x=5 AND y<10
81280 ** x=5 AND y>5 AND y<10
81281 ** x=5 AND y=5 AND z<=10
81282 **
81283 ** The z<10 term of the following cannot be used, only
81284 ** the x=5 term:
81285 **
81286 ** x=5 AND z<10
81287 **
81288 ** N may be zero if there are inequality constraints.
81289 ** If there are no inequality constraints, then N is at
81290 ** least one.
81291 **
81292 ** This case is also used when there are no WHERE clause
81293 ** constraints but an index is selected anyway, in order
81294 ** to force the output order to conform to an ORDER BY.
81295 */
81296 int aStartOp[] = {
81297 0,
81298 0,
81299 OP_Rewind, /* 2: (!start_constraints && startEq && !bRev) */
81300 OP_Last, /* 3: (!start_constraints && startEq && bRev) */
81301 OP_SeekGt, /* 4: (start_constraints && !startEq && !bRev) */
81302 OP_SeekLt, /* 5: (start_constraints && !startEq && bRev) */
81303 OP_SeekGe, /* 6: (start_constraints && startEq && !bRev) */
81304 OP_SeekLe /* 7: (start_constraints && startEq && bRev) */
81305 };
81306 int aEndOp[] = {
81307 OP_Noop, /* 0: (!end_constraints) */
81308 OP_IdxGE, /* 1: (end_constraints && !bRev) */
81309 OP_IdxLT /* 2: (end_constraints && bRev) */
81310 };
81311 int nEq = pLevel->nEq;
81312 int isMinQuery = 0; /* If this is an optimized SELECT min(x).. */
81313 int regBase; /* Base register holding constraint values */
81314 int r1; /* Temp register */
81315 WhereTerm *pRangeStart = 0; /* Inequality constraint at range start */
81316 WhereTerm *pRangeEnd = 0; /* Inequality constraint at range end */
81317 int startEq; /* True if range start uses ==, >= or <= */
81318 int endEq; /* True if range end uses ==, >= or <= */
81319 int start_constraints; /* Start of range is constrained */
81320 int nConstraint; /* Number of constraint terms */
81321 int op;
81322
81323 k = pIdx->aiColumn[nEq]; /* Column for inequality constraints */
81324
81325 /* Generate code to evaluate all constraint terms using == or IN
81326 ** and store the values of those terms in an array of registers
81327 ** starting at regBase.
81328 */
81329 regBase = codeAllEqualityTerms(pParse, pLevel, &wc, notReady, 2);
81330 addrNxt = pLevel->addrNxt;
81331
81332 /* If this loop satisfies a sort order (pOrderBy) request that
81333 ** was passed to this function to implement a "SELECT min(x) ..."
81334 ** query, then the caller will only allow the loop to run for
81335 ** a single iteration. This means that the first row returned
81336 ** should not have a NULL value stored in 'x'. If column 'x' is
81337 ** the first one after the nEq equality constraints in the index,
81338 ** this requires some special handling.
81339 */
81340 if( (wctrlFlags&WHERE_ORDERBY_MIN)!=0
81341 && (pLevel->wsFlags&WHERE_ORDERBY)
81342 && (pIdx->nColumn>nEq)
81343 ){
81344 assert( pOrderBy->nExpr==1 );
81345 assert( pOrderBy->a[0].pExpr->iColumn==pIdx->aiColumn[nEq] );
81346 isMinQuery = 1;
81347 }
81348
81349 /* Find any inequality constraint terms for the start and end
81350 ** of the range.
81351 */
81352 if( pLevel->wsFlags & WHERE_TOP_LIMIT ){
81353 pRangeEnd = findTerm(&wc, iCur, k, notReady, (WO_LT|WO_LE), pIdx);
81354 }
81355 if( pLevel->wsFlags & WHERE_BTM_LIMIT ){
81356 pRangeStart = findTerm(&wc, iCur, k, notReady, (WO_GT|WO_GE), pIdx);
81357 }
81358
81359 /* If we are doing a reverse order scan on an ascending index, or
81360 ** a forward order scan on a descending index, interchange the
81361 ** start and end terms (pRangeStart and pRangeEnd).
81362 */
81363 if( bRev==(pIdx->aSortOrder[nEq]==SQLITE_SO_ASC) ){
81364 SWAP(WhereTerm *, pRangeEnd, pRangeStart);
81365 }
81366
81367 testcase( pRangeStart && pRangeStart->eOperator & WO_LE );
81368 testcase( pRangeStart && pRangeStart->eOperator & WO_GE );
81369 testcase( pRangeEnd && pRangeEnd->eOperator & WO_LE );
81370 testcase( pRangeEnd && pRangeEnd->eOperator & WO_GE );
81371 startEq = !pRangeStart || pRangeStart->eOperator & (WO_LE|WO_GE);
81372 endEq = !pRangeEnd || pRangeEnd->eOperator & (WO_LE|WO_GE);
81373 start_constraints = pRangeStart || nEq>0;
81374
81375 /* Seek the index cursor to the start of the range. */
81376 nConstraint = nEq;
81377 if( pRangeStart ){
81378 int dcc = pParse->disableColCache;
81379 if( pRangeEnd ){
81380 pParse->disableColCache++;
81381 }
81382 sqlite3ExprCode(pParse, pRangeStart->pExpr->pRight, regBase+nEq);
81383 pParse->disableColCache = dcc;
81384 sqlite3VdbeAddOp2(v, OP_IsNull, regBase+nEq, addrNxt);
81385 nConstraint++;
81386 }else if( isMinQuery ){
81387 sqlite3VdbeAddOp2(v, OP_Null, 0, regBase+nEq);
81388 nConstraint++;
81389 startEq = 0;
81390 start_constraints = 1;
81391 }
81392 codeApplyAffinity(pParse, regBase, nConstraint, pIdx);
81393 op = aStartOp[(start_constraints<<2) + (startEq<<1) + bRev];
81394 assert( op!=0 );
81395 testcase( op==OP_Rewind );
81396 testcase( op==OP_Last );
81397 testcase( op==OP_SeekGt );
81398 testcase( op==OP_SeekGe );
81399 testcase( op==OP_SeekLe );
81400 testcase( op==OP_SeekLt );
81401 sqlite3VdbeAddOp4(v, op, iIdxCur, addrNxt, regBase,
81402 SQLITE_INT_TO_PTR(nConstraint), P4_INT32);
81403
81404 /* Load the value for the inequality constraint at the end of the
81405 ** range (if any).
81406 */
81407 nConstraint = nEq;
81408 if( pRangeEnd ){
81409 sqlite3ExprCode(pParse, pRangeEnd->pExpr->pRight, regBase+nEq);
81410 sqlite3VdbeAddOp2(v, OP_IsNull, regBase+nEq, addrNxt);
81411 codeApplyAffinity(pParse, regBase, nEq+1, pIdx);
81412 nConstraint++;
81413 }
81414
81415 /* Top of the loop body */
81416 pLevel->p2 = sqlite3VdbeCurrentAddr(v);
81417
81418 /* Check if the index cursor is past the end of the range. */
81419 op = aEndOp[(pRangeEnd || nEq) * (1 + bRev)];
81420 testcase( op==OP_Noop );
81421 testcase( op==OP_IdxGE );
81422 testcase( op==OP_IdxLT );
81423 sqlite3VdbeAddOp4(v, op, iIdxCur, addrNxt, regBase,
81424 SQLITE_INT_TO_PTR(nConstraint), P4_INT32);
81425 sqlite3VdbeChangeP5(v, endEq!=bRev ?1:0);
81426
81427 /* If there are inequality constraints, check that the value
81428 ** of the table column that the inequality contrains is not NULL.
81429 ** If it is, jump to the next iteration of the loop.
81430 */
81431 r1 = sqlite3GetTempReg(pParse);
81432 testcase( pLevel->wsFlags & WHERE_BTM_LIMIT );
81433 testcase( pLevel->wsFlags & WHERE_TOP_LIMIT );
81434 if( pLevel->wsFlags & (WHERE_BTM_LIMIT|WHERE_TOP_LIMIT) ){
81435 sqlite3VdbeAddOp3(v, OP_Column, iIdxCur, nEq, r1);
81436 sqlite3VdbeAddOp2(v, OP_IsNull, r1, addrCont);
81437 }
81438
81439 /* Seek the table cursor, if required */
81440 if( !omitTable ){
81441 sqlite3VdbeAddOp2(v, OP_IdxRowid, iIdxCur, r1);
81442 sqlite3VdbeAddOp2(v, OP_Seek, iCur, r1); /* Deferred seek */
81443 }
81444 sqlite3ReleaseTempReg(pParse, r1);
81445
81446 /* Record the instruction used to terminate the loop. Disable
81447 ** WHERE clause terms made redundant by the index range scan.
81448 */
81449 pLevel->op = bRev ? OP_Prev : OP_Next;
81450 pLevel->p1 = iIdxCur;
81451 disableTerm(pLevel, pRangeStart);
81452 disableTerm(pLevel, pRangeEnd);
81453 }else{
81454 /* Case 4: There is no usable index. We must do a complete
81455 ** scan of the entire table.
81456 */
81457 assert( omitTable==0 );
81458 assert( bRev==0 );
81459 pLevel->op = OP_Next;
81460 pLevel->p1 = iCur;
81461 pLevel->p2 = 1 + sqlite3VdbeAddOp2(v, OP_Rewind, iCur, addrBrk);
81462 pLevel->p5 = SQLITE_STMTSTATUS_FULLSCAN_STEP;
81463 }
81464 notReady &= ~getMask(&maskSet, iCur);
81465
81466 /* Insert code to test every subexpression that can be completely
81467 ** computed using the current set of tables.
81468 */
81469 k = 0;
81470 for(pTerm=wc.a, j=wc.nTerm; j>0; j--, pTerm++){
81471 Expr *pE;
81472 testcase( pTerm->wtFlags & TERM_VIRTUAL );
81473 testcase( pTerm->wtFlags & TERM_CODED );
81474 if( pTerm->wtFlags & (TERM_VIRTUAL|TERM_CODED) ) continue;
81475 if( (pTerm->prereqAll & notReady)!=0 ) continue;
81476 pE = pTerm->pExpr;
81477 assert( pE!=0 );
81478 if( pLevel->iLeftJoin && !ExprHasProperty(pE, EP_FromJoin) ){
81479 continue;
81480 }
81481 pParse->disableColCache += k;
81482 sqlite3ExprIfFalse(pParse, pE, addrCont, SQLITE_JUMPIFNULL);
81483 pParse->disableColCache -= k;
81484 k = 1;
81485 pTerm->wtFlags |= TERM_CODED;
81486 }
81487
81488 /* For a LEFT OUTER JOIN, generate code that will record the fact that
81489 ** at least one row of the right table has matched the left table.
81490 */
81491 if( pLevel->iLeftJoin ){
81492 pLevel->addrFirst = sqlite3VdbeCurrentAddr(v);
81493 sqlite3VdbeAddOp2(v, OP_Integer, 1, pLevel->iLeftJoin);
81494 VdbeComment((v, "record LEFT JOIN hit"));
81495 sqlite3ExprClearColumnCache(pParse, pLevel->iTabCur);
81496 sqlite3ExprClearColumnCache(pParse, pLevel->iIdxCur);
81497 for(pTerm=wc.a, j=0; j<wc.nTerm; j++, pTerm++){
81498 testcase( pTerm->wtFlags & TERM_VIRTUAL );
81499 testcase( pTerm->wtFlags & TERM_CODED );
81500 if( pTerm->wtFlags & (TERM_VIRTUAL|TERM_CODED) ) continue;
81501 if( (pTerm->prereqAll & notReady)!=0 ) continue;
81502 assert( pTerm->pExpr );
81503 sqlite3ExprIfFalse(pParse, pTerm->pExpr, addrCont, SQLITE_JUMPIFNULL);
81504 pTerm->wtFlags |= TERM_CODED;
81505 }
81506 }
81507 }
81508
81509 #ifdef SQLITE_TEST /* For testing and debugging use only */
81510 /* Record in the query plan information about the current table
81511 ** and the index used to access it (if any). If the table itself
@@ -81520,34 +82562,34 @@
81520 pTabItem = &pTabList->a[pLevel->iFrom];
81521 z = pTabItem->zAlias;
81522 if( z==0 ) z = pTabItem->pTab->zName;
81523 n = sqlite3Strlen30(z);
81524 if( n+nQPlan < sizeof(sqlite3_query_plan)-10 ){
81525 if( pLevel->wsFlags & WHERE_IDX_ONLY ){
81526 memcpy(&sqlite3_query_plan[nQPlan], "{}", 2);
81527 nQPlan += 2;
81528 }else{
81529 memcpy(&sqlite3_query_plan[nQPlan], z, n);
81530 nQPlan += n;
81531 }
81532 sqlite3_query_plan[nQPlan++] = ' ';
81533 }
81534 testcase( pLevel->wsFlags & WHERE_ROWID_EQ );
81535 testcase( pLevel->wsFlags & WHERE_ROWID_RANGE );
81536 if( pLevel->wsFlags & (WHERE_ROWID_EQ|WHERE_ROWID_RANGE) ){
81537 memcpy(&sqlite3_query_plan[nQPlan], "* ", 2);
81538 nQPlan += 2;
81539 }else if( pLevel->pIdx==0 ){
81540 memcpy(&sqlite3_query_plan[nQPlan], "{} ", 3);
81541 nQPlan += 3;
81542 }else{
81543 n = sqlite3Strlen30(pLevel->pIdx->zName);
81544 if( n+nQPlan < sizeof(sqlite3_query_plan)-2 ){
81545 memcpy(&sqlite3_query_plan[nQPlan], pLevel->pIdx->zName, n);
81546 nQPlan += n;
81547 sqlite3_query_plan[nQPlan++] = ' ';
81548 }
 
 
 
81549 }
81550 }
81551 while( nQPlan>0 && sqlite3_query_plan[nQPlan-1]==' ' ){
81552 sqlite3_query_plan[--nQPlan] = 0;
81553 }
@@ -81556,17 +82598,14 @@
81556 #endif /* SQLITE_TEST // Testing and debugging use only */
81557
81558 /* Record the continuation address in the WhereInfo structure. Then
81559 ** clean up and return.
81560 */
81561 pWInfo->iContinue = addrCont;
81562 whereClauseClear(&wc);
81563 return pWInfo;
81564
81565 /* Jump here if malloc fails */
81566 whereBeginError:
81567 whereClauseClear(&wc);
81568 whereInfoFree(db, pWInfo);
81569 return 0;
81570 }
81571
81572 /*
@@ -81589,20 +82628,20 @@
81589 sqlite3VdbeResolveLabel(v, pLevel->addrCont);
81590 if( pLevel->op!=OP_Noop ){
81591 sqlite3VdbeAddOp2(v, pLevel->op, pLevel->p1, pLevel->p2);
81592 sqlite3VdbeChangeP5(v, pLevel->p5);
81593 }
81594 if( pLevel->nIn ){
81595 struct InLoop *pIn;
81596 int j;
81597 sqlite3VdbeResolveLabel(v, pLevel->addrNxt);
81598 for(j=pLevel->nIn, pIn=&pLevel->aInLoop[j-1]; j>0; j--, pIn--){
81599 sqlite3VdbeJumpHere(v, pIn->addrInTop+1);
81600 sqlite3VdbeAddOp2(v, OP_Next, pIn->iCur, pIn->addrInTop);
81601 sqlite3VdbeJumpHere(v, pIn->addrInTop-1);
81602 }
81603 sqlite3DbFree(db, pLevel->aInLoop);
81604 }
81605 sqlite3VdbeResolveLabel(v, pLevel->addrBrk);
81606 if( pLevel->iLeftJoin ){
81607 int addr;
81608 addr = sqlite3VdbeAddOp1(v, OP_IfPos, pLevel->iLeftJoin);
@@ -81625,15 +82664,17 @@
81625 for(i=0, pLevel=pWInfo->a; i<pTabList->nSrc; i++, pLevel++){
81626 struct SrcList_item *pTabItem = &pTabList->a[pLevel->iFrom];
81627 Table *pTab = pTabItem->pTab;
81628 assert( pTab!=0 );
81629 if( (pTab->tabFlags & TF_Ephemeral)!=0 || pTab->pSelect ) continue;
81630 if( !pWInfo->okOnePass && (pLevel->wsFlags & WHERE_IDX_ONLY)==0 ){
81631 sqlite3VdbeAddOp1(v, OP_Close, pTabItem->iCursor);
81632 }
81633 if( pLevel->pIdx!=0 ){
81634 sqlite3VdbeAddOp1(v, OP_Close, pLevel->iIdxCur);
 
 
81635 }
81636
81637 /* If this scan uses an index, make code substitutions to read data
81638 ** from the index in preference to the table. Sometimes, this means
81639 ** the table need never be read from. This is a performance boost,
@@ -81645,15 +82686,15 @@
81645 ** sqlite3WhereEnd will have created code that references the table
81646 ** directly. This loop scans all that code looking for opcodes
81647 ** that reference the table and converts them into opcodes that
81648 ** reference the index.
81649 */
81650 if( pLevel->pIdx ){
81651 int k, j, last;
81652 VdbeOp *pOp;
81653 Index *pIdx = pLevel->pIdx;
81654 int useIndexOnly = pLevel->wsFlags & WHERE_IDX_ONLY;
81655
81656 assert( pIdx!=0 );
81657 pOp = sqlite3VdbeGetOp(v, pWInfo->iTop);
81658 last = sqlite3VdbeCurrentAddr(v);
81659 for(k=pWInfo->iTop; k<last; k++, pOp++){
@@ -81774,38 +82815,38 @@
81774 ** YYNRULE the number of rules in the grammar
81775 ** YYERRORSYMBOL is the code number of the error symbol. If not
81776 ** defined, then do no error processing.
81777 */
81778 #define YYCODETYPE unsigned char
81779 #define YYNOCODE 248
81780 #define YYACTIONTYPE unsigned short int
81781 #define YYWILDCARD 59
81782 #define sqlite3ParserTOKENTYPE Token
81783 typedef union {
81784 int yyinit;
81785 sqlite3ParserTOKENTYPE yy0;
81786 int yy46;
81787 struct LikeOp yy72;
81788 Expr* yy172;
81789 ExprList* yy174;
81790 Select* yy219;
81791 struct LimitVal yy234;
81792 TriggerStep* yy243;
81793 struct TrigEvent yy370;
81794 SrcList* yy373;
81795 struct {int value; int mask;} yy405;
81796 IdList* yy432;
81797 } YYMINORTYPE;
81798 #ifndef YYSTACKDEPTH
81799 #define YYSTACKDEPTH 100
81800 #endif
81801 #define sqlite3ParserARG_SDECL Parse *pParse;
81802 #define sqlite3ParserARG_PDECL ,Parse *pParse
81803 #define sqlite3ParserARG_FETCH Parse *pParse = yypParser->pParse
81804 #define sqlite3ParserARG_STORE yypParser->pParse = pParse
81805 #define YYNSTATE 601
81806 #define YYNRULE 314
81807 #define YYFALLBACK 1
81808 #define YY_NO_ACTION (YYNSTATE+YYNRULE+2)
81809 #define YY_ACCEPT_ACTION (YYNSTATE+YYNRULE+1)
81810 #define YY_ERROR_ACTION (YYNSTATE+YYNRULE)
81811
@@ -81860,427 +82901,431 @@
81860 ** yy_reduce_ofst[] For each state, the offset into yy_action for
81861 ** shifting non-terminals after a reduce.
81862 ** yy_default[] Default action for each state.
81863 */
81864 static const YYACTIONTYPE yy_action[] = {
81865 /* 0 */ 299, 916, 120, 600, 2, 175, 427, 427, 62, 62,
81866 /* 10 */ 62, 62, 487, 64, 64, 64, 64, 65, 65, 66,
81867 /* 20 */ 66, 66, 67, 213, 400, 397, 434, 440, 69, 64,
81868 /* 30 */ 64, 64, 64, 65, 65, 66, 66, 66, 67, 213,
81869 /* 40 */ 460, 458, 330, 171, 61, 60, 304, 444, 445, 441,
81870 /* 50 */ 441, 63, 63, 62, 62, 62, 62, 259, 64, 64,
81871 /* 60 */ 64, 64, 65, 65, 66, 66, 66, 67, 213, 299,
81872 /* 70 */ 501, 427, 427, 306, 429, 83, 68, 471, 70, 155,
81873 /* 80 */ 64, 64, 64, 64, 65, 65, 66, 66, 66, 67,
81874 /* 90 */ 213, 68, 310, 70, 155, 434, 440, 456, 215, 59,
81875 /* 100 */ 65, 65, 66, 66, 66, 67, 213, 431, 431, 431,
81876 /* 110 */ 211, 586, 299, 61, 60, 304, 444, 445, 441, 441,
81877 /* 120 */ 63, 63, 62, 62, 62, 62, 324, 64, 64, 64,
81878 /* 130 */ 64, 65, 65, 66, 66, 66, 67, 213, 434, 440,
81879 /* 140 */ 95, 320, 402, 483, 598, 907, 210, 907, 423, 35,
81880 /* 150 */ 57, 67, 213, 203, 419, 271, 61, 60, 304, 444,
81881 /* 160 */ 445, 441, 441, 63, 63, 62, 62, 62, 62, 213,
81882 /* 170 */ 64, 64, 64, 64, 65, 65, 66, 66, 66, 67,
81883 /* 180 */ 213, 299, 492, 535, 595, 584, 109, 424, 465, 460,
81884 /* 190 */ 338, 500, 416, 20, 522, 348, 272, 405, 324, 68,
81885 /* 200 */ 466, 70, 155, 583, 582, 542, 517, 434, 440, 150,
81886 /* 210 */ 151, 388, 541, 467, 523, 334, 152, 544, 271, 501,
81887 /* 220 */ 423, 42, 502, 429, 299, 61, 60, 304, 444, 445,
81888 /* 230 */ 441, 441, 63, 63, 62, 62, 62, 62, 396, 64,
81889 /* 240 */ 64, 64, 64, 65, 65, 66, 66, 66, 67, 213,
81890 /* 250 */ 434, 440, 456, 601, 400, 397, 431, 431, 431, 569,
81891 /* 260 */ 561, 217, 406, 407, 579, 214, 309, 299, 61, 60,
81892 /* 270 */ 304, 444, 445, 441, 441, 63, 63, 62, 62, 62,
81893 /* 280 */ 62, 324, 64, 64, 64, 64, 65, 65, 66, 66,
81894 /* 290 */ 66, 67, 213, 434, 440, 405, 543, 307, 560, 505,
81895 /* 300 */ 506, 560, 536, 423, 36, 195, 66, 66, 66, 67,
81896 /* 310 */ 213, 61, 60, 304, 444, 445, 441, 441, 63, 63,
81897 /* 320 */ 62, 62, 62, 62, 183, 64, 64, 64, 64, 65,
81898 /* 330 */ 65, 66, 66, 66, 67, 213, 417, 533, 584, 424,
81899 /* 340 */ 78, 271, 299, 259, 307, 530, 496, 236, 381, 277,
81900 /* 350 */ 276, 381, 277, 276, 553, 242, 583, 153, 552, 211,
81901 /* 360 */ 406, 407, 211, 379, 68, 225, 70, 155, 434, 440,
81902 /* 370 */ 370, 167, 114, 251, 351, 256, 352, 178, 226, 175,
81903 /* 380 */ 17, 427, 393, 81, 260, 382, 61, 60, 304, 444,
81904 /* 390 */ 445, 441, 441, 63, 63, 62, 62, 62, 62, 514,
81905 /* 400 */ 64, 64, 64, 64, 65, 65, 66, 66, 66, 67,
81906 /* 410 */ 213, 299, 225, 558, 506, 499, 405, 391, 214, 114,
81907 /* 420 */ 251, 351, 256, 352, 178, 184, 324, 418, 353, 356,
81908 /* 430 */ 357, 260, 395, 378, 156, 530, 405, 434, 440, 358,
81909 /* 440 */ 184, 535, 243, 353, 356, 357, 427, 235, 423, 35,
81910 /* 450 */ 545, 20, 399, 2, 358, 61, 60, 304, 444, 445,
81911 /* 460 */ 441, 441, 63, 63, 62, 62, 62, 62, 424, 64,
81912 /* 470 */ 64, 64, 64, 65, 65, 66, 66, 66, 67, 213,
81913 /* 480 */ 299, 406, 407, 184, 516, 503, 353, 356, 357, 204,
81914 /* 490 */ 338, 456, 215, 324, 420, 337, 422, 358, 227, 324,
81915 /* 500 */ 421, 406, 407, 195, 535, 335, 434, 440, 305, 451,
81916 /* 510 */ 452, 580, 581, 591, 20, 423, 42, 329, 451, 452,
81917 /* 520 */ 162, 423, 35, 424, 61, 60, 304, 444, 445, 441,
81918 /* 530 */ 441, 63, 63, 62, 62, 62, 62, 424, 64, 64,
81919 /* 540 */ 64, 64, 65, 65, 66, 66, 66, 67, 213, 299,
81920 /* 550 */ 324, 495, 465, 263, 424, 340, 218, 160, 154, 324,
81921 /* 560 */ 343, 379, 448, 342, 466, 324, 163, 161, 461, 435,
81922 /* 570 */ 436, 214, 423, 28, 21, 434, 440, 467, 427, 507,
81923 /* 580 */ 214, 423, 50, 375, 408, 409, 410, 423, 50, 508,
81924 /* 590 */ 438, 439, 424, 61, 60, 304, 444, 445, 441, 441,
81925 /* 600 */ 63, 63, 62, 62, 62, 62, 347, 64, 64, 64,
81926 /* 610 */ 64, 65, 65, 66, 66, 66, 67, 213, 299, 437,
81927 /* 620 */ 281, 294, 555, 94, 458, 534, 171, 315, 423, 3,
81928 /* 630 */ 1, 594, 298, 316, 405, 598, 906, 327, 906, 447,
81929 /* 640 */ 447, 244, 212, 427, 434, 440, 123, 477, 327, 56,
81930 /* 650 */ 447, 447, 174, 161, 327, 325, 447, 447, 284, 383,
81931 /* 660 */ 282, 299, 61, 60, 304, 444, 445, 441, 441, 63,
81932 /* 670 */ 63, 62, 62, 62, 62, 595, 64, 64, 64, 64,
81933 /* 680 */ 65, 65, 66, 66, 66, 67, 213, 434, 440, 551,
81934 /* 690 */ 368, 551, 124, 327, 478, 447, 447, 483, 557, 406,
81935 /* 700 */ 407, 265, 302, 483, 299, 61, 60, 304, 444, 445,
81936 /* 710 */ 441, 441, 63, 63, 62, 62, 62, 62, 405, 64,
81937 /* 720 */ 64, 64, 64, 65, 65, 66, 66, 66, 67, 213,
81938 /* 730 */ 434, 440, 327, 404, 447, 447, 219, 271, 839, 269,
81939 /* 740 */ 283, 267, 247, 180, 181, 182, 483, 299, 61, 71,
81940 /* 750 */ 304, 444, 445, 441, 441, 63, 63, 62, 62, 62,
81941 /* 760 */ 62, 159, 64, 64, 64, 64, 65, 65, 66, 66,
81942 /* 770 */ 66, 67, 213, 434, 440, 494, 371, 211, 571, 231,
81943 /* 780 */ 271, 374, 346, 406, 407, 249, 478, 259, 271, 259,
81944 /* 790 */ 299, 380, 60, 304, 444, 445, 441, 441, 63, 63,
81945 /* 800 */ 62, 62, 62, 62, 349, 64, 64, 64, 64, 65,
81946 /* 810 */ 65, 66, 66, 66, 67, 213, 434, 440, 405, 23,
81947 /* 820 */ 405, 572, 311, 405, 312, 115, 487, 271, 259, 573,
81948 /* 830 */ 5, 422, 19, 478, 145, 421, 304, 444, 445, 441,
81949 /* 840 */ 441, 63, 63, 62, 62, 62, 62, 324, 64, 64,
81950 /* 850 */ 64, 64, 65, 65, 66, 66, 66, 67, 213, 73,
81951 /* 860 */ 331, 430, 4, 313, 271, 457, 303, 271, 228, 423,
81952 /* 870 */ 29, 324, 361, 324, 328, 73, 331, 77, 4, 79,
81953 /* 880 */ 324, 345, 303, 406, 407, 406, 407, 369, 406, 407,
81954 /* 890 */ 328, 333, 336, 423, 24, 423, 33, 324, 378, 179,
81955 /* 900 */ 159, 460, 423, 54, 324, 229, 324, 333, 287, 479,
81956 /* 910 */ 179, 480, 476, 487, 168, 318, 119, 460, 324, 423,
81957 /* 920 */ 53, 76, 75, 469, 199, 478, 423, 99, 423, 97,
81958 /* 930 */ 74, 322, 323, 454, 454, 429, 473, 76, 75, 493,
81959 /* 940 */ 423, 102, 390, 474, 324, 365, 74, 322, 323, 73,
81960 /* 950 */ 331, 429, 4, 211, 301, 324, 303, 324, 424, 260,
81961 /* 960 */ 324, 211, 157, 230, 328, 301, 423, 103, 431, 431,
81962 /* 970 */ 431, 432, 433, 11, 314, 389, 186, 423, 108, 423,
81963 /* 980 */ 110, 333, 423, 16, 431, 431, 431, 432, 433, 11,
81964 /* 990 */ 326, 460, 189, 165, 197, 324, 424, 596, 232, 233,
81965 /* 1000 */ 234, 105, 449, 148, 22, 324, 482, 635, 324, 486,
81966 /* 1010 */ 424, 76, 75, 485, 208, 176, 289, 423, 100, 488,
81967 /* 1020 */ 74, 322, 323, 290, 324, 429, 424, 423, 34, 324,
81968 /* 1030 */ 423, 98, 324, 18, 324, 206, 597, 560, 511, 512,
81969 /* 1040 */ 257, 205, 324, 519, 207, 324, 423, 25, 324, 518,
81970 /* 1050 */ 324, 423, 55, 324, 423, 111, 423, 112, 431, 431,
81971 /* 1060 */ 431, 432, 433, 11, 423, 113, 442, 423, 26, 324,
81972 /* 1070 */ 423, 37, 423, 38, 258, 423, 27, 324, 524, 324,
81973 /* 1080 */ 521, 520, 8, 526, 324, 183, 324, 386, 286, 276,
81974 /* 1090 */ 324, 423, 39, 300, 85, 324, 525, 324, 211, 423,
81975 /* 1100 */ 40, 423, 41, 324, 537, 324, 423, 43, 423, 44,
81976 /* 1110 */ 264, 252, 423, 45, 262, 324, 183, 423, 30, 423,
81977 /* 1120 */ 31, 324, 253, 392, 266, 423, 46, 423, 47, 324,
81978 /* 1130 */ 360, 324, 183, 324, 556, 324, 183, 423, 48, 564,
81979 /* 1140 */ 565, 176, 92, 423, 49, 268, 576, 593, 92, 297,
81980 /* 1150 */ 270, 423, 32, 423, 10, 423, 51, 423, 52, 192,
81981 /* 1160 */ 275, 373, 147, 376, 377, 278, 279, 428, 280, 568,
81982 /* 1170 */ 578, 288, 291, 292, 590, 453, 332, 414, 237, 455,
81983 /* 1180 */ 472, 475, 254, 245, 517, 355, 563, 166, 403, 575,
81984 /* 1190 */ 411, 528, 412, 413, 531, 285, 7, 387, 85, 321,
81985 /* 1200 */ 425, 527, 341, 529, 84, 339, 58, 173, 80, 216,
81986 /* 1210 */ 470, 121, 308, 86, 344, 350, 125, 223, 514, 362,
81987 /* 1220 */ 187, 504, 509, 546, 255, 222, 515, 513, 238, 224,
81988 /* 1230 */ 239, 510, 240, 538, 241, 295, 426, 539, 540, 532,
81989 /* 1240 */ 188, 190, 296, 364, 246, 191, 484, 490, 248, 548,
81990 /* 1250 */ 366, 193, 117, 250, 89, 491, 372, 559, 196, 133,
81991 /* 1260 */ 384, 385, 134, 135, 566, 317, 136, 137, 587, 588,
81992 /* 1270 */ 592, 139, 401, 101, 221, 574, 104, 143, 589, 142,
81993 /* 1280 */ 415, 636, 637, 169, 446, 170, 443, 72, 144, 273,
81994 /* 1290 */ 450, 549, 459, 462, 158, 172, 463, 464, 468, 6,
81995 /* 1300 */ 13, 82, 12, 481, 122, 164, 177, 497, 93, 498,
81996 /* 1310 */ 489, 220, 87, 116, 126, 185, 261, 127, 96, 88,
81997 /* 1320 */ 128, 253, 107, 363, 146, 547, 129, 354, 359, 194,
81998 /* 1330 */ 367, 176, 274, 130, 118, 554, 131, 550, 9, 319,
81999 /* 1340 */ 562, 132, 90, 198, 14, 200, 567, 202, 201, 570,
82000 /* 1350 */ 138, 140, 141, 209, 15, 106, 585, 577, 293, 91,
82001 /* 1360 */ 398, 394, 149, 599,
 
82002 };
82003 static const YYCODETYPE yy_lookahead[] = {
82004 /* 0 */ 16, 140, 141, 142, 143, 21, 23, 23, 69, 70,
82005 /* 10 */ 71, 72, 148, 74, 75, 76, 77, 78, 79, 80,
82006 /* 20 */ 81, 82, 83, 84, 1, 2, 42, 43, 73, 74,
82007 /* 30 */ 75, 76, 77, 78, 79, 80, 81, 82, 83, 84,
82008 /* 40 */ 58, 162, 163, 164, 60, 61, 62, 63, 64, 65,
82009 /* 50 */ 66, 67, 68, 69, 70, 71, 72, 148, 74, 75,
82010 /* 60 */ 76, 77, 78, 79, 80, 81, 82, 83, 84, 16,
82011 /* 70 */ 88, 88, 88, 209, 92, 22, 218, 219, 220, 221,
82012 /* 80 */ 74, 75, 76, 77, 78, 79, 80, 81, 82, 83,
82013 /* 90 */ 84, 218, 183, 220, 221, 42, 43, 78, 79, 46,
82014 /* 100 */ 78, 79, 80, 81, 82, 83, 84, 125, 126, 127,
82015 /* 110 */ 110, 238, 16, 60, 61, 62, 63, 64, 65, 66,
82016 /* 120 */ 67, 68, 69, 70, 71, 72, 148, 74, 75, 76,
82017 /* 130 */ 77, 78, 79, 80, 81, 82, 83, 84, 42, 43,
82018 /* 140 */ 44, 144, 145, 162, 19, 20, 149, 22, 170, 171,
82019 /* 150 */ 19, 83, 84, 156, 23, 148, 60, 61, 62, 63,
82020 /* 160 */ 64, 65, 66, 67, 68, 69, 70, 71, 72, 84,
82021 /* 170 */ 74, 75, 76, 77, 78, 79, 80, 81, 82, 83,
82022 /* 180 */ 84, 16, 201, 148, 59, 148, 21, 190, 12, 58,
82023 /* 190 */ 212, 170, 157, 158, 30, 217, 189, 23, 148, 218,
82024 /* 200 */ 24, 220, 221, 166, 167, 177, 178, 42, 43, 78,
82025 /* 210 */ 79, 214, 184, 37, 50, 39, 181, 182, 148, 88,
82026 /* 220 */ 170, 171, 170, 92, 16, 60, 61, 62, 63, 64,
82027 /* 230 */ 65, 66, 67, 68, 69, 70, 71, 72, 241, 74,
82028 /* 240 */ 75, 76, 77, 78, 79, 80, 81, 82, 83, 84,
82029 /* 250 */ 42, 43, 78, 0, 1, 2, 125, 126, 127, 189,
82030 /* 260 */ 11, 211, 88, 89, 227, 228, 102, 16, 60, 61,
82031 /* 270 */ 62, 63, 64, 65, 66, 67, 68, 69, 70, 71,
82032 /* 280 */ 72, 148, 74, 75, 76, 77, 78, 79, 80, 81,
82033 /* 290 */ 82, 83, 84, 42, 43, 23, 182, 16, 49, 186,
82034 /* 300 */ 187, 49, 182, 170, 171, 156, 80, 81, 82, 83,
82035 /* 310 */ 84, 60, 61, 62, 63, 64, 65, 66, 67, 68,
82036 /* 320 */ 69, 70, 71, 72, 22, 74, 75, 76, 77, 78,
82037 /* 330 */ 79, 80, 81, 82, 83, 84, 168, 169, 148, 190,
82038 /* 340 */ 132, 148, 16, 148, 16, 177, 20, 191, 99, 100,
82039 /* 350 */ 101, 99, 100, 101, 25, 222, 166, 22, 29, 110,
82040 /* 360 */ 88, 89, 110, 214, 218, 84, 220, 221, 42, 43,
82041 /* 370 */ 41, 90, 91, 92, 93, 94, 95, 96, 183, 21,
82042 /* 380 */ 231, 23, 189, 132, 103, 236, 60, 61, 62, 63,
82043 /* 390 */ 64, 65, 66, 67, 68, 69, 70, 71, 72, 97,
82044 /* 400 */ 74, 75, 76, 77, 78, 79, 80, 81, 82, 83,
82045 /* 410 */ 84, 16, 84, 186, 187, 20, 23, 227, 228, 91,
82046 /* 420 */ 92, 93, 94, 95, 96, 90, 148, 169, 93, 94,
82047 /* 430 */ 95, 103, 239, 148, 156, 177, 23, 42, 43, 104,
82048 /* 440 */ 90, 148, 148, 93, 94, 95, 88, 154, 170, 171,
82049 /* 450 */ 157, 158, 142, 143, 104, 60, 61, 62, 63, 64,
82050 /* 460 */ 65, 66, 67, 68, 69, 70, 71, 72, 190, 74,
82051 /* 470 */ 75, 76, 77, 78, 79, 80, 81, 82, 83, 84,
82052 /* 480 */ 16, 88, 89, 90, 20, 161, 93, 94, 95, 156,
82053 /* 490 */ 212, 78, 79, 148, 170, 217, 107, 104, 213, 148,
82054 /* 500 */ 111, 88, 89, 156, 148, 187, 42, 43, 165, 166,
82055 /* 510 */ 167, 98, 99, 157, 158, 170, 171, 165, 166, 167,
82056 /* 520 */ 156, 170, 171, 190, 60, 61, 62, 63, 64, 65,
82057 /* 530 */ 66, 67, 68, 69, 70, 71, 72, 190, 74, 75,
82058 /* 540 */ 76, 77, 78, 79, 80, 81, 82, 83, 84, 16,
82059 /* 550 */ 148, 20, 12, 20, 190, 210, 211, 148, 156, 148,
82060 /* 560 */ 148, 214, 20, 212, 24, 148, 202, 203, 20, 42,
82061 /* 570 */ 43, 228, 170, 171, 19, 42, 43, 37, 23, 39,
82062 /* 580 */ 228, 170, 171, 236, 7, 8, 9, 170, 171, 49,
82063 /* 590 */ 63, 64, 190, 60, 61, 62, 63, 64, 65, 66,
82064 /* 600 */ 67, 68, 69, 70, 71, 72, 148, 74, 75, 76,
82065 /* 610 */ 77, 78, 79, 80, 81, 82, 83, 84, 16, 92,
82066 /* 620 */ 14, 159, 18, 21, 162, 163, 164, 216, 170, 171,
82067 /* 630 */ 19, 244, 245, 216, 23, 19, 20, 106, 22, 108,
82068 /* 640 */ 109, 148, 193, 88, 42, 43, 20, 204, 106, 200,
82069 /* 650 */ 108, 109, 202, 203, 106, 148, 108, 109, 52, 55,
82070 /* 660 */ 54, 16, 60, 61, 62, 63, 64, 65, 66, 67,
82071 /* 670 */ 68, 69, 70, 71, 72, 59, 74, 75, 76, 77,
82072 /* 680 */ 78, 79, 80, 81, 82, 83, 84, 42, 43, 99,
82073 /* 690 */ 100, 101, 20, 106, 22, 108, 109, 162, 94, 88,
82074 /* 700 */ 89, 14, 151, 162, 16, 60, 61, 62, 63, 64,
82075 /* 710 */ 65, 66, 67, 68, 69, 70, 71, 72, 23, 74,
82076 /* 720 */ 75, 76, 77, 78, 79, 80, 81, 82, 83, 84,
82077 /* 730 */ 42, 43, 106, 148, 108, 109, 201, 148, 134, 52,
82078 /* 740 */ 134, 54, 201, 99, 100, 101, 162, 16, 60, 61,
82079 /* 750 */ 62, 63, 64, 65, 66, 67, 68, 69, 70, 71,
82080 /* 760 */ 72, 89, 74, 75, 76, 77, 78, 79, 80, 81,
82081 /* 770 */ 82, 83, 84, 42, 43, 80, 225, 110, 189, 146,
82082 /* 780 */ 148, 230, 16, 88, 89, 201, 114, 148, 148, 148,
82083 /* 790 */ 16, 124, 61, 62, 63, 64, 65, 66, 67, 68,
82084 /* 800 */ 69, 70, 71, 72, 80, 74, 75, 76, 77, 78,
82085 /* 810 */ 79, 80, 81, 82, 83, 84, 42, 43, 23, 19,
82086 /* 820 */ 23, 189, 183, 23, 183, 148, 148, 148, 148, 189,
82087 /* 830 */ 192, 107, 19, 22, 21, 111, 62, 63, 64, 65,
82088 /* 840 */ 66, 67, 68, 69, 70, 71, 72, 148, 74, 75,
82089 /* 850 */ 76, 77, 78, 79, 80, 81, 82, 83, 84, 16,
82090 /* 860 */ 17, 148, 19, 183, 148, 162, 23, 148, 189, 170,
82091 /* 870 */ 171, 148, 16, 148, 31, 16, 17, 131, 19, 133,
82092 /* 880 */ 148, 115, 23, 88, 89, 88, 89, 209, 88, 89,
82093 /* 890 */ 31, 48, 148, 170, 171, 170, 171, 148, 148, 43,
82094 /* 900 */ 89, 58, 170, 171, 148, 189, 148, 48, 189, 114,
82095 /* 910 */ 43, 114, 22, 148, 19, 242, 243, 58, 148, 170,
82096 /* 920 */ 171, 78, 79, 148, 156, 114, 170, 171, 170, 171,
82097 /* 930 */ 87, 88, 89, 125, 126, 92, 27, 78, 79, 80,
82098 /* 940 */ 170, 171, 91, 34, 148, 233, 87, 88, 89, 16,
82099 /* 950 */ 17, 92, 19, 110, 98, 148, 23, 148, 190, 103,
82100 /* 960 */ 148, 110, 156, 213, 31, 98, 170, 171, 125, 126,
82101 /* 970 */ 127, 128, 129, 130, 209, 124, 156, 170, 171, 170,
82102 /* 980 */ 171, 48, 170, 171, 125, 126, 127, 128, 129, 130,
82103 /* 990 */ 16, 58, 156, 5, 22, 148, 190, 20, 10, 11,
82104 /* 1000 */ 12, 13, 20, 113, 22, 148, 148, 112, 148, 148,
82105 /* 1010 */ 190, 78, 79, 20, 26, 22, 28, 170, 171, 148,
82106 /* 1020 */ 87, 88, 89, 35, 148, 92, 190, 170, 171, 148,
82107 /* 1030 */ 170, 171, 148, 19, 148, 47, 59, 49, 7, 8,
82108 /* 1040 */ 148, 53, 148, 179, 56, 148, 170, 171, 148, 148,
82109 /* 1050 */ 148, 170, 171, 148, 170, 171, 170, 171, 125, 126,
82110 /* 1060 */ 127, 128, 129, 130, 170, 171, 92, 170, 171, 148,
82111 /* 1070 */ 170, 171, 170, 171, 148, 170, 171, 148, 179, 148,
82112 /* 1080 */ 91, 92, 68, 20, 148, 22, 148, 99, 100, 101,
82113 /* 1090 */ 148, 170, 171, 105, 122, 148, 179, 148, 110, 170,
82114 /* 1100 */ 171, 170, 171, 148, 148, 148, 170, 171, 170, 171,
82115 /* 1110 */ 148, 92, 170, 171, 20, 148, 22, 170, 171, 170,
82116 /* 1120 */ 171, 148, 103, 135, 148, 170, 171, 170, 171, 148,
82117 /* 1130 */ 20, 148, 22, 148, 20, 148, 22, 170, 171, 20,
82118 /* 1140 */ 20, 22, 22, 170, 171, 148, 20, 20, 22, 22,
82119 /* 1150 */ 148, 170, 171, 170, 171, 170, 171, 170, 171, 232,
82120 /* 1160 */ 148, 148, 192, 148, 148, 148, 148, 162, 148, 148,
82121 /* 1170 */ 148, 148, 148, 148, 148, 229, 224, 150, 194, 229,
82122 /* 1180 */ 173, 173, 173, 205, 178, 174, 195, 6, 147, 195,
82123 /* 1190 */ 147, 162, 147, 147, 162, 205, 22, 205, 122, 155,
82124 /* 1200 */ 190, 173, 119, 173, 120, 118, 121, 112, 131, 223,
82125 /* 1210 */ 153, 153, 40, 98, 117, 98, 19, 84, 97, 15,
82126 /* 1220 */ 152, 172, 172, 153, 172, 226, 172, 174, 195, 226,
82127 /* 1230 */ 196, 180, 197, 172, 198, 175, 199, 172, 172, 180,
82128 /* 1240 */ 152, 152, 175, 153, 206, 153, 207, 207, 206, 153,
82129 /* 1250 */ 38, 152, 60, 206, 131, 207, 153, 185, 185, 19,
82130 /* 1260 */ 153, 15, 188, 188, 195, 153, 188, 188, 33, 153,
82131 /* 1270 */ 138, 185, 1, 160, 176, 195, 176, 215, 153, 215,
82132 /* 1280 */ 20, 112, 112, 112, 107, 112, 92, 19, 19, 234,
82133 /* 1290 */ 20, 235, 20, 11, 19, 22, 20, 20, 20, 116,
82134 /* 1300 */ 116, 22, 22, 114, 19, 112, 116, 20, 237, 20,
82135 /* 1310 */ 115, 44, 19, 32, 19, 96, 20, 19, 237, 19,
82136 /* 1320 */ 19, 103, 240, 16, 21, 17, 98, 44, 44, 98,
82137 /* 1330 */ 36, 22, 134, 45, 243, 45, 19, 51, 5, 246,
82138 /* 1340 */ 1, 102, 68, 123, 19, 113, 1, 117, 14, 17,
82139 /* 1350 */ 113, 102, 123, 136, 19, 14, 20, 124, 137, 68,
82140 /* 1360 */ 3, 57, 19, 4,
 
82141 };
82142 #define YY_SHIFT_USE_DFLT (-62)
82143 #define YY_SHIFT_MAX 398
82144 static const short yy_shift_ofst[] = {
82145 /* 0 */ 23, 843, 988, -16, 843, 933, 933, 393, 413, 252,
82146 /* 10 */ 96, 933, 933, 933, 933, 933, -45, 249, 174, 272,
82147 /* 20 */ -17, 19, 19, 0, 53, 165, 208, 251, 326, 395,
82148 /* 30 */ 464, 533, 602, 645, 688, 645, 645, 645, 645, 645,
82149 /* 40 */ 645, 645, 645, 645, 645, 645, 645, 645, 645, 645,
82150 /* 50 */ 645, 645, 645, 731, 774, 774, 859, 933, 933, 933,
82151 /* 60 */ 933, 933, 933, 933, 933, 933, 933, 933, 933, 933,
82152 /* 70 */ 933, 933, 933, 933, 933, 933, 933, 933, 933, 933,
82153 /* 80 */ 933, 933, 933, 933, 933, 933, 933, 933, 933, 933,
82154 /* 90 */ 933, 933, 933, 933, 933, 933, 933, -61, -61, 6,
82155 /* 100 */ 6, 281, 22, 226, 856, 604, 272, 272, 68, -17,
82156 /* 110 */ 85, -62, -62, -62, 131, 328, 540, 540, 125, 616,
82157 /* 120 */ 253, 358, 272, 358, 358, 272, 272, 272, 272, 272,
82158 /* 130 */ 272, 272, 272, 272, 272, 272, 272, 272, 272, 272,
82159 /* 140 */ 272, 272, 851, 667, 0, 0, 0, -62, -62, -62,
82160 /* 150 */ -18, -18, 335, 350, 531, 611, 542, 548, 176, 795,
82161 /* 160 */ 797, 800, 626, 672, 695, 577, 272, 272, 724, 272,
82162 /* 170 */ 272, 555, 272, 272, 811, 272, 272, 272, 272, 272,
82163 /* 180 */ 164, 164, 164, 272, 272, 272, 587, 272, 272, 587,
82164 /* 190 */ 272, 329, 590, 272, 272, 587, 272, 272, 272, 587,
82165 /* 200 */ 272, 272, 272, 587, 587, 272, 272, 272, 272, 272,
82166 /* 210 */ 813, 389, 890, -17, 808, 808, 746, 909, 909, 766,
82167 /* 220 */ 909, 867, 909, -17, 909, -17, 302, 972, 766, 766,
82168 /* 230 */ 972, 1181, 1181, 1181, 1181, 1174, 0, 1076, 1083, 1084,
82169 /* 240 */ 1087, 1085, 1077, 1095, 1095, 1115, 1097, 1115, 1097, 1115,
82170 /* 250 */ 1097, 1117, 1117, 1172, 1117, 1121, 1117, 1197, 1133, 1133,
82171 /* 260 */ 1172, 1117, 1117, 1117, 1197, 1204, 1095, 1204, 1095, 1204,
82172 /* 270 */ 1095, 1095, 1212, 1123, 1204, 1095, 1192, 1192, 1240, 1076,
82173 /* 280 */ 1095, 1246, 1246, 1246, 1246, 1076, 1192, 1240, 1095, 1235,
82174 /* 290 */ 1235, 1095, 1095, 1132, -62, -62, -62, -62, -62, 527,
82175 /* 300 */ 606, 644, 687, 895, 974, 982, 993, 1019, 1031, 989,
82176 /* 310 */ 1063, 1094, 1110, 1114, 1119, 1120, 1126, 1014, 1127, 977,
82177 /* 320 */ 1271, 1260, 1169, 1170, 1171, 1173, 1194, 1177, 1268, 1270,
82178 /* 330 */ 1272, 1269, 1282, 1275, 1276, 1273, 1277, 1278, 1279, 1183,
82179 /* 340 */ 1280, 1184, 1279, 1189, 1285, 1190, 1195, 1193, 1287, 1289,
82180 /* 350 */ 1281, 1267, 1293, 1283, 1295, 1296, 1298, 1300, 1284, 1301,
82181 /* 360 */ 1219, 1218, 1307, 1308, 1303, 1228, 1294, 1286, 1288, 1309,
82182 /* 370 */ 1290, 1198, 1231, 1317, 1333, 1339, 1239, 1274, 1291, 1220,
82183 /* 380 */ 1325, 1232, 1345, 1334, 1230, 1332, 1237, 1249, 1229, 1335,
82184 /* 390 */ 1233, 1336, 1341, 1304, 1217, 1221, 1343, 1357, 1359,
 
82185 };
82186 #define YY_REDUCE_USE_DFLT (-143)
82187 #define YY_REDUCE_MAX 298
82188 static const short yy_reduce_ofst[] = {
82189 /* 0 */ -139, 278, -3, -19, 402, -22, 345, 35, 37, 149,
82190 /* 10 */ -127, 133, 50, 351, 411, 417, -142, 347, 190, 293,
82191 /* 20 */ 462, 343, 352, 364, 146, 146, 146, 146, 146, 146,
82192 /* 30 */ 146, 146, 146, 146, 146, 146, 146, 146, 146, 146,
82193 /* 40 */ 146, 146, 146, 146, 146, 146, 146, 146, 146, 146,
82194 /* 50 */ 146, 146, 146, 146, 146, 146, 458, 699, 723, 725,
82195 /* 60 */ 732, 749, 756, 758, 770, 796, 807, 809, 812, 847,
82196 /* 70 */ 857, 860, 876, 881, 884, 886, 894, 897, 900, 902,
82197 /* 80 */ 905, 921, 929, 931, 936, 938, 942, 947, 949, 955,
82198 /* 90 */ 957, 967, 973, 981, 983, 985, 987, 146, 146, 146,
82199 /* 100 */ 146, 168, 146, 146, 28, 551, 193, 356, 146, -121,
82200 /* 110 */ 146, 146, 146, 146, 324, 258, 113, 227, 387, 387,
82201 /* 120 */ 310, 535, -136, 541, 584, -91, 195, 639, 641, 7,
82202 /* 130 */ 678, 680, 285, 765, 70, 589, 632, 640, 679, 716,
82203 /* 140 */ 750, 719, 333, 768, 806, 820, 836, 449, 450, 673,
82204 /* 150 */ 21, 52, 114, 120, 156, 294, 156, 156, 318, 409,
82205 /* 160 */ 412, 493, 156, 443, 507, 633, 585, 677, 638, 507,
82206 /* 170 */ 713, 703, 744, 775, 443, 858, 861, 871, 892, 901,
82207 /* 180 */ 864, 899, 917, 926, 956, 962, 156, 976, 997, 156,
82208 /* 190 */ 1002, 927, 712, 1012, 1013, 156, 1015, 1016, 1017, 156,
82209 /* 200 */ 1018, 1020, 1021, 156, 156, 1022, 1023, 1024, 1025, 1026,
82210 /* 210 */ 1027, 970, 984, 1005, 946, 950, 952, 1007, 1008, 978,
82211 /* 220 */ 1009, 1006, 1028, 1029, 1030, 1032, 1011, 991, 990, 992,
82212 /* 230 */ 994, 1041, 1043, 1045, 1046, 1044, 1010, 1033, 1034, 1035,
82213 /* 240 */ 1036, 1037, 986, 1057, 1058, 1038, 1039, 1042, 1040, 1047,
82214 /* 250 */ 1048, 1049, 1050, 1051, 1052, 1053, 1054, 1060, 999, 1003,
82215 /* 260 */ 1059, 1061, 1065, 1066, 1067, 1068, 1070, 1088, 1090, 1089,
82216 /* 270 */ 1092, 1096, 1055, 1056, 1099, 1103, 1072, 1073, 1062, 1069,
82217 /* 280 */ 1107, 1074, 1075, 1078, 1079, 1080, 1086, 1064, 1112, 1071,
82218 /* 290 */ 1081, 1116, 1125, 1082, 1113, 1098, 1100, 1091, 1093,
 
82219 };
82220 static const YYACTIONTYPE yy_default[] = {
82221 /* 0 */ 606, 834, 915, 722, 915, 834, 915, 915, 861, 915,
82222 /* 10 */ 890, 832, 915, 915, 915, 915, 806, 915, 861, 915,
82223 /* 20 */ 638, 861, 861, 726, 757, 915, 915, 915, 915, 915,
82224 /* 30 */ 915, 915, 915, 758, 915, 836, 831, 827, 829, 828,
82225 /* 40 */ 835, 759, 748, 755, 762, 737, 874, 764, 765, 771,
82226 /* 50 */ 772, 891, 889, 794, 793, 812, 915, 915, 915, 915,
82227 /* 60 */ 915, 915, 915, 915, 915, 915, 915, 915, 915, 915,
82228 /* 70 */ 915, 915, 915, 915, 915, 915, 915, 915, 915, 915,
82229 /* 80 */ 915, 915, 915, 915, 915, 915, 915, 915, 915, 915,
82230 /* 90 */ 915, 915, 915, 915, 915, 915, 915, 796, 818, 795,
82231 /* 100 */ 805, 631, 797, 798, 691, 626, 915, 915, 799, 915,
82232 /* 110 */ 800, 813, 814, 815, 915, 915, 915, 915, 915, 915,
82233 /* 120 */ 606, 722, 915, 722, 722, 915, 915, 915, 915, 915,
82234 /* 130 */ 915, 915, 915, 915, 915, 915, 915, 915, 915, 915,
82235 /* 140 */ 915, 915, 915, 915, 915, 915, 915, 716, 726, 908,
82236 /* 150 */ 915, 915, 682, 915, 915, 915, 915, 915, 915, 915,
82237 /* 160 */ 915, 915, 915, 915, 915, 614, 612, 915, 714, 915,
82238 /* 170 */ 915, 640, 915, 915, 724, 915, 915, 915, 915, 915,
82239 /* 180 */ 915, 915, 915, 915, 915, 915, 628, 915, 915, 703,
82240 /* 190 */ 915, 867, 915, 915, 915, 881, 915, 915, 915, 879,
82241 /* 200 */ 915, 915, 915, 705, 767, 847, 915, 894, 896, 915,
82242 /* 210 */ 915, 714, 723, 915, 915, 915, 830, 751, 751, 739,
82243 /* 220 */ 751, 661, 751, 915, 751, 915, 664, 761, 739, 739,
82244 /* 230 */ 761, 611, 611, 611, 611, 681, 915, 761, 752, 754,
82245 /* 240 */ 744, 756, 915, 730, 730, 738, 743, 738, 743, 738,
82246 /* 250 */ 743, 693, 693, 678, 693, 664, 693, 840, 844, 844,
82247 /* 260 */ 678, 693, 693, 693, 840, 623, 730, 623, 730, 623,
82248 /* 270 */ 730, 730, 871, 873, 623, 730, 695, 695, 773, 761,
82249 /* 280 */ 730, 702, 702, 702, 702, 761, 695, 773, 730, 893,
82250 /* 290 */ 893, 730, 730, 901, 648, 666, 666, 908, 913, 915,
82251 /* 300 */ 915, 915, 915, 780, 915, 915, 915, 915, 915, 915,
82252 /* 310 */ 915, 915, 915, 915, 915, 915, 915, 854, 915, 915,
82253 /* 320 */ 915, 915, 785, 781, 915, 782, 915, 708, 915, 915,
82254 /* 330 */ 915, 915, 915, 915, 915, 915, 915, 915, 833, 915,
82255 /* 340 */ 745, 915, 753, 915, 915, 915, 915, 915, 915, 915,
82256 /* 350 */ 915, 915, 915, 915, 915, 915, 915, 915, 915, 915,
82257 /* 360 */ 915, 915, 915, 915, 915, 915, 915, 915, 869, 870,
82258 /* 370 */ 915, 915, 915, 915, 915, 915, 915, 915, 915, 915,
82259 /* 380 */ 915, 915, 915, 915, 915, 915, 915, 915, 915, 915,
82260 /* 390 */ 915, 915, 915, 900, 915, 915, 903, 607, 915, 602,
82261 /* 400 */ 604, 605, 609, 610, 613, 635, 636, 637, 615, 616,
82262 /* 410 */ 617, 618, 619, 620, 621, 627, 629, 647, 649, 633,
82263 /* 420 */ 651, 712, 713, 777, 706, 707, 711, 634, 788, 779,
82264 /* 430 */ 783, 784, 786, 787, 801, 802, 804, 810, 817, 820,
82265 /* 440 */ 803, 808, 809, 811, 816, 819, 709, 710, 823, 641,
82266 /* 450 */ 642, 645, 646, 857, 859, 858, 860, 644, 643, 789,
82267 /* 460 */ 792, 825, 826, 882, 883, 884, 885, 886, 821, 731,
82268 /* 470 */ 824, 807, 746, 749, 750, 747, 715, 725, 733, 734,
82269 /* 480 */ 735, 736, 720, 721, 727, 742, 775, 776, 740, 741,
82270 /* 490 */ 728, 729, 717, 718, 719, 822, 778, 790, 791, 652,
82271 /* 500 */ 653, 785, 654, 655, 656, 694, 697, 698, 699, 657,
82272 /* 510 */ 676, 679, 680, 658, 665, 659, 660, 667, 668, 669,
82273 /* 520 */ 672, 673, 674, 675, 670, 671, 841, 842, 845, 843,
82274 /* 530 */ 662, 663, 677, 650, 639, 632, 683, 686, 687, 688,
82275 /* 540 */ 689, 690, 692, 684, 685, 630, 622, 624, 732, 863,
82276 /* 550 */ 872, 868, 864, 865, 866, 625, 837, 838, 696, 769,
82277 /* 560 */ 770, 862, 875, 877, 774, 878, 880, 876, 905, 700,
82278 /* 570 */ 701, 704, 846, 887, 760, 763, 766, 768, 848, 849,
82279 /* 580 */ 850, 851, 852, 855, 856, 853, 888, 892, 895, 897,
82280 /* 590 */ 898, 899, 902, 904, 909, 910, 911, 914, 912, 608,
82281 /* 600 */ 603,
82282 };
82283 #define YY_SZ_ACTTAB (int)(sizeof(yy_action)/sizeof(yy_action[0]))
82284
82285 /* The next table maps tokens into fallback tokens. If a construct
82286 ** like the following:
@@ -82294,67 +83339,70 @@
82294 */
82295 #ifdef YYFALLBACK
82296 static const YYCODETYPE yyFallback[] = {
82297 0, /* $ => nothing */
82298 0, /* SEMI => nothing */
82299 23, /* EXPLAIN => ID */
82300 23, /* QUERY => ID */
82301 23, /* PLAN => ID */
82302 23, /* BEGIN => ID */
82303 0, /* TRANSACTION => nothing */
82304 23, /* DEFERRED => ID */
82305 23, /* IMMEDIATE => ID */
82306 23, /* EXCLUSIVE => ID */
82307 0, /* COMMIT => nothing */
82308 23, /* END => ID */
82309 0, /* ROLLBACK => nothing */
 
 
 
82310 0, /* CREATE => nothing */
82311 0, /* TABLE => nothing */
82312 23, /* IF => ID */
82313 0, /* NOT => nothing */
82314 0, /* EXISTS => nothing */
82315 23, /* TEMP => ID */
82316 0, /* LP => nothing */
82317 0, /* RP => nothing */
82318 0, /* AS => nothing */
82319 0, /* COMMA => nothing */
82320 0, /* ID => nothing */
82321 23, /* ABORT => ID */
82322 23, /* AFTER => ID */
82323 23, /* ANALYZE => ID */
82324 23, /* ASC => ID */
82325 23, /* ATTACH => ID */
82326 23, /* BEFORE => ID */
82327 23, /* CASCADE => ID */
82328 23, /* CAST => ID */
82329 23, /* CONFLICT => ID */
82330 23, /* DATABASE => ID */
82331 23, /* DESC => ID */
82332 23, /* DETACH => ID */
82333 23, /* EACH => ID */
82334 23, /* FAIL => ID */
82335 23, /* FOR => ID */
82336 23, /* IGNORE => ID */
82337 23, /* INITIALLY => ID */
82338 23, /* INSTEAD => ID */
82339 23, /* LIKE_KW => ID */
82340 23, /* MATCH => ID */
82341 23, /* KEY => ID */
82342 23, /* OF => ID */
82343 23, /* OFFSET => ID */
82344 23, /* PRAGMA => ID */
82345 23, /* RAISE => ID */
82346 23, /* REPLACE => ID */
82347 23, /* RESTRICT => ID */
82348 23, /* ROW => ID */
82349 23, /* TRIGGER => ID */
82350 23, /* VACUUM => ID */
82351 23, /* VIEW => ID */
82352 23, /* VIRTUAL => ID */
82353 23, /* REINDEX => ID */
82354 23, /* RENAME => ID */
82355 23, /* CTIME_KW => ID */
82356 0, /* ANY => nothing */
82357 0, /* OR => nothing */
82358 0, /* AND => nothing */
82359 0, /* IS => nothing */
82360 0, /* BETWEEN => nothing */
@@ -82428,11 +83476,10 @@
82428 0, /* WHEN => nothing */
82429 0, /* THEN => nothing */
82430 0, /* ELSE => nothing */
82431 0, /* INDEX => nothing */
82432 0, /* ALTER => nothing */
82433 0, /* TO => nothing */
82434 0, /* ADD => nothing */
82435 0, /* COLUMNKW => nothing */
82436 };
82437 #endif /* YYFALLBACK */
82438
@@ -82511,69 +83558,70 @@
82511 ** are required. The following table supplies these names */
82512 static const char *const yyTokenName[] = {
82513 "$", "SEMI", "EXPLAIN", "QUERY",
82514 "PLAN", "BEGIN", "TRANSACTION", "DEFERRED",
82515 "IMMEDIATE", "EXCLUSIVE", "COMMIT", "END",
82516 "ROLLBACK", "CREATE", "TABLE", "IF",
82517 "NOT", "EXISTS", "TEMP", "LP",
82518 "RP", "AS", "COMMA", "ID",
82519 "ABORT", "AFTER", "ANALYZE", "ASC",
82520 "ATTACH", "BEFORE", "CASCADE", "CAST",
82521 "CONFLICT", "DATABASE", "DESC", "DETACH",
82522 "EACH", "FAIL", "FOR", "IGNORE",
82523 "INITIALLY", "INSTEAD", "LIKE_KW", "MATCH",
82524 "KEY", "OF", "OFFSET", "PRAGMA",
82525 "RAISE", "REPLACE", "RESTRICT", "ROW",
82526 "TRIGGER", "VACUUM", "VIEW", "VIRTUAL",
82527 "REINDEX", "RENAME", "CTIME_KW", "ANY",
82528 "OR", "AND", "IS", "BETWEEN",
82529 "IN", "ISNULL", "NOTNULL", "NE",
82530 "EQ", "GT", "LE", "LT",
82531 "GE", "ESCAPE", "BITAND", "BITOR",
82532 "LSHIFT", "RSHIFT", "PLUS", "MINUS",
82533 "STAR", "SLASH", "REM", "CONCAT",
82534 "COLLATE", "UMINUS", "UPLUS", "BITNOT",
82535 "STRING", "JOIN_KW", "CONSTRAINT", "DEFAULT",
82536 "NULL", "PRIMARY", "UNIQUE", "CHECK",
82537 "REFERENCES", "AUTOINCR", "ON", "DELETE",
82538 "UPDATE", "INSERT", "SET", "DEFERRABLE",
82539 "FOREIGN", "DROP", "UNION", "ALL",
82540 "EXCEPT", "INTERSECT", "SELECT", "DISTINCT",
82541 "DOT", "FROM", "JOIN", "INDEXED",
82542 "BY", "USING", "ORDER", "GROUP",
82543 "HAVING", "LIMIT", "WHERE", "INTO",
82544 "VALUES", "INTEGER", "FLOAT", "BLOB",
82545 "REGISTER", "VARIABLE", "CASE", "WHEN",
82546 "THEN", "ELSE", "INDEX", "ALTER",
82547 "TO", "ADD", "COLUMNKW", "error",
82548 "input", "cmdlist", "ecmd", "explain",
82549 "cmdx", "cmd", "transtype", "trans_opt",
82550 "nm", "create_table", "create_table_args", "temp",
82551 "ifnotexists", "dbnm", "columnlist", "conslist_opt",
82552 "select", "column", "columnid", "type",
82553 "carglist", "id", "ids", "typetoken",
82554 "typename", "signed", "plus_num", "minus_num",
82555 "carg", "ccons", "term", "expr",
82556 "onconf", "sortorder", "autoinc", "idxlist_opt",
82557 "refargs", "defer_subclause", "refarg", "refact",
82558 "init_deferred_pred_opt", "conslist", "tcons", "idxlist",
82559 "defer_subclause_opt", "orconf", "resolvetype", "raisetype",
82560 "ifexists", "fullname", "oneselect", "multiselect_op",
82561 "distinct", "selcollist", "from", "where_opt",
82562 "groupby_opt", "having_opt", "orderby_opt", "limit_opt",
82563 "sclp", "as", "seltablist", "stl_prefix",
82564 "joinop", "indexed_opt", "on_opt", "using_opt",
82565 "joinop2", "inscollist", "sortlist", "sortitem",
82566 "nexprlist", "setlist", "insert_cmd", "inscollist_opt",
82567 "itemlist", "exprlist", "likeop", "escape",
82568 "between_op", "in_op", "case_operand", "case_exprlist",
82569 "case_else", "uniqueflag", "collate", "nmnum",
82570 "plus_opt", "number", "trigger_decl", "trigger_cmd_list",
82571 "trigger_time", "trigger_event", "foreach_clause", "when_clause",
82572 "trigger_cmd", "database_kw_opt", "key_opt", "add_column_fullname",
82573 "kwcolumn_opt", "create_vtab", "vtabarglist", "vtabarg",
82574 "vtabargtoken", "lp", "anylist",
 
82575 };
82576 #endif /* NDEBUG */
82577
82578 #ifndef NDEBUG
82579 /* For tracing reduce actions, the names of all rules are required.
@@ -82597,304 +83645,309 @@
82597 /* 15 */ "transtype ::= IMMEDIATE",
82598 /* 16 */ "transtype ::= EXCLUSIVE",
82599 /* 17 */ "cmd ::= COMMIT trans_opt",
82600 /* 18 */ "cmd ::= END trans_opt",
82601 /* 19 */ "cmd ::= ROLLBACK trans_opt",
82602 /* 20 */ "cmd ::= create_table create_table_args",
82603 /* 21 */ "create_table ::= CREATE temp TABLE ifnotexists nm dbnm",
82604 /* 22 */ "ifnotexists ::=",
82605 /* 23 */ "ifnotexists ::= IF NOT EXISTS",
82606 /* 24 */ "temp ::= TEMP",
82607 /* 25 */ "temp ::=",
82608 /* 26 */ "create_table_args ::= LP columnlist conslist_opt RP",
82609 /* 27 */ "create_table_args ::= AS select",
82610 /* 28 */ "columnlist ::= columnlist COMMA column",
82611 /* 29 */ "columnlist ::= column",
82612 /* 30 */ "column ::= columnid type carglist",
82613 /* 31 */ "columnid ::= nm",
82614 /* 32 */ "id ::= ID",
82615 /* 33 */ "ids ::= ID|STRING",
82616 /* 34 */ "nm ::= ID",
82617 /* 35 */ "nm ::= STRING",
82618 /* 36 */ "nm ::= JOIN_KW",
82619 /* 37 */ "type ::=",
82620 /* 38 */ "type ::= typetoken",
82621 /* 39 */ "typetoken ::= typename",
82622 /* 40 */ "typetoken ::= typename LP signed RP",
82623 /* 41 */ "typetoken ::= typename LP signed COMMA signed RP",
82624 /* 42 */ "typename ::= ids",
82625 /* 43 */ "typename ::= typename ids",
82626 /* 44 */ "signed ::= plus_num",
82627 /* 45 */ "signed ::= minus_num",
82628 /* 46 */ "carglist ::= carglist carg",
82629 /* 47 */ "carglist ::=",
82630 /* 48 */ "carg ::= CONSTRAINT nm ccons",
82631 /* 49 */ "carg ::= ccons",
82632 /* 50 */ "ccons ::= DEFAULT term",
82633 /* 51 */ "ccons ::= DEFAULT LP expr RP",
82634 /* 52 */ "ccons ::= DEFAULT PLUS term",
82635 /* 53 */ "ccons ::= DEFAULT MINUS term",
82636 /* 54 */ "ccons ::= DEFAULT id",
82637 /* 55 */ "ccons ::= NULL onconf",
82638 /* 56 */ "ccons ::= NOT NULL onconf",
82639 /* 57 */ "ccons ::= PRIMARY KEY sortorder onconf autoinc",
82640 /* 58 */ "ccons ::= UNIQUE onconf",
82641 /* 59 */ "ccons ::= CHECK LP expr RP",
82642 /* 60 */ "ccons ::= REFERENCES nm idxlist_opt refargs",
82643 /* 61 */ "ccons ::= defer_subclause",
82644 /* 62 */ "ccons ::= COLLATE ids",
82645 /* 63 */ "autoinc ::=",
82646 /* 64 */ "autoinc ::= AUTOINCR",
82647 /* 65 */ "refargs ::=",
82648 /* 66 */ "refargs ::= refargs refarg",
82649 /* 67 */ "refarg ::= MATCH nm",
82650 /* 68 */ "refarg ::= ON DELETE refact",
82651 /* 69 */ "refarg ::= ON UPDATE refact",
82652 /* 70 */ "refarg ::= ON INSERT refact",
82653 /* 71 */ "refact ::= SET NULL",
82654 /* 72 */ "refact ::= SET DEFAULT",
82655 /* 73 */ "refact ::= CASCADE",
82656 /* 74 */ "refact ::= RESTRICT",
82657 /* 75 */ "defer_subclause ::= NOT DEFERRABLE init_deferred_pred_opt",
82658 /* 76 */ "defer_subclause ::= DEFERRABLE init_deferred_pred_opt",
82659 /* 77 */ "init_deferred_pred_opt ::=",
82660 /* 78 */ "init_deferred_pred_opt ::= INITIALLY DEFERRED",
82661 /* 79 */ "init_deferred_pred_opt ::= INITIALLY IMMEDIATE",
82662 /* 80 */ "conslist_opt ::=",
82663 /* 81 */ "conslist_opt ::= COMMA conslist",
82664 /* 82 */ "conslist ::= conslist COMMA tcons",
82665 /* 83 */ "conslist ::= conslist tcons",
82666 /* 84 */ "conslist ::= tcons",
82667 /* 85 */ "tcons ::= CONSTRAINT nm",
82668 /* 86 */ "tcons ::= PRIMARY KEY LP idxlist autoinc RP onconf",
82669 /* 87 */ "tcons ::= UNIQUE LP idxlist RP onconf",
82670 /* 88 */ "tcons ::= CHECK LP expr RP onconf",
82671 /* 89 */ "tcons ::= FOREIGN KEY LP idxlist RP REFERENCES nm idxlist_opt refargs defer_subclause_opt",
82672 /* 90 */ "defer_subclause_opt ::=",
82673 /* 91 */ "defer_subclause_opt ::= defer_subclause",
82674 /* 92 */ "onconf ::=",
82675 /* 93 */ "onconf ::= ON CONFLICT resolvetype",
82676 /* 94 */ "orconf ::=",
82677 /* 95 */ "orconf ::= OR resolvetype",
82678 /* 96 */ "resolvetype ::= raisetype",
82679 /* 97 */ "resolvetype ::= IGNORE",
82680 /* 98 */ "resolvetype ::= REPLACE",
82681 /* 99 */ "cmd ::= DROP TABLE ifexists fullname",
82682 /* 100 */ "ifexists ::= IF EXISTS",
82683 /* 101 */ "ifexists ::=",
82684 /* 102 */ "cmd ::= CREATE temp VIEW ifnotexists nm dbnm AS select",
82685 /* 103 */ "cmd ::= DROP VIEW ifexists fullname",
82686 /* 104 */ "cmd ::= select",
82687 /* 105 */ "select ::= oneselect",
82688 /* 106 */ "select ::= select multiselect_op oneselect",
82689 /* 107 */ "multiselect_op ::= UNION",
82690 /* 108 */ "multiselect_op ::= UNION ALL",
82691 /* 109 */ "multiselect_op ::= EXCEPT|INTERSECT",
82692 /* 110 */ "oneselect ::= SELECT distinct selcollist from where_opt groupby_opt having_opt orderby_opt limit_opt",
82693 /* 111 */ "distinct ::= DISTINCT",
82694 /* 112 */ "distinct ::= ALL",
82695 /* 113 */ "distinct ::=",
82696 /* 114 */ "sclp ::= selcollist COMMA",
82697 /* 115 */ "sclp ::=",
82698 /* 116 */ "selcollist ::= sclp expr as",
82699 /* 117 */ "selcollist ::= sclp STAR",
82700 /* 118 */ "selcollist ::= sclp nm DOT STAR",
82701 /* 119 */ "as ::= AS nm",
82702 /* 120 */ "as ::= ids",
82703 /* 121 */ "as ::=",
82704 /* 122 */ "from ::=",
82705 /* 123 */ "from ::= FROM seltablist",
82706 /* 124 */ "stl_prefix ::= seltablist joinop",
82707 /* 125 */ "stl_prefix ::=",
82708 /* 126 */ "seltablist ::= stl_prefix nm dbnm as indexed_opt on_opt using_opt",
82709 /* 127 */ "seltablist ::= stl_prefix LP select RP as on_opt using_opt",
82710 /* 128 */ "seltablist ::= stl_prefix LP seltablist RP as on_opt using_opt",
82711 /* 129 */ "dbnm ::=",
82712 /* 130 */ "dbnm ::= DOT nm",
82713 /* 131 */ "fullname ::= nm dbnm",
82714 /* 132 */ "joinop ::= COMMA|JOIN",
82715 /* 133 */ "joinop ::= JOIN_KW JOIN",
82716 /* 134 */ "joinop ::= JOIN_KW nm JOIN",
82717 /* 135 */ "joinop ::= JOIN_KW nm nm JOIN",
82718 /* 136 */ "on_opt ::= ON expr",
82719 /* 137 */ "on_opt ::=",
82720 /* 138 */ "indexed_opt ::=",
82721 /* 139 */ "indexed_opt ::= INDEXED BY nm",
82722 /* 140 */ "indexed_opt ::= NOT INDEXED",
82723 /* 141 */ "using_opt ::= USING LP inscollist RP",
82724 /* 142 */ "using_opt ::=",
82725 /* 143 */ "orderby_opt ::=",
82726 /* 144 */ "orderby_opt ::= ORDER BY sortlist",
82727 /* 145 */ "sortlist ::= sortlist COMMA sortitem sortorder",
82728 /* 146 */ "sortlist ::= sortitem sortorder",
82729 /* 147 */ "sortitem ::= expr",
82730 /* 148 */ "sortorder ::= ASC",
82731 /* 149 */ "sortorder ::= DESC",
82732 /* 150 */ "sortorder ::=",
82733 /* 151 */ "groupby_opt ::=",
82734 /* 152 */ "groupby_opt ::= GROUP BY nexprlist",
82735 /* 153 */ "having_opt ::=",
82736 /* 154 */ "having_opt ::= HAVING expr",
82737 /* 155 */ "limit_opt ::=",
82738 /* 156 */ "limit_opt ::= LIMIT expr",
82739 /* 157 */ "limit_opt ::= LIMIT expr OFFSET expr",
82740 /* 158 */ "limit_opt ::= LIMIT expr COMMA expr",
82741 /* 159 */ "cmd ::= DELETE FROM fullname indexed_opt where_opt",
82742 /* 160 */ "where_opt ::=",
82743 /* 161 */ "where_opt ::= WHERE expr",
82744 /* 162 */ "cmd ::= UPDATE orconf fullname indexed_opt SET setlist where_opt",
82745 /* 163 */ "setlist ::= setlist COMMA nm EQ expr",
82746 /* 164 */ "setlist ::= nm EQ expr",
82747 /* 165 */ "cmd ::= insert_cmd INTO fullname inscollist_opt VALUES LP itemlist RP",
82748 /* 166 */ "cmd ::= insert_cmd INTO fullname inscollist_opt select",
82749 /* 167 */ "cmd ::= insert_cmd INTO fullname inscollist_opt DEFAULT VALUES",
82750 /* 168 */ "insert_cmd ::= INSERT orconf",
82751 /* 169 */ "insert_cmd ::= REPLACE",
82752 /* 170 */ "itemlist ::= itemlist COMMA expr",
82753 /* 171 */ "itemlist ::= expr",
82754 /* 172 */ "inscollist_opt ::=",
82755 /* 173 */ "inscollist_opt ::= LP inscollist RP",
82756 /* 174 */ "inscollist ::= inscollist COMMA nm",
82757 /* 175 */ "inscollist ::= nm",
82758 /* 176 */ "expr ::= term",
82759 /* 177 */ "expr ::= LP expr RP",
82760 /* 178 */ "term ::= NULL",
82761 /* 179 */ "expr ::= ID",
82762 /* 180 */ "expr ::= JOIN_KW",
82763 /* 181 */ "expr ::= nm DOT nm",
82764 /* 182 */ "expr ::= nm DOT nm DOT nm",
82765 /* 183 */ "term ::= INTEGER|FLOAT|BLOB",
82766 /* 184 */ "term ::= STRING",
82767 /* 185 */ "expr ::= REGISTER",
82768 /* 186 */ "expr ::= VARIABLE",
82769 /* 187 */ "expr ::= expr COLLATE ids",
82770 /* 188 */ "expr ::= CAST LP expr AS typetoken RP",
82771 /* 189 */ "expr ::= ID LP distinct exprlist RP",
82772 /* 190 */ "expr ::= ID LP STAR RP",
82773 /* 191 */ "term ::= CTIME_KW",
82774 /* 192 */ "expr ::= expr AND expr",
82775 /* 193 */ "expr ::= expr OR expr",
82776 /* 194 */ "expr ::= expr LT|GT|GE|LE expr",
82777 /* 195 */ "expr ::= expr EQ|NE expr",
82778 /* 196 */ "expr ::= expr BITAND|BITOR|LSHIFT|RSHIFT expr",
82779 /* 197 */ "expr ::= expr PLUS|MINUS expr",
82780 /* 198 */ "expr ::= expr STAR|SLASH|REM expr",
82781 /* 199 */ "expr ::= expr CONCAT expr",
82782 /* 200 */ "likeop ::= LIKE_KW",
82783 /* 201 */ "likeop ::= NOT LIKE_KW",
82784 /* 202 */ "likeop ::= MATCH",
82785 /* 203 */ "likeop ::= NOT MATCH",
82786 /* 204 */ "escape ::= ESCAPE expr",
82787 /* 205 */ "escape ::=",
82788 /* 206 */ "expr ::= expr likeop expr escape",
82789 /* 207 */ "expr ::= expr ISNULL|NOTNULL",
82790 /* 208 */ "expr ::= expr IS NULL",
82791 /* 209 */ "expr ::= expr NOT NULL",
82792 /* 210 */ "expr ::= expr IS NOT NULL",
82793 /* 211 */ "expr ::= NOT expr",
82794 /* 212 */ "expr ::= BITNOT expr",
82795 /* 213 */ "expr ::= MINUS expr",
82796 /* 214 */ "expr ::= PLUS expr",
82797 /* 215 */ "between_op ::= BETWEEN",
82798 /* 216 */ "between_op ::= NOT BETWEEN",
82799 /* 217 */ "expr ::= expr between_op expr AND expr",
82800 /* 218 */ "in_op ::= IN",
82801 /* 219 */ "in_op ::= NOT IN",
82802 /* 220 */ "expr ::= expr in_op LP exprlist RP",
82803 /* 221 */ "expr ::= LP select RP",
82804 /* 222 */ "expr ::= expr in_op LP select RP",
82805 /* 223 */ "expr ::= expr in_op nm dbnm",
82806 /* 224 */ "expr ::= EXISTS LP select RP",
82807 /* 225 */ "expr ::= CASE case_operand case_exprlist case_else END",
82808 /* 226 */ "case_exprlist ::= case_exprlist WHEN expr THEN expr",
82809 /* 227 */ "case_exprlist ::= WHEN expr THEN expr",
82810 /* 228 */ "case_else ::= ELSE expr",
82811 /* 229 */ "case_else ::=",
82812 /* 230 */ "case_operand ::= expr",
82813 /* 231 */ "case_operand ::=",
82814 /* 232 */ "exprlist ::= nexprlist",
82815 /* 233 */ "exprlist ::=",
82816 /* 234 */ "nexprlist ::= nexprlist COMMA expr",
82817 /* 235 */ "nexprlist ::= expr",
82818 /* 236 */ "cmd ::= CREATE uniqueflag INDEX ifnotexists nm dbnm ON nm LP idxlist RP",
82819 /* 237 */ "uniqueflag ::= UNIQUE",
82820 /* 238 */ "uniqueflag ::=",
82821 /* 239 */ "idxlist_opt ::=",
82822 /* 240 */ "idxlist_opt ::= LP idxlist RP",
82823 /* 241 */ "idxlist ::= idxlist COMMA nm collate sortorder",
82824 /* 242 */ "idxlist ::= nm collate sortorder",
82825 /* 243 */ "collate ::=",
82826 /* 244 */ "collate ::= COLLATE ids",
82827 /* 245 */ "cmd ::= DROP INDEX ifexists fullname",
82828 /* 246 */ "cmd ::= VACUUM",
82829 /* 247 */ "cmd ::= VACUUM nm",
82830 /* 248 */ "cmd ::= PRAGMA nm dbnm EQ nmnum",
82831 /* 249 */ "cmd ::= PRAGMA nm dbnm EQ ON",
82832 /* 250 */ "cmd ::= PRAGMA nm dbnm EQ DELETE",
82833 /* 251 */ "cmd ::= PRAGMA nm dbnm EQ minus_num",
82834 /* 252 */ "cmd ::= PRAGMA nm dbnm LP nmnum RP",
82835 /* 253 */ "cmd ::= PRAGMA nm dbnm",
82836 /* 254 */ "nmnum ::= plus_num",
82837 /* 255 */ "nmnum ::= nm",
82838 /* 256 */ "plus_num ::= plus_opt number",
82839 /* 257 */ "minus_num ::= MINUS number",
82840 /* 258 */ "number ::= INTEGER|FLOAT",
82841 /* 259 */ "plus_opt ::= PLUS",
82842 /* 260 */ "plus_opt ::=",
82843 /* 261 */ "cmd ::= CREATE trigger_decl BEGIN trigger_cmd_list END",
82844 /* 262 */ "trigger_decl ::= temp TRIGGER ifnotexists nm dbnm trigger_time trigger_event ON fullname foreach_clause when_clause",
82845 /* 263 */ "trigger_time ::= BEFORE",
82846 /* 264 */ "trigger_time ::= AFTER",
82847 /* 265 */ "trigger_time ::= INSTEAD OF",
82848 /* 266 */ "trigger_time ::=",
82849 /* 267 */ "trigger_event ::= DELETE|INSERT",
82850 /* 268 */ "trigger_event ::= UPDATE",
82851 /* 269 */ "trigger_event ::= UPDATE OF inscollist",
82852 /* 270 */ "foreach_clause ::=",
82853 /* 271 */ "foreach_clause ::= FOR EACH ROW",
82854 /* 272 */ "when_clause ::=",
82855 /* 273 */ "when_clause ::= WHEN expr",
82856 /* 274 */ "trigger_cmd_list ::= trigger_cmd_list trigger_cmd SEMI",
82857 /* 275 */ "trigger_cmd_list ::= trigger_cmd SEMI",
82858 /* 276 */ "trigger_cmd ::= UPDATE orconf nm SET setlist where_opt",
82859 /* 277 */ "trigger_cmd ::= insert_cmd INTO nm inscollist_opt VALUES LP itemlist RP",
82860 /* 278 */ "trigger_cmd ::= insert_cmd INTO nm inscollist_opt select",
82861 /* 279 */ "trigger_cmd ::= DELETE FROM nm where_opt",
82862 /* 280 */ "trigger_cmd ::= select",
82863 /* 281 */ "expr ::= RAISE LP IGNORE RP",
82864 /* 282 */ "expr ::= RAISE LP raisetype COMMA nm RP",
82865 /* 283 */ "raisetype ::= ROLLBACK",
82866 /* 284 */ "raisetype ::= ABORT",
82867 /* 285 */ "raisetype ::= FAIL",
82868 /* 286 */ "cmd ::= DROP TRIGGER ifexists fullname",
82869 /* 287 */ "cmd ::= ATTACH database_kw_opt expr AS expr key_opt",
82870 /* 288 */ "cmd ::= DETACH database_kw_opt expr",
82871 /* 289 */ "key_opt ::=",
82872 /* 290 */ "key_opt ::= KEY expr",
82873 /* 291 */ "database_kw_opt ::= DATABASE",
82874 /* 292 */ "database_kw_opt ::=",
82875 /* 293 */ "cmd ::= REINDEX",
82876 /* 294 */ "cmd ::= REINDEX nm dbnm",
82877 /* 295 */ "cmd ::= ANALYZE",
82878 /* 296 */ "cmd ::= ANALYZE nm dbnm",
82879 /* 297 */ "cmd ::= ALTER TABLE fullname RENAME TO nm",
82880 /* 298 */ "cmd ::= ALTER TABLE add_column_fullname ADD kwcolumn_opt column",
82881 /* 299 */ "add_column_fullname ::= fullname",
82882 /* 300 */ "kwcolumn_opt ::=",
82883 /* 301 */ "kwcolumn_opt ::= COLUMNKW",
82884 /* 302 */ "cmd ::= create_vtab",
82885 /* 303 */ "cmd ::= create_vtab LP vtabarglist RP",
82886 /* 304 */ "create_vtab ::= CREATE VIRTUAL TABLE nm dbnm USING nm",
82887 /* 305 */ "vtabarglist ::= vtabarg",
82888 /* 306 */ "vtabarglist ::= vtabarglist COMMA vtabarg",
82889 /* 307 */ "vtabarg ::=",
82890 /* 308 */ "vtabarg ::= vtabarg vtabargtoken",
82891 /* 309 */ "vtabargtoken ::= ANY",
82892 /* 310 */ "vtabargtoken ::= lp anylist RP",
82893 /* 311 */ "lp ::= LP",
82894 /* 312 */ "anylist ::=",
82895 /* 313 */ "anylist ::= anylist ANY",
 
 
 
 
 
82896 };
82897 #endif /* NDEBUG */
82898
82899
82900 #if YYSTACKDEPTH<=0
@@ -82969,71 +84022,71 @@
82969 **
82970 ** Note: during a reduce, the only symbols destroyed are those
82971 ** which appear on the RHS of the rule, but which are not used
82972 ** inside the C code.
82973 */
82974 case 156: /* select */
82975 case 190: /* oneselect */
82976 {
82977 sqlite3SelectDelete(pParse->db, (yypminor->yy219));
82978 }
82979 break;
82980 case 170: /* term */
82981 case 171: /* expr */
82982 case 195: /* where_opt */
82983 case 197: /* having_opt */
82984 case 206: /* on_opt */
82985 case 211: /* sortitem */
82986 case 219: /* escape */
82987 case 222: /* case_operand */
82988 case 224: /* case_else */
82989 case 235: /* when_clause */
82990 case 238: /* key_opt */
82991 {
82992 sqlite3ExprDelete(pParse->db, (yypminor->yy172));
82993 }
82994 break;
82995 case 175: /* idxlist_opt */
82996 case 183: /* idxlist */
82997 case 193: /* selcollist */
82998 case 196: /* groupby_opt */
82999 case 198: /* orderby_opt */
83000 case 200: /* sclp */
83001 case 210: /* sortlist */
83002 case 212: /* nexprlist */
83003 case 213: /* setlist */
83004 case 216: /* itemlist */
83005 case 217: /* exprlist */
83006 case 223: /* case_exprlist */
83007 {
83008 sqlite3ExprListDelete(pParse->db, (yypminor->yy174));
83009 }
83010 break;
83011 case 189: /* fullname */
83012 case 194: /* from */
83013 case 202: /* seltablist */
83014 case 203: /* stl_prefix */
83015 {
83016 sqlite3SrcListDelete(pParse->db, (yypminor->yy373));
83017 }
83018 break;
83019 case 207: /* using_opt */
83020 case 209: /* inscollist */
83021 case 215: /* inscollist_opt */
83022 {
83023 sqlite3IdListDelete(pParse->db, (yypminor->yy432));
83024 }
83025 break;
83026 case 231: /* trigger_cmd_list */
83027 case 236: /* trigger_cmd */
83028 {
83029 sqlite3DeleteTriggerStep(pParse->db, (yypminor->yy243));
83030 }
83031 break;
83032 case 233: /* trigger_event */
83033 {
83034 sqlite3IdListDelete(pParse->db, (yypminor->yy370).b);
83035 }
83036 break;
83037 default: break; /* If no destructor action specified: do nothing */
83038 }
83039 }
@@ -83262,324 +84315,329 @@
83262 */
83263 static const struct {
83264 YYCODETYPE lhs; /* Symbol on the left-hand side of the rule */
83265 unsigned char nrhs; /* Number of right-hand side symbols in the rule */
83266 } yyRuleInfo[] = {
83267 { 140, 1 },
83268 { 141, 2 },
83269 { 141, 1 },
83270 { 142, 1 },
83271 { 142, 3 },
83272 { 143, 0 },
83273 { 143, 1 },
83274 { 143, 3 },
83275 { 144, 1 },
83276 { 145, 3 },
83277 { 147, 0 },
83278 { 147, 1 },
83279 { 147, 2 },
83280 { 146, 0 },
83281 { 146, 1 },
83282 { 146, 1 },
83283 { 146, 1 },
83284 { 145, 2 },
83285 { 145, 2 },
83286 { 145, 2 },
83287 { 145, 2 },
83288 { 149, 6 },
83289 { 152, 0 },
83290 { 152, 3 },
83291 { 151, 1 },
83292 { 151, 0 },
83293 { 150, 4 },
83294 { 150, 2 },
83295 { 154, 3 },
83296 { 154, 1 },
83297 { 157, 3 },
83298 { 158, 1 },
83299 { 161, 1 },
83300 { 162, 1 },
83301 { 148, 1 },
83302 { 148, 1 },
83303 { 148, 1 },
83304 { 159, 0 },
83305 { 159, 1 },
83306 { 163, 1 },
83307 { 163, 4 },
83308 { 163, 6 },
83309 { 164, 1 },
83310 { 164, 2 },
83311 { 165, 1 },
83312 { 165, 1 },
83313 { 160, 2 },
83314 { 160, 0 },
83315 { 168, 3 },
83316 { 168, 1 },
83317 { 169, 2 },
83318 { 169, 4 },
83319 { 169, 3 },
83320 { 169, 3 },
83321 { 169, 2 },
83322 { 169, 2 },
83323 { 169, 3 },
83324 { 169, 5 },
83325 { 169, 2 },
83326 { 169, 4 },
83327 { 169, 4 },
83328 { 169, 1 },
83329 { 169, 2 },
83330 { 174, 0 },
83331 { 174, 1 },
83332 { 176, 0 },
83333 { 176, 2 },
83334 { 178, 2 },
83335 { 178, 3 },
83336 { 178, 3 },
83337 { 178, 3 },
83338 { 179, 2 },
83339 { 179, 2 },
83340 { 179, 1 },
83341 { 179, 1 },
83342 { 177, 3 },
83343 { 177, 2 },
83344 { 180, 0 },
83345 { 180, 2 },
83346 { 180, 2 },
83347 { 155, 0 },
83348 { 155, 2 },
83349 { 181, 3 },
 
 
 
 
 
 
 
 
 
83350 { 181, 2 },
83351 { 181, 1 },
 
 
 
83352 { 182, 2 },
83353 { 182, 7 },
83354 { 182, 5 },
83355 { 182, 5 },
83356 { 182, 10 },
83357 { 184, 0 },
 
 
 
 
 
 
83358 { 184, 1 },
83359 { 172, 0 },
83360 { 172, 3 },
83361 { 185, 0 },
83362 { 185, 2 },
83363 { 186, 1 },
83364 { 186, 1 },
83365 { 186, 1 },
83366 { 145, 4 },
83367 { 188, 2 },
 
 
 
83368 { 188, 0 },
83369 { 145, 8 },
83370 { 145, 4 },
83371 { 145, 1 },
83372 { 156, 1 },
83373 { 156, 3 },
83374 { 191, 1 },
83375 { 191, 2 },
83376 { 191, 1 },
83377 { 190, 9 },
83378 { 192, 1 },
83379 { 192, 1 },
83380 { 192, 0 },
83381 { 200, 2 },
83382 { 200, 0 },
83383 { 193, 3 },
83384 { 193, 2 },
83385 { 193, 4 },
83386 { 201, 2 },
83387 { 201, 1 },
83388 { 201, 0 },
83389 { 194, 0 },
83390 { 194, 2 },
 
 
 
 
 
83391 { 203, 2 },
83392 { 203, 0 },
83393 { 202, 7 },
83394 { 202, 7 },
83395 { 202, 7 },
83396 { 153, 0 },
83397 { 153, 2 },
83398 { 189, 2 },
83399 { 204, 1 },
83400 { 204, 2 },
83401 { 204, 3 },
83402 { 204, 4 },
83403 { 206, 2 },
83404 { 206, 0 },
83405 { 205, 0 },
83406 { 205, 3 },
83407 { 205, 2 },
83408 { 207, 4 },
83409 { 207, 0 },
83410 { 198, 0 },
83411 { 198, 3 },
83412 { 210, 4 },
83413 { 210, 2 },
83414 { 211, 1 },
83415 { 173, 1 },
83416 { 173, 1 },
83417 { 173, 0 },
83418 { 196, 0 },
83419 { 196, 3 },
83420 { 197, 0 },
83421 { 197, 2 },
83422 { 199, 0 },
83423 { 199, 2 },
83424 { 199, 4 },
83425 { 199, 4 },
83426 { 145, 5 },
83427 { 195, 0 },
83428 { 195, 2 },
83429 { 145, 7 },
83430 { 213, 5 },
83431 { 213, 3 },
83432 { 145, 8 },
83433 { 145, 5 },
83434 { 145, 6 },
83435 { 214, 2 },
 
 
 
 
 
 
 
 
 
83436 { 214, 1 },
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
83437 { 216, 3 },
83438 { 216, 1 },
83439 { 215, 0 },
83440 { 215, 3 },
83441 { 209, 3 },
83442 { 209, 1 },
83443 { 171, 1 },
83444 { 171, 3 },
83445 { 170, 1 },
83446 { 171, 1 },
83447 { 171, 1 },
83448 { 171, 3 },
83449 { 171, 5 },
83450 { 170, 1 },
83451 { 170, 1 },
83452 { 171, 1 },
83453 { 171, 1 },
83454 { 171, 3 },
83455 { 171, 6 },
83456 { 171, 5 },
83457 { 171, 4 },
83458 { 170, 1 },
83459 { 171, 3 },
83460 { 171, 3 },
83461 { 171, 3 },
83462 { 171, 3 },
83463 { 171, 3 },
83464 { 171, 3 },
83465 { 171, 3 },
83466 { 171, 3 },
83467 { 218, 1 },
83468 { 218, 2 },
83469 { 218, 1 },
83470 { 218, 2 },
83471 { 219, 2 },
83472 { 219, 0 },
83473 { 171, 4 },
83474 { 171, 2 },
83475 { 171, 3 },
83476 { 171, 3 },
83477 { 171, 4 },
83478 { 171, 2 },
83479 { 171, 2 },
83480 { 171, 2 },
83481 { 171, 2 },
83482 { 220, 1 },
83483 { 220, 2 },
83484 { 171, 5 },
83485 { 221, 1 },
83486 { 221, 2 },
83487 { 171, 5 },
83488 { 171, 3 },
83489 { 171, 5 },
83490 { 171, 4 },
83491 { 171, 4 },
83492 { 171, 5 },
83493 { 223, 5 },
83494 { 223, 4 },
 
 
 
 
 
 
 
83495 { 224, 2 },
83496 { 224, 0 },
83497 { 222, 1 },
83498 { 222, 0 },
83499 { 217, 1 },
83500 { 217, 0 },
83501 { 212, 3 },
83502 { 212, 1 },
83503 { 145, 11 },
 
 
83504 { 225, 1 },
83505 { 225, 0 },
83506 { 175, 0 },
83507 { 175, 3 },
83508 { 183, 5 },
83509 { 183, 3 },
83510 { 226, 0 },
83511 { 226, 2 },
83512 { 145, 4 },
83513 { 145, 1 },
83514 { 145, 2 },
83515 { 145, 5 },
83516 { 145, 5 },
83517 { 145, 5 },
83518 { 145, 5 },
83519 { 145, 6 },
83520 { 145, 3 },
83521 { 227, 1 },
83522 { 227, 1 },
83523 { 166, 2 },
83524 { 167, 2 },
83525 { 229, 1 },
83526 { 228, 1 },
83527 { 228, 0 },
83528 { 145, 5 },
83529 { 230, 11 },
83530 { 232, 1 },
83531 { 232, 1 },
83532 { 232, 2 },
83533 { 232, 0 },
83534 { 233, 1 },
83535 { 233, 1 },
83536 { 233, 3 },
83537 { 234, 0 },
83538 { 234, 3 },
83539 { 235, 0 },
 
 
 
 
 
 
 
 
 
 
 
 
 
 
83540 { 235, 2 },
83541 { 231, 3 },
83542 { 231, 2 },
83543 { 236, 6 },
83544 { 236, 8 },
83545 { 236, 5 },
83546 { 236, 4 },
83547 { 236, 1 },
83548 { 171, 4 },
83549 { 171, 6 },
83550 { 187, 1 },
83551 { 187, 1 },
83552 { 187, 1 },
83553 { 145, 4 },
83554 { 145, 6 },
83555 { 145, 3 },
83556 { 238, 0 },
83557 { 238, 2 },
83558 { 237, 1 },
83559 { 237, 0 },
83560 { 145, 1 },
83561 { 145, 3 },
83562 { 145, 1 },
83563 { 145, 3 },
83564 { 145, 6 },
83565 { 145, 6 },
83566 { 239, 1 },
83567 { 240, 0 },
 
 
 
 
 
 
 
 
 
83568 { 240, 1 },
83569 { 145, 1 },
83570 { 145, 4 },
83571 { 241, 7 },
 
 
 
 
83572 { 242, 1 },
83573 { 242, 3 },
83574 { 243, 0 },
83575 { 243, 2 },
83576 { 244, 1 },
83577 { 244, 3 },
 
83578 { 245, 1 },
 
83579 { 246, 0 },
83580 { 246, 2 },
 
 
 
 
 
83581 };
83582
83583 static void yy_accept(yyParser*); /* Forward Declaration */
83584
83585 /*
@@ -83638,37 +84696,39 @@
83638 case 3: /* ecmd ::= SEMI */
83639 case 4: /* ecmd ::= explain cmdx SEMI */
83640 case 10: /* trans_opt ::= */
83641 case 11: /* trans_opt ::= TRANSACTION */
83642 case 12: /* trans_opt ::= TRANSACTION nm */
83643 case 20: /* cmd ::= create_table create_table_args */
83644 case 28: /* columnlist ::= columnlist COMMA column */
83645 case 29: /* columnlist ::= column */
83646 case 37: /* type ::= */
83647 case 44: /* signed ::= plus_num */
83648 case 45: /* signed ::= minus_num */
83649 case 46: /* carglist ::= carglist carg */
83650 case 47: /* carglist ::= */
83651 case 48: /* carg ::= CONSTRAINT nm ccons */
83652 case 49: /* carg ::= ccons */
83653 case 55: /* ccons ::= NULL onconf */
83654 case 82: /* conslist ::= conslist COMMA tcons */
83655 case 83: /* conslist ::= conslist tcons */
83656 case 84: /* conslist ::= tcons */
83657 case 85: /* tcons ::= CONSTRAINT nm */
83658 case 259: /* plus_opt ::= PLUS */
83659 case 260: /* plus_opt ::= */
83660 case 270: /* foreach_clause ::= */
83661 case 271: /* foreach_clause ::= FOR EACH ROW */
83662 case 291: /* database_kw_opt ::= DATABASE */
83663 case 292: /* database_kw_opt ::= */
83664 case 300: /* kwcolumn_opt ::= */
83665 case 301: /* kwcolumn_opt ::= COLUMNKW */
83666 case 305: /* vtabarglist ::= vtabarg */
83667 case 306: /* vtabarglist ::= vtabarglist COMMA vtabarg */
83668 case 308: /* vtabarg ::= vtabarg vtabargtoken */
83669 case 312: /* anylist ::= */
 
 
83670 {
83671 }
83672 break;
83673 case 5: /* explain ::= */
83674 { sqlite3BeginParse(pParse, 0); }
@@ -83681,953 +84741,968 @@
83681 break;
83682 case 8: /* cmdx ::= cmd */
83683 { sqlite3FinishCoding(pParse); }
83684 break;
83685 case 9: /* cmd ::= BEGIN transtype trans_opt */
83686 {sqlite3BeginTransaction(pParse, yymsp[-1].minor.yy46);}
83687 break;
83688 case 13: /* transtype ::= */
83689 {yygotominor.yy46 = TK_DEFERRED;}
83690 break;
83691 case 14: /* transtype ::= DEFERRED */
83692 case 15: /* transtype ::= IMMEDIATE */
83693 case 16: /* transtype ::= EXCLUSIVE */
83694 case 107: /* multiselect_op ::= UNION */
83695 case 109: /* multiselect_op ::= EXCEPT|INTERSECT */
83696 {yygotominor.yy46 = yymsp[0].major;}
83697 break;
83698 case 17: /* cmd ::= COMMIT trans_opt */
83699 case 18: /* cmd ::= END trans_opt */
83700 {sqlite3CommitTransaction(pParse);}
83701 break;
83702 case 19: /* cmd ::= ROLLBACK trans_opt */
83703 {sqlite3RollbackTransaction(pParse);}
83704 break;
83705 case 21: /* create_table ::= CREATE temp TABLE ifnotexists nm dbnm */
83706 {
83707 sqlite3StartTable(pParse,&yymsp[-1].minor.yy0,&yymsp[0].minor.yy0,yymsp[-4].minor.yy46,0,0,yymsp[-2].minor.yy46);
83708 }
83709 break;
83710 case 22: /* ifnotexists ::= */
83711 case 25: /* temp ::= */
83712 case 63: /* autoinc ::= */
83713 case 77: /* init_deferred_pred_opt ::= */
83714 case 79: /* init_deferred_pred_opt ::= INITIALLY IMMEDIATE */
83715 case 90: /* defer_subclause_opt ::= */
83716 case 101: /* ifexists ::= */
83717 case 112: /* distinct ::= ALL */
83718 case 113: /* distinct ::= */
83719 case 215: /* between_op ::= BETWEEN */
83720 case 218: /* in_op ::= IN */
83721 {yygotominor.yy46 = 0;}
83722 break;
83723 case 23: /* ifnotexists ::= IF NOT EXISTS */
83724 case 24: /* temp ::= TEMP */
83725 case 64: /* autoinc ::= AUTOINCR */
83726 case 78: /* init_deferred_pred_opt ::= INITIALLY DEFERRED */
83727 case 100: /* ifexists ::= IF EXISTS */
83728 case 111: /* distinct ::= DISTINCT */
83729 case 216: /* between_op ::= NOT BETWEEN */
83730 case 219: /* in_op ::= NOT IN */
83731 {yygotominor.yy46 = 1;}
83732 break;
83733 case 26: /* create_table_args ::= LP columnlist conslist_opt RP */
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
83734 {
83735 sqlite3EndTable(pParse,&yymsp[-1].minor.yy0,&yymsp[0].minor.yy0,0);
83736 }
83737 break;
83738 case 27: /* create_table_args ::= AS select */
83739 {
83740 sqlite3EndTable(pParse,0,0,yymsp[0].minor.yy219);
83741 sqlite3SelectDelete(pParse->db, yymsp[0].minor.yy219);
83742 }
83743 break;
83744 case 30: /* column ::= columnid type carglist */
83745 {
83746 yygotominor.yy0.z = yymsp[-2].minor.yy0.z;
83747 yygotominor.yy0.n = (int)(pParse->sLastToken.z-yymsp[-2].minor.yy0.z) + pParse->sLastToken.n;
83748 }
83749 break;
83750 case 31: /* columnid ::= nm */
83751 {
83752 sqlite3AddColumn(pParse,&yymsp[0].minor.yy0);
83753 yygotominor.yy0 = yymsp[0].minor.yy0;
83754 }
83755 break;
83756 case 32: /* id ::= ID */
83757 case 33: /* ids ::= ID|STRING */
83758 case 34: /* nm ::= ID */
83759 case 35: /* nm ::= STRING */
83760 case 36: /* nm ::= JOIN_KW */
83761 case 39: /* typetoken ::= typename */
83762 case 42: /* typename ::= ids */
83763 case 119: /* as ::= AS nm */
83764 case 120: /* as ::= ids */
83765 case 130: /* dbnm ::= DOT nm */
83766 case 139: /* indexed_opt ::= INDEXED BY nm */
83767 case 244: /* collate ::= COLLATE ids */
83768 case 254: /* nmnum ::= plus_num */
83769 case 255: /* nmnum ::= nm */
83770 case 256: /* plus_num ::= plus_opt number */
83771 case 257: /* minus_num ::= MINUS number */
83772 case 258: /* number ::= INTEGER|FLOAT */
83773 {yygotominor.yy0 = yymsp[0].minor.yy0;}
83774 break;
83775 case 38: /* type ::= typetoken */
83776 {sqlite3AddColumnType(pParse,&yymsp[0].minor.yy0);}
83777 break;
83778 case 40: /* typetoken ::= typename LP signed RP */
83779 {
83780 yygotominor.yy0.z = yymsp[-3].minor.yy0.z;
83781 yygotominor.yy0.n = (int)(&yymsp[0].minor.yy0.z[yymsp[0].minor.yy0.n] - yymsp[-3].minor.yy0.z);
83782 }
83783 break;
83784 case 41: /* typetoken ::= typename LP signed COMMA signed RP */
83785 {
83786 yygotominor.yy0.z = yymsp[-5].minor.yy0.z;
83787 yygotominor.yy0.n = (int)(&yymsp[0].minor.yy0.z[yymsp[0].minor.yy0.n] - yymsp[-5].minor.yy0.z);
83788 }
83789 break;
83790 case 43: /* typename ::= typename ids */
83791 {yygotominor.yy0.z=yymsp[-1].minor.yy0.z; yygotominor.yy0.n=yymsp[0].minor.yy0.n+(int)(yymsp[0].minor.yy0.z-yymsp[-1].minor.yy0.z);}
83792 break;
83793 case 50: /* ccons ::= DEFAULT term */
83794 case 52: /* ccons ::= DEFAULT PLUS term */
83795 {sqlite3AddDefaultValue(pParse,yymsp[0].minor.yy172);}
83796 break;
83797 case 51: /* ccons ::= DEFAULT LP expr RP */
83798 {sqlite3AddDefaultValue(pParse,yymsp[-1].minor.yy172);}
83799 break;
83800 case 53: /* ccons ::= DEFAULT MINUS term */
83801 {
83802 Expr *p = sqlite3PExpr(pParse, TK_UMINUS, yymsp[0].minor.yy172, 0, 0);
83803 sqlite3ExprSpan(p,&yymsp[-1].minor.yy0,&yymsp[0].minor.yy172->span);
83804 sqlite3AddDefaultValue(pParse,p);
83805 }
83806 break;
83807 case 54: /* ccons ::= DEFAULT id */
83808 {
83809 Expr *p = sqlite3PExpr(pParse, TK_STRING, 0, 0, &yymsp[0].minor.yy0);
83810 sqlite3AddDefaultValue(pParse,p);
83811 }
83812 break;
83813 case 56: /* ccons ::= NOT NULL onconf */
83814 {sqlite3AddNotNull(pParse, yymsp[0].minor.yy46);}
83815 break;
83816 case 57: /* ccons ::= PRIMARY KEY sortorder onconf autoinc */
83817 {sqlite3AddPrimaryKey(pParse,0,yymsp[-1].minor.yy46,yymsp[0].minor.yy46,yymsp[-2].minor.yy46);}
83818 break;
83819 case 58: /* ccons ::= UNIQUE onconf */
83820 {sqlite3CreateIndex(pParse,0,0,0,0,yymsp[0].minor.yy46,0,0,0,0);}
83821 break;
83822 case 59: /* ccons ::= CHECK LP expr RP */
83823 {sqlite3AddCheckConstraint(pParse,yymsp[-1].minor.yy172);}
83824 break;
83825 case 60: /* ccons ::= REFERENCES nm idxlist_opt refargs */
83826 {sqlite3CreateForeignKey(pParse,0,&yymsp[-2].minor.yy0,yymsp[-1].minor.yy174,yymsp[0].minor.yy46);}
83827 break;
83828 case 61: /* ccons ::= defer_subclause */
83829 {sqlite3DeferForeignKey(pParse,yymsp[0].minor.yy46);}
83830 break;
83831 case 62: /* ccons ::= COLLATE ids */
83832 {sqlite3AddCollateType(pParse, &yymsp[0].minor.yy0);}
83833 break;
83834 case 65: /* refargs ::= */
83835 { yygotominor.yy46 = OE_Restrict * 0x010101; }
83836 break;
83837 case 66: /* refargs ::= refargs refarg */
83838 { yygotominor.yy46 = (yymsp[-1].minor.yy46 & ~yymsp[0].minor.yy405.mask) | yymsp[0].minor.yy405.value; }
83839 break;
83840 case 67: /* refarg ::= MATCH nm */
83841 { yygotominor.yy405.value = 0; yygotominor.yy405.mask = 0x000000; }
83842 break;
83843 case 68: /* refarg ::= ON DELETE refact */
83844 { yygotominor.yy405.value = yymsp[0].minor.yy46; yygotominor.yy405.mask = 0x0000ff; }
83845 break;
83846 case 69: /* refarg ::= ON UPDATE refact */
83847 { yygotominor.yy405.value = yymsp[0].minor.yy46<<8; yygotominor.yy405.mask = 0x00ff00; }
83848 break;
83849 case 70: /* refarg ::= ON INSERT refact */
83850 { yygotominor.yy405.value = yymsp[0].minor.yy46<<16; yygotominor.yy405.mask = 0xff0000; }
83851 break;
83852 case 71: /* refact ::= SET NULL */
83853 { yygotominor.yy46 = OE_SetNull; }
83854 break;
83855 case 72: /* refact ::= SET DEFAULT */
83856 { yygotominor.yy46 = OE_SetDflt; }
83857 break;
83858 case 73: /* refact ::= CASCADE */
83859 { yygotominor.yy46 = OE_Cascade; }
83860 break;
83861 case 74: /* refact ::= RESTRICT */
83862 { yygotominor.yy46 = OE_Restrict; }
83863 break;
83864 case 75: /* defer_subclause ::= NOT DEFERRABLE init_deferred_pred_opt */
83865 case 76: /* defer_subclause ::= DEFERRABLE init_deferred_pred_opt */
83866 case 91: /* defer_subclause_opt ::= defer_subclause */
83867 case 93: /* onconf ::= ON CONFLICT resolvetype */
83868 case 95: /* orconf ::= OR resolvetype */
83869 case 96: /* resolvetype ::= raisetype */
83870 case 168: /* insert_cmd ::= INSERT orconf */
83871 {yygotominor.yy46 = yymsp[0].minor.yy46;}
83872 break;
83873 case 80: /* conslist_opt ::= */
83874 {yygotominor.yy0.n = 0; yygotominor.yy0.z = 0;}
83875 break;
83876 case 81: /* conslist_opt ::= COMMA conslist */
83877 {yygotominor.yy0 = yymsp[-1].minor.yy0;}
83878 break;
83879 case 86: /* tcons ::= PRIMARY KEY LP idxlist autoinc RP onconf */
83880 {sqlite3AddPrimaryKey(pParse,yymsp[-3].minor.yy174,yymsp[0].minor.yy46,yymsp[-2].minor.yy46,0);}
83881 break;
83882 case 87: /* tcons ::= UNIQUE LP idxlist RP onconf */
83883 {sqlite3CreateIndex(pParse,0,0,0,yymsp[-2].minor.yy174,yymsp[0].minor.yy46,0,0,0,0);}
83884 break;
83885 case 88: /* tcons ::= CHECK LP expr RP onconf */
83886 {sqlite3AddCheckConstraint(pParse,yymsp[-2].minor.yy172);}
83887 break;
83888 case 89: /* tcons ::= FOREIGN KEY LP idxlist RP REFERENCES nm idxlist_opt refargs defer_subclause_opt */
83889 {
83890 sqlite3CreateForeignKey(pParse, yymsp[-6].minor.yy174, &yymsp[-3].minor.yy0, yymsp[-2].minor.yy174, yymsp[-1].minor.yy46);
83891 sqlite3DeferForeignKey(pParse, yymsp[0].minor.yy46);
83892 }
83893 break;
83894 case 92: /* onconf ::= */
83895 case 94: /* orconf ::= */
83896 {yygotominor.yy46 = OE_Default;}
83897 break;
83898 case 97: /* resolvetype ::= IGNORE */
83899 {yygotominor.yy46 = OE_Ignore;}
83900 break;
83901 case 98: /* resolvetype ::= REPLACE */
83902 case 169: /* insert_cmd ::= REPLACE */
83903 {yygotominor.yy46 = OE_Replace;}
83904 break;
83905 case 99: /* cmd ::= DROP TABLE ifexists fullname */
83906 {
83907 sqlite3DropTable(pParse, yymsp[0].minor.yy373, 0, yymsp[-1].minor.yy46);
83908 }
83909 break;
83910 case 102: /* cmd ::= CREATE temp VIEW ifnotexists nm dbnm AS select */
83911 {
83912 sqlite3CreateView(pParse, &yymsp[-7].minor.yy0, &yymsp[-3].minor.yy0, &yymsp[-2].minor.yy0, yymsp[0].minor.yy219, yymsp[-6].minor.yy46, yymsp[-4].minor.yy46);
83913 }
83914 break;
83915 case 103: /* cmd ::= DROP VIEW ifexists fullname */
83916 {
83917 sqlite3DropTable(pParse, yymsp[0].minor.yy373, 1, yymsp[-1].minor.yy46);
83918 }
83919 break;
83920 case 104: /* cmd ::= select */
83921 {
83922 SelectDest dest = {SRT_Output, 0, 0, 0, 0};
83923 sqlite3Select(pParse, yymsp[0].minor.yy219, &dest);
83924 sqlite3SelectDelete(pParse->db, yymsp[0].minor.yy219);
83925 }
83926 break;
83927 case 105: /* select ::= oneselect */
83928 {yygotominor.yy219 = yymsp[0].minor.yy219;}
83929 break;
83930 case 106: /* select ::= select multiselect_op oneselect */
83931 {
83932 if( yymsp[0].minor.yy219 ){
83933 yymsp[0].minor.yy219->op = (u8)yymsp[-1].minor.yy46;
83934 yymsp[0].minor.yy219->pPrior = yymsp[-2].minor.yy219;
83935 }else{
83936 sqlite3SelectDelete(pParse->db, yymsp[-2].minor.yy219);
83937 }
83938 yygotominor.yy219 = yymsp[0].minor.yy219;
83939 }
83940 break;
83941 case 108: /* multiselect_op ::= UNION ALL */
83942 {yygotominor.yy46 = TK_ALL;}
83943 break;
83944 case 110: /* oneselect ::= SELECT distinct selcollist from where_opt groupby_opt having_opt orderby_opt limit_opt */
83945 {
83946 yygotominor.yy219 = sqlite3SelectNew(pParse,yymsp[-6].minor.yy174,yymsp[-5].minor.yy373,yymsp[-4].minor.yy172,yymsp[-3].minor.yy174,yymsp[-2].minor.yy172,yymsp[-1].minor.yy174,yymsp[-7].minor.yy46,yymsp[0].minor.yy234.pLimit,yymsp[0].minor.yy234.pOffset);
83947 }
83948 break;
83949 case 114: /* sclp ::= selcollist COMMA */
83950 case 240: /* idxlist_opt ::= LP idxlist RP */
83951 {yygotominor.yy174 = yymsp[-1].minor.yy174;}
83952 break;
83953 case 115: /* sclp ::= */
83954 case 143: /* orderby_opt ::= */
83955 case 151: /* groupby_opt ::= */
83956 case 233: /* exprlist ::= */
83957 case 239: /* idxlist_opt ::= */
83958 {yygotominor.yy174 = 0;}
83959 break;
83960 case 116: /* selcollist ::= sclp expr as */
83961 {
83962 yygotominor.yy174 = sqlite3ExprListAppend(pParse,yymsp[-2].minor.yy174,yymsp[-1].minor.yy172,yymsp[0].minor.yy0.n?&yymsp[0].minor.yy0:0);
83963 }
83964 break;
83965 case 117: /* selcollist ::= sclp STAR */
83966 {
83967 Expr *p = sqlite3PExpr(pParse, TK_ALL, 0, 0, 0);
83968 yygotominor.yy174 = sqlite3ExprListAppend(pParse, yymsp[-1].minor.yy174, p, 0);
83969 }
83970 break;
83971 case 118: /* selcollist ::= sclp nm DOT STAR */
83972 {
83973 Expr *pRight = sqlite3PExpr(pParse, TK_ALL, 0, 0, &yymsp[0].minor.yy0);
83974 Expr *pLeft = sqlite3PExpr(pParse, TK_ID, 0, 0, &yymsp[-2].minor.yy0);
83975 Expr *pDot = sqlite3PExpr(pParse, TK_DOT, pLeft, pRight, 0);
83976 yygotominor.yy174 = sqlite3ExprListAppend(pParse,yymsp[-3].minor.yy174, pDot, 0);
83977 }
83978 break;
83979 case 121: /* as ::= */
83980 {yygotominor.yy0.n = 0;}
83981 break;
83982 case 122: /* from ::= */
83983 {yygotominor.yy373 = sqlite3DbMallocZero(pParse->db, sizeof(*yygotominor.yy373));}
83984 break;
83985 case 123: /* from ::= FROM seltablist */
83986 {
83987 yygotominor.yy373 = yymsp[0].minor.yy373;
83988 sqlite3SrcListShiftJoinType(yygotominor.yy373);
83989 }
83990 break;
83991 case 124: /* stl_prefix ::= seltablist joinop */
83992 {
83993 yygotominor.yy373 = yymsp[-1].minor.yy373;
83994 if( yygotominor.yy373 && yygotominor.yy373->nSrc>0 ) yygotominor.yy373->a[yygotominor.yy373->nSrc-1].jointype = (u8)yymsp[0].minor.yy46;
83995 }
83996 break;
83997 case 125: /* stl_prefix ::= */
83998 {yygotominor.yy373 = 0;}
83999 break;
84000 case 126: /* seltablist ::= stl_prefix nm dbnm as indexed_opt on_opt using_opt */
84001 {
84002 yygotominor.yy373 = sqlite3SrcListAppendFromTerm(pParse,yymsp[-6].minor.yy373,&yymsp[-5].minor.yy0,&yymsp[-4].minor.yy0,&yymsp[-3].minor.yy0,0,yymsp[-1].minor.yy172,yymsp[0].minor.yy432);
84003 sqlite3SrcListIndexedBy(pParse, yygotominor.yy373, &yymsp[-2].minor.yy0);
84004 }
84005 break;
84006 case 127: /* seltablist ::= stl_prefix LP select RP as on_opt using_opt */
84007 {
84008 yygotominor.yy373 = sqlite3SrcListAppendFromTerm(pParse,yymsp[-6].minor.yy373,0,0,&yymsp[-2].minor.yy0,yymsp[-4].minor.yy219,yymsp[-1].minor.yy172,yymsp[0].minor.yy432);
84009 }
84010 break;
84011 case 128: /* seltablist ::= stl_prefix LP seltablist RP as on_opt using_opt */
84012 {
84013 if( yymsp[-6].minor.yy373==0 && yymsp[-2].minor.yy0.n==0 && yymsp[-1].minor.yy172==0 && yymsp[0].minor.yy432==0 ){
84014 yygotominor.yy373 = yymsp[-4].minor.yy373;
84015 }else{
84016 Select *pSubquery;
84017 sqlite3SrcListShiftJoinType(yymsp[-4].minor.yy373);
84018 pSubquery = sqlite3SelectNew(pParse,0,yymsp[-4].minor.yy373,0,0,0,0,0,0,0);
84019 yygotominor.yy373 = sqlite3SrcListAppendFromTerm(pParse,yymsp[-6].minor.yy373,0,0,&yymsp[-2].minor.yy0,pSubquery,yymsp[-1].minor.yy172,yymsp[0].minor.yy432);
84020 }
84021 }
84022 break;
84023 case 129: /* dbnm ::= */
84024 case 138: /* indexed_opt ::= */
84025 {yygotominor.yy0.z=0; yygotominor.yy0.n=0;}
84026 break;
84027 case 131: /* fullname ::= nm dbnm */
84028 {yygotominor.yy373 = sqlite3SrcListAppend(pParse->db,0,&yymsp[-1].minor.yy0,&yymsp[0].minor.yy0);}
84029 break;
84030 case 132: /* joinop ::= COMMA|JOIN */
84031 { yygotominor.yy46 = JT_INNER; }
84032 break;
84033 case 133: /* joinop ::= JOIN_KW JOIN */
84034 { yygotominor.yy46 = sqlite3JoinType(pParse,&yymsp[-1].minor.yy0,0,0); }
84035 break;
84036 case 134: /* joinop ::= JOIN_KW nm JOIN */
84037 { yygotominor.yy46 = sqlite3JoinType(pParse,&yymsp[-2].minor.yy0,&yymsp[-1].minor.yy0,0); }
84038 break;
84039 case 135: /* joinop ::= JOIN_KW nm nm JOIN */
84040 { yygotominor.yy46 = sqlite3JoinType(pParse,&yymsp[-3].minor.yy0,&yymsp[-2].minor.yy0,&yymsp[-1].minor.yy0); }
84041 break;
84042 case 136: /* on_opt ::= ON expr */
84043 case 147: /* sortitem ::= expr */
84044 case 154: /* having_opt ::= HAVING expr */
84045 case 161: /* where_opt ::= WHERE expr */
84046 case 176: /* expr ::= term */
84047 case 204: /* escape ::= ESCAPE expr */
84048 case 228: /* case_else ::= ELSE expr */
84049 case 230: /* case_operand ::= expr */
84050 {yygotominor.yy172 = yymsp[0].minor.yy172;}
84051 break;
84052 case 137: /* on_opt ::= */
84053 case 153: /* having_opt ::= */
84054 case 160: /* where_opt ::= */
84055 case 205: /* escape ::= */
84056 case 229: /* case_else ::= */
84057 case 231: /* case_operand ::= */
84058 {yygotominor.yy172 = 0;}
84059 break;
84060 case 140: /* indexed_opt ::= NOT INDEXED */
84061 {yygotominor.yy0.z=0; yygotominor.yy0.n=1;}
84062 break;
84063 case 141: /* using_opt ::= USING LP inscollist RP */
84064 case 173: /* inscollist_opt ::= LP inscollist RP */
84065 {yygotominor.yy432 = yymsp[-1].minor.yy432;}
84066 break;
84067 case 142: /* using_opt ::= */
84068 case 172: /* inscollist_opt ::= */
84069 {yygotominor.yy432 = 0;}
84070 break;
84071 case 144: /* orderby_opt ::= ORDER BY sortlist */
84072 case 152: /* groupby_opt ::= GROUP BY nexprlist */
84073 case 232: /* exprlist ::= nexprlist */
84074 {yygotominor.yy174 = yymsp[0].minor.yy174;}
84075 break;
84076 case 145: /* sortlist ::= sortlist COMMA sortitem sortorder */
84077 {
84078 yygotominor.yy174 = sqlite3ExprListAppend(pParse,yymsp[-3].minor.yy174,yymsp[-1].minor.yy172,0);
84079 if( yygotominor.yy174 ) yygotominor.yy174->a[yygotominor.yy174->nExpr-1].sortOrder = (u8)yymsp[0].minor.yy46;
84080 }
84081 break;
84082 case 146: /* sortlist ::= sortitem sortorder */
84083 {
84084 yygotominor.yy174 = sqlite3ExprListAppend(pParse,0,yymsp[-1].minor.yy172,0);
84085 if( yygotominor.yy174 && yygotominor.yy174->a ) yygotominor.yy174->a[0].sortOrder = (u8)yymsp[0].minor.yy46;
84086 }
84087 break;
84088 case 148: /* sortorder ::= ASC */
84089 case 150: /* sortorder ::= */
84090 {yygotominor.yy46 = SQLITE_SO_ASC;}
84091 break;
84092 case 149: /* sortorder ::= DESC */
84093 {yygotominor.yy46 = SQLITE_SO_DESC;}
84094 break;
84095 case 155: /* limit_opt ::= */
84096 {yygotominor.yy234.pLimit = 0; yygotominor.yy234.pOffset = 0;}
84097 break;
84098 case 156: /* limit_opt ::= LIMIT expr */
84099 {yygotominor.yy234.pLimit = yymsp[0].minor.yy172; yygotominor.yy234.pOffset = 0;}
84100 break;
84101 case 157: /* limit_opt ::= LIMIT expr OFFSET expr */
84102 {yygotominor.yy234.pLimit = yymsp[-2].minor.yy172; yygotominor.yy234.pOffset = yymsp[0].minor.yy172;}
84103 break;
84104 case 158: /* limit_opt ::= LIMIT expr COMMA expr */
84105 {yygotominor.yy234.pOffset = yymsp[-2].minor.yy172; yygotominor.yy234.pLimit = yymsp[0].minor.yy172;}
84106 break;
84107 case 159: /* cmd ::= DELETE FROM fullname indexed_opt where_opt */
84108 {
84109 sqlite3SrcListIndexedBy(pParse, yymsp[-2].minor.yy373, &yymsp[-1].minor.yy0);
84110 sqlite3DeleteFrom(pParse,yymsp[-2].minor.yy373,yymsp[0].minor.yy172);
84111 }
84112 break;
84113 case 162: /* cmd ::= UPDATE orconf fullname indexed_opt SET setlist where_opt */
84114 {
84115 sqlite3SrcListIndexedBy(pParse, yymsp[-4].minor.yy373, &yymsp[-3].minor.yy0);
84116 sqlite3ExprListCheckLength(pParse,yymsp[-1].minor.yy174,"set list");
84117 sqlite3Update(pParse,yymsp[-4].minor.yy373,yymsp[-1].minor.yy174,yymsp[0].minor.yy172,yymsp[-5].minor.yy46);
84118 }
84119 break;
84120 case 163: /* setlist ::= setlist COMMA nm EQ expr */
84121 {yygotominor.yy174 = sqlite3ExprListAppend(pParse,yymsp[-4].minor.yy174,yymsp[0].minor.yy172,&yymsp[-2].minor.yy0);}
84122 break;
84123 case 164: /* setlist ::= nm EQ expr */
84124 {yygotominor.yy174 = sqlite3ExprListAppend(pParse,0,yymsp[0].minor.yy172,&yymsp[-2].minor.yy0);}
84125 break;
84126 case 165: /* cmd ::= insert_cmd INTO fullname inscollist_opt VALUES LP itemlist RP */
84127 {sqlite3Insert(pParse, yymsp[-5].minor.yy373, yymsp[-1].minor.yy174, 0, yymsp[-4].minor.yy432, yymsp[-7].minor.yy46);}
84128 break;
84129 case 166: /* cmd ::= insert_cmd INTO fullname inscollist_opt select */
84130 {sqlite3Insert(pParse, yymsp[-2].minor.yy373, 0, yymsp[0].minor.yy219, yymsp[-1].minor.yy432, yymsp[-4].minor.yy46);}
84131 break;
84132 case 167: /* cmd ::= insert_cmd INTO fullname inscollist_opt DEFAULT VALUES */
84133 {sqlite3Insert(pParse, yymsp[-3].minor.yy373, 0, 0, yymsp[-2].minor.yy432, yymsp[-5].minor.yy46);}
84134 break;
84135 case 170: /* itemlist ::= itemlist COMMA expr */
84136 case 234: /* nexprlist ::= nexprlist COMMA expr */
84137 {yygotominor.yy174 = sqlite3ExprListAppend(pParse,yymsp[-2].minor.yy174,yymsp[0].minor.yy172,0);}
84138 break;
84139 case 171: /* itemlist ::= expr */
84140 case 235: /* nexprlist ::= expr */
84141 {yygotominor.yy174 = sqlite3ExprListAppend(pParse,0,yymsp[0].minor.yy172,0);}
84142 break;
84143 case 174: /* inscollist ::= inscollist COMMA nm */
84144 {yygotominor.yy432 = sqlite3IdListAppend(pParse->db,yymsp[-2].minor.yy432,&yymsp[0].minor.yy0);}
84145 break;
84146 case 175: /* inscollist ::= nm */
84147 {yygotominor.yy432 = sqlite3IdListAppend(pParse->db,0,&yymsp[0].minor.yy0);}
84148 break;
84149 case 177: /* expr ::= LP expr RP */
84150 {yygotominor.yy172 = yymsp[-1].minor.yy172; sqlite3ExprSpan(yygotominor.yy172,&yymsp[-2].minor.yy0,&yymsp[0].minor.yy0); }
84151 break;
84152 case 178: /* term ::= NULL */
84153 case 183: /* term ::= INTEGER|FLOAT|BLOB */
84154 case 184: /* term ::= STRING */
84155 {yygotominor.yy172 = sqlite3PExpr(pParse, yymsp[0].major, 0, 0, &yymsp[0].minor.yy0);}
84156 break;
84157 case 179: /* expr ::= ID */
84158 case 180: /* expr ::= JOIN_KW */
84159 {yygotominor.yy172 = sqlite3PExpr(pParse, TK_ID, 0, 0, &yymsp[0].minor.yy0);}
84160 break;
84161 case 181: /* expr ::= nm DOT nm */
84162 {
84163 Expr *temp1 = sqlite3PExpr(pParse, TK_ID, 0, 0, &yymsp[-2].minor.yy0);
84164 Expr *temp2 = sqlite3PExpr(pParse, TK_ID, 0, 0, &yymsp[0].minor.yy0);
84165 yygotominor.yy172 = sqlite3PExpr(pParse, TK_DOT, temp1, temp2, 0);
84166 }
84167 break;
84168 case 182: /* expr ::= nm DOT nm DOT nm */
84169 {
84170 Expr *temp1 = sqlite3PExpr(pParse, TK_ID, 0, 0, &yymsp[-4].minor.yy0);
84171 Expr *temp2 = sqlite3PExpr(pParse, TK_ID, 0, 0, &yymsp[-2].minor.yy0);
84172 Expr *temp3 = sqlite3PExpr(pParse, TK_ID, 0, 0, &yymsp[0].minor.yy0);
84173 Expr *temp4 = sqlite3PExpr(pParse, TK_DOT, temp2, temp3, 0);
84174 yygotominor.yy172 = sqlite3PExpr(pParse, TK_DOT, temp1, temp4, 0);
84175 }
84176 break;
84177 case 185: /* expr ::= REGISTER */
84178 {yygotominor.yy172 = sqlite3RegisterExpr(pParse, &yymsp[0].minor.yy0);}
84179 break;
84180 case 186: /* expr ::= VARIABLE */
84181 {
84182 Token *pToken = &yymsp[0].minor.yy0;
84183 Expr *pExpr = yygotominor.yy172 = sqlite3PExpr(pParse, TK_VARIABLE, 0, 0, pToken);
84184 sqlite3ExprAssignVarNumber(pParse, pExpr);
84185 }
84186 break;
84187 case 187: /* expr ::= expr COLLATE ids */
84188 {
84189 yygotominor.yy172 = sqlite3ExprSetColl(pParse, yymsp[-2].minor.yy172, &yymsp[0].minor.yy0);
84190 }
84191 break;
84192 case 188: /* expr ::= CAST LP expr AS typetoken RP */
84193 {
84194 yygotominor.yy172 = sqlite3PExpr(pParse, TK_CAST, yymsp[-3].minor.yy172, 0, &yymsp[-1].minor.yy0);
84195 sqlite3ExprSpan(yygotominor.yy172,&yymsp[-5].minor.yy0,&yymsp[0].minor.yy0);
84196 }
84197 break;
84198 case 189: /* expr ::= ID LP distinct exprlist RP */
84199 {
84200 if( yymsp[-1].minor.yy174 && yymsp[-1].minor.yy174->nExpr>SQLITE_MAX_FUNCTION_ARG ){
84201 sqlite3ErrorMsg(pParse, "too many arguments on function %T", &yymsp[-4].minor.yy0);
84202 }
84203 yygotominor.yy172 = sqlite3ExprFunction(pParse, yymsp[-1].minor.yy174, &yymsp[-4].minor.yy0);
84204 sqlite3ExprSpan(yygotominor.yy172,&yymsp[-4].minor.yy0,&yymsp[0].minor.yy0);
84205 if( yymsp[-2].minor.yy46 && yygotominor.yy172 ){
84206 yygotominor.yy172->flags |= EP_Distinct;
84207 }
84208 }
84209 break;
84210 case 190: /* expr ::= ID LP STAR RP */
84211 {
84212 yygotominor.yy172 = sqlite3ExprFunction(pParse, 0, &yymsp[-3].minor.yy0);
84213 sqlite3ExprSpan(yygotominor.yy172,&yymsp[-3].minor.yy0,&yymsp[0].minor.yy0);
84214 }
84215 break;
84216 case 191: /* term ::= CTIME_KW */
84217 {
84218 /* The CURRENT_TIME, CURRENT_DATE, and CURRENT_TIMESTAMP values are
84219 ** treated as functions that return constants */
84220 yygotominor.yy172 = sqlite3ExprFunction(pParse, 0,&yymsp[0].minor.yy0);
84221 if( yygotominor.yy172 ){
84222 yygotominor.yy172->op = TK_CONST_FUNC;
84223 yygotominor.yy172->span = yymsp[0].minor.yy0;
84224 }
84225 }
84226 break;
84227 case 192: /* expr ::= expr AND expr */
84228 case 193: /* expr ::= expr OR expr */
84229 case 194: /* expr ::= expr LT|GT|GE|LE expr */
84230 case 195: /* expr ::= expr EQ|NE expr */
84231 case 196: /* expr ::= expr BITAND|BITOR|LSHIFT|RSHIFT expr */
84232 case 197: /* expr ::= expr PLUS|MINUS expr */
84233 case 198: /* expr ::= expr STAR|SLASH|REM expr */
84234 case 199: /* expr ::= expr CONCAT expr */
84235 {yygotominor.yy172 = sqlite3PExpr(pParse,yymsp[-1].major,yymsp[-2].minor.yy172,yymsp[0].minor.yy172,0);}
84236 break;
84237 case 200: /* likeop ::= LIKE_KW */
84238 case 202: /* likeop ::= MATCH */
84239 {yygotominor.yy72.eOperator = yymsp[0].minor.yy0; yygotominor.yy72.not = 0;}
84240 break;
84241 case 201: /* likeop ::= NOT LIKE_KW */
84242 case 203: /* likeop ::= NOT MATCH */
84243 {yygotominor.yy72.eOperator = yymsp[0].minor.yy0; yygotominor.yy72.not = 1;}
84244 break;
84245 case 206: /* expr ::= expr likeop expr escape */
84246 {
84247 ExprList *pList;
84248 pList = sqlite3ExprListAppend(pParse,0, yymsp[-1].minor.yy172, 0);
84249 pList = sqlite3ExprListAppend(pParse,pList, yymsp[-3].minor.yy172, 0);
84250 if( yymsp[0].minor.yy172 ){
84251 pList = sqlite3ExprListAppend(pParse,pList, yymsp[0].minor.yy172, 0);
84252 }
84253 yygotominor.yy172 = sqlite3ExprFunction(pParse, pList, &yymsp[-2].minor.yy72.eOperator);
84254 if( yymsp[-2].minor.yy72.not ) yygotominor.yy172 = sqlite3PExpr(pParse, TK_NOT, yygotominor.yy172, 0, 0);
84255 sqlite3ExprSpan(yygotominor.yy172, &yymsp[-3].minor.yy172->span, &yymsp[-1].minor.yy172->span);
84256 if( yygotominor.yy172 ) yygotominor.yy172->flags |= EP_InfixFunc;
84257 }
84258 break;
84259 case 207: /* expr ::= expr ISNULL|NOTNULL */
84260 {
84261 yygotominor.yy172 = sqlite3PExpr(pParse, yymsp[0].major, yymsp[-1].minor.yy172, 0, 0);
84262 sqlite3ExprSpan(yygotominor.yy172,&yymsp[-1].minor.yy172->span,&yymsp[0].minor.yy0);
84263 }
84264 break;
84265 case 208: /* expr ::= expr IS NULL */
84266 {
84267 yygotominor.yy172 = sqlite3PExpr(pParse, TK_ISNULL, yymsp[-2].minor.yy172, 0, 0);
84268 sqlite3ExprSpan(yygotominor.yy172,&yymsp[-2].minor.yy172->span,&yymsp[0].minor.yy0);
84269 }
84270 break;
84271 case 209: /* expr ::= expr NOT NULL */
84272 {
84273 yygotominor.yy172 = sqlite3PExpr(pParse, TK_NOTNULL, yymsp[-2].minor.yy172, 0, 0);
84274 sqlite3ExprSpan(yygotominor.yy172,&yymsp[-2].minor.yy172->span,&yymsp[0].minor.yy0);
84275 }
84276 break;
84277 case 210: /* expr ::= expr IS NOT NULL */
84278 {
84279 yygotominor.yy172 = sqlite3PExpr(pParse, TK_NOTNULL, yymsp[-3].minor.yy172, 0, 0);
84280 sqlite3ExprSpan(yygotominor.yy172,&yymsp[-3].minor.yy172->span,&yymsp[0].minor.yy0);
84281 }
84282 break;
84283 case 211: /* expr ::= NOT expr */
84284 case 212: /* expr ::= BITNOT expr */
84285 {
84286 yygotominor.yy172 = sqlite3PExpr(pParse, yymsp[-1].major, yymsp[0].minor.yy172, 0, 0);
84287 sqlite3ExprSpan(yygotominor.yy172,&yymsp[-1].minor.yy0,&yymsp[0].minor.yy172->span);
84288 }
84289 break;
84290 case 213: /* expr ::= MINUS expr */
84291 {
84292 yygotominor.yy172 = sqlite3PExpr(pParse, TK_UMINUS, yymsp[0].minor.yy172, 0, 0);
84293 sqlite3ExprSpan(yygotominor.yy172,&yymsp[-1].minor.yy0,&yymsp[0].minor.yy172->span);
84294 }
84295 break;
84296 case 214: /* expr ::= PLUS expr */
84297 {
84298 yygotominor.yy172 = sqlite3PExpr(pParse, TK_UPLUS, yymsp[0].minor.yy172, 0, 0);
84299 sqlite3ExprSpan(yygotominor.yy172,&yymsp[-1].minor.yy0,&yymsp[0].minor.yy172->span);
84300 }
84301 break;
84302 case 217: /* expr ::= expr between_op expr AND expr */
84303 {
84304 ExprList *pList = sqlite3ExprListAppend(pParse,0, yymsp[-2].minor.yy172, 0);
84305 pList = sqlite3ExprListAppend(pParse,pList, yymsp[0].minor.yy172, 0);
84306 yygotominor.yy172 = sqlite3PExpr(pParse, TK_BETWEEN, yymsp[-4].minor.yy172, 0, 0);
84307 if( yygotominor.yy172 ){
84308 yygotominor.yy172->pList = pList;
84309 }else{
84310 sqlite3ExprListDelete(pParse->db, pList);
84311 }
84312 if( yymsp[-3].minor.yy46 ) yygotominor.yy172 = sqlite3PExpr(pParse, TK_NOT, yygotominor.yy172, 0, 0);
84313 sqlite3ExprSpan(yygotominor.yy172,&yymsp[-4].minor.yy172->span,&yymsp[0].minor.yy172->span);
84314 }
84315 break;
84316 case 220: /* expr ::= expr in_op LP exprlist RP */
84317 {
84318 yygotominor.yy172 = sqlite3PExpr(pParse, TK_IN, yymsp[-4].minor.yy172, 0, 0);
84319 if( yygotominor.yy172 ){
84320 yygotominor.yy172->pList = yymsp[-1].minor.yy174;
84321 sqlite3ExprSetHeight(pParse, yygotominor.yy172);
84322 }else{
84323 sqlite3ExprListDelete(pParse->db, yymsp[-1].minor.yy174);
84324 }
84325 if( yymsp[-3].minor.yy46 ) yygotominor.yy172 = sqlite3PExpr(pParse, TK_NOT, yygotominor.yy172, 0, 0);
84326 sqlite3ExprSpan(yygotominor.yy172,&yymsp[-4].minor.yy172->span,&yymsp[0].minor.yy0);
84327 }
84328 break;
84329 case 221: /* expr ::= LP select RP */
84330 {
84331 yygotominor.yy172 = sqlite3PExpr(pParse, TK_SELECT, 0, 0, 0);
84332 if( yygotominor.yy172 ){
84333 yygotominor.yy172->pSelect = yymsp[-1].minor.yy219;
84334 sqlite3ExprSetHeight(pParse, yygotominor.yy172);
84335 }else{
84336 sqlite3SelectDelete(pParse->db, yymsp[-1].minor.yy219);
84337 }
84338 sqlite3ExprSpan(yygotominor.yy172,&yymsp[-2].minor.yy0,&yymsp[0].minor.yy0);
84339 }
84340 break;
84341 case 222: /* expr ::= expr in_op LP select RP */
84342 {
84343 yygotominor.yy172 = sqlite3PExpr(pParse, TK_IN, yymsp[-4].minor.yy172, 0, 0);
84344 if( yygotominor.yy172 ){
84345 yygotominor.yy172->pSelect = yymsp[-1].minor.yy219;
84346 sqlite3ExprSetHeight(pParse, yygotominor.yy172);
84347 }else{
84348 sqlite3SelectDelete(pParse->db, yymsp[-1].minor.yy219);
84349 }
84350 if( yymsp[-3].minor.yy46 ) yygotominor.yy172 = sqlite3PExpr(pParse, TK_NOT, yygotominor.yy172, 0, 0);
84351 sqlite3ExprSpan(yygotominor.yy172,&yymsp[-4].minor.yy172->span,&yymsp[0].minor.yy0);
84352 }
84353 break;
84354 case 223: /* expr ::= expr in_op nm dbnm */
84355 {
84356 SrcList *pSrc = sqlite3SrcListAppend(pParse->db, 0,&yymsp[-1].minor.yy0,&yymsp[0].minor.yy0);
84357 yygotominor.yy172 = sqlite3PExpr(pParse, TK_IN, yymsp[-3].minor.yy172, 0, 0);
84358 if( yygotominor.yy172 ){
84359 yygotominor.yy172->pSelect = sqlite3SelectNew(pParse, 0,pSrc,0,0,0,0,0,0,0);
84360 sqlite3ExprSetHeight(pParse, yygotominor.yy172);
84361 }else{
84362 sqlite3SrcListDelete(pParse->db, pSrc);
84363 }
84364 if( yymsp[-2].minor.yy46 ) yygotominor.yy172 = sqlite3PExpr(pParse, TK_NOT, yygotominor.yy172, 0, 0);
84365 sqlite3ExprSpan(yygotominor.yy172,&yymsp[-3].minor.yy172->span,yymsp[0].minor.yy0.z?&yymsp[0].minor.yy0:&yymsp[-1].minor.yy0);
84366 }
84367 break;
84368 case 224: /* expr ::= EXISTS LP select RP */
84369 {
84370 Expr *p = yygotominor.yy172 = sqlite3PExpr(pParse, TK_EXISTS, 0, 0, 0);
84371 if( p ){
84372 p->pSelect = yymsp[-1].minor.yy219;
84373 sqlite3ExprSpan(p,&yymsp[-3].minor.yy0,&yymsp[0].minor.yy0);
84374 sqlite3ExprSetHeight(pParse, yygotominor.yy172);
84375 }else{
84376 sqlite3SelectDelete(pParse->db, yymsp[-1].minor.yy219);
84377 }
84378 }
84379 break;
84380 case 225: /* expr ::= CASE case_operand case_exprlist case_else END */
84381 {
84382 yygotominor.yy172 = sqlite3PExpr(pParse, TK_CASE, yymsp[-3].minor.yy172, yymsp[-1].minor.yy172, 0);
84383 if( yygotominor.yy172 ){
84384 yygotominor.yy172->pList = yymsp[-2].minor.yy174;
84385 sqlite3ExprSetHeight(pParse, yygotominor.yy172);
84386 }else{
84387 sqlite3ExprListDelete(pParse->db, yymsp[-2].minor.yy174);
84388 }
84389 sqlite3ExprSpan(yygotominor.yy172, &yymsp[-4].minor.yy0, &yymsp[0].minor.yy0);
84390 }
84391 break;
84392 case 226: /* case_exprlist ::= case_exprlist WHEN expr THEN expr */
84393 {
84394 yygotominor.yy174 = sqlite3ExprListAppend(pParse,yymsp[-4].minor.yy174, yymsp[-2].minor.yy172, 0);
84395 yygotominor.yy174 = sqlite3ExprListAppend(pParse,yygotominor.yy174, yymsp[0].minor.yy172, 0);
84396 }
84397 break;
84398 case 227: /* case_exprlist ::= WHEN expr THEN expr */
84399 {
84400 yygotominor.yy174 = sqlite3ExprListAppend(pParse,0, yymsp[-2].minor.yy172, 0);
84401 yygotominor.yy174 = sqlite3ExprListAppend(pParse,yygotominor.yy174, yymsp[0].minor.yy172, 0);
84402 }
84403 break;
84404 case 236: /* cmd ::= CREATE uniqueflag INDEX ifnotexists nm dbnm ON nm LP idxlist RP */
84405 {
84406 sqlite3CreateIndex(pParse, &yymsp[-6].minor.yy0, &yymsp[-5].minor.yy0,
84407 sqlite3SrcListAppend(pParse->db,0,&yymsp[-3].minor.yy0,0), yymsp[-1].minor.yy174, yymsp[-9].minor.yy46,
84408 &yymsp[-10].minor.yy0, &yymsp[0].minor.yy0, SQLITE_SO_ASC, yymsp[-7].minor.yy46);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
84409 }
84410 break;
84411 case 237: /* uniqueflag ::= UNIQUE */
84412 case 284: /* raisetype ::= ABORT */
84413 {yygotominor.yy46 = OE_Abort;}
84414 break;
84415 case 238: /* uniqueflag ::= */
84416 {yygotominor.yy46 = OE_None;}
84417 break;
84418 case 241: /* idxlist ::= idxlist COMMA nm collate sortorder */
84419 {
84420 Expr *p = 0;
84421 if( yymsp[-1].minor.yy0.n>0 ){
84422 p = sqlite3PExpr(pParse, TK_COLUMN, 0, 0, 0);
84423 sqlite3ExprSetColl(pParse, p, &yymsp[-1].minor.yy0);
84424 }
84425 yygotominor.yy174 = sqlite3ExprListAppend(pParse,yymsp[-4].minor.yy174, p, &yymsp[-2].minor.yy0);
84426 sqlite3ExprListCheckLength(pParse, yygotominor.yy174, "index");
84427 if( yygotominor.yy174 ) yygotominor.yy174->a[yygotominor.yy174->nExpr-1].sortOrder = (u8)yymsp[0].minor.yy46;
84428 }
84429 break;
84430 case 242: /* idxlist ::= nm collate sortorder */
84431 {
84432 Expr *p = 0;
84433 if( yymsp[-1].minor.yy0.n>0 ){
84434 p = sqlite3PExpr(pParse, TK_COLUMN, 0, 0, 0);
84435 sqlite3ExprSetColl(pParse, p, &yymsp[-1].minor.yy0);
84436 }
84437 yygotominor.yy174 = sqlite3ExprListAppend(pParse,0, p, &yymsp[-2].minor.yy0);
84438 sqlite3ExprListCheckLength(pParse, yygotominor.yy174, "index");
84439 if( yygotominor.yy174 ) yygotominor.yy174->a[yygotominor.yy174->nExpr-1].sortOrder = (u8)yymsp[0].minor.yy46;
84440 }
84441 break;
84442 case 243: /* collate ::= */
84443 {yygotominor.yy0.z = 0; yygotominor.yy0.n = 0;}
84444 break;
84445 case 245: /* cmd ::= DROP INDEX ifexists fullname */
84446 {sqlite3DropIndex(pParse, yymsp[0].minor.yy373, yymsp[-1].minor.yy46);}
84447 break;
84448 case 246: /* cmd ::= VACUUM */
84449 case 247: /* cmd ::= VACUUM nm */
84450 {sqlite3Vacuum(pParse);}
84451 break;
84452 case 248: /* cmd ::= PRAGMA nm dbnm EQ nmnum */
84453 case 249: /* cmd ::= PRAGMA nm dbnm EQ ON */
84454 case 250: /* cmd ::= PRAGMA nm dbnm EQ DELETE */
84455 {sqlite3Pragma(pParse,&yymsp[-3].minor.yy0,&yymsp[-2].minor.yy0,&yymsp[0].minor.yy0,0);}
84456 break;
84457 case 251: /* cmd ::= PRAGMA nm dbnm EQ minus_num */
84458 {
84459 sqlite3Pragma(pParse,&yymsp[-3].minor.yy0,&yymsp[-2].minor.yy0,&yymsp[0].minor.yy0,1);
84460 }
84461 break;
84462 case 252: /* cmd ::= PRAGMA nm dbnm LP nmnum RP */
84463 {sqlite3Pragma(pParse,&yymsp[-4].minor.yy0,&yymsp[-3].minor.yy0,&yymsp[-1].minor.yy0,0);}
84464 break;
84465 case 253: /* cmd ::= PRAGMA nm dbnm */
84466 {sqlite3Pragma(pParse,&yymsp[-1].minor.yy0,&yymsp[0].minor.yy0,0,0);}
84467 break;
84468 case 261: /* cmd ::= CREATE trigger_decl BEGIN trigger_cmd_list END */
84469 {
84470 Token all;
84471 all.z = yymsp[-3].minor.yy0.z;
84472 all.n = (int)(yymsp[0].minor.yy0.z - yymsp[-3].minor.yy0.z) + yymsp[0].minor.yy0.n;
84473 sqlite3FinishTrigger(pParse, yymsp[-1].minor.yy243, &all);
84474 }
84475 break;
84476 case 262: /* trigger_decl ::= temp TRIGGER ifnotexists nm dbnm trigger_time trigger_event ON fullname foreach_clause when_clause */
84477 {
84478 sqlite3BeginTrigger(pParse, &yymsp[-7].minor.yy0, &yymsp[-6].minor.yy0, yymsp[-5].minor.yy46, yymsp[-4].minor.yy370.a, yymsp[-4].minor.yy370.b, yymsp[-2].minor.yy373, yymsp[0].minor.yy172, yymsp[-10].minor.yy46, yymsp[-8].minor.yy46);
84479 yygotominor.yy0 = (yymsp[-6].minor.yy0.n==0?yymsp[-7].minor.yy0:yymsp[-6].minor.yy0);
84480 }
84481 break;
84482 case 263: /* trigger_time ::= BEFORE */
84483 case 266: /* trigger_time ::= */
84484 { yygotominor.yy46 = TK_BEFORE; }
84485 break;
84486 case 264: /* trigger_time ::= AFTER */
84487 { yygotominor.yy46 = TK_AFTER; }
84488 break;
84489 case 265: /* trigger_time ::= INSTEAD OF */
84490 { yygotominor.yy46 = TK_INSTEAD;}
84491 break;
84492 case 267: /* trigger_event ::= DELETE|INSERT */
84493 case 268: /* trigger_event ::= UPDATE */
84494 {yygotominor.yy370.a = yymsp[0].major; yygotominor.yy370.b = 0;}
84495 break;
84496 case 269: /* trigger_event ::= UPDATE OF inscollist */
84497 {yygotominor.yy370.a = TK_UPDATE; yygotominor.yy370.b = yymsp[0].minor.yy432;}
84498 break;
84499 case 272: /* when_clause ::= */
84500 case 289: /* key_opt ::= */
84501 { yygotominor.yy172 = 0; }
84502 break;
84503 case 273: /* when_clause ::= WHEN expr */
84504 case 290: /* key_opt ::= KEY expr */
84505 { yygotominor.yy172 = yymsp[0].minor.yy172; }
84506 break;
84507 case 274: /* trigger_cmd_list ::= trigger_cmd_list trigger_cmd SEMI */
84508 {
84509 /*
84510 if( yymsp[-2].minor.yy243 ){
84511 yymsp[-2].minor.yy243->pLast->pNext = yymsp[-1].minor.yy243;
84512 }else{
84513 yymsp[-2].minor.yy243 = yymsp[-1].minor.yy243;
84514 }
84515 */
84516 assert( yymsp[-2].minor.yy243!=0 );
84517 yymsp[-2].minor.yy243->pLast->pNext = yymsp[-1].minor.yy243;
84518 yymsp[-2].minor.yy243->pLast = yymsp[-1].minor.yy243;
84519 yygotominor.yy243 = yymsp[-2].minor.yy243;
84520 }
84521 break;
84522 case 275: /* trigger_cmd_list ::= trigger_cmd SEMI */
84523 {
84524 /* if( yymsp[-1].minor.yy243 ) */
84525 assert( yymsp[-1].minor.yy243!=0 );
84526 yymsp[-1].minor.yy243->pLast = yymsp[-1].minor.yy243;
84527 yygotominor.yy243 = yymsp[-1].minor.yy243;
84528 }
84529 break;
84530 case 276: /* trigger_cmd ::= UPDATE orconf nm SET setlist where_opt */
84531 { yygotominor.yy243 = sqlite3TriggerUpdateStep(pParse->db, &yymsp[-3].minor.yy0, yymsp[-1].minor.yy174, yymsp[0].minor.yy172, yymsp[-4].minor.yy46); }
84532 break;
84533 case 277: /* trigger_cmd ::= insert_cmd INTO nm inscollist_opt VALUES LP itemlist RP */
84534 {yygotominor.yy243 = sqlite3TriggerInsertStep(pParse->db, &yymsp[-5].minor.yy0, yymsp[-4].minor.yy432, yymsp[-1].minor.yy174, 0, yymsp[-7].minor.yy46);}
84535 break;
84536 case 278: /* trigger_cmd ::= insert_cmd INTO nm inscollist_opt select */
84537 {yygotominor.yy243 = sqlite3TriggerInsertStep(pParse->db, &yymsp[-2].minor.yy0, yymsp[-1].minor.yy432, 0, yymsp[0].minor.yy219, yymsp[-4].minor.yy46);}
84538 break;
84539 case 279: /* trigger_cmd ::= DELETE FROM nm where_opt */
84540 {yygotominor.yy243 = sqlite3TriggerDeleteStep(pParse->db, &yymsp[-1].minor.yy0, yymsp[0].minor.yy172);}
84541 break;
84542 case 280: /* trigger_cmd ::= select */
84543 {yygotominor.yy243 = sqlite3TriggerSelectStep(pParse->db, yymsp[0].minor.yy219); }
84544 break;
84545 case 281: /* expr ::= RAISE LP IGNORE RP */
84546 {
84547 yygotominor.yy172 = sqlite3PExpr(pParse, TK_RAISE, 0, 0, 0);
84548 if( yygotominor.yy172 ){
84549 yygotominor.yy172->iColumn = OE_Ignore;
84550 sqlite3ExprSpan(yygotominor.yy172, &yymsp[-3].minor.yy0, &yymsp[0].minor.yy0);
84551 }
84552 }
84553 break;
84554 case 282: /* expr ::= RAISE LP raisetype COMMA nm RP */
84555 {
84556 yygotominor.yy172 = sqlite3PExpr(pParse, TK_RAISE, 0, 0, &yymsp[-1].minor.yy0);
84557 if( yygotominor.yy172 ) {
84558 yygotominor.yy172->iColumn = yymsp[-3].minor.yy46;
84559 sqlite3ExprSpan(yygotominor.yy172, &yymsp[-5].minor.yy0, &yymsp[0].minor.yy0);
84560 }
84561 }
84562 break;
84563 case 283: /* raisetype ::= ROLLBACK */
84564 {yygotominor.yy46 = OE_Rollback;}
84565 break;
84566 case 285: /* raisetype ::= FAIL */
84567 {yygotominor.yy46 = OE_Fail;}
84568 break;
84569 case 286: /* cmd ::= DROP TRIGGER ifexists fullname */
84570 {
84571 sqlite3DropTrigger(pParse,yymsp[0].minor.yy373,yymsp[-1].minor.yy46);
84572 }
84573 break;
84574 case 287: /* cmd ::= ATTACH database_kw_opt expr AS expr key_opt */
84575 {
84576 sqlite3Attach(pParse, yymsp[-3].minor.yy172, yymsp[-1].minor.yy172, yymsp[0].minor.yy172);
84577 }
84578 break;
84579 case 288: /* cmd ::= DETACH database_kw_opt expr */
84580 {
84581 sqlite3Detach(pParse, yymsp[0].minor.yy172);
84582 }
84583 break;
84584 case 293: /* cmd ::= REINDEX */
84585 {sqlite3Reindex(pParse, 0, 0);}
84586 break;
84587 case 294: /* cmd ::= REINDEX nm dbnm */
84588 {sqlite3Reindex(pParse, &yymsp[-1].minor.yy0, &yymsp[0].minor.yy0);}
84589 break;
84590 case 295: /* cmd ::= ANALYZE */
84591 {sqlite3Analyze(pParse, 0, 0);}
84592 break;
84593 case 296: /* cmd ::= ANALYZE nm dbnm */
84594 {sqlite3Analyze(pParse, &yymsp[-1].minor.yy0, &yymsp[0].minor.yy0);}
84595 break;
84596 case 297: /* cmd ::= ALTER TABLE fullname RENAME TO nm */
84597 {
84598 sqlite3AlterRenameTable(pParse,yymsp[-3].minor.yy373,&yymsp[0].minor.yy0);
84599 }
84600 break;
84601 case 298: /* cmd ::= ALTER TABLE add_column_fullname ADD kwcolumn_opt column */
84602 {
84603 sqlite3AlterFinishAddColumn(pParse, &yymsp[0].minor.yy0);
84604 }
84605 break;
84606 case 299: /* add_column_fullname ::= fullname */
84607 {
84608 sqlite3AlterBeginAddColumn(pParse, yymsp[0].minor.yy373);
84609 }
84610 break;
84611 case 302: /* cmd ::= create_vtab */
84612 {sqlite3VtabFinishParse(pParse,0);}
84613 break;
84614 case 303: /* cmd ::= create_vtab LP vtabarglist RP */
84615 {sqlite3VtabFinishParse(pParse,&yymsp[0].minor.yy0);}
84616 break;
84617 case 304: /* create_vtab ::= CREATE VIRTUAL TABLE nm dbnm USING nm */
84618 {
84619 sqlite3VtabBeginParse(pParse, &yymsp[-3].minor.yy0, &yymsp[-2].minor.yy0, &yymsp[0].minor.yy0);
84620 }
84621 break;
84622 case 307: /* vtabarg ::= */
84623 {sqlite3VtabArgInit(pParse);}
84624 break;
84625 case 309: /* vtabargtoken ::= ANY */
84626 case 310: /* vtabargtoken ::= lp anylist RP */
84627 case 311: /* lp ::= LP */
84628 case 313: /* anylist ::= anylist ANY */
84629 {sqlite3VtabArgExtend(pParse,&yymsp[0].minor.yy0);}
84630 break;
84631 };
84632 yygoto = yyRuleInfo[yyruleno].lhs;
84633 yysize = yyRuleInfo[yyruleno].nrhs;
@@ -84938,141 +86013,264 @@
84938 /************** Begin file keywordhash.h *************************************/
84939 /***** This file contains automatically generated code ******
84940 **
84941 ** The code in this file has been automatically generated by
84942 **
84943 ** $Header: /sqlite/sqlite/tool/mkkeywordhash.c,v 1.34 2008/12/10 20:11:01 shane Exp $
84944 **
84945 ** The code in this file implements a function that determines whether
84946 ** or not a given identifier is really an SQL keyword. The same thing
84947 ** might be implemented more directly using a hand-written hash table.
84948 ** But by using this automatically generated code, the size of the code
84949 ** is substantially reduced. This is important for embedded applications
84950 ** on platforms with limited memory.
84951 */
84952 /* Hash score: 167 */
84953 static int keywordCode(const char *z, int n){
84954 /* zText[] encodes 783 bytes of keywords in 528 bytes */
84955 /* REINDEXEDESCAPEACHECKEYBEFOREIGNOREGEXPLAINSTEADDATABASELECT */
84956 /* ABLEFTHENDEFERRABLELSEXCEPTRANSACTIONATURALTERAISEXCLUSIVE */
84957 /* XISTSCONSTRAINTERSECTRIGGEREFERENCESUNIQUERYATTACHAVINGROUP */
84958 /* DATEMPORARYBEGINNERENAMEBETWEENOTNULLIKECASCADELETECASECOLLATE */
84959 /* CREATECURRENT_DATEDETACHIMMEDIATEJOINSERTMATCHPLANALYZEPRAGMA */
84960 /* BORTVALUESVIRTUALIMITWHENWHEREPLACEAFTERESTRICTANDEFAULT */
84961 /* AUTOINCREMENTCASTCOLUMNCOMMITCONFLICTCROSSCURRENT_TIMESTAMP */
84962 /* RIMARYDEFERREDISTINCTDROPFAILFROMFULLGLOBYIFINTOFFSETISNULL */
84963 /* ORDERIGHTOUTEROLLBACKROWUNIONUSINGVACUUMVIEWINITIALLY */
84964 static const char zText[528] = {
 
84965 'R','E','I','N','D','E','X','E','D','E','S','C','A','P','E','A','C','H',
84966 'E','C','K','E','Y','B','E','F','O','R','E','I','G','N','O','R','E','G',
84967 'E','X','P','L','A','I','N','S','T','E','A','D','D','A','T','A','B','A',
84968 'S','E','L','E','C','T','A','B','L','E','F','T','H','E','N','D','E','F',
84969 'E','R','R','A','B','L','E','L','S','E','X','C','E','P','T','R','A','N',
84970 'S','A','C','T','I','O','N','A','T','U','R','A','L','T','E','R','A','I',
84971 'S','E','X','C','L','U','S','I','V','E','X','I','S','T','S','C','O','N',
84972 'S','T','R','A','I','N','T','E','R','S','E','C','T','R','I','G','G','E',
84973 'R','E','F','E','R','E','N','C','E','S','U','N','I','Q','U','E','R','Y',
84974 'A','T','T','A','C','H','A','V','I','N','G','R','O','U','P','D','A','T',
84975 'E','M','P','O','R','A','R','Y','B','E','G','I','N','N','E','R','E','N',
84976 'A','M','E','B','E','T','W','E','E','N','O','T','N','U','L','L','I','K',
84977 'E','C','A','S','C','A','D','E','L','E','T','E','C','A','S','E','C','O',
84978 'L','L','A','T','E','C','R','E','A','T','E','C','U','R','R','E','N','T',
84979 '_','D','A','T','E','D','E','T','A','C','H','I','M','M','E','D','I','A',
84980 'T','E','J','O','I','N','S','E','R','T','M','A','T','C','H','P','L','A',
84981 'N','A','L','Y','Z','E','P','R','A','G','M','A','B','O','R','T','V','A',
84982 'L','U','E','S','V','I','R','T','U','A','L','I','M','I','T','W','H','E',
84983 'N','W','H','E','R','E','P','L','A','C','E','A','F','T','E','R','E','S',
84984 'T','R','I','C','T','A','N','D','E','F','A','U','L','T','A','U','T','O',
84985 'I','N','C','R','E','M','E','N','T','C','A','S','T','C','O','L','U','M',
84986 'N','C','O','M','M','I','T','C','O','N','F','L','I','C','T','C','R','O',
84987 'S','S','C','U','R','R','E','N','T','_','T','I','M','E','S','T','A','M',
84988 'P','R','I','M','A','R','Y','D','E','F','E','R','R','E','D','I','S','T',
84989 'I','N','C','T','D','R','O','P','F','A','I','L','F','R','O','M','F','U',
84990 'L','L','G','L','O','B','Y','I','F','I','N','T','O','F','F','S','E','T',
84991 'I','S','N','U','L','L','O','R','D','E','R','I','G','H','T','O','U','T',
84992 'E','R','O','L','L','B','A','C','K','R','O','W','U','N','I','O','N','U',
84993 'S','I','N','G','V','A','C','U','U','M','V','I','E','W','I','N','I','T',
84994 'I','A','L','L','Y',0
84995 };
84996 static const unsigned char aHash[127] = {
84997 65, 94, 110, 63, 0, 44, 0, 0, 71, 0, 66, 0, 0,
84998 104, 12, 67, 15, 0, 108, 74, 105, 101, 0, 19, 0, 0,
84999 114, 0, 112, 78, 0, 22, 82, 0, 9, 0, 0, 59, 60,
85000 0, 58, 6, 0, 39, 79, 91, 0, 111, 90, 0, 0, 45,
85001 0, 92, 24, 0, 17, 0, 115, 40, 23, 0, 5, 99, 25,
85002 85, 0, 0, 117, 95, 50, 116, 47, 7, 42, 0, 80, 0,
85003 89, 26, 0, 88, 0, 0, 0, 84, 81, 86, 77, 98, 14,
85004 34, 97, 0, 70, 0, 18, 76, 100, 31, 0, 113, 69, 106,
85005 52, 46, 73, 0, 0, 83, 102, 0, 109, 0, 35, 0, 0,
85006 28, 0, 75, 48, 53, 0, 20, 51, 0, 43,
85007 };
85008 static const unsigned char aNext[117] = {
85009 0, 0, 0, 0, 4, 0, 0, 0, 0, 0, 0, 0, 0,
85010 0, 2, 0, 0, 0, 0, 0, 0, 13, 0, 0, 0, 0,
85011 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
85012 0, 0, 3, 38, 0, 32, 21, 0, 0, 0, 0, 29, 0,
85013 0, 37, 0, 0, 0, 1, 55, 0, 0, 56, 0, 0, 0,
85014 0, 0, 0, 0, 0, 0, 54, 0, 0, 0, 0, 30, 0,
85015 16, 33, 10, 0, 0, 0, 0, 0, 0, 0, 11, 61, 68,
85016 0, 8, 0, 93, 87, 0, 96, 0, 49, 0, 0, 64, 0,
85017 41, 103, 0, 27, 107, 36, 62, 72, 0, 0, 57, 0, 0,
 
85018 };
85019 static const unsigned char aLen[117] = {
85020 7, 7, 5, 4, 6, 4, 5, 3, 6, 7, 3, 6, 6,
85021 7, 7, 3, 8, 2, 6, 5, 4, 4, 3, 10, 4, 6,
85022 11, 2, 7, 5, 5, 9, 6, 10, 9, 7, 10, 6, 5,
85023 6, 6, 5, 6, 4, 9, 2, 5, 5, 6, 7, 7, 3,
85024 4, 4, 7, 3, 6, 4, 7, 6, 12, 6, 9, 4, 6,
85025 5, 4, 7, 6, 5, 6, 7, 5, 4, 5, 7, 5, 8,
85026 3, 7, 13, 2, 2, 4, 6, 6, 8, 5, 17, 12, 7,
85027 8, 8, 2, 4, 4, 4, 4, 4, 2, 2, 4, 6, 2,
85028 3, 6, 5, 5, 5, 8, 3, 5, 5, 6, 4, 9, 3,
 
85029 };
85030 static const unsigned short int aOffset[117] = {
85031 0, 2, 2, 8, 9, 14, 16, 20, 23, 25, 25, 29, 33,
85032 36, 41, 46, 48, 53, 54, 59, 62, 65, 67, 69, 78, 81,
85033 86, 95, 96, 101, 105, 109, 117, 123, 130, 138, 144, 154, 157,
85034 162, 167, 172, 175, 179, 179, 183, 188, 191, 195, 201, 207, 207,
85035 210, 213, 217, 218, 222, 228, 232, 239, 245, 257, 263, 272, 274,
85036 280, 285, 287, 294, 299, 304, 310, 316, 321, 325, 328, 335, 339,
85037 347, 349, 356, 358, 360, 369, 373, 379, 385, 393, 398, 398, 414,
85038 421, 428, 429, 436, 440, 444, 448, 452, 455, 457, 459, 462, 462,
85039 465, 468, 474, 478, 483, 487, 495, 498, 503, 508, 514, 518, 523,
 
85040 };
85041 static const unsigned char aCode[117] = {
85042 TK_REINDEX, TK_INDEXED, TK_INDEX, TK_DESC, TK_ESCAPE,
85043 TK_EACH, TK_CHECK, TK_KEY, TK_BEFORE, TK_FOREIGN,
85044 TK_FOR, TK_IGNORE, TK_LIKE_KW, TK_EXPLAIN, TK_INSTEAD,
85045 TK_ADD, TK_DATABASE, TK_AS, TK_SELECT, TK_TABLE,
85046 TK_JOIN_KW, TK_THEN, TK_END, TK_DEFERRABLE, TK_ELSE,
85047 TK_EXCEPT, TK_TRANSACTION,TK_ON, TK_JOIN_KW, TK_ALTER,
85048 TK_RAISE, TK_EXCLUSIVE, TK_EXISTS, TK_CONSTRAINT, TK_INTERSECT,
85049 TK_TRIGGER, TK_REFERENCES, TK_UNIQUE, TK_QUERY, TK_ATTACH,
85050 TK_HAVING, TK_GROUP, TK_UPDATE, TK_TEMP, TK_TEMP,
85051 TK_OR, TK_BEGIN, TK_JOIN_KW, TK_RENAME, TK_BETWEEN,
 
85052 TK_NOTNULL, TK_NOT, TK_NULL, TK_LIKE_KW, TK_CASCADE,
85053 TK_ASC, TK_DELETE, TK_CASE, TK_COLLATE, TK_CREATE,
85054 TK_CTIME_KW, TK_DETACH, TK_IMMEDIATE, TK_JOIN, TK_INSERT,
85055 TK_MATCH, TK_PLAN, TK_ANALYZE, TK_PRAGMA, TK_ABORT,
85056 TK_VALUES, TK_VIRTUAL, TK_LIMIT, TK_WHEN, TK_WHERE,
85057 TK_REPLACE, TK_AFTER, TK_RESTRICT, TK_AND, TK_DEFAULT,
85058 TK_AUTOINCR, TK_TO, TK_IN, TK_CAST, TK_COLUMNKW,
85059 TK_COMMIT, TK_CONFLICT, TK_JOIN_KW, TK_CTIME_KW, TK_CTIME_KW,
85060 TK_PRIMARY, TK_DEFERRED, TK_DISTINCT, TK_IS, TK_DROP,
85061 TK_FAIL, TK_FROM, TK_JOIN_KW, TK_LIKE_KW, TK_BY,
85062 TK_IF, TK_INTO, TK_OFFSET, TK_OF, TK_SET,
85063 TK_ISNULL, TK_ORDER, TK_JOIN_KW, TK_JOIN_KW, TK_ROLLBACK,
85064 TK_ROW, TK_UNION, TK_USING, TK_VACUUM, TK_VIEW,
85065 TK_INITIALLY, TK_ALL,
85066 };
85067 int h, i;
85068 if( n<2 ) return TK_ID;
85069 h = ((charMap(z[0])*4) ^
85070 (charMap(z[n-1])*3) ^
85071 n) % 127;
85072 for(i=((int)aHash[h])-1; i>=0; i=((int)aNext[i])-1){
85073 if( aLen[i]==n && sqlite3StrNICmp(&zText[aOffset[i]],z,n)==0 ){
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
85074 return aCode[i];
85075 }
85076 }
85077 return TK_ID;
85078 }
@@ -85826,11 +87024,11 @@
85826 ** Main file for the SQLite library. The routines in this file
85827 ** implement the programmer interface to the library. Routines in
85828 ** other files are for internal use by SQLite and should not be
85829 ** accessed by users of the library.
85830 **
85831 ** $Id: main.c,v 1.519 2008/12/10 23:04:13 drh Exp $
85832 */
85833
85834 #ifdef SQLITE_ENABLE_FTS3
85835 /************** Include fts3.h in the middle of main.c ***********************/
85836 /************** Begin file fts3.h ********************************************/
@@ -86442,10 +87640,25 @@
86442 ** Return the number of changes since the database handle was opened.
86443 */
86444 SQLITE_API int sqlite3_total_changes(sqlite3 *db){
86445 return db->nTotalChange;
86446 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
86447
86448 /*
86449 ** Close an existing SQLite database
86450 */
86451 SQLITE_API int sqlite3_close(sqlite3 *db){
@@ -86484,10 +87697,13 @@
86484 "Unable to close due to unfinalised statements");
86485 sqlite3_mutex_leave(db->mutex);
86486 return SQLITE_BUSY;
86487 }
86488 assert( sqlite3SafetyCheckSickOrOk(db) );
 
 
 
86489
86490 for(j=0; j<db->nDb; j++){
86491 struct Db *pDb = &db->aDb[j];
86492 if( pDb->pBt ){
86493 sqlite3BtreeClose(pDb->pBt);
@@ -88306,126 +89522,27 @@
88306 #if defined(SQLITE_ENABLE_FTS3) && !defined(SQLITE_CORE)
88307 # define SQLITE_CORE 1
88308 #endif
88309
88310
88311 /************** Include fts3_hash.h in the middle of fts3.c ******************/
88312 /************** Begin file fts3_hash.h ***************************************/
88313 /*
88314 ** 2001 September 22
88315 **
88316 ** The author disclaims copyright to this source code. In place of
88317 ** a legal notice, here is a blessing:
88318 **
88319 ** May you do good and not evil.
88320 ** May you find forgiveness for yourself and forgive others.
88321 ** May you share freely, never taking more than you give.
88322 **
88323 *************************************************************************
88324 ** This is the header file for the generic hash-table implemenation
88325 ** used in SQLite. We've modified it slightly to serve as a standalone
88326 ** hash table implementation for the full-text indexing module.
88327 **
88328 */
88329 #ifndef _FTS3_HASH_H_
88330 #define _FTS3_HASH_H_
88331
88332 /* Forward declarations of structures. */
88333 typedef struct fts3Hash fts3Hash;
88334 typedef struct fts3HashElem fts3HashElem;
88335
88336 /* A complete hash table is an instance of the following structure.
88337 ** The internals of this structure are intended to be opaque -- client
88338 ** code should not attempt to access or modify the fields of this structure
88339 ** directly. Change this structure only by using the routines below.
88340 ** However, many of the "procedures" and "functions" for modifying and
88341 ** accessing this structure are really macros, so we can't really make
88342 ** this structure opaque.
88343 */
88344 struct fts3Hash {
88345 char keyClass; /* HASH_INT, _POINTER, _STRING, _BINARY */
88346 char copyKey; /* True if copy of key made on insert */
88347 int count; /* Number of entries in this table */
88348 fts3HashElem *first; /* The first element of the array */
88349 int htsize; /* Number of buckets in the hash table */
88350 struct _fts3ht { /* the hash table */
88351 int count; /* Number of entries with this hash */
88352 fts3HashElem *chain; /* Pointer to first entry with this hash */
88353 } *ht;
88354 };
88355
88356 /* Each element in the hash table is an instance of the following
88357 ** structure. All elements are stored on a single doubly-linked list.
88358 **
88359 ** Again, this structure is intended to be opaque, but it can't really
88360 ** be opaque because it is used by macros.
88361 */
88362 struct fts3HashElem {
88363 fts3HashElem *next, *prev; /* Next and previous elements in the table */
88364 void *data; /* Data associated with this element */
88365 void *pKey; int nKey; /* Key associated with this element */
88366 };
88367
88368 /*
88369 ** There are 2 different modes of operation for a hash table:
88370 **
88371 ** FTS3_HASH_STRING pKey points to a string that is nKey bytes long
88372 ** (including the null-terminator, if any). Case
88373 ** is respected in comparisons.
88374 **
88375 ** FTS3_HASH_BINARY pKey points to binary data nKey bytes long.
88376 ** memcmp() is used to compare keys.
88377 **
88378 ** A copy of the key is made if the copyKey parameter to fts3HashInit is 1.
88379 */
88380 #define FTS3_HASH_STRING 1
88381 #define FTS3_HASH_BINARY 2
88382
88383 /*
88384 ** Access routines. To delete, insert a NULL pointer.
88385 */
88386 SQLITE_PRIVATE void sqlite3Fts3HashInit(fts3Hash*, int keytype, int copyKey);
88387 SQLITE_PRIVATE void *sqlite3Fts3HashInsert(fts3Hash*, const void *pKey, int nKey, void *pData);
88388 SQLITE_PRIVATE void *sqlite3Fts3HashFind(const fts3Hash*, const void *pKey, int nKey);
88389 SQLITE_PRIVATE void sqlite3Fts3HashClear(fts3Hash*);
88390
88391 /*
88392 ** Shorthand for the functions above
88393 */
88394 #define fts3HashInit sqlite3Fts3HashInit
88395 #define fts3HashInsert sqlite3Fts3HashInsert
88396 #define fts3HashFind sqlite3Fts3HashFind
88397 #define fts3HashClear sqlite3Fts3HashClear
88398
88399 /*
88400 ** Macros for looping over all elements of a hash table. The idiom is
88401 ** like this:
88402 **
88403 ** fts3Hash h;
88404 ** fts3HashElem *p;
88405 ** ...
88406 ** for(p=fts3HashFirst(&h); p; p=fts3HashNext(p)){
88407 ** SomeStructure *pData = fts3HashData(p);
88408 ** // do something with pData
88409 ** }
88410 */
88411 #define fts3HashFirst(H) ((H)->first)
88412 #define fts3HashNext(E) ((E)->next)
88413 #define fts3HashData(E) ((E)->data)
88414 #define fts3HashKey(E) ((E)->pKey)
88415 #define fts3HashKeysize(E) ((E)->nKey)
88416
88417 /*
88418 ** Number of entries in a hash table
88419 */
88420 #define fts3HashCount(H) ((H)->count)
88421
88422 #endif /* _FTS3_HASH_H_ */
88423
88424 /************** End of fts3_hash.h *******************************************/
88425 /************** Continuing where we left off in fts3.c ***********************/
88426 /************** Include fts3_tokenizer.h in the middle of fts3.c *************/
88427 /************** Begin file fts3_tokenizer.h **********************************/
88428 /*
88429 ** 2006 July 10
88430 **
88431 ** The author disclaims copyright to this source code.
@@ -88569,10 +89686,208 @@
88569 };
88570
88571 #endif /* _FTS3_TOKENIZER_H_ */
88572
88573 /************** End of fts3_tokenizer.h **************************************/
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
88574 /************** Continuing where we left off in fts3.c ***********************/
88575 #ifndef SQLITE_CORE
88576 SQLITE_EXTENSION_INIT1
88577 #endif
88578
@@ -88594,15 +89909,10 @@
88594 # define FTSTRACE(A) printf A; fflush(stdout)
88595 #else
88596 # define FTSTRACE(A)
88597 #endif
88598
88599 /*
88600 ** Default span for NEAR operators.
88601 */
88602 #define SQLITE_FTS3_DEFAULT_NEAR_PARAM 10
88603
88604 /* It is not safe to call isspace(), tolower(), or isalnum() on
88605 ** hi-bit-set characters. This is the same solution used in the
88606 ** tokenizer.
88607 */
88608 /* TODO(shess) The snippet-generation code should be using the
@@ -90069,94 +91379,10 @@
90069
90070 /* end utility functions */
90071
90072 /* Forward reference */
90073 typedef struct fulltext_vtab fulltext_vtab;
90074
90075 /* A single term in a query is represented by an instances of
90076 ** the following structure. Each word which may match against
90077 ** document content is a term. Operators, like NEAR or OR, are
90078 ** not terms. Query terms are organized as a flat list stored
90079 ** in the Query.pTerms array.
90080 **
90081 ** If the QueryTerm.nPhrase variable is non-zero, then the QueryTerm
90082 ** is the first in a contiguous string of terms that are either part
90083 ** of the same phrase, or connected by the NEAR operator.
90084 **
90085 ** If the QueryTerm.nNear variable is non-zero, then the token is followed
90086 ** by a NEAR operator with span set to (nNear-1). For example, the
90087 ** following query:
90088 **
90089 ** The QueryTerm.iPhrase variable stores the index of the token within
90090 ** its phrase, indexed starting at 1, or 1 if the token is not part
90091 ** of any phrase.
90092 **
90093 ** For example, the data structure used to represent the following query:
90094 **
90095 ** ... MATCH 'sqlite NEAR/5 google NEAR/2 "search engine"'
90096 **
90097 ** is:
90098 **
90099 ** {nPhrase=4, iPhrase=1, nNear=6, pTerm="sqlite"},
90100 ** {nPhrase=0, iPhrase=1, nNear=3, pTerm="google"},
90101 ** {nPhrase=0, iPhrase=1, nNear=0, pTerm="search"},
90102 ** {nPhrase=0, iPhrase=2, nNear=0, pTerm="engine"},
90103 **
90104 ** compiling the FTS3 syntax to Query structures is done by the parseQuery()
90105 ** function.
90106 */
90107 typedef struct QueryTerm {
90108 short int nPhrase; /* How many following terms are part of the same phrase */
90109 short int iPhrase; /* This is the i-th term of a phrase. */
90110 short int iColumn; /* Column of the index that must match this term */
90111 short int nNear; /* term followed by a NEAR operator with span=(nNear-1) */
90112 signed char isOr; /* this term is preceded by "OR" */
90113 signed char isNot; /* this term is preceded by "-" */
90114 signed char isPrefix; /* this term is followed by "*" */
90115 char *pTerm; /* text of the term. '\000' terminated. malloced */
90116 int nTerm; /* Number of bytes in pTerm[] */
90117 } QueryTerm;
90118
90119
90120 /* A query string is parsed into a Query structure.
90121 *
90122 * We could, in theory, allow query strings to be complicated
90123 * nested expressions with precedence determined by parentheses.
90124 * But none of the major search engines do this. (Perhaps the
90125 * feeling is that an parenthesized expression is two complex of
90126 * an idea for the average user to grasp.) Taking our lead from
90127 * the major search engines, we will allow queries to be a list
90128 * of terms (with an implied AND operator) or phrases in double-quotes,
90129 * with a single optional "-" before each non-phrase term to designate
90130 * negation and an optional OR connector.
90131 *
90132 * OR binds more tightly than the implied AND, which is what the
90133 * major search engines seem to do. So, for example:
90134 *
90135 * [one two OR three] ==> one AND (two OR three)
90136 * [one OR two three] ==> (one OR two) AND three
90137 *
90138 * A "-" before a term matches all entries that lack that term.
90139 * The "-" must occur immediately before the term with in intervening
90140 * space. This is how the search engines do it.
90141 *
90142 * A NOT term cannot be the right-hand operand of an OR. If this
90143 * occurs in the query string, the NOT is ignored:
90144 *
90145 * [one OR -two] ==> one OR two
90146 *
90147 */
90148 typedef struct Query {
90149 fulltext_vtab *pFts; /* The full text index */
90150 int nTerms; /* Number of terms in the query */
90151 QueryTerm *pTerms; /* Array of terms. Space obtained from malloc() */
90152 int nextIsOr; /* Set the isOr flag on the next inserted term */
90153 int nextIsNear; /* Set the isOr flag on the next inserted term */
90154 int nextColumn; /* Next word parsed must be in this column */
90155 int dfltColumn; /* The default column */
90156 } Query;
90157
90158
90159 /*
90160 ** An instance of the following structure keeps track of generated
90161 ** matching-word offset information and snippets.
90162 */
@@ -90304,18 +91530,18 @@
90304 typedef struct fulltext_cursor {
90305 sqlite3_vtab_cursor base; /* Base class used by SQLite core */
90306 QueryType iCursorType; /* Copy of sqlite3_index_info.idxNum */
90307 sqlite3_stmt *pStmt; /* Prepared statement in use by the cursor */
90308 int eof; /* True if at End Of Results */
90309 Query q; /* Parsed query string */
90310 Snippet snippet; /* Cached snippet for the current row */
90311 int iColumn; /* Column being searched */
90312 DataBuffer result; /* Doclist results from fulltextQuery */
90313 DLReader reader; /* Result reader if result not empty */
90314 } fulltext_cursor;
90315
90316 static struct fulltext_vtab *cursor_vtab(fulltext_cursor *c){
90317 return (fulltext_vtab *) c->base.pVtab;
90318 }
90319
90320 static const sqlite3_module fts3Module; /* forward declaration */
90321
@@ -91459,31 +92685,20 @@
91459 }else{
91460 return SQLITE_NOMEM;
91461 }
91462 }
91463
91464
91465 /* Free all of the dynamically allocated memory held by *q
91466 */
91467 static void queryClear(Query *q){
91468 int i;
91469 for(i = 0; i < q->nTerms; ++i){
91470 sqlite3_free(q->pTerms[i].pTerm);
91471 }
91472 sqlite3_free(q->pTerms);
91473 CLEAR(q);
91474 }
91475
91476 /* Free all of the dynamically allocated memory held by the
91477 ** Snippet
91478 */
91479 static void snippetClear(Snippet *p){
91480 sqlite3_free(p->aMatch);
91481 sqlite3_free(p->zOffset);
91482 sqlite3_free(p->zSnippet);
91483 CLEAR(p);
91484 }
 
91485 /*
91486 ** Append a single entry to the p->aMatch[] log.
91487 */
91488 static void snippetAppendMatch(
91489 Snippet *p, /* Append the entry to this snippet */
@@ -91514,29 +92729,88 @@
91514 /*
91515 ** Sizing information for the circular buffer used in snippetOffsetsOfColumn()
91516 */
91517 #define FTS3_ROTOR_SZ (32)
91518 #define FTS3_ROTOR_MASK (FTS3_ROTOR_SZ-1)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
91519
91520 /*
91521 ** Add entries to pSnippet->aMatch[] for every match that occurs against
91522 ** document zDoc[0..nDoc-1] which is stored in column iColumn.
91523 */
91524 static void snippetOffsetsOfColumn(
91525 Query *pQuery,
91526 Snippet *pSnippet,
91527 int iColumn,
91528 const char *zDoc,
91529 int nDoc
91530 ){
91531 const sqlite3_tokenizer_module *pTModule; /* The tokenizer module */
91532 sqlite3_tokenizer *pTokenizer; /* The specific tokenizer */
91533 sqlite3_tokenizer_cursor *pTCursor; /* Tokenizer cursor */
91534 fulltext_vtab *pVtab; /* The full text index */
91535 int nColumn; /* Number of columns in the index */
91536 const QueryTerm *aTerm; /* Query string terms */
91537 int nTerm; /* Number of query string terms */
91538 int i, j; /* Loop counters */
91539 int rc; /* Return code */
91540 unsigned int match, prevMatch; /* Phrase search bitmasks */
91541 const char *zToken; /* Next token from the tokenizer */
91542 int nToken; /* Size of zToken */
@@ -91546,41 +92820,43 @@
91546 ** few tokens */
91547 unsigned int iRotor = 0; /* Index of current token */
91548 int iRotorBegin[FTS3_ROTOR_SZ]; /* Beginning offset of token */
91549 int iRotorLen[FTS3_ROTOR_SZ]; /* Length of token */
91550
91551 pVtab = pQuery->pFts;
91552 nColumn = pVtab->nColumn;
91553 pTokenizer = pVtab->pTokenizer;
91554 pTModule = pTokenizer->pModule;
91555 rc = pTModule->xOpen(pTokenizer, zDoc, nDoc, &pTCursor);
91556 if( rc ) return;
91557 pTCursor->pTokenizer = pTokenizer;
91558 aTerm = pQuery->pTerms;
91559 nTerm = pQuery->nTerms;
91560 if( nTerm>=FTS3_ROTOR_SZ ){
91561 nTerm = FTS3_ROTOR_SZ - 1;
91562 }
91563 prevMatch = 0;
91564 while(1){
91565 rc = pTModule->xNext(pTCursor, &zToken, &nToken, &iBegin, &iEnd, &iPos);
91566 if( rc ) break;
91567 iRotorBegin[iRotor&FTS3_ROTOR_MASK] = iBegin;
91568 iRotorLen[iRotor&FTS3_ROTOR_MASK] = iEnd-iBegin;
91569 match = 0;
91570 for(i=0; i<nTerm; i++){
91571 int iCol;
91572 iCol = aTerm[i].iColumn;
 
 
 
 
 
 
91573 if( iCol>=0 && iCol<nColumn && iCol!=iColumn ) continue;
91574 if( aTerm[i].nTerm>nToken ) continue;
91575 if( !aTerm[i].isPrefix && aTerm[i].nTerm<nToken ) continue;
91576 assert( aTerm[i].nTerm<=nToken );
91577 if( memcmp(aTerm[i].pTerm, zToken, aTerm[i].nTerm) ) continue;
91578 if( aTerm[i].iPhrase>1 && (prevMatch & (1<<i))==0 ) continue;
91579 match |= 1<<i;
91580 if( i==nTerm-1 || aTerm[i+1].iPhrase==1 ){
91581 for(j=aTerm[i].iPhrase-1; j>=0; j--){
91582 int k = (iRotor-j) & FTS3_ROTOR_MASK;
91583 snippetAppendMatch(pSnippet, iColumn, i-j, iPos-j,
91584 iRotorBegin[k], iRotorLen[k]);
91585 }
91586 }
@@ -91606,90 +92882,119 @@
91606 ** A NEAR/0 E
91607 **
91608 ** then when this function is called the Snippet contains token offsets
91609 ** 0, 4 and 5. This function removes the "0" entry (because the first A
91610 ** is not near enough to an E).
91611 */
91612 static void trimSnippetOffsetsForNear(Query *pQuery, Snippet *pSnippet){
91613 int ii;
91614 int iDir = 1;
91615
91616 while(iDir>-2) {
91617 assert( iDir==1 || iDir==-1 );
91618 for(ii=0; ii<pSnippet->nMatch; ii++){
91619 int jj;
91620 int nNear;
91621 struct snippetMatch *pMatch = &pSnippet->aMatch[ii];
91622 QueryTerm *pQueryTerm = &pQuery->pTerms[pMatch->iTerm];
91623
91624 if( (pMatch->iTerm+iDir)<0
91625 || (pMatch->iTerm+iDir)>=pQuery->nTerms
91626 ){
91627 continue;
91628 }
91629
91630 nNear = pQueryTerm->nNear;
91631 if( iDir<0 ){
91632 nNear = pQueryTerm[-1].nNear;
91633 }
91634
91635 if( pMatch->iTerm>=0 && nNear ){
91636 int isOk = 0;
91637 int iNextTerm = pMatch->iTerm+iDir;
91638 int iPrevTerm = iNextTerm;
91639
91640 int iEndToken;
91641 int iStartToken;
91642
91643 if( iDir<0 ){
91644 int nPhrase = 1;
91645 iStartToken = pMatch->iToken;
91646 while( (pMatch->iTerm+nPhrase)<pQuery->nTerms
91647 && pQuery->pTerms[pMatch->iTerm+nPhrase].iPhrase>1
91648 ){
91649 nPhrase++;
91650 }
91651 iEndToken = iStartToken + nPhrase - 1;
91652 }else{
91653 iEndToken = pMatch->iToken;
91654 iStartToken = pMatch->iToken+1-pQueryTerm->iPhrase;
91655 }
91656
91657 while( pQuery->pTerms[iNextTerm].iPhrase>1 ){
91658 iNextTerm--;
91659 }
91660 while( (iPrevTerm+1)<pQuery->nTerms &&
91661 pQuery->pTerms[iPrevTerm+1].iPhrase>1
91662 ){
91663 iPrevTerm++;
91664 }
91665
91666 for(jj=0; isOk==0 && jj<pSnippet->nMatch; jj++){
91667 struct snippetMatch *p = &pSnippet->aMatch[jj];
91668 if( p->iCol==pMatch->iCol && ((
91669 p->iTerm==iNextTerm &&
91670 p->iToken>iEndToken &&
91671 p->iToken<=iEndToken+nNear
91672 ) || (
91673 p->iTerm==iPrevTerm &&
91674 p->iToken<iStartToken &&
91675 p->iToken>=iStartToken-nNear
91676 ))){
91677 isOk = 1;
91678 }
91679 }
91680 if( !isOk ){
91681 for(jj=1-pQueryTerm->iPhrase; jj<=0; jj++){
91682 pMatch[jj].iTerm = -1;
91683 }
91684 ii = -1;
91685 iDir = 1;
91686 }
91687 }
91688 }
91689 iDir -= 2;
91690 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
91691 }
91692
91693 /*
91694 ** Compute all offsets for the current row of the query.
91695 ** If the offsets have already been computed, this routine is a no-op.
@@ -91696,38 +93001,44 @@
91696 */
91697 static void snippetAllOffsets(fulltext_cursor *p){
91698 int nColumn;
91699 int iColumn, i;
91700 int iFirst, iLast;
91701 fulltext_vtab *pFts;
 
91702
91703 if( p->snippet.nMatch ) return;
91704 if( p->q.nTerms==0 ) return;
91705 pFts = p->q.pFts;
91706 nColumn = pFts->nColumn;
91707 iColumn = (p->iCursorType - QUERY_FULLTEXT);
91708 if( iColumn<0 || iColumn>=nColumn ){
 
91709 iFirst = 0;
91710 iLast = nColumn-1;
91711 }else{
 
91712 iFirst = iColumn;
91713 iLast = iColumn;
91714 }
91715 for(i=iFirst; i<=iLast; i++){
91716 const char *zDoc;
91717 int nDoc;
91718 zDoc = (const char*)sqlite3_column_text(p->pStmt, i+1);
91719 nDoc = sqlite3_column_bytes(p->pStmt, i+1);
91720 snippetOffsetsOfColumn(&p->q, &p->snippet, i, zDoc, nDoc);
91721 }
91722
91723 trimSnippetOffsetsForNear(&p->q, &p->snippet);
 
 
91724 }
91725
91726 /*
91727 ** Convert the information in the aMatch[] array of the snippet
91728 ** into the string zOffset[0..nOffset-1].
 
91729 */
91730 static void snippetOffsetText(Snippet *p){
91731 int i;
91732 int cnt = 0;
91733 StringBuffer sb;
@@ -91838,11 +93149,11 @@
91838
91839 for(i=0; i<nMatch; i++){
91840 aMatch[i].snStatus = SNIPPET_IGNORE;
91841 }
91842 nDesired = 0;
91843 for(i=0; i<pCursor->q.nTerms; i++){
91844 for(j=0; j<nMatch; j++){
91845 if( aMatch[j].iTerm==i ){
91846 aMatch[j].snStatus = SNIPPET_DESIRED;
91847 nDesired++;
91848 break;
@@ -91926,13 +93237,15 @@
91926 */
91927 static int fulltextClose(sqlite3_vtab_cursor *pCursor){
91928 fulltext_cursor *c = (fulltext_cursor *) pCursor;
91929 FTSTRACE(("FTS3 Close %p\n", c));
91930 sqlite3_finalize(c->pStmt);
91931 queryClear(&c->q);
91932 snippetClear(&c->snippet);
91933 if( c->result.nData!=0 ) dlrDestroy(&c->reader);
 
 
91934 dataBufferDestroy(&c->result);
91935 sqlite3_free(c);
91936 return SQLITE_OK;
91937 }
91938
@@ -91985,259 +93298,131 @@
91985 */
91986 static int termSelect(fulltext_vtab *v, int iColumn,
91987 const char *pTerm, int nTerm, int isPrefix,
91988 DocListType iType, DataBuffer *out);
91989
91990 /* Return a DocList corresponding to the query term *pTerm. If *pTerm
91991 ** is the first term of a phrase query, go ahead and evaluate the phrase
91992 ** query and return the doclist for the entire phrase query.
91993 **
91994 ** The resulting DL_DOCIDS doclist is stored in pResult, which is
91995 ** overwritten.
91996 */
91997 static int docListOfTerm(
91998 fulltext_vtab *v, /* The full text index */
91999 int iColumn, /* column to restrict to. No restriction if >=nColumn */
92000 QueryTerm *pQTerm, /* Term we are looking for, or 1st term of a phrase */
92001 DataBuffer *pResult /* Write the result here */
92002 ){
92003 DataBuffer left, right, new;
92004 int i, rc;
92005
92006 /* No phrase search if no position info. */
92007 assert( pQTerm->nPhrase==0 || DL_DEFAULT!=DL_DOCIDS );
 
 
 
92008
92009 /* This code should never be called with buffered updates. */
92010 assert( v->nPendingData<0 );
92011
92012 dataBufferInit(&left, 0);
92013 rc = termSelect(v, iColumn, pQTerm->pTerm, pQTerm->nTerm, pQTerm->isPrefix,
92014 (0<pQTerm->nPhrase ? DL_POSITIONS : DL_DOCIDS), &left);
92015 if( rc ) return rc;
92016 for(i=1; i<=pQTerm->nPhrase && left.nData>0; i++){
92017 /* If this token is connected to the next by a NEAR operator, and
92018 ** the next token is the start of a phrase, then set nPhraseRight
92019 ** to the number of tokens in the phrase. Otherwise leave it at 1.
92020 */
92021 int nPhraseRight = 1;
92022 while( (i+nPhraseRight)<=pQTerm->nPhrase
92023 && pQTerm[i+nPhraseRight].nNear==0
92024 ){
92025 nPhraseRight++;
92026 }
92027
92028 dataBufferInit(&right, 0);
92029 rc = termSelect(v, iColumn, pQTerm[i].pTerm, pQTerm[i].nTerm,
92030 pQTerm[i].isPrefix, DL_POSITIONS, &right);
92031 if( rc ){
92032 dataBufferDestroy(&left);
92033 return rc;
92034 }
92035 dataBufferInit(&new, 0);
92036 docListPhraseMerge(left.pData, left.nData, right.pData, right.nData,
92037 pQTerm[i-1].nNear, pQTerm[i-1].iPhrase + nPhraseRight,
92038 ((i<pQTerm->nPhrase) ? DL_POSITIONS : DL_DOCIDS),
92039 &new);
92040 dataBufferDestroy(&left);
92041 dataBufferDestroy(&right);
92042 left = new;
92043 }
92044 *pResult = left;
92045 return SQLITE_OK;
92046 }
92047
92048 /* Add a new term pTerm[0..nTerm-1] to the query *q.
92049 */
92050 static void queryAdd(Query *q, const char *pTerm, int nTerm){
92051 QueryTerm *t;
92052 ++q->nTerms;
92053 q->pTerms = sqlite3_realloc(q->pTerms, q->nTerms * sizeof(q->pTerms[0]));
92054 if( q->pTerms==0 ){
92055 q->nTerms = 0;
92056 return;
92057 }
92058 t = &q->pTerms[q->nTerms - 1];
92059 CLEAR(t);
92060 t->pTerm = sqlite3_malloc(nTerm+1);
92061 memcpy(t->pTerm, pTerm, nTerm);
92062 t->pTerm[nTerm] = 0;
92063 t->nTerm = nTerm;
92064 t->isOr = q->nextIsOr;
92065 t->isPrefix = 0;
92066 q->nextIsOr = 0;
92067 t->iColumn = q->nextColumn;
92068 q->nextColumn = q->dfltColumn;
92069 }
92070
92071 /*
92072 ** Check to see if the string zToken[0...nToken-1] matches any
92073 ** column name in the virtual table. If it does,
92074 ** return the zero-indexed column number. If not, return -1.
92075 */
92076 static int checkColumnSpecifier(
92077 fulltext_vtab *pVtab, /* The virtual table */
92078 const char *zToken, /* Text of the token */
92079 int nToken /* Number of characters in the token */
92080 ){
92081 int i;
92082 for(i=0; i<pVtab->nColumn; i++){
92083 if( memcmp(pVtab->azColumn[i], zToken, nToken)==0
92084 && pVtab->azColumn[i][nToken]==0 ){
92085 return i;
92086 }
92087 }
92088 return -1;
92089 }
92090
92091 /*
92092 ** Parse the text at zSegment[0..nSegment-1]. Add additional terms
92093 ** to the query being assemblied in pQuery.
92094 **
92095 ** inPhrase is true if zSegment[0..nSegement-1] is contained within
92096 ** double-quotes. If inPhrase is true, then the first term
92097 ** is marked with the number of terms in the phrase less one and
92098 ** OR and "-" syntax is ignored. If inPhrase is false, then every
92099 ** term found is marked with nPhrase=0 and OR and "-" syntax is significant.
92100 */
92101 static int tokenizeSegment(
92102 sqlite3_tokenizer *pTokenizer, /* The tokenizer to use */
92103 const char *zSegment, int nSegment, /* Query expression being parsed */
92104 int inPhrase, /* True if within "..." */
92105 Query *pQuery /* Append results here */
92106 ){
92107 const sqlite3_tokenizer_module *pModule = pTokenizer->pModule;
92108 sqlite3_tokenizer_cursor *pCursor;
92109 int firstIndex = pQuery->nTerms;
92110 int iCol;
92111 int nTerm = 1;
92112
92113 int rc = pModule->xOpen(pTokenizer, zSegment, nSegment, &pCursor);
92114 if( rc!=SQLITE_OK ) return rc;
92115 pCursor->pTokenizer = pTokenizer;
92116
92117 while( 1 ){
92118 const char *zToken;
92119 int nToken, iBegin, iEnd, iPos;
92120
92121 rc = pModule->xNext(pCursor,
92122 &zToken, &nToken,
92123 &iBegin, &iEnd, &iPos);
92124 if( rc!=SQLITE_OK ) break;
92125 if( !inPhrase &&
92126 zSegment[iEnd]==':' &&
92127 (iCol = checkColumnSpecifier(pQuery->pFts, zToken, nToken))>=0 ){
92128 pQuery->nextColumn = iCol;
92129 continue;
92130 }
92131 if( !inPhrase && pQuery->nTerms>0 && nToken==2
92132 && zSegment[iBegin+0]=='O'
92133 && zSegment[iBegin+1]=='R'
92134 ){
92135 pQuery->nextIsOr = 1;
92136 continue;
92137 }
92138 if( !inPhrase && pQuery->nTerms>0 && !pQuery->nextIsOr && nToken==4
92139 && memcmp(&zSegment[iBegin], "NEAR", 4)==0
92140 ){
92141 QueryTerm *pTerm = &pQuery->pTerms[pQuery->nTerms-1];
92142 if( (iBegin+6)<nSegment
92143 && zSegment[iBegin+4] == '/'
92144 && isdigit(zSegment[iBegin+5])
92145 ){
92146 int k;
92147 pTerm->nNear = 0;
92148 for(k=5; (iBegin+k)<=nSegment && isdigit(zSegment[iBegin+k]); k++){
92149 pTerm->nNear = pTerm->nNear*10 + (zSegment[iBegin+k] - '0');
92150 }
92151 pModule->xNext(pCursor, &zToken, &nToken, &iBegin, &iEnd, &iPos);
92152 } else {
92153 pTerm->nNear = SQLITE_FTS3_DEFAULT_NEAR_PARAM;
92154 }
92155 pTerm->nNear++;
92156 continue;
92157 }
92158
92159 queryAdd(pQuery, zToken, nToken);
92160 if( !inPhrase && iBegin>0 && zSegment[iBegin-1]=='-' ){
92161 pQuery->pTerms[pQuery->nTerms-1].isNot = 1;
92162 }
92163 if( iEnd<nSegment && zSegment[iEnd]=='*' ){
92164 pQuery->pTerms[pQuery->nTerms-1].isPrefix = 1;
92165 }
92166 pQuery->pTerms[pQuery->nTerms-1].iPhrase = nTerm;
92167 if( inPhrase ){
92168 nTerm++;
92169 }
92170 }
92171
92172 if( inPhrase && pQuery->nTerms>firstIndex ){
92173 pQuery->pTerms[firstIndex].nPhrase = pQuery->nTerms - firstIndex - 1;
92174 }
92175
92176 return pModule->xClose(pCursor);
92177 }
92178
92179 /* Parse a query string, yielding a Query object pQuery.
92180 **
92181 ** The calling function will need to queryClear() to clean up
92182 ** the dynamically allocated memory held by pQuery.
92183 */
92184 static int parseQuery(
92185 fulltext_vtab *v, /* The fulltext index */
92186 const char *zInput, /* Input text of the query string */
92187 int nInput, /* Size of the input text */
92188 int dfltColumn, /* Default column of the index to match against */
92189 Query *pQuery /* Write the parse results here. */
92190 ){
92191 int iInput, inPhrase = 0;
92192 int ii;
92193 QueryTerm *aTerm;
92194
92195 if( zInput==0 ) nInput = 0;
92196 if( nInput<0 ) nInput = strlen(zInput);
92197 pQuery->nTerms = 0;
92198 pQuery->pTerms = NULL;
92199 pQuery->nextIsOr = 0;
92200 pQuery->nextColumn = dfltColumn;
92201 pQuery->dfltColumn = dfltColumn;
92202 pQuery->pFts = v;
92203
92204 for(iInput=0; iInput<nInput; ++iInput){
92205 int i;
92206 for(i=iInput; i<nInput && zInput[i]!='"'; ++i){}
92207 if( i>iInput ){
92208 tokenizeSegment(v->pTokenizer, zInput+iInput, i-iInput, inPhrase,
92209 pQuery);
92210 }
92211 iInput = i;
92212 if( i<nInput ){
92213 assert( zInput[i]=='"' );
92214 inPhrase = !inPhrase;
92215 }
92216 }
92217
92218 if( inPhrase ){
92219 /* unmatched quote */
92220 queryClear(pQuery);
92221 return SQLITE_ERROR;
92222 }
92223
92224 /* Modify the values of the QueryTerm.nPhrase variables to account for
92225 ** the NEAR operator. For the purposes of QueryTerm.nPhrase, phrases
92226 ** and tokens connected by the NEAR operator are handled as a single
92227 ** phrase. See comments above the QueryTerm structure for details.
92228 */
92229 aTerm = pQuery->pTerms;
92230 for(ii=0; ii<pQuery->nTerms; ii++){
92231 if( aTerm[ii].nNear || aTerm[ii].nPhrase ){
92232 while (aTerm[ii+aTerm[ii].nPhrase].nNear) {
92233 aTerm[ii].nPhrase += (1 + aTerm[ii+aTerm[ii].nPhrase+1].nPhrase);
92234 }
92235 }
92236 }
92237
92238 return SQLITE_OK;
92239 }
92240
92241 /* TODO(shess) Refactor the code to remove this forward decl. */
92242 static int flushPendingTerms(fulltext_vtab *v);
92243
@@ -92252,16 +93437,13 @@
92252 fulltext_vtab *v, /* The full text index */
92253 int iColumn, /* Match against this column by default */
92254 const char *zInput, /* The query string */
92255 int nInput, /* Number of bytes in zInput[] */
92256 DataBuffer *pResult, /* Write the result doclist here */
92257 Query *pQuery /* Put parsed query string here */
92258 ){
92259 int i, iNext, rc;
92260 DataBuffer left, right, or, new;
92261 int nNot = 0;
92262 QueryTerm *aTerm;
92263
92264 /* TODO(shess) Instead of flushing pendingTerms, we could query for
92265 ** the relevant term and merge the doclist into what we receive from
92266 ** the database. Wait and see if this is a common issue, first.
92267 **
@@ -92269,90 +93451,24 @@
92269 ** error codes from here.
92270 */
92271
92272 /* Flush any buffered updates before executing the query. */
92273 rc = flushPendingTerms(v);
92274 if( rc!=SQLITE_OK ) return rc;
92275
92276 /* TODO(shess) I think that the queryClear() calls below are not
92277 ** necessary, because fulltextClose() already clears the query.
92278 */
92279 rc = parseQuery(v, zInput, nInput, iColumn, pQuery);
92280 if( rc!=SQLITE_OK ) return rc;
92281
92282 /* Empty or NULL queries return no results. */
92283 if( pQuery->nTerms==0 ){
92284 dataBufferInit(pResult, 0);
92285 return SQLITE_OK;
92286 }
92287
92288 /* Merge AND terms. */
92289 /* TODO(shess) I think we can early-exit if( i>nNot && left.nData==0 ). */
92290 aTerm = pQuery->pTerms;
92291 for(i = 0; i<pQuery->nTerms; i=iNext){
92292 if( aTerm[i].isNot ){
92293 /* Handle all NOT terms in a separate pass */
92294 nNot++;
92295 iNext = i + aTerm[i].nPhrase+1;
92296 continue;
92297 }
92298 iNext = i + aTerm[i].nPhrase + 1;
92299 rc = docListOfTerm(v, aTerm[i].iColumn, &aTerm[i], &right);
92300 if( rc ){
92301 if( i!=nNot ) dataBufferDestroy(&left);
92302 queryClear(pQuery);
92303 return rc;
92304 }
92305 while( iNext<pQuery->nTerms && aTerm[iNext].isOr ){
92306 rc = docListOfTerm(v, aTerm[iNext].iColumn, &aTerm[iNext], &or);
92307 iNext += aTerm[iNext].nPhrase + 1;
92308 if( rc ){
92309 if( i!=nNot ) dataBufferDestroy(&left);
92310 dataBufferDestroy(&right);
92311 queryClear(pQuery);
92312 return rc;
92313 }
92314 dataBufferInit(&new, 0);
92315 docListOrMerge(right.pData, right.nData, or.pData, or.nData, &new);
92316 dataBufferDestroy(&right);
92317 dataBufferDestroy(&or);
92318 right = new;
92319 }
92320 if( i==nNot ){ /* first term processed. */
92321 left = right;
92322 }else{
92323 dataBufferInit(&new, 0);
92324 docListAndMerge(left.pData, left.nData, right.pData, right.nData, &new);
92325 dataBufferDestroy(&right);
92326 dataBufferDestroy(&left);
92327 left = new;
92328 }
92329 }
92330
92331 if( nNot==pQuery->nTerms ){
92332 /* We do not yet know how to handle a query of only NOT terms */
92333 return SQLITE_ERROR;
92334 }
92335
92336 /* Do the EXCEPT terms */
92337 for(i=0; i<pQuery->nTerms; i += aTerm[i].nPhrase + 1){
92338 if( !aTerm[i].isNot ) continue;
92339 rc = docListOfTerm(v, aTerm[i].iColumn, &aTerm[i], &right);
92340 if( rc ){
92341 queryClear(pQuery);
92342 dataBufferDestroy(&left);
92343 return rc;
92344 }
92345 dataBufferInit(&new, 0);
92346 docListExceptMerge(left.pData, left.nData, right.pData, right.nData, &new);
92347 dataBufferDestroy(&right);
92348 dataBufferDestroy(&left);
92349 left = new;
92350 }
92351
92352 *pResult = left;
92353 return rc;
92354 }
92355
92356 /*
92357 ** This is the xFilter interface for the virtual table. See
92358 ** the virtual table xFilter method documentation for additional
@@ -92428,22 +93544,22 @@
92428 if( rc!=SQLITE_OK ) return rc;
92429 break;
92430
92431 default: /* full-text search */
92432 {
 
92433 const char *zQuery = (const char *)sqlite3_value_text(argv[0]);
92434 assert( idxNum<=QUERY_FULLTEXT+v->nColumn);
92435 assert( argc==1 );
92436 queryClear(&c->q);
92437 if( c->result.nData!=0 ){
92438 /* This case happens if the same cursor is used repeatedly. */
92439 dlrDestroy(&c->reader);
92440 dataBufferReset(&c->result);
92441 }else{
92442 dataBufferInit(&c->result, 0);
92443 }
92444 rc = fulltextQuery(v, idxNum-QUERY_FULLTEXT, zQuery, -1, &c->result, &c->q);
92445 if( rc!=SQLITE_OK ) return rc;
92446 if( c->result.nData!=0 ){
92447 dlrInit(&c->reader, DL_DOCIDS, c->result.pData, c->result.nData);
92448 }
92449 break;
@@ -94323,22 +95439,28 @@
94323 }
94324
94325 /* Scan the database and merge together the posting lists for the term
94326 ** into *out.
94327 */
94328 static int termSelect(fulltext_vtab *v, int iColumn,
94329 const char *pTerm, int nTerm, int isPrefix,
94330 DocListType iType, DataBuffer *out){
 
 
 
 
 
94331 DataBuffer doclist;
94332 sqlite3_stmt *s;
94333 int rc = sql_get_statement(v, SEGDIR_SELECT_ALL_STMT, &s);
94334 if( rc!=SQLITE_OK ) return rc;
94335
94336 /* This code should never be called with buffered updates. */
94337 assert( v->nPendingData<0 );
94338
94339 dataBufferInit(&doclist, 0);
 
94340
94341 /* Traverse the segments from oldest to newest so that newer doclist
94342 ** elements for given docids overwrite older elements.
94343 */
94344 while( (rc = sqlite3_step(s))==SQLITE_ROW ){
@@ -95451,10 +96573,14 @@
95451 || (pIcu && sqlite3Fts3HashInsert(pHash, "icu", 4, (void *)pIcu))
95452 ){
95453 rc = SQLITE_NOMEM;
95454 }
95455 }
 
 
 
 
95456
95457 /* Create the virtual table wrapper around the hash-table and overload
95458 ** the two scalar functions. If this is successful, register the
95459 ** module with sqlite.
95460 */
@@ -95494,10 +96620,897 @@
95494 #endif
95495
95496 #endif /* !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_FTS3) */
95497
95498 /************** End of fts3.c ************************************************/
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
95499 /************** Begin file fts3_hash.c ***************************************/
95500 /*
95501 ** 2001 September 22
95502 **
95503 ** The author disclaims copyright to this source code. In place of
@@ -97114,11 +99127,11 @@
97114 **
97115 *************************************************************************
97116 ** This file contains code for implementations of the r-tree and r*-tree
97117 ** algorithms packaged as an SQLite virtual table module.
97118 **
97119 ** $Id: rtree.c,v 1.11 2008/11/12 15:24:27 drh Exp $
97120 */
97121
97122 #if !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_RTREE)
97123
97124 /*
@@ -97498,11 +99511,12 @@
97498 /* Check if the requested node is already in the hash table. If so,
97499 ** increase its reference count and return it.
97500 */
97501 if( (pNode = nodeHashLookup(pRtree, iNode)) ){
97502 assert( !pParent || !pNode->pParent || pNode->pParent==pParent );
97503 if( pParent ){
 
97504 pNode->pParent = pParent;
97505 }
97506 pNode->nRef++;
97507 *ppNode = pNode;
97508 return SQLITE_OK;
97509
--- src/sqlite3.c
+++ src/sqlite3.c
@@ -1,8 +1,8 @@
1 /******************************************************************************
2 ** This file is an amalgamation of many separate C source files from SQLite
3 ** version 3.6.8. By combining all the individual C code files into this
4 ** single large file, the entire code can be compiled as a one translation
5 ** unit. This allows many compilers to do optimizations that would not be
6 ** possible if the files were compiled separately. Performance improvements
7 ** of 5% are more are commonly seen when SQLite is compiled as a single
8 ** translation unit.
@@ -9,17 +9,17 @@
9 **
10 ** This file is all you need to compile SQLite. To use SQLite in other
11 ** programs, you need this file and the "sqlite3.h" header file that defines
12 ** the programming interface to the SQLite library. (If you do not have
13 ** the "sqlite3.h" header file at hand, you will find a copy in the first
14 ** 6736 lines past this header comment.) Additional code files may be
15 ** needed if you want a wrapper to interface SQLite with your choice of
16 ** programming language. The code for the "sqlite3" command-line shell
17 ** is also in a separate file. This file contains only code for the core
18 ** SQLite library.
19 **
20 ** This amalgamation was generated on 2009-01-10 13:14:08 UTC.
21 */
22 #define SQLITE_CORE 1
23 #define SQLITE_AMALGAMATION 1
24 #ifndef SQLITE_PRIVATE
25 # define SQLITE_PRIVATE static
@@ -39,11 +39,11 @@
39 ** May you share freely, never taking more than you give.
40 **
41 *************************************************************************
42 ** Internal interface definitions for SQLite.
43 **
44 ** @(#) $Id: sqliteInt.h,v 1.821 2009/01/09 14:11:05 drh Exp $
45 */
46 #ifndef _SQLITEINT_H_
47 #define _SQLITEINT_H_
48
49 /*
@@ -68,11 +68,11 @@
68 **
69 *************************************************************************
70 **
71 ** This file defines various limits of what SQLite can process.
72 **
73 ** @(#) $Id: sqliteLimit.h,v 1.9 2009/01/07 16:15:43 danielk1977 Exp $
74 */
75
76 /*
77 ** The maximum length of a TEXT or BLOB in bytes. This also
78 ** limits the size of a row in a table or index.
@@ -152,11 +152,11 @@
152
153 /*
154 ** The maximum number of arguments to an SQL function.
155 */
156 #ifndef SQLITE_MAX_FUNCTION_ARG
157 # define SQLITE_MAX_FUNCTION_ARG 127
158 #endif
159
160 /*
161 ** The maximum number of in-memory pages to use for the main database
162 ** table and for temporary tables. The SQLITE_DEFAULT_CACHE_SIZE
@@ -275,12 +275,14 @@
275 ** in places where simple condition/decision coverage is inadequate.
276 */
277 #ifdef SQLITE_COVERAGE_TEST
278 SQLITE_PRIVATE void sqlite3Coverage(int);
279 # define testcase(X) if( X ){ sqlite3Coverage(__LINE__); }
280 # define TESTONLY(X) X
281 #else
282 # define testcase(X)
283 # define TESTONLY(X)
284 #endif
285
286 /*
287 ** The ALWAYS and NEVER macros surround boolean expressions which
288 ** are intended to always be true or false, respectively. Such
@@ -451,10 +453,24 @@
453 */
454 #if !defined(NDEBUG) && !defined(SQLITE_DEBUG)
455 # define NDEBUG 1
456 #endif
457
458 /*
459 ** Sometimes we need a small amount of code such as a variable initialization
460 ** to setup for a later assert() statement. We do not want this code to
461 ** appear when assert() is disabled. The following macro is therefore
462 ** used to contain that setup code. The "VVA" acronym stands for
463 ** "Verification, Validation, and Accreditation". In other words, the
464 ** code within VVA_ONLY() will only run during verification processes.
465 */
466 #ifndef NDEBUG
467 # define VVA_ONLY(X) X
468 #else
469 # define VVA_ONLY(X)
470 #endif
471
472 /************** Include sqlite3.h in the middle of sqliteInt.h ***************/
473 /************** Begin file sqlite3.h *****************************************/
474 /*
475 ** 2001 September 15
476 **
@@ -485,11 +501,11 @@
501 ** The name of this file under configuration management is "sqlite.h.in".
502 ** The makefile makes some minor changes to this file (such as inserting
503 ** the version number) and changes its name to "sqlite3.h" as
504 ** part of the build process.
505 **
506 ** @(#) $Id: sqlite.h.in,v 1.421 2008/12/30 06:24:58 danielk1977 Exp $
507 */
508 #ifndef _SQLITE3_H_
509 #define _SQLITE3_H_
510 #include <stdarg.h> /* Needed for the definition of va_list */
511
@@ -562,12 +578,12 @@
578 **
579 ** {H10014} The SQLITE_VERSION_NUMBER #define shall resolve to an integer
580 ** with the value (X*1000000 + Y*1000 + Z) where X, Y, and Z
581 ** are the major version, minor version, and release number.
582 */
583 #define SQLITE_VERSION "3.6.8"
584 #define SQLITE_VERSION_NUMBER 3006008
585
586 /*
587 ** CAPI3REF: Run-Time Library Version Numbers {H10020} <S60100>
588 ** KEYWORDS: sqlite3_version
589 **
@@ -2852,20 +2868,21 @@
2868 #define SQLITE_DROP_VIEW 17 /* View Name NULL */
2869 #define SQLITE_INSERT 18 /* Table Name NULL */
2870 #define SQLITE_PRAGMA 19 /* Pragma Name 1st arg or NULL */
2871 #define SQLITE_READ 20 /* Table Name Column Name */
2872 #define SQLITE_SELECT 21 /* NULL NULL */
2873 #define SQLITE_TRANSACTION 22 /* Operation NULL */
2874 #define SQLITE_UPDATE 23 /* Table Name Column Name */
2875 #define SQLITE_ATTACH 24 /* Filename NULL */
2876 #define SQLITE_DETACH 25 /* Database Name NULL */
2877 #define SQLITE_ALTER_TABLE 26 /* Database Name Table Name */
2878 #define SQLITE_REINDEX 27 /* Index Name NULL */
2879 #define SQLITE_ANALYZE 28 /* Table Name NULL */
2880 #define SQLITE_CREATE_VTABLE 29 /* Table Name Module Name */
2881 #define SQLITE_DROP_VTABLE 30 /* Table Name Module Name */
2882 #define SQLITE_FUNCTION 31 /* NULL Function Name */
2883 #define SQLITE_SAVEPOINT 32 /* Operation Savepoint Name */
2884 #define SQLITE_COPY 0 /* No longer used */
2885
2886 /*
2887 ** CAPI3REF: Tracing And Profiling Functions {H12280} <S60400>
2888 ** EXPERIMENTAL
@@ -7297,150 +7314,152 @@
7314 #define TK_IMMEDIATE 8
7315 #define TK_EXCLUSIVE 9
7316 #define TK_COMMIT 10
7317 #define TK_END 11
7318 #define TK_ROLLBACK 12
7319 #define TK_SAVEPOINT 13
7320 #define TK_RELEASE 14
7321 #define TK_TO 15
7322 #define TK_CREATE 16
7323 #define TK_TABLE 17
7324 #define TK_IF 18
7325 #define TK_NOT 19
7326 #define TK_EXISTS 20
7327 #define TK_TEMP 21
7328 #define TK_LP 22
7329 #define TK_RP 23
7330 #define TK_AS 24
7331 #define TK_COMMA 25
7332 #define TK_ID 26
7333 #define TK_ABORT 27
7334 #define TK_AFTER 28
7335 #define TK_ANALYZE 29
7336 #define TK_ASC 30
7337 #define TK_ATTACH 31
7338 #define TK_BEFORE 32
7339 #define TK_CASCADE 33
7340 #define TK_CAST 34
7341 #define TK_CONFLICT 35
7342 #define TK_DATABASE 36
7343 #define TK_DESC 37
7344 #define TK_DETACH 38
7345 #define TK_EACH 39
7346 #define TK_FAIL 40
7347 #define TK_FOR 41
7348 #define TK_IGNORE 42
7349 #define TK_INITIALLY 43
7350 #define TK_INSTEAD 44
7351 #define TK_LIKE_KW 45
7352 #define TK_MATCH 46
7353 #define TK_KEY 47
7354 #define TK_OF 48
7355 #define TK_OFFSET 49
7356 #define TK_PRAGMA 50
7357 #define TK_RAISE 51
7358 #define TK_REPLACE 52
7359 #define TK_RESTRICT 53
7360 #define TK_ROW 54
7361 #define TK_TRIGGER 55
7362 #define TK_VACUUM 56
7363 #define TK_VIEW 57
7364 #define TK_VIRTUAL 58
7365 #define TK_REINDEX 59
7366 #define TK_RENAME 60
7367 #define TK_CTIME_KW 61
7368 #define TK_ANY 62
7369 #define TK_OR 63
7370 #define TK_AND 64
7371 #define TK_IS 65
7372 #define TK_BETWEEN 66
7373 #define TK_IN 67
7374 #define TK_ISNULL 68
7375 #define TK_NOTNULL 69
7376 #define TK_NE 70
7377 #define TK_EQ 71
7378 #define TK_GT 72
7379 #define TK_LE 73
7380 #define TK_LT 74
7381 #define TK_GE 75
7382 #define TK_ESCAPE 76
7383 #define TK_BITAND 77
7384 #define TK_BITOR 78
7385 #define TK_LSHIFT 79
7386 #define TK_RSHIFT 80
7387 #define TK_PLUS 81
7388 #define TK_MINUS 82
7389 #define TK_STAR 83
7390 #define TK_SLASH 84
7391 #define TK_REM 85
7392 #define TK_CONCAT 86
7393 #define TK_COLLATE 87
7394 #define TK_UMINUS 88
7395 #define TK_UPLUS 89
7396 #define TK_BITNOT 90
7397 #define TK_STRING 91
7398 #define TK_JOIN_KW 92
7399 #define TK_CONSTRAINT 93
7400 #define TK_DEFAULT 94
7401 #define TK_NULL 95
7402 #define TK_PRIMARY 96
7403 #define TK_UNIQUE 97
7404 #define TK_CHECK 98
7405 #define TK_REFERENCES 99
7406 #define TK_AUTOINCR 100
7407 #define TK_ON 101
7408 #define TK_DELETE 102
7409 #define TK_UPDATE 103
7410 #define TK_INSERT 104
7411 #define TK_SET 105
7412 #define TK_DEFERRABLE 106
7413 #define TK_FOREIGN 107
7414 #define TK_DROP 108
7415 #define TK_UNION 109
7416 #define TK_ALL 110
7417 #define TK_EXCEPT 111
7418 #define TK_INTERSECT 112
7419 #define TK_SELECT 113
7420 #define TK_DISTINCT 114
7421 #define TK_DOT 115
7422 #define TK_FROM 116
7423 #define TK_JOIN 117
7424 #define TK_INDEXED 118
7425 #define TK_BY 119
7426 #define TK_USING 120
7427 #define TK_ORDER 121
7428 #define TK_GROUP 122
7429 #define TK_HAVING 123
7430 #define TK_LIMIT 124
7431 #define TK_WHERE 125
7432 #define TK_INTO 126
7433 #define TK_VALUES 127
7434 #define TK_INTEGER 128
7435 #define TK_FLOAT 129
7436 #define TK_BLOB 130
7437 #define TK_REGISTER 131
7438 #define TK_VARIABLE 132
7439 #define TK_CASE 133
7440 #define TK_WHEN 134
7441 #define TK_THEN 135
7442 #define TK_ELSE 136
7443 #define TK_INDEX 137
7444 #define TK_ALTER 138
7445 #define TK_ADD 139
7446 #define TK_COLUMNKW 140
7447 #define TK_TO_TEXT 141
7448 #define TK_TO_BLOB 142
7449 #define TK_TO_NUMERIC 143
7450 #define TK_TO_INT 144
7451 #define TK_TO_REAL 145
7452 #define TK_END_OF_FILE 146
7453 #define TK_ILLEGAL 147
7454 #define TK_SPACE 148
7455 #define TK_UNCLOSED_STRING 149
7456 #define TK_FUNCTION 150
7457 #define TK_COLUMN 151
7458 #define TK_AGG_FUNCTION 152
7459 #define TK_AGG_COLUMN 153
7460 #define TK_CONST_FUNC 154
7461
7462 /************** End of parse.h ***********************************************/
7463 /************** Continuing where we left off in sqliteInt.h ******************/
7464 #include <stdio.h>
7465 #include <stdlib.h>
@@ -7723,10 +7742,11 @@
7742 typedef struct Lookaside Lookaside;
7743 typedef struct LookasideSlot LookasideSlot;
7744 typedef struct Module Module;
7745 typedef struct NameContext NameContext;
7746 typedef struct Parse Parse;
7747 typedef struct Savepoint Savepoint;
7748 typedef struct Select Select;
7749 typedef struct SrcList SrcList;
7750 typedef struct StrAccum StrAccum;
7751 typedef struct Table Table;
7752 typedef struct TableLock TableLock;
@@ -7734,10 +7754,11 @@
7754 typedef struct TriggerStack TriggerStack;
7755 typedef struct TriggerStep TriggerStep;
7756 typedef struct Trigger Trigger;
7757 typedef struct UnpackedRecord UnpackedRecord;
7758 typedef struct Walker Walker;
7759 typedef struct WherePlan WherePlan;
7760 typedef struct WhereInfo WhereInfo;
7761 typedef struct WhereLevel WhereLevel;
7762
7763 /*
7764 ** Defer sourcing vdbe.h and btree.h until after the "u8" and
@@ -7759,11 +7780,11 @@
7780 *************************************************************************
7781 ** This header file defines the interface that the sqlite B-Tree file
7782 ** subsystem. See comments in the source code for a detailed description
7783 ** of what each interface routine does.
7784 **
7785 ** @(#) $Id: btree.h,v 1.106 2008/12/17 17:30:26 danielk1977 Exp $
7786 */
7787 #ifndef _BTREE_H_
7788 #define _BTREE_H_
7789
7790 /* TODO: This definition is just included so other modules compile. It
@@ -7847,10 +7868,11 @@
7868 SQLITE_PRIVATE int sqlite3BtreeIsInStmt(Btree*);
7869 SQLITE_PRIVATE int sqlite3BtreeIsInReadTrans(Btree*);
7870 SQLITE_PRIVATE void *sqlite3BtreeSchema(Btree *, int, void(*)(void *));
7871 SQLITE_PRIVATE int sqlite3BtreeSchemaLocked(Btree *);
7872 SQLITE_PRIVATE int sqlite3BtreeLockTable(Btree *, int, u8);
7873 SQLITE_PRIVATE int sqlite3BtreeSavepoint(Btree *, int, int);
7874
7875 SQLITE_PRIVATE const char *sqlite3BtreeGetFilename(Btree *);
7876 SQLITE_PRIVATE const char *sqlite3BtreeGetDirname(Btree *);
7877 SQLITE_PRIVATE const char *sqlite3BtreeGetJournalname(Btree *);
7878 SQLITE_PRIVATE int sqlite3BtreeCopyFile(Btree *, Btree *);
@@ -8122,155 +8144,157 @@
8144 */
8145 /************** Include opcodes.h in the middle of vdbe.h ********************/
8146 /************** Begin file opcodes.h *****************************************/
8147 /* Automatically generated. Do not edit */
8148 /* See the mkopcodeh.awk script for details */
8149 #define OP_VCreate 1
8150 #define OP_MemMax 2
8151 #define OP_LoadAnalysis 3
8152 #define OP_RowData 4
8153 #define OP_CreateIndex 5
8154 #define OP_Variable 6
8155 #define OP_SeekGt 7
8156 #define OP_SeekLe 8
8157 #define OP_IfNeg 9
8158 #define OP_Clear 10
8159 #define OP_Last 11
8160 #define OP_Add 81 /* same as TK_PLUS */
8161 #define OP_Savepoint 12
8162 #define OP_Sequence 13
8163 #define OP_Int64 14
8164 #define OP_VBegin 15
8165 #define OP_RowKey 16
8166 #define OP_Divide 84 /* same as TK_SLASH */
8167 #define OP_SCopy 17
8168 #define OP_ResetCount 18
8169 #define OP_Delete 20
 
 
 
 
 
8170 #define OP_Trace 21
8171 #define OP_Rowid 22
8172 #define OP_OpenRead 23
8173 #define OP_Sort 24
8174 #define OP_VerifyCookie 25
8175 #define OP_VColumn 26
8176 #define OP_Next 27
8177 #define OP_Insert 28
8178 #define OP_Prev 29
8179 #define OP_IdxGE 30
8180 #define OP_Not 19 /* same as TK_NOT */
8181 #define OP_Ge 75 /* same as TK_GE */
8182 #define OP_VRename 31
8183 #define OP_DropTable 32
8184 #define OP_MakeRecord 33
8185 #define OP_Null 34
8186 #define OP_IdxInsert 35
8187 #define OP_SeekLt 36
8188 #define OP_ReadCookie 37
8189 #define OP_VDestroy 38
8190 #define OP_DropIndex 39
8191 #define OP_IsNull 68 /* same as TK_ISNULL */
8192 #define OP_MustBeInt 40
8193 #define OP_IntegrityCk 41
8194 #define OP_CollSeq 42
8195 #define OP_ResultRow 43
8196 #define OP_Yield 44
8197 #define OP_OpenEphemeral 45
8198 #define OP_VNext 46
8199 #define OP_Seek 47
8200 #define OP_Eq 71 /* same as TK_EQ */
8201 #define OP_String8 91 /* same as TK_STRING */
8202 #define OP_Found 48
8203 #define OP_If 49
8204 #define OP_ToBlob 142 /* same as TK_TO_BLOB */
8205 #define OP_Multiply 83 /* same as TK_STAR */
8206 #define OP_IfZero 50
8207 #define OP_ShiftRight 80 /* same as TK_RSHIFT */
8208 #define OP_Goto 51
8209 #define OP_Function 52
8210 #define OP_Copy 53
8211 #define OP_Jump 54
8212 #define OP_Blob 55
8213 #define OP_BitNot 90 /* same as TK_BITNOT */
8214 #define OP_Gt 72 /* same as TK_GT */
8215 #define OP_Le 73 /* same as TK_LE */
8216 #define OP_NullRow 56
8217 #define OP_Transaction 57
8218 #define OP_VUpdate 58
8219 #define OP_TableLock 59
8220 #define OP_IdxRowid 60
8221 #define OP_SetCookie 61
8222 #define OP_And 64 /* same as TK_AND */
8223 #define OP_ToNumeric 143 /* same as TK_TO_NUMERIC*/
8224 #define OP_ToText 141 /* same as TK_TO_TEXT */
8225 #define OP_ContextPush 62
8226 #define OP_DropTrigger 65
8227 #define OP_AutoCommit 66
8228 #define OP_Column 67
8229 #define OP_AddImm 76
8230 #define OP_Remainder 85 /* same as TK_REM */
8231 #define OP_ContextPop 87
8232 #define OP_IdxDelete 88
8233 #define OP_Ne 70 /* same as TK_NE */
8234 #define OP_ToInt 144 /* same as TK_TO_INT */
8235 #define OP_IncrVacuum 89
8236 #define OP_AggFinal 92
8237 #define OP_RealAffinity 93
8238 #define OP_Concat 86 /* same as TK_CONCAT */
8239 #define OP_Return 94
8240 #define OP_Expire 95
8241 #define OP_Rewind 96
8242 #define OP_Statement 97
8243 #define OP_BitOr 78 /* same as TK_BITOR */
8244 #define OP_Integer 98
8245 #define OP_Compare 99
8246 #define OP_Destroy 100
8247 #define OP_IdxLT 101
8248 #define OP_Affinity 102
8249 #define OP_Lt 74 /* same as TK_LT */
8250 #define OP_Subtract 82 /* same as TK_MINUS */
8251 #define OP_Vacuum 103
8252 #define OP_IfNot 104
8253 #define OP_Move 105
8254 #define OP_Explain 106
8255 #define OP_ParseSchema 107
8256 #define OP_NewRowid 108
8257 #define OP_SetNumColumns 109
8258 #define OP_BitAnd 77 /* same as TK_BITAND */
8259 #define OP_String 110
8260 #define OP_AggStep 111
8261 #define OP_VRowid 112
8262 #define OP_VOpen 113
8263 #define OP_NotExists 114
8264 #define OP_Close 115
8265 #define OP_Halt 116
8266 #define OP_Noop 117
8267 #define OP_SeekGe 118
8268 #define OP_VFilter 119
8269 #define OP_OpenPseudo 120
8270 #define OP_Or 63 /* same as TK_OR */
8271 #define OP_ShiftLeft 79 /* same as TK_LSHIFT */
8272 #define OP_ToReal 145 /* same as TK_TO_REAL */
8273 #define OP_RowSetRead 121
8274 #define OP_RowSetAdd 122
8275 #define OP_IsUnique 123
8276 #define OP_OpenWrite 124
8277 #define OP_Permutation 125
8278 #define OP_Gosub 126
8279 #define OP_IfPos 127
8280 #define OP_Real 129 /* same as TK_FLOAT */
8281 #define OP_NotNull 69 /* same as TK_NOTNULL */
8282 #define OP_Pagecount 128
8283 #define OP_NotFound 130
8284 #define OP_CreateTable 131
8285
8286 /* The following opcode values are never used */
 
8287 #define OP_NotUsed_132 132
8288 #define OP_NotUsed_133 133
8289 #define OP_NotUsed_134 134
8290 #define OP_NotUsed_135 135
8291 #define OP_NotUsed_136 136
8292 #define OP_NotUsed_137 137
8293 #define OP_NotUsed_138 138
8294 #define OP_NotUsed_139 139
8295 #define OP_NotUsed_140 140
8296
8297
8298 /* Properties such as "out2" or "jump" that are specified in
8299 ** comments following the "case" for each opcode in the vdbe.c
8300 ** are encoded into bitvectors as follows:
@@ -8280,29 +8304,29 @@
8304 #define OPFLG_IN1 0x0004 /* in1: P1 is an input */
8305 #define OPFLG_IN2 0x0008 /* in2: P2 is an input */
8306 #define OPFLG_IN3 0x0010 /* in3: P3 is an input */
8307 #define OPFLG_OUT3 0x0020 /* out3: P3 is an output */
8308 #define OPFLG_INITIALIZER {\
8309 /* 0 */ 0x00, 0x00, 0x0c, 0x00, 0x00, 0x02, 0x02, 0x11,\
8310 /* 8 */ 0x11, 0x05, 0x00, 0x01, 0x00, 0x02, 0x02, 0x00,\
8311 /* 16 */ 0x00, 0x04, 0x00, 0x04, 0x00, 0x00, 0x02, 0x00,\
8312 /* 24 */ 0x01, 0x00, 0x00, 0x01, 0x00, 0x01, 0x11, 0x00,\
8313 /* 32 */ 0x00, 0x00, 0x02, 0x08, 0x11, 0x02, 0x00, 0x00,\
8314 /* 40 */ 0x05, 0x00, 0x00, 0x00, 0x04, 0x00, 0x01, 0x08,\
8315 /* 48 */ 0x11, 0x05, 0x05, 0x01, 0x00, 0x04, 0x01, 0x02,\
8316 /* 56 */ 0x00, 0x00, 0x00, 0x00, 0x02, 0x10, 0x00, 0x2c,\
8317 /* 64 */ 0x2c, 0x00, 0x00, 0x00, 0x05, 0x05, 0x15, 0x15,\
8318 /* 72 */ 0x15, 0x15, 0x15, 0x15, 0x04, 0x2c, 0x2c, 0x2c,\
8319 /* 80 */ 0x2c, 0x2c, 0x2c, 0x2c, 0x2c, 0x2c, 0x2c, 0x00,\
8320 /* 88 */ 0x00, 0x01, 0x04, 0x02, 0x00, 0x04, 0x04, 0x00,\
8321 /* 96 */ 0x01, 0x00, 0x02, 0x00, 0x02, 0x11, 0x00, 0x00,\
8322 /* 104 */ 0x05, 0x00, 0x00, 0x00, 0x02, 0x00, 0x02, 0x00,\
8323 /* 112 */ 0x02, 0x00, 0x11, 0x00, 0x00, 0x00, 0x11, 0x01,\
8324 /* 120 */ 0x00, 0x21, 0x08, 0x11, 0x00, 0x00, 0x01, 0x05,\
8325 /* 128 */ 0x02, 0x02, 0x11, 0x02, 0x00, 0x00, 0x00, 0x00,\
8326 /* 136 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x04, 0x04,\
8327 /* 144 */ 0x04, 0x04,}
8328
8329 /************** End of opcodes.h *********************************************/
8330 /************** Continuing where we left off in vdbe.h ***********************/
8331
8332 /*
@@ -8381,11 +8405,11 @@
8405 *************************************************************************
8406 ** This header file defines the interface that the sqlite page cache
8407 ** subsystem. The page cache subsystem reads and writes a file a page
8408 ** at a time and provides a journal for rollback.
8409 **
8410 ** @(#) $Id: pager.h,v 1.93 2009/01/07 15:18:21 danielk1977 Exp $
8411 */
8412
8413 #ifndef _PAGER_H_
8414 #define _PAGER_H_
8415
@@ -8456,19 +8480,15 @@
8480 SQLITE_PRIVATE int sqlite3PagerPageRefcount(DbPage*);
8481 SQLITE_PRIVATE int sqlite3PagerRef(DbPage*);
8482 SQLITE_PRIVATE int sqlite3PagerUnref(DbPage*);
8483 SQLITE_PRIVATE int sqlite3PagerWrite(DbPage*);
8484 SQLITE_PRIVATE int sqlite3PagerPagecount(Pager*, int*);
 
8485 SQLITE_PRIVATE int sqlite3PagerBegin(DbPage*, int exFlag);
8486 SQLITE_PRIVATE int sqlite3PagerCommitPhaseOne(Pager*,const char *zMaster, int);
8487 SQLITE_PRIVATE int sqlite3PagerCommitPhaseTwo(Pager*);
8488 SQLITE_PRIVATE int sqlite3PagerRollback(Pager*);
8489 SQLITE_PRIVATE u8 sqlite3PagerIsreadonly(Pager*);
 
 
 
8490 SQLITE_PRIVATE void sqlite3PagerDontRollback(DbPage*);
8491 SQLITE_PRIVATE int sqlite3PagerDontWrite(DbPage*);
8492 SQLITE_PRIVATE int sqlite3PagerRefcount(Pager*);
8493 SQLITE_PRIVATE void sqlite3PagerSetSafetyLevel(Pager*,int,int);
8494 SQLITE_PRIVATE const char *sqlite3PagerFilename(Pager*);
@@ -8483,10 +8503,18 @@
8503 SQLITE_PRIVATE int sqlite3PagerLockingMode(Pager *, int);
8504 SQLITE_PRIVATE int sqlite3PagerJournalMode(Pager *, int);
8505 SQLITE_PRIVATE i64 sqlite3PagerJournalSizeLimit(Pager *, i64);
8506 SQLITE_PRIVATE void *sqlite3PagerTempSpace(Pager*);
8507 SQLITE_PRIVATE int sqlite3PagerSync(Pager *pPager);
8508
8509 SQLITE_PRIVATE int sqlite3PagerOpenSavepoint(Pager *pPager, int n);
8510 SQLITE_PRIVATE int sqlite3PagerSavepoint(Pager *pPager, int op, int iSavepoint);
8511
8512 #ifndef SQLITE_OMIT_AUTOVACUUM
8513 SQLITE_PRIVATE void sqlite3PagerTruncateImage(Pager*,Pgno);
8514 SQLITE_PRIVATE Pgno sqlite3PagerImageSize(Pager *);
8515 #endif
8516
8517 #ifdef SQLITE_HAS_CODEC
8518 SQLITE_PRIVATE void sqlite3PagerSetCodec(Pager*,void*(*)(void*,void*,Pgno,int),void*);
8519 #endif
8520
@@ -9249,10 +9277,13 @@
9277 int busyTimeout; /* Busy handler timeout, in msec */
9278 Db aDbStatic[2]; /* Static space for the 2 default backends */
9279 #ifdef SQLITE_SSE
9280 sqlite3_stmt *pFetch; /* Used by SSE to fetch stored statements */
9281 #endif
9282 Savepoint *pSavepoint; /* List of active savepoints */
9283 int nSavepoint; /* Number of non-transaction savepoints */
9284 u8 isTransactionSavepoint; /* True if the outermost savepoint is a TS */
9285 };
9286
9287 /*
9288 ** A macro to discover the encoding of a database.
9289 */
@@ -9287,10 +9318,11 @@
9318 #define SQLITE_LoadExtension 0x00020000 /* Enable load_extension */
9319
9320 #define SQLITE_RecoveryMode 0x00040000 /* Ignore schema errors */
9321 #define SQLITE_SharedCache 0x00080000 /* Cache sharing is enabled */
9322 #define SQLITE_Vtab 0x00100000 /* There exists a virtual table */
9323 #define SQLITE_CommitBusy 0x00200000 /* In the process of committing */
9324
9325 /*
9326 ** Possible values for the sqlite.magic field.
9327 ** The numbers are obtained at random and have no special meaning, other
9328 ** than being distinct from one another.
@@ -9360,10 +9392,29 @@
9392 #define LIKEFUNC(zName, nArg, arg, flags) \
9393 {nArg, SQLITE_UTF8, flags, (void *)arg, 0, likeFunc, 0, 0, #zName, 0}
9394 #define AGGREGATE(zName, nArg, arg, nc, xStep, xFinal) \
9395 {nArg, SQLITE_UTF8, nc*8, SQLITE_INT_TO_PTR(arg), 0, 0, xStep,xFinal,#zName,0}
9396
9397 /*
9398 ** All current savepoints are stored in a linked list starting at
9399 ** sqlite3.pSavepoint. The first element in the list is the most recently
9400 ** opened savepoint. Savepoints are added to the list by the vdbe
9401 ** OP_Savepoint instruction.
9402 */
9403 struct Savepoint {
9404 char *zName; /* Savepoint name (nul-terminated) */
9405 Savepoint *pNext; /* Parent savepoint (if any) */
9406 };
9407
9408 /*
9409 ** The following are used as the second parameter to sqlite3Savepoint(),
9410 ** and as the P1 argument to the OP_Savepoint instruction.
9411 */
9412 #define SAVEPOINT_BEGIN 0
9413 #define SAVEPOINT_RELEASE 1
9414 #define SAVEPOINT_ROLLBACK 2
9415
9416
9417 /*
9418 ** Each SQLite module (virtual table definition) is defined by an
9419 ** instance of the following structure, stored in the sqlite3.aModule
9420 ** hash table.
@@ -9959,15 +10010,15 @@
10010 char *zAlias; /* The "B" part of a "A AS B" phrase. zName is the "A" */
10011 Table *pTab; /* An SQL table corresponding to zName */
10012 Select *pSelect; /* A SELECT statement used in place of a table name */
10013 u8 isPopulated; /* Temporary table associated with SELECT is populated */
10014 u8 jointype; /* Type of join between this able and the previous */
10015 u8 notIndexed; /* True if there is a NOT INDEXED clause */
10016 int iCursor; /* The VDBE cursor number used to access this table */
10017 Expr *pOn; /* The ON clause of a join */
10018 IdList *pUsing; /* The USING clause of a join */
10019 Bitmask colUsed; /* Bit N (1<<N) set if column N of pTab is used */
 
10020 char *zIndex; /* Identifier from "INDEXED BY <zIndex>" clause */
10021 Index *pIndex; /* Index structure corresponding to zIndex, if any */
10022 } a[1]; /* One entry for each identifier on the list */
10023 };
10024
@@ -9980,65 +10031,92 @@
10031 #define JT_LEFT 0x0008 /* Left outer join */
10032 #define JT_RIGHT 0x0010 /* Right outer join */
10033 #define JT_OUTER 0x0020 /* The "OUTER" keyword is present */
10034 #define JT_ERROR 0x0040 /* unknown or unsupported join type */
10035
10036
10037 /*
10038 ** A WherePlan object holds information that describes a lookup
10039 ** strategy.
10040 **
10041 ** This object is intended to be opaque outside of the where.c module.
10042 ** It is included here only so that that compiler will know how big it
10043 ** is. None of the fields in this object should be used outside of
10044 ** the where.c module.
10045 **
10046 ** Within the union, pIdx is only used when wsFlags&WHERE_INDEXED is true.
10047 ** pTerm is only used when wsFlags&WHERE_MULTI_OR is true. And pVtabIdx
10048 ** is only used when wsFlags&WHERE_VIRTUALTABLE is true. It is never the
10049 ** case that more than one of these conditions is true.
10050 */
10051 struct WherePlan {
10052 u32 wsFlags; /* WHERE_* flags that describe the strategy */
10053 u32 nEq; /* Number of == constraints */
10054 union {
10055 Index *pIdx; /* Index when WHERE_INDEXED is true */
10056 struct WhereTerm *pTerm; /* WHERE clause term for OR-search */
10057 sqlite3_index_info *pVtabIdx; /* Virtual table index to use */
10058 } u;
10059 };
10060
10061 /*
10062 ** For each nested loop in a WHERE clause implementation, the WhereInfo
10063 ** structure contains a single instance of this structure. This structure
10064 ** is intended to be private the the where.c module and should not be
10065 ** access or modified by other modules.
10066 **
10067 ** The pIdxInfo field is used to help pick the best index on a
10068 ** virtual table. The pIdxInfo pointer contains indexing
10069 ** information for the i-th table in the FROM clause before reordering.
10070 ** All the pIdxInfo pointers are freed by whereInfoFree() in where.c.
10071 ** All other information in the i-th WhereLevel object for the i-th table
10072 ** after FROM clause ordering.
 
 
 
 
 
 
10073 */
10074 struct WhereLevel {
10075 WherePlan plan; /* query plan for this element of the FROM clause */
 
 
10076 int iLeftJoin; /* Memory cell used to implement LEFT OUTER JOIN */
 
10077 int iTabCur; /* The VDBE cursor used to access the table */
10078 int iIdxCur; /* The VDBE cursor used to access pIdx */
10079 int addrBrk; /* Jump here to break out of the loop */
10080 int addrNxt; /* Jump here to start the next IN combination */
10081 int addrCont; /* Jump here to continue with the next loop cycle */
10082 int addrFirst; /* First instruction of interior of the loop */
10083 u8 iFrom; /* Which entry in the FROM clause */
10084 u8 op, p5; /* Opcode and P5 of the opcode that ends the loop */
10085 int p1, p2; /* Operands of the opcode used to ends the loop */
10086 union { /* Information that depends on plan.wsFlags */
10087 struct {
10088 int nIn; /* Number of entries in aInLoop[] */
10089 struct InLoop {
10090 int iCur; /* The VDBE cursor used by this IN operator */
10091 int addrInTop; /* Top of the IN loop */
10092 } *aInLoop; /* Information about each nested IN operator */
10093 } in; /* Used when plan.wsFlags&WHERE_IN_ABLE */
10094 struct {
10095 WherePlan *aPlan; /* Plans for each term of the WHERE clause */
10096 } or; /* Used when plan.wsFlags&WHERE_MULTI_OR */
10097 } u;
10098
10099 /* The following field is really not part of the current level. But
10100 ** we need a place to cache virtual table index information for each
10101 ** virtual table in the FROM clause and the WhereLevel structure is
10102 ** a convenient place since there is one WhereLevel for each FROM clause
10103 ** element.
10104 */
10105 sqlite3_index_info *pIdxInfo; /* Index info for n-th source table */
10106 };
10107
10108 /*
10109 ** Flags appropriate for the wctrlFlags parameter of sqlite3WhereBegin().
10110 */
10111 #define WHERE_ORDERBY_NORMAL 0x0000 /* No-op */
10112 #define WHERE_ORDERBY_MIN 0x0001 /* ORDER BY processing for min() func */
10113 #define WHERE_ORDERBY_MAX 0x0002 /* ORDER BY processing for max() func */
10114 #define WHERE_ONEPASS_DESIRED 0x0004 /* Want to do one-pass UPDATE/DELETE */
10115 #define WHERE_FILL_ROWSET 0x0008 /* Save results in a RowSet object */
10116 #define WHERE_OMIT_OPEN 0x0010 /* Table cursor are already open */
10117 #define WHERE_OMIT_CLOSE 0x0020 /* Omit close of table & index cursors */
10118
10119 /*
10120 ** The WHERE clause processing routine has two halves. The
10121 ** first part does the start of the WHERE loop and the second
10122 ** half does the tail of the WHERE loop. An instance of
@@ -10045,18 +10123,20 @@
10123 ** this structure is returned by the first half and passed
10124 ** into the second half to give some continuity.
10125 */
10126 struct WhereInfo {
10127 Parse *pParse; /* Parsing and code generating context */
10128 u16 wctrlFlags; /* Flags originally passed to sqlite3WhereBegin() */
10129 u8 okOnePass; /* Ok to use one-pass algorithm for UPDATE or DELETE */
10130 int regRowSet; /* Store rowids in this rowset if >=0 */
10131 SrcList *pTabList; /* List of tables in the join */
10132 int iTop; /* The very beginning of the WHERE loop */
10133 int iContinue; /* Jump here to continue with next record */
10134 int iBreak; /* Jump here to break out of the loop */
10135 int nLevel; /* Number of nested loop */
10136 struct WhereClause *pWC; /* Decomposition of the WHERE clause */
10137 WhereLevel a[1]; /* Information about each nest loop in WHERE */
10138 };
10139
10140 /*
10141 ** A NameContext defines a context in which to resolve table and column
10142 ** names. The context consists of a list of tables (the pSrcList) field and
@@ -10695,11 +10775,11 @@
10775 #if defined(SQLITE_ENABLE_UPDATE_DELETE_LIMIT) && !defined(SQLITE_OMIT_SUBQUERY)
10776 SQLITE_PRIVATE Expr *sqlite3LimitWhere(Parse *, SrcList *, Expr *, ExprList *, Expr *, Expr *, char *);
10777 #endif
10778 SQLITE_PRIVATE void sqlite3DeleteFrom(Parse*, SrcList*, Expr*);
10779 SQLITE_PRIVATE void sqlite3Update(Parse*, SrcList*, ExprList*, Expr*, int);
10780 SQLITE_PRIVATE WhereInfo *sqlite3WhereBegin(Parse*, SrcList*, Expr*, ExprList**, u8, int);
10781 SQLITE_PRIVATE void sqlite3WhereEnd(WhereInfo*);
10782 SQLITE_PRIVATE int sqlite3ExprCodeGetColumn(Parse*, Table*, int, int, int, int);
10783 SQLITE_PRIVATE void sqlite3ExprCodeMove(Parse*, int, int, int);
10784 SQLITE_PRIVATE void sqlite3ExprCodeCopy(Parse*, int, int, int);
10785 SQLITE_PRIVATE void sqlite3ExprClearColumnCache(Parse*, int);
@@ -10733,10 +10813,12 @@
10813 SQLITE_PRIVATE void sqlite3RollbackAll(sqlite3*);
10814 SQLITE_PRIVATE void sqlite3CodeVerifySchema(Parse*, int);
10815 SQLITE_PRIVATE void sqlite3BeginTransaction(Parse*, int);
10816 SQLITE_PRIVATE void sqlite3CommitTransaction(Parse*);
10817 SQLITE_PRIVATE void sqlite3RollbackTransaction(Parse*);
10818 SQLITE_PRIVATE void sqlite3Savepoint(Parse*, int, Token*);
10819 SQLITE_PRIVATE void sqlite3CloseSavepoints(sqlite3 *);
10820 SQLITE_PRIVATE int sqlite3ExprIsConstant(Expr*);
10821 SQLITE_PRIVATE int sqlite3ExprIsConstantNotJoin(Expr*);
10822 SQLITE_PRIVATE int sqlite3ExprIsConstantOrFunction(Expr*);
10823 SQLITE_PRIVATE int sqlite3ExprIsInteger(Expr*, int*);
10824 SQLITE_PRIVATE int sqlite3IsRowid(const char*);
@@ -11031,11 +11113,11 @@
11113 #else
11114 #define sqlite3JournalSize(pVfs) ((pVfs)->szOsFile)
11115 #endif
11116
11117 SQLITE_PRIVATE void sqlite3MemJournalOpen(sqlite3_file *);
11118 SQLITE_PRIVATE int sqlite3MemJournalSize(void);
11119 SQLITE_PRIVATE int sqlite3IsMemJournal(sqlite3_file *);
11120
11121 #if SQLITE_MAX_EXPR_DEPTH>0
11122 SQLITE_PRIVATE void sqlite3ExprSetHeight(Parse *pParse, Expr *p);
11123 SQLITE_PRIVATE int sqlite3SelectExprHeight(Select *);
@@ -11321,11 +11403,11 @@
11403 **
11404 ** There is only one exported symbol in this file - the function
11405 ** sqlite3RegisterDateTimeFunctions() found at the bottom of the file.
11406 ** All other code has file scope.
11407 **
11408 ** $Id: date.c,v 1.99 2008/12/20 13:18:50 drh Exp $
11409 **
11410 ** SQLite processes all times and dates as Julian Day numbers. The
11411 ** dates and times are stored as the number of days since noon
11412 ** in Greenwich on November 24, 4714 B.C. according to the Gregorian
11413 ** calendar system.
@@ -11750,11 +11832,11 @@
11832 x.s = s;
11833 }
11834 x.tz = 0;
11835 x.validJD = 0;
11836 computeJD(&x);
11837 t = x.iJD/1000 - 21086676*(i64)10000;
11838 #ifdef HAVE_LOCALTIME_R
11839 {
11840 struct tm sLocal;
11841 localtime_r(&t, &sLocal);
11842 y.Y = sLocal.tm_year + 1900;
@@ -11852,11 +11934,11 @@
11934 **
11935 ** Treat the current value of p->iJD as the number of
11936 ** seconds since 1970. Convert to a real julian day number.
11937 */
11938 if( strcmp(z, "unixepoch")==0 && p->validJD ){
11939 p->iJD = p->iJD/86400 + 21086676*(i64)10000000;
11940 clearYMD_HMS_TZ(p);
11941 rc = 0;
11942 }
11943 #ifndef SQLITE_OMIT_LOCALTIME
11944 else if( strcmp(z, "utc")==0 ){
@@ -17728,11 +17810,11 @@
17810 ** VDBE. This information used to all be at the top of the single
17811 ** source code file "vdbe.c". When that file became too big (over
17812 ** 6000 lines long) it was split up into several smaller files and
17813 ** this header information was factored out.
17814 **
17815 ** $Id: vdbeInt.h,v 1.161 2009/01/05 18:02:27 drh Exp $
17816 */
17817 #ifndef _VDBEINT_H_
17818 #define _VDBEINT_H_
17819
17820 /*
@@ -17886,11 +17968,12 @@
17968
17969
17970 /*
17971 ** Clear any existing type flags from a Mem and replace them with f
17972 */
17973 #define MemSetTypeFlag(p, f) \
17974 ((p)->flags = ((p)->flags&~(MEM_TypeMask|MEM_Zero))|f)
17975
17976
17977 /* A VdbeFunc is just a FuncDef (defined in sqliteInt.h) that contains
17978 ** additional information about auxiliary information bound to arguments
17979 ** of the function. This is used to implement the sqlite3_get_auxdata()
@@ -19589,11 +19672,11 @@
19672 **
19673 *************************************************************************
19674 ** This is the implementation of generic hash-tables
19675 ** used in SQLite.
19676 **
19677 ** $Id: hash.c,v 1.33 2009/01/09 01:12:28 drh Exp $
19678 */
19679
19680 /* Turn bulk memory into a hash table object by initializing the
19681 ** fields of the Hash structure.
19682 **
@@ -19623,11 +19706,11 @@
19706 sqlite3_free(pH->ht);
19707 pH->ht = 0;
19708 pH->htsize = 0;
19709 while( elem ){
19710 HashElem *next_elem = elem->next;
19711 if( pH->copyKey ){
19712 sqlite3_free(elem->pKey);
19713 }
19714 sqlite3_free(elem);
19715 elem = next_elem;
19716 }
@@ -19884,153 +19967,155 @@
19967 /* Automatically generated. Do not edit */
19968 /* See the mkopcodec.awk script for details. */
19969 #if !defined(SQLITE_OMIT_EXPLAIN) || !defined(NDEBUG) || defined(VDBE_PROFILE) || defined(SQLITE_DEBUG)
19970 SQLITE_PRIVATE const char *sqlite3OpcodeName(int i){
19971 static const char *const azName[] = { "?",
19972 /* 1 */ "VCreate",
19973 /* 2 */ "MemMax",
19974 /* 3 */ "LoadAnalysis",
19975 /* 4 */ "RowData",
19976 /* 5 */ "CreateIndex",
19977 /* 6 */ "Variable",
19978 /* 7 */ "SeekGt",
19979 /* 8 */ "SeekLe",
19980 /* 9 */ "IfNeg",
19981 /* 10 */ "Clear",
19982 /* 11 */ "Last",
19983 /* 12 */ "Savepoint",
19984 /* 13 */ "Sequence",
19985 /* 14 */ "Int64",
19986 /* 15 */ "VBegin",
19987 /* 16 */ "RowKey",
19988 /* 17 */ "SCopy",
19989 /* 18 */ "ResetCount",
19990 /* 19 */ "Not",
19991 /* 20 */ "Delete",
19992 /* 21 */ "Trace",
19993 /* 22 */ "Rowid",
19994 /* 23 */ "OpenRead",
19995 /* 24 */ "Sort",
19996 /* 25 */ "VerifyCookie",
19997 /* 26 */ "VColumn",
19998 /* 27 */ "Next",
19999 /* 28 */ "Insert",
20000 /* 29 */ "Prev",
20001 /* 30 */ "IdxGE",
20002 /* 31 */ "VRename",
20003 /* 32 */ "DropTable",
20004 /* 33 */ "MakeRecord",
20005 /* 34 */ "Null",
20006 /* 35 */ "IdxInsert",
20007 /* 36 */ "SeekLt",
20008 /* 37 */ "ReadCookie",
20009 /* 38 */ "VDestroy",
20010 /* 39 */ "DropIndex",
20011 /* 40 */ "MustBeInt",
20012 /* 41 */ "IntegrityCk",
20013 /* 42 */ "CollSeq",
20014 /* 43 */ "ResultRow",
20015 /* 44 */ "Yield",
20016 /* 45 */ "OpenEphemeral",
20017 /* 46 */ "VNext",
20018 /* 47 */ "Seek",
20019 /* 48 */ "Found",
20020 /* 49 */ "If",
20021 /* 50 */ "IfZero",
20022 /* 51 */ "Goto",
20023 /* 52 */ "Function",
20024 /* 53 */ "Copy",
20025 /* 54 */ "Jump",
20026 /* 55 */ "Blob",
20027 /* 56 */ "NullRow",
20028 /* 57 */ "Transaction",
20029 /* 58 */ "VUpdate",
20030 /* 59 */ "TableLock",
20031 /* 60 */ "IdxRowid",
20032 /* 61 */ "SetCookie",
20033 /* 62 */ "ContextPush",
20034 /* 63 */ "Or",
20035 /* 64 */ "And",
20036 /* 65 */ "DropTrigger",
20037 /* 66 */ "AutoCommit",
20038 /* 67 */ "Column",
20039 /* 68 */ "IsNull",
20040 /* 69 */ "NotNull",
20041 /* 70 */ "Ne",
20042 /* 71 */ "Eq",
20043 /* 72 */ "Gt",
20044 /* 73 */ "Le",
20045 /* 74 */ "Lt",
20046 /* 75 */ "Ge",
20047 /* 76 */ "AddImm",
20048 /* 77 */ "BitAnd",
20049 /* 78 */ "BitOr",
20050 /* 79 */ "ShiftLeft",
20051 /* 80 */ "ShiftRight",
20052 /* 81 */ "Add",
20053 /* 82 */ "Subtract",
20054 /* 83 */ "Multiply",
20055 /* 84 */ "Divide",
20056 /* 85 */ "Remainder",
20057 /* 86 */ "Concat",
20058 /* 87 */ "ContextPop",
20059 /* 88 */ "IdxDelete",
20060 /* 89 */ "IncrVacuum",
20061 /* 90 */ "BitNot",
20062 /* 91 */ "String8",
20063 /* 92 */ "AggFinal",
20064 /* 93 */ "RealAffinity",
20065 /* 94 */ "Return",
20066 /* 95 */ "Expire",
20067 /* 96 */ "Rewind",
20068 /* 97 */ "Statement",
20069 /* 98 */ "Integer",
20070 /* 99 */ "Compare",
20071 /* 100 */ "Destroy",
20072 /* 101 */ "IdxLT",
20073 /* 102 */ "Affinity",
20074 /* 103 */ "Vacuum",
20075 /* 104 */ "IfNot",
20076 /* 105 */ "Move",
20077 /* 106 */ "Explain",
20078 /* 107 */ "ParseSchema",
20079 /* 108 */ "NewRowid",
20080 /* 109 */ "SetNumColumns",
20081 /* 110 */ "String",
20082 /* 111 */ "AggStep",
20083 /* 112 */ "VRowid",
20084 /* 113 */ "VOpen",
20085 /* 114 */ "NotExists",
20086 /* 115 */ "Close",
20087 /* 116 */ "Halt",
20088 /* 117 */ "Noop",
20089 /* 118 */ "SeekGe",
20090 /* 119 */ "VFilter",
20091 /* 120 */ "OpenPseudo",
20092 /* 121 */ "RowSetRead",
20093 /* 122 */ "RowSetAdd",
20094 /* 123 */ "IsUnique",
20095 /* 124 */ "OpenWrite",
20096 /* 125 */ "Permutation",
20097 /* 126 */ "Gosub",
20098 /* 127 */ "IfPos",
20099 /* 128 */ "Pagecount",
20100 /* 129 */ "Real",
20101 /* 130 */ "NotFound",
20102 /* 131 */ "CreateTable",
20103 /* 132 */ "NotUsed_132",
20104 /* 133 */ "NotUsed_133",
20105 /* 134 */ "NotUsed_134",
20106 /* 135 */ "NotUsed_135",
20107 /* 136 */ "NotUsed_136",
20108 /* 137 */ "NotUsed_137",
20109 /* 138 */ "NotUsed_138",
20110 /* 139 */ "NotUsed_139",
20111 /* 140 */ "NotUsed_140",
20112 /* 141 */ "ToText",
20113 /* 142 */ "ToBlob",
20114 /* 143 */ "ToNumeric",
20115 /* 144 */ "ToInt",
20116 /* 145 */ "ToReal",
20117 };
20118 return azName[i];
20119 }
20120 #endif
20121
@@ -21440,11 +21525,11 @@
21525 ** * sqlite3_vfs method implementations.
21526 ** * Locking primitives for the proxy uber-locking-method. (MacOSX only)
21527 ** * Definitions of sqlite3_vfs objects for all locking methods
21528 ** plus implementations of sqlite3_os_init() and sqlite3_os_end().
21529 **
21530 ** $Id: os_unix.c,v 1.235 2009/01/09 21:41:17 drh Exp $
21531 */
21532 #if SQLITE_OS_UNIX /* This file is used on unix only */
21533
21534 /*
21535 ** There are various methods for file locking used for concurrency
@@ -21462,11 +21547,11 @@
21547 ** is defined to 1. The SQLITE_ENABLE_LOCKING_STYLE also enables automatic
21548 ** selection of the appropriate locking style based on the filesystem
21549 ** where the database is located.
21550 */
21551 #if !defined(SQLITE_ENABLE_LOCKING_STYLE)
21552 # if defined(__APPLE__)
21553 # define SQLITE_ENABLE_LOCKING_STYLE 1
21554 # else
21555 # define SQLITE_ENABLE_LOCKING_STYLE 0
21556 # endif
21557 #endif
@@ -23800,11 +23885,11 @@
23885 **
23886 ** Third-party implementations of AFP are available. But this code here
23887 ** only works on OSX.
23888 */
23889
23890 #if defined(__APPLE__) && SQLITE_ENABLE_LOCKING_STYLE
23891 /*
23892 ** The afpLockingContext structure contains all afp lock specific state
23893 */
23894 typedef struct afpLockingContext afpLockingContext;
23895 struct afpLockingContext {
@@ -24183,11 +24268,11 @@
24268 unixLeaveMutex();
24269 }
24270 return SQLITE_OK;
24271 }
24272
24273 #endif /* defined(__APPLE__) && SQLITE_ENABLE_LOCKING_STYLE */
24274 /*
24275 ** The code above is the AFP lock implementation. The code is specific
24276 ** to MacOSX and does not work on other unix platforms. No alternative
24277 ** is available. If you don't compile for a mac, then the "unix-afp"
24278 ** VFS is not available.
@@ -24562,11 +24647,11 @@
24647
24648
24649 return SQLITE_OK;
24650 }
24651
24652 #if SQLITE_ENABLE_LOCKING_STYLE && defined(__APPLE__)
24653 /*
24654 ** Handler for proxy-locking file-control verbs. Defined below in the
24655 ** proxying locking division.
24656 */
24657 static int proxyFileControl(sqlite3_file*,int,void*);
@@ -24584,16 +24669,16 @@
24669 }
24670 case SQLITE_LAST_ERRNO: {
24671 *(int*)pArg = ((unixFile*)id)->lastErrno;
24672 return SQLITE_OK;
24673 }
24674 #if SQLITE_ENABLE_LOCKING_STYLE && defined(__APPLE__)
24675 case SQLITE_SET_LOCKPROXYFILE:
24676 case SQLITE_GET_LOCKPROXYFILE: {
24677 return proxyFileControl(id,op,pArg);
24678 }
24679 #endif /* SQLITE_ENABLE_LOCKING_STYLE && defined(__APPLE__) */
24680 }
24681 return SQLITE_ERROR;
24682 }
24683
24684 /*
@@ -24732,11 +24817,11 @@
24817 semUnlock, /* xUnlock method */
24818 semCheckReservedLock /* xCheckReservedLock method */
24819 )
24820 #endif
24821
24822 #if defined(__APPLE__) && SQLITE_ENABLE_LOCKING_STYLE
24823 IOMETHODS(
24824 afpIoFinder, /* Finder function name */
24825 afpIoMethods, /* sqlite3_io_methods object name */
24826 afpClose, /* xClose method */
24827 afpLock, /* xLock method */
@@ -24752,11 +24837,11 @@
24837 ** secondary files. For this reason, the division that implements
24838 ** proxy locking is located much further down in the file. But we need
24839 ** to go ahead and define the sqlite3_io_methods and finder function
24840 ** for proxy locking here. So we forward declare the I/O methods.
24841 */
24842 #if defined(__APPLE__) && SQLITE_ENABLE_LOCKING_STYLE
24843 static int proxyClose(sqlite3_file*);
24844 static int proxyLock(sqlite3_file*, int);
24845 static int proxyUnlock(sqlite3_file*, int);
24846 static int proxyCheckReservedLock(sqlite3_file*, int*);
24847 IOMETHODS(
@@ -24768,11 +24853,11 @@
24853 proxyCheckReservedLock /* xCheckReservedLock method */
24854 )
24855 #endif
24856
24857
24858 #if defined(__APPLE__) && SQLITE_ENABLE_LOCKING_STYLE
24859 /*
24860 ** This "finder" function attempts to determine the best locking strategy
24861 ** for the database file "filePath". It then returns the sqlite3_io_methods
24862 ** object that implements that strategy.
24863 **
@@ -24829,14 +24914,14 @@
24914 return &posixIoMethods;
24915 }else{
24916 return &dotlockIoMethods;
24917 }
24918 }
24919 static const sqlite3_io_methods *(*const autolockIoFinder)(const char*,int)
24920 = autolockIoFinderImpl;
24921
24922 #endif /* defined(__APPLE__) && SQLITE_ENABLE_LOCKING_STYLE */
24923
24924 /*
24925 ** An abstract type for a pointer to a IO method finder function:
24926 */
24927 typedef const sqlite3_io_methods *(*finder_type)(const char*,int);
@@ -24905,11 +24990,11 @@
24990 unixEnterMutex();
24991 rc = findLockInfo(pNew, &pNew->pLock, &pNew->pOpen);
24992 unixLeaveMutex();
24993 }
24994
24995 #if SQLITE_ENABLE_LOCKING_STYLE && defined(__APPLE__)
24996 else if( pLockingStyle == &afpIoMethods ){
24997 /* AFP locking uses the file path so it needs to be included in
24998 ** the afpLockingContext.
24999 */
25000 afpLockingContext *pCtx;
@@ -25001,11 +25086,11 @@
25086 int ii;
25087 int fd = -1;
25088 char zDirname[MAX_PATHNAME+1];
25089
25090 sqlite3_snprintf(MAX_PATHNAME, zDirname, "%s", zFilename);
25091 for(ii=(int)strlen(zDirname); ii>1 && zDirname[ii]!='/'; ii--);
25092 if( ii>0 ){
25093 zDirname[ii] = '\0';
25094 fd = open(zDirname, O_RDONLY|O_BINARY, 0);
25095 if( fd>=0 ){
25096 #ifdef FD_CLOEXEC
@@ -25077,11 +25162,11 @@
25162 zBuf[j] = 0;
25163 }while( access(zBuf,0)==0 );
25164 return SQLITE_OK;
25165 }
25166
25167 #if SQLITE_ENABLE_LOCKING_STYLE && defined(__APPLE__)
25168 /*
25169 ** Routine to transform a unixFile into a proxy-locking unixFile.
25170 ** Implementation in the proxy-lock division, but used by unixOpen()
25171 ** if SQLITE_PREFER_PROXY_LOCKING is defined.
25172 */
@@ -25724,11 +25809,11 @@
25809 */
25810
25811 /*
25812 ** Proxy locking is only available on MacOSX
25813 */
25814 #if defined(__APPLE__) && SQLITE_ENABLE_LOCKING_STYLE
25815
25816 #ifdef SQLITE_TEST
25817 /* simulate multiple hosts by creating unique hostid file paths */
25818 SQLITE_API int sqlite3_hostid_num = 0;
25819 #endif
@@ -26214,11 +26299,11 @@
26299 **
26300 ** This routine find the filename associated with pFile and writes it
26301 ** int dbPath.
26302 */
26303 static int proxyGetDbPathForUnixFile(unixFile *pFile, char *dbPath){
26304 #if defined(__APPLE__)
26305 if( pFile->pMethod == &afpIoMethods ){
26306 /* afp style keeps a reference to the db path in the filePath field
26307 ** of the struct */
26308 assert( (int)strlen((char*)pFile->lockingContext)<=MAXPATHLEN );
26309 strcpy(dbPath, ((afpLockingContext *)pFile->lockingContext)->dbPath);
@@ -26483,11 +26568,11 @@
26568 return SQLITE_OK;
26569 }
26570
26571
26572
26573 #endif /* defined(__APPLE__) && SQLITE_ENABLE_LOCKING_STYLE */
26574 /*
26575 ** The proxy locking style is intended for use with AFP filesystems.
26576 ** And since AFP is only supported on MacOSX, the proxy locking is also
26577 ** restricted to MacOSX.
26578 **
@@ -26556,11 +26641,11 @@
26641 ** Note that the sqlite3_vfs.pNext field of the VFS object is modified
26642 ** by the SQLite core when the VFS is registered. So the following
26643 ** array cannot be const.
26644 */
26645 static sqlite3_vfs aVfs[] = {
26646 #if SQLITE_ENABLE_LOCKING_STYLE && defined(__APPLE__)
26647 UNIXVFS("unix", autolockIoFinder ),
26648 #else
26649 UNIXVFS("unix", posixIoFinder ),
26650 #endif
26651 UNIXVFS("unix-none", nolockIoFinder ),
@@ -26570,11 +26655,11 @@
26655 #endif
26656 #if SQLITE_ENABLE_LOCKING_STYLE
26657 UNIXVFS("unix-posix", posixIoFinder ),
26658 UNIXVFS("unix-flock", flockIoFinder ),
26659 #endif
26660 #if SQLITE_ENABLE_LOCKING_STYLE && defined(__APPLE__)
26661 UNIXVFS("unix-afp", afpIoFinder ),
26662 UNIXVFS("unix-proxy", proxyIoFinder ),
26663 #endif
26664 };
26665 unsigned int i; /* Loop counter */
@@ -28592,11 +28677,11 @@
28677 ** sometimes grow into tens of thousands or larger. The size of the
28678 ** Bitvec object is the number of pages in the database file at the
28679 ** start of a transaction, and is thus usually less than a few thousand,
28680 ** but can be as large as 2 billion for a really big database.
28681 **
28682 ** @(#) $Id: bitvec.c,v 1.10 2009/01/02 21:39:39 drh Exp $
28683 */
28684
28685 /* Size of the Bitvec structure in bytes. */
28686 #define BITVEC_SZ 512
28687
@@ -28731,13 +28816,11 @@
28816 i--;
28817 while((p->iSize > BITVEC_NBIT) && p->iDivisor) {
28818 u32 bin = i/p->iDivisor;
28819 i = i%p->iDivisor;
28820 if( p->u.apSub[bin]==0 ){
 
28821 p->u.apSub[bin] = sqlite3BitvecCreate( p->iDivisor );
 
28822 if( p->u.apSub[bin]==0 ) return SQLITE_NOMEM;
28823 }
28824 p = p->u.apSub[bin];
28825 }
28826 if( p->iSize<=BITVEC_NBIT ){
@@ -29546,11 +29629,11 @@
29629 ** sqlite3_pcache interface). It also contains part of the implementation
29630 ** of the SQLITE_CONFIG_PAGECACHE and sqlite3_release_memory() features.
29631 ** If the default page cache implementation is overriden, then neither of
29632 ** these two features are available.
29633 **
29634 ** @(#) $Id: pcache1.c,v 1.7 2009/01/07 15:18:21 danielk1977 Exp $
29635 */
29636
29637
29638 typedef struct PCache1 PCache1;
29639 typedef struct PgHdr1 PgHdr1;
@@ -29576,10 +29659,12 @@
29659 */
29660 unsigned int nRecyclable; /* Number of pages in the LRU list */
29661 unsigned int nPage; /* Total number of pages in apHash */
29662 unsigned int nHash; /* Number of slots in apHash[] */
29663 PgHdr1 **apHash; /* Hash table for fast lookup by key */
29664
29665 unsigned int iMaxKey; /* Largest key seen since xTruncate() */
29666 };
29667
29668 /*
29669 ** Each cache entry is represented by an instance of the following
29670 ** structure. A buffer of PgHdr1.pCache->szPage bytes is allocated
@@ -30086,10 +30171,13 @@
30171 pPage->pCache = pCache;
30172 pCache->apHash[h] = pPage;
30173 }
30174
30175 fetch_out:
30176 if( pPage && iKey>pCache->iMaxKey ){
30177 pCache->iMaxKey = iKey;
30178 }
30179 if( createFlag==1 ) sqlite3EndBenignMalloc();
30180 pcache1LeaveMutex();
30181 return (pPage ? PGHDR1_TO_PAGE(pPage) : 0);
30182 }
30183
@@ -30160,10 +30248,14 @@
30248
30249 h = iNew%pCache->nHash;
30250 pPage->iKey = iNew;
30251 pPage->pNext = pCache->apHash[h];
30252 pCache->apHash[h] = pPage;
30253
30254 if( iNew>pCache->iMaxKey ){
30255 pCache->iMaxKey = iNew;
30256 }
30257
30258 pcache1LeaveMutex();
30259 }
30260
30261 /*
@@ -30174,11 +30266,14 @@
30266 ** equal to or greater than iLimit are implicitly unpinned.
30267 */
30268 static void pcache1Truncate(sqlite3_pcache *p, unsigned int iLimit){
30269 PCache1 *pCache = (PCache1 *)p;
30270 pcache1EnterMutex();
30271 if( iLimit<=pCache->iMaxKey ){
30272 pcache1TruncateUnsafe(pCache, iLimit);
30273 pCache->iMaxKey = iLimit-1;
30274 }
30275 pcache1LeaveMutex();
30276 }
30277
30278 /*
30279 ** Implementation of the sqlite3_pcache.xDestroy method.
@@ -30343,29 +30438,27 @@
30438 ** Turn bulk memory into a RowSet object. N bytes of memory
30439 ** are available at pSpace. The db pointer is used as a memory context
30440 ** for any subsequent allocations that need to occur.
30441 ** Return a pointer to the new RowSet object.
30442 **
30443 ** It must be the case that N is sufficient to make a Rowset. If not
30444 ** an assertion fault occurs.
30445 **
30446 ** If N is larger than the minimum, use the surplus as an initial
30447 ** allocation of entries available to be filled.
30448 */
30449 SQLITE_PRIVATE RowSet *sqlite3RowSetInit(sqlite3 *db, void *pSpace, unsigned int N){
30450 RowSet *p;
30451 assert( N >= sizeof(*p) );
30452 p = pSpace;
30453 p->pChunk = 0;
30454 p->db = db;
30455 p->pEntry = 0;
30456 p->pLast = 0;
30457 p->pFresh = (struct RowSetEntry*)&p[1];
30458 p->nFresh = (u16)((N - sizeof(*p))/sizeof(struct RowSetEntry));
30459 p->isSorted = 1;
 
 
 
30460 return p;
30461 }
30462
30463 /*
30464 ** Deallocate all chunks from a RowSet.
@@ -30529,34 +30622,27 @@
30622 ** is separate from the database file. The pager also implements file
30623 ** locking to prevent two processes from writing the same database
30624 ** file simultaneously, or one process from reading the database while
30625 ** another is writing.
30626 **
30627 ** @(#) $Id: pager.c,v 1.544 2009/01/09 17:11:05 danielk1977 Exp $
30628 */
30629 #ifndef SQLITE_OMIT_DISKIO
30630
30631 /*
30632 ** Macros for troubleshooting. Normally turned off
30633 */
30634 #if 0
30635 int sqlite3PagerTrace=1; /* True to enable tracing */
30636 #define sqlite3DebugPrintf printf
30637 #define PAGERTRACE(X) if( sqlite3PagerTrace ){ sqlite3DebugPrintf X; }
 
 
 
 
30638 #else
30639 #define PAGERTRACE(X)
 
 
 
 
30640 #endif
30641
30642 /*
30643 ** The following two macros are used within the PAGERTRACE() macros above
30644 ** to print out file-descriptors.
30645 **
30646 ** PAGERID() takes a pointer to a Pager struct as its argument. The
30647 ** associated file-descriptor is returned. FILEHANDLEID() takes an sqlite3_file
30648 ** struct as its argument.
@@ -30616,27 +30702,10 @@
30702 #define PAGER_SHARED 1 /* same as SHARED_LOCK */
30703 #define PAGER_RESERVED 2 /* same as RESERVED_LOCK */
30704 #define PAGER_EXCLUSIVE 4 /* same as EXCLUSIVE_LOCK */
30705 #define PAGER_SYNCED 5
30706
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
30707 /*
30708 ** This macro rounds values up so that if the value is an address it
30709 ** is guaranteed to be an address that is aligned to an 8-byte boundary.
30710 */
30711 #define FORCE_ALIGNMENT(X) (((X)+7)&~7)
@@ -30650,10 +30719,32 @@
30719 #else
30720 # define CODEC1(P,D,N,X) /* NO-OP */
30721 # define CODEC2(P,D,N,X) ((char*)D)
30722 #endif
30723
30724 /*
30725 ** An instance of the following structure is allocated for each active
30726 ** savepoint and statement transaction in the system. All such structures
30727 ** are stored in the Pager.aSavepoint[] array, which is allocated and
30728 ** resized using sqlite3Realloc().
30729 **
30730 ** When a savepoint is created, the PagerSavepoint.iHdrOffset field is
30731 ** set to 0. If a journal-header is written into the main journal while
30732 ** the savepoint is active, then iHdrOffset is set to the byte offset
30733 ** immediately following the last journal record written into the main
30734 ** journal before the journal-header. This is required during savepoint
30735 ** rollback (see pagerPlaybackSavepoint()).
30736 */
30737 typedef struct PagerSavepoint PagerSavepoint;
30738 struct PagerSavepoint {
30739 i64 iOffset; /* Starting offset in main journal */
30740 i64 iHdrOffset; /* See above */
30741 Bitvec *pInSavepoint; /* Set of pages in this savepoint */
30742 Pgno nOrig; /* Original number of pages in file */
30743 Pgno iSubRec; /* Index of first record in sub-journal */
30744 };
30745
30746 /*
30747 ** A open page cache is an instance of the following structure.
30748 **
30749 ** Pager.errCode may be set to SQLITE_IOERR, SQLITE_CORRUPT, or
30750 ** or SQLITE_FULL. Once one of the first three errors occurs, it persists
@@ -30660,20 +30751,29 @@
30751 ** and is returned as the result of every major pager API call. The
30752 ** SQLITE_FULL return code is slightly different. It persists only until the
30753 ** next successful rollback is performed on the pager cache. Also,
30754 ** SQLITE_FULL does not affect the sqlite3PagerGet() and sqlite3PagerLookup()
30755 ** APIs, they may still be used successfully.
30756 **
30757 ** Managing the size of the database file in pages is a little complicated.
30758 ** The variable Pager.dbSize contains the number of pages that the database
30759 ** image currently contains. As the database image grows or shrinks this
30760 ** variable is updated. The variable Pager.dbFileSize contains the number
30761 ** of pages in the database file. This may be different from Pager.dbSize
30762 ** if some pages have been appended to the database image but not yet written
30763 ** out from the cache to the actual file on disk. Or if the image has been
30764 ** truncated by an incremental-vacuum operation. The Pager.dbOrigSize variable
30765 ** contains the number of pages in the database image when the current
30766 ** transaction was opened. The contents of all three of these variables is
30767 ** only guaranteed to be correct if the boolean Pager.dbSizeValid is true.
30768 */
30769 struct Pager {
30770 sqlite3_vfs *pVfs; /* OS functions to use for IO */
30771 u8 journalOpen; /* True if journal file descriptors is valid */
30772 u8 journalStarted; /* True if header of journal is synced */
30773 u8 useJournal; /* Use a rollback journal on this file */
30774 u8 noReadlock; /* Do not bother to obtain readlocks */
 
 
 
30775 u8 noSync; /* Do not sync the journal if true */
30776 u8 fullSync; /* Do extra syncs of the journal for robustness */
30777 u8 sync_flags; /* One of SYNC_NORMAL or SYNC_FULL */
30778 u8 state; /* PAGER_UNLOCK, _SHARED, _RESERVED, etc. */
30779 u8 tempFile; /* zFilename is a temporary file */
@@ -30687,38 +30787,34 @@
30787 u8 exclusiveMode; /* Boolean. True if locking_mode==EXCLUSIVE */
30788 u8 journalMode; /* On of the PAGER_JOURNALMODE_* values */
30789 u8 dbModified; /* True if there are any changes to the Db */
30790 u8 changeCountDone; /* Set after incrementing the change-counter */
30791 u8 dbSizeValid; /* Set when dbSize is correct */
30792 Pgno dbSize; /* Number of pages in the database */
30793 Pgno dbOrigSize; /* dbSize before the current transaction */
30794 Pgno dbFileSize; /* Number of pages in the database file */
30795 u32 vfsFlags; /* Flags for sqlite3_vfs.xOpen() */
30796 int errCode; /* One of several kinds of errors */
 
 
 
30797 int nRec; /* Number of pages written to the journal */
30798 u32 cksumInit; /* Quasi-random value added to every checksum */
30799 int stmtNRec; /* Number of records in stmt subjournal */
30800 int nExtra; /* Add this many bytes to each in-memory page */
30801 int pageSize; /* Number of bytes in a page */
30802 int nPage; /* Total number of in-memory pages */
30803 int mxPage; /* Maximum number of pages to hold in cache */
30804 Pgno mxPgno; /* Maximum allowed size of the database */
30805 Bitvec *pInJournal; /* One bit for each page in the database file */
 
30806 Bitvec *pAlwaysRollback; /* One bit for each page marked always-rollback */
30807 char *zFilename; /* Name of the database file */
30808 char *zJournal; /* Name of the journal file */
30809 char *zDirectory; /* Directory hold database and journal files */
30810 sqlite3_file *fd, *jfd; /* File descriptors for database and journal */
30811 sqlite3_file *sjfd; /* File descriptor for the sub-journal*/
30812 int (*xBusyHandler)(void*); /* Function to call when busy */
30813 void *pBusyHandlerArg; /* Context argument for xBusyHandler */
30814 i64 journalOff; /* Current byte offset in the journal file */
30815 i64 journalHdr; /* Byte offset to previous journal header */
 
 
 
30816 u32 sectorSize; /* Assumed sector size during rollback */
30817 #ifdef SQLITE_TEST
30818 int nHit, nMiss; /* Cache hits and missing */
30819 int nRead, nWrite; /* Database pages read/written */
30820 #endif
@@ -30729,10 +30825,12 @@
30825 #endif
30826 char *pTmpSpace; /* Pager.pageSize bytes of space for tmp use */
30827 char dbFileVers[16]; /* Changes whenever database file changes */
30828 i64 journalSizeLimit; /* Size limit for persistent journal files */
30829 PCache *pPCache; /* Pointer to page cache object */
30830 PagerSavepoint *aSavepoint; /* Array of active savepoints */
30831 int nSavepoint; /* Number of elements in aSavepoint[] */
30832 };
30833
30834 /*
30835 ** The following global variables hold counters used for
30836 ** testing purposes only. These variables do not exist in
@@ -30752,11 +30850,11 @@
30850 /*
30851 ** Journal files begin with the following magic string. The data
30852 ** was obtained from /dev/random. It is used only as a sanity check.
30853 **
30854 ** Since version 2.8.0, the journal format contains additional sanity
30855 ** checking information. If the power fails while the journal is being
30856 ** written, semi-random garbage data might appear in the journal
30857 ** file after power is restored. If an attempt is then made
30858 ** to roll the journal back, the database could be corrupted. The additional
30859 ** sanity checking data is an attempt to discover the garbage in the
30860 ** journal and ignore it.
@@ -30815,19 +30913,34 @@
30913 ** The maximum legal page number is (2^31 - 1).
30914 */
30915 #define PAGER_MAX_PGNO 2147483647
30916
30917 /*
30918 ** Return true if it is necessary to write page *pPg into the sub-journal.
30919 ** A page needs to be written into the sub-journal if there exists one
30920 ** or more open savepoints for which:
30921 **
30922 ** * The page-number is less than or equal to PagerSavepoint.nOrig, and
30923 ** * The bit corresponding to the page-number is not set in
30924 ** PagerSavepoint.pInSavepoint.
30925 */
30926 static int subjRequiresPage(PgHdr *pPg){
30927 Pgno pgno = pPg->pgno;
30928 Pager *pPager = pPg->pPager;
30929 int i;
30930 for(i=0; i<pPager->nSavepoint; i++){
30931 PagerSavepoint *p = &pPager->aSavepoint[i];
30932 if( p->nOrig>=pgno && 0==sqlite3BitvecTest(p->pInSavepoint, pgno) ){
30933 return 1;
30934 }
30935 }
30936 return 0;
30937 }
30938
30939 /*
30940 ** Return true if the page is already in the journal file.
30941 */
30942 static int pageInJournal(PgHdr *pPg){
30943 return sqlite3BitvecTest(pPg->pPager->pInJournal, pPg->pgno);
30944 }
30945
30946 /*
@@ -31070,20 +31183,23 @@
31183 ** 512 512
31184 ** 100 512
31185 ** 2000 2048
31186 **
31187 */
31188 static i64 journalHdrOffset(Pager *pPager){
31189 i64 offset = 0;
31190 i64 c = pPager->journalOff;
31191 if( c ){
31192 offset = ((c-1)/JOURNAL_HDR_SZ(pPager) + 1) * JOURNAL_HDR_SZ(pPager);
31193 }
31194 assert( offset%JOURNAL_HDR_SZ(pPager)==0 );
31195 assert( offset>=c );
31196 assert( (offset-c)<JOURNAL_HDR_SZ(pPager) );
31197 return offset;
31198 }
31199 static void seekJournalHdr(Pager *pPager){
31200 pPager->journalOff = journalHdrOffset(pPager);
31201 }
31202
31203 /*
31204 ** Write zeros over the header of the journal file. This has the
31205 ** effect of invalidating the journal file and committing the
@@ -31141,17 +31257,24 @@
31257 static int writeJournalHdr(Pager *pPager){
31258 int rc = SQLITE_OK;
31259 char *zHeader = pPager->pTmpSpace;
31260 u32 nHeader = pPager->pageSize;
31261 u32 nWrite;
31262 int ii;
31263
31264 if( nHeader>JOURNAL_HDR_SZ(pPager) ){
31265 nHeader = JOURNAL_HDR_SZ(pPager);
31266 }
31267
31268 /* If there are active savepoints and any of them were created since the
31269 ** most recent journal header was written, update the PagerSavepoint.iHdrOff
31270 ** fields now.
31271 */
31272 for(ii=0; ii<pPager->nSavepoint; ii++){
31273 if( pPager->aSavepoint[ii].iHdrOffset==0 ){
31274 pPager->aSavepoint[ii].iHdrOffset = pPager->journalOff;
31275 }
31276 }
31277
31278 seekJournalHdr(pPager);
31279 pPager->journalHdr = pPager->journalOff;
31280
@@ -31188,11 +31311,11 @@
31311
31312 /* The random check-hash initialiser */
31313 sqlite3_randomness(sizeof(pPager->cksumInit), &pPager->cksumInit);
31314 put32bits(&zHeader[sizeof(aJournalMagic)+4], pPager->cksumInit);
31315 /* The initial database size */
31316 put32bits(&zHeader[sizeof(aJournalMagic)+8], pPager->dbOrigSize);
31317 /* The assumed sector size for this process */
31318 put32bits(&zHeader[sizeof(aJournalMagic)+12], pPager->sectorSize);
31319
31320 /* Initializing the tail of the buffer is not necessary. Everything
31321 ** works find if the following memset() is omitted. But initializing
@@ -31217,21 +31340,22 @@
31340 }
31341
31342 /*
31343 ** The journal file must be open when this is called. A journal header file
31344 ** (JOURNAL_HDR_SZ bytes) is read from the current location in the journal
31345 ** file. The current location in the journal file is given by
31346 ** pPager->journalOff. See comments above function writeJournalHdr() for
31347 ** a description of the journal header format.
31348 **
31349 ** If the header is read successfully, *nRec is set to the number of
31350 ** page records following this header and *dbSize is set to the size of the
31351 ** database before the transaction began, in pages. Also, pPager->cksumInit
31352 ** is set to the value read from the journal header. SQLITE_OK is returned
31353 ** in this case.
31354 **
31355 ** If the journal header file appears to be corrupted, SQLITE_DONE is
31356 ** returned and *nRec and *dbSize are undefined. If JOURNAL_HDR_SZ bytes
31357 ** cannot be read from the journal file an error code is returned.
31358 */
31359 static int readJournalHdr(
31360 Pager *pPager,
31361 i64 journalSize,
@@ -31394,10 +31518,47 @@
31518 */
31519 static void pager_reset(Pager *pPager){
31520 if( pPager->errCode ) return;
31521 sqlite3PcacheClear(pPager->pPCache);
31522 }
31523
31524 /*
31525 ** Free all structures in the Pager.aSavepoint[] array and set both
31526 ** Pager.aSavepoint and Pager.nSavepoint to zero. Close the sub-journal
31527 ** if it is open and the pager is not in exclusive mode.
31528 */
31529 static void releaseAllSavepoint(Pager *pPager){
31530 int ii;
31531 for(ii=0; ii<pPager->nSavepoint; ii++){
31532 sqlite3BitvecDestroy(pPager->aSavepoint[ii].pInSavepoint);
31533 }
31534 if( !pPager->exclusiveMode ){
31535 sqlite3OsClose(pPager->sjfd);
31536 }
31537 sqlite3_free(pPager->aSavepoint);
31538 pPager->aSavepoint = 0;
31539 pPager->nSavepoint = 0;
31540 pPager->stmtNRec = 0;
31541 }
31542
31543 /*
31544 ** Set the bit number pgno in the PagerSavepoint.pInSavepoint bitvecs of
31545 ** all open savepoints.
31546 */
31547 static int addToSavepointBitvecs(Pager *pPager, Pgno pgno){
31548 int ii; /* Loop counter */
31549 int rc = SQLITE_OK; /* Result code */
31550
31551 for(ii=0; ii<pPager->nSavepoint; ii++){
31552 PagerSavepoint *p = &pPager->aSavepoint[ii];
31553 if( pgno<=p->nOrig ){
31554 rc |= sqlite3BitvecSet(p->pInSavepoint, pgno);
31555 assert( rc==SQLITE_OK || rc==SQLITE_NOMEM );
31556 }
31557 }
31558 return rc;
31559 }
31560
31561 /*
31562 ** Unlock the database file.
31563 **
31564 ** If the pager is currently in error state, discard the contents of
@@ -31431,21 +31592,14 @@
31592 ** cache can be discarded and the error code safely cleared.
31593 */
31594 if( pPager->errCode ){
31595 if( rc==SQLITE_OK ) pPager->errCode = SQLITE_OK;
31596 pager_reset(pPager);
31597 releaseAllSavepoint(pPager);
 
 
 
 
 
 
31598 pPager->journalOff = 0;
31599 pPager->journalStarted = 0;
31600 pPager->dbOrigSize = 0;
 
31601 }
31602
31603 pPager->state = PAGER_UNLOCK;
31604 pPager->changeCountDone = 0;
31605 }
@@ -31486,15 +31640,11 @@
31640 int rc = SQLITE_OK;
31641 int rc2 = SQLITE_OK;
31642 if( pPager->state<PAGER_RESERVED ){
31643 return SQLITE_OK;
31644 }
31645 releaseAllSavepoint(pPager);
 
 
 
 
31646 if( pPager->journalOpen ){
31647 if( pPager->journalMode==PAGER_JOURNALMODE_MEMORY ){
31648 int isMemoryJournal = sqlite3IsMemJournal(pPager->jfd);
31649 sqlite3OsClose(pPager->jfd);
31650 pPager->journalOpen = 0;
@@ -31538,14 +31688,15 @@
31688 rc2 = osUnlock(pPager->fd, SHARED_LOCK);
31689 pPager->state = PAGER_SHARED;
31690 }else if( pPager->state==PAGER_SYNCED ){
31691 pPager->state = PAGER_EXCLUSIVE;
31692 }
31693 pPager->dbOrigSize = 0;
31694 pPager->setMaster = 0;
31695 pPager->needSync = 0;
31696 /* lruListSetFirstSynced(pPager); */
31697 sqlite3PcacheTruncate(pPager->pPCache, pPager->dbSize);
31698 if( !MEMDB ){
31699 pPager->dbSizeValid = 0;
31700 }
31701 pPager->dbModified = 0;
31702
@@ -31581,59 +31732,75 @@
31732 }
31733 return cksum;
31734 }
31735
31736 /*
31737 ** Read a single page from either the journal file (if isMainJrnl==1) or
31738 ** from the sub-journal (if isMainJrnl==0) and playback that page.
31739 ** The page begins at offset *pOffset into the file. The *pOffset
31740 ** value is increased to the start of the next page in the journal.
31741 **
31742 ** The isMainJrnl flag is true if this is the main rollback journal and
31743 ** false for the statement journal. The main rollback journal uses
31744 ** checksums - the statement journal does not.
31745 **
31746 ** If pDone is not NULL, then it is a record of pages that have already
31747 ** been played back. If the page at *pOffset has already been played back
31748 ** (if the corresponding pDone bit is set) then skip the playback.
31749 ** Make sure the pDone bit corresponding to the *pOffset page is set
31750 ** prior to returning.
31751 */
31752 static int pager_playback_one_page(
31753 Pager *pPager, /* The pager being played back */
31754 int isMainJrnl, /* 1 -> main journal. 0 -> sub-journal. */
31755 i64 *pOffset, /* Offset of record to playback */
31756 int isSavepnt, /* True for a savepoint rollback */
31757 Bitvec *pDone /* Bitvec of pages already played back */
31758 ){
31759 int rc;
31760 PgHdr *pPg; /* An existing page in the cache */
31761 Pgno pgno; /* The page number of a page in journal */
31762 u32 cksum; /* Checksum used for sanity checking */
31763 u8 *aData; /* Temporary storage for the page */
31764 sqlite3_file *jfd; /* The file descriptor for the journal file */
31765
31766 assert( (isMainJrnl&~1)==0 ); /* isMainJrnl is 0 or 1 */
31767 assert( (isSavepnt&~1)==0 ); /* isSavepnt is 0 or 1 */
31768 assert( isMainJrnl || pDone ); /* pDone always used on sub-journals */
31769 assert( isSavepnt || pDone==0 ); /* pDone never used on non-savepoint */
31770
31771 aData = (u8*)pPager->pTmpSpace;
31772 assert( aData ); /* Temp storage must have already been allocated */
31773
31774 jfd = isMainJrnl ? pPager->jfd : pPager->sjfd;
31775
31776 rc = read32bits(jfd, *pOffset, &pgno);
31777 if( rc!=SQLITE_OK ) return rc;
31778 rc = sqlite3OsRead(jfd, aData, pPager->pageSize, (*pOffset)+4);
31779 if( rc!=SQLITE_OK ) return rc;
31780 *pOffset += pPager->pageSize + 4 + isMainJrnl*4;
31781
31782 /* Sanity checking on the page. This is more important that I originally
31783 ** thought. If a power failure occurs while the journal is being written,
31784 ** it could cause invalid data to be written into the journal. We need to
31785 ** detect this invalid data (with high probability) and ignore it.
31786 */
31787 if( pgno==0 || pgno==PAGER_MJ_PGNO(pPager) ){
31788 return SQLITE_DONE;
31789 }
31790 if( pgno>(Pgno)pPager->dbSize || sqlite3BitvecTest(pDone, pgno) ){
31791 return SQLITE_OK;
31792 }
31793 if( isMainJrnl ){
31794 rc = read32bits(jfd, (*pOffset)-4, &cksum);
31795 if( rc ) return rc;
31796 if( !isSavepnt && pager_cksum(pPager, aData)!=cksum ){
 
31797 return SQLITE_DONE;
31798 }
31799 }
31800 if( pDone && (rc = sqlite3BitvecSet(pDone, pgno)) ){
31801 return rc;
31802 }
31803
31804 assert( pPager->state==PAGER_RESERVED || pPager->state>=PAGER_EXCLUSIVE );
31805
31806 /* If the pager is in RESERVED state, then there must be a copy of this
@@ -31667,18 +31834,46 @@
31834 ** 2008-04-14: When attempting to vacuum a corrupt database file, it
31835 ** is possible to fail a statement on a database that does not yet exist.
31836 ** Do not attempt to write if database file has never been opened.
31837 */
31838 pPg = pager_lookup(pPager, pgno);
31839 PAGERTRACE(("PLAYBACK %d page %d hash(%08x) %s\n",
31840 PAGERID(pPager), pgno, pager_datahash(pPager->pageSize, aData),
31841 (isMainJrnl?"main-journal":"sub-journal")
31842 ));
31843 if( (pPager->state>=PAGER_EXCLUSIVE)
31844 && (pPg==0 || 0==(pPg->flags&PGHDR_NEED_SYNC))
31845 && (pPager->fd->pMethods)
31846 ){
31847 i64 ofst = (pgno-1)*(i64)pPager->pageSize;
31848 rc = sqlite3OsWrite(pPager->fd, aData, pPager->pageSize, ofst);
31849 if( pgno>pPager->dbFileSize ){
31850 pPager->dbFileSize = pgno;
31851 }
31852 }else if( !isMainJrnl && pPg==0 ){
31853 /* If this is a rollback of a savepoint and data was not written to
31854 ** the database and the page is not in-memory, there is a potential
31855 ** problem. When the page is next fetched by the b-tree layer, it
31856 ** will be read from the database file, which may or may not be
31857 ** current.
31858 **
31859 ** There are a couple of different ways this can happen. All are quite
31860 ** obscure. When running in synchronous mode, this can only happen
31861 ** if the page is on the free-list at the start of the transaction, then
31862 ** populated, then moved using sqlite3PagerMovepage().
31863 **
31864 ** The solution is to add an in-memory page to the cache containing
31865 ** the data just read from the sub-journal. Mark the page as dirty
31866 ** and if the pager requires a journal-sync, then mark the page as
31867 ** requiring a journal-sync before it is written.
31868 */
31869 assert( isSavepnt );
31870 if( (rc = sqlite3PagerAcquire(pPager, pgno, &pPg, 1)) ){
31871 return rc;
31872 }
31873 pPg->flags &= ~PGHDR_NEED_READ;
31874 sqlite3PcacheMakeDirty(pPg);
31875 }
31876 if( pPg ){
31877 /* No page should ever be explicitly rolled back that is in use, except
31878 ** for page 1 which is held in use in order to keep the lock on the
31879 ** database active. However such a page may be rolled back as a result
@@ -31689,11 +31884,29 @@
31884 pData = pPg->pData;
31885 memcpy(pData, aData, pPager->pageSize);
31886 if( pPager->xReiniter ){
31887 pPager->xReiniter(pPg);
31888 }
31889 if( isMainJrnl && (!isSavepnt || pPager->journalOff<=pPager->journalHdr) ){
31890 /* If the contents of this page were just restored from the main
31891 ** journal file, then its content must be as they were when the
31892 ** transaction was first opened. In this case we can mark the page
31893 ** as clean, since there will be no need to write it out to the.
31894 **
31895 ** There is one exception to this rule. If the page is being rolled
31896 ** back as part of a savepoint (or statement) rollback from an
31897 ** unsynced portion of the main journal file, then it is not safe
31898 ** to mark the page as clean. This is because marking the page as
31899 ** clean will clear the PGHDR_NEED_SYNC flag. Since the page is
31900 ** already in the journal file (recorded in Pager.pInJournal) and
31901 ** the PGHDR_NEED_SYNC flag is cleared, if the page is written to
31902 ** again within this transaction, it will be marked as dirty but
31903 ** the PGHDR_NEED_SYNC flag will not be set. It could then potentially
31904 ** be written out into the database file before its journal file
31905 ** segment is synced. If a crash occurs during or following this,
31906 ** database corruption may ensue.
31907 */
31908 sqlite3PcacheMakeClean(pPg);
31909 }
31910 #ifdef SQLITE_CHECK_PAGES
31911 pPg->pageHash = pager_pagehash(pPg);
31912 #endif
@@ -31708,10 +31921,50 @@
31921 sqlite3PcacheRelease(pPg);
31922 }
31923 return rc;
31924 }
31925
31926 #if !defined(NDEBUG) || defined(SQLITE_COVERAGE_TEST)
31927 /*
31928 ** This routine looks ahead into the main journal file and determines
31929 ** whether or not the next record (the record that begins at file
31930 ** offset pPager->journalOff) is a well-formed page record consisting
31931 ** of a valid page number, pPage->pageSize bytes of content, followed
31932 ** by a valid checksum.
31933 **
31934 ** The pager never needs to know this in order to do its job. This
31935 ** routine is only used from with assert() and testcase() macros.
31936 */
31937 static int pagerNextJournalPageIsValid(Pager *pPager){
31938 Pgno pgno; /* The page number of the page */
31939 u32 cksum; /* The page checksum */
31940 int rc; /* Return code from read operations */
31941 sqlite3_file *fd; /* The file descriptor from which we are reading */
31942 u8 *aData; /* Content of the page */
31943
31944 /* Read the page number header */
31945 fd = pPager->jfd;
31946 rc = read32bits(fd, pPager->journalOff, &pgno);
31947 if( rc!=SQLITE_OK ){ return 0; } /*NO_TEST*/
31948 if( pgno==0 || pgno==PAGER_MJ_PGNO(pPager) ){ return 0; } /*NO_TEST*/
31949 if( pgno>(Pgno)pPager->dbSize ){ return 0; } /*NO_TEST*/
31950
31951 /* Read the checksum */
31952 rc = read32bits(fd, pPager->journalOff+pPager->pageSize+4, &cksum);
31953 if( rc!=SQLITE_OK ){ return 0; } /*NO_TEST*/
31954
31955 /* Read the data and verify the checksum */
31956 aData = (u8*)pPager->pTmpSpace;
31957 rc = sqlite3OsRead(fd, aData, pPager->pageSize, pPager->journalOff+4);
31958 if( rc!=SQLITE_OK ){ return 0; } /*NO_TEST*/
31959 if( pager_cksum(pPager, aData)!=cksum ){ return 0; } /*NO_TEST*/
31960
31961 /* Reach this point only if the page is valid */
31962 return 1;
31963 }
31964 #endif /* !defined(NDEBUG) || defined(SQLITE_COVERAGE_TEST) */
31965
31966 /*
31967 ** Parameter zMaster is the name of a master journal file. A single journal
31968 ** file that referred to the master journal file has just been rolled back.
31969 ** This routine checks if it is possible to delete the master journal file,
31970 ** and does so if it is.
@@ -31815,17 +32068,16 @@
32068 sqlite3_free(pMaster);
32069 return rc;
32070 }
32071
32072
 
 
32073 /*
32074 ** If the main database file is open and an exclusive lock is held,
32075 ** truncate the main file of the given pager to the specified number
32076 ** of pages.
32077 **
32078 ** It might might be the case that the file on disk is smaller than nPage.
32079 ** This can happen, for example, if we are in the middle of a transaction
32080 ** which has extended the file size and the new pages are still all held
32081 ** in cache, then an INSERT or UPDATE does a statement rollback. Some
32082 ** operating system implementations can get confused if you try to
32083 ** truncate a file to some size that is larger than it currently is,
@@ -31842,16 +32094,15 @@
32094 if( currentSize>newSize ){
32095 rc = sqlite3OsTruncate(pPager->fd, newSize);
32096 }else{
32097 rc = sqlite3OsWrite(pPager->fd, "", 1, newSize-1);
32098 }
32099 if( rc==SQLITE_OK ){
32100 pPager->dbFileSize = nPage;
32101 }
32102 }
32103 }
 
 
 
 
32104 return rc;
32105 }
32106
32107 /*
32108 ** Set the sectorSize for the given pager.
@@ -31996,11 +32247,22 @@
32247 ** that this part of the journal was being filled but has not yet been
32248 ** synced to disk. Compute the number of pages based on the remaining
32249 ** size of the file.
32250 **
32251 ** The third term of the test was added to fix ticket #2565.
32252 ** When rolling back a hot journal, nRec==0 always means that the next
32253 ** chunk of the journal contains zero pages to be rolled back. But
32254 ** when doing a ROLLBACK and the nRec==0 chunk is the last chunk in
32255 ** the journal, it means that the journal might contain additional
32256 ** pages that need to be rolled back and that the number of pages
32257 ** should be computed based on the journal file size.
32258 */
32259 testcase( nRec==0 && !isHot
32260 && pPager->journalHdr+JOURNAL_HDR_SZ(pPager)!=pPager->journalOff
32261 && ((szJ - pPager->journalOff) / JOURNAL_PG_SZ(pPager))>0
32262 && pagerNextJournalPageIsValid(pPager)
32263 );
32264 if( nRec==0 && !isHot &&
32265 pPager->journalHdr+JOURNAL_HDR_SZ(pPager)==pPager->journalOff ){
32266 nRec = (int)((szJ - pPager->journalOff) / JOURNAL_PG_SZ(pPager));
32267 }
32268
@@ -32010,16 +32272,17 @@
32272 if( pPager->journalOff==JOURNAL_HDR_SZ(pPager) ){
32273 rc = pager_truncate(pPager, mxPg);
32274 if( rc!=SQLITE_OK ){
32275 goto end_playback;
32276 }
32277 pPager->dbSize = mxPg;
32278 }
32279
32280 /* Copy original pages out of the journal and back into the database file.
32281 */
32282 for(u=0; u<nRec; u++){
32283 rc = pager_playback_one_page(pPager, 1, &pPager->journalOff, 0, 0);
32284 if( rc!=SQLITE_OK ){
32285 if( rc==SQLITE_DONE ){
32286 rc = SQLITE_OK;
32287 pPager->journalOff = szJ;
32288 break;
@@ -32059,105 +32322,111 @@
32322 setSectorSize(pPager);
32323 return rc;
32324 }
32325
32326 /*
32327 ** Playback savepoint pSavepoint. Or, if pSavepoint==NULL, then playback
32328 ** the entire master journal file.
32329 **
32330 ** The case pSavepoint==NULL occurs when a ROLLBACK TO command is invoked
32331 ** on a SAVEPOINT that is a transaction savepoint.
32332 */
32333 static int pagerPlaybackSavepoint(Pager *pPager, PagerSavepoint *pSavepoint){
32334 i64 szJ; /* Effective size of the main journal */
32335 i64 iHdrOff; /* End of first segment of main-journal records */
32336 Pgno ii; /* Loop counter */
32337 int rc = SQLITE_OK; /* Return code */
32338 Bitvec *pDone = 0; /* Bitvec to ensure pages played back only once */
32339
32340 /* Allocate a bitvec to use to store the set of pages rolled back */
32341 if( pSavepoint ){
32342 pDone = sqlite3BitvecCreate(pSavepoint->nOrig);
32343 if( !pDone ){
32344 return SQLITE_NOMEM;
32345 }
32346 }
32347
32348 /* Truncate the database back to the size it was before the
32349 ** savepoint being reverted was opened.
32350 */
32351 pPager->dbSize = pSavepoint ? pSavepoint->nOrig : pPager->dbOrigSize;
 
 
 
 
 
 
 
 
 
 
 
32352 assert( pPager->state>=PAGER_SHARED );
32353
32354 /* Use pPager->journalOff as the effective size of the main rollback
32355 ** journal. The actual file might be larger than this in
32356 ** PAGER_JOURNALMODE_TRUNCATE or PAGER_JOURNALMODE_PERSIST. But anything
32357 ** past pPager->journalOff is off-limits to us.
32358 */
32359 szJ = pPager->journalOff;
32360
32361 /* Begin by rolling back records from the main journal starting at
32362 ** PagerSavepoint.iOffset and continuing to the next journal header.
32363 ** There might be records in the main journal that have a page number
32364 ** greater than the current database size (pPager->dbSize) but those
32365 ** will be skipped automatically. Pages are added to pDone as they
32366 ** are played back.
32367 */
32368 if( pSavepoint ){
32369 iHdrOff = pSavepoint->iHdrOffset ? pSavepoint->iHdrOffset : szJ;
32370 pPager->journalOff = pSavepoint->iOffset;
32371 while( rc==SQLITE_OK && pPager->journalOff<iHdrOff ){
32372 rc = pager_playback_one_page(pPager, 1, &pPager->journalOff, 1, pDone);
32373 assert( rc!=SQLITE_DONE );
32374 }
32375 }else{
32376 pPager->journalOff = 0;
32377 }
32378
32379 /* Continue rolling back records out of the main journal starting at
32380 ** the first journal header seen and continuing until the effective end
32381 ** of the main journal file. Continue to skip out-of-range pages and
32382 ** continue adding pages rolled back to pDone.
32383 */
32384 while( rc==SQLITE_OK && pPager->journalOff<szJ ){
32385 u32 nJRec = 0; /* Number of Journal Records */
 
 
 
32386 u32 dummy;
32387 rc = readJournalHdr(pPager, szJ, &nJRec, &dummy);
32388 assert( rc!=SQLITE_DONE );
32389
32390 /*
32391 ** The "pPager->journalHdr+JOURNAL_HDR_SZ(pPager)==pPager->journalOff"
32392 ** test is related to ticket #2565. See the discussion in the
32393 ** pager_playback() function for additional information.
32394 */
32395 assert( !(nJRec==0
32396 && pPager->journalHdr+JOURNAL_HDR_SZ(pPager)!=pPager->journalOff
32397 && ((szJ - pPager->journalOff) / JOURNAL_PG_SZ(pPager))>0
32398 && pagerNextJournalPageIsValid(pPager))
32399 );
32400 if( nJRec==0
32401 && pPager->journalHdr+JOURNAL_HDR_SZ(pPager)==pPager->journalOff
32402 ){
32403 nJRec = (szJ - pPager->journalOff)/JOURNAL_PG_SZ(pPager);
32404 }
32405 for(ii=0; rc==SQLITE_OK && ii<nJRec && pPager->journalOff<szJ; ii++){
32406 rc = pager_playback_one_page(pPager, 1, &pPager->journalOff, 1, pDone);
32407 assert( rc!=SQLITE_DONE );
32408 }
32409 }
32410 assert( rc!=SQLITE_OK || pPager->journalOff==szJ );
32411
32412 /* Finally, rollback pages from the sub-journal. Page that were
32413 ** previously rolled back out of the main journal (and are hence in pDone)
32414 ** will be skipped. Out-of-range pages are also skipped.
32415 */
32416 if( pSavepoint ){
32417 i64 offset = pSavepoint->iSubRec*(4+pPager->pageSize);
32418 for(ii=pSavepoint->iSubRec; rc==SQLITE_OK&&ii<(u32)pPager->stmtNRec; ii++){
32419 assert( offset == ii*(4+pPager->pageSize) );
32420 rc = pager_playback_one_page(pPager, 0, &offset, 1, pDone);
32421 assert( rc!=SQLITE_DONE );
32422 }
32423 }
32424
32425 sqlite3BitvecDestroy(pDone);
32426 if( rc==SQLITE_OK ){
32427 pPager->journalOff = szJ;
32428 }
32429 return rc;
32430 }
32431
32432 /*
@@ -32325,11 +32594,11 @@
32594 }
32595 pPager->pPCache = (PCache *)&pPager[1];
32596 pPtr = ((u8 *)&pPager[1]) + pcacheSize;
32597 pPager->vfsFlags = vfsFlags;
32598 pPager->fd = (sqlite3_file*)&pPtr[pVfs->szOsFile*0];
32599 pPager->sjfd = (sqlite3_file*)&pPtr[pVfs->szOsFile];
32600 pPager->jfd = (sqlite3_file*)&pPtr[pVfs->szOsFile+journalFileSize];
32601 pPager->zFilename = (char*)&pPtr[pVfs->szOsFile+2*journalFileSize];
32602 pPager->zDirectory = &pPager->zFilename[nPathname+1];
32603 pPager->zJournal = &pPager->zDirectory[nPathname+1];
32604 pPager->pVfs = pVfs;
@@ -32408,11 +32677,11 @@
32677 }
32678 nExtra = FORCE_ALIGNMENT(nExtra);
32679 sqlite3PcacheOpen(szPageDflt, nExtra, !memDb,
32680 !memDb?pagerStress:0, (void *)pPager, pPager->pPCache);
32681
32682 PAGERTRACE(("OPEN %d %s\n", FILEHANDLEID(pPager->fd), pPager->zFilename));
32683 IOTRACE(("OPEN %p %s\n", pPager, pPager->zFilename))
32684
32685 /* Fill in Pager.zDirectory[] */
32686 memcpy(pPager->zDirectory, pPager->zFilename, nPathname+1);
32687 for(i=sqlite3Strlen30(pPager->zDirectory);
@@ -32630,11 +32899,12 @@
32899 n = 1;
32900 }else{
32901 n /= pPager->pageSize;
32902 }
32903 if( pPager->state!=PAGER_UNLOCK ){
32904 pPager->dbSize = (Pgno)n;
32905 pPager->dbFileSize = (Pgno)n;
32906 pPager->dbSizeValid = 1;
32907 }
32908 }
32909 if( n==(PENDING_BYTE/pPager->pageSize) ){
32910 n++;
@@ -32651,26 +32921,10 @@
32921 /*
32922 ** Forward declaration
32923 */
32924 static int syncJournal(Pager*);
32925
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
32926 /*
32927 ** Try to obtain a lock on a file. Invoke the busy callback if the lock
32928 ** is currently not available. Repeat until the busy callback returns
32929 ** false or until the lock succeeds.
32930 **
@@ -32700,33 +32954,38 @@
32954 }
32955 }
32956 return rc;
32957 }
32958
32959 #ifndef SQLITE_OMIT_AUTOVACUUM
32960 /*
32961 ** Truncate the in-memory database file image to nPage pages. This
32962 ** function does not actually modify the database file on disk. It
32963 ** just sets the internal state of the pager object so that the
32964 ** truncation will be done when the current transaction is committed.
32965 */
32966 SQLITE_PRIVATE void sqlite3PagerTruncateImage(Pager *pPager, Pgno nPage){
32967 assert( pPager->dbSizeValid );
32968 assert( pPager->dbSize>=nPage );
32969 pPager->dbSize = nPage;
32970 }
32971
32972 /*
32973 ** Return the current size of the database file image in pages. This
32974 ** function differs from sqlite3PagerPagecount() in two ways:
32975 **
32976 ** a) It may only be called when at least one reference to a database
32977 ** page is held. This guarantees that the database size is already
32978 ** known and a call to sqlite3OsFileSize() is not required.
32979 **
32980 ** b) The return value is not adjusted for the locking page.
32981 */
32982 SQLITE_PRIVATE Pgno sqlite3PagerImageSize(Pager *pPager){
32983 assert( pPager->dbSizeValid );
32984 return pPager->dbSize;
32985 }
32986 #endif /* ifndef SQLITE_OMIT_AUTOVACUUM */
32987
32988 /*
32989 ** Shutdown the page cache. Free all memory and close all files.
32990 **
32991 ** If a transaction was in progress when this routine is called, that
@@ -32746,24 +33005,29 @@
33005 sqlite3BeginBenignMalloc();
33006 pPager->errCode = 0;
33007 pPager->exclusiveMode = 0;
33008 pager_reset(pPager);
33009 if( !MEMDB ){
33010 /* Set Pager.journalHdr to -1 for the benefit of the pager_playback()
33011 ** call which may be made from within pagerUnlockAndRollback(). If it
33012 ** is not -1, then the unsynced portion of an open journal file may
33013 ** be played back into the database. If a power failure occurs while
33014 ** this is happening, the database may become corrupt.
33015 */
33016 pPager->journalHdr = -1;
33017 pagerUnlockAndRollback(pPager);
33018 }
33019 enable_simulated_io_errors();
33020 sqlite3EndBenignMalloc();
33021 PAGERTRACE(("CLOSE %d\n", PAGERID(pPager)));
33022 IOTRACE(("CLOSE %p\n", pPager))
33023 if( pPager->journalOpen ){
33024 sqlite3OsClose(pPager->jfd);
33025 }
33026 sqlite3BitvecDestroy(pPager->pInJournal);
33027 sqlite3BitvecDestroy(pPager->pAlwaysRollback);
33028 releaseAllSavepoint(pPager);
 
 
33029 sqlite3OsClose(pPager->fd);
33030 /* Temp files are automatically deleted by the OS
33031 ** if( pPager->tempFile ){
33032 ** sqlite3OsDelete(pPager->zFilename);
33033 ** }
@@ -32829,10 +33093,39 @@
33093 if( pPager->journalMode!=PAGER_JOURNALMODE_MEMORY ){
33094 int iDc = sqlite3OsDeviceCharacteristics(pPager->fd);
33095 assert( pPager->journalOpen );
33096
33097 if( 0==(iDc&SQLITE_IOCAP_SAFE_APPEND) ){
33098 i64 jrnlOff = journalHdrOffset(pPager);
33099 u8 zMagic[8];
33100
33101 /* This block deals with an obscure problem. If the last connection
33102 ** that wrote to this database was operating in persistent-journal
33103 ** mode, then the journal file may at this point actually be larger
33104 ** than Pager.journalOff bytes. If the next thing in the journal
33105 ** file happens to be a journal-header (written as part of the
33106 ** previous connections transaction), and a crash or power-failure
33107 ** occurs after nRec is updated but before this connection writes
33108 ** anything else to the journal file (or commits/rolls back its
33109 ** transaction), then SQLite may become confused when doing the
33110 ** hot-journal rollback following recovery. It may roll back all
33111 ** of this connections data, then proceed to rolling back the old,
33112 ** out-of-date data that follows it. Database corruption.
33113 **
33114 ** To work around this, if the journal file does appear to contain
33115 ** a valid header following Pager.journalOff, then write a 0x00
33116 ** byte to the start of it to prevent it from being recognized.
33117 */
33118 rc = sqlite3OsRead(pPager->jfd, zMagic, 8, jrnlOff);
33119 if( rc==SQLITE_OK && 0==memcmp(zMagic, aJournalMagic, 8) ){
33120 static const u8 zerobyte = 0;
33121 rc = sqlite3OsWrite(pPager->jfd, &zerobyte, 1, jrnlOff);
33122 }
33123 if( rc!=SQLITE_OK && rc!=SQLITE_IOERR_SHORT_READ ){
33124 return rc;
33125 }
33126
33127 /* Write the nRec value into the journal file header. If in
33128 ** full-synchronous mode, sync the journal first. This ensures that
33129 ** all data has really hit the disk before nRec is updated to mark
33130 ** it as a candidate for rollback.
33131 **
@@ -32840,13 +33133,12 @@
33133 ** SAFE_APPEND property. Because in this case it is not possible
33134 ** for garbage data to be appended to the file, the nRec field
33135 ** is populated with 0xFFFFFFFF when the journal header is written
33136 ** and never needs to be updated.
33137 */
 
33138 if( pPager->fullSync && 0==(iDc&SQLITE_IOCAP_SEQUENTIAL) ){
33139 PAGERTRACE(("SYNC journal of %d\n", PAGERID(pPager)));
33140 IOTRACE(("JSYNC %p\n", pPager))
33141 rc = sqlite3OsSync(pPager->jfd, pPager->sync_flags);
33142 if( rc!=0 ) return rc;
33143 }
33144
@@ -32854,11 +33146,11 @@
33146 IOTRACE(("JHDR %p %lld %d\n", pPager, jrnlOff, 4));
33147 rc = write32bits(pPager->jfd, jrnlOff, pPager->nRec);
33148 if( rc ) return rc;
33149 }
33150 if( 0==(iDc&SQLITE_IOCAP_SEQUENTIAL) ){
33151 PAGERTRACE(("SYNC journal of %d\n", PAGERID(pPager)));
33152 IOTRACE(("JSYNC %p\n", pPager))
33153 rc = sqlite3OsSync(pPager->jfd, pPager->sync_flags|
33154 (pPager->sync_flags==SQLITE_SYNC_FULL?SQLITE_SYNC_DATAONLY:0)
33155 );
33156 if( rc!=0 ) return rc;
@@ -32918,30 +33210,34 @@
33210 rc = sqlite3PagerOpentemp(pPager, pPager->fd, pPager->vfsFlags);
33211 if( rc ) return rc;
33212 }
33213
33214 /* If there are dirty pages in the page cache with page numbers greater
33215 ** than Pager.dbSize, this means sqlite3PagerTruncateImage() was called to
33216 ** make the file smaller (presumably by auto-vacuum code). Do not write
33217 ** any such pages to the file.
33218 */
33219 if( pList->pgno<=pPager->dbSize && 0==(pList->flags&PGHDR_DONT_WRITE) ){
33220 i64 offset = (pList->pgno-1)*(i64)pPager->pageSize;
33221 char *pData = CODEC2(pPager, pList->pData, pList->pgno, 6);
33222
33223 PAGERTRACE(("STORE %d page %d hash(%08x)\n",
33224 PAGERID(pPager), pList->pgno, pager_pagehash(pList)));
33225 IOTRACE(("PGOUT %p %d\n", pPager, pList->pgno));
33226 rc = sqlite3OsWrite(pPager->fd, pData, pPager->pageSize, offset);
33227 PAGER_INCR(sqlite3_pager_writedb_count);
33228 PAGER_INCR(pPager->nWrite);
33229 if( pList->pgno==1 ){
33230 memcpy(&pPager->dbFileVers, &pData[24], sizeof(pPager->dbFileVers));
33231 }
33232 if( pList->pgno>pPager->dbFileSize ){
33233 pPager->dbFileSize = pList->pgno;
33234 }
33235 }
33236 #ifndef NDEBUG
33237 else{
33238 PAGERTRACE(("NOSTORE %d page %d\n", PAGERID(pPager), pList->pgno));
33239 }
33240 #endif
33241 if( rc ) return rc;
33242 #ifdef SQLITE_CHECK_PAGES
33243 pList->pageHash = pager_pagehash(pList);
@@ -32949,10 +33245,38 @@
33245 pList = pList->pDirty;
33246 }
33247
33248 return SQLITE_OK;
33249 }
33250
33251 /*
33252 ** Add the page to the sub-journal. It is the callers responsibility to
33253 ** use subjRequiresPage() to check that it is really required before
33254 ** calling this function.
33255 */
33256 static int subjournalPage(PgHdr *pPg){
33257 int rc;
33258 void *pData = pPg->pData;
33259 Pager *pPager = pPg->pPager;
33260 i64 offset = pPager->stmtNRec*(4+pPager->pageSize);
33261 char *pData2 = CODEC2(pPager, pData, pPg->pgno, 7);
33262
33263 PAGERTRACE(("STMT-JOURNAL %d page %d\n", PAGERID(pPager), pPg->pgno));
33264
33265 assert( pageInJournal(pPg) || pPg->pgno>pPager->dbOrigSize );
33266 rc = write32bits(pPager->sjfd, offset, pPg->pgno);
33267 if( rc==SQLITE_OK ){
33268 rc = sqlite3OsWrite(pPager->sjfd, pData2, pPager->pageSize, offset+4);
33269 }
33270 if( rc==SQLITE_OK ){
33271 pPager->stmtNRec++;
33272 assert( pPager->nSavepoint>0 );
33273 rc = addToSavepointBitvecs(pPager, pPg->pgno);
33274 }
33275 return rc;
33276 }
33277
33278
33279 /*
33280 ** This function is called by the pcache layer when it has reached some
33281 ** soft memory limit. The argument is a pointer to a purgeable Pager
33282 ** object. This function attempts to make a single dirty page that has no
@@ -32979,18 +33303,24 @@
33303 rc = writeJournalHdr(pPager);
33304 }
33305 }
33306 if( rc==SQLITE_OK ){
33307 pPg->pDirty = 0;
33308 if( pPg->pgno>pPager->dbSize && subjRequiresPage(pPg) ){
33309 rc = subjournalPage(pPg);
33310 }
33311 if( rc==SQLITE_OK ){
33312 rc = pager_write_pagelist(pPg);
33313 }
33314 }
33315 if( rc!=SQLITE_OK ){
33316 pager_error(pPager, rc);
33317 }
33318 }
33319
33320 if( rc==SQLITE_OK ){
33321 PAGERTRACE(("STRESS %d page %d\n", PAGERID(pPager), pPg->pgno));
33322 sqlite3PcacheMakeClean(pPg);
33323 }
33324 return rc;
33325 }
33326
@@ -33060,12 +33390,12 @@
33390 if( pgno==1 ){
33391 memcpy(&pPager->dbFileVers, &((u8*)pPg->pData)[24],
33392 sizeof(pPager->dbFileVers));
33393 }
33394 CODEC1(pPager, pPg->pData, pPg->pgno, 3);
33395 PAGERTRACE(("FETCH %d page %d hash(%08x)\n",
33396 PAGERID(pPager), pPg->pgno, pager_pagehash(pPg)));
33397 return rc;
33398 }
33399
33400
33401 /*
@@ -33113,12 +33443,14 @@
33443 rc = pager_wait_on_lock(pPager, SHARED_LOCK);
33444 if( rc!=SQLITE_OK ){
33445 assert( pPager->state==PAGER_UNLOCK );
33446 return pager_error(pPager, rc);
33447 }
33448 }else if( pPager->state==PAGER_UNLOCK ){
33449 pPager->state = PAGER_SHARED;
33450 }
33451 assert( pPager->state>=SHARED_LOCK );
33452
33453 /* If a journal file exists, and there is no RESERVED lock on the
33454 ** database file, then it either needs to be played back or deleted.
33455 */
33456 if( !isErrorReset ){
@@ -33183,12 +33515,15 @@
33515 pPager->journalOff = 0;
33516 pPager->setMaster = 0;
33517 pPager->journalHdr = 0;
33518
33519 /* Playback and delete the journal. Drop the database write
33520 ** lock and reacquire the read lock. Purge the cache before
33521 ** playing back the hot-journal so that we don't end up with
33522 ** an inconsistent cache.
33523 */
33524 sqlite3PcacheClear(pPager->pPCache);
33525 rc = pager_playback(pPager, 1);
33526 if( rc!=SQLITE_OK ){
33527 rc = pager_error(pPager, rc);
33528 goto failed;
33529 }
@@ -33235,14 +33570,11 @@
33570
33571 if( memcmp(pPager->dbFileVers, dbFileVers, sizeof(dbFileVers))!=0 ){
33572 pager_reset(pPager);
33573 }
33574 }
33575 assert( pPager->exclusiveMode || pPager->state==PAGER_SHARED );
 
 
 
33576 }
33577
33578 failed:
33579 if( rc!=SQLITE_OK ){
33580 /* pager_unlock() is a no-op for exclusive mode and in-memory databases. */
@@ -33458,10 +33790,31 @@
33790 sqlite3PcacheRelease(pPg);
33791 pagerUnlockIfUnused(pPager);
33792 }
33793 return SQLITE_OK;
33794 }
33795
33796 /*
33797 ** If the main journal file has already been opened, ensure that the
33798 ** sub-journal file is open too. If the main journal is not open,
33799 ** this function is a no-op.
33800 **
33801 ** SQLITE_OK is returned if everything goes according to plan. An
33802 ** SQLITE_IOERR_XXX error code is returned if the call to
33803 ** sqlite3OsOpen() fails.
33804 */
33805 static int openSubJournal(Pager *pPager){
33806 int rc = SQLITE_OK;
33807 if( pPager->journalOpen && !pPager->sjfd->pMethods ){
33808 if( pPager->journalMode==PAGER_JOURNALMODE_MEMORY ){
33809 sqlite3MemJournalOpen(pPager->sjfd);
33810 }else{
33811 rc = sqlite3PagerOpentemp(pPager, pPager->sjfd, SQLITE_OPEN_SUBJOURNAL);
33812 }
33813 }
33814 return rc;
33815 }
33816
33817 /*
33818 ** Create a journal file for pPager. There should already be a RESERVED
33819 ** or EXCLUSIVE lock on the database file when this routine is called.
33820 **
@@ -33518,16 +33871,16 @@
33871 pPager->nRec = 0;
33872 if( pPager->errCode ){
33873 rc = pPager->errCode;
33874 goto failed_to_open_journal;
33875 }
33876 pPager->dbOrigSize = pPager->dbSize;
33877
33878 rc = writeJournalHdr(pPager);
33879
33880 if( pPager->nSavepoint && rc==SQLITE_OK ){
33881 rc = openSubJournal(pPager);
33882 }
33883 if( rc!=SQLITE_OK && rc!=SQLITE_NOMEM && rc!=SQLITE_IOERR_NOMEM ){
33884 rc = pager_end_transaction(pPager, 0);
33885 if( rc==SQLITE_OK ){
33886 rc = SQLITE_FULL;
@@ -33585,11 +33938,11 @@
33938 }
33939 if( rc!=SQLITE_OK ){
33940 return rc;
33941 }
33942 pPager->dirtyCache = 0;
33943 PAGERTRACE(("TRANSACTION %d\n", PAGERID(pPager)));
33944 if( pPager->useJournal && !pPager->tempFile
33945 && pPager->journalMode!=PAGER_JOURNALMODE_OFF ){
33946 rc = pager_open_journal(pPager);
33947 }
33948 }else if( pPager->journalOpen && pPager->journalOff==0 ){
@@ -33598,18 +33951,18 @@
33951 ** by this connection. Instead of deleting the journal file it was
33952 ** kept open and either was truncated to 0 bytes or its header was
33953 ** overwritten with zeros.
33954 */
33955 assert( pPager->nRec==0 );
33956 assert( pPager->dbOrigSize==0 );
33957 assert( pPager->pInJournal==0 );
33958 sqlite3PagerPagecount(pPager, 0);
33959 pPager->pInJournal = sqlite3BitvecCreate( pPager->dbSize );
33960 if( !pPager->pInJournal ){
33961 rc = SQLITE_NOMEM;
33962 }else{
33963 pPager->dbOrigSize = pPager->dbSize;
33964 rc = writeJournalHdr(pPager);
33965 }
33966 }
33967 assert( !pPager->journalOpen || pPager->journalOff>0 || rc!=SQLITE_OK );
33968 return rc;
@@ -33665,11 +34018,11 @@
34018
34019 /* Mark the page as dirty. If the page has already been written
34020 ** to the journal then we can return right away.
34021 */
34022 sqlite3PcacheMakeDirty(pPg);
34023 if( pageInJournal(pPg) && !subjRequiresPage(pPg) ){
34024 pPager->dirtyCache = 1;
34025 pPager->dbModified = 1;
34026 }else{
34027
34028 /* If we get this far, it means that the page needs to be
@@ -33696,11 +34049,11 @@
34049 /* The transaction journal now exists and we have a RESERVED or an
34050 ** EXCLUSIVE lock on the main database file. Write the current page to
34051 ** the transaction journal if it is not there already.
34052 */
34053 if( !pageInJournal(pPg) && pPager->journalOpen ){
34054 if( pPg->pgno<=pPager->dbOrigSize ){
34055 u32 cksum;
34056 char *pData2;
34057
34058 /* We should never write to the journal file the page that
34059 ** contains the database locks. The following assert verifies
@@ -33719,13 +34072,25 @@
34072 pPager->journalOff += 4;
34073 }
34074 IOTRACE(("JOUT %p %d %lld %d\n", pPager, pPg->pgno,
34075 pPager->journalOff, pPager->pageSize));
34076 PAGER_INCR(sqlite3_pager_writej_count);
34077 PAGERTRACE(("JOURNAL %d page %d needSync=%d hash(%08x)\n",
34078 PAGERID(pPager), pPg->pgno,
34079 ((pPg->flags&PGHDR_NEED_SYNC)?1:0), pager_pagehash(pPg)));
34080
34081 /* Even if an IO or diskfull error occurred while journalling the
34082 ** page in the block above, set the need-sync flag for the page.
34083 ** Otherwise, when the transaction is rolled back, the logic in
34084 ** playback_one_page() will think that the page needs to be restored
34085 ** in the database file. And if an IO error occurs while doing so,
34086 ** then corruption may follow.
34087 */
34088 if( !pPager->noSync ){
34089 pPg->flags |= PGHDR_NEED_SYNC;
34090 pPager->needSync = 1;
34091 }
34092
34093 /* An error has occured writing to the journal file. The
34094 ** transaction will be rolled back by the layer above.
34095 */
34096 if( rc!=SQLITE_OK ){
@@ -33732,53 +34097,36 @@
34097 return rc;
34098 }
34099
34100 pPager->nRec++;
34101 assert( pPager->pInJournal!=0 );
34102 rc = sqlite3BitvecSet(pPager->pInJournal, pPg->pgno);
34103 testcase( rc==SQLITE_NOMEM );
34104 assert( rc==SQLITE_OK || rc==SQLITE_NOMEM );
34105 rc |= addToSavepointBitvecs(pPager, pPg->pgno);
34106 if( rc!=SQLITE_OK ){
34107 assert( rc==SQLITE_NOMEM );
34108 return rc;
34109 }
34110 }else{
34111 if( !pPager->journalStarted && !pPager->noSync ){
34112 pPg->flags |= PGHDR_NEED_SYNC;
34113 pPager->needSync = 1;
34114 }
34115 PAGERTRACE(("APPEND %d page %d needSync=%d\n",
34116 PAGERID(pPager), pPg->pgno,
34117 ((pPg->flags&PGHDR_NEED_SYNC)?1:0)));
 
 
 
34118 }
34119 }
34120
34121 /* If the statement journal is open and the page is not in it,
34122 ** then write the current page to the statement journal. Note that
34123 ** the statement journal format differs from the standard journal format
34124 ** in that it omits the checksums and the header.
34125 */
34126 if( subjRequiresPage(pPg) ){
34127 rc = subjournalPage(pPg);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
34128 }
34129 }
34130
34131 /* Update the database size and return.
34132 */
@@ -33849,10 +34197,11 @@
34197 rc = sqlite3PagerGet(pPager, pg, &pPage);
34198 if( rc==SQLITE_OK ){
34199 rc = pager_write(pPage);
34200 if( pPage->flags&PGHDR_NEED_SYNC ){
34201 needSync = 1;
34202 assert(pPager->needSync);
34203 }
34204 sqlite3PagerUnref(pPage);
34205 }
34206 }
34207 }else if( (pPage = pager_lookup(pPager, pg))!=0 ){
@@ -33861,22 +34210,31 @@
34210 }
34211 sqlite3PagerUnref(pPage);
34212 }
34213 }
34214
34215 /* If the PGHDR_NEED_SYNC flag is set for any of the nPage pages
34216 ** starting at pg1, then it needs to be set for all of them. Because
34217 ** writing to any of these nPage pages may damage the others, the
34218 ** journal file must contain sync()ed copies of all of them
34219 ** before any of them can be written out to the database file.
34220 **
34221 ** 2009-01-07: This block of code appears to be a no-op. I do not
34222 ** believe it is possible for any page on the sector to not have
34223 ** the PGHDR_NEED_SYNC flag set. The "pPage->flags |= PGHDR_NEED_SYNC"
34224 ** line below does nothing, I think. But it does no harm to leave
34225 ** this code in place until we can definitively prove this is the case.
34226 */
34227 if( needSync ){
34228 assert( !MEMDB && pPager->noSync==0 );
34229 for(ii=0; ii<nPage && needSync; ii++){
34230 PgHdr *pPage = pager_lookup(pPager, pg1+ii);
34231 if( pPage ){
34232 assert( pPage->flags & PGHDR_NEED_SYNC ); /* 2009-01-07 conjecture */
34233 pPage->flags |= PGHDR_NEED_SYNC;
34234 sqlite3PagerUnref(pPage);
34235 }
34236 }
34237 assert(pPager->needSync);
34238 }
34239
34240 assert( pPager->doNotSync==1 );
@@ -33927,35 +34285,35 @@
34285 SQLITE_PRIVATE int sqlite3PagerDontWrite(DbPage *pDbPage){
34286 PgHdr *pPg = pDbPage;
34287 Pager *pPager = pPg->pPager;
34288 int rc;
34289
34290 if( pPg->pgno>pPager->dbOrigSize ){
34291 return SQLITE_OK;
34292 }
34293 if( pPager->pAlwaysRollback==0 ){
34294 assert( pPager->pInJournal );
34295 pPager->pAlwaysRollback = sqlite3BitvecCreate(pPager->dbOrigSize);
34296 if( !pPager->pAlwaysRollback ){
34297 return SQLITE_NOMEM;
34298 }
34299 }
34300 rc = sqlite3BitvecSet(pPager->pAlwaysRollback, pPg->pgno);
34301
34302 if( rc==SQLITE_OK && (pPg->flags&PGHDR_DIRTY) && pPager->nSavepoint==0 ){
34303 assert( pPager->state>=PAGER_SHARED );
34304 if( pPager->dbSize==pPg->pgno && pPager->dbOrigSize<pPager->dbSize ){
34305 /* If this pages is the last page in the file and the file has grown
34306 ** during the current transaction, then do NOT mark the page as clean.
34307 ** When the database file grows, we must make sure that the last page
34308 ** gets written at least once so that the disk file will be the correct
34309 ** size. If you do not write this page and the size of the file
34310 ** on the disk ends up being too small, that can lead to database
34311 ** corruption during the next transaction.
34312 */
34313 }else{
34314 PAGERTRACE(("DONT_WRITE page %d of %d\n", pPg->pgno, PAGERID(pPager)));
34315 IOTRACE(("CLEAN %p %d\n", pPager, pPg->pgno))
34316 pPg->flags |= PGHDR_DONT_WRITE;
34317 #ifdef SQLITE_CHECK_PAGES
34318 pPg->pageHash = pager_pagehash(pPg);
34319 #endif
@@ -33975,27 +34333,28 @@
34333 ** that we will never need to read the page content in the future.
34334 ** so the needRead flag can be cleared at this point.
34335 */
34336 SQLITE_PRIVATE void sqlite3PagerDontRollback(DbPage *pPg){
34337 Pager *pPager = pPg->pPager;
34338 TESTONLY( int rc; ) /* Return value from sqlite3BitvecSet() */
34339
34340 assert( pPager->state>=PAGER_RESERVED );
34341
34342 /* If the journal file is not open, or DontWrite() has been called on
34343 ** this page (DontWrite() sets the alwaysRollback flag), then this
34344 ** function is a no-op.
34345 */
34346 if( pPager->journalOpen==0
34347 || sqlite3BitvecTest(pPager->pAlwaysRollback, pPg->pgno)
34348 || pPg->pgno>pPager->dbOrigSize
34349 ){
34350 return;
34351 }
34352
34353 #ifdef SQLITE_SECURE_DELETE
34354 if( sqlite3BitvecTest(pPager->pInJournal, pPg->pgno)!=0
34355 || pPg->pgno>pPager->dbOrigSize ){
34356 return;
34357 }
34358 #endif
34359
34360 /* If SECURE_DELETE is disabled, then there is no way that this
@@ -34006,20 +34365,30 @@
34365 **
34366 ** (Later:) Not true. If the database is corrupted by having duplicate
34367 ** pages on the freelist (ex: corrupt9.test) then the following is not
34368 ** necessarily true:
34369 */
34370 /* assert( !pPg->inJournal && (int)pPg->pgno <= pPager->dbOrigSize ); */
34371
34372 assert( pPager->pInJournal!=0 );
 
34373 pPg->flags &= ~PGHDR_NEED_READ;
34374
34375 /* Failure to set the bits in the InJournal bit-vectors is benign.
34376 ** It merely means that we might do some extra work to journal a page
34377 ** that does not need to be journaled. Nevertheless, be sure to test the
34378 ** case where a malloc error occurs while trying to set a bit in a
34379 ** bit vector.
34380 */
34381 sqlite3BeginBenignMalloc();
34382 TESTONLY( rc = ) sqlite3BitvecSet(pPager->pInJournal, pPg->pgno);
34383 testcase( rc==SQLITE_NOMEM );
34384 TESTONLY( rc = ) addToSavepointBitvecs(pPager, pPg->pgno);
34385 testcase( rc==SQLITE_NOMEM );
34386 sqlite3EndBenignMalloc();
34387
34388
34389 PAGERTRACE(("DONT_ROLLBACK page %d of %d\n", pPg->pgno, PAGERID(pPager)));
34390 IOTRACE(("GARBAGE %p %d\n", pPager, pPg->pgno))
34391 }
34392
34393
34394 /*
@@ -34032,11 +34401,11 @@
34401 int rc = SQLITE_OK;
34402
34403 #ifndef SQLITE_ENABLE_ATOMIC_WRITE
34404 assert( isDirect==0 ); /* isDirect is only true for atomic writes */
34405 #endif
34406 if( !pPager->changeCountDone && pPager->dbSize>0 ){
34407 /* Open page 1 of the file for writing. */
34408 rc = sqlite3PagerGet(pPager, 1, &pPgHdr);
34409 if( rc!=SQLITE_OK ) return rc;
34410
34411 if( !isDirect ){
@@ -34053,10 +34422,11 @@
34422 put32bits(((char*)pPgHdr->pData)+24, change_counter);
34423
34424 #ifdef SQLITE_ENABLE_ATOMIC_WRITE
34425 if( isDirect && pPager->fd->pMethods ){
34426 const void *zBuf = pPgHdr->pData;
34427 assert( pPager->dbFileSize>0 );
34428 rc = sqlite3OsWrite(pPager->fd, zBuf, pPager->pageSize, 0);
34429 }
34430 #endif
34431
34432 /* Release the page reference. */
@@ -34091,22 +34461,18 @@
34461 ** master journal file if specified).
34462 **
34463 ** Note that if zMaster==NULL, this does not overwrite a previous value
34464 ** passed to an sqlite3PagerCommitPhaseOne() call.
34465 **
 
 
 
34466 ** If the final parameter - noSync - is true, then the database file itself
34467 ** is not synced. The caller must call sqlite3PagerSync() directly to
34468 ** sync the database file before calling CommitPhaseTwo() to delete the
34469 ** journal file in this case.
34470 */
34471 SQLITE_PRIVATE int sqlite3PagerCommitPhaseOne(
34472 Pager *pPager,
34473 const char *zMaster,
 
34474 int noSync
34475 ){
34476 int rc = SQLITE_OK;
34477
34478 if( pPager->errCode ){
@@ -34120,12 +34486,12 @@
34486 pPager->exclusiveMode!=0) ){
34487 assert( pPager->dirtyCache==0 || pPager->journalOpen==0 );
34488 return SQLITE_OK;
34489 }
34490
34491 PAGERTRACE(("DATABASE SYNC: File=%s zMaster=%s nSize=%d\n",
34492 pPager->zFilename, zMaster, pPager->dbSize));
34493
34494 /* If this is an in-memory db, or no pages have been written to, or this
34495 ** function has already been called, it is a no-op.
34496 */
34497 if( pPager->state!=PAGER_SYNCED && !MEMDB && pPager->dirtyCache ){
@@ -34147,11 +34513,11 @@
34513 pPg = sqlite3PcacheDirtyList(pPager->pPCache);
34514 useAtomicWrite = (
34515 !zMaster &&
34516 pPager->journalOpen &&
34517 pPager->journalOff==jrnlBufferSize(pPager) &&
34518 pPager->dbSize>=pPager->dbFileSize &&
34519 (pPg==0 || pPg->pDirty==0)
34520 );
34521 assert( pPager->journalOpen || pPager->journalMode==PAGER_JOURNALMODE_OFF );
34522 if( useAtomicWrite ){
34523 /* Update the nRec field in the journal file. */
@@ -34184,42 +34550,38 @@
34550 if( !pPager->setMaster ){
34551 rc = pager_incr_changecounter(pPager, 0);
34552 if( rc!=SQLITE_OK ) goto sync_exit;
34553 if( pPager->journalMode!=PAGER_JOURNALMODE_OFF ){
34554 #ifndef SQLITE_OMIT_AUTOVACUUM
34555 if( pPager->dbSize<pPager->dbOrigSize ){
34556 /* If this transaction has made the database smaller, then all pages
34557 ** being discarded by the truncation must be written to the journal
34558 ** file.
34559 */
34560 Pgno i;
34561 Pgno iSkip = PAGER_MJ_PGNO(pPager);
34562 Pgno dbSize = pPager->dbSize;
34563 pPager->dbSize = pPager->dbOrigSize;
34564 for( i=dbSize+1; i<=pPager->dbOrigSize; i++ ){
34565 if( !sqlite3BitvecTest(pPager->pInJournal, i) && i!=iSkip ){
34566 rc = sqlite3PagerGet(pPager, i, &pPg);
34567 if( rc!=SQLITE_OK ) goto sync_exit;
34568 rc = sqlite3PagerWrite(pPg);
34569 sqlite3PagerUnref(pPg);
34570 if( rc!=SQLITE_OK ) goto sync_exit;
34571 }
34572 }
34573 pPager->dbSize = dbSize;
34574 }
34575 #endif
34576 rc = writeMasterJournal(pPager, zMaster);
34577 if( rc!=SQLITE_OK ) goto sync_exit;
34578 rc = syncJournal(pPager);
34579 }
34580 }
34581 if( rc!=SQLITE_OK ) goto sync_exit;
34582
 
 
 
 
 
 
 
34583 /* Write all dirty pages to the database file */
34584 pPg = sqlite3PcacheDirtyList(pPager->pPCache);
34585 rc = pager_write_pagelist(pPg);
34586 if( rc!=SQLITE_OK ){
34587 assert( rc!=SQLITE_IOERR_BLOCKED );
@@ -34231,20 +34593,24 @@
34593 ** is made to use an invalid dirty list.
34594 */
34595 goto sync_exit;
34596 }
34597 sqlite3PcacheCleanAll(pPager->pPCache);
34598
34599 if( pPager->dbSize<pPager->dbFileSize ){
34600 assert( pPager->state>=PAGER_EXCLUSIVE );
34601 rc = pager_truncate(pPager, pPager->dbSize);
34602 if( rc!=SQLITE_OK ) goto sync_exit;
34603 }
34604
34605 /* Sync the database file. */
34606 if( !pPager->noSync && !noSync ){
34607 rc = sqlite3OsSync(pPager->fd, pPager->sync_flags);
34608 }
34609 IOTRACE(("DBSYNC %p\n", pPager))
34610
34611 pPager->state = PAGER_SYNCED;
 
 
34612 }
34613
34614 sync_exit:
34615 if( rc==SQLITE_IOERR_BLOCKED ){
34616 /* pager_incr_changecounter() may attempt to obtain an exclusive
@@ -34278,11 +34644,11 @@
34644 (pPager->journalMode!=PAGER_JOURNALMODE_DELETE ||
34645 pPager->exclusiveMode!=0) ){
34646 assert( pPager->dirtyCache==0 || pPager->journalOpen==0 );
34647 return SQLITE_OK;
34648 }
34649 PAGERTRACE(("COMMIT %d\n", PAGERID(pPager)));
34650 assert( pPager->state==PAGER_SYNCED || MEMDB || !pPager->dirtyCache );
34651 rc = pager_end_transaction(pPager, pPager->setMaster);
34652 rc = pager_error(pPager, rc);
34653 return rc;
34654 }
@@ -34299,11 +34665,11 @@
34665 ** codes are returned for all these occasions. Otherwise,
34666 ** SQLITE_OK is returned.
34667 */
34668 SQLITE_PRIVATE int sqlite3PagerRollback(Pager *pPager){
34669 int rc = SQLITE_OK;
34670 PAGERTRACE(("ROLLBACK %d\n", PAGERID(pPager)));
34671 if( !pPager->dirtyCache || !pPager->journalOpen ){
34672 rc = pager_end_transaction(pPager, pPager->setMaster);
34673 }else if( pPager->errCode && pPager->errCode!=SQLITE_FULL ){
34674 if( pPager->state>=PAGER_EXCLUSIVE ){
34675 pager_playback(pPager, 0);
@@ -34379,96 +34745,101 @@
34745 return MEMDB;
34746 }
34747 #endif
34748
34749 /*
34750 ** Ensure that there are at least nSavepoint savepoints open.
34751 */
34752 SQLITE_PRIVATE int sqlite3PagerOpenSavepoint(Pager *pPager, int nSavepoint){
34753 int rc = SQLITE_OK;
34754
34755 if( nSavepoint>pPager->nSavepoint && pPager->useJournal ){
34756 int ii;
34757 PagerSavepoint *aNew;
34758
34759 /* Either the sub-journal is open or there are no active savepoints. */
34760 assert( pPager->nSavepoint==0 || pPager->sjfd->pMethods );
34761
34762 /* Grow the Pager.aSavepoint array using realloc(). Return SQLITE_NOMEM
34763 ** if the allocation fails. Otherwise, zero the new portion in case a
34764 ** malloc failure occurs while populating it in the for(...) loop below.
34765 */
34766 aNew = (PagerSavepoint *)sqlite3Realloc(
34767 pPager->aSavepoint, sizeof(PagerSavepoint)*nSavepoint
34768 );
34769 if( !aNew ){
34770 return SQLITE_NOMEM;
34771 }
34772 memset(&aNew[pPager->nSavepoint], 0,
34773 (nSavepoint - pPager->nSavepoint) * sizeof(PagerSavepoint)
34774 );
34775 pPager->aSavepoint = aNew;
34776 ii = pPager->nSavepoint;
34777 pPager->nSavepoint = nSavepoint;
34778
34779 /* Populate the PagerSavepoint structures just allocated. */
34780 for(/* no-op */; ii<nSavepoint; ii++){
34781 assert( pPager->dbSizeValid );
34782 aNew[ii].nOrig = pPager->dbSize;
34783 if( pPager->journalOpen && pPager->journalOff>0 ){
34784 aNew[ii].iOffset = pPager->journalOff;
34785 }else{
34786 aNew[ii].iOffset = JOURNAL_HDR_SZ(pPager);
34787 }
34788 aNew[ii].iSubRec = pPager->stmtNRec;
34789 aNew[ii].pInSavepoint = sqlite3BitvecCreate(pPager->dbSize);
34790 if( !aNew[ii].pInSavepoint ){
34791 return SQLITE_NOMEM;
34792 }
34793 }
34794
34795 /* Open the sub-journal, if it is not already opened. */
34796 rc = openSubJournal(pPager);
34797 }
34798
34799 return rc;
34800 }
34801
34802 /*
34803 ** Parameter op is always either SAVEPOINT_ROLLBACK or SAVEPOINT_RELEASE.
34804 ** If it is SAVEPOINT_RELEASE, then release and destroy the savepoint with
34805 ** index iSavepoint. If it is SAVEPOINT_ROLLBACK, then rollback all changes
34806 ** that have occured since savepoint iSavepoint was created.
34807 **
34808 ** In either case, all savepoints with an index greater than iSavepoint
34809 ** are destroyed.
34810 **
34811 ** If there are less than (iSavepoint+1) active savepoints when this
34812 ** function is called it is a no-op.
34813 */
34814 SQLITE_PRIVATE int sqlite3PagerSavepoint(Pager *pPager, int op, int iSavepoint){
34815 int rc = SQLITE_OK;
34816
34817 assert( op==SAVEPOINT_RELEASE || op==SAVEPOINT_ROLLBACK );
34818
34819 if( iSavepoint<pPager->nSavepoint ){
34820 int ii;
34821 int nNew = iSavepoint + (op==SAVEPOINT_ROLLBACK);
34822 for(ii=nNew; ii<pPager->nSavepoint; ii++){
34823 sqlite3BitvecDestroy(pPager->aSavepoint[ii].pInSavepoint);
34824 }
34825 pPager->nSavepoint = nNew;
34826
34827 if( op==SAVEPOINT_ROLLBACK && pPager->jfd->pMethods ){
34828 PagerSavepoint *pSavepoint = (nNew==0)?0:&pPager->aSavepoint[nNew-1];
34829 rc = pagerPlaybackSavepoint(pPager, pSavepoint);
34830 assert(rc!=SQLITE_DONE);
34831 }
34832
34833 /* If this is a release of the outermost savepoint, truncate
34834 ** the sub-journal. */
34835 if( nNew==0 && op==SAVEPOINT_RELEASE && pPager->sjfd->pMethods ){
34836 assert( rc==SQLITE_OK );
34837 rc = sqlite3OsTruncate(pPager->sjfd, 0);
34838 pPager->stmtNRec = 0;
34839 }
34840 }
34841 return rc;
34842 }
34843
34844 /*
34845 ** Return the full pathname of the database file.
@@ -34553,15 +34924,37 @@
34924 ** pPg refers to will not be written to again within this transaction.
34925 */
34926 SQLITE_PRIVATE int sqlite3PagerMovepage(Pager *pPager, DbPage *pPg, Pgno pgno, int isCommit){
34927 PgHdr *pPgOld; /* The page being overwritten. */
34928 Pgno needSyncPgno = 0;
34929 int rc;
34930
34931 assert( pPg->nRef>0 );
34932
34933 /* If the page being moved is dirty and has not been saved by the latest
34934 ** savepoint, then save the current contents of the page into the
34935 ** sub-journal now. This is required to handle the following scenario:
34936 **
34937 ** BEGIN;
34938 ** <journal page X, then modify it in memory>
34939 ** SAVEPOINT one;
34940 ** <Move page X to location Y>
34941 ** ROLLBACK TO one;
34942 **
34943 ** If page X were not written to the sub-journal here, it would not
34944 ** be possible to restore its contents when the "ROLLBACK TO one"
34945 ** statement were processed.
34946 */
34947 if( pPg->flags&PGHDR_DIRTY
34948 && subjRequiresPage(pPg)
34949 && SQLITE_OK!=(rc = subjournalPage(pPg))
34950 ){
34951 return rc;
34952 }
34953
34954 PAGERTRACE(("MOVE %d page %d (needSync=%d) moves to %d\n",
34955 PAGERID(pPager), pPg->pgno, (pPg->flags&PGHDR_NEED_SYNC)?1:0, pgno));
34956 IOTRACE(("MOVE %p %d %d\n", pPager, pPg->pgno, pgno))
34957
34958 pager_get_content(pPg);
34959
34960 /* If the journal needs to be sync()ed before page pPg->pgno can
@@ -34571,11 +34964,11 @@
34964 ** the journal needs to be sync()ed before database page pPg->pgno
34965 ** can be written to. The caller has already promised not to write to it.
34966 */
34967 if( (pPg->flags&PGHDR_NEED_SYNC) && !isCommit ){
34968 needSyncPgno = pPg->pgno;
34969 assert( pageInJournal(pPg) || pPg->pgno>pPager->dbOrigSize );
34970 assert( pPg->flags&PGHDR_DIRTY );
34971 assert( pPager->needSync );
34972 }
34973
34974 /* If the cache contains a page with page-number pgno, remove it
@@ -34615,16 +35008,15 @@
35008 ** the journal file twice, but that is not a problem.
35009 **
35010 ** The sqlite3PagerGet() call may cause the journal to sync. So make
35011 ** sure the Pager.needSync flag is set too.
35012 */
 
35013 PgHdr *pPgHdr;
35014 assert( pPager->needSync );
35015 rc = sqlite3PagerGet(pPager, needSyncPgno, &pPgHdr);
35016 if( rc!=SQLITE_OK ){
35017 if( pPager->pInJournal && needSyncPgno<=pPager->dbOrigSize ){
35018 sqlite3BitvecClear(pPager->pInJournal, needSyncPgno);
35019 }
35020 return rc;
35021 }
35022 pPager->needSync = 1;
@@ -34754,11 +35146,11 @@
35146 ** May you do good and not evil.
35147 ** May you find forgiveness for yourself and forgive others.
35148 ** May you share freely, never taking more than you give.
35149 **
35150 *************************************************************************
35151 ** $Id: btreeInt.h,v 1.38 2008/12/27 15:23:13 danielk1977 Exp $
35152 **
35153 ** This file implements a external (disk-based) database using BTrees.
35154 ** For a detailed discussion of BTrees, refer to
35155 **
35156 ** Donald E. Knuth, THE ART OF COMPUTER PROGRAMMING, Volume 3:
@@ -35111,11 +35503,10 @@
35503 u8 readOnly; /* True if the underlying file is readonly */
35504 u8 pageSizeFixed; /* True if the page size can no longer be changed */
35505 #ifndef SQLITE_OMIT_AUTOVACUUM
35506 u8 autoVacuum; /* True if auto-vacuum is enabled */
35507 u8 incrVacuum; /* True if incr-vacuum is enabled */
 
35508 #endif
35509 u16 pageSize; /* Total number of bytes on a page */
35510 u16 usableSize; /* Number of usable bytes on each page */
35511 u16 maxLocal; /* Maximum local payload in non-LEAFDATA tables */
35512 u16 minLocal; /* Minimum local payload in non-LEAFDATA tables */
@@ -35687,11 +36078,11 @@
36078 ** May you do good and not evil.
36079 ** May you find forgiveness for yourself and forgive others.
36080 ** May you share freely, never taking more than you give.
36081 **
36082 *************************************************************************
36083 ** $Id: btree.c,v 1.557 2009/01/09 14:11:05 drh Exp $
36084 **
36085 ** This file implements a external (disk-based) database using BTrees.
36086 ** See the header comment on "btreeInt.h" for additional information.
36087 ** Including a description of file format and an overview of operation.
36088 */
@@ -35711,24 +36102,10 @@
36102 # define TRACE(X) if(sqlite3BtreeTrace){printf X;fflush(stdout);}
36103 #else
36104 # define TRACE(X)
36105 #endif
36106
 
 
 
 
 
 
 
 
 
 
 
 
 
 
36107
36108
36109 #ifndef SQLITE_OMIT_SHARED_CACHE
36110 /*
36111 ** A list of BtShared objects that are eligible for participation
@@ -36858,10 +37235,11 @@
37235 ** Release a MemPage. This should be called once for each prior
37236 ** call to sqlite3BtreeGetPage.
37237 */
37238 static void releasePage(MemPage *pPage){
37239 if( pPage ){
37240 assert( pPage->nOverflow==0 || sqlite3PagerPageRefcount(pPage->pDbPage)>1 );
37241 assert( pPage->aData );
37242 assert( pPage->pBt );
37243 assert( sqlite3PagerGetExtra(pPage->pDbPage) == (void*)pPage );
37244 assert( sqlite3PagerGetData(pPage->pDbPage)==pPage->aData );
37245 assert( sqlite3_mutex_held(pPage->pBt->mutex) );
@@ -37736,10 +38114,18 @@
38114 #endif
38115 }
38116
38117
38118 trans_begun:
38119 if( rc==SQLITE_OK && wrflag ){
38120 /* This call makes sure that the pager has the correct number of
38121 ** open savepoints. If the second parameter is greater than 0 and
38122 ** the sub-journal is not already open, then it will be opened here.
38123 */
38124 rc = sqlite3PagerOpenSavepoint(pBt->pPager, p->db->nSavepoint);
38125 }
38126
38127 btreeIntegrity(p);
38128 sqlite3BtreeLeave(p);
38129 return rc;
38130 }
38131
@@ -37948,19 +38334,14 @@
38334 ** that the caller will keep calling incrVacuumStep() until
38335 ** it returns SQLITE_DONE or an error, and that nFin is the
38336 ** number of pages the database file will contain after this
38337 ** process is complete.
38338 */
38339 static int incrVacuumStep(BtShared *pBt, Pgno nFin, Pgno iLastPg){
 
38340 Pgno nFreeList; /* Number of pages still on the free-list */
38341
38342 assert( sqlite3_mutex_held(pBt->mutex) );
 
 
 
 
38343
38344 if( !PTRMAP_ISPAGE(pBt, iLastPg) && iLastPg!=PENDING_BYTE_PAGE(pBt) ){
38345 int rc;
38346 u8 eType;
38347 Pgno iPtrPage;
@@ -38030,13 +38411,16 @@
38411 return rc;
38412 }
38413 }
38414 }
38415
38416 if( nFin==0 ){
38417 iLastPg--;
38418 while( iLastPg==PENDING_BYTE_PAGE(pBt)||PTRMAP_ISPAGE(pBt, iLastPg) ){
38419 iLastPg--;
38420 }
38421 sqlite3PagerTruncateImage(pBt->pPager, iLastPg);
38422 }
38423 return SQLITE_OK;
38424 }
38425
38426 /*
@@ -38056,11 +38440,11 @@
38440 assert( pBt->inTransaction==TRANS_WRITE && p->inTrans==TRANS_WRITE );
38441 if( !pBt->autoVacuum ){
38442 rc = SQLITE_DONE;
38443 }else{
38444 invalidateAllOverflowCache(pBt);
38445 rc = incrVacuumStep(pBt, 0, sqlite3PagerImageSize(pBt->pPager));
38446 }
38447 sqlite3BtreeLeave(p);
38448 return rc;
38449 }
38450
@@ -38071,66 +38455,57 @@
38455 ** If SQLITE_OK is returned, then *pnTrunc is set to the number of pages
38456 ** the database file should be truncated to during the commit process.
38457 ** i.e. the database has been reorganized so that only the first *pnTrunc
38458 ** pages are in use.
38459 */
38460 static int autoVacuumCommit(BtShared *pBt){
38461 int rc = SQLITE_OK;
38462 Pager *pPager = pBt->pPager;
38463 VVA_ONLY( int nRef = sqlite3PagerRefcount(pPager) );
38464
38465 assert( sqlite3_mutex_held(pBt->mutex) );
38466 invalidateAllOverflowCache(pBt);
38467 assert(pBt->autoVacuum);
38468 if( !pBt->incrVacuum ){
38469 Pgno nFin;
38470 Pgno nFree;
38471 Pgno nPtrmap;
38472 Pgno iFree;
38473 const int pgsz = pBt->pageSize;
38474 Pgno nOrig = pagerPagecount(pBt);
38475
38476 if( PTRMAP_ISPAGE(pBt, nOrig) ){
38477 return SQLITE_CORRUPT_BKPT;
38478 }
38479 if( nOrig==PENDING_BYTE_PAGE(pBt) ){
38480 nOrig--;
38481 }
38482 nFree = get4byte(&pBt->pPage1->aData[36]);
38483 nPtrmap = (nFree-nOrig+PTRMAP_PAGENO(pBt, nOrig)+pgsz/5)/(pgsz/5);
38484 nFin = nOrig - nFree - nPtrmap;
38485 if( nOrig>PENDING_BYTE_PAGE(pBt) && nFin<=PENDING_BYTE_PAGE(pBt) ){
38486 nFin--;
38487 }
38488 while( PTRMAP_ISPAGE(pBt, nFin) || nFin==PENDING_BYTE_PAGE(pBt) ){
38489 nFin--;
38490 }
38491
38492 for(iFree=nOrig; iFree>nFin && rc==SQLITE_OK; iFree--){
38493 rc = incrVacuumStep(pBt, nFin, iFree);
38494 }
38495 if( (rc==SQLITE_DONE || rc==SQLITE_OK) && nFree>0 ){
 
 
 
38496 rc = SQLITE_OK;
38497 rc = sqlite3PagerWrite(pBt->pPage1->pDbPage);
38498 put4byte(&pBt->pPage1->aData[32], 0);
38499 put4byte(&pBt->pPage1->aData[36], 0);
38500 sqlite3PagerTruncateImage(pBt->pPager, nFin);
 
 
38501 }
38502 if( rc!=SQLITE_OK ){
38503 sqlite3PagerRollback(pPager);
38504 }
38505 }
38506
 
 
 
 
38507 assert( nRef==sqlite3PagerRefcount(pPager) );
38508 return rc;
38509 }
38510
38511 #endif /* ifndef SQLITE_OMIT_AUTOVACUUM */
@@ -38163,23 +38538,22 @@
38538 */
38539 SQLITE_PRIVATE int sqlite3BtreeCommitPhaseOne(Btree *p, const char *zMaster){
38540 int rc = SQLITE_OK;
38541 if( p->inTrans==TRANS_WRITE ){
38542 BtShared *pBt = p->pBt;
 
38543 sqlite3BtreeEnter(p);
38544 pBt->db = p->db;
38545 #ifndef SQLITE_OMIT_AUTOVACUUM
38546 if( pBt->autoVacuum ){
38547 rc = autoVacuumCommit(pBt);
38548 if( rc!=SQLITE_OK ){
38549 sqlite3BtreeLeave(p);
38550 return rc;
38551 }
38552 }
38553 #endif
38554 rc = sqlite3PagerCommitPhaseOne(pBt->pPager, zMaster, 0);
38555 sqlite3BtreeLeave(p);
38556 }
38557 return rc;
38558 }
38559
@@ -38345,14 +38719,10 @@
38719 unlockAllTables(p);
38720
38721 if( p->inTrans==TRANS_WRITE ){
38722 int rc2;
38723
 
 
 
 
38724 assert( TRANS_WRITE==pBt->inTransaction );
38725 rc2 = sqlite3PagerRollback(pBt->pPager);
38726 if( rc2!=SQLITE_OK ){
38727 rc = rc2;
38728 }
@@ -38402,21 +38772,28 @@
38772 SQLITE_PRIVATE int sqlite3BtreeBeginStmt(Btree *p){
38773 int rc;
38774 BtShared *pBt = p->pBt;
38775 sqlite3BtreeEnter(p);
38776 pBt->db = p->db;
38777 assert( p->inTrans==TRANS_WRITE );
38778 assert( !pBt->inStmt );
38779 assert( pBt->readOnly==0 );
38780 if( NEVER(p->inTrans!=TRANS_WRITE || pBt->inStmt || pBt->readOnly) ){
38781 rc = SQLITE_INTERNAL;
38782 }else{
38783 assert( pBt->inTransaction==TRANS_WRITE );
38784 /* At the pager level, a statement transaction is a savepoint with
38785 ** an index greater than all savepoints created explicitly using
38786 ** SQL statements. It is illegal to open, release or rollback any
38787 ** such savepoints while the statement transaction savepoint is active.
38788 */
38789 rc = sqlite3PagerOpenSavepoint(pBt->pPager, p->db->nSavepoint+1);
38790 pBt->inStmt = 1;
38791 }
38792 sqlite3BtreeLeave(p);
38793 return rc;
38794 }
 
38795
38796 /*
38797 ** Commit the statment subtransaction currently in progress. If no
38798 ** subtransaction is active, this is a no-op.
38799 */
@@ -38423,12 +38800,14 @@
38800 SQLITE_PRIVATE int sqlite3BtreeCommitStmt(Btree *p){
38801 int rc;
38802 BtShared *pBt = p->pBt;
38803 sqlite3BtreeEnter(p);
38804 pBt->db = p->db;
38805 assert( pBt->readOnly==0 );
38806 if( pBt->inStmt ){
38807 int iStmtpoint = p->db->nSavepoint;
38808 rc = sqlite3PagerSavepoint(pBt->pPager, SAVEPOINT_RELEASE, iStmtpoint);
38809 }else{
38810 rc = SQLITE_OK;
38811 }
38812 pBt->inStmt = 0;
38813 sqlite3BtreeLeave(p);
@@ -38446,17 +38825,52 @@
38825 SQLITE_PRIVATE int sqlite3BtreeRollbackStmt(Btree *p){
38826 int rc = SQLITE_OK;
38827 BtShared *pBt = p->pBt;
38828 sqlite3BtreeEnter(p);
38829 pBt->db = p->db;
38830 assert( pBt->readOnly==0 );
38831 if( pBt->inStmt ){
38832 int iStmtpoint = p->db->nSavepoint;
38833 rc = sqlite3PagerSavepoint(pBt->pPager, SAVEPOINT_ROLLBACK, iStmtpoint);
38834 if( rc==SQLITE_OK ){
38835 rc = sqlite3PagerSavepoint(pBt->pPager, SAVEPOINT_RELEASE, iStmtpoint);
38836 }
38837 pBt->inStmt = 0;
38838 }
38839 sqlite3BtreeLeave(p);
38840 return rc;
38841 }
38842
38843 /*
38844 ** The second argument to this function, op, is always SAVEPOINT_ROLLBACK
38845 ** or SAVEPOINT_RELEASE. This function either releases or rolls back the
38846 ** savepoint identified by parameter iSavepoint, depending on the value
38847 ** of op.
38848 **
38849 ** Normally, iSavepoint is greater than or equal to zero. However, if op is
38850 ** SAVEPOINT_ROLLBACK, then iSavepoint may also be -1. In this case the
38851 ** contents of the entire transaction are rolled back. This is different
38852 ** from a normal transaction rollback, as no locks are released and the
38853 ** transaction remains open.
38854 */
38855 SQLITE_PRIVATE int sqlite3BtreeSavepoint(Btree *p, int op, int iSavepoint){
38856 int rc = SQLITE_OK;
38857 if( p && p->inTrans==TRANS_WRITE ){
38858 BtShared *pBt = p->pBt;
38859 assert( pBt->inStmt==0 );
38860 assert( op==SAVEPOINT_RELEASE || op==SAVEPOINT_ROLLBACK );
38861 assert( iSavepoint>=0 || (iSavepoint==-1 && op==SAVEPOINT_ROLLBACK) );
38862 sqlite3BtreeEnter(p);
38863 pBt->db = p->db;
38864 rc = sqlite3PagerSavepoint(pBt->pPager, op, iSavepoint);
38865 if( rc==SQLITE_OK ){
38866 rc = newDatabase(pBt);
38867 }
38868 sqlite3BtreeLeave(p);
38869 }
38870 return rc;
38871 }
38872
38873 /*
38874 ** Create a new cursor for the BTree whose root is on the page
38875 ** iTable. The act of acquiring a cursor gets a read lock on
38876 ** the database file.
@@ -38498,11 +38912,12 @@
38912 BtShared *pBt = p->pBt;
38913
38914 assert( sqlite3BtreeHoldsMutex(p) );
38915 assert( wrFlag==0 || wrFlag==1 );
38916 if( wrFlag ){
38917 assert( !pBt->readOnly );
38918 if( NEVER(pBt->readOnly) ){
38919 return SQLITE_READONLY;
38920 }
38921 if( checkReadLocks(p, iTable, 0, 0) ){
38922 return SQLITE_LOCKED;
38923 }
@@ -38511,13 +38926,10 @@
38926 if( pBt->pPage1==0 ){
38927 rc = lockBtreeWithRetry(p);
38928 if( rc!=SQLITE_OK ){
38929 return rc;
38930 }
 
 
 
38931 }
38932 pCur->pgnoRoot = (Pgno)iTable;
38933 rc = sqlite3PagerPagecount(pBt->pPager, (int *)&nPage);
38934 if( rc!=SQLITE_OK ){
38935 return rc;
@@ -39394,23 +39806,24 @@
39806 ** If an exact match is not found, then the cursor is always
39807 ** left pointing at a leaf page which would hold the entry if it
39808 ** were present. The cursor might point to an entry that comes
39809 ** before or after the key.
39810 **
39811 ** An integer is written into *pRes which is the result of
39812 ** comparing the key with the entry to which the cursor is
39813 ** pointing. The meaning of the integer written into
39814 ** *pRes is as follows:
39815 **
39816 ** *pRes<0 The cursor is left pointing at an entry that
39817 ** is smaller than intKey/pIdxKey or if the table is empty
39818 ** and the cursor is therefore left point to nothing.
39819 **
39820 ** *pRes==0 The cursor is left pointing at an entry that
39821 ** exactly matches intKey/pIdxKey.
39822 **
39823 ** *pRes>0 The cursor is left pointing at an entry that
39824 ** is larger than intKey/pIdxKey.
39825 **
39826 */
39827 SQLITE_PRIVATE int sqlite3BtreeMovetoUnpacked(
39828 BtCursor *pCur, /* The cursor to be moved */
39829 UnpackedRecord *pIdxKey, /* Unpacked index key */
@@ -39455,20 +39868,20 @@
39868 Pgno chldPg;
39869 MemPage *pPage = pCur->apPage[pCur->iPage];
39870 int c = -1; /* pRes return if table is empty must be -1 */
39871 lwr = 0;
39872 upr = pPage->nCell-1;
39873 if( (!pPage->intKey && pIdxKey==0) || upr<0 ){
39874 rc = SQLITE_CORRUPT_BKPT;
39875 goto moveto_finish;
39876 }
39877 if( biasRight ){
39878 pCur->aiIdx[pCur->iPage] = (u16)upr;
39879 }else{
39880 pCur->aiIdx[pCur->iPage] = (u16)((upr+lwr)/2);
39881 }
39882 for(;;){
39883 void *pCellKey;
39884 i64 nCellKey;
39885 int idx = pCur->aiIdx[pCur->iPage];
39886 pCur->info.nSize = 0;
39887 pCur->validNKey = 1;
@@ -39511,11 +39924,11 @@
39924 if( pPage->intKey && !pPage->leaf ){
39925 lwr = idx;
39926 upr = lwr - 1;
39927 break;
39928 }else{
39929 *pRes = 0;
39930 rc = SQLITE_OK;
39931 goto moveto_finish;
39932 }
39933 }
39934 if( c<0 ){
@@ -39957,20 +40370,10 @@
40370 ** end of the file */
40371 int nPage = pagerPagecount(pBt);
40372 *pPgno = nPage + 1;
40373
40374 #ifndef SQLITE_OMIT_AUTOVACUUM
 
 
 
 
 
 
 
 
 
 
40375 if( pBt->autoVacuum && PTRMAP_ISPAGE(pBt, *pPgno) ){
40376 /* If *pPgno refers to a pointer-map page, allocate two new pages
40377 ** at the end of the file instead of one. The first allocated page
40378 ** becomes a new pointer-map page, the second is used by the caller.
40379 */
@@ -39977,13 +40380,10 @@
40380 TRACE(("ALLOCATE: %d from end of file (pointer-map page)\n", *pPgno));
40381 assert( *pPgno!=PENDING_BYTE_PAGE(pBt) );
40382 (*pPgno)++;
40383 if( *pPgno==PENDING_BYTE_PAGE(pBt) ){ (*pPgno)++; }
40384 }
 
 
 
40385 #endif
40386
40387 assert( *pPgno!=PENDING_BYTE_PAGE(pBt) );
40388 rc = sqlite3BtreeGetPage(pBt, *pPgno, ppPage, 0);
40389 if( rc ) return rc;
@@ -40606,10 +41006,11 @@
41006 ** it will not be rolled back and so it is important to make sure that
41007 ** the page data and contents of MemPage are consistent.
41008 */
41009 pPage->isInit = 0;
41010 sqlite3BtreeInitPage(pPage);
41011 assert( pPage->nOverflow==0 );
41012
41013 /* If everything else succeeded, balance the parent page, in
41014 ** case the divider cell inserted caused it to become overfull.
41015 */
41016 if( rc==SQLITE_OK ){
@@ -40654,12 +41055,12 @@
41055 MemPage *pPage; /* The over or underfull page to balance */
41056 MemPage *pParent; /* The parent of pPage */
41057 BtShared *pBt; /* The whole database */
41058 int nCell = 0; /* Number of cells in apCell[] */
41059 int nMaxCells = 0; /* Allocated size of apCell, szCell, aFrom. */
41060 int nOld = 0; /* Number of pages in apOld[] */
41061 int nNew = 0; /* Number of pages in apNew[] */
41062 int nDiv; /* Number of cells in apDiv[] */
41063 int i, j, k; /* Loop counters */
41064 int idx; /* Index of pPage in pParent->aCell[] */
41065 int nxDiv; /* Next divider slot in pParent->aCell[] */
41066 int rc; /* The return code */
@@ -40698,11 +41099,11 @@
41099 assert( sqlite3PagerIswriteable(pPage->pDbPage) || pPage->nOverflow==1 );
41100 pBt = pPage->pBt;
41101 pParent = pCur->apPage[pCur->iPage-1];
41102 assert( pParent );
41103 if( SQLITE_OK!=(rc = sqlite3PagerWrite(pParent->pDbPage)) ){
41104 goto balance_cleanup;
41105 }
41106
41107 TRACE(("BALANCE: begin page %d child of %d\n", pPage->pgno, pParent->pgno));
41108
41109 #ifndef SQLITE_OMIT_QUICKBALANCE
@@ -40729,11 +41130,11 @@
41130 return balance_quick(pCur);
41131 }
41132 #endif
41133
41134 if( SQLITE_OK!=(rc = sqlite3PagerWrite(pPage->pDbPage)) ){
41135 goto balance_cleanup;
41136 }
41137
41138 /*
41139 ** Find the cell in the parent page whose left child points back
41140 ** to pPage. The "idx" variable is the index of that cell. If pPage
@@ -40740,16 +41141,10 @@
41141 ** is the rightmost child of pParent then set idx to pParent->nCell
41142 */
41143 idx = pCur->aiIdx[pCur->iPage-1];
41144 assertParentIndex(pParent, idx, pPage->pgno);
41145
 
 
 
 
 
 
41146 /*
41147 ** Find sibling pages to pPage and the cells in pParent that divide
41148 ** the siblings. An attempt is made to find NN siblings on either
41149 ** side of pPage. More siblings are taken from one side, however, if
41150 ** pPage there are fewer than NN siblings on the other side. If pParent
@@ -41207,10 +41602,13 @@
41602 ** But the parent page will always be initialized.
41603 */
41604 assert( pParent->isInit );
41605 sqlite3ScratchFree(apCell);
41606 apCell = 0;
41607 TRACE(("BALANCE: finished with %d: old=%d new=%d cells=%d\n",
41608 pPage->pgno, nOld, nNew, nCell));
41609 pPage->nOverflow = 0;
41610 releasePage(pPage);
41611 pCur->iPage--;
41612 rc = balance(pCur, 0);
41613
41614 /*
@@ -41223,15 +41621,11 @@
41621 releasePage(apOld[i]);
41622 }
41623 for(i=0; i<nNew; i++){
41624 releasePage(apNew[i]);
41625 }
41626 pCur->apPage[pCur->iPage]->nOverflow = 0;
 
 
 
 
41627
41628 return rc;
41629 }
41630
41631 /*
@@ -41387,10 +41781,13 @@
41781 rc = ptrmapPut(pBt, pChild->pgno, PTRMAP_BTREE, pPage->pgno);
41782 #ifndef SQLITE_OMIT_AUTOVACUUM
41783 if( rc==SQLITE_OK ){
41784 rc = setChildPtrmaps(pChild);
41785 }
41786 if( rc ){
41787 pChild->nOverflow = 0;
41788 }
41789 #endif
41790 }
41791 }
41792
41793 if( rc==SQLITE_OK ){
@@ -41421,21 +41818,22 @@
41818 assert( sqlite3_mutex_held(pPage->pBt->mutex) );
41819 if( pCur->iPage==0 ){
41820 rc = sqlite3PagerWrite(pPage->pDbPage);
41821 if( rc==SQLITE_OK && pPage->nOverflow>0 ){
41822 rc = balance_deeper(pCur);
41823 assert( pCur->apPage[0]==pPage );
41824 assert( pPage->nOverflow==0 || rc!=SQLITE_OK );
41825 }
41826 if( rc==SQLITE_OK && pPage->nCell==0 ){
41827 rc = balance_shallower(pCur);
41828 assert( pCur->apPage[0]==pPage );
41829 assert( pPage->nOverflow==0 || rc!=SQLITE_OK );
41830 }
41831 }else{
41832 if( pPage->nOverflow>0 ||
41833 (!isInsert && pPage->nFree>pPage->pBt->usableSize*2/3) ){
41834 rc = balance_nonroot(pCur);
 
41835 }
41836 }
41837 return rc;
41838 }
41839
@@ -41533,19 +41931,13 @@
41931 BtShared *pBt = p->pBt;
41932 unsigned char *oldCell;
41933 unsigned char *newCell = 0;
41934
41935 assert( cursorHoldsMutex(pCur) );
41936 assert( pBt->inTransaction==TRANS_WRITE );
 
 
 
 
41937 assert( !pBt->readOnly );
41938 assert( pCur->wrFlag );
 
 
41939 if( checkReadLocks(pCur->pBtree, pCur->pgnoRoot, pCur, nKey) ){
41940 return SQLITE_LOCKED; /* The table pCur points to has a read lock */
41941 }
41942 if( pCur->eState==CURSOR_FAULT ){
41943 return pCur->skip;
@@ -41606,12 +41998,11 @@
41998 rc = balance(pCur, 1);
41999 }
42000
42001 /* Must make sure nOverflow is reset to zero even if the balance()
42002 ** fails. Internal data structure corruption will result otherwise. */
42003 pCur->apPage[pCur->iPage]->nOverflow = 0;
 
42004
42005 if( rc==SQLITE_OK ){
42006 moveToRoot(pCur);
42007 }
42008 end_insert:
@@ -41631,25 +42022,19 @@
42022 Btree *p = pCur->pBtree;
42023 BtShared *pBt = p->pBt;
42024
42025 assert( cursorHoldsMutex(pCur) );
42026 assert( pPage->isInit );
42027 assert( pBt->inTransaction==TRANS_WRITE );
 
 
 
 
42028 assert( !pBt->readOnly );
42029 if( pCur->eState==CURSOR_FAULT ){
42030 return pCur->skip;
42031 }
42032 if( NEVER(pCur->aiIdx[pCur->iPage]>=pPage->nCell) ){
42033 return SQLITE_ERROR; /* The cursor is not pointing to anything */
42034 }
42035 assert( pCur->wrFlag );
 
 
42036 if( checkReadLocks(pCur->pBtree, pCur->pgnoRoot, pCur, pCur->info.nKey) ){
42037 return SQLITE_LOCKED; /* The table pCur points to has a read lock */
42038 }
42039
42040 /* Restore the current cursor position (a no-op if the cursor is not in
@@ -41840,15 +42225,11 @@
42225 MemPage *pRoot;
42226 Pgno pgnoRoot;
42227 int rc;
42228
42229 assert( sqlite3BtreeHoldsMutex(p) );
42230 assert( pBt->inTransaction==TRANS_WRITE );
 
 
 
 
42231 assert( !pBt->readOnly );
42232
42233 #ifdef SQLITE_OMIT_AUTOVACUUM
42234 rc = allocateBtreePage(pBt, &pRoot, &pgnoRoot, 1, 0);
42235 if( rc ){
@@ -42040,13 +42421,12 @@
42421 SQLITE_PRIVATE int sqlite3BtreeClearTable(Btree *p, int iTable, int *pnChange){
42422 int rc;
42423 BtShared *pBt = p->pBt;
42424 sqlite3BtreeEnter(p);
42425 pBt->db = p->db;
42426 assert( p->inTrans==TRANS_WRITE );
42427 if( (rc = checkReadLocks(p, iTable, 0, 1))!=SQLITE_OK ){
 
42428 /* nothing to do */
42429 }else if( SQLITE_OK!=(rc = saveAllCursors(pBt, iTable, 0)) ){
42430 /* nothing to do */
42431 }else{
42432 rc = clearDatabasePage(pBt, (Pgno)iTable, 0, pnChange);
@@ -42079,13 +42459,11 @@
42459 int rc;
42460 MemPage *pPage = 0;
42461 BtShared *pBt = p->pBt;
42462
42463 assert( sqlite3BtreeHoldsMutex(p) );
42464 assert( p->inTrans==TRANS_WRITE );
 
 
42465
42466 /* It is illegal to drop a table if any cursors are open on the
42467 ** database. This is because in auto-vacuum mode the backend may
42468 ** need to move another root-page to fill a gap left by the deleted
42469 ** root page. If an open cursor was using this page a problem would
@@ -42272,26 +42650,23 @@
42650 unsigned char *pP1;
42651 int rc;
42652 assert( idx>=1 && idx<=15 );
42653 sqlite3BtreeEnter(p);
42654 pBt->db = p->db;
42655 assert( p->inTrans==TRANS_WRITE );
42656 assert( pBt->pPage1!=0 );
42657 pP1 = pBt->pPage1->aData;
42658 rc = sqlite3PagerWrite(pBt->pPage1->pDbPage);
42659 if( rc==SQLITE_OK ){
42660 put4byte(&pP1[36 + idx*4], iMeta);
 
 
42661 #ifndef SQLITE_OMIT_AUTOVACUUM
42662 if( idx==7 ){
42663 assert( pBt->autoVacuum || iMeta==0 );
42664 assert( iMeta==0 || iMeta==1 );
42665 pBt->incrVacuum = (u8)iMeta;
42666 }
42667 #endif
 
42668 }
42669 sqlite3BtreeLeave(p);
42670 return rc;
42671 }
42672
@@ -42305,12 +42680,13 @@
42680 */
42681 MemPage *pPage;
42682 restoreCursorPosition(pCur);
42683 pPage = pCur->apPage[pCur->iPage];
42684 assert( cursorHoldsMutex(pCur) );
42685 assert( pPage!=0 );
42686 assert( pPage->pBt==pCur->pBt );
42687 return pPage->aData[pPage->hdrOffset];
42688 }
42689
42690
42691 /*
42692 ** Return the pager associated with a BTree. This routine is used for
@@ -42521,11 +42897,11 @@
42897 checkAppendMsg(pCheck, zContext,
42898 "unable to get the page. error code=%d", rc);
42899 return 0;
42900 }
42901 if( (rc = sqlite3BtreeInitPage(pPage))!=0 ){
42902 assert( rc==SQLITE_CORRUPT ); /* The only possible error from InitPage */
42903 checkAppendMsg(pCheck, zContext,
42904 "sqlite3BtreeInitPage() returns error code %d", rc);
42905 releasePage(pPage);
42906 return 0;
42907 }
@@ -42690,15 +43066,10 @@
43066 sCheck.nPage = pagerPagecount(sCheck.pBt);
43067 sCheck.mxErr = mxErr;
43068 sCheck.nErr = 0;
43069 sCheck.mallocFailed = 0;
43070 *pnErr = 0;
 
 
 
 
 
43071 if( sCheck.nPage==0 ){
43072 unlockBtreeIfUnused(pBt);
43073 sqlite3BtreeLeave(p);
43074 return 0;
43075 }
@@ -42753,14 +43124,16 @@
43124 checkAppendMsg(&sCheck, 0, "Pointer map page %d is referenced", i);
43125 }
43126 #endif
43127 }
43128
43129 /* Make sure this analysis did not leave any unref() pages.
43130 ** This is an internal consistency check; an integrity check
43131 ** of the integrity check.
43132 */
43133 unlockBtreeIfUnused(pBt);
43134 if( NEVER(nRef != sqlite3PagerRefcount(pBt->pPager)) ){
43135 checkAppendMsg(&sCheck, 0,
43136 "Outstanding page count goes from %d to %d during this analysis",
43137 nRef, sqlite3PagerRefcount(pBt->pPager)
43138 );
43139 }
@@ -42845,14 +43218,13 @@
43218 pBtFrom->db = pFrom->db;
43219
43220 nToPageSize = pBtTo->pageSize;
43221 nFromPageSize = pBtFrom->pageSize;
43222
43223 assert( pTo->inTrans==TRANS_WRITE );
43224 assert( pFrom->inTrans==TRANS_WRITE );
43225 if( NEVER(pBtTo->pCursor) ){
 
43226 return SQLITE_BUSY;
43227 }
43228
43229 nToPage = pagerPagecount(pBtTo);
43230 nFromPage = pagerPagecount(pBtFrom);
@@ -42952,80 +43324,74 @@
43324 ** For example, say the page-size of pTo is 2048 bytes and the original
43325 ** number of pages is 5 (10 KB file). If pFrom has a page size of 1024
43326 ** bytes and 9 pages, then the file needs to be truncated to 9KB.
43327 */
43328 if( rc==SQLITE_OK ){
43329 sqlite3_file *pFile = sqlite3PagerFile(pBtTo->pPager);
43330 i64 iSize = (i64)nFromPageSize * (i64)nFromPage;
43331 i64 iNow = (i64)((nToPage>nNewPage)?nToPage:nNewPage) * (i64)nToPageSize;
43332 i64 iPending = ((i64)PENDING_BYTE_PAGE(pBtTo)-1) *(i64)nToPageSize;
43333
43334 assert( iSize<=iNow );
43335
43336 /* Commit phase one syncs the journal file associated with pTo
43337 ** containing the original data. It does not sync the database file
43338 ** itself. After doing this it is safe to use OsTruncate() and other
43339 ** file APIs on the database file directly.
43340 */
43341 pBtTo->db = pTo->db;
43342 rc = sqlite3PagerCommitPhaseOne(pBtTo->pPager, 0, 1);
43343 if( iSize<iNow && rc==SQLITE_OK ){
43344 rc = sqlite3OsTruncate(pFile, iSize);
43345 }
43346
43347 /* The loop that copied data from database pFrom to pTo did not
43348 ** populate the locking page of database pTo. If the page-size of
43349 ** pFrom is smaller than that of pTo, this means some data will
43350 ** not have been copied.
43351 **
43352 ** This block copies the missing data from database pFrom to pTo
43353 ** using file APIs. This is safe because at this point we know that
43354 ** all of the original data from pTo has been synced into the
43355 ** journal file. At this point it would be safe to do anything at
43356 ** all to the database file except truncate it to zero bytes.
43357 */
43358 if( rc==SQLITE_OK && nFromPageSize<nToPageSize && iSize>iPending){
43359 i64 iOff;
43360 for(
43361 iOff=iPending;
43362 rc==SQLITE_OK && iOff<(iPending+nToPageSize);
43363 iOff += nFromPageSize
43364 ){
43365 DbPage *pFromPage = 0;
43366 Pgno iFrom = (Pgno)(iOff/nFromPageSize)+1;
43367
43368 if( iFrom==PENDING_BYTE_PAGE(pBtFrom) || iFrom>nFromPage ){
43369 continue;
43370 }
43371
43372 rc = sqlite3PagerGet(pBtFrom->pPager, iFrom, &pFromPage);
43373 if( rc==SQLITE_OK ){
43374 char *zFrom = sqlite3PagerGetData(pFromPage);
43375 rc = sqlite3OsWrite(pFile, zFrom, nFromPageSize, iOff);
43376 sqlite3PagerUnref(pFromPage);
43377 }
43378 }
43379 }
43380 }
43381
43382 /* Sync the database file */
43383 if( rc==SQLITE_OK ){
43384 rc = sqlite3PagerSync(pBtTo->pPager);
43385 }
43386 if( rc==SQLITE_OK ){
43387 pBtTo->pageSizeFixed = 0;
43388 }else{
 
 
 
 
 
 
43389 sqlite3BtreeRollback(pTo);
43390 }
43391
43392 return rc;
43393 }
43394 SQLITE_PRIVATE int sqlite3BtreeCopyFile(Btree *pTo, Btree *pFrom){
43395 int rc;
43396 sqlite3BtreeEnter(pTo);
43397 sqlite3BtreeEnter(pFrom);
@@ -43048,19 +43414,21 @@
43414 /*
43415 ** Return non-zero if a statement transaction is active.
43416 */
43417 SQLITE_PRIVATE int sqlite3BtreeIsInStmt(Btree *p){
43418 assert( sqlite3BtreeHoldsMutex(p) );
43419 assert( p->pBt );
43420 return ALWAYS(p->pBt) && p->pBt->inStmt;
43421 }
43422
43423 /*
43424 ** Return non-zero if a read (or write) transaction is active.
43425 */
43426 SQLITE_PRIVATE int sqlite3BtreeIsInReadTrans(Btree *p){
43427 assert( p );
43428 assert( sqlite3_mutex_held(p->db->mutex) );
43429 return p->inTrans!=TRANS_NONE;
43430 }
43431
43432 /*
43433 ** This function returns a pointer to a blob of memory associated with
43434 ** a single shared-btree. The memory is used by client code for its own
@@ -43204,11 +43572,11 @@
43572 ** This file contains code use to manipulate "Mem" structure. A "Mem"
43573 ** stores a single value in the VDBE. Mem is an opaque structure visible
43574 ** only within the VDBE. Interface routines refer to a Mem using the
43575 ** name sqlite_value
43576 **
43577 ** $Id: vdbemem.c,v 1.134 2009/01/05 22:30:39 drh Exp $
43578 */
43579
43580 /*
43581 ** Call sqlite3VdbeMemExpandBlob() on the supplied value (type Mem*)
43582 ** P if required.
@@ -43650,11 +44018,10 @@
44018 ** Delete any previous value and set the value to be a BLOB of length
44019 ** n containing all zeros.
44020 */
44021 SQLITE_PRIVATE void sqlite3VdbeMemSetZeroBlob(Mem *pMem, int n){
44022 sqlite3VdbeMemRelease(pMem);
 
44023 pMem->flags = MEM_Blob|MEM_Zero;
44024 pMem->type = SQLITE_BLOB;
44025 pMem->n = 0;
44026 if( n<0 ) n = 0;
44027 pMem->u.nZero = n;
@@ -44292,11 +44659,11 @@
44659 ** This file contains code used for creating, destroying, and populating
44660 ** a VDBE (or an "sqlite3_stmt" as it is known to the outside world.) Prior
44661 ** to version 2.8.7, all this code was combined into the vdbe.c source file.
44662 ** But that file was getting too big so this subroutines were split out.
44663 **
44664 ** $Id: vdbeaux.c,v 1.430 2009/01/07 08:12:16 danielk1977 Exp $
44665 */
44666
44667
44668
44669 /*
@@ -45551,13 +45918,16 @@
45918 }
45919 }
45920
45921 /* If there are any write-transactions at all, invoke the commit hook */
45922 if( needXcommit && db->xCommitCallback ){
45923 assert( (db->flags & SQLITE_CommitBusy)==0 );
45924 db->flags |= SQLITE_CommitBusy;
45925 (void)sqlite3SafetyOff(db);
45926 rc = db->xCommitCallback(db->pCommitArg);
45927 (void)sqlite3SafetyOn(db);
45928 db->flags &= ~SQLITE_CommitBusy;
45929 if( rc ){
45930 return SQLITE_CONSTRAINT;
45931 }
45932 }
45933
@@ -45855,10 +46225,11 @@
46225 /* We are forced to roll back the active transaction. Before doing
46226 ** so, abort any other statements this handle currently has active.
46227 */
46228 invalidateCursorsOnModifiedBtrees(db);
46229 sqlite3RollbackAll(db);
46230 sqlite3CloseSavepoints(db);
46231 db->autoCommit = 1;
46232 }
46233 }
46234 }
46235
@@ -45869,10 +46240,11 @@
46240 ** above has occurred.
46241 */
46242 if( !sqlite3VtabInSync(db)
46243 && db->autoCommit
46244 && db->writeVdbeCnt==(p->readOnly==0)
46245 && (db->flags & SQLITE_CommitBusy)==0
46246 ){
46247 if( p->rc==SQLITE_OK || (p->errorAction==OE_Fail && !isSpecialError) ){
46248 /* The auto-commit flag is true, and the vdbe program was
46249 ** successful or hit an 'OR FAIL' constraint. This means a commit
46250 ** is required.
@@ -45898,10 +46270,11 @@
46270 }else if( p->errorAction==OE_Abort ){
46271 xFunc = sqlite3BtreeRollbackStmt;
46272 }else{
46273 invalidateCursorsOnModifiedBtrees(db);
46274 sqlite3RollbackAll(db);
46275 sqlite3CloseSavepoints(db);
46276 db->autoCommit = 1;
46277 }
46278 }
46279
46280 /* If xFunc is not NULL, then it is one of sqlite3BtreeRollbackStmt or
@@ -48171,11 +48544,11 @@
48544 ** documentation, headers files, or other derived files. The formatting
48545 ** of the code in this file is, therefore, important. See other comments
48546 ** in this file for details. If in doubt, do not deviate from existing
48547 ** commenting and indentation practices when changing or adding code.
48548 **
48549 ** $Id: vdbe.c,v 1.810 2009/01/05 22:30:39 drh Exp $
48550 */
48551
48552 /*
48553 ** The following global variable is incremented every time a cursor
48554 ** moves, either by the OP_SeekXX, OP_Next, or OP_Prev opcodes. The test
@@ -48715,10 +49088,30 @@
49088 rc = sqlite3OsAccess(db->pVfs, zFile, SQLITE_ACCESS_EXISTS, &res);
49089 return (res && rc==SQLITE_OK);
49090 }
49091 #endif
49092
49093 #ifndef NDEBUG
49094 /*
49095 ** This function is only called from within an assert() expression. It
49096 ** checks that the sqlite3.nTransaction variable is correctly set to
49097 ** the number of non-transaction savepoints currently in the
49098 ** linked list starting at sqlite3.pSavepoint.
49099 **
49100 ** Usage:
49101 **
49102 ** assert( checkSavepointCount(db) );
49103 */
49104 static int checkSavepointCount(sqlite3 *db){
49105 int n = 0;
49106 Savepoint *p;
49107 for(p=db->pSavepoint; p; p=p->pNext) n++;
49108 assert( n==(db->nSavepoint + db->isTransactionSavepoint) );
49109 return 1;
49110 }
49111 #endif
49112
49113 /*
49114 ** Execute as much of a VDBE program as we can then return.
49115 **
49116 ** sqlite3VdbeMakeReady() must be called before this routine in order to
49117 ** close the program with a final OP_Halt and to set up the callbacks
@@ -49005,15 +49398,12 @@
49398
49399 /* Opcode: Yield P1 * * * *
49400 **
49401 ** Swap the program counter with the value in register P1.
49402 */
49403 case OP_Yield: { /* in1 */
49404 int pcDest;
 
 
 
49405 assert( (pIn1->flags & MEM_Dyn)==0 );
49406 pIn1->flags = MEM_Int;
49407 pcDest = (int)pIn1->u.i;
49408 pIn1->u.i = pc;
49409 REGISTER_TRACE(pOp->p1, pIn1);
@@ -49229,14 +49619,11 @@
49619 ** Make a copy of register P1 into register P2.
49620 **
49621 ** This instruction makes a deep copy of the value. A duplicate
49622 ** is made of any string or blob constant. See also OP_SCopy.
49623 */
49624 case OP_Copy: { /* in1 */
 
 
 
49625 assert( pOp->p2>0 );
49626 assert( pOp->p2<=p->nMem );
49627 pOut = &p->aMem[pOp->p2];
49628 assert( pOut!=pIn1 );
49629 sqlite3VdbeMemShallowCopy(pOut, pIn1, MEM_Ephem);
@@ -49255,14 +49642,11 @@
49642 ** Worse, if the original is deallocated, the copy becomes invalid.
49643 ** Thus the program must guarantee that the original will not change
49644 ** during the lifetime of the copy. Use OP_Copy to make a complete
49645 ** copy.
49646 */
49647 case OP_SCopy: { /* in1 */
 
 
 
49648 REGISTER_TRACE(pOp->p1, pIn1);
49649 assert( pOp->p2>0 );
49650 assert( pOp->p2<=p->nMem );
49651 pOut = &p->aMem[pOp->p2];
49652 assert( pOut!=pIn1 );
@@ -49708,11 +50092,11 @@
50092 assert( MEM_Str==(MEM_Blob>>3) );
50093 pIn1->flags |= (pIn1->flags&MEM_Blob)>>3;
50094 applyAffinity(pIn1, SQLITE_AFF_TEXT, encoding);
50095 rc = ExpandBlob(pIn1);
50096 assert( pIn1->flags & MEM_Str || db->mallocFailed );
50097 pIn1->flags &= ~(MEM_Int|MEM_Real|MEM_Blob|MEM_Zero);
50098 UPDATE_MAX_BLOBSIZE(pIn1);
50099 break;
50100 }
50101
50102 /* Opcode: ToBlob P1 * * * *
@@ -49727,12 +50111,14 @@
50111 case OP_ToBlob: { /* same as TK_TO_BLOB, in1 */
50112 if( pIn1->flags & MEM_Null ) break;
50113 if( (pIn1->flags & MEM_Blob)==0 ){
50114 applyAffinity(pIn1, SQLITE_AFF_TEXT, encoding);
50115 assert( pIn1->flags & MEM_Str || db->mallocFailed );
50116 MemSetTypeFlag(pIn1, MEM_Blob);
50117 }else{
50118 pIn1->flags &= ~(MEM_TypeMask&~MEM_Blob);
50119 }
 
50120 UPDATE_MAX_BLOBSIZE(pIn1);
50121 break;
50122 }
50123
50124 /* Opcode: ToNumeric P1 * * * *
@@ -50571,10 +50957,144 @@
50957 p->openedStatement = 1;
50958 }
50959 }
50960 break;
50961 }
50962
50963 /* Opcode: Savepoint P1 * * P4 *
50964 **
50965 ** Open, release or rollback the savepoint named by parameter P4, depending
50966 ** on the value of P1. To open a new savepoint, P1==0. To release (commit) an
50967 ** existing savepoint, P1==1, or to rollback an existing savepoint P1==2.
50968 */
50969 case OP_Savepoint: {
50970 int p1 = pOp->p1;
50971 char *zName = pOp->p4.z; /* Name of savepoint */
50972
50973 /* Assert that the p1 parameter is valid. Also that if there is no open
50974 ** transaction, then there cannot be any savepoints.
50975 */
50976 assert( db->pSavepoint==0 || db->autoCommit==0 );
50977 assert( p1==SAVEPOINT_BEGIN||p1==SAVEPOINT_RELEASE||p1==SAVEPOINT_ROLLBACK );
50978 assert( db->pSavepoint || db->isTransactionSavepoint==0 );
50979 assert( checkSavepointCount(db) );
50980
50981 if( p1==SAVEPOINT_BEGIN ){
50982 if( db->writeVdbeCnt>0 ){
50983 /* A new savepoint cannot be created if there are active write
50984 ** statements (i.e. open read/write incremental blob handles).
50985 */
50986 sqlite3SetString(&p->zErrMsg, db, "cannot open savepoint - "
50987 "SQL statements in progress");
50988 rc = SQLITE_BUSY;
50989 }else{
50990 int nName = sqlite3Strlen30(zName);
50991 Savepoint *pNew;
50992
50993 /* Create a new savepoint structure. */
50994 pNew = sqlite3DbMallocRaw(db, sizeof(Savepoint)+nName+1);
50995 if( pNew ){
50996 pNew->zName = (char *)&pNew[1];
50997 memcpy(pNew->zName, zName, nName+1);
50998
50999 /* If there is no open transaction, then mark this as a special
51000 ** "transaction savepoint". */
51001 if( db->autoCommit ){
51002 db->autoCommit = 0;
51003 db->isTransactionSavepoint = 1;
51004 }else{
51005 db->nSavepoint++;
51006 }
51007
51008 /* Link the new savepoint into the database handle's list. */
51009 pNew->pNext = db->pSavepoint;
51010 db->pSavepoint = pNew;
51011 }
51012 }
51013 }else{
51014 Savepoint *pSavepoint;
51015 int iSavepoint = 0;
51016
51017 /* Find the named savepoint. If there is no such savepoint, then an
51018 ** an error is returned to the user. */
51019 for(
51020 pSavepoint=db->pSavepoint;
51021 pSavepoint && sqlite3StrICmp(pSavepoint->zName, zName);
51022 pSavepoint=pSavepoint->pNext
51023 ){
51024 iSavepoint++;
51025 }
51026 if( !pSavepoint ){
51027 sqlite3SetString(&p->zErrMsg, db, "no such savepoint: %s", zName);
51028 rc = SQLITE_ERROR;
51029 }else if(
51030 db->writeVdbeCnt>0 || (p1==SAVEPOINT_ROLLBACK && db->activeVdbeCnt>1)
51031 ){
51032 /* It is not possible to release (commit) a savepoint if there are
51033 ** active write statements. It is not possible to rollback a savepoint
51034 ** if there are any active statements at all.
51035 */
51036 sqlite3SetString(&p->zErrMsg, db,
51037 "cannot %s savepoint - SQL statements in progress",
51038 (p1==SAVEPOINT_ROLLBACK ? "rollback": "release")
51039 );
51040 rc = SQLITE_BUSY;
51041 }else{
51042
51043 /* Determine whether or not this is a transaction savepoint. If so,
51044 ** and this is a RELEASE command, then the current transaction
51045 ** is committed.
51046 */
51047 int isTransaction = pSavepoint->pNext==0 && db->isTransactionSavepoint;
51048 if( isTransaction && p1==SAVEPOINT_RELEASE ){
51049 db->autoCommit = 1;
51050 if( sqlite3VdbeHalt(p)==SQLITE_BUSY ){
51051 p->pc = pc;
51052 db->autoCommit = 0;
51053 p->rc = rc = SQLITE_BUSY;
51054 goto vdbe_return;
51055 }
51056 db->isTransactionSavepoint = 0;
51057 rc = p->rc;
51058 }else{
51059 int ii;
51060 iSavepoint = db->nSavepoint - iSavepoint - 1;
51061 for(ii=0; ii<db->nDb; ii++){
51062 rc = sqlite3BtreeSavepoint(db->aDb[ii].pBt, p1, iSavepoint);
51063 if( rc!=SQLITE_OK ){
51064 goto abort_due_to_error;
51065 }
51066 }
51067 if( p1==SAVEPOINT_ROLLBACK && (db->flags&SQLITE_InternChanges)!=0 ){
51068 sqlite3ExpirePreparedStatements(db);
51069 sqlite3ResetInternalSchema(db, 0);
51070 }
51071 }
51072
51073 /* Regardless of whether this is a RELEASE or ROLLBACK, destroy all
51074 ** savepoints nested inside of the savepoint being operated on. */
51075 while( db->pSavepoint!=pSavepoint ){
51076 Savepoint *pTmp = db->pSavepoint;
51077 db->pSavepoint = pTmp->pNext;
51078 sqlite3DbFree(db, pTmp);
51079 db->nSavepoint--;
51080 }
51081
51082 /* If it is a RELEASE, then destroy the savepoint being operated on too */
51083 if( p1==SAVEPOINT_RELEASE ){
51084 assert( pSavepoint==db->pSavepoint );
51085 db->pSavepoint = pSavepoint->pNext;
51086 sqlite3DbFree(db, pSavepoint);
51087 if( !isTransaction ){
51088 db->nSavepoint--;
51089 }
51090 }
51091 }
51092 }
51093
51094 break;
51095 }
51096
51097 /* Opcode: AutoCommit P1 P2 * * *
51098 **
51099 ** Set the database auto-commit flag to P1 (1 or 0). If P2 is true, roll
51100 ** back any currently active btree transactions. If there are any active
@@ -50606,11 +51126,11 @@
51126 */
51127 sqlite3SetString(&p->zErrMsg, db, "cannot commit transaction - "
51128 "SQL statements in progress");
51129 rc = SQLITE_BUSY;
51130 }else if( desiredAutoCommit!=db->autoCommit ){
51131 if( rollback ){
51132 assert( desiredAutoCommit==1 );
51133 sqlite3RollbackAll(db);
51134 db->autoCommit = 1;
51135 }else{
51136 db->autoCommit = (u8)desiredAutoCommit;
@@ -50619,10 +51139,11 @@
51139 db->autoCommit = (u8)(1-desiredAutoCommit);
51140 p->rc = rc = SQLITE_BUSY;
51141 goto vdbe_return;
51142 }
51143 }
51144 sqlite3CloseSavepoints(db);
51145 if( p->rc==SQLITE_OK ){
51146 rc = SQLITE_DONE;
51147 }else{
51148 rc = SQLITE_ERROR;
51149 }
@@ -52569,20 +53090,20 @@
53090 Mem *pIdx;
53091 i64 val;
53092 assert( pOp->p1>0 && pOp->p1<=p->nMem );
53093 CHECK_FOR_INTERRUPT;
53094 pIdx = &p->aMem[pOp->p1];
53095 pOut = &p->aMem[pOp->p3];
53096 if( (pIdx->flags & MEM_RowSet)==0
53097 || sqlite3RowSetNext(pIdx->u.pRowSet, &val)==0
53098 ){
53099 /* The boolean index is empty */
53100 sqlite3VdbeMemSetNull(pIdx);
53101 pc = pOp->p2 - 1;
53102 }else{
53103 /* A value was pulled from the index */
53104 assert( pOp->p3>0 && pOp->p3<=p->nMem );
 
53105 sqlite3VdbeMemSetInt64(pOut, val);
53106 }
53107 break;
53108 }
53109
@@ -54011,11 +54532,11 @@
54532 **
54533 ** This file contains code use to implement an in-memory rollback journal.
54534 ** The in-memory rollback journal is used to journal transactions for
54535 ** ":memory:" databases and when the journal_mode=MEMORY pragma is used.
54536 **
54537 ** @(#) $Id: memjournal.c,v 1.8 2008/12/20 02:14:40 drh Exp $
54538 */
54539
54540 /* Forward references to internal structures */
54541 typedef struct MemJournal MemJournal;
54542 typedef struct FilePoint FilePoint;
@@ -54236,11 +54757,11 @@
54757
54758 /*
54759 ** Return the number of bytes required to store a MemJournal that uses vfs
54760 ** pVfs to create the underlying on-disk files.
54761 */
54762 SQLITE_PRIVATE int sqlite3MemJournalSize(void){
54763 return sizeof(MemJournal);
54764 }
54765
54766 /************** End of memjournal.c ******************************************/
54767 /************** Begin file walker.c ******************************************/
@@ -60509,11 +61030,11 @@
61030 ** creating ID lists
61031 ** BEGIN TRANSACTION
61032 ** COMMIT
61033 ** ROLLBACK
61034 **
61035 ** $Id: build.c,v 1.511 2008/12/30 06:24:58 danielk1977 Exp $
61036 */
61037
61038 /*
61039 ** This routine is called when a new SQL statement is beginning to
61040 ** be parsed. Initialize the pParse structure as needed.
@@ -61440,11 +61961,11 @@
61961 if( p->nCol+1>db->aLimit[SQLITE_LIMIT_COLUMN] ){
61962 sqlite3ErrorMsg(pParse, "too many columns on %s", p->zName);
61963 return;
61964 }
61965 #endif
61966 z = sqlite3NameFromToken(db, pName);
61967 if( z==0 ) return;
61968 for(i=0; i<p->nCol; i++){
61969 if( STRICMP(z, p->aCol[i].zName) ){
61970 sqlite3ErrorMsg(pParse, "duplicate column name: %s", z);
61971 sqlite3DbFree(db, z);
@@ -61451,11 +61972,11 @@
61972 return;
61973 }
61974 }
61975 if( (p->nCol & 0x7)==0 ){
61976 Column *aNew;
61977 aNew = sqlite3DbRealloc(db,p->aCol,(p->nCol+8)*sizeof(p->aCol[0]));
61978 if( aNew==0 ){
61979 sqlite3DbFree(db, z);
61980 return;
61981 }
61982 p->aCol = aNew;
@@ -63795,10 +64316,30 @@
64316 v = sqlite3GetVdbe(pParse);
64317 if( v ){
64318 sqlite3VdbeAddOp2(v, OP_AutoCommit, 1, 1);
64319 }
64320 }
64321
64322 /*
64323 ** This function is called by the parser when it parses a command to create,
64324 ** release or rollback an SQL savepoint.
64325 */
64326 SQLITE_PRIVATE void sqlite3Savepoint(Parse *pParse, int op, Token *pName){
64327 char *zName = sqlite3NameFromToken(pParse->db, pName);
64328 if( zName ){
64329 Vdbe *v = sqlite3GetVdbe(pParse);
64330 #ifndef SQLITE_OMIT_AUTHORIZATION
64331 static const char *az[] = { "BEGIN", "RELEASE", "ROLLBACK" };
64332 assert( !SAVEPOINT_BEGIN && SAVEPOINT_RELEASE==1 && SAVEPOINT_ROLLBACK==2 );
64333 #endif
64334 if( !v || sqlite3AuthCheck(pParse, SQLITE_SAVEPOINT, az[op], zName, 0) ){
64335 sqlite3DbFree(pParse->db, zName);
64336 return;
64337 }
64338 sqlite3VdbeAddOp4(v, OP_Savepoint, op, 0, 0, zName, P4_DYNAMIC);
64339 }
64340 }
64341
64342 /*
64343 ** Make sure the TEMP database is open and available for use. Return
64344 ** the number of errors. Leave any error messages in the pParse structure.
64345 */
@@ -64540,11 +65081,11 @@
65081 **
65082 *************************************************************************
65083 ** This file contains C code routines that are called by the parser
65084 ** in order to generate code for DELETE FROM statements.
65085 **
65086 ** $Id: delete.c,v 1.191 2008/12/23 23:56:22 drh Exp $
65087 */
65088
65089 /*
65090 ** Look up every table that is named in pSrc. If any table is not found,
65091 ** add an error message to pParse->zErrMsg and return NULL. If all tables
@@ -64919,25 +65460,19 @@
65460 */
65461 {
65462 int iRowid = ++pParse->nMem; /* Used for storing rowid values. */
65463 int iRowSet = ++pParse->nMem; /* Register for rowset of rows to delete */
65464
65465 /* Collect rowids of every row to be deleted.
65466 */
65467 sqlite3VdbeAddOp2(v, OP_Null, 0, iRowSet);
65468 pWInfo = sqlite3WhereBegin(pParse, pTabList, pWhere, 0,
65469 WHERE_FILL_ROWSET, iRowSet);
65470 if( pWInfo==0 ) goto delete_from_cleanup;
 
 
 
65471 if( db->flags & SQLITE_CountRows ){
65472 sqlite3VdbeAddOp2(v, OP_AddImm, memCnt, 1);
65473 }
 
 
 
65474 sqlite3WhereEnd(pWInfo);
65475
65476 /* Open the pseudo-table used to store OLD if there are triggers.
65477 */
65478 if( triggers_exist ){
@@ -69450,11 +69985,11 @@
69985 ** May you share freely, never taking more than you give.
69986 **
69987 *************************************************************************
69988 ** This file contains code used to implement the PRAGMA command.
69989 **
69990 ** $Id: pragma.c,v 1.200 2009/01/09 21:41:17 drh Exp $
69991 */
69992
69993 /* Ignore this whole file if pragmas are disabled
69994 */
69995 #if !defined(SQLITE_OMIT_PRAGMA) && !defined(SQLITE_OMIT_PARSER)
@@ -69633,11 +70168,12 @@
70168 for(i=0, p=aPragma; i<ArraySize(aPragma); i++, p++){
70169 if( sqlite3StrICmp(zLeft, p->zName)==0 ){
70170 sqlite3 *db = pParse->db;
70171 Vdbe *v;
70172 v = sqlite3GetVdbe(pParse);
70173 assert( v!=0 ); /* Already allocated by sqlite3Pragma() */
70174 if( ALWAYS(v) ){
70175 if( zRight==0 ){
70176 returnSingleInt(pParse, p->zName, (db->flags & p->mask)!=0 );
70177 }else{
70178 if( getBoolean(zRight) ){
70179 db->flags |= p->mask;
@@ -69658,18 +70194,23 @@
70194 }
70195 return 0;
70196 }
70197 #endif /* SQLITE_OMIT_FLAG_PRAGMAS */
70198
70199 /*
70200 ** Return a human-readable name for a constraint resolution action.
70201 */
70202 static const char *actionName(u8 action){
70203 const char *zName;
70204 switch( action ){
70205 case OE_SetNull: zName = "SET NULL"; break;
70206 case OE_SetDflt: zName = "SET DEFAULT"; break;
70207 case OE_Cascade: zName = "CASCADE"; break;
70208 default: zName = "RESTRICT";
70209 assert( action==OE_Restrict ); break;
70210 }
70211 return zName;
70212 }
70213
70214 /*
70215 ** Process a pragma statement.
70216 **
@@ -69722,11 +70263,12 @@
70263 zRight = sqlite3MPrintf(db, "-%T", pValue);
70264 }else{
70265 zRight = sqlite3NameFromToken(db, pValue);
70266 }
70267
70268 assert( pId2 );
70269 zDb = pId2->n>0 ? pDb->zName : 0;
70270 if( sqlite3AuthCheck(pParse, SQLITE_PRAGMA, zLeft, zRight, zDb) ){
70271 goto pragma_out;
70272 }
70273
70274 #ifndef SQLITE_OMIT_PAGER_PRAGMAS
@@ -69790,12 +70332,13 @@
70332 ** database page size value. The value can only be set if
70333 ** the database has not yet been created.
70334 */
70335 if( sqlite3StrICmp(zLeft,"page_size")==0 ){
70336 Btree *pBt = pDb->pBt;
70337 assert( pBt!=0 );
70338 if( !zRight ){
70339 int size = ALWAYS(pBt) ? sqlite3BtreeGetPageSize(pBt) : 0;
70340 returnSingleInt(pParse, "page_size", size);
70341 }else{
70342 /* Malloc may fail when setting the page-size, as there is an internal
70343 ** buffer that the pager module resizes using sqlite3_realloc().
70344 */
@@ -69816,14 +70359,15 @@
70359 ** forms return the current setting.
70360 */
70361 if( sqlite3StrICmp(zLeft,"max_page_count")==0 ){
70362 Btree *pBt = pDb->pBt;
70363 int newMax = 0;
70364 assert( pBt!=0 );
70365 if( zRight ){
70366 newMax = atoi(zRight);
70367 }
70368 if( ALWAYS(pBt) ){
70369 newMax = sqlite3BtreeMaxPageCount(pBt, newMax);
70370 }
70371 returnSingleInt(pParse, "max_page_count", newMax);
70372 }else
70373
@@ -69832,11 +70376,11 @@
70376 **
70377 ** Return the number of pages in the specified database.
70378 */
70379 if( sqlite3StrICmp(zLeft,"page_count")==0 ){
70380 int iReg;
70381 if( sqlite3ReadSchema(pParse) ) goto pragma_out;
70382 sqlite3CodeVerifySchema(pParse, iDb);
70383 iReg = ++pParse->nMem;
70384 sqlite3VdbeAddOp2(v, OP_Pagecount, iDb, iReg);
70385 sqlite3VdbeAddOp2(v, OP_ResultRow, iReg, 1);
70386 sqlite3VdbeSetNumCols(v, 1);
@@ -69980,21 +70524,27 @@
70524 ** Get or set the (boolean) value of the database 'auto-vacuum' parameter.
70525 */
70526 #ifndef SQLITE_OMIT_AUTOVACUUM
70527 if( sqlite3StrICmp(zLeft,"auto_vacuum")==0 ){
70528 Btree *pBt = pDb->pBt;
70529 assert( pBt!=0 );
70530 if( sqlite3ReadSchema(pParse) ){
70531 goto pragma_out;
70532 }
70533 if( !zRight ){
70534 int auto_vacuum;
70535 if( ALWAYS(pBt) ){
70536 auto_vacuum = sqlite3BtreeGetAutoVacuum(pBt);
70537 }else{
70538 auto_vacuum = SQLITE_DEFAULT_AUTOVACUUM;
70539 }
70540 returnSingleInt(pParse, "auto_vacuum", auto_vacuum);
70541 }else{
70542 int eAuto = getAutoVacuum(zRight);
70543 assert( eAuto>=0 && eAuto<=2 );
70544 db->nextAutovac = (u8)eAuto;
70545 if( ALWAYS(eAuto>=0) ){
70546 /* Call SetAutoVacuum() to set initialize the internal auto and
70547 ** incr-vacuum flags. This is required in case this connection
70548 ** creates the database file. It is important that it is created
70549 ** as an auto-vacuum capable db.
70550 */
@@ -70141,10 +70691,18 @@
70691 }
70692 #endif /* SQLITE_OMIT_WSD */
70693 }
70694 }else
70695
70696 #if !defined(SQLITE_ENABLE_LOCKING_STYLE)
70697 # if defined(__APPLE__)
70698 # define SQLITE_ENABLE_LOCKING_STYLE 1
70699 # else
70700 # define SQLITE_ENABLE_LOCKING_STYLE 0
70701 # endif
70702 #endif
70703 #if SQLITE_ENABLE_LOCKING_STYLE
70704 /*
70705 ** PRAGMA [database.]lock_proxy_file
70706 ** PRAGMA [database.]lock_proxy_file = ":auto:"|"lock_file_path"
70707 **
70708 ** Return or set the value of the lock_proxy_file flag. Changing
@@ -70181,11 +70739,11 @@
70739 sqlite3ErrorMsg(pParse, "failed to set lock proxy file");
70740 goto pragma_out;
70741 }
70742 }
70743 }else
70744 #endif /* SQLITE_ENABLE_LOCKING_STYLE */
70745
70746 /*
70747 ** PRAGMA [database.]synchronous
70748 ** PRAGMA [database.]synchronous=OFF|ON|NORMAL|FULL
70749 **
@@ -70255,11 +70813,13 @@
70813 sqlite3VdbeAddOp2(v, OP_Integer, i-nHidden, 1);
70814 sqlite3VdbeAddOp4(v, OP_String8, 0, 2, 0, pCol->zName, 0);
70815 sqlite3VdbeAddOp4(v, OP_String8, 0, 3, 0,
70816 pCol->zType ? pCol->zType : "", 0);
70817 sqlite3VdbeAddOp2(v, OP_Integer, (pCol->notNull ? 1 : 0), 4);
70818 if( pCol->pDflt ){
70819 pDflt = &pCol->pDflt->span;
70820 assert( pDflt->z );
70821 sqlite3VdbeAddOp4(v, OP_String8, 0, 5, 0, (char*)pDflt->z, pDflt->n);
70822 }else{
70823 sqlite3VdbeAddOp2(v, OP_Null, 0, 5);
70824 }
70825 sqlite3VdbeAddOp2(v, OP_Integer, pCol->isPrimKey, 6);
@@ -70615,15 +71175,15 @@
71175 if( sqlite3StrICmp(zLeft, "encoding")==0 ){
71176 static const struct EncName {
71177 char *zName;
71178 u8 enc;
71179 } encnames[] = {
 
71180 { "UTF8", SQLITE_UTF8 },
71181 { "UTF-8", SQLITE_UTF8 }, /* Must be element [1] */
71182 { "UTF-16le", SQLITE_UTF16LE }, /* Must be element [2] */
71183 { "UTF-16be", SQLITE_UTF16BE }, /* Must be element [3] */
71184 { "UTF16le", SQLITE_UTF16LE },
 
71185 { "UTF16be", SQLITE_UTF16BE },
71186 { "UTF-16", 0 }, /* SQLITE_UTF16NATIVE */
71187 { "UTF16", 0 }, /* SQLITE_UTF16NATIVE */
71188 { 0, 0 }
71189 };
@@ -70631,16 +71191,14 @@
71191 if( !zRight ){ /* "PRAGMA encoding" */
71192 if( sqlite3ReadSchema(pParse) ) goto pragma_out;
71193 sqlite3VdbeSetNumCols(v, 1);
71194 sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "encoding", SQLITE_STATIC);
71195 sqlite3VdbeAddOp2(v, OP_String8, 0, 1);
71196 assert( encnames[SQLITE_UTF8].enc==SQLITE_UTF8 );
71197 assert( encnames[SQLITE_UTF16LE].enc==SQLITE_UTF16LE );
71198 assert( encnames[SQLITE_UTF16BE].enc==SQLITE_UTF16BE );
71199 sqlite3VdbeChangeP4(v, -1, encnames[ENC(pParse->db)].zName, P4_STATIC);
 
 
71200 sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 1);
71201 }else{ /* "PRAGMA encoding = XXX" */
71202 /* Only change the value of sqlite.enc if the database handle is not
71203 ** initialized. If the main database exists, the new sqlite.enc value
71204 ** will be overwritten when the schema is next loaded. If it does not
@@ -70781,12 +71339,30 @@
71339 sqlite3CreateStatementsTable(pParse);
71340 }else
71341 #endif
71342
71343 #if SQLITE_HAS_CODEC
71344 if( sqlite3StrICmp(zLeft, "key")==0 && zRight ){
71345 sqlite3_key(db, zRight, sqlite3Strlen30(zRight));
71346 }else
71347 if( sqlite3StrICmp(zLeft, "rekey")==0 && zRight ){
71348 sqlite3_rekey(db, zRight, sqlite3Strlen30(zRight));
71349 }else
71350 if( zRight && (sqlite3StrICmp(zLeft, "hexkey")==0 ||
71351 sqlite3StrICmp(zLeft, "hexrekey")==0) ){
71352 int i, h1, h2;
71353 char zKey[40];
71354 for(i=0; (h1 = zRight[i])!=0 && (h2 = zRight[i+1])!=0; i+=2){
71355 h1 += 9*(1&(h1>>6));
71356 h2 += 9*(1&(h2>>6));
71357 zKey[i/2] = (h2 & 0x0f) | ((h1 & 0xf)<<4);
71358 }
71359 if( (zLeft[3] & 0xf)==0xb ){
71360 sqlite3_key(db, zKey, i/2);
71361 }else{
71362 sqlite3_rekey(db, zKey, i/2);
71363 }
71364 }else
71365 #endif
71366 #if SQLITE_HAS_CODEC || defined(SQLITE_ENABLE_CEROD)
71367 if( sqlite3StrICmp(zLeft, "activate_extensions")==0 ){
71368 #if SQLITE_HAS_CODEC
@@ -70799,33 +71375,32 @@
71375 if( sqlite3StrNICmp(zRight, "cerod-", 6)==0 ){
71376 extern void sqlite3_activate_cerod(const char*);
71377 sqlite3_activate_cerod(&zRight[6]);
71378 }
71379 #endif
71380 }else
71381 #endif
71382
71383
71384 {/* Empty ELSE clause */}
71385
71386 /* Code an OP_Expire at the end of each PRAGMA program to cause
71387 ** the VDBE implementing the pragma to expire. Most (all?) pragmas
71388 ** are only valid for a single execution.
71389 */
71390 sqlite3VdbeAddOp2(v, OP_Expire, 1, 0);
71391
71392 /*
71393 ** Reset the safety level, in case the fullfsync flag or synchronous
71394 ** setting changed.
71395 */
71396 #ifndef SQLITE_OMIT_PAGER_PRAGMAS
71397 if( db->autoCommit ){
71398 sqlite3BtreeSetSafetyLevel(pDb->pBt, pDb->safety_level,
71399 (db->flags&SQLITE_FullFSync)!=0);
71400 }
71401 #endif
 
71402 pragma_out:
71403 sqlite3DbFree(db, zLeft);
71404 sqlite3DbFree(db, zRight);
71405 }
71406
@@ -70846,11 +71421,11 @@
71421 *************************************************************************
71422 ** This file contains the implementation of the sqlite3_prepare()
71423 ** interface, and routines that contribute to loading the database schema
71424 ** from disk.
71425 **
71426 ** $Id: prepare.c,v 1.104 2009/01/09 02:49:32 drh Exp $
71427 */
71428
71429 /*
71430 ** Fill the InitData structure with an error message that indicates
71431 ** that the database is corrupt.
@@ -71332,22 +71907,22 @@
71907 ** expr.c is trying to resolve a reference to a transient table (i.e. one
71908 ** created by a sub-select). In this case the return value of this
71909 ** function should never be used.
71910 **
71911 ** We return -1000000 instead of the more usual -1 simply because using
71912 ** -1000000 as the incorrect index into db->aDb[] is much
71913 ** more likely to cause a segfault than -1 (of course there are assert()
71914 ** statements too, but it never hurts to play the odds).
71915 */
71916 assert( sqlite3_mutex_held(db->mutex) );
71917 if( pSchema ){
71918 for(i=0; ALWAYS(i<db->nDb); i++){
71919 if( db->aDb[i].pSchema==pSchema ){
71920 break;
71921 }
71922 }
71923 assert( i>=0 && i<db->nDb );
71924 }
71925 return i;
71926 }
71927
71928 /*
@@ -71657,11 +72232,11 @@
72232 **
72233 *************************************************************************
72234 ** This file contains C code routines that are called by the parser
72235 ** to handle SELECT statements in SQLite.
72236 **
72237 ** $Id: select.c,v 1.498 2009/01/09 02:49:32 drh Exp $
72238 */
72239
72240
72241 /*
72242 ** Delete all the content of a Select structure but do not deallocate
@@ -71986,11 +72561,11 @@
72561 for(i=0; i<pSrc->nSrc-1; i++, pRight++, pLeft++){
72562 Table *pLeftTab = pLeft->pTab;
72563 Table *pRightTab = pRight->pTab;
72564 int isOuter;
72565
72566 if( NEVER(pLeftTab==0 || pRightTab==0) ) continue;
72567 isOuter = (pRight->jointype & JT_OUTER)!=0;
72568
72569 /* When the NATURAL keyword is present, add WHERE clause terms for
72570 ** every column that the two tables have in common.
72571 */
@@ -72186,11 +72761,12 @@
72761 int regResult; /* Start of memory holding result set */
72762 int eDest = pDest->eDest; /* How to dispose of results */
72763 int iParm = pDest->iParm; /* First argument to disposal method */
72764 int nResultCol; /* Number of result columns */
72765
72766 assert( v );
72767 if( NEVER(v==0) ) return;
72768 assert( pEList!=0 );
72769 hasDistinct = distinct>=0;
72770 if( pOrderBy==0 && !hasDistinct ){
72771 codeOffset(v, p, iContinue);
72772 }
@@ -72204,15 +72780,12 @@
72780 }
72781 if( pDest->iMem==0 ){
72782 pDest->iMem = pParse->nMem+1;
72783 pDest->nMem = nResultCol;
72784 pParse->nMem += nResultCol;
72785 }else{
72786 assert( pDest->nMem==nResultCol );
 
 
 
72787 }
72788 regResult = pDest->iMem;
72789 if( nColumn>0 ){
72790 for(i=0; i<nColumn; i++){
72791 sqlite3VdbeAddOp3(v, OP_Column, srcTab, i, regResult+i);
@@ -72457,10 +73030,12 @@
73030 regRowid = sqlite3GetTempReg(pParse);
73031 sqlite3VdbeAddOp3(v, OP_Column, iTab, pOrderBy->nExpr + 1, regRow);
73032 switch( eDest ){
73033 case SRT_Table:
73034 case SRT_EphemTab: {
73035 testcase( eDest==SRT_Table );
73036 testcase( eDest==SRT_EphemTab );
73037 sqlite3VdbeAddOp2(v, OP_NewRowid, iParm, regRowid);
73038 sqlite3VdbeAddOp3(v, OP_Insert, iParm, regRow, regRowid);
73039 sqlite3VdbeChangeP5(v, OPFLAG_APPEND);
73040 break;
73041 }
@@ -72480,10 +73055,12 @@
73055 }
73056 #endif
73057 case SRT_Output:
73058 case SRT_Coroutine: {
73059 int i;
73060 testcase( eDest==SRT_Output );
73061 testcase( eDest==SRT_Coroutine );
73062 sqlite3VdbeAddOp2(v, OP_Integer, 1, regRowid);
73063 sqlite3VdbeAddOp3(v, OP_Insert, pseudoTab, regRow, regRowid);
73064 for(i=0; i<nColumn; i++){
73065 assert( regRow!=pDest->iMem+i );
73066 sqlite3VdbeAddOp3(v, OP_Column, pseudoTab, i, pDest->iMem+i);
@@ -72590,11 +73167,11 @@
73167 if( pS ){
73168 /* The "table" is actually a sub-select or a view in the FROM clause
73169 ** of the SELECT statement. Return the declaration type and origin
73170 ** data for the result-set column of the sub-select.
73171 */
73172 if( ALWAYS(iCol>=0 && iCol<pS->pEList->nExpr) ){
73173 /* If iCol is less than zero, then the expression requests the
73174 ** rowid of the sub-select or view. This expression is legal (see
73175 ** test case misc2.2.2) - it always evaluates to NULL.
73176 */
73177 NameContext sNC;
@@ -72602,11 +73179,11 @@
73179 sNC.pSrcList = pS->pSrc;
73180 sNC.pNext = 0;
73181 sNC.pParse = pNC->pParse;
73182 zType = columnType(&sNC, p, &zOriginDb, &zOriginTab, &zOriginCol);
73183 }
73184 }else if( ALWAYS(pTab->pSchema) ){
73185 /* A real table */
73186 assert( !pS );
73187 if( iCol<0 ) iCol = pTab->iPKey;
73188 assert( iCol==-1 || (iCol>=0 && iCol<pTab->nCol) );
73189 if( iCol<0 ){
@@ -72711,11 +73288,11 @@
73288 return;
73289 }
73290 #endif
73291
73292 assert( v!=0 );
73293 if( pParse->colNamesSet || NEVER(v==0) || db->mallocFailed ) return;
73294 pParse->colNamesSet = 1;
73295 fullNames = (db->flags & SQLITE_FullColNames)!=0;
73296 shortNames = (db->flags & SQLITE_ShortColNames)!=0;
73297 sqlite3VdbeSetNumCols(v, pEList->nExpr);
73298 for(i=0; i<pEList->nExpr; i++){
@@ -72727,11 +73304,13 @@
73304 sqlite3VdbeSetColName(v, i, COLNAME_NAME, zName, SQLITE_TRANSIENT);
73305 }else if( (p->op==TK_COLUMN || p->op==TK_AGG_COLUMN) && pTabList ){
73306 Table *pTab;
73307 char *zCol;
73308 int iCol = p->iColumn;
73309 for(j=0; ALWAYS(j<pTabList->nSrc); j++){
73310 if( pTabList->a[j].iCursor==p->iTable ) break;
73311 }
73312 assert( j<pTabList->nSrc );
73313 pTab = pTabList->a[j].pTab;
73314 if( iCol<0 ) iCol = pTab->iPKey;
73315 assert( iCol==-1 || (iCol>=0 && iCol<pTab->nCol) );
73316 if( iCol<0 ){
@@ -72740,17 +73319,13 @@
73319 zCol = pTab->aCol[iCol].zName;
73320 }
73321 if( !shortNames && !fullNames ){
73322 sqlite3VdbeSetColName(v, i, COLNAME_NAME,
73323 sqlite3DbStrNDup(db, (char*)p->span.z, p->span.n), SQLITE_DYNAMIC);
73324 }else if( fullNames ){
73325 char *zName = 0;
73326 zName = sqlite3MPrintf(db, "%s.%s", pTab->zName, zCol);
 
 
 
 
73327 sqlite3VdbeSetColName(v, i, COLNAME_NAME, zName, SQLITE_DYNAMIC);
73328 }else{
73329 sqlite3VdbeSetColName(v, i, COLNAME_NAME, zCol, SQLITE_TRANSIENT);
73330 }
73331 }else{
@@ -73189,14 +73764,18 @@
73764 Expr *pLimit, *pOffset; /* Saved values of p->nLimit and p->nOffset */
73765 int addr;
73766 SelectDest uniondest;
73767
73768 priorOp = SRT_Union;
73769 if( dest.eDest==priorOp && ALWAYS(!p->pLimit &&!p->pOffset) ){
73770 /* We can reuse a temporary table generated by a SELECT to our
73771 ** right.
73772 */
73773 assert( p->pRightmost!=p ); /* Can only happen for leftward elements
73774 ** of a 3-way or more compound */
73775 assert( p->pLimit==0 ); /* Not allowed on leftward elements */
73776 assert( p->pOffset==0 ); /* Not allowed on leftward elements */
73777 unionTab = dest.iParm;
73778 }else{
73779 /* We will need to create our own temporary table to hold the
73780 ** intermediate results.
73781 */
@@ -74050,10 +74629,12 @@
74629 pExpr->iAgg = pNew->iAgg;
74630 sqlite3TokenCopy(db, &pExpr->token, &pNew->token);
74631 sqlite3TokenCopy(db, &pExpr->span, &pNew->span);
74632 pExpr->pSelect = sqlite3SelectDup(db, pNew->pSelect);
74633 pExpr->flags = pNew->flags;
74634 pExpr->pAggInfo = pNew->pAggInfo;
74635 pNew->pAggInfo = 0;
74636 }
74637 }else{
74638 substExpr(db, pExpr->pLeft, iTable, pEList);
74639 substExpr(db, pExpr->pRight, iTable, pEList);
74640 substSelect(db, pExpr->pSelect, iTable, pEList);
@@ -74087,11 +74668,12 @@
74668 substExprList(db, p->pOrderBy, iTable, pEList);
74669 substExpr(db, p->pHaving, iTable, pEList);
74670 substExpr(db, p->pWhere, iTable, pEList);
74671 substSelect(db, p->pPrior, iTable, pEList);
74672 pSrc = p->pSrc;
74673 assert( pSrc ); /* Even for (SELECT 1) we have: pSrc!=0 but pSrc->nSrc==0 */
74674 if( ALWAYS(pSrc) ){
74675 for(i=pSrc->nSrc, pItem=pSrc->a; i>0; i--, pItem++){
74676 substSelect(db, pItem->pSelect, iTable, pEList);
74677 }
74678 }
74679 }
@@ -74219,11 +74801,10 @@
74801 sqlite3 *db = pParse->db;
74802
74803 /* Check to see if flattening is permitted. Return 0 if not.
74804 */
74805 assert( p!=0 );
 
74806 assert( p->pPrior==0 ); /* Unable to flatten compound queries */
74807 pSrc = p->pSrc;
74808 assert( pSrc && iFrom>=0 && iFrom<pSrc->nSrc );
74809 pSubitem = &pSrc->a[iFrom];
74810 iParent = pSubitem->iCursor;
@@ -74297,11 +74878,11 @@
74878 ** use only the UNION ALL operator. And none of the simple select queries
74879 ** that make up the compound SELECT are allowed to be aggregate or distinct
74880 ** queries.
74881 */
74882 if( pSub->pPrior ){
74883 if( isAgg || (p->selFlags & SF_Distinct)!=0 || pSrc->nSrc!=1 ){
74884 return 0;
74885 }
74886 for(pSub1=pSub; pSub1; pSub1=pSub1->pPrior){
74887 if( (pSub1->selFlags & (SF_Distinct|SF_Aggregate))!=0
74888 || (pSub1->pPrior && pSub1->op!=TK_ALL)
@@ -75349,11 +75930,11 @@
75930 /* Aggregate and non-aggregate queries are handled differently */
75931 if( !isAgg && pGroupBy==0 ){
75932 /* This case is for non-aggregate queries
75933 ** Begin the database scan
75934 */
75935 pWInfo = sqlite3WhereBegin(pParse, pTabList, pWhere, &pOrderBy, 0, 0);
75936 if( pWInfo==0 ) goto select_end;
75937
75938 /* If sorting index that was created by a prior OP_OpenEphemeral
75939 ** instruction ended up not being needed, then change the OP_OpenEphemeral
75940 ** into an OP_Noop.
@@ -75470,11 +76051,11 @@
76051 ** This might involve two separate loops with an OP_Sort in between, or
76052 ** it might be a single loop that uses an index to extract information
76053 ** in the right order to begin with.
76054 */
76055 sqlite3VdbeAddOp2(v, OP_Gosub, regReset, addrReset);
76056 pWInfo = sqlite3WhereBegin(pParse, pTabList, pWhere, &pGroupBy, 0, 0);
76057 if( pWInfo==0 ) goto select_end;
76058 if( pGroupBy==0 ){
76059 /* The optimizer is able to deliver rows in group by order so
76060 ** we do not have to sort. The OP_OpenEphemeral table will be
76061 ** cancelled later because we still need to use the pKeyInfo
@@ -75668,11 +76249,11 @@
76249 /* This case runs if the aggregate has no GROUP BY clause. The
76250 ** processing is much simpler since there is only a single row
76251 ** of output.
76252 */
76253 resetAccumulator(pParse, &sAggInfo);
76254 pWInfo = sqlite3WhereBegin(pParse, pTabList, pWhere, &pMinMax, flag, 0);
76255 if( pWInfo==0 ){
76256 sqlite3ExprListDelete(db, pDel);
76257 goto select_end;
76258 }
76259 updateAccumulator(pParse, &sAggInfo);
@@ -76036,11 +76617,11 @@
76617 ** May you share freely, never taking more than you give.
76618 **
76619 *************************************************************************
76620 **
76621 **
76622 ** $Id: trigger.c,v 1.133 2008/12/26 07:56:39 danielk1977 Exp $
76623 */
76624
76625 #ifndef SQLITE_OMIT_TRIGGER
76626 /*
76627 ** Delete a linked list of TriggerStep structures.
@@ -76697,10 +77278,11 @@
77278 assert( pTriggerStep!=0 );
77279 assert( v!=0 );
77280 sqlite3VdbeAddOp2(v, OP_ContextPush, 0, 0);
77281 VdbeComment((v, "begin trigger %s", pStepList->pTrig->name));
77282 while( pTriggerStep ){
77283 sqlite3ExprClearColumnCache(pParse, -1);
77284 orconf = (orconfin == OE_Default)?pTriggerStep->orconf:orconfin;
77285 pParse->trigStack->orconf = orconf;
77286 switch( pTriggerStep->op ){
77287 case TK_SELECT: {
77288 Select *ss = sqlite3SelectDup(db, pTriggerStep->pSelect);
@@ -76894,11 +77476,11 @@
77476 **
77477 *************************************************************************
77478 ** This file contains C code routines that are called by the parser
77479 ** to handle UPDATE statements.
77480 **
77481 ** $Id: update.c,v 1.191 2008/12/23 23:56:22 drh Exp $
77482 */
77483
77484 #ifndef SQLITE_OMIT_VIRTUALTABLE
77485 /* Forward declaration */
77486 static void updateVirtualTable(
@@ -77227,11 +77809,11 @@
77809
77810 /* Begin the database scan
77811 */
77812 sqlite3VdbeAddOp2(v, OP_Null, 0, regOldRowid);
77813 pWInfo = sqlite3WhereBegin(pParse, pTabList, pWhere, 0,
77814 WHERE_ONEPASS_DESIRED, 0);
77815 if( pWInfo==0 ) goto update_cleanup;
77816 okOnePass = pWInfo->okOnePass;
77817
77818 /* Remember the rowid of every item to be updated.
77819 */
@@ -78731,11 +79313,11 @@
79313 ** generating the code that loops through a table looking for applicable
79314 ** rows. Indices are selected and used to speed the search when doing
79315 ** so is applicable. Because this module is responsible for selecting
79316 ** indices, you might also think of this module as the "query optimizer".
79317 **
79318 ** $Id: where.c,v 1.362 2009/01/09 02:49:32 drh Exp $
79319 */
79320
79321 /*
79322 ** Trace output macros
79323 */
@@ -78749,11 +79331,14 @@
79331 #endif
79332
79333 /* Forward reference
79334 */
79335 typedef struct WhereClause WhereClause;
79336 typedef struct WhereMaskSet WhereMaskSet;
79337 typedef struct WhereOrInfo WhereOrInfo;
79338 typedef struct WhereAndInfo WhereAndInfo;
79339 typedef struct WhereCost WhereCost;
79340
79341 /*
79342 ** The query generator uses an array of instances of this structure to
79343 ** help it analyze the subexpressions of the WHERE clause. Each WHERE
79344 ** clause subexpression is separated from the others by AND operators.
@@ -78769,23 +79354,36 @@
79354 ** When a term is of the form:
79355 **
79356 ** X <op> <expr>
79357 **
79358 ** where X is a column name and <op> is one of certain operators,
79359 ** then WhereTerm.leftCursor and WhereTerm.u.leftColumn record the
79360 ** cursor number and column number for X. WhereTerm.eOperator records
79361 ** the <op> using a bitmask encoding defined by WO_xxx below. The
79362 ** use of a bitmask encoding for the operator allows us to search
79363 ** quickly for terms that match any of several different operators.
79364 **
79365 ** A WhereTerm might also be two or more subterms connected by OR:
79366 **
79367 ** (t1.X <op> <expr>) OR (t1.Y <op> <expr>) OR ....
79368 **
79369 ** In this second case, wtFlag as the TERM_ORINFO set and eOperator==WO_OR
79370 ** and the WhereTerm.u.pOrInfo field points to auxiliary information that
79371 ** is collected about the
79372 **
79373 ** If a term in the WHERE clause does not match either of the two previous
79374 ** categories, then eOperator==0. The WhereTerm.pExpr field is still set
79375 ** to the original subexpression content and wtFlags is set up appropriately
79376 ** but no other fields in the WhereTerm object are meaningful.
79377 **
79378 ** When eOperator!=0, prereqRight and prereqAll record sets of cursor numbers,
79379 ** but they do so indirectly. A single WhereMaskSet structure translates
79380 ** cursor number into bits and the translated bit is stored in the prereq
79381 ** fields. The translation is used in order to maximize the number of
79382 ** bits that will fit in a Bitmask. The VDBE cursor numbers might be
79383 ** spread out over the non-negative integers. For example, the cursor
79384 ** numbers might be 3, 8, 9, 10, 20, 23, 41, and 45. The WhereMaskSet
79385 ** translates these sparse cursor numbers into consecutive integers
79386 ** beginning with 0 in order to make the best possible use of the available
79387 ** bits in the Bitmask. So, in the example above, the cursor numbers
79388 ** would be mapped into integers 0 through 7.
79389 **
@@ -78796,11 +79394,15 @@
79394 typedef struct WhereTerm WhereTerm;
79395 struct WhereTerm {
79396 Expr *pExpr; /* Pointer to the subexpression that is this term */
79397 int iParent; /* Disable pWC->a[iParent] when this term disabled */
79398 int leftCursor; /* Cursor number of X in "X <op> <expr>" */
79399 union {
79400 int leftColumn; /* Column number of X in "X <op> <expr>" */
79401 WhereOrInfo *pOrInfo; /* Extra information if eOperator==WO_OR */
79402 WhereAndInfo *pAndInfo; /* Extra information if eOperator==WO_AND */
79403 } u;
79404 u16 eOperator; /* A WO_xx value describing <op> */
79405 u8 wtFlags; /* TERM_xxx bit flags. See below */
79406 u8 nChild; /* Number of children that must disable us */
79407 WhereClause *pWC; /* The clause this term is part of */
79408 Bitmask prereqRight; /* Bitmask of tables used by pExpr->pRight */
@@ -78812,24 +79414,44 @@
79414 */
79415 #define TERM_DYNAMIC 0x01 /* Need to call sqlite3ExprDelete(db, pExpr) */
79416 #define TERM_VIRTUAL 0x02 /* Added by the optimizer. Do not code */
79417 #define TERM_CODED 0x04 /* This term is already coded */
79418 #define TERM_COPIED 0x08 /* Has a child */
79419 #define TERM_ORINFO 0x10 /* Need to free the WhereTerm.u.pOrInfo object */
79420 #define TERM_ANDINFO 0x20 /* Need to free the WhereTerm.u.pAndInfo obj */
79421 #define TERM_OR_OK 0x40 /* Used during OR-clause processing */
79422
79423 /*
79424 ** An instance of the following structure holds all information about a
79425 ** WHERE clause. Mostly this is a container for one or more WhereTerms.
79426 */
79427 struct WhereClause {
79428 Parse *pParse; /* The parser context */
79429 WhereMaskSet *pMaskSet; /* Mapping of table cursor numbers to bitmasks */
79430 u8 op; /* Split operator. TK_AND or TK_OR */
79431 int nTerm; /* Number of terms */
79432 int nSlot; /* Number of entries in a[] */
79433 WhereTerm *a; /* Each a[] describes a term of the WHERE cluase */
79434 WhereTerm aStatic[4]; /* Initial static space for a[] */
79435 };
79436
79437 /*
79438 ** A WhereTerm with eOperator==WO_OR has its u.pOrInfo pointer set to
79439 ** a dynamically allocated instance of the following structure.
79440 */
79441 struct WhereOrInfo {
79442 WhereClause wc; /* Decomposition into subterms */
79443 Bitmask indexable; /* Bitmask of all indexable tables in the clause */
79444 };
79445
79446 /*
79447 ** A WhereTerm with eOperator==WO_AND has its u.pAndInfo pointer set to
79448 ** a dynamically allocated instance of the following structure.
79449 */
79450 struct WhereAndInfo {
79451 WhereClause wc; /* The subexpression broken out */
79452 };
79453
79454 /*
79455 ** An instance of the following structure keeps track of a mapping
79456 ** between VDBE cursor numbers and bits of the bitmasks in WhereTerm.
79457 **
@@ -78839,29 +79461,38 @@
79461 ** contain gaps in the numbering sequence. But we want to make maximum
79462 ** use of the bits in our bitmasks. This structure provides a mapping
79463 ** from the sparse cursor numbers into consecutive integers beginning
79464 ** with 0.
79465 **
79466 ** If WhereMaskSet.ix[A]==B it means that The A-th bit of a Bitmask
79467 ** corresponds VDBE cursor number B. The A-th bit of a bitmask is 1<<A.
79468 **
79469 ** For example, if the WHERE clause expression used these VDBE
79470 ** cursors: 4, 5, 8, 29, 57, 73. Then the WhereMaskSet structure
79471 ** would map those cursor numbers into bits 0 through 5.
79472 **
79473 ** Note that the mapping is not necessarily ordered. In the example
79474 ** above, the mapping might go like this: 4->3, 5->1, 8->2, 29->0,
79475 ** 57->5, 73->4. Or one of 719 other combinations might be used. It
79476 ** does not really matter. What is important is that sparse cursor
79477 ** numbers all get mapped into bit numbers that begin with 0 and contain
79478 ** no gaps.
79479 */
79480 struct WhereMaskSet {
79481 int n; /* Number of assigned cursor values */
79482 int ix[BMS]; /* Cursor assigned to each bit */
79483 };
79484
79485 /*
79486 ** A WhereCost object records a lookup strategy and the estimated
79487 ** cost of pursuing that strategy.
79488 */
79489 struct WhereCost {
79490 WherePlan plan; /* The lookup strategy */
79491 double rCost; /* Overall cost of pursuing this search strategy */
79492 double nRow; /* Estimated number of output rows */
79493 };
79494
79495 /*
79496 ** Bitmasks for the operators that indices are able to exploit. An
79497 ** OR-ed combination of these values can be used when searching for
79498 ** terms in the where clause.
@@ -78872,31 +79503,36 @@
79503 #define WO_LE (WO_EQ<<(TK_LE-TK_EQ))
79504 #define WO_GT (WO_EQ<<(TK_GT-TK_EQ))
79505 #define WO_GE (WO_EQ<<(TK_GE-TK_EQ))
79506 #define WO_MATCH 0x040
79507 #define WO_ISNULL 0x080
79508 #define WO_OR 0x100 /* Two or more OR-connected terms */
79509 #define WO_AND 0x200 /* Two or more AND-connected terms */
79510
79511 #define WO_ALL 0xfff /* Mask of all possible WO_* values */
79512 #define WO_SINGLE 0x0ff /* Mask of all non-compound WO_* values */
79513
79514 /*
79515 ** Value for wsFlags returned by bestIndex() and stored in
79516 ** WhereLevel.wsFlags. These flags determine which search
79517 ** strategies are appropriate.
79518 **
79519 ** The least significant 12 bits is reserved as a mask for WO_ values above.
79520 ** The WhereLevel.wsFlags field is usually set to WO_IN|WO_EQ|WO_ISNULL.
79521 ** But if the table is the right table of a left join, WhereLevel.wsFlags
79522 ** is set to WO_IN|WO_EQ. The WhereLevel.wsFlags field can then be used as
79523 ** the "op" parameter to findTerm when we are resolving equality constraints.
79524 ** ISNULL constraints will then not be used on the right table of a left
79525 ** join. Tickets #2177 and #2189.
79526 */
79527 #define WHERE_ROWID_EQ 0x00001000 /* rowid=EXPR or rowid IN (...) */
79528 #define WHERE_ROWID_RANGE 0x00002000 /* rowid<EXPR and/or rowid>EXPR */
79529 #define WHERE_COLUMN_EQ 0x00010000 /* x=EXPR or x IN (...) */
79530 #define WHERE_COLUMN_RANGE 0x00020000 /* x<EXPR and/or x>EXPR */
79531 #define WHERE_COLUMN_IN 0x00040000 /* x IN (...) */
79532 #define WHERE_INDEXED 0x00070000 /* Anything that uses an index */
79533 #define WHERE_IN_ABLE 0x00071000 /* Able to support an IN operator */
79534 #define WHERE_TOP_LIMIT 0x00100000 /* x<EXPR or x<=EXPR constraint */
79535 #define WHERE_BTM_LIMIT 0x00200000 /* x>EXPR or x>=EXPR constraint */
79536 #define WHERE_IDX_ONLY 0x00800000 /* Use index only - omit table */
79537 #define WHERE_ORDERBY 0x01000000 /* Output will appear in correct order */
79538 #define WHERE_REVERSE 0x02000000 /* Scan in reverse order */
@@ -78908,18 +79544,37 @@
79544 ** Initialize a preallocated WhereClause structure.
79545 */
79546 static void whereClauseInit(
79547 WhereClause *pWC, /* The WhereClause to be initialized */
79548 Parse *pParse, /* The parsing context */
79549 WhereMaskSet *pMaskSet /* Mapping from table cursor numbers to bitmasks */
79550 ){
79551 pWC->pParse = pParse;
79552 pWC->pMaskSet = pMaskSet;
79553 pWC->nTerm = 0;
79554 pWC->nSlot = ArraySize(pWC->aStatic);
79555 pWC->a = pWC->aStatic;
79556 }
79557
79558 /* Forward reference */
79559 static void whereClauseClear(WhereClause*);
79560
79561 /*
79562 ** Deallocate all memory associated with a WhereOrInfo object.
79563 */
79564 static void whereOrInfoDelete(sqlite3 *db, WhereOrInfo *p){
79565 whereClauseClear(&p->wc);
79566 sqlite3DbFree(db, p);
79567 }
79568
79569 /*
79570 ** Deallocate all memory associated with a WhereAndInfo object.
79571 */
79572 static void whereAndInfoDelete(sqlite3 *db, WhereAndInfo *p){
79573 whereClauseClear(&p->wc);
79574 sqlite3DbFree(db, p);
79575 }
79576
79577 /*
79578 ** Deallocate a WhereClause structure. The WhereClause structure
79579 ** itself is not freed. This routine is the inverse of whereClauseInit().
79580 */
@@ -78929,10 +79584,15 @@
79584 sqlite3 *db = pWC->pParse->db;
79585 for(i=pWC->nTerm-1, a=pWC->a; i>=0; i--, a++){
79586 if( a->wtFlags & TERM_DYNAMIC ){
79587 sqlite3ExprDelete(db, a->pExpr);
79588 }
79589 if( a->wtFlags & TERM_ORINFO ){
79590 whereOrInfoDelete(db, a->u.pOrInfo);
79591 }else if( a->wtFlags & TERM_ANDINFO ){
79592 whereAndInfoDelete(db, a->u.pAndInfo);
79593 }
79594 }
79595 if( pWC->a!=pWC->aStatic ){
79596 sqlite3DbFree(db, pWC->a);
79597 }
79598 }
@@ -79000,10 +79660,11 @@
79660 ** In the previous sentence and in the diagram, "slot[]" refers to
79661 ** the WhereClause.a[] array. The slot[] array grows as needed to contain
79662 ** all terms of the WHERE clause.
79663 */
79664 static void whereSplit(WhereClause *pWC, Expr *pExpr, int op){
79665 pWC->op = (u8)op;
79666 if( pExpr==0 ) return;
79667 if( pExpr->op!=op ){
79668 whereClauseInsert(pWC, pExpr, 0);
79669 }else{
79670 whereSplit(pWC, pExpr->pLeft, op);
@@ -79018,11 +79679,11 @@
79679
79680 /*
79681 ** Return the bitmask for the given cursor number. Return 0 if
79682 ** iCursor is not in the set.
79683 */
79684 static Bitmask getMask(WhereMaskSet *pMaskSet, int iCursor){
79685 int i;
79686 for(i=0; i<pMaskSet->n; i++){
79687 if( pMaskSet->ix[i]==iCursor ){
79688 return ((Bitmask)1)<<i;
79689 }
@@ -79036,11 +79697,11 @@
79697 ** There is one cursor per table in the FROM clause. The number of
79698 ** tables in the FROM clause is limited by a test early in the
79699 ** sqlite3WhereBegin() routine. So we know that the pMaskSet->ix[]
79700 ** array will never overflow.
79701 */
79702 static void createMask(WhereMaskSet *pMaskSet, int iCursor){
79703 assert( pMaskSet->n < ArraySize(pMaskSet->ix) );
79704 pMaskSet->ix[pMaskSet->n++] = iCursor;
79705 }
79706
79707 /*
@@ -79055,13 +79716,13 @@
79716 ** sets their opcodes to TK_COLUMN and their Expr.iTable fields to
79717 ** the VDBE cursor number of the table. This routine just has to
79718 ** translate the cursor numbers into bitmask values and OR all
79719 ** the bitmasks together.
79720 */
79721 static Bitmask exprListTableUsage(WhereMaskSet*, ExprList*);
79722 static Bitmask exprSelectTableUsage(WhereMaskSet*, Select*);
79723 static Bitmask exprTableUsage(WhereMaskSet *pMaskSet, Expr *p){
79724 Bitmask mask = 0;
79725 if( p==0 ) return 0;
79726 if( p->op==TK_COLUMN ){
79727 mask = getMask(pMaskSet, p->iTable);
79728 return mask;
@@ -79070,21 +79731,21 @@
79731 mask |= exprTableUsage(pMaskSet, p->pLeft);
79732 mask |= exprListTableUsage(pMaskSet, p->pList);
79733 mask |= exprSelectTableUsage(pMaskSet, p->pSelect);
79734 return mask;
79735 }
79736 static Bitmask exprListTableUsage(WhereMaskSet *pMaskSet, ExprList *pList){
79737 int i;
79738 Bitmask mask = 0;
79739 if( pList ){
79740 for(i=0; i<pList->nExpr; i++){
79741 mask |= exprTableUsage(pMaskSet, pList->a[i].pExpr);
79742 }
79743 }
79744 return mask;
79745 }
79746 static Bitmask exprSelectTableUsage(WhereMaskSet *pMaskSet, Select *pS){
79747 Bitmask mask = 0;
79748 while( pS ){
79749 mask |= exprListTableUsage(pMaskSet, pS->pEList);
79750 mask |= exprListTableUsage(pMaskSet, pS->pGroupBy);
79751 mask |= exprListTableUsage(pMaskSet, pS->pOrderBy);
@@ -79153,18 +79814,15 @@
79814 assert( allowedOp(op) );
79815 if( op==TK_IN ){
79816 c = WO_IN;
79817 }else if( op==TK_ISNULL ){
79818 c = WO_ISNULL;
 
 
79819 }else{
79820 assert( (WO_EQ<<(op-TK_EQ)) < 0x7fff );
79821 c = (u16)(WO_EQ<<(op-TK_EQ));
79822 }
79823 assert( op!=TK_ISNULL || c==WO_ISNULL );
 
79824 assert( op!=TK_IN || c==WO_IN );
79825 assert( op!=TK_EQ || c==WO_EQ );
79826 assert( op!=TK_LT || c==WO_LT );
79827 assert( op!=TK_LE || c==WO_LE );
79828 assert( op!=TK_GT || c==WO_GT );
@@ -79191,11 +79849,11 @@
79849 assert( iCur>=0 );
79850 op &= WO_ALL;
79851 for(pTerm=pWC->a, k=pWC->nTerm; k; k--, pTerm++){
79852 if( pTerm->leftCursor==iCur
79853 && (pTerm->prereqRight & notReady)==0
79854 && pTerm->u.leftColumn==iColumn
79855 && (pTerm->eOperator & op)!=0
79856 ){
79857 if( pIdx && pTerm->eOperator!=WO_ISNULL ){
79858 Expr *pX = pTerm->pExpr;
79859 CollSeq *pColl;
@@ -79210,18 +79868,16 @@
79868 ** it to be useful for optimising expression pX. Store this
79869 ** value in variable pColl.
79870 */
79871 assert(pX->pLeft);
79872 pColl = sqlite3BinaryCompareCollSeq(pParse, pX->pLeft, pX->pRight);
79873 assert(pColl || pParse->nErr);
 
 
79874
79875 for(j=0; pIdx->aiColumn[j]!=iColumn; j++){
79876 if( NEVER(j>=pIdx->nColumn) ) return 0;
79877 }
79878 if( pColl && sqlite3StrICmp(pColl->zName, pIdx->azColl[j]) ) continue;
79879 }
79880 return pTerm;
79881 }
79882 }
79883 return 0;
@@ -79259,28 +79915,28 @@
79915 Expr *pExpr, /* Test this expression */
79916 int *pnPattern, /* Number of non-wildcard prefix characters */
79917 int *pisComplete, /* True if the only wildcard is % in the last character */
79918 int *pnoCase /* True if uppercase is equivalent to lowercase */
79919 ){
79920 const char *z; /* String on RHS of LIKE operator */
79921 Expr *pRight, *pLeft; /* Right and left size of LIKE operator */
79922 ExprList *pList; /* List of operands to the LIKE operator */
79923 int c; /* One character in z[] */
79924 int cnt; /* Number of non-wildcard prefix characters */
79925 char wc[3]; /* Wildcard characters */
79926 CollSeq *pColl; /* Collating sequence for LHS */
79927 sqlite3 *db = pParse->db; /* Database connection */
79928
79929 if( !sqlite3IsLikeFunction(db, pExpr, pnoCase, wc) ){
79930 return 0;
79931 }
79932 #ifdef SQLITE_EBCDIC
79933 if( *pnoCase ) return 0;
79934 #endif
79935 pList = pExpr->pList;
79936 pRight = pList->a[0].pExpr;
79937 if( pRight->op!=TK_STRING ){
 
79938 return 0;
79939 }
79940 pLeft = pList->a[1].pExpr;
79941 if( pLeft->op!=TK_COLUMN ){
79942 return 0;
@@ -79299,11 +79955,11 @@
79955 z = (char *)pRight->token.z;
79956 cnt = 0;
79957 if( z ){
79958 while( (c=z[cnt])!=0 && c!=wc[0] && c!=wc[1] && c!=wc[2] ){ cnt++; }
79959 }
79960 if( cnt==0 || 255==(u8)z[cnt-1] ){
79961 return 0;
79962 }
79963 *pisComplete = z[cnt]==wc[0] && z[cnt+1]==0;
79964 *pnPattern = cnt;
79965 return 1;
@@ -79351,124 +80007,312 @@
80007 pDerived->iRightJoinTable = pBase->iRightJoinTable;
80008 }
80009
80010 #if !defined(SQLITE_OMIT_OR_OPTIMIZATION) && !defined(SQLITE_OMIT_SUBQUERY)
80011 /*
80012 ** Analyze a term that consists of two or more OR-connected
80013 ** subterms. So in:
80014 **
80015 ** ... WHERE (a=5) AND (b=7 OR c=9 OR d=13) AND (d=13)
80016 ** ^^^^^^^^^^^^^^^^^^^^
80017 **
80018 ** This routine analyzes terms such as the middle term in the above example.
80019 ** A WhereOrTerm object is computed and attached to the term under
80020 ** analysis, regardless of the outcome of the analysis. Hence:
80021 **
80022 ** WhereTerm.wtFlags |= TERM_ORINFO
80023 ** WhereTerm.u.pOrInfo = a dynamically allocated WhereOrTerm object
80024 **
80025 ** The term being analyzed must have two or more of OR-connected subterms.
80026 ** A single subterm might be a set of AND-connected sub-subterms.
80027 ** Examples of terms under analysis:
80028 **
80029 ** (A) t1.x=t2.y OR t1.x=t2.z OR t1.y=15 OR t1.z=t3.a+5
80030 ** (B) x=expr1 OR expr2=x OR x=expr3
80031 ** (C) t1.x=t2.y OR (t1.x=t2.z AND t1.y=15)
80032 ** (D) x=expr1 OR (y>11 AND y<22 AND z LIKE '*hello*')
80033 ** (E) (p.a=1 AND q.b=2 AND r.c=3) OR (p.x=4 AND q.y=5 AND r.z=6)
80034 **
80035 ** CASE 1:
80036 **
80037 ** If all subterms are of the form T.C=expr for some single column of C
80038 ** a single table T (as shown in example B above) then create a new virtual
80039 ** term that is an equivalent IN expression. In other words, if the term
80040 ** being analyzed is:
80041 **
80042 ** x = expr1 OR expr2 = x OR x = expr3
80043 **
80044 ** then create a new virtual term like this:
80045 **
80046 ** x IN (expr1,expr2,expr3)
80047 **
80048 ** CASE 2:
80049 **
80050 ** If all subterms are indexable by a single table T, then set
80051 **
80052 ** WhereTerm.eOperator = WO_OR
80053 ** WhereTerm.u.pOrInfo->indexable |= the cursor number for table T
80054 **
80055 ** A subterm is "indexable" if it is of the form
80056 ** "T.C <op> <expr>" where C is any column of table T and
80057 ** <op> is one of "=", "<", "<=", ">", ">=", "IS NULL", or "IN".
80058 ** A subterm is also indexable if it is an AND of two or more
80059 ** subsubterms at least one of which is indexable. Indexable AND
80060 ** subterms have their eOperator set to WO_AND and they have
80061 ** u.pAndInfo set to a dynamically allocated WhereAndTerm object.
80062 **
80063 ** From another point of view, "indexable" means that the subterm could
80064 ** potentially be used with an index if an appropriate index exists.
80065 ** This analysis does not consider whether or not the index exists; that
80066 ** is something the bestIndex() routine will determine. This analysis
80067 ** only looks at whether subterms appropriate for indexing exist.
80068 **
80069 ** All examples A through E above all satisfy case 2. But if a term
80070 ** also statisfies case 1 (such as B) we know that the optimizer will
80071 ** always prefer case 1, so in that case we pretend that case 2 is not
80072 ** satisfied.
80073 **
80074 ** It might be the case that multiple tables are indexable. For example,
80075 ** (E) above is indexable on tables P, Q, and R.
80076 **
80077 ** Terms that satisfy case 2 are candidates for lookup by using
80078 ** separate indices to find rowids for each subterm and composing
80079 ** the union of all rowids using a RowSet object. This is similar
80080 ** to "bitmap indices" in other database engines.
80081 **
80082 ** OTHERWISE:
80083 **
80084 ** If neither case 1 nor case 2 apply, then leave the eOperator set to
80085 ** zero. This term is not useful for search.
80086 */
80087 static void exprAnalyzeOrTerm(
80088 SrcList *pSrc, /* the FROM clause */
80089 WhereClause *pWC, /* the complete WHERE clause */
80090 int idxTerm /* Index of the OR-term to be analyzed */
80091 ){
80092 Parse *pParse = pWC->pParse; /* Parser context */
80093 sqlite3 *db = pParse->db; /* Database connection */
80094 WhereTerm *pTerm = &pWC->a[idxTerm]; /* The term to be analyzed */
80095 Expr *pExpr = pTerm->pExpr; /* The expression of the term */
80096 WhereMaskSet *pMaskSet = pWC->pMaskSet; /* Table use masks */
80097 int i; /* Loop counters */
80098 WhereClause *pOrWc; /* Breakup of pTerm into subterms */
80099 WhereTerm *pOrTerm; /* A Sub-term within the pOrWc */
80100 WhereOrInfo *pOrInfo; /* Additional information associated with pTerm */
80101 Bitmask chngToIN; /* Tables that might satisfy case 1 */
80102 Bitmask indexable; /* Tables that are indexable, satisfying case 2 */
80103
80104 /*
80105 ** Break the OR clause into its separate subterms. The subterms are
80106 ** stored in a WhereClause structure containing within the WhereOrInfo
80107 ** object that is attached to the original OR clause term.
80108 */
80109 assert( (pTerm->wtFlags & (TERM_DYNAMIC|TERM_ORINFO|TERM_ANDINFO))==0 );
80110 assert( pExpr->op==TK_OR );
80111 pTerm->u.pOrInfo = pOrInfo = sqlite3DbMallocZero(db, sizeof(*pOrInfo));
80112 if( pOrInfo==0 ) return;
80113 pTerm->wtFlags |= TERM_ORINFO;
80114 pOrWc = &pOrInfo->wc;
80115 whereClauseInit(pOrWc, pWC->pParse, pMaskSet);
80116 whereSplit(pOrWc, pExpr, TK_OR);
80117 exprAnalyzeAll(pSrc, pOrWc);
80118 if( db->mallocFailed ) return;
80119 assert( pOrWc->nTerm>=2 );
80120
80121 /*
80122 ** Compute the set of tables that might satisfy cases 1 or 2.
80123 */
80124 indexable = chngToIN = ~(Bitmask)0;
80125 for(i=pOrWc->nTerm-1, pOrTerm=pOrWc->a; i>=0 && indexable; i--, pOrTerm++){
80126 if( (pOrTerm->eOperator & WO_SINGLE)==0 ){
80127 WhereAndInfo *pAndInfo;
80128 assert( pOrTerm->eOperator==0 );
80129 assert( (pOrTerm->wtFlags & (TERM_ANDINFO|TERM_ORINFO))==0 );
80130 chngToIN = 0;
80131 pAndInfo = sqlite3DbMallocRaw(db, sizeof(*pAndInfo));
80132 if( pAndInfo ){
80133 WhereClause *pAndWC;
80134 WhereTerm *pAndTerm;
80135 int j;
80136 Bitmask b = 0;
80137 pOrTerm->u.pAndInfo = pAndInfo;
80138 pOrTerm->wtFlags |= TERM_ANDINFO;
80139 pOrTerm->eOperator = WO_AND;
80140 pAndWC = &pAndInfo->wc;
80141 whereClauseInit(pAndWC, pWC->pParse, pMaskSet);
80142 whereSplit(pAndWC, pOrTerm->pExpr, TK_AND);
80143 exprAnalyzeAll(pSrc, pAndWC);
80144 testcase( db->mallocFailed );
80145 for(j=0, pAndTerm=pAndWC->a; j<pAndWC->nTerm; j++, pAndTerm++){
80146 assert( pAndTerm->pExpr );
80147 if( allowedOp(pAndTerm->pExpr->op) ){
80148 b |= getMask(pMaskSet, pAndTerm->leftCursor);
80149 }
80150 }
80151 indexable &= b;
80152 }
80153 }else if( pOrTerm->wtFlags & TERM_COPIED ){
80154 /* Skip this term for now. We revisit it when we process the
80155 ** corresponding TERM_VIRTUAL term */
80156 }else{
80157 Bitmask b;
80158 b = getMask(pMaskSet, pOrTerm->leftCursor);
80159 if( pOrTerm->wtFlags & TERM_VIRTUAL ){
80160 WhereTerm *pOther = &pOrWc->a[pOrTerm->iParent];
80161 b |= getMask(pMaskSet, pOther->leftCursor);
80162 }
80163 indexable &= b;
80164 if( pOrTerm->eOperator!=WO_EQ ){
80165 chngToIN = 0;
80166 }else{
80167 chngToIN &= b;
80168 }
80169 }
80170 }
80171
80172 /*
80173 ** Record the set of tables that satisfy case 2. The set might be
80174 ** empty.
80175 */
80176 pOrInfo->indexable = indexable;
80177 pTerm->eOperator = indexable==0 ? 0 : WO_OR;
80178
80179 /*
80180 ** chngToIN holds a set of tables that *might* satisfy case 1. But
80181 ** we have to do some additional checking to see if case 1 really
80182 ** is satisfied.
80183 */
80184 if( chngToIN ){
80185 int okToChngToIN = 0; /* True if the conversion to IN is valid */
80186 int iColumn = -1; /* Column index on lhs of IN operator */
80187 int iCursor; /* Table cursor common to all terms */
80188 int j = 0; /* Loop counter */
80189
80190 /* Search for a table and column that appears on one side or the
80191 ** other of the == operator in every subterm. That table and column
80192 ** will be recorded in iCursor and iColumn. There might not be any
80193 ** such table and column. Set okToChngToIN if an appropriate table
80194 ** and column is found but leave okToChngToIN false if not found.
80195 */
80196 for(j=0; j<2 && !okToChngToIN; j++){
80197 pOrTerm = pOrWc->a;
80198 for(i=pOrWc->nTerm-1; i>=0; i--, pOrTerm++){
80199 assert( pOrTerm->eOperator==WO_EQ );
80200 pOrTerm->wtFlags &= ~TERM_OR_OK;
80201 if( pOrTerm->leftCursor==iColumn ) continue;
80202 if( (chngToIN & getMask(pMaskSet, pOrTerm->leftCursor))==0 ) continue;
80203 iColumn = pOrTerm->u.leftColumn;
80204 iCursor = pOrTerm->leftCursor;
80205 break;
80206 }
80207 if( i<0 ){
80208 assert( j==1 );
80209 assert( (chngToIN&(chngToIN-1))==0 );
80210 assert( chngToIN==getMask(pMaskSet, iColumn) );
80211 break;
80212 }
80213 okToChngToIN = 1;
80214 for(; i>=0 && okToChngToIN; i--, pOrTerm++){
80215 assert( pOrTerm->eOperator==WO_EQ );
80216 if( pOrTerm->leftCursor!=iCursor ){
80217 pOrTerm->wtFlags &= ~TERM_OR_OK;
80218 }else if( pOrTerm->u.leftColumn!=iColumn ){
80219 okToChngToIN = 0;
80220 }else{
80221 int affLeft, affRight;
80222 /* If the right-hand side is also a column, then the affinities
80223 ** of both right and left sides must be such that no type
80224 ** conversions are required on the right. (Ticket #2249)
80225 */
80226 affRight = sqlite3ExprAffinity(pOrTerm->pExpr->pRight);
80227 affLeft = sqlite3ExprAffinity(pOrTerm->pExpr->pLeft);
80228 if( affRight!=0 && affRight!=affLeft ){
80229 okToChngToIN = 0;
80230 }else{
80231 pOrTerm->wtFlags |= TERM_OR_OK;
80232 }
80233 }
80234 }
80235 }
80236
80237 /* At this point, okToChngToIN is true if original pTerm satisfies
80238 ** case 1. In that case, construct a new virtual term that is
80239 ** pTerm converted into an IN operator.
80240 */
80241 if( okToChngToIN ){
80242 Expr *pDup; /* A transient duplicate expression */
80243 ExprList *pList = 0; /* The RHS of the IN operator */
80244 Expr *pLeft = 0; /* The LHS of the IN operator */
80245 Expr *pNew; /* The complete IN operator */
80246
80247 for(i=pOrWc->nTerm-1, pOrTerm=pOrWc->a; i>=0; i--, pOrTerm++){
80248 if( (pOrTerm->wtFlags & TERM_OR_OK)==0 ) continue;
80249 assert( pOrTerm->eOperator==WO_EQ );
80250 assert( pOrTerm->leftCursor==iCursor );
80251 assert( pOrTerm->u.leftColumn==iColumn );
80252 pDup = sqlite3ExprDup(db, pOrTerm->pExpr->pRight);
80253 pList = sqlite3ExprListAppend(pWC->pParse, pList, pDup, 0);
80254 pLeft = pOrTerm->pExpr->pLeft;
80255 }
80256 assert( pLeft!=0 );
80257 pDup = sqlite3ExprDup(db, pLeft);
80258 pNew = sqlite3Expr(db, TK_IN, pDup, 0, 0);
80259 if( pNew ){
80260 int idxNew;
80261 transferJoinMarkings(pNew, pExpr);
80262 pNew->pList = pList;
80263 idxNew = whereClauseInsert(pWC, pNew, TERM_VIRTUAL|TERM_DYNAMIC);
80264 testcase( idxNew==0 );
80265 exprAnalyze(pSrc, pWC, idxNew);
80266 pTerm = &pWC->a[idxTerm];
80267 pWC->a[idxNew].iParent = idxTerm;
80268 pTerm->nChild = 1;
80269 }else{
80270 sqlite3ExprListDelete(db, pList);
80271 }
80272 pTerm->eOperator = 0; /* case 1 trumps case 2 */
80273 }
80274 }
80275 }
80276 #endif /* !SQLITE_OMIT_OR_OPTIMIZATION && !SQLITE_OMIT_SUBQUERY */
80277
80278
80279 /*
80280 ** The input to this routine is an WhereTerm structure with only the
80281 ** "pExpr" field filled in. The job of this routine is to analyze the
80282 ** subexpression and populate all the other fields of the WhereTerm
80283 ** structure.
80284 **
80285 ** If the expression is of the form "<expr> <op> X" it gets commuted
80286 ** to the standard form of "X <op> <expr>".
80287 **
80288 ** If the expression is of the form "X <op> Y" where both X and Y are
80289 ** columns, then the original expression is unchanged and a new virtual
80290 ** term of the form "Y <op> X" is added to the WHERE clause and
80291 ** analyzed separately. The original term is marked with TERM_COPIED
80292 ** and the new term is marked with TERM_DYNAMIC (because it's pExpr
80293 ** needs to be freed with the WhereClause) and TERM_VIRTUAL (because it
80294 ** is a commuted copy of a prior term.) The original term has nChild=1
80295 ** and the copy has idxParent set to the index of the original term.
80296 */
80297 static void exprAnalyze(
80298 SrcList *pSrc, /* the FROM clause */
80299 WhereClause *pWC, /* the WHERE clause */
80300 int idxTerm /* Index of the term to be analyzed */
80301 ){
80302 WhereTerm *pTerm; /* The term to be analyzed */
80303 WhereMaskSet *pMaskSet; /* Set of table index masks */
80304 Expr *pExpr; /* The expression to be analyzed */
80305 Bitmask prereqLeft; /* Prerequesites of the pExpr->pLeft */
80306 Bitmask prereqAll; /* Prerequesites of pExpr */
80307 Bitmask extraRight = 0;
80308 int nPattern;
80309 int isComplete;
80310 int noCase;
80311 int op; /* Top-level operator. pExpr->op */
80312 Parse *pParse = pWC->pParse; /* Parsing context */
80313 sqlite3 *db = pParse->db; /* Database connection */
80314
80315 if( db->mallocFailed ){
80316 return;
80317 }
80318 pTerm = &pWC->a[idxTerm];
@@ -79499,11 +80343,11 @@
80343 if( allowedOp(op) && (pTerm->prereqRight & prereqLeft)==0 ){
80344 Expr *pLeft = pExpr->pLeft;
80345 Expr *pRight = pExpr->pRight;
80346 if( pLeft->op==TK_COLUMN ){
80347 pTerm->leftCursor = pLeft->iTable;
80348 pTerm->u.leftColumn = pLeft->iColumn;
80349 pTerm->eOperator = operatorMask(op);
80350 }
80351 if( pRight && pRight->op==TK_COLUMN ){
80352 WhereTerm *pNew;
80353 Expr *pDup;
@@ -79526,22 +80370,34 @@
80370 pNew = pTerm;
80371 }
80372 exprCommute(pParse, pDup);
80373 pLeft = pDup->pLeft;
80374 pNew->leftCursor = pLeft->iTable;
80375 pNew->u.leftColumn = pLeft->iColumn;
80376 pNew->prereqRight = prereqLeft;
80377 pNew->prereqAll = prereqAll;
80378 pNew->eOperator = operatorMask(pDup->op);
80379 }
80380 }
80381
80382 #ifndef SQLITE_OMIT_BETWEEN_OPTIMIZATION
80383 /* If a term is the BETWEEN operator, create two new virtual terms
80384 ** that define the range that the BETWEEN implements. For example:
80385 **
80386 ** a BETWEEN b AND c
80387 **
80388 ** is converted into:
80389 **
80390 ** (a BETWEEN b AND c) AND (a>=b) AND (a<=c)
80391 **
80392 ** The two new terms are added onto the end of the WhereClause object.
80393 ** The new terms are "dynamic" and are children of the original BETWEEN
80394 ** term. That means that if the BETWEEN term is coded, the children are
80395 ** skipped. Or, if the children are satisfied by an index, the original
80396 ** BETWEEN term is skipped.
80397 */
80398 else if( pExpr->op==TK_BETWEEN && pWC->op==TK_AND ){
80399 ExprList *pList = pExpr->pList;
80400 int i;
80401 static const u8 ops[] = {TK_GE, TK_LE};
80402 assert( pList!=0 );
80403 assert( pList->nExpr==2 );
@@ -79559,83 +80415,16 @@
80415 pTerm->nChild = 2;
80416 }
80417 #endif /* SQLITE_OMIT_BETWEEN_OPTIMIZATION */
80418
80419 #if !defined(SQLITE_OMIT_OR_OPTIMIZATION) && !defined(SQLITE_OMIT_SUBQUERY)
80420 /* Analyze a term that is composed of two or more subterms connected by
80421 ** an OR operator.
 
 
 
 
 
 
 
 
 
80422 */
80423 else if( pExpr->op==TK_OR ){
80424 assert( pWC->op==TK_AND );
80425 exprAnalyzeOrTerm(pSrc, pWC, idxTerm);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
80426 }
80427 #endif /* SQLITE_OMIT_OR_OPTIMIZATION */
80428
80429 #ifndef SQLITE_OMIT_LIKE_OPTIMIZATION
80430 /* Add constraints to reduce the search space on a LIKE or GLOB
@@ -79646,11 +80435,12 @@
80435 ** x>='abc' AND x<'abd' AND x LIKE 'abc%'
80436 **
80437 ** The last character of the prefix "abc" is incremented to form the
80438 ** termination condition "abd".
80439 */
80440 if( isLikeOrGlob(pParse, pExpr, &nPattern, &isComplete, &noCase)
80441 && pWC->op==TK_AND ){
80442 Expr *pLeft, *pRight;
80443 Expr *pStr1, *pStr2;
80444 Expr *pNewExpr1, *pNewExpr2;
80445 int idxNew1, idxNew2;
80446
@@ -79714,11 +80504,11 @@
80504 idxNew = whereClauseInsert(pWC, pNewExpr, TERM_VIRTUAL|TERM_DYNAMIC);
80505 testcase( idxNew==0 );
80506 pNewTerm = &pWC->a[idxNew];
80507 pNewTerm->prereqRight = prereqExpr;
80508 pNewTerm->leftCursor = pLeft->iTable;
80509 pNewTerm->u.leftColumn = pLeft->iColumn;
80510 pNewTerm->eOperator = WO_MATCH;
80511 pNewTerm->iParent = idxTerm;
80512 pTerm = &pWC->a[idxTerm];
80513 pTerm->nChild = 1;
80514 pTerm->wtFlags |= TERM_COPIED;
@@ -79737,11 +80527,11 @@
80527 ** Return TRUE if any of the expressions in pList->a[iFirst...] contain
80528 ** a reference to any table other than the iBase table.
80529 */
80530 static int referencesOtherTables(
80531 ExprList *pList, /* Search expressions in ths list */
80532 WhereMaskSet *pMaskSet, /* Mapping from tables to bitmaps */
80533 int iFirst, /* Be searching with the iFirst-th expression */
80534 int iBase /* Ignore references to this table */
80535 ){
80536 Bitmask allowed = ~getMask(pMaskSet, iBase);
80537 while( iFirst<pList->nExpr ){
@@ -79772,11 +80562,11 @@
80562 ** set to 1 if the ORDER BY clause is all DESC and it is set to 0 if
80563 ** the ORDER BY clause is all ASC.
80564 */
80565 static int isSortingIndex(
80566 Parse *pParse, /* Parsing context */
80567 WhereMaskSet *pMaskSet, /* Mapping from table cursor numbers to bitmaps */
80568 Index *pIdx, /* The index we are testing */
80569 int base, /* Cursor number for the table to be sorted */
80570 ExprList *pOrderBy, /* The ORDER BY clause */
80571 int nEqCol, /* Number of index columns with == constraints */
80572 int *pbRev /* Set to 1 if ORDER BY is DESC */
@@ -79895,11 +80685,11 @@
80685 ** true for reverse ROWID and false for forward ROWID order.
80686 */
80687 static int sortableByRowid(
80688 int base, /* Cursor number for table to be sorted */
80689 ExprList *pOrderBy, /* The ORDER BY clause */
80690 WhereMaskSet *pMaskSet, /* Mapping from table cursors to bitmaps */
80691 int *pbRev /* Set to 1 if ORDER BY is DESC */
80692 ){
80693 Expr *p;
80694
80695 assert( pOrderBy!=0 );
@@ -80076,11 +80866,11 @@
80866 if( pTerm->leftCursor != pSrc->iCursor ) continue;
80867 assert( (pTerm->eOperator&(pTerm->eOperator-1))==0 );
80868 testcase( pTerm->eOperator==WO_IN );
80869 testcase( pTerm->eOperator==WO_ISNULL );
80870 if( pTerm->eOperator & (WO_IN|WO_ISNULL) ) continue;
80871 pIdxCons[j].iColumn = pTerm->u.leftColumn;
80872 pIdxCons[j].iTermOffset = i;
80873 pIdxCons[j].op = (u8)pTerm->eOperator;
80874 /* The direct assignment in the previous line is possible only because
80875 ** the WO_ and SQLITE_INDEX_CONSTRAINT_ codes are identical. The
80876 ** following asserts verify this fact. */
@@ -80193,16 +80983,16 @@
80983 return pIdxInfo->estimatedCost;
80984 }
80985 #endif /* SQLITE_OMIT_VIRTUALTABLE */
80986
80987 /*
80988 ** Find the query plan for accessing a particular table. Write the
80989 ** best query plan and its cost into the WhereCost object supplied as the
80990 ** last parameter.
80991 **
80992 ** The lowest cost plan wins. The cost is an estimate of the amount of
80993 ** CPU and disk I/O need to process the request using the selected plan.
80994 ** Factors that influence cost include:
80995 **
80996 ** * The estimated number of rows that will be retrieved. (The
80997 ** fewer the better.)
80998 **
@@ -80210,45 +81000,41 @@
81000 **
81001 ** * Whether or not there must be separate lookups in the
81002 ** index and in the main table.
81003 **
81004 ** If there was an INDEXED BY clause attached to the table in the SELECT
81005 ** statement, then this function only considers plans using the
81006 ** named index. If one cannot be found, then the returned cost is
81007 ** SQLITE_BIG_DBL. If a plan can be found that uses the named index,
81008 ** then the cost is calculated in the usual way.
81009 **
81010 ** If a NOT INDEXED clause was attached to the table in the SELECT
81011 ** statement, then no indexes are considered. However, the selected
81012 ** plan may still take advantage of the tables built-in rowid
81013 ** index.
81014 */
81015 static void bestIndex(
81016 Parse *pParse, /* The parsing context */
81017 WhereClause *pWC, /* The WHERE clause */
81018 struct SrcList_item *pSrc, /* The FROM clause term to search */
81019 Bitmask notReady, /* Mask of cursors that are not available */
81020 ExprList *pOrderBy, /* The ORDER BY clause */
81021 WhereCost *pCost /* Lowest cost query plan */
 
 
81022 ){
81023 WhereTerm *pTerm; /* A single term of the WHERE clause */
 
 
 
 
81024 int iCur = pSrc->iCursor; /* The cursor of the table to be accessed */
81025 Index *pProbe; /* An index we are evaluating */
81026 int rev; /* True to scan in reverse order */
81027 int wsFlags; /* Flags associated with pProbe */
81028 int nEq; /* Number of == or IN constraints */
81029 int eqTermMask; /* Mask of valid equality operators */
81030 double cost; /* Cost of using pProbe */
81031 double nRow; /* Estimated number of rows in result set */
81032 int i; /* Loop counter */
81033 Bitmask maskSrc; /* Bitmask for the pSrc table */
81034
81035 WHERETRACE(("bestIndex: tbl=%s notReady=%llx\n", pSrc->pTab->zName,notReady));
 
81036 pProbe = pSrc->pTab->pIndex;
81037 if( pSrc->notIndexed ){
81038 pProbe = 0;
81039 }
81040
@@ -80256,47 +81042,48 @@
81042 ** clause that refer to the ROWID, then we will never be able to do
81043 ** anything other than a full table scan on this table. We might as
81044 ** well put it first in the join order. That way, perhaps it can be
81045 ** referenced by other tables in the join.
81046 */
81047 memset(pCost, 0, sizeof(*pCost));
81048 if( pProbe==0 &&
81049 findTerm(pWC, iCur, -1, 0, WO_EQ|WO_IN|WO_LT|WO_LE|WO_GT|WO_GE,0)==0 &&
81050 (pOrderBy==0 || !sortableByRowid(iCur, pOrderBy, pWC->pMaskSet, &rev)) ){
81051 return;
 
 
 
81052 }
81053 pCost->rCost = SQLITE_BIG_DBL;
81054
81055 /* Check for a rowid=EXPR or rowid IN (...) constraints. If there was
81056 ** an INDEXED BY clause attached to this table, skip this step.
81057 */
81058 if( !pSrc->pIndex ){
81059 pTerm = findTerm(pWC, iCur, -1, notReady, WO_EQ|WO_IN, 0);
81060 if( pTerm ){
81061 Expr *pExpr;
81062 pCost->plan.wsFlags = WHERE_ROWID_EQ;
 
81063 if( pTerm->eOperator & WO_EQ ){
81064 /* Rowid== is always the best pick. Look no further. Because only
81065 ** a single row is generated, output is always in sorted order */
81066 pCost->plan.wsFlags = WHERE_ROWID_EQ | WHERE_UNIQUE;
81067 pCost->plan.nEq = 1;
81068 WHERETRACE(("... best is rowid\n"));
81069 pCost->rCost = 0;
81070 pCost->nRow = 1;
81071 return;
81072 }else if( (pExpr = pTerm->pExpr)->pList!=0 ){
81073 /* Rowid IN (LIST): cost is NlogN where N is the number of list
81074 ** elements. */
81075 pCost->rCost = pCost->nRow = pExpr->pList->nExpr;
81076 pCost->rCost *= estLog(pCost->rCost);
81077 }else{
81078 /* Rowid IN (SELECT): cost is NlogN where N is the number of rows
81079 ** in the result of the inner select. We have no way to estimate
81080 ** that value so make a wild guess. */
81081 pCost->nRow = 100;
81082 pCost->rCost = 200;
81083 }
81084 WHERETRACE(("... rowid IN cost: %.9g\n", pCost->rCost));
81085 }
81086
81087 /* Estimate the cost of a table scan. If we do not know how many
81088 ** entries are in the table, use 1 million as a guess.
81089 */
@@ -80308,20 +81095,21 @@
81095 */
81096 pTerm = findTerm(pWC, iCur, -1, notReady, WO_LT|WO_LE|WO_GT|WO_GE, 0);
81097 if( pTerm ){
81098 if( findTerm(pWC, iCur, -1, notReady, WO_LT|WO_LE, 0) ){
81099 wsFlags |= WHERE_TOP_LIMIT;
81100 cost /= 3; /* Guess that rowid<EXPR eliminates two-thirds of rows */
81101 }
81102 if( findTerm(pWC, iCur, -1, notReady, WO_GT|WO_GE, 0) ){
81103 wsFlags |= WHERE_BTM_LIMIT;
81104 cost /= 3; /* Guess that rowid>EXPR eliminates two-thirds of rows */
81105 }
81106 WHERETRACE(("... rowid range reduces cost to %.9g\n", cost));
81107 }else{
81108 wsFlags = 0;
81109 }
81110 nRow = cost;
81111
81112 /* If the table scan does not satisfy the ORDER BY clause, increase
81113 ** the cost by NlogN to cover the expense of sorting. */
81114 if( pOrderBy ){
81115 if( sortableByRowid(iCur, pOrderBy, pWC->pMaskSet, &rev) ){
@@ -80332,16 +81120,67 @@
81120 }else{
81121 cost += cost*estLog(cost);
81122 WHERETRACE(("... sorting increases cost to %.9g\n", cost));
81123 }
81124 }
81125 if( cost<pCost->rCost ){
81126 pCost->rCost = cost;
81127 pCost->nRow = nRow;
81128 pCost->plan.wsFlags = wsFlags;
81129 }
81130 }
81131
81132 #ifndef SQLITE_OMIT_OR_OPTIMIZATION
81133 /* Search for an OR-clause that can be used to look up the table.
81134 */
81135 maskSrc = getMask(pWC->pMaskSet, iCur);
81136 for(i=0, pTerm=pWC->a; i<pWC->nTerm; i++, pTerm++){
81137 WhereClause tempWC;
81138 tempWC = *pWC;
81139 if( pTerm->eOperator==WO_OR
81140 && ((pTerm->prereqAll & ~maskSrc) & notReady)==0
81141 && (pTerm->u.pOrInfo->indexable & maskSrc)!=0 ){
81142 WhereClause *pOrWC = &pTerm->u.pOrInfo->wc;
81143 WhereTerm *pOrTerm;
81144 int j;
81145 double rTotal = 0;
81146 nRow = 0;
81147 for(j=0, pOrTerm=pOrWC->a; j<pOrWC->nTerm; j++, pOrTerm++){
81148 WhereCost sTermCost;
81149 WHERETRACE(("... Multi-index OR testing for term %d of %d....\n", j,i));
81150 if( pOrTerm->eOperator==WO_AND ){
81151 WhereClause *pAndWC = &pOrTerm->u.pAndInfo->wc;
81152 bestIndex(pParse, pAndWC, pSrc, notReady, 0, &sTermCost);
81153 }else if( pOrTerm->leftCursor==iCur ){
81154 tempWC.a = pOrTerm;
81155 tempWC.nTerm = 1;
81156 bestIndex(pParse, &tempWC, pSrc, notReady, 0, &sTermCost);
81157 }else{
81158 continue;
81159 }
81160 rTotal += sTermCost.rCost;
81161 nRow += sTermCost.nRow;
81162 if( rTotal>=pCost->rCost ) break;
81163 }
81164 WHERETRACE(("... multi-index OR cost=%.9g nrow=%.9g\n",
81165 rTotal, nRow));
81166 if( rTotal<pCost->rCost ){
81167 pCost->rCost = rTotal;
81168 pCost->nRow = nRow;
81169 pCost->plan.wsFlags = WHERE_MULTI_OR;
81170 pCost->plan.u.pTerm = pTerm;
81171 if( pOrderBy!=0
81172 && sortableByRowid(iCur, pOrderBy, pWC->pMaskSet, &rev)
81173 && !rev
81174 ){
81175 pCost->plan.wsFlags = WHERE_ORDERBY|WHERE_MULTI_OR;
81176 }
81177 }
81178 }
81179 }
81180 #endif /* SQLITE_OMIT_OR_OPTIMIZATION */
81181
81182 /* If the pSrc table is the right table of a LEFT JOIN then we may not
81183 ** use an index to satisfy IS NULL constraints on that table. This is
81184 ** because columns might end up being NULL if the table does not match -
81185 ** a circumstance which the index cannot help us discover. Ticket #2177.
81186 */
@@ -80355,11 +81194,10 @@
81194 */
81195 if( pSrc->pIndex ){
81196 pProbe = pSrc->pIndex;
81197 }
81198 for(; pProbe; pProbe=(pSrc->pIndex ? 0 : pProbe->pNext)){
 
81199 double inMultiplier = 1;
81200
81201 WHERETRACE(("... index %s:\n", pProbe->zName));
81202
81203 /* Count the number of columns in the index that are satisfied
@@ -80379,11 +81217,12 @@
81217 }else if( ALWAYS(pExpr->pList) ){
81218 inMultiplier *= pExpr->pList->nExpr + 1;
81219 }
81220 }
81221 }
81222 nRow = pProbe->aiRowEst[i] * inMultiplier;
81223 cost = nRow * estLog(inMultiplier);
81224 nEq = i;
81225 if( pProbe->onError!=OE_None && (wsFlags & WHERE_COLUMN_IN)==0
81226 && nEq==pProbe->nColumn ){
81227 wsFlags |= WHERE_UNIQUE;
81228 }
@@ -80397,14 +81236,16 @@
81236 if( pTerm ){
81237 wsFlags |= WHERE_COLUMN_RANGE;
81238 if( findTerm(pWC, iCur, j, notReady, WO_LT|WO_LE, pProbe) ){
81239 wsFlags |= WHERE_TOP_LIMIT;
81240 cost /= 3;
81241 nRow /= 3;
81242 }
81243 if( findTerm(pWC, iCur, j, notReady, WO_GT|WO_GE, pProbe) ){
81244 wsFlags |= WHERE_BTM_LIMIT;
81245 cost /= 3;
81246 nRow /= 3;
81247 }
81248 WHERETRACE(("...... range reduces cost to %.9g\n", cost));
81249 }
81250 }
81251
@@ -80446,26 +81287,27 @@
81287 }
81288 }
81289
81290 /* If this index has achieved the lowest cost so far, then use it.
81291 */
81292 if( wsFlags!=0 && cost < pCost->rCost ){
81293 pCost->rCost = cost;
81294 pCost->nRow = nRow;
81295 pCost->plan.wsFlags = wsFlags;
81296 pCost->plan.nEq = nEq;
81297 assert( pCost->plan.wsFlags & WHERE_INDEXED );
81298 pCost->plan.u.pIdx = pProbe;
81299 }
81300 }
81301
81302 /* Report the best result
81303 */
81304 pCost->plan.wsFlags |= eqTermMask;
81305 WHERETRACE(("best index is %s, cost=%.9g, nrow=%.9g, wsFlags=%x, nEq=%d\n",
81306 (pCost->plan.wsFlags & WHERE_INDEXED)!=0 ?
81307 pCost->plan.u.pIdx->zName : "(none)", pCost->nRow,
81308 pCost->rCost, pCost->plan.wsFlags, pCost->plan.nEq));
 
81309 }
81310
81311
81312 /*
81313 ** Disable a term in the WHERE clause. Except, do not disable the term
@@ -80557,28 +81399,30 @@
81399 iReg = iTarget;
81400 eType = sqlite3FindInIndex(pParse, pX, 0);
81401 iTab = pX->iTable;
81402 sqlite3VdbeAddOp2(v, OP_Rewind, iTab, 0);
81403 VdbeComment((v, "%.*s", pX->span.n, pX->span.z));
81404 assert( pLevel->plan.wsFlags & WHERE_IN_ABLE );
81405 if( pLevel->u.in.nIn==0 ){
81406 pLevel->addrNxt = sqlite3VdbeMakeLabel(v);
81407 }
81408 pLevel->u.in.nIn++;
81409 pLevel->u.in.aInLoop =
81410 sqlite3DbReallocOrFree(pParse->db, pLevel->u.in.aInLoop,
81411 sizeof(pLevel->u.in.aInLoop[0])*pLevel->u.in.nIn);
81412 pIn = pLevel->u.in.aInLoop;
81413 if( pIn ){
81414 pIn += pLevel->u.in.nIn - 1;
81415 pIn->iCur = iTab;
81416 if( eType==IN_INDEX_ROWID ){
81417 pIn->addrInTop = sqlite3VdbeAddOp2(v, OP_Rowid, iTab, iReg);
81418 }else{
81419 pIn->addrInTop = sqlite3VdbeAddOp3(v, OP_Column, iTab, 0, iReg);
81420 }
81421 sqlite3VdbeAddOp1(v, OP_IsNull, iReg);
81422 }else{
81423 pLevel->u.in.nIn = 0;
81424 }
81425 #endif
81426 }
81427 disableTerm(pLevel, pTerm);
81428 return iReg;
@@ -80591,20 +81435,20 @@
81435 ** For example, consider table t1(a,b,c,d,e,f) with index i1(a,b,c).
81436 ** Suppose the WHERE clause is this: a==5 AND b IN (1,2,3) AND c>5 AND c<10
81437 ** The index has as many as three equality constraints, but in this
81438 ** example, the third "c" value is an inequality. So only two
81439 ** constraints are coded. This routine will generate code to evaluate
81440 ** a==5 and b IN (1,2,3). The current values for a and b will be stored
81441 ** in consecutive registers and the index of the first register is returned.
81442 **
81443 ** In the example above nEq==2. But this subroutine works for any value
81444 ** of nEq including 0. If nEq==0, this routine is nearly a no-op.
81445 ** The only thing it does is allocate the pLevel->iMem memory cell.
81446 **
81447 ** This routine always allocates at least one memory cell and returns
81448 ** the index of that memory cell. The code that
81449 ** calls this routine will use that memory cell to store the termination
81450 ** key value of the loop. If one or more IN operators appear, then
81451 ** this routine allocates an additional nEq memory cells for internal
81452 ** use.
81453 */
81454 static int codeAllEqualityTerms(
@@ -80612,48 +81456,649 @@
81456 WhereLevel *pLevel, /* Which nested loop of the FROM we are coding */
81457 WhereClause *pWC, /* The WHERE clause */
81458 Bitmask notReady, /* Which parts of FROM have not yet been coded */
81459 int nExtraReg /* Number of extra registers to allocate */
81460 ){
81461 int nEq = pLevel->plan.nEq; /* The number of == or IN constraints to code */
81462 Vdbe *v = pParse->pVdbe; /* The vm under construction */
81463 Index *pIdx; /* The index being used for this loop */
81464 int iCur = pLevel->iTabCur; /* The cursor of the table */
81465 WhereTerm *pTerm; /* A single constraint term */
81466 int j; /* Loop counter */
81467 int regBase; /* Base register */
81468 int nReg; /* Number of registers to allocate */
81469
81470 /* This module is only called on query plans that use an index. */
81471 assert( pLevel->plan.wsFlags & WHERE_INDEXED );
81472 pIdx = pLevel->plan.u.pIdx;
81473
81474 /* Figure out how many memory cells we will need then allocate them.
 
 
 
81475 */
81476 regBase = pParse->nMem + 1;
81477 nReg = pLevel->plan.nEq + nExtraReg;
81478 pParse->nMem += nReg;
81479
81480 /* Evaluate the equality constraints
81481 */
81482 assert( pIdx->nColumn>=nEq );
81483 for(j=0; j<nEq; j++){
81484 int r1;
81485 int k = pIdx->aiColumn[j];
81486 pTerm = findTerm(pWC, iCur, k, notReady, pLevel->plan.wsFlags, pIdx);
81487 if( NEVER(pTerm==0) ) break;
81488 assert( (pTerm->wtFlags & TERM_CODED)==0 );
81489 r1 = codeEqualityTerm(pParse, pTerm, pLevel, regBase+j);
81490 if( r1!=regBase+j ){
81491 if( nReg==1 ){
81492 sqlite3ReleaseTempReg(pParse, regBase);
81493 regBase = r1;
81494 }else{
81495 sqlite3VdbeAddOp2(v, OP_SCopy, r1, regBase+j);
81496 }
81497 }
81498 testcase( pTerm->eOperator & WO_ISNULL );
81499 testcase( pTerm->eOperator & WO_IN );
81500 if( (pTerm->eOperator & (WO_ISNULL|WO_IN))==0 ){
81501 sqlite3VdbeAddOp2(v, OP_IsNull, regBase+j, pLevel->addrBrk);
81502 }
81503 }
81504 return regBase;
81505 }
81506
81507 /*
81508 ** Return TRUE if the WhereClause pWC contains no terms that
81509 ** are not virtual and which have not been coded.
81510 **
81511 ** To put it another way, return TRUE if no additional WHERE clauses
81512 ** tests are required in order to establish that the current row
81513 ** should go to output and return FALSE if there are some terms of
81514 ** the WHERE clause that need to be validated before outputing the row.
81515 */
81516 static int whereRowReadyForOutput(WhereClause *pWC){
81517 WhereTerm *pTerm;
81518 int j;
81519
81520 for(pTerm=pWC->a, j=pWC->nTerm; j>0; j--, pTerm++){
81521 if( (pTerm->wtFlags & (TERM_VIRTUAL|TERM_CODED))==0 ) return 0;
81522 }
81523 return 1;
81524 }
81525
81526 /*
81527 ** Generate code for the start of the iLevel-th loop in the WHERE clause
81528 ** implementation described by pWInfo.
81529 */
81530 static Bitmask codeOneLoopStart(
81531 WhereInfo *pWInfo, /* Complete information about the WHERE clause */
81532 int iLevel, /* Which level of pWInfo->a[] should be coded */
81533 u8 wctrlFlags, /* One of the WHERE_* flags defined in sqliteInt.h */
81534 Bitmask notReady /* Which tables are currently available */
81535 ){
81536 int j, k; /* Loop counters */
81537 int iCur; /* The VDBE cursor for the table */
81538 int addrNxt; /* Where to jump to continue with the next IN case */
81539 int omitTable; /* True if we use the index only */
81540 int bRev; /* True if we need to scan in reverse order */
81541 WhereLevel *pLevel; /* The where level to be coded */
81542 WhereClause *pWC; /* Decomposition of the entire WHERE clause */
81543 WhereTerm *pTerm; /* A WHERE clause term */
81544 Parse *pParse; /* Parsing context */
81545 Vdbe *v; /* The prepared stmt under constructions */
81546 struct SrcList_item *pTabItem; /* FROM clause term being coded */
81547 int addrBrk; /* Jump here to break out of the loop */
81548 int addrCont; /* Jump here to continue with next cycle */
81549 int regRowSet; /* Write rowids to this RowSet if non-negative */
81550 int codeRowSetEarly; /* True if index fully constrains the search */
81551
81552
81553 pParse = pWInfo->pParse;
81554 v = pParse->pVdbe;
81555 pWC = pWInfo->pWC;
81556 pLevel = &pWInfo->a[iLevel];
81557 pTabItem = &pWInfo->pTabList->a[pLevel->iFrom];
81558 iCur = pTabItem->iCursor;
81559 bRev = (pLevel->plan.wsFlags & WHERE_REVERSE)!=0;
81560 omitTable = (pLevel->plan.wsFlags & WHERE_IDX_ONLY)!=0;
81561 regRowSet = pWInfo->regRowSet;
81562 codeRowSetEarly = 0;
81563
81564 /* Create labels for the "break" and "continue" instructions
81565 ** for the current loop. Jump to addrBrk to break out of a loop.
81566 ** Jump to cont to go immediately to the next iteration of the
81567 ** loop.
81568 **
81569 ** When there is an IN operator, we also have a "addrNxt" label that
81570 ** means to continue with the next IN value combination. When
81571 ** there are no IN operators in the constraints, the "addrNxt" label
81572 ** is the same as "addrBrk".
81573 */
81574 addrBrk = pLevel->addrBrk = pLevel->addrNxt = sqlite3VdbeMakeLabel(v);
81575 addrCont = pLevel->addrCont = sqlite3VdbeMakeLabel(v);
81576
81577 /* If this is the right table of a LEFT OUTER JOIN, allocate and
81578 ** initialize a memory cell that records if this table matches any
81579 ** row of the left table of the join.
81580 */
81581 if( pLevel->iFrom>0 && (pTabItem[0].jointype & JT_LEFT)!=0 ){
81582 pLevel->iLeftJoin = ++pParse->nMem;
81583 sqlite3VdbeAddOp2(v, OP_Integer, 0, pLevel->iLeftJoin);
81584 VdbeComment((v, "init LEFT JOIN no-match flag"));
81585 }
81586
81587 #ifndef SQLITE_OMIT_VIRTUALTABLE
81588 if( (pLevel->plan.wsFlags & WHERE_VIRTUALTABLE)!=0 ){
81589 /* Case 0: The table is a virtual-table. Use the VFilter and VNext
81590 ** to access the data.
81591 */
81592 int iReg; /* P3 Value for OP_VFilter */
81593 sqlite3_index_info *pVtabIdx = pLevel->plan.u.pVtabIdx;
81594 int nConstraint = pVtabIdx->nConstraint;
81595 struct sqlite3_index_constraint_usage *aUsage =
81596 pVtabIdx->aConstraintUsage;
81597 const struct sqlite3_index_constraint *aConstraint =
81598 pVtabIdx->aConstraint;
81599
81600 iReg = sqlite3GetTempRange(pParse, nConstraint+2);
81601 pParse->disableColCache++;
81602 for(j=1; j<=nConstraint; j++){
81603 for(k=0; k<nConstraint; k++){
81604 if( aUsage[k].argvIndex==j ){
81605 int iTerm = aConstraint[k].iTermOffset;
81606 assert( pParse->disableColCache );
81607 sqlite3ExprCode(pParse, pWC->a[iTerm].pExpr->pRight, iReg+j+1);
81608 break;
81609 }
81610 }
81611 if( k==nConstraint ) break;
81612 }
81613 assert( pParse->disableColCache );
81614 pParse->disableColCache--;
81615 sqlite3VdbeAddOp2(v, OP_Integer, pVtabIdx->idxNum, iReg);
81616 sqlite3VdbeAddOp2(v, OP_Integer, j-1, iReg+1);
81617 sqlite3VdbeAddOp4(v, OP_VFilter, iCur, addrBrk, iReg, pVtabIdx->idxStr,
81618 pVtabIdx->needToFreeIdxStr ? P4_MPRINTF : P4_STATIC);
81619 pVtabIdx->needToFreeIdxStr = 0;
81620 for(j=0; j<nConstraint; j++){
81621 if( aUsage[j].omit ){
81622 int iTerm = aConstraint[j].iTermOffset;
81623 disableTerm(pLevel, &pWC->a[iTerm]);
81624 }
81625 }
81626 pLevel->op = OP_VNext;
81627 pLevel->p1 = iCur;
81628 pLevel->p2 = sqlite3VdbeCurrentAddr(v);
81629 codeRowSetEarly = regRowSet>=0 ? whereRowReadyForOutput(pWC) : 0;
81630 if( codeRowSetEarly ){
81631 sqlite3VdbeAddOp2(v, OP_VRowid, iCur, iReg);
81632 sqlite3VdbeAddOp2(v, OP_RowSetAdd, regRowSet, iReg);
81633 }
81634 sqlite3ReleaseTempRange(pParse, iReg, nConstraint+2);
81635 }else
81636 #endif /* SQLITE_OMIT_VIRTUALTABLE */
81637
81638 if( pLevel->plan.wsFlags & WHERE_ROWID_EQ ){
81639 /* Case 1: We can directly reference a single row using an
81640 ** equality comparison against the ROWID field. Or
81641 ** we reference multiple rows using a "rowid IN (...)"
81642 ** construct.
81643 */
81644 int r1;
81645 int rtmp = sqlite3GetTempReg(pParse);
81646 pTerm = findTerm(pWC, iCur, -1, notReady, WO_EQ|WO_IN, 0);
81647 assert( pTerm!=0 );
81648 assert( pTerm->pExpr!=0 );
81649 assert( pTerm->leftCursor==iCur );
81650 assert( omitTable==0 );
81651 r1 = codeEqualityTerm(pParse, pTerm, pLevel, rtmp);
81652 addrNxt = pLevel->addrNxt;
81653 sqlite3VdbeAddOp2(v, OP_MustBeInt, r1, addrNxt);
81654 sqlite3VdbeAddOp3(v, OP_NotExists, iCur, addrNxt, r1);
81655 codeRowSetEarly = (pWC->nTerm==1 && regRowSet>=0) ?1:0;
81656 if( codeRowSetEarly ){
81657 sqlite3VdbeAddOp2(v, OP_RowSetAdd, regRowSet, r1);
81658 }
81659 sqlite3ReleaseTempReg(pParse, rtmp);
81660 VdbeComment((v, "pk"));
81661 pLevel->op = OP_Noop;
81662 }else if( pLevel->plan.wsFlags & WHERE_ROWID_RANGE ){
81663 /* Case 2: We have an inequality comparison against the ROWID field.
81664 */
81665 int testOp = OP_Noop;
81666 int start;
81667 int memEndValue = 0;
81668 WhereTerm *pStart, *pEnd;
81669
81670 assert( omitTable==0 );
81671 pStart = findTerm(pWC, iCur, -1, notReady, WO_GT|WO_GE, 0);
81672 pEnd = findTerm(pWC, iCur, -1, notReady, WO_LT|WO_LE, 0);
81673 if( bRev ){
81674 pTerm = pStart;
81675 pStart = pEnd;
81676 pEnd = pTerm;
81677 }
81678 if( pStart ){
81679 Expr *pX; /* The expression that defines the start bound */
81680 int r1, rTemp; /* Registers for holding the start boundary */
81681
81682 /* The following constant maps TK_xx codes into corresponding
81683 ** seek opcodes. It depends on a particular ordering of TK_xx
81684 */
81685 const u8 aMoveOp[] = {
81686 /* TK_GT */ OP_SeekGt,
81687 /* TK_LE */ OP_SeekLe,
81688 /* TK_LT */ OP_SeekLt,
81689 /* TK_GE */ OP_SeekGe
81690 };
81691 assert( TK_LE==TK_GT+1 ); /* Make sure the ordering.. */
81692 assert( TK_LT==TK_GT+2 ); /* ... of the TK_xx values... */
81693 assert( TK_GE==TK_GT+3 ); /* ... is correcct. */
81694
81695 pX = pStart->pExpr;
81696 assert( pX!=0 );
81697 assert( pStart->leftCursor==iCur );
81698 r1 = sqlite3ExprCodeTemp(pParse, pX->pRight, &rTemp);
81699 sqlite3VdbeAddOp3(v, aMoveOp[pX->op-TK_GT], iCur, addrBrk, r1);
81700 VdbeComment((v, "pk"));
81701 sqlite3ExprCacheAffinityChange(pParse, r1, 1);
81702 sqlite3ReleaseTempReg(pParse, rTemp);
81703 disableTerm(pLevel, pStart);
81704 }else{
81705 sqlite3VdbeAddOp2(v, bRev ? OP_Last : OP_Rewind, iCur, addrBrk);
81706 }
81707 if( pEnd ){
81708 Expr *pX;
81709 pX = pEnd->pExpr;
81710 assert( pX!=0 );
81711 assert( pEnd->leftCursor==iCur );
81712 memEndValue = ++pParse->nMem;
81713 sqlite3ExprCode(pParse, pX->pRight, memEndValue);
81714 if( pX->op==TK_LT || pX->op==TK_GT ){
81715 testOp = bRev ? OP_Le : OP_Ge;
81716 }else{
81717 testOp = bRev ? OP_Lt : OP_Gt;
81718 }
81719 disableTerm(pLevel, pEnd);
81720 }
81721 start = sqlite3VdbeCurrentAddr(v);
81722 pLevel->op = bRev ? OP_Prev : OP_Next;
81723 pLevel->p1 = iCur;
81724 pLevel->p2 = start;
81725 pLevel->p5 = (pStart==0 && pEnd==0) ?1:0;
81726 codeRowSetEarly = regRowSet>=0 ? whereRowReadyForOutput(pWC) : 0;
81727 if( codeRowSetEarly || testOp!=OP_Noop ){
81728 int r1 = sqlite3GetTempReg(pParse);
81729 sqlite3VdbeAddOp2(v, OP_Rowid, iCur, r1);
81730 if( testOp!=OP_Noop ){
81731 sqlite3VdbeAddOp3(v, testOp, memEndValue, addrBrk, r1);
81732 sqlite3VdbeChangeP5(v, SQLITE_AFF_NUMERIC | SQLITE_JUMPIFNULL);
81733 }
81734 if( codeRowSetEarly ){
81735 sqlite3VdbeAddOp2(v, OP_RowSetAdd, regRowSet, r1);
81736 }
81737 sqlite3ReleaseTempReg(pParse, r1);
81738 }
81739 }else if( pLevel->plan.wsFlags & (WHERE_COLUMN_RANGE|WHERE_COLUMN_EQ) ){
81740 /* Case 3: A scan using an index.
81741 **
81742 ** The WHERE clause may contain zero or more equality
81743 ** terms ("==" or "IN" operators) that refer to the N
81744 ** left-most columns of the index. It may also contain
81745 ** inequality constraints (>, <, >= or <=) on the indexed
81746 ** column that immediately follows the N equalities. Only
81747 ** the right-most column can be an inequality - the rest must
81748 ** use the "==" and "IN" operators. For example, if the
81749 ** index is on (x,y,z), then the following clauses are all
81750 ** optimized:
81751 **
81752 ** x=5
81753 ** x=5 AND y=10
81754 ** x=5 AND y<10
81755 ** x=5 AND y>5 AND y<10
81756 ** x=5 AND y=5 AND z<=10
81757 **
81758 ** The z<10 term of the following cannot be used, only
81759 ** the x=5 term:
81760 **
81761 ** x=5 AND z<10
81762 **
81763 ** N may be zero if there are inequality constraints.
81764 ** If there are no inequality constraints, then N is at
81765 ** least one.
81766 **
81767 ** This case is also used when there are no WHERE clause
81768 ** constraints but an index is selected anyway, in order
81769 ** to force the output order to conform to an ORDER BY.
81770 */
81771 int aStartOp[] = {
81772 0,
81773 0,
81774 OP_Rewind, /* 2: (!start_constraints && startEq && !bRev) */
81775 OP_Last, /* 3: (!start_constraints && startEq && bRev) */
81776 OP_SeekGt, /* 4: (start_constraints && !startEq && !bRev) */
81777 OP_SeekLt, /* 5: (start_constraints && !startEq && bRev) */
81778 OP_SeekGe, /* 6: (start_constraints && startEq && !bRev) */
81779 OP_SeekLe /* 7: (start_constraints && startEq && bRev) */
81780 };
81781 int aEndOp[] = {
81782 OP_Noop, /* 0: (!end_constraints) */
81783 OP_IdxGE, /* 1: (end_constraints && !bRev) */
81784 OP_IdxLT /* 2: (end_constraints && bRev) */
81785 };
81786 int nEq = pLevel->plan.nEq;
81787 int isMinQuery = 0; /* If this is an optimized SELECT min(x).. */
81788 int regBase; /* Base register holding constraint values */
81789 int r1; /* Temp register */
81790 WhereTerm *pRangeStart = 0; /* Inequality constraint at range start */
81791 WhereTerm *pRangeEnd = 0; /* Inequality constraint at range end */
81792 int startEq; /* True if range start uses ==, >= or <= */
81793 int endEq; /* True if range end uses ==, >= or <= */
81794 int start_constraints; /* Start of range is constrained */
81795 int nConstraint; /* Number of constraint terms */
81796 Index *pIdx; /* The index we will be using */
81797 int iIdxCur; /* The VDBE cursor for the index */
81798 int nExtraReg = 0; /* Number of extra registers needed */
81799 int op; /* Instruction opcode */
81800
81801 pIdx = pLevel->plan.u.pIdx;
81802 iIdxCur = pLevel->iIdxCur;
81803 k = pIdx->aiColumn[nEq]; /* Column for inequality constraints */
81804
81805 /* If this loop satisfies a sort order (pOrderBy) request that
81806 ** was passed to this function to implement a "SELECT min(x) ..."
81807 ** query, then the caller will only allow the loop to run for
81808 ** a single iteration. This means that the first row returned
81809 ** should not have a NULL value stored in 'x'. If column 'x' is
81810 ** the first one after the nEq equality constraints in the index,
81811 ** this requires some special handling.
81812 */
81813 if( (wctrlFlags&WHERE_ORDERBY_MIN)!=0
81814 && (pLevel->plan.wsFlags&WHERE_ORDERBY)
81815 && (pIdx->nColumn>nEq)
81816 ){
81817 /* assert( pOrderBy->nExpr==1 ); */
81818 /* assert( pOrderBy->a[0].pExpr->iColumn==pIdx->aiColumn[nEq] ); */
81819 isMinQuery = 1;
81820 nExtraReg = 1;
81821 }
81822
81823 /* Find any inequality constraint terms for the start and end
81824 ** of the range.
81825 */
81826 if( pLevel->plan.wsFlags & WHERE_TOP_LIMIT ){
81827 pRangeEnd = findTerm(pWC, iCur, k, notReady, (WO_LT|WO_LE), pIdx);
81828 nExtraReg = 1;
81829 }
81830 if( pLevel->plan.wsFlags & WHERE_BTM_LIMIT ){
81831 pRangeStart = findTerm(pWC, iCur, k, notReady, (WO_GT|WO_GE), pIdx);
81832 nExtraReg = 1;
81833 }
81834
81835 /* Generate code to evaluate all constraint terms using == or IN
81836 ** and store the values of those terms in an array of registers
81837 ** starting at regBase.
81838 */
81839 regBase = codeAllEqualityTerms(pParse, pLevel, pWC, notReady, nExtraReg);
81840 addrNxt = pLevel->addrNxt;
81841
81842
81843 /* If we are doing a reverse order scan on an ascending index, or
81844 ** a forward order scan on a descending index, interchange the
81845 ** start and end terms (pRangeStart and pRangeEnd).
81846 */
81847 if( bRev==(pIdx->aSortOrder[nEq]==SQLITE_SO_ASC) ){
81848 SWAP(WhereTerm *, pRangeEnd, pRangeStart);
81849 }
81850
81851 testcase( pRangeStart && pRangeStart->eOperator & WO_LE );
81852 testcase( pRangeStart && pRangeStart->eOperator & WO_GE );
81853 testcase( pRangeEnd && pRangeEnd->eOperator & WO_LE );
81854 testcase( pRangeEnd && pRangeEnd->eOperator & WO_GE );
81855 startEq = !pRangeStart || pRangeStart->eOperator & (WO_LE|WO_GE);
81856 endEq = !pRangeEnd || pRangeEnd->eOperator & (WO_LE|WO_GE);
81857 start_constraints = pRangeStart || nEq>0;
81858
81859 /* Seek the index cursor to the start of the range. */
81860 nConstraint = nEq;
81861 if( pRangeStart ){
81862 int dcc = pParse->disableColCache;
81863 if( pRangeEnd ){
81864 pParse->disableColCache++;
81865 }
81866 sqlite3ExprCode(pParse, pRangeStart->pExpr->pRight, regBase+nEq);
81867 pParse->disableColCache = dcc;
81868 sqlite3VdbeAddOp2(v, OP_IsNull, regBase+nEq, addrNxt);
81869 nConstraint++;
81870 }else if( isMinQuery ){
81871 sqlite3VdbeAddOp2(v, OP_Null, 0, regBase+nEq);
81872 nConstraint++;
81873 startEq = 0;
81874 start_constraints = 1;
81875 }
81876 codeApplyAffinity(pParse, regBase, nConstraint, pIdx);
81877 op = aStartOp[(start_constraints<<2) + (startEq<<1) + bRev];
81878 assert( op!=0 );
81879 testcase( op==OP_Rewind );
81880 testcase( op==OP_Last );
81881 testcase( op==OP_SeekGt );
81882 testcase( op==OP_SeekGe );
81883 testcase( op==OP_SeekLe );
81884 testcase( op==OP_SeekLt );
81885 sqlite3VdbeAddOp4(v, op, iIdxCur, addrNxt, regBase,
81886 SQLITE_INT_TO_PTR(nConstraint), P4_INT32);
81887
81888 /* Load the value for the inequality constraint at the end of the
81889 ** range (if any).
81890 */
81891 nConstraint = nEq;
81892 if( pRangeEnd ){
81893 sqlite3ExprCode(pParse, pRangeEnd->pExpr->pRight, regBase+nEq);
81894 sqlite3VdbeAddOp2(v, OP_IsNull, regBase+nEq, addrNxt);
81895 codeApplyAffinity(pParse, regBase, nEq+1, pIdx);
81896 nConstraint++;
81897 }
81898
81899 /* Top of the loop body */
81900 pLevel->p2 = sqlite3VdbeCurrentAddr(v);
81901
81902 /* Check if the index cursor is past the end of the range. */
81903 op = aEndOp[(pRangeEnd || nEq) * (1 + bRev)];
81904 testcase( op==OP_Noop );
81905 testcase( op==OP_IdxGE );
81906 testcase( op==OP_IdxLT );
81907 if( op!=OP_Noop ){
81908 sqlite3VdbeAddOp4(v, op, iIdxCur, addrNxt, regBase,
81909 SQLITE_INT_TO_PTR(nConstraint), P4_INT32);
81910 sqlite3VdbeChangeP5(v, endEq!=bRev ?1:0);
81911 }
81912
81913 /* If there are inequality constraints, check that the value
81914 ** of the table column that the inequality contrains is not NULL.
81915 ** If it is, jump to the next iteration of the loop.
81916 */
81917 r1 = sqlite3GetTempReg(pParse);
81918 testcase( pLevel->plan.wsFlags & WHERE_BTM_LIMIT );
81919 testcase( pLevel->plan.wsFlags & WHERE_TOP_LIMIT );
81920 if( pLevel->plan.wsFlags & (WHERE_BTM_LIMIT|WHERE_TOP_LIMIT) ){
81921 sqlite3VdbeAddOp3(v, OP_Column, iIdxCur, nEq, r1);
81922 sqlite3VdbeAddOp2(v, OP_IsNull, r1, addrCont);
81923 }
81924
81925 /* Seek the table cursor, if required */
81926 disableTerm(pLevel, pRangeStart);
81927 disableTerm(pLevel, pRangeEnd);
81928 codeRowSetEarly = regRowSet>=0 ? whereRowReadyForOutput(pWC) : 0;
81929 if( !omitTable || codeRowSetEarly ){
81930 sqlite3VdbeAddOp2(v, OP_IdxRowid, iIdxCur, r1);
81931 if( codeRowSetEarly ){
81932 sqlite3VdbeAddOp2(v, OP_RowSetAdd, regRowSet, r1);
81933 }else{
81934 sqlite3VdbeAddOp2(v, OP_Seek, iCur, r1); /* Deferred seek */
81935 }
81936 }
81937 sqlite3ReleaseTempReg(pParse, r1);
81938
81939 /* Record the instruction used to terminate the loop. Disable
81940 ** WHERE clause terms made redundant by the index range scan.
81941 */
81942 pLevel->op = bRev ? OP_Prev : OP_Next;
81943 pLevel->p1 = iIdxCur;
81944 }else
81945
81946 #ifndef SQLITE_OMIT_OR_OPTIMIZATION
81947 if( pLevel->plan.wsFlags & WHERE_MULTI_OR ){
81948 /* Case 4: Two or more separately indexed terms connected by OR
81949 **
81950 ** Example:
81951 **
81952 ** CREATE TABLE t1(a,b,c,d);
81953 ** CREATE INDEX i1 ON t1(a);
81954 ** CREATE INDEX i2 ON t1(b);
81955 ** CREATE INDEX i3 ON t1(c);
81956 **
81957 ** SELECT * FROM t1 WHERE a=5 OR b=7 OR (c=11 AND d=13)
81958 **
81959 ** In the example, there are three indexed terms connected by OR.
81960 ** The top of the loop is constructed by creating a RowSet object
81961 ** and populating it. Then looping over elements of the rowset.
81962 **
81963 ** Null 1
81964 ** # fill RowSet 1 with entries where a=5 using i1
81965 ** # fill Rowset 1 with entries where b=7 using i2
81966 ** # fill Rowset 1 with entries where c=11 and d=13 i3 and t1
81967 ** A: RowSetRead 1, B, 2
81968 ** Seek i, 2
81969 **
81970 ** The bottom of the loop looks like this:
81971 **
81972 ** Goto 0, A
81973 ** B:
81974 */
81975 int regOrRowset; /* Register holding the RowSet object */
81976 int regNextRowid; /* Register holding next rowid */
81977 WhereClause *pOrWc; /* The OR-clause broken out into subterms */
81978 WhereTerm *pOrTerm; /* A single subterm within the OR-clause */
81979 SrcList oneTab; /* Shortened table list */
81980
81981 pTerm = pLevel->plan.u.pTerm;
81982 assert( pTerm!=0 );
81983 assert( pTerm->eOperator==WO_OR );
81984 assert( (pTerm->wtFlags & TERM_ORINFO)!=0 );
81985 pOrWc = &pTerm->u.pOrInfo->wc;
81986 codeRowSetEarly = (regRowSet>=0 && pWC->nTerm==1) ?1:0;
81987
81988 if( codeRowSetEarly ){
81989 regOrRowset = regRowSet;
81990 }else{
81991 regOrRowset = sqlite3GetTempReg(pParse);
81992 sqlite3VdbeAddOp2(v, OP_Null, 0, regOrRowset);
81993 }
81994 oneTab.nSrc = 1;
81995 oneTab.nAlloc = 1;
81996 oneTab.a[0] = *pTabItem;
81997 for(j=0, pOrTerm=pOrWc->a; j<pOrWc->nTerm; j++, pOrTerm++){
81998 WhereInfo *pSubWInfo;
81999 if( pOrTerm->leftCursor!=iCur && pOrTerm->eOperator!=WO_AND ) continue;
82000 pSubWInfo = sqlite3WhereBegin(pParse, &oneTab, pOrTerm->pExpr, 0,
82001 WHERE_FILL_ROWSET | WHERE_OMIT_OPEN | WHERE_OMIT_CLOSE,
82002 regOrRowset);
82003 if( pSubWInfo ){
82004 sqlite3WhereEnd(pSubWInfo);
82005 }
82006 }
82007 sqlite3VdbeResolveLabel(v, addrCont);
82008 if( !codeRowSetEarly ){
82009 regNextRowid = sqlite3GetTempReg(pParse);
82010 addrCont =
82011 sqlite3VdbeAddOp3(v, OP_RowSetRead, regOrRowset,addrBrk,regNextRowid);
82012 sqlite3VdbeAddOp2(v, OP_Seek, iCur, regNextRowid);
82013 sqlite3ReleaseTempReg(pParse, regNextRowid);
82014 /* sqlite3ReleaseTempReg(pParse, regOrRowset); // Preserve the RowSet */
82015 pLevel->op = OP_Goto;
82016 pLevel->p2 = addrCont;
82017 }else{
82018 pLevel->op = OP_Noop;
82019 }
82020 disableTerm(pLevel, pTerm);
82021 }else
82022 #endif /* SQLITE_OMIT_OR_OPTIMIZATION */
82023
82024 {
82025 /* Case 5: There is no usable index. We must do a complete
82026 ** scan of the entire table.
82027 */
82028 assert( omitTable==0 );
82029 assert( bRev==0 );
82030 pLevel->op = OP_Next;
82031 pLevel->p1 = iCur;
82032 pLevel->p2 = 1 + sqlite3VdbeAddOp2(v, OP_Rewind, iCur, addrBrk);
82033 pLevel->p5 = SQLITE_STMTSTATUS_FULLSCAN_STEP;
82034 codeRowSetEarly = 0;
82035 }
82036 notReady &= ~getMask(pWC->pMaskSet, iCur);
82037
82038 /* Insert code to test every subexpression that can be completely
82039 ** computed using the current set of tables.
82040 */
82041 k = 0;
82042 for(pTerm=pWC->a, j=pWC->nTerm; j>0; j--, pTerm++){
82043 Expr *pE;
82044 testcase( pTerm->wtFlags & TERM_VIRTUAL );
82045 testcase( pTerm->wtFlags & TERM_CODED );
82046 if( pTerm->wtFlags & (TERM_VIRTUAL|TERM_CODED) ) continue;
82047 if( (pTerm->prereqAll & notReady)!=0 ) continue;
82048 pE = pTerm->pExpr;
82049 assert( pE!=0 );
82050 if( pLevel->iLeftJoin && !ExprHasProperty(pE, EP_FromJoin) ){
82051 continue;
82052 }
82053 pParse->disableColCache += k;
82054 sqlite3ExprIfFalse(pParse, pE, addrCont, SQLITE_JUMPIFNULL);
82055 pParse->disableColCache -= k;
82056 k = 1;
82057 pTerm->wtFlags |= TERM_CODED;
82058 }
82059
82060 /* For a LEFT OUTER JOIN, generate code that will record the fact that
82061 ** at least one row of the right table has matched the left table.
82062 */
82063 if( pLevel->iLeftJoin ){
82064 pLevel->addrFirst = sqlite3VdbeCurrentAddr(v);
82065 sqlite3VdbeAddOp2(v, OP_Integer, 1, pLevel->iLeftJoin);
82066 VdbeComment((v, "record LEFT JOIN hit"));
82067 sqlite3ExprClearColumnCache(pParse, pLevel->iTabCur);
82068 sqlite3ExprClearColumnCache(pParse, pLevel->iIdxCur);
82069 for(pTerm=pWC->a, j=0; j<pWC->nTerm; j++, pTerm++){
82070 testcase( pTerm->wtFlags & TERM_VIRTUAL );
82071 testcase( pTerm->wtFlags & TERM_CODED );
82072 if( pTerm->wtFlags & (TERM_VIRTUAL|TERM_CODED) ) continue;
82073 if( (pTerm->prereqAll & notReady)!=0 ) continue;
82074 assert( pTerm->pExpr );
82075 sqlite3ExprIfFalse(pParse, pTerm->pExpr, addrCont, SQLITE_JUMPIFNULL);
82076 pTerm->wtFlags |= TERM_CODED;
82077 }
82078 }
82079
82080 /*
82081 ** If it was requested to store the results in a rowset and that has
82082 ** not already been do, then do so now.
82083 */
82084 if( regRowSet>=0 && !codeRowSetEarly ){
82085 int r1 = sqlite3GetTempReg(pParse);
82086 #ifndef SQLITE_OMIT_VIRTUALTABLE
82087 if( (pLevel->plan.wsFlags & WHERE_VIRTUALTABLE)!=0 ){
82088 sqlite3VdbeAddOp2(v, OP_VRowid, iCur, r1);
82089 }else
82090 #endif
82091 {
82092 sqlite3VdbeAddOp2(v, OP_Rowid, iCur, r1);
82093 }
82094 sqlite3VdbeAddOp2(v, OP_RowSetAdd, regRowSet, r1);
82095 sqlite3ReleaseTempReg(pParse, r1);
82096 }
82097
82098 return notReady;
82099 }
82100
82101 #if defined(SQLITE_TEST)
82102 /*
82103 ** The following variable holds a text description of query plan generated
82104 ** by the most recent call to sqlite3WhereBegin(). Each call to WhereBegin
@@ -80673,14 +82118,18 @@
82118 if( pWInfo ){
82119 int i;
82120 for(i=0; i<pWInfo->nLevel; i++){
82121 sqlite3_index_info *pInfo = pWInfo->a[i].pIdxInfo;
82122 if( pInfo ){
82123 assert( pInfo->needToFreeIdxStr==0 || db->mallocFailed );
82124 if( pInfo->needToFreeIdxStr ){
82125 sqlite3_free(pInfo->idxStr);
82126 }
82127 sqlite3DbFree(db, pInfo);
82128 }
82129 }
82130 whereClauseClear(pWInfo->pWC);
82131 sqlite3DbFree(db, pWInfo);
82132 }
82133 }
82134
82135
@@ -80775,24 +82224,23 @@
82224 SQLITE_PRIVATE WhereInfo *sqlite3WhereBegin(
82225 Parse *pParse, /* The parser context */
82226 SrcList *pTabList, /* A list of all tables to be scanned */
82227 Expr *pWhere, /* The WHERE clause */
82228 ExprList **ppOrderBy, /* An ORDER BY clause, or NULL */
82229 u8 wctrlFlags, /* One of the WHERE_* flags defined in sqliteInt.h */
82230 int regRowSet /* Register hold RowSet if WHERE_FILL_ROWSET is set */
82231 ){
82232 int i; /* Loop counter */
82233 WhereInfo *pWInfo; /* Will become the return value of this function */
82234 Vdbe *v = pParse->pVdbe; /* The virtual database engine */
 
82235 Bitmask notReady; /* Cursors that are not yet positioned */
82236 WhereMaskSet *pMaskSet; /* The expression mask set */
82237 WhereClause *pWC; /* Decomposition of the WHERE clause */
 
82238 struct SrcList_item *pTabItem; /* A single entry from pTabList */
82239 WhereLevel *pLevel; /* A single level in the pWInfo list */
82240 int iFrom; /* First unused FROM clause element */
82241 int andFlags; /* AND-ed combination of all pWC->a[].wtFlags */
82242 sqlite3 *db; /* Database connection */
82243 ExprList *pOrderBy = 0;
82244
82245 /* The number of tables in the FROM clause is limited by the number of
82246 ** bits in a Bitmask
@@ -80804,32 +82252,40 @@
82252
82253 if( ppOrderBy ){
82254 pOrderBy = *ppOrderBy;
82255 }
82256
 
 
 
 
 
 
 
 
82257 /* Allocate and initialize the WhereInfo structure that will become the
82258 ** return value.
82259 */
82260 db = pParse->db;
82261 pWInfo = sqlite3DbMallocZero(db,
82262 sizeof(WhereInfo)
82263 + (pTabList->nSrc-1)*sizeof(WhereLevel)
82264 + sizeof(WhereClause)
82265 + sizeof(WhereMaskSet)
82266 );
82267 if( db->mallocFailed ){
82268 goto whereBeginError;
82269 }
82270 pWInfo->nLevel = pTabList->nSrc;
82271 pWInfo->pParse = pParse;
82272 pWInfo->pTabList = pTabList;
82273 pWInfo->iBreak = sqlite3VdbeMakeLabel(v);
82274 pWInfo->regRowSet = (wctrlFlags & WHERE_FILL_ROWSET) ? regRowSet : -1;
82275 pWInfo->pWC = pWC = (WhereClause*)&pWInfo->a[pWInfo->nLevel];
82276 pWInfo->wctrlFlags = wctrlFlags;
82277 pMaskSet = (WhereMaskSet*)&pWC[1];
82278
82279 /* Split the WHERE clause into separate subexpressions where each
82280 ** subexpression is separated by an AND operator.
82281 */
82282 initMaskSet(pMaskSet);
82283 whereClauseInit(pWC, pParse, pMaskSet);
82284 sqlite3ExprCodeConstants(pParse, pWhere);
82285 whereSplit(pWC, pWhere, TK_AND);
82286
82287 /* Special case: a WHERE clause that is constant. Evaluate the
82288 ** expression and either jump over all of the code or fall thru.
82289 */
82290 if( pWhere && (pTabList->nSrc==0 || sqlite3ExprIsConstantNotJoin(pWhere)) ){
82291 sqlite3ExprIfFalse(pParse, pWhere, pWInfo->iBreak, SQLITE_JUMPIFNULL);
@@ -80846,17 +82302,17 @@
82302 ** of the join. Subtracting one from the right table bitmask gives a
82303 ** bitmask for all tables to the left of the join. Knowing the bitmask
82304 ** for all tables to the left of a left join is important. Ticket #3015.
82305 */
82306 for(i=0; i<pTabList->nSrc; i++){
82307 createMask(pMaskSet, pTabList->a[i].iCursor);
82308 }
82309 #ifndef NDEBUG
82310 {
82311 Bitmask toTheLeft = 0;
82312 for(i=0; i<pTabList->nSrc; i++){
82313 Bitmask m = getMask(pMaskSet, pTabList->a[i].iCursor);
82314 assert( (m-1)==toTheLeft );
82315 toTheLeft |= m;
82316 }
82317 }
82318 #endif
@@ -80864,11 +82320,11 @@
82320 /* Analyze all of the subexpressions. Note that exprAnalyze() might
82321 ** add new virtual terms onto the end of the WHERE clause. We do not
82322 ** want to analyze these virtual terms, so start analyzing at the end
82323 ** and work forward so that the added virtual terms are never processed.
82324 */
82325 exprAnalyzeAll(pTabList, pWC);
82326 if( db->mallocFailed ){
82327 goto whereBeginError;
82328 }
82329
82330 /* Chose the best index to use for each table in the FROM clause.
@@ -80879,10 +82335,11 @@
82335 ** pWInfo->a[].wsFlags WHERE_xxx flags associated with pIdx
82336 ** pWInfo->a[].nEq The number of == and IN constraints
82337 ** pWInfo->a[].iFrom Which term of the FROM clause is being coded
82338 ** pWInfo->a[].iTabCur The VDBE cursor for the database table
82339 ** pWInfo->a[].iIdxCur The VDBE cursor for the index
82340 ** pWInfo->a[].pTerm When wsFlags==WO_OR, the OR-clause term
82341 **
82342 ** This loop also figures out the nesting order of tables in the FROM
82343 ** clause.
82344 */
82345 notReady = ~(Bitmask)0;
@@ -80889,108 +82346,103 @@
82346 pTabItem = pTabList->a;
82347 pLevel = pWInfo->a;
82348 andFlags = ~0;
82349 WHERETRACE(("*** Optimizer Start ***\n"));
82350 for(i=iFrom=0, pLevel=pWInfo->a; i<pTabList->nSrc; i++, pLevel++){
82351 WhereCost bestPlan; /* Most efficient plan seen so far */
82352 Index *pIdx; /* Index for FROM table at pTabItem */
 
 
 
82353 int j; /* For looping over FROM tables */
 
 
 
 
82354 int bestJ = 0; /* The value of j */
82355 Bitmask m; /* Bitmask value for j or bestJ */
82356 int once = 0; /* True when first table is seen */
 
82357
82358 memset(&bestPlan, 0, sizeof(bestPlan));
82359 bestPlan.rCost = SQLITE_BIG_DBL;
82360 for(j=iFrom, pTabItem=&pTabList->a[j]; j<pTabList->nSrc; j++, pTabItem++){
82361 int doNotReorder; /* True if this table should not be reordered */
82362 WhereCost sCost; /* Cost information from bestIndex() */
82363
82364 doNotReorder = (pTabItem->jointype & (JT_LEFT|JT_CROSS))!=0;
82365 if( once && doNotReorder ) break;
82366 m = getMask(pMaskSet, pTabItem->iCursor);
82367 if( (m & notReady)==0 ){
82368 if( j==iFrom ) iFrom++;
82369 continue;
82370 }
82371 assert( pTabItem->pTab );
82372 #ifndef SQLITE_OMIT_VIRTUALTABLE
82373 if( IsVirtual(pTabItem->pTab) ){
82374 sqlite3_index_info *pVtabIdx; /* Current virtual index */
82375 sqlite3_index_info **ppIdxInfo = &pWInfo->a[j].pIdxInfo;
82376 sCost.rCost = bestVirtualIndex(pParse, pWC, pTabItem, notReady,
82377 ppOrderBy ? *ppOrderBy : 0, i==0,
82378 ppIdxInfo);
82379 sCost.plan.wsFlags = WHERE_VIRTUALTABLE;
82380 sCost.plan.u.pVtabIdx = pVtabIdx = *ppIdxInfo;
82381 if( pVtabIdx && pVtabIdx->orderByConsumed ){
82382 sCost.plan.wsFlags = WHERE_VIRTUALTABLE | WHERE_ORDERBY;
82383 }
82384 sCost.plan.nEq = 0;
82385 if( (SQLITE_BIG_DBL/2.0)<sCost.rCost ){
 
82386 /* The cost is not allowed to be larger than SQLITE_BIG_DBL (the
82387 ** inital value of lowestCost in this loop. If it is, then
82388 ** the (cost<lowestCost) test below will never be true.
 
82389 */
82390 sCost.rCost = (SQLITE_BIG_DBL/2.0);
82391 }
82392 }else
82393 #endif
82394 {
82395 bestIndex(pParse, pWC, pTabItem, notReady,
82396 (i==0 && ppOrderBy) ? *ppOrderBy : 0, &sCost);
 
 
82397 }
82398 if( once==0 || sCost.rCost<bestPlan.rCost ){
82399 once = 1;
82400 bestPlan = sCost;
 
 
 
82401 bestJ = j;
 
82402 }
82403 if( doNotReorder ) break;
82404 }
82405 assert( once );
82406 assert( notReady & getMask(pMaskSet, pTabList->a[bestJ].iCursor) );
82407 WHERETRACE(("*** Optimizer selects table %d for loop %d\n", bestJ,
82408 pLevel-pWInfo->a));
82409 if( (bestPlan.plan.wsFlags & WHERE_ORDERBY)!=0 ){
82410 *ppOrderBy = 0;
82411 }
82412 andFlags &= bestPlan.plan.wsFlags;
82413 pLevel->plan = bestPlan.plan;
82414 if( bestPlan.plan.wsFlags & WHERE_INDEXED ){
 
 
 
 
82415 pLevel->iIdxCur = pParse->nTab++;
82416 }else{
82417 pLevel->iIdxCur = -1;
82418 }
82419 notReady &= ~getMask(pMaskSet, pTabList->a[bestJ].iCursor);
82420 pLevel->iFrom = bestJ;
82421
82422 /* Check that if the table scanned by this loop iteration had an
82423 ** INDEXED BY clause attached to it, that the named index is being
82424 ** used for the scan. If not, then query compilation has failed.
82425 ** Return an error.
82426 */
82427 pIdx = pTabList->a[bestJ].pIndex;
82428 if( pIdx ){
82429 if( (bestPlan.plan.wsFlags & WHERE_INDEXED)==0 ){
82430 sqlite3ErrorMsg(pParse, "cannot use index: %s", pIdx->zName);
82431 goto whereBeginError;
82432 }else{
82433 /* If an INDEXED BY clause is used, the bestIndex() function is
82434 ** guaranteed to find the index specified in the INDEXED BY clause
82435 ** if it find an index at all. */
82436 assert( bestPlan.plan.u.pIdx==pIdx );
82437 }
82438 }
82439 }
82440 WHERETRACE(("*** Optimizer Finished ***\n"));
82441 if( db->mallocFailed ){
82442 goto whereBeginError;
82443 }
82444
82445 /* If the total query only selects a single row, then the ORDER BY
82446 ** clause is irrelevant.
82447 */
82448 if( (andFlags & WHERE_UNIQUE)!=0 && ppOrderBy ){
@@ -81003,44 +82455,45 @@
82455 ** the statement to update a single row.
82456 */
82457 assert( (wctrlFlags & WHERE_ONEPASS_DESIRED)==0 || pWInfo->nLevel==1 );
82458 if( (wctrlFlags & WHERE_ONEPASS_DESIRED)!=0 && (andFlags & WHERE_UNIQUE)!=0 ){
82459 pWInfo->okOnePass = 1;
82460 pWInfo->a[0].plan.wsFlags &= ~WHERE_IDX_ONLY;
82461 }
82462
82463 /* Open all tables in the pTabList and any indices selected for
82464 ** searching those tables.
82465 */
82466 sqlite3CodeVerifySchema(pParse, -1); /* Insert the cookie verifier Goto */
82467 for(i=0, pLevel=pWInfo->a; i<pTabList->nSrc; i++, pLevel++){
82468 Table *pTab; /* Table to open */
 
82469 int iDb; /* Index of database containing table/index */
 
82470
82471 #ifndef SQLITE_OMIT_EXPLAIN
82472 if( pParse->explain==2 ){
82473 char *zMsg;
82474 struct SrcList_item *pItem = &pTabList->a[pLevel->iFrom];
82475 zMsg = sqlite3MPrintf(db, "TABLE %s", pItem->zName);
82476 if( pItem->zAlias ){
82477 zMsg = sqlite3MAppendf(db, zMsg, "%s AS %s", zMsg, pItem->zAlias);
82478 }
82479 if( (pLevel->plan.wsFlags & WHERE_INDEXED)!=0 ){
82480 zMsg = sqlite3MAppendf(db, zMsg, "%s WITH INDEX %s",
82481 zMsg, pLevel->plan.u.pIdx->zName);
82482 }else if( pLevel->plan.wsFlags & WHERE_MULTI_OR ){
82483 zMsg = sqlite3MAppendf(db, zMsg, "%s VIA MULTI-INDEX UNION", zMsg);
82484 }else if( pLevel->plan.wsFlags & (WHERE_ROWID_EQ|WHERE_ROWID_RANGE) ){
82485 zMsg = sqlite3MAppendf(db, zMsg, "%s USING PRIMARY KEY", zMsg);
82486 }
82487 #ifndef SQLITE_OMIT_VIRTUALTABLE
82488 else if( (pLevel->plan.wsFlags & WHERE_VIRTUALTABLE)!=0 ){
82489 sqlite3_index_info *pVtabIdx = pLevel->plan.u.pVtabIdx;
82490 zMsg = sqlite3MAppendf(db, zMsg, "%s VIRTUAL TABLE INDEX %d:%s", zMsg,
82491 pVtabIdx->idxNum, pVtabIdx->idxStr);
82492 }
82493 #endif
82494 if( pLevel->plan.wsFlags & WHERE_ORDERBY ){
82495 zMsg = sqlite3MAppendf(db, zMsg, "%s ORDER BY", zMsg);
82496 }
82497 sqlite3VdbeAddOp4(v, OP_Explain, i, pLevel->iFrom, 0, zMsg, P4_DYNAMIC);
82498 }
82499 #endif /* SQLITE_OMIT_EXPLAIN */
@@ -81047,17 +82500,18 @@
82500 pTabItem = &pTabList->a[pLevel->iFrom];
82501 pTab = pTabItem->pTab;
82502 iDb = sqlite3SchemaToIndex(pParse->db, pTab->pSchema);
82503 if( (pTab->tabFlags & TF_Ephemeral)!=0 || pTab->pSelect ) continue;
82504 #ifndef SQLITE_OMIT_VIRTUALTABLE
82505 if( (pLevel->plan.wsFlags & WHERE_VIRTUALTABLE)!=0 ){
82506 int iCur = pTabItem->iCursor;
82507 sqlite3VdbeAddOp4(v, OP_VOpen, iCur, 0, 0,
82508 (const char*)pTab->pVtab, P4_VTAB);
82509 }else
82510 #endif
82511 if( (pLevel->plan.wsFlags & WHERE_IDX_ONLY)==0
82512 && (wctrlFlags & WHERE_OMIT_OPEN)==0 ){
82513 int op = pWInfo->okOnePass ? OP_OpenWrite : OP_OpenRead;
82514 sqlite3OpenTable(pParse, pTabItem->iCursor, iDb, pTab, op);
82515 if( !pWInfo->okOnePass && pTab->nCol<BMS ){
82516 Bitmask b = pTabItem->colUsed;
82517 int n = 0;
@@ -81067,13 +82521,16 @@
82521 }
82522 }else{
82523 sqlite3TableLock(pParse, iDb, pTab->tnum, 0, pTab->zName);
82524 }
82525 pLevel->iTabCur = pTabItem->iCursor;
82526 if( (pLevel->plan.wsFlags & WHERE_INDEXED)!=0 ){
82527 Index *pIx = pLevel->plan.u.pIdx;
82528 KeyInfo *pKey = sqlite3IndexKeyinfo(pParse, pIx);
82529 int iIdxCur = pLevel->iIdxCur;
82530 assert( pIx->pSchema==pTab->pSchema );
82531 assert( iIdxCur>=0 );
82532 sqlite3VdbeAddOp2(v, OP_SetNumColumns, 0, pIx->nColumn+1);
82533 sqlite3VdbeAddOp4(v, OP_OpenRead, iIdxCur, pIx->tnum, iDb,
82534 (char*)pKey, P4_KEYINFO_HANDOFF);
82535 VdbeComment((v, "%s", pIx->zName));
82536 }
@@ -81084,428 +82541,13 @@
82541 /* Generate the code to do the search. Each iteration of the for
82542 ** loop below generates code for a single nested loop of the VM
82543 ** program.
82544 */
82545 notReady = ~(Bitmask)0;
82546 for(i=0; i<pTabList->nSrc; i++){
82547 notReady = codeOneLoopStart(pWInfo, i, wctrlFlags, notReady);
82548 pWInfo->iContinue = pWInfo->a[i].addrCont;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
82549 }
82550
82551 #ifdef SQLITE_TEST /* For testing and debugging use only */
82552 /* Record in the query plan information about the current table
82553 ** and the index used to access it (if any). If the table itself
@@ -81520,34 +82562,34 @@
82562 pTabItem = &pTabList->a[pLevel->iFrom];
82563 z = pTabItem->zAlias;
82564 if( z==0 ) z = pTabItem->pTab->zName;
82565 n = sqlite3Strlen30(z);
82566 if( n+nQPlan < sizeof(sqlite3_query_plan)-10 ){
82567 if( pLevel->plan.wsFlags & WHERE_IDX_ONLY ){
82568 memcpy(&sqlite3_query_plan[nQPlan], "{}", 2);
82569 nQPlan += 2;
82570 }else{
82571 memcpy(&sqlite3_query_plan[nQPlan], z, n);
82572 nQPlan += n;
82573 }
82574 sqlite3_query_plan[nQPlan++] = ' ';
82575 }
82576 testcase( pLevel->plan.wsFlags & WHERE_ROWID_EQ );
82577 testcase( pLevel->plan.wsFlags & WHERE_ROWID_RANGE );
82578 if( pLevel->plan.wsFlags & (WHERE_ROWID_EQ|WHERE_ROWID_RANGE) ){
82579 memcpy(&sqlite3_query_plan[nQPlan], "* ", 2);
82580 nQPlan += 2;
82581 }else if( (pLevel->plan.wsFlags & WHERE_INDEXED)!=0 ){
82582 n = sqlite3Strlen30(pLevel->plan.u.pIdx->zName);
 
 
 
82583 if( n+nQPlan < sizeof(sqlite3_query_plan)-2 ){
82584 memcpy(&sqlite3_query_plan[nQPlan], pLevel->plan.u.pIdx->zName, n);
82585 nQPlan += n;
82586 sqlite3_query_plan[nQPlan++] = ' ';
82587 }
82588 }else{
82589 memcpy(&sqlite3_query_plan[nQPlan], "{} ", 3);
82590 nQPlan += 3;
82591 }
82592 }
82593 while( nQPlan>0 && sqlite3_query_plan[nQPlan-1]==' ' ){
82594 sqlite3_query_plan[--nQPlan] = 0;
82595 }
@@ -81556,17 +82598,14 @@
82598 #endif /* SQLITE_TEST // Testing and debugging use only */
82599
82600 /* Record the continuation address in the WhereInfo structure. Then
82601 ** clean up and return.
82602 */
 
 
82603 return pWInfo;
82604
82605 /* Jump here if malloc fails */
82606 whereBeginError:
 
82607 whereInfoFree(db, pWInfo);
82608 return 0;
82609 }
82610
82611 /*
@@ -81589,20 +82628,20 @@
82628 sqlite3VdbeResolveLabel(v, pLevel->addrCont);
82629 if( pLevel->op!=OP_Noop ){
82630 sqlite3VdbeAddOp2(v, pLevel->op, pLevel->p1, pLevel->p2);
82631 sqlite3VdbeChangeP5(v, pLevel->p5);
82632 }
82633 if( pLevel->plan.wsFlags & WHERE_IN_ABLE && pLevel->u.in.nIn>0 ){
82634 struct InLoop *pIn;
82635 int j;
82636 sqlite3VdbeResolveLabel(v, pLevel->addrNxt);
82637 for(j=pLevel->u.in.nIn, pIn=&pLevel->u.in.aInLoop[j-1]; j>0; j--, pIn--){
82638 sqlite3VdbeJumpHere(v, pIn->addrInTop+1);
82639 sqlite3VdbeAddOp2(v, OP_Next, pIn->iCur, pIn->addrInTop);
82640 sqlite3VdbeJumpHere(v, pIn->addrInTop-1);
82641 }
82642 sqlite3DbFree(db, pLevel->u.in.aInLoop);
82643 }
82644 sqlite3VdbeResolveLabel(v, pLevel->addrBrk);
82645 if( pLevel->iLeftJoin ){
82646 int addr;
82647 addr = sqlite3VdbeAddOp1(v, OP_IfPos, pLevel->iLeftJoin);
@@ -81625,15 +82664,17 @@
82664 for(i=0, pLevel=pWInfo->a; i<pTabList->nSrc; i++, pLevel++){
82665 struct SrcList_item *pTabItem = &pTabList->a[pLevel->iFrom];
82666 Table *pTab = pTabItem->pTab;
82667 assert( pTab!=0 );
82668 if( (pTab->tabFlags & TF_Ephemeral)!=0 || pTab->pSelect ) continue;
82669 if( (pWInfo->wctrlFlags & WHERE_OMIT_CLOSE)==0 ){
82670 if( !pWInfo->okOnePass && (pLevel->plan.wsFlags & WHERE_IDX_ONLY)==0 ){
82671 sqlite3VdbeAddOp1(v, OP_Close, pTabItem->iCursor);
82672 }
82673 if( (pLevel->plan.wsFlags & WHERE_INDEXED)!=0 ){
82674 sqlite3VdbeAddOp1(v, OP_Close, pLevel->iIdxCur);
82675 }
82676 }
82677
82678 /* If this scan uses an index, make code substitutions to read data
82679 ** from the index in preference to the table. Sometimes, this means
82680 ** the table need never be read from. This is a performance boost,
@@ -81645,15 +82686,15 @@
82686 ** sqlite3WhereEnd will have created code that references the table
82687 ** directly. This loop scans all that code looking for opcodes
82688 ** that reference the table and converts them into opcodes that
82689 ** reference the index.
82690 */
82691 if( (pLevel->plan.wsFlags & WHERE_INDEXED)!=0 ){
82692 int k, j, last;
82693 VdbeOp *pOp;
82694 Index *pIdx = pLevel->plan.u.pIdx;
82695 int useIndexOnly = pLevel->plan.wsFlags & WHERE_IDX_ONLY;
82696
82697 assert( pIdx!=0 );
82698 pOp = sqlite3VdbeGetOp(v, pWInfo->iTop);
82699 last = sqlite3VdbeCurrentAddr(v);
82700 for(k=pWInfo->iTop; k<last; k++, pOp++){
@@ -81774,38 +82815,38 @@
82815 ** YYNRULE the number of rules in the grammar
82816 ** YYERRORSYMBOL is the code number of the error symbol. If not
82817 ** defined, then do no error processing.
82818 */
82819 #define YYCODETYPE unsigned char
82820 #define YYNOCODE 251
82821 #define YYACTIONTYPE unsigned short int
82822 #define YYWILDCARD 62
82823 #define sqlite3ParserTOKENTYPE Token
82824 typedef union {
82825 int yyinit;
82826 sqlite3ParserTOKENTYPE yy0;
82827 struct LimitVal yy64;
82828 Expr* yy122;
82829 Select* yy159;
82830 IdList* yy180;
82831 struct {int value; int mask;} yy207;
82832 struct LikeOp yy318;
82833 TriggerStep* yy327;
82834 SrcList* yy347;
82835 int yy392;
82836 struct TrigEvent yy410;
82837 ExprList* yy442;
82838 } YYMINORTYPE;
82839 #ifndef YYSTACKDEPTH
82840 #define YYSTACKDEPTH 100
82841 #endif
82842 #define sqlite3ParserARG_SDECL Parse *pParse;
82843 #define sqlite3ParserARG_PDECL ,Parse *pParse
82844 #define sqlite3ParserARG_FETCH Parse *pParse = yypParser->pParse
82845 #define sqlite3ParserARG_STORE yypParser->pParse = pParse
82846 #define YYNSTATE 610
82847 #define YYNRULE 319
82848 #define YYFALLBACK 1
82849 #define YY_NO_ACTION (YYNSTATE+YYNRULE+2)
82850 #define YY_ACCEPT_ACTION (YYNSTATE+YYNRULE+1)
82851 #define YY_ERROR_ACTION (YYNSTATE+YYNRULE)
82852
@@ -81860,427 +82901,431 @@
82901 ** yy_reduce_ofst[] For each state, the offset into yy_action for
82902 ** shifting non-terminals after a reduce.
82903 ** yy_default[] Default action for each state.
82904 */
82905 static const YYACTIONTYPE yy_action[] = {
82906 /* 0 */ 304, 930, 120, 609, 1, 178, 214, 436, 62, 62,
82907 /* 10 */ 62, 62, 216, 64, 64, 64, 64, 65, 65, 66,
82908 /* 20 */ 66, 66, 67, 216, 406, 403, 443, 449, 69, 64,
82909 /* 30 */ 64, 64, 64, 65, 65, 66, 66, 66, 67, 216,
82910 /* 40 */ 469, 467, 336, 174, 61, 60, 309, 453, 454, 450,
82911 /* 50 */ 450, 63, 63, 62, 62, 62, 62, 200, 64, 64,
82912 /* 60 */ 64, 64, 65, 65, 66, 66, 66, 67, 216, 304,
82913 /* 70 */ 510, 312, 436, 509, 438, 83, 64, 64, 64, 64,
82914 /* 80 */ 65, 65, 66, 66, 66, 67, 216, 65, 65, 66,
82915 /* 90 */ 66, 66, 67, 216, 511, 443, 449, 325, 408, 59,
82916 /* 100 */ 465, 218, 57, 213, 411, 496, 428, 440, 440, 440,
82917 /* 110 */ 206, 67, 216, 61, 60, 309, 453, 454, 450, 450,
82918 /* 120 */ 63, 63, 62, 62, 62, 62, 552, 64, 64, 64,
82919 /* 130 */ 64, 65, 65, 66, 66, 66, 67, 216, 304, 228,
82920 /* 140 */ 186, 469, 544, 312, 433, 170, 114, 256, 357, 261,
82921 /* 150 */ 358, 181, 425, 20, 426, 542, 153, 85, 265, 465,
82922 /* 160 */ 218, 150, 151, 539, 443, 449, 95, 311, 394, 412,
82923 /* 170 */ 413, 510, 276, 427, 436, 438, 152, 553, 545, 589,
82924 /* 180 */ 590, 539, 61, 60, 309, 453, 454, 450, 450, 63,
82925 /* 190 */ 63, 62, 62, 62, 62, 402, 64, 64, 64, 64,
82926 /* 200 */ 65, 65, 66, 66, 66, 67, 216, 304, 440, 440,
82927 /* 210 */ 440, 228, 109, 411, 399, 523, 593, 330, 114, 256,
82928 /* 220 */ 357, 261, 358, 181, 187, 330, 485, 359, 362, 363,
82929 /* 230 */ 265, 593, 241, 443, 449, 592, 591, 248, 364, 436,
82930 /* 240 */ 432, 35, 492, 66, 66, 66, 67, 216, 432, 42,
82931 /* 250 */ 592, 61, 60, 309, 453, 454, 450, 450, 63, 63,
82932 /* 260 */ 62, 62, 62, 62, 401, 64, 64, 64, 64, 65,
82933 /* 270 */ 65, 66, 66, 66, 67, 216, 304, 570, 412, 413,
82934 /* 280 */ 187, 501, 344, 359, 362, 363, 215, 354, 346, 221,
82935 /* 290 */ 330, 341, 330, 56, 364, 569, 588, 217, 68, 156,
82936 /* 300 */ 70, 155, 443, 449, 68, 187, 70, 155, 359, 362,
82937 /* 310 */ 363, 397, 217, 432, 35, 432, 36, 148, 569, 364,
82938 /* 320 */ 61, 60, 309, 453, 454, 450, 450, 63, 63, 62,
82939 /* 330 */ 62, 62, 62, 433, 64, 64, 64, 64, 65, 65,
82940 /* 340 */ 66, 66, 66, 67, 216, 387, 282, 281, 330, 304,
82941 /* 350 */ 474, 68, 480, 70, 155, 344, 214, 154, 299, 330,
82942 /* 360 */ 343, 467, 543, 174, 384, 475, 257, 247, 387, 282,
82943 /* 370 */ 281, 432, 28, 411, 160, 443, 449, 258, 476, 214,
82944 /* 380 */ 516, 496, 432, 42, 198, 492, 68, 162, 70, 155,
82945 /* 390 */ 517, 433, 78, 61, 60, 309, 453, 454, 450, 450,
82946 /* 400 */ 63, 63, 62, 62, 62, 62, 595, 64, 64, 64,
82947 /* 410 */ 64, 65, 65, 66, 66, 66, 67, 216, 433, 367,
82948 /* 420 */ 349, 433, 304, 220, 222, 544, 505, 330, 465, 330,
82949 /* 430 */ 230, 330, 240, 163, 161, 554, 20, 431, 412, 413,
82950 /* 440 */ 2, 430, 385, 375, 411, 198, 182, 249, 443, 449,
82951 /* 450 */ 432, 35, 432, 50, 432, 50, 310, 460, 461, 17,
82952 /* 460 */ 207, 335, 460, 461, 388, 81, 61, 60, 309, 453,
82953 /* 470 */ 454, 450, 450, 63, 63, 62, 62, 62, 62, 433,
82954 /* 480 */ 64, 64, 64, 64, 65, 65, 66, 66, 66, 67,
82955 /* 490 */ 216, 304, 348, 504, 433, 508, 531, 486, 320, 353,
82956 /* 500 */ 321, 306, 457, 385, 23, 331, 265, 470, 411, 412,
82957 /* 510 */ 413, 444, 445, 551, 526, 307, 532, 443, 449, 217,
82958 /* 520 */ 550, 496, 432, 3, 217, 381, 607, 921, 333, 921,
82959 /* 530 */ 456, 456, 447, 448, 276, 61, 60, 309, 453, 454,
82960 /* 540 */ 450, 450, 63, 63, 62, 62, 62, 62, 410, 64,
82961 /* 550 */ 64, 64, 64, 65, 65, 66, 66, 66, 67, 216,
82962 /* 560 */ 304, 446, 607, 920, 525, 920, 604, 264, 314, 474,
82963 /* 570 */ 411, 123, 411, 412, 413, 124, 277, 487, 234, 333,
82964 /* 580 */ 411, 456, 456, 319, 475, 411, 443, 449, 333, 377,
82965 /* 590 */ 456, 456, 286, 333, 380, 456, 456, 476, 178, 340,
82966 /* 600 */ 436, 420, 604, 315, 61, 60, 309, 453, 454, 450,
82967 /* 610 */ 450, 63, 63, 62, 62, 62, 62, 330, 64, 64,
82968 /* 620 */ 64, 64, 65, 65, 66, 66, 66, 67, 216, 304,
82969 /* 630 */ 289, 5, 287, 268, 466, 412, 413, 412, 413, 396,
82970 /* 640 */ 432, 29, 503, 330, 159, 412, 413, 610, 406, 403,
82971 /* 650 */ 412, 413, 414, 415, 416, 443, 449, 333, 214, 456,
82972 /* 660 */ 456, 488, 276, 489, 21, 436, 432, 24, 436, 487,
82973 /* 670 */ 514, 515, 395, 61, 60, 309, 453, 454, 450, 450,
82974 /* 680 */ 63, 63, 62, 62, 62, 62, 330, 64, 64, 64,
82975 /* 690 */ 64, 65, 65, 66, 66, 66, 67, 216, 304, 560,
82976 /* 700 */ 374, 560, 352, 94, 578, 330, 567, 515, 330, 432,
82977 /* 710 */ 33, 330, 288, 330, 562, 330, 544, 330, 561, 183,
82978 /* 720 */ 184, 185, 603, 303, 443, 449, 600, 20, 432, 54,
82979 /* 730 */ 376, 432, 53, 436, 432, 99, 432, 97, 432, 102,
82980 /* 740 */ 432, 103, 61, 60, 309, 453, 454, 450, 450, 63,
82981 /* 750 */ 63, 62, 62, 62, 62, 330, 64, 64, 64, 64,
82982 /* 760 */ 65, 65, 66, 66, 66, 67, 216, 304, 330, 405,
82983 /* 770 */ 1, 202, 330, 512, 330, 214, 330, 171, 432, 108,
82984 /* 780 */ 330, 421, 429, 330, 487, 342, 330, 384, 19, 386,
82985 /* 790 */ 145, 432, 110, 443, 449, 432, 16, 432, 100, 432,
82986 /* 800 */ 34, 351, 270, 432, 98, 433, 432, 25, 276, 432,
82987 /* 810 */ 55, 61, 60, 309, 453, 454, 450, 450, 63, 63,
82988 /* 820 */ 62, 62, 62, 62, 330, 64, 64, 64, 64, 65,
82989 /* 830 */ 65, 66, 66, 66, 67, 216, 304, 330, 323, 119,
82990 /* 840 */ 274, 330, 272, 330, 355, 330, 422, 432, 111, 330,
82991 /* 850 */ 580, 159, 115, 233, 330, 177, 161, 439, 463, 463,
82992 /* 860 */ 432, 112, 443, 449, 432, 113, 432, 26, 432, 37,
82993 /* 870 */ 649, 431, 432, 38, 492, 430, 487, 432, 27, 264,
82994 /* 880 */ 61, 71, 309, 453, 454, 450, 450, 63, 63, 62,
82995 /* 890 */ 62, 62, 62, 330, 64, 64, 64, 64, 65, 65,
82996 /* 900 */ 66, 66, 66, 67, 216, 304, 330, 264, 264, 528,
82997 /* 910 */ 330, 157, 330, 252, 330, 229, 432, 39, 330, 482,
82998 /* 920 */ 332, 478, 77, 330, 79, 330, 483, 520, 521, 432,
82999 /* 930 */ 40, 443, 449, 432, 41, 432, 43, 432, 44, 492,
83000 /* 940 */ 491, 432, 45, 316, 317, 433, 432, 30, 432, 31,
83001 /* 950 */ 60, 309, 453, 454, 450, 450, 63, 63, 62, 62,
83002 /* 960 */ 62, 62, 330, 64, 64, 64, 64, 65, 65, 66,
83003 /* 970 */ 66, 66, 67, 216, 304, 330, 264, 564, 254, 330,
83004 /* 980 */ 458, 330, 22, 330, 495, 432, 46, 330, 494, 535,
83005 /* 990 */ 179, 186, 330, 267, 330, 186, 451, 497, 432, 47,
83006 /* 1000 */ 443, 449, 432, 48, 432, 49, 432, 32, 182, 262,
83007 /* 1010 */ 432, 10, 318, 276, 389, 432, 51, 432, 52, 276,
83008 /* 1020 */ 309, 453, 454, 450, 450, 63, 63, 62, 62, 62,
83009 /* 1030 */ 62, 276, 64, 64, 64, 64, 65, 65, 66, 66,
83010 /* 1040 */ 66, 67, 216, 165, 276, 276, 189, 192, 235, 236,
83011 /* 1050 */ 237, 168, 239, 566, 105, 581, 18, 530, 529, 73,
83012 /* 1060 */ 337, 582, 4, 306, 605, 527, 308, 211, 366, 294,
83013 /* 1070 */ 186, 263, 533, 231, 334, 565, 295, 186, 534, 546,
83014 /* 1080 */ 433, 433, 573, 574, 179, 92, 232, 292, 209, 269,
83015 /* 1090 */ 569, 339, 271, 853, 208, 273, 275, 210, 585, 195,
83016 /* 1100 */ 92, 469, 371, 606, 602, 8, 302, 423, 280, 379,
83017 /* 1110 */ 382, 383, 147, 242, 283, 437, 462, 284, 285, 577,
83018 /* 1120 */ 338, 76, 75, 587, 293, 296, 297, 599, 481, 464,
83019 /* 1130 */ 74, 328, 329, 250, 526, 438, 572, 166, 290, 393,
83020 /* 1140 */ 392, 291, 281, 409, 537, 584, 305, 484, 259, 540,
83021 /* 1150 */ 417, 214, 418, 214, 536, 326, 538, 419, 361, 167,
83022 /* 1160 */ 73, 337, 169, 4, 7, 327, 347, 308, 440, 440,
83023 /* 1170 */ 440, 441, 442, 11, 85, 334, 398, 84, 434, 345,
83024 /* 1180 */ 243, 58, 244, 73, 337, 80, 4, 245, 435, 246,
83025 /* 1190 */ 308, 176, 339, 479, 86, 121, 356, 350, 334, 493,
83026 /* 1200 */ 251, 253, 469, 499, 255, 513, 500, 518, 313, 519,
83027 /* 1210 */ 260, 523, 125, 522, 226, 339, 219, 524, 368, 190,
83028 /* 1220 */ 191, 300, 76, 75, 502, 469, 225, 227, 547, 541,
83029 /* 1230 */ 548, 74, 328, 329, 301, 555, 438, 549, 370, 193,
83030 /* 1240 */ 372, 194, 557, 89, 196, 76, 75, 278, 378, 117,
83031 /* 1250 */ 558, 568, 133, 390, 74, 328, 329, 199, 391, 438,
83032 /* 1260 */ 322, 134, 135, 136, 575, 143, 583, 596, 139, 440,
83033 /* 1270 */ 440, 440, 441, 442, 11, 597, 598, 601, 137, 142,
83034 /* 1280 */ 101, 224, 104, 407, 238, 424, 650, 651, 93, 172,
83035 /* 1290 */ 96, 173, 440, 440, 440, 441, 442, 11, 452, 455,
83036 /* 1300 */ 72, 471, 459, 468, 472, 144, 158, 6, 473, 490,
83037 /* 1310 */ 107, 175, 477, 82, 13, 122, 12, 180, 506, 118,
83038 /* 1320 */ 498, 164, 507, 324, 223, 87, 126, 116, 266, 127,
83039 /* 1330 */ 88, 128, 188, 258, 360, 369, 146, 556, 129, 373,
83040 /* 1340 */ 179, 365, 279, 197, 131, 130, 563, 9, 571, 132,
83041 /* 1350 */ 559, 201, 14, 576, 203, 204, 205, 579, 140, 138,
83042 /* 1360 */ 141, 15, 586, 594, 212, 106, 400, 298, 149, 404,
83043 /* 1370 */ 931, 608, 90, 91,
83044 };
83045 static const YYCODETYPE yy_lookahead[] = {
83046 /* 0 */ 19, 142, 143, 144, 145, 24, 113, 26, 72, 73,
83047 /* 10 */ 74, 75, 87, 77, 78, 79, 80, 81, 82, 83,
83048 /* 20 */ 84, 85, 86, 87, 1, 2, 45, 46, 76, 77,
83049 /* 30 */ 78, 79, 80, 81, 82, 83, 84, 85, 86, 87,
83050 /* 40 */ 61, 165, 166, 167, 63, 64, 65, 66, 67, 68,
83051 /* 50 */ 69, 70, 71, 72, 73, 74, 75, 25, 77, 78,
83052 /* 60 */ 79, 80, 81, 82, 83, 84, 85, 86, 87, 19,
83053 /* 70 */ 91, 19, 91, 173, 95, 25, 77, 78, 79, 80,
83054 /* 80 */ 81, 82, 83, 84, 85, 86, 87, 81, 82, 83,
83055 /* 90 */ 84, 85, 86, 87, 173, 45, 46, 146, 147, 49,
83056 /* 100 */ 81, 82, 22, 152, 26, 150, 26, 128, 129, 130,
83057 /* 110 */ 159, 86, 87, 63, 64, 65, 66, 67, 68, 69,
83058 /* 120 */ 70, 71, 72, 73, 74, 75, 185, 77, 78, 79,
83059 /* 130 */ 80, 81, 82, 83, 84, 85, 86, 87, 19, 87,
83060 /* 140 */ 25, 61, 150, 19, 193, 93, 94, 95, 96, 97,
83061 /* 150 */ 98, 99, 160, 161, 171, 172, 25, 125, 106, 81,
83062 /* 160 */ 82, 81, 82, 180, 45, 46, 47, 212, 217, 91,
83063 /* 170 */ 92, 91, 150, 172, 26, 95, 184, 185, 185, 101,
83064 /* 180 */ 102, 180, 63, 64, 65, 66, 67, 68, 69, 70,
83065 /* 190 */ 71, 72, 73, 74, 75, 244, 77, 78, 79, 80,
83066 /* 200 */ 81, 82, 83, 84, 85, 86, 87, 19, 128, 129,
83067 /* 210 */ 130, 87, 24, 26, 192, 100, 150, 150, 94, 95,
83068 /* 220 */ 96, 97, 98, 99, 93, 150, 25, 96, 97, 98,
83069 /* 230 */ 106, 150, 194, 45, 46, 169, 170, 150, 107, 91,
83070 /* 240 */ 173, 174, 165, 83, 84, 85, 86, 87, 173, 174,
83071 /* 250 */ 169, 63, 64, 65, 66, 67, 68, 69, 70, 71,
83072 /* 260 */ 72, 73, 74, 75, 242, 77, 78, 79, 80, 81,
83073 /* 270 */ 82, 83, 84, 85, 86, 87, 19, 11, 91, 92,
83074 /* 280 */ 93, 204, 215, 96, 97, 98, 196, 220, 213, 214,
83075 /* 290 */ 150, 190, 150, 203, 107, 52, 230, 231, 221, 159,
83076 /* 300 */ 223, 224, 45, 46, 221, 93, 223, 224, 96, 97,
83077 /* 310 */ 98, 230, 231, 173, 174, 173, 174, 116, 52, 107,
83078 /* 320 */ 63, 64, 65, 66, 67, 68, 69, 70, 71, 72,
83079 /* 330 */ 73, 74, 75, 193, 77, 78, 79, 80, 81, 82,
83080 /* 340 */ 83, 84, 85, 86, 87, 102, 103, 104, 150, 19,
83081 /* 350 */ 12, 221, 222, 223, 224, 215, 113, 159, 162, 150,
83082 /* 360 */ 220, 165, 166, 167, 150, 27, 95, 225, 102, 103,
83083 /* 370 */ 104, 173, 174, 26, 150, 45, 46, 106, 40, 113,
83084 /* 380 */ 42, 150, 173, 174, 159, 165, 221, 159, 223, 224,
83085 /* 390 */ 52, 193, 135, 63, 64, 65, 66, 67, 68, 69,
83086 /* 400 */ 70, 71, 72, 73, 74, 75, 241, 77, 78, 79,
83087 /* 410 */ 80, 81, 82, 83, 84, 85, 86, 87, 193, 19,
83088 /* 420 */ 150, 193, 19, 214, 204, 150, 23, 150, 81, 150,
83089 /* 430 */ 216, 150, 157, 205, 206, 160, 161, 110, 91, 92,
83090 /* 440 */ 22, 114, 217, 212, 26, 159, 46, 150, 45, 46,
83091 /* 450 */ 173, 174, 173, 174, 173, 174, 168, 169, 170, 234,
83092 /* 460 */ 159, 168, 169, 170, 239, 135, 63, 64, 65, 66,
83093 /* 470 */ 67, 68, 69, 70, 71, 72, 73, 74, 75, 193,
83094 /* 480 */ 77, 78, 79, 80, 81, 82, 83, 84, 85, 86,
83095 /* 490 */ 87, 19, 215, 23, 193, 23, 33, 207, 219, 150,
83096 /* 500 */ 219, 101, 23, 217, 22, 150, 106, 23, 26, 91,
83097 /* 510 */ 92, 45, 46, 180, 181, 154, 53, 45, 46, 231,
83098 /* 520 */ 187, 150, 173, 174, 231, 239, 22, 23, 109, 25,
83099 /* 530 */ 111, 112, 66, 67, 150, 63, 64, 65, 66, 67,
83100 /* 540 */ 68, 69, 70, 71, 72, 73, 74, 75, 150, 77,
83101 /* 550 */ 78, 79, 80, 81, 82, 83, 84, 85, 86, 87,
83102 /* 560 */ 19, 95, 22, 23, 23, 25, 62, 150, 105, 12,
83103 /* 570 */ 26, 23, 26, 91, 92, 23, 192, 25, 148, 109,
83104 /* 580 */ 26, 111, 112, 212, 27, 26, 45, 46, 109, 228,
83105 /* 590 */ 111, 112, 17, 109, 233, 111, 112, 40, 24, 42,
83106 /* 600 */ 26, 150, 62, 186, 63, 64, 65, 66, 67, 68,
83107 /* 610 */ 69, 70, 71, 72, 73, 74, 75, 150, 77, 78,
83108 /* 620 */ 79, 80, 81, 82, 83, 84, 85, 86, 87, 19,
83109 /* 630 */ 55, 195, 57, 23, 165, 91, 92, 91, 92, 94,
83110 /* 640 */ 173, 174, 83, 150, 92, 91, 92, 0, 1, 2,
83111 /* 650 */ 91, 92, 7, 8, 9, 45, 46, 109, 113, 111,
83112 /* 660 */ 112, 117, 150, 117, 22, 91, 173, 174, 26, 117,
83113 /* 670 */ 189, 190, 127, 63, 64, 65, 66, 67, 68, 69,
83114 /* 680 */ 70, 71, 72, 73, 74, 75, 150, 77, 78, 79,
83115 /* 690 */ 80, 81, 82, 83, 84, 85, 86, 87, 19, 102,
83116 /* 700 */ 103, 104, 19, 24, 192, 150, 189, 190, 150, 173,
83117 /* 710 */ 174, 150, 137, 150, 28, 150, 150, 150, 32, 102,
83118 /* 720 */ 103, 104, 247, 248, 45, 46, 160, 161, 173, 174,
83119 /* 730 */ 44, 173, 174, 91, 173, 174, 173, 174, 173, 174,
83120 /* 740 */ 173, 174, 63, 64, 65, 66, 67, 68, 69, 70,
83121 /* 750 */ 71, 72, 73, 74, 75, 150, 77, 78, 79, 80,
83122 /* 760 */ 81, 82, 83, 84, 85, 86, 87, 19, 150, 144,
83123 /* 770 */ 145, 159, 150, 164, 150, 113, 150, 22, 173, 174,
83124 /* 780 */ 150, 150, 173, 150, 25, 150, 150, 150, 22, 127,
83125 /* 790 */ 24, 173, 174, 45, 46, 173, 174, 173, 174, 173,
83126 /* 800 */ 174, 118, 17, 173, 174, 193, 173, 174, 150, 173,
83127 /* 810 */ 174, 63, 64, 65, 66, 67, 68, 69, 70, 71,
83128 /* 820 */ 72, 73, 74, 75, 150, 77, 78, 79, 80, 81,
83129 /* 830 */ 82, 83, 84, 85, 86, 87, 19, 150, 245, 246,
83130 /* 840 */ 55, 150, 57, 150, 83, 150, 150, 173, 174, 150,
83131 /* 850 */ 192, 92, 150, 216, 150, 205, 206, 150, 128, 129,
83132 /* 860 */ 173, 174, 45, 46, 173, 174, 173, 174, 173, 174,
83133 /* 870 */ 115, 110, 173, 174, 165, 114, 117, 173, 174, 150,
83134 /* 880 */ 63, 64, 65, 66, 67, 68, 69, 70, 71, 72,
83135 /* 890 */ 73, 74, 75, 150, 77, 78, 79, 80, 81, 82,
83136 /* 900 */ 83, 84, 85, 86, 87, 19, 150, 150, 150, 182,
83137 /* 910 */ 150, 159, 150, 204, 150, 186, 173, 174, 150, 30,
83138 /* 920 */ 19, 150, 134, 150, 136, 150, 37, 7, 8, 173,
83139 /* 930 */ 174, 45, 46, 173, 174, 173, 174, 173, 174, 165,
83140 /* 940 */ 150, 173, 174, 186, 186, 193, 173, 174, 173, 174,
83141 /* 950 */ 64, 65, 66, 67, 68, 69, 70, 71, 72, 73,
83142 /* 960 */ 74, 75, 150, 77, 78, 79, 80, 81, 82, 83,
83143 /* 970 */ 84, 85, 86, 87, 19, 150, 150, 21, 204, 150,
83144 /* 980 */ 23, 150, 25, 150, 150, 173, 174, 150, 23, 23,
83145 /* 990 */ 25, 25, 150, 23, 150, 25, 95, 150, 173, 174,
83146 /* 1000 */ 45, 46, 173, 174, 173, 174, 173, 174, 46, 150,
83147 /* 1010 */ 173, 174, 186, 150, 58, 173, 174, 173, 174, 150,
83148 /* 1020 */ 65, 66, 67, 68, 69, 70, 71, 72, 73, 74,
83149 /* 1030 */ 75, 150, 77, 78, 79, 80, 81, 82, 83, 84,
83150 /* 1040 */ 85, 86, 87, 5, 150, 150, 159, 159, 10, 11,
83151 /* 1050 */ 12, 13, 14, 97, 16, 192, 22, 94, 95, 19,
83152 /* 1060 */ 20, 192, 22, 101, 23, 150, 26, 29, 23, 31,
83153 /* 1070 */ 25, 150, 182, 192, 34, 23, 38, 25, 182, 150,
83154 /* 1080 */ 193, 193, 23, 23, 25, 25, 192, 192, 50, 150,
83155 /* 1090 */ 52, 51, 150, 137, 56, 150, 150, 59, 23, 235,
83156 /* 1100 */ 25, 61, 236, 62, 23, 71, 25, 153, 150, 150,
83157 /* 1110 */ 150, 150, 195, 197, 150, 165, 232, 150, 150, 150,
83158 /* 1120 */ 227, 81, 82, 150, 150, 150, 150, 150, 176, 232,
83159 /* 1130 */ 90, 91, 92, 208, 181, 95, 198, 6, 208, 208,
83160 /* 1140 */ 102, 103, 104, 149, 165, 198, 108, 176, 176, 165,
83161 /* 1150 */ 149, 113, 149, 113, 176, 149, 176, 13, 177, 151,
83162 /* 1160 */ 19, 20, 151, 22, 25, 158, 122, 26, 128, 129,
83163 /* 1170 */ 130, 131, 132, 133, 125, 34, 138, 123, 193, 121,
83164 /* 1180 */ 198, 124, 199, 19, 20, 134, 22, 200, 202, 201,
83165 /* 1190 */ 26, 115, 51, 156, 101, 156, 101, 120, 34, 210,
83166 /* 1200 */ 209, 209, 61, 210, 209, 175, 210, 175, 43, 183,
83167 /* 1210 */ 175, 100, 22, 177, 87, 51, 226, 175, 18, 155,
83168 /* 1220 */ 155, 178, 81, 82, 83, 61, 229, 229, 175, 183,
83169 /* 1230 */ 175, 90, 91, 92, 178, 156, 95, 175, 156, 155,
83170 /* 1240 */ 41, 156, 156, 134, 155, 81, 82, 237, 156, 63,
83171 /* 1250 */ 238, 188, 22, 156, 90, 91, 92, 188, 18, 95,
83172 /* 1260 */ 156, 191, 191, 191, 198, 218, 198, 36, 188, 128,
83173 /* 1270 */ 129, 130, 131, 132, 133, 156, 156, 140, 191, 218,
83174 /* 1280 */ 163, 179, 179, 1, 15, 23, 115, 115, 240, 115,
83175 /* 1290 */ 240, 115, 128, 129, 130, 131, 132, 133, 95, 110,
83176 /* 1300 */ 22, 11, 23, 23, 23, 22, 22, 119, 23, 117,
83177 /* 1310 */ 243, 25, 23, 25, 119, 22, 25, 119, 23, 246,
83178 /* 1320 */ 118, 115, 23, 249, 47, 22, 22, 35, 23, 22,
83179 /* 1330 */ 22, 22, 99, 106, 47, 19, 24, 20, 101, 39,
83180 /* 1340 */ 25, 47, 137, 101, 22, 48, 48, 5, 1, 105,
83181 /* 1350 */ 54, 126, 22, 1, 116, 17, 120, 20, 105, 116,
83182 /* 1360 */ 126, 22, 127, 23, 15, 17, 60, 139, 22, 3,
83183 /* 1370 */ 250, 4, 71, 71,
83184 };
83185 #define YY_SHIFT_USE_DFLT (-108)
83186 #define YY_SHIFT_MAX 404
83187 static const short yy_shift_ofst[] = {
83188 /* 0 */ 23, 1038, 1040, -19, 1040, 1164, 1164, 187, 78, 243,
83189 /* 10 */ 119, 1164, 1164, 1164, 1164, 1164, -48, 266, 347, 554,
83190 /* 20 */ 148, 19, 19, -107, 50, 188, 257, 330, 403, 472,
83191 /* 30 */ 541, 610, 679, 748, 817, 748, 748, 748, 748, 748,
83192 /* 40 */ 748, 748, 748, 748, 748, 748, 748, 748, 748, 748,
83193 /* 50 */ 748, 748, 748, 886, 955, 955, 1141, 1164, 1164, 1164,
83194 /* 60 */ 1164, 1164, 1164, 1164, 1164, 1164, 1164, 1164, 1164, 1164,
83195 /* 70 */ 1164, 1164, 1164, 1164, 1164, 1164, 1164, 1164, 1164, 1164,
83196 /* 80 */ 1164, 1164, 1164, 1164, 1164, 1164, 1164, 1164, 1164, 1164,
83197 /* 90 */ 1164, 1164, 1164, 1164, 1164, 1164, 1164, -64, -64, -1,
83198 /* 100 */ -1, 52, 6, 160, 400, 956, 554, 554, 25, 148,
83199 /* 110 */ -75, -108, -108, -108, 80, 124, 338, 338, 504, 540,
83200 /* 120 */ 647, 574, 554, 574, 574, 554, 554, 554, 554, 554,
83201 /* 130 */ 554, 554, 554, 554, 554, 554, 554, 554, 554, 554,
83202 /* 140 */ 554, 554, 545, 662, -107, -107, -107, -108, -108, -108,
83203 /* 150 */ -21, -21, 131, 212, 470, 418, 479, 484, 557, 544,
83204 /* 160 */ 546, 482, 548, 552, 559, 645, 554, 554, 554, 554,
83205 /* 170 */ 554, 761, 554, 554, 642, 554, 554, 759, 554, 554,
83206 /* 180 */ 554, 554, 554, 463, 463, 463, 554, 554, 554, 419,
83207 /* 190 */ 554, 554, 419, 554, 686, 597, 554, 554, 419, 554,
83208 /* 200 */ 554, 554, 419, 554, 554, 554, 419, 419, 554, 554,
83209 /* 210 */ 554, 554, 554, 766, 327, 201, 148, 730, 730, 788,
83210 /* 220 */ 889, 889, 683, 889, 962, 889, 148, 889, 148, 115,
83211 /* 230 */ 32, 683, 683, 32, 1131, 1131, 1131, 1131, 1144, 1144,
83212 /* 240 */ 1139, -107, 1049, 1044, 1054, 1058, 1057, 1051, 1076, 1076,
83213 /* 250 */ 1093, 1077, 1093, 1077, 1093, 1077, 1095, 1095, 1165, 1095,
83214 /* 260 */ 1111, 1095, 1190, 1127, 1127, 1165, 1095, 1095, 1095, 1190,
83215 /* 270 */ 1200, 1076, 1200, 1076, 1200, 1076, 1076, 1199, 1109, 1200,
83216 /* 280 */ 1076, 1186, 1186, 1230, 1049, 1076, 1240, 1240, 1240, 1240,
83217 /* 290 */ 1049, 1186, 1230, 1076, 1231, 1231, 1076, 1076, 1137, -108,
83218 /* 300 */ -108, -108, -108, -108, 466, 575, 617, 785, 755, 901,
83219 /* 310 */ 957, 965, 271, 920, 963, 966, 970, 1045, 1052, 1059,
83220 /* 320 */ 1060, 1075, 1034, 1081, 1041, 1282, 1269, 1262, 1171, 1172,
83221 /* 330 */ 1174, 1176, 1203, 1189, 1278, 1279, 1280, 1283, 1290, 1284,
83222 /* 340 */ 1281, 1286, 1285, 1289, 1288, 1188, 1291, 1195, 1288, 1192,
83223 /* 350 */ 1293, 1198, 1202, 1206, 1295, 1299, 1292, 1277, 1303, 1287,
83224 /* 360 */ 1304, 1305, 1307, 1308, 1294, 1309, 1233, 1227, 1316, 1317,
83225 /* 370 */ 1312, 1237, 1300, 1296, 1297, 1315, 1298, 1205, 1242, 1322,
83226 /* 380 */ 1342, 1347, 1244, 1301, 1302, 1225, 1330, 1238, 1352, 1338,
83227 /* 390 */ 1236, 1337, 1243, 1253, 1234, 1339, 1235, 1340, 1348, 1306,
83228 /* 400 */ 1349, 1228, 1346, 1366, 1367,
83229 };
83230 #define YY_REDUCE_USE_DFLT (-142)
83231 #define YY_REDUCE_MAX 303
83232 static const short yy_reduce_ofst[] = {
83233 /* 0 */ -141, -49, 140, 77, 198, 67, 75, -8, 66, 225,
83234 /* 10 */ 165, 142, 209, 277, 279, 281, 130, 286, 81, 275,
83235 /* 20 */ 196, 288, 293, 228, 83, 83, 83, 83, 83, 83,
83236 /* 30 */ 83, 83, 83, 83, 83, 83, 83, 83, 83, 83,
83237 /* 40 */ 83, 83, 83, 83, 83, 83, 83, 83, 83, 83,
83238 /* 50 */ 83, 83, 83, 83, 83, 83, 349, 467, 493, 536,
83239 /* 60 */ 555, 558, 561, 563, 565, 567, 605, 618, 622, 624,
83240 /* 70 */ 626, 630, 633, 636, 674, 687, 691, 693, 695, 699,
83241 /* 80 */ 704, 743, 756, 760, 762, 764, 768, 773, 775, 812,
83242 /* 90 */ 825, 829, 831, 833, 837, 842, 844, 83, 83, 83,
83243 /* 100 */ 83, -17, 83, 83, 333, 361, 22, 566, 83, -124,
83244 /* 110 */ 83, 83, 83, 83, 609, 1, 481, 517, 475, 475,
83245 /* 120 */ 625, 220, -45, 709, 774, 417, 729, 757, 758, 384,
83246 /* 130 */ 231, 826, 214, 371, 512, 658, 863, 869, 881, 894,
83247 /* 140 */ 637, 895, 301, 612, 752, 887, 888, 90, 650, 593,
83248 /* 150 */ -100, -79, -59, -7, 38, 87, 38, 38, 101, 224,
83249 /* 160 */ 270, 297, 38, 290, 355, 430, 398, 451, 631, 696,
83250 /* 170 */ 702, 436, 355, 707, 469, 635, 771, 290, 790, 834,
83251 /* 180 */ 847, 859, 915, 727, 890, 896, 921, 929, 939, 38,
83252 /* 190 */ 942, 945, 38, 946, 864, 866, 958, 959, 38, 960,
83253 /* 200 */ 961, 964, 38, 967, 968, 969, 38, 38, 973, 974,
83254 /* 210 */ 975, 976, 977, 954, 917, 916, 950, 884, 897, 893,
83255 /* 220 */ 952, 971, 925, 972, 953, 978, 979, 980, 984, 981,
83256 /* 230 */ 938, 930, 931, 947, 994, 1001, 1003, 1006, 1008, 1011,
83257 /* 240 */ 1007, 985, 982, 983, 987, 988, 986, 990, 1037, 1039,
83258 /* 250 */ 991, 989, 992, 993, 995, 996, 1030, 1032, 1026, 1035,
83259 /* 260 */ 1036, 1042, 1043, 997, 998, 1046, 1053, 1055, 1062, 1056,
83260 /* 270 */ 1064, 1079, 1065, 1082, 1084, 1085, 1086, 1010, 1012, 1089,
83261 /* 280 */ 1092, 1063, 1069, 1047, 1066, 1097, 1070, 1071, 1072, 1087,
83262 /* 290 */ 1068, 1080, 1061, 1104, 1048, 1050, 1119, 1120, 1067, 1117,
83263 /* 300 */ 1102, 1103, 1073, 1074,
83264 };
83265 static const YYACTIONTYPE yy_default[] = {
83266 /* 0 */ 615, 929, 848, 736, 929, 848, 929, 929, 875, 929,
83267 /* 10 */ 904, 846, 929, 929, 929, 929, 820, 929, 875, 929,
83268 /* 20 */ 652, 875, 875, 740, 771, 929, 929, 929, 929, 929,
83269 /* 30 */ 929, 929, 929, 772, 929, 850, 845, 841, 843, 842,
83270 /* 40 */ 849, 773, 762, 769, 776, 751, 888, 778, 779, 785,
83271 /* 50 */ 786, 905, 903, 808, 807, 826, 929, 929, 929, 929,
83272 /* 60 */ 929, 929, 929, 929, 929, 929, 929, 929, 929, 929,
83273 /* 70 */ 929, 929, 929, 929, 929, 929, 929, 929, 929, 929,
83274 /* 80 */ 929, 929, 929, 929, 929, 929, 929, 929, 929, 929,
83275 /* 90 */ 929, 929, 929, 929, 929, 929, 929, 810, 832, 809,
83276 /* 100 */ 819, 645, 811, 812, 705, 640, 929, 929, 813, 929,
83277 /* 110 */ 814, 827, 828, 829, 929, 929, 929, 929, 929, 929,
83278 /* 120 */ 615, 736, 929, 736, 736, 929, 929, 929, 929, 929,
83279 /* 130 */ 929, 929, 929, 929, 929, 929, 929, 929, 929, 929,
83280 /* 140 */ 929, 929, 929, 929, 929, 929, 929, 730, 740, 922,
83281 /* 150 */ 929, 929, 696, 929, 929, 929, 929, 929, 929, 929,
83282 /* 160 */ 929, 929, 929, 929, 929, 623, 621, 929, 929, 929,
83283 /* 170 */ 929, 728, 929, 929, 654, 929, 929, 738, 929, 929,
83284 /* 180 */ 929, 929, 929, 929, 929, 929, 929, 929, 929, 642,
83285 /* 190 */ 929, 929, 717, 929, 881, 929, 929, 929, 895, 929,
83286 /* 200 */ 929, 929, 893, 929, 929, 929, 719, 781, 861, 929,
83287 /* 210 */ 908, 910, 929, 929, 728, 737, 929, 929, 929, 844,
83288 /* 220 */ 765, 765, 753, 765, 675, 765, 929, 765, 929, 678,
83289 /* 230 */ 775, 753, 753, 775, 620, 620, 620, 620, 631, 631,
83290 /* 240 */ 695, 929, 775, 766, 768, 758, 770, 929, 744, 744,
83291 /* 250 */ 752, 757, 752, 757, 752, 757, 707, 707, 692, 707,
83292 /* 260 */ 678, 707, 854, 858, 858, 692, 707, 707, 707, 854,
83293 /* 270 */ 637, 744, 637, 744, 637, 744, 744, 885, 887, 637,
83294 /* 280 */ 744, 709, 709, 787, 775, 744, 716, 716, 716, 716,
83295 /* 290 */ 775, 709, 787, 744, 907, 907, 744, 744, 915, 662,
83296 /* 300 */ 680, 680, 922, 927, 929, 929, 929, 929, 794, 929,
83297 /* 310 */ 929, 929, 929, 929, 929, 929, 929, 929, 929, 929,
83298 /* 320 */ 929, 929, 868, 929, 929, 929, 629, 929, 799, 795,
83299 /* 330 */ 929, 796, 929, 722, 929, 929, 929, 929, 929, 929,
83300 /* 340 */ 929, 929, 929, 929, 847, 929, 759, 929, 767, 929,
83301 /* 350 */ 929, 929, 929, 929, 929, 929, 929, 929, 929, 929,
83302 /* 360 */ 929, 929, 929, 929, 929, 929, 929, 929, 929, 929,
83303 /* 370 */ 929, 929, 929, 929, 883, 884, 929, 929, 929, 929,
83304 /* 380 */ 929, 929, 929, 929, 929, 929, 929, 929, 929, 929,
83305 /* 390 */ 929, 929, 929, 929, 929, 929, 929, 929, 929, 914,
83306 /* 400 */ 929, 929, 917, 616, 929, 611, 613, 614, 618, 619,
83307 /* 410 */ 622, 649, 650, 651, 624, 625, 626, 627, 628, 630,
83308 /* 420 */ 634, 632, 633, 635, 641, 643, 661, 663, 647, 665,
83309 /* 430 */ 726, 727, 791, 720, 721, 725, 648, 802, 793, 797,
83310 /* 440 */ 798, 800, 801, 815, 816, 818, 824, 831, 834, 817,
83311 /* 450 */ 822, 823, 825, 830, 833, 723, 724, 837, 655, 656,
83312 /* 460 */ 659, 660, 871, 873, 872, 874, 658, 657, 803, 806,
83313 /* 470 */ 839, 840, 896, 897, 898, 899, 900, 835, 745, 838,
83314 /* 480 */ 821, 760, 763, 764, 761, 729, 739, 747, 748, 749,
83315 /* 490 */ 750, 734, 735, 741, 756, 789, 790, 754, 755, 742,
83316 /* 500 */ 743, 731, 732, 733, 836, 792, 804, 805, 666, 667,
83317 /* 510 */ 799, 668, 669, 670, 708, 711, 712, 713, 671, 690,
83318 /* 520 */ 693, 694, 672, 679, 673, 674, 681, 682, 683, 686,
83319 /* 530 */ 687, 688, 689, 684, 685, 855, 856, 859, 857, 676,
83320 /* 540 */ 677, 691, 664, 653, 646, 697, 700, 701, 702, 703,
83321 /* 550 */ 704, 706, 698, 699, 644, 636, 638, 746, 877, 886,
83322 /* 560 */ 882, 878, 879, 880, 639, 851, 852, 710, 783, 784,
83323 /* 570 */ 876, 889, 891, 788, 892, 894, 890, 919, 714, 715,
83324 /* 580 */ 718, 860, 901, 774, 777, 780, 782, 862, 863, 864,
83325 /* 590 */ 865, 866, 869, 870, 867, 902, 906, 909, 911, 912,
83326 /* 600 */ 913, 916, 918, 923, 924, 925, 928, 926, 617, 612,
83327 };
83328 #define YY_SZ_ACTTAB (int)(sizeof(yy_action)/sizeof(yy_action[0]))
83329
83330 /* The next table maps tokens into fallback tokens. If a construct
83331 ** like the following:
@@ -82294,67 +83339,70 @@
83339 */
83340 #ifdef YYFALLBACK
83341 static const YYCODETYPE yyFallback[] = {
83342 0, /* $ => nothing */
83343 0, /* SEMI => nothing */
83344 26, /* EXPLAIN => ID */
83345 26, /* QUERY => ID */
83346 26, /* PLAN => ID */
83347 26, /* BEGIN => ID */
83348 0, /* TRANSACTION => nothing */
83349 26, /* DEFERRED => ID */
83350 26, /* IMMEDIATE => ID */
83351 26, /* EXCLUSIVE => ID */
83352 0, /* COMMIT => nothing */
83353 26, /* END => ID */
83354 0, /* ROLLBACK => nothing */
83355 0, /* SAVEPOINT => nothing */
83356 0, /* RELEASE => nothing */
83357 0, /* TO => nothing */
83358 0, /* CREATE => nothing */
83359 0, /* TABLE => nothing */
83360 26, /* IF => ID */
83361 0, /* NOT => nothing */
83362 0, /* EXISTS => nothing */
83363 26, /* TEMP => ID */
83364 0, /* LP => nothing */
83365 0, /* RP => nothing */
83366 0, /* AS => nothing */
83367 0, /* COMMA => nothing */
83368 0, /* ID => nothing */
83369 26, /* ABORT => ID */
83370 26, /* AFTER => ID */
83371 26, /* ANALYZE => ID */
83372 26, /* ASC => ID */
83373 26, /* ATTACH => ID */
83374 26, /* BEFORE => ID */
83375 26, /* CASCADE => ID */
83376 26, /* CAST => ID */
83377 26, /* CONFLICT => ID */
83378 26, /* DATABASE => ID */
83379 26, /* DESC => ID */
83380 26, /* DETACH => ID */
83381 26, /* EACH => ID */
83382 26, /* FAIL => ID */
83383 26, /* FOR => ID */
83384 26, /* IGNORE => ID */
83385 26, /* INITIALLY => ID */
83386 26, /* INSTEAD => ID */
83387 26, /* LIKE_KW => ID */
83388 26, /* MATCH => ID */
83389 26, /* KEY => ID */
83390 26, /* OF => ID */
83391 26, /* OFFSET => ID */
83392 26, /* PRAGMA => ID */
83393 26, /* RAISE => ID */
83394 26, /* REPLACE => ID */
83395 26, /* RESTRICT => ID */
83396 26, /* ROW => ID */
83397 26, /* TRIGGER => ID */
83398 26, /* VACUUM => ID */
83399 26, /* VIEW => ID */
83400 26, /* VIRTUAL => ID */
83401 26, /* REINDEX => ID */
83402 26, /* RENAME => ID */
83403 26, /* CTIME_KW => ID */
83404 0, /* ANY => nothing */
83405 0, /* OR => nothing */
83406 0, /* AND => nothing */
83407 0, /* IS => nothing */
83408 0, /* BETWEEN => nothing */
@@ -82428,11 +83476,10 @@
83476 0, /* WHEN => nothing */
83477 0, /* THEN => nothing */
83478 0, /* ELSE => nothing */
83479 0, /* INDEX => nothing */
83480 0, /* ALTER => nothing */
 
83481 0, /* ADD => nothing */
83482 0, /* COLUMNKW => nothing */
83483 };
83484 #endif /* YYFALLBACK */
83485
@@ -82511,69 +83558,70 @@
83558 ** are required. The following table supplies these names */
83559 static const char *const yyTokenName[] = {
83560 "$", "SEMI", "EXPLAIN", "QUERY",
83561 "PLAN", "BEGIN", "TRANSACTION", "DEFERRED",
83562 "IMMEDIATE", "EXCLUSIVE", "COMMIT", "END",
83563 "ROLLBACK", "SAVEPOINT", "RELEASE", "TO",
83564 "CREATE", "TABLE", "IF", "NOT",
83565 "EXISTS", "TEMP", "LP", "RP",
83566 "AS", "COMMA", "ID", "ABORT",
83567 "AFTER", "ANALYZE", "ASC", "ATTACH",
83568 "BEFORE", "CASCADE", "CAST", "CONFLICT",
83569 "DATABASE", "DESC", "DETACH", "EACH",
83570 "FAIL", "FOR", "IGNORE", "INITIALLY",
83571 "INSTEAD", "LIKE_KW", "MATCH", "KEY",
83572 "OF", "OFFSET", "PRAGMA", "RAISE",
83573 "REPLACE", "RESTRICT", "ROW", "TRIGGER",
83574 "VACUUM", "VIEW", "VIRTUAL", "REINDEX",
83575 "RENAME", "CTIME_KW", "ANY", "OR",
83576 "AND", "IS", "BETWEEN", "IN",
83577 "ISNULL", "NOTNULL", "NE", "EQ",
83578 "GT", "LE", "LT", "GE",
83579 "ESCAPE", "BITAND", "BITOR", "LSHIFT",
83580 "RSHIFT", "PLUS", "MINUS", "STAR",
83581 "SLASH", "REM", "CONCAT", "COLLATE",
83582 "UMINUS", "UPLUS", "BITNOT", "STRING",
83583 "JOIN_KW", "CONSTRAINT", "DEFAULT", "NULL",
83584 "PRIMARY", "UNIQUE", "CHECK", "REFERENCES",
83585 "AUTOINCR", "ON", "DELETE", "UPDATE",
83586 "INSERT", "SET", "DEFERRABLE", "FOREIGN",
83587 "DROP", "UNION", "ALL", "EXCEPT",
83588 "INTERSECT", "SELECT", "DISTINCT", "DOT",
83589 "FROM", "JOIN", "INDEXED", "BY",
83590 "USING", "ORDER", "GROUP", "HAVING",
83591 "LIMIT", "WHERE", "INTO", "VALUES",
83592 "INTEGER", "FLOAT", "BLOB", "REGISTER",
83593 "VARIABLE", "CASE", "WHEN", "THEN",
83594 "ELSE", "INDEX", "ALTER", "ADD",
83595 "COLUMNKW", "error", "input", "cmdlist",
83596 "ecmd", "explain", "cmdx", "cmd",
83597 "transtype", "trans_opt", "nm", "savepoint_opt",
83598 "create_table", "create_table_args", "temp", "ifnotexists",
83599 "dbnm", "columnlist", "conslist_opt", "select",
83600 "column", "columnid", "type", "carglist",
83601 "id", "ids", "typetoken", "typename",
83602 "signed", "plus_num", "minus_num", "carg",
83603 "ccons", "term", "expr", "onconf",
83604 "sortorder", "autoinc", "idxlist_opt", "refargs",
83605 "defer_subclause", "refarg", "refact", "init_deferred_pred_opt",
83606 "conslist", "tcons", "idxlist", "defer_subclause_opt",
83607 "orconf", "resolvetype", "raisetype", "ifexists",
83608 "fullname", "oneselect", "multiselect_op", "distinct",
83609 "selcollist", "from", "where_opt", "groupby_opt",
83610 "having_opt", "orderby_opt", "limit_opt", "sclp",
83611 "as", "seltablist", "stl_prefix", "joinop",
83612 "indexed_opt", "on_opt", "using_opt", "joinop2",
83613 "inscollist", "sortlist", "sortitem", "nexprlist",
83614 "setlist", "insert_cmd", "inscollist_opt", "itemlist",
83615 "exprlist", "likeop", "escape", "between_op",
83616 "in_op", "case_operand", "case_exprlist", "case_else",
83617 "uniqueflag", "collate", "nmnum", "plus_opt",
83618 "number", "trigger_decl", "trigger_cmd_list", "trigger_time",
83619 "trigger_event", "foreach_clause", "when_clause", "trigger_cmd",
83620 "database_kw_opt", "key_opt", "add_column_fullname", "kwcolumn_opt",
83621 "create_vtab", "vtabarglist", "vtabarg", "vtabargtoken",
83622 "lp", "anylist",
83623 };
83624 #endif /* NDEBUG */
83625
83626 #ifndef NDEBUG
83627 /* For tracing reduce actions, the names of all rules are required.
@@ -82597,304 +83645,309 @@
83645 /* 15 */ "transtype ::= IMMEDIATE",
83646 /* 16 */ "transtype ::= EXCLUSIVE",
83647 /* 17 */ "cmd ::= COMMIT trans_opt",
83648 /* 18 */ "cmd ::= END trans_opt",
83649 /* 19 */ "cmd ::= ROLLBACK trans_opt",
83650 /* 20 */ "savepoint_opt ::= SAVEPOINT",
83651 /* 21 */ "savepoint_opt ::=",
83652 /* 22 */ "cmd ::= SAVEPOINT nm",
83653 /* 23 */ "cmd ::= RELEASE savepoint_opt nm",
83654 /* 24 */ "cmd ::= ROLLBACK trans_opt TO savepoint_opt nm",
83655 /* 25 */ "cmd ::= create_table create_table_args",
83656 /* 26 */ "create_table ::= CREATE temp TABLE ifnotexists nm dbnm",
83657 /* 27 */ "ifnotexists ::=",
83658 /* 28 */ "ifnotexists ::= IF NOT EXISTS",
83659 /* 29 */ "temp ::= TEMP",
83660 /* 30 */ "temp ::=",
83661 /* 31 */ "create_table_args ::= LP columnlist conslist_opt RP",
83662 /* 32 */ "create_table_args ::= AS select",
83663 /* 33 */ "columnlist ::= columnlist COMMA column",
83664 /* 34 */ "columnlist ::= column",
83665 /* 35 */ "column ::= columnid type carglist",
83666 /* 36 */ "columnid ::= nm",
83667 /* 37 */ "id ::= ID",
83668 /* 38 */ "ids ::= ID|STRING",
83669 /* 39 */ "nm ::= ID",
83670 /* 40 */ "nm ::= STRING",
83671 /* 41 */ "nm ::= JOIN_KW",
83672 /* 42 */ "type ::=",
83673 /* 43 */ "type ::= typetoken",
83674 /* 44 */ "typetoken ::= typename",
83675 /* 45 */ "typetoken ::= typename LP signed RP",
83676 /* 46 */ "typetoken ::= typename LP signed COMMA signed RP",
83677 /* 47 */ "typename ::= ids",
83678 /* 48 */ "typename ::= typename ids",
83679 /* 49 */ "signed ::= plus_num",
83680 /* 50 */ "signed ::= minus_num",
83681 /* 51 */ "carglist ::= carglist carg",
83682 /* 52 */ "carglist ::=",
83683 /* 53 */ "carg ::= CONSTRAINT nm ccons",
83684 /* 54 */ "carg ::= ccons",
83685 /* 55 */ "ccons ::= DEFAULT term",
83686 /* 56 */ "ccons ::= DEFAULT LP expr RP",
83687 /* 57 */ "ccons ::= DEFAULT PLUS term",
83688 /* 58 */ "ccons ::= DEFAULT MINUS term",
83689 /* 59 */ "ccons ::= DEFAULT id",
83690 /* 60 */ "ccons ::= NULL onconf",
83691 /* 61 */ "ccons ::= NOT NULL onconf",
83692 /* 62 */ "ccons ::= PRIMARY KEY sortorder onconf autoinc",
83693 /* 63 */ "ccons ::= UNIQUE onconf",
83694 /* 64 */ "ccons ::= CHECK LP expr RP",
83695 /* 65 */ "ccons ::= REFERENCES nm idxlist_opt refargs",
83696 /* 66 */ "ccons ::= defer_subclause",
83697 /* 67 */ "ccons ::= COLLATE ids",
83698 /* 68 */ "autoinc ::=",
83699 /* 69 */ "autoinc ::= AUTOINCR",
83700 /* 70 */ "refargs ::=",
83701 /* 71 */ "refargs ::= refargs refarg",
83702 /* 72 */ "refarg ::= MATCH nm",
83703 /* 73 */ "refarg ::= ON DELETE refact",
83704 /* 74 */ "refarg ::= ON UPDATE refact",
83705 /* 75 */ "refarg ::= ON INSERT refact",
83706 /* 76 */ "refact ::= SET NULL",
83707 /* 77 */ "refact ::= SET DEFAULT",
83708 /* 78 */ "refact ::= CASCADE",
83709 /* 79 */ "refact ::= RESTRICT",
83710 /* 80 */ "defer_subclause ::= NOT DEFERRABLE init_deferred_pred_opt",
83711 /* 81 */ "defer_subclause ::= DEFERRABLE init_deferred_pred_opt",
83712 /* 82 */ "init_deferred_pred_opt ::=",
83713 /* 83 */ "init_deferred_pred_opt ::= INITIALLY DEFERRED",
83714 /* 84 */ "init_deferred_pred_opt ::= INITIALLY IMMEDIATE",
83715 /* 85 */ "conslist_opt ::=",
83716 /* 86 */ "conslist_opt ::= COMMA conslist",
83717 /* 87 */ "conslist ::= conslist COMMA tcons",
83718 /* 88 */ "conslist ::= conslist tcons",
83719 /* 89 */ "conslist ::= tcons",
83720 /* 90 */ "tcons ::= CONSTRAINT nm",
83721 /* 91 */ "tcons ::= PRIMARY KEY LP idxlist autoinc RP onconf",
83722 /* 92 */ "tcons ::= UNIQUE LP idxlist RP onconf",
83723 /* 93 */ "tcons ::= CHECK LP expr RP onconf",
83724 /* 94 */ "tcons ::= FOREIGN KEY LP idxlist RP REFERENCES nm idxlist_opt refargs defer_subclause_opt",
83725 /* 95 */ "defer_subclause_opt ::=",
83726 /* 96 */ "defer_subclause_opt ::= defer_subclause",
83727 /* 97 */ "onconf ::=",
83728 /* 98 */ "onconf ::= ON CONFLICT resolvetype",
83729 /* 99 */ "orconf ::=",
83730 /* 100 */ "orconf ::= OR resolvetype",
83731 /* 101 */ "resolvetype ::= raisetype",
83732 /* 102 */ "resolvetype ::= IGNORE",
83733 /* 103 */ "resolvetype ::= REPLACE",
83734 /* 104 */ "cmd ::= DROP TABLE ifexists fullname",
83735 /* 105 */ "ifexists ::= IF EXISTS",
83736 /* 106 */ "ifexists ::=",
83737 /* 107 */ "cmd ::= CREATE temp VIEW ifnotexists nm dbnm AS select",
83738 /* 108 */ "cmd ::= DROP VIEW ifexists fullname",
83739 /* 109 */ "cmd ::= select",
83740 /* 110 */ "select ::= oneselect",
83741 /* 111 */ "select ::= select multiselect_op oneselect",
83742 /* 112 */ "multiselect_op ::= UNION",
83743 /* 113 */ "multiselect_op ::= UNION ALL",
83744 /* 114 */ "multiselect_op ::= EXCEPT|INTERSECT",
83745 /* 115 */ "oneselect ::= SELECT distinct selcollist from where_opt groupby_opt having_opt orderby_opt limit_opt",
83746 /* 116 */ "distinct ::= DISTINCT",
83747 /* 117 */ "distinct ::= ALL",
83748 /* 118 */ "distinct ::=",
83749 /* 119 */ "sclp ::= selcollist COMMA",
83750 /* 120 */ "sclp ::=",
83751 /* 121 */ "selcollist ::= sclp expr as",
83752 /* 122 */ "selcollist ::= sclp STAR",
83753 /* 123 */ "selcollist ::= sclp nm DOT STAR",
83754 /* 124 */ "as ::= AS nm",
83755 /* 125 */ "as ::= ids",
83756 /* 126 */ "as ::=",
83757 /* 127 */ "from ::=",
83758 /* 128 */ "from ::= FROM seltablist",
83759 /* 129 */ "stl_prefix ::= seltablist joinop",
83760 /* 130 */ "stl_prefix ::=",
83761 /* 131 */ "seltablist ::= stl_prefix nm dbnm as indexed_opt on_opt using_opt",
83762 /* 132 */ "seltablist ::= stl_prefix LP select RP as on_opt using_opt",
83763 /* 133 */ "seltablist ::= stl_prefix LP seltablist RP as on_opt using_opt",
83764 /* 134 */ "dbnm ::=",
83765 /* 135 */ "dbnm ::= DOT nm",
83766 /* 136 */ "fullname ::= nm dbnm",
83767 /* 137 */ "joinop ::= COMMA|JOIN",
83768 /* 138 */ "joinop ::= JOIN_KW JOIN",
83769 /* 139 */ "joinop ::= JOIN_KW nm JOIN",
83770 /* 140 */ "joinop ::= JOIN_KW nm nm JOIN",
83771 /* 141 */ "on_opt ::= ON expr",
83772 /* 142 */ "on_opt ::=",
83773 /* 143 */ "indexed_opt ::=",
83774 /* 144 */ "indexed_opt ::= INDEXED BY nm",
83775 /* 145 */ "indexed_opt ::= NOT INDEXED",
83776 /* 146 */ "using_opt ::= USING LP inscollist RP",
83777 /* 147 */ "using_opt ::=",
83778 /* 148 */ "orderby_opt ::=",
83779 /* 149 */ "orderby_opt ::= ORDER BY sortlist",
83780 /* 150 */ "sortlist ::= sortlist COMMA sortitem sortorder",
83781 /* 151 */ "sortlist ::= sortitem sortorder",
83782 /* 152 */ "sortitem ::= expr",
83783 /* 153 */ "sortorder ::= ASC",
83784 /* 154 */ "sortorder ::= DESC",
83785 /* 155 */ "sortorder ::=",
83786 /* 156 */ "groupby_opt ::=",
83787 /* 157 */ "groupby_opt ::= GROUP BY nexprlist",
83788 /* 158 */ "having_opt ::=",
83789 /* 159 */ "having_opt ::= HAVING expr",
83790 /* 160 */ "limit_opt ::=",
83791 /* 161 */ "limit_opt ::= LIMIT expr",
83792 /* 162 */ "limit_opt ::= LIMIT expr OFFSET expr",
83793 /* 163 */ "limit_opt ::= LIMIT expr COMMA expr",
83794 /* 164 */ "cmd ::= DELETE FROM fullname indexed_opt where_opt",
83795 /* 165 */ "where_opt ::=",
83796 /* 166 */ "where_opt ::= WHERE expr",
83797 /* 167 */ "cmd ::= UPDATE orconf fullname indexed_opt SET setlist where_opt",
83798 /* 168 */ "setlist ::= setlist COMMA nm EQ expr",
83799 /* 169 */ "setlist ::= nm EQ expr",
83800 /* 170 */ "cmd ::= insert_cmd INTO fullname inscollist_opt VALUES LP itemlist RP",
83801 /* 171 */ "cmd ::= insert_cmd INTO fullname inscollist_opt select",
83802 /* 172 */ "cmd ::= insert_cmd INTO fullname inscollist_opt DEFAULT VALUES",
83803 /* 173 */ "insert_cmd ::= INSERT orconf",
83804 /* 174 */ "insert_cmd ::= REPLACE",
83805 /* 175 */ "itemlist ::= itemlist COMMA expr",
83806 /* 176 */ "itemlist ::= expr",
83807 /* 177 */ "inscollist_opt ::=",
83808 /* 178 */ "inscollist_opt ::= LP inscollist RP",
83809 /* 179 */ "inscollist ::= inscollist COMMA nm",
83810 /* 180 */ "inscollist ::= nm",
83811 /* 181 */ "expr ::= term",
83812 /* 182 */ "expr ::= LP expr RP",
83813 /* 183 */ "term ::= NULL",
83814 /* 184 */ "expr ::= ID",
83815 /* 185 */ "expr ::= JOIN_KW",
83816 /* 186 */ "expr ::= nm DOT nm",
83817 /* 187 */ "expr ::= nm DOT nm DOT nm",
83818 /* 188 */ "term ::= INTEGER|FLOAT|BLOB",
83819 /* 189 */ "term ::= STRING",
83820 /* 190 */ "expr ::= REGISTER",
83821 /* 191 */ "expr ::= VARIABLE",
83822 /* 192 */ "expr ::= expr COLLATE ids",
83823 /* 193 */ "expr ::= CAST LP expr AS typetoken RP",
83824 /* 194 */ "expr ::= ID LP distinct exprlist RP",
83825 /* 195 */ "expr ::= ID LP STAR RP",
83826 /* 196 */ "term ::= CTIME_KW",
83827 /* 197 */ "expr ::= expr AND expr",
83828 /* 198 */ "expr ::= expr OR expr",
83829 /* 199 */ "expr ::= expr LT|GT|GE|LE expr",
83830 /* 200 */ "expr ::= expr EQ|NE expr",
83831 /* 201 */ "expr ::= expr BITAND|BITOR|LSHIFT|RSHIFT expr",
83832 /* 202 */ "expr ::= expr PLUS|MINUS expr",
83833 /* 203 */ "expr ::= expr STAR|SLASH|REM expr",
83834 /* 204 */ "expr ::= expr CONCAT expr",
83835 /* 205 */ "likeop ::= LIKE_KW",
83836 /* 206 */ "likeop ::= NOT LIKE_KW",
83837 /* 207 */ "likeop ::= MATCH",
83838 /* 208 */ "likeop ::= NOT MATCH",
83839 /* 209 */ "escape ::= ESCAPE expr",
83840 /* 210 */ "escape ::=",
83841 /* 211 */ "expr ::= expr likeop expr escape",
83842 /* 212 */ "expr ::= expr ISNULL|NOTNULL",
83843 /* 213 */ "expr ::= expr IS NULL",
83844 /* 214 */ "expr ::= expr NOT NULL",
83845 /* 215 */ "expr ::= expr IS NOT NULL",
83846 /* 216 */ "expr ::= NOT expr",
83847 /* 217 */ "expr ::= BITNOT expr",
83848 /* 218 */ "expr ::= MINUS expr",
83849 /* 219 */ "expr ::= PLUS expr",
83850 /* 220 */ "between_op ::= BETWEEN",
83851 /* 221 */ "between_op ::= NOT BETWEEN",
83852 /* 222 */ "expr ::= expr between_op expr AND expr",
83853 /* 223 */ "in_op ::= IN",
83854 /* 224 */ "in_op ::= NOT IN",
83855 /* 225 */ "expr ::= expr in_op LP exprlist RP",
83856 /* 226 */ "expr ::= LP select RP",
83857 /* 227 */ "expr ::= expr in_op LP select RP",
83858 /* 228 */ "expr ::= expr in_op nm dbnm",
83859 /* 229 */ "expr ::= EXISTS LP select RP",
83860 /* 230 */ "expr ::= CASE case_operand case_exprlist case_else END",
83861 /* 231 */ "case_exprlist ::= case_exprlist WHEN expr THEN expr",
83862 /* 232 */ "case_exprlist ::= WHEN expr THEN expr",
83863 /* 233 */ "case_else ::= ELSE expr",
83864 /* 234 */ "case_else ::=",
83865 /* 235 */ "case_operand ::= expr",
83866 /* 236 */ "case_operand ::=",
83867 /* 237 */ "exprlist ::= nexprlist",
83868 /* 238 */ "exprlist ::=",
83869 /* 239 */ "nexprlist ::= nexprlist COMMA expr",
83870 /* 240 */ "nexprlist ::= expr",
83871 /* 241 */ "cmd ::= CREATE uniqueflag INDEX ifnotexists nm dbnm ON nm LP idxlist RP",
83872 /* 242 */ "uniqueflag ::= UNIQUE",
83873 /* 243 */ "uniqueflag ::=",
83874 /* 244 */ "idxlist_opt ::=",
83875 /* 245 */ "idxlist_opt ::= LP idxlist RP",
83876 /* 246 */ "idxlist ::= idxlist COMMA nm collate sortorder",
83877 /* 247 */ "idxlist ::= nm collate sortorder",
83878 /* 248 */ "collate ::=",
83879 /* 249 */ "collate ::= COLLATE ids",
83880 /* 250 */ "cmd ::= DROP INDEX ifexists fullname",
83881 /* 251 */ "cmd ::= VACUUM",
83882 /* 252 */ "cmd ::= VACUUM nm",
83883 /* 253 */ "cmd ::= PRAGMA nm dbnm EQ nmnum",
83884 /* 254 */ "cmd ::= PRAGMA nm dbnm EQ ON",
83885 /* 255 */ "cmd ::= PRAGMA nm dbnm EQ DELETE",
83886 /* 256 */ "cmd ::= PRAGMA nm dbnm EQ minus_num",
83887 /* 257 */ "cmd ::= PRAGMA nm dbnm LP nmnum RP",
83888 /* 258 */ "cmd ::= PRAGMA nm dbnm",
83889 /* 259 */ "nmnum ::= plus_num",
83890 /* 260 */ "nmnum ::= nm",
83891 /* 261 */ "plus_num ::= plus_opt number",
83892 /* 262 */ "minus_num ::= MINUS number",
83893 /* 263 */ "number ::= INTEGER|FLOAT",
83894 /* 264 */ "plus_opt ::= PLUS",
83895 /* 265 */ "plus_opt ::=",
83896 /* 266 */ "cmd ::= CREATE trigger_decl BEGIN trigger_cmd_list END",
83897 /* 267 */ "trigger_decl ::= temp TRIGGER ifnotexists nm dbnm trigger_time trigger_event ON fullname foreach_clause when_clause",
83898 /* 268 */ "trigger_time ::= BEFORE",
83899 /* 269 */ "trigger_time ::= AFTER",
83900 /* 270 */ "trigger_time ::= INSTEAD OF",
83901 /* 271 */ "trigger_time ::=",
83902 /* 272 */ "trigger_event ::= DELETE|INSERT",
83903 /* 273 */ "trigger_event ::= UPDATE",
83904 /* 274 */ "trigger_event ::= UPDATE OF inscollist",
83905 /* 275 */ "foreach_clause ::=",
83906 /* 276 */ "foreach_clause ::= FOR EACH ROW",
83907 /* 277 */ "when_clause ::=",
83908 /* 278 */ "when_clause ::= WHEN expr",
83909 /* 279 */ "trigger_cmd_list ::= trigger_cmd_list trigger_cmd SEMI",
83910 /* 280 */ "trigger_cmd_list ::= trigger_cmd SEMI",
83911 /* 281 */ "trigger_cmd ::= UPDATE orconf nm SET setlist where_opt",
83912 /* 282 */ "trigger_cmd ::= insert_cmd INTO nm inscollist_opt VALUES LP itemlist RP",
83913 /* 283 */ "trigger_cmd ::= insert_cmd INTO nm inscollist_opt select",
83914 /* 284 */ "trigger_cmd ::= DELETE FROM nm where_opt",
83915 /* 285 */ "trigger_cmd ::= select",
83916 /* 286 */ "expr ::= RAISE LP IGNORE RP",
83917 /* 287 */ "expr ::= RAISE LP raisetype COMMA nm RP",
83918 /* 288 */ "raisetype ::= ROLLBACK",
83919 /* 289 */ "raisetype ::= ABORT",
83920 /* 290 */ "raisetype ::= FAIL",
83921 /* 291 */ "cmd ::= DROP TRIGGER ifexists fullname",
83922 /* 292 */ "cmd ::= ATTACH database_kw_opt expr AS expr key_opt",
83923 /* 293 */ "cmd ::= DETACH database_kw_opt expr",
83924 /* 294 */ "key_opt ::=",
83925 /* 295 */ "key_opt ::= KEY expr",
83926 /* 296 */ "database_kw_opt ::= DATABASE",
83927 /* 297 */ "database_kw_opt ::=",
83928 /* 298 */ "cmd ::= REINDEX",
83929 /* 299 */ "cmd ::= REINDEX nm dbnm",
83930 /* 300 */ "cmd ::= ANALYZE",
83931 /* 301 */ "cmd ::= ANALYZE nm dbnm",
83932 /* 302 */ "cmd ::= ALTER TABLE fullname RENAME TO nm",
83933 /* 303 */ "cmd ::= ALTER TABLE add_column_fullname ADD kwcolumn_opt column",
83934 /* 304 */ "add_column_fullname ::= fullname",
83935 /* 305 */ "kwcolumn_opt ::=",
83936 /* 306 */ "kwcolumn_opt ::= COLUMNKW",
83937 /* 307 */ "cmd ::= create_vtab",
83938 /* 308 */ "cmd ::= create_vtab LP vtabarglist RP",
83939 /* 309 */ "create_vtab ::= CREATE VIRTUAL TABLE nm dbnm USING nm",
83940 /* 310 */ "vtabarglist ::= vtabarg",
83941 /* 311 */ "vtabarglist ::= vtabarglist COMMA vtabarg",
83942 /* 312 */ "vtabarg ::=",
83943 /* 313 */ "vtabarg ::= vtabarg vtabargtoken",
83944 /* 314 */ "vtabargtoken ::= ANY",
83945 /* 315 */ "vtabargtoken ::= lp anylist RP",
83946 /* 316 */ "lp ::= LP",
83947 /* 317 */ "anylist ::=",
83948 /* 318 */ "anylist ::= anylist ANY",
83949 };
83950 #endif /* NDEBUG */
83951
83952
83953 #if YYSTACKDEPTH<=0
@@ -82969,71 +84022,71 @@
84022 **
84023 ** Note: during a reduce, the only symbols destroyed are those
84024 ** which appear on the RHS of the rule, but which are not used
84025 ** inside the C code.
84026 */
84027 case 159: /* select */
84028 case 193: /* oneselect */
84029 {
84030 sqlite3SelectDelete(pParse->db, (yypminor->yy159));
84031 }
84032 break;
84033 case 173: /* term */
84034 case 174: /* expr */
84035 case 198: /* where_opt */
84036 case 200: /* having_opt */
84037 case 209: /* on_opt */
84038 case 214: /* sortitem */
84039 case 222: /* escape */
84040 case 225: /* case_operand */
84041 case 227: /* case_else */
84042 case 238: /* when_clause */
84043 case 241: /* key_opt */
84044 {
84045 sqlite3ExprDelete(pParse->db, (yypminor->yy122));
84046 }
84047 break;
84048 case 178: /* idxlist_opt */
84049 case 186: /* idxlist */
84050 case 196: /* selcollist */
84051 case 199: /* groupby_opt */
84052 case 201: /* orderby_opt */
84053 case 203: /* sclp */
84054 case 213: /* sortlist */
84055 case 215: /* nexprlist */
84056 case 216: /* setlist */
84057 case 219: /* itemlist */
84058 case 220: /* exprlist */
84059 case 226: /* case_exprlist */
84060 {
84061 sqlite3ExprListDelete(pParse->db, (yypminor->yy442));
84062 }
84063 break;
84064 case 192: /* fullname */
84065 case 197: /* from */
84066 case 205: /* seltablist */
84067 case 206: /* stl_prefix */
84068 {
84069 sqlite3SrcListDelete(pParse->db, (yypminor->yy347));
84070 }
84071 break;
84072 case 210: /* using_opt */
84073 case 212: /* inscollist */
84074 case 218: /* inscollist_opt */
84075 {
84076 sqlite3IdListDelete(pParse->db, (yypminor->yy180));
84077 }
84078 break;
84079 case 234: /* trigger_cmd_list */
84080 case 239: /* trigger_cmd */
84081 {
84082 sqlite3DeleteTriggerStep(pParse->db, (yypminor->yy327));
84083 }
84084 break;
84085 case 236: /* trigger_event */
84086 {
84087 sqlite3IdListDelete(pParse->db, (yypminor->yy410).b);
84088 }
84089 break;
84090 default: break; /* If no destructor action specified: do nothing */
84091 }
84092 }
@@ -83262,324 +84315,329 @@
84315 */
84316 static const struct {
84317 YYCODETYPE lhs; /* Symbol on the left-hand side of the rule */
84318 unsigned char nrhs; /* Number of right-hand side symbols in the rule */
84319 } yyRuleInfo[] = {
84320 { 142, 1 },
84321 { 143, 2 },
84322 { 143, 1 },
84323 { 144, 1 },
84324 { 144, 3 },
84325 { 145, 0 },
84326 { 145, 1 },
84327 { 145, 3 },
84328 { 146, 1 },
84329 { 147, 3 },
84330 { 149, 0 },
84331 { 149, 1 },
84332 { 149, 2 },
84333 { 148, 0 },
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
84334 { 148, 1 },
84335 { 148, 1 },
84336 { 148, 1 },
84337 { 147, 2 },
84338 { 147, 2 },
84339 { 147, 2 },
84340 { 151, 1 },
84341 { 151, 0 },
84342 { 147, 2 },
84343 { 147, 3 },
84344 { 147, 5 },
84345 { 147, 2 },
84346 { 152, 6 },
84347 { 155, 0 },
84348 { 155, 3 },
84349 { 154, 1 },
84350 { 154, 0 },
84351 { 153, 4 },
84352 { 153, 2 },
84353 { 157, 3 },
84354 { 157, 1 },
84355 { 160, 3 },
84356 { 161, 1 },
84357 { 164, 1 },
84358 { 165, 1 },
84359 { 150, 1 },
84360 { 150, 1 },
84361 { 150, 1 },
84362 { 162, 0 },
84363 { 162, 1 },
84364 { 166, 1 },
84365 { 166, 4 },
84366 { 166, 6 },
84367 { 167, 1 },
84368 { 167, 2 },
84369 { 168, 1 },
84370 { 168, 1 },
84371 { 163, 2 },
84372 { 163, 0 },
84373 { 171, 3 },
84374 { 171, 1 },
84375 { 172, 2 },
84376 { 172, 4 },
84377 { 172, 3 },
84378 { 172, 3 },
84379 { 172, 2 },
84380 { 172, 2 },
84381 { 172, 3 },
84382 { 172, 5 },
84383 { 172, 2 },
84384 { 172, 4 },
84385 { 172, 4 },
84386 { 172, 1 },
84387 { 172, 2 },
84388 { 177, 0 },
84389 { 177, 1 },
84390 { 179, 0 },
84391 { 179, 2 },
84392 { 181, 2 },
84393 { 181, 3 },
84394 { 181, 3 },
84395 { 181, 3 },
84396 { 182, 2 },
84397 { 182, 2 },
84398 { 182, 1 },
84399 { 182, 1 },
84400 { 180, 3 },
84401 { 180, 2 },
84402 { 183, 0 },
84403 { 183, 2 },
84404 { 183, 2 },
84405 { 158, 0 },
84406 { 158, 2 },
84407 { 184, 3 },
84408 { 184, 2 },
84409 { 184, 1 },
 
 
 
84410 { 185, 2 },
84411 { 185, 7 },
84412 { 185, 5 },
84413 { 185, 5 },
84414 { 185, 10 },
84415 { 187, 0 },
84416 { 187, 1 },
84417 { 175, 0 },
84418 { 175, 3 },
84419 { 188, 0 },
84420 { 188, 2 },
84421 { 189, 1 },
84422 { 189, 1 },
84423 { 189, 1 },
84424 { 147, 4 },
 
84425 { 191, 2 },
84426 { 191, 0 },
84427 { 147, 8 },
84428 { 147, 4 },
84429 { 147, 1 },
84430 { 159, 1 },
84431 { 159, 3 },
84432 { 194, 1 },
 
 
 
 
 
 
 
84433 { 194, 2 },
84434 { 194, 1 },
84435 { 193, 9 },
84436 { 195, 1 },
84437 { 195, 1 },
84438 { 195, 0 },
84439 { 203, 2 },
84440 { 203, 0 },
84441 { 196, 3 },
84442 { 196, 2 },
84443 { 196, 4 },
84444 { 204, 2 },
 
 
84445 { 204, 1 },
84446 { 204, 0 },
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
84447 { 197, 0 },
84448 { 197, 2 },
84449 { 206, 2 },
84450 { 206, 0 },
84451 { 205, 7 },
84452 { 205, 7 },
84453 { 205, 7 },
84454 { 156, 0 },
84455 { 156, 2 },
84456 { 192, 2 },
84457 { 207, 1 },
84458 { 207, 2 },
84459 { 207, 3 },
84460 { 207, 4 },
84461 { 209, 2 },
84462 { 209, 0 },
84463 { 208, 0 },
84464 { 208, 3 },
84465 { 208, 2 },
84466 { 210, 4 },
84467 { 210, 0 },
84468 { 201, 0 },
84469 { 201, 3 },
84470 { 213, 4 },
84471 { 213, 2 },
84472 { 214, 1 },
84473 { 176, 1 },
84474 { 176, 1 },
84475 { 176, 0 },
84476 { 199, 0 },
84477 { 199, 3 },
84478 { 200, 0 },
84479 { 200, 2 },
84480 { 202, 0 },
84481 { 202, 2 },
84482 { 202, 4 },
84483 { 202, 4 },
84484 { 147, 5 },
84485 { 198, 0 },
84486 { 198, 2 },
84487 { 147, 7 },
84488 { 216, 5 },
84489 { 216, 3 },
84490 { 147, 8 },
84491 { 147, 5 },
84492 { 147, 6 },
84493 { 217, 2 },
84494 { 217, 1 },
84495 { 219, 3 },
84496 { 219, 1 },
84497 { 218, 0 },
84498 { 218, 3 },
84499 { 212, 3 },
84500 { 212, 1 },
84501 { 174, 1 },
84502 { 174, 3 },
84503 { 173, 1 },
84504 { 174, 1 },
84505 { 174, 1 },
84506 { 174, 3 },
84507 { 174, 5 },
84508 { 173, 1 },
84509 { 173, 1 },
84510 { 174, 1 },
84511 { 174, 1 },
84512 { 174, 3 },
84513 { 174, 6 },
84514 { 174, 5 },
84515 { 174, 4 },
84516 { 173, 1 },
84517 { 174, 3 },
84518 { 174, 3 },
84519 { 174, 3 },
84520 { 174, 3 },
84521 { 174, 3 },
84522 { 174, 3 },
84523 { 174, 3 },
84524 { 174, 3 },
84525 { 221, 1 },
84526 { 221, 2 },
 
 
 
 
 
 
 
 
 
 
84527 { 221, 1 },
84528 { 221, 2 },
84529 { 222, 2 },
84530 { 222, 0 },
84531 { 174, 4 },
84532 { 174, 2 },
84533 { 174, 3 },
84534 { 174, 3 },
84535 { 174, 4 },
84536 { 174, 2 },
84537 { 174, 2 },
84538 { 174, 2 },
84539 { 174, 2 },
84540 { 223, 1 },
84541 { 223, 2 },
84542 { 174, 5 },
84543 { 224, 1 },
84544 { 224, 2 },
84545 { 174, 5 },
84546 { 174, 3 },
84547 { 174, 5 },
84548 { 174, 4 },
84549 { 174, 4 },
84550 { 174, 5 },
84551 { 226, 5 },
84552 { 226, 4 },
84553 { 227, 2 },
84554 { 227, 0 },
84555 { 225, 1 },
84556 { 225, 0 },
84557 { 220, 1 },
84558 { 220, 0 },
84559 { 215, 3 },
84560 { 215, 1 },
84561 { 147, 11 },
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
84562 { 228, 1 },
84563 { 228, 0 },
84564 { 178, 0 },
84565 { 178, 3 },
84566 { 186, 5 },
84567 { 186, 3 },
84568 { 229, 0 },
84569 { 229, 2 },
84570 { 147, 4 },
84571 { 147, 1 },
84572 { 147, 2 },
84573 { 147, 5 },
84574 { 147, 5 },
84575 { 147, 5 },
84576 { 147, 5 },
84577 { 147, 6 },
84578 { 147, 3 },
84579 { 230, 1 },
84580 { 230, 1 },
84581 { 169, 2 },
84582 { 170, 2 },
84583 { 232, 1 },
84584 { 231, 1 },
84585 { 231, 0 },
84586 { 147, 5 },
84587 { 233, 11 },
84588 { 235, 1 },
84589 { 235, 1 },
84590 { 235, 2 },
84591 { 235, 0 },
84592 { 236, 1 },
 
 
 
 
84593 { 236, 1 },
84594 { 236, 3 },
84595 { 237, 0 },
84596 { 237, 3 },
 
 
 
 
 
84597 { 238, 0 },
84598 { 238, 2 },
84599 { 234, 3 },
84600 { 234, 2 },
84601 { 239, 6 },
84602 { 239, 8 },
84603 { 239, 5 },
84604 { 239, 4 },
 
 
84605 { 239, 1 },
84606 { 174, 4 },
84607 { 174, 6 },
84608 { 190, 1 },
84609 { 190, 1 },
84610 { 190, 1 },
84611 { 147, 4 },
84612 { 147, 6 },
84613 { 147, 3 },
84614 { 241, 0 },
84615 { 241, 2 },
84616 { 240, 1 },
84617 { 240, 0 },
84618 { 147, 1 },
84619 { 147, 3 },
84620 { 147, 1 },
84621 { 147, 3 },
84622 { 147, 6 },
84623 { 147, 6 },
84624 { 242, 1 },
 
84625 { 243, 0 },
84626 { 243, 1 },
84627 { 147, 1 },
84628 { 147, 4 },
84629 { 244, 7 },
84630 { 245, 1 },
84631 { 245, 3 },
84632 { 246, 0 },
84633 { 246, 2 },
84634 { 247, 1 },
84635 { 247, 3 },
84636 { 248, 1 },
84637 { 249, 0 },
84638 { 249, 2 },
84639 };
84640
84641 static void yy_accept(yyParser*); /* Forward Declaration */
84642
84643 /*
@@ -83638,37 +84696,39 @@
84696 case 3: /* ecmd ::= SEMI */
84697 case 4: /* ecmd ::= explain cmdx SEMI */
84698 case 10: /* trans_opt ::= */
84699 case 11: /* trans_opt ::= TRANSACTION */
84700 case 12: /* trans_opt ::= TRANSACTION nm */
84701 case 20: /* savepoint_opt ::= SAVEPOINT */
84702 case 21: /* savepoint_opt ::= */
84703 case 25: /* cmd ::= create_table create_table_args */
84704 case 33: /* columnlist ::= columnlist COMMA column */
84705 case 34: /* columnlist ::= column */
84706 case 42: /* type ::= */
84707 case 49: /* signed ::= plus_num */
84708 case 50: /* signed ::= minus_num */
84709 case 51: /* carglist ::= carglist carg */
84710 case 52: /* carglist ::= */
84711 case 53: /* carg ::= CONSTRAINT nm ccons */
84712 case 54: /* carg ::= ccons */
84713 case 60: /* ccons ::= NULL onconf */
84714 case 87: /* conslist ::= conslist COMMA tcons */
84715 case 88: /* conslist ::= conslist tcons */
84716 case 89: /* conslist ::= tcons */
84717 case 90: /* tcons ::= CONSTRAINT nm */
84718 case 264: /* plus_opt ::= PLUS */
84719 case 265: /* plus_opt ::= */
84720 case 275: /* foreach_clause ::= */
84721 case 276: /* foreach_clause ::= FOR EACH ROW */
84722 case 296: /* database_kw_opt ::= DATABASE */
84723 case 297: /* database_kw_opt ::= */
84724 case 305: /* kwcolumn_opt ::= */
84725 case 306: /* kwcolumn_opt ::= COLUMNKW */
84726 case 310: /* vtabarglist ::= vtabarg */
84727 case 311: /* vtabarglist ::= vtabarglist COMMA vtabarg */
84728 case 313: /* vtabarg ::= vtabarg vtabargtoken */
84729 case 317: /* anylist ::= */
84730 {
84731 }
84732 break;
84733 case 5: /* explain ::= */
84734 { sqlite3BeginParse(pParse, 0); }
@@ -83681,953 +84741,968 @@
84741 break;
84742 case 8: /* cmdx ::= cmd */
84743 { sqlite3FinishCoding(pParse); }
84744 break;
84745 case 9: /* cmd ::= BEGIN transtype trans_opt */
84746 {sqlite3BeginTransaction(pParse, yymsp[-1].minor.yy392);}
84747 break;
84748 case 13: /* transtype ::= */
84749 {yygotominor.yy392 = TK_DEFERRED;}
84750 break;
84751 case 14: /* transtype ::= DEFERRED */
84752 case 15: /* transtype ::= IMMEDIATE */
84753 case 16: /* transtype ::= EXCLUSIVE */
84754 case 112: /* multiselect_op ::= UNION */
84755 case 114: /* multiselect_op ::= EXCEPT|INTERSECT */
84756 {yygotominor.yy392 = yymsp[0].major;}
84757 break;
84758 case 17: /* cmd ::= COMMIT trans_opt */
84759 case 18: /* cmd ::= END trans_opt */
84760 {sqlite3CommitTransaction(pParse);}
84761 break;
84762 case 19: /* cmd ::= ROLLBACK trans_opt */
84763 {sqlite3RollbackTransaction(pParse);}
84764 break;
84765 case 22: /* cmd ::= SAVEPOINT nm */
84766 {
84767 sqlite3Savepoint(pParse, SAVEPOINT_BEGIN, &yymsp[0].minor.yy0);
84768 }
84769 break;
84770 case 23: /* cmd ::= RELEASE savepoint_opt nm */
84771 {
84772 sqlite3Savepoint(pParse, SAVEPOINT_RELEASE, &yymsp[0].minor.yy0);
84773 }
84774 break;
84775 case 24: /* cmd ::= ROLLBACK trans_opt TO savepoint_opt nm */
84776 {
84777 sqlite3Savepoint(pParse, SAVEPOINT_ROLLBACK, &yymsp[0].minor.yy0);
84778 }
84779 break;
84780 case 26: /* create_table ::= CREATE temp TABLE ifnotexists nm dbnm */
84781 {
84782 sqlite3StartTable(pParse,&yymsp[-1].minor.yy0,&yymsp[0].minor.yy0,yymsp[-4].minor.yy392,0,0,yymsp[-2].minor.yy392);
84783 }
84784 break;
84785 case 27: /* ifnotexists ::= */
84786 case 30: /* temp ::= */
84787 case 68: /* autoinc ::= */
84788 case 82: /* init_deferred_pred_opt ::= */
84789 case 84: /* init_deferred_pred_opt ::= INITIALLY IMMEDIATE */
84790 case 95: /* defer_subclause_opt ::= */
84791 case 106: /* ifexists ::= */
84792 case 117: /* distinct ::= ALL */
84793 case 118: /* distinct ::= */
84794 case 220: /* between_op ::= BETWEEN */
84795 case 223: /* in_op ::= IN */
84796 {yygotominor.yy392 = 0;}
84797 break;
84798 case 28: /* ifnotexists ::= IF NOT EXISTS */
84799 case 29: /* temp ::= TEMP */
84800 case 69: /* autoinc ::= AUTOINCR */
84801 case 83: /* init_deferred_pred_opt ::= INITIALLY DEFERRED */
84802 case 105: /* ifexists ::= IF EXISTS */
84803 case 116: /* distinct ::= DISTINCT */
84804 case 221: /* between_op ::= NOT BETWEEN */
84805 case 224: /* in_op ::= NOT IN */
84806 {yygotominor.yy392 = 1;}
84807 break;
84808 case 31: /* create_table_args ::= LP columnlist conslist_opt RP */
84809 {
84810 sqlite3EndTable(pParse,&yymsp[-1].minor.yy0,&yymsp[0].minor.yy0,0);
84811 }
84812 break;
84813 case 32: /* create_table_args ::= AS select */
84814 {
84815 sqlite3EndTable(pParse,0,0,yymsp[0].minor.yy159);
84816 sqlite3SelectDelete(pParse->db, yymsp[0].minor.yy159);
84817 }
84818 break;
84819 case 35: /* column ::= columnid type carglist */
84820 {
84821 yygotominor.yy0.z = yymsp[-2].minor.yy0.z;
84822 yygotominor.yy0.n = (int)(pParse->sLastToken.z-yymsp[-2].minor.yy0.z) + pParse->sLastToken.n;
84823 }
84824 break;
84825 case 36: /* columnid ::= nm */
84826 {
84827 sqlite3AddColumn(pParse,&yymsp[0].minor.yy0);
84828 yygotominor.yy0 = yymsp[0].minor.yy0;
84829 }
84830 break;
84831 case 37: /* id ::= ID */
84832 case 38: /* ids ::= ID|STRING */
84833 case 39: /* nm ::= ID */
84834 case 40: /* nm ::= STRING */
84835 case 41: /* nm ::= JOIN_KW */
84836 case 44: /* typetoken ::= typename */
84837 case 47: /* typename ::= ids */
84838 case 124: /* as ::= AS nm */
84839 case 125: /* as ::= ids */
84840 case 135: /* dbnm ::= DOT nm */
84841 case 144: /* indexed_opt ::= INDEXED BY nm */
84842 case 249: /* collate ::= COLLATE ids */
84843 case 259: /* nmnum ::= plus_num */
84844 case 260: /* nmnum ::= nm */
84845 case 261: /* plus_num ::= plus_opt number */
84846 case 262: /* minus_num ::= MINUS number */
84847 case 263: /* number ::= INTEGER|FLOAT */
84848 {yygotominor.yy0 = yymsp[0].minor.yy0;}
84849 break;
84850 case 43: /* type ::= typetoken */
84851 {sqlite3AddColumnType(pParse,&yymsp[0].minor.yy0);}
84852 break;
84853 case 45: /* typetoken ::= typename LP signed RP */
84854 {
84855 yygotominor.yy0.z = yymsp[-3].minor.yy0.z;
84856 yygotominor.yy0.n = (int)(&yymsp[0].minor.yy0.z[yymsp[0].minor.yy0.n] - yymsp[-3].minor.yy0.z);
84857 }
84858 break;
84859 case 46: /* typetoken ::= typename LP signed COMMA signed RP */
84860 {
84861 yygotominor.yy0.z = yymsp[-5].minor.yy0.z;
84862 yygotominor.yy0.n = (int)(&yymsp[0].minor.yy0.z[yymsp[0].minor.yy0.n] - yymsp[-5].minor.yy0.z);
84863 }
84864 break;
84865 case 48: /* typename ::= typename ids */
84866 {yygotominor.yy0.z=yymsp[-1].minor.yy0.z; yygotominor.yy0.n=yymsp[0].minor.yy0.n+(int)(yymsp[0].minor.yy0.z-yymsp[-1].minor.yy0.z);}
84867 break;
84868 case 55: /* ccons ::= DEFAULT term */
84869 case 57: /* ccons ::= DEFAULT PLUS term */
84870 {sqlite3AddDefaultValue(pParse,yymsp[0].minor.yy122);}
84871 break;
84872 case 56: /* ccons ::= DEFAULT LP expr RP */
84873 {sqlite3AddDefaultValue(pParse,yymsp[-1].minor.yy122);}
84874 break;
84875 case 58: /* ccons ::= DEFAULT MINUS term */
84876 {
84877 Expr *p = sqlite3PExpr(pParse, TK_UMINUS, yymsp[0].minor.yy122, 0, 0);
84878 sqlite3ExprSpan(p,&yymsp[-1].minor.yy0,&yymsp[0].minor.yy122->span);
84879 sqlite3AddDefaultValue(pParse,p);
84880 }
84881 break;
84882 case 59: /* ccons ::= DEFAULT id */
84883 {
84884 Expr *p = sqlite3PExpr(pParse, TK_STRING, 0, 0, &yymsp[0].minor.yy0);
84885 sqlite3AddDefaultValue(pParse,p);
84886 }
84887 break;
84888 case 61: /* ccons ::= NOT NULL onconf */
84889 {sqlite3AddNotNull(pParse, yymsp[0].minor.yy392);}
84890 break;
84891 case 62: /* ccons ::= PRIMARY KEY sortorder onconf autoinc */
84892 {sqlite3AddPrimaryKey(pParse,0,yymsp[-1].minor.yy392,yymsp[0].minor.yy392,yymsp[-2].minor.yy392);}
84893 break;
84894 case 63: /* ccons ::= UNIQUE onconf */
84895 {sqlite3CreateIndex(pParse,0,0,0,0,yymsp[0].minor.yy392,0,0,0,0);}
84896 break;
84897 case 64: /* ccons ::= CHECK LP expr RP */
84898 {sqlite3AddCheckConstraint(pParse,yymsp[-1].minor.yy122);}
84899 break;
84900 case 65: /* ccons ::= REFERENCES nm idxlist_opt refargs */
84901 {sqlite3CreateForeignKey(pParse,0,&yymsp[-2].minor.yy0,yymsp[-1].minor.yy442,yymsp[0].minor.yy392);}
84902 break;
84903 case 66: /* ccons ::= defer_subclause */
84904 {sqlite3DeferForeignKey(pParse,yymsp[0].minor.yy392);}
84905 break;
84906 case 67: /* ccons ::= COLLATE ids */
84907 {sqlite3AddCollateType(pParse, &yymsp[0].minor.yy0);}
84908 break;
84909 case 70: /* refargs ::= */
84910 { yygotominor.yy392 = OE_Restrict * 0x010101; }
84911 break;
84912 case 71: /* refargs ::= refargs refarg */
84913 { yygotominor.yy392 = (yymsp[-1].minor.yy392 & ~yymsp[0].minor.yy207.mask) | yymsp[0].minor.yy207.value; }
84914 break;
84915 case 72: /* refarg ::= MATCH nm */
84916 { yygotominor.yy207.value = 0; yygotominor.yy207.mask = 0x000000; }
84917 break;
84918 case 73: /* refarg ::= ON DELETE refact */
84919 { yygotominor.yy207.value = yymsp[0].minor.yy392; yygotominor.yy207.mask = 0x0000ff; }
84920 break;
84921 case 74: /* refarg ::= ON UPDATE refact */
84922 { yygotominor.yy207.value = yymsp[0].minor.yy392<<8; yygotominor.yy207.mask = 0x00ff00; }
84923 break;
84924 case 75: /* refarg ::= ON INSERT refact */
84925 { yygotominor.yy207.value = yymsp[0].minor.yy392<<16; yygotominor.yy207.mask = 0xff0000; }
84926 break;
84927 case 76: /* refact ::= SET NULL */
84928 { yygotominor.yy392 = OE_SetNull; }
84929 break;
84930 case 77: /* refact ::= SET DEFAULT */
84931 { yygotominor.yy392 = OE_SetDflt; }
84932 break;
84933 case 78: /* refact ::= CASCADE */
84934 { yygotominor.yy392 = OE_Cascade; }
84935 break;
84936 case 79: /* refact ::= RESTRICT */
84937 { yygotominor.yy392 = OE_Restrict; }
84938 break;
84939 case 80: /* defer_subclause ::= NOT DEFERRABLE init_deferred_pred_opt */
84940 case 81: /* defer_subclause ::= DEFERRABLE init_deferred_pred_opt */
84941 case 96: /* defer_subclause_opt ::= defer_subclause */
84942 case 98: /* onconf ::= ON CONFLICT resolvetype */
84943 case 100: /* orconf ::= OR resolvetype */
84944 case 101: /* resolvetype ::= raisetype */
84945 case 173: /* insert_cmd ::= INSERT orconf */
84946 {yygotominor.yy392 = yymsp[0].minor.yy392;}
84947 break;
84948 case 85: /* conslist_opt ::= */
84949 {yygotominor.yy0.n = 0; yygotominor.yy0.z = 0;}
84950 break;
84951 case 86: /* conslist_opt ::= COMMA conslist */
84952 {yygotominor.yy0 = yymsp[-1].minor.yy0;}
84953 break;
84954 case 91: /* tcons ::= PRIMARY KEY LP idxlist autoinc RP onconf */
84955 {sqlite3AddPrimaryKey(pParse,yymsp[-3].minor.yy442,yymsp[0].minor.yy392,yymsp[-2].minor.yy392,0);}
84956 break;
84957 case 92: /* tcons ::= UNIQUE LP idxlist RP onconf */
84958 {sqlite3CreateIndex(pParse,0,0,0,yymsp[-2].minor.yy442,yymsp[0].minor.yy392,0,0,0,0);}
84959 break;
84960 case 93: /* tcons ::= CHECK LP expr RP onconf */
84961 {sqlite3AddCheckConstraint(pParse,yymsp[-2].minor.yy122);}
84962 break;
84963 case 94: /* tcons ::= FOREIGN KEY LP idxlist RP REFERENCES nm idxlist_opt refargs defer_subclause_opt */
84964 {
84965 sqlite3CreateForeignKey(pParse, yymsp[-6].minor.yy442, &yymsp[-3].minor.yy0, yymsp[-2].minor.yy442, yymsp[-1].minor.yy392);
84966 sqlite3DeferForeignKey(pParse, yymsp[0].minor.yy392);
84967 }
84968 break;
84969 case 97: /* onconf ::= */
84970 case 99: /* orconf ::= */
84971 {yygotominor.yy392 = OE_Default;}
84972 break;
84973 case 102: /* resolvetype ::= IGNORE */
84974 {yygotominor.yy392 = OE_Ignore;}
84975 break;
84976 case 103: /* resolvetype ::= REPLACE */
84977 case 174: /* insert_cmd ::= REPLACE */
84978 {yygotominor.yy392 = OE_Replace;}
84979 break;
84980 case 104: /* cmd ::= DROP TABLE ifexists fullname */
84981 {
84982 sqlite3DropTable(pParse, yymsp[0].minor.yy347, 0, yymsp[-1].minor.yy392);
84983 }
84984 break;
84985 case 107: /* cmd ::= CREATE temp VIEW ifnotexists nm dbnm AS select */
84986 {
84987 sqlite3CreateView(pParse, &yymsp[-7].minor.yy0, &yymsp[-3].minor.yy0, &yymsp[-2].minor.yy0, yymsp[0].minor.yy159, yymsp[-6].minor.yy392, yymsp[-4].minor.yy392);
84988 }
84989 break;
84990 case 108: /* cmd ::= DROP VIEW ifexists fullname */
84991 {
84992 sqlite3DropTable(pParse, yymsp[0].minor.yy347, 1, yymsp[-1].minor.yy392);
84993 }
84994 break;
84995 case 109: /* cmd ::= select */
84996 {
84997 SelectDest dest = {SRT_Output, 0, 0, 0, 0};
84998 sqlite3Select(pParse, yymsp[0].minor.yy159, &dest);
84999 sqlite3SelectDelete(pParse->db, yymsp[0].minor.yy159);
85000 }
85001 break;
85002 case 110: /* select ::= oneselect */
85003 {yygotominor.yy159 = yymsp[0].minor.yy159;}
85004 break;
85005 case 111: /* select ::= select multiselect_op oneselect */
85006 {
85007 if( yymsp[0].minor.yy159 ){
85008 yymsp[0].minor.yy159->op = (u8)yymsp[-1].minor.yy392;
85009 yymsp[0].minor.yy159->pPrior = yymsp[-2].minor.yy159;
85010 }else{
85011 sqlite3SelectDelete(pParse->db, yymsp[-2].minor.yy159);
85012 }
85013 yygotominor.yy159 = yymsp[0].minor.yy159;
85014 }
85015 break;
85016 case 113: /* multiselect_op ::= UNION ALL */
85017 {yygotominor.yy392 = TK_ALL;}
85018 break;
85019 case 115: /* oneselect ::= SELECT distinct selcollist from where_opt groupby_opt having_opt orderby_opt limit_opt */
85020 {
85021 yygotominor.yy159 = sqlite3SelectNew(pParse,yymsp[-6].minor.yy442,yymsp[-5].minor.yy347,yymsp[-4].minor.yy122,yymsp[-3].minor.yy442,yymsp[-2].minor.yy122,yymsp[-1].minor.yy442,yymsp[-7].minor.yy392,yymsp[0].minor.yy64.pLimit,yymsp[0].minor.yy64.pOffset);
85022 }
85023 break;
85024 case 119: /* sclp ::= selcollist COMMA */
85025 case 245: /* idxlist_opt ::= LP idxlist RP */
85026 {yygotominor.yy442 = yymsp[-1].minor.yy442;}
85027 break;
85028 case 120: /* sclp ::= */
85029 case 148: /* orderby_opt ::= */
85030 case 156: /* groupby_opt ::= */
85031 case 238: /* exprlist ::= */
85032 case 244: /* idxlist_opt ::= */
85033 {yygotominor.yy442 = 0;}
85034 break;
85035 case 121: /* selcollist ::= sclp expr as */
85036 {
85037 yygotominor.yy442 = sqlite3ExprListAppend(pParse,yymsp[-2].minor.yy442,yymsp[-1].minor.yy122,yymsp[0].minor.yy0.n?&yymsp[0].minor.yy0:0);
85038 }
85039 break;
85040 case 122: /* selcollist ::= sclp STAR */
85041 {
85042 Expr *p = sqlite3PExpr(pParse, TK_ALL, 0, 0, 0);
85043 yygotominor.yy442 = sqlite3ExprListAppend(pParse, yymsp[-1].minor.yy442, p, 0);
85044 }
85045 break;
85046 case 123: /* selcollist ::= sclp nm DOT STAR */
85047 {
85048 Expr *pRight = sqlite3PExpr(pParse, TK_ALL, 0, 0, &yymsp[0].minor.yy0);
85049 Expr *pLeft = sqlite3PExpr(pParse, TK_ID, 0, 0, &yymsp[-2].minor.yy0);
85050 Expr *pDot = sqlite3PExpr(pParse, TK_DOT, pLeft, pRight, 0);
85051 yygotominor.yy442 = sqlite3ExprListAppend(pParse,yymsp[-3].minor.yy442, pDot, 0);
85052 }
85053 break;
85054 case 126: /* as ::= */
85055 {yygotominor.yy0.n = 0;}
85056 break;
85057 case 127: /* from ::= */
85058 {yygotominor.yy347 = sqlite3DbMallocZero(pParse->db, sizeof(*yygotominor.yy347));}
85059 break;
85060 case 128: /* from ::= FROM seltablist */
85061 {
85062 yygotominor.yy347 = yymsp[0].minor.yy347;
85063 sqlite3SrcListShiftJoinType(yygotominor.yy347);
85064 }
85065 break;
85066 case 129: /* stl_prefix ::= seltablist joinop */
85067 {
85068 yygotominor.yy347 = yymsp[-1].minor.yy347;
85069 if( yygotominor.yy347 && yygotominor.yy347->nSrc>0 ) yygotominor.yy347->a[yygotominor.yy347->nSrc-1].jointype = (u8)yymsp[0].minor.yy392;
85070 }
85071 break;
85072 case 130: /* stl_prefix ::= */
85073 {yygotominor.yy347 = 0;}
85074 break;
85075 case 131: /* seltablist ::= stl_prefix nm dbnm as indexed_opt on_opt using_opt */
85076 {
85077 yygotominor.yy347 = sqlite3SrcListAppendFromTerm(pParse,yymsp[-6].minor.yy347,&yymsp[-5].minor.yy0,&yymsp[-4].minor.yy0,&yymsp[-3].minor.yy0,0,yymsp[-1].minor.yy122,yymsp[0].minor.yy180);
85078 sqlite3SrcListIndexedBy(pParse, yygotominor.yy347, &yymsp[-2].minor.yy0);
85079 }
85080 break;
85081 case 132: /* seltablist ::= stl_prefix LP select RP as on_opt using_opt */
85082 {
85083 yygotominor.yy347 = sqlite3SrcListAppendFromTerm(pParse,yymsp[-6].minor.yy347,0,0,&yymsp[-2].minor.yy0,yymsp[-4].minor.yy159,yymsp[-1].minor.yy122,yymsp[0].minor.yy180);
85084 }
85085 break;
85086 case 133: /* seltablist ::= stl_prefix LP seltablist RP as on_opt using_opt */
85087 {
85088 if( yymsp[-6].minor.yy347==0 && yymsp[-2].minor.yy0.n==0 && yymsp[-1].minor.yy122==0 && yymsp[0].minor.yy180==0 ){
85089 yygotominor.yy347 = yymsp[-4].minor.yy347;
85090 }else{
85091 Select *pSubquery;
85092 sqlite3SrcListShiftJoinType(yymsp[-4].minor.yy347);
85093 pSubquery = sqlite3SelectNew(pParse,0,yymsp[-4].minor.yy347,0,0,0,0,0,0,0);
85094 yygotominor.yy347 = sqlite3SrcListAppendFromTerm(pParse,yymsp[-6].minor.yy347,0,0,&yymsp[-2].minor.yy0,pSubquery,yymsp[-1].minor.yy122,yymsp[0].minor.yy180);
85095 }
85096 }
85097 break;
85098 case 134: /* dbnm ::= */
85099 case 143: /* indexed_opt ::= */
85100 {yygotominor.yy0.z=0; yygotominor.yy0.n=0;}
85101 break;
85102 case 136: /* fullname ::= nm dbnm */
85103 {yygotominor.yy347 = sqlite3SrcListAppend(pParse->db,0,&yymsp[-1].minor.yy0,&yymsp[0].minor.yy0);}
85104 break;
85105 case 137: /* joinop ::= COMMA|JOIN */
85106 { yygotominor.yy392 = JT_INNER; }
85107 break;
85108 case 138: /* joinop ::= JOIN_KW JOIN */
85109 { yygotominor.yy392 = sqlite3JoinType(pParse,&yymsp[-1].minor.yy0,0,0); }
85110 break;
85111 case 139: /* joinop ::= JOIN_KW nm JOIN */
85112 { yygotominor.yy392 = sqlite3JoinType(pParse,&yymsp[-2].minor.yy0,&yymsp[-1].minor.yy0,0); }
85113 break;
85114 case 140: /* joinop ::= JOIN_KW nm nm JOIN */
85115 { yygotominor.yy392 = sqlite3JoinType(pParse,&yymsp[-3].minor.yy0,&yymsp[-2].minor.yy0,&yymsp[-1].minor.yy0); }
85116 break;
85117 case 141: /* on_opt ::= ON expr */
85118 case 152: /* sortitem ::= expr */
85119 case 159: /* having_opt ::= HAVING expr */
85120 case 166: /* where_opt ::= WHERE expr */
85121 case 181: /* expr ::= term */
85122 case 209: /* escape ::= ESCAPE expr */
85123 case 233: /* case_else ::= ELSE expr */
85124 case 235: /* case_operand ::= expr */
85125 {yygotominor.yy122 = yymsp[0].minor.yy122;}
85126 break;
85127 case 142: /* on_opt ::= */
85128 case 158: /* having_opt ::= */
85129 case 165: /* where_opt ::= */
85130 case 210: /* escape ::= */
85131 case 234: /* case_else ::= */
85132 case 236: /* case_operand ::= */
85133 {yygotominor.yy122 = 0;}
85134 break;
85135 case 145: /* indexed_opt ::= NOT INDEXED */
85136 {yygotominor.yy0.z=0; yygotominor.yy0.n=1;}
85137 break;
85138 case 146: /* using_opt ::= USING LP inscollist RP */
85139 case 178: /* inscollist_opt ::= LP inscollist RP */
85140 {yygotominor.yy180 = yymsp[-1].minor.yy180;}
85141 break;
85142 case 147: /* using_opt ::= */
85143 case 177: /* inscollist_opt ::= */
85144 {yygotominor.yy180 = 0;}
85145 break;
85146 case 149: /* orderby_opt ::= ORDER BY sortlist */
85147 case 157: /* groupby_opt ::= GROUP BY nexprlist */
85148 case 237: /* exprlist ::= nexprlist */
85149 {yygotominor.yy442 = yymsp[0].minor.yy442;}
85150 break;
85151 case 150: /* sortlist ::= sortlist COMMA sortitem sortorder */
85152 {
85153 yygotominor.yy442 = sqlite3ExprListAppend(pParse,yymsp[-3].minor.yy442,yymsp[-1].minor.yy122,0);
85154 if( yygotominor.yy442 ) yygotominor.yy442->a[yygotominor.yy442->nExpr-1].sortOrder = (u8)yymsp[0].minor.yy392;
85155 }
85156 break;
85157 case 151: /* sortlist ::= sortitem sortorder */
85158 {
85159 yygotominor.yy442 = sqlite3ExprListAppend(pParse,0,yymsp[-1].minor.yy122,0);
85160 if( yygotominor.yy442 && yygotominor.yy442->a ) yygotominor.yy442->a[0].sortOrder = (u8)yymsp[0].minor.yy392;
85161 }
85162 break;
85163 case 153: /* sortorder ::= ASC */
85164 case 155: /* sortorder ::= */
85165 {yygotominor.yy392 = SQLITE_SO_ASC;}
85166 break;
85167 case 154: /* sortorder ::= DESC */
85168 {yygotominor.yy392 = SQLITE_SO_DESC;}
85169 break;
85170 case 160: /* limit_opt ::= */
85171 {yygotominor.yy64.pLimit = 0; yygotominor.yy64.pOffset = 0;}
85172 break;
85173 case 161: /* limit_opt ::= LIMIT expr */
85174 {yygotominor.yy64.pLimit = yymsp[0].minor.yy122; yygotominor.yy64.pOffset = 0;}
85175 break;
85176 case 162: /* limit_opt ::= LIMIT expr OFFSET expr */
85177 {yygotominor.yy64.pLimit = yymsp[-2].minor.yy122; yygotominor.yy64.pOffset = yymsp[0].minor.yy122;}
85178 break;
85179 case 163: /* limit_opt ::= LIMIT expr COMMA expr */
85180 {yygotominor.yy64.pOffset = yymsp[-2].minor.yy122; yygotominor.yy64.pLimit = yymsp[0].minor.yy122;}
85181 break;
85182 case 164: /* cmd ::= DELETE FROM fullname indexed_opt where_opt */
85183 {
85184 sqlite3SrcListIndexedBy(pParse, yymsp[-2].minor.yy347, &yymsp[-1].minor.yy0);
85185 sqlite3DeleteFrom(pParse,yymsp[-2].minor.yy347,yymsp[0].minor.yy122);
85186 }
85187 break;
85188 case 167: /* cmd ::= UPDATE orconf fullname indexed_opt SET setlist where_opt */
85189 {
85190 sqlite3SrcListIndexedBy(pParse, yymsp[-4].minor.yy347, &yymsp[-3].minor.yy0);
85191 sqlite3ExprListCheckLength(pParse,yymsp[-1].minor.yy442,"set list");
85192 sqlite3Update(pParse,yymsp[-4].minor.yy347,yymsp[-1].minor.yy442,yymsp[0].minor.yy122,yymsp[-5].minor.yy392);
85193 }
85194 break;
85195 case 168: /* setlist ::= setlist COMMA nm EQ expr */
85196 {yygotominor.yy442 = sqlite3ExprListAppend(pParse,yymsp[-4].minor.yy442,yymsp[0].minor.yy122,&yymsp[-2].minor.yy0);}
85197 break;
85198 case 169: /* setlist ::= nm EQ expr */
85199 {yygotominor.yy442 = sqlite3ExprListAppend(pParse,0,yymsp[0].minor.yy122,&yymsp[-2].minor.yy0);}
85200 break;
85201 case 170: /* cmd ::= insert_cmd INTO fullname inscollist_opt VALUES LP itemlist RP */
85202 {sqlite3Insert(pParse, yymsp[-5].minor.yy347, yymsp[-1].minor.yy442, 0, yymsp[-4].minor.yy180, yymsp[-7].minor.yy392);}
85203 break;
85204 case 171: /* cmd ::= insert_cmd INTO fullname inscollist_opt select */
85205 {sqlite3Insert(pParse, yymsp[-2].minor.yy347, 0, yymsp[0].minor.yy159, yymsp[-1].minor.yy180, yymsp[-4].minor.yy392);}
85206 break;
85207 case 172: /* cmd ::= insert_cmd INTO fullname inscollist_opt DEFAULT VALUES */
85208 {sqlite3Insert(pParse, yymsp[-3].minor.yy347, 0, 0, yymsp[-2].minor.yy180, yymsp[-5].minor.yy392);}
85209 break;
85210 case 175: /* itemlist ::= itemlist COMMA expr */
85211 case 239: /* nexprlist ::= nexprlist COMMA expr */
85212 {yygotominor.yy442 = sqlite3ExprListAppend(pParse,yymsp[-2].minor.yy442,yymsp[0].minor.yy122,0);}
85213 break;
85214 case 176: /* itemlist ::= expr */
85215 case 240: /* nexprlist ::= expr */
85216 {yygotominor.yy442 = sqlite3ExprListAppend(pParse,0,yymsp[0].minor.yy122,0);}
85217 break;
85218 case 179: /* inscollist ::= inscollist COMMA nm */
85219 {yygotominor.yy180 = sqlite3IdListAppend(pParse->db,yymsp[-2].minor.yy180,&yymsp[0].minor.yy0);}
85220 break;
85221 case 180: /* inscollist ::= nm */
85222 {yygotominor.yy180 = sqlite3IdListAppend(pParse->db,0,&yymsp[0].minor.yy0);}
85223 break;
85224 case 182: /* expr ::= LP expr RP */
85225 {yygotominor.yy122 = yymsp[-1].minor.yy122; sqlite3ExprSpan(yygotominor.yy122,&yymsp[-2].minor.yy0,&yymsp[0].minor.yy0); }
85226 break;
85227 case 183: /* term ::= NULL */
85228 case 188: /* term ::= INTEGER|FLOAT|BLOB */
85229 case 189: /* term ::= STRING */
85230 {yygotominor.yy122 = sqlite3PExpr(pParse, yymsp[0].major, 0, 0, &yymsp[0].minor.yy0);}
85231 break;
85232 case 184: /* expr ::= ID */
85233 case 185: /* expr ::= JOIN_KW */
85234 {yygotominor.yy122 = sqlite3PExpr(pParse, TK_ID, 0, 0, &yymsp[0].minor.yy0);}
85235 break;
85236 case 186: /* expr ::= nm DOT nm */
85237 {
85238 Expr *temp1 = sqlite3PExpr(pParse, TK_ID, 0, 0, &yymsp[-2].minor.yy0);
85239 Expr *temp2 = sqlite3PExpr(pParse, TK_ID, 0, 0, &yymsp[0].minor.yy0);
85240 yygotominor.yy122 = sqlite3PExpr(pParse, TK_DOT, temp1, temp2, 0);
85241 }
85242 break;
85243 case 187: /* expr ::= nm DOT nm DOT nm */
85244 {
85245 Expr *temp1 = sqlite3PExpr(pParse, TK_ID, 0, 0, &yymsp[-4].minor.yy0);
85246 Expr *temp2 = sqlite3PExpr(pParse, TK_ID, 0, 0, &yymsp[-2].minor.yy0);
85247 Expr *temp3 = sqlite3PExpr(pParse, TK_ID, 0, 0, &yymsp[0].minor.yy0);
85248 Expr *temp4 = sqlite3PExpr(pParse, TK_DOT, temp2, temp3, 0);
85249 yygotominor.yy122 = sqlite3PExpr(pParse, TK_DOT, temp1, temp4, 0);
85250 }
85251 break;
85252 case 190: /* expr ::= REGISTER */
85253 {yygotominor.yy122 = sqlite3RegisterExpr(pParse, &yymsp[0].minor.yy0);}
85254 break;
85255 case 191: /* expr ::= VARIABLE */
85256 {
85257 Token *pToken = &yymsp[0].minor.yy0;
85258 Expr *pExpr = yygotominor.yy122 = sqlite3PExpr(pParse, TK_VARIABLE, 0, 0, pToken);
85259 sqlite3ExprAssignVarNumber(pParse, pExpr);
85260 }
85261 break;
85262 case 192: /* expr ::= expr COLLATE ids */
85263 {
85264 yygotominor.yy122 = sqlite3ExprSetColl(pParse, yymsp[-2].minor.yy122, &yymsp[0].minor.yy0);
85265 }
85266 break;
85267 case 193: /* expr ::= CAST LP expr AS typetoken RP */
85268 {
85269 yygotominor.yy122 = sqlite3PExpr(pParse, TK_CAST, yymsp[-3].minor.yy122, 0, &yymsp[-1].minor.yy0);
85270 sqlite3ExprSpan(yygotominor.yy122,&yymsp[-5].minor.yy0,&yymsp[0].minor.yy0);
85271 }
85272 break;
85273 case 194: /* expr ::= ID LP distinct exprlist RP */
85274 {
85275 if( yymsp[-1].minor.yy442 && yymsp[-1].minor.yy442->nExpr>SQLITE_MAX_FUNCTION_ARG ){
85276 sqlite3ErrorMsg(pParse, "too many arguments on function %T", &yymsp[-4].minor.yy0);
85277 }
85278 yygotominor.yy122 = sqlite3ExprFunction(pParse, yymsp[-1].minor.yy442, &yymsp[-4].minor.yy0);
85279 sqlite3ExprSpan(yygotominor.yy122,&yymsp[-4].minor.yy0,&yymsp[0].minor.yy0);
85280 if( yymsp[-2].minor.yy392 && yygotominor.yy122 ){
85281 yygotominor.yy122->flags |= EP_Distinct;
85282 }
85283 }
85284 break;
85285 case 195: /* expr ::= ID LP STAR RP */
85286 {
85287 yygotominor.yy122 = sqlite3ExprFunction(pParse, 0, &yymsp[-3].minor.yy0);
85288 sqlite3ExprSpan(yygotominor.yy122,&yymsp[-3].minor.yy0,&yymsp[0].minor.yy0);
85289 }
85290 break;
85291 case 196: /* term ::= CTIME_KW */
85292 {
85293 /* The CURRENT_TIME, CURRENT_DATE, and CURRENT_TIMESTAMP values are
85294 ** treated as functions that return constants */
85295 yygotominor.yy122 = sqlite3ExprFunction(pParse, 0,&yymsp[0].minor.yy0);
85296 if( yygotominor.yy122 ){
85297 yygotominor.yy122->op = TK_CONST_FUNC;
85298 yygotominor.yy122->span = yymsp[0].minor.yy0;
85299 }
85300 }
85301 break;
85302 case 197: /* expr ::= expr AND expr */
85303 case 198: /* expr ::= expr OR expr */
85304 case 199: /* expr ::= expr LT|GT|GE|LE expr */
85305 case 200: /* expr ::= expr EQ|NE expr */
85306 case 201: /* expr ::= expr BITAND|BITOR|LSHIFT|RSHIFT expr */
85307 case 202: /* expr ::= expr PLUS|MINUS expr */
85308 case 203: /* expr ::= expr STAR|SLASH|REM expr */
85309 case 204: /* expr ::= expr CONCAT expr */
85310 {yygotominor.yy122 = sqlite3PExpr(pParse,yymsp[-1].major,yymsp[-2].minor.yy122,yymsp[0].minor.yy122,0);}
85311 break;
85312 case 205: /* likeop ::= LIKE_KW */
85313 case 207: /* likeop ::= MATCH */
85314 {yygotominor.yy318.eOperator = yymsp[0].minor.yy0; yygotominor.yy318.not = 0;}
85315 break;
85316 case 206: /* likeop ::= NOT LIKE_KW */
85317 case 208: /* likeop ::= NOT MATCH */
85318 {yygotominor.yy318.eOperator = yymsp[0].minor.yy0; yygotominor.yy318.not = 1;}
85319 break;
85320 case 211: /* expr ::= expr likeop expr escape */
85321 {
85322 ExprList *pList;
85323 pList = sqlite3ExprListAppend(pParse,0, yymsp[-1].minor.yy122, 0);
85324 pList = sqlite3ExprListAppend(pParse,pList, yymsp[-3].minor.yy122, 0);
85325 if( yymsp[0].minor.yy122 ){
85326 pList = sqlite3ExprListAppend(pParse,pList, yymsp[0].minor.yy122, 0);
85327 }
85328 yygotominor.yy122 = sqlite3ExprFunction(pParse, pList, &yymsp[-2].minor.yy318.eOperator);
85329 if( yymsp[-2].minor.yy318.not ) yygotominor.yy122 = sqlite3PExpr(pParse, TK_NOT, yygotominor.yy122, 0, 0);
85330 sqlite3ExprSpan(yygotominor.yy122, &yymsp[-3].minor.yy122->span, &yymsp[-1].minor.yy122->span);
85331 if( yygotominor.yy122 ) yygotominor.yy122->flags |= EP_InfixFunc;
85332 }
85333 break;
85334 case 212: /* expr ::= expr ISNULL|NOTNULL */
85335 {
85336 yygotominor.yy122 = sqlite3PExpr(pParse, yymsp[0].major, yymsp[-1].minor.yy122, 0, 0);
85337 sqlite3ExprSpan(yygotominor.yy122,&yymsp[-1].minor.yy122->span,&yymsp[0].minor.yy0);
85338 }
85339 break;
85340 case 213: /* expr ::= expr IS NULL */
85341 {
85342 yygotominor.yy122 = sqlite3PExpr(pParse, TK_ISNULL, yymsp[-2].minor.yy122, 0, 0);
85343 sqlite3ExprSpan(yygotominor.yy122,&yymsp[-2].minor.yy122->span,&yymsp[0].minor.yy0);
85344 }
85345 break;
85346 case 214: /* expr ::= expr NOT NULL */
85347 {
85348 yygotominor.yy122 = sqlite3PExpr(pParse, TK_NOTNULL, yymsp[-2].minor.yy122, 0, 0);
85349 sqlite3ExprSpan(yygotominor.yy122,&yymsp[-2].minor.yy122->span,&yymsp[0].minor.yy0);
85350 }
85351 break;
85352 case 215: /* expr ::= expr IS NOT NULL */
85353 {
85354 yygotominor.yy122 = sqlite3PExpr(pParse, TK_NOTNULL, yymsp[-3].minor.yy122, 0, 0);
85355 sqlite3ExprSpan(yygotominor.yy122,&yymsp[-3].minor.yy122->span,&yymsp[0].minor.yy0);
85356 }
85357 break;
85358 case 216: /* expr ::= NOT expr */
85359 case 217: /* expr ::= BITNOT expr */
85360 {
85361 yygotominor.yy122 = sqlite3PExpr(pParse, yymsp[-1].major, yymsp[0].minor.yy122, 0, 0);
85362 sqlite3ExprSpan(yygotominor.yy122,&yymsp[-1].minor.yy0,&yymsp[0].minor.yy122->span);
85363 }
85364 break;
85365 case 218: /* expr ::= MINUS expr */
85366 {
85367 yygotominor.yy122 = sqlite3PExpr(pParse, TK_UMINUS, yymsp[0].minor.yy122, 0, 0);
85368 sqlite3ExprSpan(yygotominor.yy122,&yymsp[-1].minor.yy0,&yymsp[0].minor.yy122->span);
85369 }
85370 break;
85371 case 219: /* expr ::= PLUS expr */
85372 {
85373 yygotominor.yy122 = sqlite3PExpr(pParse, TK_UPLUS, yymsp[0].minor.yy122, 0, 0);
85374 sqlite3ExprSpan(yygotominor.yy122,&yymsp[-1].minor.yy0,&yymsp[0].minor.yy122->span);
85375 }
85376 break;
85377 case 222: /* expr ::= expr between_op expr AND expr */
85378 {
85379 ExprList *pList = sqlite3ExprListAppend(pParse,0, yymsp[-2].minor.yy122, 0);
85380 pList = sqlite3ExprListAppend(pParse,pList, yymsp[0].minor.yy122, 0);
85381 yygotominor.yy122 = sqlite3PExpr(pParse, TK_BETWEEN, yymsp[-4].minor.yy122, 0, 0);
85382 if( yygotominor.yy122 ){
85383 yygotominor.yy122->pList = pList;
85384 }else{
85385 sqlite3ExprListDelete(pParse->db, pList);
85386 }
85387 if( yymsp[-3].minor.yy392 ) yygotominor.yy122 = sqlite3PExpr(pParse, TK_NOT, yygotominor.yy122, 0, 0);
85388 sqlite3ExprSpan(yygotominor.yy122,&yymsp[-4].minor.yy122->span,&yymsp[0].minor.yy122->span);
85389 }
85390 break;
85391 case 225: /* expr ::= expr in_op LP exprlist RP */
85392 {
85393 yygotominor.yy122 = sqlite3PExpr(pParse, TK_IN, yymsp[-4].minor.yy122, 0, 0);
85394 if( yygotominor.yy122 ){
85395 yygotominor.yy122->pList = yymsp[-1].minor.yy442;
85396 sqlite3ExprSetHeight(pParse, yygotominor.yy122);
85397 }else{
85398 sqlite3ExprListDelete(pParse->db, yymsp[-1].minor.yy442);
85399 }
85400 if( yymsp[-3].minor.yy392 ) yygotominor.yy122 = sqlite3PExpr(pParse, TK_NOT, yygotominor.yy122, 0, 0);
85401 sqlite3ExprSpan(yygotominor.yy122,&yymsp[-4].minor.yy122->span,&yymsp[0].minor.yy0);
85402 }
85403 break;
85404 case 226: /* expr ::= LP select RP */
85405 {
85406 yygotominor.yy122 = sqlite3PExpr(pParse, TK_SELECT, 0, 0, 0);
85407 if( yygotominor.yy122 ){
85408 yygotominor.yy122->pSelect = yymsp[-1].minor.yy159;
85409 sqlite3ExprSetHeight(pParse, yygotominor.yy122);
85410 }else{
85411 sqlite3SelectDelete(pParse->db, yymsp[-1].minor.yy159);
85412 }
85413 sqlite3ExprSpan(yygotominor.yy122,&yymsp[-2].minor.yy0,&yymsp[0].minor.yy0);
85414 }
85415 break;
85416 case 227: /* expr ::= expr in_op LP select RP */
85417 {
85418 yygotominor.yy122 = sqlite3PExpr(pParse, TK_IN, yymsp[-4].minor.yy122, 0, 0);
85419 if( yygotominor.yy122 ){
85420 yygotominor.yy122->pSelect = yymsp[-1].minor.yy159;
85421 sqlite3ExprSetHeight(pParse, yygotominor.yy122);
85422 }else{
85423 sqlite3SelectDelete(pParse->db, yymsp[-1].minor.yy159);
85424 }
85425 if( yymsp[-3].minor.yy392 ) yygotominor.yy122 = sqlite3PExpr(pParse, TK_NOT, yygotominor.yy122, 0, 0);
85426 sqlite3ExprSpan(yygotominor.yy122,&yymsp[-4].minor.yy122->span,&yymsp[0].minor.yy0);
85427 }
85428 break;
85429 case 228: /* expr ::= expr in_op nm dbnm */
85430 {
85431 SrcList *pSrc = sqlite3SrcListAppend(pParse->db, 0,&yymsp[-1].minor.yy0,&yymsp[0].minor.yy0);
85432 yygotominor.yy122 = sqlite3PExpr(pParse, TK_IN, yymsp[-3].minor.yy122, 0, 0);
85433 if( yygotominor.yy122 ){
85434 yygotominor.yy122->pSelect = sqlite3SelectNew(pParse, 0,pSrc,0,0,0,0,0,0,0);
85435 sqlite3ExprSetHeight(pParse, yygotominor.yy122);
85436 }else{
85437 sqlite3SrcListDelete(pParse->db, pSrc);
85438 }
85439 if( yymsp[-2].minor.yy392 ) yygotominor.yy122 = sqlite3PExpr(pParse, TK_NOT, yygotominor.yy122, 0, 0);
85440 sqlite3ExprSpan(yygotominor.yy122,&yymsp[-3].minor.yy122->span,yymsp[0].minor.yy0.z?&yymsp[0].minor.yy0:&yymsp[-1].minor.yy0);
85441 }
85442 break;
85443 case 229: /* expr ::= EXISTS LP select RP */
85444 {
85445 Expr *p = yygotominor.yy122 = sqlite3PExpr(pParse, TK_EXISTS, 0, 0, 0);
85446 if( p ){
85447 p->pSelect = yymsp[-1].minor.yy159;
85448 sqlite3ExprSpan(p,&yymsp[-3].minor.yy0,&yymsp[0].minor.yy0);
85449 sqlite3ExprSetHeight(pParse, yygotominor.yy122);
85450 }else{
85451 sqlite3SelectDelete(pParse->db, yymsp[-1].minor.yy159);
85452 }
85453 }
85454 break;
85455 case 230: /* expr ::= CASE case_operand case_exprlist case_else END */
85456 {
85457 yygotominor.yy122 = sqlite3PExpr(pParse, TK_CASE, yymsp[-3].minor.yy122, yymsp[-1].minor.yy122, 0);
85458 if( yygotominor.yy122 ){
85459 yygotominor.yy122->pList = yymsp[-2].minor.yy442;
85460 sqlite3ExprSetHeight(pParse, yygotominor.yy122);
85461 }else{
85462 sqlite3ExprListDelete(pParse->db, yymsp[-2].minor.yy442);
85463 }
85464 sqlite3ExprSpan(yygotominor.yy122, &yymsp[-4].minor.yy0, &yymsp[0].minor.yy0);
85465 }
85466 break;
85467 case 231: /* case_exprlist ::= case_exprlist WHEN expr THEN expr */
85468 {
85469 yygotominor.yy442 = sqlite3ExprListAppend(pParse,yymsp[-4].minor.yy442, yymsp[-2].minor.yy122, 0);
85470 yygotominor.yy442 = sqlite3ExprListAppend(pParse,yygotominor.yy442, yymsp[0].minor.yy122, 0);
85471 }
85472 break;
85473 case 232: /* case_exprlist ::= WHEN expr THEN expr */
85474 {
85475 yygotominor.yy442 = sqlite3ExprListAppend(pParse,0, yymsp[-2].minor.yy122, 0);
85476 yygotominor.yy442 = sqlite3ExprListAppend(pParse,yygotominor.yy442, yymsp[0].minor.yy122, 0);
85477 }
85478 break;
85479 case 241: /* cmd ::= CREATE uniqueflag INDEX ifnotexists nm dbnm ON nm LP idxlist RP */
85480 {
85481 sqlite3CreateIndex(pParse, &yymsp[-6].minor.yy0, &yymsp[-5].minor.yy0,
85482 sqlite3SrcListAppend(pParse->db,0,&yymsp[-3].minor.yy0,0), yymsp[-1].minor.yy442, yymsp[-9].minor.yy392,
85483 &yymsp[-10].minor.yy0, &yymsp[0].minor.yy0, SQLITE_SO_ASC, yymsp[-7].minor.yy392);
85484 }
85485 break;
85486 case 242: /* uniqueflag ::= UNIQUE */
85487 case 289: /* raisetype ::= ABORT */
85488 {yygotominor.yy392 = OE_Abort;}
85489 break;
85490 case 243: /* uniqueflag ::= */
85491 {yygotominor.yy392 = OE_None;}
85492 break;
85493 case 246: /* idxlist ::= idxlist COMMA nm collate sortorder */
85494 {
85495 Expr *p = 0;
85496 if( yymsp[-1].minor.yy0.n>0 ){
85497 p = sqlite3PExpr(pParse, TK_COLUMN, 0, 0, 0);
85498 sqlite3ExprSetColl(pParse, p, &yymsp[-1].minor.yy0);
85499 }
85500 yygotominor.yy442 = sqlite3ExprListAppend(pParse,yymsp[-4].minor.yy442, p, &yymsp[-2].minor.yy0);
85501 sqlite3ExprListCheckLength(pParse, yygotominor.yy442, "index");
85502 if( yygotominor.yy442 ) yygotominor.yy442->a[yygotominor.yy442->nExpr-1].sortOrder = (u8)yymsp[0].minor.yy392;
85503 }
85504 break;
85505 case 247: /* idxlist ::= nm collate sortorder */
 
 
 
 
 
 
 
85506 {
85507 Expr *p = 0;
85508 if( yymsp[-1].minor.yy0.n>0 ){
85509 p = sqlite3PExpr(pParse, TK_COLUMN, 0, 0, 0);
85510 sqlite3ExprSetColl(pParse, p, &yymsp[-1].minor.yy0);
85511 }
85512 yygotominor.yy442 = sqlite3ExprListAppend(pParse,0, p, &yymsp[-2].minor.yy0);
85513 sqlite3ExprListCheckLength(pParse, yygotominor.yy442, "index");
85514 if( yygotominor.yy442 ) yygotominor.yy442->a[yygotominor.yy442->nExpr-1].sortOrder = (u8)yymsp[0].minor.yy392;
85515 }
85516 break;
85517 case 248: /* collate ::= */
 
 
 
 
 
 
 
 
 
 
 
 
85518 {yygotominor.yy0.z = 0; yygotominor.yy0.n = 0;}
85519 break;
85520 case 250: /* cmd ::= DROP INDEX ifexists fullname */
85521 {sqlite3DropIndex(pParse, yymsp[0].minor.yy347, yymsp[-1].minor.yy392);}
85522 break;
85523 case 251: /* cmd ::= VACUUM */
85524 case 252: /* cmd ::= VACUUM nm */
85525 {sqlite3Vacuum(pParse);}
85526 break;
85527 case 253: /* cmd ::= PRAGMA nm dbnm EQ nmnum */
85528 case 254: /* cmd ::= PRAGMA nm dbnm EQ ON */
85529 case 255: /* cmd ::= PRAGMA nm dbnm EQ DELETE */
85530 {sqlite3Pragma(pParse,&yymsp[-3].minor.yy0,&yymsp[-2].minor.yy0,&yymsp[0].minor.yy0,0);}
85531 break;
85532 case 256: /* cmd ::= PRAGMA nm dbnm EQ minus_num */
85533 {
85534 sqlite3Pragma(pParse,&yymsp[-3].minor.yy0,&yymsp[-2].minor.yy0,&yymsp[0].minor.yy0,1);
85535 }
85536 break;
85537 case 257: /* cmd ::= PRAGMA nm dbnm LP nmnum RP */
85538 {sqlite3Pragma(pParse,&yymsp[-4].minor.yy0,&yymsp[-3].minor.yy0,&yymsp[-1].minor.yy0,0);}
85539 break;
85540 case 258: /* cmd ::= PRAGMA nm dbnm */
85541 {sqlite3Pragma(pParse,&yymsp[-1].minor.yy0,&yymsp[0].minor.yy0,0,0);}
85542 break;
85543 case 266: /* cmd ::= CREATE trigger_decl BEGIN trigger_cmd_list END */
85544 {
85545 Token all;
85546 all.z = yymsp[-3].minor.yy0.z;
85547 all.n = (int)(yymsp[0].minor.yy0.z - yymsp[-3].minor.yy0.z) + yymsp[0].minor.yy0.n;
85548 sqlite3FinishTrigger(pParse, yymsp[-1].minor.yy327, &all);
85549 }
85550 break;
85551 case 267: /* trigger_decl ::= temp TRIGGER ifnotexists nm dbnm trigger_time trigger_event ON fullname foreach_clause when_clause */
85552 {
85553 sqlite3BeginTrigger(pParse, &yymsp[-7].minor.yy0, &yymsp[-6].minor.yy0, yymsp[-5].minor.yy392, yymsp[-4].minor.yy410.a, yymsp[-4].minor.yy410.b, yymsp[-2].minor.yy347, yymsp[0].minor.yy122, yymsp[-10].minor.yy392, yymsp[-8].minor.yy392);
85554 yygotominor.yy0 = (yymsp[-6].minor.yy0.n==0?yymsp[-7].minor.yy0:yymsp[-6].minor.yy0);
85555 }
85556 break;
85557 case 268: /* trigger_time ::= BEFORE */
85558 case 271: /* trigger_time ::= */
85559 { yygotominor.yy392 = TK_BEFORE; }
85560 break;
85561 case 269: /* trigger_time ::= AFTER */
85562 { yygotominor.yy392 = TK_AFTER; }
85563 break;
85564 case 270: /* trigger_time ::= INSTEAD OF */
85565 { yygotominor.yy392 = TK_INSTEAD;}
85566 break;
85567 case 272: /* trigger_event ::= DELETE|INSERT */
85568 case 273: /* trigger_event ::= UPDATE */
85569 {yygotominor.yy410.a = yymsp[0].major; yygotominor.yy410.b = 0;}
85570 break;
85571 case 274: /* trigger_event ::= UPDATE OF inscollist */
85572 {yygotominor.yy410.a = TK_UPDATE; yygotominor.yy410.b = yymsp[0].minor.yy180;}
85573 break;
85574 case 277: /* when_clause ::= */
85575 case 294: /* key_opt ::= */
85576 { yygotominor.yy122 = 0; }
85577 break;
85578 case 278: /* when_clause ::= WHEN expr */
85579 case 295: /* key_opt ::= KEY expr */
85580 { yygotominor.yy122 = yymsp[0].minor.yy122; }
85581 break;
85582 case 279: /* trigger_cmd_list ::= trigger_cmd_list trigger_cmd SEMI */
85583 {
85584 /*
85585 if( yymsp[-2].minor.yy327 ){
85586 yymsp[-2].minor.yy327->pLast->pNext = yymsp[-1].minor.yy327;
85587 }else{
85588 yymsp[-2].minor.yy327 = yymsp[-1].minor.yy327;
85589 }
85590 */
85591 assert( yymsp[-2].minor.yy327!=0 );
85592 yymsp[-2].minor.yy327->pLast->pNext = yymsp[-1].minor.yy327;
85593 yymsp[-2].minor.yy327->pLast = yymsp[-1].minor.yy327;
85594 yygotominor.yy327 = yymsp[-2].minor.yy327;
85595 }
85596 break;
85597 case 280: /* trigger_cmd_list ::= trigger_cmd SEMI */
85598 {
85599 /* if( yymsp[-1].minor.yy327 ) */
85600 assert( yymsp[-1].minor.yy327!=0 );
85601 yymsp[-1].minor.yy327->pLast = yymsp[-1].minor.yy327;
85602 yygotominor.yy327 = yymsp[-1].minor.yy327;
85603 }
85604 break;
85605 case 281: /* trigger_cmd ::= UPDATE orconf nm SET setlist where_opt */
85606 { yygotominor.yy327 = sqlite3TriggerUpdateStep(pParse->db, &yymsp[-3].minor.yy0, yymsp[-1].minor.yy442, yymsp[0].minor.yy122, yymsp[-4].minor.yy392); }
85607 break;
85608 case 282: /* trigger_cmd ::= insert_cmd INTO nm inscollist_opt VALUES LP itemlist RP */
85609 {yygotominor.yy327 = sqlite3TriggerInsertStep(pParse->db, &yymsp[-5].minor.yy0, yymsp[-4].minor.yy180, yymsp[-1].minor.yy442, 0, yymsp[-7].minor.yy392);}
85610 break;
85611 case 283: /* trigger_cmd ::= insert_cmd INTO nm inscollist_opt select */
85612 {yygotominor.yy327 = sqlite3TriggerInsertStep(pParse->db, &yymsp[-2].minor.yy0, yymsp[-1].minor.yy180, 0, yymsp[0].minor.yy159, yymsp[-4].minor.yy392);}
85613 break;
85614 case 284: /* trigger_cmd ::= DELETE FROM nm where_opt */
85615 {yygotominor.yy327 = sqlite3TriggerDeleteStep(pParse->db, &yymsp[-1].minor.yy0, yymsp[0].minor.yy122);}
85616 break;
85617 case 285: /* trigger_cmd ::= select */
85618 {yygotominor.yy327 = sqlite3TriggerSelectStep(pParse->db, yymsp[0].minor.yy159); }
85619 break;
85620 case 286: /* expr ::= RAISE LP IGNORE RP */
85621 {
85622 yygotominor.yy122 = sqlite3PExpr(pParse, TK_RAISE, 0, 0, 0);
85623 if( yygotominor.yy122 ){
85624 yygotominor.yy122->iColumn = OE_Ignore;
85625 sqlite3ExprSpan(yygotominor.yy122, &yymsp[-3].minor.yy0, &yymsp[0].minor.yy0);
85626 }
85627 }
85628 break;
85629 case 287: /* expr ::= RAISE LP raisetype COMMA nm RP */
85630 {
85631 yygotominor.yy122 = sqlite3PExpr(pParse, TK_RAISE, 0, 0, &yymsp[-1].minor.yy0);
85632 if( yygotominor.yy122 ) {
85633 yygotominor.yy122->iColumn = yymsp[-3].minor.yy392;
85634 sqlite3ExprSpan(yygotominor.yy122, &yymsp[-5].minor.yy0, &yymsp[0].minor.yy0);
85635 }
85636 }
85637 break;
85638 case 288: /* raisetype ::= ROLLBACK */
85639 {yygotominor.yy392 = OE_Rollback;}
85640 break;
85641 case 290: /* raisetype ::= FAIL */
85642 {yygotominor.yy392 = OE_Fail;}
85643 break;
85644 case 291: /* cmd ::= DROP TRIGGER ifexists fullname */
85645 {
85646 sqlite3DropTrigger(pParse,yymsp[0].minor.yy347,yymsp[-1].minor.yy392);
85647 }
85648 break;
85649 case 292: /* cmd ::= ATTACH database_kw_opt expr AS expr key_opt */
85650 {
85651 sqlite3Attach(pParse, yymsp[-3].minor.yy122, yymsp[-1].minor.yy122, yymsp[0].minor.yy122);
85652 }
85653 break;
85654 case 293: /* cmd ::= DETACH database_kw_opt expr */
85655 {
85656 sqlite3Detach(pParse, yymsp[0].minor.yy122);
85657 }
85658 break;
85659 case 298: /* cmd ::= REINDEX */
85660 {sqlite3Reindex(pParse, 0, 0);}
85661 break;
85662 case 299: /* cmd ::= REINDEX nm dbnm */
85663 {sqlite3Reindex(pParse, &yymsp[-1].minor.yy0, &yymsp[0].minor.yy0);}
85664 break;
85665 case 300: /* cmd ::= ANALYZE */
85666 {sqlite3Analyze(pParse, 0, 0);}
85667 break;
85668 case 301: /* cmd ::= ANALYZE nm dbnm */
85669 {sqlite3Analyze(pParse, &yymsp[-1].minor.yy0, &yymsp[0].minor.yy0);}
85670 break;
85671 case 302: /* cmd ::= ALTER TABLE fullname RENAME TO nm */
85672 {
85673 sqlite3AlterRenameTable(pParse,yymsp[-3].minor.yy347,&yymsp[0].minor.yy0);
85674 }
85675 break;
85676 case 303: /* cmd ::= ALTER TABLE add_column_fullname ADD kwcolumn_opt column */
85677 {
85678 sqlite3AlterFinishAddColumn(pParse, &yymsp[0].minor.yy0);
85679 }
85680 break;
85681 case 304: /* add_column_fullname ::= fullname */
85682 {
85683 sqlite3AlterBeginAddColumn(pParse, yymsp[0].minor.yy347);
85684 }
85685 break;
85686 case 307: /* cmd ::= create_vtab */
85687 {sqlite3VtabFinishParse(pParse,0);}
85688 break;
85689 case 308: /* cmd ::= create_vtab LP vtabarglist RP */
85690 {sqlite3VtabFinishParse(pParse,&yymsp[0].minor.yy0);}
85691 break;
85692 case 309: /* create_vtab ::= CREATE VIRTUAL TABLE nm dbnm USING nm */
85693 {
85694 sqlite3VtabBeginParse(pParse, &yymsp[-3].minor.yy0, &yymsp[-2].minor.yy0, &yymsp[0].minor.yy0);
85695 }
85696 break;
85697 case 312: /* vtabarg ::= */
85698 {sqlite3VtabArgInit(pParse);}
85699 break;
85700 case 314: /* vtabargtoken ::= ANY */
85701 case 315: /* vtabargtoken ::= lp anylist RP */
85702 case 316: /* lp ::= LP */
85703 case 318: /* anylist ::= anylist ANY */
85704 {sqlite3VtabArgExtend(pParse,&yymsp[0].minor.yy0);}
85705 break;
85706 };
85707 yygoto = yyRuleInfo[yyruleno].lhs;
85708 yysize = yyRuleInfo[yyruleno].nrhs;
@@ -84938,141 +86013,264 @@
86013 /************** Begin file keywordhash.h *************************************/
86014 /***** This file contains automatically generated code ******
86015 **
86016 ** The code in this file has been automatically generated by
86017 **
86018 ** $Header: /sqlite/sqlite/tool/mkkeywordhash.c,v 1.36 2008/12/31 21:52:41 drh Exp $
86019 **
86020 ** The code in this file implements a function that determines whether
86021 ** or not a given identifier is really an SQL keyword. The same thing
86022 ** might be implemented more directly using a hand-written hash table.
86023 ** But by using this automatically generated code, the size of the code
86024 ** is substantially reduced. This is important for embedded applications
86025 ** on platforms with limited memory.
86026 */
86027 /* Hash score: 171 */
86028 static int keywordCode(const char *z, int n){
86029 /* zText[] encodes 801 bytes of keywords in 541 bytes */
86030 /* REINDEXEDESCAPEACHECKEYBEFOREIGNOREGEXPLAINSTEADDATABASELECT */
86031 /* ABLEFTHENDEFERRABLELSEXCEPTRANSACTIONATURALTERAISEXCLUSIVE */
86032 /* XISTSAVEPOINTERSECTRIGGEREFERENCESCONSTRAINTOFFSETEMPORARY */
86033 /* UNIQUERYATTACHAVINGROUPDATEBEGINNERELEASEBETWEENOTNULLIKE */
86034 /* CASCADELETECASECOLLATECREATECURRENT_DATEDETACHIMMEDIATEJOIN */
86035 /* SERTMATCHPLANALYZEPRAGMABORTVALUESVIRTUALIMITWHENWHERENAME */
86036 /* AFTEREPLACEANDEFAULTAUTOINCREMENTCASTCOLUMNCOMMITCONFLICTCROSS */
86037 /* CURRENT_TIMESTAMPRIMARYDEFERREDISTINCTDROPFAILFROMFULLGLOBYIF */
86038 /* ISNULLORDERESTRICTOUTERIGHTROLLBACKROWUNIONUSINGVACUUMVIEW */
86039 /* INITIALLY */
86040 static const char zText[540] = {
86041 'R','E','I','N','D','E','X','E','D','E','S','C','A','P','E','A','C','H',
86042 'E','C','K','E','Y','B','E','F','O','R','E','I','G','N','O','R','E','G',
86043 'E','X','P','L','A','I','N','S','T','E','A','D','D','A','T','A','B','A',
86044 'S','E','L','E','C','T','A','B','L','E','F','T','H','E','N','D','E','F',
86045 'E','R','R','A','B','L','E','L','S','E','X','C','E','P','T','R','A','N',
86046 'S','A','C','T','I','O','N','A','T','U','R','A','L','T','E','R','A','I',
86047 'S','E','X','C','L','U','S','I','V','E','X','I','S','T','S','A','V','E',
86048 'P','O','I','N','T','E','R','S','E','C','T','R','I','G','G','E','R','E',
86049 'F','E','R','E','N','C','E','S','C','O','N','S','T','R','A','I','N','T',
86050 'O','F','F','S','E','T','E','M','P','O','R','A','R','Y','U','N','I','Q',
86051 'U','E','R','Y','A','T','T','A','C','H','A','V','I','N','G','R','O','U',
86052 'P','D','A','T','E','B','E','G','I','N','N','E','R','E','L','E','A','S',
86053 'E','B','E','T','W','E','E','N','O','T','N','U','L','L','I','K','E','C',
86054 'A','S','C','A','D','E','L','E','T','E','C','A','S','E','C','O','L','L',
86055 'A','T','E','C','R','E','A','T','E','C','U','R','R','E','N','T','_','D',
86056 'A','T','E','D','E','T','A','C','H','I','M','M','E','D','I','A','T','E',
86057 'J','O','I','N','S','E','R','T','M','A','T','C','H','P','L','A','N','A',
86058 'L','Y','Z','E','P','R','A','G','M','A','B','O','R','T','V','A','L','U',
86059 'E','S','V','I','R','T','U','A','L','I','M','I','T','W','H','E','N','W',
86060 'H','E','R','E','N','A','M','E','A','F','T','E','R','E','P','L','A','C',
86061 'E','A','N','D','E','F','A','U','L','T','A','U','T','O','I','N','C','R',
86062 'E','M','E','N','T','C','A','S','T','C','O','L','U','M','N','C','O','M',
86063 'M','I','T','C','O','N','F','L','I','C','T','C','R','O','S','S','C','U',
86064 'R','R','E','N','T','_','T','I','M','E','S','T','A','M','P','R','I','M',
86065 'A','R','Y','D','E','F','E','R','R','E','D','I','S','T','I','N','C','T',
86066 'D','R','O','P','F','A','I','L','F','R','O','M','F','U','L','L','G','L',
86067 'O','B','Y','I','F','I','S','N','U','L','L','O','R','D','E','R','E','S',
86068 'T','R','I','C','T','O','U','T','E','R','I','G','H','T','R','O','L','L',
86069 'B','A','C','K','R','O','W','U','N','I','O','N','U','S','I','N','G','V',
86070 'A','C','U','U','M','V','I','E','W','I','N','I','T','I','A','L','L','Y',
86071 };
86072 static const unsigned char aHash[127] = {
86073 70, 99, 112, 68, 0, 43, 0, 0, 76, 0, 71, 0, 0,
86074 41, 12, 72, 15, 0, 111, 79, 49, 106, 0, 19, 0, 0,
86075 116, 0, 114, 109, 0, 22, 87, 0, 9, 0, 0, 64, 65,
86076 0, 63, 6, 0, 47, 84, 96, 0, 113, 95, 0, 0, 44,
86077 0, 97, 24, 0, 17, 0, 117, 48, 23, 0, 5, 104, 25,
86078 90, 0, 0, 119, 100, 55, 118, 52, 7, 50, 0, 85, 0,
86079 94, 26, 0, 93, 0, 0, 0, 89, 86, 91, 82, 103, 14,
86080 38, 102, 0, 75, 0, 18, 83, 105, 31, 0, 115, 74, 107,
86081 57, 45, 78, 0, 0, 88, 39, 0, 110, 0, 35, 0, 0,
86082 28, 0, 80, 53, 58, 0, 20, 56, 0, 51,
86083 };
86084 static const unsigned char aNext[119] = {
86085 0, 0, 0, 0, 4, 0, 0, 0, 0, 0, 0, 0, 0,
86086 0, 2, 0, 0, 0, 0, 0, 0, 13, 0, 0, 0, 0,
86087 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
86088 0, 0, 0, 0, 32, 21, 0, 0, 0, 42, 3, 46, 0,
86089 0, 0, 0, 29, 0, 0, 37, 0, 0, 0, 1, 60, 0,
86090 0, 61, 0, 40, 0, 0, 0, 0, 0, 0, 0, 59, 0,
86091 0, 0, 0, 30, 54, 16, 33, 10, 0, 0, 0, 0, 0,
86092 0, 0, 11, 66, 73, 0, 8, 0, 98, 92, 0, 101, 0,
86093 81, 0, 69, 0, 0, 108, 27, 36, 67, 77, 0, 34, 62,
86094 0, 0,
86095 };
86096 static const unsigned char aLen[119] = {
86097 7, 7, 5, 4, 6, 4, 5, 3, 6, 7, 3, 6, 6,
86098 7, 7, 3, 8, 2, 6, 5, 4, 4, 3, 10, 4, 6,
86099 11, 2, 7, 5, 5, 9, 6, 9, 9, 7, 10, 10, 4,
86100 6, 2, 3, 4, 9, 2, 6, 5, 6, 6, 5, 6, 5,
86101 5, 7, 7, 7, 3, 4, 4, 7, 3, 6, 4, 7, 6,
86102 12, 6, 9, 4, 6, 5, 4, 7, 6, 5, 6, 7, 5,
86103 4, 5, 6, 5, 7, 3, 7, 13, 2, 2, 4, 6, 6,
86104 8, 5, 17, 12, 7, 8, 8, 2, 4, 4, 4, 4, 4,
86105 2, 2, 6, 5, 8, 5, 5, 8, 3, 5, 5, 6, 4,
86106 9, 3,
86107 };
86108 static const unsigned short int aOffset[119] = {
86109 0, 2, 2, 8, 9, 14, 16, 20, 23, 25, 25, 29, 33,
86110 36, 41, 46, 48, 53, 54, 59, 62, 65, 67, 69, 78, 81,
86111 86, 95, 96, 101, 105, 109, 117, 122, 128, 136, 142, 152, 159,
86112 162, 162, 165, 167, 167, 171, 176, 179, 184, 189, 194, 197, 203,
86113 206, 210, 217, 223, 223, 226, 229, 233, 234, 238, 244, 248, 255,
86114 261, 273, 279, 288, 290, 296, 301, 303, 310, 315, 320, 326, 332,
86115 337, 341, 344, 350, 354, 361, 363, 370, 372, 374, 383, 387, 393,
86116 399, 407, 412, 412, 428, 435, 442, 443, 450, 454, 458, 462, 466,
86117 469, 471, 473, 479, 483, 491, 495, 500, 508, 511, 516, 521, 527,
86118 531, 536,
86119 };
86120 static const unsigned char aCode[119] = {
86121 TK_REINDEX, TK_INDEXED, TK_INDEX, TK_DESC, TK_ESCAPE,
86122 TK_EACH, TK_CHECK, TK_KEY, TK_BEFORE, TK_FOREIGN,
86123 TK_FOR, TK_IGNORE, TK_LIKE_KW, TK_EXPLAIN, TK_INSTEAD,
86124 TK_ADD, TK_DATABASE, TK_AS, TK_SELECT, TK_TABLE,
86125 TK_JOIN_KW, TK_THEN, TK_END, TK_DEFERRABLE, TK_ELSE,
86126 TK_EXCEPT, TK_TRANSACTION,TK_ON, TK_JOIN_KW, TK_ALTER,
86127 TK_RAISE, TK_EXCLUSIVE, TK_EXISTS, TK_SAVEPOINT, TK_INTERSECT,
86128 TK_TRIGGER, TK_REFERENCES, TK_CONSTRAINT, TK_INTO, TK_OFFSET,
86129 TK_OF, TK_SET, TK_TEMP, TK_TEMP, TK_OR,
86130 TK_UNIQUE, TK_QUERY, TK_ATTACH, TK_HAVING, TK_GROUP,
86131 TK_UPDATE, TK_BEGIN, TK_JOIN_KW, TK_RELEASE, TK_BETWEEN,
86132 TK_NOTNULL, TK_NOT, TK_NULL, TK_LIKE_KW, TK_CASCADE,
86133 TK_ASC, TK_DELETE, TK_CASE, TK_COLLATE, TK_CREATE,
86134 TK_CTIME_KW, TK_DETACH, TK_IMMEDIATE, TK_JOIN, TK_INSERT,
86135 TK_MATCH, TK_PLAN, TK_ANALYZE, TK_PRAGMA, TK_ABORT,
86136 TK_VALUES, TK_VIRTUAL, TK_LIMIT, TK_WHEN, TK_WHERE,
86137 TK_RENAME, TK_AFTER, TK_REPLACE, TK_AND, TK_DEFAULT,
86138 TK_AUTOINCR, TK_TO, TK_IN, TK_CAST, TK_COLUMNKW,
86139 TK_COMMIT, TK_CONFLICT, TK_JOIN_KW, TK_CTIME_KW, TK_CTIME_KW,
86140 TK_PRIMARY, TK_DEFERRED, TK_DISTINCT, TK_IS, TK_DROP,
86141 TK_FAIL, TK_FROM, TK_JOIN_KW, TK_LIKE_KW, TK_BY,
86142 TK_IF, TK_ISNULL, TK_ORDER, TK_RESTRICT, TK_JOIN_KW,
86143 TK_JOIN_KW, TK_ROLLBACK, TK_ROW, TK_UNION, TK_USING,
86144 TK_VACUUM, TK_VIEW, TK_INITIALLY, TK_ALL,
 
86145 };
86146 int h, i;
86147 if( n<2 ) return TK_ID;
86148 h = ((charMap(z[0])*4) ^
86149 (charMap(z[n-1])*3) ^
86150 n) % 127;
86151 for(i=((int)aHash[h])-1; i>=0; i=((int)aNext[i])-1){
86152 if( aLen[i]==n && sqlite3StrNICmp(&zText[aOffset[i]],z,n)==0 ){
86153 testcase( i==0 ); /* TK_REINDEX */
86154 testcase( i==1 ); /* TK_INDEXED */
86155 testcase( i==2 ); /* TK_INDEX */
86156 testcase( i==3 ); /* TK_DESC */
86157 testcase( i==4 ); /* TK_ESCAPE */
86158 testcase( i==5 ); /* TK_EACH */
86159 testcase( i==6 ); /* TK_CHECK */
86160 testcase( i==7 ); /* TK_KEY */
86161 testcase( i==8 ); /* TK_BEFORE */
86162 testcase( i==9 ); /* TK_FOREIGN */
86163 testcase( i==10 ); /* TK_FOR */
86164 testcase( i==11 ); /* TK_IGNORE */
86165 testcase( i==12 ); /* TK_LIKE_KW */
86166 testcase( i==13 ); /* TK_EXPLAIN */
86167 testcase( i==14 ); /* TK_INSTEAD */
86168 testcase( i==15 ); /* TK_ADD */
86169 testcase( i==16 ); /* TK_DATABASE */
86170 testcase( i==17 ); /* TK_AS */
86171 testcase( i==18 ); /* TK_SELECT */
86172 testcase( i==19 ); /* TK_TABLE */
86173 testcase( i==20 ); /* TK_JOIN_KW */
86174 testcase( i==21 ); /* TK_THEN */
86175 testcase( i==22 ); /* TK_END */
86176 testcase( i==23 ); /* TK_DEFERRABLE */
86177 testcase( i==24 ); /* TK_ELSE */
86178 testcase( i==25 ); /* TK_EXCEPT */
86179 testcase( i==26 ); /* TK_TRANSACTION */
86180 testcase( i==27 ); /* TK_ON */
86181 testcase( i==28 ); /* TK_JOIN_KW */
86182 testcase( i==29 ); /* TK_ALTER */
86183 testcase( i==30 ); /* TK_RAISE */
86184 testcase( i==31 ); /* TK_EXCLUSIVE */
86185 testcase( i==32 ); /* TK_EXISTS */
86186 testcase( i==33 ); /* TK_SAVEPOINT */
86187 testcase( i==34 ); /* TK_INTERSECT */
86188 testcase( i==35 ); /* TK_TRIGGER */
86189 testcase( i==36 ); /* TK_REFERENCES */
86190 testcase( i==37 ); /* TK_CONSTRAINT */
86191 testcase( i==38 ); /* TK_INTO */
86192 testcase( i==39 ); /* TK_OFFSET */
86193 testcase( i==40 ); /* TK_OF */
86194 testcase( i==41 ); /* TK_SET */
86195 testcase( i==42 ); /* TK_TEMP */
86196 testcase( i==43 ); /* TK_TEMP */
86197 testcase( i==44 ); /* TK_OR */
86198 testcase( i==45 ); /* TK_UNIQUE */
86199 testcase( i==46 ); /* TK_QUERY */
86200 testcase( i==47 ); /* TK_ATTACH */
86201 testcase( i==48 ); /* TK_HAVING */
86202 testcase( i==49 ); /* TK_GROUP */
86203 testcase( i==50 ); /* TK_UPDATE */
86204 testcase( i==51 ); /* TK_BEGIN */
86205 testcase( i==52 ); /* TK_JOIN_KW */
86206 testcase( i==53 ); /* TK_RELEASE */
86207 testcase( i==54 ); /* TK_BETWEEN */
86208 testcase( i==55 ); /* TK_NOTNULL */
86209 testcase( i==56 ); /* TK_NOT */
86210 testcase( i==57 ); /* TK_NULL */
86211 testcase( i==58 ); /* TK_LIKE_KW */
86212 testcase( i==59 ); /* TK_CASCADE */
86213 testcase( i==60 ); /* TK_ASC */
86214 testcase( i==61 ); /* TK_DELETE */
86215 testcase( i==62 ); /* TK_CASE */
86216 testcase( i==63 ); /* TK_COLLATE */
86217 testcase( i==64 ); /* TK_CREATE */
86218 testcase( i==65 ); /* TK_CTIME_KW */
86219 testcase( i==66 ); /* TK_DETACH */
86220 testcase( i==67 ); /* TK_IMMEDIATE */
86221 testcase( i==68 ); /* TK_JOIN */
86222 testcase( i==69 ); /* TK_INSERT */
86223 testcase( i==70 ); /* TK_MATCH */
86224 testcase( i==71 ); /* TK_PLAN */
86225 testcase( i==72 ); /* TK_ANALYZE */
86226 testcase( i==73 ); /* TK_PRAGMA */
86227 testcase( i==74 ); /* TK_ABORT */
86228 testcase( i==75 ); /* TK_VALUES */
86229 testcase( i==76 ); /* TK_VIRTUAL */
86230 testcase( i==77 ); /* TK_LIMIT */
86231 testcase( i==78 ); /* TK_WHEN */
86232 testcase( i==79 ); /* TK_WHERE */
86233 testcase( i==80 ); /* TK_RENAME */
86234 testcase( i==81 ); /* TK_AFTER */
86235 testcase( i==82 ); /* TK_REPLACE */
86236 testcase( i==83 ); /* TK_AND */
86237 testcase( i==84 ); /* TK_DEFAULT */
86238 testcase( i==85 ); /* TK_AUTOINCR */
86239 testcase( i==86 ); /* TK_TO */
86240 testcase( i==87 ); /* TK_IN */
86241 testcase( i==88 ); /* TK_CAST */
86242 testcase( i==89 ); /* TK_COLUMNKW */
86243 testcase( i==90 ); /* TK_COMMIT */
86244 testcase( i==91 ); /* TK_CONFLICT */
86245 testcase( i==92 ); /* TK_JOIN_KW */
86246 testcase( i==93 ); /* TK_CTIME_KW */
86247 testcase( i==94 ); /* TK_CTIME_KW */
86248 testcase( i==95 ); /* TK_PRIMARY */
86249 testcase( i==96 ); /* TK_DEFERRED */
86250 testcase( i==97 ); /* TK_DISTINCT */
86251 testcase( i==98 ); /* TK_IS */
86252 testcase( i==99 ); /* TK_DROP */
86253 testcase( i==100 ); /* TK_FAIL */
86254 testcase( i==101 ); /* TK_FROM */
86255 testcase( i==102 ); /* TK_JOIN_KW */
86256 testcase( i==103 ); /* TK_LIKE_KW */
86257 testcase( i==104 ); /* TK_BY */
86258 testcase( i==105 ); /* TK_IF */
86259 testcase( i==106 ); /* TK_ISNULL */
86260 testcase( i==107 ); /* TK_ORDER */
86261 testcase( i==108 ); /* TK_RESTRICT */
86262 testcase( i==109 ); /* TK_JOIN_KW */
86263 testcase( i==110 ); /* TK_JOIN_KW */
86264 testcase( i==111 ); /* TK_ROLLBACK */
86265 testcase( i==112 ); /* TK_ROW */
86266 testcase( i==113 ); /* TK_UNION */
86267 testcase( i==114 ); /* TK_USING */
86268 testcase( i==115 ); /* TK_VACUUM */
86269 testcase( i==116 ); /* TK_VIEW */
86270 testcase( i==117 ); /* TK_INITIALLY */
86271 testcase( i==118 ); /* TK_ALL */
86272 return aCode[i];
86273 }
86274 }
86275 return TK_ID;
86276 }
@@ -85826,11 +87024,11 @@
87024 ** Main file for the SQLite library. The routines in this file
87025 ** implement the programmer interface to the library. Routines in
87026 ** other files are for internal use by SQLite and should not be
87027 ** accessed by users of the library.
87028 **
87029 ** $Id: main.c,v 1.520 2008/12/17 17:30:26 danielk1977 Exp $
87030 */
87031
87032 #ifdef SQLITE_ENABLE_FTS3
87033 /************** Include fts3.h in the middle of main.c ***********************/
87034 /************** Begin file fts3.h ********************************************/
@@ -86442,10 +87640,25 @@
87640 ** Return the number of changes since the database handle was opened.
87641 */
87642 SQLITE_API int sqlite3_total_changes(sqlite3 *db){
87643 return db->nTotalChange;
87644 }
87645
87646 /*
87647 ** Close all open savepoints. This function only manipulates fields of the
87648 ** database handle object, it does not close any savepoints that may be open
87649 ** at the b-tree/pager level.
87650 */
87651 SQLITE_PRIVATE void sqlite3CloseSavepoints(sqlite3 *db){
87652 while( db->pSavepoint ){
87653 Savepoint *pTmp = db->pSavepoint;
87654 db->pSavepoint = pTmp->pNext;
87655 sqlite3DbFree(db, pTmp);
87656 }
87657 db->nSavepoint = 0;
87658 db->isTransactionSavepoint = 0;
87659 }
87660
87661 /*
87662 ** Close an existing SQLite database
87663 */
87664 SQLITE_API int sqlite3_close(sqlite3 *db){
@@ -86484,10 +87697,13 @@
87697 "Unable to close due to unfinalised statements");
87698 sqlite3_mutex_leave(db->mutex);
87699 return SQLITE_BUSY;
87700 }
87701 assert( sqlite3SafetyCheckSickOrOk(db) );
87702
87703 /* Free any outstanding Savepoint structures. */
87704 sqlite3CloseSavepoints(db);
87705
87706 for(j=0; j<db->nDb; j++){
87707 struct Db *pDb = &db->aDb[j];
87708 if( pDb->pBt ){
87709 sqlite3BtreeClose(pDb->pBt);
@@ -88306,126 +89522,27 @@
89522 #if defined(SQLITE_ENABLE_FTS3) && !defined(SQLITE_CORE)
89523 # define SQLITE_CORE 1
89524 #endif
89525
89526
89527 /************** Include fts3_expr.h in the middle of fts3.c ******************/
89528 /************** Begin file fts3_expr.h ***************************************/
89529 /*
89530 ** 2008 Nov 28
89531 **
89532 ** The author disclaims copyright to this source code. In place of
89533 ** a legal notice, here is a blessing:
89534 **
89535 ** May you do good and not evil.
89536 ** May you find forgiveness for yourself and forgive others.
89537 ** May you share freely, never taking more than you give.
89538 **
89539 ******************************************************************************
89540 **
89541 */
89542
89543 /************** Include fts3_tokenizer.h in the middle of fts3_expr.h ********/
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
89544 /************** Begin file fts3_tokenizer.h **********************************/
89545 /*
89546 ** 2006 July 10
89547 **
89548 ** The author disclaims copyright to this source code.
@@ -88569,10 +89686,208 @@
89686 };
89687
89688 #endif /* _FTS3_TOKENIZER_H_ */
89689
89690 /************** End of fts3_tokenizer.h **************************************/
89691 /************** Continuing where we left off in fts3_expr.h ******************/
89692
89693 /*
89694 ** The following describes the syntax supported by the fts3 MATCH
89695 ** operator in a similar format to that used by the lemon parser
89696 ** generator. This module does not use actually lemon, it uses a
89697 ** custom parser.
89698 **
89699 ** query ::= andexpr (OR andexpr)*.
89700 **
89701 ** andexpr ::= notexpr (AND? notexpr)*.
89702 **
89703 ** notexpr ::= nearexpr (NOT nearexpr|-TOKEN)*.
89704 ** notexpr ::= LP query RP.
89705 **
89706 ** nearexpr ::= phrase (NEAR distance_opt nearexpr)*.
89707 **
89708 ** distance_opt ::= .
89709 ** distance_opt ::= / INTEGER.
89710 **
89711 ** phrase ::= TOKEN.
89712 ** phrase ::= COLUMN:TOKEN.
89713 ** phrase ::= "TOKEN TOKEN TOKEN...".
89714 */
89715
89716 typedef struct Fts3Expr Fts3Expr;
89717 typedef struct Fts3Phrase Fts3Phrase;
89718
89719 /*
89720 ** A "phrase" is a sequence of one or more tokens that must match in
89721 ** sequence. A single token is the base case and the most common case.
89722 ** For a sequence of tokens contained in "...", nToken will be the number
89723 ** of tokens in the string.
89724 */
89725 struct Fts3Phrase {
89726 int nToken; /* Number of tokens in the phrase */
89727 int iColumn; /* Index of column this phrase must match */
89728 int isNot; /* Phrase prefixed by unary not (-) operator */
89729 struct PhraseToken {
89730 char *z; /* Text of the token */
89731 int n; /* Number of bytes in buffer pointed to by z */
89732 int isPrefix; /* True if token ends in with a "*" character */
89733 } aToken[1]; /* One entry for each token in the phrase */
89734 };
89735
89736 /*
89737 ** A tree of these objects forms the RHS of a MATCH operator.
89738 */
89739 struct Fts3Expr {
89740 int eType; /* One of the FTSQUERY_XXX values defined below */
89741 int nNear; /* Valid if eType==FTSQUERY_NEAR */
89742 Fts3Expr *pParent; /* pParent->pLeft==this or pParent->pRight==this */
89743 Fts3Expr *pLeft; /* Left operand */
89744 Fts3Expr *pRight; /* Right operand */
89745 Fts3Phrase *pPhrase; /* Valid if eType==FTSQUERY_PHRASE */
89746 };
89747
89748 SQLITE_PRIVATE int sqlite3Fts3ExprParse(sqlite3_tokenizer *, char **, int, int,
89749 const char *, int, Fts3Expr **);
89750 SQLITE_PRIVATE void sqlite3Fts3ExprFree(Fts3Expr *);
89751
89752 /*
89753 ** Candidate values for Fts3Query.eType. Note that the order of the first
89754 ** four values is in order of precedence when parsing expressions. For
89755 ** example, the following:
89756 **
89757 ** "a OR b AND c NOT d NEAR e"
89758 **
89759 ** is equivalent to:
89760 **
89761 ** "a OR (b AND (c NOT (d NEAR e)))"
89762 */
89763 #define FTSQUERY_NEAR 1
89764 #define FTSQUERY_NOT 2
89765 #define FTSQUERY_AND 3
89766 #define FTSQUERY_OR 4
89767 #define FTSQUERY_PHRASE 5
89768
89769 #ifdef SQLITE_TEST
89770 SQLITE_PRIVATE void sqlite3Fts3ExprInitTestInterface(sqlite3 *db);
89771 #endif
89772
89773 /************** End of fts3_expr.h *******************************************/
89774 /************** Continuing where we left off in fts3.c ***********************/
89775 /************** Include fts3_hash.h in the middle of fts3.c ******************/
89776 /************** Begin file fts3_hash.h ***************************************/
89777 /*
89778 ** 2001 September 22
89779 **
89780 ** The author disclaims copyright to this source code. In place of
89781 ** a legal notice, here is a blessing:
89782 **
89783 ** May you do good and not evil.
89784 ** May you find forgiveness for yourself and forgive others.
89785 ** May you share freely, never taking more than you give.
89786 **
89787 *************************************************************************
89788 ** This is the header file for the generic hash-table implemenation
89789 ** used in SQLite. We've modified it slightly to serve as a standalone
89790 ** hash table implementation for the full-text indexing module.
89791 **
89792 */
89793 #ifndef _FTS3_HASH_H_
89794 #define _FTS3_HASH_H_
89795
89796 /* Forward declarations of structures. */
89797 typedef struct fts3Hash fts3Hash;
89798 typedef struct fts3HashElem fts3HashElem;
89799
89800 /* A complete hash table is an instance of the following structure.
89801 ** The internals of this structure are intended to be opaque -- client
89802 ** code should not attempt to access or modify the fields of this structure
89803 ** directly. Change this structure only by using the routines below.
89804 ** However, many of the "procedures" and "functions" for modifying and
89805 ** accessing this structure are really macros, so we can't really make
89806 ** this structure opaque.
89807 */
89808 struct fts3Hash {
89809 char keyClass; /* HASH_INT, _POINTER, _STRING, _BINARY */
89810 char copyKey; /* True if copy of key made on insert */
89811 int count; /* Number of entries in this table */
89812 fts3HashElem *first; /* The first element of the array */
89813 int htsize; /* Number of buckets in the hash table */
89814 struct _fts3ht { /* the hash table */
89815 int count; /* Number of entries with this hash */
89816 fts3HashElem *chain; /* Pointer to first entry with this hash */
89817 } *ht;
89818 };
89819
89820 /* Each element in the hash table is an instance of the following
89821 ** structure. All elements are stored on a single doubly-linked list.
89822 **
89823 ** Again, this structure is intended to be opaque, but it can't really
89824 ** be opaque because it is used by macros.
89825 */
89826 struct fts3HashElem {
89827 fts3HashElem *next, *prev; /* Next and previous elements in the table */
89828 void *data; /* Data associated with this element */
89829 void *pKey; int nKey; /* Key associated with this element */
89830 };
89831
89832 /*
89833 ** There are 2 different modes of operation for a hash table:
89834 **
89835 ** FTS3_HASH_STRING pKey points to a string that is nKey bytes long
89836 ** (including the null-terminator, if any). Case
89837 ** is respected in comparisons.
89838 **
89839 ** FTS3_HASH_BINARY pKey points to binary data nKey bytes long.
89840 ** memcmp() is used to compare keys.
89841 **
89842 ** A copy of the key is made if the copyKey parameter to fts3HashInit is 1.
89843 */
89844 #define FTS3_HASH_STRING 1
89845 #define FTS3_HASH_BINARY 2
89846
89847 /*
89848 ** Access routines. To delete, insert a NULL pointer.
89849 */
89850 SQLITE_PRIVATE void sqlite3Fts3HashInit(fts3Hash*, int keytype, int copyKey);
89851 SQLITE_PRIVATE void *sqlite3Fts3HashInsert(fts3Hash*, const void *pKey, int nKey, void *pData);
89852 SQLITE_PRIVATE void *sqlite3Fts3HashFind(const fts3Hash*, const void *pKey, int nKey);
89853 SQLITE_PRIVATE void sqlite3Fts3HashClear(fts3Hash*);
89854
89855 /*
89856 ** Shorthand for the functions above
89857 */
89858 #define fts3HashInit sqlite3Fts3HashInit
89859 #define fts3HashInsert sqlite3Fts3HashInsert
89860 #define fts3HashFind sqlite3Fts3HashFind
89861 #define fts3HashClear sqlite3Fts3HashClear
89862
89863 /*
89864 ** Macros for looping over all elements of a hash table. The idiom is
89865 ** like this:
89866 **
89867 ** fts3Hash h;
89868 ** fts3HashElem *p;
89869 ** ...
89870 ** for(p=fts3HashFirst(&h); p; p=fts3HashNext(p)){
89871 ** SomeStructure *pData = fts3HashData(p);
89872 ** // do something with pData
89873 ** }
89874 */
89875 #define fts3HashFirst(H) ((H)->first)
89876 #define fts3HashNext(E) ((E)->next)
89877 #define fts3HashData(E) ((E)->data)
89878 #define fts3HashKey(E) ((E)->pKey)
89879 #define fts3HashKeysize(E) ((E)->nKey)
89880
89881 /*
89882 ** Number of entries in a hash table
89883 */
89884 #define fts3HashCount(H) ((H)->count)
89885
89886 #endif /* _FTS3_HASH_H_ */
89887
89888 /************** End of fts3_hash.h *******************************************/
89889 /************** Continuing where we left off in fts3.c ***********************/
89890 #ifndef SQLITE_CORE
89891 SQLITE_EXTENSION_INIT1
89892 #endif
89893
@@ -88594,15 +89909,10 @@
89909 # define FTSTRACE(A) printf A; fflush(stdout)
89910 #else
89911 # define FTSTRACE(A)
89912 #endif
89913
 
 
 
 
 
89914 /* It is not safe to call isspace(), tolower(), or isalnum() on
89915 ** hi-bit-set characters. This is the same solution used in the
89916 ** tokenizer.
89917 */
89918 /* TODO(shess) The snippet-generation code should be using the
@@ -90069,94 +91379,10 @@
91379
91380 /* end utility functions */
91381
91382 /* Forward reference */
91383 typedef struct fulltext_vtab fulltext_vtab;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
91384
91385 /*
91386 ** An instance of the following structure keeps track of generated
91387 ** matching-word offset information and snippets.
91388 */
@@ -90304,18 +91530,18 @@
91530 typedef struct fulltext_cursor {
91531 sqlite3_vtab_cursor base; /* Base class used by SQLite core */
91532 QueryType iCursorType; /* Copy of sqlite3_index_info.idxNum */
91533 sqlite3_stmt *pStmt; /* Prepared statement in use by the cursor */
91534 int eof; /* True if at End Of Results */
91535 Fts3Expr *pExpr; /* Parsed MATCH query string */
91536 Snippet snippet; /* Cached snippet for the current row */
91537 int iColumn; /* Column being searched */
91538 DataBuffer result; /* Doclist results from fulltextQuery */
91539 DLReader reader; /* Result reader if result not empty */
91540 } fulltext_cursor;
91541
91542 static fulltext_vtab *cursor_vtab(fulltext_cursor *c){
91543 return (fulltext_vtab *) c->base.pVtab;
91544 }
91545
91546 static const sqlite3_module fts3Module; /* forward declaration */
91547
@@ -91459,31 +92685,20 @@
92685 }else{
92686 return SQLITE_NOMEM;
92687 }
92688 }
92689
 
 
 
 
 
 
 
 
 
 
 
 
92690 /* Free all of the dynamically allocated memory held by the
92691 ** Snippet
92692 */
92693 static void snippetClear(Snippet *p){
92694 sqlite3_free(p->aMatch);
92695 sqlite3_free(p->zOffset);
92696 sqlite3_free(p->zSnippet);
92697 CLEAR(p);
92698 }
92699
92700 /*
92701 ** Append a single entry to the p->aMatch[] log.
92702 */
92703 static void snippetAppendMatch(
92704 Snippet *p, /* Append the entry to this snippet */
@@ -91514,29 +92729,88 @@
92729 /*
92730 ** Sizing information for the circular buffer used in snippetOffsetsOfColumn()
92731 */
92732 #define FTS3_ROTOR_SZ (32)
92733 #define FTS3_ROTOR_MASK (FTS3_ROTOR_SZ-1)
92734
92735 /*
92736 ** Function to iterate through the tokens of a compiled expression.
92737 **
92738 ** Except, skip all tokens on the right-hand side of a NOT operator.
92739 ** This function is used to find tokens as part of snippet and offset
92740 ** generation and we do nt want snippets and offsets to report matches
92741 ** for tokens on the RHS of a NOT.
92742 */
92743 static int fts3NextExprToken(Fts3Expr **ppExpr, int *piToken){
92744 Fts3Expr *p = *ppExpr;
92745 int iToken = *piToken;
92746 if( iToken<0 ){
92747 /* In this case the expression p is the root of an expression tree.
92748 ** Move to the first token in the expression tree.
92749 */
92750 while( p->pLeft ){
92751 p = p->pLeft;
92752 }
92753 iToken = 0;
92754 }else{
92755 assert(p && p->eType==FTSQUERY_PHRASE );
92756 if( iToken<(p->pPhrase->nToken-1) ){
92757 iToken++;
92758 }else{
92759 iToken = 0;
92760 while( p->pParent && p->pParent->pLeft!=p ){
92761 assert( p->pParent->pRight==p );
92762 p = p->pParent;
92763 }
92764 p = p->pParent;
92765 if( p ){
92766 assert( p->pRight!=0 );
92767 p = p->pRight;
92768 while( p->pLeft ){
92769 p = p->pLeft;
92770 }
92771 }
92772 }
92773 }
92774
92775 *ppExpr = p;
92776 *piToken = iToken;
92777 return p?1:0;
92778 }
92779
92780 /*
92781 ** Return TRUE if the expression node pExpr is located beneath the
92782 ** RHS of a NOT operator.
92783 */
92784 static int fts3ExprBeneathNot(Fts3Expr *p){
92785 Fts3Expr *pParent;
92786 while( p ){
92787 pParent = p->pParent;
92788 if( pParent && pParent->eType==FTSQUERY_NOT && pParent->pRight==p ){
92789 return 1;
92790 }
92791 p = pParent;
92792 }
92793 return 0;
92794 }
92795
92796 /*
92797 ** Add entries to pSnippet->aMatch[] for every match that occurs against
92798 ** document zDoc[0..nDoc-1] which is stored in column iColumn.
92799 */
92800 static void snippetOffsetsOfColumn(
92801 fulltext_cursor *pCur, /* The fulltest search cursor */
92802 Snippet *pSnippet, /* The Snippet object to be filled in */
92803 int iColumn, /* Index of fulltext table column */
92804 const char *zDoc, /* Text of the fulltext table column */
92805 int nDoc /* Length of zDoc in bytes */
92806 ){
92807 const sqlite3_tokenizer_module *pTModule; /* The tokenizer module */
92808 sqlite3_tokenizer *pTokenizer; /* The specific tokenizer */
92809 sqlite3_tokenizer_cursor *pTCursor; /* Tokenizer cursor */
92810 fulltext_vtab *pVtab; /* The full text index */
92811 int nColumn; /* Number of columns in the index */
 
 
92812 int i, j; /* Loop counters */
92813 int rc; /* Return code */
92814 unsigned int match, prevMatch; /* Phrase search bitmasks */
92815 const char *zToken; /* Next token from the tokenizer */
92816 int nToken; /* Size of zToken */
@@ -91546,41 +92820,43 @@
92820 ** few tokens */
92821 unsigned int iRotor = 0; /* Index of current token */
92822 int iRotorBegin[FTS3_ROTOR_SZ]; /* Beginning offset of token */
92823 int iRotorLen[FTS3_ROTOR_SZ]; /* Length of token */
92824
92825 pVtab = cursor_vtab(pCur);
92826 nColumn = pVtab->nColumn;
92827 pTokenizer = pVtab->pTokenizer;
92828 pTModule = pTokenizer->pModule;
92829 rc = pTModule->xOpen(pTokenizer, zDoc, nDoc, &pTCursor);
92830 if( rc ) return;
92831 pTCursor->pTokenizer = pTokenizer;
92832
 
 
 
 
92833 prevMatch = 0;
92834 while( !pTModule->xNext(pTCursor, &zToken, &nToken, &iBegin, &iEnd, &iPos) ){
92835 Fts3Expr *pIter = pCur->pExpr;
92836 int iIter = -1;
92837 iRotorBegin[iRotor&FTS3_ROTOR_MASK] = iBegin;
92838 iRotorLen[iRotor&FTS3_ROTOR_MASK] = iEnd-iBegin;
92839 match = 0;
92840 for(i=0; i<(FTS3_ROTOR_SZ-1) && fts3NextExprToken(&pIter, &iIter); i++){
92841 int nPhrase; /* Number of tokens in current phrase */
92842 struct PhraseToken *pToken; /* Current token */
92843 int iCol; /* Column index */
92844
92845 if( fts3ExprBeneathNot(pIter) ) continue;
92846 nPhrase = pIter->pPhrase->nToken;
92847 pToken = &pIter->pPhrase->aToken[iIter];
92848 iCol = pIter->pPhrase->iColumn;
92849 if( iCol>=0 && iCol<nColumn && iCol!=iColumn ) continue;
92850 if( pToken->n>nToken ) continue;
92851 if( !pToken->isPrefix && pToken->n<nToken ) continue;
92852 assert( pToken->n<=nToken );
92853 if( memcmp(pToken->z, zToken, pToken->n) ) continue;
92854 if( iIter>0 && (prevMatch & (1<<i))==0 ) continue;
92855 match |= 1<<i;
92856 if( i==(FTS3_ROTOR_SZ-2) || nPhrase==iIter+1 ){
92857 for(j=nPhrase-1; j>=0; j--){
92858 int k = (iRotor-j) & FTS3_ROTOR_MASK;
92859 snippetAppendMatch(pSnippet, iColumn, i-j, iPos-j,
92860 iRotorBegin[k], iRotorLen[k]);
92861 }
92862 }
@@ -91606,90 +92882,119 @@
92882 ** A NEAR/0 E
92883 **
92884 ** then when this function is called the Snippet contains token offsets
92885 ** 0, 4 and 5. This function removes the "0" entry (because the first A
92886 ** is not near enough to an E).
92887 **
92888 ** When this function is called, the value pointed to by parameter piLeft is
92889 ** the integer id of the left-most token in the expression tree headed by
92890 ** pExpr. This function increments *piLeft by the total number of tokens
92891 ** in the expression tree headed by pExpr.
92892 **
92893 ** Return 1 if any trimming occurs. Return 0 if no trimming is required.
92894 */
92895 static int trimSnippetOffsets(
92896 Fts3Expr *pExpr, /* The search expression */
92897 Snippet *pSnippet, /* The set of snippet offsets to be trimmed */
92898 int *piLeft /* Index of left-most token in pExpr */
92899 ){
92900 if( pExpr ){
92901 if( trimSnippetOffsets(pExpr->pLeft, pSnippet, piLeft) ){
92902 return 1;
92903 }
92904
92905 switch( pExpr->eType ){
92906 case FTSQUERY_PHRASE:
92907 *piLeft += pExpr->pPhrase->nToken;
92908 break;
92909 case FTSQUERY_NEAR: {
92910 /* The right-hand-side of a NEAR operator is always a phrase. The
92911 ** left-hand-side is either a phrase or an expression tree that is
92912 ** itself headed by a NEAR operator. The following initializations
92913 ** set local variable iLeft to the token number of the left-most
92914 ** token in the right-hand phrase, and iRight to the right most
92915 ** token in the same phrase. For example, if we had:
92916 **
92917 ** <col> MATCH '"abc def" NEAR/2 "ghi jkl"'
92918 **
92919 ** then iLeft will be set to 2 (token number of ghi) and nToken will
92920 ** be set to 4.
92921 */
92922 Fts3Expr *pLeft = pExpr->pLeft;
92923 Fts3Expr *pRight = pExpr->pRight;
92924 int iLeft = *piLeft;
92925 int nNear = pExpr->nNear;
92926 int nToken = pRight->pPhrase->nToken;
92927 int jj, ii;
92928 if( pLeft->eType==FTSQUERY_NEAR ){
92929 pLeft = pLeft->pRight;
92930 }
92931 assert( pRight->eType==FTSQUERY_PHRASE );
92932 assert( pLeft->eType==FTSQUERY_PHRASE );
92933 nToken += pLeft->pPhrase->nToken;
92934
92935 for(ii=0; ii<pSnippet->nMatch; ii++){
92936 struct snippetMatch *p = &pSnippet->aMatch[ii];
92937 if( p->iTerm==iLeft ){
92938 int isOk = 0;
92939 /* Snippet ii is an occurence of query term iLeft in the document.
92940 ** It occurs at position (p->iToken) of the document. We now
92941 ** search for an instance of token (iLeft-1) somewhere in the
92942 ** range (p->iToken - nNear)...(p->iToken + nNear + nToken) within
92943 ** the set of snippetMatch structures. If one is found, proceed.
92944 ** If one cannot be found, then remove snippets ii..(ii+N-1)
92945 ** from the matching snippets, where N is the number of tokens
92946 ** in phrase pRight->pPhrase.
92947 */
92948 for(jj=0; isOk==0 && jj<pSnippet->nMatch; jj++){
92949 struct snippetMatch *p2 = &pSnippet->aMatch[jj];
92950 if( p2->iTerm==(iLeft-1) ){
92951 if( p2->iToken>=(p->iToken-nNear-1)
92952 && p2->iToken<(p->iToken+nNear+nToken)
92953 ){
92954 isOk = 1;
92955 }
92956 }
92957 }
92958 if( !isOk ){
92959 int kk;
92960 for(kk=0; kk<pRight->pPhrase->nToken; kk++){
92961 pSnippet->aMatch[kk+ii].iTerm = -2;
92962 }
92963 return 1;
92964 }
92965 }
92966 if( p->iTerm==(iLeft-1) ){
92967 int isOk = 0;
92968 for(jj=0; isOk==0 && jj<pSnippet->nMatch; jj++){
92969 struct snippetMatch *p2 = &pSnippet->aMatch[jj];
92970 if( p2->iTerm==iLeft ){
92971 if( p2->iToken<=(p->iToken+nNear+1)
92972 && p2->iToken>(p->iToken-nNear-nToken)
92973 ){
92974 isOk = 1;
92975 }
92976 }
92977 }
92978 if( !isOk ){
92979 int kk;
92980 for(kk=0; kk<pLeft->pPhrase->nToken; kk++){
92981 pSnippet->aMatch[ii-kk].iTerm = -2;
92982 }
92983 return 1;
92984 }
92985 }
92986 }
92987 break;
92988 }
92989 }
92990
92991 if( trimSnippetOffsets(pExpr->pRight, pSnippet, piLeft) ){
92992 return 1;
92993 }
92994 }
92995 return 0;
92996 }
92997
92998 /*
92999 ** Compute all offsets for the current row of the query.
93000 ** If the offsets have already been computed, this routine is a no-op.
@@ -91696,38 +93001,44 @@
93001 */
93002 static void snippetAllOffsets(fulltext_cursor *p){
93003 int nColumn;
93004 int iColumn, i;
93005 int iFirst, iLast;
93006 int iTerm = 0;
93007 fulltext_vtab *pFts = cursor_vtab(p);
93008
93009 if( p->snippet.nMatch || p->pExpr==0 ){
93010 return;
93011 }
93012 nColumn = pFts->nColumn;
93013 iColumn = (p->iCursorType - QUERY_FULLTEXT);
93014 if( iColumn<0 || iColumn>=nColumn ){
93015 /* Look for matches over all columns of the full-text index */
93016 iFirst = 0;
93017 iLast = nColumn-1;
93018 }else{
93019 /* Look for matches in the iColumn-th column of the index only */
93020 iFirst = iColumn;
93021 iLast = iColumn;
93022 }
93023 for(i=iFirst; i<=iLast; i++){
93024 const char *zDoc;
93025 int nDoc;
93026 zDoc = (const char*)sqlite3_column_text(p->pStmt, i+1);
93027 nDoc = sqlite3_column_bytes(p->pStmt, i+1);
93028 snippetOffsetsOfColumn(p, &p->snippet, i, zDoc, nDoc);
93029 }
93030
93031 while( trimSnippetOffsets(p->pExpr, &p->snippet, &iTerm) ){
93032 iTerm = 0;
93033 }
93034 }
93035
93036 /*
93037 ** Convert the information in the aMatch[] array of the snippet
93038 ** into the string zOffset[0..nOffset-1]. This string is used as
93039 ** the return of the SQL offsets() function.
93040 */
93041 static void snippetOffsetText(Snippet *p){
93042 int i;
93043 int cnt = 0;
93044 StringBuffer sb;
@@ -91838,11 +93149,11 @@
93149
93150 for(i=0; i<nMatch; i++){
93151 aMatch[i].snStatus = SNIPPET_IGNORE;
93152 }
93153 nDesired = 0;
93154 for(i=0; i<FTS3_ROTOR_SZ; i++){
93155 for(j=0; j<nMatch; j++){
93156 if( aMatch[j].iTerm==i ){
93157 aMatch[j].snStatus = SNIPPET_DESIRED;
93158 nDesired++;
93159 break;
@@ -91926,13 +93237,15 @@
93237 */
93238 static int fulltextClose(sqlite3_vtab_cursor *pCursor){
93239 fulltext_cursor *c = (fulltext_cursor *) pCursor;
93240 FTSTRACE(("FTS3 Close %p\n", c));
93241 sqlite3_finalize(c->pStmt);
93242 sqlite3Fts3ExprFree(c->pExpr);
93243 snippetClear(&c->snippet);
93244 if( c->result.nData!=0 ){
93245 dlrDestroy(&c->reader);
93246 }
93247 dataBufferDestroy(&c->result);
93248 sqlite3_free(c);
93249 return SQLITE_OK;
93250 }
93251
@@ -91985,259 +93298,131 @@
93298 */
93299 static int termSelect(fulltext_vtab *v, int iColumn,
93300 const char *pTerm, int nTerm, int isPrefix,
93301 DocListType iType, DataBuffer *out);
93302
93303 /*
93304 ** Return a DocList corresponding to the phrase *pPhrase.
 
93305 **
93306 ** The resulting DL_DOCIDS doclist is stored in pResult, which is
93307 ** overwritten.
93308 */
93309 static int docListOfPhrase(
93310 fulltext_vtab *pTab, /* The full text index */
93311 Fts3Phrase *pPhrase, /* Phrase to return a doclist corresponding to */
93312 DocListType eListType, /* Either DL_DOCIDS or DL_POSITIONS */
93313 DataBuffer *pResult /* Write the result here */
93314 ){
93315 int ii;
93316 int rc = SQLITE_OK;
93317 int iCol = pPhrase->iColumn;
93318 DocListType eType = eListType;
93319 assert( eType==DL_POSITIONS || eType==DL_DOCIDS );
93320 if( pPhrase->nToken>1 ){
93321 eType = DL_POSITIONS;
93322 }
93323
93324 /* This code should never be called with buffered updates. */
93325 assert( pTab->nPendingData<0 );
93326
93327 for(ii=0; rc==SQLITE_OK && ii<pPhrase->nToken; ii++){
93328 DataBuffer tmp;
93329 struct PhraseToken *p = &pPhrase->aToken[ii];
93330 rc = termSelect(pTab, iCol, p->z, p->n, p->isPrefix, eType, &tmp);
93331 if( rc==SQLITE_OK ){
93332 if( ii==0 ){
93333 *pResult = tmp;
93334 }else{
93335 DataBuffer res = *pResult;
93336 dataBufferInit(pResult, 0);
93337 if( ii==(pPhrase->nToken-1) ){
93338 eType = eListType;
93339 }
93340 docListPhraseMerge(
93341 res.pData, res.nData, tmp.pData, tmp.nData, 0, 0, eType, pResult
93342 );
93343 dataBufferDestroy(&res);
93344 dataBufferDestroy(&tmp);
93345 }
93346 }
93347 }
93348
93349 return rc;
93350 }
93351
93352 /*
93353 ** Evaluate the full-text expression pExpr against fts3 table pTab. Write
93354 ** the results into pRes.
93355 */
93356 static int evalFts3Expr(
93357 fulltext_vtab *pTab, /* Fts3 Virtual table object */
93358 Fts3Expr *pExpr, /* Parsed fts3 expression */
93359 DataBuffer *pRes /* OUT: Write results of the expression here */
93360 ){
93361 int rc = SQLITE_OK;
93362
93363 /* Initialize the output buffer. If this is an empty query (pExpr==0),
93364 ** this is all that needs to be done. Empty queries produce empty
93365 ** result sets.
93366 */
93367 dataBufferInit(pRes, 0);
93368
93369 if( pExpr ){
93370 if( pExpr->eType==FTSQUERY_PHRASE ){
93371 DocListType eType = DL_DOCIDS;
93372 if( pExpr->pParent && pExpr->pParent->eType==FTSQUERY_NEAR ){
93373 eType = DL_POSITIONS;
93374 }
93375 rc = docListOfPhrase(pTab, pExpr->pPhrase, eType, pRes);
93376 }else{
93377 DataBuffer lhs;
93378 DataBuffer rhs;
93379
93380 dataBufferInit(&rhs, 0);
93381 if( SQLITE_OK==(rc = evalFts3Expr(pTab, pExpr->pLeft, &lhs))
93382 && SQLITE_OK==(rc = evalFts3Expr(pTab, pExpr->pRight, &rhs))
93383 ){
93384 switch( pExpr->eType ){
93385 case FTSQUERY_NEAR: {
93386 int nToken;
93387 Fts3Expr *pLeft;
93388 DocListType eType = DL_DOCIDS;
93389 if( pExpr->pParent && pExpr->pParent->eType==FTSQUERY_NEAR ){
93390 eType = DL_POSITIONS;
93391 }
93392 pLeft = pExpr->pLeft;
93393 while( pLeft->eType==FTSQUERY_NEAR ){
93394 pLeft=pLeft->pRight;
93395 }
93396 assert( pExpr->pRight->eType==FTSQUERY_PHRASE );
93397 assert( pLeft->eType==FTSQUERY_PHRASE );
93398 nToken = pLeft->pPhrase->nToken + pExpr->pRight->pPhrase->nToken;
93399 docListPhraseMerge(lhs.pData, lhs.nData, rhs.pData, rhs.nData,
93400 pExpr->nNear+1, nToken, eType, pRes
93401 );
93402 break;
93403 }
93404 case FTSQUERY_NOT: {
93405 docListExceptMerge(lhs.pData, lhs.nData, rhs.pData, rhs.nData,pRes);
93406 break;
93407 }
93408 case FTSQUERY_AND: {
93409 docListAndMerge(lhs.pData, lhs.nData, rhs.pData, rhs.nData, pRes);
93410 break;
93411 }
93412 case FTSQUERY_OR: {
93413 docListOrMerge(lhs.pData, lhs.nData, rhs.pData, rhs.nData, pRes);
93414 break;
93415 }
93416 }
93417 }
93418 dataBufferDestroy(&lhs);
93419 dataBufferDestroy(&rhs);
93420 }
93421 }
93422
93423 return rc;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
93424 }
93425
93426 /* TODO(shess) Refactor the code to remove this forward decl. */
93427 static int flushPendingTerms(fulltext_vtab *v);
93428
@@ -92252,16 +93437,13 @@
93437 fulltext_vtab *v, /* The full text index */
93438 int iColumn, /* Match against this column by default */
93439 const char *zInput, /* The query string */
93440 int nInput, /* Number of bytes in zInput[] */
93441 DataBuffer *pResult, /* Write the result doclist here */
93442 Fts3Expr **ppExpr /* Put parsed query string here */
93443 ){
93444 int rc;
 
 
 
93445
93446 /* TODO(shess) Instead of flushing pendingTerms, we could query for
93447 ** the relevant term and merge the doclist into what we receive from
93448 ** the database. Wait and see if this is a common issue, first.
93449 **
@@ -92269,90 +93451,24 @@
93451 ** error codes from here.
93452 */
93453
93454 /* Flush any buffered updates before executing the query. */
93455 rc = flushPendingTerms(v);
93456 if( rc!=SQLITE_OK ){
93457 return rc;
93458 }
93459
93460 /* Parse the query passed to the MATCH operator. */
93461 rc = sqlite3Fts3ExprParse(v->pTokenizer,
93462 v->azColumn, v->nColumn, iColumn, zInput, nInput, ppExpr
93463 );
93464 if( rc!=SQLITE_OK ){
93465 assert( 0==(*ppExpr) );
93466 return rc;
93467 }
93468
93469 return evalFts3Expr(v, *ppExpr, pResult);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
93470 }
93471
93472 /*
93473 ** This is the xFilter interface for the virtual table. See
93474 ** the virtual table xFilter method documentation for additional
@@ -92428,22 +93544,22 @@
93544 if( rc!=SQLITE_OK ) return rc;
93545 break;
93546
93547 default: /* full-text search */
93548 {
93549 int iCol = idxNum-QUERY_FULLTEXT;
93550 const char *zQuery = (const char *)sqlite3_value_text(argv[0]);
93551 assert( idxNum<=QUERY_FULLTEXT+v->nColumn);
93552 assert( argc==1 );
 
93553 if( c->result.nData!=0 ){
93554 /* This case happens if the same cursor is used repeatedly. */
93555 dlrDestroy(&c->reader);
93556 dataBufferReset(&c->result);
93557 }else{
93558 dataBufferInit(&c->result, 0);
93559 }
93560 rc = fulltextQuery(v, iCol, zQuery, -1, &c->result, &c->pExpr);
93561 if( rc!=SQLITE_OK ) return rc;
93562 if( c->result.nData!=0 ){
93563 dlrInit(&c->reader, DL_DOCIDS, c->result.pData, c->result.nData);
93564 }
93565 break;
@@ -94323,22 +95439,28 @@
95439 }
95440
95441 /* Scan the database and merge together the posting lists for the term
95442 ** into *out.
95443 */
95444 static int termSelect(
95445 fulltext_vtab *v,
95446 int iColumn,
95447 const char *pTerm, int nTerm, /* Term to query for */
95448 int isPrefix, /* True for a prefix search */
95449 DocListType iType,
95450 DataBuffer *out /* Write results here */
95451 ){
95452 DataBuffer doclist;
95453 sqlite3_stmt *s;
95454 int rc = sql_get_statement(v, SEGDIR_SELECT_ALL_STMT, &s);
95455 if( rc!=SQLITE_OK ) return rc;
95456
95457 /* This code should never be called with buffered updates. */
95458 assert( v->nPendingData<0 );
95459
95460 dataBufferInit(&doclist, 0);
95461 dataBufferInit(out, 0);
95462
95463 /* Traverse the segments from oldest to newest so that newer doclist
95464 ** elements for given docids overwrite older elements.
95465 */
95466 while( (rc = sqlite3_step(s))==SQLITE_ROW ){
@@ -95451,10 +96573,14 @@
96573 || (pIcu && sqlite3Fts3HashInsert(pHash, "icu", 4, (void *)pIcu))
96574 ){
96575 rc = SQLITE_NOMEM;
96576 }
96577 }
96578
96579 #ifdef SQLITE_TEST
96580 sqlite3Fts3ExprInitTestInterface(db);
96581 #endif
96582
96583 /* Create the virtual table wrapper around the hash-table and overload
96584 ** the two scalar functions. If this is successful, register the
96585 ** module with sqlite.
96586 */
@@ -95494,10 +96620,897 @@
96620 #endif
96621
96622 #endif /* !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_FTS3) */
96623
96624 /************** End of fts3.c ************************************************/
96625 /************** Begin file fts3_expr.c ***************************************/
96626 /*
96627 ** 2008 Nov 28
96628 **
96629 ** The author disclaims copyright to this source code. In place of
96630 ** a legal notice, here is a blessing:
96631 **
96632 ** May you do good and not evil.
96633 ** May you find forgiveness for yourself and forgive others.
96634 ** May you share freely, never taking more than you give.
96635 **
96636 ******************************************************************************
96637 **
96638 ** This module contains code that implements a parser for fts3 query strings
96639 ** (the right-hand argument to the MATCH operator). Because the supported
96640 ** syntax is relatively simple, the whole tokenizer/parser system is
96641 ** hand-coded. The public interface to this module is declared in source
96642 ** code file "fts3_expr.h".
96643 */
96644 #if !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_FTS3)
96645
96646 /*
96647 ** By default, this module parses the legacy syntax that has been
96648 ** traditionally used by fts3. Or, if SQLITE_ENABLE_FTS3_PARENTHESIS
96649 ** is defined, then it uses the new syntax. The differences between
96650 ** the new and the old syntaxes are:
96651 **
96652 ** a) The new syntax supports parenthesis. The old does not.
96653 **
96654 ** b) The new syntax supports the AND and NOT operators. The old does not.
96655 **
96656 ** c) The old syntax supports the "-" token qualifier. This is not
96657 ** supported by the new syntax (it is replaced by the NOT operator).
96658 **
96659 ** d) When using the old syntax, the OR operator has a greater precedence
96660 ** than an implicit AND. When using the new, both implicity and explicit
96661 ** AND operators have a higher precedence than OR.
96662 **
96663 ** If compiled with SQLITE_TEST defined, then this module exports the
96664 ** symbol "int sqlite3_fts3_enable_parentheses". Setting this variable
96665 ** to zero causes the module to use the old syntax. If it is set to
96666 ** non-zero the new syntax is activated. This is so both syntaxes can
96667 ** be tested using a single build of testfixture.
96668 */
96669 #ifdef SQLITE_TEST
96670 SQLITE_API int sqlite3_fts3_enable_parentheses = 0;
96671 #else
96672 # ifdef SQLITE_ENABLE_FTS3_PARENTHESIS
96673 # define sqlite3_fts3_enable_parentheses 1
96674 # else
96675 # define sqlite3_fts3_enable_parentheses 0
96676 # endif
96677 #endif
96678
96679 /*
96680 ** Default span for NEAR operators.
96681 */
96682 #define SQLITE_FTS3_DEFAULT_NEAR_PARAM 10
96683
96684
96685 typedef struct ParseContext ParseContext;
96686 struct ParseContext {
96687 sqlite3_tokenizer *pTokenizer; /* Tokenizer module */
96688 const char **azCol; /* Array of column names for fts3 table */
96689 int nCol; /* Number of entries in azCol[] */
96690 int iDefaultCol; /* Default column to query */
96691 sqlite3_context *pCtx; /* Write error message here */
96692 int nNest; /* Number of nested brackets */
96693 };
96694
96695 /*
96696 ** This function is equivalent to the standard isspace() function.
96697 **
96698 ** The standard isspace() can be awkward to use safely, because although it
96699 ** is defined to accept an argument of type int, its behaviour when passed
96700 ** an integer that falls outside of the range of the unsigned char type
96701 ** is undefined (and sometimes, "undefined" means segfault). This wrapper
96702 ** is defined to accept an argument of type char, and always returns 0 for
96703 ** any values that fall outside of the range of the unsigned char type (i.e.
96704 ** negative values).
96705 */
96706 static int fts3isspace(char c){
96707 return (c&0x80)==0 ? isspace(c) : 0;
96708 }
96709
96710 /*
96711 ** Extract the next token from buffer z (length n) using the tokenizer
96712 ** and other information (column names etc.) in pParse. Create an Fts3Expr
96713 ** structure of type FTSQUERY_PHRASE containing a phrase consisting of this
96714 ** single token and set *ppExpr to point to it. If the end of the buffer is
96715 ** reached before a token is found, set *ppExpr to zero. It is the
96716 ** responsibility of the caller to eventually deallocate the allocated
96717 ** Fts3Expr structure (if any) by passing it to sqlite3_free().
96718 **
96719 ** Return SQLITE_OK if successful, or SQLITE_NOMEM if a memory allocation
96720 ** fails.
96721 */
96722 static int getNextToken(
96723 ParseContext *pParse, /* fts3 query parse context */
96724 int iCol, /* Value for Fts3Phrase.iColumn */
96725 const char *z, int n, /* Input string */
96726 Fts3Expr **ppExpr, /* OUT: expression */
96727 int *pnConsumed /* OUT: Number of bytes consumed */
96728 ){
96729 sqlite3_tokenizer *pTokenizer = pParse->pTokenizer;
96730 sqlite3_tokenizer_module const *pModule = pTokenizer->pModule;
96731 int rc;
96732 sqlite3_tokenizer_cursor *pCursor;
96733 Fts3Expr *pRet = 0;
96734 int nConsumed = 0;
96735
96736 rc = pModule->xOpen(pTokenizer, z, n, &pCursor);
96737 if( rc==SQLITE_OK ){
96738 const char *zToken;
96739 int nToken, iStart, iEnd, iPosition;
96740 int nByte; /* total space to allocate */
96741
96742 pCursor->pTokenizer = pTokenizer;
96743 rc = pModule->xNext(pCursor, &zToken, &nToken, &iStart, &iEnd, &iPosition);
96744
96745 if( rc==SQLITE_OK ){
96746 nByte = sizeof(Fts3Expr) + sizeof(Fts3Phrase) + nToken;
96747 pRet = (Fts3Expr *)sqlite3_malloc(nByte);
96748 if( !pRet ){
96749 rc = SQLITE_NOMEM;
96750 }else{
96751 memset(pRet, 0, nByte);
96752 pRet->eType = FTSQUERY_PHRASE;
96753 pRet->pPhrase = (Fts3Phrase *)&pRet[1];
96754 pRet->pPhrase->nToken = 1;
96755 pRet->pPhrase->iColumn = iCol;
96756 pRet->pPhrase->aToken[0].n = nToken;
96757 pRet->pPhrase->aToken[0].z = (char *)&pRet->pPhrase[1];
96758 memcpy(pRet->pPhrase->aToken[0].z, zToken, nToken);
96759
96760 if( iEnd<n && z[iEnd]=='*' ){
96761 pRet->pPhrase->aToken[0].isPrefix = 1;
96762 iEnd++;
96763 }
96764 if( !sqlite3_fts3_enable_parentheses && iStart>0 && z[iStart-1]=='-' ){
96765 pRet->pPhrase->isNot = 1;
96766 }
96767 }
96768 }
96769 nConsumed = iEnd;
96770
96771 pModule->xClose(pCursor);
96772 }
96773
96774 *pnConsumed = nConsumed;
96775 *ppExpr = pRet;
96776 return rc;
96777 }
96778
96779
96780 /*
96781 ** Enlarge a memory allocation. If an out-of-memory allocation occurs,
96782 ** then free the old allocation.
96783 */
96784 void *fts3ReallocOrFree(void *pOrig, int nNew){
96785 void *pRet = sqlite3_realloc(pOrig, nNew);
96786 if( !pRet ){
96787 sqlite3_free(pOrig);
96788 }
96789 return pRet;
96790 }
96791
96792 /*
96793 ** Buffer zInput, length nInput, contains the contents of a quoted string
96794 ** that appeared as part of an fts3 query expression. Neither quote character
96795 ** is included in the buffer. This function attempts to tokenize the entire
96796 ** input buffer and create an Fts3Expr structure of type FTSQUERY_PHRASE
96797 ** containing the results.
96798 **
96799 ** If successful, SQLITE_OK is returned and *ppExpr set to point at the
96800 ** allocated Fts3Expr structure. Otherwise, either SQLITE_NOMEM (out of memory
96801 ** error) or SQLITE_ERROR (tokenization error) is returned and *ppExpr set
96802 ** to 0.
96803 */
96804 static int getNextString(
96805 ParseContext *pParse, /* fts3 query parse context */
96806 const char *zInput, int nInput, /* Input string */
96807 Fts3Expr **ppExpr /* OUT: expression */
96808 ){
96809 sqlite3_tokenizer *pTokenizer = pParse->pTokenizer;
96810 sqlite3_tokenizer_module const *pModule = pTokenizer->pModule;
96811 int rc;
96812 Fts3Expr *p = 0;
96813 sqlite3_tokenizer_cursor *pCursor = 0;
96814 char *zTemp = 0;
96815 int nTemp = 0;
96816
96817 rc = pModule->xOpen(pTokenizer, zInput, nInput, &pCursor);
96818 if( rc==SQLITE_OK ){
96819 int ii;
96820 pCursor->pTokenizer = pTokenizer;
96821 for(ii=0; rc==SQLITE_OK; ii++){
96822 const char *zToken;
96823 int nToken, iBegin, iEnd, iPos;
96824 rc = pModule->xNext(pCursor, &zToken, &nToken, &iBegin, &iEnd, &iPos);
96825 if( rc==SQLITE_OK ){
96826 int nByte = sizeof(Fts3Expr) + sizeof(Fts3Phrase);
96827 p = fts3ReallocOrFree(p, nByte+ii*sizeof(struct PhraseToken));
96828 zTemp = fts3ReallocOrFree(zTemp, nTemp + nToken);
96829 if( !p || !zTemp ){
96830 goto no_mem;
96831 }
96832 if( ii==0 ){
96833 memset(p, 0, nByte);
96834 p->pPhrase = (Fts3Phrase *)&p[1];
96835 p->eType = FTSQUERY_PHRASE;
96836 p->pPhrase->iColumn = pParse->iDefaultCol;
96837 }
96838 p->pPhrase = (Fts3Phrase *)&p[1];
96839 p->pPhrase->nToken = ii+1;
96840 p->pPhrase->aToken[ii].n = nToken;
96841 memcpy(&zTemp[nTemp], zToken, nToken);
96842 nTemp += nToken;
96843 if( iEnd<nInput && zInput[iEnd]=='*' ){
96844 p->pPhrase->aToken[ii].isPrefix = 1;
96845 }else{
96846 p->pPhrase->aToken[ii].isPrefix = 0;
96847 }
96848 }
96849 }
96850
96851 pModule->xClose(pCursor);
96852 pCursor = 0;
96853 }
96854
96855 if( rc==SQLITE_DONE ){
96856 int jj;
96857 char *zNew;
96858 int nNew = 0;
96859 int nByte = sizeof(Fts3Expr) + sizeof(Fts3Phrase);
96860 nByte += (p->pPhrase->nToken-1) * sizeof(struct PhraseToken);
96861 p = fts3ReallocOrFree(p, nByte + nTemp);
96862 if( !p ){
96863 goto no_mem;
96864 }
96865 p->pPhrase = (Fts3Phrase *)&p[1];
96866 zNew = &(((char *)p)[nByte]);
96867 memcpy(zNew, zTemp, nTemp);
96868 for(jj=0; jj<p->pPhrase->nToken; jj++){
96869 p->pPhrase->aToken[jj].z = &zNew[nNew];
96870 nNew += p->pPhrase->aToken[jj].n;
96871 }
96872 sqlite3_free(zTemp);
96873 rc = SQLITE_OK;
96874 }
96875
96876 *ppExpr = p;
96877 return rc;
96878 no_mem:
96879
96880 if( pCursor ){
96881 pModule->xClose(pCursor);
96882 }
96883 sqlite3_free(zTemp);
96884 sqlite3_free(p);
96885 *ppExpr = 0;
96886 return SQLITE_NOMEM;
96887 }
96888
96889 /*
96890 ** Function getNextNode(), which is called by fts3ExprParse(), may itself
96891 ** call fts3ExprParse(). So this forward declaration is required.
96892 */
96893 static int fts3ExprParse(ParseContext *, const char *, int, Fts3Expr **, int *);
96894
96895 /*
96896 ** The output variable *ppExpr is populated with an allocated Fts3Expr
96897 ** structure, or set to 0 if the end of the input buffer is reached.
96898 **
96899 ** Returns an SQLite error code. SQLITE_OK if everything works, SQLITE_NOMEM
96900 ** if a malloc failure occurs, or SQLITE_ERROR if a parse error is encountered.
96901 ** If SQLITE_ERROR is returned, pContext is populated with an error message.
96902 */
96903 static int getNextNode(
96904 ParseContext *pParse, /* fts3 query parse context */
96905 const char *z, int n, /* Input string */
96906 Fts3Expr **ppExpr, /* OUT: expression */
96907 int *pnConsumed /* OUT: Number of bytes consumed */
96908 ){
96909 static const struct Fts3Keyword {
96910 char z[4]; /* Keyword text */
96911 unsigned char n; /* Length of the keyword */
96912 unsigned char parenOnly; /* Only valid in paren mode */
96913 unsigned char eType; /* Keyword code */
96914 } aKeyword[] = {
96915 { "OR" , 2, 0, FTSQUERY_OR },
96916 { "AND", 3, 1, FTSQUERY_AND },
96917 { "NOT", 3, 1, FTSQUERY_NOT },
96918 { "NEAR", 4, 0, FTSQUERY_NEAR }
96919 };
96920 int ii;
96921 int iCol;
96922 int iColLen;
96923 int rc;
96924 Fts3Expr *pRet = 0;
96925
96926 const char *zInput = z;
96927 int nInput = n;
96928
96929 /* Skip over any whitespace before checking for a keyword, an open or
96930 ** close bracket, or a quoted string.
96931 */
96932 while( nInput>0 && fts3isspace(*zInput) ){
96933 nInput--;
96934 zInput++;
96935 }
96936 if( nInput==0 ){
96937 return SQLITE_DONE;
96938 }
96939
96940 /* See if we are dealing with a keyword. */
96941 for(ii=0; ii<(int)(sizeof(aKeyword)/sizeof(struct Fts3Keyword)); ii++){
96942 const struct Fts3Keyword *pKey = &aKeyword[ii];
96943
96944 if( (pKey->parenOnly & ~sqlite3_fts3_enable_parentheses)!=0 ){
96945 continue;
96946 }
96947
96948 if( nInput>=pKey->n && 0==memcmp(zInput, pKey->z, pKey->n) ){
96949 int nNear = SQLITE_FTS3_DEFAULT_NEAR_PARAM;
96950 int nKey = pKey->n;
96951 char cNext;
96952
96953 /* If this is a "NEAR" keyword, check for an explicit nearness. */
96954 if( pKey->eType==FTSQUERY_NEAR ){
96955 assert( nKey==4 );
96956 if( zInput[4]=='/' && zInput[5]>='0' && zInput[5]<='9' ){
96957 nNear = 0;
96958 for(nKey=5; zInput[nKey]>='0' && zInput[nKey]<='9'; nKey++){
96959 nNear = nNear * 10 + (zInput[nKey] - '0');
96960 }
96961 }
96962 }
96963
96964 /* At this point this is probably a keyword. But for that to be true,
96965 ** the next byte must contain either whitespace, an open or close
96966 ** parenthesis, a quote character, or EOF.
96967 */
96968 cNext = zInput[nKey];
96969 if( fts3isspace(cNext)
96970 || cNext=='"' || cNext=='(' || cNext==')' || cNext==0
96971 ){
96972 pRet = (Fts3Expr *)sqlite3_malloc(sizeof(Fts3Expr));
96973 memset(pRet, 0, sizeof(Fts3Expr));
96974 pRet->eType = pKey->eType;
96975 pRet->nNear = nNear;
96976 *ppExpr = pRet;
96977 *pnConsumed = (zInput - z) + nKey;
96978 return SQLITE_OK;
96979 }
96980
96981 /* Turns out that wasn't a keyword after all. This happens if the
96982 ** user has supplied a token such as "ORacle". Continue.
96983 */
96984 }
96985 }
96986
96987 /* Check for an open bracket. */
96988 if( sqlite3_fts3_enable_parentheses ){
96989 if( *zInput=='(' ){
96990 int nConsumed;
96991 int rc;
96992 pParse->nNest++;
96993 rc = fts3ExprParse(pParse, &zInput[1], nInput-1, ppExpr, &nConsumed);
96994 if( rc==SQLITE_OK && !*ppExpr ){
96995 rc = SQLITE_DONE;
96996 }
96997 *pnConsumed = (zInput - z) + 1 + nConsumed;
96998 return rc;
96999 }
97000
97001 /* Check for a close bracket. */
97002 if( *zInput==')' ){
97003 pParse->nNest--;
97004 *pnConsumed = (zInput - z) + 1;
97005 return SQLITE_DONE;
97006 }
97007 }
97008
97009 /* See if we are dealing with a quoted phrase. If this is the case, then
97010 ** search for the closing quote and pass the whole string to getNextString()
97011 ** for processing. This is easy to do, as fts3 has no syntax for escaping
97012 ** a quote character embedded in a string.
97013 */
97014 if( *zInput=='"' ){
97015 for(ii=1; ii<nInput && zInput[ii]!='"'; ii++);
97016 *pnConsumed = (zInput - z) + ii + 1;
97017 if( ii==nInput ){
97018 return SQLITE_ERROR;
97019 }
97020 return getNextString(pParse, &zInput[1], ii-1, ppExpr);
97021 }
97022
97023
97024 /* If control flows to this point, this must be a regular token, or
97025 ** the end of the input. Read a regular token using the sqlite3_tokenizer
97026 ** interface. Before doing so, figure out if there is an explicit
97027 ** column specifier for the token.
97028 **
97029 ** TODO: Strangely, it is not possible to associate a column specifier
97030 ** with a quoted phrase, only with a single token. Not sure if this was
97031 ** an implementation artifact or an intentional decision when fts3 was
97032 ** first implemented. Whichever it was, this module duplicates the
97033 ** limitation.
97034 */
97035 iCol = pParse->iDefaultCol;
97036 iColLen = 0;
97037 for(ii=0; ii<pParse->nCol; ii++){
97038 const char *zStr = pParse->azCol[ii];
97039 int nStr = strlen(zStr);
97040 if( nInput>nStr && zInput[nStr]==':' && memcmp(zStr, zInput, nStr)==0 ){
97041 iCol = ii;
97042 iColLen = ((zInput - z) + nStr + 1);
97043 break;
97044 }
97045 }
97046 rc = getNextToken(pParse, iCol, &z[iColLen], n-iColLen, ppExpr, pnConsumed);
97047 *pnConsumed += iColLen;
97048 return rc;
97049 }
97050
97051 /*
97052 ** The argument is an Fts3Expr structure for a binary operator (any type
97053 ** except an FTSQUERY_PHRASE). Return an integer value representing the
97054 ** precedence of the operator. Lower values have a higher precedence (i.e.
97055 ** group more tightly). For example, in the C language, the == operator
97056 ** groups more tightly than ||, and would therefore have a higher precedence.
97057 **
97058 ** When using the new fts3 query syntax (when SQLITE_ENABLE_FTS3_PARENTHESIS
97059 ** is defined), the order of the operators in precedence from highest to
97060 ** lowest is:
97061 **
97062 ** NEAR
97063 ** NOT
97064 ** AND (including implicit ANDs)
97065 ** OR
97066 **
97067 ** Note that when using the old query syntax, the OR operator has a higher
97068 ** precedence than the AND operator.
97069 */
97070 static int opPrecedence(Fts3Expr *p){
97071 assert( p->eType!=FTSQUERY_PHRASE );
97072 if( sqlite3_fts3_enable_parentheses ){
97073 return p->eType;
97074 }else if( p->eType==FTSQUERY_NEAR ){
97075 return 1;
97076 }else if( p->eType==FTSQUERY_OR ){
97077 return 2;
97078 }
97079 assert( p->eType==FTSQUERY_AND );
97080 return 3;
97081 }
97082
97083 /*
97084 ** Argument ppHead contains a pointer to the current head of a query
97085 ** expression tree being parsed. pPrev is the expression node most recently
97086 ** inserted into the tree. This function adds pNew, which is always a binary
97087 ** operator node, into the expression tree based on the relative precedence
97088 ** of pNew and the existing nodes of the tree. This may result in the head
97089 ** of the tree changing, in which case *ppHead is set to the new root node.
97090 */
97091 static void insertBinaryOperator(
97092 Fts3Expr **ppHead, /* Pointer to the root node of a tree */
97093 Fts3Expr *pPrev, /* Node most recently inserted into the tree */
97094 Fts3Expr *pNew /* New binary node to insert into expression tree */
97095 ){
97096 Fts3Expr *pSplit = pPrev;
97097 while( pSplit->pParent && opPrecedence(pSplit->pParent)<=opPrecedence(pNew) ){
97098 pSplit = pSplit->pParent;
97099 }
97100
97101 if( pSplit->pParent ){
97102 assert( pSplit->pParent->pRight==pSplit );
97103 pSplit->pParent->pRight = pNew;
97104 pNew->pParent = pSplit->pParent;
97105 }else{
97106 *ppHead = pNew;
97107 }
97108 pNew->pLeft = pSplit;
97109 pSplit->pParent = pNew;
97110 }
97111
97112 /*
97113 ** Parse the fts3 query expression found in buffer z, length n. This function
97114 ** returns either when the end of the buffer is reached or an unmatched
97115 ** closing bracket - ')' - is encountered.
97116 **
97117 ** If successful, SQLITE_OK is returned, *ppExpr is set to point to the
97118 ** parsed form of the expression and *pnConsumed is set to the number of
97119 ** bytes read from buffer z. Otherwise, *ppExpr is set to 0 and SQLITE_NOMEM
97120 ** (out of memory error) or SQLITE_ERROR (parse error) is returned.
97121 */
97122 static int fts3ExprParse(
97123 ParseContext *pParse, /* fts3 query parse context */
97124 const char *z, int n, /* Text of MATCH query */
97125 Fts3Expr **ppExpr, /* OUT: Parsed query structure */
97126 int *pnConsumed /* OUT: Number of bytes consumed */
97127 ){
97128 Fts3Expr *pRet = 0;
97129 Fts3Expr *pPrev = 0;
97130 Fts3Expr *pNotBranch = 0; /* Only used in legacy parse mode */
97131 int nIn = n;
97132 const char *zIn = z;
97133 int rc = SQLITE_OK;
97134 int isRequirePhrase = 1;
97135
97136 while( rc==SQLITE_OK ){
97137 Fts3Expr *p = 0;
97138 int nByte = 0;
97139 rc = getNextNode(pParse, zIn, nIn, &p, &nByte);
97140 if( rc==SQLITE_OK ){
97141 int isPhrase;
97142
97143 if( !sqlite3_fts3_enable_parentheses
97144 && p->eType==FTSQUERY_PHRASE && p->pPhrase->isNot
97145 ){
97146 /* Create an implicit NOT operator. */
97147 Fts3Expr *pNot = sqlite3_malloc(sizeof(Fts3Expr));
97148 if( !pNot ){
97149 sqlite3Fts3ExprFree(p);
97150 rc = SQLITE_NOMEM;
97151 goto exprparse_out;
97152 }
97153 memset(pNot, 0, sizeof(Fts3Expr));
97154 pNot->eType = FTSQUERY_NOT;
97155 pNot->pRight = p;
97156 if( pNotBranch ){
97157 pNotBranch->pLeft = p;
97158 pNot->pRight = pNotBranch;
97159 }
97160 pNotBranch = pNot;
97161 }else{
97162 int eType = p->eType;
97163 assert( eType!=FTSQUERY_PHRASE || !p->pPhrase->isNot );
97164 isPhrase = (eType==FTSQUERY_PHRASE || p->pLeft);
97165
97166 /* The isRequirePhrase variable is set to true if a phrase or
97167 ** an expression contained in parenthesis is required. If a
97168 ** binary operator (AND, OR, NOT or NEAR) is encounted when
97169 ** isRequirePhrase is set, this is a syntax error.
97170 */
97171 if( !isPhrase && isRequirePhrase ){
97172 sqlite3Fts3ExprFree(p);
97173 rc = SQLITE_ERROR;
97174 goto exprparse_out;
97175 }
97176
97177 if( isPhrase && !isRequirePhrase ){
97178 /* Insert an implicit AND operator. */
97179 Fts3Expr *pAnd;
97180 assert( pRet && pPrev );
97181 pAnd = sqlite3_malloc(sizeof(Fts3Expr));
97182 if( !pAnd ){
97183 sqlite3Fts3ExprFree(p);
97184 rc = SQLITE_NOMEM;
97185 goto exprparse_out;
97186 }
97187 memset(pAnd, 0, sizeof(Fts3Expr));
97188 pAnd->eType = FTSQUERY_AND;
97189 insertBinaryOperator(&pRet, pPrev, pAnd);
97190 pPrev = pAnd;
97191 }
97192
97193 /* This test catches attempts to make either operand of a NEAR
97194 ** operator something other than a phrase. For example, either of
97195 ** the following:
97196 **
97197 ** (bracketed expression) NEAR phrase
97198 ** phrase NEAR (bracketed expression)
97199 **
97200 ** Return an error in either case.
97201 */
97202 if( pPrev && (
97203 (eType==FTSQUERY_NEAR && !isPhrase && pPrev->eType!=FTSQUERY_PHRASE)
97204 || (eType!=FTSQUERY_PHRASE && isPhrase && pPrev->eType==FTSQUERY_NEAR)
97205 )){
97206 sqlite3Fts3ExprFree(p);
97207 rc = SQLITE_ERROR;
97208 goto exprparse_out;
97209 }
97210
97211 if( isPhrase ){
97212 if( pRet ){
97213 assert( pPrev && pPrev->pLeft && pPrev->pRight==0 );
97214 pPrev->pRight = p;
97215 p->pParent = pPrev;
97216 }else{
97217 pRet = p;
97218 }
97219 }else{
97220 insertBinaryOperator(&pRet, pPrev, p);
97221 }
97222 isRequirePhrase = !isPhrase;
97223 }
97224 assert( nByte>0 );
97225 }
97226 assert( rc!=SQLITE_OK || (nByte>0 && nByte<=nIn) );
97227 nIn -= nByte;
97228 zIn += nByte;
97229 pPrev = p;
97230 }
97231
97232 if( rc==SQLITE_DONE && pRet && isRequirePhrase ){
97233 rc = SQLITE_ERROR;
97234 }
97235
97236 if( rc==SQLITE_DONE ){
97237 rc = SQLITE_OK;
97238 if( !sqlite3_fts3_enable_parentheses && pNotBranch ){
97239 if( !pRet ){
97240 rc = SQLITE_ERROR;
97241 }else{
97242 pNotBranch->pLeft = pRet;
97243 pRet = pNotBranch;
97244 }
97245 }
97246 }
97247 *pnConsumed = n - nIn;
97248
97249 exprparse_out:
97250 if( rc!=SQLITE_OK ){
97251 sqlite3Fts3ExprFree(pRet);
97252 sqlite3Fts3ExprFree(pNotBranch);
97253 pRet = 0;
97254 }
97255 *ppExpr = pRet;
97256 return rc;
97257 }
97258
97259 /*
97260 ** Parameters z and n contain a pointer to and length of a buffer containing
97261 ** an fts3 query expression, respectively. This function attempts to parse the
97262 ** query expression and create a tree of Fts3Expr structures representing the
97263 ** parsed expression. If successful, *ppExpr is set to point to the head
97264 ** of the parsed expression tree and SQLITE_OK is returned. If an error
97265 ** occurs, either SQLITE_NOMEM (out-of-memory error) or SQLITE_ERROR (parse
97266 ** error) is returned and *ppExpr is set to 0.
97267 **
97268 ** If parameter n is a negative number, then z is assumed to point to a
97269 ** nul-terminated string and the length is determined using strlen().
97270 **
97271 ** The first parameter, pTokenizer, is passed the fts3 tokenizer module to
97272 ** use to normalize query tokens while parsing the expression. The azCol[]
97273 ** array, which is assumed to contain nCol entries, should contain the names
97274 ** of each column in the target fts3 table, in order from left to right.
97275 ** Column names must be nul-terminated strings.
97276 **
97277 ** The iDefaultCol parameter should be passed the index of the table column
97278 ** that appears on the left-hand-side of the MATCH operator (the default
97279 ** column to match against for tokens for which a column name is not explicitly
97280 ** specified as part of the query string), or -1 if tokens may by default
97281 ** match any table column.
97282 */
97283 SQLITE_PRIVATE int sqlite3Fts3ExprParse(
97284 sqlite3_tokenizer *pTokenizer, /* Tokenizer module */
97285 char **azCol, /* Array of column names for fts3 table */
97286 int nCol, /* Number of entries in azCol[] */
97287 int iDefaultCol, /* Default column to query */
97288 const char *z, int n, /* Text of MATCH query */
97289 Fts3Expr **ppExpr /* OUT: Parsed query structure */
97290 ){
97291 int nParsed;
97292 int rc;
97293 ParseContext sParse;
97294 sParse.pTokenizer = pTokenizer;
97295 sParse.azCol = (const char **)azCol;
97296 sParse.nCol = nCol;
97297 sParse.iDefaultCol = iDefaultCol;
97298 sParse.nNest = 0;
97299 if( z==0 ){
97300 *ppExpr = 0;
97301 return SQLITE_OK;
97302 }
97303 if( n<0 ){
97304 n = strlen(z);
97305 }
97306 rc = fts3ExprParse(&sParse, z, n, ppExpr, &nParsed);
97307
97308 /* Check for mismatched parenthesis */
97309 if( rc==SQLITE_OK && sParse.nNest ){
97310 rc = SQLITE_ERROR;
97311 sqlite3Fts3ExprFree(*ppExpr);
97312 *ppExpr = 0;
97313 }
97314
97315 return rc;
97316 }
97317
97318 /*
97319 ** Free a parsed fts3 query expression allocated by sqlite3Fts3ExprParse().
97320 */
97321 SQLITE_PRIVATE void sqlite3Fts3ExprFree(Fts3Expr *p){
97322 if( p ){
97323 sqlite3Fts3ExprFree(p->pLeft);
97324 sqlite3Fts3ExprFree(p->pRight);
97325 sqlite3_free(p);
97326 }
97327 }
97328
97329 /****************************************************************************
97330 *****************************************************************************
97331 ** Everything after this point is just test code.
97332 */
97333
97334 #ifdef SQLITE_TEST
97335
97336
97337 /*
97338 ** Function to query the hash-table of tokenizers (see README.tokenizers).
97339 */
97340 static int queryTestTokenizer(
97341 sqlite3 *db,
97342 const char *zName,
97343 const sqlite3_tokenizer_module **pp
97344 ){
97345 int rc;
97346 sqlite3_stmt *pStmt;
97347 const char zSql[] = "SELECT fts3_tokenizer(?)";
97348
97349 *pp = 0;
97350 rc = sqlite3_prepare_v2(db, zSql, -1, &pStmt, 0);
97351 if( rc!=SQLITE_OK ){
97352 return rc;
97353 }
97354
97355 sqlite3_bind_text(pStmt, 1, zName, -1, SQLITE_STATIC);
97356 if( SQLITE_ROW==sqlite3_step(pStmt) ){
97357 if( sqlite3_column_type(pStmt, 0)==SQLITE_BLOB ){
97358 memcpy(pp, sqlite3_column_blob(pStmt, 0), sizeof(*pp));
97359 }
97360 }
97361
97362 return sqlite3_finalize(pStmt);
97363 }
97364
97365 /*
97366 ** This function is part of the test interface for the query parser. It
97367 ** writes a text representation of the query expression pExpr into the
97368 ** buffer pointed to by argument zBuf. It is assumed that zBuf is large
97369 ** enough to store the required text representation.
97370 */
97371 static void exprToString(Fts3Expr *pExpr, char *zBuf){
97372 switch( pExpr->eType ){
97373 case FTSQUERY_PHRASE: {
97374 Fts3Phrase *pPhrase = pExpr->pPhrase;
97375 int i;
97376 zBuf += sprintf(zBuf, "PHRASE %d %d", pPhrase->iColumn, pPhrase->isNot);
97377 for(i=0; i<pPhrase->nToken; i++){
97378 zBuf += sprintf(zBuf," %.*s",pPhrase->aToken[i].n,pPhrase->aToken[i].z);
97379 zBuf += sprintf(zBuf,"%s", (pPhrase->aToken[i].isPrefix?"+":""));
97380 }
97381 return;
97382 }
97383
97384 case FTSQUERY_NEAR:
97385 zBuf += sprintf(zBuf, "NEAR/%d ", pExpr->nNear);
97386 break;
97387 case FTSQUERY_NOT:
97388 zBuf += sprintf(zBuf, "NOT ");
97389 break;
97390 case FTSQUERY_AND:
97391 zBuf += sprintf(zBuf, "AND ");
97392 break;
97393 case FTSQUERY_OR:
97394 zBuf += sprintf(zBuf, "OR ");
97395 break;
97396 }
97397
97398 zBuf += sprintf(zBuf, "{");
97399 exprToString(pExpr->pLeft, zBuf);
97400 zBuf += strlen(zBuf);
97401 zBuf += sprintf(zBuf, "} ");
97402
97403 zBuf += sprintf(zBuf, "{");
97404 exprToString(pExpr->pRight, zBuf);
97405 zBuf += strlen(zBuf);
97406 zBuf += sprintf(zBuf, "}");
97407 }
97408
97409 /*
97410 ** This is the implementation of a scalar SQL function used to test the
97411 ** expression parser. It should be called as follows:
97412 **
97413 ** fts3_exprtest(<tokenizer>, <expr>, <column 1>, ...);
97414 **
97415 ** The first argument, <tokenizer>, is the name of the fts3 tokenizer used
97416 ** to parse the query expression (see README.tokenizers). The second argument
97417 ** is the query expression to parse. Each subsequent argument is the name
97418 ** of a column of the fts3 table that the query expression may refer to.
97419 ** For example:
97420 **
97421 ** SELECT fts3_exprtest('simple', 'Bill col2:Bloggs', 'col1', 'col2');
97422 */
97423 static void fts3ExprTest(
97424 sqlite3_context *context,
97425 int argc,
97426 sqlite3_value **argv
97427 ){
97428 sqlite3_tokenizer_module const *pModule = 0;
97429 sqlite3_tokenizer *pTokenizer = 0;
97430 int rc;
97431 char **azCol = 0;
97432 const char *zExpr;
97433 int nExpr;
97434 int nCol;
97435 int ii;
97436 Fts3Expr *pExpr;
97437 sqlite3 *db = sqlite3_context_db_handle(context);
97438
97439 if( argc<3 ){
97440 sqlite3_result_error(context,
97441 "Usage: fts3_exprtest(tokenizer, expr, col1, ...", -1
97442 );
97443 return;
97444 }
97445
97446 rc = queryTestTokenizer(db,
97447 (const char *)sqlite3_value_text(argv[0]), &pModule);
97448 if( rc==SQLITE_NOMEM ){
97449 sqlite3_result_error_nomem(context);
97450 goto exprtest_out;
97451 }else if( !pModule ){
97452 sqlite3_result_error(context, "No such tokenizer module", -1);
97453 goto exprtest_out;
97454 }
97455
97456 rc = pModule->xCreate(0, 0, &pTokenizer);
97457 assert( rc==SQLITE_NOMEM || rc==SQLITE_OK );
97458 if( rc==SQLITE_NOMEM ){
97459 sqlite3_result_error_nomem(context);
97460 goto exprtest_out;
97461 }
97462 pTokenizer->pModule = pModule;
97463
97464 zExpr = (const char *)sqlite3_value_text(argv[1]);
97465 nExpr = sqlite3_value_bytes(argv[1]);
97466 nCol = argc-2;
97467 azCol = (char **)sqlite3_malloc(nCol*sizeof(char *));
97468 if( !azCol ){
97469 sqlite3_result_error_nomem(context);
97470 goto exprtest_out;
97471 }
97472 for(ii=0; ii<nCol; ii++){
97473 azCol[ii] = (char *)sqlite3_value_text(argv[ii+2]);
97474 }
97475
97476 rc = sqlite3Fts3ExprParse(
97477 pTokenizer, azCol, nCol, nCol, zExpr, nExpr, &pExpr
97478 );
97479 if( rc==SQLITE_NOMEM ){
97480 sqlite3_result_error_nomem(context);
97481 goto exprtest_out;
97482 }else if( rc==SQLITE_OK ){
97483 char zBuf[4096];
97484 exprToString(pExpr, zBuf);
97485 sqlite3_result_text(context, zBuf, -1, SQLITE_TRANSIENT);
97486 sqlite3Fts3ExprFree(pExpr);
97487 }else{
97488 sqlite3_result_error(context, "Error parsing expression", -1);
97489 }
97490
97491 exprtest_out:
97492 if( pModule && pTokenizer ){
97493 rc = pModule->xDestroy(pTokenizer);
97494 }
97495 sqlite3_free(azCol);
97496 }
97497
97498 /*
97499 ** Register the query expression parser test function fts3_exprtest()
97500 ** with database connection db.
97501 */
97502 SQLITE_PRIVATE void sqlite3Fts3ExprInitTestInterface(sqlite3* db){
97503 sqlite3_create_function(
97504 db, "fts3_exprtest", -1, SQLITE_UTF8, 0, fts3ExprTest, 0, 0
97505 );
97506 }
97507
97508 #endif
97509 #endif /* !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_FTS3) */
97510
97511 /************** End of fts3_expr.c *******************************************/
97512 /************** Begin file fts3_hash.c ***************************************/
97513 /*
97514 ** 2001 September 22
97515 **
97516 ** The author disclaims copyright to this source code. In place of
@@ -97114,11 +99127,11 @@
99127 **
99128 *************************************************************************
99129 ** This file contains code for implementations of the r-tree and r*-tree
99130 ** algorithms packaged as an SQLite virtual table module.
99131 **
99132 ** $Id: rtree.c,v 1.12 2008/12/22 15:04:32 danielk1977 Exp $
99133 */
99134
99135 #if !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_RTREE)
99136
99137 /*
@@ -97498,11 +99511,12 @@
99511 /* Check if the requested node is already in the hash table. If so,
99512 ** increase its reference count and return it.
99513 */
99514 if( (pNode = nodeHashLookup(pRtree, iNode)) ){
99515 assert( !pParent || !pNode->pParent || pNode->pParent==pParent );
99516 if( pParent && !pNode->pParent ){
99517 nodeReference(pParent);
99518 pNode->pParent = pParent;
99519 }
99520 pNode->nRef++;
99521 *ppNode = pNode;
99522 return SQLITE_OK;
99523
+5 -4
--- src/sqlite3.h
+++ src/sqlite3.h
@@ -28,11 +28,11 @@
2828
** The name of this file under configuration management is "sqlite.h.in".
2929
** The makefile makes some minor changes to this file (such as inserting
3030
** the version number) and changes its name to "sqlite3.h" as
3131
** part of the build process.
3232
**
33
-** @(#) $Id: sqlite.h.in,v 1.420 2008/12/16 13:46:30 drh Exp $
33
+** @(#) $Id: sqlite.h.in,v 1.421 2008/12/30 06:24:58 danielk1977 Exp $
3434
*/
3535
#ifndef _SQLITE3_H_
3636
#define _SQLITE3_H_
3737
#include <stdarg.h> /* Needed for the definition of va_list */
3838
@@ -105,12 +105,12 @@
105105
**
106106
** {H10014} The SQLITE_VERSION_NUMBER #define shall resolve to an integer
107107
** with the value (X*1000000 + Y*1000 + Z) where X, Y, and Z
108108
** are the major version, minor version, and release number.
109109
*/
110
-#define SQLITE_VERSION "3.6.7"
111
-#define SQLITE_VERSION_NUMBER 3006007
110
+#define SQLITE_VERSION "3.6.8"
111
+#define SQLITE_VERSION_NUMBER 3006008
112112
113113
/*
114114
** CAPI3REF: Run-Time Library Version Numbers {H10020} <S60100>
115115
** KEYWORDS: sqlite3_version
116116
**
@@ -2395,20 +2395,21 @@
23952395
#define SQLITE_DROP_VIEW 17 /* View Name NULL */
23962396
#define SQLITE_INSERT 18 /* Table Name NULL */
23972397
#define SQLITE_PRAGMA 19 /* Pragma Name 1st arg or NULL */
23982398
#define SQLITE_READ 20 /* Table Name Column Name */
23992399
#define SQLITE_SELECT 21 /* NULL NULL */
2400
-#define SQLITE_TRANSACTION 22 /* NULL NULL */
2400
+#define SQLITE_TRANSACTION 22 /* Operation NULL */
24012401
#define SQLITE_UPDATE 23 /* Table Name Column Name */
24022402
#define SQLITE_ATTACH 24 /* Filename NULL */
24032403
#define SQLITE_DETACH 25 /* Database Name NULL */
24042404
#define SQLITE_ALTER_TABLE 26 /* Database Name Table Name */
24052405
#define SQLITE_REINDEX 27 /* Index Name NULL */
24062406
#define SQLITE_ANALYZE 28 /* Table Name NULL */
24072407
#define SQLITE_CREATE_VTABLE 29 /* Table Name Module Name */
24082408
#define SQLITE_DROP_VTABLE 30 /* Table Name Module Name */
24092409
#define SQLITE_FUNCTION 31 /* NULL Function Name */
2410
+#define SQLITE_SAVEPOINT 32 /* Operation Savepoint Name */
24102411
#define SQLITE_COPY 0 /* No longer used */
24112412
24122413
/*
24132414
** CAPI3REF: Tracing And Profiling Functions {H12280} <S60400>
24142415
** EXPERIMENTAL
24152416
--- src/sqlite3.h
+++ src/sqlite3.h
@@ -28,11 +28,11 @@
28 ** The name of this file under configuration management is "sqlite.h.in".
29 ** The makefile makes some minor changes to this file (such as inserting
30 ** the version number) and changes its name to "sqlite3.h" as
31 ** part of the build process.
32 **
33 ** @(#) $Id: sqlite.h.in,v 1.420 2008/12/16 13:46:30 drh Exp $
34 */
35 #ifndef _SQLITE3_H_
36 #define _SQLITE3_H_
37 #include <stdarg.h> /* Needed for the definition of va_list */
38
@@ -105,12 +105,12 @@
105 **
106 ** {H10014} The SQLITE_VERSION_NUMBER #define shall resolve to an integer
107 ** with the value (X*1000000 + Y*1000 + Z) where X, Y, and Z
108 ** are the major version, minor version, and release number.
109 */
110 #define SQLITE_VERSION "3.6.7"
111 #define SQLITE_VERSION_NUMBER 3006007
112
113 /*
114 ** CAPI3REF: Run-Time Library Version Numbers {H10020} <S60100>
115 ** KEYWORDS: sqlite3_version
116 **
@@ -2395,20 +2395,21 @@
2395 #define SQLITE_DROP_VIEW 17 /* View Name NULL */
2396 #define SQLITE_INSERT 18 /* Table Name NULL */
2397 #define SQLITE_PRAGMA 19 /* Pragma Name 1st arg or NULL */
2398 #define SQLITE_READ 20 /* Table Name Column Name */
2399 #define SQLITE_SELECT 21 /* NULL NULL */
2400 #define SQLITE_TRANSACTION 22 /* NULL NULL */
2401 #define SQLITE_UPDATE 23 /* Table Name Column Name */
2402 #define SQLITE_ATTACH 24 /* Filename NULL */
2403 #define SQLITE_DETACH 25 /* Database Name NULL */
2404 #define SQLITE_ALTER_TABLE 26 /* Database Name Table Name */
2405 #define SQLITE_REINDEX 27 /* Index Name NULL */
2406 #define SQLITE_ANALYZE 28 /* Table Name NULL */
2407 #define SQLITE_CREATE_VTABLE 29 /* Table Name Module Name */
2408 #define SQLITE_DROP_VTABLE 30 /* Table Name Module Name */
2409 #define SQLITE_FUNCTION 31 /* NULL Function Name */
 
2410 #define SQLITE_COPY 0 /* No longer used */
2411
2412 /*
2413 ** CAPI3REF: Tracing And Profiling Functions {H12280} <S60400>
2414 ** EXPERIMENTAL
2415
--- src/sqlite3.h
+++ src/sqlite3.h
@@ -28,11 +28,11 @@
28 ** The name of this file under configuration management is "sqlite.h.in".
29 ** The makefile makes some minor changes to this file (such as inserting
30 ** the version number) and changes its name to "sqlite3.h" as
31 ** part of the build process.
32 **
33 ** @(#) $Id: sqlite.h.in,v 1.421 2008/12/30 06:24:58 danielk1977 Exp $
34 */
35 #ifndef _SQLITE3_H_
36 #define _SQLITE3_H_
37 #include <stdarg.h> /* Needed for the definition of va_list */
38
@@ -105,12 +105,12 @@
105 **
106 ** {H10014} The SQLITE_VERSION_NUMBER #define shall resolve to an integer
107 ** with the value (X*1000000 + Y*1000 + Z) where X, Y, and Z
108 ** are the major version, minor version, and release number.
109 */
110 #define SQLITE_VERSION "3.6.8"
111 #define SQLITE_VERSION_NUMBER 3006008
112
113 /*
114 ** CAPI3REF: Run-Time Library Version Numbers {H10020} <S60100>
115 ** KEYWORDS: sqlite3_version
116 **
@@ -2395,20 +2395,21 @@
2395 #define SQLITE_DROP_VIEW 17 /* View Name NULL */
2396 #define SQLITE_INSERT 18 /* Table Name NULL */
2397 #define SQLITE_PRAGMA 19 /* Pragma Name 1st arg or NULL */
2398 #define SQLITE_READ 20 /* Table Name Column Name */
2399 #define SQLITE_SELECT 21 /* NULL NULL */
2400 #define SQLITE_TRANSACTION 22 /* Operation NULL */
2401 #define SQLITE_UPDATE 23 /* Table Name Column Name */
2402 #define SQLITE_ATTACH 24 /* Filename NULL */
2403 #define SQLITE_DETACH 25 /* Database Name NULL */
2404 #define SQLITE_ALTER_TABLE 26 /* Database Name Table Name */
2405 #define SQLITE_REINDEX 27 /* Index Name NULL */
2406 #define SQLITE_ANALYZE 28 /* Table Name NULL */
2407 #define SQLITE_CREATE_VTABLE 29 /* Table Name Module Name */
2408 #define SQLITE_DROP_VTABLE 30 /* Table Name Module Name */
2409 #define SQLITE_FUNCTION 31 /* NULL Function Name */
2410 #define SQLITE_SAVEPOINT 32 /* Operation Savepoint Name */
2411 #define SQLITE_COPY 0 /* No longer used */
2412
2413 /*
2414 ** CAPI3REF: Tracing And Profiling Functions {H12280} <S60400>
2415 ** EXPERIMENTAL
2416

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button