Accessing Pervasive.SQL With Perl

Page Last Modified:

Home Links ODBC (DBI) Contact

DBI + ODBC - Fetching Examples 3 - using RaiseError to catch errors

use strict;
use warnings;
use DBI;

my $dbHandle = DBI->connect('dbi:ODBC:DEMODATA', '', '', {PrintError=>0, RaiseError=>1});
my $stHandle = $dbHandle->prepare('SELECT Name,Description FROM Course ORDER By Name');

my $ret = $stHandle->execute();

while(my @returnRow = $stHandle->fetchrow_array())
{
print "Name: $returnRow[0], description: $returnRow[1]\n";
}

$stHandle->finish();
$dbHandle->disconnect();

Instead of explicitly checking each call and using die to stop as soon as there's a problem, we can use the RaiseError attribute to fail instantly for us. We are still not explicitly freeing resources if there is a problem, all problems will be treated as critical and stop the running ot the code, and we have no control over the more detailed error message that is displayed.

If we need more control then we need to handle things ourselves.

Another way of catching any errors and handling the error message ourselves is shown here.

Home Links ODBC (DBI) Contact

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