I have FB3 database with this table created:
CREATE TABLE BOLNAMEN
(
ID BIGINT GENERATED BY DEFAULT AS IDENTITY NOT NULL,
NAAMID VARCHAR( 6) NOT NULL COLLATE UTF8,
BOLKORT VARCHAR( 4) COLLATE UTF8,
NAAM VARCHAR( 35) COLLATE UTF8,
TYP VARCHAR( 4) COLLATE UTF8,
CONSTRAINT PK_BOLNAMEN PRIMARY KEY (ID)
);
My idea is getting the attributes from the table using this piece of code:
procedure TMyDatabase.LoadAttributes;
var index : integer;
Fielddef : TobjFielddef;
begin
fSQLQuery.First;
for index := 0 to fSQLQuery.Fields.Count -1 do
begin
Fielddef := TobjFielddef.Create;
Fielddef.fieldname := lowercase(fSQLQuery.Fields[index].FieldName);
Fielddef.varlength := fSQLQuery.Fields[index].DataSize;
Fielddef.datatype := GetEnumName(TypeInfo(TFieldType), Ord(fSQLQuery.Fields[index].DataType));
ObjFielddeflist.Add(Fielddef);
end;
end;
This code can be used by every type of database.
If I look at the length of the field, this is the result:
naam : id
len : 8
type : ftLargeint
naam : naamid
len : 25
type : ftString
naam : bolkort
len : 17
type : ftString
naam : naam
len : 141
type : ftString
naam : typ
len : 17
type : ftString
The field nameid should has the length of 6 instead of 25. It's logical, because the calculation is made by UTF-8 characters.
Can I use TSQLQuery to read the right length of a field or do I have to use somekind different?