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: John Gilmore-Baldwin <john at dwx dot com>
Subject: Re: How do I keep going after hitting error handler?
Date: Jan 20 1999 10:23PM

Here's the core of my code:


sub SQLmessageHandler
{
	my ($Database, $Message, $State, $Severity, $Text, $Server,
		$Procedure, $Line) = @_;

	# Ignore informational messages (serverity = 1). To display
informational
	# messages, change the 1 to 0.
	#
	if ($Severity > 1)
	{
		print LOGFILE "Message: $Message Text: $Text\n";
		$SQLerror = "Database: $Database\nMessage: $Message\nState:
$State\nSeverity: $Severity\n" .
					"Text: $Text\nServer:
$Server\nProcedure: $Procedure\nLine: $Line\n";
		$errorRaised = 1;
		if ($doingNightly)
		{
			$doingNightly = 0;
			$doneNightly = 0;
		}
		print LOGFILE "$sqlstatement\n";

		INT_CONTINUE;
	}
}

sub SQLerrorHandler
{
	my ($Database, $Severity, $Error, $OSerror, $ErrorMsg, $OSerrorMsg)
= @_;
	# 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);
	}
	print LOGFILE ("Sybase error: ", $error_msg, "\n");
	$SQLerror = "Database: $Database\nError: $Error\nMessage:
$ErrorMsg\nSeverity: $Severity\n" .
				"OS Error: $OSerror\nOS Error Message:
$OSerrorMsg\n";
	print LOGFILE "$SQLerror\n";
	#print LOGFILE "$sqlstatement\n";
    ($todaysec, $todaymin, $todayhour, $todaymday, $todaymon, $todayyear,
			$todaywday, $todayyday, $todayisdst) = localtime(time);
	$todaydate = sprintf("%02d/%02d/%02d", $todaymon + 1, $todaymday,
$todayyear);
	print LOGFILE "$todaydate\n";
	&flush(LOGFILE);
	$errorRaised = 1;
	if ($doingNightly)
	{
		$doingNightly = 0;
		$doneNightly = 0;
	}

	INT_CONTINUE;
}


Sybase::DBlib::dbmsghandle(\&SQLmessageHandler);
Sybase::DBlib::dberrhandle(\&SQLerrorHandler);

for (;;)
{
	$storynames = "";
	$dbHandle->dbcmd("select name, text from story where priorityid =
$priorityid");
	$dbHandle->dbsqlexec;
	$dbHandle->dbresults;
	while(@data = $dbHandle->dbnextrow)
	{
		$storynames .= "or name = \"$data[0]\"";
		printf WEBOUT "\x02";
		printf WEBOUT "%-32.32s", $data[0];
		printf WEBOUT "%s", $data[1];
		printf WEBOUT "\x03";
		printf LOGFILE "%s: %s\n", "Sent file", $data[0];
		&flush(LOGFILE);
	}
	$storynames =~ s/^or //;
	if ($storynames ne "")
	{
		&flush(WEBOUT);
		$dbHandle->dbcmd("update story set priorityid =
$donepriorityid where $storynames");
		$dbHandle->dbsqlexec;
		$dbHandle->dbresults;
		while (@data = $dbHandle->dbnextrow) {}
	}
	sleep 30;
}

$dbHandle->dbclose;

-----------------------------------

Here's the error messages I output:

Message: 540 Text: Schema for table 'story' has changed since compilation
of this query.  Please re-execute query.

Sybase error:
Database: HASH(0xce3a0)
Error: 20018
Message: General SQL Server error: Check messages from the SQL Server.
Severity: 5
OS Error: -1
OS Error Message:


01/06/99

Thanks much,
John


>>>>>> "John" == John Gilmore-Baldwin  writes:
>
>John> Every time I land in my error handler, my perl program dies.
>John> Currently I return INT_CONTINUE because INT_CANCEL, which is in
>John> the example, did the same thing.
>
>There must be something else going.
>
>I always use the error handlers that are in the sybutil.pl file and my
>scripts never exit on an error.
>
>Can you give me an example of what fails?
>
>Michael
>--
>Michael Peppler         -||-  Data Migrations Inc.
>mpeppler@mbay.net       -||-  http://www.mbay.net/~mpeppler
>Int. Sybase User Group  -||-  http://www.isug.com
>Sybase on Linux mailing list: ase-linux-list@isug.com