At 23:32 03/13/2003 -0500, Aparajita wrote:

To answer my own question, I wrote a wrapper for SAVE RECORD in the database structure which basically looks like this:

`4D_SAVE_RECORD
`Wrapper for 4D's SAVE RECORD command.
`Saves a record and returns any error code encountered.

C_LONGINT($0;$error)
C_POINTER($1;$tablePTR)
$tablePTR:=$1

DB_ERROR:=0
ON ERR CALL("DB_ON_ERROR")
SAVE RECORD($tablePTR->)
ON ERR CALL("")
$0:=DB_ERROR

The active 4D Code now looks like:

<%
If (Defined ($f_locsite_submit))
create record ([LOCATION_SITE])
[LOCATION_SITE]locsite_name:=$f_locsite_name
[LOCATION_SITE]locsite_descript:=$f_locsite_descript
$error:= 4D_SAVE_RECORD (->[LOCATION_SITE])
if ($error=0)
unload record ([LOCATION_SITE])
else
write_save_error($error) `uniform error message handler
end if
end if
%>


If anyone has any better ideas I'd love to hear them.

Actually, the standard Active4D shell wraps all calls to Active4D with ON ERR CALL("A4D_ErrorHandler") and initializes A4D_Error so you can check the value of A4D_Error within your Active4D code. You may have removed that code in your modifications to the shell. I think if that were in place you wouldn't have to use a wrapper around SAVE RECORD, you would just do this:


   SAVE RECORD([LOCATION_SITE])
   if (A4D_Error=0)
      `etc

This has the advantage of catching all errors that occur within Active4D (which as you have seen is critical), not just the ones you wrap.

In the project in question I haven't made any mods to the shell. I think this is the latest ITK shell. I looked at the code and "A4D_ErrorHandler" doesn't appear to be installed in the ITK Slave processes, so I added it as shown below.


  `### SHELL MODS ###
  `
  ` 14-Mar-2003, bdp , added error handler calls
  `
  `##################

MESSAGES OFF
C_LONGINT($streamRef)

C_LONGINT(A4D_Error) `###
A4D_Error:=0 `###
ON ERR CALL("A4D_ErrorHandler") `###
Repeat
ITK_SendIPCMsg (2;String(Current process)) ` tell master that this slave process is ready
PAUSE PROCESS(Current process)
$streamRef:=Num(ITK_RcvIPCMsg (1000+Current process)) `Receive the streamRef on which we must handle the HTTP request


  If (A4D_PreStreamExecuteHook ($streamRef))
    A4D_ITK_Server ($streamRef)  `Handle the incoming HTTP request(s)
  End if

ITK_SendIPCMsg (4;String($streamRef)) `Send the streamRef to the closer to close the stream gracefully
Until (<>A4D_ExitingDB)
ON ERR CALL("") `###


Then I changed my active4D code per your suggestion.

<%
        import ("oadb")

        If (Defined ($f_locsite_submit))
                create record ([LOCATION_SITE])
                [LOCATION_SITE]locsite_name:=uppercase($f_locsite_name)
                [LOCATION_SITE]locsite_descript:=$f_locsite_descript
                save record ([LOCATION_SITE])
                if (A4D_Error=0)
                        unload record ([LOCATION_SITE])
                else
                        write_error_message(A4D_Error)
                end if
        end if
%>

Active4D is not handling this as desired. If the trigger returns an error the web page displays an Active 4D error on the save record line. (I'll send a screen shot privately). If the triggers succeeds save record is fine.

-- Brad




Reply via email to