Debian Codegraph @

perl/manager/getValues.pm

raw
1 #
2 # getValues($dbh,
3 # [-varcol => varname,]
4 # [-valcol => varval,]
5 # [-key => keyname,]
6 # tablename => indexname,
7 # ...)
8
9 package NetSNMP::manager::getValues;
10 require Exporter;
11 @ISA = qw(Exporter);
12 @EXPORT_OK=(getValues);
13
14 my $varcol = "varcol";
15 my $valcol = "valcol";
16 my $key = "lookup";
17
18 sub getValues {
19 my $dbh = shift;
20 my (@vars2, $tmp, $cursor, $row, %results, $i, $cursor);
21 my ($varcol, $valcol, $key) = ($varcol, $valcol, $key);
22 my @vars = @_;
23 while($#vars >= 0) {
24 $i = shift @vars;
25 $tmp = shift @vars;
26 if ($i =~ /^-/) {
27 $varcol = $tmp if ($i =~ /-varcol/);
28 $valcol = $tmp if ($i =~ /-valcol/);
29 $key = $tmp if ($i =~ /-key/);
30 } else {
31 push(@vars2,$i,$tmp);
32 }
33 }
34 while($#vars2 >= 0) {
35 $i = shift @vars2;
36 $tmp = shift @vars2;
37 # print "select $varcol,$valcol from $i where $key = '$tmp'\n";
38 ($cursor =
39 $dbh->prepare("select $varcol,$valcol from $i where $key = '$tmp'"))
40 or die "\nnot ok: $DBI::errstr\n";
41 ($cursor->execute)
42 or die "\nnot ok: $DBI::errstr\n";
43 while ( $row = $cursor->fetchrow_hashref ) {
44 $results{$row->{$varcol}} = $row->{$valcol};
45 }
46 }
47 return %results;
48 }
49 1;