Re: CDatabase and UNICODE problem

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



Thank you for quick answer.

David Wilkinson wrote:
Can you store UTF-8 strings in the database? You can use
WideCharToMultiByte() to convert from "Unicode" to UTF-8.


I think I can store UTF-8 strings in the database because it is a
simple access file (.mdb).

Let me explain my problem a little deeper.
I was using this piece of code to send queries (altered to be more
clear):

sSQL = "INSERT statement with unicode characters in it like öçgs";
myDatabase.ExecuteSQL(sSQL);

After inserting some rows to DB, I looked at what is inserted, and all
the special characters are converted to their equivalents like ö->o
ç->c g->g s->s
Then I traced into ExecuteSQL() method and saw this (in dbcore.cpp):

AFX_ODBC_CALL(::SQLExecDirect(hstmt, (UCHAR*)T2A((LPTSTR)lpszSQL),
SQL_NTS));

Any unicode string I provide is converted to it's ansi equivalent via
T2A() macro. I thought that I could do nothing about it but I tried to
use WideCharToMultiByte() after you adviced me to do so.

Now my code became this:

sSQL = "INSERT statement with unicode characters in it like öçgs";
Bytes = new char[sSQL.GetLength() + 1];
WideCharToMultiByte(CP_UTF8,0,sSQL,-1,Bytes,sSQL.GetLength()+
1,NULL,NULL);
myDatabase.ExecuteSQL((LPCTSTR)Bytes);
delete [] Bytes;

But when I try to execute it throws an exception, m_strError of
exception is {"COUNT field incorrect "}.

I have no clues what to do so, I need help very badly.

Thank you for your answers.

.



Relevant Pages

  • Re: WM_CHAR Unicode and Code Page
    ... I have used WideCharToMultiByte. ... I change to the russian keyboard, input a character and run it through ... the conversion from the unicode to the single byte char ... WideCharToMultiByte function but I also need the current keyboards ANSI code ...
    (microsoft.public.win32.programmer.ui)
  • Re: how to open filename with CString?
    ... I implemented the WideCharToMultiByte() function and got it to work, ... length when I examined the string in debug. ... Can you recommend a good reference for Unicode? ... >> would you open a filename if the name were specified as a CString? ...
    (microsoft.public.windowsce.embedded.vc)
  • Re: Supporting Japanese and Chinese
    ... I assume you already have a Unicode string and you need to set it as an ANSI ... OutlookSpy - Outlook, CDO ... > call WideCharToMultiByte, ...
    (microsoft.public.win32.programmer.messaging)
  • Konvertierung von "HTML Entities"
    ... in denen Sonderzeichen als sogenannte HTML ... diese Texte in die aktuelle Codepage zu übersetzen (mit WideCharToMultiByte und MultiByteToWideChar bin ich auf keinen grünen Zweig gekommen). ... Mir fällt leider nichts besseres ein, als die Hex-Werte in einer Tabelle aufzuspüren, aber das sollte doch auch einfacher gehen. ... Um diese darzustellen, wird es ja keinen Umweg um Unicode geben, oder irr ich mich da? ...
    (microsoft.public.de.vc)