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: CT-lib Error halts script
Date: Mar 22 1999 4:36PM

I keep having problems with error handling and Sybperl.  Below is all the
relevant code.  I've been working through trying to figure out where the
program dies.  It dies after the sqlexec call.  I never get past my error
handlers.

Any ideas what's happening here?  Here's the error messages I get.  After
the error messages, the program immediately dies.

Message: 207 Text: Invalid column name 'bogusfield'.

03/22/99 10:24:05
----------------------------------------
Sybase error:
Database: HASH(0x13f9e8)
Error: 20018
Message: General SQL Server error: Check messages from the SQL Server.
Severity: 5
OS Error: -1
OS Error Message:

03/22/99 10:24:05
----------------------------------------

Thanks for any help,
John


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";
		($todaysec, $todaymin, $todayhour, $todaymday, $todaymon,
$todayyear,
				$todaywday, $todayyday, $todayisdst) =
localtime(time);
		$todaydate = sprintf("%02d/%02d/%02d %02d:%02d:%02d",
							$todaymon + 1,
$todaymday, $todayyear,
							$todayhour,
$todaymin, $todaysec);
		print LOGFILE "$todaydate\n";
		print LOGFILE "----------------------------------------\n";

	}
	0;
}

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";
	($todaysec, $todaymin, $todayhour, $todaymday, $todaymon, $todayyear,
			$todaywday, $todayyday, $todayisdst) = localtime(time);
	$todaydate = sprintf("%02d/%02d/%02d %02d:%02d:%02d",
						$todaymon + 1, $todaymday,
$todayyear,
						$todayhour, $todaymin,
$todaysec);
	print LOGFILE "$todaydate\n";
	print LOGFILE "----------------------------------------\n";
	&flush(LOGFILE);
	$errorRaised = 1;
	if ($doingNightly)
	{
		$doingNightly = 0;
		$doneNightly = 0;
	}

	INT_CANCEL;
}


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

for (;;)
{
	$dbHandle->dbcmd("select bogusfield from table");
	$result = $dbHandle->dbsqlexec;

	############################################
	# PROGRAM NEVER REACHES THIS POINT
	############################################

	if ($result == $dbHandle->SUCCEED)
	{
		print LOGFILE "Successful query.  Grabbing results\n";
		&flush(LOGFILE);
		$result = $dbHandle->dbresults;
	}
	if ($result == $dbHandle->FAIL)
	{
		print LOGFILE "Error trying to execute command\n";
		($todaysec, $todaymin, $todayhour, $todaymday, $todaymon,
$todayyear,
				$todaywday, $todayyday, $todayisdst) =
localtime(time);
		$todaydate = sprintf("%02d/%02d/%02d %02d:%02d:%02d",
							$todaymon + 1,
$todaymday, $todayyear,
							$todayhour,
$todaymin, $todaysec);
		print LOGFILE "$todaydate\n";
		print LOGFILE "----------------------------------------\n";
		&flush(LOGFILE);
		sleep 300;
		next;
	}
	...[snip]...
	sleep 30;
}