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.........................
[bug_fixed] "List out of bounds" in Metadata
Moderators: gto, cipto_kh, EgonHugeist, mdaems
- mdaems
- Zeos Project Manager
- Posts: 2766
- Joined: 20.09.2005, 15:28
- Location: Brussels, Belgium
- Contact:
Hi Niek,
Could you please tell us what the original problem was that you encountered? As you say yourself it's a workaround, we need to know what the real bug to fix is.
You can describe the bug here, but you should post it to http://zeosbugs.firmos.at/ . Please do provide a small demonstration program for the bug. (Project files + a db creation script + eventual steps to show the bug using the demo program)
Mark
Could you please tell us what the original problem was that you encountered? As you say yourself it's a workaround, we need to know what the real bug to fix is.
You can describe the bug here, but you should post it to http://zeosbugs.firmos.at/ . Please do provide a small demonstration program for the bug. (Project files + a db creation script + eventual steps to show the bug using the demo program)
Mark
- mdaems
- Zeos Project Manager
- Posts: 2766
- Joined: 20.09.2005, 15:28
- Location: Brussels, Belgium
- Contact:
Niek,
I committed following change to avoid this problem. I'm not sure it's as performant as your proposed patch, but I think it's safer in case one changes the order of the fields more than just by adding a calculated field. (Imagine select f1,f2, f3 from y, ordered in the columns editor as calc1, f3,calc2, f1,f2) Not sure if the returned indices will correspond to the expected fields in the metadata.
The patch
Please confirm if this works. It's something that can be included in the 6.6-patches branch (and that way into 6.6.4 release), but before I commit to that branch I'd like to have a 'second opinion'.
Mark
I committed following change to avoid this problem. I'm not sure it's as performant as your proposed patch, but I think it's safer in case one changes the order of the fields more than just by adding a calculated field. (Imagine select f1,f2, f3 from y, ordered in the columns editor as calc1, f3,calc2, f1,f2) Not sure if the returned indices will correspond to the expected fields in the metadata.
The patch
Code: Select all
Index: ZAbstractRODataset.pas
===================================================================
--- ZAbstractRODataset.pas (revision 451)
+++ ZAbstractRODataset.pas (working copy)
@@ -2079,9 +2079,10 @@
if Required and not ReadOnly and (FieldKind=fkData) and IsNull then
begin
// allow autoincrement and defaulted fields to be null;
- columnindex := DefineFieldIndex(FieldsLookupTable,Fields[i]);
- if not Resultset.GetMetadata.HasDefaultValue(columnIndex) and
- not Resultset.GetMetadata.IsAutoIncrement(columnIndex) then
+ columnindex := Resultset.FindColumn(Fields[i].FieldName);
+ if (Columnindex = 0) or
+ (not Resultset.GetMetadata.HasDefaultValue(columnIndex) and
+ not Resultset.GetMetadata.IsAutoIncrement(columnIndex)) then
raise EZDatabaseError.Create(Format(SNeedField,[DisplayName]));
end;
End;
Mark