At 16:33 03/13/2003 -0700, I wrote:
I am using Active4D with a database that uses triggers. In testing, I notice that if a trigger error occurs via a save record call in Active4D, the error message occurs on the server, which admittedy doesn't surprise me.

For example, this code doesn't do what I'd like it to.

<%
        If (Defined ($f_locsite_submit))
                create record ([LOCATION_SITE])
                [LOCATION_SITE]locsite_name:=$f_locsite_name
                [LOCATION_SITE]locsite_descript:=$f_locsite_descript
                save record ([LOCATION_SITE])
                if (error=0)
                  unload record ([LOCATION_SITE])
                else
                  writebr ("A trigger error occurred. "+error)
                end if

        end if
%>

How do others handle this so that the error can be communicated back to the browser in a meaningful way?

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.

-- Brad




Reply via email to