Special characters * and ? are not supported in Database Names on Windows?
(1.1) Originally by Narendra Bhagwat (bhagwatn) with edits by Richard Hipp (drh) on 2021-05-14 11:29:25 from 1.0 [source]
Hi, I am able to create database name with special characters including * and ? on RHEL 8, Sqlite3. But it fails on windows Server 2016.
So, how do I do this in windows, it works fine in RHEL 8.
Following fails on windows 2016:
C:/user1/db>sqlite3 'Test*DB2' SQLite version 3.35.5 2021-04-19 18:32:05 Enter ".help" for usage hints. sqlite> create table IF NOT EXISTS table1 (field1 varchar(10)); Error: unable to open database "'Test*DB2'": unable to open database file C:/user1/db>sqlite3 'Test\*DB2' SQLite version 3.35.5 2021-04-19 18:32:05 Enter ".help" for usage hints. sqlite> create table IF NOT EXISTS table1 (field1 varchar(10)); Error: unable to open database "'Test\*DB2'": unable to open database file
But passes in RHEL 8.
# sqlite3 'Test*DB4' SQLite version 3.35.4 2021-04-02 15:20:15 Enter ".help" for usage hints. sqlite> create table IF NOT EXISTS table1 (field1 varchar(10)); sqlite># ls -l -rw-r--r--. 1 root root 8192 May 14 16:10 'Test*DB4'
(2) By Mark Benningfield (mbenningfield1) on 2021-05-14 11:36:31 in reply to 1.1 [link] [source]
Well, no. You can't create a file on Windows with illegal filename characters.
See this list
This is not an SQLite problem at all and this is the wrong forum for it.
If you can create a text file with that name on Windows, but then SQLite isn't able to do it, you may have a reason to post here. You will however find you cannot do so, which I agree is a fair complaint, but it should be directed at Microsoft. We can't help.
I can however suggest you change that file naming convention, or introduce a translator, to use periods (points) in stead of asterisks ("*" --> ".") and underscores or dashes in stead of question marks ("?" --> "-" | "_"), which would make it work universally on all OSes.
As has already been remarked, this is not a SQLite problem and is thus off-topic for this forum. But previous responses may lead you to other, similar, mistakes so I'm giving a fuller answer.
Windows uses the question mark and asterisk characters as pattern match characters (any single character, and any sequence of characters, respectively). Filenames are not allowed to include them.
Do not use periods in names of files for Windows, except for one period which separates the filename from the extension. Some software handles multiple periods correctly. Other software does not, interpreting the first period as the separator, and everything after it as the extension, then interpreting that extension as a filetype. This is incorrect, but so much software does it good Windows programmers know to avoid it.
You will have problems if you handle a file with a name starting with a period to a Unix/Linux/Mac computer.
There are also some problems with using minus signs. Try, for example, working on various operating systems with filenames which start with a minus sign. Underscores should be fine, but filenames which start with an underscore can act weird on various platforms, including being invisible to some file browsers. Remember also that your boot volume may be some fancy modern filesystem that handles unicode and all sorts of fancy filenames, but eventually someone's gonna copy your files to a Flash Drive with FAT32, or a backup drive formatted for ext3.
Basic rules for platform-independent filenames:
ASCII characters only. Assume no distinction between upper and lower case. First character must be a letter or a digit. Subsequent characters can be letter, digit, underscore or period. Maximum of one period in the filename.
That should do you for most operating systems and most filesystems, most of the time.