Code: Select all
Insert;
FieldByName('Name').AsString := 'A name';
Post;
The table I want to insert into is very simple (got a index and two text fields), but it has an auto increment key field and that seems to be the problem. If I change to a SQLite database instead and do the exact same, it works without problems.
I'm using ZeosLib 6.6.4-stable but have also tried some of the 7.0.0 test builds with the same result. After doing some debugging I came up with the following fix by adding the line "and (not Metadata.IsAutoIncrement(I))" in DefineInsertColumns in the ZGenericCachedResolver class:
Code: Select all
procedure TZGenericCachedResolver.DefineInsertColumns(Columns: TObjectList);
var
I: Integer;
begin
{ Precache insert parameters. }
if InsertColumns.Count = 0 then
begin
for I := 1 to Metadata.GetColumnCount do
begin
if (Metadata.GetTableName(I) <> '') and (Metadata.GetColumnName(I) <> '')
and (not Metadata.IsAutoIncrement(I))
and Metadata.IsWritable(I) then
begin
InsertColumns.Add(TZResolverParameter.Create(I,
Metadata.GetColumnName(I), Metadata.GetColumnType(I), True, ''));
end;
end;
end;
{ Use cached insert parameters }
CopyResolveParameters(InsertColumns, Columns);
end;
Have anybody similar experiences? If so, is there a more 'correct' way through? Is there some setups that I've missed?