<?xml version="1.0" encoding="windows-1252"?>
<node id="220983" title="DBI and getting trigger info" created="2002-12-18 18:09:03" updated="2005-08-13 21:14:40">
<type id="115">
perlquestion</type>
<author id="131128">
rbc</author>
<data>
<field name="doctext">
Dear Monks, &lt;BR&gt;
I don't know what I am doing wrong here.&lt;BR&gt;
I think the white board marker fumes are giving&lt;BR&gt;
me a mighty buzz because I cannot figure this&lt;BR&gt;
problem I am having out.&lt;BR&gt;
&lt;BR&gt;
The below script works fine.  It pulls the source code&lt;BR&gt;
out of a Oracle database for FUNCTIONS, PROCEDURES,&lt;BR&gt;
PACKAGES and PACKAGE BODYS &lt;BR&gt;
&lt;readmore&gt;
&lt;code&gt;
#!/usr/bin/perl -w

use DBI;
$NAME = shift;
$TYPE = shift;
$dbname = 'prod';
$dbuser = 'prod';
$dbpass = 'prod';
$dbd 	= 'Oracle';
$dbh 	= DBI-&gt;connect ( $dbname, $dbuser, $dbpass, $dbd);
if (!$dbh) {
	print "Error conecting to DB; $DBI::errstr\n";
}

my $sql = &lt;&lt;SQL;
select 
	text 
from 
	user_source 
where
	name = ?
	and type = ?
SQL

my $sth = $dbh-&gt;prepare($sql) || die $dbh-&gt;errstr;

print "CREATE or REPLACE\n";
$sth-&gt;execute( $NAME, $TYPE );
while ( my @r = $sth-&gt;fetchrow_array ) {
	print @r;
}
print "/\n";
print "show errors\n";

$sth-&gt;finish || die;
$dbh-&gt;disconnect;
&lt;/code&gt;
 ... I thought that I would modify this script&lt;BR&gt;
so that I could get the source code for triggers.&lt;BR&gt;
And here's the trigger getting script which does not&lt;BR&gt;
seem to get any trigger source!&lt;BR&gt;
&lt;code&gt;
#!/usr/bin/perl -w

use DBI;
use Data::Dumper;

$NAME = shift;
$dbname = 'prod';
$dbuser = 'prod';
$dbpass = 'prod';
$dbd 	= 'Oracle';
$dbh 	= DBI-&gt;connect ( $dbname, $dbuser, $dbpass, $dbd);
if (!$dbh) {
	print "Error conecting to DB; $DBI::errstr\n";
}

my $sql = &lt;&lt;SQL;
select 
	description,
	trigger_body 
from 
	user_triggers 
where
	trigger_name = ?
SQL
#print $sql;
my $sth = $dbh-&gt;prepare($sql) || die $dbh-&gt;errstr;

print "CREATE or REPLACE $NAME\n";
$sth-&gt;execute( $NAME );
while ( my @r = $sth-&gt;fetchrow_array ) {
	print @r;
}
print "/\n";
print "show errors\n";

$sth-&gt;finish || die;
$dbh-&gt;disconnect;
&lt;/code&gt;

When I run this above script like so ...&lt;BR&gt;
&lt;pre&gt;
$ ./getTrigger.pl MY_TRIGGER
&lt;/pre&gt;
&lt;BR&gt;
... the only output I get is this ...&lt;BR&gt;
&lt;pre&gt;
CREATE or REPLACE MY_TRIGGER
/
show errors
&lt;/pre&gt;
And there is a trigger named MY_TRIGGER in my DB. :(&lt;BR&gt;
I must be missing something.  &lt;BR&gt;
Your help is appreicated!
</field>
</data>
</node>
