Beefy Boxes and Bandwidth Generously Provided by pair Networks Frank
Problems? Is your data what you think it is?

DBI and getting trigger info

by rbc (Curate)
on Dec 18, 2002 at 23:09 UTC ( #220983=perlquestion: print w/ replies, xml ) Need Help??
rbc has asked for the wisdom of the Perl Monks concerning the following question:

Dear Monks,
I don't know what I am doing wrong here.
I think the white board marker fumes are giving
me a mighty buzz because I cannot figure this
problem I am having out.

The below script works fine. It pulls the source code
out of a Oracle database for FUNCTIONS, PROCEDURES,
#!/usr/bin/perl -w use DBI; $NAME = shift; $TYPE = shift; $dbname = 'prod'; $dbuser = 'prod'; $dbpass = 'prod'; $dbd = 'Oracle'; $dbh = DBI->connect ( $dbname, $dbuser, $dbpass, $dbd); if (!$dbh) { print "Error conecting to DB; $DBI::errstr\n"; } my $sql = <<SQL; select text from user_source where name = ? and type = ? SQL my $sth = $dbh->prepare($sql) || die $dbh->errstr; print "CREATE or REPLACE\n"; $sth->execute( $NAME, $TYPE ); while ( my @r = $sth->fetchrow_array ) { print @r; } print "/\n"; print "show errors\n"; $sth->finish || die; $dbh->disconnect;
... I thought that I would modify this script
so that I could get the source code for triggers.
And here's the trigger getting script which does not
seem to get any trigger source!
#!/usr/bin/perl -w use DBI; use Data::Dumper; $NAME = shift; $dbname = 'prod'; $dbuser = 'prod'; $dbpass = 'prod'; $dbd = 'Oracle'; $dbh = DBI->connect ( $dbname, $dbuser, $dbpass, $dbd); if (!$dbh) { print "Error conecting to DB; $DBI::errstr\n"; } my $sql = <<SQL; select description, trigger_body from user_triggers where trigger_name = ? SQL #print $sql; my $sth = $dbh->prepare($sql) || die $dbh->errstr; print "CREATE or REPLACE $NAME\n"; $sth->execute( $NAME ); while ( my @r = $sth->fetchrow_array ) { print @r; } print "/\n"; print "show errors\n"; $sth->finish || die; $dbh->disconnect;
When I run this above script like so ...

... the only output I get is this ...
show errors
And there is a trigger named MY_TRIGGER in my DB. :(
I must be missing something.
Your help is appreicated!

Comment on DBI and getting trigger info
Select or Download Code
Re: DBI and getting trigger info
by pfaut (Priest) on Dec 18, 2002 at 23:25 UTC

    I had a script that reverse engineered an Oracle database. Comparing what my script did to what yours is doing it appears yours should work.

    You should check the return status from $sth->execute( $NAME );. That will probably tell you what the problem is.

    --- print map { my ($m)=1<<hex($_)&11?' ':''; $m.=substr('AHJPacehklnorstu',hex($_),1) } split //,'2fde0abe76c36c914586c';
Re: DBI and getting trigger info
by runrig (Abbot) on Dec 18, 2002 at 23:29 UTC
    $dbh = DBI->connect ( $dbname, $dbuser, $dbpass, $dbd);
    I would connect with RaiseError set, then you wouldn't have to check every dbi call you make. (Sure, errors usually seem to happen on the connect's and prepare's, but you never know what might happen on execute or fetches also). Using RaiseError would mean that you can't use the above deprecated form of connect, and it should instead look like so:
    $dbh = DBI->connect ( "dbi:$dbd:$dbname", $dbuser, $dbpass, {RaiseErro +r => 1});
    Also I'd make sure the trigger is really there by executing the same SQL statement in sqlplus (but you knew that already, right?).

    Update: And make sure that your connecting as the same user in both sqlplus and this perl script.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://220983]
Approved by ybiC
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (17)
As of 2014-04-23 20:49 GMT
Find Nodes?
    Voting Booth?

    April first is:

    Results (554 votes), past polls