Accessing Pervasive.SQL With Perl

Page Last Modified: 06/10/15

Home Links ODBC (DBI) Contact

Win32::ODBC - Examples - using DBI's Win32::DBIODBC as a drop-in emulation

Here is an example that performs the same fetch as the Win32::ODBC example, but replaces that underlying module with the DBI emulation layer:

use strict;
use warnings;
#use Win32::ODBC;
use Win32::DBIODBC;

my $DSN = "DEMODATA";
#my $conn = new Win32::ODBC($DSN); # this does not work...you need the full connection string

my $conn = new Win32::ODBC("DSN=$DSN;UID='';PWD='';");
# warning here in newer DBIs because attributes are not passed as 3rd parameter by win32::DBIODBC


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 - 2017