/ Check-in [06870bb1]
Login

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

Overview
Comment:Add the --readonly option to the ".open" command in the CLI.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 06870bb15656b50b0e14d4364bb21afac76500e313ecf67aaef3688d603fd076
User & Date: drh 2018-02-14 23:27:43
Context
2018-02-15
01:03
Fix the --heap, --pagecache, --lookaside and other options to the command-line shell that invoke sqlite3_config() so that they work again. check-in: 00707f2f user: drh tags: trunk
2018-02-14
23:27
Add the --readonly option to the ".open" command in the CLI. check-in: 06870bb1 user: drh tags: trunk
20:58
Performance optimizations to the editdist3() function in the spellfix extension. check-in: 70d304dc user: drh tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/shell.c.in.

  1065   1065   
  1066   1066   /* Allowed values for ShellState.openMode
  1067   1067   */
  1068   1068   #define SHELL_OPEN_UNSPEC     0      /* No open-mode specified */
  1069   1069   #define SHELL_OPEN_NORMAL     1      /* Normal database file */
  1070   1070   #define SHELL_OPEN_APPENDVFS  2      /* Use appendvfs */
  1071   1071   #define SHELL_OPEN_ZIPFILE    3      /* Use the zipfile virtual table */
         1072  +#define SHELL_OPEN_READONLY   4      /* Open a normal database read-only */
  1072   1073   
  1073   1074   /*
  1074   1075   ** These are the allowed shellFlgs values
  1075   1076   */
  1076   1077   #define SHFLG_Pagecache      0x00000001 /* The --pagecache option is used */
  1077   1078   #define SHFLG_Lookaside      0x00000002 /* Lookaside memory is used */
  1078   1079   #define SHFLG_Backslash      0x00000004 /* The --backslash option is used */
................................................................................
  3254   3255     "                         tcl      TCL list elements\n"
  3255   3256     ".nullvalue STRING      Use STRING in place of NULL values\n"
  3256   3257     ".once (-e|-x|FILE)     Output for the next SQL command only to FILE\n"
  3257   3258     "                         or invoke system text editor (-e) or spreadsheet (-x)\n"
  3258   3259     "                         on the output.\n"
  3259   3260     ".open ?OPTIONS? ?FILE? Close existing database and reopen FILE\n"
  3260   3261     "                         The --new option starts with an empty file\n"
         3262  +  "                         Other options: --readonly --append --zip\n"
  3261   3263     ".output ?FILE?         Send output to FILE or stdout\n"
  3262   3264     ".print STRING...       Print literal STRING\n"
  3263   3265     ".prompt MAIN CONTINUE  Replace the standard prompts\n"
  3264   3266     ".quit                  Exit this program\n"
  3265   3267     ".read FILENAME         Execute SQL in FILENAME\n"
  3266   3268     ".restore ?DB? FILE     Restore content of DB (default \"main\") from FILE\n"
  3267   3269     ".save FILE             Write in-memory database into FILE\n"
................................................................................
  3449   3451           sqlite3_open_v2(p->zDbFilename, &p->db, 
  3450   3452              SQLITE_OPEN_READWRITE|SQLITE_OPEN_CREATE, "apndvfs");
  3451   3453           break;
  3452   3454         }
  3453   3455         case SHELL_OPEN_ZIPFILE: {
  3454   3456           sqlite3_open(":memory:", &p->db);
  3455   3457           break;
         3458  +      }
         3459  +      case SHELL_OPEN_READONLY: {
         3460  +        sqlite3_open_v2(p->zDbFilename, &p->db, SQLITE_OPEN_READONLY, 0);
         3461  +        break;
  3456   3462         }
  3457   3463         case SHELL_OPEN_UNSPEC:
  3458   3464         case SHELL_OPEN_NORMAL: {
  3459   3465           sqlite3_open(p->zDbFilename, &p->db);
  3460   3466           break;
  3461   3467         }
  3462   3468       }
................................................................................
  6303   6309           newFlag = 1;
  6304   6310   #ifdef SQLITE_HAVE_ZIP
  6305   6311         }else if( optionMatch(z, "zip") ){
  6306   6312           p->openMode = SHELL_OPEN_ZIPFILE;
  6307   6313   #endif
  6308   6314         }else if( optionMatch(z, "append") ){
  6309   6315           p->openMode = SHELL_OPEN_APPENDVFS;
         6316  +      }else if( optionMatch(z, "readonly") ){
         6317  +        p->openMode = SHELL_OPEN_READONLY;
  6310   6318         }else if( z[0]=='-' ){
  6311   6319           utf8_printf(stderr, "unknown option: %s\n", z);
  6312   6320           rc = 1;
  6313   6321           goto meta_command_exit;
  6314   6322         }
  6315   6323       }
  6316   6324       /* If a filename is specified, try to open it first */
................................................................................
  7981   7989   #ifdef SQLITE_ENABLE_MULTIPLEX
  7982   7990     "   -multiplex           enable the multiplexor VFS\n"
  7983   7991   #endif
  7984   7992     "   -newline SEP         set output row separator. Default: '\\n'\n"
  7985   7993     "   -nullvalue TEXT      set text string for NULL values. Default ''\n"
  7986   7994     "   -pagecache SIZE N    use N slots of SZ bytes each for page cache memory\n"
  7987   7995     "   -quote               set output mode to 'quote'\n"
         7996  +  "   -readonly            open the database read-only\n"
  7988   7997     "   -separator SEP       set output column separator. Default: '|'\n"
  7989   7998     "   -stats               print memory stats before each finalize\n"
  7990   7999     "   -version             show SQLite version\n"
  7991   8000     "   -vfs NAME            use NAME as the default VFS\n"
  7992   8001   #ifdef SQLITE_ENABLE_VFSTRACE
  7993   8002     "   -vfstrace            enable tracing of all VFS calls\n"
  7994   8003   #endif
................................................................................
  8230   8239         }
  8231   8240   #ifdef SQLITE_HAVE_ZIP
  8232   8241       }else if( strcmp(z,"-zip")==0 ){
  8233   8242         data.openMode = SHELL_OPEN_ZIPFILE;
  8234   8243   #endif
  8235   8244       }else if( strcmp(z,"-append")==0 ){
  8236   8245         data.openMode = SHELL_OPEN_APPENDVFS;
         8246  +    }else if( strcmp(z,"-readonly")==0 ){
         8247  +      data.openMode = SHELL_OPEN_READONLY;
  8237   8248       }
  8238   8249     }
  8239   8250     if( data.zDbFilename==0 ){
  8240   8251   #ifndef SQLITE_OMIT_MEMORYDB
  8241   8252       data.zDbFilename = ":memory:";
  8242   8253       warnInmemoryDb = argc==1;
  8243   8254   #else