Automatic TxStringField size adjustment and Unicode

Discussion of open issues, suggestions and bugs regarding ODAC (Oracle Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
cis-wurzen
Posts: 75
Joined: Tue 04 Jan 2005 10:26

Automatic TxStringField size adjustment and Unicode

Post by cis-wurzen » Tue 14 Jun 2011 08:41

I've recently created a real Unicode branch of the app and noticed that the automatic field size adjustment is not available for TWideStringField.

Steps:
- create a new VCL app
- add a TOraSession and TOraQuery querying a table with a string field
- add a component for the string field using the Fields Editor and lower the Size property of the TStringField
- add a button that opens the query and shows afterwards the Size property of the TStringField component (see my test code below)
- run the app
- press the button and see that the Size property of the TStringField component is equal to the actual size in the database
- close the app
- enable Options.UseUnicode in the TOraSession
- change TStringField to TWideStringField in the .PAS and .DFM file
- run the app again
- press the button

Expected: the Size property of the TStringField component is equal to the actual size in the database
Actual: the Size property of the TStringField component is *not* equal to the actual size in the database

Code: Select all

procedure TForm1.Button1Click(Sender: TObject);
const
  ExpectedSize = 50;
var
  Counter: Integer;
begin
  Counter := 0;
  if OraQuery1FOO.Size  ExpectedSize then
    Inc(Counter);
  OraQuery1.Open;
  if OraQuery1FOO.Size = ExpectedSize then
    Inc(Counter);
  if Counter = 2 then
    ShowMessage('PASS')
  else
    ShowMessage('FAIL');
end;
In order to fix the problem I've changed line 916 in MemDS.pas (most recently release 7.20.0.6) in TMemDataSet.InternalOpen from

Code: Select all

      if FieldDefs[i].DataType = ftString then begin
to

Code: Select all

      if FieldDefs[i].DataType in [ftString, ftWideString] then begin

AlexP
Devart Team
Posts: 5530
Joined: Tue 10 Aug 2010 11:35

Post by AlexP » Tue 14 Jun 2011 13:38

Hello,

Thank you for the information, we have reproduced the problem.
We will consider what kind of behaviour is more appropriate - to bring the size of the ftWideString text field to its real size or leave the size of ftString as it was specified manually.

GeluHUN
Posts: 7
Joined: Thu 28 Jul 2011 07:46
Location: Budapest, Hungary

Post by GeluHUN » Mon 22 Aug 2011 14:17

Hi!

I just wanted to open a new topic about a bug(?) in ODAC: a query's fields' Size property is automaticaly set when you open the query, even if you have created the field object manualy and have set the size property to a specific value.

See the following simple code: create a query, create a string field object manualy, and set the size to 10. The sample SQL will select a larger string however, and instead of truncating the result, ODAC sets the field size to a bigger value.

Code: Select all

procedure TForm1.FormCreate(Sender: TObject);
begin
  OraSession1.Connect;
  OraQuery1.SQL.Text := 'select ''one-two-three-four'' as the_field from dual';
  OraQuery1THE_FIELD.Size := 10;
  Label1.Caption := Format('Field size=%d; Display width=%d; SQL="%s"', [OraQuery1THE_FIELD.Size, OraQuery1THE_FIELD.DisplayWidth, OraQuery1.SQL.Text]);
  OraQuery1.Open;
  OraQuery1.First;
  Label2.Caption := Format('Field size=%d; Display width=%d; Field Value="%s"; Value length=%d', [OraQuery1THE_FIELD.Size, OraQuery1THE_FIELD.DisplayWidth, OraQuery1THE_FIELD.AsString, Length(OraQuery1THE_FIELD.AsString)]);
end;
Setting the Field.Size changes the field's DisplayWidth property too, and triggers all DBGrid.Column.Width to be re-set (if it has the default value), thus changing a design time setup DBGrid's look and feel at run-time.

Maybe some global Boolean option would be better (either in OraSession or in DataSet), that could control this behaviour?

Best regards,
Peter

GeluHUN
Posts: 7
Joined: Thu 28 Jul 2011 07:46
Location: Budapest, Hungary

Post by GeluHUN » Fri 02 Sep 2011 09:17

Dear Devart Team,

are there any news or followups about this behavior?

Peter

AlexP
Devart Team
Posts: 5530
Joined: Tue 10 Aug 2010 11:35

Post by AlexP » Fri 02 Sep 2011 11:32

Hello,

We will try to add a property that will be responsible for such behaviour (concerning usage real or user-defined size) in one of the next versions.

Post Reply