On Fri, 6 Jun 2003 11:26:21 -0700 (PDT), steve hatfield wrote: >Hi all; Hi Steve
>I am running .sql scripts in Oracle using DBI. I was looking for >error handling when I run the different .sql's. The only thing I >found was $dbh->errstr(); >and when u connect I understand that but is there anything else that >I could do? I am running this in a Perl\Tk script with allot of Gui >stuff connecting to Oracle and DB2. I just need to do a pop up for >Oracle and I was wondering if anyone has done anything like that >with DBI? You can try Perl's Effortless Exceptions (tm). See the example below. It's a CGI script but you can easily turn it into a command line script. To test it, systematically corrupt the parameters to connect() and observe the result. -----><8----- #!/usr/bin/perl # # Name: # test-template.cgi. # # Purpose: # Test Some::Thing. # # Note: # \t = 4 spaces || die. # # Author: # Ron Savage <[EMAIL PROTECTED]> # http://savage.net.au/index.html use strict; use warnings; use CGI; use CGI::Carp qw/fatalsToBrowser/; use Error qw/:try/; # ----------------------------------------------- delete @ENV{'BASH_ENV', 'CDPATH', 'ENV', 'IFS', 'SHELL'}; # For security. my($title) = 'Test X'; my($q) = CGI -> new(); my($file_param) = 'file_name'; my($file) = $q -> param($file_param) || ''; my(@html); try { my($dbh) = DBI -> connect ( 'DBI:mysql:config:127.0.0.1', 'root', 'pass', { AutoCommit => 1, HandleError => sub {Error::Simple -> record($_[0]); 0}, # RTFM! PrintError => 0, RaiseError => 1, ShowErrorStatement => 1, } ); if ($file) { push(@html, $q -> th('File') . $q -> td($file) ); push(@html, $q -> th('X') . $q -> td('X') ); } push(@html, $q -> th('File') . $q -> td($q -> filefield({name => $file_param, size => 60}) ) ); push(@html, $q -> th({colspan => 2}, $q -> submit({name => $title, class => 'submit'}) ) ); } catch Error::Simple with { my($error) = $_[0] -> text(); chomp $error; push(@html, $q -> th('Error') . $q -> td($error) ); }; # Warning: Don't ever omit this semi-colon; The error msgs are sometimes incomprehensible. print $q -> header({type => 'text/html;charset=ISO-8859-1'}), $q -> start_html({style => {src => '/css/default.css'}, title => $title}), $q -> h1({align => 'center'}, $title), $q -> start_form({action => $q -> url(), name => 'a_form'}), $q -> table ( {align => 'center', border => 1, class => 'submit'}, $q -> Tr([EMAIL PROTECTED]) ), $q -> end_form(), $q -> end_html(); -----><8----- -- Cheers Ron Savage, [EMAIL PROTECTED] on 07/06/2003 http://savage.net.au/index.html
