Page 1 of 1
Using KeyGenerator in an insert on TIBCTable
Posted: Mon 12 Nov 2012 17:32
by MahoneyH
Code: Select all
FBTable := TIBCTable.Create(nil);
FBTable.Connection := DataMod.FBConnection;
FBTable.Active := false;
FBTable.GeneratorMode := gmPost;
FBTable.TableName := TableName;
FBTable.KeyFields := IDColumn;
FBTable.KeyGenerator := SequenceName;
try
FBTable.Active := true;
FBTable.Insert;
for i := 0 to High(Params) do
begin
FBTable.FieldByName(Params[i].Name).AsVariant := Params[i].Value;
end;
FBTable.Post;
except
on E: Exception do
begin
FBTable.Active := false;
FBTable.Free;
ShowMessage(E.ClassName + ' ' +E.Message + ' TableName: ' + TableName);
end;
end;
Result := FBTable.FieldByName(IDColumn).AsInteger;
FBTable.Active := false;
FBTable.Free;
Re: Using KeyGenerator in an insert on TIBCTable
Posted: Mon 12 Nov 2012 17:42
by MahoneyH
Sorry. That first post got away from me.
I have the following code which works fine in Delphi 2009, but not in Delphi XE2. The generated ID variable is not created from the generator. It is always 0. I wonder if the syntax is any different in the new IBDAC. The Delphi XE2 is IBDAC 4.5.9. The Delphi 2009 is 3.10 or something like that.
I'm not sure the best way to debug this problem.
Thanks
Hardee Mahoney
Washington, DC
Code: Select all
FBTable := TIBCTable.Create(nil);
FBTable.Connection := DataMod.FBConnection;
FBTable.Active := false;
FBTable.GeneratorMode := gmPost;
FBTable.TableName := TableName;
FBTable.KeyFields := IDColumn;
FBTable.KeyGenerator := SequenceName;
try
FBTable.Active := true;
FBTable.Insert;
for i := 0 to High(Params) do
begin
FBTable.FieldByName(Params[i].Name).AsVariant := Params[i].Value;
end;
FBTable.Post;
except
on E: Exception do
begin
FBTable.Active := false;
FBTable.Free;
ShowMessage(E.ClassName + ' ' +E.Message + ' TableName: ' + TableName);
end;
end;
Result := FBTable.FieldByName(IDColumn).AsInteger;
FBTable.Active := false;
FBTable.Free;
Re: Using KeyGenerator in an insert on TIBCTable
Posted: Tue 13 Nov 2012 11:08
by AndreyZ
In 3.50.0.19, we changed behaviour when TCustomIBCDataSet.GeneratorMode = gmPost. Starting from IBDAC 3.50.0.19, a value from a generator is not used if any value was inputted into the key field. To avoid the problem, you should not input any value into the key field. In this case, a value for the key field will be taken from the generator.
Re: Using KeyGenerator in an insert on TIBCTable
Posted: Tue 13 Nov 2012 12:00
by MahoneyH
Thanks!
I just determined that was the case. It is nice to see it confirmed.
Thanks for your response.
Hardee
Re: Using KeyGenerator in an insert on TIBCTable
Posted: Tue 13 Nov 2012 12:15
by AndreyZ
If any other questions come up, please contact us.