##NOTE: This code sample has been intentionally modified. ## Package names, variables, and database tables have been modified to ## ensure that this code cannot be reused in a malicious manner. ## A few random lines have also been removed to ensure that this code does not actually work. ## THIS IS JUST A SAMPLE. package Companypackage::Subname::SubSubname; use strict; use vars qw($VERSION @ISA @EXPORT @EXPORT_OK); require Exporter; require AutoLoader; @ISA = qw(Exporter AutoLoader); @EXPORT = qw(); $VERSION = '0.05'; #0.04 as of 9/1/2000, 0.05 as of 9/6/2000 sub new ($$$); sub get_some_bills ($$); sub get_all_bills ($); sub get_one_bill ($$); ### new method # IN: object ref, ref to client, dbh # OUT: ref to blessed client bills object sub new ($$$) { my ($self, $Client, $databasehandle) = @_; my $dir = $Client->realdir; return(bless({CLIENT => $Client, DIR => $dir, DBH => $databasehandle}, $self)); } ### get_all_bills method # IN: object ref # OUT: ref to array of bills hash refs sub get_all_bills ($) { my $self = shift(@_); my $databasehandle = $self->{DBH}; my $SQL_Query = qq[select * from DATABASE_TABLE_NAME_DELETED where client_id = '$self->{DIR}' order by chamber, bill_num]; my $statement = $databasehandle->prepare($SQL_Query); # Get bills and put them in array my @bills = (); my $ref; $statement->execute(); while ($ref = $statement->fetchrow_hashref) { push(@bills, $ref); } $statement->finish(); return(\@bills); } ### get_all_bills method # IN: object ref # OUT: ref to array of bills hash refs sub get_some_bills ($$) { my ($self, $criteria) = @_; my $databasehandle = $self->{DBH}; my $crit = ""; # Alter $SQL_Query to use passed criteria if (defined($criteria)) { foreach (sort keys %$criteria) { next if (!defined($criteria->{$_})); next if $_ =~ /^ismem$/i; next if $_ =~ /^memseatids$/i; $crit .= " and $_ = '$criteria->{$_}'"; }#endforeach }#endif my $SQL_Query = qq[select * from DATABASE_TABLE_OMITTED where client_id = '$self->{DIR}' $crit order by chamber, bill_num]; # Get bills and put them in array my $statement = $databasehandle->prepare($SQL_Query); my @bills = (); my $ref; $statement->execute(); while ($ref = $statement->fetchrow_hashref) { push(@bills, $ref); } $statement->finish(); return(\@bills); } ### get_one_bill method # IN: object ref, optional -> criteria hash ref # OUT: one bill hash ref sub get_one_bill ($$) { my ($self, $criteria) = @_; my $databasehandle = $self->{DBH}; my $SQL_Query = qq[select * from DATABASE_TABLE_OMITTED where client_id = '$self->{DIR}']; # Alter $SQL_Query to use passed criteria if (defined($criteria)) { my @keys = keys(%$criteria); foreach (@keys) { $SQL_Query .= " and $_ = \'$criteria->{$_}\'" if (defined($criteria->{$_})); } } my $statement = $databasehandle->prepare($SQL_Query); $statement->execute(); my $ref = $statement->fetchrow_hashref(); $statement->finish(); return($ref); } ### add_bill method # IN: object ref, optional -> criteria hash ref # OUT: N/A sub add_bill ($$) { my ($self, $criteria) = @_; my $databasehandle = $self->{DBH}; my ($colnames,$values)=("CLIENTID","'$self->{CLIENT}->{dir}'"); my $id=""; my $idreceived=0; # Alter $SQL_Query to use passed criteria if (defined($criteria)) { my @keys = keys(%$criteria); my $i=1; foreach (@keys) { $colnames .= ", $_"; $values .= ", '$criteria->{$_}'"; if ($_ =~ /^id$/i) { $idreceived=1; } $i++; }#endif }#endif if (!$id_received) { my $tmpsql= "select max(id) MAXID from DATABASE_TABLE_OMITTED"; my $tmpsth=$databasehandle->prepare($tmpsql); $tmpsth->execute(); my $ref=$tmpsth->fetchrow_hashref(); $id=$ref->{MAXID}; $id++; $colnames .= ", id"; $values .= ", $id"; }#endif my $SQL_Query = "insert into DATABASE_TABLE_OMITTED ($colnames) values ($values)"; my $statement = $databasehandle->prepare($SQL_Query); $statement->execute(); $statement->finish(); }#endsub add_bill ### modify_bill method # IN: object ref, optional -> criteria hash ref # OUT: N/A sub modify_bill ($$) { my ($self, $criteria) = @_; my $databasehandle = $self->{DBH}; my $vals = ""; my $id=""; ##### Alter $SQL_Query to use passed criteria if (defined($criteria)) { my @keys = keys(%$criteria); foreach (@keys) { next if ($_ =~ /^CLIENT$/); if ($_ =~ /^ID$/) { $id=$criteria->{$_}; }#endif $vals .= "$_='$criteria->{$_}', "; }#endif $vals =~ s/, $//; #remove extra comma }#endif my $SQL_Query = "update DATABASE_TABLE_OMITTED set $vals where ID=" . $id . " and CLIENT_ID='" . $self->{CLIENT}->{dir} . "'"; eval { my $statement = $databasehandle->prepare($SQL_Query); $statement->execute(); $statement->finish(); }; }#endsub modify_bill return(1); __END__ =head1 NAME Companypackage::Subpackagename::Subsubpackagename - Perl extension for pulling out / modifying / inserting client bills data based on Bill_Oracle module =head1 SYNOPSIS my $bills = new Companypackage::Subpackagename::Subsubpackagename $Client, $databasehandle); my $all_bills = $bills->get_all_bills(); my $one_bill = $bills->get_one_bill({CRITERIA => whatever-it-is}); $bills-> add_bill({CRITERIA => whatever-it-is}); #ID optional--not recommended $bills->modify_bill({CRITERIA => whatever-it-is}); #include ID =head1 DESCRIPTION Companypackage::Bills::Client pulls out either all live bills associated with a client or one bill that matches a given set of criteria. Some possible criteria may include POSITION, DATECREATED, SPONSORTRACK, GROUPID, BILLNUMBER, DIR, BILLID, STATE, YEAR, CHAMBER, TITLE, STATUS. See the Bills_Client table in Oracle for more criteria information. =head1 Example usage: =head2 get_all_bills my $bills = new Companypackage::Subpackagename::Subsubpackagename($Client, $databasehandle); my $all_bills = $bills->all_bills(); foreach (@$all_bills) { my ($key, $value); while (($key, $value) = each(%$_)) { print("$key = $value\n") if ($value); } } =head2 get_some_bills my $bills = new Companypackage::Subpackagename::Subsubpackagename($Client, $databasehandle); my $all_bills = $bills->all_bills({CRITERIA => whatever-it-is}); foreach (@$all_bills) { my ($key, $value); while (($key, $value) = each(%$_)) { print("$key = $value\n") if ($value); } } =head2 get_one_bill my $bills = new Companypackage::Subpackagename::Subsubpackagename($Client, $databasehandle); my $bill = $bills->get_one_bill({CHAMBER => 'HOUSE', BILLID => 913445}); my ($key, $value); while (($key, $value) = each(%$bill)) { print("$key = $value\n") if ($value); } NOTE: This returns an array, not an array ref like get_some_bills and all_bills! It might even be prudent to deprecate get_one_bill and simpy use get_some_bills all the time. =head2 ADD_BILL my $vh = new Companypackage::Subpackagename::Subsubpackagename ($Clients[0], $databasehandle); $vh->add_bill({ TITLE => 'test bill, feel free to remove', CONGRESS => '224', BILL_NUM => 'H.R. 99998888', CHAMBER => 'H', STATE => 'VA', }); ##### Other criterion could be used with add_bill as well: #STATUS #defaults to 'L' #POSITION #defaults to NP #GROUP_ID #can be null #SUBTITLE #can be null #BODY #can be null =head2 MODIFY_BILL $vh->modify_bill({ ID => $bill_ID, #required! Must exist in database currently! TITLE => 'test bill WITH NAME CHANGED', BODY => 'now it has some body too', }); =cut