summaryrefslogtreecommitdiff
path: root/perl/manager/getValues.pm
blob: bd0b9a630714d7c296d72cd3da97052f958e8796 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#
# getValues($dbh, 
#           [-varcol => varname,]
#           [-valcol => varval,]
#           [-key => keyname,]
#           tablename => indexname,
#           ...)

package NetSNMP::manager::getValues;
require Exporter;
@ISA = qw(Exporter);
@EXPORT_OK=(getValues);

my $varcol = "varcol";
my $valcol = "valcol";
my $key = "lookup";

sub getValues {
    my $dbh = shift;
    my (@vars2, $tmp, $cursor, $row, %results, $i, $cursor);
    my ($varcol, $valcol, $key) = ($varcol, $valcol, $key);
    my @vars = @_;
    while($#vars >= 0) {
	$i = shift @vars;
	$tmp = shift @vars;
	if ($i =~ /^-/) {
	    $varcol = $tmp if ($i =~ /-varcol/);
	    $valcol = $tmp if ($i =~ /-valcol/);
	    $key = $tmp if ($i =~ /-key/);
	} else {
	    push(@vars2,$i,$tmp);
	}
    }
    while($#vars2 >= 0) {
	$i = shift @vars2;
	$tmp = shift @vars2;
#	print "select $varcol,$valcol from $i where $key = '$tmp'\n";
	($cursor =
	 $dbh->prepare("select $varcol,$valcol from $i where $key = '$tmp'"))
	    or die "\nnot ok: $DBI::errstr\n";
	($cursor->execute)
	    or die "\nnot ok: $DBI::errstr\n";
	while ( $row = $cursor->fetchrow_hashref ) {
	    $results{$row->{$varcol}} = $row->{$valcol};
	}
    }
    return %results;
}
1;