WideStrings in SQL property of TOraQuery (Unicode,Chinese)

Discussion of open issues, suggestions and bugs regarding ODAC (Oracle Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
hexapole
Posts: 2
Joined: Mon 25 Feb 2008 15:25

WideStrings in SQL property of TOraQuery (Unicode,Chinese)

Post by hexapole » Mon 25 Feb 2008 15:47

I am capable of retrieving multi byte characters (Chinese) from the Oracle database by simply putting TOraSession.Options.UseUnicode to True. I am showing the values by the use of Unicode Components for Delphi. Works perfect!

Now I also need to be able to insert multi byte characters. Again i use the Unicode Components (the Text property of this component is of type WideString).

As the SQL property of TOraQuery is of type TStrings all my multi byte characters turn into question marks.

Is there a solution for this which I have overlooked??

Many thanks!

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

Post by Plash » Tue 26 Feb 2008 08:09

You can use parameters to insert Chinese characters. For example:

Code: Select all

  OraQuery.SQL.Text := 'insert into table1(f1) values (:f1)';
  OraQuery.ParamByName('F1').ParamType := ptInput;
  OraQuery.ParamByName('F1').DataType := ftWideString;
  OraQuery.ParamByName('F1').AsWideString := TntEdit1.Text;
  OraQuery.Execute;

hexapole
Posts: 2
Joined: Mon 25 Feb 2008 15:25

Post by hexapole » Tue 26 Feb 2008 09:38

First of all, may thanks for your quick response explaining how we should deal with this!

I am not sure how to create parameters in design time so I used the CreateParam function to create the parameter and set its properties. I first tried the following:

In the Init of my Datamodule I put:

OraQuery.Params.Clear();
OraQuery.Params.CreateParam(ftWideString, 'f1', ptInput);


Calling the Insert:

OraQuery.SQL.Text := 'insert into table1(f1) values (:f1)';
OraQuery.ParamByName( 'f1' ).AsWideString := Edit1.Text;
OraQuery.Execute;


The first time I call the procedure containing the Insert it indeed works (that’s a relief :D )!
Second time (and following), again question marks are written into the DB.

I have to extend the Insert procedure to make it work:

OraQuery.SQL.Text := 'insert into table1(f1) values (:f1)';
ParamByName( 'f1' ).ParamType := ptInput;
ParamByName( 'f1' ).DataType := ftWideString;
OraQuery.ParamByName( 'f1' ).AsWideString := Edit1.Text;
OraQuery.Execute;


How come the parameter losses its settings?

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

Post by Plash » Tue 26 Feb 2008 10:15

Parameters are created automatically when you assign a value to SQL property. You don't need to call Clear and CreateParam method.
You only need to set ParamType and DataType properties. You should assign values to SQL property of TOraQuery and to ParamType and DataType properties of TOraParam only once, for example, in the initialization of your datamodule.

To insert a value you need only assign this value to AsWideString property and call Execute method.

At design time double click the TOraQuery component to open the TOraQuery editor. Write SQL and then go to Parameters tab. You can set ParamType and DataType properties of parameters there.

Post Reply