Sunday, April 9, 2006, 10:57:00 PM, you wrote:
> Roman Shchugarev wrote:
>> Hello libpqxx-general,
>>
>> I am developing client application under Win32 using
>> Visual Studio .NET 2k3 the problem I'm facing is:
>> I am not able to get Unicode data from Postgres DB server. What
>> might be the problem?
>> When compiling with unicode libraries, the linker says that there
>> is an undefined external link ....
>> the code that generates this error is:
>> /*
>> for (result::size_type i = 0; i < R.size(); ++i)
>> {
>> wstring xxx;
>> R[i][3].to(xxx);
>> ---- at this point I get an error ....
>> // m_klientu_koks.InsertItem(xxx.c_str());
>> */
>>
>> maybe there is another way of getting field's data, I am new with
>> libpqxx and need some help.
> In general, in these cases it is useful if you also mail the error that
> the compiler or linker shows you.
> BTW, in this case I can give you a hint for the answer: libpqxx doesn't
> support wstring. You'll probably be able to get Unicode out, but it'll
> have to be retrieved using std::string, not std::wstring, and it will be
> UTF-8 encoded. This is just my first guess -- Jeroen may be able to tell
> you more.
> Cheers,
> Bart
Thanks for a tip BART I've managed to get out a Unicode data using these
simple functions (WideCharToMultiByte/MultiByteToWideChar):
string toNarrowString( const wchar_t* pStr , int len )
{
ASSERT( len >= 0 || len == -1 , _T("Invalid string length: ") << len ) ;
// figure out how many narrow characters we are going to get
int nChars = WideCharToMultiByte( CP_UTF8 , 0 ,
pStr , len , NULL , 0 , NULL , NULL ) ;
if ( len == -1 )
-- nChars ;
if ( nChars == 0 )
return "" ;
string buf ;
buf.resize( nChars ) ;
WideCharToMultiByte( CP_UTF8 , 0 , pStr , len ,
const_cast<char*>(buf.c_str()) , nChars , NULL , NULL ) ;
return buf ;
}
wstring toWideString( const char* pStr , int len )
{
ASSERT( len >= 0 || len == -1 , _T("Invalid string length: ") << len ) ;
// figure out how many wide characters we are going to get
int nChars = MultiByteToWideChar( CP_UTF8 , 0 , pStr , len , NULL , 0 ) ;
if ( len == -1 )
-- nChars ;
if ( nChars == 0 )
return L"" ;
wstring buf ;
buf.resize( nChars ) ;
MultiByteToWideChar( CP_UTF8 , 0 , pStr , len ,
const_cast<wchar_t*>(buf.c_str()) , nChars ) ;
return buf ;
}
Thanks again!
--
Best regards,
inbox mailto:[EMAIL PROTECTED]
_______________________________________________ Libpqxx-general mailing list [email protected] http://gborg.postgresql.org/mailman/listinfo/libpqxx-general
