Hi,
I am writing a perl script to execute several stored proc on
SQL Server 2005 and the stored proc uses the log function. When the
argument to the log function is -1, it is outside the domain for the
Log function and the SQL Server rightly generates an error message to
that effect:
Msg 3623, Level 16, State 1, Line 1
A domain error occurred.
"select log(-1)" generates this error.
The thing is I want to detect this error condition and take
appropriate course of action. I wrote this script and it doesn't seem to
catch it. It seems to work if the update statement is taken out. Or
placed at the end. What needs to be done here?
The stored proc is:
ALTER proc [dbo].[udp_test]
as
update tb_test set j = j + 1 where i=1
declare @f float
set @f = -1
select log(@f)
return
=============
The perl script is:
use strict;
use DBI;
my $data_source = q/dbi:ODBC:xxxsql04/;
my $user = q/sa/;
my $password = q/xxx/;
my $dbh = DBI->connect($data_source, $user, $password, { RaiseError =>
1} )
or die "Can't connect to $data_source: $DBI::errstr";
$dbh->{odbc_err_handle} = \&err_handler;
my $sql = "exec Volatility.dbo.udp_test";
# Prepare the statement.
my $sth = $dbh->prepare($sql)
or die "Can't prepare statement: $DBI::errstr";
# Execute the statement.
eval {
$sth->execute();
};
if ( $@ ) {
print STDERR "Error encountered. Msg = $@" . "\n";
}
# Fetch and display the result set value.
while ( my @row = $sth->fetchrow_array ) {
print "$row[0] \n";
}
# Disconnect the database from the database handle.
$dbh->disconnect;
sub err_handler {
my ($sqlstate, $msg, $nativeerr) = @_;
# Strip out all of the driver ID stuff
$msg =~ s/^(\[[\w\s:]*\])+//;
print $msg;
print "Oh No !!!===> state: $sqlstate msg: $msg nativeerr:
$nativeerr\n";
return 0;
}
Ramakrishna Raju ( "Raju" )
[EMAIL PROTECTED] <mailto:[EMAIL PROTECTED]>
DISCLAIMER: NOTICE REGARDING PRIVACY AND CONFIDENTIALITY
This e-mail, and any attachments thereto, is intended only for use by the
addressee(s) named herein and may contain legally privileged and/or
confidential information. If you are not the intended recipient of this e-mail,
you are hereby notified that any dissemination, distribution or copying of this
e-mail, and any attachments thereto, is strictly prohibited. If you have
received this e-mail in error, please immediately notify me and permanently
delete the original and any copy of any e-mail and any printout thereof. E-mail
transmission cannot be guaranteed to be secure or error-free. The sender
therefore does not accept liability for any errors or omissions in the contents
of this message which arise as a result of e-mail transmission. TJM Proprietary
Trading, LLC ("TJMPT") may, at its discretion, monitor and review the content
of all e-mail communications. TJMPT is a registered joint back office broker
dealer with the Chicago Board of Options Exchange "CBOE". TJMPT's office is
located at 318 W. Adams Floor 9, Chicago, IL 60606. For more information about
TJMPT, please call us at (312)-432- 5100 or fax (312)-432-4498.