PEPPLER.ORG
Michael Peppler
Sybase Consulting
Menu
Home
Sybase on Linux
Install Guide for Sybase on Linux
General Sybase Resources
General Perl Resources
Freeware
Sybperl
Sybase::Simple
DBD::Sybase
BCP Tool
Bug Tracker
Mailing List Archive
Downloads Directory
FAQs
Sybase on Linux FAQ
Sybperl FAQ
Personal
Michael Peppler's resume

sybperl-l Archive

Up    Prev    Next    

From: "Strauss, Fred" <STRAUSS at ap dot org>
Subject: Trigger errors
Date: Feb 14 2006 1:16PM

Is there a "recommended" way to trap errors generated by triggers
assuming the trigger is using raiserror to signal a problem?
 
I know that given the following in my trigger:
 
error:
        select @msgText = "Related Key -" + @fieldname +  "- " +
                "does not exist in the table " + @desttablename +
                " attempt to insert invalid foreign key into table - " +
                @sourcetablename + " -Failed "
        raiserror 30053 @msgText
        rollback tran
        return

that I will get a callback in my client message callback function but
the question is how do I indicate to the calling perl script that a
problem occurred?
 
I have the following routine that executes the stored proc in question:
 
sub exec_sql_nores {
        my $db_ref = shift;
        my $sql = shift;
        my ($row_count, $result_type, $status);
 
        # establish a handle to the database
        $row_count = $$db_ref->ct_execute($sql);
        while (($row_count = $$db_ref->ct_results($result_type)) ==
CS_SUCCEED) {
                if ($result_type == CS_CMD_FAIL) {
                        printf STDERR "Error in SQL: %s\n", $sql;
                }
                next unless $$db_ref->ct_fetchable($result_type);
                my %data;
                while (%data = $$db_ref->ct_fetch(CS_TRUE)) {
                        ;
                };
        }
        return $row_count;
}
 
This routine returns CS_END_RESULTS (-205) as it would if the stored
proc completed successfully.

Is it a matter of looking at the error code raised by raiserror and then
returning CS_FAIL from the message callback?
 
Thanks for any help!
 
Fred


The information contained in this communication is intended for the use of the designated recipients named above. If the reader of this communication is not the intended recipient, you are hereby notified that you have received this communication in error, and that any review, dissemination, distribution or copying of this communication is strictly prohibited. If you have received this communication in error, please notify The Associated Press immediately by telephone at +1-212-621-1898 and delete this email. Thank you.