I have the following code
PARAMETERS tnConnection,tcSql,tcOutput
IF EMPTY(tcSql)
tcSql = " "
lnResult = SQLEXEC(tnConnection)
ELSE
IF EMPTY(tcOutput)
lnResult = SQLEXEC(tnConnection,tcSql)
ELSE
lnResult = SQLEXEC(tnConnection,tcSql,tcOutput)
ENDIF
ENDIF
IF lnResult = -1
=AERROR(aTmpError)
lnStack = ASTACKINFO(aTmpStack)
IF TYPE("app_global") <> "O"
app_global = CREATEOBJECT('custom')
app_global.addproperty("app_name","Insert App Name")
app_global.addproperty("employee","RPUPKO")
ENDIF
INSERT INTO spotlight_errors(application,sql_statement,error_msg,dt_error,userid,stack) VALUES;
(app_global.app_name,tcSql,aTmpError[2],DATETIME(),app_global.employee,this.array_to_char('aTmpStack'))
USE IN (SELECT('spotlight_errors'))
IF this.showerror
=MESSAGEBOX(aTmpError[2],0,PROGRAM(aTmpStack[ALEN(aTmpStack,1)-1,1]))
SET STEP ON
ENDIF
RETURN .F.
ENDIF
One of the records in the error log has the error message
Variable 'LNRESULT' is not found."I've never been able to reproduce this error and it's quite possible that the environment would actually absorb it and allow processing to continue. So if this error were generated by
IF lnResult = -1 the record would actually get written.
What I don't understand is how the variable could not have a value. Can anybody give me a set of circumstances where this variable does not exist when AERROR() is called?
One possibility is that the error was actually generated in some other module and properly handled there. It could have been the last error generated so that's what AERROR() would find. In which case, for
this module it really has a value of -1 so I'm supposed to go into the error handling portion of the code. The problem with that is the value is being assigned by the SQLEXEC() statements. If that statement resulted in a value of -1, why doesn't AERROR() return the ODBC errors I'm expecting.
I've checked with the users of the system and nobody has noticed any unexpected results, so it appears that the final processing is correct. But this is driving me crazy(ier). Any and all suggestions gratefully accepted.
..........Rich