/ Check-in [da27a09d]
Login

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

Overview
Comment:Simplify the implementation of the "header-value" pragmas (schema_version, user_version, freelist_count, and application_id) by making them more table-driven.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1:da27a09d1d991583b59997f6cc67efa28ffd9d6a
User & Date: drh 2014-12-19 18:49:55
Context
2014-12-20
14:50
Add the "PRAGMA data_version" command for checking to see if a database has been modified. check-in: de50f25c user: drh tags: trunk
2014-12-19
22:20
Merge updates from trunk. check-in: 555fb71f user: mistachkin tags: asciiMode
19:28
Experimental "PRAGMA data_version" command for detecting when another process has changed the database file. check-in: 43db1f44 user: drh tags: data_version_pragma
18:49
Simplify the implementation of the "header-value" pragmas (schema_version, user_version, freelist_count, and application_id) by making them more table-driven. check-in: da27a09d user: drh tags: trunk
2014-12-17
15:03
Experimental opimizations to speed up FK constraint CASCADE and SET NULL action processing. check-in: 8c5dd6cc user: dan tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/pragma.c.

    67     67   #define PragTyp_ACTIVATE_EXTENSIONS           36
    68     68   #define PragTyp_HEXKEY                        37
    69     69   #define PragTyp_KEY                           38
    70     70   #define PragTyp_REKEY                         39
    71     71   #define PragTyp_LOCK_STATUS                   40
    72     72   #define PragTyp_PARSER_TRACE                  41
    73     73   #define PragFlag_NeedSchema           0x01
           74  +#define PragFlag_ReadOnly             0x02
    74     75   static const struct sPragmaNames {
    75     76     const char *const zName;  /* Name of pragma */
    76     77     u8 ePragTyp;              /* PragTyp_XXX value */
    77     78     u8 mPragFlag;             /* Zero or more PragFlag_XXX values */
    78     79     u32 iArg;                 /* Extra argument */
    79     80   } aPragmaNames[] = {
    80     81   #if defined(SQLITE_HAS_CODEC) || defined(SQLITE_ENABLE_CEROD)
................................................................................
    83     84       /* ePragFlag: */ 0,
    84     85       /* iArg:      */ 0 },
    85     86   #endif
    86     87   #if !defined(SQLITE_OMIT_SCHEMA_VERSION_PRAGMAS)
    87     88     { /* zName:     */ "application_id",
    88     89       /* ePragTyp:  */ PragTyp_HEADER_VALUE,
    89     90       /* ePragFlag: */ 0,
    90         -    /* iArg:      */ 0 },
           91  +    /* iArg:      */ BTREE_APPLICATION_ID },
    91     92   #endif
    92     93   #if !defined(SQLITE_OMIT_AUTOVACUUM)
    93     94     { /* zName:     */ "auto_vacuum",
    94     95       /* ePragTyp:  */ PragTyp_AUTO_VACUUM,
    95     96       /* ePragFlag: */ PragFlag_NeedSchema,
    96     97       /* iArg:      */ 0 },
    97     98   #endif
................................................................................
   204    205       /* ePragFlag: */ 0,
   205    206       /* iArg:      */ SQLITE_ForeignKeys },
   206    207   #endif
   207    208   #endif
   208    209   #if !defined(SQLITE_OMIT_SCHEMA_VERSION_PRAGMAS)
   209    210     { /* zName:     */ "freelist_count",
   210    211       /* ePragTyp:  */ PragTyp_HEADER_VALUE,
   211         -    /* ePragFlag: */ 0,
   212         -    /* iArg:      */ 0 },
          212  +    /* ePragFlag: */ PragFlag_ReadOnly,
          213  +    /* iArg:      */ BTREE_FREE_PAGE_COUNT },
   213    214   #endif
   214    215   #if !defined(SQLITE_OMIT_FLAG_PRAGMAS)
   215    216     { /* zName:     */ "full_column_names",
   216    217       /* ePragTyp:  */ PragTyp_FLAG,
   217    218       /* ePragFlag: */ 0,
   218    219       /* iArg:      */ SQLITE_FullColNames },
   219    220     { /* zName:     */ "fullfsync",
................................................................................
   357    358       /* ePragFlag: */ 0,
   358    359       /* iArg:      */ SQLITE_ReverseOrder },
   359    360   #endif
   360    361   #if !defined(SQLITE_OMIT_SCHEMA_VERSION_PRAGMAS)
   361    362     { /* zName:     */ "schema_version",
   362    363       /* ePragTyp:  */ PragTyp_HEADER_VALUE,
   363    364       /* ePragFlag: */ 0,
   364         -    /* iArg:      */ 0 },
          365  +    /* iArg:      */ BTREE_SCHEMA_VERSION },
   365    366   #endif
   366    367   #if !defined(SQLITE_OMIT_PAGER_PRAGMAS)
   367    368     { /* zName:     */ "secure_delete",
   368    369       /* ePragTyp:  */ PragTyp_SECURE_DELETE,
   369    370       /* ePragFlag: */ 0,
   370    371       /* iArg:      */ 0 },
   371    372   #endif
................................................................................
   423    424       /* ePragTyp:  */ PragTyp_THREADS,
   424    425       /* ePragFlag: */ 0,
   425    426       /* iArg:      */ 0 },
   426    427   #if !defined(SQLITE_OMIT_SCHEMA_VERSION_PRAGMAS)
   427    428     { /* zName:     */ "user_version",
   428    429       /* ePragTyp:  */ PragTyp_HEADER_VALUE,
   429    430       /* ePragFlag: */ 0,
   430         -    /* iArg:      */ 0 },
          431  +    /* iArg:      */ BTREE_USER_VERSION },
   431    432   #endif
   432    433   #if !defined(SQLITE_OMIT_FLAG_PRAGMAS)
   433    434   #if defined(SQLITE_DEBUG)
   434    435     { /* zName:     */ "vdbe_addoptrace",
   435    436       /* ePragTyp:  */ PragTyp_FLAG,
   436    437       /* ePragFlag: */ 0,
   437    438       /* iArg:      */ SQLITE_VdbeAddopTrace },
................................................................................
  2122   2123     ** the schema-version is potentially dangerous and may lead to program
  2123   2124     ** crashes or database corruption. Use with caution!
  2124   2125     **
  2125   2126     ** The user-version is not used internally by SQLite. It may be used by
  2126   2127     ** applications for any purpose.
  2127   2128     */
  2128   2129     case PragTyp_HEADER_VALUE: {
  2129         -    int iCookie;   /* Cookie index. 1 for schema-cookie, 6 for user-cookie. */
         2130  +    int iCookie = aPragmaNames[mid].iArg;  /* Which cookie to read or write */
  2130   2131       sqlite3VdbeUsesBtree(v, iDb);
  2131         -    switch( zLeft[0] ){
  2132         -      case 'a': case 'A':
  2133         -        iCookie = BTREE_APPLICATION_ID;
  2134         -        break;
  2135         -      case 'f': case 'F':
  2136         -        iCookie = BTREE_FREE_PAGE_COUNT;
  2137         -        break;
  2138         -      case 's': case 'S':
  2139         -        iCookie = BTREE_SCHEMA_VERSION;
  2140         -        break;
  2141         -      default:
  2142         -        iCookie = BTREE_USER_VERSION;
  2143         -        break;
  2144         -    }
  2145         -
  2146         -    if( zRight && iCookie!=BTREE_FREE_PAGE_COUNT ){
         2132  +    if( zRight && (aPragmaNames[mid].mPragFlag & PragFlag_ReadOnly)==0 ){
  2147   2133         /* Write the specified cookie value */
  2148   2134         static const VdbeOpList setCookie[] = {
  2149   2135           { OP_Transaction,    0,  1,  0},    /* 0 */
  2150   2136           { OP_Integer,        0,  1,  0},    /* 1 */
  2151   2137           { OP_SetCookie,      0,  0,  1},    /* 2 */
  2152   2138         };
  2153   2139         int addr = sqlite3VdbeAddOpList(v, ArraySize(setCookie), setCookie, 0);

Changes to tool/mkpragmatab.tcl.

   242    242     IF:   !defined(SQLITE_OMIT_INTEGRITY_CHECK)
   243    243   
   244    244     NAME: encoding
   245    245     IF:   !defined(SQLITE_OMIT_UTF16)
   246    246   
   247    247     NAME: schema_version
   248    248     TYPE: HEADER_VALUE
          249  +  ARG:  BTREE_SCHEMA_VERSION
   249    250     IF:   !defined(SQLITE_OMIT_SCHEMA_VERSION_PRAGMAS)
   250    251   
   251    252     NAME: user_version
   252    253     TYPE: HEADER_VALUE
          254  +  ARG:  BTREE_USER_VERSION
   253    255     IF:   !defined(SQLITE_OMIT_SCHEMA_VERSION_PRAGMAS)
   254    256   
   255    257     NAME: freelist_count
   256    258     TYPE: HEADER_VALUE
          259  +  ARG:  BTREE_FREE_PAGE_COUNT
          260  +  FLAG: ReadOnly
   257    261     IF:   !defined(SQLITE_OMIT_SCHEMA_VERSION_PRAGMAS)
   258    262   
   259    263     NAME: application_id
   260    264     TYPE: HEADER_VALUE
          265  +  ARG:  BTREE_APPLICATION_ID
   261    266     IF:   !defined(SQLITE_OMIT_SCHEMA_VERSION_PRAGMAS)
   262    267   
   263    268     NAME: compile_options
   264    269     IF:   !defined(SQLITE_OMIT_COMPILEOPTION_DIAGS)
   265    270   
   266    271     NAME: wal_checkpoint
   267    272     FLAG: NeedSchema