-[no]create -- shell tool feature request/offer
(1) By Larry Brasfield (LarryBrasfield) on 2020-04-03 20:11:38 [link] [source]
Often, when I start the SQLite shell tool, I know that I either: (1) want to create a new database rather than modifying an existing one; or (2) want to open an existing database where something is wrong if it does not exist. For that reason, I have added these 2 options to the modified shell I use: -create new DB file is to be created -nocreate DB file is NOT to be created In the startup options help, this is shown as -[no]create DB file is to be created [or not]
With this change, it is an error for either: the named DB file to exist when -create is specified; or the named DB file to not exist when -nocreate is specified. With neither option specified, the auto-create or use-existing behavior remains.
Yes, in scripts using the shell tool, it is possible to handle file existence without these options. This change is but a minor convenience in such scripts.
For interactive use, it avoids the annoyance of accidentally creating DB files when that was not intended or messing with existing ones when intending to newly create a DB file.
If this is attractive to the sqlite3 shell tool authors or useful to others, I can prepare and submit patch.
I would be happy with just a warning followed by
"Create? y/N" response (
N being the default when
ENTER is pressed) when specifying a new file to save me from accidentally working on an empty database due to mistyping the filename.
Something related, that
SQLITE_OPEN_EXCLUSIVE should be allowed for
sqlite3_open_v2(); this could be used to implement being an error if it already exists, like you specify for the case when -create is specified, so it can be used in the shell program when -create is specified.
(I also have a program where this would be useful, although currently it does something else. If it is implemented, I will change my program.)