question

NeeleshKalani-2657 avatar image
0 Votes"
NeeleshKalani-2657 asked DavidLowndes-6766 answered

C++ sqlite3_open_v2 function fails to open DB file when DB path has special char(ø) in it

I am trying to open a SQLite DB connection using sqlite3_open_v2 function but it fails to open the connection when DB file path has special char(ø) in it. Say something like "C:\MySøLiteDb.sqlite". Everything works fine if DB path doesn't have a special char(ø) in it.

It works with sqlite3_open16 method but then I have to change the DB encoding to UTF-16 otherwise it doesn't return any tables back.

How can I open a SQLite DB connection with sqlite3_open_v2 method when DB file path has special char in it such as ø?

c++dotnet-sqlite
· 3
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Do you convert the name to UTF-8?
"C:\MySøLiteDb.sqlite"

0 Votes 0 ·

No I don't - how do we do that? Would that fix?

0 Votes 0 ·

Hi @NeeleshKalani-2657,

Thanks for taking time to report this problem with us. Since your question is more related to SQLite, you could go to SQLite Forum for support.


0 Votes 0 ·

1 Answer

DavidLowndes-6766 avatar image
1 Vote"
DavidLowndes-6766 answered

The API does say that the parameter should be UTF-8, so converting to that would be the obvious thing to try.
Under Windows, the underlying API to use is WideCharToMultiByte, but depending on your source, there are several different wrappers you can use, such as AtlUnicodeToUTF8; more discussion here.


· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Converting to UTf 8 worked. Thank you so much.

Here is the code I used to convert:

//Get the required length of the utf byte array
int utfByteArrayLength = WideCharToMultiByte(CP_UTF8, 0, szFile, -1, NULL, 0, NULL, FALSE);
char * utf8 = new char[utfByteArrayLength];
//Convert to utf 8 using the byte array length
int j = WideCharToMultiByte(CP_UTF8, 0, szFile, -1, utf8, utfByteArrayLength, NULL, FALSE);






1 Vote 1 ·