CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
Printing SQL result using While loop

 



kuroneko1313
New User

Aug 23, 2012, 10:22 AM

Post #1 of 3 (623 views)
Printing SQL result using While loop Can't Post

Hi,

I'm trying to write a simple script that prints out (and eventually emails) a list of data from a SQL Query.

When I don't put the data in the While loop, my script successfully print out the first data from the Query result. However trying with a WHILE loop, it seems to be in infinite loop.. I know I'm missing a basic here.

Thanks for your help.


#declaring my database connection
my $ABConn = Win32::OLE->new('ADODB.Connection');
$conn_str = "Provider=sqloledb;Data Source=TestServer;"
$conn_str .= "Database=TestDatabase;Trusted_Connection=yes";
$SBEConn->Open($conn_str);
CheckErrors($ABConn, $conn_str);
$SBEConn->{CommandTimeout} = 900;

CheckMissingCode();

sub CheckMissingCode
{
my $sql =<<"EOQ";
SELECT m.merchant_id, m.merchant_name
FROM Merchant m
WHERE code = ''
EOQ

my $Rec1 = $ABConn->Execute($sql);
CheckErrors($ABConn, $sql);

if (!$Rec1->EOF)
{
print STDOUT "\tMissing Merchant Codes:\n";
while (!$Rec1->BOF && !$Rec1->EOF)
{
$prop = $Rec1->Fields("merchant_name")->Value;
$MID = $Rec1->Fields("merchant_id")->Value;
print STDOUT "* $prop \t $MID";
}
}
}


Laurent_R
Veteran / Moderator

Aug 23, 2012, 10:34 AM

Post #2 of 3 (620 views)
Re: [kuroneko1313] Printing SQL result using While loop [In reply to] Can't Post

I do not know the syntax of the module you are using, but I have the impression that the while loop keeps looping on the first line of the SQL output, since you have nothing in this loop which tells the while loop to go to the next record.

What does the $Rec1 look like? Is it a multi-line string?


kuroneko1313
New User

Aug 23, 2012, 11:07 AM

Post #3 of 3 (619 views)
Re: [Laurent_R] Printing SQL result using While loop [In reply to] Can't Post

Solved it.. just figured out I need to put below in order to move forward the WHILE loop.

$Rec1->MoveNext();

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives