Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > eval-Question

Reply
Thread Tools

eval-Question

 
 
Reinhard Glauber
Guest
Posts: n/a
 
      02-01-2006
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
 
Reply With Quote
 
 
 
 
usenet@DavidFilmer.com
Guest
Posts: n/a
 
      02-01-2006
Reinhard Glauber wrote:
> 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
}

--
http://DavidFilmer.com

 
Reply With Quote
 
 
 
 
A. Sinan Unur
Guest
Posts: n/a
 
      02-01-2006
"Reinhard Glauber" <(E-Mail Removed)> wrote in
news:43e12c46$0$16303$(E-Mail Removed)-online.net:

> 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?
--
A. Sinan Unur <(E-Mail Removed)>
(reverse each component and remove .invalid for email address)

comp.lang.perl.misc guidelines on the WWW:
http://mail.augustmail.com/~tadmc/cl...uidelines.html

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off




Advertisments