[bug_fixed] "List out of bounds" in Metadata
Posted: 08.09.2008, 12:08
I made a function DefineFieldIndexMeta to escape from a bug "List out of bounds" in Metadata. This is because calculated fields do not exist in the metadata (my assumption). It is only suppost to work as a temp solution, because i lack knowledge about zeos.
gr,
Niek
SOLUTION: add/replace code in unit ZAbstractRODataset:
{**
Defines an original field index in the metadata of the dataset, since calcfields and
@param FieldsLookupTable a lookup table to define original index.
@param Field a TDataset field object.
@returns an original fields index or -1 otherwise.
}
function DefineFieldIndexMeta(const FieldsLookupTable: TIntegerDynArray; Field: TField): Integer;
var
I, IndexCorrection: Integer;
begin
Result := -1; IndexCorrection:= 1;
for I := 0 to High(FieldsLookupTable) do
begin
if TField(FieldsLookupTable).FieldKind<>fkData then dec(IndexCorrection);
if FieldsLookupTable = Integer(Field) then
begin
Result := I + IndexCorrection;
Break;
end;
end;
end;
procedure TZAbstractRODataset.InternalPost;
Procedure Checkrequired;
Var I : longint;
columnindex : integer;
begin
For I:=0 to Fields.Count-1 do
With Fields do
Case State of
dsEdit:
if Required and not ReadOnly and (FieldKind=fkData) and IsNull then
raise EZDatabaseError.Create(Format(SNeedField,[DisplayName]));
dsInsert:
if Required and not ReadOnly and (FieldKind=fkData) and IsNull then
begin
// allow autoincrement and defaulted fields to be null;
columnindex := DefineFieldIndexMeta(FieldsLookupTable,Fields);
if not Resultset.GetMetadata.HasDefaultValue(columnIndex) and
not Resultset.GetMetadata.IsAutoIncrement(columnIndex) then
raise EZDatabaseError.Create(Format(SNeedField,[DisplayName]));
end;
End;
end;
begin.........................
gr,
Niek
SOLUTION: add/replace code in unit ZAbstractRODataset:
{**
Defines an original field index in the metadata of the dataset, since calcfields and
@param FieldsLookupTable a lookup table to define original index.
@param Field a TDataset field object.
@returns an original fields index or -1 otherwise.
}
function DefineFieldIndexMeta(const FieldsLookupTable: TIntegerDynArray; Field: TField): Integer;
var
I, IndexCorrection: Integer;
begin
Result := -1; IndexCorrection:= 1;
for I := 0 to High(FieldsLookupTable) do
begin
if TField(FieldsLookupTable).FieldKind<>fkData then dec(IndexCorrection);
if FieldsLookupTable = Integer(Field) then
begin
Result := I + IndexCorrection;
Break;
end;
end;
end;
procedure TZAbstractRODataset.InternalPost;
Procedure Checkrequired;
Var I : longint;
columnindex : integer;
begin
For I:=0 to Fields.Count-1 do
With Fields do
Case State of
dsEdit:
if Required and not ReadOnly and (FieldKind=fkData) and IsNull then
raise EZDatabaseError.Create(Format(SNeedField,[DisplayName]));
dsInsert:
if Required and not ReadOnly and (FieldKind=fkData) and IsNull then
begin
// allow autoincrement and defaulted fields to be null;
columnindex := DefineFieldIndexMeta(FieldsLookupTable,Fields);
if not Resultset.GetMetadata.HasDefaultValue(columnIndex) and
not Resultset.GetMetadata.IsAutoIncrement(columnIndex) then
raise EZDatabaseError.Create(Format(SNeedField,[DisplayName]));
end;
End;
end;
begin.........................