Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Updating a view problem
Message
 
À
01/09/2003 22:08:19
Mike Sue-Ping
Cambridge, Ontario, Canada
Information générale
Forum:
Visual FoxPro
Catégorie:
Base de données, Tables, Vues, Index et syntaxe SQL
Divers
Thread ID:
00824703
Message ID:
00825202
Vues:
21
Mike,
Admittedly I do not use triggers but here is one suggestion to achieve your requirements.
If in your database you have 2 procedures 1 to do the calculation and 1 to be the trigger then you could call the appropriate one from the trigger to update the field but just call the calculation from elsewhere. Something like this (untested!)
Procedure CalcArea()
lparam lnLen, lnWidth
return lnLen * lnWidth

Procedure TriggerCalcArea()
REPLACE mytable.area WITH CalcArea(mytable.length, mytable.width)
This way you only ever have the actual calculation in one place.
HTH
Caroline

>Hi Mike,
>
>Although that sounds simple enough I'm still puzzled by all this. My stored procedure has something similar to this:
>
>
>PROCEDURE AreaCalc
>REPLACE mytable.area WITH mytable.length * mytable.width
>
>
>that's all.
>
>Now if I'm using a view of mytable in the dataenvironment of myform, lets call it myview, then in the valid of the length textbox of myform, I could put your code
>
>
REPLACE area with calcarea()
>
>I'm not sure how that can work since my stored procedure does not return an area value. It instead returns a logical true or false since it is used for the field validation of length and width.
>
>Did I misinterpret you when you said to update the value of the textbox with the result of the calculation? How? What am I doing wrong? Please don't tell me that I should duplicate the stored procedure inside of the valid of the textboxes for length and width:( I want to avoid this by placing as much of the calcuations in the database as possible.
>
>Is it me or is this stuff asking too much of VFP8?
>
>Thanks,
>
>Mike.
>
>>As Caroline points out, you can
>>
>>
REPLACE area with calcarea()
>>
>>However, since you said the trigger is already in place, you don't need to do a replace or a tableupdate. I assume you have a textbox showing the area on the screen. Just update the value of that textbox with the result of the calculation whenever the values of length and width change.
>>
>>
>>
>>>Hi Mike,
>>>
>>>I like the sounds of your second suggestion, but, I'm not exactly sure what you mean.
>>>
>>>I already have the area calculated via a stored procedure in my DBC (I'm not sure that I had made that clear in my original message). It is called in a trigger set for updating the length and the width fields.
>>>
>>>How do I call that stored procedure from the form? Could you kindly elaborate? Treat me like a newbie to triggers and stored procedures because I really am one:)
>>>
>>>Thanks,
>>>
>>>Mike
>>>
>>>
>>>>The tableupdate sends the data from the view to the tables. This update to the tables fires the triggers, which updates area in the tables. The view is unaffected. You could ...
>>>>
>>>>1) requery the view to get the new area, which could be a performance problem.
>>>>
>>>>2) make the area calculation a stored procedure, called from the trigger and from the form.
>>>>
>>>>>I have a VFP8 form with a local view in its dataenvironment. On the form, I put two spinners, one for a length value and another for a width value. A textbox is also on the form that show the product of the former (ie. area).
>>>>>
>>>>>My VFP database container has a field update trigger that calls a stored procedure to do the area calculation when the length and width fields change. I've verified that this all works fine when I browse the table and edit the length and/or width fields and the area fields change accordingly.
>>>>>
>>>>>My problem is that when I use the view based on this table, and make changes to the length or width values, the area value never refreshes to show the correct calculated value. I issued a TABLEUPDATE on the view and expected it to update the area. It doesnt. The underlying table does in fact get updated with the correct values, however, the view does not.
>>>>>
>>>>>I checked the methods and properties of the dataenvironment and could find anything that could help.
>>>>>
>>>>>My question is, how do I get the view to update the calculated values (the stuff done in the stored procedure) so that it appears correctly on my form?
>>>>>
>>>>>Any suggestions and/or comments are greatly appreciated.
>>>>>
>>>>>TIA
>>>>>
>>>>>Mike
Caroline
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform