[freetds] Unicode strings in queries

ZIGLIO, Frediano, VF-IT Frediano.Ziglio at vodafone.com
Thu Aug 17 05:15:26 EDT 2006


> 
> Hello, everybody!
> 
> I know that UNICODE issues have been discussed a lot in this 
> mailing list,
> but I haven't managed to find solution to my particular 
> problem, though I
> have rummaged about in all threads.
> 
> I have C++ client working under FreeBSD and MS SQL. I call 
> procedures from
> C++ client, which require NVARCHAR parameters. My client 
> program operates
> with wide char strings (uses wchar_t and wstring). The 
> problem is that I
> don't know how to build and execute query which contains wide char
> parameters.
> 
> I need something like that:
> 
> const wchar_t* query = L"EXEC SomeProc 'national_symbols_here'";
> tds_submit_query(query);
> 
> But tds_submit_query expects only 1-byte strings, so I have 
> no idea how to
> implement it.
> 

libTDS work with multi-byte strings. It does not work with wide one
(like utf-16, ucs-2, ucs-4 and similar) but can work with unicode like
utf-8.

> I know TDS uses UCS-2 encoding in its protocol. I would be 
> glad to convert
> all my strings to UCS-2 and pass it to FreeTDS functions but, 
> again, I don't
> know how to do that. 

Currently is not possible. However you can use utf-8 and lead libTDS do
the conversion.

> My program is supposed to be multi-language so I can't afford 
> to myself to
> stick to one particular codepage. And the most convenient way 
> to handle
> multi-language string is using wchar_t based strings.
> 

Under Unix utf-8 is usually more convenient. It support more characters
than ucs-2 (which mostly use) and is better supported by the system (kde
and gnome for instance can speak utf8).
Support for any encoding is a todo but there is currently no plan.

> Have I missed any obvious solution to my problem? Or may be 
> somebody knows
> some kind of workaround? I have already started to think 
> about encoding all
> string parameters to Base64 and decoding them in database, 
> and this way
> definitely looks UGLY for me.
> 

Please don't :) My stomac is struggling...

> Thank you in advance,
> Kirill
> 

freddy77




More information about the FreeTDS mailing list