diff --git a/oragetsrc/GNUmakefile b/oragetsrc/GNUmakefile new file mode 100644 index 0000000..8f4b9b5 --- /dev/null +++ b/oragetsrc/GNUmakefile @@ -0,0 +1,30 @@ +include GNUmakevars + +CONFDIR=../../configure + +all: configure oragetsrc + +clean: + rm oragetsrc customize + +install: $(BINDIR) $(BINDIR)/oragetsrc + +%: %.pl customize + sh ./customize < $< > $@ + chmod +x $@ + +%: %.sh customize + sh ./customize < $< > $@ + chmod +x $@ + +customize: configure + sh ./configure + +configure: $(CONFDIR)/start $(CONFDIR)/perl $(CONFDIR)/finish + cat $^ > $@ + +$(BINDIR): + mkdir -p $@ + +include GNUmakerules + diff --git a/oragetsrc/configure b/oragetsrc/configure new file mode 100644 index 0000000..6fea68e --- /dev/null +++ b/oragetsrc/configure @@ -0,0 +1,34 @@ +#!/bin/sh +# +echo "#!/bin/sh" > customize.$$ +echo "sed \\" > customize.$$ +chmod +x customize.$$ + +################################################################ +# find a working perl: +# +for i in /usr/bin/perl /usr/local/bin/perl /usr/bin/perl5 /usr/local/bin/perl5 +do + if $i -e 'exit ($] < 5.000)' + then + echo $i works + perl="$i" + break + fi +done +if [ -z "$perl" ] +then + could not find a working perl command, sorry. + exit 1 +fi +echo " -e 's,@@@perl@@@,$perl,g' \\" >> customize.$$ + + +################################################################ +# finish +# Add trailing newline and rename temp file to final name +# +echo >> customize.$$ + +mv customize.$$ customize + diff --git a/oragetsrc/oragetsrc.pl b/oragetsrc/oragetsrc.pl new file mode 100755 index 0000000..bba8d53 --- /dev/null +++ b/oragetsrc/oragetsrc.pl @@ -0,0 +1,49 @@ +#!@@@perl@@@ -w + +# $Id: oragetsrc.pl,v 1.1 2001-02-12 14:32:43 hjp Exp $ +# +# print a named source (e.g, a function or procedure) from an oracle schema +# +use strict; +use DBI; + +sub read_cred { + my ($fn) = @_; + + open(FN, "<$fn") or die "cannot open $fn: $!"; + my $line = ; + close(FN); + my @cred = split(/[\s\n]/, $line); + return @cred; +} + +if (@ARGV != 2) { + print STDERR "Usage: $0 credential_file source_name\n"; + print STDERR "\tcredential_file is a filename relative to \$HOME/.dbi/\n"; + print STDERR "\tThe file must contain a single line with three whitespace-separated fields:\n"; + print STDERR "\tDBI data source, username, password.\n"; + print STDERR "\te.g:\n"; + print STDERR "\tdbi:Oracle:ORCL scott tiger\n"; + exit 1; +} + + +my $db_name = $ARGV[0]; +my $src_name = $ARGV[1]; + +my @cred = read_cred("$ENV{HOME}/.dbi/$ARGV[0]"); +my $dbh = DBI->connect($cred[0], $cred[1], $cred[2], + { RaiseError => 1, AutoCommit => 0 }); + +my $lines = + $dbh->selectcol_arrayref( + "select text from user_source where name=? order by line", + {}, + $src_name + ); + +for my $i (@$lines) { + print "$i"; +} +$dbh->disconnect(); +