Accessing Pervasive.SQL With Perl

Page Last Modified:

Home Links ODBC (DBI) Contact

DBI + ODBC - Fetching Data

We can use the Pervasive.SQL DEMODATA test database, and to start with the table of courses, which has the following fields:

Field

Type

Size

Name

Fixed length string

7

Description

Fixed length string

50

Credit_Hours

Small integer

2

Dept_Name

Fixed length string

20

 

The SQL query to retrieve some of this data would be:

SELECT Name, Description FROM Course ORDER BY Name

and the Perl code to run this query would be:

$stHandle = $dbHandle->prepare("SELECT Name, Description FROM Course ORDER BY Name");

The prepare method returns undef on a failure, otherwise a handle to the prepared query statement. The query can then be executed:

$ret = $stHandle->execute();

where $ret is true if successful or undef if failed.

execute() does not return any results to the application - the rows of data must be retrieved from the database engine using one of the various fetch calls available.

After fetching you should call finish to let the server know that no more rows are required, e.g. you might not return all of the rows that the SELECT query has found. This avoids warnings or the remaining rows being returned unexpectedly during a later request. Even if you return all of the rows, which should result in the driver automatically calling finish, it is worth calling it explicitly.

$stHandle->finish();

We now have enough to write a simple test...

Home Links ODBC (DBI) Contact

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