Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Illegal recursion in rule evaluation
Message
From
05/01/2005 04:59:17
 
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Environment versions
Visual FoxPro:
VFP 8 SP1
OS:
Windows XP SP2
Network:
Windows 2000 Server
Database:
Visual FoxPro
Miscellaneous
Thread ID:
00973840
Message ID:
00974309
Views:
44
hi Nadya,

Yes, the trigger could be written with the following in mind and not caring about the field rules

(1) The updates could be in a transaction which rolls back if any error (code/1887, ...)
(2) I would reopen the table and use seek and scan rest and update on a record by record basis, and roll back / exit if any single record update failed. This means that if it failed at eg record 6, that the first five updates would be undone by the rollback
(3) any routine must return TRUE or FALSE up the tree
(4) you need a specific error routine

Anyway, writing a trigger takes (imo) a lot more than writing a few lines of code (take a look a the standard trigger code for starters). You need at least error and transaction management

The trigger below does not do any of that.

Personally I think one must first understand how the standard routines work.

Then you can either replace all (insert/update/delete/error, ...) with your own, or write one or more specific using the standard that is already there

Cheers,


ps, to know what is happening behind the scenes, take a look at the standard routines (modi proc)
_______________________________________

>Hi Gregory,
>
>That's actually a very interesting situtation and I am curious to know what is happening behind the scenes. Say, some of the records will have negative value after updating the Quantity, which in turn fires the rule. Are the "good" records being already updated? How exactly does the update work? Yesterday when I saw this question I thought, that the trigger should be written conditionally to not cause negative values. On the other hand, why should trigger care about field rules?
>
>What do you think?
>
>>>HI,
>>>
>>>I've got a field rule on Items.iQtyOnHand:
>>>
>>>iqtyonhand=>0
>>>
>>>
>>>I've also got a trigger on SalesDetails:
>>>
>>>vmp_ri("INSERT").AND.adjustqtyonhand(iitemid,iqty*-1)
>>>
>>>
>>>My trigger procedure is:
>>>
>>>PROCEDURE AdjustQtyOnHand
>>>LPARAMETERS tiItemId, tiQty
>>>
>>>UPDATE Items;
>>>	SET iQtyOnHand = iQtyOnHand + m.tiQty ;
>>>	WHERE iItemId = m.tiItemId ;
>>>		AND cType # "Service"
>>>
>>>
>>>If I enter a sale of an item that results in a negative stock value, when running the exe in runtime, I get an error: "Illegal recursion in rule evaluation" (after I get my "Not enough stock available" MsgSvc message).
>>>
>>>The error is #1887 and the help suggests checking my rule and trigger code.
>>>
>>>Can anybody see what's wrong?
>>
>>Frank,
>>
>>Aside from the other answers you may get the "Illegal recursion in rule evaluation" if there's an error in your code like referencing a variable that does not exist (or a field of an alias that is not the current one) or even an operator/operand mismatch (like a='123' followed by b = a+1)
>>
>>Best you can do is to put an 'Assert FALSE' at the start of your code and debug it step by step. If you find the line that is causing the error, you will know
Gregory
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform