Thursday, March 22, 2012

_wcsupr () with german characters

Hi,
I have a string which contains some german characters e.g 'Men'. I
am converting it to upper case using wcsupr (). But is not converted to .
There are other characters too. I can use the _wsetlocale () function before
using _wcsupr (). I cannot use the current machines locale setting. The
strings have to be converted to upper case based on the locale of the target
machine which is a SQL Server. What's the most efficient way of converting
the string to upper case considering the language specific characters. I
tried using the _wsetlocale (LC_CTYPE , L".OCP"); which uses the OEM code
page. This seems to be working. What's the difference in OEM code page and
language specific code page?
Thanks in advance
AjeyHi
The easiest way may be to use the UPPER function when retrieving/saving the
data
SELECT UPPER( 'Menü')
MENü
John
"Ajey" wrote:

> Hi,
> I have a string which contains some german characters e.g 'Menü'.
I
> am converting it to upper case using wcsupr (). But ü is not converted to
ü.
> There are other characters too. I can use the _wsetlocale () function befo
re
> using _wcsupr (). I cannot use the current machines locale setting. The
> strings have to be converted to upper case based on the locale of the targ
et
> machine which is a SQL Server. What's the most efficient way of converting
> the string to upper case considering the language specific characters. I
> tried using the _wsetlocale (LC_CTYPE , L".OCP"); which uses the OEM code
> page. This seems to be working. What's the difference in OEM code page and
> language specific code page?
> Thanks in advance
> Ajey
>
>|||There are many such string. I cannot use sql query for each to just make it
a upper case. Is there a way i can find out exact local the SQL Server is
using or is there any documentation of which API UPPER function insql uses.
"John Bell" <JohnBell@.discussions.microsoft.com> wrote in message
news:E55039D7-F207-4131-AF23-4E603E29A38D@.microsoft.com...
> Hi
> The easiest way may be to use the UPPER function when retrieving/saving
the
> data
> SELECT UPPER( 'Men')
> --
> MEN
> John
> "Ajey" wrote:
>
I
to .
before
target
converting
code
and|||If i get the code page from the SQL Server as 1252 where as the language on
server is german but the machine where i am running the API has English,
will _wsetlocale(LC_CTYPE, L".1252") work fine. Are code page number specifc
to languages or they cover range of languages. (I want to make sure that
code page 1252 is not different for german and different for english)
"Ajey" <ajey5@.hotmail.com> wrote in message
news:OJYC$WQNFHA.688@.TK2MSFTNGP10.phx.gbl...
> There are many such string. I cannot use sql query for each to just make
it
> a upper case. Is there a way i can find out exact local the SQL Server is
> using or is there any documentation of which API UPPER function insql
uses.
> "John Bell" <JohnBell@.discussions.microsoft.com> wrote in message
> news:E55039D7-F207-4131-AF23-4E603E29A38D@.microsoft.com...
> the
'Men'.
> I
> to .
> before
The
> target
> converting
I
> code
> and
>|||"Ajey" <ajey5@.hotmail.com> schrieb im Newsbeitrag =
news:OkTRS$ONFHA.1528@.TK2MSFTNGP09.phx.gbl...
> Hi,
> I have a string which contains some german characters e.g =
'Men=FC'. I
> am converting it to upper case using wcsupr (). But =FC is not =
converted to =DC.
> There are other characters too. I can use the _wsetlocale () function =
before
> using _wcsupr (). I cannot use the current machines locale setting. =
The
> strings have to be converted to upper case based on the locale of the =
target
> machine which is a SQL Server. What's the most efficient way of =
converting
> the string to upper case considering the language specific characters. =
I
> tried using the _wsetlocale (LC_CTYPE , L".OCP"); which uses the OEM =
code
> page. This seems to be working. What's the difference in OEM code page =
and
> language specific code page?
wcsupr should be independent of the current locale. However, there seems =
to be a bug in the implementation of wcsupr. It first checks the current =
locale and if the "C" locale is used, it simply translates 'a'-'z' to =
upper case but ignores all other letters. If you select any locale =
different form the "C" locale, the string will be translated correctly. =
So, your call to setlocale does fix that bug, but using an OEM codepage =
might introduce other problems. Using the current ANSI codepage (".ACP") =
probably is a better choice.
If you are very cautions, you should implement your own to-upper =
function that selects a reasonable codepage and later restores the =
original one. Something like
void ToUpper(wchar_t* s)
{
char const* loc =3D setlocale(LC_CTYPE, ".ACP");
wcsupr(s);
setlocale(LC_CTYPE, loc);
}
As long as you feed unicode strings (wchar_t) to your SQL server, you =
shouldn't have to worry about locales. You only have to select some =
locale to fix that stupid bug of wcsupr.
HTH
Heinz|||Is the setting applicable to current thread only or to entire program (all
threads)?
"Heinz Ozwirk" <hozwirk.SPAM@.arcor.de> wrote in message
news:424a7cd4$0$11477$9b4e6d93@.newsread2
.arcor-online.net...
"Ajey" <ajey5@.hotmail.com> schrieb im Newsbeitrag
news:OkTRS$ONFHA.1528@.TK2MSFTNGP09.phx.gbl...
> Hi,
> I have a string which contains some german characters e.g 'Men'. I
> am converting it to upper case using wcsupr (). But is not converted to
.
> There are other characters too. I can use the _wsetlocale () function
before
> using _wcsupr (). I cannot use the current machines locale setting. The
> strings have to be converted to upper case based on the locale of the
target
> machine which is a SQL Server. What's the most efficient way of converting
> the string to upper case considering the language specific characters. I
> tried using the _wsetlocale (LC_CTYPE , L".OCP"); which uses the OEM code
> page. This seems to be working. What's the difference in OEM code page and
> language specific code page?
wcsupr should be independent of the current locale. However, there seems to
be a bug in the implementation of wcsupr. It first checks the current locale
and if the "C" locale is used, it simply translates 'a'-'z' to upper case
but ignores all other letters. If you select any locale different form the
"C" locale, the string will be translated correctly. So, your call to
setlocale does fix that bug, but using an OEM codepage might introduce other
problems. Using the current ANSI codepage (".ACP") probably is a better
choice.
If you are very cautions, you should implement your own to-upper function
that selects a reasonable codepage and later restores the original one.
Something like
void ToUpper(wchar_t* s)
{
char const* loc = setlocale(LC_CTYPE, ".ACP");
wcsupr(s);
setlocale(LC_CTYPE, loc);
}
As long as you feed unicode strings (wchar_t) to your SQL server, you
shouldn't have to worry about locales. You only have to select some locale
to fix that stupid bug of wcsupr.
HTH
Heinz|||Hi
If you always require uppercase then you may think about changing the
data and adding contraints to make sure it is always in uppercase.
Changing you queries may actually be less work than changing the code
especially if you are using stored procedures.
John
Ajey wrote:
> There are many such string. I cannot use sql query for each to just
make it
> a upper case. Is there a way i can find out exact local the SQL
Server is
> using or is there any documentation of which API UPPER function insql
uses.
> "John Bell" <JohnBell@.discussions.microsoft.com> wrote in message
> news:E55039D7-F207-4131-AF23-4E603E29A38D@.microsoft.com...
retrieving/saving
> the
'Men=FC'.
> I
converted
> to =DC.
function
> before
setting. The
the
> target
> converting
characters. I
OEM
> code
page
> and|||"Ajey" <ajey5@.hotmail.com> schrieb im Newsbeitrag =
news:e6a6QnRNFHA.3328@.TK2MSFTNGP14.phx.gbl...
> Is the setting applicable to current thread only or to entire program =
(all
> threads)?
The code looks like it should be thread specific. Give it a try...
HTH
Heinz

No comments:

Post a Comment