extra space

Discussion of open issues, suggestions and bugs regarding ODAC (Oracle Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
sinys
Posts: 186
Joined: Tue 21 Feb 2012 03:44

extra space

Post by sinys » Sun 01 Oct 2017 17:04

Hello,
Berlin + odac 10.1.3

I see extra space in DBGrid (that I don't expect), I did the demo for your

Code: Select all

procedure TForm1.Button1Click(Sender: TObject);
begin
  OraSession1.Connect;
  OraQuery1.SQL.Text := 'create table test_tab(x char(2 byte))';
  OraQuery1.ExecSQL;

  OraQuery1.SQL.Text := 'insert into test_tab values(''щ'')';
  OraQuery1.ExecSQL;

  OraQuery1.SQL.Text := 'select x, dump(x), (select value from v$nls_parameters where parameter = ''NLS_CHARACTERSET'') from test_tab';
  OraQuery1.Options.TrimFixedChar := False;
  OraQuery1.Open;

  ShowMessage('"' + OraQuery1.Fields[0].asstring + '" ' + OraQuery1.Fields[1].asstring + ' ' + OraQuery1.Fields[2].asstring);
  // "щ " Typ=96 Len=2: 195,185 AL32UTF8
end;
It is a simple example where I have AL32UTF8 character set in my database and I created a table with 2 bytes Char column. Next I inserted a symbol that takes 2 bytes in AL32UTF8. Next I switched off TrimFixedChar parameter. When I select from this table I expect to see 1 char without extra space because the field for 2 bytes and my symbol takes 2 bytes but I see 2 chars like my symbol takes 1 byte.

MaximG
Devart Team
Posts: 1822
Joined: Mon 06 Jul 2015 11:34

Re: extra space

Post by MaximG » Wed 04 Oct 2017 12:43

When retrieving the X field value of the test_tab table according to your sample, TStringField of the fixed length will be created and it will have the size of 2.
This value is maximum possible for characteres storage in the X field. The values with the size less than 2 will be added with spaces to fixed length.
When using OraQuery.Options.TrimFixedChar := False, you get a value added with spaces, and when OraQuery.Options.TrimFixedChar := True - these spaces will be absent in the returned value. This is correct behavior.

sinys
Posts: 186
Joined: Tue 21 Feb 2012 03:44

Re: extra space

Post by sinys » Thu 05 Oct 2017 06:41

I agree that it is correct behavior for 1 byte char like number(0-9) or american(a-z), in this situation for this field we need to show char + space but if char take 2 byte (a lot of chars) we need to see only 1 char (without extra space).

MaximG
Devart Team
Posts: 1822
Joined: Mon 06 Jul 2015 11:34

Re: extra space

Post by MaximG » Wed 11 Oct 2017 13:22

Value 2 is the maximum possible value for storing characters in the X field (for both single-byte and 2-byte characters).
We cannot create TStringField with different Size values, depending on the size of the data returned in each row of this field

Post Reply