PHP  
 PHP: Test and Code Coverage Analysis
downloads | QA | documentation | faq | getting help | mailing lists | reporting bugs | php.net sites | links | my php.net 
 

LTP GCOV extension - code coverage report
Current view: directory - pdo_sqlite/sqlite/src - pragma.c
Test: PHP Code Coverage
Date: 2009-11-19 Instrumented lines: 379
Code covered: 0.0 % Executed lines: 0
Legend: not executed executed

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

Generated by: LTP GCOV extension version 1.5

Generated at Thu, 19 Nov 2009 08:20:17 +0000 (5 days ago)

Copyright © 2005-2009 The PHP Group
All rights reserved.