Connecting to Ingres from Perl

This section contains the following topics:

Requirements

Ingres Perl DBI Extension

How You Can Build and Install the Ingres Perl DBI Extension

Build the DBD::Ingres Extension

Test and Install the DBD::Ingres Extension

How You Can Use the DBD::Ingres Extension

Example—Connect to Ingres and Select from a Table

Previous Topic

Requirements

To connect to Ingres from Perl, you must meet the following prerequisites:

You can download the latest version of Perl from http://www.perl.org/.

System requirements and other installation information are contained in the Ingres Perl DBI Extension readme, available from http://www.ingres.com/downloads/prod-download-drivers.php.

Ingres Perl DBI Extension

The Ingres Perl DBI is a database extension for the Perl DBI system that enables access to Ingres databases. It is built on top of the standard Perl DBI extension. The driver supports database access to Ingres 2006 and prior versions of Ingres.

The source code is available for download from the Comprehensive Perl Archive Network (CPAN) repository for Perl extensions at http://search.cpan.org/dist/DBD-Ingres/.

For more information, see the Ingres Perl DBI Driver readme, available from http://search.cpan.org/~htoug/DBD-Ingres-0.51/Ingres.pm.

How You Can Build and Install the Ingres Perl DBI Extension

Before you can use the Ingres Perl extension, DBD::Ingres, you must first build and install it. Building the extension requires a C development environment and Ingres ESQL/C. The steps required to build the extension are common to all platforms except for a slight difference between the commands used.

Note: To build the extension on Windows, Microsoft's Visual Studio .NET compiler and Platform SDK are required.

Build the DBD::Ingres Extension

Perform the following procedure to download and build the DBD::Ingres extension.

To download and build the extension

  1. Download the latest version of the DBD::Ingres extension from http://search.cpan.org/dist/DBD-Ingres/.
  2. Use a suitable tool to extract the downloaded files.

    Among other tools for Windows, you could use WinZip.

  3. Open a command prompt or shell and change the directory to the location of the extracted files.
  4. Ensure the Ingres environment is properly set up.

    Ensure that II_SYSTEM and platform-specific paths have LIB and INCLUDE defined.

  5. Enter the following command to generate the Makefile needed to build the extension:

    perl Makefile.PL

  6. Build the extension:

    nmake

Test and Install the DBD::Ingres Extension

Perform the following procedure to test and install the DBD::Ingres extension.

To test and install the extension

  1. Set the environment variable DBI_DSN to the name of a valid Ingres database, for example, perldb:

    set DBI_DSN=perldb

  2. Run the tests using the following command:

    nmake test

    If everything is set up correctly, the message "All tests successful" is displayed.

  3. Install the extension using the following command:

    nmake install

How You Can Use the DBD::Ingres Extension

To use the Ingres Perl module, the Perl DBI module must be included using the use statement. The data source name supplied to the DBI->connect() method is used determine the correct DBD module to load to make the database connection.

Example—Connect to Ingres and Select from a Table

The following is a simple segment of code that connects to the Ingres database iidbdb and selects from iitables.

use DBI;

# Define the database to used

$dbname = "dbi:Ingres:iidbdb";

# Connect to the database

my $dbh = DBI->connect($dbname, "", "");

# Prepare a statement

$cursor = $dbh->prepare("SELECT table_name, table_owner FROM iitables order by table_name asc");

# Execute the cursor

$cursor->execute;

# Fetch the results

while ($row = $cursor->fetchrow_arrayref) {

     print(DBI::neat_list($row), "\n");

}

# Close the cursor

$cursor->finish;


© 2007 Ingres Corporation. All rights reserved.