/ Check-in [870c030b]
Login

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

Overview
Comment:Change the PRAGMA parser to use a binary search for the pragma name. Also: Minor performance enhancement to sqlite3DbFree() and to the token dequoter.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 870c030b4e1854e6e0d39907fadbd82774c16f56
User & Date: drh 2013-09-13 16:36:46
Context
2013-09-13
16:56
Enhance the pragma lookup table generator script to output a comment that gives the number of pragmas. check-in: ca052050 user: drh tags: trunk
16:36
Change the PRAGMA parser to use a binary search for the pragma name. Also: Minor performance enhancement to sqlite3DbFree() and to the token dequoter. check-in: 870c030b user: drh tags: trunk
12:10
Add tests for the fts4 unicode61 tokenchars and separators options. check-in: 9ce6f40d user: dan tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/malloc.c.

   480    480   
   481    481   /*
   482    482   ** Free memory that might be associated with a particular database
   483    483   ** connection.
   484    484   */
   485    485   void sqlite3DbFree(sqlite3 *db, void *p){
   486    486     assert( db==0 || sqlite3_mutex_held(db->mutex) );
          487  +  if( p==0 ) return;
   487    488     if( db ){
   488    489       if( db->pnBytesFreed ){
   489    490         *db->pnBytesFreed += sqlite3DbMallocSize(db, p);
   490    491         return;
   491    492       }
   492    493       if( isLookaside(db, p) ){
   493    494         LookasideSlot *pBuf = (LookasideSlot*)p;

Changes to src/pragma.c.

     9      9   **    May you share freely, never taking more than you give.
    10     10   **
    11     11   *************************************************************************
    12     12   ** This file contains code used to implement the PRAGMA command.
    13     13   */
    14     14   #include "sqliteInt.h"
    15     15   
           16  +#if !defined(SQLITE_ENABLE_LOCKING_STYLE)
           17  +#  if defined(__APPLE__)
           18  +#    define SQLITE_ENABLE_LOCKING_STYLE 1
           19  +#  else
           20  +#    define SQLITE_ENABLE_LOCKING_STYLE 0
           21  +#  endif
           22  +#endif
           23  +
           24  +/***************************************************************************
           25  +** The next block of code, including the PragTyp_XXXX macro definitions and
           26  +** the aPragmaName[] object is composed of generated code. DO NOT EDIT.
           27  +**
           28  +** To add new pragmas, edit the code in ../tool/mkpragmatab.tcl and rerun
           29  +** that script.  Then copy/paste the output in place of the following:
           30  +*/
           31  +#define PragTyp_HEADER_VALUE                   0
           32  +#define PragTyp_AUTO_VACUUM                    1
           33  +#define PragTyp_FLAG                           2
           34  +#define PragTyp_BUSY_TIMEOUT                   3
           35  +#define PragTyp_CACHE_SIZE                     4
           36  +#define PragTyp_CASE_SENSITIVE_LIKE            5
           37  +#define PragTyp_COLLATION_LIST                 6
           38  +#define PragTyp_COMPILE_OPTIONS                7
           39  +#define PragTyp_DATA_STORE_DIRECTORY           8
           40  +#define PragTyp_DATABASE_LIST                  9
           41  +#define PragTyp_DEFAULT_CACHE_SIZE            10
           42  +#define PragTyp_ENCODING                      11
           43  +#define PragTyp_FOREIGN_KEY_CHECK             12
           44  +#define PragTyp_FOREIGN_KEY_LIST              13
           45  +#define PragTyp_INCREMENTAL_VACUUM            14
           46  +#define PragTyp_INDEX_INFO                    15
           47  +#define PragTyp_INDEX_LIST                    16
           48  +#define PragTyp_INTEGRITY_CHECK               17
           49  +#define PragTyp_JOURNAL_MODE                  18
           50  +#define PragTyp_JOURNAL_SIZE_LIMIT            19
           51  +#define PragTyp_LOCK_PROXY_FILE               20
           52  +#define PragTyp_LOCKING_MODE                  21
           53  +#define PragTyp_PAGE_COUNT                    22
           54  +#define PragTyp_MMAP_SIZE                     23
           55  +#define PragTyp_PAGE_SIZE                     24
           56  +#define PragTyp_SECURE_DELETE                 25
           57  +#define PragTyp_SHRINK_MEMORY                 26
           58  +#define PragTyp_SYNCHRONOUS                   27
           59  +#define PragTyp_TABLE_INFO                    28
           60  +#define PragTyp_TEMP_STORE                    29
           61  +#define PragTyp_TEMP_STORE_DIRECTORY          30
           62  +#define PragTyp_WAL_AUTOCHECKPOINT            31
           63  +#define PragTyp_WAL_CHECKPOINT                32
           64  +#define PragTyp_ACTIVATE_EXTENSIONS           33
           65  +#define PragTyp_HEXKEY                        34
           66  +#define PragTyp_KEY                           35
           67  +#define PragTyp_REKEY                         36
           68  +#define PragTyp_LOCK_STATUS                   37
           69  +#define PragTyp_PARSER_TRACE                  38
           70  +static const struct sPragmaNames {
           71  +  const char const *zName;  /* Name of pragma */
           72  +  int ePragTyp;             /* PragTyp_XXX value */
           73  +  u32 iArg;                 /* Extra argument */
           74  +} aPragmaNames[] = {
           75  +#if defined(SQLITE_HAS_CODEC) || defined(SQLITE_ENABLE_CEROD)
           76  +  { "activate_extensions",     PragTyp_ACTIVATE_EXTENSIONS,    0 },
           77  +#endif
           78  +#if !defined(SQLITE_OMIT_SCHEMA_VERSION_PRAGMAS)
           79  +  { "application_id",          PragTyp_HEADER_VALUE,           0 },
           80  +#endif
           81  +#if !defined(SQLITE_OMIT_AUTOVACUUM)
           82  +  { "auto_vacuum",             PragTyp_AUTO_VACUUM,            0 },
           83  +#endif
           84  +#if !defined(SQLITE_OMIT_AUTOMATIC_INDEX)
           85  +  { "automatic_index",         PragTyp_FLAG,                  
           86  +                               SQLITE_AutoIndex },
           87  +#endif
           88  +  { "busy_timeout",            PragTyp_BUSY_TIMEOUT,           0 },
           89  +#if !defined(SQLITE_OMIT_PAGER_PRAGMAS)
           90  +  { "cache_size",              PragTyp_CACHE_SIZE,             0 },
           91  +#endif
           92  +  { "cache_spill",             PragTyp_FLAG,                  
           93  +                               SQLITE_CacheSpill },
           94  +  { "case_sensitive_like",     PragTyp_CASE_SENSITIVE_LIKE,    0 },
           95  +  { "checkpoint_fullfsync",    PragTyp_FLAG,                  
           96  +                               SQLITE_CkptFullFSync },
           97  +#if !defined(SQLITE_OMIT_SCHEMA_PRAGMAS)
           98  +  { "collation_list",          PragTyp_COLLATION_LIST,         0 },
           99  +#endif
          100  +#if !defined(SQLITE_OMIT_COMPILEOPTION_DIAGS)
          101  +  { "compile_options",         PragTyp_COMPILE_OPTIONS,        0 },
          102  +#endif
          103  +  { "count_changes",           PragTyp_FLAG,                  
          104  +                               SQLITE_CountRows },
          105  +#if !defined(SQLITE_OMIT_PAGER_PRAGMAS) && SQLITE_OS_WIN
          106  +  { "data_store_directory",    PragTyp_DATA_STORE_DIRECTORY,   0 },
          107  +#endif
          108  +#if !defined(SQLITE_OMIT_SCHEMA_PRAGMAS)
          109  +  { "database_list",           PragTyp_DATABASE_LIST,          0 },
          110  +#endif
          111  +#if !defined(SQLITE_OMIT_PAGER_PRAGMAS) && !defined(SQLITE_OMIT_DEPRECATED)
          112  +  { "default_cache_size",      PragTyp_DEFAULT_CACHE_SIZE,     0 },
          113  +#endif
          114  +#if !defined(SQLITE_OMIT_FOREIGN_KEY) && !defined(SQLITE_OMIT_TRIGGER)
          115  +  { "defer_foreign_keys",      PragTyp_FLAG,                  
          116  +                               SQLITE_DeferFKs },
          117  +#endif
          118  +  { "empty_result_callbacks",  PragTyp_FLAG,                  
          119  +                               SQLITE_NullCallback },
          120  +#if !defined(SQLITE_OMIT_UTF16)
          121  +  { "encoding",                PragTyp_ENCODING,               0 },
          122  +#endif
          123  +#if !defined(SQLITE_OMIT_FOREIGN_KEY) && !defined(SQLITE_OMIT_TRIGGER)
          124  +  { "foreign_key_check",       PragTyp_FOREIGN_KEY_CHECK,      0 },
          125  +#endif
          126  +#if !defined(SQLITE_OMIT_FOREIGN_KEY)
          127  +  { "foreign_key_list",        PragTyp_FOREIGN_KEY_LIST,       0 },
          128  +#endif
          129  +#if !defined(SQLITE_OMIT_FOREIGN_KEY) && !defined(SQLITE_OMIT_TRIGGER)
          130  +  { "foreign_keys",            PragTyp_FLAG,                  
          131  +                               SQLITE_ForeignKeys },
          132  +#endif
          133  +#if !defined(SQLITE_OMIT_SCHEMA_VERSION_PRAGMAS)
          134  +  { "freelist_count",          PragTyp_HEADER_VALUE,           0 },
          135  +#endif
          136  +  { "full_column_names",       PragTyp_FLAG,                  
          137  +                               SQLITE_FullColNames },
          138  +  { "fullfsync",               PragTyp_FLAG,                  
          139  +                               SQLITE_FullFSync },
          140  +#if defined(SQLITE_HAS_CODEC)
          141  +  { "hexkey",                  PragTyp_HEXKEY,                 0 },
          142  +#endif
          143  +#if !defined(SQLITE_OMIT_CHECK)
          144  +  { "ignore_check_constraints", PragTyp_FLAG,                  
          145  +                               SQLITE_IgnoreChecks },
          146  +#endif
          147  +#if !defined(SQLITE_OMIT_AUTOVACUUM)
          148  +  { "incremental_vacuum",      PragTyp_INCREMENTAL_VACUUM,     0 },
          149  +#endif
          150  +#if !defined(SQLITE_OMIT_SCHEMA_PRAGMAS)
          151  +  { "index_info",              PragTyp_INDEX_INFO,             0 },
          152  +  { "index_list",              PragTyp_INDEX_LIST,             0 },
          153  +#endif
          154  +#if !defined(SQLITE_OMIT_INTEGRITY_CHECK)
          155  +  { "integrity_check",         PragTyp_INTEGRITY_CHECK,        0 },
          156  +#endif
          157  +#if !defined(SQLITE_OMIT_PAGER_PRAGMAS)
          158  +  { "journal_mode",            PragTyp_JOURNAL_MODE,           0 },
          159  +  { "journal_size_limit",      PragTyp_JOURNAL_SIZE_LIMIT,     0 },
          160  +#endif
          161  +#if defined(SQLITE_HAS_CODEC)
          162  +  { "key",                     PragTyp_KEY,                    0 },
          163  +#endif
          164  +  { "legacy_file_format",      PragTyp_FLAG,                  
          165  +                               SQLITE_LegacyFileFmt },
          166  +#if !defined(SQLITE_OMIT_PAGER_PRAGMAS) && SQLITE_ENABLE_LOCKING_STYLE
          167  +  { "lock_proxy_file",         PragTyp_LOCK_PROXY_FILE,        0 },
          168  +#endif
          169  +#if defined(SQLITE_DEBUG) || defined(SQLITE_TEST)
          170  +  { "lock_status",             PragTyp_LOCK_STATUS,            0 },
          171  +#endif
          172  +#if !defined(SQLITE_OMIT_PAGER_PRAGMAS)
          173  +  { "locking_mode",            PragTyp_LOCKING_MODE,           0 },
          174  +  { "max_page_count",          PragTyp_PAGE_COUNT,             0 },
          175  +  { "mmap_size",               PragTyp_MMAP_SIZE,              0 },
          176  +  { "page_count",              PragTyp_PAGE_COUNT,             0 },
          177  +  { "page_size",               PragTyp_PAGE_SIZE,              0 },
          178  +#endif
          179  +#if defined(SQLITE_DEBUG)
          180  +  { "parser_trace",            PragTyp_PARSER_TRACE,           0 },
          181  +#endif
          182  +  { "query_only",              PragTyp_FLAG,                  
          183  +                               SQLITE_QueryOnly },
          184  +#if !defined(SQLITE_OMIT_INTEGRITY_CHECK)
          185  +  { "quick_check",             PragTyp_INTEGRITY_CHECK,        0 },
          186  +#endif
          187  +  { "read_uncommitted",        PragTyp_FLAG,                  
          188  +                               SQLITE_ReadUncommitted },
          189  +  { "recursive_triggers",      PragTyp_FLAG,                  
          190  +                               SQLITE_RecTriggers },
          191  +#if defined(SQLITE_HAS_CODEC)
          192  +  { "rekey",                   PragTyp_REKEY,                  0 },
          193  +#endif
          194  +  { "reverse_unordered_selects", PragTyp_FLAG,                  
          195  +                               SQLITE_ReverseOrder },
          196  +#if !defined(SQLITE_OMIT_SCHEMA_VERSION_PRAGMAS)
          197  +  { "schema_version",          PragTyp_HEADER_VALUE,           0 },
          198  +#endif
          199  +#if !defined(SQLITE_OMIT_PAGER_PRAGMAS)
          200  +  { "secure_delete",           PragTyp_SECURE_DELETE,          0 },
          201  +#endif
          202  +  { "short_column_names",      PragTyp_FLAG,                  
          203  +                               SQLITE_ShortColNames },
          204  +  { "shrink_memory",           PragTyp_SHRINK_MEMORY,          0 },
          205  +#if defined(SQLITE_DEBUG)
          206  +  { "sql_trace",               PragTyp_FLAG,                  
          207  +                               SQLITE_SqlTrace },
          208  +#endif
          209  +#if !defined(SQLITE_OMIT_PAGER_PRAGMAS)
          210  +  { "synchronous",             PragTyp_SYNCHRONOUS,            0 },
          211  +#endif
          212  +#if !defined(SQLITE_OMIT_SCHEMA_PRAGMAS)
          213  +  { "table_info",              PragTyp_TABLE_INFO,             0 },
          214  +#endif
          215  +#if !defined(SQLITE_OMIT_PAGER_PRAGMAS)
          216  +  { "temp_store",              PragTyp_TEMP_STORE,             0 },
          217  +  { "temp_store_directory",    PragTyp_TEMP_STORE_DIRECTORY,   0 },
          218  +#endif
          219  +#if !defined(SQLITE_OMIT_SCHEMA_VERSION_PRAGMAS)
          220  +  { "user_version",            PragTyp_HEADER_VALUE,           0 },
          221  +#endif
          222  +#if defined(SQLITE_DEBUG)
          223  +  { "vdbe_addoptrace",         PragTyp_FLAG,                  
          224  +                               SQLITE_VdbeAddopTrace },
          225  +  { "vdbe_debug",              PragTyp_FLAG,                  
          226  +                               SQLITE_SqlTrace|SQLITE_VdbeListing|SQLITE_VdbeTrace },
          227  +  { "vdbe_listing",            PragTyp_FLAG,                  
          228  +                               SQLITE_VdbeListing },
          229  +  { "vdbe_trace",              PragTyp_FLAG,                  
          230  +                               SQLITE_VdbeTrace },
          231  +#endif
          232  +#if !defined(SQLITE_OMIT_WAL)
          233  +  { "wal_autocheckpoint",      PragTyp_WAL_AUTOCHECKPOINT,     0 },
          234  +  { "wal_checkpoint",          PragTyp_WAL_CHECKPOINT,         0 },
          235  +#endif
          236  +  { "writable_schema",         PragTyp_FLAG,                  
          237  +                               SQLITE_WriteSchema|SQLITE_RecoveryMode },
          238  +};
          239  +/* End of the automatically generated pragma table.
          240  +***************************************************************************/
          241  +
    16    242   /*
    17    243   ** Interpret the given string as a safety level.  Return 0 for OFF,
    18    244   ** 1 for ON or NORMAL and 2 for FULL.  Return 1 for an empty or 
    19    245   ** unrecognized string argument.  The FULL option is disallowed
    20    246   ** if the omitFull parameter it 1.
    21    247   **
    22    248   ** Note that the values returned are one less that the values that
................................................................................
   184    410     }
   185    411   }
   186    412   #else
   187    413   # define setAllPagerFlags(X)  /* no-op */
   188    414   #endif
   189    415   
   190    416   
   191         -#ifndef SQLITE_OMIT_FLAG_PRAGMAS
   192         -/*
   193         -** Check to see if zRight and zLeft refer to a pragma that queries
   194         -** or changes one of the flags in db->flags.  Return 1 if so and 0 if not.
   195         -** Also, implement the pragma.
   196         -*/
   197         -static int flagPragma(Parse *pParse, const char *zLeft, const char *zRight){
   198         -  static const struct sPragmaType {
   199         -    const char *zName;  /* Name of the pragma */
   200         -    int mask;           /* Mask for the db->flags value */
   201         -  } aPragma[] = {
   202         -    { "full_column_names",        SQLITE_FullColNames  },
   203         -    { "short_column_names",       SQLITE_ShortColNames },
   204         -    { "count_changes",            SQLITE_CountRows     },
   205         -    { "empty_result_callbacks",   SQLITE_NullCallback  },
   206         -    { "legacy_file_format",       SQLITE_LegacyFileFmt },
   207         -    { "fullfsync",                SQLITE_FullFSync     },
   208         -    { "checkpoint_fullfsync",     SQLITE_CkptFullFSync },
   209         -    { "cache_spill",              SQLITE_CacheSpill    },
   210         -    { "reverse_unordered_selects", SQLITE_ReverseOrder  },
   211         -    { "query_only",               SQLITE_QueryOnly     },
   212         -#ifndef SQLITE_OMIT_AUTOMATIC_INDEX
   213         -    { "automatic_index",          SQLITE_AutoIndex     },
   214         -#endif
   215         -#ifdef SQLITE_DEBUG
   216         -    { "sql_trace",                SQLITE_SqlTrace      },
   217         -    { "vdbe_listing",             SQLITE_VdbeListing   },
   218         -    { "vdbe_trace",               SQLITE_VdbeTrace     },
   219         -    { "vdbe_addoptrace",          SQLITE_VdbeAddopTrace},
   220         -    { "vdbe_debug",    SQLITE_SqlTrace | SQLITE_VdbeListing
   221         -                               | SQLITE_VdbeTrace      },
   222         -#endif
   223         -#ifndef SQLITE_OMIT_CHECK
   224         -    { "ignore_check_constraints", SQLITE_IgnoreChecks  },
   225         -#endif
   226         -    /* The following is VERY experimental */
   227         -    { "writable_schema",          SQLITE_WriteSchema|SQLITE_RecoveryMode },
   228         -
   229         -    /* TODO: Maybe it shouldn't be possible to change the ReadUncommitted
   230         -    ** flag if there are any active statements. */
   231         -    { "read_uncommitted",         SQLITE_ReadUncommitted },
   232         -    { "recursive_triggers",       SQLITE_RecTriggers   },
   233         -
   234         -    /* This flag may only be set if both foreign-key and trigger support
   235         -    ** are present in the build.  */
   236         -#if !defined(SQLITE_OMIT_FOREIGN_KEY) && !defined(SQLITE_OMIT_TRIGGER)
   237         -    { "foreign_keys",             SQLITE_ForeignKeys   },
   238         -    { "defer_foreign_keys",       SQLITE_DeferFKs      },
   239         -#endif
   240         -  };
   241         -  int i;
   242         -  const struct sPragmaType *p;
   243         -  for(i=0, p=aPragma; i<ArraySize(aPragma); i++, p++){
   244         -    if( sqlite3StrICmp(zLeft, p->zName)==0 ){
   245         -      sqlite3 *db = pParse->db;
   246         -      Vdbe *v;
   247         -      v = sqlite3GetVdbe(pParse);
   248         -      assert( v!=0 );  /* Already allocated by sqlite3Pragma() */
   249         -      if( ALWAYS(v) ){
   250         -        if( zRight==0 ){
   251         -          returnSingleInt(pParse, p->zName, (db->flags & p->mask)!=0 );
   252         -        }else{
   253         -          int mask = p->mask;          /* Mask of bits to set or clear. */
   254         -          if( db->autoCommit==0 ){
   255         -            /* Foreign key support may not be enabled or disabled while not
   256         -            ** in auto-commit mode.  */
   257         -            mask &= ~(SQLITE_ForeignKeys);
   258         -          }
   259         -
   260         -          if( sqlite3GetBoolean(zRight, 0) ){
   261         -            db->flags |= mask;
   262         -          }else{
   263         -            db->flags &= ~mask;
   264         -            if( mask==SQLITE_DeferFKs ) db->nDeferredImmCons = 0;
   265         -          }
   266         -
   267         -          /* Many of the flag-pragmas modify the code generated by the SQL 
   268         -          ** compiler (eg. count_changes). So add an opcode to expire all
   269         -          ** compiled SQL statements after modifying a pragma value.
   270         -          */
   271         -          sqlite3VdbeAddOp2(v, OP_Expire, 0, 0);
   272         -        }
   273         -      }
   274         -
   275         -      return 1;
   276         -    }
   277         -  }
   278         -  return 0;
   279         -}
   280         -#endif /* SQLITE_OMIT_FLAG_PRAGMAS */
   281         -
   282    417   /*
   283    418   ** Return a human-readable name for a constraint resolution action.
   284    419   */
   285    420   #ifndef SQLITE_OMIT_FOREIGN_KEY
   286    421   static const char *actionName(u8 action){
   287    422     const char *zName;
   288    423     switch( action ){
................................................................................
   344    479     Token *pValue,      /* Token for <value>, or NULL */
   345    480     int minusFlag       /* True if a '-' sign preceded <value> */
   346    481   ){
   347    482     char *zLeft = 0;       /* Nul-terminated UTF-8 string <id> */
   348    483     char *zRight = 0;      /* Nul-terminated UTF-8 string <value>, or NULL */
   349    484     const char *zDb = 0;   /* The database name */
   350    485     Token *pId;            /* Pointer to <id> token */
   351         -  int iDb;               /* Database index for <database> */
   352    486     char *aFcntl[4];       /* Argument to SQLITE_FCNTL_PRAGMA */
          487  +  int iDb;               /* Database index for <database> */
          488  +  int lwr, upr, mid;           /* Binary search bounds */
   353    489     int rc;                      /* return value form SQLITE_FCNTL_PRAGMA */
   354    490     sqlite3 *db = pParse->db;    /* The database connection */
   355    491     Db *pDb;                     /* The specific database being pragmaed */
   356    492     Vdbe *v = sqlite3GetVdbe(pParse);  /* Prepared statement */
   357    493   
   358    494     if( v==0 ) return;
   359    495     sqlite3VdbeRunOnlyOnce(v);
................................................................................
   401    537         int mem = ++pParse->nMem;
   402    538         sqlite3VdbeAddOp4(v, OP_String8, 0, mem, 0, aFcntl[0], 0);
   403    539         sqlite3VdbeSetNumCols(v, 1);
   404    540         sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "result", SQLITE_STATIC);
   405    541         sqlite3VdbeAddOp2(v, OP_ResultRow, mem, 1);
   406    542         sqlite3_free(aFcntl[0]);
   407    543       }
   408         -  }else if( rc!=SQLITE_NOTFOUND ){
          544  +    goto pragma_out;
          545  +  }
          546  +  if( rc!=SQLITE_NOTFOUND ){
   409    547       if( aFcntl[0] ){
   410    548         sqlite3ErrorMsg(pParse, "%s", aFcntl[0]);
   411    549         sqlite3_free(aFcntl[0]);
   412    550       }
   413    551       pParse->nErr++;
   414    552       pParse->rc = rc;
   415         -  }else
   416         -                            
   417         - 
          553  +    goto pragma_out;
          554  +  }
          555  +
          556  +  /* Locate the pragma in the lookup table */
          557  +  lwr = 0;
          558  +  upr = ArraySize(aPragmaNames)-1;
          559  +  while( lwr<=upr ){
          560  +    mid = (lwr+upr)/2;
          561  +    rc = sqlite3_stricmp(zLeft, aPragmaNames[mid].zName);
          562  +    if( rc==0 ) break;
          563  +    if( rc<0 ){
          564  +      upr = mid - 1;
          565  +    }else{
          566  +      lwr = mid + 1;
          567  +    }
          568  +  }
          569  +  if( lwr>upr ) goto pragma_out;
          570  +
          571  +  /* Jump to the appropriate pragma handler */
          572  +  switch( aPragmaNames[mid].ePragTyp ){
          573  +  
   418    574   #if !defined(SQLITE_OMIT_PAGER_PRAGMAS) && !defined(SQLITE_OMIT_DEPRECATED)
   419    575     /*
   420    576     **  PRAGMA [database.]default_cache_size
   421    577     **  PRAGMA [database.]default_cache_size=N
   422    578     **
   423    579     ** The first form reports the current persistent setting for the
   424    580     ** page cache size.  The value returned is the maximum number of
................................................................................
   428    584     **
   429    585     ** Older versions of SQLite would set the default cache size to a
   430    586     ** negative number to indicate synchronous=OFF.  These days, synchronous
   431    587     ** is always on by default regardless of the sign of the default cache
   432    588     ** size.  But continue to take the absolute value of the default cache
   433    589     ** size of historical compatibility.
   434    590     */
   435         -  if( sqlite3StrICmp(zLeft,"default_cache_size")==0 ){
          591  +  case PragTyp_DEFAULT_CACHE_SIZE: {
   436    592       static const VdbeOpList getCacheSize[] = {
   437    593         { OP_Transaction, 0, 0,        0},                         /* 0 */
   438    594         { OP_ReadCookie,  0, 1,        BTREE_DEFAULT_CACHE_SIZE},  /* 1 */
   439    595         { OP_IfPos,       1, 8,        0},
   440    596         { OP_Integer,     0, 2,        0},
   441    597         { OP_Subtract,    1, 2,        1},
   442    598         { OP_IfPos,       1, 8,        0},
................................................................................
   460    616         sqlite3BeginWriteOperation(pParse, 0, iDb);
   461    617         sqlite3VdbeAddOp2(v, OP_Integer, size, 1);
   462    618         sqlite3VdbeAddOp3(v, OP_SetCookie, iDb, BTREE_DEFAULT_CACHE_SIZE, 1);
   463    619         assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
   464    620         pDb->pSchema->cache_size = size;
   465    621         sqlite3BtreeSetCacheSize(pDb->pBt, pDb->pSchema->cache_size);
   466    622       }
   467         -  }else
          623  +    break;
          624  +  }
   468    625   #endif /* !SQLITE_OMIT_PAGER_PRAGMAS && !SQLITE_OMIT_DEPRECATED */
   469    626   
   470    627   #if !defined(SQLITE_OMIT_PAGER_PRAGMAS)
   471    628     /*
   472    629     **  PRAGMA [database.]page_size
   473    630     **  PRAGMA [database.]page_size=N
   474    631     **
   475    632     ** The first form reports the current setting for the
   476    633     ** database page size in bytes.  The second form sets the
   477    634     ** database page size value.  The value can only be set if
   478    635     ** the database has not yet been created.
   479    636     */
   480         -  if( sqlite3StrICmp(zLeft,"page_size")==0 ){
          637  +  case PragTyp_PAGE_SIZE: {
   481    638       Btree *pBt = pDb->pBt;
   482    639       assert( pBt!=0 );
   483    640       if( !zRight ){
   484    641         int size = ALWAYS(pBt) ? sqlite3BtreeGetPageSize(pBt) : 0;
   485    642         returnSingleInt(pParse, "page_size", size);
   486    643       }else{
   487    644         /* Malloc may fail when setting the page-size, as there is an internal
................................................................................
   488    645         ** buffer that the pager module resizes using sqlite3_realloc().
   489    646         */
   490    647         db->nextPagesize = sqlite3Atoi(zRight);
   491    648         if( SQLITE_NOMEM==sqlite3BtreeSetPageSize(pBt, db->nextPagesize,-1,0) ){
   492    649           db->mallocFailed = 1;
   493    650         }
   494    651       }
   495         -  }else
          652  +    break;
          653  +  }
   496    654   
   497    655     /*
   498    656     **  PRAGMA [database.]secure_delete
   499    657     **  PRAGMA [database.]secure_delete=ON/OFF
   500    658     **
   501    659     ** The first form reports the current setting for the
   502    660     ** secure_delete flag.  The second form changes the secure_delete
   503    661     ** flag setting and reports thenew value.
   504    662     */
   505         -  if( sqlite3StrICmp(zLeft,"secure_delete")==0 ){
          663  +  case PragTyp_SECURE_DELETE: {
   506    664       Btree *pBt = pDb->pBt;
   507    665       int b = -1;
   508    666       assert( pBt!=0 );
   509    667       if( zRight ){
   510    668         b = sqlite3GetBoolean(zRight, 0);
   511    669       }
   512    670       if( pId2->n==0 && b>=0 ){
................................................................................
   513    671         int ii;
   514    672         for(ii=0; ii<db->nDb; ii++){
   515    673           sqlite3BtreeSecureDelete(db->aDb[ii].pBt, b);
   516    674         }
   517    675       }
   518    676       b = sqlite3BtreeSecureDelete(pBt, b);
   519    677       returnSingleInt(pParse, "secure_delete", b);
   520         -  }else
          678  +    break;
          679  +  }
   521    680   
   522    681     /*
   523    682     **  PRAGMA [database.]max_page_count
   524    683     **  PRAGMA [database.]max_page_count=N
   525    684     **
   526    685     ** The first form reports the current setting for the
   527    686     ** maximum number of pages in the database file.  The 
................................................................................
   532    691     ** change.  The only purpose is to provide an easy way to test
   533    692     ** the sqlite3AbsInt32() function.
   534    693     **
   535    694     **  PRAGMA [database.]page_count
   536    695     **
   537    696     ** Return the number of pages in the specified database.
   538    697     */
   539         -  if( sqlite3StrICmp(zLeft,"page_count")==0
   540         -   || sqlite3StrICmp(zLeft,"max_page_count")==0
   541         -  ){
          698  +  case PragTyp_PAGE_COUNT: {
   542    699       int iReg;
   543    700       if( sqlite3ReadSchema(pParse) ) goto pragma_out;
   544    701       sqlite3CodeVerifySchema(pParse, iDb);
   545    702       iReg = ++pParse->nMem;
   546    703       if( sqlite3Tolower(zLeft[0])=='p' ){
   547    704         sqlite3VdbeAddOp2(v, OP_Pagecount, iDb, iReg);
   548    705       }else{
   549    706         sqlite3VdbeAddOp3(v, OP_MaxPgcnt, iDb, iReg, 
   550    707                           sqlite3AbsInt32(sqlite3Atoi(zRight)));
   551    708       }
   552    709       sqlite3VdbeAddOp2(v, OP_ResultRow, iReg, 1);
   553    710       sqlite3VdbeSetNumCols(v, 1);
   554    711       sqlite3VdbeSetColName(v, 0, COLNAME_NAME, zLeft, SQLITE_TRANSIENT);
   555         -  }else
          712  +    break;
          713  +  }
   556    714   
   557    715     /*
   558    716     **  PRAGMA [database.]locking_mode
   559    717     **  PRAGMA [database.]locking_mode = (normal|exclusive)
   560    718     */
   561         -  if( sqlite3StrICmp(zLeft,"locking_mode")==0 ){
          719  +  case PragTyp_LOCKING_MODE: {
   562    720       const char *zRet = "normal";
   563    721       int eMode = getLockingMode(zRight);
   564    722   
   565    723       if( pId2->n==0 && eMode==PAGER_LOCKINGMODE_QUERY ){
   566    724         /* Simple "PRAGMA locking_mode;" statement. This is a query for
   567    725         ** the current default locking mode (which may be different to
   568    726         ** the locking-mode of the main database).
................................................................................
   587    745           }
   588    746           db->dfltLockMode = (u8)eMode;
   589    747         }
   590    748         pPager = sqlite3BtreePager(pDb->pBt);
   591    749         eMode = sqlite3PagerLockingMode(pPager, eMode);
   592    750       }
   593    751   
   594         -    assert(eMode==PAGER_LOCKINGMODE_NORMAL||eMode==PAGER_LOCKINGMODE_EXCLUSIVE);
          752  +    assert( eMode==PAGER_LOCKINGMODE_NORMAL
          753  +            || eMode==PAGER_LOCKINGMODE_EXCLUSIVE );
   595    754       if( eMode==PAGER_LOCKINGMODE_EXCLUSIVE ){
   596    755         zRet = "exclusive";
   597    756       }
   598    757       sqlite3VdbeSetNumCols(v, 1);
   599    758       sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "locking_mode", SQLITE_STATIC);
   600    759       sqlite3VdbeAddOp4(v, OP_String8, 0, 1, 0, zRet, 0);
   601    760       sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 1);
   602         -  }else
          761  +    break;
          762  +  }
   603    763   
   604    764     /*
   605    765     **  PRAGMA [database.]journal_mode
   606    766     **  PRAGMA [database.]journal_mode =
   607    767     **                      (delete|persist|off|truncate|memory|wal|off)
   608    768     */
   609         -  if( sqlite3StrICmp(zLeft,"journal_mode")==0 ){
          769  +  case PragTyp_JOURNAL_MODE: {
   610    770       int eMode;        /* One of the PAGER_JOURNALMODE_XXX symbols */
   611    771       int ii;           /* Loop counter */
   612    772   
   613    773       /* Force the schema to be loaded on all databases.  This causes all
   614    774       ** database files to be opened and the journal_modes set.  This is
   615    775       ** necessary because subsequent processing must know if the databases
   616    776       ** are in WAL mode. */
................................................................................
   645    805       for(ii=db->nDb-1; ii>=0; ii--){
   646    806         if( db->aDb[ii].pBt && (ii==iDb || pId2->n==0) ){
   647    807           sqlite3VdbeUsesBtree(v, ii);
   648    808           sqlite3VdbeAddOp3(v, OP_JournalMode, ii, 1, eMode);
   649    809         }
   650    810       }
   651    811       sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 1);
   652         -  }else
          812  +    break;
          813  +  }
   653    814   
   654    815     /*
   655    816     **  PRAGMA [database.]journal_size_limit
   656    817     **  PRAGMA [database.]journal_size_limit=N
   657    818     **
   658    819     ** Get or set the size limit on rollback journal files.
   659    820     */
   660         -  if( sqlite3StrICmp(zLeft,"journal_size_limit")==0 ){
          821  +  case PragTyp_JOURNAL_SIZE_LIMIT: {
   661    822       Pager *pPager = sqlite3BtreePager(pDb->pBt);
   662    823       i64 iLimit = -2;
   663    824       if( zRight ){
   664    825         sqlite3Atoi64(zRight, &iLimit, sqlite3Strlen30(zRight), SQLITE_UTF8);
   665    826         if( iLimit<-1 ) iLimit = -1;
   666    827       }
   667    828       iLimit = sqlite3PagerJournalSizeLimit(pPager, iLimit);
   668    829       returnSingleInt(pParse, "journal_size_limit", iLimit);
   669         -  }else
          830  +    break;
          831  +  }
   670    832   
   671    833   #endif /* SQLITE_OMIT_PAGER_PRAGMAS */
   672    834   
   673    835     /*
   674    836     **  PRAGMA [database.]auto_vacuum
   675    837     **  PRAGMA [database.]auto_vacuum=N
   676    838     **
   677    839     ** Get or set the value of the database 'auto-vacuum' parameter.
   678    840     ** The value is one of:  0 NONE 1 FULL 2 INCREMENTAL
   679    841     */
   680    842   #ifndef SQLITE_OMIT_AUTOVACUUM
   681         -  if( sqlite3StrICmp(zLeft,"auto_vacuum")==0 ){
          843  +  case PragTyp_AUTO_VACUUM: {
   682    844       Btree *pBt = pDb->pBt;
   683    845       assert( pBt!=0 );
   684    846       if( sqlite3ReadSchema(pParse) ){
   685    847         goto pragma_out;
   686    848       }
   687    849       if( !zRight ){
   688    850         int auto_vacuum;
................................................................................
   724    886             sqlite3VdbeChangeP2(v, iAddr+2, iAddr+4);
   725    887             sqlite3VdbeChangeP1(v, iAddr+4, eAuto-1);
   726    888             sqlite3VdbeChangeP1(v, iAddr+5, iDb);
   727    889             sqlite3VdbeUsesBtree(v, iDb);
   728    890           }
   729    891         }
   730    892       }
   731         -  }else
          893  +    break;
          894  +  }
   732    895   #endif
   733    896   
   734    897     /*
   735    898     **  PRAGMA [database.]incremental_vacuum(N)
   736    899     **
   737    900     ** Do N steps of incremental vacuuming on a database.
   738    901     */
   739    902   #ifndef SQLITE_OMIT_AUTOVACUUM
   740         -  if( sqlite3StrICmp(zLeft,"incremental_vacuum")==0 ){
          903  +  case PragTyp_INCREMENTAL_VACUUM: {
   741    904       int iLimit, addr;
   742    905       if( sqlite3ReadSchema(pParse) ){
   743    906         goto pragma_out;
   744    907       }
   745    908       if( zRight==0 || !sqlite3GetInt32(zRight, &iLimit) || iLimit<=0 ){
   746    909         iLimit = 0x7fffffff;
   747    910       }
................................................................................
   748    911       sqlite3BeginWriteOperation(pParse, 0, iDb);
   749    912       sqlite3VdbeAddOp2(v, OP_Integer, iLimit, 1);
   750    913       addr = sqlite3VdbeAddOp1(v, OP_IncrVacuum, iDb);
   751    914       sqlite3VdbeAddOp1(v, OP_ResultRow, 1);
   752    915       sqlite3VdbeAddOp2(v, OP_AddImm, 1, -1);
   753    916       sqlite3VdbeAddOp2(v, OP_IfPos, 1, addr);
   754    917       sqlite3VdbeJumpHere(v, addr);
   755         -  }else
          918  +    break;
          919  +  }
   756    920   #endif
   757    921   
   758    922   #ifndef SQLITE_OMIT_PAGER_PRAGMAS
   759    923     /*
   760    924     **  PRAGMA [database.]cache_size
   761    925     **  PRAGMA [database.]cache_size=N
   762    926     **
................................................................................
   763    927     ** The first form reports the current local setting for the
   764    928     ** page cache size. The second form sets the local
   765    929     ** page cache size value.  If N is positive then that is the
   766    930     ** number of pages in the cache.  If N is negative, then the
   767    931     ** number of pages is adjusted so that the cache uses -N kibibytes
   768    932     ** of memory.
   769    933     */
   770         -  if( sqlite3StrICmp(zLeft,"cache_size")==0 ){
          934  +  case PragTyp_CACHE_SIZE: {
   771    935       if( sqlite3ReadSchema(pParse) ) goto pragma_out;
   772    936       assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
   773    937       if( !zRight ){
   774    938         returnSingleInt(pParse, "cache_size", pDb->pSchema->cache_size);
   775    939       }else{
   776    940         int size = sqlite3Atoi(zRight);
   777    941         pDb->pSchema->cache_size = size;
   778    942         sqlite3BtreeSetCacheSize(pDb->pBt, pDb->pSchema->cache_size);
   779    943       }
   780         -  }else
          944  +    break;
          945  +  }
   781    946   
   782    947     /*
   783    948     **  PRAGMA [database.]mmap_size(N)
   784    949     **
   785    950     ** Used to set mapping size limit. The mapping size limit is
   786    951     ** used to limit the aggregate size of all memory mapped regions of the
   787    952     ** database file. If this parameter is set to zero, then memory mapping
................................................................................
   789    954     ** limit determined by sqlite3_config(SQLITE_CONFIG_MMAP_SIZE) is set.
   790    955     ** The parameter N is measured in bytes.
   791    956     **
   792    957     ** This value is advisory.  The underlying VFS is free to memory map
   793    958     ** as little or as much as it wants.  Except, if N is set to 0 then the
   794    959     ** upper layers will never invoke the xFetch interfaces to the VFS.
   795    960     */
   796         -  if( sqlite3StrICmp(zLeft,"mmap_size")==0 ){
          961  +  case PragTyp_MMAP_SIZE: {
   797    962       sqlite3_int64 sz;
   798    963   #if SQLITE_MAX_MMAP_SIZE>0
   799    964       assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
   800    965       if( zRight ){
   801    966         int ii;
   802    967         sqlite3Atoi64(zRight, &sz, sqlite3Strlen30(zRight), SQLITE_UTF8);
   803    968         if( sz<0 ) sz = sqlite3GlobalConfig.szMmap;
................................................................................
   816    981   #endif
   817    982       if( rc==SQLITE_OK ){
   818    983         returnSingleInt(pParse, "mmap_size", sz);
   819    984       }else if( rc!=SQLITE_NOTFOUND ){
   820    985         pParse->nErr++;
   821    986         pParse->rc = rc;
   822    987       }
   823         -  }else
          988  +    break;
          989  +  }
   824    990   
   825    991     /*
   826    992     **   PRAGMA temp_store
   827    993     **   PRAGMA temp_store = "default"|"memory"|"file"
   828    994     **
   829    995     ** Return or set the local value of the temp_store flag.  Changing
   830    996     ** the local value does not make changes to the disk file and the default
   831    997     ** value will be restored the next time the database is opened.
   832    998     **
   833    999     ** Note that it is possible for the library compile-time options to
   834   1000     ** override this setting
   835   1001     */
   836         -  if( sqlite3StrICmp(zLeft, "temp_store")==0 ){
         1002  +  case PragTyp_TEMP_STORE: {
   837   1003       if( !zRight ){
   838   1004         returnSingleInt(pParse, "temp_store", db->temp_store);
   839   1005       }else{
   840   1006         changeTempStorage(pParse, zRight);
   841   1007       }
   842         -  }else
         1008  +    break;
         1009  +  }
   843   1010   
   844   1011     /*
   845   1012     **   PRAGMA temp_store_directory
   846   1013     **   PRAGMA temp_store_directory = ""|"directory_name"
   847   1014     **
   848   1015     ** Return or set the local value of the temp_store_directory flag.  Changing
   849   1016     ** the value sets a specific directory to be used for temporary files.
   850   1017     ** Setting to a null string reverts to the default temporary directory search.
   851   1018     ** If temporary directory is changed, then invalidateTempStorage.
   852   1019     **
   853   1020     */
   854         -  if( sqlite3StrICmp(zLeft, "temp_store_directory")==0 ){
         1021  +  case PragTyp_TEMP_STORE_DIRECTORY: {
   855   1022       if( !zRight ){
   856   1023         if( sqlite3_temp_directory ){
   857   1024           sqlite3VdbeSetNumCols(v, 1);
   858   1025           sqlite3VdbeSetColName(v, 0, COLNAME_NAME, 
   859   1026               "temp_store_directory", SQLITE_STATIC);
   860   1027           sqlite3VdbeAddOp4(v, OP_String8, 0, 1, 0, sqlite3_temp_directory, 0);
   861   1028           sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 1);
................................................................................
   880   1047         if( zRight[0] ){
   881   1048           sqlite3_temp_directory = sqlite3_mprintf("%s", zRight);
   882   1049         }else{
   883   1050           sqlite3_temp_directory = 0;
   884   1051         }
   885   1052   #endif /* SQLITE_OMIT_WSD */
   886   1053       }
   887         -  }else
         1054  +    break;
         1055  +  }
   888   1056   
   889   1057   #if SQLITE_OS_WIN
   890   1058     /*
   891   1059     **   PRAGMA data_store_directory
   892   1060     **   PRAGMA data_store_directory = ""|"directory_name"
   893   1061     **
   894   1062     ** Return or set the local value of the data_store_directory flag.  Changing
................................................................................
   896   1064     ** were specified with a relative pathname.  Setting to a null string reverts
   897   1065     ** to the default database directory, which for database files specified with
   898   1066     ** a relative path will probably be based on the current directory for the
   899   1067     ** process.  Database file specified with an absolute path are not impacted
   900   1068     ** by this setting, regardless of its value.
   901   1069     **
   902   1070     */
   903         -  if( sqlite3StrICmp(zLeft, "data_store_directory")==0 ){
         1071  +  case PragTyp_DATA_STORE_DIRECTORY: {
   904   1072       if( !zRight ){
   905   1073         if( sqlite3_data_directory ){
   906   1074           sqlite3VdbeSetNumCols(v, 1);
   907   1075           sqlite3VdbeSetColName(v, 0, COLNAME_NAME, 
   908   1076               "data_store_directory", SQLITE_STATIC);
   909   1077           sqlite3VdbeAddOp4(v, OP_String8, 0, 1, 0, sqlite3_data_directory, 0);
   910   1078           sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 1);
................................................................................
   923   1091         if( zRight[0] ){
   924   1092           sqlite3_data_directory = sqlite3_mprintf("%s", zRight);
   925   1093         }else{
   926   1094           sqlite3_data_directory = 0;
   927   1095         }
   928   1096   #endif /* SQLITE_OMIT_WSD */
   929   1097       }
   930         -  }else
         1098  +    break;
         1099  +  }
   931   1100   #endif
   932   1101   
   933         -#if !defined(SQLITE_ENABLE_LOCKING_STYLE)
   934         -#  if defined(__APPLE__)
   935         -#    define SQLITE_ENABLE_LOCKING_STYLE 1
   936         -#  else
   937         -#    define SQLITE_ENABLE_LOCKING_STYLE 0
   938         -#  endif
   939         -#endif
   940   1102   #if SQLITE_ENABLE_LOCKING_STYLE
   941   1103     /*
   942         -   **   PRAGMA [database.]lock_proxy_file
   943         -   **   PRAGMA [database.]lock_proxy_file = ":auto:"|"lock_file_path"
   944         -   **
   945         -   ** Return or set the value of the lock_proxy_file flag.  Changing
   946         -   ** the value sets a specific file to be used for database access locks.
   947         -   **
   948         -   */
   949         -  if( sqlite3StrICmp(zLeft, "lock_proxy_file")==0 ){
         1104  +  **   PRAGMA [database.]lock_proxy_file
         1105  +  **   PRAGMA [database.]lock_proxy_file = ":auto:"|"lock_file_path"
         1106  +  **
         1107  +  ** Return or set the value of the lock_proxy_file flag.  Changing
         1108  +  ** the value sets a specific file to be used for database access locks.
         1109  +  **
         1110  +  */
         1111  +  case PragTyp_LOCK_PROXY_FILE: {
   950   1112       if( !zRight ){
   951   1113         Pager *pPager = sqlite3BtreePager(pDb->pBt);
   952   1114         char *proxy_file_path = NULL;
   953   1115         sqlite3_file *pFile = sqlite3PagerFile(pPager);
   954   1116         sqlite3OsFileControlHint(pFile, SQLITE_GET_LOCKPROXYFILE, 
   955   1117                              &proxy_file_path);
   956   1118         
................................................................................
   973   1135                                        NULL);
   974   1136         }
   975   1137         if( res!=SQLITE_OK ){
   976   1138           sqlite3ErrorMsg(pParse, "failed to set lock proxy file");
   977   1139           goto pragma_out;
   978   1140         }
   979   1141       }
   980         -  }else
         1142  +    break;
         1143  +  }
   981   1144   #endif /* SQLITE_ENABLE_LOCKING_STYLE */      
   982   1145       
   983   1146     /*
   984   1147     **   PRAGMA [database.]synchronous
   985   1148     **   PRAGMA [database.]synchronous=OFF|ON|NORMAL|FULL
   986   1149     **
   987   1150     ** Return or set the local value of the synchronous flag.  Changing
   988   1151     ** the local value does not make changes to the disk file and the
   989   1152     ** default value will be restored the next time the database is
   990   1153     ** opened.
   991   1154     */
   992         -  if( sqlite3StrICmp(zLeft,"synchronous")==0 ){
         1155  +  case PragTyp_SYNCHRONOUS: {
   993   1156       if( sqlite3ReadSchema(pParse) ) goto pragma_out;
   994   1157       if( !zRight ){
   995   1158         returnSingleInt(pParse, "synchronous", pDb->safety_level-1);
   996   1159       }else{
   997   1160         if( !db->autoCommit ){
   998   1161           sqlite3ErrorMsg(pParse, 
   999   1162               "Safety level may not be changed inside a transaction");
  1000   1163         }else{
  1001   1164           pDb->safety_level = getSafetyLevel(zRight,0,1)+1;
  1002   1165           setAllPagerFlags(db);
  1003   1166         }
  1004   1167       }
  1005         -  }else
         1168  +    break;
         1169  +  }
  1006   1170   #endif /* SQLITE_OMIT_PAGER_PRAGMAS */
  1007   1171   
  1008   1172   #ifndef SQLITE_OMIT_FLAG_PRAGMAS
  1009         -  if( flagPragma(pParse, zLeft, zRight) ){
  1010         -    setAllPagerFlags(db);
  1011         -  }else
         1173  +  case PragTyp_FLAG: {
         1174  +    if( zRight==0 ){
         1175  +      returnSingleInt(pParse, aPragmaNames[mid].zName,
         1176  +                     (db->flags & aPragmaNames[mid].iArg)!=0 );
         1177  +    }else{
         1178  +      int mask = aPragmaNames[mid].iArg;    /* Mask of bits to set or clear. */
         1179  +      if( db->autoCommit==0 ){
         1180  +        /* Foreign key support may not be enabled or disabled while not
         1181  +        ** in auto-commit mode.  */
         1182  +        mask &= ~(SQLITE_ForeignKeys);
         1183  +      }
         1184  +
         1185  +      if( sqlite3GetBoolean(zRight, 0) ){
         1186  +        db->flags |= mask;
         1187  +      }else{
         1188  +        db->flags &= ~mask;
         1189  +        if( mask==SQLITE_DeferFKs ) db->nDeferredImmCons = 0;
         1190  +      }
         1191  +
         1192  +      /* Many of the flag-pragmas modify the code generated by the SQL 
         1193  +      ** compiler (eg. count_changes). So add an opcode to expire all
         1194  +      ** compiled SQL statements after modifying a pragma value.
         1195  +      */
         1196  +      sqlite3VdbeAddOp2(v, OP_Expire, 0, 0);
         1197  +      setAllPagerFlags(db);
         1198  +    }
         1199  +    break;
         1200  +  }
  1012   1201   #endif /* SQLITE_OMIT_FLAG_PRAGMAS */
  1013   1202   
  1014   1203   #ifndef SQLITE_OMIT_SCHEMA_PRAGMAS
  1015   1204     /*
  1016   1205     **   PRAGMA table_info(<table>)
  1017   1206     **
  1018   1207     ** Return a single row for each column of the named table. The columns of
................................................................................
  1020   1209     **
  1021   1210     ** cid:        Column id (numbered from left to right, starting at 0)
  1022   1211     ** name:       Column name
  1023   1212     ** type:       Column declaration type.
  1024   1213     ** notnull:    True if 'NOT NULL' is part of column declaration
  1025   1214     ** dflt_value: The default value for the column, if any.
  1026   1215     */
  1027         -  if( sqlite3StrICmp(zLeft, "table_info")==0 && zRight ){
         1216  +  case PragTyp_TABLE_INFO: if( zRight ){
  1028   1217       Table *pTab;
  1029   1218       if( sqlite3ReadSchema(pParse) ) goto pragma_out;
  1030   1219       pTab = sqlite3FindTable(db, zRight, zDb);
  1031   1220       if( pTab ){
  1032   1221         int i, k;
  1033   1222         int nHidden = 0;
  1034   1223         Column *pCol;
................................................................................
  1066   1255           }else{
  1067   1256             for(k=1; ALWAYS(k<=pTab->nCol) && pPk->aiColumn[k-1]!=i; k++){}
  1068   1257           }
  1069   1258           sqlite3VdbeAddOp2(v, OP_Integer, k, 6);
  1070   1259           sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 6);
  1071   1260         }
  1072   1261       }
  1073         -  }else
         1262  +  }
         1263  +  break;
  1074   1264   
  1075         -  if( sqlite3StrICmp(zLeft, "index_info")==0 && zRight ){
         1265  +  case PragTyp_INDEX_INFO: if( zRight ){
  1076   1266       Index *pIdx;
  1077   1267       Table *pTab;
  1078   1268       if( sqlite3ReadSchema(pParse) ) goto pragma_out;
  1079   1269       pIdx = sqlite3FindIndex(db, zRight, zDb);
  1080   1270       if( pIdx ){
  1081   1271         int i;
  1082   1272         pTab = pIdx->pTable;
................................................................................
  1091   1281           sqlite3VdbeAddOp2(v, OP_Integer, i, 1);
  1092   1282           sqlite3VdbeAddOp2(v, OP_Integer, cnum, 2);
  1093   1283           assert( pTab->nCol>cnum );
  1094   1284           sqlite3VdbeAddOp4(v, OP_String8, 0, 3, 0, pTab->aCol[cnum].zName, 0);
  1095   1285           sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 3);
  1096   1286         }
  1097   1287       }
  1098         -  }else
         1288  +  }
         1289  +  break;
  1099   1290   
  1100         -  if( sqlite3StrICmp(zLeft, "index_list")==0 && zRight ){
         1291  +  case PragTyp_INDEX_LIST: if( zRight ){
  1101   1292       Index *pIdx;
  1102   1293       Table *pTab;
  1103   1294       if( sqlite3ReadSchema(pParse) ) goto pragma_out;
  1104   1295       pTab = sqlite3FindTable(db, zRight, zDb);
  1105   1296       if( pTab ){
  1106   1297         v = sqlite3GetVdbe(pParse);
  1107   1298         pIdx = pTab->pIndex;
................................................................................
  1119   1310             sqlite3VdbeAddOp2(v, OP_Integer, pIdx->onError!=OE_None, 3);
  1120   1311             sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 3);
  1121   1312             ++i;
  1122   1313             pIdx = pIdx->pNext;
  1123   1314           }
  1124   1315         }
  1125   1316       }
  1126         -  }else
         1317  +  }
         1318  +  break;
  1127   1319   
  1128         -  if( sqlite3StrICmp(zLeft, "database_list")==0 ){
         1320  +  case PragTyp_DATABASE_LIST: {
  1129   1321       int i;
  1130   1322       if( sqlite3ReadSchema(pParse) ) goto pragma_out;
  1131   1323       sqlite3VdbeSetNumCols(v, 3);
  1132   1324       pParse->nMem = 3;
  1133   1325       sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "seq", SQLITE_STATIC);
  1134   1326       sqlite3VdbeSetColName(v, 1, COLNAME_NAME, "name", SQLITE_STATIC);
  1135   1327       sqlite3VdbeSetColName(v, 2, COLNAME_NAME, "file", SQLITE_STATIC);
................................................................................
  1138   1330         assert( db->aDb[i].zName!=0 );
  1139   1331         sqlite3VdbeAddOp2(v, OP_Integer, i, 1);
  1140   1332         sqlite3VdbeAddOp4(v, OP_String8, 0, 2, 0, db->aDb[i].zName, 0);
  1141   1333         sqlite3VdbeAddOp4(v, OP_String8, 0, 3, 0,
  1142   1334              sqlite3BtreeGetFilename(db->aDb[i].pBt), 0);
  1143   1335         sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 3);
  1144   1336       }
  1145         -  }else
         1337  +  }
         1338  +  break;
  1146   1339   
  1147         -  if( sqlite3StrICmp(zLeft, "collation_list")==0 ){
         1340  +  case PragTyp_COLLATION_LIST: {
  1148   1341       int i = 0;
  1149   1342       HashElem *p;
  1150   1343       sqlite3VdbeSetNumCols(v, 2);
  1151   1344       pParse->nMem = 2;
  1152   1345       sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "seq", SQLITE_STATIC);
  1153   1346       sqlite3VdbeSetColName(v, 1, COLNAME_NAME, "name", SQLITE_STATIC);
  1154   1347       for(p=sqliteHashFirst(&db->aCollSeq); p; p=sqliteHashNext(p)){
  1155   1348         CollSeq *pColl = (CollSeq *)sqliteHashData(p);
  1156   1349         sqlite3VdbeAddOp2(v, OP_Integer, i++, 1);
  1157   1350         sqlite3VdbeAddOp4(v, OP_String8, 0, 2, 0, pColl->zName, 0);
  1158   1351         sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 2);
  1159   1352       }
  1160         -  }else
         1353  +  }
         1354  +  break;
  1161   1355   #endif /* SQLITE_OMIT_SCHEMA_PRAGMAS */
  1162   1356   
  1163   1357   #ifndef SQLITE_OMIT_FOREIGN_KEY
  1164         -  if( sqlite3StrICmp(zLeft, "foreign_key_list")==0 && zRight ){
         1358  +  case PragTyp_FOREIGN_KEY_LIST: if( zRight ){
  1165   1359       FKey *pFK;
  1166   1360       Table *pTab;
  1167   1361       if( sqlite3ReadSchema(pParse) ) goto pragma_out;
  1168   1362       pTab = sqlite3FindTable(db, zRight, zDb);
  1169   1363       if( pTab ){
  1170   1364         v = sqlite3GetVdbe(pParse);
  1171   1365         pFK = pTab->pFKey;
................................................................................
  1200   1394               sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 8);
  1201   1395             }
  1202   1396             ++i;
  1203   1397             pFK = pFK->pNextFrom;
  1204   1398           }
  1205   1399         }
  1206   1400       }
  1207         -  }else
         1401  +  }
         1402  +  break;
  1208   1403   #endif /* !defined(SQLITE_OMIT_FOREIGN_KEY) */
  1209   1404   
  1210   1405   #ifndef SQLITE_OMIT_FOREIGN_KEY
  1211   1406   #ifndef SQLITE_OMIT_TRIGGER
  1212         -  if( sqlite3StrICmp(zLeft, "foreign_key_check")==0 ){
         1407  +  case PragTyp_FOREIGN_KEY_CHECK: {
  1213   1408       FKey *pFK;             /* A foreign key constraint */
  1214   1409       Table *pTab;           /* Child table contain "REFERENCES" keyword */
  1215   1410       Table *pParent;        /* Parent table that child points to */
  1216   1411       Index *pIdx;           /* Index in the parent table */
  1217   1412       int i;                 /* Loop counter:  Foreign key number for pTab */
  1218   1413       int j;                 /* Loop counter:  Field of the foreign key */
  1219   1414       HashElem *k;           /* Loop counter:  Next table in schema */
................................................................................
  1315   1510           sqlite3VdbeAddOp2(v, OP_ResultRow, regResult, 4);
  1316   1511           sqlite3VdbeResolveLabel(v, addrOk);
  1317   1512           sqlite3DbFree(db, aiCols);
  1318   1513         }
  1319   1514         sqlite3VdbeAddOp2(v, OP_Next, 0, addrTop+1);
  1320   1515         sqlite3VdbeJumpHere(v, addrTop);
  1321   1516       }
  1322         -  }else
         1517  +  }
         1518  +  break;
  1323   1519   #endif /* !defined(SQLITE_OMIT_TRIGGER) */
  1324   1520   #endif /* !defined(SQLITE_OMIT_FOREIGN_KEY) */
  1325   1521   
  1326   1522   #ifndef NDEBUG
  1327         -  if( sqlite3StrICmp(zLeft, "parser_trace")==0 ){
         1523  +  case PragTyp_PARSER_TRACE: {
  1328   1524       if( zRight ){
  1329   1525         if( sqlite3GetBoolean(zRight, 0) ){
  1330   1526           sqlite3ParserTrace(stderr, "parser: ");
  1331   1527         }else{
  1332   1528           sqlite3ParserTrace(0, 0);
  1333   1529         }
  1334   1530       }
  1335         -  }else
         1531  +  }
         1532  +  break;
  1336   1533   #endif
  1337   1534   
  1338   1535     /* Reinstall the LIKE and GLOB functions.  The variant of LIKE
  1339   1536     ** used will be case sensitive or not depending on the RHS.
  1340   1537     */
  1341         -  if( sqlite3StrICmp(zLeft, "case_sensitive_like")==0 ){
         1538  +  case PragTyp_CASE_SENSITIVE_LIKE: {
  1342   1539       if( zRight ){
  1343   1540         sqlite3RegisterLikeFunctions(db, sqlite3GetBoolean(zRight, 0));
  1344   1541       }
  1345         -  }else
         1542  +  }
         1543  +  break;
  1346   1544   
  1347   1545   #ifndef SQLITE_INTEGRITY_CHECK_ERROR_MAX
  1348   1546   # define SQLITE_INTEGRITY_CHECK_ERROR_MAX 100
  1349   1547   #endif
  1350   1548   
  1351   1549   #ifndef SQLITE_OMIT_INTEGRITY_CHECK
  1352   1550     /* Pragma "quick_check" is reduced version of 
  1353   1551     ** integrity_check designed to detect most database corruption
  1354   1552     ** without most of the overhead of a full integrity-check.
  1355   1553     */
  1356         -  if( sqlite3StrICmp(zLeft, "integrity_check")==0
  1357         -   || sqlite3StrICmp(zLeft, "quick_check")==0 
  1358         -  ){
         1554  +  case PragTyp_INTEGRITY_CHECK: {
  1359   1555       int i, j, addr, mxErr;
  1360   1556   
  1361   1557       /* Code that appears at the end of the integrity check.  If no error
  1362   1558       ** messages have been generated, output OK.  Otherwise output the
  1363   1559       ** error message
  1364   1560       */
  1365   1561       static const VdbeOpList endCode[] = {
................................................................................
  1511   1707   #endif /* SQLITE_OMIT_BTREECOUNT */
  1512   1708         } 
  1513   1709       }
  1514   1710       addr = sqlite3VdbeAddOpList(v, ArraySize(endCode), endCode);
  1515   1711       sqlite3VdbeChangeP2(v, addr, -mxErr);
  1516   1712       sqlite3VdbeJumpHere(v, addr+1);
  1517   1713       sqlite3VdbeChangeP4(v, addr+2, "ok", P4_STATIC);
  1518         -  }else
         1714  +  }
         1715  +  break;
  1519   1716   #endif /* SQLITE_OMIT_INTEGRITY_CHECK */
  1520   1717   
  1521   1718   #ifndef SQLITE_OMIT_UTF16
  1522   1719     /*
  1523   1720     **   PRAGMA encoding
  1524   1721     **   PRAGMA encoding = "utf-8"|"utf-16"|"utf-16le"|"utf-16be"
  1525   1722     **
................................................................................
  1537   1734     ** the main database has not been initialized and/or created when ATTACH
  1538   1735     ** is executed, this is done before the ATTACH operation.
  1539   1736     **
  1540   1737     ** In the second form this pragma sets the text encoding to be used in
  1541   1738     ** new database files created using this database handle. It is only
  1542   1739     ** useful if invoked immediately after the main database i
  1543   1740     */
  1544         -  if( sqlite3StrICmp(zLeft, "encoding")==0 ){
         1741  +  case PragTyp_ENCODING: {
  1545   1742       static const struct EncName {
  1546   1743         char *zName;
  1547   1744         u8 enc;
  1548   1745       } encnames[] = {
  1549   1746         { "UTF8",     SQLITE_UTF8        },
  1550   1747         { "UTF-8",    SQLITE_UTF8        },  /* Must be element [1] */
  1551   1748         { "UTF-16le", SQLITE_UTF16LE     },  /* Must be element [2] */
................................................................................
  1584   1781             }
  1585   1782           }
  1586   1783           if( !pEnc->zName ){
  1587   1784             sqlite3ErrorMsg(pParse, "unsupported encoding: %s", zRight);
  1588   1785           }
  1589   1786         }
  1590   1787       }
  1591         -  }else
         1788  +  }
         1789  +  break;
  1592   1790   #endif /* SQLITE_OMIT_UTF16 */
  1593   1791   
  1594   1792   #ifndef SQLITE_OMIT_SCHEMA_VERSION_PRAGMAS
  1595   1793     /*
  1596   1794     **   PRAGMA [database.]schema_version
  1597   1795     **   PRAGMA [database.]schema_version = <integer>
  1598   1796     **
................................................................................
  1618   1816     ** Subverting this mechanism by using "PRAGMA schema_version" to modify
  1619   1817     ** the schema-version is potentially dangerous and may lead to program
  1620   1818     ** crashes or database corruption. Use with caution!
  1621   1819     **
  1622   1820     ** The user-version is not used internally by SQLite. It may be used by
  1623   1821     ** applications for any purpose.
  1624   1822     */
  1625         -  if( sqlite3StrICmp(zLeft, "schema_version")==0 
  1626         -   || sqlite3StrICmp(zLeft, "user_version")==0 
  1627         -   || sqlite3StrICmp(zLeft, "freelist_count")==0 
  1628         -   || sqlite3StrICmp(zLeft, "application_id")==0 
  1629         -  ){
         1823  +  case PragTyp_HEADER_VALUE: {
  1630   1824       int iCookie;   /* Cookie index. 1 for schema-cookie, 6 for user-cookie. */
  1631   1825       sqlite3VdbeUsesBtree(v, iDb);
  1632   1826       switch( zLeft[0] ){
  1633   1827         case 'a': case 'A':
  1634   1828           iCookie = BTREE_APPLICATION_ID;
  1635   1829           break;
  1636   1830         case 'f': case 'F':
................................................................................
  1666   1860         int addr = sqlite3VdbeAddOpList(v, ArraySize(readCookie), readCookie);
  1667   1861         sqlite3VdbeChangeP1(v, addr, iDb);
  1668   1862         sqlite3VdbeChangeP1(v, addr+1, iDb);
  1669   1863         sqlite3VdbeChangeP3(v, addr+1, iCookie);
  1670   1864         sqlite3VdbeSetNumCols(v, 1);
  1671   1865         sqlite3VdbeSetColName(v, 0, COLNAME_NAME, zLeft, SQLITE_TRANSIENT);
  1672   1866       }
  1673         -  }else
         1867  +  }
         1868  +  break;
  1674   1869   #endif /* SQLITE_OMIT_SCHEMA_VERSION_PRAGMAS */
  1675   1870   
  1676   1871   #ifndef SQLITE_OMIT_COMPILEOPTION_DIAGS
  1677   1872     /*
  1678   1873     **   PRAGMA compile_options
  1679   1874     **
  1680   1875     ** Return the names of all compile-time options used in this build,
  1681   1876     ** one option per row.
  1682   1877     */
  1683         -  if( sqlite3StrICmp(zLeft, "compile_options")==0 ){
         1878  +  case PragTyp_COMPILE_OPTIONS: {
  1684   1879       int i = 0;
  1685   1880       const char *zOpt;
  1686   1881       sqlite3VdbeSetNumCols(v, 1);
  1687   1882       pParse->nMem = 1;
  1688   1883       sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "compile_option", SQLITE_STATIC);
  1689   1884       while( (zOpt = sqlite3_compileoption_get(i++))!=0 ){
  1690   1885         sqlite3VdbeAddOp4(v, OP_String8, 0, 1, 0, zOpt, 0);
  1691   1886         sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 1);
  1692   1887       }
  1693         -  }else
         1888  +  }
         1889  +  break;
  1694   1890   #endif /* SQLITE_OMIT_COMPILEOPTION_DIAGS */
  1695   1891   
  1696   1892   #ifndef SQLITE_OMIT_WAL
  1697   1893     /*
  1698   1894     **   PRAGMA [database.]wal_checkpoint = passive|full|restart
  1699   1895     **
  1700   1896     ** Checkpoint the database.
  1701   1897     */
  1702         -  if( sqlite3StrICmp(zLeft, "wal_checkpoint")==0 ){
         1898  +  case PragTyp_WAL_CHECKPOINT: {
  1703   1899       int iBt = (pId2->z?iDb:SQLITE_MAX_ATTACHED);
  1704   1900       int eMode = SQLITE_CHECKPOINT_PASSIVE;
  1705   1901       if( zRight ){
  1706   1902         if( sqlite3StrICmp(zRight, "full")==0 ){
  1707   1903           eMode = SQLITE_CHECKPOINT_FULL;
  1708   1904         }else if( sqlite3StrICmp(zRight, "restart")==0 ){
  1709   1905           eMode = SQLITE_CHECKPOINT_RESTART;
................................................................................
  1714   1910       pParse->nMem = 3;
  1715   1911       sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "busy", SQLITE_STATIC);
  1716   1912       sqlite3VdbeSetColName(v, 1, COLNAME_NAME, "log", SQLITE_STATIC);
  1717   1913       sqlite3VdbeSetColName(v, 2, COLNAME_NAME, "checkpointed", SQLITE_STATIC);
  1718   1914   
  1719   1915       sqlite3VdbeAddOp3(v, OP_Checkpoint, iBt, eMode, 1);
  1720   1916       sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 3);
  1721         -  }else
         1917  +  }
         1918  +  break;
  1722   1919   
  1723   1920     /*
  1724   1921     **   PRAGMA wal_autocheckpoint
  1725   1922     **   PRAGMA wal_autocheckpoint = N
  1726   1923     **
  1727   1924     ** Configure a database connection to automatically checkpoint a database
  1728   1925     ** after accumulating N frames in the log. Or query for the current value
  1729   1926     ** of N.
  1730   1927     */
  1731         -  if( sqlite3StrICmp(zLeft, "wal_autocheckpoint")==0 ){
         1928  +  case PragTyp_WAL_AUTOCHECKPOINT: {
  1732   1929       if( zRight ){
  1733   1930         sqlite3_wal_autocheckpoint(db, sqlite3Atoi(zRight));
  1734   1931       }
  1735   1932       returnSingleInt(pParse, "wal_autocheckpoint", 
  1736   1933          db->xWalCallback==sqlite3WalDefaultHook ? 
  1737   1934              SQLITE_PTR_TO_INT(db->pWalArg) : 0);
  1738         -  }else
         1935  +  }
         1936  +  break;
  1739   1937   #endif
  1740   1938   
  1741   1939     /*
  1742   1940     **  PRAGMA shrink_memory
  1743   1941     **
  1744   1942     ** This pragma attempts to free as much memory as possible from the
  1745   1943     ** current database connection.
  1746   1944     */
  1747         -  if( sqlite3StrICmp(zLeft, "shrink_memory")==0 ){
         1945  +  case PragTyp_SHRINK_MEMORY: {
  1748   1946       sqlite3_db_release_memory(db);
  1749         -  }else
         1947  +    break;
         1948  +  }
  1750   1949   
  1751   1950     /*
  1752   1951     **   PRAGMA busy_timeout
  1753   1952     **   PRAGMA busy_timeout = N
  1754   1953     **
  1755   1954     ** Call sqlite3_busy_timeout(db, N).  Return the current timeout value
  1756   1955     ** if one is set.  If no busy handler or a different busy handler is set
  1757   1956     ** then 0 is returned.  Setting the busy_timeout to 0 or negative
  1758   1957     ** disables the timeout.
  1759   1958     */
  1760         -  if( sqlite3StrICmp(zLeft, "busy_timeout")==0 ){
         1959  +  case PragTyp_BUSY_TIMEOUT: {
  1761   1960       if( zRight ){
  1762   1961         sqlite3_busy_timeout(db, sqlite3Atoi(zRight));
  1763   1962       }
  1764   1963       returnSingleInt(pParse, "timeout",  db->busyTimeout);
  1765         -  }else
         1964  +    break;
         1965  +  }
  1766   1966   
  1767   1967   #if defined(SQLITE_DEBUG) || defined(SQLITE_TEST)
  1768   1968     /*
  1769   1969     ** Report the current state of file logs for all databases
  1770   1970     */
  1771         -  if( sqlite3StrICmp(zLeft, "lock_status")==0 ){
         1971  +  case PragTyp_LOCK_STATUS: {
  1772   1972       static const char *const azLockName[] = {
  1773   1973         "unlocked", "shared", "reserved", "pending", "exclusive"
  1774   1974       };
  1775   1975       int i;
  1776   1976       sqlite3VdbeSetNumCols(v, 2);
  1777   1977       pParse->nMem = 2;
  1778   1978       sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "database", SQLITE_STATIC);
................................................................................
  1789   1989         }else if( sqlite3_file_control(db, i ? db->aDb[i].zName : 0, 
  1790   1990                                        SQLITE_FCNTL_LOCKSTATE, &j)==SQLITE_OK ){
  1791   1991            zState = azLockName[j];
  1792   1992         }
  1793   1993         sqlite3VdbeAddOp4(v, OP_String8, 0, 2, 0, zState, P4_STATIC);
  1794   1994         sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 2);
  1795   1995       }
  1796         -
  1797         -  }else
         1996  +    break;
         1997  +  }
  1798   1998   #endif
  1799   1999   
  1800   2000   #ifdef SQLITE_HAS_CODEC
  1801         -  if( sqlite3StrICmp(zLeft, "key")==0 && zRight ){
  1802         -    sqlite3_key_v2(db, zDb, zRight, sqlite3Strlen30(zRight));
  1803         -  }else
  1804         -  if( sqlite3StrICmp(zLeft, "rekey")==0 && zRight ){
  1805         -    sqlite3_rekey_v2(db, zDb, zRight, sqlite3Strlen30(zRight));
  1806         -  }else
  1807         -  if( zRight && (sqlite3StrICmp(zLeft, "hexkey")==0 ||
  1808         -                 sqlite3StrICmp(zLeft, "hexrekey")==0) ){
  1809         -    int i, h1, h2;
  1810         -    char zKey[40];
  1811         -    for(i=0; (h1 = zRight[i])!=0 && (h2 = zRight[i+1])!=0; i+=2){
  1812         -      h1 += 9*(1&(h1>>6));
  1813         -      h2 += 9*(1&(h2>>6));
  1814         -      zKey[i/2] = (h2 & 0x0f) | ((h1 & 0xf)<<4);
         2001  +  case PragTyp_KEY: {
         2002  +    if( zRight ) sqlite3_key_v2(db, zDb, zRight, sqlite3Strlen30(zRight));
         2003  +    break;
         2004  +  }
         2005  +  case PragTyp_REKEY: {
         2006  +    if( zRight ) sqlite3_rekey_v2(db, zDb, zRight, sqlite3Strlen30(zRight));
         2007  +    break;
         2008  +  }
         2009  +  case PragTyp_HEXKEY: {
         2010  +    if( zRight ){
         2011  +      int i, h1, h2;
         2012  +      char zKey[40];
         2013  +      for(i=0; (h1 = zRight[i])!=0 && (h2 = zRight[i+1])!=0; i+=2){
         2014  +        h1 += 9*(1&(h1>>6));
         2015  +        h2 += 9*(1&(h2>>6));
         2016  +        zKey[i/2] = (h2 & 0x0f) | ((h1 & 0xf)<<4);
         2017  +      }
         2018  +      if( (zLeft[3] & 0xf)==0xb ){
         2019  +        sqlite3_key_v2(db, zDb, zKey, i/2);
         2020  +      }else{
         2021  +        sqlite3_rekey_v2(db, zDb, zKey, i/2);
         2022  +      }
  1815   2023       }
  1816         -    if( (zLeft[3] & 0xf)==0xb ){
  1817         -      sqlite3_key_v2(db, zDb, zKey, i/2);
  1818         -    }else{
  1819         -      sqlite3_rekey_v2(db, zDb, zKey, i/2);
  1820         -    }
  1821         -  }else
         2024  +    break;
         2025  +  }
  1822   2026   #endif
  1823   2027   #if defined(SQLITE_HAS_CODEC) || defined(SQLITE_ENABLE_CEROD)
  1824         -  if( sqlite3StrICmp(zLeft, "activate_extensions")==0 && zRight ){
         2028  +  case PragTyp_ACTIVATE_EXTENSIONS: if( zRight ){
  1825   2029   #ifdef SQLITE_HAS_CODEC
  1826   2030       if( sqlite3StrNICmp(zRight, "see-", 4)==0 ){
  1827   2031         sqlite3_activate_see(&zRight[4]);
  1828   2032       }
  1829   2033   #endif
  1830   2034   #ifdef SQLITE_ENABLE_CEROD
  1831   2035       if( sqlite3StrNICmp(zRight, "cerod-", 6)==0 ){
  1832   2036         sqlite3_activate_cerod(&zRight[6]);
  1833   2037       }
  1834   2038   #endif
  1835         -  }else
         2039  +  }
         2040  +  break;
  1836   2041   #endif
  1837   2042   
  1838         - 
  1839         -  {/* Empty ELSE clause */}
         2043  +  } /* End of the PRAGMA switch */
  1840   2044   
  1841   2045   pragma_out:
  1842   2046     sqlite3DbFree(db, zLeft);
  1843   2047     sqlite3DbFree(db, zRight);
  1844   2048   }
  1845   2049   
  1846   2050   #endif /* SQLITE_OMIT_PRAGMA */

Changes to src/util.c.

   189    189     switch( quote ){
   190    190       case '\'':  break;
   191    191       case '"':   break;
   192    192       case '`':   break;                /* For MySQL compatibility */
   193    193       case '[':   quote = ']';  break;  /* For MS SqlServer compatibility */
   194    194       default:    return -1;
   195    195     }
   196         -  for(i=1, j=0; ALWAYS(z[i]); i++){
          196  +  for(i=1, j=0;; i++){
          197  +    assert( z[i] );
   197    198       if( z[i]==quote ){
   198    199         if( z[i+1]==quote ){
   199    200           z[j++] = quote;
   200    201           i++;
   201    202         }else{
   202    203           break;
   203    204         }

Added tool/mkpragmatab.tcl.

            1  +#!/usr/bin/tclsh
            2  +#
            3  +# Run this script to generate the pragma name lookup table C code.
            4  +#
            5  +# To add new pragmas, first add the name and other relevant attributes
            6  +# of the pragma to the "pragma_def" object below.  Then run this script
            7  +# to generate the C-code for the lookup table and copy/paste the output
            8  +# of this script into the appropriate spot in the pragma.c source file.
            9  +# Then add the extra "case PragTyp_XXXXX:" and subsequent code for the
           10  +# new pragma.
           11  +#
           12  +
           13  +set pragma_def {
           14  +  NAME: full_column_names
           15  +  TYPE: FLAG
           16  +  ARG:  SQLITE_FullColNames
           17  +
           18  +  NAME: short_column_names
           19  +  TYPE: FLAG
           20  +  ARG:  SQLITE_ShortColNames
           21  +
           22  +  NAME: count_changes
           23  +  TYPE: FLAG
           24  +  ARG:  SQLITE_CountRows
           25  +
           26  +  NAME: empty_result_callbacks
           27  +  TYPE: FLAG
           28  +  ARG:  SQLITE_NullCallback
           29  +
           30  +  NAME: legacy_file_format
           31  +  TYPE: FLAG
           32  +  ARG:  SQLITE_LegacyFileFmt
           33  +
           34  +  NAME: fullfsync
           35  +  TYPE: FLAG
           36  +  ARG:  SQLITE_FullFSync
           37  +
           38  +  NAME: checkpoint_fullfsync
           39  +  TYPE: FLAG
           40  +  ARG:  SQLITE_CkptFullFSync
           41  +
           42  +  NAME: cache_spill
           43  +  TYPE: FLAG
           44  +  ARG:  SQLITE_CacheSpill
           45  +
           46  +  NAME: reverse_unordered_selects
           47  +  TYPE: FLAG
           48  +  ARG:  SQLITE_ReverseOrder
           49  +
           50  +  NAME: query_only
           51  +  TYPE: FLAG
           52  +  ARG:  SQLITE_QueryOnly
           53  +
           54  +  NAME: automatic_index
           55  +  TYPE: FLAG
           56  +  ARG:  SQLITE_AutoIndex
           57  +  IF:   !defined(SQLITE_OMIT_AUTOMATIC_INDEX)
           58  +
           59  +  NAME: sql_trace
           60  +  TYPE: FLAG
           61  +  ARG:  SQLITE_SqlTrace
           62  +  IF:   defined(SQLITE_DEBUG)
           63  +
           64  +  NAME: vdbe_listing
           65  +  TYPE: FLAG
           66  +  ARG:  SQLITE_VdbeListing
           67  +  IF:   defined(SQLITE_DEBUG)
           68  +
           69  +  NAME: vdbe_trace
           70  +  TYPE: FLAG
           71  +  ARG:  SQLITE_VdbeTrace
           72  +  IF:   defined(SQLITE_DEBUG)
           73  +
           74  +  NAME: vdbe_addoptrace
           75  +  TYPE: FLAG
           76  +  ARG:  SQLITE_VdbeAddopTrace
           77  +  IF:   defined(SQLITE_DEBUG)
           78  +
           79  +  NAME: vdbe_debug
           80  +  TYPE: FLAG
           81  +  ARG:  SQLITE_SqlTrace|SQLITE_VdbeListing|SQLITE_VdbeTrace
           82  +  IF:   defined(SQLITE_DEBUG)
           83  +
           84  +  NAME: ignore_check_constraints
           85  +  TYPE: FLAG
           86  +  ARG:  SQLITE_IgnoreChecks
           87  +  IF:   !defined(SQLITE_OMIT_CHECK)
           88  +
           89  +  NAME: writable_schema
           90  +  TYPE: FLAG
           91  +  ARG:  SQLITE_WriteSchema|SQLITE_RecoveryMode
           92  +
           93  +  NAME: read_uncommitted
           94  +  TYPE: FLAG
           95  +  ARG:  SQLITE_ReadUncommitted
           96  +
           97  +  NAME: recursive_triggers
           98  +  TYPE: FLAG
           99  +  ARG:  SQLITE_RecTriggers
          100  +
          101  +  NAME: foreign_keys
          102  +  TYPE: FLAG
          103  +  ARG:  SQLITE_ForeignKeys
          104  +  IF:   !defined(SQLITE_OMIT_FOREIGN_KEY) && !defined(SQLITE_OMIT_TRIGGER)
          105  +
          106  +  NAME: defer_foreign_keys
          107  +  TYPE: FLAG
          108  +  ARG:  SQLITE_DeferFKs
          109  +  IF:   !defined(SQLITE_OMIT_FOREIGN_KEY) && !defined(SQLITE_OMIT_TRIGGER)
          110  +
          111  +  NAME: default_cache_size
          112  +  IF:   !defined(SQLITE_OMIT_PAGER_PRAGMAS) && !defined(SQLITE_OMIT_DEPRECATED)
          113  +
          114  +  NAME: page_size
          115  +  IF:   !defined(SQLITE_OMIT_PAGER_PRAGMAS)
          116  +
          117  +  NAME: secure_delete
          118  +  IF:   !defined(SQLITE_OMIT_PAGER_PRAGMAS)
          119  +
          120  +  NAME: page_count
          121  +  IF:   !defined(SQLITE_OMIT_PAGER_PRAGMAS)
          122  +
          123  +  NAME: max_page_count
          124  +  TYPE: PAGE_COUNT
          125  +  IF:   !defined(SQLITE_OMIT_PAGER_PRAGMAS)
          126  +
          127  +  NAME: locking_mode
          128  +  IF:   !defined(SQLITE_OMIT_PAGER_PRAGMAS)
          129  +
          130  +  NAME: journal_mode
          131  +  IF:   !defined(SQLITE_OMIT_PAGER_PRAGMAS)
          132  +
          133  +  NAME: journal_size_limit
          134  +  IF:   !defined(SQLITE_OMIT_PAGER_PRAGMAS)
          135  +
          136  +  NAME: cache_size
          137  +  IF:   !defined(SQLITE_OMIT_PAGER_PRAGMAS)
          138  +
          139  +  NAME: mmap_size
          140  +  IF:   !defined(SQLITE_OMIT_PAGER_PRAGMAS)
          141  +
          142  +  NAME: auto_vacuum
          143  +  IF:   !defined(SQLITE_OMIT_AUTOVACUUM)
          144  +
          145  +  NAME: incremental_vacuum
          146  +  IF:   !defined(SQLITE_OMIT_AUTOVACUUM)
          147  +
          148  +  NAME: temp_store
          149  +  IF:   !defined(SQLITE_OMIT_PAGER_PRAGMAS)
          150  +
          151  +  NAME: temp_store_directory
          152  +  IF:   !defined(SQLITE_OMIT_PAGER_PRAGMAS)
          153  +
          154  +  NAME: data_store_directory
          155  +  IF:   !defined(SQLITE_OMIT_PAGER_PRAGMAS) && SQLITE_OS_WIN
          156  +
          157  +  NAME: lock_proxy_file
          158  +  IF:   !defined(SQLITE_OMIT_PAGER_PRAGMAS) && SQLITE_ENABLE_LOCKING_STYLE
          159  +
          160  +  NAME: synchronous
          161  +  IF:   !defined(SQLITE_OMIT_PAGER_PRAGMAS)
          162  +
          163  +  NAME: table_info
          164  +  IF:   !defined(SQLITE_OMIT_SCHEMA_PRAGMAS)
          165  +
          166  +  NAME: index_info
          167  +  IF:   !defined(SQLITE_OMIT_SCHEMA_PRAGMAS)
          168  +
          169  +  NAME: index_list
          170  +  IF:   !defined(SQLITE_OMIT_SCHEMA_PRAGMAS)
          171  +
          172  +  NAME: database_list
          173  +  IF:   !defined(SQLITE_OMIT_SCHEMA_PRAGMAS)
          174  +
          175  +  NAME: collation_list
          176  +  IF:   !defined(SQLITE_OMIT_SCHEMA_PRAGMAS)
          177  +
          178  +  NAME: foreign_key_list
          179  +  IF:   !defined(SQLITE_OMIT_FOREIGN_KEY)
          180  +
          181  +  NAME: foreign_key_check
          182  +  IF:   !defined(SQLITE_OMIT_FOREIGN_KEY) && !defined(SQLITE_OMIT_TRIGGER)
          183  +
          184  +  NAME: parser_trace
          185  +  IF:   defined(SQLITE_DEBUG)
          186  +
          187  +  NAME: case_sensitive_like
          188  +
          189  +  NAME: integrity_check
          190  +  IF:   !defined(SQLITE_OMIT_INTEGRITY_CHECK)
          191  +
          192  +  NAME: quick_check
          193  +  TYPE: INTEGRITY_CHECK
          194  +  IF:   !defined(SQLITE_OMIT_INTEGRITY_CHECK)
          195  +
          196  +  NAME: encoding
          197  +  IF:   !defined(SQLITE_OMIT_UTF16)
          198  +
          199  +  NAME: schema_version
          200  +  TYPE: HEADER_VALUE
          201  +  IF:   !defined(SQLITE_OMIT_SCHEMA_VERSION_PRAGMAS)
          202  +
          203  +  NAME: user_version
          204  +  TYPE: HEADER_VALUE
          205  +  IF:   !defined(SQLITE_OMIT_SCHEMA_VERSION_PRAGMAS)
          206  +
          207  +  NAME: freelist_count
          208  +  TYPE: HEADER_VALUE
          209  +  IF:   !defined(SQLITE_OMIT_SCHEMA_VERSION_PRAGMAS)
          210  +
          211  +  NAME: application_id
          212  +  TYPE: HEADER_VALUE
          213  +  IF:   !defined(SQLITE_OMIT_SCHEMA_VERSION_PRAGMAS)
          214  +
          215  +  NAME: compile_options
          216  +  IF:   !defined(SQLITE_OMIT_COMPILEOPTION_DIAGS)
          217  +
          218  +  NAME: wal_checkpoint
          219  +  IF:   !defined(SQLITE_OMIT_WAL)
          220  +
          221  +  NAME: wal_autocheckpoint
          222  +  IF:   !defined(SQLITE_OMIT_WAL)
          223  +
          224  +  NAME: shrink_memory
          225  +
          226  +  NAME: busy_timeout
          227  +
          228  +  NAME: lock_status
          229  +  IF:   defined(SQLITE_DEBUG) || defined(SQLITE_TEST)
          230  +
          231  +  NAME: key
          232  +  IF:   defined(SQLITE_HAS_CODEC)
          233  +
          234  +  NAME: rekey
          235  +  IF:   defined(SQLITE_HAS_CODEC)
          236  +
          237  +  NAME: hexkey
          238  +  IF:   defined(SQLITE_HAS_CODEC)
          239  +
          240  +  NAME: activate_extensions
          241  +  IF:   defined(SQLITE_HAS_CODEC) || defined(SQLITE_ENABLE_CEROD)
          242  +}
          243  +set name {}
          244  +set type {}
          245  +set if {}
          246  +set arg 0
          247  +proc record_one {} {
          248  +  global name type if arg allbyname typebyif
          249  +  if {$name==""} return
          250  +  set allbyname($name) [list $type $arg $if]
          251  +  set name {}
          252  +  set type {}
          253  +  set if {}
          254  +  set arg 0
          255  +}
          256  +foreach line [split $pragma_def \n] {
          257  +  set line [string trim $line]
          258  +  if {$line==""} continue
          259  +  foreach {id val} [split $line :] break
          260  +  set val [string trim $val]
          261  +  if {$id=="NAME"} {
          262  +    record_one    
          263  +    set name $val
          264  +    set type [string toupper $val]
          265  +  } elseif {$id=="TYPE"} {
          266  +    set type $val
          267  +  } elseif {$id=="ARG"} {
          268  +    set arg $val
          269  +  } elseif {$id=="IF"} {
          270  +    set if $val
          271  +  } else {
          272  +    error "bad pragma_def line: $line"
          273  +  }
          274  +}
          275  +record_one
          276  +set allnames [lsort [array names allbyname]]
          277  +
          278  +# Generate #defines for all pragma type names.  Group the pragmas that are
          279  +# omit in default builds (defined(SQLITE_DEBUG) and defined(SQLITE_HAS_CODEC))
          280  +# at the end.
          281  +#
          282  +set pnum 0
          283  +foreach name $allnames {
          284  +  set type [lindex $allbyname($name) 0]
          285  +  if {[info exists seentype($type)]} continue
          286  +  set if [lindex $allbyname($name) 2]
          287  +  if {[regexp SQLITE_DEBUG $if] || [regexp SQLITE_HAS_CODEC $if]} continue
          288  +  set seentype($type) 1
          289  +  puts [format {#define %-35s %4d} PragTyp_$type $pnum]
          290  +  incr pnum
          291  +}
          292  +foreach name $allnames {
          293  +  set type [lindex $allbyname($name) 0]
          294  +  if {[info exists seentype($type)]} continue
          295  +  set if [lindex $allbyname($name) 2]
          296  +  if {[regexp SQLITE_DEBUG $if]} continue
          297  +  set seentype($type) 1
          298  +  puts [format {#define %-35s %4d} PragTyp_$type $pnum]
          299  +  incr pnum
          300  +}
          301  +foreach name $allnames {
          302  +  set type [lindex $allbyname($name) 0]
          303  +  if {[info exists seentype($type)]} continue
          304  +  set seentype($type) 1
          305  +  puts [format {#define %-35s %4d} PragTyp_$type $pnum]
          306  +  incr pnum
          307  +}
          308  +
          309  +# Generate the lookup table
          310  +#
          311  +puts "static const struct sPragmaNames \173"
          312  +puts "  const char const *zName;  /* Name of pragma */"
          313  +puts "  int ePragTyp;             /* PragTyp_XXX value */"
          314  +puts "  u32 iArg;                 /* Extra argument */"
          315  +puts "\175 aPragmaNames\[\] = \173"
          316  +
          317  +set current_if {}
          318  +set spacer [format {    %26s } {}]
          319  +foreach name $allnames {
          320  +  foreach {type arg if} $allbyname($name) break
          321  +  if {$if!=$current_if} {
          322  +    if {$current_if!=""} {puts "#endif"}
          323  +    set current_if $if
          324  +    if {$current_if!=""} {puts "#if $current_if"}
          325  +  }
          326  +  set namex [format %-26s \"$name\",]
          327  +  set typex [format PragTyp_%-23s $type,]
          328  +  if {[string length $arg]>10} {
          329  +    puts "  \173 $namex $typex\n$spacer$arg \175,"
          330  +  } else {
          331  +    puts "  \173 $namex $typex $arg \175,"
          332  +  }
          333  +}
          334  +if {$current_if!=""} {puts "#endif"}
          335  +puts "\175;"