#1 2013-10-24 00:52:44

畅雨
Member
Registered: 2013-10-24
Posts: 29

UTF8ToWideChar problem :do not support some Asian languages,eg:chinese

hi,ad

     I use synoledb, when SQL include some Asian languages(Double-byte characters),then  SQLW is Wrong. zeos,sqlite3,firedac has same problem.

-----> in synoledb.pas line 1480
  procedure TOleDBStatement.Prepare(const aSQL: RawUTF8;
  ExpectResults: Boolean);   
    begin

      ...
    SetLength(SQLW,L*2+1);
    UTF8ToWideChar(pointer(SQLW),pointer(fSQL),L); ----------------- this!
    fCommand.SetCommandText(DBGUID_DEFAULT,pointer(SQLW));

    end

    when fSQL  include some Asian languages(Double-byte characters),then  SQLW is Wrong.

   
   eg:
        fSQL ='select 'changyu畅雨'  as name '
        but  Converted to  SQLW ='select 'chan '

 ------->  symCommons   line  9432 
     function UTF8ToWideChar(dest: pWideChar; source: PUTF8Char; sourceBytes: PtrInt=0): PtrInt; 
       begin
          ...
       c := pCardinal(source)^;
       if (c and $80808080<>0)then    -------------not support some Asian languages(Double-byte characters)
              break; // break on first non ASCII quad
          ...     
       end

Offline

#2 2013-10-24 05:22:55

畅雨
Member
Registered: 2013-10-24
Posts: 29

Re: UTF8ToWideChar problem :do not support some Asian languages,eg:chinese

Problem solved, before Execute(SQL,[]) just AnsiToUtf8() :Execute(AnsiToUtf8(SQL),[])

Offline

#3 2013-10-24 09:31:21

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,655
Website

Re: UTF8ToWideChar problem :do not support some Asian languages,eg:chinese

Yes, as stated by the documentation, everywhere in mORMOt classes (including SynDB units), you have to use RawUTF8 kind of string, not plain AnsiString.

so you have to use AnsiToUtf8() if your text is AnsiString.
or even better, StringToUTF8() which is Unicode-ready, so will work with any version of Delphi.

Offline

#4 2013-10-24 10:04:33

畅雨
Member
Registered: 2013-10-24
Posts: 29

Re: UTF8ToWideChar problem :do not support some Asian languages,eg:chinese

thanks smile   mORMot Framework is great!

Offline

Board footer

Powered by FluxBB