Wapp

Check-in [58675822f3]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Update the built-in SQLite to the latest 3.28.0 alpha.
Downloads: Tarball | ZIP archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 58675822f39b614a58f339847e4840d32a358553c9fd828e887b336c0bd909ac
User & Date: drh 2019-04-09 13:11:31.543
Context
2019-04-10
15:22
Improved JSON string literal encoding. (check-in: 4b187296d9 user: drh tags: trunk)
2019-04-09
13:11
Update the built-in SQLite to the latest 3.28.0 alpha. (check-in: 58675822f3 user: drh tags: trunk)
2019-04-08
20:14
For the %string() substitution, encode newlines and carriage returns using backslash escapes. (check-in: 6385090072 user: drh tags: trunk)
Changes
Side-by-Side Diff Ignore Whitespace Patch
Changes to tclsqlite3.c.
1
2
3
4

5
6
7
8
9
10
11
1
2
3

4
5
6
7
8
9
10
11



-
+







#ifndef USE_SYSTEM_SQLITE
/******************************************************************************
** This file is an amalgamation of many separate C source files from SQLite
** version 3.27.0.  By combining all the individual C code files into this
** version 3.28.0.  By combining all the individual C code files into this
** single large file, the entire code can be compiled as a single translation
** unit.  This allows many compilers to do optimizations that would not be
** possible if the files were compiled separately.  Performance improvements
** of 5% or more are commonly seen when SQLite is compiled as a single
** translation unit.
**
** This file is all you need to compile SQLite.  To use SQLite in other
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168



1169
1170
1171
1172
1173
1174
1175
1159
1160
1161
1162
1163
1164
1165



1166
1167
1168
1169
1170
1171
1172
1173
1174
1175







-
-
-
+
+
+







** been edited in any way since it was last checked in, then the last
** four hexadecimal digits of the hash may be modified.
**
** See also: [sqlite3_libversion()],
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
** [sqlite_version()] and [sqlite_source_id()].
*/
#define SQLITE_VERSION        "3.27.0"
#define SQLITE_VERSION_NUMBER 3027000
#define SQLITE_SOURCE_ID      "2019-02-05 20:51:41 4d0a949fd92e19fbf243a2e3a1a7c2cdb111f9a6943949d2420dd846bc7d9285"
#define SQLITE_VERSION        "3.28.0"
#define SQLITE_VERSION_NUMBER 3028000
#define SQLITE_SOURCE_ID      "2019-04-09 01:26:31 8820408597341344b308277ce6ef41b47c7514d6c613520789b05ee52cbedae8"

/*
** CAPI3REF: Run-Time Library Version Numbers
** KEYWORDS: sqlite3_version sqlite3_sourceid
**
** These interfaces provide the same information as the [SQLITE_VERSION],
** [SQLITE_VERSION_NUMBER], and [SQLITE_SOURCE_ID] C preprocessor macros
1225
1226
1227
1228
1229
1230
1231



1232
1233
1234
1235
1236
1237
1238
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241







+
+
+







**
** See also: SQL functions [sqlite_compileoption_used()] and
** [sqlite_compileoption_get()] and the [compile_options pragma].
*/
#ifndef SQLITE_OMIT_COMPILEOPTION_DIAGS
SQLITE_API int sqlite3_compileoption_used(const char *zOptName);
SQLITE_API const char *sqlite3_compileoption_get(int N);
#else
# define sqlite3_compileoption_used(X) 0
# define sqlite3_compileoption_get(X)  ((void*)0)
#endif

/*
** CAPI3REF: Test To See If The Library Is Threadsafe
**
** ^The sqlite3_threadsafe() function returns zero if and only if
** SQLite was compiled with mutexing code omitted due to the
3122
3123
3124
3125
3126
3127
3128
3129
3130


3131
3132
3133
3134
3135
3136
3137
3125
3126
3127
3128
3129
3130
3131


3132
3133
3134
3135
3136
3137
3138
3139
3140







-
-
+
+







** The second parameter is a pointer to an integer into which
** is written 0 or 1 to indicate whether triggers are disabled or enabled
** following this call.  The second parameter may be a NULL pointer, in
** which case the trigger setting is not reported back. </dd>
**
** [[SQLITE_DBCONFIG_ENABLE_FTS3_TOKENIZER]]
** <dt>SQLITE_DBCONFIG_ENABLE_FTS3_TOKENIZER</dt>
** <dd> ^This option is used to enable or disable the two-argument
** version of the [fts3_tokenizer()] function which is part of the
** <dd> ^This option is used to enable or disable the
** [fts3_tokenizer()] function which is part of the
** [FTS3] full-text search engine extension.
** There should be two additional arguments.
** The first argument is an integer which is 0 to disable fts3_tokenizer() or
** positive to enable fts3_tokenizer() or negative to leave the setting
** unchanged.
** The second parameter is a pointer to an integer into which
** is written 0 or 1 to indicate whether fts3_tokenizer is disabled or enabled
3235
3236
3237
3238
3239
3240
3241











3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254

3255

3256
3257
3258
3259
3260
3261
3262
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269

3270
3271
3272
3273
3274
3275
3276
3277







+
+
+
+
+
+
+
+
+
+
+













+
-
+







** features include but are not limited to the following:
** <ul>
** <li> The [PRAGMA writable_schema=ON] statement.
** <li> Writes to the [sqlite_dbpage] virtual table.
** <li> Direct writes to [shadow tables].
** </ul>
** </dd>
**
** [[SQLITE_DBCONFIG_WRITABLE_SCHEMA]] <dt>SQLITE_DBCONFIG_WRITABLE_SCHEMA</dt>
** <dd>The SQLITE_DBCONFIG_WRITABLE_SCHEMA option activates or deactivates the
** "writable_schema" flag. This has the same effect and is logically equivalent
** to setting [PRAGMA writable_schema=ON] or [PRAGMA writable_schema=OFF].
** The first argument to this setting is an integer which is 0 to disable 
** the writable_schema, positive to enable writable_schema, or negative to
** leave the setting unchanged. The second parameter is a pointer to an
** integer into which is written 0 or 1 to indicate whether the writable_schema
** is enabled or disabled following this call.
** </dd>
** </dl>
*/
#define SQLITE_DBCONFIG_MAINDBNAME            1000 /* const char* */
#define SQLITE_DBCONFIG_LOOKASIDE             1001 /* void* int int */
#define SQLITE_DBCONFIG_ENABLE_FKEY           1002 /* int int* */
#define SQLITE_DBCONFIG_ENABLE_TRIGGER        1003 /* int int* */
#define SQLITE_DBCONFIG_ENABLE_FTS3_TOKENIZER 1004 /* int int* */
#define SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION 1005 /* int int* */
#define SQLITE_DBCONFIG_NO_CKPT_ON_CLOSE      1006 /* int int* */
#define SQLITE_DBCONFIG_ENABLE_QPSG           1007 /* int int* */
#define SQLITE_DBCONFIG_TRIGGER_EQP           1008 /* int int* */
#define SQLITE_DBCONFIG_RESET_DATABASE        1009 /* int int* */
#define SQLITE_DBCONFIG_DEFENSIVE             1010 /* int int* */
#define SQLITE_DBCONFIG_WRITABLE_SCHEMA       1011 /* int int* */
#define SQLITE_DBCONFIG_MAX                   1010 /* Largest DBCONFIG */
#define SQLITE_DBCONFIG_MAX                   1011 /* Largest DBCONFIG */

/*
** CAPI3REF: Enable Or Disable Extended Result Codes
** METHOD: sqlite3
**
** ^The sqlite3_extended_result_codes() routine enables or disables the
** [extended result codes] feature of SQLite. ^The extended result
3405
3406
3407
3408
3409
3410
3411
3412

3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426

3427
3428
3429
3430
3431
3432
3433
3434







-
+







** does not affect the value returned by sqlite3_total_changes().
** 
** ^Changes made as part of [foreign key actions] are included in the
** count, but those made as part of REPLACE constraint resolution are
** not. ^Changes to a view that are intercepted by INSTEAD OF triggers 
** are not counted.
**
** This the [sqlite3_total_changes(D)] interface only reports the number
** The [sqlite3_total_changes(D)] interface only reports the number
** of rows that changed due to SQL statement run against database
** connection D.  Any changes by other database connections are ignored.
** To detect changes against a database file from other database
** connections use the [PRAGMA data_version] command or the
** [SQLITE_FCNTL_DATA_VERSION] [file control].
** 
** If a separate thread makes changes on the same database connection
4930
4931
4932
4933
4934
4935
4936












4937
4938
4939
4940
4941
4942
4943
4945
4946
4947
4948
4949
4950
4951
4952
4953
4954
4955
4956
4957
4958
4959
4960
4961
4962
4963
4964
4965
4966
4967
4968
4969
4970







+
+
+
+
+
+
+
+
+
+
+
+







** ^The sqlite3_stmt_readonly() interface returns true for [BEGIN] since
** [BEGIN] merely sets internal flags, but the [BEGIN|BEGIN IMMEDIATE] and
** [BEGIN|BEGIN EXCLUSIVE] commands do touch the database and so
** sqlite3_stmt_readonly() returns false for those commands.
*/
SQLITE_API int sqlite3_stmt_readonly(sqlite3_stmt *pStmt);

/*
** CAPI3REF: Query The EXPLAIN Setting For A Prepared Statement
** METHOD: sqlite3_stmt
**
** ^The sqlite3_stmt_isexplain(S) interface returns 1 if the
** prepared statement S is an EXPLAIN statement, or 2 if the
** statement S is an EXPLAIN QUERY PLAN.
** ^The sqlite3_stmt_isexplain(S) interface returns 0 if S is
** an ordinary statement or a NULL pointer.
*/
SQLITE_API int sqlite3_stmt_isexplain(sqlite3_stmt *pStmt);

/*
** CAPI3REF: Determine If A Prepared Statement Has Been Reset
** METHOD: sqlite3_stmt
**
** ^The sqlite3_stmt_busy(S) interface returns true (non-zero) if the
** [prepared statement] S has been stepped at least once using 
** [sqlite3_step(S)] but has neither run to completion (returned
5069
5070
5071
5072
5073
5074
5075
5076



5077
5078
5079
5080
5081
5082
5083
5096
5097
5098
5099
5100
5101
5102

5103
5104
5105
5106
5107
5108
5109
5110
5111
5112







-
+
+
+







** the value of the fourth parameter then the resulting string value will
** contain embedded NULs.  The result of expressions involving strings
** with embedded NULs is undefined.
**
** ^The fifth argument to the BLOB and string binding interfaces
** is a destructor used to dispose of the BLOB or
** string after SQLite has finished with it.  ^The destructor is called
** to dispose of the BLOB or string even if the call to bind API fails.
** to dispose of the BLOB or string even if the call to the bind API fails,
** except the destructor is not called if the third parameter is a NULL
** pointer or the fourth parameter is negative.
** ^If the fifth argument is
** the special value [SQLITE_STATIC], then SQLite assumes that the
** information is in static, unmanaged space and does not need to be freed.
** ^If the fifth argument has the value [SQLITE_TRANSIENT], then
** SQLite makes its own private copy of the data immediately, before
** the sqlite3_bind_*() routine returns.
**
5986
5987
5988
5989
5990
5991
5992


5993
5994
5995
5996
5997
5998
5999
6015
6016
6017
6018
6019
6020
6021
6022
6023
6024
6025
6026
6027
6028
6029
6030







+
+







** <tr><td><b>sqlite3_value_type</b><td>&rarr;<td>Default
** datatype of the value
** <tr><td><b>sqlite3_value_numeric_type&nbsp;&nbsp;</b>
** <td>&rarr;&nbsp;&nbsp;<td>Best numeric datatype of the value
** <tr><td><b>sqlite3_value_nochange&nbsp;&nbsp;</b>
** <td>&rarr;&nbsp;&nbsp;<td>True if the column is unchanged in an UPDATE
** against a virtual table.
** <tr><td><b>sqlite3_value_frombind&nbsp;&nbsp;</b>
** <td>&rarr;&nbsp;&nbsp;<td>True if value originated from a [bound parameter]
** </table></blockquote>
**
** <b>Details:</b>
**
** These routines extract type, size, and content information from
** [protected sqlite3_value] objects.  Protected sqlite3_value objects
** are used to pass parameter information into implementation of
6046
6047
6048
6049
6050
6051
6052





6053
6054
6055
6056
6057
6058
6059
6077
6078
6079
6080
6081
6082
6083
6084
6085
6086
6087
6088
6089
6090
6091
6092
6093
6094
6095







+
+
+
+
+







** the value for that column returned without setting a result (probably
** because it queried [sqlite3_vtab_nochange()] and found that the column
** was unchanging).  ^Within an [xUpdate] method, any value for which
** sqlite3_value_nochange(X) is true will in all other respects appear
** to be a NULL value.  If sqlite3_value_nochange(X) is invoked anywhere other
** than within an [xUpdate] method call for an UPDATE statement, then
** the return value is arbitrary and meaningless.
**
** ^The sqlite3_value_frombind(X) interface returns non-zero if the
** value X originated from one of the [sqlite3_bind_int|sqlite3_bind()]
** interfaces.  ^If X comes from an SQL literal value, or a table column,
** and expression, then sqlite3_value_frombind(X) returns zero.
**
** Please pay particular attention to the fact that the pointer returned
** from [sqlite3_value_blob()], [sqlite3_value_text()], or
** [sqlite3_value_text16()] can be invalidated by a subsequent call to
** [sqlite3_value_bytes()], [sqlite3_value_bytes16()], [sqlite3_value_text()],
** or [sqlite3_value_text16()].
**
6092
6093
6094
6095
6096
6097
6098

6099
6100
6101
6102
6103
6104
6105
6128
6129
6130
6131
6132
6133
6134
6135
6136
6137
6138
6139
6140
6141
6142







+







SQLITE_API const void *sqlite3_value_text16le(sqlite3_value*);
SQLITE_API const void *sqlite3_value_text16be(sqlite3_value*);
SQLITE_API int sqlite3_value_bytes(sqlite3_value*);
SQLITE_API int sqlite3_value_bytes16(sqlite3_value*);
SQLITE_API int sqlite3_value_type(sqlite3_value*);
SQLITE_API int sqlite3_value_numeric_type(sqlite3_value*);
SQLITE_API int sqlite3_value_nochange(sqlite3_value*);
SQLITE_API int sqlite3_value_frombind(sqlite3_value*);

/*
** CAPI3REF: Finding The Subtype Of SQL Values
** METHOD: sqlite3_value
**
** The sqlite3_value_subtype(V) function returns the subtype for
** an [application-defined SQL function] argument V.  The subtype
6827
6828
6829
6830
6831
6832
6833
6834

6835
6836
6837
6838
6839
6840
6841
6864
6865
6866
6867
6868
6869
6870

6871
6872
6873
6874
6875
6876
6877
6878







-
+







** CAPI3REF: Return The Filename For A Database Connection
** METHOD: sqlite3
**
** ^The sqlite3_db_filename(D,N) interface returns a pointer to a filename
** associated with database N of connection D.  ^The main database file
** has the name "main".  If there is no attached database N on the database
** connection D, or if database N is a temporary or in-memory database, then
** a NULL pointer is returned.
** this function will return either a NULL pointer or an empty string.
**
** ^The filename returned by this function is the output of the
** xFullPathname method of the [VFS].  ^In other words, the filename
** will be an absolute pathname, even if the filename used
** to open the database originally was a URI or relative pathname.
*/
SQLITE_API const char *sqlite3_db_filename(sqlite3 *db, const char *zDbName);
11928
11929
11930
11931
11932
11933
11934
11935

11936
11937
11938
11939
11940
11941
11942
11965
11966
11967
11968
11969
11970
11971

11972
11973
11974
11975
11976
11977
11978
11979







-
+







** CAPI3REF: Rebase a changeset
** EXPERIMENTAL
**
** Argument pIn must point to a buffer containing a changeset nIn bytes
** in size. This function allocates and populates a buffer with a copy
** of the changeset rebased rebased according to the configuration of the
** rebaser object passed as the first argument. If successful, (*ppOut)
** is set to point to the new buffer containing the rebased changset and 
** is set to point to the new buffer containing the rebased changeset and 
** (*pnOut) to its size in bytes and SQLITE_OK returned. It is the
** responsibility of the caller to eventually free the new buffer using
** sqlite3_free(). Otherwise, if an error occurs, (*ppOut) and (*pnOut)
** are set to zero and an SQLite error code returned.
*/
SQLITE_API int sqlite3rebaser_rebase(
  sqlite3_rebaser*,
12337
12338
12339
12340
12341
12342
12343
12344

12345
12346
12347
12348
12349
12350
12351
12352
12353
12354
12355
12356
12357
12358
12359

12360
12361
12362
12363
12364
12365
12366
12374
12375
12376
12377
12378
12379
12380

12381
12382
12383
12384
12385
12386
12387
12388
12389
12390
12391
12392
12393
12394
12395

12396
12397
12398
12399
12400
12401
12402
12403







-
+














-
+







**
**
** xSetAuxdata(pFts5, pAux, xDelete)
**
**   Save the pointer passed as the second argument as the extension functions 
**   "auxiliary data". The pointer may then be retrieved by the current or any
**   future invocation of the same fts5 extension function made as part of
**   of the same MATCH query using the xGetAuxdata() API.
**   the same MATCH query using the xGetAuxdata() API.
**
**   Each extension function is allocated a single auxiliary data slot for
**   each FTS query (MATCH expression). If the extension function is invoked 
**   more than once for a single FTS query, then all invocations share a 
**   single auxiliary data context.
**
**   If there is already an auxiliary data pointer when this function is
**   invoked, then it is replaced by the new pointer. If an xDelete callback
**   was specified along with the original pointer, it is invoked at this
**   point.
**
**   The xDelete callback, if one is specified, is also invoked on the
**   auxiliary data pointer after the FTS5 query has finished.
**
**   If an error (e.g. an OOM condition) occurs within this function, an
**   If an error (e.g. an OOM condition) occurs within this function,
**   the auxiliary data is set to NULL and an error code returned. If the
**   xDelete parameter was not NULL, it is invoked on the auxiliary data
**   pointer before returning.
**
**
** xGetAuxdata(pFts5, bClear)
**
13519
13520
13521
13522
13523
13524
13525




13526
13527
13528
13529
13530
13531
13532
13533
13534
13535
13536
13537
13538
13539
13540
13541
13542
13543
13544
13545
13546
13547
13548
13549
13550
13551
13552
13553
13554
13555
13556
13557
13558
13559
13560
13561
13562
13563
13564
13565
13566
13567
13568
13569
13570
13571
13572
13573
13574
13575
13576
13577
13578
13579
13580
13581
13582
13583
13584
13585
13586
13587
13588
13589
13590
13591
13592
13593
13594
13595
13596
13597
13598
13599
13600
13601
13602
13603
13604
13605
13606
13607


















































































13608
13609
13610
13611


13612
13613
13614
13615
13616
13617
13618
13619
13620
13621
13622
13623
13624
13625
13556
13557
13558
13559
13560
13561
13562
13563
13564
13565
13566


















































































13567
13568
13569
13570
13571
13572
13573
13574
13575
13576
13577
13578
13579
13580
13581
13582
13583
13584
13585
13586
13587
13588
13589
13590
13591
13592
13593
13594
13595
13596
13597
13598
13599
13600
13601
13602
13603
13604
13605
13606
13607
13608
13609
13610
13611
13612
13613
13614
13615
13616
13617
13618
13619
13620
13621
13622
13623
13624
13625
13626
13627
13628
13629
13630
13631
13632
13633
13634
13635
13636
13637
13638
13639
13640
13641
13642
13643
13644
13645
13646
13647
13648




13649
13650







13651
13652
13653
13654
13655
13656
13657







+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
+
+
-
-
-
-
-
-
-







#define TK_WITH                            81
#define TK_CURRENT                         82
#define TK_FOLLOWING                       83
#define TK_PARTITION                       84
#define TK_PRECEDING                       85
#define TK_RANGE                           86
#define TK_UNBOUNDED                       87
#define TK_EXCLUDE                         88
#define TK_GROUPS                          89
#define TK_OTHERS                          90
#define TK_TIES                            91
#define TK_REINDEX                         88
#define TK_RENAME                          89
#define TK_CTIME_KW                        90
#define TK_ANY                             91
#define TK_BITAND                          92
#define TK_BITOR                           93
#define TK_LSHIFT                          94
#define TK_RSHIFT                          95
#define TK_PLUS                            96
#define TK_MINUS                           97
#define TK_STAR                            98
#define TK_SLASH                           99
#define TK_REM                            100
#define TK_CONCAT                         101
#define TK_COLLATE                        102
#define TK_BITNOT                         103
#define TK_ON                             104
#define TK_INDEXED                        105
#define TK_STRING                         106
#define TK_JOIN_KW                        107
#define TK_CONSTRAINT                     108
#define TK_DEFAULT                        109
#define TK_NULL                           110
#define TK_PRIMARY                        111
#define TK_UNIQUE                         112
#define TK_CHECK                          113
#define TK_REFERENCES                     114
#define TK_AUTOINCR                       115
#define TK_INSERT                         116
#define TK_DELETE                         117
#define TK_UPDATE                         118
#define TK_SET                            119
#define TK_DEFERRABLE                     120
#define TK_FOREIGN                        121
#define TK_DROP                           122
#define TK_UNION                          123
#define TK_ALL                            124
#define TK_EXCEPT                         125
#define TK_INTERSECT                      126
#define TK_SELECT                         127
#define TK_VALUES                         128
#define TK_DISTINCT                       129
#define TK_DOT                            130
#define TK_FROM                           131
#define TK_JOIN                           132
#define TK_USING                          133
#define TK_ORDER                          134
#define TK_GROUP                          135
#define TK_HAVING                         136
#define TK_LIMIT                          137
#define TK_WHERE                          138
#define TK_INTO                           139
#define TK_NOTHING                        140
#define TK_FLOAT                          141
#define TK_BLOB                           142
#define TK_INTEGER                        143
#define TK_VARIABLE                       144
#define TK_CASE                           145
#define TK_WHEN                           146
#define TK_THEN                           147
#define TK_ELSE                           148
#define TK_INDEX                          149
#define TK_ALTER                          150
#define TK_ADD                            151
#define TK_WINDOW                         152
#define TK_OVER                           153
#define TK_FILTER                         154
#define TK_TRUEFALSE                      155
#define TK_ISNOT                          156
#define TK_FUNCTION                       157
#define TK_COLUMN                         158
#define TK_AGG_FUNCTION                   159
#define TK_AGG_COLUMN                     160
#define TK_UMINUS                         161
#define TK_UPLUS                          162
#define TK_TRUTH                          163
#define TK_REGISTER                       164
#define TK_VECTOR                         165
#define TK_SELECT_COLUMN                  166
#define TK_IF_NULL_ROW                    167
#define TK_ASTERISK                       168
#define TK_SPAN                           169
#define TK_REINDEX                         92
#define TK_RENAME                          93
#define TK_CTIME_KW                        94
#define TK_ANY                             95
#define TK_BITAND                          96
#define TK_BITOR                           97
#define TK_LSHIFT                          98
#define TK_RSHIFT                          99
#define TK_PLUS                           100
#define TK_MINUS                          101
#define TK_STAR                           102
#define TK_SLASH                          103
#define TK_REM                            104
#define TK_CONCAT                         105
#define TK_COLLATE                        106
#define TK_BITNOT                         107
#define TK_ON                             108
#define TK_INDEXED                        109
#define TK_STRING                         110
#define TK_JOIN_KW                        111
#define TK_CONSTRAINT                     112
#define TK_DEFAULT                        113
#define TK_NULL                           114
#define TK_PRIMARY                        115
#define TK_UNIQUE                         116
#define TK_CHECK                          117
#define TK_REFERENCES                     118
#define TK_AUTOINCR                       119
#define TK_INSERT                         120
#define TK_DELETE                         121
#define TK_UPDATE                         122
#define TK_SET                            123
#define TK_DEFERRABLE                     124
#define TK_FOREIGN                        125
#define TK_DROP                           126
#define TK_UNION                          127
#define TK_ALL                            128
#define TK_EXCEPT                         129
#define TK_INTERSECT                      130
#define TK_SELECT                         131
#define TK_VALUES                         132
#define TK_DISTINCT                       133
#define TK_DOT                            134
#define TK_FROM                           135
#define TK_JOIN                           136
#define TK_USING                          137
#define TK_ORDER                          138
#define TK_GROUP                          139
#define TK_HAVING                         140
#define TK_LIMIT                          141
#define TK_WHERE                          142
#define TK_INTO                           143
#define TK_NOTHING                        144
#define TK_FLOAT                          145
#define TK_BLOB                           146
#define TK_INTEGER                        147
#define TK_VARIABLE                       148
#define TK_CASE                           149
#define TK_WHEN                           150
#define TK_THEN                           151
#define TK_ELSE                           152
#define TK_INDEX                          153
#define TK_ALTER                          154
#define TK_ADD                            155
#define TK_WINDOW                         156
#define TK_OVER                           157
#define TK_FILTER                         158
#define TK_TRUEFALSE                      159
#define TK_ISNOT                          160
#define TK_FUNCTION                       161
#define TK_COLUMN                         162
#define TK_AGG_FUNCTION                   163
#define TK_AGG_COLUMN                     164
#define TK_UMINUS                         165
#define TK_UPLUS                          166
#define TK_TRUTH                          167
#define TK_REGISTER                       168
#define TK_VECTOR                         169
#define TK_SELECT_COLUMN                  170
#define TK_IF_NULL_ROW                    171
#define TK_ASTERISK                       172
#define TK_SPAN                           173
#define TK_END_OF_FILE                    170
#define TK_UNCLOSED_STRING                171
#define TK_SPACE                          172
#define TK_ILLEGAL                        173
#define TK_SPACE                          174
#define TK_ILLEGAL                        175

/* The token codes above must all fit in 8 bits */
#define TKFLG_MASK           0xff  

/* Flags that can be added to a token code when it is not
** being stored in a u8: */
#define TKFLG_DONTFOLD       0x100  /* Omit constant folding optimizations */

/************** End of parse.h ***********************************************/
/************** Continuing where we left off in sqliteInt.h ******************/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
14543
14544
14545
14546
14547
14548
14549
14550
14551
14552
14553
14554
14555
14556
14557
14558
14559
14575
14576
14577
14578
14579
14580
14581



14582
14583
14584
14585
14586
14587
14588







-
-
-







  int nData;              /* Size of pData.  0 if none. */
  int nZero;              /* Extra zero data appended after pData,nData */
};

SQLITE_PRIVATE int sqlite3BtreeInsert(BtCursor*, const BtreePayload *pPayload,
                       int flags, int seekResult);
SQLITE_PRIVATE int sqlite3BtreeFirst(BtCursor*, int *pRes);
#ifndef SQLITE_OMIT_WINDOWFUNC
SQLITE_PRIVATE void sqlite3BtreeSkipNext(BtCursor*);
#endif
SQLITE_PRIVATE int sqlite3BtreeLast(BtCursor*, int *pRes);
SQLITE_PRIVATE int sqlite3BtreeNext(BtCursor*, int flags);
SQLITE_PRIVATE int sqlite3BtreeEof(BtCursor*);
SQLITE_PRIVATE int sqlite3BtreePrevious(BtCursor*, int flags);
SQLITE_PRIVATE i64 sqlite3BtreeIntegerKey(BtCursor*);
#ifdef SQLITE_ENABLE_OFFSET_SQL_FUNC
SQLITE_PRIVATE i64 sqlite3BtreeOffset(BtCursor*);
14903
14904
14905
14906
14907
14908
14909




14910
14911
14912
14913
14914
14915
14916
14917
14918
14919
14920
14921












14922
14923
14924
14925
14926
14927
14928



14929
14930
14931
14932
14933
14934
14935
14936
14937
14938
14939
14940
14941
14942
14943
14944
14945
14946
14947
14948
14949
14950
14951
14952
14953
14954
14955
14956
14957
14958

















14959
14960
14961
14962
14963
14964
14965
14966
14967
14968
14969
14970
14971
14972
14973
14974
14975
14976
14977
14978
14979
14980
14981
14982
14983
14984
14985
14986
14987
14988
14989
14990
14991

































14992
14993
14994
14995
14996
14997
14998
14932
14933
14934
14935
14936
14937
14938
14939
14940
14941
14942












14943
14944
14945
14946
14947
14948
14949
14950
14951
14952
14953
14954







14955
14956
14957
14958
14959
14960
14961
14962
14963
14964
14965
14966
14967
14968
14969


















14970
14971
14972
14973
14974
14975
14976
14977
14978
14979
14980
14981
14982
14983
14984
14985
14986

































14987
14988
14989
14990
14991
14992
14993
14994
14995
14996
14997
14998
14999
15000
15001
15002
15003
15004
15005
15006
15007
15008
15009
15010
15011
15012
15013
15014
15015
15016
15017
15018
15019
15020
15021
15022
15023
15024
15025
15026







+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
+
+
+












-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+







#define OP_Cast           85 /* synopsis: affinity(r[P1])                  */
#define OP_Permutation    86
#define OP_Compare        87 /* synopsis: r[P1@P3] <-> r[P2@P3]            */
#define OP_IsTrue         88 /* synopsis: r[P2] = coalesce(r[P1]==TRUE,P3) ^ P4 */
#define OP_Offset         89 /* synopsis: r[P3] = sqlite_offset(P1)        */
#define OP_Column         90 /* synopsis: r[P3]=PX                         */
#define OP_Affinity       91 /* synopsis: affinity(r[P1@P2])               */
#define OP_MakeRecord     92 /* synopsis: r[P3]=mkrec(r[P1@P2])            */
#define OP_Count          93 /* synopsis: r[P2]=count()                    */
#define OP_ReadCookie     94
#define OP_SetCookie      95
#define OP_BitAnd         92 /* same as TK_BITAND, synopsis: r[P3]=r[P1]&r[P2] */
#define OP_BitOr          93 /* same as TK_BITOR, synopsis: r[P3]=r[P1]|r[P2] */
#define OP_ShiftLeft      94 /* same as TK_LSHIFT, synopsis: r[P3]=r[P2]<<r[P1] */
#define OP_ShiftRight     95 /* same as TK_RSHIFT, synopsis: r[P3]=r[P2]>>r[P1] */
#define OP_Add            96 /* same as TK_PLUS, synopsis: r[P3]=r[P1]+r[P2] */
#define OP_Subtract       97 /* same as TK_MINUS, synopsis: r[P3]=r[P2]-r[P1] */
#define OP_Multiply       98 /* same as TK_STAR, synopsis: r[P3]=r[P1]*r[P2] */
#define OP_Divide         99 /* same as TK_SLASH, synopsis: r[P3]=r[P2]/r[P1] */
#define OP_Remainder     100 /* same as TK_REM, synopsis: r[P3]=r[P2]%r[P1] */
#define OP_Concat        101 /* same as TK_CONCAT, synopsis: r[P3]=r[P2]+r[P1] */
#define OP_MakeRecord    102 /* synopsis: r[P3]=mkrec(r[P1@P2])            */
#define OP_BitNot        103 /* same as TK_BITNOT, synopsis: r[P2]= ~r[P1] */
#define OP_BitAnd         96 /* same as TK_BITAND, synopsis: r[P3]=r[P1]&r[P2] */
#define OP_BitOr          97 /* same as TK_BITOR, synopsis: r[P3]=r[P1]|r[P2] */
#define OP_ShiftLeft      98 /* same as TK_LSHIFT, synopsis: r[P3]=r[P2]<<r[P1] */
#define OP_ShiftRight     99 /* same as TK_RSHIFT, synopsis: r[P3]=r[P2]>>r[P1] */
#define OP_Add           100 /* same as TK_PLUS, synopsis: r[P3]=r[P1]+r[P2] */
#define OP_Subtract      101 /* same as TK_MINUS, synopsis: r[P3]=r[P2]-r[P1] */
#define OP_Multiply      102 /* same as TK_STAR, synopsis: r[P3]=r[P1]*r[P2] */
#define OP_Divide        103 /* same as TK_SLASH, synopsis: r[P3]=r[P2]/r[P1] */
#define OP_Remainder     104 /* same as TK_REM, synopsis: r[P3]=r[P2]%r[P1] */
#define OP_Concat        105 /* same as TK_CONCAT, synopsis: r[P3]=r[P2]+r[P1] */
#define OP_ReopenIdx     106 /* synopsis: root=P2 iDb=P3                   */
#define OP_BitNot        107 /* same as TK_BITNOT, synopsis: r[P2]= ~r[P1] */
#define OP_Count         104 /* synopsis: r[P2]=count()                    */
#define OP_ReadCookie    105
#define OP_String8       106 /* same as TK_STRING, synopsis: r[P2]='P4'    */
#define OP_SetCookie     107
#define OP_ReopenIdx     108 /* synopsis: root=P2 iDb=P3                   */
#define OP_OpenRead      109 /* synopsis: root=P2 iDb=P3                   */
#define OP_OpenWrite     110 /* synopsis: root=P2 iDb=P3                   */
#define OP_OpenRead      108 /* synopsis: root=P2 iDb=P3                   */
#define OP_OpenWrite     109 /* synopsis: root=P2 iDb=P3                   */
#define OP_String8       110 /* same as TK_STRING, synopsis: r[P2]='P4'    */
#define OP_OpenDup       111
#define OP_OpenAutoindex 112 /* synopsis: nColumn=P2                       */
#define OP_OpenEphemeral 113 /* synopsis: nColumn=P2                       */
#define OP_SorterOpen    114
#define OP_SequenceTest  115 /* synopsis: if( cursor[P1].ctr++ ) pc = P2   */
#define OP_OpenPseudo    116 /* synopsis: P3 columns in r[P2]              */
#define OP_Close         117
#define OP_ColumnsUsed   118
#define OP_SeekHit       119 /* synopsis: seekHit=P2                       */
#define OP_Sequence      120 /* synopsis: r[P2]=cursor[P1].ctr++           */
#define OP_NewRowid      121 /* synopsis: r[P2]=rowid                      */
#define OP_Insert        122 /* synopsis: intkey=r[P3] data=r[P2]          */
#define OP_InsertInt     123 /* synopsis: intkey=P3 data=r[P2]             */
#define OP_Delete        124
#define OP_ResetCount    125
#define OP_SorterCompare 126 /* synopsis: if key(P1)!=trim(r[P3],P4) goto P2 */
#define OP_SorterData    127 /* synopsis: r[P2]=data                       */
#define OP_RowData       128 /* synopsis: r[P2]=data                       */
#define OP_Rowid         129 /* synopsis: r[P2]=rowid                      */
#define OP_NullRow       130
#define OP_SeekEnd       131
#define OP_SorterInsert  132 /* synopsis: key=r[P2]                        */
#define OP_IdxInsert     133 /* synopsis: key=r[P2]                        */
#define OP_IdxDelete     134 /* synopsis: key=r[P2@P3]                     */
#define OP_DeferredSeek  135 /* synopsis: Move P3 to P1.rowid if needed    */
#define OP_IdxRowid      136 /* synopsis: r[P2]=rowid                      */
#define OP_Destroy       137
#define OP_Clear         138
#define OP_ResetSorter   139
#define OP_CreateBtree   140 /* synopsis: r[P2]=root iDb=P1 flags=P3       */
#define OP_Delete        123
#define OP_ResetCount    124
#define OP_SorterCompare 125 /* synopsis: if key(P1)!=trim(r[P3],P4) goto P2 */
#define OP_SorterData    126 /* synopsis: r[P2]=data                       */
#define OP_RowData       127 /* synopsis: r[P2]=data                       */
#define OP_Rowid         128 /* synopsis: r[P2]=rowid                      */
#define OP_NullRow       129
#define OP_SeekEnd       130
#define OP_SorterInsert  131 /* synopsis: key=r[P2]                        */
#define OP_IdxInsert     132 /* synopsis: key=r[P2]                        */
#define OP_IdxDelete     133 /* synopsis: key=r[P2@P3]                     */
#define OP_DeferredSeek  134 /* synopsis: Move P3 to P1.rowid if needed    */
#define OP_IdxRowid      135 /* synopsis: r[P2]=rowid                      */
#define OP_Destroy       136
#define OP_Clear         137
#define OP_ResetSorter   138
#define OP_CreateBtree   139 /* synopsis: r[P2]=root iDb=P1 flags=P3       */
#define OP_Real          141 /* same as TK_FLOAT, synopsis: r[P2]=P4       */
#define OP_SqlExec       142
#define OP_ParseSchema   143
#define OP_LoadAnalysis  144
#define OP_DropTable     145
#define OP_DropIndex     146
#define OP_DropTrigger   147
#define OP_IntegrityCk   148
#define OP_RowSetAdd     149 /* synopsis: rowset(P1)=r[P2]                 */
#define OP_Param         150
#define OP_FkCounter     151 /* synopsis: fkctr[P1]+=P2                    */
#define OP_MemMax        152 /* synopsis: r[P1]=max(r[P1],r[P2])           */
#define OP_OffsetLimit   153 /* synopsis: if r[P1]>0 then r[P2]=r[P1]+max(0,r[P3]) else r[P2]=(-1) */
#define OP_AggInverse    154 /* synopsis: accum=r[P3] inverse(r[P2@P5])    */
#define OP_AggStep       155 /* synopsis: accum=r[P3] step(r[P2@P5])       */
#define OP_AggStep1      156 /* synopsis: accum=r[P3] step(r[P2@P5])       */
#define OP_AggValue      157 /* synopsis: r[P3]=value N=P2                 */
#define OP_AggFinal      158 /* synopsis: accum=r[P1] N=P2                 */
#define OP_Expire        159
#define OP_TableLock     160 /* synopsis: iDb=P1 root=P2 write=P3          */
#define OP_VBegin        161
#define OP_VCreate       162
#define OP_VDestroy      163
#define OP_VOpen         164
#define OP_VColumn       165 /* synopsis: r[P3]=vcolumn(P2)                */
#define OP_VRename       166
#define OP_Pagecount     167
#define OP_MaxPgcnt      168
#define OP_Trace         169
#define OP_CursorHint    170
#define OP_Noop          171
#define OP_Explain       172
#define OP_Abortable     173
#define OP_SqlExec       140
#define OP_ParseSchema   141
#define OP_LoadAnalysis  142
#define OP_DropTable     143
#define OP_DropIndex     144
#define OP_Real          145 /* same as TK_FLOAT, synopsis: r[P2]=P4       */
#define OP_DropTrigger   146
#define OP_IntegrityCk   147
#define OP_RowSetAdd     148 /* synopsis: rowset(P1)=r[P2]                 */
#define OP_Param         149
#define OP_FkCounter     150 /* synopsis: fkctr[P1]+=P2                    */
#define OP_MemMax        151 /* synopsis: r[P1]=max(r[P1],r[P2])           */
#define OP_OffsetLimit   152 /* synopsis: if r[P1]>0 then r[P2]=r[P1]+max(0,r[P3]) else r[P2]=(-1) */
#define OP_AggInverse    153 /* synopsis: accum=r[P3] inverse(r[P2@P5])    */
#define OP_AggStep       154 /* synopsis: accum=r[P3] step(r[P2@P5])       */
#define OP_AggStep1      155 /* synopsis: accum=r[P3] step(r[P2@P5])       */
#define OP_AggValue      156 /* synopsis: r[P3]=value N=P2                 */
#define OP_AggFinal      157 /* synopsis: accum=r[P1] N=P2                 */
#define OP_Expire        158
#define OP_TableLock     159 /* synopsis: iDb=P1 root=P2 write=P3          */
#define OP_VBegin        160
#define OP_VCreate       161
#define OP_VDestroy      162
#define OP_VOpen         163
#define OP_VColumn       164 /* synopsis: r[P3]=vcolumn(P2)                */
#define OP_VRename       165
#define OP_Pagecount     166
#define OP_MaxPgcnt      167
#define OP_Trace         168
#define OP_CursorHint    169
#define OP_Noop          170
#define OP_Explain       171
#define OP_Abortable     172

/* Properties such as "out2" or "jump" that are specified in
** comments following the "case" for each opcode in the vdbe.c
** are encoded into bitvectors as follows:
*/
#define OPFLG_JUMP        0x01  /* jump:  P2 holds jmp target */
#define OPFLG_IN1         0x02  /* in1:   P1 is an input */
15008
15009
15010
15011
15012
15013
15014
15015
15016
15017



15018
15019
15020
15021
15022
15023
15024
15025






15026
15027
15028
15029
15030
15031
15032
15036
15037
15038
15039
15040
15041
15042



15043
15044
15045
15046
15047






15048
15049
15050
15051
15052
15053
15054
15055
15056
15057
15058
15059
15060







-
-
-
+
+
+


-
-
-
-
-
-
+
+
+
+
+
+







/*  32 */ 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,\
/*  40 */ 0x01, 0x23, 0x0b, 0x26, 0x26, 0x01, 0x01, 0x03,\
/*  48 */ 0x03, 0x03, 0x03, 0x03, 0x0b, 0x0b, 0x0b, 0x0b,\
/*  56 */ 0x0b, 0x0b, 0x01, 0x01, 0x01, 0x01, 0x00, 0x00,\
/*  64 */ 0x00, 0x00, 0x02, 0x02, 0x08, 0x00, 0x10, 0x10,\
/*  72 */ 0x10, 0x10, 0x00, 0x10, 0x10, 0x00, 0x00, 0x10,\
/*  80 */ 0x10, 0x00, 0x00, 0x02, 0x02, 0x02, 0x00, 0x00,\
/*  88 */ 0x12, 0x20, 0x00, 0x00, 0x26, 0x26, 0x26, 0x26,\
/*  96 */ 0x26, 0x26, 0x26, 0x26, 0x26, 0x26, 0x00, 0x12,\
/* 104 */ 0x10, 0x10, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00,\
/*  88 */ 0x12, 0x20, 0x00, 0x00, 0x00, 0x10, 0x10, 0x00,\
/*  96 */ 0x26, 0x26, 0x26, 0x26, 0x26, 0x26, 0x26, 0x26,\
/* 104 */ 0x26, 0x26, 0x00, 0x12, 0x00, 0x00, 0x10, 0x00,\
/* 112 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\
/* 120 */ 0x10, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\
/* 128 */ 0x00, 0x10, 0x00, 0x00, 0x04, 0x04, 0x00, 0x00,\
/* 136 */ 0x10, 0x10, 0x00, 0x00, 0x10, 0x10, 0x00, 0x00,\
/* 144 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x10, 0x00,\
/* 152 */ 0x04, 0x1a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\
/* 160 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10,\
/* 168 */ 0x10, 0x00, 0x00, 0x00, 0x00, 0x00,}
/* 128 */ 0x10, 0x00, 0x00, 0x04, 0x04, 0x00, 0x00, 0x10,\
/* 136 */ 0x10, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00,\
/* 144 */ 0x00, 0x10, 0x00, 0x00, 0x06, 0x10, 0x00, 0x04,\
/* 152 */ 0x1a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\
/* 160 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x10,\
/* 168 */ 0x00, 0x00, 0x00, 0x00, 0x00,}

/* The sqlite3P2Values() routine is able to run faster if it knows
** the value of the largest JUMP opcode.  The smaller the maximum
** JUMP opcode the better, so the mkopcodeh.tcl script that
** generated this include file strives to group all JUMP opcodes
** together near the beginning of the list.
*/
16323
16324
16325
16326
16327
16328
16329

16330
16331
16332
16333
16334
16335
16336
16351
16352
16353
16354
16355
16356
16357
16358
16359
16360
16361
16362
16363
16364
16365







+







#endif
  void *pCommitArg;                 /* Argument to xCommitCallback() */
  int (*xCommitCallback)(void*);    /* Invoked at every commit. */
  void *pRollbackArg;               /* Argument to xRollbackCallback() */
  void (*xRollbackCallback)(void*); /* Invoked at every commit. */
  void *pUpdateArg;
  void (*xUpdateCallback)(void*,int, const char*,const char*,sqlite_int64);
  Parse *pParse;                /* Current parse */
#ifdef SQLITE_ENABLE_PREUPDATE_HOOK
  void *pPreUpdateArg;          /* First argument to xPreUpdateCallback */
  void (*xPreUpdateCallback)(   /* Registered using sqlite3_preupdate_hook() */
    void*,sqlite3*,int,char const*,char const*,sqlite3_int64,sqlite3_int64
  );
  PreUpdate *pPreUpdate;        /* Context for active pre-update callback */
#endif /* SQLITE_ENABLE_PREUPDATE_HOOK */
16456
16457
16458
16459
16460
16461
16462

16463

16464
16465
16466
16467
16468
16469
16470
16471

16472
16473
16474
16475
16476
16477
16478
16485
16486
16487
16488
16489
16490
16491
16492

16493
16494
16495
16496
16497
16498
16499
16500

16501
16502
16503
16504
16505
16506
16507
16508







+
-
+







-
+








/*
** Allowed values for sqlite3.mDbFlags
*/
#define DBFLAG_SchemaChange   0x0001  /* Uncommitted Hash table changes */
#define DBFLAG_PreferBuiltin  0x0002  /* Preference to built-in funcs */
#define DBFLAG_Vacuum         0x0004  /* Currently in a VACUUM */
#define DBFLAG_VacuumInto     0x0008  /* Currently running VACUUM INTO */
#define DBFLAG_SchemaKnownOk  0x0008  /* Schema is known to be valid */
#define DBFLAG_SchemaKnownOk  0x0010  /* Schema is known to be valid */

/*
** Bits of the sqlite3.dbOptFlags field that are used by the
** sqlite3_test_control(SQLITE_TESTCTRL_OPTIMIZATIONS,...) interface to
** selectively disable various optimizations.
*/
#define SQLITE_QueryFlattener 0x0001   /* Query flattening */
                          /*  0x0002   available for reuse */
#define SQLITE_WindowFunc     0x0002   /* Use xInverse for window functions */
#define SQLITE_GroupByOrder   0x0004   /* GROUPBY cover of ORDERBY */
#define SQLITE_FactorOutConst 0x0008   /* Constant factoring */
#define SQLITE_DistinctOpt    0x0010   /* DISTINCT using indexes */
#define SQLITE_CoverIdxScan   0x0020   /* Covering index scans */
#define SQLITE_OrderByIdxJoin 0x0040   /* ORDER BY of joins via index */
#define SQLITE_Transitive     0x0080   /* Transitive constraints */
#define SQLITE_OmitNoopJoin   0x0100   /* Omit unused tables in joins */
16582
16583
16584
16585
16586
16587
16588
16589
16590
16591
16592
16593
16594
16595
16596
16612
16613
16614
16615
16616
16617
16618

16619
16620
16621
16622
16623
16624
16625







-







#define SQLITE_FUNC_CONSTANT 0x0800 /* Constant inputs give a constant output */
#define SQLITE_FUNC_MINMAX   0x1000 /* True for min() and max() aggregates */
#define SQLITE_FUNC_SLOCHNG  0x2000 /* "Slow Change". Value constant during a
                                    ** single query - might change over time */
#define SQLITE_FUNC_AFFINITY 0x4000 /* Built-in affinity() function */
#define SQLITE_FUNC_OFFSET   0x8000 /* Built-in sqlite_offset() function */
#define SQLITE_FUNC_WINDOW   0x00010000 /* Built-in window-only function */
#define SQLITE_FUNC_WINDOW_SIZE 0x20000 /* Requires partition size as arg. */
#define SQLITE_FUNC_INTERNAL 0x00040000 /* For use by NestedParse() only */

/*
** The following three macros, FUNCTION(), LIKEFUNC() and AGGREGATE() are
** used to create the initializers for the FuncDef structures.
**
**   FUNCTION(zName, nArg, iArg, bNC, xFunc)
17388
17389
17390
17391
17392
17393
17394




17395
17396
17397

17398
17399
17400

17401
17402
17403
17404
17405
17406
17407
17408
17409
17410
17411

17412
17413
17414
17415
17416
17417
17418
17419
17420
17421
17422

17423
17424
17425
17426
17427
17428
17429
17417
17418
17419
17420
17421
17422
17423
17424
17425
17426
17427
17428
17429

17430
17431
17432

17433
17434
17435
17436
17437
17438
17439
17440
17441
17442
17443

17444
17445
17446
17447
17448
17449
17450
17451
17452
17453
17454
17455
17456
17457
17458
17459
17460
17461
17462
17463







+
+
+
+


-
+


-
+










-
+











+







      int regReturn;         /* Register used to hold return address */
    } sub;
  } y;
};

/*
** The following are the meanings of bits in the Expr.flags field.
** Value restrictions:
**
**          EP_Agg == NC_HasAgg == SF_HasAgg
**          EP_Win == NC_HasWin
*/
#define EP_FromJoin  0x000001 /* Originates in ON/USING clause of outer join */
#define EP_Agg       0x000002 /* Contains one or more aggregate functions */
#define EP_Distinct  0x000002 /* Aggregate function with DISTINCT keyword */
#define EP_HasFunc   0x000004 /* Contains one or more functions of any kind */
#define EP_FixedCol  0x000008 /* TK_Column with a known fixed value */
#define EP_Distinct  0x000010 /* Aggregate function with DISTINCT keyword */
#define EP_Agg       0x000010 /* Contains one or more aggregate functions */
#define EP_VarSelect 0x000020 /* pSelect is correlated, not constant */
#define EP_DblQuoted 0x000040 /* token.z was originally in "..." */
#define EP_InfixFunc 0x000080 /* True for an infix function: LIKE, GLOB, etc */
#define EP_Collate   0x000100 /* Tree contains a TK_COLLATE operator */
#define EP_Generic   0x000200 /* Ignore COLLATE or affinity on this tree */
#define EP_IntValue  0x000400 /* Integer value contained in u.iValue */
#define EP_xIsSelect 0x000800 /* x.pSelect is valid (otherwise x.pList is) */
#define EP_Skip      0x001000 /* COLLATE, AS, or UNLIKELY */
#define EP_Reduced   0x002000 /* Expr struct EXPR_REDUCEDSIZE bytes only */
#define EP_TokenOnly 0x004000 /* Expr struct EXPR_TOKENONLYSIZE bytes only */
#define EP_Static    0x008000 /* Held in memory not obtained from malloc() */
#define EP_Win       0x008000 /* Contains window functions */
#define EP_MemToken  0x010000 /* Need to sqlite3DbFree() Expr.zToken */
#define EP_NoReduce  0x020000 /* Cannot EXPRDUP_REDUCE this Expr */
#define EP_Unlikely  0x040000 /* unlikely() or likelihood() function */
#define EP_ConstFunc 0x080000 /* A SQLITE_FUNC_CONSTANT or _SLOCHNG function */
#define EP_CanBeNull 0x100000 /* Can be null despite NOT NULL constraint */
#define EP_Subquery  0x200000 /* Tree contains a TK_SELECT operator */
#define EP_Alias     0x400000 /* Is an alias for a result set column */
#define EP_Leaf      0x800000 /* Expr.pLeft, .pRight, .u.pSelect all NULL */
#define EP_WinFunc  0x1000000 /* TK_FUNCTION with Expr.y.pWin set */
#define EP_Subrtn   0x2000000 /* Uses Expr.y.sub. TK_IN, _SELECT, or _EXISTS */
#define EP_Quoted   0x4000000 /* TK_ID was originally quoted */
#define EP_Static   0x8000000 /* Held in memory not obtained from malloc() */

/*
** The EP_Propagate mask is a set of properties that automatically propagate
** upwards into parent nodes.
*/
#define EP_Propagate (EP_Collate|EP_Subquery|EP_HasFunc)

17655
17656
17657
17658
17659
17660
17661
17662

17663

17664
17665
17666
17667
17668
17669
17670
17671
17672
17673
17674
17675
17676
17677
17678

17679
17680
17681
17682
17683
17684
17685
17689
17690
17691
17692
17693
17694
17695

17696
17697
17698
17699
17700
17701
17702
17703
17704
17705
17706
17707
17708
17709
17710
17711
17712
17713
17714
17715
17716
17717
17718
17719
17720
17721







-
+

+















+







  Select *pWinSelect;  /* SELECT statement for any window functions */
};

/*
** Allowed values for the NameContext, ncFlags field.
**
** Value constraints (all checked via assert()):
**    NC_HasAgg    == SF_HasAgg
**    NC_HasAgg    == SF_HasAgg    == EP_Agg
**    NC_MinMaxAgg == SF_MinMaxAgg == SQLITE_FUNC_MINMAX
**    NC_HasWin    == EP_Win
**
*/
#define NC_AllowAgg  0x0001  /* Aggregate functions are allowed here */
#define NC_PartIdx   0x0002  /* True if resolving a partial index WHERE */
#define NC_IsCheck   0x0004  /* True if resolving names in a CHECK constraint */
#define NC_InAggFunc 0x0008  /* True if analyzing arguments to an agg func */
#define NC_HasAgg    0x0010  /* One or more aggregate functions seen */
#define NC_IdxExpr   0x0020  /* True if resolving columns of CREATE INDEX */
#define NC_VarSelect 0x0040  /* A correlated subquery has been seen */
#define NC_UEList    0x0080  /* True if uNC.pEList is used */
#define NC_UAggInfo  0x0100  /* True if uNC.pAggInfo is used */
#define NC_UUpsert   0x0200  /* True if uNC.pUpsert is used */
#define NC_MinMaxAgg 0x1000  /* min/max aggregates seen.  See note above */
#define NC_Complex   0x2000  /* True if a function or subquery seen */
#define NC_AllowWin  0x4000  /* Window functions are allowed here */
#define NC_HasWin    0x8000  /* One or more window functions seen */

/*
** An instance of the following object describes a single ON CONFLICT
** clause in an upsert.
**
** The pUpsertTarget field is only set if the ON CONFLICT clause includes
** conflict-target clause.  (In "ON CONFLICT(a,b)" the "(a,b)" is the
17986
17987
17988
17989
17990
17991
17992

17993
17994
17995
17996
17997
17998
17999
18022
18023
18024
18025
18026
18027
18028
18029
18030
18031
18032
18033
18034
18035
18036







+







#ifndef SQLITE_OMIT_SHARED_CACHE
  int nTableLock;        /* Number of locks in aTableLock */
  TableLock *aTableLock; /* Required table locks for shared-cache mode */
#endif
  AutoincInfo *pAinc;  /* Information about AUTOINCREMENT counters */
  Parse *pToplevel;    /* Parse structure for main program (or NULL) */
  Table *pTriggerTab;  /* Table triggers are being coded for */
  Parse *pParentParse; /* Parent parser if this parser is nested */
  int addrCrTab;       /* Address of OP_CreateBtree opcode on CREATE TABLE */
  u32 nQueryLoop;      /* Est number of iterations of a query (10*log2(N)) */
  u32 oldmask;         /* Mask of old.* columns referenced */
  u32 newmask;         /* Mask of new.* columns referenced */
  u8 eTriggerOp;       /* TK_UPDATE, TK_INSERT or TK_DELETE */
  u8 eOrconf;          /* Default ON CONFLICT policy for trigger steps */
  u8 disableTriggers;  /* True to disable triggers */
18426
18427
18428
18429
18430
18431
18432
18433

18434
18435
18436
18437
18438
18439
18440
18441
18442
18443
18444
18445
18446
18447
18448

18449
18450
18451

18452
18453
18454

18455
18456


18457
18458
18459
18460
18461
18462
18463
18464
18465
18466
18467

18468
18469
18470
18471



18472
18473
18474
18475
18476
18477

18478
18479
18480
18481
18482
18483
18484
18485
18486
18487


18488
18489
18490
18491
18492
18493
18494
18463
18464
18465
18466
18467
18468
18469

18470
18471
18472
18473
18474
18475
18476
18477
18478
18479
18480
18481
18482
18483
18484

18485
18486
18487
18488
18489
18490
18491

18492
18493
18494
18495
18496
18497
18498
18499
18500
18501
18502
18503
18504
18505
18506

18507

18508
18509
18510
18511
18512
18513
18514
18515
18516
18517
18518

18519
18520
18521
18522
18523
18524
18525
18526
18527
18528
18529
18530
18531
18532
18533
18534
18535
18536
18537
18538







-
+














-
+



+


-
+


+
+










-
+
-



+
+
+





-
+










+
+







struct TreeView {
  int iLevel;             /* Which level of the tree we are on */
  u8  bLine[100];         /* Draw vertical in column i if bLine[i] is true */
};
#endif /* SQLITE_DEBUG */

/*
** This object is used in varioius ways, all related to window functions
** This object is used in various ways, all related to window functions
**
**   (1) A single instance of this structure is attached to the
**       the Expr.pWin field for each window function in an expression tree.
**       This object holds the information contained in the OVER clause,
**       plus additional fields used during code generation.
**
**   (2) All window functions in a single SELECT form a linked-list
**       attached to Select.pWin.  The Window.pFunc and Window.pExpr
**       fields point back to the expression that is the window function.
**
**   (3) The terms of the WINDOW clause of a SELECT are instances of this
**       object on a linked list attached to Select.pWinDefn.
**
** The uses (1) and (2) are really the same Window object that just happens
** to be accessible in two different ways.  Use (3) is are separate objects.
** to be accessible in two different ways.  Use case (3) are separate objects.
*/
struct Window {
  char *zName;            /* Name of window (may be NULL) */
  char *zBase;            /* Name of base window for chaining (may be NULL) */
  ExprList *pPartition;   /* PARTITION BY clause */
  ExprList *pOrderBy;     /* ORDER BY clause */
  u8 eType;               /* TK_RANGE or TK_ROWS */
  u8 eFrmType;            /* TK_RANGE, TK_GROUPS, TK_ROWS, or 0 */
  u8 eStart;              /* UNBOUNDED, CURRENT, PRECEDING or FOLLOWING */
  u8 eEnd;                /* UNBOUNDED, CURRENT, PRECEDING or FOLLOWING */
  u8 bImplicitFrame;      /* True if frame was implicitly specified */
  u8 eExclude;            /* TK_NO, TK_CURRENT, TK_TIES, TK_GROUP, or 0 */
  Expr *pStart;           /* Expression for "<expr> PRECEDING" */
  Expr *pEnd;             /* Expression for "<expr> FOLLOWING" */
  Window *pNextWin;       /* Next window function belonging to this SELECT */
  Expr *pFilter;          /* The FILTER expression */
  FuncDef *pFunc;         /* The function */
  int iEphCsr;            /* Partition buffer or Peer buffer */
  int regAccum;
  int regResult;
  int csrApp;             /* Function cursor (used by min/max) */
  int regApp;             /* Function register (also used by min/max) */
  int regPart;            /* First in a set of registers holding PARTITION BY
  int regPart;            /* Array of registers for PARTITION BY values */
                          ** and ORDER BY values for the window */
  Expr *pOwner;           /* Expression object this window is attached to */
  int nBufferCol;         /* Number of columns in buffer table */
  int iArgCol;            /* Offset of first argument for this function */
  int regOne;             /* Register containing constant value 1 */
  int regStartRowid;
  int regEndRowid;
};

#ifndef SQLITE_OMIT_WINDOWFUNC
SQLITE_PRIVATE void sqlite3WindowDelete(sqlite3*, Window*);
SQLITE_PRIVATE void sqlite3WindowListDelete(sqlite3 *db, Window *p);
SQLITE_PRIVATE Window *sqlite3WindowAlloc(Parse*, int, int, Expr*, int , Expr*);
SQLITE_PRIVATE Window *sqlite3WindowAlloc(Parse*, int, int, Expr*, int , Expr*, u8);
SQLITE_PRIVATE void sqlite3WindowAttach(Parse*, Expr*, Window*);
SQLITE_PRIVATE int sqlite3WindowCompare(Parse*, Window*, Window*);
SQLITE_PRIVATE void sqlite3WindowCodeInit(Parse*, Window*);
SQLITE_PRIVATE void sqlite3WindowCodeStep(Parse*, Select*, WhereInfo*, int, int);
SQLITE_PRIVATE int sqlite3WindowRewrite(Parse*, Select*);
SQLITE_PRIVATE int sqlite3ExpandSubquery(Parse*, struct SrcList_item*);
SQLITE_PRIVATE void sqlite3WindowUpdate(Parse*, Window*, Window*, FuncDef*);
SQLITE_PRIVATE Window *sqlite3WindowDup(sqlite3 *db, Expr *pOwner, Window *p);
SQLITE_PRIVATE Window *sqlite3WindowListDup(sqlite3 *db, Window *p);
SQLITE_PRIVATE void sqlite3WindowFunctions(void);
SQLITE_PRIVATE void sqlite3WindowChain(Parse*, Window*, Window*);
SQLITE_PRIVATE Window *sqlite3WindowAssemble(Parse*, Window*, ExprList*, ExprList*, Token*);
#else
# define sqlite3WindowDelete(a,b)
# define sqlite3WindowFunctions()
# define sqlite3WindowAttach(a,b,c)
#endif

/*
19171
19172
19173
19174
19175
19176
19177
19178

19179
19180
19181
19182
19183
19184
19185
19215
19216
19217
19218
19219
19220
19221

19222
19223
19224
19225
19226
19227
19228
19229







-
+







SQLITE_PRIVATE void sqlite3Reindex(Parse*, Token*, Token*);
SQLITE_PRIVATE void sqlite3AlterFunctions(void);
SQLITE_PRIVATE void sqlite3AlterRenameTable(Parse*, SrcList*, Token*);
SQLITE_PRIVATE void sqlite3AlterRenameColumn(Parse*, SrcList*, Token*, Token*);
SQLITE_PRIVATE int sqlite3GetToken(const unsigned char *, int *);
SQLITE_PRIVATE void sqlite3NestedParse(Parse*, const char*, ...);
SQLITE_PRIVATE void sqlite3ExpirePreparedStatements(sqlite3*, int);
SQLITE_PRIVATE void sqlite3CodeRhsOfIN(Parse*, Expr*, int, int);
SQLITE_PRIVATE void sqlite3CodeRhsOfIN(Parse*, Expr*, int);
SQLITE_PRIVATE int sqlite3CodeSubselect(Parse*, Expr*);
SQLITE_PRIVATE void sqlite3SelectPrep(Parse*, Select*, NameContext*);
SQLITE_PRIVATE void sqlite3SelectWrongNumTermsError(Parse *pParse, Select *p);
SQLITE_PRIVATE int sqlite3MatchSpanName(const char*, const char*, const char*, const char*);
SQLITE_PRIVATE int sqlite3ResolveExprNames(NameContext*, Expr*);
SQLITE_PRIVATE int sqlite3ResolveExprListNames(NameContext*, ExprList*);
SQLITE_PRIVATE void sqlite3ResolveSelectNames(Parse*, Select*, NameContext*);
20133
20134
20135
20136
20137
20138
20139
20140

20141
20142
20143
20144

20145
20146
20147
20148
20149
20150
20151
20177
20178
20179
20180
20181
20182
20183

20184
20185
20186
20187

20188
20189
20190
20191
20192
20193
20194
20195







-
+



-
+







*/
#define MEM_Null      0x0001   /* Value is NULL (or a pointer) */
#define MEM_Str       0x0002   /* Value is a string */
#define MEM_Int       0x0004   /* Value is an integer */
#define MEM_Real      0x0008   /* Value is a real number */
#define MEM_Blob      0x0010   /* Value is a BLOB */
#define MEM_AffMask   0x001f   /* Mask of affinity bits */
/* Available          0x0020   */
#define MEM_FromBind  0x0020   /* Value originates from sqlite3_bind() */
/* Available          0x0040   */
#define MEM_Undefined 0x0080   /* Value is undefined */
#define MEM_Cleared   0x0100   /* NULL set by OP_Null, not from data */
#define MEM_TypeMask  0xc1ff   /* Mask of type bits */
#define MEM_TypeMask  0xc1df   /* Mask of type bits */


/* Whenever Mem contains a valid string or blob representation, one of
** the following flags must be set to determine the memory management
** policy for Mem.z.  The MEM_Term flag tells us whether or not the
** string is \000 or \u0000 terminated
*/
20169
20170
20171
20172
20173
20174
20175






20176
20177
20178
20179
20180
20181
20182
20213
20214
20215
20216
20217
20218
20219
20220
20221
20222
20223
20224
20225
20226
20227
20228
20229
20230
20231
20232







+
+
+
+
+
+








/*
** Clear any existing type flags from a Mem and replace them with f
*/
#define MemSetTypeFlag(p, f) \
   ((p)->flags = ((p)->flags&~(MEM_TypeMask|MEM_Zero))|f)

/*
** True if Mem X is a NULL-nochng type.
*/
#define MemNullNochng(X) \
  ((X)->flags==(MEM_Null|MEM_Zero) && (X)->n==0 && (X)->u.nZero==0)

/*
** Return true if a memory cell is not marked as invalid.  This macro
** is for use inside assert() statements only.
*/
#ifdef SQLITE_DEBUG
#define memIsValid(M)  ((M)->flags & MEM_Undefined)==0
#endif
27118
27119
27120
27121
27122
27123
27124



27125
27126
27127
27128
27129
27130
27131
27168
27169
27170
27171
27172
27173
27174
27175
27176
27177
27178
27179
27180
27181
27182
27183
27184







+
+
+







SQLITE_PRIVATE void sqlite3OomFault(sqlite3 *db){
  if( db->mallocFailed==0 && db->bBenignMalloc==0 ){
    db->mallocFailed = 1;
    if( db->nVdbeExec>0 ){
      db->u1.isInterrupted = 1;
    }
    db->lookaside.bDisable++;
    if( db->pParse ){
      db->pParse->rc = SQLITE_NOMEM_BKPT;
    }
  }
}

/*
** This routine reactivates the memory allocator and clears the
** db->mallocFailed flag as necessary.
**
27311
27312
27313
27314
27315
27316
27317
27318

27319
27320
27321
27322
27323
27324
27325
27364
27365
27366
27367
27368
27369
27370

27371
27372
27373
27374
27375
27376
27377
27378







-
+








/*
** Set the StrAccum object to an error mode.
*/
static void setStrAccumError(StrAccum *p, u8 eError){
  assert( eError==SQLITE_NOMEM || eError==SQLITE_TOOBIG );
  p->accError = eError;
  p->nAlloc = 0;
  if( p->mxAlloc ) sqlite3_str_reset(p);
}

/*
** Extra argument values from a PrintfArguments object
*/
static sqlite3_int64 getIntArg(PrintfArguments *p){
  if( p->nArg<=p->nUsed ) return 0;
27341
27342
27343
27344
27345
27346
27347

27348
27349
27350
27351
27352
27353
27354
27394
27395
27396
27397
27398
27399
27400
27401
27402
27403
27404
27405
27406
27407
27408







+







** of the output buffer in pAccum, then cause an SQLITE_TOOBIG error.
** Do the size check before the memory allocation to prevent rogue
** SQL from requesting large allocations using the precision or width
** field of the printf() function.
*/
static char *printfTempBuf(sqlite3_str *pAccum, sqlite3_int64 n){
  char *z;
  if( pAccum->accError ) return 0;
  if( n>pAccum->nAlloc && n>pAccum->mxAlloc ){
    setStrAccumError(pAccum, SQLITE_TOOBIG);
    return 0;
  }
  z = sqlite3DbMallocRaw(pAccum->db, n);
  if( z==0 ){
    setStrAccumError(pAccum, SQLITE_NOMEM);
28060
28061
28062
28063
28064
28065
28066
28067
28068
28069

28070
28071
28072
28073
28074
28075
28076
28114
28115
28116
28117
28118
28119
28120

28121

28122
28123
28124
28125
28126
28127
28128
28129







-

-
+







  assert( p->nChar+(i64)N >= p->nAlloc ); /* Only called if really needed */
  if( p->accError ){
    testcase(p->accError==SQLITE_TOOBIG);
    testcase(p->accError==SQLITE_NOMEM);
    return 0;
  }
  if( p->mxAlloc==0 ){
    N = p->nAlloc - p->nChar - 1;
    setStrAccumError(p, SQLITE_TOOBIG);
    return N;
    return p->nAlloc - p->nChar - 1;
  }else{
    char *zOld = isMalloced(p) ? p->zText : 0;
    i64 szNew = p->nChar;
    szNew += N + 1;
    if( szNew+p->nChar<=p->mxAlloc ){
      /* Force exponential buffer size growth as long as it does not overflow,
      ** to avoid having to call this routine too often */
28134
28135
28136
28137
28138
28139
28140
28141

28142
28143
28144
28145
28146
28147
28148
28187
28188
28189
28190
28191
28192
28193

28194
28195
28196
28197
28198
28199
28200
28201







-
+







** Append N bytes of text from z to the StrAccum object.  Increase the
** size of the memory allocation for StrAccum if necessary.
*/
SQLITE_API void sqlite3_str_append(sqlite3_str *p, const char *z, int N){
  assert( z!=0 || N==0 );
  assert( p->zText!=0 || p->nChar==0 || p->accError );
  assert( N>=0 );
  assert( p->accError==0 || p->nAlloc==0 );
  assert( p->accError==0 || p->nAlloc==0 || p->mxAlloc==0 );
  if( p->nChar+N >= p->nAlloc ){
    enlargeAndAppend(p,z,N);
  }else if( N ){
    assert( p->zText );
    p->nChar += N;
    memcpy(&p->zText[p->nChar-N], z, N);
  }
28767
28768
28769
28770
28771
28772
28773






28774
28775
28776

28777
28778

28779









28780
28781

28782
28783
28784

28785
28786
28787








28788
28789
28790
28791

















28792
28793
28794
28795
28796
28797
28798
28820
28821
28822
28823
28824
28825
28826
28827
28828
28829
28830
28831
28832
28833
28834

28835
28836

28837
28838
28839
28840
28841
28842
28843
28844
28845
28846
28847
28848

28849
28850
28851

28852
28853


28854
28855
28856
28857
28858
28859
28860
28861
28862
28863
28864
28865
28866
28867
28868
28869
28870
28871
28872
28873
28874
28875
28876
28877
28878
28879
28880
28881
28882
28883
28884
28885
28886
28887
28888
28889







+
+
+
+
+
+


-
+

-
+

+
+
+
+
+
+
+
+
+

-
+


-
+

-
-
+
+
+
+
+
+
+
+




+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+







#endif /* SQLITE_OMIT_WINDOWFUNC */

#ifndef SQLITE_OMIT_WINDOWFUNC
/*
** Generate a human-readable explanation for a Window object
*/
SQLITE_PRIVATE void sqlite3TreeViewWindow(TreeView *pView, const Window *pWin, u8 more){
  int nElement = 0;
  if( pWin->pFilter ){
    sqlite3TreeViewItem(pView, "FILTER", 1);
    sqlite3TreeViewExpr(pView, pWin->pFilter, 0);
    sqlite3TreeViewPop(pView);
  }
  pView = sqlite3TreeViewPush(pView, more);
  if( pWin->zName ){
    sqlite3TreeViewLine(pView, "OVER %s", pWin->zName);
    sqlite3TreeViewLine(pView, "OVER %s (%p)", pWin->zName, pWin);
  }else{
    sqlite3TreeViewLine(pView, "OVER");
    sqlite3TreeViewLine(pView, "OVER (%p)", pWin);
  }
  if( pWin->zBase )    nElement++;
  if( pWin->pOrderBy ) nElement++;
  if( pWin->eFrmType ) nElement++;
  if( pWin->eExclude ) nElement++;
  if( pWin->zBase ){
    sqlite3TreeViewPush(pView, (--nElement)>0);
    sqlite3TreeViewLine(pView, "window: %s", pWin->zBase);
    sqlite3TreeViewPop(pView);
  }
  if( pWin->pPartition ){
    sqlite3TreeViewExprList(pView, pWin->pPartition, 1, "PARTITION-BY");
    sqlite3TreeViewExprList(pView, pWin->pPartition, nElement>0,"PARTITION-BY");
  }
  if( pWin->pOrderBy ){
    sqlite3TreeViewExprList(pView, pWin->pOrderBy, 1, "ORDER-BY");
    sqlite3TreeViewExprList(pView, pWin->pOrderBy, (--nElement)>0, "ORDER-BY");
  }
  if( pWin->eType ){
    sqlite3TreeViewItem(pView, pWin->eType==TK_RANGE ? "RANGE" : "ROWS", 0);
  if( pWin->eFrmType ){
    char zBuf[30];
    const char *zFrmType = "ROWS";
    if( pWin->eFrmType==TK_RANGE ) zFrmType = "RANGE";
    if( pWin->eFrmType==TK_GROUPS ) zFrmType = "GROUPS";
    sqlite3_snprintf(sizeof(zBuf),zBuf,"%s%s",zFrmType,
        pWin->bImplicitFrame ? " (implied)" : "");
    sqlite3TreeViewItem(pView, zBuf, (--nElement)>0);
    sqlite3TreeViewBound(pView, pWin->eStart, pWin->pStart, 1);
    sqlite3TreeViewBound(pView, pWin->eEnd, pWin->pEnd, 0);
    sqlite3TreeViewPop(pView);
  }
  if( pWin->eExclude ){
    char zBuf[30];
    const char *zExclude;
    switch( pWin->eExclude ){
      case TK_NO:      zExclude = "NO OTHERS";   break;
      case TK_CURRENT: zExclude = "CURRENT ROW"; break;
      case TK_GROUP:   zExclude = "GROUP";       break;
      case TK_TIES:    zExclude = "TIES";        break;
      default:
        sqlite3_snprintf(sizeof(zBuf),zBuf,"invalid(%d)", pWin->eExclude);
        zExclude = zBuf;
        break;
    }
    sqlite3TreeViewPush(pView, 0);
    sqlite3TreeViewLine(pView, "EXCLUDE %s", zExclude);
    sqlite3TreeViewPop(pView);
  }
  sqlite3TreeViewPop(pView);
}
#endif /* SQLITE_OMIT_WINDOWFUNC */

#ifndef SQLITE_OMIT_WINDOWFUNC
/*
** Generate a human-readable explanation for a Window Function object
30131
30132
30133
30134
30135
30136
30137
30138
30139
30140



30141
30142
30143


30144



30145
30146







30147
30148
30149
30150
30151
30152
30153
30222
30223
30224
30225
30226
30227
30228



30229
30230
30231
30232


30233
30234
30235
30236
30237
30238


30239
30240
30241
30242
30243
30244
30245
30246
30247
30248
30249
30250
30251
30252







-
-
-
+
+
+

-
-
+
+

+
+
+
-
-
+
+
+
+
+
+
+







SQLITE_PRIVATE void sqlite3Coverage(int x){
  static unsigned dummy = 0;
  dummy += (unsigned)x;
}
#endif

/*
** Give a callback to the test harness that can be used to simulate faults
** in places where it is difficult or expensive to do so purely by means
** of inputs.
** Calls to sqlite3FaultSim() are used to simulate a failure during testing,
** or to bypass normal error detection during testing in order to let 
** execute proceed futher downstream.
**
** The intent of the integer argument is to let the fault simulator know
** which of multiple sqlite3FaultSim() calls has been hit.
** In deployment, sqlite3FaultSim() *always* return SQLITE_OK (0).  The
** sqlite3FaultSim() function only returns non-zero during testing.
**
** During testing, if the test harness has set a fault-sim callback using
** a call to sqlite3_test_control(SQLITE_TESTCTRL_FAULT_INSTALL), then
** each call to sqlite3FaultSim() is relayed to that application-supplied
** Return whatever integer value the test callback returns, or return
** SQLITE_OK if no test callback is installed.
** callback and the integer return value form the application-supplied
** callback is returned by sqlite3FaultSim().
**
** The integer argument to sqlite3FaultSim() is a code to identify which
** sqlite3FaultSim() instance is being invoked. Each call to sqlite3FaultSim()
** should have a unique code.  To prevent legacy testing applications from
** breaking, the codes should not be changed or reused.
*/
#ifndef SQLITE_UNTESTABLE
SQLITE_PRIVATE int sqlite3FaultSim(int iTest){
  int (*xCallback)(int) = sqlite3GlobalConfig.xTestCallback;
  return xCallback ? xCallback(iTest) : SQLITE_OK;
}
#endif
32105
32106
32107
32108
32109
32110
32111




32112
32113
32114
32115
32116
32117
32118
32119
32120
32121
32122
32123












32124
32125
32126
32127
32128
32129
32130



32131
32132
32133
32134
32135
32136
32137
32138
32139
32140
32141
32142
32143
32144
32145
32146
32147
32148
32149
32150
32151
32152
32153
32154
32155
32156
32157
32158
32159
32160

















32161
32162
32163
32164
32165
32166
32167
32168
32169
32170
32171
32172
32173
32174
32175
32176
32177
32178
32179
32180
32181
32182
32183
32184
32185
32186
32187
32188
32189
32190
32191
32192
32193

































32194
32195
32196
32197
32198
32199
32200
32204
32205
32206
32207
32208
32209
32210
32211
32212
32213
32214












32215
32216
32217
32218
32219
32220
32221
32222
32223
32224
32225
32226







32227
32228
32229
32230
32231
32232
32233
32234
32235
32236
32237
32238
32239
32240
32241


















32242
32243
32244
32245
32246
32247
32248
32249
32250
32251
32252
32253
32254
32255
32256
32257
32258

































32259
32260
32261
32262
32263
32264
32265
32266
32267
32268
32269
32270
32271
32272
32273
32274
32275
32276
32277
32278
32279
32280
32281
32282
32283
32284
32285
32286
32287
32288
32289
32290
32291
32292
32293
32294
32295
32296
32297
32298







+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
+
+
+












-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+







    /*  85 */ "Cast"             OpHelp("affinity(r[P1])"),
    /*  86 */ "Permutation"      OpHelp(""),
    /*  87 */ "Compare"          OpHelp("r[P1@P3] <-> r[P2@P3]"),
    /*  88 */ "IsTrue"           OpHelp("r[P2] = coalesce(r[P1]==TRUE,P3) ^ P4"),
    /*  89 */ "Offset"           OpHelp("r[P3] = sqlite_offset(P1)"),
    /*  90 */ "Column"           OpHelp("r[P3]=PX"),
    /*  91 */ "Affinity"         OpHelp("affinity(r[P1@P2])"),
    /*  92 */ "MakeRecord"       OpHelp("r[P3]=mkrec(r[P1@P2])"),
    /*  93 */ "Count"            OpHelp("r[P2]=count()"),
    /*  94 */ "ReadCookie"       OpHelp(""),
    /*  95 */ "SetCookie"        OpHelp(""),
    /*  92 */ "BitAnd"           OpHelp("r[P3]=r[P1]&r[P2]"),
    /*  93 */ "BitOr"            OpHelp("r[P3]=r[P1]|r[P2]"),
    /*  94 */ "ShiftLeft"        OpHelp("r[P3]=r[P2]<<r[P1]"),
    /*  95 */ "ShiftRight"       OpHelp("r[P3]=r[P2]>>r[P1]"),
    /*  96 */ "Add"              OpHelp("r[P3]=r[P1]+r[P2]"),
    /*  97 */ "Subtract"         OpHelp("r[P3]=r[P2]-r[P1]"),
    /*  98 */ "Multiply"         OpHelp("r[P3]=r[P1]*r[P2]"),
    /*  99 */ "Divide"           OpHelp("r[P3]=r[P2]/r[P1]"),
    /* 100 */ "Remainder"        OpHelp("r[P3]=r[P2]%r[P1]"),
    /* 101 */ "Concat"           OpHelp("r[P3]=r[P2]+r[P1]"),
    /* 102 */ "MakeRecord"       OpHelp("r[P3]=mkrec(r[P1@P2])"),
    /* 103 */ "BitNot"           OpHelp("r[P2]= ~r[P1]"),
    /*  96 */ "BitAnd"           OpHelp("r[P3]=r[P1]&r[P2]"),
    /*  97 */ "BitOr"            OpHelp("r[P3]=r[P1]|r[P2]"),
    /*  98 */ "ShiftLeft"        OpHelp("r[P3]=r[P2]<<r[P1]"),
    /*  99 */ "ShiftRight"       OpHelp("r[P3]=r[P2]>>r[P1]"),
    /* 100 */ "Add"              OpHelp("r[P3]=r[P1]+r[P2]"),
    /* 101 */ "Subtract"         OpHelp("r[P3]=r[P2]-r[P1]"),
    /* 102 */ "Multiply"         OpHelp("r[P3]=r[P1]*r[P2]"),
    /* 103 */ "Divide"           OpHelp("r[P3]=r[P2]/r[P1]"),
    /* 104 */ "Remainder"        OpHelp("r[P3]=r[P2]%r[P1]"),
    /* 105 */ "Concat"           OpHelp("r[P3]=r[P2]+r[P1]"),
    /* 106 */ "ReopenIdx"        OpHelp("root=P2 iDb=P3"),
    /* 107 */ "BitNot"           OpHelp("r[P2]= ~r[P1]"),
    /* 104 */ "Count"            OpHelp("r[P2]=count()"),
    /* 105 */ "ReadCookie"       OpHelp(""),
    /* 106 */ "String8"          OpHelp("r[P2]='P4'"),
    /* 107 */ "SetCookie"        OpHelp(""),
    /* 108 */ "ReopenIdx"        OpHelp("root=P2 iDb=P3"),
    /* 109 */ "OpenRead"         OpHelp("root=P2 iDb=P3"),
    /* 110 */ "OpenWrite"        OpHelp("root=P2 iDb=P3"),
    /* 108 */ "OpenRead"         OpHelp("root=P2 iDb=P3"),
    /* 109 */ "OpenWrite"        OpHelp("root=P2 iDb=P3"),
    /* 110 */ "String8"          OpHelp("r[P2]='P4'"),
    /* 111 */ "OpenDup"          OpHelp(""),
    /* 112 */ "OpenAutoindex"    OpHelp("nColumn=P2"),
    /* 113 */ "OpenEphemeral"    OpHelp("nColumn=P2"),
    /* 114 */ "SorterOpen"       OpHelp(""),
    /* 115 */ "SequenceTest"     OpHelp("if( cursor[P1].ctr++ ) pc = P2"),
    /* 116 */ "OpenPseudo"       OpHelp("P3 columns in r[P2]"),
    /* 117 */ "Close"            OpHelp(""),
    /* 118 */ "ColumnsUsed"      OpHelp(""),
    /* 119 */ "SeekHit"          OpHelp("seekHit=P2"),
    /* 120 */ "Sequence"         OpHelp("r[P2]=cursor[P1].ctr++"),
    /* 121 */ "NewRowid"         OpHelp("r[P2]=rowid"),
    /* 122 */ "Insert"           OpHelp("intkey=r[P3] data=r[P2]"),
    /* 123 */ "InsertInt"        OpHelp("intkey=P3 data=r[P2]"),
    /* 124 */ "Delete"           OpHelp(""),
    /* 125 */ "ResetCount"       OpHelp(""),
    /* 126 */ "SorterCompare"    OpHelp("if key(P1)!=trim(r[P3],P4) goto P2"),
    /* 127 */ "SorterData"       OpHelp("r[P2]=data"),
    /* 128 */ "RowData"          OpHelp("r[P2]=data"),
    /* 129 */ "Rowid"            OpHelp("r[P2]=rowid"),
    /* 130 */ "NullRow"          OpHelp(""),
    /* 131 */ "SeekEnd"          OpHelp(""),
    /* 132 */ "SorterInsert"     OpHelp("key=r[P2]"),
    /* 133 */ "IdxInsert"        OpHelp("key=r[P2]"),
    /* 134 */ "IdxDelete"        OpHelp("key=r[P2@P3]"),
    /* 135 */ "DeferredSeek"     OpHelp("Move P3 to P1.rowid if needed"),
    /* 136 */ "IdxRowid"         OpHelp("r[P2]=rowid"),
    /* 137 */ "Destroy"          OpHelp(""),
    /* 138 */ "Clear"            OpHelp(""),
    /* 139 */ "ResetSorter"      OpHelp(""),
    /* 140 */ "CreateBtree"      OpHelp("r[P2]=root iDb=P1 flags=P3"),
    /* 123 */ "Delete"           OpHelp(""),
    /* 124 */ "ResetCount"       OpHelp(""),
    /* 125 */ "SorterCompare"    OpHelp("if key(P1)!=trim(r[P3],P4) goto P2"),
    /* 126 */ "SorterData"       OpHelp("r[P2]=data"),
    /* 127 */ "RowData"          OpHelp("r[P2]=data"),
    /* 128 */ "Rowid"            OpHelp("r[P2]=rowid"),
    /* 129 */ "NullRow"          OpHelp(""),
    /* 130 */ "SeekEnd"          OpHelp(""),
    /* 131 */ "SorterInsert"     OpHelp("key=r[P2]"),
    /* 132 */ "IdxInsert"        OpHelp("key=r[P2]"),
    /* 133 */ "IdxDelete"        OpHelp("key=r[P2@P3]"),
    /* 134 */ "DeferredSeek"     OpHelp("Move P3 to P1.rowid if needed"),
    /* 135 */ "IdxRowid"         OpHelp("r[P2]=rowid"),
    /* 136 */ "Destroy"          OpHelp(""),
    /* 137 */ "Clear"            OpHelp(""),
    /* 138 */ "ResetSorter"      OpHelp(""),
    /* 139 */ "CreateBtree"      OpHelp("r[P2]=root iDb=P1 flags=P3"),
    /* 141 */ "Real"             OpHelp("r[P2]=P4"),
    /* 142 */ "SqlExec"          OpHelp(""),
    /* 143 */ "ParseSchema"      OpHelp(""),
    /* 144 */ "LoadAnalysis"     OpHelp(""),
    /* 145 */ "DropTable"        OpHelp(""),
    /* 146 */ "DropIndex"        OpHelp(""),
    /* 147 */ "DropTrigger"      OpHelp(""),
    /* 148 */ "IntegrityCk"      OpHelp(""),
    /* 149 */ "RowSetAdd"        OpHelp("rowset(P1)=r[P2]"),
    /* 150 */ "Param"            OpHelp(""),
    /* 151 */ "FkCounter"        OpHelp("fkctr[P1]+=P2"),
    /* 152 */ "MemMax"           OpHelp("r[P1]=max(r[P1],r[P2])"),
    /* 153 */ "OffsetLimit"      OpHelp("if r[P1]>0 then r[P2]=r[P1]+max(0,r[P3]) else r[P2]=(-1)"),
    /* 154 */ "AggInverse"       OpHelp("accum=r[P3] inverse(r[P2@P5])"),
    /* 155 */ "AggStep"          OpHelp("accum=r[P3] step(r[P2@P5])"),
    /* 156 */ "AggStep1"         OpHelp("accum=r[P3] step(r[P2@P5])"),
    /* 157 */ "AggValue"         OpHelp("r[P3]=value N=P2"),
    /* 158 */ "AggFinal"         OpHelp("accum=r[P1] N=P2"),
    /* 159 */ "Expire"           OpHelp(""),
    /* 160 */ "TableLock"        OpHelp("iDb=P1 root=P2 write=P3"),
    /* 161 */ "VBegin"           OpHelp(""),
    /* 162 */ "VCreate"          OpHelp(""),
    /* 163 */ "VDestroy"         OpHelp(""),
    /* 164 */ "VOpen"            OpHelp(""),
    /* 165 */ "VColumn"          OpHelp("r[P3]=vcolumn(P2)"),
    /* 166 */ "VRename"          OpHelp(""),
    /* 167 */ "Pagecount"        OpHelp(""),
    /* 168 */ "MaxPgcnt"         OpHelp(""),
    /* 169 */ "Trace"            OpHelp(""),
    /* 170 */ "CursorHint"       OpHelp(""),
    /* 171 */ "Noop"             OpHelp(""),
    /* 172 */ "Explain"          OpHelp(""),
    /* 173 */ "Abortable"        OpHelp(""),
    /* 140 */ "SqlExec"          OpHelp(""),
    /* 141 */ "ParseSchema"      OpHelp(""),
    /* 142 */ "LoadAnalysis"     OpHelp(""),
    /* 143 */ "DropTable"        OpHelp(""),
    /* 144 */ "DropIndex"        OpHelp(""),
    /* 145 */ "Real"             OpHelp("r[P2]=P4"),
    /* 146 */ "DropTrigger"      OpHelp(""),
    /* 147 */ "IntegrityCk"      OpHelp(""),
    /* 148 */ "RowSetAdd"        OpHelp("rowset(P1)=r[P2]"),
    /* 149 */ "Param"            OpHelp(""),
    /* 150 */ "FkCounter"        OpHelp("fkctr[P1]+=P2"),
    /* 151 */ "MemMax"           OpHelp("r[P1]=max(r[P1],r[P2])"),
    /* 152 */ "OffsetLimit"      OpHelp("if r[P1]>0 then r[P2]=r[P1]+max(0,r[P3]) else r[P2]=(-1)"),
    /* 153 */ "AggInverse"       OpHelp("accum=r[P3] inverse(r[P2@P5])"),
    /* 154 */ "AggStep"          OpHelp("accum=r[P3] step(r[P2@P5])"),
    /* 155 */ "AggStep1"         OpHelp("accum=r[P3] step(r[P2@P5])"),
    /* 156 */ "AggValue"         OpHelp("r[P3]=value N=P2"),
    /* 157 */ "AggFinal"         OpHelp("accum=r[P1] N=P2"),
    /* 158 */ "Expire"           OpHelp(""),
    /* 159 */ "TableLock"        OpHelp("iDb=P1 root=P2 write=P3"),
    /* 160 */ "VBegin"           OpHelp(""),
    /* 161 */ "VCreate"          OpHelp(""),
    /* 162 */ "VDestroy"         OpHelp(""),
    /* 163 */ "VOpen"            OpHelp(""),
    /* 164 */ "VColumn"          OpHelp("r[P3]=vcolumn(P2)"),
    /* 165 */ "VRename"          OpHelp(""),
    /* 166 */ "Pagecount"        OpHelp(""),
    /* 167 */ "MaxPgcnt"         OpHelp(""),
    /* 168 */ "Trace"            OpHelp(""),
    /* 169 */ "CursorHint"       OpHelp(""),
    /* 170 */ "Noop"             OpHelp(""),
    /* 171 */ "Explain"          OpHelp(""),
    /* 172 */ "Abortable"        OpHelp(""),
  };
  return azName[i];
}
#endif

/************** End of opcodes.c *********************************************/
/************** Begin file os_unix.c *****************************************/
48618
48619
48620
48621
48622
48623
48624










48625
48626
48627
48628
48629
48630


48631
48632
48633
48634
48635
48636
48637
48716
48717
48718
48719
48720
48721
48722
48723
48724
48725
48726
48727
48728
48729
48730
48731
48732
48733
48734
48735
48736


48737
48738
48739
48740
48741
48742
48743
48744
48745







+
+
+
+
+
+
+
+
+
+




-
-
+
+







typedef struct PGroup PGroup;

/*
** Each cache entry is represented by an instance of the following 
** structure. Unless SQLITE_PCACHE_SEPARATE_HEADER is defined, a buffer of
** PgHdr1.pCache->szPage bytes is allocated directly before this structure 
** in memory.
**
** Note: Variables isBulkLocal and isAnchor were once type "u8". That works,
** but causes a 2-byte gap in the structure for most architectures (since 
** pointers must be either 4 or 8-byte aligned). As this structure is located
** in memory directly after the associated page data, if the database is
** corrupt, code at the b-tree layer may overread the page buffer and 
** read part of this structure before the corruption is detected. This
** can cause a valgrind error if the unitialized gap is accessed. Using u16
** ensures there is no such gap, and therefore no bytes of unitialized memory
** in the structure.
*/
struct PgHdr1 {
  sqlite3_pcache_page page;      /* Base class. Must be first. pBuf & pExtra */
  unsigned int iKey;             /* Key value (page number) */
  u8 isBulkLocal;                /* This page from bulk local storage */
  u8 isAnchor;                   /* This is the PGroup.lru element */
  u16 isBulkLocal;               /* This page from bulk local storage */
  u16 isAnchor;                  /* This is the PGroup.lru element */
  PgHdr1 *pNext;                 /* Next in hash table chain */
  PCache1 *pCache;               /* Cache that currently owns this page */
  PgHdr1 *pLruNext;              /* Next in LRU list of unpinned pages */
  PgHdr1 *pLruPrev;              /* Previous in LRU list of unpinned pages */
                                 /* NB: pLruPrev is only valid if pLruNext!=0 */
};

48829
48830
48831
48832
48833
48834
48835

48836
48837
48838
48839
48840
48841
48842
48937
48938
48939
48940
48941
48942
48943
48944
48945
48946
48947
48948
48949
48950
48951







+







    do{
      PgHdr1 *pX = (PgHdr1*)&zBulk[pCache->szPage];
      pX->page.pBuf = zBulk;
      pX->page.pExtra = &pX[1];
      pX->isBulkLocal = 1;
      pX->isAnchor = 0;
      pX->pNext = pCache->pFree;
      pX->pLruPrev = 0;           /* Initializing this saves a valgrind error */
      pCache->pFree = pX;
      zBulk += pCache->szAlloc;
    }while( --nBulk );
  }
  return pCache->pFree!=0;
}

51290
51291
51292
51293
51294
51295
51296



51297
51298
51299
51300
51301
51302
51303
51399
51400
51401
51402
51403
51404
51405
51406
51407
51408
51409
51410
51411
51412
51413
51414
51415







+
+
+







**   * the database file is open,
**   * there are no dirty pages in the cache, and
**   * the desired page is not currently in the wal file.
*/
SQLITE_PRIVATE int sqlite3PagerDirectReadOk(Pager *pPager, Pgno pgno){
  if( pPager->fd->pMethods==0 ) return 0;
  if( sqlite3PCacheIsDirty(pPager->pPCache) ) return 0;
#ifdef SQLITE_HAS_CODEC
  if( pPager->xCodec!=0 ) return 0;
#endif
#ifndef SQLITE_OMIT_WAL
  if( pPager->pWal ){
    u32 iRead = 0;
    int rc;
    rc = sqlite3WalFindFrame(pPager->pWal, pgno, &iRead);
    return (rc==SQLITE_OK && iRead==0);
  }
54239
54240
54241
54242
54243
54244
54245


54246
54247






54248
54249
54250
54251
54252
54253
54254
54351
54352
54353
54354
54355
54356
54357
54358
54359


54360
54361
54362
54363
54364
54365
54366
54367
54368
54369
54370
54371
54372







+
+
-
-
+
+
+
+
+
+







    char *pNew = NULL;             /* New temp space */
    i64 nByte = 0;

    if( pPager->eState>PAGER_OPEN && isOpen(pPager->fd) ){
      rc = sqlite3OsFileSize(pPager->fd, &nByte);
    }
    if( rc==SQLITE_OK ){
      /* 8 bytes of zeroed overrun space is sufficient so that the b-tree
      * cell header parser will never run off the end of the allocation */
      pNew = (char *)sqlite3PageMalloc(pageSize);
      if( !pNew ) rc = SQLITE_NOMEM_BKPT;
      pNew = (char *)sqlite3PageMalloc(pageSize+8);
      if( !pNew ){
        rc = SQLITE_NOMEM_BKPT;
      }else{
        memset(pNew+pageSize, 0, 8);
      }
    }

    if( rc==SQLITE_OK ){
      pager_reset(pPager);
      rc = sqlite3PcacheSetPageSize(pPager->pPCache, pageSize);
    }
    if( rc==SQLITE_OK ){
57621
57622
57623
57624
57625
57626
57627
57628

57629




57630
57631
57632
57633
57634
57635
57636
57739
57740
57741
57742
57743
57744
57745

57746
57747
57748
57749
57750
57751
57752
57753
57754
57755
57756
57757
57758







-
+

+
+
+
+







  /* If the cache contains a page with page-number pgno, remove it
  ** from its hash chain. Also, if the PGHDR_NEED_SYNC flag was set for 
  ** page pgno before the 'move' operation, it needs to be retained 
  ** for the page moved there.
  */
  pPg->flags &= ~PGHDR_NEED_SYNC;
  pPgOld = sqlite3PagerLookup(pPager, pgno);
  assert( !pPgOld || pPgOld->nRef==1 );
  assert( !pPgOld || pPgOld->nRef==1 || CORRUPT_DB );
  if( pPgOld ){
    if( pPgOld->nRef>1 ){
      sqlite3PagerUnrefNotNull(pPgOld);
      return SQLITE_CORRUPT_BKPT;
    }
    pPg->flags |= (pPgOld->flags&PGHDR_NEED_SYNC);
    if( pPager->tempFile ){
      /* Do not discard pages from an in-memory database since we might
      ** need to rollback later.  Just move the page out of the way. */
      sqlite3PcacheMove(pPgOld, pPager->dbSize+1);
    }else{
      sqlite3PcacheDrop(pPgOld);
58150
58151
58152
58153
58154
58155
58156
58157

58158
58159
58160
58161
58162
58163
58164
58272
58273
58274
58275
58276
58277
58278

58279
58280
58281
58282
58283
58284
58285
58286







-
+








/*
** Release a lock obtained by an earlier successful call to
** sqlite3PagerSnapshotCheck().
*/
SQLITE_PRIVATE void sqlite3PagerSnapshotUnlock(Pager *pPager){
  assert( pPager->pWal );
  return sqlite3WalSnapshotUnlock(pPager->pWal);
  sqlite3WalSnapshotUnlock(pPager->pWal);
}

#endif /* SQLITE_ENABLE_SNAPSHOT */
#endif /* !SQLITE_OMIT_WAL */

#ifdef SQLITE_ENABLE_ZIPVFS
/*
59162
59163
59164
59165
59166
59167
59168

59169
59170
59171
59172
59173
59174
59175
59176
59177
59178
59179

59180
59181
59182
59183


59184
59185
59186
59187
59188
59189
59190
59284
59285
59286
59287
59288
59289
59290
59291
59292
59293
59294
59295
59296
59297
59298
59299
59300
59301

59302
59303
59304
59305

59306
59307
59308
59309
59310
59311
59312
59313
59314







+










-
+



-
+
+







** actually needed.
*/
static void walCleanupHash(Wal *pWal){
  WalHashLoc sLoc;                /* Hash table location */
  int iLimit = 0;                 /* Zero values greater than this */
  int nByte;                      /* Number of bytes to zero in aPgno[] */
  int i;                          /* Used to iterate through aHash[] */
  int rc;                         /* Return code form walHashGet() */

  assert( pWal->writeLock );
  testcase( pWal->hdr.mxFrame==HASHTABLE_NPAGE_ONE-1 );
  testcase( pWal->hdr.mxFrame==HASHTABLE_NPAGE_ONE );
  testcase( pWal->hdr.mxFrame==HASHTABLE_NPAGE_ONE+1 );

  if( pWal->hdr.mxFrame==0 ) return;

  /* Obtain pointers to the hash-table and page-number array containing 
  ** the entry that corresponds to frame pWal->hdr.mxFrame. It is guaranteed
  ** that the page said hash-table and array reside on is already mapped.
  ** that the page said hash-table and array reside on is already mapped.(1)
  */
  assert( pWal->nWiData>walFramePage(pWal->hdr.mxFrame) );
  assert( pWal->apWiData[walFramePage(pWal->hdr.mxFrame)] );
  walHashGet(pWal, walFramePage(pWal->hdr.mxFrame), &sLoc);
  rc = walHashGet(pWal, walFramePage(pWal->hdr.mxFrame), &sLoc);
  if( NEVER(rc) ) return; /* Defense-in-depth, in case (1) above is wrong */

  /* Zero all hash-table entries that correspond to frame numbers greater
  ** than pWal->hdr.mxFrame.
  */
  iLimit = pWal->hdr.mxFrame - sLoc.iZero;
  assert( iLimit>0 );
  for(i=0; i<HASHTABLE_NSLOT; i++){
62326
62327
62328
62329
62330
62331
62332
62333

62334
62335
62336
62337
62338
62339
62340
62450
62451
62452
62453
62454
62455
62456

62457
62458
62459
62460
62461
62462
62463
62464







-
+







  u8 hdrOffset;        /* 100 for page 1.  0 otherwise */
  u8 childPtrSize;     /* 0 if leaf==1.  4 if leaf==0 */
  u8 max1bytePayload;  /* min(maxLocal,127) */
  u8 nOverflow;        /* Number of overflow cell bodies in aCell[] */
  u16 maxLocal;        /* Copy of BtShared.maxLocal or BtShared.maxLeaf */
  u16 minLocal;        /* Copy of BtShared.minLocal or BtShared.minLeaf */
  u16 cellOffset;      /* Index in aData of first cell pointer */
  u16 nFree;           /* Number of free bytes on the page */
  int nFree;           /* Number of free bytes on the page. -1 for unknown */
  u16 nCell;           /* Number of cells on this page, local and ovfl */
  u16 maskPage;        /* Mask for page offset */
  u16 aiOvfl[4];       /* Insert the i-th overflow cell before the aiOvfl-th
                       ** non-overflow cell */
  u8 *apOvfl[4];       /* Pointers to the body of overflow cells */
  BtShared *pBt;       /* Pointer to BtShared that this page is part of */
  u8 *aData;           /* Pointer to disk image of the page data */
63880
63881
63882
63883
63884
63885
63886
63887

63888
63889
63890
63891
63892
63893



63894


63895
63896
63897
63898
63899
63900
63901
64004
64005
64006
64007
64008
64009
64010

64011
64012
64013
64014
64015
64016
64017
64018
64019
64020

64021
64022
64023
64024
64025
64026
64027
64028
64029







-
+






+
+
+
-
+
+







** when saveCursorPosition() was called. Note that this call deletes the 
** saved position info stored by saveCursorPosition(), so there can be
** at most one effective restoreCursorPosition() call after each 
** saveCursorPosition().
*/
static int btreeRestoreCursorPosition(BtCursor *pCur){
  int rc;
  int skipNext;
  int skipNext = 0;
  assert( cursorOwnsBtShared(pCur) );
  assert( pCur->eState>=CURSOR_REQUIRESEEK );
  if( pCur->eState==CURSOR_FAULT ){
    return pCur->skipNext;
  }
  pCur->eState = CURSOR_INVALID;
  if( sqlite3FaultSim(410) ){
    rc = SQLITE_IOERR;
  }else{
  rc = btreeMoveto(pCur, pCur->pKey, pCur->nKey, 0, &skipNext);
    rc = btreeMoveto(pCur, pCur->pKey, pCur->nKey, 0, &skipNext);
  }
  if( rc==SQLITE_OK ){
    sqlite3_free(pCur->pKey);
    pCur->pKey = 0;
    assert( pCur->eState==CURSOR_VALID || pCur->eState==CURSOR_INVALID );
    if( skipNext ) pCur->skipNext = skipNext;
    if( pCur->skipNext && pCur->eState==CURSOR_VALID ){
      pCur->eState = CURSOR_SKIPNEXT;
64468
64469
64470
64471
64472
64473
64474
64475

64476
64477
64478
64479
64480
64481
64482
64483
64484
64485
64486

64487
64488
64489
64490
64491
64492
64493
64494
64495
64496
64497
64498
64499
64500
64501
64502
64503
64504
64505
64506
64507
64508


64509

64510
64511
64512
64513
64514
64515
64516
64596
64597
64598
64599
64600
64601
64602

64603
64604
64605
64606
64607
64608
64609
64610
64611
64612
64613

64614




64615
64616
64617
64618
64619
64620
64621
64622
64623
64624
64625
64626
64627
64628
64629
64630
64631
64632
64633
64634
64635
64636
64637
64638
64639
64640
64641
64642
64643







-
+










-
+
-
-
-
-


















+
+

+







  assert( pPage->nOverflow==0 );
  assert( sqlite3_mutex_held(pPage->pBt->mutex) );
  temp = 0;
  src = data = pPage->aData;
  hdr = pPage->hdrOffset;
  cellOffset = pPage->cellOffset;
  nCell = pPage->nCell;
  assert( nCell==get2byte(&data[hdr+3]) );
  assert( nCell==get2byte(&data[hdr+3]) || CORRUPT_DB );
  iCellFirst = cellOffset + 2*nCell;
  usableSize = pPage->pBt->usableSize;

  /* This block handles pages with two or fewer free blocks and nMaxFrag
  ** or fewer fragmented bytes. In this case it is faster to move the
  ** two (or one) blocks of cells using memmove() and add the required
  ** offsets to each pointer in the cell-pointer array than it is to 
  ** reconstruct the entire page.  */
  if( (int)data[hdr+7]<=nMaxFrag ){
    int iFree = get2byte(&data[hdr+1]);

    if( iFree>usableSize-4 ) return SQLITE_CORRUPT_PAGE(pPage);
    /* If the initial freeblock offset were out of bounds, that would
    ** have been detected by btreeInitPage() when it was computing the
    ** number of free bytes on the page. */
    assert( iFree<=usableSize-4 );
    if( iFree ){
      int iFree2 = get2byte(&data[iFree]);
      if( iFree2>usableSize-4 ) return SQLITE_CORRUPT_PAGE(pPage);
      if( 0==iFree2 || (data[iFree2]==0 && data[iFree2+1]==0) ){
        u8 *pEnd = &data[cellOffset + nCell*2];
        u8 *pAddr;
        int sz2 = 0;
        int sz = get2byte(&data[iFree+2]);
        int top = get2byte(&data[hdr+5]);
        if( top>=iFree ){
          return SQLITE_CORRUPT_PAGE(pPage);
        }
        if( iFree2 ){
          if( iFree+sz>iFree2 ) return SQLITE_CORRUPT_PAGE(pPage);
          sz2 = get2byte(&data[iFree2+2]);
          if( iFree2+sz2 > usableSize ) return SQLITE_CORRUPT_PAGE(pPage);
          memmove(&data[iFree+sz+sz2], &data[iFree+sz], iFree2-(iFree+sz));
          sz += sz2;
        }else if( iFree+sz>usableSize ){
          return SQLITE_CORRUPT_PAGE(pPage);
        }

        cbrk = top+sz;
        assert( cbrk+(iFree-top) <= usableSize );
        memmove(&data[cbrk], &data[top], iFree-top);
        for(pAddr=&data[cellOffset]; pAddr<pEnd; pAddr+=2){
          pc = get2byte(pAddr);
          if( pc<iFree ){ put2byte(pAddr, pc+sz); }
          else if( pc<iFree2 ){ put2byte(pAddr, pc+sz2); }
64553
64554
64555
64556
64557
64558
64559

64560
64561
64562
64563
64564
64565
64566
64680
64681
64682
64683
64684
64685
64686
64687
64688
64689
64690
64691
64692
64693
64694







+







      src = temp;
    }
    memcpy(&data[cbrk], &src[pc], size);
  }
  data[hdr+7] = 0;

 defragment_out:
  assert( pPage->nFree>=0 );
  if( data[hdr+7]+cbrk-iCellFirst!=pPage->nFree ){
    return SQLITE_CORRUPT_PAGE(pPage);
  }
  assert( cbrk>=iCellFirst );
  put2byte(&data[hdr+5], cbrk);
  data[hdr+1] = 0;
  data[hdr+2] = 0;
64580
64581
64582
64583
64584
64585
64586
64587
64588
64589
64590
64591
64592
64593







64594
64595
64596

64597
64598
64599
64600
64601
64602
64603
64604
64605
64606
64607

64608
64609
64610
64611
64612
64613
64614
64615




64616
64617
64618

64619
64620
64621
64622
64623
64624
64625

64626
64627
64628
64629
64630











64631
64632
64633
64634
64635
64636
64637
64708
64709
64710
64711
64712
64713
64714







64715
64716
64717
64718
64719
64720
64721
64722
64723

64724
64725
64726
64727
64728
64729
64730
64731




64732
64733
64734
64735
64736
64737
64738
64739
64740
64741
64742
64743
64744
64745
64746

64747
64748
64749
64750
64751
64752
64753

64754





64755
64756
64757
64758
64759
64760
64761
64762
64763
64764
64765
64766
64767
64768
64769
64770
64771
64772







-
-
-
-
-
-
-
+
+
+
+
+
+
+


-
+







-
-
-
-
+








+
+
+
+


-
+






-
+
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+







** detected then *pRc is set to SQLITE_CORRUPT and NULL is returned.
**
** Slots on the free list that are between 1 and 3 bytes larger than nByte
** will be ignored if adding the extra space to the fragmentation count
** causes the fragmentation count to exceed 60.
*/
static u8 *pageFindSlot(MemPage *pPg, int nByte, int *pRc){
  const int hdr = pPg->hdrOffset;
  u8 * const aData = pPg->aData;
  int iAddr = hdr + 1;
  int pc = get2byte(&aData[iAddr]);
  int x;
  int usableSize = pPg->pBt->usableSize;
  int size;            /* Size of the free slot */
  const int hdr = pPg->hdrOffset;            /* Offset to page header */
  u8 * const aData = pPg->aData;             /* Page data */
  int iAddr = hdr + 1;                       /* Address of ptr to pc */
  int pc = get2byte(&aData[iAddr]);          /* Address of a free slot */
  int x;                                     /* Excess size of the slot */
  int maxPC = pPg->pBt->usableSize - nByte;  /* Max address for a usable slot */
  int size;                                  /* Size of the free slot */

  assert( pc>0 );
  while( pc<=usableSize-4 ){
  while( pc<=maxPC ){
    /* EVIDENCE-OF: R-22710-53328 The third and fourth bytes of each
    ** freeblock form a big-endian integer which is the size of the freeblock
    ** in bytes, including the 4-byte header. */
    size = get2byte(&aData[pc+2]);
    if( (x = size - nByte)>=0 ){
      testcase( x==4 );
      testcase( x==3 );
      if( size+pc > usableSize ){
        *pRc = SQLITE_CORRUPT_PAGE(pPg);
        return 0;
      }else if( x<4 ){
      if( x<4 ){
        /* EVIDENCE-OF: R-11498-58022 In a well-formed b-tree page, the total
        ** number of bytes in fragments may not exceed 60. */
        if( aData[hdr+7]>57 ) return 0;

        /* Remove the slot from the free-list. Update the number of
        ** fragmented bytes within the page. */
        memcpy(&aData[iAddr], &aData[pc], 2);
        aData[hdr+7] += (u8)x;
      }else if( x+pc > maxPC ){
        /* This slot extends off the end of the usable part of the page */
        *pRc = SQLITE_CORRUPT_PAGE(pPg);
        return 0;
      }else{
        /* The slot remains on the free-list. Reduce its size to account
         ** for the portion used by the new allocation. */
        ** for the portion used by the new allocation. */
        put2byte(&aData[pc+2], x);
      }
      return &aData[pc + x];
    }
    iAddr = pc;
    pc = get2byte(&aData[pc]);
    if( pc<iAddr+size ) break;
    if( pc<=iAddr+size ){
  }
  if( pc ){
    *pRc = SQLITE_CORRUPT_PAGE(pPg);
  }

      if( pc ){
        /* The next slot in the chain is not past the end of the current slot */
        *pRc = SQLITE_CORRUPT_PAGE(pPg);
      }
      return 0;
    }
  }
  if( pc>maxPC+nByte-4 ){
    /* The free slot chain extends off the end of the page */
    *pRc = SQLITE_CORRUPT_PAGE(pPg);
  }
  return 0;
}

/*
** Allocate nByte bytes of space from within the B-Tree page passed
** as the first argument. Write into *pIdx the index into pPage->aData[]
** of the first byte of allocated space. Return either SQLITE_OK or
64673
64674
64675
64676
64677
64678
64679
64680
64681
64682



64683
64684
64685
64686
64687
64688
64689
64808
64809
64810
64811
64812
64813
64814



64815
64816
64817
64818
64819
64820
64821
64822
64823
64824







-
-
-
+
+
+







    if( top==0 && pPage->pBt->usableSize==65536 ){
      top = 65536;
    }else{
      return SQLITE_CORRUPT_PAGE(pPage);
    }
  }

  /* If there is enough space between gap and top for one more cell pointer
  ** array entry offset, and if the freelist is not empty, then search the
  ** freelist looking for a free slot big enough to satisfy the request.
  /* If there is enough space between gap and top for one more cell pointer,
  ** and if the freelist is not empty, then search the
  ** freelist looking for a slot big enough to satisfy the request.
  */
  testcase( gap+2==top );
  testcase( gap+1==top );
  testcase( gap==top );
  if( (data[hdr+2] || data[hdr+1]) && gap+2<=top ){
    u8 *pSpace = pageFindSlot(pPage, nByte, &rc);
    if( pSpace ){
64697
64698
64699
64700
64701
64702
64703

64704
64705
64706
64707
64708
64709
64710
64711
64712

64713
64714
64715
64716
64717
64718
64719
64720
64721
64722
64723
64724
64725
64726
64727
64728
64729
64730
64731

64732
64733
64734
64735
64736
64737
64738
64832
64833
64834
64835
64836
64837
64838
64839
64840
64841
64842
64843
64844
64845
64846
64847

64848
64849
64850
64851
64852
64853
64854
64855
64856
64857
64858
64859
64860
64861
64862
64863
64864
64865
64866

64867
64868
64869
64870
64871
64872
64873
64874







+








-
+


















-
+








  /* The request could not be fulfilled using a freelist slot.  Check
  ** to see if defragmentation is necessary.
  */
  testcase( gap+2+nByte==top );
  if( gap+2+nByte>top ){
    assert( pPage->nCell>0 || CORRUPT_DB );
    assert( pPage->nFree>=0 );
    rc = defragmentPage(pPage, MIN(4, pPage->nFree - (2+nByte)));
    if( rc ) return rc;
    top = get2byteNotZero(&data[hdr+5]);
    assert( gap+2+nByte<=top );
  }


  /* Allocate memory from the gap in between the cell pointer array
  ** and the cell content area.  The btreeInitPage() call has already
  ** and the cell content area.  The btreeComputeFreeSpace() call has already
  ** validated the freelist.  Given that the freelist is valid, there
  ** is no way that the allocation can extend off the end of the page.
  ** The assert() below verifies the previous sentence.
  */
  top -= nByte;
  put2byte(&data[hdr+5], top);
  assert( top+nByte <= (int)pPage->pBt->usableSize );
  *pIdx = top;
  return SQLITE_OK;
}

/*
** Return a section of the pPage->aData to the freelist.
** The first byte of the new free block is pPage->aData[iStart]
** and the size of the block is iSize bytes.
**
** Adjacent freeblocks are coalesced.
**
** Note that even though the freeblock list was checked by btreeInitPage(),
** Even though the freeblock list was checked by btreeComputeFreeSpace(),
** that routine will not detect overlap between cells or freeblocks.  Nor
** does it detect cells or freeblocks that encrouch into the reserved bytes
** at the end of the page.  So do additional corruption checks inside this
** routine and return SQLITE_CORRUPT if any problems are found.
*/
static int freeSpace(MemPage *pPage, u16 iStart, u16 iSize){
  u16 iPtr;                             /* Address of ptr to next freeblock */
64886
64887
64888
64889
64890
64891
64892
64893
64894


64895
64896
64897
64898
64899
64900
64901

64902
64903
64904
64905
64906
64907
64908
64909
64910
64911
64912
64913
64914
64915
64916
64917
64918
64919


64920
64921

64922
64923
64924
64925
64926
64927
64928
64929
64930
64931
64932
64933
64934
64935
64936
64937
64938
64939
64940
64941
64942
64943
64944
64945
64946
64947
64948
64949
64950
64951
64952
64953
64954

64955
64956
64957
64958
64959
64960
64961
64962
64963
64964
64965
64966
64967
64968
64969
64970
64971
64972
64973
64974
64975
64976
64977
64978
64979
64980
64981
64982
64983
64984
64985
64986
64987
64988
64989
64990
65022
65023
65024
65025
65026
65027
65028


65029
65030





65031

65032
65033
65034
65035

65036

65037
65038
65039
65040
65041
65042
65043
65044
65045
65046
65047

65048
65049
65050

65051
65052
65053













65054
65055
65056
65057














65058








65059




















65060
65061
65062
65063
65064
65065
65066







-
-
+
+
-
-
-
-
-

-
+



-

-











-
+
+

-
+


-
-
-
-
-
-
-
-
-
-
-
-
-




-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
-
-
-
-
-
-
-
-

-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-







    return SQLITE_CORRUPT_PAGE(pPage);
  }
  pPage->max1bytePayload = pBt->max1bytePayload;
  return SQLITE_OK;
}

/*
** Initialize the auxiliary information for a disk block.
**
** Compute the amount of freespace on the page.  In other words, fill
** in the pPage->nFree field.
** Return SQLITE_OK on success.  If we see that the page does
** not contain a well-formed database page, then return 
** SQLITE_CORRUPT.  Note that a return of SQLITE_OK does not
** guarantee that the page is well-formed.  It only shows that
** we failed to detect any corruption.
*/
static int btreeInitPage(MemPage *pPage){
static int btreeComputeFreeSpace(MemPage *pPage){
  int pc;            /* Address of a freeblock within pPage->aData[] */
  u8 hdr;            /* Offset to beginning of page header */
  u8 *data;          /* Equal to pPage->aData */
  BtShared *pBt;        /* The main btree structure */
  int usableSize;    /* Amount of usable space on each page */
  u16 cellOffset;    /* Offset from start of page to first cell pointer */
  int nFree;         /* Number of unused bytes on the page */
  int top;           /* First byte of the cell content area */
  int iCellFirst;    /* First allowable cell or freeblock offset */
  int iCellLast;     /* Last possible cell or freeblock offset */

  assert( pPage->pBt!=0 );
  assert( pPage->pBt->db!=0 );
  assert( sqlite3_mutex_held(pPage->pBt->mutex) );
  assert( pPage->pgno==sqlite3PagerPagenumber(pPage->pDbPage) );
  assert( pPage == sqlite3PagerGetExtra(pPage->pDbPage) );
  assert( pPage->aData == sqlite3PagerGetData(pPage->pDbPage) );
  assert( pPage->isInit==0 );
  assert( pPage->isInit==1 );
  assert( pPage->nFree<0 );

  pBt = pPage->pBt;
  usableSize = pPage->pBt->usableSize;
  hdr = pPage->hdrOffset;
  data = pPage->aData;
  /* EVIDENCE-OF: R-28594-02890 The one-byte flag at offset 0 indicating
  ** the b-tree page type. */
  if( decodeFlags(pPage, data[hdr]) ){
    return SQLITE_CORRUPT_PAGE(pPage);
  }
  assert( pBt->pageSize>=512 && pBt->pageSize<=65536 );
  pPage->maskPage = (u16)(pBt->pageSize - 1);
  pPage->nOverflow = 0;
  usableSize = pBt->usableSize;
  pPage->cellOffset = cellOffset = hdr + 8 + pPage->childPtrSize;
  pPage->aDataEnd = &data[usableSize];
  pPage->aCellIdx = &data[cellOffset];
  pPage->aDataOfst = &data[pPage->childPtrSize];
  /* EVIDENCE-OF: R-58015-48175 The two-byte integer at offset 5 designates
  ** the start of the cell content area. A zero value for this integer is
  ** interpreted as 65536. */
  top = get2byteNotZero(&data[hdr+5]);
  /* EVIDENCE-OF: R-37002-32774 The two-byte integer at offset 3 gives the
  ** number of cells on the page. */
  pPage->nCell = get2byte(&data[hdr+3]);
  if( pPage->nCell>MX_CELL(pBt) ){
    /* To many cells for a single page.  The page must be corrupt */
    return SQLITE_CORRUPT_PAGE(pPage);
  }
  testcase( pPage->nCell==MX_CELL(pBt) );
  /* EVIDENCE-OF: R-24089-57979 If a page contains no cells (which is only
  ** possible for a root page of a table that contains no rows) then the
  ** offset to the cell content area will equal the page size minus the
  ** bytes of reserved space. */
  assert( pPage->nCell>0 || top==usableSize || CORRUPT_DB );

  iCellFirst = hdr + 8 + pPage->childPtrSize + 2*pPage->nCell;
  /* A malformed database page might cause us to read past the end
  ** of page when parsing a cell.  
  **
  ** The following block of code checks early to see if a cell extends
  ** past the end of a page boundary and causes SQLITE_CORRUPT to be 
  ** returned if it does.
  */
  iCellFirst = cellOffset + 2*pPage->nCell;
  iCellLast = usableSize - 4;
  if( pBt->db->flags & SQLITE_CellSizeCk ){
    int i;            /* Index into the cell pointer array */
    int sz;           /* Size of a cell */

    if( !pPage->leaf ) iCellLast--;
    for(i=0; i<pPage->nCell; i++){
      pc = get2byteAligned(&data[cellOffset+i*2]);
      testcase( pc==iCellFirst );
      testcase( pc==iCellLast );
      if( pc<iCellFirst || pc>iCellLast ){
        return SQLITE_CORRUPT_PAGE(pPage);
      }
      sz = pPage->xCellSize(pPage, &data[pc]);
      testcase( pc+sz==usableSize );
      if( pc+sz>usableSize ){
        return SQLITE_CORRUPT_PAGE(pPage);
      }
    }
    if( !pPage->leaf ) iCellLast++;
  }  

  /* Compute the total free space on the page
  ** EVIDENCE-OF: R-23588-34450 The two-byte integer at offset 1 gives the
  ** start of the first freeblock on the page, or is zero if there are no
  ** freeblocks. */
  pc = get2byte(&data[hdr+1]);
  nFree = data[hdr+7] + top;  /* Init nFree to non-freeblock free space */
65024
65025
65026
65027
65028
65029
65030


























































































65031



65032
65033
65034
65035
65036
65037
65038
65100
65101
65102
65103
65104
65105
65106
65107
65108
65109
65110
65111
65112
65113
65114
65115
65116
65117
65118
65119
65120
65121
65122
65123
65124
65125
65126
65127
65128
65129
65130
65131
65132
65133
65134
65135
65136
65137
65138
65139
65140
65141
65142
65143
65144
65145
65146
65147
65148
65149
65150
65151
65152
65153
65154
65155
65156
65157
65158
65159
65160
65161
65162
65163
65164
65165
65166
65167
65168
65169
65170
65171
65172
65173
65174
65175
65176
65177
65178
65179
65180
65181
65182
65183
65184
65185
65186
65187
65188
65189
65190
65191
65192
65193
65194
65195
65196
65197
65198
65199
65200
65201
65202
65203
65204
65205
65206
65207







+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+

+
+
+







  ** serves to verify that the offset to the start of the cell-content
  ** area, according to the page header, lies within the page.
  */
  if( nFree>usableSize ){
    return SQLITE_CORRUPT_PAGE(pPage);
  }
  pPage->nFree = (u16)(nFree - iCellFirst);
  return SQLITE_OK;
}

/*
** Do additional sanity check after btreeInitPage() if
** PRAGMA cell_size_check=ON 
*/
static SQLITE_NOINLINE int btreeCellSizeCheck(MemPage *pPage){
  int iCellFirst;    /* First allowable cell or freeblock offset */
  int iCellLast;     /* Last possible cell or freeblock offset */
  int i;             /* Index into the cell pointer array */
  int sz;            /* Size of a cell */
  int pc;            /* Address of a freeblock within pPage->aData[] */
  u8 *data;          /* Equal to pPage->aData */
  int usableSize;    /* Maximum usable space on the page */
  int cellOffset;    /* Start of cell content area */

  iCellFirst = pPage->cellOffset + 2*pPage->nCell;
  usableSize = pPage->pBt->usableSize;
  iCellLast = usableSize - 4;
  data = pPage->aData;
  cellOffset = pPage->cellOffset;
  if( !pPage->leaf ) iCellLast--;
  for(i=0; i<pPage->nCell; i++){
    pc = get2byteAligned(&data[cellOffset+i*2]);
    testcase( pc==iCellFirst );
    testcase( pc==iCellLast );
    if( pc<iCellFirst || pc>iCellLast ){
      return SQLITE_CORRUPT_PAGE(pPage);
    }
    sz = pPage->xCellSize(pPage, &data[pc]);
    testcase( pc+sz==usableSize );
    if( pc+sz>usableSize ){
      return SQLITE_CORRUPT_PAGE(pPage);
    }
  }
  return SQLITE_OK;
}

/*
** Initialize the auxiliary information for a disk block.
**
** Return SQLITE_OK on success.  If we see that the page does
** not contain a well-formed database page, then return 
** SQLITE_CORRUPT.  Note that a return of SQLITE_OK does not
** guarantee that the page is well-formed.  It only shows that
** we failed to detect any corruption.
*/
static int btreeInitPage(MemPage *pPage){
  u8 *data;          /* Equal to pPage->aData */
  BtShared *pBt;        /* The main btree structure */

  assert( pPage->pBt!=0 );
  assert( pPage->pBt->db!=0 );
  assert( sqlite3_mutex_held(pPage->pBt->mutex) );
  assert( pPage->pgno==sqlite3PagerPagenumber(pPage->pDbPage) );
  assert( pPage == sqlite3PagerGetExtra(pPage->pDbPage) );
  assert( pPage->aData == sqlite3PagerGetData(pPage->pDbPage) );
  assert( pPage->isInit==0 );

  pBt = pPage->pBt;
  data = pPage->aData + pPage->hdrOffset;
  /* EVIDENCE-OF: R-28594-02890 The one-byte flag at offset 0 indicating
  ** the b-tree page type. */
  if( decodeFlags(pPage, data[0]) ){
    return SQLITE_CORRUPT_PAGE(pPage);
  }
  assert( pBt->pageSize>=512 && pBt->pageSize<=65536 );
  pPage->maskPage = (u16)(pBt->pageSize - 1);
  pPage->nOverflow = 0;
  pPage->cellOffset = pPage->hdrOffset + 8 + pPage->childPtrSize;
  pPage->aCellIdx = data + pPage->childPtrSize + 8;
  pPage->aDataEnd = pPage->aData + pBt->usableSize;
  pPage->aDataOfst = pPage->aData + pPage->childPtrSize;
  /* EVIDENCE-OF: R-37002-32774 The two-byte integer at offset 3 gives the
  ** number of cells on the page. */
  pPage->nCell = get2byte(&data[3]);
  if( pPage->nCell>MX_CELL(pBt) ){
    /* To many cells for a single page.  The page must be corrupt */
    return SQLITE_CORRUPT_PAGE(pPage);
  }
  testcase( pPage->nCell==MX_CELL(pBt) );
  /* EVIDENCE-OF: R-24089-57979 If a page contains no cells (which is only
  ** possible for a root page of a table that contains no rows) then the
  ** offset to the cell content area will equal the page size minus the
  ** bytes of reserved space. */
  assert( pPage->nCell>0
       || get2byteNotZero(&data[5])==(int)pBt->usableSize
       || CORRUPT_DB );
  pPage->nFree = -1;  /* Indicate that this value is yet uncomputed */
  pPage->isInit = 1;
  if( pBt->db->flags & SQLITE_CellSizeCk ){
    return btreeCellSizeCheck(pPage);
  }
  return SQLITE_OK;
}

/*
** Set up a raw page so that it looks like a database page holding
** no entries.
*/
65167
65168
65169
65170
65171
65172
65173
65174

65175
65176
65177
65178

65179
65180
65181
65182
65183
65184
65185
65186

65187
65188
65189
65190
65191
65192
65193
65194
65195
65196
65197

65198
65199
65200
65201



65202
65203
65204
65205
65206
65207
65208
65336
65337
65338
65339
65340
65341
65342

65343
65344
65345
65346

65347
65348
65349
65350
65351
65352
65353


65354
65355
65356
65357
65358
65359
65360
65361
65362
65363


65364
65365
65366
65367

65368
65369
65370
65371
65372
65373
65374
65375
65376
65377







-
+



-
+






-
-
+









-
-
+



-
+
+
+







  assert( sqlite3_mutex_held(pBt->mutex) );
  assert( pCur==0 || ppPage==&pCur->pPage );
  assert( pCur==0 || bReadOnly==pCur->curPagerFlags );
  assert( pCur==0 || pCur->iPage>0 );

  if( pgno>btreePagecount(pBt) ){
    rc = SQLITE_CORRUPT_BKPT;
    goto getAndInitPage_error;
    goto getAndInitPage_error1;
  }
  rc = sqlite3PagerGet(pBt->pPager, pgno, (DbPage**)&pDbPage, bReadOnly);
  if( rc ){
    goto getAndInitPage_error;
    goto getAndInitPage_error1;
  }
  *ppPage = (MemPage*)sqlite3PagerGetExtra(pDbPage);
  if( (*ppPage)->isInit==0 ){
    btreePageFromDbPage(pDbPage, pgno, pBt);
    rc = btreeInitPage(*ppPage);
    if( rc!=SQLITE_OK ){
      releasePage(*ppPage);
      goto getAndInitPage_error;
      goto getAndInitPage_error2;
    }
  }
  assert( (*ppPage)->pgno==pgno );
  assert( (*ppPage)->aData==sqlite3PagerGetData(pDbPage) );

  /* If obtaining a child page for a cursor, we must verify that the page is
  ** compatible with the root page. */
  if( pCur && ((*ppPage)->nCell<1 || (*ppPage)->intKey!=pCur->curIntKey) ){
    rc = SQLITE_CORRUPT_PGNO(pgno);
    releasePage(*ppPage);
    goto getAndInitPage_error;
    goto getAndInitPage_error2;
  }
  return SQLITE_OK;

getAndInitPage_error:
getAndInitPage_error2:
  releasePage(*ppPage);
getAndInitPage_error1:
  if( pCur ){
    pCur->iPage--;
    pCur->pPage = pCur->apPage[pCur->iPage];
  }
  testcase( pgno==0 );
  assert( pgno!=0 || rc==SQLITE_CORRUPT );
  return rc;
68275
68276
68277
68278
68279
68280
68281
68282
68283
68284
68285
68286
68287
68288
68289
68290
68291
68292
68293
68294
68295
68296
68297
68298
68299
68300
68301
68302
68303
68304
68305
68444
68445
68446
68447
68448
68449
68450

















68451
68452
68453
68454
68455
68456
68457







-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-







    assert( pCur->pgnoRoot==0 || pCur->pPage->nCell==0 );
    *pRes = 1;
    rc = SQLITE_OK;
  }
  return rc;
}

/*
** This function is a no-op if cursor pCur does not point to a valid row.
** Otherwise, if pCur is valid, configure it so that the next call to
** sqlite3BtreeNext() is a no-op.
*/
#ifndef SQLITE_OMIT_WINDOWFUNC
SQLITE_PRIVATE void sqlite3BtreeSkipNext(BtCursor *pCur){
  /* We believe that the cursor must always be in the valid state when
  ** this routine is called, but the proof is difficult, so we add an
  ** ALWaYS() test just in case we are wrong. */
  if( ALWAYS(pCur->eState==CURSOR_VALID) ){
    pCur->eState = CURSOR_SKIPNEXT;
    pCur->skipNext = 1;
  }
}
#endif /* SQLITE_OMIT_WINDOWFUNC */

/* Move the cursor to the last entry in the table.  Return SQLITE_OK
** on success.  Set *pRes to 0 if the cursor actually points to something
** or set *pRes to 1 if the table is empty.
*/
SQLITE_PRIVATE int sqlite3BtreeLast(BtCursor *pCur, int *pRes){
  int rc;
 
68557
68558
68559
68560
68561
68562
68563
68564

68565
68566
68567
68568
68569
68570
68571
68709
68710
68711
68712
68713
68714
68715

68716
68717
68718
68719
68720
68721
68722
68723







-
+







          pCur->ix = (u16)idx;
          rc = accessPayload(pCur, 0, nCell, (unsigned char*)pCellKey, 0);
          pCur->curFlags &= ~BTCF_ValidOvfl;
          if( rc ){
            sqlite3_free(pCellKey);
            goto moveto_finish;
          }
          c = xRecordCompare(nCell, pCellKey, pIdxKey);
          c = sqlite3VdbeRecordCompare(nCell, pCellKey, pIdxKey);
          sqlite3_free(pCellKey);
        }
        assert( 
            (pIdxKey->errCode!=SQLITE_CORRUPT || c==0)
         && (pIdxKey->errCode!=SQLITE_NOMEM || pCur->pBtree->db->mallocFailed)
        );
        if( c<0 ){
69189
69190
69191
69192
69193
69194
69195
69196

69197
69198
69199
69200
69201

69202


69203
69204
69205
69206
69207
69208
69209
69341
69342
69343
69344
69345
69346
69347

69348
69349
69350
69351
69352
69353
69354

69355
69356
69357
69358
69359
69360
69361
69362
69363







-
+





+
-
+
+







*/
static int freePage2(BtShared *pBt, MemPage *pMemPage, Pgno iPage){
  MemPage *pTrunk = 0;                /* Free-list trunk page */
  Pgno iTrunk = 0;                    /* Page number of free-list trunk page */ 
  MemPage *pPage1 = pBt->pPage1;      /* Local reference to page 1 */
  MemPage *pPage;                     /* Page being freed. May be NULL. */
  int rc;                             /* Return Code */
  int nFree;                          /* Initial number of pages on free-list */
  u32 nFree;                          /* Initial number of pages on free-list */

  assert( sqlite3_mutex_held(pBt->mutex) );
  assert( CORRUPT_DB || iPage>1 );
  assert( !pMemPage || pMemPage->pgno==iPage );

  if( iPage<2 || iPage>pBt->nPage ){
  if( iPage<2 ) return SQLITE_CORRUPT_BKPT;
    return SQLITE_CORRUPT_BKPT;
  }
  if( pMemPage ){
    pPage = pMemPage;
    sqlite3PagerRef(pPage->pDbPage);
  }else{
    pPage = btreePageLookup(pBt, iPage);
  }

69606
69607
69608
69609
69610
69611
69612

69613
69614
69615
69616
69617
69618
69619
69760
69761
69762
69763
69764
69765
69766
69767
69768
69769
69770
69771
69772
69773
69774







+







  int hdr;        /* Beginning of the header.  0 most pages.  100 page 1 */

  if( *pRC ) return;
  assert( idx>=0 && idx<pPage->nCell );
  assert( CORRUPT_DB || sz==cellSize(pPage, idx) );
  assert( sqlite3PagerIswriteable(pPage->pDbPage) );
  assert( sqlite3_mutex_held(pPage->pBt->mutex) );
  assert( pPage->nFree>=0 );
  data = pPage->aData;
  ptr = &pPage->aCellIdx[2*idx];
  pc = get2byte(ptr);
  hdr = pPage->hdrOffset;
  testcase( pc==get2byte(&data[hdr+5]) );
  testcase( pc+sz==pPage->pBt->usableSize );
  if( pc+sz > pPage->pBt->usableSize ){
69676
69677
69678
69679
69680
69681
69682

69683
69684
69685
69686
69687
69688
69689
69831
69832
69833
69834
69835
69836
69837
69838
69839
69840
69841
69842
69843
69844
69845







+







  assert( sqlite3_mutex_held(pPage->pBt->mutex) );
  /* The cell should normally be sized correctly.  However, when moving a
  ** malformed cell from a leaf page to an interior page, if the cell size
  ** wanted to be less than 4 but got rounded up to 4 on the leaf, then size
  ** might be less than 8 (leaf-size + pointer) on the interior node.  Hence
  ** the term after the || in the following assert(). */
  assert( sz==pPage->xCellSize(pPage, pCell) || (sz==8 && iChild>0) );
  assert( pPage->nFree>=0 );
  if( pPage->nOverflow || sz+2>pPage->nFree ){
    if( pTemp ){
      memcpy(pTemp, pCell, sz);
      pCell = pTemp;
    }
    if( iChild ){
      put4byte(pCell, iChild);
69733
69734
69735
69736
69737
69738
69739
69740

69741
69742
69743
69744
69745
69746
69747
69889
69890
69891
69892
69893
69894
69895

69896
69897
69898
69899
69900
69901
69902
69903







-
+







    }
    pIns = pPage->aCellIdx + i*2;
    memmove(pIns+2, pIns, 2*(pPage->nCell - i));
    put2byte(pIns, idx);
    pPage->nCell++;
    /* increment the cell count */
    if( (++data[pPage->hdrOffset+4])==0 ) data[pPage->hdrOffset+3]++;
    assert( get2byte(&data[pPage->hdrOffset+3])==pPage->nCell );
    assert( get2byte(&data[pPage->hdrOffset+3])==pPage->nCell || CORRUPT_DB );
#ifndef SQLITE_OMIT_AUTOVACUUM
    if( pPage->pBt->autoVacuum ){
      /* The cell may contain a pointer to an overflow page. If so, write
      ** the entry for the overflow page into the pointer map.
      */
      ptrmapPutOvflPtr(pPage, pPage, pCell, pRC);
    }
69820
69821
69822
69823
69824
69825
69826
69827
69828







69829
69830
69831
69832
69833
69834
69835
69976
69977
69978
69979
69980
69981
69982


69983
69984
69985
69986
69987
69988
69989
69990
69991
69992
69993
69994
69995
69996







-
-
+
+
+
+
+
+
+







**    ixNx[3] = Number of cells in Child-1 and Child-2 + both divider cells
**    ixNx[4] = Total number of cells.
**
** For a table-btree, the concept is similar, except only apEnd[0]..apEnd[2]
** are used and they point to the leaf pages only, and the ixNx value are:
**
**    ixNx[0] = Number of cells in Child-1.
**    ixNx[1] = Number of cells in Child-1 and Child-2 + 1 for 1st divider.
**    ixNx[2] = Number of cells in Child-1 and Child-2 + both divider cells
**    ixNx[1] = Number of cells in Child-1 and Child-2.
**    ixNx[2] = Total number of cells.
**
** Sometimes when deleting, a child page can have zero cells.  In those
** cases, ixNx[] entries with higher indexes, and the corresponding apEnd[]
** entries, shift down.  The end result is that each ixNx[] entry should
** be larger than the previous
*/
typedef struct CellArray CellArray;
struct CellArray {
  int nCell;              /* Number of cells in apCell[] */
  MemPage *pRef;          /* Reference page */
  u8 **apCell;            /* All cells begin balanced */
  u16 *szCell;            /* Local size of all cells in apCell[] */
70150
70151
70152
70153
70154
70155
70156
70157
70158



70159
70160
70161
70162
70163
70164
70165
70311
70312
70313
70314
70315
70316
70317


70318
70319
70320
70321
70322
70323
70324
70325
70326
70327







-
-
+
+
+







  }

  /* Add any overflow cells */
  for(i=0; i<pPg->nOverflow; i++){
    int iCell = (iOld + pPg->aiOvfl[i]) - iNew;
    if( iCell>=0 && iCell<nNew ){
      pCellptr = &pPg->aCellIdx[iCell * 2];
      assert( nCell>=iCell );
      memmove(&pCellptr[2], pCellptr, (nCell - iCell) * 2);
      if( nCell>iCell ){
        memmove(&pCellptr[2], pCellptr, (nCell - iCell) * 2);
      }
      nCell++;
      if( pageInsertArray(
            pPg, pBegin, &pData, pCellptr,
            iCell+iNew, 1, pCArray
      ) ) goto editpage_fail;
    }
  }
70227
70228
70229
70230
70231
70232
70233
70234

70235


70236
70237
70238
70239
70240
70241
70242
70389
70390
70391
70392
70393
70394
70395

70396
70397
70398
70399
70400
70401
70402
70403
70404
70405
70406







-
+

+
+







  MemPage *pNew;                       /* Newly allocated page */
  int rc;                              /* Return Code */
  Pgno pgnoNew;                        /* Page number of pNew */

  assert( sqlite3_mutex_held(pPage->pBt->mutex) );
  assert( sqlite3PagerIswriteable(pParent->pDbPage) );
  assert( pPage->nOverflow==1 );

  
  if( pPage->nCell==0 ) return SQLITE_CORRUPT_BKPT;  /* dbfuzz001.test */
  assert( pPage->nFree>=0 );
  assert( pParent->nFree>=0 );

  /* Allocate a new page. This page will become the right-sibling of 
  ** pPage. Make the parent page writable, so that the new divider cell
  ** may be inserted. If both these operations are successful, proceed.
  */
  rc = allocateBtreePage(pBt, &pNew, &pgnoNew, 0, 0);

70398
70399
70400
70401
70402
70403
70404

70405
70406
70407
70408
70409
70410
70411
70562
70563
70564
70565
70566
70567
70568
70569
70570
70571
70572
70573
70574
70575
70576







+







    /* Reinitialize page pTo so that the contents of the MemPage structure
    ** match the new data. The initialization of pTo can actually fail under
    ** fairly obscure circumstances, even though it is a copy of initialized 
    ** page pFrom.
    */
    pTo->isInit = 0;
    rc = btreeInitPage(pTo);
    if( rc==SQLITE_OK ) rc = btreeComputeFreeSpace(pTo);
    if( rc!=SQLITE_OK ){
      *pRC = rc;
      return;
    }
  
    /* If this is an auto-vacuum database, update the pointer-map entries
    ** for any b-tree or overflow pages that pTo now contains the pointers to.
70506
70507
70508
70509
70510
70511
70512

70513
70514
70515
70516
70517
70518
70519
70671
70672
70673
70674
70675
70676
70677
70678
70679
70680
70681
70682
70683
70684
70685







+







  */
  assert( pParent->nOverflow==0 || pParent->nOverflow==1 );
  assert( pParent->nOverflow==0 || pParent->aiOvfl[0]==iParentIdx );

  if( !aOvflSpace ){
    return SQLITE_NOMEM_BKPT;
  }
  assert( pParent->nFree>=0 );

  /* Find the sibling pages to balance. Also locate the cells in pParent 
  ** that divide the siblings. An attempt is made to find NN siblings on 
  ** either side of pPage. More siblings are taken from one side, however, 
  ** if there are fewer than NN siblings on the other side. If pParent
  ** has NB or fewer children then all children of pParent are taken.  
  **
70545
70546
70547
70548
70549
70550
70551
70552







70553
70554
70555
70556
70557
70558
70559
70711
70712
70713
70714
70715
70716
70717

70718
70719
70720
70721
70722
70723
70724
70725
70726
70727
70728
70729
70730
70731







-
+
+
+
+
+
+
+







  pgno = get4byte(pRight);
  while( 1 ){
    rc = getAndInitPage(pBt, pgno, &apOld[i], 0, 0);
    if( rc ){
      memset(apOld, 0, (i+1)*sizeof(MemPage*));
      goto balance_cleanup;
    }
    nMaxCells += 1+apOld[i]->nCell+apOld[i]->nOverflow;
    if( apOld[i]->nFree<0 ){
      rc = btreeComputeFreeSpace(apOld[i]);
      if( rc ){
        memset(apOld, 0, (i)*sizeof(MemPage*));
        goto balance_cleanup;
      }
    }
    if( (i--)==0 ) break;

    if( pParent->nOverflow && i+nxDiv==pParent->aiOvfl[0] ){
      apDiv[i] = pParent->apOvfl[0];
      pgno = get4byte(apDiv[i]);
      szNew[i] = pParent->xCellSize(pParent, apDiv[i]);
      pParent->nOverflow = 0;
70589
70590
70591
70592
70593
70594
70595

70596
70597
70598
70599
70600
70601
70602
70603
70604
70605
70606

70607
70608
70609
70610
70611
70612
70613
70761
70762
70763
70764
70765
70766
70767
70768
70769
70770
70771
70772
70773
70774
70775
70776
70777
70778

70779
70780
70781
70782
70783
70784
70785
70786







+










-
+







      }
      dropCell(pParent, i+nxDiv-pParent->nOverflow, szNew[i], &rc);
    }
  }

  /* Make nMaxCells a multiple of 4 in order to preserve 8-byte
  ** alignment */
  nMaxCells = nOld*(MX_CELL(pBt) + ArraySize(pParent->apOvfl));
  nMaxCells = (nMaxCells + 3)&~3;

  /*
  ** Allocate space for memory structures
  */
  szScratch =
       nMaxCells*sizeof(u8*)                       /* b.apCell */
     + nMaxCells*sizeof(u16)                       /* b.szCell */
     + pBt->pageSize;                              /* aSpace1 */

  assert( szScratch<=6*(int)pBt->pageSize );
  assert( szScratch<=7*(int)pBt->pageSize );
  b.apCell = sqlite3StackAllocRaw(0, szScratch );
  if( b.apCell==0 ){
    rc = SQLITE_NOMEM_BKPT;
    goto balance_cleanup;
  }
  b.szCell = (u16*)&b.apCell[nMaxCells];
  aSpace1 = (u8*)&b.szCell[nMaxCells];
70739
70740
70741
70742
70743
70744
70745



70746
70747
70748
70749
70750

70751
70752
70753
70754
70755
70756
70757
70912
70913
70914
70915
70916
70917
70918
70919
70920
70921
70922
70923
70924
70925
70926
70927
70928
70929
70930
70931
70932
70933
70934







+
+
+





+







  ** 
  */
  usableSpace = pBt->usableSize - 12 + leafCorrection;
  for(i=k=0; i<nOld; i++, k++){
    MemPage *p = apOld[i];
    b.apEnd[k] = p->aDataEnd;
    b.ixNx[k] = cntOld[i];
    if( k && b.ixNx[k]==b.ixNx[k-1] ){
      k--;  /* Omit b.ixNx[] entry for child pages with no cells */
    }
    if( !leafData ){
      k++;
      b.apEnd[k] = pParent->aDataEnd;
      b.ixNx[k] = cntOld[i]+1;
    }
    assert( p->nFree>=0 );
    szNew[i] = usableSpace - p->nFree;
    for(j=0; j<p->nOverflow; j++){
      szNew[i] += 2 + p->xCellSize(p, p->apOvfl[j]);
    }
    cntNew[i] = cntOld[i];
  }
  k = nOld;
70969
70970
70971
70972
70973
70974
70975
70976
70977
70978
70979
70980
70981
70982
70983
70984
70985




70986
70987
70988
70989
70990
70991
70992
70993
70994
70995
70996
70997
70998
70999
71000
71001
71002

71003
71004
71005
71006
71007
71008
71009
71146
71147
71148
71149
71150
71151
71152

71153

71154
71155
71156
71157
71158


71159
71160
71161
71162
71163

71164
71165
71166
71167
71168
71169
71170
71171
71172
71173
71174
71175
71176
71177

71178
71179
71180
71181
71182
71183
71184
71185







-

-





-
-
+
+
+
+

-














-
+







  ** associated with the right-child of each sibling may also need to be 
  ** updated. This happens below, after the sibling pages have been 
  ** populated, not here.
  */
  if( ISAUTOVACUUM ){
    MemPage *pOld;
    MemPage *pNew = pOld = apNew[0];
    u8 *aOld = pNew->aData;
    int cntOldNext = pNew->nCell + pNew->nOverflow;
    int usableSize = pBt->usableSize;
    int iNew = 0;
    int iOld = 0;

    for(i=0; i<b.nCell; i++){
      u8 *pCell = b.apCell[i];
      if( i==cntOldNext ){
        pOld = (++iOld)<nNew ? apNew[iOld] : apOld[iOld];
      while( i==cntOldNext ){
        iOld++;
        assert( iOld<nNew || iOld<nOld );
        pOld = iOld<nNew ? apNew[iOld] : apOld[iOld];
        cntOldNext += pOld->nCell + pOld->nOverflow + !leafData;
        aOld = pOld->aData;
      }
      if( i==cntNew[iNew] ){
        pNew = apNew[++iNew];
        if( !leafData ) continue;
      }

      /* Cell pCell is destined for new sibling page pNew. Originally, it
      ** was either part of sibling page iOld (possibly an overflow cell), 
      ** or else the divider cell to the left of sibling page iOld. So,
      ** if sibling page iOld had the same page number as pNew, and if
      ** pCell really was a part of sibling page iOld (not a divider or
      ** overflow cell), we can skip updating the pointer map entries.  */
      if( iOld>=nNew
       || pNew->pgno!=aPgno[iOld]
       || !SQLITE_WITHIN(pCell,aOld,&aOld[usableSize])
       || !SQLITE_WITHIN(pCell,pOld->aData,pOld->aDataEnd)
      ){
        if( !leafCorrection ){
          ptrmapPut(pBt, get4byte(pCell), PTRMAP_BTREE, pNew->pgno, &rc);
        }
        if( cachedCellSize(&b,i)>pNew->minLocal ){
          ptrmapPutOvflPtr(pNew, pOld, pCell, &rc);
        }
71146
71147
71148
71149
71150
71151
71152

71153

71154
71155
71156
71157
71158
71159
71160
71322
71323
71324
71325
71326
71327
71328
71329

71330
71331
71332
71333
71334
71335
71336
71337







+
-
+







    ** by smaller than the child due to the database header, and so all the
    ** free space needs to be up front.
    */
    assert( nNew==1 || CORRUPT_DB );
    rc = defragmentPage(apNew[0], -1);
    testcase( rc!=SQLITE_OK );
    assert( apNew[0]->nFree == 
        (get2byteNotZero(&apNew[0]->aData[5]) - apNew[0]->cellOffset
        (get2byte(&apNew[0]->aData[5])-apNew[0]->cellOffset-apNew[0]->nCell*2)
          - apNew[0]->nCell*2)
      || rc!=SQLITE_OK
    );
    copyNodeContent(apNew[0], pParent, &rc);
    freePage(apNew[0], &rc);
  }else if( ISAUTOVACUUM && !leafCorrection ){
    /* Fix the pointer map entries associated with the right-child of each
    ** sibling page. All other pointer map entries have already been taken
71245
71246
71247
71248
71249
71250
71251
71252

71253
71254
71255
71256
71257
71258
71259
71422
71423
71424
71425
71426
71427
71428

71429
71430
71431
71432
71433
71434
71435
71436







-
+







  if( rc ){
    *ppChild = 0;
    releasePage(pChild);
    return rc;
  }
  assert( sqlite3PagerIswriteable(pChild->pDbPage) );
  assert( sqlite3PagerIswriteable(pRoot->pDbPage) );
  assert( pChild->nCell==pRoot->nCell );
  assert( pChild->nCell==pRoot->nCell || CORRUPT_DB );

  TRACE(("BALANCE: copy root %d into %d\n", pRoot->pgno, pChild->pgno));

  /* Copy the overflow cells from pRoot to pChild */
  memcpy(pChild->aiOvfl, pRoot->aiOvfl,
         pRoot->nOverflow*sizeof(pRoot->aiOvfl[0]));
  memcpy(pChild->apOvfl, pRoot->apOvfl,
71287
71288
71289
71290
71291
71292
71293

71294
71295
71296
71297
71298
71299
71300
71464
71465
71466
71467
71468
71469
71470
71471
71472
71473
71474
71475
71476
71477
71478







+







  VVA_ONLY( int balance_quick_called = 0 );
  VVA_ONLY( int balance_deeper_called = 0 );

  do {
    int iPage = pCur->iPage;
    MemPage *pPage = pCur->pPage;

    if( NEVER(pPage->nFree<0) && btreeComputeFreeSpace(pPage) ) break;
    if( iPage==0 ){
      if( pPage->nOverflow ){
        /* The root page of the b-tree is overfull. In this case call the
        ** balance_deeper() function to create a new child for the root-page
        ** and copy the current contents of the root-page to it. The
        ** next iteration of the do-loop will balance the child page.
        */ 
71315
71316
71317
71318
71319
71320
71321



71322
71323
71324
71325
71326
71327
71328
71493
71494
71495
71496
71497
71498
71499
71500
71501
71502
71503
71504
71505
71506
71507
71508
71509







+
+
+







    }else if( pPage->nOverflow==0 && pPage->nFree<=nMin ){
      break;
    }else{
      MemPage * const pParent = pCur->apPage[iPage-1];
      int const iIdx = pCur->aiIdx[iPage-1];

      rc = sqlite3PagerWrite(pParent->pDbPage);
      if( rc==SQLITE_OK && pParent->nFree<0 ){
        rc = btreeComputeFreeSpace(pParent);
      }
      if( rc==SQLITE_OK ){
#ifndef SQLITE_OMIT_QUICKBALANCE
        if( pPage->intKeyLeaf
         && pPage->nOverflow==1
         && pPage->aiOvfl[0]==pPage->nCell
         && pParent->pgno!=1
         && pParent->nCell==iIdx
71661
71662
71663
71664
71665
71666
71667




71668
71669
71670
71671
71672
71673
71674
71842
71843
71844
71845
71846
71847
71848
71849
71850
71851
71852
71853
71854
71855
71856
71857
71858
71859







+
+
+
+








  }
  assert( pCur->eState==CURSOR_VALID || (pCur->eState==CURSOR_INVALID && loc) );

  pPage = pCur->pPage;
  assert( pPage->intKey || pX->nKey>=0 );
  assert( pPage->leaf || !pPage->intKey );
  if( pPage->nFree<0 ){
    rc = btreeComputeFreeSpace(pPage);
    if( rc ) return rc;
  }

  TRACE(("INSERT: table=%d nkey=%lld ndata=%d page=%d %s\n",
          pCur->pgnoRoot, pX->nKey, pX->nData, pPage->pgno,
          loc==0 ? "overwrite" : "new entry"));
  assert( pPage->isInit );
  newCell = pBt->pTmpSpace;
  assert( newCell!=0 );
71803
71804
71805
71806
71807
71808
71809

71810




71811
71812
71813
71814
71815
71816
71817

71818
71819
71820
71821
71822
71823
71824
71988
71989
71990
71991
71992
71993
71994
71995

71996
71997
71998
71999
72000

72001
72002
72003
72004
72005
72006
72007
72008
72009
72010
72011
72012
72013







+
-
+
+
+
+

-





+








  assert( cursorOwnsBtShared(pCur) );
  assert( pBt->inTransaction==TRANS_WRITE );
  assert( (pBt->btsFlags & BTS_READ_ONLY)==0 );
  assert( pCur->curFlags & BTCF_WriteFlag );
  assert( hasSharedCacheTableLock(p, pCur->pgnoRoot, pCur->pKeyInfo!=0, 2) );
  assert( !hasReadConflicts(p, pCur->pgnoRoot) );
  assert( (flags & ~(BTREE_SAVEPOSITION | BTREE_AUXDELETE))==0 );
  assert( pCur->ix<pCur->pPage->nCell );
  if( pCur->eState==CURSOR_REQUIRESEEK ){
    rc = btreeRestoreCursorPosition(pCur);
    if( rc ) return rc;
  }
  assert( pCur->eState==CURSOR_VALID );
  assert( (flags & ~(BTREE_SAVEPOSITION | BTREE_AUXDELETE))==0 );

  iCellDepth = pCur->iPage;
  iCellIdx = pCur->ix;
  pPage = pCur->pPage;
  pCell = findCell(pPage, iCellIdx);
  if( pPage->nFree<0 && btreeComputeFreeSpace(pPage) ) return SQLITE_CORRUPT;

  /* If the bPreserve flag is set to true, then the cursor position must
  ** be preserved following this delete operation. If the current delete
  ** will cause a b-tree rebalance, then this is done by saving the cursor
  ** key and leaving the cursor in CURSOR_REQUIRESEEK state before 
  ** returning. 
  **
71881
71882
71883
71884
71885
71886
71887




71888
71889
71890
71891
71892
71893
71894
72070
72071
72072
72073
72074
72075
72076
72077
72078
72079
72080
72081
72082
72083
72084
72085
72086
72087







+
+
+
+







  ** node to replace the deleted cell.  */
  if( !pPage->leaf ){
    MemPage *pLeaf = pCur->pPage;
    int nCell;
    Pgno n;
    unsigned char *pTmp;

    if( pLeaf->nFree<0 ){
      rc = btreeComputeFreeSpace(pLeaf);
      if( rc ) return rc;
    }
    if( iCellDepth<pCur->iPage-1 ){
      n = pCur->apPage[iCellDepth+1]->pgno;
    }else{
      n = pCur->pPage->pgno;
    }
    pCell = findCell(pLeaf, pLeaf->nCell-1);
    if( pCell<&pLeaf->aData[4] ) return SQLITE_CORRUPT_BKPT;
72239
72240
72241
72242
72243
72244
72245



72246
72247
72248
72249
72250
72251
72252
72432
72433
72434
72435
72436
72437
72438
72439
72440
72441
72442
72443
72444
72445
72446
72447
72448







+
+
+







  int rc;
  MemPage *pPage = 0;
  BtShared *pBt = p->pBt;

  assert( sqlite3BtreeHoldsMutex(p) );
  assert( p->inTrans==TRANS_WRITE );
  assert( iTable>=2 );
  if( iTable>btreePagecount(pBt) ){
    return SQLITE_CORRUPT_BKPT;
  }

  rc = btreeGetPage(pBt, (Pgno)iTable, &pPage, 0);
  if( rc ) return rc;
  rc = sqlite3BtreeClearTable(p, iTable, 0);
  if( rc ){
    releasePage(pPage);
    return rc;
72587
72588
72589
72590
72591
72592
72593
72594

72595
72596
72597

72598
72599
72600
72601
72602
72603
72604
72783
72784
72785
72786
72787
72788
72789

72790
72791
72792

72793
72794
72795
72796
72797
72798
72799
72800







-
+


-
+







** Check the integrity of the freelist or of an overflow page list.
** Verify that the number of pages on the list is N.
*/
static void checkList(
  IntegrityCk *pCheck,  /* Integrity checking context */
  int isFreeList,       /* True for a freelist.  False for overflow page list */
  int iPage,            /* Page number for first page in the list */
  int N                 /* Expected number of pages in the list */
  u32 N                 /* Expected number of pages in the list */
){
  int i;
  int expected = N;
  u32 expected = N;
  int nErrAtStart = pCheck->nErr;
  while( iPage!=0 && pCheck->mxErr ){
    DbPage *pOvflPage;
    unsigned char *pOvflData;
    if( checkRef(pCheck, iPage) ) break;
    N--;
    if( sqlite3PagerGet(pCheck->pPager, (Pgno)iPage, &pOvflPage, 0) ){
72772
72773
72774
72775
72776
72777
72778





72779
72780
72781
72782
72783
72784
72785
72968
72969
72970
72971
72972
72973
72974
72975
72976
72977
72978
72979
72980
72981
72982
72983
72984
72985
72986







+
+
+
+
+







  pPage->isInit = 0;
  if( (rc = btreeInitPage(pPage))!=0 ){
    assert( rc==SQLITE_CORRUPT );  /* The only possible error from InitPage */
    checkAppendMsg(pCheck,
                   "btreeInitPage() returns error code %d", rc);
    goto end_of_check;
  }
  if( (rc = btreeComputeFreeSpace(pPage))!=0 ){
    assert( rc==SQLITE_CORRUPT );
    checkAppendMsg(pCheck, "free space corruption", rc);
    goto end_of_check;
  }
  data = pPage->aData;
  hdr = pPage->hdrOffset;

  /* Set up for cell analysis */
  pCheck->zPfx = "On tree page %d cell %d: ";
  contentOffset = get2byteNotZero(&data[hdr+5]);
  assert( contentOffset<=usableSize );  /* Enforced by btreeInitPage() */
72844
72845
72846
72847
72848
72849
72850
72851

72852
72853
72854
72855
72856
72857
72858
73045
73046
73047
73048
73049
73050
73051

73052
73053
73054
73055
73056
73057
73058
73059







-
+







      }
      maxKey = info.nKey;
      keyCanBeEqual = 0;     /* Only the first key on the page may ==maxKey */
    }

    /* Check the content overflow list */
    if( info.nPayload>info.nLocal ){
      int nPage;       /* Number of pages on the overflow chain */
      u32 nPage;       /* Number of pages on the overflow chain */
      Pgno pgnoOvfl;   /* First page of the overflow chain */
      assert( pc + info.nSize - 4 <= usableSize );
      nPage = (info.nPayload - info.nLocal + usableSize - 5)/(usableSize - 4);
      pgnoOvfl = get4byte(&pCell[info.nSize - 4]);
#ifndef SQLITE_OMIT_AUTOVACUUM
      if( pBt->autoVacuum ){
        checkPtrmap(pCheck, pgnoOvfl, PTRMAP_OVERFLOW1, iPage);
72904
72905
72906
72907
72908
72909
72910
72911

72912
72913

72914
72915
72916
72917
72918
72919
72920
72921
72922
72923


72924
72925
72926
72927
72928
72929
72930
73105
73106
73107
73108
73109
73110
73111

73112
73113

73114
73115
73116
73117
73118
73119
73120
73121
73122


73123
73124
73125
73126
73127
73128
73129
73130
73131







-
+

-
+








-
-
+
+







    ** EVIDENCE-OF: R-20690-50594 The second field of the b-tree page header
    ** is the offset of the first freeblock, or zero if there are no
    ** freeblocks on the page. 
    */
    i = get2byte(&data[hdr+1]);
    while( i>0 ){
      int size, j;
      assert( (u32)i<=usableSize-4 );     /* Enforced by btreeInitPage() */
      assert( (u32)i<=usableSize-4 ); /* Enforced by btreeComputeFreeSpace() */
      size = get2byte(&data[i+2]);
      assert( (u32)(i+size)<=usableSize );  /* Enforced by btreeInitPage() */
      assert( (u32)(i+size)<=usableSize ); /* due to btreeComputeFreeSpace() */
      btreeHeapInsert(heap, (((u32)i)<<16)|(i+size-1));
      /* EVIDENCE-OF: R-58208-19414 The first 2 bytes of a freeblock are a
      ** big-endian integer which is the offset in the b-tree page of the next
      ** freeblock in the chain, or zero if the freeblock is the last on the
      ** chain. */
      j = get2byte(&data[i]);
      /* EVIDENCE-OF: R-06866-39125 Freeblocks are always connected in order of
      ** increasing offset. */
      assert( j==0 || j>i+size );  /* Enforced by btreeInitPage() */
      assert( (u32)j<=usableSize-4 );   /* Enforced by btreeInitPage() */
      assert( j==0 || j>i+size );     /* Enforced by btreeComputeFreeSpace() */
      assert( (u32)j<=usableSize-4 ); /* Enforced by btreeComputeFreeSpace() */
      i = j;
    }
    /* Analyze the min-heap looking for overlap between cells and/or 
    ** freeblocks, and counting the number of untracked bytes in nFrag.
    ** 
    ** Each min-heap entry is of the form:    (start_address<<16)|end_address.
    ** There is an implied first entry the covers the page header, the cell
74260
74261
74262
74263
74264
74265
74266
74267

74268
74269
74270
74271
74272
74273
74274
74461
74462
74463
74464
74465
74466
74467

74468
74469
74470
74471
74472
74473
74474
74475







-
+







      /* This is a pointer type.  There may be a flag to indicate what to
      ** do with the pointer. */
      assert( ((p->flags&MEM_Dyn)!=0 ? 1 : 0) +
              ((p->flags&MEM_Ephem)!=0 ? 1 : 0) +
              ((p->flags&MEM_Static)!=0 ? 1 : 0) <= 1 );

      /* No other bits set */
      assert( (p->flags & ~(MEM_Null|MEM_Term|MEM_Subtype
      assert( (p->flags & ~(MEM_Null|MEM_Term|MEM_Subtype|MEM_FromBind
                           |MEM_Dyn|MEM_Ephem|MEM_Static))==0 );
    }else{
      /* A pure NULL might have other flags, such as MEM_Static, MEM_Dyn,
      ** MEM_Ephem, MEM_Cleared, or MEM_Subtype */
    }
  }else{
    /* The MEM_Cleared bit is only allowed on NULLs */
74381
74382
74383
74384
74385
74386
74387
74388

74389
74390
74391
74392
74393
74394
74395
74396
74397
74398
74399
74400
74401
74402
74403




74404
74405
74406
74407
74408
74409
74410
74411
74412
74413
74414
74415
74582
74583
74584
74585
74586
74587
74588

74589

74590
74591
74592
74593
74594
74595
74596
74597
74598
74599
74600
74601
74602

74603
74604
74605
74606
74607
74608
74609
74610

74611
74612
74613
74614
74615
74616
74617







-
+
-













-
+
+
+
+




-







  assert(rc==SQLITE_OK    || pMem->enc!=desiredEnc);
  assert(rc==SQLITE_NOMEM || pMem->enc==desiredEnc);
  return rc;
#endif
}

/*
** Make sure pMem->z points to a writable allocation of at least 
** Make sure pMem->z points to a writable allocation of at least n bytes.
** min(n,32) bytes.
**
** If the bPreserve argument is true, then copy of the content of
** pMem->z into the new allocation.  pMem must be either a string or
** blob if bPreserve is true.  If bPreserve is false, any prior content
** in pMem->z is discarded.
*/
SQLITE_PRIVATE SQLITE_NOINLINE int sqlite3VdbeMemGrow(Mem *pMem, int n, int bPreserve){
  assert( sqlite3VdbeCheckMemInvariants(pMem) );
  assert( !sqlite3VdbeMemIsRowSet(pMem) );
  testcase( pMem->db==0 );

  /* If the bPreserve flag is set to true, then the memory cell must already
  ** contain a valid string or blob value.  */
  assert( bPreserve==0 || pMem->flags&(MEM_Blob|MEM_Str) );
  assert( bPreserve==0 
       || pMem->flags&(MEM_Blob|MEM_Str)
       || MemNullNochng(pMem)
  );
  testcase( bPreserve && pMem->z==0 );

  assert( pMem->szMalloc==0
       || pMem->szMalloc==sqlite3DbMallocSize(pMem->db, pMem->zMalloc) );
  if( n<32 ) n = 32;
  if( pMem->szMalloc>0 && bPreserve && pMem->z==pMem->zMalloc ){
    pMem->z = pMem->zMalloc = sqlite3DbReallocOrFree(pMem->db, pMem->z, n);
    bPreserve = 0;
  }else{
    if( pMem->szMalloc>0 ) sqlite3DbFreeNN(pMem->db, pMem->zMalloc);
    pMem->zMalloc = sqlite3DbMallocRaw(pMem->db, n);
  }
74503
74504
74505
74506
74507
74508
74509
74510


74511
74512
74513
74514
74515
74516
74517
74705
74706
74707
74708
74709
74710
74711

74712
74713
74714
74715
74716
74717
74718
74719
74720







-
+
+







** If the given Mem* has a zero-filled tail, turn it into an ordinary
** blob stored in dynamically allocated space.
*/
#ifndef SQLITE_OMIT_INCRBLOB
SQLITE_PRIVATE int sqlite3VdbeMemExpandBlob(Mem *pMem){
  int nByte;
  assert( pMem->flags & MEM_Zero );
  assert( pMem->flags&MEM_Blob );
  assert( (pMem->flags&MEM_Blob)!=0 || MemNullNochng(pMem) );
  testcase( sqlite3_value_nochange(pMem) );
  assert( !sqlite3VdbeMemIsRowSet(pMem) );
  assert( pMem->db==0 || sqlite3_mutex_held(pMem->db->mutex) );

  /* Set nByte to the number of bytes required to store the expanded blob. */
  nByte = pMem->n + pMem->u.nZero;
  if( nByte<=0 ){
    nByte = 1;
75250
75251
75252
75253
75254
75255
75256
75257
75258
75259
75260
75261
75262
75263
75264
75265
75266
75267
75268
75269

75270
75271
75272
75273
75274
75275
75276
75277
75278
75279

75280
75281
75282
75283
75284
75285
75286
75287
75288
75289




75290
75291



75292
75293
75294
75295
75296
75297
75298
75453
75454
75455
75456
75457
75458
75459

75460
75461
75462
75463
75464
75465
75466
75467
75468
75469
75470

75471
75472
75473
75474
75475
75476
75477
75478
75479
75480

75481
75482
75483
75484




75485
75486
75487
75488
75489
75490
75491


75492
75493
75494
75495
75496
75497
75498
75499
75500
75501







-











-
+









-
+



-
-
-
-



+
+
+
+
-
-
+
+
+







    iLimit = SQLITE_MAX_LENGTH;
  }
  flags = (enc==0?MEM_Blob:MEM_Str);
  if( nByte<0 ){
    assert( enc!=0 );
    if( enc==SQLITE_UTF8 ){
      nByte = 0x7fffffff & (int)strlen(z);
      if( nByte>iLimit ) nByte = iLimit+1;
    }else{
      for(nByte=0; nByte<=iLimit && (z[nByte] | z[nByte+1]); nByte+=2){}
    }
    flags |= MEM_Term;
  }

  /* The following block sets the new values of Mem.z and Mem.xDel. It
  ** also sets a flag in local variable "flags" to indicate the memory
  ** management (one of MEM_Dyn or MEM_Static).
  */
  if( xDel==SQLITE_TRANSIENT ){
    int nAlloc = nByte;
    u32 nAlloc = nByte;
    if( flags&MEM_Term ){
      nAlloc += (enc==SQLITE_UTF8?1:2);
    }
    if( nByte>iLimit ){
      return SQLITE_TOOBIG;
    }
    testcase( nAlloc==0 );
    testcase( nAlloc==31 );
    testcase( nAlloc==32 );
    if( sqlite3VdbeMemClearAndResize(pMem, MAX(nAlloc,32)) ){
    if( sqlite3VdbeMemClearAndResize(pMem, (int)MAX(nAlloc,32)) ){
      return SQLITE_NOMEM_BKPT;
    }
    memcpy(pMem->z, z, nAlloc);
  }else if( xDel==SQLITE_DYNAMIC ){
    sqlite3VdbeMemRelease(pMem);
    pMem->zMalloc = pMem->z = (char *)z;
    pMem->szMalloc = sqlite3DbMallocSize(pMem->db, pMem->zMalloc);
  }else{
    sqlite3VdbeMemRelease(pMem);
    pMem->z = (char *)z;
    if( xDel==SQLITE_DYNAMIC ){
      pMem->zMalloc = pMem->z;
      pMem->szMalloc = sqlite3DbMallocSize(pMem->db, pMem->zMalloc);
    }else{
    pMem->xDel = xDel;
    flags |= ((xDel==SQLITE_STATIC)?MEM_Static:MEM_Dyn);
      pMem->xDel = xDel;
      flags |= ((xDel==SQLITE_STATIC)?MEM_Static:MEM_Dyn);
    }
  }

  pMem->n = nByte;
  pMem->flags = flags;
  pMem->enc = (enc==0 ? SQLITE_UTF8 : enc);

#ifndef SQLITE_OMIT_UTF16
76734
76735
76736
76737
76738
76739
76740

76741
76742
76743
76744
76745
76746
76747
76937
76938
76939
76940
76941
76942
76943
76944
76945
76946
76947
76948
76949
76950
76951







+







  memset(&sIter, 0, sizeof(sIter));
  sIter.v = v;

  while( (pOp = opIterNext(&sIter))!=0 ){
    int opcode = pOp->opcode;
    if( opcode==OP_Destroy || opcode==OP_VUpdate || opcode==OP_VRename 
     || opcode==OP_VDestroy
     || (opcode==OP_Function0 && pOp->p4.pFunc->funcFlags&SQLITE_FUNC_INTERNAL)
     || ((opcode==OP_Halt || opcode==OP_HaltIfNull) 
      && ((pOp->p1)!=SQLITE_OK && pOp->p2==OE_Abort))
    ){
      hasAbort = 1;
      break;
    }
    if( opcode==OP_CreateBtree && pOp->p3==BTREE_INTKEY ) hasCreateTable = 1;
81348
81349
81350
81351
81352
81353
81354





81355
81356
81357
81358
81359
81360
81361
81552
81553
81554
81555
81556
81557
81558
81559
81560
81561
81562
81563
81564
81565
81566
81567
81568
81569
81570







+
+
+
+
+







  return aType[pVal->flags&MEM_AffMask];
}

/* Return true if a parameter to xUpdate represents an unchanged column */
SQLITE_API int sqlite3_value_nochange(sqlite3_value *pVal){
  return (pVal->flags&(MEM_Null|MEM_Zero))==(MEM_Null|MEM_Zero);
}

/* Return true if a parameter value originated from an sqlite3_bind() */
SQLITE_API int sqlite3_value_frombind(sqlite3_value *pVal){
  return (pVal->flags&MEM_FromBind)!=0;
}

/* Make a copy of an sqlite3_value object
*/
SQLITE_API sqlite3_value *sqlite3_value_dup(const sqlite3_value *pOrig){
  sqlite3_value *pNew;
  if( pOrig==0 ) return 0;
  pNew = sqlite3_malloc( sizeof(*pNew) );
82194
82195
82196
82197
82198
82199
82200
82201
82202
82203
82204




82205
82206
82207
82208
82209
82210
82211
82212
82213
82214
82215
82216
82217
82218
82219
82220
82221
82222
82223
82224






82225
82226



82227
82228
82229
82230
82231
82232
82233
82234
82235
82236
82237
82238
82239
82240
82241
82242
82243

82244
82245
82246
82247
82248

82249
82250
82251
82252
82253
82254
82255
82256
82257
82258
82259
82260
82261
82262
82263
82264
82265
82266
82267
82268

82269
82270
82271
82272
82273

82274
82275
82276
82277
82278
82279
82280
82281
82282
82283
82284
82285
82286

82287
82288
82289
82290
82291

82292
82293
82294
82295
82296
82297
82298
82299
82300
82301
82302

82303
82304
82305
82306
82307

82308
82309
82310
82311
82312
82313
82314
82315
82316
82317
82318

82319
82320
82321
82322
82323

82324
82325
82326
82327
82328
82329
82330
82331
82403
82404
82405
82406
82407
82408
82409




82410
82411
82412
82413
82414
82415
82416
82417
82418
82419
82420
82421
82422
82423
82424
82425
82426
82427
82428
82429
82430
82431
82432
82433
82434
82435
82436
82437
82438
82439


82440
82441
82442
82443
82444
82445
82446
82447
82448
82449
82450
82451
82452
82453
82454
82455
82456
82457
82458

82459

82460
82461
82462

82463

82464
82465
82466
82467
82468
82469
82470
82471
82472
82473
82474
82475
82476
82477
82478
82479
82480
82481

82482

82483
82484
82485

82486

82487
82488
82489
82490
82491
82492
82493
82494
82495
82496
82497

82498

82499
82500
82501

82502

82503
82504
82505
82506
82507
82508
82509
82510
82511

82512

82513
82514
82515

82516

82517
82518
82519
82520
82521
82522
82523
82524
82525

82526

82527
82528
82529

82530

82531
82532
82533
82534
82535
82536
82537







-
-
-
-
+
+
+
+




















+
+
+
+
+
+
-
-
+
+
+
















-
+
-



-
+
-


















-
+
-



-
+
-











-
+
-



-
+
-









-
+
-



-
+
-









-
+
-



-
+
-







**    3      The name of the table that the column derives from
**    4      The name of the table column that the result column derives from
**
** If the result is not a simple column reference (if it is an expression
** or a constant) then useTypes 2, 3, and 4 return NULL.
*/
static const void *columnName(
  sqlite3_stmt *pStmt,
  int N,
  const void *(*xFunc)(Mem*),
  int useType
  sqlite3_stmt *pStmt,     /* The statement */
  int N,                   /* Which column to get the name for */
  int useUtf16,            /* True to return the name as UTF16 */
  int useType              /* What type of name */
){
  const void *ret;
  Vdbe *p;
  int n;
  sqlite3 *db;
#ifdef SQLITE_ENABLE_API_ARMOR
  if( pStmt==0 ){
    (void)SQLITE_MISUSE_BKPT;
    return 0;
  }
#endif
  ret = 0;
  p = (Vdbe *)pStmt;
  db = p->db;
  assert( db!=0 );
  n = sqlite3_column_count(pStmt);
  if( N<n && N>=0 ){
    N += useType*n;
    sqlite3_mutex_enter(db->mutex);
    assert( db->mallocFailed==0 );
#ifndef SQLITE_OMIT_UTF16
    if( useUtf16 ){
      ret = sqlite3_value_text16((sqlite3_value*)&p->aColName[N]);
    }else
#endif
    {
    ret = xFunc(&p->aColName[N]);
     /* A malloc may have failed inside of the xFunc() call. If this
      ret = sqlite3_value_text((sqlite3_value*)&p->aColName[N]);
    }
    /* A malloc may have failed inside of the _text() call. If this
    ** is the case, clear the mallocFailed flag and return NULL.
    */
    if( db->mallocFailed ){
      sqlite3OomClear(db);
      ret = 0;
    }
    sqlite3_mutex_leave(db->mutex);
  }
  return ret;
}

/*
** Return the name of the Nth column of the result set returned by SQL
** statement pStmt.
*/
SQLITE_API const char *sqlite3_column_name(sqlite3_stmt *pStmt, int N){
  return columnName(
  return columnName(pStmt, N, 0, COLNAME_NAME);
      pStmt, N, (const void*(*)(Mem*))sqlite3_value_text, COLNAME_NAME);
}
#ifndef SQLITE_OMIT_UTF16
SQLITE_API const void *sqlite3_column_name16(sqlite3_stmt *pStmt, int N){
  return columnName(
  return columnName(pStmt, N, 1, COLNAME_NAME);
      pStmt, N, (const void*(*)(Mem*))sqlite3_value_text16, COLNAME_NAME);
}
#endif

/*
** Constraint:  If you have ENABLE_COLUMN_METADATA then you must
** not define OMIT_DECLTYPE.
*/
#if defined(SQLITE_OMIT_DECLTYPE) && defined(SQLITE_ENABLE_COLUMN_METADATA)
# error "Must not define both SQLITE_OMIT_DECLTYPE \
         and SQLITE_ENABLE_COLUMN_METADATA"
#endif

#ifndef SQLITE_OMIT_DECLTYPE
/*
** Return the column declaration type (if applicable) of the 'i'th column
** of the result set of SQL statement pStmt.
*/
SQLITE_API const char *sqlite3_column_decltype(sqlite3_stmt *pStmt, int N){
  return columnName(
  return columnName(pStmt, N, 0, COLNAME_DECLTYPE);
      pStmt, N, (const void*(*)(Mem*))sqlite3_value_text, COLNAME_DECLTYPE);
}
#ifndef SQLITE_OMIT_UTF16
SQLITE_API const void *sqlite3_column_decltype16(sqlite3_stmt *pStmt, int N){
  return columnName(
  return columnName(pStmt, N, 1, COLNAME_DECLTYPE);
      pStmt, N, (const void*(*)(Mem*))sqlite3_value_text16, COLNAME_DECLTYPE);
}
#endif /* SQLITE_OMIT_UTF16 */
#endif /* SQLITE_OMIT_DECLTYPE */

#ifdef SQLITE_ENABLE_COLUMN_METADATA
/*
** Return the name of the database from which a result column derives.
** NULL is returned if the result column is an expression or constant or
** anything else which is not an unambiguous reference to a database column.
*/
SQLITE_API const char *sqlite3_column_database_name(sqlite3_stmt *pStmt, int N){
  return columnName(
  return columnName(pStmt, N, 0, COLNAME_DATABASE);
      pStmt, N, (const void*(*)(Mem*))sqlite3_value_text, COLNAME_DATABASE);
}
#ifndef SQLITE_OMIT_UTF16
SQLITE_API const void *sqlite3_column_database_name16(sqlite3_stmt *pStmt, int N){
  return columnName(
  return columnName(pStmt, N, 1, COLNAME_DATABASE);
      pStmt, N, (const void*(*)(Mem*))sqlite3_value_text16, COLNAME_DATABASE);
}
#endif /* SQLITE_OMIT_UTF16 */

/*
** Return the name of the table from which a result column derives.
** NULL is returned if the result column is an expression or constant or
** anything else which is not an unambiguous reference to a database column.
*/
SQLITE_API const char *sqlite3_column_table_name(sqlite3_stmt *pStmt, int N){
  return columnName(
  return columnName(pStmt, N, 0, COLNAME_TABLE);
      pStmt, N, (const void*(*)(Mem*))sqlite3_value_text, COLNAME_TABLE);
}
#ifndef SQLITE_OMIT_UTF16
SQLITE_API const void *sqlite3_column_table_name16(sqlite3_stmt *pStmt, int N){
  return columnName(
  return columnName(pStmt, N, 1, COLNAME_TABLE);
      pStmt, N, (const void*(*)(Mem*))sqlite3_value_text16, COLNAME_TABLE);
}
#endif /* SQLITE_OMIT_UTF16 */

/*
** Return the name of the table column from which a result column derives.
** NULL is returned if the result column is an expression or constant or
** anything else which is not an unambiguous reference to a database column.
*/
SQLITE_API const char *sqlite3_column_origin_name(sqlite3_stmt *pStmt, int N){
  return columnName(
  return columnName(pStmt, N, 0, COLNAME_COLUMN);
      pStmt, N, (const void*(*)(Mem*))sqlite3_value_text, COLNAME_COLUMN);
}
#ifndef SQLITE_OMIT_UTF16
SQLITE_API const void *sqlite3_column_origin_name16(sqlite3_stmt *pStmt, int N){
  return columnName(
  return columnName(pStmt, N, 1, COLNAME_COLUMN);
      pStmt, N, (const void*(*)(Mem*))sqlite3_value_text16, COLNAME_COLUMN);
}
#endif /* SQLITE_OMIT_UTF16 */
#endif /* SQLITE_ENABLE_COLUMN_METADATA */


/******************************* sqlite3_bind_  ***************************
** 
82684
82685
82686
82687
82688
82689
82690








82691
82692
82693
82694
82695
82696
82697
82890
82891
82892
82893
82894
82895
82896
82897
82898
82899
82900
82901
82902
82903
82904
82905
82906
82907
82908
82909
82910
82911







+
+
+
+
+
+
+
+







/*
** Return true if the prepared statement is guaranteed to not modify the
** database.
*/
SQLITE_API int sqlite3_stmt_readonly(sqlite3_stmt *pStmt){
  return pStmt ? ((Vdbe*)pStmt)->readOnly : 1;
}

/*
** Return 1 if the statement is an EXPLAIN and return 2 if the
** statement is an EXPLAIN QUERY PLAN
*/
SQLITE_API int sqlite3_stmt_isexplain(sqlite3_stmt *pStmt){
  return pStmt ? ((Vdbe*)pStmt)->explain : 0;
}

/*
** Return true if the prepared statement is in need of being reset.
*/
SQLITE_API int sqlite3_stmt_busy(sqlite3_stmt *pStmt){
  Vdbe *v = (Vdbe*)pStmt;
  return v!=0 && v->magic==VDBE_MAGIC_RUN && v->pc>=0;
83374
83375
83376
83377
83378
83379
83380
83381
83382
83383
83384
83385














83386
83387
83388
83389
83390
83391
83392
83393
83394
83395
83396
83397

83398
83399

83400
83401
83402
83403
83404
83405
83406
83588
83589
83590
83591
83592
83593
83594





83595
83596
83597
83598
83599
83600
83601
83602
83603
83604
83605
83606
83607
83608

83609
83610
83611
83612
83613
83614
83615
83616
83617
83618

83619
83620

83621
83622
83623
83624
83625
83626
83627
83628







-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-










-
+

-
+







#endif

/*
** Invoke the VDBE coverage callback, if that callback is defined.  This
** feature is used for test suite validation only and does not appear an
** production builds.
**
** M is an integer between 2 and 4.  2 indicates a ordinary two-way
** branch (I=0 means fall through and I=1 means taken).  3 indicates
** a 3-way branch where the third way is when one of the operands is
** NULL.  4 indicates the OP_Jump instruction which has three destinations
** depending on whether the first operand is less than, equal to, or greater
** M is the type of branch.  I is the direction taken for this instance of
** the branch.
**
**   M: 2 - two-way branch (I=0: fall-thru   1: jump                )
**      3 - two-way + NULL (I=0: fall-thru   1: jump      2: NULL   )
**      4 - OP_Jump        (I=0: jump p1     1: jump p2   2: jump p3)
**
** In other words, if M is 2, then I is either 0 (for fall-through) or
** 1 (for when the branch is taken).  If M is 3, the I is 0 for an
** ordinary fall-through, I is 1 if the branch was taken, and I is 2 
** if the result of comparison is NULL.  For M=3, I=2 the jump may or
** may not be taken, depending on the SQLITE_JUMPIFNULL flags in p5.
** When M is 4, that means that an OP_Jump is being run.  I is 0, 1, or 2
** depending on if the operands are less than, equal, or greater than.
** than the second. 
**
** iSrcLine is the source code line (from the __LINE__ macro) that
** generated the VDBE instruction combined with flag bits.  The source
** code line number is in the lower 24 bits of iSrcLine and the upper
** 8 bytes are flags.  The lower three bits of the flags indicate
** values for I that should never occur.  For example, if the branch is
** always taken, the flags should be 0x05 since the fall-through and
** alternate branch are never taken.  If a branch is never taken then
** flags should be 0x06 since only the fall-through approach is allowed.
**
** Bit 0x04 of the flags indicates an OP_Jump opcode that is only
** Bit 0x08 of the flags indicates an OP_Jump opcode that is only
** interested in equal or not-equal.  In other words, I==0 and I==2
** should be treated the same.
** should be treated as equivalent
**
** Since only a line number is retained, not the filename, this macro
** only works for amalgamation builds.  But that is ok, since these macros
** should be no-ops except for special builds used to measure test coverage.
*/
#if !defined(SQLITE_VDBE_COVERAGE)
# define VdbeBranchTaken(I,M)
83416
83417
83418
83419
83420
83421
83422












83423
83424
83425
83426
83427
83428
83429
83638
83639
83640
83641
83642
83643
83644
83645
83646
83647
83648
83649
83650
83651
83652
83653
83654
83655
83656
83657
83658
83659
83660
83661
83662
83663







+
+
+
+
+
+
+
+
+
+
+
+







    /* The upper 8 bits of iSrcLine are flags.  The lower three bits of
    ** the flags indicate directions that the branch can never go.  If
    ** a branch really does go in one of those directions, assert right
    ** away. */
    mNever = iSrcLine >> 24;
    assert( (I & mNever)==0 );
    if( sqlite3GlobalConfig.xVdbeBranch==0 ) return;  /*NO_TEST*/
    /* Invoke the branch coverage callback with three arguments:
    **    iSrcLine - the line number of the VdbeCoverage() macro, with
    **               flags removed.
    **    I        - Mask of bits 0x07 indicating which cases are are
    **               fulfilled by this instance of the jump.  0x01 means
    **               fall-thru, 0x02 means taken, 0x04 means NULL.  Any
    **               impossible cases (ex: if the comparison is never NULL)
    **               are filled in automatically so that the coverage
    **               measurement logic does not flag those impossible cases
    **               as missed coverage.
    **    M        - Type of jump.  Same as M argument above
    */
    I |= mNever;
    if( M==2 ) I |= 0x04;
    if( M==4 ){
      I |= 0x08;
      if( (mNever&0x08)!=0 && (I&0x05)!=0) I |= 0x05; /*NO_TEST*/
    }
    sqlite3GlobalConfig.xVdbeBranch(sqlite3GlobalConfig.pVdbeBranchArg,
83963
83964
83965
83966
83967
83968
83969









83970
83971
83972
83973
83974
83975
83976
83977
83978
83979
83980
83981
83982
83983
83984
83985
83986
83987
83988
83989
83990
83991
83992
83993
83994
83995
83996
83997
83998
84197
84198
84199
84200
84201
84202
84203
84204
84205
84206
84207
84208
84209
84210
84211
84212
84213
84214
84215
84216
84217
84218
84219
84220
84221
84222
84223
84224
84225









84226
84227
84228
84229
84230
84231
84232







+
+
+
+
+
+
+
+
+













-
-
-
-
-
-
-
-
-







#ifdef VDBE_PROFILE
  u64 start;                 /* CPU clock count at start of opcode */
#endif
  /*** INSERT STACK UNION HERE ***/

  assert( p->magic==VDBE_MAGIC_RUN );  /* sqlite3_step() verifies this */
  sqlite3VdbeEnter(p);
#ifndef SQLITE_OMIT_PROGRESS_CALLBACK
  if( db->xProgress ){
    u32 iPrior = p->aCounter[SQLITE_STMTSTATUS_VM_STEP];
    assert( 0 < db->nProgressOps );
    nProgressLimit = db->nProgressOps - (iPrior % db->nProgressOps);
  }else{
    nProgressLimit = 0xffffffff;
  }
#endif
  if( p->rc==SQLITE_NOMEM ){
    /* This happens if a malloc() inside a call to sqlite3_column_text() or
    ** sqlite3_column_text16() failed.  */
    goto no_mem;
  }
  assert( p->rc==SQLITE_OK || (p->rc&0xff)==SQLITE_BUSY );
  assert( p->bIsReader || p->readOnly!=0 );
  p->iCurrentTime = 0;
  assert( p->explain==0 );
  p->pResultSet = 0;
  db->busyHandler.nBusy = 0;
  if( db->u1.isInterrupted ) goto abort_due_to_interrupt;
  sqlite3VdbeIOTraceSql(p);
#ifndef SQLITE_OMIT_PROGRESS_CALLBACK
  if( db->xProgress ){
    u32 iPrior = p->aCounter[SQLITE_STMTSTATUS_VM_STEP];
    assert( 0 < db->nProgressOps );
    nProgressLimit = db->nProgressOps - (iPrior % db->nProgressOps);
  }else{
    nProgressLimit = 0xffffffff;
  }
#endif
#ifdef SQLITE_DEBUG
  sqlite3BeginBenignMalloc();
  if( p->pc==0
   && (p->db->flags & (SQLITE_VdbeListing|SQLITE_VdbeEQP|SQLITE_VdbeTrace))!=0
  ){
    int i;
    int once = 1;
84160
84161
84162
84163
84164
84165
84166
84167

84168
84169

84170

84171
84172
84173
84174
84175
84176
84177
84394
84395
84396
84397
84398
84399
84400

84401
84402

84403
84404
84405
84406
84407
84408
84409
84410
84411
84412







-
+

-
+

+







#ifndef SQLITE_OMIT_PROGRESS_CALLBACK
  /* Call the progress callback if it is configured and the required number
  ** of VDBE ops have been executed (either since this invocation of
  ** sqlite3VdbeExec() or since last time the progress callback was called).
  ** If the progress callback returns non-zero, exit the virtual machine with
  ** a return code SQLITE_ABORT.
  */
  if( nVmStep>=nProgressLimit && db->xProgress!=0 ){
  while( nVmStep>=nProgressLimit && db->xProgress!=0 ){
    assert( db->nProgressOps!=0 );
    nProgressLimit = nVmStep + db->nProgressOps - (nVmStep%db->nProgressOps);
    nProgressLimit += db->nProgressOps;
    if( db->xProgress(db->pProgressArg) ){
      nProgressLimit = 0xffffffff;
      rc = SQLITE_INTERRUPT;
      goto abort_due_to_error;
    }
  }
#endif
  
  break;
84442
84443
84444
84445
84446
84447
84448

84449
84450
84451
84452
84453
84454
84455
84456
84457
84458
84459
84460
84461
84462
84463
84464
84465
84466
84467
84468
84677
84678
84679
84680
84681
84682
84683
84684
84685
84686
84687
84688
84689
84690
84691
84692
84693
84694
84695
84696

84697
84698
84699
84700
84701
84702
84703







+












-







  pOp->opcode = OP_String;
  pOp->p1 = sqlite3Strlen30(pOp->p4.z);

#ifndef SQLITE_OMIT_UTF16
  if( encoding!=SQLITE_UTF8 ){
    rc = sqlite3VdbeMemSetStr(pOut, pOp->p4.z, -1, SQLITE_UTF8, SQLITE_STATIC);
    assert( rc==SQLITE_OK || rc==SQLITE_TOOBIG );
    if( rc ) goto too_big;
    if( SQLITE_OK!=sqlite3VdbeChangeEncoding(pOut, encoding) ) goto no_mem;
    assert( pOut->szMalloc>0 && pOut->zMalloc==pOut->z );
    assert( VdbeMemDynamic(pOut)==0 );
    pOut->szMalloc = 0;
    pOut->flags |= MEM_Static;
    if( pOp->p4type==P4_DYNAMIC ){
      sqlite3DbFree(db, pOp->p4.z);
    }
    pOp->p4type = P4_DYNAMIC;
    pOp->p4.z = pOut->z;
    pOp->p1 = pOut->n;
  }
  testcase( rc==SQLITE_TOOBIG );
#endif
  if( pOp->p1>db->aLimit[SQLITE_LIMIT_LENGTH] ){
    goto too_big;
  }
  assert( rc==SQLITE_OK );
  /* Fall through to the next case, OP_String */
}
84576
84577
84578
84579
84580
84581
84582

84583



84584
84585
84586
84587
84588
84589
84590
84811
84812
84813
84814
84815
84816
84817
84818

84819
84820
84821
84822
84823
84824
84825
84826
84827
84828







+
-
+
+
+







  assert( pOp->p1>0 && pOp->p1<=p->nVar );
  assert( pOp->p4.z==0 || pOp->p4.z==sqlite3VListNumToName(p->pVList,pOp->p1) );
  pVar = &p->aVar[pOp->p1 - 1];
  if( sqlite3VdbeMemTooBig(pVar) ){
    goto too_big;
  }
  pOut = &aMem[pOp->p2];
  if( VdbeMemDynamic(pOut) ) sqlite3VdbeMemSetNull(pOut);
  sqlite3VdbeMemShallowCopy(pOut, pVar, MEM_Static);
  memcpy(pOut, pVar, MEMCELLSIZE);
  pOut->flags &= ~(MEM_Dyn|MEM_Ephem);
  pOut->flags |= MEM_Static|MEM_FromBind;
  UPDATE_MAX_BLOBSIZE(pOut);
  break;
}

/* Opcode: Move P1 P2 P3 * *
** Synopsis: r[P2@P3]=r[P1@P3]
**
84709
84710
84711
84712
84713
84714
84715
84716
84717
84718
84719
84720
84721
84722
84723
84724
84725
84726
84727
84728
84729
84730
84731
84732
84733
84734
84947
84948
84949
84950
84951
84952
84953












84954
84955
84956
84957
84958
84959
84960







-
-
-
-
-
-
-
-
-
-
-
-







case OP_ResultRow: {
  Mem *pMem;
  int i;
  assert( p->nResColumn==pOp->p2 );
  assert( pOp->p1>0 );
  assert( pOp->p1+pOp->p2<=(p->nMem+1 - p->nCursor)+1 );

#ifndef SQLITE_OMIT_PROGRESS_CALLBACK
  /* Run the progress counter just before returning.
  */
  if( db->xProgress!=0
   && nVmStep>=nProgressLimit 
   && db->xProgress(db->pProgressArg)!=0
  ){
    rc = SQLITE_INTERRUPT;
    goto abort_due_to_error;
  }
#endif

  /* If this statement has violated immediate foreign key constraints, do
  ** not return the number of rows modified. And do not RELEASE the statement
  ** transaction. It needs to be rolled back.  */
  if( SQLITE_OK!=(rc = sqlite3VdbeCheckFk(p, 0)) ){
    assert( db->flags&SQLITE_CountRows );
    assert( p->usesStmtJournal );
    goto abort_due_to_error;
85086
85087
85088
85089
85090
85091
85092
85093
85094

85095
85096
85097
85098
85099
85100
85101
85102

85103
85104
85105
85106
85107
85108
85109
85312
85313
85314
85315
85316
85317
85318

85319
85320
85321
85322
85323
85324
85325
85326
85327
85328
85329
85330
85331
85332
85333
85334
85335
85336







-

+








+







** without data loss, then jump immediately to P2, or if P2==0
** raise an SQLITE_MISMATCH exception.
*/
case OP_MustBeInt: {            /* jump, in1 */
  pIn1 = &aMem[pOp->p1];
  if( (pIn1->flags & MEM_Int)==0 ){
    applyAffinity(pIn1, SQLITE_AFF_NUMERIC, encoding);
    VdbeBranchTaken((pIn1->flags&MEM_Int)==0, 2);
    if( (pIn1->flags & MEM_Int)==0 ){
      VdbeBranchTaken(1, 2);
      if( pOp->p2==0 ){
        rc = SQLITE_MISMATCH;
        goto abort_due_to_error;
      }else{
        goto jump_to_p2;
      }
    }
  }
  VdbeBranchTaken(0, 2);
  MemSetTypeFlag(pIn1, MEM_Int);
  break;
}

#ifndef SQLITE_OMIT_FLOATING_POINT
/* Opcode: RealAffinity P1 * * * *
**
85270
85271
85272
85273
85274
85275
85276
85277
85278
85279
85280
85281
85282
85283
85284
85285
85286

85287
85288
85289
85290
85291
85292
85293
85497
85498
85499
85500
85501
85502
85503

85504
85505
85506
85507
85508
85509
85510
85511

85512
85513
85514
85515
85516
85517
85518
85519







-








-
+







  if( (flags1 | flags3)&MEM_Null ){
    /* One or both operands are NULL */
    if( pOp->p5 & SQLITE_NULLEQ ){
      /* If SQLITE_NULLEQ is set (which will only happen if the operator is
      ** OP_Eq or OP_Ne) then take the jump or not depending on whether
      ** or not both operands are null.
      */
      assert( pOp->opcode==OP_Eq || pOp->opcode==OP_Ne );
      assert( (flags1 & MEM_Cleared)==0 );
      assert( (pOp->p5 & SQLITE_JUMPIFNULL)==0 || CORRUPT_DB );
      testcase( (pOp->p5 & SQLITE_JUMPIFNULL)!=0 );
      if( (flags1&flags3&MEM_Null)!=0
       && (flags3&MEM_Cleared)==0
      ){
        res = 0;  /* Operands are equal */
      }else{
        res = 1;  /* Operands are not equal */
        res = ((flags3 & MEM_Null) ? -1 : +1);  /* Operands are not equal */
      }
    }else{
      /* SQLITE_NULLEQ is clear and at least one operand is NULL,
      ** then the result is always NULL.
      ** The jump is taken if the SQLITE_JUMPIFNULL bit is set.
      */
      if( pOp->p5 & SQLITE_STOREP2 ){
85397
85398
85399
85400
85401
85402
85403
85404

85405
85406
85407
85408
85409
85410
85411
85623
85624
85625
85626
85627
85628
85629

85630
85631
85632
85633
85634
85635
85636
85637







-
+







      if( (pOp->opcode==OP_Eq)==res2 ) break;
    }
    memAboutToChange(p, pOut);
    MemSetTypeFlag(pOut, MEM_Int);
    pOut->u.i = res2;
    REGISTER_TRACE(pOp->p2, pOut);
  }else{
    VdbeBranchTaken(res!=0, (pOp->p5 & SQLITE_NULLEQ)?2:3);
    VdbeBranchTaken(res2!=0, (pOp->p5 & SQLITE_NULLEQ)?2:3);
    if( res2 ){
      goto jump_to_p2;
    }
  }
  break;
}

85947
85948
85949
85950
85951
85952
85953
85954

85955
85956
85957
85958

85959
85960
85961
85962

85963
85964
85965
85966
85967
85968
85969
86173
86174
86175
86176
86177
86178
86179

86180
86181
86182
86183
86184
86185
86186
86187


86188
86189
86190
86191
86192
86193
86194
86195







-
+




+


-
-
+







    op_column_read_header:
      i = pC->nHdrParsed;
      offset64 = aOffset[i];
      zHdr = zData + pC->iHdrOffset;
      zEndHdr = zData + aOffset[0];
      testcase( zHdr>=zEndHdr );
      do{
        if( (t = zHdr[0])<0x80 ){
        if( (pC->aType[i] = t = zHdr[0])<0x80 ){
          zHdr++;
          offset64 += sqlite3VdbeOneByteSerialTypeLen(t);
        }else{
          zHdr += sqlite3GetVarint32(zHdr, &t);
          pC->aType[i] = t;
          offset64 += sqlite3VdbeSerialTypeLen(t);
        }
        pC->aType[i++] = t;
        aOffset[i] = (u32)(offset64 & 0xffffffff);
        aOffset[++i] = (u32)(offset64 & 0xffffffff);
      }while( i<=p2 && zHdr<zEndHdr );

      /* The record is corrupt if any of the following are true:
      ** (1) the bytes of the header extend past the declared header size
      ** (2) the entire header was used but not all data was used
      ** (3) the end of the data extends beyond the end of the record.
      */
86958
86959
86960
86961
86962
86963
86964

86965
86966
86967
86968
86969
86970
86971
87184
87185
87186
87187
87188
87189
87190
87191
87192
87193
87194
87195
87196
87197
87198







+







  pCx = allocateCursor(p, pOp->p1, pOrig->nField, -1, CURTYPE_BTREE);
  if( pCx==0 ) goto no_mem;
  pCx->nullRow = 1;
  pCx->isEphemeral = 1;
  pCx->pKeyInfo = pOrig->pKeyInfo;
  pCx->isTable = pOrig->isTable;
  pCx->pgnoRoot = pOrig->pgnoRoot;
  pCx->isOrdered = pOrig->isOrdered;
  rc = sqlite3BtreeCursor(pOrig->pBtx, pCx->pgnoRoot, BTREE_WRCSR,
                          pCx->pKeyInfo, pCx->uc.pCursor);
  /* The sqlite3BtreeCursor() routine can only fail for the first cursor
  ** opened for a database.  Since there is already an open cursor when this
  ** opcode is run, the sqlite3BtreeCursor() cannot fail */
  assert( rc==SQLITE_OK );
  break;
87921
87922
87923
87924
87925
87926
87927
87928
87929
87930
87931
87932
87933
87934

87935
87936
87937
87938
87939
87940
87941
87942
87943
87944
87945
87946
87947
87948
87949
87950
87951
87952
87953
87954
87955
87956
87957
87958
87959
87960
87961





87962
87963
87964
87965
87966
87967
87968
87969
87970
87971
87972
88148
88149
88150
88151
88152
88153
88154







88155

88156
88157
88158
88159
88160
88161
88162
88163
88164
88165
88166
88167
88168
88169
88170
88171
88172
88173
88174
88175






88176
88177
88178
88179
88180




88181
88182
88183
88184
88185
88186
88187







-
-
-
-
-
-
-
+
-




















-
-
-
-
-
-
+
+
+
+
+
-
-
-
-







** and register P2 becomes ephemeral.  If the cursor is changed, the
** value of register P2 will then change.  Make sure this does not
** cause any problems.)
**
** This instruction only works on tables.  The equivalent instruction
** for indices is OP_IdxInsert.
*/
/* Opcode: InsertInt P1 P2 P3 P4 P5
** Synopsis: intkey=P3 data=r[P2]
**
** This works exactly like OP_Insert except that the key is the
** integer value P3, not the value of the integer stored in register P3.
*/
case OP_Insert: 
case OP_Insert: {
case OP_InsertInt: {
  Mem *pData;       /* MEM cell holding data for the record to be inserted */
  Mem *pKey;        /* MEM cell holding key  for the record */
  VdbeCursor *pC;   /* Cursor to table into which insert is written */
  int seekResult;   /* Result of prior seek or 0 if no USESEEKRESULT flag */
  const char *zDb;  /* database name - used by the update hook */
  Table *pTab;      /* Table structure - used by update and pre-update hooks */
  BtreePayload x;   /* Payload to be inserted */

  pData = &aMem[pOp->p2];
  assert( pOp->p1>=0 && pOp->p1<p->nCursor );
  assert( memIsValid(pData) );
  pC = p->apCsr[pOp->p1];
  assert( pC!=0 );
  assert( pC->eCurType==CURTYPE_BTREE );
  assert( pC->uc.pCursor!=0 );
  assert( (pOp->p5 & OPFLAG_ISNOOP) || pC->isTable );
  assert( pOp->p4type==P4_TABLE || pOp->p4type>=P4_STATIC );
  REGISTER_TRACE(pOp->p2, pData);
  sqlite3VdbeIncrWriteCounter(p, pC);

  if( pOp->opcode==OP_Insert ){
    pKey = &aMem[pOp->p3];
    assert( pKey->flags & MEM_Int );
    assert( memIsValid(pKey) );
    REGISTER_TRACE(pOp->p3, pKey);
    x.nKey = pKey->u.i;
  pKey = &aMem[pOp->p3];
  assert( pKey->flags & MEM_Int );
  assert( memIsValid(pKey) );
  REGISTER_TRACE(pOp->p3, pKey);
  x.nKey = pKey->u.i;
  }else{
    assert( pOp->opcode==OP_InsertInt );
    x.nKey = pOp->p3;
  }

  if( pOp->p4type==P4_TABLE && HAS_UPDATE_HOOK(db) ){
    assert( pC->iDb>=0 );
    zDb = db->aDb[pC->iDb].zDbSName;
    pTab = pOp->p4.pTab;
    assert( (pOp->p5 & OPFLAG_ISNOOP) || HasRowid(pTab) );
  }else{
88478
88479
88480
88481
88482
88483
88484
88485

88486
88487
88488
88489
88490
88491
88492
88493
88494
88495
88496
88497
88498
88499
88500
88501
88502
88503
88504
88505
88506

88507
88508
88509
88510
88511
88512
88513
88514
88515
88516
88517
88518
88519
88520
88521
88522
88523
88524
88525
88526
88527
88528
88529
88530
88693
88694
88695
88696
88697
88698
88699

88700
88701
88702
88703
88704
88705
88706
88707




88708
88709
88710
88711
88712
88713
88714
88715
88716
88717
88718
88719
88720
88721
88722
88723
88724
88725
88726
88727
88728
88729
88730
88731
88732



88733
88734
88735
88736
88737
88738
88739







-
+







-
-
-
-










+














-
-
-







#ifdef SQLITE_TEST
  sqlite3_sort_count++;
  sqlite3_search_count--;
#endif
  p->aCounter[SQLITE_STMTSTATUS_SORT]++;
  /* Fall through into OP_Rewind */
}
/* Opcode: Rewind P1 P2 * * P5
/* Opcode: Rewind P1 P2 * * *
**
** The next use of the Rowid or Column or Next instruction for P1 
** will refer to the first entry in the database table or index.
** If the table or index is empty, jump immediately to P2.
** If the table or index is not empty, fall through to the following 
** instruction.
**
** If P5 is non-zero and the table is not empty, then the "skip-next"
** flag is set on the cursor so that the next OP_Next instruction 
** executed on it is a no-op.
**
** This opcode leaves the cursor configured to move in forward order,
** from the beginning toward the end.  In other words, the cursor is
** configured to use Next, not Prev.
*/
case OP_Rewind: {        /* jump */
  VdbeCursor *pC;
  BtCursor *pCrsr;
  int res;

  assert( pOp->p1>=0 && pOp->p1<p->nCursor );
  assert( pOp->p5==0 );
  pC = p->apCsr[pOp->p1];
  assert( pC!=0 );
  assert( isSorter(pC)==(pOp->opcode==OP_SorterSort) );
  res = 1;
#ifdef SQLITE_DEBUG
  pC->seekOp = OP_Rewind;
#endif
  if( isSorter(pC) ){
    rc = sqlite3VdbeSorterRewind(pC, &res);
  }else{
    assert( pC->eCurType==CURTYPE_BTREE );
    pCrsr = pC->uc.pCursor;
    assert( pCrsr );
    rc = sqlite3BtreeFirst(pCrsr, &res);
#ifndef SQLITE_OMIT_WINDOWFUNC
    if( pOp->p5 ) sqlite3BtreeSkipNext(pCrsr);
#endif
    pC->deferredMoveto = 0;
    pC->cacheStatus = CACHE_STALE;
  }
  if( rc ) goto abort_due_to_error;
  pC->nullRow = (u8)res;
  assert( pOp->p2>0 && pOp->p2<p->nOp );
  VdbeBranchTaken(res!=0,2);
89526
89527
89528
89529
89530
89531
89532
89533

89534
89535
89536
89537
89538
89539
89540
89541
89735
89736
89737
89738
89739
89740
89741

89742

89743
89744
89745
89746
89747
89748
89749







-
+
-







    for(i=0; i<p->nMem; i++){
      aMem[i].pScopyFrom = 0;  /* Prevent false-positive AboutToChange() errs */
      aMem[i].flags |= MEM_Undefined; /* Cause a fault if this reg is reused */
    }
  }
#endif
  pOp = &aOp[-1];

  goto check_for_interrupt;
  break;
}

/* Opcode: Param P1 P2 * * *
**
** This opcode is only ever present in sub-programs called via the 
** OP_Program instruction. Copy a value currently stored in a memory 
** cell of the calling (parent) frame to cell P2 in the current frames 
89899
89900
89901
89902
89903
89904
89905

89906
89907
89908
89909
89910
89911
89912
90107
90108
90109
90110
90111
90112
90113
90114
90115
90116
90117
90118
90119
90120
90121







+







  Mem *pMem;
  assert( pOp->p1>0 && pOp->p1<=(p->nMem+1 - p->nCursor) );
  assert( pOp->p3==0 || pOp->opcode==OP_AggValue );
  pMem = &aMem[pOp->p1];
  assert( (pMem->flags & ~(MEM_Null|MEM_Agg))==0 );
#ifndef SQLITE_OMIT_WINDOWFUNC
  if( pOp->p3 ){
    memAboutToChange(p, &aMem[pOp->p3]);
    rc = sqlite3VdbeMemAggValue(pMem, &aMem[pOp->p3], pOp->p4.pFunc);
    pMem = &aMem[pOp->p3];
  }else
#endif
  {
    rc = sqlite3VdbeMemFinalize(pMem, pOp->p4.pFunc);
  }
90936
90937
90938
90939
90940
90941
90942

90943









90944
90945
90946
90947
90948
90949
90950
91145
91146
91147
91148
91149
91150
91151
91152

91153
91154
91155
91156
91157
91158
91159
91160
91161
91162
91163
91164
91165
91166
91167
91168







+
-
+
+
+
+
+
+
+
+
+







    sqlite3ResetOneSchema(db, resetSchemaOnFault-1);
  }

  /* This is the only way out of this procedure.  We have to
  ** release the mutexes on btrees that were acquired at the
  ** top. */
vdbe_return:
#ifndef SQLITE_OMIT_PROGRESS_CALLBACK
  testcase( nVmStep>0 );
  while( nVmStep>=nProgressLimit && db->xProgress!=0 ){
    nProgressLimit += db->nProgressOps;
    if( db->xProgress(db->pProgressArg) ){
      nProgressLimit = 0xffffffff;
      rc = SQLITE_INTERRUPT;
      goto abort_due_to_error;
    }
  }
#endif
  p->aCounter[SQLITE_STMTSTATUS_VM_STEP] += (int)nVmStep;
  sqlite3VdbeLeave(p);
  assert( rc!=SQLITE_OK || nExtraDelete==0 
       || sqlite3_strlike("DELETE%",p->zSql,0)!=0 
  );
  return rc;

95308
95309
95310
95311
95312
95313
95314




95315
95316
95317
95318
95319
95320
95321
95526
95527
95528
95529
95530
95531
95532
95533
95534
95535
95536
95537
95538
95539
95540
95541
95542
95543







+
+
+
+







          assert( pExpr->pLeft==0 && pExpr->pRight==0 );
          assert( pExpr->x.pList==0 );
          assert( pExpr->x.pSelect==0 );
          pOrig = pEList->a[j].pExpr;
          if( (pNC->ncFlags&NC_AllowAgg)==0 && ExprHasProperty(pOrig, EP_Agg) ){
            sqlite3ErrorMsg(pParse, "misuse of aliased aggregate %s", zAs);
            return WRC_Abort;
          }
          if( (pNC->ncFlags&NC_AllowWin)==0 && ExprHasProperty(pOrig, EP_Win) ){
            sqlite3ErrorMsg(pParse, "misuse of aliased window function %s",zAs);
            return WRC_Abort;
          }
          if( sqlite3ExprVectorSize(pOrig)!=1 ){
            sqlite3ErrorMsg(pParse, "row value misused");
            return WRC_Abort;
          }
          resolveAlias(pParse, pEList, j, pExpr, "", nSubquery);
          cnt = 1;
95599
95600
95601
95602
95603
95604
95605

95606
95607
95608
95609
95610
95611
95612
95821
95822
95823
95824
95825
95826
95827
95828
95829
95830
95831
95832
95833
95834
95835







+







      int no_such_func = 0;       /* True if no such function exists */
      int wrong_num_args = 0;     /* True if wrong number of arguments */
      int is_agg = 0;             /* True if is an aggregate function */
      int nId;                    /* Number of characters in function name */
      const char *zId;            /* The function name. */
      FuncDef *pDef;              /* Information about the function */
      u8 enc = ENC(pParse->db);   /* The database encoding */
      int savedAllowFlags = (pNC->ncFlags & (NC_AllowAgg | NC_AllowWin));

      assert( !ExprHasProperty(pExpr, EP_xIsSelect) );
      zId = pExpr->u.zToken;
      nId = sqlite3Strlen30(zId);
      pDef = sqlite3FindFunction(pParse->db, zId, n, enc, 0);
      if( pDef==0 ){
        pDef = sqlite3FindFunction(pParse->db, zId, -2, enc, 0);
95720
95721
95722
95723
95724
95725
95726



95727
95728

95729
95730
95731
95732
95733
95734
95735
95736
95737
95738
95739
95740
95741
95742
95743
95744
95745
95746
95747
95748
95749

95750
95751
95752
95753
95754
95755
95756
95757
95758
95759
95760
95761
95762
95763
95764
95765
95766
95767
95768

95769
95770
95771
95772
95773
95774
95775
95943
95944
95945
95946
95947
95948
95949
95950
95951
95952
95953

95954
95955
95956
95957
95958
95959
95960
95961
95962
95963
95964
95965
95966
95967
95968
95969
95970
95971
95972
95973
95974

95975
95976
95977
95978
95979
95980
95981
95982
95983
95984
95985
95986
95987
95988
95989
95990
95991
95992

95993
95994
95995
95996
95997
95998
95999
96000
96001







+
+
+

-
+




















-
+

















-

+







          pNC->nErr++;
        }else if( wrong_num_args ){
          sqlite3ErrorMsg(pParse,"wrong number of arguments to function %.*s()",
               nId, zId);
          pNC->nErr++;
        }
        if( is_agg ){
          /* Window functions may not be arguments of aggregate functions.
          ** Or arguments of other window functions. But aggregate functions
          ** may be arguments for window functions.  */
#ifndef SQLITE_OMIT_WINDOWFUNC
          pNC->ncFlags &= ~(pExpr->y.pWin ? NC_AllowWin : NC_AllowAgg);
          pNC->ncFlags &= ~(NC_AllowWin | (!pExpr->y.pWin ? NC_AllowAgg : 0));
#else
          pNC->ncFlags &= ~NC_AllowAgg;
#endif
        }
      }
      sqlite3WalkExprList(pWalker, pList);
      if( is_agg ){
#ifndef SQLITE_OMIT_WINDOWFUNC
        if( pExpr->y.pWin ){
          Select *pSel = pNC->pWinSelect;
          sqlite3WindowUpdate(pParse, pSel->pWinDefn, pExpr->y.pWin, pDef);
          sqlite3WalkExprList(pWalker, pExpr->y.pWin->pPartition);
          sqlite3WalkExprList(pWalker, pExpr->y.pWin->pOrderBy);
          sqlite3WalkExpr(pWalker, pExpr->y.pWin->pFilter);
          if( 0==pSel->pWin 
           || 0==sqlite3WindowCompare(pParse, pSel->pWin, pExpr->y.pWin) 
          ){
            pExpr->y.pWin->pNextWin = pSel->pWin;
            pSel->pWin = pExpr->y.pWin;
          }
          pNC->ncFlags |= NC_AllowWin;
          pNC->ncFlags |= NC_HasWin;
        }else
#endif /* SQLITE_OMIT_WINDOWFUNC */
        {
          NameContext *pNC2 = pNC;
          pExpr->op = TK_AGG_FUNCTION;
          pExpr->op2 = 0;
          while( pNC2 && !sqlite3FunctionUsesThisSrc(pExpr, pNC2->pSrcList) ){
            pExpr->op2++;
            pNC2 = pNC2->pNext;
          }
          assert( pDef!=0 );
          if( pNC2 ){
            assert( SQLITE_FUNC_MINMAX==NC_MinMaxAgg );
            testcase( (pDef->funcFlags & SQLITE_FUNC_MINMAX)!=0 );
            pNC2->ncFlags |= NC_HasAgg | (pDef->funcFlags & SQLITE_FUNC_MINMAX);

          }
          pNC->ncFlags |= NC_AllowAgg;
        }
        pNC->ncFlags |= savedAllowFlags;
      }
      /* FIX ME:  Compute pExpr->affinity based on the expected return
      ** type of the function 
      */
      return WRC_Prune;
    }
#ifndef SQLITE_OMIT_SUBQUERY
96117
96118
96119
96120
96121
96122
96123
































96124
96125
96126
96127
96128
96129
96130
96343
96344
96345
96346
96347
96348
96349
96350
96351
96352
96353
96354
96355
96356
96357
96358
96359
96360
96361
96362
96363
96364
96365
96366
96367
96368
96369
96370
96371
96372
96373
96374
96375
96376
96377
96378
96379
96380
96381
96382
96383
96384
96385
96386
96387
96388







+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+







      resolveAlias(pParse, pEList, pItem->u.x.iOrderByCol-1, pItem->pExpr,
                   zType,0);
    }
  }
  return 0;
}

#ifndef SQLITE_OMIT_WINDOWFUNC
/*
** Walker callback for resolveRemoveWindows().
*/
static int resolveRemoveWindowsCb(Walker *pWalker, Expr *pExpr){
  if( ExprHasProperty(pExpr, EP_WinFunc) ){
    Window **pp;
    for(pp=&pWalker->u.pSelect->pWin; *pp; pp=&(*pp)->pNextWin){
      if( *pp==pExpr->y.pWin ){
        *pp = (*pp)->pNextWin;
        break;
      }    
    }
  }
  return WRC_Continue;
}

/*
** Remove any Window objects owned by the expression pExpr from the
** Select.pWin list of Select object pSelect.
*/
static void resolveRemoveWindows(Select *pSelect, Expr *pExpr){
  Walker sWalker;
  memset(&sWalker, 0, sizeof(Walker));
  sWalker.xExprCallback = resolveRemoveWindowsCb;
  sWalker.u.pSelect = pSelect;
  sqlite3WalkExpr(&sWalker, pExpr);
}
#else
# define resolveRemoveWindows(x,y)
#endif

/*
** pOrderBy is an ORDER BY or GROUP BY clause in SELECT statement pSelect.
** The Name context of the SELECT statement is pNC.  zType is either
** "ORDER" or "GROUP" depending on which type of clause pOrderBy is.
**
** This routine resolves each term of the clause into an expression.
** If the order-by term is an integer I between 1 and N (where N is the
96183
96184
96185
96186
96187
96188
96189
96190
96191
96192
96193
96194
96195




96196
96197
96198
96199
96200
96201
96202
96203
96204
96205
96206
96207
96208
96209
96441
96442
96443
96444
96445
96446
96447






96448
96449
96450
96451







96452
96453
96454
96455
96456
96457
96458







-
-
-
-
-
-
+
+
+
+
-
-
-
-
-
-
-







    /* Otherwise, treat the ORDER BY term as an ordinary expression */
    pItem->u.x.iOrderByCol = 0;
    if( sqlite3ResolveExprNames(pNC, pE) ){
      return 1;
    }
    for(j=0; j<pSelect->pEList->nExpr; j++){
      if( sqlite3ExprCompare(0, pE, pSelect->pEList->a[j].pExpr, -1)==0 ){
#ifndef SQLITE_OMIT_WINDOWFUNC
        if( ExprHasProperty(pE, EP_WinFunc) ){
          /* Since this window function is being changed into a reference
          ** to the same window function the result set, remove the instance
          ** of this window function from the Select.pWin list. */
          Window **pp;
        /* Since this expresion is being changed into a reference
        ** to an identical expression in the result set, remove all Window
        ** objects belonging to the expression from the Select.pWin list. */
        resolveRemoveWindows(pSelect, pE);
          for(pp=&pSelect->pWin; *pp; pp=&(*pp)->pNextWin){
            if( *pp==pE->y.pWin ){
              *pp = (*pp)->pNextWin;
            }    
          }
        }
#endif
        pItem->u.x.iOrderByCol = j+1;
      }
    }
  }
  return sqlite3ResolveOrderGroupBy(pParse, pSelect, pOrderBy, zType);
}

96275
96276
96277
96278
96279
96280
96281
96282

96283
96284
96285
96286
96287
96288
96289
96524
96525
96526
96527
96528
96529
96530

96531
96532
96533
96534
96535
96536
96537
96538







-
+







      p->pOrderBy = 0;
    }
  
    /* Recursively resolve names in all subqueries
    */
    for(i=0; i<p->pSrc->nSrc; i++){
      struct SrcList_item *pItem = &p->pSrc->a[i];
      if( pItem->pSelect ){
      if( pItem->pSelect && (pItem->pSelect->selFlags & SF_Resolved)==0 ){
        NameContext *pNC;         /* Used to iterate name contexts */
        int nRef = 0;             /* Refcount for pOuterNC and outer contexts */
        const char *zSavedContext = pParse->zAuthContext;

        /* Count the total number of references to pOuterNC and all of its
        ** parent contexts. After resolving references to expressions in
        ** pItem->pSelect, check if this value has changed. If so, then
96407
96408
96409
96410
96411
96412
96413

96414
96415
96416
96417
96418
96419
96420
96421
96422
96423

96424
96425
96426
96427
96428
96429
96430
96656
96657
96658
96659
96660
96661
96662
96663
96664
96665
96666
96667
96668
96669
96670
96671
96672
96673
96674
96675
96676
96677
96678
96679
96680
96681







+










+







          sqlite3ErrorMsg(pParse, "aggregate functions are not allowed in "
              "the GROUP BY clause");
          return WRC_Abort;
        }
      }
    }

#ifndef SQLITE_OMIT_WINDOWFUNC
    if( IN_RENAME_OBJECT ){
      Window *pWin;
      for(pWin=p->pWinDefn; pWin; pWin=pWin->pNextWin){
        if( sqlite3ResolveExprListNames(&sNC, pWin->pOrderBy)
         || sqlite3ResolveExprListNames(&sNC, pWin->pPartition)
        ){
          return WRC_Abort;
        }
      }
    }
#endif

    /* If this is part of a compound SELECT, check that it has the right
    ** number of expressions in the select list. */
    if( p->pNext && p->pEList->nExpr!=p->pNext->pEList->nExpr ){
      sqlite3SelectWrongNumTermsError(pParse, p->pNext);
      return WRC_Abort;
    }
96497
96498
96499
96500
96501
96502
96503
96504
96505


96506
96507
96508
96509
96510
96511
96512
96513
96514
96515
96516
96517
96518
96519
96520


96521
96522



96523
96524
96525
96526
96527
96528
96529
96530
96748
96749
96750
96751
96752
96753
96754


96755
96756
96757
96758
96759
96760
96761
96762
96763
96764
96765
96766
96767
96768
96769
96770
96771
96772
96773


96774
96775
96776

96777
96778
96779
96780
96781
96782
96783







-
-
+
+















+
+
-
-
+
+
+
-







  NameContext *pNC,       /* Namespace to resolve expressions in. */
  Expr *pExpr             /* The expression to be analyzed. */
){
  u16 savedHasAgg;
  Walker w;

  if( pExpr==0 ) return SQLITE_OK;
  savedHasAgg = pNC->ncFlags & (NC_HasAgg|NC_MinMaxAgg);
  pNC->ncFlags &= ~(NC_HasAgg|NC_MinMaxAgg);
  savedHasAgg = pNC->ncFlags & (NC_HasAgg|NC_MinMaxAgg|NC_HasWin);
  pNC->ncFlags &= ~(NC_HasAgg|NC_MinMaxAgg|NC_HasWin);
  w.pParse = pNC->pParse;
  w.xExprCallback = resolveExprStep;
  w.xSelectCallback = resolveSelectStep;
  w.xSelectCallback2 = 0;
  w.u.pNC = pNC;
#if SQLITE_MAX_EXPR_DEPTH>0
  w.pParse->nHeight += pExpr->nHeight;
  if( sqlite3ExprCheckHeight(w.pParse, w.pParse->nHeight) ){
    return SQLITE_ERROR;
  }
#endif
  sqlite3WalkExpr(&w, pExpr);
#if SQLITE_MAX_EXPR_DEPTH>0
  w.pParse->nHeight -= pExpr->nHeight;
#endif
  assert( EP_Agg==NC_HasAgg );
  assert( EP_Win==NC_HasWin );
  if( pNC->ncFlags & NC_HasAgg ){
    ExprSetProperty(pExpr, EP_Agg);
  testcase( pNC->ncFlags & NC_HasAgg );
  testcase( pNC->ncFlags & NC_HasWin );
  ExprSetProperty(pExpr, pNC->ncFlags & (NC_HasAgg|NC_HasWin) );
  }
  pNC->ncFlags |= savedHasAgg;
  return pNC->nErr>0 || w.pParse->nErr>0;
}

/*
** Resolve all names for all expression in an expression list.  This is
** just like sqlite3ResolveExprNames() except that it works for an expression
97472
97473
97474
97475
97476
97477
97478
97479

97480
97481
97482
97483
97484
97485
97486
97725
97726
97727
97728
97729
97730
97731

97732
97733
97734
97735
97736
97737
97738
97739







-
+







  if( op==TK_AND && pParse->nErr==0 && !IN_RENAME_OBJECT ){
    /* Take advantage of short-circuit false optimization for AND */
    p = sqlite3ExprAnd(pParse->db, pLeft, pRight);
  }else{
    p = sqlite3DbMallocRawNN(pParse->db, sizeof(Expr));
    if( p ){
      memset(p, 0, sizeof(Expr));
      p->op = op & TKFLG_MASK;
      p->op = op & 0xff;
      p->iAgg = -1;
    }
    sqlite3ExprAttachSubtrees(pParse->db, p, pLeft, pRight);
  }
  if( p ) {
    sqlite3ExprCheckHeight(pParse, p->nHeight);
  }
99167
99168
99169
99170
99171
99172
99173
99174
99175
99176
99177
99178
99179
99180
99181

99182
99183
99184
99185
99186
99187
99188
99420
99421
99422
99423
99424
99425
99426



99427
99428
99429
99430

99431
99432
99433
99434
99435
99436
99437
99438







-
-
-




-
+







    ** We will have to generate an ephemeral table to do the job.
    */
    u32 savedNQueryLoop = pParse->nQueryLoop;
    int rMayHaveNull = 0;
    eType = IN_INDEX_EPH;
    if( inFlags & IN_INDEX_LOOP ){
      pParse->nQueryLoop = 0;
      if( pX->pLeft->iColumn<0 && !ExprHasProperty(pX, EP_xIsSelect) ){
        eType = IN_INDEX_ROWID;
      }
    }else if( prRhsHasNull ){
      *prRhsHasNull = rMayHaveNull = ++pParse->nMem;
    }
    assert( pX->op==TK_IN );
    sqlite3CodeRhsOfIN(pParse, pX, iTab, eType==IN_INDEX_ROWID);
    sqlite3CodeRhsOfIN(pParse, pX, iTab);
    if( rMayHaveNull ){
      sqlite3SetHasNullFlag(v, iTab, rMayHaveNull);
    }
    pParse->nQueryLoop = savedNQueryLoop;
  }

  if( aiMap && eType!=IN_INDEX_INDEX_ASC && eType!=IN_INDEX_INDEX_DESC ){
99275
99276
99277
99278
99279
99280
99281
99282
99283
99284
99285
99286
99287
99288
99289
99290
99291
99292
99293
99294
99295
99296
99297
99298
99299

99300
99301
99302
99303
99304
99305
99306
99307
99525
99526
99527
99528
99529
99530
99531






99532
99533
99534
99535
99536
99537
99538
99539
99540
99541
99542

99543

99544
99545
99546
99547
99548
99549
99550







-
-
-
-
-
-











-
+
-







**
** The pExpr parameter is the IN operator.  The cursor number for the
** constructed ephermeral table is returned.  The first time the ephemeral
** table is computed, the cursor number is also stored in pExpr->iTable,
** however the cursor number returned might not be the same, as it might
** have been duplicated using OP_OpenDup.
**
** If parameter isRowid is non-zero, then LHS of the IN operator is guaranteed
** to be a non-null integer. In this case, the ephemeral table can be an
** table B-Tree that keyed by only integers.  The more general cases uses
** an index B-Tree which can have arbitrary keys, but is slower to both
** read and write.
**
** If the LHS expression ("x" in the examples) is a column value, or
** the SELECT statement returns a column value, then the affinity of that
** column is used to build the index keys. If both 'x' and the
** SELECT... statement are columns, then numeric affinity is used
** if either column has NUMERIC or INTEGER affinity. If neither
** 'x' nor the SELECT... statement are columns, then numeric affinity
** is used.
*/
SQLITE_PRIVATE void sqlite3CodeRhsOfIN(
  Parse *pParse,          /* Parsing context */
  Expr *pExpr,            /* The IN operator */
  int iTab,               /* Use this cursor number */
  int iTab                /* Use this cursor number */
  int isRowid             /* If true, LHS is a rowid */
){
  int addrOnce = 0;           /* Address of the OP_Once instruction at top */
  int addr;                   /* Address of OP_OpenEphemeral instruction */
  Expr *pLeft;                /* the LHS of the IN operator */
  KeyInfo *pKeyInfo = 0;      /* Key information */
  int nVal;                   /* Size of vector pLeft */
  Vdbe *v;                    /* The prepared statement under construction */
99346
99347
99348
99349
99350
99351
99352
99353
99354
99355
99356
99357
99358
99359

99360
99361
99362
99363
99364
99365
99366
99367
99368

99369
99370
99371
99372
99373
99374
99375
99376
99377
99378
99379
99380
99381
99382
99383
99384
99385
99386
99387
99388
99389
99589
99590
99591
99592
99593
99594
99595

99596
99597
99598
99599
99600

99601

99602
99603
99604
99605
99606
99607
99608

99609
99610
99611
99612
99613
99614
99615
99616
99617
99618
99619
99620
99621
99622

99623
99624
99625
99626
99627
99628
99629







-





-
+
-







-
+













-








    addrOnce = sqlite3VdbeAddOp0(v, OP_Once); VdbeCoverage(v);
  }

  /* Check to see if this is a vector IN operator */
  pLeft = pExpr->pLeft;
  nVal = sqlite3ExprVectorSize(pLeft);
  assert( !isRowid || nVal==1 );

  /* Construct the ephemeral table that will contain the content of
  ** RHS of the IN operator.
  */
  pExpr->iTable = iTab;
  addr = sqlite3VdbeAddOp2(v, OP_OpenEphemeral, 
  addr = sqlite3VdbeAddOp2(v, OP_OpenEphemeral, pExpr->iTable, nVal);
      pExpr->iTable, (isRowid?0:nVal));
#ifdef SQLITE_ENABLE_EXPLAIN_COMMENTS
  if( ExprHasProperty(pExpr, EP_xIsSelect) ){
    VdbeComment((v, "Result of SELECT %u", pExpr->x.pSelect->selId));
  }else{
    VdbeComment((v, "RHS of IN operator"));
  }
#endif
  pKeyInfo = isRowid ? 0 : sqlite3KeyInfoAlloc(pParse->db, nVal, 1);
  pKeyInfo = sqlite3KeyInfoAlloc(pParse->db, nVal, 1);

  if( ExprHasProperty(pExpr, EP_xIsSelect) ){
    /* Case 1:     expr IN (SELECT ...)
    **
    ** Generate code to write the results of the select into the temporary
    ** table allocated and opened above.
    */
    Select *pSelect = pExpr->x.pSelect;
    ExprList *pEList = pSelect->pEList;

    ExplainQueryPlan((pParse, 1, "%sLIST SUBQUERY %d",
        addrOnce?"":"CORRELATED ", pSelect->selId
    ));
    assert( !isRowid );
    /* If the LHS and RHS of the IN operator do not match, that
    ** error will have been caught long before we reach this point. */
    if( ALWAYS(pEList->nExpr==nVal) ){
      SelectDest dest;
      int i;
      sqlite3SelectDestInit(&dest, SRT_Set, iTab);
      dest.zAffSdst = exprINAffinity(pParse, pExpr);
99428
99429
99430
99431
99432
99433
99434
99435
99436
99437
99438
99439
99440
99441
99442
99443
99444
99445
99446
99447
99448
99449
99450
99451
99452
99453
99454

99455
99456
99457
99458
99459
99460
99461
99462


99463
99464
99465
99466
99467
99468
99469
99470
99471
99668
99669
99670
99671
99672
99673
99674

99675
99676

99677
99678
99679
99680
99681
99682
99683
99684
99685
99686
99687
99688




99689








99690
99691


99692
99693
99694
99695
99696
99697
99698







-


-












-
-
-
-
+
-
-
-
-
-
-
-
-
+
+
-
-







      assert( sqlite3KeyInfoIsWriteable(pKeyInfo) );
      pKeyInfo->aColl[0] = sqlite3ExprCollSeq(pParse, pExpr->pLeft);
    }

    /* Loop through each expression in <exprlist>. */
    r1 = sqlite3GetTempReg(pParse);
    r2 = sqlite3GetTempReg(pParse);
    if( isRowid ) sqlite3VdbeAddOp4(v, OP_Blob, 0, r2, 0, "", P4_STATIC);
    for(i=pList->nExpr, pItem=pList->a; i>0; i--, pItem++){
      Expr *pE2 = pItem->pExpr;
      int iValToIns;

      /* If the expression is not constant then we will need to
      ** disable the test that was generated above that makes sure
      ** this code only executes once.  Because for a non-constant
      ** expression we need to rerun this code each time.
      */
      if( addrOnce && !sqlite3ExprIsConstant(pE2) ){
        sqlite3VdbeChangeToNoop(v, addrOnce);
        addrOnce = 0;
      }

      /* Evaluate the expression and insert it into the temp table */
      if( isRowid && sqlite3ExprIsInteger(pE2, &iValToIns) ){
        sqlite3VdbeAddOp3(v, OP_InsertInt, iTab, r2, iValToIns);
      }else{
        r3 = sqlite3ExprCodeTarget(pParse, pE2, r1);
      r3 = sqlite3ExprCodeTarget(pParse, pE2, r1);
        if( isRowid ){
          sqlite3VdbeAddOp2(v, OP_MustBeInt, r3,
                            sqlite3VdbeCurrentAddr(v)+2);
          VdbeCoverage(v);
          sqlite3VdbeAddOp3(v, OP_Insert, iTab, r2, r3);
        }else{
          sqlite3VdbeAddOp4(v, OP_MakeRecord, r3, 1, r2, &affinity, 1);
          sqlite3VdbeAddOp4Int(v, OP_IdxInsert, iTab, r2, r3, 1);
      sqlite3VdbeAddOp4(v, OP_MakeRecord, r3, 1, r2, &affinity, 1);
      sqlite3VdbeAddOp4Int(v, OP_IdxInsert, iTab, r2, r3, 1);
        }
      }
    }
    sqlite3ReleaseTempReg(pParse, r1);
    sqlite3ReleaseTempReg(pParse, r2);
  }
  if( pKeyInfo ){
    sqlite3VdbeChangeP4(v, addr, (void *)pKeyInfo, P4_KEYINFO);
  }
101673
101674
101675
101676
101677
101678
101679











101680
101681
101682
101683
101684
101685
101686
101900
101901
101902
101903
101904
101905
101906
101907
101908
101909
101910
101911
101912
101913
101914
101915
101916
101917
101918
101919
101920
101921
101922
101923
101924







+
+
+
+
+
+
+
+
+
+
+







** an ordinary JOIN.  The p argument is the WHERE clause.  If the WHERE
** clause requires that some column of the right table of the LEFT JOIN
** be non-NULL, then the LEFT JOIN can be safely converted into an
** ordinary join.
*/
SQLITE_PRIVATE int sqlite3ExprImpliesNonNullRow(Expr *p, int iTab){
  Walker w;
  p = sqlite3ExprSkipCollate(p);
  while( p ){
    if( p->op==TK_NOTNULL ){
      p = p->pLeft;
    }else if( p->op==TK_AND ){
      if( sqlite3ExprImpliesNonNullRow(p->pLeft, iTab) ) return 1;
      p = p->pRight;
    }else{
      break;
    }
  }
  w.xExprCallback = impliesNotNullRow;
  w.xSelectCallback = 0;
  w.xSelectCallback2 = 0;
  w.eCode = 0;
  w.u.iCur = iTab;
  sqlite3WalkExpr(&w, p);
  return w.eCode;
102254
102255
102256
102257
102258
102259
102260
102261
102262
102263
102264




102265
102266
102267
102268
102269

102270
102271
102272
102273
102274
102275
102276
102492
102493
102494
102495
102496
102497
102498




102499
102500
102501
102502

102503
102504
102505
102506
102507
102508
102509
102510
102511
102512
102513
102514







-
-
-
-
+
+
+
+
-




+







    pVTab = sqlite3GetVTable(db, pTab);
    if( pVTab->pVtab->pModule->xRename==0 ){
      pVTab = 0;
    }
  }
#endif

  /* Begin a transaction for database iDb. 
  ** Then modify the schema cookie (since the ALTER TABLE modifies the
  ** schema). Open a statement transaction if the table is a virtual
  ** table.
  /* Begin a transaction for database iDb. Then modify the schema cookie
  ** (since the ALTER TABLE modifies the schema). Call sqlite3MayAbort(),
  ** as the scalar functions (e.g. sqlite_rename_table()) invoked by the 
  ** nested SQL may raise an exception.  */
  */
  v = sqlite3GetVdbe(pParse);
  if( v==0 ){
    goto exit_rename_table;
  }
  sqlite3MayAbort(pParse);

  /* figure out how many UTF-8 characters are in zName */
  zTabName = pTab->zName;
  nTabName = sqlite3Utf8CharLen(zTabName, -1);

  /* Rewrite all CREATE TABLE, INDEX, TRIGGER or VIEW statements in
  ** the schema to use the new table name.  */
102331
102332
102333
102334
102335
102336
102337
102338
102339
102340
102341
102342
102343
102344
102345
102569
102570
102571
102572
102573
102574
102575

102576
102577
102578
102579
102580
102581
102582







-







  ** SQLite tables) that are identified by the name of the virtual table.
  */
#ifndef SQLITE_OMIT_VIRTUALTABLE
  if( pVTab ){
    int i = ++pParse->nMem;
    sqlite3VdbeLoadString(v, i, zName);
    sqlite3VdbeAddOp4(v, OP_VRename, i, 0, 0,(const char*)pVTab, P4_VTAB);
    sqlite3MayAbort(pParse);
  }
#endif

  renameReloadSchema(pParse, iDb);
  renameTestSchema(pParse, zDb, iDb==1);

exit_rename_table:
102652
102653
102654
102655
102656
102657
102658

102659
102660
102661
102662
102663
102664
102665
102889
102890
102891
102892
102893
102894
102895
102896
102897
102898
102899
102900
102901
102902
102903







+







    goto exit_rename_column;
  }

  /* Do the rename operation using a recursive UPDATE statement that
  ** uses the sqlite_rename_column() SQL function to compute the new
  ** CREATE statement text for the sqlite_master table.
  */
  sqlite3MayAbort(pParse);
  zNew = sqlite3NameFromToken(db, pNew);
  if( !zNew ) goto exit_rename_column;
  assert( pNew->n>0 );
  bQuote = sqlite3Isquote(pNew->z[0]);
  sqlite3NestedParse(pParse, 
      "UPDATE \"%w\".%s SET "
      "sql = sqlite_rename_column(sql, type, name, %Q, %Q, %d, %Q, %d, %d) "
105906
105907
105908
105909
105910
105911
105912

105913


105914
105915
105916
105917
105918
105919
105920
106144
106145
106146
106147
106148
106149
106150
106151

106152
106153
106154
106155
106156
106157
106158
106159
106160







+
-
+
+







  ** remove the entry from the db->aDb[] array. i.e. put everything back the
  ** way we found it.
  */
  if( rc==SQLITE_OK ){
    sqlite3BtreeEnterAll(db);
    db->init.iDb = 0;
    db->mDbFlags &= ~(DBFLAG_SchemaKnownOk);
    if( !REOPEN_AS_MEMDB(db) ){
    rc = sqlite3Init(db, &zErrDyn);
      rc = sqlite3Init(db, &zErrDyn);
    }
    sqlite3BtreeLeaveAll(db);
    assert( zErrDyn==0 || rc!=SQLITE_OK );
  }
#ifdef SQLITE_USER_AUTHENTICATION
  if( rc==SQLITE_OK ){
    u8 newAuth = 0;
    rc = sqlite3UserAuthCheckLogin(db, zName, &newAuth);
106840
106841
106842
106843
106844
106845
106846





106847

106848
106849
106850
106851
106852
106853
106854
107080
107081
107082
107083
107084
107085
107086
107087
107088
107089
107090
107091

107092
107093
107094
107095
107096
107097
107098
107099







+
+
+
+
+
-
+








  if( pParse->nErr ) return;
  assert( pParse->nested<10 );  /* Nesting should only be of limited depth */
  va_start(ap, zFormat);
  zSql = sqlite3VMPrintf(db, zFormat, ap);
  va_end(ap);
  if( zSql==0 ){
    /* This can result either from an OOM or because the formatted string
    ** exceeds SQLITE_LIMIT_LENGTH.  In the latter case, we need to set
    ** an error */
    if( !db->mallocFailed ) pParse->rc = SQLITE_TOOBIG;
    pParse->nErr++;
    return;   /* A malloc must have failed */
    return;
  }
  pParse->nested++;
  memcpy(saveBuf, PARSE_TAIL(pParse), PARSE_TAIL_SZ);
  memset(PARSE_TAIL(pParse), 0, PARSE_TAIL_SZ);
  sqlite3RunParser(pParse, zSql, &zErrMsg);
  sqlite3DbFree(db, zErrMsg);
  sqlite3DbFree(db, zSql);
107980
107981
107982
107983
107984
107985
107986

107987

107988
107989
107990
107991
107992
107993
107994
108225
108226
108227
108228
108229
108230
108231
108232

108233
108234
108235
108236
108237
108238
108239
108240







+
-
+







  }
  if( nTerm==1
   && pCol
   && sqlite3StrICmp(sqlite3ColumnType(pCol,""), "INTEGER")==0
   && sortOrder!=SQLITE_SO_DESC
  ){
    if( IN_RENAME_OBJECT && pList ){
      Expr *pCExpr = sqlite3ExprSkipCollate(pList->a[0].pExpr);
      sqlite3RenameTokenRemap(pParse, &pTab->iPKey, pList->a[0].pExpr);
      sqlite3RenameTokenRemap(pParse, &pTab->iPKey, pCExpr);
    }
    pTab->iPKey = iCol;
    pTab->keyConf = (u8)onError;
    assert( autoInc==0 || autoInc==1 );
    pTab->tabFlags |= autoInc*TF_Autoincrement;
    if( pList ) pParse->iPkSortOrder = pList->a[0].sortOrder;
  }else if( autoInc ){
108401
108402
108403
108404
108405
108406
108407

108408
108409
108410
108411
108412
108413
108414
108647
108648
108649
108650
108651
108652
108653
108654
108655
108656
108657
108658
108659
108660
108661







+







    sqlite3CreateIndex(pParse, 0, 0, 0, pList, pTab->keyConf, 0, 0, 0, 0,
                       SQLITE_IDXTYPE_PRIMARYKEY);
    if( db->mallocFailed || pParse->nErr ) return;
    pPk = sqlite3PrimaryKeyIndex(pTab);
    pTab->iPKey = -1;
  }else{
    pPk = sqlite3PrimaryKeyIndex(pTab);
    assert( pPk!=0 );

    /*
    ** Remove all redundant columns from the PRIMARY KEY.  For example, change
    ** "PRIMARY KEY(a,b,a,b,c,b,c,d)" into just "PRIMARY KEY(a,b,c,d)".  Later
    ** code assumes the PRIMARY KEY contains no repeated columns.
    */
    for(i=j=1; i<pPk->nKeyCol; i++){
108570
108571
108572
108573
108574
108575
108576





108577
108578
108579
108580
108581
108582
108583
108817
108818
108819
108820
108821
108822
108823
108824
108825
108826
108827
108828
108829
108830
108831
108832
108833
108834
108835







+
+
+
+
+







      sqlite3ErrorMsg(pParse, "");
      return;
    }
    p->tnum = db->init.newTnum;
    if( p->tnum==1 ) p->tabFlags |= TF_Readonly;
  }

  assert( (p->tabFlags & TF_HasPrimaryKey)==0
       || p->iPKey>=0 || sqlite3PrimaryKeyIndex(p)!=0 );
  assert( (p->tabFlags & TF_HasPrimaryKey)!=0
       || (p->iPKey<0 && sqlite3PrimaryKeyIndex(p)==0) );

  /* Special processing for WITHOUT ROWID Tables */
  if( tabOpts & TF_WithoutRowid ){
    if( (p->tabFlags & TF_Autoincrement) ){
      sqlite3ErrorMsg(pParse,
          "AUTOINCREMENT not allowed on WITHOUT ROWID tables");
      return;
    }
109723
109724
109725
109726
109727
109728
109729

109730
109731
109732
109733
109734
109735
109736
109737
109738
109739
109740
109741
109742
109743
109975
109976
109977
109978
109979
109980
109981
109982
109983
109984
109985
109986
109987
109988

109989
109990
109991
109992
109993
109994
109995







+






-







  }
  pDb = &db->aDb[iDb];

  assert( pTab!=0 );
  assert( pParse->nErr==0 );
  if( sqlite3StrNICmp(pTab->zName, "sqlite_", 7)==0 
       && db->init.busy==0
       && pTblName!=0
#if SQLITE_USER_AUTHENTICATION
       && sqlite3UserAuthTable(pTab->zName)==0
#endif
#ifdef SQLITE_ALLOW_SQLITE_MASTER_INDEX
       && sqlite3StrICmp(&pTab->zName[7],"master")!=0
#endif
       && sqlite3StrNICmp(&pTab->zName[7],"altertab_",9)!=0
 ){
    sqlite3ErrorMsg(pParse, "table %s may not be indexed", pTab->zName);
    goto exit_create_index;
  }
#ifndef SQLITE_OMIT_VIEW
  if( pTab->pSelect ){
    sqlite3ErrorMsg(pParse, "views may not be indexed");
109833
109834
109835
109836
109837
109838
109839

109840
109841
109842
109843
109844
109845
109846
109847
109848
109849
109850
109851
109852
109853
109854
109855
109856
109857

109858
109859
109860
109861
109862
109863
109864
110085
110086
110087
110088
110089
110090
110091
110092
110093
110094
110095
110096
110097
110098
110099
110100
110101
110102
110103
110104
110105
110106
110107
110108
110109
110110
110111
110112
110113
110114
110115
110116
110117
110118







+


















+







    pList = sqlite3ExprListAppend(pParse, 0,
              sqlite3ExprAlloc(db, TK_ID, &prevCol, 0));
    if( pList==0 ) goto exit_create_index;
    assert( pList->nExpr==1 );
    sqlite3ExprListSetSortOrder(pList, sortOrder);
  }else{
    sqlite3ExprListCheckLength(pParse, pList, "index");
    if( pParse->nErr ) goto exit_create_index;
  }

  /* Figure out how many bytes of space are required to store explicitly
  ** specified collation sequence names.
  */
  for(i=0; i<pList->nExpr; i++){
    Expr *pExpr = pList->a[i].pExpr;
    assert( pExpr!=0 );
    if( pExpr->op==TK_COLLATE ){
      nExtra += (1 + sqlite3Strlen30(pExpr->u.zToken));
    }
  }

  /* 
  ** Allocate the index structure. 
  */
  nName = sqlite3Strlen30(zName);
  nExtraCol = pPk ? pPk->nKeyCol : 1;
  assert( pList->nExpr + nExtraCol <= 32767 /* Fits in i16 */ );
  pIndex = sqlite3AllocateIndexObject(db, pList->nExpr + nExtraCol,
                                      nName + nExtra + 1, &zExtra);
  if( db->mallocFailed ){
    goto exit_create_index;
  }
  assert( EIGHT_BYTE_ALIGNMENT(pIndex->aiRowLogEst) );
  assert( EIGHT_BYTE_ALIGNMENT(pIndex->azColl) );
110458
110459
110460
110461
110462
110463
110464
110465
110466
110467
110468
110469
110470
110471
110472
110473
110474
110475
110476
110477
110478
110479
110480
110481
110482

110483
110484
110485
110486
110487
110488
110489
110712
110713
110714
110715
110716
110717
110718

110719
110720
110721
110722
110723
110724
110725
110726
110727
110728
110729
110730
110731
110732
110733


110734
110735
110736
110737
110738
110739
110740
110741







-















-
-
+







  assert( pSrc!=0 );
  assert( iStart<=pSrc->nSrc );

  /* Allocate additional space if needed */
  if( (u32)pSrc->nSrc+nExtra>pSrc->nAlloc ){
    SrcList *pNew;
    int nAlloc = pSrc->nSrc*2+nExtra;
    int nGot;
    sqlite3 *db = pParse->db;

    if( pSrc->nSrc+nExtra>=SQLITE_MAX_SRCLIST ){
      sqlite3ErrorMsg(pParse, "too many FROM clause terms, max: %d",
                      SQLITE_MAX_SRCLIST);
      return 0;
    }
    if( nAlloc>SQLITE_MAX_SRCLIST ) nAlloc = SQLITE_MAX_SRCLIST;
    pNew = sqlite3DbRealloc(db, pSrc,
               sizeof(*pSrc) + (nAlloc-1)*sizeof(pSrc->a[0]) );
    if( pNew==0 ){
      assert( db->mallocFailed );
      return 0;
    }
    pSrc = pNew;
    nGot = (sqlite3DbMallocSize(db, pNew) - sizeof(*pSrc))/sizeof(pSrc->a[0])+1;
    pSrc->nAlloc = nGot;
    pSrc->nAlloc = nAlloc;
  }

  /* Move existing slots that come after the newly inserted slots
  ** out of the way */
  for(i=pSrc->nSrc-1; i>=iStart; i--){
    pSrc->a[i+nExtra] = pSrc->a[i];
  }
114523
114524
114525
114526
114527
114528
114529




114530
114531
114532
114533
114534
114535
114536
114775
114776
114777
114778
114779
114780
114781
114782
114783
114784
114785
114786
114787
114788
114789
114790
114791
114792







+
+
+
+







*/
static void setLikeOptFlag(sqlite3 *db, const char *zName, u8 flagVal){
  FuncDef *pDef;
  pDef = sqlite3FindFunction(db, zName, 2, SQLITE_UTF8, 0);
  if( ALWAYS(pDef) ){
    pDef->funcFlags |= flagVal;
  }
  pDef = sqlite3FindFunction(db, zName, 3, SQLITE_UTF8, 0);
  if( pDef ){
    pDef->funcFlags |= flagVal;
  }
}

/*
** Register the built-in LIKE and GLOB functions.  The caseSensitive
** parameter determines whether or not the LIKE operator is case
** sensitive.  GLOB is always case sensitive.
*/
117845
117846
117847
117848
117849
117850
117851

117852


117853
117854
117855
117856
117857
117858
117859
118101
118102
118103
118104
118105
118106
118107
118108

118109
118110
118111
118112
118113
118114
118115
118116
118117







+
-
+
+







        sqlite3VdbeAddOp2(v, iField<0 ? OP_IntCopy : OP_SCopy, x, regIdx+i);
        VdbeComment((v, "%s", iField<0 ? "rowid" : pTab->aCol[iField].zName));
      }
    }
    sqlite3VdbeAddOp3(v, OP_MakeRecord, regIdx, pIdx->nColumn, aRegIdx[ix]);
    VdbeComment((v, "for %s", pIdx->zName));
#ifdef SQLITE_ENABLE_NULL_TRIM
    if( pIdx->idxType==SQLITE_IDXTYPE_PRIMARYKEY ){
    if( pIdx->idxType==2 ) sqlite3SetMakeRecordP5(v, pIdx->pTable);
      sqlite3SetMakeRecordP5(v, pIdx->pTable);
    }
#endif

    /* In an UPDATE operation, if this index is the PRIMARY KEY index 
    ** of a WITHOUT ROWID table and there has been no change the
    ** primary key, then no collision is possible.  The collision detection
    ** logic below can all be skipped. */
    if( isUpdate && pPk==pIdx && pkChng==0 ){
118095
118096
118097
118098
118099
118100
118101


118102
118103


118104
118105

118106
118107
118108
118109
118110
118111
118112
118353
118354
118355
118356
118357
118358
118359
118360
118361


118362
118363
118364
118365
118366
118367
118368
118369
118370
118371
118372
118373







+
+
-
-
+
+


+







    pik_flags = (useSeekResult ? OPFLAG_USESEEKRESULT : 0);
    if( IsPrimaryKeyIndex(pIdx) && !HasRowid(pTab) ){
      assert( pParse->nested==0 );
      pik_flags |= OPFLAG_NCHANGE;
      pik_flags |= (update_flags & OPFLAG_SAVEPOSITION);
#ifdef SQLITE_ENABLE_PREUPDATE_HOOK
      if( update_flags==0 ){
        int r = sqlite3GetTempReg(pParse);
        sqlite3VdbeAddOp2(v, OP_Integer, 0, r);
        sqlite3VdbeAddOp4(v, OP_InsertInt, 
            iIdxCur+i, aRegIdx[i], 0, (char*)pTab, P4_TABLE
        sqlite3VdbeAddOp4(v, OP_Insert, 
            iIdxCur+i, aRegIdx[i], r, (char*)pTab, P4_TABLE
        );
        sqlite3VdbeChangeP5(v, OPFLAG_ISNOOP);
        sqlite3ReleaseTempReg(pParse, r);
      }
#endif
    }
    sqlite3VdbeAddOp4Int(v, OP_IdxInsert, iIdxCur+i, aRegIdx[i],
                         aRegIdx[i]+1,
                         pIdx->uniqNotNull ? pIdx->nKeyCol: pIdx->nColumn);
    sqlite3VdbeChangeP5(v, pik_flags);
118446
118447
118448
118449
118450
118451
118452







118453
118454
118455
118456
118457
118458
118459
118707
118708
118709
118710
118711
118712
118713
118714
118715
118716
118717
118718
118719
118720
118721
118722
118723
118724
118725
118726
118727







+
+
+
+
+
+
+







    }
    for(pSrcIdx=pSrc->pIndex; pSrcIdx; pSrcIdx=pSrcIdx->pNext){
      if( xferCompatibleIndex(pDestIdx, pSrcIdx) ) break;
    }
    if( pSrcIdx==0 ){
      return 0;    /* pDestIdx has no corresponding index in pSrc */
    }
    if( pSrcIdx->tnum==pDestIdx->tnum && pSrc->pSchema==pDest->pSchema
         && sqlite3FaultSim(411)==SQLITE_OK ){
      /* The sqlite3FaultSim() call allows this corruption test to be
      ** bypassed during testing, in order to exercise other corruption tests
      ** further downstream. */
      return 0;   /* Corrupt schema - two indexes on the same btree */
    }
  }
#ifndef SQLITE_OMIT_CHECK
  if( pDest->pCheck && sqlite3ExprListCompare(pSrc->pCheck,pDest->pCheck,-1) ){
    return 0;   /* Tables have different CHECK constraints.  Ticket #2252 */
  }
#endif
#ifndef SQLITE_OMIT_FOREIGN_KEY
118523
118524
118525
118526
118527
118528
118529
118530

118531
118532
118533
118534
118535
118536
118537
118791
118792
118793
118794
118795
118796
118797

118798
118799
118800
118801
118802
118803
118804
118805







-
+







      addr1 = sqlite3VdbeAddOp2(v, OP_Rowid, iSrc, regRowid);
      sqlite3VdbeVerifyAbortable(v, onError);
      addr2 = sqlite3VdbeAddOp3(v, OP_NotExists, iDest, 0, regRowid);
      VdbeCoverage(v);
      sqlite3RowidConstraint(pParse, onError, pDest);
      sqlite3VdbeJumpHere(v, addr2);
      autoIncStep(pParse, regAutoinc, regRowid);
    }else if( pDest->pIndex==0 ){
    }else if( pDest->pIndex==0 && !(db->mDbFlags & DBFLAG_VacuumInto) ){
      addr1 = sqlite3VdbeAddOp2(v, OP_NewRowid, iDest, regRowid);
    }else{
      addr1 = sqlite3VdbeAddOp2(v, OP_Rowid, iSrc, regRowid);
      assert( (pDest->tabFlags & TF_Autoincrement)==0 );
    }
    sqlite3VdbeAddOp3(v, OP_RowData, iSrc, regData, 1);
    if( db->mDbFlags & DBFLAG_Vacuum ){
118586
118587
118588
118589
118590
118591
118592
118593

118594
118595
118596
118597
118598
118599
118600
118854
118855
118856
118857
118858
118859
118860

118861
118862
118863
118864
118865
118866
118867
118868







-
+







        if( sqlite3_stricmp(sqlite3StrBINARY, zColl) ) break;
      }
      if( i==pSrcIdx->nColumn ){
        idxInsFlags = OPFLAG_USESEEKRESULT;
        sqlite3VdbeAddOp1(v, OP_SeekEnd, iDest);
      }
    }
    if( !HasRowid(pSrc) && pDestIdx->idxType==2 ){
    if( !HasRowid(pSrc) && pDestIdx->idxType==SQLITE_IDXTYPE_PRIMARYKEY ){
      idxInsFlags |= OPFLAG_NCHANGE;
    }
    sqlite3VdbeAddOp2(v, OP_IdxInsert, iDest, regData);
    sqlite3VdbeChangeP5(v, idxInsFlags|OPFLAG_APPEND);
    sqlite3VdbeAddOp2(v, OP_Next, iSrc, addr1+1); VdbeCoverage(v);
    sqlite3VdbeJumpHere(v, addr1);
    sqlite3VdbeAddOp2(v, OP_Close, iSrc, 0);
119098
119099
119100
119101
119102
119103
119104



119105
119106
119107
119108
119109
119110
119111
119366
119367
119368
119369
119370
119371
119372
119373
119374
119375
119376
119377
119378
119379
119380
119381
119382







+
+
+







                            void (*xStep)(sqlite3_context*,int,sqlite3_value**),
                            void (*xFinal)(sqlite3_context*),
                            void (*xValue)(sqlite3_context*),
                            void (*xInv)(sqlite3_context*,int,sqlite3_value**),
                            void(*xDestroy)(void*));
  /* Version 3.26.0 and later */
  const char *(*normalized_sql)(sqlite3_stmt*);
  /* Version 3.28.0 and later */
  int (*stmt_isexplain)(sqlite3_stmt*);
  int (*value_frombind)(sqlite3_value*);
};

/*
** This is the function signature used for all extension entry points.  It
** is also defined in the file "loadext.c".
*/
typedef int (*sqlite3_loadext_entry)(
119387
119388
119389
119390
119391
119392
119393



119394
119395
119396
119397
119398
119399
119400
119658
119659
119660
119661
119662
119663
119664
119665
119666
119667
119668
119669
119670
119671
119672
119673
119674







+
+
+







#define sqlite3_str_errcode            sqlite3_api->str_errcode
#define sqlite3_str_length             sqlite3_api->str_length
#define sqlite3_str_value              sqlite3_api->str_value
/* Version 3.25.0 and later */
#define sqlite3_create_window_function sqlite3_api->create_window_function
/* Version 3.26.0 and later */
#define sqlite3_normalized_sql         sqlite3_api->normalized_sql
/* Version 3.28.0 and later */
#define sqlite3_stmt_isexplain         sqlite3_api->isexplain
#define sqlite3_value_frombind         sqlite3_api->frombind
#endif /* !defined(SQLITE_CORE) && !defined(SQLITE_OMIT_LOAD_EXTENSION) */

#if !defined(SQLITE_CORE) && !defined(SQLITE_OMIT_LOAD_EXTENSION)
  /* This case when the file really is being compiled as a loadable 
  ** extension */
# define SQLITE_EXTENSION_INIT1     const sqlite3_api_routines *sqlite3_api=0;
# define SQLITE_EXTENSION_INIT2(v)  sqlite3_api=v;
119846
119847
119848
119849
119850
119851
119852
119853

119854
119855

119856



119857
119858
119859
119860
119861
119862
119863
120120
120121
120122
120123
120124
120125
120126

120127
120128

120129
120130
120131
120132
120133
120134
120135
120136
120137
120138
120139
120140







-
+

-
+

+
+
+







  sqlite3_str_errcode,
  sqlite3_str_length,
  sqlite3_str_value,
  /* Version 3.25.0 and later */
  sqlite3_create_window_function,
  /* Version 3.26.0 and later */
#ifdef SQLITE_ENABLE_NORMALIZE
  sqlite3_normalized_sql
  sqlite3_normalized_sql,
#else
  0
  0,
#endif
  /* Version 3.28.0 and later */
  sqlite3_stmt_isexplain,
  sqlite3_value_frombind
};

/*
** Attempt to load an SQLite extension library contained in the file
** zFile.  The entry point is zProc.  zProc may be 0 in which case a
** default entry point name (sqlite3_extension_init) is used.  Use
** of the default name is recommended.
120461
120462
120463
120464
120465
120466
120467
120468
120469
120470
120471
120472
120473
120474
120475
120476
120477
120478
120479
120480
120481
120738
120739
120740
120741
120742
120743
120744

120745
120746
120747
120748
120749

120750
120751
120752
120753
120754
120755
120756







-





-







 {/* zName:     */ "compile_options",
  /* ePragTyp:  */ PragTyp_COMPILE_OPTIONS,
  /* ePragFlg:  */ PragFlg_Result0,
  /* ColNames:  */ 0, 0,
  /* iArg:      */ 0 },
#endif
#if !defined(SQLITE_OMIT_FLAG_PRAGMAS)
#if !defined(SQLITE_OMIT_DEPRECATED)
 {/* zName:     */ "count_changes",
  /* ePragTyp:  */ PragTyp_FLAG,
  /* ePragFlg:  */ PragFlg_Result0|PragFlg_NoColumns1,
  /* ColNames:  */ 0, 0,
  /* iArg:      */ SQLITE_CountRows },
#endif
#endif
#if !defined(SQLITE_OMIT_PAGER_PRAGMAS) && SQLITE_OS_WIN
 {/* zName:     */ "data_store_directory",
  /* ePragTyp:  */ PragTyp_DATA_STORE_DIRECTORY,
  /* ePragFlg:  */ PragFlg_NoColumns1,
  /* ColNames:  */ 0, 0,
  /* iArg:      */ 0 },
120490
120491
120492
120493
120494
120495
120496
120497

120498
120499
120500
120501
120502
120503
120504
120505
120506
120507
120508
120509
120510
120511
120512
120513
120514
120515
120516
120517
120518
120519
120520
120521
120522
120523
120524
120525
120526
120527
120528
120529
120765
120766
120767
120768
120769
120770
120771

120772

120773
120774
120775
120776
120777

120778
120779
120780
120781
120782
120783
120784
120785
120786
120787
120788

120789
120790
120791
120792
120793

120794
120795
120796
120797
120798
120799
120800







-
+
-





-











-





-







#if !defined(SQLITE_OMIT_SCHEMA_PRAGMAS)
 {/* zName:     */ "database_list",
  /* ePragTyp:  */ PragTyp_DATABASE_LIST,
  /* ePragFlg:  */ PragFlg_NeedSchema|PragFlg_Result0,
  /* ColNames:  */ 35, 3,
  /* iArg:      */ 0 },
#endif
#if !defined(SQLITE_OMIT_PAGER_PRAGMAS)
#if !defined(SQLITE_OMIT_PAGER_PRAGMAS) && !defined(SQLITE_OMIT_DEPRECATED)
#if !defined(SQLITE_OMIT_DEPRECATED)
 {/* zName:     */ "default_cache_size",
  /* ePragTyp:  */ PragTyp_DEFAULT_CACHE_SIZE,
  /* ePragFlg:  */ PragFlg_NeedSchema|PragFlg_Result0|PragFlg_SchemaReq|PragFlg_NoColumns1,
  /* ColNames:  */ 45, 1,
  /* iArg:      */ 0 },
#endif
#endif
#if !defined(SQLITE_OMIT_FLAG_PRAGMAS)
#if !defined(SQLITE_OMIT_FOREIGN_KEY) && !defined(SQLITE_OMIT_TRIGGER)
 {/* zName:     */ "defer_foreign_keys",
  /* ePragTyp:  */ PragTyp_FLAG,
  /* ePragFlg:  */ PragFlg_Result0|PragFlg_NoColumns1,
  /* ColNames:  */ 0, 0,
  /* iArg:      */ SQLITE_DeferFKs },
#endif
#endif
#if !defined(SQLITE_OMIT_FLAG_PRAGMAS)
#if !defined(SQLITE_OMIT_DEPRECATED)
 {/* zName:     */ "empty_result_callbacks",
  /* ePragTyp:  */ PragTyp_FLAG,
  /* ePragFlg:  */ PragFlg_Result0|PragFlg_NoColumns1,
  /* ColNames:  */ 0, 0,
  /* iArg:      */ SQLITE_NullCallback },
#endif
#endif
#if !defined(SQLITE_OMIT_UTF16)
 {/* zName:     */ "encoding",
  /* ePragTyp:  */ PragTyp_ENCODING,
  /* ePragFlg:  */ PragFlg_Result0|PragFlg_NoColumns1,
  /* ColNames:  */ 0, 0,
  /* iArg:      */ 0 },
120555
120556
120557
120558
120559
120560
120561
120562
120563
120564
120565
120566
120567
120568
120569
120570
120571
120572
120573
120574
120575
120576
120577
120826
120827
120828
120829
120830
120831
120832

120833
120834
120835
120836
120837



120838
120839
120840
120841
120842
120843
120844







-





-
-
-







 {/* zName:     */ "freelist_count",
  /* ePragTyp:  */ PragTyp_HEADER_VALUE,
  /* ePragFlg:  */ PragFlg_ReadOnly|PragFlg_Result0,
  /* ColNames:  */ 0, 0,
  /* iArg:      */ BTREE_FREE_PAGE_COUNT },
#endif
#if !defined(SQLITE_OMIT_FLAG_PRAGMAS)
#if !defined(SQLITE_OMIT_DEPRECATED)
 {/* zName:     */ "full_column_names",
  /* ePragTyp:  */ PragTyp_FLAG,
  /* ePragFlg:  */ PragFlg_Result0|PragFlg_NoColumns1,
  /* ColNames:  */ 0, 0,
  /* iArg:      */ SQLITE_FullColNames },
#endif
#endif
#if !defined(SQLITE_OMIT_FLAG_PRAGMAS)
 {/* zName:     */ "fullfsync",
  /* ePragTyp:  */ PragTyp_FLAG,
  /* ePragFlg:  */ PragFlg_Result0|PragFlg_NoColumns1,
  /* ColNames:  */ 0, 0,
  /* iArg:      */ SQLITE_FullFSync },
#endif
#if !defined(SQLITE_OMIT_SCHEMA_PRAGMAS)
120792
120793
120794
120795
120796
120797
120798
120799
120800
120801
120802
120803
120804
120805
120806
120807
120808
120809
120810
120811
120812
121059
121060
121061
121062
121063
121064
121065

121066
121067
121068
121069
121070

121071
121072
121073
121074
121075
121076
121077







-





-







 {/* zName:     */ "secure_delete",
  /* ePragTyp:  */ PragTyp_SECURE_DELETE,
  /* ePragFlg:  */ PragFlg_Result0,
  /* ColNames:  */ 0, 0,
  /* iArg:      */ 0 },
#endif
#if !defined(SQLITE_OMIT_FLAG_PRAGMAS)
#if !defined(SQLITE_OMIT_DEPRECATED)
 {/* zName:     */ "short_column_names",
  /* ePragTyp:  */ PragTyp_FLAG,
  /* ePragFlg:  */ PragFlg_Result0|PragFlg_NoColumns1,
  /* ColNames:  */ 0, 0,
  /* iArg:      */ SQLITE_ShortColNames },
#endif
#endif
 {/* zName:     */ "shrink_memory",
  /* ePragTyp:  */ PragTyp_SHRINK_MEMORY,
  /* ePragFlg:  */ PragFlg_NoColumns,
  /* ColNames:  */ 0, 0,
  /* iArg:      */ 0 },
 {/* zName:     */ "soft_heap_limit",
129641
129642
129643
129644
129645
129646
129647
129648

129649
129650
129651
129652
129653
129654
129655
129906
129907
129908
129909
129910
129911
129912

129913
129914
129915
129916
129917
129918
129919
129920







-
+








/*
** Update the accumulator memory cells for an aggregate based on
** the current cursor position.
**
** If regAcc is non-zero and there are no min() or max() aggregates
** in pAggInfo, then only populate the pAggInfo->nAccumulator accumulator
** registers i register regAcc contains 0. The caller will take care
** registers if register regAcc contains 0. The caller will take care
** of setting and clearing regAcc.
*/
static void updateAccumulator(Parse *pParse, int regAcc, AggInfo *pAggInfo){
  Vdbe *v = pParse->pVdbe;
  int i;
  int regHit = 0;
  int addrHitTest = 0;
130078
130079
130080
130081
130082
130083
130084

130085
130086
130087
130088
130089
130090
130091
130343
130344
130345
130346
130347
130348
130349
130350
130351
130352
130353
130354
130355
130356
130357







+







     && (pTabList->nSrc==1
         || (pTabList->a[1].fg.jointype&(JT_LEFT|JT_CROSS))!=0)
    ){
      continue;
    }

    if( flattenSubquery(pParse, p, i, isAgg) ){
      if( pParse->nErr ) goto select_end;
      /* This subquery can be absorbed into its parent. */
      i = -1;
    }
    pTabList = p->pSrc;
    if( db->mallocFailed ) goto select_end;
    if( !IgnorableOrderby(pDest) ){
      sSort.pOrderBy = p->pOrderBy;
133732
133733
133734
133735
133736
133737
133738
133739

133740
133741
133742
133743

133744
133745
133746
133747
133748
133749
133750
133751

133752
133753
133754
133755
133756
133757
133758
133759
133760
133761
133762

133763
133764
133765
133766

133767

133768
133769
133770
133771
133772
133773


133774
133775
133776
133777
133778
133779
133780
133998
133999
134000
134001
134002
134003
134004

134005
134006
134007
134008

134009
134010
134011
134012
134013
134014
134015
134016
134017
134018
134019
134020
134021
134022
134023
134024
134025
134026
134027
134028

134029
134030
134031
134032

134033
134034
134035
134036
134037
134038
134039
134040
134041
134042
134043
134044
134045
134046
134047
134048
134049
134050







-
+



-
+








+










-
+



-
+

+






+
+







  sqlite3ExprDelete(pParse->db, pInto);
  return;
}

/*
** This routine implements the OP_Vacuum opcode of the VDBE.
*/
SQLITE_PRIVATE int sqlite3RunVacuum(
SQLITE_PRIVATE SQLITE_NOINLINE int sqlite3RunVacuum(
  char **pzErrMsg,        /* Write error message here */
  sqlite3 *db,            /* Database connection */
  int iDb,                /* Which attached DB to vacuum */
  sqlite3_value *pOut     /* Write results here, if not NULL */
  sqlite3_value *pOut     /* Write results here, if not NULL. VACUUM INTO */
){
  int rc = SQLITE_OK;     /* Return code from service routines */
  Btree *pMain;           /* The database being vacuumed */
  Btree *pTemp;           /* The temporary database we vacuum into */
  u32 saved_mDbFlags;     /* Saved value of db->mDbFlags */
  u64 saved_flags;        /* Saved value of db->flags */
  int saved_nChange;      /* Saved value of db->nChange */
  int saved_nTotalChange; /* Saved value of db->nTotalChange */
  u32 saved_openFlags;    /* Saved value of db->openFlags */
  u8 saved_mTrace;        /* Saved trace settings */
  Db *pDb = 0;            /* Database to detach at end of vacuum */
  int isMemDb;            /* True if vacuuming a :memory: database */
  int nRes;               /* Bytes of reserved space at the end of each page */
  int nDb;                /* Number of attached databases */
  const char *zDbMain;    /* Schema name of database to vacuum */
  const char *zOut;       /* Name of output file */

  if( !db->autoCommit ){
    sqlite3SetString(pzErrMsg, db, "cannot VACUUM from within a transaction");
    return SQLITE_ERROR;
    return SQLITE_ERROR; /* IMP: R-12218-18073 */
  }
  if( db->nVdbeActive>1 ){
    sqlite3SetString(pzErrMsg, db,"cannot VACUUM - SQL statements in progress");
    return SQLITE_ERROR;
    return SQLITE_ERROR; /* IMP: R-15610-35227 */
  }
  saved_openFlags = db->openFlags;
  if( pOut ){
    if( sqlite3_value_type(pOut)!=SQLITE_TEXT ){
      sqlite3SetString(pzErrMsg, db, "non-text filename");
      return SQLITE_ERROR;
    }
    zOut = (const char*)sqlite3_value_text(pOut);
    db->openFlags &= ~SQLITE_OPEN_READONLY;
    db->openFlags |= SQLITE_OPEN_CREATE|SQLITE_OPEN_READWRITE;
  }else{
    zOut = "";
  }

  /* Save the current value of the database flags so that it can be 
  ** restored before returning. Then set the writable-schema flag, and
  ** disable CHECK and foreign key constraints.  */
133805
133806
133807
133808
133809
133810
133811

133812
133813
133814
133815
133816
133817
133818
133819
133820
133821
133822
133823
133824

133825
133826
133827
133828
133829
133830
133831
134075
134076
134077
134078
134079
134080
134081
134082
134083
134084
134085
134086
134087
134088
134089
134090
134091
134092
134093
134094
134095
134096
134097
134098
134099
134100
134101
134102
134103







+













+







  ** actually occurs when doing a vacuum since the vacuum_db is initially
  ** empty.  Only the journal header is written.  Apparently it takes more
  ** time to parse and run the PRAGMA to turn journalling off than it does
  ** to write the journal header file.
  */
  nDb = db->nDb;
  rc = execSqlF(db, pzErrMsg, "ATTACH %Q AS vacuum_db", zOut);
  db->openFlags = saved_openFlags;
  if( rc!=SQLITE_OK ) goto end_of_vacuum;
  assert( (db->nDb-1)==nDb );
  pDb = &db->aDb[nDb];
  assert( strcmp(pDb->zDbSName,"vacuum_db")==0 );
  pTemp = pDb->pBt;
  if( pOut ){
    sqlite3_file *id = sqlite3PagerFile(sqlite3BtreePager(pTemp));
    i64 sz = 0;
    if( id->pMethods!=0 && (sqlite3OsFileSize(id, &sz)!=SQLITE_OK || sz>0) ){
      rc = SQLITE_ERROR;
      sqlite3SetString(pzErrMsg, db, "output file already exists");
      goto end_of_vacuum;
    }
    db->mDbFlags |= DBFLAG_VacuumInto;
  }
  nRes = sqlite3BtreeGetOptimalReserve(pMain);

  /* A VACUUM cannot change the pagesize of an encrypted database. */
#ifdef SQLITE_HAS_CODEC
  if( db->nextPagesize ){
    extern void sqlite3CodecGetKey(sqlite3*, int, void**, int*);
136426
136427
136428
136429
136430
136431
136432
136433
136434
136435
136436
136437
136438
136439
136440
136698
136699
136700
136701
136702
136703
136704

136705
136706
136707
136708
136709
136710
136711







-







    if( pIn ){
      int iMap = 0;               /* Index in aiMap[] */
      pIn += i;
      for(i=iEq;i<pLoop->nLTerm; i++){
        if( pLoop->aLTerm[i]->pExpr==pX ){
          int iOut = iReg + i - iEq;
          if( eType==IN_INDEX_ROWID ){
            testcase( nEq>1 );  /* Happens with a UNIQUE index on ROWID */
            pIn->addrInTop = sqlite3VdbeAddOp2(v, OP_Rowid, iTab, iOut);
          }else{
            int iCol = aiMap ? aiMap[iMap++] : 0;
            pIn->addrInTop = sqlite3VdbeAddOp3(v,OP_Column,iTab, iCol, iOut);
          }
          sqlite3VdbeAddOp1(v, OP_IsNull, iOut); VdbeCoverage(v);
          if( i==iEq ){
137003
137004
137005
137006
137007
137008
137009




























137010
137011
137012
137013
137014
137015
137016
137274
137275
137276
137277
137278
137279
137280
137281
137282
137283
137284
137285
137286
137287
137288
137289
137290
137291
137292
137293
137294
137295
137296
137297
137298
137299
137300
137301
137302
137303
137304
137305
137306
137307
137308
137309
137310
137311
137312
137313
137314
137315







+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+







    x.iIdxCol = iIdxCol;
    x.pIdxExpr = aColExpr->a[iIdxCol].pExpr;
    sqlite3WalkExpr(&w, pWInfo->pWhere);
    sqlite3WalkExprList(&w, pWInfo->pOrderBy);
    sqlite3WalkExprList(&w, pWInfo->pResultSet);
  }
}

/*
** The pTruth expression is always true because it is the WHERE clause
** a partial index that is driving a query loop.  Look through all of the
** WHERE clause terms on the query, and if any of those terms must be
** true because pTruth is true, then mark those WHERE clause terms as
** coded.
*/
static void whereApplyPartialIndexConstraints(
  Expr *pTruth,
  int iTabCur,
  WhereClause *pWC
){
  int i;
  WhereTerm *pTerm;
  while( pTruth->op==TK_AND ){
    whereApplyPartialIndexConstraints(pTruth->pLeft, iTabCur, pWC);
    pTruth = pTruth->pRight;
  }
  for(i=0, pTerm=pWC->a; i<pWC->nTerm; i++, pTerm++){
    Expr *pExpr;
    if( pTerm->wtFlags & TERM_CODED ) continue;
    pExpr = pTerm->pExpr;
    if( sqlite3ExprCompare(0, pExpr, pTruth, iTabCur)==0 ){
      pTerm->wtFlags |= TERM_CODED;
    }
  }
}

/*
** Generate code for the start of the iLevel-th loop in the WHERE clause
** implementation described by pWInfo.
*/
SQLITE_PRIVATE Bitmask sqlite3WhereCodeOneLoopStart(
  Parse *pParse,       /* Parsing context */
137188
137189
137190
137191
137192
137193
137194



137195
137196
137197
137198
137199
137200
137201
137487
137488
137489
137490
137491
137492
137493
137494
137495
137496
137497
137498
137499
137500
137501
137502
137503







+
+
+







    iReleaseReg = ++pParse->nMem;
    iRowidReg = codeEqualityTerm(pParse, pTerm, pLevel, 0, bRev, iReleaseReg);
    if( iRowidReg!=iReleaseReg ) sqlite3ReleaseTempReg(pParse, iReleaseReg);
    addrNxt = pLevel->addrNxt;
    sqlite3VdbeAddOp3(v, OP_SeekRowid, iCur, addrNxt, iRowidReg);
    VdbeCoverage(v);
    pLevel->op = OP_Noop;
    if( (pTerm->prereqAll & pLevel->notReady)==0 ){
      pTerm->wtFlags |= TERM_CODED;
    }
  }else if( (pLoop->wsFlags & WHERE_IPK)!=0
         && (pLoop->wsFlags & WHERE_COLUMN_RANGE)!=0
  ){
    /* Case 3:  We have an inequality comparison against the ROWID field.
    */
    int testOp = OP_Noop;
    int start;
137600
137601
137602
137603
137604
137605
137606





137607
137608

137609
137610








137611
137612
137613
137614
137615
137616
137617
137902
137903
137904
137905
137906
137907
137908
137909
137910
137911
137912
137913
137914

137915
137916
137917
137918
137919
137920
137921
137922
137923
137924
137925
137926
137927
137928
137929
137930
137931
137932







+
+
+
+
+

-
+


+
+
+
+
+
+
+
+







    ** into reference to index columns.
    **
    ** Do not do this for the RHS of a LEFT JOIN. This is because the 
    ** expression may be evaluated after OP_NullRow has been executed on
    ** the cursor. In this case it is important to do the full evaluation,
    ** as the result of the expression may not be NULL, even if all table
    ** column values are.  https://www.sqlite.org/src/info/7fa8049685b50b5a
    **
    ** Also, do not do this when processing one index an a multi-index
    ** OR clause, since the transformation will become invalid once we
    ** move forward to the next index.
    ** https://sqlite.org/src/info/4e8e4857d32d401f
    */
    if( pLevel->iLeftJoin==0 ){
    if( pLevel->iLeftJoin==0 && (pWInfo->wctrlFlags & WHERE_OR_SUBCLAUSE)==0 ){
      whereIndexExprTrans(pIdx, iCur, iIdxCur, pWInfo);
    }

    /* If a partial index is driving the loop, try to eliminate WHERE clause
    ** terms from the query that must be true due to the WHERE clause of
    ** the partial index
    */
    if( pIdx->pPartIdxWhere ){
      whereApplyPartialIndexConstraints(pIdx->pPartIdxWhere, iCur, pWC);
    }

    /* Record the instruction used to terminate the loop. */
    if( pLoop->wsFlags & WHERE_ONEROW ){
      pLevel->op = OP_Noop;
    }else if( bRev ){
      pLevel->op = OP_Prev;
    }else{
137768
137769
137770
137771
137772
137773
137774





137775

137776
137777
137778
137779
137780
137781
137782
138083
138084
138085
138086
138087
138088
138089
138090
138091
138092
138093
138094

138095
138096
138097
138098
138099
138100
138101
138102







+
+
+
+
+
-
+







        if( (pWC->a[iTerm].wtFlags & (TERM_VIRTUAL|TERM_CODED))!=0 ) continue;
        if( (pWC->a[iTerm].eOperator & WO_ALL)==0 ) continue;
        testcase( pWC->a[iTerm].wtFlags & TERM_ORINFO );
        pExpr = sqlite3ExprDup(db, pExpr, 0);
        pAndExpr = sqlite3ExprAnd(db, pAndExpr, pExpr);
      }
      if( pAndExpr ){
        /* The extra 0x10000 bit on the opcode is masked off and does not
        ** become part of the new Expr.op.  However, it does make the
        ** op==TK_AND comparison inside of sqlite3PExpr() false, and this
        ** prevents sqlite3PExpr() from implementing AND short-circuit 
        ** optimization, which we do not want here. */
        pAndExpr = sqlite3PExpr(pParse, TK_AND|TKFLG_DONTFOLD, 0, pAndExpr);
        pAndExpr = sqlite3PExpr(pParse, TK_AND|0x10000, 0, pAndExpr);
      }
    }

    /* Run a separate WHERE clause for each term of the OR clause.  After
    ** eliminating duplicates from other WHERE clauses, the action for each
    ** sub-WHERE clause is to to invoke the main loop body as a subroutine.
    */
137998
137999
138000
138001
138002
138003
138004


138005
138006
138007
138008
138009
138010
138011
138012
138013
138318
138319
138320
138321
138322
138323
138324
138325
138326
138327

138328
138329
138330
138331
138332
138333
138334







+
+

-







        ** that compares BLOBs. */
#ifdef SQLITE_LIKE_DOESNT_MATCH_BLOBS
        continue;
#else
        u32 x = pLevel->iLikeRepCntr;
        if( x>0 ){
          skipLikeAddr = sqlite3VdbeAddOp1(v, (x&1)?OP_IfNot:OP_If,(int)(x>>1));
          VdbeCoverageIf(v, (x&1)==1);
          VdbeCoverageIf(v, (x&1)==0);
        }
        VdbeCoverage(v);
#endif
      }
#ifdef WHERETRACE_ENABLED /* 0xffff */
      if( sqlite3WhereTrace ){
        VdbeNoopComment((v, "WhereTerm[%d] (%p) priority=%d",
                         pWC->nTerm-j, pTerm, iLoop));
      }
139601
139602
139603
139604
139605
139606
139607






139608
139609
139610
139611
139612
139613
139614
139922
139923
139924
139925
139926
139927
139928
139929
139930
139931
139932
139933
139934
139935
139936
139937
139938
139939
139940
139941







+
+
+
+
+
+







    assert( p->x.pList==0 );
  }else if( ExprHasProperty(p, EP_xIsSelect) ){
    if( ExprHasProperty(p, EP_VarSelect) ) pMaskSet->bVarSelect = 1;
    mask |= exprSelectUsage(pMaskSet, p->x.pSelect);
  }else if( p->x.pList ){
    mask |= sqlite3WhereExprListUsage(pMaskSet, p->x.pList);
  }
#ifndef SQLITE_OMIT_WINDOWFUNC
  if( p->op==TK_FUNCTION && p->y.pWin ){
    mask |= sqlite3WhereExprListUsage(pMaskSet, p->y.pWin->pPartition);
    mask |= sqlite3WhereExprListUsage(pMaskSet, p->y.pWin->pOrderBy);
  }
#endif
  return mask;
}
SQLITE_PRIVATE Bitmask sqlite3WhereExprUsage(WhereMaskSet *pMaskSet, Expr *p){
  return p ? sqlite3WhereExprUsageNN(pMaskSet,p) : 0;
}
SQLITE_PRIVATE Bitmask sqlite3WhereExprListUsage(WhereMaskSet *pMaskSet, ExprList *pList){
  int i;
143017
143018
143019
143020
143021
143022
143023
143024
143025
143026
143027
143028





143029
143030
143031
143032
143033
143034
143035
143344
143345
143346
143347
143348
143349
143350





143351
143352
143353
143354
143355
143356
143357
143358
143359
143360
143361
143362







-
-
-
-
-
+
+
+
+
+








  /* First call xBestIndex() with all constraints usable. */
  WHERETRACE(0x800, ("BEGIN %s.addVirtual()\n", pSrc->pTab->zName));
  WHERETRACE(0x40, ("  VirtualOne: all usable\n"));
  rc = whereLoopAddVirtualOne(pBuilder, mPrereq, ALLBITS, 0, p, mNoOmit, &bIn);

  /* If the call to xBestIndex() with all terms enabled produced a plan
  ** that does not require any source tables (IOW: a plan with mBest==0),
  ** then there is no point in making any further calls to xBestIndex() 
  ** since they will all return the same result (if the xBestIndex()
  ** implementation is sane). */
  if( rc==SQLITE_OK && (mBest = (pNew->prereq & ~mPrereq))!=0 ){
  ** that does not require any source tables (IOW: a plan with mBest==0)
  ** and does not use an IN(...) operator, then there is no point in making 
  ** any further calls to xBestIndex() since they will all return the same
  ** result (if the xBestIndex() implementation is sane). */
  if( rc==SQLITE_OK && ((mBest = (pNew->prereq & ~mPrereq))!=0 || bIn) ){
    int seenZero = 0;             /* True if a plan with no prereqs seen */
    int seenZeroNoIN = 0;         /* Plan with no prereqs and no IN(...) seen */
    Bitmask mPrev = 0;
    Bitmask mBestNoIn = 0;

    /* If the plan produced by the earlier call uses an IN(...) term, call
    ** xBestIndex again, this time with IN(...) terms disabled. */
145254
145255
145256
145257
145258
145259
145260


























































































145261
145262
145263
145264
145265
145266
145267
145581
145582
145583
145584
145585
145586
145587
145588
145589
145590
145591
145592
145593
145594
145595
145596
145597
145598
145599
145600
145601
145602
145603
145604
145605
145606
145607
145608
145609
145610
145611
145612
145613
145614
145615
145616
145617
145618
145619
145620
145621
145622
145623
145624
145625
145626
145627
145628
145629
145630
145631
145632
145633
145634
145635
145636
145637
145638
145639
145640
145641
145642
145643
145644
145645
145646
145647
145648
145649
145650
145651
145652
145653
145654
145655
145656
145657
145658
145659
145660
145661
145662
145663
145664
145665
145666
145667
145668
145669
145670
145671
145672
145673
145674
145675
145676
145677
145678
145679
145680
145681
145682
145683
145684







+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+







      p->nValue++;
      p->nStep = 0;
    }
    sqlite3_result_int64(pCtx, p->nValue);
  }
}

/*
** Implementation of built-in window function nth_value(). This
** implementation is used in "slow mode" only - when the EXCLUDE clause
** is not set to the default value "NO OTHERS".
*/
struct NthValueCtx {
  i64 nStep;
  sqlite3_value *pValue;
};
static void nth_valueStepFunc(
  sqlite3_context *pCtx, 
  int nArg,
  sqlite3_value **apArg
){
  struct NthValueCtx *p;
  p = (struct NthValueCtx*)sqlite3_aggregate_context(pCtx, sizeof(*p));
  if( p ){
    i64 iVal;
    switch( sqlite3_value_numeric_type(apArg[1]) ){
      case SQLITE_INTEGER:
        iVal = sqlite3_value_int64(apArg[1]);
        break;
      case SQLITE_FLOAT: {
        double fVal = sqlite3_value_double(apArg[1]);
        if( ((i64)fVal)!=fVal ) goto error_out;
        iVal = (i64)fVal;
        break;
      }
      default:
        goto error_out;
    }
    if( iVal<=0 ) goto error_out;

    p->nStep++;
    if( iVal==p->nStep ){
      p->pValue = sqlite3_value_dup(apArg[0]);
      if( !p->pValue ){
        sqlite3_result_error_nomem(pCtx);
      }
    }
  }
  UNUSED_PARAMETER(nArg);
  UNUSED_PARAMETER(apArg);
  return;

 error_out:
  sqlite3_result_error(
      pCtx, "second argument to nth_value must be a positive integer", -1
  );
}
static void nth_valueFinalizeFunc(sqlite3_context *pCtx){
  struct NthValueCtx *p;
  p = (struct NthValueCtx*)sqlite3_aggregate_context(pCtx, 0);
  if( p && p->pValue ){
    sqlite3_result_value(pCtx, p->pValue);
    sqlite3_value_free(p->pValue);
    p->pValue = 0;
  }
}
#define nth_valueInvFunc noopStepFunc
#define nth_valueValueFunc noopValueFunc

static void first_valueStepFunc(
  sqlite3_context *pCtx, 
  int nArg,
  sqlite3_value **apArg
){
  struct NthValueCtx *p;
  p = (struct NthValueCtx*)sqlite3_aggregate_context(pCtx, sizeof(*p));
  if( p && p->pValue==0 ){
    p->pValue = sqlite3_value_dup(apArg[0]);
    if( !p->pValue ){
      sqlite3_result_error_nomem(pCtx);
    }
  }
  UNUSED_PARAMETER(nArg);
  UNUSED_PARAMETER(apArg);
}
static void first_valueFinalizeFunc(sqlite3_context *pCtx){
  struct NthValueCtx *p;
  p = (struct NthValueCtx*)sqlite3_aggregate_context(pCtx, sizeof(*p));
  if( p && p->pValue ){
    sqlite3_result_value(pCtx, p->pValue);
    sqlite3_value_free(p->pValue);
    p->pValue = 0;
  }
}
#define first_valueInvFunc noopStepFunc
#define first_valueValueFunc noopValueFunc

/*
** Implementation of built-in window function rank(). Assumes that
** the window frame has been set to:
**
**   RANGE BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW 
*/
static void rankStepFunc(
145289
145290
145291
145292
145293
145294
145295
145296

145297
145298
145299
145300
145301
145302
145303
145304
145305


145306
145307
145308

145309
145310

145311
145312
145313
145314

145315










145316
145317
145318
145319
145320

145321
145322

145323
145324
145325
145326
145327
145328
145329

145330
145331
145332
145333
145334
145335

145336
145337
145338
145339
145340
145341
145342
145343
145344


145345
145346
145347

145348
145349

145350
145351











145352
145353
145354
145355
145356


145357
145358
145359
145360

145361
145362
145363
145364
145365
145366
145367
145368
145369
145370
145371
145372
145373
145374
145375

145376
145377
145378
145379
145380
145381
145382
145383

145384
145385
145386
145387
145388
145389
145390
145391
145392
145393
145394
145395

145396











145397
145398
145399
145400
145401
145402
145403
145404

145405
145406
145407
145408

145409
145410
145411
145412
145413
145414
145415
145416
145417
145418
145419

145420
145421
145422
145423
145424
145425
145426
145706
145707
145708
145709
145710
145711
145712

145713
145714
145715
145716
145717
145718
145719
145720


145721
145722
145723
145724

145725


145726




145727

145728
145729
145730
145731
145732
145733
145734
145735
145736
145737
145738
145739
145740
145741
145742
145743
145744

145745
145746
145747
145748
145749

145750
145751
145752
145753
145754
145755
145756
145757

145758
145759
145760
145761
145762
145763
145764
145765


145766
145767
145768
145769

145770


145771


145772
145773
145774
145775
145776
145777
145778
145779
145780
145781
145782
145783
145784
145785


145786
145787
145788
145789
145790
145791
145792
145793
145794
145795
145796
145797
145798
145799
145800
145801
145802
145803
145804
145805
145806

145807
145808
145809
145810
145811
145812
145813
145814

145815
145816
145817
145818
145819

145820
145821
145822
145823
145824
145825

145826
145827
145828
145829
145830
145831
145832
145833
145834
145835
145836
145837
145838
145839
145840
145841
145842
145843
145844
145845

145846
145847
145848
145849

145850
145851
145852
145853
145854
145855
145856
145857
145858
145859
145860
145861
145862
145863
145864
145865
145866
145867
145868
145869







-
+







-
-
+
+


-
+
-
-
+
-
-
-
-
+
-
+
+
+
+
+
+
+
+
+
+





+

-
+




-


+





-
+







-
-
+
+


-
+
-
-
+
-
-
+
+
+
+
+
+
+
+
+
+
+



-
-
+
+




+














-
+







-
+




-






-
+

+
+
+
+
+
+
+
+
+
+
+







-
+



-
+











+







  }
}

/*
** Implementation of built-in window function percent_rank(). Assumes that
** the window frame has been set to:
**
**   RANGE BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW 
**   GROUPS BETWEEN CURRENT ROW AND UNBOUNDED FOLLOWING
*/
static void percent_rankStepFunc(
  sqlite3_context *pCtx, 
  int nArg,
  sqlite3_value **apArg
){
  struct CallCount *p;
  UNUSED_PARAMETER(nArg); assert( nArg==1 );

  UNUSED_PARAMETER(nArg); assert( nArg==0 );
  UNUSED_PARAMETER(apArg);
  p = (struct CallCount*)sqlite3_aggregate_context(pCtx, sizeof(*p));
  if( p ){
    if( p->nTotal==0 ){
    p->nTotal++;
      p->nTotal = sqlite3_value_int64(apArg[0]);
    }
  }
    p->nStep++;
    if( p->nValue==0 ){
      p->nValue = p->nStep;
    }
}
  }
static void percent_rankInvFunc(
  sqlite3_context *pCtx, 
  int nArg,
  sqlite3_value **apArg
){
  struct CallCount *p;
  UNUSED_PARAMETER(nArg); assert( nArg==0 );
  UNUSED_PARAMETER(apArg);
  p = (struct CallCount*)sqlite3_aggregate_context(pCtx, sizeof(*p));
  p->nStep++;
}
static void percent_rankValueFunc(sqlite3_context *pCtx){
  struct CallCount *p;
  p = (struct CallCount*)sqlite3_aggregate_context(pCtx, sizeof(*p));
  if( p ){
    p->nValue = p->nStep;
    if( p->nTotal>1 ){
      double r = (double)(p->nValue-1) / (double)(p->nTotal-1);
      double r = (double)p->nValue / (double)(p->nTotal-1);
      sqlite3_result_double(pCtx, r);
    }else{
      sqlite3_result_double(pCtx, 0.0);
    }
    p->nValue = 0;
  }
}
#define percent_rankFinalizeFunc percent_rankValueFunc

/*
** Implementation of built-in window function cume_dist(). Assumes that
** the window frame has been set to:
**
**   RANGE BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW 
**   GROUPS BETWEEN 1 FOLLOWING AND UNBOUNDED FOLLOWING
*/
static void cume_distStepFunc(
  sqlite3_context *pCtx, 
  int nArg,
  sqlite3_value **apArg
){
  struct CallCount *p;
  assert( nArg==1 ); UNUSED_PARAMETER(nArg);

  UNUSED_PARAMETER(nArg); assert( nArg==0 );
  UNUSED_PARAMETER(apArg);
  p = (struct CallCount*)sqlite3_aggregate_context(pCtx, sizeof(*p));
  if( p ){
    if( p->nTotal==0 ){
    p->nTotal++;
      p->nTotal = sqlite3_value_int64(apArg[0]);
    }
  }
    p->nStep++;
  }
}
static void cume_distInvFunc(
  sqlite3_context *pCtx, 
  int nArg,
  sqlite3_value **apArg
){
  struct CallCount *p;
  UNUSED_PARAMETER(nArg); assert( nArg==0 );
  UNUSED_PARAMETER(apArg);
  p = (struct CallCount*)sqlite3_aggregate_context(pCtx, sizeof(*p));
  p->nStep++;
}
static void cume_distValueFunc(sqlite3_context *pCtx){
  struct CallCount *p;
  p = (struct CallCount*)sqlite3_aggregate_context(pCtx, sizeof(*p));
  if( p && p->nTotal ){
  p = (struct CallCount*)sqlite3_aggregate_context(pCtx, 0);
  if( p ){
    double r = (double)(p->nStep) / (double)(p->nTotal);
    sqlite3_result_double(pCtx, r);
  }
}
#define cume_distFinalizeFunc cume_distValueFunc

/*
** Context object for ntile() window function.
*/
struct NtileCtx {
  i64 nTotal;                     /* Total rows in partition */
  i64 nParam;                     /* Parameter passed to ntile(N) */
  i64 iRow;                       /* Current row */
};

/*
** Implementation of ntile(). This assumes that the window frame has
** been coerced to:
**
**   ROWS UNBOUNDED PRECEDING AND CURRENT ROW
**   ROWS CURRENT ROW AND UNBOUNDED FOLLOWING
*/
static void ntileStepFunc(
  sqlite3_context *pCtx, 
  int nArg,
  sqlite3_value **apArg
){
  struct NtileCtx *p;
  assert( nArg==2 ); UNUSED_PARAMETER(nArg);
  assert( nArg==1 ); UNUSED_PARAMETER(nArg);
  p = (struct NtileCtx*)sqlite3_aggregate_context(pCtx, sizeof(*p));
  if( p ){
    if( p->nTotal==0 ){
      p->nParam = sqlite3_value_int64(apArg[0]);
      p->nTotal = sqlite3_value_int64(apArg[1]);
      if( p->nParam<=0 ){
        sqlite3_result_error(
            pCtx, "argument of ntile must be a positive integer", -1
        );
      }
    }
    p->iRow++;
    p->nTotal++;
  }
}
static void ntileInvFunc(
  sqlite3_context *pCtx, 
  int nArg,
  sqlite3_value **apArg
){
  struct NtileCtx *p;
  assert( nArg==1 ); UNUSED_PARAMETER(nArg);
  UNUSED_PARAMETER(apArg);
  p = (struct NtileCtx*)sqlite3_aggregate_context(pCtx, sizeof(*p));
  p->iRow++;
}
static void ntileValueFunc(sqlite3_context *pCtx){
  struct NtileCtx *p;
  p = (struct NtileCtx*)sqlite3_aggregate_context(pCtx, sizeof(*p));
  if( p && p->nParam>0 ){
    int nSize = (p->nTotal / p->nParam);
    if( nSize==0 ){
      sqlite3_result_int64(pCtx, p->iRow);
      sqlite3_result_int64(pCtx, p->iRow+1);
    }else{
      i64 nLarge = p->nTotal - p->nParam*nSize;
      i64 iSmall = nLarge*(nSize+1);
      i64 iRow = p->iRow-1;
      i64 iRow = p->iRow;

      assert( (nLarge*(nSize+1) + (p->nParam-nLarge)*nSize)==p->nTotal );

      if( iRow<iSmall ){
        sqlite3_result_int64(pCtx, 1 + iRow/(nSize+1));
      }else{
        sqlite3_result_int64(pCtx, 1 + nLarge + (iRow-iSmall)/nSize);
      }
    }
  }
}
#define ntileFinalizeFunc ntileValueFunc

/*
** Context object for last_value() window function.
*/
struct LastValueCtx {
  sqlite3_value *pVal;
  int nVal;
145462
145463
145464
145465
145466
145467
145468
145469

145470
145471
145472
145473
145474
145475
145476
145905
145906
145907
145908
145909
145910
145911

145912
145913
145914
145915
145916
145917
145918
145919







-
+







      sqlite3_value_free(p->pVal);
      p->pVal = 0;
    }
  }
}
static void last_valueValueFunc(sqlite3_context *pCtx){
  struct LastValueCtx *p;
  p = (struct LastValueCtx*)sqlite3_aggregate_context(pCtx, sizeof(*p));
  p = (struct LastValueCtx*)sqlite3_aggregate_context(pCtx, 0);
  if( p && p->pVal ){
    sqlite3_result_value(pCtx, p->pVal);
  }
}
static void last_valueFinalizeFunc(sqlite3_context *pCtx){
  struct LastValueCtx *p;
  p = (struct LastValueCtx*)sqlite3_aggregate_context(pCtx, sizeof(*p));
145552
145553
145554
145555
145556
145557
145558
145559
145560
145561



145562
145563
145564


145565
145566
145567
145568
145569
145570
145571
145572
145573











145574
145575
145576
145577
145578
145579
145580
145995
145996
145997
145998
145999
146000
146001



146002
146003
146004
146005


146006
146007
146008
146009
146010
146011
146012
146013
146014
146015
146016
146017
146018
146019
146020
146021
146022
146023
146024
146025
146026
146027
146028
146029
146030
146031
146032
146033
146034







-
-
-
+
+
+

-
-
+
+









+
+
+
+
+
+
+
+
+
+
+







** Register those built-in window functions that are not also aggregates.
*/
SQLITE_PRIVATE void sqlite3WindowFunctions(void){
  static FuncDef aWindowFuncs[] = {
    WINDOWFUNCX(row_number, 0, 0),
    WINDOWFUNCX(dense_rank, 0, 0),
    WINDOWFUNCX(rank, 0, 0),
    WINDOWFUNCX(percent_rank, 0, SQLITE_FUNC_WINDOW_SIZE),
    WINDOWFUNCX(cume_dist, 0, SQLITE_FUNC_WINDOW_SIZE),
    WINDOWFUNCX(ntile, 1, SQLITE_FUNC_WINDOW_SIZE),
    WINDOWFUNCALL(percent_rank, 0, 0),
    WINDOWFUNCALL(cume_dist, 0, 0),
    WINDOWFUNCALL(ntile, 1, 0),
    WINDOWFUNCALL(last_value, 1, 0),
    WINDOWFUNCNOOP(nth_value, 2, 0),
    WINDOWFUNCNOOP(first_value, 1, 0),
    WINDOWFUNCALL(nth_value, 2, 0),
    WINDOWFUNCALL(first_value, 1, 0),
    WINDOWFUNCNOOP(lead, 1, 0),
    WINDOWFUNCNOOP(lead, 2, 0),
    WINDOWFUNCNOOP(lead, 3, 0),
    WINDOWFUNCNOOP(lag, 1, 0),
    WINDOWFUNCNOOP(lag, 2, 0),
    WINDOWFUNCNOOP(lag, 3, 0),
  };
  sqlite3InsertBuiltinFuncs(aWindowFuncs, ArraySize(aWindowFuncs));
}

static Window *windowFind(Parse *pParse, Window *pList, const char *zName){
  Window *p;
  for(p=pList; p; p=p->pNextWin){
    if( sqlite3StrICmp(p->zName, zName)==0 ) break;
  }
  if( p==0 ){
    sqlite3ErrorMsg(pParse, "no such window: %s", zName);
  }
  return p;
}

/*
** This function is called immediately after resolving the function name
** for a window function within a SELECT statement. Argument pList is a
** linked list of WINDOW definitions for the current SELECT statement.
** Argument pFunc is the function definition just resolved and pWin
** is the Window object representing the associated OVER clause. This
145591
145592
145593
145594
145595
145596
145597
145598
145599


145600
145601
145602
145603

145604
145605
145606
145607
145608
145609
145610
145611
145612
145613




145614








145615
145616
145617
145618
145619
145620
145621
145622
145623
145624
145625
145626
145627
145628
145629
145630
145631



















145632
145633
145634
145635
145636
145637
145638
145639













145640
145641
145642
145643
145644
145645
145646
146045
146046
146047
146048
146049
146050
146051


146052
146053




146054



146055
146056
146057
146058
146059
146060

146061
146062
146063
146064
146065
146066
146067
146068
146069
146070
146071
146072
146073
146074
146075
146076
146077
146078
146079











146080
146081
146082
146083
146084
146085
146086
146087
146088
146089
146090
146091
146092
146093
146094
146095
146096
146097
146098








146099
146100
146101
146102
146103
146104
146105
146106
146107
146108
146109
146110
146111
146112
146113
146114
146115
146116
146117
146118







-
-
+
+
-
-
-
-
+
-
-
-






-
+
+
+
+

+
+
+
+
+
+
+
+






-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+







*/
SQLITE_PRIVATE void sqlite3WindowUpdate(
  Parse *pParse, 
  Window *pList,                  /* List of named windows for this SELECT */
  Window *pWin,                   /* Window frame to update */
  FuncDef *pFunc                  /* Window function definition */
){
  if( pWin->zName && pWin->eType==0 ){
    Window *p;
  if( pWin->zName && pWin->eFrmType==0 ){
    Window *p = windowFind(pParse, pList, pWin->zName);
    for(p=pList; p; p=p->pNextWin){
      if( sqlite3StrICmp(p->zName, pWin->zName)==0 ) break;
    }
    if( p==0 ){
    if( p==0 ) return;
      sqlite3ErrorMsg(pParse, "no such window: %s", pWin->zName);
      return;
    }
    pWin->pPartition = sqlite3ExprListDup(pParse->db, p->pPartition, 0);
    pWin->pOrderBy = sqlite3ExprListDup(pParse->db, p->pOrderBy, 0);
    pWin->pStart = sqlite3ExprDup(pParse->db, p->pStart, 0);
    pWin->pEnd = sqlite3ExprDup(pParse->db, p->pEnd, 0);
    pWin->eStart = p->eStart;
    pWin->eEnd = p->eEnd;
    pWin->eType = p->eType;
    pWin->eFrmType = p->eFrmType;
    pWin->eExclude = p->eExclude;
  }else{
    sqlite3WindowChain(pParse, pWin, pList);
  }
  if( (pWin->eFrmType==TK_RANGE)
   && (pWin->pStart || pWin->pEnd) 
   && (pWin->pOrderBy==0 || pWin->pOrderBy->nExpr!=1)
  ){
    sqlite3ErrorMsg(pParse, 
      "RANGE with offset PRECEDING/FOLLOWING requires one ORDER BY expression"
    );
  }else
  if( pFunc->funcFlags & SQLITE_FUNC_WINDOW ){
    sqlite3 *db = pParse->db;
    if( pWin->pFilter ){
      sqlite3ErrorMsg(pParse, 
          "FILTER clause may only be used with aggregate window functions"
      );
    }else
    if( pFunc->zName==row_numberName || pFunc->zName==ntileName ){
      sqlite3ExprDelete(db, pWin->pStart);
      sqlite3ExprDelete(db, pWin->pEnd);
      pWin->pStart = pWin->pEnd = 0;
      pWin->eType = TK_ROWS;
      pWin->eStart = TK_UNBOUNDED;
      pWin->eEnd = TK_CURRENT;
    }else

    if( pFunc->zName==dense_rankName || pFunc->zName==rankName
    }else{
      struct WindowUpdate {
        const char *zFunc;
        int eFrmType;
        int eStart;
        int eEnd;
      } aUp[] = {
        { row_numberName,   TK_ROWS,   TK_UNBOUNDED, TK_CURRENT }, 
        { dense_rankName,   TK_RANGE,  TK_UNBOUNDED, TK_CURRENT }, 
        { rankName,         TK_RANGE,  TK_UNBOUNDED, TK_CURRENT }, 
        { percent_rankName, TK_GROUPS, TK_CURRENT,   TK_UNBOUNDED }, 
        { cume_distName,    TK_GROUPS, TK_FOLLOWING, TK_UNBOUNDED }, 
        { ntileName,        TK_ROWS,   TK_CURRENT,   TK_UNBOUNDED }, 
        { leadName,         TK_ROWS,   TK_UNBOUNDED, TK_UNBOUNDED }, 
        { lagName,          TK_ROWS,   TK_UNBOUNDED, TK_CURRENT }, 
      };
      int i;
      for(i=0; i<ArraySize(aUp); i++){
        if( pFunc->zName==aUp[i].zFunc ){
     || pFunc->zName==percent_rankName || pFunc->zName==cume_distName
    ){
      sqlite3ExprDelete(db, pWin->pStart);
      sqlite3ExprDelete(db, pWin->pEnd);
      pWin->pStart = pWin->pEnd = 0;
      pWin->eType = TK_RANGE;
      pWin->eStart = TK_UNBOUNDED;
      pWin->eEnd = TK_CURRENT;
          sqlite3ExprDelete(db, pWin->pStart);
          sqlite3ExprDelete(db, pWin->pEnd);
          pWin->pEnd = pWin->pStart = 0;
          pWin->eFrmType = aUp[i].eFrmType;
          pWin->eStart = aUp[i].eStart;
          pWin->eEnd = aUp[i].eEnd;
          pWin->eExclude = 0;
          if( pWin->eStart==TK_FOLLOWING ){
            pWin->pStart = sqlite3Expr(db, TK_INTEGER, "1");
          }
          break;
        }
      }
    }
  }
  pWin->pFunc = pFunc;
}

/*
** Context object passed through sqlite3WalkExprList() to
145837
145838
145839
145840
145841
145842
145843

145844
145845
145846
145847
145848
145849
145850
146309
146310
146311
146312
146313
146314
146315
146316
146317
146318
146319
146320
146321
146322
146323







+







      }
    }

    /* Assign a cursor number for the ephemeral table used to buffer rows.
    ** The OpenEphemeral instruction is coded later, after it is known how
    ** many columns the table will have.  */
    pMWin->iEphCsr = pParse->nTab++;
    pParse->nTab += 3;

    selectWindowRewriteEList(pParse, pMWin, pSrc, p->pEList, &pSublist);
    selectWindowRewriteEList(pParse, pMWin, pSrc, p->pOrderBy, &pSublist);
    pMWin->nBufferCol = (pSublist ? pSublist->nExpr : 0);

    /* Append the PARTITION BY and ORDER BY expressions to the to the 
    ** sub-select expression list. They are required to figure out where 
145892
145893
145894
145895
145896
145897
145898



145899
145900
145901
145902
145903
145904
145905
145906
145907
145908
145909
145910
145911
145912
145913
145914
145915
145916
145917
145918

145919
145920
145921
145922
145923
145924
145925
146365
146366
146367
146368
146369
146370
146371
146372
146373
146374
146375
146376
146377
146378
146379
146380
146381
146382
146383
146384
146385
146386
146387
146388
146389
146390
146391
146392
146393
146394
146395
146396
146397
146398
146399
146400
146401
146402







+
+
+




















+







      }else{
        pSub->selFlags |= SF_Expanded;
        p->selFlags &= ~SF_Aggregate;
        sqlite3SelectPrep(pParse, pSub, 0);
      }

      sqlite3VdbeAddOp2(v, OP_OpenEphemeral, pMWin->iEphCsr, pSublist->nExpr);
      sqlite3VdbeAddOp2(v, OP_OpenDup, pMWin->iEphCsr+1, pMWin->iEphCsr);
      sqlite3VdbeAddOp2(v, OP_OpenDup, pMWin->iEphCsr+2, pMWin->iEphCsr);
      sqlite3VdbeAddOp2(v, OP_OpenDup, pMWin->iEphCsr+3, pMWin->iEphCsr);
    }else{
      sqlite3SelectDelete(db, pSub);
    }
    if( db->mallocFailed ) rc = SQLITE_NOMEM;
  }

  return rc;
}

/*
** Free the Window object passed as the second argument.
*/
SQLITE_PRIVATE void sqlite3WindowDelete(sqlite3 *db, Window *p){
  if( p ){
    sqlite3ExprDelete(db, p->pFilter);
    sqlite3ExprListDelete(db, p->pPartition);
    sqlite3ExprListDelete(db, p->pOrderBy);
    sqlite3ExprDelete(db, p->pEnd);
    sqlite3ExprDelete(db, p->pStart);
    sqlite3DbFree(db, p->zName);
    sqlite3DbFree(db, p->zBase);
    sqlite3DbFree(db, p);
  }
}

/*
** Free the linked list of Window objects starting at the second argument.
*/
145948
145949
145950
145951
145952
145953
145954
145955

145956
145957
145958
145959


145960
145961

145962
145963
145964

145965
145966
145967
145968
145969
145970
145971
145972
145973


145974
145975
145976

145977
145978
145979
145980
145981
145982
145983
145984
145985
145986
145987
145988
145989
145990
145991
145992
145993
145994
145995
145996
145997
145998

145999
146000
146001
146002
146003
146004

146005
146006





146007
146008
146009
146010
146011
146012
146013
146014
146015































































146016
146017
146018
146019
146020
146021
146022
146425
146426
146427
146428
146429
146430
146431

146432
146433
146434
146435

146436
146437
146438
146439
146440
146441
146442

146443
146444
146445
146446
146447
146448
146449
146450


146451
146452



146453


146454
146455
146456
146457
146458
146459
146460
146461
146462
146463
146464
146465
146466
146467
146468
146469
146470
146471
146472

146473
146474
146475
146476
146477
146478

146479
146480
146481
146482
146483
146484
146485
146486
146487
146488
146489
146490
146491
146492
146493
146494
146495
146496
146497
146498
146499
146500
146501
146502
146503
146504
146505
146506
146507
146508
146509
146510
146511
146512
146513
146514
146515
146516
146517
146518
146519
146520
146521
146522
146523
146524
146525
146526
146527
146528
146529
146530
146531
146532
146533
146534
146535
146536
146537
146538
146539
146540
146541
146542
146543
146544
146545
146546
146547
146548
146549
146550
146551
146552
146553
146554
146555
146556
146557
146558
146559
146560
146561
146562
146563
146564
146565







-
+



-
+
+


+


-
+







-
-
+
+
-
-
-
+
-
-



















-
+





-
+


+
+
+
+
+









+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+







}

/*
** Allocate and return a new Window object describing a Window Definition.
*/
SQLITE_PRIVATE Window *sqlite3WindowAlloc(
  Parse *pParse,    /* Parsing context */
  int eType,        /* Frame type. TK_RANGE or TK_ROWS */
  int eType,        /* Frame type. TK_RANGE, TK_ROWS, TK_GROUPS, or 0 */
  int eStart,       /* Start type: CURRENT, PRECEDING, FOLLOWING, UNBOUNDED */
  Expr *pStart,     /* Start window size if TK_PRECEDING or FOLLOWING */
  int eEnd,         /* End type: CURRENT, FOLLOWING, TK_UNBOUNDED, PRECEDING */
  Expr *pEnd        /* End window size if TK_FOLLOWING or PRECEDING */
  Expr *pEnd,       /* End window size if TK_FOLLOWING or PRECEDING */
  u8 eExclude       /* EXCLUDE clause */
){
  Window *pWin = 0;
  int bImplicitFrame = 0;

  /* Parser assures the following: */
  assert( eType==TK_RANGE || eType==TK_ROWS );
  assert( eType==0 || eType==TK_RANGE || eType==TK_ROWS || eType==TK_GROUPS );
  assert( eStart==TK_CURRENT || eStart==TK_PRECEDING
           || eStart==TK_UNBOUNDED || eStart==TK_FOLLOWING );
  assert( eEnd==TK_CURRENT || eEnd==TK_FOLLOWING
           || eEnd==TK_UNBOUNDED || eEnd==TK_PRECEDING );
  assert( (eStart==TK_PRECEDING || eStart==TK_FOLLOWING)==(pStart!=0) );
  assert( (eEnd==TK_FOLLOWING || eEnd==TK_PRECEDING)==(pEnd!=0) );


  /* If a frame is declared "RANGE" (not "ROWS"), then it may not use
  if( eType==0 ){
    bImplicitFrame = 1;
  ** either "<expr> PRECEDING" or "<expr> FOLLOWING".
  */
  if( eType==TK_RANGE && (pStart!=0 || pEnd!=0) ){
    eType = TK_RANGE;
    sqlite3ErrorMsg(pParse, "RANGE must use only UNBOUNDED or CURRENT ROW");
    goto windowAllocErr;
  }

  /* Additionally, the
  ** starting boundary type may not occur earlier in the following list than
  ** the ending boundary type:
  **
  **   UNBOUNDED PRECEDING
  **   <expr> PRECEDING
  **   CURRENT ROW
  **   <expr> FOLLOWING
  **   UNBOUNDED FOLLOWING
  **
  ** The parser ensures that "UNBOUNDED PRECEDING" cannot be used as an ending
  ** boundary, and than "UNBOUNDED FOLLOWING" cannot be used as a starting
  ** frame boundary.
  */
  if( (eStart==TK_CURRENT && eEnd==TK_PRECEDING)
   || (eStart==TK_FOLLOWING && (eEnd==TK_PRECEDING || eEnd==TK_CURRENT))
  ){
    sqlite3ErrorMsg(pParse, "unsupported frame delimiter for ROWS");
    sqlite3ErrorMsg(pParse, "unsupported frame specification");
    goto windowAllocErr;
  }

  pWin = (Window*)sqlite3DbMallocZero(pParse->db, sizeof(Window));
  if( pWin==0 ) goto windowAllocErr;
  pWin->eType = eType;
  pWin->eFrmType = eType;
  pWin->eStart = eStart;
  pWin->eEnd = eEnd;
  if( eExclude==0 && OptimizationDisabled(pParse->db, SQLITE_WindowFunc) ){
    eExclude = TK_NO;
  }
  pWin->eExclude = eExclude;
  pWin->bImplicitFrame = bImplicitFrame;
  pWin->pEnd = sqlite3WindowOffsetExpr(pParse, pEnd);
  pWin->pStart = sqlite3WindowOffsetExpr(pParse, pStart);
  return pWin;

windowAllocErr:
  sqlite3ExprDelete(pParse->db, pEnd);
  sqlite3ExprDelete(pParse->db, pStart);
  return 0;
}

/*
** Attach PARTITION and ORDER BY clauses pPartition and pOrderBy to window
** pWin. Also, if parameter pBase is not NULL, set pWin->zBase to the
** equivalent nul-terminated string.
*/
SQLITE_PRIVATE Window *sqlite3WindowAssemble(
  Parse *pParse, 
  Window *pWin, 
  ExprList *pPartition, 
  ExprList *pOrderBy, 
  Token *pBase
){
  if( pWin ){
    pWin->pPartition = pPartition;
    pWin->pOrderBy = pOrderBy;
    if( pBase ){
      pWin->zBase = sqlite3DbStrNDup(pParse->db, pBase->z, pBase->n);
    }
  }else{
    sqlite3ExprListDelete(pParse->db, pPartition);
    sqlite3ExprListDelete(pParse->db, pOrderBy);
  }
  return pWin;
}

/*
** Window *pWin has just been created from a WINDOW clause. Tokne pBase
** is the base window. Earlier windows from the same WINDOW clause are
** stored in the linked list starting at pWin->pNextWin. This function
** either updates *pWin according to the base specification, or else
** leaves an error in pParse.
*/
SQLITE_PRIVATE void sqlite3WindowChain(Parse *pParse, Window *pWin, Window *pList){
  if( pWin->zBase ){
    sqlite3 *db = pParse->db;
    Window *pExist = windowFind(pParse, pList, pWin->zBase);
    if( pExist ){
      const char *zErr = 0;
      /* Check for errors */
      if( pWin->pPartition ){
        zErr = "PARTITION clause";
      }else if( pExist->pOrderBy && pWin->pOrderBy ){
        zErr = "ORDER BY clause";
      }else if( pExist->bImplicitFrame==0 ){
        zErr = "frame specification";
      }
      if( zErr ){
        sqlite3ErrorMsg(pParse, 
            "cannot override %s of window: %s", zErr, pWin->zBase
        );
      }else{
        pWin->pPartition = sqlite3ExprListDup(db, pExist->pPartition, 0);
        if( pExist->pOrderBy ){
          assert( pWin->pOrderBy==0 );
          pWin->pOrderBy = sqlite3ExprListDup(db, pExist->pOrderBy, 0);
        }
        sqlite3DbFree(db, pWin->zBase);
        pWin->zBase = 0;
      }
    }
  }
}

/*
** Attach window object pWin to expression p.
*/
SQLITE_PRIVATE void sqlite3WindowAttach(Parse *pParse, Expr *p, Window *pWin){
  if( p ){
    assert( p->op==TK_FUNCTION );
146038
146039
146040
146041
146042
146043
146044
146045

146046
146047

146048
146049
146050
146051
146052
146053
146054
146055
146056
146057
146058
146059
146060
146061
146062
146063
146064
146065
146066





146067
146068
146069















146070
146071
146072
146073
146074
146075
146076
146581
146582
146583
146584
146585
146586
146587

146588
146589
146590
146591
146592
146593
146594
146595
146596
146597
146598
146599
146600
146601
146602
146603
146604
146605
146606
146607



146608
146609
146610
146611
146612
146613


146614
146615
146616
146617
146618
146619
146620
146621
146622
146623
146624
146625
146626
146627
146628
146629
146630
146631
146632
146633
146634
146635







-
+


+
















-
-
-
+
+
+
+
+

-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+







}

/*
** Return 0 if the two window objects are identical, or non-zero otherwise.
** Identical window objects can be processed in a single scan.
*/
SQLITE_PRIVATE int sqlite3WindowCompare(Parse *pParse, Window *p1, Window *p2){
  if( p1->eType!=p2->eType ) return 1;
  if( p1->eFrmType!=p2->eFrmType ) return 1;
  if( p1->eStart!=p2->eStart ) return 1;
  if( p1->eEnd!=p2->eEnd ) return 1;
  if( p1->eExclude!=p2->eExclude ) return 1;
  if( sqlite3ExprCompare(pParse, p1->pStart, p2->pStart, -1) ) return 1;
  if( sqlite3ExprCompare(pParse, p1->pEnd, p2->pEnd, -1) ) return 1;
  if( sqlite3ExprListCompare(p1->pPartition, p2->pPartition, -1) ) return 1;
  if( sqlite3ExprListCompare(p1->pOrderBy, p2->pOrderBy, -1) ) return 1;
  return 0;
}


/*
** This is called by code in select.c before it calls sqlite3WhereBegin()
** to begin iterating through the sub-query results. It is used to allocate
** and initialize registers and cursors used by sqlite3WindowCodeStep().
*/
SQLITE_PRIVATE void sqlite3WindowCodeInit(Parse *pParse, Window *pMWin){
  Window *pWin;
  Vdbe *v = sqlite3GetVdbe(pParse);
  int nPart = (pMWin->pPartition ? pMWin->pPartition->nExpr : 0);
  nPart += (pMWin->pOrderBy ? pMWin->pOrderBy->nExpr : 0);
  if( nPart ){

  /* Allocate registers to use for PARTITION BY values, if any. Initialize
  ** said registers to NULL.  */
  if( pMWin->pPartition ){
    int nExpr = pMWin->pPartition->nExpr;
    pMWin->regPart = pParse->nMem+1;
    pParse->nMem += nPart;
    sqlite3VdbeAddOp3(v, OP_Null, 0, pMWin->regPart, pMWin->regPart+nPart-1);
    pParse->nMem += nExpr;
    sqlite3VdbeAddOp3(v, OP_Null, 0, pMWin->regPart, pMWin->regPart+nExpr-1);
  }

  pMWin->regOne = ++pParse->nMem;
  sqlite3VdbeAddOp2(v, OP_Integer, 1, pMWin->regOne);

  if( pMWin->eExclude ){
    pMWin->regStartRowid = ++pParse->nMem;
    pMWin->regEndRowid = ++pParse->nMem;
    pMWin->csrApp = pParse->nTab++;
    sqlite3VdbeAddOp2(v, OP_Integer, 1, pMWin->regStartRowid);
    sqlite3VdbeAddOp2(v, OP_Integer, 0, pMWin->regEndRowid);
    sqlite3VdbeAddOp2(v, OP_OpenDup, pMWin->csrApp, pMWin->iEphCsr);
    return;
  }

  for(pWin=pMWin; pWin; pWin=pWin->pNextWin){
    FuncDef *p = pWin->pFunc;
    if( (p->funcFlags & SQLITE_FUNC_MINMAX) && pWin->eStart!=TK_UNBOUNDED ){
      /* The inline versions of min() and max() require a single ephemeral
      ** table and 3 registers. The registers are used as follows:
146091
146092
146093
146094
146095
146096
146097
146098
146099
146100
146101
146102
146103
146104
146105
146106
146107
146108
146109
146110






146111
146112
146113
146114
146115
146116
146117
146118
146119

146120
146121
146122
146123



146124
146125

146126
146127
146128

146129










146130
146131
146132
146133







146134
146135
146136


146137


146138
146139
146140
146141
146142
146143
146144
146650
146651
146652
146653
146654
146655
146656

146657
146658
146659
146660
146661
146662

146663
146664
146665
146666
146667
146668
146669
146670
146671
146672
146673
146674
146675
146676
146677
146678
146679
146680
146681

146682
146683
146684
146685

146686
146687
146688
146689

146690
146691
146692

146693
146694
146695
146696
146697
146698
146699
146700
146701
146702
146703
146704




146705
146706
146707
146708
146709
146710
146711
146712


146713
146714
146715
146716
146717
146718
146719
146720
146721
146722
146723
146724







-






-





+
+
+
+
+
+








-
+



-
+
+
+

-
+


-
+

+
+
+
+
+
+
+
+
+
+
-
-
-
-
+
+
+
+
+
+
+

-
-
+
+

+
+







      sqlite3VdbeAddOp2(v, OP_OpenEphemeral, pWin->csrApp, 2);
      sqlite3VdbeAppendP4(v, pKeyInfo, P4_KEYINFO);
      sqlite3VdbeAddOp2(v, OP_Integer, 0, pWin->regApp+1);
    }
    else if( p->zName==nth_valueName || p->zName==first_valueName ){
      /* Allocate two registers at pWin->regApp. These will be used to
      ** store the start and end index of the current frame.  */
      assert( pMWin->iEphCsr );
      pWin->regApp = pParse->nMem+1;
      pWin->csrApp = pParse->nTab++;
      pParse->nMem += 2;
      sqlite3VdbeAddOp2(v, OP_OpenDup, pWin->csrApp, pMWin->iEphCsr);
    }
    else if( p->zName==leadName || p->zName==lagName ){
      assert( pMWin->iEphCsr );
      pWin->csrApp = pParse->nTab++;
      sqlite3VdbeAddOp2(v, OP_OpenDup, pWin->csrApp, pMWin->iEphCsr);
    }
  }
}

#define WINDOW_STARTING_INT  0
#define WINDOW_ENDING_INT    1
#define WINDOW_NTH_VALUE_INT 2
#define WINDOW_STARTING_NUM  3
#define WINDOW_ENDING_NUM    4

/*
** A "PRECEDING <expr>" (eCond==0) or "FOLLOWING <expr>" (eCond==1) or the
** value of the second argument to nth_value() (eCond==2) has just been
** evaluated and the result left in register reg. This function generates VM
** code to check that the value is a non-negative integer and throws an
** exception if it is not.
*/
static void windowCheckIntValue(Parse *pParse, int reg, int eCond){
static void windowCheckValue(Parse *pParse, int reg, int eCond){
  static const char *azErr[] = {
    "frame starting offset must be a non-negative integer",
    "frame ending offset must be a non-negative integer",
    "second argument to nth_value must be a positive integer"
    "second argument to nth_value must be a positive integer",
    "frame starting offset must be a non-negative number",
    "frame ending offset must be a non-negative number",
  };
  static int aOp[] = { OP_Ge, OP_Ge, OP_Gt };
  static int aOp[] = { OP_Ge, OP_Ge, OP_Gt, OP_Ge, OP_Ge };
  Vdbe *v = sqlite3GetVdbe(pParse);
  int regZero = sqlite3GetTempReg(pParse);
  assert( eCond==0 || eCond==1 || eCond==2 );
  assert( eCond>=0 && eCond<ArraySize(azErr) );
  sqlite3VdbeAddOp2(v, OP_Integer, 0, regZero);
  if( eCond>=WINDOW_STARTING_NUM ){
    int regString = sqlite3GetTempReg(pParse);
    sqlite3VdbeAddOp4(v, OP_String8, 0, regString, 0, "", P4_STATIC);
    sqlite3VdbeAddOp3(v, OP_Ge, regString, sqlite3VdbeCurrentAddr(v)+2, reg);
    sqlite3VdbeChangeP5(v, SQLITE_AFF_NUMERIC|SQLITE_JUMPIFNULL);
    VdbeCoverage(v);
    assert( eCond==3 || eCond==4 );
    VdbeCoverageIf(v, eCond==3);
    VdbeCoverageIf(v, eCond==4);
  }else{
  sqlite3VdbeAddOp2(v, OP_MustBeInt, reg, sqlite3VdbeCurrentAddr(v)+2);
  VdbeCoverageIf(v, eCond==0);
  VdbeCoverageIf(v, eCond==1);
  VdbeCoverageIf(v, eCond==2);
    sqlite3VdbeAddOp2(v, OP_MustBeInt, reg, sqlite3VdbeCurrentAddr(v)+2);
    VdbeCoverage(v);
    assert( eCond==0 || eCond==1 || eCond==2 );
    VdbeCoverageIf(v, eCond==0);
    VdbeCoverageIf(v, eCond==1);
    VdbeCoverageIf(v, eCond==2);
  }
  sqlite3VdbeAddOp3(v, aOp[eCond], regZero, sqlite3VdbeCurrentAddr(v)+2, reg);
  VdbeCoverageNeverNullIf(v, eCond==0);
  VdbeCoverageNeverNullIf(v, eCond==1);
  VdbeCoverageNeverNullIf(v, eCond==0); /* NULL case captured by */
  VdbeCoverageNeverNullIf(v, eCond==1); /*   the OP_MustBeInt */
  VdbeCoverageNeverNullIf(v, eCond==2);
  VdbeCoverageNeverNullIf(v, eCond==3); /* NULL case caught by */
  VdbeCoverageNeverNullIf(v, eCond==4); /*   the OP_Ge */
  sqlite3MayAbort(pParse);
  sqlite3VdbeAddOp2(v, OP_Halt, SQLITE_ERROR, OE_Abort);
  sqlite3VdbeAppendP4(v, (void*)azErr[eCond], P4_STATIC);
  sqlite3ReleaseTempReg(pParse, regZero);
}

/*
146170
146171
146172
146173
146174
146175
146176
146177

146178
146179
146180
146181
146182
146183

146184
146185
146186
146187
146188
146189




146190
146191
146192
146193
146194
146195
146196
146197
146198



146199
146200

146201
146202
146203
146204
146205
146206
146207





146208
146209
146210
146211
146212
146213
146214
146215
146216
146217
146218
146219
146220
146221
146222
146223
146224
146225


146226
146227
146228
146229

146230
146231
146232
146233
146234
146235
146236
146237
146238
146239
146240
146241


146242
146243
146244
146245
146246
146247
146248
146249


146250
146251

146252
146253
146254
146255
146256
146257
146258
146259

146260
146261
146262
146263
146264
146265





















146266





























146267
146268


146269
146270
146271
146272



146273
146274
146275
146276

146277
146278


146279
146280
146281
146282
146283
146284
146285
146286
146287
146288

146289

146290
146291


146292
146293
146294
146295
146296

146297
146298
146299
146300
146301
146302
146303
146304
146305
146306
146307




146308
146309
146310



146311
146312
146313
146314
146315
146316
146317
146318
146319
146320
146321













146322

146323
146324
146325
146326










146327
146328
146329
146330
146331
146332
146333
146334
146335
146336
146337
146338
146339


















146340

146341
146342
146343
146344
146345
146346
146347
146348
146349
















146350
146351
146352




146353
146354

146355
146356
146357
146358












146359
146360
146361
146362
146363
146364

146365
146366
146367
146368
146369
146370
146371
146372
146373
146374
146375
146376
146377
146378
146379
146380

146381
146382
146383
146384
146385
146386
146387
146388
146389
146390
146391
146392
146393
146394
146395
146396
146397
146398
146399
146400
146401
146402
146403
146404
146405
146406
146407
146408
146409
146410
146411
146412
146413
146414




































146415
146416
146417
146418
146419
146420
146421
146422
146423
146424
146425
146426
146427
146428
146429
146430
146431
146432
146433
146434
146435
146436
146437
146438
146439
146440
146441
146442
146443





























146444
146445

146446
146447
146448
146449
146450
146451
146452
146453
146454
146455
146456
146457
146458
146459
146460
146461
146462
146463
146464
146465
146466
146467
146468
146469
146470
146471
146472
146473
146474
146475
146476

146477
146478
146479
146480
146481
146482
146483
146484
146485
146486
146487
146488
146489
146490
146491
146492
146493
146494
146495
146496
146497
146498
146499
146500

146501

146502
146503
146504
146505
146506



146507
146508
146509
146510
146511





146512
146513
146514
146515
146516
146517
146518
146519
146520

146521
146522
146523
146524
146525
146526
146527
146528
146529
146530
146531
146532


146533
146534

146535
146536
146537
146538
146539


146540
146541
146542
146543
146544
146545
146546
146547
146548
146549
146550

146551
146552

146553
146554
146555
146556
146557
146558
146559

146560
146561
146562
146563
146564
146565
146566
146567
146568
146569
146570
146571
146572
146573
146574
146575
146576
146577
146578

146579
146580
146581
146582
146583
146584
146585
146586
146587
146588
146589
146590
146591
146592
146593
146594
146595
146596





146597
146598
146599
146600



146601
146602


146603
146604
146605
146606
146607





146608
146609
146610
146611



146612
146613
146614
146615
146616
146617
146618
146619
146620
146621
146622
146623
146624
146625
146626
146627
146628
146629
146630
146631
146632
146633
146634
146635
146636
146637
146638
146639
146640
146641
146642





146643
146644
146645

146646
146647
146648
146649
146650
146651
146652

146653
146654
146655


146656
146657
146658
146659
146660
146661
146662
146663
146664


146665
146666
146667
146668
146669



146670
146671
146672
146673
146674
146675


146676
146677
146678


146679
146680

146681
146682
146683

146684
146685
146686
146687
146688


146689
146690
146691
146692
146693
146694
146695

146696
146697
146698
146699
146700
146701
146702
146703
146704
146705
146706

146707
146708
146709


146710
146711
146712
146713
146714





146715
146716
146717
146718
146719
146720
146721
146722
146723

146724
146725
146726
146727


146728
146729
146730
146731
146732

146733
146734
146735
146736
146737




146738
146739
146740
146741
146742
146743
146744

146745
146746
146747
146748

146749
146750

146751
146752
146753
146754
146755

146756
146757
146758
146759
146760

146761
146762

146763
146764
146765

146766
146767

146768
146769
146770
146771

146772
146773
146774
146775
146776
146777
146778
146779
146780
146781
146782
146783
146784
146785
146786



146787
146788

146789
146790
146791
146792
146793
146794
146795
146796
146797
146798


146799
146800

146801
146802
146803

146804
146805
146806
146807

146808


146809
146810
146811
146812
146813
146814
146815







146816
146817
146818
146819












146820
146821
146822
146823
146824
146825
146826
146827
146828
146829
146830
146831
146832
146833
146834
146835
146836
146837
146838
146839
146840
146841
146842
146843
146844
146845
146846
146847
146848
146849
146850
146851

146852
146853
146854
146855
146856






146857
146858
146859
146860
146861
146862





146863
146864
146865
146866
146867
146868

146869
146870
146871




146872
146873
146874
146875
146876
146877

146878
146879
146880
146881

146882
146883
146884


146885
146886
146887
146888
146889
146890
146891
146892


146893
146894
146895
146896
146897
146898
146899
146900
146901
146902
146903
146904
146905
146906
146907
146908
146909
146910
146911
146912
146913
146914
146915
146916
146917
146918
146919
146920
146921
146922
146923
146924
146925
146926
146927
146928

146929
146930
146931
146932
146933








146934
146935
146936
146937
146938
146939
146940
146941

146942
146943
146944
146945
146946
146947
146948



146949
146950


146951
146952
146953
146954







146955
146956
146957

146958
146959

146960
146961

146962
146963
146964


146965
146966
146967

146968
146969
146970
146971



146972
146973

146974

146975
146976
146977
146978
146979
146980
146981
146982

146983
146984
146985

146986
146987
146988
146989
146990
146991
146992


146993
146994


146995
146996
146997
146998
146999
147000
147001
147002
147003
147004
147005
147006
147007
147008
147009
147010


147011
147012
147013
147014
147015
147016
147017
147018
147019












147020
147021
147022


147023
147024
147025
147026
147027
147028
147029







147030
147031
147032
147033



147034
147035
147036
147037
147038
147039
147040
147041
147042
147043
147044
147045
147046
147047
147048
147049
147050
147051
147052
147053
147054
147055
147056
147057
147058
147059
147060
147061
147062
147063
147064
147065
147066
147067
147068
147069
147070
147071
147072
147073
147074
147075
147076
147077
147078
147079
147080
147081
147082
147083
147084
147085
147086
147087

147088
147089
147090

147091
147092
147093
147094
147095
147096

147097
147098
147099
147100
147101
147102

147103
147104
147105
147106

147107
147108

147109
147110
147111
147112

147113
147114
147115

147116
147117
147118
147119
147120
147121
147122


147123
147124
147125
147126
147127




147128
147129
147130
147131
147132
147133
147134
147135
147136
147137
147138
147139
147140
147141
147142

147143
147144
147145
147146

147147
147148
147149
147150
147151
147152

147153
147154
147155


147156
147157
147158


147159
147160
147161
147162
147163

147164
147165
147166
147167
147168

147169
147170
147171
147172
147173



147174
147175
147176


147177
147178
147179
147180
147181
147182
147183

147184
147185
147186
147187
147188
147189
147190
147191
147192
147193
147194
147195
147196
147197
147198
147199
147200

147201
147202

147203
147204
147205
147206
147207
147208
147209
146750
146751
146752
146753
146754
146755
146756

146757

146758
146759
146760
146761

146762
146763
146764




146765
146766
146767
146768
146769








146770
146771
146772


146773







146774
146775
146776
146777
146778
146779
146780
146781
146782
146783
146784
146785
146786
146787
146788
146789
146790
146791
146792
146793
146794


146795
146796
146797
146798
146799

146800




146801
146802
146803
146804
146805



146806
146807



146808
146809



146810
146811


146812
146813
146814
146815
146816
146817
146818
146819

146820
146821
146822
146823
146824
146825
146826
146827
146828
146829
146830
146831
146832
146833
146834
146835
146836
146837
146838
146839
146840
146841
146842
146843
146844
146845
146846
146847
146848
146849
146850
146851
146852
146853
146854
146855
146856
146857
146858
146859
146860
146861
146862
146863
146864
146865
146866
146867
146868
146869
146870
146871
146872
146873
146874
146875
146876
146877


146878
146879
146880
146881
146882

146883
146884
146885
146886
146887
146888
146889
146890


146891
146892
146893
146894
146895
146896
146897
146898



146899
146900
146901
146902


146903
146904
146905
146906
146907
146908

146909

146910
146911
146912
146913
146914
146915
146916



146917
146918
146919
146920
146921


146922
146923
146924











146925
146926
146927
146928
146929
146930
146931
146932
146933
146934
146935
146936
146937
146938
146939




146940
146941
146942
146943
146944
146945
146946
146947
146948
146949


146950










146951
146952
146953
146954
146955
146956
146957
146958
146959
146960
146961
146962
146963
146964
146965
146966
146967
146968
146969
146970









146971
146972
146973
146974
146975
146976
146977
146978
146979
146980
146981
146982
146983
146984
146985
146986



146987
146988
146989
146990
146991
146992
146993




146994
146995
146996
146997
146998
146999
147000
147001
147002
147003
147004
147005


147006



147007
147008
147009
147010
147011
147012
147013
147014
147015
147016
147017
147018
147019
147020
147021
147022

147023


































147024
147025
147026
147027
147028
147029
147030
147031
147032
147033
147034
147035
147036
147037
147038
147039
147040
147041
147042
147043
147044
147045
147046
147047
147048
147049
147050
147051
147052
147053
147054
147055
147056
147057
147058
147059





























147060
147061
147062
147063
147064
147065
147066
147067
147068
147069
147070
147071
147072
147073
147074
147075
147076
147077
147078
147079
147080
147081
147082
147083
147084
147085
147086
147087
147088


147089































147090







147091
147092
147093
147094
147095
147096
147097
147098
147099
147100
147101
147102
147103
147104
147105
147106
147107
147108

147109





147110
147111
147112
147113




147114
147115
147116
147117
147118
147119
147120
147121
147122
147123
147124
147125


147126












147127
147128


147129





147130
147131











147132


147133







147134



















147135


















147136
147137
147138
147139
147140




147141
147142
147143


147144
147145





147146
147147
147148
147149
147150
147151



147152
147153
147154



























147155



147156
147157
147158
147159
147160



147161
147162

147163




147164



147165
147166









147167
147168





147169
147170
147171






147172
147173



147174
147175


147176



147177

147178



147179
147180







147181











147182



147183
147184





147185
147186
147187
147188
147189









147190




147191
147192





147193





147194
147195
147196
147197







147198




147199


147200





147201





147202


147203



147204


147205




147206















147207
147208
147209


147210










147211
147212


147213
147214


147215
147216



147217

147218
147219
147220






147221
147222
147223
147224
147225
147226
147227




147228
147229
147230
147231
147232
147233
147234
147235
147236
147237
147238
147239
































147240





147241
147242
147243
147244
147245
147246






147247
147248
147249
147250
147251






147252



147253
147254
147255
147256






147257




147258



147259
147260








147261
147262




































147263





147264
147265
147266
147267
147268
147269
147270
147271

147272






147273







147274
147275
147276


147277
147278




147279
147280
147281
147282
147283
147284
147285



147286


147287


147288



147289
147290



147291




147292
147293
147294


147295

147296

147297






147298



147299




147300


147301
147302


147303
147304
















147305
147306









147307
147308
147309
147310
147311
147312
147313
147314
147315
147316
147317
147318


147319
147320
147321







147322
147323
147324
147325
147326
147327
147328




147329
147330
147331




















































147332

147333



147334






147335


147336
147337


147338




147339


147340




147341



147342







147343
147344





147345
147346
147347
147348















147349




147350






147351



147352
147353



147354
147355
147356
147357



147358





147359

147360



147361
147362
147363



147364
147365







147366
147367
147368
147369
147370
147371
147372
147373
147374
147375
147376
147377
147378
147379
147380
147381
147382

147383
147384
147385
147386
147387
147388
147389
147390
147391
147392
147393







-
+
-




-
+


-
-
-
-
+
+
+
+

-
-
-
-
-
-
-
-
+
+
+
-
-
+
-
-
-
-
-
-
-
+
+
+
+
+
















-
-
+
+



-
+
-
-
-
-





-
-
-
+
+
-
-
-


-
-
-
+
+
-
-
+







-
+






+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+

+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
+
+



-
+
+
+




+
-
-
+
+






-
-
-

+

+
-
-
+
+




-
+
-







-
-
-
+
+
+
+

-
-
+
+
+
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+

+
-
-
-
-
+
+
+
+
+
+
+
+
+
+
-
-

-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+

+
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
+
+
+
+


+
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
-
-

-
-
-
+















-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
-
-
-
-
-
-
-

















+
-
+
-
-
-
-
-
+
+
+

-
-
-
-
+
+
+
+
+







-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
+
+
-
-
+
-
-
-
-
-
+
+
-
-
-
-
-
-
-
-
-
-
-
+
-
-
+
-
-
-
-
-
-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
-
-
-
-
+
+
+
-
-
+
+
-
-
-
-
-
+
+
+
+
+

-
-
-
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-

-
-
-
+
+
+
+
+
-
-
-
+

-

-
-
-
-
+
-
-
-
+
+
-
-
-
-
-
-
-
-
-
+
+
-
-
-
-
-
+
+
+
-
-
-
-
-
-
+
+
-
-
-
+
+
-
-
+
-
-
-
+
-

-
-
-
+
+
-
-
-
-
-
-
-
+
-
-
-
-
-
-
-
-
-
-
-
+
-
-
-
+
+
-
-
-
-
-
+
+
+
+
+
-
-
-
-
-
-
-
-
-
+
-
-
-
-
+
+
-
-
-
-
-
+
-
-
-
-
-
+
+
+
+
-
-
-
-
-
-
-
+
-
-
-
-
+
-
-
+
-
-
-
-
-
+
-
-
-
-
-
+
-
-
+
-
-
-
+
-
-
+
-
-
-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
-
-
+
-
-
-
-
-
-
-
-
-
-
+
+
-
-
+

-
-
+

-
-
-
+
-
+
+

-
-
-
-
-
-
+
+
+
+
+
+
+
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
-
-
-
-
-
+
+
+
+
+
+
-
-
-
-
-
-
+
+
+
+
+
-
-
-
-
-
-
+
-
-
-
+
+
+
+
-
-
-
-
-
-
+
-
-
-
-
+
-
-
-
+
+
-
-
-
-
-
-
-
-
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
-
-
-
-
-
+
+
+
+
+
+
+
+
-

-
-
-
-
-
-
+
-
-
-
-
-
-
-
+
+
+
-
-
+
+
-
-
-
-
+
+
+
+
+
+
+
-
-
-
+
-
-
+
-
-
+
-
-
-
+
+
-
-
-
+
-
-
-
-
+
+
+
-
-
+
-
+
-

-
-
-
-
-
-
+
-
-
-
+
-
-
-
-

-
-
+
+
-
-
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
-
-

+
+
-
-
-
-
-
-
-
+
+
+
+
+
+
+
-
-
-
-
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-

-
+
-
-
-
+
-
-
-
-
-
-
+
-
-


-
-
+
-
-
-
-
+
-
-
+
-
-
-
-
+
-
-
-
+
-
-
-
-
-
-
-
+
+
-
-
-
-
-
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
-
-
-
-
+
-
-
-
-
-
-
+
-
-
-
+
+
-
-
-
+
+


-
-
-
+
-
-
-
-
-
+
-

-
-
-
+
+
+
-
-
-
+
+
-
-
-
-
-
-
-
+
















-
+


+







** number of rows in the current partition.
*/
static void windowAggStep(
  Parse *pParse, 
  Window *pMWin,                  /* Linked list of window functions */
  int csr,                        /* Read arguments from this cursor */
  int bInverse,                   /* True to invoke xInverse instead of xStep */
  int reg,                        /* Array of registers */
  int reg                         /* Array of registers */
  int regPartSize                 /* Register containing size of partition */
){
  Vdbe *v = sqlite3GetVdbe(pParse);
  Window *pWin;
  for(pWin=pMWin; pWin; pWin=pWin->pNextWin){
    int flags = pWin->pFunc->funcFlags;
    FuncDef *pFunc = pWin->pFunc;
    int regArg;
    int nArg = windowArgCount(pWin);

    if( csr>=0 ){
      int i;
      for(i=0; i<nArg; i++){
    int i;

    for(i=0; i<nArg; i++){
      if( i!=1 || pFunc->zName!=nth_valueName ){
        sqlite3VdbeAddOp3(v, OP_Column, csr, pWin->iArgCol+i, reg+i);
      }
      regArg = reg;
      if( flags & SQLITE_FUNC_WINDOW_SIZE ){
        if( nArg==0 ){
          regArg = regPartSize;
        }else{
          sqlite3VdbeAddOp2(v, OP_SCopy, regPartSize, reg+nArg);
        }
      }else{
        sqlite3VdbeAddOp3(v, OP_Column, pMWin->iEphCsr, pWin->iArgCol+i, reg+i);
      }
        nArg++;
      }
    }
    }else{
      assert( !(flags & SQLITE_FUNC_WINDOW_SIZE) );
      regArg = reg + pWin->iArgCol;
    }

    if( (pWin->pFunc->funcFlags & SQLITE_FUNC_MINMAX) 
      && pWin->eStart!=TK_UNBOUNDED 
    regArg = reg;

    if( pMWin->regStartRowid==0
     && (pFunc->funcFlags & SQLITE_FUNC_MINMAX) 
     && (pWin->eStart!=TK_UNBOUNDED)
    ){
      int addrIsNull = sqlite3VdbeAddOp1(v, OP_IsNull, regArg);
      VdbeCoverage(v);
      if( bInverse==0 ){
        sqlite3VdbeAddOp2(v, OP_AddImm, pWin->regApp+1, 1);
        sqlite3VdbeAddOp2(v, OP_SCopy, regArg, pWin->regApp);
        sqlite3VdbeAddOp3(v, OP_MakeRecord, pWin->regApp, 2, pWin->regApp+2);
        sqlite3VdbeAddOp2(v, OP_IdxInsert, pWin->csrApp, pWin->regApp+2);
      }else{
        sqlite3VdbeAddOp4Int(v, OP_SeekGE, pWin->csrApp, 0, regArg, 1);
        VdbeCoverageNeverTaken(v);
        sqlite3VdbeAddOp1(v, OP_Delete, pWin->csrApp);
        sqlite3VdbeJumpHere(v, sqlite3VdbeCurrentAddr(v)-2);
      }
      sqlite3VdbeJumpHere(v, addrIsNull);
    }else if( pWin->regApp ){
      assert( pWin->pFunc->zName==nth_valueName
           || pWin->pFunc->zName==first_valueName
      assert( pFunc->zName==nth_valueName
           || pFunc->zName==first_valueName
      );
      assert( bInverse==0 || bInverse==1 );
      sqlite3VdbeAddOp2(v, OP_AddImm, pWin->regApp+1-bInverse, 1);
    }else if( pWin->pFunc->zName==leadName
    }else if( pFunc->xSFunc!=noopStepFunc ){
           || pWin->pFunc->zName==lagName
    ){
      /* no-op */
    }else{
      int addrIf = 0;
      if( pWin->pFilter ){
        int regTmp;
        assert( nArg==0 || nArg==pWin->pOwner->x.pList->nExpr );
        assert( nArg || pWin->pOwner->x.pList==0 );
        if( csr>0 ){
          regTmp = sqlite3GetTempReg(pParse);
          sqlite3VdbeAddOp3(v, OP_Column, csr, pWin->iArgCol+nArg,regTmp);
        regTmp = sqlite3GetTempReg(pParse);
        sqlite3VdbeAddOp3(v, OP_Column, csr, pWin->iArgCol+nArg,regTmp);
        }else{
          regTmp = regArg + nArg;
        }
        addrIf = sqlite3VdbeAddOp3(v, OP_IfNot, regTmp, 0, 1);
        VdbeCoverage(v);
        if( csr>0 ){
          sqlite3ReleaseTempReg(pParse, regTmp);
        }
        sqlite3ReleaseTempReg(pParse, regTmp);
      }
      }
      if( pWin->pFunc->funcFlags & SQLITE_FUNC_NEEDCOLL ){
      if( pFunc->funcFlags & SQLITE_FUNC_NEEDCOLL ){
        CollSeq *pColl;
        assert( nArg>0 );
        pColl = sqlite3ExprNNCollSeq(pParse, pWin->pOwner->x.pList->a[0].pExpr);
        sqlite3VdbeAddOp4(v, OP_CollSeq, 0,0,0, (const char*)pColl, P4_COLLSEQ);
      }
      sqlite3VdbeAddOp3(v, bInverse? OP_AggInverse : OP_AggStep, 
                        bInverse, regArg, pWin->regAccum);
      sqlite3VdbeAppendP4(v, pWin->pFunc, P4_FUNCDEF);
      sqlite3VdbeAppendP4(v, pFunc, P4_FUNCDEF);
      sqlite3VdbeChangeP5(v, (u8)nArg);
      if( addrIf ) sqlite3VdbeJumpHere(v, addrIf);
    }
  }
}

typedef struct WindowCodeArg WindowCodeArg;
typedef struct WindowCsrAndReg WindowCsrAndReg;
struct WindowCsrAndReg {
  int csr;
  int reg;
};

struct WindowCodeArg {
  Parse *pParse;
  Window *pMWin;
  Vdbe *pVdbe;
  int regGosub;
  int addrGosub;
  int regArg;
  int eDelete;

  WindowCsrAndReg start;
  WindowCsrAndReg current;
  WindowCsrAndReg end;
};

/*
** Values that may be passed as the second argument to windowCodeOp().
*/
#define WINDOW_RETURN_ROW 1
#define WINDOW_AGGINVERSE 2
#define WINDOW_AGGSTEP    3

/*
** Generate VM code to read the window frames peer values from cursor csr into
** an array of registers starting at reg.
*/
static void windowReadPeerValues(
  WindowCodeArg *p,
  int csr,
  int reg
){
  Window *pMWin = p->pMWin;
  ExprList *pOrderBy = pMWin->pOrderBy;
  if( pOrderBy ){
    Vdbe *v = sqlite3GetVdbe(p->pParse);
    ExprList *pPart = pMWin->pPartition;
    int iColOff = pMWin->nBufferCol + (pPart ? pPart->nExpr : 0);
    int i;
    for(i=0; i<pOrderBy->nExpr; i++){
      sqlite3VdbeAddOp3(v, OP_Column, csr, iColOff+i, reg+i);
    }
  }
}

/*
** Generate VM code to invoke either xValue() (bFinal==0) or xFinalize()
** (bFinal==1) for each window function in the linked list starting at
** Generate VM code to invoke either xValue() (bFin==0) or xFinalize()
** (bFin==1) for each window function in the linked list starting at
** pMWin. Or, for built-in window-functions that do not use the standard
** API, generate the equivalent VM code.
*/
static void windowAggFinal(Parse *pParse, Window *pMWin, int bFinal){
static void windowAggFinal(WindowCodeArg *p, int bFin){
  Parse *pParse = p->pParse;
  Window *pMWin = p->pMWin;
  Vdbe *v = sqlite3GetVdbe(pParse);
  Window *pWin;

  for(pWin=pMWin; pWin; pWin=pWin->pNextWin){
    if( pMWin->regStartRowid==0
    if( (pWin->pFunc->funcFlags & SQLITE_FUNC_MINMAX) 
     && pWin->eStart!=TK_UNBOUNDED 
     && (pWin->pFunc->funcFlags & SQLITE_FUNC_MINMAX) 
     && (pWin->eStart!=TK_UNBOUNDED)
    ){
      sqlite3VdbeAddOp2(v, OP_Null, 0, pWin->regResult);
      sqlite3VdbeAddOp1(v, OP_Last, pWin->csrApp);
      VdbeCoverage(v);
      sqlite3VdbeAddOp3(v, OP_Column, pWin->csrApp, 0, pWin->regResult);
      sqlite3VdbeJumpHere(v, sqlite3VdbeCurrentAddr(v)-2);
      if( bFinal ){
        sqlite3VdbeAddOp1(v, OP_ResetSorter, pWin->csrApp);
      }
    }else if( pWin->regApp ){
      assert( pMWin->regStartRowid==0 );
    }else{
      int nArg = windowArgCount(pWin);
      if( bFinal ){
        sqlite3VdbeAddOp2(v, OP_AggFinal, pWin->regAccum, windowArgCount(pWin));
      if( bFin ){
        sqlite3VdbeAddOp2(v, OP_AggFinal, pWin->regAccum, nArg);
        sqlite3VdbeAppendP4(v, pWin->pFunc, P4_FUNCDEF);
        sqlite3VdbeAddOp2(v, OP_Copy, pWin->regAccum, pWin->regResult);
        sqlite3VdbeAddOp2(v, OP_Null, 0, pWin->regAccum);
      }else{
        sqlite3VdbeAddOp3(v, OP_AggValue, pWin->regAccum, windowArgCount(pWin),
        sqlite3VdbeAddOp3(v, OP_AggValue,pWin->regAccum,nArg,pWin->regResult);
                             pWin->regResult);
        sqlite3VdbeAppendP4(v, pWin->pFunc, P4_FUNCDEF);
      }
    }
  }
}

/*
** This function generates VM code to invoke the sub-routine at address
** lblFlushPart once for each partition with the entire partition cached in
** the Window.iEphCsr temp table.
** Generate code to calculate the current values of all window functions in the
** p->pMWin list by doing a full scan of the current window frame. Store the
** results in the Window.regResult registers, ready to return the upper
** layer.
*/
static void windowPartitionCache(
  Parse *pParse,
static void windowFullScan(WindowCodeArg *p){
  Window *pWin;
  Parse *pParse = p->pParse;
  Select *p,                      /* The rewritten SELECT statement */
  WhereInfo *pWInfo,              /* WhereInfo to call WhereEnd() on */
  int regFlushPart,               /* Register to use with Gosub lblFlushPart */
  int lblFlushPart,               /* Subroutine to Gosub to */
  int *pRegSize                   /* OUT: Register containing partition size */
){
  Window *pMWin = p->pWin;
  Vdbe *v = sqlite3GetVdbe(pParse);
  int iSubCsr = p->pSrc->a[0].iCursor;
  int nSub = p->pSrc->a[0].pTab->nCol;
  int k;
  Window *pMWin = p->pMWin;
  Vdbe *v = p->pVdbe;

  int regCRowid = 0;              /* Current rowid value */
  int regCPeer = 0;               /* Current peer values */
  int regRowid = 0;               /* AggStep rowid value */
  int regPeer = 0;                /* AggStep peer values */

  int nPeer;
  int lblNext;
  int lblBrk;
  int addrNext;
  int csr = pMWin->csrApp;

  nPeer = (pMWin->pOrderBy ? pMWin->pOrderBy->nExpr : 0);
  int reg = pParse->nMem+1;
  int regRecord = reg+nSub;
  int regRowid = regRecord+1;


  lblNext = sqlite3VdbeMakeLabel(pParse);
  lblBrk = sqlite3VdbeMakeLabel(pParse);

  regCRowid = sqlite3GetTempReg(pParse);
  regRowid = sqlite3GetTempReg(pParse);
  if( nPeer ){
    regCPeer = sqlite3GetTempRange(pParse, nPeer);
    regPeer = sqlite3GetTempRange(pParse, nPeer);
  }
  *pRegSize = regRowid;
  pParse->nMem += nSub + 2;

  /* Load the column values for the row returned by the sub-select
  ** into an array of registers starting at reg. */
  for(k=0; k<nSub; k++){
    sqlite3VdbeAddOp3(v, OP_Column, iSubCsr, k, reg+k);
  }
  sqlite3VdbeAddOp3(v, OP_MakeRecord, reg, nSub, regRecord);

  /* Check if this is the start of a new partition. If so, call the
  ** flush_partition sub-routine.  */
  if( pMWin->pPartition ){
  sqlite3VdbeAddOp2(v, OP_Rowid, pMWin->iEphCsr, regCRowid);
  windowReadPeerValues(p, pMWin->iEphCsr, regCPeer);

  for(pWin=pMWin; pWin; pWin=pWin->pNextWin){
    sqlite3VdbeAddOp2(v, OP_Null, 0, pWin->regAccum);
  }

  sqlite3VdbeAddOp3(v, OP_SeekGE, csr, lblBrk, pMWin->regStartRowid);
  VdbeCoverage(v);
  addrNext = sqlite3VdbeCurrentAddr(v);
  sqlite3VdbeAddOp2(v, OP_Rowid, csr, regRowid);
  sqlite3VdbeAddOp3(v, OP_Gt, pMWin->regEndRowid, lblBrk, regRowid);
  VdbeCoverageNeverNull(v);

  if( pMWin->eExclude==TK_CURRENT ){
    sqlite3VdbeAddOp3(v, OP_Eq, regCRowid, lblNext, regRowid);
    VdbeCoverageNeverNull(v);
  }else if( pMWin->eExclude!=TK_NO ){
    int addr;
    int addrEq = 0;
    ExprList *pPart = pMWin->pPartition;
    int nPart = pPart->nExpr;
    int regNewPart = reg + pMWin->nBufferCol;
    KeyInfo *pKeyInfo = sqlite3KeyInfoFromExprList(pParse, pPart, 0, 0);

    addr = sqlite3VdbeAddOp3(v, OP_Compare, regNewPart, pMWin->regPart,nPart);
    sqlite3VdbeAppendP4(v, (void*)pKeyInfo, P4_KEYINFO);
    sqlite3VdbeAddOp3(v, OP_Jump, addr+2, addr+4, addr+2);
    VdbeCoverageEqNe(v);
    KeyInfo *pKeyInfo = 0;

    if( pMWin->pOrderBy ){
      pKeyInfo = sqlite3KeyInfoFromExprList(pParse, pMWin->pOrderBy, 0, 0);
    }
    if( pMWin->eExclude==TK_TIES ){
      addrEq = sqlite3VdbeAddOp3(v, OP_Eq, regCRowid, 0, regRowid);
      VdbeCoverageNeverNull(v);
    }
    if( pKeyInfo ){
      windowReadPeerValues(p, csr, regPeer);
      sqlite3VdbeAddOp3(v, OP_Compare, regPeer, regCPeer, nPeer);
      sqlite3VdbeAppendP4(v, (void*)pKeyInfo, P4_KEYINFO);
      addr = sqlite3VdbeCurrentAddr(v)+1;
      sqlite3VdbeAddOp3(v, OP_Jump, addr, lblNext, addr);
      VdbeCoverageEqNe(v);
    sqlite3VdbeAddOp3(v, OP_Copy, regNewPart, pMWin->regPart, nPart-1);
    sqlite3VdbeAddOp2(v, OP_Gosub, regFlushPart, lblFlushPart);
    VdbeComment((v, "call flush_partition"));
    }else{
      sqlite3VdbeAddOp2(v, OP_Goto, 0, lblNext);
    }
    if( addrEq ) sqlite3VdbeJumpHere(v, addrEq);
  }

  windowAggStep(pParse, pMWin, csr, 0, p->regArg);
  /* Buffer the current row in the ephemeral table. */
  sqlite3VdbeAddOp2(v, OP_NewRowid, pMWin->iEphCsr, regRowid);
  sqlite3VdbeAddOp3(v, OP_Insert, pMWin->iEphCsr, regRecord, regRowid);


  sqlite3VdbeResolveLabel(v, lblNext);
  sqlite3VdbeAddOp2(v, OP_Next, csr, addrNext);
  VdbeCoverage(v);
  sqlite3VdbeJumpHere(v, addrNext-1);
  sqlite3VdbeJumpHere(v, addrNext+1);
  sqlite3ReleaseTempReg(pParse, regRowid);
  sqlite3ReleaseTempReg(pParse, regCRowid);
  if( nPeer ){
    sqlite3ReleaseTempRange(pParse, regPeer, nPeer);
    sqlite3ReleaseTempRange(pParse, regCPeer, nPeer);
  }
  /* End of the input loop */
  sqlite3WhereEnd(pWInfo);

  /* Invoke "flush_partition" to deal with the final (or only) partition */
  sqlite3VdbeAddOp2(v, OP_Gosub, regFlushPart, lblFlushPart);
  VdbeComment((v, "call flush_partition"));
  windowAggFinal(p, 1);
}

/*
** Invoke the sub-routine at regGosub (generated by code in select.c) to
** return the current row of Window.iEphCsr. If all window functions are
** aggregate window functions that use the standard API, a single
** OP_Gosub instruction is all that this routine generates. Extra VM code
** for per-row processing is only generated for the following built-in window
** functions:
**
**   nth_value()
**   first_value()
**   lag()
**   lead()
*/
static void windowReturnOneRow(
static void windowReturnOneRow(WindowCodeArg *p){
  Parse *pParse,
  Window *pMWin,
  int regGosub,
  int addrGosub
){
  Vdbe *v = sqlite3GetVdbe(pParse);
  Window *pWin;
  for(pWin=pMWin; pWin; pWin=pWin->pNextWin){
    FuncDef *pFunc = pWin->pFunc;
    if( pFunc->zName==nth_valueName
     || pFunc->zName==first_valueName
    ){
      int csr = pWin->csrApp;
      int lbl = sqlite3VdbeMakeLabel(pParse);
      int tmpReg = sqlite3GetTempReg(pParse);
      sqlite3VdbeAddOp2(v, OP_Null, 0, pWin->regResult);

      if( pFunc->zName==nth_valueName ){
        sqlite3VdbeAddOp3(v, OP_Column, pMWin->iEphCsr, pWin->iArgCol+1,tmpReg);
        windowCheckIntValue(pParse, tmpReg, 2);
      }else{
        sqlite3VdbeAddOp2(v, OP_Integer, 1, tmpReg);
      }
      sqlite3VdbeAddOp3(v, OP_Add, tmpReg, pWin->regApp, tmpReg);
      sqlite3VdbeAddOp3(v, OP_Gt, pWin->regApp+1, lbl, tmpReg);
      VdbeCoverageNeverNull(v);
      sqlite3VdbeAddOp3(v, OP_SeekRowid, csr, 0, tmpReg);
      VdbeCoverageNeverTaken(v);
      sqlite3VdbeAddOp3(v, OP_Column, csr, pWin->iArgCol, pWin->regResult);
      sqlite3VdbeResolveLabel(v, lbl);
      sqlite3ReleaseTempReg(pParse, tmpReg);
    }
    else if( pFunc->zName==leadName || pFunc->zName==lagName ){
      int nArg = pWin->pOwner->x.pList->nExpr;
  Window *pMWin = p->pMWin;
  Vdbe *v = p->pVdbe;

  if( pMWin->regStartRowid ){
    windowFullScan(p);
  }else{
    Parse *pParse = p->pParse;
    Window *pWin;

    for(pWin=pMWin; pWin; pWin=pWin->pNextWin){
      FuncDef *pFunc = pWin->pFunc;
      if( pFunc->zName==nth_valueName
       || pFunc->zName==first_valueName
      ){
        int csr = pWin->csrApp;
        int lbl = sqlite3VdbeMakeLabel(pParse);
        int tmpReg = sqlite3GetTempReg(pParse);
        sqlite3VdbeAddOp2(v, OP_Null, 0, pWin->regResult);
  
        if( pFunc->zName==nth_valueName ){
          sqlite3VdbeAddOp3(v, OP_Column,pMWin->iEphCsr,pWin->iArgCol+1,tmpReg);
          windowCheckValue(pParse, tmpReg, 2);
        }else{
          sqlite3VdbeAddOp2(v, OP_Integer, 1, tmpReg);
        }
        sqlite3VdbeAddOp3(v, OP_Add, tmpReg, pWin->regApp, tmpReg);
        sqlite3VdbeAddOp3(v, OP_Gt, pWin->regApp+1, lbl, tmpReg);
        VdbeCoverageNeverNull(v);
        sqlite3VdbeAddOp3(v, OP_SeekRowid, csr, 0, tmpReg);
        VdbeCoverageNeverTaken(v);
        sqlite3VdbeAddOp3(v, OP_Column, csr, pWin->iArgCol, pWin->regResult);
        sqlite3VdbeResolveLabel(v, lbl);
        sqlite3ReleaseTempReg(pParse, tmpReg);
      }
      else if( pFunc->zName==leadName || pFunc->zName==lagName ){
        int nArg = pWin->pOwner->x.pList->nExpr;
      int iEph = pMWin->iEphCsr;
      int csr = pWin->csrApp;
      int lbl = sqlite3VdbeMakeLabel(pParse);
      int tmpReg = sqlite3GetTempReg(pParse);

      if( nArg<3 ){
        sqlite3VdbeAddOp2(v, OP_Null, 0, pWin->regResult);
      }else{
        sqlite3VdbeAddOp3(v, OP_Column, iEph, pWin->iArgCol+2, pWin->regResult);
      }
      sqlite3VdbeAddOp2(v, OP_Rowid, iEph, tmpReg);
      if( nArg<2 ){
        int val = (pFunc->zName==leadName ? 1 : -1);
        sqlite3VdbeAddOp2(v, OP_AddImm, tmpReg, val);
      }else{
        int op = (pFunc->zName==leadName ? OP_Add : OP_Subtract);
        int tmpReg2 = sqlite3GetTempReg(pParse);
        sqlite3VdbeAddOp3(v, OP_Column, iEph, pWin->iArgCol+1, tmpReg2);
        sqlite3VdbeAddOp3(v, op, tmpReg2, tmpReg, tmpReg);
        sqlite3ReleaseTempReg(pParse, tmpReg2);
      }

      sqlite3VdbeAddOp3(v, OP_SeekRowid, csr, lbl, tmpReg);
      VdbeCoverage(v);
      sqlite3VdbeAddOp3(v, OP_Column, csr, pWin->iArgCol, pWin->regResult);
      sqlite3VdbeResolveLabel(v, lbl);
      sqlite3ReleaseTempReg(pParse, tmpReg);
    }
  }
        int csr = pWin->csrApp;
        int lbl = sqlite3VdbeMakeLabel(pParse);
        int tmpReg = sqlite3GetTempReg(pParse);
        int iEph = pMWin->iEphCsr;
  
        if( nArg<3 ){
          sqlite3VdbeAddOp2(v, OP_Null, 0, pWin->regResult);
        }else{
          sqlite3VdbeAddOp3(v, OP_Column, iEph,pWin->iArgCol+2,pWin->regResult);
        }
        sqlite3VdbeAddOp2(v, OP_Rowid, iEph, tmpReg);
        if( nArg<2 ){
          int val = (pFunc->zName==leadName ? 1 : -1);
          sqlite3VdbeAddOp2(v, OP_AddImm, tmpReg, val);
        }else{
          int op = (pFunc->zName==leadName ? OP_Add : OP_Subtract);
          int tmpReg2 = sqlite3GetTempReg(pParse);
          sqlite3VdbeAddOp3(v, OP_Column, iEph, pWin->iArgCol+1, tmpReg2);
          sqlite3VdbeAddOp3(v, op, tmpReg2, tmpReg, tmpReg);
          sqlite3ReleaseTempReg(pParse, tmpReg2);
        }
  
        sqlite3VdbeAddOp3(v, OP_SeekRowid, csr, lbl, tmpReg);
        VdbeCoverage(v);
        sqlite3VdbeAddOp3(v, OP_Column, csr, pWin->iArgCol, pWin->regResult);
        sqlite3VdbeResolveLabel(v, lbl);
        sqlite3ReleaseTempReg(pParse, tmpReg);
      }
    }
  sqlite3VdbeAddOp2(v, OP_Gosub, regGosub, addrGosub);
}
  }

/*
** Invoke the code generated by windowReturnOneRow() and, optionally, the
** xInverse() function for each window function, for one or more rows
** from the Window.iEphCsr temp table. This routine generates VM code
** similar to:
**
**   while( regCtr>0 ){
**     regCtr--;
**     windowReturnOneRow()
**     if( bInverse ){
**       AggInverse
**     }
**     Next (Window.iEphCsr)
**   }
*/
static void windowReturnRows(
  Parse *pParse,
  Window *pMWin,                  /* List of window functions */
  int regCtr,                     /* Register containing number of rows */
  int regGosub,                   /* Register for Gosub addrGosub */
  int addrGosub,                  /* Address of sub-routine for ReturnOneRow */
  int regInvArg,                  /* Array of registers for xInverse args */
  int regInvSize                  /* Register containing size of partition */
){
  int addr;
  Vdbe *v = sqlite3GetVdbe(pParse);
  windowAggFinal(pParse, pMWin, 0);
  addr = sqlite3VdbeAddOp3(v, OP_IfPos, regCtr, sqlite3VdbeCurrentAddr(v)+2 ,1);
  VdbeCoverage(v);
  sqlite3VdbeAddOp2(v, OP_Goto, 0, 0);
  sqlite3VdbeAddOp2(v, OP_Gosub, p->regGosub, p->addrGosub);
  windowReturnOneRow(pParse, pMWin, regGosub, addrGosub);
  if( regInvArg ){
    windowAggStep(pParse, pMWin, pMWin->iEphCsr, 1, regInvArg, regInvSize);
  }
  sqlite3VdbeAddOp2(v, OP_Next, pMWin->iEphCsr, addr);
  VdbeCoverage(v);
  sqlite3VdbeJumpHere(v, addr+1);   /* The OP_Goto */
}

/*
** Generate code to set the accumulator register for each window function
** in the linked list passed as the second argument to NULL. And perform
** any equivalent initialization required by any built-in window functions
** in the list.
*/
static int windowInitAccum(Parse *pParse, Window *pMWin){
  Vdbe *v = sqlite3GetVdbe(pParse);
  int regArg;
  int nArg = 0;
  Window *pWin;
  for(pWin=pMWin; pWin; pWin=pWin->pNextWin){
    FuncDef *pFunc = pWin->pFunc;
    sqlite3VdbeAddOp2(v, OP_Null, 0, pWin->regAccum);
    nArg = MAX(nArg, windowArgCount(pWin));
    if( pMWin->regStartRowid==0 ){
    if( pFunc->zName==nth_valueName
      if( pFunc->zName==nth_valueName || pFunc->zName==first_valueName ){
     || pFunc->zName==first_valueName
    ){
      sqlite3VdbeAddOp2(v, OP_Integer, 0, pWin->regApp);
      sqlite3VdbeAddOp2(v, OP_Integer, 0, pWin->regApp+1);
    }
        sqlite3VdbeAddOp2(v, OP_Integer, 0, pWin->regApp);
        sqlite3VdbeAddOp2(v, OP_Integer, 0, pWin->regApp+1);
      }

    if( (pFunc->funcFlags & SQLITE_FUNC_MINMAX) && pWin->csrApp ){
      assert( pWin->eStart!=TK_UNBOUNDED );
      sqlite3VdbeAddOp1(v, OP_ResetSorter, pWin->csrApp);
      sqlite3VdbeAddOp2(v, OP_Integer, 0, pWin->regApp+1);
      if( (pFunc->funcFlags & SQLITE_FUNC_MINMAX) && pWin->csrApp ){
        assert( pWin->eStart!=TK_UNBOUNDED );
        sqlite3VdbeAddOp1(v, OP_ResetSorter, pWin->csrApp);
        sqlite3VdbeAddOp2(v, OP_Integer, 0, pWin->regApp+1);
      }
    }
  }
  regArg = pParse->nMem+1;
  pParse->nMem += nArg;
  return regArg;
}


/*
/* 
** This function does the work of sqlite3WindowCodeStep() for all "ROWS"
** window frame types except for "BETWEEN UNBOUNDED PRECEDING AND CURRENT
** ROW". Pseudo-code for each follows.
**
** ROWS BETWEEN <expr1> PRECEDING AND <expr2> FOLLOWING
**
**     ...
**       if( new partition ){
**         Gosub flush_partition
**       }
**       Insert (record in eph-table)
**     sqlite3WhereEnd()
** Return true if the current frame should be cached in the ephemeral table,
** even if there are no xInverse() calls required.
**     Gosub flush_partition
**  
*/
**   flush_partition:
**     Once {
**       OpenDup (iEphCsr -> csrStart)
**       OpenDup (iEphCsr -> csrEnd)
**     }
static int windowCacheFrame(Window *pMWin){
  Window *pWin;
**     regStart = <expr1>                // PRECEDING expression
**     regEnd = <expr2>                  // FOLLOWING expression
**     if( regStart<0 || regEnd<0 ){ error! }
**     Rewind (csr,csrStart,csrEnd)      // if EOF goto flush_partition_done
**       Next(csrEnd)                    // if EOF skip Aggstep
**       Aggstep (csrEnd)
**       if( (regEnd--)<=0 ){
**         AggFinal (xValue)
**         Gosub addrGosub
**         Next(csr)                // if EOF goto flush_partition_done
**         if( (regStart--)<=0 ){
  if( pMWin->regStartRowid ) return 1;
**           AggInverse (csrStart)
**           Next(csrStart)
  for(pWin=pMWin; pWin; pWin=pWin->pNextWin){
**         }
**       }
**   flush_partition_done:
**     ResetSorter (csr)
**     Return
**
** ROWS BETWEEN <expr> PRECEDING    AND CURRENT ROW
    FuncDef *pFunc = pWin->pFunc;
** ROWS BETWEEN CURRENT ROW         AND <expr> FOLLOWING
** ROWS BETWEEN UNBOUNDED PRECEDING AND <expr> FOLLOWING
**
**   These are similar to the above. For "CURRENT ROW", intialize the
**   register to 0. For "UNBOUNDED PRECEDING" to infinity.
**
** ROWS BETWEEN <expr> PRECEDING    AND UNBOUNDED FOLLOWING
** ROWS BETWEEN CURRENT ROW         AND UNBOUNDED FOLLOWING
**
**     Rewind (csr,csrStart,csrEnd)    // if EOF goto flush_partition_done
**     while( 1 ){
**       Next(csrEnd)                  // Exit while(1) at EOF
**       Aggstep (csrEnd)
**     }
**     while( 1 ){
**       AggFinal (xValue)
**       Gosub addrGosub
**       Next(csr)                     // if EOF goto flush_partition_done
**       if( (regStart--)<=0 ){
    if( (pFunc->zName==nth_valueName)
**         AggInverse (csrStart)
**         Next(csrStart)
**       }
**     }
**
**   For the "CURRENT ROW AND UNBOUNDED FOLLOWING" case, the final if() 
**   condition is always true (as if regStart were initialized to 0).
**
** RANGE BETWEEN CURRENT ROW AND UNBOUNDED FOLLOWING
** 
**   This is the only RANGE case handled by this routine. It modifies the
**   second while( 1 ) loop in "ROWS BETWEEN CURRENT ... UNBOUNDED..." to
**   be:
**
**     while( 1 ){
**       AggFinal (xValue)
**       while( 1 ){
**         regPeer++
     || (pFunc->zName==first_valueName)
     || (pFunc->zName==leadName)
     || (pFunc->zName==lagName)
    ){
      return 1;
**         Gosub addrGosub
**         Next(csr)                     // if EOF goto flush_partition_done
**         if( new peer ) break;
**       }
    }
  }
  return 0;
**       while( (regPeer--)>0 ){
**         AggInverse (csrStart)
}

**         Next(csrStart)
**       }
**     }
**
** ROWS BETWEEN <expr> FOLLOWING    AND <expr> FOLLOWING
/*
** regOld and regNew are each the first register in an array of size
** pOrderBy->nExpr. This function generates code to compare the two
** arrays of registers using the collation sequences and other comparison
** parameters specified by pOrderBy. 
**
**   regEnd = regEnd - regStart
**   Rewind (csr,csrStart,csrEnd)   // if EOF goto flush_partition_done
**     Aggstep (csrEnd)
** If the two arrays are not equal, the contents of regNew is copied to 
** regOld and control falls through. Otherwise, if the contents of the arrays
** are equal, an OP_Goto is executed. The address of the OP_Goto is returned.
**     Next(csrEnd)                 // if EOF fall-through
**     if( (regEnd--)<=0 ){
**       if( (regStart--)<=0 ){
**         AggFinal (xValue)
**         Gosub addrGosub
**         Next(csr)              // if EOF goto flush_partition_done
**       }
**       AggInverse (csrStart)
**       Next (csrStart)
**     }
**
** ROWS BETWEEN <expr> PRECEDING    AND <expr> PRECEDING
**
**   Replace the bit after "Rewind" in the above with:
**
**     if( (regEnd--)<=0 ){
**       AggStep (csrEnd)
**       Next (csrEnd)
**     }
**     AggFinal (xValue)
**     Gosub addrGosub
**     Next(csr)                  // if EOF goto flush_partition_done
**     if( (regStart--)<=0 ){
**       AggInverse (csr2)
**       Next (csr2)
**     }
**
*/
static void windowCodeRowExprStep(
  Parse *pParse, 
  Select *p,
static void windowIfNewPeer(
  Parse *pParse,
  ExprList *pOrderBy,
  int regNew,                     /* First in array of new values */
  int regOld,                     /* First in array of old values */
  WhereInfo *pWInfo,
  int regGosub, 
  int addrGosub
  int addr                        /* Jump here */
){
  Window *pMWin = p->pWin;
  Vdbe *v = sqlite3GetVdbe(pParse);
  int regFlushPart;               /* Register for "Gosub flush_partition" */
  int lblFlushPart;               /* Label for "Gosub flush_partition" */
  int lblFlushDone;               /* Label for "Gosub flush_partition_done" */

  if( pOrderBy ){
  int regArg;
  int addr;
  int csrStart = pParse->nTab++;
    int nVal = pOrderBy->nExpr;
    KeyInfo *pKeyInfo = sqlite3KeyInfoFromExprList(pParse, pOrderBy, 0, 0);
  int csrEnd = pParse->nTab++;
  int regStart;                    /* Value of <expr> PRECEDING */
  int regEnd;                      /* Value of <expr> FOLLOWING */
  int addrGoto;
  int addrTop;
  int addrIfPos1 = 0;
  int addrIfPos2 = 0;
  int regSize = 0;

    sqlite3VdbeAddOp3(v, OP_Compare, regOld, regNew, nVal);
    sqlite3VdbeAppendP4(v, (void*)pKeyInfo, P4_KEYINFO);
  assert( pMWin->eStart==TK_PRECEDING 
       || pMWin->eStart==TK_CURRENT 
       || pMWin->eStart==TK_FOLLOWING 
       || pMWin->eStart==TK_UNBOUNDED 
  );
    sqlite3VdbeAddOp3(v, OP_Jump, 
      sqlite3VdbeCurrentAddr(v)+1, addr, sqlite3VdbeCurrentAddr(v)+1
    );
  assert( pMWin->eEnd==TK_FOLLOWING 
       || pMWin->eEnd==TK_CURRENT 
       || pMWin->eEnd==TK_UNBOUNDED 
       || pMWin->eEnd==TK_PRECEDING 
  );

    VdbeCoverageEqNe(v);
    sqlite3VdbeAddOp3(v, OP_Copy, regNew, regOld, nVal-1);
  /* Allocate register and label for the "flush_partition" sub-routine. */
  regFlushPart = ++pParse->nMem;
  lblFlushPart = sqlite3VdbeMakeLabel(pParse);
  }else{
    sqlite3VdbeAddOp2(v, OP_Goto, 0, addr);
  lblFlushDone = sqlite3VdbeMakeLabel(pParse);

  }
  regStart = ++pParse->nMem;
  regEnd = ++pParse->nMem;

}
  windowPartitionCache(pParse, p, pWInfo, regFlushPart, lblFlushPart, &regSize);

  addrGoto = sqlite3VdbeAddOp0(v, OP_Goto);

  /* Start of "flush_partition" */
/*
** This function is called as part of generating VM programs for RANGE
  sqlite3VdbeResolveLabel(v, lblFlushPart);
  sqlite3VdbeAddOp2(v, OP_Once, 0, sqlite3VdbeCurrentAddr(v)+3);
  VdbeCoverage(v);
  VdbeComment((v, "Flush_partition subroutine"));
  sqlite3VdbeAddOp2(v, OP_OpenDup, csrStart, pMWin->iEphCsr);
  sqlite3VdbeAddOp2(v, OP_OpenDup, csrEnd, pMWin->iEphCsr);

** offset PRECEDING/FOLLOWING frame boundaries. Assuming "ASC" order for
  /* If either regStart or regEnd are not non-negative integers, throw 
  ** an exception.  */
  if( pMWin->pStart ){
    sqlite3ExprCode(pParse, pMWin->pStart, regStart);
    windowCheckIntValue(pParse, regStart, 0);
  }
  if( pMWin->pEnd ){
    sqlite3ExprCode(pParse, pMWin->pEnd, regEnd);
    windowCheckIntValue(pParse, regEnd, 1);
  }

** the ORDER BY term in the window, it generates code equivalent to:
  /* If this is "ROWS <expr1> FOLLOWING AND ROWS <expr2> FOLLOWING", do:
  **
  **   if( regEnd<regStart ){
**
**   if( csr1.peerVal + regVal >= csr2.peerVal ) goto lbl;
  **     // The frame always consists of 0 rows
  **     regStart = regSize;
  **   }
  **   regEnd = regEnd - regStart;
  */
**
** A special type of arithmetic is used such that if csr.peerVal is not
** a numeric type (real or integer), then the result of the addition is
** a copy of csr1.peerVal.
*/
  if( pMWin->pEnd && pMWin->eStart==TK_FOLLOWING ){
    assert( pMWin->pStart!=0 );
    assert( pMWin->eEnd==TK_FOLLOWING );
    sqlite3VdbeAddOp3(v, OP_Ge, regStart, sqlite3VdbeCurrentAddr(v)+2, regEnd);
    VdbeCoverageNeverNull(v);
    sqlite3VdbeAddOp2(v, OP_Copy, regSize, regStart);
    sqlite3VdbeAddOp3(v, OP_Subtract, regStart, regEnd, regEnd);
  }

static void windowCodeRangeTest(
  if( pMWin->pStart && pMWin->eEnd==TK_PRECEDING ){
    assert( pMWin->pEnd!=0 );
    assert( pMWin->eStart==TK_PRECEDING );
    sqlite3VdbeAddOp3(v, OP_Le, regStart, sqlite3VdbeCurrentAddr(v)+3, regEnd);
  WindowCodeArg *p, 
  int op,                          /* OP_Ge or OP_Gt */
    VdbeCoverageNeverNull(v);
    sqlite3VdbeAddOp2(v, OP_Copy, regSize, regStart);
    sqlite3VdbeAddOp2(v, OP_Copy, regSize, regEnd);
  }

  int csr1, 
  /* Initialize the accumulator register for each window function to NULL */
  regArg = windowInitAccum(pParse, pMWin);

  sqlite3VdbeAddOp2(v, OP_Rewind, pMWin->iEphCsr, lblFlushDone);
  VdbeCoverage(v);
  int regVal, 
  int csr2,
  int lbl
){
  sqlite3VdbeAddOp2(v, OP_Rewind, csrStart, lblFlushDone);
  VdbeCoverageNeverTaken(v);
  sqlite3VdbeChangeP5(v, 1);
  sqlite3VdbeAddOp2(v, OP_Rewind, csrEnd, lblFlushDone);
  VdbeCoverageNeverTaken(v);
  sqlite3VdbeChangeP5(v, 1);

  Parse *pParse = p->pParse;
  /* Invoke AggStep function for each window function using the row that
  ** csrEnd currently points to. Or, if csrEnd is already at EOF,
  ** do nothing.  */
  addrTop = sqlite3VdbeCurrentAddr(v);
  Vdbe *v = sqlite3GetVdbe(pParse);
  if( pMWin->eEnd==TK_PRECEDING ){
    addrIfPos1 = sqlite3VdbeAddOp3(v, OP_IfPos, regEnd, 0 , 1);
  int reg1 = sqlite3GetTempReg(pParse);
    VdbeCoverage(v);
  }
  sqlite3VdbeAddOp2(v, OP_Next, csrEnd, sqlite3VdbeCurrentAddr(v)+2);
  VdbeCoverage(v);
  addr = sqlite3VdbeAddOp0(v, OP_Goto);
  int reg2 = sqlite3GetTempReg(pParse);
  windowAggStep(pParse, pMWin, csrEnd, 0, regArg, regSize);
  if( pMWin->eEnd==TK_UNBOUNDED ){
    sqlite3VdbeAddOp2(v, OP_Goto, 0, addrTop);
    sqlite3VdbeJumpHere(v, addr);
    addrTop = sqlite3VdbeCurrentAddr(v);
  int arith = OP_Add;
  }else{
    sqlite3VdbeJumpHere(v, addr);
  int addrGe;
    if( pMWin->eEnd==TK_PRECEDING ){
      sqlite3VdbeJumpHere(v, addrIfPos1);
    }

  }

  int regString = ++pParse->nMem;
  if( pMWin->eEnd==TK_FOLLOWING ){
    addrIfPos1 = sqlite3VdbeAddOp3(v, OP_IfPos, regEnd, 0 , 1);
    VdbeCoverage(v);
  }

  if( pMWin->eStart==TK_FOLLOWING ){
    addrIfPos2 = sqlite3VdbeAddOp3(v, OP_IfPos, regStart, 0 , 1);
    VdbeCoverage(v);
  }
  windowAggFinal(pParse, pMWin, 0);
  windowReturnOneRow(pParse, pMWin, regGosub, addrGosub);
  sqlite3VdbeAddOp2(v, OP_Next, pMWin->iEphCsr, sqlite3VdbeCurrentAddr(v)+2);
  VdbeCoverage(v);
  sqlite3VdbeAddOp2(v, OP_Goto, 0, lblFlushDone);
  if( pMWin->eStart==TK_FOLLOWING ){
    sqlite3VdbeJumpHere(v, addrIfPos2);
  }

  if( pMWin->eStart==TK_CURRENT 
   || pMWin->eStart==TK_PRECEDING 
  assert( op==OP_Ge || op==OP_Gt || op==OP_Le );
  assert( p->pMWin->pOrderBy && p->pMWin->pOrderBy->nExpr==1 );
  if( p->pMWin->pOrderBy->a[0].sortOrder ){
   || pMWin->eStart==TK_FOLLOWING 
  ){
    switch( op ){
    int lblSkipInverse = sqlite3VdbeMakeLabel(pParse);;
    if( pMWin->eStart==TK_PRECEDING ){
      sqlite3VdbeAddOp3(v, OP_IfPos, regStart, lblSkipInverse, 1);
      VdbeCoverage(v);
    }
    if( pMWin->eStart==TK_FOLLOWING ){
      sqlite3VdbeAddOp2(v, OP_Next, csrStart, sqlite3VdbeCurrentAddr(v)+2);
      VdbeCoverage(v);
      sqlite3VdbeAddOp2(v, OP_Goto, 0, lblSkipInverse);
    }else{
      case OP_Ge: op = OP_Le; break;
      case OP_Gt: op = OP_Lt; break;
      sqlite3VdbeAddOp2(v, OP_Next, csrStart, sqlite3VdbeCurrentAddr(v)+1);
      VdbeCoverageAlwaysTaken(v);
      default: assert( op==OP_Le ); op = OP_Ge; break;
    }
    windowAggStep(pParse, pMWin, csrStart, 1, regArg, regSize);
    sqlite3VdbeResolveLabel(v, lblSkipInverse);
    arith = OP_Subtract;
  }
  if( pMWin->eEnd==TK_FOLLOWING ){
    sqlite3VdbeJumpHere(v, addrIfPos1);
  }

  sqlite3VdbeAddOp2(v, OP_Goto, 0, addrTop);
  windowReadPeerValues(p, csr1, reg1);
  windowReadPeerValues(p, csr2, reg2);

  /* flush_partition_done: */
  sqlite3VdbeResolveLabel(v, lblFlushDone);
  sqlite3VdbeAddOp1(v, OP_ResetSorter, pMWin->iEphCsr);
  sqlite3VdbeAddOp1(v, OP_Return, regFlushPart);
  VdbeComment((v, "end flush_partition subroutine"));

  /* Check if the peer value for csr1 value is a text or blob by comparing
  ** it to the smallest possible string - ''. If it is, jump over the
  ** OP_Add or OP_Subtract operation and proceed directly to the comparison. */
  sqlite3VdbeAddOp4(v, OP_String8, 0, regString, 0, "", P4_STATIC);
  addrGe = sqlite3VdbeAddOp3(v, OP_Ge, regString, 0, reg1);
  VdbeCoverage(v);
  sqlite3VdbeAddOp3(v, arith, regVal, reg1, reg1);
  /* Jump to here to skip over flush_partition */
  sqlite3VdbeJumpHere(v, addrGoto);
}

  sqlite3VdbeJumpHere(v, addrGe);
  sqlite3VdbeAddOp3(v, op, reg2, lbl, reg1); VdbeCoverage(v);
  sqlite3VdbeChangeP5(v, SQLITE_NULLEQ);
  assert( op==OP_Ge || op==OP_Gt || op==OP_Lt || op==OP_Le );
  testcase(op==OP_Ge); VdbeCoverageIf(v, op==OP_Ge);
  testcase(op==OP_Lt); VdbeCoverageIf(v, op==OP_Lt);
  testcase(op==OP_Le); VdbeCoverageIf(v, op==OP_Le);
  testcase(op==OP_Gt); VdbeCoverageIf(v, op==OP_Gt);

  sqlite3ReleaseTempReg(pParse, reg1);
  sqlite3ReleaseTempReg(pParse, reg2);
}
/*
** This function does the work of sqlite3WindowCodeStep() for cases that
** would normally be handled by windowCodeDefaultStep() when there are
** one or more built-in window-functions that require the entire partition
** to be cached in a temp table before any rows can be returned. Additionally.
** "RANGE BETWEEN CURRENT ROW AND UNBOUNDED FOLLOWING" is always handled by
** this function.
**
** Pseudo-code corresponding to the VM code generated by this function
** for each type of window follows.
**
** RANGE BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW
**
**   flush_partition:
**     Once {
**       OpenDup (iEphCsr -> csrLead)
**     }
**     Integer ctr 0
**     foreach row (csrLead){
**       if( new peer ){
**         AggFinal (xValue)
**         for(i=0; i<ctr; i++){
**           Gosub addrGosub
**           Next iEphCsr
**         }
**         Integer ctr 0
**       }
**       AggStep (csrLead)
**       Incr ctr
**     }
**
**     AggFinal (xFinalize)

**     for(i=0; i<ctr; i++){
**       Gosub addrGosub
**       Next iEphCsr
**     }
**
/*
** Helper function for sqlite3WindowCodeStep(). Each call to this function
** generates VM code for a single RETURN_ROW, AGGSTEP or AGGINVERSE 
** operation. Refer to the header comment for sqlite3WindowCodeStep() for
** details.
*/
**     ResetSorter (csr)
**     Return
**
** ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW
**
**   As above, except that the "if( new peer )" branch is always taken.
static int windowCodeOp(
 WindowCodeArg *p,                /* Context object */
 int op,                          /* WINDOW_RETURN_ROW, AGGSTEP or AGGINVERSE */
 int regCountdown,                /* Register for OP_IfPos countdown */
 int jumpOnEof                    /* Jump here if stepped cursor reaches EOF */
**
** RANGE BETWEEN CURRENT ROW AND CURRENT ROW 
**
**   As above, except that each of the for() loops becomes:
**
**         for(i=0; i<ctr; i++){
){
**           Gosub addrGosub
**           AggInverse (iEphCsr)
**           Next iEphCsr
  int csr, reg;
  Parse *pParse = p->pParse;
  Window *pMWin = p->pMWin;
  int ret = 0;
**         }
**
** RANGE BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
**
**   flush_partition:
**     Once {
  Vdbe *v = p->pVdbe;
**       OpenDup (iEphCsr -> csrLead)
**     }
**     foreach row (csrLead) {
**       AggStep (csrLead)
  int addrIf = 0; 
**     }
**     foreach row (iEphCsr) {
**       Gosub addrGosub
  int addrContinue = 0;
  int addrGoto = 0;
**     }
** 
** RANGE BETWEEN CURRENT ROW AND UNBOUNDED FOLLOWING
**
**   flush_partition:
**     Once {
**       OpenDup (iEphCsr -> csrLead)
**     }
  int bPeer = (pMWin->eFrmType!=TK_ROWS);

**     foreach row (csrLead){
**       AggStep (csrLead)
**     }
**     Rewind (csrLead)
**     Integer ctr 0
**     foreach row (csrLead){
**       if( new peer ){
**         AggFinal (xValue)
**         for(i=0; i<ctr; i++){
**           Gosub addrGosub
**           AggInverse (iEphCsr)
**           Next iEphCsr
**         }
**         Integer ctr 0
**       }
**       Incr ctr
**     }
**
**     AggFinal (xFinalize)
**     for(i=0; i<ctr; i++){
**       Gosub addrGosub
**       Next iEphCsr
**     }
**
**     ResetSorter (csr)
**     Return
*/
static void windowCodeCacheStep(
  Parse *pParse, 
  Select *p,
  WhereInfo *pWInfo,
  int regGosub, 
  int addrGosub
){
  Window *pMWin = p->pWin;
  Vdbe *v = sqlite3GetVdbe(pParse);
  int lblDone = sqlite3VdbeMakeLabel(pParse);
  int k;
  int addr;
  ExprList *pPart = pMWin->pPartition;
  ExprList *pOrderBy = pMWin->pOrderBy;
  int nPeer = pOrderBy ? pOrderBy->nExpr : 0;
  int addrNextRange = 0;

  /* Special case - WINDOW_AGGINVERSE is always a no-op if the frame
  ** starts with UNBOUNDED PRECEDING. */
  if( op==WINDOW_AGGINVERSE && pMWin->eStart==TK_UNBOUNDED ){
    assert( regCountdown==0 && jumpOnEof==0 );
    return 0;
  }
  int regNewPeer;

  int addrGoto;                   /* Address of Goto used to jump flush_par.. */
  int addrNext;                   /* Jump here for next iteration of loop */
  int regFlushPart;
  int lblFlushPart;
  int csrLead;
  int regCtr;
  if( regCountdown>0 ){
  int regArg;                     /* Register array to martial function args */
  int regSize;
  int lblEmpty;
  int bReverse = pMWin->pOrderBy && pMWin->eStart==TK_CURRENT 
          && pMWin->eEnd==TK_UNBOUNDED;

  assert( (pMWin->eStart==TK_UNBOUNDED && pMWin->eEnd==TK_CURRENT) 
    if( pMWin->eFrmType==TK_RANGE ){
      addrNextRange = sqlite3VdbeCurrentAddr(v);
      assert( op==WINDOW_AGGINVERSE || op==WINDOW_AGGSTEP );
       || (pMWin->eStart==TK_UNBOUNDED && pMWin->eEnd==TK_UNBOUNDED) 
       || (pMWin->eStart==TK_CURRENT && pMWin->eEnd==TK_CURRENT) 
      if( op==WINDOW_AGGINVERSE ){
        if( pMWin->eStart==TK_FOLLOWING ){
       || (pMWin->eStart==TK_CURRENT && pMWin->eEnd==TK_UNBOUNDED) 
  );

  lblEmpty = sqlite3VdbeMakeLabel(pParse);
          windowCodeRangeTest(
              p, OP_Le, p->current.csr, regCountdown, p->start.csr, lblDone
          );
        }else{
          windowCodeRangeTest(
              p, OP_Ge, p->start.csr, regCountdown, p->current.csr, lblDone
          );
  regNewPeer = pParse->nMem+1;
  pParse->nMem += nPeer;

        }
  /* Allocate register and label for the "flush_partition" sub-routine. */
  regFlushPart = ++pParse->nMem;
      }else{
  lblFlushPart = sqlite3VdbeMakeLabel(pParse);

        windowCodeRangeTest(
  csrLead = pParse->nTab++;
  regCtr = ++pParse->nMem;

            p, OP_Gt, p->end.csr, regCountdown, p->current.csr, lblDone
        );
  windowPartitionCache(pParse, p, pWInfo, regFlushPart, lblFlushPart, &regSize);
  addrGoto = sqlite3VdbeAddOp0(v, OP_Goto);

      }
  /* Start of "flush_partition" */
  sqlite3VdbeResolveLabel(v, lblFlushPart);
  sqlite3VdbeAddOp2(v, OP_Once, 0, sqlite3VdbeCurrentAddr(v)+2);
  VdbeCoverage(v);
    }else{
      addrIf = sqlite3VdbeAddOp3(v, OP_IfPos, regCountdown, 0, 1);
      VdbeCoverage(v);
  sqlite3VdbeAddOp2(v, OP_OpenDup, csrLead, pMWin->iEphCsr);

    }
  /* Initialize the accumulator register for each window function to NULL */
  }
  regArg = windowInitAccum(pParse, pMWin);

  sqlite3VdbeAddOp2(v, OP_Integer, 0, regCtr);
  sqlite3VdbeAddOp2(v, OP_Rewind, csrLead, lblEmpty);
  VdbeCoverage(v);
  sqlite3VdbeAddOp2(v, OP_Rewind, pMWin->iEphCsr, lblEmpty);
  VdbeCoverageNeverTaken(v);

  if( op==WINDOW_RETURN_ROW && pMWin->regStartRowid==0 ){
  if( bReverse ){
    int addr2 = sqlite3VdbeCurrentAddr(v);
    windowAggStep(pParse, pMWin, csrLead, 0, regArg, regSize);
    windowAggFinal(p, 0);
    sqlite3VdbeAddOp2(v, OP_Next, csrLead, addr2);
    VdbeCoverage(v);
    sqlite3VdbeAddOp2(v, OP_Rewind, csrLead, lblEmpty);
    VdbeCoverageNeverTaken(v);
  }
  addrNext = sqlite3VdbeCurrentAddr(v);

  addrContinue = sqlite3VdbeCurrentAddr(v);
  switch( op ){
  if( pOrderBy && (pMWin->eEnd==TK_CURRENT || pMWin->eStart==TK_CURRENT) ){
    int bCurrent = (pMWin->eStart==TK_CURRENT);
    case WINDOW_RETURN_ROW:
      csr = p->current.csr;
    int addrJump = 0;             /* Address of OP_Jump below */
    if( pMWin->eType==TK_RANGE ){
      int iOff = pMWin->nBufferCol + (pPart ? pPart->nExpr : 0);
      int regPeer = pMWin->regPart + (pPart ? pPart->nExpr : 0);
      KeyInfo *pKeyInfo = sqlite3KeyInfoFromExprList(pParse, pOrderBy, 0, 0);
      for(k=0; k<nPeer; k++){
        sqlite3VdbeAddOp3(v, OP_Column, csrLead, iOff+k, regNewPeer+k);
      }
      addr = sqlite3VdbeAddOp3(v, OP_Compare, regNewPeer, regPeer, nPeer);
      sqlite3VdbeAppendP4(v, (void*)pKeyInfo, P4_KEYINFO);
      addrJump = sqlite3VdbeAddOp3(v, OP_Jump, addr+2, 0, addr+2);
      VdbeCoverage(v);
      sqlite3VdbeAddOp3(v, OP_Copy, regNewPeer, regPeer, nPeer-1);
    }

    windowReturnRows(pParse, pMWin, regCtr, regGosub, addrGosub, 
      reg = p->current.reg;
      windowReturnOneRow(p);
        (bCurrent ? regArg : 0), (bCurrent ? regSize : 0)
    );
    if( addrJump ) sqlite3VdbeJumpHere(v, addrJump);
  }

  if( bReverse==0 ){
    windowAggStep(pParse, pMWin, csrLead, 0, regArg, regSize);
  }
  sqlite3VdbeAddOp2(v, OP_AddImm, regCtr, 1);
      break;

    case WINDOW_AGGINVERSE:
      csr = p->start.csr;
      reg = p->start.reg;
      if( pMWin->regStartRowid ){
        assert( pMWin->regEndRowid );
        sqlite3VdbeAddOp2(v, OP_AddImm, pMWin->regStartRowid, 1);
      }else{
        windowAggStep(pParse, pMWin, csr, 1, p->regArg);
      }
      break;
  sqlite3VdbeAddOp2(v, OP_Next, csrLead, addrNext);
  VdbeCoverage(v);

    default:
      assert( op==WINDOW_AGGSTEP );
  windowReturnRows(pParse, pMWin, regCtr, regGosub, addrGosub, 0, 0);

  sqlite3VdbeResolveLabel(v, lblEmpty);
  sqlite3VdbeAddOp1(v, OP_ResetSorter, pMWin->iEphCsr);
  sqlite3VdbeAddOp1(v, OP_Return, regFlushPart);

  /* Jump to here to skip over flush_partition */
      csr = p->end.csr;
      reg = p->end.reg;
      if( pMWin->regStartRowid ){
        assert( pMWin->regEndRowid );
        sqlite3VdbeAddOp2(v, OP_AddImm, pMWin->regEndRowid, 1);
      }else{
        windowAggStep(pParse, pMWin, csr, 0, p->regArg);
  sqlite3VdbeJumpHere(v, addrGoto);
}


      }
      break;
  }
/*
** RANGE BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW
**
**   ...
**     if( new partition ){
**       AggFinal (xFinalize)
**       Gosub addrGosub
**       ResetSorter eph-table
**     }
**     else if( new peer ){
**       AggFinal (xValue)
**       Gosub addrGosub
**       ResetSorter eph-table
**     }
**     AggStep
**     Insert (record into eph-table)
**   sqlite3WhereEnd()
**   AggFinal (xFinalize)
**   Gosub addrGosub
**
** RANGE BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
**
**   As above, except take no action for a "new peer". Invoke
**   the sub-routine once only for each partition.
**
** RANGE BETWEEN CURRENT ROW AND CURRENT ROW
**
**   As above, except that the "new peer" condition is handled in the
**   same way as "new partition" (so there is no "else if" block).
**
** ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW
** 
**   As above, except assume every row is a "new peer".
*/
static void windowCodeDefaultStep(
  Parse *pParse, 
  Select *p,
  WhereInfo *pWInfo,
  int regGosub, 
  int addrGosub
){
  Window *pMWin = p->pWin;
  Vdbe *v = sqlite3GetVdbe(pParse);
  int k;
  int iSubCsr = p->pSrc->a[0].iCursor;
  int nSub = p->pSrc->a[0].pTab->nCol;
  int reg = pParse->nMem+1;
  int regRecord = reg+nSub;
  int regRowid = regRecord+1;
  int addr;
  ExprList *pPart = pMWin->pPartition;
  ExprList *pOrderBy = pMWin->pOrderBy;

  assert( pMWin->eType==TK_RANGE 
  if( op==p->eDelete ){
      || (pMWin->eStart==TK_UNBOUNDED && pMWin->eEnd==TK_CURRENT)
  );

    sqlite3VdbeAddOp1(v, OP_Delete, csr);
  assert( (pMWin->eStart==TK_UNBOUNDED && pMWin->eEnd==TK_CURRENT)
       || (pMWin->eStart==TK_UNBOUNDED && pMWin->eEnd==TK_UNBOUNDED)
       || (pMWin->eStart==TK_CURRENT && pMWin->eEnd==TK_CURRENT)
       || (pMWin->eStart==TK_CURRENT && pMWin->eEnd==TK_UNBOUNDED && !pOrderBy)
  );

    sqlite3VdbeChangeP5(v, OPFLAG_SAVEPOSITION);
  if( pMWin->eEnd==TK_UNBOUNDED ){
    pOrderBy = 0;
  }

  pParse->nMem += nSub + 2;

  if( jumpOnEof ){
  /* Load the individual column values of the row returned by
  ** the sub-select into an array of registers. */
  for(k=0; k<nSub; k++){
    sqlite3VdbeAddOp3(v, OP_Column, iSubCsr, k, reg+k);
    sqlite3VdbeAddOp2(v, OP_Next, csr, sqlite3VdbeCurrentAddr(v)+2);
  }

    VdbeCoverage(v);
  /* Check if this is the start of a new partition or peer group. */
  if( pPart || pOrderBy ){
    int nPart = (pPart ? pPart->nExpr : 0);
    int addrGoto = 0;
    ret = sqlite3VdbeAddOp0(v, OP_Goto);
    int addrJump = 0;
    int nPeer = (pOrderBy ? pOrderBy->nExpr : 0);

  }else{
    if( pPart ){
      int regNewPart = reg + pMWin->nBufferCol;
      KeyInfo *pKeyInfo = sqlite3KeyInfoFromExprList(pParse, pPart, 0, 0);
      addr = sqlite3VdbeAddOp3(v, OP_Compare, regNewPart, pMWin->regPart,nPart);
      sqlite3VdbeAppendP4(v, (void*)pKeyInfo, P4_KEYINFO);
      addrJump = sqlite3VdbeAddOp3(v, OP_Jump, addr+2, 0, addr+2);
      VdbeCoverageEqNe(v);
    sqlite3VdbeAddOp2(v, OP_Next, csr, sqlite3VdbeCurrentAddr(v)+1+bPeer);
    VdbeCoverage(v);
      windowAggFinal(pParse, pMWin, 1);
      if( pOrderBy ){
        addrGoto = sqlite3VdbeAddOp0(v, OP_Goto);
      }
    }
    if( bPeer ){
      addrGoto = sqlite3VdbeAddOp0(v, OP_Goto);
    }
  }

    if( pOrderBy ){
      int regNewPeer = reg + pMWin->nBufferCol + nPart;
      int regPeer = pMWin->regPart + nPart;

      if( addrJump ) sqlite3VdbeJumpHere(v, addrJump);
      if( pMWin->eType==TK_RANGE ){
        KeyInfo *pKeyInfo = sqlite3KeyInfoFromExprList(pParse, pOrderBy, 0, 0);
        addr = sqlite3VdbeAddOp3(v, OP_Compare, regNewPeer, regPeer, nPeer);
        sqlite3VdbeAppendP4(v, (void*)pKeyInfo, P4_KEYINFO);
        addrJump = sqlite3VdbeAddOp3(v, OP_Jump, addr+2, 0, addr+2);
        VdbeCoverage(v);
      }else{
        addrJump = 0;
      }

      windowAggFinal(pParse, pMWin, pMWin->eStart==TK_CURRENT);
      if( addrGoto ) sqlite3VdbeJumpHere(v, addrGoto);
    }

  if( bPeer ){
    sqlite3VdbeAddOp2(v, OP_Rewind, pMWin->iEphCsr,sqlite3VdbeCurrentAddr(v)+3);
    VdbeCoverage(v);
    sqlite3VdbeAddOp2(v, OP_Gosub, regGosub, addrGosub);
    sqlite3VdbeAddOp2(v, OP_Next, pMWin->iEphCsr, sqlite3VdbeCurrentAddr(v)-1);
    VdbeCoverage(v);

    int nReg = (pMWin->pOrderBy ? pMWin->pOrderBy->nExpr : 0);
    sqlite3VdbeAddOp1(v, OP_ResetSorter, pMWin->iEphCsr);
    sqlite3VdbeAddOp3(
        v, OP_Copy, reg+pMWin->nBufferCol, pMWin->regPart, nPart+nPeer-1
    int regTmp = (nReg ? sqlite3GetTempRange(pParse, nReg) : 0);
    windowReadPeerValues(p, csr, regTmp);
    );

    if( addrJump ) sqlite3VdbeJumpHere(v, addrJump);
    windowIfNewPeer(pParse, pMWin->pOrderBy, regTmp, reg, addrContinue);
    sqlite3ReleaseTempRange(pParse, regTmp, nReg);
  }

  /* Invoke step function for window functions */
  windowAggStep(pParse, pMWin, -1, 0, reg, 0);

  if( addrNextRange ){
  /* Buffer the current row in the ephemeral table. */
  if( pMWin->nBufferCol>0 ){
    sqlite3VdbeAddOp3(v, OP_MakeRecord, reg, pMWin->nBufferCol, regRecord);
  }else{
    sqlite3VdbeAddOp2(v, OP_Blob, 0, regRecord);
    sqlite3VdbeAddOp2(v, OP_Goto, 0, addrNextRange);
    sqlite3VdbeAppendP4(v, (void*)"", 0);
  }
  sqlite3VdbeAddOp2(v, OP_NewRowid, pMWin->iEphCsr, regRowid);
  sqlite3VdbeAddOp3(v, OP_Insert, pMWin->iEphCsr, regRecord, regRowid);

  sqlite3VdbeResolveLabel(v, lblDone);
  if( addrGoto ) sqlite3VdbeJumpHere(v, addrGoto);
  if( addrIf ) sqlite3VdbeJumpHere(v, addrIf);
  /* End the database scan loop. */
  sqlite3WhereEnd(pWInfo);

  return ret;
}
  windowAggFinal(pParse, pMWin, 1);
  sqlite3VdbeAddOp2(v, OP_Rewind, pMWin->iEphCsr,sqlite3VdbeCurrentAddr(v)+3);
  VdbeCoverage(v);
  sqlite3VdbeAddOp2(v, OP_Gosub, regGosub, addrGosub);
  sqlite3VdbeAddOp2(v, OP_Next, pMWin->iEphCsr, sqlite3VdbeCurrentAddr(v)-1);
  VdbeCoverage(v);
}


/*
** Allocate and return a duplicate of the Window object indicated by the
** third argument. Set the Window.pOwner field of the new object to
** pOwner.
*/
SQLITE_PRIVATE Window *sqlite3WindowDup(sqlite3 *db, Expr *pOwner, Window *p){
  Window *pNew = 0;
  if( ALWAYS(p) ){
    pNew = sqlite3DbMallocZero(db, sizeof(Window));
    if( pNew ){
      pNew->zName = sqlite3DbStrDup(db, p->zName);
      pNew->pFilter = sqlite3ExprDup(db, p->pFilter, 0);
      pNew->pFunc = p->pFunc;
      pNew->pPartition = sqlite3ExprListDup(db, p->pPartition, 0);
      pNew->pOrderBy = sqlite3ExprListDup(db, p->pOrderBy, 0);
      pNew->eType = p->eType;
      pNew->eFrmType = p->eFrmType;
      pNew->eEnd = p->eEnd;
      pNew->eStart = p->eStart;
      pNew->eExclude = p->eExclude;
      pNew->pStart = sqlite3ExprDup(db, p->pStart, 0);
      pNew->pEnd = sqlite3ExprDup(db, p->pEnd, 0);
      pNew->pOwner = pOwner;
    }
  }
  return pNew;
}
147221
147222
147223
147224
147225
147226
147227




















147228
147229
147230
147231
147232
147233
147234











































































































































































































































































































































147235
147236
147237
147238
147239
147240
147241
147242
147243













































147244
147245
147246
147247










147248
147249
147250
147251





147252
147253

147254
147255

147256
147257
147258
147259















147260
147261
147262
147263
147264
147265
147266
147267
147268
147269
147270
147271
147272
147273
147274
147275
147276
147277
147278
147279
147280
147281
147282
147283
147284
147285
147286
147287
147288
147289
147290




































































































































147291
147292
147293

147294
147295
147296
147297
147298
147299
147300
147301
147302
147303
147304
147305
147306
147307
147308







































































147309























147310

147311





147312


147313
147314
147315
147316
147317
147318
147319
147405
147406
147407
147408
147409
147410
147411
147412
147413
147414
147415
147416
147417
147418
147419
147420
147421
147422
147423
147424
147425
147426
147427
147428
147429
147430
147431
147432
147433
147434
147435



147436
147437
147438
147439
147440
147441
147442
147443
147444
147445
147446
147447
147448
147449
147450
147451
147452
147453
147454
147455
147456
147457
147458
147459
147460
147461
147462
147463
147464
147465
147466
147467
147468
147469
147470
147471
147472
147473
147474
147475
147476
147477
147478
147479
147480
147481
147482
147483
147484
147485
147486
147487
147488
147489
147490
147491
147492
147493
147494
147495
147496
147497
147498
147499
147500
147501
147502
147503
147504
147505
147506
147507
147508
147509
147510
147511
147512
147513
147514
147515
147516
147517
147518
147519
147520
147521
147522
147523
147524
147525
147526
147527
147528
147529
147530
147531
147532
147533
147534
147535
147536
147537
147538
147539
147540
147541
147542
147543
147544
147545
147546
147547
147548
147549
147550
147551
147552
147553
147554
147555
147556
147557
147558
147559
147560
147561
147562
147563
147564
147565
147566
147567
147568
147569
147570
147571
147572
147573
147574
147575
147576
147577
147578
147579
147580
147581
147582
147583
147584
147585
147586
147587
147588
147589
147590
147591
147592
147593
147594
147595
147596
147597
147598
147599
147600
147601
147602
147603
147604
147605
147606
147607
147608
147609
147610
147611
147612
147613
147614
147615
147616
147617
147618
147619
147620
147621
147622
147623
147624
147625
147626
147627
147628
147629
147630
147631
147632
147633
147634
147635
147636
147637
147638
147639
147640
147641
147642
147643
147644
147645
147646
147647
147648
147649
147650
147651
147652
147653
147654
147655
147656
147657
147658
147659
147660
147661
147662
147663
147664
147665
147666
147667
147668
147669
147670
147671
147672
147673
147674
147675
147676
147677
147678
147679
147680
147681
147682
147683
147684
147685
147686
147687
147688
147689
147690
147691
147692
147693
147694
147695
147696
147697
147698
147699
147700
147701
147702
147703
147704
147705
147706
147707
147708
147709
147710
147711
147712
147713
147714
147715
147716
147717
147718
147719
147720
147721
147722
147723
147724
147725
147726
147727
147728
147729
147730
147731
147732
147733
147734
147735
147736
147737
147738
147739
147740
147741
147742
147743
147744
147745
147746
147747
147748
147749
147750
147751
147752
147753
147754
147755
147756
147757
147758
147759
147760
147761
147762
147763
147764
147765
147766
147767
147768
147769
147770
147771
147772
147773
147774
147775
147776
147777
147778
147779
147780
147781
147782
147783
147784
147785
147786
147787
147788
147789
147790
147791
147792
147793
147794
147795
147796
147797
147798
147799
147800
147801
147802
147803
147804
147805
147806
147807
147808
147809
147810
147811
147812
147813
147814
147815
147816
147817
147818
147819
147820
147821



147822
147823
147824
147825
147826
147827
147828
147829
147830
147831




147832
147833
147834
147835
147836


147837


147838




147839
147840
147841
147842
147843
147844
147845
147846
147847
147848
147849
147850
147851
147852
147853































147854
147855
147856
147857
147858
147859
147860
147861
147862
147863
147864
147865
147866
147867
147868
147869
147870
147871
147872
147873
147874
147875
147876
147877
147878
147879
147880
147881
147882
147883
147884
147885
147886
147887
147888
147889
147890
147891
147892
147893
147894
147895
147896
147897
147898
147899
147900
147901
147902
147903
147904
147905
147906
147907
147908
147909
147910
147911
147912
147913
147914
147915
147916
147917
147918
147919
147920
147921
147922
147923
147924
147925
147926
147927
147928
147929
147930
147931
147932
147933
147934
147935
147936
147937
147938
147939
147940
147941
147942
147943
147944
147945
147946
147947
147948
147949
147950
147951
147952
147953
147954
147955
147956
147957
147958
147959
147960
147961
147962
147963
147964
147965
147966
147967
147968
147969
147970
147971
147972
147973
147974
147975
147976
147977
147978
147979
147980
147981
147982
147983
147984
147985



147986















147987
147988
147989
147990
147991
147992
147993
147994
147995
147996
147997
147998
147999
148000
148001
148002
148003
148004
148005
148006
148007
148008
148009
148010
148011
148012
148013
148014
148015
148016
148017
148018
148019
148020
148021
148022
148023
148024
148025
148026
148027
148028
148029
148030
148031
148032
148033
148034
148035
148036
148037
148038
148039
148040
148041
148042
148043
148044
148045
148046
148047
148048
148049
148050
148051
148052
148053
148054
148055
148056
148057
148058
148059
148060
148061
148062
148063
148064
148065
148066
148067
148068
148069
148070
148071
148072
148073
148074
148075
148076
148077
148078
148079
148080
148081

148082

148083
148084
148085
148086
148087
148088
148089
148090
148091
148092
148093
148094
148095
148096
148097







+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+




-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+









+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+

-
-
-
+
+
+
+
+
+
+
+
+
+
-
-
-
-
+
+
+
+
+
-
-
+
-
-
+
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+

+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
+
-
+
+
+
+
+

+
+







    *pp = sqlite3WindowDup(db, 0, pWin);
    if( *pp==0 ) break;
    pp = &((*pp)->pNextWin);
  }

  return pRet;
}

/*
** Return true if it can be determined at compile time that expression 
** pExpr evaluates to a value that, when cast to an integer, is greater 
** than zero. False otherwise.
**
** If an OOM error occurs, this function sets the Parse.db.mallocFailed 
** flag and returns zero.
*/
static int windowExprGtZero(Parse *pParse, Expr *pExpr){
  int ret = 0;
  sqlite3 *db = pParse->db;
  sqlite3_value *pVal = 0;
  sqlite3ValueFromExpr(db, pExpr, db->enc, SQLITE_AFF_NUMERIC, &pVal);
  if( pVal && sqlite3_value_int(pVal)>0 ){
    ret = 1;
  }
  sqlite3ValueFree(pVal);
  return ret;
}

/*
** sqlite3WhereBegin() has already been called for the SELECT statement 
** passed as the second argument when this function is invoked. It generates
** code to populate the Window.regResult register for each window function and
** invoke the sub-routine at instruction addrGosub once for each row.
** This function calls sqlite3WhereEnd() before returning. 
** code to populate the Window.regResult register for each window function 
** and invoke the sub-routine at instruction addrGosub once for each row.
** sqlite3WhereEnd() is always called before returning. 
**
** This function handles several different types of window frames, which
** require slightly different processing. The following pseudo code is
** used to implement window frames of the form:
**
**   ROWS BETWEEN <expr1> PRECEDING AND <expr2> FOLLOWING
**
** Other window frame types use variants of the following:
**
**     ... loop started by sqlite3WhereBegin() ...
**       if( new partition ){
**         Gosub flush
**       }
**       Insert new row into eph table.
**       
**       if( first row of partition ){
**         // Rewind three cursors, all open on the eph table.
**         Rewind(csrEnd);
**         Rewind(csrStart);
**         Rewind(csrCurrent);
**       
**         regEnd = <expr2>          // FOLLOWING expression
**         regStart = <expr1>        // PRECEDING expression
**       }else{
**         // First time this branch is taken, the eph table contains two 
**         // rows. The first row in the partition, which all three cursors
**         // currently point to, and the following row.
**         AGGSTEP
**         if( (regEnd--)<=0 ){
**           RETURN_ROW
**           if( (regStart--)<=0 ){
**             AGGINVERSE
**           }
**         }
**       }
**     }
**     flush:
**       AGGSTEP
**       while( 1 ){
**         RETURN ROW
**         if( csrCurrent is EOF ) break;
**         if( (regStart--)<=0 ){
**           AggInverse(csrStart)
**           Next(csrStart)
**         }
**       }
**
** The pseudo-code above uses the following shorthand:
**
**   AGGSTEP:    invoke the aggregate xStep() function for each window function
**               with arguments read from the current row of cursor csrEnd, then
**               step cursor csrEnd forward one row (i.e. sqlite3BtreeNext()).
**
**   RETURN_ROW: return a row to the caller based on the contents of the 
**               current row of csrCurrent and the current state of all 
**               aggregates. Then step cursor csrCurrent forward one row.
**
**   AGGINVERSE: invoke the aggregate xInverse() function for each window 
**               functions with arguments read from the current row of cursor
**               csrStart. Then step csrStart forward one row.
**
** There are two other ROWS window frames that are handled significantly
** differently from the above - "BETWEEN <expr> PRECEDING AND <expr> PRECEDING"
** and "BETWEEN <expr> FOLLOWING AND <expr> FOLLOWING". These are special 
** cases because they change the order in which the three cursors (csrStart,
** csrCurrent and csrEnd) iterate through the ephemeral table. Cases that
** use UNBOUNDED or CURRENT ROW are much simpler variations on one of these
** three.
**
**   ROWS BETWEEN <expr1> PRECEDING AND <expr2> PRECEDING
**
**     ... loop started by sqlite3WhereBegin() ...
**       if( new partition ){
**         Gosub flush
**       }
**       Insert new row into eph table.
**       if( first row of partition ){
**         Rewind(csrEnd) ; Rewind(csrStart) ; Rewind(csrCurrent)
**         regEnd = <expr2>
**         regStart = <expr1>
**       }else{
**         if( (regEnd--)<=0 ){
**           AGGSTEP
**         }
**         RETURN_ROW
**         if( (regStart--)<=0 ){
**           AGGINVERSE
**         }
**       }
**     }
**     flush:
**       if( (regEnd--)<=0 ){
**         AGGSTEP
**       }
**       RETURN_ROW
**
**
**   ROWS BETWEEN <expr1> FOLLOWING AND <expr2> FOLLOWING
**
**     ... loop started by sqlite3WhereBegin() ...
**     if( new partition ){
**       Gosub flush
**     }
**     Insert new row into eph table.
**     if( first row of partition ){
**       Rewind(csrEnd) ; Rewind(csrStart) ; Rewind(csrCurrent)
**       regEnd = <expr2>
**       regStart = regEnd - <expr1>
**     }else{
**       AGGSTEP
**       if( (regEnd--)<=0 ){
**         RETURN_ROW
**       }
**       if( (regStart--)<=0 ){
**         AGGINVERSE
**       }
**     }
**   }
**   flush:
**     AGGSTEP
**     while( 1 ){
**       if( (regEnd--)<=0 ){
**         RETURN_ROW
**         if( eof ) break;
**       }
**       if( (regStart--)<=0 ){
**         AGGINVERSE
**         if( eof ) break
**       }
**     }
**     while( !eof csrCurrent ){
**       RETURN_ROW
**     }
**
** For the most part, the patterns above are adapted to support UNBOUNDED by
** assuming that it is equivalent to "infinity PRECEDING/FOLLOWING" and
** CURRENT ROW by assuming that it is equivilent to "0 PRECEDING/FOLLOWING".
** This is optimized of course - branches that will never be taken and
** conditions that are always true are omitted from the VM code. The only
** exceptional case is:
**
**   ROWS BETWEEN <expr1> FOLLOWING AND UNBOUNDED FOLLOWING
**
**     ... loop started by sqlite3WhereBegin() ...
**     if( new partition ){
**       Gosub flush
**     }
**     Insert new row into eph table.
**     if( first row of partition ){
**       Rewind(csrEnd) ; Rewind(csrStart) ; Rewind(csrCurrent)
**       regStart = <expr1>
**     }else{
**       AGGSTEP
**     }
**   }
**   flush:
**     AGGSTEP
**     while( 1 ){
**       if( (regStart--)<=0 ){
**         AGGINVERSE
**         if( eof ) break
**       }
**       RETURN_ROW
**     }
**     while( !eof csrCurrent ){
**       RETURN_ROW
**     }
**
** Also requiring special handling are the cases:
**
**   ROWS BETWEEN <expr1> PRECEDING AND <expr2> PRECEDING
**   ROWS BETWEEN <expr1> FOLLOWING AND <expr2> FOLLOWING
**
** when (expr1 < expr2). This is detected at runtime, not by this function.
** To handle this case, the pseudo-code programs depicted above are modified
** slightly to be:
**
**     ... loop started by sqlite3WhereBegin() ...
**     if( new partition ){
**       Gosub flush
**     }
**     Insert new row into eph table.
**     if( first row of partition ){
**       Rewind(csrEnd) ; Rewind(csrStart) ; Rewind(csrCurrent)
**       regEnd = <expr2>
**       regStart = <expr1>
**       if( regEnd < regStart ){
**         RETURN_ROW
**         delete eph table contents
**         continue
**       }
**     ...
**
** The new "continue" statement in the above jumps to the next iteration
** of the outer loop - the one started by sqlite3WhereBegin().
**
** The various GROUPS cases are implemented using the same patterns as
** ROWS. The VM code is modified slightly so that:
**
**   1. The else branch in the main loop is only taken if the row just
**      added to the ephemeral table is the start of a new group. In
**      other words, it becomes:
**
**         ... loop started by sqlite3WhereBegin() ...
**         if( new partition ){
**           Gosub flush
**         }
**         Insert new row into eph table.
**         if( first row of partition ){
**           Rewind(csrEnd) ; Rewind(csrStart) ; Rewind(csrCurrent)
**           regEnd = <expr2>
**           regStart = <expr1>
**         }else if( new group ){
**           ... 
**         }
**       }
**
**   2. Instead of processing a single row, each RETURN_ROW, AGGSTEP or 
**      AGGINVERSE step processes the current row of the relevant cursor and
**      all subsequent rows belonging to the same group.
**
** RANGE window frames are a little different again. As for GROUPS, the 
** main loop runs once per group only. And RETURN_ROW, AGGSTEP and AGGINVERSE
** deal in groups instead of rows. As for ROWS and GROUPS, there are three
** basic cases:
**
**   RANGE BETWEEN <expr1> PRECEDING AND <expr2> FOLLOWING
**
**     ... loop started by sqlite3WhereBegin() ...
**       if( new partition ){
**         Gosub flush
**       }
**       Insert new row into eph table.
**       if( first row of partition ){
**         Rewind(csrEnd) ; Rewind(csrStart) ; Rewind(csrCurrent)
**         regEnd = <expr2>
**         regStart = <expr1>
**       }else{
**         AGGSTEP
**         while( (csrCurrent.key + regEnd) < csrEnd.key ){
**           RETURN_ROW
**           while( csrStart.key + regStart) < csrCurrent.key ){
**             AGGINVERSE
**           }
**         }
**       }
**     }
**     flush:
**       AGGSTEP
**       while( 1 ){
**         RETURN ROW
**         if( csrCurrent is EOF ) break;
**           while( csrStart.key + regStart) < csrCurrent.key ){
**             AGGINVERSE
**           }
**         }
**       }
**
** In the above notation, "csr.key" means the current value of the ORDER BY 
** expression (there is only ever 1 for a RANGE that uses an <expr> FOLLOWING
** or <expr PRECEDING) read from cursor csr.
**
**   RANGE BETWEEN <expr1> PRECEDING AND <expr2> PRECEDING
**
**     ... loop started by sqlite3WhereBegin() ...
**       if( new partition ){
**         Gosub flush
**       }
**       Insert new row into eph table.
**       if( first row of partition ){
**         Rewind(csrEnd) ; Rewind(csrStart) ; Rewind(csrCurrent)
**         regEnd = <expr2>
**         regStart = <expr1>
**       }else{
**         if( (csrEnd.key + regEnd) <= csrCurrent.key ){
**           AGGSTEP
**         }
**         while( (csrStart.key + regStart) < csrCurrent.key ){
**           AGGINVERSE
**         }
**         RETURN_ROW
**       }
**     }
**     flush:
**       while( (csrEnd.key + regEnd) <= csrCurrent.key ){
**         AGGSTEP
**       }
**       while( (csrStart.key + regStart) < csrCurrent.key ){
**         AGGINVERSE
**       }
**       RETURN_ROW
**
**   RANGE BETWEEN <expr1> FOLLOWING AND <expr2> FOLLOWING
**
**     ... loop started by sqlite3WhereBegin() ...
**       if( new partition ){
**         Gosub flush
**       }
**       Insert new row into eph table.
**       if( first row of partition ){
**         Rewind(csrEnd) ; Rewind(csrStart) ; Rewind(csrCurrent)
**         regEnd = <expr2>
**         regStart = <expr1>
**       }else{
**         AGGSTEP
**         while( (csrCurrent.key + regEnd) < csrEnd.key ){
**           while( (csrCurrent.key + regStart) > csrStart.key ){
**             AGGINVERSE
**           }
**           RETURN_ROW
**         }
**       }
**     }
**     flush:
**       AGGSTEP
**       while( 1 ){
**         while( (csrCurrent.key + regStart) > csrStart.key ){
**           AGGINVERSE
**           if( eof ) break "while( 1 )" loop.
**         }
**         RETURN_ROW
**       }
**       while( !eof csrCurrent ){
**         RETURN_ROW
**       }
**
** The text above leaves out many details. Refer to the code and comments
** below for a more complete picture.
*/
SQLITE_PRIVATE void sqlite3WindowCodeStep(
  Parse *pParse,                  /* Parse context */
  Select *p,                      /* Rewritten SELECT statement */
  WhereInfo *pWInfo,              /* Context returned by sqlite3WhereBegin() */
  int regGosub,                   /* Register for OP_Gosub */
  int addrGosub                   /* OP_Gosub here to return each row */
){
  Window *pMWin = p->pWin;
  ExprList *pOrderBy = pMWin->pOrderBy;
  Vdbe *v = sqlite3GetVdbe(pParse);
  int csrWrite;                   /* Cursor used to write to eph. table */
  int csrInput = p->pSrc->a[0].iCursor;     /* Cursor of sub-select */
  int nInput = p->pSrc->a[0].pTab->nCol;    /* Number of cols returned by sub */
  int iInput;                               /* To iterate through sub cols */
  int addrNe;                     /* Address of OP_Ne */
  int addrGosubFlush = 0;         /* Address of OP_Gosub to flush: */
  int addrInteger = 0;            /* Address of OP_Integer */
  int addrEmpty;                  /* Address of OP_Rewind in flush: */
  int regStart = 0;               /* Value of <expr> PRECEDING */
  int regEnd = 0;                 /* Value of <expr> FOLLOWING */
  int regNew;                     /* Array of registers holding new input row */
  int regRecord;                  /* regNew array in record form */
  int regRowid;                   /* Rowid for regRecord in eph table */
  int regNewPeer = 0;             /* Peer values for new row (part of regNew) */
  int regPeer = 0;                /* Peer values for current row */
  int regFlushPart = 0;           /* Register for "Gosub flush_partition" */
  WindowCodeArg s;                /* Context object for sub-routines */
  int lblWhereEnd;                /* Label just before sqlite3WhereEnd() code */

  assert( pMWin->eStart==TK_PRECEDING || pMWin->eStart==TK_CURRENT 
       || pMWin->eStart==TK_FOLLOWING || pMWin->eStart==TK_UNBOUNDED 
  );
  assert( pMWin->eEnd==TK_FOLLOWING || pMWin->eEnd==TK_CURRENT 
       || pMWin->eEnd==TK_UNBOUNDED || pMWin->eEnd==TK_PRECEDING 
  );
  assert( pMWin->eExclude==0 || pMWin->eExclude==TK_CURRENT
       || pMWin->eExclude==TK_GROUP || pMWin->eExclude==TK_TIES
       || pMWin->eExclude==TK_NO
  );

  lblWhereEnd = sqlite3VdbeMakeLabel(pParse);

  /* Fill in the context object */
  memset(&s, 0, sizeof(WindowCodeArg));
  s.pParse = pParse;
  s.pMWin = pMWin;
  s.pVdbe = v;
  s.regGosub = regGosub;
  s.addrGosub = addrGosub;
  s.current.csr = pMWin->iEphCsr;
  csrWrite = s.current.csr+1;
  s.start.csr = s.current.csr+2;
  s.end.csr = s.current.csr+3;

  /* There are three different functions that may be used to do the work
  ** of this one, depending on the window frame and the specific built-in
  ** window functions used (if any).
  /* Figure out when rows may be deleted from the ephemeral table. There
  ** are four options - they may never be deleted (eDelete==0), they may 
  ** be deleted as soon as they are no longer part of the window frame
  ** (eDelete==WINDOW_AGGINVERSE), they may be deleted as after the row 
  ** has been returned to the caller (WINDOW_RETURN_ROW), or they may
  ** be deleted after they enter the frame (WINDOW_AGGSTEP). */
  switch( pMWin->eStart ){
    case TK_FOLLOWING:
      if( pMWin->eFrmType!=TK_RANGE
       && windowExprGtZero(pParse, pMWin->pStart)
  **
  ** windowCodeRowExprStep() handles all "ROWS" window frames, except for:
  **
  **   ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW
      ){
        s.eDelete = WINDOW_RETURN_ROW;
      }
      break;
    case TK_UNBOUNDED:
  **
  ** The exception is because windowCodeRowExprStep() implements all window
      if( windowCacheFrame(pMWin)==0 ){
  ** frame types by caching the entire partition in a temp table, and
  ** "ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW" is easy enough to
        if( pMWin->eEnd==TK_PRECEDING ){
  ** implement without such a cache.
  **
  ** windowCodeCacheStep() is used for:
  **
          if( pMWin->eFrmType!=TK_RANGE
           && windowExprGtZero(pParse, pMWin->pEnd)
          ){
            s.eDelete = WINDOW_AGGSTEP;
          }
        }else{
          s.eDelete = WINDOW_RETURN_ROW;
        }
      }
      break;
    default:
      s.eDelete = WINDOW_AGGINVERSE;
      break;
  }

  **   RANGE BETWEEN CURRENT ROW AND UNBOUNDED FOLLOWING
  **
  ** It is also used for anything not handled by windowCodeRowExprStep() 
  ** that invokes a built-in window function that requires the entire 
  ** partition to be cached in a temp table before any rows are returned
  ** (e.g. nth_value() or percent_rank()).
  **
  ** Finally, assuming there is no built-in window function that requires
  ** the partition to be cached, windowCodeDefaultStep() is used for:
  **
  **   RANGE BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW 
  **   RANGE BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
  **   RANGE BETWEEN CURRENT ROW AND CURRENT ROW 
  **   ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW
  **
  ** windowCodeDefaultStep() is the only one of the three functions that
  ** does not cache each partition in a temp table before beginning to
  ** return rows.
  */
  if( pMWin->eType==TK_ROWS 
   && (pMWin->eStart!=TK_UNBOUNDED||pMWin->eEnd!=TK_CURRENT||!pMWin->pOrderBy)
  ){
    VdbeModuleComment((pParse->pVdbe, "Begin RowExprStep()"));
    windowCodeRowExprStep(pParse, p, pWInfo, regGosub, addrGosub);
  }else{
    Window *pWin;
    int bCache = 0;               /* True to use CacheStep() */

    if( pMWin->eStart==TK_CURRENT && pMWin->eEnd==TK_UNBOUNDED ){
      bCache = 1;
    }else{
  /* Allocate registers for the array of values from the sub-query, the
  ** samve values in record form, and the rowid used to insert said record
  ** into the ephemeral table.  */
  regNew = pParse->nMem+1;
  pParse->nMem += nInput;
  regRecord = ++pParse->nMem;
  regRowid = ++pParse->nMem;

  /* If the window frame contains an "<expr> PRECEDING" or "<expr> FOLLOWING"
  ** clause, allocate registers to store the results of evaluating each
  ** <expr>.  */
  if( pMWin->eStart==TK_PRECEDING || pMWin->eStart==TK_FOLLOWING ){
    regStart = ++pParse->nMem;
  }
  if( pMWin->eEnd==TK_PRECEDING || pMWin->eEnd==TK_FOLLOWING ){
    regEnd = ++pParse->nMem;
  }

  /* If this is not a "ROWS BETWEEN ..." frame, then allocate arrays of
  ** registers to store copies of the ORDER BY expressions (peer values) 
  ** for the main loop, and for each cursor (start, current and end). */
  if( pMWin->eFrmType!=TK_ROWS ){
    int nPeer = (pOrderBy ? pOrderBy->nExpr : 0);
    regNewPeer = regNew + pMWin->nBufferCol;
    if( pMWin->pPartition ) regNewPeer += pMWin->pPartition->nExpr;
    regPeer = pParse->nMem+1;       pParse->nMem += nPeer;
    s.start.reg = pParse->nMem+1;   pParse->nMem += nPeer;
    s.current.reg = pParse->nMem+1; pParse->nMem += nPeer;
    s.end.reg = pParse->nMem+1;     pParse->nMem += nPeer;
  }

  /* Load the column values for the row returned by the sub-select
  ** into an array of registers starting at regNew. Assemble them into
  ** a record in register regRecord. */
  for(iInput=0; iInput<nInput; iInput++){
    sqlite3VdbeAddOp3(v, OP_Column, csrInput, iInput, regNew+iInput);
  }
  sqlite3VdbeAddOp3(v, OP_MakeRecord, regNew, nInput, regRecord);

  /* An input row has just been read into an array of registers starting
  ** at regNew. If the window has a PARTITION clause, this block generates 
  ** VM code to check if the input row is the start of a new partition.
  ** If so, it does an OP_Gosub to an address to be filled in later. The
  ** address of the OP_Gosub is stored in local variable addrGosubFlush. */
  if( pMWin->pPartition ){
    int addr;
    ExprList *pPart = pMWin->pPartition;
    int nPart = pPart->nExpr;
    int regNewPart = regNew + pMWin->nBufferCol;
    KeyInfo *pKeyInfo = sqlite3KeyInfoFromExprList(pParse, pPart, 0, 0);

    regFlushPart = ++pParse->nMem;
    addr = sqlite3VdbeAddOp3(v, OP_Compare, regNewPart, pMWin->regPart, nPart);
    sqlite3VdbeAppendP4(v, (void*)pKeyInfo, P4_KEYINFO);
    sqlite3VdbeAddOp3(v, OP_Jump, addr+2, addr+4, addr+2);
    VdbeCoverageEqNe(v);
    addrGosubFlush = sqlite3VdbeAddOp1(v, OP_Gosub, regFlushPart);
    VdbeComment((v, "call flush_partition"));
    sqlite3VdbeAddOp3(v, OP_Copy, regNewPart, pMWin->regPart, nPart-1);
  }

  /* Insert the new row into the ephemeral table */
  sqlite3VdbeAddOp2(v, OP_NewRowid, csrWrite, regRowid);
  sqlite3VdbeAddOp3(v, OP_Insert, csrWrite, regRecord, regRowid);
  addrNe = sqlite3VdbeAddOp3(v, OP_Ne, pMWin->regOne, 0, regRowid);
  VdbeCoverageNeverNull(v);

  /* This block is run for the first row of each partition */
  s.regArg = windowInitAccum(pParse, pMWin);

  if( regStart ){
    sqlite3ExprCode(pParse, pMWin->pStart, regStart);
    windowCheckValue(pParse, regStart, 0 + (pMWin->eFrmType==TK_RANGE ? 3 : 0));
  }
  if( regEnd ){
    sqlite3ExprCode(pParse, pMWin->pEnd, regEnd);
    windowCheckValue(pParse, regEnd, 1 + (pMWin->eFrmType==TK_RANGE ? 3 : 0));
  }

  if( pMWin->eStart==pMWin->eEnd && regStart ){
    int op = ((pMWin->eStart==TK_FOLLOWING) ? OP_Ge : OP_Le);
    int addrGe = sqlite3VdbeAddOp3(v, op, regStart, 0, regEnd);
    VdbeCoverageNeverNullIf(v, op==OP_Ge); /* NeverNull because bound <expr> */
    VdbeCoverageNeverNullIf(v, op==OP_Le); /*   values previously checked */
    windowAggFinal(&s, 0);
    sqlite3VdbeAddOp2(v, OP_Rewind, s.current.csr, 1);
    VdbeCoverageNeverTaken(v);
    windowReturnOneRow(&s);
    sqlite3VdbeAddOp1(v, OP_ResetSorter, s.current.csr);
    sqlite3VdbeAddOp2(v, OP_Goto, 0, lblWhereEnd);
    sqlite3VdbeJumpHere(v, addrGe);
  }
  if( pMWin->eStart==TK_FOLLOWING && pMWin->eFrmType!=TK_RANGE && regEnd ){
    assert( pMWin->eEnd==TK_FOLLOWING );
    sqlite3VdbeAddOp3(v, OP_Subtract, regStart, regEnd, regStart);
  }

  if( pMWin->eStart!=TK_UNBOUNDED ){
    sqlite3VdbeAddOp2(v, OP_Rewind, s.start.csr, 1);
    VdbeCoverageNeverTaken(v);
  }
  sqlite3VdbeAddOp2(v, OP_Rewind, s.current.csr, 1);
  VdbeCoverageNeverTaken(v);
  sqlite3VdbeAddOp2(v, OP_Rewind, s.end.csr, 1);
  VdbeCoverageNeverTaken(v);
  if( regPeer && pOrderBy ){
    sqlite3VdbeAddOp3(v, OP_Copy, regNewPeer, regPeer, pOrderBy->nExpr-1);
    sqlite3VdbeAddOp3(v, OP_Copy, regPeer, s.start.reg, pOrderBy->nExpr-1);
    sqlite3VdbeAddOp3(v, OP_Copy, regPeer, s.current.reg, pOrderBy->nExpr-1);
    sqlite3VdbeAddOp3(v, OP_Copy, regPeer, s.end.reg, pOrderBy->nExpr-1);
  }

  sqlite3VdbeAddOp2(v, OP_Goto, 0, lblWhereEnd);

  sqlite3VdbeJumpHere(v, addrNe);

  /* Beginning of the block executed for the second and subsequent rows. */
  if( regPeer ){
    windowIfNewPeer(pParse, pOrderBy, regNewPeer, regPeer, lblWhereEnd);
  }
  if( pMWin->eStart==TK_FOLLOWING ){
    windowCodeOp(&s, WINDOW_AGGSTEP, 0, 0);
    if( pMWin->eEnd!=TK_UNBOUNDED ){
      if( pMWin->eFrmType==TK_RANGE ){
        int lbl = sqlite3VdbeMakeLabel(pParse);
        int addrNext = sqlite3VdbeCurrentAddr(v);
        windowCodeRangeTest(&s, OP_Ge, s.current.csr, regEnd, s.end.csr, lbl);
        windowCodeOp(&s, WINDOW_AGGINVERSE, regStart, 0);
        windowCodeOp(&s, WINDOW_RETURN_ROW, 0, 0);
        sqlite3VdbeAddOp2(v, OP_Goto, 0, addrNext);
        sqlite3VdbeResolveLabel(v, lbl);
      }else{
      for(pWin=pMWin; pWin; pWin=pWin->pNextWin){
        FuncDef *pFunc = pWin->pFunc;
        if( (pFunc->funcFlags & SQLITE_FUNC_WINDOW_SIZE)
        windowCodeOp(&s, WINDOW_RETURN_ROW, regEnd, 0);
         || (pFunc->zName==nth_valueName)
         || (pFunc->zName==first_valueName)
         || (pFunc->zName==leadName)
         || (pFunc->zName==lagName)
        ){
          bCache = 1;
          break;
        }
      }
    }

    /* Otherwise, call windowCodeDefaultStep().  */
    if( bCache ){
      VdbeModuleComment((pParse->pVdbe, "Begin CacheStep()"));
      windowCodeCacheStep(pParse, p, pWInfo, regGosub, addrGosub);
        windowCodeOp(&s, WINDOW_AGGINVERSE, regStart, 0);
      }
    }
  }else
  if( pMWin->eEnd==TK_PRECEDING ){
    int bRPS = (pMWin->eStart==TK_PRECEDING && pMWin->eFrmType==TK_RANGE);
    windowCodeOp(&s, WINDOW_AGGSTEP, regEnd, 0);
    if( bRPS ) windowCodeOp(&s, WINDOW_AGGINVERSE, regStart, 0);
    windowCodeOp(&s, WINDOW_RETURN_ROW, 0, 0);
    if( !bRPS ) windowCodeOp(&s, WINDOW_AGGINVERSE, regStart, 0);
  }else{
    int addr = 0;
    windowCodeOp(&s, WINDOW_AGGSTEP, 0, 0);
    if( pMWin->eEnd!=TK_UNBOUNDED ){
      if( pMWin->eFrmType==TK_RANGE ){
        int lbl = 0;
        addr = sqlite3VdbeCurrentAddr(v);
        if( regEnd ){
          lbl = sqlite3VdbeMakeLabel(pParse);
          windowCodeRangeTest(&s, OP_Ge, s.current.csr, regEnd, s.end.csr, lbl);
        }
        windowCodeOp(&s, WINDOW_RETURN_ROW, 0, 0);
        windowCodeOp(&s, WINDOW_AGGINVERSE, regStart, 0);
        if( regEnd ){
          sqlite3VdbeAddOp2(v, OP_Goto, 0, addr);
          sqlite3VdbeResolveLabel(v, lbl);
        }
      }else{
        if( regEnd ){
          addr = sqlite3VdbeAddOp3(v, OP_IfPos, regEnd, 0, 1);
          VdbeCoverage(v);
        }
        windowCodeOp(&s, WINDOW_RETURN_ROW, 0, 0);
        windowCodeOp(&s, WINDOW_AGGINVERSE, regStart, 0);
        if( regEnd ) sqlite3VdbeJumpHere(v, addr);
      }
    }
  }

  /* End of the main input loop */
  sqlite3VdbeResolveLabel(v, lblWhereEnd);
  sqlite3WhereEnd(pWInfo);

  /* Fall through */
  if( pMWin->pPartition ){
    addrInteger = sqlite3VdbeAddOp2(v, OP_Integer, 0, regFlushPart);
    sqlite3VdbeJumpHere(v, addrGosubFlush);
  }

  addrEmpty = sqlite3VdbeAddOp1(v, OP_Rewind, csrWrite);
  VdbeCoverage(v);
  if( pMWin->eEnd==TK_PRECEDING ){
    int bRPS = (pMWin->eStart==TK_PRECEDING && pMWin->eFrmType==TK_RANGE);
    windowCodeOp(&s, WINDOW_AGGSTEP, regEnd, 0);
    if( bRPS ) windowCodeOp(&s, WINDOW_AGGINVERSE, regStart, 0);
    windowCodeOp(&s, WINDOW_RETURN_ROW, 0, 0);
  }else if( pMWin->eStart==TK_FOLLOWING ){
    int addrStart;
    int addrBreak1;
    int addrBreak2;
    int addrBreak3;
    windowCodeOp(&s, WINDOW_AGGSTEP, 0, 0);
    if( pMWin->eFrmType==TK_RANGE ){
      addrStart = sqlite3VdbeCurrentAddr(v);
      addrBreak2 = windowCodeOp(&s, WINDOW_AGGINVERSE, regStart, 1);
      addrBreak1 = windowCodeOp(&s, WINDOW_RETURN_ROW, 0, 1);
    }else
    if( pMWin->eEnd==TK_UNBOUNDED ){
      addrStart = sqlite3VdbeCurrentAddr(v);
      addrBreak1 = windowCodeOp(&s, WINDOW_RETURN_ROW, regStart, 1);
      addrBreak2 = windowCodeOp(&s, WINDOW_AGGINVERSE, 0, 1);
    }else{
      assert( pMWin->eEnd==TK_FOLLOWING );
      addrStart = sqlite3VdbeCurrentAddr(v);
      addrBreak1 = windowCodeOp(&s, WINDOW_RETURN_ROW, regEnd, 1);
      addrBreak2 = windowCodeOp(&s, WINDOW_AGGINVERSE, regStart, 1);
    }
    sqlite3VdbeAddOp2(v, OP_Goto, 0, addrStart);
    sqlite3VdbeJumpHere(v, addrBreak2);
    addrStart = sqlite3VdbeCurrentAddr(v);
    addrBreak3 = windowCodeOp(&s, WINDOW_RETURN_ROW, 0, 1);
    sqlite3VdbeAddOp2(v, OP_Goto, 0, addrStart);
    sqlite3VdbeJumpHere(v, addrBreak1);
    sqlite3VdbeJumpHere(v, addrBreak3);
  }else{
    int addrBreak;
    int addrStart;
    windowCodeOp(&s, WINDOW_AGGSTEP, 0, 0);
    addrStart = sqlite3VdbeCurrentAddr(v);
    addrBreak = windowCodeOp(&s, WINDOW_RETURN_ROW, 0, 1);
    windowCodeOp(&s, WINDOW_AGGINVERSE, regStart, 0);
    sqlite3VdbeAddOp2(v, OP_Goto, 0, addrStart);
    sqlite3VdbeJumpHere(v, addrBreak);
  }
  sqlite3VdbeJumpHere(v, addrEmpty);
      VdbeModuleComment((pParse->pVdbe, "Begin DefaultStep()"));

      windowCodeDefaultStep(pParse, p, pWInfo, regGosub, addrGosub);
  sqlite3VdbeAddOp1(v, OP_ResetSorter, s.current.csr);
  if( pMWin->pPartition ){
    if( pMWin->regStartRowid ){
      sqlite3VdbeAddOp2(v, OP_Integer, 1, pMWin->regStartRowid);
      sqlite3VdbeAddOp2(v, OP_Integer, 0, pMWin->regEndRowid);
    }
    sqlite3VdbeChangeP1(v, addrInteger, sqlite3VdbeCurrentAddr(v));
    sqlite3VdbeAddOp1(v, OP_Return, regFlushPart);
  }
}

#endif /* SQLITE_OMIT_WINDOWFUNC */

/************** End of window.c **********************************************/
/************** Begin file parse.c *******************************************/
147494
147495
147496
147497
147498
147499
147500




147501
147502
147503
147504
147505
147506
147507
148272
148273
148274
148275
148276
148277
148278
148279
148280
148281
148282
148283
148284
148285
148286
148287
148288
148289







+
+
+
+







    ){
      sqlite3ErrorMsg(pParse, "syntax error after column name \"%.*s\"",
                         pIdToken->n, pIdToken->z);
    }
    sqlite3ExprListSetName(pParse, p, pIdToken, 1);
    return p;
  }

#if TK_SPAN>255
# error too many tokens in the grammar
#endif
/**************** End of %include directives **********************************/
/* These constants specify the various numeric values for terminal symbols
** in a format understandable to "makeheaders".  This section is blank unless
** "lemon" is run with the "-m" command-line option.
***************** Begin makeheaders token definitions *************************/
/**************** End makeheaders token definitions ***************************/

147557
147558
147559
147560
147561
147562
147563
147564

147565
147566

147567
147568
147569
147570

147571
147572


147573
147574
147575
147576
147577
147578
147579
147580
147581
147582
147583












147584
147585
147586
147587
147588
147589
147590
147591
147592
147593
147594
147595
147596
147597
147598
147599
147600
147601
147602
147603
147604
147605
147606
147607
147608
147609
147610











147611
147612
147613
147614
147615
147616
147617
148339
148340
148341
148342
148343
148344
148345

148346
148347

148348
148349
148350
148351
148352
148353


148354
148355











148356
148357
148358
148359
148360
148361
148362
148363
148364
148365
148366
148367

148368
148369
148370
148371
148372
148373
148374
148375
148376
148377
148378
148379
148380
148381
148382











148383
148384
148385
148386
148387
148388
148389
148390
148391
148392
148393
148394
148395
148396
148397
148398
148399
148400







-
+

-
+




+
-
-
+
+
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
-















-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+







**    YY_MAX_REDUCE      Maximum value for reduce actions
*/
#ifndef INTERFACE
# define INTERFACE 1
#endif
/************* Begin control #defines *****************************************/
#define YYCODETYPE unsigned short int
#define YYNOCODE 278
#define YYNOCODE 301
#define YYACTIONTYPE unsigned short int
#define YYWILDCARD 91
#define YYWILDCARD 95
#define sqlite3ParserTOKENTYPE Token
typedef union {
  int yyinit;
  sqlite3ParserTOKENTYPE yy0;
  With* yy59;
  ExprList* yy42;
  int yy96;
  IdList* yy62;
  struct TrigEvent yy90;
  TriggerStep* yy119;
  Window* yy147;
  SrcList* yy167;
  Upsert* yy266;
  struct FrameBound yy317;
  IdList* yy336;
  struct TrigEvent yy350;
  struct {int value; int mask;} yy367;
  Select* yy423;
  const char* yy464;
  Expr* yy490;
  Upsert* yy136;
  struct FrameBound yy201;
  u8 yy238;
  const char* yy294;
  Window* yy295;
  struct {int value; int mask;} yy355;
  ExprList* yy434;
  TriggerStep* yy455;
  Select* yy457;
  SrcList* yy483;
  int yy494;
  Expr* yy524;
  With* yy499;
} YYMINORTYPE;
#ifndef YYSTACKDEPTH
#define YYSTACKDEPTH 100
#endif
#define sqlite3ParserARG_SDECL
#define sqlite3ParserARG_PDECL
#define sqlite3ParserARG_PARAM
#define sqlite3ParserARG_FETCH
#define sqlite3ParserARG_STORE
#define sqlite3ParserCTX_SDECL Parse *pParse;
#define sqlite3ParserCTX_PDECL ,Parse *pParse
#define sqlite3ParserCTX_PARAM ,pParse
#define sqlite3ParserCTX_FETCH Parse *pParse=yypParser->pParse;
#define sqlite3ParserCTX_STORE yypParser->pParse=pParse;
#define YYFALLBACK 1
#define YYNSTATE             524
#define YYNRULE              369
#define YYNTOKEN             155
#define YY_MAX_SHIFT         523
#define YY_MIN_SHIFTREDUCE   760
#define YY_MAX_SHIFTREDUCE   1128
#define YY_ERROR_ACTION      1129
#define YY_ACCEPT_ACTION     1130
#define YY_NO_ACTION         1131
#define YY_MIN_REDUCE        1132
#define YY_MAX_REDUCE        1500
#define YYNSTATE             541
#define YYNRULE              375
#define YYNTOKEN             176
#define YY_MAX_SHIFT         540
#define YY_MIN_SHIFTREDUCE   784
#define YY_MAX_SHIFTREDUCE   1158
#define YY_ERROR_ACTION      1159
#define YY_ACCEPT_ACTION     1160
#define YY_NO_ACTION         1161
#define YY_MIN_REDUCE        1162
#define YY_MAX_REDUCE        1536
/************* End control #defines *******************************************/
#define YY_NLOOKAHEAD ((int)(sizeof(yy_lookahead)/sizeof(yy_lookahead[0])))

/* Define the yytestcase() macro to be a no-op if is not already defined
** otherwise.
**
** Applications can choose to define yytestcase() in the %include section
147670
147671
147672
147673
147674
147675
147676
147677

147678
147679
147680
147681
147682
147683
147684
147685
147686
147687
147688
147689
147690
147691
147692
147693
147694
147695
147696
147697
147698
147699
147700
147701
147702
147703
147704
147705
147706
147707
147708
147709
147710
147711
147712
147713
147714
147715
147716
147717
147718
147719
147720
147721
147722
147723
147724
147725
147726
147727
147728
147729
147730
147731
147732
147733
147734
147735
147736
147737
147738
147739
147740
147741
147742
147743
147744
147745
147746
147747
147748
147749
147750
147751
147752
147753
















































































147754
147755
147756
147757
147758
147759
147760
147761
147762
147763
147764
147765
147766
147767
147768
147769
147770
147771
147772
147773
147774
147775
147776



























147777
147778
147779
147780
147781
147782
147783
147784
147785
147786
147787
147788
147789
147790
147791
147792
147793
147794
147795
147796
147797
147798
147799
147800
147801
147802



























147803
147804
147805
147806
147807
147808
147809
147810
147811
147812
147813
147814
147815
147816
147817
147818
147819
147820
147821
147822
147823
147824
147825
147826
147827



























147828
147829
147830
147831
147832
147833
147834
147835
147836
147837
147838
147839
147840
147841
147842
147843
147844
147845
147846
147847
147848
147849
147850
147851
147852
147853



























147854
147855
147856
147857
147858
147859
147860
147861
147862
147863
147864
147865
147866
147867
147868
147869
147870
147871
147872
147873
147874
147875
147876
147877
147878
147879



























147880
147881
147882
147883
147884
147885
147886
147887
147888
147889
147890
147891
147892
147893
147894
147895
147896
147897
147898
147899
147900
147901
147902
147903
147904

























147905
147906

147907
147908
147909
147910



147911
147912
147913
147914
147915
147916
147917
147918
147919
147920
147921
147922
147923
147924
147925
147926
147927
147928
147929
147930
147931
147932
147933
147934
147935
147936
147937
147938




























147939
147940
147941
147942
147943
147944
147945
147946
147947
147948










147949
147950
147951
147952
147953
147954
147955
147956
147957
147958
147959
147960
147961
147962














147963
147964
147965
147966
147967





147968
147969
147970
147971
147972





147973
147974
147975
147976
147977
147978
147979
147980
147981
147982
147983
147984
147985
147986
147987
147988
147989
147990
147991
147992
147993
147994
147995
147996
147997
147998
147999
148000
148001
148002
148003
148004
148005
148006
148007
148008
148009
148010
148011
148012
148013
148014
148015
148016
148017
148018
148019
148020
148021
148022





























































148023
148024
148025
148026
148027
148028
148029
148030
148031
148032
148033
148034












148035
148036
148037
148038
148039
148040
148041
148042
148043
148044
148045
148046
148047
148048
148049
148050
148051
148052
148053
148054
148055
148056
148057
148058
148059
148060
148061
148062
148063
148064
148065
148066
148067
148068
148069
148070
148071







































148072
148073
148074
148075
148076
148077
148078
148079
148080
148081
148082
148083














148084
148085

148086
148087

148088
148089
148090
148091
148092
148093
148094
148095
148096
148097
148098
148099
148100
148101
148102
148103
148104
148105
148106
148107
148108
148109
148110
148111
148112
148113
148114
148115
148116
148117
148118
148119
148120
148121
148122
148123
148124
148125
148126
148127
148128
148129
148130
148131
148132
148133
148134
148135
148136
148137
148138
148139
148140
148141























































148142
148143
148144
148145



148146
148147
148148
148149
148150
148151
148152
148153
148154
148155
148156
148157
148158
148159
148160
148161
148162
148163
148164
148165
148166
148167
148168
148169
148170
148171
148172
148173
148174
148175
148176
148177
148178
148179
148180
148181
148182
148183
148184







































148185
148186
148187
148188
148189
148190
148191
148192
148193
148194
148195
148196
148197
148198
148199
148200
148201
148202
148203
148204
148205
148206
148207
148208
148209
148210
148211
148212
148213
148214
148215
148216
148217
148218
148219
148220
148221
148222
148223
148224
148225
148226
148227
148228
148229
148230
148231
148232
148233
148234
148235
148236
148237
148238
148239























































148240
148241
148242
148243
148244
148245
148246
148453
148454
148455
148456
148457
148458
148459

148460
148461











































































148462
148463
148464
148465
148466
148467
148468
148469
148470
148471
148472
148473
148474
148475
148476
148477
148478
148479
148480
148481
148482
148483
148484
148485
148486
148487
148488
148489
148490
148491
148492
148493
148494
148495
148496
148497
148498
148499
148500
148501
148502
148503
148504
148505
148506
148507
148508
148509
148510
148511
148512
148513
148514
148515
148516
148517
148518
148519
148520
148521
148522
148523
148524
148525
148526
148527
148528
148529
148530
148531
148532
148533
148534
148535
148536
148537
148538
148539
148540
148541























148542
148543
148544
148545
148546
148547
148548
148549
148550
148551
148552
148553
148554
148555
148556
148557
148558
148559
148560
148561
148562
148563
148564
148565
148566
148567
148568


























148569
148570
148571
148572
148573
148574
148575
148576
148577
148578
148579
148580
148581
148582
148583
148584
148585
148586
148587
148588
148589
148590
148591
148592
148593
148594
148595

























148596
148597
148598
148599
148600
148601
148602
148603
148604
148605
148606
148607
148608
148609
148610
148611
148612
148613
148614
148615
148616
148617
148618
148619
148620
148621
148622


























148623
148624
148625
148626
148627
148628
148629
148630
148631
148632
148633
148634
148635
148636
148637
148638
148639
148640
148641
148642
148643
148644
148645
148646
148647
148648
148649


























148650
148651
148652
148653
148654
148655
148656
148657
148658
148659
148660
148661
148662
148663
148664
148665
148666
148667
148668
148669
148670
148671
148672
148673
148674
148675
148676
148677
148678























148679
148680
148681
148682
148683
148684
148685
148686
148687
148688
148689
148690
148691
148692
148693
148694
148695
148696
148697
148698
148699
148700
148701
148702
148703


148704




148705
148706
148707




























148708
148709
148710
148711
148712
148713
148714
148715
148716
148717
148718
148719
148720
148721
148722
148723
148724
148725
148726
148727
148728
148729
148730
148731
148732
148733
148734
148735










148736
148737
148738
148739
148740
148741
148742
148743
148744
148745














148746
148747
148748
148749
148750
148751
148752
148753
148754
148755
148756
148757
148758
148759





148760
148761
148762
148763
148764





148765
148766
148767
148768
148769


















































148770
148771
148772
148773
148774
148775
148776
148777
148778
148779
148780
148781
148782
148783
148784
148785
148786
148787
148788
148789
148790
148791
148792
148793
148794
148795
148796
148797
148798
148799
148800
148801
148802
148803
148804
148805
148806
148807
148808
148809
148810
148811
148812
148813
148814
148815
148816
148817
148818
148819
148820
148821
148822
148823
148824
148825
148826
148827
148828
148829
148830












148831
148832
148833
148834
148835
148836
148837
148838
148839
148840
148841
148842





































148843
148844
148845
148846
148847
148848
148849
148850
148851
148852
148853
148854
148855
148856
148857
148858
148859
148860
148861
148862
148863
148864
148865
148866
148867
148868
148869
148870
148871
148872
148873
148874
148875
148876
148877
148878
148879
148880
148881












148882
148883
148884
148885
148886
148887
148888
148889
148890
148891
148892
148893
148894
148895
148896

148897
148898

148899
148900





















































148901
148902
148903
148904
148905
148906
148907
148908
148909
148910
148911
148912
148913
148914
148915
148916
148917
148918
148919
148920
148921
148922
148923
148924
148925
148926
148927
148928
148929
148930
148931
148932
148933
148934
148935
148936
148937
148938
148939
148940
148941
148942
148943
148944
148945
148946
148947
148948
148949
148950
148951
148952
148953
148954
148955
148956



148957
148958
148959
148960






































148961
148962
148963
148964
148965
148966
148967
148968
148969
148970
148971
148972
148973
148974
148975
148976
148977
148978
148979
148980
148981
148982
148983
148984
148985
148986
148987
148988
148989
148990
148991
148992
148993
148994
148995
148996
148997
148998
148999
149000
149001





















































149002
149003
149004
149005
149006
149007
149008
149009
149010
149011
149012
149013
149014
149015
149016
149017
149018
149019
149020
149021
149022
149023
149024
149025
149026
149027
149028
149029
149030
149031
149032
149033
149034
149035
149036
149037
149038
149039
149040
149041
149042
149043
149044
149045
149046
149047
149048
149049
149050
149051
149052
149053
149054
149055
149056
149057
149058
149059
149060
149061
149062
149063







-
+

-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+


-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
+
-
-
-
-
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
+
+
+
+
+
-
-
-
-
-
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+

-
+

-
+

-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+

-
-
-
+
+
+

-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+


-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+







**  yy_shift_ofst[]    For each state, the offset into yy_action for
**                     shifting terminals.
**  yy_reduce_ofst[]   For each state, the offset into yy_action for
**                     shifting non-terminals after a reduce.
**  yy_default[]       Default action for each state.
**
*********** Begin parsing tables **********************************************/
#define YY_ACTTAB_COUNT (2009)
#define YY_ACTTAB_COUNT (2142)
static const YYACTIONTYPE yy_action[] = {
 /*     0 */   377,  518,  371,  107,  104,  200, 1293,  518, 1130,    1,
 /*    10 */     1,  523,    2, 1134,  518, 1203, 1203, 1262,  277,  373,
 /*    20 */   129,  495,   37,   37, 1397, 1201, 1201, 1211,   65,   65,
 /*    30 */   480,  891,  107,  104,  200,   37,   37, 1043, 1494,  892,
 /*    40 */   346, 1494,  342,  114,  115,  105, 1106, 1106,  957,  960,
 /*    50 */   950,  950,  112,  112,  113,  113,  113,  113,  285,  254,
 /*    60 */   254,  518,  254,  254,  500,  518,  495,  518,  107,  104,
 /*    70 */   200, 1085,  515,  481,  386,  515, 1464,  442,  501,  230,
 /*    80 */   197,  439,   37,   37, 1172,  210,   65,   65,   65,   65,
 /*    90 */   254,  254,  111,  111,  111,  111,  110,  110,  109,  109,
 /*   100 */   109,  108,  404,  515,  404,  155, 1041,  431,  401,  400,
 /*   110 */   254,  254,  373, 1431, 1427,  408, 1110, 1085, 1086, 1087,
 /*   120 */   284, 1112,  500,  515,  500,  368, 1433, 1421, 1428, 1111,
 /*   130 */  1261,  499,  373,  502,  108,  404,  114,  115,  105, 1106,
 /*   140 */  1106,  957,  960,  950,  950,  112,  112,  113,  113,  113,
 /*   150 */   113,  276,  509, 1113,  369, 1113,  114,  115,  105, 1106,
 /*   160 */  1106,  957,  960,  950,  950,  112,  112,  113,  113,  113,
 /*   170 */   113,  496, 1420, 1431,  493, 1468, 1065,  260, 1063,  433,
 /*   180 */    74,  107,  104,  200,  498,  111,  111,  111,  111,  110,
 /*   190 */   110,  109,  109,  109,  108,  404,  373,  113,  113,  113,
 /*   200 */   113,  106,  131,   91, 1361,  111,  111,  111,  111,  110,
 /*   210 */   110,  109,  109,  109,  108,  404,  113,  113,  113,  113,
 /*   220 */   114,  115,  105, 1106, 1106,  957,  960,  950,  950,  112,
 /*   230 */   112,  113,  113,  113,  113,  111,  111,  111,  111,  110,
 /*   240 */   110,  109,  109,  109,  108,  404,  116,  110,  110,  109,
 /*   250 */   109,  109,  108,  404,  111,  111,  111,  111,  110,  110,
 /*   260 */   109,  109,  109,  108,  404,  917,  512,  512,  512,  111,
 /*   270 */   111,  111,  111,  110,  110,  109,  109,  109,  108,  404,
 /*   280 */   517, 1198, 1177,  181,  109,  109,  109,  108,  404,  373,
 /*   290 */  1198,  402,  402,  402,   75,  360,  111,  111,  111,  111,
 /*   300 */   110,  110,  109,  109,  109,  108,  404,  382,  299,  419,
 /*   310 */   287,  170,  518,  114,  115,  105, 1106, 1106,  957,  960,
 /*   320 */   950,  950,  112,  112,  113,  113,  113,  113, 1444,  523,
 /*   330 */     2, 1134,  518,   13,   13,  337,  277, 1085,  129,  226,
 /*   340 */   937, 1058, 1000,  471,  917, 1211,  453,  384, 1085,  395,
 /*   350 */   162, 1057,  155,   45,   45,  416,  928,  401,  400,  479,
 /*   360 */   927,   12,  111,  111,  111,  111,  110,  110,  109,  109,
 /*   370 */   109,  108,  404,  226,  286,  254,  254,  254,  254,  518,
 /*   380 */    16,   16,  373, 1085, 1086, 1087,  314,  299,  515,  472,
 /*   390 */   515,  927,  927,  929, 1085, 1086, 1087,  378,  276,  509,
 /*   400 */    65,   65, 1113,  210, 1113, 1085,  114,  115,  105, 1106,
 /*   410 */  1106,  957,  960,  950,  950,  112,  112,  113,  113,  113,
 /*   420 */   113, 1448,  222, 1134, 1089,  461,  458,  457,  277,  180,
 /*   430 */   129,  378,  392,  408,  423,  456,  500, 1211,  240,  257,
 /*   440 */   324,  464,  319,  463,  227,  470,   12,  317,  424,  300,
 /*   450 */   317, 1085, 1086, 1087,  485,  111,  111,  111,  111,  110,
 /*   460 */   110,  109,  109,  109,  108,  404,  181,  118, 1085,  254,
 /*   470 */   254, 1089,  518,   90,  351,  373,  518, 1181,  365,  798,
 /*   480 */  1440,  339,  515,  248,  248,   77,  325,  133, 1085,  249,
 /*   490 */   424,  300,  794,   49,   49,  210,  515,   65,   65,  114,
 /*   500 */   115,  105, 1106, 1106,  957,  960,  950,  950,  112,  112,
 /*   510 */   113,  113,  113,  113, 1085, 1086, 1087,  222, 1085,  438,
 /*   520 */   461,  458,  457,  937,  787,  408,  171,  857,  362, 1021,
 /*   530 */   456,  136,  198,  486, 1085, 1086, 1087,  448,  794,  928,
 /*   540 */     5,  193,  192,  927, 1022,  107,  104,  200,  111,  111,
 /*   550 */   111,  111,  110,  110,  109,  109,  109,  108,  404, 1023,
 /*   560 */   254,  254,  803, 1085, 1085, 1086, 1087,  437,  373, 1085,
 /*   570 */   344,  787,  791,  515,  927,  927,  929, 1085, 1408, 1396,
 /*   580 */   832, 1085,  176,    3,  852, 1085,  518, 1439,  429,  851,
 /*   590 */   833,  518,  114,  115,  105, 1106, 1106,  957,  960,  950,
 /*   600 */   950,  112,  112,  113,  113,  113,  113,   13,   13, 1085,
 /*   610 */  1086, 1087,   13,   13,  518, 1085, 1086, 1087, 1496,  358,
 /*   620 */  1085,  389, 1234, 1085, 1086, 1087,  391, 1085, 1086, 1087,
 /*   630 */   448, 1085, 1086, 1087,  518,   65,   65,  947,  947,  958,
 /*   640 */   961,  111,  111,  111,  111,  110,  110,  109,  109,  109,
 /*   650 */   108,  404,  518,  382,  878,   13,   13,  518,  877,  518,
 /*   660 */   263,  373,  518,  431,  448, 1070, 1085, 1086, 1087,  267,
 /*   670 */   448,  488, 1360,   64,   64,  431,  812,  155,   50,   50,
 /*   680 */    65,   65,  518,   65,   65,  114,  115,  105, 1106, 1106,
 /*   690 */   957,  960,  950,  950,  112,  112,  113,  113,  113,  113,
 /*   700 */   518,  951,  382,   13,   13,  415,  411,  462,  414, 1085,
 /*   710 */  1366,  777, 1210,  292,  297,  813,  399,  497,  181,  403,
 /*   720 */   261,   15,   15,  276,  509,  414,  413, 1366, 1368,  410,
 /*   730 */   372,  345, 1209,  264,  111,  111,  111,  111,  110,  110,
 /*   740 */   109,  109,  109,  108,  404,  265,  254,  254,  229, 1405,
 /*     0 */   535, 1323,  112,  109,  209,  112,  109,  209, 1160,    1,
 /*    10 */     1,  540,    2, 1164,  535, 1292, 1228, 1207,  289,  384,
 /*    20 */   134,   42,   42, 1427,  382, 1228,    9, 1241,  242,  492,
 /*    30 */  1291,  915,  373,  379, 1026,   70,   70,  427, 1026,  916,
 /*    40 */   529,  529,  529,  119,  120,  110, 1136, 1136,  981,  984,
 /*    50 */   974,  974,  117,  117,  118,  118,  118,  118,  380,  264,
 /*    60 */   264,  264,  264, 1134,  264,  264,  112,  109,  209,  397,
 /*    70 */   454,  517,  532,  491,  532, 1233, 1233,  532,  239,  206,
 /*    80 */   493,  112,  109,  209,  464,  219,  118,  118,  118,  118,
 /*    90 */   111,  393,  440,  444,   16,   16,  116,  116,  116,  116,
 /*   100 */   115,  115,  114,  114,  114,  113,  415,  971,  971,  982,
 /*   110 */   985,  235, 1463,  351, 1134,  419,  384,  116,  116,  116,
 /*   120 */   116,  115,  115,  114,  114,  114,  113,  415,  116,  116,
 /*   130 */   116,  116,  115,  115,  114,  114,  114,  113,  415,  961,
 /*   140 */   119,  120,  110, 1136, 1136,  981,  984,  974,  974,  117,
 /*   150 */   117,  118,  118,  118,  118,  952,  415,  941,  298,  951,
 /*   160 */   941, 1480,  540,    2, 1164, 1115,  535, 1458,  160,  289,
 /*   170 */     6,  134, 1504,  389,  406,  975,  338, 1024, 1241,  337,
 /*   180 */  1089, 1476, 1089,  118,  118,  118,  118,   42,   42,  329,
 /*   190 */   951,  951,  953,  116,  116,  116,  116,  115,  115,  114,
 /*   200 */   114,  114,  113,  415,  311,  430,  299,  311,  881,  160,
 /*   210 */   264,  264,  401,  384,  324, 1115, 1116, 1117,  288,  526,
 /*   220 */    96,  159, 1441,  532,  141,  116,  116,  116,  116,  115,
 /*   230 */   115,  114,  114,  114,  113,  415,  219,  119,  120,  110,
 /*   240 */  1136, 1136,  981,  984,  974,  974,  117,  117,  118,  118,
 /*   250 */   118,  118,  115,  115,  114,  114,  114,  113,  415,  288,
 /*   260 */   526,  403,  533,  121,  870,  870,  419,  250,  267,  336,
 /*   270 */   475,  331,  474,  236,  160,  319, 1084,  322, 1465,  329,
 /*   280 */   350,   12,  535,  384,  502, 1115, 1084,  435,  312, 1084,
 /*   290 */   116,  116,  116,  116,  115,  115,  114,  114,  114,  113,
 /*   300 */   415,  535,  836,   42,   42,  138,  426,  119,  120,  110,
 /*   310 */  1136, 1136,  981,  984,  974,  974,  117,  117,  118,  118,
 /*   320 */   118,  118,   70,   70,  288,  526,  412,  411,  480, 1457,
 /*   330 */   335,   79,    6,  473, 1140, 1115, 1116, 1117,  501, 1142,
 /*   340 */   334,  837,  811, 1484,  512, 1164,  534, 1141,  123,  187,
 /*   350 */   289,  384,  134,  448,  434, 1115,   80,  349,  498, 1241,
 /*   360 */   116,  116,  116,  116,  115,  115,  114,  114,  114,  113,
 /*   370 */   415, 1143, 1115, 1143,  459,  119,  120,  110, 1136, 1136,
 /*   380 */   981,  984,  974,  974,  117,  117,  118,  118,  118,  118,
 /*   390 */   404,  264,  264,  811, 1463,  506,  368, 1156,  535,  114,
 /*   400 */   114,  114,  113,  415,  532, 1115, 1116, 1117,  231,  518,
 /*   410 */  1500,  472,  469,  468,  175,  497,  422,  219, 1202,   70,
 /*   420 */    70,  467, 1115, 1116, 1117,  176,  201,  200,  116,  116,
 /*   430 */   116,  116,  115,  115,  114,  114,  114,  113,  415,  535,
 /*   440 */  1115,  264,  264,  435,  312, 1115,  273,  419,  384,  513,
 /*   450 */  1450, 1115,  326, 1084,  532,  517,   82, 1084,  167,  388,
 /*   460 */    69,   69, 1115, 1084,  519,  509, 1084, 1084,   12, 1157,
 /*   470 */  1084,  420,  119,  120,  110, 1136, 1136,  981,  984,  974,
 /*   480 */   974,  117,  117,  118,  118,  118,  118,  258,  258,  535,
 /*   490 */  1115, 1116, 1117, 1045,  535, 1115, 1116, 1117, 1323,  535,
 /*   500 */   532, 1115, 1116, 1117,  296,  483, 1211,  818, 1046,  448,
 /*   510 */    70,   70, 1115, 1116, 1117,   50,   50,  448,  356,  500,
 /*   520 */    70,   70,  207, 1047,   32,  116,  116,  116,  116,  115,
 /*   530 */   115,  114,  114,  114,  113,  415,  453,  264,  264, 1115,
 /*   540 */   450,  449,  961,  508,  856,  384,  517,    5,  900,  822,
 /*   550 */   532,  484,  181, 1115,  857,  516,  517,  818,  952,  507,
 /*   560 */     3, 1115,  951, 1231, 1231,  482,  398, 1115, 1095,  119,
 /*   570 */   120,  110, 1136, 1136,  981,  984,  974,  974,  117,  117,
 /*   580 */   118,  118,  118,  118, 1115,  535,  238, 1115, 1391, 1115,
 /*   590 */  1116, 1117,  159,  951,  951,  953,  231, 1115,  259,  472,
 /*   600 */   469,  468,  310, 1115, 1116, 1117,   13,   13,  297,  467,
 /*   610 */   276, 1115, 1116, 1117,  412,  411, 1095, 1115, 1116, 1117,
 /*   620 */   395,  355,  116,  116,  116,  116,  115,  115,  114,  114,
 /*   630 */   114,  113,  415,  208, 1115, 1116, 1117, 1115, 1116, 1117,
 /*   640 */   264,  264,  384,  337,  902,  393,  815, 1115, 1116, 1117,
 /*   650 */   413,  413,  413,  532,  112,  109,  209,  309,  900, 1143,
 /*   660 */   535, 1143,  535,  393,  901, 1210,  119,  120,  110, 1136,
 /*   670 */  1136,  981,  984,  974,  974,  117,  117,  118,  118,  118,
 /*   680 */   118,   13,   13,   13,   13,  265,  265,  535,  143,  264,
 /*   690 */   264,  288,  526,  535, 1119,  400,  535,  402,  532,  510,
 /*   700 */  1457,  512,  532,    6,  113,  415, 1067, 1530,   70,   70,
 /*   710 */  1530,  535,  271,  535,   70,   70,  535,   13,   13,  116,
 /*   720 */   116,  116,  116,  115,  115,  114,  114,  114,  113,  415,
 /*   730 */   272,  277,   13,   13,   13,   13,  535,   13,   13,  384,
 /*   740 */   535,  304,  425, 1100,  284, 1119,  184,  801,  185,  338,
 /*   750 */   285,  514, 1532,  369, 1239, 1438, 1182,   70,   70,  425,
 /*   760 */   424,   70,   70,  119,  120,  110, 1136, 1136,  981,  984,
 /*   770 */   974,  974,  117,  117,  118,  118,  118,  118,  190, 1065,
 /*   780 */  1067, 1531,  442,  107, 1531,  408,  264,  264,  264,  264,
 /*   790 */   383, 1396,  261,  410,   95,  900,  485,  414,  421,  532,
 /*   750 */   268, 1215,  268, 1103,  373, 1085, 1086, 1087,  938,  515,
 /*   760 */   393,  409,  876,  515,  254,  254, 1152,  482,  473,  262,
 /*   770 */   422,  476,  325,  503,  289,  518,  291,  515,  114,  115,
 /*   780 */   105, 1106, 1106,  957,  960,  950,  950,  112,  112,  113,
 /*   790 */   113,  113,  113,  414, 1021, 1366,   39,   39,  254,  254,
 /*   800 */   254,  254,  980,  254,  254,  254,  254,  255,  255, 1022,
 /*   810 */   279,  515,  516,  515,  846,  846,  515,  138,  515,  518,
 /*   820 */   515, 1043, 1495,  251, 1023, 1495,  876,  111,  111,  111,
 /*   830 */   111,  110,  110,  109,  109,  109,  108,  404,  518, 1353,
 /*   840 */    51,   51,  518,  199,  518,  506,  290,  373,  518,  276,
 /*   850 */   509,  922,    9,  483,  233, 1005, 1005,  445,  189,   52,
 /*   860 */    52,  325,  280,   53,   53,   54,   54,  373,  876,   55,
 /*   870 */    55,  114,  115,  105, 1106, 1106,  957,  960,  950,  950,
 /*   880 */   112,  112,  113,  113,  113,  113,   97,  518,   95, 1104,
 /*   890 */  1041,  114,  115,  105, 1106, 1106,  957,  960,  950,  950,
 /*   900 */   112,  112,  113,  113,  113,  113,  135,  199,   56,   56,
 /*   910 */   765,  766,  767,  225,  224,  223,  518,  283,  437,  233,
 /*   920 */   111,  111,  111,  111,  110,  110,  109,  109,  109,  108,
 /*   930 */   404, 1002,  876,  326,  518, 1002, 1104,   40,   40,  518,
 /*   940 */   111,  111,  111,  111,  110,  110,  109,  109,  109,  108,
 /*   950 */   404,  518,  448,  518, 1104,   41,   41,  518,   17,  518,
 /*   960 */    43,   43, 1155,  379,  518,  448,  518,  443,  518,  390,
 /*   970 */   518,  194,   44,   44,   57,   57, 1247,  518,   58,   58,
 /*   800 */  1045,  532,  301, 1133,  303,  488,  433, 1451, 1396, 1398,
 /*   810 */   278,  535,  278,  520, 1435, 1046,  116,  116,  116,  116,
 /*   820 */   115,  115,  114,  114,  114,  113,  415,  425,  264,  264,
 /*   830 */  1047,  190,   54,   54,  535,  291,  384,  264,  264,  362,
 /*   840 */   962,  532, 1004,  376, 1084,  264,  264, 1029, 1029,  456,
 /*   850 */   532,  523,  270, 1065, 1084,   55,   55, 1084,  532,  442,
 /*   860 */   119,  120,  110, 1136, 1136,  981,  984,  974,  974,  117,
 /*   870 */   117,  118,  118,  118,  118,  535, 1396,  190,  302, 1383,
 /*   880 */   208,  535,  789,  790,  791,  535,  515,  535, 1323,  371,
 /*   890 */   337,  234,  233,  232,  459,  515,   15,   15,  459,  477,
 /*   900 */   459,  459,   44,   44,  136,  900,   56,   56,   57,   57,
 /*   910 */  1185,  390,  197,  116,  116,  116,  116,  115,  115,  114,
 /*   920 */   114,  114,  113,  415,  535,  876,  535,  442,  535,  274,
 /*   930 */   875, 1323,  357,  384,  353,  140, 1426,  946, 1455, 1323,
 /*   940 */  1390,    6, 1240, 1236,  292,   58,   58,   59,   59,   60,
 /*   950 */    60,  535, 1456,  384,  535,    6,  399,  119,  120,  110,
 /*   960 */  1136, 1136,  981,  984,  974,  974,  117,  117,  118,  118,
 /*   970 */   118,  118,   61,   61,  535,   45,   45,  119,  120,  110,
 /*   980 */  1136, 1136,  981,  984,  974,  974,  117,  117,  118,  118,
 /*   990 */   118,  118, 1477,  479,  202,   46,   46,  275,   95,  455,
 /*  1000 */   535,  212,  535,  337,  535, 1454,  535,  409,    6,  242,
 /*  1010 */   116,  116,  116,  116,  115,  115,  114,  114,  114,  113,
 /*  1020 */   415,   48,   48,   49,   49,   62,   62,   63,   63,  535,
 /*  1030 */   116,  116,  116,  116,  115,  115,  114,  114,  114,  113,
 /*  1040 */   415,  535,  459,  535, 1134,  535, 1151,  535,  142,  535,
 /*  1050 */    64,   64,  535, 1338,  535,  494,  535,  446,  535, 1264,
 /*  1060 */   535, 1337,   14,   14,   65,   65,  125,  125,   66,   66,
 /*   980 */    59,   59,  518,  466,  326,   14,   14,   60,   60,  120,
 /*   990 */   120,   61,   61,  449, 1206,   93,  518,  425,   46,   46,
 /*  1000 */   518, 1104,  518,   62,   62,  518,  437,  305,  518,  852,
 /*  1010 */   518,  298,  518, 1246,  851,  373,  518,   63,   63, 1293,
 /*  1020 */   397,   47,   47,  142,  142, 1467,  143,  143,  821,   70,
 /*  1030 */    70,   48,   48,   66,   66,  373,  518,  121,  121,  114,
 /*  1040 */   115,  105, 1106, 1106,  957,  960,  950,  950,  112,  112,
 /*  1050 */   113,  113,  113,  113,  518,  418,  518,   67,   67,  114,
 /*  1060 */   115,  105, 1106, 1106,  957,  960,  950,  950,  112,  112,
 /*  1070 */   113,  113,  113,  113,  312,  122,  122,  123,  123, 1293,
 /*  1080 */   518,  357, 1126,   88,  518,  435,  325,  387,  111,  111,
 /*  1090 */   111,  111,  110,  110,  109,  109,  109,  108,  404,  266,
 /*  1100 */   518,  119,  119,  518, 1293,  141,  141,  518,  111,  111,
 /*  1110 */   111,  111,  110,  110,  109,  109,  109,  108,  404,  518,
 /*  1120 */   801,  140,  140,  518,  127,  127,  511,  379,  126,  126,
 /*  1130 */   518,  137,  518, 1308,  518,  307,  518,  310,  518,  203,
 /*  1140 */   124,  124, 1307,   96,  125,  125,  207,  388, 1441,  468,
 /*  1150 */  1127,   69,   69,   71,   71,   68,   68,   38,   38,   42,
 /*  1160 */    42,  357, 1042,  373, 1293,  276,  509,  801,  185,  469,
 /*  1170 */   494,  436,  444,    6,  380,  156,  253,  197,  469,  134,
 /*  1180 */   426,   33, 1038,  373, 1121,  359, 1411,  114,  115,  105,
 /*  1190 */  1106, 1106,  957,  960,  950,  950,  112,  112,  113,  113,
 /*  1200 */   113,  113,  914,  296,   27,  293,   90,  114,  103,  105,
 /*  1210 */  1106, 1106,  957,  960,  950,  950,  112,  112,  113,  113,
 /*  1220 */   113,  113,  919,  275,  430,  232,  891,  232,  432,  256,
 /*  1230 */  1127,  232,  398,  370,  892,   28,  111,  111,  111,  111,
 /*  1070 */    51,   51,  535,   67,   67,   68,   68,   52,   52,  147,
 /*  1080 */   147,  148,  148, 1453,  317,   98,    6,  535, 1245,  481,
 /*  1090 */   535,  827,  535,   75,   75, 1134,  102,  481,  100,  535,
 /*  1100 */   532,  535,  368, 1066, 1503,  384,  535,  845,   53,   53,
 /*  1110 */    93,   71,   71,  126,  126,  295,  528,  390,  288,  526,
 /*  1120 */    72,   72,  127,  127,  139,  384,   38,  128,  128,  119,
 /*  1130 */   120,  110, 1136, 1136,  981,  984,  974,  974,  117,  117,
 /*  1140 */   118,  118,  118,  118,  535,  495,  535,  447,  535,  119,
 /*  1150 */   120,  110, 1136, 1136,  981,  984,  974,  974,  117,  117,
 /*  1160 */   118,  118,  118,  118,  235,  124,  124,  146,  146,  145,
 /*  1170 */   145,  287,  535, 1277,  535, 1157,  535,  391,  161,  263,
 /*  1180 */   206,  381,  116,  116,  116,  116,  115,  115,  114,  114,
 /*  1190 */   114,  113,  415,  132,  132,  131,  131,  129,  129,  535,
 /*  1200 */    30,  535,  116,  116,  116,  116,  115,  115,  114,  114,
 /*  1210 */   114,  113,  415,  535,  216, 1062, 1276,  535,  370,  535,
 /*  1220 */   130,  130,   74,   74,  535,  915,  389,  876,   17,  437,
 /*  1230 */   429,   31,  875,  916,   76,   76,  266,  101,   73,   73,
 /*  1240 */    43,   43,  835,  834,  308,   47,   47,   95,  825,  943,
 /*  1250 */   441,  938,  241,  241,  305,  443,  313,  384,  241,   95,
 /*  1260 */   842,  843,  193,  465, 1209,  327,  237,  436,   95, 1011,
 /*  1270 */  1007,  909,  873,  237,  241,  107, 1023,  384, 1023,  955,
 /*  1280 */  1415,  119,  120,  110, 1136, 1136,  981,  984,  974,  974,
 /*  1290 */   117,  117,  118,  118,  118,  118, 1022,  809, 1022,  825,
 /*  1300 */   137,  119,  108,  110, 1136, 1136,  981,  984,  974,  974,
 /*  1310 */   117,  117,  118,  118,  118,  118,  874, 1414,  451,  107,
 /*  1320 */  1011,  314, 1273,  318,  218,  321,  323,  325, 1224, 1208,
 /*  1330 */   955,  330,  339,  340,  116,  116,  116,  116,  115,  115,
 /*  1240 */   110,  110,  109,  109,  109,  108,  404,  301,  454, 1385,
 /*  1250 */    90,  228,  209,  987,  811,  810,  111,  111,  111,  111,
 /*  1260 */   110,  110,  109,  109,  109,  108,  404,  315,  818,  819,
 /*  1270 */    90,  323,  983,  931,  885,  228,  373,  232,  999,  849,
 /*  1280 */   999,  322,  102,  998, 1384,  998,  785,  850,  440,  132,
 /*  1290 */   102,  302, 1243,  306,  309,  311,  373,  313, 1194, 1180,
 /*  1300 */   987,  115,  105, 1106, 1106,  957,  960,  950,  950,  112,
 /*  1310 */   112,  113,  113,  113,  113, 1178, 1179,  318,  327,  328,
 /*  1320 */   931, 1255,  105, 1106, 1106,  957,  960,  950,  950,  112,
 /*  1330 */   112,  113,  113,  113,  113, 1292, 1230, 1457,  273, 1241,
 /*  1340 */   504,  505, 1298,  100,  510,  246,    4, 1161, 1154,  111,
 /*  1350 */   111,  111,  111,  110,  110,  109,  109,  109,  108,  404,
 /*  1360 */   513, 1143,  187, 1142,  202, 1144, 1451,  356, 1227,  111,
 /*  1370 */   111,  111,  111,  110,  110,  109,  109,  109,  108,  404,
 /*  1380 */    11, 1277,  330,  405,  332,  334,  191, 1285,  364,  195,
 /*  1390 */   295,  417,  288,  100,  510,  507,    4,  434,  459,  321,
 /*  1400 */  1177,  349, 1357, 1356,  336,  155,  190, 1454, 1121,  158,
 /*  1410 */   513,  508,  235, 1404,  937, 1402, 1118,  381,   77,  428,
 /*  1420 */    98,   98,    8, 1282,  168,   30,  152,   99,  160,  405,
 /*  1430 */   520,  519,   88,  405,  927, 1362, 1274,  420,  163,   73,
 /*  1440 */   164,   76,  165,  166,  421,  507,  452,  212,  361,  363,
 /*  1450 */   427,  276,  509,   31, 1288,  172,  491,  441,  216, 1351,
 /*  1460 */    82,  490,  447, 1373,  937,  927,  927,  929,  930,   24,
 /*  1470 */    98,   98,  304,  247,  218,  177,  308,   99,  219,  405,
 /*  1480 */   520,  519,  450, 1145,  927,  220,  366, 1197,  100,  510,
 /*  1340 */   114,  114,  114,  113,  415, 1285, 1322, 1260, 1493, 1470,
 /*  1350 */  1271,  283,  521, 1328,  116,  116,  116,  116,  115,  115,
 /*  1360 */   114,  114,  114,  113,  415, 1191, 1184, 1173, 1172, 1174,
 /*  1370 */   522, 1487,  211,  460,  384,  256,  199,  367, 1257,  342,
 /*  1380 */   195,  470,  307,  344,   11,  333,  525,  445, 1307, 1315,
 /*  1390 */   375,  203, 1207, 1151,  384,  346, 1387,  188,  360,  120,
 /*  1400 */   110, 1136, 1136,  981,  984,  974,  974,  117,  117,  118,
 /*  1410 */   118,  118,  118, 1386,  428, 1490,  245,  300,  348, 1148,
 /*  1420 */   110, 1136, 1136,  981,  984,  974,  974,  117,  117,  118,
 /*  1430 */   118,  118,  118,  189,  198, 1434, 1432,   78,   81,  163,
 /*  1440 */    82,  392,  439, 1392,  173,  105,  527,   35,    4,  157,
 /*  1450 */  1312,  116,  116,  116,  116,  115,  115,  114,  114,  114,
 /*  1460 */   113,  415,  530,  165,   93, 1304,  431,  432,  168,  463,
 /*  1470 */   221,  116,  116,  116,  116,  115,  115,  114,  114,  114,
 /*  1480 */   113,  415,  169,  452,  170,  416,  171,  374,  372,  438,
 /*  1490 */    36, 1318,  177,  225, 1381,   87,  458,  524, 1403,  316,
 /*  1500 */   257,  105,  527,  227,    4,  182,  461,  160,  320,  228,
 /*  1510 */   377, 1175,  476,  229, 1227, 1226,  405, 1225,  530, 1218,
 /*  1520 */   961,  378, 1199, 1198,  827,  332,  103,  103, 1197,  407,
 /*  1530 */     8, 1217, 1502,  104,  487,  416,  537,  536,  281,  282,
 /*  1540 */   951,  416,  490, 1268,  496,   92,  341,  243, 1269,  343,
 /*  1550 */   244, 1267,  122,  524,  345, 1461,  515,  288,  526,   10,
 /*  1560 */   354, 1266, 1460,  352,  504, 1250,   99, 1367,   94,  503,
 /*  1570 */   499,  951,  951,  953,  954,   27,  961,  347, 1249,  194,
 /*  1580 */   251,  358,  103,  103,  359, 1181,   34,  538, 1110,  104,
 /*  1590 */   255,  416,  537,  536,  286,  252,  951,  254,  539,  149,
 /*  1600 */  1170, 1419, 1165, 1420, 1418,  150, 1417,  135,  279,  785,
 /*  1490 */   465,    4, 1188, 1196, 1195,  394,  803, 1169, 1187,  367,
 /*  1500 */  1168,  396,  484,  320, 1167,  513, 1466,   87,  475,  100,
 /*  1510 */   510,  271,    4,  272,  478,  927,  927,  929,  930,   24,
 /*  1520 */  1443, 1074,  407, 1238, 1239,  258,  513,  329,  405,  331,
 /*  1530 */   355,  355,  354,  243,  352,  234,  489,  774,  498,  184,
 /*  1540 */   507,  338, 1422,  339,  117, 1220,   10,  341,  333,  405,
 /*  1550 */   204,  491,  282, 1219, 1237, 1236,  492,  335,  343,  937,
 /*  1560 */   281,  507,   94, 1337,  186,   98,   98,  347,   89,  487,
 /*  1570 */   348,  241,   99,   29,  405,  520,  519,  274, 1151,  927,
 /*  1580 */   937,  521, 1080,  245,  242,  244,   98,   98,  856,  522,
 /*  1590 */   206, 1140, 1135,   99,  144,  405,  520,  519,  147,  375,
 /*  1600 */   927,  149,  376,  157, 1389, 1390, 1388, 1387,  205,  145,
 /*  1610 */   927,  927,  929,  930,   24,  146,  130,  761, 1165, 1164,
 /*  1620 */    72,  100,  510, 1162,    4,  269,  406,  188,  278,  201,
 /*  1630 */   259,  927,  927,  929,  930,   24,  128,  911,  513,  997,
 /*  1640 */   995,  159,  374,  208,  148,  161,  835,  276,  509,  211,
 /*  1650 */   294, 1011,  915,  167,  150,  383,  169,   78,  385,   79,
 /*  1660 */    80,  405,   81,  151, 1014,  213,  214, 1010,  139,   18,
 /*  1670 */   412,  215,  303,  507,  232, 1115, 1003,  446,  173,  217,
 /*  1680 */   174,   32,  776,  451,  491,  322,  221,  175,  814,  490,
 /*  1690 */    83,  455,  937,   19,  460,  316,   20,   84,   98,   98,
 /*  1700 */   270,  182,   85,  467,  153,   99,  154,  405,  520,  519,
 /*  1710 */  1074,  407,  927,  183,  258,  963, 1046,   86,   34,  355,
 /*  1720 */   355,  354,  243,  352,  474, 1047,  774,   35,  477,  196,
 /*  1730 */   250,  100,  510,  252,    4,  884,  178,  231, 1060,  204,
 /*  1740 */    21,  282,  102,  927,  927,  929,  930,   24,  513,  281,
 /*  1610 */   151,  417, 1195,  196,  290,  210,  386, 1194,  269,  387,
 /*  1620 */   162, 1021,  133,   77, 1192, 1019,  935,  951,  951,  953,
 /*  1630 */   954,   27, 1479, 1104,  418,  164,  153,  268,  217,  166,
 /*  1640 */   859,  306,  366,  366,  365,  253,  363,  220, 1035,  798,
 /*  1650 */   172,  939,  105,  527,  155,    4,  394,  174,  396,  156,
 /*  1660 */    83, 1038,  213,   84,  294,   85,   86,  223,  222,  530,
 /*  1670 */  1034,  144,  293,   18,  224,  315,  241, 1027, 1145,  178,
 /*  1680 */   457,  226,  179,   37,  800,  334,  462,  230,  328,  466,
 /*  1690 */   180,  471,  416,   88,   19,   20,   89,  280,  838,  158,
 /*  1700 */   191,   90,  215,  478,  524, 1097,  204,  192,  987,   91,
 /*  1710 */   152, 1070,   39,  154, 1071,  504,  486,   40,  489,  205,
 /*  1720 */   505,  260,  105,  527,  214,    4,  908,  961,  262,  183,
 /*  1730 */   240,   21,  903,  103,  103,  107,   22, 1086,   23,  530,
 /*  1740 */   104, 1088,  416,  537,  536,   24, 1093,  951,   25, 1074,
 /*  1750 */  1090, 1094,    7,   33,  511,  186,   26, 1002,  385,   95,
 /*  1760 */   988,  986,  416,  288,  526,  990, 1044,  246, 1043,  247,
 /*  1770 */   991,   28,   41,  106,  524,  956,  810,   29,  951,  951,
 /*  1780 */   953,  954,   27,  531,  361,  504,  423,  248,  869,  249,
 /*  1790 */   503, 1495,  364, 1105, 1161, 1494, 1161,  961, 1161, 1161,
 /*  1800 */  1161, 1161, 1161,  103,  103, 1161, 1161, 1161, 1161, 1161,
 /*  1810 */   104, 1161,  416,  537,  536, 1104,  418,  951, 1161,  268,
 /*  1820 */  1161, 1161, 1161, 1161,  366,  366,  365,  253,  363, 1161,
 /*  1830 */  1161,  798, 1161, 1161, 1161, 1161,  105,  527, 1161,    4,
 /*  1840 */  1161, 1161, 1161, 1161,  213, 1161,  294, 1161,  951,  951,
 /*  1850 */   953,  954,   27,  530,  293, 1161, 1161, 1161, 1161, 1161,
 /*  1860 */  1161, 1161, 1161, 1161, 1161, 1161, 1161, 1161, 1161, 1161,
 /*  1870 */  1161, 1161, 1161, 1161, 1161, 1161,  416, 1161, 1161, 1161,
 /*  1750 */   879,   22, 1064, 1062, 1051,    7,  340,   23,  978,  179,
 /*  1760 */    90,   92,  510,  964,    4,  236,  962,  966, 1020, 1019,
 /*  1770 */   237,  405,  967,   25,   36,  514,  932,  786,  513,  206,
 /*  1780 */   101,   26,  845,  507,  238,  239, 1459,  147,  350, 1458,
 /*  1790 */   149,  353, 1075, 1131, 1131, 1131, 1131,  205, 1131, 1131,
 /*  1800 */  1131,  405,  937, 1131, 1131, 1131, 1131, 1131,   98,   98,
 /*  1810 */  1131, 1131, 1131,  507, 1131,   99, 1131,  405,  520,  519,
 /*  1820 */  1131, 1131,  927, 1131, 1131, 1131, 1131, 1131, 1131, 1131,
 /*  1830 */  1131,  374,  937, 1131, 1131, 1131,  276,  509,   98,   98,
 /*  1840 */  1131, 1131, 1131, 1131, 1131,   99, 1131,  405,  520,  519,
 /*  1850 */  1131, 1131,  927,  927,  927,  929,  930,   24, 1131,  412,
 /*  1860 */  1131, 1131, 1131,  258, 1131, 1131, 1131, 1131,  355,  355,
 /*  1870 */   354,  243,  352, 1131, 1131,  774, 1131, 1131, 1131, 1131,
 /*  1880 */  1131, 1131, 1131,  927,  927,  929,  930,   24,  204, 1131,
 /*  1890 */   282, 1131, 1131, 1131, 1131, 1131, 1131, 1131,  281, 1131,
 /*  1900 */  1131, 1131, 1131, 1131, 1131, 1131, 1131, 1131, 1131, 1131,
 /*  1910 */  1131, 1131, 1131, 1131, 1131, 1131, 1131, 1131, 1131, 1131,
 /*  1920 */  1131, 1131, 1131, 1131, 1131, 1131, 1131, 1131,  206, 1131,
 /*  1930 */  1131, 1131, 1131, 1131, 1131, 1131,  147, 1131, 1131,  149,
 /*  1940 */  1131, 1131, 1131, 1131, 1131, 1131,  205, 1131, 1131, 1131,
 /*  1950 */  1131, 1131, 1131, 1131, 1131, 1131, 1131, 1131, 1131, 1131,
 /*  1960 */  1131, 1131, 1131, 1131, 1131, 1131, 1131, 1131, 1131, 1131,
 /*  1970 */  1131, 1131, 1131, 1131, 1131, 1131, 1131, 1131, 1131, 1131,
 /*  1980 */   374, 1131, 1131, 1131, 1131,  276,  509, 1131, 1131, 1131,
 /*  1990 */  1131, 1131, 1131, 1131, 1131, 1131, 1131, 1131, 1131, 1131,
 /*  2000 */  1131, 1131, 1131, 1131, 1131, 1131, 1131, 1131,  412,
 /*  1880 */  1161, 1161, 1161, 1161,  215, 1161, 1161, 1161,  524, 1161,
 /*  1890 */  1161, 1161,  152, 1161, 1161,  154,  105,  527, 1161,    4,
 /*  1900 */  1161, 1161, 1161, 1161, 1161, 1161,  214, 1161, 1161, 1161,
 /*  1910 */  1161,  961, 1161,  530, 1161, 1161, 1161,  103,  103,  880,
 /*  1920 */  1161, 1161, 1161, 1161,  104, 1161,  416,  537,  536, 1161,
 /*  1930 */  1161,  951, 1161, 1161, 1161, 1161,  416, 1161, 1161, 1161,
 /*  1940 */   385, 1161, 1161, 1161, 1161,  288,  526, 1161,  524, 1161,
 /*  1950 */  1161, 1161, 1161, 1161, 1161, 1161,   97,  527, 1161,    4,
 /*  1960 */  1161, 1161,  951,  951,  953,  954,   27, 1161,  423, 1161,
 /*  1970 */  1161,  961, 1161,  530, 1161, 1161, 1161,  103,  103, 1161,
 /*  1980 */  1161, 1161, 1161, 1161,  104, 1161,  416,  537,  536, 1161,
 /*  1990 */  1161,  951,  268, 1161, 1161, 1161,  416,  366,  366,  365,
 /*  2000 */   253,  363, 1161, 1161,  798, 1161, 1161, 1161,  524, 1161,
 /*  2010 */  1161, 1161, 1161, 1161, 1161, 1161, 1161,  213, 1161,  294,
 /*  2020 */  1161, 1161,  951,  951,  953,  954,   27,  293, 1161, 1161,
 /*  2030 */  1161,  961, 1161, 1161, 1161, 1161, 1161,  103,  103, 1161,
 /*  2040 */  1161, 1161, 1161, 1161,  104, 1161,  416,  537,  536, 1161,
 /*  2050 */  1161,  951, 1161, 1161, 1161, 1161, 1161,  215, 1161, 1161,
 /*  2060 */  1161, 1161, 1161, 1161, 1161,  152, 1161, 1161,  154, 1161,
 /*  2070 */  1161, 1161, 1161, 1161, 1161, 1161, 1161, 1161, 1161,  214,
 /*  2080 */  1161, 1161,  951,  951,  953,  954,   27, 1161, 1161, 1161,
 /*  2090 */  1161, 1161, 1161, 1161, 1161, 1161, 1161, 1161, 1161, 1161,
 /*  2100 */  1161, 1161, 1161, 1161, 1161, 1161, 1161, 1161, 1161, 1161,
 /*  2110 */  1161, 1161, 1161,  385, 1161, 1161, 1161, 1161,  288,  526,
 /*  2120 */  1161, 1161, 1161, 1161, 1161, 1161, 1161, 1161, 1161, 1161,
 /*  2130 */  1161, 1161, 1161, 1161, 1161, 1161, 1161, 1161, 1161, 1161,
 /*  2140 */  1161,  423,
};
static const YYCODETYPE yy_lookahead[] = {
 /*     0 */   168,  163,  184,  238,  239,  240,  163,  163,  155,  156,
 /*    10 */   157,  158,  159,  160,  163,  202,  203,  187,  165,   19,
 /*    20 */   167,  163,  184,  185,  259,  202,  203,  174,  184,  185,
 /*    30 */   174,   31,  238,  239,  240,  184,  185,   22,   23,   39,
 /*    40 */   216,   26,  218,   43,   44,   45,   46,   47,   48,   49,
 /*    50 */    50,   51,   52,   53,   54,   55,   56,   57,  174,  206,
 /*    60 */   207,  163,  206,  207,  220,  163,  163,  163,  238,  239,
 /*    70 */   240,   59,  219,  229,  231,  219,  183,  245,  174,  223,
 /*    80 */   224,  249,  184,  185,  191,  232,  184,  185,  184,  185,
 /*    90 */   206,  207,   92,   93,   94,   95,   96,   97,   98,   99,
 /*   100 */   100,  101,  102,  219,  102,   81,   91,  163,   96,   97,
 /*   110 */   206,  207,   19,  275,  276,  262,  104,  105,  106,  107,
 /*   120 */   163,  109,  220,  219,  220,  184,  275,  269,  277,  117,
 /*   130 */   187,  229,   19,  229,  101,  102,   43,   44,   45,   46,
 /*   140 */    47,   48,   49,   50,   51,   52,   53,   54,   55,   56,
 /*   150 */    57,  127,  128,  141,  184,  143,   43,   44,   45,   46,
 /*   160 */    47,   48,   49,   50,   51,   52,   53,   54,   55,   56,
 /*   170 */    57,  268,  269,  275,  276,  197,   83,  233,   85,  163,
 /*   180 */    67,  238,  239,  240,  134,   92,   93,   94,   95,   96,
 /*   190 */    97,   98,   99,  100,  101,  102,   19,   54,   55,   56,
 /*   200 */    57,   58,  152,   26,  247,   92,   93,   94,   95,   96,
 /*   210 */    97,   98,   99,  100,  101,  102,   54,   55,   56,   57,
 /*   220 */    43,   44,   45,   46,   47,   48,   49,   50,   51,   52,
 /*     0 */   184,  184,  259,  260,  261,  259,  260,  261,  176,  177,
 /*    10 */   178,  179,  180,  181,  184,  208,  212,  213,  186,   19,
 /*    20 */   188,  205,  206,  280,  205,  221,   22,  195,   24,  195,
 /*    30 */   208,   31,  195,  205,   29,  205,  206,  255,   33,   39,
 /*    40 */   200,  201,  202,   43,   44,   45,   46,   47,   48,   49,
 /*    50 */    50,   51,   52,   53,   54,   55,   56,   57,  205,  227,
 /*    60 */   228,  227,  228,   59,  227,  228,  259,  260,  261,  252,
 /*    70 */    65,  241,  240,  184,  240,  223,  224,  240,  244,  245,
 /*    80 */   250,  259,  260,  261,   19,  253,   54,   55,   56,   57,
 /*    90 */    58,  184,  255,  184,  205,  206,   96,   97,   98,   99,
 /*   100 */   100,  101,  102,  103,  104,  105,  106,   46,   47,   48,
 /*   110 */    49,   46,  296,  297,  110,  283,   19,   96,   97,   98,
 /*   120 */    99,  100,  101,  102,  103,  104,  105,  106,   96,   97,
 /*   130 */    98,   99,  100,  101,  102,  103,  104,  105,  106,   94,
 /*   140 */    43,   44,   45,   46,   47,   48,   49,   50,   51,   52,
 /*   150 */    53,   54,   55,   56,   57,  110,  106,   73,  251,  114,
 /*   160 */    73,  178,  179,  180,  181,   59,  184,  292,   81,  186,
 /*   170 */   295,  188,  218,  108,   19,  114,  184,   11,  195,  184,
 /*   180 */    83,  184,   85,   54,   55,   56,   57,  205,  206,  124,
 /*   190 */   145,  146,  147,   96,   97,   98,   99,  100,  101,  102,
 /*   200 */   103,  104,  105,  106,  120,  121,  122,  120,  102,   81,
 /*   210 */   227,  228,  220,   19,   16,  109,  110,  111,  131,  132,
 /*   220 */    26,  184,  184,  240,  229,   96,   97,   98,   99,  100,
 /*   230 */   101,  102,  103,  104,  105,  106,  253,   43,   44,   45,
 /*   240 */    46,   47,   48,   49,   50,   51,   52,   53,   54,   55,
 /*   230 */    53,   54,   55,   56,   57,   92,   93,   94,   95,   96,
 /*   240 */    97,   98,   99,  100,  101,  102,   69,   96,   97,   98,
 /*   250 */    56,   57,  100,  101,  102,  103,  104,  105,  106,  131,
 /*   250 */    99,  100,  101,  102,   92,   93,   94,   95,   96,   97,
 /*   260 */    98,   99,  100,  101,  102,   73,  179,  180,  181,   92,
 /*   270 */    93,   94,   95,   96,   97,   98,   99,  100,  101,  102,
 /*   280 */   163,  191,  192,  163,   98,   99,  100,  101,  102,   19,
 /*   260 */   132,  106,  127,   69,  129,  130,  283,  112,  113,  114,
 /*   270 */   115,  116,  117,  118,   81,   77,   76,   79,  296,  124,
 /*   280 */   298,  203,  184,   19,   84,   59,   86,  121,  122,   89,
 /*   290 */   200,  179,  180,  181,   24,  175,   92,   93,   94,   95,
 /*   300 */    96,   97,   98,   99,  100,  101,  102,  163,  116,  117,
 /*   310 */   118,   22,  163,   43,   44,   45,   46,   47,   48,   49,
 /*   320 */    50,   51,   52,   53,   54,   55,   56,   57,  157,  158,
 /*   330 */   159,  160,  163,  184,  185,  163,  165,   59,  167,   46,
 /*   340 */    90,   76,   11,  174,   73,  174,   19,  198,   59,   19,
 /*   350 */    72,   86,   81,  184,  185,  234,  106,   96,   97,  163,
 /*   360 */   110,  182,   92,   93,   94,   95,   96,   97,   98,   99,
 /*   370 */   100,  101,  102,   46,  230,  206,  207,  206,  207,  163,
 /*   380 */   184,  185,   19,  105,  106,  107,   23,  116,  219,  220,
 /*   390 */   219,  141,  142,  143,  105,  106,  107,  104,  127,  128,
 /*   400 */   184,  185,  141,  232,  143,   59,   43,   44,   45,   46,
 /*   410 */    47,   48,   49,   50,   51,   52,   53,   54,   55,   56,
 /*   420 */    57,  158,  108,  160,   59,  111,  112,  113,  165,  250,
 /*   430 */   167,  104,  102,  262,  255,  121,  220,  174,  108,  109,
 /*   440 */   110,  111,  112,  113,  114,  229,  182,  120,  117,  118,
 /*   450 */   120,  105,  106,  107,  163,   92,   93,   94,   95,   96,
 /*   460 */    97,   98,   99,  100,  101,  102,  163,   22,   59,  206,
 /*   470 */   207,  106,  163,   26,  171,   19,  163,  193,  175,   23,
 /*   480 */   163,   22,  219,  206,  207,  139,  163,   22,   59,  182,
 /*   490 */   117,  118,   59,  184,  185,  232,  219,  184,  185,   43,
 /*   500 */    44,   45,   46,   47,   48,   49,   50,   51,   52,   53,
 /*   510 */    54,   55,   56,   57,  105,  106,  107,  108,   59,  255,
 /*   520 */   111,  112,  113,   90,   59,  262,   22,   98,  174,   12,
 /*   530 */   121,  208,  163,  220,  105,  106,  107,  163,  105,  106,
 /*   540 */    22,   96,   97,  110,   27,  238,  239,  240,   92,   93,
 /*   550 */    94,   95,   96,   97,   98,   99,  100,  101,  102,   42,
 /*   560 */   206,  207,  115,   59,  105,  106,  107,  163,   19,   59,
 /*   290 */    96,   97,   98,   99,  100,  101,  102,  103,  104,  105,
 /*   300 */   106,  184,   35,  205,  206,   22,  113,   43,   44,   45,
 /*   310 */    46,   47,   48,   49,   50,   51,   52,   53,   54,   55,
 /*   320 */    56,   57,  205,  206,  131,  132,  100,  101,  291,  292,
 /*   330 */   114,   67,  295,   66,  108,  109,  110,  111,  138,  113,
 /*   340 */   124,   74,   59,  179,  184,  181,  184,  121,   22,  271,
 /*   350 */   186,   19,  188,  184,  276,   59,   24,  184,  241,  195,
 /*   360 */    96,   97,   98,   99,  100,  101,  102,  103,  104,  105,
 /*   370 */   106,  145,   59,  147,  184,   43,   44,   45,   46,   47,
 /*   380 */    48,   49,   50,   51,   52,   53,   54,   55,   56,   57,
 /*   390 */   123,  227,  228,  110,  296,  297,   22,   23,  184,  102,
 /*   400 */   103,  104,  105,  106,  240,  109,  110,  111,  112,  195,
 /*   410 */   204,  115,  116,  117,   22,  184,  226,  253,  212,  205,
 /*   420 */   206,  125,  109,  110,  111,   22,  100,  101,   96,   97,
 /*   430 */    98,   99,  100,  101,  102,  103,  104,  105,  106,  184,
 /*   440 */    59,  227,  228,  121,  122,   59,  277,  283,   19,  289,
 /*   450 */   290,   59,   23,   76,  240,  241,  143,   76,   72,  189,
 /*   460 */   205,  206,   59,   86,  250,   84,   89,   86,  203,   95,
 /*   470 */    89,  281,   43,   44,   45,   46,   47,   48,   49,   50,
 /*   480 */    51,   52,   53,   54,   55,   56,   57,  227,  228,  184,
 /*   490 */   109,  110,  111,   12,  184,  109,  110,  111,  184,  184,
 /*   500 */   240,  109,  110,  111,  184,  195,  214,   59,   27,  184,
 /*   510 */   205,  206,  109,  110,  111,  205,  206,  184,  263,  138,
 /*   520 */   205,  206,  184,   42,   22,   96,   97,   98,   99,  100,
 /*   530 */   101,  102,  103,  104,  105,  106,  266,  227,  228,   59,
 /*   540 */   270,  276,   94,   66,   63,   19,  241,   22,   26,   23,
 /*   550 */   240,  241,   72,   59,   73,  250,  241,  109,  110,   82,
 /*   560 */    22,   59,  114,  223,  224,  250,  252,   59,   91,   43,
 /*   570 */   163,  106,   23,  219,  141,  142,  143,   59,  163,  205,
 /*   580 */    63,   59,   72,   22,  124,   59,  163,  270,  234,  129,
 /*   590 */    73,  163,   43,   44,   45,   46,   47,   48,   49,   50,
 /*   600 */    51,   52,   53,   54,   55,   56,   57,  184,  185,  105,
 /*   610 */   106,  107,  184,  185,  163,  105,  106,  107,  265,  266,
 /*   620 */    59,  198,  225,  105,  106,  107,  198,  105,  106,  107,
 /*   630 */   163,  105,  106,  107,  163,  184,  185,   46,   47,   48,
 /*   640 */    49,   92,   93,   94,   95,   96,   97,   98,   99,  100,
 /*   650 */   101,  102,  163,  163,  132,  184,  185,  163,  132,  163,
 /*   660 */   256,   19,  163,  163,  163,   23,  105,  106,  107,  198,
 /*   570 */    44,   45,   46,   47,   48,   49,   50,   51,   52,   53,
 /*   580 */    54,   55,   56,   57,   59,  184,   26,   59,  268,  109,
 /*   590 */   110,  111,  184,  145,  146,  147,  112,   59,  203,  115,
 /*   600 */   116,  117,  277,  109,  110,  111,  205,  206,  195,  125,
 /*   610 */   277,  109,  110,  111,  100,  101,  139,  109,  110,  111,
 /*   620 */   219,  184,   96,   97,   98,   99,  100,  101,  102,  103,
 /*   630 */   104,  105,  106,  111,  109,  110,  111,  109,  110,  111,
 /*   640 */   227,  228,   19,  184,  136,  184,   23,  109,  110,  111,
 /*   650 */   200,  201,  202,  240,  259,  260,  261,  195,  136,  145,
 /*   660 */   184,  147,  184,  184,  136,  214,   43,   44,   45,   46,
 /*   670 */   163,  220,  205,  184,  185,  163,   35,   81,  184,  185,
 /*   680 */   184,  185,  163,  184,  185,   43,   44,   45,   46,   47,
 /*   690 */    48,   49,   50,   51,   52,   53,   54,   55,   56,   57,
 /*   700 */   163,  110,  163,  184,  185,  109,  205,   66,  163,   59,
 /*   710 */   163,   21,  205,   16,  174,   74,  220,  198,  163,  220,
 /*   720 */   230,  184,  185,  127,  128,  180,  181,  180,  181,  163,
 /*   730 */   175,  242,  174,  233,   92,   93,   94,   95,   96,   97,
 /*   740 */    98,   99,  100,  101,  102,  233,  206,  207,   26,  163,
 /*   750 */   195,  207,  197,   26,   19,  105,  106,  107,   23,  219,
 /*   760 */   119,  260,   26,  219,  206,  207,  174,   19,  174,  230,
 /*   770 */    80,  174,  163,  174,   77,  163,   79,  219,   43,   44,
 /*   780 */    45,   46,   47,   48,   49,   50,   51,   52,   53,   54,
 /*   790 */    55,   56,   57,  248,   12,  248,  184,  185,  206,  207,
 /*   800 */   206,  207,  112,  206,  207,  206,  207,  206,  207,   27,
 /*   670 */    47,   48,   49,   50,   51,   52,   53,   54,   55,   56,
 /*   680 */    57,  205,  206,  205,  206,  227,  228,  184,  229,  227,
 /*   690 */   228,  131,  132,  184,   59,  219,  184,  219,  240,  291,
 /*   700 */   292,  184,  240,  295,  105,  106,   22,   23,  205,  206,
 /*   710 */    26,  184,  251,  184,  205,  206,  184,  205,  206,   96,
 /*   720 */    97,   98,   99,  100,  101,  102,  103,  104,  105,  106,
 /*   730 */   251,  219,  205,  206,  205,  206,  184,  205,  206,   19,
 /*   740 */   184,   16,  184,   23,  241,  110,  219,   21,  219,  184,
 /*   750 */   241,  219,  286,  287,  195,  184,  195,  205,  206,  201,
 /*   760 */   202,  205,  206,   43,   44,   45,   46,   47,   48,   49,
 /*   770 */    50,   51,   52,   53,   54,   55,   56,   57,  184,   95,
 /*   780 */    22,   23,  184,   26,   26,  220,  227,  228,  227,  228,
 /*   790 */   196,  184,   23,  241,   26,   26,  195,  241,  184,  240,
 /*   800 */    12,  240,   77,   26,   79,  195,   80,  290,  201,  202,
 /*   810 */   163,  219,  123,  219,  125,  126,  219,  208,  219,  163,
 /*   820 */   219,   22,   23,   23,   42,   26,   26,   92,   93,   94,
 /*   830 */    95,   96,   97,   98,   99,  100,  101,  102,  163,  149,
 /*   840 */   184,  185,  163,  107,  163,   63,  149,   19,  163,  127,
 /*   850 */   128,   23,   22,  105,   24,  116,  117,  118,  131,  184,
 /*   810 */   216,  184,  218,  195,  184,   27,   96,   97,   98,   99,
 /*   820 */   100,  101,  102,  103,  104,  105,  106,  269,  227,  228,
 /*   830 */    42,  184,  205,  206,  184,  184,   19,  227,  228,  192,
 /*   840 */    23,  240,  116,  196,   76,  227,  228,  120,  121,  122,
 /*   850 */   240,   63,  254,   95,   86,  205,  206,   89,  240,  184,
 /*   860 */   185,  163,  163,  184,  185,  184,  185,   19,  132,  184,
 /*   870 */   185,   43,   44,   45,   46,   47,   48,   49,   50,   51,
 /*   880 */    52,   53,   54,   55,   56,   57,  146,  163,  148,   59,
 /*   890 */    91,   43,   44,   45,   46,   47,   48,   49,   50,   51,
 /*   900 */    52,   53,   54,   55,   56,   57,  208,  107,  184,  185,
 /*   860 */    43,   44,   45,   46,   47,   48,   49,   50,   51,   52,
 /*   870 */    53,   54,   55,   56,   57,  184,  269,  184,  153,  153,
 /*   880 */   111,  184,    7,    8,    9,  184,  138,  184,  184,  196,
 /*   890 */   184,  120,  121,  122,  184,  138,  205,  206,  184,  102,
 /*   900 */   184,  184,  205,  206,  156,  136,  205,  206,  205,  206,
 /*   910 */     7,    8,    9,  116,  117,  118,  163,  163,  163,   24,
 /*   920 */    92,   93,   94,   95,   96,   97,   98,   99,  100,  101,
 /*   930 */   102,   29,  132,  163,  163,   33,  106,  184,  185,  163,
 /*   940 */    92,   93,   94,   95,   96,   97,   98,   99,  100,  101,
 /*   950 */   102,  163,  163,  163,   59,  184,  185,  163,   22,  163,
 /*   960 */   184,  185,  177,  178,  163,  163,  163,   65,  163,  199,
 /*   970 */   163,   26,  184,  185,  184,  185,  163,  163,  184,  185,
 /*   980 */   184,  185,  163,   98,  163,  184,  185,  184,  185,  184,
 /*   990 */   185,  184,  185,  252,  205,  147,  163,   61,  184,  185,
 /*  1000 */   163,  106,  163,  184,  185,  163,  163,  205,  163,  124,
 /*  1010 */   163,  256,  163,  163,  129,   19,  163,  184,  185,  163,
 /*  1020 */   199,  184,  185,  184,  185,   23,  184,  185,   26,  184,
 /*  1030 */   185,  184,  185,  184,  185,   19,  163,  184,  185,   43,
 /*  1040 */    44,   45,   46,   47,   48,   49,   50,   51,   52,   53,
 /*  1050 */    54,   55,   56,   57,  163,  163,  163,  184,  185,   43,
 /*  1060 */    44,   45,   46,   47,   48,   49,   50,   51,   52,   53,
 /*  1070 */    54,   55,   56,   57,   16,  184,  185,  184,  185,  163,
 /*  1080 */   163,   22,   23,  138,  163,   19,  163,  231,   92,   93,
 /*  1090 */    94,   95,   96,   97,   98,   99,  100,  101,  102,  256,
 /*  1100 */   163,  184,  185,  163,  163,  184,  185,  163,   92,   93,
 /*  1110 */    94,   95,   96,   97,   98,   99,  100,  101,  102,  163,
 /*  1120 */    59,  184,  185,  163,  184,  185,  177,  178,  184,  185,
 /*  1130 */   163,  208,  163,  237,  163,   77,  163,   79,  163,   15,
 /*  1140 */   184,  185,  237,  147,  184,  185,   24,  231,  153,  154,
 /*  1150 */    91,  184,  185,  184,  185,  184,  185,  184,  185,  184,
 /*  1160 */   185,   22,   23,   19,  163,  127,  128,  106,   24,  273,
 /*  1170 */   271,  105,  231,  274,  263,  264,  223,  224,  273,   22,
 /*  1180 */   118,   24,   23,   19,   60,   26,  163,   43,   44,   45,
 /*  1190 */    46,   47,   48,   49,   50,   51,   52,   53,   54,   55,
 /*  1200 */    56,   57,  140,   23,   22,  163,   26,   43,   44,   45,
 /*  1210 */    46,   47,   48,   49,   50,   51,   52,   53,   54,   55,
 /*  1220 */    56,   57,   23,  211,   23,   26,   31,   26,   23,   22,
 /*  1230 */    91,   26,  231,  221,   39,   53,   92,   93,   94,   95,
 /*  1240 */    96,   97,   98,   99,  100,  101,  102,   23,   23,  163,
 /*  1250 */    26,   26,  130,   59,  109,  110,   92,   93,   94,   95,
 /*  1260 */    96,   97,   98,   99,  100,  101,  102,   23,    7,    8,
 /*  1270 */    26,  110,   23,   59,   23,   26,   19,   26,  141,   23,
 /*  1280 */   143,  120,   26,  141,  163,  143,   23,   23,  163,   26,
 /*  1290 */    26,  163,  163,  163,  163,  163,   19,  163,  163,  193,
 /*  1300 */   106,   44,   45,   46,   47,   48,   49,   50,   51,   52,
 /*  1310 */    53,   54,   55,   56,   57,  163,  193,  163,  163,  163,
 /*  1320 */   106,  163,   45,   46,   47,   48,   49,   50,   51,   52,
 /*  1330 */    53,   54,   55,   56,   57,  163,  163,  130,  222,  163,
 /*  1340 */   163,  203,  163,   19,   20,  251,   22,  163,  163,   92,
 /*  1350 */    93,   94,   95,   96,   97,   98,   99,  100,  101,  102,
 /*  1360 */    36,  163,  209,  163,  261,  163,  163,  161,  222,   92,
 /*  1370 */    93,   94,   95,   96,   97,   98,   99,  100,  101,  102,
 /*  1380 */   210,  213,  222,   59,  222,  222,  182,  213,  213,  196,
 /*  1390 */   257,  226,  226,   19,   20,   71,   22,  257,  188,  187,
 /*  1400 */   192,  212,  187,  187,  226,   81,  210,  166,   60,  261,
 /*   910 */   198,  199,  135,   96,   97,   98,   99,  100,  101,  102,
 /*   920 */   103,  104,  105,  106,  184,  128,  184,  184,  184,  254,
 /*   930 */   133,  184,  237,   19,  239,  229,  226,   23,  292,  184,
 /*   940 */   226,  295,  226,  226,  184,  205,  206,  205,  206,  205,
 /*   950 */   206,  184,  292,   19,  184,  295,  252,   43,   44,   45,
 /*   960 */    46,   47,   48,   49,   50,   51,   52,   53,   54,   55,
 /*   970 */    56,   57,  205,  206,  184,  205,  206,   43,   44,   45,
 /*   980 */    46,   47,   48,   49,   50,   51,   52,   53,   54,   55,
 /*   990 */    56,   57,  157,  158,   26,  205,  206,  254,   26,  252,
 /*  1000 */   184,   15,  184,  184,  184,  292,  184,  252,  295,   24,
 /*  1010 */    96,   97,   98,   99,  100,  101,  102,  103,  104,  105,
 /*  1020 */   106,  205,  206,  205,  206,  205,  206,  205,  206,  184,
 /*  1030 */    96,   97,   98,   99,  100,  101,  102,  103,  104,  105,
 /*  1040 */   106,  184,  184,  184,   59,  184,   60,  184,  229,  184,
 /*  1050 */   205,  206,  184,  258,  184,   19,  184,   19,  184,  246,
 /*  1060 */   184,  258,  205,  206,  205,  206,  205,  206,  205,  206,
 /*  1070 */   205,  206,  184,  205,  206,  205,  206,  205,  206,  205,
 /*  1080 */   206,  205,  206,  292,  226,  151,  295,  184,  228,  294,
 /*  1090 */   184,  119,  184,  205,  206,  110,  150,  294,  152,  184,
 /*  1100 */   240,  184,   22,   23,   23,   19,  184,   26,  205,  206,
 /*  1110 */   142,  205,  206,  205,  206,  184,  198,  199,  131,  132,
 /*  1120 */   205,  206,  205,  206,   22,   19,   24,  205,  206,   43,
 /*  1130 */    44,   45,   46,   47,   48,   49,   50,   51,   52,   53,
 /*  1140 */    54,   55,   56,   57,  184,  109,  184,  109,  184,   43,
 /*  1150 */    44,   45,   46,   47,   48,   49,   50,   51,   52,   53,
 /*  1160 */    54,   55,   56,   57,   46,  205,  206,  205,  206,  205,
 /*  1170 */   206,  232,  184,  184,  184,   95,  184,  284,  285,  244,
 /*  1180 */   245,  242,   96,   97,   98,   99,  100,  101,  102,  103,
 /*  1190 */   104,  105,  106,  205,  206,  205,  206,  205,  206,  184,
 /*  1200 */    22,  184,   96,   97,   98,   99,  100,  101,  102,  103,
 /*  1210 */   104,  105,  106,  184,   24,   23,  184,  184,   26,  184,
 /*  1220 */   205,  206,  205,  206,  184,   31,  108,  128,   22,  122,
 /*  1230 */   184,   53,  133,   39,  205,  206,   22,  151,  205,  206,
 /*  1240 */   205,  206,  113,  114,   23,  205,  206,   26,   59,   23,
 /*  1250 */    23,  144,   26,   26,  184,   23,   23,   19,   26,   26,
 /*  1260 */     7,    8,   24,   23,  214,   23,   26,   61,   26,   59,
 /*  1270 */    23,   23,   23,   26,   26,   26,  145,   19,  147,   59,
 /*  1280 */   184,   43,   44,   45,   46,   47,   48,   49,   50,   51,
 /*  1290 */    52,   53,   54,   55,   56,   57,  145,   23,  147,  110,
 /*  1300 */    26,   43,   44,   45,   46,   47,   48,   49,   50,   51,
 /*  1310 */    52,   53,   54,   55,   56,   57,   23,  184,  184,   26,
 /*  1320 */   110,  184,  184,  184,  134,  184,  184,  184,  184,  184,
 /*  1330 */   110,  184,  184,  184,   96,   97,   98,   99,  100,  101,
 /*  1340 */   102,  103,  104,  105,  106,  184,  184,  184,  134,  300,
 /*  1350 */   184,  243,  184,  184,   96,   97,   98,   99,  100,  101,
 /*  1360 */   102,  103,  104,  105,  106,  184,  184,  184,  184,  184,
 /*  1370 */   224,  184,  282,  273,   19,  272,  203,  182,  243,  243,
 /*  1380 */   230,  209,  278,  243,  231,  208,  265,  278,  234,  234,
 /*  1390 */   234,  217,  213,   60,   19,  243,  208,  237,  233,   44,
 /*  1400 */    45,   46,   47,   48,   49,   50,   51,   52,   53,   54,
 /*  1410 */    55,   56,   57,  208,  247,  187,  134,  247,  247,   38,
 /*  1420 */    45,   46,   47,   48,   49,   50,   51,   52,   53,   54,
 /*  1430 */    55,   56,   57,  237,  231,  191,  191,  279,  279,  282,
 /*  1440 */   143,  191,  108,  268,   22,   19,   20,  256,   22,   43,
 /*  1450 */   257,   96,   97,   98,   99,  100,  101,  102,  103,  104,
 /*  1460 */   105,  106,   36,  222,  142,  234,   18,  191,  225,   18,
 /*  1470 */   190,   96,   97,   98,   99,  100,  101,  102,  103,  104,
 /*  1480 */   105,  106,  225,  191,  225,   59,  225,  257,  234,  234,
 /*  1490 */   256,  222,  222,  190,  234,  150,   62,   71,  275,  274,
 /*  1500 */   191,   19,   20,  190,   22,   22,  210,   81,  191,  190,
 /*  1510 */   210,  191,  108,  190,  207,  207,   64,  207,   36,  215,
 /*  1410 */    36,  244,  130,  170,   90,  170,   38,  170,  139,  104,
 /*  1420 */    96,   97,   48,  236,   22,  235,   43,  103,  201,  105,
 /*  1430 */   106,  107,  138,   59,  110,  247,  213,   18,  204,  258,
 /*  1440 */   204,  258,  204,  204,  170,   71,   18,  169,  213,  236,
 /*  1450 */   213,  127,  128,  235,  201,  201,   82,  170,  169,  213,
 /*  1460 */   146,   87,   62,  254,   90,  141,  142,  143,  144,  145,
 /*  1470 */    96,   97,  253,  170,  169,   22,  170,  103,  169,  105,
 /*  1480 */   106,  107,  189,  170,  110,  169,  189,  186,   19,   20,
 /*  1490 */   104,   22,  194,  186,  186,   64,  115,  186,  194,  189,
 /*  1500 */   188,  102,  133,  186,  186,   36,  186,  104,  189,   19,
 /*  1510 */    20,  246,   22,  246,  189,  141,  142,  143,  144,  145,
 /*  1520 */     0,    1,    2,  228,  228,    5,   36,  227,   59,  227,
 /*  1520 */    94,  210,  207,  209,  119,  207,  100,  101,  207,  106,
 /*  1530 */    48,  215,  207,  107,  210,  109,  110,  111,  267,  267,
 /*  1540 */   114,   59,  210,  249,  137,  108,  248,  191,  249,  248,
 /*  1550 */    88,  249,  141,   71,  248,  299,  138,  131,  132,   22,
 /*  1560 */   191,  249,  299,  237,   82,  238,  150,  262,  140,   87,
 /*  1570 */   139,  145,  146,  147,  148,  149,   94,  248,  238,  236,
 /*  1580 */    25,  235,  100,  101,  234,  194,   26,  193,   13,  107,
 /*  1590 */     6,  109,  110,  111,  264,  185,  114,  185,  183,  197,
 /*  1600 */   183,  203,  183,  203,  203,  197,  203,  211,  211,    4,
 /*  1610 */   197,    3,  203,   22,  155,   15,  288,  203,   93,  288,
 /*  1620 */   285,   23,   16,  203,  203,   23,  132,  145,  146,  147,
 /*  1630 */   148,  149,    0,    1,    2,  143,  123,    5,   24,  135,
 /*  1530 */    10,   11,   12,   13,   14,  170,   84,   17,  134,  216,
 /*  1540 */    71,  272,  270,   22,  137,  217,   22,  216,  227,   59,
 /*  1550 */    30,   82,   32,  217,  228,  228,   87,  227,  170,   90,
 /*  1560 */    40,   71,  146,  241,  215,   96,   97,  214,  136,  135,
 /*  1570 */   213,   25,  103,   26,  105,  106,  107,  243,  173,  110,
 /*  1580 */    90,  172,   13,    6,  164,  164,   96,   97,   98,  162,
 /*  1590 */    70,  162,  162,  103,  176,  105,  106,  107,   78,  267,
 /*  1600 */   110,   81,  267,  264,  182,  182,  182,  182,   88,  176,
 /*  1610 */   141,  142,  143,  144,  145,  176,  190,    4,  182,  182,
 /*  1620 */   182,   19,   20,  182,   22,  190,    3,   22,  151,   15,
 /*  1630 */    89,  141,  142,  143,  144,  145,   16,  128,   36,   23,
 /*  1640 */    23,  139,  122,   24,  119,  131,   20,  127,  128,  133,
 /*  1650 */    16,    1,  140,  131,  119,   61,  139,   53,   37,   53,
 /*  1660 */    53,   59,   53,  119,  105,   34,  130,    1,    5,   22,
 /*  1670 */   150,  104,  149,   71,   26,   75,   68,   41,   68,  130,
 /*  1680 */   104,   24,   20,   19,   82,  120,  114,   22,   28,   87,
 /*  1690 */    22,   67,   90,   22,   67,   23,   22,   22,   96,   97,
 /*  1700 */    67,   23,  138,   22,   37,  103,  153,  105,  106,  107,
 /*  1710 */     1,    2,  110,   23,    5,   23,   23,   26,   22,   10,
 /*  1720 */    11,   12,   13,   14,   24,   23,   17,   22,   24,  130,
 /*  1730 */    23,   19,   20,   23,   22,  105,   22,   34,   85,   30,
 /*  1740 */    34,   32,   26,  141,  142,  143,  144,  145,   36,   40,
 /*  1750 */   132,   34,   75,   83,   23,   44,   24,   34,   23,   26,
 /*  1760 */    26,   19,   20,   23,   22,   26,   23,   23,   23,   23,
 /*  1770 */    22,   59,   11,   22,   22,   26,   23,   23,   36,   70,
 /*  1780 */    22,   22,  124,   71,  130,  130,  130,   78,   23,  130,
 /*  1790 */    81,   15,    1,  278,  278,  278,  278,   88,  278,  278,
 /*  1800 */   278,   59,   90,  278,  278,  278,  278,  278,   96,   97,
 /*  1810 */   278,  278,  278,   71,  278,  103,  278,  105,  106,  107,
 /*  1820 */   278,  278,  110,  278,  278,  278,  278,  278,  278,  278,
 /*  1830 */   278,  122,   90,  278,  278,  278,  127,  128,   96,   97,
 /*  1840 */   278,  278,  278,  278,  278,  103,  278,  105,  106,  107,
 /*  1850 */   278,  278,  110,  141,  142,  143,  144,  145,  278,  150,
 /*  1860 */   278,  278,  278,    5,  278,  278,  278,  278,   10,   11,
 /*  1870 */    12,   13,   14,  278,  278,   17,  278,  278,  278,  278,
 /*  1880 */   278,  278,  278,  141,  142,  143,  144,  145,   30,  278,
 /*  1890 */    32,  278,  278,  278,  278,  278,  278,  278,   40,  278,
 /*  1640 */    20,   16,   10,   11,   12,   13,   14,  137,    1,   17,
 /*  1650 */   135,  144,   19,   20,  123,   22,   61,  143,   37,  123,
 /*  1660 */    53,  109,   30,   53,   32,   53,   53,  134,   34,   36,
 /*  1670 */     1,    5,   40,   22,  108,  153,   26,   68,   75,   68,
 /*  1680 */    41,  134,  108,   24,   20,  124,   19,  118,   23,   67,
 /*  1690 */    22,   67,   59,   22,   22,   22,   22,   67,   28,   37,
 /*  1700 */    23,  142,   70,   22,   71,   23,  157,   23,   23,   26,
 /*  1710 */    78,   23,   22,   81,   23,   82,   24,   22,   24,  134,
 /*  1720 */    87,   23,   19,   20,   92,   22,  109,   94,   23,   22,
 /*  1730 */    34,   34,  136,  100,  101,   26,   34,   85,   34,   36,
 /*  1740 */   107,   83,  109,  110,  111,   34,   90,  114,   34,   23,
 /*  1750 */    75,   75,   44,   22,   24,   26,   34,   23,  126,   26,
 /*  1760 */    23,   23,   59,  131,  132,   23,   23,   26,   23,   22,
 /*  1770 */    11,   22,   22,   22,   71,   23,   23,   22,  145,  146,
 /*  1780 */   147,  148,  149,   26,   23,   82,  154,  134,  128,  134,
 /*  1790 */    87,  134,   15,    1,  301,  134,  301,   94,  301,  301,
 /*  1800 */   301,  301,  301,  100,  101,  301,  301,  301,  301,  301,
 /*  1810 */   107,  301,  109,  110,  111,    1,    2,  114,  301,    5,
 /*  1820 */   301,  301,  301,  301,   10,   11,   12,   13,   14,  301,
 /*  1830 */   301,   17,  301,  301,  301,  301,   19,   20,  301,   22,
 /*  1840 */   301,  301,  301,  301,   30,  301,   32,  301,  145,  146,
 /*  1850 */   147,  148,  149,   36,   40,  301,  301,  301,  301,  301,
 /*  1860 */   301,  301,  301,  301,  301,  301,  301,  301,  301,  301,
 /*  1870 */   301,  301,  301,  301,  301,  301,   59,  301,  301,  301,
 /*  1880 */   301,  301,  301,  301,   70,  301,  301,  301,   71,  301,
 /*  1890 */   301,  301,   78,  301,  301,   81,   19,   20,  301,   22,
 /*  1900 */   301,  301,  301,  301,  301,  301,   92,  301,  301,  301,
 /*  1910 */   301,   94,  301,   36,  301,  301,  301,  100,  101,  102,
 /*  1920 */   301,  301,  301,  301,  107,  301,  109,  110,  111,  301,
 /*  1930 */   301,  114,  301,  301,  301,  301,   59,  301,  301,  301,
 /*  1940 */   126,  301,  301,  301,  301,  131,  132,  301,   71,  301,
 /*  1950 */   301,  301,  301,  301,  301,  301,   19,   20,  301,   22,
 /*  1960 */   301,  301,  145,  146,  147,  148,  149,  301,  154,  301,
 /*  1970 */   301,   94,  301,   36,  301,  301,  301,  100,  101,  301,
 /*  1980 */   301,  301,  301,  301,  107,  301,  109,  110,  111,  301,
 /*  1990 */   301,  114,    5,  301,  301,  301,   59,   10,   11,   12,
 /*  2000 */    13,   14,  301,  301,   17,  301,  301,  301,   71,  301,
 /*  2010 */   301,  301,  301,  301,  301,  301,  301,   30,  301,   32,
 /*  2020 */   301,  301,  145,  146,  147,  148,  149,   40,  301,  301,
 /*  1900 */   278,  278,  278,  278,  278,  278,  278,  278,  278,  278,
 /*  1910 */   278,  278,  278,  278,  278,  278,  278,  278,  278,  278,
 /*  1920 */   278,  278,  278,  278,  278,  278,  278,  278,   70,  278,
 /*  1930 */   278,  278,  278,  278,  278,  278,   78,  278,  278,   81,
 /*  1940 */   278,  278,  278,  278,  278,  278,   88,  278,  278,  278,
 /*  1950 */   278,  278,  278,  278,  278,  278,  278,  278,  278,  278,
 /*  1960 */   278,  278,  278,  278,  278,  278,  278,  278,  278,  278,
 /*  1970 */   278,  278,  278,  278,  278,  278,  278,  278,  278,  278,
 /*  1980 */   122,  278,  278,  278,  278,  127,  128,  278,  278,  278,
 /*  1990 */   278,  278,  278,  278,  278,  278,  278,  278,  278,  278,
 /*  2000 */   278,  278,  278,  278,  278,  278,  278,  278,  150,  278,
 /*  2010 */   278,  278,  278,  278,  278,  278,  278,  278,  278,
 /*  2030 */   301,   94,  301,  301,  301,  301,  301,  100,  101,  301,
 /*  2040 */   301,  301,  301,  301,  107,  301,  109,  110,  111,  301,
 /*  2050 */   301,  114,  301,  301,  301,  301,  301,   70,  301,  301,
 /*  2060 */   301,  301,  301,  301,  301,   78,  301,  301,   81,  301,
 /*  2070 */   301,  301,  301,  301,  301,  301,  301,  301,  301,   92,
 /*  2080 */   301,  301,  145,  146,  147,  148,  149,  301,  301,  301,
 /*  2090 */   301,  301,  301,  301,  301,  301,  301,  301,  301,  301,
 /*  2100 */   301,  301,  301,  301,  301,  301,  301,  301,  301,  301,
 /*  2110 */   301,  301,  301,  126,  301,  301,  301,  301,  131,  132,
 /*  2120 */   301,  301,  301,  301,  301,  301,  301,  301,  301,  301,
 /*  2130 */   301,  301,  301,  301,  301,  301,  301,  301,  301,  301,
 /*  2140 */   301,  154,  301,  301,  301,  301,  301,  301,  301,  301,
 /*  2150 */   301,  301,  301,  301,  301,  301,  301,  301,  301,  301,
 /*  2160 */   301,  301,  301,  301,  301,  301,  301,  301,  301,
};
#define YY_SHIFT_COUNT    (523)
#define YY_SHIFT_COUNT    (540)
#define YY_SHIFT_MIN      (0)
#define YY_SHIFT_MAX      (1858)
#define YY_SHIFT_MAX      (1987)
static const unsigned short int yy_shift_ofst[] = {
 /*     0 */  1709, 1520, 1858, 1324, 1324,   24, 1374, 1469, 1602, 1712,
 /*    10 */  1712, 1712,  271,    0,    0,  113, 1016, 1712, 1712, 1712,
 /*    20 */  1712, 1712, 1712, 1712, 1712, 1712, 1712,   12,   12,  409,
 /*    30 */   596,   24,   24,   24,   24,   24,   24,   93,  177,  270,
 /*    40 */   363,  456,  549,  642,  735,  828,  848,  996, 1144, 1016,
 /*    50 */  1016, 1016, 1016, 1016, 1016, 1016, 1016, 1016, 1016, 1016,
 /*    60 */  1016, 1016, 1016, 1016, 1016, 1016, 1016, 1164, 1016, 1257,
 /*    70 */  1277, 1277, 1490, 1712, 1712, 1712, 1712, 1712, 1712, 1712,
 /*    80 */  1712, 1712, 1712, 1712, 1712, 1712, 1712, 1712, 1712, 1712,
 /*    90 */  1712, 1712, 1712, 1712, 1712, 1712, 1712, 1712, 1712, 1712,
 /*   100 */  1712, 1712, 1712, 1712, 1712, 1742, 1712, 1712, 1712, 1712,
 /*   110 */  1712, 1712, 1712, 1712, 1712, 1712, 1712, 1712, 1712,  143,
 /*   120 */   162,  162,  162,  162,  162,  204,  151,  186,  650,  690,
 /*   130 */   327,  650,  261,  261,  650,  722,  722,  722,  722,  373,
 /*   140 */    33,    2, 2009, 2009,  330,  330,  330,  346,  289,  278,
 /*   150 */   289,  289,  517,  517,  459,  510,   15,  799,  650,  650,
 /*   160 */   650,  650,  650,  650,  650,  650,  650,  650,  650,  650,
 /*   170 */   650,  650,  650,  650,  650,  650,  650,  650,  650,  650,
 /*   180 */   331,  365,  995,  995,  265,  365,   50, 1038, 2009, 2009,
 /*   190 */  2009,  433,  250,  250,  504,  314,  429,  518,  522,  526,
 /*   200 */   561,  650,  650,  650,  650,  650,  650,  650,  650,  650,
 /*   210 */   192,  650,  650,  650,  650,  650,  650,  650,  650,  650,
 /*   220 */   650,  650,  650,  641,  641,  641,  650,  650,  650,  650,
 /*   230 */   800,  650,  650,  650,  830,  650,  650,  782,  650,  650,
 /*   240 */   650,  650,  650,  650,  650,  650,  739,  902,  689,  895,
 /*   250 */   895,  895,  895,  736,  689,  689,  885,  445,  903, 1124,
 /*   260 */   945,  748,  748, 1066,  945,  945, 1066,  447, 1002,  293,
 /*   270 */  1195, 1195, 1195,  748,  740,  727,  460, 1157, 1348, 1282,
 /*   280 */  1282, 1378, 1378, 1282, 1279, 1315, 1402, 1383, 1294, 1419,
 /*   290 */  1419, 1419, 1419, 1282, 1428, 1294, 1294, 1315, 1402, 1383,
 /*   300 */  1383, 1294, 1282, 1428, 1314, 1400, 1282, 1428, 1453, 1282,
 /*   310 */  1428, 1282, 1428, 1453, 1386, 1386, 1386, 1431, 1453, 1386,
 /*   320 */  1381, 1386, 1431, 1386, 1386, 1453, 1399, 1399, 1453, 1369,
 /*   330 */  1403, 1369, 1403, 1369, 1403, 1369, 1403, 1282, 1404, 1452,
 /*   340 */  1521, 1407, 1404, 1524, 1282, 1416, 1407, 1432, 1434, 1294,
 /*   350 */  1546, 1547, 1569, 1569, 1577, 1577, 1577, 2009, 2009, 2009,
 /*   360 */  2009, 2009, 2009, 2009, 2009, 2009, 2009, 2009, 2009, 2009,
 /*   370 */  2009, 2009, 2009,  591,  697, 1059, 1139, 1058,  797,  465,
 /*   380 */  1159, 1182, 1122, 1062, 1180,  936, 1199, 1201, 1205, 1224,
 /*   390 */  1225, 1244, 1061, 1145, 1261, 1161, 1194, 1249, 1251, 1256,
 /*   400 */  1137, 1142, 1263, 1264, 1214, 1207, 1613, 1623, 1605, 1477,
 /*   410 */  1614, 1541, 1620, 1616, 1617, 1509, 1502, 1525, 1619, 1514,
 /*   420 */  1626, 1516, 1634, 1650, 1522, 1512, 1535, 1594, 1621, 1517,
 /*   430 */  1604, 1606, 1607, 1609, 1544, 1559, 1631, 1536, 1666, 1663,
 /*   440 */  1647, 1567, 1523, 1608, 1648, 1610, 1600, 1636, 1549, 1576,
 /*   450 */  1657, 1662, 1664, 1565, 1572, 1665, 1624, 1668, 1671, 1672,
 /*   460 */  1674, 1627, 1660, 1675, 1633, 1667, 1678, 1564, 1681, 1553,
 /*   470 */  1690, 1692, 1691, 1693, 1696, 1700, 1702, 1705, 1704, 1599,
 /*   480 */  1707, 1710, 1630, 1703, 1714, 1618, 1716, 1706, 1716, 1717,
 /*   490 */  1653, 1677, 1670, 1711, 1731, 1732, 1733, 1734, 1723, 1735,
 /*   500 */  1716, 1740, 1743, 1744, 1745, 1739, 1746, 1748, 1761, 1751,
 /*   510 */  1752, 1753, 1754, 1758, 1759, 1749, 1658, 1654, 1655, 1656,
 /*   520 */  1659, 1765, 1776, 1791,
 /*     0 */  1814, 1632, 1987, 1426, 1426,  128, 1482, 1633, 1703, 1877,
 /*    10 */  1877, 1877,   87,    0,    0,  264, 1106, 1877, 1877, 1877,
 /*    20 */  1877, 1877, 1877, 1877, 1877, 1877, 1877, 1877, 1877, 1877,
 /*    30 */   226,  226,  381,  381,  296,  193,  128,  128,  128,  128,
 /*    40 */   128,  128,   97,  194,  332,  429,  526,  623,  720,  817,
 /*    50 */   914,  934, 1086, 1238, 1106, 1106, 1106, 1106, 1106, 1106,
 /*    60 */  1106, 1106, 1106, 1106, 1106, 1106, 1106, 1106, 1106, 1106,
 /*    70 */  1106, 1106, 1258, 1106, 1355, 1375, 1375, 1817, 1877, 1877,
 /*    80 */  1877, 1877, 1877, 1877, 1877, 1877, 1877, 1877, 1877, 1877,
 /*    90 */  1877, 1877, 1877, 1877, 1877, 1877, 1877, 1877, 1877, 1877,
 /*   100 */  1877, 1877, 1877, 1877, 1877, 1877, 1877, 1877, 1877, 1877,
 /*   110 */  1937, 1877, 1877, 1877, 1877, 1877, 1877, 1877, 1877, 1877,
 /*   120 */  1877, 1877, 1877, 1877,   32,  129,  129,  129,  129,  129,
 /*   130 */    21,  152,  297,  494,  726,   65,  494,  514,  514,  494,
 /*   140 */   560,  560,  560,  560,  322,  599,   50, 2142, 2142,  155,
 /*   150 */   155,  155,  313,  392,  386,  392,  392,  481,  481,  200,
 /*   160 */   480,  684,  758,  494,  494,  494,  494,  494,  494,  494,
 /*   170 */   494,  494,  494,  494,  494,  494,  494,  494,  494,  494,
 /*   180 */   494,  494,  494,  494,  768,  768,  494,  166,  377,  377,
 /*   190 */   635,  835,  835,  635,  748,  987, 2142, 2142, 2142,  448,
 /*   200 */    45,   45,  403,  484,  502,  106,  525,  508,  528,  538,
 /*   210 */   494,  494,  494,  494,  494,  494,  494,  494,  494,   84,
 /*   220 */   494,  494,  494,  494,  494,  494,  494,  494,  494,  494,
 /*   230 */   494,  494,  267,  267,  267,  494,  494,  494,  494,  769,
 /*   240 */   494,  494,  494,    4,  477,  494,  494,  788,  494,  494,
 /*   250 */   494,  494,  494,  494,  494,  494,  727,    5,  135,  985,
 /*   260 */   985,  985,  985,  522,  135,  135,  797,  326,  875,  986,
 /*   270 */   968, 1036, 1036, 1038,  968,  968, 1038,  972, 1081, 1118,
 /*   280 */  1194, 1194, 1194, 1036,  757,  757,  946,  777, 1099, 1102,
 /*   290 */  1333, 1282, 1282, 1381, 1381, 1282, 1297, 1334, 1422, 1406,
 /*   300 */  1322, 1448, 1448, 1448, 1448, 1282, 1451, 1322, 1322, 1334,
 /*   310 */  1422, 1406, 1406, 1322, 1282, 1451, 1345, 1434, 1282, 1451,
 /*   320 */  1483, 1282, 1451, 1282, 1451, 1483, 1404, 1404, 1404, 1452,
 /*   330 */  1483, 1404, 1405, 1404, 1452, 1404, 1404, 1483, 1423, 1423,
 /*   340 */  1483, 1407, 1437, 1407, 1437, 1407, 1437, 1407, 1437, 1282,
 /*   350 */  1462, 1462, 1411, 1418, 1537, 1282, 1416, 1411, 1428, 1431,
 /*   360 */  1322, 1555, 1560, 1575, 1575, 1584, 1584, 1584, 2142, 2142,
 /*   370 */  2142, 2142, 2142, 2142, 2142, 2142, 2142, 2142, 2142, 2142,
 /*   380 */  2142, 2142, 2142, 2142,   61,  725,  374, 1080,  198,  771,
 /*   390 */   283, 1192, 1178, 1190, 1107, 1221, 1206, 1226, 1227, 1232,
 /*   400 */  1233, 1240, 1242, 1189, 1129, 1253,  216, 1210, 1247, 1248,
 /*   410 */  1249, 1131, 1151, 1274, 1293, 1220, 1214, 1605, 1608, 1591,
 /*   420 */  1459, 1600, 1525, 1606, 1598, 1602, 1494, 1492, 1513, 1614,
 /*   430 */  1504, 1620, 1510, 1625, 1647, 1515, 1507, 1531, 1595, 1621,
 /*   440 */  1514, 1607, 1610, 1612, 1613, 1536, 1552, 1634, 1533, 1669,
 /*   450 */  1666, 1651, 1566, 1522, 1609, 1650, 1611, 1603, 1639, 1547,
 /*   460 */  1574, 1659, 1664, 1667, 1561, 1569, 1668, 1622, 1671, 1672,
 /*   470 */  1665, 1673, 1624, 1670, 1674, 1630, 1662, 1677, 1559, 1681,
 /*   480 */  1682, 1549, 1684, 1685, 1683, 1688, 1690, 1692, 1691, 1695,
 /*   490 */  1694, 1585, 1698, 1705, 1617, 1696, 1707, 1596, 1709, 1697,
 /*   500 */  1702, 1704, 1711, 1652, 1675, 1658, 1708, 1676, 1656, 1714,
 /*   510 */  1726, 1731, 1730, 1729, 1733, 1722, 1734, 1709, 1737, 1738,
 /*   520 */  1742, 1743, 1741, 1745, 1747, 1759, 1749, 1750, 1752, 1753,
 /*   530 */  1751, 1755, 1757, 1660, 1653, 1655, 1657, 1661, 1761, 1777,
 /*   540 */  1792,
};
#define YY_REDUCE_COUNT (372)
#define YY_REDUCE_MIN   (-235)
#define YY_REDUCE_MAX   (1441)
#define YY_REDUCE_COUNT (383)
#define YY_REDUCE_MIN   (-257)
#define YY_REDUCE_MAX   (1421)
static const short yy_reduce_ofst[] = {
 /*     0 */  -147,  171,  263,  -96,  169, -144, -162, -149, -102, -156,
 /*    10 */   -98,  216,  354, -170,  -57, -235,  307,  149,  423,  428,
 /*    20 */   471,  313,  451,  519,  489,  496,  499,  545,  547,  555,
 /*    30 */  -116,  540,  558,  592,  594,  597,  599, -206, -206, -206,
 /*    40 */  -206, -206, -206, -206, -206, -206, -206, -206, -206, -206,
 /*    50 */  -206, -206, -206, -206, -206, -206, -206, -206, -206, -206,
 /*    60 */  -206, -206, -206, -206, -206, -206, -206, -206, -206, -206,
 /*    70 */  -206, -206,  196,  309,  494,  537,  612,  656,  675,  679,
 /*    80 */   681,  685,  724,  753,  771,  776,  788,  790,  794,  796,
 /*    90 */   801,  803,  805,  807,  814,  819,  833,  837,  839,  842,
 /*   100 */   845,  847,  849,  853,  873,  891,  893,  917,  921,  937,
 /*   110 */   940,  944,  956,  960,  967,  969,  971,  973,  975, -206,
 /*   120 */  -206, -206, -206, -206, -206, -206, -206, -206,  501, -168,
 /*   130 */    90,  -97,   87,  112,  303,  277,  601,  277,  601,  179,
 /*   140 */  -206, -206, -206, -206, -107, -107, -107,  -43,  -56,  323,
 /*   150 */   500,  512, -187, -177,  317,  609,  353,  353,  120,  144,
 /*   160 */   490,  539,  698,  374,  467,  507,  789,  404, -157,  755,
 /*   170 */   856,  916,  843,  941,  802,  770,  923,  821, 1001, -142,
 /*   180 */   264,  785,  896,  905,  899,  949, -176,  544,  911,  953,
 /*   190 */  1012, -182,  -59,  -30,   16,  -22,  117,  172,  291,  369,
 /*   200 */   407,  415,  566,  586,  647,  699,  754,  813,  850,  892,
 /*   210 */   121, 1023, 1042, 1086, 1121, 1125, 1128, 1129, 1130, 1131,
 /*   220 */  1132, 1134, 1135,  284, 1106, 1123, 1152, 1154, 1155, 1156,
 /*   230 */   397, 1158, 1172, 1173, 1116, 1176, 1177, 1138, 1179,  117,
 /*   240 */  1184, 1185, 1198, 1200, 1202, 1203,  741, 1094, 1153, 1146,
 /*   250 */  1160, 1162, 1163,  397, 1153, 1153, 1170, 1204, 1206, 1103,
 /*   260 */  1168, 1165, 1166, 1133, 1174, 1175, 1140, 1210, 1193, 1208,
 /*   270 */  1212, 1215, 1216, 1178, 1167, 1189, 1196, 1241, 1148, 1243,
 /*   280 */  1245, 1181, 1183, 1247, 1188, 1187, 1190, 1227, 1223, 1234,
 /*   290 */  1236, 1238, 1239, 1274, 1278, 1235, 1237, 1213, 1218, 1253,
 /*   300 */  1254, 1246, 1287, 1289, 1209, 1219, 1303, 1305, 1293, 1306,
 /*   310 */  1309, 1313, 1316, 1297, 1301, 1307, 1308, 1298, 1310, 1311,
 /*   320 */  1312, 1317, 1304, 1318, 1320, 1319, 1265, 1267, 1325, 1295,
 /*   330 */  1300, 1296, 1302, 1326, 1321, 1327, 1330, 1365, 1323, 1269,
 /*   340 */  1272, 1328, 1331, 1322, 1388, 1334, 1336, 1349, 1353, 1357,
 /*   350 */  1405, 1409, 1420, 1421, 1427, 1429, 1430, 1332, 1335, 1339,
 /*   360 */  1418, 1422, 1423, 1424, 1425, 1433, 1426, 1435, 1436, 1437,
 /*   370 */  1438, 1441, 1439,
 /*     0 */  -168,  -17,  164,  214,  310, -166, -184,  -18,   98, -170,
 /*    10 */   305,  315, -163, -193, -178, -257,  395,  401,  476,  478,
 /*    20 */   512,  117,  527,  529,  503,  509,  532,  255,  552,  556,
 /*    30 */   558,  607,   37,  408,  594,  413,  462,  559,  561,  601,
 /*    40 */   610,  618, -254, -254, -254, -254, -254, -254, -254, -254,
 /*    50 */  -254, -254, -254, -254, -254, -254, -254, -254, -254, -254,
 /*    60 */  -254, -254, -254, -254, -254, -254, -254, -254, -254, -254,
 /*    70 */  -254, -254, -254, -254, -254, -254, -254, -111,  627,  650,
 /*    80 */   691,  697,  701,  703,  740,  742,  744,  767,  770,  790,
 /*    90 */   816,  818,  820,  822,  845,  857,  859,  861,  863,  865,
 /*   100 */   868,  870,  872,  874,  876,  888,  903,  906,  908,  915,
 /*   110 */   917,  922,  960,  962,  964,  988,  990,  992, 1015, 1017,
 /*   120 */  1029, 1033, 1035, 1040, -254, -254, -254, -254, -254, -254,
 /*   130 */  -254, -254, -254,  190,  270, -196,  160, -160,  450,  647,
 /*   140 */   260,  458,  260,  458,   78, -254, -254, -254, -254,  206,
 /*   150 */   206,  206,  320,  598,   -5,  675,  743, -148,  340, -125,
 /*   160 */   459,  466,  466,  693,  -93,  461,  479,  706,  710,  714,
 /*   170 */   716,  717,  169, -183,  325,  314,  704,  333,  747,  858,
 /*   180 */    -8,  819,  565,  755,  646,  660,  517,  265,  713,  791,
 /*   190 */   712,  795,  803,  918,  695,  860,  893,  935,  939, -181,
 /*   200 */  -172, -147,  -91,  -46,   -3,  162,  173,  231,  338,  437,
 /*   210 */   571,  614,  630,  651,  760,  931,  989, 1032, 1046, -218,
 /*   220 */    38, 1070, 1096, 1133, 1134, 1137, 1138, 1139, 1141, 1142,
 /*   230 */  1143, 1144,  292,  451, 1050, 1145, 1147, 1148, 1149,  813,
 /*   240 */  1161, 1162, 1163, 1108, 1049, 1166, 1168, 1146, 1169,  162,
 /*   250 */  1181, 1182, 1183, 1184, 1185, 1187, 1100, 1103, 1150, 1135,
 /*   260 */  1136, 1140, 1152,  813, 1150, 1150, 1153, 1173, 1195, 1090,
 /*   270 */  1154, 1167, 1170, 1104, 1155, 1156, 1109, 1172, 1174, 1179,
 /*   280 */  1177, 1188, 1205, 1171, 1160, 1196, 1121, 1165, 1203, 1228,
 /*   290 */  1157, 1244, 1245, 1158, 1159, 1250, 1175, 1193, 1191, 1241,
 /*   300 */  1231, 1243, 1257, 1259, 1261, 1276, 1280, 1254, 1255, 1230,
 /*   310 */  1234, 1269, 1270, 1260, 1292, 1303, 1223, 1225, 1309, 1313,
 /*   320 */  1296, 1317, 1319, 1320, 1323, 1300, 1307, 1308, 1310, 1304,
 /*   330 */  1311, 1315, 1314, 1318, 1316, 1321, 1325, 1324, 1271, 1272,
 /*   340 */  1332, 1294, 1298, 1299, 1301, 1302, 1306, 1312, 1329, 1356,
 /*   350 */  1256, 1263, 1327, 1326, 1305, 1369, 1330, 1340, 1343, 1346,
 /*   360 */  1350, 1391, 1394, 1410, 1412, 1415, 1417, 1419, 1328, 1331,
 /*   370 */  1335, 1402, 1398, 1400, 1401, 1403, 1408, 1396, 1397, 1409,
 /*   380 */  1414, 1420, 1421, 1413,
};
static const YYACTIONTYPE yy_default[] = {
 /*     0 */  1500, 1500, 1500, 1346, 1129, 1235, 1129, 1129, 1129, 1346,
 /*    10 */  1346, 1346, 1129, 1265, 1265, 1399, 1160, 1129, 1129, 1129,
 /*    20 */  1129, 1129, 1129, 1129, 1345, 1129, 1129, 1129, 1129, 1129,
 /*    30 */  1129, 1129, 1129, 1129, 1129, 1129, 1129, 1129, 1271, 1129,
 /*    40 */  1129, 1129, 1129, 1129, 1347, 1348, 1129, 1129, 1129, 1398,
 /*    50 */  1400, 1363, 1281, 1280, 1279, 1278, 1381, 1252, 1276, 1269,
 /*    60 */  1273, 1341, 1342, 1340, 1344, 1348, 1347, 1129, 1272, 1312,
 /*    70 */  1326, 1311, 1129, 1129, 1129, 1129, 1129, 1129, 1129, 1129,
 /*    80 */  1129, 1129, 1129, 1129, 1129, 1129, 1129, 1129, 1129, 1129,
 /*    90 */  1129, 1129, 1129, 1129, 1129, 1129, 1129, 1129, 1129, 1129,
 /*   100 */  1129, 1129, 1129, 1129, 1129, 1129, 1129, 1129, 1129, 1129,
 /*   110 */  1129, 1129, 1129, 1129, 1129, 1129, 1129, 1129, 1129, 1320,
 /*   120 */  1325, 1331, 1324, 1321, 1314, 1313, 1315, 1316, 1129, 1150,
 /*   130 */  1199, 1129, 1129, 1129, 1129, 1417, 1416, 1129, 1129, 1160,
 /*   140 */  1317, 1318, 1328, 1327, 1406, 1456, 1455, 1364, 1129, 1129,
 /*   150 */  1129, 1129, 1129, 1129, 1129, 1129, 1129, 1129, 1129, 1129,
 /*   160 */  1129, 1129, 1129, 1129, 1129, 1129, 1129, 1129, 1129, 1129,
 /*   170 */  1129, 1129, 1129, 1129, 1129, 1129, 1129, 1129, 1129, 1129,
 /*   180 */  1160, 1156, 1306, 1305, 1426, 1156, 1259, 1129, 1412, 1235,
 /*   190 */  1226, 1129, 1129, 1129, 1129, 1129, 1129, 1129, 1129, 1129,
 /*   200 */  1129, 1129, 1129, 1129, 1403, 1401, 1129, 1129, 1129, 1129,
 /*   210 */  1129, 1129, 1129, 1129, 1129, 1129, 1129, 1129, 1129, 1129,
 /*   220 */  1129, 1129, 1129, 1129, 1129, 1129, 1129, 1129, 1129, 1129,
 /*   230 */  1129, 1129, 1129, 1129, 1231, 1129, 1129, 1129, 1129, 1129,
 /*   240 */  1129, 1129, 1129, 1129, 1129, 1450, 1129, 1376, 1213, 1231,
 /*   250 */  1231, 1231, 1231, 1233, 1214, 1212, 1225, 1160, 1136, 1492,
 /*   260 */  1275, 1254, 1254, 1489, 1275, 1275, 1489, 1174, 1470, 1171,
 /*   270 */  1265, 1265, 1265, 1254, 1343, 1232, 1225, 1129, 1492, 1240,
 /*   280 */  1240, 1491, 1491, 1240, 1364, 1284, 1290, 1202, 1275, 1208,
 /*   290 */  1208, 1208, 1208, 1240, 1147, 1275, 1275, 1284, 1290, 1202,
 /*   300 */  1202, 1275, 1240, 1147, 1380, 1486, 1240, 1147, 1354, 1240,
 /*   310 */  1147, 1240, 1147, 1354, 1200, 1200, 1200, 1189, 1354, 1200,
 /*   320 */  1174, 1200, 1189, 1200, 1200, 1354, 1358, 1358, 1354, 1258,
 /*   330 */  1253, 1258, 1253, 1258, 1253, 1258, 1253, 1240, 1259, 1425,
 /*   340 */  1129, 1270, 1259, 1349, 1240, 1129, 1270, 1268, 1266, 1275,
 /*   350 */  1153, 1192, 1453, 1453, 1449, 1449, 1449, 1497, 1497, 1412,
 /*   360 */  1465, 1160, 1160, 1160, 1160, 1465, 1176, 1176, 1160, 1160,
 /*   370 */  1160, 1160, 1465, 1129, 1129, 1129, 1129, 1129, 1129, 1460,
 /*   380 */  1129, 1365, 1244, 1129, 1129, 1129, 1129, 1129, 1129, 1129,
 /*   390 */  1129, 1129, 1129, 1129, 1129, 1129, 1129, 1129, 1129, 1129,
 /*   400 */  1129, 1129, 1129, 1129, 1129, 1295, 1129, 1132, 1409, 1129,
 /*   410 */  1129, 1407, 1129, 1129, 1129, 1129, 1129, 1129, 1245, 1129,
 /*   420 */  1129, 1129, 1129, 1129, 1129, 1129, 1129, 1129, 1129, 1129,
 /*   430 */  1129, 1129, 1129, 1129, 1129, 1129, 1129, 1488, 1129, 1129,
 /*   440 */  1129, 1129, 1129, 1129, 1379, 1378, 1129, 1129, 1242, 1129,
 /*   450 */  1129, 1129, 1129, 1129, 1129, 1129, 1129, 1129, 1129, 1129,
 /*   460 */  1129, 1129, 1129, 1129, 1129, 1129, 1129, 1129, 1129, 1129,
 /*   470 */  1129, 1129, 1129, 1129, 1129, 1129, 1129, 1129, 1129, 1129,
 /*   480 */  1129, 1129, 1129, 1129, 1129, 1129, 1267, 1129, 1424, 1129,
 /*   490 */  1129, 1129, 1129, 1129, 1129, 1129, 1438, 1260, 1129, 1129,
 /*   500 */  1479, 1129, 1129, 1129, 1129, 1129, 1129, 1129, 1129, 1129,
 /*   510 */  1129, 1129, 1129, 1129, 1129, 1474, 1216, 1297, 1129, 1296,
 /*   520 */  1300, 1129, 1141, 1129,
 /*     0 */  1536, 1536, 1536, 1376, 1159, 1265, 1159, 1159, 1159, 1376,
 /*    10 */  1376, 1376, 1159, 1295, 1295, 1429, 1190, 1159, 1159, 1159,
 /*    20 */  1159, 1159, 1159, 1159, 1159, 1159, 1159, 1375, 1159, 1159,
 /*    30 */  1159, 1159, 1459, 1459, 1159, 1159, 1159, 1159, 1159, 1159,
 /*    40 */  1159, 1159, 1159, 1301, 1159, 1159, 1159, 1159, 1159, 1377,
 /*    50 */  1378, 1159, 1159, 1159, 1428, 1430, 1393, 1311, 1310, 1309,
 /*    60 */  1308, 1411, 1282, 1306, 1299, 1303, 1371, 1372, 1370, 1374,
 /*    70 */  1378, 1377, 1159, 1302, 1342, 1356, 1341, 1159, 1159, 1159,
 /*    80 */  1159, 1159, 1159, 1159, 1159, 1159, 1159, 1159, 1159, 1159,
 /*    90 */  1159, 1159, 1159, 1159, 1159, 1159, 1159, 1159, 1159, 1159,
 /*   100 */  1159, 1159, 1159, 1159, 1159, 1159, 1159, 1159, 1159, 1159,
 /*   110 */  1159, 1159, 1159, 1159, 1159, 1159, 1159, 1159, 1159, 1159,
 /*   120 */  1159, 1159, 1159, 1159, 1350, 1355, 1361, 1354, 1351, 1344,
 /*   130 */  1343, 1345, 1346, 1159, 1180, 1229, 1159, 1159, 1159, 1159,
 /*   140 */  1447, 1446, 1159, 1159, 1190, 1347, 1348, 1358, 1357, 1436,
 /*   150 */  1492, 1491, 1394, 1159, 1159, 1159, 1159, 1159, 1159, 1459,
 /*   160 */  1159, 1159, 1159, 1159, 1159, 1159, 1159, 1159, 1159, 1159,
 /*   170 */  1159, 1159, 1159, 1159, 1159, 1159, 1159, 1159, 1159, 1159,
 /*   180 */  1159, 1159, 1159, 1159, 1459, 1459, 1159, 1190, 1459, 1459,
 /*   190 */  1186, 1336, 1335, 1186, 1289, 1159, 1442, 1265, 1256, 1159,
 /*   200 */  1159, 1159, 1159, 1159, 1159, 1159, 1159, 1159, 1159, 1159,
 /*   210 */  1159, 1159, 1159, 1433, 1431, 1159, 1159, 1159, 1159, 1159,
 /*   220 */  1159, 1159, 1159, 1159, 1159, 1159, 1159, 1159, 1159, 1159,
 /*   230 */  1159, 1159, 1159, 1159, 1159, 1159, 1159, 1159, 1159, 1159,
 /*   240 */  1159, 1159, 1159, 1261, 1159, 1159, 1159, 1159, 1159, 1159,
 /*   250 */  1159, 1159, 1159, 1159, 1159, 1486, 1159, 1406, 1243, 1261,
 /*   260 */  1261, 1261, 1261, 1263, 1244, 1242, 1255, 1190, 1166, 1528,
 /*   270 */  1305, 1284, 1284, 1525, 1305, 1305, 1525, 1204, 1506, 1201,
 /*   280 */  1295, 1295, 1295, 1284, 1289, 1289, 1373, 1262, 1255, 1159,
 /*   290 */  1528, 1270, 1270, 1527, 1527, 1270, 1394, 1314, 1320, 1232,
 /*   300 */  1305, 1238, 1238, 1238, 1238, 1270, 1177, 1305, 1305, 1314,
 /*   310 */  1320, 1232, 1232, 1305, 1270, 1177, 1410, 1522, 1270, 1177,
 /*   320 */  1384, 1270, 1177, 1270, 1177, 1384, 1230, 1230, 1230, 1219,
 /*   330 */  1384, 1230, 1204, 1230, 1219, 1230, 1230, 1384, 1388, 1388,
 /*   340 */  1384, 1288, 1283, 1288, 1283, 1288, 1283, 1288, 1283, 1270,
 /*   350 */  1469, 1469, 1300, 1289, 1379, 1270, 1159, 1300, 1298, 1296,
 /*   360 */  1305, 1183, 1222, 1489, 1489, 1485, 1485, 1485, 1533, 1533,
 /*   370 */  1442, 1501, 1190, 1190, 1190, 1190, 1501, 1206, 1206, 1190,
 /*   380 */  1190, 1190, 1190, 1501, 1159, 1159, 1159, 1159, 1159, 1159,
 /*   390 */  1496, 1159, 1395, 1274, 1159, 1159, 1159, 1159, 1159, 1159,
 /*   400 */  1159, 1159, 1159, 1159, 1159, 1159, 1159, 1159, 1159, 1159,
 /*   410 */  1159, 1159, 1159, 1159, 1159, 1159, 1325, 1159, 1162, 1439,
 /*   420 */  1159, 1159, 1437, 1159, 1159, 1159, 1159, 1159, 1159, 1275,
 /*   430 */  1159, 1159, 1159, 1159, 1159, 1159, 1159, 1159, 1159, 1159,
 /*   440 */  1159, 1159, 1159, 1159, 1159, 1159, 1159, 1159, 1524, 1159,
 /*   450 */  1159, 1159, 1159, 1159, 1159, 1409, 1408, 1159, 1159, 1272,
 /*   460 */  1159, 1159, 1159, 1159, 1159, 1159, 1159, 1159, 1159, 1159,
 /*   470 */  1159, 1159, 1159, 1159, 1159, 1159, 1159, 1159, 1159, 1159,
 /*   480 */  1159, 1159, 1159, 1159, 1159, 1159, 1159, 1159, 1159, 1159,
 /*   490 */  1159, 1159, 1159, 1159, 1159, 1159, 1159, 1159, 1297, 1159,
 /*   500 */  1159, 1159, 1159, 1159, 1159, 1159, 1159, 1159, 1159, 1159,
 /*   510 */  1159, 1159, 1159, 1474, 1290, 1159, 1159, 1515, 1159, 1159,
 /*   520 */  1159, 1159, 1159, 1159, 1159, 1159, 1159, 1159, 1159, 1159,
 /*   530 */  1159, 1159, 1510, 1246, 1327, 1159, 1326, 1330, 1159, 1171,
 /*   540 */  1159,
};
/********** End of lemon-generated parsing tables *****************************/

/* The next table maps tokens (terminal symbols) into fallback tokens.  
** If a construct like the following:
** 
**      %fallback ID X Y Z.
148340
148341
148342
148343
148344
148345
148346




148347
148348
148349
148350
148351
148352
148353
149157
149158
149159
149160
149161
149162
149163
149164
149165
149166
149167
149168
149169
149170
149171
149172
149173
149174







+
+
+
+







   59,  /*       WITH => ID */
   59,  /*    CURRENT => ID */
   59,  /*  FOLLOWING => ID */
   59,  /*  PARTITION => ID */
   59,  /*  PRECEDING => ID */
   59,  /*      RANGE => ID */
   59,  /*  UNBOUNDED => ID */
   59,  /*    EXCLUDE => ID */
   59,  /*     GROUPS => ID */
   59,  /*     OTHERS => ID */
   59,  /*       TIES => ID */
   59,  /*    REINDEX => ID */
   59,  /*     RENAME => ID */
   59,  /*   CTIME_KW => ID */
};
#endif /* YYFALLBACK */

/* The following structure represents a single element of the
148518
148519
148520
148521
148522
148523
148524
148525
148526
148527
148528
148529
148530
148531
148532
148533
148534
148535
148536
148537
148538
148539
148540
148541
148542
148543
148544
148545
148546
148547
148548
148549
148550
148551
148552
148553
148554
148555
148556
148557
148558
148559
148560
148561
148562
148563
148564
148565
148566
148567
148568
148569
148570
148571
148572
148573
148574
148575
148576
148577
148578
148579
148580
148581
148582
148583
148584
148585
148586
148587
148588
148589
148590
148591
148592
148593
148594
148595
148596
148597
148598
148599
148600
148601
148602
148603
148604
148605
148606
148607
148608
148609
148610
148611
148612
148613
148614
148615
148616
148617
148618
148619
148620
148621
148622
148623
148624
148625
148626
148627
148628
148629
148630
148631
148632
148633
148634
148635
148636
148637
148638
148639
148640
148641
148642
148643
148644
148645
148646
148647
148648
148649
148650
148651
148652
148653
148654
148655
148656
148657
148658
148659
148660
148661
148662
148663
148664
148665
148666
148667
148668
148669
148670
148671
148672
148673
148674
148675
148676
148677
148678
148679
148680
148681
148682
148683
148684
148685
148686
148687
148688
148689
148690
148691
148692
148693
148694
148695
148696
148697
148698
148699
148700
148701
148702
148703
148704
148705
148706
148707
148708
148709
148710
148711
148712
148713
148714





















































































































































































































148715
148716
148717
148718
148719
148720
148721
149339
149340
149341
149342
149343
149344
149345






























































































































































































149346
149347
149348
149349
149350
149351
149352
149353
149354
149355
149356
149357
149358
149359
149360
149361
149362
149363
149364
149365
149366
149367
149368
149369
149370
149371
149372
149373
149374
149375
149376
149377
149378
149379
149380
149381
149382
149383
149384
149385
149386
149387
149388
149389
149390
149391
149392
149393
149394
149395
149396
149397
149398
149399
149400
149401
149402
149403
149404
149405
149406
149407
149408
149409
149410
149411
149412
149413
149414
149415
149416
149417
149418
149419
149420
149421
149422
149423
149424
149425
149426
149427
149428
149429
149430
149431
149432
149433
149434
149435
149436
149437
149438
149439
149440
149441
149442
149443
149444
149445
149446
149447
149448
149449
149450
149451
149452
149453
149454
149455
149456
149457
149458
149459
149460
149461
149462
149463
149464
149465
149466
149467
149468
149469
149470
149471
149472
149473
149474
149475
149476
149477
149478
149479
149480
149481
149482
149483
149484
149485
149486
149487
149488
149489
149490
149491
149492
149493
149494
149495
149496
149497
149498
149499
149500
149501
149502
149503
149504
149505
149506
149507
149508
149509
149510
149511
149512
149513
149514
149515
149516
149517
149518
149519
149520
149521
149522
149523
149524
149525
149526
149527
149528
149529
149530
149531
149532
149533
149534
149535
149536
149537
149538
149539
149540
149541
149542
149543
149544
149545
149546
149547
149548
149549
149550
149551
149552
149553
149554
149555
149556
149557
149558
149559
149560
149561
149562
149563
149564
149565







-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+







  /*   81 */ "WITH",
  /*   82 */ "CURRENT",
  /*   83 */ "FOLLOWING",
  /*   84 */ "PARTITION",
  /*   85 */ "PRECEDING",
  /*   86 */ "RANGE",
  /*   87 */ "UNBOUNDED",
  /*   88 */ "REINDEX",
  /*   89 */ "RENAME",
  /*   90 */ "CTIME_KW",
  /*   91 */ "ANY",
  /*   92 */ "BITAND",
  /*   93 */ "BITOR",
  /*   94 */ "LSHIFT",
  /*   95 */ "RSHIFT",
  /*   96 */ "PLUS",
  /*   97 */ "MINUS",
  /*   98 */ "STAR",
  /*   99 */ "SLASH",
  /*  100 */ "REM",
  /*  101 */ "CONCAT",
  /*  102 */ "COLLATE",
  /*  103 */ "BITNOT",
  /*  104 */ "ON",
  /*  105 */ "INDEXED",
  /*  106 */ "STRING",
  /*  107 */ "JOIN_KW",
  /*  108 */ "CONSTRAINT",
  /*  109 */ "DEFAULT",
  /*  110 */ "NULL",
  /*  111 */ "PRIMARY",
  /*  112 */ "UNIQUE",
  /*  113 */ "CHECK",
  /*  114 */ "REFERENCES",
  /*  115 */ "AUTOINCR",
  /*  116 */ "INSERT",
  /*  117 */ "DELETE",
  /*  118 */ "UPDATE",
  /*  119 */ "SET",
  /*  120 */ "DEFERRABLE",
  /*  121 */ "FOREIGN",
  /*  122 */ "DROP",
  /*  123 */ "UNION",
  /*  124 */ "ALL",
  /*  125 */ "EXCEPT",
  /*  126 */ "INTERSECT",
  /*  127 */ "SELECT",
  /*  128 */ "VALUES",
  /*  129 */ "DISTINCT",
  /*  130 */ "DOT",
  /*  131 */ "FROM",
  /*  132 */ "JOIN",
  /*  133 */ "USING",
  /*  134 */ "ORDER",
  /*  135 */ "GROUP",
  /*  136 */ "HAVING",
  /*  137 */ "LIMIT",
  /*  138 */ "WHERE",
  /*  139 */ "INTO",
  /*  140 */ "NOTHING",
  /*  141 */ "FLOAT",
  /*  142 */ "BLOB",
  /*  143 */ "INTEGER",
  /*  144 */ "VARIABLE",
  /*  145 */ "CASE",
  /*  146 */ "WHEN",
  /*  147 */ "THEN",
  /*  148 */ "ELSE",
  /*  149 */ "INDEX",
  /*  150 */ "ALTER",
  /*  151 */ "ADD",
  /*  152 */ "WINDOW",
  /*  153 */ "OVER",
  /*  154 */ "FILTER",
  /*  155 */ "input",
  /*  156 */ "cmdlist",
  /*  157 */ "ecmd",
  /*  158 */ "cmdx",
  /*  159 */ "explain",
  /*  160 */ "cmd",
  /*  161 */ "transtype",
  /*  162 */ "trans_opt",
  /*  163 */ "nm",
  /*  164 */ "savepoint_opt",
  /*  165 */ "create_table",
  /*  166 */ "create_table_args",
  /*  167 */ "createkw",
  /*  168 */ "temp",
  /*  169 */ "ifnotexists",
  /*  170 */ "dbnm",
  /*  171 */ "columnlist",
  /*  172 */ "conslist_opt",
  /*  173 */ "table_options",
  /*  174 */ "select",
  /*  175 */ "columnname",
  /*  176 */ "carglist",
  /*  177 */ "typetoken",
  /*  178 */ "typename",
  /*  179 */ "signed",
  /*  180 */ "plus_num",
  /*  181 */ "minus_num",
  /*  182 */ "scanpt",
  /*  183 */ "ccons",
  /*  184 */ "term",
  /*  185 */ "expr",
  /*  186 */ "onconf",
  /*  187 */ "sortorder",
  /*  188 */ "autoinc",
  /*  189 */ "eidlist_opt",
  /*  190 */ "refargs",
  /*  191 */ "defer_subclause",
  /*  192 */ "refarg",
  /*  193 */ "refact",
  /*  194 */ "init_deferred_pred_opt",
  /*  195 */ "conslist",
  /*  196 */ "tconscomma",
  /*  197 */ "tcons",
  /*  198 */ "sortlist",
  /*  199 */ "eidlist",
  /*  200 */ "defer_subclause_opt",
  /*  201 */ "orconf",
  /*  202 */ "resolvetype",
  /*  203 */ "raisetype",
  /*  204 */ "ifexists",
  /*  205 */ "fullname",
  /*  206 */ "selectnowith",
  /*  207 */ "oneselect",
  /*  208 */ "wqlist",
  /*  209 */ "multiselect_op",
  /*  210 */ "distinct",
  /*  211 */ "selcollist",
  /*  212 */ "from",
  /*  213 */ "where_opt",
  /*  214 */ "groupby_opt",
  /*  215 */ "having_opt",
  /*  216 */ "orderby_opt",
  /*  217 */ "limit_opt",
  /*  218 */ "window_clause",
  /*  219 */ "values",
  /*  220 */ "nexprlist",
  /*  221 */ "sclp",
  /*  222 */ "as",
  /*  223 */ "seltablist",
  /*  224 */ "stl_prefix",
  /*  225 */ "joinop",
  /*  226 */ "indexed_opt",
  /*  227 */ "on_opt",
  /*  228 */ "using_opt",
  /*  229 */ "exprlist",
  /*  230 */ "xfullname",
  /*  231 */ "idlist",
  /*  232 */ "with",
  /*  233 */ "setlist",
  /*  234 */ "insert_cmd",
  /*  235 */ "idlist_opt",
  /*  236 */ "upsert",
  /*  237 */ "over_clause",
  /*  238 */ "likeop",
  /*  239 */ "between_op",
  /*  240 */ "in_op",
  /*  241 */ "paren_exprlist",
  /*  242 */ "case_operand",
  /*  243 */ "case_exprlist",
  /*  244 */ "case_else",
  /*  245 */ "uniqueflag",
  /*  246 */ "collate",
  /*  247 */ "vinto",
  /*  248 */ "nmnum",
  /*  249 */ "trigger_decl",
  /*  250 */ "trigger_cmd_list",
  /*  251 */ "trigger_time",
  /*  252 */ "trigger_event",
  /*  253 */ "foreach_clause",
  /*  254 */ "when_clause",
  /*  255 */ "trigger_cmd",
  /*  256 */ "trnm",
  /*  257 */ "tridxby",
  /*  258 */ "database_kw_opt",
  /*  259 */ "key_opt",
  /*  260 */ "add_column_fullname",
  /*  261 */ "kwcolumn_opt",
  /*  262 */ "create_vtab",
  /*  263 */ "vtabarglist",
  /*  264 */ "vtabarg",
  /*  265 */ "vtabargtoken",
  /*  266 */ "lp",
  /*  267 */ "anylist",
  /*  268 */ "windowdefn_list",
  /*  269 */ "windowdefn",
  /*  270 */ "window",
  /*  271 */ "frame_opt",
  /*  272 */ "part_opt",
  /*  273 */ "filter_opt",
  /*  274 */ "range_or_rows",
  /*  275 */ "frame_bound",
  /*  276 */ "frame_bound_s",
  /*  277 */ "frame_bound_e",
  /*   88 */ "EXCLUDE",
  /*   89 */ "GROUPS",
  /*   90 */ "OTHERS",
  /*   91 */ "TIES",
  /*   92 */ "REINDEX",
  /*   93 */ "RENAME",
  /*   94 */ "CTIME_KW",
  /*   95 */ "ANY",
  /*   96 */ "BITAND",
  /*   97 */ "BITOR",
  /*   98 */ "LSHIFT",
  /*   99 */ "RSHIFT",
  /*  100 */ "PLUS",
  /*  101 */ "MINUS",
  /*  102 */ "STAR",
  /*  103 */ "SLASH",
  /*  104 */ "REM",
  /*  105 */ "CONCAT",
  /*  106 */ "COLLATE",
  /*  107 */ "BITNOT",
  /*  108 */ "ON",
  /*  109 */ "INDEXED",
  /*  110 */ "STRING",
  /*  111 */ "JOIN_KW",
  /*  112 */ "CONSTRAINT",
  /*  113 */ "DEFAULT",
  /*  114 */ "NULL",
  /*  115 */ "PRIMARY",
  /*  116 */ "UNIQUE",
  /*  117 */ "CHECK",
  /*  118 */ "REFERENCES",
  /*  119 */ "AUTOINCR",
  /*  120 */ "INSERT",
  /*  121 */ "DELETE",
  /*  122 */ "UPDATE",
  /*  123 */ "SET",
  /*  124 */ "DEFERRABLE",
  /*  125 */ "FOREIGN",
  /*  126 */ "DROP",
  /*  127 */ "UNION",
  /*  128 */ "ALL",
  /*  129 */ "EXCEPT",
  /*  130 */ "INTERSECT",
  /*  131 */ "SELECT",
  /*  132 */ "VALUES",
  /*  133 */ "DISTINCT",
  /*  134 */ "DOT",
  /*  135 */ "FROM",
  /*  136 */ "JOIN",
  /*  137 */ "USING",
  /*  138 */ "ORDER",
  /*  139 */ "GROUP",
  /*  140 */ "HAVING",
  /*  141 */ "LIMIT",
  /*  142 */ "WHERE",
  /*  143 */ "INTO",
  /*  144 */ "NOTHING",
  /*  145 */ "FLOAT",
  /*  146 */ "BLOB",
  /*  147 */ "INTEGER",
  /*  148 */ "VARIABLE",
  /*  149 */ "CASE",
  /*  150 */ "WHEN",
  /*  151 */ "THEN",
  /*  152 */ "ELSE",
  /*  153 */ "INDEX",
  /*  154 */ "ALTER",
  /*  155 */ "ADD",
  /*  156 */ "WINDOW",
  /*  157 */ "OVER",
  /*  158 */ "FILTER",
  /*  159 */ "TRUEFALSE",
  /*  160 */ "ISNOT",
  /*  161 */ "FUNCTION",
  /*  162 */ "COLUMN",
  /*  163 */ "AGG_FUNCTION",
  /*  164 */ "AGG_COLUMN",
  /*  165 */ "UMINUS",
  /*  166 */ "UPLUS",
  /*  167 */ "TRUTH",
  /*  168 */ "REGISTER",
  /*  169 */ "VECTOR",
  /*  170 */ "SELECT_COLUMN",
  /*  171 */ "IF_NULL_ROW",
  /*  172 */ "ASTERISK",
  /*  173 */ "SPAN",
  /*  174 */ "SPACE",
  /*  175 */ "ILLEGAL",
  /*  176 */ "input",
  /*  177 */ "cmdlist",
  /*  178 */ "ecmd",
  /*  179 */ "cmdx",
  /*  180 */ "explain",
  /*  181 */ "cmd",
  /*  182 */ "transtype",
  /*  183 */ "trans_opt",
  /*  184 */ "nm",
  /*  185 */ "savepoint_opt",
  /*  186 */ "create_table",
  /*  187 */ "create_table_args",
  /*  188 */ "createkw",
  /*  189 */ "temp",
  /*  190 */ "ifnotexists",
  /*  191 */ "dbnm",
  /*  192 */ "columnlist",
  /*  193 */ "conslist_opt",
  /*  194 */ "table_options",
  /*  195 */ "select",
  /*  196 */ "columnname",
  /*  197 */ "carglist",
  /*  198 */ "typetoken",
  /*  199 */ "typename",
  /*  200 */ "signed",
  /*  201 */ "plus_num",
  /*  202 */ "minus_num",
  /*  203 */ "scanpt",
  /*  204 */ "ccons",
  /*  205 */ "term",
  /*  206 */ "expr",
  /*  207 */ "onconf",
  /*  208 */ "sortorder",
  /*  209 */ "autoinc",
  /*  210 */ "eidlist_opt",
  /*  211 */ "refargs",
  /*  212 */ "defer_subclause",
  /*  213 */ "refarg",
  /*  214 */ "refact",
  /*  215 */ "init_deferred_pred_opt",
  /*  216 */ "conslist",
  /*  217 */ "tconscomma",
  /*  218 */ "tcons",
  /*  219 */ "sortlist",
  /*  220 */ "eidlist",
  /*  221 */ "defer_subclause_opt",
  /*  222 */ "orconf",
  /*  223 */ "resolvetype",
  /*  224 */ "raisetype",
  /*  225 */ "ifexists",
  /*  226 */ "fullname",
  /*  227 */ "selectnowith",
  /*  228 */ "oneselect",
  /*  229 */ "wqlist",
  /*  230 */ "multiselect_op",
  /*  231 */ "distinct",
  /*  232 */ "selcollist",
  /*  233 */ "from",
  /*  234 */ "where_opt",
  /*  235 */ "groupby_opt",
  /*  236 */ "having_opt",
  /*  237 */ "orderby_opt",
  /*  238 */ "limit_opt",
  /*  239 */ "window_clause",
  /*  240 */ "values",
  /*  241 */ "nexprlist",
  /*  242 */ "sclp",
  /*  243 */ "as",
  /*  244 */ "seltablist",
  /*  245 */ "stl_prefix",
  /*  246 */ "joinop",
  /*  247 */ "indexed_opt",
  /*  248 */ "on_opt",
  /*  249 */ "using_opt",
  /*  250 */ "exprlist",
  /*  251 */ "xfullname",
  /*  252 */ "idlist",
  /*  253 */ "with",
  /*  254 */ "setlist",
  /*  255 */ "insert_cmd",
  /*  256 */ "idlist_opt",
  /*  257 */ "upsert",
  /*  258 */ "over_clause",
  /*  259 */ "likeop",
  /*  260 */ "between_op",
  /*  261 */ "in_op",
  /*  262 */ "paren_exprlist",
  /*  263 */ "case_operand",
  /*  264 */ "case_exprlist",
  /*  265 */ "case_else",
  /*  266 */ "uniqueflag",
  /*  267 */ "collate",
  /*  268 */ "vinto",
  /*  269 */ "nmnum",
  /*  270 */ "trigger_decl",
  /*  271 */ "trigger_cmd_list",
  /*  272 */ "trigger_time",
  /*  273 */ "trigger_event",
  /*  274 */ "foreach_clause",
  /*  275 */ "when_clause",
  /*  276 */ "trigger_cmd",
  /*  277 */ "trnm",
  /*  278 */ "tridxby",
  /*  279 */ "database_kw_opt",
  /*  280 */ "key_opt",
  /*  281 */ "add_column_fullname",
  /*  282 */ "kwcolumn_opt",
  /*  283 */ "create_vtab",
  /*  284 */ "vtabarglist",
  /*  285 */ "vtabarg",
  /*  286 */ "vtabargtoken",
  /*  287 */ "lp",
  /*  288 */ "anylist",
  /*  289 */ "windowdefn_list",
  /*  290 */ "windowdefn",
  /*  291 */ "window",
  /*  292 */ "frame_opt",
  /*  293 */ "part_opt",
  /*  294 */ "filter_opt",
  /*  295 */ "range_or_rows",
  /*  296 */ "frame_bound",
  /*  297 */ "frame_bound_s",
  /*  298 */ "frame_bound_e",
  /*  299 */ "frame_exclude_opt",
  /*  300 */ "frame_exclude",
};
#endif /* defined(YYCOVERAGE) || !defined(NDEBUG) */

#ifndef NDEBUG
/* For tracing reduce actions, the names of all rules are required.
*/
static const char *const yyRuleName[] = {
149005
149006
149007
149008
149009
149010
149011
149012
149013
149014
149015
149016
149017
149018
149019











149020
149021
149022
149023
149024
149025
149026






149027
149028
149029
149030
149031
149032
149033
149034
149035
149036
149037
149038
149039
149040
149041
149042
149043
149044
149045
149046
149047
149048
149049
149050
149051
149052
149053
149054
149055
149056
149057
149058
149059
149060
149061
149062
149063
149064
149065
149066
149067
149068
149069
149070
149071
149072
149073
149074
149075
149076
149077
149078
149079
149080
149081
149082
149083
149084
149085
149086
149087
149088
149089
149090




































































149091
149092
149093
149094
149095
149096
149097
149849
149850
149851
149852
149853
149854
149855








149856
149857
149858
149859
149860
149861
149862
149863
149864
149865
149866







149867
149868
149869
149870
149871
149872
































































149873
149874
149875
149876
149877
149878
149879
149880
149881
149882
149883
149884
149885
149886
149887
149888
149889
149890
149891
149892
149893
149894
149895
149896
149897
149898
149899
149900
149901
149902
149903
149904
149905
149906
149907
149908
149909
149910
149911
149912
149913
149914
149915
149916
149917
149918
149919
149920
149921
149922
149923
149924
149925
149926
149927
149928
149929
149930
149931
149932
149933
149934
149935
149936
149937
149938
149939
149940
149941
149942
149943
149944
149945
149946
149947







-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
+
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+







 /* 283 */ "lp ::= LP",
 /* 284 */ "with ::= WITH wqlist",
 /* 285 */ "with ::= WITH RECURSIVE wqlist",
 /* 286 */ "wqlist ::= nm eidlist_opt AS LP select RP",
 /* 287 */ "wqlist ::= wqlist COMMA nm eidlist_opt AS LP select RP",
 /* 288 */ "windowdefn_list ::= windowdefn",
 /* 289 */ "windowdefn_list ::= windowdefn_list COMMA windowdefn",
 /* 290 */ "windowdefn ::= nm AS window",
 /* 291 */ "window ::= LP part_opt orderby_opt frame_opt RP",
 /* 292 */ "part_opt ::= PARTITION BY nexprlist",
 /* 293 */ "part_opt ::=",
 /* 294 */ "frame_opt ::=",
 /* 295 */ "frame_opt ::= range_or_rows frame_bound_s",
 /* 296 */ "frame_opt ::= range_or_rows BETWEEN frame_bound_s AND frame_bound_e",
 /* 297 */ "range_or_rows ::= RANGE",
 /* 290 */ "windowdefn ::= nm AS LP window RP",
 /* 291 */ "window ::= PARTITION BY nexprlist orderby_opt frame_opt",
 /* 292 */ "window ::= nm PARTITION BY nexprlist orderby_opt frame_opt",
 /* 293 */ "window ::= ORDER BY sortlist frame_opt",
 /* 294 */ "window ::= nm ORDER BY sortlist frame_opt",
 /* 295 */ "window ::= frame_opt",
 /* 296 */ "window ::= nm frame_opt",
 /* 297 */ "frame_opt ::=",
 /* 298 */ "frame_opt ::= range_or_rows frame_bound_s frame_exclude_opt",
 /* 299 */ "frame_opt ::= range_or_rows BETWEEN frame_bound_s AND frame_bound_e frame_exclude_opt",
 /* 300 */ "range_or_rows ::= RANGE|ROWS|GROUPS",
 /* 298 */ "range_or_rows ::= ROWS",
 /* 299 */ "frame_bound_s ::= frame_bound",
 /* 300 */ "frame_bound_s ::= UNBOUNDED PRECEDING",
 /* 301 */ "frame_bound_e ::= frame_bound",
 /* 302 */ "frame_bound_e ::= UNBOUNDED FOLLOWING",
 /* 303 */ "frame_bound ::= expr PRECEDING",
 /* 304 */ "frame_bound ::= CURRENT ROW",
 /* 301 */ "frame_bound_s ::= frame_bound",
 /* 302 */ "frame_bound_s ::= UNBOUNDED PRECEDING",
 /* 303 */ "frame_bound_e ::= frame_bound",
 /* 304 */ "frame_bound_e ::= UNBOUNDED FOLLOWING",
 /* 305 */ "frame_bound ::= expr PRECEDING|FOLLOWING",
 /* 306 */ "frame_bound ::= CURRENT ROW",
 /* 305 */ "frame_bound ::= expr FOLLOWING",
 /* 306 */ "window_clause ::= WINDOW windowdefn_list",
 /* 307 */ "over_clause ::= filter_opt OVER window",
 /* 308 */ "over_clause ::= filter_opt OVER nm",
 /* 309 */ "filter_opt ::=",
 /* 310 */ "filter_opt ::= FILTER LP WHERE expr RP",
 /* 311 */ "input ::= cmdlist",
 /* 312 */ "cmdlist ::= cmdlist ecmd",
 /* 313 */ "cmdlist ::= ecmd",
 /* 314 */ "ecmd ::= SEMI",
 /* 315 */ "ecmd ::= cmdx SEMI",
 /* 316 */ "ecmd ::= explain cmdx",
 /* 317 */ "trans_opt ::=",
 /* 318 */ "trans_opt ::= TRANSACTION",
 /* 319 */ "trans_opt ::= TRANSACTION nm",
 /* 320 */ "savepoint_opt ::= SAVEPOINT",
 /* 321 */ "savepoint_opt ::=",
 /* 322 */ "cmd ::= create_table create_table_args",
 /* 323 */ "columnlist ::= columnlist COMMA columnname carglist",
 /* 324 */ "columnlist ::= columnname carglist",
 /* 325 */ "nm ::= ID|INDEXED",
 /* 326 */ "nm ::= STRING",
 /* 327 */ "nm ::= JOIN_KW",
 /* 328 */ "typetoken ::= typename",
 /* 329 */ "typename ::= ID|STRING",
 /* 330 */ "signed ::= plus_num",
 /* 331 */ "signed ::= minus_num",
 /* 332 */ "carglist ::= carglist ccons",
 /* 333 */ "carglist ::=",
 /* 334 */ "ccons ::= NULL onconf",
 /* 335 */ "conslist_opt ::= COMMA conslist",
 /* 336 */ "conslist ::= conslist tconscomma tcons",
 /* 337 */ "conslist ::= tcons",
 /* 338 */ "tconscomma ::=",
 /* 339 */ "defer_subclause_opt ::= defer_subclause",
 /* 340 */ "resolvetype ::= raisetype",
 /* 341 */ "selectnowith ::= oneselect",
 /* 342 */ "oneselect ::= values",
 /* 343 */ "sclp ::= selcollist COMMA",
 /* 344 */ "as ::= ID|STRING",
 /* 345 */ "expr ::= term",
 /* 346 */ "likeop ::= LIKE_KW|MATCH",
 /* 347 */ "exprlist ::= nexprlist",
 /* 348 */ "nmnum ::= plus_num",
 /* 349 */ "nmnum ::= nm",
 /* 350 */ "nmnum ::= ON",
 /* 351 */ "nmnum ::= DELETE",
 /* 352 */ "nmnum ::= DEFAULT",
 /* 353 */ "plus_num ::= INTEGER|FLOAT",
 /* 354 */ "foreach_clause ::=",
 /* 355 */ "foreach_clause ::= FOR EACH ROW",
 /* 356 */ "trnm ::= nm",
 /* 357 */ "tridxby ::=",
 /* 358 */ "database_kw_opt ::= DATABASE",
 /* 359 */ "database_kw_opt ::=",
 /* 360 */ "kwcolumn_opt ::=",
 /* 361 */ "kwcolumn_opt ::= COLUMNKW",
 /* 362 */ "vtabarglist ::= vtabarg",
 /* 363 */ "vtabarglist ::= vtabarglist COMMA vtabarg",
 /* 364 */ "vtabarg ::= vtabarg vtabargtoken",
 /* 365 */ "anylist ::=",
 /* 366 */ "anylist ::= anylist LP anylist RP",
 /* 367 */ "anylist ::= anylist ANY",
 /* 368 */ "with ::=",
 /* 307 */ "frame_exclude_opt ::=",
 /* 308 */ "frame_exclude_opt ::= EXCLUDE frame_exclude",
 /* 309 */ "frame_exclude ::= NO OTHERS",
 /* 310 */ "frame_exclude ::= CURRENT ROW",
 /* 311 */ "frame_exclude ::= GROUP|TIES",
 /* 312 */ "window_clause ::= WINDOW windowdefn_list",
 /* 313 */ "over_clause ::= filter_opt OVER LP window RP",
 /* 314 */ "over_clause ::= filter_opt OVER nm",
 /* 315 */ "filter_opt ::=",
 /* 316 */ "filter_opt ::= FILTER LP WHERE expr RP",
 /* 317 */ "input ::= cmdlist",
 /* 318 */ "cmdlist ::= cmdlist ecmd",
 /* 319 */ "cmdlist ::= ecmd",
 /* 320 */ "ecmd ::= SEMI",
 /* 321 */ "ecmd ::= cmdx SEMI",
 /* 322 */ "ecmd ::= explain cmdx",
 /* 323 */ "trans_opt ::=",
 /* 324 */ "trans_opt ::= TRANSACTION",
 /* 325 */ "trans_opt ::= TRANSACTION nm",
 /* 326 */ "savepoint_opt ::= SAVEPOINT",
 /* 327 */ "savepoint_opt ::=",
 /* 328 */ "cmd ::= create_table create_table_args",
 /* 329 */ "columnlist ::= columnlist COMMA columnname carglist",
 /* 330 */ "columnlist ::= columnname carglist",
 /* 331 */ "nm ::= ID|INDEXED",
 /* 332 */ "nm ::= STRING",
 /* 333 */ "nm ::= JOIN_KW",
 /* 334 */ "typetoken ::= typename",
 /* 335 */ "typename ::= ID|STRING",
 /* 336 */ "signed ::= plus_num",
 /* 337 */ "signed ::= minus_num",
 /* 338 */ "carglist ::= carglist ccons",
 /* 339 */ "carglist ::=",
 /* 340 */ "ccons ::= NULL onconf",
 /* 341 */ "conslist_opt ::= COMMA conslist",
 /* 342 */ "conslist ::= conslist tconscomma tcons",
 /* 343 */ "conslist ::= tcons",
 /* 344 */ "tconscomma ::=",
 /* 345 */ "defer_subclause_opt ::= defer_subclause",
 /* 346 */ "resolvetype ::= raisetype",
 /* 347 */ "selectnowith ::= oneselect",
 /* 348 */ "oneselect ::= values",
 /* 349 */ "sclp ::= selcollist COMMA",
 /* 350 */ "as ::= ID|STRING",
 /* 351 */ "expr ::= term",
 /* 352 */ "likeop ::= LIKE_KW|MATCH",
 /* 353 */ "exprlist ::= nexprlist",
 /* 354 */ "nmnum ::= plus_num",
 /* 355 */ "nmnum ::= nm",
 /* 356 */ "nmnum ::= ON",
 /* 357 */ "nmnum ::= DELETE",
 /* 358 */ "nmnum ::= DEFAULT",
 /* 359 */ "plus_num ::= INTEGER|FLOAT",
 /* 360 */ "foreach_clause ::=",
 /* 361 */ "foreach_clause ::= FOR EACH ROW",
 /* 362 */ "trnm ::= nm",
 /* 363 */ "tridxby ::=",
 /* 364 */ "database_kw_opt ::= DATABASE",
 /* 365 */ "database_kw_opt ::=",
 /* 366 */ "kwcolumn_opt ::=",
 /* 367 */ "kwcolumn_opt ::= COLUMNKW",
 /* 368 */ "vtabarglist ::= vtabarg",
 /* 369 */ "vtabarglist ::= vtabarglist COMMA vtabarg",
 /* 370 */ "vtabarg ::= vtabarg vtabargtoken",
 /* 371 */ "anylist ::=",
 /* 372 */ "anylist ::= anylist LP anylist RP",
 /* 373 */ "anylist ::= anylist ANY",
 /* 374 */ "with ::=",
};
#endif /* NDEBUG */


#if YYSTACKDEPTH<=0
/*
** Try to increase the size of the parser stack.  Return the number
149209
149210
149211
149212
149213
149214
149215
149216
149217
149218
149219




149220
149221

149222
149223
149224
149225
149226
149227
149228
149229
149230
149231
149232
149233
149234











149235
149236

149237
149238
149239
149240
149241
149242
149243
149244
149245
149246
149247
149248
149249
149250
149251













149252
149253

149254
149255
149256
149257
149258
149259
149260





149261
149262

149263
149264
149265

149266
149267

149268
149269
149270
149271


149272
149273

149274
149275
149276
149277
149278



149279
149280

149281
149282
149283
149284
149285
149286




149287
149288

149289
149290
149291
149292


149293
149294

149295
149296
149297

149298
149299

149300
149301
149302
149303
149304



149305
149306

149307
149308
149309
149310
149311
149312
149313
150059
150060
150061
150062
150063
150064
150065




150066
150067
150068
150069
150070

150071
150072
150073











150074
150075
150076
150077
150078
150079
150080
150081
150082
150083
150084
150085

150086
150087
150088













150089
150090
150091
150092
150093
150094
150095
150096
150097
150098
150099
150100
150101
150102

150103
150104
150105





150106
150107
150108
150109
150110
150111

150112
150113
150114

150115
150116

150117
150118
150119


150120
150121
150122

150123
150124
150125



150126
150127
150128
150129

150130
150131
150132




150133
150134
150135
150136
150137

150138
150139
150140


150141
150142
150143

150144
150145
150146

150147
150148

150149
150150
150151



150152
150153
150154
150155

150156
150157
150158
150159
150160
150161
150162
150163







-
-
-
-
+
+
+
+

-
+


-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+

-
+


-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+

-
+


-
-
-
-
-
+
+
+
+
+

-
+


-
+

-
+


-
-
+
+

-
+


-
-
-
+
+
+

-
+


-
-
-
-
+
+
+
+

-
+


-
-
+
+

-
+


-
+

-
+


-
-
-
+
+
+

-
+







    ** being destroyed before it is finished parsing.
    **
    ** Note: during a reduce, the only symbols destroyed are those
    ** which appear on the RHS of the rule, but which are *not* used
    ** inside the C code.
    */
/********* Begin destructor definitions ***************************************/
    case 174: /* select */
    case 206: /* selectnowith */
    case 207: /* oneselect */
    case 219: /* values */
    case 195: /* select */
    case 227: /* selectnowith */
    case 228: /* oneselect */
    case 240: /* values */
{
sqlite3SelectDelete(pParse->db, (yypminor->yy423));
sqlite3SelectDelete(pParse->db, (yypminor->yy457));
}
      break;
    case 184: /* term */
    case 185: /* expr */
    case 213: /* where_opt */
    case 215: /* having_opt */
    case 227: /* on_opt */
    case 242: /* case_operand */
    case 244: /* case_else */
    case 247: /* vinto */
    case 254: /* when_clause */
    case 259: /* key_opt */
    case 273: /* filter_opt */
    case 205: /* term */
    case 206: /* expr */
    case 234: /* where_opt */
    case 236: /* having_opt */
    case 248: /* on_opt */
    case 263: /* case_operand */
    case 265: /* case_else */
    case 268: /* vinto */
    case 275: /* when_clause */
    case 280: /* key_opt */
    case 294: /* filter_opt */
{
sqlite3ExprDelete(pParse->db, (yypminor->yy490));
sqlite3ExprDelete(pParse->db, (yypminor->yy524));
}
      break;
    case 189: /* eidlist_opt */
    case 198: /* sortlist */
    case 199: /* eidlist */
    case 211: /* selcollist */
    case 214: /* groupby_opt */
    case 216: /* orderby_opt */
    case 220: /* nexprlist */
    case 221: /* sclp */
    case 229: /* exprlist */
    case 233: /* setlist */
    case 241: /* paren_exprlist */
    case 243: /* case_exprlist */
    case 272: /* part_opt */
    case 210: /* eidlist_opt */
    case 219: /* sortlist */
    case 220: /* eidlist */
    case 232: /* selcollist */
    case 235: /* groupby_opt */
    case 237: /* orderby_opt */
    case 241: /* nexprlist */
    case 242: /* sclp */
    case 250: /* exprlist */
    case 254: /* setlist */
    case 262: /* paren_exprlist */
    case 264: /* case_exprlist */
    case 293: /* part_opt */
{
sqlite3ExprListDelete(pParse->db, (yypminor->yy42));
sqlite3ExprListDelete(pParse->db, (yypminor->yy434));
}
      break;
    case 205: /* fullname */
    case 212: /* from */
    case 223: /* seltablist */
    case 224: /* stl_prefix */
    case 230: /* xfullname */
    case 226: /* fullname */
    case 233: /* from */
    case 244: /* seltablist */
    case 245: /* stl_prefix */
    case 251: /* xfullname */
{
sqlite3SrcListDelete(pParse->db, (yypminor->yy167));
sqlite3SrcListDelete(pParse->db, (yypminor->yy483));
}
      break;
    case 208: /* wqlist */
    case 229: /* wqlist */
{
sqlite3WithDelete(pParse->db, (yypminor->yy499));
sqlite3WithDelete(pParse->db, (yypminor->yy59));
}
      break;
    case 218: /* window_clause */
    case 268: /* windowdefn_list */
    case 239: /* window_clause */
    case 289: /* windowdefn_list */
{
sqlite3WindowListDelete(pParse->db, (yypminor->yy147));
sqlite3WindowListDelete(pParse->db, (yypminor->yy295));
}
      break;
    case 228: /* using_opt */
    case 231: /* idlist */
    case 235: /* idlist_opt */
    case 249: /* using_opt */
    case 252: /* idlist */
    case 256: /* idlist_opt */
{
sqlite3IdListDelete(pParse->db, (yypminor->yy336));
sqlite3IdListDelete(pParse->db, (yypminor->yy62));
}
      break;
    case 237: /* over_clause */
    case 269: /* windowdefn */
    case 270: /* window */
    case 271: /* frame_opt */
    case 258: /* over_clause */
    case 290: /* windowdefn */
    case 291: /* window */
    case 292: /* frame_opt */
{
sqlite3WindowDelete(pParse->db, (yypminor->yy147));
sqlite3WindowDelete(pParse->db, (yypminor->yy295));
}
      break;
    case 250: /* trigger_cmd_list */
    case 255: /* trigger_cmd */
    case 271: /* trigger_cmd_list */
    case 276: /* trigger_cmd */
{
sqlite3DeleteTriggerStep(pParse->db, (yypminor->yy119));
sqlite3DeleteTriggerStep(pParse->db, (yypminor->yy455));
}
      break;
    case 252: /* trigger_event */
    case 273: /* trigger_event */
{
sqlite3IdListDelete(pParse->db, (yypminor->yy350).b);
sqlite3IdListDelete(pParse->db, (yypminor->yy90).b);
}
      break;
    case 275: /* frame_bound */
    case 276: /* frame_bound_s */
    case 277: /* frame_bound_e */
    case 296: /* frame_bound */
    case 297: /* frame_bound_s */
    case 298: /* frame_bound_e */
{
sqlite3ExprDelete(pParse->db, (yypminor->yy317).pExpr);
sqlite3ExprDelete(pParse->db, (yypminor->yy201).pExpr);
}
      break;
/********* End destructor definitions *****************************************/
    default:  break;   /* If no destructor action specified: do nothing */
  }
}

149594
149595
149596
149597
149598
149599
149600
149601
149602
149603
149604
149605
149606
149607
149608
149609
149610
149611
149612
149613
149614
149615
149616
149617
149618
149619
149620
149621
149622
149623
149624
149625
149626
149627
149628
149629
149630
149631
149632
149633
149634
149635
149636
149637
149638
149639
149640
149641
149642
149643
149644
149645
149646
149647
149648
149649
149650
149651
149652
149653
149654
149655
149656
149657
149658
149659
149660
149661
149662
149663
149664
149665
149666
149667
149668
149669
149670
149671
149672
149673
149674
149675
149676
149677
149678
149679
149680
149681
149682
149683
149684
149685
149686
149687
149688
149689
149690
149691
149692
149693
149694
149695
149696
149697
149698
149699
149700
149701
149702
149703
149704
149705
149706
149707
149708
149709
149710
149711
149712
149713
149714
149715
149716
149717
149718
149719
149720
149721
149722
149723
149724
149725
149726
149727
149728
149729
149730
149731
149732
149733
149734
149735
149736
149737
149738
149739
149740
149741
149742
149743
149744
149745
149746
149747
149748
149749
149750
149751
149752
149753
149754
149755
149756
149757
149758
149759
149760
149761
149762
149763
149764
149765
149766
149767
149768
149769
149770
149771
149772
149773
149774
149775
149776
149777
149778
149779
149780
149781
149782
149783
149784
149785
149786
149787
149788
149789
149790
149791
149792
149793
149794
149795
149796
149797
149798
149799
149800
149801
149802
149803
149804
149805
149806
149807
149808
149809
149810
149811
149812
149813
149814
149815
149816
149817
149818
149819
149820
149821
149822
149823
149824
149825
149826
149827
149828
149829
149830
149831
149832
149833
149834
149835
149836
149837
149838
149839
149840
149841
149842
149843
149844
149845
149846
149847
149848
149849
149850
149851
149852
149853
149854
149855
149856
149857
149858
149859
149860
149861
149862
149863
149864
149865
149866
149867
149868
149869
149870
149871
149872
149873
149874
149875
149876
149877
149878
149879
149880
149881
149882
149883
149884
149885
149886
149887
149888
149889
149890
149891
149892
149893
149894
149895
149896
149897
149898













































































































































































































































































































149899
149900
149901
149902
149903
149904
149905
149906
149907
149908
149909
149910
149911
149912
149913
149914
149915
149916
149917
149918
149919
149920
149921
149922
149923
149924
149925
149926
149927
149928
149929
149930
149931
149932
149933
149934
149935
149936
149937
149938
149939
149940
149941
149942
149943
149944
149945
149946
149947
149948
149949
149950
149951
149952
149953
149954
149955
149956
149957
149958
149959
149960
149961
149962
149963
149964
149965
149966
149967
149968
149969










































































149970
149971
149972
149973
149974
149975
149976
150444
150445
150446
150447
150448
150449
150450










































































































































































































































































































150451
150452
150453
150454
150455
150456
150457
150458
150459
150460
150461
150462
150463
150464
150465
150466
150467
150468
150469
150470
150471
150472
150473
150474
150475
150476
150477
150478
150479
150480
150481
150482
150483
150484
150485
150486
150487
150488
150489
150490
150491
150492
150493
150494
150495
150496
150497
150498
150499
150500
150501
150502
150503
150504
150505
150506
150507
150508
150509
150510
150511
150512
150513
150514
150515
150516
150517
150518
150519
150520
150521
150522
150523
150524
150525
150526
150527
150528
150529
150530
150531
150532
150533
150534
150535
150536
150537
150538
150539
150540
150541
150542
150543
150544
150545
150546
150547
150548
150549
150550
150551
150552
150553
150554
150555
150556
150557
150558
150559
150560
150561
150562
150563
150564
150565
150566
150567
150568
150569
150570
150571
150572
150573
150574
150575
150576
150577
150578
150579
150580
150581
150582
150583
150584
150585
150586
150587
150588
150589
150590
150591
150592
150593
150594
150595
150596
150597
150598
150599
150600
150601
150602
150603
150604
150605
150606
150607
150608
150609
150610
150611
150612
150613
150614
150615
150616
150617
150618
150619
150620
150621
150622
150623
150624
150625
150626
150627
150628
150629
150630
150631
150632
150633
150634
150635
150636
150637
150638
150639
150640
150641
150642
150643
150644
150645
150646
150647
150648
150649
150650
150651
150652
150653
150654
150655
150656
150657
150658
150659
150660
150661
150662
150663
150664
150665
150666
150667
150668
150669
150670
150671
150672
150673
150674
150675
150676
150677
150678
150679
150680
150681
150682
150683
150684
150685
150686
150687
150688
150689
150690
150691
150692
150693
150694
150695
150696
150697
150698
150699
150700
150701
150702
150703
150704
150705
150706
150707
150708
150709
150710
150711
150712
150713
150714
150715
150716
150717
150718
150719
150720
150721
150722
150723
150724
150725
150726
150727
150728
150729
150730
150731
150732
150733
150734
150735
150736
150737
150738
150739
150740
150741
150742
150743
150744
150745
150746
150747
150748
150749
150750
150751







































































150752
150753
150754
150755
150756
150757
150758
150759
150760
150761
150762
150763
150764
150765
150766
150767
150768
150769
150770
150771
150772
150773
150774
150775
150776
150777
150778
150779
150780
150781
150782
150783
150784
150785
150786
150787
150788
150789
150790
150791
150792
150793
150794
150795
150796
150797
150798
150799
150800
150801
150802
150803
150804
150805
150806
150807
150808
150809
150810
150811
150812
150813
150814
150815
150816
150817
150818
150819
150820
150821
150822
150823
150824
150825
150826
150827
150828
150829
150830
150831
150832







-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+







  yytos->minor.yy0 = yyMinor;
  yyTraceShift(yypParser, yyNewState, "Shift");
}

/* For rule J, yyRuleInfoLhs[J] contains the symbol on the left-hand side
** of that rule */
static const YYCODETYPE yyRuleInfoLhs[] = {
   159,  /* (0) explain ::= EXPLAIN */
   159,  /* (1) explain ::= EXPLAIN QUERY PLAN */
   158,  /* (2) cmdx ::= cmd */
   160,  /* (3) cmd ::= BEGIN transtype trans_opt */
   161,  /* (4) transtype ::= */
   161,  /* (5) transtype ::= DEFERRED */
   161,  /* (6) transtype ::= IMMEDIATE */
   161,  /* (7) transtype ::= EXCLUSIVE */
   160,  /* (8) cmd ::= COMMIT|END trans_opt */
   160,  /* (9) cmd ::= ROLLBACK trans_opt */
   160,  /* (10) cmd ::= SAVEPOINT nm */
   160,  /* (11) cmd ::= RELEASE savepoint_opt nm */
   160,  /* (12) cmd ::= ROLLBACK trans_opt TO savepoint_opt nm */
   165,  /* (13) create_table ::= createkw temp TABLE ifnotexists nm dbnm */
   167,  /* (14) createkw ::= CREATE */
   169,  /* (15) ifnotexists ::= */
   169,  /* (16) ifnotexists ::= IF NOT EXISTS */
   168,  /* (17) temp ::= TEMP */
   168,  /* (18) temp ::= */
   166,  /* (19) create_table_args ::= LP columnlist conslist_opt RP table_options */
   166,  /* (20) create_table_args ::= AS select */
   173,  /* (21) table_options ::= */
   173,  /* (22) table_options ::= WITHOUT nm */
   175,  /* (23) columnname ::= nm typetoken */
   177,  /* (24) typetoken ::= */
   177,  /* (25) typetoken ::= typename LP signed RP */
   177,  /* (26) typetoken ::= typename LP signed COMMA signed RP */
   178,  /* (27) typename ::= typename ID|STRING */
   182,  /* (28) scanpt ::= */
   183,  /* (29) ccons ::= CONSTRAINT nm */
   183,  /* (30) ccons ::= DEFAULT scanpt term scanpt */
   183,  /* (31) ccons ::= DEFAULT LP expr RP */
   183,  /* (32) ccons ::= DEFAULT PLUS term scanpt */
   183,  /* (33) ccons ::= DEFAULT MINUS term scanpt */
   183,  /* (34) ccons ::= DEFAULT scanpt ID|INDEXED */
   183,  /* (35) ccons ::= NOT NULL onconf */
   183,  /* (36) ccons ::= PRIMARY KEY sortorder onconf autoinc */
   183,  /* (37) ccons ::= UNIQUE onconf */
   183,  /* (38) ccons ::= CHECK LP expr RP */
   183,  /* (39) ccons ::= REFERENCES nm eidlist_opt refargs */
   183,  /* (40) ccons ::= defer_subclause */
   183,  /* (41) ccons ::= COLLATE ID|STRING */
   188,  /* (42) autoinc ::= */
   188,  /* (43) autoinc ::= AUTOINCR */
   190,  /* (44) refargs ::= */
   190,  /* (45) refargs ::= refargs refarg */
   192,  /* (46) refarg ::= MATCH nm */
   192,  /* (47) refarg ::= ON INSERT refact */
   192,  /* (48) refarg ::= ON DELETE refact */
   192,  /* (49) refarg ::= ON UPDATE refact */
   193,  /* (50) refact ::= SET NULL */
   193,  /* (51) refact ::= SET DEFAULT */
   193,  /* (52) refact ::= CASCADE */
   193,  /* (53) refact ::= RESTRICT */
   193,  /* (54) refact ::= NO ACTION */
   191,  /* (55) defer_subclause ::= NOT DEFERRABLE init_deferred_pred_opt */
   191,  /* (56) defer_subclause ::= DEFERRABLE init_deferred_pred_opt */
   194,  /* (57) init_deferred_pred_opt ::= */
   194,  /* (58) init_deferred_pred_opt ::= INITIALLY DEFERRED */
   194,  /* (59) init_deferred_pred_opt ::= INITIALLY IMMEDIATE */
   172,  /* (60) conslist_opt ::= */
   196,  /* (61) tconscomma ::= COMMA */
   197,  /* (62) tcons ::= CONSTRAINT nm */
   197,  /* (63) tcons ::= PRIMARY KEY LP sortlist autoinc RP onconf */
   197,  /* (64) tcons ::= UNIQUE LP sortlist RP onconf */
   197,  /* (65) tcons ::= CHECK LP expr RP onconf */
   197,  /* (66) tcons ::= FOREIGN KEY LP eidlist RP REFERENCES nm eidlist_opt refargs defer_subclause_opt */
   200,  /* (67) defer_subclause_opt ::= */
   186,  /* (68) onconf ::= */
   186,  /* (69) onconf ::= ON CONFLICT resolvetype */
   201,  /* (70) orconf ::= */
   201,  /* (71) orconf ::= OR resolvetype */
   202,  /* (72) resolvetype ::= IGNORE */
   202,  /* (73) resolvetype ::= REPLACE */
   160,  /* (74) cmd ::= DROP TABLE ifexists fullname */
   204,  /* (75) ifexists ::= IF EXISTS */
   204,  /* (76) ifexists ::= */
   160,  /* (77) cmd ::= createkw temp VIEW ifnotexists nm dbnm eidlist_opt AS select */
   160,  /* (78) cmd ::= DROP VIEW ifexists fullname */
   160,  /* (79) cmd ::= select */
   174,  /* (80) select ::= WITH wqlist selectnowith */
   174,  /* (81) select ::= WITH RECURSIVE wqlist selectnowith */
   174,  /* (82) select ::= selectnowith */
   206,  /* (83) selectnowith ::= selectnowith multiselect_op oneselect */
   209,  /* (84) multiselect_op ::= UNION */
   209,  /* (85) multiselect_op ::= UNION ALL */
   209,  /* (86) multiselect_op ::= EXCEPT|INTERSECT */
   207,  /* (87) oneselect ::= SELECT distinct selcollist from where_opt groupby_opt having_opt orderby_opt limit_opt */
   207,  /* (88) oneselect ::= SELECT distinct selcollist from where_opt groupby_opt having_opt window_clause orderby_opt limit_opt */
   219,  /* (89) values ::= VALUES LP nexprlist RP */
   219,  /* (90) values ::= values COMMA LP nexprlist RP */
   210,  /* (91) distinct ::= DISTINCT */
   210,  /* (92) distinct ::= ALL */
   210,  /* (93) distinct ::= */
   221,  /* (94) sclp ::= */
   211,  /* (95) selcollist ::= sclp scanpt expr scanpt as */
   211,  /* (96) selcollist ::= sclp scanpt STAR */
   211,  /* (97) selcollist ::= sclp scanpt nm DOT STAR */
   222,  /* (98) as ::= AS nm */
   222,  /* (99) as ::= */
   212,  /* (100) from ::= */
   212,  /* (101) from ::= FROM seltablist */
   224,  /* (102) stl_prefix ::= seltablist joinop */
   224,  /* (103) stl_prefix ::= */
   223,  /* (104) seltablist ::= stl_prefix nm dbnm as indexed_opt on_opt using_opt */
   223,  /* (105) seltablist ::= stl_prefix nm dbnm LP exprlist RP as on_opt using_opt */
   223,  /* (106) seltablist ::= stl_prefix LP select RP as on_opt using_opt */
   223,  /* (107) seltablist ::= stl_prefix LP seltablist RP as on_opt using_opt */
   170,  /* (108) dbnm ::= */
   170,  /* (109) dbnm ::= DOT nm */
   205,  /* (110) fullname ::= nm */
   205,  /* (111) fullname ::= nm DOT nm */
   230,  /* (112) xfullname ::= nm */
   230,  /* (113) xfullname ::= nm DOT nm */
   230,  /* (114) xfullname ::= nm DOT nm AS nm */
   230,  /* (115) xfullname ::= nm AS nm */
   225,  /* (116) joinop ::= COMMA|JOIN */
   225,  /* (117) joinop ::= JOIN_KW JOIN */
   225,  /* (118) joinop ::= JOIN_KW nm JOIN */
   225,  /* (119) joinop ::= JOIN_KW nm nm JOIN */
   227,  /* (120) on_opt ::= ON expr */
   227,  /* (121) on_opt ::= */
   226,  /* (122) indexed_opt ::= */
   226,  /* (123) indexed_opt ::= INDEXED BY nm */
   226,  /* (124) indexed_opt ::= NOT INDEXED */
   228,  /* (125) using_opt ::= USING LP idlist RP */
   228,  /* (126) using_opt ::= */
   216,  /* (127) orderby_opt ::= */
   216,  /* (128) orderby_opt ::= ORDER BY sortlist */
   198,  /* (129) sortlist ::= sortlist COMMA expr sortorder */
   198,  /* (130) sortlist ::= expr sortorder */
   187,  /* (131) sortorder ::= ASC */
   187,  /* (132) sortorder ::= DESC */
   187,  /* (133) sortorder ::= */
   214,  /* (134) groupby_opt ::= */
   214,  /* (135) groupby_opt ::= GROUP BY nexprlist */
   215,  /* (136) having_opt ::= */
   215,  /* (137) having_opt ::= HAVING expr */
   217,  /* (138) limit_opt ::= */
   217,  /* (139) limit_opt ::= LIMIT expr */
   217,  /* (140) limit_opt ::= LIMIT expr OFFSET expr */
   217,  /* (141) limit_opt ::= LIMIT expr COMMA expr */
   160,  /* (142) cmd ::= with DELETE FROM xfullname indexed_opt where_opt */
   213,  /* (143) where_opt ::= */
   213,  /* (144) where_opt ::= WHERE expr */
   160,  /* (145) cmd ::= with UPDATE orconf xfullname indexed_opt SET setlist where_opt */
   233,  /* (146) setlist ::= setlist COMMA nm EQ expr */
   233,  /* (147) setlist ::= setlist COMMA LP idlist RP EQ expr */
   233,  /* (148) setlist ::= nm EQ expr */
   233,  /* (149) setlist ::= LP idlist RP EQ expr */
   160,  /* (150) cmd ::= with insert_cmd INTO xfullname idlist_opt select upsert */
   160,  /* (151) cmd ::= with insert_cmd INTO xfullname idlist_opt DEFAULT VALUES */
   236,  /* (152) upsert ::= */
   236,  /* (153) upsert ::= ON CONFLICT LP sortlist RP where_opt DO UPDATE SET setlist where_opt */
   236,  /* (154) upsert ::= ON CONFLICT LP sortlist RP where_opt DO NOTHING */
   236,  /* (155) upsert ::= ON CONFLICT DO NOTHING */
   234,  /* (156) insert_cmd ::= INSERT orconf */
   234,  /* (157) insert_cmd ::= REPLACE */
   235,  /* (158) idlist_opt ::= */
   235,  /* (159) idlist_opt ::= LP idlist RP */
   231,  /* (160) idlist ::= idlist COMMA nm */
   231,  /* (161) idlist ::= nm */
   185,  /* (162) expr ::= LP expr RP */
   185,  /* (163) expr ::= ID|INDEXED */
   185,  /* (164) expr ::= JOIN_KW */
   185,  /* (165) expr ::= nm DOT nm */
   185,  /* (166) expr ::= nm DOT nm DOT nm */
   184,  /* (167) term ::= NULL|FLOAT|BLOB */
   184,  /* (168) term ::= STRING */
   184,  /* (169) term ::= INTEGER */
   185,  /* (170) expr ::= VARIABLE */
   185,  /* (171) expr ::= expr COLLATE ID|STRING */
   185,  /* (172) expr ::= CAST LP expr AS typetoken RP */
   185,  /* (173) expr ::= ID|INDEXED LP distinct exprlist RP */
   185,  /* (174) expr ::= ID|INDEXED LP STAR RP */
   185,  /* (175) expr ::= ID|INDEXED LP distinct exprlist RP over_clause */
   185,  /* (176) expr ::= ID|INDEXED LP STAR RP over_clause */
   184,  /* (177) term ::= CTIME_KW */
   185,  /* (178) expr ::= LP nexprlist COMMA expr RP */
   185,  /* (179) expr ::= expr AND expr */
   185,  /* (180) expr ::= expr OR expr */
   185,  /* (181) expr ::= expr LT|GT|GE|LE expr */
   185,  /* (182) expr ::= expr EQ|NE expr */
   185,  /* (183) expr ::= expr BITAND|BITOR|LSHIFT|RSHIFT expr */
   185,  /* (184) expr ::= expr PLUS|MINUS expr */
   185,  /* (185) expr ::= expr STAR|SLASH|REM expr */
   185,  /* (186) expr ::= expr CONCAT expr */
   238,  /* (187) likeop ::= NOT LIKE_KW|MATCH */
   185,  /* (188) expr ::= expr likeop expr */
   185,  /* (189) expr ::= expr likeop expr ESCAPE expr */
   185,  /* (190) expr ::= expr ISNULL|NOTNULL */
   185,  /* (191) expr ::= expr NOT NULL */
   185,  /* (192) expr ::= expr IS expr */
   185,  /* (193) expr ::= expr IS NOT expr */
   185,  /* (194) expr ::= NOT expr */
   185,  /* (195) expr ::= BITNOT expr */
   185,  /* (196) expr ::= PLUS|MINUS expr */
   239,  /* (197) between_op ::= BETWEEN */
   239,  /* (198) between_op ::= NOT BETWEEN */
   185,  /* (199) expr ::= expr between_op expr AND expr */
   240,  /* (200) in_op ::= IN */
   240,  /* (201) in_op ::= NOT IN */
   185,  /* (202) expr ::= expr in_op LP exprlist RP */
   185,  /* (203) expr ::= LP select RP */
   185,  /* (204) expr ::= expr in_op LP select RP */
   185,  /* (205) expr ::= expr in_op nm dbnm paren_exprlist */
   185,  /* (206) expr ::= EXISTS LP select RP */
   185,  /* (207) expr ::= CASE case_operand case_exprlist case_else END */
   243,  /* (208) case_exprlist ::= case_exprlist WHEN expr THEN expr */
   243,  /* (209) case_exprlist ::= WHEN expr THEN expr */
   244,  /* (210) case_else ::= ELSE expr */
   244,  /* (211) case_else ::= */
   242,  /* (212) case_operand ::= expr */
   242,  /* (213) case_operand ::= */
   229,  /* (214) exprlist ::= */
   220,  /* (215) nexprlist ::= nexprlist COMMA expr */
   220,  /* (216) nexprlist ::= expr */
   241,  /* (217) paren_exprlist ::= */
   241,  /* (218) paren_exprlist ::= LP exprlist RP */
   160,  /* (219) cmd ::= createkw uniqueflag INDEX ifnotexists nm dbnm ON nm LP sortlist RP where_opt */
   245,  /* (220) uniqueflag ::= UNIQUE */
   245,  /* (221) uniqueflag ::= */
   189,  /* (222) eidlist_opt ::= */
   189,  /* (223) eidlist_opt ::= LP eidlist RP */
   199,  /* (224) eidlist ::= eidlist COMMA nm collate sortorder */
   199,  /* (225) eidlist ::= nm collate sortorder */
   246,  /* (226) collate ::= */
   246,  /* (227) collate ::= COLLATE ID|STRING */
   160,  /* (228) cmd ::= DROP INDEX ifexists fullname */
   160,  /* (229) cmd ::= VACUUM vinto */
   160,  /* (230) cmd ::= VACUUM nm vinto */
   247,  /* (231) vinto ::= INTO expr */
   247,  /* (232) vinto ::= */
   160,  /* (233) cmd ::= PRAGMA nm dbnm */
   160,  /* (234) cmd ::= PRAGMA nm dbnm EQ nmnum */
   160,  /* (235) cmd ::= PRAGMA nm dbnm LP nmnum RP */
   160,  /* (236) cmd ::= PRAGMA nm dbnm EQ minus_num */
   160,  /* (237) cmd ::= PRAGMA nm dbnm LP minus_num RP */
   180,  /* (238) plus_num ::= PLUS INTEGER|FLOAT */
   181,  /* (239) minus_num ::= MINUS INTEGER|FLOAT */
   160,  /* (240) cmd ::= createkw trigger_decl BEGIN trigger_cmd_list END */
   249,  /* (241) trigger_decl ::= temp TRIGGER ifnotexists nm dbnm trigger_time trigger_event ON fullname foreach_clause when_clause */
   251,  /* (242) trigger_time ::= BEFORE|AFTER */
   251,  /* (243) trigger_time ::= INSTEAD OF */
   251,  /* (244) trigger_time ::= */
   252,  /* (245) trigger_event ::= DELETE|INSERT */
   252,  /* (246) trigger_event ::= UPDATE */
   252,  /* (247) trigger_event ::= UPDATE OF idlist */
   254,  /* (248) when_clause ::= */
   254,  /* (249) when_clause ::= WHEN expr */
   250,  /* (250) trigger_cmd_list ::= trigger_cmd_list trigger_cmd SEMI */
   250,  /* (251) trigger_cmd_list ::= trigger_cmd SEMI */
   256,  /* (252) trnm ::= nm DOT nm */
   257,  /* (253) tridxby ::= INDEXED BY nm */
   257,  /* (254) tridxby ::= NOT INDEXED */
   255,  /* (255) trigger_cmd ::= UPDATE orconf trnm tridxby SET setlist where_opt scanpt */
   255,  /* (256) trigger_cmd ::= scanpt insert_cmd INTO trnm idlist_opt select upsert scanpt */
   255,  /* (257) trigger_cmd ::= DELETE FROM trnm tridxby where_opt scanpt */
   255,  /* (258) trigger_cmd ::= scanpt select scanpt */
   185,  /* (259) expr ::= RAISE LP IGNORE RP */
   185,  /* (260) expr ::= RAISE LP raisetype COMMA nm RP */
   203,  /* (261) raisetype ::= ROLLBACK */
   203,  /* (262) raisetype ::= ABORT */
   203,  /* (263) raisetype ::= FAIL */
   160,  /* (264) cmd ::= DROP TRIGGER ifexists fullname */
   160,  /* (265) cmd ::= ATTACH database_kw_opt expr AS expr key_opt */
   160,  /* (266) cmd ::= DETACH database_kw_opt expr */
   259,  /* (267) key_opt ::= */
   259,  /* (268) key_opt ::= KEY expr */
   160,  /* (269) cmd ::= REINDEX */
   160,  /* (270) cmd ::= REINDEX nm dbnm */
   160,  /* (271) cmd ::= ANALYZE */
   160,  /* (272) cmd ::= ANALYZE nm dbnm */
   160,  /* (273) cmd ::= ALTER TABLE fullname RENAME TO nm */
   160,  /* (274) cmd ::= ALTER TABLE add_column_fullname ADD kwcolumn_opt columnname carglist */
   260,  /* (275) add_column_fullname ::= fullname */
   160,  /* (276) cmd ::= ALTER TABLE fullname RENAME kwcolumn_opt nm TO nm */
   160,  /* (277) cmd ::= create_vtab */
   160,  /* (278) cmd ::= create_vtab LP vtabarglist RP */
   262,  /* (279) create_vtab ::= createkw VIRTUAL TABLE ifnotexists nm dbnm USING nm */
   264,  /* (280) vtabarg ::= */
   265,  /* (281) vtabargtoken ::= ANY */
   265,  /* (282) vtabargtoken ::= lp anylist RP */
   266,  /* (283) lp ::= LP */
   232,  /* (284) with ::= WITH wqlist */
   232,  /* (285) with ::= WITH RECURSIVE wqlist */
   208,  /* (286) wqlist ::= nm eidlist_opt AS LP select RP */
   208,  /* (287) wqlist ::= wqlist COMMA nm eidlist_opt AS LP select RP */
   268,  /* (288) windowdefn_list ::= windowdefn */
   268,  /* (289) windowdefn_list ::= windowdefn_list COMMA windowdefn */
   269,  /* (290) windowdefn ::= nm AS window */
   270,  /* (291) window ::= LP part_opt orderby_opt frame_opt RP */
   272,  /* (292) part_opt ::= PARTITION BY nexprlist */
   272,  /* (293) part_opt ::= */
   271,  /* (294) frame_opt ::= */
   271,  /* (295) frame_opt ::= range_or_rows frame_bound_s */
   271,  /* (296) frame_opt ::= range_or_rows BETWEEN frame_bound_s AND frame_bound_e */
   274,  /* (297) range_or_rows ::= RANGE */
   180,  /* (0) explain ::= EXPLAIN */
   180,  /* (1) explain ::= EXPLAIN QUERY PLAN */
   179,  /* (2) cmdx ::= cmd */
   181,  /* (3) cmd ::= BEGIN transtype trans_opt */
   182,  /* (4) transtype ::= */
   182,  /* (5) transtype ::= DEFERRED */
   182,  /* (6) transtype ::= IMMEDIATE */
   182,  /* (7) transtype ::= EXCLUSIVE */
   181,  /* (8) cmd ::= COMMIT|END trans_opt */
   181,  /* (9) cmd ::= ROLLBACK trans_opt */
   181,  /* (10) cmd ::= SAVEPOINT nm */
   181,  /* (11) cmd ::= RELEASE savepoint_opt nm */
   181,  /* (12) cmd ::= ROLLBACK trans_opt TO savepoint_opt nm */
   186,  /* (13) create_table ::= createkw temp TABLE ifnotexists nm dbnm */
   188,  /* (14) createkw ::= CREATE */
   190,  /* (15) ifnotexists ::= */
   190,  /* (16) ifnotexists ::= IF NOT EXISTS */
   189,  /* (17) temp ::= TEMP */
   189,  /* (18) temp ::= */
   187,  /* (19) create_table_args ::= LP columnlist conslist_opt RP table_options */
   187,  /* (20) create_table_args ::= AS select */
   194,  /* (21) table_options ::= */
   194,  /* (22) table_options ::= WITHOUT nm */
   196,  /* (23) columnname ::= nm typetoken */
   198,  /* (24) typetoken ::= */
   198,  /* (25) typetoken ::= typename LP signed RP */
   198,  /* (26) typetoken ::= typename LP signed COMMA signed RP */
   199,  /* (27) typename ::= typename ID|STRING */
   203,  /* (28) scanpt ::= */
   204,  /* (29) ccons ::= CONSTRAINT nm */
   204,  /* (30) ccons ::= DEFAULT scanpt term scanpt */
   204,  /* (31) ccons ::= DEFAULT LP expr RP */
   204,  /* (32) ccons ::= DEFAULT PLUS term scanpt */
   204,  /* (33) ccons ::= DEFAULT MINUS term scanpt */
   204,  /* (34) ccons ::= DEFAULT scanpt ID|INDEXED */
   204,  /* (35) ccons ::= NOT NULL onconf */
   204,  /* (36) ccons ::= PRIMARY KEY sortorder onconf autoinc */
   204,  /* (37) ccons ::= UNIQUE onconf */
   204,  /* (38) ccons ::= CHECK LP expr RP */
   204,  /* (39) ccons ::= REFERENCES nm eidlist_opt refargs */
   204,  /* (40) ccons ::= defer_subclause */
   204,  /* (41) ccons ::= COLLATE ID|STRING */
   209,  /* (42) autoinc ::= */
   209,  /* (43) autoinc ::= AUTOINCR */
   211,  /* (44) refargs ::= */
   211,  /* (45) refargs ::= refargs refarg */
   213,  /* (46) refarg ::= MATCH nm */
   213,  /* (47) refarg ::= ON INSERT refact */
   213,  /* (48) refarg ::= ON DELETE refact */
   213,  /* (49) refarg ::= ON UPDATE refact */
   214,  /* (50) refact ::= SET NULL */
   214,  /* (51) refact ::= SET DEFAULT */
   214,  /* (52) refact ::= CASCADE */
   214,  /* (53) refact ::= RESTRICT */
   214,  /* (54) refact ::= NO ACTION */
   212,  /* (55) defer_subclause ::= NOT DEFERRABLE init_deferred_pred_opt */
   212,  /* (56) defer_subclause ::= DEFERRABLE init_deferred_pred_opt */
   215,  /* (57) init_deferred_pred_opt ::= */
   215,  /* (58) init_deferred_pred_opt ::= INITIALLY DEFERRED */
   215,  /* (59) init_deferred_pred_opt ::= INITIALLY IMMEDIATE */
   193,  /* (60) conslist_opt ::= */
   217,  /* (61) tconscomma ::= COMMA */
   218,  /* (62) tcons ::= CONSTRAINT nm */
   218,  /* (63) tcons ::= PRIMARY KEY LP sortlist autoinc RP onconf */
   218,  /* (64) tcons ::= UNIQUE LP sortlist RP onconf */
   218,  /* (65) tcons ::= CHECK LP expr RP onconf */
   218,  /* (66) tcons ::= FOREIGN KEY LP eidlist RP REFERENCES nm eidlist_opt refargs defer_subclause_opt */
   221,  /* (67) defer_subclause_opt ::= */
   207,  /* (68) onconf ::= */
   207,  /* (69) onconf ::= ON CONFLICT resolvetype */
   222,  /* (70) orconf ::= */
   222,  /* (71) orconf ::= OR resolvetype */
   223,  /* (72) resolvetype ::= IGNORE */
   223,  /* (73) resolvetype ::= REPLACE */
   181,  /* (74) cmd ::= DROP TABLE ifexists fullname */
   225,  /* (75) ifexists ::= IF EXISTS */
   225,  /* (76) ifexists ::= */
   181,  /* (77) cmd ::= createkw temp VIEW ifnotexists nm dbnm eidlist_opt AS select */
   181,  /* (78) cmd ::= DROP VIEW ifexists fullname */
   181,  /* (79) cmd ::= select */
   195,  /* (80) select ::= WITH wqlist selectnowith */
   195,  /* (81) select ::= WITH RECURSIVE wqlist selectnowith */
   195,  /* (82) select ::= selectnowith */
   227,  /* (83) selectnowith ::= selectnowith multiselect_op oneselect */
   230,  /* (84) multiselect_op ::= UNION */
   230,  /* (85) multiselect_op ::= UNION ALL */
   230,  /* (86) multiselect_op ::= EXCEPT|INTERSECT */
   228,  /* (87) oneselect ::= SELECT distinct selcollist from where_opt groupby_opt having_opt orderby_opt limit_opt */
   228,  /* (88) oneselect ::= SELECT distinct selcollist from where_opt groupby_opt having_opt window_clause orderby_opt limit_opt */
   240,  /* (89) values ::= VALUES LP nexprlist RP */
   240,  /* (90) values ::= values COMMA LP nexprlist RP */
   231,  /* (91) distinct ::= DISTINCT */
   231,  /* (92) distinct ::= ALL */
   231,  /* (93) distinct ::= */
   242,  /* (94) sclp ::= */
   232,  /* (95) selcollist ::= sclp scanpt expr scanpt as */
   232,  /* (96) selcollist ::= sclp scanpt STAR */
   232,  /* (97) selcollist ::= sclp scanpt nm DOT STAR */
   243,  /* (98) as ::= AS nm */
   243,  /* (99) as ::= */
   233,  /* (100) from ::= */
   233,  /* (101) from ::= FROM seltablist */
   245,  /* (102) stl_prefix ::= seltablist joinop */
   245,  /* (103) stl_prefix ::= */
   244,  /* (104) seltablist ::= stl_prefix nm dbnm as indexed_opt on_opt using_opt */
   244,  /* (105) seltablist ::= stl_prefix nm dbnm LP exprlist RP as on_opt using_opt */
   244,  /* (106) seltablist ::= stl_prefix LP select RP as on_opt using_opt */
   244,  /* (107) seltablist ::= stl_prefix LP seltablist RP as on_opt using_opt */
   191,  /* (108) dbnm ::= */
   191,  /* (109) dbnm ::= DOT nm */
   226,  /* (110) fullname ::= nm */
   226,  /* (111) fullname ::= nm DOT nm */
   251,  /* (112) xfullname ::= nm */
   251,  /* (113) xfullname ::= nm DOT nm */
   251,  /* (114) xfullname ::= nm DOT nm AS nm */
   251,  /* (115) xfullname ::= nm AS nm */
   246,  /* (116) joinop ::= COMMA|JOIN */
   246,  /* (117) joinop ::= JOIN_KW JOIN */
   246,  /* (118) joinop ::= JOIN_KW nm JOIN */
   246,  /* (119) joinop ::= JOIN_KW nm nm JOIN */
   248,  /* (120) on_opt ::= ON expr */
   248,  /* (121) on_opt ::= */
   247,  /* (122) indexed_opt ::= */
   247,  /* (123) indexed_opt ::= INDEXED BY nm */
   247,  /* (124) indexed_opt ::= NOT INDEXED */
   249,  /* (125) using_opt ::= USING LP idlist RP */
   249,  /* (126) using_opt ::= */
   237,  /* (127) orderby_opt ::= */
   237,  /* (128) orderby_opt ::= ORDER BY sortlist */
   219,  /* (129) sortlist ::= sortlist COMMA expr sortorder */
   219,  /* (130) sortlist ::= expr sortorder */
   208,  /* (131) sortorder ::= ASC */
   208,  /* (132) sortorder ::= DESC */
   208,  /* (133) sortorder ::= */
   235,  /* (134) groupby_opt ::= */
   235,  /* (135) groupby_opt ::= GROUP BY nexprlist */
   236,  /* (136) having_opt ::= */
   236,  /* (137) having_opt ::= HAVING expr */
   238,  /* (138) limit_opt ::= */
   238,  /* (139) limit_opt ::= LIMIT expr */
   238,  /* (140) limit_opt ::= LIMIT expr OFFSET expr */
   238,  /* (141) limit_opt ::= LIMIT expr COMMA expr */
   181,  /* (142) cmd ::= with DELETE FROM xfullname indexed_opt where_opt */
   234,  /* (143) where_opt ::= */
   234,  /* (144) where_opt ::= WHERE expr */
   181,  /* (145) cmd ::= with UPDATE orconf xfullname indexed_opt SET setlist where_opt */
   254,  /* (146) setlist ::= setlist COMMA nm EQ expr */
   254,  /* (147) setlist ::= setlist COMMA LP idlist RP EQ expr */
   254,  /* (148) setlist ::= nm EQ expr */
   254,  /* (149) setlist ::= LP idlist RP EQ expr */
   181,  /* (150) cmd ::= with insert_cmd INTO xfullname idlist_opt select upsert */
   181,  /* (151) cmd ::= with insert_cmd INTO xfullname idlist_opt DEFAULT VALUES */
   257,  /* (152) upsert ::= */
   257,  /* (153) upsert ::= ON CONFLICT LP sortlist RP where_opt DO UPDATE SET setlist where_opt */
   257,  /* (154) upsert ::= ON CONFLICT LP sortlist RP where_opt DO NOTHING */
   257,  /* (155) upsert ::= ON CONFLICT DO NOTHING */
   255,  /* (156) insert_cmd ::= INSERT orconf */
   255,  /* (157) insert_cmd ::= REPLACE */
   256,  /* (158) idlist_opt ::= */
   256,  /* (159) idlist_opt ::= LP idlist RP */
   252,  /* (160) idlist ::= idlist COMMA nm */
   252,  /* (161) idlist ::= nm */
   206,  /* (162) expr ::= LP expr RP */
   206,  /* (163) expr ::= ID|INDEXED */
   206,  /* (164) expr ::= JOIN_KW */
   206,  /* (165) expr ::= nm DOT nm */
   206,  /* (166) expr ::= nm DOT nm DOT nm */
   205,  /* (167) term ::= NULL|FLOAT|BLOB */
   205,  /* (168) term ::= STRING */
   205,  /* (169) term ::= INTEGER */
   206,  /* (170) expr ::= VARIABLE */
   206,  /* (171) expr ::= expr COLLATE ID|STRING */
   206,  /* (172) expr ::= CAST LP expr AS typetoken RP */
   206,  /* (173) expr ::= ID|INDEXED LP distinct exprlist RP */
   206,  /* (174) expr ::= ID|INDEXED LP STAR RP */
   206,  /* (175) expr ::= ID|INDEXED LP distinct exprlist RP over_clause */
   206,  /* (176) expr ::= ID|INDEXED LP STAR RP over_clause */
   205,  /* (177) term ::= CTIME_KW */
   206,  /* (178) expr ::= LP nexprlist COMMA expr RP */
   206,  /* (179) expr ::= expr AND expr */
   206,  /* (180) expr ::= expr OR expr */
   206,  /* (181) expr ::= expr LT|GT|GE|LE expr */
   206,  /* (182) expr ::= expr EQ|NE expr */
   206,  /* (183) expr ::= expr BITAND|BITOR|LSHIFT|RSHIFT expr */
   206,  /* (184) expr ::= expr PLUS|MINUS expr */
   206,  /* (185) expr ::= expr STAR|SLASH|REM expr */
   206,  /* (186) expr ::= expr CONCAT expr */
   259,  /* (187) likeop ::= NOT LIKE_KW|MATCH */
   206,  /* (188) expr ::= expr likeop expr */
   206,  /* (189) expr ::= expr likeop expr ESCAPE expr */
   206,  /* (190) expr ::= expr ISNULL|NOTNULL */
   206,  /* (191) expr ::= expr NOT NULL */
   206,  /* (192) expr ::= expr IS expr */
   206,  /* (193) expr ::= expr IS NOT expr */
   206,  /* (194) expr ::= NOT expr */
   206,  /* (195) expr ::= BITNOT expr */
   206,  /* (196) expr ::= PLUS|MINUS expr */
   260,  /* (197) between_op ::= BETWEEN */
   260,  /* (198) between_op ::= NOT BETWEEN */
   206,  /* (199) expr ::= expr between_op expr AND expr */
   261,  /* (200) in_op ::= IN */
   261,  /* (201) in_op ::= NOT IN */
   206,  /* (202) expr ::= expr in_op LP exprlist RP */
   206,  /* (203) expr ::= LP select RP */
   206,  /* (204) expr ::= expr in_op LP select RP */
   206,  /* (205) expr ::= expr in_op nm dbnm paren_exprlist */
   206,  /* (206) expr ::= EXISTS LP select RP */
   206,  /* (207) expr ::= CASE case_operand case_exprlist case_else END */
   264,  /* (208) case_exprlist ::= case_exprlist WHEN expr THEN expr */
   264,  /* (209) case_exprlist ::= WHEN expr THEN expr */
   265,  /* (210) case_else ::= ELSE expr */
   265,  /* (211) case_else ::= */
   263,  /* (212) case_operand ::= expr */
   263,  /* (213) case_operand ::= */
   250,  /* (214) exprlist ::= */
   241,  /* (215) nexprlist ::= nexprlist COMMA expr */
   241,  /* (216) nexprlist ::= expr */
   262,  /* (217) paren_exprlist ::= */
   262,  /* (218) paren_exprlist ::= LP exprlist RP */
   181,  /* (219) cmd ::= createkw uniqueflag INDEX ifnotexists nm dbnm ON nm LP sortlist RP where_opt */
   266,  /* (220) uniqueflag ::= UNIQUE */
   266,  /* (221) uniqueflag ::= */
   210,  /* (222) eidlist_opt ::= */
   210,  /* (223) eidlist_opt ::= LP eidlist RP */
   220,  /* (224) eidlist ::= eidlist COMMA nm collate sortorder */
   220,  /* (225) eidlist ::= nm collate sortorder */
   267,  /* (226) collate ::= */
   267,  /* (227) collate ::= COLLATE ID|STRING */
   181,  /* (228) cmd ::= DROP INDEX ifexists fullname */
   181,  /* (229) cmd ::= VACUUM vinto */
   181,  /* (230) cmd ::= VACUUM nm vinto */
   268,  /* (231) vinto ::= INTO expr */
   268,  /* (232) vinto ::= */
   181,  /* (233) cmd ::= PRAGMA nm dbnm */
   181,  /* (234) cmd ::= PRAGMA nm dbnm EQ nmnum */
   181,  /* (235) cmd ::= PRAGMA nm dbnm LP nmnum RP */
   181,  /* (236) cmd ::= PRAGMA nm dbnm EQ minus_num */
   181,  /* (237) cmd ::= PRAGMA nm dbnm LP minus_num RP */
   201,  /* (238) plus_num ::= PLUS INTEGER|FLOAT */
   202,  /* (239) minus_num ::= MINUS INTEGER|FLOAT */
   181,  /* (240) cmd ::= createkw trigger_decl BEGIN trigger_cmd_list END */
   270,  /* (241) trigger_decl ::= temp TRIGGER ifnotexists nm dbnm trigger_time trigger_event ON fullname foreach_clause when_clause */
   272,  /* (242) trigger_time ::= BEFORE|AFTER */
   272,  /* (243) trigger_time ::= INSTEAD OF */
   272,  /* (244) trigger_time ::= */
   273,  /* (245) trigger_event ::= DELETE|INSERT */
   273,  /* (246) trigger_event ::= UPDATE */
   273,  /* (247) trigger_event ::= UPDATE OF idlist */
   275,  /* (248) when_clause ::= */
   275,  /* (249) when_clause ::= WHEN expr */
   271,  /* (250) trigger_cmd_list ::= trigger_cmd_list trigger_cmd SEMI */
   271,  /* (251) trigger_cmd_list ::= trigger_cmd SEMI */
   277,  /* (252) trnm ::= nm DOT nm */
   278,  /* (253) tridxby ::= INDEXED BY nm */
   278,  /* (254) tridxby ::= NOT INDEXED */
   276,  /* (255) trigger_cmd ::= UPDATE orconf trnm tridxby SET setlist where_opt scanpt */
   276,  /* (256) trigger_cmd ::= scanpt insert_cmd INTO trnm idlist_opt select upsert scanpt */
   276,  /* (257) trigger_cmd ::= DELETE FROM trnm tridxby where_opt scanpt */
   276,  /* (258) trigger_cmd ::= scanpt select scanpt */
   206,  /* (259) expr ::= RAISE LP IGNORE RP */
   206,  /* (260) expr ::= RAISE LP raisetype COMMA nm RP */
   224,  /* (261) raisetype ::= ROLLBACK */
   224,  /* (262) raisetype ::= ABORT */
   224,  /* (263) raisetype ::= FAIL */
   181,  /* (264) cmd ::= DROP TRIGGER ifexists fullname */
   181,  /* (265) cmd ::= ATTACH database_kw_opt expr AS expr key_opt */
   181,  /* (266) cmd ::= DETACH database_kw_opt expr */
   280,  /* (267) key_opt ::= */
   280,  /* (268) key_opt ::= KEY expr */
   181,  /* (269) cmd ::= REINDEX */
   181,  /* (270) cmd ::= REINDEX nm dbnm */
   181,  /* (271) cmd ::= ANALYZE */
   181,  /* (272) cmd ::= ANALYZE nm dbnm */
   181,  /* (273) cmd ::= ALTER TABLE fullname RENAME TO nm */
   181,  /* (274) cmd ::= ALTER TABLE add_column_fullname ADD kwcolumn_opt columnname carglist */
   281,  /* (275) add_column_fullname ::= fullname */
   181,  /* (276) cmd ::= ALTER TABLE fullname RENAME kwcolumn_opt nm TO nm */
   181,  /* (277) cmd ::= create_vtab */
   181,  /* (278) cmd ::= create_vtab LP vtabarglist RP */
   283,  /* (279) create_vtab ::= createkw VIRTUAL TABLE ifnotexists nm dbnm USING nm */
   285,  /* (280) vtabarg ::= */
   286,  /* (281) vtabargtoken ::= ANY */
   286,  /* (282) vtabargtoken ::= lp anylist RP */
   287,  /* (283) lp ::= LP */
   253,  /* (284) with ::= WITH wqlist */
   253,  /* (285) with ::= WITH RECURSIVE wqlist */
   229,  /* (286) wqlist ::= nm eidlist_opt AS LP select RP */
   229,  /* (287) wqlist ::= wqlist COMMA nm eidlist_opt AS LP select RP */
   289,  /* (288) windowdefn_list ::= windowdefn */
   289,  /* (289) windowdefn_list ::= windowdefn_list COMMA windowdefn */
   290,  /* (290) windowdefn ::= nm AS LP window RP */
   291,  /* (291) window ::= PARTITION BY nexprlist orderby_opt frame_opt */
   291,  /* (292) window ::= nm PARTITION BY nexprlist orderby_opt frame_opt */
   291,  /* (293) window ::= ORDER BY sortlist frame_opt */
   291,  /* (294) window ::= nm ORDER BY sortlist frame_opt */
   291,  /* (295) window ::= frame_opt */
   291,  /* (296) window ::= nm frame_opt */
   292,  /* (297) frame_opt ::= */
   292,  /* (298) frame_opt ::= range_or_rows frame_bound_s frame_exclude_opt */
   292,  /* (299) frame_opt ::= range_or_rows BETWEEN frame_bound_s AND frame_bound_e frame_exclude_opt */
   295,  /* (300) range_or_rows ::= RANGE|ROWS|GROUPS */
   274,  /* (298) range_or_rows ::= ROWS */
   276,  /* (299) frame_bound_s ::= frame_bound */
   276,  /* (300) frame_bound_s ::= UNBOUNDED PRECEDING */
   277,  /* (301) frame_bound_e ::= frame_bound */
   277,  /* (302) frame_bound_e ::= UNBOUNDED FOLLOWING */
   275,  /* (303) frame_bound ::= expr PRECEDING */
   275,  /* (304) frame_bound ::= CURRENT ROW */
   275,  /* (305) frame_bound ::= expr FOLLOWING */
   218,  /* (306) window_clause ::= WINDOW windowdefn_list */
   237,  /* (307) over_clause ::= filter_opt OVER window */
   237,  /* (308) over_clause ::= filter_opt OVER nm */
   273,  /* (309) filter_opt ::= */
   273,  /* (310) filter_opt ::= FILTER LP WHERE expr RP */
   155,  /* (311) input ::= cmdlist */
   156,  /* (312) cmdlist ::= cmdlist ecmd */
   156,  /* (313) cmdlist ::= ecmd */
   157,  /* (314) ecmd ::= SEMI */
   157,  /* (315) ecmd ::= cmdx SEMI */
   157,  /* (316) ecmd ::= explain cmdx */
   162,  /* (317) trans_opt ::= */
   162,  /* (318) trans_opt ::= TRANSACTION */
   162,  /* (319) trans_opt ::= TRANSACTION nm */
   164,  /* (320) savepoint_opt ::= SAVEPOINT */
   164,  /* (321) savepoint_opt ::= */
   160,  /* (322) cmd ::= create_table create_table_args */
   171,  /* (323) columnlist ::= columnlist COMMA columnname carglist */
   171,  /* (324) columnlist ::= columnname carglist */
   163,  /* (325) nm ::= ID|INDEXED */
   163,  /* (326) nm ::= STRING */
   163,  /* (327) nm ::= JOIN_KW */
   177,  /* (328) typetoken ::= typename */
   178,  /* (329) typename ::= ID|STRING */
   179,  /* (330) signed ::= plus_num */
   179,  /* (331) signed ::= minus_num */
   176,  /* (332) carglist ::= carglist ccons */
   176,  /* (333) carglist ::= */
   183,  /* (334) ccons ::= NULL onconf */
   172,  /* (335) conslist_opt ::= COMMA conslist */
   195,  /* (336) conslist ::= conslist tconscomma tcons */
   195,  /* (337) conslist ::= tcons */
   196,  /* (338) tconscomma ::= */
   200,  /* (339) defer_subclause_opt ::= defer_subclause */
   202,  /* (340) resolvetype ::= raisetype */
   206,  /* (341) selectnowith ::= oneselect */
   207,  /* (342) oneselect ::= values */
   221,  /* (343) sclp ::= selcollist COMMA */
   222,  /* (344) as ::= ID|STRING */
   185,  /* (345) expr ::= term */
   238,  /* (346) likeop ::= LIKE_KW|MATCH */
   229,  /* (347) exprlist ::= nexprlist */
   248,  /* (348) nmnum ::= plus_num */
   248,  /* (349) nmnum ::= nm */
   248,  /* (350) nmnum ::= ON */
   248,  /* (351) nmnum ::= DELETE */
   248,  /* (352) nmnum ::= DEFAULT */
   180,  /* (353) plus_num ::= INTEGER|FLOAT */
   253,  /* (354) foreach_clause ::= */
   253,  /* (355) foreach_clause ::= FOR EACH ROW */
   256,  /* (356) trnm ::= nm */
   257,  /* (357) tridxby ::= */
   258,  /* (358) database_kw_opt ::= DATABASE */
   258,  /* (359) database_kw_opt ::= */
   261,  /* (360) kwcolumn_opt ::= */
   261,  /* (361) kwcolumn_opt ::= COLUMNKW */
   263,  /* (362) vtabarglist ::= vtabarg */
   263,  /* (363) vtabarglist ::= vtabarglist COMMA vtabarg */
   264,  /* (364) vtabarg ::= vtabarg vtabargtoken */
   267,  /* (365) anylist ::= */
   267,  /* (366) anylist ::= anylist LP anylist RP */
   267,  /* (367) anylist ::= anylist ANY */
   232,  /* (368) with ::= */
   297,  /* (301) frame_bound_s ::= frame_bound */
   297,  /* (302) frame_bound_s ::= UNBOUNDED PRECEDING */
   298,  /* (303) frame_bound_e ::= frame_bound */
   298,  /* (304) frame_bound_e ::= UNBOUNDED FOLLOWING */
   296,  /* (305) frame_bound ::= expr PRECEDING|FOLLOWING */
   296,  /* (306) frame_bound ::= CURRENT ROW */
   299,  /* (307) frame_exclude_opt ::= */
   299,  /* (308) frame_exclude_opt ::= EXCLUDE frame_exclude */
   300,  /* (309) frame_exclude ::= NO OTHERS */
   300,  /* (310) frame_exclude ::= CURRENT ROW */
   300,  /* (311) frame_exclude ::= GROUP|TIES */
   239,  /* (312) window_clause ::= WINDOW windowdefn_list */
   258,  /* (313) over_clause ::= filter_opt OVER LP window RP */
   258,  /* (314) over_clause ::= filter_opt OVER nm */
   294,  /* (315) filter_opt ::= */
   294,  /* (316) filter_opt ::= FILTER LP WHERE expr RP */
   176,  /* (317) input ::= cmdlist */
   177,  /* (318) cmdlist ::= cmdlist ecmd */
   177,  /* (319) cmdlist ::= ecmd */
   178,  /* (320) ecmd ::= SEMI */
   178,  /* (321) ecmd ::= cmdx SEMI */
   178,  /* (322) ecmd ::= explain cmdx */
   183,  /* (323) trans_opt ::= */
   183,  /* (324) trans_opt ::= TRANSACTION */
   183,  /* (325) trans_opt ::= TRANSACTION nm */
   185,  /* (326) savepoint_opt ::= SAVEPOINT */
   185,  /* (327) savepoint_opt ::= */
   181,  /* (328) cmd ::= create_table create_table_args */
   192,  /* (329) columnlist ::= columnlist COMMA columnname carglist */
   192,  /* (330) columnlist ::= columnname carglist */
   184,  /* (331) nm ::= ID|INDEXED */
   184,  /* (332) nm ::= STRING */
   184,  /* (333) nm ::= JOIN_KW */
   198,  /* (334) typetoken ::= typename */
   199,  /* (335) typename ::= ID|STRING */
   200,  /* (336) signed ::= plus_num */
   200,  /* (337) signed ::= minus_num */
   197,  /* (338) carglist ::= carglist ccons */
   197,  /* (339) carglist ::= */
   204,  /* (340) ccons ::= NULL onconf */
   193,  /* (341) conslist_opt ::= COMMA conslist */
   216,  /* (342) conslist ::= conslist tconscomma tcons */
   216,  /* (343) conslist ::= tcons */
   217,  /* (344) tconscomma ::= */
   221,  /* (345) defer_subclause_opt ::= defer_subclause */
   223,  /* (346) resolvetype ::= raisetype */
   227,  /* (347) selectnowith ::= oneselect */
   228,  /* (348) oneselect ::= values */
   242,  /* (349) sclp ::= selcollist COMMA */
   243,  /* (350) as ::= ID|STRING */
   206,  /* (351) expr ::= term */
   259,  /* (352) likeop ::= LIKE_KW|MATCH */
   250,  /* (353) exprlist ::= nexprlist */
   269,  /* (354) nmnum ::= plus_num */
   269,  /* (355) nmnum ::= nm */
   269,  /* (356) nmnum ::= ON */
   269,  /* (357) nmnum ::= DELETE */
   269,  /* (358) nmnum ::= DEFAULT */
   201,  /* (359) plus_num ::= INTEGER|FLOAT */
   274,  /* (360) foreach_clause ::= */
   274,  /* (361) foreach_clause ::= FOR EACH ROW */
   277,  /* (362) trnm ::= nm */
   278,  /* (363) tridxby ::= */
   279,  /* (364) database_kw_opt ::= DATABASE */
   279,  /* (365) database_kw_opt ::= */
   282,  /* (366) kwcolumn_opt ::= */
   282,  /* (367) kwcolumn_opt ::= COLUMNKW */
   284,  /* (368) vtabarglist ::= vtabarg */
   284,  /* (369) vtabarglist ::= vtabarglist COMMA vtabarg */
   285,  /* (370) vtabarg ::= vtabarg vtabargtoken */
   288,  /* (371) anylist ::= */
   288,  /* (372) anylist ::= anylist LP anylist RP */
   288,  /* (373) anylist ::= anylist ANY */
   253,  /* (374) with ::= */
};

/* For rule J, yyRuleInfoNRhs[J] contains the negative of the number
** of symbols on the right-hand side of that rule. */
static const signed char yyRuleInfoNRhs[] = {
   -1,  /* (0) explain ::= EXPLAIN */
   -3,  /* (1) explain ::= EXPLAIN QUERY PLAN */
150258
150259
150260
150261
150262
150263
150264
150265
150266
150267
150268
150269
150270
150271
150272











150273
150274
150275
150276
150277
150278
150279






150280
150281
150282
150283
150284
150285
150286
150287
150288
150289
150290
150291
150292
150293
150294
150295
150296
150297
150298
150299
150300
150301
150302
150303
150304
150305
150306
150307
150308
150309
150310
150311
150312
150313
150314
150315
150316
150317
150318
150319
150320
150321
150322
150323
150324
150325
150326
150327
150328
150329
150330
150331
150332
150333
150334
150335
150336
150337
150338
150339
150340
150341
150342
150343




































































150344
150345
150346
150347
150348
150349
150350
151114
151115
151116
151117
151118
151119
151120








151121
151122
151123
151124
151125
151126
151127
151128
151129
151130
151131







151132
151133
151134
151135
151136
151137
































































151138
151139
151140
151141
151142
151143
151144
151145
151146
151147
151148
151149
151150
151151
151152
151153
151154
151155
151156
151157
151158
151159
151160
151161
151162
151163
151164
151165
151166
151167
151168
151169
151170
151171
151172
151173
151174
151175
151176
151177
151178
151179
151180
151181
151182
151183
151184
151185
151186
151187
151188
151189
151190
151191
151192
151193
151194
151195
151196
151197
151198
151199
151200
151201
151202
151203
151204
151205
151206
151207
151208
151209
151210
151211
151212







-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
+
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+







   -1,  /* (283) lp ::= LP */
   -2,  /* (284) with ::= WITH wqlist */
   -3,  /* (285) with ::= WITH RECURSIVE wqlist */
   -6,  /* (286) wqlist ::= nm eidlist_opt AS LP select RP */
   -8,  /* (287) wqlist ::= wqlist COMMA nm eidlist_opt AS LP select RP */
   -1,  /* (288) windowdefn_list ::= windowdefn */
   -3,  /* (289) windowdefn_list ::= windowdefn_list COMMA windowdefn */
   -3,  /* (290) windowdefn ::= nm AS window */
   -5,  /* (291) window ::= LP part_opt orderby_opt frame_opt RP */
   -3,  /* (292) part_opt ::= PARTITION BY nexprlist */
    0,  /* (293) part_opt ::= */
    0,  /* (294) frame_opt ::= */
   -2,  /* (295) frame_opt ::= range_or_rows frame_bound_s */
   -5,  /* (296) frame_opt ::= range_or_rows BETWEEN frame_bound_s AND frame_bound_e */
   -1,  /* (297) range_or_rows ::= RANGE */
   -5,  /* (290) windowdefn ::= nm AS LP window RP */
   -5,  /* (291) window ::= PARTITION BY nexprlist orderby_opt frame_opt */
   -6,  /* (292) window ::= nm PARTITION BY nexprlist orderby_opt frame_opt */
   -4,  /* (293) window ::= ORDER BY sortlist frame_opt */
   -5,  /* (294) window ::= nm ORDER BY sortlist frame_opt */
   -1,  /* (295) window ::= frame_opt */
   -2,  /* (296) window ::= nm frame_opt */
    0,  /* (297) frame_opt ::= */
   -3,  /* (298) frame_opt ::= range_or_rows frame_bound_s frame_exclude_opt */
   -6,  /* (299) frame_opt ::= range_or_rows BETWEEN frame_bound_s AND frame_bound_e frame_exclude_opt */
   -1,  /* (300) range_or_rows ::= RANGE|ROWS|GROUPS */
   -1,  /* (298) range_or_rows ::= ROWS */
   -1,  /* (299) frame_bound_s ::= frame_bound */
   -2,  /* (300) frame_bound_s ::= UNBOUNDED PRECEDING */
   -1,  /* (301) frame_bound_e ::= frame_bound */
   -2,  /* (302) frame_bound_e ::= UNBOUNDED FOLLOWING */
   -2,  /* (303) frame_bound ::= expr PRECEDING */
   -2,  /* (304) frame_bound ::= CURRENT ROW */
   -1,  /* (301) frame_bound_s ::= frame_bound */
   -2,  /* (302) frame_bound_s ::= UNBOUNDED PRECEDING */
   -1,  /* (303) frame_bound_e ::= frame_bound */
   -2,  /* (304) frame_bound_e ::= UNBOUNDED FOLLOWING */
   -2,  /* (305) frame_bound ::= expr PRECEDING|FOLLOWING */
   -2,  /* (306) frame_bound ::= CURRENT ROW */
   -2,  /* (305) frame_bound ::= expr FOLLOWING */
   -2,  /* (306) window_clause ::= WINDOW windowdefn_list */
   -3,  /* (307) over_clause ::= filter_opt OVER window */
   -3,  /* (308) over_clause ::= filter_opt OVER nm */
    0,  /* (309) filter_opt ::= */
   -5,  /* (310) filter_opt ::= FILTER LP WHERE expr RP */
   -1,  /* (311) input ::= cmdlist */
   -2,  /* (312) cmdlist ::= cmdlist ecmd */
   -1,  /* (313) cmdlist ::= ecmd */
   -1,  /* (314) ecmd ::= SEMI */
   -2,  /* (315) ecmd ::= cmdx SEMI */
   -2,  /* (316) ecmd ::= explain cmdx */
    0,  /* (317) trans_opt ::= */
   -1,  /* (318) trans_opt ::= TRANSACTION */
   -2,  /* (319) trans_opt ::= TRANSACTION nm */
   -1,  /* (320) savepoint_opt ::= SAVEPOINT */
    0,  /* (321) savepoint_opt ::= */
   -2,  /* (322) cmd ::= create_table create_table_args */
   -4,  /* (323) columnlist ::= columnlist COMMA columnname carglist */
   -2,  /* (324) columnlist ::= columnname carglist */
   -1,  /* (325) nm ::= ID|INDEXED */
   -1,  /* (326) nm ::= STRING */
   -1,  /* (327) nm ::= JOIN_KW */
   -1,  /* (328) typetoken ::= typename */
   -1,  /* (329) typename ::= ID|STRING */
   -1,  /* (330) signed ::= plus_num */
   -1,  /* (331) signed ::= minus_num */
   -2,  /* (332) carglist ::= carglist ccons */
    0,  /* (333) carglist ::= */
   -2,  /* (334) ccons ::= NULL onconf */
   -2,  /* (335) conslist_opt ::= COMMA conslist */
   -3,  /* (336) conslist ::= conslist tconscomma tcons */
   -1,  /* (337) conslist ::= tcons */
    0,  /* (338) tconscomma ::= */
   -1,  /* (339) defer_subclause_opt ::= defer_subclause */
   -1,  /* (340) resolvetype ::= raisetype */
   -1,  /* (341) selectnowith ::= oneselect */
   -1,  /* (342) oneselect ::= values */
   -2,  /* (343) sclp ::= selcollist COMMA */
   -1,  /* (344) as ::= ID|STRING */
   -1,  /* (345) expr ::= term */
   -1,  /* (346) likeop ::= LIKE_KW|MATCH */
   -1,  /* (347) exprlist ::= nexprlist */
   -1,  /* (348) nmnum ::= plus_num */
   -1,  /* (349) nmnum ::= nm */
   -1,  /* (350) nmnum ::= ON */
   -1,  /* (351) nmnum ::= DELETE */
   -1,  /* (352) nmnum ::= DEFAULT */
   -1,  /* (353) plus_num ::= INTEGER|FLOAT */
    0,  /* (354) foreach_clause ::= */
   -3,  /* (355) foreach_clause ::= FOR EACH ROW */
   -1,  /* (356) trnm ::= nm */
    0,  /* (357) tridxby ::= */
   -1,  /* (358) database_kw_opt ::= DATABASE */
    0,  /* (359) database_kw_opt ::= */
    0,  /* (360) kwcolumn_opt ::= */
   -1,  /* (361) kwcolumn_opt ::= COLUMNKW */
   -1,  /* (362) vtabarglist ::= vtabarg */
   -3,  /* (363) vtabarglist ::= vtabarglist COMMA vtabarg */
   -2,  /* (364) vtabarg ::= vtabarg vtabargtoken */
    0,  /* (365) anylist ::= */
   -4,  /* (366) anylist ::= anylist LP anylist RP */
   -2,  /* (367) anylist ::= anylist ANY */
    0,  /* (368) with ::= */
    0,  /* (307) frame_exclude_opt ::= */
   -2,  /* (308) frame_exclude_opt ::= EXCLUDE frame_exclude */
   -2,  /* (309) frame_exclude ::= NO OTHERS */
   -2,  /* (310) frame_exclude ::= CURRENT ROW */
   -1,  /* (311) frame_exclude ::= GROUP|TIES */
   -2,  /* (312) window_clause ::= WINDOW windowdefn_list */
   -5,  /* (313) over_clause ::= filter_opt OVER LP window RP */
   -3,  /* (314) over_clause ::= filter_opt OVER nm */
    0,  /* (315) filter_opt ::= */
   -5,  /* (316) filter_opt ::= FILTER LP WHERE expr RP */
   -1,  /* (317) input ::= cmdlist */
   -2,  /* (318) cmdlist ::= cmdlist ecmd */
   -1,  /* (319) cmdlist ::= ecmd */
   -1,  /* (320) ecmd ::= SEMI */
   -2,  /* (321) ecmd ::= cmdx SEMI */
   -2,  /* (322) ecmd ::= explain cmdx */
    0,  /* (323) trans_opt ::= */
   -1,  /* (324) trans_opt ::= TRANSACTION */
   -2,  /* (325) trans_opt ::= TRANSACTION nm */
   -1,  /* (326) savepoint_opt ::= SAVEPOINT */
    0,  /* (327) savepoint_opt ::= */
   -2,  /* (328) cmd ::= create_table create_table_args */
   -4,  /* (329) columnlist ::= columnlist COMMA columnname carglist */
   -2,  /* (330) columnlist ::= columnname carglist */
   -1,  /* (331) nm ::= ID|INDEXED */
   -1,  /* (332) nm ::= STRING */
   -1,  /* (333) nm ::= JOIN_KW */
   -1,  /* (334) typetoken ::= typename */
   -1,  /* (335) typename ::= ID|STRING */
   -1,  /* (336) signed ::= plus_num */
   -1,  /* (337) signed ::= minus_num */
   -2,  /* (338) carglist ::= carglist ccons */
    0,  /* (339) carglist ::= */
   -2,  /* (340) ccons ::= NULL onconf */
   -2,  /* (341) conslist_opt ::= COMMA conslist */
   -3,  /* (342) conslist ::= conslist tconscomma tcons */
   -1,  /* (343) conslist ::= tcons */
    0,  /* (344) tconscomma ::= */
   -1,  /* (345) defer_subclause_opt ::= defer_subclause */
   -1,  /* (346) resolvetype ::= raisetype */
   -1,  /* (347) selectnowith ::= oneselect */
   -1,  /* (348) oneselect ::= values */
   -2,  /* (349) sclp ::= selcollist COMMA */
   -1,  /* (350) as ::= ID|STRING */
   -1,  /* (351) expr ::= term */
   -1,  /* (352) likeop ::= LIKE_KW|MATCH */
   -1,  /* (353) exprlist ::= nexprlist */
   -1,  /* (354) nmnum ::= plus_num */
   -1,  /* (355) nmnum ::= nm */
   -1,  /* (356) nmnum ::= ON */
   -1,  /* (357) nmnum ::= DELETE */
   -1,  /* (358) nmnum ::= DEFAULT */
   -1,  /* (359) plus_num ::= INTEGER|FLOAT */
    0,  /* (360) foreach_clause ::= */
   -3,  /* (361) foreach_clause ::= FOR EACH ROW */
   -1,  /* (362) trnm ::= nm */
    0,  /* (363) tridxby ::= */
   -1,  /* (364) database_kw_opt ::= DATABASE */
    0,  /* (365) database_kw_opt ::= */
    0,  /* (366) kwcolumn_opt ::= */
   -1,  /* (367) kwcolumn_opt ::= COLUMNKW */
   -1,  /* (368) vtabarglist ::= vtabarg */
   -3,  /* (369) vtabarglist ::= vtabarglist COMMA vtabarg */
   -2,  /* (370) vtabarg ::= vtabarg vtabargtoken */
    0,  /* (371) anylist ::= */
   -4,  /* (372) anylist ::= anylist LP anylist RP */
   -2,  /* (373) anylist ::= anylist ANY */
    0,  /* (374) with ::= */
};

static void yy_accept(yyParser*);  /* Forward Declaration */

/*
** Perform a reduce action and the shift that must immediately
** follow the reduce.
150433
150434
150435
150436
150437
150438
150439
150440

150441
150442
150443

150444
150445
150446
150447

150448

150449
150450
150451
150452
150453
150454
150455
151295
151296
151297
151298
151299
151300
151301

151302
151303
151304

151305
151306
151307
151308
151309
151310

151311
151312
151313
151314
151315
151316
151317
151318







-
+


-
+




+
-
+







      case 1: /* explain ::= EXPLAIN QUERY PLAN */
{ pParse->explain = 2; }
        break;
      case 2: /* cmdx ::= cmd */
{ sqlite3FinishCoding(pParse); }
        break;
      case 3: /* cmd ::= BEGIN transtype trans_opt */
{sqlite3BeginTransaction(pParse, yymsp[-1].minor.yy96);}
{sqlite3BeginTransaction(pParse, yymsp[-1].minor.yy494);}
        break;
      case 4: /* transtype ::= */
{yymsp[1].minor.yy96 = TK_DEFERRED;}
{yymsp[1].minor.yy494 = TK_DEFERRED;}
        break;
      case 5: /* transtype ::= DEFERRED */
      case 6: /* transtype ::= IMMEDIATE */ yytestcase(yyruleno==6);
      case 7: /* transtype ::= EXCLUSIVE */ yytestcase(yyruleno==7);
      case 300: /* range_or_rows ::= RANGE|ROWS|GROUPS */ yytestcase(yyruleno==300);
{yymsp[0].minor.yy96 = yymsp[0].major; /*A-overwrites-X*/}
{yymsp[0].minor.yy494 = yymsp[0].major; /*A-overwrites-X*/}
        break;
      case 8: /* cmd ::= COMMIT|END trans_opt */
      case 9: /* cmd ::= ROLLBACK trans_opt */ yytestcase(yyruleno==9);
{sqlite3EndTransaction(pParse,yymsp[-1].major);}
        break;
      case 10: /* cmd ::= SAVEPOINT nm */
{
150464
150465
150466
150467
150468
150469
150470
150471

150472
150473
150474
150475
150476
150477
150478
150479
150480
150481
150482
150483
150484
150485
150486

150487
150488
150489

150490
150491
150492
150493

150494
150495
150496
150497

150498
150499
150500
150501
150502
150503


150504
150505
150506
150507
150508
150509

150510
150511

150512
150513
150514
150515
150516
150517
150518
151327
151328
151329
151330
151331
151332
151333

151334
151335
151336
151337
151338
151339
151340
151341
151342
151343
151344
151345
151346
151347
151348

151349
151350
151351

151352
151353
151354
151355

151356
151357
151358
151359

151360
151361
151362
151363
151364


151365
151366
151367
151368
151369
151370
151371

151372
151373

151374
151375
151376
151377
151378
151379
151380
151381







-
+














-
+


-
+



-
+



-
+




-
-
+
+





-
+

-
+







      case 12: /* cmd ::= ROLLBACK trans_opt TO savepoint_opt nm */
{
  sqlite3Savepoint(pParse, SAVEPOINT_ROLLBACK, &yymsp[0].minor.yy0);
}
        break;
      case 13: /* create_table ::= createkw temp TABLE ifnotexists nm dbnm */
{
   sqlite3StartTable(pParse,&yymsp[-1].minor.yy0,&yymsp[0].minor.yy0,yymsp[-4].minor.yy96,0,0,yymsp[-2].minor.yy96);
   sqlite3StartTable(pParse,&yymsp[-1].minor.yy0,&yymsp[0].minor.yy0,yymsp[-4].minor.yy494,0,0,yymsp[-2].minor.yy494);
}
        break;
      case 14: /* createkw ::= CREATE */
{disableLookaside(pParse);}
        break;
      case 15: /* ifnotexists ::= */
      case 18: /* temp ::= */ yytestcase(yyruleno==18);
      case 21: /* table_options ::= */ yytestcase(yyruleno==21);
      case 42: /* autoinc ::= */ yytestcase(yyruleno==42);
      case 57: /* init_deferred_pred_opt ::= */ yytestcase(yyruleno==57);
      case 67: /* defer_subclause_opt ::= */ yytestcase(yyruleno==67);
      case 76: /* ifexists ::= */ yytestcase(yyruleno==76);
      case 93: /* distinct ::= */ yytestcase(yyruleno==93);
      case 226: /* collate ::= */ yytestcase(yyruleno==226);
{yymsp[1].minor.yy96 = 0;}
{yymsp[1].minor.yy494 = 0;}
        break;
      case 16: /* ifnotexists ::= IF NOT EXISTS */
{yymsp[-2].minor.yy96 = 1;}
{yymsp[-2].minor.yy494 = 1;}
        break;
      case 17: /* temp ::= TEMP */
      case 43: /* autoinc ::= AUTOINCR */ yytestcase(yyruleno==43);
{yymsp[0].minor.yy96 = 1;}
{yymsp[0].minor.yy494 = 1;}
        break;
      case 19: /* create_table_args ::= LP columnlist conslist_opt RP table_options */
{
  sqlite3EndTable(pParse,&yymsp[-2].minor.yy0,&yymsp[-1].minor.yy0,yymsp[0].minor.yy96,0);
  sqlite3EndTable(pParse,&yymsp[-2].minor.yy0,&yymsp[-1].minor.yy0,yymsp[0].minor.yy494,0);
}
        break;
      case 20: /* create_table_args ::= AS select */
{
  sqlite3EndTable(pParse,0,0,0,yymsp[0].minor.yy423);
  sqlite3SelectDelete(pParse->db, yymsp[0].minor.yy423);
  sqlite3EndTable(pParse,0,0,0,yymsp[0].minor.yy457);
  sqlite3SelectDelete(pParse->db, yymsp[0].minor.yy457);
}
        break;
      case 22: /* table_options ::= WITHOUT nm */
{
  if( yymsp[0].minor.yy0.n==5 && sqlite3_strnicmp(yymsp[0].minor.yy0.z,"rowid",5)==0 ){
    yymsp[-1].minor.yy96 = TF_WithoutRowid | TF_NoVisibleRowid;
    yymsp[-1].minor.yy494 = TF_WithoutRowid | TF_NoVisibleRowid;
  }else{
    yymsp[-1].minor.yy96 = 0;
    yymsp[-1].minor.yy494 = 0;
    sqlite3ErrorMsg(pParse, "unknown table option: %.*s", yymsp[0].minor.yy0.n, yymsp[0].minor.yy0.z);
  }
}
        break;
      case 23: /* columnname ::= nm typetoken */
{sqlite3AddColumn(pParse,&yymsp[-1].minor.yy0,&yymsp[0].minor.yy0);}
        break;
150533
150534
150535
150536
150537
150538
150539
150540

150541
150542
150543
150544
150545
150546
150547
150548

150549
150550
150551

150552
150553
150554

150555
150556
150557
150558
150559


150560
150561
150562
150563
150564
150565
150566
150567
150568
150569
150570
150571
150572
150573

150574
150575
150576

150577
150578
150579

150580
150581
150582
150583

150584
150585
150586

150587
150588
150589

150590
150591
150592
150593
150594
150595

150596
150597
150598

150599
150600
150601

150602
150603
150604

150605
150606
150607

150608
150609
150610

150611
150612
150613

150614
150615
150616

150617
150618
150619

150620
150621
150622

150623
150624
150625

150626
150627
150628

150629
150630
150631
150632
150633

150634
150635
150636
150637
150638
150639
150640

150641
150642
150643

150644
150645
150646
150647
150648
150649

150650
150651
150652

150653
150654
150655
150656

150657
150658
150659
150660
150661


150662
150663
150664
150665
150666

150667
150668
150669

150670
150671
150672

150673
150674
150675
150676

150677
150678
150679
150680

150681
150682
150683
150684
150685

150686
150687
150688
150689
150690

150691
150692
150693
150694
150695
150696
150697


150698
150699
150700
150701
150702

150703
150704

150705
150706
150707

150708
150709

150710
150711
150712
150713
150714

150715
150716

150717
150718
150719

150720
150721

150722
150723
150724
150725
150726

150727
150728
150729
150730

150731
150732
150733
150734
150735
150736


150737
150738
150739
150740
150741
150742
150743
150744
150745
150746

150747
150748
150749
150750

150751
150752
150753
150754

150755
150756
150757
150758
150759

150760
150761
150762

150763
150764
150765
150766

150767
150768
150769
150770
150771
150772
150773



150774
150775

150776
150777
150778
150779
150780
150781

150782
150783
150784
150785
150786
150787


150788
150789
150790
150791
150792

150793
150794

150795
150796
150797
150798
150799

150800
150801
150802

150803
150804
150805
150806
150807
150808
150809
150810

150811
150812
150813
150814
150815
150816



150817
150818
150819
150820
150821
150822

150823
150824
150825
150826
150827
150828
150829
150830

150831
150832
150833
150834
150835
150836
150837
150838
150839
150840

150841
150842
150843
150844
150845


150846
150847
150848
150849
150850

150851
150852
150853
150854

150855
150856
150857
150858
150859


150860
150861
150862
150863
150864
150865


150866
150867
150868
150869
150870

150871
150872
150873
150874
150875
150876
150877
150878
150879
150880
150881







150882
150883
150884
150885
150886
150887
150888
150889
150890
150891
150892
150893
150894

150895
150896
150897
150898
150899



150900
150901
150902
150903
150904
150905
150906
150907
150908
150909
150910


150911
150912

150913
150914
150915
150916
150917


150918
150919

150920
150921
150922

150923
150924
150925

150926
150927
150928
150929
150930


150931
150932
150933
150934
150935
150936


150937
150938
150939
150940

150941
150942
150943

150944
150945
150946

150947
150948
150949

150950
150951
150952
150953
150954
150955
150956

150957
150958
150959
150960
150961
150962
150963
150964
150965

150966
150967
150968
150969
150970
150971
150972
150973
150974

150975
150976
150977
150978

150979
150980
150981
150982

150983
150984
150985
150986
150987


150988
150989
150990
150991
150992
150993


150994
150995
150996
150997

150998
150999
151000

151001
151002
151003

151004
151005
151006

151007
151008
151009

151010
151011
151012

151013
151014
151015
151016
151017


151018
151019
151020
151021
151022
151023
151024



151025
151026
151027
151028
151029
151030


151031
151032
151033
151034
151035

151036
151037
151038
151039
151040
151041


151042
151043

151044
151045
151046
151047

151048
151049
151050
151051
151052

151053
151054
151055
151056
151057

151058
151059
151060
151061

151062
151063
151064

151065
151066
151067

151068
151069
151070

151071
151072
151073

151074
151075
151076

151077
151078
151079

151080
151081
151082

151083
151084
151085
151086

151087
151088
151089
151090
151091
151092
151093
151094
151095
151096

151097
151098

151099
151100
151101
151102
151103
151104
151105
151106
151107
151108
151109
151110

151111
151112

151113
151114
151115
151116

151117
151118
151119
151120

151121
151122

151123
151124
151125
151126
151127
151128
151129


151130
151131
151132
151133
151134
151135
151136
151137
151138

151139
151140
151141


151142
151143
151144
151145
151146
151147
151148

151149
151150
151151
151152
151153
151154


151155
151156
151157
151158
151159

151160
151161

151162
151163
151164
151165

151166
151167

151168
151169
151170
151171
151172


151173
151174

151175
151176
151177
151178
151179


151180
151181

151182
151183
151184
151185

151186
151187

151188
151189
151190
151191
151192
151193
151194




151195
151196
151197
151198
151199
151200
151201
151202
151203
151204
151205
151206
151207
151208

151209
151210
151211
151212
151213
151214
151215
151216
151217
151218
151219
151220
151221
151222





151223
151224
151225
151226
151227
151228
151229
151230
151231
151232
151233
151234
151235






151236
151237
151238
151239

151240
151241
151242

151243
151244
151245
151246
151247


151248
151249
151250
151251
151252
151253


151254
151255
151256
151257
151258

151259
151260
151261
151262

151263
151264
151265
151266
151267
151268

151269
151270
151271
151272
151273
151274
151275
151276





151277
151278
151279
151280

151281
151282
151283
151284
151285

151286
151287
151288
151289
151290
151291
151292
151293
151294
151295
151296


151297
151298

151299
151300
151301
151302
151303
151304
151305
151306
151307
151308
151309
151310
151311
151312
151313
151314
151315
151316
151317



151318
151319
151320
151321
151322
151323
151324

151325
151326
151327
151328
151329




151330
151331

151332
151333

151334
151335
151336
151337
151338
151339
151340


151341
151342
151343
151344
151345
151346
151347



151348
151349
151350
151351
151352
151353
151354
151355
151356
151357




151358
151359
151360
151361
151362
151363
151364


151365
151366
151367
151368
151369
151370
151371
151372




151373
151374
151375


151376
151377
151378
151379
151380
151381
151382


151383
151384
151385
151386
151387
151388


151389
151390
151391
151392

151393
151394
151395

151396
151397
151398

151399
151400
151401
151402

151403
151404
151405
151406
151407
151408


151409
151410
151411
151412
151413
151414
151415
151416

151417
151418
151419

151420
151421
151422
151423

151424
151425
151426
151427
151428

151429
151430
151431
151432

151433
151434
151435

151436
151437
151438

151439
151440
151441
151442
151443
151444
151445
151396
151397
151398
151399
151400
151401
151402

151403
151404
151405
151406
151407
151408
151409
151410

151411
151412
151413

151414
151415
151416

151417
151418
151419
151420


151421
151422
151423
151424
151425
151426
151427
151428
151429
151430
151431
151432
151433
151434
151435

151436
151437
151438

151439
151440
151441

151442
151443
151444
151445

151446
151447
151448

151449
151450
151451

151452
151453
151454
151455
151456
151457

151458
151459
151460

151461
151462
151463

151464
151465
151466

151467
151468
151469

151470
151471
151472

151473
151474
151475

151476
151477
151478

151479
151480
151481

151482
151483
151484

151485
151486
151487

151488
151489
151490

151491
151492
151493
151494
151495

151496
151497
151498
151499
151500
151501
151502

151503
151504
151505

151506
151507
151508
151509
151510
151511

151512
151513
151514

151515
151516
151517
151518

151519
151520
151521
151522


151523
151524
151525
151526
151527
151528

151529
151530
151531

151532
151533
151534

151535
151536
151537
151538

151539
151540
151541
151542

151543
151544
151545
151546
151547

151548
151549
151550
151551
151552

151553
151554
151555
151556
151557
151558


151559
151560
151561
151562
151563
151564

151565
151566

151567
151568
151569

151570
151571

151572
151573
151574
151575
151576

151577
151578

151579
151580
151581

151582
151583

151584
151585
151586
151587
151588

151589
151590
151591
151592

151593
151594
151595
151596
151597


151598
151599
151600
151601
151602
151603
151604
151605
151606
151607
151608

151609
151610
151611
151612

151613
151614
151615
151616

151617
151618
151619
151620
151621

151622
151623
151624

151625
151626
151627
151628

151629
151630
151631
151632
151633



151634
151635
151636
151637

151638
151639
151640
151641
151642
151643

151644
151645
151646
151647
151648


151649
151650
151651
151652
151653
151654

151655
151656

151657
151658
151659
151660
151661

151662
151663
151664

151665
151666
151667
151668
151669
151670
151671
151672

151673
151674
151675
151676



151677
151678
151679
151680
151681
151682
151683
151684

151685
151686
151687
151688
151689
151690
151691
151692

151693
151694
151695
151696
151697
151698
151699
151700
151701
151702

151703
151704
151705
151706


151707
151708
151709
151710
151711
151712

151713
151714
151715
151716

151717
151718
151719
151720


151721
151722
151723
151724
151725
151726


151727
151728
151729
151730
151731
151732

151733
151734
151735
151736
151737







151738
151739
151740
151741
151742
151743
151744
151745
151746
151747
151748
151749
151750
151751
151752
151753
151754
151755
151756

151757
151758
151759



151760
151761
151762
151763
151764
151765
151766
151767
151768
151769
151770
151771


151772
151773
151774

151775
151776
151777
151778


151779
151780
151781

151782
151783
151784

151785
151786
151787

151788
151789
151790
151791


151792
151793
151794
151795
151796
151797


151798
151799
151800
151801
151802

151803
151804
151805

151806
151807
151808

151809
151810
151811

151812
151813
151814
151815
151816
151817
151818

151819
151820
151821
151822
151823
151824
151825
151826
151827

151828
151829
151830
151831
151832
151833
151834
151835
151836

151837
151838
151839
151840

151841
151842
151843
151844

151845
151846
151847
151848


151849
151850
151851
151852
151853
151854


151855
151856
151857
151858
151859

151860
151861
151862

151863
151864
151865

151866
151867
151868

151869
151870
151871

151872
151873
151874

151875
151876
151877
151878


151879
151880
151881
151882
151883
151884



151885
151886
151887
151888
151889
151890
151891


151892
151893
151894
151895
151896
151897

151898
151899
151900
151901
151902


151903
151904
151905

151906
151907
151908
151909

151910
151911
151912
151913
151914

151915
151916
151917
151918
151919

151920
151921
151922
151923

151924
151925
151926

151927
151928
151929

151930
151931
151932

151933
151934
151935

151936
151937
151938

151939
151940
151941

151942
151943
151944

151945
151946
151947
151948

151949
151950
151951
151952
151953
151954
151955
151956
151957
151958

151959
151960

151961
151962
151963
151964
151965
151966
151967
151968
151969
151970
151971
151972

151973
151974

151975
151976
151977
151978

151979
151980
151981
151982

151983
151984

151985
151986
151987
151988
151989
151990


151991
151992
151993
151994
151995
151996
151997
151998
151999
152000

152001
152002


152003
152004
152005
152006
152007
152008
152009
152010

152011
152012
152013
152014
152015


152016
152017
152018
152019
152020
152021

152022
152023

152024
152025
152026
152027

152028
152029

152030
152031
152032
152033


152034
152035
152036

152037
152038
152039
152040


152041
152042
152043

152044
152045
152046
152047

152048
152049

152050
152051
152052
152053




152054
152055
152056
152057
152058
152059
152060
152061
152062
152063
152064
152065
152066
152067
152068
152069
152070

152071
152072
152073
152074
152075
152076
152077
152078
152079
152080





152081
152082
152083
152084
152085
152086
152087
152088
152089
152090
152091
152092






152093
152094
152095
152096
152097
152098
152099
152100
152101

152102
152103
152104

152105
152106
152107
152108


152109
152110
152111
152112
152113
152114


152115
152116
152117
152118
152119
152120

152121
152122
152123
152124

152125
152126
152127
152128
152129
152130

152131
152132
152133
152134





152135
152136
152137
152138
152139
152140
152141
152142

152143
152144
152145
152146
152147

152148
152149
152150
152151
152152
152153
152154
152155
152156
152157


152158
152159
152160

152161
152162
152163
152164
152165
152166
152167
152168
152169
152170
152171
152172
152173
152174
152175
152176
152177



152178
152179
152180
152181
152182
152183
152184
152185
152186

152187
152188




152189
152190
152191
152192
152193

152194
152195

152196
152197
152198
152199
152200
152201


152202
152203
152204
152205
152206
152207



152208
152209
152210
152211
152212
152213
152214
152215
152216




152217
152218
152219
152220
152221
152222
152223
152224
152225


152226
152227
152228
152229
152230
152231




152232
152233
152234
152235
152236


152237
152238
152239
152240
152241
152242
152243


152244
152245
152246
152247
152248
152249


152250
152251
152252
152253
152254

152255
152256
152257

152258
152259
152260

152261
152262
152263
152264

152265
152266
152267
152268
152269


152270
152271
152272
152273
152274
152275
152276
152277
152278

152279
152280
152281

152282
152283
152284
152285

152286
152287
152288
152289
152290

152291
152292
152293
152294

152295
152296
152297

152298
152299
152300

152301
152302
152303
152304
152305
152306
152307
152308







-
+







-
+


-
+


-
+



-
-
+
+













-
+


-
+


-
+



-
+


-
+


-
+





-
+


-
+


-
+


-
+


-
+


-
+


-
+


-
+


-
+


-
+


-
+


-
+




-
+






-
+


-
+





-
+


-
+



-
+



-
-
+
+




-
+


-
+


-
+



-
+



-
+




-
+




-
+





-
-
+
+




-
+

-
+


-
+

-
+




-
+

-
+


-
+

-
+




-
+



-
+




-
-
+
+









-
+



-
+



-
+




-
+


-
+



-
+




-
-
-
+
+
+

-
+





-
+




-
-
+
+




-
+

-
+




-
+


-
+







-
+



-
-
-
+
+
+





-
+







-
+









-
+



-
-
+
+




-
+



-
+



-
-
+
+




-
-
+
+




-
+




-
-
-
-
-
-
-
+
+
+
+
+
+
+












-
+


-
-
-
+
+
+









-
-
+
+

-
+



-
-
+
+

-
+


-
+


-
+



-
-
+
+




-
-
+
+



-
+


-
+


-
+


-
+






-
+








-
+








-
+



-
+



-
+



-
-
+
+




-
-
+
+



-
+


-
+


-
+


-
+


-
+


-
+



-
-
+
+




-
-
-
+
+
+




-
-
+
+




-
+




-
-
+
+

-
+



-
+




-
+




-
+



-
+


-
+


-
+


-
+


-
+


-
+


-
+


-
+



-
+









-
+

-
+











-
+

-
+



-
+



-
+

-
+





-
-
+
+








-
+

-
-
+
+






-
+




-
-
+
+




-
+

-
+



-
+

-
+



-
-
+
+

-
+



-
-
+
+

-
+



-
+

-
+



-
-
-
-
+
+
+
+













-
+









-
-
-
-
-
+
+
+
+
+







-
-
-
-
-
-
+
+
+
+
+
+



-
+


-
+



-
-
+
+




-
-
+
+




-
+



-
+





-
+



-
-
-
-
-
+
+
+
+
+



-
+




-
+









-
-
+
+

-
+
















-
-
-
+
+
+






-
+

-
-
-
-
+
+
+
+

-
+

-
+





-
-
+
+




-
-
-
+
+
+






-
-
-
-
+
+
+
+





-
-
+
+




-
-
-
-
+
+
+
+

-
-
+
+





-
-
+
+




-
-
+
+



-
+


-
+


-
+



-
+




-
-
+
+







-
+


-
+



-
+




-
+



-
+


-
+


-
+







        break;
      case 27: /* typename ::= typename ID|STRING */
{yymsp[-1].minor.yy0.n=yymsp[0].minor.yy0.n+(int)(yymsp[0].minor.yy0.z-yymsp[-1].minor.yy0.z);}
        break;
      case 28: /* scanpt ::= */
{
  assert( yyLookahead!=YYNOCODE );
  yymsp[1].minor.yy464 = yyLookaheadToken.z;
  yymsp[1].minor.yy294 = yyLookaheadToken.z;
}
        break;
      case 29: /* ccons ::= CONSTRAINT nm */
      case 62: /* tcons ::= CONSTRAINT nm */ yytestcase(yyruleno==62);
{pParse->constraintName = yymsp[0].minor.yy0;}
        break;
      case 30: /* ccons ::= DEFAULT scanpt term scanpt */
{sqlite3AddDefaultValue(pParse,yymsp[-1].minor.yy490,yymsp[-2].minor.yy464,yymsp[0].minor.yy464);}
{sqlite3AddDefaultValue(pParse,yymsp[-1].minor.yy524,yymsp[-2].minor.yy294,yymsp[0].minor.yy294);}
        break;
      case 31: /* ccons ::= DEFAULT LP expr RP */
{sqlite3AddDefaultValue(pParse,yymsp[-1].minor.yy490,yymsp[-2].minor.yy0.z+1,yymsp[0].minor.yy0.z);}
{sqlite3AddDefaultValue(pParse,yymsp[-1].minor.yy524,yymsp[-2].minor.yy0.z+1,yymsp[0].minor.yy0.z);}
        break;
      case 32: /* ccons ::= DEFAULT PLUS term scanpt */
{sqlite3AddDefaultValue(pParse,yymsp[-1].minor.yy490,yymsp[-2].minor.yy0.z,yymsp[0].minor.yy464);}
{sqlite3AddDefaultValue(pParse,yymsp[-1].minor.yy524,yymsp[-2].minor.yy0.z,yymsp[0].minor.yy294);}
        break;
      case 33: /* ccons ::= DEFAULT MINUS term scanpt */
{
  Expr *p = sqlite3PExpr(pParse, TK_UMINUS, yymsp[-1].minor.yy490, 0);
  sqlite3AddDefaultValue(pParse,p,yymsp[-2].minor.yy0.z,yymsp[0].minor.yy464);
  Expr *p = sqlite3PExpr(pParse, TK_UMINUS, yymsp[-1].minor.yy524, 0);
  sqlite3AddDefaultValue(pParse,p,yymsp[-2].minor.yy0.z,yymsp[0].minor.yy294);
}
        break;
      case 34: /* ccons ::= DEFAULT scanpt ID|INDEXED */
{
  Expr *p = tokenExpr(pParse, TK_STRING, yymsp[0].minor.yy0);
  if( p ){
    sqlite3ExprIdToTrueFalse(p);
    testcase( p->op==TK_TRUEFALSE && sqlite3ExprTruthValue(p) );
  }
    sqlite3AddDefaultValue(pParse,p,yymsp[0].minor.yy0.z,yymsp[0].minor.yy0.z+yymsp[0].minor.yy0.n);
}
        break;
      case 35: /* ccons ::= NOT NULL onconf */
{sqlite3AddNotNull(pParse, yymsp[0].minor.yy96);}
{sqlite3AddNotNull(pParse, yymsp[0].minor.yy494);}
        break;
      case 36: /* ccons ::= PRIMARY KEY sortorder onconf autoinc */
{sqlite3AddPrimaryKey(pParse,0,yymsp[-1].minor.yy96,yymsp[0].minor.yy96,yymsp[-2].minor.yy96);}
{sqlite3AddPrimaryKey(pParse,0,yymsp[-1].minor.yy494,yymsp[0].minor.yy494,yymsp[-2].minor.yy494);}
        break;
      case 37: /* ccons ::= UNIQUE onconf */
{sqlite3CreateIndex(pParse,0,0,0,0,yymsp[0].minor.yy96,0,0,0,0,
{sqlite3CreateIndex(pParse,0,0,0,0,yymsp[0].minor.yy494,0,0,0,0,
                                   SQLITE_IDXTYPE_UNIQUE);}
        break;
      case 38: /* ccons ::= CHECK LP expr RP */
{sqlite3AddCheckConstraint(pParse,yymsp[-1].minor.yy490);}
{sqlite3AddCheckConstraint(pParse,yymsp[-1].minor.yy524);}
        break;
      case 39: /* ccons ::= REFERENCES nm eidlist_opt refargs */
{sqlite3CreateForeignKey(pParse,0,&yymsp[-2].minor.yy0,yymsp[-1].minor.yy42,yymsp[0].minor.yy96);}
{sqlite3CreateForeignKey(pParse,0,&yymsp[-2].minor.yy0,yymsp[-1].minor.yy434,yymsp[0].minor.yy494);}
        break;
      case 40: /* ccons ::= defer_subclause */
{sqlite3DeferForeignKey(pParse,yymsp[0].minor.yy96);}
{sqlite3DeferForeignKey(pParse,yymsp[0].minor.yy494);}
        break;
      case 41: /* ccons ::= COLLATE ID|STRING */
{sqlite3AddCollateType(pParse, &yymsp[0].minor.yy0);}
        break;
      case 44: /* refargs ::= */
{ yymsp[1].minor.yy96 = OE_None*0x0101; /* EV: R-19803-45884 */}
{ yymsp[1].minor.yy494 = OE_None*0x0101; /* EV: R-19803-45884 */}
        break;
      case 45: /* refargs ::= refargs refarg */
{ yymsp[-1].minor.yy96 = (yymsp[-1].minor.yy96 & ~yymsp[0].minor.yy367.mask) | yymsp[0].minor.yy367.value; }
{ yymsp[-1].minor.yy494 = (yymsp[-1].minor.yy494 & ~yymsp[0].minor.yy355.mask) | yymsp[0].minor.yy355.value; }
        break;
      case 46: /* refarg ::= MATCH nm */
{ yymsp[-1].minor.yy367.value = 0;     yymsp[-1].minor.yy367.mask = 0x000000; }
{ yymsp[-1].minor.yy355.value = 0;     yymsp[-1].minor.yy355.mask = 0x000000; }
        break;
      case 47: /* refarg ::= ON INSERT refact */
{ yymsp[-2].minor.yy367.value = 0;     yymsp[-2].minor.yy367.mask = 0x000000; }
{ yymsp[-2].minor.yy355.value = 0;     yymsp[-2].minor.yy355.mask = 0x000000; }
        break;
      case 48: /* refarg ::= ON DELETE refact */
{ yymsp[-2].minor.yy367.value = yymsp[0].minor.yy96;     yymsp[-2].minor.yy367.mask = 0x0000ff; }
{ yymsp[-2].minor.yy355.value = yymsp[0].minor.yy494;     yymsp[-2].minor.yy355.mask = 0x0000ff; }
        break;
      case 49: /* refarg ::= ON UPDATE refact */
{ yymsp[-2].minor.yy367.value = yymsp[0].minor.yy96<<8;  yymsp[-2].minor.yy367.mask = 0x00ff00; }
{ yymsp[-2].minor.yy355.value = yymsp[0].minor.yy494<<8;  yymsp[-2].minor.yy355.mask = 0x00ff00; }
        break;
      case 50: /* refact ::= SET NULL */
{ yymsp[-1].minor.yy96 = OE_SetNull;  /* EV: R-33326-45252 */}
{ yymsp[-1].minor.yy494 = OE_SetNull;  /* EV: R-33326-45252 */}
        break;
      case 51: /* refact ::= SET DEFAULT */
{ yymsp[-1].minor.yy96 = OE_SetDflt;  /* EV: R-33326-45252 */}
{ yymsp[-1].minor.yy494 = OE_SetDflt;  /* EV: R-33326-45252 */}
        break;
      case 52: /* refact ::= CASCADE */
{ yymsp[0].minor.yy96 = OE_Cascade;  /* EV: R-33326-45252 */}
{ yymsp[0].minor.yy494 = OE_Cascade;  /* EV: R-33326-45252 */}
        break;
      case 53: /* refact ::= RESTRICT */
{ yymsp[0].minor.yy96 = OE_Restrict; /* EV: R-33326-45252 */}
{ yymsp[0].minor.yy494 = OE_Restrict; /* EV: R-33326-45252 */}
        break;
      case 54: /* refact ::= NO ACTION */
{ yymsp[-1].minor.yy96 = OE_None;     /* EV: R-33326-45252 */}
{ yymsp[-1].minor.yy494 = OE_None;     /* EV: R-33326-45252 */}
        break;
      case 55: /* defer_subclause ::= NOT DEFERRABLE init_deferred_pred_opt */
{yymsp[-2].minor.yy96 = 0;}
{yymsp[-2].minor.yy494 = 0;}
        break;
      case 56: /* defer_subclause ::= DEFERRABLE init_deferred_pred_opt */
      case 71: /* orconf ::= OR resolvetype */ yytestcase(yyruleno==71);
      case 156: /* insert_cmd ::= INSERT orconf */ yytestcase(yyruleno==156);
{yymsp[-1].minor.yy96 = yymsp[0].minor.yy96;}
{yymsp[-1].minor.yy494 = yymsp[0].minor.yy494;}
        break;
      case 58: /* init_deferred_pred_opt ::= INITIALLY DEFERRED */
      case 75: /* ifexists ::= IF EXISTS */ yytestcase(yyruleno==75);
      case 198: /* between_op ::= NOT BETWEEN */ yytestcase(yyruleno==198);
      case 201: /* in_op ::= NOT IN */ yytestcase(yyruleno==201);
      case 227: /* collate ::= COLLATE ID|STRING */ yytestcase(yyruleno==227);
{yymsp[-1].minor.yy96 = 1;}
{yymsp[-1].minor.yy494 = 1;}
        break;
      case 59: /* init_deferred_pred_opt ::= INITIALLY IMMEDIATE */
{yymsp[-1].minor.yy96 = 0;}
{yymsp[-1].minor.yy494 = 0;}
        break;
      case 61: /* tconscomma ::= COMMA */
{pParse->constraintName.n = 0;}
        break;
      case 63: /* tcons ::= PRIMARY KEY LP sortlist autoinc RP onconf */
{sqlite3AddPrimaryKey(pParse,yymsp[-3].minor.yy42,yymsp[0].minor.yy96,yymsp[-2].minor.yy96,0);}
{sqlite3AddPrimaryKey(pParse,yymsp[-3].minor.yy434,yymsp[0].minor.yy494,yymsp[-2].minor.yy494,0);}
        break;
      case 64: /* tcons ::= UNIQUE LP sortlist RP onconf */
{sqlite3CreateIndex(pParse,0,0,0,yymsp[-2].minor.yy42,yymsp[0].minor.yy96,0,0,0,0,
{sqlite3CreateIndex(pParse,0,0,0,yymsp[-2].minor.yy434,yymsp[0].minor.yy494,0,0,0,0,
                                       SQLITE_IDXTYPE_UNIQUE);}
        break;
      case 65: /* tcons ::= CHECK LP expr RP onconf */
{sqlite3AddCheckConstraint(pParse,yymsp[-2].minor.yy490);}
{sqlite3AddCheckConstraint(pParse,yymsp[-2].minor.yy524);}
        break;
      case 66: /* tcons ::= FOREIGN KEY LP eidlist RP REFERENCES nm eidlist_opt refargs defer_subclause_opt */
{
    sqlite3CreateForeignKey(pParse, yymsp[-6].minor.yy42, &yymsp[-3].minor.yy0, yymsp[-2].minor.yy42, yymsp[-1].minor.yy96);
    sqlite3DeferForeignKey(pParse, yymsp[0].minor.yy96);
    sqlite3CreateForeignKey(pParse, yymsp[-6].minor.yy434, &yymsp[-3].minor.yy0, yymsp[-2].minor.yy434, yymsp[-1].minor.yy494);
    sqlite3DeferForeignKey(pParse, yymsp[0].minor.yy494);
}
        break;
      case 68: /* onconf ::= */
      case 70: /* orconf ::= */ yytestcase(yyruleno==70);
{yymsp[1].minor.yy96 = OE_Default;}
{yymsp[1].minor.yy494 = OE_Default;}
        break;
      case 69: /* onconf ::= ON CONFLICT resolvetype */
{yymsp[-2].minor.yy96 = yymsp[0].minor.yy96;}
{yymsp[-2].minor.yy494 = yymsp[0].minor.yy494;}
        break;
      case 72: /* resolvetype ::= IGNORE */
{yymsp[0].minor.yy96 = OE_Ignore;}
{yymsp[0].minor.yy494 = OE_Ignore;}
        break;
      case 73: /* resolvetype ::= REPLACE */
      case 157: /* insert_cmd ::= REPLACE */ yytestcase(yyruleno==157);
{yymsp[0].minor.yy96 = OE_Replace;}
{yymsp[0].minor.yy494 = OE_Replace;}
        break;
      case 74: /* cmd ::= DROP TABLE ifexists fullname */
{
  sqlite3DropTable(pParse, yymsp[0].minor.yy167, 0, yymsp[-1].minor.yy96);
  sqlite3DropTable(pParse, yymsp[0].minor.yy483, 0, yymsp[-1].minor.yy494);
}
        break;
      case 77: /* cmd ::= createkw temp VIEW ifnotexists nm dbnm eidlist_opt AS select */
{
  sqlite3CreateView(pParse, &yymsp[-8].minor.yy0, &yymsp[-4].minor.yy0, &yymsp[-3].minor.yy0, yymsp[-2].minor.yy42, yymsp[0].minor.yy423, yymsp[-7].minor.yy96, yymsp[-5].minor.yy96);
  sqlite3CreateView(pParse, &yymsp[-8].minor.yy0, &yymsp[-4].minor.yy0, &yymsp[-3].minor.yy0, yymsp[-2].minor.yy434, yymsp[0].minor.yy457, yymsp[-7].minor.yy494, yymsp[-5].minor.yy494);
}
        break;
      case 78: /* cmd ::= DROP VIEW ifexists fullname */
{
  sqlite3DropTable(pParse, yymsp[0].minor.yy167, 1, yymsp[-1].minor.yy96);
  sqlite3DropTable(pParse, yymsp[0].minor.yy483, 1, yymsp[-1].minor.yy494);
}
        break;
      case 79: /* cmd ::= select */
{
  SelectDest dest = {SRT_Output, 0, 0, 0, 0, 0};
  sqlite3Select(pParse, yymsp[0].minor.yy423, &dest);
  sqlite3SelectDelete(pParse->db, yymsp[0].minor.yy423);
  sqlite3Select(pParse, yymsp[0].minor.yy457, &dest);
  sqlite3SelectDelete(pParse->db, yymsp[0].minor.yy457);
}
        break;
      case 80: /* select ::= WITH wqlist selectnowith */
{
  Select *p = yymsp[0].minor.yy423;
  Select *p = yymsp[0].minor.yy457;
  if( p ){
    p->pWith = yymsp[-1].minor.yy499;
    p->pWith = yymsp[-1].minor.yy59;
    parserDoubleLinkSelect(pParse, p);
  }else{
    sqlite3WithDelete(pParse->db, yymsp[-1].minor.yy499);
    sqlite3WithDelete(pParse->db, yymsp[-1].minor.yy59);
  }
  yymsp[-2].minor.yy423 = p;
  yymsp[-2].minor.yy457 = p;
}
        break;
      case 81: /* select ::= WITH RECURSIVE wqlist selectnowith */
{
  Select *p = yymsp[0].minor.yy423;
  Select *p = yymsp[0].minor.yy457;
  if( p ){
    p->pWith = yymsp[-1].minor.yy499;
    p->pWith = yymsp[-1].minor.yy59;
    parserDoubleLinkSelect(pParse, p);
  }else{
    sqlite3WithDelete(pParse->db, yymsp[-1].minor.yy499);
    sqlite3WithDelete(pParse->db, yymsp[-1].minor.yy59);
  }
  yymsp[-3].minor.yy423 = p;
  yymsp[-3].minor.yy457 = p;
}
        break;
      case 82: /* select ::= selectnowith */
{
  Select *p = yymsp[0].minor.yy423;
  Select *p = yymsp[0].minor.yy457;
  if( p ){
    parserDoubleLinkSelect(pParse, p);
  }
  yymsp[0].minor.yy423 = p; /*A-overwrites-X*/
  yymsp[0].minor.yy457 = p; /*A-overwrites-X*/
}
        break;
      case 83: /* selectnowith ::= selectnowith multiselect_op oneselect */
{
  Select *pRhs = yymsp[0].minor.yy423;
  Select *pLhs = yymsp[-2].minor.yy423;
  Select *pRhs = yymsp[0].minor.yy457;
  Select *pLhs = yymsp[-2].minor.yy457;
  if( pRhs && pRhs->pPrior ){
    SrcList *pFrom;
    Token x;
    x.n = 0;
    parserDoubleLinkSelect(pParse, pRhs);
    pFrom = sqlite3SrcListAppendFromTerm(pParse,0,0,0,&x,pRhs,0,0);
    pRhs = sqlite3SelectNew(pParse,0,pFrom,0,0,0,0,0,0);
  }
  if( pRhs ){
    pRhs->op = (u8)yymsp[-1].minor.yy96;
    pRhs->op = (u8)yymsp[-1].minor.yy494;
    pRhs->pPrior = pLhs;
    if( ALWAYS(pLhs) ) pLhs->selFlags &= ~SF_MultiValue;
    pRhs->selFlags &= ~SF_MultiValue;
    if( yymsp[-1].minor.yy96!=TK_ALL ) pParse->hasCompound = 1;
    if( yymsp[-1].minor.yy494!=TK_ALL ) pParse->hasCompound = 1;
  }else{
    sqlite3SelectDelete(pParse->db, pLhs);
  }
  yymsp[-2].minor.yy423 = pRhs;
  yymsp[-2].minor.yy457 = pRhs;
}
        break;
      case 84: /* multiselect_op ::= UNION */
      case 86: /* multiselect_op ::= EXCEPT|INTERSECT */ yytestcase(yyruleno==86);
{yymsp[0].minor.yy96 = yymsp[0].major; /*A-overwrites-OP*/}
{yymsp[0].minor.yy494 = yymsp[0].major; /*A-overwrites-OP*/}
        break;
      case 85: /* multiselect_op ::= UNION ALL */
{yymsp[-1].minor.yy96 = TK_ALL;}
{yymsp[-1].minor.yy494 = TK_ALL;}
        break;
      case 87: /* oneselect ::= SELECT distinct selcollist from where_opt groupby_opt having_opt orderby_opt limit_opt */
{
  yymsp[-8].minor.yy423 = sqlite3SelectNew(pParse,yymsp[-6].minor.yy42,yymsp[-5].minor.yy167,yymsp[-4].minor.yy490,yymsp[-3].minor.yy42,yymsp[-2].minor.yy490,yymsp[-1].minor.yy42,yymsp[-7].minor.yy96,yymsp[0].minor.yy490);
  yymsp[-8].minor.yy457 = sqlite3SelectNew(pParse,yymsp[-6].minor.yy434,yymsp[-5].minor.yy483,yymsp[-4].minor.yy524,yymsp[-3].minor.yy434,yymsp[-2].minor.yy524,yymsp[-1].minor.yy434,yymsp[-7].minor.yy494,yymsp[0].minor.yy524);
}
        break;
      case 88: /* oneselect ::= SELECT distinct selcollist from where_opt groupby_opt having_opt window_clause orderby_opt limit_opt */
{
  yymsp[-9].minor.yy423 = sqlite3SelectNew(pParse,yymsp[-7].minor.yy42,yymsp[-6].minor.yy167,yymsp[-5].minor.yy490,yymsp[-4].minor.yy42,yymsp[-3].minor.yy490,yymsp[-1].minor.yy42,yymsp[-8].minor.yy96,yymsp[0].minor.yy490);
  if( yymsp[-9].minor.yy423 ){
    yymsp[-9].minor.yy423->pWinDefn = yymsp[-2].minor.yy147;
  yymsp[-9].minor.yy457 = sqlite3SelectNew(pParse,yymsp[-7].minor.yy434,yymsp[-6].minor.yy483,yymsp[-5].minor.yy524,yymsp[-4].minor.yy434,yymsp[-3].minor.yy524,yymsp[-1].minor.yy434,yymsp[-8].minor.yy494,yymsp[0].minor.yy524);
  if( yymsp[-9].minor.yy457 ){
    yymsp[-9].minor.yy457->pWinDefn = yymsp[-2].minor.yy295;
  }else{
    sqlite3WindowListDelete(pParse->db, yymsp[-2].minor.yy147);
    sqlite3WindowListDelete(pParse->db, yymsp[-2].minor.yy295);
  }
}
        break;
      case 89: /* values ::= VALUES LP nexprlist RP */
{
  yymsp[-3].minor.yy423 = sqlite3SelectNew(pParse,yymsp[-1].minor.yy42,0,0,0,0,0,SF_Values,0);
  yymsp[-3].minor.yy457 = sqlite3SelectNew(pParse,yymsp[-1].minor.yy434,0,0,0,0,0,SF_Values,0);
}
        break;
      case 90: /* values ::= values COMMA LP nexprlist RP */
{
  Select *pRight, *pLeft = yymsp[-4].minor.yy423;
  pRight = sqlite3SelectNew(pParse,yymsp[-1].minor.yy42,0,0,0,0,0,SF_Values|SF_MultiValue,0);
  Select *pRight, *pLeft = yymsp[-4].minor.yy457;
  pRight = sqlite3SelectNew(pParse,yymsp[-1].minor.yy434,0,0,0,0,0,SF_Values|SF_MultiValue,0);
  if( ALWAYS(pLeft) ) pLeft->selFlags &= ~SF_MultiValue;
  if( pRight ){
    pRight->op = TK_ALL;
    pRight->pPrior = pLeft;
    yymsp[-4].minor.yy423 = pRight;
    yymsp[-4].minor.yy457 = pRight;
  }else{
    yymsp[-4].minor.yy423 = pLeft;
    yymsp[-4].minor.yy457 = pLeft;
  }
}
        break;
      case 91: /* distinct ::= DISTINCT */
{yymsp[0].minor.yy96 = SF_Distinct;}
{yymsp[0].minor.yy494 = SF_Distinct;}
        break;
      case 92: /* distinct ::= ALL */
{yymsp[0].minor.yy96 = SF_All;}
{yymsp[0].minor.yy494 = SF_All;}
        break;
      case 94: /* sclp ::= */
      case 127: /* orderby_opt ::= */ yytestcase(yyruleno==127);
      case 134: /* groupby_opt ::= */ yytestcase(yyruleno==134);
      case 214: /* exprlist ::= */ yytestcase(yyruleno==214);
      case 217: /* paren_exprlist ::= */ yytestcase(yyruleno==217);
      case 222: /* eidlist_opt ::= */ yytestcase(yyruleno==222);
{yymsp[1].minor.yy42 = 0;}
{yymsp[1].minor.yy434 = 0;}
        break;
      case 95: /* selcollist ::= sclp scanpt expr scanpt as */
{
   yymsp[-4].minor.yy42 = sqlite3ExprListAppend(pParse, yymsp[-4].minor.yy42, yymsp[-2].minor.yy490);
   if( yymsp[0].minor.yy0.n>0 ) sqlite3ExprListSetName(pParse, yymsp[-4].minor.yy42, &yymsp[0].minor.yy0, 1);
   sqlite3ExprListSetSpan(pParse,yymsp[-4].minor.yy42,yymsp[-3].minor.yy464,yymsp[-1].minor.yy464);
   yymsp[-4].minor.yy434 = sqlite3ExprListAppend(pParse, yymsp[-4].minor.yy434, yymsp[-2].minor.yy524);
   if( yymsp[0].minor.yy0.n>0 ) sqlite3ExprListSetName(pParse, yymsp[-4].minor.yy434, &yymsp[0].minor.yy0, 1);
   sqlite3ExprListSetSpan(pParse,yymsp[-4].minor.yy434,yymsp[-3].minor.yy294,yymsp[-1].minor.yy294);
}
        break;
      case 96: /* selcollist ::= sclp scanpt STAR */
{
  Expr *p = sqlite3Expr(pParse->db, TK_ASTERISK, 0);
  yymsp[-2].minor.yy42 = sqlite3ExprListAppend(pParse, yymsp[-2].minor.yy42, p);
  yymsp[-2].minor.yy434 = sqlite3ExprListAppend(pParse, yymsp[-2].minor.yy434, p);
}
        break;
      case 97: /* selcollist ::= sclp scanpt nm DOT STAR */
{
  Expr *pRight = sqlite3PExpr(pParse, TK_ASTERISK, 0, 0);
  Expr *pLeft = sqlite3ExprAlloc(pParse->db, TK_ID, &yymsp[-2].minor.yy0, 1);
  Expr *pDot = sqlite3PExpr(pParse, TK_DOT, pLeft, pRight);
  yymsp[-4].minor.yy42 = sqlite3ExprListAppend(pParse,yymsp[-4].minor.yy42, pDot);
  yymsp[-4].minor.yy434 = sqlite3ExprListAppend(pParse,yymsp[-4].minor.yy434, pDot);
}
        break;
      case 98: /* as ::= AS nm */
      case 109: /* dbnm ::= DOT nm */ yytestcase(yyruleno==109);
      case 238: /* plus_num ::= PLUS INTEGER|FLOAT */ yytestcase(yyruleno==238);
      case 239: /* minus_num ::= MINUS INTEGER|FLOAT */ yytestcase(yyruleno==239);
{yymsp[-1].minor.yy0 = yymsp[0].minor.yy0;}
        break;
      case 100: /* from ::= */
{yymsp[1].minor.yy167 = sqlite3DbMallocZero(pParse->db, sizeof(*yymsp[1].minor.yy167));}
{yymsp[1].minor.yy483 = sqlite3DbMallocZero(pParse->db, sizeof(*yymsp[1].minor.yy483));}
        break;
      case 101: /* from ::= FROM seltablist */
{
  yymsp[-1].minor.yy167 = yymsp[0].minor.yy167;
  sqlite3SrcListShiftJoinType(yymsp[-1].minor.yy167);
  yymsp[-1].minor.yy483 = yymsp[0].minor.yy483;
  sqlite3SrcListShiftJoinType(yymsp[-1].minor.yy483);
}
        break;
      case 102: /* stl_prefix ::= seltablist joinop */
{
   if( ALWAYS(yymsp[-1].minor.yy167 && yymsp[-1].minor.yy167->nSrc>0) ) yymsp[-1].minor.yy167->a[yymsp[-1].minor.yy167->nSrc-1].fg.jointype = (u8)yymsp[0].minor.yy96;
   if( ALWAYS(yymsp[-1].minor.yy483 && yymsp[-1].minor.yy483->nSrc>0) ) yymsp[-1].minor.yy483->a[yymsp[-1].minor.yy483->nSrc-1].fg.jointype = (u8)yymsp[0].minor.yy494;
}
        break;
      case 103: /* stl_prefix ::= */
{yymsp[1].minor.yy167 = 0;}
{yymsp[1].minor.yy483 = 0;}
        break;
      case 104: /* seltablist ::= stl_prefix nm dbnm as indexed_opt on_opt using_opt */
{
  yymsp[-6].minor.yy167 = sqlite3SrcListAppendFromTerm(pParse,yymsp[-6].minor.yy167,&yymsp[-5].minor.yy0,&yymsp[-4].minor.yy0,&yymsp[-3].minor.yy0,0,yymsp[-1].minor.yy490,yymsp[0].minor.yy336);
  sqlite3SrcListIndexedBy(pParse, yymsp[-6].minor.yy167, &yymsp[-2].minor.yy0);
  yymsp[-6].minor.yy483 = sqlite3SrcListAppendFromTerm(pParse,yymsp[-6].minor.yy483,&yymsp[-5].minor.yy0,&yymsp[-4].minor.yy0,&yymsp[-3].minor.yy0,0,yymsp[-1].minor.yy524,yymsp[0].minor.yy62);
  sqlite3SrcListIndexedBy(pParse, yymsp[-6].minor.yy483, &yymsp[-2].minor.yy0);
}
        break;
      case 105: /* seltablist ::= stl_prefix nm dbnm LP exprlist RP as on_opt using_opt */
{
  yymsp[-8].minor.yy167 = sqlite3SrcListAppendFromTerm(pParse,yymsp[-8].minor.yy167,&yymsp[-7].minor.yy0,&yymsp[-6].minor.yy0,&yymsp[-2].minor.yy0,0,yymsp[-1].minor.yy490,yymsp[0].minor.yy336);
  sqlite3SrcListFuncArgs(pParse, yymsp[-8].minor.yy167, yymsp[-4].minor.yy42);
  yymsp[-8].minor.yy483 = sqlite3SrcListAppendFromTerm(pParse,yymsp[-8].minor.yy483,&yymsp[-7].minor.yy0,&yymsp[-6].minor.yy0,&yymsp[-2].minor.yy0,0,yymsp[-1].minor.yy524,yymsp[0].minor.yy62);
  sqlite3SrcListFuncArgs(pParse, yymsp[-8].minor.yy483, yymsp[-4].minor.yy434);
}
        break;
      case 106: /* seltablist ::= stl_prefix LP select RP as on_opt using_opt */
{
    yymsp[-6].minor.yy167 = sqlite3SrcListAppendFromTerm(pParse,yymsp[-6].minor.yy167,0,0,&yymsp[-2].minor.yy0,yymsp[-4].minor.yy423,yymsp[-1].minor.yy490,yymsp[0].minor.yy336);
    yymsp[-6].minor.yy483 = sqlite3SrcListAppendFromTerm(pParse,yymsp[-6].minor.yy483,0,0,&yymsp[-2].minor.yy0,yymsp[-4].minor.yy457,yymsp[-1].minor.yy524,yymsp[0].minor.yy62);
  }
        break;
      case 107: /* seltablist ::= stl_prefix LP seltablist RP as on_opt using_opt */
{
    if( yymsp[-6].minor.yy167==0 && yymsp[-2].minor.yy0.n==0 && yymsp[-1].minor.yy490==0 && yymsp[0].minor.yy336==0 ){
      yymsp[-6].minor.yy167 = yymsp[-4].minor.yy167;
    }else if( yymsp[-4].minor.yy167->nSrc==1 ){
      yymsp[-6].minor.yy167 = sqlite3SrcListAppendFromTerm(pParse,yymsp[-6].minor.yy167,0,0,&yymsp[-2].minor.yy0,0,yymsp[-1].minor.yy490,yymsp[0].minor.yy336);
      if( yymsp[-6].minor.yy167 ){
        struct SrcList_item *pNew = &yymsp[-6].minor.yy167->a[yymsp[-6].minor.yy167->nSrc-1];
        struct SrcList_item *pOld = yymsp[-4].minor.yy167->a;
    if( yymsp[-6].minor.yy483==0 && yymsp[-2].minor.yy0.n==0 && yymsp[-1].minor.yy524==0 && yymsp[0].minor.yy62==0 ){
      yymsp[-6].minor.yy483 = yymsp[-4].minor.yy483;
    }else if( yymsp[-4].minor.yy483->nSrc==1 ){
      yymsp[-6].minor.yy483 = sqlite3SrcListAppendFromTerm(pParse,yymsp[-6].minor.yy483,0,0,&yymsp[-2].minor.yy0,0,yymsp[-1].minor.yy524,yymsp[0].minor.yy62);
      if( yymsp[-6].minor.yy483 ){
        struct SrcList_item *pNew = &yymsp[-6].minor.yy483->a[yymsp[-6].minor.yy483->nSrc-1];
        struct SrcList_item *pOld = yymsp[-4].minor.yy483->a;
        pNew->zName = pOld->zName;
        pNew->zDatabase = pOld->zDatabase;
        pNew->pSelect = pOld->pSelect;
        if( pOld->fg.isTabFunc ){
          pNew->u1.pFuncArg = pOld->u1.pFuncArg;
          pOld->u1.pFuncArg = 0;
          pOld->fg.isTabFunc = 0;
          pNew->fg.isTabFunc = 1;
        }
        pOld->zName = pOld->zDatabase = 0;
        pOld->pSelect = 0;
      }
      sqlite3SrcListDelete(pParse->db, yymsp[-4].minor.yy167);
      sqlite3SrcListDelete(pParse->db, yymsp[-4].minor.yy483);
    }else{
      Select *pSubquery;
      sqlite3SrcListShiftJoinType(yymsp[-4].minor.yy167);
      pSubquery = sqlite3SelectNew(pParse,0,yymsp[-4].minor.yy167,0,0,0,0,SF_NestedFrom,0);
      yymsp[-6].minor.yy167 = sqlite3SrcListAppendFromTerm(pParse,yymsp[-6].minor.yy167,0,0,&yymsp[-2].minor.yy0,pSubquery,yymsp[-1].minor.yy490,yymsp[0].minor.yy336);
      sqlite3SrcListShiftJoinType(yymsp[-4].minor.yy483);
      pSubquery = sqlite3SelectNew(pParse,0,yymsp[-4].minor.yy483,0,0,0,0,SF_NestedFrom,0);
      yymsp[-6].minor.yy483 = sqlite3SrcListAppendFromTerm(pParse,yymsp[-6].minor.yy483,0,0,&yymsp[-2].minor.yy0,pSubquery,yymsp[-1].minor.yy524,yymsp[0].minor.yy62);
    }
  }
        break;
      case 108: /* dbnm ::= */
      case 122: /* indexed_opt ::= */ yytestcase(yyruleno==122);
{yymsp[1].minor.yy0.z=0; yymsp[1].minor.yy0.n=0;}
        break;
      case 110: /* fullname ::= nm */
{
  yylhsminor.yy167 = sqlite3SrcListAppend(pParse,0,&yymsp[0].minor.yy0,0);
  if( IN_RENAME_OBJECT && yylhsminor.yy167 ) sqlite3RenameTokenMap(pParse, yylhsminor.yy167->a[0].zName, &yymsp[0].minor.yy0);
  yylhsminor.yy483 = sqlite3SrcListAppend(pParse,0,&yymsp[0].minor.yy0,0);
  if( IN_RENAME_OBJECT && yylhsminor.yy483 ) sqlite3RenameTokenMap(pParse, yylhsminor.yy483->a[0].zName, &yymsp[0].minor.yy0);
}
  yymsp[0].minor.yy167 = yylhsminor.yy167;
  yymsp[0].minor.yy483 = yylhsminor.yy483;
        break;
      case 111: /* fullname ::= nm DOT nm */
{
  yylhsminor.yy167 = sqlite3SrcListAppend(pParse,0,&yymsp[-2].minor.yy0,&yymsp[0].minor.yy0);
  if( IN_RENAME_OBJECT && yylhsminor.yy167 ) sqlite3RenameTokenMap(pParse, yylhsminor.yy167->a[0].zName, &yymsp[0].minor.yy0);
  yylhsminor.yy483 = sqlite3SrcListAppend(pParse,0,&yymsp[-2].minor.yy0,&yymsp[0].minor.yy0);
  if( IN_RENAME_OBJECT && yylhsminor.yy483 ) sqlite3RenameTokenMap(pParse, yylhsminor.yy483->a[0].zName, &yymsp[0].minor.yy0);
}
  yymsp[-2].minor.yy167 = yylhsminor.yy167;
  yymsp[-2].minor.yy483 = yylhsminor.yy483;
        break;
      case 112: /* xfullname ::= nm */
{yymsp[0].minor.yy167 = sqlite3SrcListAppend(pParse,0,&yymsp[0].minor.yy0,0); /*A-overwrites-X*/}
{yymsp[0].minor.yy483 = sqlite3SrcListAppend(pParse,0,&yymsp[0].minor.yy0,0); /*A-overwrites-X*/}
        break;
      case 113: /* xfullname ::= nm DOT nm */
{yymsp[-2].minor.yy167 = sqlite3SrcListAppend(pParse,0,&yymsp[-2].minor.yy0,&yymsp[0].minor.yy0); /*A-overwrites-X*/}
{yymsp[-2].minor.yy483 = sqlite3SrcListAppend(pParse,0,&yymsp[-2].minor.yy0,&yymsp[0].minor.yy0); /*A-overwrites-X*/}
        break;
      case 114: /* xfullname ::= nm DOT nm AS nm */
{
   yymsp[-4].minor.yy167 = sqlite3SrcListAppend(pParse,0,&yymsp[-4].minor.yy0,&yymsp[-2].minor.yy0); /*A-overwrites-X*/
   if( yymsp[-4].minor.yy167 ) yymsp[-4].minor.yy167->a[0].zAlias = sqlite3NameFromToken(pParse->db, &yymsp[0].minor.yy0);
   yymsp[-4].minor.yy483 = sqlite3SrcListAppend(pParse,0,&yymsp[-4].minor.yy0,&yymsp[-2].minor.yy0); /*A-overwrites-X*/
   if( yymsp[-4].minor.yy483 ) yymsp[-4].minor.yy483->a[0].zAlias = sqlite3NameFromToken(pParse->db, &yymsp[0].minor.yy0);
}
        break;
      case 115: /* xfullname ::= nm AS nm */
{  
   yymsp[-2].minor.yy167 = sqlite3SrcListAppend(pParse,0,&yymsp[-2].minor.yy0,0); /*A-overwrites-X*/
   if( yymsp[-2].minor.yy167 ) yymsp[-2].minor.yy167->a[0].zAlias = sqlite3NameFromToken(pParse->db, &yymsp[0].minor.yy0);
   yymsp[-2].minor.yy483 = sqlite3SrcListAppend(pParse,0,&yymsp[-2].minor.yy0,0); /*A-overwrites-X*/
   if( yymsp[-2].minor.yy483 ) yymsp[-2].minor.yy483->a[0].zAlias = sqlite3NameFromToken(pParse->db, &yymsp[0].minor.yy0);
}
        break;
      case 116: /* joinop ::= COMMA|JOIN */
{ yymsp[0].minor.yy96 = JT_INNER; }
{ yymsp[0].minor.yy494 = JT_INNER; }
        break;
      case 117: /* joinop ::= JOIN_KW JOIN */
{yymsp[-1].minor.yy96 = sqlite3JoinType(pParse,&yymsp[-1].minor.yy0,0,0);  /*X-overwrites-A*/}
{yymsp[-1].minor.yy494 = sqlite3JoinType(pParse,&yymsp[-1].minor.yy0,0,0);  /*X-overwrites-A*/}
        break;
      case 118: /* joinop ::= JOIN_KW nm JOIN */
{yymsp[-2].minor.yy96 = sqlite3JoinType(pParse,&yymsp[-2].minor.yy0,&yymsp[-1].minor.yy0,0); /*X-overwrites-A*/}
{yymsp[-2].minor.yy494 = sqlite3JoinType(pParse,&yymsp[-2].minor.yy0,&yymsp[-1].minor.yy0,0); /*X-overwrites-A*/}
        break;
      case 119: /* joinop ::= JOIN_KW nm nm JOIN */
{yymsp[-3].minor.yy96 = sqlite3JoinType(pParse,&yymsp[-3].minor.yy0,&yymsp[-2].minor.yy0,&yymsp[-1].minor.yy0);/*X-overwrites-A*/}
{yymsp[-3].minor.yy494 = sqlite3JoinType(pParse,&yymsp[-3].minor.yy0,&yymsp[-2].minor.yy0,&yymsp[-1].minor.yy0);/*X-overwrites-A*/}
        break;
      case 120: /* on_opt ::= ON expr */
      case 137: /* having_opt ::= HAVING expr */ yytestcase(yyruleno==137);
      case 144: /* where_opt ::= WHERE expr */ yytestcase(yyruleno==144);
      case 210: /* case_else ::= ELSE expr */ yytestcase(yyruleno==210);
      case 231: /* vinto ::= INTO expr */ yytestcase(yyruleno==231);
{yymsp[-1].minor.yy490 = yymsp[0].minor.yy490;}
{yymsp[-1].minor.yy524 = yymsp[0].minor.yy524;}
        break;
      case 121: /* on_opt ::= */
      case 136: /* having_opt ::= */ yytestcase(yyruleno==136);
      case 138: /* limit_opt ::= */ yytestcase(yyruleno==138);
      case 143: /* where_opt ::= */ yytestcase(yyruleno==143);
      case 211: /* case_else ::= */ yytestcase(yyruleno==211);
      case 213: /* case_operand ::= */ yytestcase(yyruleno==213);
      case 232: /* vinto ::= */ yytestcase(yyruleno==232);
{yymsp[1].minor.yy490 = 0;}
{yymsp[1].minor.yy524 = 0;}
        break;
      case 123: /* indexed_opt ::= INDEXED BY nm */
{yymsp[-2].minor.yy0 = yymsp[0].minor.yy0;}
        break;
      case 124: /* indexed_opt ::= NOT INDEXED */
{yymsp[-1].minor.yy0.z=0; yymsp[-1].minor.yy0.n=1;}
        break;
      case 125: /* using_opt ::= USING LP idlist RP */
{yymsp[-3].minor.yy336 = yymsp[-1].minor.yy336;}
{yymsp[-3].minor.yy62 = yymsp[-1].minor.yy62;}
        break;
      case 126: /* using_opt ::= */
      case 158: /* idlist_opt ::= */ yytestcase(yyruleno==158);
{yymsp[1].minor.yy336 = 0;}
{yymsp[1].minor.yy62 = 0;}
        break;
      case 128: /* orderby_opt ::= ORDER BY sortlist */
      case 135: /* groupby_opt ::= GROUP BY nexprlist */ yytestcase(yyruleno==135);
{yymsp[-2].minor.yy42 = yymsp[0].minor.yy42;}
{yymsp[-2].minor.yy434 = yymsp[0].minor.yy434;}
        break;
      case 129: /* sortlist ::= sortlist COMMA expr sortorder */
{
  yymsp[-3].minor.yy42 = sqlite3ExprListAppend(pParse,yymsp[-3].minor.yy42,yymsp[-1].minor.yy490);
  sqlite3ExprListSetSortOrder(yymsp[-3].minor.yy42,yymsp[0].minor.yy96);
  yymsp[-3].minor.yy434 = sqlite3ExprListAppend(pParse,yymsp[-3].minor.yy434,yymsp[-1].minor.yy524);
  sqlite3ExprListSetSortOrder(yymsp[-3].minor.yy434,yymsp[0].minor.yy494);
}
        break;
      case 130: /* sortlist ::= expr sortorder */
{
  yymsp[-1].minor.yy42 = sqlite3ExprListAppend(pParse,0,yymsp[-1].minor.yy490); /*A-overwrites-Y*/
  sqlite3ExprListSetSortOrder(yymsp[-1].minor.yy42,yymsp[0].minor.yy96);
  yymsp[-1].minor.yy434 = sqlite3ExprListAppend(pParse,0,yymsp[-1].minor.yy524); /*A-overwrites-Y*/
  sqlite3ExprListSetSortOrder(yymsp[-1].minor.yy434,yymsp[0].minor.yy494);
}
        break;
      case 131: /* sortorder ::= ASC */
{yymsp[0].minor.yy96 = SQLITE_SO_ASC;}
{yymsp[0].minor.yy494 = SQLITE_SO_ASC;}
        break;
      case 132: /* sortorder ::= DESC */
{yymsp[0].minor.yy96 = SQLITE_SO_DESC;}
{yymsp[0].minor.yy494 = SQLITE_SO_DESC;}
        break;
      case 133: /* sortorder ::= */
{yymsp[1].minor.yy96 = SQLITE_SO_UNDEFINED;}
{yymsp[1].minor.yy494 = SQLITE_SO_UNDEFINED;}
        break;
      case 139: /* limit_opt ::= LIMIT expr */
{yymsp[-1].minor.yy490 = sqlite3PExpr(pParse,TK_LIMIT,yymsp[0].minor.yy490,0);}
{yymsp[-1].minor.yy524 = sqlite3PExpr(pParse,TK_LIMIT,yymsp[0].minor.yy524,0);}
        break;
      case 140: /* limit_opt ::= LIMIT expr OFFSET expr */
{yymsp[-3].minor.yy490 = sqlite3PExpr(pParse,TK_LIMIT,yymsp[-2].minor.yy490,yymsp[0].minor.yy490);}
{yymsp[-3].minor.yy524 = sqlite3PExpr(pParse,TK_LIMIT,yymsp[-2].minor.yy524,yymsp[0].minor.yy524);}
        break;
      case 141: /* limit_opt ::= LIMIT expr COMMA expr */
{yymsp[-3].minor.yy490 = sqlite3PExpr(pParse,TK_LIMIT,yymsp[0].minor.yy490,yymsp[-2].minor.yy490);}
{yymsp[-3].minor.yy524 = sqlite3PExpr(pParse,TK_LIMIT,yymsp[0].minor.yy524,yymsp[-2].minor.yy524);}
        break;
      case 142: /* cmd ::= with DELETE FROM xfullname indexed_opt where_opt */
{
  sqlite3SrcListIndexedBy(pParse, yymsp[-2].minor.yy167, &yymsp[-1].minor.yy0);
  sqlite3DeleteFrom(pParse,yymsp[-2].minor.yy167,yymsp[0].minor.yy490,0,0);
  sqlite3SrcListIndexedBy(pParse, yymsp[-2].minor.yy483, &yymsp[-1].minor.yy0);
  sqlite3DeleteFrom(pParse,yymsp[-2].minor.yy483,yymsp[0].minor.yy524,0,0);
}
        break;
      case 145: /* cmd ::= with UPDATE orconf xfullname indexed_opt SET setlist where_opt */
{
  sqlite3SrcListIndexedBy(pParse, yymsp[-4].minor.yy167, &yymsp[-3].minor.yy0);
  sqlite3ExprListCheckLength(pParse,yymsp[-1].minor.yy42,"set list"); 
  sqlite3Update(pParse,yymsp[-4].minor.yy167,yymsp[-1].minor.yy42,yymsp[0].minor.yy490,yymsp[-5].minor.yy96,0,0,0);
  sqlite3SrcListIndexedBy(pParse, yymsp[-4].minor.yy483, &yymsp[-3].minor.yy0);
  sqlite3ExprListCheckLength(pParse,yymsp[-1].minor.yy434,"set list"); 
  sqlite3Update(pParse,yymsp[-4].minor.yy483,yymsp[-1].minor.yy434,yymsp[0].minor.yy524,yymsp[-5].minor.yy494,0,0,0);
}
        break;
      case 146: /* setlist ::= setlist COMMA nm EQ expr */
{
  yymsp[-4].minor.yy42 = sqlite3ExprListAppend(pParse, yymsp[-4].minor.yy42, yymsp[0].minor.yy490);
  sqlite3ExprListSetName(pParse, yymsp[-4].minor.yy42, &yymsp[-2].minor.yy0, 1);
  yymsp[-4].minor.yy434 = sqlite3ExprListAppend(pParse, yymsp[-4].minor.yy434, yymsp[0].minor.yy524);
  sqlite3ExprListSetName(pParse, yymsp[-4].minor.yy434, &yymsp[-2].minor.yy0, 1);
}
        break;
      case 147: /* setlist ::= setlist COMMA LP idlist RP EQ expr */
{
  yymsp[-6].minor.yy42 = sqlite3ExprListAppendVector(pParse, yymsp[-6].minor.yy42, yymsp[-3].minor.yy336, yymsp[0].minor.yy490);
  yymsp[-6].minor.yy434 = sqlite3ExprListAppendVector(pParse, yymsp[-6].minor.yy434, yymsp[-3].minor.yy62, yymsp[0].minor.yy524);
}
        break;
      case 148: /* setlist ::= nm EQ expr */
{
  yylhsminor.yy42 = sqlite3ExprListAppend(pParse, 0, yymsp[0].minor.yy490);
  sqlite3ExprListSetName(pParse, yylhsminor.yy42, &yymsp[-2].minor.yy0, 1);
  yylhsminor.yy434 = sqlite3ExprListAppend(pParse, 0, yymsp[0].minor.yy524);
  sqlite3ExprListSetName(pParse, yylhsminor.yy434, &yymsp[-2].minor.yy0, 1);
}
  yymsp[-2].minor.yy42 = yylhsminor.yy42;
  yymsp[-2].minor.yy434 = yylhsminor.yy434;
        break;
      case 149: /* setlist ::= LP idlist RP EQ expr */
{
  yymsp[-4].minor.yy42 = sqlite3ExprListAppendVector(pParse, 0, yymsp[-3].minor.yy336, yymsp[0].minor.yy490);
  yymsp[-4].minor.yy434 = sqlite3ExprListAppendVector(pParse, 0, yymsp[-3].minor.yy62, yymsp[0].minor.yy524);
}
        break;
      case 150: /* cmd ::= with insert_cmd INTO xfullname idlist_opt select upsert */
{
  sqlite3Insert(pParse, yymsp[-3].minor.yy167, yymsp[-1].minor.yy423, yymsp[-2].minor.yy336, yymsp[-5].minor.yy96, yymsp[0].minor.yy266);
  sqlite3Insert(pParse, yymsp[-3].minor.yy483, yymsp[-1].minor.yy457, yymsp[-2].minor.yy62, yymsp[-5].minor.yy494, yymsp[0].minor.yy136);
}
        break;
      case 151: /* cmd ::= with insert_cmd INTO xfullname idlist_opt DEFAULT VALUES */
{
  sqlite3Insert(pParse, yymsp[-3].minor.yy167, 0, yymsp[-2].minor.yy336, yymsp[-5].minor.yy96, 0);
  sqlite3Insert(pParse, yymsp[-3].minor.yy483, 0, yymsp[-2].minor.yy62, yymsp[-5].minor.yy494, 0);
}
        break;
      case 152: /* upsert ::= */
{ yymsp[1].minor.yy266 = 0; }
{ yymsp[1].minor.yy136 = 0; }
        break;
      case 153: /* upsert ::= ON CONFLICT LP sortlist RP where_opt DO UPDATE SET setlist where_opt */
{ yymsp[-10].minor.yy266 = sqlite3UpsertNew(pParse->db,yymsp[-7].minor.yy42,yymsp[-5].minor.yy490,yymsp[-1].minor.yy42,yymsp[0].minor.yy490);}
{ yymsp[-10].minor.yy136 = sqlite3UpsertNew(pParse->db,yymsp[-7].minor.yy434,yymsp[-5].minor.yy524,yymsp[-1].minor.yy434,yymsp[0].minor.yy524);}
        break;
      case 154: /* upsert ::= ON CONFLICT LP sortlist RP where_opt DO NOTHING */
{ yymsp[-7].minor.yy266 = sqlite3UpsertNew(pParse->db,yymsp[-4].minor.yy42,yymsp[-2].minor.yy490,0,0); }
{ yymsp[-7].minor.yy136 = sqlite3UpsertNew(pParse->db,yymsp[-4].minor.yy434,yymsp[-2].minor.yy524,0,0); }
        break;
      case 155: /* upsert ::= ON CONFLICT DO NOTHING */
{ yymsp[-3].minor.yy266 = sqlite3UpsertNew(pParse->db,0,0,0,0); }
{ yymsp[-3].minor.yy136 = sqlite3UpsertNew(pParse->db,0,0,0,0); }
        break;
      case 159: /* idlist_opt ::= LP idlist RP */
{yymsp[-2].minor.yy336 = yymsp[-1].minor.yy336;}
{yymsp[-2].minor.yy62 = yymsp[-1].minor.yy62;}
        break;
      case 160: /* idlist ::= idlist COMMA nm */
{yymsp[-2].minor.yy336 = sqlite3IdListAppend(pParse,yymsp[-2].minor.yy336,&yymsp[0].minor.yy0);}
{yymsp[-2].minor.yy62 = sqlite3IdListAppend(pParse,yymsp[-2].minor.yy62,&yymsp[0].minor.yy0);}
        break;
      case 161: /* idlist ::= nm */
{yymsp[0].minor.yy336 = sqlite3IdListAppend(pParse,0,&yymsp[0].minor.yy0); /*A-overwrites-Y*/}
{yymsp[0].minor.yy62 = sqlite3IdListAppend(pParse,0,&yymsp[0].minor.yy0); /*A-overwrites-Y*/}
        break;
      case 162: /* expr ::= LP expr RP */
{yymsp[-2].minor.yy490 = yymsp[-1].minor.yy490;}
{yymsp[-2].minor.yy524 = yymsp[-1].minor.yy524;}
        break;
      case 163: /* expr ::= ID|INDEXED */
      case 164: /* expr ::= JOIN_KW */ yytestcase(yyruleno==164);
{yymsp[0].minor.yy490=tokenExpr(pParse,TK_ID,yymsp[0].minor.yy0); /*A-overwrites-X*/}
{yymsp[0].minor.yy524=tokenExpr(pParse,TK_ID,yymsp[0].minor.yy0); /*A-overwrites-X*/}
        break;
      case 165: /* expr ::= nm DOT nm */
{
  Expr *temp1 = sqlite3ExprAlloc(pParse->db, TK_ID, &yymsp[-2].minor.yy0, 1);
  Expr *temp2 = sqlite3ExprAlloc(pParse->db, TK_ID, &yymsp[0].minor.yy0, 1);
  if( IN_RENAME_OBJECT ){
    sqlite3RenameTokenMap(pParse, (void*)temp2, &yymsp[0].minor.yy0);
    sqlite3RenameTokenMap(pParse, (void*)temp1, &yymsp[-2].minor.yy0);
  }
  yylhsminor.yy490 = sqlite3PExpr(pParse, TK_DOT, temp1, temp2);
  yylhsminor.yy524 = sqlite3PExpr(pParse, TK_DOT, temp1, temp2);
}
  yymsp[-2].minor.yy490 = yylhsminor.yy490;
  yymsp[-2].minor.yy524 = yylhsminor.yy524;
        break;
      case 166: /* expr ::= nm DOT nm DOT nm */
{
  Expr *temp1 = sqlite3ExprAlloc(pParse->db, TK_ID, &yymsp[-4].minor.yy0, 1);
  Expr *temp2 = sqlite3ExprAlloc(pParse->db, TK_ID, &yymsp[-2].minor.yy0, 1);
  Expr *temp3 = sqlite3ExprAlloc(pParse->db, TK_ID, &yymsp[0].minor.yy0, 1);
  Expr *temp4 = sqlite3PExpr(pParse, TK_DOT, temp2, temp3);
  if( IN_RENAME_OBJECT ){
    sqlite3RenameTokenMap(pParse, (void*)temp3, &yymsp[0].minor.yy0);
    sqlite3RenameTokenMap(pParse, (void*)temp2, &yymsp[-2].minor.yy0);
  }
  yylhsminor.yy490 = sqlite3PExpr(pParse, TK_DOT, temp1, temp4);
  yylhsminor.yy524 = sqlite3PExpr(pParse, TK_DOT, temp1, temp4);
}
  yymsp[-4].minor.yy490 = yylhsminor.yy490;
  yymsp[-4].minor.yy524 = yylhsminor.yy524;
        break;
      case 167: /* term ::= NULL|FLOAT|BLOB */
      case 168: /* term ::= STRING */ yytestcase(yyruleno==168);
{yymsp[0].minor.yy490=tokenExpr(pParse,yymsp[0].major,yymsp[0].minor.yy0); /*A-overwrites-X*/}
{yymsp[0].minor.yy524=tokenExpr(pParse,yymsp[0].major,yymsp[0].minor.yy0); /*A-overwrites-X*/}
        break;
      case 169: /* term ::= INTEGER */
{
  yylhsminor.yy490 = sqlite3ExprAlloc(pParse->db, TK_INTEGER, &yymsp[0].minor.yy0, 1);
  yylhsminor.yy524 = sqlite3ExprAlloc(pParse->db, TK_INTEGER, &yymsp[0].minor.yy0, 1);
}
  yymsp[0].minor.yy490 = yylhsminor.yy490;
  yymsp[0].minor.yy524 = yylhsminor.yy524;
        break;
      case 170: /* expr ::= VARIABLE */
{
  if( !(yymsp[0].minor.yy0.z[0]=='#' && sqlite3Isdigit(yymsp[0].minor.yy0.z[1])) ){
    u32 n = yymsp[0].minor.yy0.n;
    yymsp[0].minor.yy490 = tokenExpr(pParse, TK_VARIABLE, yymsp[0].minor.yy0);
    sqlite3ExprAssignVarNumber(pParse, yymsp[0].minor.yy490, n);
    yymsp[0].minor.yy524 = tokenExpr(pParse, TK_VARIABLE, yymsp[0].minor.yy0);
    sqlite3ExprAssignVarNumber(pParse, yymsp[0].minor.yy524, n);
  }else{
    /* When doing a nested parse, one can include terms in an expression
    ** that look like this:   #1 #2 ...  These terms refer to registers
    ** in the virtual machine.  #N is the N-th register. */
    Token t = yymsp[0].minor.yy0; /*A-overwrites-X*/
    assert( t.n>=2 );
    if( pParse->nested==0 ){
      sqlite3ErrorMsg(pParse, "near \"%T\": syntax error", &t);
      yymsp[0].minor.yy490 = 0;
      yymsp[0].minor.yy524 = 0;
    }else{
      yymsp[0].minor.yy490 = sqlite3PExpr(pParse, TK_REGISTER, 0, 0);
      if( yymsp[0].minor.yy490 ) sqlite3GetInt32(&t.z[1], &yymsp[0].minor.yy490->iTable);
      yymsp[0].minor.yy524 = sqlite3PExpr(pParse, TK_REGISTER, 0, 0);
      if( yymsp[0].minor.yy524 ) sqlite3GetInt32(&t.z[1], &yymsp[0].minor.yy524->iTable);
    }
  }
}
        break;
      case 171: /* expr ::= expr COLLATE ID|STRING */
{
  yymsp[-2].minor.yy490 = sqlite3ExprAddCollateToken(pParse, yymsp[-2].minor.yy490, &yymsp[0].minor.yy0, 1);
  yymsp[-2].minor.yy524 = sqlite3ExprAddCollateToken(pParse, yymsp[-2].minor.yy524, &yymsp[0].minor.yy0, 1);
}
        break;
      case 172: /* expr ::= CAST LP expr AS typetoken RP */
{
  yymsp[-5].minor.yy490 = sqlite3ExprAlloc(pParse->db, TK_CAST, &yymsp[-1].minor.yy0, 1);
  sqlite3ExprAttachSubtrees(pParse->db, yymsp[-5].minor.yy490, yymsp[-3].minor.yy490, 0);
  yymsp[-5].minor.yy524 = sqlite3ExprAlloc(pParse->db, TK_CAST, &yymsp[-1].minor.yy0, 1);
  sqlite3ExprAttachSubtrees(pParse->db, yymsp[-5].minor.yy524, yymsp[-3].minor.yy524, 0);
}
        break;
      case 173: /* expr ::= ID|INDEXED LP distinct exprlist RP */
{
  yylhsminor.yy490 = sqlite3ExprFunction(pParse, yymsp[-1].minor.yy42, &yymsp[-4].minor.yy0, yymsp[-2].minor.yy96);
  yylhsminor.yy524 = sqlite3ExprFunction(pParse, yymsp[-1].minor.yy434, &yymsp[-4].minor.yy0, yymsp[-2].minor.yy494);
}
  yymsp[-4].minor.yy490 = yylhsminor.yy490;
  yymsp[-4].minor.yy524 = yylhsminor.yy524;
        break;
      case 174: /* expr ::= ID|INDEXED LP STAR RP */
{
  yylhsminor.yy490 = sqlite3ExprFunction(pParse, 0, &yymsp[-3].minor.yy0, 0);
  yylhsminor.yy524 = sqlite3ExprFunction(pParse, 0, &yymsp[-3].minor.yy0, 0);
}
  yymsp[-3].minor.yy490 = yylhsminor.yy490;
  yymsp[-3].minor.yy524 = yylhsminor.yy524;
        break;
      case 175: /* expr ::= ID|INDEXED LP distinct exprlist RP over_clause */
{
  yylhsminor.yy490 = sqlite3ExprFunction(pParse, yymsp[-2].minor.yy42, &yymsp[-5].minor.yy0, yymsp[-3].minor.yy96);
  sqlite3WindowAttach(pParse, yylhsminor.yy490, yymsp[0].minor.yy147);
  yylhsminor.yy524 = sqlite3ExprFunction(pParse, yymsp[-2].minor.yy434, &yymsp[-5].minor.yy0, yymsp[-3].minor.yy494);
  sqlite3WindowAttach(pParse, yylhsminor.yy524, yymsp[0].minor.yy295);
}
  yymsp[-5].minor.yy490 = yylhsminor.yy490;
  yymsp[-5].minor.yy524 = yylhsminor.yy524;
        break;
      case 176: /* expr ::= ID|INDEXED LP STAR RP over_clause */
{
  yylhsminor.yy490 = sqlite3ExprFunction(pParse, 0, &yymsp[-4].minor.yy0, 0);
  sqlite3WindowAttach(pParse, yylhsminor.yy490, yymsp[0].minor.yy147);
  yylhsminor.yy524 = sqlite3ExprFunction(pParse, 0, &yymsp[-4].minor.yy0, 0);
  sqlite3WindowAttach(pParse, yylhsminor.yy524, yymsp[0].minor.yy295);
}
  yymsp[-4].minor.yy490 = yylhsminor.yy490;
  yymsp[-4].minor.yy524 = yylhsminor.yy524;
        break;
      case 177: /* term ::= CTIME_KW */
{
  yylhsminor.yy490 = sqlite3ExprFunction(pParse, 0, &yymsp[0].minor.yy0, 0);
  yylhsminor.yy524 = sqlite3ExprFunction(pParse, 0, &yymsp[0].minor.yy0, 0);
}
  yymsp[0].minor.yy490 = yylhsminor.yy490;
  yymsp[0].minor.yy524 = yylhsminor.yy524;
        break;
      case 178: /* expr ::= LP nexprlist COMMA expr RP */
{
  ExprList *pList = sqlite3ExprListAppend(pParse, yymsp[-3].minor.yy42, yymsp[-1].minor.yy490);
  yymsp[-4].minor.yy490 = sqlite3PExpr(pParse, TK_VECTOR, 0, 0);
  if( yymsp[-4].minor.yy490 ){
    yymsp[-4].minor.yy490->x.pList = pList;
  ExprList *pList = sqlite3ExprListAppend(pParse, yymsp[-3].minor.yy434, yymsp[-1].minor.yy524);
  yymsp[-4].minor.yy524 = sqlite3PExpr(pParse, TK_VECTOR, 0, 0);
  if( yymsp[-4].minor.yy524 ){
    yymsp[-4].minor.yy524->x.pList = pList;
  }else{
    sqlite3ExprListDelete(pParse->db, pList);
  }
}
        break;
      case 179: /* expr ::= expr AND expr */
      case 180: /* expr ::= expr OR expr */ yytestcase(yyruleno==180);
      case 181: /* expr ::= expr LT|GT|GE|LE expr */ yytestcase(yyruleno==181);
      case 182: /* expr ::= expr EQ|NE expr */ yytestcase(yyruleno==182);
      case 183: /* expr ::= expr BITAND|BITOR|LSHIFT|RSHIFT expr */ yytestcase(yyruleno==183);
      case 184: /* expr ::= expr PLUS|MINUS expr */ yytestcase(yyruleno==184);
      case 185: /* expr ::= expr STAR|SLASH|REM expr */ yytestcase(yyruleno==185);
      case 186: /* expr ::= expr CONCAT expr */ yytestcase(yyruleno==186);
{yymsp[-2].minor.yy490=sqlite3PExpr(pParse,yymsp[-1].major,yymsp[-2].minor.yy490,yymsp[0].minor.yy490);}
{yymsp[-2].minor.yy524=sqlite3PExpr(pParse,yymsp[-1].major,yymsp[-2].minor.yy524,yymsp[0].minor.yy524);}
        break;
      case 187: /* likeop ::= NOT LIKE_KW|MATCH */
{yymsp[-1].minor.yy0=yymsp[0].minor.yy0; yymsp[-1].minor.yy0.n|=0x80000000; /*yymsp[-1].minor.yy0-overwrite-yymsp[0].minor.yy0*/}
        break;
      case 188: /* expr ::= expr likeop expr */
{
  ExprList *pList;
  int bNot = yymsp[-1].minor.yy0.n & 0x80000000;
  yymsp[-1].minor.yy0.n &= 0x7fffffff;
  pList = sqlite3ExprListAppend(pParse,0, yymsp[0].minor.yy490);
  pList = sqlite3ExprListAppend(pParse,pList, yymsp[-2].minor.yy490);
  yymsp[-2].minor.yy490 = sqlite3ExprFunction(pParse, pList, &yymsp[-1].minor.yy0, 0);
  if( bNot ) yymsp[-2].minor.yy490 = sqlite3PExpr(pParse, TK_NOT, yymsp[-2].minor.yy490, 0);
  if( yymsp[-2].minor.yy490 ) yymsp[-2].minor.yy490->flags |= EP_InfixFunc;
  pList = sqlite3ExprListAppend(pParse,0, yymsp[0].minor.yy524);
  pList = sqlite3ExprListAppend(pParse,pList, yymsp[-2].minor.yy524);
  yymsp[-2].minor.yy524 = sqlite3ExprFunction(pParse, pList, &yymsp[-1].minor.yy0, 0);
  if( bNot ) yymsp[-2].minor.yy524 = sqlite3PExpr(pParse, TK_NOT, yymsp[-2].minor.yy524, 0);
  if( yymsp[-2].minor.yy524 ) yymsp[-2].minor.yy524->flags |= EP_InfixFunc;
}
        break;
      case 189: /* expr ::= expr likeop expr ESCAPE expr */
{
  ExprList *pList;
  int bNot = yymsp[-3].minor.yy0.n & 0x80000000;
  yymsp[-3].minor.yy0.n &= 0x7fffffff;
  pList = sqlite3ExprListAppend(pParse,0, yymsp[-2].minor.yy490);
  pList = sqlite3ExprListAppend(pParse,pList, yymsp[-4].minor.yy490);
  pList = sqlite3ExprListAppend(pParse,pList, yymsp[0].minor.yy490);
  yymsp[-4].minor.yy490 = sqlite3ExprFunction(pParse, pList, &yymsp[-3].minor.yy0, 0);
  if( bNot ) yymsp[-4].minor.yy490 = sqlite3PExpr(pParse, TK_NOT, yymsp[-4].minor.yy490, 0);
  if( yymsp[-4].minor.yy490 ) yymsp[-4].minor.yy490->flags |= EP_InfixFunc;
  pList = sqlite3ExprListAppend(pParse,0, yymsp[-2].minor.yy524);
  pList = sqlite3ExprListAppend(pParse,pList, yymsp[-4].minor.yy524);
  pList = sqlite3ExprListAppend(pParse,pList, yymsp[0].minor.yy524);
  yymsp[-4].minor.yy524 = sqlite3ExprFunction(pParse, pList, &yymsp[-3].minor.yy0, 0);
  if( bNot ) yymsp[-4].minor.yy524 = sqlite3PExpr(pParse, TK_NOT, yymsp[-4].minor.yy524, 0);
  if( yymsp[-4].minor.yy524 ) yymsp[-4].minor.yy524->flags |= EP_InfixFunc;
}
        break;
      case 190: /* expr ::= expr ISNULL|NOTNULL */
{yymsp[-1].minor.yy490 = sqlite3PExpr(pParse,yymsp[0].major,yymsp[-1].minor.yy490,0);}
{yymsp[-1].minor.yy524 = sqlite3PExpr(pParse,yymsp[0].major,yymsp[-1].minor.yy524,0);}
        break;
      case 191: /* expr ::= expr NOT NULL */
{yymsp[-2].minor.yy490 = sqlite3PExpr(pParse,TK_NOTNULL,yymsp[-2].minor.yy490,0);}
{yymsp[-2].minor.yy524 = sqlite3PExpr(pParse,TK_NOTNULL,yymsp[-2].minor.yy524,0);}
        break;
      case 192: /* expr ::= expr IS expr */
{
  yymsp[-2].minor.yy490 = sqlite3PExpr(pParse,TK_IS,yymsp[-2].minor.yy490,yymsp[0].minor.yy490);
  binaryToUnaryIfNull(pParse, yymsp[0].minor.yy490, yymsp[-2].minor.yy490, TK_ISNULL);
  yymsp[-2].minor.yy524 = sqlite3PExpr(pParse,TK_IS,yymsp[-2].minor.yy524,yymsp[0].minor.yy524);
  binaryToUnaryIfNull(pParse, yymsp[0].minor.yy524, yymsp[-2].minor.yy524, TK_ISNULL);
}
        break;
      case 193: /* expr ::= expr IS NOT expr */
{
  yymsp[-3].minor.yy490 = sqlite3PExpr(pParse,TK_ISNOT,yymsp[-3].minor.yy490,yymsp[0].minor.yy490);
  binaryToUnaryIfNull(pParse, yymsp[0].minor.yy490, yymsp[-3].minor.yy490, TK_NOTNULL);
  yymsp[-3].minor.yy524 = sqlite3PExpr(pParse,TK_ISNOT,yymsp[-3].minor.yy524,yymsp[0].minor.yy524);
  binaryToUnaryIfNull(pParse, yymsp[0].minor.yy524, yymsp[-3].minor.yy524, TK_NOTNULL);
}
        break;
      case 194: /* expr ::= NOT expr */
      case 195: /* expr ::= BITNOT expr */ yytestcase(yyruleno==195);
{yymsp[-1].minor.yy490 = sqlite3PExpr(pParse, yymsp[-1].major, yymsp[0].minor.yy490, 0);/*A-overwrites-B*/}
{yymsp[-1].minor.yy524 = sqlite3PExpr(pParse, yymsp[-1].major, yymsp[0].minor.yy524, 0);/*A-overwrites-B*/}
        break;
      case 196: /* expr ::= PLUS|MINUS expr */
{
  yymsp[-1].minor.yy490 = sqlite3PExpr(pParse, yymsp[-1].major==TK_PLUS ? TK_UPLUS : TK_UMINUS, yymsp[0].minor.yy490, 0);
  yymsp[-1].minor.yy524 = sqlite3PExpr(pParse, yymsp[-1].major==TK_PLUS ? TK_UPLUS : TK_UMINUS, yymsp[0].minor.yy524, 0);
  /*A-overwrites-B*/
}
        break;
      case 197: /* between_op ::= BETWEEN */
      case 200: /* in_op ::= IN */ yytestcase(yyruleno==200);
{yymsp[0].minor.yy96 = 0;}
{yymsp[0].minor.yy494 = 0;}
        break;
      case 199: /* expr ::= expr between_op expr AND expr */
{
  ExprList *pList = sqlite3ExprListAppend(pParse,0, yymsp[-2].minor.yy490);
  pList = sqlite3ExprListAppend(pParse,pList, yymsp[0].minor.yy490);
  yymsp[-4].minor.yy490 = sqlite3PExpr(pParse, TK_BETWEEN, yymsp[-4].minor.yy490, 0);
  if( yymsp[-4].minor.yy490 ){
    yymsp[-4].minor.yy490->x.pList = pList;
  ExprList *pList = sqlite3ExprListAppend(pParse,0, yymsp[-2].minor.yy524);
  pList = sqlite3ExprListAppend(pParse,pList, yymsp[0].minor.yy524);
  yymsp[-4].minor.yy524 = sqlite3PExpr(pParse, TK_BETWEEN, yymsp[-4].minor.yy524, 0);
  if( yymsp[-4].minor.yy524 ){
    yymsp[-4].minor.yy524->x.pList = pList;
  }else{
    sqlite3ExprListDelete(pParse->db, pList);
  } 
  if( yymsp[-3].minor.yy96 ) yymsp[-4].minor.yy490 = sqlite3PExpr(pParse, TK_NOT, yymsp[-4].minor.yy490, 0);
  if( yymsp[-3].minor.yy494 ) yymsp[-4].minor.yy524 = sqlite3PExpr(pParse, TK_NOT, yymsp[-4].minor.yy524, 0);
}
        break;
      case 202: /* expr ::= expr in_op LP exprlist RP */
{
    if( yymsp[-1].minor.yy42==0 ){
    if( yymsp[-1].minor.yy434==0 ){
      /* Expressions of the form
      **
      **      expr1 IN ()
      **      expr1 NOT IN ()
      **
      ** simplify to constants 0 (false) and 1 (true), respectively,
      ** regardless of the value of expr1.
      */
      if( IN_RENAME_OBJECT==0 ){
        sqlite3ExprDelete(pParse->db, yymsp[-4].minor.yy490);
        yymsp[-4].minor.yy490 = sqlite3ExprAlloc(pParse->db, TK_INTEGER,&sqlite3IntTokens[yymsp[-3].minor.yy96],1);
        sqlite3ExprDelete(pParse->db, yymsp[-4].minor.yy524);
        yymsp[-4].minor.yy524 = sqlite3ExprAlloc(pParse->db, TK_INTEGER,&sqlite3IntTokens[yymsp[-3].minor.yy494],1);
      }
    }else if( yymsp[-1].minor.yy42->nExpr==1 ){
    }else if( yymsp[-1].minor.yy434->nExpr==1 ){
      /* Expressions of the form:
      **
      **      expr1 IN (?1)
      **      expr1 NOT IN (?2)
      **
      ** with exactly one value on the RHS can be simplified to something
      ** like this:
      **
      **      expr1 == ?1
      **      expr1 <> ?2
      **
      ** But, the RHS of the == or <> is marked with the EP_Generic flag
      ** so that it may not contribute to the computation of comparison
      ** affinity or the collating sequence to use for comparison.  Otherwise,
      ** the semantics would be subtly different from IN or NOT IN.
      */
      Expr *pRHS = yymsp[-1].minor.yy42->a[0].pExpr;
      yymsp[-1].minor.yy42->a[0].pExpr = 0;
      sqlite3ExprListDelete(pParse->db, yymsp[-1].minor.yy42);
      Expr *pRHS = yymsp[-1].minor.yy434->a[0].pExpr;
      yymsp[-1].minor.yy434->a[0].pExpr = 0;
      sqlite3ExprListDelete(pParse->db, yymsp[-1].minor.yy434);
      /* pRHS cannot be NULL because a malloc error would have been detected
      ** before now and control would have never reached this point */
      if( ALWAYS(pRHS) ){
        pRHS->flags &= ~EP_Collate;
        pRHS->flags |= EP_Generic;
      }
      yymsp[-4].minor.yy490 = sqlite3PExpr(pParse, yymsp[-3].minor.yy96 ? TK_NE : TK_EQ, yymsp[-4].minor.yy490, pRHS);
      yymsp[-4].minor.yy524 = sqlite3PExpr(pParse, yymsp[-3].minor.yy494 ? TK_NE : TK_EQ, yymsp[-4].minor.yy524, pRHS);
    }else{
      yymsp[-4].minor.yy490 = sqlite3PExpr(pParse, TK_IN, yymsp[-4].minor.yy490, 0);
      if( yymsp[-4].minor.yy490 ){
        yymsp[-4].minor.yy490->x.pList = yymsp[-1].minor.yy42;
        sqlite3ExprSetHeightAndFlags(pParse, yymsp[-4].minor.yy490);
      yymsp[-4].minor.yy524 = sqlite3PExpr(pParse, TK_IN, yymsp[-4].minor.yy524, 0);
      if( yymsp[-4].minor.yy524 ){
        yymsp[-4].minor.yy524->x.pList = yymsp[-1].minor.yy434;
        sqlite3ExprSetHeightAndFlags(pParse, yymsp[-4].minor.yy524);
      }else{
        sqlite3ExprListDelete(pParse->db, yymsp[-1].minor.yy42);
        sqlite3ExprListDelete(pParse->db, yymsp[-1].minor.yy434);
      }
      if( yymsp[-3].minor.yy96 ) yymsp[-4].minor.yy490 = sqlite3PExpr(pParse, TK_NOT, yymsp[-4].minor.yy490, 0);
      if( yymsp[-3].minor.yy494 ) yymsp[-4].minor.yy524 = sqlite3PExpr(pParse, TK_NOT, yymsp[-4].minor.yy524, 0);
    }
  }
        break;
      case 203: /* expr ::= LP select RP */
{
    yymsp[-2].minor.yy490 = sqlite3PExpr(pParse, TK_SELECT, 0, 0);
    sqlite3PExprAddSelect(pParse, yymsp[-2].minor.yy490, yymsp[-1].minor.yy423);
    yymsp[-2].minor.yy524 = sqlite3PExpr(pParse, TK_SELECT, 0, 0);
    sqlite3PExprAddSelect(pParse, yymsp[-2].minor.yy524, yymsp[-1].minor.yy457);
  }
        break;
      case 204: /* expr ::= expr in_op LP select RP */
{
    yymsp[-4].minor.yy490 = sqlite3PExpr(pParse, TK_IN, yymsp[-4].minor.yy490, 0);
    sqlite3PExprAddSelect(pParse, yymsp[-4].minor.yy490, yymsp[-1].minor.yy423);
    if( yymsp[-3].minor.yy96 ) yymsp[-4].minor.yy490 = sqlite3PExpr(pParse, TK_NOT, yymsp[-4].minor.yy490, 0);
    yymsp[-4].minor.yy524 = sqlite3PExpr(pParse, TK_IN, yymsp[-4].minor.yy524, 0);
    sqlite3PExprAddSelect(pParse, yymsp[-4].minor.yy524, yymsp[-1].minor.yy457);
    if( yymsp[-3].minor.yy494 ) yymsp[-4].minor.yy524 = sqlite3PExpr(pParse, TK_NOT, yymsp[-4].minor.yy524, 0);
  }
        break;
      case 205: /* expr ::= expr in_op nm dbnm paren_exprlist */
{
    SrcList *pSrc = sqlite3SrcListAppend(pParse, 0,&yymsp[-2].minor.yy0,&yymsp[-1].minor.yy0);
    Select *pSelect = sqlite3SelectNew(pParse, 0,pSrc,0,0,0,0,0,0);
    if( yymsp[0].minor.yy42 )  sqlite3SrcListFuncArgs(pParse, pSelect ? pSrc : 0, yymsp[0].minor.yy42);
    yymsp[-4].minor.yy490 = sqlite3PExpr(pParse, TK_IN, yymsp[-4].minor.yy490, 0);
    sqlite3PExprAddSelect(pParse, yymsp[-4].minor.yy490, pSelect);
    if( yymsp[-3].minor.yy96 ) yymsp[-4].minor.yy490 = sqlite3PExpr(pParse, TK_NOT, yymsp[-4].minor.yy490, 0);
    if( yymsp[0].minor.yy434 )  sqlite3SrcListFuncArgs(pParse, pSelect ? pSrc : 0, yymsp[0].minor.yy434);
    yymsp[-4].minor.yy524 = sqlite3PExpr(pParse, TK_IN, yymsp[-4].minor.yy524, 0);
    sqlite3PExprAddSelect(pParse, yymsp[-4].minor.yy524, pSelect);
    if( yymsp[-3].minor.yy494 ) yymsp[-4].minor.yy524 = sqlite3PExpr(pParse, TK_NOT, yymsp[-4].minor.yy524, 0);
  }
        break;
      case 206: /* expr ::= EXISTS LP select RP */
{
    Expr *p;
    p = yymsp[-3].minor.yy490 = sqlite3PExpr(pParse, TK_EXISTS, 0, 0);
    sqlite3PExprAddSelect(pParse, p, yymsp[-1].minor.yy423);
    p = yymsp[-3].minor.yy524 = sqlite3PExpr(pParse, TK_EXISTS, 0, 0);
    sqlite3PExprAddSelect(pParse, p, yymsp[-1].minor.yy457);
  }
        break;
      case 207: /* expr ::= CASE case_operand case_exprlist case_else END */
{
  yymsp[-4].minor.yy490 = sqlite3PExpr(pParse, TK_CASE, yymsp[-3].minor.yy490, 0);
  if( yymsp[-4].minor.yy490 ){
    yymsp[-4].minor.yy490->x.pList = yymsp[-1].minor.yy490 ? sqlite3ExprListAppend(pParse,yymsp[-2].minor.yy42,yymsp[-1].minor.yy490) : yymsp[-2].minor.yy42;
    sqlite3ExprSetHeightAndFlags(pParse, yymsp[-4].minor.yy490);
  yymsp[-4].minor.yy524 = sqlite3PExpr(pParse, TK_CASE, yymsp[-3].minor.yy524, 0);
  if( yymsp[-4].minor.yy524 ){
    yymsp[-4].minor.yy524->x.pList = yymsp[-1].minor.yy524 ? sqlite3ExprListAppend(pParse,yymsp[-2].minor.yy434,yymsp[-1].minor.yy524) : yymsp[-2].minor.yy434;
    sqlite3ExprSetHeightAndFlags(pParse, yymsp[-4].minor.yy524);
  }else{
    sqlite3ExprListDelete(pParse->db, yymsp[-2].minor.yy42);
    sqlite3ExprDelete(pParse->db, yymsp[-1].minor.yy490);
    sqlite3ExprListDelete(pParse->db, yymsp[-2].minor.yy434);
    sqlite3ExprDelete(pParse->db, yymsp[-1].minor.yy524);
  }
}
        break;
      case 208: /* case_exprlist ::= case_exprlist WHEN expr THEN expr */
{
  yymsp[-4].minor.yy42 = sqlite3ExprListAppend(pParse,yymsp[-4].minor.yy42, yymsp[-2].minor.yy490);
  yymsp[-4].minor.yy42 = sqlite3ExprListAppend(pParse,yymsp[-4].minor.yy42, yymsp[0].minor.yy490);
  yymsp[-4].minor.yy434 = sqlite3ExprListAppend(pParse,yymsp[-4].minor.yy434, yymsp[-2].minor.yy524);
  yymsp[-4].minor.yy434 = sqlite3ExprListAppend(pParse,yymsp[-4].minor.yy434, yymsp[0].minor.yy524);
}
        break;
      case 209: /* case_exprlist ::= WHEN expr THEN expr */
{
  yymsp[-3].minor.yy42 = sqlite3ExprListAppend(pParse,0, yymsp[-2].minor.yy490);
  yymsp[-3].minor.yy42 = sqlite3ExprListAppend(pParse,yymsp[-3].minor.yy42, yymsp[0].minor.yy490);
  yymsp[-3].minor.yy434 = sqlite3ExprListAppend(pParse,0, yymsp[-2].minor.yy524);
  yymsp[-3].minor.yy434 = sqlite3ExprListAppend(pParse,yymsp[-3].minor.yy434, yymsp[0].minor.yy524);
}
        break;
      case 212: /* case_operand ::= expr */
{yymsp[0].minor.yy490 = yymsp[0].minor.yy490; /*A-overwrites-X*/}
{yymsp[0].minor.yy524 = yymsp[0].minor.yy524; /*A-overwrites-X*/}
        break;
      case 215: /* nexprlist ::= nexprlist COMMA expr */
{yymsp[-2].minor.yy42 = sqlite3ExprListAppend(pParse,yymsp[-2].minor.yy42,yymsp[0].minor.yy490);}
{yymsp[-2].minor.yy434 = sqlite3ExprListAppend(pParse,yymsp[-2].minor.yy434,yymsp[0].minor.yy524);}
        break;
      case 216: /* nexprlist ::= expr */
{yymsp[0].minor.yy42 = sqlite3ExprListAppend(pParse,0,yymsp[0].minor.yy490); /*A-overwrites-Y*/}
{yymsp[0].minor.yy434 = sqlite3ExprListAppend(pParse,0,yymsp[0].minor.yy524); /*A-overwrites-Y*/}
        break;
      case 218: /* paren_exprlist ::= LP exprlist RP */
      case 223: /* eidlist_opt ::= LP eidlist RP */ yytestcase(yyruleno==223);
{yymsp[-2].minor.yy42 = yymsp[-1].minor.yy42;}
{yymsp[-2].minor.yy434 = yymsp[-1].minor.yy434;}
        break;
      case 219: /* cmd ::= createkw uniqueflag INDEX ifnotexists nm dbnm ON nm LP sortlist RP where_opt */
{
  sqlite3CreateIndex(pParse, &yymsp[-7].minor.yy0, &yymsp[-6].minor.yy0, 
                     sqlite3SrcListAppend(pParse,0,&yymsp[-4].minor.yy0,0), yymsp[-2].minor.yy42, yymsp[-10].minor.yy96,
                      &yymsp[-11].minor.yy0, yymsp[0].minor.yy490, SQLITE_SO_ASC, yymsp[-8].minor.yy96, SQLITE_IDXTYPE_APPDEF);
                     sqlite3SrcListAppend(pParse,0,&yymsp[-4].minor.yy0,0), yymsp[-2].minor.yy434, yymsp[-10].minor.yy494,
                      &yymsp[-11].minor.yy0, yymsp[0].minor.yy524, SQLITE_SO_ASC, yymsp[-8].minor.yy494, SQLITE_IDXTYPE_APPDEF);
  if( IN_RENAME_OBJECT && pParse->pNewIndex ){
    sqlite3RenameTokenMap(pParse, pParse->pNewIndex->zName, &yymsp[-4].minor.yy0);
  }
}
        break;
      case 220: /* uniqueflag ::= UNIQUE */
      case 262: /* raisetype ::= ABORT */ yytestcase(yyruleno==262);
{yymsp[0].minor.yy96 = OE_Abort;}
{yymsp[0].minor.yy494 = OE_Abort;}
        break;
      case 221: /* uniqueflag ::= */
{yymsp[1].minor.yy96 = OE_None;}
{yymsp[1].minor.yy494 = OE_None;}
        break;
      case 224: /* eidlist ::= eidlist COMMA nm collate sortorder */
{
  yymsp[-4].minor.yy42 = parserAddExprIdListTerm(pParse, yymsp[-4].minor.yy42, &yymsp[-2].minor.yy0, yymsp[-1].minor.yy96, yymsp[0].minor.yy96);
  yymsp[-4].minor.yy434 = parserAddExprIdListTerm(pParse, yymsp[-4].minor.yy434, &yymsp[-2].minor.yy0, yymsp[-1].minor.yy494, yymsp[0].minor.yy494);
}
        break;
      case 225: /* eidlist ::= nm collate sortorder */
{
  yymsp[-2].minor.yy42 = parserAddExprIdListTerm(pParse, 0, &yymsp[-2].minor.yy0, yymsp[-1].minor.yy96, yymsp[0].minor.yy96); /*A-overwrites-Y*/
  yymsp[-2].minor.yy434 = parserAddExprIdListTerm(pParse, 0, &yymsp[-2].minor.yy0, yymsp[-1].minor.yy494, yymsp[0].minor.yy494); /*A-overwrites-Y*/
}
        break;
      case 228: /* cmd ::= DROP INDEX ifexists fullname */
{sqlite3DropIndex(pParse, yymsp[0].minor.yy167, yymsp[-1].minor.yy96);}
{sqlite3DropIndex(pParse, yymsp[0].minor.yy483, yymsp[-1].minor.yy494);}
        break;
      case 229: /* cmd ::= VACUUM vinto */
{sqlite3Vacuum(pParse,0,yymsp[0].minor.yy490);}
{sqlite3Vacuum(pParse,0,yymsp[0].minor.yy524);}
        break;
      case 230: /* cmd ::= VACUUM nm vinto */
{sqlite3Vacuum(pParse,&yymsp[-1].minor.yy0,yymsp[0].minor.yy490);}
{sqlite3Vacuum(pParse,&yymsp[-1].minor.yy0,yymsp[0].minor.yy524);}
        break;
      case 233: /* cmd ::= PRAGMA nm dbnm */
{sqlite3Pragma(pParse,&yymsp[-1].minor.yy0,&yymsp[0].minor.yy0,0,0);}
        break;
      case 234: /* cmd ::= PRAGMA nm dbnm EQ nmnum */
{sqlite3Pragma(pParse,&yymsp[-3].minor.yy0,&yymsp[-2].minor.yy0,&yymsp[0].minor.yy0,0);}
        break;
151453
151454
151455
151456
151457
151458
151459
151460

151461
151462
151463
151464
151465

151466
151467
151468
151469
151470

151471
151472
151473

151474
151475
151476

151477
151478
151479
151480

151481
151482
151483

151484
151485
151486
151487
151488


151489
151490
151491
151492

151493
151494
151495
151496
151497
151498



151499
151500
151501
151502
151503
151504


151505
151506
151507
151508
151509
151510
151511
152316
152317
152318
152319
152320
152321
152322

152323
152324
152325
152326
152327

152328
152329
152330
152331
152332

152333
152334
152335

152336
152337
152338

152339
152340
152341
152342

152343
152344
152345

152346
152347
152348
152349


152350
152351
152352
152353
152354

152355
152356
152357
152358



152359
152360
152361
152362
152363
152364
152365


152366
152367
152368
152369
152370
152371
152372
152373
152374







-
+




-
+




-
+


-
+


-
+



-
+


-
+



-
-
+
+



-
+



-
-
-
+
+
+




-
-
+
+







{sqlite3Pragma(pParse,&yymsp[-4].minor.yy0,&yymsp[-3].minor.yy0,&yymsp[-1].minor.yy0,1);}
        break;
      case 240: /* cmd ::= createkw trigger_decl BEGIN trigger_cmd_list END */
{
  Token all;
  all.z = yymsp[-3].minor.yy0.z;
  all.n = (int)(yymsp[0].minor.yy0.z - yymsp[-3].minor.yy0.z) + yymsp[0].minor.yy0.n;
  sqlite3FinishTrigger(pParse, yymsp[-1].minor.yy119, &all);
  sqlite3FinishTrigger(pParse, yymsp[-1].minor.yy455, &all);
}
        break;
      case 241: /* trigger_decl ::= temp TRIGGER ifnotexists nm dbnm trigger_time trigger_event ON fullname foreach_clause when_clause */
{
  sqlite3BeginTrigger(pParse, &yymsp[-7].minor.yy0, &yymsp[-6].minor.yy0, yymsp[-5].minor.yy96, yymsp[-4].minor.yy350.a, yymsp[-4].minor.yy350.b, yymsp[-2].minor.yy167, yymsp[0].minor.yy490, yymsp[-10].minor.yy96, yymsp[-8].minor.yy96);
  sqlite3BeginTrigger(pParse, &yymsp[-7].minor.yy0, &yymsp[-6].minor.yy0, yymsp[-5].minor.yy494, yymsp[-4].minor.yy90.a, yymsp[-4].minor.yy90.b, yymsp[-2].minor.yy483, yymsp[0].minor.yy524, yymsp[-10].minor.yy494, yymsp[-8].minor.yy494);
  yymsp[-10].minor.yy0 = (yymsp[-6].minor.yy0.n==0?yymsp[-7].minor.yy0:yymsp[-6].minor.yy0); /*A-overwrites-T*/
}
        break;
      case 242: /* trigger_time ::= BEFORE|AFTER */
{ yymsp[0].minor.yy96 = yymsp[0].major; /*A-overwrites-X*/ }
{ yymsp[0].minor.yy494 = yymsp[0].major; /*A-overwrites-X*/ }
        break;
      case 243: /* trigger_time ::= INSTEAD OF */
{ yymsp[-1].minor.yy96 = TK_INSTEAD;}
{ yymsp[-1].minor.yy494 = TK_INSTEAD;}
        break;
      case 244: /* trigger_time ::= */
{ yymsp[1].minor.yy96 = TK_BEFORE; }
{ yymsp[1].minor.yy494 = TK_BEFORE; }
        break;
      case 245: /* trigger_event ::= DELETE|INSERT */
      case 246: /* trigger_event ::= UPDATE */ yytestcase(yyruleno==246);
{yymsp[0].minor.yy350.a = yymsp[0].major; /*A-overwrites-X*/ yymsp[0].minor.yy350.b = 0;}
{yymsp[0].minor.yy90.a = yymsp[0].major; /*A-overwrites-X*/ yymsp[0].minor.yy90.b = 0;}
        break;
      case 247: /* trigger_event ::= UPDATE OF idlist */
{yymsp[-2].minor.yy350.a = TK_UPDATE; yymsp[-2].minor.yy350.b = yymsp[0].minor.yy336;}
{yymsp[-2].minor.yy90.a = TK_UPDATE; yymsp[-2].minor.yy90.b = yymsp[0].minor.yy62;}
        break;
      case 248: /* when_clause ::= */
      case 267: /* key_opt ::= */ yytestcase(yyruleno==267);
      case 309: /* filter_opt ::= */ yytestcase(yyruleno==309);
{ yymsp[1].minor.yy490 = 0; }
      case 315: /* filter_opt ::= */ yytestcase(yyruleno==315);
{ yymsp[1].minor.yy524 = 0; }
        break;
      case 249: /* when_clause ::= WHEN expr */
      case 268: /* key_opt ::= KEY expr */ yytestcase(yyruleno==268);
{ yymsp[-1].minor.yy490 = yymsp[0].minor.yy490; }
{ yymsp[-1].minor.yy524 = yymsp[0].minor.yy524; }
        break;
      case 250: /* trigger_cmd_list ::= trigger_cmd_list trigger_cmd SEMI */
{
  assert( yymsp[-2].minor.yy119!=0 );
  yymsp[-2].minor.yy119->pLast->pNext = yymsp[-1].minor.yy119;
  yymsp[-2].minor.yy119->pLast = yymsp[-1].minor.yy119;
  assert( yymsp[-2].minor.yy455!=0 );
  yymsp[-2].minor.yy455->pLast->pNext = yymsp[-1].minor.yy455;
  yymsp[-2].minor.yy455->pLast = yymsp[-1].minor.yy455;
}
        break;
      case 251: /* trigger_cmd_list ::= trigger_cmd SEMI */
{ 
  assert( yymsp[-1].minor.yy119!=0 );
  yymsp[-1].minor.yy119->pLast = yymsp[-1].minor.yy119;
  assert( yymsp[-1].minor.yy455!=0 );
  yymsp[-1].minor.yy455->pLast = yymsp[-1].minor.yy455;
}
        break;
      case 252: /* trnm ::= nm DOT nm */
{
  yymsp[-2].minor.yy0 = yymsp[0].minor.yy0;
  sqlite3ErrorMsg(pParse, 
        "qualified table names are not allowed on INSERT, UPDATE, and DELETE "
151523
151524
151525
151526
151527
151528
151529
151530
151531


151532
151533
151534
151535

151536
151537

151538
151539
151540
151541


151542
151543
151544
151545


151546
151547
151548
151549
151550
151551



151552
151553
151554
151555
151556
151557
151558
151559



151560
151561
151562
151563
151564

151565
151566
151567

151568
151569
151570
151571

151572
151573
151574
151575
151576

151577
151578
151579
151580
151581

151582
151583
151584
151585
151586
151587
151588
151589
151590
151591
151592
151593
151594
151595
151596
151597
151598

151599
151600
151601
151602
151603
151604
151605
151606
151607
151608
151609
151610

151611
151612
151613
151614
151615

151616
151617
151618
151619
151620
151621
151622
151623
151624
151625
151626

151627
151628
151629
151630
151631
151632
151633
151634
151635
151636
151637
151638
151639

151640
151641
151642
151643

151644
151645
151646
151647
151648

151649
151650
151651
151652
151653


151654
151655
151656
151657
151658
151659




151660
151661

151662
151663

151664
151665
151666


151667
151668

151669
151670

151671
151672

151673
151674
151675

151676
151677
151678











151679
151680
151681
151682





151683
151684
151685





151686
151687
151688
151689



151690

151691
151692

151693
151694

151695
151696
151697
151698

151699
151700

151701
151702

151703
151704
151705
151706
151707
151708





151709
151710
151711
151712
151713




151714
151715
151716
151717





151718
151719
151720
151721



151722
151723
151724


151725
151726
151727
151728






151729



151730
151731


151732
151733

151734
151735
151736
151737



151738
151739

151740
151741

151742
151743
151744
151745
151746




151747
151748

151749
151750
151751

151752
151753
151754


151755
151756
151757
151758
151759
151760
151761
151762
151763
151764
151765
151766
151767
151768
151769
151770
151771
151772
151773
151774
151775
151776
151777
151778
151779
151780
151781
151782
151783
151784
151785
151786
151787
151788
151789
151790
151791
151792
151793
151794
151795
151796
151797
151798
151799
151800
151801
151802
151803
151804
151805
151806
151807
151808
151809
151810
151811
151812
151813
151814


























































151815
151816
151817
151818
151819
151820
151821
152386
152387
152388
152389
152390
152391
152392


152393
152394
152395
152396
152397

152398
152399

152400
152401
152402


152403
152404
152405
152406


152407
152408
152409
152410
152411



152412
152413
152414
152415
152416
152417
152418
152419



152420
152421
152422
152423
152424
152425
152426

152427
152428
152429

152430
152431
152432
152433

152434
152435
152436
152437
152438

152439
152440
152441
152442
152443

152444
152445
152446
152447
152448
152449
152450
152451
152452
152453
152454
152455
152456
152457
152458
152459
152460

152461
152462
152463
152464
152465
152466
152467
152468
152469
152470
152471
152472

152473
152474
152475
152476
152477

152478
152479
152480
152481
152482
152483
152484
152485
152486
152487
152488

152489
152490
152491
152492
152493
152494
152495
152496
152497
152498
152499
152500
152501

152502
152503
152504
152505

152506
152507
152508
152509
152510

152511
152512
152513
152514


152515
152516
152517
152518
152519



152520
152521
152522
152523
152524

152525
152526

152527
152528


152529
152530
152531

152532
152533

152534
152535

152536
152537


152538



152539
152540
152541
152542
152543
152544
152545
152546
152547
152548
152549
152550
152551


152552
152553
152554
152555
152556
152557


152558
152559
152560
152561
152562
152563



152564
152565
152566
152567
152568
152569

152570
152571

152572
152573

152574

152575
152576

152577
152578

152579



152580


152581
152582
152583
152584
152585
152586




152587
152588
152589
152590
152591



152592
152593
152594
152595
152596
152597



152598
152599
152600
152601


152602
152603
152604



152605
152606
152607
152608
152609
152610
152611
152612
152613
152614


152615
152616
152617

152618
152619



152620
152621
152622
152623

152624
152625

152626
152627




152628
152629
152630
152631
152632

152633
152634
152635

152636
152637


152638
152639
152640
152641


























































152642
152643
152644
152645
152646
152647
152648
152649
152650
152651
152652
152653
152654
152655
152656
152657
152658
152659
152660
152661
152662
152663
152664
152665
152666
152667
152668
152669
152670
152671
152672
152673
152674
152675
152676
152677
152678
152679
152680
152681
152682
152683
152684
152685
152686
152687
152688
152689
152690
152691
152692
152693
152694
152695
152696
152697
152698
152699
152700
152701
152702
152703
152704
152705
152706







-
-
+
+



-
+

-
+


-
-
+
+


-
-
+
+



-
-
-
+
+
+





-
-
-
+
+
+




-
+


-
+



-
+




-
+




-
+
















-
+











-
+




-
+










-
+












-
+



-
+




-
+



-
-
+
+



-
-
-
+
+
+
+

-
+

-
+

-
-
+
+

-
+

-
+

-
+

-
-
+
-
-
-
+
+
+
+
+
+
+
+
+
+
+


-
-
+
+
+
+
+

-
-
+
+
+
+
+

-
-
-
+
+
+

+

-
+

-
+

-

-
+

-
+

-
+
-
-
-

-
-
+
+
+
+
+

-
-
-
-
+
+
+
+

-
-
-
+
+
+
+
+

-
-
-
+
+
+

-
-
+
+

-
-
-
+
+
+
+
+
+

+
+
+
-
-
+
+

-
+

-
-
-
+
+
+

-
+

-
+

-
-
-
-
+
+
+
+

-
+


-
+

-
-
+
+


-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+







{
  sqlite3ErrorMsg(pParse,
        "the NOT INDEXED clause is not allowed on UPDATE or DELETE statements "
        "within triggers");
}
        break;
      case 255: /* trigger_cmd ::= UPDATE orconf trnm tridxby SET setlist where_opt scanpt */
{yylhsminor.yy119 = sqlite3TriggerUpdateStep(pParse, &yymsp[-5].minor.yy0, yymsp[-2].minor.yy42, yymsp[-1].minor.yy490, yymsp[-6].minor.yy96, yymsp[-7].minor.yy0.z, yymsp[0].minor.yy464);}
  yymsp[-7].minor.yy119 = yylhsminor.yy119;
{yylhsminor.yy455 = sqlite3TriggerUpdateStep(pParse, &yymsp[-5].minor.yy0, yymsp[-2].minor.yy434, yymsp[-1].minor.yy524, yymsp[-6].minor.yy494, yymsp[-7].minor.yy0.z, yymsp[0].minor.yy294);}
  yymsp[-7].minor.yy455 = yylhsminor.yy455;
        break;
      case 256: /* trigger_cmd ::= scanpt insert_cmd INTO trnm idlist_opt select upsert scanpt */
{
   yylhsminor.yy119 = sqlite3TriggerInsertStep(pParse,&yymsp[-4].minor.yy0,yymsp[-3].minor.yy336,yymsp[-2].minor.yy423,yymsp[-6].minor.yy96,yymsp[-1].minor.yy266,yymsp[-7].minor.yy464,yymsp[0].minor.yy464);/*yylhsminor.yy119-overwrites-yymsp[-6].minor.yy96*/
   yylhsminor.yy455 = sqlite3TriggerInsertStep(pParse,&yymsp[-4].minor.yy0,yymsp[-3].minor.yy62,yymsp[-2].minor.yy457,yymsp[-6].minor.yy494,yymsp[-1].minor.yy136,yymsp[-7].minor.yy294,yymsp[0].minor.yy294);/*yylhsminor.yy455-overwrites-yymsp[-6].minor.yy494*/
}
  yymsp[-7].minor.yy119 = yylhsminor.yy119;
  yymsp[-7].minor.yy455 = yylhsminor.yy455;
        break;
      case 257: /* trigger_cmd ::= DELETE FROM trnm tridxby where_opt scanpt */
{yylhsminor.yy119 = sqlite3TriggerDeleteStep(pParse, &yymsp[-3].minor.yy0, yymsp[-1].minor.yy490, yymsp[-5].minor.yy0.z, yymsp[0].minor.yy464);}
  yymsp[-5].minor.yy119 = yylhsminor.yy119;
{yylhsminor.yy455 = sqlite3TriggerDeleteStep(pParse, &yymsp[-3].minor.yy0, yymsp[-1].minor.yy524, yymsp[-5].minor.yy0.z, yymsp[0].minor.yy294);}
  yymsp[-5].minor.yy455 = yylhsminor.yy455;
        break;
      case 258: /* trigger_cmd ::= scanpt select scanpt */
{yylhsminor.yy119 = sqlite3TriggerSelectStep(pParse->db, yymsp[-1].minor.yy423, yymsp[-2].minor.yy464, yymsp[0].minor.yy464); /*yylhsminor.yy119-overwrites-yymsp[-1].minor.yy423*/}
  yymsp[-2].minor.yy119 = yylhsminor.yy119;
{yylhsminor.yy455 = sqlite3TriggerSelectStep(pParse->db, yymsp[-1].minor.yy457, yymsp[-2].minor.yy294, yymsp[0].minor.yy294); /*yylhsminor.yy455-overwrites-yymsp[-1].minor.yy457*/}
  yymsp[-2].minor.yy455 = yylhsminor.yy455;
        break;
      case 259: /* expr ::= RAISE LP IGNORE RP */
{
  yymsp[-3].minor.yy490 = sqlite3PExpr(pParse, TK_RAISE, 0, 0); 
  if( yymsp[-3].minor.yy490 ){
    yymsp[-3].minor.yy490->affinity = OE_Ignore;
  yymsp[-3].minor.yy524 = sqlite3PExpr(pParse, TK_RAISE, 0, 0); 
  if( yymsp[-3].minor.yy524 ){
    yymsp[-3].minor.yy524->affinity = OE_Ignore;
  }
}
        break;
      case 260: /* expr ::= RAISE LP raisetype COMMA nm RP */
{
  yymsp[-5].minor.yy490 = sqlite3ExprAlloc(pParse->db, TK_RAISE, &yymsp[-1].minor.yy0, 1); 
  if( yymsp[-5].minor.yy490 ) {
    yymsp[-5].minor.yy490->affinity = (char)yymsp[-3].minor.yy96;
  yymsp[-5].minor.yy524 = sqlite3ExprAlloc(pParse->db, TK_RAISE, &yymsp[-1].minor.yy0, 1); 
  if( yymsp[-5].minor.yy524 ) {
    yymsp[-5].minor.yy524->affinity = (char)yymsp[-3].minor.yy494;
  }
}
        break;
      case 261: /* raisetype ::= ROLLBACK */
{yymsp[0].minor.yy96 = OE_Rollback;}
{yymsp[0].minor.yy494 = OE_Rollback;}
        break;
      case 263: /* raisetype ::= FAIL */
{yymsp[0].minor.yy96 = OE_Fail;}
{yymsp[0].minor.yy494 = OE_Fail;}
        break;
      case 264: /* cmd ::= DROP TRIGGER ifexists fullname */
{
  sqlite3DropTrigger(pParse,yymsp[0].minor.yy167,yymsp[-1].minor.yy96);
  sqlite3DropTrigger(pParse,yymsp[0].minor.yy483,yymsp[-1].minor.yy494);
}
        break;
      case 265: /* cmd ::= ATTACH database_kw_opt expr AS expr key_opt */
{
  sqlite3Attach(pParse, yymsp[-3].minor.yy490, yymsp[-1].minor.yy490, yymsp[0].minor.yy490);
  sqlite3Attach(pParse, yymsp[-3].minor.yy524, yymsp[-1].minor.yy524, yymsp[0].minor.yy524);
}
        break;
      case 266: /* cmd ::= DETACH database_kw_opt expr */
{
  sqlite3Detach(pParse, yymsp[0].minor.yy490);
  sqlite3Detach(pParse, yymsp[0].minor.yy524);
}
        break;
      case 269: /* cmd ::= REINDEX */
{sqlite3Reindex(pParse, 0, 0);}
        break;
      case 270: /* cmd ::= REINDEX nm dbnm */
{sqlite3Reindex(pParse, &yymsp[-1].minor.yy0, &yymsp[0].minor.yy0);}
        break;
      case 271: /* cmd ::= ANALYZE */
{sqlite3Analyze(pParse, 0, 0);}
        break;
      case 272: /* cmd ::= ANALYZE nm dbnm */
{sqlite3Analyze(pParse, &yymsp[-1].minor.yy0, &yymsp[0].minor.yy0);}
        break;
      case 273: /* cmd ::= ALTER TABLE fullname RENAME TO nm */
{
  sqlite3AlterRenameTable(pParse,yymsp[-3].minor.yy167,&yymsp[0].minor.yy0);
  sqlite3AlterRenameTable(pParse,yymsp[-3].minor.yy483,&yymsp[0].minor.yy0);
}
        break;
      case 274: /* cmd ::= ALTER TABLE add_column_fullname ADD kwcolumn_opt columnname carglist */
{
  yymsp[-1].minor.yy0.n = (int)(pParse->sLastToken.z-yymsp[-1].minor.yy0.z) + pParse->sLastToken.n;
  sqlite3AlterFinishAddColumn(pParse, &yymsp[-1].minor.yy0);
}
        break;
      case 275: /* add_column_fullname ::= fullname */
{
  disableLookaside(pParse);
  sqlite3AlterBeginAddColumn(pParse, yymsp[0].minor.yy167);
  sqlite3AlterBeginAddColumn(pParse, yymsp[0].minor.yy483);
}
        break;
      case 276: /* cmd ::= ALTER TABLE fullname RENAME kwcolumn_opt nm TO nm */
{
  sqlite3AlterRenameColumn(pParse, yymsp[-5].minor.yy167, &yymsp[-2].minor.yy0, &yymsp[0].minor.yy0);
  sqlite3AlterRenameColumn(pParse, yymsp[-5].minor.yy483, &yymsp[-2].minor.yy0, &yymsp[0].minor.yy0);
}
        break;
      case 277: /* cmd ::= create_vtab */
{sqlite3VtabFinishParse(pParse,0);}
        break;
      case 278: /* cmd ::= create_vtab LP vtabarglist RP */
{sqlite3VtabFinishParse(pParse,&yymsp[0].minor.yy0);}
        break;
      case 279: /* create_vtab ::= createkw VIRTUAL TABLE ifnotexists nm dbnm USING nm */
{
    sqlite3VtabBeginParse(pParse, &yymsp[-3].minor.yy0, &yymsp[-2].minor.yy0, &yymsp[0].minor.yy0, yymsp[-4].minor.yy96);
    sqlite3VtabBeginParse(pParse, &yymsp[-3].minor.yy0, &yymsp[-2].minor.yy0, &yymsp[0].minor.yy0, yymsp[-4].minor.yy494);
}
        break;
      case 280: /* vtabarg ::= */
{sqlite3VtabArgInit(pParse);}
        break;
      case 281: /* vtabargtoken ::= ANY */
      case 282: /* vtabargtoken ::= lp anylist RP */ yytestcase(yyruleno==282);
      case 283: /* lp ::= LP */ yytestcase(yyruleno==283);
{sqlite3VtabArgExtend(pParse,&yymsp[0].minor.yy0);}
        break;
      case 284: /* with ::= WITH wqlist */
      case 285: /* with ::= WITH RECURSIVE wqlist */ yytestcase(yyruleno==285);
{ sqlite3WithPush(pParse, yymsp[0].minor.yy499, 1); }
{ sqlite3WithPush(pParse, yymsp[0].minor.yy59, 1); }
        break;
      case 286: /* wqlist ::= nm eidlist_opt AS LP select RP */
{
  yymsp[-5].minor.yy499 = sqlite3WithAdd(pParse, 0, &yymsp[-5].minor.yy0, yymsp[-4].minor.yy42, yymsp[-1].minor.yy423); /*A-overwrites-X*/
  yymsp[-5].minor.yy59 = sqlite3WithAdd(pParse, 0, &yymsp[-5].minor.yy0, yymsp[-4].minor.yy434, yymsp[-1].minor.yy457); /*A-overwrites-X*/
}
        break;
      case 287: /* wqlist ::= wqlist COMMA nm eidlist_opt AS LP select RP */
{
  yymsp[-7].minor.yy499 = sqlite3WithAdd(pParse, yymsp[-7].minor.yy499, &yymsp[-5].minor.yy0, yymsp[-4].minor.yy42, yymsp[-1].minor.yy423);
  yymsp[-7].minor.yy59 = sqlite3WithAdd(pParse, yymsp[-7].minor.yy59, &yymsp[-5].minor.yy0, yymsp[-4].minor.yy434, yymsp[-1].minor.yy457);
}
        break;
      case 288: /* windowdefn_list ::= windowdefn */
{ yylhsminor.yy147 = yymsp[0].minor.yy147; }
  yymsp[0].minor.yy147 = yylhsminor.yy147;
{ yylhsminor.yy295 = yymsp[0].minor.yy295; }
  yymsp[0].minor.yy295 = yylhsminor.yy295;
        break;
      case 289: /* windowdefn_list ::= windowdefn_list COMMA windowdefn */
{
  assert( yymsp[0].minor.yy147!=0 );
  yymsp[0].minor.yy147->pNextWin = yymsp[-2].minor.yy147;
  yylhsminor.yy147 = yymsp[0].minor.yy147;
  assert( yymsp[0].minor.yy295!=0 );
  sqlite3WindowChain(pParse, yymsp[0].minor.yy295, yymsp[-2].minor.yy295);
  yymsp[0].minor.yy295->pNextWin = yymsp[-2].minor.yy295;
  yylhsminor.yy295 = yymsp[0].minor.yy295;
}
  yymsp[-2].minor.yy147 = yylhsminor.yy147;
  yymsp[-2].minor.yy295 = yylhsminor.yy295;
        break;
      case 290: /* windowdefn ::= nm AS window */
      case 290: /* windowdefn ::= nm AS LP window RP */
{
  if( ALWAYS(yymsp[0].minor.yy147) ){
    yymsp[0].minor.yy147->zName = sqlite3DbStrNDup(pParse->db, yymsp[-2].minor.yy0.z, yymsp[-2].minor.yy0.n);
  if( ALWAYS(yymsp[-1].minor.yy295) ){
    yymsp[-1].minor.yy295->zName = sqlite3DbStrNDup(pParse->db, yymsp[-4].minor.yy0.z, yymsp[-4].minor.yy0.n);
  }
  yylhsminor.yy147 = yymsp[0].minor.yy147;
  yylhsminor.yy295 = yymsp[-1].minor.yy295;
}
  yymsp[-2].minor.yy147 = yylhsminor.yy147;
  yymsp[-4].minor.yy295 = yylhsminor.yy295;
        break;
      case 291: /* window ::= LP part_opt orderby_opt frame_opt RP */
      case 291: /* window ::= PARTITION BY nexprlist orderby_opt frame_opt */
{
  yymsp[-4].minor.yy147 = yymsp[-1].minor.yy147;
  if( ALWAYS(yymsp[-4].minor.yy147) ){
  yymsp[-4].minor.yy295 = sqlite3WindowAssemble(pParse, yymsp[0].minor.yy295, yymsp[-2].minor.yy434, yymsp[-1].minor.yy434, 0);
    yymsp[-4].minor.yy147->pPartition = yymsp[-3].minor.yy42;
    yymsp[-4].minor.yy147->pOrderBy = yymsp[-2].minor.yy42;
  }
}
        break;
      case 292: /* window ::= nm PARTITION BY nexprlist orderby_opt frame_opt */
{
  yylhsminor.yy295 = sqlite3WindowAssemble(pParse, yymsp[0].minor.yy295, yymsp[-2].minor.yy434, yymsp[-1].minor.yy434, &yymsp[-5].minor.yy0);
}
  yymsp[-5].minor.yy295 = yylhsminor.yy295;
        break;
      case 293: /* window ::= ORDER BY sortlist frame_opt */
{
  yymsp[-3].minor.yy295 = sqlite3WindowAssemble(pParse, yymsp[0].minor.yy295, 0, yymsp[-1].minor.yy434, 0);
}
        break;
      case 292: /* part_opt ::= PARTITION BY nexprlist */
{ yymsp[-2].minor.yy42 = yymsp[0].minor.yy42; }
      case 294: /* window ::= nm ORDER BY sortlist frame_opt */
{
  yylhsminor.yy295 = sqlite3WindowAssemble(pParse, yymsp[0].minor.yy295, 0, yymsp[-1].minor.yy434, &yymsp[-4].minor.yy0);
}
  yymsp[-4].minor.yy295 = yylhsminor.yy295;
        break;
      case 293: /* part_opt ::= */
{ yymsp[1].minor.yy42 = 0; }
      case 295: /* window ::= frame_opt */
{
  yylhsminor.yy295 = yymsp[0].minor.yy295;
}
  yymsp[0].minor.yy295 = yylhsminor.yy295;
        break;
      case 294: /* frame_opt ::= */
{ 
  yymsp[1].minor.yy147 = sqlite3WindowAlloc(pParse, TK_RANGE, TK_UNBOUNDED, 0, TK_CURRENT, 0);
      case 296: /* window ::= nm frame_opt */
{
  yylhsminor.yy295 = sqlite3WindowAssemble(pParse, yymsp[0].minor.yy295, 0, 0, &yymsp[-1].minor.yy0);
}
  yymsp[-1].minor.yy295 = yylhsminor.yy295;
        break;
      case 295: /* frame_opt ::= range_or_rows frame_bound_s */
      case 297: /* frame_opt ::= */
{ 
  yylhsminor.yy147 = sqlite3WindowAlloc(pParse, yymsp[-1].minor.yy96, yymsp[0].minor.yy317.eType, yymsp[0].minor.yy317.pExpr, TK_CURRENT, 0);
  yymsp[1].minor.yy295 = sqlite3WindowAlloc(pParse, 0, TK_UNBOUNDED, 0, TK_CURRENT, 0, 0);
}
  yymsp[-1].minor.yy147 = yylhsminor.yy147;
        break;
      case 296: /* frame_opt ::= range_or_rows BETWEEN frame_bound_s AND frame_bound_e */
      case 298: /* frame_opt ::= range_or_rows frame_bound_s frame_exclude_opt */
{ 
  yylhsminor.yy147 = sqlite3WindowAlloc(pParse, yymsp[-4].minor.yy96, yymsp[-2].minor.yy317.eType, yymsp[-2].minor.yy317.pExpr, yymsp[0].minor.yy317.eType, yymsp[0].minor.yy317.pExpr);
  yylhsminor.yy295 = sqlite3WindowAlloc(pParse, yymsp[-2].minor.yy494, yymsp[-1].minor.yy201.eType, yymsp[-1].minor.yy201.pExpr, TK_CURRENT, 0, yymsp[0].minor.yy238);
}
  yymsp[-4].minor.yy147 = yylhsminor.yy147;
  yymsp[-2].minor.yy295 = yylhsminor.yy295;
        break;
      case 297: /* range_or_rows ::= RANGE */
{ yymsp[0].minor.yy96 = TK_RANGE; }
        break;
      case 298: /* range_or_rows ::= ROWS */
{ yymsp[0].minor.yy96 = TK_ROWS;  }
      case 299: /* frame_opt ::= range_or_rows BETWEEN frame_bound_s AND frame_bound_e frame_exclude_opt */
{ 
  yylhsminor.yy295 = sqlite3WindowAlloc(pParse, yymsp[-5].minor.yy494, yymsp[-3].minor.yy201.eType, yymsp[-3].minor.yy201.pExpr, yymsp[-1].minor.yy201.eType, yymsp[-1].minor.yy201.pExpr, yymsp[0].minor.yy238);
}
  yymsp[-5].minor.yy295 = yylhsminor.yy295;
        break;
      case 299: /* frame_bound_s ::= frame_bound */
      case 301: /* frame_bound_e ::= frame_bound */ yytestcase(yyruleno==301);
{ yylhsminor.yy317 = yymsp[0].minor.yy317; }
  yymsp[0].minor.yy317 = yylhsminor.yy317;
      case 301: /* frame_bound_s ::= frame_bound */
      case 303: /* frame_bound_e ::= frame_bound */ yytestcase(yyruleno==303);
{yylhsminor.yy201 = yymsp[0].minor.yy201;}
  yymsp[0].minor.yy201 = yylhsminor.yy201;
        break;
      case 300: /* frame_bound_s ::= UNBOUNDED PRECEDING */
      case 302: /* frame_bound_e ::= UNBOUNDED FOLLOWING */ yytestcase(yyruleno==302);
{yymsp[-1].minor.yy317.eType = TK_UNBOUNDED; yymsp[-1].minor.yy317.pExpr = 0;}
      case 302: /* frame_bound_s ::= UNBOUNDED PRECEDING */
      case 304: /* frame_bound_e ::= UNBOUNDED FOLLOWING */ yytestcase(yyruleno==304);
      case 306: /* frame_bound ::= CURRENT ROW */ yytestcase(yyruleno==306);
{yylhsminor.yy201.eType = yymsp[-1].major; yylhsminor.yy201.pExpr = 0;}
  yymsp[-1].minor.yy201 = yylhsminor.yy201;
        break;
      case 303: /* frame_bound ::= expr PRECEDING */
{ yylhsminor.yy317.eType = TK_PRECEDING; yylhsminor.yy317.pExpr = yymsp[-1].minor.yy490; }
  yymsp[-1].minor.yy317 = yylhsminor.yy317;
      case 305: /* frame_bound ::= expr PRECEDING|FOLLOWING */
{yylhsminor.yy201.eType = yymsp[0].major; yylhsminor.yy201.pExpr = yymsp[-1].minor.yy524;}
  yymsp[-1].minor.yy201 = yylhsminor.yy201;
        break;
      case 304: /* frame_bound ::= CURRENT ROW */
{ yymsp[-1].minor.yy317.eType = TK_CURRENT  ; yymsp[-1].minor.yy317.pExpr = 0; }
      case 307: /* frame_exclude_opt ::= */
{yymsp[1].minor.yy238 = 0;}
        break;
      case 305: /* frame_bound ::= expr FOLLOWING */
{ yylhsminor.yy317.eType = TK_FOLLOWING; yylhsminor.yy317.pExpr = yymsp[-1].minor.yy490; }
  yymsp[-1].minor.yy317 = yylhsminor.yy317;
      case 308: /* frame_exclude_opt ::= EXCLUDE frame_exclude */
{yymsp[-1].minor.yy238 = yymsp[0].minor.yy238;}
        break;
      case 309: /* frame_exclude ::= NO OTHERS */
      case 310: /* frame_exclude ::= CURRENT ROW */ yytestcase(yyruleno==310);
{yymsp[-1].minor.yy238 = yymsp[-1].major; /*A-overwrites-X*/}
        break;
      case 311: /* frame_exclude ::= GROUP|TIES */
{yymsp[0].minor.yy238 = yymsp[0].major; /*A-overwrites-X*/}
        break;
      case 306: /* window_clause ::= WINDOW windowdefn_list */
{ yymsp[-1].minor.yy147 = yymsp[0].minor.yy147; }
      case 312: /* window_clause ::= WINDOW windowdefn_list */
{ yymsp[-1].minor.yy295 = yymsp[0].minor.yy295; }
        break;
      case 307: /* over_clause ::= filter_opt OVER window */
      case 313: /* over_clause ::= filter_opt OVER LP window RP */
{
  yylhsminor.yy147 = yymsp[0].minor.yy147;
  assert( yylhsminor.yy147!=0 );
  yylhsminor.yy147->pFilter = yymsp[-2].minor.yy490;
  yylhsminor.yy295 = yymsp[-1].minor.yy295;
  assert( yylhsminor.yy295!=0 );
  yylhsminor.yy295->pFilter = yymsp[-4].minor.yy524;
}
  yymsp[-2].minor.yy147 = yylhsminor.yy147;
  yymsp[-4].minor.yy295 = yylhsminor.yy295;
        break;
      case 308: /* over_clause ::= filter_opt OVER nm */
      case 314: /* over_clause ::= filter_opt OVER nm */
{
  yylhsminor.yy147 = (Window*)sqlite3DbMallocZero(pParse->db, sizeof(Window));
  if( yylhsminor.yy147 ){
    yylhsminor.yy147->zName = sqlite3DbStrNDup(pParse->db, yymsp[0].minor.yy0.z, yymsp[0].minor.yy0.n);
    yylhsminor.yy147->pFilter = yymsp[-2].minor.yy490;
  yylhsminor.yy295 = (Window*)sqlite3DbMallocZero(pParse->db, sizeof(Window));
  if( yylhsminor.yy295 ){
    yylhsminor.yy295->zName = sqlite3DbStrNDup(pParse->db, yymsp[0].minor.yy0.z, yymsp[0].minor.yy0.n);
    yylhsminor.yy295->pFilter = yymsp[-2].minor.yy524;
  }else{
    sqlite3ExprDelete(pParse->db, yymsp[-2].minor.yy490);
    sqlite3ExprDelete(pParse->db, yymsp[-2].minor.yy524);
  }
}
  yymsp[-2].minor.yy147 = yylhsminor.yy147;
  yymsp[-2].minor.yy295 = yylhsminor.yy295;
        break;
      case 310: /* filter_opt ::= FILTER LP WHERE expr RP */
{ yymsp[-4].minor.yy490 = yymsp[-1].minor.yy490; }
      case 316: /* filter_opt ::= FILTER LP WHERE expr RP */
{ yymsp[-4].minor.yy524 = yymsp[-1].minor.yy524; }
        break;
      default:
      /* (311) input ::= cmdlist */ yytestcase(yyruleno==311);
      /* (312) cmdlist ::= cmdlist ecmd */ yytestcase(yyruleno==312);
      /* (313) cmdlist ::= ecmd (OPTIMIZED OUT) */ assert(yyruleno!=313);
      /* (314) ecmd ::= SEMI */ yytestcase(yyruleno==314);
      /* (315) ecmd ::= cmdx SEMI */ yytestcase(yyruleno==315);
      /* (316) ecmd ::= explain cmdx */ yytestcase(yyruleno==316);
      /* (317) trans_opt ::= */ yytestcase(yyruleno==317);
      /* (318) trans_opt ::= TRANSACTION */ yytestcase(yyruleno==318);
      /* (319) trans_opt ::= TRANSACTION nm */ yytestcase(yyruleno==319);
      /* (320) savepoint_opt ::= SAVEPOINT */ yytestcase(yyruleno==320);
      /* (321) savepoint_opt ::= */ yytestcase(yyruleno==321);
      /* (322) cmd ::= create_table create_table_args */ yytestcase(yyruleno==322);
      /* (323) columnlist ::= columnlist COMMA columnname carglist */ yytestcase(yyruleno==323);
      /* (324) columnlist ::= columnname carglist */ yytestcase(yyruleno==324);
      /* (325) nm ::= ID|INDEXED */ yytestcase(yyruleno==325);
      /* (326) nm ::= STRING */ yytestcase(yyruleno==326);
      /* (327) nm ::= JOIN_KW */ yytestcase(yyruleno==327);
      /* (328) typetoken ::= typename */ yytestcase(yyruleno==328);
      /* (329) typename ::= ID|STRING */ yytestcase(yyruleno==329);
      /* (330) signed ::= plus_num (OPTIMIZED OUT) */ assert(yyruleno!=330);
      /* (331) signed ::= minus_num (OPTIMIZED OUT) */ assert(yyruleno!=331);
      /* (332) carglist ::= carglist ccons */ yytestcase(yyruleno==332);
      /* (333) carglist ::= */ yytestcase(yyruleno==333);
      /* (334) ccons ::= NULL onconf */ yytestcase(yyruleno==334);
      /* (335) conslist_opt ::= COMMA conslist */ yytestcase(yyruleno==335);
      /* (336) conslist ::= conslist tconscomma tcons */ yytestcase(yyruleno==336);
      /* (337) conslist ::= tcons (OPTIMIZED OUT) */ assert(yyruleno!=337);
      /* (338) tconscomma ::= */ yytestcase(yyruleno==338);
      /* (339) defer_subclause_opt ::= defer_subclause (OPTIMIZED OUT) */ assert(yyruleno!=339);
      /* (340) resolvetype ::= raisetype (OPTIMIZED OUT) */ assert(yyruleno!=340);
      /* (341) selectnowith ::= oneselect (OPTIMIZED OUT) */ assert(yyruleno!=341);
      /* (342) oneselect ::= values */ yytestcase(yyruleno==342);
      /* (343) sclp ::= selcollist COMMA */ yytestcase(yyruleno==343);
      /* (344) as ::= ID|STRING */ yytestcase(yyruleno==344);
      /* (345) expr ::= term (OPTIMIZED OUT) */ assert(yyruleno!=345);
      /* (346) likeop ::= LIKE_KW|MATCH */ yytestcase(yyruleno==346);
      /* (347) exprlist ::= nexprlist */ yytestcase(yyruleno==347);
      /* (348) nmnum ::= plus_num (OPTIMIZED OUT) */ assert(yyruleno!=348);
      /* (349) nmnum ::= nm (OPTIMIZED OUT) */ assert(yyruleno!=349);
      /* (350) nmnum ::= ON */ yytestcase(yyruleno==350);
      /* (351) nmnum ::= DELETE */ yytestcase(yyruleno==351);
      /* (352) nmnum ::= DEFAULT */ yytestcase(yyruleno==352);
      /* (353) plus_num ::= INTEGER|FLOAT */ yytestcase(yyruleno==353);
      /* (354) foreach_clause ::= */ yytestcase(yyruleno==354);
      /* (355) foreach_clause ::= FOR EACH ROW */ yytestcase(yyruleno==355);
      /* (356) trnm ::= nm */ yytestcase(yyruleno==356);
      /* (357) tridxby ::= */ yytestcase(yyruleno==357);
      /* (358) database_kw_opt ::= DATABASE */ yytestcase(yyruleno==358);
      /* (359) database_kw_opt ::= */ yytestcase(yyruleno==359);
      /* (360) kwcolumn_opt ::= */ yytestcase(yyruleno==360);
      /* (361) kwcolumn_opt ::= COLUMNKW */ yytestcase(yyruleno==361);
      /* (362) vtabarglist ::= vtabarg */ yytestcase(yyruleno==362);
      /* (363) vtabarglist ::= vtabarglist COMMA vtabarg */ yytestcase(yyruleno==363);
      /* (364) vtabarg ::= vtabarg vtabargtoken */ yytestcase(yyruleno==364);
      /* (365) anylist ::= */ yytestcase(yyruleno==365);
      /* (366) anylist ::= anylist LP anylist RP */ yytestcase(yyruleno==366);
      /* (367) anylist ::= anylist ANY */ yytestcase(yyruleno==367);
      /* (368) with ::= */ yytestcase(yyruleno==368);
      /* (317) input ::= cmdlist */ yytestcase(yyruleno==317);
      /* (318) cmdlist ::= cmdlist ecmd */ yytestcase(yyruleno==318);
      /* (319) cmdlist ::= ecmd (OPTIMIZED OUT) */ assert(yyruleno!=319);
      /* (320) ecmd ::= SEMI */ yytestcase(yyruleno==320);
      /* (321) ecmd ::= cmdx SEMI */ yytestcase(yyruleno==321);
      /* (322) ecmd ::= explain cmdx */ yytestcase(yyruleno==322);
      /* (323) trans_opt ::= */ yytestcase(yyruleno==323);
      /* (324) trans_opt ::= TRANSACTION */ yytestcase(yyruleno==324);
      /* (325) trans_opt ::= TRANSACTION nm */ yytestcase(yyruleno==325);
      /* (326) savepoint_opt ::= SAVEPOINT */ yytestcase(yyruleno==326);
      /* (327) savepoint_opt ::= */ yytestcase(yyruleno==327);
      /* (328) cmd ::= create_table create_table_args */ yytestcase(yyruleno==328);
      /* (329) columnlist ::= columnlist COMMA columnname carglist */ yytestcase(yyruleno==329);
      /* (330) columnlist ::= columnname carglist */ yytestcase(yyruleno==330);
      /* (331) nm ::= ID|INDEXED */ yytestcase(yyruleno==331);
      /* (332) nm ::= STRING */ yytestcase(yyruleno==332);
      /* (333) nm ::= JOIN_KW */ yytestcase(yyruleno==333);
      /* (334) typetoken ::= typename */ yytestcase(yyruleno==334);
      /* (335) typename ::= ID|STRING */ yytestcase(yyruleno==335);
      /* (336) signed ::= plus_num (OPTIMIZED OUT) */ assert(yyruleno!=336);
      /* (337) signed ::= minus_num (OPTIMIZED OUT) */ assert(yyruleno!=337);
      /* (338) carglist ::= carglist ccons */ yytestcase(yyruleno==338);
      /* (339) carglist ::= */ yytestcase(yyruleno==339);
      /* (340) ccons ::= NULL onconf */ yytestcase(yyruleno==340);
      /* (341) conslist_opt ::= COMMA conslist */ yytestcase(yyruleno==341);
      /* (342) conslist ::= conslist tconscomma tcons */ yytestcase(yyruleno==342);
      /* (343) conslist ::= tcons (OPTIMIZED OUT) */ assert(yyruleno!=343);
      /* (344) tconscomma ::= */ yytestcase(yyruleno==344);
      /* (345) defer_subclause_opt ::= defer_subclause (OPTIMIZED OUT) */ assert(yyruleno!=345);
      /* (346) resolvetype ::= raisetype (OPTIMIZED OUT) */ assert(yyruleno!=346);
      /* (347) selectnowith ::= oneselect (OPTIMIZED OUT) */ assert(yyruleno!=347);
      /* (348) oneselect ::= values */ yytestcase(yyruleno==348);
      /* (349) sclp ::= selcollist COMMA */ yytestcase(yyruleno==349);
      /* (350) as ::= ID|STRING */ yytestcase(yyruleno==350);
      /* (351) expr ::= term (OPTIMIZED OUT) */ assert(yyruleno!=351);
      /* (352) likeop ::= LIKE_KW|MATCH */ yytestcase(yyruleno==352);
      /* (353) exprlist ::= nexprlist */ yytestcase(yyruleno==353);
      /* (354) nmnum ::= plus_num (OPTIMIZED OUT) */ assert(yyruleno!=354);
      /* (355) nmnum ::= nm (OPTIMIZED OUT) */ assert(yyruleno!=355);
      /* (356) nmnum ::= ON */ yytestcase(yyruleno==356);
      /* (357) nmnum ::= DELETE */ yytestcase(yyruleno==357);
      /* (358) nmnum ::= DEFAULT */ yytestcase(yyruleno==358);
      /* (359) plus_num ::= INTEGER|FLOAT */ yytestcase(yyruleno==359);
      /* (360) foreach_clause ::= */ yytestcase(yyruleno==360);
      /* (361) foreach_clause ::= FOR EACH ROW */ yytestcase(yyruleno==361);
      /* (362) trnm ::= nm */ yytestcase(yyruleno==362);
      /* (363) tridxby ::= */ yytestcase(yyruleno==363);
      /* (364) database_kw_opt ::= DATABASE */ yytestcase(yyruleno==364);
      /* (365) database_kw_opt ::= */ yytestcase(yyruleno==365);
      /* (366) kwcolumn_opt ::= */ yytestcase(yyruleno==366);
      /* (367) kwcolumn_opt ::= COLUMNKW */ yytestcase(yyruleno==367);
      /* (368) vtabarglist ::= vtabarg */ yytestcase(yyruleno==368);
      /* (369) vtabarglist ::= vtabarglist COMMA vtabarg */ yytestcase(yyruleno==369);
      /* (370) vtabarg ::= vtabarg vtabargtoken */ yytestcase(yyruleno==370);
      /* (371) anylist ::= */ yytestcase(yyruleno==371);
      /* (372) anylist ::= anylist LP anylist RP */ yytestcase(yyruleno==372);
      /* (373) anylist ::= anylist ANY */ yytestcase(yyruleno==373);
      /* (374) with ::= */ yytestcase(yyruleno==374);
        break;
/********** End reduce actions ************************************************/
  };
  assert( yyruleno<sizeof(yyRuleInfoLhs)/sizeof(yyRuleInfoLhs[0]) );
  yygoto = yyRuleInfoLhs[yyruleno];
  yysize = yyRuleInfoNRhs[yyruleno];
  yyact = yy_find_reduce_action(yymsp[yysize].stateno,(YYCODETYPE)yygoto);
152270
152271
152272
152273
152274
152275
152276
152277
152278


152279
152280
152281
152282
152283
152284
152285
152286
152287
152288
152289
152290











152291
152292
152293
152294
152295
152296
152297





152298
152299

152300
152301
152302
152303
152304
152305
152306
152307
152308
152309
152310
152311
152312
152313
152314
152315
152316
152317
152318
152319
152320
152321
152322
152323
152324

























152325
152326
152327
152328
152329
152330
152331
152332
152333
152334
152335
152336
152337
152338










152339
152340
152341
152342
152343

152344
152345

152346
152347
152348
152349
152350





152351
152352
152353
152354



152355
152356
152357

152358
152359
152360



152361
152362
152363
152364
152365
152366
152367
152368







152369
152370
152371
152372

152373
152374
152375
152376
152377
152378
152379
152380
152381
152382
152383









152384
152385
152386

152387
152388
152389
152390
152391
152392
152393
152394
152395
152396
152397
152398
152399









152400
152401
152402
152403
152404
152405
152406
152407
152408
152409
152410
152411
152412
152413














152414
152415
152416
152417
152418
152419
152420
152421
153155
153156
153157
153158
153159
153160
153161


153162
153163
153164











153165
153166
153167
153168
153169
153170
153171
153172
153173
153174
153175
153176
153177
153178
153179



153180
153181
153182
153183
153184


153185

























153186
153187
153188
153189
153190
153191
153192
153193
153194
153195
153196
153197
153198
153199
153200
153201
153202
153203
153204
153205
153206
153207
153208
153209
153210

153211
153212
153213










153214
153215
153216
153217
153218
153219
153220
153221
153222
153223
153224
153225
153226
153227

153228
153229
153230
153231





153232
153233
153234
153235
153236




153237
153238
153239
153240
153241

153242
153243


153244
153245
153246








153247
153248
153249
153250
153251
153252
153253
153254
153255
153256

153257
153258
153259









153260
153261
153262
153263
153264
153265
153266
153267
153268
153269
153270

153271
153272
153273
153274
153275
153276








153277
153278
153279
153280
153281
153282
153283
153284
153285














153286
153287
153288
153289
153290
153291
153292
153293
153294
153295
153296
153297
153298
153299

153300
153301
153302
153303
153304
153305
153306







-
-
+
+

-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+




-
-
-
+
+
+
+
+
-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-



-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+




-
+


+
-
-
-
-
-
+
+
+
+
+
-
-
-
-
+
+
+


-
+

-
-
+
+
+
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+



-
+


-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+


-
+





-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-







** The code in this file implements a function that determines whether
** or not a given identifier is really an SQL keyword.  The same thing
** might be implemented more directly using a hand-written hash table.
** But by using this automatically generated code, the size of the code
** is substantially reduced.  This is important for embedded applications
** on platforms with limited memory.
*/
/* Hash score: 208 */
/* zKWText[] encodes 923 bytes of keyword text in 614 bytes */
/* Hash score: 214 */
/* zKWText[] encodes 950 bytes of keyword text in 629 bytes */
/*   REINDEXEDESCAPEACHECKEYBEFOREIGNOREGEXPLAINSTEADDATABASELECT       */
/*   ABLEFTHENDEFERRABLELSEXCEPTRANSACTIONATURALTERAISEXCLUSIVE         */
/*   XISTSAVEPOINTERSECTRIGGEREFERENCESCONSTRAINTOFFSETEMPORARY         */
/*   UNIQUERYWITHOUTERELEASEATTACHAVINGROUPDATEBEGINNERANGEBETWEEN      */
/*   OTHINGLOBYCASCADELETECASECOLLATECREATECURRENT_DATEDETACH           */
/*   IMMEDIATEJOINSERTLIKEMATCHPLANALYZEPRAGMABORTVALUESVIRTUALIMIT     */
/*   WHENOTNULLWHERECURSIVEAFTERENAMEANDEFAULTAUTOINCREMENTCAST         */
/*   COLUMNCOMMITCONFLICTCROSSCURRENT_TIMESTAMPARTITIONDEFERRED         */
/*   ISTINCTDROPRECEDINGFAILFILTEREPLACEFOLLOWINGFROMFULLIFISNULL       */
/*   ORDERESTRICTOVERIGHTROLLBACKROWSUNBOUNDEDUNIONUSINGVACUUMVIEW      */
/*   INDOWINITIALLYPRIMARY                                              */
static const char zKWText[613] = {
/*   ABLEFTHENDEFERRABLELSEXCLUDELETEMPORARYCONSTRAINTERSECTIES         */
/*   AVEPOINTOFFSETRANSACTIONATURALTERAISEXCEPTRIGGEREFERENCES          */
/*   UNIQUERYWITHOUTERELEASEXCLUSIVEXISTSATTACHAVINGLOBEGINNERANGE      */
/*   BETWEENOTHINGROUPSCASCADETACHCASECOLLATECREATECURRENT_DATE         */
/*   IMMEDIATEJOINSERTLIKEMATCHPLANALYZEPRAGMABORTUPDATEVALUES          */
/*   VIRTUALIMITWHENOTNULLWHERECURSIVEAFTERENAMEANDEFAULT               */
/*   AUTOINCREMENTCASTCOLUMNCOMMITCONFLICTCROSSCURRENT_TIMESTAMP        */
/*   ARTITIONDEFERREDISTINCTDROPRECEDINGFAILFILTEREPLACEFOLLOWING       */
/*   FROMFULLIFISNULLORDERESTRICTOTHERSOVERIGHTROLLBACKROWS             */
/*   UNBOUNDEDUNIONUSINGVACUUMVIEWINDOWBYINITIALLYPRIMARY               */
static const char zKWText[628] = {
  'R','E','I','N','D','E','X','E','D','E','S','C','A','P','E','A','C','H',
  'E','C','K','E','Y','B','E','F','O','R','E','I','G','N','O','R','E','G',
  'E','X','P','L','A','I','N','S','T','E','A','D','D','A','T','A','B','A',
  'S','E','L','E','C','T','A','B','L','E','F','T','H','E','N','D','E','F',
  'E','R','R','A','B','L','E','L','S','E','X','C','E','P','T','R','A','N',
  'S','A','C','T','I','O','N','A','T','U','R','A','L','T','E','R','A','I',
  'S','E','X','C','L','U','S','I','V','E','X','I','S','T','S','A','V','E',
  'E','R','R','A','B','L','E','L','S','E','X','C','L','U','D','E','L','E',
  'T','E','M','P','O','R','A','R','Y','C','O','N','S','T','R','A','I','N',
  'T','E','R','S','E','C','T','I','E','S','A','V','E','P','O','I','N','T',
  'O','F','F','S','E','T','R','A','N','S','A','C','T','I','O','N','A','T',
  'U','R','A','L','T','E','R','A','I','S','E','X','C','E','P','T','R','I',
  'P','O','I','N','T','E','R','S','E','C','T','R','I','G','G','E','R','E',
  'F','E','R','E','N','C','E','S','C','O','N','S','T','R','A','I','N','T',
  'G','G','E','R','E','F','E','R','E','N','C','E','S','U','N','I','Q','U',
  'O','F','F','S','E','T','E','M','P','O','R','A','R','Y','U','N','I','Q',
  'U','E','R','Y','W','I','T','H','O','U','T','E','R','E','L','E','A','S',
  'E','A','T','T','A','C','H','A','V','I','N','G','R','O','U','P','D','A',
  'T','E','B','E','G','I','N','N','E','R','A','N','G','E','B','E','T','W',
  'E','E','N','O','T','H','I','N','G','L','O','B','Y','C','A','S','C','A',
  'D','E','L','E','T','E','C','A','S','E','C','O','L','L','A','T','E','C',
  'R','E','A','T','E','C','U','R','R','E','N','T','_','D','A','T','E','D',
  'E','T','A','C','H','I','M','M','E','D','I','A','T','E','J','O','I','N',
  'S','E','R','T','L','I','K','E','M','A','T','C','H','P','L','A','N','A',
  'L','Y','Z','E','P','R','A','G','M','A','B','O','R','T','V','A','L','U',
  'E','S','V','I','R','T','U','A','L','I','M','I','T','W','H','E','N','O',
  'T','N','U','L','L','W','H','E','R','E','C','U','R','S','I','V','E','A',
  'F','T','E','R','E','N','A','M','E','A','N','D','E','F','A','U','L','T',
  'A','U','T','O','I','N','C','R','E','M','E','N','T','C','A','S','T','C',
  'O','L','U','M','N','C','O','M','M','I','T','C','O','N','F','L','I','C',
  'T','C','R','O','S','S','C','U','R','R','E','N','T','_','T','I','M','E',
  'S','T','A','M','P','A','R','T','I','T','I','O','N','D','E','F','E','R',
  'R','E','D','I','S','T','I','N','C','T','D','R','O','P','R','E','C','E',
  'D','I','N','G','F','A','I','L','F','I','L','T','E','R','E','P','L','A',
  'C','E','F','O','L','L','O','W','I','N','G','F','R','O','M','F','U','L',
  'L','I','F','I','S','N','U','L','L','O','R','D','E','R','E','S','T','R',
  'I','C','T','O','V','E','R','I','G','H','T','R','O','L','L','B','A','C',
  'K','R','O','W','S','U','N','B','O','U','N','D','E','D','U','N','I','O',
  'N','U','S','I','N','G','V','A','C','U','U','M','V','I','E','W','I','N',
  'D','O','W','I','N','I','T','I','A','L','L','Y','P','R','I','M','A','R',
  'E','R','Y','W','I','T','H','O','U','T','E','R','E','L','E','A','S','E',
  'X','C','L','U','S','I','V','E','X','I','S','T','S','A','T','T','A','C',
  'H','A','V','I','N','G','L','O','B','E','G','I','N','N','E','R','A','N',
  'G','E','B','E','T','W','E','E','N','O','T','H','I','N','G','R','O','U',
  'P','S','C','A','S','C','A','D','E','T','A','C','H','C','A','S','E','C',
  'O','L','L','A','T','E','C','R','E','A','T','E','C','U','R','R','E','N',
  'T','_','D','A','T','E','I','M','M','E','D','I','A','T','E','J','O','I',
  'N','S','E','R','T','L','I','K','E','M','A','T','C','H','P','L','A','N',
  'A','L','Y','Z','E','P','R','A','G','M','A','B','O','R','T','U','P','D',
  'A','T','E','V','A','L','U','E','S','V','I','R','T','U','A','L','I','M',
  'I','T','W','H','E','N','O','T','N','U','L','L','W','H','E','R','E','C',
  'U','R','S','I','V','E','A','F','T','E','R','E','N','A','M','E','A','N',
  'D','E','F','A','U','L','T','A','U','T','O','I','N','C','R','E','M','E',
  'N','T','C','A','S','T','C','O','L','U','M','N','C','O','M','M','I','T',
  'C','O','N','F','L','I','C','T','C','R','O','S','S','C','U','R','R','E',
  'N','T','_','T','I','M','E','S','T','A','M','P','A','R','T','I','T','I',
  'O','N','D','E','F','E','R','R','E','D','I','S','T','I','N','C','T','D',
  'R','O','P','R','E','C','E','D','I','N','G','F','A','I','L','F','I','L',
  'T','E','R','E','P','L','A','C','E','F','O','L','L','O','W','I','N','G',
  'F','R','O','M','F','U','L','L','I','F','I','S','N','U','L','L','O','R',
  'D','E','R','E','S','T','R','I','C','T','O','T','H','E','R','S','O','V',
  'E','R','I','G','H','T','R','O','L','L','B','A','C','K','R','O','W','S',
  'U','N','B','O','U','N','D','E','D','U','N','I','O','N','U','S','I','N',
  'G','V','A','C','U','U','M','V','I','E','W','I','N','D','O','W','B','Y',
  'I','N','I','T','I','A','L','L','Y','P','R','I','M','A','R','Y',
  'Y',
};
/* aKWHash[i] is the hash value for the i-th keyword */
static const unsigned char aKWHash[127] = {
    74, 109, 124,  72, 106,  45,   0,   0,  81,   0,  76,  61,   0,
    42,  12,  77,  15,   0, 123,  84,  54, 118, 125,  19,   0,   0,
   130,   0, 128, 121,   0,  22,  96,   0,   9,   0,   0, 115,  69,
     0,  67,   6,   0,  48,  93, 136,   0, 126, 104,   0,   0,  44,
     0, 107,  24,   0,  17,   0, 131,  53,  23,   0,   5,  62, 132,
    99,   0,   0, 135, 110,  60, 134,  57, 113,  55,   0,  94,   0,
   103,  26,   0, 102,   0,   0,   0,  98,  95, 100, 105, 117,  14,
    39, 116,   0,  80,   0, 133, 114,  92,  59,   0, 129,  79, 119,
    86,  46,  83,   0,   0,  97,  40, 122, 120,   0, 127,   0,   0,
    29,   0,  89,  87,  88,   0,  20,  85, 111,  56,
    75, 111, 127,  73, 108,  29,   0,   0,  83,   0,  77,  63,   0,
    37,  33,  78,  15,   0, 126,  86,  57, 120, 128,  19,   0,   0,
   133,   0, 131, 123,   0,  22,  98,   0,   9,   0,   0, 117,  71,
     0,  69,   6,   0,  49,  95, 140,   0, 129, 106,   0,   0,  54,
     0, 109,  24,   0,  17,   0, 134,  56,  23,  26,   5,  58, 135,
   101,   0,   0, 139, 112,  62, 138,  59, 115,  65,   0,  96,   0,
   105,  45,   0, 104,   0,   0,   0, 100,  97, 102, 107, 119,  14,
    31, 118,   0,  81,   0, 136, 116, 137,  61, 124, 132,  80, 121,
    88,  30,  85,   0,   0,  99,  35, 125, 122,   0, 130,   0,   0,
    41,   0,  91,  89,  90,   0,  20,  87, 113,  82,
};
/* aKWNext[] forms the hash collision chain.  If aKWHash[i]==0
** then the i-th keyword has no more hash collisions.  Otherwise,
** the next keyword with the same hash is aKWHash[i]-1. */
static const unsigned char aKWNext[136] = {
static const unsigned char aKWNext[140] = {
     0,   0,   0,   0,   4,   0,   0,   0,   0,   0,   0,   0,   0,
     0,   2,   0,   0,   0,   0,   0,   0,  13,   0,   0,   0,   0,
     0,   0,   0,  21,   0,   0,  12,   0,   0,   0,   0,   0,   0,
     0,   7,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,
     0,   0,   0,   0,  33,   0,  21,   0,   0,   0,   0,   0,  50,
     0,  43,   3,  47,   0,   0,  32,   0,   0,   0,   0,   0,   0,
     0,   1,  64,   0,   0,  65,   0,  41,   0,  38,   0,   0,   0,
     0,   0,  49,  75,   0,   0,  30,   0,  58,   0,   0,   0,  31,
     7,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,
    51,  28,   0,   0,  38,   0,   0,   0,  44,   0,   0,   0,   3,
     0,   0,  67,   1,  66,   0,   0,   0,  36,   0,  47,   0,   0,
     0,   0,   0,  48,  50,  76,   0,   0,  42,   0,  60,   0,   0,
     0,  43,   0,  16,  55,  10,   0,   0,   0,   0,   0,   0,   0,
    63,  16,  34,  10,   0,   0,   0,   0,   0,   0,   0,  11,  70,
    91,   0,   0,   8,   0, 108,   0, 101,  28,  52,  68,   0, 112,
     0,  73,  51,   0,  90,  27,  37,   0,  71,  36,  82,   0,  35,
    66,  25,  18,   0,   0,  78,
    11,  72,  93,   0,   0,   8,   0, 110,   0, 103,  40,  53,  70,
     0, 114,   0,  74,  52,   0,   0,  92,  39,  46,   0,  68,  32,
    84,   0,  34,  27,  25,  18,  94,   0,  64,  79,
};
/* aKWLen[i] is the length (in bytes) of the i-th keyword */
static const unsigned char aKWLen[136] = {
static const unsigned char aKWLen[140] = {
     7,   7,   5,   4,   6,   4,   5,   3,   6,   7,   3,   6,   6,
     7,   7,   3,   8,   2,   6,   5,   4,   4,   3,  10,   4,   6,
    11,   6,   2,   7,   5,   5,   9,   6,   9,   9,   7,  10,  10,
     7,   7,   3,   8,   2,   6,   5,   4,   4,   3,  10,   4,   7,
     6,   9,   4,   2,  10,   9,   4,   9,   4,   6,   2,   3,  11,
     6,   2,   7,   5,   5,   6,   7,  10,   6,   5,   7,   4,   5,
     4,   6,   2,   3,   9,   4,   2,   6,   5,   7,   4,   5,   7,
     6,   6,   5,   6,   5,   5,   5,   7,   7,   4,   2,   7,   3,
     6,   4,   7,   6,  12,   6,   9,   4,   6,   4,   5,   4,   7,
     6,   5,   6,   7,   5,   4,   7,   3,   2,   4,   5,   9,   5,
     6,   3,   7,  13,   2,   2,   4,   6,   6,   8,   5,  17,  12,
     7,   9,   8,   8,   2,   4,   9,   4,   6,   7,   9,   4,   4,
     2,   6,   5,   8,   4,   5,   8,   4,   3,   9,   5,   5,   6,
     4,   6,   2,   9,   3,   7,
     7,   9,   6,   6,   6,   4,   5,   5,   5,   7,   7,   6,   5,
     7,   3,   6,   4,   7,   6,  12,   9,   4,   6,   4,   5,   4,
     7,   6,   5,   6,   6,   7,   5,   4,   7,   3,   2,   4,   5,
     9,   5,   6,   3,   7,  13,   2,   2,   4,   6,   6,   8,   5,
    17,  12,   7,   9,   8,   8,   2,   4,   9,   4,   6,   7,   9,
     4,   4,   2,   6,   5,   8,   6,   4,   5,   8,   4,   3,   9,
     5,   5,   6,   4,   6,   2,   2,   9,   3,   7,
};
/* aKWOffset[i] is the index into zKWText[] of the start of
** the text for the i-th keyword. */
static const unsigned short int aKWOffset[136] = {
static const unsigned short int aKWOffset[140] = {
     0,   2,   2,   8,   9,  14,  16,  20,  23,  25,  25,  29,  33,
    36,  41,  46,  48,  53,  54,  59,  62,  65,  67,  69,  78,  81,
    86,  91,  95,  96, 101, 105, 109, 117, 122, 128, 136, 142, 152,
   159, 162, 162, 165, 167, 167, 171, 176, 179, 184, 184, 188, 192,
   199, 204, 209, 212, 218, 221, 225, 230, 236, 242, 245, 247, 248,
   252, 258, 262, 269, 275, 287, 293, 302, 304, 310, 314, 319, 321,
   328, 333, 338, 344, 350, 355, 358, 358, 358, 361, 365, 368, 377,
   381, 387, 389, 396, 398, 400, 409, 413, 419, 425, 433, 438, 438,
   438, 454, 463, 470, 471, 478, 481, 490, 494, 499, 506, 515, 519,
   523, 525, 531, 535, 543, 546, 551, 559, 559, 563, 572, 577, 582,
   588, 591, 594, 597, 602, 606,
    86,  90,  90,  94,  99, 106, 114, 117, 123, 126, 126, 129, 131,
   136, 140, 141, 146, 150, 154, 159, 165, 175, 178, 183, 183, 187,
   191, 197, 205, 211, 216, 221, 224, 227, 231, 236, 242, 248, 248,
   254, 255, 259, 265, 269, 276, 282, 294, 303, 305, 311, 315, 320,
   322, 329, 334, 339, 345, 351, 357, 362, 365, 365, 365, 368, 372,
   375, 384, 388, 394, 396, 403, 405, 407, 416, 420, 426, 432, 440,
   445, 445, 445, 461, 470, 477, 478, 485, 488, 497, 501, 506, 513,
   522, 526, 530, 532, 538, 542, 550, 556, 559, 564, 572, 572, 576,
   585, 590, 595, 601, 604, 607, 610, 612, 617, 621,
};
/* aKWCode[i] is the parser symbol code for the i-th keyword */
static const unsigned char aKWCode[136] = {
static const unsigned char aKWCode[140] = {
  TK_REINDEX,    TK_INDEXED,    TK_INDEX,      TK_DESC,       TK_ESCAPE,     
  TK_EACH,       TK_CHECK,      TK_KEY,        TK_BEFORE,     TK_FOREIGN,    
  TK_FOR,        TK_IGNORE,     TK_LIKE_KW,    TK_EXPLAIN,    TK_INSTEAD,    
  TK_ADD,        TK_DATABASE,   TK_AS,         TK_SELECT,     TK_TABLE,      
  TK_JOIN_KW,    TK_THEN,       TK_END,        TK_DEFERRABLE, TK_ELSE,       
  TK_EXCEPT,     TK_TRANSACTION,TK_ACTION,     TK_ON,         TK_JOIN_KW,    
  TK_ALTER,      TK_RAISE,      TK_EXCLUSIVE,  TK_EXISTS,     TK_SAVEPOINT,  
  TK_INTERSECT,  TK_TRIGGER,    TK_REFERENCES, TK_CONSTRAINT, TK_INTO,       
  TK_OFFSET,     TK_OF,         TK_SET,        TK_TEMP,       TK_TEMP,       
  TK_OR,         TK_UNIQUE,     TK_QUERY,      TK_WITHOUT,    TK_WITH,       
  TK_JOIN_KW,    TK_RELEASE,    TK_ATTACH,     TK_HAVING,     TK_GROUP,      
  TK_UPDATE,     TK_BEGIN,      TK_JOIN_KW,    TK_RANGE,      TK_BETWEEN,    
  TK_NOTHING,    TK_LIKE_KW,    TK_BY,         TK_CASCADE,    TK_ASC,        
  TK_EXCLUDE,    TK_DELETE,     TK_TEMP,       TK_TEMP,       TK_OR,         
  TK_CONSTRAINT, TK_INTERSECT,  TK_TIES,       TK_SAVEPOINT,  TK_INTO,       
  TK_OFFSET,     TK_OF,         TK_SET,        TK_TRANSACTION,TK_ACTION,     
  TK_ON,         TK_JOIN_KW,    TK_ALTER,      TK_RAISE,      TK_EXCEPT,     
  TK_TRIGGER,    TK_REFERENCES, TK_UNIQUE,     TK_QUERY,      TK_WITHOUT,    
  TK_WITH,       TK_JOIN_KW,    TK_RELEASE,    TK_EXCLUSIVE,  TK_EXISTS,     
  TK_ATTACH,     TK_HAVING,     TK_LIKE_KW,    TK_BEGIN,      TK_JOIN_KW,    
  TK_RANGE,      TK_BETWEEN,    TK_NOTHING,    TK_GROUPS,     TK_GROUP,      
  TK_CASCADE,    TK_ASC,        TK_DETACH,     TK_CASE,       TK_COLLATE,    
  TK_DELETE,     TK_CASE,       TK_COLLATE,    TK_CREATE,     TK_CTIME_KW,   
  TK_DETACH,     TK_IMMEDIATE,  TK_JOIN,       TK_INSERT,     TK_LIKE_KW,    
  TK_MATCH,      TK_PLAN,       TK_ANALYZE,    TK_PRAGMA,     TK_ABORT,      
  TK_VALUES,     TK_VIRTUAL,    TK_LIMIT,      TK_WHEN,       TK_NOTNULL,    
  TK_NOT,        TK_NO,         TK_NULL,       TK_WHERE,      TK_RECURSIVE,  
  TK_AFTER,      TK_RENAME,     TK_AND,        TK_DEFAULT,    TK_AUTOINCR,   
  TK_TO,         TK_IN,         TK_CAST,       TK_COLUMNKW,   TK_COMMIT,     
  TK_CONFLICT,   TK_JOIN_KW,    TK_CTIME_KW,   TK_CTIME_KW,   TK_CURRENT,    
  TK_PARTITION,  TK_DEFERRED,   TK_DISTINCT,   TK_IS,         TK_DROP,       
  TK_PRECEDING,  TK_FAIL,       TK_FILTER,     TK_REPLACE,    TK_FOLLOWING,  
  TK_FROM,       TK_JOIN_KW,    TK_IF,         TK_ISNULL,     TK_ORDER,      
  TK_RESTRICT,   TK_OVER,       TK_JOIN_KW,    TK_ROLLBACK,   TK_ROWS,       
  TK_ROW,        TK_UNBOUNDED,  TK_UNION,      TK_USING,      TK_VACUUM,     
  TK_VIEW,       TK_WINDOW,     TK_DO,         TK_INITIALLY,  TK_ALL,        
  TK_CREATE,     TK_CTIME_KW,   TK_IMMEDIATE,  TK_JOIN,       TK_INSERT,     
  TK_LIKE_KW,    TK_MATCH,      TK_PLAN,       TK_ANALYZE,    TK_PRAGMA,     
  TK_ABORT,      TK_UPDATE,     TK_VALUES,     TK_VIRTUAL,    TK_LIMIT,      
  TK_WHEN,       TK_NOTNULL,    TK_NOT,        TK_NO,         TK_NULL,       
  TK_WHERE,      TK_RECURSIVE,  TK_AFTER,      TK_RENAME,     TK_AND,        
  TK_DEFAULT,    TK_AUTOINCR,   TK_TO,         TK_IN,         TK_CAST,       
  TK_COLUMNKW,   TK_COMMIT,     TK_CONFLICT,   TK_JOIN_KW,    TK_CTIME_KW,   
  TK_CTIME_KW,   TK_CURRENT,    TK_PARTITION,  TK_DEFERRED,   TK_DISTINCT,   
  TK_IS,         TK_DROP,       TK_PRECEDING,  TK_FAIL,       TK_FILTER,     
  TK_REPLACE,    TK_FOLLOWING,  TK_FROM,       TK_JOIN_KW,    TK_IF,         
  TK_ISNULL,     TK_ORDER,      TK_RESTRICT,   TK_OTHERS,     TK_OVER,       
  TK_JOIN_KW,    TK_ROLLBACK,   TK_ROWS,       TK_ROW,        TK_UNBOUNDED,  
  TK_UNION,      TK_USING,      TK_VACUUM,     TK_VIEW,       TK_WINDOW,     
  TK_DO,         TK_BY,         TK_INITIALLY,  TK_ALL,        TK_PRIMARY,    
  TK_PRIMARY,    
};
/* Check to see if z[0..n-1] is a keyword. If it is, write the
** parser symbol code for that keyword into *pType.  Always
** return the integer n (the length of the token). */
static int keywordCode(const char *z, int n, int *pType){
  int i, j;
  const char *zKW;
152453
152454
152455
152456
152457
152458
152459
152460
152461
152462
152463
152464
152465
152466
152467
152468
152469
152470
152471
152472
152473
152474
152475
152476
152477
152478
152479
152480
152481
152482
152483
152484
152485
152486
152487
152488
152489
152490
152491
152492
152493
152494
152495
152496
152497
152498
152499
152500
152501
152502
152503
152504
152505
152506
152507
152508
152509
152510
152511
152512
152513
152514
152515
152516
152517
152518
152519
152520
152521
152522
152523
152524
152525
152526
152527
152528
152529
152530
152531
152532
152533
152534
152535
152536
152537
152538
152539
152540
152541
152542
152543
152544
152545
152546
152547
152548
152549
152550
152551
152552
152553
152554
152555
152556
152557
152558
152559
152560
152561
152562
152563
152564
152565
152566
152567
152568
152569
152570



















































































































152571
152572
152573
152574
152575
152576
152577
152578
152579
152580
152581
152582

152583
152584
152585
152586
152587
152588
152589
153338
153339
153340
153341
153342
153343
153344















































































































153345
153346
153347
153348
153349
153350
153351
153352
153353
153354
153355
153356
153357
153358
153359
153360
153361
153362
153363
153364
153365
153366
153367
153368
153369
153370
153371
153372
153373
153374
153375
153376
153377
153378
153379
153380
153381
153382
153383
153384
153385
153386
153387
153388
153389
153390
153391
153392
153393
153394
153395
153396
153397
153398
153399
153400
153401
153402
153403
153404
153405
153406
153407
153408
153409
153410
153411
153412
153413
153414
153415
153416
153417
153418
153419
153420
153421
153422
153423
153424
153425
153426
153427
153428
153429
153430
153431
153432
153433
153434
153435
153436
153437
153438
153439
153440
153441
153442
153443
153444
153445
153446
153447
153448
153449
153450
153451
153452
153453
153454
153455
153456
153457
153458
153459
153460
153461
153462
153463
153464
153465
153466
153467
153468
153469
153470

153471
153472
153473
153474
153475
153476
153477
153478







-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+











-
+







      testcase( i==18 ); /* SELECT */
      testcase( i==19 ); /* TABLE */
      testcase( i==20 ); /* LEFT */
      testcase( i==21 ); /* THEN */
      testcase( i==22 ); /* END */
      testcase( i==23 ); /* DEFERRABLE */
      testcase( i==24 ); /* ELSE */
      testcase( i==25 ); /* EXCEPT */
      testcase( i==26 ); /* TRANSACTION */
      testcase( i==27 ); /* ACTION */
      testcase( i==28 ); /* ON */
      testcase( i==29 ); /* NATURAL */
      testcase( i==30 ); /* ALTER */
      testcase( i==31 ); /* RAISE */
      testcase( i==32 ); /* EXCLUSIVE */
      testcase( i==33 ); /* EXISTS */
      testcase( i==34 ); /* SAVEPOINT */
      testcase( i==35 ); /* INTERSECT */
      testcase( i==36 ); /* TRIGGER */
      testcase( i==37 ); /* REFERENCES */
      testcase( i==38 ); /* CONSTRAINT */
      testcase( i==39 ); /* INTO */
      testcase( i==40 ); /* OFFSET */
      testcase( i==41 ); /* OF */
      testcase( i==42 ); /* SET */
      testcase( i==43 ); /* TEMPORARY */
      testcase( i==44 ); /* TEMP */
      testcase( i==45 ); /* OR */
      testcase( i==46 ); /* UNIQUE */
      testcase( i==47 ); /* QUERY */
      testcase( i==48 ); /* WITHOUT */
      testcase( i==49 ); /* WITH */
      testcase( i==50 ); /* OUTER */
      testcase( i==51 ); /* RELEASE */
      testcase( i==52 ); /* ATTACH */
      testcase( i==53 ); /* HAVING */
      testcase( i==54 ); /* GROUP */
      testcase( i==55 ); /* UPDATE */
      testcase( i==56 ); /* BEGIN */
      testcase( i==57 ); /* INNER */
      testcase( i==58 ); /* RANGE */
      testcase( i==59 ); /* BETWEEN */
      testcase( i==60 ); /* NOTHING */
      testcase( i==61 ); /* GLOB */
      testcase( i==62 ); /* BY */
      testcase( i==63 ); /* CASCADE */
      testcase( i==64 ); /* ASC */
      testcase( i==65 ); /* DELETE */
      testcase( i==66 ); /* CASE */
      testcase( i==67 ); /* COLLATE */
      testcase( i==68 ); /* CREATE */
      testcase( i==69 ); /* CURRENT_DATE */
      testcase( i==70 ); /* DETACH */
      testcase( i==71 ); /* IMMEDIATE */
      testcase( i==72 ); /* JOIN */
      testcase( i==73 ); /* INSERT */
      testcase( i==74 ); /* LIKE */
      testcase( i==75 ); /* MATCH */
      testcase( i==76 ); /* PLAN */
      testcase( i==77 ); /* ANALYZE */
      testcase( i==78 ); /* PRAGMA */
      testcase( i==79 ); /* ABORT */
      testcase( i==80 ); /* VALUES */
      testcase( i==81 ); /* VIRTUAL */
      testcase( i==82 ); /* LIMIT */
      testcase( i==83 ); /* WHEN */
      testcase( i==84 ); /* NOTNULL */
      testcase( i==85 ); /* NOT */
      testcase( i==86 ); /* NO */
      testcase( i==87 ); /* NULL */
      testcase( i==88 ); /* WHERE */
      testcase( i==89 ); /* RECURSIVE */
      testcase( i==90 ); /* AFTER */
      testcase( i==91 ); /* RENAME */
      testcase( i==92 ); /* AND */
      testcase( i==93 ); /* DEFAULT */
      testcase( i==94 ); /* AUTOINCREMENT */
      testcase( i==95 ); /* TO */
      testcase( i==96 ); /* IN */
      testcase( i==97 ); /* CAST */
      testcase( i==98 ); /* COLUMN */
      testcase( i==99 ); /* COMMIT */
      testcase( i==100 ); /* CONFLICT */
      testcase( i==101 ); /* CROSS */
      testcase( i==102 ); /* CURRENT_TIMESTAMP */
      testcase( i==103 ); /* CURRENT_TIME */
      testcase( i==104 ); /* CURRENT */
      testcase( i==105 ); /* PARTITION */
      testcase( i==106 ); /* DEFERRED */
      testcase( i==107 ); /* DISTINCT */
      testcase( i==108 ); /* IS */
      testcase( i==109 ); /* DROP */
      testcase( i==110 ); /* PRECEDING */
      testcase( i==111 ); /* FAIL */
      testcase( i==112 ); /* FILTER */
      testcase( i==113 ); /* REPLACE */
      testcase( i==114 ); /* FOLLOWING */
      testcase( i==115 ); /* FROM */
      testcase( i==116 ); /* FULL */
      testcase( i==117 ); /* IF */
      testcase( i==118 ); /* ISNULL */
      testcase( i==119 ); /* ORDER */
      testcase( i==120 ); /* RESTRICT */
      testcase( i==121 ); /* OVER */
      testcase( i==122 ); /* RIGHT */
      testcase( i==123 ); /* ROLLBACK */
      testcase( i==124 ); /* ROWS */
      testcase( i==125 ); /* ROW */
      testcase( i==126 ); /* UNBOUNDED */
      testcase( i==127 ); /* UNION */
      testcase( i==128 ); /* USING */
      testcase( i==129 ); /* VACUUM */
      testcase( i==130 ); /* VIEW */
      testcase( i==131 ); /* WINDOW */
      testcase( i==132 ); /* DO */
      testcase( i==133 ); /* INITIALLY */
      testcase( i==134 ); /* ALL */
      testcase( i==135 ); /* PRIMARY */
      testcase( i==25 ); /* EXCLUDE */
      testcase( i==26 ); /* DELETE */
      testcase( i==27 ); /* TEMPORARY */
      testcase( i==28 ); /* TEMP */
      testcase( i==29 ); /* OR */
      testcase( i==30 ); /* CONSTRAINT */
      testcase( i==31 ); /* INTERSECT */
      testcase( i==32 ); /* TIES */
      testcase( i==33 ); /* SAVEPOINT */
      testcase( i==34 ); /* INTO */
      testcase( i==35 ); /* OFFSET */
      testcase( i==36 ); /* OF */
      testcase( i==37 ); /* SET */
      testcase( i==38 ); /* TRANSACTION */
      testcase( i==39 ); /* ACTION */
      testcase( i==40 ); /* ON */
      testcase( i==41 ); /* NATURAL */
      testcase( i==42 ); /* ALTER */
      testcase( i==43 ); /* RAISE */
      testcase( i==44 ); /* EXCEPT */
      testcase( i==45 ); /* TRIGGER */
      testcase( i==46 ); /* REFERENCES */
      testcase( i==47 ); /* UNIQUE */
      testcase( i==48 ); /* QUERY */
      testcase( i==49 ); /* WITHOUT */
      testcase( i==50 ); /* WITH */
      testcase( i==51 ); /* OUTER */
      testcase( i==52 ); /* RELEASE */
      testcase( i==53 ); /* EXCLUSIVE */
      testcase( i==54 ); /* EXISTS */
      testcase( i==55 ); /* ATTACH */
      testcase( i==56 ); /* HAVING */
      testcase( i==57 ); /* GLOB */
      testcase( i==58 ); /* BEGIN */
      testcase( i==59 ); /* INNER */
      testcase( i==60 ); /* RANGE */
      testcase( i==61 ); /* BETWEEN */
      testcase( i==62 ); /* NOTHING */
      testcase( i==63 ); /* GROUPS */
      testcase( i==64 ); /* GROUP */
      testcase( i==65 ); /* CASCADE */
      testcase( i==66 ); /* ASC */
      testcase( i==67 ); /* DETACH */
      testcase( i==68 ); /* CASE */
      testcase( i==69 ); /* COLLATE */
      testcase( i==70 ); /* CREATE */
      testcase( i==71 ); /* CURRENT_DATE */
      testcase( i==72 ); /* IMMEDIATE */
      testcase( i==73 ); /* JOIN */
      testcase( i==74 ); /* INSERT */
      testcase( i==75 ); /* LIKE */
      testcase( i==76 ); /* MATCH */
      testcase( i==77 ); /* PLAN */
      testcase( i==78 ); /* ANALYZE */
      testcase( i==79 ); /* PRAGMA */
      testcase( i==80 ); /* ABORT */
      testcase( i==81 ); /* UPDATE */
      testcase( i==82 ); /* VALUES */
      testcase( i==83 ); /* VIRTUAL */
      testcase( i==84 ); /* LIMIT */
      testcase( i==85 ); /* WHEN */
      testcase( i==86 ); /* NOTNULL */
      testcase( i==87 ); /* NOT */
      testcase( i==88 ); /* NO */
      testcase( i==89 ); /* NULL */
      testcase( i==90 ); /* WHERE */
      testcase( i==91 ); /* RECURSIVE */
      testcase( i==92 ); /* AFTER */
      testcase( i==93 ); /* RENAME */
      testcase( i==94 ); /* AND */
      testcase( i==95 ); /* DEFAULT */
      testcase( i==96 ); /* AUTOINCREMENT */
      testcase( i==97 ); /* TO */
      testcase( i==98 ); /* IN */
      testcase( i==99 ); /* CAST */
      testcase( i==100 ); /* COLUMN */
      testcase( i==101 ); /* COMMIT */
      testcase( i==102 ); /* CONFLICT */
      testcase( i==103 ); /* CROSS */
      testcase( i==104 ); /* CURRENT_TIMESTAMP */
      testcase( i==105 ); /* CURRENT_TIME */
      testcase( i==106 ); /* CURRENT */
      testcase( i==107 ); /* PARTITION */
      testcase( i==108 ); /* DEFERRED */
      testcase( i==109 ); /* DISTINCT */
      testcase( i==110 ); /* IS */
      testcase( i==111 ); /* DROP */
      testcase( i==112 ); /* PRECEDING */
      testcase( i==113 ); /* FAIL */
      testcase( i==114 ); /* FILTER */
      testcase( i==115 ); /* REPLACE */
      testcase( i==116 ); /* FOLLOWING */
      testcase( i==117 ); /* FROM */
      testcase( i==118 ); /* FULL */
      testcase( i==119 ); /* IF */
      testcase( i==120 ); /* ISNULL */
      testcase( i==121 ); /* ORDER */
      testcase( i==122 ); /* RESTRICT */
      testcase( i==123 ); /* OTHERS */
      testcase( i==124 ); /* OVER */
      testcase( i==125 ); /* RIGHT */
      testcase( i==126 ); /* ROLLBACK */
      testcase( i==127 ); /* ROWS */
      testcase( i==128 ); /* ROW */
      testcase( i==129 ); /* UNBOUNDED */
      testcase( i==130 ); /* UNION */
      testcase( i==131 ); /* USING */
      testcase( i==132 ); /* VACUUM */
      testcase( i==133 ); /* VIEW */
      testcase( i==134 ); /* WINDOW */
      testcase( i==135 ); /* DO */
      testcase( i==136 ); /* BY */
      testcase( i==137 ); /* INITIALLY */
      testcase( i==138 ); /* ALL */
      testcase( i==139 ); /* PRIMARY */
      *pType = aKWCode[i];
      break;
    }
  }
  return n;
}
SQLITE_PRIVATE int sqlite3KeywordCode(const unsigned char *z, int n){
  int id = TK_ID;
  keywordCode((char*)z, n, &id);
  return id;
}
#define SQLITE_N_KEYWORD 136
#define SQLITE_N_KEYWORD 140
SQLITE_API int sqlite3_keyword_name(int i,const char **pzName,int *pnName){
  if( i<0 || i>=SQLITE_N_KEYWORD ) return SQLITE_ERROR;
  *pzName = zKWText + aKWOffset[i];
  *pnName = aKWLen[i];
  return SQLITE_OK;
}
SQLITE_API int sqlite3_keyword_count(void){ return SQLITE_N_KEYWORD; }
153008
153009
153010
153011
153012
153013
153014

153015
153016
153017
153018
153019
153020
153021
153897
153898
153899
153900
153901
153902
153903
153904
153905
153906
153907
153908
153909
153910
153911







+







  int tokenType;                  /* type of the next token */
  int lastTokenParsed = -1;       /* type of the previous token */
  sqlite3 *db = pParse->db;       /* The database connection */
  int mxSqlLen;                   /* Max length of an SQL string */
#ifdef sqlite3Parser_ENGINEALWAYSONSTACK
  yyParser sEngine;    /* Space to hold the Lemon-generated Parser object */
#endif
  VVA_ONLY( u8 startedWithOom = db->mallocFailed );

  assert( zSql!=0 );
  mxSqlLen = db->aLimit[SQLITE_LIMIT_SQL_LENGTH];
  if( db->nVdbeActive==0 ){
    db->u1.isInterrupted = 0;
  }
  pParse->rc = SQLITE_OK;
153039
153040
153041
153042
153043
153044
153045


153046
153047
153048
153049
153050
153051
153052
153929
153930
153931
153932
153933
153934
153935
153936
153937
153938
153939
153940
153941
153942
153943
153944







+
+







    return SQLITE_NOMEM_BKPT;
  }
#endif
  assert( pParse->pNewTable==0 );
  assert( pParse->pNewTrigger==0 );
  assert( pParse->nVar==0 );
  assert( pParse->pVList==0 );
  pParse->pParentParse = db->pParse;
  db->pParse = pParse;
  while( 1 ){
    n = sqlite3GetToken((u8*)zSql, &tokenType);
    mxSqlLen -= n;
    if( mxSqlLen<0 ){
      pParse->rc = SQLITE_TOOBIG;
      break;
    }
153095
153096
153097
153098
153099
153100
153101

153102

153103
153104
153105
153106
153107
153108
153109
153987
153988
153989
153990
153991
153992
153993
153994

153995
153996
153997
153998
153999
154000
154001
154002







+
-
+







      }
    }
    pParse->sLastToken.z = zSql;
    pParse->sLastToken.n = n;
    sqlite3Parser(pEngine, tokenType, pParse->sLastToken);
    lastTokenParsed = tokenType;
    zSql += n;
    assert( db->mallocFailed==0 || pParse->rc!=SQLITE_OK || startedWithOom );
    if( pParse->rc!=SQLITE_OK || db->mallocFailed ) break;
    if( pParse->rc!=SQLITE_OK ) break;
  }
  assert( nErr==0 );
#ifdef YYTRACKMAXSTACKDEPTH
  sqlite3_mutex_enter(sqlite3MallocMutex());
  sqlite3StatusHighwater(SQLITE_STATUS_PARSER_STACK,
      sqlite3ParserStackPeak(pEngine)
  );
153163
153164
153165
153166
153167
153168
153169


153170
153171
153172
153173
153174
153175
153176
154056
154057
154058
154059
154060
154061
154062
154063
154064
154065
154066
154067
154068
154069
154070
154071







+
+







    sqlite3DbFreeNN(db, p);
  }
  while( pParse->pZombieTab ){
    Table *p = pParse->pZombieTab;
    pParse->pZombieTab = p->pNextZombie;
    sqlite3DeleteTable(db, p);
  }
  db->pParse = pParse->pParentParse;
  pParse->pParentParse = 0;
  assert( nErr==0 || pParse->rc!=SQLITE_OK );
  return nErr;
}


#ifdef SQLITE_ENABLE_NORMALIZE
/*
154537
154538
154539
154540
154541
154542
154543


154544
154545
154546
154547
154548
154549
154550
155432
155433
155434
155435
155436
155437
155438
155439
155440
155441
155442
155443
155444
155445
155446
155447







+
+







        { SQLITE_DBCONFIG_ENABLE_FTS3_TOKENIZER, SQLITE_Fts3Tokenizer  },
        { SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION, SQLITE_LoadExtension  },
        { SQLITE_DBCONFIG_NO_CKPT_ON_CLOSE,      SQLITE_NoCkptOnClose  },
        { SQLITE_DBCONFIG_ENABLE_QPSG,           SQLITE_EnableQPSG     },
        { SQLITE_DBCONFIG_TRIGGER_EQP,           SQLITE_TriggerEQP     },
        { SQLITE_DBCONFIG_RESET_DATABASE,        SQLITE_ResetDatabase  },
        { SQLITE_DBCONFIG_DEFENSIVE,             SQLITE_Defensive      },
        { SQLITE_DBCONFIG_WRITABLE_SCHEMA,       SQLITE_WriteSchema|
                                                 SQLITE_NoSchemaError  },
      };
      unsigned int i;
      rc = SQLITE_ERROR; /* IMP: R-42790-23372 */
      for(i=0; i<ArraySize(aFlagOp); i++){
        if( aFlagOp[i].op==op ){
          int onoff = va_arg(ap, int);
          int *pRes = va_arg(ap, int*);
161205
161206
161207
161208
161209
161210
161211
161212

161213
161214
161215
161216
161217
161218
161219
162102
162103
162104
162105
162106
162107
162108

162109
162110
162111
162112
162113
162114
162115
162116







-
+







    if( !isFirstTerm ){
      zCsr += fts3GetVarint32(zCsr, &nPrefix);
    }
    isFirstTerm = 0;
    zCsr += fts3GetVarint32(zCsr, &nSuffix);
    
    assert( nPrefix>=0 && nSuffix>=0 );
    if( nPrefix>zCsr-zNode || nSuffix>zEnd-zCsr ){
    if( nPrefix>zCsr-zNode || nSuffix>zEnd-zCsr || nSuffix==0 ){
      rc = FTS_CORRUPT_VTAB;
      goto finish_scan;
    }
    if( (i64)nPrefix+nSuffix>nAlloc ){
      char *zNew;
      nAlloc = ((i64)nPrefix+nSuffix) * 2;
      zNew = (char *)sqlite3_realloc64(zBuffer, nAlloc);
168318
168319
168320
168321
168322
168323
168324
168325

168326
168327
168328
168329
168330
168331
168332
169215
169216
169217
169218
169219
169220
169221

169222
169223
169224
169225
169226
169227
169228
169229







-
+








  pHash = (Fts3Hash *)sqlite3_user_data(context);

  zName = sqlite3_value_text(argv[0]);
  nName = sqlite3_value_bytes(argv[0])+1;

  if( argc==2 ){
    if( fts3TokenizerEnabled(context) ){
    if( fts3TokenizerEnabled(context) || sqlite3_value_frombind(argv[1]) ){
      void *pOld;
      int n = sqlite3_value_bytes(argv[1]);
      if( zName==0 || n!=sizeof(pPtr) ){
        sqlite3_result_error(context, "argument type mismatch", -1);
        return;
      }
      pPtr = *(void **)sqlite3_value_blob(argv[1]);
168345
168346
168347
168348
168349
168350
168351

168352


168353
168354
168355
168356
168357
168358
168359
169242
169243
169244
169245
169246
169247
169248
169249

169250
169251
169252
169253
169254
169255
169256
169257
169258







+
-
+
+







    if( !pPtr ){
      char *zErr = sqlite3_mprintf("unknown tokenizer: %s", zName);
      sqlite3_result_error(context, zErr, -1);
      sqlite3_free(zErr);
      return;
    }
  }
  if( fts3TokenizerEnabled(context) || sqlite3_value_frombind(argv[0]) ){
  sqlite3_result_blob(context, (void *)&pPtr, sizeof(pPtr), SQLITE_TRANSIENT);
    sqlite3_result_blob(context, (void *)&pPtr, sizeof(pPtr), SQLITE_TRANSIENT);
  }
}

SQLITE_PRIVATE int sqlite3Fts3IsIdChar(char c){
  static const char isFtsIdChar[] = {
      0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,  /* 0x */
      0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,  /* 1x */
      0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,  /* 2x */
170801
170802
170803
170804
170805
170806
170807

170808


170809
170810
170811
170812
170813
170814
170815
171700
171701
171702
171703
171704
171705
171706
171707

171708
171709
171710
171711
171712
171713
171714
171715
171716







+
-
+
+







      return SQLITE_OK;
    }

    fts3SegReaderSetEof(pReader);

    /* If iCurrentBlock>=iLeafEndBlock, this is an EOF condition. All leaf 
    ** blocks have already been traversed.  */
#ifdef CORRUPT_DB
    assert( pReader->iCurrentBlock<=pReader->iLeafEndBlock );
    assert( pReader->iCurrentBlock<=pReader->iLeafEndBlock || CORRUPT_DB );
#endif
    if( pReader->iCurrentBlock>=pReader->iLeafEndBlock ){
      return SQLITE_OK;
    }

    rc = sqlite3Fts3ReadBlock(
        p, ++pReader->iCurrentBlock, &pReader->aNode, &pReader->nNode, 
        (bIncr ? &pReader->nPopulate : 0)
172688
172689
172690
172691
172692
172693
172694
172695
172696




172697
172698
172699
172700
172701
172702
172703
173589
173590
173591
173592
173593
173594
173595


173596
173597
173598
173599
173600
173601
173602
173603
173604
173605
173606







-
-
+
+
+
+







    iNewLevel = getAbsoluteLevel(p, iLangid, iIndex, iLevel+1);
    rc = fts3AllocateSegdirIdx(p, iLangid, iIndex, iLevel+1, &iIdx);
    bIgnoreEmpty = (iLevel!=FTS3_SEGCURSOR_PENDING) && (iNewLevel>iMaxLevel);
  }
  if( rc!=SQLITE_OK ) goto finished;

  assert( csr.nSegment>0 );
  assert( iNewLevel>=getAbsoluteLevel(p, iLangid, iIndex, 0) );
  assert( iNewLevel<getAbsoluteLevel(p, iLangid, iIndex,FTS3_SEGDIR_MAXLEVEL) );
  assert_fts3_nc( iNewLevel>=getAbsoluteLevel(p, iLangid, iIndex, 0) );
  assert_fts3_nc( 
    iNewLevel<getAbsoluteLevel(p, iLangid, iIndex,FTS3_SEGDIR_MAXLEVEL) 
  );

  memset(&filter, 0, sizeof(Fts3SegFilter));
  filter.flags = FTS3_SEGMENT_REQUIRE_POS;
  filter.flags |= (bIgnoreEmpty ? FTS3_SEGMENT_IGNORE_EMPTY : 0);

  rc = sqlite3Fts3SegReaderStart(p, &csr, &filter);
  while( SQLITE_OK==rc ){
175594
175595
175596
175597
175598
175599
175600
175601

175602
175603
175604
175605
175606
175607
175608
176497
176498
176499
176500
176501
176502
176503

176504
176505
176506
176507
176508
176509
176510
176511







-
+








  for(i=0; i<pIter->nPhrase; i++){
    SnippetPhrase *pPhrase = &pIter->aPhrase[i];
    if( pPhrase->pTail ){
      char *pCsr = pPhrase->pTail;
      int iCsr = pPhrase->iTail;

      while( iCsr<(iStart+pIter->nSnippet) ){
      while( iCsr<(iStart+pIter->nSnippet) && iCsr>=iStart ){
        int j;
        u64 mPhrase = (u64)1 << i;
        u64 mPos = (u64)1 << (iCsr - iStart);
        assert( iCsr>=iStart && (iCsr - iStart)<=64 );
        assert( i>=0 && i<=64 );
        if( (mCover|mCovered)&mPhrase ){
          iScore++;
176708
176709
176710
176711
176712
176713
176714
176715

176716
176717
176718
176719
176720
176721
176722
177611
177612
177613
177614
177615
177616
177617

177618
177619
177620
177621
177622
177623
177624
177625







-
+







  int rc;

  UNUSED_PARAMETER(iPhrase);
  rc = sqlite3Fts3EvalPhrasePoslist(p->pCsr, pExpr, p->iCol, &pList);
  nTerm = pExpr->pPhrase->nToken;
  if( pList ){
    fts3GetDeltaPosition(&pList, &iPos);
    assert( iPos>=0 );
    assert_fts3_nc( iPos>=0 );
  }

  for(iTerm=0; iTerm<nTerm; iTerm++){
    TermOffset *pT = &p->aTerm[p->iTerm++];
    pT->iOff = nTerm-iTerm-1;
    pT->pList = pList;
    pT->iPos = iPos;
176818
176819
176820
176821
176822
176823
176824
176825

176826
176827
176828
176829
176830
176831
176832
177721
177722
177723
177724
177725
177726
177727

177728
177729
177730
177731
177732
177733
177734
177735







-
+







        }
      }

      if( !pTerm ){
        /* All offsets for this column have been gathered. */
        rc = SQLITE_DONE;
      }else{
        assert( iCurrent<=iMinPos );
        assert_fts3_nc( iCurrent<=iMinPos );
        if( 0==(0xFE&*pTerm->pList) ){
          pTerm->pList = 0;
        }else{
          fts3GetDeltaPosition(&pTerm->pList, &pTerm->iPos);
        }
        while( rc==SQLITE_OK && iCurrent<iMinPos ){
          rc = pMod->xNext(pC, &ZDUMMY, &NDUMMY, &iStart, &iEnd, &iCurrent);
183976
183977
183978
183979
183980
183981
183982
183983
183984
183985
183986



183987
183988
183989
183990
183991

183992
183993
183994



183995

183996
183997
183998
183999
184000
184001
184002

184003

184004
184005
184006
184007
184008

184009
184010
184011

184012
184013
184014
184015

184016
184017
184018
184019
184020
184021
184022

184023
184024
184025



184026
184027
184028
184029
184030
184031
184032
184879
184880
184881
184882
184883
184884
184885

184886
184887
184888
184889
184890
184891
184892
184893
184894
184895
184896
184897
184898
184899
184900
184901
184902
184903
184904
184905
184906


184907
184908
184909
184910
184911

184912

184913
184914


184915
184916


184917
184918

184919

184920







184921



184922
184923
184924
184925
184926
184927
184928
184929
184930
184931







-



+
+
+





+



+
+
+

+

-
-




+
-
+
-


-
-
+

-
-
+

-

-
+
-
-
-
-
-
-
-
+
-
-
-
+
+
+







**
** The human readable string takes the form of a Tcl list with one
** entry for each cell in the r-tree node. Each entry is itself a
** list, containing the 8-byte rowid/pageno followed by the 
** <num-dimension>*2 coordinates.
*/
static void rtreenode(sqlite3_context *ctx, int nArg, sqlite3_value **apArg){
  char *zText = 0;
  RtreeNode node;
  Rtree tree;
  int ii;
  int nData;
  int errCode;
  sqlite3_str *pOut;

  UNUSED_PARAMETER(nArg);
  memset(&node, 0, sizeof(RtreeNode));
  memset(&tree, 0, sizeof(Rtree));
  tree.nDim = (u8)sqlite3_value_int(apArg[0]);
  if( tree.nDim<1 || tree.nDim>5 ) return;
  tree.nDim2 = tree.nDim*2;
  tree.nBytesPerCell = 8 + 8 * tree.nDim;
  node.zData = (u8 *)sqlite3_value_blob(apArg[1]);
  nData = sqlite3_value_bytes(apArg[1]);
  if( nData<4 ) return;
  if( nData<NCELL(&node)*tree.nBytesPerCell ) return;

  pOut = sqlite3_str_new(0);
  for(ii=0; ii<NCELL(&node); ii++){
    char zCell[512];
    int nCell = 0;
    RtreeCell cell;
    int jj;

    nodeGetCell(&tree, &node, ii, &cell);
    if( ii>0 ) sqlite3_str_append(pOut, " ", 1);
    sqlite3_snprintf(512-nCell,&zCell[nCell],"%lld", cell.iRowid);
    sqlite3_str_appendf(pOut, "{%lld", cell.iRowid);
    nCell = (int)strlen(zCell);
    for(jj=0; jj<tree.nDim2; jj++){
#ifndef SQLITE_RTREE_INT_ONLY
      sqlite3_snprintf(512-nCell,&zCell[nCell], " %g",
                       (double)cell.aCoord[jj].f);
      sqlite3_str_appendf(pOut, " %g", (double)cell.aCoord[jj].f);
#else
      sqlite3_snprintf(512-nCell,&zCell[nCell], " %d",
                       cell.aCoord[jj].i);
      sqlite3_str_appendf(pOut, " %d", cell.aCoord[jj].i);
#endif
      nCell = (int)strlen(zCell);
    }

    sqlite3_str_append(pOut, "}", 1);
    if( zText ){
      char *zTextNew = sqlite3_mprintf("%s {%s}", zText, zCell);
      sqlite3_free(zText);
      zText = zTextNew;
    }else{
      zText = sqlite3_mprintf("{%s}", zCell);
    }
  }
  }
  
  sqlite3_result_text(ctx, zText, -1, sqlite3_free);
  errCode = sqlite3_str_errcode(pOut);
  sqlite3_result_text(ctx, sqlite3_str_finish(pOut), -1, sqlite3_free);
  sqlite3_result_error_code(ctx, errCode);
}

/* This routine implements an SQL function that returns the "depth" parameter
** from the front of a blob that is an r-tree node.  For example:
**
**     SELECT rtreedepth(data) FROM rt_node WHERE nodeno=1;
**
188618
188619
188620
188621
188622
188623
188624

188625
188626
188627
188628
188629
188630
188631
189517
189518
189519
189520
189521
189522
189523
189524
189525
189526
189527
189528
189529
189530
189531







+








  aOut = sqlite3_malloc(nOut+1);
  if( aOut==0 ){
    sqlite3_result_error_nomem(context);
  }else{
    nOut2 = rbuDeltaApply(aOrig, nOrig, aDelta, nDelta, aOut);
    if( nOut2!=nOut ){
      sqlite3_free(aOut);
      sqlite3_result_error(context, "corrupt fossil delta", -1);
    }else{
      sqlite3_result_blob(context, aOut, nOut, sqlite3_free);
    }
  }
}

197895
197896
197897
197898
197899
197900
197901
197902

197903
197904
197905
197906
197907
197908
197909
198795
198796
198797
198798
198799
198800
198801

198802
198803
198804
198805
198806
198807
198808
198809







-
+







    if( rc!=SQLITE_ROW ) rc = sqlite3_reset(pSelect);
  }

  return rc;
}

/*
** This function is called from within sqlite3changset_apply_v2() when
** This function is called from within sqlite3changeset_apply_v2() when
** a conflict is encountered and resolved using conflict resolution
** mode eType (either SQLITE_CHANGESET_OMIT or SQLITE_CHANGESET_REPLACE)..
** It adds a conflict resolution record to the buffer in 
** SessionApplyCtx.rebase, which will eventually be returned to the caller
** of apply_v2() as the "rebase" buffer.
**
** Return SQLITE_OK if successful, or an SQLite error code otherwise.
199677
199678
199679
199680
199681
199682
199683
199684

199685
199686
199687
199688
199689
199690
199691
199692
199693
199694
199695
199696
199697
199698
199699

199700
199701
199702
199703
199704
199705
199706
200577
200578
200579
200580
200581
200582
200583

200584
200585
200586
200587
200588
200589
200590
200591
200592
200593
200594
200595
200596
200597
200598

200599
200600
200601
200602
200603
200604
200605
200606







-
+














-
+







**
**
** xSetAuxdata(pFts5, pAux, xDelete)
**
**   Save the pointer passed as the second argument as the extension functions 
**   "auxiliary data". The pointer may then be retrieved by the current or any
**   future invocation of the same fts5 extension function made as part of
**   of the same MATCH query using the xGetAuxdata() API.
**   the same MATCH query using the xGetAuxdata() API.
**
**   Each extension function is allocated a single auxiliary data slot for
**   each FTS query (MATCH expression). If the extension function is invoked 
**   more than once for a single FTS query, then all invocations share a 
**   single auxiliary data context.
**
**   If there is already an auxiliary data pointer when this function is
**   invoked, then it is replaced by the new pointer. If an xDelete callback
**   was specified along with the original pointer, it is invoked at this
**   point.
**
**   The xDelete callback, if one is specified, is also invoked on the
**   auxiliary data pointer after the FTS5 query has finished.
**
**   If an error (e.g. an OOM condition) occurs within this function, an
**   If an error (e.g. an OOM condition) occurs within this function,
**   the auxiliary data is set to NULL and an error code returned. If the
**   xDelete parameter was not NULL, it is invoked on the auxiliary data
**   pointer before returning.
**
**
** xGetAuxdata(pFts5, bClear)
**
200674
200675
200676
200677
200678
200679
200680

200681
200682

200683
200684
200685
200686
200687
200688
200689
201574
201575
201576
201577
201578
201579
201580
201581
201582

201583
201584
201585
201586
201587
201588
201589
201590







+

-
+







/*
** Empty (but do not delete) a hash table.
*/
static void sqlite3Fts5HashClear(Fts5Hash*);

static int sqlite3Fts5HashQuery(
  Fts5Hash*,                      /* Hash table to query */
  int nPre,
  const char *pTerm, int nTerm,   /* Query term */
  const u8 **ppDoclist,           /* OUT: Pointer to doclist for pTerm */
  void **ppObj,                   /* OUT: Pointer to doclist for pTerm */
  int *pnDoclist                  /* OUT: Size of doclist in bytes */
);

static int sqlite3Fts5HashScanInit(
  Fts5Hash*,                      /* Hash table to query */
  const char *pTerm, int nTerm    /* Query prefix */
);
202745
202746
202747
202748
202749
202750
202751
202752

202753
202754
202755
202756
202757
202758
202759
203646
203647
203648
203649
203650
203651
203652

203653
203654
203655
203656
203657
203658
203659
203660







-
+







  }

  *pnScore = nScore;
  if( piPos ){
    sqlite3_int64 iAdj = iFirst - (nToken - (iLast-iFirst)) / 2;
    if( (iAdj+nToken)>nDocsize ) iAdj = nDocsize - nToken;
    if( iAdj<0 ) iAdj = 0;
    *piPos = iAdj;
    *piPos = (int)iAdj;
  }

  return rc;
}

/*
** Return the value in pVal interpreted as utf-8 text. Except, if pVal 
202973
202974
202975
202976
202977
202978
202979
202980

202981
202982
202983
202984
202985
202986
202987
203874
203875
203876
203877
203878
203879
203880

203881
203882
203883
203884
203885
203886
203887
203888







-
+







    /* Allocate the Fts5Bm25Data object */
    nPhrase = pApi->xPhraseCount(pFts);
    nByte = sizeof(Fts5Bm25Data) + nPhrase*2*sizeof(double);
    p = (Fts5Bm25Data*)sqlite3_malloc64(nByte);
    if( p==0 ){
      rc = SQLITE_NOMEM;
    }else{
      memset(p, 0, nByte);
      memset(p, 0, (size_t)nByte);
      p->nPhrase = nPhrase;
      p->aIDF = (double*)&p[1];
      p->aFreq = &p->aIDF[nPhrase];
    }

    /* Calculate the average document length for this FTS5 table */
    if( rc==SQLITE_OK ) rc = pApi->xRowCount(pFts, &nRow);
203136
203137
203138
203139
203140
203141
203142
203143

203144
203145
203146
203147
203148
203149
203150
204037
204038
204039
204040
204041
204042
204043

204044
204045
204046
204047
204048
204049
204050
204051







-
+







      nNew = nNew * 2;
    }
    pNew = sqlite3_realloc64(pBuf->p, nNew);
    if( pNew==0 ){
      *pRc = SQLITE_NOMEM;
      return 1;
    }else{
      pBuf->nSpace = nNew;
      pBuf->nSpace = (int)nNew;
      pBuf->p = pNew;
    }
  }
  return 0;
}


203360
203361
203362
203363
203364
203365
203366
203367

203368
203369
203370
203371
203372
203373
203374
204261
204262
204263
204264
204265
204266
204267

204268
204269
204270
204271
204272
204273
204274
204275







-
+







static void *sqlite3Fts5MallocZero(int *pRc, sqlite3_int64 nByte){
  void *pRet = 0;
  if( *pRc==SQLITE_OK ){
    pRet = sqlite3_malloc64(nByte);
    if( pRet==0 ){
      if( nByte>0 ) *pRc = SQLITE_NOMEM;
    }else{
      memset(pRet, 0, nByte);
      memset(pRet, 0, (size_t)nByte);
    }
  }
  return pRet;
}

/*
** Return a nul-terminated copy of the string indicated by pIn. If nIn
203829
203830
203831
203832
203833
203834
203835
203836

203837
203838
203839
203840
203841
203842
203843
204730
204731
204732
204733
204734
204735
204736

204737
204738
204739
204740
204741
204742
204743
204744







-
+







          }
        }
        if( p==0 ){
          *pzErr = sqlite3_mprintf("parse error in tokenize directive");
          rc = SQLITE_ERROR;
        }else{
          rc = sqlite3Fts5GetTokenizer(pGlobal, 
              (const char**)azArg, nArg, &pConfig->pTok, &pConfig->pTokApi,
              (const char**)azArg, (int)nArg, &pConfig->pTok, &pConfig->pTokApi,
              pzErr
          );
        }
      }
    }

    sqlite3_free(azArg);
203939
203940
203941
203942
203943
203944
203945
203946

203947
203948
203949
203950
203951
203952
203953
204840
204841
204842
204843
204844
204845
204846

204847
204848
204849
204850
204851
204852
204853
204854







-
+







  assert( *pRc==SQLITE_OK );
  *pbQuoted = 0;
  *pzOut = 0;

  if( zOut==0 ){
    *pRc = SQLITE_NOMEM;
  }else{
    memcpy(zOut, zIn, nIn+1);
    memcpy(zOut, zIn, (size_t)(nIn+1));
    if( fts5_isopenquote(zOut[0]) ){
      int ii = fts5Dequote(zOut);
      zRet = &zIn[ii];
      *pbQuoted = 1;
    }else{
      zRet = fts5ConfigSkipBareword(zIn);
      if( zRet ){
205953
205954
205955
205956
205957
205958
205959
205960

205961
205962
205963
205964
205965
205966
205967
206854
206855
206856
206857
206858
206859
206860

206861
206862
206863
206864
206865
206866
206867
206868







-
+







    if( pNear==0 ){
      sqlite3_int64 nByte;
      nByte = sizeof(Fts5ExprNearset) + SZALLOC * sizeof(Fts5ExprPhrase*);
      pRet = sqlite3_malloc64(nByte);
      if( pRet==0 ){
        pParse->rc = SQLITE_NOMEM;
      }else{
        memset(pRet, 0, nByte);
        memset(pRet, 0, (size_t)nByte);
      }
    }else if( (pNear->nPhrase % SZALLOC)==0 ){
      int nNew = pNear->nPhrase + SZALLOC;
      sqlite3_int64 nByte;

      nByte = sizeof(Fts5ExprNearset) + nNew * sizeof(Fts5ExprPhrase*);
      pRet = (Fts5ExprNearset*)sqlite3_realloc64(pNear, nByte);
206029
206030
206031
206032
206033
206034
206035
206036

206037
206038
206039
206040
206041
206042
206043
206930
206931
206932
206933
206934
206935
206936

206937
206938
206939
206940
206941
206942
206943
206944







-
+







  if( pPhrase && pPhrase->nTerm>0 && (tflags & FTS5_TOKEN_COLOCATED) ){
    Fts5ExprTerm *pSyn;
    sqlite3_int64 nByte = sizeof(Fts5ExprTerm) + sizeof(Fts5Buffer) + nToken+1;
    pSyn = (Fts5ExprTerm*)sqlite3_malloc64(nByte);
    if( pSyn==0 ){
      rc = SQLITE_NOMEM;
    }else{
      memset(pSyn, 0, nByte);
      memset(pSyn, 0, (size_t)nByte);
      pSyn->zTerm = ((char*)pSyn) + sizeof(Fts5ExprTerm) + sizeof(Fts5Buffer);
      memcpy(pSyn->zTerm, pToken, nToken);
      pSyn->pSynonym = pPhrase->aTerm[pPhrase->nTerm-1].pSynonym;
      pPhrase->aTerm[pPhrase->nTerm-1].pSynonym = pSyn;
    }
  }else{
    Fts5ExprTerm *pTerm;
206189
206190
206191
206192
206193
206194
206195
206196

206197
206198
206199
206200
206201
206202
206203
207090
207091
207092
207093
207094
207095
207096

207097
207098
207099
207100
207101
207102
207103
207104







-
+







    Fts5Colset *pColsetOrig = pOrig->pNode->pNear->pColset;
    if( pColsetOrig ){
      sqlite3_int64 nByte;
      Fts5Colset *pColset;
      nByte = sizeof(Fts5Colset) + (pColsetOrig->nCol-1) * sizeof(int);
      pColset = (Fts5Colset*)sqlite3Fts5MallocZero(&rc, nByte);
      if( pColset ){ 
        memcpy(pColset, pColsetOrig, nByte);
        memcpy(pColset, pColsetOrig, (size_t)nByte);
      }
      pNew->pRoot->pNear->pColset = pColset;
    }
  }

  if( pOrig->nTerm ){
    int i;                          /* Used to iterate through phrase terms */
206406
206407
206408
206409
206410
206411
206412
206413

206414
206415
206416
206417
206418
206419
206420
207307
207308
207309
207310
207311
207312
207313

207314
207315
207316
207317
207318
207319
207320
207321







-
+







*/
static Fts5Colset *fts5CloneColset(int *pRc, Fts5Colset *pOrig){
  Fts5Colset *pRet;
  if( pOrig ){
    sqlite3_int64 nByte = sizeof(Fts5Colset) + (pOrig->nCol-1) * sizeof(int);
    pRet = (Fts5Colset*)sqlite3Fts5MallocZero(pRc, nByte);
    if( pRet ){ 
      memcpy(pRet, pOrig, nByte);
      memcpy(pRet, pOrig, (size_t)nByte);
    }
  }else{
    pRet = 0;
  }
  return pRet;
}

207423
207424
207425
207426
207427
207428
207429
207430

207431
207432
207433
207434
207435
207436
207437
208324
208325
208326
208327
208328
208329
208330

208331
208332
208333
208334
208335
208336
208337
208338







-
+







    nByte = sizeof(Fts5HashEntry*) * pNew->nSlot;
    pNew->aSlot = (Fts5HashEntry**)sqlite3_malloc64(nByte);
    if( pNew->aSlot==0 ){
      sqlite3_free(pNew);
      *ppNew = 0;
      rc = SQLITE_NOMEM;
    }else{
      memset(pNew->aSlot, 0, nByte);
      memset(pNew->aSlot, 0, (size_t)nByte);
    }
  }
  return rc;
}

/*
** Free a hash table object.
207507
207508
207509
207510
207511
207512
207513
207514






207515
207516


207517
207518

207519
207520

207521
207522

207523
207524
207525
207526

207527
207528
207529
207530
207531
207532
207533
207534
207535
207536

207537
207538
207539


207540
207541
207542
207543







207544
207545
207546
207547
207548
207549
207550
208408
208409
208410
208411
208412
208413
208414

208415
208416
208417
208418
208419
208420
208421

208422
208423
208424

208425
208426

208427
208428

208429
208430
208431
208432

208433
208434
208435
208436
208437
208438
208439
208440
208441
208442

208443
208444
208445
208446
208447
208448




208449
208450
208451
208452
208453
208454
208455
208456
208457
208458
208459
208460
208461
208462







-
+
+
+
+
+
+

-
+
+

-
+

-
+

-
+



-
+









-
+



+
+
-
-
-
-
+
+
+
+
+
+
+








  sqlite3_free(apOld);
  pHash->nSlot = nNew;
  pHash->aSlot = apNew;
  return SQLITE_OK;
}

static void fts5HashAddPoslistSize(Fts5Hash *pHash, Fts5HashEntry *p){
static int fts5HashAddPoslistSize(
  Fts5Hash *pHash, 
  Fts5HashEntry *p,
  Fts5HashEntry *p2
){
  int nRet = 0;
  if( p->iSzPoslist ){
    u8 *pPtr = (u8*)p;
    u8 *pPtr = p2 ? (u8*)p2 : (u8*)p;
    int nData = p->nData;
    if( pHash->eDetail==FTS5_DETAIL_NONE ){
      assert( p->nData==p->iSzPoslist );
      assert( nData==p->iSzPoslist );
      if( p->bDel ){
        pPtr[p->nData++] = 0x00;
        pPtr[nData++] = 0x00;
        if( p->bContent ){
          pPtr[p->nData++] = 0x00;
          pPtr[nData++] = 0x00;
        }
      }
    }else{
      int nSz = (p->nData - p->iSzPoslist - 1);       /* Size in bytes */
      int nSz = (nData - p->iSzPoslist - 1);       /* Size in bytes */
      int nPos = nSz*2 + p->bDel;                     /* Value of nPos field */

      assert( p->bDel==0 || p->bDel==1 );
      if( nPos<=127 ){
        pPtr[p->iSzPoslist] = (u8)nPos;
      }else{
        int nByte = sqlite3Fts5GetVarintLen((u32)nPos);
        memmove(&pPtr[p->iSzPoslist + nByte], &pPtr[p->iSzPoslist + 1], nSz);
        sqlite3Fts5PutVarint(&pPtr[p->iSzPoslist], nPos);
        p->nData += (nByte-1);
        nData += (nByte-1);
      }
    }

    nRet = nData - p->nData;
    if( p2==0 ){
    p->iSzPoslist = 0;
    p->bDel = 0;
    p->bContent = 0;
  }
      p->iSzPoslist = 0;
      p->bDel = 0;
      p->bContent = 0;
      p->nData = nData;
    }
  }
  return nRet;
}

/*
** Add an entry to the in-memory hash table. The key is the concatenation
** of bByte and (pToken/nToken). The value is (iRowid/iCol/iPos).
**
**     (bByte || pToken) -> (iRowid,iCol,iPos)
207593
207594
207595
207596
207597
207598
207599
207600

207601
207602
207603
207604
207605
207606
207607
208505
208506
208507
208508
208509
208510
208511

208512
208513
208514
208515
208516
208517
208518
208519







-
+







      iHash = fts5HashKey2(pHash->nSlot, (u8)bByte, (const u8*)pToken, nToken);
    }

    /* Allocate new Fts5HashEntry and add it to the hash table. */
    p = (Fts5HashEntry*)sqlite3_malloc64(nByte);
    if( !p ) return SQLITE_NOMEM;
    memset(p, 0, sizeof(Fts5HashEntry));
    p->nAlloc = nByte;
    p->nAlloc = (int)nByte;
    zKey = fts5EntryKey(p);
    zKey[0] = bByte;
    memcpy(&zKey[1], pToken, nToken);
    assert( iHash==fts5HashKey(pHash->nSlot, (u8*)zKey, nToken+1) );
    p->nKey = nToken;
    zKey[nToken+1] = '\0';
    p->nData = nToken+1 + 1 + sizeof(Fts5HashEntry);
207648
207649
207650
207651
207652
207653
207654
207655

207656
207657
207658
207659
207660
207661
207662
208560
208561
208562
208563
208564
208565
208566

208567
208568
208569
208570
208571
208572
208573
208574







-
+







  assert( (p->nAlloc - p->nData) >= (9 + 4 + 1 + 3 + 5) );

  pPtr = (u8*)p;

  /* If this is a new rowid, append the 4-byte size field for the previous
  ** entry, and the new rowid for this entry.  */
  if( iRowid!=p->iRowid ){
    fts5HashAddPoslistSize(pHash, p);
    fts5HashAddPoslistSize(pHash, p, 0);
    p->nData += sqlite3Fts5PutVarint(&pPtr[p->nData], iRowid - p->iRowid);
    p->iRowid = iRowid;
    bNew = 1;
    p->iSzPoslist = p->nData;
    if( pHash->eDetail!=FTS5_DETAIL_NONE ){
      p->nData += 1;
      p->iCol = (pHash->eDetail==FTS5_DETAIL_FULL ? 0 : -1);
207765
207766
207767
207768
207769
207770
207771

207772


207773
207774
207775
207776
207777
207778
207779
208677
208678
208679
208680
208681
208682
208683
208684

208685
208686
208687
208688
208689
208690
208691
208692
208693







+
-
+
+







  ap = sqlite3_malloc64(sizeof(Fts5HashEntry*) * nMergeSlot);
  if( !ap ) return SQLITE_NOMEM;
  memset(ap, 0, sizeof(Fts5HashEntry*) * nMergeSlot);

  for(iSlot=0; iSlot<pHash->nSlot; iSlot++){
    Fts5HashEntry *pIter;
    for(pIter=pHash->aSlot[iSlot]; pIter; pIter=pIter->pHashNext){
      if( pTerm==0 
      if( pTerm==0 || 0==memcmp(fts5EntryKey(pIter), pTerm, nTerm) ){
       || (pIter->nKey+1>=nTerm && 0==memcmp(fts5EntryKey(pIter), pTerm, nTerm))
      ){
        Fts5HashEntry *pEntry = pIter;
        pEntry->pScanNext = 0;
        for(i=0; ap[i]; i++){
          pEntry = fts5HashEntryMerge(pEntry, ap[i]);
          ap[i] = 0;
        }
        ap[i] = pEntry;
207793
207794
207795
207796
207797
207798
207799

207800
207801

207802
207803
207804
207805
207806
207807
207808
207809
207810
207811
207812
207813
207814






207815
207816
207817






207818
207819

207820
207821
207822
207823
207824
207825
207826
208707
208708
208709
208710
208711
208712
208713
208714
208715

208716
208717
208718
208719
208720
208721
208722
208723
208724
208725
208726
208727
208728
208729
208730
208731
208732
208733
208734
208735



208736
208737
208738
208739
208740
208741
208742

208743
208744
208745
208746
208747
208748
208749
208750







+

-
+













+
+
+
+
+
+
-
-
-
+
+
+
+
+
+

-
+







}

/*
** Query the hash table for a doclist associated with term pTerm/nTerm.
*/
static int sqlite3Fts5HashQuery(
  Fts5Hash *pHash,                /* Hash table to query */
  int nPre,
  const char *pTerm, int nTerm,   /* Query term */
  const u8 **ppDoclist,           /* OUT: Pointer to doclist for pTerm */
  void **ppOut,                   /* OUT: Pointer to new object */
  int *pnDoclist                  /* OUT: Size of doclist in bytes */
){
  unsigned int iHash = fts5HashKey(pHash->nSlot, (const u8*)pTerm, nTerm);
  char *zKey = 0;
  Fts5HashEntry *p;

  for(p=pHash->aSlot[iHash]; p; p=p->pHashNext){
    zKey = fts5EntryKey(p);
    assert( p->nKey+1==(int)strlen(zKey) );
    if( nTerm==p->nKey+1 && memcmp(zKey, pTerm, nTerm)==0 ) break;
  }

  if( p ){
    int nHashPre = sizeof(Fts5HashEntry) + nTerm + 1;
    int nList = p->nData - nHashPre;
    u8 *pRet = (u8*)(*ppOut = sqlite3_malloc64(nPre + nList + 10));
    if( pRet ){
      Fts5HashEntry *pFaux = (Fts5HashEntry*)&pRet[nPre-nHashPre];
      memcpy(&pRet[nPre], &((u8*)p)[nHashPre], nList);
    fts5HashAddPoslistSize(pHash, p);
    *ppDoclist = (const u8*)&zKey[nTerm+1];
    *pnDoclist = p->nData - (sizeof(Fts5HashEntry) + nTerm + 1);
      nList += fts5HashAddPoslistSize(pHash, p, pFaux);
      *pnDoclist = nList;
    }else{
      *pnDoclist = 0;
      return SQLITE_NOMEM;
    }
  }else{
    *ppDoclist = 0;
    *ppOut = 0;
    *pnDoclist = 0;
  }

  return SQLITE_OK;
}

static int sqlite3Fts5HashScanInit(
207845
207846
207847
207848
207849
207850
207851
207852

207853
207854
207855
207856
207857
207858
207859
208769
208770
208771
208772
208773
208774
208775

208776
208777
208778
208779
208780
208781
208782
208783







-
+







  const u8 **ppDoclist,           /* OUT: pointer to doclist */
  int *pnDoclist                  /* OUT: size of doclist in bytes */
){
  Fts5HashEntry *p;
  if( (p = pHash->pScan) ){
    char *zKey = fts5EntryKey(p);
    int nTerm = (int)strlen(zKey);
    fts5HashAddPoslistSize(pHash, p);
    fts5HashAddPoslistSize(pHash, p, 0);
    *pzTerm = zKey;
    *ppDoclist = (const u8*)&zKey[nTerm+1];
    *pnDoclist = p->nData - (sizeof(Fts5HashEntry) + nTerm + 1);
  }else{
    *pzTerm = 0;
    *ppDoclist = 0;
    *pnDoclist = 0;
210315
210316
210317
210318
210319
210320
210321
210322
210323
210324
210325

210326
210327
210328
210329
210330


210331
210332
210333






210334
210335
210336






210337
210338

210339
210340
210341

210342
210343
210344
210345
210346
210347
210348
210349
210350
210351
210352
210353
211239
211240
211241
211242
211243
211244
211245

211246
211247
211248
211249
211250
211251
211252
211253
211254
211255
211256
211257
211258
211259
211260
211261
211262
211263
211264
211265
211266


211267
211268
211269
211270
211271
211272
211273
211274
211275
211276
211277

211278

211279



211280
211281
211282
211283
211284
211285
211286







-



+





+
+



+
+
+
+
+
+

-
-
+
+
+
+
+
+


+


-
+
-

-
-
-







*/
static void fts5SegIterHashInit(
  Fts5Index *p,                   /* FTS5 backend */
  const u8 *pTerm, int nTerm,     /* Term to seek to */
  int flags,                      /* Mask of FTS5INDEX_XXX flags */
  Fts5SegIter *pIter              /* Object to populate */
){
  const u8 *pList = 0;
  int nList = 0;
  const u8 *z = 0;
  int n = 0;
  Fts5Data *pLeaf = 0;

  assert( p->pHash );
  assert( p->rc==SQLITE_OK );

  if( pTerm==0 || (flags & FTS5INDEX_QUERY_SCAN) ){
    const u8 *pList = 0;

    p->rc = sqlite3Fts5HashScanInit(p->pHash, (const char*)pTerm, nTerm);
    sqlite3Fts5HashScanEntry(p->pHash, (const char**)&z, &pList, &nList);
    n = (z ? (int)strlen((const char*)z) : 0);
    if( pList ){
      pLeaf = fts5IdxMalloc(p, sizeof(Fts5Data));
      if( pLeaf ){
        pLeaf->p = (u8*)pList;
      }
    }
  }else{
    pIter->flags |= FTS5_SEGITER_ONETERM;
    sqlite3Fts5HashQuery(p->pHash, (const char*)pTerm, nTerm, &pList, &nList);
    p->rc = sqlite3Fts5HashQuery(p->pHash, sizeof(Fts5Data), 
        (const char*)pTerm, nTerm, (void**)&pLeaf, &nList
    );
    if( pLeaf ){
      pLeaf->p = (u8*)&pLeaf[1];
    }
    z = pTerm;
    n = nTerm;
    pIter->flags |= FTS5_SEGITER_ONETERM;
  }

  if( pList ){
  if( pLeaf ){
    Fts5Data *pLeaf;
    sqlite3Fts5BufferSet(&p->rc, &pIter->term, n, z);
    pLeaf = fts5IdxMalloc(p, sizeof(Fts5Data));
    if( pLeaf==0 ) return;
    pLeaf->p = (u8*)pList;
    pLeaf->nn = pLeaf->szLeaf = nList;
    pIter->pLeaf = pLeaf;
    pIter->iLeafOffset = fts5GetVarint(pLeaf->p, (u64*)&pIter->iRowid);
    pIter->iEndofDoclist = pLeaf->nn;

    if( flags & FTS5INDEX_QUERY_DESC ){
      pIter->flags |= FTS5_SEGITER_REVERSE;
210492
210493
210494
210495
210496
210497
210498
210499
210500


210501
210502
210503
210504
210505
210506
210507
211425
211426
211427
211428
211429
211430
211431


211432
211433
211434
211435
211436
211437
211438
211439
211440







-
-
+
+







  if( p1->pLeaf==0 ){           /* If p1 is at EOF */
    iRes = i2;
  }else if( p2->pLeaf==0 ){     /* If p2 is at EOF */
    iRes = i1;
  }else{
    int res = fts5BufferCompare(&p1->term, &p2->term);
    if( res==0 ){
      assert( i2>i1 );
      assert( i2!=0 );
      assert_nc( i2>i1 );
      assert_nc( i2!=0 );
      pRes->bTermEq = 1;
      if( p1->iRowid==p2->iRowid ){
        p1->bDel = p2->bDel;
        return i2;
      }
      res = ((p1->iRowid > p2->iRowid)==pIter->bRev) ? -1 : +1;
    }
212027
212028
212029
212030
212031
212032
212033
212034
212035



212036
212037
212038
212039
212040

212041
212042
212043
212044
212045
212046
212047
212960
212961
212962
212963
212964
212965
212966


212967
212968
212969
212970
212971
212972
212973

212974
212975
212976
212977
212978
212979
212980
212981







-
-
+
+
+




-
+







            /* Set the szLeaf field */
            fts5PutU16(&buf.p[2], (u16)buf.n);
          }

          /* Set up the new page-index array */
          fts5BufferAppendVarint(&p->rc, &buf, 4);
          if( pSeg->iLeafPgno==pSeg->iTermLeafPgno 
              && pSeg->iEndofDoclist<pData->szLeaf 
            ){
           && pSeg->iEndofDoclist<pData->szLeaf
           && pSeg->iPgidxOff<=pData->nn
          ){
            int nDiff = pData->szLeaf - pSeg->iEndofDoclist;
            fts5BufferAppendVarint(&p->rc, &buf, buf.n - 1 - nDiff - 4);
            fts5BufferAppendBlob(&p->rc, &buf, 
                pData->nn - pSeg->iPgidxOff, &pData->p[pSeg->iPgidxOff]
                );
            );
          }

          pSeg->pSeg->pgnoFirst = pSeg->iTermLeafPgno;
          fts5DataDelete(p, FTS5_SEGMENT_ROWID(iId, 1), iLeafRowid);
          fts5DataWrite(p, iLeafRowid, buf.p, buf.n);
        }
        fts5DataRelease(pData);
215055
215056
215057
215058
215059
215060
215061
215062

215063
215064
215065
215066
215067
215068
215069
215989
215990
215991
215992
215993
215994
215995

215996
215997
215998
215999
216000
216001
216002
216003







-
+








  rc = fts5NewTransaction(pTab);
  if( rc==SQLITE_OK ){
    nByte = sizeof(Fts5Cursor) + pConfig->nCol * sizeof(int);
    pCsr = (Fts5Cursor*)sqlite3_malloc64(nByte);
    if( pCsr ){
      Fts5Global *pGlobal = pTab->pGlobal;
      memset(pCsr, 0, nByte);
      memset(pCsr, 0, (size_t)nByte);
      pCsr->aColumnSize = (int*)&pCsr[1];
      pCsr->pNext = pGlobal->pCsr;
      pGlobal->pCsr = pCsr;
      pCsr->iCsrId = ++pGlobal->iNextId;
    }else{
      rc = SQLITE_NOMEM;
    }
215336
215337
215338
215339
215340
215341
215342
215343

215344
215345
215346
215347
215348
215349
215350
216270
216271
216272
216273
216274
216275
216276

216277
216278
216279
216280
216281
216282
216283
216284







-
+







  const char *zRank = pCsr->zRank;
  const char *zRankArgs = pCsr->zRankArgs;
  
  nPhrase = sqlite3Fts5ExprPhraseCount(pCsr->pExpr);
  nByte = sizeof(Fts5Sorter) + sizeof(int) * (nPhrase-1);
  pSorter = (Fts5Sorter*)sqlite3_malloc64(nByte);
  if( pSorter==0 ) return SQLITE_NOMEM;
  memset(pSorter, 0, nByte);
  memset(pSorter, 0, (size_t)nByte);
  pSorter->nIdx = nPhrase;

  /* TODO: It would be better to have some system for reusing statement
  ** handles here, rather than preparing a new one for each query. But that
  ** is not possible as SQLite reference counts the virtual table objects.
  ** And since the statement required here reads from this very virtual 
  ** table, saving it creates a circular reference.
217070
217071
217072
217073
217074
217075
217076
217077

217078
217079
217080
217081
217082
217083
217084
218004
218005
218006
218007
218008
218009
218010

218011
218012
218013
218014
218015
218016
218017
218018







-
+







static void fts5SourceIdFunc(
  sqlite3_context *pCtx,          /* Function call context */
  int nArg,                       /* Number of args */
  sqlite3_value **apUnused        /* Function arguments */
){
  assert( nArg==0 );
  UNUSED_PARAM2(nArg, apUnused);
  sqlite3_result_text(pCtx, "fts5: 2019-02-05 20:51:41 4d0a949fd92e19fbf243a2e3a1a7c2cdb111f9a6943949d2420dd846bc7d9285", -1, SQLITE_TRANSIENT);
  sqlite3_result_text(pCtx, "fts5: 2019-04-07 18:21:12 80704a16f6dbbeacc65fa36a3623df10292a28aeacf9e2c1d2891258479e3b89", -1, SQLITE_TRANSIENT);
}

/*
** Return true if zName is the extension on one of the shadow tables used
** by this module.
*/
static int fts5ShadowName(const char *zName){
217493
217494
217495
217496
217497
217498
217499
217500

217501
217502
217503
217504
217505
217506
217507
218427
218428
218429
218430
218431
218432
218433

218434
218435
218436
218437
218438
218439
218440
218441







-
+







  sqlite3_int64 nByte;            /* Bytes of space to allocate */

  nByte = sizeof(Fts5Storage)               /* Fts5Storage object */
        + pConfig->nCol * sizeof(i64);      /* Fts5Storage.aTotalSize[] */
  *pp = p = (Fts5Storage*)sqlite3_malloc64(nByte);
  if( !p ) return SQLITE_NOMEM;

  memset(p, 0, nByte);
  memset(p, 0, (size_t)nByte);
  p->aTotalSize = (i64*)&p[1];
  p->pConfig = pConfig;
  p->pIndex = pIndex;

  if( bCreate ){
    if( pConfig->eContent==FTS5_CONTENT_NORMAL ){
      int nDefn = 32 + pConfig->nCol*10;
220403
220404
220405
220406
220407
220408
220409
220410

220411
220412
220413
220414
220415
220416
220417
221337
221338
221339
221340
221341
221342
221343

221344
221345
221346
221347
221348
221349
221350
221351







-
+







static void sqlite3Fts5UnicodeAscii(u8 *aArray, u8 *aAscii){
  int i = 0;
  int iTbl = 0;
  while( i<128 ){
    int bToken = aArray[ aFts5UnicodeData[iTbl] & 0x1F ];
    int n = (aFts5UnicodeData[iTbl] >> 5) + i;
    for(; i<128 && i<n; i++){
      aAscii[i] = bToken;
      aAscii[i] = (u8)bToken;
    }
    iTbl++;
  }
}

/*
** 2015 May 30
221834
221835
221836
221837
221838
221839
221840
221841

221842
221843

221844
221845
221846
221847
221848
221849
221850
222768
222769
222770
222771
222772
222773
222774

222775
222776

222777
222778
222779
222780
222781
222782
222783
222784







-
+

-
+







#endif
  return rc;
}
#endif /* SQLITE_CORE */
#endif /* !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_STMTVTAB) */

/************** End of stmt.c ************************************************/
#if __LINE__!=221840
#if __LINE__!=222774
#undef SQLITE_SOURCE_ID
#define SQLITE_SOURCE_ID      "2019-02-05 20:51:41 4d0a949fd92e19fbf243a2e3a1a7c2cdb111f9a6943949d2420dd846bc7dalt2"
#define SQLITE_SOURCE_ID      "2019-04-09 01:26:31 8820408597341344b308277ce6ef41b47c7514d6c613520789b05ee52cbealt2"
#endif
/* Return the source-id for this library */
SQLITE_API const char *sqlite3_sourceid(void){ return SQLITE_SOURCE_ID; }
/************************** End of sqlite3.c ******************************/
#endif /* USE_SYSTEM_SQLITE */
/*
** 2001 September 15
221937
221938
221939
221940
221941
221942
221943








221944
221945
221946
221947
221948
221949
221950

221951
221952
221953
221954
221955
221956
221957
222871
222872
222873
222874
222875
222876
222877
222878
222879
222880
222881
222882
222883
222884
222885
222886
222887
222888
222889
222890
222891
222892
222893
222894
222895
222896
222897
222898
222899
222900







+
+
+
+
+
+
+
+







+








/* Forward declaration */
typedef struct SqliteDb SqliteDb;

/*
** New SQL functions can be created as TCL scripts.  Each such function
** is described by an instance of the following structure.
**
** Variable eType may be set to SQLITE_INTEGER, SQLITE_FLOAT, SQLITE_TEXT,
** SQLITE_BLOB or SQLITE_NULL. If it is SQLITE_NULL, then the implementation
** attempts to determine the type of the result based on the Tcl object.
** If it is SQLITE_TEXT or SQLITE_BLOB, then a text (sqlite3_result_text())
** or blob (sqlite3_result_blob()) is returned. If it is SQLITE_INTEGER
** or SQLITE_FLOAT, then an attempt is made to return an integer or float
** value, falling back to float and then text if this is not possible.
*/
typedef struct SqlFunc SqlFunc;
struct SqlFunc {
  Tcl_Interp *interp;   /* The TCL interpret to execute the function */
  Tcl_Obj *pScript;     /* The Tcl_Obj representation of the script */
  SqliteDb *pDb;        /* Database connection that owns this function */
  int useEvalObjv;      /* True if it is safe to use Tcl_EvalObjv */
  int eType;            /* Type of value to return */
  char *zName;          /* Name of this function */
  SqlFunc *pNext;       /* Next function on the list of them all */
};

/*
** New collation sequences function can be created as TCL scripts.  Each such
** function is described by an instance of the following structure.
221994
221995
221996
221997
221998
221999
222000

222001
222002
222003
222004
222005
222006
222007
222937
222938
222939
222940
222941
222942
222943
222944
222945
222946
222947
222948
222949
222950
222951







+







  Tcl_Interp *interp;        /* The interpreter used for this database */
  char *zBusy;               /* The busy callback routine */
  char *zCommit;             /* The commit hook callback routine */
  char *zTrace;              /* The trace callback routine */
  char *zTraceV2;            /* The trace_v2 callback routine */
  char *zProfile;            /* The profile callback routine */
  char *zProgress;           /* The progress callback routine */
  char *zBindFallback;       /* Callback to invoke on a binding miss */
  char *zAuth;               /* The authorization callback routine */
  int disableAuth;           /* Disable the authorizer if it exists */
  char *zNull;               /* Text to substitute for an SQL NULL value */
  SqlFunc *pFunc;            /* List of SQL functions */
  Tcl_Obj *pUpdateHook;      /* Update hook script (if any) */
  Tcl_Obj *pPreUpdateHook;   /* Pre-update hook script (if any) */
  Tcl_Obj *pRollbackHook;    /* Rollback hook script (if any) */
222384
222385
222386
222387
222388
222389
222390



222391
222392
222393
222394
222395
222396
222397
223328
223329
223330
223331
223332
223333
223334
223335
223336
223337
223338
223339
223340
223341
223342
223343
223344







+
+
+







  }
  if( pDb->zTraceV2 ){
    Tcl_Free(pDb->zTraceV2);
  }
  if( pDb->zProfile ){
    Tcl_Free(pDb->zProfile);
  }
  if( pDb->zBindFallback ){
    Tcl_Free(pDb->zBindFallback);
  }
  if( pDb->zAuth ){
    Tcl_Free(pDb->zAuth);
  }
  if( pDb->zNull ){
    Tcl_Free(pDb->zNull);
  }
  if( pDb->pUpdateHook ){
222839
222840
222841
222842
222843
222844
222845



222846
222847
222848
222849
222850




















222851
222852
222853






222854
222855
222856
222857








222858
222859
222860

222861
222862




222863
222864
222865
222866






222867
222868
222869
222870
222871
222872
222873
223786
223787
223788
223789
223790
223791
223792
223793
223794
223795





223796
223797
223798
223799
223800
223801
223802
223803
223804
223805
223806
223807
223808
223809
223810
223811
223812
223813
223814
223815



223816
223817
223818
223819
223820
223821




223822
223823
223824
223825
223826
223827
223828
223829



223830


223831
223832
223833
223834




223835
223836
223837
223838
223839
223840
223841
223842
223843
223844
223845
223846
223847







+
+
+
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
+
+
+
+
+
+
-
-
-
-
+
+
+
+
+
+
+
+
-
-
-
+
-
-
+
+
+
+
-
-
-
-
+
+
+
+
+
+







    sqlite3_result_error(context, Tcl_GetStringResult(p->interp), -1);
  }else{
    Tcl_Obj *pVar = Tcl_GetObjResult(p->interp);
    int n;
    u8 *data;
    const char *zType = (pVar->typePtr ? pVar->typePtr->name : "");
    char c = zType[0];
    int eType = p->eType;

    if( eType==SQLITE_NULL ){
    if( c=='b' && strcmp(zType,"bytearray")==0 && pVar->bytes==0 ){
      /* Only return a BLOB type if the Tcl variable is a bytearray and
      ** has no string representation. */
      data = Tcl_GetByteArrayFromObj(pVar, &n);
      sqlite3_result_blob(context, data, n, SQLITE_TRANSIENT);
      if( c=='b' && strcmp(zType,"bytearray")==0 && pVar->bytes==0 ){
        /* Only return a BLOB type if the Tcl variable is a bytearray and
        ** has no string representation. */
        eType = SQLITE_BLOB;
      }else if( (c=='b' && strcmp(zType,"boolean")==0)
             || (c=='w' && strcmp(zType,"wideInt")==0)
             || (c=='i' && strcmp(zType,"int")==0) 
      ){
        eType = SQLITE_INTEGER;
      }else if( c=='d' && strcmp(zType,"double")==0 ){
        eType = SQLITE_FLOAT;
      }else{
        eType = SQLITE_TEXT;
      }
    }

    switch( eType ){
      case SQLITE_BLOB: {
        data = Tcl_GetByteArrayFromObj(pVar, &n);
        sqlite3_result_blob(context, data, n, SQLITE_TRANSIENT);
    }else if( c=='b' && strcmp(zType,"boolean")==0 ){
      Tcl_GetIntFromObj(0, pVar, &n);
      sqlite3_result_int(context, n);
        break;
      }
      case SQLITE_INTEGER: {
        Tcl_WideInt v;
        if( TCL_OK==Tcl_GetWideIntFromObj(0, pVar, &v) ){
          sqlite3_result_int64(context, v);
    }else if( c=='d' && strcmp(zType,"double")==0 ){
      double r;
      Tcl_GetDoubleFromObj(0, pVar, &r);
      sqlite3_result_double(context, r);
          break;
        }
        /* fall-through */
      }
      case SQLITE_FLOAT: {
        double r;
        if( TCL_OK==Tcl_GetDoubleFromObj(0, pVar, &r) ){
          sqlite3_result_double(context, r);
    }else if( (c=='w' && strcmp(zType,"wideInt")==0) ||
          (c=='i' && strcmp(zType,"int")==0) ){
      Tcl_WideInt v;
          break;
      Tcl_GetWideIntFromObj(0, pVar, &v);
      sqlite3_result_int64(context, v);
        }
        /* fall-through */
      }
      default: {
    }else{
      data = (unsigned char *)Tcl_GetStringFromObj(pVar, &n);
      sqlite3_result_text(context, (char *)data, n, SQLITE_TRANSIENT);
    }
        data = (unsigned char *)Tcl_GetStringFromObj(pVar, &n);
        sqlite3_result_text(context, (char *)data, n, SQLITE_TRANSIENT);
        break;
      }
    }

  }
}

#ifndef SQLITE_OMIT_AUTHORIZATION
/*
** This is the authentication function.  It appends the authentication
** type code and the two arguments to zCmd[] then invokes the result
223109
223110
223111
223112
223113
223114
223115


223116
223117
223118
223119
223120
223121
223122
224083
224084
224085
224086
224087
224088
224089
224090
224091
224092
224093
224094
224095
224096
224097
224098







+
+







  sqlite3_stmt *pStmt = 0;        /* Prepared statement object */
  SqlPreparedStmt *pPreStmt;      /* Pointer to cached statement */
  int nSql;                       /* Length of zSql in bytes */
  int nVar = 0;                   /* Number of variables in statement */
  int iParm = 0;                  /* Next free entry in apParm */
  char c;
  int i;
  int needResultReset = 0;        /* Need to invoke Tcl_ResetResult() */
  int rc = SQLITE_OK;             /* Value to return */
  Tcl_Interp *interp = pDb->interp;

  *ppPreStmt = 0;

  /* Trim spaces from the start of zSql and calculate the remaining length. */
  while( (c = zSql[0])==' ' || c=='\t' || c=='\r' || c=='\n' ){ zSql++; }
  nSql = strlen30(zSql);
223196
223197
223198
223199
223200
223201
223202



















223203
223204
223205
223206
223207
223208
223209
224172
224173
224174
224175
224176
224177
224178
224179
224180
224181
224182
224183
224184
224185
224186
224187
224188
224189
224190
224191
224192
224193
224194
224195
224196
224197
224198
224199
224200
224201
224202
224203
224204







+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+







  assert( 0==memcmp(pPreStmt->zSql, zSql, pPreStmt->nSql) );

  /* Bind values to parameters that begin with $ or : */
  for(i=1; i<=nVar; i++){
    const char *zVar = sqlite3_bind_parameter_name(pStmt, i);
    if( zVar!=0 && (zVar[0]=='$' || zVar[0]==':' || zVar[0]=='@') ){
      Tcl_Obj *pVar = Tcl_GetVar2Ex(interp, &zVar[1], 0, 0);
      if( pVar==0 && pDb->zBindFallback!=0 ){
        Tcl_Obj *pCmd;
        int rx;
        pCmd = Tcl_NewStringObj(pDb->zBindFallback, -1);
        Tcl_IncrRefCount(pCmd);
        Tcl_ListObjAppendElement(interp, pCmd, Tcl_NewStringObj(zVar,-1));
        if( needResultReset ) Tcl_ResetResult(interp);
        needResultReset = 1;
        rx = Tcl_EvalObjEx(interp, pCmd, TCL_EVAL_DIRECT);
        Tcl_DecrRefCount(pCmd);
        if( rx==TCL_OK ){
          pVar = Tcl_GetObjResult(interp);
        }else if( rx==TCL_ERROR ){
          rc = TCL_ERROR;
          break;
        }else{
          pVar = 0;
        }
      }
      if( pVar ){
        int n;
        u8 *data;
        const char *zType = (pVar->typePtr ? pVar->typePtr->name : "");
        c = zType[0];
        if( zVar[0]=='@' ||
           (c=='b' && strcmp(zType,"bytearray")==0 && pVar->bytes==0) ){
223231
223232
223233
223234
223235
223236
223237

223238
223239
223240
223241

223242
223243

223244
223245
223246
223247
223248
223249
223250
224226
224227
224228
224229
224230
224231
224232
224233
224234
224235
224236
224237
224238
224239

224240
224241
224242
224243
224244
224245
224246
224247







+




+

-
+







          sqlite3_bind_text(pStmt, i, (char *)data, n, SQLITE_STATIC);
          Tcl_IncrRefCount(pVar);
          pPreStmt->apParm[iParm++] = pVar;
        }
      }else{
        sqlite3_bind_null(pStmt, i);
      }
      if( needResultReset ) Tcl_ResetResult(pDb->interp);
    }
  }
  pPreStmt->nParm = iParm;
  *ppPreStmt = pPreStmt;
  if( needResultReset && rc==TCL_OK ) Tcl_ResetResult(pDb->interp);

  return TCL_OK;
  return rc;
}

/*
** Release a statement reference obtained by calling dbPrepareAndBind().
** There should be exactly one call to this function for each call to
** dbPrepareAndBind().
**
223695
223696
223697
223698
223699
223700
223701
223702
223703
223704
223705
223706
223707
223708
223709
223710
223711
223712
223713
223714














223715
223716
223717
223718
223719
223720
223721
223722
223723
223724
223725
223726
223727
223728
223729
223730














223731
223732
223733
223734
223735
223736
223737
224692
224693
224694
224695
224696
224697
224698













224699
224700
224701
224702
224703
224704
224705
224706
224707
224708
224709
224710
224711
224712

224713
224714













224715
224716
224717
224718
224719
224720
224721
224722
224723
224724
224725
224726
224727
224728
224729
224730
224731
224732
224733
224734
224735







-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-


-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+







  int objc,
  Tcl_Obj *const*objv
){
  SqliteDb *pDb = (SqliteDb*)cd;
  int choice;
  int rc = TCL_OK;
  static const char *DB_strs[] = {
    "authorizer",             "backup",                "busy",
    "cache",                  "changes",               "close",
    "collate",                "collation_needed",      "commit_hook",
    "complete",               "copy",                  "deserialize",
    "enable_load_extension",  "errorcode",             "eval",
    "exists",                 "function",              "incrblob",
    "interrupt",              "last_insert_rowid",     "nullvalue",
    "onecolumn",              "preupdate",             "profile",
    "progress",               "rekey",                 "restore",
    "rollback_hook",          "serialize",             "status",
    "timeout",                "total_changes",         "trace",
    "trace_v2",               "transaction",           "unlock_notify",
    "update_hook",            "version",               "wal_hook",
    "authorizer",             "backup",                "bind_fallback",
    "busy",                   "cache",                 "changes",
    "close",                  "collate",               "collation_needed",
    "commit_hook",            "complete",              "copy",
    "deserialize",            "enable_load_extension", "errorcode",
    "eval",                   "exists",                "function",
    "incrblob",               "interrupt",             "last_insert_rowid",
    "nullvalue",              "onecolumn",             "preupdate",
    "profile",                "progress",              "rekey",
    "restore",                "rollback_hook",         "serialize",
    "status",                 "timeout",               "total_changes",
    "trace",                  "trace_v2",              "transaction",
    "unlock_notify",          "update_hook",           "version",
    "wal_hook",               0                        
    0                        
  };
  enum DB_enum {
    DB_AUTHORIZER,            DB_BACKUP,               DB_BUSY,
    DB_CACHE,                 DB_CHANGES,              DB_CLOSE,
    DB_COLLATE,               DB_COLLATION_NEEDED,     DB_COMMIT_HOOK,
    DB_COMPLETE,              DB_COPY,                 DB_DESERIALIZE,
    DB_ENABLE_LOAD_EXTENSION, DB_ERRORCODE,            DB_EVAL,
    DB_EXISTS,                DB_FUNCTION,             DB_INCRBLOB,
    DB_INTERRUPT,             DB_LAST_INSERT_ROWID,    DB_NULLVALUE,
    DB_ONECOLUMN,             DB_PREUPDATE,            DB_PROFILE,
    DB_PROGRESS,              DB_REKEY,                DB_RESTORE,
    DB_ROLLBACK_HOOK,         DB_SERIALIZE,            DB_STATUS,
    DB_TIMEOUT,               DB_TOTAL_CHANGES,        DB_TRACE,
    DB_TRACE_V2,              DB_TRANSACTION,          DB_UNLOCK_NOTIFY,
    DB_UPDATE_HOOK,           DB_VERSION,              DB_WAL_HOOK
    DB_AUTHORIZER,            DB_BACKUP,               DB_BIND_FALLBACK,
    DB_BUSY,                  DB_CACHE,                DB_CHANGES,
    DB_CLOSE,                 DB_COLLATE,              DB_COLLATION_NEEDED,
    DB_COMMIT_HOOK,           DB_COMPLETE,             DB_COPY,
    DB_DESERIALIZE,           DB_ENABLE_LOAD_EXTENSION,DB_ERRORCODE,
    DB_EVAL,                  DB_EXISTS,               DB_FUNCTION,
    DB_INCRBLOB,              DB_INTERRUPT,            DB_LAST_INSERT_ROWID,
    DB_NULLVALUE,             DB_ONECOLUMN,            DB_PREUPDATE,
    DB_PROFILE,               DB_PROGRESS,             DB_REKEY,
    DB_RESTORE,               DB_ROLLBACK_HOOK,        DB_SERIALIZE,
    DB_STATUS,                DB_TIMEOUT,              DB_TOTAL_CHANGES,
    DB_TRACE,                 DB_TRACE_V2,             DB_TRANSACTION,
    DB_UNLOCK_NOTIFY,         DB_UPDATE_HOOK,          DB_VERSION,
    DB_WAL_HOOK             
  };
  /* don't leave trailing commas on DB_enum, it confuses the AIX xlc compiler */

  if( objc<2 ){
    Tcl_WrongNumArgs(interp, 1, objv, "SUBCOMMAND ...");
    return TCL_ERROR;
  }
223844
223845
223846
223847
223848
223849
223850











































223851
223852
223853
223854
223855
223856
223857
224842
224843
224844
224845
224846
224847
224848
224849
224850
224851
224852
224853
224854
224855
224856
224857
224858
224859
224860
224861
224862
224863
224864
224865
224866
224867
224868
224869
224870
224871
224872
224873
224874
224875
224876
224877
224878
224879
224880
224881
224882
224883
224884
224885
224886
224887
224888
224889
224890
224891
224892
224893
224894
224895
224896
224897
224898







+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+







      Tcl_AppendResult(interp, "backup failed: ",
           sqlite3_errmsg(pDest), (char*)0);
      rc = TCL_ERROR;
    }
    sqlite3_close(pDest);
    break;
  }

  /*    $db bind_fallback ?CALLBACK?
  **
  ** When resolving bind parameters in an SQL statement, if the parameter
  ** cannot be associated with a TCL variable then invoke CALLBACK with a
  ** single argument that is the name of the parameter and use the return
  ** value of the CALLBACK as the binding.  If CALLBACK returns something
  ** other than TCL_OK or TCL_ERROR then bind a NULL.
  **
  ** If CALLBACK is an empty string, then revert to the default behavior 
  ** which is to set the binding to NULL.
  **
  ** If CALLBACK returns an error, that causes the statement execution to
  ** abort.  Hence, to configure a connection so that it throws an error
  ** on an attempt to bind an unknown variable, do something like this:
  **
  **     proc bind_error {name} {error "no such variable: $name"}
  **     db bind_fallback bind_error
  */
  case DB_BIND_FALLBACK: {
    if( objc>3 ){
      Tcl_WrongNumArgs(interp, 2, objv, "?CALLBACK?");
      return TCL_ERROR;
    }else if( objc==2 ){
      if( pDb->zBindFallback ){
        Tcl_AppendResult(interp, pDb->zBindFallback, (char*)0);
      }
    }else{
      char *zCallback;
      int len;
      if( pDb->zBindFallback ){
        Tcl_Free(pDb->zBindFallback);
      }
      zCallback = Tcl_GetStringFromObj(objv[2], &len);
      if( zCallback && len>0 ){
        pDb->zBindFallback = Tcl_Alloc( len + 1 );
        memcpy(pDb->zBindFallback, zCallback, len+1);
      }else{
        pDb->zBindFallback = 0;
      }
    }
    break;
  }

  /*    $db busy ?CALLBACK?
  **
  ** Invoke the given callback if an SQL statement attempts to open
  ** a locked database file.
  */
  case DB_BUSY: {
224490
224491
224492
224493
224494
224495
224496

224497
224498
224499
224500
224501
224502
224503
224504

224505
224506
224507
224508
224509
224510
224511
224512
224513
224514
224515
224516
224517

224518














224519
224520
224521

224522
224523
224524
224525
224526
224527
224528
224529
224530
224531
224532
224533
224534
224535
224536

224537
224538
224539
224540
224541
224542
224543
225531
225532
225533
225534
225535
225536
225537
225538
225539
225540
225541
225542
225543
225544
225545

225546
225547
225548
225549
225550
225551
225552
225553
225554
225555
225556
225557
225558

225559
225560
225561
225562
225563
225564
225565
225566
225567
225568
225569
225570
225571
225572
225573
225574
225575
225576

225577
225578
225579
225580
225581
225582
225583
225584
225585
225586
225587
225588
225589
225590
225591
225592
225593
225594
225595
225596
225597
225598
225599
225600







+







-
+












-
+

+
+
+
+
+
+
+
+
+
+
+
+
+
+


-
+















+







  case DB_FUNCTION: {
    int flags = SQLITE_UTF8;
    SqlFunc *pFunc;
    Tcl_Obj *pScript;
    char *zName;
    int nArg = -1;
    int i;
    int eType = SQLITE_NULL;
    if( objc<4 ){
      Tcl_WrongNumArgs(interp, 2, objv, "NAME ?SWITCHES? SCRIPT");
      return TCL_ERROR;
    }
    for(i=3; i<(objc-1); i++){
      const char *z = Tcl_GetString(objv[i]);
      int n = strlen30(z);
      if( n>2 && strncmp(z, "-argcount",n)==0 ){
      if( n>1 && strncmp(z, "-argcount",n)==0 ){
        if( i==(objc-2) ){
          Tcl_AppendResult(interp, "option requires an argument: ", z,(char*)0);
          return TCL_ERROR;
        }
        if( Tcl_GetIntFromObj(interp, objv[i+1], &nArg) ) return TCL_ERROR;
        if( nArg<0 ){
          Tcl_AppendResult(interp, "number of arguments must be non-negative",
                           (char*)0);
          return TCL_ERROR;
        }
        i++;
      }else
      if( n>2 && strncmp(z, "-deterministic",n)==0 ){
      if( n>1 && strncmp(z, "-deterministic",n)==0 ){
        flags |= SQLITE_DETERMINISTIC;
      }else
      if( n>1 && strncmp(z, "-returntype", n)==0 ){
        const char *azType[] = {"integer", "real", "text", "blob", "any", 0};
        assert( SQLITE_INTEGER==1 && SQLITE_FLOAT==2 && SQLITE_TEXT==3 );
        assert( SQLITE_BLOB==4 && SQLITE_NULL==5 );
        if( i==(objc-2) ){
          Tcl_AppendResult(interp, "option requires an argument: ", z,(char*)0);
          return TCL_ERROR;
        }
        i++;
        if( Tcl_GetIndexFromObj(interp, objv[i], azType, "type", 0, &eType) ){
          return TCL_ERROR;
        }
        eType++;
      }else{
        Tcl_AppendResult(interp, "bad option \"", z,
            "\": must be -argcount or -deterministic", (char*)0
            "\": must be -argcount, -deterministic or -returntype", (char*)0
        );
        return TCL_ERROR;
      }
    }

    pScript = objv[objc-1];
    zName = Tcl_GetStringFromObj(objv[2], 0);
    pFunc = findSqlFunc(pDb, zName);
    if( pFunc==0 ) return TCL_ERROR;
    if( pFunc->pScript ){
      Tcl_DecrRefCount(pFunc->pScript);
    }
    pFunc->pScript = pScript;
    Tcl_IncrRefCount(pScript);
    pFunc->useEvalObjv = safeToUseEvalObjv(interp, pScript);
    pFunc->eType = eType;
    rc = sqlite3_create_function(pDb->db, zName, nArg, flags,
        pFunc, tclSqlFunc, 0, 0);
    if( rc!=SQLITE_OK ){
      rc = TCL_ERROR;
      Tcl_SetResult(interp, (char *)sqlite3_errmsg(pDb->db), TCL_VOLATILE);
    }
    break;