Using KeyGenerator in an insert on TIBCTable

Discussion of open issues, suggestions and bugs regarding IBDAC (InterBase Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
MahoneyH
Posts: 9
Joined: Mon 21 Jul 2008 13:53

Using KeyGenerator in an insert on TIBCTable

Post by MahoneyH » Mon 12 Nov 2012 17:32

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;

MahoneyH
Posts: 9
Joined: Mon 21 Jul 2008 13:53

Re: Using KeyGenerator in an insert on TIBCTable

Post by MahoneyH » Mon 12 Nov 2012 17:42

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;


AndreyZ

Re: Using KeyGenerator in an insert on TIBCTable

Post by AndreyZ » Tue 13 Nov 2012 11:08

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.

MahoneyH
Posts: 9
Joined: Mon 21 Jul 2008 13:53

Re: Using KeyGenerator in an insert on TIBCTable

Post by MahoneyH » Tue 13 Nov 2012 12:00

Thanks!

I just determined that was the case. It is nice to see it confirmed.

Thanks for your response.

Hardee

AndreyZ

Re: Using KeyGenerator in an insert on TIBCTable

Post by AndreyZ » Tue 13 Nov 2012 12:15

If any other questions come up, please contact us.

Post Reply