Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
How to insert data from one-to-many form?
Message
De
08/12/2000 06:16:16
Cetin Basoz
Engineerica Inc.
Izmir, Turquie
 
Information générale
Forum:
Visual FoxPro
Catégorie:
Base de données, Tables, Vues, Index et syntaxe SQL
Divers
Thread ID:
00450690
Message ID:
00450734
Vues:
40
>I have a one to many form with a grid for child records. I use this to add records.
>The key that links the tables has a primary index (machnum) on the parent and a regular index on the child. I get the next Machnum by..
>select parent
>set order to Machnum
>go bottom
>NewMachnum=Machnum+1
>Insert into machine (Machnum) values (NewMachnum)
>...in the init of the form. Right now I also am starting a transaction in the init. I don't like this because then I have an open
>transaction till the form is exited. I need this however because I need the primary index so I can insert child records with
>that same index into the child table. I also need the ability to back out of the transaction if a user decides to cancel the form.
>What other method could I use so that I still have a new index but not an open transaction?

Joe,
First getting a new primary key with that method is dangerous. You could use the sample NextId method in tastrade.app to get PkId. However lets think it's correct and talk about rest of problem.
Use buffering. General tendency is to use row level buffering for parent and table level buffering for child. You could use optimistic type buffering and only in your save-discard method start-end a transaction.
Roughly a save method could look like :
begin transaction
if tableupdate(2,.t.,'parent') and tableupdate(2,.t.,'child')
 end transaction
else
 rollback
endif
You really don't need to start a transaction to insert records into child. Buffered or not you have access to parent.pkid value. At any moment you could insert into child :
Insert into machine_child (ParentId) values (Machine.Machnum)
Cetin
Çetin Basöz

The way to Go
Flutter - For mobile, web and desktop.
World's most advanced open source relational database.
.Net for foxheads - Blog (main)
FoxSharp - Blog (mirror)
Welcome to FoxyClasses

LinqPad - C#,VB,F#,SQL,eSQL ... scratchpad
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform