#! perl -w scipt use strict; use warnings; use DBI; use DBD::ODBC; use File::Copy; my ($data_source, $database, $user_id, $password) = qw( *********** ******** ******** ********); my $conn_string = "driver={SQL Server}; Server=$data_source; Database=$database; Trusted_Connection=yes"; my $dbh = DBI->connect( "DBI:ODBC:$conn_string" ) or die $DBI::errstr; my $Request_id; my $Variable_number; my $Variable; my $Choice; my @VARIABLE; my @CHOICE; my $Command; my $Return_results; my $Component_number_old = 1; my $Component_number = 1; my $SPROC; my $unique; my $flat_file = "Flat_file.txt"; open (FLAT_FILE, "<$flat_file"); while (){ chomp; print "look at me\n"; $Component_number_old = $Component_number; # undef $Component_number; if ($_ =~ /SPROC\sName\:\s([a-z|A-Z|0-9|_]{1,100})/){ print "Hi_A\n"; $SPROC = $1; } elsif ($_ =~ /^\*(.{36})\;(\d{1,5})\;(\d{1,5})\;([a-z|A-Z|0-9|_]{1,50})\;(.{1,100})/){ print "$_\n"; push (@VARIABLE, $Variable); push (@CHOICE, $Choice); print "Hi_B\n"; $unique = $1; $Component_number = $2; $Variable = $4; $Choice = $5; } if ($_ =~ /^\sEND/){ print "Hi_E\n"; push (@VARIABLE, $Variable); push (@CHOICE, $Choice); # $Command = join(' ', # 'EXEC', # $SPROC, # join(', ', # @CHOICE[1 .. $Component_number_old])) . ';'; $Command = "EXEC ".$SPROC." ".$CHOICE[1].", ".$CHOICE[2].", ".$CHOICE[3].", ".$CHOICE[4].", ".$CHOICE[5].", ".$CHOICE[6].", ".$CHOICE[7].", ".$CHOICE[8].", ".$CHOICE[9].", ".$CHOICE[10].", ".$CHOICE[11].", ".$CHOICE[12].", ".$CHOICE[13].", ".$CHOICE[14].", ".$CHOICE[15].", ".$CHOICE[16].", ".$CHOICE[17].", ".$CHOICE[18].", ".$CHOICE[19].", ".$CHOICE[20].", ".$CHOICE[21].", ".$CHOICE[22].", ".$CHOICE[23].", ".$CHOICE[24].", ".$CHOICE[25].", ".$CHOICE[26].";"; my $Request_id = $CHOICE[26]; print "$Command\n"; Got_Command($Command, $Request_id); # exit; undef @CHOICE; my @CHOICE; } if ($Component_number_old != $Component_number){ print "Hi_D\n"; push (@VARIABLE, $Variable); push (@CHOICE, $Choice); # $Command = join(' ', # 'EXEC', # $SPROC, # join(', ', # @CHOICE[1 .. $Component_number_old])) . ';'; if ($Component_number > 1){ my $a = 1+($Component_number*26); my $b = 2+($Component_number*26); my $c = 3+($Component_number*26); my $d = 4+($Component_number*26); my $e = 5+($Component_number*26); my $f = 6+($Component_number*26); my $g = 7+($Component_number*26); my $h = 8+($Component_number*26); my $i = 9+($Component_number*26); my $j = 10+($Component_number*26); my $k = 11+($Component_number*26); my $l = 12+($Component_number*26); my $m = 13+($Component_number*26); my $n = 14+($Component_number*26); my $o = 15+($Component_number*26); my $p = 16+($Component_number*26); my $q = 17+($Component_number*26); my $r = 18+($Component_number*26); my $s = 19+($Component_number*26); my $t = 20+($Component_number*26); my $u = 21+($Component_number*26); my $v = 22+($Component_number*26); my $w = 23+($Component_number*26); my $x = 24+($Component_number*26); my $y = 25+($Component_number*26); my $z = 26+($Component_number*26); $Command = "EXEC ".$SPROC." ".$CHOICE[1].", ".$CHOICE[2].", ".$CHOICE[3].", ".$CHOICE[4].", ".$CHOICE[5].", ".$CHOICE[6].", ".$CHOICE[7].", ".$CHOICE[8].", ".$CHOICE[9].", ".$CHOICE[10].", ".$CHOICE[11].", ".$CHOICE[12].", ".$CHOICE[13].", ".$CHOICE[14].", ".$CHOICE[15].", ".$CHOICE[16].", ".$CHOICE[17].", ".$CHOICE[18].", ".$CHOICE[19].", ".$CHOICE[20].", ".$CHOICE[21].", ".$CHOICE[22].", ".$CHOICE[23].", ".$CHOICE[24].", ".$CHOICE[25].", ".$CHOICE[26].";"; # $Command = "EXEC ".$SPROC." ".$CHOICE[$a].", ".$CHOICE[$b].", ".$CHOICE[$c].", ".$CHOICE[$d].", ".$CHOICE[$e].", ".$CHOICE[$f].", ".$CHOICE[$g].", ".$CHOICE[$h].", ".$CHOICE[$i].", ".$CHOICE[$j].", ".$CHOICE[$k].", ".$CHOICE[$l].", ".$CHOICE[$m].", ".$CHOICE[$n].", ".$CHOICE[$o].", ".$CHOICE[$p].", ".$CHOICE[$q].", ".$CHOICE[$r]." , ".$CHOICE[$s].", ".$CHOICE[$t].", ".$CHOICE[$u].", ".$CHOICE[$v].", ".$CHOICE[$w].", ".$CHOICE[$x].", ".$CHOICE[$y].", ".$CHOICE[$z].";"; } else{ $Command = "EXEC ".$SPROC." ".$CHOICE[1].", ".$CHOICE[2].", ".$CHOICE[3].", ".$CHOICE[4].", ".$CHOICE[5].", ".$CHOICE[6].", ".$CHOICE[7].", ".$CHOICE[8].", ".$CHOICE[9].", ".$CHOICE[10].", ".$CHOICE[11].", ".$CHOICE[12].", ".$CHOICE[13].", ".$CHOICE[14].", ".$CHOICE[15].", ".$CHOICE[16].", ".$CHOICE[17].", ".$CHOICE[18].", ".$CHOICE[19].", ".$CHOICE[20].", ".$CHOICE[21].", ".$CHOICE[22].", ".$CHOICE[23].", ".$CHOICE[24].", ".$CHOICE[25].", ".$CHOICE[26].";"; } my $Request_id = $CHOICE[26]; print "$Command\n"; Got_Command($Command, $Request_id); # undef @CHOICE; # my @CHOICE; print "@CHOICE"; # exit; push (@VARIABLE, $Variable); push (@CHOICE, $Choice); # $VARIABLE[0] = $Variable; # $CHOICE[0] = $Choice; } } close FLAT_FILE; my $source = $flat_file; my $dest = 'Bin'; move($source, $dest) or die "Error moving file: $!\n"; sub Got_Command { my($Command,$Request_id) = @_; print "Hi_F\n"; print "here\n"; my $output_file = "Output/Output_file_".$Request_id.".txt"; open (OUTPUT_FILE, "+>>$output_file"); # Pass parameters to a stored procedure stored procedure print "$Command\n"; my $sthB_A = $dbh->prepare($Command) or die "Couldn't prepare query: ".$dbh->errstr; $sthB_A->execute() or die "Couldn't execute query: ".$sthB_A->errstr; my $Return_results = "Select * from Result_storage_keep where Unique_identifier = ".$Request_id."\;"; print "$Return_results\n"; my $sth = $dbh->prepare($Return_results) or die "Couldn't prepare query: ".$dbh->errstr; $sth->execute() or die "Couldn't execute query: ".$sth->errstr; # my @row; while (my @row = $sth->fetchrow_array ) { print OUTPUT_FILE join("\t", @row); print OUTPUT_FILE "\n"; } }