
looping through an sql query using win32::odbc
I have been using the win32 odbc module to write the contents on a file
into an access database unfortunately it will only write the first line of
that file...What I am having trouble figuring out is how to construct a
loop which will read the next line of that file and then run the sql to
import it into access. It seems inefficient to do it this way but after
trying to open another $DSN and running into permission errors when
writing that data this seems the logical solution. Below is the script I
have put together. Any suggestions would be appreciated.
Bob
#!/usr/bin/perl
use Win32::ODBC;
$data = "C:/Perl/down.txt";
# open reads and closes files
close(FILE);
# separates each line of the file and breaks each line up into an array
$_ = $line;
Quote:
}
#open database
$DSN ="Bob";
if (!($db = new Win32::ODBC($DSN))){
print "Error connecting to $DSN\n";
print "Error: " . Win32::ODBC::Error() . "\n";
exit;
Quote:
}
# execute SQL command
$sql = "INSERT INTO test (1,2,3) VALUES ($ok[0],'$ok[1]','$ok[2]');";
if ($db->Sql($sql)){
print "SQL failed.\n";
print "Error: " . $db->Error() . "\n";
$db->Close();
exit;
}
# close the connection to the database:
$db->Close();