lurcher / unixODBC

The unixODBC Project goals are to develop and promote unixODBC to be the definitive standard for ODBC on non MS Windows platforms.
GNU Lesser General Public License v2.1
94 stars 51 forks source link

[question] Unclear Unicode handling in SQLGetPrivateProfileStringW #152

Closed lfrancke closed 7 months ago

lfrancke commented 8 months ago

Hi, I'm sorry for asking a question here but I couldn't find the answer on my own.

I tried calling SQLGetPrivateProfileStringW and I expected a "wide char" in response which I thought'd be UTF-16. But that doesn't seem to be the case. It seems as if it's calling the non W version and then basically just passes this on.

https://github.com/lurcher/unixODBC/blob/9b31cd228d01e768a7ad9126d5da8860f1ed72a9/odbcinst/SQLGetPrivateProfileString.c#L645-L665

https://github.com/lurcher/unixODBC/blob/9b31cd228d01e768a7ad9126d5da8860f1ed72a9/odbcinst/SQLCreateDataSource.c#L256-L271

I'm sure I'm just missing something obvious. Any hint is appreciated

polluks commented 8 months ago

Indeed, _single_copy_to_wide is simple copying. However SQLGetPrivateProfileString does not call _multi_string_copy_to_wide, which converts a string.

lfrancke commented 8 months ago

Thank you. But....am I missing something? Shouldn't the W version convert anything it gets to a wide string? I'm afraid I'm not sure if this is a bug or intended behavior now.

lurcher commented 8 months ago

On 16/11/2023 11:58, Lars Francke wrote:

Thank you. But....am I missing something? Shouldn't the |W| version convert anything it gets to a wide string? I'm afraid I'm not sure if this is a bug or intended behavior now.

Is it not doing that?

lfrancke commented 8 months ago

Unless I'm stupid - which is entirely possible - I don't think so. I haven't dealt with C in ages and "wide chars" / UTF-16 are also not something I'm super familiar with.

I do call SQLGetPrivateProfileStringW in my code and I would expect to get UTF-16 in return. When I get the string "foo" I would expect to get a six-byte buffer back but I get just three bytes.

I'm not at my computer right now but I can check again in a bit.

Any of my expectations might be wrong, so I'm not saying this is a bug. Instead I'm not sure what the intention is.

v-chojas commented 8 months ago

_single_copy_to_wide and _multi_string_copy_to_wide do widen the string when copying it.

lfrancke commented 8 months ago

I believe the "I'm an idiot" thing is what happened here. I will check when I get back and close this issue as needed. Thank you for the answers and sorry for the noise.

lfrancke commented 7 months ago

Okay, I am very sorry for the noise. It was indeed me being too stupid to understand the debugger output properly. I'll close this.