/ Check-in [3ac5723164]
Login

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

Overview
Comment:Add the SQLITE_TESTCTRL_PRNG_SEED test control.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | prng-seed-test-control
Files: files | file ages | folders
SHA3-256: 3ac5723164ae801e209ce525a5d94692767136f9d06be2a84883dcea677d02da
User & Date: drh 2019-08-02 20:45:04
Context
2019-08-02
21:03
Fixes to the PRNG_SEED pragma idea. check-in: c71098409c user: drh tags: prng-seed-test-control
20:45
Add the SQLITE_TESTCTRL_PRNG_SEED test control. check-in: 3ac5723164 user: drh tags: prng-seed-test-control
19:40
If a query like "SELECT min(a), b FROM t1" visits no rows where "a" is not null, extract a value for "b" from one of the rows where "a" is null. Fix for ticket [41866dc37]. check-in: faaaae4940 user: dan tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/global.c.

   256    256   #ifndef SQLITE_UNTESTABLE
   257    257      0,                         /* xTestCallback */
   258    258   #endif
   259    259      0,                         /* bLocaltimeFault */
   260    260      0,                         /* bInternalFunctions */
   261    261      0x7ffffffe,                /* iOnceResetThreshold */
   262    262      SQLITE_DEFAULT_SORTERREF_SIZE,   /* szSorterRef */
          263  +   0,                         /* iPrngSeed */
   263    264   };
   264    265   
   265    266   /*
   266    267   ** Hash table for global functions - functions common to all
   267    268   ** database connections.  After initialization, this table is
   268    269   ** read-only.
   269    270   */

Changes to src/main.c.

  3820   3820       ** this verb acts like PRNG_RESET.
  3821   3821       */
  3822   3822       case SQLITE_TESTCTRL_PRNG_RESTORE: {
  3823   3823         sqlite3PrngRestoreState();
  3824   3824         break;
  3825   3825       }
  3826   3826   
  3827         -    /*
  3828         -    ** Reset the PRNG back to its uninitialized state.  The next call
  3829         -    ** to sqlite3_randomness() will reseed the PRNG using a single call
  3830         -    ** to the xRandomness method of the default VFS.
         3827  +    /*  sqlite3_test_control(SQLITE_TESTCTRL_PRNG_SEED, unsigned int);
         3828  +    **
         3829  +    ** Use the integer value as the seed for SQLite's internal PRNG.
         3830  +    ** rather than the VFS xRandomness() function.
  3831   3831       */
  3832         -    case SQLITE_TESTCTRL_PRNG_RESET: {
  3833         -      sqlite3_randomness(0,0);
         3832  +    case SQLITE_TESTCTRL_PRNG_SEED: {
         3833  +      sqlite3Config.iPrngSeed = va_arg(ap, unsigned int);
  3834   3834         break;
  3835   3835       }
  3836   3836   
  3837   3837       /*
  3838   3838       **  sqlite3_test_control(BITVEC_TEST, size, program)
  3839   3839       **
  3840   3840       ** Run a test against a Bitvec object of size.  The program argument

Changes to src/os.c.

   254    254     return pVfs->xDlSym(pVfs, pHdle, zSym);
   255    255   }
   256    256   void sqlite3OsDlClose(sqlite3_vfs *pVfs, void *pHandle){
   257    257     pVfs->xDlClose(pVfs, pHandle);
   258    258   }
   259    259   #endif /* SQLITE_OMIT_LOAD_EXTENSION */
   260    260   int sqlite3OsRandomness(sqlite3_vfs *pVfs, int nByte, char *zBufOut){
   261         -  return pVfs->xRandomness(pVfs, nByte, zBufOut);
          261  +  if( sqlite3Config.iPrngSeed ){
          262  +    memset(zBufOut, 0, nByte);
          263  +    if( nByte>sizeof(unsigned) ) nByte = sizeof(unsigned int);
          264  +    memcpy(zBufOut, &sqlite3Config.iPrngSeed, nByte);
          265  +    return SQLITE_OK;
          266  +  }else{
          267  +    return pVfs->xRandomness(pVfs, nByte, zBufOut);
          268  +  }
          269  +  
   262    270   }
   263    271   int sqlite3OsSleep(sqlite3_vfs *pVfs, int nMicro){
   264    272     return pVfs->xSleep(pVfs, nMicro);
   265    273   }
   266    274   int sqlite3OsGetLastError(sqlite3_vfs *pVfs){
   267    275     return pVfs->xGetLastError ? pVfs->xGetLastError(pVfs, 0, 0) : 0;
   268    276   }

Changes to src/shell.c.in.

  9146   9146         { "localtime_fault",    SQLITE_TESTCTRL_LOCALTIME_FAULT,"BOOLEAN"           },
  9147   9147         { "never_corrupt",      SQLITE_TESTCTRL_NEVER_CORRUPT, "BOOLEAN"            },
  9148   9148         { "optimizations",      SQLITE_TESTCTRL_OPTIMIZATIONS, "DISABLE-MASK"       },
  9149   9149   #ifdef YYCOVERAGE
  9150   9150         { "parser_coverage",    SQLITE_TESTCTRL_PARSER_COVERAGE, ""                 },
  9151   9151   #endif
  9152   9152         { "pending_byte",       SQLITE_TESTCTRL_PENDING_BYTE,  "OFFSET  "           },
  9153         -      { "prng_reset",         SQLITE_TESTCTRL_PRNG_RESET,    ""                   },
  9154   9153         { "prng_restore",       SQLITE_TESTCTRL_PRNG_RESTORE,  ""                   },
  9155   9154         { "prng_save",          SQLITE_TESTCTRL_PRNG_SAVE,     ""                   },
         9155  +      { "prng_seed",          SQLITE_TESTCTRL_PRNG_SEED,     "SEED"               },
  9156   9156         { "reserve",            SQLITE_TESTCTRL_RESERVE,       "BYTES-OF-RESERVE"   },
  9157   9157       };
  9158   9158       int testctrl = -1;
  9159   9159       int iCtrl = -1;
  9160   9160       int rc2 = 0;    /* 0: usage.  1: %d  2: %x  3: no-output */
  9161   9161       int isOk = 0;
  9162   9162       int i, n2;
................................................................................
  9223   9223               rc2 = sqlite3_test_control(testctrl);
  9224   9224               isOk = testctrl==SQLITE_TESTCTRL_BYTEORDER ? 1 : 3;
  9225   9225             }
  9226   9226             break;
  9227   9227   
  9228   9228           /* sqlite3_test_control(int, uint) */
  9229   9229           case SQLITE_TESTCTRL_PENDING_BYTE:
         9230  +        case SQLITE_TESTCTRL_PRNG_SEED:
  9230   9231             if( nArg==3 ){
  9231   9232               unsigned int opt = (unsigned int)integerValue(azArg[2]);
  9232   9233               rc2 = sqlite3_test_control(testctrl, opt);
  9233   9234               isOk = 3;
  9234   9235             }
  9235   9236             break;
  9236   9237   

Changes to src/sqlite.h.in.

  7331   7331   ** without notice.  These values are for testing purposes only.
  7332   7332   ** Applications should not use any of these parameters or the
  7333   7333   ** [sqlite3_test_control()] interface.
  7334   7334   */
  7335   7335   #define SQLITE_TESTCTRL_FIRST                    5
  7336   7336   #define SQLITE_TESTCTRL_PRNG_SAVE                5
  7337   7337   #define SQLITE_TESTCTRL_PRNG_RESTORE             6
  7338         -#define SQLITE_TESTCTRL_PRNG_RESET               7
         7338  +#define SQLITE_TESTCTRL_PRNG_RESET               7  /* NOT USED */
  7339   7339   #define SQLITE_TESTCTRL_BITVEC_TEST              8
  7340   7340   #define SQLITE_TESTCTRL_FAULT_INSTALL            9
  7341   7341   #define SQLITE_TESTCTRL_BENIGN_MALLOC_HOOKS     10
  7342   7342   #define SQLITE_TESTCTRL_PENDING_BYTE            11
  7343   7343   #define SQLITE_TESTCTRL_ASSERT                  12
  7344   7344   #define SQLITE_TESTCTRL_ALWAYS                  13
  7345   7345   #define SQLITE_TESTCTRL_RESERVE                 14
................................................................................
  7354   7354   #define SQLITE_TESTCTRL_VDBE_COVERAGE           21
  7355   7355   #define SQLITE_TESTCTRL_BYTEORDER               22
  7356   7356   #define SQLITE_TESTCTRL_ISINIT                  23
  7357   7357   #define SQLITE_TESTCTRL_SORTER_MMAP             24
  7358   7358   #define SQLITE_TESTCTRL_IMPOSTER                25
  7359   7359   #define SQLITE_TESTCTRL_PARSER_COVERAGE         26
  7360   7360   #define SQLITE_TESTCTRL_RESULT_INTREAL          27
  7361         -#define SQLITE_TESTCTRL_LAST                    27  /* Largest TESTCTRL */
         7361  +#define SQLITE_TESTCTRL_PRNG_SEED               28
         7362  +#define SQLITE_TESTCTRL_LAST                    28  /* Largest TESTCTRL */
  7362   7363   
  7363   7364   /*
  7364   7365   ** CAPI3REF: SQL Keyword Checking
  7365   7366   **
  7366   7367   ** These routines provide access to the set of SQL language keywords 
  7367   7368   ** recognized by SQLite.  Applications can uses these routines to determine
  7368   7369   ** whether or not a specific identifier needs to be escaped (for example,

Changes to src/sqliteInt.h.

  3460   3460   #ifndef SQLITE_UNTESTABLE
  3461   3461     int (*xTestCallback)(int);        /* Invoked by sqlite3FaultSim() */
  3462   3462   #endif
  3463   3463     int bLocaltimeFault;              /* True to fail localtime() calls */
  3464   3464     int bInternalFunctions;           /* Internal SQL functions are visible */
  3465   3465     int iOnceResetThreshold;          /* When to reset OP_Once counters */
  3466   3466     u32 szSorterRef;                  /* Min size in bytes to use sorter-refs */
         3467  +  unsigned int iPrngSeed;           /* Alternative fixed seed for the PRNG */
  3467   3468   };
  3468   3469   
  3469   3470   /*
  3470   3471   ** This macro is used inside of assert() statements to indicate that
  3471   3472   ** the assert is only valid on a well-formed database.  Instead of:
  3472   3473   **
  3473   3474   **     assert( X );

Changes to src/test1.c.

  6369   6369   */
  6370   6370   static int SQLITE_TCLAPI reset_prng_state(
  6371   6371     ClientData clientData, /* Pointer to sqlite3_enable_XXX function */
  6372   6372     Tcl_Interp *interp,    /* The TCL interpreter that invoked this command */
  6373   6373     int objc,              /* Number of arguments */
  6374   6374     Tcl_Obj *CONST objv[]  /* Command arguments */
  6375   6375   ){
  6376         -  sqlite3_test_control(SQLITE_TESTCTRL_PRNG_RESET);
         6376  +  sqlite3_randomness(0,0);
         6377  +  return TCL_OK;
         6378  +}
         6379  +/*
         6380  +** tclcmd:  prng_seed INT
         6381  +**
         6382  +** Establish TEXT as the seed for the PRNG
         6383  +*/
         6384  +static int SQLITE_TCLAPI prng_seed(
         6385  +  ClientData clientData, /* Pointer to sqlite3_enable_XXX function */
         6386  +  Tcl_Interp *interp,    /* The TCL interpreter that invoked this command */
         6387  +  int objc,              /* Number of arguments */
         6388  +  Tcl_Obj *CONST objv[]  /* Command arguments */
         6389  +){
         6390  +  unsigned int i;
         6391  +  if( objc!=2 ){
         6392  +    Tcl_WrongNumArgs(interp, 1, objv, "PRNG-SEED-TEXT");
         6393  +    return TCL_ERROR;
         6394  +  }
         6395  +  if( Tcl_GetIntFromObj(objv[0],&i) ) return TCL_ERROR;
         6396  +  sqlite3_test_control(SQLITE_TESTCTRL_PRNG_SEED, (unsigned int)i);
         6397  +  sqlite3_randomness(0,0);
  6377   6398     return TCL_OK;
  6378   6399   }
  6379   6400   
  6380   6401   /*
  6381   6402   ** tclcmd:  database_may_be_corrupt
  6382   6403   **
  6383   6404   ** Indicate that database files might be corrupt. In other words, set the normal
................................................................................
  7919   7940        { "sqlite3_extended_result_codes", test_extended_result_codes, 0},
  7920   7941        { "sqlite3_limit",                 test_limit,                 0},
  7921   7942        { "dbconfig_maindbname_icecube",   test_dbconfig_maindbname_icecube },
  7922   7943   
  7923   7944        { "save_prng_state",               save_prng_state,    0 },
  7924   7945        { "restore_prng_state",            restore_prng_state, 0 },
  7925   7946        { "reset_prng_state",              reset_prng_state,   0 },
         7947  +     { "prng_seed",                     prng_seed,          0 },
  7926   7948        { "database_never_corrupt",        database_never_corrupt, 0},
  7927   7949        { "database_may_be_corrupt",       database_may_be_corrupt, 0},
  7928   7950        { "optimization_control",          optimization_control,0},
  7929   7951   #if SQLITE_OS_WIN
  7930   7952        { "lock_win32_file",               win32_file_lock,    0 },
  7931   7953        { "exists_win32_path",             win32_exists_path,  0 },
  7932   7954        { "find_win32_file",               win32_find_file,    0 },