>>Yes - My key expression field is a characture format. lcKeyType does return a N on "10056" where it should be a C. No - it does not log any changes - it dies before the SQL update code.
>>
>>Jeff
>Post your code. I feel you have lcKey and luKey mixed up at some place.
>
>BOb
Thanks for helping me on this. Sorry it has taken so long to get back to you. On May 27 I crashed my motorcycle into the side of a mini van and I just now getting back up to speed. Here is the code.
****
* logit.prg
****
FUNCTION logit(tckey, tctranstype)
#DEFINE sep "~"
set library to home() + "FoxTools.FLL"
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
suspend
lnArea = SELECT()
lcPK = GetPrimaryKey( lnArea )
? "LcPK" + lcpk
luKey = EVAL( lcPK )
? " Lukey" + lukey
lcChanges = ""
lcTable = JUSTSTEM(DBF())
lcDBC = JUSTSTEM(DBC())
lcKeyType = TYPE(luKey)
* Assign the character representation of the key
* to lcKey for storage in the log table
DO CASE
? "lcKeyType" + lcKeyType
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
Jeff Pearce