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;
ASKER CERTIFIED SOLUTION
erkinbaba

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Log in to continue reading
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform for $9.99/mo
View membership options
Unlock 1 Answer and 4 Comments.
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
See how we're fighting big data
The Value of Experts Exchange in My Daily IT Life

Experts Exchange (EE) has become my company's go-to resource to get answers. I've used EE to make decisions, solve problems and even save customers. OutagesIO has been a challenging project and... Keep reading >>

Mike

Owner of Outages.IO
Phoenix, Arizona, United States
Member Since 2016
Join a full scale community that combines the best parts of other tools into one platform.
Unlock 1 Answer and 4 Comments.
View membership options
“All of life is about relationships, and EE has made a virtual community a real community. It lifts everyone's boat.”
William Peck

Member since 2004