Perl and DB2
Supported Operating Systems
- AIX: Perl 5.8 or later, DBI 1.41 or later
- HP-UX on IPF (IA64): Perl 5.8 or later, DBI 1.41 or later
- Linux on x86 (32-bit DB2 instances and compilers only): Perl 5.8 or later, DBI 1.41 or later
- Linux on x64: Perl 5.8 or later, DBI 1.41 or later
- Linux on POWER® (PowerPC®, Power Systems Servers, pSeries®): Perl 5.8 or later, DBI 1.41 or later
- Linux on zSeries® (s/390x): Perl 5.8 or later, DBI 1.41 or later
- Solaris on UltraSPARC: Perl 5.8 or later, DBI 1.41 or later
- Solaris on x64: Perl 5.8 or later, DBI 1.41 or later
- Windows on x86 (32-bit DB2instances only): Perl 5.8 or later, DBI 1.41 or later
- Windows on x64: Perl 5.8 or later, DBI 1.41 or later
Installation of DB2 Perl Interface for L/U/W
Pre-requisites:
- Linux: Perl version 5.8 or above
- Windows: ActivePerl version 5.8 or above
- DBI version 1.53 and above
- IBM DB2 client version 9 fp2 and above
Pre-requisites for manual installation from scratch:
- C compiler
- Windows: MingW compiler and the dmake utility or the VC compiler
- Linux: gcc compiler
- AIX: xlc compiler
Windows – ActiveState Perl
Install the binary version of DBD::DB2 module by issuing the following commands
- 32-bitppm install http://www.bribes.org/perl/ppm/DBD-DB2.ppd
- 64-bitppm install http://www.bribes.org/perl/ppm64/DBD-DB2.ppd
Linux – CPAN installation
As for any cpan module issue the cpan command specifying DBD::DB2 as the module name, after setting the necessary environment variables as below
$ export DB2_HOME= $ export DB2LIB=/lib[64/32] # Based on your perl is 32-bit or 64-bit set the DB2LIB accordingly to lib32 or lib64 respectively # If you are using DS Driver then make sure you have selected and untarred the correct libraries (32 or 64 bit ) as per you perl's architecture and set DB2LIB to the lib directory $ cpan DBD::DB2
Compiling and Installing the Driver
Untar the archive and issue the following commands
$ export DB2_HOME= $ export DB2LIB=/lib[64/32] # Based on your perl is 32-bit or 64-bit set the DB2LIB accordingly to lib32 or lib64 respectively # If you are using DS Driver then make sure you have selected and untarred the correct libraries (32 or 64 bit ) as per you perl's architecture and set DB2LIB to the lib directory $ perl Makefile.PL $ make $ make install
Read more.
Links
- CPAN DBD::DB2 DataBase Driver for DB2 UDB and as a prerequesite CPAN DBI Database independent interface for Perl
- IBM DB2 Perl Database Interface for LUW
- DBI – Perl’s Database Interface
- ActiveState Perl distribution on Window
- IndigoPerl is a binary distribution of Perl for Windows
- Perl programming with DB2 Universal Database (IBM developerWorks)
- The O’Reilly perl.com Web site is a great resource for all things Perl.
- Perl Mongers is a loose association of international Perl User Groups.
- Perlmonks Latest News.
- CPAN, the Comprehensive Perl Archive Network, is another good Perl resource.
- YAPC, Yet Another Perl Conference, is a resource for grassroots symposia on the Perl programming language.
- „The Camel and the Snake, or „Cheat the Prophet““ (developerWorks, October 2002) discusses open source development with Perl, Python, and DB2.
- perlre – Perl regular expressions
- perlrequick – Perl Regular Expressions Quick Reference
Null Indicator in Perl
- NULL values are represented by undefined values in Perl
- In a scalar context, fetchrow[_array] returns the value of the first field. An undef is returned if there are no more rows or if an error occurred. Since that undef can’t be distinguished from an undef returned because the first field value was NULL, you should exercise some caution if you use fetchrow[_array] in a scalar context.
- print „First column MAY return NULL\n“ if $sth->{NULLABLE}->[0];
NULLABLE (array-ref, read-only)
Returns a reference to an array indicating the possibility of each column returning a null. Possible values are 0 (or an empty string) = no, 1 = yes, 2 = unknown. - Here’s how to convert fetched NULLs (undefined values) into empty strings:
while($row = $sth->fetchrow_arrayref) { # this is a fast and simple way to deal with nulls: foreach (@$row) { $_ = '' unless defined } print "@$row\n"; }Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â