troubleshooting Question

Master detail same table

Avatar of cula99
cula99 asked on
Delphi
4 Comments1 Solution539 ViewsLast Modified:
Hello,

my problem is… I don’t know, somehow stupid.
Datebase is InterBase.
Cached updates are on.
Supose, I have one table where storing organizations. In the same table, there are suborganisations. When I try to insert organisation it is not problem, ApplyUpdates Commit and done, database generate PrimaryKey. But I wont something else. I wont to put organizsation and suborganisations in the same time.

What I tried:
-      2 querys on same table and procedure in database that generate PK.
-      2 querys and 2 tables in the other there are trigger after insert that insert into orginal table and delete from it unnecesary data

Structure is like this

pk integer,
pk_sub integer,
name varchar(50);

if  pk=pk_sub it means that it is main organisation. In other chases pk_sub must exist in column pk



  OK:=True;
  if (SpisakQuery.State in [dsInsert]) then
    begin
      nrProc.ParamByName('PARAM').AsString:='ORG_PK';
      nrProc.ExecProc;
      Broj:=nrProc.ParamByName('NR’).AsInteger;
    end
  else
    BNr:=SpisakQueryORG_PK.AsInteger;
  try
    if (BQuery.UpdateStatus in [usModified, usInserted]) then
      begin
        if (AQuery.State in [dsInsert]) then
          begin
            AQueryORGANIZACIJA_PK.AsInteger:=Broj;
            AQuery.Post;
            BQuery.First;
            while not BQuery.Eof do
              begin
                BQuery.Edit;
                BQueryPK_sub.AsInteger:=BNr;
                BQuery.Post;
                BQuery.Next;
              end;
           end;
        AQuery.Transaction.Databases[0].ApplyUpdates([AQuery, BQuery]);
      end
    else
      begin
        AQueryORG_PK.AsInteger:=Broj;
        AQuery.Transaction.Databases[0].ApplyUpdates([AQuery]);
      end;
  except
    on EIBInterBaseError do
      begin
        ShowMessage('Something is bad');
        OK:=False;
      end;
  end;

  if OK then
    begin
      AQuery.Transaction.Commit;//Retaining;
      //temp:=AQueryORG_PK.AsString;
      AQuery.Close;
      AActionExecute(Sender);
      AQuery.Locate('ORG_PK', Broj, []);
      {Some action}
    end;
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 4 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 4 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros