Fossil

Check-in [8af8232f]
Login

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

Overview
Comment:merge in latest trunk
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | hide-diff-on-vdiff_page
Files: files | file ages | folders
SHA1:8af8232fc07bb5844c5092bb13e5b1107950eb9e
User & Date: mgagnon 2013-11-22 01:09:09
Context
2013-11-22
01:14
Merge in hide-diff-on-vdiff_page...

Which now give possibility to hide or show full detailed diff on vdiff page. (when clicking on 2 nodes on timeline) Just like the /info page. check-in: 74a4db25 user: mgagnon tags: trunk

01:09
merge in latest trunk Closed-Leaf check-in: 8af8232f user: mgagnon tags: hide-diff-on-vdiff_page
2013-11-21
23:39
Update to the lastest SQLite that includes the OP_Column rewrite and the constant expression factoring logic. check-in: 8dc9d009 user: drh tags: trunk
01:47
Merge in latest from trunk. check-in: e2929a4b user: andybradford tags: hide-diff-on-vdiff_page
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to src/shell.c.

1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
        if( zExplain && zExplain[0] ){
          fprintf(pArg->out, "%s", zExplain);
        }
      }

      /* If the shell is currently in ".explain" mode, gather the extra
      ** data required to add indents to the output.*/
      if( pArg->mode==MODE_Explain ){
        explain_data_prepare(pArg, pStmt);
      }

      /* perform the first step.  this will tell us if we
      ** have a result set or not and how wide it is.
      */
      rc = sqlite3_step(pStmt);







|







1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
        if( zExplain && zExplain[0] ){
          fprintf(pArg->out, "%s", zExplain);
        }
      }

      /* If the shell is currently in ".explain" mode, gather the extra
      ** data required to add indents to the output.*/
      if( pArg && pArg->mode==MODE_Explain ){
        explain_data_prepare(pArg, pStmt);
      }

      /* perform the first step.  this will tell us if we
      ** have a result set or not and how wide it is.
      */
      rc = sqlite3_step(pStmt);

Changes to src/sqlite3.c.

133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
....
8138
8139
8140
8141
8142
8143
8144
8145
8146
8147
8148
8149
8150
8151
8152
8153
8154
....
8776
8777
8778
8779
8780
8781
8782
8783
8784
8785
8786
8787
8788
8789
8790
8791
....
9019
9020
9021
9022
9023
9024
9025


9026
9027
9028
9029
9030
9031
9032
9033
9034
9035
9036

9037
9038
9039
9040
9041
9042
9043
9044
9045
9046
9047
9048
9049
9050
9051
9052
9053
9054
9055
9056
9057
9058
9059
9060
9061
9062
9063
9064
9065
9066
9067
9068
9069
9070
9071
9072
9073
9074
9075
9076
9077
9078
9079
9080
9081
9082
9083
9084
9085
9086
9087
9088
9089
9090


9091
9092
9093
9094
9095
9096
9097
9098
9099
9100
9101
9102
9103
9104
9105
9106
9107
9108
9109
9110
9111
9112
9113
9114
9115


9116
9117
9118
9119
9120
9121
9122
9123
9124
9125
9126
9127
9128
9129
9130
9131
9132
9133
9134
9135
9136
9137
9138
9139
9140
9141
9142
9143
9144
9145
9146
9147
9148

9149
9150
9151
9152
9153
9154
9155
9156
9157
9158
9159
9160
9161
9162
9163
9164
9165
9166


9167
9168
9169
9170
9171
9172
9173
9174
9175
9176
9177
....
9179
9180
9181
9182
9183
9184
9185
9186
9187
9188
9189
9190
9191
9192
9193
9194
9195
9196
9197
9198
9199
9200
9201
9202
9203

9204
9205
9206
9207
9208
9209
9210
.....
10334
10335
10336
10337
10338
10339
10340







10341
10342
10343
10344
10345
10346
10347
.....
10400
10401
10402
10403
10404
10405
10406

10407
10408
10409
10410
10411
10412
10413
10414
10415
10416
10417
10418



10419
10420
10421
10422
10423
10424
10425
.....
10427
10428
10429
10430
10431
10432
10433



10434
10435
10436
10437
10438
10439
10440
10441
10442

10443
10444
10445
10446
10447
10448
10449
10450
.....
11096
11097
11098
11099
11100
11101
11102

11103
11104
11105
11106
11107
11108
11109
.....
11157
11158
11159
11160
11161
11162
11163

11164
11165
11166
11167
11168
11169
11170
.....
12151
12152
12153
12154
12155
12156
12157

12158
12159
12160
12161


12162
12163
12164
12165
12166
12167
12168
.....
13384
13385
13386
13387
13388
13389
13390
13391
13392
13393
13394
13395
13396
13397
13398
.....
13401
13402
13403
13404
13405
13406
13407



13408
13409
13410
13411
13412
13413
13414
13415
13416
13417
13418
13419
13420
13421
13422
13423

13424

13425
13426
13427
13428
13429
13430
13431
13432
13433
13434
13435
13436
13437
13438
13439
13440
13441
13442
13443
13444
13445
13446
13447
13448
13449
13450
13451
13452
13453




13454
13455
13456
13457
13458
13459
13460
.....
13771
13772
13773
13774
13775
13776
13777
13778
13779
13780
13781
13782
13783
13784
13785
.....
22899
22900
22901
22902
22903
22904
22905


22906
22907
22908
22909
22910
22911
22912
22913
22914
22915
22916

22917
22918
22919
22920
22921
22922
22923
22924
22925
22926
22927
22928
22929
22930
22931
22932
22933
22934
22935
22936
22937
22938
22939
22940
22941
22942
22943
22944
22945
22946
22947
22948
22949
22950
22951
22952
22953
22954
22955
22956
22957
22958
22959
22960
22961
22962
22963
22964
22965
22966
22967
22968
22969
22970


22971
22972
22973
22974
22975
22976
22977
22978
22979
22980
22981
22982
22983
22984
22985
22986
22987
22988
22989
22990
22991
22992
22993
22994
22995


22996
22997
22998
22999
23000
23001
23002
23003
23004
23005
23006
23007
23008
23009
23010
23011
23012
23013
23014
23015
23016
23017
23018
23019
23020
23021
23022
23023
23024
23025
23026
23027
23028

23029
23030
23031
23032
23033
23034
23035
23036
23037
23038
23039
23040
23041
23042
23043
23044
23045
23046


23047
23048
23049
23050
23051
23052
23053
23054
23055
23056
23057
.....
54456
54457
54458
54459
54460
54461
54462
54463
54464
54465
54466
54467
54468
54469
54470
.....
54506
54507
54508
54509
54510
54511
54512
54513
54514
54515
54516
54517
54518
54519
54520
54521
54522
54523
54524
54525
54526
54527
54528
54529
.....
60418
60419
60420
60421
60422
60423
60424
60425
60426
60427
60428
60429
60430
60431
60432
60433
60434
60435
60436
60437
60438
.....
60439
60440
60441
60442
60443
60444
60445
60446
60447
60448
60449
60450
60451
60452
60453
.....
60458
60459
60460
60461
60462
60463
60464
60465
60466
60467
60468
60469
60470
60471
60472
.....
61389
61390
61391
61392
61393
61394
61395

61396
61397
61398
61399
61400
61401

61402
61403
61404
61405
61406
61407
61408
.....
62610
62611
62612
62613
62614
62615
62616
62617
62618
62619
62620
62621
62622
62623
62624
.....
63594
63595
63596
63597
63598
63599
63600
63601
63602
63603
63604
63605
63606
63607
63608
.....
64139
64140
64141
64142
64143
64144
64145
64146
64147
64148
64149
64150
64151
64152
64153
.....
64217
64218
64219
64220
64221
64222
64223
64224
64225
64226
64227
64228
64229
64230
64231
.....
66152
66153
66154
66155
66156
66157
66158
66159
66160
66161
66162
66163
66164
66165
66166
66167
66168
66169
66170
66171
66172
66173
66174
66175
66176
66177
66178
66179
66180
66181
66182
66183
66184
66185
.....
66667
66668
66669
66670
66671
66672
66673
66674
66675
66676
66677
66678
66679
66680
66681
66682
66683
66684
66685
66686
66687
66688
66689


66690
66691
66692
66693
66694
66695
66696
66697
66698
66699
66700
66701
.....
66850
66851
66852
66853
66854
66855
66856
66857
66858
66859
66860
66861
66862
66863
66864
.....
67551
67552
67553
67554
67555
67556
67557
67558
67559
67560
67561
67562
67563
67564
67565
67566
67567
67568
67569
67570
67571
67572
67573
.....
67576
67577
67578
67579
67580
67581
67582
67583
67584
67585
67586
67587
67588
67589
67590
.....
67967
67968
67969
67970
67971
67972
67973
67974
67975
67976
67977
67978
67979
67980
67981
67982
67983
67984
67985



67986
67987
67988
67989
67990
67991
67992
.....
68013
68014
68015
68016
68017
68018
68019

68020
68021
68022
68023
68024
68025
68026
68027
.....
68140
68141
68142
68143
68144
68145
68146

68147
68148
68149
68150
68151
68152
68153

68154
68155
68156
68157


68158
68159
68160
68161
68162
68163
68164
.....
68738
68739
68740
68741
68742
68743
68744
68745
68746
68747
68748
68749
68750
68751
68752
68753
68754
68755
68756
68757
68758
68759
68760


68761
68762
68763
68764
68765
68766
68767
68768
68769
68770
68771
68772
68773
68774
68775
68776
68777
68778
68779
68780
68781
68782
68783
68784
68785
68786
68787
68788
68789
68790
68791
68792
68793
68794
68795
68796
68797
68798
68799
68800
68801
68802
68803
68804
68805
68806
68807
68808
68809
68810
68811
68812
68813
68814
68815
68816
68817
68818
68819
68820
68821
68822
68823
68824
68825
68826
68827
68828
68829
68830
68831
68832
68833
68834
68835
68836
68837
68838
68839
68840
68841
68842
68843
68844
68845
68846
68847
68848
68849
68850
68851
68852
68853
68854
68855
68856
68857
68858
68859
68860
68861
68862
68863
68864
68865
68866
68867
68868
68869
68870
68871
68872
68873
68874
68875
68876
68877
68878
68879
68880
68881
68882
68883
68884
68885
68886
68887
68888
68889
68890
68891
68892
68893
68894
68895
68896
68897
68898
68899
68900
68901
68902
68903
68904
68905
68906

68907
68908
68909
68910
68911
68912
68913
68914
68915
68916
68917
68918
68919
68920
68921
68922
68923
68924
68925
68926



68927
68928
68929
68930




68931

68932
68933
68934


68935
68936
68937
68938
68939
68940
68941


68942
68943
68944
68945

68946
68947


68948
68949
68950
68951
68952
68953
68954
68955
68956
68957
68958
68959
68960
68961
68962
68963
68964
68965
68966
68967

68968
68969
68970




68971
68972
68973

68974
68975
68976
68977
68978
68979

68980
68981

68982














68983
68984
68985
68986
68987
68988
68989
68990
68991
68992
68993

68994
68995

68996

68997
68998
68999
69000
69001
69002
69003

69004
69005
69006
69007
69008
69009

69010

69011
69012

69013
69014
69015
69016
69017
69018
69019
69020
69021
69022
69023
69024
69025
69026
69027
69028
69029
69030
69031
69032
69033
69034
69035
69036
69037
69038
69039
69040
69041
69042
69043
69044
69045
69046
69047

69048
69049


69050
69051
69052
69053
69054
69055
69056
.....
69818
69819
69820
69821
69822
69823
69824


69825
69826
69827
69828
69829
69830
69831
69832
69833
69834
69835
69836
69837
69838
69839
69840
69841
69842
69843
69844
69845
69846
69847
69848
69849
69850
.....
69880
69881
69882
69883
69884
69885
69886

69887
69888
69889
69890
69891
69892
69893
.....
69912
69913
69914
69915
69916
69917
69918
69919
69920
69921
69922
69923
69924
69925
69926
.....
69927
69928
69929
69930
69931
69932
69933


69934
69935
69936
69937
69938
69939
69940
69941
69942
69943
69944
69945
69946
.....
69960
69961
69962
69963
69964
69965
69966

69967
69968
69969
69970
69971
69972
69973
69974
69975
69976
69977
69978
69979
.....
70799
70800
70801
70802
70803
70804
70805
70806
70807
70808
70809
70810
70811
70812
70813
.....
70841
70842
70843
70844
70845
70846
70847
70848
70849
70850
70851
70852
70853
70854
70855
70856
70857
.....
70860
70861
70862
70863
70864
70865
70866
70867
70868
70869
70870
70871
70872
70873
70874
.....
70880
70881
70882
70883
70884
70885
70886
70887
70888
70889
70890
70891
70892
70893
70894
.....
70957
70958
70959
70960
70961
70962
70963

70964
70965
70966
70967
70968
70969
70970
.....
71036
71037
71038
71039
71040
71041
71042
71043
71044
71045
71046
71047
71048
71049
71050
71051
71052
71053
71054
71055
71056
71057
71058
.....
71064
71065
71066
71067
71068
71069
71070
71071

71072
71073
71074
71075
71076
71077
71078
71079





71080
71081
71082
71083
71084
71085
71086
71087
71088

71089
71090
71091
71092
71093
71094
71095
71096
71097
71098



71099
71100
71101
71102
71103










71104
71105
71106
71107
71108
71109
71110
71111
71112
71113
71114
71115
71116
71117
71118
71119


71120
71121
71122

71123
71124

71125
71126
71127
71128
71129


71130
71131
71132
71133
71134
71135
71136
.....
71153
71154
71155
71156
71157
71158
71159
71160
71161
71162
71163
71164
71165
71166
71167
.....
72444
72445
72446
72447
72448
72449
72450
72451
72452
72453
72454
72455
72456
72457
72458
.....
73015
73016
73017
73018
73019
73020
73021

73022
73023
73024
73025
73026
73027
73028
73029
73030
73031
73032
73033
73034
73035
73036
73037
73038
73039
73040
.....
75804
75805
75806
75807
75808
75809
75810
75811
75812
75813
75814
75815
75816
75817
75818
75819
75820
75821
75822
75823
75824
75825
75826
75827
75828
75829
75830
75831
.....
75862
75863
75864
75865
75866
75867
75868

75869
75870
75871
75872
75873
75874
75875
.....
77779
77780
77781
77782
77783
77784
77785
77786

77787
77788


77789
77790
77791
77792
77793
77794
77795
.....
79211
79212
79213
79214
79215
79216
79217
79218
79219
79220
79221
79222
79223
79224
79225
79226
79227
79228
79229
79230
79231
79232
79233
79234
79235
79236
79237
79238
79239
.....
79269
79270
79271
79272
79273
79274
79275








79276




79277

79278
79279
79280
79281
79282
79283
79284
.....
79285
79286
79287
79288
79289
79290
79291
79292
79293
79294
79295
79296
79297
79298
79299

79300
79301
79302
79303
79304
79305
79306
.....
79316
79317
79318
79319
79320
79321
79322
79323
79324
79325
79326
79327
79328
79329
79330
79331
79332
79333
79334
79335
79336
79337
79338
79339
79340
79341
79342
79343
79344
79345
.....
79567
79568
79569
79570
79571
79572
79573






















79574
79575
79576
79577
79578
79579
79580
.....
79584
79585
79586
79587
79588
79589
79590
79591
79592
79593
79594
79595
79596
79597
79598
79599
79600

79601
79602
79603
79604
79605
79606
79607
79608

79609
79610
79611
79612
79613
79614
79615
.....
79791
79792
79793
79794
79795
79796
79797
79798
79799
79800
79801
79802
79803
79804
79805
.....
79947
79948
79949
79950
79951
79952
79953






79954
79955
79956
79957
79958
79959
79960
79961
79962

79963
79964
79965
79966

79967
79968



79969
79970
79971
79972

79973
79974
79975
79976
79977
79978
79979
.....
91336
91337
91338
91339
91340
91341
91342
91343
91344
91345
91346
91347
91348
91349
91350
91351
91352
91353
91354
91355
91356
91357
91358
91359
91360
91361
91362
91363
......
100001
100002
100003
100004
100005
100006
100007
100008

100009
100010
100011
100012
100013
100014
100015
......
103287
103288
103289
103290
103291
103292
103293
103294
103295
103296
103297
103298
103299
103300
103301
......
110763
110764
110765
110766
110767
110768
110769
110770
110771
110772
110773
110774
110775
110776
110777
......
117025
117026
117027
117028
117029
117030
117031
117032
117033
117034
117035
117036
117037
117038
117039
117040
117041
117042
117043
117044
**
** See also: [sqlite3_libversion()],
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
** [sqlite_version()] and [sqlite_source_id()].
*/
#define SQLITE_VERSION        "3.8.2"
#define SQLITE_VERSION_NUMBER 3008002
#define SQLITE_SOURCE_ID      "2013-11-19 13:55:34 17e8524fc05aa1e6074c19a8ccccc5ab5883103a"

/*
** 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
................................................................................
#define TK_ILLEGAL                        149
#define TK_SPACE                          150
#define TK_UNCLOSED_STRING                151
#define TK_FUNCTION                       152
#define TK_COLUMN                         153
#define TK_AGG_FUNCTION                   154
#define TK_AGG_COLUMN                     155
#define TK_CONST_FUNC                     156
#define TK_UMINUS                         157
#define TK_UPLUS                          158

/************** End of parse.h ***********************************************/
/************** Continuing where we left off in sqliteInt.h ******************/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
................................................................................
SQLITE_PRIVATE int sqlite3BtreeFirst(BtCursor*, int *pRes);
SQLITE_PRIVATE int sqlite3BtreeLast(BtCursor*, int *pRes);
SQLITE_PRIVATE int sqlite3BtreeNext(BtCursor*, int *pRes);
SQLITE_PRIVATE int sqlite3BtreeEof(BtCursor*);
SQLITE_PRIVATE int sqlite3BtreePrevious(BtCursor*, int *pRes);
SQLITE_PRIVATE int sqlite3BtreeKeySize(BtCursor*, i64 *pSize);
SQLITE_PRIVATE int sqlite3BtreeKey(BtCursor*, u32 offset, u32 amt, void*);
SQLITE_PRIVATE const void *sqlite3BtreeKeyFetch(BtCursor*, int *pAmt);
SQLITE_PRIVATE const void *sqlite3BtreeDataFetch(BtCursor*, int *pAmt);
SQLITE_PRIVATE int sqlite3BtreeDataSize(BtCursor*, u32 *pSize);
SQLITE_PRIVATE int sqlite3BtreeData(BtCursor*, u32 offset, u32 amt, void*);
SQLITE_PRIVATE void sqlite3BtreeSetCachedRowid(BtCursor*, sqlite3_int64);
SQLITE_PRIVATE sqlite3_int64 sqlite3BtreeGetCachedRowid(BtCursor*);

SQLITE_PRIVATE char *sqlite3BtreeIntegrityCheck(Btree*, int *aRoot, int nRoot, int, int*);
SQLITE_PRIVATE struct Pager *sqlite3BtreePager(Btree*);
................................................................................
/* Automatically generated.  Do not edit */
/* See the mkopcodeh.awk script for details */
#define OP_Function        1 /* synopsis: r[P3]=func(r[P2@P5])             */
#define OP_Savepoint       2
#define OP_AutoCommit      3
#define OP_Transaction     4
#define OP_SorterNext      5


#define OP_Prev            6
#define OP_Next            7
#define OP_AggStep         8 /* synopsis: accum=r[P3] step(r[P2@P5])       */
#define OP_Checkpoint      9
#define OP_JournalMode    10
#define OP_Vacuum         11
#define OP_VFilter        12 /* synopsis: iPlan=r[P3] zPlan='P4'           */
#define OP_VUpdate        13 /* synopsis: data=r[P3@P2]                    */
#define OP_Goto           14
#define OP_Gosub          15
#define OP_Return         16

#define OP_Yield          17
#define OP_HaltIfNull     18 /* synopsis: if r[P3] null then halt          */
#define OP_Not            19 /* same as TK_NOT, synopsis: r[P2]= !r[P1]    */
#define OP_Halt           20
#define OP_Integer        21 /* synopsis: r[P2]=P1                         */
#define OP_Int64          22 /* synopsis: r[P2]=P4                         */
#define OP_String         23 /* synopsis: r[P2]='P4' (len=P1)              */
#define OP_Null           24 /* synopsis: r[P2..P3]=NULL                   */
#define OP_Blob           25 /* synopsis: r[P2]=P4 (len=P1)                */
#define OP_Variable       26 /* synopsis: r[P2]=parameter(P1,P4)           */
#define OP_Move           27 /* synopsis: r[P2@P3]=r[P1@P3]                */
#define OP_Copy           28 /* synopsis: r[P2@P3]=r[P1@P3]                */
#define OP_SCopy          29 /* synopsis: r[P2]=r[P1]                      */
#define OP_ResultRow      30 /* synopsis: output=r[P1@P2]                  */
#define OP_CollSeq        31
#define OP_AddImm         32 /* synopsis: r[P1]=r[P1]+P2                   */
#define OP_MustBeInt      33
#define OP_RealAffinity   34
#define OP_Permutation    35
#define OP_Compare        36
#define OP_Jump           37
#define OP_Once           38
#define OP_If             39
#define OP_IfNot          40
#define OP_Column         41 /* synopsis: r[P3]=PX                         */
#define OP_Affinity       42 /* synopsis: affinity(r[P1@P2])               */
#define OP_MakeRecord     43 /* synopsis: r[P3]=mkrec(r[P1@P2])            */
#define OP_Count          44 /* synopsis: r[P2]=count()                    */
#define OP_ReadCookie     45
#define OP_SetCookie      46
#define OP_VerifyCookie   47
#define OP_OpenRead       48 /* synopsis: root=P2 iDb=P3                   */
#define OP_OpenWrite      49 /* synopsis: root=P2 iDb=P3                   */
#define OP_OpenAutoindex  50 /* synopsis: nColumn=P2                       */
#define OP_OpenEphemeral  51 /* synopsis: nColumn=P2                       */
#define OP_SorterOpen     52
#define OP_OpenPseudo     53 /* synopsis: content in r[P2@P3]              */
#define OP_Close          54
#define OP_SeekLt         55 /* synopsis: key=r[P3@P4]                     */
#define OP_SeekLe         56 /* synopsis: key=r[P3@P4]                     */
#define OP_SeekGe         57 /* synopsis: key=r[P3@P4]                     */
#define OP_SeekGt         58 /* synopsis: key=r[P3@P4]                     */
#define OP_Seek           59 /* synopsis: intkey=r[P2]                     */
#define OP_NoConflict     60 /* synopsis: key=r[P3@P4]                     */
#define OP_NotFound       61 /* synopsis: key=r[P3@P4]                     */
#define OP_Found          62 /* synopsis: key=r[P3@P4]                     */
#define OP_NotExists      63 /* synopsis: intkey=r[P3]                     */
#define OP_Sequence       64 /* synopsis: r[P2]=rowid                      */
#define OP_NewRowid       65 /* synopsis: r[P2]=rowid                      */
#define OP_Insert         66 /* synopsis: intkey=r[P3] data=r[P2]          */
#define OP_InsertInt      67 /* synopsis: intkey=P3 data=r[P2]             */
#define OP_Delete         68
#define OP_Or             69 /* same as TK_OR, synopsis: r[P3]=(r[P1] || r[P2]) */
#define OP_And            70 /* same as TK_AND, synopsis: r[P3]=(r[P1] && r[P2]) */


#define OP_ResetCount     71
#define OP_SorterCompare  72 /* synopsis: if key(P1)!=rtrim(r[P3],P4) goto P2 */
#define OP_SorterData     73 /* synopsis: r[P2]=data                       */
#define OP_IsNull         74 /* same as TK_ISNULL, synopsis: if r[P1]==NULL goto P2 */
#define OP_NotNull        75 /* same as TK_NOTNULL, synopsis: if r[P1]!=NULL goto P2 */
#define OP_Ne             76 /* same as TK_NE, synopsis: if r[P1]!=r[P3] goto P2 */
#define OP_Eq             77 /* same as TK_EQ, synopsis: if r[P1]==r[P3] goto P2 */
#define OP_Gt             78 /* same as TK_GT, synopsis: if r[P1]>r[P3] goto P2 */
#define OP_Le             79 /* same as TK_LE, synopsis: if r[P1]<=r[P3] goto P2 */
#define OP_Lt             80 /* same as TK_LT, synopsis: if r[P1]<r[P3] goto P2 */
#define OP_Ge             81 /* same as TK_GE, synopsis: if r[P1]>=r[P3] goto P2 */
#define OP_RowKey         82 /* synopsis: r[P2]=key                        */
#define OP_BitAnd         83 /* same as TK_BITAND, synopsis: r[P3]=r[P1]&r[P2] */
#define OP_BitOr          84 /* same as TK_BITOR, synopsis: r[P3]=r[P1]|r[P2] */
#define OP_ShiftLeft      85 /* same as TK_LSHIFT, synopsis: r[P3]=r[P2]<<r[P1] */
#define OP_ShiftRight     86 /* same as TK_RSHIFT, synopsis: r[P3]=r[P2]>>r[P1] */
#define OP_Add            87 /* same as TK_PLUS, synopsis: r[P3]=r[P1]+r[P2] */
#define OP_Subtract       88 /* same as TK_MINUS, synopsis: r[P3]=r[P2]-r[P1] */
#define OP_Multiply       89 /* same as TK_STAR, synopsis: r[P3]=r[P1]*r[P2] */
#define OP_Divide         90 /* same as TK_SLASH, synopsis: r[P3]=r[P2]/r[P1] */
#define OP_Remainder      91 /* same as TK_REM, synopsis: r[P3]=r[P2]%r[P1] */
#define OP_Concat         92 /* same as TK_CONCAT, synopsis: r[P3]=r[P2]+r[P1] */
#define OP_RowData        93 /* synopsis: r[P2]=data                       */
#define OP_BitNot         94 /* same as TK_BITNOT, synopsis: r[P1]= ~r[P1] */
#define OP_String8        95 /* same as TK_STRING, synopsis: r[P2]='P4'    */


#define OP_Rowid          96 /* synopsis: r[P2]=rowid                      */
#define OP_NullRow        97
#define OP_Last           98
#define OP_SorterSort     99
#define OP_Sort          100
#define OP_Rewind        101
#define OP_SorterInsert  102
#define OP_IdxInsert     103 /* synopsis: key=r[P2]                        */
#define OP_IdxDelete     104 /* synopsis: key=r[P2@P3]                     */
#define OP_IdxRowid      105 /* synopsis: r[P2]=rowid                      */
#define OP_IdxLT         106 /* synopsis: key=r[P3@P4]                     */
#define OP_IdxGE         107 /* synopsis: key=r[P3@P4]                     */
#define OP_Destroy       108
#define OP_Clear         109
#define OP_CreateIndex   110 /* synopsis: r[P2]=root iDb=P1                */
#define OP_CreateTable   111 /* synopsis: r[P2]=root iDb=P1                */
#define OP_ParseSchema   112
#define OP_LoadAnalysis  113
#define OP_DropTable     114
#define OP_DropIndex     115
#define OP_DropTrigger   116
#define OP_IntegrityCk   117
#define OP_RowSetAdd     118 /* synopsis: rowset(P1)=r[P2]                 */
#define OP_RowSetRead    119 /* synopsis: r[P3]=rowset(P1)                 */
#define OP_RowSetTest    120 /* synopsis: if r[P3] in rowset(P1) goto P2   */
#define OP_Program       121
#define OP_Param         122
#define OP_FkCounter     123 /* synopsis: fkctr[P1]+=P2                    */
#define OP_FkIfZero      124 /* synopsis: if fkctr[P1]==0 goto P2          */
#define OP_MemMax        125 /* synopsis: r[P1]=max(r[P1],r[P2])           */
#define OP_IfPos         126 /* synopsis: if r[P1]>0 goto P2               */
#define OP_IfNeg         127 /* synopsis: if r[P1]<0 goto P2               */
#define OP_IfZero        128 /* synopsis: r[P1]+=P3, if r[P1]==0 goto P2   */

#define OP_AggFinal      129 /* synopsis: accum=r[P1] N=P2                 */
#define OP_IncrVacuum    130
#define OP_Real          131 /* same as TK_FLOAT, synopsis: r[P2]=P4       */
#define OP_Expire        132
#define OP_TableLock     133 /* synopsis: iDb=P1 root=P2 write=P3          */
#define OP_VBegin        134
#define OP_VCreate       135
#define OP_VDestroy      136
#define OP_VOpen         137
#define OP_VColumn       138 /* synopsis: r[P3]=vcolumn(P2)                */
#define OP_VNext         139
#define OP_VRename       140
#define OP_Pagecount     141
#define OP_ToText        142 /* same as TK_TO_TEXT                         */
#define OP_ToBlob        143 /* same as TK_TO_BLOB                         */
#define OP_ToNumeric     144 /* same as TK_TO_NUMERIC                      */
#define OP_ToInt         145 /* same as TK_TO_INT                          */
#define OP_ToReal        146 /* same as TK_TO_REAL                         */


#define OP_MaxPgcnt      147
#define OP_Trace         148
#define OP_Noop          149
#define OP_Explain       150


/* 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            0x0001  /* jump:  P2 holds jmp target */
................................................................................
#define OPFLG_IN1             0x0004  /* in1:   P1 is an input */
#define OPFLG_IN2             0x0008  /* in2:   P2 is an input */
#define OPFLG_IN3             0x0010  /* in3:   P3 is an input */
#define OPFLG_OUT2            0x0020  /* out2:  P2 is an output */
#define OPFLG_OUT3            0x0040  /* out3:  P3 is an output */
#define OPFLG_INITIALIZER {\
/*   0 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01,\
/*   8 */ 0x00, 0x00, 0x02, 0x00, 0x01, 0x00, 0x01, 0x01,\
/*  16 */ 0x04, 0x04, 0x10, 0x24, 0x00, 0x02, 0x02, 0x02,\
/*  24 */ 0x02, 0x02, 0x02, 0x00, 0x00, 0x20, 0x00, 0x00,\
/*  32 */ 0x04, 0x05, 0x04, 0x00, 0x00, 0x01, 0x01, 0x05,\
/*  40 */ 0x05, 0x00, 0x00, 0x00, 0x02, 0x02, 0x10, 0x00,\
/*  48 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x11,\
/*  56 */ 0x11, 0x11, 0x11, 0x08, 0x11, 0x11, 0x11, 0x11,\
/*  64 */ 0x02, 0x02, 0x00, 0x00, 0x00, 0x4c, 0x4c, 0x00,\
/*  72 */ 0x00, 0x00, 0x05, 0x05, 0x15, 0x15, 0x15, 0x15,\
/*  80 */ 0x15, 0x15, 0x00, 0x4c, 0x4c, 0x4c, 0x4c, 0x4c,\
/*  88 */ 0x4c, 0x4c, 0x4c, 0x4c, 0x4c, 0x00, 0x24, 0x02,\
/*  96 */ 0x02, 0x00, 0x01, 0x01, 0x01, 0x01, 0x08, 0x08,\
/* 104 */ 0x00, 0x02, 0x01, 0x01, 0x02, 0x00, 0x02, 0x02,\
/* 112 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0c, 0x45,\
/* 120 */ 0x15, 0x01, 0x02, 0x00, 0x01, 0x08, 0x05, 0x05,\
/* 128 */ 0x05, 0x00, 0x01, 0x02, 0x00, 0x00, 0x00, 0x00,\
/* 136 */ 0x00, 0x00, 0x00, 0x01, 0x00, 0x02, 0x04, 0x04,\
/* 144 */ 0x04, 0x04, 0x04, 0x02, 0x00, 0x00, 0x00,}


/************** End of opcodes.h *********************************************/
/************** Continuing where we left off in vdbe.h ***********************/

/*
** Prototypes for the VDBE interface.  See comments on the implementation
** for a description of what each of these routines does.
................................................................................
#define OptimizationDisabled(db, mask)  (((db)->dbOptFlags&(mask))!=0)
#define OptimizationEnabled(db, mask)   (((db)->dbOptFlags&(mask))==0)
#else
#define OptimizationDisabled(db, mask)  0
#define OptimizationEnabled(db, mask)   1
#endif








/*
** Possible values for the sqlite.magic field.
** The numbers are obtained at random and have no special meaning, other
** than being distinct from one another.
*/
#define SQLITE_MAGIC_OPEN     0xa029a697  /* Database is open */
#define SQLITE_MAGIC_CLOSED   0x9f3c2d33  /* Database is closed */
................................................................................
#define SQLITE_FUNC_EPHEM    0x010 /* Ephemeral.  Delete with VDBE */
#define SQLITE_FUNC_NEEDCOLL 0x020 /* sqlite3GetFuncCollSeq() might be called */
#define SQLITE_FUNC_LENGTH   0x040 /* Built-in length() function */
#define SQLITE_FUNC_TYPEOF   0x080 /* Built-in typeof() function */
#define SQLITE_FUNC_COUNT    0x100 /* Built-in count(*) aggregate */
#define SQLITE_FUNC_COALESCE 0x200 /* Built-in coalesce() or ifnull() */
#define SQLITE_FUNC_UNLIKELY 0x400 /* Built-in unlikely() function */


/*
** The following three macros, FUNCTION(), LIKEFUNC() and AGGREGATE() are
** used to create the initializers for the FuncDef structures.
**
**   FUNCTION(zName, nArg, iArg, bNC, xFunc)
**     Used to create a scalar function definition of a function zName 
**     implemented by C function xFunc that accepts nArg arguments. The
**     value passed as iArg is cast to a (void*) and made available
**     as the user-data (sqlite3_user_data()) for the function. If 
**     argument bNC is true, then the SQLITE_FUNC_NEEDCOLL flag is set.
**



**   AGGREGATE(zName, nArg, iArg, bNC, xStep, xFinal)
**     Used to create an aggregate function definition implemented by
**     the C functions xStep and xFinal. The first four parameters
**     are interpreted in the same way as the first 4 parameters to
**     FUNCTION().
**
**   LIKEFUNC(zName, nArg, pArg, flags)
................................................................................
**     that accepts nArg arguments and is implemented by a call to C 
**     function likeFunc. Argument pArg is cast to a (void *) and made
**     available as the function user-data (sqlite3_user_data()). The
**     FuncDef.flags variable is set to the value passed as the flags
**     parameter.
*/
#define FUNCTION(zName, nArg, iArg, bNC, xFunc) \



  {nArg, SQLITE_UTF8|(bNC*SQLITE_FUNC_NEEDCOLL), \
   SQLITE_INT_TO_PTR(iArg), 0, xFunc, 0, 0, #zName, 0, 0}
#define FUNCTION2(zName, nArg, iArg, bNC, xFunc, extraFlags) \
  {nArg, SQLITE_UTF8|(bNC*SQLITE_FUNC_NEEDCOLL)|extraFlags, \
   SQLITE_INT_TO_PTR(iArg), 0, xFunc, 0, 0, #zName, 0, 0}
#define STR_FUNCTION(zName, nArg, pArg, bNC, xFunc) \
  {nArg, SQLITE_UTF8|(bNC*SQLITE_FUNC_NEEDCOLL), \
   pArg, 0, xFunc, 0, 0, #zName, 0, 0}
#define LIKEFUNC(zName, nArg, arg, flags) \

  {nArg, SQLITE_UTF8|flags, (void *)arg, 0, likeFunc, 0, 0, #zName, 0, 0}
#define AGGREGATE(zName, nArg, arg, nc, xStep, xFinal) \
  {nArg, SQLITE_UTF8|(nc*SQLITE_FUNC_NEEDCOLL), \
   SQLITE_INT_TO_PTR(arg), 0, 0, xStep,xFinal,#zName,0,0}

/*
** All current savepoints are stored in a linked list starting at
** sqlite3.pSavepoint. The first element in the list is the most recently
................................................................................
#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_MemToken  0x010000 /* Need to sqlite3DbFree() Expr.zToken */
#define EP_NoReduce  0x020000 /* Cannot EXPRDUP_REDUCE this Expr */
#define EP_Unlikely  0x040000 /* unlikely() or likelihood() function */


/*
** These macros can be used to test, set, or clear bits in the 
** Expr.flags field.
*/
#define ExprHasProperty(E,P)     (((E)->flags&(P))!=0)
#define ExprHasAllProperty(E,P)  (((E)->flags&(P))==(P))
................................................................................
  struct ExprList_item { /* For each expression in the list */
    Expr *pExpr;            /* The list of expressions */
    char *zName;            /* Token associated with this expression */
    char *zSpan;            /* Original text of the expression */
    u8 sortOrder;           /* 1 for DESC or 0 for ASC */
    unsigned done :1;       /* A flag to indicate when processing is finished */
    unsigned bSpanIsTab :1; /* zSpan holds DB.TABLE.COLUMN */

    union {
      struct {
        u16 iOrderByCol;      /* For ORDER BY, column number in result set */
        u16 iAlias;           /* Index into Parse.aAlias[] for zName */
      } x;
      int iConstExprReg;      /* Register in which Expr value is cached */
    } u;
................................................................................
SQLITE_PRIVATE void sqlite3ExprCacheStore(Parse*, int, int, int);
SQLITE_PRIVATE void sqlite3ExprCachePush(Parse*);
SQLITE_PRIVATE void sqlite3ExprCachePop(Parse*, int);
SQLITE_PRIVATE void sqlite3ExprCacheRemove(Parse*, int, int);
SQLITE_PRIVATE void sqlite3ExprCacheClear(Parse*);
SQLITE_PRIVATE void sqlite3ExprCacheAffinityChange(Parse*, int, int);
SQLITE_PRIVATE int sqlite3ExprCode(Parse*, Expr*, int);

SQLITE_PRIVATE int sqlite3ExprCodeTemp(Parse*, Expr*, int*);
SQLITE_PRIVATE int sqlite3ExprCodeTarget(Parse*, Expr*, int);
SQLITE_PRIVATE int sqlite3ExprCodeAndCache(Parse*, Expr*, int);
SQLITE_PRIVATE int sqlite3ExprCodeExprList(Parse*, ExprList*, int, int);


SQLITE_PRIVATE void sqlite3ExprIfTrue(Parse*, Expr*, int, int);
SQLITE_PRIVATE void sqlite3ExprIfFalse(Parse*, Expr*, int, int);
SQLITE_PRIVATE Table *sqlite3FindTable(sqlite3*,const char*, const char*);
SQLITE_PRIVATE Table *sqlite3LocateTable(Parse*,int isView,const char*, const char*);
SQLITE_PRIVATE Table *sqlite3LocateTableItem(Parse*,int isView,struct SrcList_item *);
SQLITE_PRIVATE Index *sqlite3FindIndex(sqlite3*,const char*, const char*);
SQLITE_PRIVATE void sqlite3UnlinkAndDeleteTable(sqlite3*,int,const char*);
................................................................................
** of the following structure.
*/
typedef struct VdbeOp Op;

/*
** Boolean values
*/
typedef unsigned char Bool;

/* Opaque type used by code in vdbesort.c */
typedef struct VdbeSorter VdbeSorter;

/* Opaque type used by the explainer */
typedef struct Explain Explain;

................................................................................

/*
** A cursor is a pointer into a single BTree within a database file.
** The cursor can seek to a BTree entry with a particular key, or
** loop over all entries of the Btree.  You can also insert new BTree
** entries or retrieve the key or data from the entry that the cursor
** is currently pointing to.



** 
** Every cursor that the virtual machine has open is represented by an
** instance of the following structure.
*/
struct VdbeCursor {
  BtCursor *pCursor;    /* The cursor structure of the backend */
  Btree *pBt;           /* Separate file holding temporary table */
  KeyInfo *pKeyInfo;    /* Info about index keys needed by index cursors */
  int iDb;              /* Index of cursor database in db->aDb[] (or -1) */
  int pseudoTableReg;   /* Register holding pseudotable content. */
  int nField;           /* Number of fields in the header */
  Bool zeroed;          /* True if zeroed out and ready for reuse */
  Bool rowidIsValid;    /* True if lastRowid is valid */
  Bool atFirst;         /* True if pointing to first entry */
  Bool useRandomRowid;  /* Generate new record numbers semi-randomly */
  Bool nullRow;         /* True if pointing to a row with no data */

  Bool deferredMoveto;  /* A call to sqlite3BtreeMoveto() is needed */

  Bool isTable;         /* True if a table requiring integer keys */
  Bool isIndex;         /* True if an index containing keys only - no data */
  Bool isOrdered;       /* True if the underlying table is BTREE_UNORDERED */
  Bool isSorter;        /* True if a new-style sorter */
  Bool multiPseudo;     /* Multi-register pseudo-cursor */
  sqlite3_vtab_cursor *pVtabCursor;  /* The cursor for a virtual table */
  const sqlite3_module *pModule;     /* Module for cursor pVtabCursor */
  i64 seqCount;         /* Sequence counter */
  i64 movetoTarget;     /* Argument to the deferred sqlite3BtreeMoveto() */
  i64 lastRowid;        /* Last rowid from a Next or NextIdx operation */
  VdbeSorter *pSorter;  /* Sorter object for OP_SorterOpen cursors */

  /* Result of last sqlite3BtreeMoveto() done by an OP_NotExists */
  int seekResult;

  /* Cached information about the header for the data record that the
  ** cursor is currently pointing to.  Only valid if cacheStatus matches
  ** Vdbe.cacheCtr.  Vdbe.cacheCtr will never take on the value of
  ** CACHE_STALE and so setting cacheStatus=CACHE_STALE guarantees that
  ** the cache is out of date.
  **
  ** aRow might point to (ephemeral) data for the current row, or it might
  ** be NULL.
  */
  u32 cacheStatus;      /* Cache is valid if this matches Vdbe.cacheCtr */
  int payloadSize;      /* Total number of bytes in the record */
  u32 *aType;           /* Type values for all entries in the record */
  u32 *aOffset;         /* Cached offsets to the start of each columns data */
  u8 *aRow;             /* Data for the current row, if all on one page */




};
typedef struct VdbeCursor VdbeCursor;

/*
** When a sub-program is executed (OP_Program), a structure of this type
** is allocated to store the current value of the program counter, as
** well as the current memory cell array and various other frame specific
................................................................................
SQLITE_PRIVATE int sqlite3VdbeMemStringify(Mem*, int);
SQLITE_PRIVATE i64 sqlite3VdbeIntValue(Mem*);
SQLITE_PRIVATE int sqlite3VdbeMemIntegerify(Mem*);
SQLITE_PRIVATE double sqlite3VdbeRealValue(Mem*);
SQLITE_PRIVATE void sqlite3VdbeIntegerAffinity(Mem*);
SQLITE_PRIVATE int sqlite3VdbeMemRealify(Mem*);
SQLITE_PRIVATE int sqlite3VdbeMemNumerify(Mem*);
SQLITE_PRIVATE int sqlite3VdbeMemFromBtree(BtCursor*,int,int,int,Mem*);
SQLITE_PRIVATE void sqlite3VdbeMemRelease(Mem *p);
SQLITE_PRIVATE void sqlite3VdbeMemReleaseExternal(Mem *p);
#define VdbeMemRelease(X)  \
  if((X)->flags&(MEM_Agg|MEM_Dyn|MEM_RowSet|MEM_Frame)) \
    sqlite3VdbeMemReleaseExternal(X);
SQLITE_PRIVATE int sqlite3VdbeMemFinalize(Mem*, FuncDef*);
SQLITE_PRIVATE const char *sqlite3OpcodeName(int);
................................................................................
SQLITE_PRIVATE const char *sqlite3OpcodeName(int i){
 static const char *const azName[] = { "?",
     /*   1 */ "Function"         OpHelp("r[P3]=func(r[P2@P5])"),
     /*   2 */ "Savepoint"        OpHelp(""),
     /*   3 */ "AutoCommit"       OpHelp(""),
     /*   4 */ "Transaction"      OpHelp(""),
     /*   5 */ "SorterNext"       OpHelp(""),


     /*   6 */ "Prev"             OpHelp(""),
     /*   7 */ "Next"             OpHelp(""),
     /*   8 */ "AggStep"          OpHelp("accum=r[P3] step(r[P2@P5])"),
     /*   9 */ "Checkpoint"       OpHelp(""),
     /*  10 */ "JournalMode"      OpHelp(""),
     /*  11 */ "Vacuum"           OpHelp(""),
     /*  12 */ "VFilter"          OpHelp("iPlan=r[P3] zPlan='P4'"),
     /*  13 */ "VUpdate"          OpHelp("data=r[P3@P2]"),
     /*  14 */ "Goto"             OpHelp(""),
     /*  15 */ "Gosub"            OpHelp(""),
     /*  16 */ "Return"           OpHelp(""),

     /*  17 */ "Yield"            OpHelp(""),
     /*  18 */ "HaltIfNull"       OpHelp("if r[P3] null then halt"),
     /*  19 */ "Not"              OpHelp("r[P2]= !r[P1]"),
     /*  20 */ "Halt"             OpHelp(""),
     /*  21 */ "Integer"          OpHelp("r[P2]=P1"),
     /*  22 */ "Int64"            OpHelp("r[P2]=P4"),
     /*  23 */ "String"           OpHelp("r[P2]='P4' (len=P1)"),
     /*  24 */ "Null"             OpHelp("r[P2..P3]=NULL"),
     /*  25 */ "Blob"             OpHelp("r[P2]=P4 (len=P1)"),
     /*  26 */ "Variable"         OpHelp("r[P2]=parameter(P1,P4)"),
     /*  27 */ "Move"             OpHelp("r[P2@P3]=r[P1@P3]"),
     /*  28 */ "Copy"             OpHelp("r[P2@P3]=r[P1@P3]"),
     /*  29 */ "SCopy"            OpHelp("r[P2]=r[P1]"),
     /*  30 */ "ResultRow"        OpHelp("output=r[P1@P2]"),
     /*  31 */ "CollSeq"          OpHelp(""),
     /*  32 */ "AddImm"           OpHelp("r[P1]=r[P1]+P2"),
     /*  33 */ "MustBeInt"        OpHelp(""),
     /*  34 */ "RealAffinity"     OpHelp(""),
     /*  35 */ "Permutation"      OpHelp(""),
     /*  36 */ "Compare"          OpHelp(""),
     /*  37 */ "Jump"             OpHelp(""),
     /*  38 */ "Once"             OpHelp(""),
     /*  39 */ "If"               OpHelp(""),
     /*  40 */ "IfNot"            OpHelp(""),
     /*  41 */ "Column"           OpHelp("r[P3]=PX"),
     /*  42 */ "Affinity"         OpHelp("affinity(r[P1@P2])"),
     /*  43 */ "MakeRecord"       OpHelp("r[P3]=mkrec(r[P1@P2])"),
     /*  44 */ "Count"            OpHelp("r[P2]=count()"),
     /*  45 */ "ReadCookie"       OpHelp(""),
     /*  46 */ "SetCookie"        OpHelp(""),
     /*  47 */ "VerifyCookie"     OpHelp(""),
     /*  48 */ "OpenRead"         OpHelp("root=P2 iDb=P3"),
     /*  49 */ "OpenWrite"        OpHelp("root=P2 iDb=P3"),
     /*  50 */ "OpenAutoindex"    OpHelp("nColumn=P2"),
     /*  51 */ "OpenEphemeral"    OpHelp("nColumn=P2"),
     /*  52 */ "SorterOpen"       OpHelp(""),
     /*  53 */ "OpenPseudo"       OpHelp("content in r[P2@P3]"),
     /*  54 */ "Close"            OpHelp(""),
     /*  55 */ "SeekLt"           OpHelp("key=r[P3@P4]"),
     /*  56 */ "SeekLe"           OpHelp("key=r[P3@P4]"),
     /*  57 */ "SeekGe"           OpHelp("key=r[P3@P4]"),
     /*  58 */ "SeekGt"           OpHelp("key=r[P3@P4]"),
     /*  59 */ "Seek"             OpHelp("intkey=r[P2]"),
     /*  60 */ "NoConflict"       OpHelp("key=r[P3@P4]"),
     /*  61 */ "NotFound"         OpHelp("key=r[P3@P4]"),
     /*  62 */ "Found"            OpHelp("key=r[P3@P4]"),
     /*  63 */ "NotExists"        OpHelp("intkey=r[P3]"),
     /*  64 */ "Sequence"         OpHelp("r[P2]=rowid"),
     /*  65 */ "NewRowid"         OpHelp("r[P2]=rowid"),
     /*  66 */ "Insert"           OpHelp("intkey=r[P3] data=r[P2]"),
     /*  67 */ "InsertInt"        OpHelp("intkey=P3 data=r[P2]"),
     /*  68 */ "Delete"           OpHelp(""),
     /*  69 */ "Or"               OpHelp("r[P3]=(r[P1] || r[P2])"),
     /*  70 */ "And"              OpHelp("r[P3]=(r[P1] && r[P2])"),


     /*  71 */ "ResetCount"       OpHelp(""),
     /*  72 */ "SorterCompare"    OpHelp("if key(P1)!=rtrim(r[P3],P4) goto P2"),
     /*  73 */ "SorterData"       OpHelp("r[P2]=data"),
     /*  74 */ "IsNull"           OpHelp("if r[P1]==NULL goto P2"),
     /*  75 */ "NotNull"          OpHelp("if r[P1]!=NULL goto P2"),
     /*  76 */ "Ne"               OpHelp("if r[P1]!=r[P3] goto P2"),
     /*  77 */ "Eq"               OpHelp("if r[P1]==r[P3] goto P2"),
     /*  78 */ "Gt"               OpHelp("if r[P1]>r[P3] goto P2"),
     /*  79 */ "Le"               OpHelp("if r[P1]<=r[P3] goto P2"),
     /*  80 */ "Lt"               OpHelp("if r[P1]<r[P3] goto P2"),
     /*  81 */ "Ge"               OpHelp("if r[P1]>=r[P3] goto P2"),
     /*  82 */ "RowKey"           OpHelp("r[P2]=key"),
     /*  83 */ "BitAnd"           OpHelp("r[P3]=r[P1]&r[P2]"),
     /*  84 */ "BitOr"            OpHelp("r[P3]=r[P1]|r[P2]"),
     /*  85 */ "ShiftLeft"        OpHelp("r[P3]=r[P2]<<r[P1]"),
     /*  86 */ "ShiftRight"       OpHelp("r[P3]=r[P2]>>r[P1]"),
     /*  87 */ "Add"              OpHelp("r[P3]=r[P1]+r[P2]"),
     /*  88 */ "Subtract"         OpHelp("r[P3]=r[P2]-r[P1]"),
     /*  89 */ "Multiply"         OpHelp("r[P3]=r[P1]*r[P2]"),
     /*  90 */ "Divide"           OpHelp("r[P3]=r[P2]/r[P1]"),
     /*  91 */ "Remainder"        OpHelp("r[P3]=r[P2]%r[P1]"),
     /*  92 */ "Concat"           OpHelp("r[P3]=r[P2]+r[P1]"),
     /*  93 */ "RowData"          OpHelp("r[P2]=data"),
     /*  94 */ "BitNot"           OpHelp("r[P1]= ~r[P1]"),
     /*  95 */ "String8"          OpHelp("r[P2]='P4'"),


     /*  96 */ "Rowid"            OpHelp("r[P2]=rowid"),
     /*  97 */ "NullRow"          OpHelp(""),
     /*  98 */ "Last"             OpHelp(""),
     /*  99 */ "SorterSort"       OpHelp(""),
     /* 100 */ "Sort"             OpHelp(""),
     /* 101 */ "Rewind"           OpHelp(""),
     /* 102 */ "SorterInsert"     OpHelp(""),
     /* 103 */ "IdxInsert"        OpHelp("key=r[P2]"),
     /* 104 */ "IdxDelete"        OpHelp("key=r[P2@P3]"),
     /* 105 */ "IdxRowid"         OpHelp("r[P2]=rowid"),
     /* 106 */ "IdxLT"            OpHelp("key=r[P3@P4]"),
     /* 107 */ "IdxGE"            OpHelp("key=r[P3@P4]"),
     /* 108 */ "Destroy"          OpHelp(""),
     /* 109 */ "Clear"            OpHelp(""),
     /* 110 */ "CreateIndex"      OpHelp("r[P2]=root iDb=P1"),
     /* 111 */ "CreateTable"      OpHelp("r[P2]=root iDb=P1"),
     /* 112 */ "ParseSchema"      OpHelp(""),
     /* 113 */ "LoadAnalysis"     OpHelp(""),
     /* 114 */ "DropTable"        OpHelp(""),
     /* 115 */ "DropIndex"        OpHelp(""),
     /* 116 */ "DropTrigger"      OpHelp(""),
     /* 117 */ "IntegrityCk"      OpHelp(""),
     /* 118 */ "RowSetAdd"        OpHelp("rowset(P1)=r[P2]"),
     /* 119 */ "RowSetRead"       OpHelp("r[P3]=rowset(P1)"),
     /* 120 */ "RowSetTest"       OpHelp("if r[P3] in rowset(P1) goto P2"),
     /* 121 */ "Program"          OpHelp(""),
     /* 122 */ "Param"            OpHelp(""),
     /* 123 */ "FkCounter"        OpHelp("fkctr[P1]+=P2"),
     /* 124 */ "FkIfZero"         OpHelp("if fkctr[P1]==0 goto P2"),
     /* 125 */ "MemMax"           OpHelp("r[P1]=max(r[P1],r[P2])"),
     /* 126 */ "IfPos"            OpHelp("if r[P1]>0 goto P2"),
     /* 127 */ "IfNeg"            OpHelp("if r[P1]<0 goto P2"),
     /* 128 */ "IfZero"           OpHelp("r[P1]+=P3, if r[P1]==0 goto P2"),

     /* 129 */ "AggFinal"         OpHelp("accum=r[P1] N=P2"),
     /* 130 */ "IncrVacuum"       OpHelp(""),
     /* 131 */ "Real"             OpHelp("r[P2]=P4"),
     /* 132 */ "Expire"           OpHelp(""),
     /* 133 */ "TableLock"        OpHelp("iDb=P1 root=P2 write=P3"),
     /* 134 */ "VBegin"           OpHelp(""),
     /* 135 */ "VCreate"          OpHelp(""),
     /* 136 */ "VDestroy"         OpHelp(""),
     /* 137 */ "VOpen"            OpHelp(""),
     /* 138 */ "VColumn"          OpHelp("r[P3]=vcolumn(P2)"),
     /* 139 */ "VNext"            OpHelp(""),
     /* 140 */ "VRename"          OpHelp(""),
     /* 141 */ "Pagecount"        OpHelp(""),
     /* 142 */ "ToText"           OpHelp(""),
     /* 143 */ "ToBlob"           OpHelp(""),
     /* 144 */ "ToNumeric"        OpHelp(""),
     /* 145 */ "ToInt"            OpHelp(""),
     /* 146 */ "ToReal"           OpHelp(""),


     /* 147 */ "MaxPgcnt"         OpHelp(""),
     /* 148 */ "Trace"            OpHelp(""),
     /* 149 */ "Noop"             OpHelp(""),
     /* 150 */ "Explain"          OpHelp(""),
  };
  return azName[i];
}
#endif

/************** End of opcodes.c *********************************************/
/************** Begin file os_unix.c *****************************************/
................................................................................
**
** The pointer returned by this routine looks directly into the cached
** page of the database.  The data might change or move the next time
** any btree routine is called.
*/
static const unsigned char *fetchPayload(
  BtCursor *pCur,      /* Cursor pointing to entry to read from */
  int *pAmt,           /* Write the number of available bytes here */
  int skipKey          /* read beginning at data if this is true */
){
  unsigned char *aPayload;
  MemPage *pPage;
  u32 nKey;
  u32 nLocal;

................................................................................
** including calls from other threads against the same cache.
** Hence, a mutex on the BtShared should be held prior to calling
** this routine.
**
** These routines is used to get quick access to key and data
** in the common case where no overflow pages are used.
*/
SQLITE_PRIVATE const void *sqlite3BtreeKeyFetch(BtCursor *pCur, int *pAmt){
  const void *p = 0;
  assert( sqlite3_mutex_held(pCur->pBtree->db->mutex) );
  assert( cursorHoldsMutex(pCur) );
  if( ALWAYS(pCur->eState==CURSOR_VALID) ){
    p = (const void*)fetchPayload(pCur, pAmt, 0);
  }
  return p;
}
SQLITE_PRIVATE const void *sqlite3BtreeDataFetch(BtCursor *pCur, int *pAmt){
  const void *p = 0;
  assert( sqlite3_mutex_held(pCur->pBtree->db->mutex) );
  assert( cursorHoldsMutex(pCur) );
  if( ALWAYS(pCur->eState==CURSOR_VALID) ){
    p = (const void*)fetchPayload(pCur, pAmt, 1);
  }
  return p;
................................................................................
** is overwritten without being freed.
**
** If this routine fails for any reason (malloc returns NULL or unable
** to read from the disk) then the pMem is left in an inconsistent state.
*/
SQLITE_PRIVATE int sqlite3VdbeMemFromBtree(
  BtCursor *pCur,   /* Cursor pointing at record to retrieve. */
  int offset,       /* Offset from the start of data to return bytes from. */
  int amt,          /* Number of bytes to return. */
  int key,          /* If true, retrieve from the btree key, not data. */
  Mem *pMem         /* OUT: Return data in this Mem structure. */
){
  char *zData;        /* Data from the btree layer */
  int available = 0;  /* Number of bytes available on the local btree page */
  int rc = SQLITE_OK; /* Return code */

  assert( sqlite3BtreeCursorIsValid(pCur) );

  /* Note: the calls to BtreeKeyFetch() and DataFetch() below assert() 
  ** that both the BtShared and database handle mutexes are held. */
  assert( (pMem->flags & MEM_RowSet)==0 );
................................................................................
  if( key ){
    zData = (char *)sqlite3BtreeKeyFetch(pCur, &available);
  }else{
    zData = (char *)sqlite3BtreeDataFetch(pCur, &available);
  }
  assert( zData!=0 );

  if( offset+amt<=available && (pMem->flags&MEM_Dyn)==0 ){
    sqlite3VdbeMemRelease(pMem);
    pMem->z = &zData[offset];
    pMem->flags = MEM_Blob|MEM_Ephem;
  }else if( SQLITE_OK==(rc = sqlite3VdbeMemGrow(pMem, amt+2, 0)) ){
    pMem->flags = MEM_Blob|MEM_Dyn|MEM_Term;
    pMem->enc = 0;
    pMem->type = SQLITE_BLOB;
................................................................................
    }
    pMem->z[amt] = 0;
    pMem->z[amt+1] = 0;
    if( rc!=SQLITE_OK ){
      sqlite3VdbeMemRelease(pMem);
    }
  }
  pMem->n = amt;

  return rc;
}

/* This function is only available internally, it is not part of the
** external API. It works in a similar way to sqlite3_value_text(),
** except the data returned is in the encoding specified by the second
................................................................................
        assert( pOp[-1].opcode==OP_Integer );
        n = pOp[-1].p1;
        if( n>nMaxArgs ) nMaxArgs = n;
        break;
      }
#endif
      case OP_Next:

      case OP_SorterNext: {
        pOp->p4.xAdvance = sqlite3BtreeNext;
        pOp->p4type = P4_ADVANCE;
        break;
      }
      case OP_Prev: {

        pOp->p4.xAdvance = sqlite3BtreePrevious;
        pOp->p4type = P4_ADVANCE;
        break;
      }
    }

    pOp->opflags = sqlite3OpcodeProperty[opcode];
................................................................................
    ** the call above. */
  }else if( pCx->pCursor ){
    sqlite3BtreeCloseCursor(pCx->pCursor);
  }
#ifndef SQLITE_OMIT_VIRTUALTABLE
  if( pCx->pVtabCursor ){
    sqlite3_vtab_cursor *pVtabCursor = pCx->pVtabCursor;
    const sqlite3_module *pModule = pCx->pModule;
    p->inVtabMethod = 1;
    pModule->xClose(pVtabCursor);
    p->inVtabMethod = 0;
  }
#endif
}

................................................................................
    if( res!=0 ) return SQLITE_CORRUPT_BKPT;
    p->rowidIsValid = 1;
#ifdef SQLITE_TEST
    sqlite3_search_count++;
#endif
    p->deferredMoveto = 0;
    p->cacheStatus = CACHE_STALE;
  }else if( ALWAYS(p->pCursor) ){
    int hasMoved;
    int rc = sqlite3BtreeCursorHasMoved(p->pCursor, &hasMoved);
    if( rc ) return rc;
    if( hasMoved ){
      p->cacheStatus = CACHE_STALE;
      p->nullRow = 1;
    }
................................................................................
  assert( sqlite3BtreeCursorIsValid(pCur) );
  VVA_ONLY(rc =) sqlite3BtreeKeySize(pCur, &nCellKey);
  assert( rc==SQLITE_OK );     /* pCur is always valid so KeySize cannot fail */
  assert( (nCellKey & SQLITE_MAX_U32)==(u64)nCellKey );

  /* Read in the complete content of the index entry */
  memset(&m, 0, sizeof(m));
  rc = sqlite3VdbeMemFromBtree(pCur, 0, (int)nCellKey, 1, &m);
  if( rc ){
    return rc;
  }

  /* The index entry must begin with a header size */
  (void)getVarint32((u8*)m.z, szHdr);
  testcase( szHdr==3 );
................................................................................
  /* nCellKey will always be between 0 and 0xffffffff because of the say
  ** that btreeParseCellPtr() and sqlite3GetVarint32() are implemented */
  if( nCellKey<=0 || nCellKey>0x7fffffff ){
    *res = 0;
    return SQLITE_CORRUPT_BKPT;
  }
  memset(&m, 0, sizeof(m));
  rc = sqlite3VdbeMemFromBtree(pC->pCursor, 0, (int)nCellKey, 1, &m);
  if( rc ){
    return rc;
  }
  assert( pUnpacked->flags & UNPACKED_PREFIX_MATCH );
  *res = sqlite3VdbeRecordCompare(m.n, m.z, pUnpacked);
  sqlite3VdbeMemRelease(&m);
  return SQLITE_OK;
................................................................................
  ** cursor 1 is managed by memory cell (p->nMem-1), etc.
  */
  Mem *pMem = &p->aMem[p->nMem-iCur];

  int nByte;
  VdbeCursor *pCx = 0;
  nByte = 
      ROUND8(sizeof(VdbeCursor)) + 
      (isBtreeCursor?sqlite3BtreeCursorSize():0) + 
      2*nField*sizeof(u32);

  assert( iCur<p->nCursor );
  if( p->apCsr[iCur] ){
    sqlite3VdbeFreeCursor(p, p->apCsr[iCur]);
    p->apCsr[iCur] = 0;
  }
  if( SQLITE_OK==sqlite3VdbeMemGrow(pMem, nByte, 0) ){
    p->apCsr[iCur] = pCx = (VdbeCursor*)pMem->z;
    memset(pCx, 0, sizeof(VdbeCursor));
    pCx->iDb = iDb;
    pCx->nField = nField;
    if( nField ){
      pCx->aType = (u32 *)&pMem->z[ROUND8(sizeof(VdbeCursor))];
    }
    if( isBtreeCursor ){
      pCx->pCursor = (BtCursor*)
          &pMem->z[ROUND8(sizeof(VdbeCursor))+2*nField*sizeof(u32)];
      sqlite3BtreeCursorZero(pCx->pCursor);
    }
  }
  return pCx;
}

/*
................................................................................
      int v1;    /* Left operand:  0==FALSE, 1==TRUE, 2==UNKNOWN or NULL */
      int v2;    /* Right operand: 0==FALSE, 1==TRUE, 2==UNKNOWN or NULL */
    } an;
    struct OP_IfNot_stack_vars {
      int c;
    } ao;
    struct OP_Column_stack_vars {
      u32 payloadSize;   /* Number of bytes in the record */
      i64 payloadSize64; /* Number of bytes in the record */
      int p1;            /* P1 value of the opcode */
      int p2;            /* column number to retrieve */
      VdbeCursor *pC;    /* The VDBE cursor */
      char *zRec;        /* Pointer to complete record-data */
      BtCursor *pCrsr;   /* The BTree cursor */
      u32 *aType;        /* aType[i] holds the numeric type of the i-th column */
      u32 *aOffset;      /* aOffset[i] is offset to start of data for i-th column */
      int nField;        /* number of fields in the record */
      int len;           /* The length of the serialized data for the column */
      int i;             /* Loop counter */
      char *zData;       /* Part of the record being decoded */
      Mem *pDest;        /* Where to write the extracted value */
      Mem sMem;          /* For storing the record being decoded */
      u8 *zIdx;          /* Index into header */


      u8 *zEndHdr;       /* Pointer to first byte after the header */
      u32 offset;        /* Offset into the data */
      u32 szField;       /* Number of bytes in the content of a field */
      int szHdr;         /* Size of the header size field at start of record */
      int avail;         /* Number of bytes of available data */
      u32 t;             /* A type code from the record header */
      Mem *pReg;         /* PseudoTable input register */
    } ap;
    struct OP_Affinity_stack_vars {
      const char *zAffinity;   /* The affinity to be applied */
      char cAff;               /* A single character of affinity */
    } aq;
................................................................................
      int res;
    } bp;
    struct OP_Rewind_stack_vars {
      VdbeCursor *pC;
      BtCursor *pCrsr;
      int res;
    } bq;
    struct OP_Next_stack_vars {
      VdbeCursor *pC;
      int res;
    } br;
    struct OP_IdxInsert_stack_vars {
      VdbeCursor *pC;
      BtCursor *pCrsr;
      int nKey;
................................................................................
#if 0  /* local variables moved into u.ae */
  char *zMalloc;   /* Holding variable for allocated memory */
  int n;           /* Number of registers left to copy */
  int p1;          /* Register to copy from */
  int p2;          /* Register to copy to */
#endif /* local variables moved into u.ae */

  u.ae.n = pOp->p3 + 1;
  u.ae.p1 = pOp->p1;
  u.ae.p2 = pOp->p2;
  assert( u.ae.n>0 && u.ae.p1>0 && u.ae.p2>0 );
  assert( u.ae.p1+u.ae.n<=u.ae.p2 || u.ae.p2+u.ae.n<=u.ae.p1 );

  pIn1 = &aMem[u.ae.p1];
  pOut = &aMem[u.ae.p2];
  while( u.ae.n-- ){
    assert( pOut<=&aMem[(p->nMem-p->nCursor)] );
    assert( pIn1<=&aMem[(p->nMem-p->nCursor)] );
    assert( memIsValid(pIn1) );
    memAboutToChange(p, pOut);
    u.ae.zMalloc = pOut->zMalloc;
    pOut->zMalloc = 0;
    sqlite3VdbeMemMove(pOut, pIn1);
................................................................................
      pOut->pScopyFrom += u.ae.p1 - pOp->p2;
    }
#endif
    pIn1->zMalloc = u.ae.zMalloc;
    REGISTER_TRACE(u.ae.p2++, pOut);
    pIn1++;
    pOut++;
  }
  break;
}

/* Opcode: Copy P1 P2 P3 * *
** Synopsis: r[P2@P3]=r[P1@P3]
**
** Make a copy of registers P1..P1+P3 into registers P2..P2+P3.
................................................................................
    Deephemeralize(u.aj.pArg);
    sqlite3VdbeMemStoreType(u.aj.pArg);
    REGISTER_TRACE(pOp->p2+u.aj.i, u.aj.pArg);
  }

  assert( pOp->p4type==P4_FUNCDEF );
  u.aj.ctx.pFunc = pOp->p4.pFunc;
  u.aj.ctx.s.flags = MEM_Null;
  u.aj.ctx.s.db = db;
  u.aj.ctx.s.xDel = 0;
  u.aj.ctx.s.zMalloc = 0;
  u.aj.ctx.iOp = pc;
  u.aj.ctx.pVdbe = p;

  /* The output cell may already have a buffer allocated. Move
  ** the pointer to u.aj.ctx.s so in case the user-function can use
  ** the already allocated buffer instead of allocating a new one.
  */
  sqlite3VdbeMemMove(&u.aj.ctx.s, pOut);



  MemSetTypeFlag(&u.aj.ctx.s, MEM_Null);

  u.aj.ctx.fErrorOrAux = 0;
  if( u.aj.ctx.pFunc->funcFlags & SQLITE_FUNC_NEEDCOLL ){
    assert( pOp>aOp );
    assert( pOp[-1].p4type==P4_COLLSEQ );
    assert( pOp[-1].opcode==OP_CollSeq );
................................................................................
      rc = u.aj.ctx.isError;
    }
    sqlite3VdbeDeleteAuxData(p, pc, pOp->p1);
  }

  /* Copy the result of the function into register P3 */
  sqlite3VdbeChangeEncoding(&u.aj.ctx.s, encoding);

  sqlite3VdbeMemMove(pOut, &u.aj.ctx.s);
  if( sqlite3VdbeMemTooBig(pOut) ){
    goto too_big;
  }

#if 0
  /* The app-defined function has done something that as caused this
  ** statement to expire.  (Perhaps the function called sqlite3_exec()
................................................................................
** Force the value in register P1 to be an integer.  If the value
** in P1 is not an integer and cannot be converted into an integer
** 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];

  applyAffinity(pIn1, SQLITE_AFF_NUMERIC, encoding);
  if( (pIn1->flags & MEM_Int)==0 ){
    if( pOp->p2==0 ){
      rc = SQLITE_MISMATCH;
      goto abort_due_to_error;
    }else{
      pc = pOp->p2 - 1;

    }
  }else{
    MemSetTypeFlag(pIn1, MEM_Int);
  }


  break;
}

#ifndef SQLITE_OMIT_FLOATING_POINT
/* Opcode: RealAffinity P1 * * * *
**
** If register P1 holds an integer convert it to a real value.
................................................................................
** If the OPFLAG_LENGTHARG and OPFLAG_TYPEOFARG bits are set on P5 when
** the result is guaranteed to only be used as the argument of a length()
** or typeof() function, respectively.  The loading of large blobs can be
** skipped for length() and all content loading can be skipped for typeof().
*/
case OP_Column: {
#if 0  /* local variables moved into u.ap */
  u32 payloadSize;   /* Number of bytes in the record */
  i64 payloadSize64; /* Number of bytes in the record */
  int p1;            /* P1 value of the opcode */
  int p2;            /* column number to retrieve */
  VdbeCursor *pC;    /* The VDBE cursor */
  char *zRec;        /* Pointer to complete record-data */
  BtCursor *pCrsr;   /* The BTree cursor */
  u32 *aType;        /* aType[i] holds the numeric type of the i-th column */
  u32 *aOffset;      /* aOffset[i] is offset to start of data for i-th column */
  int nField;        /* number of fields in the record */
  int len;           /* The length of the serialized data for the column */
  int i;             /* Loop counter */
  char *zData;       /* Part of the record being decoded */
  Mem *pDest;        /* Where to write the extracted value */
  Mem sMem;          /* For storing the record being decoded */
  u8 *zIdx;          /* Index into header */


  u8 *zEndHdr;       /* Pointer to first byte after the header */
  u32 offset;        /* Offset into the data */
  u32 szField;       /* Number of bytes in the content of a field */
  int szHdr;         /* Size of the header size field at start of record */
  int avail;         /* Number of bytes of available data */
  u32 t;             /* A type code from the record header */
  Mem *pReg;         /* PseudoTable input register */
#endif /* local variables moved into u.ap */


  u.ap.p1 = pOp->p1;
  u.ap.p2 = pOp->p2;
  u.ap.pC = 0;
  memset(&u.ap.sMem, 0, sizeof(u.ap.sMem));
  assert( u.ap.p1<p->nCursor );
  assert( pOp->p3>0 && pOp->p3<=(p->nMem-p->nCursor) );
  u.ap.pDest = &aMem[pOp->p3];
  memAboutToChange(p, u.ap.pDest);
  u.ap.zRec = 0;

  /* This block sets the variable u.ap.payloadSize to be the total number of
  ** bytes in the record.
  **
  ** u.ap.zRec is set to be the complete text of the record if it is available.
  ** The complete record text is always available for pseudo-tables
  ** If the record is stored in a cursor, the complete record text
  ** might be available in the  u.ap.pC->aRow cache.  Or it might not be.
  ** If the data is unavailable,  u.ap.zRec is set to NULL.
  **
  ** We also compute the number of columns in the record.  For cursors,
  ** the number of columns is stored in the VdbeCursor.nField element.
  */
  u.ap.pC = p->apCsr[u.ap.p1];
  assert( u.ap.pC!=0 );
#ifndef SQLITE_OMIT_VIRTUALTABLE
  assert( u.ap.pC->pVtabCursor==0 );
#endif
  u.ap.pCrsr = u.ap.pC->pCursor;
  if( u.ap.pCrsr!=0 ){
    /* The record is stored in a B-Tree */
    rc = sqlite3VdbeCursorMoveto(u.ap.pC);
    if( rc ) goto abort_due_to_error;
    if( u.ap.pC->nullRow ){
      u.ap.payloadSize = 0;
    }else if( u.ap.pC->cacheStatus==p->cacheCtr ){
      u.ap.payloadSize = u.ap.pC->payloadSize;
      u.ap.zRec = (char*)u.ap.pC->aRow;
    }else if( u.ap.pC->isIndex ){
      assert( sqlite3BtreeCursorIsValid(u.ap.pCrsr) );
      VVA_ONLY(rc =) sqlite3BtreeKeySize(u.ap.pCrsr, &u.ap.payloadSize64);
      assert( rc==SQLITE_OK );   /* True because of CursorMoveto() call above */
      /* sqlite3BtreeParseCellPtr() uses getVarint32() to extract the
      ** payload size, so it is impossible for u.ap.payloadSize64 to be
      ** larger than 32 bits. */
      assert( (u.ap.payloadSize64 & SQLITE_MAX_U32)==(u64)u.ap.payloadSize64 );
      u.ap.payloadSize = (u32)u.ap.payloadSize64;
    }else{
      assert( sqlite3BtreeCursorIsValid(u.ap.pCrsr) );
      VVA_ONLY(rc =) sqlite3BtreeDataSize(u.ap.pCrsr, &u.ap.payloadSize);
      assert( rc==SQLITE_OK );   /* DataSize() cannot fail */
    }
  }else{
    assert( u.ap.pC->pseudoTableReg>0 );
    u.ap.pReg = &aMem[u.ap.pC->pseudoTableReg];
    if( u.ap.pC->multiPseudo ){
      sqlite3VdbeMemShallowCopy(u.ap.pDest, u.ap.pReg+u.ap.p2, MEM_Ephem);
      Deephemeralize(u.ap.pDest);
      goto op_column_out;
    }
    assert( u.ap.pReg->flags & MEM_Blob );
    assert( memIsValid(u.ap.pReg) );
    u.ap.payloadSize = u.ap.pReg->n;
    u.ap.zRec = u.ap.pReg->z;
    u.ap.pC->cacheStatus = (pOp->p5&OPFLAG_CLEARCACHE) ? CACHE_STALE : p->cacheCtr;
    assert( u.ap.payloadSize==0 || u.ap.zRec!=0 );
  }

  /* If u.ap.payloadSize is 0, then just store a NULL.  This can happen because of
  ** nullRow or because of a corrupt database. */
  if( u.ap.payloadSize==0 ){
    MemSetTypeFlag(u.ap.pDest, MEM_Null);
    goto op_column_out;
  }
  assert( db->aLimit[SQLITE_LIMIT_LENGTH]>=0 );
  if( u.ap.payloadSize > (u32)db->aLimit[SQLITE_LIMIT_LENGTH] ){
    goto too_big;
  }

  u.ap.nField = u.ap.pC->nField;
  assert( u.ap.p2<u.ap.nField );

  /* Read and parse the table header.  Store the results of the parse
  ** into the record header cache fields of the cursor.
  */
  u.ap.aType = u.ap.pC->aType;
  if( u.ap.pC->cacheStatus==p->cacheCtr ){
    u.ap.aOffset = u.ap.pC->aOffset;
  }else{
    assert(u.ap.aType);
    u.ap.avail = 0;
    u.ap.pC->aOffset = u.ap.aOffset = &u.ap.aType[u.ap.nField];
    u.ap.pC->payloadSize = u.ap.payloadSize;
    u.ap.pC->cacheStatus = p->cacheCtr;

    /* Figure out how many bytes are in the header */
    if( u.ap.zRec ){
      u.ap.zData = u.ap.zRec;
    }else{
      if( u.ap.pC->isIndex ){
        u.ap.zData = (char*)sqlite3BtreeKeyFetch(u.ap.pCrsr, &u.ap.avail);
      }else{
        u.ap.zData = (char*)sqlite3BtreeDataFetch(u.ap.pCrsr, &u.ap.avail);
      }
      /* If KeyFetch()/DataFetch() managed to get the entire payload,
      ** save the payload in the u.ap.pC->aRow cache.  That will save us from
      ** having to make additional calls to fetch the content portion of
      ** the record.
      */
      assert( u.ap.avail>=0 );
      if( u.ap.payloadSize <= (u32)u.ap.avail ){
        u.ap.zRec = u.ap.zData;
        u.ap.pC->aRow = (u8*)u.ap.zData;
      }else{
        u.ap.pC->aRow = 0;
      }
    }
    /* The following assert is true in all cases except when
    ** the database file has been corrupted externally.
    **    assert( u.ap.zRec!=0 || u.ap.avail>=u.ap.payloadSize || u.ap.avail>=9 ); */
    u.ap.szHdr = getVarint32((u8*)u.ap.zData, u.ap.offset);

    /* Make sure a corrupt database has not given us an oversize header.
    ** Do this now to avoid an oversize memory allocation.
    **
    ** Type entries can be between 1 and 5 bytes each.  But 4 and 5 byte
    ** types use so much data space that there can only be 4096 and 32 of
    ** them, respectively.  So the maximum header length results from a
    ** 3-byte type for each of the maximum of 32768 columns plus three
    ** extra bytes for the header length itself.  32768*3 + 3 = 98307.
    */
    if( u.ap.offset > 98307 ){
      rc = SQLITE_CORRUPT_BKPT;
      goto op_column_out;
    }

    /* Compute in u.ap.len the number of bytes of data we need to read in order

    ** to get u.ap.nField type values.  u.ap.offset is an upper bound on this.  But
    ** u.ap.nField might be significantly less than the true number of columns
    ** in the table, and in that case, 5*u.ap.nField+3 might be smaller than u.ap.offset.
    ** We want to minimize u.ap.len in order to limit the size of the memory
    ** allocation, especially if a corrupt database file has caused u.ap.offset
    ** to be oversized. Offset is limited to 98307 above.  But 98307 might
    ** still exceed Robson memory allocation limits on some configurations.
    ** On systems that cannot tolerate large memory allocations, u.ap.nField*5+3
    ** will likely be much smaller since u.ap.nField will likely be less than
    ** 20 or so.  This insures that Robson memory allocation limits are
    ** not exceeded even for corrupt database files.
    */
    u.ap.len = u.ap.nField*5 + 3;
    if( u.ap.len > (int)u.ap.offset ) u.ap.len = (int)u.ap.offset;

    /* The KeyFetch() or DataFetch() above are fast and will get the entire
    ** record header in most cases.  But they will fail to get the complete
    ** record header if the record header does not fit on a single page
    ** in the B-Tree.  When that happens, use sqlite3VdbeMemFromBtree() to
    ** acquire the complete header text.



    */
    if( !u.ap.zRec && u.ap.avail<u.ap.len ){
      u.ap.sMem.flags = 0;
      u.ap.sMem.db = 0;




      rc = sqlite3VdbeMemFromBtree(u.ap.pCrsr, 0, u.ap.len, u.ap.pC->isIndex, &u.ap.sMem);

      if( rc!=SQLITE_OK ){
        goto op_column_out;
      }


      u.ap.zData = u.ap.sMem.z;
    }
    u.ap.zEndHdr = (u8 *)&u.ap.zData[u.ap.len];
    u.ap.zIdx = (u8 *)&u.ap.zData[u.ap.szHdr];

    /* Scan the header and use it to fill in the u.ap.aType[] and u.ap.aOffset[]
    ** arrays.  u.ap.aType[u.ap.i] will contain the type integer for the u.ap.i-th


    ** column and u.ap.aOffset[u.ap.i] will contain the u.ap.offset from the beginning
    ** of the record to the start of the data for the u.ap.i-th column
    */
    for(u.ap.i=0; u.ap.i<u.ap.nField; u.ap.i++){

      if( u.ap.zIdx<u.ap.zEndHdr ){
        u.ap.aOffset[u.ap.i] = u.ap.offset;


        if( u.ap.zIdx[0]<0x80 ){
          u.ap.t = u.ap.zIdx[0];
          u.ap.zIdx++;
        }else{
          u.ap.zIdx += sqlite3GetVarint32(u.ap.zIdx, &u.ap.t);
        }
        u.ap.aType[u.ap.i] = u.ap.t;
        u.ap.szField = sqlite3VdbeSerialTypeLen(u.ap.t);
        u.ap.offset += u.ap.szField;
        if( u.ap.offset<u.ap.szField ){  /* True if u.ap.offset overflows */
          u.ap.zIdx = &u.ap.zEndHdr[1];  /* Forces SQLITE_CORRUPT return below */
          break;
        }
      }else{
        /* If u.ap.i is less that u.ap.nField, then there are fewer fields in this
        ** record than SetNumColumns indicated there are columns in the
        ** table. Set the u.ap.offset for any extra columns not present in
        ** the record to 0. This tells code below to store the default value
        ** for the column instead of deserializing a value from the record.
        */

        u.ap.aOffset[u.ap.i] = 0;
      }
    }




    sqlite3VdbeMemRelease(&u.ap.sMem);
    u.ap.sMem.flags = MEM_Null;


    /* If we have read more header data than was contained in the header,
    ** or if the end of the last field appears to be past the end of the
    ** record, or if the end of the last field appears to be before the end
    ** of the record (when all fields present), then we must be dealing
    ** with a corrupt database.
    */

    if( (u.ap.zIdx > u.ap.zEndHdr) || (u.ap.offset > u.ap.payloadSize)
         || (u.ap.zIdx==u.ap.zEndHdr && u.ap.offset!=u.ap.payloadSize) ){

      rc = SQLITE_CORRUPT_BKPT;














      goto op_column_out;
    }
  }

  /* Get the column information. If u.ap.aOffset[u.ap.p2] is non-zero, then
  ** deserialize the value from the record. If u.ap.aOffset[u.ap.p2] is zero,
  ** then there are not enough fields in the record to satisfy the
  ** request.  In this case, set the value NULL or to P4 if P4 is
  ** a pointer to a Mem object.
  */
  if( u.ap.aOffset[u.ap.p2] ){

    assert( rc==SQLITE_OK );
    if( u.ap.zRec ){

      /* This is the common case where the whole row fits on a single page */

      VdbeMemRelease(u.ap.pDest);
      sqlite3VdbeSerialGet((u8 *)&u.ap.zRec[u.ap.aOffset[u.ap.p2]], u.ap.aType[u.ap.p2], u.ap.pDest);
    }else{
      /* This branch happens only when the row overflows onto multiple pages */
      u.ap.t = u.ap.aType[u.ap.p2];
      if( (pOp->p5 & (OPFLAG_LENGTHARG|OPFLAG_TYPEOFARG))!=0
       && ((u.ap.t>=12 && (u.ap.t&1)==0) || (pOp->p5 & OPFLAG_TYPEOFARG)!=0)

      ){
        /* Content is irrelevant for the typeof() function and for
        ** the length(X) function if X is a blob.  So we might as well use
        ** bogus content rather than reading content from disk.  NULL works
        ** for text and blob and whatever is in the u.ap.payloadSize64 variable
        ** will work for everything else. */

        u.ap.zData = u.ap.t<12 ? (char*)&u.ap.payloadSize64 : 0;

      }else{
        u.ap.len = sqlite3VdbeSerialTypeLen(u.ap.t);

        sqlite3VdbeMemMove(&u.ap.sMem, u.ap.pDest);
        rc = sqlite3VdbeMemFromBtree(u.ap.pCrsr, u.ap.aOffset[u.ap.p2], u.ap.len,  u.ap.pC->isIndex,
                                     &u.ap.sMem);
        if( rc!=SQLITE_OK ){
          goto op_column_out;
        }
        u.ap.zData = u.ap.sMem.z;
      }
      sqlite3VdbeSerialGet((u8*)u.ap.zData, u.ap.t, u.ap.pDest);
    }
    u.ap.pDest->enc = encoding;
  }else{
    if( pOp->p4type==P4_MEM ){
      sqlite3VdbeMemShallowCopy(u.ap.pDest, pOp->p4.pMem, MEM_Static);
    }else{
      MemSetTypeFlag(u.ap.pDest, MEM_Null);
    }
  }

  /* If we dynamically allocated space to hold the data (in the
  ** sqlite3VdbeMemFromBtree() call above) then transfer control of that
  ** dynamically allocated space over to the u.ap.pDest structure.
  ** This prevents a memory copy.
  */
  if( u.ap.sMem.zMalloc ){
    assert( u.ap.sMem.z==u.ap.sMem.zMalloc );
    assert( !(u.ap.pDest->flags & MEM_Dyn) );
    assert( !(u.ap.pDest->flags & (MEM_Blob|MEM_Str)) || u.ap.pDest->z==u.ap.sMem.z );
    u.ap.pDest->flags &= ~(MEM_Ephem|MEM_Static);
    u.ap.pDest->flags |= MEM_Term;
    u.ap.pDest->z = u.ap.sMem.z;
    u.ap.pDest->zMalloc = u.ap.sMem.zMalloc;
  }

  rc = sqlite3VdbeMemMakeWriteable(u.ap.pDest);


op_column_out:


  UPDATE_MAX_BLOBSIZE(u.ap.pDest);
  REGISTER_TRACE(pOp->p3, u.ap.pDest);
  break;
}

/* Opcode: Affinity P1 P2 * P4 *
** Synopsis: affinity(r[P1@P2])
................................................................................
    assert( u.az.pKeyInfo->enc==ENC(db) );
    assert( u.az.pKeyInfo->db==db );
    u.az.nField = u.az.pKeyInfo->nField+u.az.pKeyInfo->nXField;
  }else if( pOp->p4type==P4_INT32 ){
    u.az.nField = pOp->p4.i;
  }
  assert( pOp->p1>=0 );


  u.az.pCur = allocateCursor(p, pOp->p1, u.az.nField, u.az.iDb, 1);
  if( u.az.pCur==0 ) goto no_mem;
  u.az.pCur->nullRow = 1;
  u.az.pCur->isOrdered = 1;
  rc = sqlite3BtreeCursor(u.az.pX, u.az.p2, u.az.wrFlag, u.az.pKeyInfo, u.az.pCur->pCursor);
  u.az.pCur->pKeyInfo = u.az.pKeyInfo;
  assert( OPFLAG_BULKCSR==BTREE_BULKLOAD );
  sqlite3BtreeCursorHints(u.az.pCur->pCursor, (pOp->p5 & OPFLAG_BULKCSR));

  /* Since it performs no memory allocation or IO, the only value that
  ** sqlite3BtreeCursor() may return is SQLITE_OK. */
  assert( rc==SQLITE_OK );

  /* Set the VdbeCursor.isTable and isIndex variables. Previous versions of
  ** SQLite used to check if the root-page flags were sane at this point
  ** and report database corruption if they were not, but this check has
  ** since moved into the btree layer.  */
  u.az.pCur->isTable = pOp->p4type!=P4_KEYINFO;
  u.az.pCur->isIndex = !u.az.pCur->isTable;
  break;
}

/* Opcode: OpenEphemeral P1 P2 * P4 P5
** Synopsis: nColumn=P2
**
** Open a new cursor P1 to a transient table.
................................................................................
  static const int vfsFlags =
      SQLITE_OPEN_READWRITE |
      SQLITE_OPEN_CREATE |
      SQLITE_OPEN_EXCLUSIVE |
      SQLITE_OPEN_DELETEONCLOSE |
      SQLITE_OPEN_TRANSIENT_DB;
  assert( pOp->p1>=0 );

  u.ba.pCx = allocateCursor(p, pOp->p1, pOp->p2, -1, 1);
  if( u.ba.pCx==0 ) goto no_mem;
  u.ba.pCx->nullRow = 1;
  rc = sqlite3BtreeOpen(db->pVfs, 0, db, &u.ba.pCx->pBt,
                        BTREE_OMIT_JOURNAL | BTREE_SINGLE | pOp->p5, vfsFlags);
  if( rc==SQLITE_OK ){
    rc = sqlite3BtreeBeginTrans(u.ba.pCx->pBt, 1);
................................................................................
      u.ba.pCx->isTable = 0;
    }else{
      rc = sqlite3BtreeCursor(u.ba.pCx->pBt, MASTER_ROOT, 1, 0, u.ba.pCx->pCursor);
      u.ba.pCx->isTable = 1;
    }
  }
  u.ba.pCx->isOrdered = (pOp->p5!=BTREE_UNORDERED);
  u.ba.pCx->isIndex = !u.ba.pCx->isTable;
  break;
}

/* Opcode: SorterOpen P1 * * P4 *
**
** This opcode works like OP_OpenEphemeral except that it opens
** a transient index that is specifically designed to sort large
................................................................................
** tables using an external merge-sort algorithm.
*/
case OP_SorterOpen: {
#if 0  /* local variables moved into u.bb */
  VdbeCursor *pCx;
#endif /* local variables moved into u.bb */



  u.bb.pCx = allocateCursor(p, pOp->p1, pOp->p2, -1, 1);
  if( u.bb.pCx==0 ) goto no_mem;
  u.bb.pCx->pKeyInfo = pOp->p4.pKeyInfo;
  assert( u.bb.pCx->pKeyInfo->db==db );
  assert( u.bb.pCx->pKeyInfo->enc==ENC(db) );
  u.bb.pCx->isSorter = 1;
  rc = sqlite3VdbeSorterInit(db, u.bb.pCx);
  break;
}

/* Opcode: OpenPseudo P1 P2 P3 * P5
** Synopsis: content in r[P2@P3]
**
................................................................................
*/
case OP_OpenPseudo: {
#if 0  /* local variables moved into u.bc */
  VdbeCursor *pCx;
#endif /* local variables moved into u.bc */

  assert( pOp->p1>=0 );

  u.bc.pCx = allocateCursor(p, pOp->p1, pOp->p3, -1, 0);
  if( u.bc.pCx==0 ) goto no_mem;
  u.bc.pCx->nullRow = 1;
  u.bc.pCx->pseudoTableReg = pOp->p2;
  u.bc.pCx->isTable = 1;
  u.bc.pCx->isIndex = 0;
  u.bc.pCx->multiPseudo = pOp->p5;
  break;
}

/* Opcode: Close P1 * * * *
**
** Close a cursor previously opened as P1.  If P1 is not
................................................................................
case OP_SorterData: {
#if 0  /* local variables moved into u.bl */
  VdbeCursor *pC;
#endif /* local variables moved into u.bl */

  pOut = &aMem[pOp->p2];
  u.bl.pC = p->apCsr[pOp->p1];
  assert( u.bl.pC->isSorter );
  rc = sqlite3VdbeSorterRowkey(u.bl.pC, pOut);
  break;
}

/* Opcode: RowData P1 P2 * * *
** Synopsis: r[P2]=data
**
................................................................................

  pOut = &aMem[pOp->p2];
  memAboutToChange(p, pOut);

  /* Note that RowKey and RowData are really exactly the same instruction */
  assert( pOp->p1>=0 && pOp->p1<p->nCursor );
  u.bm.pC = p->apCsr[pOp->p1];
  assert( u.bm.pC->isSorter==0 );
  assert( u.bm.pC->isTable || pOp->opcode!=OP_RowData );
  assert( u.bm.pC->isIndex || pOp->opcode==OP_RowData );
  assert( u.bm.pC!=0 );
  assert( u.bm.pC->nullRow==0 );
  assert( u.bm.pC->pseudoTableReg==0 );
  assert( u.bm.pC->pCursor!=0 );
  u.bm.pCrsr = u.bm.pC->pCursor;
  assert( sqlite3BtreeCursorIsValid(u.bm.pCrsr) );

................................................................................
  ** the cursor.  Hence the following sqlite3VdbeCursorMoveto() call is always
  ** a no-op and can never fail.  But we leave it in place as a safety.
  */
  assert( u.bm.pC->deferredMoveto==0 );
  rc = sqlite3VdbeCursorMoveto(u.bm.pC);
  if( NEVER(rc!=SQLITE_OK) ) goto abort_due_to_error;

  if( u.bm.pC->isIndex ){
    assert( !u.bm.pC->isTable );
    VVA_ONLY(rc =) sqlite3BtreeKeySize(u.bm.pCrsr, &u.bm.n64);
    assert( rc==SQLITE_OK );    /* True because of CursorMoveto() call above */
    if( u.bm.n64>db->aLimit[SQLITE_LIMIT_LENGTH] ){
      goto too_big;
    }
    u.bm.n = (u32)u.bm.n64;
................................................................................
    }
  }
  if( sqlite3VdbeMemGrow(pOut, u.bm.n, 0) ){
    goto no_mem;
  }
  pOut->n = u.bm.n;
  MemSetTypeFlag(pOut, MEM_Blob);
  if( u.bm.pC->isIndex ){
    rc = sqlite3BtreeKey(u.bm.pCrsr, 0, u.bm.n, pOut->z);
  }else{
    rc = sqlite3BtreeData(u.bm.pCrsr, 0, u.bm.n, pOut->z);
  }
  pOut->enc = SQLITE_UTF8;  /* In case the blob is ever cast to text */
  UPDATE_MAX_BLOBSIZE(pOut);
  REGISTER_TRACE(pOp->p2, pOut);
................................................................................
#endif /* local variables moved into u.bo */

  assert( pOp->p1>=0 && pOp->p1<p->nCursor );
  u.bo.pC = p->apCsr[pOp->p1];
  assert( u.bo.pC!=0 );
  u.bo.pC->nullRow = 1;
  u.bo.pC->rowidIsValid = 0;

  assert( u.bo.pC->pCursor || u.bo.pC->pVtabCursor );
  if( u.bo.pC->pCursor ){
    sqlite3BtreeClearCursor(u.bo.pC->pCursor);
  }
  break;
}

................................................................................
  BtCursor *pCrsr;
  int res;
#endif /* local variables moved into u.bq */

  assert( pOp->p1>=0 && pOp->p1<p->nCursor );
  u.bq.pC = p->apCsr[pOp->p1];
  assert( u.bq.pC!=0 );
  assert( u.bq.pC->isSorter==(pOp->opcode==OP_SorterSort) );
  u.bq.res = 1;
  if( isSorter(u.bq.pC) ){
    rc = sqlite3VdbeSorterRewind(db, u.bq.pC, &u.bq.res);
  }else{
    u.bq.pCrsr = u.bq.pC->pCursor;
    assert( u.bq.pCrsr );
    rc = sqlite3BtreeFirst(u.bq.pCrsr, &u.bq.res);
    u.bq.pC->atFirst = u.bq.res==0 ?1:0;
    u.bq.pC->deferredMoveto = 0;
    u.bq.pC->cacheStatus = CACHE_STALE;
    u.bq.pC->rowidIsValid = 0;
  }
  u.bq.pC->nullRow = (u8)u.bq.res;
  assert( pOp->p2>0 && pOp->p2<p->nOp );
  if( u.bq.res ){
................................................................................
/* Opcode: Next P1 P2 * * P5
**
** Advance cursor P1 so that it points to the next key/data pair in its
** table or index.  If there are no more key/value pairs then fall through
** to the following instruction.  But if the cursor advance was successful,
** jump immediately to P2.
**
** The P1 cursor must be for a real table, not a pseudo-table.

**
** P4 is always of type P4_ADVANCE. The function pointer points to
** sqlite3BtreeNext().
**
** If P5 is positive and the jump is taken, then event counter
** number P5-1 in the prepared statement is incremented.
**
** See also: Prev





*/
/* Opcode: Prev P1 P2 * * P5
**
** Back up cursor P1 so that it points to the previous key/data pair in its
** table or index.  If there is no previous key/value pairs then fall through
** to the following instruction.  But if the cursor backup was successful,
** jump immediately to P2.
**
** The P1 cursor must be for a real table, not a pseudo-table.

**
** P4 is always of type P4_ADVANCE. The function pointer points to
** sqlite3BtreePrevious().
**
** If P5 is positive and the jump is taken, then event counter
** number P5-1 in the prepared statement is incremented.
*/
case OP_SorterNext:    /* jump */
case OP_Prev:          /* jump */
case OP_Next: {        /* jump */



#if 0  /* local variables moved into u.br */
  VdbeCursor *pC;
  int res;
#endif /* local variables moved into u.br */











  assert( pOp->p1>=0 && pOp->p1<p->nCursor );
  assert( pOp->p5<ArraySize(p->aCounter) );
  u.br.pC = p->apCsr[pOp->p1];
  if( u.br.pC==0 ){
    break;  /* See ticket #2273 */
  }
  assert( u.br.pC->isSorter==(pOp->opcode==OP_SorterNext) );
  if( isSorter(u.br.pC) ){
    assert( pOp->opcode==OP_SorterNext );
    rc = sqlite3VdbeSorterNext(db, u.br.pC, &u.br.res);
  }else{
    /* u.br.res = 1; // Always initialized by the xAdvance() call */
    assert( u.br.pC->deferredMoveto==0 );
    assert( u.br.pC->pCursor );
    assert( pOp->opcode!=OP_Next || pOp->p4.xAdvance==sqlite3BtreeNext );
    assert( pOp->opcode!=OP_Prev || pOp->p4.xAdvance==sqlite3BtreePrevious );


    rc = pOp->p4.xAdvance(u.br.pC->pCursor, &u.br.res);
  }
  u.br.pC->nullRow = (u8)u.br.res;

  u.br.pC->cacheStatus = CACHE_STALE;
  if( u.br.res==0 ){

    pc = pOp->p2 - 1;
    p->aCounter[pOp->p5]++;
#ifdef SQLITE_TEST
    sqlite3_search_count++;
#endif


  }
  u.br.pC->rowidIsValid = 0;
  goto check_for_interrupt;
}

/* Opcode: IdxInsert P1 P2 P3 * P5
** Synopsis: key=r[P2]
................................................................................
  int nKey;
  const char *zKey;
#endif /* local variables moved into u.bs */

  assert( pOp->p1>=0 && pOp->p1<p->nCursor );
  u.bs.pC = p->apCsr[pOp->p1];
  assert( u.bs.pC!=0 );
  assert( u.bs.pC->isSorter==(pOp->opcode==OP_SorterInsert) );
  pIn2 = &aMem[pOp->p2];
  assert( pIn2->flags & MEM_Blob );
  u.bs.pCrsr = u.bs.pC->pCursor;
  if( pOp->p5 & OPFLAG_NCHANGE ) p->nChange++;
  assert( u.bs.pCrsr!=0 );
  assert( u.bs.pC->isTable==0 );
  rc = ExpandBlob(pIn2);
................................................................................
    /* Initialize sqlite3_vtab_cursor base class */
    u.cm.pVtabCursor->pVtab = u.cm.pVtab;

    /* Initialize vdbe cursor object */
    u.cm.pCur = allocateCursor(p, pOp->p1, 0, -1, 0);
    if( u.cm.pCur ){
      u.cm.pCur->pVtabCursor = u.cm.pVtabCursor;
      u.cm.pCur->pModule = u.cm.pVtabCursor->pVtab->pModule;
    }else{
      db->mallocFailed = 1;
      u.cm.pModule->xClose(u.cm.pVtabCursor);
    }
  }
  break;
}
................................................................................
  ** triggering asserts related to mutexes.
  */
  assert( v->aVar[0].flags&MEM_Int );
  v->aVar[0].u.i = iRow;

  rc = sqlite3_step(p->pStmt);
  if( rc==SQLITE_ROW ){

    u32 type = v->apCsr[0]->aType[p->iCol];
    if( type<12 ){
      zErr = sqlite3MPrintf(p->db, "cannot open value of type %s",
          type==0?"null": type==7?"real": "integer"
      );
      rc = SQLITE_ERROR;
      sqlite3_finalize(p->pStmt);
      p->pStmt = 0;
    }else{
      p->iOffset = v->apCsr[0]->aOffset[p->iCol];
      p->nByte = sqlite3VdbeSerialTypeLen(type);
      p->pCsr =  v->apCsr[0]->pCursor;
      sqlite3BtreeEnterCursor(p->pCsr);
      sqlite3BtreeCacheOverflow(p->pCsr);
      sqlite3BtreeLeaveCursor(p->pCsr);
    }
  }

  if( rc==SQLITE_ROW ){
................................................................................
        zColumn = pRight->pRight->u.zToken;
      }
      return lookupName(pParse, zDb, zTable, zColumn, pNC, pExpr);
    }

    /* Resolve function names
    */
    case TK_CONST_FUNC:
    case TK_FUNCTION: {
      ExprList *pList = pExpr->x.pList;    /* The argument list */
      int n = pList ? pList->nExpr : 0;    /* Number of arguments */
      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 auth;                   /* Authorization to use the 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 */

      testcase( pExpr->op==TK_CONST_FUNC );
      assert( !ExprHasProperty(pExpr, EP_xIsSelect) );
      notValidPartIdxWhere(pParse, pNC, "functions");
      zId = pExpr->u.zToken;
      nId = sqlite3Strlen30(zId);
      pDef = sqlite3FindFunction(pParse->db, zId, nId, n, enc, 0);
      if( pDef==0 ){
        pDef = sqlite3FindFunction(pParse->db, zId, nId, -2, enc, 0);
................................................................................
            sqlite3ErrorMsg(pParse, "not authorized to use function: %s",
                                    pDef->zName);
            pNC->nErr++;
          }
          pExpr->op = TK_NULL;
          return WRC_Prune;
        }

      }
#endif
      if( is_agg && (pNC->ncFlags & NC_AllowAgg)==0 ){
        sqlite3ErrorMsg(pParse, "misuse of aggregate function %.*s()", nId,zId);
        pNC->nErr++;
        is_agg = 0;
      }else if( no_such_func && pParse->db->init.busy==0 ){
................................................................................
  if( pWalker->u.i==3 && ExprHasProperty(pExpr, EP_FromJoin) ){
    pWalker->u.i = 0;
    return WRC_Abort;
  }

  switch( pExpr->op ){
    /* Consider functions to be constant if all their arguments are constant
    ** and pWalker->u.i==2 */

    case TK_FUNCTION:
      if( pWalker->u.i==2 ) return 0;


      /* Fall through */
    case TK_ID:
    case TK_COLUMN:
    case TK_AGG_FUNCTION:
    case TK_AGG_COLUMN:
      testcase( pExpr->op==TK_ID );
      testcase( pExpr->op==TK_COLUMN );
................................................................................
        assert( !ExprHasProperty(pExpr, EP_IntValue) );
        sqlite3ErrorMsg(pParse, "misuse of aggregate: %s()", pExpr->u.zToken);
      }else{
        inReg = pInfo->aFunc[pExpr->iAgg].iMem;
      }
      break;
    }
    case TK_CONST_FUNC:
    case TK_FUNCTION: {
      ExprList *pFarg;       /* List of function arguments */
      int nFarg;             /* Number of function arguments */
      FuncDef *pDef;         /* The function definition object */
      int nId;               /* Length of the function name in bytes */
      const char *zId;       /* The function name */
      int constMask = 0;     /* Mask of function arguments that are constant */
      int i;                 /* Loop counter */
      u8 enc = ENC(db);      /* The text encoding used by this database */
      CollSeq *pColl = 0;    /* A collating sequence */

      assert( !ExprHasProperty(pExpr, EP_xIsSelect) );
      testcase( op==TK_CONST_FUNC );
      testcase( op==TK_FUNCTION );
      if( ExprHasProperty(pExpr, EP_TokenOnly) ){
        pFarg = 0;
      }else{
        pFarg = pExpr->x.pList;
      }
      nFarg = pFarg ? pFarg->nExpr : 0;
      assert( !ExprHasProperty(pExpr, EP_IntValue) );
................................................................................
      */
      if( pDef->funcFlags & SQLITE_FUNC_UNLIKELY ){
        assert( nFarg>=1 );
        sqlite3ExprCode(pParse, pFarg->a[0].pExpr, target);
        break;
      }









      if( pFarg ){




        r1 = sqlite3GetTempRange(pParse, nFarg);


        /* For length() and typeof() functions with a column argument,
        ** set the P5 parameter to the OP_Column opcode to OPFLAG_LENGTHARG
        ** or OPFLAG_TYPEOFARG respectively, to avoid unnecessary data
        ** loading.
        */
        if( (pDef->funcFlags & (SQLITE_FUNC_LENGTH|SQLITE_FUNC_TYPEOF))!=0 ){
................................................................................
          u8 exprOp;
          assert( nFarg==1 );
          assert( pFarg->a[0].pExpr!=0 );
          exprOp = pFarg->a[0].pExpr->op;
          if( exprOp==TK_COLUMN || exprOp==TK_AGG_COLUMN ){
            assert( SQLITE_FUNC_LENGTH==OPFLAG_LENGTHARG );
            assert( SQLITE_FUNC_TYPEOF==OPFLAG_TYPEOFARG );
            testcase( (pDef->funcFlags&~SQLITE_FUNC_ENCMASK)
                       ==SQLITE_FUNC_LENGTH );
            pFarg->a[0].pExpr->op2 = pDef->funcFlags&~SQLITE_FUNC_ENCMASK;
          }
        }

        sqlite3ExprCachePush(pParse);     /* Ticket 2ea2425d34be */
        sqlite3ExprCodeExprList(pParse, pFarg, r1, 1);

        sqlite3ExprCachePop(pParse, 1);   /* Ticket 2ea2425d34be */
      }else{
        r1 = 0;
      }
#ifndef SQLITE_OMIT_VIRTUALTABLE
      /* Possibly overload the function if the first argument is
      ** a virtual table column.
................................................................................
      */
      if( nFarg>=2 && (pExpr->flags & EP_InfixFunc) ){
        pDef = sqlite3VtabOverloadFunction(db, pDef, nFarg, pFarg->a[1].pExpr);
      }else if( nFarg>0 ){
        pDef = sqlite3VtabOverloadFunction(db, pDef, nFarg, pFarg->a[0].pExpr);
      }
#endif
      for(i=0; i<nFarg; i++){
        if( i<32 && sqlite3ExprIsConstant(pFarg->a[i].pExpr) ){
          constMask |= (1<<i);
        }
        if( (pDef->funcFlags & SQLITE_FUNC_NEEDCOLL)!=0 && !pColl ){
          pColl = sqlite3ExprCollSeq(pParse, pFarg->a[i].pExpr);
        }
      }
      if( pDef->funcFlags & SQLITE_FUNC_NEEDCOLL ){
        if( !pColl ) pColl = db->pDfltColl; 
        sqlite3VdbeAddOp4(v, OP_CollSeq, 0, 0, 0, (char *)pColl, P4_COLLSEQ);
      }
      sqlite3VdbeAddOp4(v, OP_Function, constMask, r1, target,
                        (char*)pDef, P4_FUNCDEF);
      sqlite3VdbeChangeP5(v, (u8)nFarg);
      if( nFarg ){
        sqlite3ReleaseTempRange(pParse, r1, nFarg);
      }
      break;
    }
#ifndef SQLITE_OMIT_SUBQUERY
    case TK_EXISTS:
    case TK_SELECT: {
................................................................................
    }
#endif
  }
  sqlite3ReleaseTempReg(pParse, regFree1);
  sqlite3ReleaseTempReg(pParse, regFree2);
  return inReg;
}























/*
** Generate code to evaluate an expression and store the results
** into a register.  Return the register number where the results
** are stored.
**
** If the register is a temporary register that can be deallocated,
................................................................................
** If pExpr is a constant, then this routine might generate this
** code to fill the register in the initialization section of the
** VDBE program, in order to factor it out of the evaluation loop.
*/
SQLITE_PRIVATE int sqlite3ExprCodeTemp(Parse *pParse, Expr *pExpr, int *pReg){
  int r2;
  pExpr = sqlite3ExprSkipCollate(pExpr);
  if( pParse->cookieGoto>0
   && pExpr->op!=TK_REGISTER
   && sqlite3ExprIsConstantNotJoin(pExpr)
  ){
    ExprList *p = pParse->pConstExpr;
    int i;
    *pReg  = 0;
    if( p ){
      for(i=0; i<p->nExpr; i++){
        if( sqlite3ExprCompare(p->a[i].pExpr, pExpr, -1)==0 ){

          return p->a[i].u.iConstExprReg;
        }
      }
    }
    p = sqlite3ExprListAppend(pParse, p, sqlite3ExprDup(pParse->db, pExpr, 0));
    pParse->pConstExpr = p;
    r2 = ++pParse->nMem;
    if( p ) p->a[p->nExpr-1].u.iConstExprReg = r2;

  }else{
    int r1 = sqlite3GetTempReg(pParse);
    r2 = sqlite3ExprCodeTarget(pParse, pExpr, r1);
    if( r2==r1 ){
      *pReg = r1;
    }else{
      sqlite3ReleaseTempReg(pParse, r1);
................................................................................
    case TK_COLLATE: {
      sqlite3ExplainExpr(pOut, pExpr->pLeft);
      sqlite3ExplainPrintf(pOut,".COLLATE(%s)",pExpr->u.zToken);
      break;
    }

    case TK_AGG_FUNCTION:
    case TK_CONST_FUNC:
    case TK_FUNCTION: {
      ExprList *pFarg;       /* List of function arguments */
      if( ExprHasProperty(pExpr, EP_TokenOnly) ){
        pFarg = 0;
      }else{
        pFarg = pExpr->x.pList;
      }
................................................................................
#endif /* SQLITE_DEBUG */

/*
** Generate code that pushes the value of every element of the given
** expression list into a sequence of registers beginning at target.
**
** Return the number of elements evaluated.






*/
SQLITE_PRIVATE int sqlite3ExprCodeExprList(
  Parse *pParse,     /* Parsing context */
  ExprList *pList,   /* The expression list to be coded */
  int target,        /* Where to write results */
  int doHardCopy     /* Make a hard copy of every element */
){
  struct ExprList_item *pItem;
  int i, n;

  assert( pList!=0 );
  assert( target>0 );
  assert( pParse->pVdbe!=0 );  /* Never gets this far otherwise */
  n = pList->nExpr;

  for(pItem=pList->a, i=0; i<n; i++, pItem++){
    Expr *pExpr = pItem->pExpr;



    int inReg = sqlite3ExprCodeTarget(pParse, pExpr, target+i);
    if( inReg!=target+i ){
      sqlite3VdbeAddOp2(pParse->pVdbe, doHardCopy ? OP_Copy : OP_SCopy,
                        inReg, target+i);

    }
  }
  return n;
}

/*
** Generate code for a BETWEEN operator.
................................................................................
    FUNCTION(coalesce,           1, 0, 0, 0                ),
    FUNCTION(coalesce,           0, 0, 0, 0                ),
    FUNCTION2(coalesce,         -1, 0, 0, noopFunc,  SQLITE_FUNC_COALESCE),
    FUNCTION(hex,                1, 0, 0, hexFunc          ),
    FUNCTION2(ifnull,            2, 0, 0, noopFunc,  SQLITE_FUNC_COALESCE),
    FUNCTION2(unlikely,          1, 0, 0, noopFunc,  SQLITE_FUNC_UNLIKELY),
    FUNCTION2(likelihood,        2, 0, 0, noopFunc,  SQLITE_FUNC_UNLIKELY),
    FUNCTION(random,             0, 0, 0, randomFunc       ),
    FUNCTION(randomblob,         1, 0, 0, randomBlob       ),
    FUNCTION(nullif,             2, 0, 1, nullifFunc       ),
    FUNCTION(sqlite_version,     0, 0, 0, versionFunc      ),
    FUNCTION(sqlite_source_id,   0, 0, 0, sourceidFunc     ),
    FUNCTION(sqlite_log,         2, 0, 0, errlogFunc       ),
#ifndef SQLITE_OMIT_COMPILEOPTION_DIAGS
    FUNCTION(sqlite_compileoption_used,1, 0, 0, compileoptionusedFunc  ),
    FUNCTION(sqlite_compileoption_get, 1, 0, 0, compileoptiongetFunc  ),
#endif /* SQLITE_OMIT_COMPILEOPTION_DIAGS */
    FUNCTION(quote,              1, 0, 0, quoteFunc        ),
    FUNCTION(last_insert_rowid,  0, 0, 0, last_insert_rowid),
    FUNCTION(changes,            0, 0, 0, changes          ),
    FUNCTION(total_changes,      0, 0, 0, total_changes    ),
    FUNCTION(replace,            3, 0, 0, replaceFunc      ),
    FUNCTION(zeroblob,           1, 0, 0, zeroblobFunc     ),
  #ifdef SQLITE_SOUNDEX
    FUNCTION(soundex,            1, 0, 0, soundexFunc      ),
  #endif
  #ifndef SQLITE_OMIT_LOAD_EXTENSION
    FUNCTION(load_extension,     1, 0, 0, loadExt          ),
................................................................................
      sqlite3VdbeAddOp3(v, OP_Column, srcTab, i, regResult+i);
    }
  }else if( eDest!=SRT_Exists ){
    /* If the destination is an EXISTS(...) expression, the actual
    ** values returned by the SELECT are not required.
    */
    sqlite3ExprCacheClear(pParse);
    sqlite3ExprCodeExprList(pParse, pEList, regResult, eDest==SRT_Output);

  }
  nColumn = nResultCol;

  /* If the DISTINCT keyword was present on the SELECT statement
  ** and this row has been seen before, then do not make this row
  ** part of the result.
  */
................................................................................
    int addrNext = 0;
    int regAgg;
    ExprList *pList = pF->pExpr->x.pList;
    assert( !ExprHasProperty(pF->pExpr, EP_xIsSelect) );
    if( pList ){
      nArg = pList->nExpr;
      regAgg = sqlite3GetTempRange(pParse, nArg);
      sqlite3ExprCodeExprList(pParse, pList, regAgg, 1);
    }else{
      nArg = 0;
      regAgg = 0;
    }
    if( pF->iDistinct>=0 ){
      addrNext = sqlite3VdbeMakeLabel(v);
      assert( nArg==1 );
................................................................................
      pIn += pLevel->u.in.nIn - 1;
      pIn->iCur = iTab;
      if( eType==IN_INDEX_ROWID ){
        pIn->addrInTop = sqlite3VdbeAddOp2(v, OP_Rowid, iTab, iReg);
      }else{
        pIn->addrInTop = sqlite3VdbeAddOp3(v, OP_Column, iTab, 0, iReg);
      }
      pIn->eEndLoopOp = bRev ? OP_Prev : OP_Next;
      sqlite3VdbeAddOp1(v, OP_IsNull, iReg);
    }else{
      pLevel->u.in.nIn = 0;
    }
#endif
  }
  disableTerm(pLevel, pTerm);
................................................................................
{
  yygotominor.yy118.pExpr = sqlite3ExprFunction(pParse, 0, &yymsp[-3].minor.yy0);
  spanSet(&yygotominor.yy118,&yymsp[-3].minor.yy0,&yymsp[0].minor.yy0);
}
        break;
      case 200: /* term ::= CTIME_KW */
{
  /* The CURRENT_TIME, CURRENT_DATE, and CURRENT_TIMESTAMP values are
  ** treated as functions that return constants */
  yygotominor.yy118.pExpr = sqlite3ExprFunction(pParse, 0,&yymsp[0].minor.yy0);
  if( yygotominor.yy118.pExpr ){
    yygotominor.yy118.pExpr->op = TK_CONST_FUNC;  
  }
  spanSet(&yygotominor.yy118, &yymsp[0].minor.yy0, &yymsp[0].minor.yy0);
}
        break;
      case 201: /* expr ::= expr AND expr */
      case 202: /* expr ::= expr OR expr */ yytestcase(yyruleno==202);
      case 203: /* expr ::= expr LT|GT|GE|LE expr */ yytestcase(yyruleno==203);
      case 204: /* expr ::= expr EQ|NE expr */ yytestcase(yyruleno==204);







|







 







<
|
|







 







|
|







 







>
>
|
|
|
|
|
|
|
|
|
|
|
>
|
|
<
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<
<


>
>
|
<
<








|










|


>
>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
>
|
|
<
|
|
|
|
|
|
|
|
<
<





>
>
|
|
|
|







 







|
|
|
|
|
|
|
|



|
|
|
|
|
|
|
>







 







>
>
>
>
>
>
>







 







>












>
>
>







 







>
>
>



|


|


>
|







 







>







 







>







 







>



|
>
>







 







|







 







>
>
>








|

|
|
|
<
<
|
>
|
>
|
<
|
<
|

<


|


<
<
<










|
|
|
|
>
>
>
>







 







|







 







>
>
|
|
|
|
|
|
|
|
|
|
|
>
|
|
<
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<
<


>
>
|
<
<








|










|


>
>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
>
|
|
<
|
|
|
|
|
|
|
|
<
<





>
>
|
|
|
|







 







|







 







|








|







 







|
|




|







 







|







 







|







 







>





|
>







 







|







 







|







 







|







 







|







 







|
|
<











<
<
<


|







 







<

<


<



<


<


<
>
>
|


<
|







 







|







 







|


|




|







 







|







 







<
<
<
<







|
>
>
>







 







>
|







 







>
|
|
|
|
|
|
|
>
|
<
<
|
>
>







 







<

<


<



<


<


<
>
>
|


<
|




<
<

<
<
<



|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<










|

|

|
<
>
|
|
<
<
<
<
<
<
<
<
<
|
<
<
<
<
<
<
<
<
>
>
>

<
<
<
>
>
>
>
|
>
|
|
|
>
>
|
|
<
<

<
<
>
>
|
<
<
<
>
|
<
>
>
|
|
|

|





|


<
<
<
<
<
<
<
>
|
<
<
>
>
>
>
|
|
|
>
|
|
|
|
|
|
>
|
|
>
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>




|
|
|
<
<

<
>
|
<
>
|
>
|
|
|
|
|
|
|
>
|
|
|
|
|
|
>
|
>
|
<
>
|
|
|
|
|
|
|
|
|
<
<
<
<
<
<
<
<
<
<
|
|
|
|
<
|
|
|
|
|
|
|
|
|
|
<
>


>
>







 







>
>













|




<







 







>







 







<







 







>
>





<







 







>





<







 







|







 







|

|







 







|







 







|







 







>







 







|







<







 







|
>







|
>
>
>
>
>








|
>







|
|
|
>
>
>





>
>
>
>
>
>
>
>
>
>



|
<
<
<
<
<
<
<
<
|
|
|
|
>
>
|
<
<
>


>





>
>







 







|







 







<







 







>
|








|

|







 







<












<







 







>







 







|
>

|
>
>







 







<












<
<







 







>
>
>
>
>
>
>
>

>
>
>
>
|
>







 







|
|
|




|
>







 







<
<
<
<
<
<
<
<







|







 







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







 







|







|
|
>
|



<
<

<
>







 







<







 







>
>
>
>
>
>





|



>




>


>
>
>
|
|
|
<
>







 







|
|









|
|
|







 







|
>







 







|







 







|







 







<
<
|
<
<
<







133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
....
8138
8139
8140
8141
8142
8143
8144

8145
8146
8147
8148
8149
8150
8151
8152
8153
....
8775
8776
8777
8778
8779
8780
8781
8782
8783
8784
8785
8786
8787
8788
8789
8790
....
9018
9019
9020
9021
9022
9023
9024
9025
9026
9027
9028
9029
9030
9031
9032
9033
9034
9035
9036
9037
9038
9039
9040

9041
9042
9043
9044
9045
9046
9047
9048
9049
9050
9051
9052
9053
9054
9055
9056
9057
9058
9059
9060
9061
9062
9063
9064
9065
9066
9067
9068
9069
9070
9071
9072
9073
9074
9075
9076
9077
9078
9079
9080
9081
9082
9083
9084
9085
9086
9087


9088
9089
9090
9091
9092


9093
9094
9095
9096
9097
9098
9099
9100
9101
9102
9103
9104
9105
9106
9107
9108
9109
9110
9111
9112
9113
9114
9115
9116
9117
9118
9119
9120
9121
9122
9123
9124
9125
9126
9127
9128
9129
9130
9131
9132
9133
9134
9135
9136
9137
9138
9139
9140
9141
9142
9143
9144
9145
9146
9147
9148
9149
9150
9151
9152

9153
9154
9155
9156
9157
9158
9159
9160


9161
9162
9163
9164
9165
9166
9167
9168
9169
9170
9171
9172
9173
9174
9175
9176
9177
9178
....
9180
9181
9182
9183
9184
9185
9186
9187
9188
9189
9190
9191
9192
9193
9194
9195
9196
9197
9198
9199
9200
9201
9202
9203
9204
9205
9206
9207
9208
9209
9210
9211
9212
.....
10336
10337
10338
10339
10340
10341
10342
10343
10344
10345
10346
10347
10348
10349
10350
10351
10352
10353
10354
10355
10356
.....
10409
10410
10411
10412
10413
10414
10415
10416
10417
10418
10419
10420
10421
10422
10423
10424
10425
10426
10427
10428
10429
10430
10431
10432
10433
10434
10435
10436
10437
10438
.....
10440
10441
10442
10443
10444
10445
10446
10447
10448
10449
10450
10451
10452
10453
10454
10455
10456
10457
10458
10459
10460
10461
10462
10463
10464
10465
10466
10467
.....
11113
11114
11115
11116
11117
11118
11119
11120
11121
11122
11123
11124
11125
11126
11127
.....
11175
11176
11177
11178
11179
11180
11181
11182
11183
11184
11185
11186
11187
11188
11189
.....
12170
12171
12172
12173
12174
12175
12176
12177
12178
12179
12180
12181
12182
12183
12184
12185
12186
12187
12188
12189
12190
.....
13406
13407
13408
13409
13410
13411
13412
13413
13414
13415
13416
13417
13418
13419
13420
.....
13423
13424
13425
13426
13427
13428
13429
13430
13431
13432
13433
13434
13435
13436
13437
13438
13439
13440
13441
13442
13443
13444
13445


13446
13447
13448
13449
13450

13451

13452
13453

13454
13455
13456
13457
13458



13459
13460
13461
13462
13463
13464
13465
13466
13467
13468
13469
13470
13471
13472
13473
13474
13475
13476
13477
13478
13479
13480
13481
13482
13483
.....
13794
13795
13796
13797
13798
13799
13800
13801
13802
13803
13804
13805
13806
13807
13808
.....
22922
22923
22924
22925
22926
22927
22928
22929
22930
22931
22932
22933
22934
22935
22936
22937
22938
22939
22940
22941
22942
22943
22944

22945
22946
22947
22948
22949
22950
22951
22952
22953
22954
22955
22956
22957
22958
22959
22960
22961
22962
22963
22964
22965
22966
22967
22968
22969
22970
22971
22972
22973
22974
22975
22976
22977
22978
22979
22980
22981
22982
22983
22984
22985
22986
22987
22988
22989
22990
22991


22992
22993
22994
22995
22996


22997
22998
22999
23000
23001
23002
23003
23004
23005
23006
23007
23008
23009
23010
23011
23012
23013
23014
23015
23016
23017
23018
23019
23020
23021
23022
23023
23024
23025
23026
23027
23028
23029
23030
23031
23032
23033
23034
23035
23036
23037
23038
23039
23040
23041
23042
23043
23044
23045
23046
23047
23048
23049
23050
23051
23052
23053
23054
23055
23056

23057
23058
23059
23060
23061
23062
23063
23064


23065
23066
23067
23068
23069
23070
23071
23072
23073
23074
23075
23076
23077
23078
23079
23080
23081
23082
.....
54481
54482
54483
54484
54485
54486
54487
54488
54489
54490
54491
54492
54493
54494
54495
.....
54531
54532
54533
54534
54535
54536
54537
54538
54539
54540
54541
54542
54543
54544
54545
54546
54547
54548
54549
54550
54551
54552
54553
54554
.....
60443
60444
60445
60446
60447
60448
60449
60450
60451
60452
60453
60454
60455
60456
60457
60458
60459
60460
60461
60462
60463
.....
60464
60465
60466
60467
60468
60469
60470
60471
60472
60473
60474
60475
60476
60477
60478
.....
60483
60484
60485
60486
60487
60488
60489
60490
60491
60492
60493
60494
60495
60496
60497
.....
61414
61415
61416
61417
61418
61419
61420
61421
61422
61423
61424
61425
61426
61427
61428
61429
61430
61431
61432
61433
61434
61435
.....
62637
62638
62639
62640
62641
62642
62643
62644
62645
62646
62647
62648
62649
62650
62651
.....
63621
63622
63623
63624
63625
63626
63627
63628
63629
63630
63631
63632
63633
63634
63635
.....
64166
64167
64168
64169
64170
64171
64172
64173
64174
64175
64176
64177
64178
64179
64180
.....
64244
64245
64246
64247
64248
64249
64250
64251
64252
64253
64254
64255
64256
64257
64258
.....
66179
66180
66181
66182
66183
66184
66185
66186
66187

66188
66189
66190
66191
66192
66193
66194
66195
66196
66197
66198



66199
66200
66201
66202
66203
66204
66205
66206
66207
66208
.....
66690
66691
66692
66693
66694
66695
66696

66697

66698
66699

66700
66701
66702

66703
66704

66705
66706

66707
66708
66709
66710
66711

66712
66713
66714
66715
66716
66717
66718
66719
.....
66868
66869
66870
66871
66872
66873
66874
66875
66876
66877
66878
66879
66880
66881
66882
.....
67569
67570
67571
67572
67573
67574
67575
67576
67577
67578
67579
67580
67581
67582
67583
67584
67585
67586
67587
67588
67589
67590
67591
.....
67594
67595
67596
67597
67598
67599
67600
67601
67602
67603
67604
67605
67606
67607
67608
.....
67985
67986
67987
67988
67989
67990
67991




67992
67993
67994
67995
67996
67997
67998
67999
68000
68001
68002
68003
68004
68005
68006
68007
68008
68009
.....
68030
68031
68032
68033
68034
68035
68036
68037
68038
68039
68040
68041
68042
68043
68044
68045
.....
68158
68159
68160
68161
68162
68163
68164
68165
68166
68167
68168
68169
68170
68171
68172
68173
68174


68175
68176
68177
68178
68179
68180
68181
68182
68183
68184
.....
68758
68759
68760
68761
68762
68763
68764

68765

68766
68767

68768
68769
68770

68771
68772

68773
68774

68775
68776
68777
68778
68779

68780
68781
68782
68783
68784


68785



68786
68787
68788
68789
68790
68791
68792
68793
68794
68795
68796
68797
68798
68799
68800
68801
68802
68803
68804
68805
68806
68807
68808
68809
68810
68811
68812
68813
68814
68815
68816
68817
68818
68819
68820
68821
68822
68823
68824
68825
68826
68827
68828
68829
68830
68831
68832
68833
68834
68835
68836
68837
68838
68839
68840
68841
68842
68843
68844
68845
68846
68847
68848
68849
68850
68851
68852
68853
68854
68855
68856
68857
68858
68859
68860
68861
68862






































68863
68864
68865
68866
68867
68868
68869
68870
68871
68872
68873
68874
68875
68876
68877

68878
68879
68880









68881








68882
68883
68884
68885



68886
68887
68888
68889
68890
68891
68892
68893
68894
68895
68896
68897
68898


68899


68900
68901
68902



68903
68904

68905
68906
68907
68908
68909
68910
68911
68912
68913
68914
68915
68916
68917
68918
68919







68920
68921


68922
68923
68924
68925
68926
68927
68928
68929
68930
68931
68932
68933
68934
68935
68936
68937
68938
68939
68940
68941
68942
68943
68944
68945
68946
68947
68948
68949
68950
68951
68952
68953
68954
68955
68956
68957
68958
68959
68960
68961


68962

68963
68964

68965
68966
68967
68968
68969
68970
68971
68972
68973
68974
68975
68976
68977
68978
68979
68980
68981
68982
68983
68984
68985

68986
68987
68988
68989
68990
68991
68992
68993
68994
68995










68996
68997
68998
68999

69000
69001
69002
69003
69004
69005
69006
69007
69008
69009

69010
69011
69012
69013
69014
69015
69016
69017
69018
69019
69020
69021
.....
69783
69784
69785
69786
69787
69788
69789
69790
69791
69792
69793
69794
69795
69796
69797
69798
69799
69800
69801
69802
69803
69804
69805
69806
69807
69808
69809

69810
69811
69812
69813
69814
69815
69816
.....
69846
69847
69848
69849
69850
69851
69852
69853
69854
69855
69856
69857
69858
69859
69860
.....
69879
69880
69881
69882
69883
69884
69885

69886
69887
69888
69889
69890
69891
69892
.....
69893
69894
69895
69896
69897
69898
69899
69900
69901
69902
69903
69904
69905
69906

69907
69908
69909
69910
69911
69912
69913
.....
69927
69928
69929
69930
69931
69932
69933
69934
69935
69936
69937
69938
69939

69940
69941
69942
69943
69944
69945
69946
.....
70766
70767
70768
70769
70770
70771
70772
70773
70774
70775
70776
70777
70778
70779
70780
.....
70808
70809
70810
70811
70812
70813
70814
70815
70816
70817
70818
70819
70820
70821
70822
70823
70824
.....
70827
70828
70829
70830
70831
70832
70833
70834
70835
70836
70837
70838
70839
70840
70841
.....
70847
70848
70849
70850
70851
70852
70853
70854
70855
70856
70857
70858
70859
70860
70861
.....
70924
70925
70926
70927
70928
70929
70930
70931
70932
70933
70934
70935
70936
70937
70938
.....
71004
71005
71006
71007
71008
71009
71010
71011
71012
71013
71014
71015
71016
71017
71018

71019
71020
71021
71022
71023
71024
71025
.....
71031
71032
71033
71034
71035
71036
71037
71038
71039
71040
71041
71042
71043
71044
71045
71046
71047
71048
71049
71050
71051
71052
71053
71054
71055
71056
71057
71058
71059
71060
71061
71062
71063
71064
71065
71066
71067
71068
71069
71070
71071
71072
71073
71074
71075
71076
71077
71078
71079
71080
71081
71082
71083
71084
71085
71086
71087
71088
71089
71090
71091
71092
71093
71094








71095
71096
71097
71098
71099
71100
71101


71102
71103
71104
71105
71106
71107
71108
71109
71110
71111
71112
71113
71114
71115
71116
71117
71118
71119
.....
71136
71137
71138
71139
71140
71141
71142
71143
71144
71145
71146
71147
71148
71149
71150
.....
72427
72428
72429
72430
72431
72432
72433

72434
72435
72436
72437
72438
72439
72440
.....
72997
72998
72999
73000
73001
73002
73003
73004
73005
73006
73007
73008
73009
73010
73011
73012
73013
73014
73015
73016
73017
73018
73019
73020
73021
73022
73023
.....
75787
75788
75789
75790
75791
75792
75793

75794
75795
75796
75797
75798
75799
75800
75801
75802
75803
75804
75805

75806
75807
75808
75809
75810
75811
75812
.....
75843
75844
75845
75846
75847
75848
75849
75850
75851
75852
75853
75854
75855
75856
75857
.....
77761
77762
77763
77764
77765
77766
77767
77768
77769
77770
77771
77772
77773
77774
77775
77776
77777
77778
77779
77780
.....
79196
79197
79198
79199
79200
79201
79202

79203
79204
79205
79206
79207
79208
79209
79210
79211
79212
79213
79214


79215
79216
79217
79218
79219
79220
79221
.....
79251
79252
79253
79254
79255
79256
79257
79258
79259
79260
79261
79262
79263
79264
79265
79266
79267
79268
79269
79270
79271
79272
79273
79274
79275
79276
79277
79278
79279
.....
79280
79281
79282
79283
79284
79285
79286
79287
79288
79289
79290
79291
79292
79293
79294
79295
79296
79297
79298
79299
79300
79301
79302
.....
79312
79313
79314
79315
79316
79317
79318








79319
79320
79321
79322
79323
79324
79325
79326
79327
79328
79329
79330
79331
79332
79333
.....
79555
79556
79557
79558
79559
79560
79561
79562
79563
79564
79565
79566
79567
79568
79569
79570
79571
79572
79573
79574
79575
79576
79577
79578
79579
79580
79581
79582
79583
79584
79585
79586
79587
79588
79589
79590
.....
79594
79595
79596
79597
79598
79599
79600
79601
79602
79603
79604
79605
79606
79607
79608
79609
79610
79611
79612
79613
79614
79615


79616

79617
79618
79619
79620
79621
79622
79623
79624
.....
79800
79801
79802
79803
79804
79805
79806

79807
79808
79809
79810
79811
79812
79813
.....
79955
79956
79957
79958
79959
79960
79961
79962
79963
79964
79965
79966
79967
79968
79969
79970
79971
79972
79973
79974
79975
79976
79977
79978
79979
79980
79981
79982
79983
79984
79985
79986
79987
79988
79989
79990

79991
79992
79993
79994
79995
79996
79997
79998
.....
91355
91356
91357
91358
91359
91360
91361
91362
91363
91364
91365
91366
91367
91368
91369
91370
91371
91372
91373
91374
91375
91376
91377
91378
91379
91380
91381
91382
......
100020
100021
100022
100023
100024
100025
100026
100027
100028
100029
100030
100031
100032
100033
100034
100035
......
103307
103308
103309
103310
103311
103312
103313
103314
103315
103316
103317
103318
103319
103320
103321
......
110783
110784
110785
110786
110787
110788
110789
110790
110791
110792
110793
110794
110795
110796
110797
......
117045
117046
117047
117048
117049
117050
117051


117052



117053
117054
117055
117056
117057
117058
117059
**
** See also: [sqlite3_libversion()],
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
** [sqlite_version()] and [sqlite_source_id()].
*/
#define SQLITE_VERSION        "3.8.2"
#define SQLITE_VERSION_NUMBER 3008002
#define SQLITE_SOURCE_ID      "2013-11-21 23:37:02 3d47a556f0074e39b880186fb7661b1b8955f742"

/*
** 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
................................................................................
#define TK_ILLEGAL                        149
#define TK_SPACE                          150
#define TK_UNCLOSED_STRING                151
#define TK_FUNCTION                       152
#define TK_COLUMN                         153
#define TK_AGG_FUNCTION                   154
#define TK_AGG_COLUMN                     155

#define TK_UMINUS                         156
#define TK_UPLUS                          157

/************** End of parse.h ***********************************************/
/************** Continuing where we left off in sqliteInt.h ******************/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
................................................................................
SQLITE_PRIVATE int sqlite3BtreeFirst(BtCursor*, int *pRes);
SQLITE_PRIVATE int sqlite3BtreeLast(BtCursor*, int *pRes);
SQLITE_PRIVATE int sqlite3BtreeNext(BtCursor*, int *pRes);
SQLITE_PRIVATE int sqlite3BtreeEof(BtCursor*);
SQLITE_PRIVATE int sqlite3BtreePrevious(BtCursor*, int *pRes);
SQLITE_PRIVATE int sqlite3BtreeKeySize(BtCursor*, i64 *pSize);
SQLITE_PRIVATE int sqlite3BtreeKey(BtCursor*, u32 offset, u32 amt, void*);
SQLITE_PRIVATE const void *sqlite3BtreeKeyFetch(BtCursor*, u32 *pAmt);
SQLITE_PRIVATE const void *sqlite3BtreeDataFetch(BtCursor*, u32 *pAmt);
SQLITE_PRIVATE int sqlite3BtreeDataSize(BtCursor*, u32 *pSize);
SQLITE_PRIVATE int sqlite3BtreeData(BtCursor*, u32 offset, u32 amt, void*);
SQLITE_PRIVATE void sqlite3BtreeSetCachedRowid(BtCursor*, sqlite3_int64);
SQLITE_PRIVATE sqlite3_int64 sqlite3BtreeGetCachedRowid(BtCursor*);

SQLITE_PRIVATE char *sqlite3BtreeIntegrityCheck(Btree*, int *aRoot, int nRoot, int, int*);
SQLITE_PRIVATE struct Pager *sqlite3BtreePager(Btree*);
................................................................................
/* Automatically generated.  Do not edit */
/* See the mkopcodeh.awk script for details */
#define OP_Function        1 /* synopsis: r[P3]=func(r[P2@P5])             */
#define OP_Savepoint       2
#define OP_AutoCommit      3
#define OP_Transaction     4
#define OP_SorterNext      5
#define OP_PrevIfOpen      6
#define OP_NextIfOpen      7
#define OP_Prev            8
#define OP_Next            9
#define OP_AggStep        10 /* synopsis: accum=r[P3] step(r[P2@P5])       */
#define OP_Checkpoint     11
#define OP_JournalMode    12
#define OP_Vacuum         13
#define OP_VFilter        14 /* synopsis: iPlan=r[P3] zPlan='P4'           */
#define OP_VUpdate        15 /* synopsis: data=r[P3@P2]                    */
#define OP_Goto           16
#define OP_Gosub          17
#define OP_Return         18
#define OP_Not            19 /* same as TK_NOT, synopsis: r[P2]= !r[P1]    */
#define OP_Yield          20
#define OP_HaltIfNull     21 /* synopsis: if r[P3] null then halt          */

#define OP_Halt           22
#define OP_Integer        23 /* synopsis: r[P2]=P1                         */
#define OP_Int64          24 /* synopsis: r[P2]=P4                         */
#define OP_String         25 /* synopsis: r[P2]='P4' (len=P1)              */
#define OP_Null           26 /* synopsis: r[P2..P3]=NULL                   */
#define OP_Blob           27 /* synopsis: r[P2]=P4 (len=P1)                */
#define OP_Variable       28 /* synopsis: r[P2]=parameter(P1,P4)           */
#define OP_Move           29 /* synopsis: r[P2@P3]=r[P1@P3]                */
#define OP_Copy           30 /* synopsis: r[P2@P3]=r[P1@P3]                */
#define OP_SCopy          31 /* synopsis: r[P2]=r[P1]                      */
#define OP_ResultRow      32 /* synopsis: output=r[P1@P2]                  */
#define OP_CollSeq        33
#define OP_AddImm         34 /* synopsis: r[P1]=r[P1]+P2                   */
#define OP_MustBeInt      35
#define OP_RealAffinity   36
#define OP_Permutation    37
#define OP_Compare        38
#define OP_Jump           39
#define OP_Once           40
#define OP_If             41
#define OP_IfNot          42
#define OP_Column         43 /* synopsis: r[P3]=PX                         */
#define OP_Affinity       44 /* synopsis: affinity(r[P1@P2])               */
#define OP_MakeRecord     45 /* synopsis: r[P3]=mkrec(r[P1@P2])            */
#define OP_Count          46 /* synopsis: r[P2]=count()                    */
#define OP_ReadCookie     47
#define OP_SetCookie      48
#define OP_VerifyCookie   49
#define OP_OpenRead       50 /* synopsis: root=P2 iDb=P3                   */
#define OP_OpenWrite      51 /* synopsis: root=P2 iDb=P3                   */
#define OP_OpenAutoindex  52 /* synopsis: nColumn=P2                       */
#define OP_OpenEphemeral  53 /* synopsis: nColumn=P2                       */
#define OP_SorterOpen     54
#define OP_OpenPseudo     55 /* synopsis: content in r[P2@P3]              */
#define OP_Close          56
#define OP_SeekLt         57 /* synopsis: key=r[P3@P4]                     */
#define OP_SeekLe         58 /* synopsis: key=r[P3@P4]                     */
#define OP_SeekGe         59 /* synopsis: key=r[P3@P4]                     */
#define OP_SeekGt         60 /* synopsis: key=r[P3@P4]                     */
#define OP_Seek           61 /* synopsis: intkey=r[P2]                     */
#define OP_NoConflict     62 /* synopsis: key=r[P3@P4]                     */
#define OP_NotFound       63 /* synopsis: key=r[P3@P4]                     */
#define OP_Found          64 /* synopsis: key=r[P3@P4]                     */
#define OP_NotExists      65 /* synopsis: intkey=r[P3]                     */
#define OP_Sequence       66 /* synopsis: r[P2]=rowid                      */
#define OP_NewRowid       67 /* synopsis: r[P2]=rowid                      */
#define OP_Insert         68 /* synopsis: intkey=r[P3] data=r[P2]          */


#define OP_Or             69 /* same as TK_OR, synopsis: r[P3]=(r[P1] || r[P2]) */
#define OP_And            70 /* same as TK_AND, synopsis: r[P3]=(r[P1] && r[P2]) */
#define OP_InsertInt      71 /* synopsis: intkey=P3 data=r[P2]             */
#define OP_Delete         72
#define OP_ResetCount     73


#define OP_IsNull         74 /* same as TK_ISNULL, synopsis: if r[P1]==NULL goto P2 */
#define OP_NotNull        75 /* same as TK_NOTNULL, synopsis: if r[P1]!=NULL goto P2 */
#define OP_Ne             76 /* same as TK_NE, synopsis: if r[P1]!=r[P3] goto P2 */
#define OP_Eq             77 /* same as TK_EQ, synopsis: if r[P1]==r[P3] goto P2 */
#define OP_Gt             78 /* same as TK_GT, synopsis: if r[P1]>r[P3] goto P2 */
#define OP_Le             79 /* same as TK_LE, synopsis: if r[P1]<=r[P3] goto P2 */
#define OP_Lt             80 /* same as TK_LT, synopsis: if r[P1]<r[P3] goto P2 */
#define OP_Ge             81 /* same as TK_GE, synopsis: if r[P1]>=r[P3] goto P2 */
#define OP_SorterCompare  82 /* synopsis: if key(P1)!=rtrim(r[P3],P4) goto P2 */
#define OP_BitAnd         83 /* same as TK_BITAND, synopsis: r[P3]=r[P1]&r[P2] */
#define OP_BitOr          84 /* same as TK_BITOR, synopsis: r[P3]=r[P1]|r[P2] */
#define OP_ShiftLeft      85 /* same as TK_LSHIFT, synopsis: r[P3]=r[P2]<<r[P1] */
#define OP_ShiftRight     86 /* same as TK_RSHIFT, synopsis: r[P3]=r[P2]>>r[P1] */
#define OP_Add            87 /* same as TK_PLUS, synopsis: r[P3]=r[P1]+r[P2] */
#define OP_Subtract       88 /* same as TK_MINUS, synopsis: r[P3]=r[P2]-r[P1] */
#define OP_Multiply       89 /* same as TK_STAR, synopsis: r[P3]=r[P1]*r[P2] */
#define OP_Divide         90 /* same as TK_SLASH, synopsis: r[P3]=r[P2]/r[P1] */
#define OP_Remainder      91 /* same as TK_REM, synopsis: r[P3]=r[P2]%r[P1] */
#define OP_Concat         92 /* same as TK_CONCAT, synopsis: r[P3]=r[P2]+r[P1] */
#define OP_SorterData     93 /* synopsis: r[P2]=data                       */
#define OP_BitNot         94 /* same as TK_BITNOT, synopsis: r[P1]= ~r[P1] */
#define OP_String8        95 /* same as TK_STRING, synopsis: r[P2]='P4'    */
#define OP_RowKey         96 /* synopsis: r[P2]=key                        */
#define OP_RowData        97 /* synopsis: r[P2]=data                       */
#define OP_Rowid          98 /* synopsis: r[P2]=rowid                      */
#define OP_NullRow        99
#define OP_Last          100
#define OP_SorterSort    101
#define OP_Sort          102
#define OP_Rewind        103
#define OP_SorterInsert  104
#define OP_IdxInsert     105 /* synopsis: key=r[P2]                        */
#define OP_IdxDelete     106 /* synopsis: key=r[P2@P3]                     */
#define OP_IdxRowid      107 /* synopsis: r[P2]=rowid                      */
#define OP_IdxLT         108 /* synopsis: key=r[P3@P4]                     */
#define OP_IdxGE         109 /* synopsis: key=r[P3@P4]                     */
#define OP_Destroy       110
#define OP_Clear         111
#define OP_CreateIndex   112 /* synopsis: r[P2]=root iDb=P1                */
#define OP_CreateTable   113 /* synopsis: r[P2]=root iDb=P1                */
#define OP_ParseSchema   114
#define OP_LoadAnalysis  115
#define OP_DropTable     116
#define OP_DropIndex     117
#define OP_DropTrigger   118
#define OP_IntegrityCk   119
#define OP_RowSetAdd     120 /* synopsis: rowset(P1)=r[P2]                 */
#define OP_RowSetRead    121 /* synopsis: r[P3]=rowset(P1)                 */
#define OP_RowSetTest    122 /* synopsis: if r[P3] in rowset(P1) goto P2   */
#define OP_Program       123
#define OP_Param         124
#define OP_FkCounter     125 /* synopsis: fkctr[P1]+=P2                    */
#define OP_FkIfZero      126 /* synopsis: if fkctr[P1]==0 goto P2          */
#define OP_MemMax        127 /* synopsis: r[P1]=max(r[P1],r[P2])           */
#define OP_IfPos         128 /* synopsis: if r[P1]>0 goto P2               */
#define OP_IfNeg         129 /* synopsis: if r[P1]<0 goto P2               */
#define OP_IfZero        130 /* synopsis: r[P1]+=P3, if r[P1]==0 goto P2   */
#define OP_Real          131 /* same as TK_FLOAT, synopsis: r[P2]=P4       */
#define OP_AggFinal      132 /* synopsis: accum=r[P1] N=P2                 */
#define OP_IncrVacuum    133

#define OP_Expire        134
#define OP_TableLock     135 /* synopsis: iDb=P1 root=P2 write=P3          */
#define OP_VBegin        136
#define OP_VCreate       137
#define OP_VDestroy      138
#define OP_VOpen         139
#define OP_VColumn       140 /* synopsis: r[P3]=vcolumn(P2)                */
#define OP_VNext         141


#define OP_ToText        142 /* same as TK_TO_TEXT                         */
#define OP_ToBlob        143 /* same as TK_TO_BLOB                         */
#define OP_ToNumeric     144 /* same as TK_TO_NUMERIC                      */
#define OP_ToInt         145 /* same as TK_TO_INT                          */
#define OP_ToReal        146 /* same as TK_TO_REAL                         */
#define OP_VRename       147
#define OP_Pagecount     148
#define OP_MaxPgcnt      149
#define OP_Trace         150
#define OP_Noop          151
#define OP_Explain       152


/* 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            0x0001  /* jump:  P2 holds jmp target */
................................................................................
#define OPFLG_IN1             0x0004  /* in1:   P1 is an input */
#define OPFLG_IN2             0x0008  /* in2:   P2 is an input */
#define OPFLG_IN3             0x0010  /* in3:   P3 is an input */
#define OPFLG_OUT2            0x0020  /* out2:  P2 is an output */
#define OPFLG_OUT3            0x0040  /* out3:  P3 is an output */
#define OPFLG_INITIALIZER {\
/*   0 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01,\
/*   8 */ 0x01, 0x01, 0x00, 0x00, 0x02, 0x00, 0x01, 0x00,\
/*  16 */ 0x01, 0x01, 0x04, 0x24, 0x04, 0x10, 0x00, 0x02,\
/*  24 */ 0x02, 0x02, 0x02, 0x02, 0x02, 0x00, 0x00, 0x20,\
/*  32 */ 0x00, 0x00, 0x04, 0x05, 0x04, 0x00, 0x00, 0x01,\
/*  40 */ 0x01, 0x05, 0x05, 0x00, 0x00, 0x00, 0x02, 0x02,\
/*  48 */ 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\
/*  56 */ 0x00, 0x11, 0x11, 0x11, 0x11, 0x08, 0x11, 0x11,\
/*  64 */ 0x11, 0x11, 0x02, 0x02, 0x00, 0x4c, 0x4c, 0x00,\
/*  72 */ 0x00, 0x00, 0x05, 0x05, 0x15, 0x15, 0x15, 0x15,\
/*  80 */ 0x15, 0x15, 0x00, 0x4c, 0x4c, 0x4c, 0x4c, 0x4c,\
/*  88 */ 0x4c, 0x4c, 0x4c, 0x4c, 0x4c, 0x00, 0x24, 0x02,\
/*  96 */ 0x00, 0x00, 0x02, 0x00, 0x01, 0x01, 0x01, 0x01,\
/* 104 */ 0x08, 0x08, 0x00, 0x02, 0x01, 0x01, 0x02, 0x00,\
/* 112 */ 0x02, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\
/* 120 */ 0x0c, 0x45, 0x15, 0x01, 0x02, 0x00, 0x01, 0x08,\
/* 128 */ 0x05, 0x05, 0x05, 0x02, 0x00, 0x01, 0x00, 0x00,\
/* 136 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x04, 0x04,\
/* 144 */ 0x04, 0x04, 0x04, 0x00, 0x02, 0x02, 0x00, 0x00,\
/* 152 */ 0x00,}

/************** End of opcodes.h *********************************************/
/************** Continuing where we left off in vdbe.h ***********************/

/*
** Prototypes for the VDBE interface.  See comments on the implementation
** for a description of what each of these routines does.
................................................................................
#define OptimizationDisabled(db, mask)  (((db)->dbOptFlags&(mask))!=0)
#define OptimizationEnabled(db, mask)   (((db)->dbOptFlags&(mask))==0)
#else
#define OptimizationDisabled(db, mask)  0
#define OptimizationEnabled(db, mask)   1
#endif

/*
** Return true if it OK to factor constant expressions into the initialization
** code. The argument is a Parse object for the code generator.
*/
#define ConstFactorOk(P) \
  ((P)->cookieGoto>0 && OptimizationEnabled((P)->db,SQLITE_FactorOutConst))

/*
** Possible values for the sqlite.magic field.
** The numbers are obtained at random and have no special meaning, other
** than being distinct from one another.
*/
#define SQLITE_MAGIC_OPEN     0xa029a697  /* Database is open */
#define SQLITE_MAGIC_CLOSED   0x9f3c2d33  /* Database is closed */
................................................................................
#define SQLITE_FUNC_EPHEM    0x010 /* Ephemeral.  Delete with VDBE */
#define SQLITE_FUNC_NEEDCOLL 0x020 /* sqlite3GetFuncCollSeq() might be called */
#define SQLITE_FUNC_LENGTH   0x040 /* Built-in length() function */
#define SQLITE_FUNC_TYPEOF   0x080 /* Built-in typeof() function */
#define SQLITE_FUNC_COUNT    0x100 /* Built-in count(*) aggregate */
#define SQLITE_FUNC_COALESCE 0x200 /* Built-in coalesce() or ifnull() */
#define SQLITE_FUNC_UNLIKELY 0x400 /* Built-in unlikely() function */
#define SQLITE_FUNC_CONSTANT 0x800 /* Constant inputs give a constant output */

/*
** The following three macros, FUNCTION(), LIKEFUNC() and AGGREGATE() are
** used to create the initializers for the FuncDef structures.
**
**   FUNCTION(zName, nArg, iArg, bNC, xFunc)
**     Used to create a scalar function definition of a function zName 
**     implemented by C function xFunc that accepts nArg arguments. The
**     value passed as iArg is cast to a (void*) and made available
**     as the user-data (sqlite3_user_data()) for the function. If 
**     argument bNC is true, then the SQLITE_FUNC_NEEDCOLL flag is set.
**
**   VFUNCTION(zName, nArg, iArg, bNC, xFunc)
**     Like FUNCTION except it omits the SQLITE_FUNC_CONSTANT flag.
**
**   AGGREGATE(zName, nArg, iArg, bNC, xStep, xFinal)
**     Used to create an aggregate function definition implemented by
**     the C functions xStep and xFinal. The first four parameters
**     are interpreted in the same way as the first 4 parameters to
**     FUNCTION().
**
**   LIKEFUNC(zName, nArg, pArg, flags)
................................................................................
**     that accepts nArg arguments and is implemented by a call to C 
**     function likeFunc. Argument pArg is cast to a (void *) and made
**     available as the function user-data (sqlite3_user_data()). The
**     FuncDef.flags variable is set to the value passed as the flags
**     parameter.
*/
#define FUNCTION(zName, nArg, iArg, bNC, xFunc) \
  {nArg, SQLITE_FUNC_CONSTANT|SQLITE_UTF8|(bNC*SQLITE_FUNC_NEEDCOLL), \
   SQLITE_INT_TO_PTR(iArg), 0, xFunc, 0, 0, #zName, 0, 0}
#define VFUNCTION(zName, nArg, iArg, bNC, xFunc) \
  {nArg, SQLITE_UTF8|(bNC*SQLITE_FUNC_NEEDCOLL), \
   SQLITE_INT_TO_PTR(iArg), 0, xFunc, 0, 0, #zName, 0, 0}
#define FUNCTION2(zName, nArg, iArg, bNC, xFunc, extraFlags) \
  {nArg,SQLITE_FUNC_CONSTANT|SQLITE_UTF8|(bNC*SQLITE_FUNC_NEEDCOLL)|extraFlags,\
   SQLITE_INT_TO_PTR(iArg), 0, xFunc, 0, 0, #zName, 0, 0}
#define STR_FUNCTION(zName, nArg, pArg, bNC, xFunc) \
  {nArg, SQLITE_FUNC_CONSTANT|SQLITE_UTF8|(bNC*SQLITE_FUNC_NEEDCOLL), \
   pArg, 0, xFunc, 0, 0, #zName, 0, 0}
#define LIKEFUNC(zName, nArg, arg, flags) \
  {nArg, SQLITE_FUNC_CONSTANT|SQLITE_UTF8|flags, \
   (void *)arg, 0, likeFunc, 0, 0, #zName, 0, 0}
#define AGGREGATE(zName, nArg, arg, nc, xStep, xFinal) \
  {nArg, SQLITE_UTF8|(nc*SQLITE_FUNC_NEEDCOLL), \
   SQLITE_INT_TO_PTR(arg), 0, 0, xStep,xFinal,#zName,0,0}

/*
** All current savepoints are stored in a linked list starting at
** sqlite3.pSavepoint. The first element in the list is the most recently
................................................................................
#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_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_Constant  0x080000 /* Node is a constant */

/*
** These macros can be used to test, set, or clear bits in the 
** Expr.flags field.
*/
#define ExprHasProperty(E,P)     (((E)->flags&(P))!=0)
#define ExprHasAllProperty(E,P)  (((E)->flags&(P))==(P))
................................................................................
  struct ExprList_item { /* For each expression in the list */
    Expr *pExpr;            /* The list of expressions */
    char *zName;            /* Token associated with this expression */
    char *zSpan;            /* Original text of the expression */
    u8 sortOrder;           /* 1 for DESC or 0 for ASC */
    unsigned done :1;       /* A flag to indicate when processing is finished */
    unsigned bSpanIsTab :1; /* zSpan holds DB.TABLE.COLUMN */
    unsigned reusable :1;   /* Constant expression is reusable */
    union {
      struct {
        u16 iOrderByCol;      /* For ORDER BY, column number in result set */
        u16 iAlias;           /* Index into Parse.aAlias[] for zName */
      } x;
      int iConstExprReg;      /* Register in which Expr value is cached */
    } u;
................................................................................
SQLITE_PRIVATE void sqlite3ExprCacheStore(Parse*, int, int, int);
SQLITE_PRIVATE void sqlite3ExprCachePush(Parse*);
SQLITE_PRIVATE void sqlite3ExprCachePop(Parse*, int);
SQLITE_PRIVATE void sqlite3ExprCacheRemove(Parse*, int, int);
SQLITE_PRIVATE void sqlite3ExprCacheClear(Parse*);
SQLITE_PRIVATE void sqlite3ExprCacheAffinityChange(Parse*, int, int);
SQLITE_PRIVATE int sqlite3ExprCode(Parse*, Expr*, int);
SQLITE_PRIVATE void sqlite3ExprCodeAtInit(Parse*, Expr*, int, u8);
SQLITE_PRIVATE int sqlite3ExprCodeTemp(Parse*, Expr*, int*);
SQLITE_PRIVATE int sqlite3ExprCodeTarget(Parse*, Expr*, int);
SQLITE_PRIVATE int sqlite3ExprCodeAndCache(Parse*, Expr*, int);
SQLITE_PRIVATE int sqlite3ExprCodeExprList(Parse*, ExprList*, int, u8);
#define SQLITE_ECEL_DUP      0x01  /* Deep, not shallow copies */
#define SQLITE_ECEL_FACTOR   0x02  /* Factor out constant terms */
SQLITE_PRIVATE void sqlite3ExprIfTrue(Parse*, Expr*, int, int);
SQLITE_PRIVATE void sqlite3ExprIfFalse(Parse*, Expr*, int, int);
SQLITE_PRIVATE Table *sqlite3FindTable(sqlite3*,const char*, const char*);
SQLITE_PRIVATE Table *sqlite3LocateTable(Parse*,int isView,const char*, const char*);
SQLITE_PRIVATE Table *sqlite3LocateTableItem(Parse*,int isView,struct SrcList_item *);
SQLITE_PRIVATE Index *sqlite3FindIndex(sqlite3*,const char*, const char*);
SQLITE_PRIVATE void sqlite3UnlinkAndDeleteTable(sqlite3*,int,const char*);
................................................................................
** of the following structure.
*/
typedef struct VdbeOp Op;

/*
** Boolean values
*/
typedef unsigned Bool;

/* Opaque type used by code in vdbesort.c */
typedef struct VdbeSorter VdbeSorter;

/* Opaque type used by the explainer */
typedef struct Explain Explain;

................................................................................

/*
** A cursor is a pointer into a single BTree within a database file.
** The cursor can seek to a BTree entry with a particular key, or
** loop over all entries of the Btree.  You can also insert new BTree
** entries or retrieve the key or data from the entry that the cursor
** is currently pointing to.
**
** Cursors can also point to virtual tables, sorters, or "pseudo-tables".
** A pseudo-table is a single-row table implemented by registers.
** 
** Every cursor that the virtual machine has open is represented by an
** instance of the following structure.
*/
struct VdbeCursor {
  BtCursor *pCursor;    /* The cursor structure of the backend */
  Btree *pBt;           /* Separate file holding temporary table */
  KeyInfo *pKeyInfo;    /* Info about index keys needed by index cursors */
  int seekResult;       /* Result of previous sqlite3BtreeMoveto() */
  int pseudoTableReg;   /* Register holding pseudotable content. */
  i16 nField;           /* Number of fields in the header */
  u16 nHdrParsed;       /* Number of header fields parsed so far */
  i8 iDb;               /* Index of cursor database in db->aDb[] (or -1) */


  u8 nullRow;           /* True if pointing to a row with no data */
  u8 rowidIsValid;      /* True if lastRowid is valid */
  u8 deferredMoveto;    /* A call to sqlite3BtreeMoveto() is needed */
  Bool useRandomRowid:1;/* Generate new record numbers semi-randomly */
  Bool isTable:1;       /* True if a table requiring integer keys */

  Bool isOrdered:1;     /* True if the underlying table is BTREE_UNORDERED */

  Bool multiPseudo:1;   /* Multi-register pseudo-cursor */
  sqlite3_vtab_cursor *pVtabCursor;  /* The cursor for a virtual table */

  i64 seqCount;         /* Sequence counter */
  i64 movetoTarget;     /* Argument to the deferred sqlite3BtreeMoveto() */
  i64 lastRowid;        /* Rowid being deleted by OP_Delete */
  VdbeSorter *pSorter;  /* Sorter object for OP_SorterOpen cursors */




  /* Cached information about the header for the data record that the
  ** cursor is currently pointing to.  Only valid if cacheStatus matches
  ** Vdbe.cacheCtr.  Vdbe.cacheCtr will never take on the value of
  ** CACHE_STALE and so setting cacheStatus=CACHE_STALE guarantees that
  ** the cache is out of date.
  **
  ** aRow might point to (ephemeral) data for the current row, or it might
  ** be NULL.
  */
  u32 cacheStatus;      /* Cache is valid if this matches Vdbe.cacheCtr */
  u32 payloadSize;      /* Total number of bytes in the record */
  u32 szRow;            /* Byte available in aRow */
  u32 iHdrOffset;       /* Offset to next unparsed byte of the header */
  const u8 *aRow;       /* Data for the current row, if all on one page */
  u32 aType[1];         /* Type values for all entries in the record */
  /* 2*nField extra array elements allocated for aType[], beyond the one
  ** static element declared in the structure.  nField total array slots for
  ** aType[] and nField+1 array slots for aOffset[] */
};
typedef struct VdbeCursor VdbeCursor;

/*
** When a sub-program is executed (OP_Program), a structure of this type
** is allocated to store the current value of the program counter, as
** well as the current memory cell array and various other frame specific
................................................................................
SQLITE_PRIVATE int sqlite3VdbeMemStringify(Mem*, int);
SQLITE_PRIVATE i64 sqlite3VdbeIntValue(Mem*);
SQLITE_PRIVATE int sqlite3VdbeMemIntegerify(Mem*);
SQLITE_PRIVATE double sqlite3VdbeRealValue(Mem*);
SQLITE_PRIVATE void sqlite3VdbeIntegerAffinity(Mem*);
SQLITE_PRIVATE int sqlite3VdbeMemRealify(Mem*);
SQLITE_PRIVATE int sqlite3VdbeMemNumerify(Mem*);
SQLITE_PRIVATE int sqlite3VdbeMemFromBtree(BtCursor*,u32,u32,int,Mem*);
SQLITE_PRIVATE void sqlite3VdbeMemRelease(Mem *p);
SQLITE_PRIVATE void sqlite3VdbeMemReleaseExternal(Mem *p);
#define VdbeMemRelease(X)  \
  if((X)->flags&(MEM_Agg|MEM_Dyn|MEM_RowSet|MEM_Frame)) \
    sqlite3VdbeMemReleaseExternal(X);
SQLITE_PRIVATE int sqlite3VdbeMemFinalize(Mem*, FuncDef*);
SQLITE_PRIVATE const char *sqlite3OpcodeName(int);
................................................................................
SQLITE_PRIVATE const char *sqlite3OpcodeName(int i){
 static const char *const azName[] = { "?",
     /*   1 */ "Function"         OpHelp("r[P3]=func(r[P2@P5])"),
     /*   2 */ "Savepoint"        OpHelp(""),
     /*   3 */ "AutoCommit"       OpHelp(""),
     /*   4 */ "Transaction"      OpHelp(""),
     /*   5 */ "SorterNext"       OpHelp(""),
     /*   6 */ "PrevIfOpen"       OpHelp(""),
     /*   7 */ "NextIfOpen"       OpHelp(""),
     /*   8 */ "Prev"             OpHelp(""),
     /*   9 */ "Next"             OpHelp(""),
     /*  10 */ "AggStep"          OpHelp("accum=r[P3] step(r[P2@P5])"),
     /*  11 */ "Checkpoint"       OpHelp(""),
     /*  12 */ "JournalMode"      OpHelp(""),
     /*  13 */ "Vacuum"           OpHelp(""),
     /*  14 */ "VFilter"          OpHelp("iPlan=r[P3] zPlan='P4'"),
     /*  15 */ "VUpdate"          OpHelp("data=r[P3@P2]"),
     /*  16 */ "Goto"             OpHelp(""),
     /*  17 */ "Gosub"            OpHelp(""),
     /*  18 */ "Return"           OpHelp(""),
     /*  19 */ "Not"              OpHelp("r[P2]= !r[P1]"),
     /*  20 */ "Yield"            OpHelp(""),
     /*  21 */ "HaltIfNull"       OpHelp("if r[P3] null then halt"),

     /*  22 */ "Halt"             OpHelp(""),
     /*  23 */ "Integer"          OpHelp("r[P2]=P1"),
     /*  24 */ "Int64"            OpHelp("r[P2]=P4"),
     /*  25 */ "String"           OpHelp("r[P2]='P4' (len=P1)"),
     /*  26 */ "Null"             OpHelp("r[P2..P3]=NULL"),
     /*  27 */ "Blob"             OpHelp("r[P2]=P4 (len=P1)"),
     /*  28 */ "Variable"         OpHelp("r[P2]=parameter(P1,P4)"),
     /*  29 */ "Move"             OpHelp("r[P2@P3]=r[P1@P3]"),
     /*  30 */ "Copy"             OpHelp("r[P2@P3]=r[P1@P3]"),
     /*  31 */ "SCopy"            OpHelp("r[P2]=r[P1]"),
     /*  32 */ "ResultRow"        OpHelp("output=r[P1@P2]"),
     /*  33 */ "CollSeq"          OpHelp(""),
     /*  34 */ "AddImm"           OpHelp("r[P1]=r[P1]+P2"),
     /*  35 */ "MustBeInt"        OpHelp(""),
     /*  36 */ "RealAffinity"     OpHelp(""),
     /*  37 */ "Permutation"      OpHelp(""),
     /*  38 */ "Compare"          OpHelp(""),
     /*  39 */ "Jump"             OpHelp(""),
     /*  40 */ "Once"             OpHelp(""),
     /*  41 */ "If"               OpHelp(""),
     /*  42 */ "IfNot"            OpHelp(""),
     /*  43 */ "Column"           OpHelp("r[P3]=PX"),
     /*  44 */ "Affinity"         OpHelp("affinity(r[P1@P2])"),
     /*  45 */ "MakeRecord"       OpHelp("r[P3]=mkrec(r[P1@P2])"),
     /*  46 */ "Count"            OpHelp("r[P2]=count()"),
     /*  47 */ "ReadCookie"       OpHelp(""),
     /*  48 */ "SetCookie"        OpHelp(""),
     /*  49 */ "VerifyCookie"     OpHelp(""),
     /*  50 */ "OpenRead"         OpHelp("root=P2 iDb=P3"),
     /*  51 */ "OpenWrite"        OpHelp("root=P2 iDb=P3"),
     /*  52 */ "OpenAutoindex"    OpHelp("nColumn=P2"),
     /*  53 */ "OpenEphemeral"    OpHelp("nColumn=P2"),
     /*  54 */ "SorterOpen"       OpHelp(""),
     /*  55 */ "OpenPseudo"       OpHelp("content in r[P2@P3]"),
     /*  56 */ "Close"            OpHelp(""),
     /*  57 */ "SeekLt"           OpHelp("key=r[P3@P4]"),
     /*  58 */ "SeekLe"           OpHelp("key=r[P3@P4]"),
     /*  59 */ "SeekGe"           OpHelp("key=r[P3@P4]"),
     /*  60 */ "SeekGt"           OpHelp("key=r[P3@P4]"),
     /*  61 */ "Seek"             OpHelp("intkey=r[P2]"),
     /*  62 */ "NoConflict"       OpHelp("key=r[P3@P4]"),
     /*  63 */ "NotFound"         OpHelp("key=r[P3@P4]"),
     /*  64 */ "Found"            OpHelp("key=r[P3@P4]"),
     /*  65 */ "NotExists"        OpHelp("intkey=r[P3]"),
     /*  66 */ "Sequence"         OpHelp("r[P2]=rowid"),
     /*  67 */ "NewRowid"         OpHelp("r[P2]=rowid"),
     /*  68 */ "Insert"           OpHelp("intkey=r[P3] data=r[P2]"),


     /*  69 */ "Or"               OpHelp("r[P3]=(r[P1] || r[P2])"),
     /*  70 */ "And"              OpHelp("r[P3]=(r[P1] && r[P2])"),
     /*  71 */ "InsertInt"        OpHelp("intkey=P3 data=r[P2]"),
     /*  72 */ "Delete"           OpHelp(""),
     /*  73 */ "ResetCount"       OpHelp(""),


     /*  74 */ "IsNull"           OpHelp("if r[P1]==NULL goto P2"),
     /*  75 */ "NotNull"          OpHelp("if r[P1]!=NULL goto P2"),
     /*  76 */ "Ne"               OpHelp("if r[P1]!=r[P3] goto P2"),
     /*  77 */ "Eq"               OpHelp("if r[P1]==r[P3] goto P2"),
     /*  78 */ "Gt"               OpHelp("if r[P1]>r[P3] goto P2"),
     /*  79 */ "Le"               OpHelp("if r[P1]<=r[P3] goto P2"),
     /*  80 */ "Lt"               OpHelp("if r[P1]<r[P3] goto P2"),
     /*  81 */ "Ge"               OpHelp("if r[P1]>=r[P3] goto P2"),
     /*  82 */ "SorterCompare"    OpHelp("if key(P1)!=rtrim(r[P3],P4) goto P2"),
     /*  83 */ "BitAnd"           OpHelp("r[P3]=r[P1]&r[P2]"),
     /*  84 */ "BitOr"            OpHelp("r[P3]=r[P1]|r[P2]"),
     /*  85 */ "ShiftLeft"        OpHelp("r[P3]=r[P2]<<r[P1]"),
     /*  86 */ "ShiftRight"       OpHelp("r[P3]=r[P2]>>r[P1]"),
     /*  87 */ "Add"              OpHelp("r[P3]=r[P1]+r[P2]"),
     /*  88 */ "Subtract"         OpHelp("r[P3]=r[P2]-r[P1]"),
     /*  89 */ "Multiply"         OpHelp("r[P3]=r[P1]*r[P2]"),
     /*  90 */ "Divide"           OpHelp("r[P3]=r[P2]/r[P1]"),
     /*  91 */ "Remainder"        OpHelp("r[P3]=r[P2]%r[P1]"),
     /*  92 */ "Concat"           OpHelp("r[P3]=r[P2]+r[P1]"),
     /*  93 */ "SorterData"       OpHelp("r[P2]=data"),
     /*  94 */ "BitNot"           OpHelp("r[P1]= ~r[P1]"),
     /*  95 */ "String8"          OpHelp("r[P2]='P4'"),
     /*  96 */ "RowKey"           OpHelp("r[P2]=key"),
     /*  97 */ "RowData"          OpHelp("r[P2]=data"),
     /*  98 */ "Rowid"            OpHelp("r[P2]=rowid"),
     /*  99 */ "NullRow"          OpHelp(""),
     /* 100 */ "Last"             OpHelp(""),
     /* 101 */ "SorterSort"       OpHelp(""),
     /* 102 */ "Sort"             OpHelp(""),
     /* 103 */ "Rewind"           OpHelp(""),
     /* 104 */ "SorterInsert"     OpHelp(""),
     /* 105 */ "IdxInsert"        OpHelp("key=r[P2]"),
     /* 106 */ "IdxDelete"        OpHelp("key=r[P2@P3]"),
     /* 107 */ "IdxRowid"         OpHelp("r[P2]=rowid"),
     /* 108 */ "IdxLT"            OpHelp("key=r[P3@P4]"),
     /* 109 */ "IdxGE"            OpHelp("key=r[P3@P4]"),
     /* 110 */ "Destroy"          OpHelp(""),
     /* 111 */ "Clear"            OpHelp(""),
     /* 112 */ "CreateIndex"      OpHelp("r[P2]=root iDb=P1"),
     /* 113 */ "CreateTable"      OpHelp("r[P2]=root iDb=P1"),
     /* 114 */ "ParseSchema"      OpHelp(""),
     /* 115 */ "LoadAnalysis"     OpHelp(""),
     /* 116 */ "DropTable"        OpHelp(""),
     /* 117 */ "DropIndex"        OpHelp(""),
     /* 118 */ "DropTrigger"      OpHelp(""),
     /* 119 */ "IntegrityCk"      OpHelp(""),
     /* 120 */ "RowSetAdd"        OpHelp("rowset(P1)=r[P2]"),
     /* 121 */ "RowSetRead"       OpHelp("r[P3]=rowset(P1)"),
     /* 122 */ "RowSetTest"       OpHelp("if r[P3] in rowset(P1) goto P2"),
     /* 123 */ "Program"          OpHelp(""),
     /* 124 */ "Param"            OpHelp(""),
     /* 125 */ "FkCounter"        OpHelp("fkctr[P1]+=P2"),
     /* 126 */ "FkIfZero"         OpHelp("if fkctr[P1]==0 goto P2"),
     /* 127 */ "MemMax"           OpHelp("r[P1]=max(r[P1],r[P2])"),
     /* 128 */ "IfPos"            OpHelp("if r[P1]>0 goto P2"),
     /* 129 */ "IfNeg"            OpHelp("if r[P1]<0 goto P2"),
     /* 130 */ "IfZero"           OpHelp("r[P1]+=P3, if r[P1]==0 goto P2"),
     /* 131 */ "Real"             OpHelp("r[P2]=P4"),
     /* 132 */ "AggFinal"         OpHelp("accum=r[P1] N=P2"),
     /* 133 */ "IncrVacuum"       OpHelp(""),

     /* 134 */ "Expire"           OpHelp(""),
     /* 135 */ "TableLock"        OpHelp("iDb=P1 root=P2 write=P3"),
     /* 136 */ "VBegin"           OpHelp(""),
     /* 137 */ "VCreate"          OpHelp(""),
     /* 138 */ "VDestroy"         OpHelp(""),
     /* 139 */ "VOpen"            OpHelp(""),
     /* 140 */ "VColumn"          OpHelp("r[P3]=vcolumn(P2)"),
     /* 141 */ "VNext"            OpHelp(""),


     /* 142 */ "ToText"           OpHelp(""),
     /* 143 */ "ToBlob"           OpHelp(""),
     /* 144 */ "ToNumeric"        OpHelp(""),
     /* 145 */ "ToInt"            OpHelp(""),
     /* 146 */ "ToReal"           OpHelp(""),
     /* 147 */ "VRename"          OpHelp(""),
     /* 148 */ "Pagecount"        OpHelp(""),
     /* 149 */ "MaxPgcnt"         OpHelp(""),
     /* 150 */ "Trace"            OpHelp(""),
     /* 151 */ "Noop"             OpHelp(""),
     /* 152 */ "Explain"          OpHelp(""),
  };
  return azName[i];
}
#endif

/************** End of opcodes.c *********************************************/
/************** Begin file os_unix.c *****************************************/
................................................................................
**
** The pointer returned by this routine looks directly into the cached
** page of the database.  The data might change or move the next time
** any btree routine is called.
*/
static const unsigned char *fetchPayload(
  BtCursor *pCur,      /* Cursor pointing to entry to read from */
  u32 *pAmt,           /* Write the number of available bytes here */
  int skipKey          /* read beginning at data if this is true */
){
  unsigned char *aPayload;
  MemPage *pPage;
  u32 nKey;
  u32 nLocal;

................................................................................
** including calls from other threads against the same cache.
** Hence, a mutex on the BtShared should be held prior to calling
** this routine.
**
** These routines is used to get quick access to key and data
** in the common case where no overflow pages are used.
*/
SQLITE_PRIVATE const void *sqlite3BtreeKeyFetch(BtCursor *pCur, u32 *pAmt){
  const void *p = 0;
  assert( sqlite3_mutex_held(pCur->pBtree->db->mutex) );
  assert( cursorHoldsMutex(pCur) );
  if( ALWAYS(pCur->eState==CURSOR_VALID) ){
    p = (const void*)fetchPayload(pCur, pAmt, 0);
  }
  return p;
}
SQLITE_PRIVATE const void *sqlite3BtreeDataFetch(BtCursor *pCur, u32 *pAmt){
  const void *p = 0;
  assert( sqlite3_mutex_held(pCur->pBtree->db->mutex) );
  assert( cursorHoldsMutex(pCur) );
  if( ALWAYS(pCur->eState==CURSOR_VALID) ){
    p = (const void*)fetchPayload(pCur, pAmt, 1);
  }
  return p;
................................................................................
** is overwritten without being freed.
**
** If this routine fails for any reason (malloc returns NULL or unable
** to read from the disk) then the pMem is left in an inconsistent state.
*/
SQLITE_PRIVATE int sqlite3VdbeMemFromBtree(
  BtCursor *pCur,   /* Cursor pointing at record to retrieve. */
  u32 offset,       /* Offset from the start of data to return bytes from. */
  u32 amt,          /* Number of bytes to return. */
  int key,          /* If true, retrieve from the btree key, not data. */
  Mem *pMem         /* OUT: Return data in this Mem structure. */
){
  char *zData;        /* Data from the btree layer */
  u32 available = 0;  /* Number of bytes available on the local btree page */
  int rc = SQLITE_OK; /* Return code */

  assert( sqlite3BtreeCursorIsValid(pCur) );

  /* Note: the calls to BtreeKeyFetch() and DataFetch() below assert() 
  ** that both the BtShared and database handle mutexes are held. */
  assert( (pMem->flags & MEM_RowSet)==0 );
................................................................................
  if( key ){
    zData = (char *)sqlite3BtreeKeyFetch(pCur, &available);
  }else{
    zData = (char *)sqlite3BtreeDataFetch(pCur, &available);
  }
  assert( zData!=0 );

  if( offset+amt<=available ){
    sqlite3VdbeMemRelease(pMem);
    pMem->z = &zData[offset];
    pMem->flags = MEM_Blob|MEM_Ephem;
  }else if( SQLITE_OK==(rc = sqlite3VdbeMemGrow(pMem, amt+2, 0)) ){
    pMem->flags = MEM_Blob|MEM_Dyn|MEM_Term;
    pMem->enc = 0;
    pMem->type = SQLITE_BLOB;
................................................................................
    }
    pMem->z[amt] = 0;
    pMem->z[amt+1] = 0;
    if( rc!=SQLITE_OK ){
      sqlite3VdbeMemRelease(pMem);
    }
  }
  pMem->n = (int)amt;

  return rc;
}

/* This function is only available internally, it is not part of the
** external API. It works in a similar way to sqlite3_value_text(),
** except the data returned is in the encoding specified by the second
................................................................................
        assert( pOp[-1].opcode==OP_Integer );
        n = pOp[-1].p1;
        if( n>nMaxArgs ) nMaxArgs = n;
        break;
      }
#endif
      case OP_Next:
      case OP_NextIfOpen:
      case OP_SorterNext: {
        pOp->p4.xAdvance = sqlite3BtreeNext;
        pOp->p4type = P4_ADVANCE;
        break;
      }
      case OP_Prev:
      case OP_PrevIfOpen: {
        pOp->p4.xAdvance = sqlite3BtreePrevious;
        pOp->p4type = P4_ADVANCE;
        break;
      }
    }

    pOp->opflags = sqlite3OpcodeProperty[opcode];
................................................................................
    ** the call above. */
  }else if( pCx->pCursor ){
    sqlite3BtreeCloseCursor(pCx->pCursor);
  }
#ifndef SQLITE_OMIT_VIRTUALTABLE
  if( pCx->pVtabCursor ){
    sqlite3_vtab_cursor *pVtabCursor = pCx->pVtabCursor;
    const sqlite3_module *pModule = pVtabCursor->pVtab->pModule;
    p->inVtabMethod = 1;
    pModule->xClose(pVtabCursor);
    p->inVtabMethod = 0;
  }
#endif
}

................................................................................
    if( res!=0 ) return SQLITE_CORRUPT_BKPT;
    p->rowidIsValid = 1;
#ifdef SQLITE_TEST
    sqlite3_search_count++;
#endif
    p->deferredMoveto = 0;
    p->cacheStatus = CACHE_STALE;
  }else if( p->pCursor ){
    int hasMoved;
    int rc = sqlite3BtreeCursorHasMoved(p->pCursor, &hasMoved);
    if( rc ) return rc;
    if( hasMoved ){
      p->cacheStatus = CACHE_STALE;
      p->nullRow = 1;
    }
................................................................................
  assert( sqlite3BtreeCursorIsValid(pCur) );
  VVA_ONLY(rc =) sqlite3BtreeKeySize(pCur, &nCellKey);
  assert( rc==SQLITE_OK );     /* pCur is always valid so KeySize cannot fail */
  assert( (nCellKey & SQLITE_MAX_U32)==(u64)nCellKey );

  /* Read in the complete content of the index entry */
  memset(&m, 0, sizeof(m));
  rc = sqlite3VdbeMemFromBtree(pCur, 0, (u32)nCellKey, 1, &m);
  if( rc ){
    return rc;
  }

  /* The index entry must begin with a header size */
  (void)getVarint32((u8*)m.z, szHdr);
  testcase( szHdr==3 );
................................................................................
  /* nCellKey will always be between 0 and 0xffffffff because of the say
  ** that btreeParseCellPtr() and sqlite3GetVarint32() are implemented */
  if( nCellKey<=0 || nCellKey>0x7fffffff ){
    *res = 0;
    return SQLITE_CORRUPT_BKPT;
  }
  memset(&m, 0, sizeof(m));
  rc = sqlite3VdbeMemFromBtree(pC->pCursor, 0, (u32)nCellKey, 1, &m);
  if( rc ){
    return rc;
  }
  assert( pUnpacked->flags & UNPACKED_PREFIX_MATCH );
  *res = sqlite3VdbeRecordCompare(m.n, m.z, pUnpacked);
  sqlite3VdbeMemRelease(&m);
  return SQLITE_OK;
................................................................................
  ** cursor 1 is managed by memory cell (p->nMem-1), etc.
  */
  Mem *pMem = &p->aMem[p->nMem-iCur];

  int nByte;
  VdbeCursor *pCx = 0;
  nByte = 
      ROUND8(sizeof(VdbeCursor)) + 2*sizeof(u32)*nField + 
      (isBtreeCursor?sqlite3BtreeCursorSize():0);


  assert( iCur<p->nCursor );
  if( p->apCsr[iCur] ){
    sqlite3VdbeFreeCursor(p, p->apCsr[iCur]);
    p->apCsr[iCur] = 0;
  }
  if( SQLITE_OK==sqlite3VdbeMemGrow(pMem, nByte, 0) ){
    p->apCsr[iCur] = pCx = (VdbeCursor*)pMem->z;
    memset(pCx, 0, sizeof(VdbeCursor));
    pCx->iDb = iDb;
    pCx->nField = nField;



    if( isBtreeCursor ){
      pCx->pCursor = (BtCursor*)
          &pMem->z[ROUND8(sizeof(VdbeCursor))+2*sizeof(u32)*nField];
      sqlite3BtreeCursorZero(pCx->pCursor);
    }
  }
  return pCx;
}

/*
................................................................................
      int v1;    /* Left operand:  0==FALSE, 1==TRUE, 2==UNKNOWN or NULL */
      int v2;    /* Right operand: 0==FALSE, 1==TRUE, 2==UNKNOWN or NULL */
    } an;
    struct OP_IfNot_stack_vars {
      int c;
    } ao;
    struct OP_Column_stack_vars {

      i64 payloadSize64; /* Number of bytes in the record */

      int p2;            /* column number to retrieve */
      VdbeCursor *pC;    /* The VDBE cursor */

      BtCursor *pCrsr;   /* The BTree cursor */
      u32 *aType;        /* aType[i] holds the numeric type of the i-th column */
      u32 *aOffset;      /* aOffset[i] is offset to start of data for i-th column */

      int len;           /* The length of the serialized data for the column */
      int i;             /* Loop counter */

      Mem *pDest;        /* Where to write the extracted value */
      Mem sMem;          /* For storing the record being decoded */

      const u8 *zData;   /* Part of the record being decoded */
      const u8 *zHdr;    /* Next unparsed byte of the header */
      const u8 *zEndHdr; /* Pointer to first byte after the header */
      u32 offset;        /* Offset into the data */
      u32 szField;       /* Number of bytes in the content of a field */

      u32 avail;         /* Number of bytes of available data */
      u32 t;             /* A type code from the record header */
      Mem *pReg;         /* PseudoTable input register */
    } ap;
    struct OP_Affinity_stack_vars {
      const char *zAffinity;   /* The affinity to be applied */
      char cAff;               /* A single character of affinity */
    } aq;
................................................................................
      int res;
    } bp;
    struct OP_Rewind_stack_vars {
      VdbeCursor *pC;
      BtCursor *pCrsr;
      int res;
    } bq;
    struct OP_SorterNext_stack_vars {
      VdbeCursor *pC;
      int res;
    } br;
    struct OP_IdxInsert_stack_vars {
      VdbeCursor *pC;
      BtCursor *pCrsr;
      int nKey;
................................................................................
#if 0  /* local variables moved into u.ae */
  char *zMalloc;   /* Holding variable for allocated memory */
  int n;           /* Number of registers left to copy */
  int p1;          /* Register to copy from */
  int p2;          /* Register to copy to */
#endif /* local variables moved into u.ae */

  u.ae.n = pOp->p3;
  u.ae.p1 = pOp->p1;
  u.ae.p2 = pOp->p2;
  assert( u.ae.n>=0 && u.ae.p1>0 && u.ae.p2>0 );
  assert( u.ae.p1+u.ae.n<=u.ae.p2 || u.ae.p2+u.ae.n<=u.ae.p1 );

  pIn1 = &aMem[u.ae.p1];
  pOut = &aMem[u.ae.p2];
  do{
    assert( pOut<=&aMem[(p->nMem-p->nCursor)] );
    assert( pIn1<=&aMem[(p->nMem-p->nCursor)] );
    assert( memIsValid(pIn1) );
    memAboutToChange(p, pOut);
    u.ae.zMalloc = pOut->zMalloc;
    pOut->zMalloc = 0;
    sqlite3VdbeMemMove(pOut, pIn1);
................................................................................
      pOut->pScopyFrom += u.ae.p1 - pOp->p2;
    }
#endif
    pIn1->zMalloc = u.ae.zMalloc;
    REGISTER_TRACE(u.ae.p2++, pOut);
    pIn1++;
    pOut++;
  }while( u.ae.n-- );
  break;
}

/* Opcode: Copy P1 P2 P3 * *
** Synopsis: r[P2@P3]=r[P1@P3]
**
** Make a copy of registers P1..P1+P3 into registers P2..P2+P3.
................................................................................
    Deephemeralize(u.aj.pArg);
    sqlite3VdbeMemStoreType(u.aj.pArg);
    REGISTER_TRACE(pOp->p2+u.aj.i, u.aj.pArg);
  }

  assert( pOp->p4type==P4_FUNCDEF );
  u.aj.ctx.pFunc = pOp->p4.pFunc;




  u.aj.ctx.iOp = pc;
  u.aj.ctx.pVdbe = p;

  /* The output cell may already have a buffer allocated. Move
  ** the pointer to u.aj.ctx.s so in case the user-function can use
  ** the already allocated buffer instead of allocating a new one.
  */
  memcpy(&u.aj.ctx.s, pOut, sizeof(Mem));
  pOut->flags = MEM_Null;
  pOut->xDel = 0;
  pOut->zMalloc = 0;
  MemSetTypeFlag(&u.aj.ctx.s, MEM_Null);

  u.aj.ctx.fErrorOrAux = 0;
  if( u.aj.ctx.pFunc->funcFlags & SQLITE_FUNC_NEEDCOLL ){
    assert( pOp>aOp );
    assert( pOp[-1].p4type==P4_COLLSEQ );
    assert( pOp[-1].opcode==OP_CollSeq );
................................................................................
      rc = u.aj.ctx.isError;
    }
    sqlite3VdbeDeleteAuxData(p, pc, pOp->p1);
  }

  /* Copy the result of the function into register P3 */
  sqlite3VdbeChangeEncoding(&u.aj.ctx.s, encoding);
  assert( pOut->flags==MEM_Null );
  memcpy(pOut, &u.aj.ctx.s, sizeof(Mem));
  if( sqlite3VdbeMemTooBig(pOut) ){
    goto too_big;
  }

#if 0
  /* The app-defined function has done something that as caused this
  ** statement to expire.  (Perhaps the function called sqlite3_exec()
................................................................................
** Force the value in register P1 to be an integer.  If the value
** in P1 is not an integer and cannot be converted into an integer
** 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);
    if( (pIn1->flags & MEM_Int)==0 ){
      if( pOp->p2==0 ){
        rc = SQLITE_MISMATCH;
        goto abort_due_to_error;
      }else{
        pc = pOp->p2 - 1;
        break;
      }


    }
  }
  MemSetTypeFlag(pIn1, MEM_Int);
  break;
}

#ifndef SQLITE_OMIT_FLOATING_POINT
/* Opcode: RealAffinity P1 * * * *
**
** If register P1 holds an integer convert it to a real value.
................................................................................
** If the OPFLAG_LENGTHARG and OPFLAG_TYPEOFARG bits are set on P5 when
** the result is guaranteed to only be used as the argument of a length()
** or typeof() function, respectively.  The loading of large blobs can be
** skipped for length() and all content loading can be skipped for typeof().
*/
case OP_Column: {
#if 0  /* local variables moved into u.ap */

  i64 payloadSize64; /* Number of bytes in the record */

  int p2;            /* column number to retrieve */
  VdbeCursor *pC;    /* The VDBE cursor */

  BtCursor *pCrsr;   /* The BTree cursor */
  u32 *aType;        /* aType[i] holds the numeric type of the i-th column */
  u32 *aOffset;      /* aOffset[i] is offset to start of data for i-th column */

  int len;           /* The length of the serialized data for the column */
  int i;             /* Loop counter */

  Mem *pDest;        /* Where to write the extracted value */
  Mem sMem;          /* For storing the record being decoded */

  const u8 *zData;   /* Part of the record being decoded */
  const u8 *zHdr;    /* Next unparsed byte of the header */
  const u8 *zEndHdr; /* Pointer to first byte after the header */
  u32 offset;        /* Offset into the data */
  u32 szField;       /* Number of bytes in the content of a field */

  u32 avail;         /* Number of bytes of available data */
  u32 t;             /* A type code from the record header */
  Mem *pReg;         /* PseudoTable input register */
#endif /* local variables moved into u.ap */



  u.ap.p2 = pOp->p2;



  assert( pOp->p3>0 && pOp->p3<=(p->nMem-p->nCursor) );
  u.ap.pDest = &aMem[pOp->p3];
  memAboutToChange(p, u.ap.pDest);
  assert( pOp->p1>=0 && pOp->p1<p->nCursor );
  u.ap.pC = p->apCsr[pOp->p1];
  assert( u.ap.pC!=0 );
  assert( u.ap.p2<u.ap.pC->nField );
  u.ap.aType = u.ap.pC->aType;
  u.ap.aOffset = u.ap.aType + u.ap.pC->nField;
#ifndef SQLITE_OMIT_VIRTUALTABLE
  assert( u.ap.pC->pVtabCursor==0 ); /* OP_Column never called on virtual table */
#endif
  u.ap.pCrsr = u.ap.pC->pCursor;
  assert( u.ap.pCrsr!=0 || u.ap.pC->pseudoTableReg>0 ); /* u.ap.pCrsr NULL on PseudoTables */
  assert( u.ap.pCrsr!=0 || u.ap.pC->nullRow );          /* u.ap.pC->nullRow on PseudoTables */

  /* If the cursor cache is stale, bring it up-to-date */
  rc = sqlite3VdbeCursorMoveto(u.ap.pC);
  if( rc ) goto abort_due_to_error;
  if( u.ap.pC->cacheStatus!=p->cacheCtr || (pOp->p5&OPFLAG_CLEARCACHE)!=0 ){
    if( u.ap.pC->nullRow ){
      if( u.ap.pCrsr==0 ){
        assert( u.ap.pC->pseudoTableReg>0 );
        u.ap.pReg = &aMem[u.ap.pC->pseudoTableReg];
        if( u.ap.pC->multiPseudo ){
          sqlite3VdbeMemShallowCopy(u.ap.pDest, u.ap.pReg+u.ap.p2, MEM_Ephem);
          Deephemeralize(u.ap.pDest);
          goto op_column_out;
        }
        assert( u.ap.pReg->flags & MEM_Blob );
        assert( memIsValid(u.ap.pReg) );
        u.ap.pC->payloadSize = u.ap.pC->szRow = u.ap.avail = u.ap.pReg->n;
        u.ap.pC->aRow = (u8*)u.ap.pReg->z;
      }else{
        MemSetTypeFlag(u.ap.pDest, MEM_Null);
        goto op_column_out;
      }
    }else{
      assert( u.ap.pCrsr );
      if( u.ap.pC->isTable==0 ){
        assert( sqlite3BtreeCursorIsValid(u.ap.pCrsr) );
        VVA_ONLY(rc =) sqlite3BtreeKeySize(u.ap.pCrsr, &u.ap.payloadSize64);
        assert( rc==SQLITE_OK ); /* True because of CursorMoveto() call above */
        /* sqlite3BtreeParseCellPtr() uses getVarint32() to extract the
        ** payload size, so it is impossible for u.ap.payloadSize64 to be
        ** larger than 32 bits. */
        assert( (u.ap.payloadSize64 & SQLITE_MAX_U32)==(u64)u.ap.payloadSize64 );
        u.ap.pC->aRow = sqlite3BtreeKeyFetch(u.ap.pCrsr, &u.ap.avail);
        u.ap.pC->payloadSize = (u32)u.ap.payloadSize64;
      }else{
        assert( sqlite3BtreeCursorIsValid(u.ap.pCrsr) );
        VVA_ONLY(rc =) sqlite3BtreeDataSize(u.ap.pCrsr, &u.ap.pC->payloadSize);
        assert( rc==SQLITE_OK );   /* DataSize() cannot fail */
        u.ap.pC->aRow = sqlite3BtreeDataFetch(u.ap.pCrsr, &u.ap.avail);
      }
      assert( u.ap.avail<=65536 );  /* Maximum page size is 64KiB */
      if( u.ap.pC->payloadSize <= (u32)u.ap.avail ){
        u.ap.pC->szRow = u.ap.pC->payloadSize;
      }else{
        u.ap.pC->szRow = u.ap.avail;
      }
      if( u.ap.pC->payloadSize > (u32)db->aLimit[SQLITE_LIMIT_LENGTH] ){
        goto too_big;
      }
    }
    u.ap.pC->cacheStatus = p->cacheCtr;
    u.ap.pC->iHdrOffset = getVarint32(u.ap.pC->aRow, u.ap.offset);
    u.ap.pC->nHdrParsed = 0;
    u.ap.aOffset[0] = u.ap.offset;
    if( u.ap.avail<u.ap.offset ){
      /* u.ap.pC->aRow does not have to hold the entire row, but it does at least
      ** need to cover the header of the record.  If u.ap.pC->aRow does not contain
      ** the complete header, then set it to zero, forcing the header to be
      ** dynamically allocated. */
      u.ap.pC->aRow = 0;
      u.ap.pC->szRow = 0;
    }







































    /* Make sure a corrupt database has not given us an oversize header.
    ** Do this now to avoid an oversize memory allocation.
    **
    ** Type entries can be between 1 and 5 bytes each.  But 4 and 5 byte
    ** types use so much data space that there can only be 4096 and 32 of
    ** them, respectively.  So the maximum header length results from a
    ** 3-byte type for each of the maximum of 32768 columns plus three
    ** extra bytes for the header length itself.  32768*3 + 3 = 98307.
    */
    if( u.ap.offset > 98307 || u.ap.offset > u.ap.pC->payloadSize ){
      rc = SQLITE_CORRUPT_BKPT;
      goto op_column_error;
    }
  }


  /* Make sure at least the first u.ap.p2+1 entries of the header have been
  ** parsed and valid information is in u.ap.aOffset[] and u.ap.aType[].









  */








  if( u.ap.pC->nHdrParsed<=u.ap.p2 ){
    /* If there is more header available for parsing in the record, try
    ** to extract additional fields up through the u.ap.p2+1-th field
    */



    if( u.ap.pC->iHdrOffset<u.ap.aOffset[0] ){
      /* Make sure u.ap.zData points to enough of the record to cover the header. */
      if( u.ap.pC->aRow==0 ){
        memset(&u.ap.sMem, 0, sizeof(u.ap.sMem));
        rc = sqlite3VdbeMemFromBtree(u.ap.pCrsr, 0, u.ap.aOffset[0],
                                     !u.ap.pC->isTable, &u.ap.sMem);
        if( rc!=SQLITE_OK ){
          goto op_column_error;
        }
        u.ap.zData = (u8*)u.ap.sMem.z;
      }else{
        u.ap.zData = u.ap.pC->aRow;
      }





      /* Fill in u.ap.aType[u.ap.i] and u.ap.aOffset[u.ap.i] values through the u.ap.p2-th field. */
      u.ap.i = u.ap.pC->nHdrParsed;
      u.ap.offset = u.ap.aOffset[u.ap.i];



      u.ap.zHdr = u.ap.zData + u.ap.pC->iHdrOffset;
      u.ap.zEndHdr = u.ap.zData + u.ap.aOffset[0];

      assert( u.ap.i<=u.ap.p2 && u.ap.zHdr<u.ap.zEndHdr );
      do{
        if( u.ap.zHdr[0]<0x80 ){
          u.ap.t = u.ap.zHdr[0];
          u.ap.zHdr++;
        }else{
          u.ap.zHdr += sqlite3GetVarint32(u.ap.zHdr, &u.ap.t);
        }
        u.ap.aType[u.ap.i] = u.ap.t;
        u.ap.szField = sqlite3VdbeSerialTypeLen(u.ap.t);
        u.ap.offset += u.ap.szField;
        if( u.ap.offset<u.ap.szField ){  /* True if u.ap.offset overflows */
          u.ap.zHdr = &u.ap.zEndHdr[1];  /* Forces SQLITE_CORRUPT return below */
          break;
        }







        u.ap.i++;
        u.ap.aOffset[u.ap.i] = u.ap.offset;


      }while( u.ap.i<=u.ap.p2 && u.ap.zHdr<u.ap.zEndHdr );
      u.ap.pC->nHdrParsed = u.ap.i;
      u.ap.pC->iHdrOffset = (u32)(u.ap.zHdr - u.ap.zData);
      if( u.ap.pC->aRow==0 ){
        sqlite3VdbeMemRelease(&u.ap.sMem);
        u.ap.sMem.flags = MEM_Null;
      }

      /* If we have read more header data than was contained in the header,
      ** or if the end of the last field appears to be past the end of the
      ** record, or if the end of the last field appears to be before the end
      ** of the record (when all fields present), then we must be dealing
      ** with a corrupt database.
      */
      if( (u.ap.zHdr > u.ap.zEndHdr)
       || (u.ap.offset > u.ap.pC->payloadSize)
       || (u.ap.zHdr==u.ap.zEndHdr && u.ap.offset!=u.ap.pC->payloadSize)
      ){
        rc = SQLITE_CORRUPT_BKPT;
        goto op_column_error;
      }
    }

    /* If after trying to extra new entries from the header, nHdrParsed is
    ** still not up to u.ap.p2, that means that the record has fewer than u.ap.p2
    ** columns.  So the result will be either the default value or a NULL.
    */
    if( u.ap.pC->nHdrParsed<=u.ap.p2 ){
      if( pOp->p4type==P4_MEM ){
        sqlite3VdbeMemShallowCopy(u.ap.pDest, pOp->p4.pMem, MEM_Static);
      }else{
        MemSetTypeFlag(u.ap.pDest, MEM_Null);
      }
      goto op_column_out;
    }
  }

  /* Extract the content for the u.ap.p2+1-th column.  Control can only
  ** reach this point if u.ap.aOffset[u.ap.p2], u.ap.aOffset[u.ap.p2+1], and u.ap.aType[u.ap.p2] are
  ** all valid.


  */

  assert( u.ap.p2<u.ap.pC->nHdrParsed );
  assert( rc==SQLITE_OK );

  if( u.ap.pC->szRow>=u.ap.aOffset[u.ap.p2+1] ){
    /* This is the common case where the desired content fits on the original
    ** page - where the content is not on an overflow page */
    VdbeMemRelease(u.ap.pDest);
    sqlite3VdbeSerialGet(u.ap.pC->aRow+u.ap.aOffset[u.ap.p2], u.ap.aType[u.ap.p2], u.ap.pDest);
  }else{
    /* This branch happens only when content is on overflow pages */
    u.ap.t = u.ap.aType[u.ap.p2];
    if( ((pOp->p5 & (OPFLAG_LENGTHARG|OPFLAG_TYPEOFARG))!=0
          && ((u.ap.t>=12 && (u.ap.t&1)==0) || (pOp->p5 & OPFLAG_TYPEOFARG)!=0))
     || (u.ap.len = sqlite3VdbeSerialTypeLen(u.ap.t))==0
    ){
      /* Content is irrelevant for the typeof() function and for
      ** the length(X) function if X is a blob.  So we might as well use
      ** bogus content rather than reading content from disk.  NULL works
      ** for text and blob and whatever is in the u.ap.payloadSize64 variable
      ** will work for everything else.  Content is also irrelevant if
      ** the content length is 0. */
      u.ap.zData = u.ap.t<=13 ? (u8*)&u.ap.payloadSize64 : 0;
      u.ap.sMem.zMalloc = 0;
    }else{

      memset(&u.ap.sMem, 0, sizeof(u.ap.sMem));
      sqlite3VdbeMemMove(&u.ap.sMem, u.ap.pDest);
      rc = sqlite3VdbeMemFromBtree(u.ap.pCrsr, u.ap.aOffset[u.ap.p2], u.ap.len, !u.ap.pC->isTable,
                                   &u.ap.sMem);
      if( rc!=SQLITE_OK ){
        goto op_column_error;
      }
      u.ap.zData = (u8*)u.ap.sMem.z;
    }
    sqlite3VdbeSerialGet(u.ap.zData, u.ap.t, u.ap.pDest);










    /* If we dynamically allocated space to hold the data (in the
    ** sqlite3VdbeMemFromBtree() call above) then transfer control of that
    ** dynamically allocated space over to the u.ap.pDest structure.
    ** This prevents a memory copy. */

    if( u.ap.sMem.zMalloc ){
      assert( u.ap.sMem.z==u.ap.sMem.zMalloc );
      assert( !(u.ap.pDest->flags & MEM_Dyn) );
      assert( !(u.ap.pDest->flags & (MEM_Blob|MEM_Str)) || u.ap.pDest->z==u.ap.sMem.z );
      u.ap.pDest->flags &= ~(MEM_Ephem|MEM_Static);
      u.ap.pDest->flags |= MEM_Term;
      u.ap.pDest->z = u.ap.sMem.z;
      u.ap.pDest->zMalloc = u.ap.sMem.zMalloc;
    }
  }

  u.ap.pDest->enc = encoding;

op_column_out:
  rc = sqlite3VdbeMemMakeWriteable(u.ap.pDest);
op_column_error:
  UPDATE_MAX_BLOBSIZE(u.ap.pDest);
  REGISTER_TRACE(pOp->p3, u.ap.pDest);
  break;
}

/* Opcode: Affinity P1 P2 * P4 *
** Synopsis: affinity(r[P1@P2])
................................................................................
    assert( u.az.pKeyInfo->enc==ENC(db) );
    assert( u.az.pKeyInfo->db==db );
    u.az.nField = u.az.pKeyInfo->nField+u.az.pKeyInfo->nXField;
  }else if( pOp->p4type==P4_INT32 ){
    u.az.nField = pOp->p4.i;
  }
  assert( pOp->p1>=0 );
  assert( u.az.nField>=0 );
  testcase( u.az.nField==0 );  /* Table with INTEGER PRIMARY KEY and nothing else */
  u.az.pCur = allocateCursor(p, pOp->p1, u.az.nField, u.az.iDb, 1);
  if( u.az.pCur==0 ) goto no_mem;
  u.az.pCur->nullRow = 1;
  u.az.pCur->isOrdered = 1;
  rc = sqlite3BtreeCursor(u.az.pX, u.az.p2, u.az.wrFlag, u.az.pKeyInfo, u.az.pCur->pCursor);
  u.az.pCur->pKeyInfo = u.az.pKeyInfo;
  assert( OPFLAG_BULKCSR==BTREE_BULKLOAD );
  sqlite3BtreeCursorHints(u.az.pCur->pCursor, (pOp->p5 & OPFLAG_BULKCSR));

  /* Since it performs no memory allocation or IO, the only value that
  ** sqlite3BtreeCursor() may return is SQLITE_OK. */
  assert( rc==SQLITE_OK );

  /* Set the VdbeCursor.isTable variable. Previous versions of
  ** SQLite used to check if the root-page flags were sane at this point
  ** and report database corruption if they were not, but this check has
  ** since moved into the btree layer.  */
  u.az.pCur->isTable = pOp->p4type!=P4_KEYINFO;

  break;
}

/* Opcode: OpenEphemeral P1 P2 * P4 P5
** Synopsis: nColumn=P2
**
** Open a new cursor P1 to a transient table.
................................................................................
  static const int vfsFlags =
      SQLITE_OPEN_READWRITE |
      SQLITE_OPEN_CREATE |
      SQLITE_OPEN_EXCLUSIVE |
      SQLITE_OPEN_DELETEONCLOSE |
      SQLITE_OPEN_TRANSIENT_DB;
  assert( pOp->p1>=0 );
  assert( pOp->p2>=0 );
  u.ba.pCx = allocateCursor(p, pOp->p1, pOp->p2, -1, 1);
  if( u.ba.pCx==0 ) goto no_mem;
  u.ba.pCx->nullRow = 1;
  rc = sqlite3BtreeOpen(db->pVfs, 0, db, &u.ba.pCx->pBt,
                        BTREE_OMIT_JOURNAL | BTREE_SINGLE | pOp->p5, vfsFlags);
  if( rc==SQLITE_OK ){
    rc = sqlite3BtreeBeginTrans(u.ba.pCx->pBt, 1);
................................................................................
      u.ba.pCx->isTable = 0;
    }else{
      rc = sqlite3BtreeCursor(u.ba.pCx->pBt, MASTER_ROOT, 1, 0, u.ba.pCx->pCursor);
      u.ba.pCx->isTable = 1;
    }
  }
  u.ba.pCx->isOrdered = (pOp->p5!=BTREE_UNORDERED);

  break;
}

/* Opcode: SorterOpen P1 * * P4 *
**
** This opcode works like OP_OpenEphemeral except that it opens
** a transient index that is specifically designed to sort large
................................................................................
** tables using an external merge-sort algorithm.
*/
case OP_SorterOpen: {
#if 0  /* local variables moved into u.bb */
  VdbeCursor *pCx;
#endif /* local variables moved into u.bb */

  assert( pOp->p1>=0 );
  assert( pOp->p2>=0 );
  u.bb.pCx = allocateCursor(p, pOp->p1, pOp->p2, -1, 1);
  if( u.bb.pCx==0 ) goto no_mem;
  u.bb.pCx->pKeyInfo = pOp->p4.pKeyInfo;
  assert( u.bb.pCx->pKeyInfo->db==db );
  assert( u.bb.pCx->pKeyInfo->enc==ENC(db) );

  rc = sqlite3VdbeSorterInit(db, u.bb.pCx);
  break;
}

/* Opcode: OpenPseudo P1 P2 P3 * P5
** Synopsis: content in r[P2@P3]
**
................................................................................
*/
case OP_OpenPseudo: {
#if 0  /* local variables moved into u.bc */
  VdbeCursor *pCx;
#endif /* local variables moved into u.bc */

  assert( pOp->p1>=0 );
  assert( pOp->p3>=0 );
  u.bc.pCx = allocateCursor(p, pOp->p1, pOp->p3, -1, 0);
  if( u.bc.pCx==0 ) goto no_mem;
  u.bc.pCx->nullRow = 1;
  u.bc.pCx->pseudoTableReg = pOp->p2;
  u.bc.pCx->isTable = 1;

  u.bc.pCx->multiPseudo = pOp->p5;
  break;
}

/* Opcode: Close P1 * * * *
**
** Close a cursor previously opened as P1.  If P1 is not
................................................................................
case OP_SorterData: {
#if 0  /* local variables moved into u.bl */
  VdbeCursor *pC;
#endif /* local variables moved into u.bl */

  pOut = &aMem[pOp->p2];
  u.bl.pC = p->apCsr[pOp->p1];
  assert( isSorter(u.bl.pC) );
  rc = sqlite3VdbeSorterRowkey(u.bl.pC, pOut);
  break;
}

/* Opcode: RowData P1 P2 * * *
** Synopsis: r[P2]=data
**
................................................................................

  pOut = &aMem[pOp->p2];
  memAboutToChange(p, pOut);

  /* Note that RowKey and RowData are really exactly the same instruction */
  assert( pOp->p1>=0 && pOp->p1<p->nCursor );
  u.bm.pC = p->apCsr[pOp->p1];
  assert( isSorter(u.bm.pC)==0 );
  assert( u.bm.pC->isTable || pOp->opcode!=OP_RowData );
  assert( u.bm.pC->isTable==0 || pOp->opcode==OP_RowData );
  assert( u.bm.pC!=0 );
  assert( u.bm.pC->nullRow==0 );
  assert( u.bm.pC->pseudoTableReg==0 );
  assert( u.bm.pC->pCursor!=0 );
  u.bm.pCrsr = u.bm.pC->pCursor;
  assert( sqlite3BtreeCursorIsValid(u.bm.pCrsr) );

................................................................................
  ** the cursor.  Hence the following sqlite3VdbeCursorMoveto() call is always
  ** a no-op and can never fail.  But we leave it in place as a safety.
  */
  assert( u.bm.pC->deferredMoveto==0 );
  rc = sqlite3VdbeCursorMoveto(u.bm.pC);
  if( NEVER(rc!=SQLITE_OK) ) goto abort_due_to_error;

  if( u.bm.pC->isTable==0 ){
    assert( !u.bm.pC->isTable );
    VVA_ONLY(rc =) sqlite3BtreeKeySize(u.bm.pCrsr, &u.bm.n64);
    assert( rc==SQLITE_OK );    /* True because of CursorMoveto() call above */
    if( u.bm.n64>db->aLimit[SQLITE_LIMIT_LENGTH] ){
      goto too_big;
    }
    u.bm.n = (u32)u.bm.n64;
................................................................................
    }
  }
  if( sqlite3VdbeMemGrow(pOut, u.bm.n, 0) ){
    goto no_mem;
  }
  pOut->n = u.bm.n;
  MemSetTypeFlag(pOut, MEM_Blob);
  if( u.bm.pC->isTable==0 ){
    rc = sqlite3BtreeKey(u.bm.pCrsr, 0, u.bm.n, pOut->z);
  }else{
    rc = sqlite3BtreeData(u.bm.pCrsr, 0, u.bm.n, pOut->z);
  }
  pOut->enc = SQLITE_UTF8;  /* In case the blob is ever cast to text */
  UPDATE_MAX_BLOBSIZE(pOut);
  REGISTER_TRACE(pOp->p2, pOut);
................................................................................
#endif /* local variables moved into u.bo */

  assert( pOp->p1>=0 && pOp->p1<p->nCursor );
  u.bo.pC = p->apCsr[pOp->p1];
  assert( u.bo.pC!=0 );
  u.bo.pC->nullRow = 1;
  u.bo.pC->rowidIsValid = 0;
  u.bo.pC->cacheStatus = CACHE_STALE;
  assert( u.bo.pC->pCursor || u.bo.pC->pVtabCursor );
  if( u.bo.pC->pCursor ){
    sqlite3BtreeClearCursor(u.bo.pC->pCursor);
  }
  break;
}

................................................................................
  BtCursor *pCrsr;
  int res;
#endif /* local variables moved into u.bq */

  assert( pOp->p1>=0 && pOp->p1<p->nCursor );
  u.bq.pC = p->apCsr[pOp->p1];
  assert( u.bq.pC!=0 );
  assert( isSorter(u.bq.pC)==(pOp->opcode==OP_SorterSort) );
  u.bq.res = 1;
  if( isSorter(u.bq.pC) ){
    rc = sqlite3VdbeSorterRewind(db, u.bq.pC, &u.bq.res);
  }else{
    u.bq.pCrsr = u.bq.pC->pCursor;
    assert( u.bq.pCrsr );
    rc = sqlite3BtreeFirst(u.bq.pCrsr, &u.bq.res);

    u.bq.pC->deferredMoveto = 0;
    u.bq.pC->cacheStatus = CACHE_STALE;
    u.bq.pC->rowidIsValid = 0;
  }
  u.bq.pC->nullRow = (u8)u.bq.res;
  assert( pOp->p2>0 && pOp->p2<p->nOp );
  if( u.bq.res ){
................................................................................
/* Opcode: Next P1 P2 * * P5
**
** Advance cursor P1 so that it points to the next key/data pair in its
** table or index.  If there are no more key/value pairs then fall through
** to the following instruction.  But if the cursor advance was successful,
** jump immediately to P2.
**
** The P1 cursor must be for a real table, not a pseudo-table.  P1 must have
** been opened prior to this opcode or the program will segfault.
**
** P4 is always of type P4_ADVANCE. The function pointer points to
** sqlite3BtreeNext().
**
** If P5 is positive and the jump is taken, then event counter
** number P5-1 in the prepared statement is incremented.
**
** See also: Prev, NextIfOpen
*/
/* Opcode: NextIfOpen P1 P2 * * P5
**
** This opcode works just like OP_Next except that if cursor P1 is not
** open it behaves a no-op.
*/
/* Opcode: Prev P1 P2 * * P5
**
** Back up cursor P1 so that it points to the previous key/data pair in its
** table or index.  If there is no previous key/value pairs then fall through
** to the following instruction.  But if the cursor backup was successful,
** jump immediately to P2.
**
** The P1 cursor must be for a real table, not a pseudo-table.  If P1 is
** not open then the behavior is undefined.
**
** P4 is always of type P4_ADVANCE. The function pointer points to
** sqlite3BtreePrevious().
**
** If P5 is positive and the jump is taken, then event counter
** number P5-1 in the prepared statement is incremented.
*/
/* Opcode: PrevIfOpen P1 P2 * * P5
**
** This opcode works just like OP_Prev except that if cursor P1 is not
** open it behaves a no-op.
*/
case OP_SorterNext: {  /* jump */
#if 0  /* local variables moved into u.br */
  VdbeCursor *pC;
  int res;
#endif /* local variables moved into u.br */

  u.br.pC = p->apCsr[pOp->p1];
  assert( isSorter(u.br.pC) );
  rc = sqlite3VdbeSorterNext(db, u.br.pC, &u.br.res);
  goto next_tail;
case OP_PrevIfOpen:    /* jump */
case OP_NextIfOpen:    /* jump */
  if( p->apCsr[pOp->p1]==0 ) break;
  /* Fall through */
case OP_Prev:          /* jump */
case OP_Next:          /* jump */
  assert( pOp->p1>=0 && pOp->p1<p->nCursor );
  assert( pOp->p5<ArraySize(p->aCounter) );
  u.br.pC = p->apCsr[pOp->p1];
  assert( u.br.pC!=0 );








  assert( u.br.pC->deferredMoveto==0 );
  assert( u.br.pC->pCursor );
  assert( pOp->opcode!=OP_Next || pOp->p4.xAdvance==sqlite3BtreeNext );
  assert( pOp->opcode!=OP_Prev || pOp->p4.xAdvance==sqlite3BtreePrevious );
  assert( pOp->opcode!=OP_NextIfOpen || pOp->p4.xAdvance==sqlite3BtreeNext );
  assert( pOp->opcode!=OP_PrevIfOpen || pOp->p4.xAdvance==sqlite3BtreePrevious);
  rc = pOp->p4.xAdvance(u.br.pC->pCursor, &u.br.res);


next_tail:
  u.br.pC->cacheStatus = CACHE_STALE;
  if( u.br.res==0 ){
    u.br.pC->nullRow = 0;
    pc = pOp->p2 - 1;
    p->aCounter[pOp->p5]++;
#ifdef SQLITE_TEST
    sqlite3_search_count++;
#endif
  }else{
    u.br.pC->nullRow = 1;
  }
  u.br.pC->rowidIsValid = 0;
  goto check_for_interrupt;
}

/* Opcode: IdxInsert P1 P2 P3 * P5
** Synopsis: key=r[P2]
................................................................................
  int nKey;
  const char *zKey;
#endif /* local variables moved into u.bs */

  assert( pOp->p1>=0 && pOp->p1<p->nCursor );
  u.bs.pC = p->apCsr[pOp->p1];
  assert( u.bs.pC!=0 );
  assert( isSorter(u.bs.pC)==(pOp->opcode==OP_SorterInsert) );
  pIn2 = &aMem[pOp->p2];
  assert( pIn2->flags & MEM_Blob );
  u.bs.pCrsr = u.bs.pC->pCursor;
  if( pOp->p5 & OPFLAG_NCHANGE ) p->nChange++;
  assert( u.bs.pCrsr!=0 );
  assert( u.bs.pC->isTable==0 );
  rc = ExpandBlob(pIn2);
................................................................................
    /* Initialize sqlite3_vtab_cursor base class */
    u.cm.pVtabCursor->pVtab = u.cm.pVtab;

    /* Initialize vdbe cursor object */
    u.cm.pCur = allocateCursor(p, pOp->p1, 0, -1, 0);
    if( u.cm.pCur ){
      u.cm.pCur->pVtabCursor = u.cm.pVtabCursor;

    }else{
      db->mallocFailed = 1;
      u.cm.pModule->xClose(u.cm.pVtabCursor);
    }
  }
  break;
}
................................................................................
  ** triggering asserts related to mutexes.
  */
  assert( v->aVar[0].flags&MEM_Int );
  v->aVar[0].u.i = iRow;

  rc = sqlite3_step(p->pStmt);
  if( rc==SQLITE_ROW ){
    VdbeCursor *pC = v->apCsr[0];
    u32 type = pC->aType[p->iCol];
    if( type<12 ){
      zErr = sqlite3MPrintf(p->db, "cannot open value of type %s",
          type==0?"null": type==7?"real": "integer"
      );
      rc = SQLITE_ERROR;
      sqlite3_finalize(p->pStmt);
      p->pStmt = 0;
    }else{
      p->iOffset = pC->aType[p->iCol + pC->nField];
      p->nByte = sqlite3VdbeSerialTypeLen(type);
      p->pCsr =  pC->pCursor;
      sqlite3BtreeEnterCursor(p->pCsr);
      sqlite3BtreeCacheOverflow(p->pCsr);
      sqlite3BtreeLeaveCursor(p->pCsr);
    }
  }

  if( rc==SQLITE_ROW ){
................................................................................
        zColumn = pRight->pRight->u.zToken;
      }
      return lookupName(pParse, zDb, zTable, zColumn, pNC, pExpr);
    }

    /* Resolve function names
    */

    case TK_FUNCTION: {
      ExprList *pList = pExpr->x.pList;    /* The argument list */
      int n = pList ? pList->nExpr : 0;    /* Number of arguments */
      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 auth;                   /* Authorization to use the 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 */


      assert( !ExprHasProperty(pExpr, EP_xIsSelect) );
      notValidPartIdxWhere(pParse, pNC, "functions");
      zId = pExpr->u.zToken;
      nId = sqlite3Strlen30(zId);
      pDef = sqlite3FindFunction(pParse->db, zId, nId, n, enc, 0);
      if( pDef==0 ){
        pDef = sqlite3FindFunction(pParse->db, zId, nId, -2, enc, 0);
................................................................................
            sqlite3ErrorMsg(pParse, "not authorized to use function: %s",
                                    pDef->zName);
            pNC->nErr++;
          }
          pExpr->op = TK_NULL;
          return WRC_Prune;
        }
        if( pDef->funcFlags & SQLITE_FUNC_CONSTANT ) ExprSetProperty(pExpr,EP_Constant);
      }
#endif
      if( is_agg && (pNC->ncFlags & NC_AllowAgg)==0 ){
        sqlite3ErrorMsg(pParse, "misuse of aggregate function %.*s()", nId,zId);
        pNC->nErr++;
        is_agg = 0;
      }else if( no_such_func && pParse->db->init.busy==0 ){
................................................................................
  if( pWalker->u.i==3 && ExprHasProperty(pExpr, EP_FromJoin) ){
    pWalker->u.i = 0;
    return WRC_Abort;
  }

  switch( pExpr->op ){
    /* Consider functions to be constant if all their arguments are constant
    ** and either pWalker->u.i==2 or the function as the SQLITE_FUNC_CONST
    ** flag. */
    case TK_FUNCTION:
      if( pWalker->u.i==2 || ExprHasProperty(pExpr,EP_Constant) ){
        return WRC_Continue;
      }
      /* Fall through */
    case TK_ID:
    case TK_COLUMN:
    case TK_AGG_FUNCTION:
    case TK_AGG_COLUMN:
      testcase( pExpr->op==TK_ID );
      testcase( pExpr->op==TK_COLUMN );
................................................................................
        assert( !ExprHasProperty(pExpr, EP_IntValue) );
        sqlite3ErrorMsg(pParse, "misuse of aggregate: %s()", pExpr->u.zToken);
      }else{
        inReg = pInfo->aFunc[pExpr->iAgg].iMem;
      }
      break;
    }

    case TK_FUNCTION: {
      ExprList *pFarg;       /* List of function arguments */
      int nFarg;             /* Number of function arguments */
      FuncDef *pDef;         /* The function definition object */
      int nId;               /* Length of the function name in bytes */
      const char *zId;       /* The function name */
      int constMask = 0;     /* Mask of function arguments that are constant */
      int i;                 /* Loop counter */
      u8 enc = ENC(db);      /* The text encoding used by this database */
      CollSeq *pColl = 0;    /* A collating sequence */

      assert( !ExprHasProperty(pExpr, EP_xIsSelect) );


      if( ExprHasProperty(pExpr, EP_TokenOnly) ){
        pFarg = 0;
      }else{
        pFarg = pExpr->x.pList;
      }
      nFarg = pFarg ? pFarg->nExpr : 0;
      assert( !ExprHasProperty(pExpr, EP_IntValue) );
................................................................................
      */
      if( pDef->funcFlags & SQLITE_FUNC_UNLIKELY ){
        assert( nFarg>=1 );
        sqlite3ExprCode(pParse, pFarg->a[0].pExpr, target);
        break;
      }

      for(i=0; i<nFarg; i++){
        if( i<32 && sqlite3ExprIsConstant(pFarg->a[i].pExpr) ){
          constMask |= (1<<i);
        }
        if( (pDef->funcFlags & SQLITE_FUNC_NEEDCOLL)!=0 && !pColl ){
          pColl = sqlite3ExprCollSeq(pParse, pFarg->a[i].pExpr);
        }
      }
      if( pFarg ){
        if( constMask ){
          r1 = pParse->nMem+1;
          pParse->nMem += nFarg;
        }else{
          r1 = sqlite3GetTempRange(pParse, nFarg);
        }

        /* For length() and typeof() functions with a column argument,
        ** set the P5 parameter to the OP_Column opcode to OPFLAG_LENGTHARG
        ** or OPFLAG_TYPEOFARG respectively, to avoid unnecessary data
        ** loading.
        */
        if( (pDef->funcFlags & (SQLITE_FUNC_LENGTH|SQLITE_FUNC_TYPEOF))!=0 ){
................................................................................
          u8 exprOp;
          assert( nFarg==1 );
          assert( pFarg->a[0].pExpr!=0 );
          exprOp = pFarg->a[0].pExpr->op;
          if( exprOp==TK_COLUMN || exprOp==TK_AGG_COLUMN ){
            assert( SQLITE_FUNC_LENGTH==OPFLAG_LENGTHARG );
            assert( SQLITE_FUNC_TYPEOF==OPFLAG_TYPEOFARG );
            testcase( pDef->funcFlags & OPFLAG_LENGTHARG );
            pFarg->a[0].pExpr->op2 = 
                  pDef->funcFlags & (OPFLAG_LENGTHARG|OPFLAG_TYPEOFARG);
          }
        }

        sqlite3ExprCachePush(pParse);     /* Ticket 2ea2425d34be */
        sqlite3ExprCodeExprList(pParse, pFarg, r1, 
                                SQLITE_ECEL_DUP|SQLITE_ECEL_FACTOR);
        sqlite3ExprCachePop(pParse, 1);   /* Ticket 2ea2425d34be */
      }else{
        r1 = 0;
      }
#ifndef SQLITE_OMIT_VIRTUALTABLE
      /* Possibly overload the function if the first argument is
      ** a virtual table column.
................................................................................
      */
      if( nFarg>=2 && (pExpr->flags & EP_InfixFunc) ){
        pDef = sqlite3VtabOverloadFunction(db, pDef, nFarg, pFarg->a[1].pExpr);
      }else if( nFarg>0 ){
        pDef = sqlite3VtabOverloadFunction(db, pDef, nFarg, pFarg->a[0].pExpr);
      }
#endif








      if( pDef->funcFlags & SQLITE_FUNC_NEEDCOLL ){
        if( !pColl ) pColl = db->pDfltColl; 
        sqlite3VdbeAddOp4(v, OP_CollSeq, 0, 0, 0, (char *)pColl, P4_COLLSEQ);
      }
      sqlite3VdbeAddOp4(v, OP_Function, constMask, r1, target,
                        (char*)pDef, P4_FUNCDEF);
      sqlite3VdbeChangeP5(v, (u8)nFarg);
      if( nFarg && constMask==0 ){
        sqlite3ReleaseTempRange(pParse, r1, nFarg);
      }
      break;
    }
#ifndef SQLITE_OMIT_SUBQUERY
    case TK_EXISTS:
    case TK_SELECT: {
................................................................................
    }
#endif
  }
  sqlite3ReleaseTempReg(pParse, regFree1);
  sqlite3ReleaseTempReg(pParse, regFree2);
  return inReg;
}

/*
** Factor out the code of the given expression to initialization time.
*/
SQLITE_PRIVATE void sqlite3ExprCodeAtInit(
  Parse *pParse,    /* Parsing context */
  Expr *pExpr,      /* The expression to code when the VDBE initializes */
  int regDest,      /* Store the value in this register */
  u8 reusable       /* True if this expression is reusable */
){
  ExprList *p;
  assert( ConstFactorOk(pParse) );
  p = pParse->pConstExpr;
  pExpr = sqlite3ExprDup(pParse->db, pExpr, 0);
  p = sqlite3ExprListAppend(pParse, p, pExpr);
  if( p ){
     struct ExprList_item *pItem = &p->a[p->nExpr-1];
     pItem->u.iConstExprReg = regDest;
     pItem->reusable = reusable;
  }
  pParse->pConstExpr = p;
}

/*
** Generate code to evaluate an expression and store the results
** into a register.  Return the register number where the results
** are stored.
**
** If the register is a temporary register that can be deallocated,
................................................................................
** If pExpr is a constant, then this routine might generate this
** code to fill the register in the initialization section of the
** VDBE program, in order to factor it out of the evaluation loop.
*/
SQLITE_PRIVATE int sqlite3ExprCodeTemp(Parse *pParse, Expr *pExpr, int *pReg){
  int r2;
  pExpr = sqlite3ExprSkipCollate(pExpr);
  if( ConstFactorOk(pParse)
   && pExpr->op!=TK_REGISTER
   && sqlite3ExprIsConstantNotJoin(pExpr)
  ){
    ExprList *p = pParse->pConstExpr;
    int i;
    *pReg  = 0;
    if( p ){
      struct ExprList_item *pItem;
      for(pItem=p->a, i=p->nExpr; i>0; pItem++, i--){
        if( pItem->reusable && sqlite3ExprCompare(pItem->pExpr,pExpr,-1)==0 ){
          return pItem->u.iConstExprReg;
        }
      }
    }


    r2 = ++pParse->nMem;

    sqlite3ExprCodeAtInit(pParse, pExpr, r2, 1);
  }else{
    int r1 = sqlite3GetTempReg(pParse);
    r2 = sqlite3ExprCodeTarget(pParse, pExpr, r1);
    if( r2==r1 ){
      *pReg = r1;
    }else{
      sqlite3ReleaseTempReg(pParse, r1);
................................................................................
    case TK_COLLATE: {
      sqlite3ExplainExpr(pOut, pExpr->pLeft);
      sqlite3ExplainPrintf(pOut,".COLLATE(%s)",pExpr->u.zToken);
      break;
    }

    case TK_AGG_FUNCTION:

    case TK_FUNCTION: {
      ExprList *pFarg;       /* List of function arguments */
      if( ExprHasProperty(pExpr, EP_TokenOnly) ){
        pFarg = 0;
      }else{
        pFarg = pExpr->x.pList;
      }
................................................................................
#endif /* SQLITE_DEBUG */

/*
** Generate code that pushes the value of every element of the given
** expression list into a sequence of registers beginning at target.
**
** Return the number of elements evaluated.
**
** The SQLITE_ECEL_DUP flag prevents the arguments from being
** filled using OP_SCopy.  OP_Copy must be used instead.
**
** The SQLITE_ECEL_FACTOR argument allows constant arguments to be
** factored out into initialization code.
*/
SQLITE_PRIVATE int sqlite3ExprCodeExprList(
  Parse *pParse,     /* Parsing context */
  ExprList *pList,   /* The expression list to be coded */
  int target,        /* Where to write results */
  u8 flags           /* SQLITE_ECEL_* flags */
){
  struct ExprList_item *pItem;
  int i, n;
  u8 copyOp = (flags & SQLITE_ECEL_DUP) ? OP_Copy : OP_SCopy;
  assert( pList!=0 );
  assert( target>0 );
  assert( pParse->pVdbe!=0 );  /* Never gets this far otherwise */
  n = pList->nExpr;
  if( !ConstFactorOk(pParse) ) flags &= ~SQLITE_ECEL_FACTOR;
  for(pItem=pList->a, i=0; i<n; i++, pItem++){
    Expr *pExpr = pItem->pExpr;
    if( (flags & SQLITE_ECEL_FACTOR)!=0 && sqlite3ExprIsConstant(pExpr) ){
      sqlite3ExprCodeAtInit(pParse, pExpr, target+i, 0);
    }else{
      int inReg = sqlite3ExprCodeTarget(pParse, pExpr, target+i);
      if( inReg!=target+i ){
        sqlite3VdbeAddOp2(pParse->pVdbe, copyOp, inReg, target+i);

      }
    }
  }
  return n;
}

/*
** Generate code for a BETWEEN operator.
................................................................................
    FUNCTION(coalesce,           1, 0, 0, 0                ),
    FUNCTION(coalesce,           0, 0, 0, 0                ),
    FUNCTION2(coalesce,         -1, 0, 0, noopFunc,  SQLITE_FUNC_COALESCE),
    FUNCTION(hex,                1, 0, 0, hexFunc          ),
    FUNCTION2(ifnull,            2, 0, 0, noopFunc,  SQLITE_FUNC_COALESCE),
    FUNCTION2(unlikely,          1, 0, 0, noopFunc,  SQLITE_FUNC_UNLIKELY),
    FUNCTION2(likelihood,        2, 0, 0, noopFunc,  SQLITE_FUNC_UNLIKELY),
    VFUNCTION(random,            0, 0, 0, randomFunc       ),
    VFUNCTION(randomblob,        1, 0, 0, randomBlob       ),
    FUNCTION(nullif,             2, 0, 1, nullifFunc       ),
    FUNCTION(sqlite_version,     0, 0, 0, versionFunc      ),
    FUNCTION(sqlite_source_id,   0, 0, 0, sourceidFunc     ),
    FUNCTION(sqlite_log,         2, 0, 0, errlogFunc       ),
#ifndef SQLITE_OMIT_COMPILEOPTION_DIAGS
    FUNCTION(sqlite_compileoption_used,1, 0, 0, compileoptionusedFunc  ),
    FUNCTION(sqlite_compileoption_get, 1, 0, 0, compileoptiongetFunc  ),
#endif /* SQLITE_OMIT_COMPILEOPTION_DIAGS */
    FUNCTION(quote,              1, 0, 0, quoteFunc        ),
    VFUNCTION(last_insert_rowid, 0, 0, 0, last_insert_rowid),
    VFUNCTION(changes,           0, 0, 0, changes          ),
    VFUNCTION(total_changes,     0, 0, 0, total_changes    ),
    FUNCTION(replace,            3, 0, 0, replaceFunc      ),
    FUNCTION(zeroblob,           1, 0, 0, zeroblobFunc     ),
  #ifdef SQLITE_SOUNDEX
    FUNCTION(soundex,            1, 0, 0, soundexFunc      ),
  #endif
  #ifndef SQLITE_OMIT_LOAD_EXTENSION
    FUNCTION(load_extension,     1, 0, 0, loadExt          ),
................................................................................
      sqlite3VdbeAddOp3(v, OP_Column, srcTab, i, regResult+i);
    }
  }else if( eDest!=SRT_Exists ){
    /* If the destination is an EXISTS(...) expression, the actual
    ** values returned by the SELECT are not required.
    */
    sqlite3ExprCacheClear(pParse);
    sqlite3ExprCodeExprList(pParse, pEList, regResult,
                            (eDest==SRT_Output)?SQLITE_ECEL_DUP:0);
  }
  nColumn = nResultCol;

  /* If the DISTINCT keyword was present on the SELECT statement
  ** and this row has been seen before, then do not make this row
  ** part of the result.
  */
................................................................................
    int addrNext = 0;
    int regAgg;
    ExprList *pList = pF->pExpr->x.pList;
    assert( !ExprHasProperty(pF->pExpr, EP_xIsSelect) );
    if( pList ){
      nArg = pList->nExpr;
      regAgg = sqlite3GetTempRange(pParse, nArg);
      sqlite3ExprCodeExprList(pParse, pList, regAgg, SQLITE_ECEL_DUP);
    }else{
      nArg = 0;
      regAgg = 0;
    }
    if( pF->iDistinct>=0 ){
      addrNext = sqlite3VdbeMakeLabel(v);
      assert( nArg==1 );
................................................................................
      pIn += pLevel->u.in.nIn - 1;
      pIn->iCur = iTab;
      if( eType==IN_INDEX_ROWID ){
        pIn->addrInTop = sqlite3VdbeAddOp2(v, OP_Rowid, iTab, iReg);
      }else{
        pIn->addrInTop = sqlite3VdbeAddOp3(v, OP_Column, iTab, 0, iReg);
      }
      pIn->eEndLoopOp = bRev ? OP_PrevIfOpen : OP_NextIfOpen;
      sqlite3VdbeAddOp1(v, OP_IsNull, iReg);
    }else{
      pLevel->u.in.nIn = 0;
    }
#endif
  }
  disableTerm(pLevel, pTerm);
................................................................................
{
  yygotominor.yy118.pExpr = sqlite3ExprFunction(pParse, 0, &yymsp[-3].minor.yy0);
  spanSet(&yygotominor.yy118,&yymsp[-3].minor.yy0,&yymsp[0].minor.yy0);
}
        break;
      case 200: /* term ::= CTIME_KW */
{


  yygotominor.yy118.pExpr = sqlite3ExprFunction(pParse, 0, &yymsp[0].minor.yy0);



  spanSet(&yygotominor.yy118, &yymsp[0].minor.yy0, &yymsp[0].minor.yy0);
}
        break;
      case 201: /* expr ::= expr AND expr */
      case 202: /* expr ::= expr OR expr */ yytestcase(yyruleno==202);
      case 203: /* expr ::= expr LT|GT|GE|LE expr */ yytestcase(yyruleno==203);
      case 204: /* expr ::= expr EQ|NE expr */ yytestcase(yyruleno==204);

Changes to src/sqlite3.h.

105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
**
** See also: [sqlite3_libversion()],
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
** [sqlite_version()] and [sqlite_source_id()].
*/
#define SQLITE_VERSION        "3.8.2"
#define SQLITE_VERSION_NUMBER 3008002
#define SQLITE_SOURCE_ID      "2013-11-19 13:55:34 17e8524fc05aa1e6074c19a8ccccc5ab5883103a"

/*
** 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







|







105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
**
** See also: [sqlite3_libversion()],
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
** [sqlite_version()] and [sqlite_source_id()].
*/
#define SQLITE_VERSION        "3.8.2"
#define SQLITE_VERSION_NUMBER 3008002
#define SQLITE_SOURCE_ID      "2013-11-21 23:37:02 3d47a556f0074e39b880186fb7661b1b8955f742"

/*
** 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