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: mpeppler at itf1 dot itf dot ch (Michael Peppler)
Subject: Re: Don't want error message printed out
Date: Mar 15 1996 10:16AM

Sorry again - seems I have to send it once more...  I've just upgraded my
machine from SunOS 4.x to Solaris 2.5 with CDE, and it appears that a stray '.'
at the begining of a line is truncating the message I'm trying to send...

So here we go again, with my appologies!

Michael.

> From: "Meetings: A practical alternative to work" 
> 
> I wrote the following piece of perl to make sure the date
> I'm being passed in is valid and to convert it to the form
> I can use later in my program.
> 

[...snip...]


> 
> The output is:
> 
> Msg 242, Level 16, State 3
> Server 'gummo', Line 1
>         The conversion of CHAR to DATETIME resulted in a DATETIME value out of
> DB-Library error:
>         General SQL Server error: Check messages from the SQL Server.
> '29-feb-1995' is a bad date - try again
> 
> What I would like is to suppress the the server message and only 
> print out the message I supply.

You need to supply a specialized message/error handler:

Something like this should work:

sub msg_handler {
   my ($db, $message, $state, $severity, $text, $server, $procedure, $line)
	= @_;

    # Don't display 'informational' messages, or char/datetime conversion errs:
    # You may need to add other error numbers in addition to #242
    if ($severity > 10 || $message == 242)   
    {
	print STDERR ("Sybase message ", $message, ", Severity ", $severity,
	       ", state ", $state);
	print STDERR ("\nServer `", $server, "'") if defined ($server);
	print STDERR ("\nProcedure `", $procedure, "'") if defined ($procedure);
	print STDERR ("\nLine ", $line) if defined ($line);
	print STDERR ("\n    ", $text, "\n\n");

    }
    elsif ($message == 0)
    {
	print STDERR ($text, "\n");
    }
    
    0;
}

sub err_handler {
    my ($db, $severity, $error, $os_error, $error_msg, $os_error_msg)
	= @_;
    # Check the error code to see if we should report this.
    if ($error != SYBESMSG) {
	print STDERR ("Sybase error: ", $error_msg, "\n");
	print STDERR ("OS Error: ", $os_error_msg, "\n") if defined 
($os_error_msg);
    }

    INT_CANCEL;
}

# INstall the error/msg handlers:
&dbmsghandle (\&msg_handler);
&dberrhandle (\&err_handler);

__END__

You can lookup the discussion of error and message handlers in the Sybase
DBlibrary docs, and in the sybperl man page.

Michael