thor has asked for the wisdom of the Perl Monks concerning the following question:

Greetnings all, I'm trying to write a script that, at a base level, performs a backup on a Sybase database. In testing the error modes, I came across a particularly unsettling scenario. Even though I turn on the RaiseError attribute when I connect to the database through DBI, no exception is raised if the backup was unsuccessful. For instance, the following code completes successfully:
use warnings; use strict; use DBI; my $dbh = DBI->connect( "dbi:Sybase:server", "sa", $ENV{SYBPW}, { ChopBlanks => 1, RaiseError => 1, PrintError => 1, } ); $dbh->do( "dump database non_existant_db to 'non-existant file'" );
I could write an error handler and have it look for messages from the server, but was wondering if there was some way to do it automagically.

Thanks in advance,
thor

Replies are listed 'Best First'.
Re: DBD::Sybase and dump dataabse
by jZed (Prior) on May 14, 2004 at 21:25 UTC
    I don't know Sybase at all, but what's the return value from the do() on a successful dump? is it the same on an unsuccessful dump? Check the actual value, not true or false, maybe it's OEO in one of the circumstances.
Re: DBD::Sybase and dump dataabse
by mpeppler (Vicar) on May 15, 2004 at 05:44 UTC
    I just tried it, and I did get a RaiseError. Run your script with DBI->trace(3) to see what the system is doing (note that a "missing/unknown database" error is error #911)

    Michael

      Sometimes I amaze myself with my own myopia. In actuality, I had set a syb_err_handler...that always returned 0. However, I have a question related to that. What I'm trying to do is create a record of what all is happening For example, when you normally dump a database, you receive messages like "DUMP phase 1 complete". I want to retain these messages, but continue to fail where I should.

      My question is: if you don't explicitly return from the custom handler, is the error handled "properly" by DBI in all cases? That is to say: with respect to RaiseError, is any functionality changed by installing a custom handler?

      thor

        The normal way of handling this would be to check the second argument to the error handler (the error "severity"). If the severity is > 10 it is an error, and you should return a positive value from the handler so that DBI's normal error handling can catch the error. If the severity is <= 10 you do what you want with the message, and return 0 from the handler so that there is no risk that DBI will catch the error/message.

        Michael