webengine/webkitutils/SqliteSymbian/pragma.c
changeset 0 dd21522fd290
equal deleted inserted replaced
-1:000000000000 0:dd21522fd290
       
     1 /*
       
     2 ** 2003 April 6
       
     3 **
       
     4 ** The author disclaims copyright to this source code.  In place of
       
     5 ** a legal notice, here is a blessing:
       
     6 **
       
     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.
       
    10 **
       
    11 *************************************************************************
       
    12 ** This file contains code used to implement the PRAGMA command.
       
    13 **
       
    14 ** $Id: pragma.c,v 1.122 2006/08/14 14:23:42 drh Exp $
       
    15 */
       
    16 #include "sqliteInt.h"
       
    17 #include "os.h"
       
    18 #include <ctype.h>
       
    19 
       
    20 /* Ignore this whole file if pragmas are disabled
       
    21 */
       
    22 #if !defined(SQLITE_OMIT_PRAGMA) && !defined(SQLITE_OMIT_PARSER)
       
    23 
       
    24 #if defined(SQLITE_DEBUG) || defined(SQLITE_TEST)
       
    25 # include "pager.h"
       
    26 # include "btree.h"
       
    27 #endif
       
    28 
       
    29 /*
       
    30 ** Interpret the given string as a safety level.  Return 0 for OFF,
       
    31 ** 1 for ON or NORMAL and 2 for FULL.  Return 1 for an empty or 
       
    32 ** unrecognized string argument.
       
    33 **
       
    34 ** Note that the values returned are one less that the values that
       
    35 ** should be passed into sqlite3BtreeSetSafetyLevel().  The is done
       
    36 ** to support legacy SQL code.  The safety level used to be boolean
       
    37 ** and older scripts may have used numbers 0 for OFF and 1 for ON.
       
    38 */
       
    39 static int getSafetyLevel(const char *z){
       
    40                              /* 123456789 123456789 */
       
    41   static const char zText[] = "onoffalseyestruefull";
       
    42   static const u8 iOffset[] = {0, 1, 2, 4, 9, 12, 16};
       
    43   static const u8 iLength[] = {2, 2, 3, 5, 3, 4, 4};
       
    44   static const u8 iValue[] =  {1, 0, 0, 0, 1, 1, 2};
       
    45   int i, n;
       
    46   if( isdigit(*z) ){
       
    47     return atoi(z);
       
    48   }
       
    49   n = strlen(z);
       
    50   for(i=0; i<sizeof(iLength); i++){
       
    51     if( iLength[i]==n && sqlite3StrNICmp(&zText[iOffset[i]],z,n)==0 ){
       
    52       return iValue[i];
       
    53     }
       
    54   }
       
    55   return 1;
       
    56 }
       
    57 
       
    58 /*
       
    59 ** Interpret the given string as a boolean value.
       
    60 */
       
    61 static int getBoolean(const char *z){
       
    62   return getSafetyLevel(z)&1;
       
    63 }
       
    64 
       
    65 #ifndef SQLITE_OMIT_PAGER_PRAGMAS
       
    66 /*
       
    67 ** Interpret the given string as a temp db location. Return 1 for file
       
    68 ** backed temporary databases, 2 for the Red-Black tree in memory database
       
    69 ** and 0 to use the compile-time default.
       
    70 */
       
    71 static int getTempStore(const char *z){
       
    72   if( z[0]>='0' && z[0]<='2' ){
       
    73     return z[0] - '0';
       
    74   }else if( sqlite3StrICmp(z, "file")==0 ){
       
    75     return 1;
       
    76   }else if( sqlite3StrICmp(z, "memory")==0 ){
       
    77     return 2;
       
    78   }else{
       
    79     return 0;
       
    80   }
       
    81 }
       
    82 #endif /* SQLITE_PAGER_PRAGMAS */
       
    83 
       
    84 #ifndef SQLITE_OMIT_PAGER_PRAGMAS
       
    85 /*
       
    86 ** Invalidate temp storage, either when the temp storage is changed
       
    87 ** from default, or when 'file' and the temp_store_directory has changed
       
    88 */
       
    89 static int invalidateTempStorage(Parse *pParse){
       
    90   sqlite3 *db = pParse->db;
       
    91   if( db->aDb[1].pBt!=0 ){
       
    92     if( db->flags & SQLITE_InTrans ){
       
    93       sqlite3ErrorMsg(pParse, "temporary storage cannot be changed "
       
    94         "from within a transaction");
       
    95       return SQLITE_ERROR;
       
    96     }
       
    97     sqlite3BtreeClose(db->aDb[1].pBt);
       
    98     db->aDb[1].pBt = 0;
       
    99     sqlite3ResetInternalSchema(db, 0);
       
   100   }
       
   101   return SQLITE_OK;
       
   102 }
       
   103 #endif /* SQLITE_PAGER_PRAGMAS */
       
   104 
       
   105 #ifndef SQLITE_OMIT_PAGER_PRAGMAS
       
   106 /*
       
   107 ** If the TEMP database is open, close it and mark the database schema
       
   108 ** as needing reloading.  This must be done when using the TEMP_STORE
       
   109 ** or DEFAULT_TEMP_STORE pragmas.
       
   110 */
       
   111 static int changeTempStorage(Parse *pParse, const char *zStorageType){
       
   112   int ts = getTempStore(zStorageType);
       
   113   sqlite3 *db = pParse->db;
       
   114   if( db->temp_store==ts ) return SQLITE_OK;
       
   115   if( invalidateTempStorage( pParse ) != SQLITE_OK ){
       
   116     return SQLITE_ERROR;
       
   117   }
       
   118   db->temp_store = ts;
       
   119   return SQLITE_OK;
       
   120 }
       
   121 #endif /* SQLITE_PAGER_PRAGMAS */
       
   122 
       
   123 /*
       
   124 ** Generate code to return a single integer value.
       
   125 */
       
   126 static void returnSingleInt(Parse *pParse, const char *zLabel, int value){
       
   127   Vdbe *v = sqlite3GetVdbe(pParse);
       
   128   sqlite3VdbeAddOp(v, OP_Integer, value, 0);
       
   129   if( pParse->explain==0 ){
       
   130     sqlite3VdbeSetNumCols(v, 1);
       
   131     sqlite3VdbeSetColName(v, 0, COLNAME_NAME, zLabel, P3_STATIC);
       
   132   }
       
   133   sqlite3VdbeAddOp(v, OP_Callback, 1, 0);
       
   134 }
       
   135 
       
   136 #ifndef SQLITE_OMIT_FLAG_PRAGMAS
       
   137 /*
       
   138 ** Check to see if zRight and zLeft refer to a pragma that queries
       
   139 ** or changes one of the flags in db->flags.  Return 1 if so and 0 if not.
       
   140 ** Also, implement the pragma.
       
   141 */
       
   142 static int flagPragma(Parse *pParse, const char *zLeft, const char *zRight){
       
   143   static const struct sPragmaType {
       
   144     const char *zName;  /* Name of the pragma */
       
   145     int mask;           /* Mask for the db->flags value */
       
   146   } aPragma[] = {
       
   147     { "vdbe_trace",               SQLITE_VdbeTrace     },
       
   148     { "sql_trace",                SQLITE_SqlTrace      },
       
   149     { "vdbe_listing",             SQLITE_VdbeListing   },
       
   150     { "full_column_names",        SQLITE_FullColNames  },
       
   151     { "short_column_names",       SQLITE_ShortColNames },
       
   152     { "count_changes",            SQLITE_CountRows     },
       
   153     { "empty_result_callbacks",   SQLITE_NullCallback  },
       
   154     { "legacy_file_format",       SQLITE_LegacyFileFmt },
       
   155     { "fullfsync",                SQLITE_FullFSync     },
       
   156 #ifndef SQLITE_OMIT_CHECK
       
   157     { "ignore_check_constraints", SQLITE_IgnoreChecks  },
       
   158 #endif
       
   159     /* The following is VERY experimental */
       
   160     { "writable_schema",          SQLITE_WriteSchema   },
       
   161     { "omit_readlock",            SQLITE_NoReadlock    },
       
   162 
       
   163     /* TODO: Maybe it shouldn't be possible to change the ReadUncommitted
       
   164     ** flag if there are any active statements. */
       
   165     { "read_uncommitted",         SQLITE_ReadUncommitted },
       
   166   };
       
   167   int i;
       
   168   const struct sPragmaType *p;
       
   169   for(i=0, p=aPragma; i<sizeof(aPragma)/sizeof(aPragma[0]); i++, p++){
       
   170     if( sqlite3StrICmp(zLeft, p->zName)==0 ){
       
   171       sqlite3 *db = pParse->db;
       
   172       Vdbe *v;
       
   173       v = sqlite3GetVdbe(pParse);
       
   174       if( v ){
       
   175         if( zRight==0 ){
       
   176           returnSingleInt(pParse, p->zName, (db->flags & p->mask)!=0 );
       
   177         }else{
       
   178           if( getBoolean(zRight) ){
       
   179             db->flags |= p->mask;
       
   180           }else{
       
   181             db->flags &= ~p->mask;
       
   182           }
       
   183         }
       
   184       }
       
   185       return 1;
       
   186     }
       
   187   }
       
   188   return 0;
       
   189 }
       
   190 #endif /* SQLITE_OMIT_FLAG_PRAGMAS */
       
   191 
       
   192 /*
       
   193 ** Process a pragma statement.  
       
   194 **
       
   195 ** Pragmas are of this form:
       
   196 **
       
   197 **      PRAGMA [database.]id [= value]
       
   198 **
       
   199 ** The identifier might also be a string.  The value is a string, and
       
   200 ** identifier, or a number.  If minusFlag is true, then the value is
       
   201 ** a number that was preceded by a minus sign.
       
   202 **
       
   203 ** If the left side is "database.id" then pId1 is the database name
       
   204 ** and pId2 is the id.  If the left side is just "id" then pId1 is the
       
   205 ** id and pId2 is any empty string.
       
   206 */
       
   207 void sqlite3Pragma(
       
   208   Parse *pParse, 
       
   209   Token *pId1,        /* First part of [database.]id field */
       
   210   Token *pId2,        /* Second part of [database.]id field, or NULL */
       
   211   Token *pValue,      /* Token for <value>, or NULL */
       
   212   int minusFlag       /* True if a '-' sign preceded <value> */
       
   213 ){
       
   214   char *zLeft = 0;       /* Nul-terminated UTF-8 string <id> */
       
   215   char *zRight = 0;      /* Nul-terminated UTF-8 string <value>, or NULL */
       
   216   const char *zDb = 0;   /* The database name */
       
   217   Token *pId;            /* Pointer to <id> token */
       
   218   int iDb;               /* Database index for <database> */
       
   219   sqlite3 *db = pParse->db;
       
   220   Db *pDb;
       
   221   Vdbe *v = sqlite3GetVdbe(pParse);
       
   222   if( v==0 ) return;
       
   223 
       
   224   /* Interpret the [database.] part of the pragma statement. iDb is the
       
   225   ** index of the database this pragma is being applied to in db.aDb[]. */
       
   226   iDb = sqlite3TwoPartName(pParse, pId1, pId2, &pId);
       
   227   if( iDb<0 ) return;
       
   228   pDb = &db->aDb[iDb];
       
   229 
       
   230   /* If the temp database has been explicitly named as part of the 
       
   231   ** pragma, make sure it is open. 
       
   232   */
       
   233   if( iDb==1 && sqlite3OpenTempDatabase(pParse) ){
       
   234     return;
       
   235   }
       
   236 
       
   237   zLeft = sqlite3NameFromToken(pId);
       
   238   if( !zLeft ) return;
       
   239   if( minusFlag ){
       
   240     zRight = sqlite3MPrintf("-%T", pValue);
       
   241   }else{
       
   242     zRight = sqlite3NameFromToken(pValue);
       
   243   }
       
   244 
       
   245   zDb = ((iDb>0)?pDb->zName:0);
       
   246   if( sqlite3AuthCheck(pParse, SQLITE_PRAGMA, zLeft, zRight, zDb) ){
       
   247     goto pragma_out;
       
   248   }
       
   249  
       
   250 #ifndef SQLITE_OMIT_PAGER_PRAGMAS
       
   251   /*
       
   252   **  PRAGMA [database.]default_cache_size
       
   253   **  PRAGMA [database.]default_cache_size=N
       
   254   **
       
   255   ** The first form reports the current persistent setting for the
       
   256   ** page cache size.  The value returned is the maximum number of
       
   257   ** pages in the page cache.  The second form sets both the current
       
   258   ** page cache size value and the persistent page cache size value
       
   259   ** stored in the database file.
       
   260   **
       
   261   ** The default cache size is stored in meta-value 2 of page 1 of the
       
   262   ** database file.  The cache size is actually the absolute value of
       
   263   ** this memory location.  The sign of meta-value 2 determines the
       
   264   ** synchronous setting.  A negative value means synchronous is off
       
   265   ** and a positive value means synchronous is on.
       
   266   */
       
   267   if( sqlite3StrICmp(zLeft,"default_cache_size")==0 ){
       
   268     static const VdbeOpList getCacheSize[] = {
       
   269       { OP_ReadCookie,  0, 2,        0},  /* 0 */
       
   270       { OP_AbsValue,    0, 0,        0},
       
   271       { OP_Dup,         0, 0,        0},
       
   272       { OP_Integer,     0, 0,        0},
       
   273       { OP_Ne,          0, 6,        0},
       
   274       { OP_Integer,     0, 0,        0},  /* 5 */
       
   275       { OP_Callback,    1, 0,        0},
       
   276     };
       
   277     int addr;
       
   278     if( sqlite3ReadSchema(pParse) ) goto pragma_out;
       
   279     if( !zRight ){
       
   280       sqlite3VdbeSetNumCols(v, 1);
       
   281       sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "cache_size", P3_STATIC);
       
   282       addr = sqlite3VdbeAddOpList(v, ArraySize(getCacheSize), getCacheSize);
       
   283       sqlite3VdbeChangeP1(v, addr, iDb);
       
   284       sqlite3VdbeChangeP1(v, addr+5, MAX_PAGES);
       
   285     }else{
       
   286       int size = atoi(zRight);
       
   287       if( size<0 ) size = -size;
       
   288       sqlite3BeginWriteOperation(pParse, 0, iDb);
       
   289       sqlite3VdbeAddOp(v, OP_Integer, size, 0);
       
   290       sqlite3VdbeAddOp(v, OP_ReadCookie, iDb, 2);
       
   291       addr = sqlite3VdbeAddOp(v, OP_Integer, 0, 0);
       
   292       sqlite3VdbeAddOp(v, OP_Ge, 0, addr+3);
       
   293       sqlite3VdbeAddOp(v, OP_Negative, 0, 0);
       
   294       sqlite3VdbeAddOp(v, OP_SetCookie, iDb, 2);
       
   295       pDb->pSchema->cache_size = size;
       
   296       sqlite3BtreeSetCacheSize(pDb->pBt, pDb->pSchema->cache_size);
       
   297     }
       
   298   }else
       
   299 
       
   300   /*
       
   301   **  PRAGMA [database.]page_size
       
   302   **  PRAGMA [database.]page_size=N
       
   303   **
       
   304   ** The first form reports the current setting for the
       
   305   ** database page size in bytes.  The second form sets the
       
   306   ** database page size value.  The value can only be set if
       
   307   ** the database has not yet been created.
       
   308   */
       
   309   if( sqlite3StrICmp(zLeft,"page_size")==0 ){
       
   310     Btree *pBt = pDb->pBt;
       
   311     if( !zRight ){
       
   312       int size = pBt ? sqlite3BtreeGetPageSize(pBt) : 0;
       
   313       returnSingleInt(pParse, "page_size", size);
       
   314     }else{
       
   315       sqlite3BtreeSetPageSize(pBt, atoi(zRight), -1);
       
   316     }
       
   317   }else
       
   318 #endif /* SQLITE_OMIT_PAGER_PRAGMAS */
       
   319 
       
   320   /*
       
   321   **  PRAGMA [database.]auto_vacuum
       
   322   **  PRAGMA [database.]auto_vacuum=N
       
   323   **
       
   324   ** Get or set the (boolean) value of the database 'auto-vacuum' parameter.
       
   325   */
       
   326 #ifndef SQLITE_OMIT_AUTOVACUUM
       
   327   if( sqlite3StrICmp(zLeft,"auto_vacuum")==0 ){
       
   328     Btree *pBt = pDb->pBt;
       
   329     if( !zRight ){
       
   330       int auto_vacuum = 
       
   331           pBt ? sqlite3BtreeGetAutoVacuum(pBt) : SQLITE_DEFAULT_AUTOVACUUM;
       
   332       returnSingleInt(pParse, "auto_vacuum", auto_vacuum);
       
   333     }else{
       
   334       sqlite3BtreeSetAutoVacuum(pBt, getBoolean(zRight));
       
   335     }
       
   336   }else
       
   337 #endif
       
   338 
       
   339 #ifndef SQLITE_OMIT_PAGER_PRAGMAS
       
   340   /*
       
   341   **  PRAGMA [database.]cache_size
       
   342   **  PRAGMA [database.]cache_size=N
       
   343   **
       
   344   ** The first form reports the current local setting for the
       
   345   ** page cache size.  The local setting can be different from
       
   346   ** the persistent cache size value that is stored in the database
       
   347   ** file itself.  The value returned is the maximum number of
       
   348   ** pages in the page cache.  The second form sets the local
       
   349   ** page cache size value.  It does not change the persistent
       
   350   ** cache size stored on the disk so the cache size will revert
       
   351   ** to its default value when the database is closed and reopened.
       
   352   ** N should be a positive integer.
       
   353   */
       
   354   if( sqlite3StrICmp(zLeft,"cache_size")==0 ){
       
   355     if( sqlite3ReadSchema(pParse) ) goto pragma_out;
       
   356     if( !zRight ){
       
   357       returnSingleInt(pParse, "cache_size", pDb->pSchema->cache_size);
       
   358     }else{
       
   359       int size = atoi(zRight);
       
   360       if( size<0 ) size = -size;
       
   361       pDb->pSchema->cache_size = size;
       
   362       sqlite3BtreeSetCacheSize(pDb->pBt, pDb->pSchema->cache_size);
       
   363     }
       
   364   }else
       
   365 
       
   366   /*
       
   367   **   PRAGMA temp_store
       
   368   **   PRAGMA temp_store = "default"|"memory"|"file"
       
   369   **
       
   370   ** Return or set the local value of the temp_store flag.  Changing
       
   371   ** the local value does not make changes to the disk file and the default
       
   372   ** value will be restored the next time the database is opened.
       
   373   **
       
   374   ** Note that it is possible for the library compile-time options to
       
   375   ** override this setting
       
   376   */
       
   377   if( sqlite3StrICmp(zLeft, "temp_store")==0 ){
       
   378     if( !zRight ){
       
   379       returnSingleInt(pParse, "temp_store", db->temp_store);
       
   380     }else{
       
   381       changeTempStorage(pParse, zRight);
       
   382     }
       
   383   }else
       
   384 
       
   385   /*
       
   386   **   PRAGMA temp_store_directory
       
   387   **   PRAGMA temp_store_directory = ""|"directory_name"
       
   388   **
       
   389   ** Return or set the local value of the temp_store_directory flag.  Changing
       
   390   ** the value sets a specific directory to be used for temporary files.
       
   391   ** Setting to a null string reverts to the default temporary directory search.
       
   392   ** If temporary directory is changed, then invalidateTempStorage.
       
   393   **
       
   394   */
       
   395   if( sqlite3StrICmp(zLeft, "temp_store_directory")==0 ){
       
   396     if( !zRight ){
       
   397       if( sqlite3_temp_directory ){
       
   398         sqlite3VdbeSetNumCols(v, 1);
       
   399         sqlite3VdbeSetColName(v, 0, COLNAME_NAME, 
       
   400             "temp_store_directory", P3_STATIC);
       
   401         sqlite3VdbeOp3(v, OP_String8, 0, 0, sqlite3_temp_directory, 0);
       
   402         sqlite3VdbeAddOp(v, OP_Callback, 1, 0);
       
   403       }
       
   404     }else{
       
   405       if( zRight[0] && !sqlite3OsIsDirWritable(zRight) ){
       
   406         sqlite3ErrorMsg(pParse, "not a writable directory");
       
   407         goto pragma_out;
       
   408       }
       
   409       if( TEMP_STORE==0
       
   410        || (TEMP_STORE==1 && db->temp_store<=1)
       
   411        || (TEMP_STORE==2 && db->temp_store==1)
       
   412       ){
       
   413         invalidateTempStorage(pParse);
       
   414       }
       
   415       sqliteFree(sqlite3_temp_directory);
       
   416       if( zRight[0] ){
       
   417         sqlite3_temp_directory = zRight;
       
   418         zRight = 0;
       
   419       }else{
       
   420         sqlite3_temp_directory = 0;
       
   421       }
       
   422     }
       
   423   }else
       
   424 
       
   425   /*
       
   426   **   PRAGMA [database.]synchronous
       
   427   **   PRAGMA [database.]synchronous=OFF|ON|NORMAL|FULL
       
   428   **
       
   429   ** Return or set the local value of the synchronous flag.  Changing
       
   430   ** the local value does not make changes to the disk file and the
       
   431   ** default value will be restored the next time the database is
       
   432   ** opened.
       
   433   */
       
   434   if( sqlite3StrICmp(zLeft,"synchronous")==0 ){
       
   435     if( sqlite3ReadSchema(pParse) ) goto pragma_out;
       
   436     if( !zRight ){
       
   437       returnSingleInt(pParse, "synchronous", pDb->safety_level-1);
       
   438     }else{
       
   439       if( !db->autoCommit ){
       
   440         sqlite3ErrorMsg(pParse, 
       
   441             "Safety level may not be changed inside a transaction");
       
   442       }else{
       
   443         pDb->safety_level = getSafetyLevel(zRight)+1;
       
   444       }
       
   445     }
       
   446   }else
       
   447 #endif /* SQLITE_OMIT_PAGER_PRAGMAS */
       
   448 
       
   449 #ifndef SQLITE_OMIT_FLAG_PRAGMAS
       
   450   if( flagPragma(pParse, zLeft, zRight) ){
       
   451     /* The flagPragma() subroutine also generates any necessary code
       
   452     ** there is nothing more to do here */
       
   453   }else
       
   454 #endif /* SQLITE_OMIT_FLAG_PRAGMAS */
       
   455 
       
   456 #ifndef SQLITE_OMIT_SCHEMA_PRAGMAS
       
   457   /*
       
   458   **   PRAGMA table_info(<table>)
       
   459   **
       
   460   ** Return a single row for each column of the named table. The columns of
       
   461   ** the returned data set are:
       
   462   **
       
   463   ** cid:        Column id (numbered from left to right, starting at 0)
       
   464   ** name:       Column name
       
   465   ** type:       Column declaration type.
       
   466   ** notnull:    True if 'NOT NULL' is part of column declaration
       
   467   ** dflt_value: The default value for the column, if any.
       
   468   */
       
   469   if( sqlite3StrICmp(zLeft, "table_info")==0 && zRight ){
       
   470     Table *pTab;
       
   471     if( sqlite3ReadSchema(pParse) ) goto pragma_out;
       
   472     pTab = sqlite3FindTable(db, zRight, zDb);
       
   473     if( pTab ){
       
   474       int i;
       
   475       Column *pCol;
       
   476       sqlite3VdbeSetNumCols(v, 6);
       
   477       sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "cid", P3_STATIC);
       
   478       sqlite3VdbeSetColName(v, 1, COLNAME_NAME, "name", P3_STATIC);
       
   479       sqlite3VdbeSetColName(v, 2, COLNAME_NAME, "type", P3_STATIC);
       
   480       sqlite3VdbeSetColName(v, 3, COLNAME_NAME, "notnull", P3_STATIC);
       
   481       sqlite3VdbeSetColName(v, 4, COLNAME_NAME, "dflt_value", P3_STATIC);
       
   482       sqlite3VdbeSetColName(v, 5, COLNAME_NAME, "pk", P3_STATIC);
       
   483       sqlite3ViewGetColumnNames(pParse, pTab);
       
   484       for(i=0, pCol=pTab->aCol; i<pTab->nCol; i++, pCol++){
       
   485         const Token *pDflt;
       
   486         static const Token noDflt =  { (unsigned char*)"", 0, 0 };
       
   487         sqlite3VdbeAddOp(v, OP_Integer, i, 0);
       
   488         sqlite3VdbeOp3(v, OP_String8, 0, 0, pCol->zName, 0);
       
   489         sqlite3VdbeOp3(v, OP_String8, 0, 0,
       
   490            pCol->zType ? pCol->zType : "", 0);
       
   491         sqlite3VdbeAddOp(v, OP_Integer, pCol->notNull, 0);
       
   492         pDflt = pCol->pDflt ? &pCol->pDflt->span : &noDflt;
       
   493         sqlite3VdbeOp3(v, OP_String8, 0, 0, (char*)pDflt->z, pDflt->n);
       
   494         sqlite3VdbeAddOp(v, OP_Integer, pCol->isPrimKey, 0);
       
   495         sqlite3VdbeAddOp(v, OP_Callback, 6, 0);
       
   496       }
       
   497     }
       
   498   }else
       
   499 
       
   500   if( sqlite3StrICmp(zLeft, "index_info")==0 && zRight ){
       
   501     Index *pIdx;
       
   502     Table *pTab;
       
   503     if( sqlite3ReadSchema(pParse) ) goto pragma_out;
       
   504     pIdx = sqlite3FindIndex(db, zRight, zDb);
       
   505     if( pIdx ){
       
   506       int i;
       
   507       pTab = pIdx->pTable;
       
   508       sqlite3VdbeSetNumCols(v, 3);
       
   509       sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "seqno", P3_STATIC);
       
   510       sqlite3VdbeSetColName(v, 1, COLNAME_NAME, "cid", P3_STATIC);
       
   511       sqlite3VdbeSetColName(v, 2, COLNAME_NAME, "name", P3_STATIC);
       
   512       for(i=0; i<pIdx->nColumn; i++){
       
   513         int cnum = pIdx->aiColumn[i];
       
   514         sqlite3VdbeAddOp(v, OP_Integer, i, 0);
       
   515         sqlite3VdbeAddOp(v, OP_Integer, cnum, 0);
       
   516         assert( pTab->nCol>cnum );
       
   517         sqlite3VdbeOp3(v, OP_String8, 0, 0, pTab->aCol[cnum].zName, 0);
       
   518         sqlite3VdbeAddOp(v, OP_Callback, 3, 0);
       
   519       }
       
   520     }
       
   521   }else
       
   522 
       
   523   if( sqlite3StrICmp(zLeft, "index_list")==0 && zRight ){
       
   524     Index *pIdx;
       
   525     Table *pTab;
       
   526     if( sqlite3ReadSchema(pParse) ) goto pragma_out;
       
   527     pTab = sqlite3FindTable(db, zRight, zDb);
       
   528     if( pTab ){
       
   529       v = sqlite3GetVdbe(pParse);
       
   530       pIdx = pTab->pIndex;
       
   531       if( pIdx ){
       
   532         int i = 0; 
       
   533         sqlite3VdbeSetNumCols(v, 3);
       
   534         sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "seq", P3_STATIC);
       
   535         sqlite3VdbeSetColName(v, 1, COLNAME_NAME, "name", P3_STATIC);
       
   536         sqlite3VdbeSetColName(v, 2, COLNAME_NAME, "unique", P3_STATIC);
       
   537         while(pIdx){
       
   538           sqlite3VdbeAddOp(v, OP_Integer, i, 0);
       
   539           sqlite3VdbeOp3(v, OP_String8, 0, 0, pIdx->zName, 0);
       
   540           sqlite3VdbeAddOp(v, OP_Integer, pIdx->onError!=OE_None, 0);
       
   541           sqlite3VdbeAddOp(v, OP_Callback, 3, 0);
       
   542           ++i;
       
   543           pIdx = pIdx->pNext;
       
   544         }
       
   545       }
       
   546     }
       
   547   }else
       
   548 
       
   549   if( sqlite3StrICmp(zLeft, "database_list")==0 ){
       
   550     int i;
       
   551     if( sqlite3ReadSchema(pParse) ) goto pragma_out;
       
   552     sqlite3VdbeSetNumCols(v, 3);
       
   553     sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "seq", P3_STATIC);
       
   554     sqlite3VdbeSetColName(v, 1, COLNAME_NAME, "name", P3_STATIC);
       
   555     sqlite3VdbeSetColName(v, 2, COLNAME_NAME, "file", P3_STATIC);
       
   556     for(i=0; i<db->nDb; i++){
       
   557       if( db->aDb[i].pBt==0 ) continue;
       
   558       assert( db->aDb[i].zName!=0 );
       
   559       sqlite3VdbeAddOp(v, OP_Integer, i, 0);
       
   560       sqlite3VdbeOp3(v, OP_String8, 0, 0, db->aDb[i].zName, 0);
       
   561       sqlite3VdbeOp3(v, OP_String8, 0, 0,
       
   562            sqlite3BtreeGetFilename(db->aDb[i].pBt), 0);
       
   563       sqlite3VdbeAddOp(v, OP_Callback, 3, 0);
       
   564     }
       
   565   }else
       
   566 
       
   567   if( sqlite3StrICmp(zLeft, "collation_list")==0 ){
       
   568     int i = 0;
       
   569     HashElem *p;
       
   570     sqlite3VdbeSetNumCols(v, 2);
       
   571     sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "seq", P3_STATIC);
       
   572     sqlite3VdbeSetColName(v, 1, COLNAME_NAME, "name", P3_STATIC);
       
   573     for(p=sqliteHashFirst(&db->aCollSeq); p; p=sqliteHashNext(p)){
       
   574       CollSeq *pColl = (CollSeq *)sqliteHashData(p);
       
   575       sqlite3VdbeAddOp(v, OP_Integer, i++, 0);
       
   576       sqlite3VdbeOp3(v, OP_String8, 0, 0, pColl->zName, 0);
       
   577       sqlite3VdbeAddOp(v, OP_Callback, 2, 0);
       
   578     }
       
   579   }else
       
   580 #endif /* SQLITE_OMIT_SCHEMA_PRAGMAS */
       
   581 
       
   582 #ifndef SQLITE_OMIT_FOREIGN_KEY
       
   583   if( sqlite3StrICmp(zLeft, "foreign_key_list")==0 && zRight ){
       
   584     FKey *pFK;
       
   585     Table *pTab;
       
   586     if( sqlite3ReadSchema(pParse) ) goto pragma_out;
       
   587     pTab = sqlite3FindTable(db, zRight, zDb);
       
   588     if( pTab ){
       
   589       v = sqlite3GetVdbe(pParse);
       
   590       pFK = pTab->pFKey;
       
   591       if( pFK ){
       
   592         int i = 0; 
       
   593         sqlite3VdbeSetNumCols(v, 5);
       
   594         sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "id", P3_STATIC);
       
   595         sqlite3VdbeSetColName(v, 1, COLNAME_NAME, "seq", P3_STATIC);
       
   596         sqlite3VdbeSetColName(v, 2, COLNAME_NAME, "table", P3_STATIC);
       
   597         sqlite3VdbeSetColName(v, 3, COLNAME_NAME, "from", P3_STATIC);
       
   598         sqlite3VdbeSetColName(v, 4, COLNAME_NAME, "to", P3_STATIC);
       
   599         while(pFK){
       
   600           int j;
       
   601           for(j=0; j<pFK->nCol; j++){
       
   602             char *zCol = pFK->aCol[j].zCol;
       
   603             sqlite3VdbeAddOp(v, OP_Integer, i, 0);
       
   604             sqlite3VdbeAddOp(v, OP_Integer, j, 0);
       
   605             sqlite3VdbeOp3(v, OP_String8, 0, 0, pFK->zTo, 0);
       
   606             sqlite3VdbeOp3(v, OP_String8, 0, 0,
       
   607                              pTab->aCol[pFK->aCol[j].iFrom].zName, 0);
       
   608             sqlite3VdbeOp3(v, zCol ? OP_String8 : OP_Null, 0, 0, zCol, 0);
       
   609             sqlite3VdbeAddOp(v, OP_Callback, 5, 0);
       
   610           }
       
   611           ++i;
       
   612           pFK = pFK->pNextFrom;
       
   613         }
       
   614       }
       
   615     }
       
   616   }else
       
   617 #endif /* !defined(SQLITE_OMIT_FOREIGN_KEY) */
       
   618 
       
   619 #ifndef NDEBUG
       
   620   if( sqlite3StrICmp(zLeft, "parser_trace")==0 ){
       
   621     extern void sqlite3ParserTrace(FILE*, char *);
       
   622     if( zRight ){
       
   623       if( getBoolean(zRight) ){
       
   624         sqlite3ParserTrace(stderr, "parser: ");
       
   625       }else{
       
   626         sqlite3ParserTrace(0, 0);
       
   627       }
       
   628     }
       
   629   }else
       
   630 #endif
       
   631 
       
   632   /* Reinstall the LIKE and GLOB functions.  The variant of LIKE
       
   633   ** used will be case sensitive or not depending on the RHS.
       
   634   */
       
   635   if( sqlite3StrICmp(zLeft, "case_sensitive_like")==0 ){
       
   636     if( zRight ){
       
   637       sqlite3RegisterLikeFunctions(db, getBoolean(zRight));
       
   638     }
       
   639   }else
       
   640 
       
   641 #ifndef SQLITE_OMIT_INTEGRITY_CHECK
       
   642   if( sqlite3StrICmp(zLeft, "integrity_check")==0 ){
       
   643     int i, j, addr;
       
   644 
       
   645     /* Code that appears at the end of the integrity check.  If no error
       
   646     ** messages have been generated, output OK.  Otherwise output the
       
   647     ** error message
       
   648     */
       
   649     static const VdbeOpList endCode[] = {
       
   650       { OP_MemLoad,     0, 0,        0},
       
   651       { OP_Integer,     0, 0,        0},
       
   652       { OP_Ne,          0, 0,        0},    /* 2 */
       
   653       { OP_String8,     0, 0,        "ok"},
       
   654       { OP_Callback,    1, 0,        0},
       
   655     };
       
   656 
       
   657     /* Initialize the VDBE program */
       
   658     if( sqlite3ReadSchema(pParse) ) goto pragma_out;
       
   659     sqlite3VdbeSetNumCols(v, 1);
       
   660     sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "integrity_check", P3_STATIC);
       
   661     sqlite3VdbeAddOp(v, OP_MemInt, 0, 0);  /* Initialize error count to 0 */
       
   662 
       
   663     /* Do an integrity check on each database file */
       
   664     for(i=0; i<db->nDb; i++){
       
   665       HashElem *x;
       
   666       Hash *pTbls;
       
   667       int cnt = 0;
       
   668 
       
   669       if( OMIT_TEMPDB && i==1 ) continue;
       
   670 
       
   671       sqlite3CodeVerifySchema(pParse, i);
       
   672 
       
   673       /* Do an integrity check of the B-Tree
       
   674       */
       
   675       pTbls = &db->aDb[i].pSchema->tblHash;
       
   676       for(x=sqliteHashFirst(pTbls); x; x=sqliteHashNext(x)){
       
   677         Table *pTab = sqliteHashData(x);
       
   678         Index *pIdx;
       
   679         sqlite3VdbeAddOp(v, OP_Integer, pTab->tnum, 0);
       
   680         cnt++;
       
   681         for(pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext){
       
   682           sqlite3VdbeAddOp(v, OP_Integer, pIdx->tnum, 0);
       
   683           cnt++;
       
   684         }
       
   685       }
       
   686       assert( cnt>0 );
       
   687       sqlite3VdbeAddOp(v, OP_IntegrityCk, cnt, i);
       
   688       sqlite3VdbeAddOp(v, OP_Dup, 0, 1);
       
   689       addr = sqlite3VdbeOp3(v, OP_String8, 0, 0, "ok", P3_STATIC);
       
   690       sqlite3VdbeAddOp(v, OP_Eq, 0, addr+7);
       
   691       sqlite3VdbeOp3(v, OP_String8, 0, 0,
       
   692          sqlite3MPrintf("*** in database %s ***\n", db->aDb[i].zName),
       
   693          P3_DYNAMIC);
       
   694       sqlite3VdbeAddOp(v, OP_Pull, 1, 0);
       
   695       sqlite3VdbeAddOp(v, OP_Concat, 0, 1);
       
   696       sqlite3VdbeAddOp(v, OP_Callback, 1, 0);
       
   697       sqlite3VdbeAddOp(v, OP_MemIncr, 1, 0);
       
   698 
       
   699       /* Make sure all the indices are constructed correctly.
       
   700       */
       
   701       sqlite3CodeVerifySchema(pParse, i);
       
   702       for(x=sqliteHashFirst(pTbls); x; x=sqliteHashNext(x)){
       
   703         Table *pTab = sqliteHashData(x);
       
   704         Index *pIdx;
       
   705         int loopTop;
       
   706 
       
   707         if( pTab->pIndex==0 ) continue;
       
   708         sqlite3OpenTableAndIndices(pParse, pTab, 1, OP_OpenRead);
       
   709         sqlite3VdbeAddOp(v, OP_MemInt, 0, 1);
       
   710         loopTop = sqlite3VdbeAddOp(v, OP_Rewind, 1, 0);
       
   711         sqlite3VdbeAddOp(v, OP_MemIncr, 1, 1);
       
   712         for(j=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, j++){
       
   713           int jmp2;
       
   714           static const VdbeOpList idxErr[] = {
       
   715             { OP_MemIncr,     1,  0,  0},
       
   716             { OP_String8,     0,  0,  "rowid "},
       
   717             { OP_Rowid,       1,  0,  0},
       
   718             { OP_String8,     0,  0,  " missing from index "},
       
   719             { OP_String8,     0,  0,  0},    /* 4 */
       
   720             { OP_Concat,      2,  0,  0},
       
   721             { OP_Callback,    1,  0,  0},
       
   722           };
       
   723           sqlite3GenerateIndexKey(v, pIdx, 1);
       
   724           jmp2 = sqlite3VdbeAddOp(v, OP_Found, j+2, 0);
       
   725           addr = sqlite3VdbeAddOpList(v, ArraySize(idxErr), idxErr);
       
   726           sqlite3VdbeChangeP3(v, addr+4, pIdx->zName, P3_STATIC);
       
   727           sqlite3VdbeJumpHere(v, jmp2);
       
   728         }
       
   729         sqlite3VdbeAddOp(v, OP_Next, 1, loopTop+1);
       
   730         sqlite3VdbeJumpHere(v, loopTop);
       
   731         for(j=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, j++){
       
   732           static const VdbeOpList cntIdx[] = {
       
   733              { OP_MemInt,       0,  2,  0},
       
   734              { OP_Rewind,       0,  0,  0},  /* 1 */
       
   735              { OP_MemIncr,      1,  2,  0},
       
   736              { OP_Next,         0,  0,  0},  /* 3 */
       
   737              { OP_MemLoad,      1,  0,  0},
       
   738              { OP_MemLoad,      2,  0,  0},
       
   739              { OP_Eq,           0,  0,  0},  /* 6 */
       
   740              { OP_MemIncr,      1,  0,  0},
       
   741              { OP_String8,      0,  0,  "wrong # of entries in index "},
       
   742              { OP_String8,      0,  0,  0},  /* 9 */
       
   743              { OP_Concat,       0,  0,  0},
       
   744              { OP_Callback,     1,  0,  0},
       
   745           };
       
   746           if( pIdx->tnum==0 ) continue;
       
   747           addr = sqlite3VdbeAddOpList(v, ArraySize(cntIdx), cntIdx);
       
   748           sqlite3VdbeChangeP1(v, addr+1, j+2);
       
   749           sqlite3VdbeChangeP2(v, addr+1, addr+4);
       
   750           sqlite3VdbeChangeP1(v, addr+3, j+2);
       
   751           sqlite3VdbeChangeP2(v, addr+3, addr+2);
       
   752           sqlite3VdbeJumpHere(v, addr+6);
       
   753           sqlite3VdbeChangeP3(v, addr+9, pIdx->zName, P3_STATIC);
       
   754         }
       
   755       } 
       
   756     }
       
   757     addr = sqlite3VdbeAddOpList(v, ArraySize(endCode), endCode);
       
   758     sqlite3VdbeJumpHere(v, addr+2);
       
   759   }else
       
   760 #endif /* SQLITE_OMIT_INTEGRITY_CHECK */
       
   761 
       
   762 #ifndef SQLITE_OMIT_UTF16
       
   763   /*
       
   764   **   PRAGMA encoding
       
   765   **   PRAGMA encoding = "utf-8"|"utf-16"|"utf-16le"|"utf-16be"
       
   766   **
       
   767   ** In it's first form, this pragma returns the encoding of the main
       
   768   ** database. If the database is not initialized, it is initialized now.
       
   769   **
       
   770   ** The second form of this pragma is a no-op if the main database file
       
   771   ** has not already been initialized. In this case it sets the default
       
   772   ** encoding that will be used for the main database file if a new file
       
   773   ** is created. If an existing main database file is opened, then the
       
   774   ** default text encoding for the existing database is used.
       
   775   ** 
       
   776   ** In all cases new databases created using the ATTACH command are
       
   777   ** created to use the same default text encoding as the main database. If
       
   778   ** the main database has not been initialized and/or created when ATTACH
       
   779   ** is executed, this is done before the ATTACH operation.
       
   780   **
       
   781   ** In the second form this pragma sets the text encoding to be used in
       
   782   ** new database files created using this database handle. It is only
       
   783   ** useful if invoked immediately after the main database i
       
   784   */
       
   785   if( sqlite3StrICmp(zLeft, "encoding")==0 ){
       
   786     static const struct EncName {
       
   787       char *zName;
       
   788       u8 enc;
       
   789     } encnames[] = {
       
   790       { "UTF-8",    SQLITE_UTF8        },
       
   791       { "UTF8",     SQLITE_UTF8        },
       
   792       { "UTF-16le", SQLITE_UTF16LE     },
       
   793       { "UTF16le",  SQLITE_UTF16LE     },
       
   794       { "UTF-16be", SQLITE_UTF16BE     },
       
   795       { "UTF16be",  SQLITE_UTF16BE     },
       
   796       { "UTF-16",   0                  }, /* SQLITE_UTF16NATIVE */
       
   797       { "UTF16",    0                  }, /* SQLITE_UTF16NATIVE */
       
   798       { 0, 0 }
       
   799     };
       
   800     const struct EncName *pEnc;
       
   801     if( !zRight ){    /* "PRAGMA encoding" */
       
   802       if( sqlite3ReadSchema(pParse) ) goto pragma_out;
       
   803       sqlite3VdbeSetNumCols(v, 1);
       
   804       sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "encoding", P3_STATIC);
       
   805       sqlite3VdbeAddOp(v, OP_String8, 0, 0);
       
   806       for(pEnc=&encnames[0]; pEnc->zName; pEnc++){
       
   807         if( pEnc->enc==ENC(pParse->db) ){
       
   808           sqlite3VdbeChangeP3(v, -1, pEnc->zName, P3_STATIC);
       
   809           break;
       
   810         }
       
   811       }
       
   812       sqlite3VdbeAddOp(v, OP_Callback, 1, 0);
       
   813     }else{                        /* "PRAGMA encoding = XXX" */
       
   814       /* Only change the value of sqlite.enc if the database handle is not
       
   815       ** initialized. If the main database exists, the new sqlite.enc value
       
   816       ** will be overwritten when the schema is next loaded. If it does not
       
   817       ** already exists, it will be created to use the new encoding value.
       
   818       */
       
   819       if( 
       
   820         !(DbHasProperty(db, 0, DB_SchemaLoaded)) || 
       
   821         DbHasProperty(db, 0, DB_Empty) 
       
   822       ){
       
   823         for(pEnc=&encnames[0]; pEnc->zName; pEnc++){
       
   824           if( 0==sqlite3StrICmp(zRight, pEnc->zName) ){
       
   825             ENC(pParse->db) = pEnc->enc ? pEnc->enc : SQLITE_UTF16NATIVE;
       
   826             break;
       
   827           }
       
   828         }
       
   829         if( !pEnc->zName ){
       
   830           sqlite3ErrorMsg(pParse, "unsupported encoding: %s", zRight);
       
   831         }
       
   832       }
       
   833     }
       
   834   }else
       
   835 #endif /* SQLITE_OMIT_UTF16 */
       
   836 
       
   837 #ifndef SQLITE_OMIT_SCHEMA_VERSION_PRAGMAS
       
   838   /*
       
   839   **   PRAGMA [database.]schema_version
       
   840   **   PRAGMA [database.]schema_version = <integer>
       
   841   **
       
   842   **   PRAGMA [database.]user_version
       
   843   **   PRAGMA [database.]user_version = <integer>
       
   844   **
       
   845   ** The pragma's schema_version and user_version are used to set or get
       
   846   ** the value of the schema-version and user-version, respectively. Both
       
   847   ** the schema-version and the user-version are 32-bit signed integers
       
   848   ** stored in the database header.
       
   849   **
       
   850   ** The schema-cookie is usually only manipulated internally by SQLite. It
       
   851   ** is incremented by SQLite whenever the database schema is modified (by
       
   852   ** creating or dropping a table or index). The schema version is used by
       
   853   ** SQLite each time a query is executed to ensure that the internal cache
       
   854   ** of the schema used when compiling the SQL query matches the schema of
       
   855   ** the database against which the compiled query is actually executed.
       
   856   ** Subverting this mechanism by using "PRAGMA schema_version" to modify
       
   857   ** the schema-version is potentially dangerous and may lead to program
       
   858   ** crashes or database corruption. Use with caution!
       
   859   **
       
   860   ** The user-version is not used internally by SQLite. It may be used by
       
   861   ** applications for any purpose.
       
   862   */
       
   863   if( sqlite3StrICmp(zLeft, "schema_version")==0 ||
       
   864       sqlite3StrICmp(zLeft, "user_version")==0 ){
       
   865 
       
   866     int iCookie;   /* Cookie index. 0 for schema-cookie, 6 for user-cookie. */
       
   867     if( zLeft[0]=='s' || zLeft[0]=='S' ){
       
   868       iCookie = 0;
       
   869     }else{
       
   870       iCookie = 5;
       
   871     }
       
   872 
       
   873     if( zRight ){
       
   874       /* Write the specified cookie value */
       
   875       static const VdbeOpList setCookie[] = {
       
   876         { OP_Transaction,    0,  1,  0},    /* 0 */
       
   877         { OP_Integer,        0,  0,  0},    /* 1 */
       
   878         { OP_SetCookie,      0,  0,  0},    /* 2 */
       
   879       };
       
   880       int addr = sqlite3VdbeAddOpList(v, ArraySize(setCookie), setCookie);
       
   881       sqlite3VdbeChangeP1(v, addr, iDb);
       
   882       sqlite3VdbeChangeP1(v, addr+1, atoi(zRight));
       
   883       sqlite3VdbeChangeP1(v, addr+2, iDb);
       
   884       sqlite3VdbeChangeP2(v, addr+2, iCookie);
       
   885     }else{
       
   886       /* Read the specified cookie value */
       
   887       static const VdbeOpList readCookie[] = {
       
   888         { OP_ReadCookie,      0,  0,  0},    /* 0 */
       
   889         { OP_Callback,        1,  0,  0}
       
   890       };
       
   891       int addr = sqlite3VdbeAddOpList(v, ArraySize(readCookie), readCookie);
       
   892       sqlite3VdbeChangeP1(v, addr, iDb);
       
   893       sqlite3VdbeChangeP2(v, addr, iCookie);
       
   894       sqlite3VdbeSetNumCols(v, 1);
       
   895     }
       
   896   }
       
   897 #endif /* SQLITE_OMIT_SCHEMA_VERSION_PRAGMAS */
       
   898 
       
   899 #if defined(SQLITE_DEBUG) || defined(SQLITE_TEST)
       
   900   /*
       
   901   ** Report the current state of file logs for all databases
       
   902   */
       
   903   if( sqlite3StrICmp(zLeft, "lock_status")==0 ){
       
   904     static const char *const azLockName[] = {
       
   905       "unlocked", "shared", "reserved", "pending", "exclusive"
       
   906     };
       
   907     int i;
       
   908     Vdbe *v = sqlite3GetVdbe(pParse);
       
   909     sqlite3VdbeSetNumCols(v, 2);
       
   910     sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "database", P3_STATIC);
       
   911     sqlite3VdbeSetColName(v, 1, COLNAME_NAME, "status", P3_STATIC);
       
   912     for(i=0; i<db->nDb; i++){
       
   913       Btree *pBt;
       
   914       Pager *pPager;
       
   915       if( db->aDb[i].zName==0 ) continue;
       
   916       sqlite3VdbeOp3(v, OP_String8, 0, 0, db->aDb[i].zName, P3_STATIC);
       
   917       pBt = db->aDb[i].pBt;
       
   918       if( pBt==0 || (pPager = sqlite3BtreePager(pBt))==0 ){
       
   919         sqlite3VdbeOp3(v, OP_String8, 0, 0, "closed", P3_STATIC);
       
   920       }else{
       
   921         int j = sqlite3pager_lockstate(pPager);
       
   922         sqlite3VdbeOp3(v, OP_String8, 0, 0, 
       
   923             (j>=0 && j<=4) ? azLockName[j] : "unknown", P3_STATIC);
       
   924       }
       
   925       sqlite3VdbeAddOp(v, OP_Callback, 2, 0);
       
   926     }
       
   927   }else
       
   928 #endif
       
   929 
       
   930 #ifdef SQLITE_SSE
       
   931   /*
       
   932   ** Check to see if the sqlite_statements table exists.  Create it
       
   933   ** if it does not.
       
   934   */
       
   935   if( sqlite3StrICmp(zLeft, "create_sqlite_statement_table")==0 ){
       
   936     extern int sqlite3CreateStatementsTable(Parse*);
       
   937     sqlite3CreateStatementsTable(pParse);
       
   938   }else
       
   939 #endif
       
   940 
       
   941 #if SQLITE_HAS_CODEC
       
   942   if( sqlite3StrICmp(zLeft, "key")==0 ){
       
   943     sqlite3_key(db, zRight, strlen(zRight));
       
   944   }else
       
   945 #endif
       
   946 
       
   947   {}
       
   948 
       
   949   if( v ){
       
   950     /* Code an OP_Expire at the end of each PRAGMA program to cause
       
   951     ** the VDBE implementing the pragma to expire. Most (all?) pragmas
       
   952     ** are only valid for a single execution.
       
   953     */
       
   954     sqlite3VdbeAddOp(v, OP_Expire, 1, 0);
       
   955 
       
   956     /*
       
   957     ** Reset the safety level, in case the fullfsync flag or synchronous
       
   958     ** setting changed.
       
   959     */
       
   960 #ifndef SQLITE_OMIT_PAGER_PRAGMAS
       
   961     if( db->autoCommit ){
       
   962       sqlite3BtreeSetSafetyLevel(pDb->pBt, pDb->safety_level,
       
   963                  (db->flags&SQLITE_FullFSync)!=0);
       
   964     }
       
   965 #endif
       
   966   }
       
   967 pragma_out:
       
   968   sqliteFree(zLeft);
       
   969   sqliteFree(zRight);
       
   970 }
       
   971 
       
   972 #endif /* SQLITE_OMIT_PRAGMA || SQLITE_OMIT_PARSER */