I have installed the following SW on Solaris 2.6:
        perl 5.6.1
        DBI-1.21
        DBD:Oracle-1.12
        DBD:Sybase-0.94
        freetds-0.53   (connecting to MS-SQL 7.0 with TDS_VER 7.0)

Because I'm new to DBI, I tried to write some programs (copies/modifications
of examples found in the documentation) to learn the handling. 
Now I stuck at the error handling of SQL-Statements. Here is my test:

use DBI;
#my $server = "dbi:Oracle:$obase";
my $server = "dbi:Sybase:server=$obase";

my $DbS = DBI->connect($server, $ouser, $opass,
    { AutoCommit => 0, RaiseError => 0, PrintError => 0 } )
    or die $DBI::errstr;

my $stmt = "INSERT INTO tbl1( ID, CREATION_TS) VALUES (1491, '27.02.2002
10:41:00')";
#Should return 'uniq constraint' on Oracle and 'out-of-range datetime' on
MS-SQL
$DbS->do($stmt) or err_trap("Error during do");
$DbS->disconnect;

#---------------------------------------------------------------
#      Subroutines
#---------------------------------------------------------------
sub err_trap
{
   my $error_message = shift(@_);
   $DbS->rollback;
   die "$error_message\n  ERROR: $DBI::err ($DBI::errstr)\n";
}


I thought after reading the documentation, I should be able to test in
err_trap via $DBI::err for specific SQL error codes and handle them. But...
Connecting to MS-Sql, I get the following output:

  Changed database context to 'wsdbs'.
  Changed language setting to us_english.
  The conversion of a char data type to a datetime data type resulted in an
out-of-range datetime value.
  The statement has been terminated.
  Use of uninitialized value in concatenation (.) or string at tst4.pl line
33.
  Use of uninitialized value in concatenation (.) or string at tst4.pl line
33.
  Error during do
    ERROR:  ()
  Issuing rollback() for database handle being DESTROY'd without explicit
disconnect().

Connecting to Oracle, I get the following output:

  Use of uninitialized value in concatenation (.) or string at tst5.pl line
37.
  Use of uninitialized value in concatenation (.) or string at tst5.pl line
37.
  Error during do
    ERROR:  ()

So here are the things which I don't understand:

1) Why are $DBI::err and $DBI::errstr set to undef at that point of
execution? Is this the wrong way to check for errors? Do I need to test them
via the database handle ( $DbS->err ) ?

2) I also tied to use 
        $DbS->do($stmt)    or die " State: ", $DBI::state, ", Error: ",
$DBI::err, ", Msg: ", $DBI::errstr, "\n";
   and got for that specific part:
        Use of uninitialized value in die at tst4.pl line 22.
        Use of uninitialized value in die at tst4.pl line 22.
         State: , Error: , Msg:
   So why do I get this errormsg only 2 times and not 3 times?

3) Were are the additional lines of output coming from using the DBD:Sybase
driver? How can I get rid of them?

It seems to me, that I've done something in an incorrect way, but I have no
idea what? So any help would be appriciated.

Thanks

Martin Sauer



Reply via email to