Reading and writing unicode strings to database
Posted: Wed 03 Aug 2005 12:27
Hi,
I have some basic problems with write and read unicode strings to db. I know that it is lame, but if u could help me that would be great.
lets create a table is sql for example:
create table testtbl (a number, b nvarchar2(40))
;we use oracle server 9 and client 9. and Borland C++ Builder 6 by the way.
writing:
WideString ws;
... //initialize the ws with a eg. string containing Russian characters
// I set the OraSession1->Options->UseUnicode to true in design time
OraQuery1->SQL->Clear();
OraQuery1->SQL->Add("insert into testtbl values (:nr, :wstr)");
OraQuery1->ParamByName("nr")->AsInteger=7;
OraQuery1->ParamByName("wstr")->AsWideString=ws;
OraQuery1->Execute();
well it write some thing to the db, but I dont know if it is unicoded or not, because i see only ???? instead of the string in the db viewer.
But I cannot read it back anyway.
reading:
OraQuery1->SQL->Clear();
OraQuery1->SQL->Add("select a, b from testtbl");
OraQuery1->Open();
while(!OraQuery1->Eof)
{int i=OraQuery1->FieldsByName("A")->AsInteger; //ok i==7
WideString ws2=OraQuery1->FieldsByName("B")->AsWideString;
//error: TField dont have the AsWideString property.
//If I use the AsString then ws=="??????"
//I realized that BCB's TWideString dont have the AsWideString property as well
//I saw that the TOraDataSet class (which is what the TQuery uses) has a lot of GetFile, GetLob, GetInterval... methods but there is no GetWideString
//How read back the widestring, (and did i wrote it to the db correctly)
}
Waiting for your kindly reply
Gabor
I have some basic problems with write and read unicode strings to db. I know that it is lame, but if u could help me that would be great.
lets create a table is sql for example:
create table testtbl (a number, b nvarchar2(40))
;we use oracle server 9 and client 9. and Borland C++ Builder 6 by the way.
writing:
WideString ws;
... //initialize the ws with a eg. string containing Russian characters
// I set the OraSession1->Options->UseUnicode to true in design time
OraQuery1->SQL->Clear();
OraQuery1->SQL->Add("insert into testtbl values (:nr, :wstr)");
OraQuery1->ParamByName("nr")->AsInteger=7;
OraQuery1->ParamByName("wstr")->AsWideString=ws;
OraQuery1->Execute();
well it write some thing to the db, but I dont know if it is unicoded or not, because i see only ???? instead of the string in the db viewer.
But I cannot read it back anyway.
reading:
OraQuery1->SQL->Clear();
OraQuery1->SQL->Add("select a, b from testtbl");
OraQuery1->Open();
while(!OraQuery1->Eof)
{int i=OraQuery1->FieldsByName("A")->AsInteger; //ok i==7
WideString ws2=OraQuery1->FieldsByName("B")->AsWideString;
//error: TField dont have the AsWideString property.
//If I use the AsString then ws=="??????"
//I realized that BCB's TWideString dont have the AsWideString property as well
//I saw that the TOraDataSet class (which is what the TQuery uses) has a lot of GetFile, GetLob, GetInterval... methods but there is no GetWideString
//How read back the widestring, (and did i wrote it to the db correctly)
}
Waiting for your kindly reply
Gabor