# used to lookup_values from the NTSM database sub lookup_NTSM_val { LogIt( $fhDEBUG, "=x" x 40 ); # so we can see the start of a new "run" LogIt( $fhDEBUG,"Entering sub:lookup_NTSM_val args: @_") if $CONFIG{DEBUG} > 3; my $cols = shift; # comma sep my $table = shift; my $criteria = shift; LogIt( $fhDEBUG,"calling: lookup( $cols, $table, $criteria);") if $CONFIG{DEBUG}>1; my $results = lookup($CONFIG{"NTSM_DB_DSN"}, $cols, $table, $criteria); LogIt( $fhDEBUG, "lookup_NTSM_val got result \"" . $results->{$cols} . "\"") if $CONFIG{DEBUG}>1; return( $results->{ $cols }); } # used to lookup_values from the FAAD database sub lookup_FAAD_val { LogIt( $fhDEBUG, "=x" x 40 ); # so we can see the start of a new "run" LogIt( $fhDEBUG,"Entering sub:lookup_FADD_val args: @_") if $CONFIG{DEBUG} > 3; my $cols = shift; # comma sep my $table = shift; my $criteria = shift; LogIt( $fhDEBUG,"calling: lookup( $cols, $table, $criteria);") if $CONFIG{DEBUG}>1; my $FAADval = lookup($CONFIG{"FAAD_DB_DSN"}, $cols, $table, $criteria); LogIt( $fhDEBUG, "lookup_FADD_val got result \"" . $FAADval->{$cols} . "\"") if $CONFIG{DEBUG}>1; return( $FAADval->{ $cols }); } # used to lookup_values from the CSS database sub lookup_CSSD_val { LogIt( $fhDEBUG, "=x" x 40 ); # so we can see the start of a new "run" LogIt( $fhDEBUG,"Entering sub:lookup_CSSD_val args: @_") if $CONFIG{DEBUG} > 3; my $cols = shift; # comma sep my $table = shift; my $criteria = shift; LogIt( $fhDEBUG,"calling: lookup( $cols, $table, $criteria);") if $CONFIG{DEBUG}>1; my $CSSDval = lookup($CONFIG{"CSSD_DB_DSN"}, $cols, $table, $criteria); LogIt( $fhDEBUG, "lookup_CSSD_val got result \"" . $CSSDval->{$cols} . "\"") if $CONFIG{DEBUG}>1; return( $CSSDval->{ $cols }); } sub lookup { LogIt( $fhDEBUG, "Entering sub:lookup args: @_") if $CONFIG{DEBUG} > 3; my $DSN = shift; # comma sep my $cols = shift; my $table = shift; my $criteria = shift; my $result; # Let's create the Connection object used to establish the connection # my $conn = Win32::OLE->CreateObject('ADODB.Connection'); # Open a connection using the SQL Server OLE DB Provider # LogIt( $fhDEBUG, "Opening ADODB connection") if $CONFIG{DEBUG} > 3; $conn->Open(< 3; # my $sql =< 3; my $rs = $conn->Execute($sql); LogIt( $fhDEBUG, "COMPLETE: executing SQL") if $CONFIG{DEBUG} > 3; if( !defined( $rs ) ){ LogIt( $fhDEBUG,"something went wrong: ", Win32::OLE->LastError()); LogIt( $fhERROR, "something went wrong: ", Win32::OLE->LastError()); die " died something went wrong: ", Win32::OLE->LastError(),"\n"; } while( ! $rs->EOF) { my $i= 0; COL: foreach my $col (split /,/, $cols) { next COL unless $col =~ /\w+/; LogIt( $fhDEBUG,"getting val for \$col $col") if $CONFIG{DEBUG} > 3; LogIt( $fhDEBUG,"Value: ". $rs->Fields($i)->value) if $CONFIG{DEBUG} > 3; $result->{$col} = $rs->Fields($i)->value; trim( $result->{$col}); $i++; } $rs->MoveNext; } LogIt( $fhDEBUG, "Closing ADODB connection") if $CONFIG{DEBUG} > 3; $conn->Close(); #commented out because this doesn't log correctly.... Dumper output is split over multipul lines #LogIt( $fhDEBUG,"". Dumper $result) if $CONFIG{DEBUG}; ( map { LogIt( $fhDEBUG,"". $_ ) } split /\n/, Dumper $result ) if $CONFIG{DEBUG} > 3; return( $result ); }