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 itf dot ch (Michael Peppler)
Subject: Re: The message and error handler
Date: Feb 7 1996 11:57AM

> Have some question in calling the dbmsghandle and dberrhandle.
> The following subroutine :
> 
> if (defined(dbmsghandler))
> {
>    &dbmsghandle("message_handler");
> }B
> 
> sub message_handler
> {
>     local (......) (ignored them!)
> ;
> ;
> ;
> }
> 
> If you use &dbmsghandle("message_handler"), it does not work as the
> a sub rountine must be called with "&" at the beginning.
> Then how should I use the dbmsghandle?

First, which version of perl/sybperl are you using?

In all versions, saying
	&dbmsghandle("message_handler");
works, because perl will use the name of the routine to look it up in
it's symbol table. With Perl 5 / Sybperl 2.x, you can use this form
instead:
	&dbmsghandle(\&message_handler);
Both forms register the perl subroutine 'message_handler'  to be called
when Sybase returns a 'message'.


> 
> Also, the handler does not get the message from Sybase
> as I print $message, nothing happen.

Sorry, I'm not sure what the problem is... If you use the following SQL code:

PRINT "This is a message"

then the message handler will be called:

#!/usr/local/bin/perl

require 'sybperl.pl';   # This normally registers the message handler

$d = &dblogin(user);
&dbcmd($d, "PRINT 'This is a message'");
&dbsqlexec($d);
&dbresults($d);


Given this message handler:

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

    # Don't display 'informational' messages:
    if ($severity > 10)
    {
	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)
    {
### Sybase PRINT statements end up here:
###
	print STDERR ($text, "\n");
    }
    
    0;
}


> 
> Thanks!
> 
> Michelle (HK)
> 
> 

You're welcome :-)

Michael