4
** The author disclaims copyright to this source code. In place of
5
** a legal notice, here is a blessing:
7
** May you do good and not evil.
8
** May you find forgiveness for yourself and forgive others.
9
** May you share freely, never taking more than you give.
11
*************************************************************************
12
** This file contains code used to implement the PRAGMA command.
14
** $Id: pragma.c 326789 2004-07-07 21:25:56Z pahlibar $
16
#include "sqliteInt.h"
20
** Interpret the given string as a boolean value.
22
static int getBoolean(const char *z){
23
static char *azTrue[] = { "yes", "on", "true" };
25
if( z[0]==0 ) return 0;
26
if( isdigit(z[0]) || (z[0]=='-' && isdigit(z[1])) ){
29
for(i=0; i<sizeof(azTrue)/sizeof(azTrue[0]); i++){
30
if( sqliteStrICmp(z,azTrue[i])==0 ) return 1;
36
** Interpret the given string as a safety level. Return 0 for OFF,
37
** 1 for ON or NORMAL and 2 for FULL. Return 1 for an empty or
38
** unrecognized string argument.
40
** Note that the values returned are one less that the values that
41
** should be passed into sqliteBtreeSetSafetyLevel(). The is done
42
** to support legacy SQL code. The safety level used to be boolean
43
** and older scripts may have used numbers 0 for OFF and 1 for ON.
45
static int getSafetyLevel(char *z){
59
if( z[0]==0 ) return 1;
60
if( isdigit(z[0]) || (z[0]=='-' && isdigit(z[1])) ){
63
for(i=0; i<sizeof(aKey)/sizeof(aKey[0]); i++){
64
if( sqliteStrICmp(z,aKey[i].zWord)==0 ) return aKey[i].val;
70
** Interpret the given string as a temp db location. Return 1 for file
71
** backed temporary databases, 2 for the Red-Black tree in memory database
72
** and 0 to use the compile-time default.
74
static int getTempStore(const char *z){
75
if( z[0]>='0' && z[0]<='2' ){
77
}else if( sqliteStrICmp(z, "file")==0 ){
79
}else if( sqliteStrICmp(z, "memory")==0 ){
87
** If the TEMP database is open, close it and mark the database schema
88
** as needing reloading. This must be done when using the TEMP_STORE
89
** or DEFAULT_TEMP_STORE pragmas.
91
static int changeTempStorage(Parse *pParse, const char *zStorageType){
92
int ts = getTempStore(zStorageType);
93
sqlite *db = pParse->db;
94
if( db->temp_store==ts ) return SQLITE_OK;
95
if( db->aDb[1].pBt!=0 ){
96
if( db->flags & SQLITE_InTrans ){
97
sqliteErrorMsg(pParse, "temporary storage cannot be changed "
98
"from within a transaction");
101
sqliteBtreeClose(db->aDb[1].pBt);
103
sqliteResetInternalSchema(db, 0);
110
** Check to see if zRight and zLeft refer to a pragma that queries
111
** or changes one of the flags in db->flags. Return 1 if so and 0 if not.
112
** Also, implement the pragma.
114
static int flagPragma(Parse *pParse, const char *zLeft, const char *zRight){
115
static const struct {
116
const char *zName; /* Name of the pragma */
117
int mask; /* Mask for the db->flags value */
119
{ "vdbe_trace", SQLITE_VdbeTrace },
120
{ "full_column_names", SQLITE_FullColNames },
121
{ "short_column_names", SQLITE_ShortColNames },
122
{ "show_datatypes", SQLITE_ReportTypes },
123
{ "count_changes", SQLITE_CountRows },
124
{ "empty_result_callbacks", SQLITE_NullCallback },
127
for(i=0; i<sizeof(aPragma)/sizeof(aPragma[0]); i++){
128
if( sqliteStrICmp(zLeft, aPragma[i].zName)==0 ){
129
sqlite *db = pParse->db;
131
if( strcmp(zLeft,zRight)==0 && (v = sqliteGetVdbe(pParse))!=0 ){
132
sqliteVdbeOp3(v, OP_ColumnName, 0, 1, aPragma[i].zName, P3_STATIC);
133
sqliteVdbeOp3(v, OP_ColumnName, 1, 0, "boolean", P3_STATIC);
134
sqliteVdbeCode(v, OP_Integer, (db->flags & aPragma[i].mask)!=0, 0,
137
}else if( getBoolean(zRight) ){
138
db->flags |= aPragma[i].mask;
140
db->flags &= ~aPragma[i].mask;
149
** Process a pragma statement.
151
** Pragmas are of this form:
155
** The identifier might also be a string. The value is a string, and
156
** identifier, or a number. If minusFlag is true, then the value is
157
** a number that was preceded by a minus sign.
159
void sqlitePragma(Parse *pParse, Token *pLeft, Token *pRight, int minusFlag){
162
sqlite *db = pParse->db;
163
Vdbe *v = sqliteGetVdbe(pParse);
166
zLeft = sqliteStrNDup(pLeft->z, pLeft->n);
167
sqliteDequote(zLeft);
170
sqliteSetNString(&zRight, "-", 1, pRight->z, pRight->n, 0);
172
zRight = sqliteStrNDup(pRight->z, pRight->n);
173
sqliteDequote(zRight);
175
if( sqliteAuthCheck(pParse, SQLITE_PRAGMA, zLeft, zRight, 0) ){
182
** PRAGMA default_cache_size
183
** PRAGMA default_cache_size=N
185
** The first form reports the current persistent setting for the
186
** page cache size. The value returned is the maximum number of
187
** pages in the page cache. The second form sets both the current
188
** page cache size value and the persistent page cache size value
189
** stored in the database file.
191
** The default cache size is stored in meta-value 2 of page 1 of the
192
** database file. The cache size is actually the absolute value of
193
** this memory location. The sign of meta-value 2 determines the
194
** synchronous setting. A negative value means synchronous is off
195
** and a positive value means synchronous is on.
197
if( sqliteStrICmp(zLeft,"default_cache_size")==0 ){
198
static VdbeOpList getCacheSize[] = {
199
{ OP_ReadCookie, 0, 2, 0},
200
{ OP_AbsValue, 0, 0, 0},
202
{ OP_Integer, 0, 0, 0},
204
{ OP_Integer, 0, 0, 0}, /* 5 */
205
{ OP_ColumnName, 0, 1, "cache_size"},
206
{ OP_Callback, 1, 0, 0},
209
if( pRight->z==pLeft->z ){
210
addr = sqliteVdbeAddOpList(v, ArraySize(getCacheSize), getCacheSize);
211
sqliteVdbeChangeP1(v, addr+5, MAX_PAGES);
213
int size = atoi(zRight);
214
if( size<0 ) size = -size;
215
sqliteBeginWriteOperation(pParse, 0, 0);
216
sqliteVdbeAddOp(v, OP_Integer, size, 0);
217
sqliteVdbeAddOp(v, OP_ReadCookie, 0, 2);
218
addr = sqliteVdbeAddOp(v, OP_Integer, 0, 0);
219
sqliteVdbeAddOp(v, OP_Ge, 0, addr+3);
220
sqliteVdbeAddOp(v, OP_Negative, 0, 0);
221
sqliteVdbeAddOp(v, OP_SetCookie, 0, 2);
222
sqliteEndWriteOperation(pParse);
223
db->cache_size = db->cache_size<0 ? -size : size;
224
sqliteBtreeSetCacheSize(db->aDb[0].pBt, db->cache_size);
230
** PRAGMA cache_size=N
232
** The first form reports the current local setting for the
233
** page cache size. The local setting can be different from
234
** the persistent cache size value that is stored in the database
235
** file itself. The value returned is the maximum number of
236
** pages in the page cache. The second form sets the local
237
** page cache size value. It does not change the persistent
238
** cache size stored on the disk so the cache size will revert
239
** to its default value when the database is closed and reopened.
240
** N should be a positive integer.
242
if( sqliteStrICmp(zLeft,"cache_size")==0 ){
243
static VdbeOpList getCacheSize[] = {
244
{ OP_ColumnName, 0, 1, "cache_size"},
245
{ OP_Callback, 1, 0, 0},
247
if( pRight->z==pLeft->z ){
248
int size = db->cache_size;;
249
if( size<0 ) size = -size;
250
sqliteVdbeAddOp(v, OP_Integer, size, 0);
251
sqliteVdbeAddOpList(v, ArraySize(getCacheSize), getCacheSize);
253
int size = atoi(zRight);
254
if( size<0 ) size = -size;
255
if( db->cache_size<0 ) size = -size;
256
db->cache_size = size;
257
sqliteBtreeSetCacheSize(db->aDb[0].pBt, db->cache_size);
262
** PRAGMA default_synchronous
263
** PRAGMA default_synchronous=ON|OFF|NORMAL|FULL
265
** The first form returns the persistent value of the "synchronous" setting
266
** that is stored in the database. This is the synchronous setting that
267
** is used whenever the database is opened unless overridden by a separate
268
** "synchronous" pragma. The second form changes the persistent and the
269
** local synchronous setting to the value given.
271
** If synchronous is OFF, SQLite does not attempt any fsync() systems calls
272
** to make sure data is committed to disk. Write operations are very fast,
273
** but a power failure can leave the database in an inconsistent state.
274
** If synchronous is ON or NORMAL, SQLite will do an fsync() system call to
275
** make sure data is being written to disk. The risk of corruption due to
276
** a power loss in this mode is negligible but non-zero. If synchronous
277
** is FULL, extra fsync()s occur to reduce the risk of corruption to near
278
** zero, but with a write performance penalty. The default mode is NORMAL.
280
if( sqliteStrICmp(zLeft,"default_synchronous")==0 ){
281
static VdbeOpList getSync[] = {
282
{ OP_ColumnName, 0, 1, "synchronous"},
283
{ OP_ReadCookie, 0, 3, 0},
285
{ OP_If, 0, 0, 0}, /* 3 */
286
{ OP_ReadCookie, 0, 2, 0},
287
{ OP_Integer, 0, 0, 0},
289
{ OP_AddImm, 1, 0, 0},
290
{ OP_Callback, 1, 0, 0},
292
{ OP_AddImm, -1, 0, 0}, /* 10 */
293
{ OP_Callback, 1, 0, 0}
295
if( pRight->z==pLeft->z ){
296
int addr = sqliteVdbeAddOpList(v, ArraySize(getSync), getSync);
297
sqliteVdbeChangeP2(v, addr+3, addr+10);
300
int size = db->cache_size;
301
if( size<0 ) size = -size;
302
sqliteBeginWriteOperation(pParse, 0, 0);
303
sqliteVdbeAddOp(v, OP_ReadCookie, 0, 2);
304
sqliteVdbeAddOp(v, OP_Dup, 0, 0);
305
addr = sqliteVdbeAddOp(v, OP_Integer, 0, 0);
306
sqliteVdbeAddOp(v, OP_Ne, 0, addr+3);
307
sqliteVdbeAddOp(v, OP_AddImm, MAX_PAGES, 0);
308
sqliteVdbeAddOp(v, OP_AbsValue, 0, 0);
309
db->safety_level = getSafetyLevel(zRight)+1;
310
if( db->safety_level==1 ){
311
sqliteVdbeAddOp(v, OP_Negative, 0, 0);
314
sqliteVdbeAddOp(v, OP_SetCookie, 0, 2);
315
sqliteVdbeAddOp(v, OP_Integer, db->safety_level, 0);
316
sqliteVdbeAddOp(v, OP_SetCookie, 0, 3);
317
sqliteEndWriteOperation(pParse);
318
db->cache_size = size;
319
sqliteBtreeSetCacheSize(db->aDb[0].pBt, db->cache_size);
320
sqliteBtreeSetSafetyLevel(db->aDb[0].pBt, db->safety_level);
325
** PRAGMA synchronous
326
** PRAGMA synchronous=OFF|ON|NORMAL|FULL
328
** Return or set the local value of the synchronous flag. Changing
329
** the local value does not make changes to the disk file and the
330
** default value will be restored the next time the database is
333
if( sqliteStrICmp(zLeft,"synchronous")==0 ){
334
static VdbeOpList getSync[] = {
335
{ OP_ColumnName, 0, 1, "synchronous"},
336
{ OP_Callback, 1, 0, 0},
338
if( pRight->z==pLeft->z ){
339
sqliteVdbeAddOp(v, OP_Integer, db->safety_level-1, 0);
340
sqliteVdbeAddOpList(v, ArraySize(getSync), getSync);
342
int size = db->cache_size;
343
if( size<0 ) size = -size;
344
db->safety_level = getSafetyLevel(zRight)+1;
345
if( db->safety_level==1 ) size = -size;
346
db->cache_size = size;
347
sqliteBtreeSetCacheSize(db->aDb[0].pBt, db->cache_size);
348
sqliteBtreeSetSafetyLevel(db->aDb[0].pBt, db->safety_level);
353
if( sqliteStrICmp(zLeft, "trigger_overhead_test")==0 ){
354
if( getBoolean(zRight) ){
355
always_code_trigger_setup = 1;
357
always_code_trigger_setup = 0;
362
if( flagPragma(pParse, zLeft, zRight) ){
363
/* The flagPragma() call also generates any necessary code */
366
if( sqliteStrICmp(zLeft, "table_info")==0 ){
368
pTab = sqliteFindTable(db, zRight, 0);
370
static VdbeOpList tableInfoPreface[] = {
371
{ OP_ColumnName, 0, 0, "cid"},
372
{ OP_ColumnName, 1, 0, "name"},
373
{ OP_ColumnName, 2, 0, "type"},
374
{ OP_ColumnName, 3, 0, "notnull"},
375
{ OP_ColumnName, 4, 0, "dflt_value"},
376
{ OP_ColumnName, 5, 1, "pk"},
379
sqliteVdbeAddOpList(v, ArraySize(tableInfoPreface), tableInfoPreface);
380
sqliteViewGetColumnNames(pParse, pTab);
381
for(i=0; i<pTab->nCol; i++){
382
sqliteVdbeAddOp(v, OP_Integer, i, 0);
383
sqliteVdbeOp3(v, OP_String, 0, 0, pTab->aCol[i].zName, 0);
384
sqliteVdbeOp3(v, OP_String, 0, 0,
385
pTab->aCol[i].zType ? pTab->aCol[i].zType : "numeric", 0);
386
sqliteVdbeAddOp(v, OP_Integer, pTab->aCol[i].notNull, 0);
387
sqliteVdbeOp3(v, OP_String, 0, 0,
388
pTab->aCol[i].zDflt, P3_STATIC);
389
sqliteVdbeAddOp(v, OP_Integer, pTab->aCol[i].isPrimKey, 0);
390
sqliteVdbeAddOp(v, OP_Callback, 6, 0);
395
if( sqliteStrICmp(zLeft, "index_info")==0 ){
398
pIdx = sqliteFindIndex(db, zRight, 0);
400
static VdbeOpList tableInfoPreface[] = {
401
{ OP_ColumnName, 0, 0, "seqno"},
402
{ OP_ColumnName, 1, 0, "cid"},
403
{ OP_ColumnName, 2, 1, "name"},
407
sqliteVdbeAddOpList(v, ArraySize(tableInfoPreface), tableInfoPreface);
408
for(i=0; i<pIdx->nColumn; i++){
409
int cnum = pIdx->aiColumn[i];
410
sqliteVdbeAddOp(v, OP_Integer, i, 0);
411
sqliteVdbeAddOp(v, OP_Integer, cnum, 0);
412
assert( pTab->nCol>cnum );
413
sqliteVdbeOp3(v, OP_String, 0, 0, pTab->aCol[cnum].zName, 0);
414
sqliteVdbeAddOp(v, OP_Callback, 3, 0);
419
if( sqliteStrICmp(zLeft, "index_list")==0 ){
422
pTab = sqliteFindTable(db, zRight, 0);
424
v = sqliteGetVdbe(pParse);
429
static VdbeOpList indexListPreface[] = {
430
{ OP_ColumnName, 0, 0, "seq"},
431
{ OP_ColumnName, 1, 0, "name"},
432
{ OP_ColumnName, 2, 1, "unique"},
435
sqliteVdbeAddOpList(v, ArraySize(indexListPreface), indexListPreface);
437
sqliteVdbeAddOp(v, OP_Integer, i, 0);
438
sqliteVdbeOp3(v, OP_String, 0, 0, pIdx->zName, 0);
439
sqliteVdbeAddOp(v, OP_Integer, pIdx->onError!=OE_None, 0);
440
sqliteVdbeAddOp(v, OP_Callback, 3, 0);
447
if( sqliteStrICmp(zLeft, "foreign_key_list")==0 ){
450
pTab = sqliteFindTable(db, zRight, 0);
452
v = sqliteGetVdbe(pParse);
457
static VdbeOpList indexListPreface[] = {
458
{ OP_ColumnName, 0, 0, "id"},
459
{ OP_ColumnName, 1, 0, "seq"},
460
{ OP_ColumnName, 2, 0, "table"},
461
{ OP_ColumnName, 3, 0, "from"},
462
{ OP_ColumnName, 4, 1, "to"},
465
sqliteVdbeAddOpList(v, ArraySize(indexListPreface), indexListPreface);
468
for(j=0; j<pFK->nCol; j++){
469
sqliteVdbeAddOp(v, OP_Integer, i, 0);
470
sqliteVdbeAddOp(v, OP_Integer, j, 0);
471
sqliteVdbeOp3(v, OP_String, 0, 0, pFK->zTo, 0);
472
sqliteVdbeOp3(v, OP_String, 0, 0,
473
pTab->aCol[pFK->aCol[j].iFrom].zName, 0);
474
sqliteVdbeOp3(v, OP_String, 0, 0, pFK->aCol[j].zCol, 0);
475
sqliteVdbeAddOp(v, OP_Callback, 5, 0);
478
pFK = pFK->pNextFrom;
483
if( sqliteStrICmp(zLeft, "database_list")==0 ){
485
static VdbeOpList indexListPreface[] = {
486
{ OP_ColumnName, 0, 0, "seq"},
487
{ OP_ColumnName, 1, 0, "name"},
488
{ OP_ColumnName, 2, 1, "file"},
491
sqliteVdbeAddOpList(v, ArraySize(indexListPreface), indexListPreface);
492
for(i=0; i<db->nDb; i++){
493
if( db->aDb[i].pBt==0 ) continue;
494
assert( db->aDb[i].zName!=0 );
495
sqliteVdbeAddOp(v, OP_Integer, i, 0);
496
sqliteVdbeOp3(v, OP_String, 0, 0, db->aDb[i].zName, 0);
497
sqliteVdbeOp3(v, OP_String, 0, 0,
498
sqliteBtreeGetFilename(db->aDb[i].pBt), 0);
499
sqliteVdbeAddOp(v, OP_Callback, 3, 0);
506
** PRAGMA temp_store = "default"|"memory"|"file"
508
** Return or set the local value of the temp_store flag. Changing
509
** the local value does not make changes to the disk file and the default
510
** value will be restored the next time the database is opened.
512
** Note that it is possible for the library compile-time options to
513
** override this setting
515
if( sqliteStrICmp(zLeft, "temp_store")==0 ){
516
static VdbeOpList getTmpDbLoc[] = {
517
{ OP_ColumnName, 0, 1, "temp_store"},
518
{ OP_Callback, 1, 0, 0},
520
if( pRight->z==pLeft->z ){
521
sqliteVdbeAddOp(v, OP_Integer, db->temp_store, 0);
522
sqliteVdbeAddOpList(v, ArraySize(getTmpDbLoc), getTmpDbLoc);
524
changeTempStorage(pParse, zRight);
529
** PRAGMA default_temp_store
530
** PRAGMA default_temp_store = "default"|"memory"|"file"
532
** Return or set the value of the persistent temp_store flag. Any
533
** change does not take effect until the next time the database is
536
** Note that it is possible for the library compile-time options to
537
** override this setting
539
if( sqliteStrICmp(zLeft, "default_temp_store")==0 ){
540
static VdbeOpList getTmpDbLoc[] = {
541
{ OP_ColumnName, 0, 1, "temp_store"},
542
{ OP_ReadCookie, 0, 5, 0},
543
{ OP_Callback, 1, 0, 0}};
544
if( pRight->z==pLeft->z ){
545
sqliteVdbeAddOpList(v, ArraySize(getTmpDbLoc), getTmpDbLoc);
547
sqliteBeginWriteOperation(pParse, 0, 0);
548
sqliteVdbeAddOp(v, OP_Integer, getTempStore(zRight), 0);
549
sqliteVdbeAddOp(v, OP_SetCookie, 0, 5);
550
sqliteEndWriteOperation(pParse);
555
if( sqliteStrICmp(zLeft, "parser_trace")==0 ){
556
extern void sqliteParserTrace(FILE*, char *);
557
if( getBoolean(zRight) ){
558
sqliteParserTrace(stdout, "parser: ");
560
sqliteParserTrace(0, 0);
565
if( sqliteStrICmp(zLeft, "integrity_check")==0 ){
568
/* Code that initializes the integrity check program. Set the
571
static VdbeOpList initCode[] = {
572
{ OP_Integer, 0, 0, 0},
573
{ OP_MemStore, 0, 1, 0},
574
{ OP_ColumnName, 0, 1, "integrity_check"},
577
/* Code to do an BTree integrity check on a single database file.
579
static VdbeOpList checkDb[] = {
580
{ OP_SetInsert, 0, 0, "2"},
581
{ OP_Integer, 0, 0, 0}, /* 1 */
582
{ OP_OpenRead, 0, 2, 0},
583
{ OP_Rewind, 0, 7, 0}, /* 3 */
584
{ OP_Column, 0, 3, 0}, /* 4 */
585
{ OP_SetInsert, 0, 0, 0},
586
{ OP_Next, 0, 4, 0}, /* 6 */
587
{ OP_IntegrityCk, 0, 0, 0}, /* 7 */
589
{ OP_String, 0, 0, "ok"},
590
{ OP_StrEq, 0, 12, 0}, /* 10 */
591
{ OP_MemIncr, 0, 0, 0},
592
{ OP_String, 0, 0, "*** in database "},
593
{ OP_String, 0, 0, 0}, /* 13 */
594
{ OP_String, 0, 0, " ***\n"},
596
{ OP_Concat, 4, 1, 0},
597
{ OP_Callback, 1, 0, 0},
600
/* Code that appears at the end of the integrity check. If no error
601
** messages have been generated, output OK. Otherwise output the
604
static VdbeOpList endCode[] = {
605
{ OP_MemLoad, 0, 0, 0},
606
{ OP_Integer, 0, 0, 0},
607
{ OP_Ne, 0, 0, 0}, /* 2 */
608
{ OP_String, 0, 0, "ok"},
609
{ OP_Callback, 1, 0, 0},
612
/* Initialize the VDBE program */
613
sqliteVdbeAddOpList(v, ArraySize(initCode), initCode);
615
/* Do an integrity check on each database file */
616
for(i=0; i<db->nDb; i++){
619
/* Do an integrity check of the B-Tree
621
addr = sqliteVdbeAddOpList(v, ArraySize(checkDb), checkDb);
622
sqliteVdbeChangeP1(v, addr+1, i);
623
sqliteVdbeChangeP2(v, addr+3, addr+7);
624
sqliteVdbeChangeP2(v, addr+6, addr+4);
625
sqliteVdbeChangeP2(v, addr+7, i);
626
sqliteVdbeChangeP2(v, addr+10, addr+ArraySize(checkDb));
627
sqliteVdbeChangeP3(v, addr+13, db->aDb[i].zName, P3_STATIC);
629
/* Make sure all the indices are constructed correctly.
631
sqliteCodeVerifySchema(pParse, i);
632
for(x=sqliteHashFirst(&db->aDb[i].tblHash); x; x=sqliteHashNext(x)){
633
Table *pTab = sqliteHashData(x);
637
if( pTab->pIndex==0 ) continue;
638
sqliteVdbeAddOp(v, OP_Integer, i, 0);
639
sqliteVdbeOp3(v, OP_OpenRead, 1, pTab->tnum, pTab->zName, 0);
640
for(j=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, j++){
641
if( pIdx->tnum==0 ) continue;
642
sqliteVdbeAddOp(v, OP_Integer, pIdx->iDb, 0);
643
sqliteVdbeOp3(v, OP_OpenRead, j+2, pIdx->tnum, pIdx->zName, 0);
645
sqliteVdbeAddOp(v, OP_Integer, 0, 0);
646
sqliteVdbeAddOp(v, OP_MemStore, 1, 1);
647
loopTop = sqliteVdbeAddOp(v, OP_Rewind, 1, 0);
648
sqliteVdbeAddOp(v, OP_MemIncr, 1, 0);
649
for(j=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, j++){
651
static VdbeOpList idxErr[] = {
652
{ OP_MemIncr, 0, 0, 0},
653
{ OP_String, 0, 0, "rowid "},
654
{ OP_Recno, 1, 0, 0},
655
{ OP_String, 0, 0, " missing from index "},
656
{ OP_String, 0, 0, 0}, /* 4 */
657
{ OP_Concat, 4, 0, 0},
658
{ OP_Callback, 1, 0, 0},
660
sqliteVdbeAddOp(v, OP_Recno, 1, 0);
661
for(k=0; k<pIdx->nColumn; k++){
662
int idx = pIdx->aiColumn[k];
663
if( idx==pTab->iPKey ){
664
sqliteVdbeAddOp(v, OP_Recno, 1, 0);
666
sqliteVdbeAddOp(v, OP_Column, 1, idx);
669
sqliteVdbeAddOp(v, OP_MakeIdxKey, pIdx->nColumn, 0);
670
if( db->file_format>=4 ) sqliteAddIdxKeyType(v, pIdx);
671
jmp2 = sqliteVdbeAddOp(v, OP_Found, j+2, 0);
672
addr = sqliteVdbeAddOpList(v, ArraySize(idxErr), idxErr);
673
sqliteVdbeChangeP3(v, addr+4, pIdx->zName, P3_STATIC);
674
sqliteVdbeChangeP2(v, jmp2, sqliteVdbeCurrentAddr(v));
676
sqliteVdbeAddOp(v, OP_Next, 1, loopTop+1);
677
sqliteVdbeChangeP2(v, loopTop, sqliteVdbeCurrentAddr(v));
678
for(j=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, j++){
679
static VdbeOpList cntIdx[] = {
680
{ OP_Integer, 0, 0, 0},
681
{ OP_MemStore, 2, 1, 0},
682
{ OP_Rewind, 0, 0, 0}, /* 2 */
683
{ OP_MemIncr, 2, 0, 0},
684
{ OP_Next, 0, 0, 0}, /* 4 */
685
{ OP_MemLoad, 1, 0, 0},
686
{ OP_MemLoad, 2, 0, 0},
687
{ OP_Eq, 0, 0, 0}, /* 7 */
688
{ OP_MemIncr, 0, 0, 0},
689
{ OP_String, 0, 0, "wrong # of entries in index "},
690
{ OP_String, 0, 0, 0}, /* 10 */
691
{ OP_Concat, 2, 0, 0},
692
{ OP_Callback, 1, 0, 0},
694
if( pIdx->tnum==0 ) continue;
695
addr = sqliteVdbeAddOpList(v, ArraySize(cntIdx), cntIdx);
696
sqliteVdbeChangeP1(v, addr+2, j+2);
697
sqliteVdbeChangeP2(v, addr+2, addr+5);
698
sqliteVdbeChangeP1(v, addr+4, j+2);
699
sqliteVdbeChangeP2(v, addr+4, addr+3);
700
sqliteVdbeChangeP2(v, addr+7, addr+ArraySize(cntIdx));
701
sqliteVdbeChangeP3(v, addr+10, pIdx->zName, P3_STATIC);
705
addr = sqliteVdbeAddOpList(v, ArraySize(endCode), endCode);
706
sqliteVdbeChangeP2(v, addr+2, addr+ArraySize(endCode));