Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Use of triggers
Message
From
07/12/2000 19:29:07
 
 
To
07/12/2000 18:28:52
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Title:
Miscellaneous
Thread ID:
00450619
Message ID:
00450666
Views:
38
Actually, you cannot alter the data during an update trigger. The update trigger locks the record, so only it can unlock it.
The UNLOCK call will also cause an error because it is read as a data alteration.

Instead, you can use the Record validation Rule for this.
The record is already locked, so there is no need to RLOCK() it, and the UNLOCK will throw an error.
I made a couple of other changes, in my code sample at the bottom I've commented these to explain them.

>Thank you Trey. I done the function in stored procedure of database.
>I put the function name and parameters in the update trigger field of
>the table. I put a suspend and used debugger to follow the execution.
>Because I got an error message "Trigger Failed" but exactly "Cannot
>Update Cursor" when the REPLACE command was executing below.
>****************************
>FUNCTION UpdateSearchField
>LPARAMETERS tcTableName, tcField1, tcField2, tcFieldSearch
>LOCAL lcNameSearch, llOk, lcOnError, llError
>
>lcOnError=ON("ERROR")
ON ERROR llError=.T.
IF PCOUNT()=4 AND TYPE('tcTableName')="C" AND TYPE('tcField1')="C" ;
      AND TYPE('tcFieldSearch')="C"
   IF USED("&tcTableName")
      IF  TYPE('tcField2')="C"
          IF !EMPTY(&tcTableName..&tcField2)
              lcNameSearch=LOWER(&tcTableName..&tcField2)
          ELSE
              lcNameSearch=LOWER(&tcTableName..&tcField1)
          ENDIF
      ELSE
          lcNameSearch=LOWER(&tcTableName..&tcField1)
      ENDIF		
      IF &tcTableName..&tcFieldSearchlcNameSearch
         IF RLOCK("&tcTableName")			
            REPLACE &tcTableName..&tcFieldSearch WITH lcNameSearch
             IN &tcTableName
            UNLOCK IN &tcTableName
            llOk=not llError
         ENDIF
      ENDIF
   ENDIF
ENDIF
ON ERROR &lcOnError
RETURN llOk
LPARAMETERS tcTableName, tcField1, tcField2, tcFieldSearch
LOCAL lcNameSearch, llOk, lcOnError, llError, lcField1Val, lcField2Val
lcOnError=ON("ERROR")

*-- initialize llOk to .T.

llOk = .T.

ON ERROR llError=.T.
IF PCOUNT()=4 AND TYPE('tcTableName')="C" AND TYPE('tcField1')="C" AND TYPE('tcFieldSearch')="C"
  IF USED(tcTableName)
    IF  TYPE('tcField2')="C"

      *-- store these to vars instead of evaluating them each time
      *   also, use Eval() instead of macro expansion
      *   ForceExt() is part of VFP6, prior to that it's in FoxTools.fll
      lcField1Val = Eval(ForceExt(tcTableName,tcField1))
      lcField2Val = Eval(ForceExt(tcTableName,tcField2))

      IF !EMPTY(lcField2Val)
        lcNameSearch=LOWER(lcField2Val)
      ELSE
        lcNameSearch=LOWER(lcField1Val)
      ENDIF
    ELSE
      lcNameSearch=LOWER(lcField1Val)
    ENDIF

    *--     again, use Eval() instead of macro expansion
    IF Eval(ForceExt(tcTableName,tcFieldSearch))<>lcNameSearch
      *-- the record is already locked
      **IF RLOCK(tcTableName)
      REPLACE (tcFieldSearch) WITH lcNameSearch IN (tcTableName)
      **UNLOCK IN (tcTableName)
      llOk=not llError
      **ENDIF
    ENDIF
  ENDIF
ENDIF
ON ERROR &lcOnError
RETURN llOk
**************
>Is it possible for you to find my problem?
>Thank you again.
Insanity: Doing the same thing over and over and expecting different results.
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform