/ Check-in [b3692c40]
Login

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

Overview
Comment:Combine the implementations of the key and hexkey pragmas into a single case. Have both pragmas return "ok" if they are implemented.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: b3692c406f7ba62587c9d3256f888748393519680e9e2db53f59557f1a300e05
User & Date: drh 2019-05-21 17:04:27
Context
2019-05-22
14:22
Fix a buffer overread that could in fts3 when dealing with corrupt records. check-in: 1660d773 user: dan tags: trunk
2019-05-21
17:04
Combine the implementations of the key and hexkey pragmas into a single case. Have both pragmas return "ok" if they are implemented. check-in: b3692c40 user: drh tags: trunk
16:32
Fix a problem in [b5ca442a] causing an assert() to fail in REINDEX commands. check-in: a3e77c77 user: dan tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/pragma.c.

  2126   2126     **  hexkey        2
  2127   2127     **  hexrekey      3
  2128   2128     **  textkey       4
  2129   2129     **  textrekey     5
  2130   2130     */
  2131   2131     case PragTyp_KEY: {
  2132   2132       if( zRight ){
  2133         -      int n = pPragma->iArg<4 ? sqlite3Strlen30(zRight) : -1;
  2134         -      if( (pPragma->iArg & 1)==0 ){
  2135         -        sqlite3_key_v2(db, zDb, zRight, n);
         2133  +      char zBuf[40];
         2134  +      const char *zKey = zRight;
         2135  +      int n;
         2136  +      if( pPragma->iArg==2 || pPragma->iArg==3 ){
         2137  +        u8 iByte;
         2138  +        int i;
         2139  +        for(i=0, iByte=0; i<sizeof(zBuf)*2 && sqlite3Isxdigit(zRight[i]); i++){
         2140  +          iByte = (iByte<<4) + sqlite3HexToInt(zRight[i]);
         2141  +          if( (i&1)!=0 ) zBuf[i/2] = iByte;
         2142  +        }
         2143  +        zKey = zBuf;
         2144  +        n = i/2;
  2136   2145         }else{
  2137         -        sqlite3_rekey_v2(db, zDb, zRight, n);
  2138         -      }
  2139         -    }
  2140         -    break;
  2141         -  }
  2142         -  case PragTyp_HEXKEY: {
  2143         -    if( zRight ){
  2144         -      u8 iByte;
  2145         -      int i;
  2146         -      char zKey[40];
  2147         -      for(i=0, iByte=0; i<sizeof(zKey)*2 && sqlite3Isxdigit(zRight[i]); i++){
  2148         -        iByte = (iByte<<4) + sqlite3HexToInt(zRight[i]);
  2149         -        if( (i&1)!=0 ) zKey[i/2] = iByte;
         2146  +        n = pPragma->iArg<4 ? sqlite3Strlen30(zRight) : -1;
  2150   2147         }
  2151   2148         if( (pPragma->iArg & 1)==0 ){
  2152         -        sqlite3_key_v2(db, zDb, zKey, i/2);
         2149  +        rc = sqlite3_key_v2(db, zDb, zKey, n);
  2153   2150         }else{
  2154         -        sqlite3_rekey_v2(db, zDb, zKey, i/2);
         2151  +        rc = sqlite3_rekey_v2(db, zDb, zKey, n);
         2152  +      }
         2153  +      if( rc==SQLITE_OK && n!=0 ){
         2154  +        sqlite3VdbeSetNumCols(v, 1);
         2155  +        sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "ok", SQLITE_STATIC);
         2156  +        returnSingleText(v, "ok");
  2155   2157         }
  2156   2158       }
  2157   2159       break;
  2158   2160     }
  2159   2161   #endif
  2160   2162   #if defined(SQLITE_HAS_CODEC) || defined(SQLITE_ENABLE_CEROD)
  2161   2163     case PragTyp_ACTIVATE_EXTENSIONS: if( zRight ){

Changes to src/pragma.h.

    42     42   #define PragTyp_TABLE_INFO                    34
    43     43   #define PragTyp_TEMP_STORE                    35
    44     44   #define PragTyp_TEMP_STORE_DIRECTORY          36
    45     45   #define PragTyp_THREADS                       37
    46     46   #define PragTyp_WAL_AUTOCHECKPOINT            38
    47     47   #define PragTyp_WAL_CHECKPOINT                39
    48     48   #define PragTyp_ACTIVATE_EXTENSIONS           40
    49         -#define PragTyp_HEXKEY                        41
    50         -#define PragTyp_KEY                           42
    51         -#define PragTyp_LOCK_STATUS                   43
    52         -#define PragTyp_STATS                         44
           49  +#define PragTyp_KEY                           41
           50  +#define PragTyp_LOCK_STATUS                   42
           51  +#define PragTyp_STATS                         43
    53     52   
    54     53   /* Property flags associated with various pragma. */
    55     54   #define PragFlg_NeedSchema 0x01 /* Force schema load before running */
    56     55   #define PragFlg_NoColumns  0x02 /* OP_ResultRow called with zero columns */
    57     56   #define PragFlg_NoColumns1 0x04 /* zero columns if RHS argument is present */
    58     57   #define PragFlg_ReadOnly   0x08 /* Read-only HEADER_VALUE */
    59     58   #define PragFlg_Result0    0x10 /* Acts as query when no argument */
................................................................................
   318    317     /* ePragFlg:  */ PragFlg_Result0,
   319    318     /* ColNames:  */ 41, 2,
   320    319     /* iArg:      */ 0 },
   321    320   #endif
   322    321   #endif
   323    322   #if defined(SQLITE_HAS_CODEC)
   324    323    {/* zName:     */ "hexkey",
   325         -  /* ePragTyp:  */ PragTyp_HEXKEY,
          324  +  /* ePragTyp:  */ PragTyp_KEY,
   326    325     /* ePragFlg:  */ 0,
   327    326     /* ColNames:  */ 0, 0,
   328    327     /* iArg:      */ 2 },
   329    328    {/* zName:     */ "hexrekey",
   330         -  /* ePragTyp:  */ PragTyp_HEXKEY,
          329  +  /* ePragTyp:  */ PragTyp_KEY,
   331    330     /* ePragFlg:  */ 0,
   332    331     /* ColNames:  */ 0, 0,
   333    332     /* iArg:      */ 3 },
   334    333   #endif
   335    334   #if !defined(SQLITE_OMIT_FLAG_PRAGMAS)
   336    335   #if !defined(SQLITE_OMIT_CHECK)
   337    336    {/* zName:     */ "ignore_check_constraints",

Changes to tool/mkpragmatab.tcl.

   377    377   
   378    378     NAME: rekey
   379    379     TYPE: KEY
   380    380     ARG:  1
   381    381     IF:   defined(SQLITE_HAS_CODEC)
   382    382   
   383    383     NAME: hexkey
   384         -  TYPE: HEXKEY
          384  +  TYPE: KEY
   385    385     ARG:  2
   386    386     IF:   defined(SQLITE_HAS_CODEC)
   387    387   
   388    388     NAME: hexrekey
   389         -  TYPE: HEXKEY
          389  +  TYPE: KEY
   390    390     ARG:  3
   391    391     IF:   defined(SQLITE_HAS_CODEC)
   392    392   
   393    393     NAME: textkey
   394    394     TYPE: KEY
   395    395     ARG:  4
   396    396     IF:   defined(SQLITE_HAS_CODEC)