This question has never been answered. To out it another way, given the code
...
foreach my $mytable (@mytables) {
my $sth = $dbh->prepare("SELECT COUNT(*) FROM mytable");
# report error but move on to next table
}
how do I ignore the situation/error that DBI throws when $mytable does not
exist and just move on to the next table?
--- On Mon, 1/2/10, Tony Esposito <[email protected]> wrote:
From: Tony Esposito <[email protected]>
Subject: Re: prepare(SELECT ... FROM TABLE) error
To: "Beginners Perl" <[email protected]>, "7" <[email protected]>
Date: Monday, 1 February, 2010, 17:02
Also, if prepare fails, I want to continue processing -- hence the need to
capture the error in my code and not have DBI::DBD throw and exception then
stop all processing ...
--- On Mon, 1/2/10, Tony Esposito <[email protected]> wrote:
From: Tony Esposito <[email protected]>
Subject: Re: prepare(SELECT ... FROM TABLE) error
To: "Beginners Perl" <[email protected]>, "7" <[email protected]>
Date: Monday, 1 February, 2010, 14:40
Is this the idea? I do not ever want to catch the error from the prepare
statement itself -- I want my code to catch and throw the error. And I am
using Perl 5.8 so I do not need the use 5.010; pragma .... thx
use strict;
use warnings;
use 5.010;
eval {
my $sth = $dbh->prepare("SELECT COUNT(*) FROM mytable");
};
if ($dbh->err) {
print "Table $table -- DOES NOT EXIST\n";
}
$retCode = $sth->execute();
--- On Mon, 1/2/10, 7 <[email protected]> wrote:
From: 7 <[email protected]>
Subject: Re: prepare(SELECT ... FROM TABLE) error
To: "Beginners Perl" <[email protected]>
Date: Monday, 1 February, 2010, 14:05
On Mon, Feb 1, 2010 at 12:11 PM, Tony Esposito
<[email protected]>wrote:
> when the table does not exist the prepare fails. How do ignore the error
> thrown by the prepare() and catch it later in the program?
>
>
> my $dbh = DBI->connect("dbi:ODBC:mysql"
> ,$login
> ,$passwd
> ,{ RaiseError => 0 }
> );
> ...
> $sth = $dbh->prepare("SELECT COUNT(*) FROM mytable"); # don't catch
> $retCode = $sth->execute();
> if ($dbh->err) {
> print "Table $table -- DOES NOT EXIST\n";
> }
> ....
>
See if this helps:
use strict;
use warnings;
use 5.010;
eval {
die "***prepare error***";
};
say 'executing other code here';
if ($@) {
say "There was an error inside that eval block above: $@";
}
> my $dbh = DBI->connect("dbi:ODBC:mysql"
> ,$login
> ,$passwd
> ,{ RaiseError => 0 }
> );
> ...
> $sth = $dbh->prepare("SELECT COUNT(*) FROM mytable"); # don't catch
> $retCode = $sth->execute();
> if ($dbh->err) {
> print "Table $table -- DOES NOT EXIST\n";
> }
> ....
>
See if this helps:
use strict;
use warnings;
use 5.010;
eval {
die "***prepare error***";
};
say 'executing other code here';
if ($@) {
say "There was an error inside that eval block above: $@";
}
--- On Mon, 1/2/10, 7 <[email protected]> wrote:
From: 7 <[email protected]>
Subject: Re: prepare(SELECT ... FROM TABLE) error
To: "Beginners Perl" <[email protected]>
Date: Monday, 1 February, 2010, 14:05
On Mon, Feb 1, 2010 at 12:11 PM, Tony Esposito
<[email protected]>wrote:
> when the table does not exist the prepare fails. How do ignore the error
> thrown by the prepare() and catch it later in the program?
>
>
> my $dbh = DBI->connect("dbi:ODBC:mysql"
> ,$login
> ,$passwd
> ,{ RaiseError => 0 }
> );
> ...
> $sth = $dbh->prepare("SELECT COUNT(*) FROM mytable"); # don't catch
> $retCode = $sth->execute();
> if ($dbh->err) {
> print "Table $table -- DOES NOT EXIST\n";
> }
> ....
>
See if this helps:
use strict;
use warnings;
use 5.010;
eval {
die "***prepare error***";
};
say 'executing other code here';
if ($@) {
say "There was an error inside that eval block above: $@";
}
--output:--
executing other code here
There was an error inside that eval block above: ***prepare error*** at
2perl.pl line 7.