Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Using Triggers
Message
Information générale
Forum:
Visual FoxPro
Catégorie:
Base de données, Tables, Vues, Index et syntaxe SQL
Titre:
Divers
Thread ID:
00220554
Message ID:
00220946
Vues:
39
So this is what I have now and it pukes on the line:

luKey = EVAL( lcPK )

with the error "Missing Expression" - did i miss something?

Jeff



FUNCTION logit(tckey, tctranstype)
#DEFINE sep "~"

IF ! INLIST(UPPER(tctranstype),"I","D","U")
MESSAGEBOX("Invalid Transaction Type Specified")
RETURN(.F.)
ENDIF

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
* deturmned if an Update, Delete, or Insert is
* in progress
****
FOR i = 1 TO FCOUNT() && Loop through all fields
lcfield = ALLT(FIELD(i)) && STORE FIELD NAME
IF TYPE("EVAL(lcfield)")="G" && Skip General Fields
LOOP
ENDIF

****
* What type of transaction is occuring
****
IF (tctranstype = "D" OR ;
tctranstype = "I" OR ;
(GETFLDSTATE(lcfield) <> 1 AND tctranstype = "U"))

lxoldfieldvalue = iif(INLIST(tctranstype,"D","I"),"", ;
oldval(lcfield))
lxcurfieldvalue = EVAL(lcfield)

lcdatatype = TYPE("lxcurfieldvalue")
DO CASE

****
* Process Characture or Memo Fields
****
CASE INLIST(lcdatatype, "C","M" )
lcoldfieldvalue = IIF(INLIST(tctranstype,"D","I"),"", ;
ALLTRIM(lxoldfieldvalue))
lccurfieldvalue = ALLTRIM(lxcurfieldvalue)

****
* Process date fields
****
CASE lcdatatype = "D"
iif(INLIST(tctranstype,"D","I"),"", ;
ALLTRIM(TTOC(lxoldfieldvalue,1)))
lccurfieldvalue = ALLTRIM(DTOS(lxcurfieldvalue))

****
* Process DateTime fields
****
CASE lcdatatype = "T"
lcoldfieldvalue = IIF(INLIST(tctranstype,"D","I"),"", ;
ALLTRIM(TTOC(lxoldfieldvalue,1)))
lccurfieldvalue = ALLTRIM(TTOC(lxcurfieldvalue,1))

****
* Process numberic, currency, or integer fields
* Use AFIELDS() to determine the width and decimal places
****
CASE INLIST(lcdatatype,"N","Y","I")
= AFIELDS(lafields)
liwidth = lafields(i,3)
lidecimal = lafileds(i,4)
lcoldfieldvalue = IIF(INLIST(tctranstype,"D","I","", ;
ALLTRIM(STR(lxoldfieldvalue,liwidth,lidecimal)))
lccurfieldvalue = ALLTRIM(STR(lccurfieldvalue, ;
liwidth, lidecimal))

****
* Process Logical fields
****
CASE lcdatatype = "L"
lcoldfieldvalue = IIF(INLIST(tctranstype,"D","I","", ;
IIF(lxoldfieldvalue,'True','False'))

ENDCASE

lcchanges = lcchanges + lcdatatype + sep + ;
lcfield + sep + ;
lcoldfieldvalue + sep + ;
lccurfieldvalue + sep + CHR(13)
ENDIF
ENDFOR

****
* Update Log Table
****
INSERT INTO LOG( ;
ctrg_type, ;
cdbc_name, ;
ctbl_name, ;
ckey_type, ;
crec_key, ;
mactions, ;
tupd_when) ;
VALUES (tctranstype, ;
lcdbc, ;
lctable, ;
lckeytype, ;
lckey, ;
lcchanges, ;
DATETIME())
SELECT (lnarea)
RETURN(.T.)


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




>>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
Jeff Pearce
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform