Accessing Pervasive.SQL With Perl

Page Last Modified: 22/02/10

Home Links ODBC (DBI) Contact

Win32::ODBC - Examples - fetching data

Here is an example that performs the same fetch as the DBI versions, but uses Win32::ODBC:

use strict;
use warnings;
use Win32::ODBC;

my $DSN = "DEMODATA";
my $conn = new Win32::ODBC($DSN);

if(!$conn)
{
print "Error connecting to $DSN\n";
print "Error: " . Win32::ODBC::Error() . "\n";
exit;
}
else
{
print "Connected to $DSN...\n";
my $statement = "SELECT Name, Description FROM Course";
if ($conn->Sql($statement))
{
print "SQL failed.\n";
print "Error: " . $conn->Error() . "\n";
}
else
{
my $i = 1;
while($conn->FetchRow())
{
my %data = $conn->DataHash();
print "$i\t$data{'Name'}\t$data{'Description'}\n";
$i++;
}
}

$conn->Close();
}

Home Links ODBC (DBI) Contact

All content on this site is copyright
Neil Hughes 2010 - 2020