extensions/sqlite/sqlite-source/pragma.c
branchsourcemod-1.1.0
changeset 2283 03a67e41afbc
parent 1951 c7b4237fff50
child 2287 017a725c9d17
     1.1 --- a/extensions/sqlite/sqlite-source/pragma.c	Fri Mar 28 06:21:34 2008 +0000
     1.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.3 @@ -1,1186 +0,0 @@
     1.4 -/*
     1.5 -** 2003 April 6
     1.6 -**
     1.7 -** The author disclaims copyright to this source code.  In place of
     1.8 -** a legal notice, here is a blessing:
     1.9 -**
    1.10 -**    May you do good and not evil.
    1.11 -**    May you find forgiveness for yourself and forgive others.
    1.12 -**    May you share freely, never taking more than you give.
    1.13 -**
    1.14 -*************************************************************************
    1.15 -** This file contains code used to implement the PRAGMA command.
    1.16 -**
    1.17 -** $Id$
    1.18 -*/
    1.19 -#include "sqliteInt.h"
    1.20 -#include <ctype.h>
    1.21 -
    1.22 -/* Ignore this whole file if pragmas are disabled
    1.23 -*/
    1.24 -#if !defined(SQLITE_OMIT_PRAGMA) && !defined(SQLITE_OMIT_PARSER)
    1.25 -
    1.26 -/*
    1.27 -** Interpret the given string as a safety level.  Return 0 for OFF,
    1.28 -** 1 for ON or NORMAL and 2 for FULL.  Return 1 for an empty or 
    1.29 -** unrecognized string argument.
    1.30 -**
    1.31 -** Note that the values returned are one less that the values that
    1.32 -** should be passed into sqlite3BtreeSetSafetyLevel().  The is done
    1.33 -** to support legacy SQL code.  The safety level used to be boolean
    1.34 -** and older scripts may have used numbers 0 for OFF and 1 for ON.
    1.35 -*/
    1.36 -static int getSafetyLevel(const char *z){
    1.37 -                             /* 123456789 123456789 */
    1.38 -  static const char zText[] = "onoffalseyestruefull";
    1.39 -  static const u8 iOffset[] = {0, 1, 2, 4, 9, 12, 16};
    1.40 -  static const u8 iLength[] = {2, 2, 3, 5, 3, 4, 4};
    1.41 -  static const u8 iValue[] =  {1, 0, 0, 0, 1, 1, 2};
    1.42 -  int i, n;
    1.43 -  if( isdigit(*z) ){
    1.44 -    return atoi(z);
    1.45 -  }
    1.46 -  n = strlen(z);
    1.47 -  for(i=0; i<sizeof(iLength); i++){
    1.48 -    if( iLength[i]==n && sqlite3StrNICmp(&zText[iOffset[i]],z,n)==0 ){
    1.49 -      return iValue[i];
    1.50 -    }
    1.51 -  }
    1.52 -  return 1;
    1.53 -}
    1.54 -
    1.55 -/*
    1.56 -** Interpret the given string as a boolean value.
    1.57 -*/
    1.58 -static int getBoolean(const char *z){
    1.59 -  return getSafetyLevel(z)&1;
    1.60 -}
    1.61 -
    1.62 -/*
    1.63 -** Interpret the given string as a locking mode value.
    1.64 -*/
    1.65 -static int getLockingMode(const char *z){
    1.66 -  if( z ){
    1.67 -    if( 0==sqlite3StrICmp(z, "exclusive") ) return PAGER_LOCKINGMODE_EXCLUSIVE;
    1.68 -    if( 0==sqlite3StrICmp(z, "normal") ) return PAGER_LOCKINGMODE_NORMAL;
    1.69 -  }
    1.70 -  return PAGER_LOCKINGMODE_QUERY;
    1.71 -}
    1.72 -
    1.73 -#ifndef SQLITE_OMIT_AUTOVACUUM
    1.74 -/*
    1.75 -** Interpret the given string as an auto-vacuum mode value.
    1.76 -**
    1.77 -** The following strings, "none", "full" and "incremental" are 
    1.78 -** acceptable, as are their numeric equivalents: 0, 1 and 2 respectively.
    1.79 -*/
    1.80 -static int getAutoVacuum(const char *z){
    1.81 -  int i;
    1.82 -  if( 0==sqlite3StrICmp(z, "none") ) return BTREE_AUTOVACUUM_NONE;
    1.83 -  if( 0==sqlite3StrICmp(z, "full") ) return BTREE_AUTOVACUUM_FULL;
    1.84 -  if( 0==sqlite3StrICmp(z, "incremental") ) return BTREE_AUTOVACUUM_INCR;
    1.85 -  i = atoi(z);
    1.86 -  return ((i>=0&&i<=2)?i:0);
    1.87 -}
    1.88 -#endif /* ifndef SQLITE_OMIT_AUTOVACUUM */
    1.89 -
    1.90 -#ifndef SQLITE_OMIT_PAGER_PRAGMAS
    1.91 -/*
    1.92 -** Interpret the given string as a temp db location. Return 1 for file
    1.93 -** backed temporary databases, 2 for the Red-Black tree in memory database
    1.94 -** and 0 to use the compile-time default.
    1.95 -*/
    1.96 -static int getTempStore(const char *z){
    1.97 -  if( z[0]>='0' && z[0]<='2' ){
    1.98 -    return z[0] - '0';
    1.99 -  }else if( sqlite3StrICmp(z, "file")==0 ){
   1.100 -    return 1;
   1.101 -  }else if( sqlite3StrICmp(z, "memory")==0 ){
   1.102 -    return 2;
   1.103 -  }else{
   1.104 -    return 0;
   1.105 -  }
   1.106 -}
   1.107 -#endif /* SQLITE_PAGER_PRAGMAS */
   1.108 -
   1.109 -#ifndef SQLITE_OMIT_PAGER_PRAGMAS
   1.110 -/*
   1.111 -** Invalidate temp storage, either when the temp storage is changed
   1.112 -** from default, or when 'file' and the temp_store_directory has changed
   1.113 -*/
   1.114 -static int invalidateTempStorage(Parse *pParse){
   1.115 -  sqlite3 *db = pParse->db;
   1.116 -  if( db->aDb[1].pBt!=0 ){
   1.117 -    if( !db->autoCommit ){
   1.118 -      sqlite3ErrorMsg(pParse, "temporary storage cannot be changed "
   1.119 -        "from within a transaction");
   1.120 -      return SQLITE_ERROR;
   1.121 -    }
   1.122 -    sqlite3BtreeClose(db->aDb[1].pBt);
   1.123 -    db->aDb[1].pBt = 0;
   1.124 -    sqlite3ResetInternalSchema(db, 0);
   1.125 -  }
   1.126 -  return SQLITE_OK;
   1.127 -}
   1.128 -#endif /* SQLITE_PAGER_PRAGMAS */
   1.129 -
   1.130 -#ifndef SQLITE_OMIT_PAGER_PRAGMAS
   1.131 -/*
   1.132 -** If the TEMP database is open, close it and mark the database schema
   1.133 -** as needing reloading.  This must be done when using the TEMP_STORE
   1.134 -** or DEFAULT_TEMP_STORE pragmas.
   1.135 -*/
   1.136 -static int changeTempStorage(Parse *pParse, const char *zStorageType){
   1.137 -  int ts = getTempStore(zStorageType);
   1.138 -  sqlite3 *db = pParse->db;
   1.139 -  if( db->temp_store==ts ) return SQLITE_OK;
   1.140 -  if( invalidateTempStorage( pParse ) != SQLITE_OK ){
   1.141 -    return SQLITE_ERROR;
   1.142 -  }
   1.143 -  db->temp_store = ts;
   1.144 -  return SQLITE_OK;
   1.145 -}
   1.146 -#endif /* SQLITE_PAGER_PRAGMAS */
   1.147 -
   1.148 -/*
   1.149 -** Generate code to return a single integer value.
   1.150 -*/
   1.151 -static void returnSingleInt(Parse *pParse, const char *zLabel, int value){
   1.152 -  Vdbe *v = sqlite3GetVdbe(pParse);
   1.153 -  sqlite3VdbeAddOp(v, OP_Integer, value, 0);
   1.154 -  if( pParse->explain==0 ){
   1.155 -    sqlite3VdbeSetNumCols(v, 1);
   1.156 -    sqlite3VdbeSetColName(v, 0, COLNAME_NAME, zLabel, P3_STATIC);
   1.157 -  }
   1.158 -  sqlite3VdbeAddOp(v, OP_Callback, 1, 0);
   1.159 -}
   1.160 -
   1.161 -#ifndef SQLITE_OMIT_FLAG_PRAGMAS
   1.162 -/*
   1.163 -** Check to see if zRight and zLeft refer to a pragma that queries
   1.164 -** or changes one of the flags in db->flags.  Return 1 if so and 0 if not.
   1.165 -** Also, implement the pragma.
   1.166 -*/
   1.167 -static int flagPragma(Parse *pParse, const char *zLeft, const char *zRight){
   1.168 -  static const struct sPragmaType {
   1.169 -    const char *zName;  /* Name of the pragma */
   1.170 -    int mask;           /* Mask for the db->flags value */
   1.171 -  } aPragma[] = {
   1.172 -    { "full_column_names",        SQLITE_FullColNames  },
   1.173 -    { "short_column_names",       SQLITE_ShortColNames },
   1.174 -    { "count_changes",            SQLITE_CountRows     },
   1.175 -    { "empty_result_callbacks",   SQLITE_NullCallback  },
   1.176 -    { "legacy_file_format",       SQLITE_LegacyFileFmt },
   1.177 -    { "fullfsync",                SQLITE_FullFSync     },
   1.178 -#ifdef SQLITE_DEBUG
   1.179 -    { "sql_trace",                SQLITE_SqlTrace      },
   1.180 -    { "vdbe_listing",             SQLITE_VdbeListing   },
   1.181 -    { "vdbe_trace",               SQLITE_VdbeTrace     },
   1.182 -#endif
   1.183 -#ifndef SQLITE_OMIT_CHECK
   1.184 -    { "ignore_check_constraints", SQLITE_IgnoreChecks  },
   1.185 -#endif
   1.186 -    /* The following is VERY experimental */
   1.187 -    { "writable_schema",          SQLITE_WriteSchema|SQLITE_RecoveryMode },
   1.188 -    { "omit_readlock",            SQLITE_NoReadlock    },
   1.189 -
   1.190 -    /* TODO: Maybe it shouldn't be possible to change the ReadUncommitted
   1.191 -    ** flag if there are any active statements. */
   1.192 -    { "read_uncommitted",         SQLITE_ReadUncommitted },
   1.193 -  };
   1.194 -  int i;
   1.195 -  const struct sPragmaType *p;
   1.196 -  for(i=0, p=aPragma; i<sizeof(aPragma)/sizeof(aPragma[0]); i++, p++){
   1.197 -    if( sqlite3StrICmp(zLeft, p->zName)==0 ){
   1.198 -      sqlite3 *db = pParse->db;
   1.199 -      Vdbe *v;
   1.200 -      v = sqlite3GetVdbe(pParse);
   1.201 -      if( v ){
   1.202 -        if( zRight==0 ){
   1.203 -          returnSingleInt(pParse, p->zName, (db->flags & p->mask)!=0 );
   1.204 -        }else{
   1.205 -          if( getBoolean(zRight) ){
   1.206 -            db->flags |= p->mask;
   1.207 -          }else{
   1.208 -            db->flags &= ~p->mask;
   1.209 -          }
   1.210 -        }
   1.211 -      }
   1.212 -      return 1;
   1.213 -    }
   1.214 -  }
   1.215 -  return 0;
   1.216 -}
   1.217 -#endif /* SQLITE_OMIT_FLAG_PRAGMAS */
   1.218 -
   1.219 -/*
   1.220 -** Process a pragma statement.  
   1.221 -**
   1.222 -** Pragmas are of this form:
   1.223 -**
   1.224 -**      PRAGMA [database.]id [= value]
   1.225 -**
   1.226 -** The identifier might also be a string.  The value is a string, and
   1.227 -** identifier, or a number.  If minusFlag is true, then the value is
   1.228 -** a number that was preceded by a minus sign.
   1.229 -**
   1.230 -** If the left side is "database.id" then pId1 is the database name
   1.231 -** and pId2 is the id.  If the left side is just "id" then pId1 is the
   1.232 -** id and pId2 is any empty string.
   1.233 -*/
   1.234 -void sqlite3Pragma(
   1.235 -  Parse *pParse, 
   1.236 -  Token *pId1,        /* First part of [database.]id field */
   1.237 -  Token *pId2,        /* Second part of [database.]id field, or NULL */
   1.238 -  Token *pValue,      /* Token for <value>, or NULL */
   1.239 -  int minusFlag       /* True if a '-' sign preceded <value> */
   1.240 -){
   1.241 -  char *zLeft = 0;       /* Nul-terminated UTF-8 string <id> */
   1.242 -  char *zRight = 0;      /* Nul-terminated UTF-8 string <value>, or NULL */
   1.243 -  const char *zDb = 0;   /* The database name */
   1.244 -  Token *pId;            /* Pointer to <id> token */
   1.245 -  int iDb;               /* Database index for <database> */
   1.246 -  sqlite3 *db = pParse->db;
   1.247 -  Db *pDb;
   1.248 -  Vdbe *v = sqlite3GetVdbe(pParse);
   1.249 -  if( v==0 ) return;
   1.250 -
   1.251 -  /* Interpret the [database.] part of the pragma statement. iDb is the
   1.252 -  ** index of the database this pragma is being applied to in db.aDb[]. */
   1.253 -  iDb = sqlite3TwoPartName(pParse, pId1, pId2, &pId);
   1.254 -  if( iDb<0 ) return;
   1.255 -  pDb = &db->aDb[iDb];
   1.256 -
   1.257 -  /* If the temp database has been explicitly named as part of the 
   1.258 -  ** pragma, make sure it is open. 
   1.259 -  */
   1.260 -  if( iDb==1 && sqlite3OpenTempDatabase(pParse) ){
   1.261 -    return;
   1.262 -  }
   1.263 -
   1.264 -  zLeft = sqlite3NameFromToken(db, pId);
   1.265 -  if( !zLeft ) return;
   1.266 -  if( minusFlag ){
   1.267 -    zRight = sqlite3MPrintf(db, "-%T", pValue);
   1.268 -  }else{
   1.269 -    zRight = sqlite3NameFromToken(db, pValue);
   1.270 -  }
   1.271 -
   1.272 -  zDb = ((iDb>0)?pDb->zName:0);
   1.273 -  if( sqlite3AuthCheck(pParse, SQLITE_PRAGMA, zLeft, zRight, zDb) ){
   1.274 -    goto pragma_out;
   1.275 -  }
   1.276 - 
   1.277 -#ifndef SQLITE_OMIT_PAGER_PRAGMAS
   1.278 -  /*
   1.279 -  **  PRAGMA [database.]default_cache_size
   1.280 -  **  PRAGMA [database.]default_cache_size=N
   1.281 -  **
   1.282 -  ** The first form reports the current persistent setting for the
   1.283 -  ** page cache size.  The value returned is the maximum number of
   1.284 -  ** pages in the page cache.  The second form sets both the current
   1.285 -  ** page cache size value and the persistent page cache size value
   1.286 -  ** stored in the database file.
   1.287 -  **
   1.288 -  ** The default cache size is stored in meta-value 2 of page 1 of the
   1.289 -  ** database file.  The cache size is actually the absolute value of
   1.290 -  ** this memory location.  The sign of meta-value 2 determines the
   1.291 -  ** synchronous setting.  A negative value means synchronous is off
   1.292 -  ** and a positive value means synchronous is on.
   1.293 -  */
   1.294 -  if( sqlite3StrICmp(zLeft,"default_cache_size")==0 ){
   1.295 -    static const VdbeOpList getCacheSize[] = {
   1.296 -      { OP_ReadCookie,  0, 2,        0},  /* 0 */
   1.297 -      { OP_AbsValue,    0, 0,        0},
   1.298 -      { OP_Dup,         0, 0,        0},
   1.299 -      { OP_Integer,     0, 0,        0},
   1.300 -      { OP_Ne,          0, 6,        0},
   1.301 -      { OP_Integer,     0, 0,        0},  /* 5 */
   1.302 -      { OP_Callback,    1, 0,        0},
   1.303 -    };
   1.304 -    int addr;
   1.305 -    if( sqlite3ReadSchema(pParse) ) goto pragma_out;
   1.306 -    sqlite3VdbeUsesBtree(v, iDb);
   1.307 -    if( !zRight ){
   1.308 -      sqlite3VdbeSetNumCols(v, 1);
   1.309 -      sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "cache_size", P3_STATIC);
   1.310 -      addr = sqlite3VdbeAddOpList(v, ArraySize(getCacheSize), getCacheSize);
   1.311 -      sqlite3VdbeChangeP1(v, addr, iDb);
   1.312 -      sqlite3VdbeChangeP1(v, addr+5, SQLITE_DEFAULT_CACHE_SIZE);
   1.313 -    }else{
   1.314 -      int size = atoi(zRight);
   1.315 -      if( size<0 ) size = -size;
   1.316 -      sqlite3BeginWriteOperation(pParse, 0, iDb);
   1.317 -      sqlite3VdbeAddOp(v, OP_Integer, size, 0);
   1.318 -      sqlite3VdbeAddOp(v, OP_ReadCookie, iDb, 2);
   1.319 -      addr = sqlite3VdbeAddOp(v, OP_Integer, 0, 0);
   1.320 -      sqlite3VdbeAddOp(v, OP_Ge, 0, addr+3);
   1.321 -      sqlite3VdbeAddOp(v, OP_Negative, 0, 0);
   1.322 -      sqlite3VdbeAddOp(v, OP_SetCookie, iDb, 2);
   1.323 -      pDb->pSchema->cache_size = size;
   1.324 -      sqlite3BtreeSetCacheSize(pDb->pBt, pDb->pSchema->cache_size);
   1.325 -    }
   1.326 -  }else
   1.327 -
   1.328 -  /*
   1.329 -  **  PRAGMA [database.]page_size
   1.330 -  **  PRAGMA [database.]page_size=N
   1.331 -  **
   1.332 -  ** The first form reports the current setting for the
   1.333 -  ** database page size in bytes.  The second form sets the
   1.334 -  ** database page size value.  The value can only be set if
   1.335 -  ** the database has not yet been created.
   1.336 -  */
   1.337 -  if( sqlite3StrICmp(zLeft,"page_size")==0 ){
   1.338 -    Btree *pBt = pDb->pBt;
   1.339 -    if( !zRight ){
   1.340 -      int size = pBt ? sqlite3BtreeGetPageSize(pBt) : 0;
   1.341 -      returnSingleInt(pParse, "page_size", size);
   1.342 -    }else{
   1.343 -      /* Malloc may fail when setting the page-size, as there is an internal
   1.344 -      ** buffer that the pager module resizes using sqlite3_realloc().
   1.345 -      */
   1.346 -      if( SQLITE_NOMEM==sqlite3BtreeSetPageSize(pBt, atoi(zRight), -1) ){
   1.347 -        db->mallocFailed = 1;
   1.348 -      }
   1.349 -    }
   1.350 -  }else
   1.351 -
   1.352 -  /*
   1.353 -  **  PRAGMA [database.]max_page_count
   1.354 -  **  PRAGMA [database.]max_page_count=N
   1.355 -  **
   1.356 -  ** The first form reports the current setting for the
   1.357 -  ** maximum number of pages in the database file.  The 
   1.358 -  ** second form attempts to change this setting.  Both
   1.359 -  ** forms return the current setting.
   1.360 -  */
   1.361 -  if( sqlite3StrICmp(zLeft,"max_page_count")==0 ){
   1.362 -    Btree *pBt = pDb->pBt;
   1.363 -    int newMax = 0;
   1.364 -    if( zRight ){
   1.365 -      newMax = atoi(zRight);
   1.366 -    }
   1.367 -    if( pBt ){
   1.368 -      newMax = sqlite3BtreeMaxPageCount(pBt, newMax);
   1.369 -    }
   1.370 -    returnSingleInt(pParse, "max_page_count", newMax);
   1.371 -  }else
   1.372 -
   1.373 -  /*
   1.374 -  **  PRAGMA [database.]locking_mode
   1.375 -  **  PRAGMA [database.]locking_mode = (normal|exclusive)
   1.376 -  */
   1.377 -  if( sqlite3StrICmp(zLeft,"locking_mode")==0 ){
   1.378 -    const char *zRet = "normal";
   1.379 -    int eMode = getLockingMode(zRight);
   1.380 -
   1.381 -    if( pId2->n==0 && eMode==PAGER_LOCKINGMODE_QUERY ){
   1.382 -      /* Simple "PRAGMA locking_mode;" statement. This is a query for
   1.383 -      ** the current default locking mode (which may be different to
   1.384 -      ** the locking-mode of the main database).
   1.385 -      */
   1.386 -      eMode = db->dfltLockMode;
   1.387 -    }else{
   1.388 -      Pager *pPager;
   1.389 -      if( pId2->n==0 ){
   1.390 -        /* This indicates that no database name was specified as part
   1.391 -        ** of the PRAGMA command. In this case the locking-mode must be
   1.392 -        ** set on all attached databases, as well as the main db file.
   1.393 -        **
   1.394 -        ** Also, the sqlite3.dfltLockMode variable is set so that
   1.395 -        ** any subsequently attached databases also use the specified
   1.396 -        ** locking mode.
   1.397 -        */
   1.398 -        int ii;
   1.399 -        assert(pDb==&db->aDb[0]);
   1.400 -        for(ii=2; ii<db->nDb; ii++){
   1.401 -          pPager = sqlite3BtreePager(db->aDb[ii].pBt);
   1.402 -          sqlite3PagerLockingMode(pPager, eMode);
   1.403 -        }
   1.404 -        db->dfltLockMode = eMode;
   1.405 -      }
   1.406 -      pPager = sqlite3BtreePager(pDb->pBt);
   1.407 -      eMode = sqlite3PagerLockingMode(pPager, eMode);
   1.408 -    }
   1.409 -
   1.410 -    assert(eMode==PAGER_LOCKINGMODE_NORMAL||eMode==PAGER_LOCKINGMODE_EXCLUSIVE);
   1.411 -    if( eMode==PAGER_LOCKINGMODE_EXCLUSIVE ){
   1.412 -      zRet = "exclusive";
   1.413 -    }
   1.414 -    sqlite3VdbeSetNumCols(v, 1);
   1.415 -    sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "locking_mode", P3_STATIC);
   1.416 -    sqlite3VdbeOp3(v, OP_String8, 0, 0, zRet, 0);
   1.417 -    sqlite3VdbeAddOp(v, OP_Callback, 1, 0);
   1.418 -  }else
   1.419 -#endif /* SQLITE_OMIT_PAGER_PRAGMAS */
   1.420 -
   1.421 -  /*
   1.422 -  **  PRAGMA [database.]auto_vacuum
   1.423 -  **  PRAGMA [database.]auto_vacuum=N
   1.424 -  **
   1.425 -  ** Get or set the (boolean) value of the database 'auto-vacuum' parameter.
   1.426 -  */
   1.427 -#ifndef SQLITE_OMIT_AUTOVACUUM
   1.428 -  if( sqlite3StrICmp(zLeft,"auto_vacuum")==0 ){
   1.429 -    Btree *pBt = pDb->pBt;
   1.430 -    if( sqlite3ReadSchema(pParse) ){
   1.431 -      goto pragma_out;
   1.432 -    }
   1.433 -    if( !zRight ){
   1.434 -      int auto_vacuum = 
   1.435 -          pBt ? sqlite3BtreeGetAutoVacuum(pBt) : SQLITE_DEFAULT_AUTOVACUUM;
   1.436 -      returnSingleInt(pParse, "auto_vacuum", auto_vacuum);
   1.437 -    }else{
   1.438 -      int eAuto = getAutoVacuum(zRight);
   1.439 -      if( eAuto>=0 ){
   1.440 -        /* Call SetAutoVacuum() to set initialize the internal auto and
   1.441 -        ** incr-vacuum flags. This is required in case this connection
   1.442 -        ** creates the database file. It is important that it is created
   1.443 -        ** as an auto-vacuum capable db.
   1.444 -        */
   1.445 -        int rc = sqlite3BtreeSetAutoVacuum(pBt, eAuto);
   1.446 -        if( rc==SQLITE_OK && (eAuto==1 || eAuto==2) ){
   1.447 -          /* When setting the auto_vacuum mode to either "full" or 
   1.448 -          ** "incremental", write the value of meta[6] in the database
   1.449 -          ** file. Before writing to meta[6], check that meta[3] indicates
   1.450 -          ** that this really is an auto-vacuum capable database.
   1.451 -          */
   1.452 -          static const VdbeOpList setMeta6[] = {
   1.453 -            { OP_Transaction,    0,               1,        0},    /* 0 */
   1.454 -            { OP_ReadCookie,     0,               3,        0},    /* 1 */
   1.455 -            { OP_If,             0,               0,        0},    /* 2 */
   1.456 -            { OP_Halt,           SQLITE_OK,       OE_Abort, 0},    /* 3 */
   1.457 -            { OP_Integer,        0,               0,        0},    /* 4 */
   1.458 -            { OP_SetCookie,      0,               6,        0},    /* 5 */
   1.459 -          };
   1.460 -          int iAddr;
   1.461 -          iAddr = sqlite3VdbeAddOpList(v, ArraySize(setMeta6), setMeta6);
   1.462 -          sqlite3VdbeChangeP1(v, iAddr, iDb);
   1.463 -          sqlite3VdbeChangeP1(v, iAddr+1, iDb);
   1.464 -          sqlite3VdbeChangeP2(v, iAddr+2, iAddr+4);
   1.465 -          sqlite3VdbeChangeP1(v, iAddr+4, eAuto-1);
   1.466 -          sqlite3VdbeChangeP1(v, iAddr+5, iDb);
   1.467 -          sqlite3VdbeUsesBtree(v, iDb);
   1.468 -        }
   1.469 -      }
   1.470 -    }
   1.471 -  }else
   1.472 -#endif
   1.473 -
   1.474 -  /*
   1.475 -  **  PRAGMA [database.]incremental_vacuum(N)
   1.476 -  **
   1.477 -  ** Do N steps of incremental vacuuming on a database.
   1.478 -  */
   1.479 -#ifndef SQLITE_OMIT_AUTOVACUUM
   1.480 -  if( sqlite3StrICmp(zLeft,"incremental_vacuum")==0 ){
   1.481 -    int iLimit, addr;
   1.482 -    if( sqlite3ReadSchema(pParse) ){
   1.483 -      goto pragma_out;
   1.484 -    }
   1.485 -    if( zRight==0 || !sqlite3GetInt32(zRight, &iLimit) || iLimit<=0 ){
   1.486 -      iLimit = 0x7fffffff;
   1.487 -    }
   1.488 -    sqlite3BeginWriteOperation(pParse, 0, iDb);
   1.489 -    sqlite3VdbeAddOp(v, OP_MemInt, iLimit, 0);
   1.490 -    addr = sqlite3VdbeAddOp(v, OP_IncrVacuum, iDb, 0);
   1.491 -    sqlite3VdbeAddOp(v, OP_Callback, 0, 0);
   1.492 -    sqlite3VdbeAddOp(v, OP_MemIncr, -1, 0);
   1.493 -    sqlite3VdbeAddOp(v, OP_IfMemPos, 0, addr);
   1.494 -    sqlite3VdbeJumpHere(v, addr);
   1.495 -  }else
   1.496 -#endif
   1.497 -
   1.498 -#ifndef SQLITE_OMIT_PAGER_PRAGMAS
   1.499 -  /*
   1.500 -  **  PRAGMA [database.]cache_size
   1.501 -  **  PRAGMA [database.]cache_size=N
   1.502 -  **
   1.503 -  ** The first form reports the current local setting for the
   1.504 -  ** page cache size.  The local setting can be different from
   1.505 -  ** the persistent cache size value that is stored in the database
   1.506 -  ** file itself.  The value returned is the maximum number of
   1.507 -  ** pages in the page cache.  The second form sets the local
   1.508 -  ** page cache size value.  It does not change the persistent
   1.509 -  ** cache size stored on the disk so the cache size will revert
   1.510 -  ** to its default value when the database is closed and reopened.
   1.511 -  ** N should be a positive integer.
   1.512 -  */
   1.513 -  if( sqlite3StrICmp(zLeft,"cache_size")==0 ){
   1.514 -    if( sqlite3ReadSchema(pParse) ) goto pragma_out;
   1.515 -    if( !zRight ){
   1.516 -      returnSingleInt(pParse, "cache_size", pDb->pSchema->cache_size);
   1.517 -    }else{
   1.518 -      int size = atoi(zRight);
   1.519 -      if( size<0 ) size = -size;
   1.520 -      pDb->pSchema->cache_size = size;
   1.521 -      sqlite3BtreeSetCacheSize(pDb->pBt, pDb->pSchema->cache_size);
   1.522 -    }
   1.523 -  }else
   1.524 -
   1.525 -  /*
   1.526 -  **   PRAGMA temp_store
   1.527 -  **   PRAGMA temp_store = "default"|"memory"|"file"
   1.528 -  **
   1.529 -  ** Return or set the local value of the temp_store flag.  Changing
   1.530 -  ** the local value does not make changes to the disk file and the default
   1.531 -  ** value will be restored the next time the database is opened.
   1.532 -  **
   1.533 -  ** Note that it is possible for the library compile-time options to
   1.534 -  ** override this setting
   1.535 -  */
   1.536 -  if( sqlite3StrICmp(zLeft, "temp_store")==0 ){
   1.537 -    if( !zRight ){
   1.538 -      returnSingleInt(pParse, "temp_store", db->temp_store);
   1.539 -    }else{
   1.540 -      changeTempStorage(pParse, zRight);
   1.541 -    }
   1.542 -  }else
   1.543 -
   1.544 -  /*
   1.545 -  **   PRAGMA temp_store_directory
   1.546 -  **   PRAGMA temp_store_directory = ""|"directory_name"
   1.547 -  **
   1.548 -  ** Return or set the local value of the temp_store_directory flag.  Changing
   1.549 -  ** the value sets a specific directory to be used for temporary files.
   1.550 -  ** Setting to a null string reverts to the default temporary directory search.
   1.551 -  ** If temporary directory is changed, then invalidateTempStorage.
   1.552 -  **
   1.553 -  */
   1.554 -  if( sqlite3StrICmp(zLeft, "temp_store_directory")==0 ){
   1.555 -    if( !zRight ){
   1.556 -      if( sqlite3_temp_directory ){
   1.557 -        sqlite3VdbeSetNumCols(v, 1);
   1.558 -        sqlite3VdbeSetColName(v, 0, COLNAME_NAME, 
   1.559 -            "temp_store_directory", P3_STATIC);
   1.560 -        sqlite3VdbeOp3(v, OP_String8, 0, 0, sqlite3_temp_directory, 0);
   1.561 -        sqlite3VdbeAddOp(v, OP_Callback, 1, 0);
   1.562 -      }
   1.563 -    }else{
   1.564 -      if( zRight[0] 
   1.565 -       && !sqlite3OsAccess(db->pVfs, zRight, SQLITE_ACCESS_READWRITE) 
   1.566 -      ){
   1.567 -        sqlite3ErrorMsg(pParse, "not a writable directory");
   1.568 -        goto pragma_out;
   1.569 -      }
   1.570 -      if( TEMP_STORE==0
   1.571 -       || (TEMP_STORE==1 && db->temp_store<=1)
   1.572 -       || (TEMP_STORE==2 && db->temp_store==1)
   1.573 -      ){
   1.574 -        invalidateTempStorage(pParse);
   1.575 -      }
   1.576 -      sqlite3_free(sqlite3_temp_directory);
   1.577 -      if( zRight[0] ){
   1.578 -        sqlite3_temp_directory = zRight;
   1.579 -        zRight = 0;
   1.580 -      }else{
   1.581 -        sqlite3_temp_directory = 0;
   1.582 -      }
   1.583 -    }
   1.584 -  }else
   1.585 -
   1.586 -  /*
   1.587 -  **   PRAGMA [database.]synchronous
   1.588 -  **   PRAGMA [database.]synchronous=OFF|ON|NORMAL|FULL
   1.589 -  **
   1.590 -  ** Return or set the local value of the synchronous flag.  Changing
   1.591 -  ** the local value does not make changes to the disk file and the
   1.592 -  ** default value will be restored the next time the database is
   1.593 -  ** opened.
   1.594 -  */
   1.595 -  if( sqlite3StrICmp(zLeft,"synchronous")==0 ){
   1.596 -    if( sqlite3ReadSchema(pParse) ) goto pragma_out;
   1.597 -    if( !zRight ){
   1.598 -      returnSingleInt(pParse, "synchronous", pDb->safety_level-1);
   1.599 -    }else{
   1.600 -      if( !db->autoCommit ){
   1.601 -        sqlite3ErrorMsg(pParse, 
   1.602 -            "Safety level may not be changed inside a transaction");
   1.603 -      }else{
   1.604 -        pDb->safety_level = getSafetyLevel(zRight)+1;
   1.605 -      }
   1.606 -    }
   1.607 -  }else
   1.608 -#endif /* SQLITE_OMIT_PAGER_PRAGMAS */
   1.609 -
   1.610 -#ifndef SQLITE_OMIT_FLAG_PRAGMAS
   1.611 -  if( flagPragma(pParse, zLeft, zRight) ){
   1.612 -    /* The flagPragma() subroutine also generates any necessary code
   1.613 -    ** there is nothing more to do here */
   1.614 -  }else
   1.615 -#endif /* SQLITE_OMIT_FLAG_PRAGMAS */
   1.616 -
   1.617 -#ifndef SQLITE_OMIT_SCHEMA_PRAGMAS
   1.618 -  /*
   1.619 -  **   PRAGMA table_info(<table>)
   1.620 -  **
   1.621 -  ** Return a single row for each column of the named table. The columns of
   1.622 -  ** the returned data set are:
   1.623 -  **
   1.624 -  ** cid:        Column id (numbered from left to right, starting at 0)
   1.625 -  ** name:       Column name
   1.626 -  ** type:       Column declaration type.
   1.627 -  ** notnull:    True if 'NOT NULL' is part of column declaration
   1.628 -  ** dflt_value: The default value for the column, if any.
   1.629 -  */
   1.630 -  if( sqlite3StrICmp(zLeft, "table_info")==0 && zRight ){
   1.631 -    Table *pTab;
   1.632 -    if( sqlite3ReadSchema(pParse) ) goto pragma_out;
   1.633 -    pTab = sqlite3FindTable(db, zRight, zDb);
   1.634 -    if( pTab ){
   1.635 -      int i;
   1.636 -      int nHidden = 0;
   1.637 -      Column *pCol;
   1.638 -      sqlite3VdbeSetNumCols(v, 6);
   1.639 -      sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "cid", P3_STATIC);
   1.640 -      sqlite3VdbeSetColName(v, 1, COLNAME_NAME, "name", P3_STATIC);
   1.641 -      sqlite3VdbeSetColName(v, 2, COLNAME_NAME, "type", P3_STATIC);
   1.642 -      sqlite3VdbeSetColName(v, 3, COLNAME_NAME, "notnull", P3_STATIC);
   1.643 -      sqlite3VdbeSetColName(v, 4, COLNAME_NAME, "dflt_value", P3_STATIC);
   1.644 -      sqlite3VdbeSetColName(v, 5, COLNAME_NAME, "pk", P3_STATIC);
   1.645 -      sqlite3ViewGetColumnNames(pParse, pTab);
   1.646 -      for(i=0, pCol=pTab->aCol; i<pTab->nCol; i++, pCol++){
   1.647 -        const Token *pDflt;
   1.648 -        if( IsHiddenColumn(pCol) ){
   1.649 -          nHidden++;
   1.650 -          continue;
   1.651 -        }
   1.652 -        sqlite3VdbeAddOp(v, OP_Integer, i-nHidden, 0);
   1.653 -        sqlite3VdbeOp3(v, OP_String8, 0, 0, pCol->zName, 0);
   1.654 -        sqlite3VdbeOp3(v, OP_String8, 0, 0,
   1.655 -           pCol->zType ? pCol->zType : "", 0);
   1.656 -        sqlite3VdbeAddOp(v, OP_Integer, pCol->notNull, 0);
   1.657 -        if( pCol->pDflt && (pDflt = &pCol->pDflt->span)->z ){
   1.658 -          sqlite3VdbeOp3(v, OP_String8, 0, 0, (char*)pDflt->z, pDflt->n);
   1.659 -        }else{
   1.660 -          sqlite3VdbeAddOp(v, OP_Null, 0, 0);
   1.661 -        }
   1.662 -        sqlite3VdbeAddOp(v, OP_Integer, pCol->isPrimKey, 0);
   1.663 -        sqlite3VdbeAddOp(v, OP_Callback, 6, 0);
   1.664 -      }
   1.665 -    }
   1.666 -  }else
   1.667 -
   1.668 -  if( sqlite3StrICmp(zLeft, "index_info")==0 && zRight ){
   1.669 -    Index *pIdx;
   1.670 -    Table *pTab;
   1.671 -    if( sqlite3ReadSchema(pParse) ) goto pragma_out;
   1.672 -    pIdx = sqlite3FindIndex(db, zRight, zDb);
   1.673 -    if( pIdx ){
   1.674 -      int i;
   1.675 -      pTab = pIdx->pTable;
   1.676 -      sqlite3VdbeSetNumCols(v, 3);
   1.677 -      sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "seqno", P3_STATIC);
   1.678 -      sqlite3VdbeSetColName(v, 1, COLNAME_NAME, "cid", P3_STATIC);
   1.679 -      sqlite3VdbeSetColName(v, 2, COLNAME_NAME, "name", P3_STATIC);
   1.680 -      for(i=0; i<pIdx->nColumn; i++){
   1.681 -        int cnum = pIdx->aiColumn[i];
   1.682 -        sqlite3VdbeAddOp(v, OP_Integer, i, 0);
   1.683 -        sqlite3VdbeAddOp(v, OP_Integer, cnum, 0);
   1.684 -        assert( pTab->nCol>cnum );
   1.685 -        sqlite3VdbeOp3(v, OP_String8, 0, 0, pTab->aCol[cnum].zName, 0);
   1.686 -        sqlite3VdbeAddOp(v, OP_Callback, 3, 0);
   1.687 -      }
   1.688 -    }
   1.689 -  }else
   1.690 -
   1.691 -  if( sqlite3StrICmp(zLeft, "index_list")==0 && zRight ){
   1.692 -    Index *pIdx;
   1.693 -    Table *pTab;
   1.694 -    if( sqlite3ReadSchema(pParse) ) goto pragma_out;
   1.695 -    pTab = sqlite3FindTable(db, zRight, zDb);
   1.696 -    if( pTab ){
   1.697 -      v = sqlite3GetVdbe(pParse);
   1.698 -      pIdx = pTab->pIndex;
   1.699 -      if( pIdx ){
   1.700 -        int i = 0; 
   1.701 -        sqlite3VdbeSetNumCols(v, 3);
   1.702 -        sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "seq", P3_STATIC);
   1.703 -        sqlite3VdbeSetColName(v, 1, COLNAME_NAME, "name", P3_STATIC);
   1.704 -        sqlite3VdbeSetColName(v, 2, COLNAME_NAME, "unique", P3_STATIC);
   1.705 -        while(pIdx){
   1.706 -          sqlite3VdbeAddOp(v, OP_Integer, i, 0);
   1.707 -          sqlite3VdbeOp3(v, OP_String8, 0, 0, pIdx->zName, 0);
   1.708 -          sqlite3VdbeAddOp(v, OP_Integer, pIdx->onError!=OE_None, 0);
   1.709 -          sqlite3VdbeAddOp(v, OP_Callback, 3, 0);
   1.710 -          ++i;
   1.711 -          pIdx = pIdx->pNext;
   1.712 -        }
   1.713 -      }
   1.714 -    }
   1.715 -  }else
   1.716 -
   1.717 -  if( sqlite3StrICmp(zLeft, "database_list")==0 ){
   1.718 -    int i;
   1.719 -    if( sqlite3ReadSchema(pParse) ) goto pragma_out;
   1.720 -    sqlite3VdbeSetNumCols(v, 3);
   1.721 -    sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "seq", P3_STATIC);
   1.722 -    sqlite3VdbeSetColName(v, 1, COLNAME_NAME, "name", P3_STATIC);
   1.723 -    sqlite3VdbeSetColName(v, 2, COLNAME_NAME, "file", P3_STATIC);
   1.724 -    for(i=0; i<db->nDb; i++){
   1.725 -      if( db->aDb[i].pBt==0 ) continue;
   1.726 -      assert( db->aDb[i].zName!=0 );
   1.727 -      sqlite3VdbeAddOp(v, OP_Integer, i, 0);
   1.728 -      sqlite3VdbeOp3(v, OP_String8, 0, 0, db->aDb[i].zName, 0);
   1.729 -      sqlite3VdbeOp3(v, OP_String8, 0, 0,
   1.730 -           sqlite3BtreeGetFilename(db->aDb[i].pBt), 0);
   1.731 -      sqlite3VdbeAddOp(v, OP_Callback, 3, 0);
   1.732 -    }
   1.733 -  }else
   1.734 -
   1.735 -  if( sqlite3StrICmp(zLeft, "collation_list")==0 ){
   1.736 -    int i = 0;
   1.737 -    HashElem *p;
   1.738 -    sqlite3VdbeSetNumCols(v, 2);
   1.739 -    sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "seq", P3_STATIC);
   1.740 -    sqlite3VdbeSetColName(v, 1, COLNAME_NAME, "name", P3_STATIC);
   1.741 -    for(p=sqliteHashFirst(&db->aCollSeq); p; p=sqliteHashNext(p)){
   1.742 -      CollSeq *pColl = (CollSeq *)sqliteHashData(p);
   1.743 -      sqlite3VdbeAddOp(v, OP_Integer, i++, 0);
   1.744 -      sqlite3VdbeOp3(v, OP_String8, 0, 0, pColl->zName, 0);
   1.745 -      sqlite3VdbeAddOp(v, OP_Callback, 2, 0);
   1.746 -    }
   1.747 -  }else
   1.748 -#endif /* SQLITE_OMIT_SCHEMA_PRAGMAS */
   1.749 -
   1.750 -#ifndef SQLITE_OMIT_FOREIGN_KEY
   1.751 -  if( sqlite3StrICmp(zLeft, "foreign_key_list")==0 && zRight ){
   1.752 -    FKey *pFK;
   1.753 -    Table *pTab;
   1.754 -    if( sqlite3ReadSchema(pParse) ) goto pragma_out;
   1.755 -    pTab = sqlite3FindTable(db, zRight, zDb);
   1.756 -    if( pTab ){
   1.757 -      v = sqlite3GetVdbe(pParse);
   1.758 -      pFK = pTab->pFKey;
   1.759 -      if( pFK ){
   1.760 -        int i = 0; 
   1.761 -        sqlite3VdbeSetNumCols(v, 5);
   1.762 -        sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "id", P3_STATIC);
   1.763 -        sqlite3VdbeSetColName(v, 1, COLNAME_NAME, "seq", P3_STATIC);
   1.764 -        sqlite3VdbeSetColName(v, 2, COLNAME_NAME, "table", P3_STATIC);
   1.765 -        sqlite3VdbeSetColName(v, 3, COLNAME_NAME, "from", P3_STATIC);
   1.766 -        sqlite3VdbeSetColName(v, 4, COLNAME_NAME, "to", P3_STATIC);
   1.767 -        while(pFK){
   1.768 -          int j;
   1.769 -          for(j=0; j<pFK->nCol; j++){
   1.770 -            char *zCol = pFK->aCol[j].zCol;
   1.771 -            sqlite3VdbeAddOp(v, OP_Integer, i, 0);
   1.772 -            sqlite3VdbeAddOp(v, OP_Integer, j, 0);
   1.773 -            sqlite3VdbeOp3(v, OP_String8, 0, 0, pFK->zTo, 0);
   1.774 -            sqlite3VdbeOp3(v, OP_String8, 0, 0,
   1.775 -                             pTab->aCol[pFK->aCol[j].iFrom].zName, 0);
   1.776 -            sqlite3VdbeOp3(v, zCol ? OP_String8 : OP_Null, 0, 0, zCol, 0);
   1.777 -            sqlite3VdbeAddOp(v, OP_Callback, 5, 0);
   1.778 -          }
   1.779 -          ++i;
   1.780 -          pFK = pFK->pNextFrom;
   1.781 -        }
   1.782 -      }
   1.783 -    }
   1.784 -  }else
   1.785 -#endif /* !defined(SQLITE_OMIT_FOREIGN_KEY) */
   1.786 -
   1.787 -#ifndef NDEBUG
   1.788 -  if( sqlite3StrICmp(zLeft, "parser_trace")==0 ){
   1.789 -    if( zRight ){
   1.790 -      if( getBoolean(zRight) ){
   1.791 -        sqlite3ParserTrace(stderr, "parser: ");
   1.792 -      }else{
   1.793 -        sqlite3ParserTrace(0, 0);
   1.794 -      }
   1.795 -    }
   1.796 -  }else
   1.797 -#endif
   1.798 -
   1.799 -  /* Reinstall the LIKE and GLOB functions.  The variant of LIKE
   1.800 -  ** used will be case sensitive or not depending on the RHS.
   1.801 -  */
   1.802 -  if( sqlite3StrICmp(zLeft, "case_sensitive_like")==0 ){
   1.803 -    if( zRight ){
   1.804 -      sqlite3RegisterLikeFunctions(db, getBoolean(zRight));
   1.805 -    }
   1.806 -  }else
   1.807 -
   1.808 -#ifndef SQLITE_INTEGRITY_CHECK_ERROR_MAX
   1.809 -# define SQLITE_INTEGRITY_CHECK_ERROR_MAX 100
   1.810 -#endif
   1.811 -
   1.812 -#ifndef SQLITE_OMIT_INTEGRITY_CHECK
   1.813 -  if( sqlite3StrICmp(zLeft, "integrity_check")==0 ){
   1.814 -    int i, j, addr, mxErr;
   1.815 -
   1.816 -    /* Code that appears at the end of the integrity check.  If no error
   1.817 -    ** messages have been generated, output OK.  Otherwise output the
   1.818 -    ** error message
   1.819 -    */
   1.820 -    static const VdbeOpList endCode[] = {
   1.821 -      { OP_MemLoad,     0, 0,        0},
   1.822 -      { OP_Integer,     0, 0,        0},
   1.823 -      { OP_Ne,          0, 0,        0},    /* 2 */
   1.824 -      { OP_String8,     0, 0,        "ok"},
   1.825 -      { OP_Callback,    1, 0,        0},
   1.826 -    };
   1.827 -
   1.828 -    /* Initialize the VDBE program */
   1.829 -    if( sqlite3ReadSchema(pParse) ) goto pragma_out;
   1.830 -    sqlite3VdbeSetNumCols(v, 1);
   1.831 -    sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "integrity_check", P3_STATIC);
   1.832 -
   1.833 -    /* Set the maximum error count */
   1.834 -    mxErr = SQLITE_INTEGRITY_CHECK_ERROR_MAX;
   1.835 -    if( zRight ){
   1.836 -      mxErr = atoi(zRight);
   1.837 -      if( mxErr<=0 ){
   1.838 -        mxErr = SQLITE_INTEGRITY_CHECK_ERROR_MAX;
   1.839 -      }
   1.840 -    }
   1.841 -    sqlite3VdbeAddOp(v, OP_MemInt, mxErr, 0);
   1.842 -
   1.843 -    /* Do an integrity check on each database file */
   1.844 -    for(i=0; i<db->nDb; i++){
   1.845 -      HashElem *x;
   1.846 -      Hash *pTbls;
   1.847 -      int cnt = 0;
   1.848 -
   1.849 -      if( OMIT_TEMPDB && i==1 ) continue;
   1.850 -
   1.851 -      sqlite3CodeVerifySchema(pParse, i);
   1.852 -      addr = sqlite3VdbeAddOp(v, OP_IfMemPos, 0, 0);
   1.853 -      sqlite3VdbeAddOp(v, OP_Halt, 0, 0);
   1.854 -      sqlite3VdbeJumpHere(v, addr);
   1.855 -
   1.856 -      /* Do an integrity check of the B-Tree
   1.857 -      */
   1.858 -      pTbls = &db->aDb[i].pSchema->tblHash;
   1.859 -      for(x=sqliteHashFirst(pTbls); x; x=sqliteHashNext(x)){
   1.860 -        Table *pTab = sqliteHashData(x);
   1.861 -        Index *pIdx;
   1.862 -        sqlite3VdbeAddOp(v, OP_Integer, pTab->tnum, 0);
   1.863 -        cnt++;
   1.864 -        for(pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext){
   1.865 -          sqlite3VdbeAddOp(v, OP_Integer, pIdx->tnum, 0);
   1.866 -          cnt++;
   1.867 -        }
   1.868 -      }
   1.869 -      if( cnt==0 ) continue;
   1.870 -      sqlite3VdbeAddOp(v, OP_IntegrityCk, 0, i);
   1.871 -      addr = sqlite3VdbeAddOp(v, OP_IsNull, -1, 0);
   1.872 -      sqlite3VdbeOp3(v, OP_String8, 0, 0,
   1.873 -         sqlite3MPrintf(db, "*** in database %s ***\n", db->aDb[i].zName),
   1.874 -         P3_DYNAMIC);
   1.875 -      sqlite3VdbeAddOp(v, OP_Pull, 1, 0);
   1.876 -      sqlite3VdbeAddOp(v, OP_Concat, 0, 0);
   1.877 -      sqlite3VdbeAddOp(v, OP_Callback, 1, 0);
   1.878 -      sqlite3VdbeJumpHere(v, addr);
   1.879 -
   1.880 -      /* Make sure all the indices are constructed correctly.
   1.881 -      */
   1.882 -      for(x=sqliteHashFirst(pTbls); x; x=sqliteHashNext(x)){
   1.883 -        Table *pTab = sqliteHashData(x);
   1.884 -        Index *pIdx;
   1.885 -        int loopTop;
   1.886 -
   1.887 -        if( pTab->pIndex==0 ) continue;
   1.888 -        addr = sqlite3VdbeAddOp(v, OP_IfMemPos, 0, 0);
   1.889 -        sqlite3VdbeAddOp(v, OP_Halt, 0, 0);
   1.890 -        sqlite3VdbeJumpHere(v, addr);
   1.891 -        sqlite3OpenTableAndIndices(pParse, pTab, 1, OP_OpenRead);
   1.892 -        sqlite3VdbeAddOp(v, OP_MemInt, 0, 1);
   1.893 -        loopTop = sqlite3VdbeAddOp(v, OP_Rewind, 1, 0);
   1.894 -        sqlite3VdbeAddOp(v, OP_MemIncr, 1, 1);
   1.895 -        for(j=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, j++){
   1.896 -          int jmp2;
   1.897 -          static const VdbeOpList idxErr[] = {
   1.898 -            { OP_MemIncr,    -1,  0,  0},
   1.899 -            { OP_String8,     0,  0,  "rowid "},
   1.900 -            { OP_Rowid,       1,  0,  0},
   1.901 -            { OP_String8,     0,  0,  " missing from index "},
   1.902 -            { OP_String8,     0,  0,  0},    /* 4 */
   1.903 -            { OP_Concat,      2,  0,  0},
   1.904 -            { OP_Callback,    1,  0,  0},
   1.905 -          };
   1.906 -          sqlite3GenerateIndexKey(v, pIdx, 1);
   1.907 -          jmp2 = sqlite3VdbeAddOp(v, OP_Found, j+2, 0);
   1.908 -          addr = sqlite3VdbeAddOpList(v, ArraySize(idxErr), idxErr);
   1.909 -          sqlite3VdbeChangeP3(v, addr+4, pIdx->zName, P3_STATIC);
   1.910 -          sqlite3VdbeJumpHere(v, jmp2);
   1.911 -        }
   1.912 -        sqlite3VdbeAddOp(v, OP_Next, 1, loopTop+1);
   1.913 -        sqlite3VdbeJumpHere(v, loopTop);
   1.914 -        for(j=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, j++){
   1.915 -          static const VdbeOpList cntIdx[] = {
   1.916 -             { OP_MemInt,       0,  2,  0},
   1.917 -             { OP_Rewind,       0,  0,  0},  /* 1 */
   1.918 -             { OP_MemIncr,      1,  2,  0},
   1.919 -             { OP_Next,         0,  0,  0},  /* 3 */
   1.920 -             { OP_MemLoad,      1,  0,  0},
   1.921 -             { OP_MemLoad,      2,  0,  0},
   1.922 -             { OP_Eq,           0,  0,  0},  /* 6 */
   1.923 -             { OP_MemIncr,     -1,  0,  0},
   1.924 -             { OP_String8,      0,  0,  "wrong # of entries in index "},
   1.925 -             { OP_String8,      0,  0,  0},  /* 9 */
   1.926 -             { OP_Concat,       0,  0,  0},
   1.927 -             { OP_Callback,     1,  0,  0},
   1.928 -          };
   1.929 -          if( pIdx->tnum==0 ) continue;
   1.930 -          addr = sqlite3VdbeAddOp(v, OP_IfMemPos, 0, 0);
   1.931 -          sqlite3VdbeAddOp(v, OP_Halt, 0, 0);
   1.932 -          sqlite3VdbeJumpHere(v, addr);
   1.933 -          addr = sqlite3VdbeAddOpList(v, ArraySize(cntIdx), cntIdx);
   1.934 -          sqlite3VdbeChangeP1(v, addr+1, j+2);
   1.935 -          sqlite3VdbeChangeP2(v, addr+1, addr+4);
   1.936 -          sqlite3VdbeChangeP1(v, addr+3, j+2);
   1.937 -          sqlite3VdbeChangeP2(v, addr+3, addr+2);
   1.938 -          sqlite3VdbeJumpHere(v, addr+6);
   1.939 -          sqlite3VdbeChangeP3(v, addr+9, pIdx->zName, P3_STATIC);
   1.940 -        }
   1.941 -      } 
   1.942 -    }
   1.943 -    addr = sqlite3VdbeAddOpList(v, ArraySize(endCode), endCode);
   1.944 -    sqlite3VdbeChangeP1(v, addr+1, mxErr);
   1.945 -    sqlite3VdbeJumpHere(v, addr+2);
   1.946 -  }else
   1.947 -#endif /* SQLITE_OMIT_INTEGRITY_CHECK */
   1.948 -
   1.949 -#ifndef SQLITE_OMIT_UTF16
   1.950 -  /*
   1.951 -  **   PRAGMA encoding
   1.952 -  **   PRAGMA encoding = "utf-8"|"utf-16"|"utf-16le"|"utf-16be"
   1.953 -  **
   1.954 -  ** In it's first form, this pragma returns the encoding of the main
   1.955 -  ** database. If the database is not initialized, it is initialized now.
   1.956 -  **
   1.957 -  ** The second form of this pragma is a no-op if the main database file
   1.958 -  ** has not already been initialized. In this case it sets the default
   1.959 -  ** encoding that will be used for the main database file if a new file
   1.960 -  ** is created. If an existing main database file is opened, then the
   1.961 -  ** default text encoding for the existing database is used.
   1.962 -  ** 
   1.963 -  ** In all cases new databases created using the ATTACH command are
   1.964 -  ** created to use the same default text encoding as the main database. If
   1.965 -  ** the main database has not been initialized and/or created when ATTACH
   1.966 -  ** is executed, this is done before the ATTACH operation.
   1.967 -  **
   1.968 -  ** In the second form this pragma sets the text encoding to be used in
   1.969 -  ** new database files created using this database handle. It is only
   1.970 -  ** useful if invoked immediately after the main database i
   1.971 -  */
   1.972 -  if( sqlite3StrICmp(zLeft, "encoding")==0 ){
   1.973 -    static const struct EncName {
   1.974 -      char *zName;
   1.975 -      u8 enc;
   1.976 -    } encnames[] = {
   1.977 -      { "UTF-8",    SQLITE_UTF8        },
   1.978 -      { "UTF8",     SQLITE_UTF8        },
   1.979 -      { "UTF-16le", SQLITE_UTF16LE     },
   1.980 -      { "UTF16le",  SQLITE_UTF16LE     },
   1.981 -      { "UTF-16be", SQLITE_UTF16BE     },
   1.982 -      { "UTF16be",  SQLITE_UTF16BE     },
   1.983 -      { "UTF-16",   0                  }, /* SQLITE_UTF16NATIVE */
   1.984 -      { "UTF16",    0                  }, /* SQLITE_UTF16NATIVE */
   1.985 -      { 0, 0 }
   1.986 -    };
   1.987 -    const struct EncName *pEnc;
   1.988 -    if( !zRight ){    /* "PRAGMA encoding" */
   1.989 -      if( sqlite3ReadSchema(pParse) ) goto pragma_out;
   1.990 -      sqlite3VdbeSetNumCols(v, 1);
   1.991 -      sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "encoding", P3_STATIC);
   1.992 -      sqlite3VdbeAddOp(v, OP_String8, 0, 0);
   1.993 -      for(pEnc=&encnames[0]; pEnc->zName; pEnc++){
   1.994 -        if( pEnc->enc==ENC(pParse->db) ){
   1.995 -          sqlite3VdbeChangeP3(v, -1, pEnc->zName, P3_STATIC);
   1.996 -          break;
   1.997 -        }
   1.998 -      }
   1.999 -      sqlite3VdbeAddOp(v, OP_Callback, 1, 0);
  1.1000 -    }else{                        /* "PRAGMA encoding = XXX" */
  1.1001 -      /* Only change the value of sqlite.enc if the database handle is not
  1.1002 -      ** initialized. If the main database exists, the new sqlite.enc value
  1.1003 -      ** will be overwritten when the schema is next loaded. If it does not
  1.1004 -      ** already exists, it will be created to use the new encoding value.
  1.1005 -      */
  1.1006 -      if( 
  1.1007 -        !(DbHasProperty(db, 0, DB_SchemaLoaded)) || 
  1.1008 -        DbHasProperty(db, 0, DB_Empty) 
  1.1009 -      ){
  1.1010 -        for(pEnc=&encnames[0]; pEnc->zName; pEnc++){
  1.1011 -          if( 0==sqlite3StrICmp(zRight, pEnc->zName) ){
  1.1012 -            ENC(pParse->db) = pEnc->enc ? pEnc->enc : SQLITE_UTF16NATIVE;
  1.1013 -            break;
  1.1014 -          }
  1.1015 -        }
  1.1016 -        if( !pEnc->zName ){
  1.1017 -          sqlite3ErrorMsg(pParse, "unsupported encoding: %s", zRight);
  1.1018 -        }
  1.1019 -      }
  1.1020 -    }
  1.1021 -  }else
  1.1022 -#endif /* SQLITE_OMIT_UTF16 */
  1.1023 -
  1.1024 -#ifndef SQLITE_OMIT_SCHEMA_VERSION_PRAGMAS
  1.1025 -  /*
  1.1026 -  **   PRAGMA [database.]schema_version
  1.1027 -  **   PRAGMA [database.]schema_version = <integer>
  1.1028 -  **
  1.1029 -  **   PRAGMA [database.]user_version
  1.1030 -  **   PRAGMA [database.]user_version = <integer>
  1.1031 -  **
  1.1032 -  ** The pragma's schema_version and user_version are used to set or get
  1.1033 -  ** the value of the schema-version and user-version, respectively. Both
  1.1034 -  ** the schema-version and the user-version are 32-bit signed integers
  1.1035 -  ** stored in the database header.
  1.1036 -  **
  1.1037 -  ** The schema-cookie is usually only manipulated internally by SQLite. It
  1.1038 -  ** is incremented by SQLite whenever the database schema is modified (by
  1.1039 -  ** creating or dropping a table or index). The schema version is used by
  1.1040 -  ** SQLite each time a query is executed to ensure that the internal cache
  1.1041 -  ** of the schema used when compiling the SQL query matches the schema of
  1.1042 -  ** the database against which the compiled query is actually executed.
  1.1043 -  ** Subverting this mechanism by using "PRAGMA schema_version" to modify
  1.1044 -  ** the schema-version is potentially dangerous and may lead to program
  1.1045 -  ** crashes or database corruption. Use with caution!
  1.1046 -  **
  1.1047 -  ** The user-version is not used internally by SQLite. It may be used by
  1.1048 -  ** applications for any purpose.
  1.1049 -  */
  1.1050 -  if( sqlite3StrICmp(zLeft, "schema_version")==0 
  1.1051 -   || sqlite3StrICmp(zLeft, "user_version")==0 
  1.1052 -   || sqlite3StrICmp(zLeft, "freelist_count")==0 
  1.1053 -  ){
  1.1054 -
  1.1055 -    int iCookie;   /* Cookie index. 0 for schema-cookie, 6 for user-cookie. */
  1.1056 -    sqlite3VdbeUsesBtree(v, iDb);
  1.1057 -    switch( zLeft[0] ){
  1.1058 -      case 's': case 'S':
  1.1059 -        iCookie = 0;
  1.1060 -        break;
  1.1061 -      case 'f': case 'F':
  1.1062 -        iCookie = 1;
  1.1063 -        iDb = (-1*(iDb+1));
  1.1064 -        assert(iDb<=0);
  1.1065 -        break;
  1.1066 -      default:
  1.1067 -        iCookie = 5;
  1.1068 -        break;
  1.1069 -    }
  1.1070 -
  1.1071 -    if( zRight && iDb>=0 ){
  1.1072 -      /* Write the specified cookie value */
  1.1073 -      static const VdbeOpList setCookie[] = {
  1.1074 -        { OP_Transaction,    0,  1,  0},    /* 0 */
  1.1075 -        { OP_Integer,        0,  0,  0},    /* 1 */
  1.1076 -        { OP_SetCookie,      0,  0,  0},    /* 2 */
  1.1077 -      };
  1.1078 -      int addr = sqlite3VdbeAddOpList(v, ArraySize(setCookie), setCookie);
  1.1079 -      sqlite3VdbeChangeP1(v, addr, iDb);
  1.1080 -      sqlite3VdbeChangeP1(v, addr+1, atoi(zRight));
  1.1081 -      sqlite3VdbeChangeP1(v, addr+2, iDb);
  1.1082 -      sqlite3VdbeChangeP2(v, addr+2, iCookie);
  1.1083 -    }else{
  1.1084 -      /* Read the specified cookie value */
  1.1085 -      static const VdbeOpList readCookie[] = {
  1.1086 -        { OP_ReadCookie,      0,  0,  0},    /* 0 */
  1.1087 -        { OP_Callback,        1,  0,  0}
  1.1088 -      };
  1.1089 -      int addr = sqlite3VdbeAddOpList(v, ArraySize(readCookie), readCookie);
  1.1090 -      sqlite3VdbeChangeP1(v, addr, iDb);
  1.1091 -      sqlite3VdbeChangeP2(v, addr, iCookie);
  1.1092 -      sqlite3VdbeSetNumCols(v, 1);
  1.1093 -      sqlite3VdbeSetColName(v, 0, COLNAME_NAME, zLeft, P3_TRANSIENT);
  1.1094 -    }
  1.1095 -  }else
  1.1096 -#endif /* SQLITE_OMIT_SCHEMA_VERSION_PRAGMAS */
  1.1097 -
  1.1098 -#if defined(SQLITE_DEBUG) || defined(SQLITE_TEST)
  1.1099 -  /*
  1.1100 -  ** Report the current state of file logs for all databases
  1.1101 -  */
  1.1102 -  if( sqlite3StrICmp(zLeft, "lock_status")==0 ){
  1.1103 -    static const char *const azLockName[] = {
  1.1104 -      "unlocked", "shared", "reserved", "pending", "exclusive"
  1.1105 -    };
  1.1106 -    int i;
  1.1107 -    Vdbe *v = sqlite3GetVdbe(pParse);
  1.1108 -    sqlite3VdbeSetNumCols(v, 2);
  1.1109 -    sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "database", P3_STATIC);
  1.1110 -    sqlite3VdbeSetColName(v, 1, COLNAME_NAME, "status", P3_STATIC);
  1.1111 -    for(i=0; i<db->nDb; i++){
  1.1112 -      Btree *pBt;
  1.1113 -      Pager *pPager;
  1.1114 -      const char *zState = "unknown";
  1.1115 -      int j;
  1.1116 -      if( db->aDb[i].zName==0 ) continue;
  1.1117 -      sqlite3VdbeOp3(v, OP_String8, 0, 0, db->aDb[i].zName, P3_STATIC);
  1.1118 -      pBt = db->aDb[i].pBt;
  1.1119 -      if( pBt==0 || (pPager = sqlite3BtreePager(pBt))==0 ){
  1.1120 -        zState = "closed";
  1.1121 -      }else if( sqlite3_file_control(db, db->aDb[i].zName, 
  1.1122 -                                     SQLITE_FCNTL_LOCKSTATE, &j)==SQLITE_OK ){
  1.1123 -         zState = azLockName[j];
  1.1124 -      }
  1.1125 -      sqlite3VdbeOp3(v, OP_String8, 0, 0, zState, P3_STATIC);
  1.1126 -      sqlite3VdbeAddOp(v, OP_Callback, 2, 0);
  1.1127 -    }
  1.1128 -  }else
  1.1129 -#endif
  1.1130 -
  1.1131 -#ifdef SQLITE_SSE
  1.1132 -  /*
  1.1133 -  ** Check to see if the sqlite_statements table exists.  Create it
  1.1134 -  ** if it does not.
  1.1135 -  */
  1.1136 -  if( sqlite3StrICmp(zLeft, "create_sqlite_statement_table")==0 ){
  1.1137 -    extern int sqlite3CreateStatementsTable(Parse*);
  1.1138 -    sqlite3CreateStatementsTable(pParse);
  1.1139 -  }else
  1.1140 -#endif
  1.1141 -
  1.1142 -#if SQLITE_HAS_CODEC
  1.1143 -  if( sqlite3StrICmp(zLeft, "key")==0 ){
  1.1144 -    sqlite3_key(db, zRight, strlen(zRight));
  1.1145 -  }else
  1.1146 -#endif
  1.1147 -#if SQLITE_HAS_CODEC || defined(SQLITE_ENABLE_CEROD)
  1.1148 -  if( sqlite3StrICmp(zLeft, "activate_extensions")==0 ){
  1.1149 -#if SQLITE_HAS_CODEC
  1.1150 -    if( sqlite3StrNICmp(zRight, "see-", 4)==0 ){
  1.1151 -      extern void sqlite3_activate_see(const char*);
  1.1152 -      sqlite3_activate_see(&zRight[4]);
  1.1153 -    }
  1.1154 -#endif
  1.1155 -#ifdef SQLITE_ENABLE_CEROD
  1.1156 -    if( sqlite3StrNICmp(zRight, "cerod-", 6)==0 ){
  1.1157 -      extern void sqlite3_activate_cerod(const char*);
  1.1158 -      sqlite3_activate_cerod(&zRight[6]);
  1.1159 -    }
  1.1160 -#endif
  1.1161 -  }
  1.1162 -#endif
  1.1163 -
  1.1164 -  {}
  1.1165 -
  1.1166 -  if( v ){
  1.1167 -    /* Code an OP_Expire at the end of each PRAGMA program to cause
  1.1168 -    ** the VDBE implementing the pragma to expire. Most (all?) pragmas
  1.1169 -    ** are only valid for a single execution.
  1.1170 -    */
  1.1171 -    sqlite3VdbeAddOp(v, OP_Expire, 1, 0);
  1.1172 -
  1.1173 -    /*
  1.1174 -    ** Reset the safety level, in case the fullfsync flag or synchronous
  1.1175 -    ** setting changed.
  1.1176 -    */
  1.1177 -#ifndef SQLITE_OMIT_PAGER_PRAGMAS
  1.1178 -    if( db->autoCommit ){
  1.1179 -      sqlite3BtreeSetSafetyLevel(pDb->pBt, pDb->safety_level,
  1.1180 -                 (db->flags&SQLITE_FullFSync)!=0);
  1.1181 -    }
  1.1182 -#endif
  1.1183 -  }
  1.1184 -pragma_out:
  1.1185 -  sqlite3_free(zLeft);
  1.1186 -  sqlite3_free(zRight);
  1.1187 -}
  1.1188 -
  1.1189 -#endif /* SQLITE_OMIT_PRAGMA || SQLITE_OMIT_PARSER */