Get trigger source if this is not a procedure or function.

This commit is contained in:
hjp 2002-06-18 15:10:59 +00:00
parent 7dfd0f68ae
commit 439ec1a2ed
1 changed files with 23 additions and 3 deletions

View File

@ -1,6 +1,6 @@
#!@@@perl@@@ -w
# $Id: oragetsrc.pl,v 1.1 2001-02-12 14:32:43 hjp Exp $
# $Id: oragetsrc.pl,v 1.2 2002-06-18 15:10:59 hjp Exp $
#
# print a named source (e.g, a function or procedure) from an oracle schema
#
@ -35,6 +35,7 @@ my @cred = read_cred("$ENV{HOME}/.dbi/$ARGV[0]");
my $dbh = DBI->connect($cred[0], $cred[1], $cred[2],
{ RaiseError => 1, AutoCommit => 0 });
# check if it is a procedure or function
my $lines =
$dbh->selectcol_arrayref(
"select text from user_source where name=? order by line",
@ -42,8 +43,27 @@ my $lines =
$src_name
);
for my $i (@$lines) {
print "$i";
if (@$lines) {
for my $i (@$lines) {
print "$i";
}
exit(0);
}
# nope - maybe a trigger?
$dbh->{LongReadLen} = 1000000;
$dbh->{LongTruncOk} = 0;
my $sth = $dbh->prepare("select description, trigger_body from user_triggers where trigger_name=?");
$sth->execute($src_name);
my $found = 0;
while (my $r = $sth->fetchrow_hashref("NAME_lc")) {
print "TRIGGER ", $r->{description}, "\n", $r->{trigger_body}, "\n";;
$found = 1;
}
exit(0) if ($found);
$dbh->disconnect();
exit(1);