Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Trigger -> Wrong Results
Message
De
14/02/2004 16:15:01
Hilmar Zonneveld
Independent Consultant
Cochabamba, Bolivie
 
Information générale
Forum:
Visual FoxPro
Catégorie:
Base de données, Tables, Vues, Index et syntaxe SQL
Divers
Thread ID:
00877268
Message ID:
00877418
Vues:
12
This message has been marked as the solution to the initial question of the thread.
Instead of summing all child records for a parent record, you might consider a differential approach: just add the difference to the other table. This might be faster, anyway, than summing possibly hundreds of records.

For instance, assuming tcTriggerType contains the trigger type:
do case
case tcTriggerType = "U" && update
  lnDifference = Total_A - oldval("Total_A")
case tcTriggerType = "D" && delete
  lnDifference = -oldval("Total_A")
case tcTriggerType = "I" && insert
  lnDifference = Total_A
endcase
* insert commands to go to other table, and search record
replace Total_A with Total_A + lnDifference
...
>Hello.
>
>Let me try to explain my problem!
>
>TableA -> Id_A, Total_A
>TableB -> Id_A, Id_B, Total_B
>
>Both tables have triggers for insert, update and delete. My problem is in Table_B, that calls the function TableB_Trigger for Insert, Update and Delete.
>
>
>Function TableB_Trigger
>m.Id_A = TableB.Id_A
>m.Id_B = TableB.Id_B
>Select Sum(Total_B) From TableB Where Id_B = m.Id_B Into Array Total_A
>m.Total_A = Iif(Type("Total_A[1]")#"N",0,Total_A[1])
>Update Table_A Where Id_A = m.Id_A Set Total_A = m.Total_A
>
>
>Ok. The code works fine, but the results doesn't!
>
>If I open the Table_B (Use) and change the value of field Total_B (from 10 to 50), my trigger is fired and the code returns Total_A = 10 ... and it should be 50, ok?
>
>I think the Select Sum(Total_B) is taking the "old value" in the table... because VFP doesn't know if that transaction will complete or won't.
>
>I just want to calculate this total and put it in other table...
>
>Do you have some "magic potion" to fix it?
>
>TIA! TIA! TIA!
Difference in opinions hath cost many millions of lives: for instance, whether flesh be bread, or bread be flesh; whether whistling be a vice or a virtue; whether it be better to kiss a post, or throw it into the fire... (from Gulliver's Travels)
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform