Recent

Author Topic: Firebird character fields with UTF8 connection charset  (Read 1344 times)

tonyw

  • Full Member
  • ***
  • Posts: 174
    • MWA Software
Re: Firebird character fields with UTF8 connection charset
« Reply #15 on: July 25, 2020, 05:46:51 pm »
Complete ignorance. In a database (storage) the UTF8 really needs to store four bytes.
Correct. That is what Firebird does. The issue under discussion is the byte length of a Pascal AnsiString.

The problem was that when a fixed length string is stored by Firebird, if the UTF8 encoded byte length is less than the allocated column storage then Firebird right pads it with space characters. If the database driver (e.g. IBX) does not truncate the string so that the number of UTF8 characters matches the character width of the column then the UTF8Length of the AnsiString will be longer than it should be. This is at best misleading. At worst, if the user tried to write back the same string (as returned from the database), they would get a string too long error.

Soner

  • Full Member
  • ***
  • Posts: 193
Re: Firebird character fields with UTF8 connection charset
« Reply #16 on: July 25, 2020, 06:29:06 pm »
I am using ZEOS-components and Ii definied characterfields as varchar utf-8. TFIeld reverses 4 byte for each charakter.

The problem with utf8 fields is you can never know how length your text can be.

I solved the problem with TDBEdit by setting TEDBedit.MaxLength to the right length manually.
Also I modified TDBGrid to set fieldlength:
Code: Pascal  [Select][+][-]
  1. // usage MyDBGrid.Columns[n].Fieldlength
  2. dbgrids.pas
  3.   TColumn = class(TGridColumn)
  4.   private
  5.     fFieldLength: integer; //soner added
  6.   //..
  7.   public
  8.     property FieldLength: integer read fFieldLength write fFieldLength default 0; //soner added for manipulate fieldlength, especially to solve problem with unicode problem fieldlenghtx4!
  9.   end;
  10.  
  11. procedure TCustomDBGrid.SelectEditor;
  12. //..
  13.     if (SelectedField is TStringField) then begin //soner add: begin
  14.       if SelectedColumn.FieldLength=0 then aMaxLen := SelectedField.Size //soner add: if SelectedColumn.FieldLength=0 then
  15.       else aMaxLen := SelectedColumn.FieldLength; //soner add: else aMaxLen := SelectedColumn.FieldLength;
  16.     end //soner add: end
  17.     else
  18.       aMaxLen := 0;  
  19.  

emilt

  • New Member
  • *
  • Posts: 20
Re: Firebird character fields with UTF8 connection charset
« Reply #17 on: July 25, 2020, 07:13:36 pm »
Do you have a specific problem in mind as a result of the change?
No.
I am creating IBQuery components programatically, and I expected that since CheckParams is True by default, the Params would be created when I set the SQL.Text. (TSQLQuery does so). When I found out that they are not, I actually commented out the "if" part I was referring to, so that FParams.ParseSQL is called always, not only when State is csDesigning. It seems to work at the moment, so I was wondering why it had to be otherwise. Of course, in my case I only set SQL.Text once, maybe there would be a problem if Params are not empty and have to be re-created.
But, to be on the safe side, I will probably reverse this change and start calling Prepare after setting SQL.Text as you suggest.

 

TinyPortal © 2005-2018