|
This section contains the following topics: How You Can Build and Install the Ingres Perl DBI Extension Build the DBD::Ingres Extension Test and Install the DBD::Ingres Extension |
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.
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.
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.
Perform the following procedure to download and build the DBD::Ingres extension.
To download and build the extension
A common command for UNIX or Linux would be:
gzip -cd DBD-Ingres-0.51.tar.gz | tar xvf -
Ensure that II_SYSTEM and platform-specific paths have LD_LIBRARY_PATH defined.
perl Makefile.PL
make
Perform the following procedure to test and install the DBD::Ingres extension.
To test and install the extension
DBI_DSN=perldb #ksh, bash, sh
setenv DBI_DSN=perldb #tcsh, csh
make test
If everything is set up correctly, the message "All tests successful" will be displayed.
make install
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.
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;