if(exists $arg{I}) {
my $hreplist = initialize_rep_file($username, $password, $filename);
db_update( update_replist('I', $hreplist, [keys %$hreplist]) )
if exists $arg{d};
exit;
}
####
sub read_file {
@_ == 2 or croak 'Incorrect number of parameters';
my $dbh = shift;
my $source = shift;
my $statement = sprintf(q{
SELECT NodeId
, Title
, Date
, LastReputation
, Reputation
FROM %s
},
$source,
);
my $sth = $dbh->prepare($statement);
$sth->execute;
my %nodehash;
while(my $row = $sth->fetchrow_hashref) {
croak "Node ID $row->{NodeId} is duplicated!"
if exists $nodehash{ $row->{NodeId} };
$nodehash{ $row->{NodeId} } = $row;
}
return \%nodehash;
}
##
##
sub db_update {
@_ == 2 or croak 'Incorrect number of parameters';
my $dbh = shift;
my $hreplist = shift;
my $statement = sprintf(q{
INSERT
INTO %s
(%s)
VALUES (%s)
},
DEF_DBTABLE,
join(', ', @{ &DB_COLUMNS }),
join(', ', ('?') x @{ &DB_COLUMNS }),
);
my $sth = $dbh->prepare($statement);
foreach my $nodeid (sort keys %$hreplist) {
$sth->execute(@{ $hreplist->{$nodeid} }{ @{&DB_COLUMNS} };
}
}