[fpc-devel] TFieldDef.Size vs TField.Size

LacaK lacak at zoznam.sk
Wed Mar 2 14:32:32 CET 2011


> One way is: TField.Size := (TFieldDef.Size div 2) if it's a WideString,
> and div 4 if unicode is enabled. Or the TDataset descendant has to
> correct the value for WideStrings when creating fields. (How?)
>
>   
Very simple/primitive Idea No1:

add property DataSize: integer read GetDataSize write FDataSize; into 
TFieldDef class

add next parameter ADataSize to Constructor TFieldDef.Create(AOwner:
TFieldDefs; const AName: string;
      ADataType: TFieldType; ASize: Integer; ARequired: Boolean;
AFieldNo: Longint
      ADataSize: Integer=0);
which is used in every TSQLConnection descendant to create fielddefs

So connectors can supply ASize="character length" and also 
ADataSize="byte length" , which they require to write/read character 
data into local buffer (each connector should be aware of this 
information ... i.e. encoding of character data which exchanges with DB 
engine)
If not specified , then default =0 means use ASize+1 for ftString,
(ASize+1)*2 for ftWideString ... for backward compatibility,
  for most others datatypes ignore it (because they are internaly stored 
in fixed length data structures).

Each TSQLConnection has CharSet property and each DB engine supports 
limited number of connection charsets. So SQLConnection can read CharSet 
property and determine "character width".
For example if CharSet='UTF-8' then char_width:=3 (or 4)
if CharSet='UCS-2' then char_width:=2
if CharSet='UTF-16' then char_width:=4;

So with conjuction with "Column size" (ASize) can easy compute buffer 
size (ADataSize)

or

Constructor TFieldDef.Create(AOwner:
TFieldDefs; const AName: string;
      ADataType: TFieldType; ASize: Integer; ARequired: Boolean; 
AFieldNo: Longint
      ACharEncoding: TCharEncoding);

TCharEncoding=(cheUnknown, cheAnsi, cheUTF8, cheUTF16);

and then

ADataSize can be computed inside TFieldDef.Create and stored into 
FDataSize for later usage.(as I wrote before TFieldDef.GetDataSize will 
replace TCustomBufDataset.GetFieldSize)

Laco.




More information about the fpc-devel mailing list