Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Using Triggers
Message
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Title:
Miscellaneous
Thread ID:
00220554
Message ID:
00220615
Views:
34
>I am using the programming example in the FoxPro Advisor July 1998 edition. In the article "I Know Who You Are and I Saw What You Did" (Page 38), I am trying to implement the use of triggers in a database to log the changes made to tables.
>
>I have placed the code
>
>__ri_update_warranty().AND.(logit(warranty_id,"U"))
>
>into the update trigger of my warranty table. When I make changes to the table I recieve the error message:
>
>"File Warranty_id does not exist."
>
>Why would I be getting this error?
>
>TIA

I don't know... is warranty_id the field name of the primary key? Anyway... what I did was modify the beginning of the program so that you do not need to pass any parameters to the function... Here is the code from the local declarations to where the program starts doing it's work. Also, take out the lparameters statement too...
LOCAL ;
		lnArea, ;
		luKey, ;
		lcPK, ;
		lcRecordState, ;
		lcChanges, ;
		lcDataType, ;
		lcTransType, ;
		lcDBC, ;
		lcTable, ;
		lcField, ;
		lcKey, ;
		lcKeyType, ;
		lcFieldType, ;
		lcOldFieldValue, ;
		lcCurFieldValue, ;
		lxOldFieldValue, ;
		lxCurFieldValue, ;
		lcUserID, ;
		i

	lnArea  		= SELECT()
	lcPK			= GetPrimaryKey( lnArea )
	luKey			= EVAL( lcPK )
	lcChanges 		= ""
	lcTable			= JUSTSTEM(DBF())
	lcDBC			= JUSTSTEM(DBC())
	lcKeyType		= VARTYPE(luKey)

	* Assign the character representation of the key
	* to lcKey for storage in the log table
	DO CASE
		CASE INLIST(lcKeyType, "N", "Y")
			lcKey = ALLTRIM(STR(luKey))
		CASE INLIST(lcKeyType, "C", "M")
			lcKey = luKey
		CASE lcKeyType = "D"
			lcKey = DTOC(luKey)
		CASE lcKeyType = "L"
			lcKey = IIF(luKey,"T","F")
		OTHERWISE
			RETURN .F.
	ENDCASE

	* Determine Trigger Type
	lcRecordState = GETFLDSTATE(-1)
	DO CASE
		CASE LEFT(lcRecordState,1) = "2" AND DELETED()
			lcTransType = "D"

		CASE LEFT(lcRecordState,1) = "2" AND ! DELETED()
			lcTransType = "I"

		CASE "3" $ lcRecordState OR "4" $ lcRecordState
			lcTransType = "I"

		CASE "2" $ lcRecordState
			lcTransType = "U"
	ENDCASE


	* Loop through all fields in the updated record
Here is the GetPrimaryKey function... just add it at the end of the logit function:
FUNCTION GetPrimaryKey ( tnArea )

	LOCAL nCount, nNumTags, cKey

	nNumTags = TAGCOUNT( "", tnArea )

	FOR nCount = 1 TO nNumTags
		IF PRIMARY( nCount, tnArea )
			EXIT
		ENDIF
	ENDFOR &&* nCount = 1 to nNumTags

	cKey = SYS(14, nCount, tnArea)

	RETURN cKey

ENDFUNC
BOb
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform