TBFileField.AsString with unicode

Discussion of open issues, suggestions and bugs regarding ODAC (Oracle Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
jdorlon
Posts: 202
Joined: Fri 05 Jan 2007 22:07

TBFileField.AsString with unicode

Post by jdorlon » Mon 15 Jun 2009 20:47

Hello,

I have an 11g database with AL32UTF8 characterset. I am using ODAC 6.7 with Delphi 2009. I have OraCall.OCIUnicode = True and TOraSession.Options.UseUnicode = true.

I created this folder on my windows server: C:\bfiles
I put a file in it called test.txt, which is encoded as UTF8 and has chinese characters.

I created this directory on my database: CREATE OR REPLACE DIRECTORY TEST_DIR AS 'C:\bfiles';

I have this table:

create table bfile_test
(col1 number,
bfile_col bfile,
comment_col varchar2(30);

and I inserted this row:

INSERT INTO bfile_test
VALUES (1, bfilename('TEST_DIR' , 'test.txt'), 'test');

commit;

now, I use a TSmartQuery and do a select * from bfile_test. When this code executes....

var
BF: TBFileField;
s: String;
begin
BF := query.FieldByName('BFILE_COL');
s := BF.AsString;
end;

....S now contains garbled data. I also tried BF.AsWideString - which gives me different data, but still garbled.

Is this a bug or am I doing something wrong?

Thanks,

John

Plash
Devart Team
Posts: 2844
Joined: Wed 10 May 2006 07:09

Post by Plash » Tue 16 Jun 2009 09:56

BFILE is treated as binary (not character) data. So ODAC returns the data from BFILE as is. When you use the AsString property, you get data in UTF-8 encoding.

You should decode the data yourself (using the UTF8Decode function, for example).

jdorlon
Posts: 202
Joined: Fri 05 Jan 2007 22:07

Post by jdorlon » Tue 16 Jun 2009 17:03

I was able to save it to a file and process it from there. thanks for your help.

Post Reply