Thread

Posted on Thu Nov 23 13:09:28 2006 by rfarabi
no display error
I insert a record in Oracle table XXX (This table not exists in my database):

$sql =qq{ INSERT INTO XXX VALUES('BYE', SYSDATE) };
$sth=$dbh->prepare( $sql );
$sth->execute;

During the execute I have this error in display:

DBD::Oracle::st execute failed: ORA-00942: table or view does not exist (DBD ERROR: error
possibly near <*> indicator at char 13 in ' INSERT INTO <*>XXX VALUES('BYE', SYSDATE) ')
[for Statement " INSERT INTO XXX VALUES('BYE', SYSDATE) "] at d:\perl\job\pgm_3.pl line 23.

I don't want to display the error!
How can I do?
In database connection I resolved this with {RaiseError => 1}.

Best Regards

rfarabi
Direct Responses: 3604 | 3607 | Write a response
Posted on Thu Nov 23 14:14:18 2006 by byterock in response to 3603
Re: no display error
RaiseError does not stop Perl errors from happening!. When set to 1 will raise a perl error when Oracle raises an error. So in you code above if {RaiseError => 1} you will get an error on line 2 (an Oracle error) with {RaiseError => 0} you will get an error on line 3 (A perl error) You will have to wrap you statments in a eval{ }; block to trap the error. By the way you would be much better off posting your question to dbi-users@perl.org (you don't need to subscribe in order to post, and you won't be automatically subscribed either as very few people use this form for dbi or driver support. dbi-users is where you'll get the best support
Direct Responses: 3606 | Write a response
Posted on Thu Nov 23 15:16:31 2006 by rfarabi in response to 3604
Re: no display error

this is my program:

use DBI;
use Error qw(:try);
#-
my $username = "SCOTT";
my $password = "TIGER";
my $hostname = "192.168.0.14";
my $dbh;
my $sth;
my $sql;
#-
try{
    $dbh = DBI->connect('dbi:Oracle:host='.$hostname.';sid=ORCL;port=1521;server=dedicated', $username,$password,{RaiseError => 1,AutoCommit => 0});
    try{
       $sql =qq{ INSERT INTO PROVAXX VALUES('RICCARDO', 1) };
       $sth=$dbh->prepare( $sql );
       $sth->execute;
       print "\n * insert ok \n";
    }otherwise{
       $dbh->rollback();
       print "\n * Error insert \n";
    };
    $dbh->disconnect;
}otherwise{
    print "\n * Error connect \n";
};
--------------------------- Result is:
DBD::Oracle::st execute failed: ORA-00942: table or view does not exist (DBD ERROR: error possibly near <*> indicator at char 13 in ' INSERT INTO <*>PROVAXX VALUES('RICCARDO', 1) ') [for Statement " INSERT INTO PROVAXX VALUES('RICCARDO', 1) "] at d:\perl\job\pgm_3.pl line 17.

* Error insert
--------------------------- I want this result:

* Error insert
---------------------------
Direct Responses: 3608 | Write a response
Posted on Thu Nov 23 15:50:09 2006 by byterock in response to 3603
Re: no display error
RaiseError does not stop Perl errors from happening!. When set to 1 will raise a perl error when Oracle raises an error. So in you code above if {RaiseError => 1} you will get an error on line 2 (an Oracle error) with {RaiseError => 0} you will get an error on line 3 (A perl error) You will have to wrap you statments in a eval{ }; block to trap the error. By the way you would be much better off posting your question to dbi-users@perl.org (you don't need to subscribe in order to post, and you won't be automatically subscribed either as very few people use this form for dbi or driver support. dbi-users is where you'll get the best support
Write a response
Posted on Thu Nov 23 15:59:11 2006 by byterock in response to 3606
Re: no display error
in that case try PrintError =>0 which will turn off any printing of the Oracle errors
Direct Responses: 3609 | Write a response
Posted on Thu Nov 23 16:53:54 2006 by rfarabi in response to 3608
Re: no display error

ok,

I resolved my problem with PrintError=>0

Thanks for yuour collaboration

Best Regards

rfarabi
Write a response