in reply to DBI Error Trapping

Setting 'RaiseError' to 1 means 'die if there is an error'. You have two choices: eval the prepare statement and then check $@ after the prepare, or set RaiseError to 0 and check the status returned from the prepare statement.

Replies are listed 'Best First'.
Re: Re: DBI Error Trapping
by timo (Novice) on Dec 19, 2001 at 11:43 UTC
    I've changed it to:
    $db3->{RaiseError}=0; unless ($sth_minus = $db3->prepare_cached(" SELECT $column_list FROM $ +database_user_1.$table_names_r->[0]".'@'."$config{database_dblink_1} MINUS SELECT $column_list FROM $ +database_user_2.$table_names_r->[0]".'@'."$config{database_dblink_2} ")) {warn $@ if $@;}
    but the program still dies. Any suggestions?
      Try something like:
      { local $db3->{RaiseError}=0; $sth_minus = $db3->prepare_cached(" SELECT $column_list FROM $database_user_1.$table_names_r->[0]". +'@'."$config{database_dblink_1} MINUS SELECT $column_list FROM $database_user_2.$table_names_r->[0]". +'@'."$config{database_dblink_2} "); warn "prepare fails with $db3->errstr" if $db3->err; }
      The errorcode is returned in $db3->err and the string in $db3->errstr not in $@.

      Localising $db3->{RaiseError} is a way of locally setting the RaiseError attribute without having to rembember the state (probably not needed here, but it is a useful idiom :-).

      The error string will be in $@ if you set RaiseError to 1 AND eval the prepare statement. Or do what htoug suggests above. Sorry if I was unclear :)