Page 1 of 1

orac and unicode?

Posted: Wed 06 May 2009 13:15
by albourgz
Dear all,

I use bcb2009. I have a (unicode) TEdit with hebraic characters in it.
I have a button, clicking the button generates a unicode string containing
L"update owner.table set column='"+TEdit1->Text+L"' where id=2345"

The oracle column type is NVARCHAR2(50);

This string is copied into the TQuery's SQL statement and executed, one row updated, no error.

Problem: when re-reading the field (UnicodeString s=Query->FieldValues["column"]), I receive question marks and not unicode text.
Selecting in oracle does this, also. :shock:

why why why?

NVarchar2 is supposed to store unicode, no matter what is the db character set.. Why didn't odac update the column to unicode?

Regards,
Alain

Posted: Thu 07 May 2009 07:22
by Plash
Unicode support in SQL statements is disabled by default because of OCI bugs.

We recommend using a parameter with DataType = ftWideString. For example:

Code: Select all

OraQuery->SQL->Text = "UPDATE Table1 SET Column1 = :Column1 WHERE id = 2345";
OraQuery->ParamByName("Column1")->DataType = ftWideString;
OraQuery->ParamByName("Column1")->Value = TEdit1->Text;
You should set the UseUnicode option of TOraSession to True to read the data you have inserted as Unicode.

You can also enable Unicode support in SQL statements:
- include OraCall.hpp to one of your source files;
- set the OCIUnicode global variable to True before opening first connection.

UseUnicode causes problems

Posted: Fri 08 May 2009 12:02
by albourgz
The application I am writing should be able to read hebrew in database.
"You should set the UseUnicode option of TOraSession to True to read the data you have inserted as Unicode."
-> I tried setting UseUnicode to true and I get the following problem:
SQL> desc cec.prod_ref_cli
Name Null? Type
----------------------------------------- -------- ---------------

IDCLIENT NOT NULL NUMBER(10)
IDPROD NOT NULL NUMBER(10)
REF NOT NULL VARCHAR2(30)
COMMENTAIRE VARCHAR2(50)
I get an error running
SELECT REF FROM CEC.PROD_REF_CLI WHERE IDPROD=:1 AND IDCLIENT=:2
Because the TField associated is of thte TStringField and not TWideStringField.

However, the field is varchar2 with english text!

So it seems that with this setting, all varchar2 have to be considered as unicode, not only NVARCHAR2 (and all TStringFields have to be converted to TWideStringField).

Posted: Tue 12 May 2009 07:25
by Plash
Yes, with UseUnicode=True TWideStringField is used for all string fields.

You should recreate fields on your forms if you need to read data in Unicode.

You can use two TOraSession components: one with UseUnicode=False, and the second with UseUnicode=True. This allows you not to convert all your forms.