eval-Question

  • Thread starter Reinhard Glauber
  • Start date
R

Reinhard Glauber

I have a sub called "insert".
In the main - Programm I call this subroutine. The Problem is, that I get an DB-Errormessage.
That's something I don't want. That's the reason why I tried to write the code with "eval".
The error occures, when there is a duplicate value.
The error is not the Problem. The Problem is, that I dont want Perl to write me all the time this Errorcode.
A simple "Error" is enough for me...
So look at the Code...

sub insert
{
........

eval {

$dbh = DBI->connect('DBI:mysq blabla');
my $sql = "INSERT INTO blabla";
my $sth = $dbh->prepare( $sql );
$sth->execute();

};

if (!$@) { $isok = "... ok\n";}
if ($@) {$isok = "Error\n";}

} # end of sub


$res = insert ($value);
print $isok;



Any Hints for a Perl-Newbie ??

Thanks a lot
 
U

usenet

Reinhard said:
The error is not the Problem. The Problem is, that I dont want Perl to write me all the time this Errorcode.
$dbh = DBI->connect('DBI:mysq blabla');

Your question is not completely clear to me, but you may get what you
want by changing your connect method a bit:

$dbh = DBI->connect('DBI:mysq blabla', PrintError => 0);

If you do that, you need to catch and print errors yourself with
something like this (from the DBI docs):

eval {
...
$sth->execute();
...
};
if ($@) {
# $sth->err and $DBI::err will be true if error was from DBI
warn $@; # print the error
... # do whatever you need to deal with the error
}
 
A

A. Sinan Unur

I have a sub called "insert".
In the main - Programm I call this subroutine. The Problem is, that I
get an DB-Errormessage. That's something I don't want. That's the
reason why I tried to write the code with "eval". The error occures,
when there is a duplicate value. The error is not the Problem. The
Problem is, that I dont want Perl to write me all the time this
Errorcode. A simple "Error" is enough for me...
So look at the Code...

sub insert
{
........

eval {

$dbh = DBI->connect('DBI:mysq blabla');

What is the specific blabla you use in this instance?

Have you read the posting guidelines posted here regularly? They contain
invaluable information on how to compose a post that conveys information
that helps us diagnose the problem.

Have you read the DBI documentation?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,009
Latest member
GidgetGamb

Latest Threads

Top