Delphi XE, Firebird and UTF8

烂漫一生 提交于 2019-12-07 13:36:49

问题


I'm upgrading a D7 program to XE, and under Delphi 7 I had code like this...

ParamByName ('Somefield').AsString:=someutf8rawbytestring;

Under XE if someutf8rawbytestring contains unicode characters such as Cyrillic script, then they appear as ???? in the DB.

I see that someutf8rawbytestring is 8 characters long, for my 4 character string, which is correct. But in the DB there are just four characters.

I'm using Firebird 2 through TIBQuery with XE and updating a Varchar field with character type 'NONE'.

So what it looks like is that the utf8 is being detected and converted somehow back to unicode data points, and then that is failing a string conversion for the DB. I've tried setting the varchar field to UTF8 encoding but with the same result.

So how should this be handled?

EDIT: I can use a database tool and edit my DB field to have some non-ASCII data and when I read it back it comes as a utf8 encoded string that I can use UTF8decode on and it's correct. But writing data back to this field seems impossible without getting a bunch of ???? in the DB. I've tried ParamByName ('Somefield').AsString:=somewidestring; and ParamByName ('Somefield').AsWideString:=somewidestring; and I just get rubbish in the DB...

EDIT2: Here's the code (in one iteration) ...



procedure TFormnameEdit.savename(id : integer);
begin
    With DataModule.UpdateNameQuery do begin
        ParamByName ('Name').AsString:=UTF8Encode(NameEdit.Text);
        ParamByName ('ID').AsInteger:=id;
        ExecSQL;
        Transaction.Commit;
    end;
end;


回答1:


As @Lightbulb recommended, adding lc_ctype=UTF8 to the TIBDatabase params solved the problem.



来源:https://stackoverflow.com/questions/10892779/delphi-xe-firebird-and-utf8

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!