/ Check-in [89209000]
Login

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

Overview
Comment:Fix a problem in the shell preventing it from working with SQLITE_OMIT_AUTOINIT builds.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256:89209000a205c685bb6bd941376ef16e507919d192d606c1be110ccf2921d9bd
User & Date: dan 2018-04-18 09:16:11
Context
2018-04-18
10:44
Add checks to the CLI that issue a warning if SQLite gets initialized prior to the last sqlite3_config() call. check-in: 40b11734 user: drh tags: trunk
09:16
Fix a problem in the shell preventing it from working with SQLITE_OMIT_AUTOINIT builds. check-in: 89209000 user: dan tags: trunk
2018-04-16
14:31
Lemon enhancements: (1) Do not allocate space for the 'error' non-terminal if it is not used. (2) Fix an off-by-one problem so that 'unsigned char' can be used for symbol numbers if the number of symbols is 256. check-in: 3b7801ac user: drh tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/shell.c.in.

  3480   3480   
  3481   3481   /*
  3482   3482   ** Make sure the database is open.  If it is not, then open it.  If
  3483   3483   ** the database fails to open, print an error message and exit.
  3484   3484   */
  3485   3485   static void open_db(ShellState *p, int keepAlive){
  3486   3486     if( p->db==0 ){
  3487         -    sqlite3_initialize();
  3488   3487       if( p->openMode==SHELL_OPEN_UNSPEC && access(p->zDbFilename,0)==0 ){
  3489   3488         p->openMode = (u8)deduceDatabaseType(p->zDbFilename, 0);
  3490   3489       }
  3491   3490       switch( p->openMode ){
  3492   3491         case SHELL_OPEN_APPENDVFS: {
  3493   3492           sqlite3_open_v2(p->zDbFilename, &p->db, 
  3494   3493              SQLITE_OPEN_READWRITE|SQLITE_OPEN_CREATE, "apndvfs");
................................................................................
  8021   8020     if (sqliterc == NULL) {
  8022   8021       home_dir = find_home_dir(0);
  8023   8022       if( home_dir==0 ){
  8024   8023         raw_printf(stderr, "-- warning: cannot find home directory;"
  8025   8024                         " cannot read ~/.sqliterc\n");
  8026   8025         return;
  8027   8026       }
  8028         -    sqlite3_initialize();
  8029   8027       zBuf = sqlite3_mprintf("%s/.sqliterc",home_dir);
  8030   8028       sqliterc = zBuf;
  8031   8029     }
  8032   8030     in = fopen(sqliterc,"rb");
  8033   8031     if( in ){
  8034   8032       if( stdin_is_interactive ){
  8035   8033         utf8_printf(stderr,"-- Loading resources from %s\n",sqliterc);
................................................................................
  8169   8167     const char *zInitFile = 0;
  8170   8168     int i;
  8171   8169     int rc = 0;
  8172   8170     int warnInmemoryDb = 0;
  8173   8171     int readStdin = 1;
  8174   8172     int nCmd = 0;
  8175   8173     char **azCmd = 0;
         8174  +  const char *zVfs = 0;           /* Value of -vfs command-line option */
  8176   8175   
  8177   8176     setBinaryMode(stdin, 0);
  8178   8177     setvbuf(stderr, 0, _IONBF, 0); /* Make sure stderr is unbuffered */
  8179   8178     stdin_is_interactive = isatty(0);
  8180   8179     stdout_is_console = isatty(1);
  8181   8180   
  8182   8181   #if USE_SYSTEM_SQLITE+0!=1
................................................................................
  8328   8327         extern int sqlite3_multiple_initialize(const char*,int);
  8329   8328         sqlite3_multiplex_initialize(0, 1);
  8330   8329   #endif
  8331   8330       }else if( strcmp(z,"-mmap")==0 ){
  8332   8331         sqlite3_int64 sz = integerValue(cmdline_option_value(argc,argv,++i));
  8333   8332         sqlite3_config(SQLITE_CONFIG_MMAP_SIZE, sz, sz);
  8334   8333       }else if( strcmp(z,"-vfs")==0 ){
  8335         -      sqlite3_vfs *pVfs = sqlite3_vfs_find(cmdline_option_value(argc,argv,++i));
  8336         -      if( pVfs ){
  8337         -        sqlite3_vfs_register(pVfs, 1);
  8338         -      }else{
  8339         -        utf8_printf(stderr, "no such VFS: \"%s\"\n", argv[i]);
  8340         -        exit(1);
  8341         -      }
         8334  +      zVfs = cmdline_option_value(argc, argv, ++i);
  8342   8335   #ifdef SQLITE_HAVE_ZLIB
  8343   8336       }else if( strcmp(z,"-zip")==0 ){
  8344   8337         data.openMode = SHELL_OPEN_ZIPFILE;
  8345   8338   #endif
  8346   8339       }else if( strcmp(z,"-append")==0 ){
  8347   8340         data.openMode = SHELL_OPEN_APPENDVFS;
  8348   8341       }else if( strcmp(z,"-readonly")==0 ){
................................................................................
  8351   8344       }else if( strncmp(z, "-A",2)==0 ){
  8352   8345         /* All remaining command-line arguments are passed to the ".archive"
  8353   8346         ** command, so ignore them */
  8354   8347         break;
  8355   8348   #endif
  8356   8349       }
  8357   8350     }
         8351  +
         8352  +  /* All the sqlite3_config() calls have now been made. So it is safe
         8353  +  ** to call sqlite3_initialize() and process any command line -vfs option. */
         8354  +  sqlite3_initialize();
         8355  +  if( zVfs ){
         8356  +    sqlite3_vfs *pVfs = sqlite3_vfs_find(zVfs);
         8357  +    if( pVfs ){
         8358  +      sqlite3_vfs_register(pVfs, 1);
         8359  +    }else{
         8360  +      utf8_printf(stderr, "no such VFS: \"%s\"\n", argv[i]);
         8361  +      exit(1);
         8362  +    }
         8363  +  }
         8364  +
  8358   8365     if( data.zDbFilename==0 ){
  8359   8366   #ifndef SQLITE_OMIT_MEMORYDB
  8360   8367       data.zDbFilename = ":memory:";
  8361   8368       warnInmemoryDb = argc==1;
  8362   8369   #else
  8363   8370       utf8_printf(stderr,"%s: Error: no database filename specified\n", Argv0);
  8364   8371       return 1;