#!/usr/local/bin/perl # by Jin Choi , 2000-03-26 # Utility script for comparing definitions triggers in different data # dictionaries. # Can be run in one of three modes. # "Connect" is given two connect strings and does the diff then and there. # "Write" is given a connect string and a file, and writes the results # out to the file. You can do this twice on different data dictionaries, # then use "Read" mode to compare the two. # $Id: triggers-diff.pl,v 1.1.1.1 2001/03/13 22:59:26 ben Exp $ use strict; use DBI; use Data::Dumper; my $usage_string = <{$key})) { push @new_triggers, $key; delete $trigger2_info->{$key}; } elsif (!defined($trigger2_info->{$key})) { push @deleted_triggers, $key; delete $trigger1_info->{$key}; } } print "New triggers:\n", join("\n", @new_triggers), "\n\n"; print "Deleted triggers:\n", join("\n", @deleted_triggers), "\n\n"; # Report triggers which are different. trigger_infoes 1 and 2 should # both contain the same triggers now. print "Modified triggers:\n"; foreach my $key (sort keys %$trigger1_info) { if ($trigger1_info->{$key} ne $trigger2_info->{$key}) { print "$trigger1_info->{$key}\n--\n$trigger2_info->{$key}\n\n"; } } exit; sub get_trigger_info { my $db = shift; my $trigger_info = {}; my $sth = $db->prepare("select trigger_name, description, trigger_body from user_triggers"); $sth->execute; while (my $rowref = $sth->fetchrow_arrayref) { my ($name, $description, $body) = @$rowref; chop $body; # Get rid of extraneous NULL. $trigger_info->{$name} .= "$description $body"; } $sth->finish; $db->disconnect; return $trigger_info; } sub get_dbhandle { my $connstr = shift; print "Opening database connection for $connstr.\n"; my $db = DBI->connect("dbi:Oracle:", $connstr) || die $!; $db->{AutoCommit} = 0; $db->{RaiseError} = 1; $db->{LongReadLen} = 2048; $db->{LongTruncOk} = 1; return $db; } # Returns a union of the keys of the two argument hashes. # The values are unimportant. sub union_hashes { my %union; my $h1_ref = shift; my $h2_ref = shift; foreach my $key (keys(%$h1_ref), keys(%$h2_ref)) { $union{$key} = 1; } return %union; } sub write_trigger_info_to_file { my ($trigger_info, $outfile) = @_; open(F, ">$outfile") || die $!; print "Outputting data to file $outfile.\n"; print F Dumper($trigger_info); close F; } sub get_trigger_info_from_file { my $filename = shift; return do $filename; }